@newkrok/nape-js 3.7.6 → 3.8.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/README.md +24 -1
- package/dist/ConvexResult-CYFNMlT2.d.cts +2690 -0
- package/dist/ConvexResult-CYFNMlT2.d.ts +2690 -0
- package/dist/chunk-3TXNIYBK.js +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +120 -2670
- package/dist/index.d.ts +120 -2670
- package/dist/index.js +1 -1
- package/dist/serialization/index.cjs +2 -0
- package/dist/serialization/index.d.cts +230 -0
- package/dist/serialization/index.d.ts +230 -0
- package/dist/serialization/index.js +2 -0
- package/package.json +11 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Li=class{static POSINF(){return 1/0}static NEGINF(){return-1/0}};Li.__name__=["zpp_nape","ZPP_Const"],Li.FMAX=1e100;var It=class It{static Constraint(){return It._Constraint++}static Interactor(){return It._Interactor++}static CbType(){return It._CbType++}static CbSet(){return It._CbSet++}static Listener(){return It._Listener++}static ZPP_SimpleVert(){return It._ZPP_SimpleVert++}static ZPP_SimpleSeg(){return It._ZPP_SimpleSeg++}static Space(){return It._Space++}static InteractionGroup(){return It._InteractionGroup++}};It.__name__=["zpp_nape","ZPP_ID"],It._Constraint=0,It._Interactor=0,It._CbType=0,It._CbSet=0,It._Listener=0,It._ZPP_SimpleVert=0,It._ZPP_SimpleSeg=0,It._Space=0,It._InteractionGroup=0;var In=It;var T=class{};T.__name__=["zpp_nape","util","ZPP_Flags"],T.GravMassMode_DEFAULT=null,T.GravMassMode_FIXED=null,T.GravMassMode_SCALED=null,T.InertiaMode_DEFAULT=null,T.InertiaMode_FIXED=null,T.MassMode_DEFAULT=null,T.MassMode_FIXED=null,T.BodyType_STATIC=null,T.BodyType_DYNAMIC=null,T.BodyType_KINEMATIC=null,T.ListenerType_BODY=null,T.ListenerType_CONSTRAINT=null,T.ListenerType_INTERACTION=null,T.ListenerType_PRE=null,T.PreFlag_ACCEPT=null,T.PreFlag_IGNORE=null,T.PreFlag_ACCEPT_ONCE=null,T.PreFlag_IGNORE_ONCE=null,T.CbEvent_BEGIN=null,T.CbEvent_ONGOING=null,T.CbEvent_END=null,T.CbEvent_WAKE=null,T.CbEvent_SLEEP=null,T.CbEvent_BREAK=null,T.CbEvent_PRE=null,T.InteractionType_COLLISION=null,T.InteractionType_SENSOR=null,T.InteractionType_FLUID=null,T.InteractionType_ANY=null,T.Winding_UNDEFINED=null,T.Winding_CLOCKWISE=null,T.Winding_ANTICLOCKWISE=null,T.ValidationResult_VALID=null,T.ValidationResult_DEGENERATE=null,T.ValidationResult_CONCAVE=null,T.ValidationResult_SELF_INTERSECTING=null,T.ShapeType_CIRCLE=null,T.ShapeType_POLYGON=null,T.Broadphase_DYNAMIC_AABB_TREE=null,T.Broadphase_SWEEP_AND_PRUNE=null,T.ArbiterType_COLLISION=null,T.ArbiterType_SENSOR=null,T.ArbiterType_FLUID=null,T.internal=!1,T.id_ImmState_ACCEPT=1,T.id_ImmState_IGNORE=2,T.id_ImmState_ALWAYS=4,T.id_GravMassMode_DEFAULT=0,T.id_GravMassMode_FIXED=1,T.id_GravMassMode_SCALED=2,T.id_InertiaMode_DEFAULT=0,T.id_InertiaMode_FIXED=1,T.id_MassMode_DEFAULT=0,T.id_MassMode_FIXED=1,T.id_BodyType_STATIC=1,T.id_BodyType_DYNAMIC=2,T.id_BodyType_KINEMATIC=3,T.id_ListenerType_BODY=0,T.id_ListenerType_CONSTRAINT=1,T.id_ListenerType_INTERACTION=2,T.id_ListenerType_PRE=3,T.id_PreFlag_ACCEPT=1,T.id_PreFlag_IGNORE=2,T.id_PreFlag_ACCEPT_ONCE=3,T.id_PreFlag_IGNORE_ONCE=4,T.id_CbEvent_BEGIN=0,T.id_CbEvent_END=1,T.id_CbEvent_WAKE=2,T.id_CbEvent_SLEEP=3,T.id_CbEvent_BREAK=4,T.id_CbEvent_PRE=5,T.id_CbEvent_ONGOING=6,T.id_InteractionType_COLLISION=1,T.id_InteractionType_SENSOR=2,T.id_InteractionType_FLUID=4,T.id_InteractionType_ANY=7,T.id_Winding_UNDEFINED=0,T.id_Winding_CLOCKWISE=1,T.id_Winding_ANTICLOCKWISE=2,T.id_ValidationResult_VALID=0,T.id_ValidationResult_DEGENERATE=1,T.id_ValidationResult_CONCAVE=2,T.id_ValidationResult_SELF_INTERSECTING=3,T.id_ShapeType_CIRCLE=0,T.id_ShapeType_POLYGON=1,T.id_Broadphase_DYNAMIC_AABB_TREE=0,T.id_Broadphase_SWEEP_AND_PRUNE=1,T.id_ArbiterType_COLLISION=1,T.id_ArbiterType_SENSOR=2,T.id_ArbiterType_FLUID=4;var mr=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}};mr.__name__=["zpp_nape","util","ZPP_Math"];var ue=class{};ue.__name__=["zpp_nape","util","ZPP_PubPool"],ue.poolGeomPoly=null,ue.nextGeomPoly=null,ue.poolVec2=null,ue.nextVec2=null,ue.poolVec3=null,ue.nextVec3=null;var fr=class{constructor(e,t){this.list=[];this.width=0;this.width=e,this.list=[]}resize(e,t,n){this.width=e;let l=e*t;for(let s=0;s<l;s++)this.list[s]=n}get(e,t){return this.list[t*this.width+e]}set(e,t,n){return this.list[t*this.width+e]=n}},vs=class extends fr{};vs.__name__=["zpp_nape","util","ZNPArray2_Float"];var gs=class extends fr{};gs.__name__=["zpp_nape","util","ZNPArray2_ZPP_GeomVert"];var Cs=class extends fr{};Cs.__name__=["zpp_nape","util","ZNPArray2_ZPP_MarchPair"];var En=class En{constructor(){this.value=!1;this.next=null;this.hnext=null;this.id=0;this.di=0;this.__class__=En}static _alloc(){if(En.zpp_pool==null)return new En;let e=En.zpp_pool;return En.zpp_pool=e.next,e.next=null,e}static get(e,t,n){let l=En._alloc();return l.id=e,l.di=t,l.value=n,l}static getpersist(e,t){let n=En._alloc();return n.id=e,n.di=t,n}static ordered_get(e,t,n){if(e<=t){let l=En._alloc();return l.id=e,l.di=t,l.value=n,l}else{let l=En._alloc();return l.id=t,l.di=e,l.value=n,l}}static ordered_get_persist(e,t){if(e<=t){let n=En._alloc();return n.id=e,n.di=t,n}else{let n=En._alloc();return n.id=t,n.di=e,n}}free(){}alloc(){}};En.__name__=["zpp_nape","util","Hashable2_Boolfalse"],En.zpp_pool=null;var Le=En;var Fo=1048576,Zs=1048575,Ms=106039,Hr=class Hr{constructor(){this.cnt=0;this.__class__=Hr;this.cnt=0,this.table=new Array(Fo).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*Ms+t&Zs];if(n==null)return null;if(n.id==e&&n.di==t)return n;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n}ordered_get(e,t){if(e>t){let l=e;e=t,t=l}let n=this.table[e*Ms+t&Zs];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*Ms+t&Zs];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*Ms+e.di&Zs,n=this.table[t],l=!0;n==null?(this.table[t]=e,e.hnext=null):l&&(e.hnext=n.hnext,n.hnext=e),l&&this.cnt++}add(e){let t=e.id*Ms+e.di&Zs,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*Ms+e.di&Zs,n=this.table[t];if(n==e)this.table[t]=n.hnext;else if(n!=null){let l;for(;l=n,n=n.hnext,n!=null&&n!=e;);l.hnext=n.hnext}e.hnext=null,this.cnt--}hash(e,t){return e*Ms+t&Zs}};Hr.__name__=["zpp_nape","util","FastHash2_Hashable2_Boolfalse"];var Es=Hr;var br=class{constructor(){this.elt=null;this.next=null}alloc(){}free(){this.elt=null}elem(){return this.elt}};br.zpp_pool=null;var Nt=class{constructor(){this.head=null;this.length=0;this.modified=!1;this.pushmod=!1}_allocNode(){let e=this.constructor._NodeClass,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor._NodeClass;e.elt=null,e.next=t.zpp_pool,t.zpp_pool=e}begin(){return this.head}setbegin(e){this.head=e,this.modified=!0,this.pushmod=!0}add(e){let t=this._allocNode();return t.elt=e,t.next=this.head,this.head=t,this.modified=!0,this.length++,e}addAll(e){let t=e.head;for(;t!=null;)this.add(t.elt),t=t.next}insert(e,t){let n=this._allocNode();return n.elt=t,e==null?(n.next=this.head,this.head=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.head.elt;return this.pop(),e}erase(e){let t,n;return e==null?(t=this.head,n=t.next,this.head=n,this.head==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),this._freeNode(t),this.modified=!0,this.length--,this.pushmod=!0,n}remove(e){let t=null,n=this.head;for(;n!=null;){if(n.elt==e){this.erase(t);break}t=n,n=n.next}}try_remove(e){let t=null,n=this.head,l=!1;for(;n!=null;){if(n.elt==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){for(;this.head!=null;){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=!0),this.modified=!0,this.length--}this.pushmod=!0}reverse(){let e=this.head,t=null;for(;e!=null;){let n=e.next;e.next=t,this.head=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.head==null}size(){return this.length}has(e){let t=this.head;for(;t!=null;){if(t.elt==e)return!0;t=t.next}return!1}front(){return this.head.elt}back(){let e=this.head,t=e;for(;t!=null;)e=t,t=t.next;return e.elt}iterator_at(e){let t=this.head;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t!=null?t.elt:null}};Nt.prototype.inlined_add=Nt.prototype.add;Nt.prototype.inlined_insert=Nt.prototype.insert;Nt.prototype.inlined_pop=Nt.prototype.pop;Nt.prototype.inlined_pop_unsafe=Nt.prototype.pop_unsafe;Nt.prototype.inlined_erase=Nt.prototype.erase;Nt.prototype.inlined_remove=Nt.prototype.remove;Nt.prototype.inlined_try_remove=Nt.prototype.try_remove;Nt.prototype.inlined_clear=Nt.prototype.clear;Nt.prototype.inlined_has=Nt.prototype.has;var zr=class{constructor(){this.colour=0;this.parent=null;this.next=null;this.prev=null;this.data=null;this.swapped=null;this.lt=null}_allocNode(){let e=this.constructor,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor;e.data=null,e.lt=null,e.swapped=null,e.next=t.zpp_pool,t.zpp_pool=e}free(){this.data=null,this.lt=null,this.swapped=null}alloc(){}verify(){if(!this.empty()){let e=this.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;){let t=e.data,n=!0;if(!this.empty()){let l=this.parent;for(;l.prev!=null;)l=l.prev;for(;l!=null;){let s=l.data;if(n){if(t==s)n=!1;else if(!this.lt(s,t)&&this.lt(t,s))return!1}else if(!this.lt(t,s)&&this.lt(s,t))return!1;if(l.next!=null)for(l=l.next;l.prev!=null;)l=l.prev;else{for(;l.parent!=null&&l==l.parent.next;)l=l.parent;l=l.parent}}}if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent}}}return!0}empty(){return this.parent==null}singular(){return this.parent!=null&&this.parent.prev==null?this.parent.next==null:!1}size(){let e=0;if(!this.empty()){let t=this.parent;for(;t.prev!=null;)t=t.prev;for(;t!=null;)if(++e,t.next!=null)for(t=t.next;t.prev!=null;)t=t.prev;else{for(;t.parent!=null&&t==t.parent.next;)t=t.parent;t=t.parent}}return e}has(e){return this.find(e)!=null}find(e){let t=this.parent;for(;t!=null&&t.data!=e;)this.lt(e,t.data)?t=t.prev:t=t.next;return t}has_weak(e){return this.find_weak(e)!=null}find_weak(e){let t=this.parent;for(;t!=null;)if(this.lt(e,t.data))t=t.prev;else if(this.lt(t.data,e))t=t.next;else break;return t}lower_bound(e){let t=null;if(!this.empty()){let n=this.parent;for(;n.prev!=null;)n=n.prev;for(;n!=null;){if(!this.lt(n.data,e)){t=n.data;break}if(n.next!=null)for(n=n.next;n.prev!=null;)n=n.prev;else{for(;n.parent!=null&&n==n.parent.next;)n=n.parent;n=n.parent}}}return t}first(){let e=this.parent;for(;e.prev!=null;)e=e.prev;return e.data}pop_front(){let e=this.parent;for(;e.prev!=null;)e=e.prev;let t=e.data;return this.remove_node(e),t}remove(e){this.remove_node(this.find(e))}successor_node(e){if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{let t=e;for(e=e.parent;e!=null&&e.prev!=t;)t=e,e=e.parent}return e}predecessor_node(e){if(e.prev!=null)for(e=e.prev;e.next!=null;)e=e.next;else{let t=e;for(e=e.parent;e!=null&&e.next!=t;)t=e,e=e.parent}return e}successor(e){let t=this.successor_node(this.find(e));return t==null?null:t.data}predecessor(e){let t=this.predecessor_node(this.find(e));return t==null?null:t.data}remove_node(e){if(e.next!=null&&e.prev!=null){let l=e.next;for(;l.prev!=null;)l=l.prev;let s=e.data;e.data=l.data,l.data=s,this.swapped!=null&&this.swapped(e.data,l.data),e=l}let t=e.prev==null?e.next:e.prev;if(e.colour==1){if(e.prev!=null||e.next!=null)t.colour=1;else if(e.parent!=null){let l=e.parent;for(;;){l.colour++,l.prev.colour--,l.next.colour--;let s=l.prev;if(s.colour==-1){this.__fix_neg_red(s);break}else if(s.colour==0){if(s.prev!=null&&s.prev.colour==0){this.__fix_dbl_red(s.prev);break}if(s.next!=null&&s.next.colour==0){this.__fix_dbl_red(s.next);break}}let i=l.next;if(i.colour==-1){this.__fix_neg_red(i);break}else if(i.colour==0){if(i.prev!=null&&i.prev.colour==0){this.__fix_dbl_red(i.prev);break}if(i.next!=null&&i.next.colour==0){this.__fix_dbl_red(i.next);break}}if(l.colour==2)if(l.parent==null)l.colour=1;else{l=l.parent;continue}break}}}let n=e.parent;n==null?this.parent=t:n.prev==e?n.prev=t:n.next=t,t!=null&&(t.parent=n),e.parent=e.prev=e.next=null,this._freeNode(e)}clear(){if(this.parent!=null){let e=this.parent;for(;e!=null;)if(e.prev!=null)e=e.prev;else if(e.next!=null)e=e.next;else{let t=e.parent;t!=null&&(e==t.prev?t.prev=null:t.next=null,e.parent=null),this._freeNode(e),e=t}this.parent=null}}clear_with(e){if(this.parent==null)return;let t=this.parent;for(;t!=null;)if(t.prev!=null)t=t.prev;else if(t.next!=null)t=t.next;else{e(t.data);let n=t.parent;n!=null&&(t==n.prev?n.prev=null:n.next=null,t.parent=null),this._freeNode(t),t=n}this.parent=null}clear_node(e,t){t(e.data);let n=e.parent;return n!=null&&(e==n.prev?n.prev=null:n.next=null,e.parent=null),this._freeNode(e),n}__fix_neg_red(e){let t=e.parent,n;if(t.prev==e){let l=e.prev,s=e.next,i=s.prev,r=s.next;l.colour=0,e.colour=t.colour=1,e.next=i,i!=null&&(i.parent=e);let o=t.data;t.data=s.data,s.data=o,this.swapped!=null&&this.swapped(t.data,s.data),s.prev=r,r!=null&&(r.parent=s),s.next=t.next,t.next!=null&&(t.next.parent=s),t.next=s,s!=null&&(s.parent=t),n=l}else{let l=e.next,s=e.prev,i=s.next,r=s.prev;l.colour=0,e.colour=t.colour=1,e.prev=i,i!=null&&(i.parent=e);let o=t.data;t.data=s.data,s.data=o,this.swapped!=null&&this.swapped(t.data,s.data),s.next=r,r!=null&&(r.parent=s),s.prev=t.prev,t.prev!=null&&(t.prev.parent=s),t.prev=s,s!=null&&(s.parent=t),n=l}n.prev!=null&&n.prev.colour==0?this.__fix_dbl_red(n.prev):n.next!=null&&n.next.colour==0&&this.__fix_dbl_red(n.next)}__fix_dbl_red(e){for(;;){let t=e.parent,n=t.parent;if(n==null){t.colour=1;break}let l,s,i,r,o,a,p;t==n.prev?(i=n,p=n.next,e==t.prev?(l=e,s=t,r=e.prev,o=e.next,a=t.next):(l=t,s=e,r=t.prev,o=e.prev,a=e.next)):(l=n,r=n.prev,e==t.prev?(s=e,i=t,o=e.prev,a=e.next,p=t.next):(s=t,i=e,o=t.prev,a=e.prev,p=e.next));let c=n.parent;if(c==null?this.parent=s:c.prev==n?c.prev=s:c.next=s,s!=null&&(s.parent=c),l.prev=r,r!=null&&(r.parent=l),l.next=o,o!=null&&(o.parent=l),s.prev=l,l!=null&&(l.parent=s),s.next=i,i!=null&&(i.parent=s),i.prev=a,a!=null&&(a.parent=i),i.next=p,p!=null&&(p.parent=i),s.colour=n.colour-1,l.colour=1,i.colour=1,s==this.parent)this.parent.colour=1;else if(s.colour==0&&s.parent.colour==0){e=s;continue}break}}try_insert_bool(e){let t=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else{let n=this.parent;for(;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break}return t==null?!1:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),!0)}try_insert(e){let t=null,n=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else for(n=this.parent;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break;return t==null?n:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t)}insert(e){let t=this._allocNode();if(t.data=e,this.parent==null)this.parent=t;else{let n=this.parent;for(;;)if(this.lt(t.data,n.data))if(n.prev==null){n.prev=t,t.parent=n;break}else n=n.prev;else if(n.next==null){n.next=t,t.parent=n;break}else n=n.next}return t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t}};zr.zpp_pool=null;var $i=null,ks=null,hi=null,uo=null,_o=null,xo=null,xl=null,bn=null,dl=null,Mi=null,yl=null,ml=null,yo=null,Ro=null,Go=null,qo=null,Wo=null,Jo=null,Uo=null,Ko=null,Yo=null;function Ye(S){let e=class extends br{};return e.__name__=["zpp_nape","util","ZNPNode_"+S],e.zpp_pool=null,e}function Xe(S,e){let t=class extends Nt{};return t.__name__=["zpp_nape","util","ZNPList_"+S],t._NodeClass=e,t}function Qi(S){let e=class extends zr{};return e.__name__=["zpp_nape","util","ZPP_Set_"+S],e.zpp_pool=null,e}function go(S){S.util||(S.util={}),S.util.ZNPNode_ZPP_CbType=Ye("ZPP_CbType"),S.util.ZNPNode_ZPP_CallbackSet=Ye("ZPP_CallbackSet"),S.util.ZNPNode_ZPP_Shape=Ye("ZPP_Shape"),S.util.ZNPNode_ZPP_Body=Ye("ZPP_Body"),S.util.ZNPNode_ZPP_Constraint=Ye("ZPP_Constraint"),S.util.ZNPNode_ZPP_Compound=Ye("ZPP_Compound"),S.util.ZNPNode_ZPP_Arbiter=Ye("ZPP_Arbiter"),S.util.ZNPNode_ZPP_InteractionListener=Ye("ZPP_InteractionListener"),S.util.ZNPNode_ZPP_CbSet=Ye("ZPP_CbSet"),S.util.ZNPNode_ZPP_Interactor=Ye("ZPP_Interactor"),S.util.ZNPNode_ZPP_BodyListener=Ye("ZPP_BodyListener"),S.util.ZNPNode_ZPP_CbSetPair=Ye("ZPP_CbSetPair"),S.util.ZNPNode_ZPP_ConstraintListener=Ye("ZPP_ConstraintListener"),S.util.ZNPNode_ZPP_CutInt=Ye("ZPP_CutInt"),S.util.ZNPNode_ZPP_CutVert=Ye("ZPP_CutVert"),S.util.ZNPNode_ZPP_PartitionVertex=Ye("ZPP_PartitionVertex"),S.util.ZNPNode_ZPP_SimplifyP=Ye("ZPP_SimplifyP"),S.util.ZNPNode_ZPP_PartitionedPoly=Ye("ZPP_PartitionedPoly"),S.util.ZNPNode_ZPP_GeomVert=Ye("ZPP_GeomVert"),S.util.ZNPNode_ZPP_SimpleVert=Ye("ZPP_SimpleVert"),S.util.ZNPNode_ZPP_SimpleEvent=Ye("ZPP_SimpleEvent"),S.util.ZNPNode_ZPP_Vec2=Ye("ZPP_Vec2"),S.util.ZNPNode_ZPP_AABBPair=Ye("ZPP_AABBPair"),S.util.ZNPNode_ZPP_Edge=Ye("ZPP_Edge"),S.util.ZNPNode_ZPP_AABBNode=Ye("ZPP_AABBNode"),S.util.ZNPNode_ZPP_Component=Ye("ZPP_Component"),S.util.ZNPNode_ZPP_FluidArbiter=Ye("ZPP_FluidArbiter"),S.util.ZNPNode_ZPP_SensorArbiter=Ye("ZPP_SensorArbiter"),S.util.ZNPNode_ZPP_Listener=Ye("ZPP_Listener"),S.util.ZNPNode_ZPP_ColArbiter=Ye("ZPP_ColArbiter"),S.util.ZNPNode_ZPP_InteractionGroup=Ye("ZPP_InteractionGroup"),S.util.ZNPNode_ZPP_ToiEvent=Ye("ZPP_ToiEvent"),S.util.ZNPNode_ConvexResult=Ye("ConvexResult"),S.util.ZNPNode_ZPP_GeomPoly=Ye("ZPP_GeomPoly"),S.util.ZNPNode_RayResult=Ye("RayResult");let e=S.util;Go=S.util.ZNPList_ZPP_InteractionListener=Xe("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),qo=S.util.ZNPList_ZPP_BodyListener=Xe("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),Wo=S.util.ZNPList_ZPP_ConstraintListener=Xe("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),Jo=S.util.ZNPList_ZPP_Constraint=Xe("ZPP_Constraint",e.ZNPNode_ZPP_Constraint),Uo=S.util.ZNPList_ZPP_Interactor=Xe("ZPP_Interactor",e.ZNPNode_ZPP_Interactor),Ko=S.util.ZNPList_ZPP_CbSet=Xe("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),Ro=S.util.ZNPList_ZPP_CbType=Xe("ZPP_CbType",e.ZNPNode_ZPP_CbType),S.util.ZNPList_ZPP_Vec2=Xe("ZPP_Vec2",e.ZNPNode_ZPP_Vec2),_o=S.util.ZNPList_ZPP_Vec2,S.util.ZNPList_ZPP_CallbackSet=Xe("ZPP_CallbackSet",e.ZNPNode_ZPP_CallbackSet),S.util.ZNPList_ZPP_Shape=Xe("ZPP_Shape",e.ZNPNode_ZPP_Shape),S.util.ZNPList_ZPP_Body=Xe("ZPP_Body",e.ZNPNode_ZPP_Body),S.util.ZNPList_ZPP_Compound=Xe("ZPP_Compound",e.ZNPNode_ZPP_Compound),S.util.ZNPList_ZPP_Arbiter=Xe("ZPP_Arbiter",e.ZNPNode_ZPP_Arbiter),Yo=S.util.ZNPList_ZPP_CbSetPair=Xe("ZPP_CbSetPair",e.ZNPNode_ZPP_CbSetPair),S.util.ZNPList_ZPP_CutInt=Xe("ZPP_CutInt",e.ZNPNode_ZPP_CutInt),S.util.ZNPList_ZPP_CutVert=Xe("ZPP_CutVert",e.ZNPNode_ZPP_CutVert),S.util.ZNPList_ZPP_PartitionVertex=Xe("ZPP_PartitionVertex",e.ZNPNode_ZPP_PartitionVertex),$i=S.util.ZNPList_ZPP_PartitionVertex,S.util.ZNPList_ZPP_SimplifyP=Xe("ZPP_SimplifyP",e.ZNPNode_ZPP_SimplifyP),uo=S.util.ZNPList_ZPP_SimplifyP,S.util.ZNPList_ZPP_PartitionedPoly=Xe("ZPP_PartitionedPoly",e.ZNPNode_ZPP_PartitionedPoly),ks=S.util.ZNPList_ZPP_PartitionedPoly,S.util.ZNPList_ZPP_GeomVert=Xe("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),hi=S.util.ZNPList_ZPP_GeomVert,S.util.ZNPList_ZPP_SimpleVert=Xe("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),yo=S.util.ZNPList_ZPP_SimpleEvent=Xe("ZPP_SimpleEvent",e.ZNPNode_ZPP_SimpleEvent),S.util.ZNPList_ZPP_AABBPair=Xe("ZPP_AABBPair",e.ZNPNode_ZPP_AABBPair),S.util.ZNPList_ZPP_Edge=Xe("ZPP_Edge",e.ZNPNode_ZPP_Edge),S.util.ZNPList_ZPP_AABBNode=Xe("ZPP_AABBNode",e.ZNPNode_ZPP_AABBNode),S.util.ZNPList_ZPP_Component=Xe("ZPP_Component",e.ZNPNode_ZPP_Component),S.util.ZNPList_ZPP_FluidArbiter=Xe("ZPP_FluidArbiter",e.ZNPNode_ZPP_FluidArbiter),S.util.ZNPList_ZPP_SensorArbiter=Xe("ZPP_SensorArbiter",e.ZNPNode_ZPP_SensorArbiter),S.util.ZNPList_ZPP_Listener=Xe("ZPP_Listener",e.ZNPNode_ZPP_Listener),S.util.ZNPList_ZPP_ColArbiter=Xe("ZPP_ColArbiter",e.ZNPNode_ZPP_ColArbiter),S.util.ZNPList_ZPP_InteractionGroup=Xe("ZPP_InteractionGroup",e.ZNPNode_ZPP_InteractionGroup),S.util.ZNPList_ZPP_ToiEvent=Xe("ZPP_ToiEvent",e.ZNPNode_ZPP_ToiEvent),S.util.ZNPList_ConvexResult=Xe("ConvexResult",e.ZNPNode_ConvexResult),S.util.ZNPList_ZPP_GeomPoly=Xe("ZPP_GeomPoly",e.ZNPNode_ZPP_GeomPoly),S.util.ZNPList_RayResult=Xe("RayResult",e.ZNPNode_RayResult),xl=S.util.ZNPNode_RayResult,xo=S.util.ZNPList_ZPP_SimpleVert,S.util.ZPP_Set_ZPP_Body=Qi("ZPP_Body"),S.util.ZPP_Set_ZPP_CbSetPair=Qi("ZPP_CbSetPair"),S.util.ZPP_Set_ZPP_PartitionVertex=Qi("ZPP_PartitionVertex"),yl=S.util.ZPP_Set_ZPP_PartitionVertex,S.util.ZPP_Set_ZPP_PartitionPair=Qi("ZPP_PartitionPair"),ml=S.util.ZPP_Set_ZPP_PartitionPair,S.util.ZPP_Set_ZPP_SimpleVert=Qi("ZPP_SimpleVert"),bn=S.util.ZPP_Set_ZPP_SimpleVert,S.util.ZPP_Set_ZPP_SimpleSeg=Qi("ZPP_SimpleSeg"),dl=S.util.ZPP_Set_ZPP_SimpleSeg,S.util.ZPP_Set_ZPP_SimpleEvent=Qi("ZPP_SimpleEvent"),Mi=S.util.ZPP_Set_ZPP_SimpleEvent,S.util.ZPP_Set_ZPP_CbSet=Qi("ZPP_CbSet")}var Ot=class Ot{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&&(Ot.internal=!0,this.outer_body=Ot._createBodyCb(),Ot.internal=!1,this.outer_body.zpp_inner=this),this.outer_body}wrapper_con(){return this.outer_con==null&&(Ot.internal=!0,this.outer_con=Ot._createConCb(),Ot.internal=!1,this.outer_con.zpp_inner=this),this.outer_con}wrapper_int(){let e=Ot._zpp;return this.outer_int==null&&(Ot.internal=!0,this.outer_int=Ot._createIntCb(),Ot.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=Ot._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}};Ot.__name__=["zpp_nape","callbacks","ZPP_Callback"],Ot._nape=null,Ot._zpp=null,Ot.internal=!1,Ot.zpp_pool=null,Ot._createBodyCb=null,Ot._createConCb=null,Ot._createIntCb=null,Ot._createPreCb=null;var _t=Ot;var ln=class ln{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=ln._zpp;this.cbTypes=new e.util.ZNPList_ZPP_CbType,this.listeners=new e.util.ZNPList_ZPP_InteractionListener,this.zip_listeners=!0,this.bodylisteners=new e.util.ZNPList_ZPP_BodyListener,this.zip_bodylisteners=!0,this.conlisteners=new e.util.ZNPList_ZPP_ConstraintListener,this.zip_conlisteners=!0,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.interactors=new e.util.ZNPList_ZPP_Interactor,this.id=e.ZPP_ID.CbSet(),this.cbpairs=new e.util.ZNPList_ZPP_CbSetPair}static setlt(e,t){let n=e.cbTypes.head,l=t.cbTypes.head;for(;n!=null&&l!=null;){let s=n.elt,i=l.elt;if(s.id<i.id)return!0;if(i.id<s.id)return!1;n=n.next,l=l.next}return l!=null?n==null:!1}static get(e){let t;ln.zpp_pool==null?t=new ln:(t=ln.zpp_pool,ln.zpp_pool=t.next,t.next=null);let n=null,l=e.head;for(;l!=null;){let s=l.elt;n=t.cbTypes.insert(n,s),s.cbsets.add(t),l=l.next}return t}static compatible(e,t,n){let l,s=e.options1,i=t.cbTypes;if(s.nonemptyintersection(i,s.includes)&&!s.nonemptyintersection(i,s.excludes)){let r=e.options2,o=n.cbTypes;l=r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.excludes)}else l=!1;if(l)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=ln._zpp,l=null,i=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;i!=null;){let r=i.elt;if(r.a==e&&r.b==t||r.a==t&&r.b==e){l=r;break}i=i.next}if(l==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,ln.setlt(e,t)?(r.a=e,r.b=t):(r.a=t,r.b=e),l=r,e.cbpairs.add(l),t!=e&&t.cbpairs.add(l)}return l.zip_listeners&&(l.zip_listeners=!1,l.__validate()),l}static empty_intersection(e,t){return ln.findOrCreatePair(e,t).listeners.head==null}static single_intersection(e,t,n){let s=ln.findOrCreatePair(e,t).listeners.head;return s!=null&&s.elt==n?s.next==null:!1}static find_all(e,t,n,l){let i=ln.findOrCreatePair(e,t).listeners.head;for(;i!=null;){let r=i.elt;r.event==n&&l(r),i=i.next}}increment(){this.count++}decrement(){return--this.count==0}invalidate_pairs(){let e=this.cbpairs.head;for(;e!=null;){let t=e.elt;t.zip_listeners=!0,e=e.next}}invalidate_listeners(){this.zip_listeners=!0,this.invalidate_pairs()}validate_listeners(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners())}realvalidate_listeners(){let e=ln._zpp;this.listeners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,l=null,s=this.listeners.head,i=n.listeners.head;for(;i!=null;){let r=i.elt;if(s!=null&&s.elt==r)i=i.next,l=s,s=s.next;else{let o;if(s!=null){let a=s.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;l==null?(c.next=a.head,a.head=c):(c.next=l.next,l.next=c),a.pushmod=a.modified=!0,a.length++,l=c}i=i.next}else l=s,s=s.next}}t=t.next}}invalidate_bodylisteners(){this.zip_bodylisteners=!0}validate_bodylisteners(){this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners())}realvalidate_bodylisteners(){let e=ln._zpp;this.bodylisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,l=null,s=this.bodylisteners.head,i=n.bodylisteners.head;for(;i!=null;){let r=i.elt;if(s!=null&&s.elt==r)i=i.next,l=s,s=s.next;else{let o;if(s!=null){let a=s.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 u=c;l==null?(u.next=p.head,p.head=u):(u.next=l.next,l.next=u),p.pushmod=p.modified=!0,p.length++,l=u}i=i.next}else l=s,s=s.next}}t=t.next}}invalidate_conlisteners(){this.zip_conlisteners=!0}validate_conlisteners(){this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}realvalidate_conlisteners(){let e=ln._zpp;this.conlisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,l=null,s=this.conlisteners.head,i=n.conlisteners.head;for(;i!=null;){let r=i.elt;if(s!=null&&s.elt==r)i=i.next,l=s,s=s.next;else{let o;if(s!=null){let a=s.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 u=c;l==null?(u.next=p.head,p.head=u):(u.next=l.next,l.next=u),p.pushmod=p.modified=!0,p.length++,l=u}i=i.next}else l=s,s=s.next}}t=t.next}}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners()),this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners()),this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}addConstraint(e){this.constraints.add(e)}addInteractor(e){this.interactors.add(e)}remConstraint(e){this.constraints.remove(e)}remInteractor(e){this.interactors.remove(e)}free(){for(this.listeners.clear(),this.zip_listeners=!0,this.bodylisteners.clear(),this.zip_bodylisteners=!0,this.conlisteners.clear(),this.zip_conlisteners=!0;this.cbTypes.head!=null;)this.cbTypes.pop_unsafe().cbsets.remove(this)}alloc(){}};ln.__name__=["zpp_nape","callbacks","ZPP_CbSet"],ln._zpp=null,ln.zpp_pool=null;var St=ln;var si=class si{constructor(){this.a=null;this.b=null;this.next=null;this.zip_listeners=!1;this.listeners=null;let e=si._zpp;this.listeners=new e.util.ZNPList_ZPP_InteractionListener}static get(e,t){let n=si._zpp,l;return si.zpp_pool==null?l=new si:(l=si.zpp_pool,si.zpp_pool=l.next,l.next=null),l.zip_listeners=!0,n.callbacks.ZPP_CbSet.setlt(e,t)?(l.a=e,l.b=t):(l.a=t,l.b=e),l}static setlt(e,t){let n=si._zpp;return n.callbacks.ZPP_CbSet.setlt(e.a,t.a)?!0:e.a==t.a?n.callbacks.ZPP_CbSet.setlt(e.b,t.b):!1}free(){this.a=this.b=null,this.listeners.clear()}alloc(){this.zip_listeners=!0}compatible(e){let t,n=e.options1,l=this.a.cbTypes;if(n.nonemptyintersection(l,n.includes)&&!n.nonemptyintersection(l,n.excludes)){let s=e.options2,i=this.b.cbTypes;t=s.nonemptyintersection(i,s.includes)&&!s.nonemptyintersection(i,s.excludes)}else t=!1;if(t)return!0;{let s=e.options2,i=this.a.cbTypes;if(s.nonemptyintersection(i,s.includes)&&!s.nonemptyintersection(i,s.excludes)){let 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,l=t.elt;if(n==l){let s,i,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;i=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else i=!1;if(i)s=!0;else{let a=n.options2,p=this.a.cbTypes;if(a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)){let c=n.options1,u=this.b.cbTypes;s=c.nonemptyintersection(u,c.includes)&&!c.nonemptyintersection(u,c.excludes)}else s=!1}s&&this.listeners.add(n),e=e.next,t=t.next}else n.precedence>l.precedence||n.precedence==l.precedence&&n.id>l.id?e=e.next:t=t.next}}empty_intersection(){return this.listeners.head==null}single_intersection(e){let t=this.listeners.head;return t!=null&&t.elt==e?t.next==null:!1}forall(e,t){let n=this.listeners.head;for(;n!=null;){let l=n.elt;l.event==e&&t(l),n=n.next}}};si.__name__=["zpp_nape","callbacks","ZPP_CbSetPair"],si._zpp=null,si.zpp_pool=null;var Se=si;var zn=class zn{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=zn._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){zn.ANY_SHAPE=new e.callbacks.CbType,zn.ANY_BODY=new e.callbacks.CbType,zn.ANY_COMPOUND=new e.callbacks.CbType,zn.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=zn._zpp,n=null,l=this.listeners.head;for(;l!=null;){let o=l.elt;if(e.precedence>o.precedence||e.precedence===o.precedence&&e.id>o.id)break;n=l,l=l.next}let s=this.listeners,i;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?i=new t.util.ZNPNode_ZPP_InteractionListener:(i=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=i.next,i.next=null),i.elt=e,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++;let 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=zn._zpp,n=null,l=this.bodylisteners.head;for(;l!=null;){let o=l.elt;if(e.precedence>o.precedence||e.precedence===o.precedence&&e.id>o.id)break;n=l,l=l.next}let s=this.bodylisteners,i;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?i=new t.util.ZNPNode_ZPP_BodyListener:(i=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=i.next,i.next=null),i.elt=e,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++;let 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=zn._zpp,n=null,l=this.conlisteners.head;for(;l!=null;){let o=l.elt;if(e.precedence>o.precedence||e.precedence===o.precedence&&e.id>o.id)break;n=l,l=l.next}let s=this.conlisteners,i;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?i=new t.util.ZNPNode_ZPP_ConstraintListener:(i=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=i.next,i.next=null),i.elt=e,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++;let 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}};zn.__name__=["zpp_nape","callbacks","ZPP_CbType"],zn._zpp=null,zn.ANY_SHAPE=null,zn.ANY_BODY=null,zn.ANY_COMPOUND=null,zn.ANY_CONSTRAINT=null;var zt=zn;var Ei=class Ei{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=In.Listener()}static setlt(e,t){return e.precedence<=t.precedence?e.precedence==t.precedence?e.id>t.id:!1:!0}swapEvent(e){}invalidate_precedence(){}addedToSpace(){}removedFromSpace(){}static _initEnums(e,t){let n=()=>{t.internal=!0;let s=new e.callbacks.ListenerType;return t.internal=!1,s};t.ListenerType_BODY==null&&(t.ListenerType_BODY=n()),t.ListenerType_CONSTRAINT==null&&(t.ListenerType_CONSTRAINT=n()),t.ListenerType_INTERACTION==null&&(t.ListenerType_INTERACTION=n()),t.ListenerType_PRE==null&&(t.ListenerType_PRE=n()),Ei.types=[t.ListenerType_BODY,t.ListenerType_CONSTRAINT,t.ListenerType_INTERACTION,t.ListenerType_PRE];let l=()=>{t.internal=!0;let s=new e.callbacks.CbEvent;return t.internal=!1,s};t.CbEvent_BEGIN==null&&(t.CbEvent_BEGIN=l()),t.CbEvent_END==null&&(t.CbEvent_END=l()),t.CbEvent_WAKE==null&&(t.CbEvent_WAKE=l()),t.CbEvent_SLEEP==null&&(t.CbEvent_SLEEP=l()),t.CbEvent_BREAK==null&&(t.CbEvent_BREAK=l()),t.CbEvent_PRE==null&&(t.CbEvent_PRE=l()),t.CbEvent_ONGOING==null&&(t.CbEvent_ONGOING=l()),Ei.events=[t.CbEvent_BEGIN,t.CbEvent_END,t.CbEvent_WAKE,t.CbEvent_SLEEP,t.CbEvent_BREAK,t.CbEvent_PRE,t.CbEvent_ONGOING]}};Ei.__name__=["zpp_nape","callbacks","ZPP_Listener"],Ei._nape=null,Ei._zpp=null,Ei.internal=!1,Ei.types=[],Ei.events=[];var Ke=Ei;var Ns=class extends Ke{constructor(t,n,l){super();this.handler=null;this.options=null;this.outer_zn=null;this.event=n,this.handler=l,this.body=this,this.type=0,this.options=t.zpp_inner}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=Ke._zpp;this.options.handler=(l,s,i)=>this.cbtype_change(l,s,i);let n=this.options.includes.head;for(;n!=null;){let l=n.elt,s=null,i=l.bodylisteners.head;for(;i!=null;){let c=i.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;s=i,i=i.next}let r=l.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;s==null?(a.next=r.head,r.head=a):(a.next=s.next,s.next=a),r.pushmod=r.modified=!0,r.length++;let p=l.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_bodylisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.bodylisteners.remove(this);let l=n.cbsets.head;for(;l!=null;){let s=l.elt;s.zip_bodylisteners=!0,l=l.next}t=t.next}this.options.handler=null}cbtype_change(t,n,l){this.removedFromSpace();let s=this.options;n?l?s.effect_change(t,!0,!0):s.includes.remove(t):l?s.effect_change(t,!1,!0):s.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3)throw new Error("Error: BodyListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};Ns.__name__=["zpp_nape","callbacks","ZPP_BodyListener"];var Os=class extends Ke{constructor(t,n,l){super();this.handler=null;this.options=null;this.outer_zn=null;this.event=n,this.handler=l,this.constraint=this,this.type=1,this.options=t.zpp_inner}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=Ke._zpp;this.options.handler=(l,s,i)=>this.cbtype_change(l,s,i);let n=this.options.includes.head;for(;n!=null;){let l=n.elt,s=null,i=l.conlisteners.head;for(;i!=null;){let c=i.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;s=i,i=i.next}let r=l.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;s==null?(a.next=r.head,r.head=a):(a.next=s.next,s.next=a),r.pushmod=r.modified=!0,r.length++;let p=l.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_conlisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.conlisteners.remove(this);let l=n.cbsets.head;for(;l!=null;){let s=l.elt;s.zip_conlisteners=!0,l=l.next}t=t.next}this.options.handler=null}cbtype_change(t,n,l){this.removedFromSpace();let s=this.options;n?l?s.effect_change(t,!0,!0):s.includes.remove(t):l?s.effect_change(t,!1,!0):s.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3&&t!=4)throw new Error("Error: ConstraintListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};Os.__name__=["zpp_nape","callbacks","ZPP_ConstraintListener"];var Tt=class Tt extends Ke{constructor(t,n,l,s){super();this.outer_zni=null;this.outer_znp=null;this.itype=0;this.handleri=null;this.allowSleepingCallbacks=!1;this.pure=!1;this.handlerp=null;this.type=s,this.interaction=this,this.event=l,this.options1=t.zpp_inner,this.options2=n.zpp_inner,this.allowSleepingCallbacks=!1}setInteractionType(t){this.itype=t}wake(){let t=this.options1.includes.head,n=this.options2.includes.head;for(;t!=null&&n!=null;){let l=t.elt,s=n.elt;if(l==s){let i=l.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next;t=t.next,n=n.next}else if(l.id<s.id){let i=l.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next;t=t.next}else{let i=s.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next;n=n.next}}for(;t!=null;){let l=t.elt.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;t=t.next}for(;n!=null;){let l=n.elt.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;n=n.next}}CbSetset(t,n,l){let s=Ke._zpp,i=Tt.UCbSet,r=Tt.VCbSet,o=Tt.WCbSet,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,u=p.elt;if(c==u){let h=this._allocCbSetNode(s);h.elt=c,h.next=o.head,o.head=h,o.modified=!0,o.length++,a=a.next,p=p.next}else if(s.callbacks.ZPP_CbSet.setlt(c,u)){let h=this._allocCbSetNode(s);h.elt=c,h.next=i.head,i.head=h,i.modified=!0,i.length++,a=a.next}else{let h=this._allocCbSetNode(s);h.elt=u,h.next=r.head,r.head=h,r.modified=!0,r.length++,p=p.next}}for(;a!=null;){let c=this._allocCbSetNode(s);c.elt=a.elt,c.next=i.head,i.head=c,i.modified=!0,i.length++,a=a.next}for(;p!=null;){let c=this._allocCbSetNode(s);c.elt=p.elt,c.next=r.head,r.head=c,r.modified=!0,r.length++,p=p.next}for(;i.head!=null;){let c=i.pop_unsafe(),u=n.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;r.head!=null;){let c=r.pop_unsafe(),u=o.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;o.head!=null;){let c=o.pop_unsafe();l(c,c);let u=o.head;for(;u!=null;)l(c,u.elt),u=u.next}}CbTypeset(t,n,l){let s=Ke._zpp,i=Tt.UCbType,r=Tt.VCbType,o=Tt.WCbType,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,u=p.elt;if(c==u){let h=this._allocCbTypeNode(s);h.elt=c,h.next=o.head,o.head=h,o.modified=!0,o.length++,a=a.next,p=p.next}else if(c.id<u.id){let h=this._allocCbTypeNode(s);h.elt=c,h.next=i.head,i.head=h,i.modified=!0,i.length++,a=a.next}else{let h=this._allocCbTypeNode(s);h.elt=u,h.next=r.head,r.head=h,r.modified=!0,r.length++,p=p.next}}for(;a!=null;){let c=this._allocCbTypeNode(s);c.elt=a.elt,c.next=i.head,i.head=c,i.modified=!0,i.length++,a=a.next}for(;p!=null;){let c=this._allocCbTypeNode(s);c.elt=p.elt,c.next=r.head,r.head=c,r.modified=!0,r.length++,p=p.next}for(;i.head!=null;){let c=i.pop_unsafe(),u=n.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;r.head!=null;){let c=r.pop_unsafe(),u=o.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;o.head!=null;){let c=o.pop_unsafe();l(c,c);let u=o.head;for(;u!=null;)l(c,u.elt),u=u.next}}with_uniquesets(t){let n=Ke._zpp,l;if(n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool==null?l=new n.util.ZPP_Set_ZPP_CbSetPair:(l=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=l.next,l.next=null),l.lt=n.callbacks.ZPP_CbSetPair.setlt,this.CbTypeset(this.options1.includes,this.options2.includes,(i,r)=>{this.CbSetset(i.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),l.try_insert(p)}})}),l.parent!=null){let i=l.parent;for(;i!=null;)if(i.prev!=null)i=i.prev;else if(i.next!=null)i=i.next;else{let r=i.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=i.parent;a!=null&&(i==a.prev?a.prev=null:a.next=null,i.parent=null);let p=i;p.data=null,p.lt=null,p.swapped=null,p.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=p,i=a}l.parent=null}let s=l;s.data=null,s.lt=null,s.swapped=null,s.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=s}with_union(t){let n=this.options1.includes.head,l=this.options2.includes.head;for(;n!=null&&l!=null;){let s=n.elt,i=l.elt;s==i?(t(s),n=n.next,l=l.next):s.id<i.id?(t(s),n=n.next):(t(i),l=l.next)}for(;n!=null;)t(n.elt),n=n.next;for(;l!=null;)t(l.elt),l=l.next}addedToSpace(){let t=Ke._zpp,n=this.type==3;this.with_union(l=>{let s=null,i=l.listeners.head;for(;i!=null;){let c=i.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;s=i,i=i.next}let r=l.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;s==null?(a.next=r.head,r.head=a):(a.next=s.next,s.next=a),r.pushmod=r.modified=!0,r.length++;let p=l.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_listeners=!0,c.invalidate_pairs(),p=p.next}if(n){let c=l.interactors.head;for(;c!=null;)c.elt.wake(),c=c.next}}),this.options1.handler=(l,s,i)=>this.cbtype_change1(l,s,i),this.options2.handler=(l,s,i)=>this.cbtype_change2(l,s,i),this.with_uniquesets(!0)}removedFromSpace(){this.with_uniquesets(!1);let t=this.type==3;this.with_union(n=>{n.listeners.remove(this);let l=n.cbsets.head;for(;l!=null;){let s=l.elt;s.zip_listeners=!0,s.invalidate_pairs(),l=l.next}if(t){let s=n.interactors.head;for(;s!=null;)s.elt.wake(),s=s.next}}),this.options1.handler=null,this.options2.handler=null}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}cbtype_change1(t,n,l){this.cbtype_change(this.options1,t,n,l)}cbtype_change2(t,n,l){this.cbtype_change(this.options2,t,n,l)}cbtype_change(t,n,l,s){this.removedFromSpace(),l?s?t.effect_change(n,!0,!0):t.includes.remove(n):s?t.effect_change(n,!1,!0):t.excludes.remove(n),this.addedToSpace()}swapEvent(t){if(this.type==3)throw new Error("Error: PreListener event can only be PRE");if(t!=0&&t!=1&&t!=6)throw new Error("Error: InteractionListener event must be either BEGIN, END, ONGOING");this.removedFromSpace(),this.event=t,this.addedToSpace()}_allocCbSetNode(t){let n;return t.util.ZNPNode_ZPP_CbSet.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbSet:(n=t.util.ZNPNode_ZPP_CbSet.zpp_pool,t.util.ZNPNode_ZPP_CbSet.zpp_pool=n.next,n.next=null),n}_allocCbTypeNode(t){let n;return t.util.ZNPNode_ZPP_CbType.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbType:(n=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=n.next,n.next=null),n}static _initStatics(t){Tt.UCbSet=new t.util.ZNPList_ZPP_CbSet,Tt.VCbSet=new t.util.ZNPList_ZPP_CbSet,Tt.WCbSet=new t.util.ZNPList_ZPP_CbSet,Tt.UCbType=new t.util.ZNPList_ZPP_CbType,Tt.VCbType=new t.util.ZNPList_ZPP_CbType,Tt.WCbType=new t.util.ZNPList_ZPP_CbType}};Tt.__name__=["zpp_nape","callbacks","ZPP_InteractionListener"],Tt.UCbSet=null,Tt.VCbSet=null,Tt.WCbSet=null,Tt.UCbType=null,Tt.VCbType=null,Tt.WCbType=null;var es=Tt;var ui=class ui{constructor(){this.outer=null;this.handler=null;this.includes=null;this.excludes=null;this.wrap_includes=null;this.wrap_excludes=null;let e=ui._zpp;this.includes=new e.util.ZNPList_ZPP_CbType,this.excludes=new e.util.ZNPList_ZPP_CbType}static argument(e){let t=ui._nape;return e==null?new t.callbacks.OptionType:e instanceof t.callbacks.OptionType?e:new t.callbacks.OptionType().including(e)}setup_includes(){let e=ui._zpp;this.wrap_includes=e.util.ZPP_CbTypeList.get(this.includes,!0)}setup_excludes(){let e=ui._zpp;this.wrap_excludes=e.util.ZPP_CbTypeList.get(this.excludes,!0)}excluded(e){return this.nonemptyintersection(e,this.excludes)}included(e){return this.nonemptyintersection(e,this.includes)}compatible(e){return this.nonemptyintersection(e,this.includes)?!this.nonemptyintersection(e,this.excludes):!1}nonemptyintersection(e,t){let n=!1,l=e.head,s=t.head;for(;s!=null&&l!=null;){let i=s.elt,r=l.elt;if(i===r){n=!0;break}else i.id<r.id?s=s.next:l=l.next}return n}insertOrdered(e,t){let n=ui._zpp,l=null,s=e.head;for(;s!=null;){let r=s.elt;if(t.id<r.id)break;l=s,s=s.next}let i;n.util.ZNPNode_ZPP_CbType.zpp_pool==null?i=new n.util.ZNPNode_ZPP_CbType:(i=n.util.ZNPNode_ZPP_CbType.zpp_pool,n.util.ZNPNode_ZPP_CbType.zpp_pool=i.next,i.next=null),i.elt=t,l==null?(i.next=e.head,e.head=i):(i.next=l.next,l.next=i),e.pushmod=e.modified=!0,e.length++}effect_change(e,t,n){t?n?this.insertOrdered(this.includes,e):this.includes.remove(e):n?this.insertOrdered(this.excludes,e):this.excludes.remove(e)}append_type(e,t){e===this.includes?this.includes.has(t)||(this.excludes.has(t)?this.handler!=null?this.handler(t,!1,!1):this.excludes.remove(t):this.handler!=null?this.handler(t,!0,!0):this.insertOrdered(this.includes,t)):this.excludes.has(t)||(this.includes.has(t)?this.handler!=null?this.handler(t,!0,!1):this.includes.remove(t):this.handler!=null?this.handler(t,!1,!0):this.insertOrdered(this.excludes,t))}set(e){if(e!==this){for(;this.includes.head!=null;)this.append_type(this.excludes,this.includes.head.elt);for(;this.excludes.head!=null;)this.append_type(this.includes,this.excludes.head.elt);let t=e.excludes.head;for(;t!=null;){let l=t.elt;this.append_type(this.excludes,l),t=t.next}let n=e.includes.head;for(;n!=null;){let l=n.elt;this.append_type(this.includes,l),n=n.next}}return this}append(e,t){let n=ui._nape;if(t==null)throw new Error("Error: Cannot append null, only CbType and CbType list values");if(t instanceof n.callbacks.CbType){let l=t;this.append_type(e,l.zpp_inner)}else if(t instanceof n.callbacks.CbTypeList){let l=t;l.zpp_inner.valmod();let s=n.callbacks.CbTypeIterator.get(l);for(;;){s.zpp_inner.zpp_inner.valmod();let i=s.zpp_inner;i.zpp_inner.valmod(),i.zpp_inner.zip_length&&(i.zpp_inner.zip_length=!1,i.zpp_inner.user_length=i.zpp_inner.inner.length);let r=i.zpp_inner.user_length;s.zpp_critical=!0;let o;if(s.zpp_i<r?o=!0:(s.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=s,s.zpp_inner=null,o=!1),!o)break;s.zpp_critical=!1;let a=s.zpp_inner.at(s.zpp_i++);this.append_type(e,a.zpp_inner)}}else if(t instanceof Array){let l=t,s=0;for(;s<l.length;){let i=l[s];if(++s,!(i instanceof n.callbacks.CbType))throw new Error("Error: Cannot append non-CbType or CbType list value");let r=i;this.append_type(e,r.zpp_inner)}}else throw new Error("Error: Cannot append non-CbType or CbType list value")}};ui.__name__=["zpp_nape","callbacks","ZPP_OptionType"],ui._nape=null,ui._zpp=null;var Ht=ui;var kn=class kn{constructor(){this.outer=null;this.id=0;this.userData=null;this.compound=null;this.space=null;this.active=!1;this.stiff=!1;this.frequency=0;this.damping=0;this.maxForce=0;this.maxError=0;this.breakUnderForce=!1;this.breakUnderError=!1;this.removeOnBreak=!1;this.component=null;this.ignore=!1;this.__velocity=!1;this.cbTypes=null;this.cbSet=null;this.wrap_cbTypes=null;this.pre_dt=-1;this.__class__=kn;this._initBase()}_initBase(){let e=kn._zpp;this.id=In.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=kn._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=kn._zpp;if(!this.cbTypes.has(e)){this.space!=null&&(this.dealloc_cbSet(),e.constraints.add(this));let n=null,l=this.cbTypes.head;for(;l!=null;){let o=l.elt;if(e.id<o.id)break;n=l,l=l.next}let s=this.cbTypes,i;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?i=new t.util.ZNPNode_ZPP_CbType:(i=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=i.next,i.next=null),i.elt=e;let r=i;n==null?(r.next=s.head,s.head=r):(r.next=n.next,n.next=r),s.pushmod=s.modified=!0,s.length++,this.space!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){(this.cbSet=this.space.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.constraints.add(this))}dealloc_cbSet(){let e=kn._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=kn._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=kn._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=kn._nape,n=this.outer;n.zpp_inner.wrap_cbTypes==null&&n.zpp_inner.setupcbTypes();let l=n.zpp_inner.wrap_cbTypes;l.zpp_inner.valmod();let s=t.callbacks.CbTypeIterator.get(l);for(;;){s.zpp_inner.zpp_inner.valmod();let f=s.zpp_inner;f.zpp_inner.valmod(),f.zpp_inner.zip_length&&(f.zpp_inner.zip_length=!1,f.zpp_inner.user_length=f.zpp_inner.inner.length);let _=f.zpp_inner.user_length;s.zpp_critical=!0;let d;if(s.zpp_i<_?d=!0:(s.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=s,s.zpp_inner=null,d=!1),!d)break;s.zpp_critical=!1;let b=s.zpp_inner.at(s.zpp_i++);e.zpp_inner.wrap_cbTypes==null&&e.zpp_inner.setupcbTypes();let m=e.zpp_inner.wrap_cbTypes;m.zpp_inner.reverse_flag?m.push(b):m.unshift(b)}e.zpp_inner.removeOnBreak=n.zpp_inner.removeOnBreak;let i=n.zpp_inner.breakUnderError;e.zpp_inner.breakUnderError!=i&&(e.zpp_inner.breakUnderError=i,e.zpp_inner.wake());let 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 u=n.zpp_inner.stiff;e.zpp_inner.stiff!=u&&(e.zpp_inner.stiff=u,e.zpp_inner.wake());let h=n.zpp_inner.ignore;e.zpp_inner.ignore!=h&&(e.zpp_inner.ignore=h,e.zpp_inner.wake());let x=n.zpp_inner.active;e.zpp_inner.active!=x&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.woken=!1),e.zpp_inner.clearcache(),x?(e.zpp_inner.active=x,e.zpp_inner.activate(),e.zpp_inner.space!=null&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.sleeping=!0),e.zpp_inner.space.wake_constraint(e.zpp_inner,!0))):(e.zpp_inner.space!=null&&(e.zpp_inner.wake(),e.zpp_inner.space.live_constraints.remove(e.zpp_inner)),e.zpp_inner.active=x,e.zpp_inner.deactivate()))}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let l=t.parent;t.parent=n,n=t,t=l}for(;n!=null;){let l=n.parent;n.parent=t,n=l}return t}static _unionComponents(e,t){let n=kn._findRoot(e),l=kn._findRoot(t);n!=l&&(n.rank<l.rank?n.parent=l:n.rank>l.rank?l.parent=n:(l.parent=n,n.rank++))}};kn.__name__=["zpp_nape","constraint","ZPP_Constraint"],kn._nape=null,kn._zpp=null;var Ze=kn;var Pr=class Pr{constructor(){this.id=0;this.bc=null;this.cb=null}static dict(e,t){let n=new Pr;return n.id=e,n.bc=t,n}static todo(e,t){let n=new Pr;return n.id=e,n.cb=t,n}};Pr.__name__=["zpp_nape","constraint","ZPP_CopyHelper"];var _i=Pr;var fl=class fl extends Ze{constructor(){super();this.outer_zn=null;this.ratio=0;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.scale=0;this.b1=null;this.b2=null;this.kMass=0;this.jAcc=0;this.jMax=0;this.gamma=0;this.bias=0;this.stepped=!1;this.ratio=1,this.jAcc=0,this.slack=!1,this.jMax=1/0,this.stepped=!1}is_slack(){let t=this.ratio*this.b2.rot-this.b1.rot;return this.equal?(this.scale=1,!1):t<this.jointMin?(this.scale=-1,!1):t>this.jointMax?(this.scale=1,!1):(this.scale=0,!0)}bodyImpulse(t){let n=oe();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.scale*this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.scale*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let l=fl._createFn(null,null,this.jointMin,this.jointMax,this.ratio);if(this.copyto(l),t!=null&&this.b1!=null){let s=null,i=0;for(;i<t.length;){let r=t[i];if(++i,r.id==this.b1.id){s=r.bc;break}}s!=null?l.zpp_inner.b1=s.zpp_inner:n.push(_i.todo(this.b1.id,r=>{l.zpp_inner.b1=r.zpp_inner}))}if(t!=null&&this.b2!=null){let s=null,i=0;for(;i<t.length;){let r=t[i];if(++i,r.id==this.b2.id){s=r.bc;break}}s!=null?l.zpp_inner.b2=s.zpp_inner:n.push(_i.todo(this.b2.id,r=>{l.zpp_inner.b2=r.zpp_inner}))}return l}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: AngleJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: AngleJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let l=this.b1.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let l=this.b2.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1,this.slack=!1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax;let l=this.ratio*this.b2.rot-this.b1.rot;this.equal?(l-=this.jointMax,this.slack=!1,this.scale=1):l<this.jointMin?(l=this.jointMin-l,this.scale=-1,this.slack=!1):l>this.jointMax?(l-=this.jointMax,this.scale=1,this.slack=!1):(this.scale=0,l=0,this.slack=!0);let s=l;if(!this.slack){if(this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&s*s>this.maxError*this.maxError)return!0;let i=2*Math.PI*this.frequency;this.gamma=1/(t*i*(2*this.damping+i*t));let r=1/(1+this.gamma),o=t*i*i*this.gamma;this.gamma*=r,this.kMass*=r,this.bias=-s*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,l=this.jAcc;return this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&(this.jAcc>this.jMax||this.jAcc<-this.jMax)?!0:(this.stiff||(this.jAcc>this.jMax?this.jAcc=this.jMax:this.jAcc<-this.jMax&&(this.jAcc=-this.jMax)),n=this.jAcc-l,this.b1.angvel-=this.scale*this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*n,!1)}applyImpulsePos(){let t=this.ratio*this.b2.rot-this.b1.rot,n;this.equal?(t-=this.jointMax,n=!1,this.scale=1):t<this.jointMin?(t=this.jointMin-t,this.scale=-1,n=!1):t>this.jointMax?(t-=this.jointMax,this.scale=1,n=!1):(this.scale=0,t=0,n=!0);let l=t;if(!n){if(this.breakUnderError&&l*l>this.maxError*this.maxError)return!0;let i=-(l*.5)*this.kMass;if(this.equal||i<0){let r=this.b1,o=-this.scale*i*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,u=1-.5*c,h=1-c*c/8,x=(u*r.axisx+o*r.axisy)*h;r.axisy=(u*r.axisy-o*r.axisx)*h,r.axisx=x}let a=this.b2,p=this.ratio*this.scale*i*this.b2.iinertia;if(a.rot+=p,p*p>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let c=p*p,u=1-.5*c,h=1-c*c/8,x=(u*a.axisx+p*a.axisy)*h;a.axisy=(u*a.axisy-p*a.axisx)*h,a.axisx=x}}}return!1}draw(t){}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let l=n*n,s=1-.5*l,i=1-l*l/8,r=(s*t.axisx+n*t.axisy)*i;t.axisy=(s*t.axisy-n*t.axisx)*i,t.axisx=r}}static _copyBody(t,n,l,s,i){if(t!=null&&l!=null){let r=null;for(let o=0;o<t.length;o++){let a=t[o];if(a.id==l.id){r=a.bc;break}}r!=null?s.zpp_inner_zn[i]=r.zpp_inner:n.push(_i.todo(l.id,function(o){s.zpp_inner_zn[i]=o.zpp_inner}))}}};fl.__name__=["zpp_nape","constraint","ZPP_AngleJoint"],fl._wrapFn=null,fl._createFn=null;var We=fl;var Gt=class Gt{constructor(){this.x=0;this.y=0;this.next=null;this.length=0;this.modified=!1;this.pushmod=!1;this._inuse=!1;this.weak=!1;this.outer=null;this._immutable=!1;this._isimmutable=null;this._validate=null;this._invalidate=null}static get(e,t,n){n==null&&(n=!1);let l;return Gt.zpp_pool==null?l=new Gt:(l=Gt.zpp_pool,Gt.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=n,l.x=e,l.y=t,l}validate(){this._validate!=null&&this._validate()}invalidate(){this._invalidate!=null&&this._invalidate(this)}immutable(){if(this._immutable)throw new Error("Error: Vec2 is immutable");this._isimmutable!=null&&this._isimmutable()}wrapper(){if(this.outer==null)if(Gt._wrapFn)this.outer=Gt._wrapFn(this);else{this.outer=new Gt._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=Gt.zpp_pool,Gt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this._isimmutable=null,this._validate=null,this._invalidate=null}alloc(){this.weak=!1}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}inlined_add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;)this.add(t),t=t.next}insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}inlined_insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let l;t==null?(l=this.next,this.next=l.next,this.next==null&&(this.pushmod=!0)):(l=t.next,t.next=l.next,l.next==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e)return this.erase(t),!0;t=n,n=n.next}return!1}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let l;t==null?(l=this.next,this.next=l.next,this.next==null&&(this.pushmod=!0)):(l=t.next,t.next=l.next,l.next==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let l;return t==null?(l=this.next,this.next=l.next,this.next==null&&(this.pushmod=!0)):(l=t.next,t.next=l.next,l.next==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,!0}t=n,n=n.next}return!1}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=this.next;for(;t!=null;){if(t===e)return!0;t=t.next}return!1}inlined_has(e){let t=this.next;for(;t!=null;){if(t===e)return!0;t=t.next}return!1}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}copy(){let e=this.x,t=this.y,n;return Gt.zpp_pool==null?n=new Gt:(n=Gt.zpp_pool,Gt.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+" }"}};Gt.zpp_pool=null,Gt.__name__=["zpp_nape","geom","ZPP_Vec2"],Gt._nape=null,Gt._zpp=null,Gt._wrapFn=null;var ie=Gt;var ji=class ji extends Ze{constructor(){super();this.outer_zn=null;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.nx=0;this.ny=0;this.cx1=0;this.cx2=0;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a1=null;this.wrap_a2=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),l=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),s=n*n+l*l;return s<Ze._nape.Config.epsilon?t=!0:(s=Math.sqrt(s),this.equal||s<this.jointMin||s>this.jointMax?t=!1:t=!0),t}bodyImpulse(t){let n=Ze._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAcc*this.nx,-this.jAcc*this.ny,-this.cx1*this.jAcc):n.geom.Vec3.get(this.jAcc*this.nx,this.jAcc*this.ny,this.cx2*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){this.wrap_a1=ji._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=ji._setupAnchorVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let r=ji._createFn(null,null,s,i.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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.nx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.ny=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely);let l=this.nx*this.nx+this.ny*this.ny;if(l<Ze._nape.Config.epsilon)this.nx=0,this.ny=0,l=0,this.slack=!0;else{l=Math.sqrt(l);let i=1/l;this.nx*=i,this.ny*=i,this.equal?(l-=this.jointMax,this.slack=!1):l<this.jointMin?(l=this.jointMin-l,this.nx=-this.nx,this.ny=-this.ny,this.slack=!1):l>this.jointMax?(l-=this.jointMax,this.slack=!1):(this.nx=0,this.ny=0,l=0,this.slack=!0)}let s=l;if(!this.slack){if(this.cx1=this.ny*this.a1relx-this.nx*this.a1rely,this.cx2=this.ny*this.a2relx-this.nx*this.a2rely,this.kMass=this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&s*s>this.maxError*this.maxError)return!0;let i=2*Math.PI*this.frequency;this.gamma=1/(t*i*(2*this.damping+i*t));let r=1/(1+this.gamma),o=t*i*i*this.gamma;this.gamma*=r,this.kMass*=r,this.bias=-s*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,l=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-l;let s=this.b1.imass*n;this.b1.velx-=this.nx*s,this.b1.vely-=this.ny*s;let i=this.b2.imass*n;return this.b2.velx+=this.nx*i,this.b2.vely+=this.ny*i,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,!1}applyImpulsePos(){let t,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,s=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,i=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r,o=this.b2.posx+s-(this.b1.posx+n),a=this.b2.posy+i-(this.b1.posy+l),p=o*o+a*a;if(p<Ze._nape.Config.epsilon)o=0,a=0,p=0,r=!0;else{p=Math.sqrt(p);let u=1/p;o*=u,a*=u,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<Ze._nape.Config.constraintLinearSlop*Ze._nape.Config.constraintLinearSlop)return!1;if(c*=.5,c*c>6){let f=this.b1.smass+this.b2.smass;if(f>Ze._nape.Config.epsilon){let _=.75/f;if(t=-c*_,this.equal||t<0){let d=t*this.b1.imass;this.b1.posx-=o*d,this.b1.posy-=a*d;let b=t*this.b2.imass;this.b2.posx+=o*b,this.b2.posy+=a*b,o=this.b2.posx+s-(this.b1.posx+n),a=this.b2.posy+i-(this.b1.posy+l);let m=o*o+a*a;if(m<Ze._nape.Config.epsilon)o=0,a=0,m=0;else{m=Math.sqrt(m);let z=1/m;o*=z,a*=z,this.equal?m-=this.jointMax:m<this.jointMin?(m=this.jointMin-m,o=-o,a=-a):m>this.jointMax?m-=this.jointMax:(o=0,a=0,m=0)}c=m,c*=.5}}}let u=a*n-o*l,h=a*s-o*i,x=this.b1.smass+this.b2.smass+u*u*this.b1.sinertia+h*h*this.b2.sinertia;if(x!=0&&(x=1/x),t=-c*x,this.equal||t<0){let f=this.b1.imass*t;this.b1.posx-=o*f,this.b1.posy-=a*f;let _=this.b2.imass*t;this.b2.posx+=o*_,this.b2.posy+=a*_,We._rotateBody(this.b1,-u*this.b1.iinertia*t),We._rotateBody(this.b2,h*this.b2.iinertia*t)}}return!1}draw(t){}static _setupAnchorVec2(t,n,l,s){let i=Ze._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 i.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;ie.zpp_pool==null?p=new ie:(p=ie.zpp_pool,ie.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 u=a.zpp_inner;if(u._validate!=null&&u._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 h=a.zpp_inner;h._validate!=null&&h._validate(),c=a.zpp_inner.y==o}else c=!1;if(!c){a.zpp_inner.x=r,a.zpp_inner.y=o;let h=a.zpp_inner;h._invalidate!=null&&h._invalidate(h)}}return a.zpp_inner.weak=!1,a.zpp_inner._inuse=!0,a.zpp_inner._validate=l,a.zpp_inner._invalidate=s,a}};ji.__name__=["zpp_nape","constraint","ZPP_DistanceJoint"],ji.__super__=Ze,ji._wrapFn=null,ji._createFn=null;var xi=ji;var Ss=class Ss extends Ze{constructor(){super();this.outer_zn=null;this.scale=0;this.jointMin=0;this.jointMax=0;this.equal=!1;this.dot1=0;this.dot2=0;this.cx1=0;this.cx2=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.zip_n=null;this.nlocalx=0;this.nlocaly=0;this.nrelx=0;this.nrely=0;this.wrap_n=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.jAccx=0;this.jAccy=0;this.jMax=null;this.gamma=null;this.biasx=0;this.biasy=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.nlocalx=0,this.nlocaly=0,this.nrelx=0,this.nrely=0,this.jAccx=0,this.jAccy=0,this.jMax=1/0,this.jointMin=-1/0,this.jointMax=1/0,this.stepped=!1}_setupVec2(t,n,l,s){let i=Ze._nape,r=Ze._zpp;if(n==null&&(n=0),t==null&&(t=0),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");let o;if(r.util.ZPP_PubPool.poolVec2==null?o=new i.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 u=o.zpp_inner;u._validate!=null&&u._validate(),c=o.zpp_inner.y==n}else c=!1;if(!c){o.zpp_inner.x=t,o.zpp_inner.y=n;let u=o.zpp_inner;u._invalidate!=null&&u._invalidate(u)}}return o.zpp_inner.weak=!1,o.zpp_inner._inuse=!0,o.zpp_inner._validate=l,o.zpp_inner._invalidate=s,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,l=1/Math.sqrt(t);this.nlocalx*=l,this.nlocaly*=l}}bodyImpulse(t){let n=Ze._nape;if(this.stepped){let l=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,s=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy;return t==this.b1?n.geom.Vec3.get(-l,-s,this.scale*this.cx1*s-this.dot1*l):n.geom.Vec3.get(l,s,this.scale*this.cx1*s-this.dot1*l)}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let r=i.zpp_inner_zn.wrap_a2,o=this.outer_zn;o.zpp_inner_zn.wrap_n==null&&o.zpp_inner_zn.setup_n();let a=Ss._createFn(null,null,s,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=Ze._nape;if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.nlocalx*this.nlocalx+this.nlocaly*this.nlocaly<t.Config.epsilon)throw new Error("Error: DistanceJoint direction must be non-degenerate");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.equal=this.jointMin==this.jointMax,this.stepped=!0,this.validate_norm(),this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.nrelx=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,this.nrely=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let l=this.b2.posx+this.a2relx-this.b1.posx-this.a1relx,s=this.b2.posy+this.a2rely-this.b1.posy-this.a1rely,i=s*this.nrelx-l*this.nrely,r=this.nrelx*l+this.nrely*s;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=l+this.a1relx,a=s+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 h=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,h|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,h|=2),this.kMassb=0,c=h}else{let h=1/p,x=this.kMassc*h;this.kMassc=this.kMassa*h,this.kMassa=x,this.kMassb*=-h,c=0}if((c&1)!=0&&(this.jAccx=0),(c&2)!=0&&(this.jAccy=0),this.stiff)this.gamma=0,this.biasx=0,this.biasy=0;else{if(this.breakUnderError&&i*i+r*r>this.maxError*this.maxError)return!0;let h=2*Math.PI*this.frequency;this.gamma=1/(t*h*(2*this.damping+h*t));let x=1/(1+this.gamma),f=t*h*h*this.gamma;this.gamma*=x;let _=x;this.kMassa*=_,this.kMassb*=_,this.kMassc*=_,this.biasx=i,this.biasy=r;let d=-f;this.biasx*=d,this.biasy*=d;let b=this.maxError,m=this.biasx*this.biasx+this.biasy*this.biasy;if(m>b*b){let z=b*(1/Math.sqrt(m));this.biasx*=z,this.biasy*=z}}let u=n;return this.jAccx*=u,this.jAccy*=u,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,n=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy,l=this.b1.imass;this.b1.velx-=t*l,this.b1.vely-=n*l;let s=this.b2.imass;this.b2.velx+=t*s,this.b2.vely+=n*s,this.b1.angvel+=(this.scale*this.cx1*this.jAccy-this.dot1*this.jAccx)*this.b1.iinertia,this.b2.angvel+=(this.dot2*this.jAccx-this.scale*this.cx2*this.jAccy)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx-this.b1.velx,n=this.b2.vely-this.b1.vely;t+=this.b2.kinvelx-this.b1.kinvelx,n+=this.b2.kinvely-this.b1.kinvely;let l=n*this.nrelx-t*this.nrely+(this.b2.angvel+this.b2.kinangvel)*this.dot2-(this.b1.angvel+this.b1.kinangvel)*this.dot1,s=this.scale*(this.nrelx*t+this.nrely*n-(this.b2.angvel+this.b2.kinangvel)*this.cx2+(this.b1.angvel+this.b1.kinangvel)*this.cx1),i=this.biasx-l,r=this.biasy-s,o=this.kMassa*i+this.kMassb*r;r=this.kMassb*i+this.kMassc*r,i=o;let a=this.gamma;i-=this.jAccx*a,r-=this.jAccy*a;let p=this.jAccx,c=this.jAccy;if(this.jAccx+=i,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 b=this.jMax,m=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(m>b*b){let z=b*(1/Math.sqrt(m));this.jAccx*=z,this.jAccy*=z}}let u=this.jAccx-p,h=this.jAccy-c,x=this.scale*this.nrelx*h-this.nrely*u,f=this.nrelx*u+this.scale*this.nrely*h,_=this.b1.imass;this.b1.velx-=x*_,this.b1.vely-=f*_;let d=this.b2.imass;return this.b2.velx+=x*d,this.b2.vely+=f*d,this.b1.angvel+=(this.scale*this.cx1*h-this.dot1*u)*this.b1.iinertia,this.b2.angvel+=(this.dot2*u-this.scale*this.cx2*h)*this.b2.iinertia,!1}applyImpulsePos(){let t=Ze._nape,n=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,l=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,s=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,i=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,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-s,p=this.b2.posy+o-this.b1.posy-i,c,u=p*n-a*l,h=n*a+l*p;if(this.equal?(h-=this.jointMin,c=1):h>this.jointMax?(h-=this.jointMax,c=1):h<this.jointMin?(h=this.jointMin-h,c=-1):(h=0,c=0),this.breakUnderError&&u*u+h*h>this.maxError*this.maxError)return!0;if(u*u+h*h<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let x,f,_=.5;if(u*=_,h*=_,u*u+h*h>6){let C=this.b1.smass+this.b2.smass;if(C>t.Config.epsilon){let F=.8/C,O=F*(l*u-c*n*h),B=F*(n*u*c-l*u),D=this.b1.imass;this.b1.posx-=O*D,this.b1.posy-=B*D;let U=this.b2.imass;this.b2.posx+=O*U,this.b2.posy+=B*U,a=this.b2.posx+r-this.b1.posx-s,p=this.b2.posy+o-this.b1.posy-i,u=p*n-a*l,h=n*a+l*p,this.equal?(h-=this.jointMin,c=1):h>this.jointMax?(h-=this.jointMax,c=1):h<this.jointMin?(h=this.jointMin-h,c=-1):(h=0,c=0);let W=.5;u*=W,h*=W}}let d=a+s,b=p+i,m=n*d+l*b,z=b*n-d*l,M=n*r+l*o,y=o*n-r*l,w=this.b1.smass+this.b2.smass+m*m*this.b1.sinertia+M*M*this.b2.sinertia,v=-c*(m*z*this.b1.sinertia+M*y*this.b2.sinertia),P=c*c*(this.b1.smass+this.b2.smass+z*z*this.b1.sinertia+y*y*this.b2.sinertia);x=-u,f=-h;let g=w*P-v*v;if(g!==g)f=0,x=f;else if(g==0)w!=0?x/=w:x=0,P!=0?f/=P:f=0;else{let C=1/g,F=C*(P*x-v*f);f=C*(w*f-v*x),x=F}f>0&&(f=0);let E=c*n*f-l*x,N=n*x+c*l*f,k=this.b1.imass;this.b1.posx-=E*k,this.b1.posy-=N*k;let Z=this.b2.imass;return this.b2.posx+=E*Z,this.b2.posy+=N*Z,We._rotateBody(this.b1,(c*z*f-m*x)*this.b1.iinertia),We._rotateBody(this.b2,(M*x-c*y*f)*this.b2.iinertia),!1}draw(t){}};Ss.__name__=["zpp_nape","constraint","ZPP_LineJoint"],Ss.__super__=Ze,Ss._wrapFn=null,Ss._createFn=null;var di=Ss;var bl=class bl extends Ze{constructor(){super();this.outer_zn=null;this.ratio=0;this.rate=0;this.b1=null;this.b2=null;this.kMass=0;this.jAcc=0;this.jMax=0;this.stepped=!1;this.jAcc=0,this.stepped=!1,this.__velocity=!0}bodyImpulse(t){let n=oe();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let l=bl._createFn(null,null,this.rate,this.ratio);if(this.copyto(l),t!=null&&this.b1!=null){let s=null,i=0;for(;i<t.length;){let r=t[i];if(++i,r.id==this.b1.id){s=r.bc;break}}s!=null?l.zpp_inner.b1=s.zpp_inner:n.push(_i.todo(this.b1.id,r=>{l.zpp_inner.b1=r.zpp_inner}))}if(t!=null&&this.b2!=null){let s=null,i=0;for(;i<t.length;){let r=t[i];if(++i,r.id==this.b2.id){s=r.bc;break}}s!=null?l.zpp_inner.b2=s.zpp_inner:n.push(_i.todo(this.b2.id,r=>{l.zpp_inner.b2=r.zpp_inner}))}return l}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: MotorJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let l=this.b1.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let l=this.b2.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;return this.pre_dt=t,this.stepped=!0,this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass=1/this.kMass,this.jAcc*=n,this.jMax=this.maxForce*t,!1}warmStart(){this.b1.angvel-=this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.b2.iinertia*this.jAcc}applyImpulseVel(){let t=this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel-this.rate,n=-this.kMass*t,l=this.jAcc;if(this.jAcc+=n,this.breakUnderForce){if(this.jAcc>this.jMax||this.jAcc<-this.jMax)return!0}else this.jAcc<-this.jMax?this.jAcc=-this.jMax:this.jAcc>this.jMax&&(this.jAcc=this.jMax);return n=this.jAcc-l,this.b1.angvel-=this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.b2.iinertia*n,!1}applyImpulsePos(){return!1}};bl.__name__=["zpp_nape","constraint","ZPP_MotorJoint"],bl._wrapFn=null,bl._createFn=null;var yi=bl;var As=class As extends Ze{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.jAccx=0;this.jAccy=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.stepped=!1;this.stepped=!1,this.jAccx=0,this.jAccy=0,this.jMax=1/0,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0}bodyImpulse(t){let n=Ze._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAccx,-this.jAccy,-(this.jAccy*this.a1relx-this.jAccx*this.a1rely)):n.geom.Vec3.get(this.jAccx,this.jAccy,this.jAccy*this.a2relx-this.jAccx*this.a2rely):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){let t=Ze._nape,n=Ze._zpp,l=this.a1localx,s=this.a1localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let 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=l,r.y=s,i.zpp_inner=r,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 r=i.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),o=i.zpp_inner.y==s}else o=!1;if(!o){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a1=i,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=Ze._nape,n=Ze._zpp,l=this.a2localx,s=this.a2localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let 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=l,r.y=s,i.zpp_inner=r,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 r=i.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),o=i.zpp_inner.y==s}else o=!1;if(!o){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a2=i,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let r=As._createFn(null,null,s,i.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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let l=this.b1.smass+this.b2.smass;if(this.kMassa=l,this.kMassb=0,this.kMassc=l,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 s=this.kMassa*this.kMassc-this.kMassb*this.kMassb,i;if(s!=s)this.kMassa=this.kMassb=this.kMassc=0,i=3;else if(s==0){let 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,i=o}else{let o=1/s,a=this.kMassc*o;this.kMassc=this.kMassa*o,this.kMassa=a,this.kMassb*=-o,i=0}if((i&1)!=0&&(this.jAccx=0),(i&2)!=0&&(this.jAccy=0),this.stiff)this.biasx=0,this.biasy=0,this.gamma=0;else{let 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 u=-p;this.biasx*=u,this.biasy*=u;let h=this.maxError,x=this.biasx*this.biasx+this.biasy*this.biasy;if(x>h*h){let f=h*(1/Math.sqrt(x));this.biasx*=f,this.biasy*=f}}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)),l=this.biasx-t,s=this.biasy-n,i=this.kMassa*l+this.kMassb*s;s=this.kMassb*l+this.kMassc*s,l=i;let r=this.gamma;l-=this.jAccx*r,s-=this.jAccy*r;let o=this.jAccx,a=this.jAccy,p=1;if(this.jAccx+=l*p,this.jAccy+=s*p,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let h=this.jMax,x=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(x>h*h){let f=h*(1/Math.sqrt(x));this.jAccx*=f,this.jAccy*=f}}l=this.jAccx-o,s=this.jAccy-a;let c=this.b1.imass;this.b1.velx-=l*c,this.b1.vely-=s*c;let u=this.b2.imass;return this.b2.velx+=l*u,this.b2.vely+=s*u,this.b1.angvel-=(s*this.a1relx-l*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(s*this.a2relx-l*this.a2rely)*this.b2.iinertia,!1}applyImpulsePos(){let t=Ze._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,s=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,i=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b2.posx+s-(this.b1.posx+n),o=this.b2.posy+i-(this.b1.posy+l);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 w=this.b1.smass+this.b2.smass;if(w>t.Config.epsilon){let v=.75/w;p=-r*v,c=-o*v;let P=20,g=p*p+c*c;if(g>P*P){let Z=P*(1/Math.sqrt(g));p*=Z,c*=Z}let E=this.b1.imass;this.b1.posx-=p*E,this.b1.posy-=c*E;let N=this.b2.imass;this.b2.posx+=p*N,this.b2.posy+=c*N,r=this.b2.posx+s-(this.b1.posx+n),o=this.b2.posy+i-(this.b1.posy+l);let k=.5;r*=k,o*=k}}let u=this.b1.smass+this.b2.smass,h=u,x=0,f=u;if(this.b1.sinertia!=0){let w=n*this.b1.sinertia,v=l*this.b1.sinertia;h+=v*l,x+=-v*n,f+=w*n}if(this.b2.sinertia!=0){let w=s*this.b2.sinertia,v=i*this.b2.sinertia;h+=v*i,x+=-v*s,f+=w*s}p=-r,c=-o;let _=6,d=p*p+c*c;if(d>_*_){let w=_*(1/Math.sqrt(d));p*=w,c*=w}let b=h*f-x*x;if(b!=b)c=0,p=0;else if(b==0)h!=0?p/=h:p=0,f!=0?c/=f:c=0;else{let w=1/b,v=w*(f*p-x*c);c=w*(h*c-x*p),p=v}let m=this.b1.imass;this.b1.posx-=p*m,this.b1.posy-=c*m;let z=this.b2.imass;this.b2.posx+=p*z,this.b2.posy+=c*z;let M=-(c*n-p*l)*this.b1.iinertia;We._rotateBody(this.b1,M);let y=(c*s-p*i)*this.b2.iinertia;return We._rotateBody(this.b2,y),!1}draw(t){}};As.__name__=["zpp_nape","constraint","ZPP_PivotJoint"],As.__super__=Ze,As._wrapFn=null,As._createFn=null;var mi=As;var Vs=class Vs extends Ze{constructor(){super();this.outer_zn=null;this.ratio=1;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.n12x=0;this.n12y=0;this.n34x=0;this.n34y=0;this.cx1=0;this.cx2=0;this.cx3=0;this.cx4=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.b3=null;this.a3localx=0;this.a3localy=0;this.a3relx=0;this.a3rely=0;this.wrap_a3=null;this.b4=null;this.a4localx=0;this.a4localy=0;this.a4relx=0;this.a4rely=0;this.wrap_a4=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.a3localx=0,this.a3localy=0,this.a3relx=0,this.a3rely=0,this.a4localx=0,this.a4localy=0,this.a4relx=0,this.a4rely=0,this.n12x=1,this.n12y=0,this.n34x=1,this.n34y=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=this.cx3=this.cx4=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),l=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),s=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),i=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),r=Math.sqrt(n*n+l*l),o=Math.sqrt(s*s+i*i),a=r+this.ratio*o;return this.equal||a<this.jointMin||a>this.jointMax?t=!1:t=!0,t}bodyImpulse(t){let n=Ze._nape;if(this.stepped){let l=n.geom.Vec3.get();return t==this.b1&&(l.zpp_inner.x=l.zpp_inner.x-this.jAcc*this.n12x,l.zpp_inner.y=l.zpp_inner.y-this.jAcc*this.n12y,l.zpp_inner.z=l.zpp_inner.z-this.cx1*this.jAcc),t==this.b2&&(l.zpp_inner.x=l.zpp_inner.x+this.jAcc*this.n12x,l.zpp_inner.y=l.zpp_inner.y+this.jAcc*this.n12y,l.zpp_inner.z=l.zpp_inner.z+this.cx2*this.jAcc),t==this.b3&&(l.zpp_inner.x=l.zpp_inner.x-this.jAcc*this.n34x,l.zpp_inner.y=l.zpp_inner.y-this.jAcc*this.n34y,l.zpp_inner.z=l.zpp_inner.z-this.cx3*this.jAcc),t==this.b4&&(l.zpp_inner.x=l.zpp_inner.x+this.jAcc*this.n34x,l.zpp_inner.y=l.zpp_inner.y+this.jAcc*this.n34y,l.zpp_inner.z=l.zpp_inner.z+this.cx4*this.jAcc),l}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this),this.b3!=this.b1&&this.b3!=this.b2&&this.b3!=null&&this.b3.constraints.add(this),this.b4!=this.b1&&this.b4!=this.b2&&this.b4!=this.b3&&this.b4!=null&&this.b4.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this),this.b3!=this.b1&&this.b3!=this.b2&&this.b3!=null&&this.b3.constraints.remove(this),this.b4!=this.b1&&this.b4!=this.b2&&this.b4!=this.b3&&this.b4!=null&&this.b4.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){let t=Ze._nape,n=Ze._zpp,l=this.a1localx,s=this.a1localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let 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=l,r.y=s,i.zpp_inner=r,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 r=i.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),o=i.zpp_inner.y==s}else o=!1;if(!o){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a1=i,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=Ze._nape,n=Ze._zpp,l=this.a2localx,s=this.a2localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let 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=l,r.y=s,i.zpp_inner=r,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 r=i.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),o=i.zpp_inner.y==s}else o=!1;if(!o){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a2=i,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}validate_a3(){this.wrap_a3.zpp_inner.x=this.a3localx,this.wrap_a3.zpp_inner.y=this.a3localy}invalidate_a3(t){this.immutable_midstep("Constraint::a3"),this.a3localx=t.x,this.a3localy=t.y,this.wake()}setup_a3(){let t=Ze._nape,n=Ze._zpp,l=this.a3localx,s=this.a3localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let 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=l,r.y=s,i.zpp_inner=r,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 r=i.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),o=i.zpp_inner.y==s}else o=!1;if(!o){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a3=i,this.wrap_a3.zpp_inner._inuse=!0,this.wrap_a3.zpp_inner._validate=this.validate_a3.bind(this),this.wrap_a3.zpp_inner._invalidate=this.invalidate_a3.bind(this)}validate_a4(){this.wrap_a4.zpp_inner.x=this.a4localx,this.wrap_a4.zpp_inner.y=this.a4localy}invalidate_a4(t){this.immutable_midstep("Constraint::a4"),this.a4localx=t.x,this.a4localy=t.y,this.wake()}setup_a4(){let t=Ze._nape,n=Ze._zpp,l=this.a4localx,s=this.a4localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let 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=l,r.y=s,i.zpp_inner=r,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 r=i.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),o=i.zpp_inner.y==s}else o=!1;if(!o){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a4=i,this.wrap_a4.zpp_inner._inuse=!0,this.wrap_a4.zpp_inner._validate=this.validate_a4.bind(this),this.wrap_a4.zpp_inner._invalidate=this.invalidate_a4.bind(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let r=i.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=Vs._createFn(null,null,null,null,s,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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component),this.b3.type==2&&Ze._unionComponents(this.b3.component,this.component),this.b4.type==2&&Ze._unionComponents(this.b4.component,this.component)}pair_exists(t,n){return this.b1.id==t&&(this.b2.id==n||this.b3.id==n||this.b4.id==n)||this.b2.id==t&&(this.b3.id==n||this.b4.id==n||this.b1.id==n)||this.b3.id==t&&(this.b4.id==n||this.b1.id==n||this.b2.id==n)?!0:this.b4.id==t?this.b1.id==n||this.b2.id==n?!0:this.b3.id==n:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let l=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),r=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),o=Math.sqrt(l*l+s*s),a=Math.sqrt(i*i+r*r);if(o!=0){let u=1/o;this.n12x=l*u,this.n12y=s*u}if(a!=0){let u=1/a;this.n34x=i*u,this.n34y=r*u;let h=this.ratio;this.n34x*=h,this.n34y*=h}else{let u=this.ratio/Math.sqrt(this.n34x*this.n34x+this.n34y*this.n34y);this.n34x*=u,this.n34y*=u}let p=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 u=this.ratio*this.ratio,h=this.b1.smass+this.b2.smass+u*(this.b3.smass+this.b4.smass)+this.b1.sinertia*this.cx1*this.cx1+this.b2.sinertia*this.cx2*this.cx2+this.b3.sinertia*this.cx3*this.cx3+this.b4.sinertia*this.cx4*this.cx4;if(this.b1==this.b4&&(h-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx4*this.b1.sinertia)),this.b1==this.b3&&(h+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx3*this.b1.sinertia)),this.b2==this.b3&&(h-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx3*this.b2.sinertia)),this.b2==this.b4&&(h+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx4*this.b2.sinertia)),this.kMass=h,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;let x=2*Math.PI*this.frequency;this.gamma=1/(t*x*(2*this.damping+x*t));let f=1/(1+this.gamma),_=t*x*x*this.gamma;this.gamma*=f,this.kMass*=f,this.bias=-c*_,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.n12x*t,this.b1.vely-=this.n12y*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.n12x*n,this.b2.vely+=this.n12y*n;let l=this.b3.imass*this.jAcc;this.b3.velx-=this.n34x*l,this.b3.vely-=this.n34y*l;let s=this.b4.imass*this.jAcc;this.b4.velx+=this.n34x*s,this.b4.vely+=this.n34y*s,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc,this.b3.angvel-=this.cx3*this.b3.iinertia*this.jAcc,this.b4.angvel+=this.cx4*this.b4.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.n12x*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.n12y*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+this.n34x*(this.b4.velx+this.b4.kinvelx-this.b3.velx-this.b3.kinvelx)+this.n34y*(this.b4.vely+this.b4.kinvely-this.b3.vely-this.b3.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1+(this.b4.angvel+this.b4.kinangvel)*this.cx4-(this.b3.angvel+this.b3.kinangvel)*this.cx3,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,l=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-l;let s=this.b1.imass*n;this.b1.velx-=this.n12x*s,this.b1.vely-=this.n12y*s;let i=this.b2.imass*n;this.b2.velx+=this.n12x*i,this.b2.vely+=this.n12y*i;let 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=Ze._nape,n,l=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,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,u,h=this.n12x,x=this.n12y,f=this.n34x,_=this.n34y,d=this.b2.posx+i-(this.b1.posx+l),b=this.b2.posy+r-(this.b1.posy+s),m=this.b4.posx+p-(this.b3.posx+o),z=this.b4.posy+c-(this.b3.posy+a),M=Math.sqrt(d*d+b*b),y=Math.sqrt(m*m+z*z);if(M!=0){let P=1/M;h=d*P,x=b*P}if(y!=0){let P=1/y;f=m*P,_=z*P;let g=this.ratio;f*=g,_*=g}else{let P=this.ratio/Math.sqrt(f*f+_*_);f*=P,_*=P}let w=M+this.ratio*y;this.equal?(w-=this.jointMax,u=!1):w<this.jointMin?(w=this.jointMin-w,h=-h,x=-x,f=-f,_=-_,u=!1):w>this.jointMax?(w-=this.jointMax,u=!1):(h=0,x=0,f=0,_=0,w=0,u=!0);let v=w;if(!u){if(this.breakUnderError&&v*v>this.maxError*this.maxError)return!0;if(v*v<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;if(v*=.5,v*v>6){let F=this.b1.smass+this.b2.smass;if(F>t.Config.epsilon){let O=.75/F;if(n=-v*O,this.equal||n<0){let B=n*this.b1.imass;this.b1.posx-=h*B,this.b1.posy-=x*B;let D=n*this.b2.imass;this.b2.posx+=h*D,this.b2.posy+=x*D;let U=n*this.b3.imass;this.b3.posx-=f*U,this.b3.posy-=_*U;let W=n*this.b4.imass;this.b4.posx+=f*W,this.b4.posy+=_*W;let q=this.b2.posx+i-(this.b1.posx+l),L=this.b2.posy+r-(this.b1.posy+s),A=this.b4.posx+p-(this.b3.posx+o),J=this.b4.posy+c-(this.b3.posy+a),$=Math.sqrt(q*q+L*L),X=Math.sqrt(A*A+J*J);if($!=0){let ee=1/$;h=q*ee,x=L*ee}if(X!=0){let ee=1/X;f=A*ee,_=J*ee;let G=this.ratio;f*=G,_*=G}else{let ee=this.ratio/Math.sqrt(f*f+_*_);f*=ee,_*=ee}let H=$+this.ratio*X;this.equal?H-=this.jointMax:H<this.jointMin?(H=this.jointMin-H,h=-h,x=-x,f=-f,_=-_):H>this.jointMax?H-=this.jointMax:(h=0,x=0,f=0,_=0,H=0),v=H,v*=.5}}}let P=x*l-h*s,g=x*i-h*r,E=_*o-f*a,N=_*p-f*c,k=this.ratio*this.ratio,Z=this.b1.smass+this.b2.smass+k*(this.b3.smass+this.b4.smass)+this.b1.sinertia*P*P+this.b2.sinertia*g*g+this.b3.sinertia*E*E+this.b4.sinertia*N*N;this.b1==this.b4&&(Z-=2*((h*f+x*_)*this.b1.smass+P*N*this.b1.sinertia)),this.b1==this.b3&&(Z+=2*((h*f+x*_)*this.b1.smass+P*E*this.b1.sinertia)),this.b2==this.b3&&(Z-=2*((h*f+x*_)*this.b2.smass+g*E*this.b2.sinertia)),this.b2==this.b4&&(Z+=2*((h*f+x*_)*this.b2.smass+g*N*this.b2.sinertia));let C=Z;if(C!=0&&(C=1/C),n=-v*C,this.equal||n<0){let F=this.b1.imass*n;this.b1.posx-=h*F,this.b1.posy-=x*F;let O=this.b2.imass*n;this.b2.posx+=h*O,this.b2.posy+=x*O;let B=this.b3.imass*n;this.b3.posx-=f*B,this.b3.posy-=_*B;let D=this.b4.imass*n;this.b4.posx+=f*D,this.b4.posy+=_*D,We._rotateBody(this.b1,-P*this.b1.iinertia*n),We._rotateBody(this.b2,g*this.b2.iinertia*n),We._rotateBody(this.b3,-E*this.b3.iinertia*n),We._rotateBody(this.b4,N*this.b4.iinertia*n)}}return!1}draw(t){}};Vs.__name__=["zpp_nape","constraint","ZPP_PulleyJoint"],Vs.__super__=Ze,Vs._wrapFn=null,Vs._createFn=null;var fi=Vs;var Is=class{constructor(e,t){this.cnt=0;this.body=null;this.cnt=e,this.body=t}};Is.__name__=["zpp_nape","constraint","ZPP_UserBody"];var wr=class wr extends Ze{constructor(t,n){super();this.outer_zn=null;this.bodies=null;this.dim=0;this.jAcc=null;this.bias=null;this.stepped=!1;this.L=null;this.y=null;this.soft=0;this.gamma=0;this.velonly=!1;this.jMax=0;this.Keff=null;this.vec3=null;this.J=null;this.jOld=null;this.__class__=wr;this.bodies=[],this.dim=t,this.velonly=n,this.jAcc=[],this.bias=[],this.L=[],this.J=[],this.jOld=[],this.y=[],this.Keff=[],this.vec3=Ze._nape.geom.Vec3.get(0,0,0);for(let l=0;l<t;l++){let s=this.bias[l]=this.J[l]=this.jOld[l]=this.y[l]=0;this.jAcc[l]=s;for(let i=0;i<t;i++)this.L[l*t+i]=0}this.stepped=!1}bindVec2_invalidate(t){this.outer_zn.__invalidate()}addBody(t){let n=null;for(let l of this.bodies)if(l.body===t){n=l;break}n===null?(this.bodies.push(new Is(1,t)),this.active&&this.space!=null&&t?.constraints.add(this)):n.cnt++}remBody(t){let n=null,l=this.bodies.length|0,s=0;for(;s<l;){let i=this.bodies[s];if(i.body===t){i.cnt--,i.cnt===0&&(l>0&&(this.bodies[s]=this.bodies[l-1]),this.bodies.pop(),this.active&&this.space!=null&&t?.constraints.remove(this)),n=i;break}++s}return n!=null}bodyImpulse(t){for(let l=0;l<this.dim;l++)this.J[l]=this.jAcc[l];let n=Ze._nape.geom.Vec3.get(0,0,0);return this.stepped&&this.outer_zn.__impulse(this.J,t.outer,n),n}activeBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.add(this)}inactiveBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.remove(this)}copy(t,n){let l=this.outer_zn.__copy();throw this.copyto(l),new Error("not done yet")}validate(){for(let t of this.bodies)if(t.body.space!==this.space)throw new Error("Error: Constraints must have each body within the same sapce to which the constraint has been assigned");this.outer_zn.__validate()}wake_connected(){for(let t of this.bodies)t.body.type===2&&t.body.wake()}forest(){for(let t of this.bodies)if(t.body.type===2){let n;if(t.body.component===t.body.component.parent)n=t.body.component;else{let s=t.body.component,i=null;for(;s!==s.parent;){let r=s.parent;s.parent=i,i=s,s=r}for(;i!=null;){let r=i.parent;i.parent=s,i=r}n=s}let l;if(this.component===this.component.parent)l=this.component;else{let s=this.component,i=null;for(;s!==s.parent;){let r=s.parent;s.parent=i,i=s,s=r}for(;i!=null;){let r=i.parent;i.parent=s,i=r}l=s}n!==l&&(n.rank<l.rank?n.parent=l:n.rank>l.rank?l.parent=n:(l.parent=n,n.rank++))}}pair_exists(t,n){let l=!1,s=this.bodies.length|0;for(let i=0;i<s;i++){let r=this.bodies[i].body;for(let o=i+1;o<s;o++){let a=this.bodies[o].body;if(r.id===t&&a.id===n||r.id===n&&a.id===t){l=!0;break}}if(l)break}return l}broken(){this.outer_zn.__broken()}clearcache(){for(let t=0;t<this.dim;t++)this.jAcc[t]=0;this.pre_dt=-1}lsq(t){let n=0;for(let l=0;l<this.dim;l++)n+=t[l]*t[l];return n}_clamp(t,n){let l=this.lsq(t);if(l>n*n){let s=n/Math.sqrt(l);for(let i=0;i<this.dim;i++)t[i]*=s}}solve(t){let n=0;for(let l=0;l<this.dim;l++){let s=0;for(let r=0;r<l-1;r++)s+=this.L[l*this.dim+r]*this.L[l*this.dim+r];let i=Math.sqrt(t[n++]-s);if(this.L[l*this.dim+l]=i,i!==0){i=1/i;for(let r=l+1;r<this.dim;r++){let o=0;for(let a=0;a<l-1;a++)o+=this.L[r*this.dim+a]*this.L[l*this.dim+a];this.L[r*this.dim+l]=i*(t[n++]-o)}}else{for(let r=l+1;r<this.dim;r++)this.L[r*this.dim+l]=0;n+=this.dim-l-1}}return this.L}transform(t,n){for(let l=0;l<this.dim;l++){let s=n[l],i=t[l*this.dim+l];if(i!==0){for(let r=0;r<l;r++)s-=t[l*this.dim+r]*this.y[r];this.y[l]=s/i}else this.y[l]=0}for(let l=0;l<this.dim;l++){let s=this.dim-1-l,i=t[s*this.dim+s];if(i!==0){let r=this.y[s];for(let o=s+1;o<this.dim;o++)r-=t[o*this.dim+s]*n[o];n[s]=r/i}else n[s]=0}}preStep(t){this.pre_dt===-1&&(this.pre_dt=t);let n=t/this.pre_dt;if(this.pre_dt=t,this.stepped=!0,this.outer_zn.__prepare(),this.outer_zn.__eff_mass(this.Keff),this.L=this.solve(this.Keff),!this.stiff&&!this.velonly){let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let s=1/(1+this.gamma),i=t*l*l*this.gamma;if(this.gamma*=s,this.soft=s,this.outer_zn.__position(this.bias),this.breakUnderError&&this.lsq(this.bias)>this.maxError*this.maxError)return!0;for(let r=0;r<this.dim;r++)this.bias[r]*=-i;this._clamp(this.bias,this.maxError)}else{for(let l=0;l<this.dim;l++)this.bias[l]=0;this.gamma=0,this.soft=1}for(let l=0;l<this.dim;l++)this.jAcc[l]*=n;return this.jMax=this.maxForce*t,!1}warmStart(){for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.jAcc,n.outer,this.vec3);let l=n.imass,s=n,i=s.velx,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(),s.velx=i+r.zpp_inner.x*l;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let u=c.zpp_inner;u._validate!=null&&u._validate(),a.vely=p+c.zpp_inner.y*l;let h=n,x=h.angvel,f=this.vec3;if(f!=null&&f.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=f.zpp_inner;_._validate!=null&&_._validate(),h.angvel=x+f.zpp_inner.z*n.iinertia}}applyImpulseVel(){this.outer_zn.__velocity(this.J);for(let t=0;t<this.dim;t++)this.J[t]=this.bias[t]-this.J[t];this.transform(this.L,this.J);for(let t=0;t<this.dim;t++)this.jOld[t]=this.jAcc[t],this.jAcc[t]+=this.J[t]=this.J[t]*this.soft-this.jAcc[t]*this.gamma;if(this.outer_zn.__clamp(this.jAcc),(this.breakUnderForce||!this.stiff)&&this.lsq(this.jAcc)>this.jMax*this.jMax){if(this.breakUnderForce)return!0;this.stiff||this._clamp(this.jAcc,this.jMax)}for(let t=0;t<this.dim;t++)this.J[t]=this.jAcc[t]-this.jOld[t];for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.J,n.outer,this.vec3);let l=n.imass,s=n,i=s.velx,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(),s.velx=i+r.zpp_inner.x*l;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let u=c.zpp_inner;u._validate!=null&&u._validate(),a.vely=p+c.zpp_inner.y*l;let h=n,x=h.angvel,f=this.vec3;if(f!=null&&f.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=f.zpp_inner;_._validate!=null&&_._validate(),h.angvel=x+f.zpp_inner.z*n.iinertia}return!1}applyImpulsePos(){if(this.velonly)return!1;this.outer_zn.__prepare(),this.outer_zn.__position(this.J);let t=this.lsq(this.J);if(this.breakUnderError&&t>this.maxError*this.maxError)return!0;if(t<Ze._nape.Config.constraintLinearSlop*Ze._nape.Config.constraintLinearSlop)return!1;for(let n=0;n<this.dim;n++)this.J[n]*=-1;this.outer_zn.__eff_mass(this.Keff),this.transform(this.solve(this.Keff),this.J),this.outer_zn.__clamp(this.J);for(let n of this.bodies){let l=n.body;this.outer_zn.__impulse(this.J,l.outer,this.vec3);let s=l.imass,i=l,r=i.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(),i.posx=r+o.zpp_inner.x*s;let p=l,c=p.posy,u=this.vec3;if(u!=null&&u.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let h=u.zpp_inner;h._validate!=null&&h._validate(),p.posy=c+u.zpp_inner.y*s;let x=this.vec3;if(x!=null&&x.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let f=x.zpp_inner;f._validate!=null&&f._validate();let _=x.zpp_inner.z*l.iinertia;if(l.rot+=_,_*_>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let d=_*_,b=1-.5*d,m=1-d*d/8,z=(b*l.axisx+_*l.axisy)*m;l.axisy=(b*l.axisy-_*l.axisx)*m,l.axisx=z}}return!1}draw(t){this.outer_zn.__draw(t)}};wr.__name__=["zpp_nape","constraint","ZPP_UserConstraint"],wr.__super__=Ze;var Ts=wr;var Bs=class Bs extends Ze{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.phase=0;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.kMassd=0;this.kMasse=0;this.kMassf=0;this.jAccx=0;this.jAccy=0;this.jAccz=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.biasz=0;this.stepped=!1;this.phase=0,this.jAccx=0,this.jAccy=0,this.jAccz=0,this.jMax=1/0,this.stepped=!1,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0}bodyImpulse(t){let n=Ze._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAccx,-this.jAccy,-(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)):n.geom.Vec3.get(this.jAccx,this.jAccy,this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){let t=Ze._nape,n=Ze._zpp,l=this.a1localx,s=this.a1localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let 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=l,r.y=s,i.zpp_inner=r,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 r=i.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),o=i.zpp_inner.y==s}else o=!1;if(!o){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a1=i,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=Ze._nape,n=Ze._zpp,l=this.a2localx,s=this.a2localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let 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=l,r.y=s,i.zpp_inner=r,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 r=i.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),o=i.zpp_inner.y==s}else o=!1;if(!o){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a2=i,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let r=Bs._createFn(null,null,s,i.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&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.jAccz=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let l=this.b1.smass+this.b2.smass;if(this.kMassa=l,this.kMassb=0,this.kMassd=l,this.kMassc=0,this.kMasse=0,this.kMassf=0,this.b1.sinertia!=0){let 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 s=this.kMassa*(this.kMassd*this.kMassf-this.kMasse*this.kMasse)+this.kMassb*(this.kMassc*this.kMasse-this.kMassb*this.kMassf)+this.kMassc*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),i;if(s!=s)this.kMassa=0,this.kMassb=0,this.kMassd=0,this.kMassc=0,this.kMasse=0,this.kMassf=0,i=7;else if(s==0){let 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,i=r}else{let r=1/s,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),u=r*(this.kMassb*this.kMassc-this.kMassa*this.kMasse),h=r*(this.kMassa*this.kMassd-this.kMassb*this.kMassb);this.kMassa=o,this.kMassb=a,this.kMassd=p,this.kMassc=c,this.kMasse=u,this.kMassf=h,i=0}if((i&1)!=0&&(this.jAccx=0),(i&2)!=0&&(this.jAccy=0),(i&4)!=0&&(this.jAccz=0),this.stiff)this.biasx=0,this.biasy=0,this.biasz=0,this.gamma=0;else{let 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 u=this.maxError,h=this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz;if(h>u*u){let x=u*(1/Math.sqrt(h));this.biasx*=x,this.biasy*=x,this.biasz*=x}}return this.jAccx*=n,this.jAccy*=n,this.jAccz*=n,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),l=this.b2.angvel+this.b2.kinangvel-this.b1.angvel-this.b1.kinangvel,s=this.biasx-t,i=this.biasy-n,r=this.biasz-l,o=this.kMassa*s+this.kMassb*i+this.kMassc*r,a=this.kMassb*s+this.kMassd*i+this.kMasse*r;r=this.kMassc*s+this.kMasse*i+this.kMassf*r,s=o,i=a,s-=this.jAccx*this.gamma,i-=this.jAccy*this.gamma,r-=this.jAccz*this.gamma;let p=this.jAccx,c=this.jAccy,u=this.jAccz;if(this.jAccx+=s,this.jAccy+=i,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 f=this.jMax,_=this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz;if(_>f*f){let d=f*(1/Math.sqrt(_));this.jAccx*=d,this.jAccy*=d,this.jAccz*=d}}s=this.jAccx-p,i=this.jAccy-c,r=this.jAccz-u;let h=this.b1.imass;this.b1.velx-=s*h,this.b1.vely-=i*h;let x=this.b2.imass;return this.b2.velx+=s*x,this.b2.vely+=i*x,this.b1.angvel-=(i*this.a1relx-s*this.a1rely+r)*this.b1.iinertia,this.b2.angvel+=(i*this.a2relx-s*this.a2rely+r)*this.b2.iinertia,!1}applyImpulsePos(){let t=Ze._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,s=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,i=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b2.posx+s-(this.b1.posx+n),o=this.b2.posy+i-(this.b1.posy+l),a=this.b2.rot-this.b1.rot-this.phase,p,c,u;if(this.breakUnderError&&r*r+o*o+a*a>this.maxError*this.maxError)return!0;let h=!0;r*r+o*o<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(h=!1,r=0,o=0);let x=t.Config.constraintAngularSlop;if(a*a<x*x)if(h)a=0;else return!1;if(r*=.5,o*=.5,a*=.5,r*r+o*o>6){let O=this.b1.smass+this.b2.smass;if(O>t.Config.epsilon){let B=.75/O;p=-r*B,c=-o*B;let D=20,U=p*p+c*c;if(U>D*D){let L=D*(1/Math.sqrt(U));p*=L,c*=L}let W=this.b1.imass;this.b1.posx-=p*W,this.b1.posy-=c*W;let q=this.b2.imass;this.b2.posx+=p*q,this.b2.posy+=c*q,r=this.b2.posx+s-(this.b1.posx+n),o=this.b2.posy+i-(this.b1.posy+l),a=this.b2.rot-this.b1.rot-this.phase,r*=.5,o*=.5,a*=.5}}let f=this.b1.smass+this.b2.smass,_=f,d=0,b=f,m=0,z=0,M=0;if(this.b1.sinertia!=0){let O=n*this.b1.sinertia,B=l*this.b1.sinertia;_+=B*l,d+=-B*n,b+=O*n,m+=-B,z+=O,M+=this.b1.sinertia}if(this.b2.sinertia!=0){let O=s*this.b2.sinertia,B=i*this.b2.sinertia;_+=B*i,d+=-B*s,b+=O*s,m+=-B,z+=O,M+=this.b2.sinertia}p=-r,c=-o,u=-a;let y=6,w=p*p+c*c;if(w>y*y){let O=y*(1/Math.sqrt(w));p*=O,c*=O}let P=u<-.25,g=_*(b*M-z*z)+d*(m*z-d*M)+m*(d*z-m*b);if(g!=g)u=0,c=u,p=c;else if(g==0)_!=0?p/=_:p=0,b!=0?c/=b:c=0,M!=0?u/=M:u=0;else{let O=1/g,B=z*m-d*M,D=d*z-m*b,U=d*m-_*z,W=O*(p*(b*M-z*z)+c*B+u*D),q=O*(p*B+c*(_*M-m*m)+u*U);u=O*(p*D+c*U+u*(_*b-d*d)),p=W,c=q}let E=this.b1.imass;this.b1.posx-=p*E,this.b1.posy-=c*E;let N=this.b2.imass;this.b2.posx+=p*N,this.b2.posy+=c*N;let k=this.b1,Z=-(c*n-p*l+u)*this.b1.iinertia;We._rotateBody(k,Z);let C=this.b2,F=(c*s-p*i+u)*this.b2.iinertia;return We._rotateBody(C,F),!1}draw(t){}};Bs.__name__=["zpp_nape","constraint","ZPP_WeldJoint"],Bs.__super__=Ze,Bs._wrapFn=null,Bs._createFn=null;var bi=Bs;var ut=class ut{constructor(){this.outer=null;this.hnext=null;this.id=0;this.di=0;this.stamp=0;this.up_stamp=0;this.sleep_stamp=0;this.endGenerated=0;this.active=!1;this.cleared=!1;this.sleeping=!1;this.present=0;this.intchange=!1;this.presentable=!1;this.continuous=!1;this.fresh=!1;this.immState=0;this.invalidated=!1;this.b1=null;this.b2=null;this.ws1=null;this.ws2=null;this.pair=null;this.type=0;this.colarb=null;this.fluidarb=null;this.sensorarb=null;this.sensorarb=null,this.fluidarb=null,this.colarb=null,this.type=0,this.pair=null,this.ws2=null,this.ws1=null,this.b2=null,this.b1=null,this.invalidated=!1,this.immState=0,this.fresh=!1,this.continuous=!1,this.presentable=!1,this.intchange=!1,this.present=0,this.sleeping=!1,this.cleared=!1,this.active=!1,this.endGenerated=0,this.sleep_stamp=0,this.up_stamp=0,this.stamp=0,this.di=0,this.id=0,this.hnext=null,this.outer=null}static _initEnums(e,t){let n=()=>{t.internal=!0;let l=new e.dynamics.ArbiterType;return t.internal=!1,l};t.ArbiterType_COLLISION==null&&(t.ArbiterType_COLLISION=n()),t.ArbiterType_SENSOR==null&&(t.ArbiterType_SENSOR=n()),t.ArbiterType_FLUID==null&&(t.ArbiterType_FLUID=n()),ut.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID]}wrapper(){if(this.outer==null){let e=ut._nape;ut.internal=!0,this.type==ut.COL?(this.colarb.outer_zn=ut._createColArb(),this.outer=this.colarb.outer_zn):this.type==ut.FLUID?(this.fluidarb.outer_zn=ut._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,ut.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=ut._zpp;this.cleared=!0,(t==null||this.b2==t)&&ut._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&ut._removeFromArbiterList(this.b2.arbiters,this,n),this.pair!=null&&(this.pair.arb=null,this.pair=null),this.active=!1,e.f_arbiters.modified=!0}sup_assign(e,t,n,l){let s=ut._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=l,ut._addToArbiterList(this.b1.arbiters,this,s),ut._addToArbiterList(this.b2.arbiters,this,s),this.active=!0,this.present=0,this.cleared=!1,this.sleeping=!1,this.fresh=!1,this.presentable=!1}sup_retire(){let e=ut._zpp;this.cleared||(ut._removeFromArbiterList(this.b1.arbiters,this,e),ut._removeFromArbiterList(this.b2.arbiters,this,e),this.pair!=null&&(this.pair.arb=null,this.pair=null)),this.b1=this.b2=null,this.active=!1,this.intchange=!1}static _removeFromArbiterList(e,t,n){let l=null,s=e.head;for(;s!=null;){if(s.elt==t){let i,r;l==null?(i=e.head,r=i.next,e.head=r,e.head==null&&(e.pushmod=!0)):(i=l.next,r=i.next,l.next=r,r==null&&(e.pushmod=!0));let o=i;o.elt=null,o.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=o,e.modified=!0,e.length--,e.pushmod=!0;break}l=s,s=s.next}}static _addToArbiterList(e,t,n){let l;n.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?l=new n.util.ZNPNode_ZPP_Arbiter:(l=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=l.next,l.next=null),l.elt=t;let s=l;s.next=e.head,e.head=s,e.modified=!0,e.length++}};ut.__name__=["zpp_nape","dynamics","ZPP_Arbiter"],ut._nape=null,ut._zpp=null,ut.internal=!1,ut._createColArb=null,ut._createFluidArb=null,ut.COL=1,ut.FLUID=4,ut.SENSOR=2,ut.types=[];var ke=ut;var Ls=class Ls extends ke{constructor(){super(),this.next=null,this.type=ke.SENSOR,this.sensorarb=this}alloc(){}free(){}assign(e,t,n,l){this.sup_assign(e,t,n,l)}retire(){this.sup_retire(),this.next=Ls.zpp_pool,Ls.zpp_pool=this}makemutable(){}makeimmutable(){}};Ls.__name__=["zpp_nape","dynamics","ZPP_SensorArbiter"],Ls.__super__=ke,Ls.zpp_pool=null;var Qt=Ls;var js=class js extends ke{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=ke.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=ke._zpp,n=ke._nape,l;if(t.util.ZPP_PubPool.poolVec2==null?l=new n.geom.Vec2:(l=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let s;t.geom.ZPP_Vec2.zpp_pool==null?s=new t.geom.ZPP_Vec2:(s=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,l.zpp_inner=s,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==0){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;o._validate!=null&&o._validate(),i=l.zpp_inner.y==0}else i=!1;if(!i){l.zpp_inner.x=0,l.zpp_inner.y=0;let o=l.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}l.zpp_inner.weak=!1,this.wrap_position=l,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!this.mutable,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this),this.wrap_position.zpp_inner._invalidate=this.position_invalidate.bind(this)}assign(t,n,l,s){this.sup_assign(t,n,l,s),this.nx=0,this.ny=1,this.dampx=0,this.dampy=0,this.adamp=0}retire(){this.sup_retire(),this.next=js.zpp_pool,js.zpp_pool=this,this.pre_dt=-1}makemutable(){this.mutable=!0,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=!1)}makeimmutable(){this.mutable=!1,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=!0)}inject(t,n,l){this.overlap=t,this.centroidx=n,this.centroidy=l}preStep(t,n){let l=ke._nape;this.pre_dt==-1&&(this.pre_dt=n);let s=n/this.pre_dt;this.pre_dt=n,this.r1x=this.centroidx-this.b1.posx,this.r1y=this.centroidy-this.b1.posy,this.r2x=this.centroidx-this.b2.posx,this.r2y=this.centroidy-this.b2.posy;let i,r;this.ws1.fluidEnabled&&this.ws1.fluidProperties.wrap_gravity!=null?(i=this.ws1.fluidProperties.gravityx,r=this.ws1.fluidProperties.gravityy):(i=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 u=this.overlap*this.ws1.fluidProperties.density,h=this.overlap*this.ws2.fluidProperties.density;if(u>h){let x=u+h;p-=i*x,c-=r*x}else if(u<h){let x=u+h;p+=o*x,c+=a*x}else{let x=i+o,f=r+a,_=.5;if(x*=_,f*=_,this.ws1.worldCOMx*x+this.ws1.worldCOMy*f>this.ws2.worldCOMx*x+this.ws2.worldCOMy*f){let d=u+h;p-=x*d,c-=f*d}else{let d=u+h;p+=x*d,c+=f*d}}}else if(this.ws1.fluidEnabled){let u=this.overlap*this.ws1.fluidProperties.density;p-=i*u,c-=r*u}else if(this.ws2.fluidEnabled){let u=this.overlap*this.ws2.fluidProperties.density;p+=o*u,c+=a*u}if(p*=n,c*=n,this.buoyx=p,this.buoyy=c,this.b1.type==2&&(this.b1.velx-=p*this.b1.imass,this.b1.vely-=c*this.b1.imass,this.b1.angvel-=(c*this.r1x-p*this.r1y)*this.b1.iinertia),this.b2.type==2&&(this.b2.velx+=p*this.b2.imass,this.b2.vely+=c*this.b2.imass,this.b2.angvel+=(c*this.r2x-p*this.r2y)*this.b2.iinertia),(!this.ws1.fluidEnabled||this.ws1.fluidProperties.viscosity==0)&&(!this.ws2.fluidEnabled||this.ws2.fluidProperties.viscosity==0))this.nodrag=!0,this.dampx=0,this.dampy=0,this.adamp=0;else{this.nodrag=!1;let u=0;if(this.ws1.fluidEnabled&&(this.ws2.validate_angDrag(),u+=this.ws1.fluidProperties.viscosity*this.ws2.angDrag*this.overlap/this.ws2.area),this.ws2.fluidEnabled&&(this.ws1.validate_angDrag(),u+=this.ws2.fluidProperties.viscosity*this.ws1.angDrag*this.overlap/this.ws1.area),u!=0){let _=this.b1.sinertia+this.b2.sinertia;_!=0?this.wMass=1/_:this.wMass=0,u*=4e-4;let d=2*Math.PI*u;this.agamma=1/(n*d*(2+d*n));let b=1/(1+this.agamma);this.agamma*=b,this.wMass*=b}else this.wMass=0,this.agamma=0;let h=this.b2.velx+this.b2.kinvelx-this.r2y*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.r1y*(this.b2.angvel+this.b2.kinangvel)),x=this.b2.vely+this.b2.kinvely+this.r2x*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.r1x*(this.b1.angvel+this.b1.kinangvel));if(!(h*h+x*x<l.Config.epsilon*l.Config.epsilon)){let _=h*h+x*x,d=1/Math.sqrt(_);this.nx=h*d,this.ny=x*d}let f=0;if(this.ws1.fluidEnabled){let _=-this.ws1.fluidProperties.viscosity*this.overlap/this.ws2.area;if(this.ws2.type==0)f-=_*this.ws2.circle.radius*l.Config.fluidLinearDrag/(2*this.ws2.circle.radius*Math.PI);else{let d=this.ws2.polygon,b=0,m=0,z=d.edges.head;for(;z!=null;){let M=z.elt;b+=M.length;let y=_*M.length*(M.gnormx*this.nx+M.gnormy*this.ny);y>0&&(y*=-l.Config.fluidVacuumDrag),m-=y*.5*l.Config.fluidLinearDrag,z=z.next}f+=m/b}}if(this.ws2.fluidEnabled){let _=-this.ws2.fluidProperties.viscosity*this.overlap/this.ws1.area;if(this.ws1.type==0)f-=_*this.ws1.circle.radius*l.Config.fluidLinearDrag/(2*this.ws1.circle.radius*Math.PI);else{let d=this.ws1.polygon,b=0,m=0,z=d.edges.head;for(;z!=null;){let M=z.elt;b+=M.length;let y=_*M.length*(M.gnormx*this.nx+M.gnormy*this.ny);y>0&&(y*=-l.Config.fluidVacuumDrag),m-=y*.5*l.Config.fluidLinearDrag,z=z.next}f+=m/b}}if(f!=0){let _=this.b1.smass+this.b2.smass,d=_,b=0,m=_;if(this.b1.sinertia!=0){let w=this.r1x*this.b1.sinertia,v=this.r1y*this.b1.sinertia;d+=v*this.r1y,b+=-v*this.r1x,m+=w*this.r1x}if(this.b2.sinertia!=0){let w=this.r2x*this.b2.sinertia,v=this.r2y*this.b2.sinertia;d+=v*this.r2y,b+=-v*this.r2x,m+=w*this.r2x}let z=d*m-b*b;if(z!==z)m=0,b=m,d=b;else if(z==0)d!=0?d=1/d:d=0,m!=0?m=1/m:m=0,b=0;else{let w=1/z,v=m*w;m=d*w,d=v,b*=-w}this.vMassa=d,this.vMassb=b,this.vMassc=m;let M=2*Math.PI*f;this.lgamma=1/(n*M*(2+M*n));let y=1/(1+this.lgamma);this.lgamma*=y,this.vMassa*=y,this.vMassb*=y,this.vMassc*=y}else this.vMassa=0,this.vMassb=0,this.vMassc=0,this.lgamma=0}this.dampx*=s,this.dampy*=s,this.adamp*=s}warmStart(){this.b1.velx-=this.dampx*this.b1.imass,this.b1.vely-=this.dampy*this.b1.imass,this.b2.velx+=this.dampx*this.b2.imass,this.b2.vely+=this.dampy*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(this.dampy*this.r1x-this.dampx*this.r1y),this.b2.angvel+=this.b2.iinertia*(this.dampy*this.r2x-this.dampx*this.r2y),this.b1.angvel-=this.adamp*this.b1.iinertia,this.b2.angvel+=this.adamp*this.b2.iinertia}applyImpulseVel(){if(!this.nodrag){let t=this.b1.angvel+this.b1.kinangvel,n=this.b2.angvel+this.b2.kinangvel,l=this.b1.velx+this.b1.kinvelx-this.r1y*t-(this.b2.velx+this.b2.kinvelx-this.r2y*n),s=this.b1.vely+this.b1.kinvely+this.r1x*t-(this.b2.vely+this.b2.kinvely+this.r2x*n),i=this.vMassa*l+this.vMassb*s;s=this.vMassb*l+this.vMassc*s,l=i,l-=this.dampx*this.lgamma,s-=this.dampy*this.lgamma,this.dampx+=l,this.dampy+=s,this.b1.velx-=l*this.b1.imass,this.b1.vely-=s*this.b1.imass,this.b2.velx+=l*this.b2.imass,this.b2.vely+=s*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(s*this.r1x-l*this.r1y),this.b2.angvel+=this.b2.iinertia*(s*this.r2x-l*this.r2y);let 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}}};js.__name__=["zpp_nape","dynamics","ZPP_FluidArbiter"],js.__super__=ke,js.zpp_pool=null;var Bt=js;var Di=class{constructor(){this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.r1x=0;this.r1y=0;this.r2x=0;this.r2y=0;this.nMass=0;this.tMass=0;this.bounce=0;this.friction=0;this.jnAcc=0;this.jtAcc=0;this.lr1x=0;this.lr1y=0;this.lr2x=0;this.lr2y=0}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};Di.__name__=["zpp_nape","dynamics","ZPP_IContact"];var Nn=class Nn{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 Di}wrapper(){return this.outer==null&&(Nn._wrapFn?this.outer=Nn._wrapFn(this):(Nn.internal=!0,this.outer=new Nn._nape.dynamics.Contact,Nn.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=Nn._zpp,t=Nn._nape,n;if(e.util.ZPP_PubPool.poolVec2==null?n=new t.geom.Vec2:(n=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=0,l.y=0,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");l._isimmutable!=null&&l._isimmutable();let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),s=n.zpp_inner.y==0}else s=!1;if(!s){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 l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};Nn.__name__=["zpp_nape","dynamics","ZPP_Contact"],Nn._nape=null,Nn._zpp=null,Nn.zpp_pool=null,Nn.internal=!1,Nn._wrapFn=null;var we=Nn;var vt=class vt extends ke{constructor(){super();this.outer_zn=null;this.dyn_fric=0;this.stat_fric=0;this.restitution=0;this.rfric=0;this.userdef_dyn_fric=!1;this.userdef_stat_fric=!1;this.userdef_restitution=!1;this.userdef_rfric=!1;this.s1=null;this.s2=null;this.wrap_contacts=null;this.nx=0;this.ny=0;this.wrap_normal=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.Ka=0;this.Kb=0;this.Kc=0;this.rMass=0;this.jrAcc=0;this.rn1a=0;this.rt1a=0;this.rn1b=0;this.rt1b=0;this.rn2a=0;this.rt2a=0;this.rn2b=0;this.rt2b=0;this.k1x=0;this.k1y=0;this.k2x=0;this.k2y=0;this.surfacex=0;this.surfacey=0;this.ptype=null;this.lnormx=0;this.lnormy=0;this.lproj=0;this.radius=0;this.rev=!1;this.biasCoef=0;this.__ref_edge1=null;this.__ref_edge2=null;this.__ref_vertex=0;this.c1=null;this.oc1=null;this.c2=null;this.oc2=null;this.hc2=!1;this.hpc2=!1;this.stat=!1;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.stat=!1,this.next=null,this.hpc2=!1,this.hc2=!1,this.oc2=null,this.c2=null,this.oc1=null,this.c1=null,this.__ref_vertex=0,this.__ref_edge2=null,this.__ref_edge1=null,this.biasCoef=0,this.rev=!1,this.radius=0,this.lproj=0,this.lnormy=0,this.lnormx=0,this.surfacey=0,this.surfacex=0,this.k2y=0,this.k2x=0,this.k1y=0,this.k1x=0,this.rt2b=0,this.rn2b=0,this.rt2a=0,this.rn2a=0,this.rt1b=0,this.rn1b=0,this.rt1a=0,this.rn1a=0,this.jrAcc=0,this.rMass=0,this.Kc=0,this.Kb=0,this.Ka=0,this.kMassc=0,this.kMassb=0,this.kMassa=0,this.wrap_normal=null,this.ny=0,this.nx=0,this.innards=null,this.wrap_contacts=null,this.contacts=null,this.s2=null,this.s1=null,this.userdef_rfric=!1,this.userdef_restitution=!1,this.userdef_stat_fric=!1,this.userdef_dyn_fric=!1,this.rfric=0,this.restitution=0,this.stat_fric=0,this.dyn_fric=0,this.outer_zn=null,this.pre_dt=-1,this.contacts=new we,this.innards=new Di,this.type=ke.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=ke._zpp,n=ke._nape,l=0,s=0,i;if(t.util.ZPP_PubPool.poolVec2==null?i=new n.geom.Vec2:(i=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let 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=l,r.y=s,i.zpp_inner=r,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 r=i.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),l!==l||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),o=i.zpp_inner.y==s}else o=!1;if(!o){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_normal=i,this.wrap_normal.zpp_inner._immutable=!0,this.wrap_normal.zpp_inner._inuse=!0,this.wrap_normal.zpp_inner._validate=this.normal_validate.bind(this)}injectContact(t,n,l,s,i,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=l,this.ny=s,a.dist=i,a.stamp=this.stamp,a.posOnly=o,a}assign(t,n,l,s){this.sup_assign(t,n,l,s),this.s1=t,this.s2=n,this._calcFrictionRestitution()}calcProperties(){this._calcFrictionRestitution()}validate_props(){this.invalidated&&(this.invalidated=!1,this._calcFrictionRestitution())}_calcFrictionRestitution(){this.userdef_restitution||(this.s1.material.elasticity<=-1/0||this.s2.material.elasticity<=-1/0?this.restitution=0:this.s1.material.elasticity>=1/0||this.s2.material.elasticity>=1/0?this.restitution=1:this.restitution=(this.s1.material.elasticity+this.s2.material.elasticity)/2,this.restitution<0&&(this.restitution=0),this.restitution>1&&(this.restitution=1)),this.userdef_dyn_fric||(this.dyn_fric=Math.sqrt(this.s1.material.dynamicFriction*this.s2.material.dynamicFriction)),this.userdef_stat_fric||(this.stat_fric=Math.sqrt(this.s1.material.staticFriction*this.s2.material.staticFriction)),this.userdef_rfric||(this.rfric=Math.sqrt(this.s1.material.rollingFriction*this.s2.material.rollingFriction))}retire(){for(this.sup_retire();this.contacts.next!=null;){let t=this.contacts.next;this.contacts.pop(),t.arbiter=null,t.next=we.zpp_pool,we.zpp_pool=t;let n=this.innards.next;this.innards.next=n.next,n._inuse=!1,this.innards.next==null&&(this.innards.pushmod=!0),this.innards.modified=!0,this.innards.length--}this.free(),this.next=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,l=null,s=this.innards.next,i=this.contacts.next;for(;i!=null;){if(i==t.zpp_inner){this.contacts.erase(n),this.innards.erase(l),i.arbiter=null,i.next=we.zpp_pool,we.zpp_pool=i;break}n=i,l=s,s=s.next,i=i.next}}setupcontacts(){let t=ke._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=ke._nape,n=!0,l=null,s=null,i=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,l),i=vt._eraseFromList(this.innards,s),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),l=r,s=i,i=i.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=ke._nape;this.validate_props(),this.pre_dt==-1&&(this.pre_dt=t);let l=t/this.pre_dt;this.pre_dt=t;let s=this.b1.smass+this.b2.smass;this.hc2=!1;let i=!0,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,u=this.contacts.next;for(;u!=null;){let h=u;if(h.stamp+n.Config.arbiterExpirationDelay<this.stamp){u=vt._eraseFromList(this.contacts,a),c=vt._eraseFromList(this.innards,p),h.arbiter=null,h.next=we.zpp_pool,we.zpp_pool=h;continue}let x=h.inner,f=h.active;if(h.active=h.stamp==this.stamp,h.active){i?(i=!1,this.c1=x,this.oc1=h):(this.hc2=!0,this.c2=x,this.oc2=h),x.r2x=h.px-this.b2.posx,x.r2y=h.py-this.b2.posy,x.r1x=h.px-this.b1.posx,x.r1y=h.py-this.b1.posy;let _=x.r2x*this.nx+x.r2y*this.ny,d=s+this.b2.sinertia*(_*_);_=x.r1x*this.nx+x.r1y*this.ny,d+=this.b1.sinertia*(_*_),x.tMass=d<n.Config.epsilon*n.Config.epsilon?0:1/d,_=this.ny*x.r2x-this.nx*x.r2y;let b=s+this.b2.sinertia*(_*_);_=this.ny*x.r1x-this.nx*x.r1y,b+=this.b1.sinertia*(_*_),x.nMass=b<n.Config.epsilon*n.Config.epsilon?0:1/b;let m=this.b2.angvel+this.b2.kinangvel,z=this.b2.velx+this.b2.kinvelx-x.r2y*m,M=this.b2.vely+this.b2.kinvely+x.r2x*m;m=this.b1.angvel+this.b1.kinangvel,z-=this.b1.velx+this.b1.kinvelx-x.r1y*m,M-=this.b1.vely+this.b1.kinvely+x.r1x*m;let y=this.nx*z+this.ny*M;h.elasticity=this.restitution,x.bounce=y*h.elasticity,x.bounce>-n.Config.elasticThreshold&&(x.bounce=0);let w=M*this.nx-z*this.ny,v=n.Config.staticFrictionThreshold;w*w>v*v?x.friction=this.dyn_fric:x.friction=this.stat_fric,x.jnAcc*=l,x.jtAcc*=l}f!=h.active&&(this.contacts.modified=!0),a=u,p=c,c=c.next,u=u.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let h=this.c1;this.c1=this.c2,this.c2=h,h=this.oc1,this.oc1=this.oc2,this.oc2=h,this.hc2=!1}else this.oc2.posOnly&&(this.hc2=!1);this.oc1.posOnly&&(i=!0)}else this.hpc2=!1;if(this.jrAcc*=l,i||(this.rn1a=this.ny*this.c1.r1x-this.nx*this.c1.r1y,this.rt1a=this.c1.r1x*this.nx+this.c1.r1y*this.ny,this.rn1b=this.ny*this.c1.r2x-this.nx*this.c1.r2y,this.rt1b=this.c1.r2x*this.nx+this.c1.r2y*this.ny,this.k1x=this.b2.kinvelx-this.c1.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c1.r1y*this.b1.kinangvel),this.k1y=this.b2.kinvely+this.c1.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c1.r1x*this.b1.kinangvel)),this.hc2)if(this.rn2a=this.ny*this.c2.r1x-this.nx*this.c2.r1y,this.rt2a=this.c2.r1x*this.nx+this.c2.r1y*this.ny,this.rn2b=this.ny*this.c2.r2x-this.nx*this.c2.r2y,this.rt2b=this.c2.r2x*this.nx+this.c2.r2y*this.ny,this.k2x=this.b2.kinvelx-this.c2.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c2.r1y*this.b1.kinangvel),this.k2y=this.b2.kinvely+this.c2.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c2.r1x*this.b1.kinangvel),this.kMassa=s+this.b1.sinertia*this.rn1a*this.rn1a+this.b2.sinertia*this.rn1b*this.rn1b,this.kMassb=s+this.b1.sinertia*this.rn1a*this.rn2a+this.b2.sinertia*this.rn1b*this.rn2b,this.kMassc=s+this.b1.sinertia*this.rn2a*this.rn2a+this.b2.sinertia*this.rn2b*this.rn2b,this.kMassa*this.kMassa+2*this.kMassb*this.kMassb+this.kMassc*this.kMassc<n.Config.illConditionedThreshold*(this.kMassa*this.kMassc-this.kMassb*this.kMassb)){this.Ka=this.kMassa,this.Kb=this.kMassb,this.Kc=this.kMassc;let x=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(x!==x)this.kMassa=this.kMassb=this.kMassc=0;else if(x==0)this.kMassa!=0?this.kMassa=1/this.kMassa:this.kMassa=0,this.kMassc!=0?this.kMassc=1/this.kMassc:this.kMassc=0,this.kMassb=0;else{let f=1/x,_=this.kMassc*f;this.kMassc=this.kMassa*f,this.kMassa=_,this.kMassb*=-f}}else{if(this.hc2=!1,this.oc2.dist<this.oc1.dist){let x=this.c1;this.c1=this.c2,this.c2=x}this.oc2.active=!1,this.contacts.modified=!0}return this.surfacex=this.b2.svelx,this.surfacey=this.b2.svely,this.surfacex+=this.b1.svelx,this.surfacey+=this.b1.svely,this.surfacex=-this.surfacex,this.surfacey=-this.surfacey,this.rMass=this.b1.sinertia+this.b2.sinertia,this.rMass!=0&&(this.rMass=1/this.rMass),i}warmStart(){let t=this.nx*this.c1.jnAcc-this.ny*this.c1.jtAcc,n=this.ny*this.c1.jnAcc+this.nx*this.c1.jtAcc;this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c1.r1x-t*this.c1.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c1.r2x-t*this.c1.r2y),this.hc2&&(t=this.nx*this.c2.jnAcc-this.ny*this.c2.jtAcc,n=this.ny*this.c2.jnAcc+this.nx*this.c2.jtAcc,this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c2.r1x-t*this.c2.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c2.r2x-t*this.c2.r2y)),this.b2.angvel+=this.jrAcc*this.b2.iinertia,this.b1.angvel-=this.jrAcc*this.b1.iinertia}applyImpulseVel(){let t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),l=(n*this.nx-t*this.ny+this.surfacex)*this.c1.tMass,s=this.c1.friction*this.c1.jnAcc,i=this.c1.jtAcc,r=i-l;r>s?r=s:r<-s&&(r=-s),l=r-i,this.c1.jtAcc=r;let o=-this.ny*l,a=this.nx*l;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*l*this.b2.iinertia,this.b1.angvel-=this.rt1a*l*this.b1.iinertia,this.hc2){let p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);l=(c*this.nx-p*this.ny+this.surfacex)*this.c2.tMass,s=this.c2.friction*this.c2.jnAcc,i=this.c2.jtAcc,r=i-l,r>s?r=s:r<-s&&(r=-s),l=r-i,this.c2.jtAcc=r,o=-this.ny*l,a=this.nx*l,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*l*this.b2.iinertia,this.b1.angvel-=this.rt2a*l*this.b1.iinertia,t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);let u=this.c1.jnAcc,h=this.c2.jnAcc,x=t*this.nx+n*this.ny+this.surfacey+this.c1.bounce-(this.Ka*u+this.Kb*h),f=p*this.nx+c*this.ny+this.surfacey+this.c2.bounce-(this.Kb*u+this.Kc*h),_=-(this.kMassa*x+this.kMassb*f),d=-(this.kMassb*x+this.kMassc*f);_>=0&&d>=0?(x=_-u,f=d-h,this.c1.jnAcc=_,this.c2.jnAcc=d):(_=-this.c1.nMass*x,_>=0&&this.Kb*_+f>=0?(x=_-u,f=-h,this.c1.jnAcc=_,this.c2.jnAcc=0):(d=-this.c2.nMass*f,d>=0&&this.Kb*d+x>=0?(x=-u,f=d-h,this.c1.jnAcc=0,this.c2.jnAcc=d):x>=0&&f>=0?(x=-u,f=-h,this.c1.jnAcc=this.c2.jnAcc=0):(x=0,f=0))),l=x+f,o=this.nx*l,a=this.ny*l,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*x+this.rn2b*f)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*x+this.rn2a*f)*this.b1.iinertia}else this.radius!=0&&(l=(this.b2.angvel-this.b1.angvel)*this.rMass,s=this.rfric*this.c1.jnAcc,i=this.jrAcc,this.jrAcc-=l,this.jrAcc>s?this.jrAcc=s:this.jrAcc<-s&&(this.jrAcc=-s),l=this.jrAcc-i,this.b2.angvel+=l*this.b2.iinertia,this.b1.angvel-=l*this.b1.iinertia),t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),l=(this.c1.bounce+(this.nx*t+this.ny*n)+this.surfacey)*this.c1.nMass,i=this.c1.jnAcc,r=i-l,r<0&&(r=0),l=r-i,this.c1.jnAcc=r,o=this.nx*l,a=this.ny*l,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*l*this.b2.iinertia,this.b1.angvel-=this.rn1a*l*this.b1.iinertia}applyImpulsePos(){let t=ke._nape;this.ptype==2?this._applyImpulsePosCircle(t):this._applyImpulsePosEdge(t)}_applyImpulsePosCircle(t){let n=this.c1,l=this.b2.axisy*n.lr2x-this.b2.axisx*n.lr2y,s=n.lr2x*this.b2.axisx+n.lr2y*this.b2.axisy;l+=this.b2.posx,s+=this.b2.posy;let i=this.b1.axisy*n.lr1x-this.b1.axisx*n.lr1y,r=n.lr1x*this.b1.axisx+n.lr1y*this.b1.axisy;i+=this.b1.posx,r+=this.b1.posy;let o=l-i,a=s-r,p=Math.sqrt(o*o+a*a),c=this.radius-t.Config.collisionSlop,u=p-c;if(o*this.nx+a*this.ny<0&&(o=-o,a=-a,u-=this.radius),u<0)if(p<t.Config.epsilon)this.b1.smass!=0?this.b1.posx+=t.Config.epsilon*10:this.b2.posx+=t.Config.epsilon*10;else{let h=1/p;o*=h,a*=h;let x=.5*(i+l),f=.5*(r+s),_=p-c;i=x-this.b1.posx,r=f-this.b1.posy,l=x-this.b2.posx,s=f-this.b2.posy;let d=a*i-o*r,b=a*l-o*s,m=this.b2.smass+b*b*this.b2.sinertia+this.b1.smass+d*d*this.b1.sinertia;if(m!=0){let z=-this.biasCoef*_/m,M=o*z,y=a*z;this.b1.posx-=M*this.b1.imass,this.b1.posy-=y*this.b1.imass,vt._rotateBody(this.b1,-d*this.b1.iinertia*z),this.b2.posx+=M*this.b2.imass,this.b2.posy+=y*this.b2.imass,vt._rotateBody(this.b2,b*this.b2.iinertia*z)}}}_applyImpulsePosEdge(t){let n,l,s,i,r,o=0,a=0;this.ptype==0?(n=this.b1.axisy*this.lnormx-this.b1.axisx*this.lnormy,l=this.lnormx*this.b1.axisx+this.lnormy*this.b1.axisy,s=this.lproj+(n*this.b1.posx+l*this.b1.posy),i=this.b2.axisy*this.c1.lr1x-this.b2.axisx*this.c1.lr1y,r=this.c1.lr1x*this.b2.axisx+this.c1.lr1y*this.b2.axisy,i+=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,l=this.lnormx*this.b2.axisx+this.lnormy*this.b2.axisy,s=this.lproj+(n*this.b2.posx+l*this.b2.posy),i=this.b1.axisy*this.c1.lr1x-this.b1.axisx*this.c1.lr1y,r=this.c1.lr1x*this.b1.axisx+this.c1.lr1y*this.b1.axisy,i+=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=i*n+r*l-s-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=o*n+a*l-s-this.radius,c+=t.Config.collisionSlop),p<0||c<0){this.rev&&(n=-n,l=-l);let u=i-this.b1.posx,h=r-this.b1.posy,x=i-this.b2.posx,f=r-this.b2.posy;if(this.hpc2){let _=o-this.b1.posx,d=a-this.b1.posy,b=o-this.b2.posx,m=a-this.b2.posy,z=l*u-n*h,M=l*x-n*f,y=l*_-n*d,w=l*b-n*m,v=this.b1.smass+this.b2.smass;this.kMassa=v+this.b1.sinertia*z*z+this.b2.sinertia*M*M,this.kMassb=v+this.b1.sinertia*z*y+this.b2.sinertia*M*w,this.kMassc=v+this.b1.sinertia*y*y+this.b2.sinertia*w*w;let P=this.kMassa,g=this.kMassb,E=this.kMassc,N=p*this.biasCoef,k=c*this.biasCoef;for(;;){let Z=-N,C=-k,F=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(F!==F)Z=0,C=0;else if(F==0)this.kMassa!=0?Z/=this.kMassa:Z=0,this.kMassc!=0?C/=this.kMassc:C=0;else{let O=1/F,B=O*(this.kMassc*Z-this.kMassb*C);C=O*(this.kMassa*C-this.kMassb*Z),Z=B}if(Z>=0&&C>=0){vt._applyPosImpulse2(this.b1,this.b2,n,l,Z,C,z,y,M,w);break}if(Z=-N/P,C=0,Z>=0&&g*Z+k>=0){vt._applyPosImpulse2(this.b1,this.b2,n,l,Z,C,z,y,M,w);break}if(Z=0,C=-k/E,C>=0&&g*C+N>=0){vt._applyPosImpulse2(this.b1,this.b2,n,l,Z,C,z,y,M,w);break}break}}else{let _=l*u-n*h,d=l*x-n*f,b=this.b2.smass+d*d*this.b2.sinertia+this.b1.smass+_*_*this.b1.sinertia;if(b!=0){let m=-this.biasCoef*p/b,z=n*m,M=l*m;this.b1.posx-=z*this.b1.imass,this.b1.posy-=M*this.b1.imass,vt._rotateBody(this.b1,-_*this.b1.iinertia*m),this.b2.posx+=z*this.b2.imass,this.b2.posy+=M*this.b2.imass,vt._rotateBody(this.b2,d*this.b2.iinertia*m)}}}}static _eraseFromList(t,n){let l,s;return n==null?(l=t.next,s=l.next,t.next=s,t.next==null&&(t.pushmod=!0)):(l=n.next,s=l.next,n.next=s,s==null&&(t.pushmod=!0)),l._inuse=!1,t.modified=!0,t.length--,t.pushmod=!0,s}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let l=n*n,s=1-.5*l,i=1-l*l/8,r=(s*t.axisx+n*t.axisy)*i;t.axisy=(s*t.axisy-n*t.axisx)*i,t.axisx=r}}static _applyPosImpulse2(t,n,l,s,i,r,o,a,p,c){let u=(i+r)*t.imass;t.posx-=l*u,t.posy-=s*u,vt._rotateBody(t,-t.iinertia*(o*i+a*r));let h=(i+r)*n.imass;n.posx+=l*h,n.posy+=s*h,vt._rotateBody(n,n.iinertia*(p*i+c*r))}};vt.__name__=["zpp_nape","dynamics","ZPP_ColArbiter"],vt.__super__=ke,vt.FACE1=0,vt.FACE2=1,vt.CIRCLE=2,vt.zpp_pool=null;var gt=vt;var rn=class rn{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 rn._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(rn._wrapFn)this.outer=rn._wrapFn(this);else{this.outer=new rn._nape.dynamics.InteractionFilter;let e=this.outer.zpp_inner;e.outer=null,e.next=rn.zpp_pool,rn.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new rn._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return rn.zpp_pool==null?e=new rn:(e=rn.zpp_pool,rn.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}};rn.zpp_pool=null,rn.__name__=["zpp_nape","dynamics","ZPP_InteractionFilter"],rn._nape=null,rn._zpp=null,rn._wrapFn=null;var Ct=rn;var ts=class ts{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=ts._zpp;this.groups=new e.util.ZNPList_ZPP_InteractionGroup,this.interactors=new e.util.ZNPList_ZPP_Interactor}setGroup(e){this.group!==e&&(this.group!=null&&(this.group.groups.remove(this),this.depth=0,this.group.invalidate(!0)),this.group=e,e!=null?(e.groups.add(this),this.depth=e.depth+1,e.invalidate(!0)):this.invalidate(!0))}invalidate(e){if(e==null&&(e=!1),!(e||this.ignore))return;let t=this.interactors.head;for(;t!=null;){let l=t.elt;l.ibody!=null?l.ibody.wake():l.ishape!=null?l.ishape.body.wake():l.icompound.wake(),t=t.next}let n=this.groups.head;for(;n!=null;)n.elt.invalidate(e),n=n.next}addGroup(e){this.groups.add(e),e.depth=this.depth+1}remGroup(e){this.groups.remove(e),e.depth=0}addInteractor(e){this.interactors.add(e)}remInteractor(e,t){this.interactors.remove(e)}};ts.SHAPE=1,ts.BODY=2,ts.__name__=["zpp_nape","dynamics","ZPP_InteractionGroup"],ts._zpp=null,ts._wrapFn=null;var Fi=ts;var zi=class{constructor(){this.zpp_inner=null;this.space=null;this._length=0;this.zip_length=!1;this.lengths=[];this.ite_0=null;this.ite_1=null;this.ite_2=null;this.ite_3=null;this.at_index_0=0;this.at_index_1=0;this.at_index_2=0;this.at_index_3=0;this.at_index_0=0,this.at_index_1=0,this.at_index_2=0,this.at_index_3=0,this.zip_length=!0,this._length=0,this.lengths=[],this.lengths.push(0),this.lengths.push(0),this.lengths.push(0),this.lengths.push(0)}zpp_gl(){if(this.zpp_vm(),this.zip_length){this._length=0;let e=0,t=0,n=this.space.c_arbiters_true.head;for(;n!=null;)n.elt.active&&++t,n=n.next;this.lengths[e++]=t,this._length+=t;let l=0,s=this.space.c_arbiters_false.head;for(;s!=null;)s.elt.active&&++l,s=s.next;this.lengths[e++]=l,this._length+=l;let i=0,r=this.space.f_arbiters.head;for(;r!=null;)r.elt.active&&++i,r=r.next;this.lengths[e++]=i,this._length+=i;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 l=e-n;if(l<this.at_index_0||this.ite_0==null)for(this.at_index_0=0,this.ite_0=this.space.c_arbiters_true.head;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;for(;this.at_index_0!=l;)for(this.at_index_0++,this.ite_0=this.ite_0.next;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;t=this.ite_0.elt.wrapper()}else n+=this.lengths[0];if(t==null)if(e<n+this.lengths[1]){let l=e-n;if(l<this.at_index_1||this.ite_1==null)for(this.at_index_1=0,this.ite_1=this.space.c_arbiters_false.head;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;for(;this.at_index_1!=l;)for(this.at_index_1++,this.ite_1=this.ite_1.next;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;t=this.ite_1.elt.wrapper()}else n+=this.lengths[1];if(t==null)if(e<n+this.lengths[2]){let l=e-n;if(l<this.at_index_2||this.ite_2==null)for(this.at_index_2=0,this.ite_2=this.space.f_arbiters.head;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;for(;this.at_index_2!=l;)for(this.at_index_2++,this.ite_2=this.ite_2.next;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;t=this.ite_2.elt.wrapper()}else n+=this.lengths[2];if(t==null)if(e<n+this.lengths[3]){let l=e-n;if(l<this.at_index_3||this.ite_3==null)for(this.at_index_3=0,this.ite_3=this.space.s_arbiters.head;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;for(;this.at_index_3!=l;)for(this.at_index_3++,this.ite_3=this.ite_3.next;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;t=this.ite_3.elt.wrapper()}else n+=this.lengths[3];return t}};zi.__name__=["zpp_nape","dynamics","ZPP_SpaceArbiterList"],zi._nape=null,zi._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,l){let s;return Lt.zpp_pool==null?s=new Lt:(s=Lt.zpp_pool,Lt.zpp_pool=s.next,s.next=null),s.minx=e,s.miny=t,s.maxx=n,s.maxy=l,s}validate(){this._validate!=null&&this._validate()}invalidate(){this._invalidate!=null&&this._invalidate(this)}wrapper(){if(this.outer==null)if(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,l=Lt._nape;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(n.util.ZPP_PubPool.poolVec2==null?s=new l.geom.Vec2:(s=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;n.geom.ZPP_Vec2.zpp_pool==null?i=new n.geom.ZPP_Vec2:(i=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=e,i.y=t,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");i._validate!=null&&i._validate(),(i.x!==e||i.y!==t)&&(i.x=e,i.y=t,i._invalidate!=null&&i._invalidate(i))}return s.zpp_inner.weak=!1,s}getmin(){this.wrap_min==null&&(this.wrap_min=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.__name__=["zpp_nape","geom","ZPP_AABB"],Lt._nape=null,Lt._zpp=null,Lt._wrapFn=null;var fe=Lt;var Me=class Me{static _initStatics(e){Me.flowpoly=new e.util.ZNPList_ZPP_Vec2,Me.flowsegs=new e.util.ZNPList_ZPP_Vec2}static circleContains(e,t){let n=t.x-e.worldCOMx,l=t.y-e.worldCOMy;return n*n+l*l<e.radius*e.radius}static polyContains(e,t){let n;n=!0;let l=e.edges.head;for(;l!=null;){let s=l.elt;if(s.gnormx*t.x+s.gnormy*t.y<=s.gprojection){l=l.next;continue}else{n=!1;break}}return n}static shapeContains(e,t){return e.type==0?Me.circleContains(e.circle,t):Me.polyContains(e.polygon,t)}static bodyContains(e,t){let n;n=!1;let l=e.shapes.head;for(;l!=null;){let s=l.elt;if(Me.shapeContains(s,t)){n=!0;break}l=l.next}return n}static containTest(e,t){let n=e.aabb,l=t.aabb;if(l.minx>=n.minx&&l.miny>=n.miny&&l.maxx<=n.maxx&&l.maxy<=n.maxy)if(e.type==0)if(t.type==0){let s=e.circle.radius+-t.circle.radius,i=t.circle.worldCOMx-e.circle.worldCOMx,r=t.circle.worldCOMy-e.circle.worldCOMy;return i*i+r*r<=s*s}else{let s;s=!0;let i=t.polygon.gverts.next;for(;i!=null;){let r=i,o=e.circle.radius,a=r.x-e.circle.worldCOMx,p=r.y-e.circle.worldCOMy;if(a*a+p*p<=o*o){i=i.next;continue}else{s=!1;break}}return s}else if(t.type==0){let s;s=!0;let i=e.polygon.edges.head;for(;i!=null;){let r=i.elt;if(r.gnormx*t.circle.worldCOMx+r.gnormy*t.circle.worldCOMy+t.circle.radius<=r.gprojection){i=i.next;continue}else{s=!1;break}}return s}else{let s;s=!0;let i=e.polygon.edges.head;for(;i!=null;){let r=i.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){i=i.next;continue}else{s=!1;break}}return s}else return!1}static contactCollide(e,t,n,l){let s=oe();if(t.type==1)if(e.type==1){let i=!0,r=-1e100,o=-1e100,a=-1,p=null,c=null,u=e.polygon.edges.head;for(;u!=null;){let h=u.elt,x=1e100,f=t.polygon.gverts.next;for(;f!=null;){let _=f,d=h.gnormx*_.x+h.gnormy*_.y;if(d<x&&(x=d),x-h.gprojection<=r)break;f=f.next}if(x-=h.gprojection,x>=0){i=!1;break}x>r&&(r=x,p=h,a=1),u=u.next}if(i){let h=t.polygon.edges.head;for(;h!=null;){let x=h.elt,f=1e100,_=e.polygon.gverts.next;for(;_!=null;){let d=_,b=x.gnormx*d.x+x.gnormy*d.y;if(b<f&&(f=b),f-x.gprojection<=r)break;_=_.next}if(f-=x.gprojection,f>=0){i=!1;break}f>r&&(r=f,c=x,a=2),h=h.next}if(i){let x,f,_,d;a==1?(x=e.polygon,f=t.polygon,_=p,d=1):(x=t.polygon,f=e.polygon,_=c,d=-1);let b=null,m=1e100,z=f.edges.head;for(;z!=null;){let W=z.elt,q=_.gnormx*W.gnormx+_.gnormy*W.gnormy;q<m&&(m=q,b=W),z=z.next}let M=b.gp0.x,y=b.gp0.y,w=b.gp1.x,v=b.gp1.y,P=w-M,g=v-y,E=_.gnormy*M-_.gnormx*y,N=_.gnormy*w-_.gnormx*v,k=1/(N-E),Z=(-_.tp1-E)*k;if(Z>s.Config.epsilon){let W=Z;M+=P*W,y+=g*W}let C=(-_.tp0-N)*k;if(C<-s.Config.epsilon){let W=C;w+=P*W,v+=g*W}let F=d,O=_.gnormx*F,B=_.gnormy*F;n.lnormx=_.lnormx,n.lnormy=_.lnormy,n.lproj=_.lprojection,n.radius=0,n.rev=l!=(d==-1),n.ptype=n.rev?1:0;let D=M*_.gnormx+y*_.gnormy-_.gprojection,U=w*_.gnormx+v*_.gnormy-_.gprojection;if(D>0&&U>0)return!1;{l&&(O=-O,B=-B);let W=M-_.gnormx*D*.5,q=y-_.gnormy*D*.5,L=n.rev?1:0,A=D>0;A==null&&(A=!1);let J=null,$=n.contacts.next;for(;$!=null;){let Y=$;if(L==Y.hash){J=Y;break}$=$.next}if(J==null){we.zpp_pool==null?J=new we:(J=we.zpp_pool,we.zpp_pool=J.next,J.next=null);let Y=J.inner;Y.jnAcc=Y.jtAcc=0,J.hash=L,J.fresh=!0,J.arbiter=n,n.jrAcc=0;let ne=n.contacts;J._inuse=!0;let ae=J;ae.next=ne.next,ne.next=ae,ne.modified=!0,ne.length++,n.innards.add(Y)}else J.fresh=!1;J.px=W,J.py=q,n.nx=O,n.ny=B,J.dist=D,J.stamp=n.stamp,J.posOnly=A;let X=J,H=1;M-=f.body.posx*H,y-=f.body.posy*H,X.inner.lr1x=M*f.body.axisy+y*f.body.axisx,X.inner.lr1y=y*f.body.axisy-M*f.body.axisx;let ee=w-_.gnormx*U*.5,G=v-_.gnormy*U*.5,R=n.rev?0:1,j=U>0;j==null&&(j=!1);let V=null,K=n.contacts.next;for(;K!=null;){let Y=K;if(R==Y.hash){V=Y;break}K=K.next}if(V==null){we.zpp_pool==null?V=new we:(V=we.zpp_pool,we.zpp_pool=V.next,V.next=null);let Y=V.inner;Y.jnAcc=Y.jtAcc=0,V.hash=R,V.fresh=!0,V.arbiter=n,n.jrAcc=0;let ne=n.contacts;V._inuse=!0;let ae=V;ae.next=ne.next,ne.next=ae,ne.modified=!0,ne.length++,n.innards.add(Y)}else V.fresh=!1;V.px=ee,V.py=G,n.nx=O,n.ny=B,V.dist=U,V.stamp=n.stamp,V.posOnly=j,X=V;let Q=1;return w-=f.body.posx*Q,v-=f.body.posy*Q,X.inner.lr1x=w*f.body.axisy+v*f.body.axisx,X.inner.lr1y=v*f.body.axisy-w*f.body.axisx,a==1?(n.__ref_edge1=_,n.__ref_edge2=b):(n.__ref_edge2=_,n.__ref_edge1=b),!0}}else return!1}else return!1}else{let i=-1e100,r=-1e100,o=!0,a=null,p=null,c=t.polygon.gverts.next,u=t.polygon.edges.head;for(;u!=null;){let h=u.elt,x=h.gnormx*e.circle.worldCOMx+h.gnormy*e.circle.worldCOMy-h.gprojection-e.circle.radius;if(x>0){o=!1;break}x>i&&(i=x,a=h,p=c),c=c.next,u=u.next}if(o){let h=p,x=p.next==null?t.polygon.gverts.next:p.next,f=e.circle.worldCOMy*a.gnormx-e.circle.worldCOMx*a.gnormy;if(f<=h.y*a.gnormx-h.x*a.gnormy){let _=e.circle.radius,d=h.x-e.circle.worldCOMx,b=h.y-e.circle.worldCOMy,m=d*d+b*b,z;if(m>_*_)z=null;else if(m<s.Config.epsilon*s.Config.epsilon){let M=e.circle.worldCOMx,y=e.circle.worldCOMy,w=null,v=n.contacts.next;for(;v!=null;){let P=v;if(P.hash==0){w=P;break}v=v.next}if(w==null){we.zpp_pool==null?w=new we:(w=we.zpp_pool,we.zpp_pool=w.next,w.next=null);let P=w.inner;P.jnAcc=P.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let E=w;E.next=g.next,g.next=E,g.modified=!0,g.length++,n.innards.add(P)}else w.fresh=!1;w.px=M,w.py=y,n.nx=1,n.ny=0,w.dist=-_,w.stamp=n.stamp,w.posOnly=!1,z=w}else{let M=1/Math.sqrt(m),y=M<s.Config.epsilon?1e100:1/M,w=.5+(e.circle.radius-.5*_)*M;if(l){let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+b*w,g=null,E=n.contacts.next;for(;E!=null;){let N=E;if(N.hash==0){g=N;break}E=E.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 k=n.contacts;g._inuse=!0;let Z=g;Z.next=k.next,k.next=Z,k.modified=!0,k.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=-d*M,n.ny=-b*M,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}else{let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+b*w,g=null,E=n.contacts.next;for(;E!=null;){let N=E;if(N.hash==0){g=N;break}E=E.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 k=n.contacts;g._inuse=!0;let Z=g;Z.next=k.next,k.next=Z,k.modified=!0,k.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=d*M,n.ny=b*M,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}}if(z!=null){let M=z.inner;n.ptype=2;let y=h.x-t.polygon.body.posx,w=h.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=-1,l?(M.lr1x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,M.lr1y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,M.lr2x=e.circle.localCOMx,M.lr2y=e.circle.localCOMy):(M.lr2x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,M.lr2y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,M.lr1x=e.circle.localCOMx,M.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return z!=null}else if(f>=x.y*a.gnormx-x.x*a.gnormy){let _=e.circle.radius,d=x.x-e.circle.worldCOMx,b=x.y-e.circle.worldCOMy,m=d*d+b*b,z;if(m>_*_)z=null;else if(m<s.Config.epsilon*s.Config.epsilon){let M=e.circle.worldCOMx,y=e.circle.worldCOMy,w=null,v=n.contacts.next;for(;v!=null;){let P=v;if(P.hash==0){w=P;break}v=v.next}if(w==null){we.zpp_pool==null?w=new we:(w=we.zpp_pool,we.zpp_pool=w.next,w.next=null);let P=w.inner;P.jnAcc=P.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let E=w;E.next=g.next,g.next=E,g.modified=!0,g.length++,n.innards.add(P)}else w.fresh=!1;w.px=M,w.py=y,n.nx=1,n.ny=0,w.dist=-_,w.stamp=n.stamp,w.posOnly=!1,z=w}else{let M=1/Math.sqrt(m),y=M<s.Config.epsilon?1e100:1/M,w=.5+(e.circle.radius-.5*_)*M;if(l){let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+b*w,g=null,E=n.contacts.next;for(;E!=null;){let N=E;if(N.hash==0){g=N;break}E=E.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 k=n.contacts;g._inuse=!0;let Z=g;Z.next=k.next,k.next=Z,k.modified=!0,k.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=-d*M,n.ny=-b*M,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}else{let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+b*w,g=null,E=n.contacts.next;for(;E!=null;){let N=E;if(N.hash==0){g=N;break}E=E.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 k=n.contacts;g._inuse=!0;let Z=g;Z.next=k.next,k.next=Z,k.modified=!0,k.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=d*M,n.ny=b*M,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}}if(z!=null){let M=z.inner;n.ptype=2;let y=x.x-t.polygon.body.posx,w=x.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=1,l?(M.lr1x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,M.lr1y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,M.lr2x=e.circle.localCOMx,M.lr2y=e.circle.localCOMy):(M.lr2x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,M.lr2y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,M.lr1x=e.circle.localCOMx,M.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return z!=null}else{let _=e.circle.radius+i*.5,d=a.gnormx*_,b=a.gnormy*_,m=e.circle.worldCOMx-d,z=e.circle.worldCOMy-b,M;if(l){let y=a.gnormx,w=a.gnormy,v=null,P=n.contacts.next;for(;P!=null;){let g=P;if(g.hash==0){v=g;break}P=P.next}if(v==null){we.zpp_pool==null?v=new we:(v=we.zpp_pool,we.zpp_pool=v.next,v.next=null);let g=v.inner;g.jnAcc=g.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let E=n.contacts;v._inuse=!0;let N=v;N.next=E.next,E.next=N,E.modified=!0,E.length++,n.innards.add(g)}else v.fresh=!1;v.px=m,v.py=z,n.nx=y,n.ny=w,v.dist=i,v.stamp=n.stamp,v.posOnly=!1,M=v}else{let y=-a.gnormx,w=-a.gnormy,v=null,P=n.contacts.next;for(;P!=null;){let g=P;if(g.hash==0){v=g;break}P=P.next}if(v==null){we.zpp_pool==null?v=new we:(v=we.zpp_pool,we.zpp_pool=v.next,v.next=null);let g=v.inner;g.jnAcc=g.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let E=n.contacts;v._inuse=!0;let N=v;N.next=E.next,E.next=N,E.modified=!0,E.length++,n.innards.add(g)}else v.fresh=!1;v.px=m,v.py=z,n.nx=y,n.ny=w,v.dist=i,v.stamp=n.stamp,v.posOnly=!1,M=v}return n.ptype=l?0:1,n.lnormx=a.lnormx,n.lnormy=a.lnormy,n.rev=!l,n.lproj=a.lprojection,n.radius=e.circle.radius,M.inner.lr1x=e.circle.localCOMx,M.inner.lr1y=e.circle.localCOMy,n.__ref_edge1=a,n.__ref_vertex=0,!0}}else return!1}else{let i=e.circle.radius+t.circle.radius,r=t.circle.worldCOMx-e.circle.worldCOMx,o=t.circle.worldCOMy-e.circle.worldCOMy,a=r*r+o*o,p;if(a>i*i)p=null;else if(a<s.Config.epsilon*s.Config.epsilon){let c=e.circle.worldCOMx,u=e.circle.worldCOMy,h=null,x=n.contacts.next;for(;x!=null;){let f=x;if(f.hash==0){h=f;break}x=x.next}if(h==null){we.zpp_pool==null?h=new we:(h=we.zpp_pool,we.zpp_pool=h.next,h.next=null);let f=h.inner;f.jnAcc=f.jtAcc=0,h.hash=0,h.fresh=!0,h.arbiter=n,n.jrAcc=0;let _=n.contacts;h._inuse=!0;let d=h;d.next=_.next,_.next=d,_.modified=!0,_.length++,n.innards.add(f)}else h.fresh=!1;h.px=c,h.py=u,n.nx=1,n.ny=0,h.dist=-i,h.stamp=n.stamp,h.posOnly=!1,p=h}else{let c=1/Math.sqrt(a),u=c<s.Config.epsilon?1e100:1/c,h=.5+(e.circle.radius-.5*i)*c;if(l){let x=e.circle.worldCOMx+r*h,f=e.circle.worldCOMy+o*h,_=null,d=n.contacts.next;for(;d!=null;){let b=d;if(b.hash==0){_=b;break}d=d.next}if(_==null){we.zpp_pool==null?_=new we:(_=we.zpp_pool,we.zpp_pool=_.next,_.next=null);let b=_.inner;b.jnAcc=b.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let m=n.contacts;_._inuse=!0;let z=_;z.next=m.next,m.next=z,m.modified=!0,m.length++,n.innards.add(b)}else _.fresh=!1;_.px=x,_.py=f,n.nx=-r*c,n.ny=-o*c,_.dist=u-i,_.stamp=n.stamp,_.posOnly=!1,p=_}else{let x=e.circle.worldCOMx+r*h,f=e.circle.worldCOMy+o*h,_=null,d=n.contacts.next;for(;d!=null;){let b=d;if(b.hash==0){_=b;break}d=d.next}if(_==null){we.zpp_pool==null?_=new we:(_=we.zpp_pool,we.zpp_pool=_.next,_.next=null);let b=_.inner;b.jnAcc=b.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let m=n.contacts;_._inuse=!0;let z=_;z.next=m.next,m.next=z,m.modified=!0,m.length++,n.innards.add(b)}else _.fresh=!1;_.px=x,_.py=f,n.nx=r*c,n.ny=o*c,_.dist=u-i,_.stamp=n.stamp,_.posOnly=!1,p=_}}if(p!=null){let c=p.inner;return l?(c.lr1x=t.circle.localCOMx,c.lr1y=t.circle.localCOMy,c.lr2x=e.circle.localCOMx,c.lr2y=e.circle.localCOMy):(c.lr1x=e.circle.localCOMx,c.lr1y=e.circle.localCOMy,c.lr2x=t.circle.localCOMx,c.lr2y=t.circle.localCOMy),n.radius=e.circle.radius+t.circle.radius,n.ptype=2,!0}else return!1}}static testCollide_safe(e,t){let n=oe();if(t.type==0){let l=e;e=t,t=l}return Me.testCollide(e,t)}static testCollide(e,t){let n=oe();if(t.type==1)if(e.type==1){let l=!0,s=e.polygon.edges.head;for(;s!=null;){let i=s.elt,r=1e100,o=t.polygon.gverts.next;for(;o!=null;){let a=o,p=i.gnormx*a.x+i.gnormy*a.y;p<r&&(r=p),o=o.next}if(r-=i.gprojection,r>0){l=!1;break}s=s.next}if(l){let i=t.polygon.edges.head;for(;i!=null;){let r=i.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){l=!1;break}i=i.next}return l}else return!1}else{let l=null,s=null,i=!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){i=!1;break}c>r&&(r=c,l=p,s=o),o=o.next,a=a.next}if(i){let p=s,c=s.next==null?t.polygon.gverts.next:s.next,u=e.circle.worldCOMy*l.gnormx-e.circle.worldCOMx*l.gnormy;if(u<=p.y*l.gnormx-p.x*l.gnormy){let h=e.circle.radius,x=p.x-e.circle.worldCOMx,f=p.y-e.circle.worldCOMy;return x*x+f*f<=h*h}else if(u>=c.y*l.gnormx-c.x*l.gnormy){let h=e.circle.radius,x=c.x-e.circle.worldCOMx,f=c.y-e.circle.worldCOMy;return x*x+f*f<=h*h}else return!0}else return!1}else{let l=e.circle.radius+t.circle.radius,s=t.circle.worldCOMx-e.circle.worldCOMx,i=t.circle.worldCOMy-e.circle.worldCOMy;return s*s+i*i<=l*l}}static flowCollide(e,t,n){let l=oe();if(t.type==1)if(e.type==1){let s=[],i=[],r=!0,o=!0,a=e.polygon.edges.head;for(;a!=null;){let p=a.elt,c=1e100,u=0,h=t.polygon.gverts.next;for(;h!=null;){let x=h,f=p.gnormx*x.x+p.gnormy*x.y;f<c&&(c=f),f>=p.gprojection+l.Config.epsilon&&(i[u]=!0,o=!1),++u,h=h.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 u=p.polygon;if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(u.lverts.next.next==null)u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;else if(u.lverts.next.next.next==null){u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;let h=1;u.localCOMx+=u.lverts.next.next.x*h,u.localCOMy+=u.lverts.next.next.y*h;let x=.5;u.localCOMx*=x,u.localCOMy*=x}else{u.localCOMx=0,u.localCOMy=0;let h=0,x=u.lverts.next,f=x;x=x.next;let _=x;for(x=x.next;x!=null;){let y=x;h+=_.x*(y.y-f.y);let w=y.y*_.x-y.x*_.y;u.localCOMx+=(_.x+y.x)*w,u.localCOMy+=(_.y+y.y)*w,f=_,_=y,x=x.next}x=u.lverts.next;let d=x;h+=_.x*(d.y-f.y);let b=d.y*_.x-d.x*_.y;u.localCOMx+=(_.x+d.x)*b,u.localCOMy+=(_.y+d.y)*b,f=_,_=d,x=x.next;let m=x;h+=_.x*(m.y-f.y);let z=m.y*_.x-m.x*_.y;u.localCOMx+=(_.x+m.x)*z,u.localCOMy+=(_.y+m.y)*z,h=1/(3*h);let M=h;u.localCOMx*=M,u.localCOMy*=M}}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,u=1e100,h=0,x=e.polygon.gverts.next;for(;x!=null;){let f=x,_=c.gnormx*f.x+c.gnormy*f.y;_<u&&(u=_),_>=c.gprojection+l.Config.epsilon&&(s[h]=!0,o=!1),++h,x=x.next}if(u-=c.gprojection,u>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 h=c.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let x=1;h.localCOMx+=h.lverts.next.next.x*x,h.localCOMy+=h.lverts.next.next.y*x;let f=.5;h.localCOMx*=f,h.localCOMy*=f}else{h.localCOMx=0,h.localCOMy=0;let x=0,f=h.lverts.next,_=f;f=f.next;let d=f;for(f=f.next;f!=null;){let w=f;x+=d.x*(w.y-_.y);let v=w.y*d.x-w.x*d.y;h.localCOMx+=(d.x+w.x)*v,h.localCOMy+=(d.y+w.y)*v,_=d,d=w,f=f.next}f=h.lverts.next;let b=f;x+=d.x*(b.y-_.y);let m=b.y*d.x-b.x*d.y;h.localCOMx+=(d.x+b.x)*m,h.localCOMy+=(d.y+b.y)*m,_=d,d=b,f=f.next;let z=f;x+=d.x*(z.y-_.y);let M=z.y*d.x-z.x*d.y;h.localCOMx+=(d.x+z.x)*M,h.localCOMy+=(d.y+z.y)*M,x=1/(3*x);let y=x;h.localCOMx*=y,h.localCOMy*=y}}c.wrap_localCOM!=null&&(c.wrap_localCOM.zpp_inner.x=c.localCOMx,c.wrap_localCOM.zpp_inner.y=c.localCOMy)}let u=c.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),c.worldCOMx=c.body.posx+(c.body.axisy*c.localCOMx-c.body.axisx*c.localCOMy),c.worldCOMy=c.body.posy+(c.localCOMx*c.body.axisx+c.localCOMy*c.body.axisy)}return n.overlap=e.polygon.area,n.centroidx=e.polygon.worldCOMx,n.centroidy=e.polygon.worldCOMy,!0}else if(r){for(;Me.flowpoly.head!=null;){let z=Me.flowpoly.pop_unsafe();if(!z._inuse){let M=z;M.outer!=null&&(M.outer.zpp_inner=null,M.outer=null),M._isimmutable=null,M._validate=null,M._invalidate=null,M.next=ie.zpp_pool,ie.zpp_pool=M}}let c=null,u=!1,h=e.polygon.gverts.next,x=0,f=t.polygon.gverts.next,_=0,d=0,b=t.polygon.edgeCnt;for(;d<b;){let z=d++;if(i[z])f=f.next;else{_=z;break}}if(f==null){f=t.polygon.gverts.next,u=!0;let z=0,M=e.polygon.edgeCnt;for(;z<M;){let y=z++;if(s[y])h=h.next;else{x=y;break}}h==null?h=e.polygon.gverts.next:(Me.flowpoly.add(h),c=Me.flowpoly.head.elt)}else Me.flowpoly.add(f),c=Me.flowpoly.head.elt;let m=1;if(Me.flowpoly.head==null){let z=!0,M=e.polygon.gverts.next,y=M,w=M.next;for(;w!=null;){let v=w,P=2,g=!0,E=t.polygon.gverts.next,N=E,k=E.next;for(;k!=null;){let Z=k,C=0,F=y.x-N.x,O=y.y-N.y,B=v.x-y.x,D=v.y-y.y,U=Z.x-N.x,W=Z.y-N.y,q=D*U-B*W,L;if(q*q>l.Config.epsilon*l.Config.epsilon){q=1/q;let A=(W*F-U*O)*q;if(A>l.Config.epsilon&&A<1-l.Config.epsilon){let J=(D*F-B*O)*q;J>l.Config.epsilon&&J<1-l.Config.epsilon?(C=A,L=!0):L=!1}else L=!1}else L=!1;L&&C<P&&(P=C,f=E),E=k,N=Z,k=k.next}if(g)for(;;){k=t.polygon.gverts.next;let Z=k,C=0,F=y.x-N.x,O=y.y-N.y,B=v.x-y.x,D=v.y-y.y,U=Z.x-N.x,W=Z.y-N.y,q=D*U-B*W,L;if(q*q>l.Config.epsilon*l.Config.epsilon){q=1/q;let A=(W*F-U*O)*q;if(A>l.Config.epsilon&&A<1-l.Config.epsilon){let J=(D*F-B*O)*q;J>l.Config.epsilon&&J<1-l.Config.epsilon?(C=A,L=!0):L=!1}else L=!1}else L=!1;L&&C<P&&(P=C,f=E);break}if(P!=2){let Z=P,C=y.x+(v.x-y.x)*Z,F=y.y+(v.y-y.y)*Z,O;ie.zpp_pool==null?O=new ie:(O=ie.zpp_pool,ie.zpp_pool=O.next,O.next=null),O.weak=!1,O._immutable=!1,O.x=C,O.y=F,c=O,Me.flowpoly.add(c),u=!0,h=M,z=!1;break}M=w,y=v,w=w.next}if(z)for(;;){w=e.polygon.gverts.next;let v=w,P=2,g=!0,E=t.polygon.gverts.next,N=E,k=E.next;for(;k!=null;){let Z=k,C=0,F=y.x-N.x,O=y.y-N.y,B=v.x-y.x,D=v.y-y.y,U=Z.x-N.x,W=Z.y-N.y,q=D*U-B*W,L;if(q*q>l.Config.epsilon*l.Config.epsilon){q=1/q;let A=(W*F-U*O)*q;if(A>l.Config.epsilon&&A<1-l.Config.epsilon){let J=(D*F-B*O)*q;J>l.Config.epsilon&&J<1-l.Config.epsilon?(C=A,L=!0):L=!1}else L=!1}else L=!1;L&&C<P&&(P=C,f=E),E=k,N=Z,k=k.next}if(g)for(;;){k=t.polygon.gverts.next;let Z=k,C=0,F=y.x-N.x,O=y.y-N.y,B=v.x-y.x,D=v.y-y.y,U=Z.x-N.x,W=Z.y-N.y,q=D*U-B*W,L;if(q*q>l.Config.epsilon*l.Config.epsilon){q=1/q;let A=(W*F-U*O)*q;if(A>l.Config.epsilon&&A<1-l.Config.epsilon){let J=(D*F-B*O)*q;J>l.Config.epsilon&&J<1-l.Config.epsilon?(C=A,L=!0):L=!1}else L=!1}else L=!1;L&&C<P&&(P=C,f=E);break}if(P!=2){let Z=P,C=y.x+(v.x-y.x)*Z,F=y.y+(v.y-y.y)*Z,O;ie.zpp_pool==null?O=new ie:(O=ie.zpp_pool,ie.zpp_pool=O.next,O.next=null),O.weak=!1,O._immutable=!1,O.x=C,O.y=F,c=O,Me.flowpoly.add(c),u=!0,h=M;break}break}m=2}for(;;)if(u)if(h=h.next,++x,h==null&&(h=e.polygon.gverts.next,x=0),s[x]){let z=Me.flowpoly.head.elt,M=h,y=f,w=f.next;w==null&&(w=t.polygon.gverts.next);let v=-1,P=null,g=0,E=0,N=w,k=w;for(;;){let L=k,A=0,J=y.x-z.x,$=y.y-z.y,X=L.x-y.x,H=L.y-y.y,ee=M.x-z.x,G=M.y-z.y,R=H*ee-X*G,j;if(R*R>l.Config.epsilon*l.Config.epsilon){R=1/R;let V=(G*J-ee*$)*R;if(V>l.Config.epsilon&&V<1-l.Config.epsilon){let K=(H*J-X*$)*R;K>l.Config.epsilon&&K<1-l.Config.epsilon?(A=V,j=!0):j=!1}else j=!1}else j=!1;if(j&&A>=v)if(P=f,g=_,++E==m){v=A,k=N;break}else v=A;y=L,f=k,++_,_>=t.polygon.edgeCnt&&(_=0),k=k.next,k==null&&(k=t.polygon.gverts.next);break}for(;k!=N;){let L=k,A=0,J=y.x-z.x,$=y.y-z.y,X=L.x-y.x,H=L.y-y.y,ee=M.x-z.x,G=M.y-z.y,R=H*ee-X*G,j;if(R*R>l.Config.epsilon*l.Config.epsilon){R=1/R;let V=(G*J-ee*$)*R;if(V>l.Config.epsilon&&V<1-l.Config.epsilon){let K=(H*J-X*$)*R;K>l.Config.epsilon&&K<1-l.Config.epsilon?(A=V,j=!0):j=!1}else j=!1}else j=!1;if(j&&A>=v)if(P=f,g=_,++E==m){v=A;break}else v=A;y=L,f=k,++_,_>=t.polygon.edgeCnt&&(_=0),k=k.next,k==null&&(k=t.polygon.gverts.next)}if(P==null)break;let Z=P,C=P.next;C==null&&(C=t.polygon.gverts.next);let F=C,O=v,B=Z.x+(F.x-Z.x)*O,D=Z.y+(F.y-Z.y)*O,U;if(c!=null){let L=B-c.x,A=D-c.y;U=L*L+A*A<l.Config.epsilon}else U=!1;if(U)break;let W=Me.flowpoly,q;ie.zpp_pool==null?q=new ie:(q=ie.zpp_pool,ie.zpp_pool=q.next,q.next=null),q.weak=!1,q._immutable=!1,q.x=B,q.y=D,W.add(q),c==null&&(c=Me.flowpoly.head.elt),f=P,_=g,u=!u,m=2}else{let z=h,M;if(c!=null){let y=z.x-c.x,w=z.y-c.y;M=y*y+w*w<l.Config.epsilon}else M=!1;if(M)break;Me.flowpoly.add(z),c==null&&(c=Me.flowpoly.head.elt),m=1}else if(f=f.next,++_,f==null&&(f=t.polygon.gverts.next,_=0),i[_]){let z=Me.flowpoly.head.elt,M=f,y=h,w=h.next;w==null&&(w=e.polygon.gverts.next);let v=-1,P=null,g=0,E=0,N=w,k=w;for(;;){let L=k,A=0,J=y.x-z.x,$=y.y-z.y,X=L.x-y.x,H=L.y-y.y,ee=M.x-z.x,G=M.y-z.y,R=H*ee-X*G,j;if(R*R>l.Config.epsilon*l.Config.epsilon){R=1/R;let V=(G*J-ee*$)*R;if(V>l.Config.epsilon&&V<1-l.Config.epsilon){let K=(H*J-X*$)*R;K>l.Config.epsilon&&K<1-l.Config.epsilon?(A=V,j=!0):j=!1}else j=!1}else j=!1;if(j&&A>=v)if(P=h,g=x,++E==m){v=A,k=N;break}else v=A;y=L,h=k,++x,x>=e.polygon.edgeCnt&&(x=0),k=k.next,k==null&&(k=e.polygon.gverts.next);break}for(;k!=N;){let L=k,A=0,J=y.x-z.x,$=y.y-z.y,X=L.x-y.x,H=L.y-y.y,ee=M.x-z.x,G=M.y-z.y,R=H*ee-X*G,j;if(R*R>l.Config.epsilon*l.Config.epsilon){R=1/R;let V=(G*J-ee*$)*R;if(V>l.Config.epsilon&&V<1-l.Config.epsilon){let K=(H*J-X*$)*R;K>l.Config.epsilon&&K<1-l.Config.epsilon?(A=V,j=!0):j=!1}else j=!1}else j=!1;if(j&&A>=v)if(P=h,g=x,++E==m){v=A;break}else v=A;y=L,h=k,++x,x>=e.polygon.edgeCnt&&(x=0),k=k.next,k==null&&(k=e.polygon.gverts.next)}if(P==null)break;let Z=P,C=P.next;C==null&&(C=e.polygon.gverts.next);let F=C,O=v,B=Z.x+(F.x-Z.x)*O,D=Z.y+(F.y-Z.y)*O,U;if(c!=null){let L=B-c.x,A=D-c.y;U=L*L+A*A<l.Config.epsilon}else U=!1;if(U)break;let W=Me.flowpoly,q;ie.zpp_pool==null?q=new ie:(q=ie.zpp_pool,ie.zpp_pool=q.next,q.next=null),q.weak=!1,q._immutable=!1,q.x=B,q.y=D,W.add(q),c==null&&(c=Me.flowpoly.head.elt),h=P,x=g,u=!u,m=2}else{let z=f,M;if(c!=null){let y=z.x-c.x,w=z.y-c.y;M=y*y+w*w<l.Config.epsilon}else M=!1;if(M)break;Me.flowpoly.add(z),c==null&&(c=Me.flowpoly.head.elt),m=1}if(Me.flowpoly.head!=null&&Me.flowpoly.head.next!=null&&Me.flowpoly.head.next.next!=null){let z=0,M=0,y=0,w=Me.flowpoly.head,v=w.elt;w=w.next;let P=w.elt;for(w=w.next;w!=null;){let F=w.elt;z+=P.x*(F.y-v.y);let O=F.y*P.x-F.x*P.y;M+=(P.x+F.x)*O,y+=(P.y+F.y)*O,v=P,P=F,w=w.next}w=Me.flowpoly.head;let g=w.elt;z+=P.x*(g.y-v.y);let E=g.y*P.x-g.x*P.y;M+=(P.x+g.x)*E,y+=(P.y+g.y)*E,v=P,P=g,w=w.next;let N=w.elt;z+=P.x*(N.y-v.y);let k=N.y*P.x-N.x*P.y;M+=(P.x+N.x)*k,y+=(P.y+N.y)*k,z*=.5;let C=1/(6*z);return M*=C,y*=C,n.overlap=-z,n.centroidx=M,n.centroidy=y,!0}else return!1}else return!1}else return!1}else{let s=[],i=!0,r=null,o=null,a=-1e100,p=!0,c=t.polygon.gverts.next,u=0,h=t.polygon.edges.head;for(;h!=null;){let x=h.elt,f=x.gnormx*e.circle.worldCOMx+x.gnormy*e.circle.worldCOMy;if(f>x.gprojection+e.circle.radius){p=!1;break}else f+e.circle.radius>x.gprojection+l.Config.epsilon&&(i=!1,s[u]=!0);f-=x.gprojection+e.circle.radius,f>a&&(a=f,r=x,o=c),c=c.next,++u,h=h.next}if(p){if(i)return n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0;{let x=o,f=o.next==null?t.polygon.gverts.next:o.next,_=e.circle.worldCOMy*r.gnormx-e.circle.worldCOMx*r.gnormy,d;if(_<=x.y*r.gnormx-x.x*r.gnormy){let b=e.circle.radius,m=x.x-e.circle.worldCOMx,z=x.y-e.circle.worldCOMy;d=m*m+z*z<=b*b}else if(_>=f.y*r.gnormx-f.x*r.gnormy){let b=e.circle.radius,m=f.x-e.circle.worldCOMx,z=f.y-e.circle.worldCOMy;d=m*m+z*z<=b*b}else d=!0;if(d){let b=[],m=0,z=!0,M=null,y=0,w=t.polygon.gverts.next;for(;w!=null;){let v=w,P=v.x-e.circle.worldCOMx,g=v.y-e.circle.worldCOMy,E=P*P+g*g;(b[m]=E<=e.circle.radius*e.circle.radius)?(y=m,M=w):z=!1,++m,w=w.next}if(z){let v=t.polygon;if(v.zip_worldCOM&&v.body!=null){if(v.zip_worldCOM=!1,v.zip_localCOM){if(v.zip_localCOM=!1,v.type==1){let g=v.polygon;if(g.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(g.lverts.next.next==null)g.localCOMx=g.lverts.next.x,g.localCOMy=g.lverts.next.y;else if(g.lverts.next.next.next==null){g.localCOMx=g.lverts.next.x,g.localCOMy=g.lverts.next.y;let E=1;g.localCOMx+=g.lverts.next.next.x*E,g.localCOMy+=g.lverts.next.next.y*E;let N=.5;g.localCOMx*=N,g.localCOMy*=N}else{g.localCOMx=0,g.localCOMy=0;let E=0,N=g.lverts.next,k=N;N=N.next;let Z=N;for(N=N.next;N!=null;){let U=N;E+=Z.x*(U.y-k.y);let W=U.y*Z.x-U.x*Z.y;g.localCOMx+=(Z.x+U.x)*W,g.localCOMy+=(Z.y+U.y)*W,k=Z,Z=U,N=N.next}N=g.lverts.next;let C=N;E+=Z.x*(C.y-k.y);let F=C.y*Z.x-C.x*Z.y;g.localCOMx+=(Z.x+C.x)*F,g.localCOMy+=(Z.y+C.y)*F,k=Z,Z=C,N=N.next;let O=N;E+=Z.x*(O.y-k.y);let B=O.y*Z.x-O.x*Z.y;g.localCOMx+=(Z.x+O.x)*B,g.localCOMy+=(Z.y+O.y)*B,E=1/(3*E);let D=E;g.localCOMx*=D,g.localCOMy*=D}}v.wrap_localCOM!=null&&(v.wrap_localCOM.zpp_inner.x=v.localCOMx,v.wrap_localCOM.zpp_inner.y=v.localCOMy)}let P=v.body;P.zip_axis&&(P.zip_axis=!1,P.axisx=Math.sin(P.rot),P.axisy=Math.cos(P.rot)),v.worldCOMx=v.body.posx+(v.body.axisy*v.localCOMx-v.body.axisx*v.localCOMy),v.worldCOMy=v.body.posy+(v.localCOMx*v.body.axisx+v.localCOMy*v.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else{for(;Me.flowpoly.head!=null;){let g=Me.flowpoly.pop_unsafe();if(!g._inuse){let E=g;E.outer!=null&&(E.outer.zpp_inner=null,E.outer=null),E._isimmutable=null,E._validate=null,E._invalidate=null,E.next=ie.zpp_pool,ie.zpp_pool=E}}Me.flowsegs.clear();let v=null,P=1;for(M==null?(M=t.polygon.gverts.next,P=2):(v=M,Me.flowpoly.add(v));P!=0;)if(P==1)if(M=M.next,M==null&&(M=t.polygon.gverts.next),++y,y>=t.polygon.edgeCnt&&(y=0),b[y]){let g=v.x-M.x,E=v.y-M.y;if(g*g+E*E<l.Config.epsilon)break;Me.flowpoly.add(M)}else{let g=Me.flowpoly.head.elt,E=M,N=E.x-g.x,k=E.y-g.y,Z=g.x-e.circle.worldCOMx,C=g.y-e.circle.worldCOMy,F=N*N+k*k,O=2*(Z*N+C*k),B=Z*Z+C*C-e.circle.radius*e.circle.radius,D=Math.sqrt(O*O-4*F*B);F=1/(2*F);let U=(-O-D)*F,W=U<l.Config.epsilon?(-O+D)*F:U,q=0,L=0,A=W;q=g.x+(E.x-g.x)*A,L=g.y+(E.y-g.y)*A;let J=v.x-q,$=v.y-L;if(J*J+$*$<l.Config.epsilon)break;let X=Me.flowpoly,H;ie.zpp_pool==null?H=new ie:(H=ie.zpp_pool,ie.zpp_pool=H.next,H.next=null),H.weak=!1,H._immutable=!1,H.x=q,H.y=L,X.add(H),P=2}else if(P==2){let g=M.next;g==null&&(g=t.polygon.gverts.next);let E=M;P=0;let N=g,k=g;for(;;){let Z=k,C=y+1;if(C==t.polygon.edgeCnt&&(C=0),s[y])if(b[C]){let F=Z.x-E.x,O=Z.y-E.y,B=E.x-e.circle.worldCOMx,D=E.y-e.circle.worldCOMy,U=F*F+O*O,W=2*(B*F+D*O),q=B*B+D*D-e.circle.radius*e.circle.radius,L=Math.sqrt(W*W-4*U*q);U=1/(2*U);let A=(-W-L)*U,J=A<l.Config.epsilon?(-W+L)*U:A,$=0,X=0,H=J;$=E.x+(Z.x-E.x)*H,X=E.y+(Z.y-E.y)*H;let ee=v.x-$,G=v.y-X;if(ee*ee+G*G<l.Config.epsilon){P=0,k=N;break}let R;ie.zpp_pool==null?R=new ie:(R=ie.zpp_pool,ie.zpp_pool=R.next,R.next=null),R.weak=!1,R._immutable=!1,R.x=$,R.y=X;let j=R;Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(j),Me.flowpoly.add(j),P=1,k=N;break}else{let F=0,O=0,B=Z.x-E.x,D=Z.y-E.y,U=E.x-e.circle.worldCOMx,W=E.y-e.circle.worldCOMy,q=B*B+D*D,L=2*(U*B+W*D),A=U*U+W*W-e.circle.radius*e.circle.radius,J=L*L-4*q*A,$;if(J*J<l.Config.epsilon?(J<0?F=10:(O=-L/(2*q),F=O),$=!1):(J=Math.sqrt(J),q=1/(2*q),F=(-L-J)*q,O=(-L+J)*q,$=!0),F<1-l.Config.epsilon&&O>l.Config.epsilon){let X=0,H=0,ee=F;X=E.x+(Z.x-E.x)*ee,H=E.y+(Z.y-E.y)*ee;let G;if(v!=null){let V=v.x-X,K=v.y-H;G=V*V+K*K<l.Config.epsilon}else G=!1;if(G){P=0,k=N;break}let R;ie.zpp_pool==null?R=new ie:(R=ie.zpp_pool,ie.zpp_pool=R.next,R.next=null),R.weak=!1,R._immutable=!1,R.x=X,R.y=H;let j=R;if(Me.flowpoly.head!=null&&(Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(j)),Me.flowpoly.add(j),v==null&&(v=Me.flowpoly.head.elt),$){let V=0,K=0,Q=O;V=E.x+(Z.x-E.x)*Q,K=E.y+(Z.y-E.y)*Q;let Y=Me.flowpoly,ne;ie.zpp_pool==null?ne=new ie:(ne=ie.zpp_pool,ie.zpp_pool=ne.next,ne.next=null),ne.weak=!1,ne._immutable=!1,ne.x=V,ne.y=K,Y.add(ne)}}}E=Z,M=k,y=C,k=k.next,k==null&&(k=t.polygon.gverts.next);break}for(;k!=N;){let Z=k,C=y+1;if(C==t.polygon.edgeCnt&&(C=0),s[y])if(b[C]){let F=Z.x-E.x,O=Z.y-E.y,B=E.x-e.circle.worldCOMx,D=E.y-e.circle.worldCOMy,U=F*F+O*O,W=2*(B*F+D*O),q=B*B+D*D-e.circle.radius*e.circle.radius,L=Math.sqrt(W*W-4*U*q);U=1/(2*U);let A=(-W-L)*U,J=A<l.Config.epsilon?(-W+L)*U:A,$=0,X=0,H=J;$=E.x+(Z.x-E.x)*H,X=E.y+(Z.y-E.y)*H;let ee=v.x-$,G=v.y-X;if(ee*ee+G*G<l.Config.epsilon){P=0,k=N;break}let R;ie.zpp_pool==null?R=new ie:(R=ie.zpp_pool,ie.zpp_pool=R.next,R.next=null),R.weak=!1,R._immutable=!1,R.x=$,R.y=X;let j=R;Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(j),Me.flowpoly.add(j),P=1,k=N;break}else{let F=0,O=0,B=Z.x-E.x,D=Z.y-E.y,U=E.x-e.circle.worldCOMx,W=E.y-e.circle.worldCOMy,q=B*B+D*D,L=2*(U*B+W*D),A=U*U+W*W-e.circle.radius*e.circle.radius,J=L*L-4*q*A,$;if(J*J<l.Config.epsilon?(J<0?F=10:(O=-L/(2*q),F=O),$=!1):(J=Math.sqrt(J),q=1/(2*q),F=(-L-J)*q,O=(-L+J)*q,$=!0),F<1-l.Config.epsilon&&O>l.Config.epsilon){let X=0,H=0,ee=F;X=E.x+(Z.x-E.x)*ee,H=E.y+(Z.y-E.y)*ee;let G;if(v!=null){let V=v.x-X,K=v.y-H;G=V*V+K*K<l.Config.epsilon}else G=!1;if(G){P=0,k=N;break}let R;ie.zpp_pool==null?R=new ie:(R=ie.zpp_pool,ie.zpp_pool=R.next,R.next=null),R.weak=!1,R._immutable=!1,R.x=X,R.y=H;let j=R;if(Me.flowpoly.head!=null&&(Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(j)),Me.flowpoly.add(j),v==null&&(v=Me.flowpoly.head.elt),$){let V=0,K=0,Q=O;V=E.x+(Z.x-E.x)*Q,K=E.y+(Z.y-E.y)*Q;let Y=Me.flowpoly,ne;ie.zpp_pool==null?ne=new ie:(ne=ie.zpp_pool,ie.zpp_pool=ne.next,ne.next=null),ne.weak=!1,ne._immutable=!1,ne.x=V,ne.y=K,Y.add(ne)}}}E=Z,M=k,y=C,k=k.next,k==null&&(k=t.polygon.gverts.next)}}if(Me.flowpoly.head==null)return!1;if(Me.flowpoly.head.next==null){let g=!0,E=t.polygon.edges.head;for(;E!=null;){let N=E.elt;if(N.gnormx*e.circle.worldCOMx+N.gnormy*e.circle.worldCOMy>N.gprojection){g=!1;break}E=E.next}return g?(n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0):!1}else{let g=0,E=0,N=0;if(Me.flowpoly.head.next.next!=null){let Z=0,C=0,F=0;Z=0;let O=Me.flowpoly.head,B=O.elt;O=O.next;let D=O.elt;for(O=O.next;O!=null;){let X=O.elt;Z+=D.x*(X.y-B.y);let H=X.y*D.x-X.x*D.y;C+=(D.x+X.x)*H,F+=(D.y+X.y)*H,B=D,D=X,O=O.next}O=Me.flowpoly.head;let U=O.elt;Z+=D.x*(U.y-B.y);let W=U.y*D.x-U.x*D.y;C+=(D.x+U.x)*W,F+=(D.y+U.y)*W,B=D,D=U,O=O.next;let q=O.elt;Z+=D.x*(q.y-B.y);let L=q.y*D.x-q.x*D.y;C+=(D.x+q.x)*L,F+=(D.y+q.y)*L,Z*=.5;let J=1/(6*Z);C*=J,F*=J;let $=-Z;g+=C*$,E+=F*$,N-=Z}else Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(Me.flowpoly.head.next.elt);for(;Me.flowsegs.head!=null;){let Z=Me.flowsegs.pop_unsafe(),C=Me.flowsegs.pop_unsafe(),F=C.x-Z.x,O=C.y-Z.y,B=F,D=O,U=B*B+D*D,q=1/Math.sqrt(U);B*=q,D*=q;let L=B;B=-D,D=L;let A=Z.x+C.x,J=Z.y+C.y,$=.5;A*=$,J*=$;let X=1;A-=e.circle.worldCOMx*X,J-=e.circle.worldCOMy*X;let H=B*A+D*J,ee=0,G=0,R=H,j=R/e.circle.radius,V=Math.sqrt(1-j*j),K=Math.acos(j);ee=e.circle.radius*(e.circle.radius*K-R*V),G=.6666666666666666*e.circle.radius*V*V*V/(K-j*V),A=e.circle.worldCOMx,J=e.circle.worldCOMy;let Q=G;A+=B*Q,J+=D*Q;let Y=ee;g+=A*Y,E+=J*Y,N+=ee}let k=1/N;return g*=k,E*=k,n.overlap=N,n.centroidx=g,n.centroidy=E,!0}}}else return!1}}else return!1}else{let s=e.circle,i=t.circle,r=i.worldCOMx-s.worldCOMx,o=i.worldCOMy-s.worldCOMy,a=s.radius+i.radius,p=r*r+o*o;if(p>a*a)return!1;if(p<l.Config.epsilon*l.Config.epsilon)return s.radius<i.radius?(n.overlap=s.area,n.centroidx=s.worldCOMx,n.centroidy=s.worldCOMy):(n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy),!0;{let c=Math.sqrt(p),u=1/c,h=.5*(c-(i.radius*i.radius-s.radius*s.radius)*u);if(h<=-s.radius)n.overlap=s.area,n.centroidx=s.worldCOMx,n.centroidy=s.worldCOMy;else{let x=c-h;if(x<=-i.radius)n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy;else{let f=0,_=0,d=0,b=0,m=h,z=m/s.radius,M=Math.sqrt(1-z*z),y=Math.acos(z);f=s.radius*(s.radius*y-m*M),_=.6666666666666666*s.radius*M*M*M/(y-z*M);let w=x,v=w/i.radius,P=Math.sqrt(1-v*v),g=Math.acos(v);d=i.radius*(i.radius*g-w*P),b=.6666666666666666*i.radius*P*P*P/(g-v*P);let E=f+d,N=(_*f+(c-b)*d)/E*u;n.overlap=E,n.centroidx=s.worldCOMx+r*N,n.centroidy=s.worldCOMy+o*N}}return!0}}}};Me.__name__=["zpp_nape","geom","ZPP_Collide"],Me.flowpoly=null,Me.flowsegs=null;var Ne=Me;var vr=class vr{static isinner(e,t,n){let l=e.x-t.x,s=e.y-t.y,i=n.x-t.x;return(n.y-t.y)*l-i*s>=0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let i=t;for(;i.sort(),i=i.next,i!=n;);}let l=e.vertices,s=e.vertices;if(l!=null){let i=l;for(;;){let r=i,o=r.prev,a=null,p=r.diagonals.head;for(;p!=null;){let c=p.elt,u=p.next==null?r.next:p.next.elt;if(!vr.isinner(u,r,o)){a=p,o=c,p=p.next;continue}let h=!0,x=c,f=x.prev,_=null,d=x.diagonals.head;for(;d!=null;){let b=d.elt;if(b==r){let m=d.next==null?x.next:d.next.elt;h=vr.isinner(m,x,f);break}f=b,_=d,d=d.next}if(h){p=r.diagonals.erase(a),x.diagonals.erase(_);continue}o=c,a=p,p=p.next}if(i=i.next,i==s)break}}}};vr.__name__=["zpp_nape","geom","ZPP_Convex"];var zl=vr;var ct=class ct{constructor(){this.normal=null;this.shape=null;this.convex=null;this.position=null;this.ray=null;this.inner=!1;this.next=null;this.toiDistance=0}static getRay(e,t,n,l){let s;ct.rayPool==null?(ct.internal=!0,s=ct._createRayResult(),s.zpp_inner=new ct,s.zpp_inner.ray=s,ct.internal=!1):(s=ct.rayPool.ray,ct.rayPool=ct.rayPool.next,s.zpp_inner.next=null);let i=s.zpp_inner;return i.normal=e,e.zpp_inner._immutable=!0,i.toiDistance=t,i.inner=n,i.shape=l,s}static getConvex(e,t,n,l){let s;ct.convexPool==null?(ct.internal=!0,s=ct._createConvexResult(),s.zpp_inner=new ct,s.zpp_inner.convex=s,ct.internal=!1):(s=ct.convexPool.convex,ct.convexPool=ct.convexPool.next,s.zpp_inner.next=null);let i=s.zpp_inner;return i.normal=e,i.position=t,e.zpp_inner._immutable=!0,t.zpp_inner._immutable=!0,i.toiDistance=n,i.shape=l,s}disposed(){if(this.next!=null)throw new Error("Error: This object has been disposed of and cannot be used")}free(){ct._disposeVec2(this.normal),this.position!=null&&ct._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=ct.convexPool,ct.convexPool=this):(this.next=ct.rayPool,ct.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=ie.zpp_pool,ie.zpp_pool=n}};ct.__name__=["zpp_nape","geom","ZPP_ConvexRayResult"],ct.rayPool=null,ct.convexPool=null,ct.internal=!1,ct._createRayResult=null,ct._createConvexResult=null;var qt=ct;var ns=class ns{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 ns.zpp_pool==null?t=new ns:(t=ns.zpp_pool,ns.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}};ns.__name__=["zpp_nape","geom","ZPP_CutVert"],ns.zpp_pool=null;var rt=ns;var is=class is{constructor(){this.next=null;this.time=0;this.virtualint=!1;this.vertex=!1;this.path0=null;this.end=null;this.start=null;this.path1=null}static get(e,t,n,l,s,i=!1,r=!1){let o;return is.zpp_pool==null?o=new is:(o=is.zpp_pool,is.zpp_pool=o.next,o.next=null),o.virtualint=i,o.end=t,o.start=n,o.path0=l,o.path1=s,o.time=e,o.vertex=r,o}alloc(){}free(){this.end=this.start=null,this.path0=this.path1=null}};is.__name__=["zpp_nape","geom","ZPP_CutInt"],is.zpp_pool=null;var xt=is;var ki=class ki{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 ki.zpp_pool==null?n=new ki:(n=ki.zpp_pool,ki.zpp_pool=n.next,n.next=null),n.forced=!1,n.x=e,n.y=t,n}alloc(){this.forced=!1}free(){if(this.wrap!=null){this.wrap.zpp_inner._inuse=!1;let e=this.wrap;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=e.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");if(t._isimmutable!=null&&t._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let n=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let l=e;l.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=l:ue.poolVec2=l,ue.nextVec2=l,l.zpp_disp=!0;let s=n;s.outer!=null&&(s.outer.zpp_inner=null,s.outer=null),s._isimmutable=null,s._validate=null,s._invalidate=null,s.next=ie.zpp_pool,ie.zpp_pool=s,this.wrap=null}this.prev=this.next=null}wrapper(){if(this.wrap==null){let e=this.x,t=this.y;if(t==null&&(t=0),e==null&&(e=0),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(ue.poolVec2==null?n=ki._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 l;ie.zpp_pool==null?l=new ie:(l=ie.zpp_pool,ie.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=e,l.y=t,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x===e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),s=n.zpp_inner.y===t}else s=!1;if(!s){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=l=>this.modwrap(l),this.wrap.zpp_inner._validate=()=>this.getwrap()}return this.wrap}modwrap(e){this.x=e.x,this.y=e.y}getwrap(){this.wrap.zpp_inner.x=this.x,this.wrap.zpp_inner.y=this.y}};ki.__name__=["zpp_nape","geom","ZPP_GeomVert"],ki.zpp_pool=null,ki._createVec2Fn=null;var Ce=ki;var ot=class ot{static run(e,t,n,l,s,i){let r=oe(),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 u=t.zpp_inner.y;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=n.zpp_inner;h._validate!=null&&h._validate();let x=n.zpp_inner.x-p;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let f=n.zpp_inner;f._validate!=null&&f._validate();let _=n.zpp_inner.y-u,d=l?0:-1/0,b=s?1:1/0,m=-(u*x-p*_),z=null,M=!1,y=e;for(;;){let L;rt.zpp_pool==null?L=new rt:(L=rt.zpp_pool,rt.zpp_pool=L.next,L.next=null),L.vert=y,L.posx=y.x,L.posy=y.y,L.value=L.posy*x-L.posx*_+m,L.positive=L.value>0,L.value==0&&(M=!0);let A=L;if(z==null?A.prev=A.next=A:(A.prev=z,A.next=z.next,z.next.prev=A,z.next=A),z=A,y=y.next,y==e)break}if(M){let L=null,A=z,J=z;if(A!=null){let K=A;for(;;){let Q=K;if(Q.value!=0){L=Q;break}if(K=K.next,K==J)break}}let $,X;$=x,X=_;let H=$*$+X*X,G=1/Math.sqrt(H);$*=G,X*=G;let R=$;$=-X,X=R;let j=null,V=L;for(;;){if(V.value!=0&&(j==null||V==j.next)){if(j=V,V=V.next,V==L)break;continue}let K=j.value*V.value;if(K==0){if(V=V.next,V==L)break;continue}let Q=j.next,Y;if(K>0)Y=j.positive;else{let le=Q.next,se,re;se=Q.posx+le.posx,re=Q.posy+le.posy;let he=.5;se*=he,re*=he;let ce=se+$*1e-8,pe=re+X*1e-8,de=!1,te=e,_e=e;if(te!=null){let me=te;for(;;){let xe=me,ge=xe.prev;if((xe.y<pe&&ge.y>=pe||ge.y<pe&&xe.y>=pe)&&(xe.x<=ce||ge.x<=ce)&&xe.x+(pe-xe.y)/(ge.y-xe.y)*(ge.x-xe.x)<ce&&(de=!de),me=me.next,me==_e)break}}Y=de}let ne=Q,ae=V;if(ne!=null){let le=ne;for(;;){let se=le;if(se.positive=Y,le=le.next,le==ae)break}}if(j=V,V=V.next,V==L)break}for(;!(V.value!=0&&(j==null||V==j.next));){let K=j.value*V.value;if(K==0)break;let Q=j.next,Y;if(K>0)Y=j.positive;else{let le=Q.next,se,re;se=Q.posx+le.posx,re=Q.posy+le.posy;let he=.5;se*=he,re*=he;let ce=se+$*1e-8,pe=re+X*1e-8,de=!1,te=e,_e=e;if(te!=null){let me=te;for(;;){let xe=me,ge=xe.prev;if((xe.y<pe&&ge.y>=pe||ge.y<pe&&xe.y>=pe)&&(xe.x<=ce||ge.x<=ce)&&xe.x+(pe-xe.y)/(ge.y-xe.y)*(ge.x-xe.x)<ce&&(de=!de),me=me.next,me==_e)break}}Y=de}let ne=Q,ae=V;if(ne!=null){let le=ne;for(;;){let se=le;if(se.positive=Y,le=le.next,le==ae)break}}break}}ot.ints==null&&(ot.ints=new o.util.ZNPList_ZPP_CutInt),ot.paths==null&&(ot.paths=new o.util.ZNPList_ZPP_CutVert);let w=null,v=z.posx,P=z.posy,g;Ce.zpp_pool==null?g=new Ce:(g=Ce.zpp_pool,Ce.zpp_pool=g.next,g.next=null),g.forced=!1,g.x=v,g.y=P;let E=g;E.prev=E.next=E,w=E;let N=w,k;rt.zpp_pool==null?k=new rt:(k=rt.zpp_pool,rt.zpp_pool=k.next,k.next=null),k.vert=w,k.parent=k,k.rank=0,k.used=!1;let Z=k;ot.paths.add(Z);let C=z;for(;;){let L=C.next,A=L.posx,J=L.posy,$;Ce.zpp_pool==null?$=new Ce:($=Ce.zpp_pool,Ce.zpp_pool=$.next,$.next=null),$.forced=!1,$.x=A,$.y=J;let X=$;if(C.positive==L.positive){let H=X;w==null?(H.prev=H.next=H,w=H):(H.next=w,H.prev=w.prev,w.prev.next=H,w.prev=H)}else{let H=L.posx-C.posx,ee=L.posy-C.posy,G=_*H-x*ee;G=1/G;let R=p-C.posx,j=u-C.posy,V=(ee*R-H*j)*G;if(V<d||V>b){let K=ot.ints,Q=!0;Q==null&&(Q=!1);let Y;xt.zpp_pool==null?Y=new xt:(Y=xt.zpp_pool,xt.zpp_pool=Y.next,Y.next=null),Y.virtualint=Q,Y.end=null,Y.start=null,Y.path0=null,Y.path1=null,Y.time=V,Y.vertex=!1,K.add(Y);let ne=X;w==null?(ne.prev=ne.next=ne,w=ne):(ne.next=w,ne.prev=w.prev,w.prev.next=ne,w.prev=ne)}else if(C.value==0){let K=w.prev;w=null;let Q=K.x,Y=K.y,ne;Ce.zpp_pool==null?ne=new Ce:(ne=Ce.zpp_pool,Ce.zpp_pool=ne.next,ne.next=null),ne.forced=!1,ne.x=Q,ne.y=Y;let ae=ne;ae.prev=ae.next=ae,w=ae;let le=X;w==null?(le.prev=le.next=le,w=le):(le.next=w,le.prev=w.prev,w.prev.next=le,w.prev=le);let se=ot.paths.head.elt,re=ot.paths,he;rt.zpp_pool==null?he=new rt:(he=rt.zpp_pool,rt.zpp_pool=he.next,he.next=null),he.vert=w,he.parent=he,he.rank=0,he.used=!1,re.add(he);let ce=ot.paths.head.elt,pe=ot.ints,de=!0;de==null&&(de=!1);let te;xt.zpp_pool==null?te=new xt:(te=xt.zpp_pool,xt.zpp_pool=te.next,te.next=null),te.virtualint=de,te.end=K,te.start=w,te.path0=se,te.path1=ce,te.time=V,te.vertex=!1,pe.add(te)}else if(L.value==0){let K=X;w==null?(K.prev=K.next=K,w=K):(K.next=w,K.prev=w.prev,w.prev.next=K,w.prev=K);let Q=w.prev;w=null;let Y=L.posx,ne=L.posy,ae;Ce.zpp_pool==null?ae=new Ce:(ae=Ce.zpp_pool,Ce.zpp_pool=ae.next,ae.next=null),ae.forced=!1,ae.x=Y,ae.y=ne;let le=ae;le.prev=le.next=le,w=le;let se=ot.paths.head.elt,re=ot.paths,he;rt.zpp_pool==null?he=new rt:(he=rt.zpp_pool,rt.zpp_pool=he.next,he.next=null),he.vert=w,he.parent=he,he.rank=0,he.used=!1,re.add(he);let ce=ot.paths.head.elt,pe=ot.ints,de=!0;de==null&&(de=!1);let te;xt.zpp_pool==null?te=new xt:(te=xt.zpp_pool,xt.zpp_pool=te.next,te.next=null),te.virtualint=de,te.end=Q,te.start=w,te.path0=se,te.path1=ce,te.time=V,te.vertex=!1,pe.add(te)}else{let K=(_*R-x*j)*G,Q,Y;Q=C.posx,Y=C.posy;let ne=K;Q+=H*ne,Y+=ee*ne;let ae;Ce.zpp_pool==null?ae=new Ce:(ae=Ce.zpp_pool,Ce.zpp_pool=ae.next,ae.next=null),ae.forced=!1,ae.x=Q,ae.y=Y;let le=ae;w==null?(le.prev=le.next=le,w=le):(le.next=w,le.prev=w.prev,w.prev.next=le,w.prev=le);let se=w.prev;w=null;let re;Ce.zpp_pool==null?re=new Ce:(re=Ce.zpp_pool,Ce.zpp_pool=re.next,re.next=null),re.forced=!1,re.x=Q,re.y=Y;let he=re;he.prev=he.next=he,w=he;let ce=X;w==null?(ce.prev=ce.next=ce,w=ce):(ce.next=w,ce.prev=w.prev,w.prev.next=ce,w.prev=ce);let pe=ot.paths.head.elt,de=ot.paths,te;rt.zpp_pool==null?te=new rt:(te=rt.zpp_pool,rt.zpp_pool=te.next,te.next=null),te.vert=w,te.parent=te,te.rank=0,te.used=!1,de.add(te);let _e=ot.paths.head.elt,me=ot.ints,xe=!1;xe==null&&(xe=!1);let ge;xt.zpp_pool==null?ge=new xt:(ge=xt.zpp_pool,xt.zpp_pool=ge.next,ge.next=null),ge.virtualint=xe,ge.end=se,ge.start=w,ge.path0=pe,ge.path1=_e,ge.time=V,ge.vertex=!1,me.add(ge)}}if(C=C.next,C==z)break}let F=w.prev;F.next.prev=N.prev,N.prev.next=F.next,F.next=N,N.prev=F;let O=ot.paths.head.elt,B;if(Z==Z.parent)B=Z;else{let L=Z,A=null;for(;L!=L.parent;){let J=L.parent;L.parent=A,A=L,L=J}for(;A!=null;){let J=A.parent;A.parent=L,A=J}B=L}let D;if(O==O.parent)D=O;else{let L=O,A=null;for(;L!=L.parent;){let J=L.parent;L.parent=A,A=L,L=J}for(;A!=null;){let J=A.parent;A.parent=L,A=J}D=L}B!=D&&(B.rank<D.rank?B.parent=D:B.rank>D.rank?D.parent=B:(D.parent=B,B.rank++));let U=ot.ints;if(U.head!=null&&U.head.next!=null){let L=U.head,A,J,$,X,H=1,ee,G,R;for(;;){for(ee=0,J=L,L=null,A=L;J!=null;){for(++ee,$=J,G=0,R=H;$!=null&&G<H;)++G,$=$.next;for(;G>0||R>0&&$!=null;)G==0?(X=$,$=$.next,--R):R==0||$==null||J.elt.time<$.elt.time?(X=J,J=J.next,--G):(X=$,$=$.next,--R),A!=null?A.next=X:L=X,A=X;J=$}if(A.next=null,H<<=1,!(ee>1))break}U.head=L,U.modified=!0,U.pushmod=!0}for(;ot.ints.head!=null;){let L=ot.ints.pop_unsafe(),A=ot.ints.pop_unsafe();if(!L.virtualint&&!A.virtualint){L.end.next.prev=A.start.prev,A.start.prev.next=L.end.next,L.end.next=A.start,A.start.prev=L.end,A.end.next.prev=L.start.prev,L.start.prev.next=A.end.next,A.end.next=L.start,L.start.prev=A.end;let X;if(L.path0==L.path0.parent)X=L.path0;else{let R=L.path0,j=null;for(;R!=R.parent;){let V=R.parent;R.parent=j,j=R,R=V}for(;j!=null;){let V=j.parent;j.parent=R,j=V}X=R}let H;if(A.path1==A.path1.parent)H=A.path1;else{let R=A.path1,j=null;for(;R!=R.parent;){let V=R.parent;R.parent=j,j=R,R=V}for(;j!=null;){let V=j.parent;j.parent=R,j=V}H=R}X!=H&&(X.rank<H.rank?X.parent=H:X.rank>H.rank?H.parent=X:(H.parent=X,X.rank++));let ee;if(L.path1==L.path1.parent)ee=L.path1;else{let R=L.path1,j=null;for(;R!=R.parent;){let V=R.parent;R.parent=j,j=R,R=V}for(;j!=null;){let V=j.parent;j.parent=R,j=V}ee=R}let G;if(A.path0==A.path0.parent)G=A.path0;else{let R=A.path0,j=null;for(;R!=R.parent;){let V=R.parent;R.parent=j,j=R,R=V}for(;j!=null;){let V=j.parent;j.parent=R,j=V}G=R}ee!=G&&(ee.rank<G.rank?ee.parent=G:ee.rank>G.rank?G.parent=ee:(G.parent=ee,ee.rank++))}else if(L.virtualint&&!A.virtualint){let X;if(A.end!=null&&A.end.prev==A.end){A.end.next=A.end.prev=null;let G=A.end;if(G.wrap!=null){G.wrap.zpp_inner._inuse=!1;let R=G.wrap;if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let j=R.zpp_inner;if(j._immutable)throw new Error("Error: Vec2 is immutable");if(j._isimmutable!=null&&j._isimmutable(),R.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let V=R.zpp_inner;R.zpp_inner.outer=null,R.zpp_inner=null;let K=R;K.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=K:ue.poolVec2=K,ue.nextVec2=K,K.zpp_disp=!0;let Q=V;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=ie.zpp_pool,ie.zpp_pool=Q,G.wrap=null}G.prev=G.next=null,G.next=Ce.zpp_pool,Ce.zpp_pool=G,X=null}else{let G=A.end.prev;A.end.prev.next=A.end.next,A.end.next.prev=A.end.prev,A.end.next=A.end.prev=null;let R=A.end;if(R.wrap!=null){R.wrap.zpp_inner._inuse=!1;let j=R.wrap;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=j.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),j.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let K=j.zpp_inner;j.zpp_inner.outer=null,j.zpp_inner=null;let Q=j;Q.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let Y=K;Y.outer!=null&&(Y.outer.zpp_inner=null,Y.outer=null),Y._isimmutable=null,Y._validate=null,Y._invalidate=null,Y.next=ie.zpp_pool,ie.zpp_pool=Y,R.wrap=null}R.prev=R.next=null,R.next=Ce.zpp_pool,Ce.zpp_pool=R,A.end=null,X=G}if(A.end=X,!A.vertex)if(A.end!=A.path0.vert){A.start.x=A.end.x,A.start.y=A.end.y;let G;if(A.end!=null&&A.end.prev==A.end){A.end.next=A.end.prev=null;let R=A.end;if(R.wrap!=null){R.wrap.zpp_inner._inuse=!1;let j=R.wrap;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=j.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),j.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let K=j.zpp_inner;j.zpp_inner.outer=null,j.zpp_inner=null;let Q=j;Q.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let Y=K;Y.outer!=null&&(Y.outer.zpp_inner=null,Y.outer=null),Y._isimmutable=null,Y._validate=null,Y._invalidate=null,Y.next=ie.zpp_pool,ie.zpp_pool=Y,R.wrap=null}R.prev=R.next=null,R.next=Ce.zpp_pool,Ce.zpp_pool=R,G=null}else{let R=A.end.prev;A.end.prev.next=A.end.next,A.end.next.prev=A.end.prev,A.end.next=A.end.prev=null;let j=A.end;if(j.wrap!=null){j.wrap.zpp_inner._inuse=!1;let V=j.wrap;if(V!=null&&V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let K=V.zpp_inner;if(K._immutable)throw new Error("Error: Vec2 is immutable");if(K._isimmutable!=null&&K._isimmutable(),V.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let Q=V.zpp_inner;V.zpp_inner.outer=null,V.zpp_inner=null;let Y=V;Y.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Y:ue.poolVec2=Y,ue.nextVec2=Y,Y.zpp_disp=!0;let ne=Q;ne.outer!=null&&(ne.outer.zpp_inner=null,ne.outer=null),ne._isimmutable=null,ne._validate=null,ne._invalidate=null,ne.next=ie.zpp_pool,ie.zpp_pool=ne,j.wrap=null}j.prev=j.next=null,j.next=Ce.zpp_pool,Ce.zpp_pool=j,A.end=null,G=R}A.end=G}else{let G=A.start.next;if(A.start.x=G.x,A.start.y=G.y,G!=null&&G.prev==G){G.next=G.prev=null;let R=G;if(R.wrap!=null){R.wrap.zpp_inner._inuse=!1;let j=R.wrap;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=j.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),j.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let K=j.zpp_inner;j.zpp_inner.outer=null,j.zpp_inner=null;let Q=j;Q.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let Y=K;Y.outer!=null&&(Y.outer.zpp_inner=null,Y.outer=null),Y._isimmutable=null,Y._validate=null,Y._invalidate=null,Y.next=ie.zpp_pool,ie.zpp_pool=Y,R.wrap=null}R.prev=R.next=null,R.next=Ce.zpp_pool,Ce.zpp_pool=R}else{G.prev.next=G.next,G.next.prev=G.prev,G.next=G.prev=null;let R=G;if(R.wrap!=null){R.wrap.zpp_inner._inuse=!1;let j=R.wrap;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=j.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),j.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let K=j.zpp_inner;j.zpp_inner.outer=null,j.zpp_inner=null;let Q=j;Q.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let Y=K;Y.outer!=null&&(Y.outer.zpp_inner=null,Y.outer=null),Y._isimmutable=null,Y._validate=null,Y._invalidate=null,Y.next=ie.zpp_pool,ie.zpp_pool=Y,R.wrap=null}R.prev=R.next=null,R.next=Ce.zpp_pool,Ce.zpp_pool=R}}A.end.next.prev=A.start.prev,A.start.prev.next=A.end.next,A.end.next=A.start,A.start.prev=A.end;let H;if(A.path0==A.path0.parent)H=A.path0;else{let G=A.path0,R=null;for(;G!=G.parent;){let j=G.parent;G.parent=R,R=G,G=j}for(;R!=null;){let j=R.parent;R.parent=G,R=j}H=G}let ee;if(A.path1==A.path1.parent)ee=A.path1;else{let G=A.path1,R=null;for(;G!=G.parent;){let j=G.parent;G.parent=R,R=G,G=j}for(;R!=null;){let j=R.parent;R.parent=G,R=j}ee=G}H!=ee&&(H.rank<ee.rank?H.parent=ee:H.rank>ee.rank?ee.parent=H:(ee.parent=H,H.rank++))}else if(A.virtualint&&!L.virtualint){let X;if(L.end!=null&&L.end.prev==L.end){L.end.next=L.end.prev=null;let G=L.end;if(G.wrap!=null){G.wrap.zpp_inner._inuse=!1;let R=G.wrap;if(R!=null&&R.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let j=R.zpp_inner;if(j._immutable)throw new Error("Error: Vec2 is immutable");if(j._isimmutable!=null&&j._isimmutable(),R.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let V=R.zpp_inner;R.zpp_inner.outer=null,R.zpp_inner=null;let K=R;K.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=K:ue.poolVec2=K,ue.nextVec2=K,K.zpp_disp=!0;let Q=V;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=ie.zpp_pool,ie.zpp_pool=Q,G.wrap=null}G.prev=G.next=null,G.next=Ce.zpp_pool,Ce.zpp_pool=G,X=null}else{let G=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 R=L.end;if(R.wrap!=null){R.wrap.zpp_inner._inuse=!1;let j=R.wrap;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=j.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),j.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let K=j.zpp_inner;j.zpp_inner.outer=null,j.zpp_inner=null;let Q=j;Q.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let Y=K;Y.outer!=null&&(Y.outer.zpp_inner=null,Y.outer=null),Y._isimmutable=null,Y._validate=null,Y._invalidate=null,Y.next=ie.zpp_pool,ie.zpp_pool=Y,R.wrap=null}R.prev=R.next=null,R.next=Ce.zpp_pool,Ce.zpp_pool=R,L.end=null,X=G}if(L.end=X,!L.vertex)if(L.end!=L.path0.vert){L.start.x=L.end.x,L.start.y=L.end.y;let G;if(L.end!=null&&L.end.prev==L.end){L.end.next=L.end.prev=null;let R=L.end;if(R.wrap!=null){R.wrap.zpp_inner._inuse=!1;let j=R.wrap;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=j.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),j.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let K=j.zpp_inner;j.zpp_inner.outer=null,j.zpp_inner=null;let Q=j;Q.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let Y=K;Y.outer!=null&&(Y.outer.zpp_inner=null,Y.outer=null),Y._isimmutable=null,Y._validate=null,Y._invalidate=null,Y.next=ie.zpp_pool,ie.zpp_pool=Y,R.wrap=null}R.prev=R.next=null,R.next=Ce.zpp_pool,Ce.zpp_pool=R,G=null}else{let R=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 j=L.end;if(j.wrap!=null){j.wrap.zpp_inner._inuse=!1;let V=j.wrap;if(V!=null&&V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let K=V.zpp_inner;if(K._immutable)throw new Error("Error: Vec2 is immutable");if(K._isimmutable!=null&&K._isimmutable(),V.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let Q=V.zpp_inner;V.zpp_inner.outer=null,V.zpp_inner=null;let Y=V;Y.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Y:ue.poolVec2=Y,ue.nextVec2=Y,Y.zpp_disp=!0;let ne=Q;ne.outer!=null&&(ne.outer.zpp_inner=null,ne.outer=null),ne._isimmutable=null,ne._validate=null,ne._invalidate=null,ne.next=ie.zpp_pool,ie.zpp_pool=ne,j.wrap=null}j.prev=j.next=null,j.next=Ce.zpp_pool,Ce.zpp_pool=j,L.end=null,G=R}L.end=G}else{let G=L.start.next;if(L.start.x=G.x,L.start.y=G.y,G!=null&&G.prev==G){G.next=G.prev=null;let R=G;if(R.wrap!=null){R.wrap.zpp_inner._inuse=!1;let j=R.wrap;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=j.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),j.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let K=j.zpp_inner;j.zpp_inner.outer=null,j.zpp_inner=null;let Q=j;Q.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let Y=K;Y.outer!=null&&(Y.outer.zpp_inner=null,Y.outer=null),Y._isimmutable=null,Y._validate=null,Y._invalidate=null,Y.next=ie.zpp_pool,ie.zpp_pool=Y,R.wrap=null}R.prev=R.next=null,R.next=Ce.zpp_pool,Ce.zpp_pool=R}else{G.prev.next=G.next,G.next.prev=G.prev,G.next=G.prev=null;let R=G;if(R.wrap!=null){R.wrap.zpp_inner._inuse=!1;let j=R.wrap;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=j.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),j.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let K=j.zpp_inner;j.zpp_inner.outer=null,j.zpp_inner=null;let Q=j;Q.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=Q:ue.poolVec2=Q,ue.nextVec2=Q,Q.zpp_disp=!0;let Y=K;Y.outer!=null&&(Y.outer.zpp_inner=null,Y.outer=null),Y._isimmutable=null,Y._validate=null,Y._invalidate=null,Y.next=ie.zpp_pool,ie.zpp_pool=Y,R.wrap=null}R.prev=R.next=null,R.next=Ce.zpp_pool,Ce.zpp_pool=R}}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 H;if(L.path0==L.path0.parent)H=L.path0;else{let G=L.path0,R=null;for(;G!=G.parent;){let j=G.parent;G.parent=R,R=G,G=j}for(;R!=null;){let j=R.parent;R.parent=G,R=j}H=G}let ee;if(L.path1==L.path1.parent)ee=L.path1;else{let G=L.path1,R=null;for(;G!=G.parent;){let j=G.parent;G.parent=R,R=G,G=j}for(;R!=null;){let j=R.parent;R.parent=G,R=j}ee=G}H!=ee&&(H.rank<ee.rank?H.parent=ee:H.rank>ee.rank?ee.parent=H:(ee.parent=H,H.rank++))}let J=L;J.end=J.start=null,J.path0=J.path1=null,J.next=xt.zpp_pool,xt.zpp_pool=J;let $=A;$.end=$.start=null,$.path0=$.path1=null,$.next=xt.zpp_pool,xt.zpp_pool=$}let W=i??new r.geom.GeomPolyList,q=ot.paths.head;for(;q!=null;){let L=q.elt,A;if(L==L.parent)A=L;else{let X=L,H=null;for(;X!=X.parent;){let ee=X.parent;X.parent=H,H=X,X=ee}for(;H!=null;){let ee=H.parent;H.parent=X,H=ee}A=X}if(A.used){q=q.next;continue}A.used=!0;let J=A.vert,$=!0;for(;A.vert!=null&&($||J!=A.vert);)if($=!1,J.x==J.next.x&&J.y==J.next.y)if(J==A.vert&&(A.vert=J.next==J?null:J.next,$=!0),J!=null&&J.prev==J)J.next=J.prev=null,J=null;else{let X=J.next;J.prev.next=J.next,J.next.prev=J.prev,J.next=J.prev=null,J=X}else J=J.next;if(A.vert!=null){let X=r.geom.GeomPoly.get();X.zpp_inner.vertices=A.vert,W.zpp_inner.reverse_flag?W.push(X):W.unshift(X)}q=q.next}for(;ot.paths.head!=null;){let A=ot.paths.pop_unsafe();A.vert=null,A.parent=null,A.next=rt.zpp_pool,rt.zpp_pool=A}for(;z!=null;)if(z!=null&&z.prev==z){z.next=z.prev=null;let L=z;L.vert=null,L.parent=null,L.next=rt.zpp_pool,rt.zpp_pool=L,z=null}else{let L=z.next;z.prev.next=z.next,z.next.prev=z.prev,z.next=z.prev=null;let A=z;A.vert=null,A.parent=null,A.next=rt.zpp_pool,rt.zpp_pool=A,z=L}return W}};ot.__name__=["zpp_nape","geom","ZPP_Cutter"],ot.ints=null,ot.paths=null;var Pl=ot;var wl=class wl{static validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=t.body.posx+(t.body.axisy*h.x-t.body.axisx*h.y),u.y=t.body.posy+(h.x*t.body.axisx+h.y*t.body.axisy),c=c.next}}let l=t.edges.head,s=t.gverts.next,i=s;for(s=s.next;s!=null;){let a=s,p=l.elt;l=l.next,p.gp0=i,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,i=a,s=s.next}let r=t.gverts.next,o=l.elt;o.gp0=i,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;wl._validateWorldCOM(t);let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,r=t.gverts.next;for(;r!=null;){let o=r,a=i;i=i.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 l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type==1&&wl._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&&wl._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy));let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}static _computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null){e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;let t=1;e.localCOMx+=e.lverts.next.next.x*t,e.localCOMy+=e.lverts.next.next.y*t;let n=.5;e.localCOMx*=n,e.localCOMy*=n}else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,l=n;n=n.next;let s=n;for(n=n.next;n!=null;){let c=n;t+=s.x*(c.y-l.y);let u=c.y*s.x-c.x*s.y;e.localCOMx+=(s.x+c.x)*u,e.localCOMy+=(s.y+c.y)*u,l=s,s=c,n=n.next}n=e.lverts.next;let i=n;t+=s.x*(i.y-l.y);let r=i.y*s.x-i.x*s.y;e.localCOMx+=(s.x+i.x)*r,e.localCOMy+=(s.y+i.y)*r,l=s,s=i,n=n.next;let o=n;t+=s.x*(o.y-l.y);let a=o.y*s.x-o.x*s.y;e.localCOMx+=(s.x+o.x)*a,e.localCOMy+=(s.y+o.y)*a,t=1/(3*t);let p=t;e.localCOMx*=p,e.localCOMy*=p}}};wl.__name__=["zpp_nape","geom","ZPP_Geom"];var hn=wl;var Ds=class{constructor(e=null){this.outer=null;this.vertices=null;this.outer=e}};Ds.__name__=["zpp_nape","geom","ZPP_GeomPoly"];var Rn=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}};Rn.__name__=["zpp_nape","geom","ZPP_MarchSpan"],Rn.zpp_pool=null;var Gn=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(){}};Gn.__name__=["zpp_nape","geom","ZPP_MarchPair"],Gn.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 Ce.zpp_pool==null?n=new Ce:(n=Ce.zpp_pool,Ce.zpp_pool=n.next,n.next=null),n.forced=!1,n.x=e,n.y=t,n}static _freeVert(e){if(e.wrap!=null){e.wrap.zpp_inner._inuse=!1;let t=e.wrap;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=t.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let l=t.zpp_inner;t.zpp_inner.outer=null,t.zpp_inner=null;let s=t;s.zpp_pool=null,ue.nextVec2!=null?ue.nextVec2.zpp_pool=s:ue.poolVec2=s,ue.nextVec2=s,s.zpp_disp=!0;let i=l;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i._isimmutable=null,i._validate=null,i._invalidate=null,i.next=ie.zpp_pool,ie.zpp_pool=i,e.wrap=null}e.prev=e.next=null,e.next=Ce.zpp_pool,Ce.zpp_pool=e}static _allocSpan(){let e;return Rn.zpp_pool==null?e=new Rn:(e=Rn.zpp_pool,Rn.zpp_pool=e.next,e.next=null),e.out=!1,e.rank=0,e}static _allocPair(){let e;return Gn.zpp_pool==null?e=new Gn:(e=Gn.zpp_pool,Gn.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=Gn.zpp_pool,Gn.zpp_pool=e}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let l=t.parent;t.parent=n,n=t,t=l}for(;n!=null;){let l=n.parent;n.parent=t,n=l}return t}static _union(e,t){let n=Pe._findRoot(e),l=Pe._findRoot(t);n!=l&&(n.rank<l.rank?n.parent=l:n.rank>l.rank?l.parent=n:(l.parent=n,n.rank++))}static _pushVert(e,t){return e==null?t.prev=t.next=t:(t.prev=e,t.next=e.next,e.next.prev=t,e.next=t),t}static _isDegenKey(e){return e==1||e==4||e==16||e==64||e==3||e==12||e==48||e==192||e==129||e==6||e==24||e==96||e==5||e==20||e==80||e==65||e==17||e==68}static ISO(e,t,n){return e(t,n)}static run(e,t,n,l,s,i,r,o,a){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate();let c=(l-t)/i.zpp_inner.x,u=c|0;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");p=i.zpp_inner,p._validate!=null&&p._validate();let h=(s-n)/i.zpp_inner.y,x=h|0;c!=u&&++u,h!=x&&++x,o&&(Pe.map==null?Pe.map=new Cs(u,x):Pe.map.resize(u,x,null)),Pe.isos==null?Pe.isos=new vs(u+1,x+1):Pe.isos.resize(u+1,x+1,0);for(let d=0;d<x+1;d++){let b;if(d==0)b=n;else if(d<=x){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let m=i.zpp_inner;m._validate!=null&&m._validate(),b=n+i.zpp_inner.y*d}else b=s;for(let m=0;m<u+1;m++){let z;if(m==0)z=t;else if(m<=u){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let w=i.zpp_inner;w._validate!=null&&w._validate(),z=t+i.zpp_inner.x*m}else z=l;let M=Pe.isos,y=e(z,b);M.list[d*M.width+m]=y}}Pe.ints==null?Pe.ints=new gs(u+1,(x<<1)+1):Pe.ints.resize(u+1,(x<<1)+1,null);let f=null;o&&(f=Pe._allocSpan(),f.next=null);let _=n;for(let d=0;d<x;d++){let b=_,m;if(d==x-1)m=s;else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let y=i.zpp_inner;y._validate!=null&&y._validate(),m=n+i.zpp_inner.y*(d+1)}_=m;let z=t,M=null;for(let y=0;y<u;y++){let w=z,v;if(y==u-1)v=l;else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Z=i.zpp_inner;Z._validate!=null&&Z._validate(),v=t+i.zpp_inner.x*(y+1)}z=v;let P=y==0||!o,g=d==0||!o,E=y==u-1||!o,N=d==x-1||!o,k=Pe.me.marchSquare(e,Pe.isos,Pe.ints,w,b,v,m,y,d,P,g,E,N,r);if(k==null){M=null;continue}if(o){let Z=k.p2!=null&&k.okey2!=14?k.p2:k.p1;k.pd=((Z==k.p2?k.okey2:k.okey1)&128)==0?Z.prev:Z.prev.prev;let C=Pe.map;C.list[d*C.width+y]=k;let F;if(M!=null){let D=k.key1,U=D&1|(D&192)>>5,W=0;(U&1)!=0&&++W,(U&2)!=0&&++W,(U&4)!=0&&++W,F=W>=2}else F=!1;F?(Pe.me.combLR(M,k),k.span1=M.spanr):(k.span1=Pe._allocSpan(),k.span1.next=f,f=k.span1),k.p2!=null?(k.span2=Pe._allocSpan(),k.span2.next=f,f=k.span2,k.spanr=k.span2):k.spanr=k.span1;let O=(k.keyr&28)>>2,B=0;(O&1)!=0&&++B,(O&2)!=0&&++B,(O&4)!=0&&++B,B>=2?M=k:M=null}else Pe.me.output(a,k.p1),k.p2!=null&&Pe.me.output(a,k.p2),Pe._freePair(k)}}if(o){for(let d=1;d<x;d++){let b=null;for(let m=0;m<u;m++){let z=Pe.map,M=z.list[d*z.width+m];if(M==null){b=null;continue}let w=(M.p2!=null&&M.okey2==14?M.okey2:M.okey1)&7,v=0;if((w&1)!=0&&++v,(w&2)!=0&&++v,(w&4)!=0&&++v,v<2){b=null;continue}let P=Pe.map,g=P.list[(d-1)*P.width+m];if(g==null){b=null;continue}let N=((g.p2!=null&&g.okey2==56?g.okey2:g.okey1)&112)>>4,k=0;if((N&1)!=0&&++k,(N&2)!=0&&++k,(N&4)!=0&&++k,k<2){b=null;continue}let Z=g.p2!=null&&g.okey2==56?g.span2:g.span1,C=M.p2!=null&&M.okey2==14?M.span2:M.span1,F=Pe._findRoot(Z),O=Pe._findRoot(C);F==O?b!=C&&Pe.me.combUD_virtual(g,M):(Pe._union(Z,C),Pe.me.combUD(g,M)),b=((C==M.span2?M.okey2:M.okey1)&4)!=0?C:null}}for(let d=0;d<x;d++)for(let b=0;b<u;b++){let m=Pe.map,z=m.list[d*m.width+b];if(z==null)continue;let M=Pe._findRoot(z.span1);M.out||(M.out=!0,Pe.me.output(a,z.p1)),z.p2!=null&&(M=Pe._findRoot(z.span2),M.out||(M.out=!0,Pe.me.output(a,z.p2))),Pe._freePair(z),m.list[d*m.width+b]=null}for(;f!=null;){let d=f;f=d.next;let b=d;b.parent=b,b.next=Rn.zpp_pool,Rn.zpp_pool=b}}}output(e,t){let n=Pe._nape,l;if(t==null||t.next==t||t.next==t.prev)l=!0;else{let r=0,o=t,a=t;if(o!=null){let c=o;for(;;){let u=c;if(r+=u.x*(u.next.y-u.prev.y),c=c.next,c==a)break}}let p=r*.5;l=p*p<n.Config.epsilon*n.Config.epsilon}if(l){for(;t!=null;)if(t!=null&&t.prev==t)t.next=t.prev=null,t=null;else{let r=t.next;t.prev.next=t.next,t.next.prev=t.prev,t.next=t.prev=null,t=r}return}let s=n.geom.GeomPoly.get();s.zpp_inner.vertices=t;let i=e;i.zpp_inner.reverse_flag?i.push(s):i.unshift(s)}linkright(e,t){let n=t&7;return n==0?e:n==3?e.next.next:e.next}linkleft(e,t){return(t&1)==0?e.prev:e}linkdown(e,t){return(t&128)==0?e.prev:e.prev.prev}linkup(e,t){return e}combLR(e,t){let n=e.pr,l=e.okeyr&7,s=l==0?n:l==3?n.next.next:n.next,i=t.p1,r=(t.okey1&1)==0?i.prev:i,o=s.next,a=r.prev;(e.keyr&4)!=0?(t.pr==t.p1&&(t.pr=s.prev),t.p1=s.prev,s.prev.next=r.next,r.next.prev=s.prev,Pe._freeVert(s)):(s.next=r.next,r.next.prev=s),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,l=t.p2!=null&&t.key2==14?t.p2:t.p1,s=n.prev,i=l.next;l.next=n.next,n.next.prev=l,Pe._freeVert(n),i.prev=s.prev,s.prev.next=i,s==e.p1&&(e.p1=i),Pe._freeVert(s)}combUD_virtual(e,t){let n=e.pd,l=t.p2!=null&&t.key2==14?t.p2:t.p1,s=n.prev,i=l.next;n.forced=l.forced=s.forced=i.forced=!0}combLeft(e){let t=e&1|(e&192)>>5,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combRight(e){let t=(e&28)>>2,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combUp(e){let t=e&7,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combDown(e){let t=(e&112)>>4,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}comb(e){let t=0;return(e&1)!=0&&++t,(e&2)!=0&&++t,(e&4)!=0&&++t,t>=2}_buildPoly(e,t,n,l,s,i,r,o,a,p,c,u,h,x,f,_,d,b,m){let z=null;for(let M=0;M<8;M++)if((e&1<<M)!=0){let y;if(M==0)y=Pe._allocVert(l,s),(x||f)&&(y.forced=!0);else if(M==2)y=Pe._allocVert(i,s),(_||f)&&(y.forced=!0);else if(M==4)y=Pe._allocVert(i,r),(_||d)&&(y.forced=!0);else if(M==6)y=Pe._allocVert(l,r),(x||d)&&(y.forced=!0);else if(M==1){if(y=n.list[(a<<1)*n.width+o],y==null){let w=this.xlerp(l,i,s,p,c,b,m);y=Pe._allocVert(w,s),n.list[(a<<1)*n.width+o]=y}else y=Pe._allocVert(y.x,y.y);f&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&1)!=0||y.x==i&&(e&4)!=0)&&(e^=2)}else if(M==5){if(y=n.list[((a<<1)+2)*n.width+o],y==null){let w=this.xlerp(l,i,r,h,u,b,m);y=Pe._allocVert(w,r),n.list[((a<<1)+2)*n.width+o]=y}else y=Pe._allocVert(y.x,y.y);d&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&64)!=0||y.x==i&&(e&16)!=0)&&(e^=32)}else if(M==3){if(y=n.list[((a<<1)+1)*n.width+(o+1)],y==null){let w=this.ylerp(s,r,i,c,u,b,m);y=Pe._allocVert(i,w),n.list[((a<<1)+1)*n.width+(o+1)]=y}else y=Pe._allocVert(y.x,y.y);_&&(y.forced=!0),(y.y==s||y.y==r)&&(y.y==s&&(e&4)!=0||y.y==r&&(e&16)!=0)&&(e^=8)}else{if(y=n.list[((a<<1)+1)*n.width+o],y==null){let w=this.ylerp(s,r,l,p,h,b,m);y=Pe._allocVert(l,w),n.list[((a<<1)+1)*n.width+o]=y}else y=Pe._allocVert(y.x,y.y);x&&(y.forced=!0),(y.y==s||y.y==r)&&(y.y==s&&(e&1)!=0||y.y==r&&(e&64)!=0)&&(e^=128)}z=Pe._pushVert(z,y)}return z!=null&&(z=z.next),{head:z,val:e}}marchSquare(e,t,n,l,s,i,r,o,a,p,c,u,h,x){let f=0,_=t.list[a*t.width+o];_<0&&(f|=8);let d=t.list[a*t.width+(o+1)];d<0&&(f|=4);let b=t.list[(a+1)*t.width+(o+1)];b<0&&(f|=2);let m=t.list[(a+1)*t.width+o];if(m<0&&(f|=1),f==0)return null;let z=Pe._allocPair();if(f!=10&&f!=5){let M=Pe.look_march[f];z.okey1=M;let y=this._buildPoly(M,t,n,l,s,i,r,o,a,_,d,b,m,p,c,u,h,e,x);z.p1=y.head,M=y.val,z.key1=M,Pe._isDegenKey(M)&&(M=0,z.key1=0,z.p1=null),M==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}else{let M=e(.5*(l+i),.5*(s+r))<0;if(f==10)if(M){let y=187;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,r,o,a,_,d,b,m,p,c,u,h,e,x);z.p1=w.head,y=w.val,z.key1=y,Pe._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}else{let y=131;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,r,o,a,_,d,b,m,p,c,u,h,e,x);if(z.p1=w.head,y=w.val,z.key1=y,Pe._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y!=0){let v=56;z.okey2=v,v=this._buildPoly2(v,t,n,l,s,i,r,o,a,_,d,b,m,p,c,u,h,e,x,z).val,z.key2=v,Pe._isDegenKey(v)&&(v=0,z.key2=0,z.p2=null),v==0?(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1):(z.pr=z.p2,z.okeyr=z.okey2,z.keyr=z.key2)}else{let v=56;z.okey1=v;let P=this._buildPoly(v,t,n,l,s,i,r,o,a,_,d,b,m,p,c,u,h,e,x);z.p1=P.head,v=P.val,z.key1=v,Pe._isDegenKey(v)&&(v=0,z.key1=0,z.p1=null),v==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}}else if(M){let y=238;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,r,o,a,_,d,b,m,p,c,u,h,e,x);z.p1=w.head,y=w.val,z.key1=y,Pe._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}else{let y=224;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,r,o,a,_,d,b,m,p,c,u,h,e,x);if(z.p1=w.head,y=w.val,z.key1=y,Pe._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y!=0){let v=14;z.okey2=v,v=this._buildPoly2(v,t,n,l,s,i,r,o,a,_,d,b,m,p,c,u,h,e,x,z).val,z.key2=v,Pe._isDegenKey(v)&&(v=0,z.key2=0,z.p2=null),v==0?(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1):(z.pr=z.p2,z.okeyr=z.okey2,z.keyr=z.key2)}else{let v=14;z.okey1=v;let P=this._buildPoly(v,t,n,l,s,i,r,o,a,_,d,b,m,p,c,u,h,e,x);z.p1=P.head,v=P.val,z.key1=v,Pe._isDegenKey(v)&&(v=0,z.key1=0,z.p1=null),v==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}}}return z}_buildPoly2(e,t,n,l,s,i,r,o,a,p,c,u,h,x,f,_,d,b,m,z){for(let M=0;M<8;M++)if((e&1<<M)!=0){let y;if(M==0)y=Pe._allocVert(l,s),(x||f)&&(y.forced=!0);else if(M==2)y=Pe._allocVert(i,s),(_||f)&&(y.forced=!0);else if(M==4)y=Pe._allocVert(i,r),(_||d)&&(y.forced=!0);else if(M==6)y=Pe._allocVert(l,r),(x||d)&&(y.forced=!0);else if(M==1){if(y=n.list[(a<<1)*n.width+o],y==null){let v=this.xlerp(l,i,s,p,c,b,m);y=Pe._allocVert(v,s),n.list[(a<<1)*n.width+o]=y}else y=Pe._allocVert(y.x,y.y);f&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&1)!=0||y.x==i&&(e&4)!=0)&&(e^=2)}else if(M==5){if(y=n.list[((a<<1)+2)*n.width+o],y==null){let v=this.xlerp(l,i,r,h,u,b,m);y=Pe._allocVert(v,r),n.list[((a<<1)+2)*n.width+o]=y}else y=Pe._allocVert(y.x,y.y);d&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&64)!=0||y.x==i&&(e&16)!=0)&&(e^=32)}else if(M==3){if(y=n.list[((a<<1)+1)*n.width+(o+1)],y==null){let v=this.ylerp(s,r,i,c,u,b,m);y=Pe._allocVert(i,v),n.list[((a<<1)+1)*n.width+(o+1)]=y}else y=Pe._allocVert(y.x,y.y);_&&(y.forced=!0),(y.y==s||y.y==r)&&(y.y==s&&(e&4)!=0||y.y==r&&(e&16)!=0)&&(e^=8)}else{if(y=n.list[((a<<1)+1)*n.width+o],y==null){let v=this.ylerp(s,r,l,p,h,b,m);y=Pe._allocVert(l,v),n.list[((a<<1)+1)*n.width+o]=y}else y=Pe._allocVert(y.x,y.y);x&&(y.forced=!0),(y.y==s||y.y==r)&&(y.y==s&&(e&1)!=0||y.y==r&&(e&64)!=0)&&(e^=128)}let w=y;z.p2==null?z.p2=w.prev=w.next=w:(w.prev=z.p2,w.next=z.p2.next,z.p2.next.prev=w,z.p2.next=w),z.p2=w}return z.p2!=null&&(z.p2=z.p2.next),{val:e}}lerp(e,t,n,l){let s=Pe._nape;if(n==0)return e;if(l==0)return t;{let i=n-l,r=i*i<s.Config.epsilon*s.Config.epsilon?.5:n/i;return r<0?r=0:r>1&&(r=1),e+r*(t-e)}}xlerp(e,t,n,l,s,i,r){let o=Pe._nape,a;if(l==0)a=e;else if(s==0)a=t;else{let p=l-s,c=p*p<o.Config.epsilon*o.Config.epsilon?.5:l/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;r--!=0&&e<a&&a<t;){let p=i(a,n);if(p==0)break;if(l*p<0?(t=a,s=p):(e=a,l=p),l==0)a=e;else if(s==0)a=t;else{let c=l-s,u=c*c<o.Config.epsilon*o.Config.epsilon?.5:l/c;u<0?u=0:u>1&&(u=1),a=e+u*(t-e)}}return a}ylerp(e,t,n,l,s,i,r){let o=Pe._nape,a;if(l==0)a=e;else if(s==0)a=t;else{let p=l-s,c=p*p<o.Config.epsilon*o.Config.epsilon?.5:l/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;r--!=0&&e<a&&a<t;){let p=i(n,a);if(p==0)break;if(l*p<0?(t=a,s=p):(e=a,l=p),l==0)a=e;else if(s==0)a=t;else{let c=l-s,u=c*c<o.Config.epsilon*o.Config.epsilon?.5:l/c;u<0?u=0:u>1&&(u=1),a=e+u*(t-e)}}return a}};Pe.__name__=["zpp_nape","geom","ZPP_MarchingSquares"],Pe.isos=null,Pe.ints=null,Pe.map=null,Pe._zpp=null,Pe._nape=null;var Fs=Pe;var Pn=class Pn{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 Pn.zpp_pool==null?e=new Pn:(e=Pn.zpp_pool,Pn.zpp_pool=e.next,e.next=null),e}static identity(){let e=Pn.get();return e.setas(1,0,0,1,0,0),e}wrapper(){if(this.outer==null)if(Pn._wrapFn)this.outer=Pn._wrapFn(this);else{this.outer=new Pn._nape.geom.Mat23;let e=this.outer.zpp_inner;e.next=Pn.zpp_pool,Pn.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}invalidate(){this._invalidate!=null&&this._invalidate()}set(e){this.setas(e.a,e.b,e.c,e.d,e.tx,e.ty)}setas(e,t,n,l,s,i){this.tx=s,this.ty=i,this.a=e,this.b=t,this.c=n,this.d=l}free(){}alloc(){}};Pn.__name__=["zpp_nape","geom","ZPP_Mat23"],Pn._nape=null,Pn._wrapFn=null,Pn.zpp_pool=null;var Ri=Pn;var ss=class{constructor(e,t){this.outer=null;this.m=0;this.n=0;this.m=e,this.n=t,this.x=[];let n=0,l=e*t;for(;n<l;)n++,this.x.push(0)}};ss.__name__=["zpp_nape","geom","ZPP_MatMN"];var Zt=class Zt{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=Zt.nextId++,this.diagonals=new $i}static get(e){let t;return Zt.zpp_pool==null?t=new Zt:(t=Zt.zpp_pool,Zt.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t}static rightdistance(e,t){let n=e.next.y>e.y,l=e.next.x-e.x,s=e.next.y-e.y,i=t.x-e.x,r=t.y-e.y;return(n?-1:1)*(r*l-i*s)}static vert_lt(e,t){if(t==e||t==e.next)return!0;if(e.y==e.next.y){let n=e.x,l=e.next.x;return(n<l?n:l)<=t.x}else return Zt.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!Zt.vert_lt(e,t);if(t==e.next)return Zt.vert_lt(t,e);if(e.y==e.next.y)if(t.y==t.next.y){let n=e.x,l=e.next.x,s=t.x,i=t.next.x;return(n>l?n:l)>(s>i?s:i)}else return Zt.rightdistance(t,e)>0?!0:Zt.rightdistance(t,e.next)>0;else{let n=Zt.rightdistance(e,t),l=Zt.rightdistance(e,t.next);if(n==0&&l==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*l>=0)return n<0?!0:l<0;let s=Zt.rightdistance(t,e),i=Zt.rightdistance(t,e.next);return s*i>=0?s>0?!0:i>0:!1}}alloc(){}free(){this.helper=null}copy(){let e;return Zt.zpp_pool==null?e=new Zt:(e=Zt.zpp_pool,Zt.zpp_pool=e.next,e.next=null),e.x=this.x,e.y=this.y,e.forced=this.forced,e}sort(){let e=this.prev.x-this.x,t=this.prev.y-this.y,n=this.next.x-this.x,l=this.next.y-this.y,s=l*e-n*t,i=s>0?-1:s==0?0:1,r=this.diagonals;if(r.head!=null&&r.head.next!=null){let o=r.head,a,p,c,u,h=1,x,f,_;for(;;){for(x=0,p=o,o=null,a=o;p!=null;){for(++x,c=p,f=0,_=h;c!=null&&f<h;)++f,c=c.next;for(;f>0||_>0&&c!=null;){if(f==0)u=c,c=c.next,--_;else if(_==0||c==null)u=p,p=p.next,--f;else{let d;if(i==1){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,l=c.elt.y-this.y;let b=l*e-n*t;d=(b>0?-1:b==0?0:1)==1}else{e=this.prev.x-this.x,t=this.prev.y-this.y,n=p.elt.x-this.x,l=p.elt.y-this.y;let b=l*e-n*t,m=b>0?-1:b==0?0:1;e=this.prev.x-this.x,t=this.prev.y-this.y,n=c.elt.x-this.x,l=c.elt.y-this.y;let z=l*e-n*t,M=z>0?-1:z==0?0:1;if(m*M==1||m*M==0&&(m==1||M==1)){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,l=c.elt.y-this.y;let y=l*e-n*t;d=(y>0?-1:y==0?0:1)==1}else if(m==-1||M==-1)d=M==-1;else if(m==0&&M==0){e=this.x-this.prev.x,t=this.y-this.prev.y,n=p.elt.x-this.x,l=p.elt.y-this.y;let y=e*n+t*l;n=c.elt.x-this.x,l=c.elt.y-this.y;let w=e*n+t*l;d=y<0&&w>0?!0:!(w<0&&y>0)}else d=!0}d?(u=p,p=p.next,--f):(u=c,c=c.next,--_)}a!=null?a.next=u:o=u,a=u}p=c}if(a.next=null,h<<=1,!(x>1))break}r.head=o,r.modified=!0,r.pushmod=!0}}};Zt.__name__=["zpp_nape","geom","ZPP_PartitionVertex"],Zt.zpp_pool=null,Zt.nextId=0;var Je=Zt;var wn=class wn{constructor(e){this.next=null;this.vertices=null;this.init(e)}static getSharedPP(){return wn.sharedPPList==null&&(wn.sharedPPList=new ks),wn.sharedPPList}static getShared(){return wn.sharedGVList==null&&(wn.sharedGVList=new hi),wn.sharedGVList}eq(e,t){let n=e.x-t.x,l=e.y-t.y;return n*n+l*l<oe().Config.epsilon*oe().Config.epsilon}alloc(){}free(){}init(e){if(e==null)return;let t=0,n=e,l=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==l)break}}let s=t*.5>0,i=e;for(;;){let r;if(s){let o;Je.zpp_pool==null?o=new Je:(o=Je.zpp_pool,Je.zpp_pool=o.next,o.next=null),o.x=i.x,o.y=i.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=i.x,o.y=i.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=i.forced,i=i.next,i==e)break}this.remove_collinear_vertices()}remove_collinear_vertices(){let e=this.vertices,t=!0;for(;t||e!=this.vertices;)if(t=!1,this.eq(e,e.next)){if(e==this.vertices&&(this.vertices=e.next,t=!0),e.forced&&(e.next.forced=!0),e!=null&&e.prev==e){e.next=e.prev=null;let l=e;l.helper=null,l.next=Je.zpp_pool,Je.zpp_pool=l,e=null,e=null}else{let l=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let s=e;s.helper=null,s.next=Je.zpp_pool,Je.zpp_pool=s,e=l}if(e==null){this.vertices=null;break}}else e=e.next;if(this.vertices==null)return!0;let n;for(;;){for(n=!1,e=this.vertices,t=!0;t||e!=this.vertices;){t=!1;let l=e.prev,s=e.x-l.x,i=e.y-l.y,r=e.next.x-e.x,a=(e.next.y-e.y)*s-r*i;if(a*a>=oe().Config.epsilon*oe().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 ks),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let i=t;for(;i.sort(),i=i.next,i!=n;);}for(this.pull_partitions(this.vertices,e);this.vertices!=null;){let i;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let r=this.vertices;r.helper=null,r.next=Je.zpp_pool,Je.zpp_pool=r,i=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,i=r}this.vertices=i}let l=null,s=e.head;for(;s!=null;){if(s.elt.remove_collinear_vertices()){e.erase(l);continue}l=s,s=s.next}}return e}pull_partitions(e,t){let n;wn.zpp_pool==null?n=new wn:(n=wn.zpp_pool,wn.zpp_pool=n.next,n.next=null);let l=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=l.x,o.y=l.y,o.forced=l.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=l.forced,l.diagonals.head!=null){let p=l.diagonals,c=p.head.elt;if(p.pop(),c==e)break;l=this.pull_partitions(l,t)}else l=l.next;if(l==e)break}let s=0,i=n.vertices,r=n.vertices;if(i!=null){let o=i;for(;;){let a=o;if(s+=a.x*(a.next.y-a.prev.y),o=o.next,o==r)break}}return s*.5!=0&&t.add(n),l}extract(e){if(e==null&&(e=new hi),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}for(this.pull(this.vertices,e);this.vertices!=null;){let l;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let s=this.vertices;s.helper=null,s.next=Je.zpp_pool,Je.zpp_pool=s,l=this.vertices=null}else{let s=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let i=this.vertices;i.helper=null,i.next=Je.zpp_pool,Je.zpp_pool=i,this.vertices=null,l=s}this.vertices=l}}return e}pull(e,t){let n=null,l=e;for(;;){let a=l.x,p=l.y,c;Ce.zpp_pool==null?c=new Ce:(c=Ce.zpp_pool,Ce.zpp_pool=c.next,c.next=null),c.forced=!1,c.x=a,c.y=p;let u=c;if(n==null?u.prev=u.next=u:(u.prev=n,u.next=n.next,n.next.prev=u,n.next=u),n=u,n.forced=l.forced,l.diagonals.head!=null){let h=l.diagonals,x=h.head.elt;if(h.pop(),x==e)break;l=this.pull(l,t)}else l=l.next;if(l==e)break}let s=0,i=n,r=n;if(i!=null){let a=i;for(;;){let p=a;if(s+=p.x*(p.next.y-p.prev.y),a=a.next,a==r)break}}let o=s*.5;if(o*o>=oe().Config.epsilon*oe().Config.epsilon){let a=n,p=!0;for(;p||a!=n;){p=!1;let c=a.x-a.next.x,u=a.y-a.next.y;if(c*c+u*u<oe().Config.epsilon*oe().Config.epsilon){if(a==n&&(n=a.next,p=!0),a.forced&&(a.next.forced=!0),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else{let h=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=h}if(a==null){n=null;break}}else a=a.next}if(n!=null){let c;for(;;){for(c=!1,a=n,p=!0;p||a!=n;){p=!1;let u=a.prev,h=a.x-u.x,x=a.y-u.y,f=a.next.x-a.x,d=(a.next.y-a.y)*h-f*x;if(d*d>=oe().Config.epsilon*oe().Config.epsilon)a=a.next;else{if(a==n&&(n=a.next,p=!0),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else{let b=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=b}if(c=!0,a==null){c=!1,n=null;break}}}if(!c)break}}n!=null&&t.add(n)}return l}};wn.__name__=["zpp_nape","geom","ZPP_PartitionedPoly"],wn.zpp_pool=null,wn.sharedPPList=null,wn.sharedGVList=null;var He=wn;var Ge=class Ge{static bisector(e){let t=e.prev,n=e.next,l=e.x-t.x,s=e.y-t.y,i=n.x-e.x,r=n.y-e.y,o;ie.zpp_pool==null?o=new ie:(o=ie.zpp_pool,ie.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=-s-r,o.y=l+i;let a=o,p=a.x*a.x+a.y*a.y,u=1/Math.sqrt(p);return a.x*=u,a.y*=u,r*l-i*s<0&&(a.x=-a.x,a.y=-a.y),a}static below(e,t){if(e.y<t.y)return!0;if(e.y>t.y)return!1;if(e.x<t.x)return!0;if(e.x>t.x)return!1;{let n=Ge.bisector(e),l=Ge.bisector(t),s=1;n.x+=e.x*s,n.y+=e.y*s;let i=1;l.x+=t.x*i,l.y+=t.y*i;let r=n.x<l.x||n.x==l.x&&n.y<l.y;return n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=ie.zpp_pool,ie.zpp_pool=n,l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l._isimmutable=null,l._validate=null,l._invalidate=null,l.next=ie.zpp_pool,ie.zpp_pool=l,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,l=e.next,s=e;if(l!=null){let o=l;for(;;){let a=o;if(a.y<t.y&&(t=a),a.y>n.y&&(n=a),o=o.next,o==s)break}}let i=!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){i=!1;break}if(r=c,p=p.next,p==a)break}}}if(!i)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){i=!1;break}if(r=c,p=p.prev,p==a)break}}}return i}static getShared(){return Ge.sharedPPoly==null&&(Ge.sharedPPoly=new He),Ge.sharedPPoly}static decompose(e,t){if(t==null?t=new He(e):t.init(e),t.vertices==null)return t;Ge.queue==null&&(Ge.queue=new $i);let n=t.vertices,l=t.vertices;if(n!=null){let i=n;for(;;){let r=i;Ge.queue.add(r);let o=r.next.x-r.x,a=r.next.y-r.y,p=r.prev.x-r.x,u=(r.prev.y-r.y)*o-p*a>0;if(r.type=Ge.below(r.prev,r)?Ge.below(r.next,r)?u?0:3:4:Ge.below(r,r.next)?u?1:2:4,i=i.next,i==l)break}}let s=Ge.queue;if(s.head!=null&&s.head.next!=null){let i=s.head,r,o,a,p,c=1,u,h,x;for(;;){for(u=0,o=i,i=null,r=i;o!=null;){for(++u,a=o,h=0,x=c;a!=null&&h<c;)++h,a=a.next;for(;h>0||x>0&&a!=null;)h==0?(p=a,a=a.next,--x):x==0||a==null||Ge.above(o.elt,a.elt)?(p=o,o=o.next,--h):(p=a,a=a.next,--x),r!=null?r.next=p:i=p,r=p;o=a}if(r.next=null,c<<=1,!(u>1))break}s.head=i,s.modified=!0,s.pushmod=!0}for(Ge.edges==null&&(yl.zpp_pool==null?Ge.edges=new yl:(Ge.edges=yl.zpp_pool,yl.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 i=Ge.queue.pop_unsafe();switch(i.type){case 0:i.helper=i,i.node=Ge.edges.insert(i);break;case 1:{let r=i.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(i,r.helper),Ge.edges.remove_node(r.node),r.helper=null;break}case 2:{let r=i.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(i,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,i)){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(i,a.helper),a.helper=i}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,i)){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(i,o.helper),o.helper=i}i.node=Ge.edges.insert(i),i.helper=i;break}case 4:{let r=i.prev;if(Ge.left_vertex(i)){if(r.helper==null)throw new Error("Fatal error (5): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(i,r.helper),Ge.edges.remove_node(r.node),r.helper=null,i.node=Ge.edges.insert(i),i.helper=i}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,i)){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(i,a.helper),a.helper=i}break}}}return t}};Ge.__name__=["zpp_nape","geom","ZPP_Monotone"],Ge.queue=null,Ge.edges=null,Ge.sharedPPoly=null;var on=Ge;var ls=class ls{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 ls.zpp_pool==null?n=new ls:(n=ls.zpp_pool,ls.zpp_pool=n.next,n.next=null),n.a=e,n.b=t,e.id<t.id?(n.id=e.id,n.di=t.id):(n.id=t.id,n.di=e.id),n}static edge_swap(e,t){let n=e.node;e.node=t.node,t.node=n}static edge_lt(e,t){return e.id>=t.id?e.id==t.id?e.di<t.di:!1:!0}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){this.a=this.b=null,this.node=null}alloc(){}};ls.__name__=["zpp_nape","geom","ZPP_PartitionPair"],ls.zpp_pool=null;var $t=ls;var Wt=class Wt{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=oe(),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 l;ie.zpp_pool==null?l=new ie:(l=ie.zpp_pool,ie.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=0,l.y=0,t.zpp_inner=l,t.zpp_inner.outer=t}else{if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=t.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");l._isimmutable!=null&&l._isimmutable();let s;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=t.zpp_inner;if(i._validate!=null&&i._validate(),t.zpp_inner.x==0){if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=t.zpp_inner;r._validate!=null&&r._validate(),s=t.zpp_inner.y==0}else s=!1;if(!s){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=l=>this.origin_invalidate(l);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 l;ie.zpp_pool==null?l=new ie:(l=ie.zpp_pool,ie.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=0,l.y=0,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");l._isimmutable!=null&&l._isimmutable();let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),s=n.zpp_inner.y==0}else s=!1;if(!s){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=l=>this.direction_invalidate(l),this.originx=0,this.originy=0,this.dirx=0,this.diry=0,this.zip_dir=!1}origin_invalidate(e){this.originx=e.x,this.originy=e.y}direction_invalidate(e){this.dirx=e.x,this.diry=e.y,this.zip_dir=!0}invalidate_dir(){this.zip_dir=!0}validate_dir(){if(this.zip_dir){this.zip_dir=!1;let e=oe();if(this.dirx*this.dirx+this.diry*this.diry<e.Config.epsilon)throw new Error("Error: Ray::direction is degenerate");let t=this.dirx*this.dirx+this.diry*this.diry,n=1/Math.sqrt(t);this.dirx*=n,this.diry*=n,this.idirx=1/this.dirx,this.idiry=1/this.diry,this.normalx=-this.diry,this.normaly=this.dirx;let l=this.normalx;this.absnormalx=l<0?-l:l;let s=this.normaly;this.absnormaly=s<0?-s:s}}rayAABB(){let e=this.originx,t=e,n=this.originy,l=n;if(this.maxdist>=1/0?(this.dirx>0?t=1/0:this.dirx<0&&(t=-1/0),this.diry>0?l=1/0:this.diry<0&&(l=-1/0)):(t+=this.maxdist*this.dirx,l+=this.maxdist*this.diry),t<e){let i=e;e=t,t=i}if(l<n){let i=n;n=l,l=i}let s;return fe.zpp_pool==null?s=new fe:(s=fe.zpp_pool,fe.zpp_pool=s.next,s.next=null),s.minx=e,s.miny=n,s.maxx=t,s.maxy=l,s}aabbtest(e){let t=this.normalx*(this.originx-.5*(e.minx+e.maxx))+this.normaly*(this.originy-.5*(e.miny+e.maxy)),n=this.absnormalx*.5*(e.maxx-e.minx)+this.absnormaly*.5*(e.maxy-e.miny),l=t;return(l<0?-l:l)<n}aabbsect(e){let t=this.originx>=e.minx&&this.originx<=e.maxx,n=this.originy>=e.miny&&this.originy<=e.maxy;if(t&&n)return 0;{let l=-1;for(;!(this.dirx>=0&&this.originx>=e.maxx)&&!(this.dirx<=0&&this.originx<=e.minx||this.diry>=0&&this.originy>=e.maxy||this.diry<=0&&this.originy<=e.miny);){if(this.dirx>0){let s=(e.minx-this.originx)*this.idirx;if(s>=0&&s<=this.maxdist){let i=this.originy+s*this.diry;if(i>=e.miny&&i<=e.maxy){l=s;break}}}else if(this.dirx<0){let s=(e.maxx-this.originx)*this.idirx;if(s>=0&&s<=this.maxdist){let i=this.originy+s*this.diry;if(i>=e.miny&&i<=e.maxy){l=s;break}}}if(this.diry>0){let s=(e.miny-this.originy)*this.idiry;if(s>=0&&s<=this.maxdist){let i=this.originx+s*this.dirx;if(i>=e.minx&&i<=e.maxx){l=s;break}}}else if(this.diry<0){let s=(e.maxy-this.originy)*this.idiry;if(s>=0&&s<=this.maxdist){let i=this.originx+s*this.dirx;if(i>=e.minx&&i<=e.maxx){l=s;break}}}break}return l}}static _allocVec2(e,t){let n=oe();if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;if(ue.poolVec2==null?l=new n.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 s;ie.zpp_pool==null?s=new ie:(s=ie.zpp_pool,ie.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,l.zpp_inner=s,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let i;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x==e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),i=l.zpp_inner.y==t):i=!1,i||(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner._invalidate!=null&&l.zpp_inner._invalidate(l.zpp_inner))}return l.zpp_inner.weak=!1,l}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let l=1;n.localCOMx+=n.lverts.next.next.x*l,n.localCOMy+=n.lverts.next.next.y*l;let s=.5;n.localCOMx*=s,n.localCOMy*=s}else{n.localCOMx=0,n.localCOMy=0;let l=0,s=n.lverts.next,i=s;s=s.next;let r=s;for(s=s.next;s!=null;){let h=s;l+=r.x*(h.y-i.y);let x=h.y*r.x-h.x*r.y;n.localCOMx+=(r.x+h.x)*x,n.localCOMy+=(r.y+h.y)*x,i=r,r=h,s=s.next}s=n.lverts.next;let o=s;l+=r.x*(o.y-i.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,i=r,r=o,s=s.next;let p=s;l+=r.x*(p.y-i.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,l=1/(3*l);let u=l;n.localCOMx*=u,n.localCOMy*=u}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}_circleNormal(e,t,n){let l=this.originx+this.dirx*e,s=this.originy+this.diry*e;l-=t.worldCOMx,s-=t.worldCOMy;let i=l*l+s*s,r=1/Math.sqrt(i);return l*=r,s*=r,n&&(l=-l,s=-s),{nx:l,ny:s}}static _insertSorted(e,t){let n=null,l=e.zpp_inner.inner.head;for(;l!=null;){let r=l.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=l,l=l.next}let s=e.zpp_inner.inner,i;xl.zpp_pool==null?i=new xl:(i=xl.zpp_pool,xl.zpp_pool=i.next,i.next=null),i.elt=t,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++}circlesect(e,t,n){Wt._validateWorldCOM(e);let l=this.originx-e.worldCOMx,s=this.originy-e.worldCOMy,i=this.dirx*this.dirx+this.diry*this.diry,r=2*(l*this.dirx+s*this.diry),o=l*l+s*s-e.radius*e.radius,a=r*r-4*i*o;if(a==0){let p=-r/2*i;if((!t||o>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,o<=0),u=Wt._allocVec2(c.nx,c.ny);return qt.getRay(u,p,o<=0,e.outer)}else return null}else{a=Math.sqrt(a),i=1/(2*i);let p=(-r-a)*i,c=(-r+a)*i;if(p>0)if(p<n&&p<=this.maxdist){let u=this._circleNormal(p,e,!1),h=Wt._allocVec2(u.nx,u.ny);return qt.getRay(h,p,!1,e.outer)}else return null;else if(c>0&&t)if(c<n&&c<=this.maxdist){let u=this._circleNormal(c,e,!0),h=Wt._allocVec2(u.nx,u.ny);return qt.getRay(h,c,!0,e.outer)}else return null;else return null}}circlesect2(e,t,n){Wt._validateWorldCOM(e);let l=this.originx-e.worldCOMx,s=this.originy-e.worldCOMy,i=this.dirx*this.dirx+this.diry*this.diry,r=2*(l*this.dirx+s*this.diry),o=l*l+s*s-e.radius*e.radius,a=r*r-4*i*o;if(a==0){let p=-r/2*i;if((!t||o>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,o<=0),u=Wt._allocVec2(c.nx,c.ny),h=qt.getRay(u,p,o<=0,e.outer);Wt._insertSorted(n,h)}}else{a=Math.sqrt(a),i=1/(2*i);let p=(-r-a)*i,c=(-r+a)*i;if(p>0&&p<=this.maxdist){let u=this._circleNormal(p,e,!1),h=Wt._allocVec2(u.nx,u.ny),x=qt.getRay(h,p,!1,e.outer);Wt._insertSorted(n,x)}if(c>0&&c<=this.maxdist&&t){let u=this._circleNormal(c,e,!0),h=Wt._allocVec2(u.nx,u.ny),x=qt.getRay(h,c,!0,e.outer);Wt._insertSorted(n,x)}}}polysect(e,t,n){let l=oe(),s=n,i=null,r=e.edges.head,o=!0,a=e.gverts.next,p=a,c=a.next;for(;c!=null;){let u=c,h=r.elt;if(t||h.gnormx*this.dirx+h.gnormy*this.diry<0){let x=u.x-p.x,f=u.y-p.y,_=p.x-this.originx,d=p.y-this.originy,b=f*this.dirx-x*this.diry;if(b*b>l.Config.epsilon){b=1/b;let m=(f*_-x*d)*b;if(m>0&&m<s&&m<=this.maxdist){let z=(this.diry*_-this.dirx*d)*b;z>-l.Config.epsilon&&z<1+l.Config.epsilon&&(s=m,i=r.elt)}}}r=r.next,p=u,c=c.next}if(o){c=e.gverts.next;let u=c,h=r.elt;if(t||h.gnormx*this.dirx+h.gnormy*this.diry<0){let x=u.x-p.x,f=u.y-p.y,_=p.x-this.originx,d=p.y-this.originy,b=f*this.dirx-x*this.diry;if(b*b>l.Config.epsilon){b=1/b;let m=(f*_-x*d)*b;if(m>0&&m<s&&m<=this.maxdist){let z=(this.diry*_-this.dirx*d)*b;z>-l.Config.epsilon&&z<1+l.Config.epsilon&&(s=m,i=r.elt)}}}}if(i!=null){let u=i.gnormx,h=i.gnormy,x=u*this.dirx+h*this.diry>0;x&&(u=-u,h=-h);let f=Wt._allocVec2(u,h);return qt.getRay(f,s,x,e.outer)}else return null}polysect2(e,t,n){let l=oe(),s=1/0,i=-1,r=null,o=null,a=e.edges.head,p=!0,c=e.gverts.next,u=c,h=c.next;for(;h!=null;){let x=h,f=a.elt;if(t||f.gnormx*this.dirx+f.gnormy*this.diry<0){let _=x.x-u.x,d=x.y-u.y,b=u.x-this.originx,m=u.y-this.originy,z=d*this.dirx-_*this.diry;if(z*z>l.Config.epsilon){z=1/z;let M=(d*b-_*m)*z;if(M>0&&M<=this.maxdist&&(M<s||M>i)){let y=(this.diry*b-this.dirx*m)*z;y>-l.Config.epsilon&&y<1+l.Config.epsilon&&(M<s&&(s=M,r=a.elt),M>i&&(i=M,o=a.elt))}}}a=a.next,u=x,h=h.next}if(p){h=e.gverts.next;let x=h,f=a.elt;if(t||f.gnormx*this.dirx+f.gnormy*this.diry<0){let _=x.x-u.x,d=x.y-u.y,b=u.x-this.originx,m=u.y-this.originy,z=d*this.dirx-_*this.diry;if(z*z>l.Config.epsilon){z=1/z;let M=(d*b-_*m)*z;if(M>0&&M<=this.maxdist&&(M<s||M>i)){let y=(this.diry*b-this.dirx*m)*z;y>-l.Config.epsilon&&y<1+l.Config.epsilon&&(M<s&&(s=M,r=a.elt),M>i&&(i=M,o=a.elt))}}}}if(r!=null){let x=r.gnormx,f=r.gnormy,_=x*this.dirx+f*this.diry>0;_&&(x=-x,f=-f);let d=Wt._allocVec2(x,f),b=qt.getRay(d,s,_,e.outer);Wt._insertSorted(n,b)}if(o!=null&&r!=o){let x=o.gnormx,f=o.gnormy,_=x*this.dirx+f*this.diry>0;_&&(x=-x,f=-f);let d=Wt._allocVec2(x,f),b=qt.getRay(d,i,_,e.outer);Wt._insertSorted(n,b)}}};Wt.__name__=["zpp_nape","geom","ZPP_Ray"],Wt.internal=!1;var vl=Wt;var Gi=class Gi{constructor(){this.forced=!1;this.x=0;this.y=0;this.links=null;this.id=0;this.next=null;this.node=null;this.id=In.ZPP_SimpleVert(),bn.zpp_pool==null?this.links=new bn:(this.links=bn.zpp_pool,bn.zpp_pool=this.links.next,this.links.next=null),this.links.lt=Gi.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 Gi.zpp_pool==null?n=new Gi:(n=Gi.zpp_pool,Gi.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(){}};Gi.__name__=["zpp_nape","geom","ZPP_SimpleVert"],Gi.zpp_pool=null;var Oe=Gi;var rs=class rs{constructor(){this.left=null;this.right=null;this.vertices=null;this.id=0;this.next=null;this.prev=null;this.node=null;this.id=In.ZPP_SimpleSeg(),bn.zpp_pool==null?this.vertices=new bn:(this.vertices=bn.zpp_pool,bn.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 rs.zpp_pool==null?n=new rs:(n=rs.zpp_pool,rs.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}};rs.__name__=["zpp_nape","geom","ZPP_SimpleSeg"],rs.zpp_pool=null;var en=rs;var os=class os{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 os.zpp_pool==null?t=new os:(t=os.zpp_pool,os.zpp_pool=t.next,t.next=null),t.vertex=e,t}free(){this.vertex=null,this.segment=this.segment2=null,this.node=null}alloc(){}};os.__name__=["zpp_nape","geom","ZPP_SimpleEvent"],os.zpp_pool=null;var Ee=os;var as=class{constructor(){this.sweepx=0;this.tree=null;dl.zpp_pool==null?this.tree=new dl:(this.tree=dl.zpp_pool,dl.zpp_pool=this.tree.next,this.tree.next=null),this.tree.lt=(e,t)=>this.edge_lt(e,t),this.tree.swapped=(e,t)=>this.swap_nodes(e,t)}swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}edge_lt(e,t){let n=e.left,l=e.right,s=t.left,i=t.right,r,o,a,p,c;if(e.left==t.left&&e.right==t.right)return!1;if(e.left==t.right)return n.x==l.x?n.y<l.y?n.y>s.y:l.y>s.y:(c=l.x<n.x,r=l.x-n.x,o=l.y-n.y,a=s.x-n.x,p=s.y-n.y,(c?o*a-r*p:p*r-a*o)<0);if(e.right==t.left){let u;return s.x==i.x?u=s.y<i.y?s.y>n.y:i.y>n.y:(c=i.x<s.x,r=i.x-s.x,o=i.y-s.y,a=n.x-s.x,p=n.y-s.y,u=(c?o*a-r*p:p*r-a*o)<0),!u}else{if(e.left==t.left)return n.x==l.x?n.y<l.y?n.y>i.y:l.y>i.y:(c=l.x<n.x,r=l.x-n.x,o=l.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.right)return n.x==l.x?n.y<l.y?n.y>s.y:l.y>s.y:(c=l.x<n.x,r=l.x-n.x,o=l.y-n.y,a=s.x-n.x,p=s.y-n.y,(c?o*a-r*p:p*r-a*o)<0)}if(n.x==l.x)if(s.x==i.x){let u=n.y<l.y?l:n,h=s.y<i.y?i:s;return u.y>h.y}else{c=i.x<s.x,r=i.x-s.x,o=i.y-s.y,a=n.x-s.x,p=n.y-s.y;let u=c?o*a-r*p:p*r-a*o;c=i.x<s.x,r=i.x-s.x,o=i.y-s.y,a=l.x-s.x,p=l.y-s.y;let h=c?o*a-r*p:p*r-a*o;return u*h>=0?u>=0:this.sweepx>=n.x}else if(s.x==i.x){c=l.x<n.x,r=l.x-n.x,o=l.y-n.y,a=s.x-n.x,p=s.y-n.y;let u=c?o*a-r*p:p*r-a*o;c=l.x<n.x,r=l.x-n.x,o=l.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=c?o*a-r*p:p*r-a*o;return u*h>=0?u<0:this.sweepx<s.x}else{c=l.x<n.x,r=l.x-n.x,o=l.y-n.y,a=s.x-n.x,p=s.y-n.y;let u=(c?o*a-r*p:p*r-a*o)<0;c=l.x<n.x,r=l.x-n.x,o=l.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;if(u==h)return u;{c=i.x<s.x,r=i.x-s.x,o=i.y-s.y,a=n.x-s.x,p=n.y-s.y;let x=(c?o*a-r*p:p*r-a*o)>=0;c=i.x<s.x,r=i.x-s.x,o=i.y-s.y,a=l.x-s.x,p=l.y-s.y;let f=(c?o*a-r*p:p*r-a*o)>=0;if(x==f)return x;let _=(this.sweepx-n.x)/(l.x-n.x)*(l.y-n.y)+n.y,d=(this.sweepx-s.x)/(i.x-s.x)*(i.y-s.y)+s.y;return _>d}}}clear(){this.tree.clear()}add(e){e.node=this.tree.insert(e);let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);return t!=null&&(e.next=t.data,t.data.prev=e),n!=null&&(e.prev=n.data,n.data.next=e),e}remove(e){let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);t!=null&&(t.data.prev=e.prev),n!=null&&(n.data.next=e.next),this.tree.remove_node(e.node),e.node=null}intersect(e,t){if(e==null||t==null)return!1;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return!1;{let n=e.left,l=e.right,s=t.left,i=t.right,r=(s.x-n.x)*(l.y-n.y)-(l.x-n.x)*(s.y-n.y),o=(i.x-n.x)*(l.y-n.y)-(l.x-n.x)*(i.y-n.y);if(r*o>0)return!1;{let a=(n.x-s.x)*(i.y-s.y)-(i.x-s.x)*(n.y-s.y),p=(l.x-s.x)*(i.y-s.y)-(i.x-s.x)*(l.y-s.y);return!(a*p>0)}}}intersection(e,t){if(e==null||t==null)return null;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return null;{let n=e.left,l=e.right,s=t.left,i=t.right,r=l.x-n.x,o=l.y-n.y,a=i.x-s.x,p=i.y-s.y,c=p*r-a*o;if(c==0)return null;c=1/c;let u=s.x-n.x,h=s.y-n.y,x=(p*u-a*h)*c;if(x<0||x>1)return null;let f=(o*u-r*h)*c;if(f<0||f>1)return null;let _;if(f==0||f==1||x==0||x==1){let m=f==0;if(f==1&&m)throw new Error("corner case 1a");if(f==1&&(m=!0),x==0&&m)throw new Error("corner case 1b");if(x==0&&(m=!0),x==1&&m)throw new Error("corner case 1c");_=f==0?s:f==1?i:x==0?n:l}else{let m=.5*(n.x+r*x+s.x+a*f),z=.5*(n.y+o*x+s.y+p*f),M;Oe.zpp_pool==null?M=new Oe:(M=Oe.zpp_pool,Oe.zpp_pool=M.next,M.next=null),M.x=m,M.y=z,_=M}let d;Ee.zpp_pool==null?d=new Ee:(d=Ee.zpp_pool,Ee.zpp_pool=d.next,d.next=null),d.vertex=_;let b=d;return b.type=0,b.segment=e,b.segment2=t,b}}};as.__name__=["zpp_nape","geom","ZPP_SimpleSweep"];var ye=class ye{static decompose(e,t){ye.sweep==null&&(ye.sweep=new as,ye.inthash=new Es),ye.vertices==null&&(bn.zpp_pool==null?ye.vertices=new bn:(ye.vertices=bn.zpp_pool,bn.zpp_pool=ye.vertices.next,ye.vertices.next=null),ye.vertices.lt=Oe.less_xy,ye.vertices.swapped=Oe.swap_nodes),ye.queue==null&&(Mi.zpp_pool==null?ye.queue=new Mi:(ye.queue=Mi.zpp_pool,Mi.zpp_pool=ye.queue.next,ye.queue.next=null),ye.queue.lt=Ee.less_xy,ye.queue.swapped=Ee.swap_nodes);let n=null,l=null,s=e,i=e;if(s!=null){let x=s;for(;;){let f=x,_=f.x,d=f.y,b;Oe.zpp_pool==null?b=new Oe:(b=Oe.zpp_pool,Oe.zpp_pool=b.next,b.next=null),b.x=_,b.y=d;let m=b,z=ye.vertices.parent;for(;z!=null;)if(ye.vertices.lt(m,z.data))z=z.prev;else if(ye.vertices.lt(z.data,m))z=z.next;else break;let M=z;if(M!=null){let y=m;y.links.clear(),y.node=null,y.forced=!1,y.next=Oe.zpp_pool,Oe.zpp_pool=y,m=M.data}else m.node=ye.vertices.insert(m);if(l!=null){let y;Ee.zpp_pool==null?y=new Ee:(y=Ee.zpp_pool,Ee.zpp_pool=y.next,y.next=null),y.vertex=l;let w=y,v;Ee.zpp_pool==null?v=new Ee:(v=Ee.zpp_pool,Ee.zpp_pool=v.next,v.next=null),v.vertex=m;let P=v,g;Ee.less_xy(w,P)?(w.type=1,P.type=2,g=en.get(l,m)):(w.type=2,P.type=1,g=en.get(m,l)),w.segment=P.segment=g,ye.queue.insert(w),ye.queue.insert(P),l.links.insert(m),m.links.insert(l)}if(l=m,n==null&&(n=m),x=x.next,x==i)break}}let r;Ee.zpp_pool==null?r=new Ee:(r=Ee.zpp_pool,Ee.zpp_pool=r.next,r.next=null),r.vertex=l;let o=r,a;Ee.zpp_pool==null?a=new Ee:(a=Ee.zpp_pool,Ee.zpp_pool=a.next,a.next=null),a.vertex=n;let p=a,c;for(Ee.less_xy(o,p)?(o.type=1,p.type=2,c=en.get(l,n)):(o.type=2,p.type=1,c=en.get(n,l)),o.segment=p.segment=c,ye.queue.insert(o),ye.queue.insert(p),l.links.insert(n),n.links.insert(l),ye.ints==null&&(Mi.zpp_pool==null?ye.ints=new Mi:(ye.ints=Mi.zpp_pool,Mi.zpp_pool=ye.ints.next,ye.ints.next=null),ye.ints.lt=Ee.less_xy);!ye.queue.empty();){let x=ye.queue.pop_front();if(ye.sweep.sweepx=x.vertex.x,x.type==1){let _=x.segment;if(ye.sweep.add(_),_.next!=null&&_!=null&&!(_.next.id<_.id?ye.inthash.has(_.next.id,_.id):ye.inthash.has(_.id,_.next.id))){let d=ye.sweep.intersection(_.next,_);if(d!=null)if(d.vertex.x>=ye.sweep.sweepx){let b=ye.queue.parent;for(;b!=null;)if(ye.queue.lt(d,b.data))b=b.prev;else if(ye.queue.lt(b.data,d))b=b.next;else break;let m=b;if(m==null){let z=ye.ints.parent;for(;z!=null;)if(ye.ints.lt(d,z.data))z=z.prev;else if(ye.ints.lt(z.data,d))z=z.next;else break;let M=z;if(M!=null){let y=d.vertex;y.links.clear(),y.node=null,y.forced=!1,y.next=Oe.zpp_pool,Oe.zpp_pool=y,d.vertex=M.data.vertex,M.data=d,ye.queue.insert(d)}else ye.queue.insert(d),ye.ints.insert(d);if(_.next.id<_.id){let y=ye.inthash,w=_.next.id,v=_.id,P;Le.zpp_pool==null?P=new Le:(P=Le.zpp_pool,Le.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}else{let y=ye.inthash,w=_.id,v=_.next.id,P;Le.zpp_pool==null?P=new Le:(P=Le.zpp_pool,Le.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}}else{let z=m.data;if(z.segment!=d.segment||d.segment2!=z.segment2)throw new Error("corner case 2, shiiiit.");let M=d.vertex;M.links.clear(),M.node=null,M.forced=!1,M.next=Oe.zpp_pool,Oe.zpp_pool=M;let y=d;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Ee.zpp_pool,Ee.zpp_pool=y}}else{let b=d.vertex;b.links.clear(),b.node=null,b.forced=!1,b.next=Oe.zpp_pool,Oe.zpp_pool=b;let m=d;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Ee.zpp_pool,Ee.zpp_pool=m}}if(_!=null&&_.prev!=null&&!(_.id<_.prev.id?ye.inthash.has(_.id,_.prev.id):ye.inthash.has(_.prev.id,_.id))){let d=ye.sweep.intersection(_,_.prev);if(d!=null)if(d.vertex.x>=ye.sweep.sweepx){let b=ye.queue.parent;for(;b!=null;)if(ye.queue.lt(d,b.data))b=b.prev;else if(ye.queue.lt(b.data,d))b=b.next;else break;let m=b;if(m==null){let z=ye.ints.parent;for(;z!=null;)if(ye.ints.lt(d,z.data))z=z.prev;else if(ye.ints.lt(z.data,d))z=z.next;else break;let M=z;if(M!=null){let y=d.vertex;y.links.clear(),y.node=null,y.forced=!1,y.next=Oe.zpp_pool,Oe.zpp_pool=y,d.vertex=M.data.vertex,M.data=d,ye.queue.insert(d)}else ye.queue.insert(d),ye.ints.insert(d);if(_.id<_.prev.id){let y=ye.inthash,w=_.id,v=_.prev.id,P;Le.zpp_pool==null?P=new Le:(P=Le.zpp_pool,Le.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}else{let y=ye.inthash,w=_.prev.id,v=_.id,P;Le.zpp_pool==null?P=new Le:(P=Le.zpp_pool,Le.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}}else{let z=m.data;if(z.segment!=d.segment||d.segment2!=z.segment2)throw new Error("corner case 2, shiiiit.");let M=d.vertex;M.links.clear(),M.node=null,M.forced=!1,M.next=Oe.zpp_pool,Oe.zpp_pool=M;let y=d;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Ee.zpp_pool,Ee.zpp_pool=y}}else{let b=d.vertex;b.links.clear(),b.node=null,b.forced=!1,b.next=Oe.zpp_pool,Oe.zpp_pool=b;let m=d;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Ee.zpp_pool,Ee.zpp_pool=m}}}else if(x.type==2){let _=x.segment;if(_.node!=null){let d=_.next,b=_.prev;ye.sweep.remove(_);let m=_;if(m.left=m.right=null,m.prev=null,m.node=null,m.vertices.clear(),m.next=en.zpp_pool,en.zpp_pool=m,d!=null&&b!=null&&!(d.id<b.id?ye.inthash.has(d.id,b.id):ye.inthash.has(b.id,d.id))){let z=ye.sweep.intersection(d,b);if(z!=null)if(z.vertex.x>=ye.sweep.sweepx){let M=ye.queue.parent;for(;M!=null;)if(ye.queue.lt(z,M.data))M=M.prev;else if(ye.queue.lt(M.data,z))M=M.next;else break;let y=M;if(y==null){let w=ye.ints.parent;for(;w!=null;)if(ye.ints.lt(z,w.data))w=w.prev;else if(ye.ints.lt(w.data,z))w=w.next;else break;let v=w;if(v!=null){let P=z.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=Oe.zpp_pool,Oe.zpp_pool=P,z.vertex=v.data.vertex,v.data=z,ye.queue.insert(z)}else ye.queue.insert(z),ye.ints.insert(z);if(d.id<b.id){let P=ye.inthash,g=d.id,E=b.id,N;Le.zpp_pool==null?N=new Le:(N=Le.zpp_pool,Le.zpp_pool=N.next,N.next=null),N.id=g,N.di=E;let k=N;k.value=!0,P.add(k)}else{let P=ye.inthash,g=b.id,E=d.id,N;Le.zpp_pool==null?N=new Le:(N=Le.zpp_pool,Le.zpp_pool=N.next,N.next=null),N.id=g,N.di=E;let k=N;k.value=!0,P.add(k)}}else{let w=y.data;if(w.segment!=z.segment||z.segment2!=w.segment2)throw new Error("corner case 2, shiiiit.");let v=z.vertex;v.links.clear(),v.node=null,v.forced=!1,v.next=Oe.zpp_pool,Oe.zpp_pool=v;let P=z;P.vertex=null,P.segment=P.segment2=null,P.node=null,P.next=Ee.zpp_pool,Ee.zpp_pool=P}}else{let M=z.vertex;M.links.clear(),M.node=null,M.forced=!1,M.next=Oe.zpp_pool,Oe.zpp_pool=M;let y=z;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Ee.zpp_pool,Ee.zpp_pool=y}}}}else{let _=x.vertex,d=_.node==null,b=x.segment,m=x.segment2;if(m.next!=b){let v=b;b=m,m=v}let z=b.vertices.parent;for(;z!=null;)if(b.vertices.lt(_,z.data))z=z.prev;else if(b.vertices.lt(z.data,_))z=z.next;else break;let M=z==null,y=m.vertices.parent;for(;y!=null;)if(m.vertices.lt(_,y.data))y=y.prev;else if(m.vertices.lt(y.data,_))y=y.next;else break;let w=y==null;if(M){let v=b.vertices.insert(_),P=_==b.left?_:b.vertices.predecessor_node(v).data,g=_==b.right?_:b.vertices.successor_node(v).data;P.links.remove(g),_!=P&&P.links.insert(_),g.links.remove(P),_!=g&&g.links.insert(_),_!=P&&_.links.insert(P),_!=g&&_.links.insert(g)}if(w){let v=m.vertices.insert(_),P=_==m.left?_:m.vertices.predecessor_node(v).data,g=_==m.right?_:m.vertices.successor_node(v).data;P.links.remove(g),_!=P&&P.links.insert(_),g.links.remove(P),_!=g&&g.links.insert(_),_!=P&&_.links.insert(P),_!=g&&_.links.insert(g)}if(d&&(_.node=ye.vertices.insert(_)),_.forced=!0,d){let v=b.node,P=m.node;v.data=m,P.data=b,b.node=P,m.node=v,m.next=b.next,b.next=m,b.prev=m.prev,m.prev=b,b.prev!=null&&(b.prev.next=b),m.next!=null&&(m.next.prev=m)}if(m.next!=null&&m!=null&&!(m.next.id<m.id?ye.inthash.has(m.next.id,m.id):ye.inthash.has(m.id,m.next.id))){let v=ye.sweep.intersection(m.next,m);if(v!=null)if(v.vertex.x>=ye.sweep.sweepx){let P=ye.queue.parent;for(;P!=null;)if(ye.queue.lt(v,P.data))P=P.prev;else if(ye.queue.lt(P.data,v))P=P.next;else break;let g=P;if(g==null){let E=ye.ints.parent;for(;E!=null;)if(ye.ints.lt(v,E.data))E=E.prev;else if(ye.ints.lt(E.data,v))E=E.next;else break;let N=E;if(N!=null){let k=v.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=Oe.zpp_pool,Oe.zpp_pool=k,v.vertex=N.data.vertex,N.data=v,ye.queue.insert(v)}else ye.queue.insert(v),ye.ints.insert(v);if(m.next.id<m.id){let k=ye.inthash,Z=m.next.id,C=m.id,F;Le.zpp_pool==null?F=new Le:(F=Le.zpp_pool,Le.zpp_pool=F.next,F.next=null),F.id=Z,F.di=C;let O=F;O.value=!0,k.add(O)}else{let k=ye.inthash,Z=m.id,C=m.next.id,F;Le.zpp_pool==null?F=new Le:(F=Le.zpp_pool,Le.zpp_pool=F.next,F.next=null),F.id=Z,F.di=C;let O=F;O.value=!0,k.add(O)}}else{let E=g.data;if(E.segment!=v.segment||v.segment2!=E.segment2)throw new Error("corner case 2, shiiiit.");let N=v.vertex;N.links.clear(),N.node=null,N.forced=!1,N.next=Oe.zpp_pool,Oe.zpp_pool=N;let k=v;k.vertex=null,k.segment=k.segment2=null,k.node=null,k.next=Ee.zpp_pool,Ee.zpp_pool=k}}else{let P=v.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=Oe.zpp_pool,Oe.zpp_pool=P;let g=v;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Ee.zpp_pool,Ee.zpp_pool=g}}if(b!=null&&b.prev!=null&&!(b.id<b.prev.id?ye.inthash.has(b.id,b.prev.id):ye.inthash.has(b.prev.id,b.id))){let v=ye.sweep.intersection(b,b.prev);if(v!=null)if(v.vertex.x>=ye.sweep.sweepx){let P=ye.queue.parent;for(;P!=null;)if(ye.queue.lt(v,P.data))P=P.prev;else if(ye.queue.lt(P.data,v))P=P.next;else break;let g=P;if(g==null){let E=ye.ints.parent;for(;E!=null;)if(ye.ints.lt(v,E.data))E=E.prev;else if(ye.ints.lt(E.data,v))E=E.next;else break;let N=E;if(N!=null){let k=v.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=Oe.zpp_pool,Oe.zpp_pool=k,v.vertex=N.data.vertex,N.data=v,ye.queue.insert(v)}else ye.queue.insert(v),ye.ints.insert(v);if(b.id<b.prev.id){let k=ye.inthash,Z=b.id,C=b.prev.id,F;Le.zpp_pool==null?F=new Le:(F=Le.zpp_pool,Le.zpp_pool=F.next,F.next=null),F.id=Z,F.di=C;let O=F;O.value=!0,k.add(O)}else{let k=ye.inthash,Z=b.prev.id,C=b.id,F;Le.zpp_pool==null?F=new Le:(F=Le.zpp_pool,Le.zpp_pool=F.next,F.next=null),F.id=Z,F.di=C;let O=F;O.value=!0,k.add(O)}}else{let E=g.data;if(E.segment!=v.segment||v.segment2!=E.segment2)throw new Error("corner case 2, shiiiit.");let N=v.vertex;N.links.clear(),N.node=null,N.forced=!1,N.next=Oe.zpp_pool,Oe.zpp_pool=N;let k=v;k.vertex=null,k.segment=k.segment2=null,k.node=null,k.next=Ee.zpp_pool,Ee.zpp_pool=k}}else{let P=v.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=Oe.zpp_pool,Oe.zpp_pool=P;let g=v;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Ee.zpp_pool,Ee.zpp_pool=g}}ye.ints.remove(x)}let f=x;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Ee.zpp_pool,Ee.zpp_pool=f}let u=0,h=ye.inthash.table.length;for(;u<h;){let x=u++,f=ye.inthash.table[x];if(f!=null){for(;f!=null;){let _=f.hnext;f.hnext=null;let d=f;d.next=Le.zpp_pool,Le.zpp_pool=d,f=_}ye.inthash.table[x]=null}}for(t==null&&(t=new hi);!ye.vertices.empty();)ye.clip_polygon(ye.vertices,t);return t}static clip_polygon(e,t){let n=null,l=e.first(),s=l,i=l.links.parent,r=i.prev==null?i.next:i.prev,o=i.data,a=r.data,p=l.x-o.x,c=l.y-o.y,u=a.x-l.x;(a.y-l.y)*p-u*c<0&&(a=o);let x=l.x,f=l.y,_;Ce.zpp_pool==null?_=new Ce:(_=Ce.zpp_pool,Ce.zpp_pool=_.next,_.next=null),_.forced=!1,_.x=x,_.y=f;let d=_;if(n==null)d.prev=d.next=d;else{let m=n,z=m.next;d.prev=m,d.next=z,z.prev=d,m.next=d}for(n=d,n.forced=l.forced;;){if(l.links.remove(a),a.links.remove(l),a==s){if(l.links.empty()){e.remove(l);let w=l;w.links.clear(),w.node=null,w.forced=!1,w.next=Oe.zpp_pool,Oe.zpp_pool=w}break}let m=a.x,z=a.y,M;Ce.zpp_pool==null?M=new Ce:(M=Ce.zpp_pool,Ce.zpp_pool=M.next,M.next=null),M.forced=!1,M.x=m,M.y=z;let y=M;if(n==null)y.prev=y.next=y;else{let w=n,v=w.next;y.prev=w,y.next=v,v.prev=y,w.next=y}if(n=y,n.forced=a.forced,a.links.singular()){if(l.links.empty()){e.remove(l);let w=l;w.links.clear(),w.node=null,w.forced=!1,w.next=Oe.zpp_pool,Oe.zpp_pool=w}l=a,a=a.links.parent.data}else{let w=null,v=0;if(!a.links.empty()){let P=a.links.parent;for(;P.prev!=null;)P=P.prev;for(;P!=null;){let g=P.data;if(w==null){w=g;let E=a.x-l.x,N=a.y-l.y,k=g.x-a.x;v=(g.y-a.y)*E-k*N}else{let E=a.x-l.x,N=a.y-l.y,k=g.x-a.x,C=(g.y-a.y)*E-k*N;if(C>0&&v<=0)w=g,v=C;else if(v*C>=0){let F=a.x-g.x,O=a.y-g.y,B=w.x-a.x;(w.y-a.y)*F-B*O>0&&(w=g,v=C)}}if(P.next!=null)for(P=P.next;P.prev!=null;)P=P.prev;else{for(;P.parent!=null&&P==P.parent.next;)P=P.parent;P=P.parent}}}if(l.links.empty()){e.remove(l);let P=l;P.links.clear(),P.node=null,P.forced=!1,P.next=Oe.zpp_pool,Oe.zpp_pool=P}l=a,a=w}}e.remove(s);let b=s;b.links.clear(),b.node=null,b.forced=!1,b.next=Oe.zpp_pool,Oe.zpp_pool=b,t.add(n)}static isSimple(e){ye.sweep==null&&(ye.sweep=new as,ye.inthash=new Es);let t=ye.list_vertices;t==null&&(t=ye.list_vertices=new xo);let n=e,l=e;if(n!=null){let _=n;for(;;){let d=_,b=d.x,m=d.y,z;if(Oe.zpp_pool==null?z=new Oe:(z=Oe.zpp_pool,Oe.zpp_pool=z.next,z.next=null),z.x=b,z.y=m,t.add(z),_=_.next,_==l)break}}let s=ye.list_queue;s==null&&(s=ye.list_queue=new yo);let i=t.head,r=i.elt;for(i=i.next;i!=null;){let _=i.elt,d;Ee.zpp_pool==null?d=new Ee:(d=Ee.zpp_pool,Ee.zpp_pool=d.next,d.next=null),d.vertex=r;let b=s.add(d),m;Ee.zpp_pool==null?m=new Ee:(m=Ee.zpp_pool,Ee.zpp_pool=m.next,m.next=null),m.vertex=_;let z=s.add(m),M;Ee.less_xy(b,z)?(b.type=1,z.type=2,M=en.get(r,_)):(b.type=2,z.type=1,M=en.get(_,r)),b.segment=z.segment=M,r=_,i=i.next}let o=t.head.elt,a;Ee.zpp_pool==null?a=new Ee:(a=Ee.zpp_pool,Ee.zpp_pool=a.next,a.next=null),a.vertex=r;let p=s.add(a),c;Ee.zpp_pool==null?c=new Ee:(c=Ee.zpp_pool,Ee.zpp_pool=c.next,c.next=null),c.vertex=o;let u=s.add(c),h;Ee.less_xy(p,u)?(p.type=1,u.type=2,h=en.get(r,o)):(p.type=2,u.type=1,h=en.get(o,r)),p.segment=u.segment=h;let x=s;if(x.head!=null&&x.head.next!=null){let _=x.head,d,b,m,z,M=1,y,w,v;for(;;){for(y=0,b=_,_=null,d=null;b!=null;){for(++y,m=b,w=0,v=M;m!=null&&w<M;)++w,m=m.next;for(;w>0||v>0&&m!=null;)w==0?(z=m,m=m.next,--v):v==0||m==null||Ee.less_xy(b.elt,m.elt)?(z=b,b=b.next,--w):(z=m,m=m.next,--v),d!=null?d.next=z:_=z,d=z;b=m}if(d.next=null,M<<=1,!(y>1))break}x.head=_,x.modified=!0,x.pushmod=!0}let f=!0;for(;s.head!=null;){let _=s.pop_unsafe(),d=_.segment;if(_.type==1){if(ye.sweep.add(d),ye.sweep.intersect(d,d.next)||ye.sweep.intersect(d,d.prev)){f=!1;break}}else if(_.type==2){if(ye.sweep.intersect(d.prev,d.next)){f=!1;break}ye.sweep.remove(d);let m=d;m.left=m.right=null,m.prev=null,m.node=null,m.vertices.clear(),m.next=en.zpp_pool,en.zpp_pool=m}let b=_;b.vertex=null,b.segment=b.segment2=null,b.node=null,b.next=Ee.zpp_pool,Ee.zpp_pool=b}for(;s.head!=null;){let _=s.pop_unsafe();if(_.type==2){let b=_.segment;b.left=b.right=null,b.prev=null,b.node=null,b.vertices.clear(),b.next=en.zpp_pool,en.zpp_pool=b}let d=_;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Ee.zpp_pool,Ee.zpp_pool=d}for(ye.sweep.clear();t.head!=null;){let _=t.pop_unsafe();_.links.clear(),_.node=null,_.forced=!1,_.next=Oe.zpp_pool,Oe.zpp_pool=_}return f}};ye.__name__=["zpp_nape","geom","ZPP_Simple"],ye.sweep=null,ye.inthash=null,ye.vertices=null,ye.queue=null,ye.ints=null,ye.list_vertices=null,ye.list_queue=null;var ps=ye;var cs=class cs{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 cs.zpp_pool==null?t=new cs:(t=cs.zpp_pool,cs.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t.flag=!1,t}free(){}alloc(){}};cs.__name__=["zpp_nape","geom","ZPP_SimplifyV"],cs.zpp_pool=null;var qn=cs;var hs=class hs{constructor(){this.next=null;this.min=null;this.max=null}static get(e,t){let n;return hs.zpp_pool==null?n=new hs:(n=hs.zpp_pool,hs.zpp_pool=n.next,n.next=null),n.min=e,n.max=t,n}free(){this.min=null,this.max=null}alloc(){}};hs.__name__=["zpp_nape","geom","ZPP_SimplifyP"],hs.zpp_pool=null;var je=hs;var Jt=class Jt{static lessval(e,t){return e.x-t.x+(e.y-t.y)}static less(e,t){return e.x-t.x+(e.y-t.y)<0}static distance(e,t,n){let l=n.x-t.x,s=n.y-t.y,i=e.x-t.x,r=e.y-t.y;if(l*l+s*s==0)return i*i+r*r;{let a=(i*l+r*s)/(l*l+s*s);if(a<=0)return i*i+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 i-=l*p,r-=s*p,i*i+r*r}}}static simplify(e,t){let n=null,l=null,s=null;t*=t,Jt.stack==null&&(Jt.stack=new uo);let i=null,r=null,o=e;for(;;){let p;qn.zpp_pool==null?p=new qn:(p=qn.zpp_pool,qn.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,i!=null){let h=Jt.stack,x;je.zpp_pool==null?x=new je:(x=je.zpp_pool,je.zpp_pool=x.next,x.next=null),x.min=i,x.max=c,h.add(x)}else r=c;i=c}let u=c;if(n==null?u.prev=u.next=u:(u.prev=n,u.next=n.next,n.next.prev=u,n.next=u),n=u,l==null?(l=n,s=n):(n.x-l.x+(n.y-l.y)<0&&(l=n),s.x-n.x+(s.y-n.y)<0&&(s=n)),o=o.next,o==e)break}if(Jt.stack.head==null)if(r==null){l.flag=s.flag=!0;let p=Jt.stack,c;je.zpp_pool==null?c=new je:(c=je.zpp_pool,je.zpp_pool=c.next,c.next=null),c.min=l,c.max=s,p.add(c);let u=Jt.stack,h;je.zpp_pool==null?h=new je:(h=je.zpp_pool,je.zpp_pool=h.next,h.next=null),h.min=s,h.max=l,u.add(h)}else{let p=l.x-r.x+(l.y-r.y);p<0&&(p=-p);let c=s.x-r.x+(s.y-r.y);if(c<0&&(c=-c),p>c){l.flag=r.flag=!0;let u=Jt.stack,h;je.zpp_pool==null?h=new je:(h=je.zpp_pool,je.zpp_pool=h.next,h.next=null),h.min=l,h.max=r,u.add(h);let x=Jt.stack,f;je.zpp_pool==null?f=new je:(f=je.zpp_pool,je.zpp_pool=f.next,f.next=null),f.min=r,f.max=l,x.add(f)}else{s.flag=r.flag=!0;let u=Jt.stack,h;je.zpp_pool==null?h=new je:(h=je.zpp_pool,je.zpp_pool=h.next,h.next=null),h.min=s,h.max=r,u.add(h);let x=Jt.stack,f;je.zpp_pool==null?f=new je:(f=je.zpp_pool,je.zpp_pool=f.next,f.next=null),f.min=r,f.max=s,x.add(f)}}else{let p=Jt.stack,c;je.zpp_pool==null?c=new je:(c=je.zpp_pool,je.zpp_pool=c.next,c.next=null),c.min=i,c.max=r,p.add(c)}for(;Jt.stack.head!=null;){let p=Jt.stack.pop_unsafe(),c=p.min,u=p.max,h=p;h.min=h.max=null,h.next=je.zpp_pool,je.zpp_pool=h;let x=t,f=null,_=c.next;for(;_!=u;){let d=Jt.distance(_,c,u);d>x&&(x=d,f=_),_=_.next}if(f!=null){f.flag=!0;let d=Jt.stack,b;je.zpp_pool==null?b=new je:(b=je.zpp_pool,je.zpp_pool=b.next,b.next=null),b.min=c,b.max=f,d.add(b);let m=Jt.stack,z;je.zpp_pool==null?z=new je:(z=je.zpp_pool,je.zpp_pool=z.next,z.next=null),z.min=f,z.max=u,m.add(z)}}let a=null;for(;n!=null;){if(n.flag){let p=n.x,c=n.y,u;Ce.zpp_pool==null?u=new Ce:(u=Ce.zpp_pool,Ce.zpp_pool=u.next,u.next=null),u.forced=!1,u.x=p,u.y=c;let h=u;a==null?h.prev=h.next=h:(h.prev=a,h.next=a.next,a.next.prev=h,a.next=h),a=h,a.forced=n.forced}if(n!=null&&n.prev==n)n.next=n.prev=null,n.next=qn.zpp_pool,qn.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=qn.zpp_pool,qn.zpp_pool=n,n=p}}return a}};Jt.__name__=["zpp_nape","geom","ZPP_Simplify"],Jt.stack=null;var gl=Jt;var Cl=class{constructor(){this.next=null;this.toi=0;this.s1=null;this.s2=null;this.arbiter=null;this.frozen1=!1;this.frozen2=!1;this.slipped=!1;this.failed=!1;this.kinematic=!1;this.c1=new ie,this.c2=new ie,this.axis=new ie}alloc(){this.failed=!1,this.s1=this.s2=null,this.arbiter=null}free(){}};Cl.__name__=["zpp_nape","geom","ZPP_ToiEvent"],Cl.zpp_pool=null;var un=class{static dynamicSweep(e,t,n,l,s){let i=oe();s==null&&(s=!1);let r=e.s1,o=e.s2,a=r.body,p=o.body,c=0,u=0;c=p.velx-a.velx,u=p.vely-a.vely;let h=a.angvel;h<0&&(h=-h);let x=p.angvel;x<0&&(x=-x);let f=r.sweepCoef*h+o.sweepCoef*x;if(!s&&!e.kinematic&&c*c+u*u<i.Config.dynamicSweepLinearThreshold*i.Config.dynamicSweepLinearThreshold&&f<i.Config.dynamicSweepAngularThreshold){e.toi=-1,e.failed=!0;return}let _=e.c1,d=e.c2,b=e.axis,m=n,z=0;for(;;){let C=m*t,F=C-a.sweepTime;if(F!=0){a.sweepTime=C;let X=F;if(a.posx+=a.velx*X,a.posy+=a.vely*X,a.angvel!=0){let H=a.sweep_angvel*F;if(a.rot+=H,H*H>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let ee=H*H,G=1-.5*ee,R=1-ee*ee/8,j=(G*a.axisx+H*a.axisy)*R;a.axisy=(G*a.axisy-H*a.axisx)*R,a.axisx=j}}}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 X=r.polygon,H=X.lverts.next,ee=X.gverts.next;for(;ee!=null;){let Q=ee,Y=H;H=H.next,Q.x=a.posx+(a.axisy*Y.x-a.axisx*Y.y),Q.y=a.posy+(Y.x*a.axisx+Y.y*a.axisy),ee=ee.next}let G=X.edges.head,R=X.gverts.next,j=R;for(R=R.next;R!=null;){let Q=R,Y=G.elt;G=G.next,Y.gnormx=a.axisy*Y.lnormx-a.axisx*Y.lnormy,Y.gnormy=Y.lnormx*a.axisx+Y.lnormy*a.axisy,Y.gprojection=a.posx*Y.gnormx+a.posy*Y.gnormy+Y.lprojection,Y.tp0=j.y*Y.gnormx-j.x*Y.gnormy,Y.tp1=Q.y*Y.gnormx-Q.x*Y.gnormy,j=Q,R=R.next}let V=X.gverts.next,K=G.elt;G=G.next,K.gnormx=a.axisy*K.lnormx-a.axisx*K.lnormy,K.gnormy=K.lnormx*a.axisx+K.lnormy*a.axisy,K.gprojection=a.posx*K.gnormx+a.posy*K.gnormy+K.lprojection,K.tp0=j.y*K.gnormx-j.x*K.gnormy,K.tp1=V.y*K.gnormx-V.x*K.gnormy}let O=m*t,B=O-p.sweepTime;if(B!=0){p.sweepTime=O;let X=B;if(p.posx+=p.velx*X,p.posy+=p.vely*X,p.angvel!=0){let H=p.sweep_angvel*B;if(p.rot+=H,H*H>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let ee=H*H,G=1-.5*ee,R=1-ee*ee/8,j=(G*p.axisx+H*p.axisy)*R;p.axisy=(G*p.axisy-H*p.axisx)*R,p.axisx=j}}}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 X=o.polygon,H=X.lverts.next,ee=X.gverts.next;for(;ee!=null;){let Q=ee,Y=H;H=H.next,Q.x=p.posx+(p.axisy*Y.x-p.axisx*Y.y),Q.y=p.posy+(Y.x*p.axisx+Y.y*p.axisy),ee=ee.next}let G=X.edges.head,R=X.gverts.next,j=R;for(R=R.next;R!=null;){let Q=R,Y=G.elt;G=G.next,Y.gnormx=p.axisy*Y.lnormx-p.axisx*Y.lnormy,Y.gnormy=Y.lnormx*p.axisx+Y.lnormy*p.axisy,Y.gprojection=p.posx*Y.gnormx+p.posy*Y.gnormy+Y.lprojection,Y.tp0=j.y*Y.gnormx-j.x*Y.gnormy,Y.tp1=Q.y*Y.gnormx-Q.x*Y.gnormy,j=Q,R=R.next}let V=X.gverts.next,K=G.elt;G=G.next,K.gnormx=p.axisy*K.lnormx-p.axisx*K.lnormy,K.gnormy=K.lnormx*p.axisx+K.lnormy*p.axisy,K.gprojection=p.posx*K.gnormx+p.posy*K.gnormy+K.lprojection,K.tp0=j.y*K.gnormx-j.x*K.gnormy,K.tp1=V.y*K.gnormx-V.x*K.gnormy}let D=r,U=o,W=_,q=d;var M;if(D.type==0&&U.type==0){let X=D.circle,H=U.circle;var y;let ee=0,G=0;ee=H.worldCOMx-X.worldCOMx,G=H.worldCOMy-X.worldCOMy;let R=Math.sqrt(ee*ee+G*G);if(y=R-(X.radius+H.radius),y<1e100){if(R==0)ee=1,G=0;else{let K=1/R;ee*=K,G*=K}let j=X.radius;W.x=X.worldCOMx+ee*j,W.y=X.worldCOMy+G*j;let V=-H.radius;q.x=H.worldCOMx+ee*V,q.y=H.worldCOMy+G*V,b.x=ee,b.y=G}M=y}else{let X=!1;if(D.type==0&&U.type==1){let H=D;D=U,U=H;let ee=W;W=q,q=ee,X=!0}if(D.type==1&&U.type==0){let H=D.polygon,ee=U.circle,G=-1e100,R=null,j=H.edges.head;for(;j!=null;){let V=j.elt,K=V.gnormx*ee.worldCOMx+V.gnormy*ee.worldCOMy-V.gprojection-ee.radius;if(K>1e100){G=K;break}K>0?K>G&&(G=K,R=V):G<0&&K>G&&(G=K,R=V),j=j.next}if(G<1e100){let V=R.gp0,K=R.gp1,Q=ee.worldCOMy*R.gnormx-ee.worldCOMx*R.gnormy;if(Q<=V.y*R.gnormx-V.x*R.gnormy){let Y=0,ne=0;Y=ee.worldCOMx-V.x,ne=ee.worldCOMy-V.y;let ae=Math.sqrt(Y*Y+ne*ne);if(G=ae-ee.radius,G<1e100){if(ae==0)Y=1,ne=0;else{let re=1/ae;Y*=re,ne*=re}let le=0;W.x=V.x+Y*le,W.y=V.y+ne*le;let se=-ee.radius;q.x=ee.worldCOMx+Y*se,q.y=ee.worldCOMy+ne*se,b.x=Y,b.y=ne}}else if(Q>=K.y*R.gnormx-K.x*R.gnormy){let Y=0,ne=0;Y=ee.worldCOMx-K.x,ne=ee.worldCOMy-K.y;let ae=Math.sqrt(Y*Y+ne*ne);if(G=ae-ee.radius,G<1e100){if(ae==0)Y=1,ne=0;else{let re=1/ae;Y*=re,ne*=re}let le=0;W.x=K.x+Y*le,W.y=K.y+ne*le;let se=-ee.radius;q.x=ee.worldCOMx+Y*se,q.y=ee.worldCOMy+ne*se,b.x=Y,b.y=ne}}else{let Y=-ee.radius;q.x=ee.worldCOMx+R.gnormx*Y,q.y=ee.worldCOMy+R.gnormy*Y;let ne=-G;W.x=q.x+R.gnormx*ne,W.y=q.y+R.gnormy*ne,b.x=R.gnormx,b.y=R.gnormy}}X&&(b.x=-b.x,b.y=-b.y),M=G}else{let H=D.polygon,ee=U.polygon,G=-1e100,R=null,j=null,V=0,K=H.edges.head;for(;K!=null;){let Q=K.elt,Y=1e100,ne=ee.gverts.next;for(;ne!=null;){let ae=ne,le=Q.gnormx*ae.x+Q.gnormy*ae.y;le<Y&&(Y=le),ne=ne.next}if(Y-=Q.gprojection,Y>1e100){G=Y;break}Y>0?Y>G&&(G=Y,R=Q,V=1):G<0&&Y>G&&(G=Y,R=Q,V=1),K=K.next}if(G<1e100){let Q=ee.edges.head;for(;Q!=null;){let Y=Q.elt,ne=1e100,ae=H.gverts.next;for(;ae!=null;){let le=ae,se=Y.gnormx*le.x+Y.gnormy*le.y;se<ne&&(ne=se),ae=ae.next}if(ne-=Y.gprojection,ne>1e100){G=ne;break}ne>0?ne>G&&(G=ne,j=Y,V=2):G<0&&ne>G&&(G=ne,j=Y,V=2),Q=Q.next}if(G<1e100){var w,v,P;if(V==1)w=H,v=ee,P=R;else{w=ee,v=H,P=j;let le=W;W=q,q=le,X=!X}let Y=null,ne=1e100,ae=v.edges.head;for(;ae!=null;){let le=ae.elt,se=P.gnormx*le.gnormx+P.gnormy*le.gnormy;se<ne&&(ne=se,Y=le),ae=ae.next}if(X?(b.x=-P.gnormx,b.y=-P.gnormy):(b.x=P.gnormx,b.y=P.gnormy),G>=0){let le=P.gp0,se=P.gp1,re=Y.gp0,he=Y.gp1,ce=0,pe=0,de=0,te=0;ce=se.x-le.x,pe=se.y-le.y,de=he.x-re.x,te=he.y-re.y;let _e=1/(ce*ce+pe*pe),me=1/(de*de+te*te),xe=-(ce*(le.x-re.x)+pe*(le.y-re.y))*_e,ge=-(ce*(le.x-he.x)+pe*(le.y-he.y))*_e,Ie=-(de*(re.x-le.x)+te*(re.y-le.y))*me,De=-(de*(re.x-se.x)+te*(re.y-se.y))*me;xe<0?xe=0:xe>1&&(xe=1),ge<0?ge=0:ge>1&&(ge=1),Ie<0?Ie=0:Ie>1&&(Ie=1),De<0?De=0:De>1&&(De=1);let tt=0,st=0,lt=xe;tt=le.x+ce*lt,st=le.y+pe*lt;let qe=0,At=0,Rt=ge;qe=le.x+ce*Rt,At=le.y+pe*Rt;let Pt=0,wt=0,bt=Ie;Pt=re.x+de*bt,wt=re.y+te*bt;let nt=0,Vt=0,sn=De;nt=re.x+de*sn,Vt=re.y+te*sn;let pn=0,Yt=0;pn=tt-re.x,Yt=st-re.y;let Xt=pn*pn+Yt*Yt,Dn=0,dn=0;Dn=qe-he.x,dn=At-he.y;let Sn=Dn*Dn+dn*dn,Zn=0,An=0;Zn=Pt-le.x,An=wt-le.y;let yn=Zn*Zn+An*An,Fn=0,mn=0;Fn=nt-se.x,mn=Vt-se.y;let Vn=Fn*Fn+mn*mn,cn=0,fn=0,Mn=null;Xt<Sn?(cn=tt,fn=st,Mn=re):(cn=qe,fn=At,Mn=he,Xt=Sn);let Bi=0,ci=0,ni=null;if(yn<Vn?(Bi=Pt,ci=wt,ni=le):(Bi=nt,ci=Vt,ni=se,yn=Vn),Xt<yn?(W.x=cn,W.y=fn,q.x=Mn.x,q.y=Mn.y,G=Math.sqrt(Xt)):(q.x=Bi,q.y=ci,W.x=ni.x,W.y=ni.y,G=Math.sqrt(yn)),G!=0){b.x=q.x-W.x,b.y=q.y-W.y;let ii=1/G;b.x*=ii,b.y*=ii,X&&(b.x=-b.x,b.y=-b.y)}M=G}else{let le=0,se=0;le=Y.gp0.x,se=Y.gp0.y;let re=0,he=0;re=Y.gp1.x,he=Y.gp1.y;let ce=0,pe=0;ce=re-le,pe=he-se;let de=P.gnormy*le-P.gnormx*se,te=P.gnormy*re-P.gnormx*he,_e=1/(te-de),me=(-P.tp1-de)*_e;if(me>i.Config.epsilon){let De=me;le+=ce*De,se+=pe*De}let xe=(-P.tp0-te)*_e;if(xe<-i.Config.epsilon){let De=xe;re+=ce*De,he+=pe*De}let ge=le*P.gnormx+se*P.gnormy-P.gprojection,Ie=re*P.gnormx+he*P.gnormy-P.gprojection;if(ge<Ie){q.x=le,q.y=se;let De=-ge;W.x=q.x+P.gnormx*De,W.y=q.y+P.gnormy*De,M=ge}else{q.x=re,q.y=he;let De=-Ie;W.x=q.x+P.gnormx*De,W.y=q.y+P.gnormy*De,M=Ie}}}else M=1e100}else M=1e100}}let L=M+l,A=c*b.x+u*b.y;if(L<i.Config.distanceThresholdCCD){if(s)break;let X=0,H=0;X=_.x-a.posx,H=_.y-a.posy;let ee=0,G=0;ee=d.x-p.posx,G=d.y-p.posy;let R=A-a.sweep_angvel*(b.y*X-b.x*H)+p.sweep_angvel*(b.y*ee-b.x*G);if(R>0&&(e.slipped=!0),R<=0||L<i.Config.distanceThresholdCCD*.5)break}let J=(f-A)*t;if(J<=0){m=-1;break}let $=L/J;if($<1e-6&&($=1e-6),m+=$,m>=1){m=1;let X=m*t,H=X-a.sweepTime;if(H!=0){a.sweepTime=X;let ne=H;if(a.posx+=a.velx*ne,a.posy+=a.vely*ne,a.angvel!=0){let ae=a.sweep_angvel*H;if(a.rot+=ae,ae*ae>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let le=ae*ae,se=1-.5*le,re=1-le*le/8,he=(se*a.axisx+ae*a.axisy)*re;a.axisy=(se*a.axisy-ae*a.axisx)*re,a.axisx=he}}}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 ne=r.polygon,ae=ne.lverts.next,le=ne.gverts.next;for(;le!=null;){let de=le,te=ae;ae=ae.next,de.x=a.posx+(a.axisy*te.x-a.axisx*te.y),de.y=a.posy+(te.x*a.axisx+te.y*a.axisy),le=le.next}let se=ne.edges.head,re=ne.gverts.next,he=re;for(re=re.next;re!=null;){let de=re,te=se.elt;se=se.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=he.y*te.gnormx-he.x*te.gnormy,te.tp1=de.y*te.gnormx-de.x*te.gnormy,he=de,re=re.next}let ce=ne.gverts.next,pe=se.elt;se=se.next,pe.gnormx=a.axisy*pe.lnormx-a.axisx*pe.lnormy,pe.gnormy=pe.lnormx*a.axisx+pe.lnormy*a.axisy,pe.gprojection=a.posx*pe.gnormx+a.posy*pe.gnormy+pe.lprojection,pe.tp0=he.y*pe.gnormx-he.x*pe.gnormy,pe.tp1=ce.y*pe.gnormx-ce.x*pe.gnormy}let ee=m*t,G=ee-p.sweepTime;if(G!=0){p.sweepTime=ee;let ne=G;if(p.posx+=p.velx*ne,p.posy+=p.vely*ne,p.angvel!=0){let ae=p.sweep_angvel*G;if(p.rot+=ae,ae*ae>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let le=ae*ae,se=1-.5*le,re=1-le*le/8,he=(se*p.axisx+ae*p.axisy)*re;p.axisy=(se*p.axisy-ae*p.axisx)*re,p.axisx=he}}}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 ne=o.polygon,ae=ne.lverts.next,le=ne.gverts.next;for(;le!=null;){let de=le,te=ae;ae=ae.next,de.x=p.posx+(p.axisy*te.x-p.axisx*te.y),de.y=p.posy+(te.x*p.axisx+te.y*p.axisy),le=le.next}let se=ne.edges.head,re=ne.gverts.next,he=re;for(re=re.next;re!=null;){let de=re,te=se.elt;se=se.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=he.y*te.gnormx-he.x*te.gnormy,te.tp1=de.y*te.gnormx-de.x*te.gnormy,he=de,re=re.next}let ce=ne.gverts.next,pe=se.elt;se=se.next,pe.gnormx=p.axisy*pe.lnormx-p.axisx*pe.lnormy,pe.gnormy=pe.lnormx*p.axisx+pe.lnormy*p.axisy,pe.gprojection=p.posx*pe.gnormx+p.posy*pe.gnormy+pe.lprojection,pe.tp0=he.y*pe.gnormx-he.x*pe.gnormy,pe.tp1=ce.y*pe.gnormx-ce.x*pe.gnormy}let R=r,j=o,V=_,K=d;var g;if(R.type==0&&j.type==0){let ne=R.circle,ae=j.circle;var E;let le=0,se=0;le=ae.worldCOMx-ne.worldCOMx,se=ae.worldCOMy-ne.worldCOMy;let re=Math.sqrt(le*le+se*se);if(E=re-(ne.radius+ae.radius),E<1e100){if(re==0)le=1,se=0;else{let pe=1/re;le*=pe,se*=pe}let he=ne.radius;V.x=ne.worldCOMx+le*he,V.y=ne.worldCOMy+se*he;let ce=-ae.radius;K.x=ae.worldCOMx+le*ce,K.y=ae.worldCOMy+se*ce,b.x=le,b.y=se}g=E}else{let ne=!1;if(R.type==0&&j.type==1){let ae=R;R=j,j=ae;let le=V;V=K,K=le,ne=!0}if(R.type==1&&j.type==0){let ae=R.polygon,le=j.circle,se=-1e100,re=null,he=ae.edges.head;for(;he!=null;){let ce=he.elt,pe=ce.gnormx*le.worldCOMx+ce.gnormy*le.worldCOMy-ce.gprojection-le.radius;if(pe>1e100){se=pe;break}pe>0?pe>se&&(se=pe,re=ce):se<0&&pe>se&&(se=pe,re=ce),he=he.next}if(se<1e100){let ce=re.gp0,pe=re.gp1,de=le.worldCOMy*re.gnormx-le.worldCOMx*re.gnormy;if(de<=ce.y*re.gnormx-ce.x*re.gnormy){let te=0,_e=0;te=le.worldCOMx-ce.x,_e=le.worldCOMy-ce.y;let me=Math.sqrt(te*te+_e*_e);if(se=me-le.radius,se<1e100){if(me==0)te=1,_e=0;else{let Ie=1/me;te*=Ie,_e*=Ie}let xe=0;V.x=ce.x+te*xe,V.y=ce.y+_e*xe;let ge=-le.radius;K.x=le.worldCOMx+te*ge,K.y=le.worldCOMy+_e*ge,b.x=te,b.y=_e}}else if(de>=pe.y*re.gnormx-pe.x*re.gnormy){let te=0,_e=0;te=le.worldCOMx-pe.x,_e=le.worldCOMy-pe.y;let me=Math.sqrt(te*te+_e*_e);if(se=me-le.radius,se<1e100){if(me==0)te=1,_e=0;else{let Ie=1/me;te*=Ie,_e*=Ie}let xe=0;V.x=pe.x+te*xe,V.y=pe.y+_e*xe;let ge=-le.radius;K.x=le.worldCOMx+te*ge,K.y=le.worldCOMy+_e*ge,b.x=te,b.y=_e}}else{let te=-le.radius;K.x=le.worldCOMx+re.gnormx*te,K.y=le.worldCOMy+re.gnormy*te;let _e=-se;V.x=K.x+re.gnormx*_e,V.y=K.y+re.gnormy*_e,b.x=re.gnormx,b.y=re.gnormy}}ne&&(b.x=-b.x,b.y=-b.y),g=se}else{let ae=R.polygon,le=j.polygon,se=-1e100,re=null,he=null,ce=0,pe=ae.edges.head;for(;pe!=null;){let de=pe.elt,te=1e100,_e=le.gverts.next;for(;_e!=null;){let me=_e,xe=de.gnormx*me.x+de.gnormy*me.y;xe<te&&(te=xe),_e=_e.next}if(te-=de.gprojection,te>1e100){se=te;break}te>0?te>se&&(se=te,re=de,ce=1):se<0&&te>se&&(se=te,re=de,ce=1),pe=pe.next}if(se<1e100){let de=le.edges.head;for(;de!=null;){let te=de.elt,_e=1e100,me=ae.gverts.next;for(;me!=null;){let xe=me,ge=te.gnormx*xe.x+te.gnormy*xe.y;ge<_e&&(_e=ge),me=me.next}if(_e-=te.gprojection,_e>1e100){se=_e;break}_e>0?_e>se&&(se=_e,he=te,ce=2):se<0&&_e>se&&(se=_e,he=te,ce=2),de=de.next}if(se<1e100){var N,k,Z;if(ce==1)N=ae,k=le,Z=re;else{N=le,k=ae,Z=he;let xe=V;V=K,K=xe,ne=!ne}let te=null,_e=1e100,me=k.edges.head;for(;me!=null;){let xe=me.elt,ge=Z.gnormx*xe.gnormx+Z.gnormy*xe.gnormy;ge<_e&&(_e=ge,te=xe),me=me.next}if(ne?(b.x=-Z.gnormx,b.y=-Z.gnormy):(b.x=Z.gnormx,b.y=Z.gnormy),se>=0){let xe=Z.gp0,ge=Z.gp1,Ie=te.gp0,De=te.gp1,tt=0,st=0,lt=0,qe=0;tt=ge.x-xe.x,st=ge.y-xe.y,lt=De.x-Ie.x,qe=De.y-Ie.y;let At=1/(tt*tt+st*st),Rt=1/(lt*lt+qe*qe),Pt=-(tt*(xe.x-Ie.x)+st*(xe.y-Ie.y))*At,wt=-(tt*(xe.x-De.x)+st*(xe.y-De.y))*At,bt=-(lt*(Ie.x-xe.x)+qe*(Ie.y-xe.y))*Rt,nt=-(lt*(Ie.x-ge.x)+qe*(Ie.y-ge.y))*Rt;Pt<0?Pt=0:Pt>1&&(Pt=1),wt<0?wt=0:wt>1&&(wt=1),bt<0?bt=0:bt>1&&(bt=1),nt<0?nt=0:nt>1&&(nt=1);let Vt=0,sn=0,pn=Pt;Vt=xe.x+tt*pn,sn=xe.y+st*pn;let Yt=0,Xt=0,Dn=wt;Yt=xe.x+tt*Dn,Xt=xe.y+st*Dn;let dn=0,Sn=0,Zn=bt;dn=Ie.x+lt*Zn,Sn=Ie.y+qe*Zn;let An=0,yn=0,Fn=nt;An=Ie.x+lt*Fn,yn=Ie.y+qe*Fn;let mn=0,Vn=0;mn=Vt-Ie.x,Vn=sn-Ie.y;let cn=mn*mn+Vn*Vn,fn=0,Mn=0;fn=Yt-De.x,Mn=Xt-De.y;let Bi=fn*fn+Mn*Mn,ci=0,ni=0;ci=dn-xe.x,ni=Sn-xe.y;let ii=ci*ci+ni*ni,zs=0,Ps=0;zs=An-ge.x,Ps=yn-ge.y;let ws=zs*zs+Ps*Ps,_l=0,po=0,Yr=null;cn<Bi?(_l=Vt,po=sn,Yr=Ie):(_l=Yt,po=Xt,Yr=De,cn=Bi);let co=0,ho=0,Xr=null;if(ii<ws?(co=dn,ho=Sn,Xr=xe):(co=An,ho=yn,Xr=ge,ii=ws),cn<ii?(V.x=_l,V.y=po,K.x=Yr.x,K.y=Yr.y,se=Math.sqrt(cn)):(K.x=co,K.y=ho,V.x=Xr.x,V.y=Xr.y,se=Math.sqrt(ii)),se!=0){b.x=K.x-V.x,b.y=K.y-V.y;let vo=1/se;b.x*=vo,b.y*=vo,ne&&(b.x=-b.x,b.y=-b.y)}g=se}else{let xe=0,ge=0;xe=te.gp0.x,ge=te.gp0.y;let Ie=0,De=0;Ie=te.gp1.x,De=te.gp1.y;let tt=0,st=0;tt=Ie-xe,st=De-ge;let lt=Z.gnormy*xe-Z.gnormx*ge,qe=Z.gnormy*Ie-Z.gnormx*De,At=1/(qe-lt),Rt=(-Z.tp1-lt)*At;if(Rt>i.Config.epsilon){let nt=Rt;xe+=tt*nt,ge+=st*nt}let Pt=(-Z.tp0-qe)*At;if(Pt<-i.Config.epsilon){let nt=Pt;Ie+=tt*nt,De+=st*nt}let wt=xe*Z.gnormx+ge*Z.gnormy-Z.gprojection,bt=Ie*Z.gnormx+De*Z.gnormy-Z.gprojection;if(wt<bt){K.x=xe,K.y=ge;let nt=-wt;V.x=K.x+Z.gnormx*nt,V.y=K.y+Z.gnormy*nt,g=wt}else{K.x=Ie,K.y=De;let nt=-bt;V.x=K.x+Z.gnormx*nt,V.y=K.y+Z.gnormy*nt,g=bt}}}else g=1e100}else g=1e100}}let Q=g+l,Y=c*b.x+u*b.y;if(Q<i.Config.distanceThresholdCCD){if(s)break;let ne=0,ae=0;ne=_.x-a.posx,ae=_.y-a.posy;let le=0,se=0;le=d.x-p.posx,se=d.y-p.posy;let re=Y-a.sweep_angvel*(b.y*ne-b.x*ae)+p.sweep_angvel*(b.y*le-b.x*se);if(re>0&&(e.slipped=!0),re<=0||Q<i.Config.distanceThresholdCCD*.5)break}m=-1;break}if(++z>=40){L>l&&(e.failed=!0);break}}e.toi=m}static staticSweep(e,t,n,l){let s=oe(),i=e.s1,r=e.s2,o=i.body,a=r.body,p=0,c=0;p=-o.velx,c=-o.vely;let u=o.sweep_angvel;u<0&&(u=-u);let h=i.sweepCoef*u,x=e.c1,f=e.c2,_=e.axis,d=n,b=0;for(;;){let k=d*t,Z=k-o.sweepTime;if(Z!=0){o.sweepTime=k;let L=Z;if(o.posx+=o.velx*L,o.posy+=o.vely*L,o.angvel!=0){let A=o.sweep_angvel*Z;if(o.rot+=A,A*A>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let J=A*A,$=1-.5*J,X=1-J*J/8,H=($*o.axisx+A*o.axisy)*X;o.axisy=($*o.axisy-A*o.axisx)*X,o.axisx=H}}}if(i.type==0)i.worldCOMx=o.posx+(o.axisy*i.localCOMx-o.axisx*i.localCOMy),i.worldCOMy=o.posy+(i.localCOMx*o.axisx+i.localCOMy*o.axisy);else{let L=i.polygon,A=L.lverts.next,J=L.gverts.next;for(;J!=null;){let R=J,j=A;A=A.next,R.x=o.posx+(o.axisy*j.x-o.axisx*j.y),R.y=o.posy+(j.x*o.axisx+j.y*o.axisy),J=J.next}let $=L.edges.head,X=L.gverts.next,H=X;for(X=X.next;X!=null;){let R=X,j=$.elt;$=$.next,j.gnormx=o.axisy*j.lnormx-o.axisx*j.lnormy,j.gnormy=j.lnormx*o.axisx+j.lnormy*o.axisy,j.gprojection=o.posx*j.gnormx+o.posy*j.gnormy+j.lprojection,j.tp0=H.y*j.gnormx-H.x*j.gnormy,j.tp1=R.y*j.gnormx-R.x*j.gnormy,H=R,X=X.next}let ee=L.gverts.next,G=$.elt;$=$.next,G.gnormx=o.axisy*G.lnormx-o.axisx*G.lnormy,G.gnormy=G.lnormx*o.axisx+G.lnormy*o.axisy,G.gprojection=o.posx*G.gnormx+o.posy*G.gnormy+G.lprojection,G.tp0=H.y*G.gnormx-H.x*G.gnormy,G.tp1=ee.y*G.gnormx-ee.x*G.gnormy}let C=i,F=r,O=x,B=f;var m;if(C.type==0&&F.type==0){let L=C.circle,A=F.circle;var z;let J=0,$=0;J=A.worldCOMx-L.worldCOMx,$=A.worldCOMy-L.worldCOMy;let X=Math.sqrt(J*J+$*$);if(z=X-(L.radius+A.radius),z<1e100){if(X==0)J=1,$=0;else{let G=1/X;J*=G,$*=G}let H=L.radius;O.x=L.worldCOMx+J*H,O.y=L.worldCOMy+$*H;let ee=-A.radius;B.x=A.worldCOMx+J*ee,B.y=A.worldCOMy+$*ee,_.x=J,_.y=$}m=z}else{let L=!1;if(C.type==0&&F.type==1){let A=C;C=F,F=A;let J=O;O=B,B=J,L=!0}if(C.type==1&&F.type==0){let A=C.polygon,J=F.circle,$=-1e100,X=null,H=A.edges.head;for(;H!=null;){let ee=H.elt,G=ee.gnormx*J.worldCOMx+ee.gnormy*J.worldCOMy-ee.gprojection-J.radius;if(G>1e100){$=G;break}G>0?G>$&&($=G,X=ee):$<0&&G>$&&($=G,X=ee),H=H.next}if($<1e100){let ee=X.gp0,G=X.gp1,R=J.worldCOMy*X.gnormx-J.worldCOMx*X.gnormy;if(R<=ee.y*X.gnormx-ee.x*X.gnormy){let j=0,V=0;j=J.worldCOMx-ee.x,V=J.worldCOMy-ee.y;let K=Math.sqrt(j*j+V*V);if($=K-J.radius,$<1e100){if(K==0)j=1,V=0;else{let ne=1/K;j*=ne,V*=ne}let Q=0;O.x=ee.x+j*Q,O.y=ee.y+V*Q;let Y=-J.radius;B.x=J.worldCOMx+j*Y,B.y=J.worldCOMy+V*Y,_.x=j,_.y=V}}else if(R>=G.y*X.gnormx-G.x*X.gnormy){let j=0,V=0;j=J.worldCOMx-G.x,V=J.worldCOMy-G.y;let K=Math.sqrt(j*j+V*V);if($=K-J.radius,$<1e100){if(K==0)j=1,V=0;else{let ne=1/K;j*=ne,V*=ne}let Q=0;O.x=G.x+j*Q,O.y=G.y+V*Q;let Y=-J.radius;B.x=J.worldCOMx+j*Y,B.y=J.worldCOMy+V*Y,_.x=j,_.y=V}}else{let j=-J.radius;B.x=J.worldCOMx+X.gnormx*j,B.y=J.worldCOMy+X.gnormy*j;let V=-$;O.x=B.x+X.gnormx*V,O.y=B.y+X.gnormy*V,_.x=X.gnormx,_.y=X.gnormy}}L&&(_.x=-_.x,_.y=-_.y),m=$}else{let A=C.polygon,J=F.polygon,$=-1e100,X=null,H=null,ee=0,G=A.edges.head;for(;G!=null;){let R=G.elt,j=1e100,V=J.gverts.next;for(;V!=null;){let K=V,Q=R.gnormx*K.x+R.gnormy*K.y;Q<j&&(j=Q),V=V.next}if(j-=R.gprojection,j>1e100){$=j;break}j>0?j>$&&($=j,X=R,ee=1):$<0&&j>$&&($=j,X=R,ee=1),G=G.next}if($<1e100){let R=J.edges.head;for(;R!=null;){let j=R.elt,V=1e100,K=A.gverts.next;for(;K!=null;){let Q=K,Y=j.gnormx*Q.x+j.gnormy*Q.y;Y<V&&(V=Y),K=K.next}if(V-=j.gprojection,V>1e100){$=V;break}V>0?V>$&&($=V,H=j,ee=2):$<0&&V>$&&($=V,H=j,ee=2),R=R.next}if($<1e100){var M,y,w;if(ee==1)M=A,y=J,w=X;else{M=J,y=A,w=H;let Q=O;O=B,B=Q,L=!L}let j=null,V=1e100,K=y.edges.head;for(;K!=null;){let Q=K.elt,Y=w.gnormx*Q.gnormx+w.gnormy*Q.gnormy;Y<V&&(V=Y,j=Q),K=K.next}if(L?(_.x=-w.gnormx,_.y=-w.gnormy):(_.x=w.gnormx,_.y=w.gnormy),$>=0){let Q=w.gp0,Y=w.gp1,ne=j.gp0,ae=j.gp1,le=0,se=0,re=0,he=0;le=Y.x-Q.x,se=Y.y-Q.y,re=ae.x-ne.x,he=ae.y-ne.y;let ce=1/(le*le+se*se),pe=1/(re*re+he*he),de=-(le*(Q.x-ne.x)+se*(Q.y-ne.y))*ce,te=-(le*(Q.x-ae.x)+se*(Q.y-ae.y))*ce,_e=-(re*(ne.x-Q.x)+he*(ne.y-Q.y))*pe,me=-(re*(ne.x-Y.x)+he*(ne.y-Y.y))*pe;de<0?de=0:de>1&&(de=1),te<0?te=0:te>1&&(te=1),_e<0?_e=0:_e>1&&(_e=1),me<0?me=0:me>1&&(me=1);let xe=0,ge=0,Ie=de;xe=Q.x+le*Ie,ge=Q.y+se*Ie;let De=0,tt=0,st=te;De=Q.x+le*st,tt=Q.y+se*st;let lt=0,qe=0,At=_e;lt=ne.x+re*At,qe=ne.y+he*At;let Rt=0,Pt=0,wt=me;Rt=ne.x+re*wt,Pt=ne.y+he*wt;let bt=0,nt=0;bt=xe-ne.x,nt=ge-ne.y;let Vt=bt*bt+nt*nt,sn=0,pn=0;sn=De-ae.x,pn=tt-ae.y;let Yt=sn*sn+pn*pn,Xt=0,Dn=0;Xt=lt-Q.x,Dn=qe-Q.y;let dn=Xt*Xt+Dn*Dn,Sn=0,Zn=0;Sn=Rt-Y.x,Zn=Pt-Y.y;let An=Sn*Sn+Zn*Zn,yn=0,Fn=0,mn=null;Vt<Yt?(yn=xe,Fn=ge,mn=ne):(yn=De,Fn=tt,mn=ae,Vt=Yt);let Vn=0,cn=0,fn=null;if(dn<An?(Vn=lt,cn=qe,fn=Q):(Vn=Rt,cn=Pt,fn=Y,dn=An),Vt<dn?(O.x=yn,O.y=Fn,B.x=mn.x,B.y=mn.y,$=Math.sqrt(Vt)):(B.x=Vn,B.y=cn,O.x=fn.x,O.y=fn.y,$=Math.sqrt(dn)),$!=0){_.x=B.x-O.x,_.y=B.y-O.y;let Mn=1/$;_.x*=Mn,_.y*=Mn,L&&(_.x=-_.x,_.y=-_.y)}m=$}else{let Q=0,Y=0;Q=j.gp0.x,Y=j.gp0.y;let ne=0,ae=0;ne=j.gp1.x,ae=j.gp1.y;let le=0,se=0;le=ne-Q,se=ae-Y;let re=w.gnormy*Q-w.gnormx*Y,he=w.gnormy*ne-w.gnormx*ae,ce=1/(he-re),pe=(-w.tp1-re)*ce;if(pe>s.Config.epsilon){let me=pe;Q+=le*me,Y+=se*me}let de=(-w.tp0-he)*ce;if(de<-s.Config.epsilon){let me=de;ne+=le*me,ae+=se*me}let te=Q*w.gnormx+Y*w.gnormy-w.gprojection,_e=ne*w.gnormx+ae*w.gnormy-w.gprojection;if(te<_e){B.x=Q,B.y=Y;let me=-te;O.x=B.x+w.gnormx*me,O.y=B.y+w.gnormy*me,m=te}else{B.x=ne,B.y=ae;let me=-_e;O.x=B.x+w.gnormx*me,O.y=B.y+w.gnormy*me,m=_e}}}else m=1e100}else m=1e100}}let D=m+l,U=p*_.x+c*_.y;if(D<s.Config.distanceThresholdCCD){let L=0,A=0;L=x.x-o.posx,A=x.y-o.posy;let J=U-o.sweep_angvel*(_.y*L-_.x*A);if(J>0&&(e.slipped=!0),J<=0||D<s.Config.distanceThresholdCCD*.5)break}let W=(h-U)*t;if(W<=0){d=-1;break}let q=D/W;if(q<1e-6&&(q=1e-6),d+=q,d>=1){d=1;let L=d*t,A=L-o.sweepTime;if(A!=0){o.sweepTime=L;let R=A;if(o.posx+=o.velx*R,o.posy+=o.vely*R,o.angvel!=0){let j=o.sweep_angvel*A;if(o.rot+=j,j*j>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let V=j*j,K=1-.5*V,Q=1-V*V/8,Y=(K*o.axisx+j*o.axisy)*Q;o.axisy=(K*o.axisy-j*o.axisx)*Q,o.axisx=Y}}}if(i.type==0)i.worldCOMx=o.posx+(o.axisy*i.localCOMx-o.axisx*i.localCOMy),i.worldCOMy=o.posy+(i.localCOMx*o.axisx+i.localCOMy*o.axisy);else{let R=i.polygon,j=R.lverts.next,V=R.gverts.next;for(;V!=null;){let le=V,se=j;j=j.next,le.x=o.posx+(o.axisy*se.x-o.axisx*se.y),le.y=o.posy+(se.x*o.axisx+se.y*o.axisy),V=V.next}let K=R.edges.head,Q=R.gverts.next,Y=Q;for(Q=Q.next;Q!=null;){let le=Q,se=K.elt;K=K.next,se.gnormx=o.axisy*se.lnormx-o.axisx*se.lnormy,se.gnormy=se.lnormx*o.axisx+se.lnormy*o.axisy,se.gprojection=o.posx*se.gnormx+o.posy*se.gnormy+se.lprojection,se.tp0=Y.y*se.gnormx-Y.x*se.gnormy,se.tp1=le.y*se.gnormx-le.x*se.gnormy,Y=le,Q=Q.next}let ne=R.gverts.next,ae=K.elt;K=K.next,ae.gnormx=o.axisy*ae.lnormx-o.axisx*ae.lnormy,ae.gnormy=ae.lnormx*o.axisx+ae.lnormy*o.axisy,ae.gprojection=o.posx*ae.gnormx+o.posy*ae.gnormy+ae.lprojection,ae.tp0=Y.y*ae.gnormx-Y.x*ae.gnormy,ae.tp1=ne.y*ae.gnormx-ne.x*ae.gnormy}let J=i,$=r,X=x,H=f;var v;if(J.type==0&&$.type==0){let R=J.circle,j=$.circle;var P;let V=0,K=0;V=j.worldCOMx-R.worldCOMx,K=j.worldCOMy-R.worldCOMy;let Q=Math.sqrt(V*V+K*K);if(P=Q-(R.radius+j.radius),P<1e100){if(Q==0)V=1,K=0;else{let ae=1/Q;V*=ae,K*=ae}let Y=R.radius;X.x=R.worldCOMx+V*Y,X.y=R.worldCOMy+K*Y;let ne=-j.radius;H.x=j.worldCOMx+V*ne,H.y=j.worldCOMy+K*ne,_.x=V,_.y=K}v=P}else{let R=!1;if(J.type==0&&$.type==1){let j=J;J=$,$=j;let V=X;X=H,H=V,R=!0}if(J.type==1&&$.type==0){let j=J.polygon,V=$.circle,K=-1e100,Q=null,Y=j.edges.head;for(;Y!=null;){let ne=Y.elt,ae=ne.gnormx*V.worldCOMx+ne.gnormy*V.worldCOMy-ne.gprojection-V.radius;if(ae>1e100){K=ae;break}ae>0?ae>K&&(K=ae,Q=ne):K<0&&ae>K&&(K=ae,Q=ne),Y=Y.next}if(K<1e100){let ne=Q.gp0,ae=Q.gp1,le=V.worldCOMy*Q.gnormx-V.worldCOMx*Q.gnormy;if(le<=ne.y*Q.gnormx-ne.x*Q.gnormy){let se=0,re=0;se=V.worldCOMx-ne.x,re=V.worldCOMy-ne.y;let he=Math.sqrt(se*se+re*re);if(K=he-V.radius,K<1e100){if(he==0)se=1,re=0;else{let de=1/he;se*=de,re*=de}let ce=0;X.x=ne.x+se*ce,X.y=ne.y+re*ce;let pe=-V.radius;H.x=V.worldCOMx+se*pe,H.y=V.worldCOMy+re*pe,_.x=se,_.y=re}}else if(le>=ae.y*Q.gnormx-ae.x*Q.gnormy){let se=0,re=0;se=V.worldCOMx-ae.x,re=V.worldCOMy-ae.y;let he=Math.sqrt(se*se+re*re);if(K=he-V.radius,K<1e100){if(he==0)se=1,re=0;else{let de=1/he;se*=de,re*=de}let ce=0;X.x=ae.x+se*ce,X.y=ae.y+re*ce;let pe=-V.radius;H.x=V.worldCOMx+se*pe,H.y=V.worldCOMy+re*pe,_.x=se,_.y=re}}else{let se=-V.radius;H.x=V.worldCOMx+Q.gnormx*se,H.y=V.worldCOMy+Q.gnormy*se;let re=-K;X.x=H.x+Q.gnormx*re,X.y=H.y+Q.gnormy*re,_.x=Q.gnormx,_.y=Q.gnormy}}R&&(_.x=-_.x,_.y=-_.y),v=K}else{let j=J.polygon,V=$.polygon,K=-1e100,Q=null,Y=null,ne=0,ae=j.edges.head;for(;ae!=null;){let le=ae.elt,se=1e100,re=V.gverts.next;for(;re!=null;){let he=re,ce=le.gnormx*he.x+le.gnormy*he.y;ce<se&&(se=ce),re=re.next}if(se-=le.gprojection,se>1e100){K=se;break}se>0?se>K&&(K=se,Q=le,ne=1):K<0&&se>K&&(K=se,Q=le,ne=1),ae=ae.next}if(K<1e100){let le=V.edges.head;for(;le!=null;){let se=le.elt,re=1e100,he=j.gverts.next;for(;he!=null;){let ce=he,pe=se.gnormx*ce.x+se.gnormy*ce.y;pe<re&&(re=pe),he=he.next}if(re-=se.gprojection,re>1e100){K=re;break}re>0?re>K&&(K=re,Y=se,ne=2):K<0&&re>K&&(K=re,Y=se,ne=2),le=le.next}if(K<1e100){var g,E,N;if(ne==1)g=j,E=V,N=Q;else{g=V,E=j,N=Y;let ce=X;X=H,H=ce,R=!R}let se=null,re=1e100,he=E.edges.head;for(;he!=null;){let ce=he.elt,pe=N.gnormx*ce.gnormx+N.gnormy*ce.gnormy;pe<re&&(re=pe,se=ce),he=he.next}if(R?(_.x=-N.gnormx,_.y=-N.gnormy):(_.x=N.gnormx,_.y=N.gnormy),K>=0){let ce=N.gp0,pe=N.gp1,de=se.gp0,te=se.gp1,_e=0,me=0,xe=0,ge=0;_e=pe.x-ce.x,me=pe.y-ce.y,xe=te.x-de.x,ge=te.y-de.y;let Ie=1/(_e*_e+me*me),De=1/(xe*xe+ge*ge),tt=-(_e*(ce.x-de.x)+me*(ce.y-de.y))*Ie,st=-(_e*(ce.x-te.x)+me*(ce.y-te.y))*Ie,lt=-(xe*(de.x-ce.x)+ge*(de.y-ce.y))*De,qe=-(xe*(de.x-pe.x)+ge*(de.y-pe.y))*De;tt<0?tt=0:tt>1&&(tt=1),st<0?st=0:st>1&&(st=1),lt<0?lt=0:lt>1&&(lt=1),qe<0?qe=0:qe>1&&(qe=1);let At=0,Rt=0,Pt=tt;At=ce.x+_e*Pt,Rt=ce.y+me*Pt;let wt=0,bt=0,nt=st;wt=ce.x+_e*nt,bt=ce.y+me*nt;let Vt=0,sn=0,pn=lt;Vt=de.x+xe*pn,sn=de.y+ge*pn;let Yt=0,Xt=0,Dn=qe;Yt=de.x+xe*Dn,Xt=de.y+ge*Dn;let dn=0,Sn=0;dn=At-de.x,Sn=Rt-de.y;let Zn=dn*dn+Sn*Sn,An=0,yn=0;An=wt-te.x,yn=bt-te.y;let Fn=An*An+yn*yn,mn=0,Vn=0;mn=Vt-ce.x,Vn=sn-ce.y;let cn=mn*mn+Vn*Vn,fn=0,Mn=0;fn=Yt-pe.x,Mn=Xt-pe.y;let Bi=fn*fn+Mn*Mn,ci=0,ni=0,ii=null;Zn<Fn?(ci=At,ni=Rt,ii=de):(ci=wt,ni=bt,ii=te,Zn=Fn);let zs=0,Ps=0,ws=null;if(cn<Bi?(zs=Vt,Ps=sn,ws=ce):(zs=Yt,Ps=Xt,ws=pe,cn=Bi),Zn<cn?(X.x=ci,X.y=ni,H.x=ii.x,H.y=ii.y,K=Math.sqrt(Zn)):(H.x=zs,H.y=Ps,X.x=ws.x,X.y=ws.y,K=Math.sqrt(cn)),K!=0){_.x=H.x-X.x,_.y=H.y-X.y;let _l=1/K;_.x*=_l,_.y*=_l,R&&(_.x=-_.x,_.y=-_.y)}v=K}else{let ce=0,pe=0;ce=se.gp0.x,pe=se.gp0.y;let de=0,te=0;de=se.gp1.x,te=se.gp1.y;let _e=0,me=0;_e=de-ce,me=te-pe;let xe=N.gnormy*ce-N.gnormx*pe,ge=N.gnormy*de-N.gnormx*te,Ie=1/(ge-xe),De=(-N.tp1-xe)*Ie;if(De>s.Config.epsilon){let qe=De;ce+=_e*qe,pe+=me*qe}let tt=(-N.tp0-ge)*Ie;if(tt<-s.Config.epsilon){let qe=tt;de+=_e*qe,te+=me*qe}let st=ce*N.gnormx+pe*N.gnormy-N.gprojection,lt=de*N.gnormx+te*N.gnormy-N.gprojection;if(st<lt){H.x=ce,H.y=pe;let qe=-st;X.x=H.x+N.gnormx*qe,X.y=H.y+N.gnormy*qe,v=st}else{H.x=de,H.y=te;let qe=-lt;X.x=H.x+N.gnormx*qe,X.y=H.y+N.gnormy*qe,v=lt}}}else v=1e100}else v=1e100}}let ee=v+l,G=p*_.x+c*_.y;if(ee<s.Config.distanceThresholdCCD){let R=0,j=0;R=x.x-o.posx,j=x.y-o.posy;let V=G-o.sweep_angvel*(_.y*R-_.x*j);if(V>0&&(e.slipped=!0),V<=0||ee<s.Config.distanceThresholdCCD*.5)break}d=-1;break}if(++b>=40){D>l&&(e.failed=!0);break}}e.toi=d}static distanceBody(e,t,n,l){let s=oe(),i;ie.zpp_pool==null?i=new ie:(i=ie.zpp_pool,ie.zpp_pool=i.next,i.next=null),i.weak=!1;let r;ie.zpp_pool==null?r=new ie:(r=ie.zpp_pool,ie.zpp_pool=r.next,r.next=null),r.weak=!1;let o;ie.zpp_pool==null?o=new ie:(o=ie.zpp_pool,ie.zpp_pool=o.next,o.next=null),o.weak=!1;let a=1e100,p=e.shapes.head;for(;p!=null;){let m=p.elt,z=t.shapes.head;for(;z!=null;){let M=z.elt,y=m,w=M,v=i,P=r,g=a;g==null&&(g=1e100);var c;if(y.type==0&&w.type==0){let E=y.circle,N=w.circle;var u;let k=0,Z=0;k=N.worldCOMx-E.worldCOMx,Z=N.worldCOMy-E.worldCOMy;let C=Math.sqrt(k*k+Z*Z);if(u=C-(E.radius+N.radius),u<g){if(C==0)k=1,Z=0;else{let B=1/C;k*=B,Z*=B}let F=E.radius;v.x=E.worldCOMx+k*F,v.y=E.worldCOMy+Z*F;let O=-N.radius;P.x=N.worldCOMx+k*O,P.y=N.worldCOMy+Z*O,o.x=k,o.y=Z}c=u}else{let E=!1;if(y.type==0&&w.type==1){let N=y;y=w,w=N;let k=v;v=P,P=k,E=!0}if(y.type==1&&w.type==0){let N=y.polygon,k=w.circle,Z=-1e100,C=null,F=N.edges.head;for(;F!=null;){let O=F.elt,B=O.gnormx*k.worldCOMx+O.gnormy*k.worldCOMy-O.gprojection-k.radius;if(B>g){Z=B;break}B>0?B>Z&&(Z=B,C=O):Z<0&&B>Z&&(Z=B,C=O),F=F.next}if(Z<g){let O=C.gp0,B=C.gp1,D=k.worldCOMy*C.gnormx-k.worldCOMx*C.gnormy;if(D<=O.y*C.gnormx-O.x*C.gnormy){let U=0,W=0;U=k.worldCOMx-O.x,W=k.worldCOMy-O.y;let q=Math.sqrt(U*U+W*W);if(Z=q-k.radius,Z<g){if(q==0)U=1,W=0;else{let J=1/q;U*=J,W*=J}let L=0;v.x=O.x+U*L,v.y=O.y+W*L;let A=-k.radius;P.x=k.worldCOMx+U*A,P.y=k.worldCOMy+W*A,o.x=U,o.y=W}}else if(D>=B.y*C.gnormx-B.x*C.gnormy){let U=0,W=0;U=k.worldCOMx-B.x,W=k.worldCOMy-B.y;let q=Math.sqrt(U*U+W*W);if(Z=q-k.radius,Z<g){if(q==0)U=1,W=0;else{let J=1/q;U*=J,W*=J}let L=0;v.x=B.x+U*L,v.y=B.y+W*L;let A=-k.radius;P.x=k.worldCOMx+U*A,P.y=k.worldCOMy+W*A,o.x=U,o.y=W}}else{let U=-k.radius;P.x=k.worldCOMx+C.gnormx*U,P.y=k.worldCOMy+C.gnormy*U;let W=-Z;v.x=P.x+C.gnormx*W,v.y=P.y+C.gnormy*W,o.x=C.gnormx,o.y=C.gnormy}}E&&(o.x=-o.x,o.y=-o.y),c=Z}else{let N=y.polygon,k=w.polygon,Z=-1e100,C=null,F=null,O=0,B=N.edges.head;for(;B!=null;){let D=B.elt,U=1e100,W=k.gverts.next;for(;W!=null;){let q=W,L=D.gnormx*q.x+D.gnormy*q.y;L<U&&(U=L),W=W.next}if(U-=D.gprojection,U>g){Z=U;break}U>0?U>Z&&(Z=U,C=D,O=1):Z<0&&U>Z&&(Z=U,C=D,O=1),B=B.next}if(Z<g){let D=k.edges.head;for(;D!=null;){let U=D.elt,W=1e100,q=N.gverts.next;for(;q!=null;){let L=q,A=U.gnormx*L.x+U.gnormy*L.y;A<W&&(W=A),q=q.next}if(W-=U.gprojection,W>g){Z=W;break}W>0?W>Z&&(Z=W,F=U,O=2):Z<0&&W>Z&&(Z=W,F=U,O=2),D=D.next}if(Z<g){var h,x,f;if(O==1)h=N,x=k,f=C;else{h=k,x=N,f=F;let L=v;v=P,P=L,E=!E}let U=null,W=1e100,q=x.edges.head;for(;q!=null;){let L=q.elt,A=f.gnormx*L.gnormx+f.gnormy*L.gnormy;A<W&&(W=A,U=L),q=q.next}if(E?(o.x=-f.gnormx,o.y=-f.gnormy):(o.x=f.gnormx,o.y=f.gnormy),Z>=0){let L=f.gp0,A=f.gp1,J=U.gp0,$=U.gp1,X=0,H=0,ee=0,G=0;X=A.x-L.x,H=A.y-L.y,ee=$.x-J.x,G=$.y-J.y;let R=1/(X*X+H*H),j=1/(ee*ee+G*G),V=-(X*(L.x-J.x)+H*(L.y-J.y))*R,K=-(X*(L.x-$.x)+H*(L.y-$.y))*R,Q=-(ee*(J.x-L.x)+G*(J.y-L.y))*j,Y=-(ee*(J.x-A.x)+G*(J.y-A.y))*j;V<0?V=0:V>1&&(V=1),K<0?K=0:K>1&&(K=1),Q<0?Q=0:Q>1&&(Q=1),Y<0?Y=0:Y>1&&(Y=1);let ne=0,ae=0,le=V;ne=L.x+X*le,ae=L.y+H*le;let se=0,re=0,he=K;se=L.x+X*he,re=L.y+H*he;let ce=0,pe=0,de=Q;ce=J.x+ee*de,pe=J.y+G*de;let te=0,_e=0,me=Y;te=J.x+ee*me,_e=J.y+G*me;let xe=0,ge=0;xe=ne-J.x,ge=ae-J.y;let Ie=xe*xe+ge*ge,De=0,tt=0;De=se-$.x,tt=re-$.y;let st=De*De+tt*tt,lt=0,qe=0;lt=ce-L.x,qe=pe-L.y;let At=lt*lt+qe*qe,Rt=0,Pt=0;Rt=te-A.x,Pt=_e-A.y;let wt=Rt*Rt+Pt*Pt,bt=0,nt=0,Vt=null;Ie<st?(bt=ne,nt=ae,Vt=J):(bt=se,nt=re,Vt=$,Ie=st);let sn=0,pn=0,Yt=null;if(At<wt?(sn=ce,pn=pe,Yt=L):(sn=te,pn=_e,Yt=A,At=wt),Ie<At?(v.x=bt,v.y=nt,P.x=Vt.x,P.y=Vt.y,Z=Math.sqrt(Ie)):(P.x=sn,P.y=pn,v.x=Yt.x,v.y=Yt.y,Z=Math.sqrt(At)),Z!=0){o.x=P.x-v.x,o.y=P.y-v.y;let Xt=1/Z;o.x*=Xt,o.y*=Xt,E&&(o.x=-o.x,o.y=-o.y)}c=Z}else{let L=0,A=0;L=U.gp0.x,A=U.gp0.y;let J=0,$=0;J=U.gp1.x,$=U.gp1.y;let X=0,H=0;X=J-L,H=$-A;let ee=f.gnormy*L-f.gnormx*A,G=f.gnormy*J-f.gnormx*$,R=1/(G-ee),j=(-f.tp1-ee)*R;if(j>s.Config.epsilon){let Y=j;L+=X*Y,A+=H*Y}let V=(-f.tp0-G)*R;if(V<-s.Config.epsilon){let Y=V;J+=X*Y,$+=H*Y}let K=L*f.gnormx+A*f.gnormy-f.gprojection,Q=J*f.gnormx+$*f.gnormy-f.gprojection;if(K<Q){P.x=L,P.y=A;let Y=-K;v.x=P.x+f.gnormx*Y,v.y=P.y+f.gnormy*Y,c=K}else{P.x=J,P.y=$;let Y=-Q;v.x=P.x+f.gnormx*Y,v.y=P.y+f.gnormy*Y,c=Q}}}else c=g}else c=g}}c<a&&(a=c,n.x=i.x,n.y=i.y,l.x=r.x,l.y=r.y),z=z.next}p=p.next}let _=i;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=ie.zpp_pool,ie.zpp_pool=_;let d=r;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=ie.zpp_pool,ie.zpp_pool=d;let b=o;return b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b._isimmutable=null,b._validate=null,b._invalidate=null,b.next=ie.zpp_pool,ie.zpp_pool=b,a}static distance(e,t,n,l,s,i){let r=oe();if(i==null&&(i=1e100),e.type==0&&t.type==0){let o=e.circle,a=t.circle,p,c=0,u=0;c=a.worldCOMx-o.worldCOMx,u=a.worldCOMy-o.worldCOMy;let h=Math.sqrt(c*c+u*u);if(p=h-(o.radius+a.radius),p<i){if(h==0)c=1,u=0;else{let _=1/h;c*=_,u*=_}let x=o.radius;n.x=o.worldCOMx+c*x,n.y=o.worldCOMy+u*x;let f=-a.radius;l.x=a.worldCOMx+c*f,l.y=a.worldCOMy+u*f,s.x=c,s.y=u}return p}else{let o=!1;if(e.type==0&&t.type==1){let a=e;e=t,t=a;let p=n;n=l,l=p,o=!0}if(e.type==1&&t.type==0){let a=e.polygon,p=t.circle,c=-1e100,u=null,h=a.edges.head;for(;h!=null;){let x=h.elt,f=x.gnormx*p.worldCOMx+x.gnormy*p.worldCOMy-x.gprojection-p.radius;if(f>i){c=f;break}f>0?f>c&&(c=f,u=x):c<0&&f>c&&(c=f,u=x),h=h.next}if(c<i){let x=u.gp0,f=u.gp1,_=p.worldCOMy*u.gnormx-p.worldCOMx*u.gnormy;if(_<=x.y*u.gnormx-x.x*u.gnormy){let d=0,b=0;d=p.worldCOMx-x.x,b=p.worldCOMy-x.y;let m=Math.sqrt(d*d+b*b);if(c=m-p.radius,c<i){if(m==0)d=1,b=0;else{let y=1/m;d*=y,b*=y}let z=0;n.x=x.x+d*z,n.y=x.y+b*z;let M=-p.radius;l.x=p.worldCOMx+d*M,l.y=p.worldCOMy+b*M,s.x=d,s.y=b}}else if(_>=f.y*u.gnormx-f.x*u.gnormy){let d=0,b=0;d=p.worldCOMx-f.x,b=p.worldCOMy-f.y;let m=Math.sqrt(d*d+b*b);if(c=m-p.radius,c<i){if(m==0)d=1,b=0;else{let y=1/m;d*=y,b*=y}let z=0;n.x=f.x+d*z,n.y=f.y+b*z;let M=-p.radius;l.x=p.worldCOMx+d*M,l.y=p.worldCOMy+b*M,s.x=d,s.y=b}}else{let d=-p.radius;l.x=p.worldCOMx+u.gnormx*d,l.y=p.worldCOMy+u.gnormy*d;let b=-c;n.x=l.x+u.gnormx*b,n.y=l.y+u.gnormy*b,s.x=u.gnormx,s.y=u.gnormy}}return o&&(s.x=-s.x,s.y=-s.y),c}else{let a=e.polygon,p=t.polygon,c=-1e100,u=null,h=null,x=0,f=a.edges.head;for(;f!=null;){let _=f.elt,d=1e100,b=p.gverts.next;for(;b!=null;){let m=b,z=_.gnormx*m.x+_.gnormy*m.y;z<d&&(d=z),b=b.next}if(d-=_.gprojection,d>i){c=d;break}d>0?d>c&&(c=d,u=_,x=1):c<0&&d>c&&(c=d,u=_,x=1),f=f.next}if(c<i){let _=p.edges.head;for(;_!=null;){let d=_.elt,b=1e100,m=a.gverts.next;for(;m!=null;){let z=m,M=d.gnormx*z.x+d.gnormy*z.y;M<b&&(b=M),m=m.next}if(b-=d.gprojection,b>i){c=b;break}b>0?b>c&&(c=b,h=d,x=2):c<0&&b>c&&(c=b,h=d,x=2),_=_.next}if(c<i){let d,b,m;if(x==1)d=a,b=p,m=u;else{d=p,b=a,m=h;let w=n;n=l,l=w,o=!o}let z=null,M=1e100,y=b.edges.head;for(;y!=null;){let w=y.elt,v=m.gnormx*w.gnormx+m.gnormy*w.gnormy;v<M&&(M=v,z=w),y=y.next}if(o?(s.x=-m.gnormx,s.y=-m.gnormy):(s.x=m.gnormx,s.y=m.gnormy),c>=0){let w=m.gp0,v=m.gp1,P=z.gp0,g=z.gp1,E=0,N=0,k=0,Z=0;E=v.x-w.x,N=v.y-w.y,k=g.x-P.x,Z=g.y-P.y;let C=1/(E*E+N*N),F=1/(k*k+Z*Z),O=-(E*(w.x-P.x)+N*(w.y-P.y))*C,B=-(E*(w.x-g.x)+N*(w.y-g.y))*C,D=-(k*(P.x-w.x)+Z*(P.y-w.y))*F,U=-(k*(P.x-v.x)+Z*(P.y-v.y))*F;O<0?O=0:O>1&&(O=1),B<0?B=0:B>1&&(B=1),D<0?D=0:D>1&&(D=1),U<0?U=0:U>1&&(U=1);let W=0,q=0,L=O;W=w.x+E*L,q=w.y+N*L;let A=0,J=0,$=B;A=w.x+E*$,J=w.y+N*$;let X=0,H=0,ee=D;X=P.x+k*ee,H=P.y+Z*ee;let G=0,R=0,j=U;G=P.x+k*j,R=P.y+Z*j;let V=0,K=0;V=W-P.x,K=q-P.y;let Q=V*V+K*K,Y=0,ne=0;Y=A-g.x,ne=J-g.y;let ae=Y*Y+ne*ne,le=0,se=0;le=X-w.x,se=H-w.y;let re=le*le+se*se,he=0,ce=0;he=G-v.x,ce=R-v.y;let pe=he*he+ce*ce,de=0,te=0,_e=null;Q<ae?(de=W,te=q,_e=P):(de=A,te=J,_e=g,Q=ae);let me=0,xe=0,ge=null;if(re<pe?(me=X,xe=H,ge=w):(me=G,xe=R,ge=v,re=pe),Q<re?(n.x=de,n.y=te,l.x=_e.x,l.y=_e.y,c=Math.sqrt(Q)):(l.x=me,l.y=xe,n.x=ge.x,n.y=ge.y,c=Math.sqrt(re)),c!=0){s.x=l.x-n.x,s.y=l.y-n.y;let Ie=1/c;s.x*=Ie,s.y*=Ie,o&&(s.x=-s.x,s.y=-s.y)}return c}else{let w=0,v=0;w=z.gp0.x,v=z.gp0.y;let P=0,g=0;P=z.gp1.x,g=z.gp1.y;let E=0,N=0;E=P-w,N=g-v;let k=m.gnormy*w-m.gnormx*v,Z=m.gnormy*P-m.gnormx*g,C=1/(Z-k),F=(-m.tp1-k)*C;if(F>r.Config.epsilon){let U=F;w+=E*U,v+=N*U}let O=(-m.tp0-Z)*C;if(O<-r.Config.epsilon){let U=O;P+=E*U,g+=N*U}let B=w*m.gnormx+v*m.gnormy-m.gprojection,D=P*m.gnormx+g*m.gnormy-m.gprojection;if(B<D){l.x=w,l.y=v;let U=-B;return n.x=l.x+m.gnormx*U,n.y=l.y+m.gnormy*U,B}else{l.x=P,l.y=g;let U=-D;return n.x=l.x+m.gnormx*U,n.y=l.y+m.gnormy*U,D}}}else return i}else return i}}}};un.__name__=["zpp_nape","geom","ZPP_SweepDistance"];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 l=n.x-t.x,s=n.y-t.y,i=t.x-e.x;return(t.y-e.y)*l-i*s}static delaunay(e,t,n,l){let s=n.x-t.x,i=n.y-t.y,r=t.x-e.x,o=t.y-e.y,a,p,c;return o*s-r*i>=0?c=!0:(s=l.x-n.x,i=l.y-n.y,r=n.x-t.x,o=n.y-t.y,c=o*s-r*i>=0),c?p=!0:(s=e.x-l.x,i=e.y-l.y,r=l.x-n.x,o=l.y-n.y,p=o*s-r*i>=0),p?a=!0:(s=t.x-e.x,i=t.y-e.y,r=e.x-l.x,o=e.y-l.y,a=o*s-r*i>=0),a?!0:t.x*(n.y*l.mag-n.mag*l.y)-n.x*(t.y*l.mag-t.mag*l.y)+l.x*(t.y*n.mag-t.mag*n.y)-(e.x*(n.y*l.mag-n.mag*l.y)-n.x*(e.y*l.mag-e.mag*l.y)+l.x*(e.y*n.mag-e.mag*n.y))+(e.x*(t.y*l.mag-t.mag*l.y)-t.x*(e.y*l.mag-e.mag*l.y)+l.x*(e.y*t.mag-e.mag*t.y))-(e.x*(t.y*n.mag-t.mag*n.y)-t.x*(e.y*n.mag-e.mag*n.y)+n.x*(e.y*t.mag-e.mag*t.y))>0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let 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&&(ml.zpp_pool==null?Re.edgeSet=new ml:(Re.edgeSet=ml.zpp_pool,ml.zpp_pool=Re.edgeSet.next,Re.edgeSet.next=null),Re.edgeSet.lt=$t.edge_lt,Re.edgeSet.swapped=$t.edge_swap);let l;$t.zpp_pool==null?l=new $t:(l=$t.zpp_pool,$t.zpp_pool=l.next,l.next=null);let s=e.vertices,i=e.vertices;if(s!=null){let o=s;for(;;){let a=o,p=a.next;a.diagonals.reverse();let c=a.diagonals.head;for(;c!=null;){let u=c.elt;if(u.id<a.id){p=u,c=c.next;continue}let h=c.next==null?a.prev:c.next.elt;if(!Re.delaunay(a,p,u,h)){let x;$t.zpp_pool==null?x=new $t:(x=$t.zpp_pool,$t.zpp_pool=x.next,x.next=null),x.a=a,x.b=u,a.id<u.id?(x.id=a.id,x.di=u.id):(x.id=u.id,x.di=a.id);let f=x;l.add(f),f.node=Re.edgeSet.insert(f)}p=u,c=c.next}if(o=o.next,o==i)break}}for(;l.next!=null;){let o=l.pop_unsafe(),a=o.a,p=o.b,c=a.next,u=null,h=a.diagonals.head;for(;h!=null;){let f=h.elt;if(f==p){h=h.next,u=h==null?a.prev:h.elt;break}c=f,h=h.next}if(a.diagonals.remove(p),p.diagonals.remove(a),p==c.next)c.diagonals.add(u);else{let f=c.diagonals.head;for(;f!=null;){if(f.elt==p){c.diagonals.insert(f,u);break}f=f.next}}if(a==u.next)u.diagonals.add(c);else{let f=u.diagonals.head;for(;f!=null;){if(f.elt==a){u.diagonals.insert(f,c);break}f=f.next}}Re.edgeSet.remove_node(o.node);let x=o;x.a=x.b=null,x.node=null,x.next=$t.zpp_pool,$t.zpp_pool=x}let r=l;r.a=r.b=null,r.node=null,r.next=$t.zpp_pool,$t.zpp_pool=r}static triangulate(e){let t=e.vertices,n=e.vertices,l=e.vertices.next,s=e.vertices;if(l!=null){let a=l;for(;;){let p=a;if((p.y<t.y||p.y==t.y&&p.x<t.x)&&(t=p),(n.y<p.y||n.y==p.y&&n.x<p.x)&&(n=p),a=a.next,a==s)break}}Re.queue==null&&(Re.queue=new $i);let i=n.prev,r=n.next;for(Re.queue.add(n);i!=t||r!=t;)i==t||r!=t&&(i.y<r.y||i.y==r.y&&i.x<r.x)?(Re.queue.add(r),r.rightchain=!1,r=r.next):(Re.queue.add(i),i.rightchain=!0,i=i.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,u=a.x-p.x,h=a.y-p.y,x=p.x-c.x,_=(p.y-c.y)*u-x*h;if(a.rightchain&&_>=0||!a.rightchain&&_<=0)break;e.add_diagonal(c,a),p=c,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.__name__=["zpp_nape","geom","ZPP_Triangular"],Re.queue=null,Re.stack=null,Re.edgeSet=null;var qi=Re;var Rs=class Rs{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&&Rs._wrapFn&&(this.outer=Rs._wrapFn(this)),this.outer}};Rs.__name__=["zpp_nape","geom","ZPP_Vec3"],Rs._zpp=null,Rs._wrapFn=null;var Wi=Rs;var gr=class{static vec_dsq(e,t,n,l){let s=e-n,i=t-l;return s*s+i*i}static vec_distance(e,t,n,l){let s=e-n,i=t-l;return Math.sqrt(s*s+i*i)}};gr.__name__=["zpp_nape","geom","ZPP_VecMath"];var On=class On{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;On.initFields(this)}static initFields(e){let t=On._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=In.Interactor(),e.cbsets=new t.util.ZNPList_ZPP_CallbackSet,e.cbTypes=new t.util.ZNPList_ZPP_CbType}static get(e,t){let n=e.id<t.id?e.id:t.id,l=e.id<t.id?t.id:e.id,s=e.cbsets.length<t.cbsets.length?e.cbsets:t.cbsets,i=null,r=s.head;for(;r!=null;){let o=r.elt;if(o.id==n&&o.di==l){i=o;break}r=r.next}return i}static int_callback(e,t,n){let l=e.int1,s=e.int2,i,r=t.options1,o=l.cbTypes;if(r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.excludes)){let a=t.options2,p=s.cbTypes;i=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else i=!1;i?(n.int1=l,n.int2=s):(n.int1=s,n.int2=l)}isShape(){return this.ishape!=null}isBody(){return this.ibody!=null}isCompound(){return this.icompound!=null}__iaddedToSpace(){this.group!=null&&this.group.interactors.add(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.add(this),e=e.next;this.alloc_cbSet()}__iremovedFromSpace(){this.group!=null&&this.group.interactors.remove(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.remove(this),e=e.next;this.dealloc_cbSet()}wake(){if(this.ishape!=null){let e=this.ishape.body;e!=null&&e.space!=null&&e.space.non_inlined_wake(e)}else this.ibody!=null?this.ibody.space!=null&&this.ibody.space.non_inlined_wake(this.ibody):this.icompound.space!=null&&this.icompound.space.wakeCompound(this.icompound)}_getSpace(){return this.ishape!=null?this.ishape.body==null?null:this.ishape.body.space:this.ibody!=null?this.ibody.space:this.icompound.space}getSpace(){return this._getSpace()}setupcbTypes(){let e=On._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=On._zpp;if(!this.cbTypes.has(e)){let n=this._getSpace();n!=null&&(this.dealloc_cbSet(),e.interactors.add(this));let l=null,s=this.cbTypes.head;for(;s!=null;){let a=s.elt;if(e.id<a.id)break;l=s,s=s.next}let i=this.cbTypes,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;l==null?(o.next=i.head,i.head=o):(o.next=l.next,l.next=o),i.pushmod=i.modified=!0,i.length++,n!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){let e=this._getSpace();(this.cbSet=e.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.interactors.add(this),this.cbSet.validate(),e.freshInteractorType(this))}dealloc_cbSet(){let e=this._getSpace();if(this.cbSet!=null){if(this.cbSet.interactors.remove(this),e.nullInteractorType(this),--this.cbSet.count==0){e.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=!0,t.bodylisteners.clear(),t.zip_bodylisteners=!0,t.conlisteners.clear(),t.zip_conlisteners=!0;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=St.zpp_pool,St.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=On._nape;e.zpp_inner_i.group=this.group;let n=this.outer_i;n.zpp_inner_i.wrap_cbTypes==null&&n.zpp_inner_i.setupcbTypes();let l=n.zpp_inner_i.wrap_cbTypes;l.zpp_inner.valmod();let s=t.callbacks.CbTypeIterator.get(l);for(;;){s.zpp_inner.zpp_inner.valmod();let i=s.zpp_inner;i.zpp_inner.valmod(),i.zpp_inner.zip_length&&(i.zpp_inner.zip_length=!1,i.zpp_inner.user_length=i.zpp_inner.inner.length);let r=i.zpp_inner.user_length;s.zpp_critical=!0;let o;if(s.zpp_i<r?o=!0:(s.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=s,s.zpp_inner=null,o=!1),!o)break;s.zpp_critical=!1;let a=s.zpp_inner.at(s.zpp_i++);e.zpp_inner_i.wrap_cbTypes==null&&e.zpp_inner_i.setupcbTypes();let p=e.zpp_inner_i.wrap_cbTypes;p.zpp_inner.reverse_flag?p.push(a):p.unshift(a)}this.userData!=null&&(e.zpp_inner_i.userData=Object.assign({},this.userData))}static _init(e,t){On._initialized||(On._initialized=!0,On._zpp=e,On._nape=t)}};On.__name__=["zpp_nape","phys","ZPP_Interactor"],On._nape=null,On._zpp=null,On._initialized=!1;var Ut=On;var Be=class Be{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.world=!1;this.type=0;this.compound=null;this.shapes=null;this.wrap_shapes=null;this.space=null;this.arbiters=null;this.wrap_arbiters=null;this.constraints=null;this.wrap_constraints=null;this.component=null;this.graph_depth=0;this.sweepTime=0;this.sweep_angvel=0;this.sweepFrozen=!1;this.sweepRadius=0;this.bullet=!1;this.bulletEnabled=!1;this.disableCCD=!1;this.pre_posx=0;this.pre_posy=0;this.posx=0;this.posy=0;this.wrap_pos=null;this.velx=0;this.vely=0;this.wrap_vel=null;this.forcex=0;this.forcey=0;this.wrap_force=null;this.kinvelx=0;this.kinvely=0;this.wrap_kinvel=null;this.svelx=0;this.svely=0;this.wrap_svel=null;this.wrapcvel=null;this.angvel=0;this.torque=0;this.kinangvel=0;this.pre_rot=0;this.rot=0;this.axisx=0;this.axisy=0;this.zip_axis=!1;this.kinematicDelaySleep=!1;this.mass=0;this.zip_mass=!1;this.massMode=0;this.imass=0;this.smass=0;this.cmass=0;this.nomove=!1;this.gravMass=0;this.zip_gravMass=!1;this.gravMassMode=0;this.gravMassScale=0;this.zip_gravMassScale=!1;this.inertiaMode=0;this.inertia=0;this.zip_inertia=!1;this.cinertia=0;this.iinertia=0;this.sinertia=0;this.norotate=!1;this.aabb=null;this.zip_aabb=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;let e=Be._zpp;Ut.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=Be._nape,t=Be._zpp;t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new e.phys.BodyType,t.util.ZPP_Flags.internal=!1);let n=new e.phys.Body(t.util.ZPP_Flags.BodyType_STATIC),l=n.zpp_inner;return l.world=!0,l.wrap_shapes.zpp_inner.immutable=!0,l.smass=l.imass=l.cmass=l.mass=l.gravMass=0,l.sinertia=l.iinertia=l.cinertia=l.inertia=0,l.cbTypes.clear(),n}isStatic(){return this.type===1}isDynamic(){return this.type===2}isKinematic(){return this.type===3}invalidate_type(){this.invalidate_mass(),this.invalidate_inertia()}invalidate_shapes(){this.zip_aabb=!0,this.zip_localCOM=!0,this.zip_worldCOM=!0,this.invalidate_mass(),this.invalidate_inertia()}init_bodysetlist(){if(Be.bodyset==null){let e=Be._zpp;Be.bodyset=new e.util.ZPP_Set_ZPP_Body,Be.bodyset.lt=Be.bodysetlt,Be.bodystack=new e.util.ZNPList_ZPP_Body}}connectedBodies_cont(e){Be.bodyset.try_insert_bool(e.zpp_inner)&&(Be.bodystack.add(e.zpp_inner),e.zpp_inner.graph_depth=Be.cur_graph_depth+1)}connectedBodies(e,t){let n=Be._nape;Be.bodyset==null&&this.init_bodysetlist();let l=t??new n.phys.BodyList;for(Be.bodystack.add(this),Be.bodyset.insert(this),this.graph_depth=0;Be.bodystack.head!=null;){let i=Be.bodystack.pop_unsafe();if(i.graph_depth===e)continue;Be.cur_graph_depth=i.graph_depth;let r=i.constraints.head;for(;r!=null;)r.elt.outer.visitBodies(this.connectedBodies_cont.bind(this)),r=r.next}let s=Be.bodyset;if(s.parent!=null){let i=s.parent;for(;i!=null;)if(i.prev!=null)i=i.prev;else if(i.next!=null)i=i.next;else{let r=i.data;if(r!==this){let p=r.outer;l.zpp_inner.reverse_flag?l.push(p):l.unshift(p)}let o=i.parent;o!=null&&(i===o.prev?o.prev=null:o.next=null,i.parent=null);let a=i;a.data=null,a.lt=null,a.next=Be._zpp.util.ZPP_Set_ZPP_Body.zpp_pool,Be._zpp.util.ZPP_Set_ZPP_Body.zpp_pool=a,i=o}s.parent=null}return l}interactingBodies(e,t){let n=Be._nape,l=Be._zpp;Be.bodyset==null&&this.init_bodysetlist();let s=t??new n.phys.BodyList,i=this.arbiters.head;for(;i!=null;){let o=i.elt;if(!o.sleeping&&(e===4||o.type===e)){let a=o.b1===this?o.b2:o.b1;if(Be.bodyset.try_insert_bool(a)){let p=a.outer;s.zpp_inner.reverse_flag?s.push(p):s.unshift(p)}}i=i.next}let r=Be.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=l.util.ZPP_Set_ZPP_Body.zpp_pool,l.util.ZPP_Set_ZPP_Body.zpp_pool=p,o=a}r.parent=null}return s}atRest(e){let t=Be._nape;if(this.type!==2)return this.component.sleeping;let n=t.Config.linearSleepThreshold*t.Config.linearSleepThreshold,l;if(this.velx*this.velx+this.vely*this.vely>n)l=!1;else{let s=this.posx-this.pre_posx,i=this.posy-this.pre_posy;if(s*s+i*i>.25*n*e*e)l=!1;else{let 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)l=!1;else{let c=this.rot-this.pre_rot;l=!(c*c*a>p*e*e)}}}return l||(this.component.waket=this.space.stamp),this.component.waket+t.Config.sleepDelay<this.space.stamp}refreshArbiters(){let e=this.arbiters.head;for(;e!=null;){let t=e.elt;t.invalidated=!0,e=e.next}}sweepIntegrate(e){let t=e-this.sweepTime;if(t!==0&&(this.sweepTime=e,this.posx+=this.velx*t,this.posy+=this.vely*t,this.angvel!==0)){let n=this.sweep_angvel*t;if(this.rot+=n,n*n>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let l=n*n,s=1-.5*l,i=1-l*l/8,r=(s*this.axisx+n*this.axisy)*i;this.axisy=(s*this.axisy-n*this.axisx)*i,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,l=t.gverts.next;for(;l!=null;){let p=l,c=n;n=n.next,p.x=this.posx+(this.axisy*c.x-this.axisx*c.y),p.y=this.posy+(c.x*this.axisx+c.y*this.axisy),l=l.next}let s=t.edges.head,i=t.gverts.next,r=i;for(i=i.next;i!=null;){let p=i,c=s.elt;s=s.next,c.gnormx=this.axisy*c.lnormx-this.axisx*c.lnormy,c.gnormy=c.lnormx*this.axisx+c.lnormy*this.axisy,c.gprojection=this.posx*c.gnormx+this.posy*c.gnormy+c.lprojection,c.tp0=r.y*c.gnormx-r.x*c.gnormy,c.tp1=p.y*c.gnormx-p.x*c.gnormy,r=p,i=i.next}let o=t.gverts.next,a=s.elt;a.gnormx=this.axisy*a.lnormx-this.axisx*a.lnormy,a.gnormy=a.lnormx*this.axisx+a.lnormy*this.axisy,a.gprojection=this.posx*a.gnormx+this.posy*a.gnormy+a.lprojection,a.tp0=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,l){let s=Be._nape;if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let 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 r;ie.zpp_pool==null?r=new ie:(r=ie.zpp_pool,ie.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=e,r.y=t,i.zpp_inner=r,i.zpp_inner.outer=i}else{if(i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=i.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;i.zpp_inner._validate!=null&&i.zpp_inner._validate(),i.zpp_inner.x===e?(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),o=i.zpp_inner.y===t):o=!1,o||(i.zpp_inner.x=e,i.zpp_inner.y=t,i.zpp_inner._invalidate!=null&&i.zpp_inner._invalidate(i.zpp_inner))}return i.zpp_inner.weak=!1,i}setupPosition(){this.wrap_pos=this._setupVec2Wrapper(this.posx,this.posy,null,null),this.wrap_pos.zpp_inner._inuse=!0,this.world?this.wrap_pos.zpp_inner._immutable=!0:(this.wrap_pos.zpp_inner._invalidate=this.pos_invalidate.bind(this),this.wrap_pos.zpp_inner._validate=this.pos_validate.bind(this))}setupVelocity(){this.wrap_vel=this._setupVec2Wrapper(this.velx,this.vely,null,null),this.wrap_vel.zpp_inner._inuse=!0,this.world?this.wrap_vel.zpp_inner._immutable=!0:(this.wrap_vel.zpp_inner._invalidate=this.vel_invalidate.bind(this),this.wrap_vel.zpp_inner._validate=this.vel_validate.bind(this))}setupkinvel(){this.wrap_kinvel=this._setupVec2Wrapper(this.kinvelx,this.kinvely,null,null),this.wrap_kinvel.zpp_inner._inuse=!0,this.world?this.wrap_kinvel.zpp_inner._immutable=!0:(this.wrap_kinvel.zpp_inner._invalidate=this.kinvel_invalidate.bind(this),this.wrap_kinvel.zpp_inner._validate=this.kinvel_validate.bind(this))}setupsvel(){this.wrap_svel=this._setupVec2Wrapper(this.svelx,this.svely,null,null),this.wrap_svel.zpp_inner._inuse=!0,this.world?this.wrap_svel.zpp_inner._immutable=!0:(this.wrap_svel.zpp_inner._invalidate=this.svel_invalidate.bind(this),this.wrap_svel.zpp_inner._validate=this.svel_validate.bind(this))}setupForce(){this.wrap_force=this._setupVec2Wrapper(this.forcex,this.forcey,null,null),this.wrap_force.zpp_inner._inuse=!0,this.world?this.wrap_force.zpp_inner._immutable=!0:(this.wrap_force.zpp_inner._invalidate=this.force_invalidate.bind(this),this.wrap_force.zpp_inner._validate=this.force_validate.bind(this))}cvel_validate(){this.wrapcvel.zpp_inner.x=this.velx+this.kinvelx,this.wrapcvel.zpp_inner.y=this.vely+this.kinvely}setup_cvel(){this.wrapcvel=this._setupVec2Wrapper(this.velx+this.kinvelx,this.vely+this.kinvely,null,null),this.wrapcvel.zpp_inner._inuse=!0,this.wrapcvel.zpp_inner._immutable=!0,this.wrapcvel.zpp_inner._validate=this.cvel_validate.bind(this)}invalidate_rot(){this.zip_axis=!0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}validate_axis(){this.zip_axis&&(this.zip_axis=!1,this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}quick_validate_axis(){this.zip_axis&&(this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}delta_rot(e){if(e*e>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let t=e*e,n=1-.5*t,l=1-t*t/8,s=(n*this.axisx+e*this.axisy)*l;this.axisy=(n*this.axisy-e*this.axisx)*l,this.axisx=s}this.zip_axis=!1}invalidate_mass(){this.zip_mass=!0,this.invalidate_gravMass()}validate_mass(){if(this.zip_mass||this.massMode===0&&!1){if(this.zip_mass=!1,this.massMode===0){this.cmass=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cmass+=n.area*n.material.density,t=t.next}}this.type===2&&!this.nomove?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0)}}invalidate_gravMass(){this.gravMassMode!==1&&(this.zip_gravMass=!0),this.gravMassMode!==2&&(this.zip_gravMassScale=!0),this.wake()}validate_gravMass(){this.zip_gravMass&&(this.zip_gravMass=!1,this.validate_mass(),this.gravMassMode===0?(this.validate_mass(),this.gravMass=this.cmass):this.gravMassMode===2&&(this.validate_mass(),this.gravMass=this.cmass*this.gravMassScale))}invalidate_gravMassScale(){this.gravMassMode!==2?this.zip_gravMassScale=!0:this.invalidate_gravMass()}validate_gravMassScale(){this.zip_gravMassScale&&(this.zip_gravMassScale=!1,this.gravMassMode===0?this.gravMassScale=1:this.gravMassMode===1&&(this.validate_mass(),this.gravMassScale=this.gravMass/this.cmass))}invalidate_inertia(){this.zip_inertia=!0,this.wake()}validate_inertia(){if(this.zip_inertia||this.inertiaMode===0&&!1){if(this.zip_inertia=!1,this.inertiaMode===0){this.cinertia=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cinertia+=n.inertia*n.area*n.material.density,t=t.next}}this.type===2&&!this.norotate?(this.inertia=this.cinertia,this.sinertia=this.iinertia=1/this.inertia):(this.inertia=1/0,this.sinertia=this.iinertia=0)}}invalidate_wake(){this.wake()}invalidate_aabb(){this.zip_aabb=!0}validate_aabb(){if(this.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(this.zip_aabb){this.zip_aabb=!1,this.aabb.minx=1/0,this.aabb.miny=1/0,this.aabb.maxx=-1/0,this.aabb.maxy=-1/0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.zip_aabb&&t.body!=null&&(t.zip_aabb=!1,t.type===0?this._validateCircleAABB(t.circle):this._validatePolygonAABB(t.polygon)),t.aabb.minx<this.aabb.minx&&(this.aabb.minx=t.aabb.minx),t.aabb.maxx>this.aabb.maxx&&(this.aabb.maxx=t.aabb.maxx),t.aabb.miny<this.aabb.miny&&(this.aabb.miny=t.aabb.miny),t.aabb.maxy>this.aabb.maxy&&(this.aabb.maxy=t.aabb.maxy),e=e.next}}}_validateCircleAABB(e){e.zip_worldCOM&&e.body!=null&&(e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type===1&&this._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)),this.validate_axis(),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy));let t=e.radius;e.aabb.minx=e.worldCOMx-t,e.aabb.miny=e.worldCOMy-t,e.aabb.maxx=e.worldCOMx+t,e.aabb.maxy=e.worldCOMy+t}_validatePolygonAABB(e){if(e.zip_gverts&&e.body!=null){e.zip_gverts=!1,e.validate_lverts(),this.validate_axis();let l=e.lverts.next,s=e.gverts.next;for(;s!=null;){let i=s,r=l;l=l.next,i.x=e.body.posx+(e.body.axisy*r.x-e.body.axisx*r.y),i.y=e.body.posy+(r.x*e.body.axisx+r.y*e.body.axisy),s=s.next}}if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let t=e.gverts.next;e.aabb.minx=t.x,e.aabb.miny=t.y,e.aabb.maxx=t.x,e.aabb.maxy=t.y;let n=e.gverts.next.next;for(;n!=null;){let l=n;l.x<e.aabb.minx&&(e.aabb.minx=l.x),l.x>e.aabb.maxx&&(e.aabb.maxx=l.x),l.y<e.aabb.miny&&(e.aabb.miny=l.y),l.y>e.aabb.maxy&&(e.aabb.maxy=l.y),n=n.next}}aabb_validate(){if(this.shapes.head==null)throw new Error("Error: bounds only makes sense when Body has shapes");this.validate_aabb()}invalidate_localCOM(){this.zip_localCOM=!0,this.zip_worldCOM=!0}invalidate_worldCOM(){this.zip_worldCOM=!0}_computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y,e.localCOMx+=e.lverts.next.next.x,e.localCOMy+=e.lverts.next.next.y,e.localCOMx*=.5,e.localCOMy*=.5;else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,l=n;n=n.next;let s=n;for(n=n.next;n!=null;){let p=n;t+=s.x*(p.y-l.y);let c=p.y*s.x-p.x*s.y;e.localCOMx+=(s.x+p.x)*c,e.localCOMy+=(s.y+p.y)*c,l=s,s=p,n=n.next}n=e.lverts.next;let i=n;t+=s.x*(i.y-l.y);let r=i.y*s.x-i.x*s.y;e.localCOMx+=(s.x+i.x)*r,e.localCOMy+=(s.y+i.y)*r,l=s,s=i,n=n.next;let o=n;t+=s.x*(o.y-l.y);let a=o.y*s.x-o.x*s.y;e.localCOMx+=(s.x+o.x)*a,e.localCOMy+=(s.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,l=this.shapes.head;for(;l!=null;){let s=l.elt;s.zip_localCOM&&(s.zip_localCOM=!1,s.type===1&&this._computePolygonLocalCOM(s.polygon),s.wrap_localCOM!=null&&(s.wrap_localCOM.zpp_inner.x=s.localCOMx,s.wrap_localCOM.zpp_inner.y=s.localCOMy)),s.validate_area_inertia();let i=s.area*s.material.density;e+=s.localCOMx*i,t+=s.localCOMy*i,n+=s.area*s.material.density,l=l.next}if(n!==0){let s=1/n;this.localCOMx=e*s,this.localCOMy=t*s}this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy),this.zip_mass&&this.massMode===0&&(this.zip_mass=!1,this.cmass=n,this.type===2?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0))}}validate_worldCOM(){this.zip_worldCOM&&(this.zip_worldCOM=!1,this.validate_localCOM(),this.validate_axis(),this.worldCOMx=this.posx+(this.axisy*this.localCOMx-this.axisx*this.localCOMy),this.worldCOMy=this.posy+(this.localCOMx*this.axisx+this.localCOMy*this.axisy)),this.wrap_worldCOM!=null&&(this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy)}getlocalCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its localCOM");this.validate_localCOM()}getworldCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its worldCOM");this.validate_worldCOM()}__immutable_midstep(){if(this.world)throw new Error("Error: Space::world is immutable")}clear(){if(this.space!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a Space!");if(this.constraints.head!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a constraint!");for(;this.shapes.head!=null;){let t=this.shapes.pop_unsafe();t.removedFromBody(),t.body=null}this.invalidate_shapes(),this.pre_posx=0,this.pre_posy=0,this.posx=0,this.posy=0,this.velx=0,this.vely=0,this.forcex=0,this.forcey=0,this.kinvelx=0,this.kinvely=0,this.svelx=0,this.svely=0,this.angvel=this.torque=this.kinangvel=this.pre_rot=this.rot=0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}for(this.zip_worldCOM=!0,this.zip_axis=!0,e=this.shapes.head;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0,this.axisx=0,this.axisy=1,this.zip_axis=!1,this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.norotate=!1,this.nomove=!1}shapes_adder(e){if(e.zpp_inner.body!==this){if(e.zpp_inner.body!=null&&e.zpp_inner.body.wrap_shapes.remove(e),e.zpp_inner.body=this,e.zpp_inner.addedToBody(),this.space!=null){let t=this.space,n=e.zpp_inner,l=n.body;l.world||(l.component.waket=t.stamp+(t.midstep?0:1),l.type===3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&t.really_wake(l,!1)),t.bphase.insert(n),n.addedToSpace()}return e.zpp_inner.type===1&&(e.zpp_inner.polygon.invalidate_gaxi(),e.zpp_inner.polygon.invalidate_gverts()),!0}else return!1}shapes_subber(e){this.space!=null&&this.space.removed_shape(e.zpp_inner),e.zpp_inner.body=null,e.zpp_inner.removedFromBody()}shapes_invalidate(e){this.invalidate_shapes()}shapes_modifiable(){if(this.immutable_midstep("Body::shapes"),this.type===1&&this.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}addedToSpace(){let e=Be._zpp,t;e.space.ZPP_Component.zpp_pool==null?t=new e.space.ZPP_Component:(t=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t.next,t.next=null),t.isBody=!0,t.body=this,this.component=t,this.__iaddedToSpace()}removedFromSpace(){let e=Be._zpp;for(;this.arbiters.head!=null;){let n=this.arbiters.pop_unsafe(),l=this.space;n.cleared=!0,n.b2===this&&this._removeArbiterFromList(n.b1.arbiters,n,e),n.b1===this&&this._removeArbiterFromList(n.b2.arbiters,n,e),n.pair!=null&&(n.pair.arb=null,n.pair=null),n.active=!1,l.f_arbiters.modified=!0}let t=this.component;t.body=null,t.constraint=null,t.next=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t,this.component=null,this.__iremovedFromSpace()}_removeArbiterFromList(e,t,n){let l=null,s=e.head;for(;s!=null;){if(s.elt===t){let i;l==null?(i=e.head,e.head=i.next,e.head==null&&(e.pushmod=!0)):(i=l.next,l.next=i.next,i.next==null&&(e.pushmod=!0));let r=i;r.elt=null,r.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=r,e.modified=!0,e.length--,e.pushmod=!0;break}l=s,s=s.next}}copy(){let e=Be._nape,t=new e.phys.Body().zpp_inner;t.type=this.type,t.bulletEnabled=this.bulletEnabled,t.disableCCD=this.disableCCD;let n=this.shapes.head;for(;n!=null;){let l=n.elt,s=t.outer.zpp_inner.wrap_shapes,i=l.outer.copy();s.zpp_inner.reverse_flag?s.push(i):s.unshift(i),n=n.next}if(t.posx=this.posx,t.posy=this.posy,t.velx=this.velx,t.vely=this.vely,t.forcex=this.forcex,t.forcey=this.forcey,t.rot=this.rot,t.angvel=this.angvel,t.torque=this.torque,t.kinvelx=this.kinvelx,t.kinvely=this.kinvely,t.kinangvel=this.kinangvel,t.svelx=this.svelx,t.svely=this.svely,!this.zip_axis)t.axisx=this.axisx,t.axisy=this.axisy;else{t.zip_axis=!0;let l=t.shapes.head;for(;l!=null;){let s=l.elt;s.type===1&&(s.polygon.invalidate_gverts(),s.polygon.invalidate_gaxi()),s.invalidate_worldCOM(),l=l.next}t.zip_worldCOM=!0}return t.rot=this.rot,t.massMode=this.massMode,t.gravMassMode=this.gravMassMode,t.inertiaMode=this.inertiaMode,t.norotate=this.norotate,t.nomove=this.nomove,t.cmass=this.cmass,t.cinertia=this.cinertia,this.zip_mass?t.invalidate_mass():t.mass=this.mass,this.zip_gravMass?t.invalidate_gravMass():t.gravMass=this.gravMass,this.zip_gravMassScale?t.invalidate_gravMassScale():t.gravMassScale=this.gravMassScale,this.zip_inertia?t.invalidate_inertia():t.inertia=this.inertia,this.zip_aabb?t.zip_aabb=!0:(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy),this.zip_localCOM?(t.zip_localCOM=!0,t.zip_worldCOM=!0):(t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy),this.zip_worldCOM?t.zip_worldCOM=!0:(t.worldCOMx=this.worldCOMx,t.worldCOMy=this.worldCOMy),this.copyto(t.outer),t.outer}static _init(e,t){if(!Be._initialized){Be._initialized=!0,Be._zpp=e,Be._nape=t,Be.__super__=Ut;for(let n of Object.getOwnPropertyNames(Ut.prototype))n!=="constructor"&&n!=="__class__"&&!(n in Be.prototype)&&(Be.prototype[n]=Ut.prototype[n])}}static _initEnums(e,t){let n=()=>{t.internal=!0;let l=new e.phys.BodyType;return t.internal=!1,l};t.BodyType_STATIC==null&&(t.BodyType_STATIC=n()),t.BodyType_DYNAMIC==null&&(t.BodyType_DYNAMIC=n()),t.BodyType_KINEMATIC==null&&(t.BodyType_KINEMATIC=n()),Be.types=[null,t.BodyType_STATIC,t.BodyType_DYNAMIC,t.BodyType_KINEMATIC]}};Be.__name__=["zpp_nape","phys","ZPP_Body"],Be.__super__=null,Be._nape=null,Be._zpp=null,Be.types=[],Be.bodystack=null,Be.bodyset=null,Be.cur_graph_depth=0,Be._initialized=!1;var Wn=Be;var tn=class tn{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=tn._zpp;Ut.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=tn._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=tn._zppOf(e);t.compound=null,this.space!=null&&this.space.remBody(t)}bodies_modifiable(){this.immutable_midstep("Compound::bodies")}constraints_adder(e){let t=tn._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=tn._zppOf(e);t.compound=null,this.space!=null&&this.space.remConstraint(t)}constraints_modifiable(){this.immutable_midstep("Compound::constraints")}compounds_adder(e){let t=tn._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=tn._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=tn._nape,l=tn._zpp,s=e==null;e==null&&(e=[]),t==null&&(t=[]);let i=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)!==i&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_compounds.remove(c),i!=null)){let u=i.zpp_inner.wrap_compounds;u.zpp_inner.reverse_flag?u.push(c):u.unshift(c)}r=r.next}let o=this.bodies.head;for(;o!=null;){let p=o.elt,c=p.outer.copy();if(e.push(l.constraint.ZPP_CopyHelper.dict(p.id,c)),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==i&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_bodies.remove(c),i!=null)){let u=i.zpp_inner.wrap_bodies;u.zpp_inner.reverse_flag?u.push(c):u.unshift(c)}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)!==i&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_constraints.remove(c),i!=null)){let u=i.zpp_inner.wrap_constraints;u.zpp_inner.reverse_flag?u.push(c):u.unshift(c)}a=a.next}if(s)for(;t.length>0;){let p=t.pop();for(let c=0;c<e.length;c++){let u=e[c];if(u.id===p.id){p.cb(u.bc);break}}}return this.copyto(i),i}static _init(){tn.__super__=Ut;for(let e of Object.getOwnPropertyNames(Ut.prototype))e!=="constructor"&&e!=="__class__"&&!Object.prototype.hasOwnProperty.call(tn.prototype,e)&&(tn.prototype[e]=Ut.prototype[e])}};tn.__name__=["zpp_nape","phys","ZPP_Compound"],tn.__super__=null,tn._nape=null,tn._zpp=null,tn._wrapFn=null;var Pi=tn;var Kt=class Kt{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 Kt._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Kt._wrapFn)this.outer=Kt._wrapFn(this);else{this.outer=new Kt._nape.phys.FluidProperties;let e=this.outer.zpp_inner;e.outer=null,e.next=Kt.zpp_pool,Kt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Kt._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Kt.zpp_pool==null?e=new Kt:(e=Kt.zpp_pool,Kt.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=Kt._zpp,t=Kt._nape,n=this.gravityx??0,l=this.gravityy??0;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let r=!1;i._validate!=null&&i._validate(),(i.x!==n||i.y!==l)&&(r=!0),r&&(i.x=n,i.y=l,i._invalidate!=null&&i._invalidate(i))}s.zpp_inner.weak=!1,this.wrap_gravity=s,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=this.gravity_invalidate.bind(this),this.wrap_gravity.zpp_inner._validate=this.gravity_validate.bind(this)}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_fluidprops(),e=e.next}};Kt.zpp_pool=null,Kt.__name__=["zpp_nape","phys","ZPP_FluidProperties"],Kt._nape=null,Kt._zpp=null,Kt._wrapFn=null;var Jn=Kt;var nn=class nn{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 nn._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(nn._wrapFn)this.outer=nn._wrapFn(this);else{this.outer=new nn._nape.phys.Material;let e=this.outer.zpp_inner;e.outer=null,e.next=nn.zpp_pool,nn.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new nn._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e=new nn;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}};nn.zpp_pool=null,nn.WAKE=1,nn.PROPS=2,nn.ANGDRAG=4,nn.ARBITERS=8,nn.__name__=["zpp_nape","phys","ZPP_Material"],nn._nape=null,nn._zpp=null,nn._wrapFn=null;var Te=nn;var vn=class vn{constructor(e){this.outer=null;this.body=null;this.type=0;this.area=0;this.zip_area_inertia=!1;this.inertia=0;this.angDrag=0;this.zip_angDrag=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;this.sweepRadius=0;this.zip_sweepRadius=!1;this.sweepCoef=0;this.circle=null;this.polygon=null;this.refmaterial=null;this.material=null;this.filter=null;this.fluidProperties=null;this.fluidEnabled=!1;this.sensorEnabled=!1;this.sweep=null;this.node=null;this.pairs=null;this.aabb=null;this.zip_aabb=!1;this.ishape=null;this.userData=null;e!==void 0&&this._initShape(e)}static _initEnums(e,t){let n=()=>{t.internal=!0;let l=new e.shape.ShapeType;return t.internal=!1,l};t.ShapeType_CIRCLE==null&&(t.ShapeType_CIRCLE=n()),t.ShapeType_POLYGON==null&&(t.ShapeType_POLYGON=n()),vn.types=[t.ShapeType_CIRCLE,t.ShapeType_POLYGON]}_initShape(e){let t=vn._zpp;Ut.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 Te,this.sweepRadius=this.sweepCoef=0}static _init(){if(!vn._initialized){vn._initialized=!0,vn.__super__=Ut;for(let e of Object.getOwnPropertyNames(Ut.prototype))e!=="constructor"&&e!=="__class__"&&!Object.prototype.hasOwnProperty.call(vn.prototype,e)&&(vn.prototype[e]=Ut.prototype[e])}}isCircle(){return this.type===0}isPolygon(){return this.type===1}invalidate_sweepRadius(){this.zip_sweepRadius=!0}validate_sweepRadius(){this.zip_sweepRadius&&(this.zip_sweepRadius=!1,this.type===0?this.circle.__validate_sweepRadius():this.polygon.__validate_sweepRadius())}clear(){this.type===0?this.circle.__clear():this.polygon.__clear()}validate_aabb(){this.zip_aabb&&this.body!=null&&(this.zip_aabb=!1,this.type===0?this.circle.__validate_aabb():this.polygon.__validate_aabb())}force_validate_aabb(){this.type===0?this.circle._force_validate_aabb():this.polygon._force_validate_aabb()}invalidate_aabb(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}validate_area_inertia(){this.zip_area_inertia&&(this.zip_area_inertia=!1,this.type===0?this.circle.__validate_area_inertia():this.polygon.__validate_area_inertia())}validate_angDrag(){(this.zip_angDrag||this.refmaterial.dynamicFriction!==this.material.dynamicFriction)&&(this.zip_angDrag=!1,this.refmaterial.dynamicFriction=this.material.dynamicFriction,this.type===0?this.circle.__validate_angDrag():this.polygon.__validate_angDrag())}validate_localCOM(){this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy))}validate_worldCOM(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.validate_localCOM();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy)}}getworldCOM(){if(this.body==null)throw new Error("Error: worldCOM only makes sense when Shape belongs to a Body");this.validate_worldCOM(),this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy}invalidate_area_inertia(){this.zip_area_inertia=!0,this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia())}invalidate_angDrag(){this.zip_angDrag=!0}invalidate_localCOM(){this.zip_localCOM=!0,this.invalidate_area_inertia(),this.type===0&&(this.zip_sweepRadius=!0),this.invalidate_angDrag(),this.invalidate_worldCOM(),this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0)}invalidate_worldCOM(){this.zip_worldCOM=!0,this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}invalidate_material(e){(e&Te.WAKE)!==0&&this.wake(),(e&Te.ARBITERS)!==0&&this.body!=null&&this.body.refreshArbiters(),(e&Te.PROPS)!==0&&this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia()),(e&Te.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=vn._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=Te.zpp_pool,Te.zpp_pool=n;let l=t.filter;return l.outer=null,l.next=e.dynamics.ZPP_InteractionFilter.zpp_pool,e.dynamics.ZPP_InteractionFilter.zpp_pool=l,t.material=this.material,t.filter=this.filter,this.fluidProperties!=null&&(t.fluidProperties=this.fluidProperties),t.fluidEnabled=this.fluidEnabled,t.sensorEnabled=this.sensorEnabled,this.userData!=null&&(t.userData=Object.assign({},this.userData)),this.copyto(t.outer),t.outer}};vn.__name__=["zpp_nape","shape","ZPP_Shape"],vn.__super__=null,vn._nape=null,vn._zpp=null,vn.types=[],vn._initialized=!1;var Ji=vn;var gn=class gn{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(gn._initialized)return;gn._initialized=!0;let e=gn._zpp;gn.__super__=e.shape.ZPP_Shape;let t=e.shape.ZPP_Shape.prototype,n=gn.prototype;for(let l in t)l!=="__class__"&&!Object.prototype.hasOwnProperty.call(n,l)&&(n[l]=t[l]);for(let l of Object.getOwnPropertyNames(t))l!=="constructor"&&l!=="__class__"&&!Object.prototype.hasOwnProperty.call(n,l)&&(n[l]=t[l])}__clear(){}invalidate_radius(){this.invalidate_area_inertia(),this.invalidate_angDrag(),this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0),this.body!=null&&this.body.wake()}localCOM_validate(){this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy}localCOM_invalidate(e){this.localCOMx=e.x,this.localCOMy=e.y,this.invalidate_localCOM(),this.body!=null&&this.body.wake()}localCOM_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify localCOM of Circle added to a static Body whilst within a Space")}setupLocalCOM(){let e=gn._zpp,t=gn._nape,n=this.localCOMx,l=this.localCOMy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,this.wrap_localCOM=s,this.wrap_localCOM.zpp_inner._inuse=!0,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this),this.wrap_localCOM.zpp_inner._isimmutable=this.localCOM_immutable.bind(this)}__validate_aabb(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy));let n=this.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),this.worldCOMx=n.posx+(n.axisy*this.localCOMx-n.axisx*this.localCOMy),this.worldCOMy=n.posy+(this.localCOMx*n.axisx+this.localCOMy*n.axisy)}let e=this.radius,t=this.radius;this.aabb.minx=this.worldCOMx-e,this.aabb.miny=this.worldCOMy-t,this.aabb.maxx=this.worldCOMx+e,this.aabb.maxy=this.worldCOMy+t}_force_validate_aabb(){let e=this.body;this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy),this.aabb.minx=this.worldCOMx-this.radius,this.aabb.miny=this.worldCOMy-this.radius,this.aabb.maxx=this.worldCOMx+this.radius,this.aabb.maxy=this.worldCOMy+this.radius}__validate_sweepRadius(){this.sweepCoef=Math.sqrt(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy),this.sweepRadius=this.sweepCoef+this.radius}__validate_area_inertia(){let e=this.radius*this.radius;this.area=e*Math.PI,this.inertia=e*.5+(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy)}__validate_angDrag(){let e=gn._nape,t=this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy,n=this.radius*this.radius,l=this.material.dynamicFriction*e.Config.fluidAngularDragFriction;this.angDrag=(t+2*n)*l+.5*e.Config.fluidAngularDrag*(1+e.Config.fluidVacuumDrag)*t,this.angDrag/=2*(t+.5*n)}__scale(e,t){let n=((e<0?-e:e)+(t<0?-t:t))/2;this.radius*=n<0?-n:n,this.invalidate_radius(),this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0&&(this.localCOMx*=e,this.localCOMy*=t,this.invalidate_localCOM())}__translate(e,t){this.localCOMx+=e,this.localCOMy+=t,this.invalidate_localCOM()}__rotate(e,t){if(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0){let n=t*this.localCOMx-e*this.localCOMy,l=this.localCOMx*e+this.localCOMy*t;this.localCOMx=n,this.localCOMy=l,this.invalidate_localCOM()}}__transform(e){let t=e.zpp_inner.a*e.zpp_inner.d-e.zpp_inner.b*e.zpp_inner.c;t<0&&(t=-t),this.radius*=Math.sqrt(t);let n=e.zpp_inner.a*this.localCOMx+e.zpp_inner.b*this.localCOMy+e.zpp_inner.tx;this.localCOMy=e.zpp_inner.c*this.localCOMx+e.zpp_inner.d*this.localCOMy+e.zpp_inner.ty,this.localCOMx=n,this.invalidate_radius(),this.invalidate_localCOM()}__copy(){let e=gn._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}};gn.__name__=["zpp_nape","shape","ZPP_Circle"],gn.__super__=null,gn._nape=null,gn._zpp=null,gn._initialized=!1;var Ni=gn;var _n=class _n{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&&(_n._wrapFn?this.outer=_n._wrapFn(this):(_n.internal=!0,this.outer=new _n._nape.shape.Edge,_n.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=_n._zpp,t=_n._nape,n=this.lnormx,l=this.lnormy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,this.wrap_lnorm=s,this.wrap_lnorm.zpp_inner._immutable=!0,this.wrap_lnorm.zpp_inner._validate=this.lnorm_validate.bind(this)}getgnorm(){let e=_n._zpp,t=_n._nape,n=this.gnormx,l=this.gnormy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,this.wrap_gnorm=s,this.wrap_gnorm.zpp_inner._immutable=!0,this.wrap_gnorm.zpp_inner._validate=this.gnorm_validate.bind(this)}};_n.__name__=["zpp_nape","shape","ZPP_Edge"],_n.zpp_pool=null,_n.internal=!1,_n._nape=null,_n._zpp=null,_n._wrapFn=null;var Qe=_n;var dt=class dt{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=dt._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(dt._initialized)return;dt._initialized=!0;let e=dt._zpp;dt.__super__=e.shape.ZPP_Shape;let t=e.shape.ZPP_Shape.prototype,n=dt.prototype;for(let l in t)l!=="__class__"&&!Object.prototype.hasOwnProperty.call(n,l)&&(n[l]=t[l]);for(let l of Object.getOwnPropertyNames(t))l!=="constructor"&&l!=="__class__"&&!Object.prototype.hasOwnProperty.call(n,l)&&(n[l]=t[l])}__clear(){}lverts_pa_invalidate(e){this.invalidate_lverts()}lverts_pa_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify local vertex of Polygon added to a static body whilst within a Space")}gverts_pa_validate(){if(this.body==null)throw new Error("Error: World vertex only makes sense when Polygon is contained in a rigid body");this._validateGverts()}lverts_post_adder(e){let t=dt._zpp;e.zpp_inner._invalidate=this.lverts_pa_invalidate.bind(this),e.zpp_inner._isimmutable=this.lverts_pa_immutable.bind(this);let n=null,l=null,s=this.lverts.next;for(;s!=null&&s!==e.zpp_inner;)n=n==null?this.gverts.next:n.next,l=l==null?this.edges.head:l.next,s=s.next;let i;if(t.geom.ZPP_Vec2.zpp_pool==null?i=new t.geom.ZPP_Vec2:(i=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!0,i.x=0,i.y=0,this.gverts.insert(n,i),this.lverts.next.next!=null)if(this.lverts.next.next.next==null){let r;Qe.zpp_pool==null?r=new Qe:(r=Qe.zpp_pool,Qe.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.add(r);let o;Qe.zpp_pool==null?o=new Qe:(o=Qe.zpp_pool,Qe.zpp_pool=o.next,o.next=null),o.polygon=this,this.edges.add(o),this.edgeCnt+=2}else{let r;Qe.zpp_pool==null?r=new Qe:(r=Qe.zpp_pool,Qe.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.insert(l,r),this.edgeCnt++}i._validate=this.gverts_pa_validate.bind(this)}lverts_subber(e){this.cleanup_lvert(e.zpp_inner)}lverts_invalidate(e){this.invalidate_lverts()}lverts_validate(){this.validate_lverts()}lverts_modifiable(){if(this.immutable_midstep("Polygon::localVerts"),this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}gverts_validate(){this._validateGverts()}edges_validate(){this.validate_lverts()}getlverts(){let e=dt._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=dt._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=dt._zpp;this.wrap_edges=e.util.ZPP_EdgeList.get(this.edges,!0),this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag,this.wrap_edges.zpp_inner._validate=this.edges_validate.bind(this)}invalidate_lverts(){this.invalidate_laxi(),this.invalidate_area_inertia(),this.invalidate_angDrag(),this.invalidate_localCOM(),this.invalidate_gverts(),this.zip_lverts=!0,this.zip_valid=!0,this.zip_sanitation=!0,this.body!=null&&this.body.wake()}invalidate_laxi(){this.invalidate_gaxi(),this.zip_sweepRadius=!0,this.zip_laxi=!0}invalidate_gverts(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0),this.zip_gverts=!0}invalidate_gaxi(){this.zip_gaxi=!0}validate_lverts(){this.zip_lverts&&(this.zip_lverts=!1,this.lverts.length>2&&(this.validate_area_inertia(),this.area<0&&(this.reverse_vertices(),this.area=-this.area)))}validate_laxi(){if(this.zip_laxi){this.zip_laxi=!1,this.validate_lverts();let t=this.edges.head,n=this.lverts.next,l=n;for(n=n.next;n!=null;){let u=n,h=t.elt;t=t.next,h.lp0=l,h.lp1=u;let x=l.x-u.x,f=l.y-u.y,_=Math.sqrt(x*x+f*f);h.length=_;let d=1/_;x*=d,f*=d;let b=x;x=-f,f=b,h.lprojection=x*l.x+f*l.y,h.lnormx=x,h.lnormy=f,h.wrap_lnorm!=null&&(h.wrap_lnorm.zpp_inner.x=x,h.wrap_lnorm.zpp_inner.y=f),l=u,n=n.next}let s=this.lverts.next,i=t.elt;i.lp0=l,i.lp1=s;let r=l.x-s.x,o=l.y-s.y,a=Math.sqrt(r*r+o*o);i.length=a;let p=1/a;r*=p,o*=p;let c=r;r=-o,o=c,i.lprojection=r*l.x+o*l.y,i.lnormx=r,i.lnormy=o,i.wrap_lnorm!=null&&(i.wrap_lnorm.zpp_inner.x=r,i.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,l=n;for(n=n.next;n!=null;){let r=n,o=t.elt;t=t.next,o.gp0=l,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,l=r,n=n.next}let s=this.gverts.next,i=t.elt;i.gp0=l,i.gp1=s,i.gnormx=e.axisy*i.lnormx-e.axisx*i.lnormy,i.gnormy=i.lnormx*e.axisx+i.lnormy*e.axisy,i.gprojection=e.posx*i.gnormx+e.posy*i.gnormy+i.lprojection,i.wrap_gnorm!=null&&(i.wrap_gnorm.zpp_inner.x=i.gnormx,i.wrap_gnorm.zpp_inner.y=i.gnormy),i.tp0=i.gp0.y*i.gnormx-i.gp0.x*i.gnormy,i.tp1=i.gp1.y*i.gnormx-i.gp1.x*i.gnormy}}_validateGverts(){if(this.zip_gverts&&this.body!=null){this.zip_gverts=!1,this.validate_lverts();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let t=this.lverts.next,n=this.gverts.next;for(;n!=null;){let l=n,s=t;t=t.next,l.x=e.posx+(e.axisy*s.x-e.axisx*s.y),l.y=e.posy+(s.x*e.axisx+s.y*e.axisy),n=n.next}}}cleanup_lvert(e){let t=dt._zpp,n=null,l=null,s=this.lverts.next;for(;s!=null&&s!==e;)n=n==null?this.gverts.next:n.next,l=l==null?this.edges.head:l.next,s=s.next;let i=n==null?this.gverts.next:n.next;this.gverts.erase(n);let r=i;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=Qe.zpp_pool,Qe.zpp_pool=o,o=this.edges.pop_unsafe(),o.polygon=null,o.next=Qe.zpp_pool,Qe.zpp_pool=o,this.edgeCnt=0}else if(this.edgeCnt!==0){let o=l==null?this.edges.head.elt:l.next.elt;this.edges.erase(l),o.polygon=null,o.next=Qe.zpp_pool,Qe.zpp_pool=o,this.edgeCnt--}}splice_collinear(){this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real())}splice_collinear_real(){let e=dt._nape;if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)return;let t=null,n=this.lverts.next;for(;n!=null;){let s=n.next==null?this.lverts.next:n.next,i=n.x-s.x,r=n.y-s.y;i*i+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 l;for(;;){l=!1;let s=this.lverts.next;for(;s!=null;){let i=s.next==null?this.lverts.next:s.next,r=i.next==null?this.lverts.next:i.next,o=i.x-s.x,a=i.y-s.y,p=r.x-i.x,u=(r.y-i.y)*o-p*a;u*u>=e.Config.epsilon*e.Config.epsilon||(this.cleanup_lvert(i),this.lverts.erase(s.next==null?null:s),l=!0),s=s.next}if(!l)break}}reverse_vertices(){this.lverts.reverse(),this.gverts.reverse(),this.edges.reverse();let e=this.edges.iterator_at(this.edgeCnt-1),t=this.edges.pop_unsafe();this.edges.insert(e,t),this.reverse_flag=!this.reverse_flag,this.wrap_lverts!=null&&(this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_gverts!=null&&(this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_edges!=null&&(this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag)}valid(){let e=dt._nape,t=dt._zpp;if(this.zip_valid){if(this.zip_valid=!1,this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real()),this.lverts.length<3)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;if(this.validate_lverts(),this.validate_area_inertia(),this.area<e.Config.epsilon)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;{let n=!1,l=!1,s=!0,i=this.lverts.next,r=i;i=i.next;let o=i;for(i=i.next;i!=null;){let a=i,p=a.x-o.x,c=a.y-o.y,u=o.x-r.x,x=(o.y-r.y)*p-u*c;if(x>e.Config.epsilon?l=!0:x<-e.Config.epsilon&&(n=!0),l&&n){s=!1;break}r=o,o=a,i=i.next}if(s){i=this.lverts.next;let a=i,p=a.x-o.x,c=a.y-o.y,u=o.x-r.x,x=(o.y-r.y)*p-u*c;if(x>e.Config.epsilon?l=!0:x<-e.Config.epsilon&&(n=!0),!(l&&n)){r=o,o=a,i=i.next;let f=i,_=f.x-o.x,d=f.y-o.y,b=o.x-r.x,z=(o.y-r.y)*_-b*d;z>e.Config.epsilon?l=!0:z<-e.Config.epsilon&&(n=!0)}}if(l&&n)return t.util.ZPP_Flags.ValidationResult_CONCAVE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_CONCAVE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_CONCAVE;{let a=!0,p=this.lverts.next,c=p;for(p=p.next;p!=null&&a;){let u=p,h=this.lverts.next,x=h.next;for(;x!=null&&a;){let f=x;c!==h&&c!==f&&u!==h&&u!==f&&(a=this._checkNoIntersection(c,u,h,f,e)),h=f,x=x.next}if(a){let f=this.lverts.next;c!==h&&c!==f&&u!==h&&u!==f&&(a=this._checkNoIntersection(c,u,h,f,e))}c=u,p=p.next}if(a){let u=this.lverts.next,h=this.lverts.next,x=h.next;for(;x!=null&&a;){let f=x;c!==h&&c!==f&&u!==h&&u!==f&&(a=this._checkNoIntersection(c,u,h,f,e)),h=f,x=x.next}if(a){let f=this.lverts.next;c!==h&&c!==f&&u!==h&&u!==f&&(a=this._checkNoIntersection(c,u,h,f,e))}}return a?(t.util.ZPP_Flags.ValidationResult_VALID==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_VALID=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_VALID):(t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING)}}}else return this.validation}_checkNoIntersection(e,t,n,l,s){let i=e.x-n.x,r=e.y-n.y,o=t.x-e.x,a=t.y-e.y,p=l.x-n.x,c=l.y-n.y,u=a*p-o*c;if(u*u>s.Config.epsilon){u=1/u;let h=(c*i-p*r)*u;if(h>s.Config.epsilon&&h<1-s.Config.epsilon){let x=(a*i-o*r)*u;if(x>s.Config.epsilon&&x<1-s.Config.epsilon)return!1}}return!0}__validate_aabb(){if(this._validateGverts(),this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let e=this.gverts.next;this.aabb.minx=e.x,this.aabb.miny=e.y,this.aabb.maxx=e.x,this.aabb.maxy=e.y;let t=this.gverts.next.next;for(;t!=null;){let n=t;n.x<this.aabb.minx&&(this.aabb.minx=n.x),n.x>this.aabb.maxx&&(this.aabb.maxx=n.x),n.y<this.aabb.miny&&(this.aabb.miny=n.y),n.y>this.aabb.maxy&&(this.aabb.maxy=n.y),t=t.next}}_force_validate_aabb(){let e=this.body,t=this.lverts.next,n=this.gverts.next,l=t;t=t.next,n.x=e.posx+(e.axisy*l.x-e.axisx*l.y),n.y=e.posy+(l.x*e.axisx+l.y*e.axisy),this.aabb.minx=n.x,this.aabb.miny=n.y,this.aabb.maxx=n.x,this.aabb.maxy=n.y;let s=this.gverts.next.next;for(;s!=null;){let i=s,r=t;t=t.next,i.x=e.posx+(e.axisy*r.x-e.axisx*r.y),i.y=e.posy+(r.x*e.axisx+r.y*e.axisy),i.x<this.aabb.minx&&(this.aabb.minx=i.x),i.x>this.aabb.maxx&&(this.aabb.maxx=i.x),i.y<this.aabb.miny&&(this.aabb.miny=i.y),i.y>this.aabb.maxy&&(this.aabb.maxy=i.y),s=s.next}}__validate_sweepRadius(){let e=0,t=0;this.validate_laxi();let n=this.lverts.next;for(;n!=null;){let s=n,i=s.x*s.x+s.y*s.y;i>e&&(e=i),n=n.next}let l=this.edges.head;for(;l!=null;){let s=l.elt;if(s.lprojection<t&&(t=s.lprojection,t<0))break;l=l.next}t<0&&(t=0),this.sweepRadius=Math.sqrt(e),this.sweepCoef=this.sweepRadius-t}__validate_area_inertia(){if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)this.area=0,this.inertia=0;else{this.area=0;let e=0,t=0,n=this.lverts.next,l=n;n=n.next;let s=n;for(n=n.next;n!=null;){let p=n,c=s.y*l.x-s.x*l.y,u=s.x*s.x+s.y*s.y+(s.x*l.x+s.y*l.y)+(l.x*l.x+l.y*l.y);e+=c*u,t+=c,this.area+=s.x*(p.y-l.y),l=s,s=p,n=n.next}n=this.lverts.next;let i=n,r=s.y*l.x-s.x*l.y,o=s.x*s.x+s.y*s.y+(s.x*l.x+s.y*l.y)+(l.x*l.x+l.y*l.y);e+=r*o,t+=r,this.area+=s.x*(i.y-l.y),l=s,s=i,n=n.next;let a=n;r=s.y*l.x-s.x*l.y,o=s.x*s.x+s.y*s.y+(s.x*l.x+s.y*l.y)+(l.x*l.x+l.y*l.y),e+=r*o,t+=r,this.area+=s.x*(a.y-l.y),this.inertia=e/(6*t),this.area*=.5,this.area<0&&(this.area=-this.area,this.reverse_vertices())}}__validate_angDrag(){let e=dt._nape;if(this.lverts.length<3)throw new Error("Error: Polygon's with less than 3 vertices have no meaningful angDrag");this.validate_area_inertia(),this.validate_laxi();let t=0,n=this.edges.head,l=0,s=this.lverts.next,i=s,r=s.next;for(;r!=null;){let o=r,a=n.elt;n=n.next,l+=a.length;let p=o.x-i.x,c=o.y-i.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let u=-(i.y*a.lnormx-i.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(u>0){let h=u>1?1:u,x=i.x,f=i.y;x+=p*h,f+=c*h;let _=a.lnormy*i.x-a.lnormx*i.y,d=a.lnormy*x-a.lnormx*f,b=(d*d*d-_*_*_)/(3*(d-_));t+=b*h*a.length*e.Config.fluidAngularDrag}if(u<1){let h=u<0?0:u,x=i.x,f=i.y;x+=p*h,f+=c*h;let _=a.lnormy*x-a.lnormx*f,d=a.lnormy*o.x-a.lnormx*o.y,b=(d*d*d-_*_*_)/(3*(d-_));t+=b*e.Config.fluidVacuumDrag*(1-h)*a.length*e.Config.fluidAngularDrag}i=o,r=r.next}{let o=this.lverts.next,a=n.elt;l+=a.length;let p=o.x-i.x,c=o.y-i.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let u=-(i.y*a.lnormx-i.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(u>0){let h=u>1?1:u,x=i.x,f=i.y;x+=p*h,f+=c*h;let _=a.lnormy*i.x-a.lnormx*i.y,d=a.lnormy*x-a.lnormx*f,b=(d*d*d-_*_*_)/(3*(d-_));t+=b*h*a.length*e.Config.fluidAngularDrag}if(u<1){let h=u<0?0:u,x=i.x,f=i.y;x+=p*h,f+=c*h;let _=a.lnormy*x-a.lnormx*f,d=a.lnormy*o.x-a.lnormx*o.y,b=(d*d*d-_*_*_)/(3*(d-_));t+=b*e.Config.fluidVacuumDrag*(1-h)*a.length*e.Config.fluidAngularDrag}}this.angDrag=t/(this.inertia*l)}__validate_localCOM(){if(this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(this.lverts.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y;else if(this.lverts.next.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y,this.localCOMx+=this.lverts.next.next.x,this.localCOMy+=this.lverts.next.next.y,this.localCOMx*=.5,this.localCOMy*=.5;else{this.localCOMx=0,this.localCOMy=0;let e=0,t=this.lverts.next,n=t;t=t.next;let l=t;for(t=t.next;t!=null;){let o=t;e+=l.x*(o.y-n.y);let a=o.y*l.x-o.x*l.y;this.localCOMx+=(l.x+o.x)*a,this.localCOMy+=(l.y+o.y)*a,n=l,l=o,t=t.next}t=this.lverts.next;let s=t;e+=l.x*(s.y-n.y);let i=s.y*l.x-s.x*l.y;this.localCOMx+=(l.x+s.x)*i,this.localCOMy+=(l.y+s.y)*i,n=l,l=s,t=t.next;let r=t;e+=l.x*(r.y-n.y),i=r.y*l.x-r.x*l.y,this.localCOMx+=(l.x+r.x)*i,this.localCOMy+=(l.y+r.y)*i,e=1/(3*e),this.localCOMx*=e,this.localCOMy*=e}}localCOM_validate(){if(this.lverts.next==null)throw new Error("Error: An empty polygon does not have any meaningful localCOM");this.validate_localCOM()}localCOM_invalidate(e){this.validate_localCOM();let t=e.x-this.localCOMx,n=e.y-this.localCOMy,l=this.lverts.next;for(;l!=null;)l.x+=t,l.y+=n,l=l.next;this.invalidate_lverts()}setupLocalCOM(){let e=dt._zpp,t=dt._nape,n=this.localCOMx,l=this.localCOMy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,this.wrap_localCOM=s,this.wrap_localCOM.zpp_inner._inuse=!0,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this)}__translate(e,t){let n=this.lverts.next;for(;n!=null;)n.x+=e,n.y+=t,n=n.next;this.invalidate_lverts()}__scale(e,t){let n=this.lverts.next;for(;n!=null;)n.x*=e,n.y*=t,n=n.next;this.invalidate_lverts()}__rotate(e,t){let n=this.lverts.next;for(;n!=null;){let l=t*n.x-e*n.y,s=n.x*e+n.y*t;n.x=l,n.y=s,n=n.next}this.invalidate_lverts()}__transform(e){let t=this.lverts.next;for(;t!=null;){let n=e.zpp_inner.a*t.x+e.zpp_inner.b*t.y+e.zpp_inner.tx;t.y=e.zpp_inner.c*t.x+e.zpp_inner.d*t.y+e.zpp_inner.ty,t.x=n,t=t.next}this.invalidate_lverts()}__copy(){let e=dt._nape;this.outer_zn.zpp_inner_zn.wrap_lverts==null&&this.outer_zn.zpp_inner_zn.getlverts();let t=this.outer_zn.zpp_inner_zn.wrap_lverts,n=[],l=t.iterator();for(;l.hasNext();)n.push(l.next());return new e.shape.Polygon(n).zpp_inner_zn}};dt.__name__=["zpp_nape","shape","ZPP_Polygon"],dt.__super__=null,dt._nape=null,dt._zpp=null,dt._initialized=!1;var Oi=dt;var Ui=class Ui{constructor(){this.space=null;this.is_sweep=!1;this.sweep=null;this.dynab=null;this.aabbShape=null;this.matrix=null;this.circShape=null}static _initFields(e){e.space=null,e.is_sweep=!1,e.sweep=null,e.dynab=null,e.aabbShape=null,e.matrix=null,e.circShape=null}insert(e){this.is_sweep?this.sweep.__insert(e):this.dynab.__insert(e)}remove(e){this.is_sweep?this.sweep.__remove(e):this.dynab.__remove(e)}sync(e){if(this.is_sweep){if(!this.sweep.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let i=t.polygon;if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(i.lverts.next.next==null)i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;else if(i.lverts.next.next.next==null){i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;let r=1;i.localCOMx+=i.lverts.next.next.x*r,i.localCOMy+=i.lverts.next.next.y*r;let o=.5;i.localCOMx*=o,i.localCOMy*=o}else{i.localCOMx=0,i.localCOMy=0;let r=0,o=i.lverts.next,a=o;o=o.next;let p=o;for(o=o.next;o!=null;){let _=o;r+=p.x*(_.y-a.y);let d=_.y*p.x-_.x*p.y;i.localCOMx+=(p.x+_.x)*d,i.localCOMy+=(p.y+_.y)*d,a=p,p=_,o=o.next}o=i.lverts.next;let c=o;r+=p.x*(c.y-a.y);let u=c.y*p.x-c.x*p.y;i.localCOMx+=(p.x+c.x)*u,i.localCOMy+=(p.y+c.y)*u,a=p,p=c,o=o.next;let h=o;r+=p.x*(h.y-a.y);let x=h.y*p.x-h.x*p.y;i.localCOMx+=(p.x+h.x)*x,i.localCOMy+=(p.y+h.y)*x,r=1/(3*r);let f=r;i.localCOMx*=f,i.localCOMy*=f}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,r=t.gverts.next;for(;r!=null;){let o=r,a=i;i=i.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 l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}}else{let t=this.dynab,n=e.node;if(!n.synced){if(!t.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let s=e.circle;if(s.zip_worldCOM&&s.body!=null){if(s.zip_worldCOM=!1,s.zip_localCOM){if(s.zip_localCOM=!1,s.type==1){let a=s.polygon;if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(a.lverts.next.next==null)a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;else if(a.lverts.next.next.next==null){a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;let p=1;a.localCOMx+=a.lverts.next.next.x*p,a.localCOMy+=a.lverts.next.next.y*p;let c=.5;a.localCOMx*=c,a.localCOMy*=c}else{a.localCOMx=0,a.localCOMy=0;let p=0,c=a.lverts.next,u=c;c=c.next;let h=c;for(c=c.next;c!=null;){let m=c;p+=h.x*(m.y-u.y);let z=m.y*h.x-m.x*h.y;a.localCOMx+=(h.x+m.x)*z,a.localCOMy+=(h.y+m.y)*z,u=h,h=m,c=c.next}c=a.lverts.next;let x=c;p+=h.x*(x.y-u.y);let f=x.y*h.x-x.x*h.y;a.localCOMx+=(h.x+x.x)*f,a.localCOMy+=(h.y+x.y)*f,u=h,h=x,c=c.next;let _=c;p+=h.x*(_.y-u.y);let d=_.y*h.x-_.x*h.y;a.localCOMx+=(h.x+_.x)*d,a.localCOMy+=(h.y+_.y)*d,p=1/(3*p);let b=p;a.localCOMx*=b,a.localCOMy*=b}}s.wrap_localCOM!=null&&(s.wrap_localCOM.zpp_inner.x=s.localCOMx,s.wrap_localCOM.zpp_inner.y=s.localCOMy)}let o=s.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),s.worldCOMx=s.body.posx+(s.body.axisy*s.localCOMx-s.body.axisx*s.localCOMy),s.worldCOMy=s.body.posy+(s.localCOMx*s.body.axisx+s.localCOMy*s.body.axisy)}let i=s.radius,r=s.radius;s.aabb.minx=s.worldCOMx-i,s.aabb.miny=s.worldCOMy-r,s.aabb.maxx=s.worldCOMx+i,s.aabb.maxy=s.worldCOMy+r}else{let s=e.polygon;if(s.zip_gverts&&s.body!=null){s.zip_gverts=!1,s.validate_lverts();let o=s.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot));let a=s.lverts.next,p=s.gverts.next;for(;p!=null;){let c=p,u=a;a=a.next,c.x=s.body.posx+(s.body.axisy*u.x-s.body.axisx*u.y),c.y=s.body.posy+(u.x*s.body.axisx+u.y*s.body.axisy),p=p.next}}if(s.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let i=s.gverts.next;s.aabb.minx=i.x,s.aabb.miny=i.y,s.aabb.maxx=i.x,s.aabb.maxy=i.y;let r=s.gverts.next.next;for(;r!=null;){let o=r;o.x<s.aabb.minx&&(s.aabb.minx=o.x),o.x>s.aabb.maxx&&(s.aabb.maxx=o.x),o.y<s.aabb.miny&&(s.aabb.miny=o.y),o.y>s.aabb.maxy&&(s.aabb.maxy=o.y),r=r.next}}let l;if(n.dyn==(e.body.type==1?!1:!e.body.component.sleeping)){let s=n.aabb,i=e.aabb;l=!(i.minx>=s.minx&&i.miny>=s.miny&&i.maxx<=s.maxx&&i.maxy<=s.maxy)}else l=!0;l&&(n.synced=!0,n.snext=t.syncs,t.syncs=n)}}}broadphase(e,t){}clear(){}shapesUnderPoint(e,t,n,l){return null}bodiesUnderPoint(e,t,n,l){return null}updateAABBShape(e){let t=Ui._zpp,n=Ui._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 i=this.aabbShape.zpp_inner.aabb,r=(e.maxx-e.minx)/(i.maxx-i.minx),o=(e.maxy-e.miny)/(i.maxy-i.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,u=this.matrix;u.zpp_inner.c=0;let h=u.zpp_inner;h._invalidate!=null&&h._invalidate();let x=u.zpp_inner.c;if(x!==x)throw new Error("Error: Mat23::b cannot be NaN");c.zpp_inner.b=x;let f=c.zpp_inner;f._invalidate!=null&&f._invalidate();let _=this.matrix;if(o!==o)throw new Error("Error: Mat23::d cannot be NaN");_.zpp_inner.d=o;let d=_.zpp_inner;d._invalidate!=null&&d._invalidate();let b=this.matrix,m=e.minx-r*i.minx;if(m!==m)throw new Error("Error: Mat23::tx cannot be NaN");b.zpp_inner.tx=m;let z=b.zpp_inner;z._invalidate!=null&&z._invalidate();let M=this.matrix,y=e.miny-o*i.miny;if(y!==y)throw new Error("Error: Mat23::ty cannot be NaN");M.zpp_inner.ty=y;let w=M.zpp_inner;w._invalidate!=null&&w._invalidate(),this.aabbShape.transform(this.matrix)}let l=this.aabbShape.zpp_inner;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let i=l.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=!1,i.zip_localCOM){if(i.zip_localCOM=!1,i.type==1){let p=i.polygon;if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(p.lverts.next.next==null)p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;else if(p.lverts.next.next.next==null){p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;let c=1;p.localCOMx+=p.lverts.next.next.x*c,p.localCOMy+=p.lverts.next.next.y*c;let u=.5;p.localCOMx*=u,p.localCOMy*=u}else{p.localCOMx=0,p.localCOMy=0;let c=0,u=p.lverts.next,h=u;u=u.next;let x=u;for(u=u.next;u!=null;){let z=u;c+=x.x*(z.y-h.y);let M=z.y*x.x-z.x*x.y;p.localCOMx+=(x.x+z.x)*M,p.localCOMy+=(x.y+z.y)*M,h=x,x=z,u=u.next}u=p.lverts.next;let f=u;c+=x.x*(f.y-h.y);let _=f.y*x.x-f.x*x.y;p.localCOMx+=(x.x+f.x)*_,p.localCOMy+=(x.y+f.y)*_,h=x,x=f,u=u.next;let d=u;c+=x.x*(d.y-h.y);let b=d.y*x.x-d.x*x.y;p.localCOMx+=(x.x+d.x)*b,p.localCOMy+=(x.y+d.y)*b,c=1/(3*c);let m=c;p.localCOMx*=m,p.localCOMy*=m}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let r=i.radius,o=i.radius;i.aabb.minx=i.worldCOMx-r,i.aabb.miny=i.worldCOMy-o,i.aabb.maxx=i.worldCOMx+r,i.aabb.maxy=i.worldCOMy+o}else{let i=l.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=i.lverts.next,c=i.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=i.body.posx+(i.body.axisy*h.x-i.body.axisx*h.y),u.y=i.body.posy+(h.x*i.body.axisx+h.y*i.body.axisy),c=c.next}}if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=i.gverts.next;i.aabb.minx=r.x,i.aabb.miny=r.y,i.aabb.maxx=r.x,i.aabb.maxy=r.y;let o=i.gverts.next.next;for(;o!=null;){let a=o;a.x<i.aabb.minx&&(i.aabb.minx=a.x),a.x>i.aabb.maxx&&(i.aabb.maxx=a.x),a.y<i.aabb.miny&&(i.aabb.miny=a.y),a.y>i.aabb.maxy&&(i.aabb.maxy=a.y),o=o.next}}let s=this.aabbShape.zpp_inner.polygon;if(s.zip_gaxi&&s.body!=null){s.zip_gaxi=!1,s.validate_laxi();let i=s.body;if(i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),s.zip_gverts&&s.body!=null){s.zip_gverts=!1,s.validate_lverts();let u=s.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let h=s.lverts.next,x=s.gverts.next;for(;x!=null;){let f=x,_=h;h=h.next,f.x=s.body.posx+(s.body.axisy*_.x-s.body.axisx*_.y),f.y=s.body.posy+(_.x*s.body.axisx+_.y*s.body.axisy),x=x.next}}let r=s.edges.head,o=s.gverts.next,a=o;for(o=o.next;o!=null;){let u=o,h=r.elt;r=r.next,h.gp0=a,h.gp1=u,h.gnormx=s.body.axisy*h.lnormx-s.body.axisx*h.lnormy,h.gnormy=h.lnormx*s.body.axisx+h.lnormy*s.body.axisy,h.gprojection=s.body.posx*h.gnormx+s.body.posy*h.gnormy+h.lprojection,h.wrap_gnorm!=null&&(h.wrap_gnorm.zpp_inner.x=h.gnormx,h.wrap_gnorm.zpp_inner.y=h.gnormy),h.tp0=h.gp0.y*h.gnormx-h.gp0.x*h.gnormy,h.tp1=h.gp1.y*h.gnormx-h.gp1.x*h.gnormy,a=u,o=o.next}let p=s.gverts.next,c=r.elt;r=r.next,c.gp0=a,c.gp1=p,c.gnormx=s.body.axisy*c.lnormx-s.body.axisx*c.lnormy,c.gnormy=c.lnormx*s.body.axisx+c.lnormy*s.body.axisy,c.gprojection=s.body.posx*c.gnormx+s.body.posy*c.gnormy+c.lprojection,c.wrap_gnorm!=null&&(c.wrap_gnorm.zpp_inner.x=c.gnormx,c.wrap_gnorm.zpp_inner.y=c.gnormy),c.tp0=c.gp0.y*c.gnormx-c.gp0.x*c.gnormy,c.tp1=c.gp1.y*c.gnormx-c.gp1.x*c.gnormy}}shapesInAABB(e,t,n,l,s){return null}bodiesInAABB(e,t,n,l,s){return null}updateCircShape(e,t,n){let l=Ui._zpp,s=Ui._nape;if(this.circShape==null){l.util.ZPP_Flags.BodyType_STATIC==null&&(l.util.ZPP_Flags.internal=!0,l.util.ZPP_Flags.BodyType_STATIC=new s.phys.BodyType,l.util.ZPP_Flags.internal=!1);let o=new s.phys.Body(l.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,a=e,p=t;if(p==null&&(p=0),a==null&&(a=0),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let c;if(l.util.ZPP_PubPool.poolVec2==null?c=new s.geom.Vec2:(c=l.util.ZPP_PubPool.poolVec2,l.util.ZPP_PubPool.poolVec2=c.zpp_pool,c.zpp_pool=null,c.zpp_disp=!1,c==l.util.ZPP_PubPool.nextVec2&&(l.util.ZPP_PubPool.nextVec2=null)),c.zpp_inner==null){let h;l.geom.ZPP_Vec2.zpp_pool==null?h=new l.geom.ZPP_Vec2:(h=l.geom.ZPP_Vec2.zpp_pool,l.geom.ZPP_Vec2.zpp_pool=h.next,h.next=null),h.weak=!1,h._immutable=!1,h.x=a,h.y=p,c.zpp_inner=h,c.zpp_inner.outer=c}else{if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=c.zpp_inner;if(h._immutable)throw new Error("Error: Vec2 is immutable");if(h._isimmutable!=null&&h._isimmutable(),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let x;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let f=c.zpp_inner;if(f._validate!=null&&f._validate(),c.zpp_inner.x==a){if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let _=c.zpp_inner;_._validate!=null&&_._validate(),x=c.zpp_inner.y==p}else x=!1;if(!x){c.zpp_inner.x=a,c.zpp_inner.y=p;let _=c.zpp_inner;_._invalidate!=null&&_._invalidate(_)}}c.zpp_inner.weak=!1;let u=this.circShape=new s.shape.Circle(n,c);o.zpp_inner.reverse_flag?o.push(u):o.unshift(u)}else{let r=this.circShape.zpp_inner.circle,o=n/r.radius;this.matrix==null&&(this.matrix=new s.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 u=p.zpp_inner.d;if(u!==u)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=u;let h=a.zpp_inner;h._invalidate!=null&&h._invalidate();let x=this.matrix,f=this.matrix;f.zpp_inner.c=0;let _=f.zpp_inner;_._invalidate!=null&&_._invalidate();let d=f.zpp_inner.c;if(d!==d)throw new Error("Error: Mat23::b cannot be NaN");x.zpp_inner.b=d;let b=x.zpp_inner;b._invalidate!=null&&b._invalidate();let m=this.matrix,z=e-o*r.localCOMx;if(z!==z)throw new Error("Error: Mat23::tx cannot be NaN");m.zpp_inner.tx=z;let M=m.zpp_inner;M._invalidate!=null&&M._invalidate();let y=this.matrix,w=t-o*r.localCOMy;if(w!==w)throw new Error("Error: Mat23::ty cannot be NaN");y.zpp_inner.ty=w;let v=y.zpp_inner;v._invalidate!=null&&v._invalidate(),this.circShape.transform(this.matrix)}let i=this.circShape.zpp_inner;if(i.zip_aabb&&i.body!=null)if(i.zip_aabb=!1,i.type==0){let r=i.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 u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let f=h;for(h=h.next;h!=null;){let M=h;u+=f.x*(M.y-x.y);let y=M.y*f.x-M.x*f.y;c.localCOMx+=(f.x+M.x)*y,c.localCOMy+=(f.y+M.y)*y,x=f,f=M,h=h.next}h=c.lverts.next;let _=h;u+=f.x*(_.y-x.y);let d=_.y*f.x-_.x*f.y;c.localCOMx+=(f.x+_.x)*d,c.localCOMy+=(f.y+_.y)*d,x=f,f=_,h=h.next;let b=h;u+=f.x*(b.y-x.y);let m=b.y*f.x-b.x*f.y;c.localCOMx+=(f.x+b.x)*m,c.localCOMy+=(f.y+b.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}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=i.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,u=r.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=r.body.posx+(r.body.axisy*x.x-r.body.axisx*x.y),h.y=r.body.posy+(x.x*r.body.axisx+x.y*r.body.axisy),u=u.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,l,s,i){return null}bodiesInCircle(e,t,n,l,s,i){return null}validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=t.body.posx+(t.body.axisy*h.x-t.body.axisx*h.y),u.y=t.body.posy+(h.x*t.body.axisx+h.y*t.body.axisy),c=c.next}}let l=t.edges.head,s=t.gverts.next,i=s;for(s=s.next;s!=null;){let a=s,p=l.elt;l=l.next,p.gp0=i,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,i=a,s=s.next}let r=t.gverts.next,o=l.elt;l=l.next,o.gp0=i,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 i=t.polygon;if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(i.lverts.next.next==null)i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;else if(i.lverts.next.next.next==null){i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;let r=1;i.localCOMx+=i.lverts.next.next.x*r,i.localCOMy+=i.lverts.next.next.y*r;let o=.5;i.localCOMx*=o,i.localCOMy*=o}else{i.localCOMx=0,i.localCOMy=0;let r=0,o=i.lverts.next,a=o;o=o.next;let p=o;for(o=o.next;o!=null;){let _=o;r+=p.x*(_.y-a.y);let d=_.y*p.x-_.x*p.y;i.localCOMx+=(p.x+_.x)*d,i.localCOMy+=(p.y+_.y)*d,a=p,p=_,o=o.next}o=i.lverts.next;let c=o;r+=p.x*(c.y-a.y);let u=c.y*p.x-c.x*p.y;i.localCOMx+=(p.x+c.x)*u,i.localCOMy+=(p.y+c.y)*u,a=p,p=c,o=o.next;let h=o;r+=p.x*(h.y-a.y);let x=h.y*p.x-h.x*p.y;i.localCOMx+=(p.x+h.x)*x,i.localCOMy+=(p.y+h.y)*x,r=1/(3*r);let f=r;i.localCOMx*=f,i.localCOMy*=f}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,r=t.gverts.next;for(;r!=null;){let o=r,a=i;i=i.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 l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let l=1;n.localCOMx+=n.lverts.next.next.x*l,n.localCOMy+=n.lverts.next.next.y*l;let s=.5;n.localCOMx*=s,n.localCOMy*=s}else{n.localCOMx=0,n.localCOMy=0;let l=0,s=n.lverts.next,i=s;s=s.next;let r=s;for(s=s.next;s!=null;){let h=s;l+=r.x*(h.y-i.y);let x=h.y*r.x-h.x*r.y;n.localCOMx+=(r.x+h.x)*x,n.localCOMy+=(r.y+h.y)*x,i=r,r=h,s=s.next}s=n.lverts.next;let o=s;l+=r.x*(o.y-i.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,i=r,r=o,s=s.next;let p=s;l+=r.x*(p.y-i.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,l=1/(3*l);let u=l;n.localCOMx*=u,n.localCOMy*=u}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}shapesInShape(e,t,n,l){return null}bodiesInShape(e,t,n,l){return null}rayCast(e,t,n){return null}rayMultiCast(e,t,n,l){return null}};Ui.__name__=["zpp_nape","space","ZPP_Broadphase"],Ui._zpp=null,Ui._nape=null;var us=Ui;var Ve=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}};Ve.__name__=["zpp_nape","space","ZPP_AABBNode"],Ve.zpp_pool=null;var at=class{constructor(){this.n1=null;this.n2=null;this.first=!1;this.sleeping=!1;this.id=0;this.di=0;this.arb=null;this.next=null}alloc(){}free(){this.n1=this.n2=null,this.sleeping=!1}};at.__name__=["zpp_nape","space","ZPP_AABBPair"],at.zpp_pool=null;var jt=class jt{constructor(){this.root=null}static _initStatics(){jt.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 l=n;l.height=-1;let s=l.aabb;s.outer!=null&&(s.outer.zpp_inner=null,s.outer=null),s.wrap_min=s.wrap_max=null,s._invalidate=null,s._validate=null,s.next=fe.zpp_pool,fe.zpp_pool=s,l.child1=l.child2=l.parent=null,l.next=null,l.snext=null,l.mnext=null,l.next=Ve.zpp_pool,Ve.zpp_pool=l}this.root=null}insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else{let t=e.aabb,n=this.root;for(;n.child1!=null;){let a=n.child1,p=n.child2,c=n.aabb,u=(c.maxx-c.minx+(c.maxy-c.miny))*2,h=jt.tmpaabb,x=n.aabb;h.minx=x.minx<t.minx?x.minx:t.minx,h.miny=x.miny<t.miny?x.miny:t.miny,h.maxx=x.maxx>t.maxx?x.maxx:t.maxx,h.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let f=jt.tmpaabb,_=(f.maxx-f.minx+(f.maxy-f.miny))*2,d=2*_,b=2*(_-u),m=jt.tmpaabb,z=a.aabb;m.minx=t.minx<z.minx?t.minx:z.minx,m.miny=t.miny<z.miny?t.miny:z.miny,m.maxx=t.maxx>z.maxx?t.maxx:z.maxx,m.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let M;if(a.child1==null){let P=jt.tmpaabb;M=(P.maxx-P.minx+(P.maxy-P.miny))*2+b}else{let P=a.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,E=jt.tmpaabb;M=(E.maxx-E.minx+(E.maxy-E.miny))*2-g+b}let y=jt.tmpaabb,w=p.aabb;y.minx=t.minx<w.minx?t.minx:w.minx,y.miny=t.miny<w.miny?t.miny:w.miny,y.maxx=t.maxx>w.maxx?t.maxx:w.maxx,y.maxy=t.maxy>w.maxy?t.maxy:w.maxy;let v;if(p.child1==null){let P=jt.tmpaabb;v=(P.maxx-P.minx+(P.maxy-P.miny))*2+b}else{let P=p.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,E=jt.tmpaabb;v=(E.maxx-E.minx+(E.maxy-E.miny))*2-g+b}if(d<M&&d<v)break;n=M<v?a:p}let l=n,s=l.parent,i;Ve.zpp_pool==null?i=new Ve:(i=Ve.zpp_pool,Ve.zpp_pool=i.next,i.next=null),fe.zpp_pool==null?i.aabb=new fe:(i.aabb=fe.zpp_pool,fe.zpp_pool=i.aabb.next,i.aabb.next=null),i.moved=!1,i.synced=!1,i.first_sync=!1,i.parent=s;let r=i.aabb,o=l.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,i.height=l.height+1,s!=null?(s.child1==l?s.child1=i:s.child2=i,i.child1=l,i.child2=e,l.parent=i,e.parent=i):(i.child1=l,i.child2=e,l.parent=i,e.parent=i,this.root=i),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let _=n.child1,d=n.child2,b=d.height-_.height;if(b>1){let m=d.child1,z=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,n.child2=z,z.parent=n;let M=n.aabb,y=_.aabb,w=z.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=_.height,N=z.height;n.height=1+(E>N?E:N);let k=n.height,Z=m.height;d.height=1+(k>Z?k:Z)}else{d.child2=z,n.child2=m,m.parent=n;let M=n.aabb,y=_.aabb,w=m.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=_.height,N=m.height;n.height=1+(E>N?E:N);let k=n.height,Z=z.height;d.height=1+(k>Z?k:Z)}n=d}else if(b<-1){let m=_.child1,z=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,n.child1=z,z.parent=n;let M=n.aabb,y=d.aabb,w=z.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=d.height,N=z.height;n.height=1+(E>N?E:N);let k=n.height,Z=m.height;_.height=1+(k>Z?k:Z)}else{_.child2=z,n.child1=m,m.parent=n;let M=n.aabb,y=d.aabb,w=m.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=d.height,N=m.height;n.height=1+(E>N?E:N);let k=n.height,Z=z.height;_.height=1+(k>Z?k:Z)}n=_}else n=n}let a=n.child1,p=n.child2,c=a.height,u=p.height;n.height=1+(c>u?c:u);let h=n.aabb,x=a.aabb,f=p.aabb;h.minx=x.minx<f.minx?x.minx:f.minx,h.miny=x.miny<f.miny?x.miny:f.miny,h.maxx=x.maxx>f.maxx?x.maxx:f.maxx,h.maxy=x.maxy>f.maxy?x.maxy:f.maxy,n=n.parent}}}inlined_insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else{let t=e.aabb,n=this.root;for(;n.child1!=null;){let a=n.child1,p=n.child2,c=n.aabb,u=(c.maxx-c.minx+(c.maxy-c.miny))*2,h=jt.tmpaabb,x=n.aabb;h.minx=x.minx<t.minx?x.minx:t.minx,h.miny=x.miny<t.miny?x.miny:t.miny,h.maxx=x.maxx>t.maxx?x.maxx:t.maxx,h.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let f=jt.tmpaabb,_=(f.maxx-f.minx+(f.maxy-f.miny))*2,d=2*_,b=2*(_-u),m=jt.tmpaabb,z=a.aabb;m.minx=t.minx<z.minx?t.minx:z.minx,m.miny=t.miny<z.miny?t.miny:z.miny,m.maxx=t.maxx>z.maxx?t.maxx:z.maxx,m.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let M;if(a.child1==null){let P=jt.tmpaabb;M=(P.maxx-P.minx+(P.maxy-P.miny))*2+b}else{let P=a.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,E=jt.tmpaabb;M=(E.maxx-E.minx+(E.maxy-E.miny))*2-g+b}let y=jt.tmpaabb,w=p.aabb;y.minx=t.minx<w.minx?t.minx:w.minx,y.miny=t.miny<w.miny?t.miny:w.miny,y.maxx=t.maxx>w.maxx?t.maxx:w.maxx,y.maxy=t.maxy>w.maxy?t.maxy:w.maxy;let v;if(p.child1==null){let P=jt.tmpaabb;v=(P.maxx-P.minx+(P.maxy-P.miny))*2+b}else{let P=p.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,E=jt.tmpaabb;v=(E.maxx-E.minx+(E.maxy-E.miny))*2-g+b}if(d<M&&d<v)break;n=M<v?a:p}let l=n,s=l.parent,i;Ve.zpp_pool==null?i=new Ve:(i=Ve.zpp_pool,Ve.zpp_pool=i.next,i.next=null),fe.zpp_pool==null?i.aabb=new fe:(i.aabb=fe.zpp_pool,fe.zpp_pool=i.aabb.next,i.aabb.next=null),i.moved=!1,i.synced=!1,i.first_sync=!1,i.parent=s;let r=i.aabb,o=l.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,i.height=l.height+1,s!=null?(s.child1==l?s.child1=i:s.child2=i,i.child1=l,i.child2=e,l.parent=i,e.parent=i):(i.child1=l,i.child2=e,l.parent=i,e.parent=i,this.root=i),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let _=n.child1,d=n.child2,b=d.height-_.height;if(b>1){let m=d.child1,z=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,n.child2=z,z.parent=n;let M=n.aabb,y=_.aabb,w=z.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=_.height,N=z.height;n.height=1+(E>N?E:N);let k=n.height,Z=m.height;d.height=1+(k>Z?k:Z)}else{d.child2=z,n.child2=m,m.parent=n;let M=n.aabb,y=_.aabb,w=m.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=_.height,N=m.height;n.height=1+(E>N?E:N);let k=n.height,Z=z.height;d.height=1+(k>Z?k:Z)}n=d}else if(b<-1){let m=_.child1,z=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,n.child1=z,z.parent=n;let M=n.aabb,y=d.aabb,w=z.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=d.height,N=z.height;n.height=1+(E>N?E:N);let k=n.height,Z=m.height;_.height=1+(k>Z?k:Z)}else{_.child2=z,n.child1=m,m.parent=n;let M=n.aabb,y=d.aabb,w=m.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=d.height,N=m.height;n.height=1+(E>N?E:N);let k=n.height,Z=z.height;_.height=1+(k>Z?k:Z)}n=_}else n=n}let a=n.child1,p=n.child2,c=a.height,u=p.height;n.height=1+(c>u?c:u);let h=n.aabb,x=a.aabb,f=p.aabb;h.minx=x.minx<f.minx?x.minx:f.minx,h.miny=x.miny<f.miny?x.miny:f.miny,h.maxx=x.maxx>f.maxx?x.maxx:f.maxx,h.maxy=x.maxy>f.maxy?x.maxy:f.maxy,n=n.parent}}}removeLeaf(e){if(e==this.root)this.root=null;else{let t=e.parent,n=t.parent,l=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=l:n.child2=l,l.parent=n;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=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=Ve.zpp_pool,Ve.zpp_pool=s;let r=n;for(;r!=null;){if(r.child1==null||r.height<2)r=r;else{let _=r.child1,d=r.child2,b=d.height-_.height;if(b>1){let m=d.child1,z=d.child2;if(d.child1=r,d.parent=r.parent,r.parent=d,d.parent!=null?d.parent.child1==r?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,r.child2=z,z.parent=r;let M=r.aabb,y=_.aabb,w=z.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=r.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=_.height,N=z.height;r.height=1+(E>N?E:N);let k=r.height,Z=m.height;d.height=1+(k>Z?k:Z)}else{d.child2=z,r.child2=m,m.parent=r;let M=r.aabb,y=_.aabb,w=m.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=r.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=_.height,N=m.height;r.height=1+(E>N?E:N);let k=r.height,Z=z.height;d.height=1+(k>Z?k:Z)}r=d}else if(b<-1){let m=_.child1,z=_.child2;if(_.child1=r,_.parent=r.parent,r.parent=_,_.parent!=null?_.parent.child1==r?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,r.child1=z,z.parent=r;let M=r.aabb,y=d.aabb,w=z.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=r.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=d.height,N=z.height;r.height=1+(E>N?E:N);let k=r.height,Z=m.height;_.height=1+(k>Z?k:Z)}else{_.child2=z,r.child1=m,m.parent=r;let M=r.aabb,y=d.aabb,w=m.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=r.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=d.height,N=m.height;r.height=1+(E>N?E:N);let k=r.height,Z=z.height;_.height=1+(k>Z?k:Z)}r=_}else r=r}let o=r,a=o.child1,p=o.child2,c=o.aabb,u=a.aabb,h=p.aabb;c.minx=u.minx<h.minx?u.minx:h.minx,c.miny=u.miny<h.miny?u.miny:h.miny,c.maxx=u.maxx>h.maxx?u.maxx:h.maxx,c.maxy=u.maxy>h.maxy?u.maxy:h.maxy;let x=a.height,f=p.height;o.height=1+(x>f?x:f),r=o.parent}}else{this.root=l,l.parent=null;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=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=Ve.zpp_pool,Ve.zpp_pool=s}}}inlined_removeLeaf(e){if(e==this.root){this.root=null;return}else{let t=e.parent,n=t.parent,l=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=l:n.child2=l,l.parent=n;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=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=Ve.zpp_pool,Ve.zpp_pool=s;let r=n;for(;r!=null;){if(r.child1==null||r.height<2)r=r;else{let _=r.child1,d=r.child2,b=d.height-_.height;if(b>1){let m=d.child1,z=d.child2;if(d.child1=r,d.parent=r.parent,r.parent=d,d.parent!=null?d.parent.child1==r?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,r.child2=z,z.parent=r;let M=r.aabb,y=_.aabb,w=z.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=r.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=_.height,N=z.height;r.height=1+(E>N?E:N);let k=r.height,Z=m.height;d.height=1+(k>Z?k:Z)}else{d.child2=z,r.child2=m,m.parent=r;let M=r.aabb,y=_.aabb,w=m.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=r.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=_.height,N=m.height;r.height=1+(E>N?E:N);let k=r.height,Z=z.height;d.height=1+(k>Z?k:Z)}r=d}else if(b<-1){let m=_.child1,z=_.child2;if(_.child1=r,_.parent=r.parent,r.parent=_,_.parent!=null?_.parent.child1==r?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,r.child1=z,z.parent=r;let M=r.aabb,y=d.aabb,w=z.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=r.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=d.height,N=z.height;r.height=1+(E>N?E:N);let k=r.height,Z=m.height;_.height=1+(k>Z?k:Z)}else{_.child2=z,r.child1=m,m.parent=r;let M=r.aabb,y=d.aabb,w=m.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=r.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let E=d.height,N=m.height;r.height=1+(E>N?E:N);let k=r.height,Z=z.height;_.height=1+(k>Z?k:Z)}r=_}else r=r}let o=r,a=o.child1,p=o.child2,c=o.aabb,u=a.aabb,h=p.aabb;c.minx=u.minx<h.minx?u.minx:h.minx,c.miny=u.miny<h.miny?u.miny:h.miny,c.maxx=u.maxx>h.maxx?u.maxx:h.maxx,c.maxy=u.maxy>h.maxy?u.maxy:h.maxy;let x=a.height,f=p.height;o.height=1+(x>f?x:f),r=o.parent}}else{this.root=l,l.parent=null;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=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=Ve.zpp_pool,Ve.zpp_pool=s}}}balance(e){if(e.child1==null||e.height<2)return e;{let t=e.child1,n=e.child2,l=n.height-t.height;if(l>1){let s=n.child1,i=n.child2;if(n.child1=e,n.parent=e.parent,e.parent=n,n.parent!=null?n.parent.child1==e?n.parent.child1=n:n.parent.child2=n:this.root=n,s.height>i.height){n.child2=s,e.child2=i,i.parent=e;let 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,u=s.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=t.height,x=i.height;e.height=1+(h>x?h:x);let f=e.height,_=s.height;n.height=1+(f>_?f:_)}else{n.child2=i,e.child2=s,s.parent=e;let r=e.aabb,o=t.aabb,a=s.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,u=i.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=t.height,x=s.height;e.height=1+(h>x?h:x);let f=e.height,_=i.height;n.height=1+(f>_?f:_)}return n}else if(l<-1){let s=t.child1,i=t.child2;if(t.child1=e,t.parent=e.parent,e.parent=t,t.parent!=null?t.parent.child1==e?t.parent.child1=t:t.parent.child2=t:this.root=t,s.height>i.height){t.child2=s,e.child1=i,i.parent=e;let 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,u=s.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=n.height,x=i.height;e.height=1+(h>x?h:x);let f=e.height,_=s.height;t.height=1+(f>_?f:_)}else{t.child2=i,e.child1=s,s.parent=e;let r=e.aabb,o=n.aabb,a=s.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,u=i.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=n.height,x=s.height;e.height=1+(h>x?h:x);let f=e.height,_=i.height;t.height=1+(f>_?f:_)}return t}else return e}}};jt.__name__=["zpp_nape","space","ZPP_AABBTree"],jt.tmpaabb=null;var pt=jt;var be=class be{constructor(e){this.pairs=null;this.syncs=null;this.moves=null;this.treeStack=null;this.treeStack2=null;this.failed=null;this.openlist=null;this.space=null;this.is_sweep=!1;this.sweep=null;this.dynab=null;this.aabbShape=null;this.matrix=null;this.circShape=null;this.__class__=be;us._initFields(this),this.space=e,this.is_sweep=!1,this.dynab=this,this.stree=new pt,this.dtree=new pt}static _init(){be.__super__=be._zpp.space.ZPP_Broadphase;let e=be._zpp.space.ZPP_Broadphase.prototype;Object.getOwnPropertyNames(e).forEach(t=>{t!=="constructor"&&!(t in be.prototype)&&(be.prototype[t]=e[t])})}dyn(e){return e.body.type==1?!1:!e.body.component.sleeping}__insert(e){let t;Ve.zpp_pool==null?t=new Ve:(t=Ve.zpp_pool,Ve.zpp_pool=t.next,t.next=null),fe.zpp_pool==null?t.aabb=new fe:(t.aabb=fe.zpp_pool,fe.zpp_pool=t.aabb.next,t.aabb.next=null),t.moved=!1,t.synced=!1,t.first_sync=!1,t.shape=e,e.node=t,t.synced=!0,t.first_sync=!0,t.snext=this.syncs,this.syncs=t}__remove(e){let t=e.node;if(t.first_sync||(t.dyn?this.dtree.removeLeaf(t):this.stree.removeLeaf(t)),e.node=null,t.synced){let r=null,o=this.syncs;for(;o!=null&&o!=t;)r=o,o=o.snext;r==null?this.syncs=o.snext:r.snext=o.snext,o.snext=null,t.synced=!1}if(t.moved){let r=null,o=this.moves;for(;o!=null&&o!=t;)r=o,o=o.mnext;r==null?this.moves=o.mnext:r.mnext=o.mnext,o.mnext=null,t.moved=!1}let n=null,l=this.pairs;for(;l!=null;){let r=l.next;if(l.n1==t||l.n2==t){n==null?this.pairs=r:n.next=r,l.arb!=null&&(l.arb.pair=null),l.arb=null,l.n1.shape.pairs.remove(l),l.n2.shape.pairs.remove(l);let o=l;o.n1=o.n2=null,o.sleeping=!1,o.next=at.zpp_pool,at.zpp_pool=o,l=r;continue}n=l,l=r}for(;e.pairs.head!=null;){let r=e.pairs.pop_unsafe();r.n1==t?r.n2.shape.pairs.remove(r):r.n1.shape.pairs.remove(r),r.arb!=null&&(r.arb.pair=null),r.arb=null;let o=r;o.n1=o.n2=null,o.sleeping=!1,o.next=at.zpp_pool,at.zpp_pool=o}let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=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=Ve.zpp_pool,Ve.zpp_pool=s}__sync(e){let t=e.node;if(!t.synced){if(!this.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let l=e.circle;if(l.zip_worldCOM&&l.body!=null){if(l.zip_worldCOM=!1,l.zip_localCOM){if(l.zip_localCOM=!1,l.type==1){let o=l.polygon;if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(o.lverts.next.next==null)o.localCOMx=o.lverts.next.x,o.localCOMy=o.lverts.next.y;else if(o.lverts.next.next.next==null){o.localCOMx=o.lverts.next.x,o.localCOMy=o.lverts.next.y;let a=1;o.localCOMx+=o.lverts.next.next.x*a,o.localCOMy+=o.lverts.next.next.y*a;let p=.5;o.localCOMx*=p,o.localCOMy*=p}else{o.localCOMx=0,o.localCOMy=0;let a=0,p=o.lverts.next,c=p;p=p.next;let u=p;for(p=p.next;p!=null;){let b=p;a+=u.x*(b.y-c.y);let m=b.y*u.x-b.x*u.y;o.localCOMx+=(u.x+b.x)*m,o.localCOMy+=(u.y+b.y)*m,c=u,u=b,p=p.next}p=o.lverts.next;let h=p;a+=u.x*(h.y-c.y);let x=h.y*u.x-h.x*u.y;o.localCOMx+=(u.x+h.x)*x,o.localCOMy+=(u.y+h.y)*x,c=u,u=h,p=p.next;let f=p;a+=u.x*(f.y-c.y);let _=f.y*u.x-f.x*u.y;o.localCOMx+=(u.x+f.x)*_,o.localCOMy+=(u.y+f.y)*_,a=1/(3*a);let d=a;o.localCOMx*=d,o.localCOMy*=d}}l.wrap_localCOM!=null&&(l.wrap_localCOM.zpp_inner.x=l.localCOMx,l.wrap_localCOM.zpp_inner.y=l.localCOMy)}let r=l.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),l.worldCOMx=l.body.posx+(l.body.axisy*l.localCOMx-l.body.axisx*l.localCOMy),l.worldCOMy=l.body.posy+(l.localCOMx*l.body.axisx+l.localCOMy*l.body.axisy)}let s=l.radius,i=l.radius;l.aabb.minx=l.worldCOMx-s,l.aabb.miny=l.worldCOMy-i,l.aabb.maxx=l.worldCOMx+s,l.aabb.maxy=l.worldCOMy+i}else{let l=e.polygon;if(l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let r=l.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let o=l.lverts.next,a=l.gverts.next;for(;a!=null;){let p=a,c=o;o=o.next,p.x=l.body.posx+(l.body.axisy*c.x-l.body.axisx*c.y),p.y=l.body.posy+(c.x*l.body.axisx+c.y*l.body.axisy),a=a.next}}if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let s=l.gverts.next;l.aabb.minx=s.x,l.aabb.miny=s.y,l.aabb.maxx=s.x,l.aabb.maxy=s.y;let i=l.gverts.next.next;for(;i!=null;){let r=i;r.x<l.aabb.minx&&(l.aabb.minx=r.x),r.x>l.aabb.maxx&&(l.aabb.maxx=r.x),r.y<l.aabb.miny&&(l.aabb.miny=r.y),r.y>l.aabb.maxy&&(l.aabb.maxy=r.y),i=i.next}}let n;if(t.dyn==(e.body.type==1?!1:!e.body.component.sleeping)){let l=t.aabb,s=e.aabb;n=!(s.minx>=l.minx&&s.miny>=l.miny&&s.maxx<=l.maxx&&s.maxy<=l.maxy)}else n=!0;n&&(t.synced=!0,t.snext=this.syncs,this.syncs=t)}}sync_broadphase(){if(this.space.validation(),this.syncs!=null)if(this.moves==null){let e=this.syncs;for(;e!=null;){let n=e.shape;if(e.first_sync)e.first_sync=!1;else{let r=e.dyn?this.dtree:this.stree;if(e==r.root)r.root=null;else{let o=e.parent,a=o.parent,p=o.child1==e?o.child2:o.child1;if(a!=null){a.child1==o?a.child1=p:a.child2=p,p.parent=a;let c=o;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=fe.zpp_pool,fe.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Ve.zpp_pool,Ve.zpp_pool=c;let h=a;for(;h!=null;){if(h.child1==null||h.height<2)h=h;else{let M=h.child1,y=h.child2,w=y.height-M.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=h,y.parent=h.parent,h.parent=y,y.parent!=null?y.parent.child1==h?y.parent.child1=y:y.parent.child2=y:r.root=y,v.height>P.height){y.child2=v,h.child2=P,P.parent=h;let g=h.aabb,E=M.aabb,N=P.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=y.aabb,Z=h.aabb,C=v.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=M.height,O=P.height;h.height=1+(F>O?F:O);let B=h.height,D=v.height;y.height=1+(B>D?B:D)}else{y.child2=P,h.child2=v,v.parent=h;let g=h.aabb,E=M.aabb,N=v.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=y.aabb,Z=h.aabb,C=P.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=M.height,O=v.height;h.height=1+(F>O?F:O);let B=h.height,D=P.height;y.height=1+(B>D?B:D)}h=y}else if(w<-1){let v=M.child1,P=M.child2;if(M.child1=h,M.parent=h.parent,h.parent=M,M.parent!=null?M.parent.child1==h?M.parent.child1=M:M.parent.child2=M:r.root=M,v.height>P.height){M.child2=v,h.child1=P,P.parent=h;let g=h.aabb,E=y.aabb,N=P.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=M.aabb,Z=h.aabb,C=v.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=y.height,O=P.height;h.height=1+(F>O?F:O);let B=h.height,D=v.height;M.height=1+(B>D?B:D)}else{M.child2=P,h.child1=v,v.parent=h;let g=h.aabb,E=y.aabb,N=v.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=M.aabb,Z=h.aabb,C=P.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=y.height,O=v.height;h.height=1+(F>O?F:O);let B=h.height,D=P.height;M.height=1+(B>D?B:D)}h=M}else h=h}let x=h.child1,f=h.child2,_=h.aabb,d=x.aabb,b=f.aabb;_.minx=d.minx<b.minx?d.minx:b.minx,_.miny=d.miny<b.miny?d.miny:b.miny,_.maxx=d.maxx>b.maxx?d.maxx:b.maxx,_.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let m=x.height,z=f.height;h.height=1+(m>z?m:z),h=h.parent}}else{r.root=p,p.parent=null;let c=o;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=fe.zpp_pool,fe.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Ve.zpp_pool,Ve.zpp_pool=c}}}let l=e.aabb;if(!this.space.continuous&&n.zip_aabb&&n.body!=null)if(n.zip_aabb=!1,n.type==0){let r=n.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 u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let f=h;for(h=h.next;h!=null;){let M=h;u+=f.x*(M.y-x.y);let y=M.y*f.x-M.x*f.y;c.localCOMx+=(f.x+M.x)*y,c.localCOMy+=(f.y+M.y)*y,x=f,f=M,h=h.next}h=c.lverts.next;let _=h;u+=f.x*(_.y-x.y);let d=_.y*f.x-_.x*f.y;c.localCOMx+=(f.x+_.x)*d,c.localCOMy+=(f.y+_.y)*d,x=f,f=_,h=h.next;let b=h;u+=f.x*(b.y-x.y);let m=b.y*f.x-b.x*f.y;c.localCOMx+=(f.x+b.x)*m,c.localCOMy+=(f.y+b.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}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=n.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,u=r.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=r.body.posx+(r.body.axisy*x.x-r.body.axisx*x.y),h.y=r.body.posy+(x.x*r.body.axisx+x.y*r.body.axisy),u=u.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 s=n.aabb;l.minx=s.minx-3,l.miny=s.miny-3,l.maxx=s.maxx+3,l.maxy=s.maxy+3;let i=(e.dyn=n.body.type==1?!1:!n.body.component.sleeping)?this.dtree:this.stree;if(i.root==null)i.root=e,i.root.parent=null;else{let r=e.aabb,o=i.root;for(;o.child1!=null;){let x=o.child1,f=o.child2,_=o.aabb,d=(_.maxx-_.minx+(_.maxy-_.miny))*2,b=pt.tmpaabb,m=o.aabb;b.minx=m.minx<r.minx?m.minx:r.minx,b.miny=m.miny<r.miny?m.miny:r.miny,b.maxx=m.maxx>r.maxx?m.maxx:r.maxx,b.maxy=m.maxy>r.maxy?m.maxy:r.maxy;let z=pt.tmpaabb,M=(z.maxx-z.minx+(z.maxy-z.miny))*2,y=2*M,w=2*(M-d),v=pt.tmpaabb,P=x.aabb;v.minx=r.minx<P.minx?r.minx:P.minx,v.miny=r.miny<P.miny?r.miny:P.miny,v.maxx=r.maxx>P.maxx?r.maxx:P.maxx,v.maxy=r.maxy>P.maxy?r.maxy:P.maxy;let g;if(x.child1==null){let Z=pt.tmpaabb;g=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+w}else{let Z=x.aabb,C=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,F=pt.tmpaabb;g=(F.maxx-F.minx+(F.maxy-F.miny))*2-C+w}let E=pt.tmpaabb,N=f.aabb;E.minx=r.minx<N.minx?r.minx:N.minx,E.miny=r.miny<N.miny?r.miny:N.miny,E.maxx=r.maxx>N.maxx?r.maxx:N.maxx,E.maxy=r.maxy>N.maxy?r.maxy:N.maxy;let k;if(f.child1==null){let Z=pt.tmpaabb;k=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+w}else{let Z=f.aabb,C=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,F=pt.tmpaabb;k=(F.maxx-F.minx+(F.maxy-F.miny))*2-C+w}if(y<g&&y<k)break;o=g<k?x:f}let a=o,p=a.parent,c;Ve.zpp_pool==null?c=new Ve:(c=Ve.zpp_pool,Ve.zpp_pool=c.next,c.next=null),fe.zpp_pool==null?c.aabb=new fe:(c.aabb=fe.zpp_pool,fe.zpp_pool=c.aabb.next,c.aabb.next=null),c.moved=!1,c.synced=!1,c.first_sync=!1,c.parent=p;let u=c.aabb,h=a.aabb;for(u.minx=r.minx<h.minx?r.minx:h.minx,u.miny=r.miny<h.miny?r.miny:h.miny,u.maxx=r.maxx>h.maxx?r.maxx:h.maxx,u.maxy=r.maxy>h.maxy?r.maxy:h.maxy,c.height=a.height+1,p!=null?(p.child1==a?p.child1=c:p.child2=c,c.child1=a,c.child2=e,a.parent=c,e.parent=c):(c.child1=a,c.child2=e,a.parent=c,e.parent=c,i.root=c),o=e.parent;o!=null;){if(o.child1==null||o.height<2)o=o;else{let M=o.child1,y=o.child2,w=y.height-M.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=o,y.parent=o.parent,o.parent=y,y.parent!=null?y.parent.child1==o?y.parent.child1=y:y.parent.child2=y:i.root=y,v.height>P.height){y.child2=v,o.child2=P,P.parent=o;let g=o.aabb,E=M.aabb,N=P.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=y.aabb,Z=o.aabb,C=v.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=M.height,O=P.height;o.height=1+(F>O?F:O);let B=o.height,D=v.height;y.height=1+(B>D?B:D)}else{y.child2=P,o.child2=v,v.parent=o;let g=o.aabb,E=M.aabb,N=v.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=y.aabb,Z=o.aabb,C=P.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=M.height,O=v.height;o.height=1+(F>O?F:O);let B=o.height,D=P.height;y.height=1+(B>D?B:D)}o=y}else if(w<-1){let v=M.child1,P=M.child2;if(M.child1=o,M.parent=o.parent,o.parent=M,M.parent!=null?M.parent.child1==o?M.parent.child1=M:M.parent.child2=M:i.root=M,v.height>P.height){M.child2=v,o.child1=P,P.parent=o;let g=o.aabb,E=y.aabb,N=P.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=M.aabb,Z=o.aabb,C=v.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=y.height,O=P.height;o.height=1+(F>O?F:O);let B=o.height,D=v.height;M.height=1+(B>D?B:D)}else{M.child2=P,o.child1=v,v.parent=o;let g=o.aabb,E=y.aabb,N=v.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=M.aabb,Z=o.aabb,C=P.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=y.height,O=v.height;o.height=1+(F>O?F:O);let B=o.height,D=P.height;M.height=1+(B>D?B:D)}o=M}else o=o}let x=o.child1,f=o.child2,_=x.height,d=f.height;o.height=1+(_>d?_:d);let b=o.aabb,m=x.aabb,z=f.aabb;b.minx=m.minx<z.minx?m.minx:z.minx,b.miny=m.miny<z.miny?m.miny:z.miny,b.maxx=m.maxx>z.maxx?m.maxx:z.maxx,b.maxy=m.maxy>z.maxy?m.maxy:z.maxy,o=o.parent}}e.synced=!1,e.moved=!0,e.mnext=e.snext,e.snext=null,e=e.mnext}let t=this.syncs;this.syncs=this.moves,this.moves=t}else for(;this.syncs!=null;){let e=this.syncs;this.syncs=e.snext,e.snext=null;let t=e,n=t.shape;if(t.first_sync)t.first_sync=!1;else{let r=t.dyn?this.dtree:this.stree;if(t==r.root)r.root=null;else{let o=t.parent,a=o.parent,p=o.child1==t?o.child2:o.child1;if(a!=null){a.child1==o?a.child1=p:a.child2=p,p.parent=a;let c=o;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=fe.zpp_pool,fe.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Ve.zpp_pool,Ve.zpp_pool=c;let h=a;for(;h!=null;){if(h.child1==null||h.height<2)h=h;else{let M=h.child1,y=h.child2,w=y.height-M.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=h,y.parent=h.parent,h.parent=y,y.parent!=null?y.parent.child1==h?y.parent.child1=y:y.parent.child2=y:r.root=y,v.height>P.height){y.child2=v,h.child2=P,P.parent=h;let g=h.aabb,E=M.aabb,N=P.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=y.aabb,Z=h.aabb,C=v.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=M.height,O=P.height;h.height=1+(F>O?F:O);let B=h.height,D=v.height;y.height=1+(B>D?B:D)}else{y.child2=P,h.child2=v,v.parent=h;let g=h.aabb,E=M.aabb,N=v.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=y.aabb,Z=h.aabb,C=P.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=M.height,O=v.height;h.height=1+(F>O?F:O);let B=h.height,D=P.height;y.height=1+(B>D?B:D)}h=y}else if(w<-1){let v=M.child1,P=M.child2;if(M.child1=h,M.parent=h.parent,h.parent=M,M.parent!=null?M.parent.child1==h?M.parent.child1=M:M.parent.child2=M:r.root=M,v.height>P.height){M.child2=v,h.child1=P,P.parent=h;let g=h.aabb,E=y.aabb,N=P.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=M.aabb,Z=h.aabb,C=v.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=y.height,O=P.height;h.height=1+(F>O?F:O);let B=h.height,D=v.height;M.height=1+(B>D?B:D)}else{M.child2=P,h.child1=v,v.parent=h;let g=h.aabb,E=y.aabb,N=v.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=M.aabb,Z=h.aabb,C=P.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=y.height,O=v.height;h.height=1+(F>O?F:O);let B=h.height,D=P.height;M.height=1+(B>D?B:D)}h=M}else h=h}let x=h.child1,f=h.child2,_=h.aabb,d=x.aabb,b=f.aabb;_.minx=d.minx<b.minx?d.minx:b.minx,_.miny=d.miny<b.miny?d.miny:b.miny,_.maxx=d.maxx>b.maxx?d.maxx:b.maxx,_.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let m=x.height,z=f.height;h.height=1+(m>z?m:z),h=h.parent}}else{r.root=p,p.parent=null;let c=o;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=fe.zpp_pool,fe.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Ve.zpp_pool,Ve.zpp_pool=c}}}let l=t.aabb;if(!this.space.continuous&&n.zip_aabb&&n.body!=null)if(n.zip_aabb=!1,n.type==0){let r=n.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 u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let f=h;for(h=h.next;h!=null;){let M=h;u+=f.x*(M.y-x.y);let y=M.y*f.x-M.x*f.y;c.localCOMx+=(f.x+M.x)*y,c.localCOMy+=(f.y+M.y)*y,x=f,f=M,h=h.next}h=c.lverts.next;let _=h;u+=f.x*(_.y-x.y);let d=_.y*f.x-_.x*f.y;c.localCOMx+=(f.x+_.x)*d,c.localCOMy+=(f.y+_.y)*d,x=f,f=_,h=h.next;let b=h;u+=f.x*(b.y-x.y);let m=b.y*f.x-b.x*f.y;c.localCOMx+=(f.x+b.x)*m,c.localCOMy+=(f.y+b.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}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=n.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,u=r.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=r.body.posx+(r.body.axisy*x.x-r.body.axisx*x.y),h.y=r.body.posy+(x.x*r.body.axisx+x.y*r.body.axisy),u=u.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 s=n.aabb;l.minx=s.minx-3,l.miny=s.miny-3,l.maxx=s.maxx+3,l.maxy=s.maxy+3;let i=(t.dyn=n.body.type==1?!1:!n.body.component.sleeping)?this.dtree:this.stree;if(i.root==null)i.root=t,i.root.parent=null;else{let r=t.aabb,o=i.root;for(;o.child1!=null;){let x=o.child1,f=o.child2,_=o.aabb,d=(_.maxx-_.minx+(_.maxy-_.miny))*2,b=pt.tmpaabb,m=o.aabb;b.minx=m.minx<r.minx?m.minx:r.minx,b.miny=m.miny<r.miny?m.miny:r.miny,b.maxx=m.maxx>r.maxx?m.maxx:r.maxx,b.maxy=m.maxy>r.maxy?m.maxy:r.maxy;let z=pt.tmpaabb,M=(z.maxx-z.minx+(z.maxy-z.miny))*2,y=2*M,w=2*(M-d),v=pt.tmpaabb,P=x.aabb;v.minx=r.minx<P.minx?r.minx:P.minx,v.miny=r.miny<P.miny?r.miny:P.miny,v.maxx=r.maxx>P.maxx?r.maxx:P.maxx,v.maxy=r.maxy>P.maxy?r.maxy:P.maxy;let g;if(x.child1==null){let Z=pt.tmpaabb;g=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+w}else{let Z=x.aabb,C=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,F=pt.tmpaabb;g=(F.maxx-F.minx+(F.maxy-F.miny))*2-C+w}let E=pt.tmpaabb,N=f.aabb;E.minx=r.minx<N.minx?r.minx:N.minx,E.miny=r.miny<N.miny?r.miny:N.miny,E.maxx=r.maxx>N.maxx?r.maxx:N.maxx,E.maxy=r.maxy>N.maxy?r.maxy:N.maxy;let k;if(f.child1==null){let Z=pt.tmpaabb;k=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2+w}else{let Z=f.aabb,C=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,F=pt.tmpaabb;k=(F.maxx-F.minx+(F.maxy-F.miny))*2-C+w}if(y<g&&y<k)break;o=g<k?x:f}let a=o,p=a.parent,c;Ve.zpp_pool==null?c=new Ve:(c=Ve.zpp_pool,Ve.zpp_pool=c.next,c.next=null),fe.zpp_pool==null?c.aabb=new fe:(c.aabb=fe.zpp_pool,fe.zpp_pool=c.aabb.next,c.aabb.next=null),c.moved=!1,c.synced=!1,c.first_sync=!1,c.parent=p;let u=c.aabb,h=a.aabb;for(u.minx=r.minx<h.minx?r.minx:h.minx,u.miny=r.miny<h.miny?r.miny:h.miny,u.maxx=r.maxx>h.maxx?r.maxx:h.maxx,u.maxy=r.maxy>h.maxy?r.maxy:h.maxy,c.height=a.height+1,p!=null?(p.child1==a?p.child1=c:p.child2=c,c.child1=a,c.child2=t,a.parent=c,t.parent=c):(c.child1=a,c.child2=t,a.parent=c,t.parent=c,i.root=c),o=t.parent;o!=null;){if(o.child1==null||o.height<2)o=o;else{let M=o.child1,y=o.child2,w=y.height-M.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=o,y.parent=o.parent,o.parent=y,y.parent!=null?y.parent.child1==o?y.parent.child1=y:y.parent.child2=y:i.root=y,v.height>P.height){y.child2=v,o.child2=P,P.parent=o;let g=o.aabb,E=M.aabb,N=P.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=y.aabb,Z=o.aabb,C=v.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=M.height,O=P.height;o.height=1+(F>O?F:O);let B=o.height,D=v.height;y.height=1+(B>D?B:D)}else{y.child2=P,o.child2=v,v.parent=o;let g=o.aabb,E=M.aabb,N=v.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=y.aabb,Z=o.aabb,C=P.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=M.height,O=v.height;o.height=1+(F>O?F:O);let B=o.height,D=P.height;y.height=1+(B>D?B:D)}o=y}else if(w<-1){let v=M.child1,P=M.child2;if(M.child1=o,M.parent=o.parent,o.parent=M,M.parent!=null?M.parent.child1==o?M.parent.child1=M:M.parent.child2=M:i.root=M,v.height>P.height){M.child2=v,o.child1=P,P.parent=o;let g=o.aabb,E=y.aabb,N=P.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=M.aabb,Z=o.aabb,C=v.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=y.height,O=P.height;o.height=1+(F>O?F:O);let B=o.height,D=v.height;M.height=1+(B>D?B:D)}else{M.child2=P,o.child1=v,v.parent=o;let g=o.aabb,E=y.aabb,N=v.aabb;g.minx=E.minx<N.minx?E.minx:N.minx,g.miny=E.miny<N.miny?E.miny:N.miny,g.maxx=E.maxx>N.maxx?E.maxx:N.maxx,g.maxy=E.maxy>N.maxy?E.maxy:N.maxy;let k=M.aabb,Z=o.aabb,C=P.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=y.height,O=v.height;o.height=1+(F>O?F:O);let B=o.height,D=P.height;M.height=1+(B>D?B:D)}o=M}else o=o}let x=o.child1,f=o.child2,_=x.height,d=f.height;o.height=1+(_>d?_:d);let b=o.aabb,m=x.aabb,z=f.aabb;b.minx=m.minx<z.minx?m.minx:z.minx,b.miny=m.miny<z.miny?m.miny:z.miny,b.maxx=m.maxx>z.maxx?m.maxx:z.maxx,b.maxy=m.maxy>z.maxy?m.maxy:z.maxy,o=o.parent}}t.synced=!1,t.moved||(t.moved=!0,t.mnext=this.moves,this.moves=t)}}broadphase(e,t){let n=this.syncs;for(;n!=null;){let i=n.shape;if(n.first_sync)n.first_sync=!1;else{let p=n.dyn?this.dtree:this.stree;if(n==p.root)p.root=null;else{let c=n.parent,u=c.parent,h=c.child1==n?c.child2:c.child1;if(u!=null){u.child1==c?u.child1=h:u.child2=h,h.parent=u;let x=c;x.height=-1;let f=x.aabb;f.outer!=null&&(f.outer.zpp_inner=null,f.outer=null),f.wrap_min=f.wrap_max=null,f._invalidate=null,f._validate=null,f.next=fe.zpp_pool,fe.zpp_pool=f,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ve.zpp_pool,Ve.zpp_pool=x;let _=u;for(;_!=null;){if(_.child1==null||_.height<2)_=_;else{let v=_.child1,P=_.child2,g=P.height-v.height;if(g>1){let E=P.child1,N=P.child2;if(P.child1=_,P.parent=_.parent,_.parent=P,P.parent!=null?P.parent.child1==_?P.parent.child1=P:P.parent.child2=P:p.root=P,E.height>N.height){P.child2=E,_.child2=N,N.parent=_;let k=_.aabb,Z=v.aabb,C=N.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=P.aabb,O=_.aabb,B=E.aabb;F.minx=O.minx<B.minx?O.minx:B.minx,F.miny=O.miny<B.miny?O.miny:B.miny,F.maxx=O.maxx>B.maxx?O.maxx:B.maxx,F.maxy=O.maxy>B.maxy?O.maxy:B.maxy;let D=v.height,U=N.height;_.height=1+(D>U?D:U);let W=_.height,q=E.height;P.height=1+(W>q?W:q)}else{P.child2=N,_.child2=E,E.parent=_;let k=_.aabb,Z=v.aabb,C=E.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=P.aabb,O=_.aabb,B=N.aabb;F.minx=O.minx<B.minx?O.minx:B.minx,F.miny=O.miny<B.miny?O.miny:B.miny,F.maxx=O.maxx>B.maxx?O.maxx:B.maxx,F.maxy=O.maxy>B.maxy?O.maxy:B.maxy;let D=v.height,U=E.height;_.height=1+(D>U?D:U);let W=_.height,q=N.height;P.height=1+(W>q?W:q)}_=P}else if(g<-1){let E=v.child1,N=v.child2;if(v.child1=_,v.parent=_.parent,_.parent=v,v.parent!=null?v.parent.child1==_?v.parent.child1=v:v.parent.child2=v:p.root=v,E.height>N.height){v.child2=E,_.child1=N,N.parent=_;let k=_.aabb,Z=P.aabb,C=N.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=v.aabb,O=_.aabb,B=E.aabb;F.minx=O.minx<B.minx?O.minx:B.minx,F.miny=O.miny<B.miny?O.miny:B.miny,F.maxx=O.maxx>B.maxx?O.maxx:B.maxx,F.maxy=O.maxy>B.maxy?O.maxy:B.maxy;let D=P.height,U=N.height;_.height=1+(D>U?D:U);let W=_.height,q=E.height;v.height=1+(W>q?W:q)}else{v.child2=N,_.child1=E,E.parent=_;let k=_.aabb,Z=P.aabb,C=E.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=v.aabb,O=_.aabb,B=N.aabb;F.minx=O.minx<B.minx?O.minx:B.minx,F.miny=O.miny<B.miny?O.miny:B.miny,F.maxx=O.maxx>B.maxx?O.maxx:B.maxx,F.maxy=O.maxy>B.maxy?O.maxy:B.maxy;let D=P.height,U=E.height;_.height=1+(D>U?D:U);let W=_.height,q=N.height;v.height=1+(W>q?W:q)}_=v}else _=_}let d=_.child1,b=_.child2,m=_.aabb,z=d.aabb,M=b.aabb;m.minx=z.minx<M.minx?z.minx:M.minx,m.miny=z.miny<M.miny?z.miny:M.miny,m.maxx=z.maxx>M.maxx?z.maxx:M.maxx,m.maxy=z.maxy>M.maxy?z.maxy:M.maxy;let y=d.height,w=b.height;_.height=1+(y>w?y:w),_=_.parent}}else{p.root=h,h.parent=null;let x=c;x.height=-1;let f=x.aabb;f.outer!=null&&(f.outer.zpp_inner=null,f.outer=null),f.wrap_min=f.wrap_max=null,f._invalidate=null,f._validate=null,f.next=fe.zpp_pool,fe.zpp_pool=f,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ve.zpp_pool,Ve.zpp_pool=x}}}let r=n.aabb;if(!e.continuous&&i.zip_aabb&&i.body!=null)if(i.zip_aabb=!1,i.type==0){let p=i.circle;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=!1,p.zip_localCOM){if(p.zip_localCOM=!1,p.type==1){let x=p.polygon;if(x.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(x.lverts.next.next==null)x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;else if(x.lverts.next.next.next==null){x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;let f=1;x.localCOMx+=x.lverts.next.next.x*f,x.localCOMy+=x.lverts.next.next.y*f;let _=.5;x.localCOMx*=_,x.localCOMy*=_}else{x.localCOMx=0,x.localCOMy=0;let f=0,_=x.lverts.next,d=_;_=_.next;let b=_;for(_=_.next;_!=null;){let v=_;f+=b.x*(v.y-d.y);let P=v.y*b.x-v.x*b.y;x.localCOMx+=(b.x+v.x)*P,x.localCOMy+=(b.y+v.y)*P,d=b,b=v,_=_.next}_=x.lverts.next;let m=_;f+=b.x*(m.y-d.y);let z=m.y*b.x-m.x*b.y;x.localCOMx+=(b.x+m.x)*z,x.localCOMy+=(b.y+m.y)*z,d=b,b=m,_=_.next;let M=_;f+=b.x*(M.y-d.y);let y=M.y*b.x-M.x*b.y;x.localCOMx+=(b.x+M.x)*y,x.localCOMy+=(b.y+M.y)*y,f=1/(3*f);let w=f;x.localCOMx*=w,x.localCOMy*=w}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let h=p.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy)}let c=p.radius,u=p.radius;p.aabb.minx=p.worldCOMx-c,p.aabb.miny=p.worldCOMy-u,p.aabb.maxx=p.worldCOMx+c,p.aabb.maxy=p.worldCOMy+u}else{let p=i.polygon;if(p.zip_gverts&&p.body!=null){p.zip_gverts=!1,p.validate_lverts();let h=p.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot));let x=p.lverts.next,f=p.gverts.next;for(;f!=null;){let _=f,d=x;x=x.next,_.x=p.body.posx+(p.body.axisy*d.x-p.body.axisx*d.y),_.y=p.body.posy+(d.x*p.body.axisx+d.y*p.body.axisy),f=f.next}}if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let c=p.gverts.next;p.aabb.minx=c.x,p.aabb.miny=c.y,p.aabb.maxx=c.x,p.aabb.maxy=c.y;let u=p.gverts.next.next;for(;u!=null;){let h=u;h.x<p.aabb.minx&&(p.aabb.minx=h.x),h.x>p.aabb.maxx&&(p.aabb.maxx=h.x),h.y<p.aabb.miny&&(p.aabb.miny=h.y),h.y>p.aabb.maxy&&(p.aabb.maxy=h.y),u=u.next}}let o=i.aabb;r.minx=o.minx-3,r.miny=o.miny-3,r.maxx=o.maxx+3,r.maxy=o.maxy+3;let a=(n.dyn=i.body.type==1?!1:!i.body.component.sleeping)?this.dtree:this.stree;if(a.root==null)a.root=n,a.root.parent=null;else{let p=n.aabb,c=a.root;for(;c.child1!=null;){let d=c.child1,b=c.child2,m=c.aabb,z=(m.maxx-m.minx+(m.maxy-m.miny))*2,M=pt.tmpaabb,y=c.aabb;M.minx=y.minx<p.minx?y.minx:p.minx,M.miny=y.miny<p.miny?y.miny:p.miny,M.maxx=y.maxx>p.maxx?y.maxx:p.maxx,M.maxy=y.maxy>p.maxy?y.maxy:p.maxy;let w=pt.tmpaabb,v=(w.maxx-w.minx+(w.maxy-w.miny))*2,P=2*v,g=2*(v-z),E=pt.tmpaabb,N=d.aabb;E.minx=p.minx<N.minx?p.minx:N.minx,E.miny=p.miny<N.miny?p.miny:N.miny,E.maxx=p.maxx>N.maxx?p.maxx:N.maxx,E.maxy=p.maxy>N.maxy?p.maxy:N.maxy;let k;if(d.child1==null){let O=pt.tmpaabb;k=(O.maxx-O.minx+(O.maxy-O.miny))*2+g}else{let O=d.aabb,B=(O.maxx-O.minx+(O.maxy-O.miny))*2,D=pt.tmpaabb;k=(D.maxx-D.minx+(D.maxy-D.miny))*2-B+g}let Z=pt.tmpaabb,C=b.aabb;Z.minx=p.minx<C.minx?p.minx:C.minx,Z.miny=p.miny<C.miny?p.miny:C.miny,Z.maxx=p.maxx>C.maxx?p.maxx:C.maxx,Z.maxy=p.maxy>C.maxy?p.maxy:C.maxy;let F;if(b.child1==null){let O=pt.tmpaabb;F=(O.maxx-O.minx+(O.maxy-O.miny))*2+g}else{let O=b.aabb,B=(O.maxx-O.minx+(O.maxy-O.miny))*2,D=pt.tmpaabb;F=(D.maxx-D.minx+(D.maxy-D.miny))*2-B+g}if(P<k&&P<F)break;c=k<F?d:b}let u=c,h=u.parent,x;Ve.zpp_pool==null?x=new Ve:(x=Ve.zpp_pool,Ve.zpp_pool=x.next,x.next=null),fe.zpp_pool==null?x.aabb=new fe:(x.aabb=fe.zpp_pool,fe.zpp_pool=x.aabb.next,x.aabb.next=null),x.moved=!1,x.synced=!1,x.first_sync=!1,x.parent=h;let f=x.aabb,_=u.aabb;for(f.minx=p.minx<_.minx?p.minx:_.minx,f.miny=p.miny<_.miny?p.miny:_.miny,f.maxx=p.maxx>_.maxx?p.maxx:_.maxx,f.maxy=p.maxy>_.maxy?p.maxy:_.maxy,x.height=u.height+1,h!=null?(h.child1==u?h.child1=x:h.child2=x,x.child1=u,x.child2=n,u.parent=x,n.parent=x):(x.child1=u,x.child2=n,u.parent=x,n.parent=x,a.root=x),c=n.parent;c!=null;){if(c.child1==null||c.height<2)c=c;else{let v=c.child1,P=c.child2,g=P.height-v.height;if(g>1){let E=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,E.height>N.height){P.child2=E,c.child2=N,N.parent=c;let k=c.aabb,Z=v.aabb,C=N.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=P.aabb,O=c.aabb,B=E.aabb;F.minx=O.minx<B.minx?O.minx:B.minx,F.miny=O.miny<B.miny?O.miny:B.miny,F.maxx=O.maxx>B.maxx?O.maxx:B.maxx,F.maxy=O.maxy>B.maxy?O.maxy:B.maxy;let D=v.height,U=N.height;c.height=1+(D>U?D:U);let W=c.height,q=E.height;P.height=1+(W>q?W:q)}else{P.child2=N,c.child2=E,E.parent=c;let k=c.aabb,Z=v.aabb,C=E.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=P.aabb,O=c.aabb,B=N.aabb;F.minx=O.minx<B.minx?O.minx:B.minx,F.miny=O.miny<B.miny?O.miny:B.miny,F.maxx=O.maxx>B.maxx?O.maxx:B.maxx,F.maxy=O.maxy>B.maxy?O.maxy:B.maxy;let D=v.height,U=E.height;c.height=1+(D>U?D:U);let W=c.height,q=N.height;P.height=1+(W>q?W:q)}c=P}else if(g<-1){let E=v.child1,N=v.child2;if(v.child1=c,v.parent=c.parent,c.parent=v,v.parent!=null?v.parent.child1==c?v.parent.child1=v:v.parent.child2=v:a.root=v,E.height>N.height){v.child2=E,c.child1=N,N.parent=c;let k=c.aabb,Z=P.aabb,C=N.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=v.aabb,O=c.aabb,B=E.aabb;F.minx=O.minx<B.minx?O.minx:B.minx,F.miny=O.miny<B.miny?O.miny:B.miny,F.maxx=O.maxx>B.maxx?O.maxx:B.maxx,F.maxy=O.maxy>B.maxy?O.maxy:B.maxy;let D=P.height,U=N.height;c.height=1+(D>U?D:U);let W=c.height,q=E.height;v.height=1+(W>q?W:q)}else{v.child2=N,c.child1=E,E.parent=c;let k=c.aabb,Z=P.aabb,C=E.aabb;k.minx=Z.minx<C.minx?Z.minx:C.minx,k.miny=Z.miny<C.miny?Z.miny:C.miny,k.maxx=Z.maxx>C.maxx?Z.maxx:C.maxx,k.maxy=Z.maxy>C.maxy?Z.maxy:C.maxy;let F=v.aabb,O=c.aabb,B=N.aabb;F.minx=O.minx<B.minx?O.minx:B.minx,F.miny=O.miny<B.miny?O.miny:B.miny,F.maxx=O.maxx>B.maxx?O.maxx:B.maxx,F.maxy=O.maxy>B.maxy?O.maxy:B.maxy;let D=P.height,U=E.height;c.height=1+(D>U?D:U);let W=c.height,q=N.height;v.height=1+(W>q?W:q)}c=v}else c=c}let d=c.child1,b=c.child2,m=d.height,z=b.height;c.height=1+(m>z?m:z);let M=c.aabb,y=d.aabb,w=b.aabb;M.minx=y.minx<w.minx?y.minx:w.minx,M.miny=y.miny<w.miny?y.miny:w.miny,M.maxx=y.maxx>w.maxx?y.maxx:w.maxx,M.maxy=y.maxy>w.maxy?y.maxy:w.maxy,c=c.parent}}n.synced=!1,n=n.snext}for(;this.syncs!=null;){let i=this.syncs;this.syncs=i.snext,i.snext=null;let r=i;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 u=c;c=u.next,u.next=null;let h=u;if(h!=r)if(h.child1==null){let x=h.shape;if(x.body!=o.body&&!(x.body.type==1&&o.body.type==1)){let f=h.aabb;if(f.miny<=p.maxy&&p.miny<=f.maxy&&f.minx<=p.maxx&&p.minx<=f.maxx){let _,d;o.id<x.id?(_=o.id,d=x.id):(_=x.id,d=o.id);let b=o.pairs.length<x.pairs.length?o:x,m=null,z=b.pairs.head;for(;z!=null;){let E=z.elt;if(E.id==_&&E.di==d){m=E;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}at.zpp_pool==null?m=new at:(m=at.zpp_pool,at.zpp_pool=m.next,m.next=null),m.n1=r,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let M=o.pairs,y;be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new be._zpp.util.ZNPNode_ZPP_AABBPair:(y=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=M.head,M.head=w,M.modified=!0,M.length++;let v=x.pairs,P;be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new be._zpp.util.ZNPNode_ZPP_AABBPair:(P=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=r)if(h.child1==null){let x=h.shape;if(x.body!=o.body&&!(x.body.type==1&&o.body.type==1)){let f=h.aabb;if(f.miny<=p.maxy&&p.miny<=f.maxy&&f.minx<=p.maxx&&p.minx<=f.maxx){let _,d;o.id<x.id?(_=o.id,d=x.id):(_=x.id,d=o.id);let b=o.pairs.length<x.pairs.length?o:x,m=null,z=b.pairs.head;for(;z!=null;){let E=z.elt;if(E.id==_&&E.di==d){m=E;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}at.zpp_pool==null?m=new at:(m=at.zpp_pool,at.zpp_pool=m.next,m.next=null),m.n1=r,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let M=o.pairs,y;be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new be._zpp.util.ZNPNode_ZPP_AABBPair:(y=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=M.head,M.head=w,M.modified=!0,M.length++;let v=x.pairs,P;be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new be._zpp.util.ZNPNode_ZPP_AABBPair:(P=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}}for(;this.moves!=null;){let i=this.moves;this.moves=i.mnext,i.mnext=null;let r=i;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 u=c;c=u.next,u.next=null;let h=u;if(h!=r)if(h.child1==null){let x=h.shape;if(x.body!=o.body&&!(x.body.type==1&&o.body.type==1)){let f=h.aabb;if(f.miny<=p.maxy&&p.miny<=f.maxy&&f.minx<=p.maxx&&p.minx<=f.maxx){let _,d;o.id<x.id?(_=o.id,d=x.id):(_=x.id,d=o.id);let b=o.pairs.length<x.pairs.length?o:x,m=null,z=b.pairs.head;for(;z!=null;){let E=z.elt;if(E.id==_&&E.di==d){m=E;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}at.zpp_pool==null?m=new at:(m=at.zpp_pool,at.zpp_pool=m.next,m.next=null),m.n1=r,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let M=o.pairs,y;be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new be._zpp.util.ZNPNode_ZPP_AABBPair:(y=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=M.head,M.head=w,M.modified=!0,M.length++;let v=x.pairs,P;be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new be._zpp.util.ZNPNode_ZPP_AABBPair:(P=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=r)if(h.child1==null){let x=h.shape;if(x.body!=o.body&&!(x.body.type==1&&o.body.type==1)){let f=h.aabb;if(f.miny<=p.maxy&&p.miny<=f.maxy&&f.minx<=p.maxx&&p.minx<=f.maxx){let _,d;o.id<x.id?(_=o.id,d=x.id):(_=x.id,d=o.id);let b=o.pairs.length<x.pairs.length?o:x,m=null,z=b.pairs.head;for(;z!=null;){let E=z.elt;if(E.id==_&&E.di==d){m=E;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}at.zpp_pool==null?m=new at:(m=at.zpp_pool,at.zpp_pool=m.next,m.next=null),m.n1=r,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let M=o.pairs,y;be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new be._zpp.util.ZNPNode_ZPP_AABBPair:(y=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=M.head,M.head=w,M.modified=!0,M.length++;let v=x.pairs,P;be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new be._zpp.util.ZNPNode_ZPP_AABBPair:(P=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}}let l=null,s=this.pairs;for(;s!=null;){let i;if(s.first)i=!1;else{let h=s.n1.aabb,x=s.n2.aabb;i=!(x.miny<=h.maxy&&h.miny<=x.maxy&&x.minx<=h.maxx&&h.minx<=x.maxx)}if(i){l==null?this.pairs=s.next:l.next=s.next;let h=s.n1.shape.pairs,x=null,f=h.head,_=!1;for(;f!=null;){if(f.elt==s){let w,v;x==null?(w=h.head,v=w.next,h.head=v,h.head==null&&(h.pushmod=!0)):(w=x.next,v=w.next,x.next=v,v==null&&(h.pushmod=!0));let P=w;P.elt=null,P.next=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P,h.modified=!0,h.length--,h.pushmod=!0,_=!0;break}x=f,f=f.next}let d=s.n2.shape.pairs,b=null,m=d.head,z=!1;for(;m!=null;){if(m.elt==s){let w,v;b==null?(w=d.head,v=w.next,d.head=v,d.head==null&&(d.pushmod=!0)):(w=b.next,v=w.next,b.next=v,v==null&&(d.pushmod=!0));let P=w;P.elt=null,P.next=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P,d.modified=!0,d.length--,d.pushmod=!0,z=!0;break}b=m,m=m.next}let M=s.next;s.arb!=null&&(s.arb.pair=null),s.arb=null;let y=s;y.n1=y.n2=null,y.sleeping=!1,y.next=at.zpp_pool,at.zpp_pool=y,s=M;continue}let r=s.n1.shape,o=r.body,a=s.n2.shape,p=a.body;if(!s.first&&(o.component.sleeping||o.type==1)&&(p.component.sleeping||p.type==1)){s.sleeping=!0,l==null?this.pairs=s.next:l.next=s.next,s=s.next;continue}s.first=!1;let c=r.aabb,u=a.aabb;if(u.miny<=c.maxy&&c.miny<=u.maxy&&u.minx<=c.maxx&&c.minx<=u.maxx){let h=s.arb;t?s.arb=e.narrowPhase(r,a,o.type!=2||p.type!=2,s.arb,!1):s.arb=e.continuousEvent(r,a,o.type!=2||p.type!=2,s.arb,!1),s.arb==null?h!=null&&(h.pair=null):s.arb.pair=s}l=s,s=s.next}}clear(){for(;this.syncs!=null;){let e=this.syncs.snext;this.syncs.snext=null,this.syncs.first_sync&&(this.syncs.shape.node=null,this.syncs.shape.removedFromSpace(),this.syncs.shape=null),this.syncs=e}for(;this.moves!=null;){let e=this.moves.mnext;this.moves.mnext=null,this.moves.first_sync&&(this.moves.shape.node=null,this.moves.shape.removedFromSpace(),this.moves.shape=null),this.moves=e}for(;this.pairs!=null;){let e=this.pairs.next;this.pairs.arb!=null&&(this.pairs.arb.pair=null),this.pairs.arb=null;let t=this.pairs.n1.shape.pairs,n=this.pairs,l=null,s=t.head,i=!1;for(;s!=null;){if(s.elt==n){let h,x;l==null?(h=t.head,x=h.next,t.head=x,t.head==null&&(t.pushmod=!0)):(h=l.next,x=h.next,l.next=x,x==null&&(t.pushmod=!0));let f=h;f.elt=null,f.next=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=f,t.modified=!0,t.length--,t.pushmod=!0,i=!0;break}l=s,s=s.next}let r=this.pairs.n2.shape.pairs,o=this.pairs,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==o){let h,x;a==null?(h=r.head,x=h.next,r.head=x,r.head==null&&(r.pushmod=!0)):(h=a.next,x=h.next,a.next=x,x==null&&(r.pushmod=!0));let f=h;f.elt=null,f.next=be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=f,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}let u=this.pairs;u.n1=u.n2=null,u.sleeping=!1,u.next=at.zpp_pool,at.zpp_pool=u,this.pairs=e}this.dtree.clear(),this.stree.clear()}shapesUnderPoint(e,t,n,l){this.sync_broadphase();let s;ie.zpp_pool==null?s=new ie:(s=ie.zpp_pool,ie.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,r=l??new be._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c;if(n!=null){let u=a.shape.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(a.shape.type==0?Ne.circleContains(a.shape.circle,i)&&r.push(a.shape.outer):Ne.polyContains(a.shape.polygon,i)&&r.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c;if(n!=null){let u=a.shape.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(a.shape.type==0?Ne.circleContains(a.shape.circle,i)&&r.push(a.shape.outer):Ne.polyContains(a.shape.polygon,i)&&r.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}let o=i;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=ie.zpp_pool,ie.zpp_pool=o,r}bodiesUnderPoint(e,t,n,l){this.sync_broadphase();let s;ie.zpp_pool==null?s=new ie:(s=ie.zpp_pool,ie.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,r=l??new be._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c=a.shape.body.outer;if(!r.has(c)){let u;if(n!=null){let h=a.shape.filter;u=(h.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(a.shape.type==0?Ne.circleContains(a.shape.circle,i)&&r.push(c):Ne.polyContains(a.shape.polygon,i)&&r.push(c))}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c=a.shape.body.outer;if(!r.has(c)){let u;if(n!=null){let h=a.shape.filter;u=(h.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(a.shape.type==0?Ne.circleContains(a.shape.circle,i)&&r.push(c):Ne.polyContains(a.shape.polygon,i)&&r.push(c))}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}let o=i;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=ie.zpp_pool,ie.zpp_pool=o,r}shapesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,r=s??new be._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._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(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(o.child1==null){let p;if(l!=null){let c=o.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;p&&r.push(o.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(o);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;c&&r.push(p.shape.outer)}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=o.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(o.child1==null){let c;if(l!=null){let u=o.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c)if(t)if(n)Ne.containTest(this.aabbShape.zpp_inner,o.shape)&&r.push(o.shape.outer);else{let u=o.shape.aabb;(u.minx>=i.minx&&u.miny>=i.miny&&u.maxx<=i.maxx&&u.maxy<=i.maxy||Ne.testCollide_safe(o.shape,this.aabbShape.zpp_inner))&&r.push(o.shape.outer)}else{let u;if(n){let h=o.shape.aabb;u=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy}else u=!0;u&&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 be._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(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(o.child1==null){let p;if(l!=null){let c=o.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;p&&r.push(o.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(o);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;c&&r.push(p.shape.outer)}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=o.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(o.child1==null){let c;if(l!=null){let u=o.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c)if(t)if(n)Ne.containTest(this.aabbShape.zpp_inner,o.shape)&&r.push(o.shape.outer);else{let u=o.shape.aabb;(u.minx>=i.minx&&u.miny>=i.miny&&u.maxx<=i.maxx&&u.maxy<=i.maxy||Ne.testCollide_safe(o.shape,this.aabbShape.zpp_inner))&&r.push(o.shape.outer)}else{let u;if(n){let h=o.shape.aabb;u=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy}else u=!0;u&&r.push(o.shape.outer)}}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}}return r}bodiesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,r=s??new be._nape.phys.BodyList;if(this.failed==null&&(this.failed=new be._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._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(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(o.child1==null){let p;if(l!=null){let c=o.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;if(p){let c=o.shape.body.outer;r.has(c)||r.push(c)}}else for(this.treeStack2==null&&(this.treeStack2=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(o);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c){let u=p.shape.body.outer;r.has(u)||r.push(u)}}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=o.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(o.child1==null){let c=o.shape.body.outer,u;if(l!=null){let h=o.shape.filter;u=(h.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(t)if(n){if(!this.failed.has(c)){let h=Ne.containTest(this.aabbShape.zpp_inner,o.shape);!r.has(c)&&h?r.push(c):h||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ne.testCollide_safe(o.shape,this.aabbShape.zpp_inner)&&r.push(c);else if(n){if(!this.failed.has(c)){let h=o.shape.aabb,x=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy;!r.has(c)&&x?r.push(c):x||(r.remove(c),this.failed.push(c))}}else{let h;if(r.has(c))h=!1;else{let x=o.shape.aabb;h=x.minx>=i.minx&&x.miny>=i.miny&&x.maxx<=i.maxx&&x.maxy<=i.maxy}h&&r.push(c)}}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 be._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(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(o.child1==null){let p;if(l!=null){let c=o.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;if(p){let c=o.shape.body.outer;r.has(c)||r.push(c)}}else for(this.treeStack2==null&&(this.treeStack2=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(o);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c){let u=p.shape.body.outer;r.has(u)||r.push(u)}}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=o.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(o.child1==null){let c=o.shape.body.outer,u;if(l!=null){let h=o.shape.filter;u=(h.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(t)if(n){if(!this.failed.has(c)){let h=Ne.containTest(this.aabbShape.zpp_inner,o.shape);!r.has(c)&&h?r.push(c):h||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ne.testCollide_safe(o.shape,this.aabbShape.zpp_inner)&&r.push(c);else if(n){if(!this.failed.has(c)){let h=o.shape.aabb,x=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy;!r.has(c)&&x?r.push(c):x||(r.remove(c),this.failed.push(c))}}else{let h;if(r.has(c))h=!1;else{let x=o.shape.aabb;h=x.minx>=i.minx&&x.miny>=i.miny&&x.maxx<=i.maxx&&x.maxy<=i.maxy}h&&r.push(c)}}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}}return this.failed.clear(),r}shapesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let r=this.circShape.zpp_inner.aabb,o=i??new be._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._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(r.miny<=p.maxy&&p.miny<=r.maxy&&r.minx<=p.maxx&&p.minx<=r.maxx)if(a.child1==null){let c;if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(l?Ne.containTest(this.circShape.zpp_inner,a.shape)&&o.push(a.shape.outer):Ne.testCollide_safe(a.shape,this.circShape.zpp_inner)&&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 be._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(r.miny<=p.maxy&&p.miny<=r.maxy&&r.minx<=p.maxx&&p.minx<=r.maxx)if(a.child1==null){let c;if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(l?Ne.containTest(this.circShape.zpp_inner,a.shape)&&o.push(a.shape.outer):Ne.testCollide_safe(a.shape,this.circShape.zpp_inner)&&o.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return o}bodiesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let r=this.circShape.zpp_inner.aabb,o=i??new be._nape.phys.BodyList;if(this.failed==null&&(this.failed=new be._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._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(r.miny<=p.maxy&&p.miny<=r.maxy&&r.minx<=p.maxx&&p.minx<=r.maxx)if(a.child1==null){let c=a.shape.body.outer,u;if(s!=null){let h=a.shape.filter;u=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(l){if(!this.failed.has(c)){let h=Ne.containTest(this.circShape.zpp_inner,a.shape);!o.has(c)&&h?o.push(c):h||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ne.testCollide_safe(a.shape,this.circShape.zpp_inner)&&o.push(c)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._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(r.miny<=p.maxy&&p.miny<=r.maxy&&r.minx<=p.maxx&&p.minx<=r.maxx)if(a.child1==null){let c=a.shape.body.outer,u;if(s!=null){let h=a.shape.filter;u=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(l){if(!this.failed.has(c)){let h=Ne.containTest(this.circShape.zpp_inner,a.shape);!o.has(c)&&h?o.push(c):h||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ne.testCollide_safe(a.shape,this.circShape.zpp_inner)&&o.push(c)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return this.failed.clear(),o}shapesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new be._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),o=r.aabb;if(s.miny<=o.maxy&&o.miny<=s.maxy&&s.minx<=o.maxx&&o.minx<=s.maxx)if(r.child1==null){let a;if(n!=null){let p=r.shape.filter;a=(p.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&p.collisionGroup)!=0}else a=!0;a&&(t?Ne.containTest(e,r.shape)&&i.push(r.shape.outer):Ne.testCollide_safe(r.shape,e)&&i.push(r.shape.outer))}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),o=r.aabb;if(s.miny<=o.maxy&&o.miny<=s.maxy&&s.minx<=o.maxx&&o.minx<=s.maxx)if(r.child1==null){let a;if(n!=null){let p=r.shape.filter;a=(p.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&p.collisionGroup)!=0}else a=!0;a&&(t?Ne.containTest(e,r.shape)&&i.push(r.shape.outer):Ne.testCollide_safe(r.shape,e)&&i.push(r.shape.outer))}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}return i}bodiesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new be._nape.phys.BodyList;if(this.failed==null&&(this.failed=new be._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),o=r.aabb;if(s.miny<=o.maxy&&o.miny<=s.maxy&&s.minx<=o.maxx&&o.minx<=s.maxx)if(r.child1==null){let a=r.shape.body.outer,p;if(n!=null){let c=r.shape.filter;p=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else p=!0;if(p)if(t){if(!this.failed.has(a)){let c=Ne.containTest(e,r.shape);!i.has(a)&&c?i.push(a):c||(i.remove(a),this.failed.push(a))}}else!i.has(a)&&Ne.testCollide_safe(r.shape,e)&&i.push(a)}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new be._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),o=r.aabb;if(s.miny<=o.maxy&&o.miny<=s.maxy&&s.minx<=o.maxx&&o.minx<=s.maxx)if(r.child1==null){let a=r.shape.body.outer,p;if(n!=null){let c=r.shape.filter;p=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else p=!0;if(p)if(t){if(!this.failed.has(a)){let c=Ne.containTest(e,r.shape);!i.has(a)&&c?i.push(a):c||(i.remove(a),this.failed.push(a))}}else!i.has(a)&&Ne.testCollide_safe(r.shape,e)&&i.push(a)}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}return this.failed.clear(),i}rayCast(e,t,n){this.openlist==null&&(this.openlist=new be._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),e.validate_dir();let l=e.maxdist;if(this.dtree.root!=null&&e.aabbtest(this.dtree.root.aabb)){let i=e.aabbsect(this.dtree.root.aabb);if(i>=0&&i<l){this.dtree.root.rayt=i;let r=null,o=this.openlist.head;for(;o!=null;){let h=o.elt;if(this.dtree.root.rayt<h.rayt)break;r=o,o=o.next}let a=this.openlist,p=this.dtree.root,c;be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?c=new be._zpp.util.ZNPNode_ZPP_AABBNode:(c=be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=c.next,c.next=null),c.elt=p;let u=c;r==null?(u.next=a.head,a.head=u):(u.next=r.next,r.next=u),a.pushmod=a.modified=!0,a.length++}}if(this.stree.root!=null&&e.aabbtest(this.stree.root.aabb)){let i=e.aabbsect(this.stree.root.aabb);if(i>=0&&i<l){this.stree.root.rayt=i;let r=null,o=this.openlist.head;for(;o!=null;){let h=o.elt;if(this.stree.root.rayt<h.rayt)break;r=o,o=o.next}let a=this.openlist,p=this.stree.root,c;be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?c=new be._zpp.util.ZNPNode_ZPP_AABBNode:(c=be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=c.next,c.next=null),c.elt=p;let u=c;r==null?(u.next=a.head,a.head=u):(u.next=r.next,r.next=u),a.pushmod=a.modified=!0,a.length++}}let s=null;for(;this.openlist.head!=null;){let i=this.openlist.pop_unsafe();if(i.rayt>=l)break;if(i.child1==null){let r=i.shape,o;if(n!=null){let a=r.filter;o=(a.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&a.collisionGroup)!=0}else o=!0;if(o){let a=r.type==0?e.circlesect(r.circle,t,l):e.aabbtest(r.aabb)?e.polysect(r.polygon,t,l):null;if(a!=null){if(a.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=a.zpp_inner.toiDistance,s!=null){if(s.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");s.zpp_inner.free()}s=a}}}else{if(i.child1!=null&&e.aabbtest(i.child1.aabb)){let r=e.aabbsect(i.child1.aabb);if(r>=0&&r<l){i.child1.rayt=r;let o=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(i.child1.rayt<x.rayt)break;o=a,a=a.next}let p=this.openlist,c=i.child1,u;be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new be._zpp.util.ZNPNode_ZPP_AABBNode:(u=be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=c;let h=u;o==null?(h.next=p.head,p.head=h):(h.next=o.next,o.next=h),p.pushmod=p.modified=!0,p.length++}}if(i.child2!=null&&e.aabbtest(i.child2.aabb)){let r=e.aabbsect(i.child2.aabb);if(r>=0&&r<l){i.child2.rayt=r;let o=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(i.child2.rayt<x.rayt)break;o=a,a=a.next}let p=this.openlist,c=i.child2,u;be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new be._zpp.util.ZNPNode_ZPP_AABBNode:(u=be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,be._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=c;let h=u;o==null?(h.next=p.head,p.head=h):(h.next=o.next,o.next=h),p.pushmod=p.modified=!0,p.length++}}}}return this.openlist.clear(),s}rayMultiCast(e,t,n,l){this.openlist==null&&(this.openlist=new be._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),e.validate_dir();let s=e.maxdist>=1/0,i=l??new be._nape.geom.RayResultList;if(this.dtree.root!=null&&e.aabbtest(this.dtree.root.aabb))if(s)this.openlist.add(this.dtree.root);else{let r=e.aabbsect(this.dtree.root.aabb);r>=0&&r<e.maxdist&&this.openlist.add(this.dtree.root)}if(this.stree.root!=null&&e.aabbtest(this.stree.root.aabb))if(s)this.openlist.add(this.stree.root);else{let r=e.aabbsect(this.stree.root.aabb);r>=0&&r<e.maxdist&&this.openlist.add(this.stree.root)}for(;this.openlist.head!=null;){let r=this.openlist.pop_unsafe();if(r.child1==null){let o=r.shape,a;if(n!=null){let p=o.filter;a=(p.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&p.collisionGroup)!=0}else a=!0;a&&(o.type==0?e.circlesect2(o.circle,t,i):e.aabbtest(o.aabb)&&e.polysect2(o.polygon,t,i))}else{if(r.child1!=null&&e.aabbtest(r.child1.aabb))if(s)this.openlist.add(r.child1);else{let o=e.aabbsect(r.child1.aabb);o>=0&&o<e.maxdist&&this.openlist.add(r.child1)}if(r.child2!=null&&e.aabbtest(r.child2.aabb))if(s)this.openlist.add(r.child2);else{let o=e.aabbsect(r.child2.aabb);o>=0&&o<e.maxdist&&this.openlist.add(r.child2)}}}return this.openlist.clear(),i}};be.__name__=["zpp_nape","space","ZPP_DynAABBPhase"],be.__super__=null,be._zpp=null,be._nape=null,be.FATTEN=3,be.VEL_STEPS=2;var Gs=be;var Zl=class Zl{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 Zl._zpp.util.ZNPList_ZPP_Component}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){}alloc(){this.waket=0}};Zl.__name__=["zpp_nape","space","ZPP_Island"],Zl.zpp_pool=null,Zl._zpp=null;var Mt=Zl;var Ml=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}};Ml.__name__=["zpp_nape","space","ZPP_Component"],Ml.zpp_pool=null;var Un=class Un{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 Un._zpp.util.ZNPList_ZPP_Arbiter}static get(e,t){let n;return Un.zpp_pool==null?n=new Un:(n=Un.zpp_pool,Un.zpp_pool=n.next,n.next=null),n.freed=!1,n.lazydel=!1,n.COLLISIONstate=1,n.COLLISIONstamp=0,n.SENSORstate=1,n.SENSORstamp=0,n.FLUIDstate=1,n.FLUIDstamp=0,e.id<t.id?(n.int1=e,n.int2=t):(n.int1=t,n.int2=e),n.id=n.int1.id,n.di=n.int2.id,n}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){this.int1=this.int2=null,this.id=this.di=-1,this.freed=!0}alloc(){this.freed=!1,this.lazydel=!1,this.COLLISIONstate=1,this.COLLISIONstamp=0,this.SENSORstate=1,this.SENSORstamp=0,this.FLUIDstate=1,this.FLUIDstamp=0}add_arb(e){let t=!1,n=this.arbiters.head;for(;n!=null;){if(n.elt==e){t=!0;break}n=n.next}if(t)return!1;{let l=this.arbiters,s,i=Un._zpp.util.ZNPNode_ZPP_Arbiter;i.zpp_pool==null?s=new i:(s=i.zpp_pool,i.zpp_pool=s.next,s.next=null),s.elt=e;let r=s;return r.next=l.head,l.head=r,l.modified=!0,l.length++,!0}}try_remove_arb(e){let t=this.arbiters,n=null,l=t.head,s=!1;for(;l!=null;){if(l.elt==e){let i,r;n==null?(i=t.head,r=i.next,t.head=r,t.head==null&&(t.pushmod=!0)):(i=n.next,r=i.next,n.next=r,r==null&&(t.pushmod=!0));let o=i;o.elt=null;let a=Un._zpp.util.ZNPNode_ZPP_Arbiter;o.next=a.zpp_pool,a.zpp_pool=o,t.modified=!0,t.length--,t.pushmod=!0,s=!0;break}n=l,l=l.next}return s}remove_arb(e){let t=this.arbiters,n=null,l=t.head;for(;l!=null;){if(l.elt==e){let s,i;n==null?(s=t.head,i=s.next,t.head=i,t.head==null&&(t.pushmod=!0)):(s=n.next,i=s.next,n.next=i,i==null&&(t.pushmod=!0));let r=s;r.elt=null;let o=Un._zpp.util.ZNPNode_ZPP_Arbiter;r.next=o.zpp_pool,o.zpp_pool=r,t.modified=!0,t.length--,t.pushmod=!0;break}n=l,l=l.next}}empty_arb(e){let t=!0,n=this.arbiters.head;for(;n!=null;)if((n.elt.type&e)==0){n=n.next;continue}else{t=!1;break}return t}really_empty(){return this.arbiters.head==null}sleeping(){let e=!0,t=this.arbiters.head;for(;t!=null;)if(t.elt.sleeping){t=t.next;continue}else{e=!1;break}return e}};Un.__name__=["zpp_nape","space","ZPP_CallbackSet"],Un.zpp_pool=null,Un._zpp=null;var xn=Un;var Si=class Si{constructor(e){this.cbsets=null;this.space=null;let t=Si._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=Si._zpp.callbacks.ZPP_CbSet.setlt,this.space=e}get(e){if(e.head==null)return null;let t=Si._zpp.callbacks.ZPP_CbSet,n;t.zpp_pool==null?n=new t:(n=t.zpp_pool,t.zpp_pool=n.next,n.next=null);let l=n.cbTypes;n.cbTypes=e;let s=this.cbsets.find_weak(n),i;if(s!=null)i=s.data;else{let o=t.get(e);this.cbsets.insert(o),o.manager=this,i=o}n.cbTypes=l;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,i}remove(e){let t=Si._zpp.callbacks.ZPP_CbSetPair;for(this.cbsets.remove(e);e.cbpairs.head!=null;){let n=e.cbpairs.pop_unsafe();n.a!=n.b&&(e==n.a?n.b.cbpairs.remove(n):n.a.cbpairs.remove(n));let l=n;l.a=l.b=null,l.listeners.clear(),l.next=t.zpp_pool,t.zpp_pool=l}e.manager=null}clear(){}validate(){if(!this.cbsets.empty()){let e=this.cbsets.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;)if(e.data.validate(),e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent}}}pair(e,t){let n=Si._zpp.callbacks.ZPP_CbSet,l=Si._zpp.callbacks.ZPP_CbSetPair,s=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){s=o;break}r=r.next}if(s==null){let o;l.zpp_pool==null?o=new l:(o=l.zpp_pool,l.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),s=o,e.cbpairs.add(s),t!=e&&t.cbpairs.add(s)}return s.zip_listeners&&(s.zip_listeners=!1,s.__validate()),s}valid_listener(e){return e.space==this.space}};Si.__name__=["zpp_nape","space","ZPP_CbSetManager"],Si._zpp=null;var qs=Si;var I=class I{constructor(e,t){this.outer=null;this.userData=null;this.gravityx=null;this.gravityy=null;this.wrap_gravity=null;this.bodies=null;this.wrap_bodies=null;this.compounds=null;this.wrap_compounds=null;this.constraints=null;this.wrap_constraints=null;this.kinematics=null;this.bphase=null;this.__static=null;this.global_lin_drag=null;this.global_ang_drag=null;this.stamp=null;this.midstep=null;this.time=null;this.sortcontacts=null;this.c_arbiters_true=null;this.c_arbiters_false=null;this.f_arbiters=null;this.s_arbiters=null;this.wrap_arbiters=null;this.live=null;this.wrap_live=null;this.live_constraints=null;this.wrap_livecon=null;this.staticsleep=null;this.islands=null;this.listeners=null;this.wrap_listeners=null;this.callbacks=null;this.callbackset_list=null;this.cbsets=null;this.convexShapeList=null;this.pre_dt=null;this.toiEvents=null;this.continuous=null;this.precb=null;this.prelisteners=null;this.mrca1=null;this.mrca2=null;this.__class__=I;this.prelisteners=null,this.precb=null,this.continuous=!1,this.toiEvents=null,this.pre_dt=0,this.convexShapeList=null,this.cbsets=null,this.callbackset_list=null,this.callbacks=null,this.wrap_listeners=null,this.listeners=null,this.islands=null,this.staticsleep=null,this.wrap_livecon=null,this.live_constraints=null,this.wrap_live=null,this.live=null,this.wrap_arbiters=null,this.s_arbiters=null,this.f_arbiters=null,this.c_arbiters_false=null,this.c_arbiters_true=null,this.sortcontacts=!1,this.time=0,this.midstep=!1,this.stamp=0,this.global_ang_drag=0,this.global_lin_drag=0,this.__static=null,this.bphase=null,this.kinematics=null,this.wrap_constraints=null,this.constraints=null,this.wrap_compounds=null,this.compounds=null,this.wrap_bodies=null,this.bodies=null,this.wrap_gravity=null,this.gravityy=0,this.gravityx=0,this.userData=null,this.outer=null,this.toiEvents=new I._zpp.util.ZNPList_ZPP_ToiEvent,this.global_lin_drag=.015,this.global_ang_drag=.015,_t.internal=!0,this.precb=_t._createPreCb(),this.precb.zpp_inner=new _t,_t.internal=!1,this.sortcontacts=!0,this.pre_dt=0;let n;t!=null?(T.Broadphase_DYNAMIC_AABB_TREE==null&&(T.internal=!0,T.Broadphase_DYNAMIC_AABB_TREE=new I._nape.space.Broadphase,T.internal=!1),n=t==T.Broadphase_DYNAMIC_AABB_TREE):n=!0,n?this.bphase=new I._zpp.space.ZPP_DynAABBPhase(this):(T.Broadphase_SWEEP_AND_PRUNE==null&&(T.internal=!0,T.Broadphase_SWEEP_AND_PRUNE=new I._nape.space.Broadphase,T.internal=!1),t==T.Broadphase_SWEEP_AND_PRUNE&&(this.bphase=new I._zpp.space.ZPP_SweepPhase(this))),this.time=0;let l=this;e!=null?(this.gravityx=e.x,this.gravityy=e.y):(this.gravityx=0,this.gravityy=0),this.bodies=new I._zpp.util.ZNPList_ZPP_Body,this.wrap_bodies=I._zpp.util.ZPP_BodyList.get(this.bodies),this.wrap_bodies.zpp_inner.adder=s=>this.bodies_adder(s),this.wrap_bodies.zpp_inner.subber=s=>this.bodies_subber(s),this.wrap_bodies.zpp_inner._modifiable=()=>this.bodies_modifiable(),this.compounds=new I._zpp.util.ZNPList_ZPP_Compound,this.wrap_compounds=I._zpp.util.ZPP_CompoundList.get(this.compounds),this.wrap_compounds.zpp_inner.adder=s=>this.compounds_adder(s),this.wrap_compounds.zpp_inner.subber=s=>this.compounds_subber(s),this.wrap_compounds.zpp_inner._modifiable=()=>this.compounds_modifiable(),this.kinematics=new I._zpp.util.ZNPList_ZPP_Body,this.c_arbiters_true=new I._zpp.util.ZNPList_ZPP_ColArbiter,this.c_arbiters_false=new I._zpp.util.ZNPList_ZPP_ColArbiter,this.f_arbiters=new I._zpp.util.ZNPList_ZPP_FluidArbiter,this.s_arbiters=new I._zpp.util.ZNPList_ZPP_SensorArbiter,this.islands=new Mt,this.live=new I._zpp.util.ZNPList_ZPP_Body,this.wrap_live=I._zpp.util.ZPP_BodyList.get(this.live,!0),this.staticsleep=new I._zpp.util.ZNPList_ZPP_Body,this.constraints=new I._zpp.util.ZNPList_ZPP_Constraint,this.wrap_constraints=I._zpp.util.ZPP_ConstraintList.get(this.constraints),this.wrap_constraints.zpp_inner.adder=s=>this.constraints_adder(s),this.wrap_constraints.zpp_inner.subber=s=>this.constraints_subber(s),this.wrap_constraints.zpp_inner._modifiable=()=>this.constraints_modifiable(),this.live_constraints=new I._zpp.util.ZNPList_ZPP_Constraint,this.wrap_livecon=I._zpp.util.ZPP_ConstraintList.get(this.live_constraints,!0),this.__static=Wn.__static(),this.__static.zpp_inner.space=this,this.callbacks=new _t,this.midstep=!1,this.listeners=new I._zpp.util.ZNPList_ZPP_Listener,this.wrap_listeners=I._zpp.util.ZPP_ListenerList.get(this.listeners),this.wrap_listeners.zpp_inner.adder=s=>this.listeners_adder(s),this.wrap_listeners.zpp_inner.subber=s=>this.listeners_subber(s),this.wrap_listeners.zpp_inner._modifiable=()=>this.listeners_modifiable(),this.callbackset_list=new xn,this.mrca1=new I._zpp.util.ZNPList_ZPP_Interactor,this.mrca2=new I._zpp.util.ZNPList_ZPP_Interactor,this.prelisteners=new I._zpp.util.ZNPList_ZPP_InteractionListener,this.cbsets=new qs(this)}getgravity(){let e=this.gravityx,t=this.gravityy;if(t==null&&(t=0),e==null&&(e=0),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(I._zpp.util.ZPP_PubPool.poolVec2==null?n=new I._nape.geom.Vec2:(n=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let l;ie.zpp_pool==null?l=new ie:(l=ie.zpp_pool,ie.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=e,l.y=t,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x==e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),s=n.zpp_inner.y==t}else s=!1;if(!s){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=l=>this.gravity_invalidate(l),this.wrap_gravity.zpp_inner._validate=()=>this.gravity_validate()}gravity_invalidate(e){if(this.midstep)throw new Error("Error: Space::gravity cannot be set during space step");this.gravityx=e.x,this.gravityy=e.y;let t=new I._zpp.util.ZNPList_ZPP_Compound,n=this.bodies.head;for(;n!=null;){let i=n.elt;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1)),n=n.next}let l=this.compounds.head;for(;l!=null;){let s=l.elt;t.add(s),l=l.next}for(;t.head!=null;){let s=t.pop_unsafe(),i=s.bodies.head;for(;i!=null;){let a=i.elt;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1)),i=i.next}let r=s.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=xn.zpp_pool,xn.zpp_pool=n}for(;this.c_arbiters_true.head!=null;){let t=this.c_arbiters_true.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,r=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,r=!0;break}s=i,i=i.next}let o=t.b2.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=o.head,h=u.next,o.head=h,o.head==null&&(o.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(o.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,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 l=t.contacts,s=l.next;l.pop();let i=s;i.arbiter=null,i.next=we.zpp_pool,we.zpp_pool=i;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=gt.zpp_pool,gt.zpp_pool=n,t.pre_dt=-1}for(;this.c_arbiters_false.head!=null;){let t=this.c_arbiters_false.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,r=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,r=!0;break}s=i,i=i.next}let o=t.b2.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=o.head,h=u.next,o.head=h,o.head==null&&(o.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(o.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,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 l=t.contacts,s=l.next;l.pop();let i=s;i.arbiter=null,i.next=we.zpp_pool,we.zpp_pool=i;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=gt.zpp_pool,gt.zpp_pool=n,t.pre_dt=-1}for(;this.s_arbiters.head!=null;){let t=this.s_arbiters.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,r=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,r=!0;break}s=i,i=i.next}let o=t.b2.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=o.head,h=u.next,o.head=h,o.head==null&&(o.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(o.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,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=Qt.zpp_pool,Qt.zpp_pool=n}for(;this.f_arbiters.head!=null;){let t=this.f_arbiters.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,r=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,r=!0;break}s=i,i=i.next}let o=t.b2.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=o.head,h=u.next,o.head=h,o.head==null&&(o.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(o.pushmod=!0));let x=u;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,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=Bt.zpp_pool,Bt.zpp_pool=n,t.pre_dt=-1}for(this.bphase.clear();this.bodies.head!=null;){let t=this.bodies.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let s=n.comps.pop_unsafe();s.sleeping=!1,s.island=null,s.parent=s,s.rank=0}let l=n;l.next=Mt.zpp_pool,Mt.zpp_pool=l}}t.removedFromSpace(),t.space=null}for(;this.constraints.head!=null;){let t=this.constraints.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let s=n.comps.pop_unsafe();s.sleeping=!1,s.island=null,s.parent=s,s.rank=0}let l=n;l.next=Mt.zpp_pool,Mt.zpp_pool=l}}t.removedFromSpace(),t.space=null}this.kinematics.clear();let e=new I._zpp.util.ZNPList_ZPP_Compound;for(;this.compounds.head!=null;){let t=this.compounds.pop_unsafe();e.add(t)}for(;e.head!=null;){let t=e.pop_unsafe();t.removedFromSpace(),t.space=null;let n=t.bodies.head;for(;n!=null;){let i=n.elt;if(i.component!=null){let r=i.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=Mt.zpp_pool,Mt.zpp_pool=o}}i.removedFromSpace(),i.space=null,n=n.next}let l=t.constraints.head;for(;l!=null;){let i=l.elt;if(i.component!=null){let r=i.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=Mt.zpp_pool,Mt.zpp_pool=o}}i.removedFromSpace(),i.space=null,l=l.next}let s=t.compounds.head;for(;s!=null;){let i=s.elt;e.add(i),s=s.next}}this.staticsleep.clear(),this.live.clear(),this.live_constraints.clear(),this.stamp=0,this.time=0,this.mrca1.clear(),this.mrca2.clear(),this.prelisteners.clear(),this.cbsets.clear()}bodies_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_bodies.remove(e),this.addBody(e.zpp_inner),!0):!1}bodies_subber(e){this.remBody(e.zpp_inner)}bodies_modifiable(){if(this.midstep)throw new Error("Error: Space::bodies cannot be set during space step()")}compounds_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.wrap_compounds.remove(e),this.addCompound(e.zpp_inner),!0):!1}compounds_subber(e){this.remCompound(e.zpp_inner)}compounds_modifiable(){if(this.midstep)throw new Error("Error: Space::compounds cannot be set during space step()")}constraints_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_constraints.remove(e),this.addConstraint(e.zpp_inner),!0):!1}constraints_subber(e){this.remConstraint(e.zpp_inner)}constraints_modifiable(){if(this.midstep)throw new Error("Error: Space::constraints cannot be set during space step()")}listeners_adder(e){return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_listeners.remove(e),this.addListener(e.zpp_inner),!0):!1}listeners_subber(e){this.remListener(e.zpp_inner)}listeners_modifiable(){if(this.midstep)throw new Error("Error: Space::listeners cannot be set during space step()")}revoke_listener(e){}unrevoke_listener(e){}addListener(e){e.space=this,e.addedToSpace();let t=e.interaction!=null}remListener(e){let t=e.interaction!=null;e.removedFromSpace(),e.space=null}add_callbackset(e){let t=e.int1.cbsets,n;I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?n=new I._zpp.util.ZNPNode_ZPP_CallbackSet:(n=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=n.next,n.next=null),n.elt=e;let l=n;l.next=t.head,t.head=l,t.modified=!0,t.length++;let s=e.int2.cbsets,i;I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?i=new I._zpp.util.ZNPNode_ZPP_CallbackSet:(i=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=i.next,i.next=null),i.elt=e;let r=i;r.next=s.head,s.head=r,s.modified=!0,s.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,l=t.head,s=!1;for(;l!=null;){if(l.elt==e){let p,c;n==null?(p=t.head,c=p.next,t.head=c,t.head==null&&(t.pushmod=!0)):(p=n.next,c=p.next,n.next=c,c==null&&(t.pushmod=!0));let u=p;u.elt=null,u.next=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=u,t.modified=!0,t.length--,t.pushmod=!0,s=!0;break}n=l,l=l.next}let i=e.int2.cbsets,r=null,o=i.head,a=!1;for(;o!=null;){if(o.elt==e){let p,c;r==null?(p=i.head,c=p.next,i.head=c,i.head==null&&(i.pushmod=!0)):(p=r.next,c=p.next,r.next=c,c==null&&(i.pushmod=!0));let u=p;u.elt=null,u.next=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=u,i.modified=!0,i.length--,i.pushmod=!0,a=!0;break}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 l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0))}added_shape(e,t){if(t==null&&(t=!1),!t){let n=e.body;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!1))}this.bphase.insert(e),e.addedToSpace()}removed_shape(e,t){t==null&&(t=!1);let n=this,l=e.body;t||l.wake();let s=null,i=l.arbiters.head;for(;i!=null;){let r=i.elt;if(r.ws1==e||r.ws2==e){if(r.present!=0){this.MRCA_chains(r.ws1,r.ws2);let a=this.mrca1.head;for(;a!=null;){let p=a.elt,c=this.mrca2.head;for(;c!=null;){let u=c.elt,h=p.cbSet,x=u.cbSet;h.validate(),x.validate();let f=h.manager,_=null,b=(h.cbpairs.length<x.cbpairs.length?h.cbpairs:x.cbpairs).head;for(;b!=null;){let P=b.elt;if(P.a==h&&P.b==x||P.a==x&&P.b==h){_=P;break}b=b.next}if(_==null){let P;Se.zpp_pool==null?P=new Se:(P=Se.zpp_pool,Se.zpp_pool=P.next,P.next=null),P.zip_listeners=!0,St.setlt(h,x)?(P.a=h,P.b=x):(P.a=x,P.b=h),_=P,h.cbpairs.add(_),x!=h&&x.cbpairs.add(_)}if(_.zip_listeners&&(_.zip_listeners=!1,_.__validate()),_.listeners.head==null){c=c.next;continue}let m=I._zpp.phys.ZPP_Interactor.get(p,u);m.remove_arb(r),r.present--;let z=h.manager,M=null,w=(h.cbpairs.length<x.cbpairs.length?h.cbpairs:x.cbpairs).head;for(;w!=null;){let P=w.elt;if(P.a==h&&P.b==x||P.a==x&&P.b==h){M=P;break}w=w.next}if(M==null){let P;Se.zpp_pool==null?P=new Se:(P=Se.zpp_pool,Se.zpp_pool=P.next,P.next=null),P.zip_listeners=!0,St.setlt(h,x)?(P.a=h,P.b=x):(P.a=x,P.b=h),M=P,h.cbpairs.add(M),x!=h&&x.cbpairs.add(M)}M.zip_listeners&&(M.zip_listeners=!1,M.__validate());let v=M.listeners.head;for(;v!=null;){let P=v.elt;if(P.event==1&&(P.itype&r.type)!=0&&m.empty_arb(P.itype)){let g=n.push_callback(P);g.event=1;let E=m.int1,N=m.int2,k,Z=P.options1,C=E.cbTypes;if(Z.nonemptyintersection(C,Z.includes)&&!Z.nonemptyintersection(C,Z.excludes)){let F=P.options2,O=N.cbTypes;k=F.nonemptyintersection(O,F.includes)&&!F.nonemptyintersection(O,F.excludes)}else k=!1;k?(g.int1=E,g.int2=N):(g.int1=N,g.int2=E),g.set=m}v=v.next}m.arbiters.head==null&&this.remove_callbackset(m),c=c.next}a=a.next}}if(r.b1!=l&&r.b1.type==2){let a=r.b1;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(r.b2!=l&&r.b2.type==2){let a=r.b2;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(r.cleared=!0,l==null||r.b2==l){let a=r.b1.arbiters,p=null,c=a.head,u=!1;for(;c!=null;){if(c.elt==r){let h,x;p==null?(h=a.head,x=h.next,a.head=x,a.head==null&&(a.pushmod=!0)):(h=p.next,x=h.next,p.next=x,x==null&&(a.pushmod=!0));let f=h;f.elt=null,f.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,a.modified=!0,a.length--,a.pushmod=!0,u=!0;break}p=c,c=c.next}}if(l==null||r.b1==l){let a=r.b2.arbiters,p=null,c=a.head,u=!1;for(;c!=null;){if(c.elt==r){let h,x;p==null?(h=a.head,x=h.next,a.head=x,a.head==null&&(a.pushmod=!0)):(h=p.next,x=h.next,p.next=x,x==null&&(a.pushmod=!0));let f=h;f.elt=null,f.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,a.modified=!0,a.length--,a.pushmod=!0,u=!0;break}p=c,c=c.next}}r.pair!=null&&(r.pair.arb=null,r.pair=null),r.active=!1,this.f_arbiters.modified=!0,i=l.arbiters.erase(s);continue}s=i,i=i.next}this.bphase.remove(e),e.removedFromSpace()}addConstraint(e){e.space=this,e.addedToSpace(),e.active&&(e.component.sleeping=!0,this.wake_constraint(e,!0))}remConstraint(e){e.active&&(this.wake_constraint(e,!0),this.live_constraints.remove(e)),e.removedFromSpace(),e.space=null}addCompound(e){e.space=this,e.addedToSpace();let t=e.bodies.head;for(;t!=null;){let s=t.elt;this.addBody(s),t=t.next}let n=e.constraints.head;for(;n!=null;){let s=n.elt;this.addConstraint(s),n=n.next}let l=e.compounds.head;for(;l!=null;){let s=l.elt;this.addCompound(s),l=l.next}}remCompound(e){let t=e.bodies.head;for(;t!=null;){let s=t.elt;this.remBody(s),t=t.next}let n=e.constraints.head;for(;n!=null;){let s=n.elt;this.remConstraint(s),n=n.next}let l=e.compounds.head;for(;l!=null;){let s=l.elt;this.remCompound(s),l=l.next}e.removedFromSpace(),e.space=null}addBody(e,t){t==null&&(t=-1),e.space=this,e.addedToSpace(),e.component.sleeping=!0;let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!0));let l=e.shapes.head;for(;l!=null;){let s=l.elt,i=!0;if(i==null&&(i=!1),!i){let r=s.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(s),s.addedToSpace(),l=l.next}e.type==1?this.static_validation(e):e.type!=2&&t!=3&&this.kinematics.add(e)}remBody(e,t){if(t==null&&(t=-1),e.type==1){let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0)),this.staticsleep.remove(e)}else if(e.type==2){let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0)),this.live.remove(e)}else{t!=3&&this.kinematics.remove(e);let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0)),this.staticsleep.remove(e)}let n=e.shapes.head;for(;n!=null;){let l=n.elt;this.removed_shape(l,!0),n=n.next}e.removedFromSpace(),e.space=null}shapesUnderPoint(e,t,n,l){return this.bphase.shapesUnderPoint(e,t,n,l)}bodiesUnderPoint(e,t,n,l){return this.bphase.bodiesUnderPoint(e,t,n,l)}shapesInAABB(e,t,n,l,s){return this.bphase.shapesInAABB(e.zpp_inner,t,n,l,s)}bodiesInAABB(e,t,n,l,s){return this.bphase.bodiesInAABB(e.zpp_inner,t,n,l,s)}shapesInCircle(e,t,n,l,s){let i=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let 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(),i.shapesInCircle(o,e.zpp_inner.y,t,n,l,s)}bodiesInCircle(e,t,n,l,s){let i=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let 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(),i.bodiesInCircle(o,e.zpp_inner.y,t,n,l,s)}shapesInShape(e,t,n,l){return this.bphase.shapesInShape(e,t,n,l)}bodiesInShape(e,t,n,l){return this.bphase.bodiesInShape(e,t,n,l)}rayCast(e,t,n){return this.bphase.rayCast(e.zpp_inner,t,n==null?null:n.zpp_inner)}rayMultiCast(e,t,n,l){return this.bphase.rayMultiCast(e.zpp_inner,t,n==null?null:n.zpp_inner,l)}convexCast(e,t,n,l){let s;if(I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?s=new I._zpp.geom.ZPP_ToiEvent:(s=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=s.next,s.next=null),s.failed=!1,s.s1=s.s2=null,s.arbiter=null,e.type==0){let O=e.circle;if(O.zip_worldCOM&&O.body!=null){if(O.zip_worldCOM=!1,O.zip_localCOM){if(O.zip_localCOM=!1,O.type==1){let D=O.polygon;if(D.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(D.lverts.next.next==null)D.localCOMx=D.lverts.next.x,D.localCOMy=D.lverts.next.y;else if(D.lverts.next.next.next==null){D.localCOMx=D.lverts.next.x,D.localCOMy=D.lverts.next.y;let U=1;D.localCOMx+=D.lverts.next.next.x*U,D.localCOMy+=D.lverts.next.next.y*U;let W=.5;D.localCOMx*=W,D.localCOMy*=W}else{D.localCOMx=0,D.localCOMy=0;let U=0,W=D.lverts.next,q=W;W=W.next;let L=W;for(W=W.next;W!=null;){let ee=W;U+=L.x*(ee.y-q.y);let G=ee.y*L.x-ee.x*L.y;D.localCOMx+=(L.x+ee.x)*G,D.localCOMy+=(L.y+ee.y)*G,q=L,L=ee,W=W.next}W=D.lverts.next;let A=W;U+=L.x*(A.y-q.y);let J=A.y*L.x-A.x*L.y;D.localCOMx+=(L.x+A.x)*J,D.localCOMy+=(L.y+A.y)*J,q=L,L=A,W=W.next;let $=W;U+=L.x*($.y-q.y);let X=$.y*L.x-$.x*L.y;D.localCOMx+=(L.x+$.x)*X,D.localCOMy+=(L.y+$.y)*X,U=1/(3*U);let H=U;D.localCOMx*=H,D.localCOMy*=H}}O.wrap_localCOM!=null&&(O.wrap_localCOM.zpp_inner.x=O.localCOMx,O.wrap_localCOM.zpp_inner.y=O.localCOMy)}let B=O.body;B.zip_axis&&(B.zip_axis=!1,B.axisx=Math.sin(B.rot),B.axisy=Math.cos(B.rot)),O.worldCOMx=O.body.posx+(O.body.axisy*O.localCOMx-O.body.axisx*O.localCOMy),O.worldCOMy=O.body.posy+(O.localCOMx*O.body.axisx+O.localCOMy*O.body.axisy)}}else{let O=e.polygon;if(O.zip_gaxi&&O.body!=null){O.zip_gaxi=!1,O.validate_laxi();let B=O.body;if(B.zip_axis&&(B.zip_axis=!1,B.axisx=Math.sin(B.rot),B.axisy=Math.cos(B.rot)),O.zip_gverts&&O.body!=null){O.zip_gverts=!1,O.validate_lverts();let A=O.body;A.zip_axis&&(A.zip_axis=!1,A.axisx=Math.sin(A.rot),A.axisy=Math.cos(A.rot));let J=O.lverts.next,$=O.gverts.next;for(;$!=null;){let X=$,H=J;J=J.next,X.x=O.body.posx+(O.body.axisy*H.x-O.body.axisx*H.y),X.y=O.body.posy+(H.x*O.body.axisx+H.y*O.body.axisy),$=$.next}}let D=O.edges.head,U=O.gverts.next,W=U;for(U=U.next;U!=null;){let A=U,J=D.elt;D=D.next,J.gp0=W,J.gp1=A,J.gnormx=O.body.axisy*J.lnormx-O.body.axisx*J.lnormy,J.gnormy=J.lnormx*O.body.axisx+J.lnormy*O.body.axisy,J.gprojection=O.body.posx*J.gnormx+O.body.posy*J.gnormy+J.lprojection,J.wrap_gnorm!=null&&(J.wrap_gnorm.zpp_inner.x=J.gnormx,J.wrap_gnorm.zpp_inner.y=J.gnormy),J.tp0=J.gp0.y*J.gnormx-J.gp0.x*J.gnormy,J.tp1=J.gp1.y*J.gnormx-J.gp1.x*J.gnormy,W=A,U=U.next}let q=O.gverts.next,L=D.elt;D=D.next,L.gp0=W,L.gp1=q,L.gnormx=O.body.axisy*L.lnormx-O.body.axisx*L.lnormy,L.gnormy=L.lnormx*O.body.axisx+L.lnormy*O.body.axisy,L.gprojection=O.body.posx*L.gnormx+O.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 i=e.body,r=i.posx,o=i.posy;i.sweepTime=0,i.sweep_angvel=i.angvel;let a=t-i.sweepTime;if(a!=0){i.sweepTime=t;let O=a;if(i.posx+=i.velx*O,i.posy+=i.vely*O,i.angvel!=0){let B=i.sweep_angvel*a;if(i.rot+=B,B*B>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let D=B*B,U=1-.5*D,W=1-D*D/8,q=(U*i.axisx+B*i.axisy)*W;i.axisy=(U*i.axisy-B*i.axisx)*W,i.axisx=q}}}let p=i.posx,c=i.posy;e.validate_sweepRadius();let u=e.sweepRadius,h;fe.zpp_pool==null?h=new fe:(h=fe.zpp_pool,fe.zpp_pool=h.next,h.next=null);let x=r,f=p;h.minx=(x<f?x:f)-u;let _=r,d=p;h.maxx=(_>d?_:d)+u;let b=o,m=c;h.miny=(b<m?b:m)-u;let z=o,M=c;h.maxy=(z>M?z:M)+u;let y=this.convexShapeList=this.bphase.shapesInAABB(h,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),w=h;w.outer!=null&&(w.outer.zpp_inner=null,w.outer=null),w.wrap_min=w.wrap_max=null,w._invalidate=null,w._validate=null,w.next=fe.zpp_pool,fe.zpp_pool=w;let v=0,P=0;v=0,P=0;let g=0,E=0;g=0,E=0;let N=null,k=t+1;y.zpp_inner.valmod();let Z=I._nape.shape.ShapeIterator.get(y);for(;;){Z.zpp_inner.zpp_inner.valmod();let O=Z.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 B=O.zpp_inner.user_length;Z.zpp_critical=!0;let D;if(Z.zpp_i<B?D=!0:(Z.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=Z,Z.zpp_inner=null,D=!1),!D)break;Z.zpp_critical=!1;let U=Z.zpp_inner.at(Z.zpp_i++);if(U!=e.outer&&(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null)!=i.outer){if(s.s1=e,s.s2=U.zpp_inner,l){U.zpp_inner.validate_sweepRadius(),(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner.angvel,(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,un.dynamicSweep(s,t,0,0,!0);let W=(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner,q=0-W.sweepTime;if(q!=0){W.sweepTime=0;let J=q;if(W.posx+=W.velx*J,W.posy+=W.vely*J,W.angvel!=0){let $=W.sweep_angvel*q;if(W.rot+=$,$*$>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let X=$*$,H=1-.5*X,ee=1-X*X/8,G=(H*W.axisx+$*W.axisy)*ee;W.axisy=(H*W.axisy-$*W.axisx)*ee,W.axisx=G}}}let L=(U.zpp_inner.body!=null?U.zpp_inner.body.outer:null).zpp_inner,A=U.zpp_inner;if(A.type==0)A.worldCOMx=L.posx+(L.axisy*A.localCOMx-L.axisx*A.localCOMy),A.worldCOMy=L.posy+(A.localCOMx*L.axisx+A.localCOMy*L.axisy);else{let J=A.polygon,$=J.lverts.next,X=J.gverts.next;for(;X!=null;){let V=X,K=$;$=$.next,V.x=L.posx+(L.axisy*K.x-L.axisx*K.y),V.y=L.posy+(K.x*L.axisx+K.y*L.axisy),X=X.next}let H=J.edges.head,ee=J.gverts.next,G=ee;for(ee=ee.next;ee!=null;){let V=ee,K=H.elt;H=H.next,K.gnormx=L.axisy*K.lnormx-L.axisx*K.lnormy,K.gnormy=K.lnormx*L.axisx+K.lnormy*L.axisy,K.gprojection=L.posx*K.gnormx+L.posy*K.gnormy+K.lprojection,K.tp0=G.y*K.gnormx-G.x*K.gnormy,K.tp1=V.y*K.gnormx-V.x*K.gnormy,G=V,ee=ee.next}let R=J.gverts.next,j=H.elt;H=H.next,j.gnormx=L.axisy*j.lnormx-L.axisx*j.lnormy,j.gnormy=j.lnormx*L.axisx+j.lnormy*L.axisy,j.gprojection=L.posx*j.gnormx+L.posy*j.gnormy+j.lprojection,j.tp0=G.y*j.gnormx-G.x*j.gnormy,j.tp1=R.y*j.gnormx-R.x*j.gnormy}}else un.staticSweep(s,t,0,0);s.toi*=t,s.toi>0&&s.toi<k&&(k=s.toi,v=s.axis.x,P=s.axis.y,g=s.c2.x,E=s.c2.y,N=U)}}y.clear();let C=s;C.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=C;let F=0-i.sweepTime;if(F!=0){i.sweepTime=0;let O=F;if(i.posx+=i.velx*O,i.posy+=i.vely*O,i.angvel!=0){let B=i.sweep_angvel*F;if(i.rot+=B,B*B>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let D=B*B,U=1-.5*D,W=1-D*D/8,q=(U*i.axisx+B*i.axisy)*W;i.axisy=(U*i.axisy-B*i.axisx)*W,i.axisx=q}}}if(e.type==0)e.worldCOMx=i.posx+(i.axisy*e.localCOMx-i.axisx*e.localCOMy),e.worldCOMy=i.posy+(e.localCOMx*i.axisx+e.localCOMy*i.axisy);else{let O=e.polygon,B=O.lverts.next,D=O.gverts.next;for(;D!=null;){let J=D,$=B;B=B.next,J.x=i.posx+(i.axisy*$.x-i.axisx*$.y),J.y=i.posy+($.x*i.axisx+$.y*i.axisy),D=D.next}let U=O.edges.head,W=O.gverts.next,q=W;for(W=W.next;W!=null;){let J=W,$=U.elt;U=U.next,$.gnormx=i.axisy*$.lnormx-i.axisx*$.lnormy,$.gnormy=$.lnormx*i.axisx+$.lnormy*i.axisy,$.gprojection=i.posx*$.gnormx+i.posy*$.gnormy+$.lprojection,$.tp0=q.y*$.gnormx-q.x*$.gnormy,$.tp1=J.y*$.gnormx-J.x*$.gnormy,q=J,W=W.next}let L=O.gverts.next,A=U.elt;U=U.next,A.gnormx=i.axisy*A.lnormx-i.axisx*A.lnormy,A.gnormy=A.lnormx*i.axisx+A.lnormy*i.axisy,A.gprojection=i.posx*A.gnormx+i.posy*A.gnormy+A.lprojection,A.tp0=q.y*A.gnormx-q.x*A.gnormy,A.tp1=L.y*A.gnormx-L.x*A.gnormy}if(k<=t){let O=-v,B=-P;if(B==null&&(B=0),O==null&&(O=0),O!=O||B!=B)throw new Error("Error: Vec2 components cannot be NaN");let D;if(I._zpp.util.ZPP_PubPool.poolVec2==null?D=new I._nape.geom.Vec2:(D=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=D.zpp_pool,D.zpp_pool=null,D.zpp_disp=!1,D==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),D.zpp_inner==null){let L;ie.zpp_pool==null?L=new ie:(L=ie.zpp_pool,ie.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=O,L.y=B,D.zpp_inner=L,D.zpp_inner.outer=D}else{if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=D.zpp_inner;if(L._immutable)throw new Error("Error: Vec2 is immutable");if(L._isimmutable!=null&&L._isimmutable(),O!=O||B!=B)throw new Error("Error: Vec2 components cannot be NaN");let A;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let J=D.zpp_inner;if(J._validate!=null&&J._validate(),D.zpp_inner.x==O){if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let $=D.zpp_inner;$._validate!=null&&$._validate(),A=D.zpp_inner.y==B}else A=!1;if(!A){D.zpp_inner.x=O,D.zpp_inner.y=B;let $=D.zpp_inner;$._invalidate!=null&&$._invalidate($)}}D.zpp_inner.weak=!1;let U=g,W=E;if(W==null&&(W=0),U==null&&(U=0),U!=U||W!=W)throw new Error("Error: Vec2 components cannot be NaN");let q;if(I._zpp.util.ZPP_PubPool.poolVec2==null?q=new I._nape.geom.Vec2:(q=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=q.zpp_pool,q.zpp_pool=null,q.zpp_disp=!1,q==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),q.zpp_inner==null){let L;ie.zpp_pool==null?L=new ie:(L=ie.zpp_pool,ie.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=U,L.y=W,q.zpp_inner=L,q.zpp_inner.outer=q}else{if(q!=null&&q.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=q.zpp_inner;if(L._immutable)throw new Error("Error: Vec2 is immutable");if(L._isimmutable!=null&&L._isimmutable(),U!=U||W!=W)throw new Error("Error: Vec2 components cannot be NaN");let A;if(q!=null&&q.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let J=q.zpp_inner;if(J._validate!=null&&J._validate(),q.zpp_inner.x==U){if(q!=null&&q.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let $=q.zpp_inner;$._validate!=null&&$._validate(),A=q.zpp_inner.y==W}else A=!1;if(!A){q.zpp_inner.x=U,q.zpp_inner.y=W;let $=q.zpp_inner;$._invalidate!=null&&$._invalidate($)}}return q.zpp_inner.weak=!1,I._zpp.geom.ZPP_ConvexRayResult.getConvex(D,q,k,N)}else return null}prepareCast(e){if(e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let s=1;l.localCOMx+=l.lverts.next.next.x*s,l.localCOMy+=l.lverts.next.next.y*s;let i=.5;l.localCOMx*=i,l.localCOMy*=i}else{l.localCOMx=0,l.localCOMy=0;let s=0,i=l.lverts.next,r=i;i=i.next;let o=i;for(i=i.next;i!=null;){let x=i;s+=o.x*(x.y-r.y);let f=x.y*o.x-x.x*o.y;l.localCOMx+=(o.x+x.x)*f,l.localCOMy+=(o.y+x.y)*f,r=o,o=x,i=i.next}i=l.lverts.next;let a=i;s+=o.x*(a.y-r.y);let p=a.y*o.x-a.x*o.y;l.localCOMx+=(o.x+a.x)*p,l.localCOMy+=(o.y+a.y)*p,r=o,o=a,i=i.next;let c=i;s+=o.x*(c.y-r.y);let u=c.y*o.x-c.x*o.y;l.localCOMx+=(o.x+c.x)*u,l.localCOMy+=(o.y+c.y)*u,s=1/(3*s);let h=s;l.localCOMx*=h,l.localCOMy*=h}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let n=t.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}}else{let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=t.body.posx+(t.body.axisy*h.x-t.body.axisx*h.y),u.y=t.body.posy+(h.x*t.body.axisx+h.y*t.body.axisy),c=c.next}}let l=t.edges.head,s=t.gverts.next,i=s;for(s=s.next;s!=null;){let a=s,p=l.elt;l=l.next,p.gp0=i,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,i=a,s=s.next}let r=t.gverts.next,o=l.elt;l=l.next,o.gp0=i,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,l,s){let i;if(I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?i=new I._zpp.geom.ZPP_ToiEvent:(i=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=i.next,i.next=null),i.failed=!1,i.s1=i.s2=null,i.arbiter=null,e.type==0){let k=e.circle;if(k.zip_worldCOM&&k.body!=null){if(k.zip_worldCOM=!1,k.zip_localCOM){if(k.zip_localCOM=!1,k.type==1){let C=k.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 F=1;C.localCOMx+=C.lverts.next.next.x*F,C.localCOMy+=C.lverts.next.next.y*F;let O=.5;C.localCOMx*=O,C.localCOMy*=O}else{C.localCOMx=0,C.localCOMy=0;let F=0,O=C.lverts.next,B=O;O=O.next;let D=O;for(O=O.next;O!=null;){let J=O;F+=D.x*(J.y-B.y);let $=J.y*D.x-J.x*D.y;C.localCOMx+=(D.x+J.x)*$,C.localCOMy+=(D.y+J.y)*$,B=D,D=J,O=O.next}O=C.lverts.next;let U=O;F+=D.x*(U.y-B.y);let W=U.y*D.x-U.x*D.y;C.localCOMx+=(D.x+U.x)*W,C.localCOMy+=(D.y+U.y)*W,B=D,D=U,O=O.next;let q=O;F+=D.x*(q.y-B.y);let L=q.y*D.x-q.x*D.y;C.localCOMx+=(D.x+q.x)*L,C.localCOMy+=(D.y+q.y)*L,F=1/(3*F);let A=F;C.localCOMx*=A,C.localCOMy*=A}}k.wrap_localCOM!=null&&(k.wrap_localCOM.zpp_inner.x=k.localCOMx,k.wrap_localCOM.zpp_inner.y=k.localCOMy)}let Z=k.body;Z.zip_axis&&(Z.zip_axis=!1,Z.axisx=Math.sin(Z.rot),Z.axisy=Math.cos(Z.rot)),k.worldCOMx=k.body.posx+(k.body.axisy*k.localCOMx-k.body.axisx*k.localCOMy),k.worldCOMy=k.body.posy+(k.localCOMx*k.body.axisx+k.localCOMy*k.body.axisy)}}else{let k=e.polygon;if(k.zip_gaxi&&k.body!=null){k.zip_gaxi=!1,k.validate_laxi();let Z=k.body;if(Z.zip_axis&&(Z.zip_axis=!1,Z.axisx=Math.sin(Z.rot),Z.axisy=Math.cos(Z.rot)),k.zip_gverts&&k.body!=null){k.zip_gverts=!1,k.validate_lverts();let U=k.body;U.zip_axis&&(U.zip_axis=!1,U.axisx=Math.sin(U.rot),U.axisy=Math.cos(U.rot));let W=k.lverts.next,q=k.gverts.next;for(;q!=null;){let L=q,A=W;W=W.next,L.x=k.body.posx+(k.body.axisy*A.x-k.body.axisx*A.y),L.y=k.body.posy+(A.x*k.body.axisx+A.y*k.body.axisy),q=q.next}}let C=k.edges.head,F=k.gverts.next,O=F;for(F=F.next;F!=null;){let U=F,W=C.elt;C=C.next,W.gp0=O,W.gp1=U,W.gnormx=k.body.axisy*W.lnormx-k.body.axisx*W.lnormy,W.gnormy=W.lnormx*k.body.axisx+W.lnormy*k.body.axisy,W.gprojection=k.body.posx*W.gnormx+k.body.posy*W.gnormy+W.lprojection,W.wrap_gnorm!=null&&(W.wrap_gnorm.zpp_inner.x=W.gnormx,W.wrap_gnorm.zpp_inner.y=W.gnormy),W.tp0=W.gp0.y*W.gnormx-W.gp0.x*W.gnormy,W.tp1=W.gp1.y*W.gnormx-W.gp1.x*W.gnormy,O=U,F=F.next}let B=k.gverts.next,D=C.elt;C=C.next,D.gp0=O,D.gp1=B,D.gnormx=k.body.axisy*D.lnormx-k.body.axisx*D.lnormy,D.gnormy=D.lnormx*k.body.axisx+D.lnormy*k.body.axisy,D.gprojection=k.body.posx*D.gnormx+k.body.posy*D.gnormy+D.lprojection,D.wrap_gnorm!=null&&(D.wrap_gnorm.zpp_inner.x=D.gnormx,D.wrap_gnorm.zpp_inner.y=D.gnormy),D.tp0=D.gp0.y*D.gnormx-D.gp0.x*D.gnormy,D.tp1=D.gp1.y*D.gnormx-D.gp1.x*D.gnormy}}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 k=p;if(r.posx+=r.velx*k,r.posy+=r.vely*k,r.angvel!=0){let Z=r.sweep_angvel*p;if(r.rot+=Z,Z*Z>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let C=Z*Z,F=1-.5*C,O=1-C*C/8,B=(F*r.axisx+Z*r.axisy)*O;r.axisy=(F*r.axisy-Z*r.axisx)*O,r.axisx=B}}}let c=r.posx,u=r.posy;e.validate_sweepRadius();let h=e.sweepRadius,x;fe.zpp_pool==null?x=new fe:(x=fe.zpp_pool,fe.zpp_pool=x.next,x.next=null);let f=o,_=c;x.minx=(f<_?f:_)-h;let d=o,b=c;x.maxx=(d>b?d:b)+h;let m=a,z=u;x.miny=(m<z?m:z)-h;let M=a,y=u;x.maxy=(M>y?M:y)+h;let w=this.convexShapeList=this.bphase.shapesInAABB(x,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),v=x;v.outer!=null&&(v.outer.zpp_inner=null,v.outer=null),v.wrap_min=v.wrap_max=null,v._invalidate=null,v._validate=null,v.next=fe.zpp_pool,fe.zpp_pool=v;let P=s??new I._nape.geom.ConvexResultList;w.zpp_inner.valmod();let g=I._nape.shape.ShapeIterator.get(w);for(;;){g.zpp_inner.zpp_inner.valmod();let k=g.zpp_inner;k.zpp_inner.valmod(),k.zpp_inner.zip_length&&(k.zpp_inner.zip_length=!1,k.zpp_inner.user_length=k.zpp_inner.inner.length);let Z=k.zpp_inner.user_length;g.zpp_critical=!0;let C;if(g.zpp_i<Z?C=!0:(g.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=g,g.zpp_inner=null,C=!1),!C)break;g.zpp_critical=!1;let F=g.zpp_inner.at(g.zpp_i++);if(F!=e.outer&&(F.zpp_inner.body!=null?F.zpp_inner.body.outer:null)!=r.outer){if(i.s1=e,i.s2=F.zpp_inner,l){F.zpp_inner.validate_sweepRadius(),(F.zpp_inner.body!=null?F.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(F.zpp_inner.body!=null?F.zpp_inner.body.outer:null).zpp_inner.angvel,(F.zpp_inner.body!=null?F.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,un.dynamicSweep(i,t,0,0,!0);let O=(F.zpp_inner.body!=null?F.zpp_inner.body.outer:null).zpp_inner,B=0-O.sweepTime;if(B!=0){O.sweepTime=0;let W=B;if(O.posx+=O.velx*W,O.posy+=O.vely*W,O.angvel!=0){let q=O.sweep_angvel*B;if(O.rot+=q,q*q>1e-4)O.axisx=Math.sin(O.rot),O.axisy=Math.cos(O.rot);else{let L=q*q,A=1-.5*L,J=1-L*L/8,$=(A*O.axisx+q*O.axisy)*J;O.axisy=(A*O.axisy-q*O.axisx)*J,O.axisx=$}}}let D=(F.zpp_inner.body!=null?F.zpp_inner.body.outer:null).zpp_inner,U=F.zpp_inner;if(U.type==0)U.worldCOMx=D.posx+(D.axisy*U.localCOMx-D.axisx*U.localCOMy),U.worldCOMy=D.posy+(U.localCOMx*D.axisx+U.localCOMy*D.axisy);else{let W=U.polygon,q=W.lverts.next,L=W.gverts.next;for(;L!=null;){let ee=L,G=q;q=q.next,ee.x=D.posx+(D.axisy*G.x-D.axisx*G.y),ee.y=D.posy+(G.x*D.axisx+G.y*D.axisy),L=L.next}let A=W.edges.head,J=W.gverts.next,$=J;for(J=J.next;J!=null;){let ee=J,G=A.elt;A=A.next,G.gnormx=D.axisy*G.lnormx-D.axisx*G.lnormy,G.gnormy=G.lnormx*D.axisx+G.lnormy*D.axisy,G.gprojection=D.posx*G.gnormx+D.posy*G.gnormy+G.lprojection,G.tp0=$.y*G.gnormx-$.x*G.gnormy,G.tp1=ee.y*G.gnormx-ee.x*G.gnormy,$=ee,J=J.next}let X=W.gverts.next,H=A.elt;A=A.next,H.gnormx=D.axisy*H.lnormx-D.axisx*H.lnormy,H.gnormy=H.lnormx*D.axisx+H.lnormy*D.axisy,H.gprojection=D.posx*H.gnormx+D.posy*H.gnormy+H.lprojection,H.tp0=$.y*H.gnormx-$.x*H.gnormy,H.tp1=X.y*H.gnormx-X.x*H.gnormy}}else un.staticSweep(i,t,0,0);if(i.toi*=t,i.toi>0){let O=-i.axis.x,B=-i.axis.y;if(B==null&&(B=0),O==null&&(O=0),O!=O||B!=B)throw new Error("Error: Vec2 components cannot be NaN");let D;if(I._zpp.util.ZPP_PubPool.poolVec2==null?D=new I._nape.geom.Vec2:(D=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=D.zpp_pool,D.zpp_pool=null,D.zpp_disp=!1,D==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),D.zpp_inner==null){let ee;ie.zpp_pool==null?ee=new ie:(ee=ie.zpp_pool,ie.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=O,ee.y=B,D.zpp_inner=ee,D.zpp_inner.outer=D}else{if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=D.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),O!=O||B!=B)throw new Error("Error: Vec2 components cannot be NaN");let G;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let R=D.zpp_inner;if(R._validate!=null&&R._validate(),D.zpp_inner.x==O){if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let j=D.zpp_inner;j._validate!=null&&j._validate(),G=D.zpp_inner.y==B}else G=!1;if(!G){D.zpp_inner.x=O,D.zpp_inner.y=B;let j=D.zpp_inner;j._invalidate!=null&&j._invalidate(j)}}D.zpp_inner.weak=!1;let U=i.c2.x,W=i.c2.y;if(W==null&&(W=0),U==null&&(U=0),U!=U||W!=W)throw new Error("Error: Vec2 components cannot be NaN");let q;if(I._zpp.util.ZPP_PubPool.poolVec2==null?q=new I._nape.geom.Vec2:(q=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=q.zpp_pool,q.zpp_pool=null,q.zpp_disp=!1,q==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),q.zpp_inner==null){let ee;ie.zpp_pool==null?ee=new ie:(ee=ie.zpp_pool,ie.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=U,ee.y=W,q.zpp_inner=ee,q.zpp_inner.outer=q}else{if(q!=null&&q.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=q.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),U!=U||W!=W)throw new Error("Error: Vec2 components cannot be NaN");let G;if(q!=null&&q.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let R=q.zpp_inner;if(R._validate!=null&&R._validate(),q.zpp_inner.x==U){if(q!=null&&q.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let j=q.zpp_inner;j._validate!=null&&j._validate(),G=q.zpp_inner.y==W}else G=!1;if(!G){q.zpp_inner.x=U,q.zpp_inner.y=W;let j=q.zpp_inner;j._invalidate!=null&&j._invalidate(j)}}q.zpp_inner.weak=!1;let L=I._zpp.geom.ZPP_ConvexRayResult.getConvex(D,q,i.toi,F),A=null,J=P.zpp_inner.inner.head;for(;J!=null;){let ee=J.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;A=J,J=J.next}let $=P.zpp_inner.inner,X;I._zpp.util.ZNPNode_ConvexResult.zpp_pool==null?X=new I._zpp.util.ZNPNode_ConvexResult:(X=I._zpp.util.ZNPNode_ConvexResult.zpp_pool,I._zpp.util.ZNPNode_ConvexResult.zpp_pool=X.next,X.next=null),X.elt=L;let H=X;A==null?(H.next=$.head,$.head=H):(H.next=A.next,A.next=H),$.pushmod=$.modified=!0,$.length++}}}w.clear();let E=i;E.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=E;let N=0-r.sweepTime;if(N!=0){r.sweepTime=0;let k=N;if(r.posx+=r.velx*k,r.posy+=r.vely*k,r.angvel!=0){let Z=r.sweep_angvel*N;if(r.rot+=Z,Z*Z>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let C=Z*Z,F=1-.5*C,O=1-C*C/8,B=(F*r.axisx+Z*r.axisy)*O;r.axisy=(F*r.axisy-Z*r.axisx)*O,r.axisx=B}}}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 k=e.polygon,Z=k.lverts.next,C=k.gverts.next;for(;C!=null;){let W=C,q=Z;Z=Z.next,W.x=r.posx+(r.axisy*q.x-r.axisx*q.y),W.y=r.posy+(q.x*r.axisx+q.y*r.axisy),C=C.next}let F=k.edges.head,O=k.gverts.next,B=O;for(O=O.next;O!=null;){let W=O,q=F.elt;F=F.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=B.y*q.gnormx-B.x*q.gnormy,q.tp1=W.y*q.gnormx-W.x*q.gnormy,B=W,O=O.next}let D=k.gverts.next,U=F.elt;F=F.next,U.gnormx=r.axisy*U.lnormx-r.axisx*U.lnormy,U.gnormy=U.lnormx*r.axisx+U.lnormy*r.axisy,U.gprojection=r.posx*U.gnormx+r.posy*U.gnormy+U.lprojection,U.tp0=B.y*U.gnormx-B.x*U.gnormy,U.tp1=D.y*U.gnormx-D.x*U.gnormy}return P}push_callback(e){let t;return _t.zpp_pool==null?t=new _t:(t=_t.zpp_pool,_t.zpp_pool=t.next,t.next=null),this.callbacks.push(t),t.listener=e,t}step(e,t,n){let l=this;if(this.midstep)throw new Error("Error: ... REALLY?? you're going to call space.step() inside of space.step()? COME ON!!");if(this.time+=e,this.pre_dt=e,this.midstep=!0,this.stamp++,this.validation(),this.bphase.broadphase(this,!0),this.prestep(e),this.sortcontacts){let h=this.c_arbiters_false;if(h.head!=null&&h.head.next!=null){let x=h.head,f=null,_=null,d=null,b=null,m=1,z,M,y;for(;;){for(z=0,_=x,x=null,f=x;_!=null;){for(++z,d=_,M=0,y=m;d!=null&&M<m;)++M,d=d.next;for(;M>0||y>0&&d!=null;)M==0?(b=d,d=d.next,--y):y==0||d==null||!(_.elt.active&&d.elt.active)||_.elt.oc1.dist<d.elt.oc1.dist?(b=_,_=_.next,--M):(b=d,d=d.next,--y),f!=null?f.next=b:x=b,f=b;_=d}if(f.next=null,m<<=1,!(z>1))break}h.head=x,h.modified=!0,h.pushmod=!0}}this.updateVel(e),this.warmStart(),this.iterateVel(t);let s=this.kinematics.head;for(;s!=null;){let h=s.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,s=s.next}let i=this.live.head;for(;i!=null;){let h=i.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,i=i.next}this.updatePos(e),this.continuous=!0,this.continuousCollisions(e),this.continuous=!1,this.iteratePos(n);let r=this.kinematics.head;for(;r!=null;){let h=r.elt,x=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),f=h.pre_rot!=h.rot;if(x){let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}if(f){h.zip_axis=!0;let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}r=r.next}let o=this.live.head;for(;o!=null;){let h=o.elt,x=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),f=h.pre_rot!=h.rot;if(x){let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}if(f){h.zip_axis=!0;let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}o=o.next}let a=null,p=this.staticsleep.head;for(;p!=null;){let h=p.elt;if(h.type!=3||h.velx==0&&h.vely==0&&h.angvel==0){if(h.kinematicDelaySleep){h.kinematicDelaySleep=!1,p=p.next;continue}h.component.sleeping=!0;let x=this.staticsleep,f,_;a==null?(f=x.head,_=f.next,x.head=_,x.head==null&&(x.pushmod=!0)):(f=a.next,_=f.next,a.next=_,_==null&&(x.pushmod=!0));let d=f;d.elt=null,d.next=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=d,x.modified=!0,x.length--,x.pushmod=!0,p=_;continue}a=p,p=p.next}this.doForests(e),this.sleepArbiters(),this.midstep=!1;let c=null,u=this.callbackset_list.next;for(;u!=null;){let h=u;if(h.arbiters.head==null){let v=this.callbackset_list,P,g;c==null?(P=v.next,g=P.next,v.next=g,v.next==null&&(v.pushmod=!0)):(P=c.next,g=P.next,c.next=g,g==null&&(v.pushmod=!0)),P._inuse=!1,v.modified=!0,v.length--,v.pushmod=!0,u=g;let E=h;E.int1=E.int2=null,E.id=E.di=-1,E.freed=!0,E.next=xn.zpp_pool,xn.zpp_pool=E;continue}let x;x=!0;let f=h.arbiters.head;for(;f!=null;)if(f.elt.sleeping){f=f.next;continue}else{x=!1;break}let _=x,d=h.int1.cbSet,b=h.int2.cbSet,m=d.manager,z=null,y=(d.cbpairs.length<b.cbpairs.length?d.cbpairs:b.cbpairs).head;for(;y!=null;){let v=y.elt;if(v.a==d&&v.b==b||v.a==b&&v.b==d){z=v;break}y=y.next}if(z==null){let v;Se.zpp_pool==null?v=new Se:(v=Se.zpp_pool,Se.zpp_pool=v.next,v.next=null),v.zip_listeners=!0,St.setlt(d,b)?(v.a=d,v.b=b):(v.a=b,v.b=d),z=v,d.cbpairs.add(z),b!=d&&b.cbpairs.add(z)}z.zip_listeners&&(z.zip_listeners=!1,z.__validate());let w=z.listeners.head;for(;w!=null;){let v=w.elt;if(v.event==6&&(!_||v.allowSleepingCallbacks)&&!h.empty_arb(v.itype)){let P=l.push_callback(v);P.event=6;let g=h.int1,E=h.int2,N,k=v.options1,Z=g.cbTypes;if(k.nonemptyintersection(Z,k.includes)&&!k.nonemptyintersection(Z,k.excludes)){let C=v.options2,F=E.cbTypes;N=C.nonemptyintersection(F,C.includes)&&!C.nonemptyintersection(F,C.excludes)}else N=!1;N?(P.int1=g,P.int2=E):(P.int1=E,P.int2=g),P.set=h}w=w.next}c=u,u=u.next}for(;!this.callbacks.empty();){let h=this.callbacks.pop();h.listener.type==0?h.listener.body.handler(h.wrapper_body()):h.listener.type==1?h.listener.constraint.handler(h.wrapper_con()):h.listener.type==2&&h.listener.interaction.handleri(h.wrapper_int());let x=h;x.int1=x.int2=null,x.body=null,x.constraint=null,x.listener=null,x.wrap_arbiters!=null&&(x.wrap_arbiters.zpp_inner.inner=null),x.set=null,x.next=_t.zpp_pool,_t.zpp_pool=x}}continuousCollisions(e){let t=2*Math.PI/e;this.bphase.broadphase(this,!1);let n=0;for(;n<1&&this.toiEvents.head!=null;){let i=null,r=2,o=!1,a=null,p=null,c=this.toiEvents.head;for(;c!=null;){let d=c.elt,b=d.s1.body,m=d.s2.body;if(b.sweepFrozen&&m.sweepFrozen)if(d.toi!=0&&Ne.testCollide_safe(d.s1,d.s2))d.toi=0;else{c=this.toiEvents.erase(p);let z=d;z.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=z;continue}if(d.frozen1!=b.sweepFrozen||d.frozen2!=m.sweepFrozen)if(d.kinematic){c=this.toiEvents.erase(p);let z=d;z.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=z;continue}else{if(d.frozen1=b.sweepFrozen,d.frozen2=m.sweepFrozen,d.frozen1){let z=d.s1;d.s1=d.s2,d.s2=z,d.frozen1=!1,d.frozen2=!0}if(un.staticSweep(d,e,0,I._nape.Config.collisionSlopCCD),d.toi<0){c=this.toiEvents.erase(p);let z=d;z.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=z;continue}}d.toi>=0&&(d.toi<r||!o&&d.kinematic)&&(i=d,r=d.toi,o=d.kinematic,a=p),p=c,c=c.next}if(i==null)break;this.toiEvents.erase(a),n=i.toi;let u=i.s1.body,h=i.s2.body;if(!u.sweepFrozen){let d=n*e,b=d-u.sweepTime;if(b!=0){u.sweepTime=d;let z=b;if(u.posx+=u.velx*z,u.posy+=u.vely*z,u.angvel!=0){let M=u.sweep_angvel*b;if(u.rot+=M,M*M>1e-4)u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot);else{let y=M*M,w=1-.5*y,v=1-y*y/8,P=(w*u.axisx+M*u.axisy)*v;u.axisy=(w*u.axisy-M*u.axisx)*v,u.axisx=P}}}let m=i.s1;if(m.type==0)m.worldCOMx=u.posx+(u.axisy*m.localCOMx-u.axisx*m.localCOMy),m.worldCOMy=u.posy+(m.localCOMx*u.axisx+m.localCOMy*u.axisy);else{let z=m.polygon,M=z.lverts.next,y=z.gverts.next;for(;y!=null;){let N=y,k=M;M=M.next,N.x=u.posx+(u.axisy*k.x-u.axisx*k.y),N.y=u.posy+(k.x*u.axisx+k.y*u.axisy),y=y.next}let w=z.edges.head,v=z.gverts.next,P=v;for(v=v.next;v!=null;){let N=v,k=w.elt;w=w.next,k.gnormx=u.axisy*k.lnormx-u.axisx*k.lnormy,k.gnormy=k.lnormx*u.axisx+k.lnormy*u.axisy,k.gprojection=u.posx*k.gnormx+u.posy*k.gnormy+k.lprojection,k.tp0=P.y*k.gnormx-P.x*k.gnormy,k.tp1=N.y*k.gnormx-N.x*k.gnormy,P=N,v=v.next}let g=z.gverts.next,E=w.elt;w=w.next,E.gnormx=u.axisy*E.lnormx-u.axisx*E.lnormy,E.gnormy=E.lnormx*u.axisx+E.lnormy*u.axisy,E.gprojection=u.posx*E.gnormx+u.posy*E.gnormy+E.lprojection,E.tp0=P.y*E.gnormx-P.x*E.gnormy,E.tp1=g.y*E.gnormx-g.x*E.gnormy}}if(!h.sweepFrozen){let d=n*e,b=d-h.sweepTime;if(b!=0){h.sweepTime=d;let z=b;if(h.posx+=h.velx*z,h.posy+=h.vely*z,h.angvel!=0){let M=h.sweep_angvel*b;if(h.rot+=M,M*M>1e-4)h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot);else{let y=M*M,w=1-.5*y,v=1-y*y/8,P=(w*h.axisx+M*h.axisy)*v;h.axisy=(w*h.axisy-M*h.axisx)*v,h.axisx=P}}}let m=i.s2;if(m.type==0)m.worldCOMx=h.posx+(h.axisy*m.localCOMx-h.axisx*m.localCOMy),m.worldCOMy=h.posy+(m.localCOMx*h.axisx+m.localCOMy*h.axisy);else{let z=m.polygon,M=z.lverts.next,y=z.gverts.next;for(;y!=null;){let N=y,k=M;M=M.next,N.x=h.posx+(h.axisy*k.x-h.axisx*k.y),N.y=h.posy+(k.x*h.axisx+k.y*h.axisy),y=y.next}let w=z.edges.head,v=z.gverts.next,P=v;for(v=v.next;v!=null;){let N=v,k=w.elt;w=w.next,k.gnormx=h.axisy*k.lnormx-h.axisx*k.lnormy,k.gnormy=k.lnormx*h.axisx+k.lnormy*h.axisy,k.gprojection=h.posx*k.gnormx+h.posy*k.gnormy+k.lprojection,k.tp0=P.y*k.gnormx-P.x*k.gnormy,k.tp1=N.y*k.gnormx-N.x*k.gnormy,P=N,v=v.next}let g=z.gverts.next,E=w.elt;w=w.next,E.gnormx=h.axisy*E.lnormx-h.axisx*E.lnormy,E.gnormy=E.lnormx*h.axisx+E.lnormy*h.axisy,E.gprojection=h.posx*E.gnormx+h.posy*E.gnormy+E.lprojection,E.tp0=P.y*E.gnormx-P.x*E.gnormy,E.tp1=g.y*E.gnormx-g.x*E.gnormy}}let x=i.arbiter==null,f=this.narrowPhase(i.s1,i.s2,!0,i.arbiter,!0);if(f==null)i.arbiter!=null&&i.arbiter.pair!=null&&(i.arbiter.pair.arb=null,i.arbiter.pair=null);else if(!this.presteparb(f,e,!0)&&f.type==ke.COL&&f.active&&(f.immState&1)!=0){let d=f.colarb,b=d.nx*d.c1.jnAcc-d.ny*d.c1.jtAcc,m=d.ny*d.c1.jnAcc+d.nx*d.c1.jtAcc,z=d.b1.imass;d.b1.velx-=b*z,d.b1.vely-=m*z,d.b1.angvel-=d.b1.iinertia*(m*d.c1.r1x-b*d.c1.r1y);let M=d.b2.imass;if(d.b2.velx+=b*M,d.b2.vely+=m*M,d.b2.angvel+=d.b2.iinertia*(m*d.c1.r2x-b*d.c1.r2y),d.hc2){let he=d.nx*d.c2.jnAcc-d.ny*d.c2.jtAcc,ce=d.ny*d.c2.jnAcc+d.nx*d.c2.jtAcc,pe=d.b1.imass;d.b1.velx-=he*pe,d.b1.vely-=ce*pe,d.b1.angvel-=d.b1.iinertia*(ce*d.c2.r1x-he*d.c2.r1y);let de=d.b2.imass;d.b2.velx+=he*de,d.b2.vely+=ce*de,d.b2.angvel+=d.b2.iinertia*(ce*d.c2.r2x-he*d.c2.r2y)}d.b2.angvel+=d.jrAcc*d.b2.iinertia,d.b1.angvel-=d.jrAcc*d.b1.iinertia;let y=f.colarb,w=y.k1x+y.b2.velx-y.c1.r2y*y.b2.angvel-(y.b1.velx-y.c1.r1y*y.b1.angvel),v=y.k1y+y.b2.vely+y.c1.r2x*y.b2.angvel-(y.b1.vely+y.c1.r1x*y.b1.angvel),P=(v*y.nx-w*y.ny+y.surfacex)*y.c1.tMass,g=y.c1.friction*y.c1.jnAcc,E=y.c1.jtAcc,N=E-P;N>g?N=g:N<-g&&(N=-g),P=N-E,y.c1.jtAcc=N;let k=-y.ny*P,Z=y.nx*P;if(y.b2.velx+=k*y.b2.imass,y.b2.vely+=Z*y.b2.imass,y.b1.velx-=k*y.b1.imass,y.b1.vely-=Z*y.b1.imass,y.b2.angvel+=y.rt1b*P*y.b2.iinertia,y.b1.angvel-=y.rt1a*P*y.b1.iinertia,y.hc2){let he=y.k2x+y.b2.velx-y.c2.r2y*y.b2.angvel-(y.b1.velx-y.c2.r1y*y.b1.angvel),ce=y.k2y+y.b2.vely+y.c2.r2x*y.b2.angvel-(y.b1.vely+y.c2.r1x*y.b1.angvel);P=(ce*y.nx-he*y.ny+y.surfacex)*y.c2.tMass,g=y.c2.friction*y.c2.jnAcc,E=y.c2.jtAcc,N=E-P,N>g?N=g:N<-g&&(N=-g),P=N-E,y.c2.jtAcc=N,k=-y.ny*P,Z=y.nx*P,y.b2.velx+=k*y.b2.imass,y.b2.vely+=Z*y.b2.imass,y.b1.velx-=k*y.b1.imass,y.b1.vely-=Z*y.b1.imass,y.b2.angvel+=y.rt2b*P*y.b2.iinertia,y.b1.angvel-=y.rt2a*P*y.b1.iinertia,w=y.k1x+y.b2.velx-y.c1.r2y*y.b2.angvel-(y.b1.velx-y.c1.r1y*y.b1.angvel),v=y.k1y+y.b2.vely+y.c1.r2x*y.b2.angvel-(y.b1.vely+y.c1.r1x*y.b1.angvel),he=y.k2x+y.b2.velx-y.c2.r2y*y.b2.angvel-(y.b1.velx-y.c2.r1y*y.b1.angvel),ce=y.k2y+y.b2.vely+y.c2.r2x*y.b2.angvel-(y.b1.vely+y.c2.r1x*y.b1.angvel);let pe=y.c1.jnAcc,de=y.c2.jnAcc,te=w*y.nx+v*y.ny+y.surfacey+y.c1.bounce-(y.Ka*pe+y.Kb*de),_e=he*y.nx+ce*y.ny+y.surfacey+y.c2.bounce-(y.Kb*pe+y.Kc*de),me=-(y.kMassa*te+y.kMassb*_e),xe=-(y.kMassb*te+y.kMassc*_e);me>=0&&xe>=0?(te=me-pe,_e=xe-de,y.c1.jnAcc=me,y.c2.jnAcc=xe):(me=-y.c1.nMass*te,me>=0&&y.Kb*me+_e>=0?(te=me-pe,_e=-de,y.c1.jnAcc=me,y.c2.jnAcc=0):(xe=-y.c2.nMass*_e,xe>=0&&y.Kb*xe+te>=0?(te=-pe,_e=xe-de,y.c1.jnAcc=0,y.c2.jnAcc=xe):te>=0&&_e>=0?(te=-pe,_e=-de,y.c1.jnAcc=y.c2.jnAcc=0):(te=0,_e=0))),P=te+_e,k=y.nx*P,Z=y.ny*P,y.b2.velx+=k*y.b2.imass,y.b2.vely+=Z*y.b2.imass,y.b1.velx-=k*y.b1.imass,y.b1.vely-=Z*y.b1.imass,y.b2.angvel+=(y.rn1b*te+y.rn2b*_e)*y.b2.iinertia,y.b1.angvel-=(y.rn1a*te+y.rn2a*_e)*y.b1.iinertia}else y.radius!=0&&(P=(y.b2.angvel-y.b1.angvel)*y.rMass,g=y.rfric*y.c1.jnAcc,E=y.jrAcc,y.jrAcc-=P,y.jrAcc>g?y.jrAcc=g:y.jrAcc<-g&&(y.jrAcc=-g),P=y.jrAcc-E,y.b2.angvel+=P*y.b2.iinertia,y.b1.angvel-=P*y.b1.iinertia),w=y.k1x+y.b2.velx-y.c1.r2y*y.b2.angvel-(y.b1.velx-y.c1.r1y*y.b1.angvel),v=y.k1y+y.b2.vely+y.c1.r2x*y.b2.angvel-(y.b1.vely+y.c1.r1x*y.b1.angvel),P=(y.c1.bounce+(y.nx*w+y.ny*v)+y.surfacey)*y.c1.nMass,E=y.c1.jnAcc,N=E-P,N<0&&(N=0),P=N-E,y.c1.jnAcc=N,k=y.nx*P,Z=y.ny*P,y.b2.velx+=k*y.b2.imass,y.b2.vely+=Z*y.b2.imass,y.b1.velx-=k*y.b1.imass,y.b1.vely-=Z*y.b1.imass,y.b2.angvel+=y.rn1b*P*y.b2.iinertia,y.b1.angvel-=y.rn1a*P*y.b1.iinertia;let C=f.colarb,F=C.k1x+C.b2.velx-C.c1.r2y*C.b2.angvel-(C.b1.velx-C.c1.r1y*C.b1.angvel),O=C.k1y+C.b2.vely+C.c1.r2x*C.b2.angvel-(C.b1.vely+C.c1.r1x*C.b1.angvel),B=(O*C.nx-F*C.ny+C.surfacex)*C.c1.tMass,D=C.c1.friction*C.c1.jnAcc,U=C.c1.jtAcc,W=U-B;W>D?W=D:W<-D&&(W=-D),B=W-U,C.c1.jtAcc=W;let q=-C.ny*B,L=C.nx*B;if(C.b2.velx+=q*C.b2.imass,C.b2.vely+=L*C.b2.imass,C.b1.velx-=q*C.b1.imass,C.b1.vely-=L*C.b1.imass,C.b2.angvel+=C.rt1b*B*C.b2.iinertia,C.b1.angvel-=C.rt1a*B*C.b1.iinertia,C.hc2){let he=C.k2x+C.b2.velx-C.c2.r2y*C.b2.angvel-(C.b1.velx-C.c2.r1y*C.b1.angvel),ce=C.k2y+C.b2.vely+C.c2.r2x*C.b2.angvel-(C.b1.vely+C.c2.r1x*C.b1.angvel);B=(ce*C.nx-he*C.ny+C.surfacex)*C.c2.tMass,D=C.c2.friction*C.c2.jnAcc,U=C.c2.jtAcc,W=U-B,W>D?W=D:W<-D&&(W=-D),B=W-U,C.c2.jtAcc=W,q=-C.ny*B,L=C.nx*B,C.b2.velx+=q*C.b2.imass,C.b2.vely+=L*C.b2.imass,C.b1.velx-=q*C.b1.imass,C.b1.vely-=L*C.b1.imass,C.b2.angvel+=C.rt2b*B*C.b2.iinertia,C.b1.angvel-=C.rt2a*B*C.b1.iinertia,F=C.k1x+C.b2.velx-C.c1.r2y*C.b2.angvel-(C.b1.velx-C.c1.r1y*C.b1.angvel),O=C.k1y+C.b2.vely+C.c1.r2x*C.b2.angvel-(C.b1.vely+C.c1.r1x*C.b1.angvel),he=C.k2x+C.b2.velx-C.c2.r2y*C.b2.angvel-(C.b1.velx-C.c2.r1y*C.b1.angvel),ce=C.k2y+C.b2.vely+C.c2.r2x*C.b2.angvel-(C.b1.vely+C.c2.r1x*C.b1.angvel);let pe=C.c1.jnAcc,de=C.c2.jnAcc,te=F*C.nx+O*C.ny+C.surfacey+C.c1.bounce-(C.Ka*pe+C.Kb*de),_e=he*C.nx+ce*C.ny+C.surfacey+C.c2.bounce-(C.Kb*pe+C.Kc*de),me=-(C.kMassa*te+C.kMassb*_e),xe=-(C.kMassb*te+C.kMassc*_e);me>=0&&xe>=0?(te=me-pe,_e=xe-de,C.c1.jnAcc=me,C.c2.jnAcc=xe):(me=-C.c1.nMass*te,me>=0&&C.Kb*me+_e>=0?(te=me-pe,_e=-de,C.c1.jnAcc=me,C.c2.jnAcc=0):(xe=-C.c2.nMass*_e,xe>=0&&C.Kb*xe+te>=0?(te=-pe,_e=xe-de,C.c1.jnAcc=0,C.c2.jnAcc=xe):te>=0&&_e>=0?(te=-pe,_e=-de,C.c1.jnAcc=C.c2.jnAcc=0):(te=0,_e=0))),B=te+_e,q=C.nx*B,L=C.ny*B,C.b2.velx+=q*C.b2.imass,C.b2.vely+=L*C.b2.imass,C.b1.velx-=q*C.b1.imass,C.b1.vely-=L*C.b1.imass,C.b2.angvel+=(C.rn1b*te+C.rn2b*_e)*C.b2.iinertia,C.b1.angvel-=(C.rn1a*te+C.rn2a*_e)*C.b1.iinertia}else C.radius!=0&&(B=(C.b2.angvel-C.b1.angvel)*C.rMass,D=C.rfric*C.c1.jnAcc,U=C.jrAcc,C.jrAcc-=B,C.jrAcc>D?C.jrAcc=D:C.jrAcc<-D&&(C.jrAcc=-D),B=C.jrAcc-U,C.b2.angvel+=B*C.b2.iinertia,C.b1.angvel-=B*C.b1.iinertia),F=C.k1x+C.b2.velx-C.c1.r2y*C.b2.angvel-(C.b1.velx-C.c1.r1y*C.b1.angvel),O=C.k1y+C.b2.vely+C.c1.r2x*C.b2.angvel-(C.b1.vely+C.c1.r1x*C.b1.angvel),B=(C.c1.bounce+(C.nx*F+C.ny*O)+C.surfacey)*C.c1.nMass,U=C.c1.jnAcc,W=U-B,W<0&&(W=0),B=W-U,C.c1.jnAcc=W,q=C.nx*B,L=C.ny*B,C.b2.velx+=q*C.b2.imass,C.b2.vely+=L*C.b2.imass,C.b1.velx-=q*C.b1.imass,C.b1.vely-=L*C.b1.imass,C.b2.angvel+=C.rn1b*B*C.b2.iinertia,C.b1.angvel-=C.rn1a*B*C.b1.iinertia;let A=f.colarb,J=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),$=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),X=($*A.nx-J*A.ny+A.surfacex)*A.c1.tMass,H=A.c1.friction*A.c1.jnAcc,ee=A.c1.jtAcc,G=ee-X;G>H?G=H:G<-H&&(G=-H),X=G-ee,A.c1.jtAcc=G;let R=-A.ny*X,j=A.nx*X;if(A.b2.velx+=R*A.b2.imass,A.b2.vely+=j*A.b2.imass,A.b1.velx-=R*A.b1.imass,A.b1.vely-=j*A.b1.imass,A.b2.angvel+=A.rt1b*X*A.b2.iinertia,A.b1.angvel-=A.rt1a*X*A.b1.iinertia,A.hc2){let he=A.k2x+A.b2.velx-A.c2.r2y*A.b2.angvel-(A.b1.velx-A.c2.r1y*A.b1.angvel),ce=A.k2y+A.b2.vely+A.c2.r2x*A.b2.angvel-(A.b1.vely+A.c2.r1x*A.b1.angvel);X=(ce*A.nx-he*A.ny+A.surfacex)*A.c2.tMass,H=A.c2.friction*A.c2.jnAcc,ee=A.c2.jtAcc,G=ee-X,G>H?G=H:G<-H&&(G=-H),X=G-ee,A.c2.jtAcc=G,R=-A.ny*X,j=A.nx*X,A.b2.velx+=R*A.b2.imass,A.b2.vely+=j*A.b2.imass,A.b1.velx-=R*A.b1.imass,A.b1.vely-=j*A.b1.imass,A.b2.angvel+=A.rt2b*X*A.b2.iinertia,A.b1.angvel-=A.rt2a*X*A.b1.iinertia,J=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),$=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),he=A.k2x+A.b2.velx-A.c2.r2y*A.b2.angvel-(A.b1.velx-A.c2.r1y*A.b1.angvel),ce=A.k2y+A.b2.vely+A.c2.r2x*A.b2.angvel-(A.b1.vely+A.c2.r1x*A.b1.angvel);let pe=A.c1.jnAcc,de=A.c2.jnAcc,te=J*A.nx+$*A.ny+A.surfacey+A.c1.bounce-(A.Ka*pe+A.Kb*de),_e=he*A.nx+ce*A.ny+A.surfacey+A.c2.bounce-(A.Kb*pe+A.Kc*de),me=-(A.kMassa*te+A.kMassb*_e),xe=-(A.kMassb*te+A.kMassc*_e);me>=0&&xe>=0?(te=me-pe,_e=xe-de,A.c1.jnAcc=me,A.c2.jnAcc=xe):(me=-A.c1.nMass*te,me>=0&&A.Kb*me+_e>=0?(te=me-pe,_e=-de,A.c1.jnAcc=me,A.c2.jnAcc=0):(xe=-A.c2.nMass*_e,xe>=0&&A.Kb*xe+te>=0?(te=-pe,_e=xe-de,A.c1.jnAcc=0,A.c2.jnAcc=xe):te>=0&&_e>=0?(te=-pe,_e=-de,A.c1.jnAcc=A.c2.jnAcc=0):(te=0,_e=0))),X=te+_e,R=A.nx*X,j=A.ny*X,A.b2.velx+=R*A.b2.imass,A.b2.vely+=j*A.b2.imass,A.b1.velx-=R*A.b1.imass,A.b1.vely-=j*A.b1.imass,A.b2.angvel+=(A.rn1b*te+A.rn2b*_e)*A.b2.iinertia,A.b1.angvel-=(A.rn1a*te+A.rn2a*_e)*A.b1.iinertia}else A.radius!=0&&(X=(A.b2.angvel-A.b1.angvel)*A.rMass,H=A.rfric*A.c1.jnAcc,ee=A.jrAcc,A.jrAcc-=X,A.jrAcc>H?A.jrAcc=H:A.jrAcc<-H&&(A.jrAcc=-H),X=A.jrAcc-ee,A.b2.angvel+=X*A.b2.iinertia,A.b1.angvel-=X*A.b1.iinertia),J=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),$=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),X=(A.c1.bounce+(A.nx*J+A.ny*$)+A.surfacey)*A.c1.nMass,ee=A.c1.jnAcc,G=ee-X,G<0&&(G=0),X=G-ee,A.c1.jnAcc=G,R=A.nx*X,j=A.ny*X,A.b2.velx+=R*A.b2.imass,A.b2.vely+=j*A.b2.imass,A.b1.velx-=R*A.b1.imass,A.b1.vely-=j*A.b1.imass,A.b2.angvel+=A.rn1b*X*A.b2.iinertia,A.b1.angvel-=A.rn1a*X*A.b1.iinertia;let V=f.colarb,K=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),Q=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),Y=(Q*V.nx-K*V.ny+V.surfacex)*V.c1.tMass,ne=V.c1.friction*V.c1.jnAcc,ae=V.c1.jtAcc,le=ae-Y;le>ne?le=ne:le<-ne&&(le=-ne),Y=le-ae,V.c1.jtAcc=le;let se=-V.ny*Y,re=V.nx*Y;if(V.b2.velx+=se*V.b2.imass,V.b2.vely+=re*V.b2.imass,V.b1.velx-=se*V.b1.imass,V.b1.vely-=re*V.b1.imass,V.b2.angvel+=V.rt1b*Y*V.b2.iinertia,V.b1.angvel-=V.rt1a*Y*V.b1.iinertia,V.hc2){let he=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),ce=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);Y=(ce*V.nx-he*V.ny+V.surfacex)*V.c2.tMass,ne=V.c2.friction*V.c2.jnAcc,ae=V.c2.jtAcc,le=ae-Y,le>ne?le=ne:le<-ne&&(le=-ne),Y=le-ae,V.c2.jtAcc=le,se=-V.ny*Y,re=V.nx*Y,V.b2.velx+=se*V.b2.imass,V.b2.vely+=re*V.b2.imass,V.b1.velx-=se*V.b1.imass,V.b1.vely-=re*V.b1.imass,V.b2.angvel+=V.rt2b*Y*V.b2.iinertia,V.b1.angvel-=V.rt2a*Y*V.b1.iinertia,K=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),Q=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),he=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),ce=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);let pe=V.c1.jnAcc,de=V.c2.jnAcc,te=K*V.nx+Q*V.ny+V.surfacey+V.c1.bounce-(V.Ka*pe+V.Kb*de),_e=he*V.nx+ce*V.ny+V.surfacey+V.c2.bounce-(V.Kb*pe+V.Kc*de),me=-(V.kMassa*te+V.kMassb*_e),xe=-(V.kMassb*te+V.kMassc*_e);me>=0&&xe>=0?(te=me-pe,_e=xe-de,V.c1.jnAcc=me,V.c2.jnAcc=xe):(me=-V.c1.nMass*te,me>=0&&V.Kb*me+_e>=0?(te=me-pe,_e=-de,V.c1.jnAcc=me,V.c2.jnAcc=0):(xe=-V.c2.nMass*_e,xe>=0&&V.Kb*xe+te>=0?(te=-pe,_e=xe-de,V.c1.jnAcc=0,V.c2.jnAcc=xe):te>=0&&_e>=0?(te=-pe,_e=-de,V.c1.jnAcc=V.c2.jnAcc=0):(te=0,_e=0))),Y=te+_e,se=V.nx*Y,re=V.ny*Y,V.b2.velx+=se*V.b2.imass,V.b2.vely+=re*V.b2.imass,V.b1.velx-=se*V.b1.imass,V.b1.vely-=re*V.b1.imass,V.b2.angvel+=(V.rn1b*te+V.rn2b*_e)*V.b2.iinertia,V.b1.angvel-=(V.rn1a*te+V.rn2a*_e)*V.b1.iinertia}else V.radius!=0&&(Y=(V.b2.angvel-V.b1.angvel)*V.rMass,ne=V.rfric*V.c1.jnAcc,ae=V.jrAcc,V.jrAcc-=Y,V.jrAcc>ne?V.jrAcc=ne:V.jrAcc<-ne&&(V.jrAcc=-ne),Y=V.jrAcc-ae,V.b2.angvel+=Y*V.b2.iinertia,V.b1.angvel-=Y*V.b1.iinertia),K=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),Q=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),Y=(V.c1.bounce+(V.nx*K+V.ny*Q)+V.surfacey)*V.c1.nMass,ae=V.c1.jnAcc,le=ae-Y,le<0&&(le=0),Y=le-ae,V.c1.jnAcc=le,se=V.nx*Y,re=V.ny*Y,V.b2.velx+=se*V.b2.imass,V.b2.vely+=re*V.b2.imass,V.b1.velx-=se*V.b1.imass,V.b1.vely-=re*V.b1.imass,V.b2.angvel+=V.rn1b*Y*V.b2.iinertia,V.b1.angvel-=V.rn1a*Y*V.b1.iinertia;u.sweep_angvel=u.angvel%t,h.sweep_angvel=h.angvel%t}if(f!=null&&f.active&&(f.immState&1)!=0&&f.type==ke.COL){if(!u.sweepFrozen&&u.type!=3)if(u.sweepFrozen=!0,i.failed)u.angvel=u.sweep_angvel=0;else if(i.slipped){let d=u;d.sweep_angvel*=I._nape.Config.angularCCDSlipScale,u.angvel=d.sweep_angvel}else u.angvel=u.sweep_angvel;if(!h.sweepFrozen&&h.type!=3)if(h.sweepFrozen=!0,i.failed)h.angvel=h.sweep_angvel=0;else if(i.slipped){let d=h;d.sweep_angvel*=I._nape.Config.angularCCDSlipScale,h.angvel=d.sweep_angvel}else h.angvel=h.sweep_angvel}let _=i;_.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=_}for(;this.toiEvents.head!=null;){let r=this.toiEvents.pop_unsafe();r.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=r}let l=this.kinematics.head;for(;l!=null;){let i=l.elt,r=e-i.sweepTime;if(r!=0){i.sweepTime=e;let o=r;if(i.posx+=i.velx*o,i.posy+=i.vely*o,i.angvel!=0){let a=i.sweep_angvel*r;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let p=a*a,c=1-.5*p,u=1-p*p/8,h=(c*i.axisx+a*i.axisy)*u;i.axisy=(c*i.axisy-a*i.axisx)*u,i.axisx=h}}}i.sweepTime=0,l=l.next}let s=this.live.head;for(;s!=null;){let i=s.elt;if(!i.sweepFrozen){let r=e-i.sweepTime;if(r!=0){i.sweepTime=e;let o=r;if(i.posx+=i.velx*o,i.posy+=i.vely*o,i.angvel!=0){let a=i.sweep_angvel*r;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let p=a*a,c=1-.5*p,u=1-p*p/8,h=(c*i.axisx+a*i.axisy)*u;i.axisy=(c*i.axisy-a*i.axisx)*u,i.axisx=h}}}}i.sweepTime=0,s=s.next}}continuousEvent(e,t,n,l,s){if(e.body.sweepFrozen&&t.body.sweepFrozen||e.body.disableCCD||t.body.disableCCD)return l;let i;if(l!=null&&l.colarb==null)i=!0;else{let a=e.body,p=t.body,c;c=!1;let u=a.constraints.head;for(;u!=null;){let f=u.elt;if(f.ignore&&f.pair_exists(a.id,p.id)){c=!0;break}u=u.next}let h,x;if(c)x=!1;else{let f=e;for(;f!=null&&f.group==null;)f.ishape!=null?f=f.ishape.body:f.icompound!=null?f=f.icompound.compound:f=f.ibody.compound;let _=f==null?null:f.group,d;if(_==null)d=!1;else{let b=t;for(;b!=null&&b.group==null;)b.ishape!=null?b=b.ishape.body:b.icompound!=null?b=b.icompound.compound:b=b.ibody.compound;let m=b==null?null:b.group;if(m==null)d=!1;else{let z=!1;for(;_!=null&&m!=null;){if(_==m){z=_.ignore;break}_.depth<m.depth?m=m.group:_=_.group}d=z}}x=!d}if(x){let f;if(e.sensorEnabled||t.sensorEnabled){let _=e.filter,d=t.filter;f=(_.sensorMask&d.sensorGroup)!=0&&(d.sensorMask&_.sensorGroup)!=0}else f=!1;if(f)h=2;else{let _;if(e.fluidEnabled||t.fluidEnabled){let d=e.filter,b=t.filter;_=(d.fluidMask&b.fluidGroup)!=0&&(b.fluidMask&d.fluidGroup)!=0}else _=!1;if(_&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0))h=0;else{let d=e.filter,b=t.filter;h=(d.collisionMask&b.collisionGroup)!=0&&(b.collisionMask&d.collisionGroup)!=0&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0)?1:-1}}}else h=-1;i=h<=0}if(i)return l;let r=e.body,o=t.body;if(n||r.bullet||o.bullet){let a;I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?a=new I._zpp.geom.ZPP_ToiEvent:(a=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=a.next,a.next=null),a.failed=!1,a.s1=a.s2=null,a.arbiter=null;let p=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,un.staticSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD);else if(a.s1=e,a.s2=t,a.kinematic=p,a.s1.body.sweepFrozen||a.s2.body.sweepFrozen){if(a.s1.body.sweepFrozen){let c=a.s1;a.s1=a.s2,a.s2=c,a.frozen1=!1,a.frozen2=!0}un.staticSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD)}else un.dynamicSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD,!1);if(n&&a.toi<0||a.failed){let c=a;c.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=c}else this.toiEvents.add(a),a.frozen1=a.s1.body.sweepFrozen,a.frozen2=a.s2.body.sweepFrozen,a.arbiter=l!=null?l.colarb:null}return l}bodyCbWake(e){if(e.type==2&&e.cbSet!=null)if(this.midstep){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let l=this.push_callback(n);l.event=2,l.body=e,t=t.next}}else e.component.woken=!0}bodyCbSleep(e){if(e.type==2&&e.cbSet!=null){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let l=this.push_callback(n);l.event=3,l.body=e,t=t.next}}}constraintCbWake(e){if(e.cbSet!=null)if(this.midstep){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let l=this.push_callback(n);l.event=2,l.constraint=e,t=t.next}}else e.component.woken=!0}constraintCbSleep(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let l=this.push_callback(n);l.event=3,l.constraint=e,t=t.next}}}constraintCbBreak(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=4){t=t.next;continue}let l=this.push_callback(n);l.event=4,l.constraint=e,t=t.next}}}nullListenerType(e,t){let n=new I._zpp.util.ZNPList_ZPP_Interactor,l=e.interactors.head;for(;l!=null;){let s=l.elt;n.add(s),l=l.next}if(e!=t){let s=t.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next}}for(;n.head!=null;){let s=n.pop_unsafe();if(s.icompound!=null){let i=s.icompound,r=i.bodies.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}let o=i.compounds.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}}else{let i=s.ibody!=null?s.ibody:s.ishape.body,r=s.ishape!=null?s.ishape:null,o=i.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 u=this.mrca2.head;for(;u!=null;){let h=u.elt;if(c.cbSet==e&&h.cbSet!=t||c.cbSet==t&&h.cbSet!=e){u=u.next;continue}let x=I._zpp.phys.ZPP_Interactor.get(c,h);if(x!=null){for(;x.arbiters.head!=null;){let f=x.arbiters.pop_unsafe();f.present--}this.remove_callbackset(x)}u=u.next}p=p.next}o=o.next}}}}nullInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,l=n.bodies.head;for(;l!=null;){let i=l.elt;this.nullInteractorType(i,t),l=l.next}let s=n.compounds.head;for(;s!=null;){let i=s.elt;this.nullInteractorType(i,t),s=s.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,l=e.ishape!=null?e.ishape:null,s=n.arbiters.head;for(;s!=null;){let i=s.elt;if(i.present==0){s=s.next;continue}if(l!=null&&!(i.ws1==l||i.ws2==l)){s=s.next;continue}this.MRCA_chains(i.ws1,i.ws2);let 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=I._zpp.phys.ZPP_Interactor.get(o,p);c!=null&&(i.present--,c.remove_arb(i),c.arbiters.head==null&&this.remove_callbackset(c)),a=a.next}r=r.next}s=s.next}}}freshListenerType(e,t){let n=new I._zpp.util.ZNPList_ZPP_Interactor,l=e.interactors.head;for(;l!=null;){let s=l.elt;n.add(s),l=l.next}if(e!=t){let s=t.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next}}for(;n.head!=null;){let s=n.pop_unsafe();if(s.icompound!=null){let i=s.icompound,r=i.bodies.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}let o=i.compounds.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}}else{let i=s.ibody!=null?s.ibody:s.ishape.body,r=s.ishape!=null?s.ishape:null,o=i.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 u=this.mrca2.head;for(;u!=null;){let h=u.elt;if(c.cbSet==e&&h.cbSet!=t||c.cbSet==t&&h.cbSet!=e){u=u.next;continue}let x=I._zpp.phys.ZPP_Interactor.get(c,h);x==null&&(x=xn.get(c,h),this.add_callbackset(x));let f,_;_=!1;let d=x.arbiters.head;for(;d!=null;){if(d.elt==a){_=!0;break}d=d.next}if(_)f=!1;else{let b=x.arbiters,m;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?m=new I._zpp.util.ZNPNode_ZPP_Arbiter:(m=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=m.next,m.next=null),m.elt=a;let z=m;z.next=b.head,b.head=z,b.modified=!0,b.length++,f=!0}f&&a.present++,u=u.next}p=p.next}o=o.next}}}}freshInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,l=n.bodies.head;for(;l!=null;){let i=l.elt;this.freshInteractorType(i,t),l=l.next}let s=n.compounds.head;for(;s!=null;){let i=s.elt;this.freshInteractorType(i,t),s=s.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,l=e.ishape!=null?e.ishape:null,s=n.arbiters.head;for(;s!=null;){let i=s.elt;if(!i.presentable){s=s.next;continue}if(l!=null&&!(i.ws1==l||i.ws2==l)){s=s.next;continue}this.MRCA_chains(i.ws1,i.ws2);let 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,u=p.cbSet;c.validate(),u.validate();let h=c.manager,x=null,_=(c.cbpairs.length<u.cbpairs.length?c.cbpairs:u.cbpairs).head;for(;_!=null;){let d=_.elt;if(d.a==c&&d.b==u||d.a==u&&d.b==c){x=d;break}_=_.next}if(x==null){let d;Se.zpp_pool==null?d=new Se:(d=Se.zpp_pool,Se.zpp_pool=d.next,d.next=null),d.zip_listeners=!0,St.setlt(c,u)?(d.a=c,d.b=u):(d.a=u,d.b=c),x=d,c.cbpairs.add(x),u!=c&&u.cbpairs.add(x)}if(x.zip_listeners&&(x.zip_listeners=!1,x.__validate()),x.listeners.head!=null){let d=I._zpp.phys.ZPP_Interactor.get(o,p);d==null&&(d=xn.get(o,p),this.add_callbackset(d));let b,m;m=!1;let z=d.arbiters.head;for(;z!=null;){if(z.elt==i){m=!0;break}z=z.next}if(m)b=!1;else{let M=d.arbiters,y;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?y=new I._zpp.util.ZNPNode_ZPP_Arbiter:(y=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y.next,y.next=null),y.elt=i;let w=y;w.next=M.head,M.head=w,M.modified=!0,M.length++,b=!0}b&&i.present++}a=a.next}r=r.next}s=s.next}}}wakeCompound(e){let t=e.bodies.head;for(;t!=null;){let i=t.elt;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1)),t=t.next}let n=e.constraints.head;for(;n!=null;){let s=n.elt;this.wake_constraint(s),n=n.next}let l=e.compounds.head;for(;l!=null;){let s=l.elt;this.wakeCompound(s),l=l.next}}wakeIsland(e){for(;e.comps.head!=null;){let n=e.comps.pop_unsafe();if(n.waket=this.stamp+(this.midstep?0:1),n.isBody){let l=n.body;this.live.add(l);let s=l.arbiters.head;for(;s!=null;){let i=s.elt;if(i.sleeping)if(i.sleeping=!1,i.up_stamp+=this.stamp-i.sleep_stamp,i.type==ke.COL){let r=i.colarb;if(r.stat){let o=this.c_arbiters_true,a;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(a=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}else{let o=this.c_arbiters_false,a;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(a=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}}else if(i.type==ke.FLUID){let r=this.f_arbiters,o=i.fluidarb,a;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(a=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}else{let r=this.s_arbiters,o=i.sensorarb,a;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(a=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}s=s.next}if(this.bodyCbWake(l),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0,l.type!=1){let i=l.shapes.head;for(;i!=null;){let r=i.elt;r.node!=null&&this.bphase.sync(r),i=i.next}}}else{let l=n.constraint,s=this.live_constraints,i;I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?i=new I._zpp.util.ZNPNode_ZPP_Constraint:(i=I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=i.next,i.next=null),i.elt=l;let r=i;r.next=s.head,s.head=r,s.modified=!0,s.length++,this.constraintCbWake(l),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0}}let t=e;t.next=Mt.zpp_pool,Mt.zpp_pool=t}non_inlined_wake(e,t){t==null&&(t=!1);let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,t))}really_wake(e,t){if(t==null&&(t=!1),e.component.island==null){if(e.component.sleeping=!1,e.type==3||e.type==1){let s=this.staticsleep,i;I._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?i=new I._zpp.util.ZNPNode_ZPP_Body:(i=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=i.next,i.next=null),i.elt=e;let r=i;r.next=s.head,s.head=r,s.modified=!0,s.length++}else{let s=this.live,i;I._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?i=new I._zpp.util.ZNPNode_ZPP_Body:(i=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=i.next,i.next=null),i.elt=e;let r=i;r.next=s.head,s.head=r,s.modified=!0,s.length++}let n=e.constraints.head;for(;n!=null;){let s=n.elt;s.space==this&&this.wake_constraint(s),n=n.next}let l=e.arbiters.head;for(;l!=null;){let s=l.elt;if(s.sleeping)if(s.sleeping=!1,s.up_stamp+=this.stamp+(this.midstep?0:1)-s.sleep_stamp,s.type==ke.COL){let i=s.colarb;if(i.stat){let r=this.c_arbiters_true,o;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(o=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=o.next,o.next=null),o.elt=i;let a=o;a.next=r.head,r.head=a,r.modified=!0,r.length++}else{let r=this.c_arbiters_false,o;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(o=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=o.next,o.next=null),o.elt=i;let a=o;a.next=r.head,r.head=a,r.modified=!0,r.length++}}else if(s.type==ke.FLUID){let i=this.f_arbiters,r=s.fluidarb,o;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(o=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=o.next,o.next=null),o.elt=r;let a=o;a.next=i.head,i.head=a,i.modified=!0,i.length++}else{let i=this.s_arbiters,r=s.sensorarb,o;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(o=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=o.next,o.next=null),o.elt=r;let a=o;a.next=i.head,i.head=a,i.modified=!0,i.length++}if(s.type!=ke.SENSOR&&!s.cleared&&s.up_stamp>=this.stamp&&(s.immState&1)!=0){if(s.b1.type==2&&s.b1.component.sleeping){let i=s.b1;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1))}if(s.b2.type==2&&s.b2.component.sleeping){let i=s.b2;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1))}}l=l.next}if(!t&&e.type==2&&this.bodyCbWake(e),!t&&!this.bphase.is_sweep&&e.type!=1){let s=e.shapes.head;for(;s!=null;){let i=s.elt;i.node!=null&&this.bphase.sync(i),s=s.next}}}else this.wakeIsland(e.component.island)}wake_constraint(e,t){if(t==null&&(t=!1),e.active)if(e.component.waket=this.stamp+(this.midstep?0:1),e.component.sleeping){if(e.component.island==null){e.component.sleeping=!1;let n=this.live_constraints,l;I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?l=new I._zpp.util.ZNPNode_ZPP_Constraint:(l=I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=l.next,l.next=null),l.elt=e;let s=l;s.next=n.head,n.head=s,n.modified=!0,n.length++,e.wake_connected(),t||this.constraintCbWake(e)}else this.wakeIsland(e.component.island);return!0}else return!1;else return!1}doForests(e){let t=this.c_arbiters_false.head;for(;t!=null;){let s=t.elt;if(!s.cleared&&s.up_stamp==this.stamp&&(s.immState&1)!=0&&s.b1.type==2&&s.b2.type==2){let i;if(s.b1.component==s.b1.component.parent)i=s.b1.component;else{let o=s.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}i=o}let r;if(s.b2.component==s.b2.component.parent)r=s.b2.component;else{let o=s.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}i!=r&&(i.rank<r.rank?i.parent=r:i.rank>r.rank?r.parent=i:(r.parent=i,i.rank++))}t=t.next}let n=this.f_arbiters.head;for(;n!=null;){let s=n.elt;if(!s.cleared&&s.up_stamp==this.stamp&&(s.immState&1)!=0&&s.b1.type==2&&s.b2.type==2){let i;if(s.b1.component==s.b1.component.parent)i=s.b1.component;else{let o=s.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}i=o}let r;if(s.b2.component==s.b2.component.parent)r=s.b2.component;else{let o=s.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}i!=r&&(i.rank<r.rank?i.parent=r:i.rank>r.rank?r.parent=i:(r.parent=i,i.rank++))}n=n.next}let l=this.live_constraints.head;for(;l!=null;)l.elt.forest(),l=l.next;for(;this.live.head!=null;){let s=this.live,i=s.head.elt;s.pop();let r=i,o=r.component,a;if(o==o.parent)a=o;else{let x=o,f=null;for(;x!=x.parent;){let _=x.parent;x.parent=f,f=x,x=_}for(;f!=null;){let _=f.parent;f.parent=x,f=_}a=x}if(a.island==null){Mt.zpp_pool==null?a.island=new Mt:(a.island=Mt.zpp_pool,Mt.zpp_pool=a.island.next,a.island.next=null),a.island.waket=0;let x=this.islands,f=a.island;f._inuse=!0;let _=f;_.next=x.next,x.next=_,x.modified=!0,x.length++,a.island.sleep=!0}o.island=a.island;let p=o.island.comps,c;I._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new I._zpp.util.ZNPNode_ZPP_Component:(c=I._zpp.util.ZNPNode_ZPP_Component.zpp_pool,I._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=o;let u=c;u.next=p.head,p.head=u,p.modified=!0,p.length++;let h=r.atRest(e);o.island.sleep=o.island.sleep&&h,o.waket>o.island.waket&&(o.island.waket=o.waket)}for(;this.live_constraints.head!=null;){let s=this.live_constraints,i=s.head.elt;s.pop();let o=i.component,a;if(o==o.parent)a=o;else{let h=o,x=null;for(;h!=h.parent;){let f=h.parent;h.parent=x,x=h,h=f}for(;x!=null;){let f=x.parent;x.parent=h,x=f}a=h}o.island=a.island;let p=o.island.comps,c;I._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new I._zpp.util.ZNPNode_ZPP_Component:(c=I._zpp.util.ZNPNode_ZPP_Component.zpp_pool,I._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=o;let u=c;u.next=p.head,p.head=u,p.modified=!0,p.length++,o.waket>o.island.waket&&(o.island.waket=o.waket)}for(;this.islands.next!=null;){let s=this.islands,i=s.next;s.pop();let r=i;if(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 u=c.elt;this.bphase.sync(u),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 u=this.live,h=c.body,x;I._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?x=new I._zpp.util.ZNPNode_ZPP_Body:(x=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=x.next,x.next=null),x.elt=h;let f=x;f.next=u.head,u.head=f,u.modified=!0,u.length++}else{let u=this.live_constraints,h=c.constraint,x;I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?x=new I._zpp.util.ZNPNode_ZPP_Constraint:(x=I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=x.next,x.next=null),x.elt=h;let f=x;f.next=u.head,u.head=f,u.modified=!0,u.length++}c.sleeping=!1,c.island=null,c.parent=c,c.rank=0}let o=r;o.next=Mt.zpp_pool,Mt.zpp_pool=o}}}sleepArbiters(){let e=null,t=this.c_arbiters_true,n=t.head,l=this.c_arbiters_false!=null;for(l&&n==null&&(l=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);n!=null;){let h=n.elt;if(h.b1.component.sleeping&&h.b2.component.sleeping){h.sleep_stamp=this.stamp,h.sleeping=!0;let x,f;e==null?(x=t.head,f=x.next,t.head=f,t.head==null&&(t.pushmod=!0)):(x=e.next,f=x.next,e.next=f,f==null&&(t.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=_,t.modified=!0,t.length--,t.pushmod=!0,n=f,l&&n==null&&(l=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);continue}e=n,n=n.next,l&&n==null&&(l=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null)}let s=null,i=this.f_arbiters,r=i.head,o=!1;for(o&&r==null&&(o=!1,i=null,s=null);r!=null;){let h=r.elt;if(h.b1.component.sleeping&&h.b2.component.sleeping){h.sleep_stamp=this.stamp,h.sleeping=!0;let x,f;s==null?(x=i.head,f=x.next,i.head=f,i.head==null&&(i.pushmod=!0)):(x=s.next,f=x.next,s.next=f,f==null&&(i.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=_,i.modified=!0,i.length--,i.pushmod=!0,r=f,o&&r==null&&(o=!1,i=null,s=null);continue}s=r,r=r.next,o&&r==null&&(o=!1,i=null,s=null)}let a=null,p=this.s_arbiters,c=p.head,u=!1;for(u&&c==null&&(u=!1,p=null,a=null);c!=null;){let h=c.elt;if(h.b1.component.sleeping&&h.b2.component.sleeping){h.sleep_stamp=this.stamp,h.sleeping=!0;let x,f;a==null?(x=p.head,f=x.next,p.head=f,p.head==null&&(p.pushmod=!0)):(x=a.next,f=x.next,a.next=f,f==null&&(p.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=_,p.modified=!0,p.length--,p.pushmod=!0,c=f,u&&c==null&&(u=!1,p=null,a=null);continue}a=c,c=c.next,u&&c==null&&(u=!1,p=null,a=null)}}static_validation(e){if(e.shapes.head!=null){if(e.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(e.zip_aabb){e.zip_aabb=!1,e.aabb.minx=1/0,e.aabb.miny=1/0,e.aabb.maxx=-1/0,e.aabb.maxy=-1/0;let n=e.shapes.head;for(;n!=null;){let l=n.elt;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let 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 u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let f=h;for(h=h.next;h!=null;){let M=h;u+=f.x*(M.y-x.y);let y=M.y*f.x-M.x*f.y;c.localCOMx+=(f.x+M.x)*y,c.localCOMy+=(f.y+M.y)*y,x=f,f=M,h=h.next}h=c.lverts.next;let _=h;u+=f.x*(_.y-x.y);let d=_.y*f.x-_.x*f.y;c.localCOMx+=(f.x+_.x)*d,c.localCOMy+=(f.y+_.y)*d,x=f,f=_,h=h.next;let b=h;u+=f.x*(b.y-x.y);let m=b.y*f.x-b.x*f.y;c.localCOMx+=(f.x+b.x)*m,c.localCOMy+=(f.y+b.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}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,u=r.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=r.body.posx+(r.body.axisy*x.x-r.body.axisx*x.y),h.y=r.body.posy+(x.x*r.body.axisx+x.y*r.body.axisy),u=u.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 s=e.aabb,i=l.aabb;i.minx<s.minx&&(s.minx=i.minx),i.maxx>s.maxx&&(s.maxx=i.maxx),i.miny<s.miny&&(s.miny=i.miny),i.maxy>s.maxy&&(s.maxy=i.maxy),n=n.next}}}if(e.validate_mass(),e.validate_inertia(),e.velx!=0||e.vely!=0||e.angvel!=0)throw new Error("Error: Static body cannot have any real velocity, only kinematic or surface velocities");let t=e.shapes.head;for(;t!=null;){let n=t.elt;if(n.type==1){let l=n.polygon;l.zip_sanitation&&(l.zip_sanitation=!1,l.splice_collinear_real());let s=n.polygon.valid();if(T.ValidationResult_VALID==null&&(T.internal=!0,T.ValidationResult_VALID=new I._nape.shape.ValidationResult,T.internal=!1),s!=T.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+n.polygon.outer.toString()+" is invalid : "+s.toString());let i=n.polygon;if(i.zip_gaxi&&i.body!=null){i.zip_gaxi=!1,i.validate_laxi();let r=i.body;if(r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let h=i.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot));let x=i.lverts.next,f=i.gverts.next;for(;f!=null;){let _=f,d=x;x=x.next,_.x=i.body.posx+(i.body.axisy*d.x-i.body.axisx*d.y),_.y=i.body.posy+(d.x*i.body.axisx+d.y*i.body.axisy),f=f.next}}let o=i.edges.head,a=i.gverts.next,p=a;for(a=a.next;a!=null;){let h=a,x=o.elt;o=o.next,x.gp0=p,x.gp1=h,x.gnormx=i.body.axisy*x.lnormx-i.body.axisx*x.lnormy,x.gnormy=x.lnormx*i.body.axisx+x.lnormy*i.body.axisy,x.gprojection=i.body.posx*x.gnormx+i.body.posy*x.gnormy+x.lprojection,x.wrap_gnorm!=null&&(x.wrap_gnorm.zpp_inner.x=x.gnormx,x.wrap_gnorm.zpp_inner.y=x.gnormy),x.tp0=x.gp0.y*x.gnormx-x.gp0.x*x.gnormy,x.tp1=x.gp1.y*x.gnormx-x.gp1.x*x.gnormy,p=h,a=a.next}let c=i.gverts.next,u=o.elt;o=o.next,u.gp0=p,u.gp1=c,u.gnormx=i.body.axisy*u.lnormx-i.body.axisx*u.lnormy,u.gnormy=u.lnormx*i.body.axisx+u.lnormy*i.body.axisy,u.gprojection=i.body.posx*u.gnormx+i.body.posy*u.gnormy+u.lprojection,u.wrap_gnorm!=null&&(u.wrap_gnorm.zpp_inner.x=u.gnormx,u.wrap_gnorm.zpp_inner.y=u.gnormy),u.tp0=u.gp0.y*u.gnormx-u.gp0.x*u.gnormy,u.tp1=u.gp1.y*u.gnormx-u.gp1.x*u.gnormy}}t=t.next}e.sweepFrozen=!0}validation(){let e=this.cbsets;if(!e.cbsets.empty()){let s=e.cbsets.parent;for(;s.prev!=null;)s=s.prev;for(;s!=null;)if(s.data.validate(),s.next!=null)for(s=s.next;s.prev!=null;)s=s.prev;else{for(;s.parent!=null&&s==s.parent.next;)s=s.parent;s=s.parent}}let t=this.live.head;for(;t!=null;){let s=t.elt;s.sweepRadius=0;let i=s.shapes.head;for(;i!=null;){let o=i.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(T.ValidationResult_VALID==null&&(T.internal=!0,T.ValidationResult_VALID=new I._nape.shape.ValidationResult,T.internal=!1),p!=T.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 u=c.body;if(u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let b=c.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot));let m=c.lverts.next,z=c.gverts.next;for(;z!=null;){let M=z,y=m;m=m.next,M.x=c.body.posx+(c.body.axisy*y.x-c.body.axisx*y.y),M.y=c.body.posy+(y.x*c.body.axisx+y.y*c.body.axisy),z=z.next}}let h=c.edges.head,x=c.gverts.next,f=x;for(x=x.next;x!=null;){let b=x,m=h.elt;h=h.next,m.gp0=f,m.gp1=b,m.gnormx=c.body.axisy*m.lnormx-c.body.axisx*m.lnormy,m.gnormy=m.lnormx*c.body.axisx+m.lnormy*c.body.axisy,m.gprojection=c.body.posx*m.gnormx+c.body.posy*m.gnormy+m.lprojection,m.wrap_gnorm!=null&&(m.wrap_gnorm.zpp_inner.x=m.gnormx,m.wrap_gnorm.zpp_inner.y=m.gnormy),m.tp0=m.gp0.y*m.gnormx-m.gp0.x*m.gnormy,m.tp1=m.gp1.y*m.gnormx-m.gp1.x*m.gnormy,f=b,x=x.next}let _=c.gverts.next,d=h.elt;h=h.next,d.gp0=f,d.gp1=_,d.gnormx=c.body.axisy*d.lnormx-c.body.axisx*d.lnormy,d.gnormy=d.lnormx*c.body.axisx+d.lnormy*c.body.axisy,d.gprojection=c.body.posx*d.gnormx+c.body.posy*d.gnormy+d.lprojection,d.wrap_gnorm!=null&&(d.wrap_gnorm.zpp_inner.x=d.gnormx,d.wrap_gnorm.zpp_inner.y=d.gnormy),d.tp0=d.gp0.y*d.gnormx-d.gp0.x*d.gnormy,d.tp1=d.gp1.y*d.gnormx-d.gp1.x*d.gnormy}}o.validate_sweepRadius(),o.sweepRadius>s.sweepRadius&&(s.sweepRadius=o.sweepRadius),i=i.next}if(s.validate_mass(),s.validate_inertia(),s.shapes.head!=null){if(s.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(s.zip_aabb){s.zip_aabb=!1,s.aabb.minx=1/0,s.aabb.miny=1/0,s.aabb.maxx=-1/0,s.aabb.maxy=-1/0;let o=s.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 u=a.circle;if(u.zip_worldCOM&&u.body!=null){if(u.zip_worldCOM=!1,u.zip_localCOM){if(u.zip_localCOM=!1,u.type==1){let _=u.polygon;if(_.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(_.lverts.next.next==null)_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;else if(_.lverts.next.next.next==null){_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;let d=1;_.localCOMx+=_.lverts.next.next.x*d,_.localCOMy+=_.lverts.next.next.y*d;let b=.5;_.localCOMx*=b,_.localCOMy*=b}else{_.localCOMx=0,_.localCOMy=0;let d=0,b=_.lverts.next,m=b;b=b.next;let z=b;for(b=b.next;b!=null;){let g=b;d+=z.x*(g.y-m.y);let E=g.y*z.x-g.x*z.y;_.localCOMx+=(z.x+g.x)*E,_.localCOMy+=(z.y+g.y)*E,m=z,z=g,b=b.next}b=_.lverts.next;let M=b;d+=z.x*(M.y-m.y);let y=M.y*z.x-M.x*z.y;_.localCOMx+=(z.x+M.x)*y,_.localCOMy+=(z.y+M.y)*y,m=z,z=M,b=b.next;let w=b;d+=z.x*(w.y-m.y);let v=w.y*z.x-w.x*z.y;_.localCOMx+=(z.x+w.x)*v,_.localCOMy+=(z.y+w.y)*v,d=1/(3*d);let P=d;_.localCOMx*=P,_.localCOMy*=P}}u.wrap_localCOM!=null&&(u.wrap_localCOM.zpp_inner.x=u.localCOMx,u.wrap_localCOM.zpp_inner.y=u.localCOMy)}let f=u.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot)),u.worldCOMx=u.body.posx+(u.body.axisy*u.localCOMx-u.body.axisx*u.localCOMy),u.worldCOMy=u.body.posy+(u.localCOMx*u.body.axisx+u.localCOMy*u.body.axisy)}let h=u.radius,x=u.radius;u.aabb.minx=u.worldCOMx-h,u.aabb.miny=u.worldCOMy-x,u.aabb.maxx=u.worldCOMx+h,u.aabb.maxy=u.worldCOMy+x}else{let u=a.polygon;if(u.zip_gverts&&u.body!=null){u.zip_gverts=!1,u.validate_lverts();let f=u.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let _=u.lverts.next,d=u.gverts.next;for(;d!=null;){let b=d,m=_;_=_.next,b.x=u.body.posx+(u.body.axisy*m.x-u.body.axisx*m.y),b.y=u.body.posy+(m.x*u.body.axisx+m.y*u.body.axisy),d=d.next}}if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let h=u.gverts.next;u.aabb.minx=h.x,u.aabb.miny=h.y,u.aabb.maxx=h.x,u.aabb.maxy=h.y;let x=u.gverts.next.next;for(;x!=null;){let f=x;f.x<u.aabb.minx&&(u.aabb.minx=f.x),f.x>u.aabb.maxx&&(u.aabb.maxx=f.x),f.y<u.aabb.miny&&(u.aabb.miny=f.y),f.y>u.aabb.maxy&&(u.aabb.maxy=f.y),x=x.next}}let p=s.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),o=o.next}}s.validate_worldCOM()}if(s.validate_gravMass(),s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),!s.nomove&&s.type==2&&s.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!s.norotate&&s.type==2&&s.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");if(s.component.woken&&s.cbSet!=null){let o=s.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=s,o=o.next}}s.component.woken=!1;let r=s.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 s=n.elt;s.sweepRadius=0;let i=s.shapes.head;for(;i!=null;){let o=i.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(T.ValidationResult_VALID==null&&(T.internal=!0,T.ValidationResult_VALID=new I._nape.shape.ValidationResult,T.internal=!1),p!=T.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 u=c.body;if(u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let b=c.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot));let m=c.lverts.next,z=c.gverts.next;for(;z!=null;){let M=z,y=m;m=m.next,M.x=c.body.posx+(c.body.axisy*y.x-c.body.axisx*y.y),M.y=c.body.posy+(y.x*c.body.axisx+y.y*c.body.axisy),z=z.next}}let h=c.edges.head,x=c.gverts.next,f=x;for(x=x.next;x!=null;){let b=x,m=h.elt;h=h.next,m.gp0=f,m.gp1=b,m.gnormx=c.body.axisy*m.lnormx-c.body.axisx*m.lnormy,m.gnormy=m.lnormx*c.body.axisx+m.lnormy*c.body.axisy,m.gprojection=c.body.posx*m.gnormx+c.body.posy*m.gnormy+m.lprojection,m.wrap_gnorm!=null&&(m.wrap_gnorm.zpp_inner.x=m.gnormx,m.wrap_gnorm.zpp_inner.y=m.gnormy),m.tp0=m.gp0.y*m.gnormx-m.gp0.x*m.gnormy,m.tp1=m.gp1.y*m.gnormx-m.gp1.x*m.gnormy,f=b,x=x.next}let _=c.gverts.next,d=h.elt;h=h.next,d.gp0=f,d.gp1=_,d.gnormx=c.body.axisy*d.lnormx-c.body.axisx*d.lnormy,d.gnormy=d.lnormx*c.body.axisx+d.lnormy*c.body.axisy,d.gprojection=c.body.posx*d.gnormx+c.body.posy*d.gnormy+d.lprojection,d.wrap_gnorm!=null&&(d.wrap_gnorm.zpp_inner.x=d.gnormx,d.wrap_gnorm.zpp_inner.y=d.gnormy),d.tp0=d.gp0.y*d.gnormx-d.gp0.x*d.gnormy,d.tp1=d.gp1.y*d.gnormx-d.gp1.x*d.gnormy}}o.validate_sweepRadius(),o.sweepRadius>s.sweepRadius&&(s.sweepRadius=o.sweepRadius),i=i.next}if(s.validate_mass(),s.validate_inertia(),s.shapes.head!=null){if(s.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(s.zip_aabb){s.zip_aabb=!1,s.aabb.minx=1/0,s.aabb.miny=1/0,s.aabb.maxx=-1/0,s.aabb.maxy=-1/0;let o=s.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 u=a.circle;if(u.zip_worldCOM&&u.body!=null){if(u.zip_worldCOM=!1,u.zip_localCOM){if(u.zip_localCOM=!1,u.type==1){let _=u.polygon;if(_.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(_.lverts.next.next==null)_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;else if(_.lverts.next.next.next==null){_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;let d=1;_.localCOMx+=_.lverts.next.next.x*d,_.localCOMy+=_.lverts.next.next.y*d;let b=.5;_.localCOMx*=b,_.localCOMy*=b}else{_.localCOMx=0,_.localCOMy=0;let d=0,b=_.lverts.next,m=b;b=b.next;let z=b;for(b=b.next;b!=null;){let g=b;d+=z.x*(g.y-m.y);let E=g.y*z.x-g.x*z.y;_.localCOMx+=(z.x+g.x)*E,_.localCOMy+=(z.y+g.y)*E,m=z,z=g,b=b.next}b=_.lverts.next;let M=b;d+=z.x*(M.y-m.y);let y=M.y*z.x-M.x*z.y;_.localCOMx+=(z.x+M.x)*y,_.localCOMy+=(z.y+M.y)*y,m=z,z=M,b=b.next;let w=b;d+=z.x*(w.y-m.y);let v=w.y*z.x-w.x*z.y;_.localCOMx+=(z.x+w.x)*v,_.localCOMy+=(z.y+w.y)*v,d=1/(3*d);let P=d;_.localCOMx*=P,_.localCOMy*=P}}u.wrap_localCOM!=null&&(u.wrap_localCOM.zpp_inner.x=u.localCOMx,u.wrap_localCOM.zpp_inner.y=u.localCOMy)}let f=u.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot)),u.worldCOMx=u.body.posx+(u.body.axisy*u.localCOMx-u.body.axisx*u.localCOMy),u.worldCOMy=u.body.posy+(u.localCOMx*u.body.axisx+u.localCOMy*u.body.axisy)}let h=u.radius,x=u.radius;u.aabb.minx=u.worldCOMx-h,u.aabb.miny=u.worldCOMy-x,u.aabb.maxx=u.worldCOMx+h,u.aabb.maxy=u.worldCOMy+x}else{let u=a.polygon;if(u.zip_gverts&&u.body!=null){u.zip_gverts=!1,u.validate_lverts();let f=u.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let _=u.lverts.next,d=u.gverts.next;for(;d!=null;){let b=d,m=_;_=_.next,b.x=u.body.posx+(u.body.axisy*m.x-u.body.axisx*m.y),b.y=u.body.posy+(m.x*u.body.axisx+m.y*u.body.axisy),d=d.next}}if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let h=u.gverts.next;u.aabb.minx=h.x,u.aabb.miny=h.y,u.aabb.maxx=h.x,u.aabb.maxy=h.y;let x=u.gverts.next.next;for(;x!=null;){let f=x;f.x<u.aabb.minx&&(u.aabb.minx=f.x),f.x>u.aabb.maxx&&(u.aabb.maxx=f.x),f.y<u.aabb.miny&&(u.aabb.miny=f.y),f.y>u.aabb.maxy&&(u.aabb.maxy=f.y),x=x.next}}let p=s.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),o=o.next}}s.validate_worldCOM()}if(s.validate_gravMass(),s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),!s.nomove&&s.type==2&&s.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!s.norotate&&s.type==2&&s.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");let r=s.shapes.head;for(;r!=null;){let o=r.elt;this.bphase.sync(o),r=r.next}n=n.next}let l=this.live_constraints.head;for(;l!=null;){let s=l.elt;if(s.active){if(s.validate(),s.component.woken&&s.cbSet!=null){let i=s.cbSet.conlisteners.head;for(;i!=null;){let r=i.elt;if(r.event!=2){i=i.next;continue}let o=this.push_callback(r);o.event=2,o.constraint=s,i=i.next}}s.component.woken=!1}l=l.next}}updateVel(e){let t=null,n=1-e*this.global_lin_drag,l=1-e*this.global_ang_drag,s=this.live.head;for(;s!=null;){let i=s.elt;if(i.smass!=0){let r=e*i.imass;i.velx=n*i.velx+(i.forcex+this.gravityx*i.gravMass)*r,i.vely=n*i.vely+(i.forcey+this.gravityy*i.gravMass)*r}if(i.sinertia!=0){let r=0,o=0;r=i.worldCOMx-i.posx,o=i.worldCOMy-i.posy;let a=i.torque+(this.gravityy*r-this.gravityx*o)*i.gravMass;i.angvel=l*i.angvel+a*e*i.iinertia}t=s,s=s.next}}updatePos(e){let t=2*Math.PI/e,n=this.live.head;for(;n!=null;){let s=n.elt;s.pre_posx=s.posx,s.pre_posy=s.posy,s.pre_rot=s.rot,s.sweepTime=0,s.sweep_angvel=s.angvel%t;let i=e-s.sweepTime;if(i!=0){s.sweepTime=e;let r=i;if(s.posx+=s.velx*r,s.posy+=s.vely*r,s.angvel!=0){let o=s.sweep_angvel*i;if(s.rot+=o,o*o>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let a=o*o,p=1-.5*a,c=1-a*a/8,u=(p*s.axisx+o*s.axisy)*c;s.axisy=(p*s.axisy-o*s.axisx)*c,s.axisx=u}}}if(s.disableCCD)s.sweepFrozen=!0,s.bullet=!1;else{let r=I._nape.Config.staticCCDLinearThreshold*s.sweepRadius,o=I._nape.Config.staticCCDAngularThreshold;if((s.velx*s.velx+s.vely*s.vely)*e*e>r*r||s.angvel*s.angvel*e*e>o*o||s.type==3){let a=s.sweep_angvel;a<0&&(a=-a);let p=1/a,c=s.shapes.head;for(;c!=null;){let u=c.elt,h=u.aabb,x=h.minx,f=h.miny,_=h.maxx,d=h.maxy,b=a*e*u.sweepCoef*.008333333333333333|0;b>8&&(b=8);let m=a*e/b,z=e-s.sweepTime;if(z!=0){s.sweepTime=e;let w=z;if(s.posx+=s.velx*w,s.posy+=s.vely*w,s.angvel!=0){let v=s.sweep_angvel*z;if(s.rot+=v,v*v>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let P=v*v,g=1-.5*P,E=1-P*P/8,N=(g*s.axisx+v*s.axisy)*E;s.axisy=(g*s.axisy-v*s.axisx)*E,s.axisx=N}}}if(u.type==0){let w=u.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else{let w=u.polygon,v=w.lverts.next,P=w.gverts.next,g=v;v=v.next,P.x=w.body.posx+(w.body.axisy*g.x-w.body.axisx*g.y),P.y=w.body.posy+(g.x*w.body.axisx+g.y*w.body.axisy),w.aabb.minx=P.x,w.aabb.miny=P.y,w.aabb.maxx=P.x,w.aabb.maxy=P.y;let E=w.gverts.next.next;for(;E!=null;){let N=E,k=v;v=v.next,N.x=w.body.posx+(w.body.axisy*k.x-w.body.axisx*k.y),N.y=w.body.posy+(k.x*w.body.axisx+k.y*w.body.axisy),N.x<w.aabb.minx&&(w.aabb.minx=N.x),N.x>w.aabb.maxx&&(w.aabb.maxx=N.x),N.y<w.aabb.miny&&(w.aabb.miny=N.y),N.y>w.aabb.maxy&&(w.aabb.maxy=N.y),E=E.next}}x<h.minx?h.minx=x:x=h.minx,f<h.miny?h.miny=f:f=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy;let M=1,y=b;for(;M<y;){let w=M++,v=m*w*p,P=v-s.sweepTime;if(P!=0){s.sweepTime=v;let g=P;if(s.posx+=s.velx*g,s.posy+=s.vely*g,s.angvel!=0){let E=s.sweep_angvel*P;if(s.rot+=E,E*E>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let N=E*E,k=1-.5*N,Z=1-N*N/8,C=(k*s.axisx+E*s.axisy)*Z;s.axisy=(k*s.axisy-E*s.axisx)*Z,s.axisx=C}}}if(u.type==0){let g=u.circle;g.worldCOMx=g.body.posx+(g.body.axisy*g.localCOMx-g.body.axisx*g.localCOMy),g.worldCOMy=g.body.posy+(g.localCOMx*g.body.axisx+g.localCOMy*g.body.axisy),g.aabb.minx=g.worldCOMx-g.radius,g.aabb.miny=g.worldCOMy-g.radius,g.aabb.maxx=g.worldCOMx+g.radius,g.aabb.maxy=g.worldCOMy+g.radius}else{let g=u.polygon,E=g.lverts.next,N=g.gverts.next,k=E;E=E.next,N.x=g.body.posx+(g.body.axisy*k.x-g.body.axisx*k.y),N.y=g.body.posy+(k.x*g.body.axisx+k.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 Z=g.gverts.next.next;for(;Z!=null;){let C=Z,F=E;E=E.next,C.x=g.body.posx+(g.body.axisy*F.x-g.body.axisx*F.y),C.y=g.body.posy+(F.x*g.body.axisx+F.y*g.body.axisy),C.x<g.aabb.minx&&(g.aabb.minx=C.x),C.x>g.aabb.maxx&&(g.aabb.maxx=C.x),C.y<g.aabb.miny&&(g.aabb.miny=C.y),C.y>g.aabb.maxy&&(g.aabb.maxy=C.y),Z=Z.next}}x<h.minx?h.minx=x:x=h.minx,f<h.miny?h.miny=f:f=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy}this.bphase.sync(u),c=c.next}if(s.sweepFrozen=!1,s.type==2&&s.bulletEnabled){let u=I._nape.Config.bulletCCDLinearThreshold*s.sweepRadius,h=I._nape.Config.bulletCCDAngularThreshold;((s.velx*s.velx+s.vely*s.vely)*e*e>u*u||s.angvel*s.angvel*e*e>h*h)&&(s.bullet=!0)}}else s.sweepFrozen=!0,s.bullet=!1}n=n.next}let l=this.kinematics.head;for(;l!=null;){let s=l.elt;s.pre_posx=s.posx,s.pre_posy=s.posy,s.pre_rot=s.rot,s.sweepTime=0,s.sweep_angvel=s.angvel%t;let i=e-s.sweepTime;if(i!=0){s.sweepTime=e;let r=i;if(s.posx+=s.velx*r,s.posy+=s.vely*r,s.angvel!=0){let o=s.sweep_angvel*i;if(s.rot+=o,o*o>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let a=o*o,p=1-.5*a,c=1-a*a/8,u=(p*s.axisx+o*s.axisy)*c;s.axisy=(p*s.axisy-o*s.axisx)*c,s.axisx=u}}}if(s.disableCCD)s.sweepFrozen=!0,s.bullet=!1;else{let r=I._nape.Config.staticCCDLinearThreshold*s.sweepRadius,o=I._nape.Config.staticCCDAngularThreshold;if((s.velx*s.velx+s.vely*s.vely)*e*e>r*r||s.angvel*s.angvel*e*e>o*o||s.type==3){let a=s.sweep_angvel;a<0&&(a=-a);let p=1/a,c=s.shapes.head;for(;c!=null;){let u=c.elt,h=u.aabb,x=h.minx,f=h.miny,_=h.maxx,d=h.maxy,b=a*e*u.sweepCoef*.008333333333333333|0;b>8&&(b=8);let m=a*e/b,z=e-s.sweepTime;if(z!=0){s.sweepTime=e;let w=z;if(s.posx+=s.velx*w,s.posy+=s.vely*w,s.angvel!=0){let v=s.sweep_angvel*z;if(s.rot+=v,v*v>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let P=v*v,g=1-.5*P,E=1-P*P/8,N=(g*s.axisx+v*s.axisy)*E;s.axisy=(g*s.axisy-v*s.axisx)*E,s.axisx=N}}}if(u.type==0){let w=u.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else{let w=u.polygon,v=w.lverts.next,P=w.gverts.next,g=v;v=v.next,P.x=w.body.posx+(w.body.axisy*g.x-w.body.axisx*g.y),P.y=w.body.posy+(g.x*w.body.axisx+g.y*w.body.axisy),w.aabb.minx=P.x,w.aabb.miny=P.y,w.aabb.maxx=P.x,w.aabb.maxy=P.y;let E=w.gverts.next.next;for(;E!=null;){let N=E,k=v;v=v.next,N.x=w.body.posx+(w.body.axisy*k.x-w.body.axisx*k.y),N.y=w.body.posy+(k.x*w.body.axisx+k.y*w.body.axisy),N.x<w.aabb.minx&&(w.aabb.minx=N.x),N.x>w.aabb.maxx&&(w.aabb.maxx=N.x),N.y<w.aabb.miny&&(w.aabb.miny=N.y),N.y>w.aabb.maxy&&(w.aabb.maxy=N.y),E=E.next}}x<h.minx?h.minx=x:x=h.minx,f<h.miny?h.miny=f:f=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy;let M=1,y=b;for(;M<y;){let w=M++,v=m*w*p,P=v-s.sweepTime;if(P!=0){s.sweepTime=v;let g=P;if(s.posx+=s.velx*g,s.posy+=s.vely*g,s.angvel!=0){let E=s.sweep_angvel*P;if(s.rot+=E,E*E>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let N=E*E,k=1-.5*N,Z=1-N*N/8,C=(k*s.axisx+E*s.axisy)*Z;s.axisy=(k*s.axisy-E*s.axisx)*Z,s.axisx=C}}}if(u.type==0){let g=u.circle;g.worldCOMx=g.body.posx+(g.body.axisy*g.localCOMx-g.body.axisx*g.localCOMy),g.worldCOMy=g.body.posy+(g.localCOMx*g.body.axisx+g.localCOMy*g.body.axisy),g.aabb.minx=g.worldCOMx-g.radius,g.aabb.miny=g.worldCOMy-g.radius,g.aabb.maxx=g.worldCOMx+g.radius,g.aabb.maxy=g.worldCOMy+g.radius}else{let g=u.polygon,E=g.lverts.next,N=g.gverts.next,k=E;E=E.next,N.x=g.body.posx+(g.body.axisy*k.x-g.body.axisx*k.y),N.y=g.body.posy+(k.x*g.body.axisx+k.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 Z=g.gverts.next.next;for(;Z!=null;){let C=Z,F=E;E=E.next,C.x=g.body.posx+(g.body.axisy*F.x-g.body.axisx*F.y),C.y=g.body.posy+(F.x*g.body.axisx+F.y*g.body.axisy),C.x<g.aabb.minx&&(g.aabb.minx=C.x),C.x>g.aabb.maxx&&(g.aabb.maxx=C.x),C.y<g.aabb.miny&&(g.aabb.miny=C.y),C.y>g.aabb.maxy&&(g.aabb.maxy=C.y),Z=Z.next}}x<h.minx?h.minx=x:x=h.minx,f<h.miny?h.miny=f:f=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy}this.bphase.sync(u),c=c.next}if(s.sweepFrozen=!1,s.type==2&&s.bulletEnabled){let u=I._nape.Config.bulletCCDLinearThreshold*s.sweepRadius,h=I._nape.Config.bulletCCDAngularThreshold;((s.velx*s.velx+s.vely*s.vely)*e*e>u*u||s.angvel*s.angvel*e*e>h*h)&&(s.bullet=!0)}}else s.sweepFrozen=!0,s.bullet=!1}l=l.next}}presteparb(e,t,n){n==null&&(n=!1);let l=this;if(!e.cleared&&e.b1.component.sleeping&&e.b2.component.sleeping)return e.sleep_stamp=this.stamp,e.sleeping=!0,!0;if(!e.cleared||e.present!=0||e.intchange){let i=!n&&e.up_stamp==this.stamp-1&&!e.cleared&&!e.intchange,r=e.fresh&&!e.cleared&&!e.intchange;if(i&&(e.endGenerated=this.stamp),r||i||e.cleared||e.intchange){let o=e.ws1,a=e.ws2,p=this.mrca1;for(;p.head!=null;){let f=p.head;p.head=f.next;let _=f;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_,p.head==null&&(p.pushmod=!0),p.modified=!0,p.length--}p.pushmod=!0;let c=this.mrca2;for(;c.head!=null;){let f=c.head;c.head=f.next;let _=f;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_,c.head==null&&(c.pushmod=!0),c.modified=!0,c.length--}if(c.pushmod=!0,o.cbSet!=null){let f=this.mrca1,_;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new I._zpp.util.ZNPNode_ZPP_Interactor:(_=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=o;let d=_;d.next=f.head,f.head=d,f.modified=!0,f.length++}if(o.body.cbSet!=null){let f=this.mrca1,_=o.body,d;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_Interactor:(d=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=_;let b=d;b.next=f.head,f.head=b,f.modified=!0,f.length++}if(a.cbSet!=null){let f=this.mrca2,_;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new I._zpp.util.ZNPNode_ZPP_Interactor:(_=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=a;let d=_;d.next=f.head,f.head=d,f.modified=!0,f.length++}if(a.body.cbSet!=null){let f=this.mrca2,_=a.body,d;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_Interactor:(d=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=_;let b=d;b.next=f.head,f.head=b,f.modified=!0,f.length++}let u=o.body.compound,h=a.body.compound;for(;u!=h;){let f=u==null?0:u.depth,_=h==null?0:h.depth;if(f<_){if(h.cbSet!=null){let d=this.mrca2,b;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?b=new I._zpp.util.ZNPNode_ZPP_Interactor:(b=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=b.next,b.next=null),b.elt=h;let m=b;m.next=d.head,d.head=m,d.modified=!0,d.length++}h=h.compound}else{if(u.cbSet!=null){let d=this.mrca1,b;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?b=new I._zpp.util.ZNPNode_ZPP_Interactor:(b=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=b.next,b.next=null),b.elt=u;let m=b;m.next=d.head,d.head=m,d.modified=!0,d.length++}u=u.compound}}let x=this.mrca1.head;for(;x!=null;){let f=x.elt,_=this.mrca2.head;for(;_!=null;){let d=_.elt,b=f.cbSet,m=d.cbSet,z=b.manager,M=null,w=(b.cbpairs.length<m.cbpairs.length?b.cbpairs:m.cbpairs).head;for(;w!=null;){let P=w.elt;if(P.a==b&&P.b==m||P.a==m&&P.b==b){M=P;break}w=w.next}if(M==null){let P;Se.zpp_pool==null?P=new Se:(P=Se.zpp_pool,Se.zpp_pool=P.next,P.next=null),P.zip_listeners=!0,St.setlt(b,m)?(P.a=b,P.b=m):(P.a=m,P.b=b),M=P,b.cbpairs.add(M),m!=b&&m.cbpairs.add(M)}if(M.zip_listeners&&(M.zip_listeners=!1,M.__validate()),M.listeners.head==null){_=_.next;continue}let v=I._zpp.phys.ZPP_Interactor.get(f,d);if(r||e.intchange){v==null&&(v=xn.get(f,d),this.add_callbackset(v));let P=b.manager,g=null,N=(b.cbpairs.length<m.cbpairs.length?b.cbpairs:m.cbpairs).head;for(;N!=null;){let O=N.elt;if(O.a==b&&O.b==m||O.a==m&&O.b==b){g=O;break}N=N.next}if(g==null){let O;Se.zpp_pool==null?O=new Se:(O=Se.zpp_pool,Se.zpp_pool=O.next,O.next=null),O.zip_listeners=!0,St.setlt(b,m)?(O.a=b,O.b=m):(O.a=m,O.b=b),g=O,b.cbpairs.add(g),m!=b&&m.cbpairs.add(g)}g.zip_listeners&&(g.zip_listeners=!1,g.__validate());let k=g.listeners.head;for(;k!=null;){let O=k.elt;if(O.event==0&&(O.itype&e.type)!=0&&v.empty_arb(O.itype)){let B=l.push_callback(O);B.event=0;let D=v.int1,U=v.int2,W,q=O.options1,L=D.cbTypes;if(q.nonemptyintersection(L,q.includes)&&!q.nonemptyintersection(L,q.excludes)){let A=O.options2,J=U.cbTypes;W=A.nonemptyintersection(J,A.includes)&&!A.nonemptyintersection(J,A.excludes)}else W=!1;W?(B.int1=D,B.int2=U):(B.int1=U,B.int2=D),B.set=v}k=k.next}let Z,C;C=!1;let F=v.arbiters.head;for(;F!=null;){if(F.elt==e){C=!0;break}F=F.next}if(C)Z=!1;else{let O=v.arbiters,B;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?B=new I._zpp.util.ZNPNode_ZPP_Arbiter:(B=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=B.next,B.next=null),B.elt=e;let D=B;D.next=O.head,O.head=D,O.modified=!0,O.length++,Z=!0}Z&&e.present++}else{e.present--,v.remove_arb(e);let P=b.manager,g=null,N=(b.cbpairs.length<m.cbpairs.length?b.cbpairs:m.cbpairs).head;for(;N!=null;){let Z=N.elt;if(Z.a==b&&Z.b==m||Z.a==m&&Z.b==b){g=Z;break}N=N.next}if(g==null){let Z;Se.zpp_pool==null?Z=new Se:(Z=Se.zpp_pool,Se.zpp_pool=Z.next,Z.next=null),Z.zip_listeners=!0,St.setlt(b,m)?(Z.a=b,Z.b=m):(Z.a=m,Z.b=b),g=Z,b.cbpairs.add(g),m!=b&&m.cbpairs.add(g)}g.zip_listeners&&(g.zip_listeners=!1,g.__validate());let k=g.listeners.head;for(;k!=null;){let Z=k.elt;if(Z.event==1&&(Z.itype&e.type)!=0&&v.empty_arb(Z.itype)){let C=l.push_callback(Z);C.event=1;let F=v.int1,O=v.int2,B,D=Z.options1,U=F.cbTypes;if(D.nonemptyintersection(U,D.includes)&&!D.nonemptyintersection(U,D.excludes)){let W=Z.options2,q=O.cbTypes;B=W.nonemptyintersection(q,W.includes)&&!W.nonemptyintersection(q,W.excludes)}else B=!1;B?(C.int1=F,C.int2=O):(C.int1=O,C.int2=F),C.set=v}k=k.next}v.arbiters.head==null&&this.remove_callbackset(v)}_=_.next}x=x.next}}e.fresh=!1,e.intchange=!1}if(e.cleared||e.up_stamp+(e.type==ke.COL?I._nape.Config.arbiterExpirationDelay:0)<this.stamp){if(e.type==ke.SENSOR){let i=e.sensorarb;if(!i.cleared){let o=i.b1.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==i){let _,d;a==null?(_=o.head,d=_.next,o.head=d,o.head==null&&(o.pushmod=!0)):(_=a.next,d=_.next,a.next=d,d==null&&(o.pushmod=!0));let b=_;b.elt=null,b.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,o.modified=!0,o.length--,o.pushmod=!0,c=!0;break}a=p,p=p.next}let u=i.b2.arbiters,h=null,x=u.head,f=!1;for(;x!=null;){if(x.elt==i){let _,d;h==null?(_=u.head,d=_.next,u.head=d,u.head==null&&(u.pushmod=!0)):(_=h.next,d=_.next,h.next=d,d==null&&(u.pushmod=!0));let b=_;b.elt=null,b.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,u.modified=!0,u.length--,u.pushmod=!0,f=!0;break}h=x,x=x.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let r=i;r.next=Qt.zpp_pool,Qt.zpp_pool=r}else if(e.type==ke.FLUID){let i=e.fluidarb;if(!i.cleared){let o=i.b1.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==i){let _,d;a==null?(_=o.head,d=_.next,o.head=d,o.head==null&&(o.pushmod=!0)):(_=a.next,d=_.next,a.next=d,d==null&&(o.pushmod=!0));let b=_;b.elt=null,b.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,o.modified=!0,o.length--,o.pushmod=!0,c=!0;break}a=p,p=p.next}let u=i.b2.arbiters,h=null,x=u.head,f=!1;for(;x!=null;){if(x.elt==i){let _,d;h==null?(_=u.head,d=_.next,u.head=d,u.head==null&&(u.pushmod=!0)):(_=h.next,d=_.next,h.next=d,d==null&&(u.pushmod=!0));let b=_;b.elt=null,b.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,u.modified=!0,u.length--,u.pushmod=!0,f=!0;break}h=x,x=x.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let r=i;r.next=Bt.zpp_pool,Bt.zpp_pool=r,i.pre_dt=-1}else{let i=e.colarb;if(!i.cleared){let o=i.b1.arbiters,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==i){let _,d;a==null?(_=o.head,d=_.next,o.head=d,o.head==null&&(o.pushmod=!0)):(_=a.next,d=_.next,a.next=d,d==null&&(o.pushmod=!0));let b=_;b.elt=null,b.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,o.modified=!0,o.length--,o.pushmod=!0,c=!0;break}a=p,p=p.next}let u=i.b2.arbiters,h=null,x=u.head,f=!1;for(;x!=null;){if(x.elt==i){let _,d;h==null?(_=u.head,d=_.next,u.head=d,u.head==null&&(u.pushmod=!0)):(_=h.next,d=_.next,h.next=d,d==null&&(u.pushmod=!0));let b=_;b.elt=null,b.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,u.modified=!0,u.length--,u.pushmod=!0,f=!0;break}h=x,x=x.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}for(i.b1=i.b2=null,i.active=!1,i.intchange=!1;i.contacts.next!=null;){let o=i.contacts,a=o.next;o.pop();let p=a;p.arbiter=null,p.next=we.zpp_pool,we.zpp_pool=p;let c=i.innards,u=c.next;c.next=u.next,u._inuse=!1,c.next==null&&(c.pushmod=!0),c.modified=!0,c.length--}let r=i;r.userdef_dyn_fric=!1,r.userdef_stat_fric=!1,r.userdef_restitution=!1,r.userdef_rfric=!1,r.__ref_edge1=r.__ref_edge2=null,r.next=gt.zpp_pool,gt.zpp_pool=r,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!=ke.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 r=t/i.pre_dt;i.pre_dt=t;let o=i.b1.smass+i.b2.smass;i.hc2=!1;let a=!0,c=i.b1.type!=2||i.b2.type!=2?i.continuous?I._nape.Config.contactContinuousStaticBiasCoef:I._nape.Config.contactStaticBiasCoef:i.continuous?I._nape.Config.contactContinuousBiasCoef:I._nape.Config.contactBiasCoef;i.biasCoef=c,i.continuous=!1;let u=null,h=null,x=i.innards.next,f=i.contacts.next;for(;f!=null;){let d=f;if(d.stamp+I._nape.Config.arbiterExpirationDelay<i.stamp){let z=i.contacts,M,y;u==null?(M=z.next,y=M.next,z.next=y,z.next==null&&(z.pushmod=!0)):(M=u.next,y=M.next,u.next=y,y==null&&(z.pushmod=!0)),M._inuse=!1,z.modified=!0,z.length--,z.pushmod=!0,f=y;let w=i.innards,v,P;h==null?(v=w.next,P=v.next,w.next=P,w.next==null&&(w.pushmod=!0)):(v=h.next,P=v.next,h.next=P,P==null&&(w.pushmod=!0)),v._inuse=!1,w.modified=!0,w.length--,w.pushmod=!0,x=P;let g=d;g.arbiter=null,g.next=we.zpp_pool,we.zpp_pool=g;continue}let b=d.inner,m=d.active;if(d.active=d.stamp==i.stamp,d.active){a?(a=!1,i.c1=b,i.oc1=d):(i.hc2=!0,i.c2=b,i.oc2=d),b.r2x=d.px-i.b2.posx,b.r2y=d.py-i.b2.posy,b.r1x=d.px-i.b1.posx,b.r1y=d.py-i.b1.posy;let z=b.r2x*i.nx+b.r2y*i.ny,M=o+i.b2.sinertia*(z*z),y=b.r1x*i.nx+b.r1y*i.ny;M+=i.b1.sinertia*(y*y),b.tMass=M<I._nape.Config.epsilon*I._nape.Config.epsilon?0:1/M;let w=i.ny*b.r2x-i.nx*b.r2y,v=o+i.b2.sinertia*(w*w),P=i.ny*b.r1x-i.nx*b.r1y;v+=i.b1.sinertia*(P*P),b.nMass=v<I._nape.Config.epsilon*I._nape.Config.epsilon?0:1/v;let g=0,E=0,N=i.b2.angvel+i.b2.kinangvel;g=i.b2.velx+i.b2.kinvelx-b.r2y*N,E=i.b2.vely+i.b2.kinvely+b.r2x*N,N=i.b1.angvel+i.b1.kinangvel,g-=i.b1.velx+i.b1.kinvelx-b.r1y*N,E-=i.b1.vely+i.b1.kinvely+b.r1x*N;let k=i.nx*g+i.ny*E;d.elasticity=i.restitution,b.bounce=k*d.elasticity,b.bounce>-I._nape.Config.elasticThreshold&&(b.bounce=0),k=E*i.nx-g*i.ny;let Z=I._nape.Config.staticFrictionThreshold;k*k>Z*Z?b.friction=i.dyn_fric:b.friction=i.stat_fric,b.jnAcc*=r,b.jtAcc*=r}m!=d.active&&(i.contacts.modified=!0),u=f,h=x,x=x.next,f=f.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let d=i.c1;i.c1=i.c2,i.c2=d;let b=i.oc1;i.oc1=i.oc2,i.oc2=b,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(a=!0)}else i.hpc2=!1;if(i.jrAcc*=r,a||(i.rn1a=i.ny*i.c1.r1x-i.nx*i.c1.r1y,i.rt1a=i.c1.r1x*i.nx+i.c1.r1y*i.ny,i.rn1b=i.ny*i.c1.r2x-i.nx*i.c1.r2y,i.rt1b=i.c1.r2x*i.nx+i.c1.r2y*i.ny,i.k1x=i.b2.kinvelx-i.c1.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c1.r1y*i.b1.kinangvel),i.k1y=i.b2.kinvely+i.c1.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c1.r1x*i.b1.kinangvel)),i.hc2)if(i.rn2a=i.ny*i.c2.r1x-i.nx*i.c2.r1y,i.rt2a=i.c2.r1x*i.nx+i.c2.r1y*i.ny,i.rn2b=i.ny*i.c2.r2x-i.nx*i.c2.r2y,i.rt2b=i.c2.r2x*i.nx+i.c2.r2y*i.ny,i.k2x=i.b2.kinvelx-i.c2.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c2.r1y*i.b1.kinangvel),i.k2y=i.b2.kinvely+i.c2.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c2.r1x*i.b1.kinangvel),i.kMassa=o+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=o+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=o+i.b1.sinertia*i.rn2a*i.rn2a+i.b2.sinertia*i.rn2b*i.rn2b,i.kMassa*i.kMassa+2*i.kMassb*i.kMassb+i.kMassc*i.kMassc<I._nape.Config.illConditionedThreshold*(i.kMassa*i.kMassc-i.kMassb*i.kMassb)){i.Ka=i.kMassa,i.Kb=i.kMassb,i.Kc=i.kMassc;let b=i.kMassa*i.kMassc-i.kMassb*i.kMassb;if(b!=b)i.kMassa=i.kMassb=i.kMassc=0;else if(b==0){let m=0;i.kMassa!=0?i.kMassa=1/i.kMassa:(i.kMassa=0,m|=1),i.kMassc!=0?i.kMassc=1/i.kMassc:(i.kMassc=0,m|=2),i.kMassb=0}else{b=1/b;let m=i.kMassc*b;i.kMassc=i.kMassa*b,i.kMassa=m,i.kMassb*=-b}}else{if(i.hc2=!1,i.oc2.dist<i.oc1.dist){let b=i.c1;i.c1=i.c2,i.c2=b}i.oc2.active=!1,i.contacts.modified=!0}i.surfacex=i.b2.svelx,i.surfacey=i.b2.svely;let _=1;i.surfacex+=i.b1.svelx*_,i.surfacey+=i.b1.svely*_,i.surfacex=-i.surfacex,i.surfacey=-i.surfacey,i.rMass=i.b1.sinertia+i.b2.sinertia,i.rMass!=0&&(i.rMass=1/i.rMass),a&&(e.active=!1)}else{let i=e.fluidarb;i.pre_dt==-1&&(i.pre_dt=t);let r=t/i.pre_dt;i.pre_dt=t,i.r1x=i.centroidx-i.b1.posx,i.r1y=i.centroidy-i.b1.posy,i.r2x=i.centroidx-i.b2.posx,i.r2y=i.centroidy-i.b2.posy;let o=0,a=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(o=i.ws1.fluidProperties.gravityx,a=i.ws1.fluidProperties.gravityy):(o=this.gravityx,a=this.gravityy);let p=0,c=0;i.ws2.fluidEnabled&&i.ws2.fluidProperties.wrap_gravity!=null?(p=i.ws2.fluidProperties.gravityx,c=i.ws2.fluidProperties.gravityy):(p=this.gravityx,c=this.gravityy);let u=0,h=0;if(i.ws1.fluidEnabled&&i.ws2.fluidEnabled){let _=i.overlap*i.ws1.fluidProperties.density,d=i.overlap*i.ws2.fluidProperties.density;if(_>d){let b=_+d;u-=o*b,h-=a*b}else if(_<d){let b=_+d;u+=p*b,h+=c*b}else{let b=0,m=0;b=o+p,m=a+c;let z=.5;if(b*=z,m*=z,i.ws1.worldCOMx*b+i.ws1.worldCOMy*m>i.ws2.worldCOMx*b+i.ws2.worldCOMy*m){let M=_+d;u-=b*M,h-=m*M}else{let M=_+d;u+=b*M,h+=m*M}}}else if(i.ws1.fluidEnabled){let d=i.overlap*i.ws1.fluidProperties.density;u-=o*d,h-=a*d}else if(i.ws2.fluidEnabled){let d=i.overlap*i.ws2.fluidProperties.density;u+=p*d,h+=c*d}let x=t;if(u*=x,h*=x,i.buoyx=u,i.buoyy=h,i.b1.type==2){let _=i.b1.imass;i.b1.velx-=u*_,i.b1.vely-=h*_,i.b1.angvel-=(h*i.r1x-u*i.r1y)*i.b1.iinertia}if(i.b2.type==2){let _=i.b2.imass;i.b2.velx+=u*_,i.b2.vely+=h*_,i.b2.angvel+=(h*i.r2x-u*i.r2y)*i.b2.iinertia}if((!i.ws1.fluidEnabled||i.ws1.fluidProperties.viscosity==0)&&(!i.ws2.fluidEnabled||i.ws2.fluidProperties.viscosity==0))i.nodrag=!0,i.dampx=0,i.dampy=0,i.adamp=0;else{i.nodrag=!1;let _=0;if(i.ws1.fluidEnabled&&(i.ws2.validate_angDrag(),_+=i.ws1.fluidProperties.viscosity*i.ws2.angDrag*i.overlap/i.ws2.area),i.ws2.fluidEnabled&&(i.ws1.validate_angDrag(),_+=i.ws2.fluidProperties.viscosity*i.ws1.angDrag*i.overlap/i.ws1.area),_!=0){let z=i.b1.sinertia+i.b2.sinertia;z!=0?i.wMass=1/z:i.wMass=0,_*=4e-4;let M=2*Math.PI*_;i.agamma=1/(t*M*(2+M*t));let y=1/(1+i.agamma),w=t*M*M*i.agamma;i.agamma*=y,i.wMass*=y}else i.wMass=0,i.agamma=0;let d=i.b2.velx+i.b2.kinvelx-i.r2y*(i.b2.angvel+i.b2.kinangvel)-(i.b1.velx+i.b1.kinvelx-i.r1y*(i.b2.angvel+i.b2.kinangvel)),b=i.b2.vely+i.b2.kinvely+i.r2x*(i.b2.angvel+i.b2.kinangvel)-(i.b1.vely+i.b1.kinvely+i.r1x*(i.b1.angvel+i.b1.kinangvel));if(!(d*d+b*b<I._nape.Config.epsilon*I._nape.Config.epsilon)){let z=d*d+b*b,y=1/Math.sqrt(z);d*=y,b*=y,i.nx=d,i.ny=b}let m=0;if(i.ws1.fluidEnabled){let z=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)m-=z*i.ws2.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else{let M=i.ws2.polygon,y=0,w=0,v=M.edges.head;for(;v!=null;){let P=v.elt;y+=P.length;let g=z*P.length*(P.gnormx*i.nx+P.gnormy*i.ny);g>0&&(g*=-I._nape.Config.fluidVacuumDrag,g=g),w-=g*.5*I._nape.Config.fluidLinearDrag,v=v.next}m+=w/y}}if(i.ws2.fluidEnabled){let z=-i.ws2.fluidProperties.viscosity*i.overlap/i.ws1.area;if(i.ws1.type==0)m-=z*i.ws1.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else{let M=i.ws1.polygon,y=0,w=0,v=M.edges.head;for(;v!=null;){let P=v.elt;y+=P.length;let g=z*P.length*(P.gnormx*i.nx+P.gnormy*i.ny);g>0&&(g*=-I._nape.Config.fluidVacuumDrag,g=g),w-=g*.5*I._nape.Config.fluidLinearDrag,v=v.next}m+=w/y}}if(m!=0){let z=i.b1.smass+i.b2.smass,M=0,y=0,w=0;if(M=z,y=0,w=z,i.b1.sinertia!=0){let k=i.r1x*i.b1.sinertia,Z=i.r1y*i.b1.sinertia;M+=Z*i.r1y,y+=-Z*i.r1x,w+=k*i.r1x}if(i.b2.sinertia!=0){let k=i.r2x*i.b2.sinertia,Z=i.r2y*i.b2.sinertia;M+=Z*i.r2y,y+=-Z*i.r2x,w+=k*i.r2x}let v=M*w-y*y;if(v!=v)w=0,y=w,M=y;else if(v==0){let k=0;M!=0?M=1/M:(M=0,k|=1),w!=0?w=1/w:(w=0,k|=2),y=0}else{v=1/v;let k=w*v;w=M*v,M=k,y*=-v}i.vMassa=M,i.vMassb=y,i.vMassc=w;let P,g=2*Math.PI*m;i.lgamma=1/(t*g*(2+g*t));let E=1/(1+i.lgamma);P=t*g*g*i.lgamma,i.lgamma*=E;let N=E;i.vMassa*=N,i.vMassb*=N,i.vMassc*=N}else i.vMassa=0,i.vMassb=0,i.vMassc=0,i.lgamma=0}let f=r;i.dampx*=f,i.dampy*=f,i.adamp*=r}}else if(e.colarb!=null){let i=e.colarb,r=!0,o=null,a=null,p=i.innards.next;i.hc2=!1;let c=i.contacts.next;for(;c!=null;){let u=c;if(u.stamp+I._nape.Config.arbiterExpirationDelay<i.stamp){let f=i.contacts,_,d;o==null?(_=f.next,d=_.next,f.next=d,f.next==null&&(f.pushmod=!0)):(_=o.next,d=_.next,o.next=d,d==null&&(f.pushmod=!0)),_._inuse=!1,f.modified=!0,f.length--,f.pushmod=!0,c=d;let b=i.innards,m,z;a==null?(m=b.next,z=m.next,b.next=z,b.next==null&&(b.pushmod=!0)):(m=a.next,z=m.next,a.next=z,z==null&&(b.pushmod=!0)),m._inuse=!1,b.modified=!0,b.length--,b.pushmod=!0,p=z;let M=u;M.arbiter=null,M.next=we.zpp_pool,we.zpp_pool=M;continue}let h=u.inner,x=u.active;u.active=u.stamp==i.stamp,u.active&&(r?(r=!1,i.c1=h,i.oc1=u):(i.hc2=!0,i.c2=h,i.oc2=u)),x!=u.active&&(i.contacts.modified=!0),o=c,a=p,p=p.next,c=c.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let u=i.c1;i.c1=i.c2,i.c2=u;let h=i.oc1;i.oc1=i.oc2,i.oc2=h,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(r=!0)}else i.hpc2=!1;r&&(e.active=!1)}return s!=e.active&&(e.b1.arbiters.modified=!0,e.b2.arbiters.modified=!0,this.c_arbiters_true.modified=this.c_arbiters_false.modified=!0,this.s_arbiters.modified=this.f_arbiters.modified=!0),!1}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let _=n.elt;if(_.preStep(e)){n=this.live_constraints.erase(t),_.broken(),this.constraintCbBreak(_),_.removeOnBreak?(_.component.sleeping=!0,this.midstep=!1,_.compound!=null?_.compound.wrap_constraints.remove(_.outer):this.wrap_constraints.remove(_.outer),this.midstep=!0):_.active=!1,_.clearcache();continue}t=n,n=n.next}let l=null,s=this.c_arbiters_true,i=s.head,r=this.c_arbiters_false!=null;for(r&&i==null&&(r=!1,i=this.c_arbiters_false.head,s=this.c_arbiters_false,l=null);i!=null;){let _=i.elt;if(this.presteparb(_,e)){let d,b;l==null?(d=s.head,b=d.next,s.head=b,s.head==null&&(s.pushmod=!0)):(d=l.next,b=d.next,l.next=b,b==null&&(s.pushmod=!0));let m=d;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=m,s.modified=!0,s.length--,s.pushmod=!0,i=b,r&&i==null&&(r=!1,i=this.c_arbiters_false.head,s=this.c_arbiters_false,l=null);continue}l=i,i=i.next,r&&i==null&&(r=!1,i=this.c_arbiters_false.head,s=this.c_arbiters_false,l=null)}let o=null,a=this.f_arbiters,p=a.head,c=!1;for(c&&p==null&&(c=!1,a=null,o=null);p!=null;){let _=p.elt;if(this.presteparb(_,e)){let d,b;o==null?(d=a.head,b=d.next,a.head=b,a.head==null&&(a.pushmod=!0)):(d=o.next,b=d.next,o.next=b,b==null&&(a.pushmod=!0));let m=d;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=m,a.modified=!0,a.length--,a.pushmod=!0,p=b,c&&p==null&&(c=!1,a=null,o=null);continue}o=p,p=p.next,c&&p==null&&(c=!1,a=null,o=null)}let u=null,h=this.s_arbiters,x=h.head,f=!1;for(f&&x==null&&(f=!1,h=null,u=null);x!=null;){let _=x.elt;if(this.presteparb(_,e)){let d,b;u==null?(d=h.head,b=d.next,h.head=b,h.head==null&&(h.pushmod=!0)):(d=u.next,b=d.next,u.next=b,b==null&&(h.pushmod=!0));let m=d;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=m,h.modified=!0,h.length--,h.pushmod=!0,x=b,f&&x==null&&(f=!1,h=null,u=null);continue}u=x,x=x.next,f&&x==null&&(f=!1,h=null,u=null)}}warmStart(){let e=this.f_arbiters.head;for(;e!=null;){let s=e.elt;if(s.active&&(s.immState&1)!=0){let i=s.b1.imass;s.b1.velx-=s.dampx*i,s.b1.vely-=s.dampy*i;let r=s.b2.imass;s.b2.velx+=s.dampx*r,s.b2.vely+=s.dampy*r,s.b1.angvel-=s.b1.iinertia*(s.dampy*s.r1x-s.dampx*s.r1y),s.b2.angvel+=s.b2.iinertia*(s.dampy*s.r2x-s.dampx*s.r2y),s.b1.angvel-=s.adamp*s.b1.iinertia,s.b2.angvel+=s.adamp*s.b2.iinertia}e=e.next}let t=this.c_arbiters_false.head,n=!0;for(t==null&&(t=this.c_arbiters_true.head,n=!1);t!=null;){let s=t.elt;if(s.active&&(s.immState&1)!=0){let i=s.nx*s.c1.jnAcc-s.ny*s.c1.jtAcc,r=s.ny*s.c1.jnAcc+s.nx*s.c1.jtAcc,o=s.b1.imass;s.b1.velx-=i*o,s.b1.vely-=r*o,s.b1.angvel-=s.b1.iinertia*(r*s.c1.r1x-i*s.c1.r1y);let a=s.b2.imass;if(s.b2.velx+=i*a,s.b2.vely+=r*a,s.b2.angvel+=s.b2.iinertia*(r*s.c1.r2x-i*s.c1.r2y),s.hc2){let p=s.nx*s.c2.jnAcc-s.ny*s.c2.jtAcc,c=s.ny*s.c2.jnAcc+s.nx*s.c2.jtAcc,u=s.b1.imass;s.b1.velx-=p*u,s.b1.vely-=c*u,s.b1.angvel-=s.b1.iinertia*(c*s.c2.r1x-p*s.c2.r1y);let h=s.b2.imass;s.b2.velx+=p*h,s.b2.vely+=c*h,s.b2.angvel+=s.b2.iinertia*(c*s.c2.r2x-p*s.c2.r2y)}s.b2.angvel+=s.jrAcc*s.b2.iinertia,s.b1.angvel-=s.jrAcc*s.b1.iinertia}t=t.next,n&&t==null&&(t=this.c_arbiters_true.head,n=!1)}let l=this.live_constraints.head;for(;l!=null;)l.elt.warmStart(),l=l.next}iterateVel(e){let t=0,n=e;for(;t<n;){let l=t++,s=this.f_arbiters.head;for(;s!=null;){let p=s.elt;if(p.active&&(p.immState&1)!=0&&!p.nodrag){let c=p.b1.angvel+p.b1.kinangvel,u=p.b2.angvel+p.b2.kinangvel,h=p.b1.velx+p.b1.kinvelx-p.r1y*c-(p.b2.velx+p.b2.kinvelx-p.r2y*u),x=p.b1.vely+p.b1.kinvely+p.r1x*c-(p.b2.vely+p.b2.kinvely+p.r2x*u),f=p.vMassa*h+p.vMassb*x;x=p.vMassb*h+p.vMassc*x,h=f;let _=p.lgamma;h-=p.dampx*_,x-=p.dampy*_;let d=1;p.dampx+=h*d,p.dampy+=x*d;let b=p.b1.imass;p.b1.velx-=h*b,p.b1.vely-=x*b;let m=p.b2.imass;p.b2.velx+=h*m,p.b2.vely+=x*m,p.b1.angvel-=p.b1.iinertia*(x*p.r1x-h*p.r1y),p.b2.angvel+=p.b2.iinertia*(x*p.r2x-h*p.r2y);let z=(c-u)*p.wMass-p.adamp*p.agamma;p.adamp+=z,p.b1.angvel-=z*p.b1.iinertia,p.b2.angvel+=z*p.b2.iinertia}s=s.next}let i=null,r=this.live_constraints.head;for(;r!=null;){let p=r.elt;if(p.applyImpulseVel()){r=this.live_constraints.erase(i),p.broken(),this.constraintCbBreak(p),p.removeOnBreak?(p.component.sleeping=!0,this.midstep=!1,p.compound!=null?p.compound.wrap_constraints.remove(p.outer):this.wrap_constraints.remove(p.outer),this.midstep=!0):p.active=!1,p.clearcache();continue}i=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),u=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),h=(u*p.nx-c*p.ny+p.surfacex)*p.c1.tMass,x=p.c1.friction*p.c1.jnAcc,f=p.c1.jtAcc,_=f-h;_>x?_=x:_<-x&&(_=-x),h=_-f,p.c1.jtAcc=_;let d=-p.ny*h,b=p.nx*h;if(p.b2.velx+=d*p.b2.imass,p.b2.vely+=b*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=b*p.b1.imass,p.b2.angvel+=p.rt1b*h*p.b2.iinertia,p.b1.angvel-=p.rt1a*h*p.b1.iinertia,p.hc2){let m=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),z=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);h=(z*p.nx-m*p.ny+p.surfacex)*p.c2.tMass,x=p.c2.friction*p.c2.jnAcc,f=p.c2.jtAcc,_=f-h,_>x?_=x:_<-x&&(_=-x),h=_-f,p.c2.jtAcc=_,d=-p.ny*h,b=p.nx*h,p.b2.velx+=d*p.b2.imass,p.b2.vely+=b*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=b*p.b1.imass,p.b2.angvel+=p.rt2b*h*p.b2.iinertia,p.b1.angvel-=p.rt2a*h*p.b1.iinertia,c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),u=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),m=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),z=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);let M=p.c1.jnAcc,y=p.c2.jnAcc,w=c*p.nx+u*p.ny+p.surfacey+p.c1.bounce-(p.Ka*M+p.Kb*y),v=m*p.nx+z*p.ny+p.surfacey+p.c2.bounce-(p.Kb*M+p.Kc*y),P=-(p.kMassa*w+p.kMassb*v),g=-(p.kMassb*w+p.kMassc*v);P>=0&&g>=0?(w=P-M,v=g-y,p.c1.jnAcc=P,p.c2.jnAcc=g):(P=-p.c1.nMass*w,P>=0&&p.Kb*P+v>=0?(w=P-M,v=-y,p.c1.jnAcc=P,p.c2.jnAcc=0):(g=-p.c2.nMass*v,g>=0&&p.Kb*g+w>=0?(w=-M,v=g-y,p.c1.jnAcc=0,p.c2.jnAcc=g):w>=0&&v>=0?(w=-M,v=-y,p.c1.jnAcc=p.c2.jnAcc=0):(w=0,v=0))),h=w+v,d=p.nx*h,b=p.ny*h,p.b2.velx+=d*p.b2.imass,p.b2.vely+=b*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=b*p.b1.imass,p.b2.angvel+=(p.rn1b*w+p.rn2b*v)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*w+p.rn2a*v)*p.b1.iinertia}else p.radius!=0&&(h=(p.b2.angvel-p.b1.angvel)*p.rMass,x=p.rfric*p.c1.jnAcc,f=p.jrAcc,p.jrAcc-=h,p.jrAcc>x?p.jrAcc=x:p.jrAcc<-x&&(p.jrAcc=-x),h=p.jrAcc-f,p.b2.angvel+=h*p.b2.iinertia,p.b1.angvel-=h*p.b1.iinertia),c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),u=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),h=(p.c1.bounce+(p.nx*c+p.ny*u)+p.surfacey)*p.c1.nMass,f=p.c1.jnAcc,_=f-h,_<0&&(_=0),h=_-f,p.c1.jnAcc=_,d=p.nx*h,b=p.ny*h,p.b2.velx+=d*p.b2.imass,p.b2.vely+=b*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=b*p.b1.imass,p.b2.angvel+=p.rn1b*h*p.b2.iinertia,p.b1.angvel-=p.rn1a*h*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 l=t++,s=null,i=this.live_constraints.head;for(;i!=null;){let a=i.elt;if(!a.__velocity&&a.stiff&&a.applyImpulsePos()){i=this.live_constraints.erase(s),a.broken(),this.constraintCbBreak(a),a.removeOnBreak?(a.component.sleeping=!0,this.midstep=!1,a.compound!=null?a.compound.wrap_constraints.remove(a.outer):this.wrap_constraints.remove(a.outer),this.midstep=!0):a.active=!1,a.clearcache();continue}s=i,i=i.next}let 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,u=0;c=a.b2.axisy*p.lr2x-a.b2.axisx*p.lr2y,u=p.lr2x*a.b2.axisx+p.lr2y*a.b2.axisy;let h=1;c+=a.b2.posx*h,u+=a.b2.posy*h;let x=0,f=0;x=a.b1.axisy*p.lr1x-a.b1.axisx*p.lr1y,f=p.lr1x*a.b1.axisx+p.lr1y*a.b1.axisy;let _=1;x+=a.b1.posx*_,f+=a.b1.posy*_;let d=0,b=0;d=c-x,b=u-f;let m=Math.sqrt(d*d+b*b),z=a.radius-I._nape.Config.collisionSlop,M=m-z;if(d*a.nx+b*a.ny<0&&(d=-d,b=-b,M-=a.radius),M<0)if(m<I._nape.Config.epsilon)a.b1.smass!=0?a.b1.posx+=I._nape.Config.epsilon*10:a.b2.posx+=I._nape.Config.epsilon*10;else{let y=1/m;d*=y,b*=y;let w=.5*(x+c),v=.5*(f+u),P=m-z;x=w-a.b1.posx,f=v-a.b1.posy,c=w-a.b2.posx,u=v-a.b2.posy;let g=b*x-d*f,E=b*c-d*u,N=a.b2.smass+E*E*a.b2.sinertia+a.b1.smass+g*g*a.b1.sinertia;if(N!=0){let k=-a.biasCoef*P/N,Z=0,C=0,F=k;Z=d*F,C=b*F;let O=a.b1.imass;a.b1.posx-=Z*O,a.b1.posy-=C*O;let B=a.b1,D=-g*a.b1.iinertia*k;if(B.rot+=D,D*D>1e-4)B.axisx=Math.sin(B.rot),B.axisy=Math.cos(B.rot);else{let L=D*D,A=1-.5*L,J=1-L*L/8,$=(A*B.axisx+D*B.axisy)*J;B.axisy=(A*B.axisy-D*B.axisx)*J,B.axisx=$}let U=a.b2.imass;a.b2.posx+=Z*U,a.b2.posy+=C*U;let W=a.b2,q=E*a.b2.iinertia*k;if(W.rot+=q,q*q>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let L=q*q,A=1-.5*L,J=1-L*L/8,$=(A*W.axisx+q*W.axisy)*J;W.axisy=(A*W.axisy-q*W.axisx)*J,W.axisx=$}}}}else{let p=0,c=0,u,h=0,x=0,f=0,_=0;if(a.ptype==0){p=a.b1.axisy*a.lnormx-a.b1.axisx*a.lnormy,c=a.lnormx*a.b1.axisx+a.lnormy*a.b1.axisy,u=a.lproj+(p*a.b1.posx+c*a.b1.posy),h=a.b2.axisy*a.c1.lr1x-a.b2.axisx*a.c1.lr1y,x=a.c1.lr1x*a.b2.axisx+a.c1.lr1y*a.b2.axisy;let m=1;if(h+=a.b2.posx*m,x+=a.b2.posy*m,a.hpc2){f=a.b2.axisy*a.c2.lr1x-a.b2.axisx*a.c2.lr1y,_=a.c2.lr1x*a.b2.axisx+a.c2.lr1y*a.b2.axisy;let z=1;f+=a.b2.posx*z,_+=a.b2.posy*z}}else{p=a.b2.axisy*a.lnormx-a.b2.axisx*a.lnormy,c=a.lnormx*a.b2.axisx+a.lnormy*a.b2.axisy,u=a.lproj+(p*a.b2.posx+c*a.b2.posy),h=a.b1.axisy*a.c1.lr1x-a.b1.axisx*a.c1.lr1y,x=a.c1.lr1x*a.b1.axisx+a.c1.lr1y*a.b1.axisy;let m=1;if(h+=a.b1.posx*m,x+=a.b1.posy*m,a.hpc2){f=a.b1.axisy*a.c2.lr1x-a.b1.axisx*a.c2.lr1y,_=a.c2.lr1x*a.b1.axisx+a.c2.lr1y*a.b1.axisy;let z=1;f+=a.b1.posx*z,_+=a.b1.posy*z}}let d=h*p+x*c-u-a.radius;d+=I._nape.Config.collisionSlop;let b=0;if(a.hpc2&&(b=f*p+_*c-u-a.radius,b+=I._nape.Config.collisionSlop),d<0||b<0){a.rev&&(p=-p,c=-c);let m=0,z=0;m=h-a.b1.posx,z=x-a.b1.posy;let M=0,y=0;M=h-a.b2.posx,y=x-a.b2.posy;let w=0,v=0,P=0,g=0;if(a.hpc2){w=f-a.b1.posx,v=_-a.b1.posy,P=f-a.b2.posx,g=_-a.b2.posy;let E=c*m-p*z,N=c*M-p*y,k=c*w-p*v,Z=c*P-p*g,C=a.b1.smass+a.b2.smass;a.kMassa=C+a.b1.sinertia*E*E+a.b2.sinertia*N*N,a.kMassb=C+a.b1.sinertia*E*k+a.b2.sinertia*N*Z,a.kMassc=C+a.b1.sinertia*k*k+a.b2.sinertia*Z*Z;let F=0,O=0,B=0;F=a.kMassa,O=a.kMassb,B=a.kMassc;let D=d*a.biasCoef,U=b*a.biasCoef;for(;;){let W=0,q=0;W=D,q=U,W=-W,q=-q;let L=a.kMassa*a.kMassc-a.kMassb*a.kMassb;if(L!=L)q=0,W=q;else if(L==0)a.kMassa!=0?W/=a.kMassa:W=0,a.kMassc!=0?q/=a.kMassc:q=0;else{L=1/L;let $=L*(a.kMassc*W-a.kMassb*q);q=L*(a.kMassa*q-a.kMassb*W),W=$}if(W>=0&&q>=0){let $=(W+q)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let X=a.b1,H=-a.b1.iinertia*(E*W+k*q);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let j=H*H,V=1-.5*j,K=1-j*j/8,Q=(V*X.axisx+H*X.axisy)*K;X.axisy=(V*X.axisy-H*X.axisx)*K,X.axisx=Q}let ee=(W+q)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let G=a.b2,R=a.b2.iinertia*(N*W+Z*q);if(G.rot+=R,R*R>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else{let j=R*R,V=1-.5*j,K=1-j*j/8,Q=(V*G.axisx+R*G.axisy)*K;G.axisy=(V*G.axisy-R*G.axisx)*K,G.axisx=Q}break}W=-D/F,q=0;let A=O*W+U;if(W>=0&&A>=0){let $=(W+q)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let X=a.b1,H=-a.b1.iinertia*(E*W+k*q);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let j=H*H,V=1-.5*j,K=1-j*j/8,Q=(V*X.axisx+H*X.axisy)*K;X.axisy=(V*X.axisy-H*X.axisx)*K,X.axisx=Q}let ee=(W+q)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let G=a.b2,R=a.b2.iinertia*(N*W+Z*q);if(G.rot+=R,R*R>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else{let j=R*R,V=1-.5*j,K=1-j*j/8,Q=(V*G.axisx+R*G.axisy)*K;G.axisy=(V*G.axisy-R*G.axisx)*K,G.axisx=Q}break}W=0,q=-U/B;let J=O*q+D;if(q>=0&&J>=0){let $=(W+q)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let X=a.b1,H=-a.b1.iinertia*(E*W+k*q);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let j=H*H,V=1-.5*j,K=1-j*j/8,Q=(V*X.axisx+H*X.axisy)*K;X.axisy=(V*X.axisy-H*X.axisx)*K,X.axisx=Q}let ee=(W+q)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let G=a.b2,R=a.b2.iinertia*(N*W+Z*q);if(G.rot+=R,R*R>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else{let j=R*R,V=1-.5*j,K=1-j*j/8,Q=(V*G.axisx+R*G.axisy)*K;G.axisy=(V*G.axisy-R*G.axisx)*K,G.axisx=Q}break}break}}else{let E=c*m-p*z,N=c*M-p*y,k=a.b2.smass+N*N*a.b2.sinertia+a.b1.smass+E*E*a.b1.sinertia;if(k!=0){let Z=-a.biasCoef*d/k,C=0,F=0,O=Z;C=p*O,F=c*O;let B=a.b1.imass;a.b1.posx-=C*B,a.b1.posy-=F*B;let D=a.b1,U=-E*a.b1.iinertia*Z;if(D.rot+=U,U*U>1e-4)D.axisx=Math.sin(D.rot),D.axisy=Math.cos(D.rot);else{let A=U*U,J=1-.5*A,$=1-A*A/8,X=(J*D.axisx+U*D.axisy)*$;D.axisy=(J*D.axisy-U*D.axisx)*$,D.axisx=X}let W=a.b2.imass;a.b2.posx+=C*W,a.b2.posy+=F*W;let q=a.b2,L=N*a.b2.iinertia*Z;if(q.rot+=L,L*L>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else{let A=L*L,J=1-.5*A,$=1-A*A/8,X=(J*q.axisx+L*q.axisy)*$;q.axisy=(J*q.axisy-L*q.axisx)*$,q.axisx=X}}}}}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 l=n==null?null:n.group;if(l==null)return!1;{let s=t;for(;s!=null&&s.group==null;)s.ishape!=null?s=s.ishape.body:s.icompound!=null?s=s.icompound.compound:s=s.ibody.compound;let i=s==null?null:s.group;if(i==null)return!1;{let r=!1;for(;l!=null&&i!=null;){if(l==i){r=l.ignore;break}l.depth<i.depth?i=i.group:l=l.group}return r}}}interactionType(e,t,n,l){let s;s=!1;let i=n.constraints.head;for(;i!=null;){let o=i.elt;if(o.ignore&&o.pair_exists(n.id,l.id)){s=!0;break}i=i.next}let r;if(s)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 u=c==null?null:c.group;if(u==null)p=!1;else{let h=!1;for(;a!=null&&u!=null;){if(a==u){h=a.ignore;break}a.depth<u.depth?u=u.group:a=a.group}p=h}}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&&l.imass==0&&n.iinertia==0&&l.iinertia==0))return 0;{let p=e.filter,c=t.filter;return(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!(n.imass==0&&l.imass==0&&n.iinertia==0&&l.iinertia==0)?1:-1}}}else return-1}narrowPhase(e,t,n,l,s){let i=this,r=null,o=e.body,a=t.body,p;p=!1;let c=o.constraints.head;for(;c!=null;){let x=c.elt;if(x.ignore&&x.pair_exists(o.id,a.id)){p=!0;break}c=c.next}let u,h;if(p)h=!1;else{let x=e;for(;x!=null&&x.group==null;)x.ishape!=null?x=x.ishape.body:x.icompound!=null?x=x.icompound.compound:x=x.ibody.compound;let f=x==null?null:x.group,_;if(f==null)_=!1;else{let d=t;for(;d!=null&&d.group==null;)d.ishape!=null?d=d.ishape.body:d.icompound!=null?d=d.icompound.compound:d=d.ibody.compound;let b=d==null?null:d.group;if(b==null)_=!1;else{let m=!1;for(;f!=null&&b!=null;){if(f==b){m=f.ignore;break}f.depth<b.depth?b=b.group:f=f.group}_=m}}h=!_}if(h){let x;if(e.sensorEnabled||t.sensorEnabled){let f=e.filter,_=t.filter;x=(f.sensorMask&_.sensorGroup)!=0&&(_.sensorMask&f.sensorGroup)!=0}else x=!1;if(x)u=2;else{let f;if(e.fluidEnabled||t.fluidEnabled){let _=e.filter,d=t.filter;f=(_.fluidMask&d.fluidGroup)!=0&&(d.fluidMask&_.fluidGroup)!=0}else f=!1;if(f&&!(o.imass==0&&a.imass==0&&o.iinertia==0&&a.iinertia==0))u=0;else{let _=e.filter,d=t.filter;u=(_.collisionMask&d.collisionGroup)!=0&&(d.collisionMask&_.collisionGroup)!=0&&!(o.imass==0&&a.imass==0&&o.iinertia==0&&a.iinertia==0)?1:-1}}}else u=-1;if(u!=-1){let x,f;e.type>t.type?(x=t,f=e):e.type==t.type?e.id<t.id?(x=e,f=t):(f=e,x=t):(x=e,f=t);let _=x==t;if(u==0){let d;if(l==null){let y=null,v=(o.arbiters.length<a.arbiters.length?o:a).arbiters.head;for(;v!=null;){let P=v.elt;if(P.id==x.id&&P.di==f.id){y=P;break}v=v.next}d=y}else d=l;let b=d==null,m,z=!1;if(b)Bt.zpp_pool==null?m=new Bt:(m=Bt.zpp_pool,Bt.zpp_pool=m.next,m.next=null);else if(d.fluidarb==null){d.cleared=!0;{let w=d.b1.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let E,N;v==null?(E=w.head,N=E.next,w.head=N,w.head==null&&(w.pushmod=!0)):(E=v.next,N=E.next,v.next=N,N==null&&(w.pushmod=!0));let k=E;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}{let w=d.b2.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let E,N;v==null?(E=w.head,N=E.next,w.head=N,w.head==null&&(w.pushmod=!0)):(E=v.next,N=E.next,v.next=N,N==null&&(w.pushmod=!0));let k=E;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Bt.zpp_pool==null?m=new Bt:(m=Bt.zpp_pool,Bt.zpp_pool=m.next,m.next=null),m.intchange=!0,b=!0,z=!0}else m=d.fluidarb;let M=4;if(b||m.stamp!=this.stamp||s)if(m.stamp=this.stamp,Ne.flowCollide(x,f,m)){if(b){let y=f.id;m.b1=e.body,m.ws1=e,m.b2=t.body,m.ws2=t,m.id=x.id,m.di=y;let w=m.b1.arbiters,v;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?v=new I._zpp.util.ZNPNode_ZPP_Arbiter:(v=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=v.next,v.next=null),v.elt=m;let P=v;P.next=w.head,w.head=P,w.modified=!0,w.length++;let g=m.b2.arbiters,E;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?E=new I._zpp.util.ZNPNode_ZPP_Arbiter:(E=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E.next,E.next=null),E.elt=m;let N=E;N.next=g.head,g.head=N,g.modified=!0,g.length++,m.active=!0,m.present=0,m.cleared=!1,m.sleeping=!1,m.fresh=!1,m.presentable=!1,m.nx=0,m.ny=1,m.dampx=0,m.dampy=0,m.adamp=0;let k=this.f_arbiters,Z;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?Z=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(Z=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=Z.next,Z.next=null),Z.elt=m;let C=Z;C.next=k.head,k.head=C,k.modified=!0,k.length++,m.fresh=!z}else m.fresh=m.up_stamp<this.stamp-1||m.endGenerated==this.stamp&&s;if(m.up_stamp=m.stamp,m.fresh||(m.immState&4)==0){m.immState=1;let y=!1,w=m.ws1.id>m.ws2.id?m.ws2:m.ws1,v=m.ws1.id>m.ws2.id?m.ws1:m.ws2,P=this.mrca1;for(;P.head!=null;){let Z=P.head;P.head=Z.next;let C=Z;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}P.pushmod=!0;let g=this.mrca2;for(;g.head!=null;){let Z=g.head;g.head=Z.next;let C=Z;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}if(g.pushmod=!0,w.cbSet!=null){let Z=this.mrca1,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=w;let F=C;F.next=Z.head,Z.head=F,Z.modified=!0,Z.length++}if(w.body.cbSet!=null){let Z=this.mrca1,C=w.body,F;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?F=new I._zpp.util.ZNPNode_ZPP_Interactor:(F=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=F.next,F.next=null),F.elt=C;let O=F;O.next=Z.head,Z.head=O,Z.modified=!0,Z.length++}if(v.cbSet!=null){let Z=this.mrca2,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=v;let F=C;F.next=Z.head,Z.head=F,Z.modified=!0,Z.length++}if(v.body.cbSet!=null){let Z=this.mrca2,C=v.body,F;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?F=new I._zpp.util.ZNPNode_ZPP_Interactor:(F=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=F.next,F.next=null),F.elt=C;let O=F;O.next=Z.head,Z.head=O,Z.modified=!0,Z.length++}let E=w.body.compound,N=v.body.compound;for(;E!=N;){let Z=E==null?0:E.depth,C=N==null?0:N.depth;if(Z<C){if(N.cbSet!=null){let F=this.mrca2,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=N;let B=O;B.next=F.head,F.head=B,F.modified=!0,F.length++}N=N.compound}else{if(E.cbSet!=null){let F=this.mrca1,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=E;let B=O;B.next=F.head,F.head=B,F.modified=!0,F.length++}E=E.compound}}let k=this.mrca1.head;for(;k!=null;){let Z=k.elt,C=this.mrca2.head;for(;C!=null;){let F=C.elt,O=Z.cbSet,B=F.cbSet,D=O.manager,U=null,q=(O.cbpairs.length<B.cbpairs.length?O.cbpairs:B.cbpairs).head;for(;q!=null;){let j=q.elt;if(j.a==O&&j.b==B||j.a==B&&j.b==O){U=j;break}q=q.next}if(U==null){let j;Se.zpp_pool==null?j=new Se:(j=Se.zpp_pool,Se.zpp_pool=j.next,j.next=null),j.zip_listeners=!0,St.setlt(O,B)?(j.a=O,j.b=B):(j.a=B,j.b=O),U=j,O.cbpairs.add(U),B!=O&&B.cbpairs.add(U)}if(U.zip_listeners&&(U.zip_listeners=!1,U.__validate()),U.listeners.head==null){C=C.next;continue}let L=null,A=null,J=this.prelisteners;for(;J.head!=null;){let j=J.head;J.head=j.next;let V=j;V.elt=null,V.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=V,J.head==null&&(J.pushmod=!0),J.modified=!0,J.length--}J.pushmod=!0;let $=null,X=O.manager,H=null,G=(O.cbpairs.length<B.cbpairs.length?O.cbpairs:B.cbpairs).head;for(;G!=null;){let j=G.elt;if(j.a==O&&j.b==B||j.a==B&&j.b==O){H=j;break}G=G.next}if(H==null){let j;Se.zpp_pool==null?j=new Se:(j=Se.zpp_pool,Se.zpp_pool=j.next,j.next=null),j.zip_listeners=!0,St.setlt(O,B)?(j.a=O,j.b=B):(j.a=B,j.b=O),H=j,O.cbpairs.add(H),B!=O&&B.cbpairs.add(H)}H.zip_listeners&&(H.zip_listeners=!1,H.__validate());let R=H.listeners.head;for(;R!=null;){let j=R.elt;if(j.event==5&&(j.itype&M)!=0){let V=i.prelisteners,K;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?K=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(K=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=K.next,K.next=null),K.elt=j;let Q=K;$==null?(Q.next=V.head,V.head=Q):(Q.next=$.next,$.next=Q),V.pushmod=V.modified=!0,V.length++,$=Q,y=y||!j.pure}R=R.next}if(this.prelisteners.head==null){C=C.next;continue}if(L=I._zpp.phys.ZPP_Interactor.get(Z,F),L==null&&(A=xn.get(Z,F),this.add_callbackset(A)),L==null||(L.FLUIDstamp!=this.stamp||s)&&(L.FLUIDstate&4)==0){if(A!=null&&(L=A),L!=null){let Q=this.prelisteners.head;for(;Q!=null;)Q.elt.itype==7?(L.COLLISIONstamp=this.stamp,L.SENSORstamp=this.stamp,L.FLUIDstamp=this.stamp):L.FLUIDstamp=this.stamp,Q=Q.next}m.mutable=!0,m.wrap_position!=null&&(m.wrap_position.zpp_inner._immutable=!1);let j=m.active;m.active=!0;let V=!1;this.precb.zpp_inner.pre_arbiter=m,this.precb.zpp_inner.set=L;let K=this.prelisteners.head;for(;K!=null;){let Q=K.elt;this.precb.zpp_inner.listener=Q;let Y=this.precb.zpp_inner,ne=L.int1,ae=L.int2,le,se=Q.options1,re=ne.cbTypes;if(se.nonemptyintersection(re,se.includes)&&!se.nonemptyintersection(re,se.excludes)){let ce=Q.options2,pe=ae.cbTypes;le=ce.nonemptyintersection(pe,ce.includes)&&!ce.nonemptyintersection(pe,ce.excludes)}else le=!1;le?(Y.int1=ne,Y.int2=ae):(Y.int1=ae,Y.int2=ne),this.precb.zpp_inner.pre_swapped=Z!=this.precb.zpp_inner.int1;let he=Q.handlerp(this.precb);if(he!=null){let ce;T.PreFlag_ACCEPT==null&&(T.internal=!0,T.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,T.internal=!1),he==T.PreFlag_ACCEPT?ce=5:(T.PreFlag_ACCEPT_ONCE==null&&(T.internal=!0,T.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,T.internal=!1),he==T.PreFlag_ACCEPT_ONCE?ce=1:(T.PreFlag_IGNORE==null&&(T.internal=!0,T.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,T.internal=!1),ce=he==T.PreFlag_IGNORE?6:2)),m.immState=ce}K=K.next}if(m.mutable=!1,m.wrap_position!=null&&(m.wrap_position.zpp_inner._immutable=!0),m.active=j,L!=null){let Q=this.prelisteners.head;for(;Q!=null;)Q.elt.itype==7&&(L.COLLISIONstate=m.immState,L.SENSORstate=m.immState),L.FLUIDstate=m.immState,Q=Q.next}}else L==null?(m.immState&4)==0&&(m.immState=1):m.immState=L.FLUIDstate;C=C.next}k=k.next}if(y&&(m.immState&4)==0){if(m.b1.type==2){let Z=m.b1;Z.world||(Z.component.waket=this.stamp+(this.midstep?0:1),Z.type==3&&(Z.kinematicDelaySleep=!0),Z.component.sleeping&&this.really_wake(Z,!1))}if(m.b1.type==2){let Z=m.b2;Z.world||(Z.component.waket=this.stamp+(this.midstep?0:1),Z.type==3&&(Z.kinematicDelaySleep=!0),Z.component.sleeping&&this.really_wake(Z,!1))}}}if((m.immState&1)!=0){if(m.b1.type==2&&m.b1.component.sleeping){let y=m.b1;y.world||(y.component.waket=this.stamp+(this.midstep?0:1),y.type==3&&(y.kinematicDelaySleep=!0),y.component.sleeping&&this.really_wake(y,!1))}if(m.b2.type==2&&m.b2.component.sleeping){let y=m.b2;y.world||(y.component.waket=this.stamp+(this.midstep?0:1),y.type==3&&(y.kinematicDelaySleep=!0),y.component.sleeping&&this.really_wake(y,!1))}}if(m.sleeping){m.sleeping=!1;let y=this.f_arbiters,w;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?w=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(w=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=w.next,w.next=null),w.elt=m;let v=w;v.next=y.head,y.head=v,y.modified=!0,y.length++}r=m}else if(b){let y=m;y.next=Bt.zpp_pool,Bt.zpp_pool=y,r=null}else r=m;else r=m}else if(u==1){let d=n?this.c_arbiters_true:this.c_arbiters_false,b;if(l==null){let w=null,P=(o.arbiters.length<a.arbiters.length?o:a).arbiters.head;for(;P!=null;){let g=P.elt;if(g.id==x.id&&g.di==f.id){w=g;break}P=P.next}b=w}else b=l;let m=b==null,z,M=!1;if(m)gt.zpp_pool==null?z=new gt:(z=gt.zpp_pool,gt.zpp_pool=z.next,z.next=null),z.stat=n;else if(b.colarb==null){b.cleared=!0;{let v=b.b1.arbiters,P=null,g=v.head,E=!1;for(;g!=null;){if(g.elt==b){let N,k;P==null?(N=v.head,k=N.next,v.head=k,v.head==null&&(v.pushmod=!0)):(N=P.next,k=N.next,P.next=k,k==null&&(v.pushmod=!0));let Z=N;Z.elt=null,Z.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=Z,v.modified=!0,v.length--,v.pushmod=!0,E=!0;break}P=g,g=g.next}}{let v=b.b2.arbiters,P=null,g=v.head,E=!1;for(;g!=null;){if(g.elt==b){let N,k;P==null?(N=v.head,k=N.next,v.head=k,v.head==null&&(v.pushmod=!0)):(N=P.next,k=N.next,P.next=k,k==null&&(v.pushmod=!0));let Z=N;Z.elt=null,Z.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=Z,v.modified=!0,v.length--,v.pushmod=!0,E=!0;break}P=g,g=g.next}}b.pair!=null&&(b.pair.arb=null,b.pair=null),b.active=!1,this.f_arbiters.modified=!0,gt.zpp_pool==null?z=new gt:(z=gt.zpp_pool,gt.zpp_pool=z.next,z.next=null),z.intchange=!0,z.stat=n,m=!0,M=!0}else z=b.colarb,_=x!=z.s1,z.stat!=n&&(z.stat=n,z.sleeping||((n?this.c_arbiters_false:this.c_arbiters_true).remove(z),d.add(z)));let y=1;if(m||z.stamp!=this.stamp||s)if(z.stamp=this.stamp,Ne.contactCollide(x,f,z,_)){if(m){let w=f.id;z.b1=e.body,z.ws1=e,z.b2=t.body,z.ws2=t,z.id=x.id,z.di=w;let v=z.b1.arbiters,P;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?P=new I._zpp.util.ZNPNode_ZPP_Arbiter:(P=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=P.next,P.next=null),P.elt=z;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++;let E=z.b2.arbiters,N;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?N=new I._zpp.util.ZNPNode_ZPP_Arbiter:(N=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=N.next,N.next=null),N.elt=z;let k=N;k.next=E.head,E.head=k,E.modified=!0,E.length++,z.active=!0,z.present=0,z.cleared=!1,z.sleeping=!1,z.fresh=!1,z.presentable=!1,z.s1=e,z.s2=t,z.userdef_restitution||(z.s1.material.elasticity<=-1/0||z.s2.material.elasticity<=-1/0?z.restitution=0:z.s1.material.elasticity>=1/0||z.s2.material.elasticity>=1/0?z.restitution=1:z.restitution=(z.s1.material.elasticity+z.s2.material.elasticity)/2,z.restitution<0&&(z.restitution=0),z.restitution>1&&(z.restitution=1)),z.userdef_dyn_fric||(z.dyn_fric=Math.sqrt(z.s1.material.dynamicFriction*z.s2.material.dynamicFriction)),z.userdef_stat_fric||(z.stat_fric=Math.sqrt(z.s1.material.staticFriction*z.s2.material.staticFriction)),z.userdef_rfric||(z.rfric=Math.sqrt(z.s1.material.rollingFriction*z.s2.material.rollingFriction));let Z;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?Z=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(Z=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=Z.next,Z.next=null),Z.elt=z;let C=Z;C.next=d.head,d.head=C,d.modified=!0,d.length++,z.fresh=!M}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&s;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let w=!1,v=z.ws1.id>z.ws2.id?z.ws2:z.ws1,P=z.ws1.id>z.ws2.id?z.ws1:z.ws2,g=this.mrca1;for(;g.head!=null;){let C=g.head;g.head=C.next;let F=C;F.elt=null,F.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=F,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}g.pushmod=!0;let E=this.mrca2;for(;E.head!=null;){let C=E.head;E.head=C.next;let F=C;F.elt=null,F.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=F,E.head==null&&(E.pushmod=!0),E.modified=!0,E.length--}if(E.pushmod=!0,v.cbSet!=null){let C=this.mrca1,F;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?F=new I._zpp.util.ZNPNode_ZPP_Interactor:(F=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=F.next,F.next=null),F.elt=v;let O=F;O.next=C.head,C.head=O,C.modified=!0,C.length++}if(v.body.cbSet!=null){let C=this.mrca1,F=v.body,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=F;let B=O;B.next=C.head,C.head=B,C.modified=!0,C.length++}if(P.cbSet!=null){let C=this.mrca2,F;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?F=new I._zpp.util.ZNPNode_ZPP_Interactor:(F=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=F.next,F.next=null),F.elt=P;let O=F;O.next=C.head,C.head=O,C.modified=!0,C.length++}if(P.body.cbSet!=null){let C=this.mrca2,F=P.body,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=F;let B=O;B.next=C.head,C.head=B,C.modified=!0,C.length++}let N=v.body.compound,k=P.body.compound;for(;N!=k;){let C=N==null?0:N.depth,F=k==null?0:k.depth;if(C<F){if(k.cbSet!=null){let O=this.mrca2,B;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?B=new I._zpp.util.ZNPNode_ZPP_Interactor:(B=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=B.next,B.next=null),B.elt=k;let D=B;D.next=O.head,O.head=D,O.modified=!0,O.length++}k=k.compound}else{if(N.cbSet!=null){let O=this.mrca1,B;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?B=new I._zpp.util.ZNPNode_ZPP_Interactor:(B=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=B.next,B.next=null),B.elt=N;let D=B;D.next=O.head,O.head=D,O.modified=!0,O.length++}N=N.compound}}let Z=this.mrca1.head;for(;Z!=null;){let C=Z.elt,F=this.mrca2.head;for(;F!=null;){let O=F.elt,B=C.cbSet,D=O.cbSet,U=B.manager,W=null,L=(B.cbpairs.length<D.cbpairs.length?B.cbpairs:D.cbpairs).head;for(;L!=null;){let V=L.elt;if(V.a==B&&V.b==D||V.a==D&&V.b==B){W=V;break}L=L.next}if(W==null){let V;Se.zpp_pool==null?V=new Se:(V=Se.zpp_pool,Se.zpp_pool=V.next,V.next=null),V.zip_listeners=!0,St.setlt(B,D)?(V.a=B,V.b=D):(V.a=D,V.b=B),W=V,B.cbpairs.add(W),D!=B&&D.cbpairs.add(W)}if(W.zip_listeners&&(W.zip_listeners=!1,W.__validate()),W.listeners.head==null){F=F.next;continue}let A=null,J=null,$=this.prelisteners;for(;$.head!=null;){let V=$.head;$.head=V.next;let K=V;K.elt=null,K.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=K,$.head==null&&($.pushmod=!0),$.modified=!0,$.length--}$.pushmod=!0;let X=null,H=B.manager,ee=null,R=(B.cbpairs.length<D.cbpairs.length?B.cbpairs:D.cbpairs).head;for(;R!=null;){let V=R.elt;if(V.a==B&&V.b==D||V.a==D&&V.b==B){ee=V;break}R=R.next}if(ee==null){let V;Se.zpp_pool==null?V=new Se:(V=Se.zpp_pool,Se.zpp_pool=V.next,V.next=null),V.zip_listeners=!0,St.setlt(B,D)?(V.a=B,V.b=D):(V.a=D,V.b=B),ee=V,B.cbpairs.add(ee),D!=B&&D.cbpairs.add(ee)}ee.zip_listeners&&(ee.zip_listeners=!1,ee.__validate());let j=ee.listeners.head;for(;j!=null;){let V=j.elt;if(V.event==5&&(V.itype&y)!=0){let K=i.prelisteners,Q;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?Q=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(Q=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=Q.next,Q.next=null),Q.elt=V;let Y=Q;X==null?(Y.next=K.head,K.head=Y):(Y.next=X.next,X.next=Y),K.pushmod=K.modified=!0,K.length++,X=Y,w=w||!V.pure}j=j.next}if(this.prelisteners.head==null){F=F.next;continue}if(A=I._zpp.phys.ZPP_Interactor.get(C,O),A==null&&(J=xn.get(C,O),this.add_callbackset(J)),A==null||(A.COLLISIONstamp!=this.stamp||s)&&(A.COLLISIONstate&4)==0){if(J!=null&&(A=J),A!=null){let re=this.prelisteners.head;for(;re!=null;)re.elt.itype==7?(A.COLLISIONstamp=this.stamp,A.SENSORstamp=this.stamp,A.FLUIDstamp=this.stamp):A.COLLISIONstamp=this.stamp,re=re.next}z.mutable=!0,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!1),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!1);let V=z.active;z.active=!0;let K=!1,Q=!0,Y=null,ne=null,ae=z.innards.next;z.hc2=!1;let le=z.contacts.next;for(;le!=null;){let re=le;if(re.stamp+I._nape.Config.arbiterExpirationDelay<z.stamp){let pe=z.contacts,de,te;Y==null?(de=pe.next,te=de.next,pe.next=te,pe.next==null&&(pe.pushmod=!0)):(de=Y.next,te=de.next,Y.next=te,te==null&&(pe.pushmod=!0)),de._inuse=!1,pe.modified=!0,pe.length--,pe.pushmod=!0,le=te;let _e=z.innards,me,xe;ne==null?(me=_e.next,xe=me.next,_e.next=xe,_e.next==null&&(_e.pushmod=!0)):(me=ne.next,xe=me.next,ne.next=xe,xe==null&&(_e.pushmod=!0)),me._inuse=!1,_e.modified=!0,_e.length--,_e.pushmod=!0,ae=xe;let ge=re;ge.arbiter=null,ge.next=we.zpp_pool,we.zpp_pool=ge;continue}let he=re.inner,ce=re.active;re.active=re.stamp==z.stamp,re.active&&(Q?(Q=!1,z.c1=he,z.oc1=re):(z.hc2=!0,z.c2=he,z.oc2=re)),ce!=re.active&&(z.contacts.modified=!0),Y=le,ne=ae,ae=ae.next,le=le.next}if(z.hc2){if(z.hpc2=!0,z.oc1.posOnly){let re=z.c1;z.c1=z.c2,z.c2=re;let he=z.oc1;z.oc1=z.oc2,z.oc2=he,z.hc2=!1}else z.oc2.posOnly&&(z.hc2=!1);z.oc1.posOnly&&(Q=!0)}else z.hpc2=!1;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=A;let se=this.prelisteners.head;for(;se!=null;){let re=se.elt;this.precb.zpp_inner.listener=re;let he=this.precb.zpp_inner,ce=A.int1,pe=A.int2,de,te=re.options1,_e=ce.cbTypes;if(te.nonemptyintersection(_e,te.includes)&&!te.nonemptyintersection(_e,te.excludes)){let xe=re.options2,ge=pe.cbTypes;de=xe.nonemptyintersection(ge,xe.includes)&&!xe.nonemptyintersection(ge,xe.excludes)}else de=!1;de?(he.int1=ce,he.int2=pe):(he.int1=pe,he.int2=ce),this.precb.zpp_inner.pre_swapped=C!=this.precb.zpp_inner.int1;let me=re.handlerp(this.precb);if(me!=null){let xe;T.PreFlag_ACCEPT==null&&(T.internal=!0,T.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,T.internal=!1),me==T.PreFlag_ACCEPT?xe=5:(T.PreFlag_ACCEPT_ONCE==null&&(T.internal=!0,T.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,T.internal=!1),me==T.PreFlag_ACCEPT_ONCE?xe=1:(T.PreFlag_IGNORE==null&&(T.internal=!0,T.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,T.internal=!1),xe=me==T.PreFlag_IGNORE?6:2)),z.immState=xe}se=se.next}if(z.mutable=!1,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!0),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!0),z.active=V,A!=null){let re=this.prelisteners.head;for(;re!=null;)re.elt.itype==7?(A.COLLISIONstate=z.immState,A.SENSORstate=z.immState,A.FLUIDstate=z.immState):A.COLLISIONstate=z.immState,re=re.next}}else A==null?(z.immState&4)==0&&(z.immState=1):z.immState=A.COLLISIONstate;F=F.next}Z=Z.next}if(w&&(z.immState&4)==0){if(z.b1.type==2){let C=z.b1;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}if(z.b1.type==2){let C=z.b2;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}}}if((z.immState&1)!=0){if(z.b1.type==2&&z.b1.component.sleeping){let w=z.b1;w.world||(w.component.waket=this.stamp+(this.midstep?0:1),w.type==3&&(w.kinematicDelaySleep=!0),w.component.sleeping&&this.really_wake(w,!1))}if(z.b2.type==2&&z.b2.component.sleeping){let w=z.b2;w.world||(w.component.waket=this.stamp+(this.midstep?0:1),w.type==3&&(w.kinematicDelaySleep=!0),w.component.sleeping&&this.really_wake(w,!1))}}if(z.sleeping){z.sleeping=!1;let w;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?w=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(w=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=w.next,w.next=null),w.elt=z;let v=w;v.next=d.head,d.head=v,d.modified=!0,d.length++}r=z}else if(m){let w=z;w.userdef_dyn_fric=!1,w.userdef_stat_fric=!1,w.userdef_restitution=!1,w.userdef_rfric=!1,w.__ref_edge1=w.__ref_edge2=null,w.next=gt.zpp_pool,gt.zpp_pool=w,r=null}else r=z;else r=z}else{let d;if(l==null){let y=null,v=(o.arbiters.length<a.arbiters.length?o:a).arbiters.head;for(;v!=null;){let P=v.elt;if(P.id==x.id&&P.di==f.id){y=P;break}v=v.next}d=y}else d=l;let b=d==null,m,z=!1;if(b)Qt.zpp_pool==null?m=new Qt:(m=Qt.zpp_pool,Qt.zpp_pool=m.next,m.next=null);else if(d.sensorarb==null){d.cleared=!0;{let w=d.b1.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let E,N;v==null?(E=w.head,N=E.next,w.head=N,w.head==null&&(w.pushmod=!0)):(E=v.next,N=E.next,v.next=N,N==null&&(w.pushmod=!0));let k=E;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}{let w=d.b2.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let E,N;v==null?(E=w.head,N=E.next,w.head=N,w.head==null&&(w.pushmod=!0)):(E=v.next,N=E.next,v.next=N,N==null&&(w.pushmod=!0));let k=E;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Qt.zpp_pool==null?m=new Qt:(m=Qt.zpp_pool,Qt.zpp_pool=m.next,m.next=null),m.intchange=!0,b=!0,z=!0}else m=d.sensorarb;let M=2;if(b||m.stamp!=this.stamp||s)if(m.stamp=this.stamp,Ne.testCollide(x,f)){if(b){let y=f.id;m.b1=e.body,m.ws1=e,m.b2=t.body,m.ws2=t,m.id=x.id,m.di=y;let w=m.b1.arbiters,v;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?v=new I._zpp.util.ZNPNode_ZPP_Arbiter:(v=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=v.next,v.next=null),v.elt=m;let P=v;P.next=w.head,w.head=P,w.modified=!0,w.length++;let g=m.b2.arbiters,E;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?E=new I._zpp.util.ZNPNode_ZPP_Arbiter:(E=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E.next,E.next=null),E.elt=m;let N=E;N.next=g.head,g.head=N,g.modified=!0,g.length++,m.active=!0,m.present=0,m.cleared=!1,m.sleeping=!1,m.fresh=!1,m.presentable=!1;let k=this.s_arbiters,Z;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?Z=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(Z=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=Z.next,Z.next=null),Z.elt=m;let C=Z;C.next=k.head,k.head=C,k.modified=!0,k.length++,m.fresh=!z}else m.fresh=m.up_stamp<this.stamp-1||m.endGenerated==this.stamp&&s;if(m.up_stamp=m.stamp,m.fresh||(m.immState&4)==0){m.immState=1;let y=!1,w=m.ws1.id>m.ws2.id?m.ws2:m.ws1,v=m.ws1.id>m.ws2.id?m.ws1:m.ws2,P=this.mrca1;for(;P.head!=null;){let Z=P.head;P.head=Z.next;let C=Z;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}P.pushmod=!0;let g=this.mrca2;for(;g.head!=null;){let Z=g.head;g.head=Z.next;let C=Z;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}if(g.pushmod=!0,w.cbSet!=null){let Z=this.mrca1,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=w;let F=C;F.next=Z.head,Z.head=F,Z.modified=!0,Z.length++}if(w.body.cbSet!=null){let Z=this.mrca1,C=w.body,F;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?F=new I._zpp.util.ZNPNode_ZPP_Interactor:(F=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=F.next,F.next=null),F.elt=C;let O=F;O.next=Z.head,Z.head=O,Z.modified=!0,Z.length++}if(v.cbSet!=null){let Z=this.mrca2,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=v;let F=C;F.next=Z.head,Z.head=F,Z.modified=!0,Z.length++}if(v.body.cbSet!=null){let Z=this.mrca2,C=v.body,F;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?F=new I._zpp.util.ZNPNode_ZPP_Interactor:(F=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=F.next,F.next=null),F.elt=C;let O=F;O.next=Z.head,Z.head=O,Z.modified=!0,Z.length++}let E=w.body.compound,N=v.body.compound;for(;E!=N;){let Z=E==null?0:E.depth,C=N==null?0:N.depth;if(Z<C){if(N.cbSet!=null){let F=this.mrca2,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=N;let B=O;B.next=F.head,F.head=B,F.modified=!0,F.length++}N=N.compound}else{if(E.cbSet!=null){let F=this.mrca1,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=E;let B=O;B.next=F.head,F.head=B,F.modified=!0,F.length++}E=E.compound}}let k=this.mrca1.head;for(;k!=null;){let Z=k.elt,C=this.mrca2.head;for(;C!=null;){let F=C.elt,O=Z.cbSet,B=F.cbSet,D=O.manager,U=null,q=(O.cbpairs.length<B.cbpairs.length?O.cbpairs:B.cbpairs).head;for(;q!=null;){let j=q.elt;if(j.a==O&&j.b==B||j.a==B&&j.b==O){U=j;break}q=q.next}if(U==null){let j;Se.zpp_pool==null?j=new Se:(j=Se.zpp_pool,Se.zpp_pool=j.next,j.next=null),j.zip_listeners=!0,St.setlt(O,B)?(j.a=O,j.b=B):(j.a=B,j.b=O),U=j,O.cbpairs.add(U),B!=O&&B.cbpairs.add(U)}if(U.zip_listeners&&(U.zip_listeners=!1,U.__validate()),U.listeners.head==null){C=C.next;continue}let L=null,A=null,J=this.prelisteners;for(;J.head!=null;){let j=J.head;J.head=j.next;let V=j;V.elt=null,V.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=V,J.head==null&&(J.pushmod=!0),J.modified=!0,J.length--}J.pushmod=!0;let $=null,X=O.manager,H=null,G=(O.cbpairs.length<B.cbpairs.length?O.cbpairs:B.cbpairs).head;for(;G!=null;){let j=G.elt;if(j.a==O&&j.b==B||j.a==B&&j.b==O){H=j;break}G=G.next}if(H==null){let j;Se.zpp_pool==null?j=new Se:(j=Se.zpp_pool,Se.zpp_pool=j.next,j.next=null),j.zip_listeners=!0,St.setlt(O,B)?(j.a=O,j.b=B):(j.a=B,j.b=O),H=j,O.cbpairs.add(H),B!=O&&B.cbpairs.add(H)}H.zip_listeners&&(H.zip_listeners=!1,H.__validate());let R=H.listeners.head;for(;R!=null;){let j=R.elt;if(j.event==5&&(j.itype&M)!=0){let V=i.prelisteners,K;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?K=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(K=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=K.next,K.next=null),K.elt=j;let Q=K;$==null?(Q.next=V.head,V.head=Q):(Q.next=$.next,$.next=Q),V.pushmod=V.modified=!0,V.length++,$=Q,y=y||!j.pure}R=R.next}if(this.prelisteners.head==null){C=C.next;continue}if(L=I._zpp.phys.ZPP_Interactor.get(Z,F),L==null&&(A=xn.get(Z,F),this.add_callbackset(A)),L==null||(L.SENSORstamp!=this.stamp||s)&&(L.SENSORstate&4)==0){if(A!=null&&(L=A),L!=null){let Q=this.prelisteners.head;for(;Q!=null;)Q.elt.itype==7?(L.COLLISIONstamp=this.stamp,L.SENSORstamp=this.stamp,L.FLUIDstamp=this.stamp):L.SENSORstamp=this.stamp,Q=Q.next}let j=m.active;m.active=!0;let V=!1;this.precb.zpp_inner.pre_arbiter=m,this.precb.zpp_inner.set=L;let K=this.prelisteners.head;for(;K!=null;){let Q=K.elt;this.precb.zpp_inner.listener=Q;let Y=this.precb.zpp_inner,ne=L.int1,ae=L.int2,le,se=Q.options1,re=ne.cbTypes;if(se.nonemptyintersection(re,se.includes)&&!se.nonemptyintersection(re,se.excludes)){let ce=Q.options2,pe=ae.cbTypes;le=ce.nonemptyintersection(pe,ce.includes)&&!ce.nonemptyintersection(pe,ce.excludes)}else le=!1;le?(Y.int1=ne,Y.int2=ae):(Y.int1=ae,Y.int2=ne),this.precb.zpp_inner.pre_swapped=Z!=this.precb.zpp_inner.int1;let he=Q.handlerp(this.precb);if(he!=null){let ce;T.PreFlag_ACCEPT==null&&(T.internal=!0,T.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,T.internal=!1),he==T.PreFlag_ACCEPT?ce=5:(T.PreFlag_ACCEPT_ONCE==null&&(T.internal=!0,T.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,T.internal=!1),he==T.PreFlag_ACCEPT_ONCE?ce=1:(T.PreFlag_IGNORE==null&&(T.internal=!0,T.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,T.internal=!1),ce=he==T.PreFlag_IGNORE?6:2)),m.immState=ce}K=K.next}if(m.active=j,L!=null){let Q=this.prelisteners.head;for(;Q!=null;)Q.elt.itype==7?(L.COLLISIONstate=m.immState,L.SENSORstate=m.immState,L.FLUIDstate=m.immState):L.SENSORstate=m.immState,Q=Q.next}}else L==null?(m.immState&4)==0&&(m.immState=1):m.immState=L.SENSORstate;C=C.next}k=k.next}if(y&&(m.immState&4)==0){if(m.b1.type!=1){let Z=m.b1;Z.world||(Z.component.waket=this.stamp+(this.midstep?0:1),Z.type==3&&(Z.kinematicDelaySleep=!0),Z.component.sleeping&&this.really_wake(Z,!1))}if(m.b2.type!=1){let Z=m.b2;Z.world||(Z.component.waket=this.stamp+(this.midstep?0:1),Z.type==3&&(Z.kinematicDelaySleep=!0),Z.component.sleeping&&this.really_wake(Z,!1))}}}if(m.sleeping){m.sleeping=!1;let y=this.s_arbiters,w;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?w=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(w=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=w.next,w.next=null),w.elt=m;let v=w;v.next=y.head,y.head=v,y.modified=!0,y.length++}r=m}else if(b){let y=m;y.next=Qt.zpp_pool,Qt.zpp_pool=y,r=null}else r=m;else r=m}}return r}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=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let l=this.mrca2;for(;l.head!=null;){let r=l.head;l.head=r.next;let o=r;o.elt=null,o.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,l.head==null&&(l.pushmod=!0),l.modified=!0,l.length--}if(l.pushmod=!0,e.cbSet!=null){let r=this.mrca1,o;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_Interactor:(o=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=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;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=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;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_Interactor:(o=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=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;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}let s=e.body.compound,i=t.body.compound;for(;s!=i;){let r=s==null?0:s.depth,o=i==null?0:i.depth;if(r<o){if(i.cbSet!=null){let a=this.mrca2,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=i;let c=p;c.next=a.head,a.head=c,a.modified=!0,a.length++}i=i.compound}else{if(s.cbSet!=null){let a=this.mrca1,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=s;let c=p;c.next=a.head,a.head=c,a.modified=!0,a.length++}s=s.compound}}}inlined_MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let r=n.head;n.head=r.next;let o=r;o.elt=null,o.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let l=this.mrca2;for(;l.head!=null;){let r=l.head;l.head=r.next;let o=r;o.elt=null,o.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,l.head==null&&(l.pushmod=!0),l.modified=!0,l.length--}if(l.pushmod=!0,e.cbSet!=null){let r=this.mrca1,o;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_Interactor:(o=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=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;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=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;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_Interactor:(o=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=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;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}let s=e.body.compound,i=t.body.compound;for(;s!=i;){let r=s==null?0:s.depth,o=i==null?0:i.depth;if(r<o){if(i.cbSet!=null){let a=this.mrca2,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=i;let c=p;c.next=a.head,a.head=c,a.modified=!0,a.length++}i=i.compound}else{if(s.cbSet!=null){let a=this.mrca1,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=s;let c=p;c.next=a.head,a.head=c,a.modified=!0,a.length++}s=s.compound}}}};I.__name__=["zpp_nape","space","ZPP_Space"],I._zpp=null,I._nape=null;var Ki=I;var Kn=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}};Kn.__name__=["zpp_nape","space","ZPP_SweepData"],Kn.zpp_pool=null;var yt=class yt{constructor(e){this.failed=null;this.list=null;this.space=null;this.is_sweep=!1;this.sweep=null;this.__class__=yt;yt._zpp.space.ZPP_Broadphase._initFields(this),this.space=e,this.is_sweep=!0,this.sweep=this}static _init(){yt.__super__=yt._zpp.space.ZPP_Broadphase;let e=yt._zpp.space.ZPP_Broadphase.prototype;Object.getOwnPropertyNames(e).forEach(t=>{t!=="constructor"&&!(t in yt.prototype)&&(yt.prototype[t]=e[t])})}__insert(e){let t;Kn.zpp_pool==null?t=new Kn:(t=Kn.zpp_pool,Kn.zpp_pool=t.next,t.next=null),e.sweep=t,t.shape=e,t.aabb=e.aabb,t.next=this.list,this.list!=null&&(this.list.prev=t),this.list=t}__remove(e){let t=e.sweep;t.prev==null?this.list=t.next:t.prev.next=t.next,t.next!=null&&(t.next.prev=t.prev),e.sweep=null;let n=t;n.prev=null,n.shape=null,n.aabb=null,n.next=Kn.zpp_pool,Kn.zpp_pool=n}__sync(e){if(!this.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let i=t.polygon;if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(i.lverts.next.next==null)i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;else if(i.lverts.next.next.next==null){i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;let r=1;i.localCOMx+=i.lverts.next.next.x*r,i.localCOMy+=i.lverts.next.next.y*r;let o=.5;i.localCOMx*=o,i.localCOMy*=o}else{i.localCOMx=0,i.localCOMy=0;let r=0,o=i.lverts.next,a=o;o=o.next;let p=o;for(o=o.next;o!=null;){let _=o;r+=p.x*(_.y-a.y);let d=_.y*p.x-_.x*p.y;i.localCOMx+=(p.x+_.x)*d,i.localCOMy+=(p.y+_.y)*d,a=p,p=_,o=o.next}o=i.lverts.next;let c=o;r+=p.x*(c.y-a.y);let u=c.y*p.x-c.x*p.y;i.localCOMx+=(p.x+c.x)*u,i.localCOMy+=(p.y+c.y)*u,a=p,p=c,o=o.next;let h=o;r+=p.x*(h.y-a.y);let x=h.y*p.x-h.x*p.y;i.localCOMx+=(p.x+h.x)*x,i.localCOMy+=(p.y+h.y)*x,r=1/(3*r);let f=r;i.localCOMx*=f,i.localCOMy*=f}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,r=t.gverts.next;for(;r!=null;){let o=r,a=i;i=i.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 l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}}sync_broadphase(){if(this.space.validation(),this.list!=null){let e=this.list.next;for(;e!=null;){let t=e.next,n=e.prev;if(n!=null&&e.aabb.minx>n.aabb.minx){e=t;continue}for(;n.prev!=null&&n.prev.aabb.minx>e.aabb.minx;)n=n.prev;let l=e.prev;l.next=e.next,e.next!=null&&(e.next.prev=l),n.prev==null?(e.prev=null,this.list=e,e.next=n,n.prev=e):(e.prev=n.prev,n.prev=e,e.prev.next=e,e.next=n),e=t}}}sync_broadphase_fast(){let e=this.list.next;for(;e!=null;){let t=e.next,n=e.prev;if(n!=null&&e.aabb.minx>n.aabb.minx){e=t;continue}for(;n.prev!=null&&n.prev.aabb.minx>e.aabb.minx;)n=n.prev;let l=e.prev;l.next=e.next,e.next!=null&&(e.next.prev=l),n.prev==null?(e.prev=null,this.list=e,e.next=n,n.prev=e):(e.prev=n.prev,n.prev=e,e.prev.next=e,e.next=n),e=t}}broadphase(e,t){if(this.list!=null){let n=this.list.next;for(;n!=null;){let s=n.next,i=n.prev;if(i!=null&&n.aabb.minx>i.aabb.minx){n=s;continue}for(;i.prev!=null&&i.prev.aabb.minx>n.aabb.minx;)i=i.prev;let r=n.prev;r.next=n.next,n.next!=null&&(n.next.prev=r),i.prev==null?(n.prev=null,this.list=n,n.next=i,i.prev=n):(n.prev=i.prev,i.prev=n,n.prev.next=n,n.next=i),n=s}let l=this.list;for(;l!=null;){let s=l.next,i=l.shape,r=i.body,o=l.aabb.maxx;for(;s!=null&&!(s.aabb.minx>o);){let a=s.shape,p=a.body;if(p==r){s=s.next;continue}if(r.type==1&&p.type==1){s=s.next;continue}if(r.component.sleeping&&p.component.sleeping){s=s.next;continue}let c=i.aabb,u=a.aabb;u.miny>c.maxy||c.miny>u.maxy||(t?e.narrowPhase(i,a,r.type!=2||p.type!=2,null,!1):e.continuousEvent(i,a,r.type!=2||p.type!=2,null,!1)),s=s.next}l=l.next}}}clear(){for(;this.list!=null;)this.list.shape.removedFromSpace(),this.__remove(this.list.shape)}shapesUnderPoint(e,t,n,l){this.sync_broadphase();let s;ie.zpp_pool==null?s=new ie:(s=ie.zpp_pool,ie.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,r=l??new yt._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.minx>e;)o=o.next;for(;o!=null&&o.aabb.minx<=e;){if(o.aabb.maxx>=e&&o.aabb.miny<=t&&o.aabb.maxy>=t){let p=o.shape,c;if(n!=null){let u=p.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(p.type==0?Ne.circleContains(p.circle,i)&&r.push(p.outer):Ne.polyContains(p.polygon,i)&&r.push(p.outer))}o=o.next}let a=i;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ie.zpp_pool,ie.zpp_pool=a,r}bodiesUnderPoint(e,t,n,l){this.sync_broadphase();let s;ie.zpp_pool==null?s=new ie:(s=ie.zpp_pool,ie.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,r=l??new yt._nape.phys.BodyList,o=this.list;for(;o!=null&&o.aabb.minx>e;)o=o.next;for(;o!=null&&o.aabb.minx<=e;){if(o.aabb.maxx>=e&&o.aabb.miny<=t&&o.aabb.maxy>=t){let p=o.shape,c=p.body.outer;if(!r.has(c)){let u;if(n!=null){let h=p.filter;u=(h.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(p.type==0?Ne.circleContains(p.circle,i)&&r.push(c):Ne.polyContains(p.polygon,i)&&r.push(c))}}o=o.next}let a=i;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ie.zpp_pool,ie.zpp_pool=a,r}shapesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,r=s??new yt._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.maxx<i.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=i.maxx;){let a=o.shape,p;if(l!=null){let c=a.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;if(p)if(t)if(n)Ne.containTest(this.aabbShape.zpp_inner,a)&&r.push(a.outer);else{let c=o.aabb;if(c.minx>=i.minx&&c.miny>=i.miny&&c.maxx<=i.maxx&&c.maxy<=i.maxy)r.push(a.outer);else{let u=o.aabb;i.miny<=u.maxy&&u.miny<=i.maxy&&i.minx<=u.maxx&&u.minx<=i.maxx&&Ne.testCollide_safe(a,this.aabbShape.zpp_inner)&&r.push(a.outer)}}else{let c;if(n){let u=o.aabb;c=u.minx>=i.minx&&u.miny>=i.miny&&u.maxx<=i.maxx&&u.maxy<=i.maxy}else{let u=o.aabb;c=i.miny<=u.maxy&&u.miny<=i.maxy&&i.minx<=u.maxx&&u.minx<=i.maxx}c&&r.push(a.outer)}o=o.next}return r}bodiesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,r=s??new yt._nape.phys.BodyList;this.failed==null&&(this.failed=new yt._nape.phys.BodyList);let o=this.list;for(;o!=null&&o.aabb.maxx<i.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=i.maxx;){let a=o.shape,p=a.body.outer,c=o.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx){let u;if(l!=null){let h=a.filter;u=(h.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(t)if(n){if(!this.failed.has(p)){let h=Ne.containTest(this.aabbShape.zpp_inner,a);!r.has(p)&&h?r.push(p):h||(r.remove(p),this.failed.push(p))}}else!r.has(p)&&Ne.testCollide_safe(a,this.aabbShape.zpp_inner)&&r.push(p);else if(n){if(!this.failed.has(p)){let h=a.aabb,x=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy;!r.has(p)&&x?r.push(p):x||(r.remove(p),this.failed.push(p))}}else{let h;if(r.has(p))h=!1;else{let x=a.aabb;h=x.minx>=i.minx&&x.miny>=i.miny&&x.maxx<=i.maxx&&x.maxy<=i.maxy}h&&r.push(p)}}o=o.next}return this.failed.clear(),r}shapesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let r=this.circShape.zpp_inner.aabb,o=i??new yt._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.aabb;if(r.miny<=p.maxy&&p.miny<=r.maxy&&r.minx<=p.maxx&&p.minx<=r.maxx){let c=a.shape,u;if(s!=null){let h=c.filter;u=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(l?Ne.containTest(this.circShape.zpp_inner,c)&&o.push(c.outer):Ne.testCollide_safe(c,this.circShape.zpp_inner)&&o.push(c.outer))}a=a.next}return o}bodiesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let r=this.circShape.zpp_inner.aabb,o=i??new yt._nape.phys.BodyList;this.failed==null&&(this.failed=new yt._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.aabb;if(r.miny<=p.maxy&&p.miny<=r.maxy&&r.minx<=p.maxx&&p.minx<=r.maxx){let c=a.shape,u=c.body.outer,h;if(s!=null){let x=c.filter;h=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else h=!0;if(h)if(l){if(!this.failed.has(u)){let x=Ne.containTest(this.circShape.zpp_inner,c);!o.has(u)&&x?o.push(u):x||(o.remove(u),this.failed.push(u))}}else!o.has(u)&&Ne.testCollide_safe(c,this.circShape.zpp_inner)&&o.push(u)}a=a.next}return this.failed.clear(),o}shapesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new yt._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.maxx<s.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=s.maxx;){let o=r.aabb;if(s.miny<=o.maxy&&o.miny<=s.maxy&&s.minx<=o.maxx&&o.minx<=s.maxx){let a=r.shape,p;if(n!=null){let c=a.filter;p=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(t?Ne.containTest(e,a)&&i.push(a.outer):Ne.testCollide_safe(a,e)&&i.push(a.outer))}r=r.next}return i}bodiesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new yt._nape.phys.BodyList;this.failed==null&&(this.failed=new yt._nape.phys.BodyList);let r=this.list;for(;r!=null&&r.aabb.maxx<s.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=s.maxx;){let o=r.aabb;if(s.miny<=o.maxy&&o.miny<=s.maxy&&s.minx<=o.maxx&&o.minx<=s.maxx){let a=r.shape,p=a.body.outer,c;if(n!=null){let u=a.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;if(c)if(t){if(!this.failed.has(p)){let u=Ne.containTest(e,a);!i.has(p)&&u?i.push(p):u||(i.remove(p),this.failed.push(p))}}else!i.has(p)&&Ne.testCollide_safe(e,a)&&i.push(p)}r=r.next}return this.failed.clear(),i}rayCast(e,t,n){this.sync_broadphase(),e.validate_dir();let l=e.rayAABB(),s=e.maxdist,i=null;if(e.dirx==0){let o=this.list;for(;o!=null&&o.aabb.minx<=l.minx;){let a,p=o.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx)if(n!=null){let c=o.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;if(a){let c=e.aabbsect(o.aabb);if(c>=0&&c<s){let u=o.shape.type==0?e.circlesect(o.shape.circle,t,s):e.polysect(o.shape.polygon,t,s);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(s=u.zpp_inner.toiDistance,i!=null){if(i.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");i.zpp_inner.free()}i=u}}}o=o.next}}else if(e.dirx<0){let o=this.list,a=null;for(;o!=null&&o.aabb.minx<=l.maxx;)a=o,o=o.next;for(o=a;o!=null;){let p,c=o.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(n!=null){let u=o.shape.filter;p=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else p=!0;else p=!1;if(p){let u=e.aabbsect(o.aabb);if(u>=0&&u<s){let h=o.shape.type==0?e.circlesect(o.shape.circle,t,s):e.polysect(o.shape.polygon,t,s);if(h!=null){if(h.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(s=h.zpp_inner.toiDistance,i!=null){if(i.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");i.zpp_inner.free()}i=h}}}o=o.prev}}else{let o=this.list;for(;o!=null&&o.aabb.minx<=l.maxx&&o.aabb.minx<e.originx+e.dirx*s;){let a,p=o.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx)if(n!=null){let c=o.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;if(a){let c=e.aabbsect(o.aabb);if(c>=0&&c<s){let u=o.shape.type==0?e.circlesect(o.shape.circle,t,s):e.polysect(o.shape.polygon,t,s);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(s=u.zpp_inner.toiDistance,i!=null){if(i.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");i.zpp_inner.free()}i=u}}}o=o.next}}let r=l;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r.wrap_min=r.wrap_max=null,r._invalidate=null,r._validate=null,r.next=fe.zpp_pool,fe.zpp_pool=r,i}rayMultiCast(e,t,n,l){this.sync_broadphase(),e.validate_dir();let s=e.rayAABB(),i=l??new yt._nape.geom.RayResultList;if(e.dirx==0){let o=this.list;for(;o!=null&&o.aabb.minx<=s.minx;){let a,p=o.aabb;if(s.miny<=p.maxy&&p.miny<=s.maxy&&s.minx<=p.maxx&&p.minx<=s.maxx)if(n!=null){let c=o.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;a&&e.aabbsect(o.aabb)>=0&&(o.shape.type==0?e.circlesect2(o.shape.circle,t,i):e.polysect2(o.shape.polygon,t,i)),o=o.next}}else if(e.dirx<0){let o=this.list,a=null;for(;o!=null&&o.aabb.minx<=s.maxx;)a=o,o=o.next;for(o=a;o!=null;){let p,c=o.aabb;if(s.miny<=c.maxy&&c.miny<=s.maxy&&s.minx<=c.maxx&&c.minx<=s.maxx)if(n!=null){let u=o.shape.filter;p=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else p=!0;else p=!1;p&&e.aabbsect(o.aabb)>=0&&(o.shape.type==0?e.circlesect2(o.shape.circle,t,i):e.polysect2(o.shape.polygon,t,i)),o=o.prev}}else{let o=this.list;for(;o!=null&&o.aabb.minx<=s.maxx;){let a,p=o.aabb;if(s.miny<=p.maxy&&p.miny<=s.maxy&&s.minx<=p.maxx&&p.minx<=s.maxx)if(n!=null){let c=o.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;a&&e.aabbsect(o.aabb)>=0&&(o.shape.type==0?e.circlesect2(o.shape.circle,t,i):e.polysect2(o.shape.polygon,t,i)),o=o.next}}let r=s;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r.wrap_min=r.wrap_max=null,r._invalidate=null,r._validate=null,r.next=fe.zpp_pool,fe.zpp_pool=r,i}};yt.__name__=["zpp_nape","space","ZPP_SweepPhase"],yt.__super__=null,yt._zpp=null,yt._nape=null;var Ws=yt;function Co(){let S={},e={};return S.callbacks={},S.constraint={},S.dynamics={},S.geom={},S.phys={},S.shape={},S.space={},S.util={},e.ZPP_Const=Li,e.ZPP_ID=In,e.callbacks||(e.callbacks={}),_t._nape=S,_t._zpp=e,e.callbacks.ZPP_Callback=_t,St._zpp=e,e.callbacks.ZPP_CbSet=St,Se._zpp=e,e.callbacks.ZPP_CbSetPair=Se,e.util||(e.util={}),go(e),zt._zpp=e,e.callbacks.ZPP_CbType=zt,e.util.ZPP_Flags=T,Ke._nape=S,Ke._zpp=e,e.callbacks.ZPP_Listener=Ke,e.callbacks.ZPP_BodyListener=Ns,e.callbacks.ZPP_ConstraintListener=Os,e.callbacks.ZPP_InteractionListener=es,Ht._nape=S,Ht._zpp=e,e.callbacks.ZPP_OptionType=Ht,e.constraint||(e.constraint={}),Ze._nape=S,Ze._zpp=e,e.constraint.ZPP_Constraint=Ze,e.constraint.ZPP_Constraint.__name__=Ze.__name__,e.constraint.ZPP_AngleJoint=We,e.constraint.ZPP_AngleJoint.__name__=We.__name__,e.constraint.ZPP_CopyHelper=_i,e.constraint.ZPP_DistanceJoint=xi,e.constraint.ZPP_DistanceJoint.__name__=xi.__name__,e.constraint.ZPP_LineJoint=di,e.constraint.ZPP_LineJoint.__name__=di.__name__,e.constraint.ZPP_MotorJoint=yi,e.constraint.ZPP_MotorJoint.__name__=yi.__name__,e.constraint.ZPP_PivotJoint=mi,e.constraint.ZPP_PivotJoint.__name__=mi.__name__,e.constraint.ZPP_PulleyJoint=fi,e.constraint.ZPP_PulleyJoint.__name__=fi.__name__,e.constraint.ZPP_UserConstraint=Ts,e.constraint.ZPP_UserConstraint.__name__=Ts.__name__,e.constraint.ZPP_UserBody=Is,e.constraint.ZPP_WeldJoint=bi,e.constraint.ZPP_WeldJoint.__name__=bi.__name__,e.dynamics||(e.dynamics={}),ke._nape=S,ke._zpp=e,e.dynamics.ZPP_Arbiter=ke,e.dynamics.ZPP_SensorArbiter=Qt,Bt._nape=S,Bt._zpp=e,e.dynamics.ZPP_FluidArbiter=Bt,gt._nape=S,gt._zpp=e,e.dynamics.ZPP_ColArbiter=gt,e.dynamics.ZPP_IContact=Di,we._nape=S,we._zpp=e,e.dynamics.ZPP_Contact=we,Ct._nape=S,Ct._zpp=e,e.dynamics.ZPP_InteractionFilter=Ct,Fi._zpp=e,e.dynamics.ZPP_InteractionGroup=Fi,zi._nape=S,zi._zpp=e,e.dynamics.ZPP_SpaceArbiterList=zi,e.geom||(e.geom={}),fe._nape=S,fe._zpp=e,e.geom.ZPP_AABB=fe,e.geom.ZPP_Collide=Ne,e.geom.ZPP_Convex=zl,e.geom.ZPP_ConvexRayResult=qt,e.geom.ZPP_CutVert=rt,e.geom.ZPP_CutInt=xt,e.geom.ZPP_Cutter=Pl,e.geom.ZPP_Geom=hn,e.geom.ZPP_GeomVert=Ce,Ce._createVec2Fn=function(){return new S.geom.Vec2},e.geom.ZPP_GeomPoly=Ds,e.geom.ZPP_MarchSpan=Rn,e.geom.ZPP_MarchPair=Gn,Fs._init(e,S),e.geom.ZPP_MarchingSquares=Fs,Ri._nape=S,e.geom.ZPP_Mat23=Ri,e.geom.ZPP_MatMN=ss,e.geom.ZPP_Monotone=on,e.geom.ZPP_PartitionVertex=Je,e.geom.ZPP_PartitionedPoly=He,e.geom.ZPP_Ray=vl,e.geom.ZPP_SimpleVert=Oe,e.geom.ZPP_SimpleSeg=en,e.geom.ZPP_SimpleEvent=Ee,e.geom.ZPP_SimpleSweep=as,e.geom.ZPP_Simple=ps,e.geom.ZPP_SimplifyV=qn,e.geom.ZPP_SimplifyP=je,e.geom.ZPP_Simplify=gl,e.geom.ZPP_ToiEvent=Cl,e.geom.ZPP_SweepDistance=un,e.geom.ZPP_PartitionPair=$t,e.geom.ZPP_Triangular=qi,e.geom.ZPP_Vec2=ie,Wi._zpp=e,e.geom.ZPP_Vec3=Wi,e.geom.ZPP_VecMath=gr,e.phys||(e.phys={}),e.phys.ZPP_Interactor=Ut,Ut._init(e,S),Wn._init(e,S),e.phys.ZPP_Body=Wn,Pi._nape=S,Pi._zpp=e,Pi._init(),e.phys.ZPP_Compound=Pi,Jn._nape=S,Jn._zpp=e,e.phys.ZPP_FluidProperties=Jn,Te._nape=S,Te._zpp=e,e.phys.ZPP_Material=Te,e.shape||(e.shape={}),Ji._nape=S,Ji._zpp=e,Ji._init(),e.shape.ZPP_Shape=Ji,Ni._nape=S,Ni._zpp=e,Ni._init(),e.shape.ZPP_Circle=Ni,Qe._nape=S,Qe._zpp=e,e.shape.ZPP_Edge=Qe,Oi._nape=S,Oi._zpp=e,Oi._init(),e.shape.ZPP_Polygon=Oi,e.space||(e.space={}),us._zpp=e,us._nape=S,e.space.ZPP_Broadphase=us,e.space.ZPP_AABBNode=Ve,e.space.ZPP_AABBPair=at,e.space.ZPP_AABBTree=pt,Gs._zpp=e,Gs._nape=S,Gs._init(),e.space.ZPP_DynAABBPhase=Gs,Mt._zpp=e,e.space.ZPP_Island=Mt,e.space.ZPP_Component=Ml,xn._zpp=e,e.space.ZPP_CallbackSet=xn,qs._zpp=e,e.space.ZPP_CbSetManager=qs,Ki._zpp=e,Ki._nape=S,e.space.ZPP_Space=Ki,e.space.ZPP_SweepData=Kn,Ws._zpp=e,Ws._nape=S,Ws._init(),e.space.ZPP_SweepPhase=Ws,e.util.ZNPArray2_Float=vs,e.util.ZNPArray2_ZPP_GeomVert=gs,e.util.ZNPArray2_ZPP_MarchPair=Cs,e.util.Hashable2_Boolfalse=Le,e.util.FastHash2_Hashable2_Boolfalse=Es,e.util.ZPP_Math=mr,e.util.ZPP_PubPool=ue,e.callbacks.ZPP_InteractionListener._initStatics(e),e.geom.ZPP_Collide._initStatics(e),e.space.ZPP_AABBTree._initStatics(),S.__zpp=e,S}var Qr;function oe(){return Qr||(Qr=Co()),Qr}var Zo=!1;function li(){if(Zo)return;let S=Qr;if(!S?.callbacks?.CbEvent||!S?.callbacks?.CbType||!S?.callbacks?.ListenerType||!S?.dynamics?.ArbiterType||!S?.phys?.BodyType||!S?.shape?.ShapeType)return;Zo=!0;let e=S.__zpp;e.callbacks.ZPP_CbType._initEnums(S),e.callbacks.ZPP_Listener._initEnums(S,e.util.ZPP_Flags),e.dynamics.ZPP_Arbiter._initEnums(S,e.util.ZPP_Flags),e.phys.ZPP_Body._initEnums(S,e.util.ZPP_Flags),e.shape.ZPP_Shape._initEnums(S,e.util.ZPP_Flags)}var mo={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},Mo=oe();Mo.Config=Object.assign(Mo.Config||{},mo);function ze(S,e,t){for(;S[e]!=null;){let n=S[e][t];S[e][t]=null,S[e]=n}}var $r=class{static version(){return"Nape 2.0.19"}static clearObjectPools(){let e=oe(),t=e.__zpp;ze(e.constraint.ConstraintIterator,"zpp_pool","zpp_next"),ze(e.phys.InteractorIterator,"zpp_pool","zpp_next"),ze(e.phys.BodyIterator,"zpp_pool","zpp_next"),ze(e.phys.CompoundIterator,"zpp_pool","zpp_next"),ze(e.callbacks.ListenerIterator,"zpp_pool","zpp_next"),ze(e.callbacks.CbTypeIterator,"zpp_pool","zpp_next"),ze(e.geom.ConvexResultIterator,"zpp_pool","zpp_next"),ze(e.geom.GeomPolyIterator,"zpp_pool","zpp_next"),ze(e.geom.Vec2Iterator,"zpp_pool","zpp_next"),ze(e.geom.RayResultIterator,"zpp_pool","zpp_next"),ze(e.shape.ShapeIterator,"zpp_pool","zpp_next"),ze(e.shape.EdgeIterator,"zpp_pool","zpp_next"),ze(e.dynamics.ContactIterator,"zpp_pool","zpp_next"),ze(e.dynamics.ArbiterIterator,"zpp_pool","zpp_next"),ze(e.dynamics.InteractionGroupIterator,"zpp_pool","zpp_next"),ze(t.util.ZNPNode_ZPP_CbType,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_CallbackSet,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Shape,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Body,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Constraint,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Compound,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Arbiter,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_InteractionListener,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_CbSet,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Interactor,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_BodyListener,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_CbSetPair,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_ConstraintListener,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_CutInt,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_CutVert,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_PartitionVertex,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_SimplifyP,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_PartitionedPoly,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_GeomVert,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_SimpleVert,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_SimpleEvent,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Vec2,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_AABBPair,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Edge,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_AABBNode,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Component,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_FluidArbiter,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_SensorArbiter,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_Listener,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_ColArbiter,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_InteractionGroup,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_ToiEvent,"zpp_pool","next"),ze(t.util.ZNPNode_ConvexResult,"zpp_pool","next"),ze(t.util.ZNPNode_ZPP_GeomPoly,"zpp_pool","next"),ze(t.util.ZNPNode_RayResult,"zpp_pool","next"),ze(t.phys.ZPP_Material,"zpp_pool","next"),ze(t.phys.ZPP_FluidProperties,"zpp_pool","next"),ze(t.callbacks.ZPP_CbSetPair,"zpp_pool","next"),ze(t.callbacks.ZPP_Callback,"zpp_pool","next"),ze(t.callbacks.ZPP_CbSet,"zpp_pool","next"),ze(t.geom.ZPP_GeomVert,"zpp_pool","next"),ze(t.geom.ZPP_GeomVertexIterator,"zpp_pool","next"),ze(t.geom.ZPP_Mat23,"zpp_pool","next"),ze(t.geom.ZPP_CutVert,"zpp_pool","next"),ze(t.geom.ZPP_CutInt,"zpp_pool","next"),ze(t.geom.ZPP_Vec2,"zpp_pool","next"),ze(t.geom.ZPP_PartitionVertex,"zpp_pool","next"),ze(t.geom.ZPP_SimplifyV,"zpp_pool","next"),ze(t.geom.ZPP_SimplifyP,"zpp_pool","next"),ze(t.geom.ZPP_PartitionedPoly,"zpp_pool","next"),ze(t.geom.ZPP_PartitionPair,"zpp_pool","next"),ze(t.geom.ZPP_AABB,"zpp_pool","next"),ze(t.geom.ZPP_SimpleVert,"zpp_pool","next"),ze(t.geom.ZPP_SimpleSeg,"zpp_pool","next"),ze(t.geom.ZPP_SimpleEvent,"zpp_pool","next"),ze(t.util.Hashable2_Boolfalse,"zpp_pool","next"),ze(t.geom.ZPP_ToiEvent,"zpp_pool","next"),ze(t.geom.ZPP_MarchSpan,"zpp_pool","next"),ze(t.geom.ZPP_MarchPair,"zpp_pool","next"),ze(t.shape.ZPP_Edge,"zpp_pool","next"),ze(t.space.ZPP_SweepData,"zpp_pool","next"),ze(t.space.ZPP_AABBNode,"zpp_pool","next"),ze(t.space.ZPP_AABBPair,"zpp_pool","next"),ze(t.dynamics.ZPP_Contact,"zpp_pool","next"),ze(t.space.ZPP_Island,"zpp_pool","next"),ze(t.space.ZPP_Component,"zpp_pool","next"),ze(t.space.ZPP_CallbackSet,"zpp_pool","next"),ze(t.dynamics.ZPP_SensorArbiter,"zpp_pool","next"),ze(t.dynamics.ZPP_FluidArbiter,"zpp_pool","next"),ze(t.dynamics.ZPP_ColArbiter,"zpp_pool","next"),ze(t.dynamics.ZPP_InteractionFilter,"zpp_pool","next"),ze(t.util.ZPP_Set_ZPP_Body,"zpp_pool","next"),ze(t.util.ZPP_Set_ZPP_CbSetPair,"zpp_pool","next"),ze(t.util.ZPP_Set_ZPP_PartitionVertex,"zpp_pool","next"),ze(t.util.ZPP_Set_ZPP_PartitionPair,"zpp_pool","next"),ze(t.util.ZPP_Set_ZPP_SimpleVert,"zpp_pool","next"),ze(t.util.ZPP_Set_ZPP_SimpleSeg,"zpp_pool","next"),ze(t.util.ZPP_Set_ZPP_SimpleEvent,"zpp_pool","next"),ze(t.util.ZPP_Set_ZPP_CbSet,"zpp_pool","next"),ze(t.util.ZPP_PubPool,"poolGeomPoly","zpp_pool"),ze(t.util.ZPP_PubPool,"poolVec2","zpp_pool"),ze(t.util.ZPP_PubPool,"poolVec3","zpp_pool")}};var Eo=new WeakMap;function ve(S,e){if(!S)return null;let t=Eo.get(S);return t||(t=e(S),Eo.set(S,t)),t}var Ue=class Ue{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;ie.zpp_pool==null?n=new ie:(n=ie.zpp_pool,ie.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,this.zpp_inner=n,n.outer=this}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}_checkImmutable(){this.zpp_inner.immutable()}_validate(){this.zpp_inner.validate()}_invalidate(){this.zpp_inner.invalidate()}static _disposeWeak(e){e.zpp_inner.weak&&e.dispose()}_setXY(e,t){if(this._checkDisposed(),this._checkImmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");this._validate(),(this.zpp_inner.x!==e||this.zpp_inner.y!==t)&&(this.zpp_inner.x=e,this.zpp_inner.y=t,this._invalidate())}static _poolGet(e,t,n){let l;if(ue.poolVec2==null?l=new Ue:(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 s;ie.zpp_pool==null?s=new ie:(s=ie.zpp_pool,ie.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,l.zpp_inner=s,s.outer=l}else l.zpp_inner.immutable(),l.zpp_inner.validate(),(l.zpp_inner.x!==e||l.zpp_inner.y!==t)&&(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner.invalidate());return l.zpp_inner.weak=n,l}static _wrap(e){return e instanceof Ue?e:e?e instanceof ie?ve(e,t=>{let n=Object.create(Ue.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?Ue._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 Ue._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 Ue._poolGet(e,t,!0)}static fromPolar(e,t,n=!1){if(e!==e)throw new Error("Error: Vec2::length cannot be NaN");if(t!==t)throw new Error("Error: Vec2::angle cannot be NaN");let l=e*Math.cos(t),s=e*Math.sin(t);return Ue._poolGet(l,s,n)}static fromAngle(e,t=!1){return Ue.fromPolar(1,e,t)}static lerp(e,t,n,l=!1){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot lerp with null Vec2");if(n!==n)throw new Error("Error: Cannot lerp with NaN t");e.zpp_inner.validate(),t.zpp_inner.validate();let s=e.zpp_inner.x+n*(t.zpp_inner.x-e.zpp_inner.x),i=e.zpp_inner.y+n*(t.zpp_inner.y-e.zpp_inner.y),r=Ue._poolGet(s,i,l);return Ue._disposeWeak(e),Ue._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&&Ue._disposeWeak(e),t!=null&&Ue._disposeWeak(t),r}e.zpp_inner.validate(),t.zpp_inner.validate();let l=e.zpp_inner.x-t.zpp_inner.x,s=e.zpp_inner.y-t.zpp_inner.y,i=(l<0?-l:l)<=n&&(s<0?-s:s)<=n;return Ue._disposeWeak(e),Ue._disposeWeak(t),i}static dsq(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,l=e.zpp_inner.y;t.zpp_inner.validate();let s=t.zpp_inner.x,i=t.zpp_inner.y,r=n-s,o=l-i,a=r*r+o*o;return Ue._disposeWeak(e),Ue._disposeWeak(t),a}static distance(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,l=e.zpp_inner.y;t.zpp_inner.validate();let s=t.zpp_inner.x,i=t.zpp_inner.y,r=n-s,o=l-i,a=Math.sqrt(r*r+o*o);return Ue._disposeWeak(e),Ue._disposeWeak(t),a}get x(){return this._checkDisposed(),this._validate(),this.zpp_inner.x}set x(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.x!==e){if(e!==e)throw new Error("Error: Vec2::x cannot be NaN");this.zpp_inner.x=e,this._invalidate()}}get y(){return this._checkDisposed(),this._validate(),this.zpp_inner.y}set y(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.y!==e){if(e!==e)throw new Error("Error: Vec2::y cannot be NaN");this.zpp_inner.y=e,this._invalidate()}}get length(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return Math.sqrt(e*e+t*t)}set length(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::length cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,l=t*t+n*n;if(l===0)throw new Error("Error: Cannot set length of a zero vector");let s=e/Math.sqrt(l);this._setXY(t*s,n*s),this._invalidate()}get angle(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e===t&&e===0?0:Math.atan2(t,e)}set angle(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::angle cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,l=Math.sqrt(t*t+n*n),s=l*Math.cos(e),i=l*Math.sin(e);this._setXY(s,i)}lsq(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e*e+t*t}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");e.zpp_inner.validate();let t=e.zpp_inner.x,n=e.zpp_inner.y;return this._setXY(t,n),Ue._disposeWeak(e),this}setxy(e,t){return this._checkDisposed(),this._checkImmutable(),this._setXY(e,t),this}clone(){return this.copy()}equals(e,t=0){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)return!1;this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,l=this.zpp_inner.y-e.zpp_inner.y;return(n<0?-n:n)<=t&&(l<0?-l:l)<=t}copy(e=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y;return Ue._poolGet(t,n,e)}rotate(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Cannot rotate Vec2 by NaN");if(e%(Math.PI*2)!==0){let t=Math.sin(e),n=Math.cos(e),l=n*this.zpp_inner.x-t*this.zpp_inner.y;this.zpp_inner.y=this.zpp_inner.x*t+this.zpp_inner.y*n,this.zpp_inner.x=l,this._invalidate()}return this}reflect(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this._validate();let n=this.zpp_inner.x,l=this.zpp_inner.y;if(Math.sqrt(n*n+l*l)===0)throw new Error("Error: Cannot reflect in zero vector");let s=Ue._poolGet(n,l,!0);s.normalise();let i=e.sub(s.muleq(2*s.dot(e)),t);return Ue._disposeWeak(e),i}normalise(){this._checkDisposed(),this._checkImmutable(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y,n=e*e+t*t;if(Math.sqrt(n)===0)throw new Error("Error: Cannot normalise vector of length 0");let l=1/Math.sqrt(n);return this._setXY(e*l,t*l),this._invalidate(),this}unit(e=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,l=t*t+n*n;if(Math.sqrt(l)===0)throw new Error("Error: Cannot normalise vector of length 0");let s=1/Math.sqrt(l);return Ue._poolGet(t*s,n*s,e)}add(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x+e.zpp_inner.x,l=this.zpp_inner.y+e.zpp_inner.y,s=Ue._poolGet(n,l,t);return Ue._disposeWeak(e),s}addMul(e,t,n=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let l=this.zpp_inner.x+e.zpp_inner.x*t,s=this.zpp_inner.y+e.zpp_inner.y*t,i=Ue._poolGet(l,s,n);return Ue._disposeWeak(e),i}sub(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot subtract null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,l=this.zpp_inner.y-e.zpp_inner.y,s=Ue._poolGet(n,l,t);return Ue._disposeWeak(e),s}mul(e,t=!1){if(this._checkDisposed(),e!==e)throw new Error("Error: Cannot multiply with NaN");this._validate();let n=this.zpp_inner.x*e,l=this.zpp_inner.y*e;return Ue._poolGet(n,l,t)}addeq(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x+e.zpp_inner.x,n=this.zpp_inner.y+e.zpp_inner.y;return this._setXY(t,n),Ue._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),Ue._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 Ue._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 Ue._disposeWeak(e),t}perp(e=!1){this._checkDisposed(),this._validate();let t=-this.zpp_inner.y,n=this.zpp_inner.x;return Ue._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=ie.zpp_pool,ie.zpp_pool=e}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};Ue.__name__=["nape","geom","Vec2"];var Fe=Ue;ie._wrapFn=S=>ve(S,e=>{let t=Object.create(Fe.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Xo=oe();Xo.geom.Vec2=Fe;var _s=class _s{constructor(e=0,t=0,n=0){this.zpp_pool=null;this.zpp_disp=!1;let l=new Wi;this.zpp_inner=l,l.outer=this,l.x=e,l.y=t,l.z=n}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!")}_checkImmutable(){if(this.zpp_inner.immutable)throw new Error("Error: Vec3 is immutable")}static _wrap(e){return e instanceof _s?e:e?e instanceof Wi?ve(e,t=>{let n=Object.create(_s.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?_s._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=0){let l;return ue.poolVec3==null?l=new _s:(l=ue.poolVec3,ue.poolVec3=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===ue.nextVec3&&(ue.nextVec3=null)),l.setxyz(e,t,n),l.zpp_inner.immutable=!1,l.zpp_inner._validate=null,l}get x(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.x}set x(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e}get y(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.y}set y(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.y=e}get z(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.z}set z(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.z=e}get length(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return Math.sqrt(e*e+t*t+n*n)}set length(e){if(this._checkDisposed(),e!==e)throw new Error("Error: Vec3::length cannot be NaN");this.zpp_inner.validate();let{x:t,y:n,z:l}=this.zpp_inner,s=t*t+n*n+l*l;if(s===0)throw new Error("Error: Cannot set length of a zero vector");let i=e/Math.sqrt(s);this._checkImmutable(),this.zpp_inner.x=t*i,this.zpp_inner.y=n*i,this.zpp_inner.z=l*i}lsq(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return e*e+t*t+n*n}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot assign null Vec3");return e.zpp_inner.validate(),this.setxyz(e.zpp_inner.x,e.zpp_inner.y,e.zpp_inner.z)}setxyz(e,t,n){return this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e,this._checkImmutable(),this.zpp_inner.y=t,this._checkImmutable(),this.zpp_inner.z=n,this}equals(e,t=0){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)return!1;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,l=this.zpp_inner.y-e.zpp_inner.y,s=this.zpp_inner.z-e.zpp_inner.z;return(n<0?-n:n)<=t&&(l<0?-l:l)<=t&&(s<0?-s:s)<=t}clone(){return this._checkDisposed(),this.zpp_inner.validate(),_s.get(this.zpp_inner.x,this.zpp_inner.y,this.zpp_inner.z)}xy(e=!1){return this._checkDisposed(),this.zpp_inner.validate(),Fe.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+" }"}};_s.__name__=["nape","geom","Vec3"];var $e=_s;Wi._wrapFn=S=>ve(S,e=>{let t=Object.create($e.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Yn=class Yn{get _inner(){return this}constructor(e=1,t=0,n=0,l=1,s=0,i=0){let r=Ri.get();this.zpp_inner=r,r.outer=this;let o=["a","b","tx","c","d","ty"],a=[e,t,s,n,l,i];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,l,s,i)}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 Yn(t,-n,n,t,0,0)}static translation(e,t){return new Yn(1,0,0,1,e,t)}static scale(e,t){return new Yn(e,0,0,t,0,0)}static _wrap(e){return e instanceof Yn?e:e?e instanceof Ri?ve(e,t=>{let n=Object.create(Yn.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?Yn._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,l=e.zpp_inner,s=n.a-l.a,i=n.b-l.b,r=n.c-l.c,o=n.d-l.d,a=n.tx-l.tx,p=n.ty-l.ty;return(s<0?-s:s)<=t&&(i<0?-i:i)<=t&&(r<0?-r:r)<=t&&(o<0?-o:o)<=t&&(a<0?-a:a)<=t&&(p<0?-p:p)<=t}copy(){return new Yn(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,l=1,s=0,i=0){return this.zpp_inner.setas(e,t,n,l,s,i),this.zpp_inner.invalidate(),this}reset(){return this.setAs()}singular(){let{a:e,b:t,c:n,d:l}=this.zpp_inner,s=e*e+t*t+n*n+l*l,i=e*l-t*n;i<0&&(i=-i);let r=oe();return s>r.Config.illConditionedThreshold*i}inverse(){if(this.singular())throw new Error("Error: Matrix is singular and cannot be inverted");let{a:e,b:t,c:n,d:l,tx:s,ty:i}=this.zpp_inner,r=1/(e*l-t*n);return new Yn(l*r,-t*r,-n*r,e*r,(t*i-l*s)*r,(n*s-e*i)*r)}transpose(){let{a:e,b:t,c:n,d:l,tx:s,ty:i}=this.zpp_inner;return new Yn(e,n,t,l,-e*s-n*i,-t*s-l*i)}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 Yn(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 l=e.zpp_inner.x,s=e.zpp_inner.y,{a:i,b:r,c:o,d:a,tx:p,ty:c}=this.zpp_inner,u,h;t?(u=l*i+s*r,h=l*o+s*a):(u=l*i+s*r+p,h=l*o+s*a+c);let x=Fe.get(u,h,n);return e.zpp_inner.weak&&e.dispose(),x}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:l,b:s,c:i,d:r,tx:o,ty:a}=this.zpp_inner,p=1/(l*r-s*i);e.zpp_inner.validate();let c=e.zpp_inner.x,u=e.zpp_inner.y,h,x;if(t)h=(c*r-u*s)*p,x=(u*l-c*i)*p;else{let _=c-o,d=u-a;h=(_*r-d*s)*p,x=(d*l-_*i)*p}let f=Fe.get(h,x,n);return e.zpp_inner.weak&&e.dispose(),f}equiorthogonal(){if(this.singular())return!1;let{a:e,b:t,c:n,d:l}=this.zpp_inner,s=oe(),i=e*t+n*l;if(i*i>=s.Config.epsilon)return!1;let r=e*e+t*t-n*n-l*l;return r*r<s.Config.epsilon}orthogonal(){let{a:e,b:t,c:n,d:l}=this.zpp_inner,s=oe(),i=e*t+n*l;if(i*i>=s.Config.epsilon)return!1;let r=e*e+t*t-1,o=n*n+l*l-1;return r*r<s.Config.epsilon&&o*o<s.Config.epsilon}_orthogonaliseImpl(e){let{a:t,b:n,c:l,d:s}=this.zpp_inner,i=oe(),r=Math.sqrt(t*t+l*l),o=Math.sqrt(n*n+s*s);if(r*r<i.Config.epsilon||o*o<i.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 u=Math.sin(c),h=Math.cos(c),x=this.zpp_inner.a*h-this.zpp_inner.c*u,f=this.zpp_inner.b*h+this.zpp_inner.d*u,_=this.zpp_inner.c*h+this.zpp_inner.a*u,d=this.zpp_inner.d*h-this.zpp_inner.b*u;return this.c=_,this.a=x,this.d=d,this.b=f,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:l,tx:s,ty:i}=this.zpp_inner;return"{ a: "+e+" b: "+t+" c: "+n+" d: "+l+" tx: "+s+" ty: "+i+" }"}};Yn.__name__=["nape","geom","Mat23"];var El=Yn;Ri._wrapFn=S=>ve(S,e=>{let t=Object.create(El.prototype);return t.zpp_inner=e,e.outer=t,t});var Yi=class Yi{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 ss(e,t),this.zpp_inner.outer=this}static _wrap(e){return e instanceof Yi?e:e?e instanceof ss?ve(e,t=>{let n=Object.create(Yi.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?Yi._wrap(e.zpp_inner):null:null}get rows(){return this.zpp_inner.m}get cols(){return this.zpp_inner.n}x(e,t){if(e<0||t<0||e>=this.zpp_inner.m||t>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return this.zpp_inner.x[e*this.zpp_inner.n+t]}setx(e,t,n){if(e<0||t<0||e>=this.zpp_inner.m||t>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return this.zpp_inner.x[e*this.zpp_inner.n+t]=n}equals(e,t=0){if(e==null||this.zpp_inner.m!==e.zpp_inner.m||this.zpp_inner.n!==e.zpp_inner.n)return!1;for(let n=0;n<this.zpp_inner.x.length;n++){let l=this.zpp_inner.x[n]-e.zpp_inner.x[n];if((l<0?-l:l)>t)return!1}return!0}clone(){let e=new Yi(this.zpp_inner.m,this.zpp_inner.n);for(let t=0;t<this.zpp_inner.x.length;t++)e.zpp_inner.x[t]=this.zpp_inner.x[t];return e}toString(){let e="{ ",t=!0;for(let n=0;n<this.zpp_inner.m;n++){t||(e+="; "),t=!1;for(let l=0;l<this.zpp_inner.n;l++){if(n<0||l<0||n>=this.zpp_inner.m||l>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");e+=this.zpp_inner.x[n*this.zpp_inner.n+l]+" "}}return e+="}",e}transpose(){let e=new Yi(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 Yi(this.zpp_inner.m,t.zpp_inner.n);for(let l=0;l<this.zpp_inner.m;l++)for(let s=0;s<t.zpp_inner.n;s++){let i=0;for(let r=0;r<this.zpp_inner.n;r++)i+=this.zpp_inner.x[l*this.zpp_inner.n+r]*t.zpp_inner.x[r*t.zpp_inner.n+s];n.zpp_inner.x[l*n.zpp_inner.n+s]=i}return n}};Yi.__name__=["nape","geom","MatMN"];var Ai=Yi,Ho=oe();Ho.geom.MatMN=Ai;var Js=class Js{get _inner(){return this}constructor(e=0,t=0,n=0,l=0){if(e!==e||t!==t)throw new Error("Error: AABB position cannot be NaN");if(n!==n||l!==l)throw new Error("Error: AABB dimensions cannot be NaN");let s;fe.zpp_pool==null?s=new fe:(s=fe.zpp_pool,fe.zpp_pool=s.next,s.next=null),s.minx=e,s.miny=t,s.maxx=e+n,s.maxy=t+l,this.zpp_inner=s,s.outer=this}static fromPoints(e){if(e==null||e.length===0)throw new Error("Error: AABB::fromPoints requires at least one point");let t=e[0];if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");t.zpp_inner.validate();let n=t.zpp_inner.x,l=t.zpp_inner.y,s=n,i=l;for(let 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<l&&(l=p),a>s&&(s=a),p>i&&(i=p)}return new Js(n,l,s-n,i-l)}static _wrap(e){return e instanceof Js?e:e?e instanceof fe?ve(e,t=>{let n=Object.create(Js.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?Js._wrap(e.zpp_inner):null:null}get x(){return this.zpp_inner.validate(),this.zpp_inner.minx}set x(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::x cannot be NaN");this.zpp_inner.maxx+=e-this.zpp_inner.minx,this.zpp_inner.minx=e,this.zpp_inner.invalidate()}}get y(){return this.zpp_inner.validate(),this.zpp_inner.miny}set y(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::y cannot be NaN");this.zpp_inner.maxy+=e-this.zpp_inner.miny,this.zpp_inner.miny=e,this.zpp_inner.invalidate()}}get width(){return this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx}set width(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::width cannot be NaN");if(e<0)throw new Error("Error: AABB::width ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxx=this.zpp_inner.minx+e,this.zpp_inner.invalidate()}}get height(){return this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny}set height(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::height cannot be NaN");if(e<0)throw new Error("Error: AABB::height ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxy=this.zpp_inner.miny+e,this.zpp_inner.invalidate()}}get min(){return this.zpp_inner.getmin(),this.zpp_inner.wrap_min}set min(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::min");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::min components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::min components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.x;this.zpp_inner.getmax();let s=this.zpp_inner.wrap_max;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l>s.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let i=e.zpp_inner.y;this.zpp_inner.getmin();let 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(),i>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 l=e.zpp_inner.x;this.zpp_inner.getmin();let s=this.zpp_inner.wrap_min;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l<s.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let i=e.zpp_inner.y;this.zpp_inner.getmin();let 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(),i<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 l=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let s=t.zpp_inner.y;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=e.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let 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==l){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate(),r=e.zpp_inner.y==s}else r=!1;r||(e.zpp_inner.x=l,e.zpp_inner.y=s,e.zpp_inner._invalidate!=null&&e.zpp_inner._invalidate(e.zpp_inner))}_disposeVec2(e){let n=oe().zpp_nape;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let s=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let i=e;i.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=i:n.util.ZPP_PubPool.poolVec2=i,n.util.ZPP_PubPool.nextVec2=i,i.zpp_disp=!0;let r=s;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,l=this.zpp_inner.miny-e.zpp_inner.miny,s=this.zpp_inner.maxx-e.zpp_inner.maxx,i=this.zpp_inner.maxy-e.zpp_inner.maxy;return(n<0?-n:n)<=t&&(l<0?-l:l)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t}copy(){this.zpp_inner.validate();let e=this.zpp_inner;return fe.get(e.minx,e.miny,e.maxx,e.maxy).wrapper()}toString(){return this.zpp_inner.validate(),this.zpp_inner.toString()}};Js.__name__=["nape","geom","AABB"];var ri=Js;fe._wrapFn=S=>ve(S,e=>{let t=Object.create(ri.prototype);return t.zpp_inner=e,e.outer=t,t});var kl=class kl{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate Winding derp!")}static get UNDEFINED(){return T.Winding_UNDEFINED==null&&(T.internal=!0,T.Winding_UNDEFINED=new kl,T.internal=!1),T.Winding_UNDEFINED}static get CLOCKWISE(){return T.Winding_CLOCKWISE==null&&(T.internal=!0,T.Winding_CLOCKWISE=new kl,T.internal=!1),T.Winding_CLOCKWISE}static get ANTICLOCKWISE(){return T.Winding_ANTICLOCKWISE==null&&(T.internal=!0,T.Winding_ANTICLOCKWISE=new kl,T.internal=!1),T.Winding_ANTICLOCKWISE}toString(){return this===T.Winding_UNDEFINED?"UNDEFINED":this===T.Winding_CLOCKWISE?"CLOCKWISE":this===T.Winding_ANTICLOCKWISE?"ANTICLOCKWISE":""}};kl.__name__=["nape","geom","Winding"];var Nl=kl,Qo=oe();Qo.geom.Winding=Nl;function eo(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.x}function to(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Ol(S){S.zpp_inner.weak&&S.dispose()}var Us=class Us{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 vl;this.zpp_inner=n;let l=eo(e),s=to(e);n.origin.zpp_inner.x=l,n.origin.zpp_inner.y=s,n.origin.zpp_inner._invalidate!=null&&n.origin.zpp_inner._invalidate(n.origin.zpp_inner),Ol(e);let i=eo(t),r=to(t);n.direction.zpp_inner.x=i,n.direction.zpp_inner.y=r,n.direction.zpp_inner._invalidate!=null&&n.direction.zpp_inner._invalidate(n.direction.zpp_inner),Ol(t),n.zip_dir=!0,n.maxdist=1/0}static _wrap(e){return e==null?null:e instanceof Us?e:ve(e,t=>{let n=Object.create(Us.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),l=new Us(e,n),s=eo(e),i=to(e),r=eo(t),o=to(t),a=r-s,p=o-i,c=Math.sqrt(a*a+p*p);if(c!==c)throw new Error("Error: maxDistance cannot be NaN");return l.zpp_inner.maxdist=c,Ol(e),Ol(t),l}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),Ol(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,Ol(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 ri._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 l=n.x,s=n.y,i=l+e*this.zpp_inner.dirx,r=s+e*this.zpp_inner.diry;return Fe.get(i,r,t)}clone(){return this.copy()}copy(){let e=new Us(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}};Us.__name__=["nape","geom","Ray"];var Cr=Us;var Zr=class Zr{get _inner(){return this}constructor(){if(this.zpp_inner=null,!qt.internal)throw new Error("Error: ConvexResult cannot be instantiated derp!")}static _wrap(e){if(!e)return null;if(e instanceof Zr)return e;let t=e.zpp_inner??e;return ve(t,n=>{let l=Object.create(Zr.prototype);return l.zpp_inner=n,l})}get normal(){return this._disposed(),Fe._wrap(this.zpp_inner.normal)}get position(){return this._disposed(),Fe._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")}};Zr.__name__=["nape","geom","ConvexResult"];var Sl=Zr;qt._createConvexResult=()=>new Sl;var Mr=class Mr{get _inner(){return this}constructor(){if(this.zpp_inner=null,!qt.internal)throw new Error("Error: RayResult cannot be instantiated derp!")}static _wrap(e){if(!e)return null;if(e instanceof Mr)return e;let t=e.zpp_inner??e;return ve(t,n=>{let l=Object.create(Mr.prototype);return l.zpp_inner=n,l})}get normal(){return this._disposed(),Fe._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")}};Mr.__name__=["nape","geom","RayResult"];var Al=Mr;qt._createRayResult=()=>new Al;function Ks(S){return S?.zpp_inner??S?._inner?.zpp_inner}function no(S){return S?.zpp_inner??S?._inner?.zpp_inner}function io(S,e){if(S!=null&&S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=S.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");t._isimmutable!=null&&t._isimmutable()}function Vl(S,e){if(Ks(S)?.body?.outer==null)throw new Error(`Error: Shape must be part of a Body to calculate ${e}`)}var Il=class{static distanceBody(e,t,n,l){io(n,"out1"),io(l,"out2");let s=no(e),i=no(t);if(s.shapes.head==null||i.shapes.head==null)throw new Error("Error: Bodies cannot be empty in calculating distances");let r=s.shapes.head;for(;r!=null;)hn.validateShape(r.elt),r=r.next;for(r=i.shapes.head;r!=null;)hn.validateShape(r.elt),r=r.next;return un.distanceBody(s,i,n.zpp_inner,l.zpp_inner)}static distance(e,t,n,l){io(n,"out1"),io(l,"out2"),Vl(e,"distances"),Vl(t,"distances");let s=Ks(e),i=Ks(t);hn.validateShape(s),hn.validateShape(i);let r;ie.zpp_pool==null?r=new ie:(r=ie.zpp_pool,ie.zpp_pool=r.next,r.next=null),r.weak=!1;let o=un.distance(s,i,n.zpp_inner,l.zpp_inner,r,1e100);return r.next=ie.zpp_pool,ie.zpp_pool=r,o}static intersectsBody(e,t){let n=no(e),l=no(t);if(n.shapes.head==null||l.shapes.head==null)throw new Error("Error: Bodies must have shapes to test for intersection.");let s=n.shapes.head;for(;s!=null;)hn.validateShape(s.elt),s=s.next;for(s=l.shapes.head;s!=null;)hn.validateShape(s.elt),s=s.next;let i=n.aabb,r=l.aabb;if(i.minx>r.maxx||i.maxx<r.minx||i.miny>r.maxy||i.maxy<r.miny)return!1;let o=n.shapes.head;for(;o!=null;){let a=l.shapes.head;for(;a!=null;){if(Ne.testCollide_safe(o.elt,a.elt))return!0;a=a.next}o=o.next}return!1}static intersects(e,t){Vl(e,"intersection"),Vl(t,"intersection");let n=Ks(e),l=Ks(t);hn.validateShape(n),hn.validateShape(l);let s=n.aabb,i=l.aabb;return s.minx>i.maxx||s.maxx<i.minx||s.miny>i.maxy||s.maxy<i.miny?!1:Ne.testCollide_safe(n,l)}static contains(e,t){Vl(e,"containment"),Vl(t,"containment");let n=Ks(e),l=Ks(t);return hn.validateShape(n),hn.validateShape(l),Ne.containTest(n,l)}};Il.__name__=["nape","geom","Geom"];var wi=class wi{constructor(){this.ptr=null;this.start=null;this.first=!1;this.forward=!1;this.outer=null;this.next=null;wi.internal=!0;let e=oe();this.outer=new e.geom.GeomVertexIterator,wi.internal=!1}static get(e,t){let n;return wi.zpp_pool==null?n=new wi:(n=wi.zpp_pool,wi.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(){}};wi.__name__=["zpp_nape","geom","ZPP_GeomVertexIterator"],wi.zpp_pool=null,wi.internal=!1;var oi=wi;var it=class it{constructor(e){this.zpp_pool=null;this.zpp_disp=!1;this.zpp_inner=new Ds(this),e!=null&&(it._addVertices(this,e),this.skipForward(1),it._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 Ce.zpp_pool==null?n=new Ce:(n=Ce.zpp_pool,Ce.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=Ce.zpp_pool,Ce.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 s=t?e==="y"?"topmost":"leftmost":e==="y"?"bottommost":"rightmost";throw new Error("Error: empty GeomPoly has no defineable "+s+" vertex")}let n=this.zpp_inner.vertices,l=n.next;for(;l!==this.zpp_inner.vertices;)(t?l[e]<n[e]:l[e]>n[e])&&(n=l),l=l.next;return n.wrapper()}static _addVertices(e,t){let n=oe();if(t instanceof Array)for(let l=0;l<t.length;l++){let s=t[l];if(s==null)throw new Error("Error: Array<Vec2> contains null objects");if(!(s instanceof Fe))throw new Error("Error: Array<Vec2> contains non Vec2 objects");let i=s;if(i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.zpp_inner.validate();let r=i.zpp_inner.x;i.zpp_inner.validate();let o=i.zpp_inner.y,a=it._createVert(r,o);it._pushVert(e,a)}else if(t instanceof n.geom.Vec2List){let l=t.iterator();for(;l.hasNext();){let s=l.next();if(s==null)throw new Error("Error: Vec2List contains null objects");if(s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");s.zpp_inner.validate();let i=s.zpp_inner.x;s.zpp_inner.validate();let r=s.zpp_inner.y,o=it._createVert(i,r);it._pushVert(e,o)}}else if(t instanceof it){if(t.zpp_disp)throw new Error("Error: GeomPoly has been disposed and cannot be used!");let l=t.zpp_inner.vertices;if(l!=null){let s=l;do{let i=it._createVert(s.x,s.y);it._pushVert(e,i),s=s.next}while(s!==l)}}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 oe().geom.Vec2List){let t=e;t.zpp_inner._validate!=null&&t.zpp_inner._validate();let n=t.zpp_inner.inner,l=null,s=n.head;for(;s!=null;){let i=s.elt;i.outer&&i.outer.zpp_inner&&i.outer.zpp_inner.weak?(s=n.erase(l),i.outer.zpp_inner.weak&&i.outer.dispose()):(l=s,s=s.next)}}}static get(e){let t;return ue.poolGeomPoly==null?t=new it:(t=ue.poolGeomPoly,ue.poolGeomPoly=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t===ue.nextGeomPoly&&(ue.nextGeomPoly=null)),e!=null&&(it._addVertices(t,e),t.skipForward(1),it._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(),oi.get(this.zpp_inner.vertices,!0)}forwardIterator(){return this._checkDisposed(),oi.get(this.zpp_inner.vertices,!0)}backwardsIterator(){return this._checkDisposed(),oi.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,l=it._createVert(t,n);return it._pushVert(this,l),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 it._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,l=it._createVert(t,n);return it._unshiftVert(this,l),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 it._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),it._freeVert(t)}return this}clear(){for(this._checkDisposed();this.zpp_inner.vertices!=null;){let e=this._shiftHead();it._freeVert(e)}return this}copy(){this._checkDisposed();let e=it.get();return this._forEachVert(t=>{let n=it._createVert(t.x,t.y);it._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 T.Winding_UNDEFINED==null&&(T.internal=!0,T.Winding_UNDEFINED=new(oe()).geom.Winding,T.internal=!1),T.Winding_UNDEFINED;let e=0;this._forEachVert(n=>{e+=n.x*(n.next.y-n.prev.y)});let t=e*.5;return t>0?(T.Winding_CLOCKWISE==null&&(T.internal=!0,T.Winding_CLOCKWISE=new(oe()).geom.Winding,T.internal=!1),T.Winding_CLOCKWISE):t===0?(T.Winding_UNDEFINED==null&&(T.internal=!0,T.Winding_UNDEFINED=new(oe()).geom.Winding,T.internal=!1),T.Winding_UNDEFINED):(T.Winding_ANTICLOCKWISE==null&&(T.internal=!0,T.Winding_ANTICLOCKWISE=new(oe()).geom.Winding,T.internal=!1),T.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,l=!1;return this._forEachVert(s=>{let i=s.prev;(s.y<n&&i.y>=n||i.y<n&&s.y>=n)&&(s.x<=t||i.x<=t)&&s.x+(n-s.y)/(i.y-s.y)*(i.x-s.x)<t&&(l=!l)}),e.zpp_inner.weak&&e.dispose(),l}isClockwise(){let e=this.winding();return T.Winding_CLOCKWISE==null&&(T.internal=!0,T.Winding_CLOCKWISE=new(oe()).geom.Winding,T.internal=!1),e===T.Winding_CLOCKWISE}isConvex(){if(this._checkDisposed(),this._isDegenRing())return!0;let e=!1,t=!1,n=!0,l=this.zpp_inner.vertices,s=l;do{let i=s,r=i.prev,o=i.next,a=o.x-i.x,p=o.y-i.y,c=i.x-r.x,h=(i.y-r.y)*a-c*p;if(h>0?t=!0:h<0&&(e=!0),t&&e){n=!1;break}s=s.next}while(s!==l);return n}isSimple(){return this._checkDisposed(),this._isDegenRing()?!0:ps.isSimple(this.zpp_inner.vertices)}isMonotone(){return this._checkDisposed(),this._isDegenRing()?!0:on.isMonotone(this.zpp_inner.vertices)}isDegenerate(){return this._checkDisposed(),this._isDegenRing()?!0:this.area()<oe().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=gl.simplify(this.zpp_inner.vertices,e),n=it.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=oe(),n=this.zpp_inner.vertices;He.sharedGVList==null&&(He.sharedGVList=new hi);let l=ps.decompose(n,He.sharedGVList),s=e??new t.geom.GeomPolyList;for(;l.head!=null;){let i=l.pop_unsafe(),r=it.get();r.zpp_inner.vertices=i,s.zpp_inner.reverse_flag?s.push(r):s.unshift(r)}return s}monotoneDecomposition(e){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let t=oe(),n=this.zpp_inner.vertices;on.sharedPPoly==null&&(on.sharedPPoly=new He);let l=on.decompose(n,on.sharedPPoly);He.sharedGVList==null&&(He.sharedGVList=new hi);let s=l.extract(He.sharedGVList),i=e??new t.geom.GeomPolyList;for(;s.head!=null;){let r=s.pop_unsafe(),o=it.get();o.zpp_inner.vertices=r,i.zpp_inner.reverse_flag?i.push(o):i.unshift(o)}return i}convexDecomposition(e=!1,t){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let n=oe(),l=this.zpp_inner.vertices;on.sharedPPoly==null&&(on.sharedPPoly=new He);let s=on.decompose(l,on.sharedPPoly);He.sharedPPList==null&&(He.sharedPPList=new ks);let i=s.extract_partitions(He.sharedPPList),r=t??new n.geom.GeomPolyList;for(;i.head!=null;){let o=i.pop_unsafe();qi.triangulate(o),e&&qi.optimise(o),zl.optimise(o),He.sharedGVList==null&&(He.sharedGVList=new hi);let a=o.extract(He.sharedGVList),p=o;for(p.next=He.zpp_pool,He.zpp_pool=p;a.head!=null;){let c=a.pop_unsafe(),u=it.get();u.zpp_inner.vertices=c,r.zpp_inner.reverse_flag?r.push(u):r.unshift(u)}}return r}triangularDecomposition(e=!1,t){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let n=oe(),l=this.zpp_inner.vertices;on.sharedPPoly==null&&(on.sharedPPoly=new He);let s=on.decompose(l,on.sharedPPoly);He.sharedPPList==null&&(He.sharedPPList=new ks);let i=s.extract_partitions(He.sharedPPList),r=t??new n.geom.GeomPolyList;for(;i.head!=null;){let o=i.pop_unsafe();qi.triangulate(o),e&&qi.optimise(o),He.sharedGVList==null&&(He.sharedGVList=new hi);let a=o.extract(He.sharedGVList),p=o;for(p.next=He.zpp_pool,He.zpp_pool=p;a.head!=null;){let c=a.pop_unsafe(),u=it.get();u.zpp_inner.vertices=c,r.zpp_inner.reverse_flag?r.push(u):r.unshift(u)}}return r}inflate(e){this._checkDisposed();let t=it.get();return this.isClockwise()&&(e=-e),this._forEachVert(n=>{let l=n.prev,s=n.next,i=n.x-l.x,r=n.y-l.y,o=s.x-n.x,a=s.y-n.y,p=Math.sqrt(i*i+r*r),c=-r/p*e,u=i/p*e,h=Math.sqrt(o*o+a*a),x=-a/h*e,f=o/h*e,_=x-c,d=f-u,b=a*_-o*d,m=b===0?0:b/(a*i-o*r),z=n.x+c+i*m,M=n.y+u+r*m,y=Fe.get(z,M);t.push(y)}),t.skipForward(1)}cut(e,t,n=!1,l=!1,s){if(this._checkDisposed(),!(this._isDegenRing()||ps.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 i=Pl.run(this.zpp_inner.vertices,e,t,n,l,s);return e.zpp_inner.weak&&e.dispose(),t.zpp_inner.weak&&t.dispose(),i}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,l=-1e100;return this._forEachVert(s=>{s.x<e&&(e=s.x),s.y<t&&(t=s.y),s.x>n&&(n=s.x),s.y>l&&(l=s.y)}),new ri(e,t,n-e,l-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+"]"}};it.__name__=["nape","geom","GeomPoly"];var Er=it;var Tl=class{static run(e,t,n,l=2,s=null,i=!0,r=null){if(n!=null&&n.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!");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(l<0)throw new Error("Error: MarchingSquares cannot use a negative quality value for interpolation");if(s!=null){let h=s.zpp_inner;if(h._validate!=null&&h._validate(),h.x<=0||h.y<=0)throw new Error("Error: MarchingSquares cannot with non-positive sub-grid dimensions")}let a=oe(),p=r??new a.geom.GeomPolyList,c=Fs,u=t.zpp_inner;if(u._validate!=null&&u._validate(),s==null){let h=u.minx,x=u.miny,f=u.maxx,_=u.maxy;c.run(e,h,x,f,_,n,l,i,p)}else{let h=s.zpp_inner;h._validate!=null&&h._validate();let x=u.maxx-u.minx,f=u.maxy-u.miny,_=x/h.x,d=f/h.y,b=_|0,m=d|0;b!==_&&++b,m!==d&&++m;for(let z=0;z<b;z++){let M=u.minx+h.x*z,y=z===b-1?u.maxx:M+h.x;for(let w=0;w<m;w++){let v=u.miny+h.y*w,P=w===m-1?u.maxy:v+h.y;c.run(e,M,v,y,P,n,l,i,p)}}}return o.weak&&n.dispose(),s!=null&&s.zpp_inner.weak&&s.dispose(),p}};Tl.__name__=["nape","geom","MarchingSquares"];var Xi=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 _o,this._invalidated=!0}static get(e,t){t==null&&(t=!1);let n=oe(),l=new n.geom.Vec2List;return l.zpp_inner.inner=e,t&&(l.zpp_inner.immutable=!0),l.zpp_inner.zip_length=!0,l}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)}};Xi.__name__=["zpp_nape","util","ZPP_Vec2List"],Xi.internal=!1;function Ys(S){if(S.outer==null){let e=oe();S.outer=new e.geom.Vec2;let t=S.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=ie.zpp_pool,ie.zpp_pool=t,S.outer.zpp_inner=S}return S.outer}function Et(){if(this.zpp_next=null,this.zpp_critical=!1,this.zpp_i=0,this.zpp_inner=null,!Xi.internal)throw new Error("Error: Cannot instantiate Vec2Iterator derp!")}Et.__name__=["nape","geom","Vec2Iterator"];Et.zpp_pool=null;Et.get=function(S){let e;return Et.zpp_pool==null?(Xi.internal=!0,e=new Et,Xi.internal=!1):(e=Et.zpp_pool,Et.zpp_pool=e.zpp_next),e.zpp_i=0,e.zpp_inner=S,e.zpp_critical=!1,e};Et.prototype.zpp_inner=null;Et.prototype.zpp_i=null;Et.prototype.zpp_critical=null;Et.prototype.zpp_next=null;Et.prototype.hasNext=function(){this.zpp_inner.zpp_inner.valmod();let S=this.zpp_inner.zpp_gl();return this.zpp_critical=!0,this.zpp_i<S?!0:(this.zpp_next=Et.zpp_pool,Et.zpp_pool=this,this.zpp_inner=null,!1)};Et.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 Xi,this.zpp_inner.outer=this}ht.__name__=["nape","geom","Vec2List"];ht.fromArray=function(S){if(S==null)throw new Error("Error: Cannot convert null Array to Nape list");let e=oe(),t=new e.geom.Vec2List;for(let n=0;n<S.length;n++)t.push(S[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(S){return this.zpp_vm(),this.zpp_inner.inner.has(S.zpp_inner)};ht.prototype.at=function(S){if(this.zpp_vm(),S<0||S>=this.zpp_gl())throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(S=this.zpp_gl()-1-S),S<this.zpp_inner.at_index||this.zpp_inner.at_ite==null)this.zpp_inner.at_index=S,this.zpp_inner.at_ite=this.zpp_inner.inner.iterator_at(S);else for(;this.zpp_inner.at_index!=S;)this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;return Ys(this.zpp_inner.at_ite.elt)};ht.prototype.push=function(S){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(S):!0;return e&&(this.zpp_inner.reverse_flag?this.zpp_inner.inner.add(S.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,S.zpp_inner)),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(S)),e};ht.prototype.unshift=function(S){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(S):!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,S.zpp_inner)):this.zpp_inner.inner.add(S.zpp_inner),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(S)),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 S;if(this.zpp_inner.reverse_flag){S=this.zpp_inner.inner.head.elt;let e=Ys(S);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);S=e==null?this.zpp_inner.inner.head.elt:e.next.elt;let t=Ys(S);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(),Ys(S)};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 S;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);S=e==null?this.zpp_inner.inner.head.elt:e.next.elt;let t=Ys(S);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(e)}else{S=this.zpp_inner.inner.head.elt;let e=Ys(S);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}return this.zpp_inner.invalidate(),Ys(S)};ht.prototype.add=function(S){return this.zpp_inner.reverse_flag?this.push(S):this.unshift(S)};ht.prototype.remove=function(S){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==S.zpp_inner){e=!0;break}t=t.next}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(S),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(S.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(),Et.get(this)};ht.prototype.copy=function(S){S==null&&(S=!1);let e=oe(),t=new e.geom.Vec2List,n=Et.get(this);for(;n.hasNext();){let l=n.next(),s;if(S){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=l.zpp_inner;i._validate!=null&&i._validate();let r=l.zpp_inner.x,o=l.zpp_inner;o._validate!=null&&o._validate();let a=l.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;ie.zpp_pool==null?c=new ie:(c=ie.zpp_pool,ie.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,s=p}else s=l;t.push(s)}return t};ht.prototype.merge=function(S){if(S==null)throw new Error("Error: Cannot merge with null list");let e=S.iterator();for(;e.hasNext();){let t=e.next();this.has(t)||this.add(t)}};ht.prototype.toString=function(){let S="[",e=!0,t=Et.get(this);for(;t.hasNext();){let n=t.next();e||(S+=","),S+=n==null?"NULL":n.toString(),e=!1}return S+"]"};ht.prototype.foreach=function(S){if(S==null)throw new Error("Error: Cannot execute null on list elements");let e=this.iterator();for(;e.hasNext();)try{S(e.next())}catch{e.zpp_next=Et.zpp_pool,Et.zpp_pool=e,e.zpp_inner=null;break}return this};ht.prototype[Symbol.iterator]=function(){let S=Et.get(this);return{next(){return S.hasNext()?{value:S.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};ht.prototype.filter=function(S){if(S==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{S(t)?++e:this.remove(t)}catch{break}}return this};function xs(){if(!oi.internal)throw new Error("Error: Cannot instantiate GeomVertexIterator")}xs.__name__=["nape","geom","GeomVertexIterator"];xs.prototype.zpp_inner=null;xs.prototype.hasNext=function(){if(this.zpp_inner==null)throw new Error("Error: Iterator has been disposed");let S=this.zpp_inner.ptr!=this.zpp_inner.start||this.zpp_inner.first;if(this.zpp_inner.first=!1,!S){let e=this.zpp_inner;e.outer.zpp_inner=null,e.ptr=e.start=null,e.next=oi.zpp_pool,oi.zpp_pool=e}return S};xs.prototype.next=function(){if(this.zpp_inner==null)throw new Error("Error: Iterator has been disposed");let S=this.zpp_inner.ptr;if(S.wrap==null){let t=S.x,n=S.y;if(t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");let l=oe(),s;if(ue.poolVec2==null?s=new l.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;ie.zpp_pool==null?i=new ie:(i=ie.zpp_pool,ie.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=t,i.y=n,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(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(),i.x==t&&i.y==n||(i.x=t,i.y=n,i._invalidate!=null&&i._invalidate(i))}s.zpp_inner.weak=!1,S.wrap=s,S.wrap.zpp_inner._inuse=!0,S.wrap.zpp_inner._invalidate=i=>S.modwrap(i),S.wrap.zpp_inner._validate=()=>S.getwrap()}let e=S.wrap;return this.zpp_inner.ptr=this.zpp_inner.forward?this.zpp_inner.ptr.next:this.zpp_inner.ptr.prev,e};xs.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 $o=oe();$o.geom.GeomVertexIterator=xs;var vi=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=oe(),l=new n.dynamics.ContactList;return l.zpp_inner.inner=e,t&&(l.zpp_inner.immutable=!0),l.zpp_inner.zip_length=!0,l}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)}};vi.__name__=["zpp_nape","util","ZPP_ContactList"],vi.internal=!1;var kr,Nr,Or;function so(S){kr=S}function ko(S){Nr=S}function No(S){Or=S}var Sr=class Sr{constructor(){this._inner=void 0,this.zpp_inner_i=null}static _wrap(e){return e?e instanceof Sr?e:e.isBody&&e.isBody()&&kr?kr(e):e.isShape&&e.isShape()&&Nr?Nr(e):e.isCompound&&e.isCompound()&&Or?Or(e):ve(e,t=>{let n=Object.create(Sr.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 kr?kr(e):e}return null}get castShape(){if(this.zpp_inner_i.ishape!=null){let e=this.zpp_inner_i.ishape.outer;return Nr?Nr(e):e}return null}get castCompound(){if(this.zpp_inner_i.icompound!=null){let e=this.zpp_inner_i.icompound.outer;return Or?Or(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""}};Sr.zpp_internalAlloc=!1;var Xn=Sr;var Ar=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 Xs=class Xs{get _inner(){return this}constructor(e=1,t=1){let n;if(Jn.zpp_pool==null?n=new Jn:(n=Jn.zpp_pool,Jn.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 Xs?e:e?e instanceof Jn?ve(e,t=>{let n=Object.create(Xs.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?Xs._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=oe().zpp_nape;if(e==null){if(this.zpp_inner.wrap_gravity!=null){this.zpp_inner.wrap_gravity.zpp_inner._inuse=!1;let l=this.zpp_inner.wrap_gravity;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),l.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let i=l.zpp_inner;l.zpp_inner.outer=null,l.zpp_inner=null;let r=l;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=i;o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o,this.zpp_inner.wrap_gravity=null}}else{if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity();let l=this.zpp_inner.wrap_gravity;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=e.zpp_inner;i._validate!=null&&i._validate();let 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(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),r!=r||a!=a)throw new Error("Error: Vec2 components cannot be NaN");let c;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=l.zpp_inner;if(u._validate!=null&&u._validate(),l.zpp_inner.x==r){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=l.zpp_inner;h._validate!=null&&h._validate(),c=l.zpp_inner.y==a}else c=!1;if(!c){l.zpp_inner.x=r,l.zpp_inner.y=a;let h=l.zpp_inner;h._invalidate!=null&&h._invalidate(h)}if(e.zpp_inner.weak){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=e.zpp_inner;if(h._immutable)throw new Error("Error: Vec2 is immutable");if(h._isimmutable!=null&&h._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let x=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let f=e;f.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=f:n.util.ZPP_PubPool.poolVec2=f,n.util.ZPP_PubPool.nextVec2=f,f.zpp_disp=!0;let _=x;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=_}}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get shapes(){if(this.zpp_inner.wrap_shapes==null){let e=oe();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=oe().zpp_nape,n=new Xs(this.zpp_inner.density*1e3,this.zpp_inner.viscosity);this.zpp_inner.userData!=null&&(n.zpp_inner.userData={...this.zpp_inner.userData});let l=this.zpp_inner.wrap_gravity;if(l==null){if(n.zpp_inner.wrap_gravity!=null){n.zpp_inner.wrap_gravity.zpp_inner._inuse=!1;let s=n.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),s.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let r=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let o=s;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(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");n.zpp_inner.wrap_gravity==null&&n.zpp_inner.getgravity();let s=n.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),l==null)throw new Error("Error: Cannot assign null Vec2");if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;r._validate!=null&&r._validate();let o=l.zpp_inner.x;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;a._validate!=null&&a._validate();let p=l.zpp_inner.y;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=s.zpp_inner;if(c._immutable)throw new Error("Error: Vec2 is immutable");if(c._isimmutable!=null&&c._isimmutable(),o!=o||p!=p)throw new Error("Error: Vec2 components cannot be NaN");let u;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=s.zpp_inner;if(h._validate!=null&&h._validate(),s.zpp_inner.x==o){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=s.zpp_inner;x._validate!=null&&x._validate(),u=s.zpp_inner.y==p}else u=!1;if(!u){s.zpp_inner.x=o,s.zpp_inner.y=p;let x=s.zpp_inner;x._invalidate!=null&&x._invalidate(x)}if(l.zpp_inner.weak){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=l.zpp_inner;if(x._immutable)throw new Error("Error: Vec2 is immutable");if(x._isimmutable!=null&&x._isimmutable(),l.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let f=l.zpp_inner;l.zpp_inner.outer=null,l.zpp_inner=null;let _=l;_.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=_:t.util.ZPP_PubPool.poolVec2=_,t.util.ZPP_PubPool.nextVec2=_,_.zpp_disp=!0;let d=f;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=d}}return n}toString(){return"{ density: "+this.zpp_inner.density*1e3+" viscosity: "+this.zpp_inner.viscosity+" gravity: "+String(this.zpp_inner.wrap_gravity)+" }"}};Xs.__name__=["nape","phys","FluidProperties"];var ai=Xs;Jn._wrapFn=S=>ve(S,e=>{let t=Object.create(ai.prototype);return t.zpp_inner=e,e.outer=t,t});var ea=oe();ea.phys.FluidProperties=ai;var Vr=class Vr{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate ShapeType derp!")}static get CIRCLE(){return T.ShapeType_CIRCLE==null&&(T.internal=!0,T.ShapeType_CIRCLE=new Vr,T.internal=!1),T.ShapeType_CIRCLE}static get POLYGON(){return T.ShapeType_POLYGON==null&&(T.internal=!0,T.ShapeType_POLYGON=new Vr,T.internal=!1),T.ShapeType_POLYGON}toString(){return this===T.ShapeType_CIRCLE?"CIRCLE":this===T.ShapeType_POLYGON?"POLYGON":""}};Vr.__name__=["nape","shape","ShapeType"];var Bl=Vr,ta=oe();ta.shape.ShapeType=Bl;li();var Ir,Tr;function Oo(S){Ir=S}function So(S){Tr=S}var Tn=class S extends Xn{constructor(){super()}static _wrap(e){if(!e)return null;let t=e.isCircle?e.isCircle()?0:e.isPolygon?.()?1:-1:e.zpp_inner?.type??-1;return t===0&&Ir?Ir(e):t===1&&Tr?Tr(e):e.outer?e.outer:ve(e,n=>{let l=Object.create(S.prototype);return l._inner=n,l.zpp_inner=n.zpp_inner??n,l.zpp_inner_i=n.zpp_inner_i??n,l})}get type(){return Ji.types[this.zpp_inner.type]}isCircle(){return this.zpp_inner.type===0}isPolygon(){return this.zpp_inner.type===1}get body(){let e=this.zpp_inner;return e.body!=null?e.body.outer:null}set body(e){let t=this.zpp_inner;t.immutable_midstep("Shape::body");let n=t.body!=null?t.body.outer:null;if(n!==e&&(t.body!=null&&n.zpp_inner.wrap_shapes.remove(this),e!=null)){let l=e.zpp_inner.wrap_shapes;l.zpp_inner.reverse_flag?l.push(this):l.unshift(this)}}get castCircle(){let e=this.zpp_inner;if(e.type===0){let t=e.circle.outer_zn;return Ir?Ir(t):t}return null}get castPolygon(){let e=this.zpp_inner;if(e.type===1){let t=e.polygon.outer_zn;return Tr?Tr(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 ai().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 ai().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 ai;t.setFluid(n.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new ai().zpp_inner),t.fluidProperties.wrapper()}t.wake()}get sensorEnabled(){return this.zpp_inner.sensorEnabled}set sensorEnabled(e){let t=this.zpp_inner;t.immutable_midstep("Shape::sensorEnabled"),t.sensorEnabled=e,t.wake()}get bounds(){return this.zpp_inner.aabb.wrapper()}translate(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::translate()"),e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Cannot displace Shape by null Vec2");if(e.lsq()>0){let n=e.zpp_inner;n._validate!=null&&n._validate();let l=n.x;n._validate!=null&&n._validate();let s=n.y;(t.type===0?t.circle:t.polygon).__translate(l,s)}return e.zpp_inner.weak&&e.dispose(),this}scale(e,t){let n=this.zpp_inner,l=oe();if(n.immutable_midstep("Shape::scale()"),n.body!=null&&n.body.space!=null&&n.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e!==e||t!==t)throw new Error("Error: Cannot scale Shape by NaN");if(e===0||t===0)throw new Error("Error: Cannot Scale shape by a factor of 0");if(n.type===0){let s=e*e-t*t;if(s*s<l.Config.epsilon*l.Config.epsilon)n.circle.__scale(e,t);else throw new Error("Error: Cannot perform a non equal scaling on a Circle")}else n.polygon.__scale(e,t);return this}rotate(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::rotate()"),t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e!==e)throw new Error("Error: Cannot rotate Shape by NaN");if(e%(2*Math.PI)!==0){let l=Math.cos(e),s=Math.sin(e);t.type===0?t.circle.__rotate(s,l):t.polygon.__rotate(s,l)}return this}transform(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::transform()"),t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Cannot transform Shape by null matrix");let n=e._inner??e;if(n.singular())throw new Error("Error: Cannot transform Shape by a singular matrix");if(t.type===0)if(n.equiorthogonal())t.circle.__transform(n);else throw new Error("Error: Cannot transform Circle by a non equiorthogonal matrix");else t.polygon.__transform(n);return this}contains(e){let t=this.zpp_inner;if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Cannot check null point for containment");if((t.body!=null?t.body.outer:null)==null)throw new Error("Error: Shape is not well defined without a Body");hn.validateShape(t);let n=e.zpp_inner;n._validate!=null&&n._validate();let l=Ne.shapeContains(t,n);return n.weak&&e.dispose(),l}copy(){let e=this.zpp_inner.copy();return e instanceof S?e:S._wrap(e)}toString(){return(this.zpp_inner.type===0?"Circle":"Polygon")+"#"+this.zpp_inner_i.id}_setupWorldCOM(){let e=oe(),t=this.zpp_inner,n=t.worldCOMx,l=t.worldCOMy;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(ue.poolVec2==null?s=new e.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;ie.zpp_pool==null?i=new ie:(i=ie.zpp_pool,ie.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,t.wrap_worldCOM=s,t.wrap_worldCOM.zpp_inner._inuse=!0,t.wrap_worldCOM.zpp_inner._immutable=!0,t.wrap_worldCOM.zpp_inner._validate=t.getworldCOM.bind(t)}};var gi=class S{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 S?e:e instanceof Ki?e.outer?e.outer:ve(e,t=>{let n=Object.create(S.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?.outer?e.zpp_inner.outer:ve(e,t=>{let n=Object.create(S.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n}):null}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get gravity(){return this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity(),this.zpp_inner.wrap_gravity}set gravity(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Space::gravity cannot be null");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity(),this.zpp_inner.wrap_gravity.set(e),e.zpp_inner?.weak&&e.dispose()}get broadphase(){return this.zpp_inner.bphase.is_sweep?(T.Broadphase_SWEEP_AND_PRUNE==null&&(T.internal=!0,T.Broadphase_SWEEP_AND_PRUNE=new(oe()).space.Broadphase,T.internal=!1),T.Broadphase_SWEEP_AND_PRUNE):(T.Broadphase_DYNAMIC_AABB_TREE==null&&(T.internal=!0,T.Broadphase_DYNAMIC_AABB_TREE=new(oe()).space.Broadphase,T.internal=!1),T.Broadphase_DYNAMIC_AABB_TREE)}get sortContacts(){return this.zpp_inner.sortcontacts}set sortContacts(e){this.zpp_inner.sortcontacts=e}get worldAngularDrag(){return this.zpp_inner.global_ang_drag}set worldAngularDrag(e){if(e!==e)throw new Error("Error: Space::worldAngularDrag cannot be NaN");this.zpp_inner.global_ang_drag=e}get worldLinearDrag(){return this.zpp_inner.global_lin_drag}set worldLinearDrag(e){if(e!==e)throw new Error("Error: Space::worldLinearDrag cannot be NaN");this.zpp_inner.global_lin_drag=e}get compounds(){return this.zpp_inner.wrap_compounds}get bodies(){return this.zpp_inner.wrap_bodies}get liveBodies(){return this.zpp_inner.wrap_live}get constraints(){return this.zpp_inner.wrap_constraints}get liveConstraints(){return this.zpp_inner.wrap_livecon}get world(){return et._wrap(this.zpp_inner.__static)}get arbiters(){if(this.zpp_inner.wrap_arbiters==null){let e=new zi;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=oe(),n=this.zpp_inner.wrap_bodies;n.zpp_inner.valmod();let l=t.phys.BodyIterator.get(n);for(;;){l.zpp_inner.zpp_inner.valmod();let 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.BodyIterator.zpp_pool,t.phys.BodyIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,e(l.zpp_inner.at(l.zpp_i++))}let s=this.zpp_inner.wrap_compounds;s.zpp_inner.valmod();let i=t.phys.CompoundIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let r=i.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(i.zpp_critical=!0,i.zpp_i>=o){i.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1,i.zpp_inner.at(i.zpp_i++).visitBodies(e)}}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitConstraints");let t=oe(),n=this.zpp_inner.wrap_constraints;n.zpp_inner.valmod();let l=t.constraint.ConstraintIterator.get(n);for(;;){l.zpp_inner.zpp_inner.valmod();let 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.constraint.ConstraintIterator.zpp_pool,t.constraint.ConstraintIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,e(l.zpp_inner.at(l.zpp_i++))}let s=this.zpp_inner.wrap_compounds;s.zpp_inner.valmod();let i=t.phys.CompoundIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let r=i.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(i.zpp_critical=!0,i.zpp_i>=o){i.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1,i.zpp_inner.at(i.zpp_i++).visitConstraints(e)}}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitCompounds");let t=oe(),n=this.zpp_inner.wrap_compounds;n.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(n);for(;;){l.zpp_inner.zpp_inner.valmod();let s=l.zpp_inner;s.zpp_inner.valmod(),s.zpp_inner.zip_length&&(s.zpp_inner.zip_length=!1,s.zpp_inner.user_length=s.zpp_inner.inner.length);let i=s.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=i){l.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1;let r=l.zpp_inner.at(l.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,l=t.zpp_inner;if((n.body!=null?n.body.outer:null)==null||(l.body!=null?l.body.outer:null)==null)throw new Error("Error: Cannot evaluate interaction type for shapes not part of a Body");let s=n.body,i=l.body;if(s.type==1&&i.type==1||s.outer==i.outer)return null;let r=!1,o=s.constraints.head;for(;o!=null;){let h=o.elt;if(h.ignore&&h.pair_exists(s.id,i.id)){r=!0;break}o=o.next}let a;if(r)a=!1;else{let h=n;for(;h!=null&&h.group==null;)h.ishape!=null?h=h.ishape.body:h.icompound!=null?h=h.icompound.compound:h=h.ibody.compound;let x=h==null?null:h.group,f;if(x==null)f=!1;else{let _=l;for(;_!=null&&_.group==null;)_.ishape!=null?_=_.ishape.body:_.icompound!=null?_=_.icompound.compound:_=_.ibody.compound;let d=_==null?null:_.group;if(d==null)f=!1;else{let b=!1;for(;x!=null&&d!=null;){if(x==d){b=x.ignore;break}x.depth<d.depth?d=d.group:x=x.group}f=b}}a=!f}if(!a)return null;let p=n.filter,c=l.filter,u=s.imass==0&&i.imass==0&&s.iinertia==0&&i.iinertia==0;return(n.sensorEnabled||l.sensorEnabled)&&(p.sensorMask&c.sensorGroup)!=0&&(c.sensorMask&p.sensorGroup)!=0?(T.InteractionType_SENSOR==null&&(T.internal=!0,T.InteractionType_SENSOR=new(oe()).callbacks.InteractionType,T.internal=!1),T.InteractionType_SENSOR):(n.fluidEnabled||l.fluidEnabled)&&(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0&&!u?(T.InteractionType_FLUID==null&&(T.internal=!0,T.InteractionType_FLUID=new(oe()).callbacks.InteractionType,T.internal=!1),T.InteractionType_FLUID):(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!u?(T.InteractionType_COLLISION==null&&(T.internal=!0,T.InteractionType_COLLISION=new(oe()).callbacks.InteractionType,T.internal=!1),T.InteractionType_COLLISION):null}shapesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes under a null point :)");let l=e.zpp_inner;l._validate!=null&&l._validate();let s=l.x;l._validate!=null&&l._validate();let i=l.y,r=t==null?null:t.zpp_inner??t,o=this.zpp_inner.shapesUnderPoint(s,i,r,n);return l.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 l=e.zpp_inner;l._validate!=null&&l._validate();let s=l.x;l._validate!=null&&l._validate();let i=l.y,r=t==null?null:t.zpp_inner??t,o=this.zpp_inner.bodiesUnderPoint(s,i,r,n);return l.weak&&e.dispose(),o}shapesInAABB(e,t=!1,n=!0,l,s){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null AABB :)");let i=e.zpp_inner;if(i._validate!=null&&i._validate(),i.maxx-i.minx==0||i.maxy-i.miny==0)throw new Error("Error: Cannot evaluate shapes in degenerate AABB :/");let r=l==null?null:l.zpp_inner??l;return this.zpp_inner.shapesInAABB(e,n,t,r,s)}bodiesInAABB(e,t=!1,n=!0,l,s){if(e==null)throw new Error("Error: Cannot evaluate objects in a null AABB :)");let i=e.zpp_inner;if(i._validate!=null&&i._validate(),i.maxx-i.minx==0||i.maxy-i.miny==0)throw new Error("Error: Cannot evaluate objects in degenerate AABB :/");let r=l==null?null:l.zpp_inner??l;return this.zpp_inner.bodiesInAABB(e,n,t,r,s)}shapesInCircle(e,t,n=!1,l,s){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let i=l==null?null:l.zpp_inner??l,r=this.zpp_inner.shapesInCircle(e,t,n,i,s);return e.zpp_inner?.weak&&e.dispose(),r}bodiesInCircle(e,t,n=!1,l,s){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let i=l==null?null:l.zpp_inner??l,r=this.zpp_inner.bodiesInCircle(e,t,n,i,s);return e.zpp_inner?.weak&&e.dispose(),r}shapesInShape(e,t=!1,n,l){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null shapes :)");let s=e.zpp_inner;if((s.body!=null?s.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(s.type==1){let r=s.polygon.valid();if(T.ValidationResult_VALID==null&&(T.internal=!0,T.ValidationResult_VALID=new(oe()).shape.ValidationResult,T.internal=!1),r!=T.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+r.toString())}let i=n==null?null:n.zpp_inner??n;return this.zpp_inner.shapesInShape(s,t,i,l)}bodiesInShape(e,t=!1,n,l){if(e==null)throw new Error("Error: Cannot evaluate bodies in a null shapes :)");let s=e.zpp_inner;if((s.body!=null?s.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(s.type==1){let r=s.polygon.valid();if(T.ValidationResult_VALID==null&&(T.internal=!0,T.ValidationResult_VALID=new(oe()).shape.ValidationResult,T.internal=!1),r!=T.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+r.toString())}let i=n==null?null:n.zpp_inner??n;return this.zpp_inner.bodiesInShape(s,t,i,l)}shapesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let l=oe(),s=n??new l.shape.ShapeList,i=e.zpp_inner.wrap_shapes;i.zpp_inner.valmod();let r=l.shape.ShapeIterator.get(i);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=l.shape.ShapeIterator.zpp_pool,l.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,s)}return s}bodiesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let l=oe(),s=n??new l.phys.BodyList,i=e.zpp_inner.wrap_shapes;i.zpp_inner.valmod();let r=l.shape.ShapeIterator.get(i);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=l.shape.ShapeIterator.zpp_pool,l.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,s)}return s}convexCast(e,t,n=!1,l){if(e==null)throw new Error("Error: Cannot cast null shape :)");let s=e.zpp_inner;if((s.body!=null?s.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexCast(s,t,l,n)}convexMultiCast(e,t,n=!1,l,s){if(e==null)throw new Error("Error: Cannot cast null shape :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexMultiCast(i,t,l,n,s)}rayCast(e,t=!1,n){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayCast(e,t,n)}rayMultiCast(e,t=!1,n,l){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayMultiCast(e,t,n,l)}toString(){return`Space(bodies=${this.bodies.length})`}};var fo=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(S,e,t,n){let l=oe(),s=l.__zpp;class i extends fo{constructor(){super(),this.inner=new s.util[S]}static get(o,a=!1){let p=new l[e][t];return p.zpp_inner.inner=o,a&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}}return i.internal=!1,i.__name__=["zpp_nape","util",n],i.prototype.__class__=i,s.util[n]=i,i}var Br=null,bo=null,zo=null;Br=Hn("ZNPList_ZPP_Constraint","constraint","ConstraintList","ZPP_ConstraintList");Hn("ZNPList_ZPP_Body","phys","BodyList","ZPP_BodyList");bo=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");zo=Hn("ZNPList_ZPP_Arbiter","dynamics","ArbiterList","ZPP_ArbiterList");function Ci(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Zi(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.y}function pi(S){if(S!=null&&S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}function Qn(S){S.zpp_inner.weak&&S.dispose()}function Ll(S,e,t,n,l){if(pi(t),t==null)throw new Error("Error: Body::"+S+" cannot be null");return e==null&&n!=null&&(n(),e=l()),e.set(t),e}function lo(S,e,t){return Fe.get(S,e,t)}function Cn(S,e){return T[S]==null&&(T.internal=!0,T[S]=e(),T.internal=!1),T[S]}var ds=class ds extends Xn{constructor(t,n){super();this.debugDraw=!0;let l=new Wn;this.zpp_inner=l,l.outer=this,l.outer_i=this,this.zpp_inner_i=l,this._inner=this,n!=null?(pi(n),l.posx=Ci(n),l.posy=Zi(n)):(l.posx=0,l.posy=0);let s=oe(),i;if(t==null?i=Cn("BodyType_DYNAMIC",()=>new s.phys.BodyType):i=t,l.immutable_midstep("Body::type"),l.world)throw new Error("Error: Space::world is immutable");if(Wn.types[l.type]!==i){if(i==null)throw new Error("Error: Cannot use null BodyType");let r=Ao(i,s);r===1&&l.space!=null&&(l.velx=0,l.vely=0,l.angvel=0),l.invalidate_type(),l.space!=null?l.space.transmitType(l,r):l.type=r}n!=null&&Qn(n),l.insert_cbtype(zt.ANY_BODY.zpp_inner)}static _wrap(t){return t?t instanceof ds?t:t instanceof Wn?ve(t,n=>{let l=Object.create(ds.prototype);return l.zpp_inner=n,n.outer=l,n.outer_i=l,l.zpp_inner_i=n,l._inner=l,l.debugDraw=!0,l}):t.zpp_inner?ds._wrap(t.zpp_inner):ve(t,n=>{let l=Object.create(ds.prototype);return l._inner=n,l}):null}get type(){return Wn.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(Wn.types[n.type]!==t){if(t==null)throw new Error("Error: Cannot use null BodyType");let l=oe(),s=Ao(t,l);s===1&&n.space!=null&&(n.velx=0,n.vely=0,n.angvel=0),n.invalidate_type(),n.space!=null?n.space.transmitType(n,s):n.type=s}}isStatic(){return this.zpp_inner.type===1}isDynamic(){return this.zpp_inner.type===2}isKinematic(){return this.zpp_inner.type===3}get position(){return this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),this.zpp_inner.wrap_pos}set position(t){Ll("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){Ll("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){Ll("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){Ll("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){Ll("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 Ar(this.zpp_inner.wrap_shapes,Tn._wrap)}get space(){return this.zpp_inner.space==null?null:gi._wrap(this.zpp_inner.space.outer)}set space(t){let n=t!=null?t._inner??t:null;if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let l=this.zpp_inner.space==null?null:this.zpp_inner.space.outer;if(l!==n&&(l!=null&&(this.zpp_inner.component.woken=!1,l.zpp_inner.wrap_bodies.remove(this)),n!=null)){let s=n.zpp_inner.wrap_bodies;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(t){let n=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(n!==t&&(n?.zpp_inner.wrap_bodies.remove(this),t!=null)){let l=t.zpp_inner.wrap_bodies;l.zpp_inner.reverse_flag?l.push(this):l.unshift(this)}}get bounds(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no bounds");return ri._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=Fe.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=Fe.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=oe(),n=Cn("MassMode_DEFAULT",()=>new t.phys.MassMode),l=Cn("MassMode_FIXED",()=>new t.phys.MassMode);return[n,l][this.zpp_inner.massMode]}set massMode(t){let n=oe();if(this.zpp_inner.immutable_midstep("Body::massMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: cannot use null massMode");let l=Cn("MassMode_DEFAULT",()=>new n.phys.MassMode);this.zpp_inner.massMode=t===l?0:1,this.zpp_inner.invalidate_mass()}get inertiaMode(){let t=oe(),n=Cn("InertiaMode_DEFAULT",()=>new t.phys.InertiaMode),l=Cn("InertiaMode_FIXED",()=>new t.phys.InertiaMode);return[n,l][this.zpp_inner.inertiaMode]}set inertiaMode(t){let n=oe();if(this.zpp_inner.immutable_midstep("Body::inertiaMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot use null InertiaMode");let l=Cn("InertiaMode_FIXED",()=>new n.phys.InertiaMode);this.zpp_inner.inertiaMode=t===l?1:0,this.zpp_inner.invalidate_inertia()}get gravMassMode(){let t=oe(),n=Cn("GravMassMode_DEFAULT",()=>new t.phys.GravMassMode),l=Cn("GravMassMode_FIXED",()=>new t.phys.GravMassMode),s=Cn("GravMassMode_SCALED",()=>new t.phys.GravMassMode);return[n,l,s][this.zpp_inner.gravMassMode]}set gravMassMode(t){let n=oe();if(this.zpp_inner.immutable_midstep("Body::gravMassMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot use null gravMassMode");let l=Cn("GravMassMode_SCALED",()=>new n.phys.GravMassMode);if(t===l)this.zpp_inner.gravMassMode=2;else{let s=Cn("GravMassMode_DEFAULT",()=>new n.phys.GravMassMode);this.zpp_inner.gravMassMode=t===s?0:1}this.zpp_inner.invalidate_gravMass()}copy(){if(this.zpp_inner.world)throw new Error("Error: Space::world cannot be copied");return this.zpp_inner.copy()}toString(){let t=this.zpp_inner;return(t.world?"(space::world":"("+(t.type===2?"dynamic":t.type===1?"static":"kinematic"))+")#"+this.zpp_inner_i.id}integrate(t){if(t!==t)throw new Error("Cannot integrate by NaN time");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t===0)return this;let n=this.zpp_inner;n.sweepTime=0,n.sweep_angvel=n.angvel;let l=t-n.sweepTime;if(l!==0&&(n.sweepTime=t,n.posx+=n.velx*l,n.posy+=n.vely*l,n.angvel!==0)){let s=n.sweep_angvel*l;if(n.rot+=s,s*s>1e-4)n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot);else{let i=s*s,r=1-.5*i,o=1-i*i/8,a=(r*n.axisx+s*n.axisy)*o;n.axisy=(r*n.axisy-s*n.axisx)*o,n.axisx=a}}return Vo(n),n.zip_worldCOM=!0,n.zip_axis=!0,Vo(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 l=Ci(t),s=Zi(t),i=this.zpp_inner.axisy*l-this.zpp_inner.axisx*s,r=l*this.zpp_inner.axisx+s*this.zpp_inner.axisy;return Qn(t),lo(i+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 l=Ci(t)-this.zpp_inner.posx,s=Zi(t)-this.zpp_inner.posy,i=l*this.zpp_inner.axisy+s*this.zpp_inner.axisx,r=s*this.zpp_inner.axisy-l*this.zpp_inner.axisx;return Qn(t),lo(i,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 l=Ci(t),s=Zi(t),i=this.zpp_inner.axisy*l-this.zpp_inner.axisx*s,r=l*this.zpp_inner.axisx+s*this.zpp_inner.axisy;return Qn(t),lo(i,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 l=Ci(t),s=Zi(t),i=l*this.zpp_inner.axisy+s*this.zpp_inner.axisx,r=s*this.zpp_inner.axisy-l*this.zpp_inner.axisx;return Qn(t),lo(i,r,n)}applyImpulse(t,n,l=!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(l&&this.isSleeping)return Qn(t),n!=null&&Qn(n),this;this.zpp_inner.validate_mass();let s=this.zpp_inner.imass,i=Ci(t),r=Zi(t);if(this.zpp_inner.velx+=i*s,this.zpp_inner.vely+=r*s,n!=null){let o=Ci(n)-this.zpp_inner.posx,a=Zi(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(r*o-i*a)*this.zpp_inner.iinertia,Qn(n)}return l||this.zpp_inner.type===2&&this.zpp_inner.wake(),Qn(t),this}applyAngularImpulse(t,n=!1){if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");return n&&this.isSleeping?this:(this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=t*this.zpp_inner.iinertia,n||this.zpp_inner.type===2&&this.zpp_inner.wake(),this)}setVelocityFromTarget(t,n,l){if(pi(t),t==null)throw new Error("Cannot set velocity for null target position");if(l===0)throw new Error("deltaTime cannot be 0 for setVelocityFromTarget");let s=1/l;this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity(),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let i=t.sub(this.zpp_inner.wrap_pos,!0).muleq(s);this.zpp_inner.wrap_vel.set(i);let r=(n-this.zpp_inner.rot)*s;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 Qn(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 l=this.zpp_inner.shapes.head;for(;l!=null;)l.elt.outer.translate(t),l=l.next;return t.zpp_inner.weak=n,Qn(t),this}rotateShapes(t){if(this.zpp_inner.immutable_midstep("Body::rotateShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.rotate(t),n=n.next;return this}scaleShapes(t,n){if(this.zpp_inner.immutable_midstep("Body::scaleShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let l=this.zpp_inner.shapes.head;for(;l!=null;)l.elt.outer.scale(t,n),l=l.next;return this}transformShapes(t){if(this.zpp_inner.immutable_midstep("Body::transformShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.transform(t),n=n.next;return this}align(){if(this.zpp_inner.immutable_midstep("Body::align()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.shapes.head==null)throw new Error("Error: Cannot align empty Body");this.zpp_inner.validate_localCOM();let t=Fe.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-=Ci(n),this.zpp_inner.pre_posy-=Zi(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 l=t.zpp_inner.weak;t.zpp_inner.weak=!1,this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let s=this.zpp_inner.wrap_pos.sub(t);s.rotate(n);let i=t.add(s,!0);Ll("position",this.zpp_inner.wrap_pos,i,()=>this.zpp_inner.setupPosition(),()=>this.zpp_inner.wrap_pos),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),s.dispose();{let 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=l,Qn(t),this}setShapeMaterials(t){if(this.zpp_inner.immutable_midstep("Body::setShapeMaterials()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let l=n.elt.outer;if(l.zpp_inner.immutable_midstep("Shape::material"),t==null)throw new Error("Error: Cannot assign null as Shape material");l.zpp_inner.setMaterial(t.zpp_inner),l.zpp_inner.material.wrapper(),n=n.next}return this}setShapeFilters(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFilters()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let l=n.elt.outer;if(l.zpp_inner.immutable_midstep("Shape::filter"),t==null)throw new Error("Error: Cannot assign null as Shape filter");l.zpp_inner.setFilter(t.zpp_inner),l.zpp_inner.filter.wrapper(),n=n.next}return this}setShapeFluidProperties(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFluidProperties()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=oe(),l=this.zpp_inner.shapes.head;for(;l!=null;){let s=l.elt.outer;if(t==null)throw new Error("Error: Cannot assign null as Shape fluidProperties, disable fluids by setting fluidEnabled to false");s.zpp_inner.setFluid(t.zpp_inner),s.zpp_inner.immutable_midstep("Shape::fluidProperties"),s.zpp_inner.fluidProperties==null&&s.zpp_inner.setFluid(new n.phys.FluidProperties().zpp_inner),s.zpp_inner.fluidProperties.wrapper(),l=l.next}return this}contains(t){if(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 l=!1,s=this.zpp_inner.shapes.head;for(;s!=null;){if(s.elt.outer.contains(t)){l=!0;break}s=s.next}return t.zpp_inner.weak=n,Qn(t),l}connectedBodies(t=-1,n=null){return this.zpp_inner.connectedBodies(t,n)}interactingBodies(t=null,n=-1,l=null){let s;if(t==null)s=ke.COL|ke.SENSOR|ke.FLUID;else{let i=oe(),r=Cn("InteractionType_COLLISION",()=>new i.callbacks.InteractionType);if(t===r)s=ke.COL;else{let o=Cn("InteractionType_SENSOR",()=>new i.callbacks.InteractionType);s=t===o?ke.SENSOR:ke.FLUID}}return this.zpp_inner.interactingBodies(s,l)}normalImpulse(t=null,n=!1){return this._arbiterImpulseQuery(ke.COL,l=>l.collisionArbiter.normalImpulse(this,n),t)}tangentImpulse(t=null,n=!1){return this._arbiterImpulseQuery(ke.COL,l=>l.collisionArbiter.tangentImpulse(this,n),t)}totalContactsImpulse(t=null,n=!1){return this._arbiterImpulseQuery(ke.COL,l=>l.collisionArbiter.totalImpulse(this,n),t)}rollingImpulse(t=null,n=!1){let l=0,i=this._getArbiters().iterator();for(;;){i.zpp_inner.zpp_inner.valmod();let r=i.zpp_inner.zpp_gl();if(i.zpp_critical=!0,i.zpp_i>=r){i.zpp_next=oe().dynamics.ArbiterIterator.zpp_pool,oe().dynamics.ArbiterIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1;let o=i.zpp_inner.at(i.zpp_i++),a=o.zpp_inner;a.type===ke.COL&&(t!=null&&a.b2!==t.zpp_inner&&a.b1!==t.zpp_inner||(l+=o.collisionArbiter.rollingImpulse(this,n)))}return l}buoyancyImpulse(t=null){return this._arbiterImpulseQuery(ke.FLUID,n=>n.fluidArbiter.buoyancyImpulse(this),t)}dragImpulse(t=null){return this._arbiterImpulseQuery(ke.FLUID,n=>n.fluidArbiter.dragImpulse(this),t)}totalFluidImpulse(t=null){return this._arbiterImpulseQuery(ke.FLUID,n=>n.fluidArbiter.totalImpulse(this),t)}constraintsImpulse(){let t=0,n=0,l=0,s=this.zpp_inner.constraints.head;for(;s!=null;){let r=s.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(),l+=o.z,r.dispose(),s=s.next}return $e.get(t,n,l)}totalImpulse(t=null,n=!1){let l=0,s=0,i=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=oe().dynamics.ArbiterIterator.zpp_pool,oe().dynamics.ArbiterIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let u=o.zpp_inner.at(o.zpp_i++).zpp_inner;if(u.type===ke.SENSOR||t!=null&&u.b2!==t.zpp_inner&&u.b1!==t.zpp_inner)continue;let h=u.wrapper().totalImpulse(this,n),x=h.zpp_inner;x._validate!=null&&x._validate(),l+=x.x,x._validate!=null&&x._validate(),s+=x.y,x._validate!=null&&x._validate(),i+=x.z,h.dispose()}let a=this.zpp_inner.constraints.head;for(;a!=null;){let p=a.elt;if(p.outer.active){let c=p.outer.bodyImpulse(this),u=c.zpp_inner;u._validate!=null&&u._validate(),l+=u.x,u._validate!=null&&u._validate(),s+=u.y,u._validate!=null&&u._validate(),i+=u.z,c.dispose()}a=a.next}return $e.get(l,s,i)}crushFactor(){if(this.zpp_inner.space==null)throw new Error("Error: Makes no sense to see how much an object not taking part in a simulation is being crushed");let t=0,n=Fe.get(0,0),s=this._getArbiters().iterator();for(;;){s.zpp_inner.zpp_inner.valmod();let x=s.zpp_inner.zpp_gl();if(s.zpp_critical=!0,s.zpp_i>=x){s.zpp_next=oe().dynamics.ArbiterIterator.zpp_pool,oe().dynamics.ArbiterIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1;let _=s.zpp_inner.at(s.zpp_i++).totalImpulse(this),d=_.xy();n.addeq(d);let b=Ci(d),m=Zi(d);t+=Math.sqrt(b*b+m*m),d.dispose(),_.dispose()}let r=this._getConstraints();r.zpp_inner.valmod();let o=oe().constraint.ConstraintIterator.get(r);for(;;){o.zpp_inner.zpp_inner.valmod();let x=o.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 f=x.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=f){o.zpp_next=oe().constraint.ConstraintIterator.zpp_pool,oe().constraint.ConstraintIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let d=o.zpp_inner.at(o.zpp_i++).bodyImpulse(this),b=d.xy();n.addeq(b);let m=Ci(b),z=Zi(b);t+=Math.sqrt(m*m+z*z),b.dispose(),d.dispose()}let a=Ci(n),p=Zi(n),c=Math.sqrt(a*a+p*p),u=this.mass,h=(t-c)/(u*this.zpp_inner.space.pre_dt);return n.dispose(),h}_getArbiters(){return this.zpp_inner.wrap_arbiters==null&&(this.zpp_inner.wrap_arbiters=zo.get(this.zpp_inner.arbiters,!0)),this.zpp_inner.wrap_arbiters}_getConstraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=Br.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}_arbiterImpulseQuery(t,n,l){let s=0,i=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=oe().dynamics.ArbiterIterator.zpp_pool,oe().dynamics.ArbiterIterator.zpp_pool=a,a.zpp_inner=null;break}a.zpp_critical=!1;let c=a.zpp_inner.at(a.zpp_i++),u=c.zpp_inner;if(u.type!==t||l!=null&&u.b2!==l.zpp_inner&&u.b1!==l.zpp_inner)continue;let h=n(c),x=h.zpp_inner;x._validate!=null&&x._validate(),s+=x.x,x._validate!=null&&x._validate(),i+=x.y,x._validate!=null&&x._validate(),r+=x.z,h.dispose()}return $e.get(s,i,r)}};ds.__name__=["nape","phys","Body"],ds.__super__=Xn;var et=ds;function Ao(S,e){let t=Cn("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(S===t)return 2;let n=Cn("BodyType_KINEMATIC",()=>new e.phys.BodyType);return S===n?3:1}function Vo(S){let e=S.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 na=oe();na.phys.Body=et;so(S=>et._wrap(S));var jl=class jl{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate BodyType derp!")}static get STATIC(){return T.BodyType_STATIC==null&&(T.internal=!0,T.BodyType_STATIC=new jl,T.internal=!1),T.BodyType_STATIC}static get DYNAMIC(){return T.BodyType_DYNAMIC==null&&(T.internal=!0,T.BodyType_DYNAMIC=new jl,T.internal=!1),T.BodyType_DYNAMIC}static get KINEMATIC(){return T.BodyType_KINEMATIC==null&&(T.internal=!0,T.BodyType_KINEMATIC=new jl,T.internal=!1),T.BodyType_KINEMATIC}toString(){return this===T.BodyType_STATIC?"STATIC":this===T.BodyType_DYNAMIC?"DYNAMIC":this===T.BodyType_KINEMATIC?"KINEMATIC":""}};jl.__name__=["nape","phys","BodyType"];var Dl=jl,ia=oe();ia.phys.BodyType=Dl;li();var ys=class ys extends Xn{constructor(){super();let e=new Pi;this.zpp_inner=e,e.outer=this,e.outer_i=this,this.zpp_inner_i=e,this._inner=this,e.insert_cbtype(zt.ANY_COMPOUND.zpp_inner)}static _wrap(e){return e?e instanceof ys?e:e instanceof Pi?ve(e,t=>{let n=Object.create(ys.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?ys._wrap(e.zpp_inner):ve(e,t=>{let n=Object.create(ys.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:gi._wrap(this.zpp_inner.space.outer)}set space(e){if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");this.zpp_inner.immutable_midstep("Compound::space");let t=this.zpp_inner.space==null?null:this.zpp_inner.space.outer;if(t!==e?._inner&&(t?.zpp_inner.wrap_compounds.remove(this),e!=null)){let n=e._inner.zpp_inner.wrap_compounds;n.zpp_inner.reverse_flag?n.push(this):n.unshift(this)}}copy(){return this.zpp_inner.copy()}breakApart(){this.zpp_inner.breakApart()}visitBodies(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitBodies");let t=this.zpp_inner.wrap_bodies,n=t.length;for(let i=0;i<n;i++)e(t.at(i));let l=this.zpp_inner.wrap_compounds,s=l.length;for(let i=0;i<s;i++)l.at(i).visitBodies(e)}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitConstraints");let t=this.zpp_inner.wrap_constraints,n=t.length;for(let i=0;i<n;i++)e(t.at(i));let l=this.zpp_inner.wrap_compounds,s=l.length;for(let i=0;i<s;i++)l.at(i).visitConstraints(e)}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitConstraints");let t=this.zpp_inner.wrap_compounds,n=t.length;for(let l=0;l<n;l++){let s=t.at(l);e(s),s.visitCompounds(e)}}COM(e=!1){let t=new Fe(0,0),n=0;if(this.visitBodies(l=>{if(l.zpp_inner.wrap_shapes.zpp_inner.inner.head!=null){if(l.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");l.zpp_inner.wrap_worldCOM==null&&l.zpp_inner.getworldCOM();let i=l.zpp_inner.wrap_worldCOM;if(l.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(l.zpp_inner.validate_mass(),l.zpp_inner.massMode==0&&l.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");let r=l.zpp_inner.cmass;t.addeq(i.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(l=>{l.rotate(e,t)}),e.zpp_inner.weak=n,e.zpp_inner.weak&&e.dispose(),this}toString(){return"Compound"+this.zpp_inner.id}};ys.__name__=["nape","phys","Compound"],ys.__super__=Xn;var Vi=ys;Pi._wrapFn=S=>ve(S,e=>{let t=Object.create(Vi.prototype);return t.zpp_inner=e,e.outer=t,e.outer_i=t,t.zpp_inner_i=e,t._inner=t,t});Object.defineProperty(Vi.prototype,"bodies",{get:function(){return this.zpp_inner.wrap_bodies},configurable:!0});Object.defineProperty(Vi.prototype,"constraints",{get:function(){return this.zpp_inner.wrap_constraints},configurable:!0});Object.defineProperty(Vi.prototype,"compounds",{get:function(){return this.zpp_inner.wrap_compounds},configurable:!0});var $n=class $n{get _inner(){return this}constructor(e=0,t=1,n=2,l=1,s=.001){let i;if(Te.zpp_pool==null?i=new Te:(i=Te.zpp_pool,Te.zpp_pool=i.next,i.next=null),this.zpp_inner=i,i.outer=this,e!==i.elasticity){if(e!==e)throw new Error("Error: Material::elasticity cannot be NaN");i.elasticity=e,i.invalidate(Te.WAKE|Te.ARBITERS)}if(t!==i.dynamicFriction){if(t!==t)throw new Error("Error: Material::dynamicFriction cannot be NaN");if(t<0)throw new Error("Error: Material::dynamicFriction cannot be negative");i.dynamicFriction=t,i.invalidate(Te.WAKE|Te.ANGDRAG|Te.ARBITERS)}if(n!==i.staticFriction){if(n!==n)throw new Error("Error: Material::staticFriction cannot be NaN");if(n<0)throw new Error("Error: Material::staticFriction cannot be negative");i.staticFriction=n,i.invalidate(Te.WAKE|Te.ARBITERS)}if(l!==i.density*1e3){if(l!==l)throw new Error("Error: Material::density cannot be NaN");if(l<0)throw new Error("Error: Material::density must be positive");i.density=l/1e3,i.invalidate(Te.WAKE|Te.PROPS)}if(s!==i.rollingFriction){if(s!==s)throw new Error("Error: Material::rollingFriction cannot be NaN");if(s<0)throw new Error("Error: Material::rollingFriction cannot be negative");i.rollingFriction=s,i.invalidate(Te.WAKE|Te.ARBITERS)}}static _wrap(e){return e instanceof $n?e:e?e instanceof Te?ve(e,t=>{let n=Object.create($n.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?$n._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(Te.WAKE|Te.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(Te.WAKE|Te.ANGDRAG|Te.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(Te.WAKE|Te.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(Te.WAKE|Te.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(Te.WAKE|Te.ARBITERS)}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}copy(){let e=new $n(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 $n(.4,.2,.38,.7,.005)}static steel(){return new $n(.2,.57,.74,7.8,.001)}static ice(){return new $n(.3,.03,.1,.9,1e-4)}static rubber(){return new $n(.8,1,1.4,1.5,.01)}static glass(){return new $n(.4,.4,.94,2.6,.002)}static sand(){return new $n(-1,.45,.6,1.6,16)}};$n.__name__=["nape","phys","Material"];var Fl=$n;Te._wrapFn=S=>ve(S,e=>{let t=Object.create(Fl.prototype);return t.zpp_inner=e,e.outer=t,t});var Rl=class Rl{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate GravMassMode derp!")}static get DEFAULT(){return T.GravMassMode_DEFAULT==null&&(T.internal=!0,T.GravMassMode_DEFAULT=new Rl,T.internal=!1),T.GravMassMode_DEFAULT}static get FIXED(){return T.GravMassMode_FIXED==null&&(T.internal=!0,T.GravMassMode_FIXED=new Rl,T.internal=!1),T.GravMassMode_FIXED}static get SCALED(){return T.GravMassMode_SCALED==null&&(T.internal=!0,T.GravMassMode_SCALED=new Rl,T.internal=!1),T.GravMassMode_SCALED}toString(){return this===T.GravMassMode_DEFAULT?"DEFAULT":this===T.GravMassMode_FIXED?"FIXED":this===T.GravMassMode_SCALED?"SCALED":""}};Rl.__name__=["nape","phys","GravMassMode"];var Gl=Rl,sa=oe();sa.phys.GravMassMode=Gl;var Lr=class Lr{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate InertiaMode derp!")}static get DEFAULT(){return T.InertiaMode_DEFAULT==null&&(T.internal=!0,T.InertiaMode_DEFAULT=new Lr,T.internal=!1),T.InertiaMode_DEFAULT}static get FIXED(){return T.InertiaMode_FIXED==null&&(T.internal=!0,T.InertiaMode_FIXED=new Lr,T.internal=!1),T.InertiaMode_FIXED}toString(){return this===T.InertiaMode_DEFAULT?"DEFAULT":this===T.InertiaMode_FIXED?"FIXED":""}};Lr.__name__=["nape","phys","InertiaMode"];var ql=Lr,la=oe();la.phys.InertiaMode=ql;var jr=class jr{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate MassMode derp!")}static get DEFAULT(){return T.MassMode_DEFAULT==null&&(T.internal=!0,T.MassMode_DEFAULT=new jr,T.internal=!1),T.MassMode_DEFAULT}static get FIXED(){return T.MassMode_FIXED==null&&(T.internal=!0,T.MassMode_FIXED=new jr,T.internal=!1),T.MassMode_FIXED}toString(){return this===T.MassMode_DEFAULT?"DEFAULT":this===T.MassMode_FIXED?"FIXED":""}};jr.__name__=["nape","phys","MassMode"];var Wl=jr,ra=oe();ra.phys.MassMode=Wl;var ms=class ms extends Tn{constructor(e=50,t,n,l){super();let s=oe(),i=new Ni;if(this.zpp_inner_zn=i,this.zpp_inner=i,this.zpp_inner_i=i,i.outer=this,i.outer_zn=this,i.outer_i=this,this._inner=this,e!==i.radius){if(e!==e)throw new Error("Error: Circle::radius cannot be NaN");if(e<s.Config.epsilon)throw new Error("Error: Circle::radius ("+e+") must be > Config.epsilon");if(e>Li.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");i.radius=e,i.invalidate_radius()}if(t!=null){if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=t.zpp_inner;r._validate!=null&&r._validate(),i.localCOMx=r.x,r._validate!=null&&r._validate(),i.localCOMy=r.y,r.weak&&t.dispose()}else i.localCOMx=0,i.localCOMy=0;n==null?Te.zpp_pool!=null?(i.material=Te.zpp_pool,Te.zpp_pool=i.material.next,i.material.next=null):i.material=new Te:(i.immutable_midstep("Shape::material"),i.setMaterial(n.zpp_inner),i.material.wrapper()),l==null?Ct.zpp_pool!=null?(i.filter=Ct.zpp_pool,Ct.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new Ct:(i.immutable_midstep("Shape::filter"),i.setFilter(l.zpp_inner),i.filter.wrapper()),i.insert_cbtype(zt.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof ms?e:e instanceof Ni?ve(e,t=>{let n=Object.create(ms.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?ms._wrap(e.zpp_inner_zn):ve(e,t=>{let n=Object.create(ms.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=oe();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>Li.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}};ms.__name__=["nape","shape","Circle"],ms.__super__=Tn;var Hs=ms;Oo(S=>Hs._wrap(S));var oa=oe();oa.shape.Circle=Hs;var Hi=class Hi extends Tn{constructor(e,t,n){super();let l=oe();if(e==null)throw new Error("Error: localVerts cannot be null");let s=new Oi;if(this.zpp_inner_zn=s,this.zpp_inner=s,this.zpp_inner_i=s,s.outer=this,s.outer_zn=this,s.outer_i=this,this._inner=this,Array.isArray(e)){for(let i of e){if(i==null)throw new Error("Error: Array<Vec2> contains null objects");if(!(i instanceof Fe))throw new Error("Error: Array<Vec2> contains non Vec2 objects");if(i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");s.wrap_lverts==null&&s.getlverts();let r=i.zpp_inner;r._validate!=null&&r._validate();let o=r.x;r._validate!=null&&r._validate();let a=r.y,p=new Fe(o,a);s.wrap_lverts.push(p)}for(let i=e.length-1;i>=0;i--)e[i].zpp_inner?.weak&&(e[i].dispose(),e.splice(i,1))}else if(e instanceof l.geom.Vec2List){let i=e,r=i.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=l.geom.Vec2Iterator.zpp_pool,l.geom.Vec2Iterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let u=r.zpp_inner.at(r.zpp_i++);if(u==null)throw new Error("Error: Vec2List contains null objects");if(u.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");s.wrap_lverts==null&&s.getlverts();let h=u.zpp_inner;h._validate!=null&&h._validate();let x=h.x;h._validate!=null&&h._validate();let f=h.y,_=new Fe(x,f);s.wrap_lverts.push(_)}i.zpp_inner._validate!=null&&i.zpp_inner._validate();let o=i.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 l.geom.GeomPoly){let i=e.zpp_inner.vertices;if(i!=null){let r=i;do{s.wrap_lverts==null&&s.getlverts();let o=new Fe(r.x,r.y);s.wrap_lverts.push(o),r=r.next}while(r!==i)}}else throw new Error("Error: Invalid type for polygon object, should be Array<Vec2>, Vec2List, GeomPoly or for flash10+ flash.Vector<Vec2>");t==null?Te.zpp_pool!=null?(s.material=Te.zpp_pool,Te.zpp_pool=s.material.next,s.material.next=null):s.material=new Te:(s.immutable_midstep("Shape::material"),s.setMaterial(t.zpp_inner),s.material.wrapper()),n==null?Ct.zpp_pool!=null?(s.filter=Ct.zpp_pool,Ct.zpp_pool=s.filter.next,s.filter.next=null):s.filter=new Ct:(s.immutable_midstep("Shape::filter"),s.setFilter(n.zpp_inner),s.filter.wrapper()),s.insert_cbtype(zt.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof Hi?e:e instanceof Oi?ve(e,t=>{let n=Object.create(Hi.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?Hi._wrap(e.zpp_inner_zn):ve(e,t=>{let n=Object.create(Hi.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i,n}):null}static rect(e,t,n,l,s=!1){if(e!==e||t!==t||n!==n||l!==l)throw new Error("Error: Polygon.rect cannot accept NaN arguments");let i=new Fe(e,t);i.zpp_inner.weak=s;let r=new Fe(e+n,t);r.zpp_inner.weak=s;let o=new Fe(e+n,t+l);o.zpp_inner.weak=s;let a=new Fe(e,t+l);return a.zpp_inner.weak=s,[i,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 Hi.rect(-e/2,-t/2,e,t,n)}static regular(e,t,n,l=0,s=!1){if(e!==e||t!==t||l!==l)throw new Error("Error: Polygon.regular cannot accept NaN arguments");let i=[],r=Math.PI*2/n;for(let o=0;o<n;o++){let a=o*r+l,p=Math.cos(a)*e,c=Math.sin(a)*t,u=new Fe(p,c);u.zpp_inner.weak=s,i.push(u)}return i}get localVerts(){return this.zpp_inner_zn.wrap_lverts==null&&this.zpp_inner_zn.getlverts(),this.zpp_inner_zn.wrap_lverts}get worldVerts(){return this.zpp_inner_zn.wrap_gverts==null&&this.zpp_inner_zn.getgverts(),this.zpp_inner_zn.wrap_gverts}get edges(){return this.zpp_inner_zn.wrap_edges==null&&this.zpp_inner_zn.getedges(),this.zpp_inner_zn.wrap_edges}validity(){return this.zpp_inner_zn.valid()}};Hi.__name__=["nape","shape","Polygon"],Hi.__super__=Tn;var Qs=Hi;So(S=>Qs._wrap(S));var aa=oe();aa.shape.Polygon=Qs;var Dr=class Dr{constructor(){if(!Qe.internal)throw new Error("Error: Cannot instantiate an Edge derp!")}static _wrap(e){return e?e instanceof Dr?e:e instanceof Qe?ve(e,t=>{Qe.internal=!0;let n=new Dr;return Qe.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=oe();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=ie.zpp_pool,ie.zpp_pool=n,e.outer.zpp_inner=e}return e.outer}};Dr.__name__=["nape","shape","Edge"];var Jl=Dr;Qe._wrapFn=S=>ve(S,e=>{Qe.internal=!0;let t=new Jl;return Qe.internal=!1,t.zpp_inner=e,e.outer=t,t});var $s=class $s{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate ValidationResult derp!")}static get VALID(){return T.ValidationResult_VALID==null&&(T.internal=!0,T.ValidationResult_VALID=new $s,T.internal=!1),T.ValidationResult_VALID}static get DEGENERATE(){return T.ValidationResult_DEGENERATE==null&&(T.internal=!0,T.ValidationResult_DEGENERATE=new $s,T.internal=!1),T.ValidationResult_DEGENERATE}static get CONCAVE(){return T.ValidationResult_CONCAVE==null&&(T.internal=!0,T.ValidationResult_CONCAVE=new $s,T.internal=!1),T.ValidationResult_CONCAVE}static get SELF_INTERSECTING(){return T.ValidationResult_SELF_INTERSECTING==null&&(T.internal=!0,T.ValidationResult_SELF_INTERSECTING=new $s,T.internal=!1),T.ValidationResult_SELF_INTERSECTING}toString(){return this===T.ValidationResult_VALID?"VALID":this===T.ValidationResult_DEGENERATE?"DEGENERATE":this===T.ValidationResult_CONCAVE?"CONCAVE":this===T.ValidationResult_SELF_INTERSECTING?"SELF_INTERSECTING":""}};$s.__name__=["nape","shape","ValidationResult"];var Ul=$s,pa=oe();pa.shape.ValidationResult=Ul;var Fr=class Fr{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate Broadphase derp!")}static get DYNAMIC_AABB_TREE(){return T.Broadphase_DYNAMIC_AABB_TREE==null&&(T.internal=!0,T.Broadphase_DYNAMIC_AABB_TREE=new Fr,T.internal=!1),T.Broadphase_DYNAMIC_AABB_TREE}static get SWEEP_AND_PRUNE(){return T.Broadphase_SWEEP_AND_PRUNE==null&&(T.internal=!0,T.Broadphase_SWEEP_AND_PRUNE=new Fr,T.internal=!1),T.Broadphase_SWEEP_AND_PRUNE}toString(){return this===T.Broadphase_DYNAMIC_AABB_TREE?"DYNAMIC_AABB_TREE":this===T.Broadphase_SWEEP_AND_PRUNE?"SWEEP_AND_PRUNE":""}};Fr.__name__=["nape","space","Broadphase"];var Rr=Fr;var el=class el{get _inner(){return this}constructor(e=1,t=-1,n=1,l=-1,s=1,i=-1){let r;Ct.zpp_pool==null?r=new Ct:(r=Ct.zpp_pool,Ct.zpp_pool=r.next,r.next=null),this.zpp_inner=r,r.outer=this,r.collisionGroup!=e&&(r.collisionGroup=e,r.invalidate()),r.collisionMask!=t&&(r.collisionMask=t,r.invalidate()),r.sensorGroup!=n&&(r.sensorGroup=n,r.invalidate()),r.sensorMask!=l&&(r.sensorMask=l,r.invalidate()),r.fluidGroup!=s&&(r.fluidGroup=s,r.invalidate()),r.fluidMask!=i&&(r.fluidMask=i,r.invalidate())}static _wrap(e){return e instanceof el?e:e?e instanceof Ct?ve(e,t=>{let n=Object.create(el.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?el._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=oe();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 el(this.zpp_inner.collisionGroup,this.zpp_inner.collisionMask,this.zpp_inner.sensorGroup,this.zpp_inner.sensorMask,this.zpp_inner.fluidGroup,this.zpp_inner.fluidMask)}toString(){let e=(t,n)=>{let l="",s="0123456789ABCDEF",i=t;do l=s.charAt(i&15)+l,i>>>=4;while(i>0);for(;l.length<n;)l="0"+l;return l};return"{ collision: "+e(this.zpp_inner.collisionGroup,8)+"~"+e(this.zpp_inner.collisionMask,8)+" sensor: "+e(this.zpp_inner.sensorGroup,8)+"~"+e(this.zpp_inner.sensorMask,8)+" fluid: "+e(this.zpp_inner.fluidGroup,8)+"~"+e(this.zpp_inner.fluidMask,8)+" }"}};el.__name__=["nape","dynamics","InteractionFilter"];var Kl=el;Ct._wrapFn=S=>ve(S,e=>{let t=Object.create(Kl.prototype);return t.zpp_inner=e,e.outer=t,t});var Yl=class Yl{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 Yl?e:e?e instanceof Fi?ve(e,t=>{let n=Object.create(Yl.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?Yl._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=oe();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=oe();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}};Yl.__name__=["nape","dynamics","InteractionGroup"];var Xl=Yl;Fi._wrapFn=S=>ve(S,e=>{let t=Object.create(Xl.prototype);return t.zpp_inner=e,e.outer=t,t});var Hl=class Hl{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate ArbiterType derp!")}static get COLLISION(){return T.ArbiterType_COLLISION==null&&(T.internal=!0,T.ArbiterType_COLLISION=new Hl,T.internal=!1),T.ArbiterType_COLLISION}static get SENSOR(){return T.ArbiterType_SENSOR==null&&(T.internal=!0,T.ArbiterType_SENSOR=new Hl,T.internal=!1),T.ArbiterType_SENSOR}static get FLUID(){return T.ArbiterType_FLUID==null&&(T.internal=!0,T.ArbiterType_FLUID=new Hl,T.internal=!1),T.ArbiterType_FLUID}toString(){return this===T.ArbiterType_COLLISION?"COLLISION":this===T.ArbiterType_SENSOR?"SENSOR":this===T.ArbiterType_FLUID?"FLUID":""}};Hl.__name__=["nape","dynamics","ArbiterType"];var Ql=Hl,ca=oe();ca.dynamics.ArbiterType=Ql;li();var ei=class{get _inner(){return this}constructor(){if(this.zpp_inner=null,!ke.internal)throw new Error("Error: Cannot instantiate Arbiter derp!")}get isSleeping(){return this._activeCheck(),this.zpp_inner.sleeping}get type(){return ke.types[this.zpp_inner.type]}get collisionArbiter(){return this.zpp_inner.type==ke.COL?this.zpp_inner.colarb.outer_zn:null}get fluidArbiter(){return this.zpp_inner.type==ke.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=oe(),t=this.zpp_inner.immState;return t==5?(T.PreFlag_ACCEPT==null&&(T.internal=!0,T.PreFlag_ACCEPT=new e.callbacks.PreFlag,T.internal=!1),T.PreFlag_ACCEPT):t==1?(T.PreFlag_ACCEPT_ONCE==null&&(T.internal=!0,T.PreFlag_ACCEPT_ONCE=new e.callbacks.PreFlag,T.internal=!1),T.PreFlag_ACCEPT_ONCE):t==6?(T.PreFlag_IGNORE==null&&(T.internal=!0,T.PreFlag_IGNORE=new e.callbacks.PreFlag,T.internal=!1),T.PreFlag_IGNORE):(T.PreFlag_IGNORE_ONCE==null&&(T.internal=!0,T.PreFlag_IGNORE_ONCE=new e.callbacks.PreFlag,T.internal=!1),T.PreFlag_IGNORE_ONCE)}isCollisionArbiter(){return this.zpp_inner.type==ke.COL}isFluidArbiter(){return this.zpp_inner.type==ke.FLUID}isSensorArbiter(){return this.zpp_inner.type==ke.SENSOR}totalImpulse(e=null,t=!1){return this._activeCheck(),e!=null&&this._checkBody(e),$e.get(0,0,0)}toString(){let e=this.zpp_inner.type==ke.COL?"CollisionArbiter":this.zpp_inner.type==ke.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,l=e+"("+t.toString()+"|"+n.toString()+")";return this.zpp_inner.type==ke.COL&&(l+="["+["SD","DD"][this.zpp_inner.colarb.stat?0:1]+"]"),l+="<-"+this.state.toString(),l}_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,l=t.ws1.id>t.ws2.id?t.b1.outer:t.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Arbiter does not relate to body")}};ei.__name__=["nape","dynamics","Arbiter"];var ha=oe();ha.dynamics.Arbiter=ei;var tl=class extends ei{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 l=0,s=0,i=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(),l+=a.x,a._validate!=null&&a._validate(),s+=a.y,a._validate!=null&&a._validate(),i+=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(),l+=a.x,a._validate!=null&&a._validate(),s+=a.y,a._validate!=null&&a._validate(),i+=a.z,o.dispose()}return $e.get(l,s,i)}};tl.__name__=["nape","dynamics","CollisionArbiter"],tl.__super__=ei;var nl=class extends ei{constructor(){super()}get position(){return this._activeCheck(),this.zpp_inner.fluidarb.wrap_position==null&&this.zpp_inner.fluidarb.getposition(),Fe._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?$e.get(t.buoyx,t.buoyy,0):e.zpp_inner==this.zpp_inner.b2?$e.get(t.buoyx,t.buoyy,t.buoyy*t.r2x-t.buoyx*t.r2y):$e.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 $e.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),l=this.dragImpulse(e),s=n.zpp_inner,i=l.zpp_inner;return s._validate!=null&&s._validate(),i._validate!=null&&i._validate(),i.x=i.x+s.x,s._validate!=null&&s._validate(),i._validate!=null&&i._validate(),i.y=i.y+s.y,s._validate!=null&&s._validate(),i._validate!=null&&i._validate(),i.z=i.z+s.z,n.dispose(),l}};nl.__name__=["nape","dynamics","FluidArbiter"],nl.__super__=ei;var il=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==ke.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(),Fe._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,l=n.jnAcc;return e==null?$e.get(t.nx*l,t.ny*l):(this._checkBody(e,t),e==t.b1.outer?$e.get(t.nx*-l,t.ny*-l,-(t.ny*n.r1x-t.nx*n.r1y)*l):$e.get(t.nx*l,t.ny*l,(t.ny*n.r2x-t.nx*n.r2y)*l))}tangentImpulse(e=null){this._inactiveCheck();let t=this.zpp_inner.arbiter.colarb,n=this.zpp_inner.inner,l=n.jtAcc;return e==null?$e.get(-t.ny*l,t.nx*l):(this._checkBody(e,t),e==t.b1.outer?$e.get(t.ny*l,-t.nx*l,-(n.r1x*t.nx+n.r1y*t.ny)*l):$e.get(-t.ny*l,t.nx*l,(n.r2x*t.nx+n.r2y*t.ny)*l))}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,l=n.jnAcc,s=n.jtAcc,i=t.jrAcc;if(e==null)return $e.get(t.nx*l-t.ny*s,t.ny*l+t.nx*s,i);this._checkBody(e,t);let r=t.nx*l-t.ny*s,o=t.ny*l+t.nx*s;return e==t.b1.outer?$e.get(-r,-o,-(o*n.r1x-r*n.r1y)-i):$e.get(r,o,o*n.r2x-r*n.r2y+i)}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")}};il.__name__=["nape","dynamics","Contact"];we._wrapFn=S=>{we.internal=!0;let e=new il;return we.internal=!1,e.zpp_inner=S,S.outer=e,e};function ua(S){let e=0,t=S.inner.next;for(;t!=null;)t.active&&t.arbiter.active&&e++,t=t.next;return e}function Bn(S){return S.valmod(),S.zip_length&&(S.zip_length=!1,S.user_length=ua(S)),S.user_length}function mt(){if(this.zpp_next=null,this.zpp_critical=!1,this.zpp_i=0,this.zpp_inner=null,!vi.internal)throw new Error("Error: Cannot instantiate ContactIterator derp!")}mt.__name__=["nape","dynamics","ContactIterator"];mt.zpp_pool=null;mt.get=function(S){let e;return mt.zpp_pool==null?(vi.internal=!0,e=new mt,vi.internal=!1):(e=mt.zpp_pool,mt.zpp_pool=e.zpp_next),e.zpp_i=0,e.zpp_inner=S,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 S=Bn(this.zpp_inner.zpp_inner);return this.zpp_critical=!0,this.zpp_i<S?!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 kt(){this.zpp_inner=null,this.zpp_inner=new vi,this.zpp_inner.outer=this}kt.__name__=["nape","dynamics","ContactList"];kt.fromArray=function(S){if(S==null)throw new Error("Error: Cannot convert null Array to Nape list");let e=oe(),t=new e.dynamics.ContactList;for(let n=0;n<S.length;n++)t.push(S[n]);return t};kt.prototype.zpp_inner=null;Object.defineProperty(kt.prototype,"length",{get:function(){return Bn(this.zpp_inner)}});kt.prototype.has=function(S){return this.zpp_inner.valmod(),this.zpp_inner.inner.has(S.zpp_inner)};kt.prototype.at=function(S){this.zpp_inner.valmod();let e=Bn(this.zpp_inner);if(S<0||S>=e)throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(S=Bn(this.zpp_inner)-1-S),S<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!=S;)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()};kt.prototype.push=function(S){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(S):!0;if(e){if(this.zpp_inner.reverse_flag)this.zpp_inner.inner.add(S.zpp_inner);else{if(this.zpp_inner.push_ite==null){let t=Bn(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,S.zpp_inner)}this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(S)}return e};kt.prototype.unshift=function(S){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(S):!0;if(e){if(this.zpp_inner.reverse_flag){if(this.zpp_inner.push_ite==null){let t=Bn(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,S.zpp_inner)}else this.zpp_inner.inner.add(S.zpp_inner);this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(S)}return e};kt.prototype.pop=function(){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");if(this.zpp_inner.modify_test(),Bn(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=Bn(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 l=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(l),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(n)}return this.zpp_inner.invalidate(),e.wrapper()};kt.prototype.shift=function(){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");if(this.zpp_inner.modify_test(),Bn(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=Bn(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 l=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(l),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()};kt.prototype.add=function(S){return this.zpp_inner.reverse_flag?this.push(S):this.unshift(S)};kt.prototype.remove=function(S){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==S.zpp_inner){e=!0;break}t=t.next}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(S),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(S.zpp_inner),this.zpp_inner.invalidate()),e};kt.prototype.clear=function(){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");if(this.zpp_inner.reverse_flag)for(;Bn(this.zpp_inner)!=0;)this.pop();else for(;Bn(this.zpp_inner)!=0;)this.shift()};kt.prototype.empty=function(){return Bn(this.zpp_inner)==0};kt.prototype.iterator=function(){return this.zpp_inner.valmod(),mt.get(this)};kt.prototype.copy=function(S){S==null&&(S=!1);let e=oe(),t=new e.dynamics.ContactList;this.zpp_inner.valmod();let n=mt.get(this);for(;n.hasNext();){let l=n.next();if(S)throw new Error("Error: Contact is not a copyable type");t.push(l)}return t};kt.prototype.merge=function(S){if(S==null)throw new Error("Error: Cannot merge with null list");S.zpp_inner.valmod();let e=mt.get(S);for(;e.hasNext();){let t=e.next();this.has(t)||(this.zpp_inner.reverse_flag?this.push(t):this.unshift(t))}};kt.prototype.toString=function(){let S="[",e=!0;this.zpp_inner.valmod();let t=mt.get(this);for(;t.hasNext();){let n=t.next();e||(S+=","),S+=n==null?"NULL":n.toString(),e=!1}return S+"]"};kt.prototype.foreach=function(S){if(S==null)throw new Error("Error: Cannot execute null on list elements");this.zpp_inner.valmod();let e=mt.get(this);for(;e.hasNext();)try{S(e.next())}catch{e.zpp_next=mt.zpp_pool,mt.zpp_pool=e,e.zpp_inner=null;break}return this};kt.prototype[Symbol.iterator]=function(){let S=mt.get(this);return{next(){return S.hasNext()?{value:S.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};kt.prototype.filter=function(S){if(S==null)throw new Error("Error: Cannot select elements of list with null");let e=0;for(;;){let t=Bn(this.zpp_inner);if(!(e<t))break;let n=this.at(e);try{S(n)?++e:this.remove(n)}catch{break}}return this};var Ii=class Ii{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate CbEvent derp!")}static get BEGIN(){return T.CbEvent_BEGIN==null&&(T.internal=!0,T.CbEvent_BEGIN=new Ii,T.internal=!1),T.CbEvent_BEGIN}static get ONGOING(){return T.CbEvent_ONGOING==null&&(T.internal=!0,T.CbEvent_ONGOING=new Ii,T.internal=!1),T.CbEvent_ONGOING}static get END(){return T.CbEvent_END==null&&(T.internal=!0,T.CbEvent_END=new Ii,T.internal=!1),T.CbEvent_END}static get WAKE(){return T.CbEvent_WAKE==null&&(T.internal=!0,T.CbEvent_WAKE=new Ii,T.internal=!1),T.CbEvent_WAKE}static get SLEEP(){return T.CbEvent_SLEEP==null&&(T.internal=!0,T.CbEvent_SLEEP=new Ii,T.internal=!1),T.CbEvent_SLEEP}static get BREAK(){return T.CbEvent_BREAK==null&&(T.internal=!0,T.CbEvent_BREAK=new Ii,T.internal=!1),T.CbEvent_BREAK}static get PRE(){return T.CbEvent_PRE==null&&(T.internal=!0,T.CbEvent_PRE=new Ii,T.internal=!1),T.CbEvent_PRE}toString(){return this===T.CbEvent_BEGIN?"BEGIN":this===T.CbEvent_ONGOING?"ONGOING":this===T.CbEvent_END?"END":this===T.CbEvent_WAKE?"WAKE":this===T.CbEvent_SLEEP?"SLEEP":this===T.CbEvent_BREAK?"BREAK":this===T.CbEvent_PRE?"PRE":""}};Ii.__name__=["nape","callbacks","CbEvent"];var ft=Ii,_a=oe();_a.callbacks.CbEvent=ft;li();var $l=class $l{get _inner(){return this}constructor(){this.zpp_inner=new zt,this.zpp_inner.outer=this}static get ANY_BODY(){return zt.ANY_BODY}static get ANY_CONSTRAINT(){return zt.ANY_CONSTRAINT}static get ANY_SHAPE(){return zt.ANY_SHAPE}static get ANY_COMPOUND(){return zt.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=bo.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=Br.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}including(e){return new(oe()).callbacks.OptionType(this).including(e)}excluding(e){return new(oe()).callbacks.OptionType(this).excluding(e)}toString(){return this===zt.ANY_BODY?"ANY_BODY":this===zt.ANY_SHAPE?"ANY_SHAPE":this===zt.ANY_COMPOUND?"ANY_COMPOUND":this===zt.ANY_CONSTRAINT?"ANY_CONSTRAINT":"CbType#"+this.zpp_inner.id}static _wrap(e){return e instanceof $l?e:e?e instanceof zt?ve(e,t=>{let n=Object.create($l.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?$l._wrap(e.zpp_inner):null:null}};$l.__name__=["nape","callbacks","CbType"];var er=$l,xa=oe();xa.callbacks.CbType=er;li();var sl=class sl{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate InteractionType derp!")}static get COLLISION(){return T.InteractionType_COLLISION==null&&(T.internal=!0,T.InteractionType_COLLISION=new sl,T.internal=!1),T.InteractionType_COLLISION}static get SENSOR(){return T.InteractionType_SENSOR==null&&(T.internal=!0,T.InteractionType_SENSOR=new sl,T.internal=!1),T.InteractionType_SENSOR}static get FLUID(){return T.InteractionType_FLUID==null&&(T.internal=!0,T.InteractionType_FLUID=new sl,T.internal=!1),T.InteractionType_FLUID}static get ANY(){return T.InteractionType_ANY==null&&(T.internal=!0,T.InteractionType_ANY=new sl,T.internal=!1),T.InteractionType_ANY}toString(){return this===T.InteractionType_COLLISION?"COLLISION":this===T.InteractionType_SENSOR?"SENSOR":this===T.InteractionType_FLUID?"FLUID":this===T.InteractionType_ANY?"ANY":""}};sl.__name__=["nape","callbacks","InteractionType"];var Ln=sl,da=oe();da.callbacks.InteractionType=Ln;var ll=class ll{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate PreFlag derp!")}static get ACCEPT(){return T.PreFlag_ACCEPT==null&&(T.internal=!0,T.PreFlag_ACCEPT=new ll,T.internal=!1),T.PreFlag_ACCEPT}static get IGNORE(){return T.PreFlag_IGNORE==null&&(T.internal=!0,T.PreFlag_IGNORE=new ll,T.internal=!1),T.PreFlag_IGNORE}static get ACCEPT_ONCE(){return T.PreFlag_ACCEPT_ONCE==null&&(T.internal=!0,T.PreFlag_ACCEPT_ONCE=new ll,T.internal=!1),T.PreFlag_ACCEPT_ONCE}static get IGNORE_ONCE(){return T.PreFlag_IGNORE_ONCE==null&&(T.internal=!0,T.PreFlag_IGNORE_ONCE=new ll,T.internal=!1),T.PreFlag_IGNORE_ONCE}toString(){return this===T.PreFlag_ACCEPT?"ACCEPT":this===T.PreFlag_IGNORE?"IGNORE":this===T.PreFlag_ACCEPT_ONCE?"ACCEPT_ONCE":this===T.PreFlag_IGNORE_ONCE?"IGNORE_ONCE":""}};ll.__name__=["nape","callbacks","PreFlag"];var tr=ll,ya=oe();ya.callbacks.PreFlag=tr;var nr=class nr{get _inner(){return this}constructor(e,t){this.zpp_inner=new Ht,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 nr?e:e?e instanceof Ht?ve(e,t=>{let n=Object.create(nr.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?nr._wrap(e.zpp_inner):null:null}};nr.__name__=["nape","callbacks","OptionType"];var ir=nr,ma=oe();ma.callbacks.OptionType=ir;function fa(S){return S===ft.BEGIN?0:S===ft.END?1:S===ft.WAKE?2:S===ft.SLEEP?3:S===ft.BREAK?4:S===ft.PRE?5:S===ft.ONGOING?6:-1}var Gr=class Gr{get _inner(){return this}constructor(){if(!Ke.internal)throw new Error("Error: Cannot instantiate Listener derp!");this.zpp_inner=null}static _wrap(e){return e instanceof Gr?e:e&&e instanceof Ke?ve(e,t=>{if(t.outer)return t.outer;let n=Object.create(Gr.prototype);return n.zpp_inner=t,t.outer=n,n}):null}get type(){return Ke.types[this.zpp_inner.type]}get event(){return Ke.events[this.zpp_inner.event]}set event(e){if(e==null)throw new Error("Error: Cannot set listener event type to null");if(Ke.events[this.zpp_inner.event]!=e){let t=fa(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:gi._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 l=t.zpp_inner.wrap_listeners;l.zpp_inner.reverse_flag?l.push(this):l.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,l;switch(n.itype){case 1:l="COLLISION";break;case 2:l="SENSOR";break;case 4:l="FLUID";break;default:l="ALL"}return this.zpp_inner.type==2?"InteractionListener{"+t+"#"+l+"::"+String(n.outer_zni.zpp_inner_zn.options1.outer)+":"+String(n.outer_zni.zpp_inner_zn.options2.outer)+"} precedence="+this.zpp_inner.precedence:"PreListener{"+l+"::"+String(n.outer_znp.zpp_inner_zn.options1.outer)+":"+String(n.outer_znp.zpp_inner_zn.options2.outer)+"} precedence="+this.zpp_inner.precedence}}};Gr.__name__=["nape","callbacks","Listener"];var ti=Gr;var rl=class rl{constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate ListenerType derp!")}static get BODY(){return T.ListenerType_BODY==null&&(T.internal=!0,T.ListenerType_BODY=new rl,T.internal=!1),T.ListenerType_BODY}static get CONSTRAINT(){return T.ListenerType_CONSTRAINT==null&&(T.internal=!0,T.ListenerType_CONSTRAINT=new rl,T.internal=!1),T.ListenerType_CONSTRAINT}static get INTERACTION(){return T.ListenerType_INTERACTION==null&&(T.internal=!0,T.ListenerType_INTERACTION=new rl,T.internal=!1),T.ListenerType_INTERACTION}static get PRE(){return T.ListenerType_PRE==null&&(T.internal=!0,T.ListenerType_PRE=new rl,T.internal=!1),T.ListenerType_PRE}toString(){return this===T.ListenerType_BODY?"BODY":this===T.ListenerType_CONSTRAINT?"CONSTRAINT":this===T.ListenerType_INTERACTION?"INTERACTION":this===T.ListenerType_PRE?"PRE":""}};rl.__name__=["nape","callbacks","ListenerType"];var sr=rl,ba=oe();ba.callbacks.ListenerType=sr;li();var an=class{constructor(){this.zpp_inner=null;if(!_t.internal)throw new Error("Error: Callback cannot be instantiated derp!")}get event(){return Ke.events[this.zpp_inner.event]}get listener(){return this.zpp_inner.listener.outer}toString(){return""}};an.__name__=["nape","callbacks","Callback"];var ol=class extends an{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)}};ol.__name__=["nape","callbacks","BodyCallback"];var al=class extends an{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)}};al.__name__=["nape","callbacks","ConstraintCallback"];var pl=class extends an{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)}};pl.__name__=["nape","callbacks","InteractionCallback"];var cl=class extends an{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)}};cl.__name__=["nape","callbacks","PreCallback"];var lr=class extends ti{constructor(e,t,n,l=0){if(Ke.internal=!0,super(),Ke.internal=!1,n==null)throw new Error("Error: BodyListener::handler cannot be null");let s;if(e===ft.WAKE)s=2;else if(e===ft.SLEEP)s=3;else throw new Error("Error: cbEvent '"+e.toString()+"' is not a valid event type for a BodyListener");this.zpp_inner_zn=new Ns(Ht.argument(t),s,n),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zn=this,this.zpp_inner.precedence=l}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}};lr.__name__=["nape","callbacks","BodyListener"];var rr=class extends ti{constructor(e,t,n,l=0){if(Ke.internal=!0,super(),Ke.internal=!1,n==null)throw new Error("Error: ConstraintListener::handler cannot be null");let s;if(e===ft.WAKE)s=2;else if(e===ft.SLEEP)s=3;else if(e===ft.BREAK)s=4;else throw new Error("Error: cbEvent '"+e.toString()+"' is not a valid event type for a ConstraintListener");this.zpp_inner_zn=new Os(Ht.argument(t),s,n),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zn=this,this.zpp_inner.precedence=l}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}};rr.__name__=["nape","callbacks","ConstraintListener"];function qr(S){return S===Ln.COLLISION?1:S===Ln.SENSOR?2:S===Ln.FLUID?4:7}function hl(S){return S==1?Ln.COLLISION:S==2?Ln.SENSOR:S==4?Ln.FLUID:S==7?Ln.ANY:null}var or=class extends ti{constructor(e,t,n,l,s,i=0){if(Ke.internal=!0,super(),Ke.internal=!1,s==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===ft.BEGIN)r=0;else if(e===ft.END)r=1;else if(e===ft.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(Ht.argument(n),Ht.argument(l),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=i,this.zpp_inner_zn.handleri=s,t==null)throw new Error("Error: Cannot set listener interaction type to null");hl(this.zpp_inner_zn.itype)!=t&&(this.zpp_inner_zn.itype=qr(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 hl(this.zpp_inner_zn.itype)}set interactionType(e){if(e==null)throw new Error("Error: Cannot set listener interaction type to null");hl(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=qr(e))}get allowSleepingCallbacks(){return this.zpp_inner_zn.allowSleepingCallbacks}set allowSleepingCallbacks(e){this.zpp_inner_zn.allowSleepingCallbacks=e}};or.__name__=["nape","callbacks","InteractionListener"];var ar=class extends ti{constructor(e,t,n,l,s=0,i=!1){if(Ke.internal=!0,super(),Ke.internal=!1,l==null)throw new Error("Error: PreListener must take a handler!");if(this.zpp_inner_zn=new es(Ht.argument(t),Ht.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=s,this.zpp_inner_zn.pure=i,this.zpp_inner_zn.handlerp=l,e==null)throw new Error("Error: Cannot set listener interaction type to null");hl(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=qr(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 hl(this.zpp_inner_zn.itype)}set interactionType(e){if(e==null)throw new Error("Error: Cannot set listener interaction type to null");hl(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=qr(e))}};ar.__name__=["nape","callbacks","PreListener"];var fs=class fs{constructor(){this.debugDraw=!0;this._inner=this}static _wrap(e){return e==null?null:e instanceof fs?e:e.zpp_inner?.outer instanceof fs?e.zpp_inner.outer:ve(e,t=>{let n=Object.create(fs.prototype);return n.zpp_inner=t.zpp_inner??t,n._inner=t,n.zpp_inner.outer=n,n.debugDraw=t.debugDraw??!0,n})}get space(){return this.zpp_inner.space==null?null:this.zpp_inner.space.outer}set space(e){if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");if((this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=e)if(this.zpp_inner.component!=null&&(this.zpp_inner.component.woken=!1),this.zpp_inner.clearcache(),this.zpp_inner.space!=null&&this.zpp_inner.space.wrap_constraints.remove(this),e!=null){let l=(e._inner?.zpp_inner??e.zpp_inner).wrap_constraints;l.zpp_inner.reverse_flag?l.push(this):l.unshift(this)}else this.zpp_inner.space=null}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(e){let t=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(t!=e&&(t?.zpp_inner.wrap_constraints.remove(this),e!=null)){let l=e.zpp_inner.wrap_constraints;l.zpp_inner.reverse_flag?l.push(this):l.unshift(this)}}get active(){return this.zpp_inner.active}set active(e){this.zpp_inner.active!=e&&(this.zpp_inner.component!=null&&(this.zpp_inner.component.woken=!1),this.zpp_inner.clearcache(),e?(this.zpp_inner.active=e,this.zpp_inner.activate(),this.zpp_inner.space!=null&&(this.zpp_inner.component!=null&&(this.zpp_inner.component.sleeping=!0),this.zpp_inner.space.wake_constraint(this.zpp_inner,!0))):(this.zpp_inner.space!=null&&(this.zpp_inner.wake(),this.zpp_inner.space.live_constraints.remove(this.zpp_inner)),this.zpp_inner.active=e,this.zpp_inner.deactivate()))}get ignore(){return this.zpp_inner.ignore}set ignore(e){this.zpp_inner.ignore!=e&&(this.zpp_inner.ignore=e,this.zpp_inner.wake())}get stiff(){return this.zpp_inner.stiff}set stiff(e){this.zpp_inner.stiff!=e&&(this.zpp_inner.stiff=e,this.zpp_inner.wake())}get frequency(){return this.zpp_inner.frequency}set frequency(e){if(e!==e)throw new Error("Error: Constraint::Frequency cannot be NaN");if(e<=0)throw new Error("Error: Constraint::Frequency must be >0");this.zpp_inner.frequency!=e&&(this.zpp_inner.frequency=e,this.zpp_inner.stiff||this.zpp_inner.wake())}get damping(){return this.zpp_inner.damping}set damping(e){if(e!==e)throw new Error("Error: Constraint::Damping cannot be Nan");if(e<0)throw new Error("Error: Constraint::Damping must be >=0");this.zpp_inner.damping!=e&&(this.zpp_inner.damping=e,this.zpp_inner.stiff||this.zpp_inner.wake())}get maxForce(){return this.zpp_inner.maxForce}set maxForce(e){if(e!==e)throw new Error("Error: Constraint::maxForce cannot be NaN");if(e<0)throw new Error("Error: Constraint::maxForce must be >=0");this.zpp_inner.maxForce!=e&&(this.zpp_inner.maxForce=e,this.zpp_inner.wake())}get maxError(){return this.zpp_inner.maxError}set maxError(e){if(e!==e)throw new Error("Error: Constraint::maxError cannot be NaN");if(e<0)throw new Error("Error: Constraint::maxError must be >=0");this.zpp_inner.maxError!=e&&(this.zpp_inner.maxError=e,this.zpp_inner.wake())}get breakUnderForce(){return this.zpp_inner.breakUnderForce}set breakUnderForce(e){this.zpp_inner.breakUnderForce!=e&&(this.zpp_inner.breakUnderForce=e,this.zpp_inner.wake())}get breakUnderError(){return this.zpp_inner.breakUnderError}set breakUnderError(e){this.zpp_inner.breakUnderError!=e&&(this.zpp_inner.breakUnderError=e,this.zpp_inner.wake())}get removeOnBreak(){return this.zpp_inner.removeOnBreak}set removeOnBreak(e){this.zpp_inner.removeOnBreak=e}get isSleeping(){if(this.zpp_inner.space==null||!this.zpp_inner.active)throw new Error("Error: isSleeping only makes sense if constraint is active and inside a space");return this.zpp_inner.component.sleeping}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get cbTypes(){return this.zpp_inner.wrap_cbTypes==null&&this.zpp_inner.setupcbTypes(),this.zpp_inner.wrap_cbTypes}impulse(){return null}bodyImpulse(e){return null}visitBodies(e){}copy(){return fs._wrap(this.zpp_inner.copy())}toString(){return"{Constraint}"}};fs.__name__=["nape","constraint","Constraint"],fs.zpp_internalAlloc=!1;var Dt=fs;var pr=class S extends Dt{constructor(e,t,n,l,s=1){super();let i=new We;if(this.zpp_inner=i,i.outer=this,i.outer_zn=this,this._setBody1(e),this._setBody2(t),this.zpp_inner.immutable_midstep("AngleJoint::jointMin"),n!==n)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(i.jointMin!=n&&(i.jointMin=n,i.wake()),this.zpp_inner.immutable_midstep("AngleJoint::jointMax"),l!==l)throw new Error("Error: AngleJoint::jointMax cannot be NaN");if(i.jointMax!=l&&(i.jointMax=l,i.wake()),this.zpp_inner.immutable_midstep("AngleJoint::ratio"),s!==s)throw new Error("Error: AngleJoint::ratio cannot be NaN");i.ratio!=s&&(i.ratio=s,i.wake())}static _wrap(e){return e==null?null:e instanceof S?e:e.zpp_inner?.outer instanceof S?e.zpp_inner.outer:e instanceof We?ve(e,t=>{let n=Object.create(S.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ve(e,t=>{let n=Object.create(S.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:et._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:et._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=oe(),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=oe();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};We._wrapFn=S=>ve(S,e=>{let t=Object.create(pr.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Io(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.x}function To(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.y}function ro(S){S.zpp_inner.weak&&S.dispose()}var cr=class S extends Dt{constructor(e,t,n,l,s,i){super();let r=new xi;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=Io(n),a=To(n);if(r.a1localx=o,r.a1localy=a,ro(n),l?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l==null)throw new Error("Error: Constraint::anchor2 cannot be null");let p=Io(l),c=To(l);if(r.a2localx=p,r.a2localy=c,ro(l),this.zpp_inner.immutable_midstep("DistanceJoint::jointMin"),s!==s)throw new Error("Error: DistanceJoint::jointMin cannot be NaN");if(s<0)throw new Error("Error: DistanceJoint::jointMin must be >= 0");if(r.jointMin!=s&&(r.jointMin=s,r.wake()),this.zpp_inner.immutable_midstep("DistanceJoint::jointMax"),i!==i)throw new Error("Error: DistanceJoint::jointMax cannot be NaN");if(i<0)throw new Error("Error: DistanceJoint::jointMax must be >= 0");r.jointMax!=i&&(r.jointMax=i,r.wake())}static _wrap(e){return e==null?null:e instanceof S?e:e.zpp_inner?.outer instanceof S?e.zpp_inner.outer:e instanceof xi?ve(e,t=>{let n=Object.create(S.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ve(e,t=>{let n=Object.create(S.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:et._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:et._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),ro(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),ro(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=oe(),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=oe();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};xi._wrapFn=S=>ve(S,e=>{let t=Object.create(cr.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Po(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.x}function wo(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.y}function hr(S){S.zpp_inner.weak&&S.dispose()}var ur=class S extends Dt{constructor(e,t,n,l,s,i,r){super();let o=new di;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=Po(n),o.a1localy=wo(n),hr(n),l?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l==null)throw new Error("Error: Constraint::anchor2 cannot be null");if(o.a2localx=Po(l),o.a2localy=wo(l),hr(l),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::direction cannot be null");if(o.nlocalx=Po(s),o.nlocaly=wo(s),o.zip_n=!0,hr(s),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),i!==i)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(o.jointMin!=i&&(o.jointMin=i,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 S?e:e.zpp_inner?.outer instanceof S?e.zpp_inner.outer:e instanceof di?ve(e,t=>{let n=Object.create(S.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ve(e,t=>{let n=Object.create(S.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:et._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:et._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),hr(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),hr(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),hr(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=oe(),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=oe();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};di._wrapFn=S=>ve(S,e=>{let t=Object.create(ur.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var _r=class S extends Dt{constructor(e,t,n=0,l=1){super();let s=new yi;if(this.zpp_inner=s,s.outer=this,s.outer_zn=this,this._setBody1(e),this._setBody2(t),this.zpp_inner.immutable_midstep("MotorJoint::rate"),n!==n)throw new Error("Error: MotorJoint::rate cannot be NaN");if(s.rate!=n&&(s.rate=n,s.wake()),this.zpp_inner.immutable_midstep("MotorJoint::ratio"),l!==l)throw new Error("Error: MotorJoint::ratio cannot be NaN");s.ratio!=l&&(s.ratio=l,s.wake())}static _wrap(e){return e==null?null:e instanceof S?e:e.zpp_inner?.outer instanceof S?e.zpp_inner.outer:e instanceof yi?ve(e,t=>{let n=Object.create(S.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ve(e,t=>{let n=Object.create(S.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:et._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:et._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=oe(),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=oe();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};yi._wrapFn=S=>ve(S,e=>{let t=Object.create(_r.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Bo(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Lo(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.y}function oo(S){S.zpp_inner.weak&&S.dispose()}var xr=class S extends Dt{constructor(e,t,n,l){super();let s=new mi;if(this.zpp_inner=s,s.outer=this,s.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(s.a1localx=Bo(n),s.a1localy=Lo(n),oo(n),l?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l==null)throw new Error("Error: Constraint::anchor2 cannot be null");s.a2localx=Bo(l),s.a2localy=Lo(l),oo(l)}static _wrap(e){return e==null?null:e instanceof S?e:e.zpp_inner?.outer instanceof S?e.zpp_inner.outer:e instanceof mi?ve(e,t=>{let n=Object.create(S.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ve(e,t=>{let n=Object.create(S.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:et._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:et._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),oo(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),oo(e)}impulse(){let e=oe(),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=oe();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};mi._wrapFn=S=>ve(S,e=>{let t=Object.create(xr.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Wr(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Jr(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Ur(S){S.zpp_inner.weak&&S.dispose()}var dr=class S extends Dt{constructor(e,t,n,l,s,i,r,o,a,p,c=1){super();let u=new fi;if(this.zpp_inner=u,u.outer=this,u.outer_zn=this,this._setBody1(e),this._setBody2(t),this._setBody3(n),this._setBody4(l),this._setAnchorInit(s,"anchor1",(h,x)=>{u.a1localx=h,u.a1localy=x}),this._setAnchorInit(i,"anchor2",(h,x)=>{u.a2localx=h,u.a2localy=x}),this._setAnchorInit(r,"anchor3",(h,x)=>{u.a3localx=h,u.a3localy=x}),this._setAnchorInit(o,"anchor4",(h,x)=>{u.a4localx=h,u.a4localy=x}),u.immutable_midstep("PulleyJoint::jointMin"),a!==a)throw new Error("Error: PulleyJoint::jointMin cannot be NaN");if(a<0)throw new Error("Error: PulleyJoint::jointMin must be >= 0");if(u.jointMin!=a&&(u.jointMin=a,u.wake()),u.immutable_midstep("PulleyJoint::jointMax"),p!==p)throw new Error("Error: PulleyJoint::jointMax cannot be NaN");if(p<0)throw new Error("Error: PulleyJoint::jointMax must be >= 0");if(u.jointMax!=p&&(u.jointMax=p,u.wake()),u.immutable_midstep("PulleyJoint::ratio"),c!==c)throw new Error("Error: PulleyJoint::ratio cannot be NaN");u.ratio!=c&&(u.ratio=c,u.wake())}_setAnchorInit(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::"+t+" cannot be null");n(Wr(e),Jr(e)),Ur(e)}static _wrap(e){return e==null?null:e instanceof S?e:e.zpp_inner?.outer instanceof S?e.zpp_inner.outer:e instanceof fi?ve(e,t=>{let n=Object.create(S.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ve(e,t=>{let n=Object.create(S.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:et._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}get body2(){return this.zpp_inner.b2==null?null:et._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}get body3(){return this.zpp_inner.b3==null?null:et._wrap(this.zpp_inner.b3)}set body3(e){this._setBody3(e)}get body4(){return this.zpp_inner.b4==null?null:et._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(),Wr(e),Jr(e),this.zpp_inner.wrap_a1.set(e),Ur(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(),Wr(e),Jr(e),this.zpp_inner.wrap_a2.set(e),Ur(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(),Wr(e),Jr(e),this.zpp_inner.wrap_a3.set(e),Ur(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(),Wr(e),Jr(e),this.zpp_inner.wrap_a4.set(e),Ur(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 Ai(1,1);if(0>=e.zpp_inner.m||0>=e.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return e.zpp_inner.x[0*e.zpp_inner.n]=this.zpp_inner.jAcc,e}bodyImpulse(e){if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let t=this.zpp_inner.b1?.outer??null,n=this.zpp_inner.b2?.outer??null,l=this.zpp_inner.b3?.outer??null,s=this.zpp_inner.b4?.outer??null;if(e!=t&&e!=n&&e!=l&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):$e.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1?.outer??null,n=this.zpp_inner.b2?.outer??null,l=this.zpp_inner.b3?.outer??null,s=this.zpp_inner.b4?.outer??null;t!=null&&e(t),n!=null&&n!=t&&e(n),l!=null&&l!=t&&l!=n&&e(l),s!=null&&s!=t&&s!=n&&s!=l&&e(s)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};fi._wrapFn=S=>ve(S,e=>{let t=Object.create(dr.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function jo(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Do(S){if(S.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=S.zpp_inner;return e._validate!=null&&e._validate(),e.y}function ao(S){S.zpp_inner.weak&&S.dispose()}var yr=class S extends Dt{constructor(e,t,n,l,s=0){super();let i=new bi;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=jo(n),i.a1localy=Do(n),ao(n),l?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l==null)throw new Error("Error: Constraint::anchor2 cannot be null");if(i.a2localx=jo(l),i.a2localy=Do(l),ao(l),this.zpp_inner.immutable_midstep("WeldJoint::phase"),s!==s)throw new Error("Error: WeldJoint::phase cannot be NaN");i.phase!=s&&(i.phase=s,i.wake())}static _wrap(e){return e==null?null:e instanceof S?e:e.zpp_inner?.outer instanceof S?e.zpp_inner.outer:e instanceof bi?ve(e,t=>{let n=Object.create(S.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):ve(e,t=>{let n=Object.create(S.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:et._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:et._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),ao(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),ao(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=oe(),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=oe();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};bi._wrapFn=S=>ve(S,e=>{let t=Object.create(yr.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var Kr=class S extends Dt{constructor(e,t=!1){if(super(),e<1)throw new Error("Error: Constraint dimension must be at least 1");let n=new Ts(e,t);this.zpp_inner=n,n.outer=this,n.outer_zn=this}static _wrap(e){return e==null?null:e instanceof S?e:e.zpp_inner?.outer instanceof S?e.zpp_inner.outer:ve(e,t=>{let n=Object.create(S.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 Fe;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 Ai(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):$e.get()}visitBodies(e){let t=this.zpp_inner.bodies.length,n=0;for(;n<t;){let l=this.zpp_inner.bodies[n];if(l.body!=null){let s=!1;for(let i=n+1;i<t;i++)if(this.zpp_inner.bodies[i].body==l.body){s=!0;break}s||e(l.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 jn(S){let{typeName:e,namespaceParts:t,zppListClass:n,wrapElement:l,unwrapElement:s}=S,i=oe(),r=i.__zpp,o=()=>r.util[n],a=()=>{let _=i;for(let d=1;d<t.length;d++)_=_[t[d]];return _};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.__name__=[...t,e+"Iterator"],p.zpp_pool=null,p.get=function(_){let d,b=o();return p.zpp_pool==null?(b.internal=!0,d=new p,b.internal=!1):(d=p.zpp_pool,p.zpp_pool=d.zpp_next),d.zpp_i=0,d.zpp_inner=_,d.zpp_critical=!1,d},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 _=this.zpp_inner;_.zpp_inner.valmod(),_.zpp_inner.zip_length&&(_.zpp_inner.zip_length=!1,_.zpp_inner.user_length=_.zpp_inner.inner.length);let d=_.zpp_inner.user_length;return this.zpp_critical=!0,this.zpp_i<d?!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.__name__=[...t,e+"List"],c.fromArray=function(_){if(_==null)throw new Error("Error: Cannot convert null Array to Nape list");let d=new c;for(let b=0;b<_.length;b++)d.push(_[b]);return d},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 u(_){return _.zpp_inner.valmod(),_.zpp_inner.zip_length&&(_.zpp_inner.zip_length=!1,_.zpp_inner.user_length=_.zpp_inner.inner.length),_.zpp_inner.user_length}Object.defineProperty(c.prototype,"length",{get:function(){return u(this)}}),c.prototype.has=function(_){return this.zpp_inner.valmod(),this.zpp_inner.inner.has(s(_))},c.prototype.at=function(_){if(this.zpp_inner.valmod(),_<0||_>=u(this))throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(_=u(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 l(this.zpp_inner.at_ite.elt)},c.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 d=this.zpp_inner.adder!=null?this.zpp_inner.adder(_):!0;return d&&(this.zpp_inner.reverse_flag?this.zpp_inner.inner.add(s(_)):(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.zpp_inner.inner.head==null?null:this.zpp_inner.inner.iterator_at(u(this)-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,s(_))),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(_)),d},c.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 d=this.zpp_inner.adder!=null?this.zpp_inner.adder(_):!0;return d&&(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(u(this)-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,s(_))):this.zpp_inner.inner.add(s(_)),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(_)),d},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 _;if(this.zpp_inner.reverse_flag){_=this.zpp_inner.inner.head.elt;let d=l(_);this.zpp_inner.subber!=null&&this.zpp_inner.subber(d),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 d;u(this)==1?d=null:d=this.zpp_inner.inner.iterator_at(u(this)-2),_=d==null?this.zpp_inner.inner.head.elt:d.next.elt;let b=l(_);this.zpp_inner.subber!=null&&this.zpp_inner.subber(b),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(d)}return this.zpp_inner.invalidate(),l(_)},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 _;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 d;u(this)==1?d=null:d=this.zpp_inner.inner.iterator_at(u(this)-2),_=d==null?this.zpp_inner.inner.head.elt:d.next.elt;let b=l(_);this.zpp_inner.subber!=null&&this.zpp_inner.subber(b),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(d)}else{_=this.zpp_inner.inner.head.elt;let d=l(_);this.zpp_inner.subber!=null&&this.zpp_inner.subber(d),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}return this.zpp_inner.invalidate(),l(_)},c.prototype.add=function(_){return this.zpp_inner.reverse_flag?this.push(_):this.unshift(_)},c.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 d=!1,b=this.zpp_inner.inner.head,m=s(_);for(;b!=null;){if(b.elt==m){d=!0;break}b=b.next}return d&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(_),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(m),this.zpp_inner.invalidate()),d},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(_){_==null&&(_=!1);let d=new c,b=p.get(this);for(;b.hasNext();){let m=b.next();if(_)throw new Error("Error: "+e+" is not a copyable type");d.push(m)}return d},c.prototype.merge=function(_){if(_==null)throw new Error("Error: Cannot merge with null list");let d=p.get(_);for(;d.hasNext();){let b=d.next();this.has(b)||(this.zpp_inner.reverse_flag?this.push(b):this.unshift(b))}},c.prototype.toString=function(){let _="[",d=!0,b=p.get(this);for(;b.hasNext();){let m=b.next();d||(_+=","),_+=m==null?"NULL":m.toString(),d=!1}return _+"]"},c.prototype.foreach=function(_){if(_==null)throw new Error("Error: Cannot execute null on list elements");this.zpp_inner.valmod();let d=p.get(this);for(;d.hasNext();)try{_(d.next())}catch{d.zpp_next=p.zpp_pool,p.zpp_pool=d,d.zpp_inner=null;break}return this},c.prototype.filter=function(_){if(_==null)throw new Error("Error: Cannot select elements of list with null");let d=0;for(;d<u(this);){let b=this.at(d);try{_(b)?++d:this.remove(b)}catch{break}}return this},c.prototype.toArray=function(){let _=[],d=p.get(this);for(;d.hasNext();)_.push(d.next());return _},c.prototype[Symbol.iterator]=function(){let _=p.get(this);return{next(){return _.hasNext()?{value:_.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};let h=a(),x=e+"Iterator",f=e+"List";return h[x]=p,h[f]=c,{Iterator:p,List:c}}var bs=S=>S.outer,Ti=S=>S.zpp_inner??(S._inner?S._inner.zpp_inner??S._inner:S);jn({typeName:"CbType",namespaceParts:["nape","callbacks"],zppListClass:"ZPP_CbTypeList",wrapElement:bs,unwrapElement:Ti});jn({typeName:"Listener",namespaceParts:["nape","callbacks"],zppListClass:"ZPP_ListenerList",wrapElement:bs,unwrapElement:Ti});jn({typeName:"Constraint",namespaceParts:["nape","constraint"],zppListClass:"ZPP_ConstraintList",wrapElement:bs,unwrapElement:Ti});jn({typeName:"InteractionGroup",namespaceParts:["nape","dynamics"],zppListClass:"ZPP_InteractionGroupList",wrapElement:bs,unwrapElement:Ti});jn({typeName:"GeomPoly",namespaceParts:["nape","geom"],zppListClass:"ZPP_GeomPolyList",wrapElement:bs,unwrapElement:Ti});jn({typeName:"Body",namespaceParts:["nape","phys"],zppListClass:"ZPP_BodyList",wrapElement:bs,unwrapElement:Ti});jn({typeName:"Compound",namespaceParts:["nape","phys"],zppListClass:"ZPP_CompoundList",wrapElement:bs,unwrapElement:Ti});jn({typeName:"Shape",namespaceParts:["nape","shape"],zppListClass:"ZPP_ShapeList",wrapElement:bs,unwrapElement:Ti});jn({typeName:"Arbiter",namespaceParts:["nape","dynamics"],zppListClass:"ZPP_ArbiterList",wrapElement:S=>S.wrapper(),unwrapElement:Ti});jn({typeName:"Edge",namespaceParts:["nape","shape"],zppListClass:"ZPP_EdgeList",wrapElement:S=>S.wrapper(),unwrapElement:Ti});jn({typeName:"ConvexResult",namespaceParts:["nape","geom"],zppListClass:"ZPP_ConvexResultList",wrapElement:S=>S,unwrapElement:S=>S});jn({typeName:"RayResult",namespaceParts:["nape","geom"],zppListClass:"ZPP_RayResultList",wrapElement:S=>S,unwrapElement:S=>S});jn({typeName:"Interactor",namespaceParts:["nape","phys"],zppListClass:"ZPP_InteractorList",wrapElement:S=>S.outer_i,unwrapElement:S=>S.zpp_inner_i});function ul(S){if(S.outer==null){let e=oe();S.outer=new e.geom.Vec2;let t=S.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=ie.zpp_pool,ie.zpp_pool=t,S.outer.zpp_inner=S}return S.outer}function Ft(){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}Ft.__name__=["zpp_nape","util","ZPP_MixVec2List"];Ft.__super__=ht;for(let S in ht.prototype)Ft.prototype[S]=ht.prototype[S];Object.defineProperty(Ft.prototype,"length",{get:function(){return this.zpp_gl()},configurable:!0});Ft.prototype.inner=null;Ft.prototype._length=0;Ft.prototype.zip_length=!1;Ft.prototype.at_ite=null;Ft.prototype.at_index=0;Ft.get=function(S,e){e==null&&(e=!1);let t=new Ft;return t.inner=S,t.zpp_inner.immutable=e,t};Ft.prototype.zpp_gl=function(){if(this.zpp_vm(),this.zip_length){this._length=0;let S=this.inner.next;for(;S!=null;)this._length++,S=S.next;this.zip_length=!1}return this._length};Ft.prototype.zpp_vm=function(){this.zpp_inner.validate(),this.inner.modified&&(this.zip_length=!0,this._length=0,this.at_ite=null)};Ft.prototype.at=function(S){if(this.zpp_vm(),S<0||S>=this.zpp_gl())throw new Error("Error: Index out of bounds");for(this.zpp_inner.reverse_flag&&(S=this.zpp_gl()-1-S),(S<this.at_index||this.at_ite==null)&&(this.at_index=0,this.at_ite=this.inner.next);this.at_index!==S;)this.at_index++,this.at_ite=this.at_ite.next;return ul(this.at_ite)};Ft.prototype.push=function(S){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.zpp_vm(),S.zpp_inner._inuse)throw new Error("Error: Vec2 is already in use");let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(S):!0;if(e){if(this.zpp_inner.reverse_flag)this.inner.add(S.zpp_inner);else{let t=this.inner.iterator_at(this.zpp_gl()-1);this.inner.insert(t,S.zpp_inner)}this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(S)}return e};Ft.prototype.unshift=function(S){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.zpp_vm(),S.zpp_inner._inuse)throw new Error("Error: Vec2 is already in use");let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(S):!0;if(e){if(this.zpp_inner.reverse_flag){let t=this.inner.iterator_at(this.zpp_gl()-1);this.inner.insert(t,S.zpp_inner)}else this.inner.add(S.zpp_inner);this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(S)}return e};Ft.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 S;if(this.zpp_inner.reverse_flag){S=this.inner.next;let e=ul(S);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);S=e==null?this.inner.next:e.next;let t=ul(S);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.inner.erase(e)}return this.zpp_inner.invalidate(),ul(S)};Ft.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 S;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);S=e==null?this.inner.next:e.next;let t=ul(S);this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.inner.erase(e)}else{S=this.inner.next;let e=ul(S);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.inner.pop()}return this.zpp_inner.invalidate(),ul(S)};Ft.prototype.remove=function(S){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(S.zpp_inner===t){e=!0;break}t=t.next}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(S),this.zpp_inner.dontremove||this.inner.remove(S.zpp_inner),this.zpp_inner.invalidate()),e};Ft.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 za=oe(),Pa=za.__zpp;Pa.util.ZPP_MixVec2List=Ft;var Ae=oe();Ae.Config=Object.assign(Ae.Config||{},mo);Ae.util.Debug=$r;Ae.geom.Vec2=Fe;Ae.geom.Vec3=$e;Ae.geom.Mat23=El;Ae.geom.MatMN=Ai;Ae.geom.AABB=ri;Ae.geom.Winding=Nl;Ae.geom.Ray=Cr;Ae.geom.ConvexResult=Sl;Ae.geom.RayResult=Al;Ae.geom.Geom=Il;Ae.geom.GeomPoly=Er;Ae.geom.MarchingSquares=Tl;Ae.geom.Vec2Iterator=Et;Ae.geom.Vec2List=ht;Ae.geom.GeomVertexIterator=xs;Ae.__zpp.geom.ZPP_GeomVertexIterator=oi;Ae.__zpp.util.ZPP_ContactList=vi;Ae.phys.Interactor=Xn;Ae.phys.Body=et;so(S=>et._wrap(S));Ae.phys.BodyType=Dl;Ae.phys.Compound=Vi;No(S=>Vi._wrap(S));Ae.phys.FluidProperties=ai;Ae.phys.Material=Fl;Ae.phys.GravMassMode=Gl;Ae.phys.InertiaMode=ql;Ae.phys.MassMode=Wl;Ae.shape.Shape=Tn;ko(S=>Tn._wrap(S));Ae.shape.Circle=Hs;Ae.shape.Polygon=Qs;Ae.shape.Edge=Jl;Ae.shape.ShapeType=Bl;Ae.shape.ValidationResult=Ul;Ae.space.Space=gi;Ae.space.Broadphase=Rr;Ae.dynamics.InteractionFilter=Kl;Ae.dynamics.InteractionGroup=Xl;Ae.dynamics.ArbiterType=Ql;Ae.dynamics.Arbiter=ei;ke._createColArb=()=>new tl;ke._createFluidArb=()=>new nl;Ae.dynamics.Contact=il;Ae.dynamics.ContactIterator=mt;Ae.dynamics.ContactList=kt;Ae.callbacks.CbEvent=ft;Ae.callbacks.CbType=er;Ae.callbacks.InteractionType=Ln;Ae.callbacks.PreFlag=tr;Ae.callbacks.OptionType=ir;Ae.callbacks.Listener=ti;Ae.callbacks.ListenerType=sr;Ae.callbacks.Callback=an;ol.__super__=an;_t._createBodyCb=()=>new ol;al.__super__=an;_t._createConCb=()=>new al;pl.__super__=an;_t._createIntCb=()=>new pl;cl.__super__=an;_t._createPreCb=()=>new cl;Ae.callbacks.BodyListener=lr;Ae.callbacks.ConstraintListener=rr;Ae.callbacks.InteractionListener=or;Ae.callbacks.PreListener=ar;Ae.constraint.Constraint=Dt;We._createFn=(...S)=>new pr(...S);xi._createFn=(...S)=>new cr(...S);di._createFn=(...S)=>new ur(...S);yi._createFn=(...S)=>new _r(...S);mi._createFn=(...S)=>new xr(...S);fi._createFn=(...S)=>new dr(...S);bi._createFn=(...S)=>new yr(...S);Ae.constraint.UserConstraint=Kr;var hw="3.7.5";export{ri as AABB,pr as AngleJoint,ei as Arbiter,Ql as ArbiterType,et as Body,ol as BodyCallback,lr as BodyListener,Dl as BodyType,Rr as Broadphase,an as Callback,ft as CbEvent,er as CbType,Hs as Circle,tl as CollisionArbiter,Vi as Compound,Dt as Constraint,al as ConstraintCallback,rr as ConstraintListener,il as Contact,Sl as ConvexResult,cr as DistanceJoint,Jl as Edge,nl as FluidArbiter,ai as FluidProperties,Il as Geom,Er as GeomPoly,Gl as GravMassMode,ql as InertiaMode,pl as InteractionCallback,Kl as InteractionFilter,Xl as InteractionGroup,or as InteractionListener,Ln as InteractionType,Xn as Interactor,ur as LineJoint,ti as Listener,sr as ListenerType,Tl as MarchingSquares,Wl as MassMode,El as Mat23,Ai as MatMN,Fl as Material,_r as MotorJoint,Ar as NapeList,ir as OptionType,xr as PivotJoint,Qs as Polygon,cl as PreCallback,tr as PreFlag,ar as PreListener,dr as PulleyJoint,Cr as Ray,Al as RayResult,Tn as Shape,Bl as ShapeType,gi as Space,Kr as UserConstraint,hw as VERSION,Ul as ValidationResult,Fe as Vec2,$e as Vec3,yr as WeldJoint,Nl as Winding};
|
|
1
|
+
import{$ as En,A as sn,B as et,C as mn,D as X,E as c,F as $,G as v,H as L,I as C,J as Ye,K as je,L as yn,M as ge,N as dn,O as nt,P as tt,Q as rt,R as bn,S as lt,T as gn,U as wn,V as an,W as _t,X as We,Y as it,Z as pt,_ as ln,a as i,aa as _n,b as U,ba as Pn,c as Mn,ca as xn,d as ne,da as Cn,e as Y,ea as vn,f as T,fa as Nn,g as Un,ga as In,h as Yn,ha as An,i as rn,ia as Tn,j as B,ja as Ke,k as jn,ka as Ln,l as E,la as Sn,m as Wn,ma as Zn,n as Kn,na as Vn,o as Jn,oa as On,p as qn,pa as kn,q as Hn,qa as Rn,r as Xn,s as $n,t as Z,u as te,v as pn,w as on,x as be,y as j,z as Qn}from"./chunk-3TXNIYBK.js";var Bn={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},ot=c();ot.Config=Object.assign(ot.Config||{},Bn);function a(t,e,n){for(;t[e]!=null;){let r=t[e][n];t[e][n]=null,t[e]=r}}var un=class{static version(){return"Nape 2.0.19"}static clearObjectPools(){let e=c(),n=e.__zpp;a(e.constraint.ConstraintIterator,"zpp_pool","zpp_next"),a(e.phys.InteractorIterator,"zpp_pool","zpp_next"),a(e.phys.BodyIterator,"zpp_pool","zpp_next"),a(e.phys.CompoundIterator,"zpp_pool","zpp_next"),a(e.callbacks.ListenerIterator,"zpp_pool","zpp_next"),a(e.callbacks.CbTypeIterator,"zpp_pool","zpp_next"),a(e.geom.ConvexResultIterator,"zpp_pool","zpp_next"),a(e.geom.GeomPolyIterator,"zpp_pool","zpp_next"),a(e.geom.Vec2Iterator,"zpp_pool","zpp_next"),a(e.geom.RayResultIterator,"zpp_pool","zpp_next"),a(e.shape.ShapeIterator,"zpp_pool","zpp_next"),a(e.shape.EdgeIterator,"zpp_pool","zpp_next"),a(e.dynamics.ContactIterator,"zpp_pool","zpp_next"),a(e.dynamics.ArbiterIterator,"zpp_pool","zpp_next"),a(e.dynamics.InteractionGroupIterator,"zpp_pool","zpp_next"),a(n.util.ZNPNode_ZPP_CbType,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_CallbackSet,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Shape,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Body,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Constraint,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Compound,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Arbiter,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_InteractionListener,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_CbSet,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Interactor,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_BodyListener,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_CbSetPair,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_ConstraintListener,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_CutInt,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_CutVert,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_PartitionVertex,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_SimplifyP,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_PartitionedPoly,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_GeomVert,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_SimpleVert,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_SimpleEvent,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Vec2,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_AABBPair,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Edge,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_AABBNode,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Component,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_FluidArbiter,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_SensorArbiter,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_Listener,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_ColArbiter,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_InteractionGroup,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_ToiEvent,"zpp_pool","next"),a(n.util.ZNPNode_ConvexResult,"zpp_pool","next"),a(n.util.ZNPNode_ZPP_GeomPoly,"zpp_pool","next"),a(n.util.ZNPNode_RayResult,"zpp_pool","next"),a(n.phys.ZPP_Material,"zpp_pool","next"),a(n.phys.ZPP_FluidProperties,"zpp_pool","next"),a(n.callbacks.ZPP_CbSetPair,"zpp_pool","next"),a(n.callbacks.ZPP_Callback,"zpp_pool","next"),a(n.callbacks.ZPP_CbSet,"zpp_pool","next"),a(n.geom.ZPP_GeomVert,"zpp_pool","next"),a(n.geom.ZPP_GeomVertexIterator,"zpp_pool","next"),a(n.geom.ZPP_Mat23,"zpp_pool","next"),a(n.geom.ZPP_CutVert,"zpp_pool","next"),a(n.geom.ZPP_CutInt,"zpp_pool","next"),a(n.geom.ZPP_Vec2,"zpp_pool","next"),a(n.geom.ZPP_PartitionVertex,"zpp_pool","next"),a(n.geom.ZPP_SimplifyV,"zpp_pool","next"),a(n.geom.ZPP_SimplifyP,"zpp_pool","next"),a(n.geom.ZPP_PartitionedPoly,"zpp_pool","next"),a(n.geom.ZPP_PartitionPair,"zpp_pool","next"),a(n.geom.ZPP_AABB,"zpp_pool","next"),a(n.geom.ZPP_SimpleVert,"zpp_pool","next"),a(n.geom.ZPP_SimpleSeg,"zpp_pool","next"),a(n.geom.ZPP_SimpleEvent,"zpp_pool","next"),a(n.util.Hashable2_Boolfalse,"zpp_pool","next"),a(n.geom.ZPP_ToiEvent,"zpp_pool","next"),a(n.geom.ZPP_MarchSpan,"zpp_pool","next"),a(n.geom.ZPP_MarchPair,"zpp_pool","next"),a(n.shape.ZPP_Edge,"zpp_pool","next"),a(n.space.ZPP_SweepData,"zpp_pool","next"),a(n.space.ZPP_AABBNode,"zpp_pool","next"),a(n.space.ZPP_AABBPair,"zpp_pool","next"),a(n.dynamics.ZPP_Contact,"zpp_pool","next"),a(n.space.ZPP_Island,"zpp_pool","next"),a(n.space.ZPP_Component,"zpp_pool","next"),a(n.space.ZPP_CallbackSet,"zpp_pool","next"),a(n.dynamics.ZPP_SensorArbiter,"zpp_pool","next"),a(n.dynamics.ZPP_FluidArbiter,"zpp_pool","next"),a(n.dynamics.ZPP_ColArbiter,"zpp_pool","next"),a(n.dynamics.ZPP_InteractionFilter,"zpp_pool","next"),a(n.util.ZPP_Set_ZPP_Body,"zpp_pool","next"),a(n.util.ZPP_Set_ZPP_CbSetPair,"zpp_pool","next"),a(n.util.ZPP_Set_ZPP_PartitionVertex,"zpp_pool","next"),a(n.util.ZPP_Set_ZPP_PartitionPair,"zpp_pool","next"),a(n.util.ZPP_Set_ZPP_SimpleVert,"zpp_pool","next"),a(n.util.ZPP_Set_ZPP_SimpleSeg,"zpp_pool","next"),a(n.util.ZPP_Set_ZPP_SimpleEvent,"zpp_pool","next"),a(n.util.ZPP_Set_ZPP_CbSet,"zpp_pool","next"),a(n.util.ZPP_PubPool,"poolGeomPoly","zpp_pool"),a(n.util.ZPP_PubPool,"poolVec2","zpp_pool"),a(n.util.ZPP_PubPool,"poolVec3","zpp_pool")}};var F=class F{get _inner(){return this}constructor(e=1,n=0,r=0,p=1,o=0,s=0){let _=sn.get();this.zpp_inner=_,_.outer=this;let f=["a","b","tx","c","d","ty"],y=[e,n,o,r,p,s];for(let h=0;h<y.length;h++)if(y[h]!==y[h])throw new Error("Error: Mat23::"+f[h]+" cannot be NaN");_.setas(e,n,r,p,o,s)}static rotation(e){if(e!==e)throw new Error("Error: Cannot create rotation matrix with NaN angle");let n=Math.cos(e),r=Math.sin(e);return new F(n,-r,r,n,0,0)}static translation(e,n){return new F(1,0,0,1,e,n)}static scale(e,n){return new F(e,0,0,n,0,0)}static _wrap(e){return e instanceof F?e:e?e instanceof sn?v(e,n=>{let r=Object.create(F.prototype);return r.zpp_inner=n,n.outer=r,r}):e.zpp_inner?F._wrap(e.zpp_inner):null:null}_setProp(e,n){if(n!==n)throw new Error("Error: Mat23::"+e+" cannot be NaN");this.zpp_inner[e]=n,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,n=0){if(e==null)return!1;let r=this.zpp_inner,p=e.zpp_inner,o=r.a-p.a,s=r.b-p.b,_=r.c-p.c,f=r.d-p.d,y=r.tx-p.tx,h=r.ty-p.ty;return(o<0?-o:o)<=n&&(s<0?-s:s)<=n&&(_<0?-_:_)<=n&&(f<0?-f:f)<=n&&(y<0?-y:y)<=n&&(h<0?-h:h)<=n}copy(){return new F(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 n=e.zpp_inner;return this.zpp_inner.setas(n.a,n.b,n.c,n.d,n.tx,n.ty),this.zpp_inner.invalidate(),this}setAs(e=1,n=0,r=0,p=1,o=0,s=0){return this.zpp_inner.setas(e,n,r,p,o,s),this.zpp_inner.invalidate(),this}reset(){return this.setAs()}singular(){let{a:e,b:n,c:r,d:p}=this.zpp_inner,o=e*e+n*n+r*r+p*p,s=e*p-n*r;s<0&&(s=-s);let _=c();return o>_.Config.illConditionedThreshold*s}inverse(){if(this.singular())throw new Error("Error: Matrix is singular and cannot be inverted");let{a:e,b:n,c:r,d:p,tx:o,ty:s}=this.zpp_inner,_=1/(e*p-n*r);return new F(p*_,-n*_,-r*_,e*_,(n*s-p*o)*_,(r*o-e*s)*_)}transpose(){let{a:e,b:n,c:r,d:p,tx:o,ty:s}=this.zpp_inner;return new F(e,r,n,p,-e*o-r*s,-n*o-p*s)}concat(e){if(e==null)throw new Error("Error: Cannot concatenate with null Mat23");let n=e.zpp_inner,r=this.zpp_inner;return new F(n.a*r.a+n.b*r.c,n.a*r.b+n.b*r.d,n.c*r.a+n.d*r.c,n.c*r.b+n.d*r.d,n.a*r.tx+n.b*r.ty+n.tx,n.c*r.tx+n.d*r.ty+n.ty)}transform(e,n=!1,r=!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 p=e.zpp_inner.x,o=e.zpp_inner.y,{a:s,b:_,c:f,d:y,tx:h,ty:m}=this.zpp_inner,d,g;n?(d=p*s+o*_,g=p*f+o*y):(d=p*s+o*_+h,g=p*f+o*y+m);let R=L.get(d,g,r);return e.zpp_inner.weak&&e.dispose(),R}inverseTransform(e,n=!1,r=!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:p,b:o,c:s,d:_,tx:f,ty:y}=this.zpp_inner,h=1/(p*_-o*s);e.zpp_inner.validate();let m=e.zpp_inner.x,d=e.zpp_inner.y,g,R;if(n)g=(m*_-d*o)*h,R=(d*p-m*s)*h;else{let l=m-f,u=d-y;g=(l*_-u*o)*h,R=(u*p-l*s)*h}let q=L.get(g,R,r);return e.zpp_inner.weak&&e.dispose(),q}equiorthogonal(){if(this.singular())return!1;let{a:e,b:n,c:r,d:p}=this.zpp_inner,o=c(),s=e*n+r*p;if(s*s>=o.Config.epsilon)return!1;let _=e*e+n*n-r*r-p*p;return _*_<o.Config.epsilon}orthogonal(){let{a:e,b:n,c:r,d:p}=this.zpp_inner,o=c(),s=e*n+r*p;if(s*s>=o.Config.epsilon)return!1;let _=e*e+n*n-1,f=r*r+p*p-1;return _*_<o.Config.epsilon&&f*f<o.Config.epsilon}_orthogonaliseImpl(e){let{a:n,b:r,c:p,d:o}=this.zpp_inner,s=c(),_=Math.sqrt(n*n+p*p),f=Math.sqrt(r*r+o*o);if(_*_<s.Config.epsilon||f*f<s.Config.epsilon)throw new Error("Error: Matrix is singular and cannot be "+(e?"equiorthogonal":"orthogonal")+"ised");let y=e?(_+f)/2:1;_=y/_,f=y/f,this.a=this.zpp_inner.a*_,this.c=this.zpp_inner.c*_,this.b=this.zpp_inner.b*f,this.d=this.zpp_inner.d*f;let h=this.zpp_inner.a*this.zpp_inner.b+this.zpp_inner.c*this.zpp_inner.d,m=.25*Math.PI-.5*Math.acos(h/(y*y));this.zpp_inner.a*this.zpp_inner.d-this.zpp_inner.b*this.zpp_inner.c>0&&(m=-m);let d=Math.sin(m),g=Math.cos(m),R=this.zpp_inner.a*g-this.zpp_inner.c*d,q=this.zpp_inner.b*g+this.zpp_inner.d*d,l=this.zpp_inner.c*g+this.zpp_inner.a*d,u=this.zpp_inner.d*g-this.zpp_inner.b*d;return this.c=l,this.a=R,this.d=u,this.b=q,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:n,c:r,d:p,tx:o,ty:s}=this.zpp_inner;return"{ a: "+e+" b: "+n+" c: "+r+" d: "+p+" tx: "+o+" ty: "+s+" }"}};F.__name__=["nape","geom","Mat23"];var we=F;sn._wrapFn=t=>v(t,e=>{let n=Object.create(we.prototype);return n.zpp_inner=e,e.outer=n,n});function hn(t){if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=t.zpp_inner;return e._validate!=null&&e._validate(),e.x}function cn(t){if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=t.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Ee(t){t.zpp_inner.weak&&t.dispose()}var re=class re{get _inner(){return this}constructor(e,n){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(n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Ray::direction cannot be null");let r=new et;this.zpp_inner=r;let p=hn(e),o=cn(e);r.origin.zpp_inner.x=p,r.origin.zpp_inner.y=o,r.origin.zpp_inner._invalidate!=null&&r.origin.zpp_inner._invalidate(r.origin.zpp_inner),Ee(e);let s=hn(n),_=cn(n);r.direction.zpp_inner.x=s,r.direction.zpp_inner.y=_,r.direction.zpp_inner._invalidate!=null&&r.direction.zpp_inner._invalidate(r.direction.zpp_inner),Ee(n),r.zip_dir=!0,r.maxdist=1/0}static _wrap(e){return e==null?null:e instanceof re?e:v(e,n=>{let r=Object.create(re.prototype);return r.zpp_inner=n.zpp_inner??n,r})}static fromSegment(e,n){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(n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Ray::fromSegment::end is null");let r=n.sub(e,!0),p=new re(e,r),o=hn(e),s=cn(e),_=hn(n),f=cn(n),y=_-o,h=f-s,m=Math.sqrt(y*y+h*h);if(m!==m)throw new Error("Error: maxDistance cannot be NaN");return p.zpp_inner.maxdist=m,Ee(e),Ee(n),p}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),Ee(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,Ee(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 je._wrap(this.zpp_inner.rayAABB())}at(e,n=!1){this.zpp_inner.validate_dir();let r=this.zpp_inner.origin.zpp_inner;r._validate!=null&&r._validate();let p=r.x,o=r.y,s=p+e*this.zpp_inner.dirx,_=o+e*this.zpp_inner.diry;return L.get(s,_,n)}clone(){return this.copy()}copy(){let e=new re(this.zpp_inner.origin,this.zpp_inner.direction),n=this.zpp_inner.maxdist;if(n!==n)throw new Error("Error: maxDistance cannot be NaN");return e.zpp_inner.maxdist=n,e}};re.__name__=["nape","geom","Ray"];var Je=re;var qe=class qe{get _inner(){return this}constructor(){if(this.zpp_inner=null,!be.internal)throw new Error("Error: ConvexResult cannot be instantiated derp!")}static _wrap(e){if(!e)return null;if(e instanceof qe)return e;let n=e.zpp_inner??e;return v(n,r=>{let p=Object.create(qe.prototype);return p.zpp_inner=r,p})}get normal(){return this._disposed(),L._wrap(this.zpp_inner.normal)}get position(){return this._disposed(),L._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")}};qe.__name__=["nape","geom","ConvexResult"];var Pe=qe;be._createConvexResult=()=>new Pe;var He=class He{get _inner(){return this}constructor(){if(this.zpp_inner=null,!be.internal)throw new Error("Error: RayResult cannot be instantiated derp!")}static _wrap(e){if(!e)return null;if(e instanceof He)return e;let n=e.zpp_inner??e;return v(n,r=>{let p=Object.create(He.prototype);return p.zpp_inner=r,p})}get normal(){return this._disposed(),L._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")}};He.__name__=["nape","geom","RayResult"];var xe=He;be._createRayResult=()=>new xe;function ie(t){return t?.zpp_inner??t?._inner?.zpp_inner}function zn(t){return t?.zpp_inner??t?._inner?.zpp_inner}function fn(t,e){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");n._isimmutable!=null&&n._isimmutable()}function Ce(t,e){if(ie(t)?.body?.outer==null)throw new Error(`Error: Shape must be part of a Body to calculate ${e}`)}var ve=class{static distanceBody(e,n,r,p){fn(r,"out1"),fn(p,"out2");let o=zn(e),s=zn(n);if(o.shapes.head==null||s.shapes.head==null)throw new Error("Error: Bodies cannot be empty in calculating distances");let _=o.shapes.head;for(;_!=null;)j.validateShape(_.elt),_=_.next;for(_=s.shapes.head;_!=null;)j.validateShape(_.elt),_=_.next;return mn.distanceBody(o,s,r.zpp_inner,p.zpp_inner)}static distance(e,n,r,p){fn(r,"out1"),fn(p,"out2"),Ce(e,"distances"),Ce(n,"distances");let o=ie(e),s=ie(n);j.validateShape(o),j.validateShape(s);let _;E.zpp_pool==null?_=new E:(_=E.zpp_pool,E.zpp_pool=_.next,_.next=null),_.weak=!1;let f=mn.distance(o,s,r.zpp_inner,p.zpp_inner,_,1e100);return _.next=E.zpp_pool,E.zpp_pool=_,f}static intersectsBody(e,n){let r=zn(e),p=zn(n);if(r.shapes.head==null||p.shapes.head==null)throw new Error("Error: Bodies must have shapes to test for intersection.");let o=r.shapes.head;for(;o!=null;)j.validateShape(o.elt),o=o.next;for(o=p.shapes.head;o!=null;)j.validateShape(o.elt),o=o.next;let s=r.aabb,_=p.aabb;if(s.minx>_.maxx||s.maxx<_.minx||s.miny>_.maxy||s.maxy<_.miny)return!1;let f=r.shapes.head;for(;f!=null;){let y=p.shapes.head;for(;y!=null;){if(on.testCollide_safe(f.elt,y.elt))return!0;y=y.next}f=f.next}return!1}static intersects(e,n){Ce(e,"intersection"),Ce(n,"intersection");let r=ie(e),p=ie(n);j.validateShape(r),j.validateShape(p);let o=r.aabb,s=p.aabb;return o.minx>s.maxx||o.maxx<s.minx||o.miny>s.maxy||o.maxy<s.miny?!1:on.testCollide_safe(r,p)}static contains(e,n){Ce(e,"containment"),Ce(n,"containment");let r=ie(e),p=ie(n);return j.validateShape(r),j.validateShape(p),on.containTest(r,p)}};ve.__name__=["nape","geom","Geom"];var Ne=class{static run(e,n,r,p=2,o=null,s=!0,_=null){if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(o!=null&&o.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(n==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 f=r.zpp_inner;if(f._validate!=null&&f._validate(),f.x<=0||f.y<=0)throw new Error("Error: MarchingSquares cannot operate with non-positive cell dimensions");if(p<0)throw new Error("Error: MarchingSquares cannot use a negative quality value for interpolation");if(o!=null){let g=o.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 y=c(),h=_??new y.geom.GeomPolyList,m=Qn,d=n.zpp_inner;if(d._validate!=null&&d._validate(),o==null){let g=d.minx,R=d.miny,q=d.maxx,l=d.maxy;m.run(e,g,R,q,l,r,p,s,h)}else{let g=o.zpp_inner;g._validate!=null&&g._validate();let R=d.maxx-d.minx,q=d.maxy-d.miny,l=R/g.x,u=q/g.y,b=l|0,M=u|0;b!==l&&++b,M!==u&&++M;for(let nn=0;nn<b;nn++){let Gn=d.minx+g.x*nn,st=nn===b-1?d.maxx:Gn+g.x;for(let tn=0;tn<M;tn++){let Dn=d.miny+g.y*tn,at=tn===M-1?d.maxy:Dn+g.y;m.run(e,Gn,Dn,st,at,r,p,s,h)}}}return f.weak&&r.dispose(),o!=null&&o.zpp_inner.weak&&o.dispose(),h}};Ne.__name__=["nape","geom","MarchingSquares"];var H=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 Mn,this._invalidated=!0}static get(e,n){n==null&&(n=!1);let r=c(),p=new r.geom.Vec2List;return p.zpp_inner.inner=e,n&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}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)}};H.__name__=["zpp_nape","util","ZPP_Vec2List"],H.internal=!1;function pe(t){if(t.outer==null){let e=c();t.outer=new e.geom.Vec2;let n=t.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=E.zpp_pool,E.zpp_pool=n,t.outer.zpp_inner=t}return t.outer}function N(){if(this.zpp_next=null,this.zpp_critical=!1,this.zpp_i=0,this.zpp_inner=null,!H.internal)throw new Error("Error: Cannot instantiate Vec2Iterator derp!")}N.__name__=["nape","geom","Vec2Iterator"];N.zpp_pool=null;N.get=function(t){let e;return N.zpp_pool==null?(H.internal=!0,e=new N,H.internal=!1):(e=N.zpp_pool,N.zpp_pool=e.zpp_next),e.zpp_i=0,e.zpp_inner=t,e.zpp_critical=!1,e};N.prototype.zpp_inner=null;N.prototype.zpp_i=null;N.prototype.zpp_critical=null;N.prototype.zpp_next=null;N.prototype.hasNext=function(){this.zpp_inner.zpp_inner.valmod();let t=this.zpp_inner.zpp_gl();return this.zpp_critical=!0,this.zpp_i<t?!0:(this.zpp_next=N.zpp_pool,N.zpp_pool=this,this.zpp_inner=null,!1)};N.prototype.next=function(){return this.zpp_critical=!1,this.zpp_inner.at(this.zpp_i++)};function w(){this.zpp_inner=null,this.zpp_inner=new H,this.zpp_inner.outer=this}w.__name__=["nape","geom","Vec2List"];w.fromArray=function(t){if(t==null)throw new Error("Error: Cannot convert null Array to Nape list");let e=c(),n=new e.geom.Vec2List;for(let r=0;r<t.length;r++)n.push(t[r]);return n};w.prototype.zpp_inner=null;Object.defineProperty(w.prototype,"length",{get:function(){return this.zpp_gl()}});w.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};w.prototype.zpp_vm=function(){this.zpp_inner.valmod()};w.prototype.has=function(t){return this.zpp_vm(),this.zpp_inner.inner.has(t.zpp_inner)};w.prototype.at=function(t){if(this.zpp_vm(),t<0||t>=this.zpp_gl())throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(t=this.zpp_gl()-1-t),t<this.zpp_inner.at_index||this.zpp_inner.at_ite==null)this.zpp_inner.at_index=t,this.zpp_inner.at_ite=this.zpp_inner.inner.iterator_at(t);else for(;this.zpp_inner.at_index!=t;)this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;return pe(this.zpp_inner.at_ite.elt)};w.prototype.push=function(t){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(t):!0;return e&&(this.zpp_inner.reverse_flag?this.zpp_inner.inner.add(t.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,t.zpp_inner)),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(t)),e};w.prototype.unshift=function(t){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(t):!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,t.zpp_inner)):this.zpp_inner.inner.add(t.zpp_inner),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(t)),e};w.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 t;if(this.zpp_inner.reverse_flag){t=this.zpp_inner.inner.head.elt;let e=pe(t);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);t=e==null?this.zpp_inner.inner.head.elt:e.next.elt;let n=pe(t);this.zpp_inner.subber!=null&&this.zpp_inner.subber(n),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(e)}return this.zpp_inner.invalidate(),pe(t)};w.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 t;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);t=e==null?this.zpp_inner.inner.head.elt:e.next.elt;let n=pe(t);this.zpp_inner.subber!=null&&this.zpp_inner.subber(n),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(e)}else{t=this.zpp_inner.inner.head.elt;let e=pe(t);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}return this.zpp_inner.invalidate(),pe(t)};w.prototype.add=function(t){return this.zpp_inner.reverse_flag?this.push(t):this.unshift(t)};w.prototype.remove=function(t){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=!1,n=this.zpp_inner.inner.head;for(;n!=null;){if(n.elt==t.zpp_inner){e=!0;break}n=n.next}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(t.zpp_inner),this.zpp_inner.invalidate()),e};w.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()};w.prototype.empty=function(){return this.zpp_gl()==0};w.prototype.iterator=function(){return this.zpp_vm(),N.get(this)};w.prototype.copy=function(t){t==null&&(t=!1);let e=c(),n=new e.geom.Vec2List,r=N.get(this);for(;r.hasNext();){let p=r.next(),o;if(t){if(p!=null&&p.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=p.zpp_inner;s._validate!=null&&s._validate();let _=p.zpp_inner.x,f=p.zpp_inner;f._validate!=null&&f._validate();let y=p.zpp_inner.y,h;if(U.poolVec2==null?h=new e.geom.Vec2:(h=U.poolVec2,U.poolVec2=h.zpp_pool,h.zpp_pool=null,h.zpp_disp=!1,h==U.nextVec2&&(U.nextVec2=null)),h.zpp_inner==null){let m;E.zpp_pool==null?m=new E:(m=E.zpp_pool,E.zpp_pool=m.next,m.next=null),m.weak=!1,m._immutable=!1,m.x=_,m.y=y,h.zpp_inner=m,h.zpp_inner.outer=h}else h.zpp_inner.x=_,h.zpp_inner.y=y,h.zpp_inner._invalidate!=null&&h.zpp_inner._invalidate(h.zpp_inner);h.zpp_inner.weak=!1,o=h}else o=p;n.push(o)}return n};w.prototype.merge=function(t){if(t==null)throw new Error("Error: Cannot merge with null list");let e=t.iterator();for(;e.hasNext();){let n=e.next();this.has(n)||this.add(n)}};w.prototype.toString=function(){let t="[",e=!0,n=N.get(this);for(;n.hasNext();){let r=n.next();e||(t+=","),t+=r==null?"NULL":r.toString(),e=!1}return t+"]"};w.prototype.foreach=function(t){if(t==null)throw new Error("Error: Cannot execute null on list elements");let e=this.iterator();for(;e.hasNext();)try{t(e.next())}catch{e.zpp_next=N.zpp_pool,N.zpp_pool=e,e.zpp_inner=null;break}return this};w.prototype[Symbol.iterator]=function(){let t=N.get(this);return{next(){return t.hasNext()?{value:t.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};w.prototype.filter=function(t){if(t==null)throw new Error("Error: Cannot select elements of list with null");let e=0;for(;e<this.zpp_gl();){let n=this.at(e);try{t(n)?++e:this.remove(n)}catch{break}}return this};function Q(){if(!ge.internal)throw new Error("Error: Cannot instantiate GeomVertexIterator")}Q.__name__=["nape","geom","GeomVertexIterator"];Q.prototype.zpp_inner=null;Q.prototype.hasNext=function(){if(this.zpp_inner==null)throw new Error("Error: Iterator has been disposed");let t=this.zpp_inner.ptr!=this.zpp_inner.start||this.zpp_inner.first;if(this.zpp_inner.first=!1,!t){let e=this.zpp_inner;e.outer.zpp_inner=null,e.ptr=e.start=null,e.next=ge.zpp_pool,ge.zpp_pool=e}return t};Q.prototype.next=function(){if(this.zpp_inner==null)throw new Error("Error: Iterator has been disposed");let t=this.zpp_inner.ptr;if(t.wrap==null){let n=t.x,r=t.y;if(n!==n||r!==r)throw new Error("Error: Vec2 components cannot be NaN");let p=c(),o;if(U.poolVec2==null?o=new p.geom.Vec2:(o=U.poolVec2,U.poolVec2=o.zpp_pool,o.zpp_pool=null,o.zpp_disp=!1,o==U.nextVec2&&(U.nextVec2=null)),o.zpp_inner==null){let s;E.zpp_pool==null?s=new E:(s=E.zpp_pool,E.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=n,s.y=r,o.zpp_inner=s,o.zpp_inner.outer=o}else{if(o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=o.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable(),s.x==n&&s.y==r||(s.x=n,s.y=r,s._invalidate!=null&&s._invalidate(s))}o.zpp_inner.weak=!1,t.wrap=o,t.wrap.zpp_inner._inuse=!0,t.wrap.zpp_inner._invalidate=s=>t.modwrap(s),t.wrap.zpp_inner._validate=()=>t.getwrap()}let e=t.wrap;return this.zpp_inner.ptr=this.zpp_inner.forward?this.zpp_inner.ptr.next:this.zpp_inner.ptr.prev,e};Q.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 ut=c();ut.geom.GeomVertexIterator=Q;var W=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 te,this._invalidated=!0}static get(e,n){n==null&&(n=!1);let r=c(),p=new r.dynamics.ContactList;return p.zpp_inner.inner=e,n&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}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)}};W.__name__=["zpp_nape","util","ZPP_ContactList"],W.internal=!1;var Xe=class Xe{constructor(){if(!X.internal)throw new Error("Error: Cannot instantiate an Edge derp!")}static _wrap(e){return e?e instanceof Xe?e:e instanceof X?v(e,n=>{X.internal=!0;let r=new Xe;return X.internal=!1,r.zpp_inner=n,n.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 n=c();if(e.outer==null){e.outer=new n.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=E.zpp_pool,E.zpp_pool=r,e.outer.zpp_inner=e}return e.outer}};Xe.__name__=["nape","shape","Edge"];var Ie=Xe;X._wrapFn=t=>v(t,e=>{X.internal=!0;let n=new Ie;return X.internal=!1,n.zpp_inner=e,e.outer=n,n});var oe=class oe{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 oe,i.internal=!1),i.ValidationResult_VALID}static get DEGENERATE(){return i.ValidationResult_DEGENERATE==null&&(i.internal=!0,i.ValidationResult_DEGENERATE=new oe,i.internal=!1),i.ValidationResult_DEGENERATE}static get CONCAVE(){return i.ValidationResult_CONCAVE==null&&(i.internal=!0,i.ValidationResult_CONCAVE=new oe,i.internal=!1),i.ValidationResult_CONCAVE}static get SELF_INTERSECTING(){return i.ValidationResult_SELF_INTERSECTING==null&&(i.internal=!0,i.ValidationResult_SELF_INTERSECTING=new oe,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":""}};oe.__name__=["nape","shape","ValidationResult"];var Ae=oe,ht=c();ht.shape.ValidationResult=Ae;var Te=class Te{get _inner(){return this}constructor(e=!1){let n=new pn;this.zpp_inner=n,n.outer=this,n.ignore!=e&&(n.invalidate(!0),n.ignore=e)}static _wrap(e){return e instanceof Te?e:e?e instanceof pn?v(e,n=>{let r=Object.create(Te.prototype);return r.zpp_inner=n,n.outer=r,r}):e.zpp_inner?Te._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=c();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=c();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}};Te.__name__=["nape","dynamics","InteractionGroup"];var Le=Te;pn._wrapFn=t=>v(t,e=>{let n=Object.create(Le.prototype);return n.zpp_inner=e,e.outer=n,n});var Se=class Se{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 Se,i.internal=!1),i.ArbiterType_COLLISION}static get SENSOR(){return i.ArbiterType_SENSOR==null&&(i.internal=!0,i.ArbiterType_SENSOR=new Se,i.internal=!1),i.ArbiterType_SENSOR}static get FLUID(){return i.ArbiterType_FLUID==null&&(i.internal=!0,i.ArbiterType_FLUID=new Se,i.internal=!1),i.ArbiterType_FLUID}toString(){return this===i.ArbiterType_COLLISION?"COLLISION":this===i.ArbiterType_SENSOR?"SENSOR":this===i.ArbiterType_FLUID?"FLUID":""}};Se.__name__=["nape","dynamics","ArbiterType"];var Ze=Se,ct=c();ct.dynamics.ArbiterType=Ze;$();var G=class{get _inner(){return this}constructor(){if(this.zpp_inner=null,!Z.internal)throw new Error("Error: Cannot instantiate Arbiter derp!")}get isSleeping(){return this._activeCheck(),this.zpp_inner.sleeping}get type(){return Z.types[this.zpp_inner.type]}get collisionArbiter(){return this.zpp_inner.type==Z.COL?this.zpp_inner.colarb.outer_zn:null}get fluidArbiter(){return this.zpp_inner.type==Z.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=c(),n=this.zpp_inner.immState;return n==5?(i.PreFlag_ACCEPT==null&&(i.internal=!0,i.PreFlag_ACCEPT=new e.callbacks.PreFlag,i.internal=!1),i.PreFlag_ACCEPT):n==1?(i.PreFlag_ACCEPT_ONCE==null&&(i.internal=!0,i.PreFlag_ACCEPT_ONCE=new e.callbacks.PreFlag,i.internal=!1),i.PreFlag_ACCEPT_ONCE):n==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==Z.COL}isFluidArbiter(){return this.zpp_inner.type==Z.FLUID}isSensorArbiter(){return this.zpp_inner.type==Z.SENSOR}totalImpulse(e=null,n=!1){return this._activeCheck(),e!=null&&this._checkBody(e),C.get(0,0,0)}toString(){let e=this.zpp_inner.type==Z.COL?"CollisionArbiter":this.zpp_inner.type==Z.FLUID?"FluidArbiter":"SensorArbiter";if(this.zpp_inner.cleared)return e+"(object-pooled)";this._activeCheck();let n=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,p=e+"("+n.toString()+"|"+r.toString()+")";return this.zpp_inner.type==Z.COL&&(p+="["+["SD","DD"][this.zpp_inner.colarb.stat?0:1]+"]"),p+="<-"+this.state.toString(),p}_activeCheck(){if(!this.zpp_inner.active)throw new Error("Error: Arbiter not currently in use")}_checkBody(e){let n=this.zpp_inner,r=n.ws1.id>n.ws2.id?n.b2.outer:n.b1.outer,p=n.ws1.id>n.ws2.id?n.b1.outer:n.b2.outer;if(e!=r&&e!=p)throw new Error("Error: Arbiter does not relate to body")}};G.__name__=["nape","dynamics","Arbiter"];var zt=c();zt.dynamics.Arbiter=G;var se=class extends G{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 n=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws2.outer:this.zpp_inner.ws1.outer;n.zpp_inner.type==1?n.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 n=this.zpp_inner.ws1.id>this.zpp_inner.ws2.id?this.zpp_inner.ws1.outer:this.zpp_inner.ws2.outer;n.zpp_inner.type==1?n.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,n=!1){return this._activeCheck(),e!=null&&this._checkBody(e),this._accumulateImpulse("normalImpulse",e,n)}tangentImpulse(e=null,n=!1){return this._activeCheck(),e!=null&&this._checkBody(e),this._accumulateImpulse("tangentImpulse",e,n)}totalImpulse(e=null,n=!1){return this._activeCheck(),e!=null&&this._checkBody(e),this._accumulateImpulse("totalImpulse",e,n)}rollingImpulse(e=null,n=!1){this._activeCheck(),e!=null&&this._checkBody(e);let r=this.zpp_inner.colarb;return!n||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,n,r){let p=0,o=0,s=0,_=this.zpp_inner.colarb;if(!r||_.oc1.fresh){let f=_.oc1.wrapper()[e](n),y=f.zpp_inner;y._validate!=null&&y._validate(),p+=y.x,y._validate!=null&&y._validate(),o+=y.y,y._validate!=null&&y._validate(),s+=y.z,f.dispose()}if(_.hc2&&(!r||_.oc2.fresh)){let f=_.oc2.wrapper()[e](n),y=f.zpp_inner;y._validate!=null&&y._validate(),p+=y.x,y._validate!=null&&y._validate(),o+=y.y,y._validate!=null&&y._validate(),s+=y.z,f.dispose()}return C.get(p,o,s)}};se.__name__=["nape","dynamics","CollisionArbiter"],se.__super__=G;var ae=class extends G{constructor(){super()}get position(){return this._activeCheck(),this.zpp_inner.fluidarb.wrap_position==null&&this.zpp_inner.fluidarb.getposition(),L._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 n=this.zpp_inner.fluidarb;return e==null?C.get(n.buoyx,n.buoyy,0):e.zpp_inner==this.zpp_inner.b2?C.get(n.buoyx,n.buoyy,n.buoyy*n.r2x-n.buoyx*n.r2y):C.get(-n.buoyx,-n.buoyy,-(n.buoyy*n.r1x-n.buoyx*n.r1y))}dragImpulse(e=null){this._activeCheck(),e!=null&&this._checkBody(e);let n=this.zpp_inner.fluidarb,r=e==null||e.zpp_inner==this.zpp_inner.b2?1:-1;return C.get(n.dampx*r,n.dampy*r,n.adamp*r)}totalImpulse(e=null,n=!1){this._activeCheck(),e!=null&&this._checkBody(e);let r=this.buoyancyImpulse(e),p=this.dragImpulse(e),o=r.zpp_inner,s=p.zpp_inner;return o._validate!=null&&o._validate(),s._validate!=null&&s._validate(),s.x=s.x+o.x,o._validate!=null&&o._validate(),s._validate!=null&&s._validate(),s.y=s.y+o.y,o._validate!=null&&o._validate(),s._validate!=null&&s._validate(),s.z=s.z+o.z,r.dispose(),p}};ae.__name__=["nape","dynamics","FluidArbiter"],ae.__super__=G;var le=class{get _inner(){return this}constructor(){if(this.zpp_inner=null,!te.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==Z.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(),L._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 n=this.zpp_inner.arbiter.colarb,r=this.zpp_inner.inner,p=r.jnAcc;return e==null?C.get(n.nx*p,n.ny*p):(this._checkBody(e,n),e==n.b1.outer?C.get(n.nx*-p,n.ny*-p,-(n.ny*r.r1x-n.nx*r.r1y)*p):C.get(n.nx*p,n.ny*p,(n.ny*r.r2x-n.nx*r.r2y)*p))}tangentImpulse(e=null){this._inactiveCheck();let n=this.zpp_inner.arbiter.colarb,r=this.zpp_inner.inner,p=r.jtAcc;return e==null?C.get(-n.ny*p,n.nx*p):(this._checkBody(e,n),e==n.b1.outer?C.get(n.ny*p,-n.nx*p,-(r.r1x*n.nx+r.r1y*n.ny)*p):C.get(-n.ny*p,n.nx*p,(r.r2x*n.nx+r.r2y*n.ny)*p))}rollingImpulse(e=null){this._inactiveCheck();let n=this.zpp_inner.arbiter.colarb,r=n.jrAcc;return e==null?r:(this._checkBody(e,n),e==n.b1.outer?-r:r)}totalImpulse(e=null){this._inactiveCheck();let n=this.zpp_inner.arbiter.colarb,r=this.zpp_inner.inner,p=r.jnAcc,o=r.jtAcc,s=n.jrAcc;if(e==null)return C.get(n.nx*p-n.ny*o,n.ny*p+n.nx*o,s);this._checkBody(e,n);let _=n.nx*p-n.ny*o,f=n.ny*p+n.nx*o;return e==n.b1.outer?C.get(-_,-f,-(f*r.r1x-_*r.r1y)-s):C.get(_,f,f*r.r2x-_*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,n){if(e!=n.b1.outer&&e!=n.b2.outer)throw new Error("Error: Contact does not relate to the given body")}};le.__name__=["nape","dynamics","Contact"];te._wrapFn=t=>{te.internal=!0;let e=new le;return te.internal=!1,e.zpp_inner=t,t.outer=e,e};function ft(t){let e=0,n=t.inner.next;for(;n!=null;)n.active&&n.arbiter.active&&e++,n=n.next;return e}function V(t){return t.valmod(),t.zip_length&&(t.zip_length=!1,t.user_length=ft(t)),t.user_length}function P(){if(this.zpp_next=null,this.zpp_critical=!1,this.zpp_i=0,this.zpp_inner=null,!W.internal)throw new Error("Error: Cannot instantiate ContactIterator derp!")}P.__name__=["nape","dynamics","ContactIterator"];P.zpp_pool=null;P.get=function(t){let e;return P.zpp_pool==null?(W.internal=!0,e=new P,W.internal=!1):(e=P.zpp_pool,P.zpp_pool=e.zpp_next),e.zpp_i=0,e.zpp_inner=t,e.zpp_critical=!1,e};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 t=V(this.zpp_inner.zpp_inner);return this.zpp_critical=!0,this.zpp_i<t?!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 I(){this.zpp_inner=null,this.zpp_inner=new W,this.zpp_inner.outer=this}I.__name__=["nape","dynamics","ContactList"];I.fromArray=function(t){if(t==null)throw new Error("Error: Cannot convert null Array to Nape list");let e=c(),n=new e.dynamics.ContactList;for(let r=0;r<t.length;r++)n.push(t[r]);return n};I.prototype.zpp_inner=null;Object.defineProperty(I.prototype,"length",{get:function(){return V(this.zpp_inner)}});I.prototype.has=function(t){return this.zpp_inner.valmod(),this.zpp_inner.inner.has(t.zpp_inner)};I.prototype.at=function(t){this.zpp_inner.valmod();let e=V(this.zpp_inner);if(t<0||t>=e)throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(t=V(this.zpp_inner)-1-t),t<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 n=this.zpp_inner.at_ite;if(n.active&&n.arbiter.active)break;this.zpp_inner.at_ite=this.zpp_inner.at_ite.next}for(;this.zpp_inner.at_index!=t;)for(this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;;){let n=this.zpp_inner.at_ite;if(n.active&&n.arbiter.active)break;this.zpp_inner.at_ite=this.zpp_inner.at_ite.next}return this.zpp_inner.at_ite.wrapper()};I.prototype.push=function(t){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(t):!0;if(e){if(this.zpp_inner.reverse_flag)this.zpp_inner.inner.add(t.zpp_inner);else{if(this.zpp_inner.push_ite==null){let n=V(this.zpp_inner);n==0?this.zpp_inner.push_ite=null:this.zpp_inner.push_ite=this.zpp_inner.inner.iterator_at(n-1)}this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,t.zpp_inner)}this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(t)}return e};I.prototype.unshift=function(t){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(t):!0;if(e){if(this.zpp_inner.reverse_flag){if(this.zpp_inner.push_ite==null){let n=V(this.zpp_inner);n==0?this.zpp_inner.push_ite=null:this.zpp_inner.push_ite=this.zpp_inner.inner.iterator_at(n-1)}this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,t.zpp_inner)}else this.zpp_inner.inner.add(t.zpp_inner);this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(t)}return e};I.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 n=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(n),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 n=V(this.zpp_inner),r;n==1?r=null:r=this.zpp_inner.inner.iterator_at(n-2),e=r==null?this.zpp_inner.inner.next:r.next;let p=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(p),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(r)}return this.zpp_inner.invalidate(),e.wrapper()};I.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 n=V(this.zpp_inner),r;n==1?r=null:r=this.zpp_inner.inner.iterator_at(n-2),e=r==null?this.zpp_inner.inner.next:r.next;let p=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(p),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(r)}else{e=this.zpp_inner.inner.next;let n=e.wrapper();this.zpp_inner.subber!=null&&this.zpp_inner.subber(n),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}return this.zpp_inner.invalidate(),e.wrapper()};I.prototype.add=function(t){return this.zpp_inner.reverse_flag?this.push(t):this.unshift(t)};I.prototype.remove=function(t){if(this.zpp_inner.immutable)throw new Error("Error: ContactList is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let e=!1,n=this.zpp_inner.inner.next;for(;n!=null;){if(n==t.zpp_inner){e=!0;break}n=n.next}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(t.zpp_inner),this.zpp_inner.invalidate()),e};I.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()};I.prototype.empty=function(){return V(this.zpp_inner)==0};I.prototype.iterator=function(){return this.zpp_inner.valmod(),P.get(this)};I.prototype.copy=function(t){t==null&&(t=!1);let e=c(),n=new e.dynamics.ContactList;this.zpp_inner.valmod();let r=P.get(this);for(;r.hasNext();){let p=r.next();if(t)throw new Error("Error: Contact is not a copyable type");n.push(p)}return n};I.prototype.merge=function(t){if(t==null)throw new Error("Error: Cannot merge with null list");t.zpp_inner.valmod();let e=P.get(t);for(;e.hasNext();){let n=e.next();this.has(n)||(this.zpp_inner.reverse_flag?this.push(n):this.unshift(n))}};I.prototype.toString=function(){let t="[",e=!0;this.zpp_inner.valmod();let n=P.get(this);for(;n.hasNext();){let r=n.next();e||(t+=","),t+=r==null?"NULL":r.toString(),e=!1}return t+"]"};I.prototype.foreach=function(t){if(t==null)throw new Error("Error: Cannot execute null on list elements");this.zpp_inner.valmod();let e=P.get(this);for(;e.hasNext();)try{t(e.next())}catch{e.zpp_next=P.zpp_pool,P.zpp_pool=e,e.zpp_inner=null;break}return this};I.prototype[Symbol.iterator]=function(){let t=P.get(this);return{next(){return t.hasNext()?{value:t.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};I.prototype.filter=function(t){if(t==null)throw new Error("Error: Cannot select elements of list with null");let e=0;for(;;){let n=V(this.zpp_inner);if(!(e<n))break;let r=this.at(e);try{t(r)?++e:this.remove(r)}catch{break}}return this};var K=class K{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 K,i.internal=!1),i.CbEvent_BEGIN}static get ONGOING(){return i.CbEvent_ONGOING==null&&(i.internal=!0,i.CbEvent_ONGOING=new K,i.internal=!1),i.CbEvent_ONGOING}static get END(){return i.CbEvent_END==null&&(i.internal=!0,i.CbEvent_END=new K,i.internal=!1),i.CbEvent_END}static get WAKE(){return i.CbEvent_WAKE==null&&(i.internal=!0,i.CbEvent_WAKE=new K,i.internal=!1),i.CbEvent_WAKE}static get SLEEP(){return i.CbEvent_SLEEP==null&&(i.internal=!0,i.CbEvent_SLEEP=new K,i.internal=!1),i.CbEvent_SLEEP}static get BREAK(){return i.CbEvent_BREAK==null&&(i.internal=!0,i.CbEvent_BREAK=new K,i.internal=!1),i.CbEvent_BREAK}static get PRE(){return i.CbEvent_PRE==null&&(i.internal=!0,i.CbEvent_PRE=new K,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":""}};K.__name__=["nape","callbacks","CbEvent"];var x=K,mt=c();mt.callbacks.CbEvent=x;$();var Ve=class Ve{get _inner(){return this}constructor(){this.zpp_inner=new Y,this.zpp_inner.outer=this}static get ANY_BODY(){return Y.ANY_BODY}static get ANY_CONSTRAINT(){return Y.ANY_CONSTRAINT}static get ANY_SHAPE(){return Y.ANY_SHAPE}static get ANY_COMPOUND(){return Y.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=pt.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=it.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}including(e){return new(c()).callbacks.OptionType(this).including(e)}excluding(e){return new(c()).callbacks.OptionType(this).excluding(e)}toString(){return this===Y.ANY_BODY?"ANY_BODY":this===Y.ANY_SHAPE?"ANY_SHAPE":this===Y.ANY_COMPOUND?"ANY_COMPOUND":this===Y.ANY_CONSTRAINT?"ANY_CONSTRAINT":"CbType#"+this.zpp_inner.id}static _wrap(e){return e instanceof Ve?e:e?e instanceof Y?v(e,n=>{let r=Object.create(Ve.prototype);return r.zpp_inner=n,n.outer=r,r}):e.zpp_inner?Ve._wrap(e.zpp_inner):null:null}};Ve.__name__=["nape","callbacks","CbType"];var Oe=Ve,yt=c();yt.callbacks.CbType=Oe;$();var _e=class _e{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 _e,i.internal=!1),i.InteractionType_COLLISION}static get SENSOR(){return i.InteractionType_SENSOR==null&&(i.internal=!0,i.InteractionType_SENSOR=new _e,i.internal=!1),i.InteractionType_SENSOR}static get FLUID(){return i.InteractionType_FLUID==null&&(i.internal=!0,i.InteractionType_FLUID=new _e,i.internal=!1),i.InteractionType_FLUID}static get ANY(){return i.InteractionType_ANY==null&&(i.internal=!0,i.InteractionType_ANY=new _e,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":""}};_e.__name__=["nape","callbacks","InteractionType"];var O=_e,dt=c();dt.callbacks.InteractionType=O;var ue=class ue{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 ue,i.internal=!1),i.PreFlag_ACCEPT}static get IGNORE(){return i.PreFlag_IGNORE==null&&(i.internal=!0,i.PreFlag_IGNORE=new ue,i.internal=!1),i.PreFlag_IGNORE}static get ACCEPT_ONCE(){return i.PreFlag_ACCEPT_ONCE==null&&(i.internal=!0,i.PreFlag_ACCEPT_ONCE=new ue,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 ue,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":""}};ue.__name__=["nape","callbacks","PreFlag"];var ke=ue,bt=c();bt.callbacks.PreFlag=ke;var Re=class Re{get _inner(){return this}constructor(e,n){this.zpp_inner=new B,this.zpp_inner.outer=this,e!=null&&this.including(e),n!=null&&this.excluding(n)}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 n=this.zpp_inner.wrap_excludes.toString();return"@{"+e+" excluding "+n+"}"}static _wrap(e){return e instanceof Re?e:e?e instanceof B?v(e,n=>{let r=Object.create(Re.prototype);return r.zpp_inner=n,n.outer=r,r}):e.zpp_inner?Re._wrap(e.zpp_inner):null:null}};Re.__name__=["nape","callbacks","OptionType"];var Be=Re,gt=c();gt.callbacks.OptionType=Be;function wt(t){return t===x.BEGIN?0:t===x.END?1:t===x.WAKE?2:t===x.SLEEP?3:t===x.BREAK?4:t===x.PRE?5:t===x.ONGOING?6:-1}var $e=class $e{get _inner(){return this}constructor(){if(!T.internal)throw new Error("Error: Cannot instantiate Listener derp!");this.zpp_inner=null}static _wrap(e){return e instanceof $e?e:e&&e instanceof T?v(e,n=>{if(n.outer)return n.outer;let r=Object.create($e.prototype);return r.zpp_inner=n,n.outer=r,r}):null}get type(){return T.types[this.zpp_inner.type]}get event(){return T.events[this.zpp_inner.event]}set event(e){if(e==null)throw new Error("Error: Cannot set listener event type to null");if(T.events[this.zpp_inner.event]!=e){let n=wt(e);this.zpp_inner.swapEvent(n)}}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:We._wrap(this.zpp_inner.space.outer)}set space(e){let n=e!=null?e._inner??e:null;if((this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=n)if(this.zpp_inner.space!=null&&this.zpp_inner.space.wrap_listeners.remove(this),n!=null){let p=n.zpp_inner.wrap_listeners;p.zpp_inner.reverse_flag?p.push(this):p.unshift(this)}else this.zpp_inner.space=null}toString(){let n=["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{"+n+"::"+String(r.outer_zn.zpp_inner_zn.options.outer)+"}"}else if(this.zpp_inner.type==1){let r=this.zpp_inner.constraint;return"ConstraintListener{"+n+"::"+String(r.outer_zn.zpp_inner_zn.options.outer)+"}"}else{let r=this.zpp_inner.interaction,p;switch(r.itype){case 1:p="COLLISION";break;case 2:p="SENSOR";break;case 4:p="FLUID";break;default:p="ALL"}return this.zpp_inner.type==2?"InteractionListener{"+n+"#"+p+"::"+String(r.outer_zni.zpp_inner_zn.options1.outer)+":"+String(r.outer_zni.zpp_inner_zn.options2.outer)+"} precedence="+this.zpp_inner.precedence:"PreListener{"+p+"::"+String(r.outer_znp.zpp_inner_zn.options1.outer)+":"+String(r.outer_znp.zpp_inner_zn.options2.outer)+"} precedence="+this.zpp_inner.precedence}}};$e.__name__=["nape","callbacks","Listener"];var D=$e;var he=class he{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 he,i.internal=!1),i.ListenerType_BODY}static get CONSTRAINT(){return i.ListenerType_CONSTRAINT==null&&(i.internal=!0,i.ListenerType_CONSTRAINT=new he,i.internal=!1),i.ListenerType_CONSTRAINT}static get INTERACTION(){return i.ListenerType_INTERACTION==null&&(i.internal=!0,i.ListenerType_INTERACTION=new he,i.internal=!1),i.ListenerType_INTERACTION}static get PRE(){return i.ListenerType_PRE==null&&(i.internal=!0,i.ListenerType_PRE=new he,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":""}};he.__name__=["nape","callbacks","ListenerType"];var Fe=he,Et=c();Et.callbacks.ListenerType=Fe;$();var S=class{constructor(){this.zpp_inner=null;if(!ne.internal)throw new Error("Error: Callback cannot be instantiated derp!")}get event(){return T.events[this.zpp_inner.event]}get listener(){return this.zpp_inner.listener.outer}toString(){return""}};S.__name__=["nape","callbacks","Callback"];var ce=class extends S{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)}};ce.__name__=["nape","callbacks","BodyCallback"];var ze=class extends S{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)}};ze.__name__=["nape","callbacks","ConstraintCallback"];var fe=class extends S{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)}};fe.__name__=["nape","callbacks","InteractionCallback"];var me=class extends S{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)}};me.__name__=["nape","callbacks","PreCallback"];var Ge=class extends D{constructor(e,n,r,p=0){if(T.internal=!0,super(),T.internal=!1,r==null)throw new Error("Error: BodyListener::handler cannot be null");let o;if(e===x.WAKE)o=2;else if(e===x.SLEEP)o=3;else throw new Error("Error: cbEvent '"+e.toString()+"' is not a valid event type for a BodyListener");this.zpp_inner_zn=new Un(B.argument(n),o,r),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zn=this,this.zpp_inner.precedence=p}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}};Ge.__name__=["nape","callbacks","BodyListener"];var De=class extends D{constructor(e,n,r,p=0){if(T.internal=!0,super(),T.internal=!1,r==null)throw new Error("Error: ConstraintListener::handler cannot be null");let o;if(e===x.WAKE)o=2;else if(e===x.SLEEP)o=3;else if(e===x.BREAK)o=4;else throw new Error("Error: cbEvent '"+e.toString()+"' is not a valid event type for a ConstraintListener");this.zpp_inner_zn=new Yn(B.argument(n),o,r),this.zpp_inner=this.zpp_inner_zn,this.zpp_inner.outer=this,this.zpp_inner_zn.outer_zn=this,this.zpp_inner.precedence=p}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}};De.__name__=["nape","callbacks","ConstraintListener"];function Qe(t){return t===O.COLLISION?1:t===O.SENSOR?2:t===O.FLUID?4:7}function ye(t){return t==1?O.COLLISION:t==2?O.SENSOR:t==4?O.FLUID:t==7?O.ANY:null}var Me=class extends D{constructor(e,n,r,p,o,s=0){if(T.internal=!0,super(),T.internal=!1,o==null)throw new Error("Error: InteractionListener::handler cannot be null");if(e==null)throw new Error("Error: CbEvent cannot be null for InteractionListener");let _;if(e===x.BEGIN)_=0;else if(e===x.END)_=1;else if(e===x.ONGOING)_=6;else throw new Error("Error: CbEvent '"+e.toString()+"' is not a valid event type for InteractionListener");if(this.zpp_inner_zn=new rn(B.argument(r),B.argument(p),_,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=o,n==null)throw new Error("Error: Cannot set listener interaction type to null");ye(this.zpp_inner_zn.itype)!=n&&(this.zpp_inner_zn.itype=Qe(n))}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 ye(this.zpp_inner_zn.itype)}set interactionType(e){if(e==null)throw new Error("Error: Cannot set listener interaction type to null");ye(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=Qe(e))}get allowSleepingCallbacks(){return this.zpp_inner_zn.allowSleepingCallbacks}set allowSleepingCallbacks(e){this.zpp_inner_zn.allowSleepingCallbacks=e}};Me.__name__=["nape","callbacks","InteractionListener"];var Ue=class extends D{constructor(e,n,r,p,o=0,s=!1){if(T.internal=!0,super(),T.internal=!1,p==null)throw new Error("Error: PreListener must take a handler!");if(this.zpp_inner_zn=new rn(B.argument(n),B.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=o,this.zpp_inner_zn.pure=s,this.zpp_inner_zn.handlerp=p,e==null)throw new Error("Error: Cannot set listener interaction type to null");ye(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=Qe(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 ye(this.zpp_inner_zn.itype)}set interactionType(e){if(e==null)throw new Error("Error: Cannot set listener interaction type to null");ye(this.zpp_inner_zn.itype)!=e&&(this.zpp_inner_zn.itype=Qe(e))}};Ue.__name__=["nape","callbacks","PreListener"];var en=class t extends Ke{constructor(e,n=!1){if(super(),e<1)throw new Error("Error: Constraint dimension must be at least 1");let r=new Xn(e,n);this.zpp_inner=r,r.outer=this,r.outer_zn=this}static _wrap(e){return e==null?null:e instanceof t?e:e.zpp_inner?.outer instanceof t?e.zpp_inner.outer:v(e,n=>{let r=Object.create(t.prototype);return r.zpp_inner=n.zpp_inner??n,r.zpp_inner.outer=r,r.zpp_inner.outer_zn=r,r})}__bindVec2(){let e=new L;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,n,r){throw new Error("Error: UserConstraint::__impulse must be overriden")}impulse(){let e=this.zpp_inner.dim,n=new Ye(e,1);for(let r=0;r<e;r++){if(r<0||r>=n.zpp_inner.m||0>=n.zpp_inner.n)throw new Error("Error: MatMN indices out of range");n.zpp_inner.x[r*n.zpp_inner.n]=this.zpp_inner.jAcc[r]}return n}bodyImpulse(e){if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=!1;for(let r of this.zpp_inner.bodies)if(r.body==e.zpp_inner){n=!0;break}if(!n)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):C.get()}visitBodies(e){let n=this.zpp_inner.bodies.length,r=0;for(;r<n;){let p=this.zpp_inner.bodies[r];if(p.body!=null){let o=!1;for(let s=r+1;s<n;s++)if(this.zpp_inner.bodies[s].body==p.body){o=!0;break}o||e(p.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,n){if(this.zpp_inner.immutable_midstep("UserConstraint::registerBody(..)"),e!=n){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()}n!=null&&this.zpp_inner.addBody(n.zpp_inner),this.zpp_inner.wake(),n?.zpp_inner.wake()}return n}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};function k(t){let{typeName:e,namespaceParts:n,zppListClass:r,wrapElement:p,unwrapElement:o}=t,s=c(),_=s.__zpp,f=()=>_.util[r],y=()=>{let l=s;for(let u=1;u<n.length;u++)l=l[n[u]];return l};function h(){if(this.zpp_next=null,this.zpp_critical=!1,this.zpp_i=0,this.zpp_inner=null,!f().internal)throw new Error("Error: Cannot instantiate "+e+"Iterator derp!")}h.__name__=[...n,e+"Iterator"],h.zpp_pool=null,h.get=function(l){let u,b=f();return h.zpp_pool==null?(b.internal=!0,u=new h,b.internal=!1):(u=h.zpp_pool,h.zpp_pool=u.zpp_next),u.zpp_i=0,u.zpp_inner=l,u.zpp_critical=!1,u},h.prototype.zpp_inner=null,h.prototype.zpp_i=null,h.prototype.zpp_critical=null,h.prototype.zpp_next=null,h.prototype.hasNext=function(){this.zpp_inner.zpp_inner.valmod();let l=this.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 u=l.zpp_inner.user_length;return this.zpp_critical=!0,this.zpp_i<u?!0:(this.zpp_next=h.zpp_pool,h.zpp_pool=this,this.zpp_inner=null,!1)},h.prototype.next=function(){return this.zpp_critical=!1,this.zpp_inner.at(this.zpp_i++)};function m(){this.zpp_inner=null,this.zpp_inner=new(f()),this.zpp_inner.outer=this}m.__name__=[...n,e+"List"],m.fromArray=function(l){if(l==null)throw new Error("Error: Cannot convert null Array to Nape list");let u=new m;for(let b=0;b<l.length;b++)u.push(l[b]);return u},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=!1,this.zpp_inner.user_length=this.zpp_inner.inner.length),this.zpp_inner.user_length};function d(l){return 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),l.zpp_inner.user_length}Object.defineProperty(m.prototype,"length",{get:function(){return d(this)}}),m.prototype.has=function(l){return this.zpp_inner.valmod(),this.zpp_inner.inner.has(o(l))},m.prototype.at=function(l){if(this.zpp_inner.valmod(),l<0||l>=d(this))throw new Error("Error: Index out of bounds");if(this.zpp_inner.reverse_flag&&(l=d(this)-1-l),l<this.zpp_inner.at_index||this.zpp_inner.at_ite==null)this.zpp_inner.at_index=l,this.zpp_inner.at_ite=this.zpp_inner.inner.iterator_at(l);else for(;this.zpp_inner.at_index!=l;)this.zpp_inner.at_index++,this.zpp_inner.at_ite=this.zpp_inner.at_ite.next;return p(this.zpp_inner.at_ite.elt)},m.prototype.push=function(l){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let u=this.zpp_inner.adder!=null?this.zpp_inner.adder(l):!0;return u&&(this.zpp_inner.reverse_flag?this.zpp_inner.inner.add(o(l)):(this.zpp_inner.push_ite==null&&(this.zpp_inner.push_ite=this.zpp_inner.inner.head==null?null:this.zpp_inner.inner.iterator_at(d(this)-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,o(l))),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(l)),u},m.prototype.unshift=function(l){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let u=this.zpp_inner.adder!=null?this.zpp_inner.adder(l):!0;return u&&(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(d(this)-1)),this.zpp_inner.push_ite=this.zpp_inner.inner.insert(this.zpp_inner.push_ite,o(l))):this.zpp_inner.inner.add(o(l)),this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(l)),u},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 l;if(this.zpp_inner.reverse_flag){l=this.zpp_inner.inner.head.elt;let u=p(l);this.zpp_inner.subber!=null&&this.zpp_inner.subber(u),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 u;d(this)==1?u=null:u=this.zpp_inner.inner.iterator_at(d(this)-2),l=u==null?this.zpp_inner.inner.head.elt:u.next.elt;let b=p(l);this.zpp_inner.subber!=null&&this.zpp_inner.subber(b),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(u)}return this.zpp_inner.invalidate(),p(l)},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 l;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 u;d(this)==1?u=null:u=this.zpp_inner.inner.iterator_at(d(this)-2),l=u==null?this.zpp_inner.inner.head.elt:u.next.elt;let b=p(l);this.zpp_inner.subber!=null&&this.zpp_inner.subber(b),this.zpp_inner.dontremove||this.zpp_inner.inner.erase(u)}else{l=this.zpp_inner.inner.head.elt;let u=p(l);this.zpp_inner.subber!=null&&this.zpp_inner.subber(u),this.zpp_inner.dontremove||this.zpp_inner.inner.pop()}return this.zpp_inner.invalidate(),p(l)},m.prototype.add=function(l){return this.zpp_inner.reverse_flag?this.push(l):this.unshift(l)},m.prototype.remove=function(l){if(this.zpp_inner.immutable)throw new Error("Error: "+e+"List is immutable");this.zpp_inner.modify_test(),this.zpp_inner.valmod();let u=!1,b=this.zpp_inner.inner.head,M=o(l);for(;b!=null;){if(b.elt==M){u=!0;break}b=b.next}return u&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(l),this.zpp_inner.dontremove||this.zpp_inner.inner.remove(M),this.zpp_inner.invalidate()),u},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(),h.get(this)},m.prototype.copy=function(l){l==null&&(l=!1);let u=new m,b=h.get(this);for(;b.hasNext();){let M=b.next();if(l)throw new Error("Error: "+e+" is not a copyable type");u.push(M)}return u},m.prototype.merge=function(l){if(l==null)throw new Error("Error: Cannot merge with null list");let u=h.get(l);for(;u.hasNext();){let b=u.next();this.has(b)||(this.zpp_inner.reverse_flag?this.push(b):this.unshift(b))}},m.prototype.toString=function(){let l="[",u=!0,b=h.get(this);for(;b.hasNext();){let M=b.next();u||(l+=","),l+=M==null?"NULL":M.toString(),u=!1}return l+"]"},m.prototype.foreach=function(l){if(l==null)throw new Error("Error: Cannot execute null on list elements");this.zpp_inner.valmod();let u=h.get(this);for(;u.hasNext();)try{l(u.next())}catch{u.zpp_next=h.zpp_pool,h.zpp_pool=u,u.zpp_inner=null;break}return this},m.prototype.filter=function(l){if(l==null)throw new Error("Error: Cannot select elements of list with null");let u=0;for(;u<d(this);){let b=this.at(u);try{l(b)?++u:this.remove(b)}catch{break}}return this},m.prototype.toArray=function(){let l=[],u=h.get(this);for(;u.hasNext();)l.push(u.next());return l},m.prototype[Symbol.iterator]=function(){let l=h.get(this);return{next(){return l.hasNext()?{value:l.next(),done:!1}:{value:void 0,done:!0}},[Symbol.iterator](){return this}}};let g=y(),R=e+"Iterator",q=e+"List";return g[R]=h,g[q]=m,{Iterator:h,List:m}}var ee=t=>t.outer,J=t=>t.zpp_inner??(t._inner?t._inner.zpp_inner??t._inner:t);k({typeName:"CbType",namespaceParts:["nape","callbacks"],zppListClass:"ZPP_CbTypeList",wrapElement:ee,unwrapElement:J});k({typeName:"Listener",namespaceParts:["nape","callbacks"],zppListClass:"ZPP_ListenerList",wrapElement:ee,unwrapElement:J});k({typeName:"Constraint",namespaceParts:["nape","constraint"],zppListClass:"ZPP_ConstraintList",wrapElement:ee,unwrapElement:J});k({typeName:"InteractionGroup",namespaceParts:["nape","dynamics"],zppListClass:"ZPP_InteractionGroupList",wrapElement:ee,unwrapElement:J});k({typeName:"GeomPoly",namespaceParts:["nape","geom"],zppListClass:"ZPP_GeomPolyList",wrapElement:ee,unwrapElement:J});k({typeName:"Body",namespaceParts:["nape","phys"],zppListClass:"ZPP_BodyList",wrapElement:ee,unwrapElement:J});k({typeName:"Compound",namespaceParts:["nape","phys"],zppListClass:"ZPP_CompoundList",wrapElement:ee,unwrapElement:J});k({typeName:"Shape",namespaceParts:["nape","shape"],zppListClass:"ZPP_ShapeList",wrapElement:ee,unwrapElement:J});k({typeName:"Arbiter",namespaceParts:["nape","dynamics"],zppListClass:"ZPP_ArbiterList",wrapElement:t=>t.wrapper(),unwrapElement:J});k({typeName:"Edge",namespaceParts:["nape","shape"],zppListClass:"ZPP_EdgeList",wrapElement:t=>t.wrapper(),unwrapElement:J});k({typeName:"ConvexResult",namespaceParts:["nape","geom"],zppListClass:"ZPP_ConvexResultList",wrapElement:t=>t,unwrapElement:t=>t});k({typeName:"RayResult",namespaceParts:["nape","geom"],zppListClass:"ZPP_RayResultList",wrapElement:t=>t,unwrapElement:t=>t});k({typeName:"Interactor",namespaceParts:["nape","phys"],zppListClass:"ZPP_InteractorList",wrapElement:t=>t.outer_i,unwrapElement:t=>t.zpp_inner_i});function de(t){if(t.outer==null){let e=c();t.outer=new e.geom.Vec2;let n=t.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=E.zpp_pool,E.zpp_pool=n,t.outer.zpp_inner=t}return t.outer}function A(){this.at_index=0,this.at_ite=null,this.zip_length=!1,this._length=0,this.inner=null,w.call(this),this.at_ite=null,this.at_index=0,this.zip_length=!0,this._length=0}A.__name__=["zpp_nape","util","ZPP_MixVec2List"];A.__super__=w;for(let t in w.prototype)A.prototype[t]=w.prototype[t];Object.defineProperty(A.prototype,"length",{get:function(){return this.zpp_gl()},configurable:!0});A.prototype.inner=null;A.prototype._length=0;A.prototype.zip_length=!1;A.prototype.at_ite=null;A.prototype.at_index=0;A.get=function(t,e){e==null&&(e=!1);let n=new A;return n.inner=t,n.zpp_inner.immutable=e,n};A.prototype.zpp_gl=function(){if(this.zpp_vm(),this.zip_length){this._length=0;let t=this.inner.next;for(;t!=null;)this._length++,t=t.next;this.zip_length=!1}return this._length};A.prototype.zpp_vm=function(){this.zpp_inner.validate(),this.inner.modified&&(this.zip_length=!0,this._length=0,this.at_ite=null)};A.prototype.at=function(t){if(this.zpp_vm(),t<0||t>=this.zpp_gl())throw new Error("Error: Index out of bounds");for(this.zpp_inner.reverse_flag&&(t=this.zpp_gl()-1-t),(t<this.at_index||this.at_ite==null)&&(this.at_index=0,this.at_ite=this.inner.next);this.at_index!==t;)this.at_index++,this.at_ite=this.at_ite.next;return de(this.at_ite)};A.prototype.push=function(t){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.zpp_vm(),t.zpp_inner._inuse)throw new Error("Error: Vec2 is already in use");let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(t):!0;if(e){if(this.zpp_inner.reverse_flag)this.inner.add(t.zpp_inner);else{let n=this.inner.iterator_at(this.zpp_gl()-1);this.inner.insert(n,t.zpp_inner)}this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(t)}return e};A.prototype.unshift=function(t){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");if(this.zpp_inner.modify_test(),this.zpp_vm(),t.zpp_inner._inuse)throw new Error("Error: Vec2 is already in use");let e=this.zpp_inner.adder!=null?this.zpp_inner.adder(t):!0;if(e){if(this.zpp_inner.reverse_flag){let n=this.inner.iterator_at(this.zpp_gl()-1);this.inner.insert(n,t.zpp_inner)}else this.inner.add(t.zpp_inner);this.zpp_inner.invalidate(),this.zpp_inner.post_adder!=null&&this.zpp_inner.post_adder(t)}return e};A.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 t;if(this.zpp_inner.reverse_flag){t=this.inner.next;let e=de(t);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);t=e==null?this.inner.next:e.next;let n=de(t);this.zpp_inner.subber!=null&&this.zpp_inner.subber(n),this.zpp_inner.dontremove||this.inner.erase(e)}return this.zpp_inner.invalidate(),de(t)};A.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 t;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);t=e==null?this.inner.next:e.next;let n=de(t);this.zpp_inner.subber!=null&&this.zpp_inner.subber(n),this.zpp_inner.dontremove||this.inner.erase(e)}else{t=this.inner.next;let e=de(t);this.zpp_inner.subber!=null&&this.zpp_inner.subber(e),this.zpp_inner.dontremove||this.inner.pop()}return this.zpp_inner.invalidate(),de(t)};A.prototype.remove=function(t){if(this.zpp_inner.immutable)throw new Error("Error: Vec2List is immutable");this.zpp_inner.modify_test(),this.zpp_vm();let e=!1,n=this.inner.next;for(;n!=null;){if(t.zpp_inner===n){e=!0;break}n=n.next}return e&&(this.zpp_inner.subber!=null&&this.zpp_inner.subber(t),this.zpp_inner.dontremove||this.inner.remove(t.zpp_inner),this.zpp_inner.invalidate()),e};A.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 Pt=c(),xt=Pt.__zpp;xt.util.ZPP_MixVec2List=A;var z=c();z.Config=Object.assign(z.Config||{},Bn);z.util.Debug=un;z.geom.Vec2=L;z.geom.Vec3=C;z.geom.Mat23=we;z.geom.MatMN=Ye;z.geom.AABB=je;z.geom.Winding=yn;z.geom.Ray=Je;z.geom.ConvexResult=Pe;z.geom.RayResult=xe;z.geom.Geom=ve;z.geom.GeomPoly=dn;z.geom.MarchingSquares=Ne;z.geom.Vec2Iterator=N;z.geom.Vec2List=w;z.geom.GeomVertexIterator=Q;z.__zpp.geom.ZPP_GeomVertexIterator=ge;z.__zpp.util.ZPP_ContactList=W;z.phys.Interactor=bn;z.phys.Body=ln;nt(t=>ln._wrap(t));z.phys.BodyType=En;z.phys.Compound=_n;rt(t=>_n._wrap(t));z.phys.FluidProperties=gn;z.phys.Material=Pn;z.phys.GravMassMode=xn;z.phys.InertiaMode=Cn;z.phys.MassMode=vn;z.shape.Shape=an;tt(t=>an._wrap(t));z.shape.Circle=Nn;z.shape.Polygon=In;z.shape.Edge=Ie;z.shape.ShapeType=wn;z.shape.ValidationResult=Ae;z.space.Space=We;z.space.Broadphase=An;z.dynamics.InteractionFilter=Tn;z.dynamics.InteractionGroup=Le;z.dynamics.ArbiterType=Ze;z.dynamics.Arbiter=G;Z._createColArb=()=>new se;Z._createFluidArb=()=>new ae;z.dynamics.Contact=le;z.dynamics.ContactIterator=P;z.dynamics.ContactList=I;z.callbacks.CbEvent=x;z.callbacks.CbType=Oe;z.callbacks.InteractionType=O;z.callbacks.PreFlag=ke;z.callbacks.OptionType=Be;z.callbacks.Listener=D;z.callbacks.ListenerType=Fe;z.callbacks.Callback=S;ce.__super__=S;ne._createBodyCb=()=>new ce;ze.__super__=S;ne._createConCb=()=>new ze;fe.__super__=S;ne._createIntCb=()=>new fe;me.__super__=S;ne._createPreCb=()=>new me;z.callbacks.BodyListener=Ge;z.callbacks.ConstraintListener=De;z.callbacks.InteractionListener=Me;z.callbacks.PreListener=Ue;z.constraint.Constraint=Ke;jn._createFn=(...t)=>new Ln(...t);Wn._createFn=(...t)=>new Sn(...t);Kn._createFn=(...t)=>new Zn(...t);Jn._createFn=(...t)=>new Vn(...t);qn._createFn=(...t)=>new On(...t);Hn._createFn=(...t)=>new kn(...t);$n._createFn=(...t)=>new Rn(...t);z.constraint.UserConstraint=en;var Fn=class{drawSegment(e,n,r){}drawCircle(e,n,r){}drawSolidCircle(e,n,r,p){}drawPolygon(e,n){}drawSolidPolygon(e,n){}drawPoint(e,n){}};var Ho="3.7.6";export{je as AABB,Ln as AngleJoint,G as Arbiter,Ze as ArbiterType,ln as Body,ce as BodyCallback,Ge as BodyListener,En as BodyType,An as Broadphase,S as Callback,x as CbEvent,Oe as CbType,Nn as Circle,se as CollisionArbiter,_n as Compound,Ke as Constraint,ze as ConstraintCallback,De as ConstraintListener,le as Contact,Pe as ConvexResult,Fn as DebugDraw,_t as DebugDrawFlags,Sn as DistanceJoint,Ie as Edge,ae as FluidArbiter,gn as FluidProperties,ve as Geom,dn as GeomPoly,xn as GravMassMode,Cn as InertiaMode,fe as InteractionCallback,Tn as InteractionFilter,Le as InteractionGroup,Me as InteractionListener,O as InteractionType,bn as Interactor,Zn as LineJoint,D as Listener,Fe as ListenerType,Ne as MarchingSquares,vn as MassMode,we as Mat23,Ye as MatMN,Pn as Material,Vn as MotorJoint,lt as NapeList,Be as OptionType,On as PivotJoint,In as Polygon,me as PreCallback,ke as PreFlag,Ue as PreListener,kn as PulleyJoint,Je as Ray,xe as RayResult,an as Shape,wn as ShapeType,We as Space,en as UserConstraint,Ho as VERSION,Ae as ValidationResult,L as Vec2,C as Vec3,Rn as WeldJoint,yn as Winding};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|