@newkrok/nape-js 3.9.0 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ConvexResult-CYFNMlT2.d.cts → ConvexResult-Hai2aEI-.d.cts} +0 -37
- package/dist/{ConvexResult-CYFNMlT2.d.ts → ConvexResult-Hai2aEI-.d.ts} +0 -37
- package/dist/chunk-7HUI2OS2.js +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -27
- package/dist/index.d.ts +2 -27
- package/dist/index.js +1 -1
- package/dist/serialization/index.cjs +1 -1
- package/dist/serialization/index.d.cts +1 -1
- package/dist/serialization/index.d.ts +1 -1
- package/dist/serialization/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3TXNIYBK.js +0 -2
package/dist/chunk-3TXNIYBK.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var si=class{static POSINF(){return 1/0}static NEGINF(){return-1/0}};si.__name__=["zpp_nape","ZPP_Const"],si.FMAX=1e100;var gt=class gt{static Constraint(){return gt._Constraint++}static Interactor(){return gt._Interactor++}static CbType(){return gt._CbType++}static CbSet(){return gt._CbSet++}static Listener(){return gt._Listener++}static ZPP_SimpleVert(){return gt._ZPP_SimpleVert++}static ZPP_SimpleSeg(){return gt._ZPP_SimpleSeg++}static Space(){return gt._Space++}static InteractionGroup(){return gt._InteractionGroup++}};gt.__name__=["zpp_nape","ZPP_ID"],gt._Constraint=0,gt._Interactor=0,gt._CbType=0,gt._CbSet=0,gt._Listener=0,gt._ZPP_SimpleVert=0,gt._ZPP_SimpleSeg=0,gt._Space=0,gt._InteractionGroup=0;var zn=gt;var U=class{};U.__name__=["zpp_nape","util","ZPP_Flags"],U.GravMassMode_DEFAULT=null,U.GravMassMode_FIXED=null,U.GravMassMode_SCALED=null,U.InertiaMode_DEFAULT=null,U.InertiaMode_FIXED=null,U.MassMode_DEFAULT=null,U.MassMode_FIXED=null,U.BodyType_STATIC=null,U.BodyType_DYNAMIC=null,U.BodyType_KINEMATIC=null,U.ListenerType_BODY=null,U.ListenerType_CONSTRAINT=null,U.ListenerType_INTERACTION=null,U.ListenerType_PRE=null,U.PreFlag_ACCEPT=null,U.PreFlag_IGNORE=null,U.PreFlag_ACCEPT_ONCE=null,U.PreFlag_IGNORE_ONCE=null,U.CbEvent_BEGIN=null,U.CbEvent_ONGOING=null,U.CbEvent_END=null,U.CbEvent_WAKE=null,U.CbEvent_SLEEP=null,U.CbEvent_BREAK=null,U.CbEvent_PRE=null,U.InteractionType_COLLISION=null,U.InteractionType_SENSOR=null,U.InteractionType_FLUID=null,U.InteractionType_ANY=null,U.Winding_UNDEFINED=null,U.Winding_CLOCKWISE=null,U.Winding_ANTICLOCKWISE=null,U.ValidationResult_VALID=null,U.ValidationResult_DEGENERATE=null,U.ValidationResult_CONCAVE=null,U.ValidationResult_SELF_INTERSECTING=null,U.ShapeType_CIRCLE=null,U.ShapeType_POLYGON=null,U.Broadphase_DYNAMIC_AABB_TREE=null,U.Broadphase_SWEEP_AND_PRUNE=null,U.ArbiterType_COLLISION=null,U.ArbiterType_SENSOR=null,U.ArbiterType_FLUID=null,U.internal=!1,U.id_ImmState_ACCEPT=1,U.id_ImmState_IGNORE=2,U.id_ImmState_ALWAYS=4,U.id_GravMassMode_DEFAULT=0,U.id_GravMassMode_FIXED=1,U.id_GravMassMode_SCALED=2,U.id_InertiaMode_DEFAULT=0,U.id_InertiaMode_FIXED=1,U.id_MassMode_DEFAULT=0,U.id_MassMode_FIXED=1,U.id_BodyType_STATIC=1,U.id_BodyType_DYNAMIC=2,U.id_BodyType_KINEMATIC=3,U.id_ListenerType_BODY=0,U.id_ListenerType_CONSTRAINT=1,U.id_ListenerType_INTERACTION=2,U.id_ListenerType_PRE=3,U.id_PreFlag_ACCEPT=1,U.id_PreFlag_IGNORE=2,U.id_PreFlag_ACCEPT_ONCE=3,U.id_PreFlag_IGNORE_ONCE=4,U.id_CbEvent_BEGIN=0,U.id_CbEvent_END=1,U.id_CbEvent_WAKE=2,U.id_CbEvent_SLEEP=3,U.id_CbEvent_BREAK=4,U.id_CbEvent_PRE=5,U.id_CbEvent_ONGOING=6,U.id_InteractionType_COLLISION=1,U.id_InteractionType_SENSOR=2,U.id_InteractionType_FLUID=4,U.id_InteractionType_ANY=7,U.id_Winding_UNDEFINED=0,U.id_Winding_CLOCKWISE=1,U.id_Winding_ANTICLOCKWISE=2,U.id_ValidationResult_VALID=0,U.id_ValidationResult_DEGENERATE=1,U.id_ValidationResult_CONCAVE=2,U.id_ValidationResult_SELF_INTERSECTING=3,U.id_ShapeType_CIRCLE=0,U.id_ShapeType_POLYGON=1,U.id_Broadphase_DYNAMIC_AABB_TREE=0,U.id_Broadphase_SWEEP_AND_PRUNE=1,U.id_ArbiterType_COLLISION=1,U.id_ArbiterType_SENSOR=2,U.id_ArbiterType_FLUID=4;var Ls=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}};Ls.__name__=["zpp_nape","util","ZPP_Math"];var xe=class{};xe.__name__=["zpp_nape","util","ZPP_PubPool"],xe.poolGeomPoly=null,xe.nextGeomPoly=null,xe.poolVec2=null,xe.nextVec2=null,xe.poolVec3=null,xe.nextVec3=null;var Ds=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}},Ji=class extends Ds{};Ji.__name__=["zpp_nape","util","ZNPArray2_Float"];var Ui=class extends Ds{};Ui.__name__=["zpp_nape","util","ZNPArray2_ZPP_GeomVert"];var Ki=class extends Ds{};Ki.__name__=["zpp_nape","util","ZNPArray2_ZPP_MarchPair"];var xn=class xn{constructor(){this.value=!1;this.next=null;this.hnext=null;this.id=0;this.di=0;this.__class__=xn}static _alloc(){if(xn.zpp_pool==null)return new xn;let e=xn.zpp_pool;return xn.zpp_pool=e.next,e.next=null,e}static get(e,t,n){let l=xn._alloc();return l.id=e,l.di=t,l.value=n,l}static getpersist(e,t){let n=xn._alloc();return n.id=e,n.di=t,n}static ordered_get(e,t,n){if(e<=t){let l=xn._alloc();return l.id=e,l.di=t,l.value=n,l}else{let l=xn._alloc();return l.id=t,l.di=e,l.value=n,l}}static ordered_get_persist(e,t){if(e<=t){let n=xn._alloc();return n.id=e,n.di=t,n}else{let n=xn._alloc();return n.id=t,n.di=e,n}}free(){}alloc(){}};xn.__name__=["zpp_nape","util","Hashable2_Boolfalse"],xn.zpp_pool=null;var je=xn;var bo=1048576,Yi=1048575,Xi=106039,dl=class dl{constructor(){this.cnt=0;this.__class__=dl;this.cnt=0,this.table=new Array(bo).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*Xi+t&Yi];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*Xi+t&Yi];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*Xi+t&Yi];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*Xi+e.di&Yi,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*Xi+e.di&Yi,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*Xi+e.di&Yi,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*Xi+t&Yi}};dl.__name__=["zpp_nape","util","FastHash2_Hashable2_Boolfalse"];var Hi=dl;var Fs=class{constructor(){this.elt=null;this.next=null}alloc(){}free(){this.elt=null}elem(){return this.elt}};Fs.zpp_pool=null;var ft=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}};ft.prototype.inlined_add=ft.prototype.add;ft.prototype.inlined_insert=ft.prototype.insert;ft.prototype.inlined_pop=ft.prototype.pop;ft.prototype.inlined_pop_unsafe=ft.prototype.pop_unsafe;ft.prototype.inlined_erase=ft.prototype.erase;ft.prototype.inlined_remove=ft.prototype.remove;ft.prototype.inlined_try_remove=ft.prototype.try_remove;ft.prototype.inlined_clear=ft.prototype.clear;ft.prototype.inlined_has=ft.prototype.has;var Gs=class{constructor(){this.colour=0;this.parent=null;this.next=null;this.prev=null;this.data=null;this.swapped=null;this.lt=null}_allocNode(){let e=this.constructor,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor;e.data=null,e.lt=null,e.swapped=null,e.next=t.zpp_pool,t.zpp_pool=e}free(){this.data=null,this.lt=null,this.swapped=null}alloc(){}verify(){if(!this.empty()){let e=this.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;){let t=e.data,n=!0;if(!this.empty()){let l=this.parent;for(;l.prev!=null;)l=l.prev;for(;l!=null;){let s=l.data;if(n){if(t==s)n=!1;else if(!this.lt(s,t)&&this.lt(t,s))return!1}else if(!this.lt(t,s)&&this.lt(s,t))return!1;if(l.next!=null)for(l=l.next;l.prev!=null;)l=l.prev;else{for(;l.parent!=null&&l==l.parent.next;)l=l.parent;l=l.parent}}}if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent}}}return!0}empty(){return this.parent==null}singular(){return this.parent!=null&&this.parent.prev==null?this.parent.next==null:!1}size(){let e=0;if(!this.empty()){let t=this.parent;for(;t.prev!=null;)t=t.prev;for(;t!=null;)if(++e,t.next!=null)for(t=t.next;t.prev!=null;)t=t.prev;else{for(;t.parent!=null&&t==t.parent.next;)t=t.parent;t=t.parent}}return e}has(e){return this.find(e)!=null}find(e){let t=this.parent;for(;t!=null&&t.data!=e;)this.lt(e,t.data)?t=t.prev:t=t.next;return t}has_weak(e){return this.find_weak(e)!=null}find_weak(e){let t=this.parent;for(;t!=null;)if(this.lt(e,t.data))t=t.prev;else if(this.lt(t.data,e))t=t.next;else break;return t}lower_bound(e){let t=null;if(!this.empty()){let n=this.parent;for(;n.prev!=null;)n=n.prev;for(;n!=null;){if(!this.lt(n.data,e)){t=n.data;break}if(n.next!=null)for(n=n.next;n.prev!=null;)n=n.prev;else{for(;n.parent!=null&&n==n.parent.next;)n=n.parent;n=n.parent}}}return t}first(){let e=this.parent;for(;e.prev!=null;)e=e.prev;return e.data}pop_front(){let e=this.parent;for(;e.prev!=null;)e=e.prev;let t=e.data;return this.remove_node(e),t}remove(e){this.remove_node(this.find(e))}successor_node(e){if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{let t=e;for(e=e.parent;e!=null&&e.prev!=t;)t=e,e=e.parent}return e}predecessor_node(e){if(e.prev!=null)for(e=e.prev;e.next!=null;)e=e.next;else{let t=e;for(e=e.parent;e!=null&&e.next!=t;)t=e,e=e.parent}return e}successor(e){let t=this.successor_node(this.find(e));return t==null?null:t.data}predecessor(e){let t=this.predecessor_node(this.find(e));return t==null?null:t.data}remove_node(e){if(e.next!=null&&e.prev!=null){let l=e.next;for(;l.prev!=null;)l=l.prev;let s=e.data;e.data=l.data,l.data=s,this.swapped!=null&&this.swapped(e.data,l.data),e=l}let t=e.prev==null?e.next:e.prev;if(e.colour==1){if(e.prev!=null||e.next!=null)t.colour=1;else if(e.parent!=null){let l=e.parent;for(;;){l.colour++,l.prev.colour--,l.next.colour--;let s=l.prev;if(s.colour==-1){this.__fix_neg_red(s);break}else if(s.colour==0){if(s.prev!=null&&s.prev.colour==0){this.__fix_dbl_red(s.prev);break}if(s.next!=null&&s.next.colour==0){this.__fix_dbl_red(s.next);break}}let i=l.next;if(i.colour==-1){this.__fix_neg_red(i);break}else if(i.colour==0){if(i.prev!=null&&i.prev.colour==0){this.__fix_dbl_red(i.prev);break}if(i.next!=null&&i.next.colour==0){this.__fix_dbl_red(i.next);break}}if(l.colour==2)if(l.parent==null)l.colour=1;else{l=l.parent;continue}break}}}let n=e.parent;n==null?this.parent=t:n.prev==e?n.prev=t:n.next=t,t!=null&&(t.parent=n),e.parent=e.prev=e.next=null,this._freeNode(e)}clear(){if(this.parent!=null){let e=this.parent;for(;e!=null;)if(e.prev!=null)e=e.prev;else if(e.next!=null)e=e.next;else{let t=e.parent;t!=null&&(e==t.prev?t.prev=null:t.next=null,e.parent=null),this._freeNode(e),e=t}this.parent=null}}clear_with(e){if(this.parent==null)return;let t=this.parent;for(;t!=null;)if(t.prev!=null)t=t.prev;else if(t.next!=null)t=t.next;else{e(t.data);let n=t.parent;n!=null&&(t==n.prev?n.prev=null:n.next=null,t.parent=null),this._freeNode(t),t=n}this.parent=null}clear_node(e,t){t(e.data);let n=e.parent;return n!=null&&(e==n.prev?n.prev=null:n.next=null,e.parent=null),this._freeNode(e),n}__fix_neg_red(e){let t=e.parent,n;if(t.prev==e){let l=e.prev,s=e.next,i=s.prev,o=s.next;l.colour=0,e.colour=t.colour=1,e.next=i,i!=null&&(i.parent=e);let r=t.data;t.data=s.data,s.data=r,this.swapped!=null&&this.swapped(t.data,s.data),s.prev=o,o!=null&&(o.parent=s),s.next=t.next,t.next!=null&&(t.next.parent=s),t.next=s,s!=null&&(s.parent=t),n=l}else{let l=e.next,s=e.prev,i=s.next,o=s.prev;l.colour=0,e.colour=t.colour=1,e.prev=i,i!=null&&(i.parent=e);let r=t.data;t.data=s.data,s.data=r,this.swapped!=null&&this.swapped(t.data,s.data),s.next=o,o!=null&&(o.parent=s),s.prev=t.prev,t.prev!=null&&(t.prev.parent=s),t.prev=s,s!=null&&(s.parent=t),n=l}n.prev!=null&&n.prev.colour==0?this.__fix_dbl_red(n.prev):n.next!=null&&n.next.colour==0&&this.__fix_dbl_red(n.next)}__fix_dbl_red(e){for(;;){let t=e.parent,n=t.parent;if(n==null){t.colour=1;break}let l,s,i,o,r,a,p;t==n.prev?(i=n,p=n.next,e==t.prev?(l=e,s=t,o=e.prev,r=e.next,a=t.next):(l=t,s=e,o=t.prev,r=e.prev,a=e.next)):(l=n,o=n.prev,e==t.prev?(s=e,i=t,r=e.prev,a=e.next,p=t.next):(s=t,i=e,r=t.prev,a=e.prev,p=e.next));let c=n.parent;if(c==null?this.parent=s:c.prev==n?c.prev=s:c.next=s,s!=null&&(s.parent=c),l.prev=o,o!=null&&(o.parent=l),l.next=r,r!=null&&(r.parent=l),s.prev=l,l!=null&&(l.parent=s),s.next=i,i!=null&&(i.parent=s),i.prev=a,a!=null&&(a.parent=i),i.next=p,p!=null&&(p.parent=i),s.colour=n.colour-1,l.colour=1,i.colour=1,s==this.parent)this.parent.colour=1;else if(s.colour==0&&s.parent.colour==0){e=s;continue}break}}try_insert_bool(e){let t=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else{let n=this.parent;for(;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break}return t==null?!1:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),!0)}try_insert(e){let t=null,n=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else for(n=this.parent;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break;return t==null?n:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t)}insert(e){let t=this._allocNode();if(t.data=e,this.parent==null)this.parent=t;else{let n=this.parent;for(;;)if(this.lt(t.data,n.data))if(n.prev==null){n.prev=t,t.parent=n;break}else n=n.prev;else if(n.next==null){n.next=t,t.parent=n;break}else n=n.next}return t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t}};Gs.zpp_pool=null;var gi=null,Qi=null,Fn=null,Nl=null,fo=null,Ol=null,ys=null,nn=null,ms=null,Yn=null,bs=null,fs=null,Sl=null,zo=null,Po=null,wo=null,vo=null,go=null,Co=null,Mo=null,Zo=null;function We(Y){let e=class extends Fs{};return e.__name__=["zpp_nape","util","ZNPNode_"+Y],e.zpp_pool=null,e}function Je(Y,e){let t=class extends ft{};return t.__name__=["zpp_nape","util","ZNPList_"+Y],t._NodeClass=e,t}function vi(Y){let e=class extends Gs{};return e.__name__=["zpp_nape","util","ZPP_Set_"+Y],e.zpp_pool=null,e}function eo(Y){Y.util||(Y.util={}),Y.util.ZNPNode_ZPP_CbType=We("ZPP_CbType"),Y.util.ZNPNode_ZPP_CallbackSet=We("ZPP_CallbackSet"),Y.util.ZNPNode_ZPP_Shape=We("ZPP_Shape"),Y.util.ZNPNode_ZPP_Body=We("ZPP_Body"),Y.util.ZNPNode_ZPP_Constraint=We("ZPP_Constraint"),Y.util.ZNPNode_ZPP_Compound=We("ZPP_Compound"),Y.util.ZNPNode_ZPP_Arbiter=We("ZPP_Arbiter"),Y.util.ZNPNode_ZPP_InteractionListener=We("ZPP_InteractionListener"),Y.util.ZNPNode_ZPP_CbSet=We("ZPP_CbSet"),Y.util.ZNPNode_ZPP_Interactor=We("ZPP_Interactor"),Y.util.ZNPNode_ZPP_BodyListener=We("ZPP_BodyListener"),Y.util.ZNPNode_ZPP_CbSetPair=We("ZPP_CbSetPair"),Y.util.ZNPNode_ZPP_ConstraintListener=We("ZPP_ConstraintListener"),Y.util.ZNPNode_ZPP_CutInt=We("ZPP_CutInt"),Y.util.ZNPNode_ZPP_CutVert=We("ZPP_CutVert"),Y.util.ZNPNode_ZPP_PartitionVertex=We("ZPP_PartitionVertex"),Y.util.ZNPNode_ZPP_SimplifyP=We("ZPP_SimplifyP"),Y.util.ZNPNode_ZPP_PartitionedPoly=We("ZPP_PartitionedPoly"),Y.util.ZNPNode_ZPP_GeomVert=We("ZPP_GeomVert"),Y.util.ZNPNode_ZPP_SimpleVert=We("ZPP_SimpleVert"),Y.util.ZNPNode_ZPP_SimpleEvent=We("ZPP_SimpleEvent"),Y.util.ZNPNode_ZPP_Vec2=We("ZPP_Vec2"),Y.util.ZNPNode_ZPP_AABBPair=We("ZPP_AABBPair"),Y.util.ZNPNode_ZPP_Edge=We("ZPP_Edge"),Y.util.ZNPNode_ZPP_AABBNode=We("ZPP_AABBNode"),Y.util.ZNPNode_ZPP_Component=We("ZPP_Component"),Y.util.ZNPNode_ZPP_FluidArbiter=We("ZPP_FluidArbiter"),Y.util.ZNPNode_ZPP_SensorArbiter=We("ZPP_SensorArbiter"),Y.util.ZNPNode_ZPP_Listener=We("ZPP_Listener"),Y.util.ZNPNode_ZPP_ColArbiter=We("ZPP_ColArbiter"),Y.util.ZNPNode_ZPP_InteractionGroup=We("ZPP_InteractionGroup"),Y.util.ZNPNode_ZPP_ToiEvent=We("ZPP_ToiEvent"),Y.util.ZNPNode_ConvexResult=We("ConvexResult"),Y.util.ZNPNode_ZPP_GeomPoly=We("ZPP_GeomPoly"),Y.util.ZNPNode_RayResult=We("RayResult");let e=Y.util;Po=Y.util.ZNPList_ZPP_InteractionListener=Je("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),wo=Y.util.ZNPList_ZPP_BodyListener=Je("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),vo=Y.util.ZNPList_ZPP_ConstraintListener=Je("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),go=Y.util.ZNPList_ZPP_Constraint=Je("ZPP_Constraint",e.ZNPNode_ZPP_Constraint),Co=Y.util.ZNPList_ZPP_Interactor=Je("ZPP_Interactor",e.ZNPNode_ZPP_Interactor),Mo=Y.util.ZNPList_ZPP_CbSet=Je("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),zo=Y.util.ZNPList_ZPP_CbType=Je("ZPP_CbType",e.ZNPNode_ZPP_CbType),Y.util.ZNPList_ZPP_Vec2=Je("ZPP_Vec2",e.ZNPNode_ZPP_Vec2),fo=Y.util.ZNPList_ZPP_Vec2,Y.util.ZNPList_ZPP_CallbackSet=Je("ZPP_CallbackSet",e.ZNPNode_ZPP_CallbackSet),Y.util.ZNPList_ZPP_Shape=Je("ZPP_Shape",e.ZNPNode_ZPP_Shape),Y.util.ZNPList_ZPP_Body=Je("ZPP_Body",e.ZNPNode_ZPP_Body),Y.util.ZNPList_ZPP_Compound=Je("ZPP_Compound",e.ZNPNode_ZPP_Compound),Y.util.ZNPList_ZPP_Arbiter=Je("ZPP_Arbiter",e.ZNPNode_ZPP_Arbiter),Zo=Y.util.ZNPList_ZPP_CbSetPair=Je("ZPP_CbSetPair",e.ZNPNode_ZPP_CbSetPair),Y.util.ZNPList_ZPP_CutInt=Je("ZPP_CutInt",e.ZNPNode_ZPP_CutInt),Y.util.ZNPList_ZPP_CutVert=Je("ZPP_CutVert",e.ZNPNode_ZPP_CutVert),Y.util.ZNPList_ZPP_PartitionVertex=Je("ZPP_PartitionVertex",e.ZNPNode_ZPP_PartitionVertex),gi=Y.util.ZNPList_ZPP_PartitionVertex,Y.util.ZNPList_ZPP_SimplifyP=Je("ZPP_SimplifyP",e.ZNPNode_ZPP_SimplifyP),Nl=Y.util.ZNPList_ZPP_SimplifyP,Y.util.ZNPList_ZPP_PartitionedPoly=Je("ZPP_PartitionedPoly",e.ZNPNode_ZPP_PartitionedPoly),Qi=Y.util.ZNPList_ZPP_PartitionedPoly,Y.util.ZNPList_ZPP_GeomVert=Je("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),Fn=Y.util.ZNPList_ZPP_GeomVert,Y.util.ZNPList_ZPP_SimpleVert=Je("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),Sl=Y.util.ZNPList_ZPP_SimpleEvent=Je("ZPP_SimpleEvent",e.ZNPNode_ZPP_SimpleEvent),Y.util.ZNPList_ZPP_AABBPair=Je("ZPP_AABBPair",e.ZNPNode_ZPP_AABBPair),Y.util.ZNPList_ZPP_Edge=Je("ZPP_Edge",e.ZNPNode_ZPP_Edge),Y.util.ZNPList_ZPP_AABBNode=Je("ZPP_AABBNode",e.ZNPNode_ZPP_AABBNode),Y.util.ZNPList_ZPP_Component=Je("ZPP_Component",e.ZNPNode_ZPP_Component),Y.util.ZNPList_ZPP_FluidArbiter=Je("ZPP_FluidArbiter",e.ZNPNode_ZPP_FluidArbiter),Y.util.ZNPList_ZPP_SensorArbiter=Je("ZPP_SensorArbiter",e.ZNPNode_ZPP_SensorArbiter),Y.util.ZNPList_ZPP_Listener=Je("ZPP_Listener",e.ZNPNode_ZPP_Listener),Y.util.ZNPList_ZPP_ColArbiter=Je("ZPP_ColArbiter",e.ZNPNode_ZPP_ColArbiter),Y.util.ZNPList_ZPP_InteractionGroup=Je("ZPP_InteractionGroup",e.ZNPNode_ZPP_InteractionGroup),Y.util.ZNPList_ZPP_ToiEvent=Je("ZPP_ToiEvent",e.ZNPNode_ZPP_ToiEvent),Y.util.ZNPList_ConvexResult=Je("ConvexResult",e.ZNPNode_ConvexResult),Y.util.ZNPList_ZPP_GeomPoly=Je("ZPP_GeomPoly",e.ZNPNode_ZPP_GeomPoly),Y.util.ZNPList_RayResult=Je("RayResult",e.ZNPNode_RayResult),ys=Y.util.ZNPNode_RayResult,Ol=Y.util.ZNPList_ZPP_SimpleVert,Y.util.ZPP_Set_ZPP_Body=vi("ZPP_Body"),Y.util.ZPP_Set_ZPP_CbSetPair=vi("ZPP_CbSetPair"),Y.util.ZPP_Set_ZPP_PartitionVertex=vi("ZPP_PartitionVertex"),bs=Y.util.ZPP_Set_ZPP_PartitionVertex,Y.util.ZPP_Set_ZPP_PartitionPair=vi("ZPP_PartitionPair"),fs=Y.util.ZPP_Set_ZPP_PartitionPair,Y.util.ZPP_Set_ZPP_SimpleVert=vi("ZPP_SimpleVert"),nn=Y.util.ZPP_Set_ZPP_SimpleVert,Y.util.ZPP_Set_ZPP_SimpleSeg=vi("ZPP_SimpleSeg"),ms=Y.util.ZPP_Set_ZPP_SimpleSeg,Y.util.ZPP_Set_ZPP_SimpleEvent=vi("ZPP_SimpleEvent"),Yn=Y.util.ZPP_Set_ZPP_SimpleEvent,Y.util.ZPP_Set_ZPP_CbSet=vi("ZPP_CbSet")}var zt=class zt{constructor(){this.outer_body=null;this.outer_con=null;this.outer_int=null;this.event=0;this.listener=null;this.space=null;this.index=0;this.next=null;this.prev=null;this.length=0;this.int1=null;this.int2=null;this.set=null;this.wrap_arbiters=null;this.pre_arbiter=null;this.pre_swapped=!1;this.body=null;this.constraint=null}wrapper_body(){return this.outer_body==null&&(zt.internal=!0,this.outer_body=zt._createBodyCb(),zt.internal=!1,this.outer_body.zpp_inner=this),this.outer_body}wrapper_con(){return this.outer_con==null&&(zt.internal=!0,this.outer_con=zt._createConCb(),zt.internal=!1,this.outer_con.zpp_inner=this),this.outer_con}wrapper_int(){let e=zt._zpp;return this.outer_int==null&&(zt.internal=!0,this.outer_int=zt._createIntCb(),zt.internal=!1,this.outer_int.zpp_inner=this),this.wrap_arbiters==null?this.wrap_arbiters=e.util.ZPP_ArbiterList.get(this.set.arbiters,!0):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=!0,this.wrap_arbiters.zpp_inner.at_ite=null,this.outer_int}push(e){this.prev!=null?this.prev.next=e:this.next=e,e.prev=this.prev,e.next=null,this.prev=e,this.length++}push_rev(e){this.next!=null?this.next.prev=e:this.prev=e,e.next=this.next,e.prev=null,this.next=e,this.length++}pop(){let e=this.next;return this.next=e.next,this.next==null?this.prev=null:this.next.prev=null,this.length--,e}pop_rev(){let e=this.prev;return this.prev=e.prev,this.prev==null?this.next=null:this.prev.next=null,this.length--,e}empty(){return this.next==null}clear(){for(;!this.empty();)this.pop()}splice(e){let t=e.next;return e.prev==null?(this.next=e.next,this.next!=null?this.next.prev=null:this.prev=null):(e.prev.next=e.next,e.next!=null?e.next.prev=e.prev:this.prev=e.prev),this.length--,t}rotateL(){this.push(this.pop())}rotateR(){this.push_rev(this.pop_rev())}cycleNext(e){return e.next==null?this.next:e.next}cyclePrev(e){return e.prev==null?this.prev:e.prev}at(e){let t=this.next;for(;e--!=0;)t=t.next;return t}rev_at(e){let t=this.prev;for(;e--!=0;)t=t.prev;return t}free(){this.int1=this.int2=null,this.body=null,this.constraint=null,this.listener=null,this.wrap_arbiters!=null&&(this.wrap_arbiters.zpp_inner.inner=null),this.set=null}alloc(){}genarbs(){let e=zt._zpp;this.wrap_arbiters==null?this.wrap_arbiters=e.util.ZPP_ArbiterList.get(this.set.arbiters,!0):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=!0,this.wrap_arbiters.zpp_inner.at_ite=null}};zt.__name__=["zpp_nape","callbacks","ZPP_Callback"],zt._nape=null,zt._zpp=null,zt.internal=!1,zt.zpp_pool=null,zt._createBodyCb=null,zt._createConCb=null,zt._createIntCb=null,zt._createPreCb=null;var Rt=zt;var qt=class qt{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=qt._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;qt.zpp_pool==null?t=new qt:(t=qt.zpp_pool,qt.zpp_pool=t.next,t.next=null);let n=null,l=e.head;for(;l!=null;){let s=l.elt;n=t.cbTypes.insert(n,s),s.cbsets.add(t),l=l.next}return t}static compatible(e,t,n){let l,s=e.options1,i=t.cbTypes;if(s.nonemptyintersection(i,s.includes)&&!s.nonemptyintersection(i,s.excludes)){let o=e.options2,r=n.cbTypes;l=o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)}else l=!1;if(l)return!0;{let o=e.options2,r=t.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=e.options1,p=n.cbTypes;return a.nonemptyintersection(p,a.includes)?!a.nonemptyintersection(p,a.excludes):!1}else return!1}}static findOrCreatePair(e,t){let n=qt._zpp,l=null,i=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;i!=null;){let o=i.elt;if(o.a==e&&o.b==t||o.a==t&&o.b==e){l=o;break}i=i.next}if(l==null){let o;n.callbacks.ZPP_CbSetPair.zpp_pool==null?o=new n.callbacks.ZPP_CbSetPair:(o=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=o.next,o.next=null),o.zip_listeners=!0,qt.setlt(e,t)?(o.a=e,o.b=t):(o.a=t,o.b=e),l=o,e.cbpairs.add(l),t!=e&&t.cbpairs.add(l)}return l.zip_listeners&&(l.zip_listeners=!1,l.__validate()),l}static empty_intersection(e,t){return qt.findOrCreatePair(e,t).listeners.head==null}static single_intersection(e,t,n){let s=qt.findOrCreatePair(e,t).listeners.head;return s!=null&&s.elt==n?s.next==null:!1}static find_all(e,t,n,l){let i=qt.findOrCreatePair(e,t).listeners.head;for(;i!=null;){let o=i.elt;o.event==n&&l(o),i=i.next}}increment(){this.count++}decrement(){return--this.count==0}invalidate_pairs(){let e=this.cbpairs.head;for(;e!=null;){let t=e.elt;t.zip_listeners=!0,e=e.next}}invalidate_listeners(){this.zip_listeners=!0,this.invalidate_pairs()}validate_listeners(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners())}realvalidate_listeners(){let e=qt._zpp;this.listeners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,l=null,s=this.listeners.head,i=n.listeners.head;for(;i!=null;){let o=i.elt;if(s!=null&&s.elt==o)i=i.next,l=s,s=s.next;else{let r;if(s!=null){let a=s.elt;r=o.precedence>a.precedence||o.precedence==a.precedence&&o.id>a.id}else r=!0;if(r){if(o.space==this.manager.space){let a=this.listeners,p;e.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?p=new e.util.ZNPNode_ZPP_InteractionListener:(p=e.util.ZNPNode_ZPP_InteractionListener.zpp_pool,e.util.ZNPNode_ZPP_InteractionListener.zpp_pool=p.next,p.next=null),p.elt=o;let c=p;l==null?(c.next=a.head,a.head=c):(c.next=l.next,l.next=c),a.pushmod=a.modified=!0,a.length++,l=c}i=i.next}else l=s,s=s.next}}t=t.next}}invalidate_bodylisteners(){this.zip_bodylisteners=!0}validate_bodylisteners(){this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners())}realvalidate_bodylisteners(){let e=qt._zpp;this.bodylisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,l=null,s=this.bodylisteners.head,i=n.bodylisteners.head;for(;i!=null;){let o=i.elt;if(s!=null&&s.elt==o)i=i.next,l=s,s=s.next;else{let r;if(s!=null){let a=s.elt;r=o.precedence>a.precedence||o.precedence==a.precedence&&o.id>a.id}else r=!0;if(r){let a=o.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&o.space==this.manager.space){let p=this.bodylisteners,c;e.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_BodyListener:(c=e.util.ZNPNode_ZPP_BodyListener.zpp_pool,e.util.ZNPNode_ZPP_BodyListener.zpp_pool=c.next,c.next=null),c.elt=o;let u=c;l==null?(u.next=p.head,p.head=u):(u.next=l.next,l.next=u),p.pushmod=p.modified=!0,p.length++,l=u}i=i.next}else l=s,s=s.next}}t=t.next}}invalidate_conlisteners(){this.zip_conlisteners=!0}validate_conlisteners(){this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}realvalidate_conlisteners(){let e=qt._zpp;this.conlisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,l=null,s=this.conlisteners.head,i=n.conlisteners.head;for(;i!=null;){let o=i.elt;if(s!=null&&s.elt==o)i=i.next,l=s,s=s.next;else{let r;if(s!=null){let a=s.elt;r=o.precedence>a.precedence||o.precedence==a.precedence&&o.id>a.id}else r=!0;if(r){let a=o.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&o.space==this.manager.space){let p=this.conlisteners,c;e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_ConstraintListener:(c=e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=c.next,c.next=null),c.elt=o;let u=c;l==null?(u.next=p.head,p.head=u):(u.next=l.next,l.next=u),p.pushmod=p.modified=!0,p.length++,l=u}i=i.next}else l=s,s=s.next}}t=t.next}}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners()),this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners()),this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}addConstraint(e){this.constraints.add(e)}addInteractor(e){this.interactors.add(e)}remConstraint(e){this.constraints.remove(e)}remInteractor(e){this.interactors.remove(e)}free(){for(this.listeners.clear(),this.zip_listeners=!0,this.bodylisteners.clear(),this.zip_bodylisteners=!0,this.conlisteners.clear(),this.zip_conlisteners=!0;this.cbTypes.head!=null;)this.cbTypes.pop_unsafe().cbsets.remove(this)}alloc(){}};qt.__name__=["zpp_nape","callbacks","ZPP_CbSet"],qt._zpp=null,qt.zpp_pool=null;var Pt=qt;var Tn=class Tn{constructor(){this.a=null;this.b=null;this.next=null;this.zip_listeners=!1;this.listeners=null;let e=Tn._zpp;this.listeners=new e.util.ZNPList_ZPP_InteractionListener}static get(e,t){let n=Tn._zpp,l;return Tn.zpp_pool==null?l=new Tn:(l=Tn.zpp_pool,Tn.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=Tn._zpp;return n.callbacks.ZPP_CbSet.setlt(e.a,t.a)?!0:e.a==t.a?n.callbacks.ZPP_CbSet.setlt(e.b,t.b):!1}free(){this.a=this.b=null,this.listeners.clear()}alloc(){this.zip_listeners=!0}compatible(e){let t,n=e.options1,l=this.a.cbTypes;if(n.nonemptyintersection(l,n.includes)&&!n.nonemptyintersection(l,n.excludes)){let s=e.options2,i=this.b.cbTypes;t=s.nonemptyintersection(i,s.includes)&&!s.nonemptyintersection(i,s.excludes)}else t=!1;if(t)return!0;{let s=e.options2,i=this.a.cbTypes;if(s.nonemptyintersection(i,s.includes)&&!s.nonemptyintersection(i,s.excludes)){let o=e.options1,r=this.b.cbTypes;return o.nonemptyintersection(r,o.includes)?!o.nonemptyintersection(r,o.excludes):!1}else return!1}}invalidate(){this.zip_listeners=!0}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.__validate())}__validate(){this.listeners.clear();let e=this.a.listeners.head,t=this.b.listeners.head;for(;e!=null&&t!=null;){let n=e.elt,l=t.elt;if(n==l){let s,i,o=n.options1,r=this.a.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=n.options2,p=this.b.cbTypes;i=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else i=!1;if(i)s=!0;else{let a=n.options2,p=this.a.cbTypes;if(a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)){let c=n.options1,u=this.b.cbTypes;s=c.nonemptyintersection(u,c.includes)&&!c.nonemptyintersection(u,c.excludes)}else s=!1}s&&this.listeners.add(n),e=e.next,t=t.next}else n.precedence>l.precedence||n.precedence==l.precedence&&n.id>l.id?e=e.next:t=t.next}}empty_intersection(){return this.listeners.head==null}single_intersection(e){let t=this.listeners.head;return t!=null&&t.elt==e?t.next==null:!1}forall(e,t){let n=this.listeners.head;for(;n!=null;){let l=n.elt;l.event==e&&t(l),n=n.next}}};Tn.__name__=["zpp_nape","callbacks","ZPP_CbSetPair"],Tn._zpp=null,Tn.zpp_pool=null;var Ne=Tn;var sn=class sn{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=sn._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){sn.ANY_SHAPE=new e.callbacks.CbType,sn.ANY_BODY=new e.callbacks.CbType,sn.ANY_COMPOUND=new e.callbacks.CbType,sn.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=sn._zpp,n=null,l=this.listeners.head;for(;l!=null;){let r=l.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.id)break;n=l,l=l.next}let s=this.listeners,i;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?i=new t.util.ZNPNode_ZPP_InteractionListener:(i=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=i.next,i.next=null),i.elt=e,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++;let o=this.cbsets.head;for(;o!=null;)o.elt.zip_listeners=!0,o.elt.invalidate_pairs(),o=o.next}removeint(e){this.listeners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_listeners=!0,t.elt.invalidate_pairs(),t=t.next}invalidateint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_listeners=!0,e.elt.invalidate_pairs(),e=e.next}addbody(e){let t=sn._zpp,n=null,l=this.bodylisteners.head;for(;l!=null;){let r=l.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.id)break;n=l,l=l.next}let s=this.bodylisteners,i;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?i=new t.util.ZNPNode_ZPP_BodyListener:(i=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=i.next,i.next=null),i.elt=e,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++;let o=this.cbsets.head;for(;o!=null;)o.elt.zip_bodylisteners=!0,o=o.next}removebody(e){this.bodylisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_bodylisteners=!0,t=t.next}invalidatebody(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_bodylisteners=!0,e=e.next}addconstraint(e){let t=sn._zpp,n=null,l=this.conlisteners.head;for(;l!=null;){let r=l.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.id)break;n=l,l=l.next}let s=this.conlisteners,i;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?i=new t.util.ZNPNode_ZPP_ConstraintListener:(i=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=i.next,i.next=null),i.elt=e,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++;let o=this.cbsets.head;for(;o!=null;)o.elt.zip_conlisteners=!0,o=o.next}removeconstraint(e){this.conlisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_conlisteners=!0,t=t.next}invalidateconstraint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_conlisteners=!0,e=e.next}};sn.__name__=["zpp_nape","callbacks","ZPP_CbType"],sn._zpp=null,sn.ANY_SHAPE=null,sn.ANY_BODY=null,sn.ANY_COMPOUND=null,sn.ANY_CONSTRAINT=null;var Cn=sn;var Xn=class Xn{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=zn.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()),Xn.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()),Xn.events=[t.CbEvent_BEGIN,t.CbEvent_END,t.CbEvent_WAKE,t.CbEvent_SLEEP,t.CbEvent_BREAK,t.CbEvent_PRE,t.CbEvent_ONGOING]}};Xn.__name__=["zpp_nape","callbacks","ZPP_Listener"],Xn._nape=null,Xn._zpp=null,Xn.internal=!1,Xn.types=[],Xn.events=[];var Wt=Xn;var Rs=class extends Wt{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=Wt._zpp;this.options.handler=(l,s,i)=>this.cbtype_change(l,s,i);let n=this.options.includes.head;for(;n!=null;){let l=n.elt,s=null,i=l.bodylisteners.head;for(;i!=null;){let c=i.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;s=i,i=i.next}let o=l.bodylisteners,r;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?r=new t.util.ZNPNode_ZPP_BodyListener:(r=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=r.next,r.next=null),r.elt=this;let a=r;s==null?(a.next=o.head,o.head=a):(a.next=s.next,s.next=a),o.pushmod=o.modified=!0,o.length++;let p=l.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_bodylisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.bodylisteners.remove(this);let l=n.cbsets.head;for(;l!=null;){let s=l.elt;s.zip_bodylisteners=!0,l=l.next}t=t.next}this.options.handler=null}cbtype_change(t,n,l){this.removedFromSpace();let s=this.options;n?l?s.effect_change(t,!0,!0):s.includes.remove(t):l?s.effect_change(t,!1,!0):s.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3)throw new Error("Error: BodyListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};Rs.__name__=["zpp_nape","callbacks","ZPP_BodyListener"];var qs=class extends Wt{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=Wt._zpp;this.options.handler=(l,s,i)=>this.cbtype_change(l,s,i);let n=this.options.includes.head;for(;n!=null;){let l=n.elt,s=null,i=l.conlisteners.head;for(;i!=null;){let c=i.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;s=i,i=i.next}let o=l.conlisteners,r;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?r=new t.util.ZNPNode_ZPP_ConstraintListener:(r=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=r.next,r.next=null),r.elt=this;let a=r;s==null?(a.next=o.head,o.head=a):(a.next=s.next,s.next=a),o.pushmod=o.modified=!0,o.length++;let p=l.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_conlisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.conlisteners.remove(this);let l=n.cbsets.head;for(;l!=null;){let s=l.elt;s.zip_conlisteners=!0,l=l.next}t=t.next}this.options.handler=null}cbtype_change(t,n,l){this.removedFromSpace();let s=this.options;n?l?s.effect_change(t,!0,!0):s.includes.remove(t):l?s.effect_change(t,!1,!0):s.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3&&t!=4)throw new Error("Error: ConstraintListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};qs.__name__=["zpp_nape","callbacks","ZPP_ConstraintListener"];var Ct=class Ct extends Wt{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=Wt._zpp,i=Ct.UCbSet,o=Ct.VCbSet,r=Ct.WCbSet,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,u=p.elt;if(c==u){let h=this._allocCbSetNode(s);h.elt=c,h.next=r.head,r.head=h,r.modified=!0,r.length++,a=a.next,p=p.next}else if(s.callbacks.ZPP_CbSet.setlt(c,u)){let h=this._allocCbSetNode(s);h.elt=c,h.next=i.head,i.head=h,i.modified=!0,i.length++,a=a.next}else{let h=this._allocCbSetNode(s);h.elt=u,h.next=o.head,o.head=h,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbSetNode(s);c.elt=a.elt,c.next=i.head,i.head=c,i.modified=!0,i.length++,a=a.next}for(;p!=null;){let c=this._allocCbSetNode(s);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.length++,p=p.next}for(;i.head!=null;){let c=i.pop_unsafe(),u=n.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;o.head!=null;){let c=o.pop_unsafe(),u=r.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;r.head!=null;){let c=r.pop_unsafe();l(c,c);let u=r.head;for(;u!=null;)l(c,u.elt),u=u.next}}CbTypeset(t,n,l){let s=Wt._zpp,i=Ct.UCbType,o=Ct.VCbType,r=Ct.WCbType,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,u=p.elt;if(c==u){let h=this._allocCbTypeNode(s);h.elt=c,h.next=r.head,r.head=h,r.modified=!0,r.length++,a=a.next,p=p.next}else if(c.id<u.id){let h=this._allocCbTypeNode(s);h.elt=c,h.next=i.head,i.head=h,i.modified=!0,i.length++,a=a.next}else{let h=this._allocCbTypeNode(s);h.elt=u,h.next=o.head,o.head=h,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbTypeNode(s);c.elt=a.elt,c.next=i.head,i.head=c,i.modified=!0,i.length++,a=a.next}for(;p!=null;){let c=this._allocCbTypeNode(s);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.length++,p=p.next}for(;i.head!=null;){let c=i.pop_unsafe(),u=n.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;o.head!=null;){let c=o.pop_unsafe(),u=r.head;for(;u!=null;)l(c,u.elt),u=u.next}for(;r.head!=null;){let c=r.pop_unsafe();l(c,c);let u=r.head;for(;u!=null;)l(c,u.elt),u=u.next}}with_uniquesets(t){let n=Wt._zpp,l;if(n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool==null?l=new n.util.ZPP_Set_ZPP_CbSetPair:(l=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=l.next,l.next=null),l.lt=n.callbacks.ZPP_CbSetPair.setlt,this.CbTypeset(this.options1.includes,this.options2.includes,(i,o)=>{this.CbSetset(i.cbsets,o.cbsets,(r,a)=>{if(r.validate(),a.validate(),n.callbacks.ZPP_CbSet.single_intersection(r,a,this)){let p;n.callbacks.ZPP_CbSetPair.zpp_pool==null?p=new n.callbacks.ZPP_CbSetPair:(p=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=p.next,p.next=null),p.zip_listeners=!0,n.callbacks.ZPP_CbSet.setlt(r,a)?(p.a=r,p.b=a):(p.a=a,p.b=r),l.try_insert(p)}})}),l.parent!=null){let i=l.parent;for(;i!=null;)if(i.prev!=null)i=i.prev;else if(i.next!=null)i=i.next;else{let o=i.data;t?this.space.freshListenerType(o.a,o.b):this.space.nullListenerType(o.a,o.b);let r=o;r.a=r.b=null,r.listeners.clear(),r.next=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=r;let a=i.parent;a!=null&&(i==a.prev?a.prev=null:a.next=null,i.parent=null);let p=i;p.data=null,p.lt=null,p.swapped=null,p.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=p,i=a}l.parent=null}let s=l;s.data=null,s.lt=null,s.swapped=null,s.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=s}with_union(t){let n=this.options1.includes.head,l=this.options2.includes.head;for(;n!=null&&l!=null;){let s=n.elt,i=l.elt;s==i?(t(s),n=n.next,l=l.next):s.id<i.id?(t(s),n=n.next):(t(i),l=l.next)}for(;n!=null;)t(n.elt),n=n.next;for(;l!=null;)t(l.elt),l=l.next}addedToSpace(){let t=Wt._zpp,n=this.type==3;this.with_union(l=>{let s=null,i=l.listeners.head;for(;i!=null;){let c=i.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;s=i,i=i.next}let o=l.listeners,r;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?r=new t.util.ZNPNode_ZPP_InteractionListener:(r=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=r.next,r.next=null),r.elt=this;let a=r;s==null?(a.next=o.head,o.head=a):(a.next=s.next,s.next=a),o.pushmod=o.modified=!0,o.length++;let p=l.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_listeners=!0,c.invalidate_pairs(),p=p.next}if(n){let c=l.interactors.head;for(;c!=null;)c.elt.wake(),c=c.next}}),this.options1.handler=(l,s,i)=>this.cbtype_change1(l,s,i),this.options2.handler=(l,s,i)=>this.cbtype_change2(l,s,i),this.with_uniquesets(!0)}removedFromSpace(){this.with_uniquesets(!1);let t=this.type==3;this.with_union(n=>{n.listeners.remove(this);let l=n.cbsets.head;for(;l!=null;){let s=l.elt;s.zip_listeners=!0,s.invalidate_pairs(),l=l.next}if(t){let s=n.interactors.head;for(;s!=null;)s.elt.wake(),s=s.next}}),this.options1.handler=null,this.options2.handler=null}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}cbtype_change1(t,n,l){this.cbtype_change(this.options1,t,n,l)}cbtype_change2(t,n,l){this.cbtype_change(this.options2,t,n,l)}cbtype_change(t,n,l,s){this.removedFromSpace(),l?s?t.effect_change(n,!0,!0):t.includes.remove(n):s?t.effect_change(n,!1,!0):t.excludes.remove(n),this.addedToSpace()}swapEvent(t){if(this.type==3)throw new Error("Error: PreListener event can only be PRE");if(t!=0&&t!=1&&t!=6)throw new Error("Error: InteractionListener event must be either BEGIN, END, ONGOING");this.removedFromSpace(),this.event=t,this.addedToSpace()}_allocCbSetNode(t){let n;return t.util.ZNPNode_ZPP_CbSet.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbSet:(n=t.util.ZNPNode_ZPP_CbSet.zpp_pool,t.util.ZNPNode_ZPP_CbSet.zpp_pool=n.next,n.next=null),n}_allocCbTypeNode(t){let n;return t.util.ZNPNode_ZPP_CbType.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbType:(n=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=n.next,n.next=null),n}static _initStatics(t){Ct.UCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.VCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.WCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.UCbType=new t.util.ZNPList_ZPP_CbType,Ct.VCbType=new t.util.ZNPList_ZPP_CbType,Ct.WCbType=new t.util.ZNPList_ZPP_CbType}};Ct.__name__=["zpp_nape","callbacks","ZPP_InteractionListener"],Ct.UCbSet=null,Ct.VCbSet=null,Ct.WCbSet=null,Ct.UCbType=null,Ct.VCbType=null,Ct.WCbType=null;var yl=Ct;var Gn=class Gn{constructor(){this.outer=null;this.handler=null;this.includes=null;this.excludes=null;this.wrap_includes=null;this.wrap_excludes=null;let e=Gn._zpp;this.includes=new e.util.ZNPList_ZPP_CbType,this.excludes=new e.util.ZNPList_ZPP_CbType}static argument(e){let t=Gn._nape;return e==null?new t.callbacks.OptionType:e instanceof t.callbacks.OptionType?e:new t.callbacks.OptionType().including(e)}setup_includes(){let e=Gn._zpp;this.wrap_includes=e.util.ZPP_CbTypeList.get(this.includes,!0)}setup_excludes(){let e=Gn._zpp;this.wrap_excludes=e.util.ZPP_CbTypeList.get(this.excludes,!0)}excluded(e){return this.nonemptyintersection(e,this.excludes)}included(e){return this.nonemptyintersection(e,this.includes)}compatible(e){return this.nonemptyintersection(e,this.includes)?!this.nonemptyintersection(e,this.excludes):!1}nonemptyintersection(e,t){let n=!1,l=e.head,s=t.head;for(;s!=null&&l!=null;){let i=s.elt,o=l.elt;if(i===o){n=!0;break}else i.id<o.id?s=s.next:l=l.next}return n}insertOrdered(e,t){let n=Gn._zpp,l=null,s=e.head;for(;s!=null;){let o=s.elt;if(t.id<o.id)break;l=s,s=s.next}let i;n.util.ZNPNode_ZPP_CbType.zpp_pool==null?i=new n.util.ZNPNode_ZPP_CbType:(i=n.util.ZNPNode_ZPP_CbType.zpp_pool,n.util.ZNPNode_ZPP_CbType.zpp_pool=i.next,i.next=null),i.elt=t,l==null?(i.next=e.head,e.head=i):(i.next=l.next,l.next=i),e.pushmod=e.modified=!0,e.length++}effect_change(e,t,n){t?n?this.insertOrdered(this.includes,e):this.includes.remove(e):n?this.insertOrdered(this.excludes,e):this.excludes.remove(e)}append_type(e,t){e===this.includes?this.includes.has(t)||(this.excludes.has(t)?this.handler!=null?this.handler(t,!1,!1):this.excludes.remove(t):this.handler!=null?this.handler(t,!0,!0):this.insertOrdered(this.includes,t)):this.excludes.has(t)||(this.includes.has(t)?this.handler!=null?this.handler(t,!0,!1):this.includes.remove(t):this.handler!=null?this.handler(t,!1,!0):this.insertOrdered(this.excludes,t))}set(e){if(e!==this){for(;this.includes.head!=null;)this.append_type(this.excludes,this.includes.head.elt);for(;this.excludes.head!=null;)this.append_type(this.includes,this.excludes.head.elt);let t=e.excludes.head;for(;t!=null;){let l=t.elt;this.append_type(this.excludes,l),t=t.next}let n=e.includes.head;for(;n!=null;){let l=n.elt;this.append_type(this.includes,l),n=n.next}}return this}append(e,t){let n=Gn._nape;if(t==null)throw new Error("Error: Cannot append null, only CbType and CbType list values");if(t instanceof n.callbacks.CbType){let l=t;this.append_type(e,l.zpp_inner)}else if(t instanceof n.callbacks.CbTypeList){let l=t;l.zpp_inner.valmod();let s=n.callbacks.CbTypeIterator.get(l);for(;;){s.zpp_inner.zpp_inner.valmod();let i=s.zpp_inner;i.zpp_inner.valmod(),i.zpp_inner.zip_length&&(i.zpp_inner.zip_length=!1,i.zpp_inner.user_length=i.zpp_inner.inner.length);let o=i.zpp_inner.user_length;s.zpp_critical=!0;let r;if(s.zpp_i<o?r=!0:(s.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=s,s.zpp_inner=null,r=!1),!r)break;s.zpp_critical=!1;let a=s.zpp_inner.at(s.zpp_i++);this.append_type(e,a.zpp_inner)}}else if(t instanceof Array){let l=t,s=0;for(;s<l.length;){let i=l[s];if(++s,!(i instanceof n.callbacks.CbType))throw new Error("Error: Cannot append non-CbType or CbType list value");let o=i;this.append_type(e,o.zpp_inner)}}else throw new Error("Error: Cannot append non-CbType or CbType list value")}};Gn.__name__=["zpp_nape","callbacks","ZPP_OptionType"],Gn._nape=null,Gn._zpp=null;var zs=Gn;var _n=class _n{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__=_n;this._initBase()}_initBase(){let e=_n._zpp;this.id=zn.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=_n._zpp;this.wrap_cbTypes=e.util.ZPP_CbTypeList.get(this.cbTypes),this.wrap_cbTypes.zpp_inner.adder=this.wrap_cbTypes_adder.bind(this),this.wrap_cbTypes.zpp_inner.subber=this.wrap_cbTypes_subber.bind(this),this.wrap_cbTypes.zpp_inner.dontremove=!0,this.wrap_cbTypes.zpp_inner._modifiable=this.immutable_cbTypes.bind(this)}immutable_cbTypes(){this.immutable_midstep("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=_n._zpp;if(!this.cbTypes.has(e)){this.space!=null&&(this.dealloc_cbSet(),e.constraints.add(this));let n=null,l=this.cbTypes.head;for(;l!=null;){let r=l.elt;if(e.id<r.id)break;n=l,l=l.next}let s=this.cbTypes,i;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?i=new t.util.ZNPNode_ZPP_CbType:(i=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=i.next,i.next=null),i.elt=e;let o=i;n==null?(o.next=s.head,s.head=o):(o.next=n.next,n.next=o),s.pushmod=s.modified=!0,s.length++,this.space!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){(this.cbSet=this.space.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.constraints.add(this))}dealloc_cbSet(){let e=_n._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=_n._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=_n._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=_n._nape,n=this.outer;n.zpp_inner.wrap_cbTypes==null&&n.zpp_inner.setupcbTypes();let l=n.zpp_inner.wrap_cbTypes;l.zpp_inner.valmod();let s=t.callbacks.CbTypeIterator.get(l);for(;;){s.zpp_inner.zpp_inner.valmod();let b=s.zpp_inner;b.zpp_inner.valmod(),b.zpp_inner.zip_length&&(b.zpp_inner.zip_length=!1,b.zpp_inner.user_length=b.zpp_inner.inner.length);let _=b.zpp_inner.user_length;s.zpp_critical=!0;let d;if(s.zpp_i<_?d=!0:(s.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=s,s.zpp_inner=null,d=!1),!d)break;s.zpp_critical=!1;let f=s.zpp_inner.at(s.zpp_i++);e.zpp_inner.wrap_cbTypes==null&&e.zpp_inner.setupcbTypes();let m=e.zpp_inner.wrap_cbTypes;m.zpp_inner.reverse_flag?m.push(f):m.unshift(f)}e.zpp_inner.removeOnBreak=n.zpp_inner.removeOnBreak;let i=n.zpp_inner.breakUnderError;e.zpp_inner.breakUnderError!=i&&(e.zpp_inner.breakUnderError=i,e.zpp_inner.wake());let o=n.zpp_inner.breakUnderForce;e.zpp_inner.breakUnderForce!=o&&(e.zpp_inner.breakUnderForce=o,e.zpp_inner.wake());let r=n.zpp_inner.maxError;if(r!==r)throw new Error("Error: Constraint::maxError cannot be NaN");if(r<0)throw new Error("Error: Constraint::maxError must be >=0");e.zpp_inner.maxError!=r&&(e.zpp_inner.maxError=r,e.zpp_inner.wake());let a=n.zpp_inner.maxForce;if(a!==a)throw new Error("Error: Constraint::maxForce cannot be NaN");if(a<0)throw new Error("Error: Constraint::maxForce must be >=0");e.zpp_inner.maxForce!=a&&(e.zpp_inner.maxForce=a,e.zpp_inner.wake());let p=n.zpp_inner.damping;if(p!==p)throw new Error("Error: Constraint::Damping cannot be Nan");if(p<0)throw new Error("Error: Constraint::Damping must be >=0");e.zpp_inner.damping!=p&&(e.zpp_inner.damping=p,e.zpp_inner.stiff||e.zpp_inner.wake());let c=n.zpp_inner.frequency;if(c!==c)throw new Error("Error: Constraint::Frequency cannot be NaN");if(c<=0)throw new Error("Error: Constraint::Frequency must be >0");e.zpp_inner.frequency!=c&&(e.zpp_inner.frequency=c,e.zpp_inner.stiff||e.zpp_inner.wake());let u=n.zpp_inner.stiff;e.zpp_inner.stiff!=u&&(e.zpp_inner.stiff=u,e.zpp_inner.wake());let h=n.zpp_inner.ignore;e.zpp_inner.ignore!=h&&(e.zpp_inner.ignore=h,e.zpp_inner.wake());let x=n.zpp_inner.active;e.zpp_inner.active!=x&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.woken=!1),e.zpp_inner.clearcache(),x?(e.zpp_inner.active=x,e.zpp_inner.activate(),e.zpp_inner.space!=null&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.sleeping=!0),e.zpp_inner.space.wake_constraint(e.zpp_inner,!0))):(e.zpp_inner.space!=null&&(e.zpp_inner.wake(),e.zpp_inner.space.live_constraints.remove(e.zpp_inner)),e.zpp_inner.active=x,e.zpp_inner.deactivate()))}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let l=t.parent;t.parent=n,n=t,t=l}for(;n!=null;){let l=n.parent;n.parent=t,n=l}return t}static _unionComponents(e,t){let n=_n._findRoot(e),l=_n._findRoot(t);n!=l&&(n.rank<l.rank?n.parent=l:n.rank>l.rank?l.parent=n:(l.parent=n,n.rank++))}};_n.__name__=["zpp_nape","constraint","ZPP_Constraint"],_n._nape=null,_n._zpp=null;var ge=_n;var Ws=class Ws{constructor(){this.id=0;this.bc=null;this.cb=null}static dict(e,t){let n=new Ws;return n.id=e,n.bc=t,n}static todo(e,t){let n=new Ws;return n.id=e,n.cb=t,n}};Ws.__name__=["zpp_nape","constraint","ZPP_CopyHelper"];var Rn=Ws;var Ps=class Ps extends ge{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=ye();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.scale*this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.scale*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let l=Ps._createFn(null,null,this.jointMin,this.jointMax,this.ratio);if(this.copyto(l),t!=null&&this.b1!=null){let s=null,i=0;for(;i<t.length;){let o=t[i];if(++i,o.id==this.b1.id){s=o.bc;break}}s!=null?l.zpp_inner.b1=s.zpp_inner:n.push(Rn.todo(this.b1.id,o=>{l.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let s=null,i=0;for(;i<t.length;){let o=t[i];if(++i,o.id==this.b2.id){s=o.bc;break}}s!=null?l.zpp_inner.b2=s.zpp_inner:n.push(Rn.todo(this.b2.id,o=>{l.zpp_inner.b2=o.zpp_inner}))}return l}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: AngleJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: AngleJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let l=this.b1.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let l=this.b2.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1,this.slack=!1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax;let l=this.ratio*this.b2.rot-this.b1.rot;this.equal?(l-=this.jointMax,this.slack=!1,this.scale=1):l<this.jointMin?(l=this.jointMin-l,this.scale=-1,this.slack=!1):l>this.jointMax?(l-=this.jointMax,this.scale=1,this.slack=!1):(this.scale=0,l=0,this.slack=!0);let s=l;if(!this.slack){if(this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&s*s>this.maxError*this.maxError)return!0;let i=2*Math.PI*this.frequency;this.gamma=1/(t*i*(2*this.damping+i*t));let o=1/(1+this.gamma),r=t*i*i*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-s*r,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){this.slack||(this.b1.angvel-=this.scale*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*this.jAcc)}applyImpulseVel(){if(this.slack)return!1;let t=this.scale*(this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel),n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,l=this.jAcc;return this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&(this.jAcc>this.jMax||this.jAcc<-this.jMax)?!0:(this.stiff||(this.jAcc>this.jMax?this.jAcc=this.jMax:this.jAcc<-this.jMax&&(this.jAcc=-this.jMax)),n=this.jAcc-l,this.b1.angvel-=this.scale*this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*n,!1)}applyImpulsePos(){let t=this.ratio*this.b2.rot-this.b1.rot,n;this.equal?(t-=this.jointMax,n=!1,this.scale=1):t<this.jointMin?(t=this.jointMin-t,this.scale=-1,n=!1):t>this.jointMax?(t-=this.jointMax,this.scale=1,n=!1):(this.scale=0,t=0,n=!0);let l=t;if(!n){if(this.breakUnderError&&l*l>this.maxError*this.maxError)return!0;let i=-(l*.5)*this.kMass;if(this.equal||i<0){let o=this.b1,r=-this.scale*i*this.b1.iinertia;if(o.rot+=r,r*r>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let c=r*r,u=1-.5*c,h=1-c*c/8,x=(u*o.axisx+r*o.axisy)*h;o.axisy=(u*o.axisy-r*o.axisx)*h,o.axisx=x}let a=this.b2,p=this.ratio*this.scale*i*this.b2.iinertia;if(a.rot+=p,p*p>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let c=p*p,u=1-.5*c,h=1-c*c/8,x=(u*a.axisx+p*a.axisy)*h;a.axisy=(u*a.axisy-p*a.axisx)*h,a.axisx=x}}}return!1}draw(t){}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let l=n*n,s=1-.5*l,i=1-l*l/8,o=(s*t.axisx+n*t.axisy)*i;t.axisy=(s*t.axisy-n*t.axisx)*i,t.axisx=o}}static _copyBody(t,n,l,s,i){if(t!=null&&l!=null){let o=null;for(let r=0;r<t.length;r++){let a=t[r];if(a.id==l.id){o=a.bc;break}}o!=null?s.zpp_inner_zn[i]=o.zpp_inner:n.push(Rn.todo(l.id,function(r){s.zpp_inner_zn[i]=r.zpp_inner}))}}};Ps.__name__=["zpp_nape","constraint","ZPP_AngleJoint"],Ps._wrapFn=null,Ps._createFn=null;var qe=Ps;var Nt=class Nt{constructor(){this.x=0;this.y=0;this.next=null;this.length=0;this.modified=!1;this.pushmod=!1;this._inuse=!1;this.weak=!1;this.outer=null;this._immutable=!1;this._isimmutable=null;this._validate=null;this._invalidate=null}static get(e,t,n){n==null&&(n=!1);let l;return Nt.zpp_pool==null?l=new Nt:(l=Nt.zpp_pool,Nt.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(Nt._wrapFn)this.outer=Nt._wrapFn(this);else{this.outer=new Nt._nape.geom.Vec2;let e=this.outer.zpp_inner;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e._isimmutable=null,e._validate=null,e._invalidate=null,e.next=Nt.zpp_pool,Nt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this._isimmutable=null,this._validate=null,this._invalidate=null}alloc(){this.weak=!1}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}inlined_add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;)this.add(t),t=t.next}insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}inlined_insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let 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 Nt.zpp_pool==null?n=new Nt:(n=Nt.zpp_pool,Nt.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,n}toString(){return"{ x: "+this.x+" y: "+this.y+" }"}};Nt.zpp_pool=null,Nt.__name__=["zpp_nape","geom","ZPP_Vec2"],Nt._nape=null,Nt._zpp=null,Nt._wrapFn=null;var le=Nt;var li=class li extends ge{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<ge._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=ge._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAcc*this.nx,-this.jAcc*this.ny,-this.cx1*this.jAcc):n.geom.Vec3.get(this.jAcc*this.nx,this.jAcc*this.ny,this.cx2*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){this.wrap_a1=li._setupAnchorVec2(this.a1localx,this.a1localy,this.validate_a1.bind(this),this.invalidate_a1.bind(this))}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){this.wrap_a2=li._setupAnchorVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=li._createFn(null,null,s,i.zpp_inner_zn.wrap_a2,this.jointMin,this.jointMax);return this.copyto(o),qe._copyBody(t,n,this.b1,o,"b1"),qe._copyBody(t,n,this.b2,o,"b2"),o}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: DistanceJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&ge._unionComponents(this.b1.component,this.component),this.b2.type==2&&ge._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<ge._nape.Config.epsilon)this.nx=0,this.ny=0,l=0,this.slack=!0;else{l=Math.sqrt(l);let i=1/l;this.nx*=i,this.ny*=i,this.equal?(l-=this.jointMax,this.slack=!1):l<this.jointMin?(l=this.jointMin-l,this.nx=-this.nx,this.ny=-this.ny,this.slack=!1):l>this.jointMax?(l-=this.jointMax,this.slack=!1):(this.nx=0,this.ny=0,l=0,this.slack=!0)}let s=l;if(!this.slack){if(this.cx1=this.ny*this.a1relx-this.nx*this.a1rely,this.cx2=this.ny*this.a2relx-this.nx*this.a2rely,this.kMass=this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&s*s>this.maxError*this.maxError)return!0;let i=2*Math.PI*this.frequency;this.gamma=1/(t*i*(2*this.damping+i*t));let o=1/(1+this.gamma),r=t*i*i*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-s*r,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.nx*t,this.b1.vely-=this.ny*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.nx*n,this.b2.vely+=this.ny*n,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.nx*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.ny*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,l=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-l;let s=this.b1.imass*n;this.b1.velx-=this.nx*s,this.b1.vely-=this.ny*s;let i=this.b2.imass*n;return this.b2.velx+=this.nx*i,this.b2.vely+=this.ny*i,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,!1}applyImpulsePos(){let t,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,s=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,i=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o,r=this.b2.posx+s-(this.b1.posx+n),a=this.b2.posy+i-(this.b1.posy+l),p=r*r+a*a;if(p<ge._nape.Config.epsilon)r=0,a=0,p=0,o=!0;else{p=Math.sqrt(p);let u=1/p;r*=u,a*=u,this.equal?(p-=this.jointMax,o=!1):p<this.jointMin?(p=this.jointMin-p,r=-r,a=-a,o=!1):p>this.jointMax?(p-=this.jointMax,o=!1):(r=0,a=0,p=0,o=!0)}let c=p;if(!o){if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;if(c*c<ge._nape.Config.constraintLinearSlop*ge._nape.Config.constraintLinearSlop)return!1;if(c*=.5,c*c>6){let b=this.b1.smass+this.b2.smass;if(b>ge._nape.Config.epsilon){let _=.75/b;if(t=-c*_,this.equal||t<0){let d=t*this.b1.imass;this.b1.posx-=r*d,this.b1.posy-=a*d;let f=t*this.b2.imass;this.b2.posx+=r*f,this.b2.posy+=a*f,r=this.b2.posx+s-(this.b1.posx+n),a=this.b2.posy+i-(this.b1.posy+l);let m=r*r+a*a;if(m<ge._nape.Config.epsilon)r=0,a=0,m=0;else{m=Math.sqrt(m);let z=1/m;r*=z,a*=z,this.equal?m-=this.jointMax:m<this.jointMin?(m=this.jointMin-m,r=-r,a=-a):m>this.jointMax?m-=this.jointMax:(r=0,a=0,m=0)}c=m,c*=.5}}}let u=a*n-r*l,h=a*s-r*i,x=this.b1.smass+this.b2.smass+u*u*this.b1.sinertia+h*h*this.b2.sinertia;if(x!=0&&(x=1/x),t=-c*x,this.equal||t<0){let b=this.b1.imass*t;this.b1.posx-=r*b,this.b1.posy-=a*b;let _=this.b2.imass*t;this.b2.posx+=r*_,this.b2.posy+=a*_,qe._rotateBody(this.b1,-u*this.b1.iinertia*t),qe._rotateBody(this.b2,h*this.b2.iinertia*t)}}return!1}draw(t){}static _setupAnchorVec2(t,n,l,s){let i=ge._nape,o=t,r=n;if(r==null&&(r=0),o==null&&(o=0),o!=o||r!=r)throw new Error("Error: Vec2 components cannot be NaN");let a;if(xe.poolVec2==null?a=new i.geom.Vec2:(a=xe.poolVec2,xe.poolVec2=a.zpp_pool,a.zpp_pool=null,a.zpp_disp=!1,a==xe.nextVec2&&(xe.nextVec2=null)),a.zpp_inner==null){let p;le.zpp_pool==null?p=new le:(p=le.zpp_pool,le.zpp_pool=p.next,p.next=null),p.weak=!1,p._immutable=!1,p.x=o,p.y=r,a.zpp_inner=p,a.zpp_inner.outer=a}else{if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=a.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),o!=o||r!=r)throw new Error("Error: Vec2 components cannot be NaN");let c;if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=a.zpp_inner;if(u._validate!=null&&u._validate(),a.zpp_inner.x==o){if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=a.zpp_inner;h._validate!=null&&h._validate(),c=a.zpp_inner.y==r}else c=!1;if(!c){a.zpp_inner.x=o,a.zpp_inner.y=r;let h=a.zpp_inner;h._invalidate!=null&&h._invalidate(h)}}return a.zpp_inner.weak=!1,a.zpp_inner._inuse=!0,a.zpp_inner._validate=l,a.zpp_inner._invalidate=s,a}};li.__name__=["zpp_nape","constraint","ZPP_DistanceJoint"],li.__super__=ge,li._wrapFn=null,li._createFn=null;var oi=li;var $i=class $i extends ge{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=ge._nape,o=ge._zpp;if(n==null&&(n=0),t==null&&(t=0),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");let r;if(o.util.ZPP_PubPool.poolVec2==null?r=new i.geom.Vec2:(r=o.util.ZPP_PubPool.poolVec2,o.util.ZPP_PubPool.poolVec2=r.zpp_pool,r.zpp_pool=null,r.zpp_disp=!1,r==o.util.ZPP_PubPool.nextVec2&&(o.util.ZPP_PubPool.nextVec2=null)),r.zpp_inner==null){let a;o.geom.ZPP_Vec2.zpp_pool==null?a=new o.geom.ZPP_Vec2:(a=o.geom.ZPP_Vec2.zpp_pool,o.geom.ZPP_Vec2.zpp_pool=a.next,a.next=null),a.weak=!1,a._immutable=!1,a.x=t,a.y=n,r.zpp_inner=a,r.zpp_inner.outer=r}else{if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=r.zpp_inner;if(a._immutable)throw new Error("Error: Vec2 is immutable");if(a._isimmutable!=null&&a._isimmutable(),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=r.zpp_inner;p._validate!=null&&p._validate();let c;if(r.zpp_inner.x==t){if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=r.zpp_inner;u._validate!=null&&u._validate(),c=r.zpp_inner.y==n}else c=!1;if(!c){r.zpp_inner.x=t,r.zpp_inner.y=n;let u=r.zpp_inner;u._invalidate!=null&&u._invalidate(u)}}return r.zpp_inner.weak=!1,r.zpp_inner._inuse=!0,r.zpp_inner._validate=l,r.zpp_inner._invalidate=s,r}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){this.wrap_a1=this._setupVec2(this.a1localx,this.a1localy,this.validate_a1.bind(this),this.invalidate_a1.bind(this))}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){this.wrap_a2=this._setupVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}validate_n(){this.wrap_n.zpp_inner.x=this.nlocalx,this.wrap_n.zpp_inner.y=this.nlocaly}invalidate_n(t){this.immutable_midstep("Constraint::n"),this.nlocalx=t.x,this.nlocaly=t.y,this.zip_n=!0,this.wake()}setup_n(){this.wrap_n=this._setupVec2(this.nlocalx,this.nlocaly,this.validate_n.bind(this),this.invalidate_n.bind(this))}validate_norm(){if(this.zip_n){this.zip_n=!1;let t=this.nlocalx*this.nlocalx+this.nlocaly*this.nlocaly,l=1/Math.sqrt(t);this.nlocalx*=l,this.nlocaly*=l}}bodyImpulse(t){let n=ge._nape;if(this.stepped){let l=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,s=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy;return t==this.b1?n.geom.Vec3.get(-l,-s,this.scale*this.cx1*s-this.dot1*l):n.geom.Vec3.get(l,s,this.scale*this.cx1*s-this.dot1*l)}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=i.zpp_inner_zn.wrap_a2,r=this.outer_zn;r.zpp_inner_zn.wrap_n==null&&r.zpp_inner_zn.setup_n();let a=$i._createFn(null,null,s,o,r.zpp_inner_zn.wrap_n,this.jointMin,this.jointMax);return this.copyto(a),qe._copyBody(t,n,this.b1,a,"b1"),qe._copyBody(t,n,this.b2,a,"b2"),a}validate(){let t=ge._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&&ge._unionComponents(this.b1.component,this.component),this.b2.type==2&&ge._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.equal=this.jointMin==this.jointMax,this.stepped=!0,this.validate_norm(),this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.nrelx=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,this.nrely=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let l=this.b2.posx+this.a2relx-this.b1.posx-this.a1relx,s=this.b2.posy+this.a2rely-this.b1.posy-this.a1rely,i=s*this.nrelx-l*this.nrely,o=this.nrelx*l+this.nrely*s;this.equal?(o-=this.jointMin,this.scale=1):o>this.jointMax?(o-=this.jointMax,this.scale=1):o<this.jointMin?(o=this.jointMin-o,this.scale=-1):(o=0,this.scale=0);let r=l+this.a1relx,a=s+this.a1rely;this.dot1=this.nrelx*r+this.nrely*a,this.cx1=a*this.nrelx-r*this.nrely,this.dot2=this.nrelx*this.a2relx+this.nrely*this.a2rely,this.cx2=this.a2rely*this.nrelx-this.a2relx*this.nrely,this.kMassa=this.b1.smass+this.b2.smass+this.dot1*this.dot1*this.b1.sinertia+this.dot2*this.dot2*this.b2.sinertia,this.kMassb=-this.scale*(this.dot1*this.cx1*this.b1.sinertia+this.dot2*this.cx2*this.b2.sinertia),this.kMassc=this.scale*this.scale*(this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia);let p=this.kMassa*this.kMassc-this.kMassb*this.kMassb,c;if(p!==p)this.kMassa=this.kMassb=this.kMassc=0,c=3;else if(p==0){let h=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,h|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,h|=2),this.kMassb=0,c=h}else{let h=1/p,x=this.kMassc*h;this.kMassc=this.kMassa*h,this.kMassa=x,this.kMassb*=-h,c=0}if((c&1)!=0&&(this.jAccx=0),(c&2)!=0&&(this.jAccy=0),this.stiff)this.gamma=0,this.biasx=0,this.biasy=0;else{if(this.breakUnderError&&i*i+o*o>this.maxError*this.maxError)return!0;let h=2*Math.PI*this.frequency;this.gamma=1/(t*h*(2*this.damping+h*t));let x=1/(1+this.gamma),b=t*h*h*this.gamma;this.gamma*=x;let _=x;this.kMassa*=_,this.kMassb*=_,this.kMassc*=_,this.biasx=i,this.biasy=o;let d=-b;this.biasx*=d,this.biasy*=d;let f=this.maxError,m=this.biasx*this.biasx+this.biasy*this.biasy;if(m>f*f){let z=f*(1/Math.sqrt(m));this.biasx*=z,this.biasy*=z}}let u=n;return this.jAccx*=u,this.jAccy*=u,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,n=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy,l=this.b1.imass;this.b1.velx-=t*l,this.b1.vely-=n*l;let s=this.b2.imass;this.b2.velx+=t*s,this.b2.vely+=n*s,this.b1.angvel+=(this.scale*this.cx1*this.jAccy-this.dot1*this.jAccx)*this.b1.iinertia,this.b2.angvel+=(this.dot2*this.jAccx-this.scale*this.cx2*this.jAccy)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx-this.b1.velx,n=this.b2.vely-this.b1.vely;t+=this.b2.kinvelx-this.b1.kinvelx,n+=this.b2.kinvely-this.b1.kinvely;let l=n*this.nrelx-t*this.nrely+(this.b2.angvel+this.b2.kinangvel)*this.dot2-(this.b1.angvel+this.b1.kinangvel)*this.dot1,s=this.scale*(this.nrelx*t+this.nrely*n-(this.b2.angvel+this.b2.kinangvel)*this.cx2+(this.b1.angvel+this.b1.kinangvel)*this.cx1),i=this.biasx-l,o=this.biasy-s,r=this.kMassa*i+this.kMassb*o;o=this.kMassb*i+this.kMassc*o,i=r;let a=this.gamma;i-=this.jAccx*a,o-=this.jAccy*a;let p=this.jAccx,c=this.jAccy;if(this.jAccx+=i,this.jAccy+=o,this.jAccy>0&&(this.jAccy=0),this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let f=this.jMax,m=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(m>f*f){let z=f*(1/Math.sqrt(m));this.jAccx*=z,this.jAccy*=z}}let u=this.jAccx-p,h=this.jAccy-c,x=this.scale*this.nrelx*h-this.nrely*u,b=this.nrelx*u+this.scale*this.nrely*h,_=this.b1.imass;this.b1.velx-=x*_,this.b1.vely-=b*_;let d=this.b2.imass;return this.b2.velx+=x*d,this.b2.vely+=b*d,this.b1.angvel+=(this.scale*this.cx1*h-this.dot1*u)*this.b1.iinertia,this.b2.angvel+=(this.dot2*u-this.scale*this.cx2*h)*this.b2.iinertia,!1}applyImpulsePos(){let t=ge._nape,n=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,l=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,s=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,i=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,o=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,r=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,a=this.b2.posx+o-this.b1.posx-s,p=this.b2.posy+r-this.b1.posy-i,c,u=p*n-a*l,h=n*a+l*p;if(this.equal?(h-=this.jointMin,c=1):h>this.jointMax?(h-=this.jointMax,c=1):h<this.jointMin?(h=this.jointMin-h,c=-1):(h=0,c=0),this.breakUnderError&&u*u+h*h>this.maxError*this.maxError)return!0;if(u*u+h*h<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let x,b,_=.5;if(u*=_,h*=_,u*u+h*h>6){let C=this.b1.smass+this.b2.smass;if(C>t.Config.epsilon){let L=.8/C,O=L*(l*u-c*n*h),I=L*(n*u*c-l*u),T=this.b1.imass;this.b1.posx-=O*T,this.b1.posy-=I*T;let W=this.b2.imass;this.b2.posx+=O*W,this.b2.posy+=I*W,a=this.b2.posx+o-this.b1.posx-s,p=this.b2.posy+r-this.b1.posy-i,u=p*n-a*l,h=n*a+l*p,this.equal?(h-=this.jointMin,c=1):h>this.jointMax?(h-=this.jointMax,c=1):h<this.jointMin?(h=this.jointMin-h,c=-1):(h=0,c=0);let R=.5;u*=R,h*=R}}let d=a+s,f=p+i,m=n*d+l*f,z=f*n-d*l,Z=n*o+l*r,y=r*n-o*l,w=this.b1.smass+this.b2.smass+m*m*this.b1.sinertia+Z*Z*this.b2.sinertia,v=-c*(m*z*this.b1.sinertia+Z*y*this.b2.sinertia),P=c*c*(this.b1.smass+this.b2.smass+z*z*this.b1.sinertia+y*y*this.b2.sinertia);x=-u,b=-h;let g=w*P-v*v;if(g!==g)b=0,x=b;else if(g==0)w!=0?x/=w:x=0,P!=0?b/=P:b=0;else{let C=1/g,L=C*(P*x-v*b);b=C*(w*b-v*x),x=L}b>0&&(b=0);let k=c*n*b-l*x,N=n*x+c*l*b,E=this.b1.imass;this.b1.posx-=k*E,this.b1.posy-=N*E;let M=this.b2.imass;return this.b2.posx+=k*M,this.b2.posy+=N*M,qe._rotateBody(this.b1,(c*z*b-m*x)*this.b1.iinertia),qe._rotateBody(this.b2,(Z*x-c*y*b)*this.b2.iinertia),!1}draw(t){}};$i.__name__=["zpp_nape","constraint","ZPP_LineJoint"],$i.__super__=ge,$i._wrapFn=null,$i._createFn=null;var ri=$i;var ws=class ws extends ge{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=ye();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let l=ws._createFn(null,null,this.rate,this.ratio);if(this.copyto(l),t!=null&&this.b1!=null){let s=null,i=0;for(;i<t.length;){let o=t[i];if(++i,o.id==this.b1.id){s=o.bc;break}}s!=null?l.zpp_inner.b1=s.zpp_inner:n.push(Rn.todo(this.b1.id,o=>{l.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let s=null,i=0;for(;i<t.length;){let o=t[i];if(++i,o.id==this.b2.id){s=o.bc;break}}s!=null?l.zpp_inner.b2=s.zpp_inner:n.push(Rn.todo(this.b2.id,o=>{l.zpp_inner.b2=o.zpp_inner}))}return l}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: MotorJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let l=this.b1.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let l=this.b2.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}t=l}let n;if(this.component==this.component.parent)n=this.component;else{let l=this.component,s=null;for(;l!=l.parent;){let i=l.parent;l.parent=s,s=l,l=i}for(;s!=null;){let i=s.parent;s.parent=l,s=i}n=l}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;return this.pre_dt=t,this.stepped=!0,this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass=1/this.kMass,this.jAcc*=n,this.jMax=this.maxForce*t,!1}warmStart(){this.b1.angvel-=this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.b2.iinertia*this.jAcc}applyImpulseVel(){let t=this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel-this.rate,n=-this.kMass*t,l=this.jAcc;if(this.jAcc+=n,this.breakUnderForce){if(this.jAcc>this.jMax||this.jAcc<-this.jMax)return!0}else this.jAcc<-this.jMax?this.jAcc=-this.jMax:this.jAcc>this.jMax&&(this.jAcc=this.jMax);return n=this.jAcc-l,this.b1.angvel-=this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.b2.iinertia*n,!1}applyImpulsePos(){return!1}};ws.__name__=["zpp_nape","constraint","ZPP_MotorJoint"],ws._wrapFn=null,ws._createFn=null;var ai=ws;var es=class es extends ge{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=ge._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=ge._nape,n=ge._zpp,l=this.a1localx,s=this.a1localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a1=i,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=ge._nape,n=ge._zpp,l=this.a2localx,s=this.a2localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a2=i,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=es._createFn(null,null,s,i.zpp_inner_zn.wrap_a2);return this.copyto(o),qe._copyBody(t,n,this.b1,o,"b1"),qe._copyBody(t,n,this.b2,o,"b2"),o}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: 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&&ge._unionComponents(this.b1.component,this.component),this.b2.type==2&&ge._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let l=this.b1.smass+this.b2.smass;if(this.kMassa=l,this.kMassb=0,this.kMassc=l,this.b1.sinertia!=0){let r=this.a1relx*this.b1.sinertia,a=this.a1rely*this.b1.sinertia;this.kMassa+=a*this.a1rely,this.kMassb+=-a*this.a1relx,this.kMassc+=r*this.a1relx}if(this.b2.sinertia!=0){let r=this.a2relx*this.b2.sinertia,a=this.a2rely*this.b2.sinertia;this.kMassa+=a*this.a2rely,this.kMassb+=-a*this.a2relx,this.kMassc+=r*this.a2relx}let s=this.kMassa*this.kMassc-this.kMassb*this.kMassb,i;if(s!=s)this.kMassa=this.kMassb=this.kMassc=0,i=3;else if(s==0){let r=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,r|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,r|=2),this.kMassb=0,i=r}else{let r=1/s,a=this.kMassc*r;this.kMassc=this.kMassa*r,this.kMassa=a,this.kMassb*=-r,i=0}if((i&1)!=0&&(this.jAccx=0),(i&2)!=0&&(this.jAccy=0),this.stiff)this.biasx=0,this.biasy=0,this.gamma=0;else{let r=2*Math.PI*this.frequency;this.gamma=1/(t*r*(2*this.damping+r*t));let a=1/(1+this.gamma),p=t*r*r*this.gamma;this.gamma*=a;let c=a;if(this.kMassa*=c,this.kMassb*=c,this.kMassc*=c,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy>this.maxError*this.maxError)return!0;let u=-p;this.biasx*=u,this.biasy*=u;let h=this.maxError,x=this.biasx*this.biasx+this.biasy*this.biasy;if(x>h*h){let b=h*(1/Math.sqrt(x));this.biasx*=b,this.biasy*=b}}let o=n;return this.jAccx*=o,this.jAccy*=o,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),l=this.biasx-t,s=this.biasy-n,i=this.kMassa*l+this.kMassb*s;s=this.kMassb*l+this.kMassc*s,l=i;let o=this.gamma;l-=this.jAccx*o,s-=this.jAccy*o;let r=this.jAccx,a=this.jAccy,p=1;if(this.jAccx+=l*p,this.jAccy+=s*p,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let h=this.jMax,x=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(x>h*h){let b=h*(1/Math.sqrt(x));this.jAccx*=b,this.jAccy*=b}}l=this.jAccx-r,s=this.jAccy-a;let c=this.b1.imass;this.b1.velx-=l*c,this.b1.vely-=s*c;let u=this.b2.imass;return this.b2.velx+=l*u,this.b2.vely+=s*u,this.b1.angvel-=(s*this.a1relx-l*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(s*this.a2relx-l*this.a2rely)*this.b2.iinertia,!1}applyImpulsePos(){let t=ge._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,s=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,i=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o=this.b2.posx+s-(this.b1.posx+n),r=this.b2.posy+i-(this.b1.posy+l);if(this.breakUnderError&&o*o+r*r>this.maxError*this.maxError)return!0;if(o*o+r*r<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let a=.5;o*=a,r*=a;let p,c;if(o*o+r*r>6){let w=this.b1.smass+this.b2.smass;if(w>t.Config.epsilon){let v=.75/w;p=-o*v,c=-r*v;let P=20,g=p*p+c*c;if(g>P*P){let M=P*(1/Math.sqrt(g));p*=M,c*=M}let k=this.b1.imass;this.b1.posx-=p*k,this.b1.posy-=c*k;let N=this.b2.imass;this.b2.posx+=p*N,this.b2.posy+=c*N,o=this.b2.posx+s-(this.b1.posx+n),r=this.b2.posy+i-(this.b1.posy+l);let E=.5;o*=E,r*=E}}let u=this.b1.smass+this.b2.smass,h=u,x=0,b=u;if(this.b1.sinertia!=0){let w=n*this.b1.sinertia,v=l*this.b1.sinertia;h+=v*l,x+=-v*n,b+=w*n}if(this.b2.sinertia!=0){let w=s*this.b2.sinertia,v=i*this.b2.sinertia;h+=v*i,x+=-v*s,b+=w*s}p=-o,c=-r;let _=6,d=p*p+c*c;if(d>_*_){let w=_*(1/Math.sqrt(d));p*=w,c*=w}let f=h*b-x*x;if(f!=f)c=0,p=0;else if(f==0)h!=0?p/=h:p=0,b!=0?c/=b:c=0;else{let w=1/f,v=w*(b*p-x*c);c=w*(h*c-x*p),p=v}let m=this.b1.imass;this.b1.posx-=p*m,this.b1.posy-=c*m;let z=this.b2.imass;this.b2.posx+=p*z,this.b2.posy+=c*z;let Z=-(c*n-p*l)*this.b1.iinertia;qe._rotateBody(this.b1,Z);let y=(c*s-p*i)*this.b2.iinertia;return qe._rotateBody(this.b2,y),!1}draw(t){}};es.__name__=["zpp_nape","constraint","ZPP_PivotJoint"],es.__super__=ge,es._wrapFn=null,es._createFn=null;var pi=es;var ts=class ts extends ge{constructor(){super();this.outer_zn=null;this.ratio=1;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.n12x=0;this.n12y=0;this.n34x=0;this.n34y=0;this.cx1=0;this.cx2=0;this.cx3=0;this.cx4=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.b3=null;this.a3localx=0;this.a3localy=0;this.a3relx=0;this.a3rely=0;this.wrap_a3=null;this.b4=null;this.a4localx=0;this.a4localy=0;this.a4relx=0;this.a4rely=0;this.wrap_a4=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.a3localx=0,this.a3localy=0,this.a3relx=0,this.a3rely=0,this.a4localx=0,this.a4localy=0,this.a4relx=0,this.a4rely=0,this.n12x=1,this.n12y=0,this.n34x=1,this.n34y=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=this.cx3=this.cx4=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),l=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),s=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),i=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),o=Math.sqrt(n*n+l*l),r=Math.sqrt(s*s+i*i),a=o+this.ratio*r;return this.equal||a<this.jointMin||a>this.jointMax?t=!1:t=!0,t}bodyImpulse(t){let n=ge._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=ge._nape,n=ge._zpp,l=this.a1localx,s=this.a1localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a1=i,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=ge._nape,n=ge._zpp,l=this.a2localx,s=this.a2localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a2=i,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}validate_a3(){this.wrap_a3.zpp_inner.x=this.a3localx,this.wrap_a3.zpp_inner.y=this.a3localy}invalidate_a3(t){this.immutable_midstep("Constraint::a3"),this.a3localx=t.x,this.a3localy=t.y,this.wake()}setup_a3(){let t=ge._nape,n=ge._zpp,l=this.a3localx,s=this.a3localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a3=i,this.wrap_a3.zpp_inner._inuse=!0,this.wrap_a3.zpp_inner._validate=this.validate_a3.bind(this),this.wrap_a3.zpp_inner._invalidate=this.invalidate_a3.bind(this)}validate_a4(){this.wrap_a4.zpp_inner.x=this.a4localx,this.wrap_a4.zpp_inner.y=this.a4localy}invalidate_a4(t){this.immutable_midstep("Constraint::a4"),this.a4localx=t.x,this.a4localy=t.y,this.wake()}setup_a4(){let t=ge._nape,n=ge._zpp,l=this.a4localx,s=this.a4localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a4=i,this.wrap_a4.zpp_inner._inuse=!0,this.wrap_a4.zpp_inner._validate=this.validate_a4.bind(this),this.wrap_a4.zpp_inner._invalidate=this.invalidate_a4.bind(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=i.zpp_inner_zn.wrap_a2,r=this.outer_zn;r.zpp_inner_zn.wrap_a3==null&&r.zpp_inner_zn.setup_a3();let a=r.zpp_inner_zn.wrap_a3,p=this.outer_zn;p.zpp_inner_zn.wrap_a4==null&&p.zpp_inner_zn.setup_a4();let c=ts._createFn(null,null,null,null,s,o,a,p.zpp_inner_zn.wrap_a4,this.jointMin,this.jointMax,this.ratio);return this.copyto(c),qe._copyBody(t,n,this.b1,c,"b1"),qe._copyBody(t,n,this.b2,c,"b2"),qe._copyBody(t,n,this.b3,c,"b3"),qe._copyBody(t,n,this.b4,c,"b4"),c}validate(){if(this.b1==null||this.b2==null||this.b3==null||this.b4==null)throw new Error("Error: PulleyJoint cannot be simulated with null bodies");if(this.b1==this.b2||this.b3==this.b4)throw new Error("Error: PulleyJoint cannot have body1==body2 or body3==body4");if(this.b1.space!=this.space||this.b2.space!=this.space||this.b3.space!=this.space||this.b4.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: PulleyJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: PulleyJoint cannot have both bodies in a linked pair non-dynamic");if(this.b3.type!=2&&this.b4.type!=2)throw new Error("Error: PulleyJoint cannot have both bodies in a linked pair non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake(),this.b3!=null&&this.b3.type==2&&this.b3.wake(),this.b4!=null&&this.b4.type==2&&this.b4.wake()}forest(){this.b1.type==2&&ge._unionComponents(this.b1.component,this.component),this.b2.type==2&&ge._unionComponents(this.b2.component,this.component),this.b3.type==2&&ge._unionComponents(this.b3.component,this.component),this.b4.type==2&&ge._unionComponents(this.b4.component,this.component)}pair_exists(t,n){return this.b1.id==t&&(this.b2.id==n||this.b3.id==n||this.b4.id==n)||this.b2.id==t&&(this.b3.id==n||this.b4.id==n||this.b1.id==n)||this.b3.id==t&&(this.b4.id==n||this.b1.id==n||this.b2.id==n)?!0:this.b4.id==t?this.b1.id==n||this.b2.id==n?!0:this.b3.id==n:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let l=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),o=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),r=Math.sqrt(l*l+s*s),a=Math.sqrt(i*i+o*o);if(r!=0){let u=1/r;this.n12x=l*u,this.n12y=s*u}if(a!=0){let u=1/a;this.n34x=i*u,this.n34y=o*u;let h=this.ratio;this.n34x*=h,this.n34y*=h}else{let u=this.ratio/Math.sqrt(this.n34x*this.n34x+this.n34y*this.n34y);this.n34x*=u,this.n34y*=u}let p=r+this.ratio*a;this.equal?(p-=this.jointMax,this.slack=!1):p<this.jointMin?(p=this.jointMin-p,this.n12x=-this.n12x,this.n12y=-this.n12y,this.n34x=-this.n34x,this.n34y=-this.n34y,this.slack=!1):p>this.jointMax?(p-=this.jointMax,this.slack=!1):(this.n12x=0,this.n12y=0,this.n34x=0,this.n34y=0,p=0,this.slack=!0);let c=p;if(!this.slack){this.cx1=this.n12y*this.a1relx-this.n12x*this.a1rely,this.cx2=this.n12y*this.a2relx-this.n12x*this.a2rely,this.cx3=this.n34y*this.a3relx-this.n34x*this.a3rely,this.cx4=this.n34y*this.a4relx-this.n34x*this.a4rely;let u=this.ratio*this.ratio,h=this.b1.smass+this.b2.smass+u*(this.b3.smass+this.b4.smass)+this.b1.sinertia*this.cx1*this.cx1+this.b2.sinertia*this.cx2*this.cx2+this.b3.sinertia*this.cx3*this.cx3+this.b4.sinertia*this.cx4*this.cx4;if(this.b1==this.b4&&(h-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx4*this.b1.sinertia)),this.b1==this.b3&&(h+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx3*this.b1.sinertia)),this.b2==this.b3&&(h-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx3*this.b2.sinertia)),this.b2==this.b4&&(h+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx4*this.b2.sinertia)),this.kMass=h,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;let x=2*Math.PI*this.frequency;this.gamma=1/(t*x*(2*this.damping+x*t));let b=1/(1+this.gamma),_=t*x*x*this.gamma;this.gamma*=b,this.kMass*=b,this.bias=-c*_,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.n12x*t,this.b1.vely-=this.n12y*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.n12x*n,this.b2.vely+=this.n12y*n;let l=this.b3.imass*this.jAcc;this.b3.velx-=this.n34x*l,this.b3.vely-=this.n34y*l;let s=this.b4.imass*this.jAcc;this.b4.velx+=this.n34x*s,this.b4.vely+=this.n34y*s,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc,this.b3.angvel-=this.cx3*this.b3.iinertia*this.jAcc,this.b4.angvel+=this.cx4*this.b4.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.n12x*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.n12y*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+this.n34x*(this.b4.velx+this.b4.kinvelx-this.b3.velx-this.b3.kinvelx)+this.n34y*(this.b4.vely+this.b4.kinvely-this.b3.vely-this.b3.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1+(this.b4.angvel+this.b4.kinangvel)*this.cx4-(this.b3.angvel+this.b3.kinangvel)*this.cx3,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,l=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-l;let s=this.b1.imass*n;this.b1.velx-=this.n12x*s,this.b1.vely-=this.n12y*s;let i=this.b2.imass*n;this.b2.velx+=this.n12x*i,this.b2.vely+=this.n12y*i;let o=this.b3.imass*n;this.b3.velx-=this.n34x*o,this.b3.vely-=this.n34y*o;let r=this.b4.imass*n;return this.b4.velx+=this.n34x*r,this.b4.vely+=this.n34y*r,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,this.b3.angvel-=this.cx3*this.b3.iinertia*n,this.b4.angvel+=this.cx4*this.b4.iinertia*n,!1}applyImpulsePos(){let t=ge._nape,n,l=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,o=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,a=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,p=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,c=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy,u,h=this.n12x,x=this.n12y,b=this.n34x,_=this.n34y,d=this.b2.posx+i-(this.b1.posx+l),f=this.b2.posy+o-(this.b1.posy+s),m=this.b4.posx+p-(this.b3.posx+r),z=this.b4.posy+c-(this.b3.posy+a),Z=Math.sqrt(d*d+f*f),y=Math.sqrt(m*m+z*z);if(Z!=0){let P=1/Z;h=d*P,x=f*P}if(y!=0){let P=1/y;b=m*P,_=z*P;let g=this.ratio;b*=g,_*=g}else{let P=this.ratio/Math.sqrt(b*b+_*_);b*=P,_*=P}let w=Z+this.ratio*y;this.equal?(w-=this.jointMax,u=!1):w<this.jointMin?(w=this.jointMin-w,h=-h,x=-x,b=-b,_=-_,u=!1):w>this.jointMax?(w-=this.jointMax,u=!1):(h=0,x=0,b=0,_=0,w=0,u=!0);let v=w;if(!u){if(this.breakUnderError&&v*v>this.maxError*this.maxError)return!0;if(v*v<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;if(v*=.5,v*v>6){let L=this.b1.smass+this.b2.smass;if(L>t.Config.epsilon){let O=.75/L;if(n=-v*O,this.equal||n<0){let I=n*this.b1.imass;this.b1.posx-=h*I,this.b1.posy-=x*I;let T=n*this.b2.imass;this.b2.posx+=h*T,this.b2.posy+=x*T;let W=n*this.b3.imass;this.b3.posx-=b*W,this.b3.posy-=_*W;let R=n*this.b4.imass;this.b4.posx+=b*R,this.b4.posy+=_*R;let G=this.b2.posx+i-(this.b1.posx+l),j=this.b2.posy+o-(this.b1.posy+s),S=this.b4.posx+p-(this.b3.posx+r),q=this.b4.posy+c-(this.b3.posy+a),$=Math.sqrt(G*G+j*j),X=Math.sqrt(S*S+q*q);if($!=0){let ee=1/$;h=G*ee,x=j*ee}if(X!=0){let ee=1/X;b=S*ee,_=q*ee;let F=this.ratio;b*=F,_*=F}else{let ee=this.ratio/Math.sqrt(b*b+_*_);b*=ee,_*=ee}let H=$+this.ratio*X;this.equal?H-=this.jointMax:H<this.jointMin?(H=this.jointMin-H,h=-h,x=-x,b=-b,_=-_):H>this.jointMax?H-=this.jointMax:(h=0,x=0,b=0,_=0,H=0),v=H,v*=.5}}}let P=x*l-h*s,g=x*i-h*o,k=_*r-b*a,N=_*p-b*c,E=this.ratio*this.ratio,M=this.b1.smass+this.b2.smass+E*(this.b3.smass+this.b4.smass)+this.b1.sinertia*P*P+this.b2.sinertia*g*g+this.b3.sinertia*k*k+this.b4.sinertia*N*N;this.b1==this.b4&&(M-=2*((h*b+x*_)*this.b1.smass+P*N*this.b1.sinertia)),this.b1==this.b3&&(M+=2*((h*b+x*_)*this.b1.smass+P*k*this.b1.sinertia)),this.b2==this.b3&&(M-=2*((h*b+x*_)*this.b2.smass+g*k*this.b2.sinertia)),this.b2==this.b4&&(M+=2*((h*b+x*_)*this.b2.smass+g*N*this.b2.sinertia));let C=M;if(C!=0&&(C=1/C),n=-v*C,this.equal||n<0){let L=this.b1.imass*n;this.b1.posx-=h*L,this.b1.posy-=x*L;let O=this.b2.imass*n;this.b2.posx+=h*O,this.b2.posy+=x*O;let I=this.b3.imass*n;this.b3.posx-=b*I,this.b3.posy-=_*I;let T=this.b4.imass*n;this.b4.posx+=b*T,this.b4.posy+=_*T,qe._rotateBody(this.b1,-P*this.b1.iinertia*n),qe._rotateBody(this.b2,g*this.b2.iinertia*n),qe._rotateBody(this.b3,-k*this.b3.iinertia*n),qe._rotateBody(this.b4,N*this.b4.iinertia*n)}}return!1}draw(t){}};ts.__name__=["zpp_nape","constraint","ZPP_PulleyJoint"],ts.__super__=ge,ts._wrapFn=null,ts._createFn=null;var ci=ts;var ns=class{constructor(e,t){this.cnt=0;this.body=null;this.cnt=e,this.body=t}};ns.__name__=["zpp_nape","constraint","ZPP_UserBody"];var Js=class Js extends ge{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__=Js;this.bodies=[],this.dim=t,this.velonly=n,this.jAcc=[],this.bias=[],this.L=[],this.J=[],this.jOld=[],this.y=[],this.Keff=[],this.vec3=ge._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 ns(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=ge._nape.geom.Vec3.get(0,0,0);return this.stepped&&this.outer_zn.__impulse(this.J,t.outer,n),n}activeBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.add(this)}inactiveBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.remove(this)}copy(t,n){let l=this.outer_zn.__copy();throw this.copyto(l),new Error("not done yet")}validate(){for(let t of this.bodies)if(t.body.space!==this.space)throw new Error("Error: Constraints must have each body within the same sapce to which the constraint has been assigned");this.outer_zn.__validate()}wake_connected(){for(let t of this.bodies)t.body.type===2&&t.body.wake()}forest(){for(let t of this.bodies)if(t.body.type===2){let n;if(t.body.component===t.body.component.parent)n=t.body.component;else{let s=t.body.component,i=null;for(;s!==s.parent;){let o=s.parent;s.parent=i,i=s,s=o}for(;i!=null;){let o=i.parent;i.parent=s,i=o}n=s}let l;if(this.component===this.component.parent)l=this.component;else{let s=this.component,i=null;for(;s!==s.parent;){let o=s.parent;s.parent=i,i=s,s=o}for(;i!=null;){let o=i.parent;i.parent=s,i=o}l=s}n!==l&&(n.rank<l.rank?n.parent=l:n.rank>l.rank?l.parent=n:(l.parent=n,n.rank++))}}pair_exists(t,n){let l=!1,s=this.bodies.length|0;for(let i=0;i<s;i++){let o=this.bodies[i].body;for(let r=i+1;r<s;r++){let a=this.bodies[r].body;if(o.id===t&&a.id===n||o.id===n&&a.id===t){l=!0;break}}if(l)break}return l}broken(){this.outer_zn.__broken()}clearcache(){for(let t=0;t<this.dim;t++)this.jAcc[t]=0;this.pre_dt=-1}lsq(t){let n=0;for(let l=0;l<this.dim;l++)n+=t[l]*t[l];return n}_clamp(t,n){let l=this.lsq(t);if(l>n*n){let s=n/Math.sqrt(l);for(let i=0;i<this.dim;i++)t[i]*=s}}solve(t){let n=0;for(let l=0;l<this.dim;l++){let s=0;for(let o=0;o<l-1;o++)s+=this.L[l*this.dim+o]*this.L[l*this.dim+o];let i=Math.sqrt(t[n++]-s);if(this.L[l*this.dim+l]=i,i!==0){i=1/i;for(let o=l+1;o<this.dim;o++){let r=0;for(let a=0;a<l-1;a++)r+=this.L[o*this.dim+a]*this.L[l*this.dim+a];this.L[o*this.dim+l]=i*(t[n++]-r)}}else{for(let o=l+1;o<this.dim;o++)this.L[o*this.dim+l]=0;n+=this.dim-l-1}}return this.L}transform(t,n){for(let l=0;l<this.dim;l++){let s=n[l],i=t[l*this.dim+l];if(i!==0){for(let o=0;o<l;o++)s-=t[l*this.dim+o]*this.y[o];this.y[l]=s/i}else this.y[l]=0}for(let l=0;l<this.dim;l++){let s=this.dim-1-l,i=t[s*this.dim+s];if(i!==0){let o=this.y[s];for(let r=s+1;r<this.dim;r++)o-=t[r*this.dim+s]*n[r];n[s]=o/i}else n[s]=0}}preStep(t){this.pre_dt===-1&&(this.pre_dt=t);let n=t/this.pre_dt;if(this.pre_dt=t,this.stepped=!0,this.outer_zn.__prepare(),this.outer_zn.__eff_mass(this.Keff),this.L=this.solve(this.Keff),!this.stiff&&!this.velonly){let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let s=1/(1+this.gamma),i=t*l*l*this.gamma;if(this.gamma*=s,this.soft=s,this.outer_zn.__position(this.bias),this.breakUnderError&&this.lsq(this.bias)>this.maxError*this.maxError)return!0;for(let o=0;o<this.dim;o++)this.bias[o]*=-i;this._clamp(this.bias,this.maxError)}else{for(let l=0;l<this.dim;l++)this.bias[l]=0;this.gamma=0,this.soft=1}for(let l=0;l<this.dim;l++)this.jAcc[l]*=n;return this.jMax=this.maxForce*t,!1}warmStart(){for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.jAcc,n.outer,this.vec3);let l=n.imass,s=n,i=s.velx,o=this.vec3;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let r=o.zpp_inner;r._validate!=null&&r._validate(),s.velx=i+o.zpp_inner.x*l;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let u=c.zpp_inner;u._validate!=null&&u._validate(),a.vely=p+c.zpp_inner.y*l;let h=n,x=h.angvel,b=this.vec3;if(b!=null&&b.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=b.zpp_inner;_._validate!=null&&_._validate(),h.angvel=x+b.zpp_inner.z*n.iinertia}}applyImpulseVel(){this.outer_zn.__velocity(this.J);for(let t=0;t<this.dim;t++)this.J[t]=this.bias[t]-this.J[t];this.transform(this.L,this.J);for(let t=0;t<this.dim;t++)this.jOld[t]=this.jAcc[t],this.jAcc[t]+=this.J[t]=this.J[t]*this.soft-this.jAcc[t]*this.gamma;if(this.outer_zn.__clamp(this.jAcc),(this.breakUnderForce||!this.stiff)&&this.lsq(this.jAcc)>this.jMax*this.jMax){if(this.breakUnderForce)return!0;this.stiff||this._clamp(this.jAcc,this.jMax)}for(let t=0;t<this.dim;t++)this.J[t]=this.jAcc[t]-this.jOld[t];for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.J,n.outer,this.vec3);let l=n.imass,s=n,i=s.velx,o=this.vec3;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let r=o.zpp_inner;r._validate!=null&&r._validate(),s.velx=i+o.zpp_inner.x*l;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let u=c.zpp_inner;u._validate!=null&&u._validate(),a.vely=p+c.zpp_inner.y*l;let h=n,x=h.angvel,b=this.vec3;if(b!=null&&b.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=b.zpp_inner;_._validate!=null&&_._validate(),h.angvel=x+b.zpp_inner.z*n.iinertia}return!1}applyImpulsePos(){if(this.velonly)return!1;this.outer_zn.__prepare(),this.outer_zn.__position(this.J);let t=this.lsq(this.J);if(this.breakUnderError&&t>this.maxError*this.maxError)return!0;if(t<ge._nape.Config.constraintLinearSlop*ge._nape.Config.constraintLinearSlop)return!1;for(let n=0;n<this.dim;n++)this.J[n]*=-1;this.outer_zn.__eff_mass(this.Keff),this.transform(this.solve(this.Keff),this.J),this.outer_zn.__clamp(this.J);for(let n of this.bodies){let l=n.body;this.outer_zn.__impulse(this.J,l.outer,this.vec3);let s=l.imass,i=l,o=i.posx,r=this.vec3;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let a=r.zpp_inner;a._validate!=null&&a._validate(),i.posx=o+r.zpp_inner.x*s;let p=l,c=p.posy,u=this.vec3;if(u!=null&&u.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let h=u.zpp_inner;h._validate!=null&&h._validate(),p.posy=c+u.zpp_inner.y*s;let x=this.vec3;if(x!=null&&x.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let b=x.zpp_inner;b._validate!=null&&b._validate();let _=x.zpp_inner.z*l.iinertia;if(l.rot+=_,_*_>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let d=_*_,f=1-.5*d,m=1-d*d/8,z=(f*l.axisx+_*l.axisy)*m;l.axisy=(f*l.axisy-_*l.axisx)*m,l.axisx=z}}return!1}draw(t){this.outer_zn.__draw(t)}};Js.__name__=["zpp_nape","constraint","ZPP_UserConstraint"],Js.__super__=ge;var Us=Js;var is=class is extends ge{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=ge._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=ge._nape,n=ge._zpp,l=this.a1localx,s=this.a1localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a1=i,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=ge._nape,n=ge._zpp,l=this.a2localx,s=this.a2localy;if(s==null&&(s=0),l==null&&(l=0),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_a2=i,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let l=this.outer_zn;l.zpp_inner_zn.wrap_a1==null&&l.zpp_inner_zn.setup_a1();let s=l.zpp_inner_zn.wrap_a1,i=this.outer_zn;i.zpp_inner_zn.wrap_a2==null&&i.zpp_inner_zn.setup_a2();let o=is._createFn(null,null,s,i.zpp_inner_zn.wrap_a2);return this.copyto(o),qe._copyBody(t,n,this.b1,o,"b1"),qe._copyBody(t,n,this.b2,o,"b2"),o}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: WeldJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&ge._unionComponents(this.b1.component,this.component),this.b2.type==2&&ge._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.jAccz=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let l=this.b1.smass+this.b2.smass;if(this.kMassa=l,this.kMassb=0,this.kMassd=l,this.kMassc=0,this.kMasse=0,this.kMassf=0,this.b1.sinertia!=0){let o=this.a1relx*this.b1.sinertia,r=this.a1rely*this.b1.sinertia;this.kMassa+=r*this.a1rely,this.kMassb+=-r*this.a1relx,this.kMassd+=o*this.a1relx,this.kMassc+=-r,this.kMasse+=o,this.kMassf+=this.b1.sinertia}if(this.b2.sinertia!=0){let o=this.a2relx*this.b2.sinertia,r=this.a2rely*this.b2.sinertia;this.kMassa+=r*this.a2rely,this.kMassb+=-r*this.a2relx,this.kMassd+=o*this.a2relx,this.kMassc+=-r,this.kMasse+=o,this.kMassf+=this.b2.sinertia}let s=this.kMassa*(this.kMassd*this.kMassf-this.kMasse*this.kMasse)+this.kMassb*(this.kMassc*this.kMasse-this.kMassb*this.kMassf)+this.kMassc*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),i;if(s!=s)this.kMassa=0,this.kMassb=0,this.kMassd=0,this.kMassc=0,this.kMasse=0,this.kMassf=0,i=7;else if(s==0){let o=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,o|=1),this.kMassd!=0?this.kMassd=1/this.kMassd:(this.kMassd=0,o|=2),this.kMassf!=0?this.kMassf=1/this.kMassf:(this.kMassf=0,o|=4),this.kMassb=this.kMassc=this.kMasse=0,i=o}else{let o=1/s,r=o*(this.kMassd*this.kMassf-this.kMasse*this.kMasse),a=o*(this.kMasse*this.kMassc-this.kMassb*this.kMassf),p=o*(this.kMassa*this.kMassf-this.kMassc*this.kMassc),c=o*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),u=o*(this.kMassb*this.kMassc-this.kMassa*this.kMasse),h=o*(this.kMassa*this.kMassd-this.kMassb*this.kMassb);this.kMassa=r,this.kMassb=a,this.kMassd=p,this.kMassc=c,this.kMasse=u,this.kMassf=h,i=0}if((i&1)!=0&&(this.jAccx=0),(i&2)!=0&&(this.jAccy=0),(i&4)!=0&&(this.jAccz=0),this.stiff)this.biasx=0,this.biasy=0,this.biasz=0,this.gamma=0;else{let o=2*Math.PI*this.frequency;this.gamma=1/(t*o*(2*this.damping+o*t));let r=1/(1+this.gamma),a=t*o*o*this.gamma;this.gamma*=r;let p=r;if(this.kMassa*=p,this.kMassb*=p,this.kMassd*=p,this.kMassc*=p,this.kMasse*=p,this.kMassf*=p,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.biasz=this.b2.rot-this.b1.rot-this.phase,this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz>this.maxError*this.maxError)return!0;let c=-a;this.biasx*=c,this.biasy*=c,this.biasz*=c;let u=this.maxError,h=this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz;if(h>u*u){let x=u*(1/Math.sqrt(h));this.biasx*=x,this.biasy*=x,this.biasz*=x}}return this.jAccx*=n,this.jAccy*=n,this.jAccz*=n,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),l=this.b2.angvel+this.b2.kinangvel-this.b1.angvel-this.b1.kinangvel,s=this.biasx-t,i=this.biasy-n,o=this.biasz-l,r=this.kMassa*s+this.kMassb*i+this.kMassc*o,a=this.kMassb*s+this.kMassd*i+this.kMasse*o;o=this.kMassc*s+this.kMasse*i+this.kMassf*o,s=r,i=a,s-=this.jAccx*this.gamma,i-=this.jAccy*this.gamma,o-=this.jAccz*this.gamma;let p=this.jAccx,c=this.jAccy,u=this.jAccz;if(this.jAccx+=s,this.jAccy+=i,this.jAccz+=o,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz>this.jMax*this.jMax)return!0}else if(!this.stiff){let b=this.jMax,_=this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz;if(_>b*b){let d=b*(1/Math.sqrt(_));this.jAccx*=d,this.jAccy*=d,this.jAccz*=d}}s=this.jAccx-p,i=this.jAccy-c,o=this.jAccz-u;let h=this.b1.imass;this.b1.velx-=s*h,this.b1.vely-=i*h;let x=this.b2.imass;return this.b2.velx+=s*x,this.b2.vely+=i*x,this.b1.angvel-=(i*this.a1relx-s*this.a1rely+o)*this.b1.iinertia,this.b2.angvel+=(i*this.a2relx-s*this.a2rely+o)*this.b2.iinertia,!1}applyImpulsePos(){let t=ge._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,s=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,i=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o=this.b2.posx+s-(this.b1.posx+n),r=this.b2.posy+i-(this.b1.posy+l),a=this.b2.rot-this.b1.rot-this.phase,p,c,u;if(this.breakUnderError&&o*o+r*r+a*a>this.maxError*this.maxError)return!0;let h=!0;o*o+r*r<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(h=!1,o=0,r=0);let x=t.Config.constraintAngularSlop;if(a*a<x*x)if(h)a=0;else return!1;if(o*=.5,r*=.5,a*=.5,o*o+r*r>6){let O=this.b1.smass+this.b2.smass;if(O>t.Config.epsilon){let I=.75/O;p=-o*I,c=-r*I;let T=20,W=p*p+c*c;if(W>T*T){let j=T*(1/Math.sqrt(W));p*=j,c*=j}let R=this.b1.imass;this.b1.posx-=p*R,this.b1.posy-=c*R;let G=this.b2.imass;this.b2.posx+=p*G,this.b2.posy+=c*G,o=this.b2.posx+s-(this.b1.posx+n),r=this.b2.posy+i-(this.b1.posy+l),a=this.b2.rot-this.b1.rot-this.phase,o*=.5,r*=.5,a*=.5}}let b=this.b1.smass+this.b2.smass,_=b,d=0,f=b,m=0,z=0,Z=0;if(this.b1.sinertia!=0){let O=n*this.b1.sinertia,I=l*this.b1.sinertia;_+=I*l,d+=-I*n,f+=O*n,m+=-I,z+=O,Z+=this.b1.sinertia}if(this.b2.sinertia!=0){let O=s*this.b2.sinertia,I=i*this.b2.sinertia;_+=I*i,d+=-I*s,f+=O*s,m+=-I,z+=O,Z+=this.b2.sinertia}p=-o,c=-r,u=-a;let y=6,w=p*p+c*c;if(w>y*y){let O=y*(1/Math.sqrt(w));p*=O,c*=O}let P=u<-.25,g=_*(f*Z-z*z)+d*(m*z-d*Z)+m*(d*z-m*f);if(g!=g)u=0,c=u,p=c;else if(g==0)_!=0?p/=_:p=0,f!=0?c/=f:c=0,Z!=0?u/=Z:u=0;else{let O=1/g,I=z*m-d*Z,T=d*z-m*f,W=d*m-_*z,R=O*(p*(f*Z-z*z)+c*I+u*T),G=O*(p*I+c*(_*Z-m*m)+u*W);u=O*(p*T+c*W+u*(_*f-d*d)),p=R,c=G}let k=this.b1.imass;this.b1.posx-=p*k,this.b1.posy-=c*k;let N=this.b2.imass;this.b2.posx+=p*N,this.b2.posy+=c*N;let E=this.b1,M=-(c*n-p*l+u)*this.b1.iinertia;qe._rotateBody(E,M);let C=this.b2,L=(c*s-p*i+u)*this.b2.iinertia;return qe._rotateBody(C,L),!1}draw(t){}};is.__name__=["zpp_nape","constraint","ZPP_WeldJoint"],is.__super__=ge,is._wrapFn=null,is._createFn=null;var hi=is;var st=class st{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()),st.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID]}wrapper(){if(this.outer==null){let e=st._nape;st.internal=!0,this.type==st.COL?(this.colarb.outer_zn=st._createColArb(),this.outer=this.colarb.outer_zn):this.type==st.FLUID?(this.fluidarb.outer_zn=st._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,st.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=st._zpp;this.cleared=!0,(t==null||this.b2==t)&&st._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&st._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=st._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=l,st._addToArbiterList(this.b1.arbiters,this,s),st._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=st._zpp;this.cleared||(st._removeFromArbiterList(this.b1.arbiters,this,e),st._removeFromArbiterList(this.b2.arbiters,this,e),this.pair!=null&&(this.pair.arb=null,this.pair=null)),this.b1=this.b2=null,this.active=!1,this.intchange=!1}static _removeFromArbiterList(e,t,n){let l=null,s=e.head;for(;s!=null;){if(s.elt==t){let i,o;l==null?(i=e.head,o=i.next,e.head=o,e.head==null&&(e.pushmod=!0)):(i=l.next,o=i.next,l.next=o,o==null&&(e.pushmod=!0));let r=i;r.elt=null,r.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=r,e.modified=!0,e.length--,e.pushmod=!0;break}l=s,s=s.next}}static _addToArbiterList(e,t,n){let l;n.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?l=new n.util.ZNPNode_ZPP_Arbiter:(l=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=l.next,l.next=null),l.elt=t;let s=l;s.next=e.head,e.head=s,e.modified=!0,e.length++}};st.__name__=["zpp_nape","dynamics","ZPP_Arbiter"],st._nape=null,st._zpp=null,st.internal=!1,st._createColArb=null,st._createFluidArb=null,st.COL=1,st.FLUID=4,st.SENSOR=2,st.types=[];var Ve=st;var ss=class ss extends Ve{constructor(){super(),this.next=null,this.type=Ve.SENSOR,this.sensorarb=this}alloc(){}free(){}assign(e,t,n,l){this.sup_assign(e,t,n,l)}retire(){this.sup_retire(),this.next=ss.zpp_pool,ss.zpp_pool=this}makemutable(){}makeimmutable(){}};ss.__name__=["zpp_nape","dynamics","ZPP_SensorArbiter"],ss.__super__=Ve,ss.zpp_pool=null;var Bt=ss;var ls=class ls extends Ve{constructor(){super();this.outer_zn=null;this.centroidx=0;this.centroidy=0;this.overlap=0;this.r1x=0;this.r1y=0;this.r2x=0;this.r2y=0;this.nodrag=!1;this.wMass=0;this.adamp=0;this.agamma=0;this.vMassa=0;this.vMassb=0;this.vMassc=0;this.dampx=0;this.dampy=0;this.lgamma=0;this.nx=0;this.ny=0;this.buoyx=0;this.buoyy=0;this.wrap_position=null;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.wrap_position=null,this.buoyy=0,this.buoyx=0,this.ny=0,this.nx=0,this.lgamma=0,this.dampy=0,this.dampx=0,this.vMassc=0,this.vMassb=0,this.vMassa=0,this.agamma=0,this.adamp=0,this.wMass=0,this.nodrag=!1,this.r2y=0,this.r2x=0,this.r1y=0,this.r1x=0,this.overlap=0,this.centroidy=0,this.centroidx=0,this.next=null,this.outer_zn=null,this.type=Ve.FLUID,this.fluidarb=this,this.buoyx=0,this.buoyy=0,this.pre_dt=-1}alloc(){}free(){}position_validate(){if(!this.active)throw new Error("Error: Arbiter not currently in use");this.wrap_position.zpp_inner.x=this.centroidx,this.wrap_position.zpp_inner.y=this.centroidy}position_invalidate(t){this.centroidx=t.x,this.centroidy=t.y}getposition(){let t=Ve._zpp,n=Ve._nape,l;if(t.util.ZPP_PubPool.poolVec2==null?l=new n.geom.Vec2:(l=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let s;t.geom.ZPP_Vec2.zpp_pool==null?s=new t.geom.ZPP_Vec2:(s=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,l.zpp_inner=s,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._validate!=null&&o._validate(),l.zpp_inner.x==0){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;r._validate!=null&&r._validate(),i=l.zpp_inner.y==0}else i=!1;if(!i){l.zpp_inner.x=0,l.zpp_inner.y=0;let r=l.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}l.zpp_inner.weak=!1,this.wrap_position=l,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!this.mutable,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this),this.wrap_position.zpp_inner._invalidate=this.position_invalidate.bind(this)}assign(t,n,l,s){this.sup_assign(t,n,l,s),this.nx=0,this.ny=1,this.dampx=0,this.dampy=0,this.adamp=0}retire(){this.sup_retire(),this.next=ls.zpp_pool,ls.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=Ve._nape;this.pre_dt==-1&&(this.pre_dt=n);let s=n/this.pre_dt;this.pre_dt=n,this.r1x=this.centroidx-this.b1.posx,this.r1y=this.centroidy-this.b1.posy,this.r2x=this.centroidx-this.b2.posx,this.r2y=this.centroidy-this.b2.posy;let i,o;this.ws1.fluidEnabled&&this.ws1.fluidProperties.wrap_gravity!=null?(i=this.ws1.fluidProperties.gravityx,o=this.ws1.fluidProperties.gravityy):(i=t.gravityx,o=t.gravityy);let r,a;this.ws2.fluidEnabled&&this.ws2.fluidProperties.wrap_gravity!=null?(r=this.ws2.fluidProperties.gravityx,a=this.ws2.fluidProperties.gravityy):(r=t.gravityx,a=t.gravityy);let p=0,c=0;if(this.ws1.fluidEnabled&&this.ws2.fluidEnabled){let u=this.overlap*this.ws1.fluidProperties.density,h=this.overlap*this.ws2.fluidProperties.density;if(u>h){let x=u+h;p-=i*x,c-=o*x}else if(u<h){let x=u+h;p+=r*x,c+=a*x}else{let x=i+r,b=o+a,_=.5;if(x*=_,b*=_,this.ws1.worldCOMx*x+this.ws1.worldCOMy*b>this.ws2.worldCOMx*x+this.ws2.worldCOMy*b){let d=u+h;p-=x*d,c-=b*d}else{let d=u+h;p+=x*d,c+=b*d}}}else if(this.ws1.fluidEnabled){let u=this.overlap*this.ws1.fluidProperties.density;p-=i*u,c-=o*u}else if(this.ws2.fluidEnabled){let u=this.overlap*this.ws2.fluidProperties.density;p+=r*u,c+=a*u}if(p*=n,c*=n,this.buoyx=p,this.buoyy=c,this.b1.type==2&&(this.b1.velx-=p*this.b1.imass,this.b1.vely-=c*this.b1.imass,this.b1.angvel-=(c*this.r1x-p*this.r1y)*this.b1.iinertia),this.b2.type==2&&(this.b2.velx+=p*this.b2.imass,this.b2.vely+=c*this.b2.imass,this.b2.angvel+=(c*this.r2x-p*this.r2y)*this.b2.iinertia),(!this.ws1.fluidEnabled||this.ws1.fluidProperties.viscosity==0)&&(!this.ws2.fluidEnabled||this.ws2.fluidProperties.viscosity==0))this.nodrag=!0,this.dampx=0,this.dampy=0,this.adamp=0;else{this.nodrag=!1;let u=0;if(this.ws1.fluidEnabled&&(this.ws2.validate_angDrag(),u+=this.ws1.fluidProperties.viscosity*this.ws2.angDrag*this.overlap/this.ws2.area),this.ws2.fluidEnabled&&(this.ws1.validate_angDrag(),u+=this.ws2.fluidProperties.viscosity*this.ws1.angDrag*this.overlap/this.ws1.area),u!=0){let _=this.b1.sinertia+this.b2.sinertia;_!=0?this.wMass=1/_:this.wMass=0,u*=4e-4;let d=2*Math.PI*u;this.agamma=1/(n*d*(2+d*n));let f=1/(1+this.agamma);this.agamma*=f,this.wMass*=f}else this.wMass=0,this.agamma=0;let h=this.b2.velx+this.b2.kinvelx-this.r2y*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.r1y*(this.b2.angvel+this.b2.kinangvel)),x=this.b2.vely+this.b2.kinvely+this.r2x*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.r1x*(this.b1.angvel+this.b1.kinangvel));if(!(h*h+x*x<l.Config.epsilon*l.Config.epsilon)){let _=h*h+x*x,d=1/Math.sqrt(_);this.nx=h*d,this.ny=x*d}let b=0;if(this.ws1.fluidEnabled){let _=-this.ws1.fluidProperties.viscosity*this.overlap/this.ws2.area;if(this.ws2.type==0)b-=_*this.ws2.circle.radius*l.Config.fluidLinearDrag/(2*this.ws2.circle.radius*Math.PI);else{let d=this.ws2.polygon,f=0,m=0,z=d.edges.head;for(;z!=null;){let Z=z.elt;f+=Z.length;let y=_*Z.length*(Z.gnormx*this.nx+Z.gnormy*this.ny);y>0&&(y*=-l.Config.fluidVacuumDrag),m-=y*.5*l.Config.fluidLinearDrag,z=z.next}b+=m/f}}if(this.ws2.fluidEnabled){let _=-this.ws2.fluidProperties.viscosity*this.overlap/this.ws1.area;if(this.ws1.type==0)b-=_*this.ws1.circle.radius*l.Config.fluidLinearDrag/(2*this.ws1.circle.radius*Math.PI);else{let d=this.ws1.polygon,f=0,m=0,z=d.edges.head;for(;z!=null;){let Z=z.elt;f+=Z.length;let y=_*Z.length*(Z.gnormx*this.nx+Z.gnormy*this.ny);y>0&&(y*=-l.Config.fluidVacuumDrag),m-=y*.5*l.Config.fluidLinearDrag,z=z.next}b+=m/f}}if(b!=0){let _=this.b1.smass+this.b2.smass,d=_,f=0,m=_;if(this.b1.sinertia!=0){let w=this.r1x*this.b1.sinertia,v=this.r1y*this.b1.sinertia;d+=v*this.r1y,f+=-v*this.r1x,m+=w*this.r1x}if(this.b2.sinertia!=0){let w=this.r2x*this.b2.sinertia,v=this.r2y*this.b2.sinertia;d+=v*this.r2y,f+=-v*this.r2x,m+=w*this.r2x}let z=d*m-f*f;if(z!==z)m=0,f=m,d=f;else if(z==0)d!=0?d=1/d:d=0,m!=0?m=1/m:m=0,f=0;else{let w=1/z,v=m*w;m=d*w,d=v,f*=-w}this.vMassa=d,this.vMassb=f,this.vMassc=m;let Z=2*Math.PI*b;this.lgamma=1/(n*Z*(2+Z*n));let y=1/(1+this.lgamma);this.lgamma*=y,this.vMassa*=y,this.vMassb*=y,this.vMassc*=y}else this.vMassa=0,this.vMassb=0,this.vMassc=0,this.lgamma=0}this.dampx*=s,this.dampy*=s,this.adamp*=s}warmStart(){this.b1.velx-=this.dampx*this.b1.imass,this.b1.vely-=this.dampy*this.b1.imass,this.b2.velx+=this.dampx*this.b2.imass,this.b2.vely+=this.dampy*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(this.dampy*this.r1x-this.dampx*this.r1y),this.b2.angvel+=this.b2.iinertia*(this.dampy*this.r2x-this.dampx*this.r2y),this.b1.angvel-=this.adamp*this.b1.iinertia,this.b2.angvel+=this.adamp*this.b2.iinertia}applyImpulseVel(){if(!this.nodrag){let t=this.b1.angvel+this.b1.kinangvel,n=this.b2.angvel+this.b2.kinangvel,l=this.b1.velx+this.b1.kinvelx-this.r1y*t-(this.b2.velx+this.b2.kinvelx-this.r2y*n),s=this.b1.vely+this.b1.kinvely+this.r1x*t-(this.b2.vely+this.b2.kinvely+this.r2x*n),i=this.vMassa*l+this.vMassb*s;s=this.vMassb*l+this.vMassc*s,l=i,l-=this.dampx*this.lgamma,s-=this.dampy*this.lgamma,this.dampx+=l,this.dampy+=s,this.b1.velx-=l*this.b1.imass,this.b1.vely-=s*this.b1.imass,this.b2.velx+=l*this.b2.imass,this.b2.vely+=s*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(s*this.r1x-l*this.r1y),this.b2.angvel+=this.b2.iinertia*(s*this.r2x-l*this.r2y);let o=(t-n)*this.wMass-this.adamp*this.agamma;this.adamp+=o,this.b1.angvel-=o*this.b1.iinertia,this.b2.angvel+=o*this.b2.iinertia}}};ls.__name__=["zpp_nape","dynamics","ZPP_FluidArbiter"],ls.__super__=Ve,ls.zpp_pool=null;var Mt=ls;var ui=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}};ui.__name__=["zpp_nape","dynamics","ZPP_IContact"];var dn=class dn{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 ui}wrapper(){return this.outer==null&&(dn._wrapFn?this.outer=dn._wrapFn(this):(dn.internal=!0,this.outer=new dn._nape.dynamics.Contact,dn.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=dn._zpp,t=dn._nape,n;if(e.util.ZPP_PubPool.poolVec2==null?n=new t.geom.Vec2:(n=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=0,l.y=0,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");l._isimmutable!=null&&l._isimmutable();let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),s=n.zpp_inner.y==0}else s=!1;if(!s){n.zpp_inner.x=0,n.zpp_inner.y=0;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.wrap_position=n,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!0,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this)}inactiveme(){return!(this.active&&this.arbiter!=null&&this.arbiter.active)}free(){this.arbiter=null}alloc(){}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){this.erase(t),l=!0;break}t=n,n=n.next}return l}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let l,s;t==null?(l=this.next,s=l.next,this.next=s,this.next==null&&(this.pushmod=!0)):(l=t.next,s=l.next,t.next=s,s==null&&(this.pushmod=!0)),l._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,l=!1;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,l=!0;break}t=n,n=n.next}return l}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};dn.__name__=["zpp_nape","dynamics","ZPP_Contact"],dn._nape=null,dn._zpp=null,dn.zpp_pool=null,dn.internal=!1,dn._wrapFn=null;var ve=dn;var _t=class _t extends Ve{constructor(){super();this.outer_zn=null;this.dyn_fric=0;this.stat_fric=0;this.restitution=0;this.rfric=0;this.userdef_dyn_fric=!1;this.userdef_stat_fric=!1;this.userdef_restitution=!1;this.userdef_rfric=!1;this.s1=null;this.s2=null;this.wrap_contacts=null;this.nx=0;this.ny=0;this.wrap_normal=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.Ka=0;this.Kb=0;this.Kc=0;this.rMass=0;this.jrAcc=0;this.rn1a=0;this.rt1a=0;this.rn1b=0;this.rt1b=0;this.rn2a=0;this.rt2a=0;this.rn2b=0;this.rt2b=0;this.k1x=0;this.k1y=0;this.k2x=0;this.k2y=0;this.surfacex=0;this.surfacey=0;this.ptype=null;this.lnormx=0;this.lnormy=0;this.lproj=0;this.radius=0;this.rev=!1;this.biasCoef=0;this.__ref_edge1=null;this.__ref_edge2=null;this.__ref_vertex=0;this.c1=null;this.oc1=null;this.c2=null;this.oc2=null;this.hc2=!1;this.hpc2=!1;this.stat=!1;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.stat=!1,this.next=null,this.hpc2=!1,this.hc2=!1,this.oc2=null,this.c2=null,this.oc1=null,this.c1=null,this.__ref_vertex=0,this.__ref_edge2=null,this.__ref_edge1=null,this.biasCoef=0,this.rev=!1,this.radius=0,this.lproj=0,this.lnormy=0,this.lnormx=0,this.surfacey=0,this.surfacex=0,this.k2y=0,this.k2x=0,this.k1y=0,this.k1x=0,this.rt2b=0,this.rn2b=0,this.rt2a=0,this.rn2a=0,this.rt1b=0,this.rn1b=0,this.rt1a=0,this.rn1a=0,this.jrAcc=0,this.rMass=0,this.Kc=0,this.Kb=0,this.Ka=0,this.kMassc=0,this.kMassb=0,this.kMassa=0,this.wrap_normal=null,this.ny=0,this.nx=0,this.innards=null,this.wrap_contacts=null,this.contacts=null,this.s2=null,this.s1=null,this.userdef_rfric=!1,this.userdef_restitution=!1,this.userdef_stat_fric=!1,this.userdef_dyn_fric=!1,this.rfric=0,this.restitution=0,this.stat_fric=0,this.dyn_fric=0,this.outer_zn=null,this.pre_dt=-1,this.contacts=new ve,this.innards=new ui,this.type=Ve.COL,this.colarb=this}alloc(){}free(){this.userdef_dyn_fric=!1,this.userdef_stat_fric=!1,this.userdef_restitution=!1,this.userdef_rfric=!1,this.__ref_edge1=this.__ref_edge2=null}normal_validate(){if(this.cleared)throw new Error("Error: Arbiter not currently in use");this.wrap_normal.zpp_inner.x=this.nx,this.wrap_normal.zpp_inner.y=this.ny,this.ws1.id>this.ws2.id&&(this.wrap_normal.zpp_inner.x=-this.wrap_normal.zpp_inner.x,this.wrap_normal.zpp_inner.y=-this.wrap_normal.zpp_inner.y)}getnormal(){let t=Ve._zpp,n=Ve._nape,l=0,s=0,i;if(t.util.ZPP_PubPool.poolVec2==null?i=new n.geom.Vec2:(i=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let o;t.geom.ZPP_Vec2.zpp_pool==null?o=new t.geom.ZPP_Vec2:(o=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=l,o.y=s,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),l!==l||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let r;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=i.zpp_inner;if(a._validate!=null&&a._validate(),i.zpp_inner.x==l){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate(),r=i.zpp_inner.y==s}else r=!1;if(!r){i.zpp_inner.x=l,i.zpp_inner.y=s;let p=i.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}i.zpp_inner.weak=!1,this.wrap_normal=i,this.wrap_normal.zpp_inner._immutable=!0,this.wrap_normal.zpp_inner._inuse=!0,this.wrap_normal.zpp_inner._validate=this.normal_validate.bind(this)}injectContact(t,n,l,s,i,o,r=!1){let a=null,p=this.contacts.next;for(;p!=null;){if(o==p.hash){a=p;break}p=p.next}if(a==null){ve.zpp_pool==null?a=new ve:(a=ve.zpp_pool,ve.zpp_pool=a.next,a.next=null);let c=a.inner;c.jnAcc=c.jtAcc=0,a.hash=o,a.fresh=!0,a.arbiter=this,this.jrAcc=0,a._inuse=!0,a.next=this.contacts.next,this.contacts.next=a,this.contacts.modified=!0,this.contacts.length++,this.innards.add(c)}else a.fresh=!1;return a.px=t,a.py=n,this.nx=l,this.ny=s,a.dist=i,a.stamp=this.stamp,a.posOnly=r,a}assign(t,n,l,s){this.sup_assign(t,n,l,s),this.s1=t,this.s2=n,this._calcFrictionRestitution()}calcProperties(){this._calcFrictionRestitution()}validate_props(){this.invalidated&&(this.invalidated=!1,this._calcFrictionRestitution())}_calcFrictionRestitution(){this.userdef_restitution||(this.s1.material.elasticity<=-1/0||this.s2.material.elasticity<=-1/0?this.restitution=0:this.s1.material.elasticity>=1/0||this.s2.material.elasticity>=1/0?this.restitution=1:this.restitution=(this.s1.material.elasticity+this.s2.material.elasticity)/2,this.restitution<0&&(this.restitution=0),this.restitution>1&&(this.restitution=1)),this.userdef_dyn_fric||(this.dyn_fric=Math.sqrt(this.s1.material.dynamicFriction*this.s2.material.dynamicFriction)),this.userdef_stat_fric||(this.stat_fric=Math.sqrt(this.s1.material.staticFriction*this.s2.material.staticFriction)),this.userdef_rfric||(this.rfric=Math.sqrt(this.s1.material.rollingFriction*this.s2.material.rollingFriction))}retire(){for(this.sup_retire();this.contacts.next!=null;){let t=this.contacts.next;this.contacts.pop(),t.arbiter=null,t.next=ve.zpp_pool,ve.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=_t.zpp_pool,_t.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=ve.zpp_pool,ve.zpp_pool=i;break}n=i,l=s,s=s.next,i=i.next}}setupcontacts(){let t=Ve._zpp;this.wrap_contacts=t.util.ZPP_ContactList.get(this.contacts,!0),this.wrap_contacts.zpp_inner.immutable=!this.mutable,this.wrap_contacts.zpp_inner.adder=this.contacts_adder.bind(this),this.wrap_contacts.zpp_inner.dontremove=!0,this.wrap_contacts.zpp_inner.subber=this.contacts_subber.bind(this)}cleanupContacts(){let t=Ve._nape,n=!0,l=null,s=null,i=this.innards.next;this.hc2=!1;let o=this.contacts.next;for(;o!=null;){let r=o;if(r.stamp+t.Config.arbiterExpirationDelay<this.stamp){o=_t._eraseFromList(this.contacts,l),i=_t._eraseFromList(this.innards,s),r.arbiter=null,r.next=ve.zpp_pool,ve.zpp_pool=r;continue}let a=r.inner,p=r.active;r.active=r.stamp==this.stamp,r.active&&(n?(n=!1,this.c1=a,this.oc1=r):(this.hc2=!0,this.c2=a,this.oc2=r)),p!=r.active&&(this.contacts.modified=!0),l=o,s=i,i=i.next,o=o.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let r=this.c1;this.c1=this.c2,this.c2=r,r=this.oc1,this.oc1=this.oc2,this.oc2=r,this.hc2=!1}else this.oc2.posOnly&&(this.hc2=!1);this.oc1.posOnly&&(n=!0)}else this.hpc2=!1;return n}preStep(t){let n=Ve._nape;this.validate_props(),this.pre_dt==-1&&(this.pre_dt=t);let l=t/this.pre_dt;this.pre_dt=t;let s=this.b1.smass+this.b2.smass;this.hc2=!1;let i=!0,r=this.b1.type!=2||this.b2.type!=2?this.continuous?n.Config.contactContinuousStaticBiasCoef:n.Config.contactStaticBiasCoef:this.continuous?n.Config.contactContinuousBiasCoef:n.Config.contactBiasCoef;this.biasCoef=r,this.continuous=!1;let a=null,p=null,c=this.innards.next,u=this.contacts.next;for(;u!=null;){let h=u;if(h.stamp+n.Config.arbiterExpirationDelay<this.stamp){u=_t._eraseFromList(this.contacts,a),c=_t._eraseFromList(this.innards,p),h.arbiter=null,h.next=ve.zpp_pool,ve.zpp_pool=h;continue}let x=h.inner,b=h.active;if(h.active=h.stamp==this.stamp,h.active){i?(i=!1,this.c1=x,this.oc1=h):(this.hc2=!0,this.c2=x,this.oc2=h),x.r2x=h.px-this.b2.posx,x.r2y=h.py-this.b2.posy,x.r1x=h.px-this.b1.posx,x.r1y=h.py-this.b1.posy;let _=x.r2x*this.nx+x.r2y*this.ny,d=s+this.b2.sinertia*(_*_);_=x.r1x*this.nx+x.r1y*this.ny,d+=this.b1.sinertia*(_*_),x.tMass=d<n.Config.epsilon*n.Config.epsilon?0:1/d,_=this.ny*x.r2x-this.nx*x.r2y;let f=s+this.b2.sinertia*(_*_);_=this.ny*x.r1x-this.nx*x.r1y,f+=this.b1.sinertia*(_*_),x.nMass=f<n.Config.epsilon*n.Config.epsilon?0:1/f;let m=this.b2.angvel+this.b2.kinangvel,z=this.b2.velx+this.b2.kinvelx-x.r2y*m,Z=this.b2.vely+this.b2.kinvely+x.r2x*m;m=this.b1.angvel+this.b1.kinangvel,z-=this.b1.velx+this.b1.kinvelx-x.r1y*m,Z-=this.b1.vely+this.b1.kinvely+x.r1x*m;let y=this.nx*z+this.ny*Z;h.elasticity=this.restitution,x.bounce=y*h.elasticity,x.bounce>-n.Config.elasticThreshold&&(x.bounce=0);let w=Z*this.nx-z*this.ny,v=n.Config.staticFrictionThreshold;w*w>v*v?x.friction=this.dyn_fric:x.friction=this.stat_fric,x.jnAcc*=l,x.jtAcc*=l}b!=h.active&&(this.contacts.modified=!0),a=u,p=c,c=c.next,u=u.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let h=this.c1;this.c1=this.c2,this.c2=h,h=this.oc1,this.oc1=this.oc2,this.oc2=h,this.hc2=!1}else this.oc2.posOnly&&(this.hc2=!1);this.oc1.posOnly&&(i=!0)}else this.hpc2=!1;if(this.jrAcc*=l,i||(this.rn1a=this.ny*this.c1.r1x-this.nx*this.c1.r1y,this.rt1a=this.c1.r1x*this.nx+this.c1.r1y*this.ny,this.rn1b=this.ny*this.c1.r2x-this.nx*this.c1.r2y,this.rt1b=this.c1.r2x*this.nx+this.c1.r2y*this.ny,this.k1x=this.b2.kinvelx-this.c1.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c1.r1y*this.b1.kinangvel),this.k1y=this.b2.kinvely+this.c1.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c1.r1x*this.b1.kinangvel)),this.hc2)if(this.rn2a=this.ny*this.c2.r1x-this.nx*this.c2.r1y,this.rt2a=this.c2.r1x*this.nx+this.c2.r1y*this.ny,this.rn2b=this.ny*this.c2.r2x-this.nx*this.c2.r2y,this.rt2b=this.c2.r2x*this.nx+this.c2.r2y*this.ny,this.k2x=this.b2.kinvelx-this.c2.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c2.r1y*this.b1.kinangvel),this.k2y=this.b2.kinvely+this.c2.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c2.r1x*this.b1.kinangvel),this.kMassa=s+this.b1.sinertia*this.rn1a*this.rn1a+this.b2.sinertia*this.rn1b*this.rn1b,this.kMassb=s+this.b1.sinertia*this.rn1a*this.rn2a+this.b2.sinertia*this.rn1b*this.rn2b,this.kMassc=s+this.b1.sinertia*this.rn2a*this.rn2a+this.b2.sinertia*this.rn2b*this.rn2b,this.kMassa*this.kMassa+2*this.kMassb*this.kMassb+this.kMassc*this.kMassc<n.Config.illConditionedThreshold*(this.kMassa*this.kMassc-this.kMassb*this.kMassb)){this.Ka=this.kMassa,this.Kb=this.kMassb,this.Kc=this.kMassc;let x=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(x!==x)this.kMassa=this.kMassb=this.kMassc=0;else if(x==0)this.kMassa!=0?this.kMassa=1/this.kMassa:this.kMassa=0,this.kMassc!=0?this.kMassc=1/this.kMassc:this.kMassc=0,this.kMassb=0;else{let b=1/x,_=this.kMassc*b;this.kMassc=this.kMassa*b,this.kMassa=_,this.kMassb*=-b}}else{if(this.hc2=!1,this.oc2.dist<this.oc1.dist){let x=this.c1;this.c1=this.c2,this.c2=x}this.oc2.active=!1,this.contacts.modified=!0}return this.surfacex=this.b2.svelx,this.surfacey=this.b2.svely,this.surfacex+=this.b1.svelx,this.surfacey+=this.b1.svely,this.surfacex=-this.surfacex,this.surfacey=-this.surfacey,this.rMass=this.b1.sinertia+this.b2.sinertia,this.rMass!=0&&(this.rMass=1/this.rMass),i}warmStart(){let t=this.nx*this.c1.jnAcc-this.ny*this.c1.jtAcc,n=this.ny*this.c1.jnAcc+this.nx*this.c1.jtAcc;this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c1.r1x-t*this.c1.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c1.r2x-t*this.c1.r2y),this.hc2&&(t=this.nx*this.c2.jnAcc-this.ny*this.c2.jtAcc,n=this.ny*this.c2.jnAcc+this.nx*this.c2.jtAcc,this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c2.r1x-t*this.c2.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c2.r2x-t*this.c2.r2y)),this.b2.angvel+=this.jrAcc*this.b2.iinertia,this.b1.angvel-=this.jrAcc*this.b1.iinertia}applyImpulseVel(){let t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),l=(n*this.nx-t*this.ny+this.surfacex)*this.c1.tMass,s=this.c1.friction*this.c1.jnAcc,i=this.c1.jtAcc,o=i-l;o>s?o=s:o<-s&&(o=-s),l=o-i,this.c1.jtAcc=o;let r=-this.ny*l,a=this.nx*l;if(this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rt1b*l*this.b2.iinertia,this.b1.angvel-=this.rt1a*l*this.b1.iinertia,this.hc2){let p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);l=(c*this.nx-p*this.ny+this.surfacex)*this.c2.tMass,s=this.c2.friction*this.c2.jnAcc,i=this.c2.jtAcc,o=i-l,o>s?o=s:o<-s&&(o=-s),l=o-i,this.c2.jtAcc=o,r=-this.ny*l,a=this.nx*l,this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rt2b*l*this.b2.iinertia,this.b1.angvel-=this.rt2a*l*this.b1.iinertia,t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);let u=this.c1.jnAcc,h=this.c2.jnAcc,x=t*this.nx+n*this.ny+this.surfacey+this.c1.bounce-(this.Ka*u+this.Kb*h),b=p*this.nx+c*this.ny+this.surfacey+this.c2.bounce-(this.Kb*u+this.Kc*h),_=-(this.kMassa*x+this.kMassb*b),d=-(this.kMassb*x+this.kMassc*b);_>=0&&d>=0?(x=_-u,b=d-h,this.c1.jnAcc=_,this.c2.jnAcc=d):(_=-this.c1.nMass*x,_>=0&&this.Kb*_+b>=0?(x=_-u,b=-h,this.c1.jnAcc=_,this.c2.jnAcc=0):(d=-this.c2.nMass*b,d>=0&&this.Kb*d+x>=0?(x=-u,b=d-h,this.c1.jnAcc=0,this.c2.jnAcc=d):x>=0&&b>=0?(x=-u,b=-h,this.c1.jnAcc=this.c2.jnAcc=0):(x=0,b=0))),l=x+b,r=this.nx*l,a=this.ny*l,this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=(this.rn1b*x+this.rn2b*b)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*x+this.rn2a*b)*this.b1.iinertia}else this.radius!=0&&(l=(this.b2.angvel-this.b1.angvel)*this.rMass,s=this.rfric*this.c1.jnAcc,i=this.jrAcc,this.jrAcc-=l,this.jrAcc>s?this.jrAcc=s:this.jrAcc<-s&&(this.jrAcc=-s),l=this.jrAcc-i,this.b2.angvel+=l*this.b2.iinertia,this.b1.angvel-=l*this.b1.iinertia),t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),l=(this.c1.bounce+(this.nx*t+this.ny*n)+this.surfacey)*this.c1.nMass,i=this.c1.jnAcc,o=i-l,o<0&&(o=0),l=o-i,this.c1.jnAcc=o,r=this.nx*l,a=this.ny*l,this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rn1b*l*this.b2.iinertia,this.b1.angvel-=this.rn1a*l*this.b1.iinertia}applyImpulsePos(){let t=Ve._nape;this.ptype==2?this._applyImpulsePosCircle(t):this._applyImpulsePosEdge(t)}_applyImpulsePosCircle(t){let n=this.c1,l=this.b2.axisy*n.lr2x-this.b2.axisx*n.lr2y,s=n.lr2x*this.b2.axisx+n.lr2y*this.b2.axisy;l+=this.b2.posx,s+=this.b2.posy;let i=this.b1.axisy*n.lr1x-this.b1.axisx*n.lr1y,o=n.lr1x*this.b1.axisx+n.lr1y*this.b1.axisy;i+=this.b1.posx,o+=this.b1.posy;let r=l-i,a=s-o,p=Math.sqrt(r*r+a*a),c=this.radius-t.Config.collisionSlop,u=p-c;if(r*this.nx+a*this.ny<0&&(r=-r,a=-a,u-=this.radius),u<0)if(p<t.Config.epsilon)this.b1.smass!=0?this.b1.posx+=t.Config.epsilon*10:this.b2.posx+=t.Config.epsilon*10;else{let h=1/p;r*=h,a*=h;let x=.5*(i+l),b=.5*(o+s),_=p-c;i=x-this.b1.posx,o=b-this.b1.posy,l=x-this.b2.posx,s=b-this.b2.posy;let d=a*i-r*o,f=a*l-r*s,m=this.b2.smass+f*f*this.b2.sinertia+this.b1.smass+d*d*this.b1.sinertia;if(m!=0){let z=-this.biasCoef*_/m,Z=r*z,y=a*z;this.b1.posx-=Z*this.b1.imass,this.b1.posy-=y*this.b1.imass,_t._rotateBody(this.b1,-d*this.b1.iinertia*z),this.b2.posx+=Z*this.b2.imass,this.b2.posy+=y*this.b2.imass,_t._rotateBody(this.b2,f*this.b2.iinertia*z)}}}_applyImpulsePosEdge(t){let n,l,s,i,o,r=0,a=0;this.ptype==0?(n=this.b1.axisy*this.lnormx-this.b1.axisx*this.lnormy,l=this.lnormx*this.b1.axisx+this.lnormy*this.b1.axisy,s=this.lproj+(n*this.b1.posx+l*this.b1.posy),i=this.b2.axisy*this.c1.lr1x-this.b2.axisx*this.c1.lr1y,o=this.c1.lr1x*this.b2.axisx+this.c1.lr1y*this.b2.axisy,i+=this.b2.posx,o+=this.b2.posy,this.hpc2&&(r=this.b2.axisy*this.c2.lr1x-this.b2.axisx*this.c2.lr1y,a=this.c2.lr1x*this.b2.axisx+this.c2.lr1y*this.b2.axisy,r+=this.b2.posx,a+=this.b2.posy)):(n=this.b2.axisy*this.lnormx-this.b2.axisx*this.lnormy,l=this.lnormx*this.b2.axisx+this.lnormy*this.b2.axisy,s=this.lproj+(n*this.b2.posx+l*this.b2.posy),i=this.b1.axisy*this.c1.lr1x-this.b1.axisx*this.c1.lr1y,o=this.c1.lr1x*this.b1.axisx+this.c1.lr1y*this.b1.axisy,i+=this.b1.posx,o+=this.b1.posy,this.hpc2&&(r=this.b1.axisy*this.c2.lr1x-this.b1.axisx*this.c2.lr1y,a=this.c2.lr1x*this.b1.axisx+this.c2.lr1y*this.b1.axisy,r+=this.b1.posx,a+=this.b1.posy));let p=i*n+o*l-s-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=r*n+a*l-s-this.radius,c+=t.Config.collisionSlop),p<0||c<0){this.rev&&(n=-n,l=-l);let u=i-this.b1.posx,h=o-this.b1.posy,x=i-this.b2.posx,b=o-this.b2.posy;if(this.hpc2){let _=r-this.b1.posx,d=a-this.b1.posy,f=r-this.b2.posx,m=a-this.b2.posy,z=l*u-n*h,Z=l*x-n*b,y=l*_-n*d,w=l*f-n*m,v=this.b1.smass+this.b2.smass;this.kMassa=v+this.b1.sinertia*z*z+this.b2.sinertia*Z*Z,this.kMassb=v+this.b1.sinertia*z*y+this.b2.sinertia*Z*w,this.kMassc=v+this.b1.sinertia*y*y+this.b2.sinertia*w*w;let P=this.kMassa,g=this.kMassb,k=this.kMassc,N=p*this.biasCoef,E=c*this.biasCoef;for(;;){let M=-N,C=-E,L=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(L!==L)M=0,C=0;else if(L==0)this.kMassa!=0?M/=this.kMassa:M=0,this.kMassc!=0?C/=this.kMassc:C=0;else{let O=1/L,I=O*(this.kMassc*M-this.kMassb*C);C=O*(this.kMassa*C-this.kMassb*M),M=I}if(M>=0&&C>=0){_t._applyPosImpulse2(this.b1,this.b2,n,l,M,C,z,y,Z,w);break}if(M=-N/P,C=0,M>=0&&g*M+E>=0){_t._applyPosImpulse2(this.b1,this.b2,n,l,M,C,z,y,Z,w);break}if(M=0,C=-E/k,C>=0&&g*C+N>=0){_t._applyPosImpulse2(this.b1,this.b2,n,l,M,C,z,y,Z,w);break}break}}else{let _=l*u-n*h,d=l*x-n*b,f=this.b2.smass+d*d*this.b2.sinertia+this.b1.smass+_*_*this.b1.sinertia;if(f!=0){let m=-this.biasCoef*p/f,z=n*m,Z=l*m;this.b1.posx-=z*this.b1.imass,this.b1.posy-=Z*this.b1.imass,_t._rotateBody(this.b1,-_*this.b1.iinertia*m),this.b2.posx+=z*this.b2.imass,this.b2.posy+=Z*this.b2.imass,_t._rotateBody(this.b2,d*this.b2.iinertia*m)}}}}static _eraseFromList(t,n){let l,s;return n==null?(l=t.next,s=l.next,t.next=s,t.next==null&&(t.pushmod=!0)):(l=n.next,s=l.next,n.next=s,s==null&&(t.pushmod=!0)),l._inuse=!1,t.modified=!0,t.length--,t.pushmod=!0,s}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let l=n*n,s=1-.5*l,i=1-l*l/8,o=(s*t.axisx+n*t.axisy)*i;t.axisy=(s*t.axisy-n*t.axisx)*i,t.axisx=o}}static _applyPosImpulse2(t,n,l,s,i,o,r,a,p,c){let u=(i+o)*t.imass;t.posx-=l*u,t.posy-=s*u,_t._rotateBody(t,-t.iinertia*(r*i+a*o));let h=(i+o)*n.imass;n.posx+=l*h,n.posy+=s*h,_t._rotateBody(n,n.iinertia*(p*i+c*o))}};_t.__name__=["zpp_nape","dynamics","ZPP_ColArbiter"],_t.__super__=Ve,_t.FACE1=0,_t.FACE2=1,_t.CIRCLE=2,_t.zpp_pool=null;var dt=_t;var Jt=class Jt{constructor(){this.collisionGroup=1;this.collisionMask=-1;this.sensorGroup=1;this.sensorMask=-1;this.fluidGroup=1;this.fluidMask=-1;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new Jt._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Jt._wrapFn)this.outer=Jt._wrapFn(this);else{this.outer=new Jt._nape.dynamics.InteractionFilter;let e=this.outer.zpp_inner;e.outer=null,e.next=Jt.zpp_pool,Jt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Jt._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Jt.zpp_pool==null?e=new Jt:(e=Jt.zpp_pool,Jt.zpp_pool=e.next,e.next=null),e.collisionGroup=this.collisionGroup,e.collisionMask=this.collisionMask,e.sensorGroup=this.sensorGroup,e.sensorMask=this.sensorMask,e.fluidGroup=this.fluidGroup,e.fluidMask=this.fluidMask,e}shouldCollide(e){return(this.collisionMask&e.collisionGroup)!==0&&(e.collisionMask&this.collisionGroup)!==0}shouldSense(e){return(this.sensorMask&e.sensorGroup)!==0&&(e.sensorMask&this.sensorGroup)!==0}shouldFlow(e){return(this.fluidMask&e.fluidGroup)!==0&&(e.fluidMask&this.fluidGroup)!==0}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_filter(),e=e.next}};Jt.zpp_pool=null,Jt.__name__=["zpp_nape","dynamics","ZPP_InteractionFilter"],Jt._nape=null,Jt._zpp=null,Jt._wrapFn=null;var yt=Jt;var Ci=class Ci{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=Ci._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)}};Ci.SHAPE=1,Ci.BODY=2,Ci.__name__=["zpp_nape","dynamics","ZPP_InteractionGroup"],Ci._zpp=null,Ci._wrapFn=null;var Ks=Ci;var qn=class{constructor(){this.zpp_inner=null;this.space=null;this._length=0;this.zip_length=!1;this.lengths=[];this.ite_0=null;this.ite_1=null;this.ite_2=null;this.ite_3=null;this.at_index_0=0;this.at_index_1=0;this.at_index_2=0;this.at_index_3=0;this.at_index_0=0,this.at_index_1=0,this.at_index_2=0,this.at_index_3=0,this.zip_length=!0,this._length=0,this.lengths=[],this.lengths.push(0),this.lengths.push(0),this.lengths.push(0),this.lengths.push(0)}zpp_gl(){if(this.zpp_vm(),this.zip_length){this._length=0;let e=0,t=0,n=this.space.c_arbiters_true.head;for(;n!=null;)n.elt.active&&++t,n=n.next;this.lengths[e++]=t,this._length+=t;let l=0,s=this.space.c_arbiters_false.head;for(;s!=null;)s.elt.active&&++l,s=s.next;this.lengths[e++]=l,this._length+=l;let i=0,o=this.space.f_arbiters.head;for(;o!=null;)o.elt.active&&++i,o=o.next;this.lengths[e++]=i,this._length+=i;let r=0,a=this.space.s_arbiters.head;for(;a!=null;)a.elt.active&&++r,a=a.next;this.lengths[e++]=r,this._length+=r,this.zip_length=!1}return this._length}zpp_vm(){let e=!1;this.space.c_arbiters_true.modified&&(e=!0,this.space.c_arbiters_true.modified=!1),this.space.c_arbiters_false.modified&&(e=!0,this.space.c_arbiters_false.modified=!1),this.space.f_arbiters.modified&&(e=!0,this.space.f_arbiters.modified=!1),this.space.s_arbiters.modified&&(e=!0,this.space.s_arbiters.modified=!1),e&&(this.zip_length=!0,this._length=0,this.ite_0=null,this.ite_1=null,this.ite_2=null,this.ite_3=null)}push(e){throw new Error("Error: ArbiterList is immutable")}pop(){throw new Error("Error: ArbiterList is immutable")}unshift(e){throw new Error("Error: ArbiterList is immutable")}shift(){throw new Error("Error: ArbiterList is immutable")}remove(e){throw new Error("Error: ArbiterList is immutable")}clear(){throw new Error("Error: ArbiterList is immutable")}at(e){if(this.zpp_vm(),e<0||e>=this.zpp_gl())throw new Error("Error: Index out of bounds");let t=null,n=0;if(t==null)if(e<n+this.lengths[0]){let l=e-n;if(l<this.at_index_0||this.ite_0==null)for(this.at_index_0=0,this.ite_0=this.space.c_arbiters_true.head;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;for(;this.at_index_0!=l;)for(this.at_index_0++,this.ite_0=this.ite_0.next;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;t=this.ite_0.elt.wrapper()}else n+=this.lengths[0];if(t==null)if(e<n+this.lengths[1]){let l=e-n;if(l<this.at_index_1||this.ite_1==null)for(this.at_index_1=0,this.ite_1=this.space.c_arbiters_false.head;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;for(;this.at_index_1!=l;)for(this.at_index_1++,this.ite_1=this.ite_1.next;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;t=this.ite_1.elt.wrapper()}else n+=this.lengths[1];if(t==null)if(e<n+this.lengths[2]){let l=e-n;if(l<this.at_index_2||this.ite_2==null)for(this.at_index_2=0,this.ite_2=this.space.f_arbiters.head;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;for(;this.at_index_2!=l;)for(this.at_index_2++,this.ite_2=this.ite_2.next;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;t=this.ite_2.elt.wrapper()}else n+=this.lengths[2];if(t==null)if(e<n+this.lengths[3]){let l=e-n;if(l<this.at_index_3||this.ite_3==null)for(this.at_index_3=0,this.ite_3=this.space.s_arbiters.head;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;for(;this.at_index_3!=l;)for(this.at_index_3++,this.ite_3=this.ite_3.next;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;t=this.ite_3.elt.wrapper()}else n+=this.lengths[3];return t}};qn.__name__=["zpp_nape","dynamics","ZPP_SpaceArbiterList"],qn._nape=null,qn._zpp=null;var Zt=class Zt{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 Zt.zpp_pool==null?s=new Zt:(s=Zt.zpp_pool,Zt.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(Zt._wrapFn)this.outer=Zt._wrapFn(this);else{this.outer=new Zt._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=Zt.zpp_pool,Zt.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 Zt.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=Zt._zpp,l=Zt._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=Zt._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=Zt._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)+" }"}};Zt.zpp_pool=null,Zt.__name__=["zpp_nape","geom","ZPP_AABB"],Zt._nape=null,Zt._zpp=null,Zt._wrapFn=null;var be=Zt;var Ce=class Ce{static _initStatics(e){Ce.flowpoly=new e.util.ZNPList_ZPP_Vec2,Ce.flowsegs=new e.util.ZNPList_ZPP_Vec2}static circleContains(e,t){let n=t.x-e.worldCOMx,l=t.y-e.worldCOMy;return n*n+l*l<e.radius*e.radius}static polyContains(e,t){let n;n=!0;let l=e.edges.head;for(;l!=null;){let s=l.elt;if(s.gnormx*t.x+s.gnormy*t.y<=s.gprojection){l=l.next;continue}else{n=!1;break}}return n}static shapeContains(e,t){return e.type==0?Ce.circleContains(e.circle,t):Ce.polyContains(e.polygon,t)}static bodyContains(e,t){let n;n=!1;let l=e.shapes.head;for(;l!=null;){let s=l.elt;if(Ce.shapeContains(s,t)){n=!0;break}l=l.next}return n}static containTest(e,t){let n=e.aabb,l=t.aabb;if(l.minx>=n.minx&&l.miny>=n.miny&&l.maxx<=n.maxx&&l.maxy<=n.maxy)if(e.type==0)if(t.type==0){let s=e.circle.radius+-t.circle.radius,i=t.circle.worldCOMx-e.circle.worldCOMx,o=t.circle.worldCOMy-e.circle.worldCOMy;return i*i+o*o<=s*s}else{let s;s=!0;let i=t.polygon.gverts.next;for(;i!=null;){let o=i,r=e.circle.radius,a=o.x-e.circle.worldCOMx,p=o.y-e.circle.worldCOMy;if(a*a+p*p<=r*r){i=i.next;continue}else{s=!1;break}}return s}else if(t.type==0){let s;s=!0;let i=e.polygon.edges.head;for(;i!=null;){let o=i.elt;if(o.gnormx*t.circle.worldCOMx+o.gnormy*t.circle.worldCOMy+t.circle.radius<=o.gprojection){i=i.next;continue}else{s=!1;break}}return s}else{let s;s=!0;let i=e.polygon.edges.head;for(;i!=null;){let o=i.elt,r=-1e100,a=t.polygon.gverts.next;for(;a!=null;){let p=a,c=o.gnormx*p.x+o.gnormy*p.y;c>r&&(r=c),a=a.next}if(r<=o.gprojection){i=i.next;continue}else{s=!1;break}}return s}else return!1}static contactCollide(e,t,n,l){let s=ye();if(t.type==1)if(e.type==1){let i=!0,o=-1e100,r=-1e100,a=-1,p=null,c=null,u=e.polygon.edges.head;for(;u!=null;){let h=u.elt,x=1e100,b=t.polygon.gverts.next;for(;b!=null;){let _=b,d=h.gnormx*_.x+h.gnormy*_.y;if(d<x&&(x=d),x-h.gprojection<=o)break;b=b.next}if(x-=h.gprojection,x>=0){i=!1;break}x>o&&(o=x,p=h,a=1),u=u.next}if(i){let h=t.polygon.edges.head;for(;h!=null;){let x=h.elt,b=1e100,_=e.polygon.gverts.next;for(;_!=null;){let d=_,f=x.gnormx*d.x+x.gnormy*d.y;if(f<b&&(b=f),b-x.gprojection<=o)break;_=_.next}if(b-=x.gprojection,b>=0){i=!1;break}b>o&&(o=b,c=x,a=2),h=h.next}if(i){let x,b,_,d;a==1?(x=e.polygon,b=t.polygon,_=p,d=1):(x=t.polygon,b=e.polygon,_=c,d=-1);let f=null,m=1e100,z=b.edges.head;for(;z!=null;){let R=z.elt,G=_.gnormx*R.gnormx+_.gnormy*R.gnormy;G<m&&(m=G,f=R),z=z.next}let Z=f.gp0.x,y=f.gp0.y,w=f.gp1.x,v=f.gp1.y,P=w-Z,g=v-y,k=_.gnormy*Z-_.gnormx*y,N=_.gnormy*w-_.gnormx*v,E=1/(N-k),M=(-_.tp1-k)*E;if(M>s.Config.epsilon){let R=M;Z+=P*R,y+=g*R}let C=(-_.tp0-N)*E;if(C<-s.Config.epsilon){let R=C;w+=P*R,v+=g*R}let L=d,O=_.gnormx*L,I=_.gnormy*L;n.lnormx=_.lnormx,n.lnormy=_.lnormy,n.lproj=_.lprojection,n.radius=0,n.rev=l!=(d==-1),n.ptype=n.rev?1:0;let T=Z*_.gnormx+y*_.gnormy-_.gprojection,W=w*_.gnormx+v*_.gnormy-_.gprojection;if(T>0&&W>0)return!1;{l&&(O=-O,I=-I);let R=Z-_.gnormx*T*.5,G=y-_.gnormy*T*.5,j=n.rev?1:0,S=T>0;S==null&&(S=!1);let q=null,$=n.contacts.next;for(;$!=null;){let K=$;if(j==K.hash){q=K;break}$=$.next}if(q==null){ve.zpp_pool==null?q=new ve:(q=ve.zpp_pool,ve.zpp_pool=q.next,q.next=null);let K=q.inner;K.jnAcc=K.jtAcc=0,q.hash=j,q.fresh=!0,q.arbiter=n,n.jrAcc=0;let ne=n.contacts;q._inuse=!0;let re=q;re.next=ne.next,ne.next=re,ne.modified=!0,ne.length++,n.innards.add(K)}else q.fresh=!1;q.px=R,q.py=G,n.nx=O,n.ny=I,q.dist=T,q.stamp=n.stamp,q.posOnly=S;let X=q,H=1;Z-=b.body.posx*H,y-=b.body.posy*H,X.inner.lr1x=Z*b.body.axisy+y*b.body.axisx,X.inner.lr1y=y*b.body.axisy-Z*b.body.axisx;let ee=w-_.gnormx*W*.5,F=v-_.gnormy*W*.5,D=n.rev?0:1,B=W>0;B==null&&(B=!1);let V=null,J=n.contacts.next;for(;J!=null;){let K=J;if(D==K.hash){V=K;break}J=J.next}if(V==null){ve.zpp_pool==null?V=new ve:(V=ve.zpp_pool,ve.zpp_pool=V.next,V.next=null);let K=V.inner;K.jnAcc=K.jtAcc=0,V.hash=D,V.fresh=!0,V.arbiter=n,n.jrAcc=0;let ne=n.contacts;V._inuse=!0;let re=V;re.next=ne.next,ne.next=re,ne.modified=!0,ne.length++,n.innards.add(K)}else V.fresh=!1;V.px=ee,V.py=F,n.nx=O,n.ny=I,V.dist=W,V.stamp=n.stamp,V.posOnly=B,X=V;let Q=1;return w-=b.body.posx*Q,v-=b.body.posy*Q,X.inner.lr1x=w*b.body.axisy+v*b.body.axisx,X.inner.lr1y=v*b.body.axisy-w*b.body.axisx,a==1?(n.__ref_edge1=_,n.__ref_edge2=f):(n.__ref_edge2=_,n.__ref_edge1=f),!0}}else return!1}else return!1}else{let i=-1e100,o=-1e100,r=!0,a=null,p=null,c=t.polygon.gverts.next,u=t.polygon.edges.head;for(;u!=null;){let h=u.elt,x=h.gnormx*e.circle.worldCOMx+h.gnormy*e.circle.worldCOMy-h.gprojection-e.circle.radius;if(x>0){r=!1;break}x>i&&(i=x,a=h,p=c),c=c.next,u=u.next}if(r){let h=p,x=p.next==null?t.polygon.gverts.next:p.next,b=e.circle.worldCOMy*a.gnormx-e.circle.worldCOMx*a.gnormy;if(b<=h.y*a.gnormx-h.x*a.gnormy){let _=e.circle.radius,d=h.x-e.circle.worldCOMx,f=h.y-e.circle.worldCOMy,m=d*d+f*f,z;if(m>_*_)z=null;else if(m<s.Config.epsilon*s.Config.epsilon){let Z=e.circle.worldCOMx,y=e.circle.worldCOMy,w=null,v=n.contacts.next;for(;v!=null;){let P=v;if(P.hash==0){w=P;break}v=v.next}if(w==null){ve.zpp_pool==null?w=new ve:(w=ve.zpp_pool,ve.zpp_pool=w.next,w.next=null);let P=w.inner;P.jnAcc=P.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let k=w;k.next=g.next,g.next=k,g.modified=!0,g.length++,n.innards.add(P)}else w.fresh=!1;w.px=Z,w.py=y,n.nx=1,n.ny=0,w.dist=-_,w.stamp=n.stamp,w.posOnly=!1,z=w}else{let Z=1/Math.sqrt(m),y=Z<s.Config.epsilon?1e100:1/Z,w=.5+(e.circle.radius-.5*_)*Z;if(l){let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+f*w,g=null,k=n.contacts.next;for(;k!=null;){let N=k;if(N.hash==0){g=N;break}k=k.next}if(g==null){ve.zpp_pool==null?g=new ve:(g=ve.zpp_pool,ve.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let E=n.contacts;g._inuse=!0;let M=g;M.next=E.next,E.next=M,E.modified=!0,E.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=-d*Z,n.ny=-f*Z,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}else{let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+f*w,g=null,k=n.contacts.next;for(;k!=null;){let N=k;if(N.hash==0){g=N;break}k=k.next}if(g==null){ve.zpp_pool==null?g=new ve:(g=ve.zpp_pool,ve.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let E=n.contacts;g._inuse=!0;let M=g;M.next=E.next,E.next=M,E.modified=!0,E.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=d*Z,n.ny=f*Z,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}}if(z!=null){let Z=z.inner;n.ptype=2;let y=h.x-t.polygon.body.posx,w=h.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=-1,l?(Z.lr1x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,Z.lr1y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,Z.lr2x=e.circle.localCOMx,Z.lr2y=e.circle.localCOMy):(Z.lr2x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,Z.lr2y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,Z.lr1x=e.circle.localCOMx,Z.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return z!=null}else if(b>=x.y*a.gnormx-x.x*a.gnormy){let _=e.circle.radius,d=x.x-e.circle.worldCOMx,f=x.y-e.circle.worldCOMy,m=d*d+f*f,z;if(m>_*_)z=null;else if(m<s.Config.epsilon*s.Config.epsilon){let Z=e.circle.worldCOMx,y=e.circle.worldCOMy,w=null,v=n.contacts.next;for(;v!=null;){let P=v;if(P.hash==0){w=P;break}v=v.next}if(w==null){ve.zpp_pool==null?w=new ve:(w=ve.zpp_pool,ve.zpp_pool=w.next,w.next=null);let P=w.inner;P.jnAcc=P.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let k=w;k.next=g.next,g.next=k,g.modified=!0,g.length++,n.innards.add(P)}else w.fresh=!1;w.px=Z,w.py=y,n.nx=1,n.ny=0,w.dist=-_,w.stamp=n.stamp,w.posOnly=!1,z=w}else{let Z=1/Math.sqrt(m),y=Z<s.Config.epsilon?1e100:1/Z,w=.5+(e.circle.radius-.5*_)*Z;if(l){let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+f*w,g=null,k=n.contacts.next;for(;k!=null;){let N=k;if(N.hash==0){g=N;break}k=k.next}if(g==null){ve.zpp_pool==null?g=new ve:(g=ve.zpp_pool,ve.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let E=n.contacts;g._inuse=!0;let M=g;M.next=E.next,E.next=M,E.modified=!0,E.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=-d*Z,n.ny=-f*Z,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}else{let v=e.circle.worldCOMx+d*w,P=e.circle.worldCOMy+f*w,g=null,k=n.contacts.next;for(;k!=null;){let N=k;if(N.hash==0){g=N;break}k=k.next}if(g==null){ve.zpp_pool==null?g=new ve:(g=ve.zpp_pool,ve.zpp_pool=g.next,g.next=null);let N=g.inner;N.jnAcc=N.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let E=n.contacts;g._inuse=!0;let M=g;M.next=E.next,E.next=M,E.modified=!0,E.length++,n.innards.add(N)}else g.fresh=!1;g.px=v,g.py=P,n.nx=d*Z,n.ny=f*Z,g.dist=y-_,g.stamp=n.stamp,g.posOnly=!1,z=g}}if(z!=null){let Z=z.inner;n.ptype=2;let y=x.x-t.polygon.body.posx,w=x.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=1,l?(Z.lr1x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,Z.lr1y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,Z.lr2x=e.circle.localCOMx,Z.lr2y=e.circle.localCOMy):(Z.lr2x=y*t.polygon.body.axisy+w*t.polygon.body.axisx,Z.lr2y=w*t.polygon.body.axisy-y*t.polygon.body.axisx,Z.lr1x=e.circle.localCOMx,Z.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return z!=null}else{let _=e.circle.radius+i*.5,d=a.gnormx*_,f=a.gnormy*_,m=e.circle.worldCOMx-d,z=e.circle.worldCOMy-f,Z;if(l){let y=a.gnormx,w=a.gnormy,v=null,P=n.contacts.next;for(;P!=null;){let g=P;if(g.hash==0){v=g;break}P=P.next}if(v==null){ve.zpp_pool==null?v=new ve:(v=ve.zpp_pool,ve.zpp_pool=v.next,v.next=null);let g=v.inner;g.jnAcc=g.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let k=n.contacts;v._inuse=!0;let N=v;N.next=k.next,k.next=N,k.modified=!0,k.length++,n.innards.add(g)}else v.fresh=!1;v.px=m,v.py=z,n.nx=y,n.ny=w,v.dist=i,v.stamp=n.stamp,v.posOnly=!1,Z=v}else{let y=-a.gnormx,w=-a.gnormy,v=null,P=n.contacts.next;for(;P!=null;){let g=P;if(g.hash==0){v=g;break}P=P.next}if(v==null){ve.zpp_pool==null?v=new ve:(v=ve.zpp_pool,ve.zpp_pool=v.next,v.next=null);let g=v.inner;g.jnAcc=g.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let k=n.contacts;v._inuse=!0;let N=v;N.next=k.next,k.next=N,k.modified=!0,k.length++,n.innards.add(g)}else v.fresh=!1;v.px=m,v.py=z,n.nx=y,n.ny=w,v.dist=i,v.stamp=n.stamp,v.posOnly=!1,Z=v}return n.ptype=l?0:1,n.lnormx=a.lnormx,n.lnormy=a.lnormy,n.rev=!l,n.lproj=a.lprojection,n.radius=e.circle.radius,Z.inner.lr1x=e.circle.localCOMx,Z.inner.lr1y=e.circle.localCOMy,n.__ref_edge1=a,n.__ref_vertex=0,!0}}else return!1}else{let i=e.circle.radius+t.circle.radius,o=t.circle.worldCOMx-e.circle.worldCOMx,r=t.circle.worldCOMy-e.circle.worldCOMy,a=o*o+r*r,p;if(a>i*i)p=null;else if(a<s.Config.epsilon*s.Config.epsilon){let c=e.circle.worldCOMx,u=e.circle.worldCOMy,h=null,x=n.contacts.next;for(;x!=null;){let b=x;if(b.hash==0){h=b;break}x=x.next}if(h==null){ve.zpp_pool==null?h=new ve:(h=ve.zpp_pool,ve.zpp_pool=h.next,h.next=null);let b=h.inner;b.jnAcc=b.jtAcc=0,h.hash=0,h.fresh=!0,h.arbiter=n,n.jrAcc=0;let _=n.contacts;h._inuse=!0;let d=h;d.next=_.next,_.next=d,_.modified=!0,_.length++,n.innards.add(b)}else h.fresh=!1;h.px=c,h.py=u,n.nx=1,n.ny=0,h.dist=-i,h.stamp=n.stamp,h.posOnly=!1,p=h}else{let c=1/Math.sqrt(a),u=c<s.Config.epsilon?1e100:1/c,h=.5+(e.circle.radius-.5*i)*c;if(l){let x=e.circle.worldCOMx+o*h,b=e.circle.worldCOMy+r*h,_=null,d=n.contacts.next;for(;d!=null;){let f=d;if(f.hash==0){_=f;break}d=d.next}if(_==null){ve.zpp_pool==null?_=new ve:(_=ve.zpp_pool,ve.zpp_pool=_.next,_.next=null);let f=_.inner;f.jnAcc=f.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let m=n.contacts;_._inuse=!0;let z=_;z.next=m.next,m.next=z,m.modified=!0,m.length++,n.innards.add(f)}else _.fresh=!1;_.px=x,_.py=b,n.nx=-o*c,n.ny=-r*c,_.dist=u-i,_.stamp=n.stamp,_.posOnly=!1,p=_}else{let x=e.circle.worldCOMx+o*h,b=e.circle.worldCOMy+r*h,_=null,d=n.contacts.next;for(;d!=null;){let f=d;if(f.hash==0){_=f;break}d=d.next}if(_==null){ve.zpp_pool==null?_=new ve:(_=ve.zpp_pool,ve.zpp_pool=_.next,_.next=null);let f=_.inner;f.jnAcc=f.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let m=n.contacts;_._inuse=!0;let z=_;z.next=m.next,m.next=z,m.modified=!0,m.length++,n.innards.add(f)}else _.fresh=!1;_.px=x,_.py=b,n.nx=o*c,n.ny=r*c,_.dist=u-i,_.stamp=n.stamp,_.posOnly=!1,p=_}}if(p!=null){let c=p.inner;return l?(c.lr1x=t.circle.localCOMx,c.lr1y=t.circle.localCOMy,c.lr2x=e.circle.localCOMx,c.lr2y=e.circle.localCOMy):(c.lr1x=e.circle.localCOMx,c.lr1y=e.circle.localCOMy,c.lr2x=t.circle.localCOMx,c.lr2y=t.circle.localCOMy),n.radius=e.circle.radius+t.circle.radius,n.ptype=2,!0}else return!1}}static testCollide_safe(e,t){let n=ye();if(t.type==0){let l=e;e=t,t=l}return Ce.testCollide(e,t)}static testCollide(e,t){let n=ye();if(t.type==1)if(e.type==1){let l=!0,s=e.polygon.edges.head;for(;s!=null;){let i=s.elt,o=1e100,r=t.polygon.gverts.next;for(;r!=null;){let a=r,p=i.gnormx*a.x+i.gnormy*a.y;p<o&&(o=p),r=r.next}if(o-=i.gprojection,o>0){l=!1;break}s=s.next}if(l){let i=t.polygon.edges.head;for(;i!=null;){let o=i.elt,r=1e100,a=e.polygon.gverts.next;for(;a!=null;){let p=a,c=o.gnormx*p.x+o.gnormy*p.y;c<r&&(r=c),a=a.next}if(r-=o.gprojection,r>0){l=!1;break}i=i.next}return l}else return!1}else{let l=null,s=null,i=!0,o=-1e100,r=t.polygon.gverts.next,a=t.polygon.edges.head;for(;a!=null;){let p=a.elt,c=p.gnormx*e.circle.worldCOMx+p.gnormy*e.circle.worldCOMy-p.gprojection-e.circle.radius;if(c>0){i=!1;break}c>o&&(o=c,l=p,s=r),r=r.next,a=a.next}if(i){let p=s,c=s.next==null?t.polygon.gverts.next:s.next,u=e.circle.worldCOMy*l.gnormx-e.circle.worldCOMx*l.gnormy;if(u<=p.y*l.gnormx-p.x*l.gnormy){let h=e.circle.radius,x=p.x-e.circle.worldCOMx,b=p.y-e.circle.worldCOMy;return x*x+b*b<=h*h}else if(u>=c.y*l.gnormx-c.x*l.gnormy){let h=e.circle.radius,x=c.x-e.circle.worldCOMx,b=c.y-e.circle.worldCOMy;return x*x+b*b<=h*h}else return!0}else return!1}else{let l=e.circle.radius+t.circle.radius,s=t.circle.worldCOMx-e.circle.worldCOMx,i=t.circle.worldCOMy-e.circle.worldCOMy;return s*s+i*i<=l*l}}static flowCollide(e,t,n){let l=ye();if(t.type==1)if(e.type==1){let s=[],i=[],o=!0,r=!0,a=e.polygon.edges.head;for(;a!=null;){let p=a.elt,c=1e100,u=0,h=t.polygon.gverts.next;for(;h!=null;){let x=h,b=p.gnormx*x.x+p.gnormy*x.y;b<c&&(c=b),b>=p.gprojection+l.Config.epsilon&&(i[u]=!0,r=!1),++u,h=h.next}if(c-=p.gprojection,c>0){o=!1;break}a=a.next}if(r){let p=t.polygon;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=!1,p.zip_localCOM){if(p.zip_localCOM=!1,p.type==1){let u=p.polygon;if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(u.lverts.next.next==null)u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;else if(u.lverts.next.next.next==null){u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;let h=1;u.localCOMx+=u.lverts.next.next.x*h,u.localCOMy+=u.lverts.next.next.y*h;let x=.5;u.localCOMx*=x,u.localCOMy*=x}else{u.localCOMx=0,u.localCOMy=0;let h=0,x=u.lverts.next,b=x;x=x.next;let _=x;for(x=x.next;x!=null;){let y=x;h+=_.x*(y.y-b.y);let w=y.y*_.x-y.x*_.y;u.localCOMx+=(_.x+y.x)*w,u.localCOMy+=(_.y+y.y)*w,b=_,_=y,x=x.next}x=u.lverts.next;let d=x;h+=_.x*(d.y-b.y);let f=d.y*_.x-d.x*_.y;u.localCOMx+=(_.x+d.x)*f,u.localCOMy+=(_.y+d.y)*f,b=_,_=d,x=x.next;let m=x;h+=_.x*(m.y-b.y);let z=m.y*_.x-m.x*_.y;u.localCOMx+=(_.x+m.x)*z,u.localCOMy+=(_.y+m.y)*z,h=1/(3*h);let Z=h;u.localCOMx*=Z,u.localCOMy*=Z}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let c=p.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else if(o){r=!0;let p=t.polygon.edges.head;for(;p!=null;){let c=p.elt,u=1e100,h=0,x=e.polygon.gverts.next;for(;x!=null;){let b=x,_=c.gnormx*b.x+c.gnormy*b.y;_<u&&(u=_),_>=c.gprojection+l.Config.epsilon&&(s[h]=!0,r=!1),++h,x=x.next}if(u-=c.gprojection,u>0){o=!1;break}p=p.next}if(r){let c=e.polygon;if(c.zip_worldCOM&&c.body!=null){if(c.zip_worldCOM=!1,c.zip_localCOM){if(c.zip_localCOM=!1,c.type==1){let h=c.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let x=1;h.localCOMx+=h.lverts.next.next.x*x,h.localCOMy+=h.lverts.next.next.y*x;let b=.5;h.localCOMx*=b,h.localCOMy*=b}else{h.localCOMx=0,h.localCOMy=0;let x=0,b=h.lverts.next,_=b;b=b.next;let d=b;for(b=b.next;b!=null;){let w=b;x+=d.x*(w.y-_.y);let v=w.y*d.x-w.x*d.y;h.localCOMx+=(d.x+w.x)*v,h.localCOMy+=(d.y+w.y)*v,_=d,d=w,b=b.next}b=h.lverts.next;let f=b;x+=d.x*(f.y-_.y);let m=f.y*d.x-f.x*d.y;h.localCOMx+=(d.x+f.x)*m,h.localCOMy+=(d.y+f.y)*m,_=d,d=f,b=b.next;let z=b;x+=d.x*(z.y-_.y);let Z=z.y*d.x-z.x*d.y;h.localCOMx+=(d.x+z.x)*Z,h.localCOMy+=(d.y+z.y)*Z,x=1/(3*x);let y=x;h.localCOMx*=y,h.localCOMy*=y}}c.wrap_localCOM!=null&&(c.wrap_localCOM.zpp_inner.x=c.localCOMx,c.wrap_localCOM.zpp_inner.y=c.localCOMy)}let u=c.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),c.worldCOMx=c.body.posx+(c.body.axisy*c.localCOMx-c.body.axisx*c.localCOMy),c.worldCOMy=c.body.posy+(c.localCOMx*c.body.axisx+c.localCOMy*c.body.axisy)}return n.overlap=e.polygon.area,n.centroidx=e.polygon.worldCOMx,n.centroidy=e.polygon.worldCOMy,!0}else if(o){for(;Ce.flowpoly.head!=null;){let z=Ce.flowpoly.pop_unsafe();if(!z._inuse){let Z=z;Z.outer!=null&&(Z.outer.zpp_inner=null,Z.outer=null),Z._isimmutable=null,Z._validate=null,Z._invalidate=null,Z.next=le.zpp_pool,le.zpp_pool=Z}}let c=null,u=!1,h=e.polygon.gverts.next,x=0,b=t.polygon.gverts.next,_=0,d=0,f=t.polygon.edgeCnt;for(;d<f;){let z=d++;if(i[z])b=b.next;else{_=z;break}}if(b==null){b=t.polygon.gverts.next,u=!0;let z=0,Z=e.polygon.edgeCnt;for(;z<Z;){let y=z++;if(s[y])h=h.next;else{x=y;break}}h==null?h=e.polygon.gverts.next:(Ce.flowpoly.add(h),c=Ce.flowpoly.head.elt)}else Ce.flowpoly.add(b),c=Ce.flowpoly.head.elt;let m=1;if(Ce.flowpoly.head==null){let z=!0,Z=e.polygon.gverts.next,y=Z,w=Z.next;for(;w!=null;){let v=w,P=2,g=!0,k=t.polygon.gverts.next,N=k,E=k.next;for(;E!=null;){let M=E,C=0,L=y.x-N.x,O=y.y-N.y,I=v.x-y.x,T=v.y-y.y,W=M.x-N.x,R=M.y-N.y,G=T*W-I*R,j;if(G*G>l.Config.epsilon*l.Config.epsilon){G=1/G;let S=(R*L-W*O)*G;if(S>l.Config.epsilon&&S<1-l.Config.epsilon){let q=(T*L-I*O)*G;q>l.Config.epsilon&&q<1-l.Config.epsilon?(C=S,j=!0):j=!1}else j=!1}else j=!1;j&&C<P&&(P=C,b=k),k=E,N=M,E=E.next}if(g)for(;;){E=t.polygon.gverts.next;let M=E,C=0,L=y.x-N.x,O=y.y-N.y,I=v.x-y.x,T=v.y-y.y,W=M.x-N.x,R=M.y-N.y,G=T*W-I*R,j;if(G*G>l.Config.epsilon*l.Config.epsilon){G=1/G;let S=(R*L-W*O)*G;if(S>l.Config.epsilon&&S<1-l.Config.epsilon){let q=(T*L-I*O)*G;q>l.Config.epsilon&&q<1-l.Config.epsilon?(C=S,j=!0):j=!1}else j=!1}else j=!1;j&&C<P&&(P=C,b=k);break}if(P!=2){let M=P,C=y.x+(v.x-y.x)*M,L=y.y+(v.y-y.y)*M,O;le.zpp_pool==null?O=new le:(O=le.zpp_pool,le.zpp_pool=O.next,O.next=null),O.weak=!1,O._immutable=!1,O.x=C,O.y=L,c=O,Ce.flowpoly.add(c),u=!0,h=Z,z=!1;break}Z=w,y=v,w=w.next}if(z)for(;;){w=e.polygon.gverts.next;let v=w,P=2,g=!0,k=t.polygon.gverts.next,N=k,E=k.next;for(;E!=null;){let M=E,C=0,L=y.x-N.x,O=y.y-N.y,I=v.x-y.x,T=v.y-y.y,W=M.x-N.x,R=M.y-N.y,G=T*W-I*R,j;if(G*G>l.Config.epsilon*l.Config.epsilon){G=1/G;let S=(R*L-W*O)*G;if(S>l.Config.epsilon&&S<1-l.Config.epsilon){let q=(T*L-I*O)*G;q>l.Config.epsilon&&q<1-l.Config.epsilon?(C=S,j=!0):j=!1}else j=!1}else j=!1;j&&C<P&&(P=C,b=k),k=E,N=M,E=E.next}if(g)for(;;){E=t.polygon.gverts.next;let M=E,C=0,L=y.x-N.x,O=y.y-N.y,I=v.x-y.x,T=v.y-y.y,W=M.x-N.x,R=M.y-N.y,G=T*W-I*R,j;if(G*G>l.Config.epsilon*l.Config.epsilon){G=1/G;let S=(R*L-W*O)*G;if(S>l.Config.epsilon&&S<1-l.Config.epsilon){let q=(T*L-I*O)*G;q>l.Config.epsilon&&q<1-l.Config.epsilon?(C=S,j=!0):j=!1}else j=!1}else j=!1;j&&C<P&&(P=C,b=k);break}if(P!=2){let M=P,C=y.x+(v.x-y.x)*M,L=y.y+(v.y-y.y)*M,O;le.zpp_pool==null?O=new le:(O=le.zpp_pool,le.zpp_pool=O.next,O.next=null),O.weak=!1,O._immutable=!1,O.x=C,O.y=L,c=O,Ce.flowpoly.add(c),u=!0,h=Z;break}break}m=2}for(;;)if(u)if(h=h.next,++x,h==null&&(h=e.polygon.gverts.next,x=0),s[x]){let z=Ce.flowpoly.head.elt,Z=h,y=b,w=b.next;w==null&&(w=t.polygon.gverts.next);let v=-1,P=null,g=0,k=0,N=w,E=w;for(;;){let j=E,S=0,q=y.x-z.x,$=y.y-z.y,X=j.x-y.x,H=j.y-y.y,ee=Z.x-z.x,F=Z.y-z.y,D=H*ee-X*F,B;if(D*D>l.Config.epsilon*l.Config.epsilon){D=1/D;let V=(F*q-ee*$)*D;if(V>l.Config.epsilon&&V<1-l.Config.epsilon){let J=(H*q-X*$)*D;J>l.Config.epsilon&&J<1-l.Config.epsilon?(S=V,B=!0):B=!1}else B=!1}else B=!1;if(B&&S>=v)if(P=b,g=_,++k==m){v=S,E=N;break}else v=S;y=j,b=E,++_,_>=t.polygon.edgeCnt&&(_=0),E=E.next,E==null&&(E=t.polygon.gverts.next);break}for(;E!=N;){let j=E,S=0,q=y.x-z.x,$=y.y-z.y,X=j.x-y.x,H=j.y-y.y,ee=Z.x-z.x,F=Z.y-z.y,D=H*ee-X*F,B;if(D*D>l.Config.epsilon*l.Config.epsilon){D=1/D;let V=(F*q-ee*$)*D;if(V>l.Config.epsilon&&V<1-l.Config.epsilon){let J=(H*q-X*$)*D;J>l.Config.epsilon&&J<1-l.Config.epsilon?(S=V,B=!0):B=!1}else B=!1}else B=!1;if(B&&S>=v)if(P=b,g=_,++k==m){v=S;break}else v=S;y=j,b=E,++_,_>=t.polygon.edgeCnt&&(_=0),E=E.next,E==null&&(E=t.polygon.gverts.next)}if(P==null)break;let M=P,C=P.next;C==null&&(C=t.polygon.gverts.next);let L=C,O=v,I=M.x+(L.x-M.x)*O,T=M.y+(L.y-M.y)*O,W;if(c!=null){let j=I-c.x,S=T-c.y;W=j*j+S*S<l.Config.epsilon}else W=!1;if(W)break;let R=Ce.flowpoly,G;le.zpp_pool==null?G=new le:(G=le.zpp_pool,le.zpp_pool=G.next,G.next=null),G.weak=!1,G._immutable=!1,G.x=I,G.y=T,R.add(G),c==null&&(c=Ce.flowpoly.head.elt),b=P,_=g,u=!u,m=2}else{let z=h,Z;if(c!=null){let y=z.x-c.x,w=z.y-c.y;Z=y*y+w*w<l.Config.epsilon}else Z=!1;if(Z)break;Ce.flowpoly.add(z),c==null&&(c=Ce.flowpoly.head.elt),m=1}else if(b=b.next,++_,b==null&&(b=t.polygon.gverts.next,_=0),i[_]){let z=Ce.flowpoly.head.elt,Z=b,y=h,w=h.next;w==null&&(w=e.polygon.gverts.next);let v=-1,P=null,g=0,k=0,N=w,E=w;for(;;){let j=E,S=0,q=y.x-z.x,$=y.y-z.y,X=j.x-y.x,H=j.y-y.y,ee=Z.x-z.x,F=Z.y-z.y,D=H*ee-X*F,B;if(D*D>l.Config.epsilon*l.Config.epsilon){D=1/D;let V=(F*q-ee*$)*D;if(V>l.Config.epsilon&&V<1-l.Config.epsilon){let J=(H*q-X*$)*D;J>l.Config.epsilon&&J<1-l.Config.epsilon?(S=V,B=!0):B=!1}else B=!1}else B=!1;if(B&&S>=v)if(P=h,g=x,++k==m){v=S,E=N;break}else v=S;y=j,h=E,++x,x>=e.polygon.edgeCnt&&(x=0),E=E.next,E==null&&(E=e.polygon.gverts.next);break}for(;E!=N;){let j=E,S=0,q=y.x-z.x,$=y.y-z.y,X=j.x-y.x,H=j.y-y.y,ee=Z.x-z.x,F=Z.y-z.y,D=H*ee-X*F,B;if(D*D>l.Config.epsilon*l.Config.epsilon){D=1/D;let V=(F*q-ee*$)*D;if(V>l.Config.epsilon&&V<1-l.Config.epsilon){let J=(H*q-X*$)*D;J>l.Config.epsilon&&J<1-l.Config.epsilon?(S=V,B=!0):B=!1}else B=!1}else B=!1;if(B&&S>=v)if(P=h,g=x,++k==m){v=S;break}else v=S;y=j,h=E,++x,x>=e.polygon.edgeCnt&&(x=0),E=E.next,E==null&&(E=e.polygon.gverts.next)}if(P==null)break;let M=P,C=P.next;C==null&&(C=e.polygon.gverts.next);let L=C,O=v,I=M.x+(L.x-M.x)*O,T=M.y+(L.y-M.y)*O,W;if(c!=null){let j=I-c.x,S=T-c.y;W=j*j+S*S<l.Config.epsilon}else W=!1;if(W)break;let R=Ce.flowpoly,G;le.zpp_pool==null?G=new le:(G=le.zpp_pool,le.zpp_pool=G.next,G.next=null),G.weak=!1,G._immutable=!1,G.x=I,G.y=T,R.add(G),c==null&&(c=Ce.flowpoly.head.elt),h=P,x=g,u=!u,m=2}else{let z=b,Z;if(c!=null){let y=z.x-c.x,w=z.y-c.y;Z=y*y+w*w<l.Config.epsilon}else Z=!1;if(Z)break;Ce.flowpoly.add(z),c==null&&(c=Ce.flowpoly.head.elt),m=1}if(Ce.flowpoly.head!=null&&Ce.flowpoly.head.next!=null&&Ce.flowpoly.head.next.next!=null){let z=0,Z=0,y=0,w=Ce.flowpoly.head,v=w.elt;w=w.next;let P=w.elt;for(w=w.next;w!=null;){let L=w.elt;z+=P.x*(L.y-v.y);let O=L.y*P.x-L.x*P.y;Z+=(P.x+L.x)*O,y+=(P.y+L.y)*O,v=P,P=L,w=w.next}w=Ce.flowpoly.head;let g=w.elt;z+=P.x*(g.y-v.y);let k=g.y*P.x-g.x*P.y;Z+=(P.x+g.x)*k,y+=(P.y+g.y)*k,v=P,P=g,w=w.next;let N=w.elt;z+=P.x*(N.y-v.y);let E=N.y*P.x-N.x*P.y;Z+=(P.x+N.x)*E,y+=(P.y+N.y)*E,z*=.5;let C=1/(6*z);return Z*=C,y*=C,n.overlap=-z,n.centroidx=Z,n.centroidy=y,!0}else return!1}else return!1}else return!1}else{let s=[],i=!0,o=null,r=null,a=-1e100,p=!0,c=t.polygon.gverts.next,u=0,h=t.polygon.edges.head;for(;h!=null;){let x=h.elt,b=x.gnormx*e.circle.worldCOMx+x.gnormy*e.circle.worldCOMy;if(b>x.gprojection+e.circle.radius){p=!1;break}else b+e.circle.radius>x.gprojection+l.Config.epsilon&&(i=!1,s[u]=!0);b-=x.gprojection+e.circle.radius,b>a&&(a=b,o=x,r=c),c=c.next,++u,h=h.next}if(p){if(i)return n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0;{let x=r,b=r.next==null?t.polygon.gverts.next:r.next,_=e.circle.worldCOMy*o.gnormx-e.circle.worldCOMx*o.gnormy,d;if(_<=x.y*o.gnormx-x.x*o.gnormy){let f=e.circle.radius,m=x.x-e.circle.worldCOMx,z=x.y-e.circle.worldCOMy;d=m*m+z*z<=f*f}else if(_>=b.y*o.gnormx-b.x*o.gnormy){let f=e.circle.radius,m=b.x-e.circle.worldCOMx,z=b.y-e.circle.worldCOMy;d=m*m+z*z<=f*f}else d=!0;if(d){let f=[],m=0,z=!0,Z=null,y=0,w=t.polygon.gverts.next;for(;w!=null;){let v=w,P=v.x-e.circle.worldCOMx,g=v.y-e.circle.worldCOMy,k=P*P+g*g;(f[m]=k<=e.circle.radius*e.circle.radius)?(y=m,Z=w):z=!1,++m,w=w.next}if(z){let v=t.polygon;if(v.zip_worldCOM&&v.body!=null){if(v.zip_worldCOM=!1,v.zip_localCOM){if(v.zip_localCOM=!1,v.type==1){let g=v.polygon;if(g.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(g.lverts.next.next==null)g.localCOMx=g.lverts.next.x,g.localCOMy=g.lverts.next.y;else if(g.lverts.next.next.next==null){g.localCOMx=g.lverts.next.x,g.localCOMy=g.lverts.next.y;let k=1;g.localCOMx+=g.lverts.next.next.x*k,g.localCOMy+=g.lverts.next.next.y*k;let N=.5;g.localCOMx*=N,g.localCOMy*=N}else{g.localCOMx=0,g.localCOMy=0;let k=0,N=g.lverts.next,E=N;N=N.next;let M=N;for(N=N.next;N!=null;){let W=N;k+=M.x*(W.y-E.y);let R=W.y*M.x-W.x*M.y;g.localCOMx+=(M.x+W.x)*R,g.localCOMy+=(M.y+W.y)*R,E=M,M=W,N=N.next}N=g.lverts.next;let C=N;k+=M.x*(C.y-E.y);let L=C.y*M.x-C.x*M.y;g.localCOMx+=(M.x+C.x)*L,g.localCOMy+=(M.y+C.y)*L,E=M,M=C,N=N.next;let O=N;k+=M.x*(O.y-E.y);let I=O.y*M.x-O.x*M.y;g.localCOMx+=(M.x+O.x)*I,g.localCOMy+=(M.y+O.y)*I,k=1/(3*k);let T=k;g.localCOMx*=T,g.localCOMy*=T}}v.wrap_localCOM!=null&&(v.wrap_localCOM.zpp_inner.x=v.localCOMx,v.wrap_localCOM.zpp_inner.y=v.localCOMy)}let P=v.body;P.zip_axis&&(P.zip_axis=!1,P.axisx=Math.sin(P.rot),P.axisy=Math.cos(P.rot)),v.worldCOMx=v.body.posx+(v.body.axisy*v.localCOMx-v.body.axisx*v.localCOMy),v.worldCOMy=v.body.posy+(v.localCOMx*v.body.axisx+v.localCOMy*v.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else{for(;Ce.flowpoly.head!=null;){let g=Ce.flowpoly.pop_unsafe();if(!g._inuse){let k=g;k.outer!=null&&(k.outer.zpp_inner=null,k.outer=null),k._isimmutable=null,k._validate=null,k._invalidate=null,k.next=le.zpp_pool,le.zpp_pool=k}}Ce.flowsegs.clear();let v=null,P=1;for(Z==null?(Z=t.polygon.gverts.next,P=2):(v=Z,Ce.flowpoly.add(v));P!=0;)if(P==1)if(Z=Z.next,Z==null&&(Z=t.polygon.gverts.next),++y,y>=t.polygon.edgeCnt&&(y=0),f[y]){let g=v.x-Z.x,k=v.y-Z.y;if(g*g+k*k<l.Config.epsilon)break;Ce.flowpoly.add(Z)}else{let g=Ce.flowpoly.head.elt,k=Z,N=k.x-g.x,E=k.y-g.y,M=g.x-e.circle.worldCOMx,C=g.y-e.circle.worldCOMy,L=N*N+E*E,O=2*(M*N+C*E),I=M*M+C*C-e.circle.radius*e.circle.radius,T=Math.sqrt(O*O-4*L*I);L=1/(2*L);let W=(-O-T)*L,R=W<l.Config.epsilon?(-O+T)*L:W,G=0,j=0,S=R;G=g.x+(k.x-g.x)*S,j=g.y+(k.y-g.y)*S;let q=v.x-G,$=v.y-j;if(q*q+$*$<l.Config.epsilon)break;let X=Ce.flowpoly,H;le.zpp_pool==null?H=new le:(H=le.zpp_pool,le.zpp_pool=H.next,H.next=null),H.weak=!1,H._immutable=!1,H.x=G,H.y=j,X.add(H),P=2}else if(P==2){let g=Z.next;g==null&&(g=t.polygon.gverts.next);let k=Z;P=0;let N=g,E=g;for(;;){let M=E,C=y+1;if(C==t.polygon.edgeCnt&&(C=0),s[y])if(f[C]){let L=M.x-k.x,O=M.y-k.y,I=k.x-e.circle.worldCOMx,T=k.y-e.circle.worldCOMy,W=L*L+O*O,R=2*(I*L+T*O),G=I*I+T*T-e.circle.radius*e.circle.radius,j=Math.sqrt(R*R-4*W*G);W=1/(2*W);let S=(-R-j)*W,q=S<l.Config.epsilon?(-R+j)*W:S,$=0,X=0,H=q;$=k.x+(M.x-k.x)*H,X=k.y+(M.y-k.y)*H;let ee=v.x-$,F=v.y-X;if(ee*ee+F*F<l.Config.epsilon){P=0,E=N;break}let D;le.zpp_pool==null?D=new le:(D=le.zpp_pool,le.zpp_pool=D.next,D.next=null),D.weak=!1,D._immutable=!1,D.x=$,D.y=X;let B=D;Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(B),Ce.flowpoly.add(B),P=1,E=N;break}else{let L=0,O=0,I=M.x-k.x,T=M.y-k.y,W=k.x-e.circle.worldCOMx,R=k.y-e.circle.worldCOMy,G=I*I+T*T,j=2*(W*I+R*T),S=W*W+R*R-e.circle.radius*e.circle.radius,q=j*j-4*G*S,$;if(q*q<l.Config.epsilon?(q<0?L=10:(O=-j/(2*G),L=O),$=!1):(q=Math.sqrt(q),G=1/(2*G),L=(-j-q)*G,O=(-j+q)*G,$=!0),L<1-l.Config.epsilon&&O>l.Config.epsilon){let X=0,H=0,ee=L;X=k.x+(M.x-k.x)*ee,H=k.y+(M.y-k.y)*ee;let F;if(v!=null){let V=v.x-X,J=v.y-H;F=V*V+J*J<l.Config.epsilon}else F=!1;if(F){P=0,E=N;break}let D;le.zpp_pool==null?D=new le:(D=le.zpp_pool,le.zpp_pool=D.next,D.next=null),D.weak=!1,D._immutable=!1,D.x=X,D.y=H;let B=D;if(Ce.flowpoly.head!=null&&(Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(B)),Ce.flowpoly.add(B),v==null&&(v=Ce.flowpoly.head.elt),$){let V=0,J=0,Q=O;V=k.x+(M.x-k.x)*Q,J=k.y+(M.y-k.y)*Q;let K=Ce.flowpoly,ne;le.zpp_pool==null?ne=new le:(ne=le.zpp_pool,le.zpp_pool=ne.next,ne.next=null),ne.weak=!1,ne._immutable=!1,ne.x=V,ne.y=J,K.add(ne)}}}k=M,Z=E,y=C,E=E.next,E==null&&(E=t.polygon.gverts.next);break}for(;E!=N;){let M=E,C=y+1;if(C==t.polygon.edgeCnt&&(C=0),s[y])if(f[C]){let L=M.x-k.x,O=M.y-k.y,I=k.x-e.circle.worldCOMx,T=k.y-e.circle.worldCOMy,W=L*L+O*O,R=2*(I*L+T*O),G=I*I+T*T-e.circle.radius*e.circle.radius,j=Math.sqrt(R*R-4*W*G);W=1/(2*W);let S=(-R-j)*W,q=S<l.Config.epsilon?(-R+j)*W:S,$=0,X=0,H=q;$=k.x+(M.x-k.x)*H,X=k.y+(M.y-k.y)*H;let ee=v.x-$,F=v.y-X;if(ee*ee+F*F<l.Config.epsilon){P=0,E=N;break}let D;le.zpp_pool==null?D=new le:(D=le.zpp_pool,le.zpp_pool=D.next,D.next=null),D.weak=!1,D._immutable=!1,D.x=$,D.y=X;let B=D;Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(B),Ce.flowpoly.add(B),P=1,E=N;break}else{let L=0,O=0,I=M.x-k.x,T=M.y-k.y,W=k.x-e.circle.worldCOMx,R=k.y-e.circle.worldCOMy,G=I*I+T*T,j=2*(W*I+R*T),S=W*W+R*R-e.circle.radius*e.circle.radius,q=j*j-4*G*S,$;if(q*q<l.Config.epsilon?(q<0?L=10:(O=-j/(2*G),L=O),$=!1):(q=Math.sqrt(q),G=1/(2*G),L=(-j-q)*G,O=(-j+q)*G,$=!0),L<1-l.Config.epsilon&&O>l.Config.epsilon){let X=0,H=0,ee=L;X=k.x+(M.x-k.x)*ee,H=k.y+(M.y-k.y)*ee;let F;if(v!=null){let V=v.x-X,J=v.y-H;F=V*V+J*J<l.Config.epsilon}else F=!1;if(F){P=0,E=N;break}let D;le.zpp_pool==null?D=new le:(D=le.zpp_pool,le.zpp_pool=D.next,D.next=null),D.weak=!1,D._immutable=!1,D.x=X,D.y=H;let B=D;if(Ce.flowpoly.head!=null&&(Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(B)),Ce.flowpoly.add(B),v==null&&(v=Ce.flowpoly.head.elt),$){let V=0,J=0,Q=O;V=k.x+(M.x-k.x)*Q,J=k.y+(M.y-k.y)*Q;let K=Ce.flowpoly,ne;le.zpp_pool==null?ne=new le:(ne=le.zpp_pool,le.zpp_pool=ne.next,ne.next=null),ne.weak=!1,ne._immutable=!1,ne.x=V,ne.y=J,K.add(ne)}}}k=M,Z=E,y=C,E=E.next,E==null&&(E=t.polygon.gverts.next)}}if(Ce.flowpoly.head==null)return!1;if(Ce.flowpoly.head.next==null){let g=!0,k=t.polygon.edges.head;for(;k!=null;){let N=k.elt;if(N.gnormx*e.circle.worldCOMx+N.gnormy*e.circle.worldCOMy>N.gprojection){g=!1;break}k=k.next}return g?(n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0):!1}else{let g=0,k=0,N=0;if(Ce.flowpoly.head.next.next!=null){let M=0,C=0,L=0;M=0;let O=Ce.flowpoly.head,I=O.elt;O=O.next;let T=O.elt;for(O=O.next;O!=null;){let X=O.elt;M+=T.x*(X.y-I.y);let H=X.y*T.x-X.x*T.y;C+=(T.x+X.x)*H,L+=(T.y+X.y)*H,I=T,T=X,O=O.next}O=Ce.flowpoly.head;let W=O.elt;M+=T.x*(W.y-I.y);let R=W.y*T.x-W.x*T.y;C+=(T.x+W.x)*R,L+=(T.y+W.y)*R,I=T,T=W,O=O.next;let G=O.elt;M+=T.x*(G.y-I.y);let j=G.y*T.x-G.x*T.y;C+=(T.x+G.x)*j,L+=(T.y+G.y)*j,M*=.5;let q=1/(6*M);C*=q,L*=q;let $=-M;g+=C*$,k+=L*$,N-=M}else Ce.flowsegs.add(Ce.flowpoly.head.elt),Ce.flowsegs.add(Ce.flowpoly.head.next.elt);for(;Ce.flowsegs.head!=null;){let M=Ce.flowsegs.pop_unsafe(),C=Ce.flowsegs.pop_unsafe(),L=C.x-M.x,O=C.y-M.y,I=L,T=O,W=I*I+T*T,G=1/Math.sqrt(W);I*=G,T*=G;let j=I;I=-T,T=j;let S=M.x+C.x,q=M.y+C.y,$=.5;S*=$,q*=$;let X=1;S-=e.circle.worldCOMx*X,q-=e.circle.worldCOMy*X;let H=I*S+T*q,ee=0,F=0,D=H,B=D/e.circle.radius,V=Math.sqrt(1-B*B),J=Math.acos(B);ee=e.circle.radius*(e.circle.radius*J-D*V),F=.6666666666666666*e.circle.radius*V*V*V/(J-B*V),S=e.circle.worldCOMx,q=e.circle.worldCOMy;let Q=F;S+=I*Q,q+=T*Q;let K=ee;g+=S*K,k+=q*K,N+=ee}let E=1/N;return g*=E,k*=E,n.overlap=N,n.centroidx=g,n.centroidy=k,!0}}}else return!1}}else return!1}else{let s=e.circle,i=t.circle,o=i.worldCOMx-s.worldCOMx,r=i.worldCOMy-s.worldCOMy,a=s.radius+i.radius,p=o*o+r*r;if(p>a*a)return!1;if(p<l.Config.epsilon*l.Config.epsilon)return s.radius<i.radius?(n.overlap=s.area,n.centroidx=s.worldCOMx,n.centroidy=s.worldCOMy):(n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy),!0;{let c=Math.sqrt(p),u=1/c,h=.5*(c-(i.radius*i.radius-s.radius*s.radius)*u);if(h<=-s.radius)n.overlap=s.area,n.centroidx=s.worldCOMx,n.centroidy=s.worldCOMy;else{let x=c-h;if(x<=-i.radius)n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy;else{let b=0,_=0,d=0,f=0,m=h,z=m/s.radius,Z=Math.sqrt(1-z*z),y=Math.acos(z);b=s.radius*(s.radius*y-m*Z),_=.6666666666666666*s.radius*Z*Z*Z/(y-z*Z);let w=x,v=w/i.radius,P=Math.sqrt(1-v*v),g=Math.acos(v);d=i.radius*(i.radius*g-w*P),f=.6666666666666666*i.radius*P*P*P/(g-v*P);let k=b+d,N=(_*b+(c-f)*d)/k*u;n.overlap=k,n.centroidx=s.worldCOMx+o*N,n.centroidy=s.worldCOMy+r*N}}return!0}}}};Ce.__name__=["zpp_nape","geom","ZPP_Collide"],Ce.flowpoly=null,Ce.flowsegs=null;var Ee=Ce;var Ys=class Ys{static isinner(e,t,n){let l=e.x-t.x,s=e.y-t.y,i=n.x-t.x;return(n.y-t.y)*l-i*s>=0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let i=t;for(;i.sort(),i=i.next,i!=n;);}let l=e.vertices,s=e.vertices;if(l!=null){let i=l;for(;;){let o=i,r=o.prev,a=null,p=o.diagonals.head;for(;p!=null;){let c=p.elt,u=p.next==null?o.next:p.next.elt;if(!Ys.isinner(u,o,r)){a=p,r=c,p=p.next;continue}let h=!0,x=c,b=x.prev,_=null,d=x.diagonals.head;for(;d!=null;){let f=d.elt;if(f==o){let m=d.next==null?x.next:d.next.elt;h=Ys.isinner(m,x,b);break}b=f,_=d,d=d.next}if(h){p=o.diagonals.erase(a),x.diagonals.erase(_);continue}r=c,a=p,p=p.next}if(i=i.next,i==s)break}}}};Ys.__name__=["zpp_nape","geom","ZPP_Convex"];var vs=Ys;var it=class it{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;it.rayPool==null?(it.internal=!0,s=it._createRayResult(),s.zpp_inner=new it,s.zpp_inner.ray=s,it.internal=!1):(s=it.rayPool.ray,it.rayPool=it.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;it.convexPool==null?(it.internal=!0,s=it._createConvexResult(),s.zpp_inner=new it,s.zpp_inner.convex=s,it.internal=!1):(s=it.convexPool.convex,it.convexPool=it.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(){it._disposeVec2(this.normal),this.position!=null&&it._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=it.convexPool,it.convexPool=this):(this.next=it.rayPool,it.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,xe.nextVec2!=null?xe.nextVec2.zpp_pool=e:xe.poolVec2=e,xe.nextVec2=e,e.zpp_disp=!0,n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=le.zpp_pool,le.zpp_pool=n}};it.__name__=["zpp_nape","geom","ZPP_ConvexRayResult"],it.rayPool=null,it.convexPool=null,it.internal=!1,it._createRayResult=null,it._createConvexResult=null;var Pn=it;var Mi=class Mi{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 Mi.zpp_pool==null?t=new Mi:(t=Mi.zpp_pool,Mi.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}};Mi.__name__=["zpp_nape","geom","ZPP_CutVert"],Mi.zpp_pool=null;var $e=Mi;var Zi=class Zi{constructor(){this.next=null;this.time=0;this.virtualint=!1;this.vertex=!1;this.path0=null;this.end=null;this.start=null;this.path1=null}static get(e,t,n,l,s,i=!1,o=!1){let r;return Zi.zpp_pool==null?r=new Zi:(r=Zi.zpp_pool,Zi.zpp_pool=r.next,r.next=null),r.virtualint=i,r.end=t,r.start=n,r.path0=l,r.path1=s,r.time=e,r.vertex=o,r}alloc(){}free(){this.end=this.start=null,this.path0=this.path1=null}};Zi.__name__=["zpp_nape","geom","ZPP_CutInt"],Zi.zpp_pool=null;var rt=Zi;var Hn=class Hn{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 Hn.zpp_pool==null?n=new Hn:(n=Hn.zpp_pool,Hn.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,xe.nextVec2!=null?xe.nextVec2.zpp_pool=l:xe.poolVec2=l,xe.nextVec2=l,l.zpp_disp=!0;let s=n;s.outer!=null&&(s.outer.zpp_inner=null,s.outer=null),s._isimmutable=null,s._validate=null,s._invalidate=null,s.next=le.zpp_pool,le.zpp_pool=s,this.wrap=null}this.prev=this.next=null}wrapper(){if(this.wrap==null){let e=this.x,t=this.y;if(t==null&&(t=0),e==null&&(e=0),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(xe.poolVec2==null?n=Hn._createVec2Fn():(n=xe.poolVec2,xe.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n===xe.nextVec2&&(xe.nextVec2=null)),n.zpp_inner==null){let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=e,l.y=t,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x===e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),s=n.zpp_inner.y===t}else s=!1;if(!s){n.zpp_inner.x=e,n.zpp_inner.y=t;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.wrap=n,this.wrap.zpp_inner._inuse=!0,this.wrap.zpp_inner._invalidate=l=>this.modwrap(l),this.wrap.zpp_inner._validate=()=>this.getwrap()}return this.wrap}modwrap(e){this.x=e.x,this.y=e.y}getwrap(){this.wrap.zpp_inner.x=this.x,this.wrap.zpp_inner.y=this.y}};Hn.__name__=["zpp_nape","geom","ZPP_GeomVert"],Hn.zpp_pool=null,Hn._createVec2Fn=null;var we=Hn;var et=class et{static run(e,t,n,l,s,i){let o=ye(),r=o.__zpp;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=t.zpp_inner;a._validate!=null&&a._validate();let p=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=t.zpp_inner;c._validate!=null&&c._validate();let u=t.zpp_inner.y;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=n.zpp_inner;h._validate!=null&&h._validate();let x=n.zpp_inner.x-p;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let b=n.zpp_inner;b._validate!=null&&b._validate();let _=n.zpp_inner.y-u,d=l?0:-1/0,f=s?1:1/0,m=-(u*x-p*_),z=null,Z=!1,y=e;for(;;){let j;$e.zpp_pool==null?j=new $e:(j=$e.zpp_pool,$e.zpp_pool=j.next,j.next=null),j.vert=y,j.posx=y.x,j.posy=y.y,j.value=j.posy*x-j.posx*_+m,j.positive=j.value>0,j.value==0&&(Z=!0);let S=j;if(z==null?S.prev=S.next=S:(S.prev=z,S.next=z.next,z.next.prev=S,z.next=S),z=S,y=y.next,y==e)break}if(Z){let j=null,S=z,q=z;if(S!=null){let J=S;for(;;){let Q=J;if(Q.value!=0){j=Q;break}if(J=J.next,J==q)break}}let $,X;$=x,X=_;let H=$*$+X*X,F=1/Math.sqrt(H);$*=F,X*=F;let D=$;$=-X,X=D;let B=null,V=j;for(;;){if(V.value!=0&&(B==null||V==B.next)){if(B=V,V=V.next,V==j)break;continue}let J=B.value*V.value;if(J==0){if(V=V.next,V==j)break;continue}let Q=B.next,K;if(J>0)K=B.positive;else{let se=Q.next,ie,oe;ie=Q.posx+se.posx,oe=Q.posy+se.posy;let ce=.5;ie*=ce,oe*=ce;let pe=ie+$*1e-8,ae=oe+X*1e-8,_e=!1,te=e,he=e;if(te!=null){let me=te;for(;;){let ue=me,Pe=ue.prev;if((ue.y<ae&&Pe.y>=ae||Pe.y<ae&&ue.y>=ae)&&(ue.x<=pe||Pe.x<=pe)&&ue.x+(ae-ue.y)/(Pe.y-ue.y)*(Pe.x-ue.x)<pe&&(_e=!_e),me=me.next,me==he)break}}K=_e}let ne=Q,re=V;if(ne!=null){let se=ne;for(;;){let ie=se;if(ie.positive=K,se=se.next,se==re)break}}if(B=V,V=V.next,V==j)break}for(;!(V.value!=0&&(B==null||V==B.next));){let J=B.value*V.value;if(J==0)break;let Q=B.next,K;if(J>0)K=B.positive;else{let se=Q.next,ie,oe;ie=Q.posx+se.posx,oe=Q.posy+se.posy;let ce=.5;ie*=ce,oe*=ce;let pe=ie+$*1e-8,ae=oe+X*1e-8,_e=!1,te=e,he=e;if(te!=null){let me=te;for(;;){let ue=me,Pe=ue.prev;if((ue.y<ae&&Pe.y>=ae||Pe.y<ae&&ue.y>=ae)&&(ue.x<=pe||Pe.x<=pe)&&ue.x+(ae-ue.y)/(Pe.y-ue.y)*(Pe.x-ue.x)<pe&&(_e=!_e),me=me.next,me==he)break}}K=_e}let ne=Q,re=V;if(ne!=null){let se=ne;for(;;){let ie=se;if(ie.positive=K,se=se.next,se==re)break}}break}}et.ints==null&&(et.ints=new r.util.ZNPList_ZPP_CutInt),et.paths==null&&(et.paths=new r.util.ZNPList_ZPP_CutVert);let w=null,v=z.posx,P=z.posy,g;we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null),g.forced=!1,g.x=v,g.y=P;let k=g;k.prev=k.next=k,w=k;let N=w,E;$e.zpp_pool==null?E=new $e:(E=$e.zpp_pool,$e.zpp_pool=E.next,E.next=null),E.vert=w,E.parent=E,E.rank=0,E.used=!1;let M=E;et.paths.add(M);let C=z;for(;;){let j=C.next,S=j.posx,q=j.posy,$;we.zpp_pool==null?$=new we:($=we.zpp_pool,we.zpp_pool=$.next,$.next=null),$.forced=!1,$.x=S,$.y=q;let X=$;if(C.positive==j.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=j.posx-C.posx,ee=j.posy-C.posy,F=_*H-x*ee;F=1/F;let D=p-C.posx,B=u-C.posy,V=(ee*D-H*B)*F;if(V<d||V>f){let J=et.ints,Q=!0;Q==null&&(Q=!1);let K;rt.zpp_pool==null?K=new rt:(K=rt.zpp_pool,rt.zpp_pool=K.next,K.next=null),K.virtualint=Q,K.end=null,K.start=null,K.path0=null,K.path1=null,K.time=V,K.vertex=!1,J.add(K);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 J=w.prev;w=null;let Q=J.x,K=J.y,ne;we.zpp_pool==null?ne=new we:(ne=we.zpp_pool,we.zpp_pool=ne.next,ne.next=null),ne.forced=!1,ne.x=Q,ne.y=K;let re=ne;re.prev=re.next=re,w=re;let se=X;w==null?(se.prev=se.next=se,w=se):(se.next=w,se.prev=w.prev,w.prev.next=se,w.prev=se);let ie=et.paths.head.elt,oe=et.paths,ce;$e.zpp_pool==null?ce=new $e:(ce=$e.zpp_pool,$e.zpp_pool=ce.next,ce.next=null),ce.vert=w,ce.parent=ce,ce.rank=0,ce.used=!1,oe.add(ce);let pe=et.paths.head.elt,ae=et.ints,_e=!0;_e==null&&(_e=!1);let te;rt.zpp_pool==null?te=new rt:(te=rt.zpp_pool,rt.zpp_pool=te.next,te.next=null),te.virtualint=_e,te.end=J,te.start=w,te.path0=ie,te.path1=pe,te.time=V,te.vertex=!1,ae.add(te)}else if(j.value==0){let J=X;w==null?(J.prev=J.next=J,w=J):(J.next=w,J.prev=w.prev,w.prev.next=J,w.prev=J);let Q=w.prev;w=null;let K=j.posx,ne=j.posy,re;we.zpp_pool==null?re=new we:(re=we.zpp_pool,we.zpp_pool=re.next,re.next=null),re.forced=!1,re.x=K,re.y=ne;let se=re;se.prev=se.next=se,w=se;let ie=et.paths.head.elt,oe=et.paths,ce;$e.zpp_pool==null?ce=new $e:(ce=$e.zpp_pool,$e.zpp_pool=ce.next,ce.next=null),ce.vert=w,ce.parent=ce,ce.rank=0,ce.used=!1,oe.add(ce);let pe=et.paths.head.elt,ae=et.ints,_e=!0;_e==null&&(_e=!1);let te;rt.zpp_pool==null?te=new rt:(te=rt.zpp_pool,rt.zpp_pool=te.next,te.next=null),te.virtualint=_e,te.end=Q,te.start=w,te.path0=ie,te.path1=pe,te.time=V,te.vertex=!1,ae.add(te)}else{let J=(_*D-x*B)*F,Q,K;Q=C.posx,K=C.posy;let ne=J;Q+=H*ne,K+=ee*ne;let re;we.zpp_pool==null?re=new we:(re=we.zpp_pool,we.zpp_pool=re.next,re.next=null),re.forced=!1,re.x=Q,re.y=K;let se=re;w==null?(se.prev=se.next=se,w=se):(se.next=w,se.prev=w.prev,w.prev.next=se,w.prev=se);let ie=w.prev;w=null;let oe;we.zpp_pool==null?oe=new we:(oe=we.zpp_pool,we.zpp_pool=oe.next,oe.next=null),oe.forced=!1,oe.x=Q,oe.y=K;let ce=oe;ce.prev=ce.next=ce,w=ce;let pe=X;w==null?(pe.prev=pe.next=pe,w=pe):(pe.next=w,pe.prev=w.prev,w.prev.next=pe,w.prev=pe);let ae=et.paths.head.elt,_e=et.paths,te;$e.zpp_pool==null?te=new $e:(te=$e.zpp_pool,$e.zpp_pool=te.next,te.next=null),te.vert=w,te.parent=te,te.rank=0,te.used=!1,_e.add(te);let he=et.paths.head.elt,me=et.ints,ue=!1;ue==null&&(ue=!1);let Pe;rt.zpp_pool==null?Pe=new rt:(Pe=rt.zpp_pool,rt.zpp_pool=Pe.next,Pe.next=null),Pe.virtualint=ue,Pe.end=ie,Pe.start=w,Pe.path0=ae,Pe.path1=he,Pe.time=V,Pe.vertex=!1,me.add(Pe)}}if(C=C.next,C==z)break}let L=w.prev;L.next.prev=N.prev,N.prev.next=L.next,L.next=N,N.prev=L;let O=et.paths.head.elt,I;if(M==M.parent)I=M;else{let j=M,S=null;for(;j!=j.parent;){let q=j.parent;j.parent=S,S=j,j=q}for(;S!=null;){let q=S.parent;S.parent=j,S=q}I=j}let T;if(O==O.parent)T=O;else{let j=O,S=null;for(;j!=j.parent;){let q=j.parent;j.parent=S,S=j,j=q}for(;S!=null;){let q=S.parent;S.parent=j,S=q}T=j}I!=T&&(I.rank<T.rank?I.parent=T:I.rank>T.rank?T.parent=I:(T.parent=I,I.rank++));let W=et.ints;if(W.head!=null&&W.head.next!=null){let j=W.head,S,q,$,X,H=1,ee,F,D;for(;;){for(ee=0,q=j,j=null,S=j;q!=null;){for(++ee,$=q,F=0,D=H;$!=null&&F<H;)++F,$=$.next;for(;F>0||D>0&&$!=null;)F==0?(X=$,$=$.next,--D):D==0||$==null||q.elt.time<$.elt.time?(X=q,q=q.next,--F):(X=$,$=$.next,--D),S!=null?S.next=X:j=X,S=X;q=$}if(S.next=null,H<<=1,!(ee>1))break}W.head=j,W.modified=!0,W.pushmod=!0}for(;et.ints.head!=null;){let j=et.ints.pop_unsafe(),S=et.ints.pop_unsafe();if(!j.virtualint&&!S.virtualint){j.end.next.prev=S.start.prev,S.start.prev.next=j.end.next,j.end.next=S.start,S.start.prev=j.end,S.end.next.prev=j.start.prev,j.start.prev.next=S.end.next,S.end.next=j.start,j.start.prev=S.end;let X;if(j.path0==j.path0.parent)X=j.path0;else{let D=j.path0,B=null;for(;D!=D.parent;){let V=D.parent;D.parent=B,B=D,D=V}for(;B!=null;){let V=B.parent;B.parent=D,B=V}X=D}let H;if(S.path1==S.path1.parent)H=S.path1;else{let D=S.path1,B=null;for(;D!=D.parent;){let V=D.parent;D.parent=B,B=D,D=V}for(;B!=null;){let V=B.parent;B.parent=D,B=V}H=D}X!=H&&(X.rank<H.rank?X.parent=H:X.rank>H.rank?H.parent=X:(H.parent=X,X.rank++));let ee;if(j.path1==j.path1.parent)ee=j.path1;else{let D=j.path1,B=null;for(;D!=D.parent;){let V=D.parent;D.parent=B,B=D,D=V}for(;B!=null;){let V=B.parent;B.parent=D,B=V}ee=D}let F;if(S.path0==S.path0.parent)F=S.path0;else{let D=S.path0,B=null;for(;D!=D.parent;){let V=D.parent;D.parent=B,B=D,D=V}for(;B!=null;){let V=B.parent;B.parent=D,B=V}F=D}ee!=F&&(ee.rank<F.rank?ee.parent=F:ee.rank>F.rank?F.parent=ee:(F.parent=ee,ee.rank++))}else if(j.virtualint&&!S.virtualint){let X;if(S.end!=null&&S.end.prev==S.end){S.end.next=S.end.prev=null;let F=S.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let B=D.zpp_inner;if(B._immutable)throw new Error("Error: Vec2 is immutable");if(B._isimmutable!=null&&B._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let V=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let J=D;J.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=J:xe.poolVec2=J,xe.nextVec2=J,J.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=le.zpp_pool,le.zpp_pool=Q,F.wrap=null}F.prev=F.next=null,F.next=we.zpp_pool,we.zpp_pool=F,X=null}else{let F=S.end.prev;S.end.prev.next=S.end.next,S.end.next.prev=S.end.prev,S.end.next=S.end.prev=null;let D=S.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let B=D.wrap;if(B!=null&&B.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=B.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),B.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=B.zpp_inner;B.zpp_inner.outer=null,B.zpp_inner=null;let Q=B;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,D.wrap=null}D.prev=D.next=null,D.next=we.zpp_pool,we.zpp_pool=D,S.end=null,X=F}if(S.end=X,!S.vertex)if(S.end!=S.path0.vert){S.start.x=S.end.x,S.start.y=S.end.y;let F;if(S.end!=null&&S.end.prev==S.end){S.end.next=S.end.prev=null;let D=S.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let B=D.wrap;if(B!=null&&B.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=B.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),B.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=B.zpp_inner;B.zpp_inner.outer=null,B.zpp_inner=null;let Q=B;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,D.wrap=null}D.prev=D.next=null,D.next=we.zpp_pool,we.zpp_pool=D,F=null}else{let D=S.end.prev;S.end.prev.next=S.end.next,S.end.next.prev=S.end.prev,S.end.next=S.end.prev=null;let B=S.end;if(B.wrap!=null){B.wrap.zpp_inner._inuse=!1;let V=B.wrap;if(V!=null&&V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let J=V.zpp_inner;if(J._immutable)throw new Error("Error: Vec2 is immutable");if(J._isimmutable!=null&&J._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 K=V;K.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=K:xe.poolVec2=K,xe.nextVec2=K,K.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=le.zpp_pool,le.zpp_pool=ne,B.wrap=null}B.prev=B.next=null,B.next=we.zpp_pool,we.zpp_pool=B,S.end=null,F=D}S.end=F}else{let F=S.start.next;if(S.start.x=F.x,S.start.y=F.y,F!=null&&F.prev==F){F.next=F.prev=null;let D=F;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let B=D.wrap;if(B!=null&&B.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=B.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),B.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=B.zpp_inner;B.zpp_inner.outer=null,B.zpp_inner=null;let Q=B;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,D.wrap=null}D.prev=D.next=null,D.next=we.zpp_pool,we.zpp_pool=D}else{F.prev.next=F.next,F.next.prev=F.prev,F.next=F.prev=null;let D=F;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let B=D.wrap;if(B!=null&&B.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=B.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),B.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=B.zpp_inner;B.zpp_inner.outer=null,B.zpp_inner=null;let Q=B;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,D.wrap=null}D.prev=D.next=null,D.next=we.zpp_pool,we.zpp_pool=D}}S.end.next.prev=S.start.prev,S.start.prev.next=S.end.next,S.end.next=S.start,S.start.prev=S.end;let H;if(S.path0==S.path0.parent)H=S.path0;else{let F=S.path0,D=null;for(;F!=F.parent;){let B=F.parent;F.parent=D,D=F,F=B}for(;D!=null;){let B=D.parent;D.parent=F,D=B}H=F}let ee;if(S.path1==S.path1.parent)ee=S.path1;else{let F=S.path1,D=null;for(;F!=F.parent;){let B=F.parent;F.parent=D,D=F,F=B}for(;D!=null;){let B=D.parent;D.parent=F,D=B}ee=F}H!=ee&&(H.rank<ee.rank?H.parent=ee:H.rank>ee.rank?ee.parent=H:(ee.parent=H,H.rank++))}else if(S.virtualint&&!j.virtualint){let X;if(j.end!=null&&j.end.prev==j.end){j.end.next=j.end.prev=null;let F=j.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let B=D.zpp_inner;if(B._immutable)throw new Error("Error: Vec2 is immutable");if(B._isimmutable!=null&&B._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let V=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let J=D;J.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=J:xe.poolVec2=J,xe.nextVec2=J,J.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=le.zpp_pool,le.zpp_pool=Q,F.wrap=null}F.prev=F.next=null,F.next=we.zpp_pool,we.zpp_pool=F,X=null}else{let F=j.end.prev;j.end.prev.next=j.end.next,j.end.next.prev=j.end.prev,j.end.next=j.end.prev=null;let D=j.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let B=D.wrap;if(B!=null&&B.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=B.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),B.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=B.zpp_inner;B.zpp_inner.outer=null,B.zpp_inner=null;let Q=B;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,D.wrap=null}D.prev=D.next=null,D.next=we.zpp_pool,we.zpp_pool=D,j.end=null,X=F}if(j.end=X,!j.vertex)if(j.end!=j.path0.vert){j.start.x=j.end.x,j.start.y=j.end.y;let F;if(j.end!=null&&j.end.prev==j.end){j.end.next=j.end.prev=null;let D=j.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let B=D.wrap;if(B!=null&&B.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=B.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),B.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=B.zpp_inner;B.zpp_inner.outer=null,B.zpp_inner=null;let Q=B;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,D.wrap=null}D.prev=D.next=null,D.next=we.zpp_pool,we.zpp_pool=D,F=null}else{let D=j.end.prev;j.end.prev.next=j.end.next,j.end.next.prev=j.end.prev,j.end.next=j.end.prev=null;let B=j.end;if(B.wrap!=null){B.wrap.zpp_inner._inuse=!1;let V=B.wrap;if(V!=null&&V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let J=V.zpp_inner;if(J._immutable)throw new Error("Error: Vec2 is immutable");if(J._isimmutable!=null&&J._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 K=V;K.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=K:xe.poolVec2=K,xe.nextVec2=K,K.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=le.zpp_pool,le.zpp_pool=ne,B.wrap=null}B.prev=B.next=null,B.next=we.zpp_pool,we.zpp_pool=B,j.end=null,F=D}j.end=F}else{let F=j.start.next;if(j.start.x=F.x,j.start.y=F.y,F!=null&&F.prev==F){F.next=F.prev=null;let D=F;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let B=D.wrap;if(B!=null&&B.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=B.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),B.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=B.zpp_inner;B.zpp_inner.outer=null,B.zpp_inner=null;let Q=B;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,D.wrap=null}D.prev=D.next=null,D.next=we.zpp_pool,we.zpp_pool=D}else{F.prev.next=F.next,F.next.prev=F.prev,F.next=F.prev=null;let D=F;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let B=D.wrap;if(B!=null&&B.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=B.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),B.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=B.zpp_inner;B.zpp_inner.outer=null,B.zpp_inner=null;let Q=B;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,D.wrap=null}D.prev=D.next=null,D.next=we.zpp_pool,we.zpp_pool=D}}j.end.next.prev=j.start.prev,j.start.prev.next=j.end.next,j.end.next=j.start,j.start.prev=j.end;let H;if(j.path0==j.path0.parent)H=j.path0;else{let F=j.path0,D=null;for(;F!=F.parent;){let B=F.parent;F.parent=D,D=F,F=B}for(;D!=null;){let B=D.parent;D.parent=F,D=B}H=F}let ee;if(j.path1==j.path1.parent)ee=j.path1;else{let F=j.path1,D=null;for(;F!=F.parent;){let B=F.parent;F.parent=D,D=F,F=B}for(;D!=null;){let B=D.parent;D.parent=F,D=B}ee=F}H!=ee&&(H.rank<ee.rank?H.parent=ee:H.rank>ee.rank?ee.parent=H:(ee.parent=H,H.rank++))}let q=j;q.end=q.start=null,q.path0=q.path1=null,q.next=rt.zpp_pool,rt.zpp_pool=q;let $=S;$.end=$.start=null,$.path0=$.path1=null,$.next=rt.zpp_pool,rt.zpp_pool=$}let R=i??new o.geom.GeomPolyList,G=et.paths.head;for(;G!=null;){let j=G.elt,S;if(j==j.parent)S=j;else{let X=j,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}S=X}if(S.used){G=G.next;continue}S.used=!0;let q=S.vert,$=!0;for(;S.vert!=null&&($||q!=S.vert);)if($=!1,q.x==q.next.x&&q.y==q.next.y)if(q==S.vert&&(S.vert=q.next==q?null:q.next,$=!0),q!=null&&q.prev==q)q.next=q.prev=null,q=null;else{let X=q.next;q.prev.next=q.next,q.next.prev=q.prev,q.next=q.prev=null,q=X}else q=q.next;if(S.vert!=null){let X=o.geom.GeomPoly.get();X.zpp_inner.vertices=S.vert,R.zpp_inner.reverse_flag?R.push(X):R.unshift(X)}G=G.next}for(;et.paths.head!=null;){let S=et.paths.pop_unsafe();S.vert=null,S.parent=null,S.next=$e.zpp_pool,$e.zpp_pool=S}for(;z!=null;)if(z!=null&&z.prev==z){z.next=z.prev=null;let j=z;j.vert=null,j.parent=null,j.next=$e.zpp_pool,$e.zpp_pool=j,z=null}else{let j=z.next;z.prev.next=z.next,z.next.prev=z.prev,z.next=z.prev=null;let S=z;S.vert=null,S.parent=null,S.next=$e.zpp_pool,$e.zpp_pool=S,z=j}return R}};et.__name__=["zpp_nape","geom","ZPP_Cutter"],et.ints=null,et.paths=null;var gs=et;var Cs=class Cs{static validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=t.body.posx+(t.body.axisy*h.x-t.body.axisx*h.y),u.y=t.body.posy+(h.x*t.body.axisx+h.y*t.body.axisy),c=c.next}}let l=t.edges.head,s=t.gverts.next,i=s;for(s=s.next;s!=null;){let a=s,p=l.elt;l=l.next,p.gp0=i,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,i=a,s=s.next}let o=t.gverts.next,r=l.elt;r.gp0=i,r.gp1=o,r.gnormx=t.body.axisy*r.lnormx-t.body.axisx*r.lnormy,r.gnormy=r.lnormx*t.body.axisx+r.lnormy*t.body.axisy,r.gprojection=t.body.posx*r.gnormx+t.body.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;Cs._validateWorldCOM(t);let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=i;i=i.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type==1&&Cs._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&&Cs._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy));let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}static _computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null){e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;let t=1;e.localCOMx+=e.lverts.next.next.x*t,e.localCOMy+=e.lverts.next.next.y*t;let n=.5;e.localCOMx*=n,e.localCOMy*=n}else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,l=n;n=n.next;let s=n;for(n=n.next;n!=null;){let c=n;t+=s.x*(c.y-l.y);let u=c.y*s.x-c.x*s.y;e.localCOMx+=(s.x+c.x)*u,e.localCOMy+=(s.y+c.y)*u,l=s,s=c,n=n.next}n=e.lverts.next;let i=n;t+=s.x*(i.y-l.y);let o=i.y*s.x-i.x*s.y;e.localCOMx+=(s.x+i.x)*o,e.localCOMy+=(s.y+i.y)*o,l=s,s=i,n=n.next;let r=n;t+=s.x*(r.y-l.y);let a=r.y*s.x-r.x*s.y;e.localCOMx+=(s.x+r.x)*a,e.localCOMy+=(s.y+r.y)*a,t=1/(3*t);let p=t;e.localCOMx*=p,e.localCOMy*=p}}};Cs.__name__=["zpp_nape","geom","ZPP_Geom"];var Ms=Cs;var os=class{constructor(e=null){this.outer=null;this.vertices=null;this.outer=e}};os.__name__=["zpp_nape","geom","ZPP_GeomPoly"];var Mn=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}};Mn.__name__=["zpp_nape","geom","ZPP_MarchSpan"],Mn.zpp_pool=null;var Zn=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(){}};Zn.__name__=["zpp_nape","geom","ZPP_MarchPair"],Zn.zpp_pool=null;var ze=class ze{static _init(e,t){ze._zpp=e,ze._nape=t,ze.me=new ze,ze.look_march=[-1,224,56,216,14,-1,54,214,131,99,-1,91,141,109,181,85]}static _allocVert(e,t){let n;return we.zpp_pool==null?n=new we:(n=we.zpp_pool,we.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,xe.nextVec2!=null?xe.nextVec2.zpp_pool=s:xe.poolVec2=s,xe.nextVec2=s,s.zpp_disp=!0;let i=l;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i._isimmutable=null,i._validate=null,i._invalidate=null,i.next=le.zpp_pool,le.zpp_pool=i,e.wrap=null}e.prev=e.next=null,e.next=we.zpp_pool,we.zpp_pool=e}static _allocSpan(){let e;return Mn.zpp_pool==null?e=new Mn:(e=Mn.zpp_pool,Mn.zpp_pool=e.next,e.next=null),e.out=!1,e.rank=0,e}static _allocPair(){let e;return Zn.zpp_pool==null?e=new Zn:(e=Zn.zpp_pool,Zn.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=Zn.zpp_pool,Zn.zpp_pool=e}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let l=t.parent;t.parent=n,n=t,t=l}for(;n!=null;){let l=n.parent;n.parent=t,n=l}return t}static _union(e,t){let n=ze._findRoot(e),l=ze._findRoot(t);n!=l&&(n.rank<l.rank?n.parent=l:n.rank>l.rank?l.parent=n:(l.parent=n,n.rank++))}static _pushVert(e,t){return e==null?t.prev=t.next=t:(t.prev=e,t.next=e.next,e.next.prev=t,e.next=t),t}static _isDegenKey(e){return e==1||e==4||e==16||e==64||e==3||e==12||e==48||e==192||e==129||e==6||e==24||e==96||e==5||e==20||e==80||e==65||e==17||e==68}static ISO(e,t,n){return e(t,n)}static run(e,t,n,l,s,i,o,r,a){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=i.zpp_inner;p._validate!=null&&p._validate();let c=(l-t)/i.zpp_inner.x,u=c|0;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");p=i.zpp_inner,p._validate!=null&&p._validate();let h=(s-n)/i.zpp_inner.y,x=h|0;c!=u&&++u,h!=x&&++x,r&&(ze.map==null?ze.map=new Ki(u,x):ze.map.resize(u,x,null)),ze.isos==null?ze.isos=new Ji(u+1,x+1):ze.isos.resize(u+1,x+1,0);for(let d=0;d<x+1;d++){let f;if(d==0)f=n;else if(d<=x){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let m=i.zpp_inner;m._validate!=null&&m._validate(),f=n+i.zpp_inner.y*d}else f=s;for(let m=0;m<u+1;m++){let z;if(m==0)z=t;else if(m<=u){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let w=i.zpp_inner;w._validate!=null&&w._validate(),z=t+i.zpp_inner.x*m}else z=l;let Z=ze.isos,y=e(z,f);Z.list[d*Z.width+m]=y}}ze.ints==null?ze.ints=new Ui(u+1,(x<<1)+1):ze.ints.resize(u+1,(x<<1)+1,null);let b=null;r&&(b=ze._allocSpan(),b.next=null);let _=n;for(let d=0;d<x;d++){let f=_,m;if(d==x-1)m=s;else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let y=i.zpp_inner;y._validate!=null&&y._validate(),m=n+i.zpp_inner.y*(d+1)}_=m;let z=t,Z=null;for(let y=0;y<u;y++){let w=z,v;if(y==u-1)v=l;else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let M=i.zpp_inner;M._validate!=null&&M._validate(),v=t+i.zpp_inner.x*(y+1)}z=v;let P=y==0||!r,g=d==0||!r,k=y==u-1||!r,N=d==x-1||!r,E=ze.me.marchSquare(e,ze.isos,ze.ints,w,f,v,m,y,d,P,g,k,N,o);if(E==null){Z=null;continue}if(r){let M=E.p2!=null&&E.okey2!=14?E.p2:E.p1;E.pd=((M==E.p2?E.okey2:E.okey1)&128)==0?M.prev:M.prev.prev;let C=ze.map;C.list[d*C.width+y]=E;let L;if(Z!=null){let T=E.key1,W=T&1|(T&192)>>5,R=0;(W&1)!=0&&++R,(W&2)!=0&&++R,(W&4)!=0&&++R,L=R>=2}else L=!1;L?(ze.me.combLR(Z,E),E.span1=Z.spanr):(E.span1=ze._allocSpan(),E.span1.next=b,b=E.span1),E.p2!=null?(E.span2=ze._allocSpan(),E.span2.next=b,b=E.span2,E.spanr=E.span2):E.spanr=E.span1;let O=(E.keyr&28)>>2,I=0;(O&1)!=0&&++I,(O&2)!=0&&++I,(O&4)!=0&&++I,I>=2?Z=E:Z=null}else ze.me.output(a,E.p1),E.p2!=null&&ze.me.output(a,E.p2),ze._freePair(E)}}if(r){for(let d=1;d<x;d++){let f=null;for(let m=0;m<u;m++){let z=ze.map,Z=z.list[d*z.width+m];if(Z==null){f=null;continue}let w=(Z.p2!=null&&Z.okey2==14?Z.okey2:Z.okey1)&7,v=0;if((w&1)!=0&&++v,(w&2)!=0&&++v,(w&4)!=0&&++v,v<2){f=null;continue}let P=ze.map,g=P.list[(d-1)*P.width+m];if(g==null){f=null;continue}let N=((g.p2!=null&&g.okey2==56?g.okey2:g.okey1)&112)>>4,E=0;if((N&1)!=0&&++E,(N&2)!=0&&++E,(N&4)!=0&&++E,E<2){f=null;continue}let M=g.p2!=null&&g.okey2==56?g.span2:g.span1,C=Z.p2!=null&&Z.okey2==14?Z.span2:Z.span1,L=ze._findRoot(M),O=ze._findRoot(C);L==O?f!=C&&ze.me.combUD_virtual(g,Z):(ze._union(M,C),ze.me.combUD(g,Z)),f=((C==Z.span2?Z.okey2:Z.okey1)&4)!=0?C:null}}for(let d=0;d<x;d++)for(let f=0;f<u;f++){let m=ze.map,z=m.list[d*m.width+f];if(z==null)continue;let Z=ze._findRoot(z.span1);Z.out||(Z.out=!0,ze.me.output(a,z.p1)),z.p2!=null&&(Z=ze._findRoot(z.span2),Z.out||(Z.out=!0,ze.me.output(a,z.p2))),ze._freePair(z),m.list[d*m.width+f]=null}for(;b!=null;){let d=b;b=d.next;let f=d;f.parent=f,f.next=Mn.zpp_pool,Mn.zpp_pool=f}}}output(e,t){let n=ze._nape,l;if(t==null||t.next==t||t.next==t.prev)l=!0;else{let o=0,r=t,a=t;if(r!=null){let c=r;for(;;){let u=c;if(o+=u.x*(u.next.y-u.prev.y),c=c.next,c==a)break}}let p=o*.5;l=p*p<n.Config.epsilon*n.Config.epsilon}if(l){for(;t!=null;)if(t!=null&&t.prev==t)t.next=t.prev=null,t=null;else{let o=t.next;t.prev.next=t.next,t.next.prev=t.prev,t.next=t.prev=null,t=o}return}let s=n.geom.GeomPoly.get();s.zpp_inner.vertices=t;let i=e;i.zpp_inner.reverse_flag?i.push(s):i.unshift(s)}linkright(e,t){let n=t&7;return n==0?e:n==3?e.next.next:e.next}linkleft(e,t){return(t&1)==0?e.prev:e}linkdown(e,t){return(t&128)==0?e.prev:e.prev.prev}linkup(e,t){return e}combLR(e,t){let n=e.pr,l=e.okeyr&7,s=l==0?n:l==3?n.next.next:n.next,i=t.p1,o=(t.okey1&1)==0?i.prev:i,r=s.next,a=o.prev;(e.keyr&4)!=0?(t.pr==t.p1&&(t.pr=s.prev),t.p1=s.prev,s.prev.next=o.next,o.next.prev=s.prev,ze._freeVert(s)):(s.next=o.next,o.next.prev=s),ze._freeVert(o),(e.keyr&16)!=0?(t.pd=r.next,r.next.prev=a.prev,a.prev.next=r.next,ze._freeVert(r)):(r.prev=a.prev,a.prev.next=r),ze._freeVert(a)}combUD(e,t){let n=e.pd,l=t.p2!=null&&t.key2==14?t.p2:t.p1,s=n.prev,i=l.next;l.next=n.next,n.next.prev=l,ze._freeVert(n),i.prev=s.prev,s.prev.next=i,s==e.p1&&(e.p1=i),ze._freeVert(s)}combUD_virtual(e,t){let n=e.pd,l=t.p2!=null&&t.key2==14?t.p2:t.p1,s=n.prev,i=l.next;n.forced=l.forced=s.forced=i.forced=!0}combLeft(e){let t=e&1|(e&192)>>5,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combRight(e){let t=(e&28)>>2,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combUp(e){let t=e&7,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combDown(e){let t=(e&112)>>4,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}comb(e){let t=0;return(e&1)!=0&&++t,(e&2)!=0&&++t,(e&4)!=0&&++t,t>=2}_buildPoly(e,t,n,l,s,i,o,r,a,p,c,u,h,x,b,_,d,f,m){let z=null;for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let y;if(Z==0)y=ze._allocVert(l,s),(x||b)&&(y.forced=!0);else if(Z==2)y=ze._allocVert(i,s),(_||b)&&(y.forced=!0);else if(Z==4)y=ze._allocVert(i,o),(_||d)&&(y.forced=!0);else if(Z==6)y=ze._allocVert(l,o),(x||d)&&(y.forced=!0);else if(Z==1){if(y=n.list[(a<<1)*n.width+r],y==null){let w=this.xlerp(l,i,s,p,c,f,m);y=ze._allocVert(w,s),n.list[(a<<1)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);b&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&1)!=0||y.x==i&&(e&4)!=0)&&(e^=2)}else if(Z==5){if(y=n.list[((a<<1)+2)*n.width+r],y==null){let w=this.xlerp(l,i,o,h,u,f,m);y=ze._allocVert(w,o),n.list[((a<<1)+2)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);d&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&64)!=0||y.x==i&&(e&16)!=0)&&(e^=32)}else if(Z==3){if(y=n.list[((a<<1)+1)*n.width+(r+1)],y==null){let w=this.ylerp(s,o,i,c,u,f,m);y=ze._allocVert(i,w),n.list[((a<<1)+1)*n.width+(r+1)]=y}else y=ze._allocVert(y.x,y.y);_&&(y.forced=!0),(y.y==s||y.y==o)&&(y.y==s&&(e&4)!=0||y.y==o&&(e&16)!=0)&&(e^=8)}else{if(y=n.list[((a<<1)+1)*n.width+r],y==null){let w=this.ylerp(s,o,l,p,h,f,m);y=ze._allocVert(l,w),n.list[((a<<1)+1)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);x&&(y.forced=!0),(y.y==s||y.y==o)&&(y.y==s&&(e&1)!=0||y.y==o&&(e&64)!=0)&&(e^=128)}z=ze._pushVert(z,y)}return z!=null&&(z=z.next),{head:z,val:e}}marchSquare(e,t,n,l,s,i,o,r,a,p,c,u,h,x){let b=0,_=t.list[a*t.width+r];_<0&&(b|=8);let d=t.list[a*t.width+(r+1)];d<0&&(b|=4);let f=t.list[(a+1)*t.width+(r+1)];f<0&&(b|=2);let m=t.list[(a+1)*t.width+r];if(m<0&&(b|=1),b==0)return null;let z=ze._allocPair();if(b!=10&&b!=5){let Z=ze.look_march[b];z.okey1=Z;let y=this._buildPoly(Z,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=y.head,Z=y.val,z.key1=Z,ze._isDegenKey(Z)&&(Z=0,z.key1=0,z.p1=null),Z==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}else{let Z=e(.5*(l+i),.5*(s+o))<0;if(b==10)if(Z){let y=187;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=w.head,y=w.val,z.key1=y,ze._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}else{let y=131;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);if(z.p1=w.head,y=w.val,z.key1=y,ze._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y!=0){let v=56;z.okey2=v,v=this._buildPoly2(v,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x,z).val,z.key2=v,ze._isDegenKey(v)&&(v=0,z.key2=0,z.p2=null),v==0?(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1):(z.pr=z.p2,z.okeyr=z.okey2,z.keyr=z.key2)}else{let v=56;z.okey1=v;let P=this._buildPoly(v,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=P.head,v=P.val,z.key1=v,ze._isDegenKey(v)&&(v=0,z.key1=0,z.p1=null),v==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}}else if(Z){let y=238;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=w.head,y=w.val,z.key1=y,ze._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}else{let y=224;z.okey1=y;let w=this._buildPoly(y,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);if(z.p1=w.head,y=w.val,z.key1=y,ze._isDegenKey(y)&&(y=0,z.key1=0,z.p1=null),y!=0){let v=14;z.okey2=v,v=this._buildPoly2(v,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x,z).val,z.key2=v,ze._isDegenKey(v)&&(v=0,z.key2=0,z.p2=null),v==0?(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1):(z.pr=z.p2,z.okeyr=z.okey2,z.keyr=z.key2)}else{let v=14;z.okey1=v;let P=this._buildPoly(v,t,n,l,s,i,o,r,a,_,d,f,m,p,c,u,h,e,x);z.p1=P.head,v=P.val,z.key1=v,ze._isDegenKey(v)&&(v=0,z.key1=0,z.p1=null),v==0?z=null:(z.pr=z.p1,z.okeyr=z.okey1,z.keyr=z.key1)}}}return z}_buildPoly2(e,t,n,l,s,i,o,r,a,p,c,u,h,x,b,_,d,f,m,z){for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let y;if(Z==0)y=ze._allocVert(l,s),(x||b)&&(y.forced=!0);else if(Z==2)y=ze._allocVert(i,s),(_||b)&&(y.forced=!0);else if(Z==4)y=ze._allocVert(i,o),(_||d)&&(y.forced=!0);else if(Z==6)y=ze._allocVert(l,o),(x||d)&&(y.forced=!0);else if(Z==1){if(y=n.list[(a<<1)*n.width+r],y==null){let v=this.xlerp(l,i,s,p,c,f,m);y=ze._allocVert(v,s),n.list[(a<<1)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);b&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&1)!=0||y.x==i&&(e&4)!=0)&&(e^=2)}else if(Z==5){if(y=n.list[((a<<1)+2)*n.width+r],y==null){let v=this.xlerp(l,i,o,h,u,f,m);y=ze._allocVert(v,o),n.list[((a<<1)+2)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);d&&(y.forced=!0),(y.x==l||y.x==i)&&(y.x==l&&(e&64)!=0||y.x==i&&(e&16)!=0)&&(e^=32)}else if(Z==3){if(y=n.list[((a<<1)+1)*n.width+(r+1)],y==null){let v=this.ylerp(s,o,i,c,u,f,m);y=ze._allocVert(i,v),n.list[((a<<1)+1)*n.width+(r+1)]=y}else y=ze._allocVert(y.x,y.y);_&&(y.forced=!0),(y.y==s||y.y==o)&&(y.y==s&&(e&4)!=0||y.y==o&&(e&16)!=0)&&(e^=8)}else{if(y=n.list[((a<<1)+1)*n.width+r],y==null){let v=this.ylerp(s,o,l,p,h,f,m);y=ze._allocVert(l,v),n.list[((a<<1)+1)*n.width+r]=y}else y=ze._allocVert(y.x,y.y);x&&(y.forced=!0),(y.y==s||y.y==o)&&(y.y==s&&(e&1)!=0||y.y==o&&(e&64)!=0)&&(e^=128)}let w=y;z.p2==null?z.p2=w.prev=w.next=w:(w.prev=z.p2,w.next=z.p2.next,z.p2.next.prev=w,z.p2.next=w),z.p2=w}return z.p2!=null&&(z.p2=z.p2.next),{val:e}}lerp(e,t,n,l){let s=ze._nape;if(n==0)return e;if(l==0)return t;{let i=n-l,o=i*i<s.Config.epsilon*s.Config.epsilon?.5:n/i;return o<0?o=0:o>1&&(o=1),e+o*(t-e)}}xlerp(e,t,n,l,s,i,o){let r=ze._nape,a;if(l==0)a=e;else if(s==0)a=t;else{let p=l-s,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:l/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=i(a,n);if(p==0)break;if(l*p<0?(t=a,s=p):(e=a,l=p),l==0)a=e;else if(s==0)a=t;else{let c=l-s,u=c*c<r.Config.epsilon*r.Config.epsilon?.5:l/c;u<0?u=0:u>1&&(u=1),a=e+u*(t-e)}}return a}ylerp(e,t,n,l,s,i,o){let r=ze._nape,a;if(l==0)a=e;else if(s==0)a=t;else{let p=l-s,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:l/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=i(n,a);if(p==0)break;if(l*p<0?(t=a,s=p):(e=a,l=p),l==0)a=e;else if(s==0)a=t;else{let c=l-s,u=c*c<r.Config.epsilon*r.Config.epsilon?.5:l/c;u<0?u=0:u>1&&(u=1),a=e+u*(t-e)}}return a}};ze.__name__=["zpp_nape","geom","ZPP_MarchingSquares"],ze.isos=null,ze.ints=null,ze.map=null,ze._zpp=null,ze._nape=null;var Xs=ze;var ln=class ln{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 ln.zpp_pool==null?e=new ln:(e=ln.zpp_pool,ln.zpp_pool=e.next,e.next=null),e}static identity(){let e=ln.get();return e.setas(1,0,0,1,0,0),e}wrapper(){if(this.outer==null)if(ln._wrapFn)this.outer=ln._wrapFn(this);else{this.outer=new ln._nape.geom.Mat23;let e=this.outer.zpp_inner;e.next=ln.zpp_pool,ln.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(){}};ln.__name__=["zpp_nape","geom","ZPP_Mat23"],ln._nape=null,ln._wrapFn=null,ln.zpp_pool=null;var Hs=ln;var ki=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)}};ki.__name__=["zpp_nape","geom","ZPP_MatMN"];var mt=class mt{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=mt.nextId++,this.diagonals=new gi}static get(e){let t;return mt.zpp_pool==null?t=new mt:(t=mt.zpp_pool,mt.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t}static rightdistance(e,t){let n=e.next.y>e.y,l=e.next.x-e.x,s=e.next.y-e.y,i=t.x-e.x,o=t.y-e.y;return(n?-1:1)*(o*l-i*s)}static vert_lt(e,t){if(t==e||t==e.next)return!0;if(e.y==e.next.y){let n=e.x,l=e.next.x;return(n<l?n:l)<=t.x}else return mt.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!mt.vert_lt(e,t);if(t==e.next)return mt.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 mt.rightdistance(t,e)>0?!0:mt.rightdistance(t,e.next)>0;else{let n=mt.rightdistance(e,t),l=mt.rightdistance(e,t.next);if(n==0&&l==0){let o=e.x,r=e.next.x,a=t.x,p=t.next.x;return(o>r?o:r)>(a>p?a:p)}if(n*l>=0)return n<0?!0:l<0;let s=mt.rightdistance(t,e),i=mt.rightdistance(t,e.next);return s*i>=0?s>0?!0:i>0:!1}}alloc(){}free(){this.helper=null}copy(){let e;return mt.zpp_pool==null?e=new mt:(e=mt.zpp_pool,mt.zpp_pool=e.next,e.next=null),e.x=this.x,e.y=this.y,e.forced=this.forced,e}sort(){let e=this.prev.x-this.x,t=this.prev.y-this.y,n=this.next.x-this.x,l=this.next.y-this.y,s=l*e-n*t,i=s>0?-1:s==0?0:1,o=this.diagonals;if(o.head!=null&&o.head.next!=null){let r=o.head,a,p,c,u,h=1,x,b,_;for(;;){for(x=0,p=r,r=null,a=r;p!=null;){for(++x,c=p,b=0,_=h;c!=null&&b<h;)++b,c=c.next;for(;b>0||_>0&&c!=null;){if(b==0)u=c,c=c.next,--_;else if(_==0||c==null)u=p,p=p.next,--b;else{let d;if(i==1){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,l=c.elt.y-this.y;let f=l*e-n*t;d=(f>0?-1:f==0?0:1)==1}else{e=this.prev.x-this.x,t=this.prev.y-this.y,n=p.elt.x-this.x,l=p.elt.y-this.y;let f=l*e-n*t,m=f>0?-1:f==0?0:1;e=this.prev.x-this.x,t=this.prev.y-this.y,n=c.elt.x-this.x,l=c.elt.y-this.y;let z=l*e-n*t,Z=z>0?-1:z==0?0:1;if(m*Z==1||m*Z==0&&(m==1||Z==1)){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,l=c.elt.y-this.y;let y=l*e-n*t;d=(y>0?-1:y==0?0:1)==1}else if(m==-1||Z==-1)d=Z==-1;else if(m==0&&Z==0){e=this.x-this.prev.x,t=this.y-this.prev.y,n=p.elt.x-this.x,l=p.elt.y-this.y;let y=e*n+t*l;n=c.elt.x-this.x,l=c.elt.y-this.y;let w=e*n+t*l;d=y<0&&w>0?!0:!(w<0&&y>0)}else d=!0}d?(u=p,p=p.next,--b):(u=c,c=c.next,--_)}a!=null?a.next=u:r=u,a=u}p=c}if(a.next=null,h<<=1,!(x>1))break}o.head=r,o.modified=!0,o.pushmod=!0}}};mt.__name__=["zpp_nape","geom","ZPP_PartitionVertex"],mt.zpp_pool=null,mt.nextId=0;var Ge=mt;var on=class on{constructor(e){this.next=null;this.vertices=null;this.init(e)}static getSharedPP(){return on.sharedPPList==null&&(on.sharedPPList=new Qi),on.sharedPPList}static getShared(){return on.sharedGVList==null&&(on.sharedGVList=new Fn),on.sharedGVList}eq(e,t){let n=e.x-t.x,l=e.y-t.y;return n*n+l*l<ye().Config.epsilon*ye().Config.epsilon}alloc(){}free(){}init(e){if(e==null)return;let t=0,n=e,l=e;if(n!=null){let o=n;for(;;){let r=o;if(t+=r.x*(r.next.y-r.prev.y),o=o.next,o==l)break}}let s=t*.5>0,i=e;for(;;){let o;if(s){let r;Ge.zpp_pool==null?r=new Ge:(r=Ge.zpp_pool,Ge.zpp_pool=r.next,r.next=null),r.x=i.x,r.y=i.y;let a=r;this.vertices==null?this.vertices=a.prev=a.next=a:(a.prev=this.vertices,a.next=this.vertices.next,this.vertices.next.prev=a,this.vertices.next=a),o=a}else{let r;Ge.zpp_pool==null?r=new Ge:(r=Ge.zpp_pool,Ge.zpp_pool=r.next,r.next=null),r.x=i.x,r.y=i.y;let a=r;this.vertices==null?this.vertices=a.prev=a.next=a:(a.next=this.vertices,a.prev=this.vertices.prev,this.vertices.prev.next=a,this.vertices.prev=a),o=a}if(this.vertices=o,this.vertices.forced=i.forced,i=i.next,i==e)break}this.remove_collinear_vertices()}remove_collinear_vertices(){let e=this.vertices,t=!0;for(;t||e!=this.vertices;)if(t=!1,this.eq(e,e.next)){if(e==this.vertices&&(this.vertices=e.next,t=!0),e.forced&&(e.next.forced=!0),e!=null&&e.prev==e){e.next=e.prev=null;let l=e;l.helper=null,l.next=Ge.zpp_pool,Ge.zpp_pool=l,e=null,e=null}else{let l=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let s=e;s.helper=null,s.next=Ge.zpp_pool,Ge.zpp_pool=s,e=l}if(e==null){this.vertices=null;break}}else e=e.next;if(this.vertices==null)return!0;let n;for(;;){for(n=!1,e=this.vertices,t=!0;t||e!=this.vertices;){t=!1;let l=e.prev,s=e.x-l.x,i=e.y-l.y,o=e.next.x-e.x,a=(e.next.y-e.y)*s-o*i;if(a*a>=ye().Config.epsilon*ye().Config.epsilon)e=e.next;else{if(e==this.vertices&&(this.vertices=e.next,t=!0),e!=null&&e.prev==e){e.next=e.prev=null;let p=e;p.helper=null,p.next=Ge.zpp_pool,Ge.zpp_pool=p,e=null,e=null}else{let p=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let c=e;c.helper=null,c.next=Ge.zpp_pool,Ge.zpp_pool=c,e=p}if(n=!0,e==null){n=!1,this.vertices=null;break}}}if(!n)break}return this.vertices==null}add_diagonal(e,t){e.diagonals.add(t),t.diagonals.add(e),e.forced=t.forced=!0}extract_partitions(e){if(e==null&&(e=new Qi),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let i=t;for(;i.sort(),i=i.next,i!=n;);}for(this.pull_partitions(this.vertices,e);this.vertices!=null;){let i;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let o=this.vertices;o.helper=null,o.next=Ge.zpp_pool,Ge.zpp_pool=o,i=this.vertices=null}else{let o=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let r=this.vertices;r.helper=null,r.next=Ge.zpp_pool,Ge.zpp_pool=r,this.vertices=null,i=o}this.vertices=i}let l=null,s=e.head;for(;s!=null;){if(s.elt.remove_collinear_vertices()){e.erase(l);continue}l=s,s=s.next}}return e}pull_partitions(e,t){let n;on.zpp_pool==null?n=new on:(n=on.zpp_pool,on.zpp_pool=n.next,n.next=null);let l=e;for(;;){let r;Ge.zpp_pool==null?r=new Ge:(r=Ge.zpp_pool,Ge.zpp_pool=r.next,r.next=null),r.x=l.x,r.y=l.y,r.forced=l.forced;let a=r;if(n.vertices==null?n.vertices=a.prev=a.next=a:(a.prev=n.vertices,a.next=n.vertices.next,n.vertices.next.prev=a,n.vertices.next=a),n.vertices=a,n.vertices.forced=l.forced,l.diagonals.head!=null){let p=l.diagonals,c=p.head.elt;if(p.pop(),c==e)break;l=this.pull_partitions(l,t)}else l=l.next;if(l==e)break}let s=0,i=n.vertices,o=n.vertices;if(i!=null){let r=i;for(;;){let a=r;if(s+=a.x*(a.next.y-a.prev.y),r=r.next,r==o)break}}return s*.5!=0&&t.add(n),l}extract(e){if(e==null&&(e=new Fn),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}for(this.pull(this.vertices,e);this.vertices!=null;){let l;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let s=this.vertices;s.helper=null,s.next=Ge.zpp_pool,Ge.zpp_pool=s,l=this.vertices=null}else{let s=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let i=this.vertices;i.helper=null,i.next=Ge.zpp_pool,Ge.zpp_pool=i,this.vertices=null,l=s}this.vertices=l}}return e}pull(e,t){let n=null,l=e;for(;;){let a=l.x,p=l.y,c;we.zpp_pool==null?c=new we:(c=we.zpp_pool,we.zpp_pool=c.next,c.next=null),c.forced=!1,c.x=a,c.y=p;let u=c;if(n==null?u.prev=u.next=u:(u.prev=n,u.next=n.next,n.next.prev=u,n.next=u),n=u,n.forced=l.forced,l.diagonals.head!=null){let h=l.diagonals,x=h.head.elt;if(h.pop(),x==e)break;l=this.pull(l,t)}else l=l.next;if(l==e)break}let s=0,i=n,o=n;if(i!=null){let a=i;for(;;){let p=a;if(s+=p.x*(p.next.y-p.prev.y),a=a.next,a==o)break}}let r=s*.5;if(r*r>=ye().Config.epsilon*ye().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<ye().Config.epsilon*ye().Config.epsilon){if(a==n&&(n=a.next,p=!0),a.forced&&(a.next.forced=!0),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else{let h=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=h}if(a==null){n=null;break}}else a=a.next}if(n!=null){let c;for(;;){for(c=!1,a=n,p=!0;p||a!=n;){p=!1;let u=a.prev,h=a.x-u.x,x=a.y-u.y,b=a.next.x-a.x,d=(a.next.y-a.y)*h-b*x;if(d*d>=ye().Config.epsilon*ye().Config.epsilon)a=a.next;else{if(a==n&&(n=a.next,p=!0),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else{let f=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=f}if(c=!0,a==null){c=!1,n=null;break}}}if(!c)break}}n!=null&&t.add(n)}return l}};on.__name__=["zpp_nape","geom","ZPP_PartitionedPoly"],on.zpp_pool=null,on.sharedPPList=null,on.sharedGVList=null;var Ue=on;var De=class De{static bisector(e){let t=e.prev,n=e.next,l=e.x-t.x,s=e.y-t.y,i=n.x-e.x,o=n.y-e.y,r;le.zpp_pool==null?r=new le:(r=le.zpp_pool,le.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=-s-o,r.y=l+i;let a=r,p=a.x*a.x+a.y*a.y,u=1/Math.sqrt(p);return a.x*=u,a.y*=u,o*l-i*s<0&&(a.x=-a.x,a.y=-a.y),a}static below(e,t){if(e.y<t.y)return!0;if(e.y>t.y)return!1;if(e.x<t.x)return!0;if(e.x>t.x)return!1;{let n=De.bisector(e),l=De.bisector(t),s=1;n.x+=e.x*s,n.y+=e.y*s;let i=1;l.x+=t.x*i,l.y+=t.y*i;let o=n.x<l.x||n.x==l.x&&n.y<l.y;return n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=le.zpp_pool,le.zpp_pool=n,l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l._isimmutable=null,l._validate=null,l._invalidate=null,l.next=le.zpp_pool,le.zpp_pool=l,o}}static above(e,t){return De.below(t,e)}static left_vertex(e){let t=e.prev;return t.y>e.y?!0:t.y==e.y?e.next.y<e.y:!1}static isMonotone(e){let t=e,n=e,l=e.next,s=e;if(l!=null){let r=l;for(;;){let a=r;if(a.y<t.y&&(t=a),a.y>n.y&&(n=a),r=r.next,r==s)break}}let i=!0,o=t;if(n!=t.next){let r=t.next,a=n;if(r!=null){let p=r;for(;;){let c=p;if(c.y<o.y){i=!1;break}if(o=c,p=p.next,p==a)break}}}if(!i)return!1;if(o=t,n!=t.prev){let r=t.prev,a=n;if(r!=null){let p=r;for(;;){let c=p;if(c.y<o.y){i=!1;break}if(o=c,p=p.prev,p==a)break}}}return i}static getShared(){return De.sharedPPoly==null&&(De.sharedPPoly=new Ue),De.sharedPPoly}static decompose(e,t){if(t==null?t=new Ue(e):t.init(e),t.vertices==null)return t;De.queue==null&&(De.queue=new gi);let n=t.vertices,l=t.vertices;if(n!=null){let i=n;for(;;){let o=i;De.queue.add(o);let r=o.next.x-o.x,a=o.next.y-o.y,p=o.prev.x-o.x,u=(o.prev.y-o.y)*r-p*a>0;if(o.type=De.below(o.prev,o)?De.below(o.next,o)?u?0:3:4:De.below(o,o.next)?u?1:2:4,i=i.next,i==l)break}}let s=De.queue;if(s.head!=null&&s.head.next!=null){let i=s.head,o,r,a,p,c=1,u,h,x;for(;;){for(u=0,r=i,i=null,o=i;r!=null;){for(++u,a=r,h=0,x=c;a!=null&&h<c;)++h,a=a.next;for(;h>0||x>0&&a!=null;)h==0?(p=a,a=a.next,--x):x==0||a==null||De.above(r.elt,a.elt)?(p=r,r=r.next,--h):(p=a,a=a.next,--x),o!=null?o.next=p:i=p,o=p;r=a}if(o.next=null,c<<=1,!(u>1))break}s.head=i,s.modified=!0,s.pushmod=!0}for(De.edges==null&&(bs.zpp_pool==null?De.edges=new bs:(De.edges=bs.zpp_pool,bs.zpp_pool=De.edges.next,De.edges.next=null),De.edges.lt=Ge.edge_lt,De.edges.swapped=Ge.edge_swap);De.queue.head!=null;){let i=De.queue.pop_unsafe();switch(i.type){case 0:i.helper=i,i.node=De.edges.insert(i);break;case 1:{let o=i.prev;if(o.helper==null)throw new Error("Fatal error (1): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(i,o.helper),De.edges.remove_node(o.node),o.helper=null;break}case 2:{let o=i.prev;if(o.helper==null)throw new Error("Fatal error (3): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(i,o.helper),De.edges.remove_node(o.node),o.helper=null;let r=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,i)){r=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else{for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent}}}let a=r;if(a!=null){if(a.helper==null)throw new Error("Fatal error (4): Polygon is not weakly-simple and clockwise");a.helper.type==2&&t.add_diagonal(i,a.helper),a.helper=i}break}case 3:{let o=null;if(!De.edges.empty()){let a=De.edges.parent;for(;a.prev!=null;)a=a.prev;for(;a!=null;){let p=a.data;if(!Ge.vert_lt(p,i)){o=p;break}if(a.next!=null)for(a=a.next;a.prev!=null;)a=a.prev;else{for(;a.parent!=null&&a==a.parent.next;)a=a.parent;a=a.parent}}}let r=o;if(r!=null){if(r.helper==null)throw new Error("Fatal error (2): Polygon is not weakly-simple and clockwise");t.add_diagonal(i,r.helper),r.helper=i}i.node=De.edges.insert(i),i.helper=i;break}case 4:{let o=i.prev;if(De.left_vertex(i)){if(o.helper==null)throw new Error("Fatal error (5): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(i,o.helper),De.edges.remove_node(o.node),o.helper=null,i.node=De.edges.insert(i),i.helper=i}else{let r=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,i)){r=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else{for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent}}}let a=r;if(a==null||a.helper==null)throw new Error("Fatal error (6): Polygon is not weakly-simple and clockwise");a.helper.type==2&&t.add_diagonal(i,a.helper),a.helper=i}break}}}return t}};De.__name__=["zpp_nape","geom","ZPP_Monotone"],De.queue=null,De.edges=null,De.sharedPPoly=null;var Ut=De;var Ei=class Ei{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 Ei.zpp_pool==null?n=new Ei:(n=Ei.zpp_pool,Ei.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(){}};Ei.__name__=["zpp_nape","geom","ZPP_PartitionPair"],Ei.zpp_pool=null;var Tt=Ei;var Ot=class Ot{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=ye(),t;if(xe.poolVec2==null?t=new e.geom.Vec2:(t=xe.poolVec2,xe.poolVec2=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t==xe.nextVec2&&(xe.nextVec2=null)),t.zpp_inner==null){let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=0,l.y=0,t.zpp_inner=l,t.zpp_inner.outer=t}else{if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=t.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");l._isimmutable!=null&&l._isimmutable();let s;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=t.zpp_inner;if(i._validate!=null&&i._validate(),t.zpp_inner.x==0){if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=t.zpp_inner;o._validate!=null&&o._validate(),s=t.zpp_inner.y==0}else s=!1;if(!s){t.zpp_inner.x=0,t.zpp_inner.y=0;let o=t.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}t.zpp_inner.weak=!1,this.origin=t,this.origin.zpp_inner._invalidate=l=>this.origin_invalidate(l);let n;if(xe.poolVec2==null?n=new e.geom.Vec2:(n=xe.poolVec2,xe.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==xe.nextVec2&&(xe.nextVec2=null)),n.zpp_inner==null){let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=0,l.y=0,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");l._isimmutable!=null&&l._isimmutable();let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),s=n.zpp_inner.y==0}else s=!1;if(!s){n.zpp_inner.x=0,n.zpp_inner.y=0;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.direction=n,this.direction.zpp_inner._invalidate=l=>this.direction_invalidate(l),this.originx=0,this.originy=0,this.dirx=0,this.diry=0,this.zip_dir=!1}origin_invalidate(e){this.originx=e.x,this.originy=e.y}direction_invalidate(e){this.dirx=e.x,this.diry=e.y,this.zip_dir=!0}invalidate_dir(){this.zip_dir=!0}validate_dir(){if(this.zip_dir){this.zip_dir=!1;let e=ye();if(this.dirx*this.dirx+this.diry*this.diry<e.Config.epsilon)throw new Error("Error: Ray::direction is degenerate");let t=this.dirx*this.dirx+this.diry*this.diry,n=1/Math.sqrt(t);this.dirx*=n,this.diry*=n,this.idirx=1/this.dirx,this.idiry=1/this.diry,this.normalx=-this.diry,this.normaly=this.dirx;let l=this.normalx;this.absnormalx=l<0?-l:l;let s=this.normaly;this.absnormaly=s<0?-s:s}}rayAABB(){let e=this.originx,t=e,n=this.originy,l=n;if(this.maxdist>=1/0?(this.dirx>0?t=1/0:this.dirx<0&&(t=-1/0),this.diry>0?l=1/0:this.diry<0&&(l=-1/0)):(t+=this.maxdist*this.dirx,l+=this.maxdist*this.diry),t<e){let i=e;e=t,t=i}if(l<n){let i=n;n=l,l=i}let s;return be.zpp_pool==null?s=new be:(s=be.zpp_pool,be.zpp_pool=s.next,s.next=null),s.minx=e,s.miny=n,s.maxx=t,s.maxy=l,s}aabbtest(e){let t=this.normalx*(this.originx-.5*(e.minx+e.maxx))+this.normaly*(this.originy-.5*(e.miny+e.maxy)),n=this.absnormalx*.5*(e.maxx-e.minx)+this.absnormaly*.5*(e.maxy-e.miny),l=t;return(l<0?-l:l)<n}aabbsect(e){let t=this.originx>=e.minx&&this.originx<=e.maxx,n=this.originy>=e.miny&&this.originy<=e.maxy;if(t&&n)return 0;{let l=-1;for(;!(this.dirx>=0&&this.originx>=e.maxx)&&!(this.dirx<=0&&this.originx<=e.minx||this.diry>=0&&this.originy>=e.maxy||this.diry<=0&&this.originy<=e.miny);){if(this.dirx>0){let s=(e.minx-this.originx)*this.idirx;if(s>=0&&s<=this.maxdist){let i=this.originy+s*this.diry;if(i>=e.miny&&i<=e.maxy){l=s;break}}}else if(this.dirx<0){let s=(e.maxx-this.originx)*this.idirx;if(s>=0&&s<=this.maxdist){let i=this.originy+s*this.diry;if(i>=e.miny&&i<=e.maxy){l=s;break}}}if(this.diry>0){let s=(e.miny-this.originy)*this.idiry;if(s>=0&&s<=this.maxdist){let i=this.originx+s*this.dirx;if(i>=e.minx&&i<=e.maxx){l=s;break}}}else if(this.diry<0){let s=(e.maxy-this.originy)*this.idiry;if(s>=0&&s<=this.maxdist){let i=this.originx+s*this.dirx;if(i>=e.minx&&i<=e.maxx){l=s;break}}}break}return l}}static _allocVec2(e,t){let n=ye();if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;if(xe.poolVec2==null?l=new n.geom.Vec2:(l=xe.poolVec2,xe.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==xe.nextVec2&&(xe.nextVec2=null)),l.zpp_inner==null){let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,l.zpp_inner=s,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let i;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x==e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),i=l.zpp_inner.y==t):i=!1,i||(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner._invalidate!=null&&l.zpp_inner._invalidate(l.zpp_inner))}return l.zpp_inner.weak=!1,l}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let l=1;n.localCOMx+=n.lverts.next.next.x*l,n.localCOMy+=n.lverts.next.next.y*l;let s=.5;n.localCOMx*=s,n.localCOMy*=s}else{n.localCOMx=0,n.localCOMy=0;let l=0,s=n.lverts.next,i=s;s=s.next;let o=s;for(s=s.next;s!=null;){let h=s;l+=o.x*(h.y-i.y);let x=h.y*o.x-h.x*o.y;n.localCOMx+=(o.x+h.x)*x,n.localCOMy+=(o.y+h.y)*x,i=o,o=h,s=s.next}s=n.lverts.next;let r=s;l+=o.x*(r.y-i.y);let a=r.y*o.x-r.x*o.y;n.localCOMx+=(o.x+r.x)*a,n.localCOMy+=(o.y+r.y)*a,i=o,o=r,s=s.next;let p=s;l+=o.x*(p.y-i.y);let c=p.y*o.x-p.x*o.y;n.localCOMx+=(o.x+p.x)*c,n.localCOMy+=(o.y+p.y)*c,l=1/(3*l);let u=l;n.localCOMx*=u,n.localCOMy*=u}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}_circleNormal(e,t,n){let l=this.originx+this.dirx*e,s=this.originy+this.diry*e;l-=t.worldCOMx,s-=t.worldCOMy;let i=l*l+s*s,o=1/Math.sqrt(i);return l*=o,s*=o,n&&(l=-l,s=-s),{nx:l,ny:s}}static _insertSorted(e,t){let n=null,l=e.zpp_inner.inner.head;for(;l!=null;){let o=l.elt;if(t.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(t.zpp_inner.toiDistance<o.zpp_inner.toiDistance)break;n=l,l=l.next}let s=e.zpp_inner.inner,i;ys.zpp_pool==null?i=new ys:(i=ys.zpp_pool,ys.zpp_pool=i.next,i.next=null),i.elt=t,n==null?(i.next=s.head,s.head=i):(i.next=n.next,n.next=i),s.pushmod=s.modified=!0,s.length++}circlesect(e,t,n){Ot._validateWorldCOM(e);let l=this.originx-e.worldCOMx,s=this.originy-e.worldCOMy,i=this.dirx*this.dirx+this.diry*this.diry,o=2*(l*this.dirx+s*this.diry),r=l*l+s*s-e.radius*e.radius,a=o*o-4*i*r;if(a==0){let p=-o/2*i;if((!t||r>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),u=Ot._allocVec2(c.nx,c.ny);return Pn.getRay(u,p,r<=0,e.outer)}else return null}else{a=Math.sqrt(a),i=1/(2*i);let p=(-o-a)*i,c=(-o+a)*i;if(p>0)if(p<n&&p<=this.maxdist){let u=this._circleNormal(p,e,!1),h=Ot._allocVec2(u.nx,u.ny);return Pn.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=Ot._allocVec2(u.nx,u.ny);return Pn.getRay(h,c,!0,e.outer)}else return null;else return null}}circlesect2(e,t,n){Ot._validateWorldCOM(e);let l=this.originx-e.worldCOMx,s=this.originy-e.worldCOMy,i=this.dirx*this.dirx+this.diry*this.diry,o=2*(l*this.dirx+s*this.diry),r=l*l+s*s-e.radius*e.radius,a=o*o-4*i*r;if(a==0){let p=-o/2*i;if((!t||r>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),u=Ot._allocVec2(c.nx,c.ny),h=Pn.getRay(u,p,r<=0,e.outer);Ot._insertSorted(n,h)}}else{a=Math.sqrt(a),i=1/(2*i);let p=(-o-a)*i,c=(-o+a)*i;if(p>0&&p<=this.maxdist){let u=this._circleNormal(p,e,!1),h=Ot._allocVec2(u.nx,u.ny),x=Pn.getRay(h,p,!1,e.outer);Ot._insertSorted(n,x)}if(c>0&&c<=this.maxdist&&t){let u=this._circleNormal(c,e,!0),h=Ot._allocVec2(u.nx,u.ny),x=Pn.getRay(h,c,!0,e.outer);Ot._insertSorted(n,x)}}}polysect(e,t,n){let l=ye(),s=n,i=null,o=e.edges.head,r=!0,a=e.gverts.next,p=a,c=a.next;for(;c!=null;){let u=c,h=o.elt;if(t||h.gnormx*this.dirx+h.gnormy*this.diry<0){let x=u.x-p.x,b=u.y-p.y,_=p.x-this.originx,d=p.y-this.originy,f=b*this.dirx-x*this.diry;if(f*f>l.Config.epsilon){f=1/f;let m=(b*_-x*d)*f;if(m>0&&m<s&&m<=this.maxdist){let z=(this.diry*_-this.dirx*d)*f;z>-l.Config.epsilon&&z<1+l.Config.epsilon&&(s=m,i=o.elt)}}}o=o.next,p=u,c=c.next}if(r){c=e.gverts.next;let u=c,h=o.elt;if(t||h.gnormx*this.dirx+h.gnormy*this.diry<0){let x=u.x-p.x,b=u.y-p.y,_=p.x-this.originx,d=p.y-this.originy,f=b*this.dirx-x*this.diry;if(f*f>l.Config.epsilon){f=1/f;let m=(b*_-x*d)*f;if(m>0&&m<s&&m<=this.maxdist){let z=(this.diry*_-this.dirx*d)*f;z>-l.Config.epsilon&&z<1+l.Config.epsilon&&(s=m,i=o.elt)}}}}if(i!=null){let u=i.gnormx,h=i.gnormy,x=u*this.dirx+h*this.diry>0;x&&(u=-u,h=-h);let b=Ot._allocVec2(u,h);return Pn.getRay(b,s,x,e.outer)}else return null}polysect2(e,t,n){let l=ye(),s=1/0,i=-1,o=null,r=null,a=e.edges.head,p=!0,c=e.gverts.next,u=c,h=c.next;for(;h!=null;){let x=h,b=a.elt;if(t||b.gnormx*this.dirx+b.gnormy*this.diry<0){let _=x.x-u.x,d=x.y-u.y,f=u.x-this.originx,m=u.y-this.originy,z=d*this.dirx-_*this.diry;if(z*z>l.Config.epsilon){z=1/z;let Z=(d*f-_*m)*z;if(Z>0&&Z<=this.maxdist&&(Z<s||Z>i)){let y=(this.diry*f-this.dirx*m)*z;y>-l.Config.epsilon&&y<1+l.Config.epsilon&&(Z<s&&(s=Z,o=a.elt),Z>i&&(i=Z,r=a.elt))}}}a=a.next,u=x,h=h.next}if(p){h=e.gverts.next;let x=h,b=a.elt;if(t||b.gnormx*this.dirx+b.gnormy*this.diry<0){let _=x.x-u.x,d=x.y-u.y,f=u.x-this.originx,m=u.y-this.originy,z=d*this.dirx-_*this.diry;if(z*z>l.Config.epsilon){z=1/z;let Z=(d*f-_*m)*z;if(Z>0&&Z<=this.maxdist&&(Z<s||Z>i)){let y=(this.diry*f-this.dirx*m)*z;y>-l.Config.epsilon&&y<1+l.Config.epsilon&&(Z<s&&(s=Z,o=a.elt),Z>i&&(i=Z,r=a.elt))}}}}if(o!=null){let x=o.gnormx,b=o.gnormy,_=x*this.dirx+b*this.diry>0;_&&(x=-x,b=-b);let d=Ot._allocVec2(x,b),f=Pn.getRay(d,s,_,e.outer);Ot._insertSorted(n,f)}if(r!=null&&o!=r){let x=r.gnormx,b=r.gnormy,_=x*this.dirx+b*this.diry>0;_&&(x=-x,b=-b);let d=Ot._allocVec2(x,b),f=Pn.getRay(d,i,_,e.outer);Ot._insertSorted(n,f)}}};Ot.__name__=["zpp_nape","geom","ZPP_Ray"],Ot.internal=!1;var ml=Ot;var xi=class xi{constructor(){this.forced=!1;this.x=0;this.y=0;this.links=null;this.id=0;this.next=null;this.node=null;this.id=zn.ZPP_SimpleVert(),nn.zpp_pool==null?this.links=new nn:(this.links=nn.zpp_pool,nn.zpp_pool=this.links.next,this.links.next=null),this.links.lt=xi.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 xi.zpp_pool==null?n=new xi:(n=xi.zpp_pool,xi.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(){}};xi.__name__=["zpp_nape","geom","ZPP_SimpleVert"],xi.zpp_pool=null;var ke=xi;var Ni=class Ni{constructor(){this.left=null;this.right=null;this.vertices=null;this.id=0;this.next=null;this.prev=null;this.node=null;this.id=zn.ZPP_SimpleSeg(),nn.zpp_pool==null?this.vertices=new nn:(this.vertices=nn.zpp_pool,nn.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 Ni.zpp_pool==null?n=new Ni:(n=Ni.zpp_pool,Ni.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}};Ni.__name__=["zpp_nape","geom","ZPP_SimpleSeg"],Ni.zpp_pool=null;var Lt=Ni;var Oi=class Oi{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 Oi.zpp_pool==null?t=new Oi:(t=Oi.zpp_pool,Oi.zpp_pool=t.next,t.next=null),t.vertex=e,t}free(){this.vertex=null,this.segment=this.segment2=null,this.node=null}alloc(){}};Oi.__name__=["zpp_nape","geom","ZPP_SimpleEvent"],Oi.zpp_pool=null;var Me=Oi;var Si=class{constructor(){this.sweepx=0;this.tree=null;ms.zpp_pool==null?this.tree=new ms:(this.tree=ms.zpp_pool,ms.zpp_pool=this.tree.next,this.tree.next=null),this.tree.lt=(e,t)=>this.edge_lt(e,t),this.tree.swapped=(e,t)=>this.swap_nodes(e,t)}swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}edge_lt(e,t){let n=e.left,l=e.right,s=t.left,i=t.right,o,r,a,p,c;if(e.left==t.left&&e.right==t.right)return!1;if(e.left==t.right)return n.x==l.x?n.y<l.y?n.y>s.y:l.y>s.y:(c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=s.x-n.x,p=s.y-n.y,(c?r*a-o*p:p*o-a*r)<0);if(e.right==t.left){let u;return s.x==i.x?u=s.y<i.y?s.y>n.y:i.y>n.y:(c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=n.x-s.x,p=n.y-s.y,u=(c?r*a-o*p:p*o-a*r)<0),!u}else{if(e.left==t.left)return n.x==l.x?n.y<l.y?n.y>i.y:l.y>i.y:(c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?r*a-o*p:p*o-a*r)<0);if(e.right==t.right)return n.x==l.x?n.y<l.y?n.y>s.y:l.y>s.y:(c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=s.x-n.x,p=s.y-n.y,(c?r*a-o*p:p*o-a*r)<0)}if(n.x==l.x)if(s.x==i.x){let u=n.y<l.y?l:n,h=s.y<i.y?i:s;return u.y>h.y}else{c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=n.x-s.x,p=n.y-s.y;let u=c?r*a-o*p:p*o-a*r;c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=l.x-s.x,p=l.y-s.y;let h=c?r*a-o*p:p*o-a*r;return u*h>=0?u>=0:this.sweepx>=n.x}else if(s.x==i.x){c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=s.x-n.x,p=s.y-n.y;let u=c?r*a-o*p:p*o-a*r;c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=c?r*a-o*p:p*o-a*r;return u*h>=0?u<0:this.sweepx<s.x}else{c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=s.x-n.x,p=s.y-n.y;let u=(c?r*a-o*p:p*o-a*r)<0;c=l.x<n.x,o=l.x-n.x,r=l.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=(c?r*a-o*p:p*o-a*r)<0;if(u==h)return u;{c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=n.x-s.x,p=n.y-s.y;let x=(c?r*a-o*p:p*o-a*r)>=0;c=i.x<s.x,o=i.x-s.x,r=i.y-s.y,a=l.x-s.x,p=l.y-s.y;let b=(c?r*a-o*p:p*o-a*r)>=0;if(x==b)return x;let _=(this.sweepx-n.x)/(l.x-n.x)*(l.y-n.y)+n.y,d=(this.sweepx-s.x)/(i.x-s.x)*(i.y-s.y)+s.y;return _>d}}}clear(){this.tree.clear()}add(e){e.node=this.tree.insert(e);let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);return t!=null&&(e.next=t.data,t.data.prev=e),n!=null&&(e.prev=n.data,n.data.next=e),e}remove(e){let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);t!=null&&(t.data.prev=e.prev),n!=null&&(n.data.next=e.next),this.tree.remove_node(e.node),e.node=null}intersect(e,t){if(e==null||t==null)return!1;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return!1;{let n=e.left,l=e.right,s=t.left,i=t.right,o=(s.x-n.x)*(l.y-n.y)-(l.x-n.x)*(s.y-n.y),r=(i.x-n.x)*(l.y-n.y)-(l.x-n.x)*(i.y-n.y);if(o*r>0)return!1;{let a=(n.x-s.x)*(i.y-s.y)-(i.x-s.x)*(n.y-s.y),p=(l.x-s.x)*(i.y-s.y)-(i.x-s.x)*(l.y-s.y);return!(a*p>0)}}}intersection(e,t){if(e==null||t==null)return null;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return null;{let n=e.left,l=e.right,s=t.left,i=t.right,o=l.x-n.x,r=l.y-n.y,a=i.x-s.x,p=i.y-s.y,c=p*o-a*r;if(c==0)return null;c=1/c;let u=s.x-n.x,h=s.y-n.y,x=(p*u-a*h)*c;if(x<0||x>1)return null;let b=(r*u-o*h)*c;if(b<0||b>1)return null;let _;if(b==0||b==1||x==0||x==1){let m=b==0;if(b==1&&m)throw new Error("corner case 1a");if(b==1&&(m=!0),x==0&&m)throw new Error("corner case 1b");if(x==0&&(m=!0),x==1&&m)throw new Error("corner case 1c");_=b==0?s:b==1?i:x==0?n:l}else{let m=.5*(n.x+o*x+s.x+a*b),z=.5*(n.y+r*x+s.y+p*b),Z;ke.zpp_pool==null?Z=new ke:(Z=ke.zpp_pool,ke.zpp_pool=Z.next,Z.next=null),Z.x=m,Z.y=z,_=Z}let d;Me.zpp_pool==null?d=new Me:(d=Me.zpp_pool,Me.zpp_pool=d.next,d.next=null),d.vertex=_;let f=d;return f.type=0,f.segment=e,f.segment2=t,f}}};Si.__name__=["zpp_nape","geom","ZPP_SimpleSweep"];var de=class de{static decompose(e,t){de.sweep==null&&(de.sweep=new Si,de.inthash=new Hi),de.vertices==null&&(nn.zpp_pool==null?de.vertices=new nn:(de.vertices=nn.zpp_pool,nn.zpp_pool=de.vertices.next,de.vertices.next=null),de.vertices.lt=ke.less_xy,de.vertices.swapped=ke.swap_nodes),de.queue==null&&(Yn.zpp_pool==null?de.queue=new Yn:(de.queue=Yn.zpp_pool,Yn.zpp_pool=de.queue.next,de.queue.next=null),de.queue.lt=Me.less_xy,de.queue.swapped=Me.swap_nodes);let n=null,l=null,s=e,i=e;if(s!=null){let x=s;for(;;){let b=x,_=b.x,d=b.y,f;ke.zpp_pool==null?f=new ke:(f=ke.zpp_pool,ke.zpp_pool=f.next,f.next=null),f.x=_,f.y=d;let m=f,z=de.vertices.parent;for(;z!=null;)if(de.vertices.lt(m,z.data))z=z.prev;else if(de.vertices.lt(z.data,m))z=z.next;else break;let Z=z;if(Z!=null){let y=m;y.links.clear(),y.node=null,y.forced=!1,y.next=ke.zpp_pool,ke.zpp_pool=y,m=Z.data}else m.node=de.vertices.insert(m);if(l!=null){let y;Me.zpp_pool==null?y=new Me:(y=Me.zpp_pool,Me.zpp_pool=y.next,y.next=null),y.vertex=l;let w=y,v;Me.zpp_pool==null?v=new Me:(v=Me.zpp_pool,Me.zpp_pool=v.next,v.next=null),v.vertex=m;let P=v,g;Me.less_xy(w,P)?(w.type=1,P.type=2,g=Lt.get(l,m)):(w.type=2,P.type=1,g=Lt.get(m,l)),w.segment=P.segment=g,de.queue.insert(w),de.queue.insert(P),l.links.insert(m),m.links.insert(l)}if(l=m,n==null&&(n=m),x=x.next,x==i)break}}let o;Me.zpp_pool==null?o=new Me:(o=Me.zpp_pool,Me.zpp_pool=o.next,o.next=null),o.vertex=l;let r=o,a;Me.zpp_pool==null?a=new Me:(a=Me.zpp_pool,Me.zpp_pool=a.next,a.next=null),a.vertex=n;let p=a,c;for(Me.less_xy(r,p)?(r.type=1,p.type=2,c=Lt.get(l,n)):(r.type=2,p.type=1,c=Lt.get(n,l)),r.segment=p.segment=c,de.queue.insert(r),de.queue.insert(p),l.links.insert(n),n.links.insert(l),de.ints==null&&(Yn.zpp_pool==null?de.ints=new Yn:(de.ints=Yn.zpp_pool,Yn.zpp_pool=de.ints.next,de.ints.next=null),de.ints.lt=Me.less_xy);!de.queue.empty();){let x=de.queue.pop_front();if(de.sweep.sweepx=x.vertex.x,x.type==1){let _=x.segment;if(de.sweep.add(_),_.next!=null&&_!=null&&!(_.next.id<_.id?de.inthash.has(_.next.id,_.id):de.inthash.has(_.id,_.next.id))){let d=de.sweep.intersection(_.next,_);if(d!=null)if(d.vertex.x>=de.sweep.sweepx){let f=de.queue.parent;for(;f!=null;)if(de.queue.lt(d,f.data))f=f.prev;else if(de.queue.lt(f.data,d))f=f.next;else break;let m=f;if(m==null){let z=de.ints.parent;for(;z!=null;)if(de.ints.lt(d,z.data))z=z.prev;else if(de.ints.lt(z.data,d))z=z.next;else break;let Z=z;if(Z!=null){let y=d.vertex;y.links.clear(),y.node=null,y.forced=!1,y.next=ke.zpp_pool,ke.zpp_pool=y,d.vertex=Z.data.vertex,Z.data=d,de.queue.insert(d)}else de.queue.insert(d),de.ints.insert(d);if(_.next.id<_.id){let y=de.inthash,w=_.next.id,v=_.id,P;je.zpp_pool==null?P=new je:(P=je.zpp_pool,je.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}else{let y=de.inthash,w=_.id,v=_.next.id,P;je.zpp_pool==null?P=new je:(P=je.zpp_pool,je.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}}else{let z=m.data;if(z.segment!=d.segment||d.segment2!=z.segment2)throw new Error("corner case 2, shiiiit.");let Z=d.vertex;Z.links.clear(),Z.node=null,Z.forced=!1,Z.next=ke.zpp_pool,ke.zpp_pool=Z;let y=d;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Me.zpp_pool,Me.zpp_pool=y}}else{let f=d.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f;let m=d;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Me.zpp_pool,Me.zpp_pool=m}}if(_!=null&&_.prev!=null&&!(_.id<_.prev.id?de.inthash.has(_.id,_.prev.id):de.inthash.has(_.prev.id,_.id))){let d=de.sweep.intersection(_,_.prev);if(d!=null)if(d.vertex.x>=de.sweep.sweepx){let f=de.queue.parent;for(;f!=null;)if(de.queue.lt(d,f.data))f=f.prev;else if(de.queue.lt(f.data,d))f=f.next;else break;let m=f;if(m==null){let z=de.ints.parent;for(;z!=null;)if(de.ints.lt(d,z.data))z=z.prev;else if(de.ints.lt(z.data,d))z=z.next;else break;let Z=z;if(Z!=null){let y=d.vertex;y.links.clear(),y.node=null,y.forced=!1,y.next=ke.zpp_pool,ke.zpp_pool=y,d.vertex=Z.data.vertex,Z.data=d,de.queue.insert(d)}else de.queue.insert(d),de.ints.insert(d);if(_.id<_.prev.id){let y=de.inthash,w=_.id,v=_.prev.id,P;je.zpp_pool==null?P=new je:(P=je.zpp_pool,je.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}else{let y=de.inthash,w=_.prev.id,v=_.id,P;je.zpp_pool==null?P=new je:(P=je.zpp_pool,je.zpp_pool=P.next,P.next=null),P.id=w,P.di=v;let g=P;g.value=!0,y.add(g)}}else{let z=m.data;if(z.segment!=d.segment||d.segment2!=z.segment2)throw new Error("corner case 2, shiiiit.");let Z=d.vertex;Z.links.clear(),Z.node=null,Z.forced=!1,Z.next=ke.zpp_pool,ke.zpp_pool=Z;let y=d;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Me.zpp_pool,Me.zpp_pool=y}}else{let f=d.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f;let m=d;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Me.zpp_pool,Me.zpp_pool=m}}}else if(x.type==2){let _=x.segment;if(_.node!=null){let d=_.next,f=_.prev;de.sweep.remove(_);let m=_;if(m.left=m.right=null,m.prev=null,m.node=null,m.vertices.clear(),m.next=Lt.zpp_pool,Lt.zpp_pool=m,d!=null&&f!=null&&!(d.id<f.id?de.inthash.has(d.id,f.id):de.inthash.has(f.id,d.id))){let z=de.sweep.intersection(d,f);if(z!=null)if(z.vertex.x>=de.sweep.sweepx){let Z=de.queue.parent;for(;Z!=null;)if(de.queue.lt(z,Z.data))Z=Z.prev;else if(de.queue.lt(Z.data,z))Z=Z.next;else break;let y=Z;if(y==null){let w=de.ints.parent;for(;w!=null;)if(de.ints.lt(z,w.data))w=w.prev;else if(de.ints.lt(w.data,z))w=w.next;else break;let v=w;if(v!=null){let P=z.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.zpp_pool=P,z.vertex=v.data.vertex,v.data=z,de.queue.insert(z)}else de.queue.insert(z),de.ints.insert(z);if(d.id<f.id){let P=de.inthash,g=d.id,k=f.id,N;je.zpp_pool==null?N=new je:(N=je.zpp_pool,je.zpp_pool=N.next,N.next=null),N.id=g,N.di=k;let E=N;E.value=!0,P.add(E)}else{let P=de.inthash,g=f.id,k=d.id,N;je.zpp_pool==null?N=new je:(N=je.zpp_pool,je.zpp_pool=N.next,N.next=null),N.id=g,N.di=k;let E=N;E.value=!0,P.add(E)}}else{let w=y.data;if(w.segment!=z.segment||z.segment2!=w.segment2)throw new Error("corner case 2, shiiiit.");let v=z.vertex;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v;let P=z;P.vertex=null,P.segment=P.segment2=null,P.node=null,P.next=Me.zpp_pool,Me.zpp_pool=P}}else{let Z=z.vertex;Z.links.clear(),Z.node=null,Z.forced=!1,Z.next=ke.zpp_pool,ke.zpp_pool=Z;let y=z;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Me.zpp_pool,Me.zpp_pool=y}}}}else{let _=x.vertex,d=_.node==null,f=x.segment,m=x.segment2;if(m.next!=f){let v=f;f=m,m=v}let z=f.vertices.parent;for(;z!=null;)if(f.vertices.lt(_,z.data))z=z.prev;else if(f.vertices.lt(z.data,_))z=z.next;else break;let Z=z==null,y=m.vertices.parent;for(;y!=null;)if(m.vertices.lt(_,y.data))y=y.prev;else if(m.vertices.lt(y.data,_))y=y.next;else break;let w=y==null;if(Z){let v=f.vertices.insert(_),P=_==f.left?_:f.vertices.predecessor_node(v).data,g=_==f.right?_:f.vertices.successor_node(v).data;P.links.remove(g),_!=P&&P.links.insert(_),g.links.remove(P),_!=g&&g.links.insert(_),_!=P&&_.links.insert(P),_!=g&&_.links.insert(g)}if(w){let v=m.vertices.insert(_),P=_==m.left?_:m.vertices.predecessor_node(v).data,g=_==m.right?_:m.vertices.successor_node(v).data;P.links.remove(g),_!=P&&P.links.insert(_),g.links.remove(P),_!=g&&g.links.insert(_),_!=P&&_.links.insert(P),_!=g&&_.links.insert(g)}if(d&&(_.node=de.vertices.insert(_)),_.forced=!0,d){let v=f.node,P=m.node;v.data=m,P.data=f,f.node=P,m.node=v,m.next=f.next,f.next=m,f.prev=m.prev,m.prev=f,f.prev!=null&&(f.prev.next=f),m.next!=null&&(m.next.prev=m)}if(m.next!=null&&m!=null&&!(m.next.id<m.id?de.inthash.has(m.next.id,m.id):de.inthash.has(m.id,m.next.id))){let v=de.sweep.intersection(m.next,m);if(v!=null)if(v.vertex.x>=de.sweep.sweepx){let P=de.queue.parent;for(;P!=null;)if(de.queue.lt(v,P.data))P=P.prev;else if(de.queue.lt(P.data,v))P=P.next;else break;let g=P;if(g==null){let k=de.ints.parent;for(;k!=null;)if(de.ints.lt(v,k.data))k=k.prev;else if(de.ints.lt(k.data,v))k=k.next;else break;let N=k;if(N!=null){let E=v.vertex;E.links.clear(),E.node=null,E.forced=!1,E.next=ke.zpp_pool,ke.zpp_pool=E,v.vertex=N.data.vertex,N.data=v,de.queue.insert(v)}else de.queue.insert(v),de.ints.insert(v);if(m.next.id<m.id){let E=de.inthash,M=m.next.id,C=m.id,L;je.zpp_pool==null?L=new je:(L=je.zpp_pool,je.zpp_pool=L.next,L.next=null),L.id=M,L.di=C;let O=L;O.value=!0,E.add(O)}else{let E=de.inthash,M=m.id,C=m.next.id,L;je.zpp_pool==null?L=new je:(L=je.zpp_pool,je.zpp_pool=L.next,L.next=null),L.id=M,L.di=C;let O=L;O.value=!0,E.add(O)}}else{let k=g.data;if(k.segment!=v.segment||v.segment2!=k.segment2)throw new Error("corner case 2, shiiiit.");let N=v.vertex;N.links.clear(),N.node=null,N.forced=!1,N.next=ke.zpp_pool,ke.zpp_pool=N;let E=v;E.vertex=null,E.segment=E.segment2=null,E.node=null,E.next=Me.zpp_pool,Me.zpp_pool=E}}else{let P=v.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.zpp_pool=P;let g=v;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Me.zpp_pool,Me.zpp_pool=g}}if(f!=null&&f.prev!=null&&!(f.id<f.prev.id?de.inthash.has(f.id,f.prev.id):de.inthash.has(f.prev.id,f.id))){let v=de.sweep.intersection(f,f.prev);if(v!=null)if(v.vertex.x>=de.sweep.sweepx){let P=de.queue.parent;for(;P!=null;)if(de.queue.lt(v,P.data))P=P.prev;else if(de.queue.lt(P.data,v))P=P.next;else break;let g=P;if(g==null){let k=de.ints.parent;for(;k!=null;)if(de.ints.lt(v,k.data))k=k.prev;else if(de.ints.lt(k.data,v))k=k.next;else break;let N=k;if(N!=null){let E=v.vertex;E.links.clear(),E.node=null,E.forced=!1,E.next=ke.zpp_pool,ke.zpp_pool=E,v.vertex=N.data.vertex,N.data=v,de.queue.insert(v)}else de.queue.insert(v),de.ints.insert(v);if(f.id<f.prev.id){let E=de.inthash,M=f.id,C=f.prev.id,L;je.zpp_pool==null?L=new je:(L=je.zpp_pool,je.zpp_pool=L.next,L.next=null),L.id=M,L.di=C;let O=L;O.value=!0,E.add(O)}else{let E=de.inthash,M=f.prev.id,C=f.id,L;je.zpp_pool==null?L=new je:(L=je.zpp_pool,je.zpp_pool=L.next,L.next=null),L.id=M,L.di=C;let O=L;O.value=!0,E.add(O)}}else{let k=g.data;if(k.segment!=v.segment||v.segment2!=k.segment2)throw new Error("corner case 2, shiiiit.");let N=v.vertex;N.links.clear(),N.node=null,N.forced=!1,N.next=ke.zpp_pool,ke.zpp_pool=N;let E=v;E.vertex=null,E.segment=E.segment2=null,E.node=null,E.next=Me.zpp_pool,Me.zpp_pool=E}}else{let P=v.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.zpp_pool=P;let g=v;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Me.zpp_pool,Me.zpp_pool=g}}de.ints.remove(x)}let b=x;b.vertex=null,b.segment=b.segment2=null,b.node=null,b.next=Me.zpp_pool,Me.zpp_pool=b}let u=0,h=de.inthash.table.length;for(;u<h;){let x=u++,b=de.inthash.table[x];if(b!=null){for(;b!=null;){let _=b.hnext;b.hnext=null;let d=b;d.next=je.zpp_pool,je.zpp_pool=d,b=_}de.inthash.table[x]=null}}for(t==null&&(t=new Fn);!de.vertices.empty();)de.clip_polygon(de.vertices,t);return t}static clip_polygon(e,t){let n=null,l=e.first(),s=l,i=l.links.parent,o=i.prev==null?i.next:i.prev,r=i.data,a=o.data,p=l.x-r.x,c=l.y-r.y,u=a.x-l.x;(a.y-l.y)*p-u*c<0&&(a=r);let x=l.x,b=l.y,_;we.zpp_pool==null?_=new we:(_=we.zpp_pool,we.zpp_pool=_.next,_.next=null),_.forced=!1,_.x=x,_.y=b;let d=_;if(n==null)d.prev=d.next=d;else{let m=n,z=m.next;d.prev=m,d.next=z,z.prev=d,m.next=d}for(n=d,n.forced=l.forced;;){if(l.links.remove(a),a.links.remove(l),a==s){if(l.links.empty()){e.remove(l);let w=l;w.links.clear(),w.node=null,w.forced=!1,w.next=ke.zpp_pool,ke.zpp_pool=w}break}let m=a.x,z=a.y,Z;we.zpp_pool==null?Z=new we:(Z=we.zpp_pool,we.zpp_pool=Z.next,Z.next=null),Z.forced=!1,Z.x=m,Z.y=z;let y=Z;if(n==null)y.prev=y.next=y;else{let w=n,v=w.next;y.prev=w,y.next=v,v.prev=y,w.next=y}if(n=y,n.forced=a.forced,a.links.singular()){if(l.links.empty()){e.remove(l);let w=l;w.links.clear(),w.node=null,w.forced=!1,w.next=ke.zpp_pool,ke.zpp_pool=w}l=a,a=a.links.parent.data}else{let w=null,v=0;if(!a.links.empty()){let P=a.links.parent;for(;P.prev!=null;)P=P.prev;for(;P!=null;){let g=P.data;if(w==null){w=g;let k=a.x-l.x,N=a.y-l.y,E=g.x-a.x;v=(g.y-a.y)*k-E*N}else{let k=a.x-l.x,N=a.y-l.y,E=g.x-a.x,C=(g.y-a.y)*k-E*N;if(C>0&&v<=0)w=g,v=C;else if(v*C>=0){let L=a.x-g.x,O=a.y-g.y,I=w.x-a.x;(w.y-a.y)*L-I*O>0&&(w=g,v=C)}}if(P.next!=null)for(P=P.next;P.prev!=null;)P=P.prev;else{for(;P.parent!=null&&P==P.parent.next;)P=P.parent;P=P.parent}}}if(l.links.empty()){e.remove(l);let P=l;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.zpp_pool=P}l=a,a=w}}e.remove(s);let f=s;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f,t.add(n)}static isSimple(e){de.sweep==null&&(de.sweep=new Si,de.inthash=new Hi);let t=de.list_vertices;t==null&&(t=de.list_vertices=new Ol);let n=e,l=e;if(n!=null){let _=n;for(;;){let d=_,f=d.x,m=d.y,z;if(ke.zpp_pool==null?z=new ke:(z=ke.zpp_pool,ke.zpp_pool=z.next,z.next=null),z.x=f,z.y=m,t.add(z),_=_.next,_==l)break}}let s=de.list_queue;s==null&&(s=de.list_queue=new Sl);let i=t.head,o=i.elt;for(i=i.next;i!=null;){let _=i.elt,d;Me.zpp_pool==null?d=new Me:(d=Me.zpp_pool,Me.zpp_pool=d.next,d.next=null),d.vertex=o;let f=s.add(d),m;Me.zpp_pool==null?m=new Me:(m=Me.zpp_pool,Me.zpp_pool=m.next,m.next=null),m.vertex=_;let z=s.add(m),Z;Me.less_xy(f,z)?(f.type=1,z.type=2,Z=Lt.get(o,_)):(f.type=2,z.type=1,Z=Lt.get(_,o)),f.segment=z.segment=Z,o=_,i=i.next}let r=t.head.elt,a;Me.zpp_pool==null?a=new Me:(a=Me.zpp_pool,Me.zpp_pool=a.next,a.next=null),a.vertex=o;let p=s.add(a),c;Me.zpp_pool==null?c=new Me:(c=Me.zpp_pool,Me.zpp_pool=c.next,c.next=null),c.vertex=r;let u=s.add(c),h;Me.less_xy(p,u)?(p.type=1,u.type=2,h=Lt.get(o,r)):(p.type=2,u.type=1,h=Lt.get(r,o)),p.segment=u.segment=h;let x=s;if(x.head!=null&&x.head.next!=null){let _=x.head,d,f,m,z,Z=1,y,w,v;for(;;){for(y=0,f=_,_=null,d=null;f!=null;){for(++y,m=f,w=0,v=Z;m!=null&&w<Z;)++w,m=m.next;for(;w>0||v>0&&m!=null;)w==0?(z=m,m=m.next,--v):v==0||m==null||Me.less_xy(f.elt,m.elt)?(z=f,f=f.next,--w):(z=m,m=m.next,--v),d!=null?d.next=z:_=z,d=z;f=m}if(d.next=null,Z<<=1,!(y>1))break}x.head=_,x.modified=!0,x.pushmod=!0}let b=!0;for(;s.head!=null;){let _=s.pop_unsafe(),d=_.segment;if(_.type==1){if(de.sweep.add(d),de.sweep.intersect(d,d.next)||de.sweep.intersect(d,d.prev)){b=!1;break}}else if(_.type==2){if(de.sweep.intersect(d.prev,d.next)){b=!1;break}de.sweep.remove(d);let m=d;m.left=m.right=null,m.prev=null,m.node=null,m.vertices.clear(),m.next=Lt.zpp_pool,Lt.zpp_pool=m}let f=_;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Me.zpp_pool,Me.zpp_pool=f}for(;s.head!=null;){let _=s.pop_unsafe();if(_.type==2){let f=_.segment;f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=Lt.zpp_pool,Lt.zpp_pool=f}let d=_;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Me.zpp_pool,Me.zpp_pool=d}for(de.sweep.clear();t.head!=null;){let _=t.pop_unsafe();_.links.clear(),_.node=null,_.forced=!1,_.next=ke.zpp_pool,ke.zpp_pool=_}return b}};de.__name__=["zpp_nape","geom","ZPP_Simple"],de.sweep=null,de.inthash=null,de.vertices=null,de.queue=null,de.ints=null,de.list_vertices=null,de.list_queue=null;var Vi=de;var Ai=class Ai{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 Ai.zpp_pool==null?t=new Ai:(t=Ai.zpp_pool,Ai.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t.flag=!1,t}free(){}alloc(){}};Ai.__name__=["zpp_nape","geom","ZPP_SimplifyV"],Ai.zpp_pool=null;var kn=Ai;var Ii=class Ii{constructor(){this.next=null;this.min=null;this.max=null}static get(e,t){let n;return Ii.zpp_pool==null?n=new Ii:(n=Ii.zpp_pool,Ii.zpp_pool=n.next,n.next=null),n.min=e,n.max=t,n}free(){this.min=null,this.max=null}alloc(){}};Ii.__name__=["zpp_nape","geom","ZPP_SimplifyP"],Ii.zpp_pool=null;var Be=Ii;var St=class St{static lessval(e,t){return e.x-t.x+(e.y-t.y)}static less(e,t){return e.x-t.x+(e.y-t.y)<0}static distance(e,t,n){let l=n.x-t.x,s=n.y-t.y,i=e.x-t.x,o=e.y-t.y;if(l*l+s*s==0)return i*i+o*o;{let a=(i*l+o*s)/(l*l+s*s);if(a<=0)return i*i+o*o;if(a>=1){let p=e.x-n.x,c=e.y-n.y;return p*p+c*c}else{let p=a;return i-=l*p,o-=s*p,i*i+o*o}}}static simplify(e,t){let n=null,l=null,s=null;t*=t,St.stack==null&&(St.stack=new Nl);let i=null,o=null,r=e;for(;;){let p;kn.zpp_pool==null?p=new kn:(p=kn.zpp_pool,kn.zpp_pool=p.next,p.next=null),p.x=r.x,p.y=r.y,p.flag=!1;let c=p;if(c.forced=r.forced,c.forced){if(c.flag=!0,i!=null){let h=St.stack,x;Be.zpp_pool==null?x=new Be:(x=Be.zpp_pool,Be.zpp_pool=x.next,x.next=null),x.min=i,x.max=c,h.add(x)}else o=c;i=c}let u=c;if(n==null?u.prev=u.next=u:(u.prev=n,u.next=n.next,n.next.prev=u,n.next=u),n=u,l==null?(l=n,s=n):(n.x-l.x+(n.y-l.y)<0&&(l=n),s.x-n.x+(s.y-n.y)<0&&(s=n)),r=r.next,r==e)break}if(St.stack.head==null)if(o==null){l.flag=s.flag=!0;let p=St.stack,c;Be.zpp_pool==null?c=new Be:(c=Be.zpp_pool,Be.zpp_pool=c.next,c.next=null),c.min=l,c.max=s,p.add(c);let u=St.stack,h;Be.zpp_pool==null?h=new Be:(h=Be.zpp_pool,Be.zpp_pool=h.next,h.next=null),h.min=s,h.max=l,u.add(h)}else{let p=l.x-o.x+(l.y-o.y);p<0&&(p=-p);let c=s.x-o.x+(s.y-o.y);if(c<0&&(c=-c),p>c){l.flag=o.flag=!0;let u=St.stack,h;Be.zpp_pool==null?h=new Be:(h=Be.zpp_pool,Be.zpp_pool=h.next,h.next=null),h.min=l,h.max=o,u.add(h);let x=St.stack,b;Be.zpp_pool==null?b=new Be:(b=Be.zpp_pool,Be.zpp_pool=b.next,b.next=null),b.min=o,b.max=l,x.add(b)}else{s.flag=o.flag=!0;let u=St.stack,h;Be.zpp_pool==null?h=new Be:(h=Be.zpp_pool,Be.zpp_pool=h.next,h.next=null),h.min=s,h.max=o,u.add(h);let x=St.stack,b;Be.zpp_pool==null?b=new Be:(b=Be.zpp_pool,Be.zpp_pool=b.next,b.next=null),b.min=o,b.max=s,x.add(b)}}else{let p=St.stack,c;Be.zpp_pool==null?c=new Be:(c=Be.zpp_pool,Be.zpp_pool=c.next,c.next=null),c.min=i,c.max=o,p.add(c)}for(;St.stack.head!=null;){let p=St.stack.pop_unsafe(),c=p.min,u=p.max,h=p;h.min=h.max=null,h.next=Be.zpp_pool,Be.zpp_pool=h;let x=t,b=null,_=c.next;for(;_!=u;){let d=St.distance(_,c,u);d>x&&(x=d,b=_),_=_.next}if(b!=null){b.flag=!0;let d=St.stack,f;Be.zpp_pool==null?f=new Be:(f=Be.zpp_pool,Be.zpp_pool=f.next,f.next=null),f.min=c,f.max=b,d.add(f);let m=St.stack,z;Be.zpp_pool==null?z=new Be:(z=Be.zpp_pool,Be.zpp_pool=z.next,z.next=null),z.min=b,z.max=u,m.add(z)}}let a=null;for(;n!=null;){if(n.flag){let p=n.x,c=n.y,u;we.zpp_pool==null?u=new we:(u=we.zpp_pool,we.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=kn.zpp_pool,kn.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=kn.zpp_pool,kn.zpp_pool=n,n=p}}return a}};St.__name__=["zpp_nape","geom","ZPP_Simplify"],St.stack=null;var Zs=St;var ks=class{constructor(){this.next=null;this.toi=0;this.s1=null;this.s2=null;this.arbiter=null;this.frozen1=!1;this.frozen2=!1;this.slipped=!1;this.failed=!1;this.kinematic=!1;this.c1=new le,this.c2=new le,this.axis=new le}alloc(){this.failed=!1,this.s1=this.s2=null,this.arbiter=null}free(){}};ks.__name__=["zpp_nape","geom","ZPP_ToiEvent"],ks.zpp_pool=null;var wn=class{static dynamicSweep(e,t,n,l,s){let i=ye();s==null&&(s=!1);let o=e.s1,r=e.s2,a=o.body,p=r.body,c=0,u=0;c=p.velx-a.velx,u=p.vely-a.vely;let h=a.angvel;h<0&&(h=-h);let x=p.angvel;x<0&&(x=-x);let b=o.sweepCoef*h+r.sweepCoef*x;if(!s&&!e.kinematic&&c*c+u*u<i.Config.dynamicSweepLinearThreshold*i.Config.dynamicSweepLinearThreshold&&b<i.Config.dynamicSweepAngularThreshold){e.toi=-1,e.failed=!0;return}let _=e.c1,d=e.c2,f=e.axis,m=n,z=0;for(;;){let C=m*t,L=C-a.sweepTime;if(L!=0){a.sweepTime=C;let X=L;if(a.posx+=a.velx*X,a.posy+=a.vely*X,a.angvel!=0){let H=a.sweep_angvel*L;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,F=1-.5*ee,D=1-ee*ee/8,B=(F*a.axisx+H*a.axisy)*D;a.axisy=(F*a.axisy-H*a.axisx)*D,a.axisx=B}}}if(o.type==0)o.worldCOMx=a.posx+(a.axisy*o.localCOMx-a.axisx*o.localCOMy),o.worldCOMy=a.posy+(o.localCOMx*a.axisx+o.localCOMy*a.axisy);else{let X=o.polygon,H=X.lverts.next,ee=X.gverts.next;for(;ee!=null;){let Q=ee,K=H;H=H.next,Q.x=a.posx+(a.axisy*K.x-a.axisx*K.y),Q.y=a.posy+(K.x*a.axisx+K.y*a.axisy),ee=ee.next}let F=X.edges.head,D=X.gverts.next,B=D;for(D=D.next;D!=null;){let Q=D,K=F.elt;F=F.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=B.y*K.gnormx-B.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,B=Q,D=D.next}let V=X.gverts.next,J=F.elt;F=F.next,J.gnormx=a.axisy*J.lnormx-a.axisx*J.lnormy,J.gnormy=J.lnormx*a.axisx+J.lnormy*a.axisy,J.gprojection=a.posx*J.gnormx+a.posy*J.gnormy+J.lprojection,J.tp0=B.y*J.gnormx-B.x*J.gnormy,J.tp1=V.y*J.gnormx-V.x*J.gnormy}let O=m*t,I=O-p.sweepTime;if(I!=0){p.sweepTime=O;let X=I;if(p.posx+=p.velx*X,p.posy+=p.vely*X,p.angvel!=0){let H=p.sweep_angvel*I;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,F=1-.5*ee,D=1-ee*ee/8,B=(F*p.axisx+H*p.axisy)*D;p.axisy=(F*p.axisy-H*p.axisx)*D,p.axisx=B}}}if(r.type==0)r.worldCOMx=p.posx+(p.axisy*r.localCOMx-p.axisx*r.localCOMy),r.worldCOMy=p.posy+(r.localCOMx*p.axisx+r.localCOMy*p.axisy);else{let X=r.polygon,H=X.lverts.next,ee=X.gverts.next;for(;ee!=null;){let Q=ee,K=H;H=H.next,Q.x=p.posx+(p.axisy*K.x-p.axisx*K.y),Q.y=p.posy+(K.x*p.axisx+K.y*p.axisy),ee=ee.next}let F=X.edges.head,D=X.gverts.next,B=D;for(D=D.next;D!=null;){let Q=D,K=F.elt;F=F.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=B.y*K.gnormx-B.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,B=Q,D=D.next}let V=X.gverts.next,J=F.elt;F=F.next,J.gnormx=p.axisy*J.lnormx-p.axisx*J.lnormy,J.gnormy=J.lnormx*p.axisx+J.lnormy*p.axisy,J.gprojection=p.posx*J.gnormx+p.posy*J.gnormy+J.lprojection,J.tp0=B.y*J.gnormx-B.x*J.gnormy,J.tp1=V.y*J.gnormx-V.x*J.gnormy}let T=o,W=r,R=_,G=d;var Z;if(T.type==0&&W.type==0){let X=T.circle,H=W.circle;var y;let ee=0,F=0;ee=H.worldCOMx-X.worldCOMx,F=H.worldCOMy-X.worldCOMy;let D=Math.sqrt(ee*ee+F*F);if(y=D-(X.radius+H.radius),y<1e100){if(D==0)ee=1,F=0;else{let J=1/D;ee*=J,F*=J}let B=X.radius;R.x=X.worldCOMx+ee*B,R.y=X.worldCOMy+F*B;let V=-H.radius;G.x=H.worldCOMx+ee*V,G.y=H.worldCOMy+F*V,f.x=ee,f.y=F}Z=y}else{let X=!1;if(T.type==0&&W.type==1){let H=T;T=W,W=H;let ee=R;R=G,G=ee,X=!0}if(T.type==1&&W.type==0){let H=T.polygon,ee=W.circle,F=-1e100,D=null,B=H.edges.head;for(;B!=null;){let V=B.elt,J=V.gnormx*ee.worldCOMx+V.gnormy*ee.worldCOMy-V.gprojection-ee.radius;if(J>1e100){F=J;break}J>0?J>F&&(F=J,D=V):F<0&&J>F&&(F=J,D=V),B=B.next}if(F<1e100){let V=D.gp0,J=D.gp1,Q=ee.worldCOMy*D.gnormx-ee.worldCOMx*D.gnormy;if(Q<=V.y*D.gnormx-V.x*D.gnormy){let K=0,ne=0;K=ee.worldCOMx-V.x,ne=ee.worldCOMy-V.y;let re=Math.sqrt(K*K+ne*ne);if(F=re-ee.radius,F<1e100){if(re==0)K=1,ne=0;else{let oe=1/re;K*=oe,ne*=oe}let se=0;R.x=V.x+K*se,R.y=V.y+ne*se;let ie=-ee.radius;G.x=ee.worldCOMx+K*ie,G.y=ee.worldCOMy+ne*ie,f.x=K,f.y=ne}}else if(Q>=J.y*D.gnormx-J.x*D.gnormy){let K=0,ne=0;K=ee.worldCOMx-J.x,ne=ee.worldCOMy-J.y;let re=Math.sqrt(K*K+ne*ne);if(F=re-ee.radius,F<1e100){if(re==0)K=1,ne=0;else{let oe=1/re;K*=oe,ne*=oe}let se=0;R.x=J.x+K*se,R.y=J.y+ne*se;let ie=-ee.radius;G.x=ee.worldCOMx+K*ie,G.y=ee.worldCOMy+ne*ie,f.x=K,f.y=ne}}else{let K=-ee.radius;G.x=ee.worldCOMx+D.gnormx*K,G.y=ee.worldCOMy+D.gnormy*K;let ne=-F;R.x=G.x+D.gnormx*ne,R.y=G.y+D.gnormy*ne,f.x=D.gnormx,f.y=D.gnormy}}X&&(f.x=-f.x,f.y=-f.y),Z=F}else{let H=T.polygon,ee=W.polygon,F=-1e100,D=null,B=null,V=0,J=H.edges.head;for(;J!=null;){let Q=J.elt,K=1e100,ne=ee.gverts.next;for(;ne!=null;){let re=ne,se=Q.gnormx*re.x+Q.gnormy*re.y;se<K&&(K=se),ne=ne.next}if(K-=Q.gprojection,K>1e100){F=K;break}K>0?K>F&&(F=K,D=Q,V=1):F<0&&K>F&&(F=K,D=Q,V=1),J=J.next}if(F<1e100){let Q=ee.edges.head;for(;Q!=null;){let K=Q.elt,ne=1e100,re=H.gverts.next;for(;re!=null;){let se=re,ie=K.gnormx*se.x+K.gnormy*se.y;ie<ne&&(ne=ie),re=re.next}if(ne-=K.gprojection,ne>1e100){F=ne;break}ne>0?ne>F&&(F=ne,B=K,V=2):F<0&&ne>F&&(F=ne,B=K,V=2),Q=Q.next}if(F<1e100){var w,v,P;if(V==1)w=H,v=ee,P=D;else{w=ee,v=H,P=B;let se=R;R=G,G=se,X=!X}let K=null,ne=1e100,re=v.edges.head;for(;re!=null;){let se=re.elt,ie=P.gnormx*se.gnormx+P.gnormy*se.gnormy;ie<ne&&(ne=ie,K=se),re=re.next}if(X?(f.x=-P.gnormx,f.y=-P.gnormy):(f.x=P.gnormx,f.y=P.gnormy),F>=0){let se=P.gp0,ie=P.gp1,oe=K.gp0,ce=K.gp1,pe=0,ae=0,_e=0,te=0;pe=ie.x-se.x,ae=ie.y-se.y,_e=ce.x-oe.x,te=ce.y-oe.y;let he=1/(pe*pe+ae*ae),me=1/(_e*_e+te*te),ue=-(pe*(se.x-oe.x)+ae*(se.y-oe.y))*he,Pe=-(pe*(se.x-ce.x)+ae*(se.y-ce.y))*he,Se=-(_e*(oe.x-se.x)+te*(oe.y-se.y))*me,Te=-(_e*(oe.x-ie.x)+te*(oe.y-ie.y))*me;ue<0?ue=0:ue>1&&(ue=1),Pe<0?Pe=0:Pe>1&&(Pe=1),Se<0?Se=0:Se>1&&(Se=1),Te<0?Te=0:Te>1&&(Te=1);let Ke=0,He=0,Qe=ue;Ke=se.x+pe*Qe,He=se.y+ae*Qe;let Fe=0,wt=0,Et=Pe;Fe=se.x+pe*Et,wt=se.y+ae*Et;let ut=0,xt=0,ht=Se;ut=oe.x+_e*ht,xt=oe.y+te*ht;let Ye=0,vt=0,Gt=Te;Ye=oe.x+_e*Gt,vt=oe.y+te*Gt;let Kt=0,It=0;Kt=Ke-oe.x,It=He-oe.y;let jt=Kt*Kt+It*It,vn=0,Qt=0;vn=Fe-ce.x,Qt=wt-ce.y;let mn=vn*vn+Qt*Qt,hn=0,bn=0;hn=ut-se.x,bn=xt-se.y;let $t=hn*hn+bn*bn,gn=0,en=0;gn=Ye-ie.x,en=vt-ie.y;let fn=gn*gn+en*en,Yt=0,tn=0,un=null;jt<mn?(Yt=Ke,tn=He,un=oe):(Yt=Fe,tn=wt,un=ce,jt=mn);let ii=0,Dn=0,jn=null;if($t<fn?(ii=ut,Dn=xt,jn=se):(ii=Ye,Dn=vt,jn=ie,$t=fn),jt<$t?(R.x=Yt,R.y=tn,G.x=un.x,G.y=un.y,F=Math.sqrt(jt)):(G.x=ii,G.y=Dn,R.x=jn.x,R.y=jn.y,F=Math.sqrt($t)),F!=0){f.x=G.x-R.x,f.y=G.y-R.y;let Bn=1/F;f.x*=Bn,f.y*=Bn,X&&(f.x=-f.x,f.y=-f.y)}Z=F}else{let se=0,ie=0;se=K.gp0.x,ie=K.gp0.y;let oe=0,ce=0;oe=K.gp1.x,ce=K.gp1.y;let pe=0,ae=0;pe=oe-se,ae=ce-ie;let _e=P.gnormy*se-P.gnormx*ie,te=P.gnormy*oe-P.gnormx*ce,he=1/(te-_e),me=(-P.tp1-_e)*he;if(me>i.Config.epsilon){let Te=me;se+=pe*Te,ie+=ae*Te}let ue=(-P.tp0-te)*he;if(ue<-i.Config.epsilon){let Te=ue;oe+=pe*Te,ce+=ae*Te}let Pe=se*P.gnormx+ie*P.gnormy-P.gprojection,Se=oe*P.gnormx+ce*P.gnormy-P.gprojection;if(Pe<Se){G.x=se,G.y=ie;let Te=-Pe;R.x=G.x+P.gnormx*Te,R.y=G.y+P.gnormy*Te,Z=Pe}else{G.x=oe,G.y=ce;let Te=-Se;R.x=G.x+P.gnormx*Te,R.y=G.y+P.gnormy*Te,Z=Se}}}else Z=1e100}else Z=1e100}}let j=Z+l,S=c*f.x+u*f.y;if(j<i.Config.distanceThresholdCCD){if(s)break;let X=0,H=0;X=_.x-a.posx,H=_.y-a.posy;let ee=0,F=0;ee=d.x-p.posx,F=d.y-p.posy;let D=S-a.sweep_angvel*(f.y*X-f.x*H)+p.sweep_angvel*(f.y*ee-f.x*F);if(D>0&&(e.slipped=!0),D<=0||j<i.Config.distanceThresholdCCD*.5)break}let q=(b-S)*t;if(q<=0){m=-1;break}let $=j/q;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 re=a.sweep_angvel*H;if(a.rot+=re,re*re>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let se=re*re,ie=1-.5*se,oe=1-se*se/8,ce=(ie*a.axisx+re*a.axisy)*oe;a.axisy=(ie*a.axisy-re*a.axisx)*oe,a.axisx=ce}}}if(o.type==0)o.worldCOMx=a.posx+(a.axisy*o.localCOMx-a.axisx*o.localCOMy),o.worldCOMy=a.posy+(o.localCOMx*a.axisx+o.localCOMy*a.axisy);else{let ne=o.polygon,re=ne.lverts.next,se=ne.gverts.next;for(;se!=null;){let _e=se,te=re;re=re.next,_e.x=a.posx+(a.axisy*te.x-a.axisx*te.y),_e.y=a.posy+(te.x*a.axisx+te.y*a.axisy),se=se.next}let ie=ne.edges.head,oe=ne.gverts.next,ce=oe;for(oe=oe.next;oe!=null;){let _e=oe,te=ie.elt;ie=ie.next,te.gnormx=a.axisy*te.lnormx-a.axisx*te.lnormy,te.gnormy=te.lnormx*a.axisx+te.lnormy*a.axisy,te.gprojection=a.posx*te.gnormx+a.posy*te.gnormy+te.lprojection,te.tp0=ce.y*te.gnormx-ce.x*te.gnormy,te.tp1=_e.y*te.gnormx-_e.x*te.gnormy,ce=_e,oe=oe.next}let pe=ne.gverts.next,ae=ie.elt;ie=ie.next,ae.gnormx=a.axisy*ae.lnormx-a.axisx*ae.lnormy,ae.gnormy=ae.lnormx*a.axisx+ae.lnormy*a.axisy,ae.gprojection=a.posx*ae.gnormx+a.posy*ae.gnormy+ae.lprojection,ae.tp0=ce.y*ae.gnormx-ce.x*ae.gnormy,ae.tp1=pe.y*ae.gnormx-pe.x*ae.gnormy}let ee=m*t,F=ee-p.sweepTime;if(F!=0){p.sweepTime=ee;let ne=F;if(p.posx+=p.velx*ne,p.posy+=p.vely*ne,p.angvel!=0){let re=p.sweep_angvel*F;if(p.rot+=re,re*re>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let se=re*re,ie=1-.5*se,oe=1-se*se/8,ce=(ie*p.axisx+re*p.axisy)*oe;p.axisy=(ie*p.axisy-re*p.axisx)*oe,p.axisx=ce}}}if(r.type==0)r.worldCOMx=p.posx+(p.axisy*r.localCOMx-p.axisx*r.localCOMy),r.worldCOMy=p.posy+(r.localCOMx*p.axisx+r.localCOMy*p.axisy);else{let ne=r.polygon,re=ne.lverts.next,se=ne.gverts.next;for(;se!=null;){let _e=se,te=re;re=re.next,_e.x=p.posx+(p.axisy*te.x-p.axisx*te.y),_e.y=p.posy+(te.x*p.axisx+te.y*p.axisy),se=se.next}let ie=ne.edges.head,oe=ne.gverts.next,ce=oe;for(oe=oe.next;oe!=null;){let _e=oe,te=ie.elt;ie=ie.next,te.gnormx=p.axisy*te.lnormx-p.axisx*te.lnormy,te.gnormy=te.lnormx*p.axisx+te.lnormy*p.axisy,te.gprojection=p.posx*te.gnormx+p.posy*te.gnormy+te.lprojection,te.tp0=ce.y*te.gnormx-ce.x*te.gnormy,te.tp1=_e.y*te.gnormx-_e.x*te.gnormy,ce=_e,oe=oe.next}let pe=ne.gverts.next,ae=ie.elt;ie=ie.next,ae.gnormx=p.axisy*ae.lnormx-p.axisx*ae.lnormy,ae.gnormy=ae.lnormx*p.axisx+ae.lnormy*p.axisy,ae.gprojection=p.posx*ae.gnormx+p.posy*ae.gnormy+ae.lprojection,ae.tp0=ce.y*ae.gnormx-ce.x*ae.gnormy,ae.tp1=pe.y*ae.gnormx-pe.x*ae.gnormy}let D=o,B=r,V=_,J=d;var g;if(D.type==0&&B.type==0){let ne=D.circle,re=B.circle;var k;let se=0,ie=0;se=re.worldCOMx-ne.worldCOMx,ie=re.worldCOMy-ne.worldCOMy;let oe=Math.sqrt(se*se+ie*ie);if(k=oe-(ne.radius+re.radius),k<1e100){if(oe==0)se=1,ie=0;else{let ae=1/oe;se*=ae,ie*=ae}let ce=ne.radius;V.x=ne.worldCOMx+se*ce,V.y=ne.worldCOMy+ie*ce;let pe=-re.radius;J.x=re.worldCOMx+se*pe,J.y=re.worldCOMy+ie*pe,f.x=se,f.y=ie}g=k}else{let ne=!1;if(D.type==0&&B.type==1){let re=D;D=B,B=re;let se=V;V=J,J=se,ne=!0}if(D.type==1&&B.type==0){let re=D.polygon,se=B.circle,ie=-1e100,oe=null,ce=re.edges.head;for(;ce!=null;){let pe=ce.elt,ae=pe.gnormx*se.worldCOMx+pe.gnormy*se.worldCOMy-pe.gprojection-se.radius;if(ae>1e100){ie=ae;break}ae>0?ae>ie&&(ie=ae,oe=pe):ie<0&&ae>ie&&(ie=ae,oe=pe),ce=ce.next}if(ie<1e100){let pe=oe.gp0,ae=oe.gp1,_e=se.worldCOMy*oe.gnormx-se.worldCOMx*oe.gnormy;if(_e<=pe.y*oe.gnormx-pe.x*oe.gnormy){let te=0,he=0;te=se.worldCOMx-pe.x,he=se.worldCOMy-pe.y;let me=Math.sqrt(te*te+he*he);if(ie=me-se.radius,ie<1e100){if(me==0)te=1,he=0;else{let Se=1/me;te*=Se,he*=Se}let ue=0;V.x=pe.x+te*ue,V.y=pe.y+he*ue;let Pe=-se.radius;J.x=se.worldCOMx+te*Pe,J.y=se.worldCOMy+he*Pe,f.x=te,f.y=he}}else if(_e>=ae.y*oe.gnormx-ae.x*oe.gnormy){let te=0,he=0;te=se.worldCOMx-ae.x,he=se.worldCOMy-ae.y;let me=Math.sqrt(te*te+he*he);if(ie=me-se.radius,ie<1e100){if(me==0)te=1,he=0;else{let Se=1/me;te*=Se,he*=Se}let ue=0;V.x=ae.x+te*ue,V.y=ae.y+he*ue;let Pe=-se.radius;J.x=se.worldCOMx+te*Pe,J.y=se.worldCOMy+he*Pe,f.x=te,f.y=he}}else{let te=-se.radius;J.x=se.worldCOMx+oe.gnormx*te,J.y=se.worldCOMy+oe.gnormy*te;let he=-ie;V.x=J.x+oe.gnormx*he,V.y=J.y+oe.gnormy*he,f.x=oe.gnormx,f.y=oe.gnormy}}ne&&(f.x=-f.x,f.y=-f.y),g=ie}else{let re=D.polygon,se=B.polygon,ie=-1e100,oe=null,ce=null,pe=0,ae=re.edges.head;for(;ae!=null;){let _e=ae.elt,te=1e100,he=se.gverts.next;for(;he!=null;){let me=he,ue=_e.gnormx*me.x+_e.gnormy*me.y;ue<te&&(te=ue),he=he.next}if(te-=_e.gprojection,te>1e100){ie=te;break}te>0?te>ie&&(ie=te,oe=_e,pe=1):ie<0&&te>ie&&(ie=te,oe=_e,pe=1),ae=ae.next}if(ie<1e100){let _e=se.edges.head;for(;_e!=null;){let te=_e.elt,he=1e100,me=re.gverts.next;for(;me!=null;){let ue=me,Pe=te.gnormx*ue.x+te.gnormy*ue.y;Pe<he&&(he=Pe),me=me.next}if(he-=te.gprojection,he>1e100){ie=he;break}he>0?he>ie&&(ie=he,ce=te,pe=2):ie<0&&he>ie&&(ie=he,ce=te,pe=2),_e=_e.next}if(ie<1e100){var N,E,M;if(pe==1)N=re,E=se,M=oe;else{N=se,E=re,M=ce;let ue=V;V=J,J=ue,ne=!ne}let te=null,he=1e100,me=E.edges.head;for(;me!=null;){let ue=me.elt,Pe=M.gnormx*ue.gnormx+M.gnormy*ue.gnormy;Pe<he&&(he=Pe,te=ue),me=me.next}if(ne?(f.x=-M.gnormx,f.y=-M.gnormy):(f.x=M.gnormx,f.y=M.gnormy),ie>=0){let ue=M.gp0,Pe=M.gp1,Se=te.gp0,Te=te.gp1,Ke=0,He=0,Qe=0,Fe=0;Ke=Pe.x-ue.x,He=Pe.y-ue.y,Qe=Te.x-Se.x,Fe=Te.y-Se.y;let wt=1/(Ke*Ke+He*He),Et=1/(Qe*Qe+Fe*Fe),ut=-(Ke*(ue.x-Se.x)+He*(ue.y-Se.y))*wt,xt=-(Ke*(ue.x-Te.x)+He*(ue.y-Te.y))*wt,ht=-(Qe*(Se.x-ue.x)+Fe*(Se.y-ue.y))*Et,Ye=-(Qe*(Se.x-Pe.x)+Fe*(Se.y-Pe.y))*Et;ut<0?ut=0:ut>1&&(ut=1),xt<0?xt=0:xt>1&&(xt=1),ht<0?ht=0:ht>1&&(ht=1),Ye<0?Ye=0:Ye>1&&(Ye=1);let vt=0,Gt=0,Kt=ut;vt=ue.x+Ke*Kt,Gt=ue.y+He*Kt;let It=0,jt=0,vn=xt;It=ue.x+Ke*vn,jt=ue.y+He*vn;let Qt=0,mn=0,hn=ht;Qt=Se.x+Qe*hn,mn=Se.y+Fe*hn;let bn=0,$t=0,gn=Ye;bn=Se.x+Qe*gn,$t=Se.y+Fe*gn;let en=0,fn=0;en=vt-Se.x,fn=Gt-Se.y;let Yt=en*en+fn*fn,tn=0,un=0;tn=It-Te.x,un=jt-Te.y;let ii=tn*tn+un*un,Dn=0,jn=0;Dn=Qt-ue.x,jn=mn-ue.y;let Bn=Dn*Dn+jn*jn,Ri=0,qi=0;Ri=bn-Pe.x,qi=$t-Pe.y;let Wi=Ri*Ri+qi*qi,ds=0,Zl=0,xl=null;Yt<ii?(ds=vt,Zl=Gt,xl=Se):(ds=It,Zl=jt,xl=Te,Yt=ii);let kl=0,El=0,_l=null;if(Bn<Wi?(kl=Qt,El=mn,_l=ue):(kl=bn,El=$t,_l=Pe,Bn=Wi),Yt<Bn?(V.x=ds,V.y=Zl,J.x=xl.x,J.y=xl.y,ie=Math.sqrt(Yt)):(J.x=kl,J.y=El,V.x=_l.x,V.y=_l.y,ie=Math.sqrt(Bn)),ie!=0){f.x=J.x-V.x,f.y=J.y-V.y;let $l=1/ie;f.x*=$l,f.y*=$l,ne&&(f.x=-f.x,f.y=-f.y)}g=ie}else{let ue=0,Pe=0;ue=te.gp0.x,Pe=te.gp0.y;let Se=0,Te=0;Se=te.gp1.x,Te=te.gp1.y;let Ke=0,He=0;Ke=Se-ue,He=Te-Pe;let Qe=M.gnormy*ue-M.gnormx*Pe,Fe=M.gnormy*Se-M.gnormx*Te,wt=1/(Fe-Qe),Et=(-M.tp1-Qe)*wt;if(Et>i.Config.epsilon){let Ye=Et;ue+=Ke*Ye,Pe+=He*Ye}let ut=(-M.tp0-Fe)*wt;if(ut<-i.Config.epsilon){let Ye=ut;Se+=Ke*Ye,Te+=He*Ye}let xt=ue*M.gnormx+Pe*M.gnormy-M.gprojection,ht=Se*M.gnormx+Te*M.gnormy-M.gprojection;if(xt<ht){J.x=ue,J.y=Pe;let Ye=-xt;V.x=J.x+M.gnormx*Ye,V.y=J.y+M.gnormy*Ye,g=xt}else{J.x=Se,J.y=Te;let Ye=-ht;V.x=J.x+M.gnormx*Ye,V.y=J.y+M.gnormy*Ye,g=ht}}}else g=1e100}else g=1e100}}let Q=g+l,K=c*f.x+u*f.y;if(Q<i.Config.distanceThresholdCCD){if(s)break;let ne=0,re=0;ne=_.x-a.posx,re=_.y-a.posy;let se=0,ie=0;se=d.x-p.posx,ie=d.y-p.posy;let oe=K-a.sweep_angvel*(f.y*ne-f.x*re)+p.sweep_angvel*(f.y*se-f.x*ie);if(oe>0&&(e.slipped=!0),oe<=0||Q<i.Config.distanceThresholdCCD*.5)break}m=-1;break}if(++z>=40){j>l&&(e.failed=!0);break}}e.toi=m}static staticSweep(e,t,n,l){let s=ye(),i=e.s1,o=e.s2,r=i.body,a=o.body,p=0,c=0;p=-r.velx,c=-r.vely;let u=r.sweep_angvel;u<0&&(u=-u);let h=i.sweepCoef*u,x=e.c1,b=e.c2,_=e.axis,d=n,f=0;for(;;){let E=d*t,M=E-r.sweepTime;if(M!=0){r.sweepTime=E;let j=M;if(r.posx+=r.velx*j,r.posy+=r.vely*j,r.angvel!=0){let S=r.sweep_angvel*M;if(r.rot+=S,S*S>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let q=S*S,$=1-.5*q,X=1-q*q/8,H=($*r.axisx+S*r.axisy)*X;r.axisy=($*r.axisy-S*r.axisx)*X,r.axisx=H}}}if(i.type==0)i.worldCOMx=r.posx+(r.axisy*i.localCOMx-r.axisx*i.localCOMy),i.worldCOMy=r.posy+(i.localCOMx*r.axisx+i.localCOMy*r.axisy);else{let j=i.polygon,S=j.lverts.next,q=j.gverts.next;for(;q!=null;){let D=q,B=S;S=S.next,D.x=r.posx+(r.axisy*B.x-r.axisx*B.y),D.y=r.posy+(B.x*r.axisx+B.y*r.axisy),q=q.next}let $=j.edges.head,X=j.gverts.next,H=X;for(X=X.next;X!=null;){let D=X,B=$.elt;$=$.next,B.gnormx=r.axisy*B.lnormx-r.axisx*B.lnormy,B.gnormy=B.lnormx*r.axisx+B.lnormy*r.axisy,B.gprojection=r.posx*B.gnormx+r.posy*B.gnormy+B.lprojection,B.tp0=H.y*B.gnormx-H.x*B.gnormy,B.tp1=D.y*B.gnormx-D.x*B.gnormy,H=D,X=X.next}let ee=j.gverts.next,F=$.elt;$=$.next,F.gnormx=r.axisy*F.lnormx-r.axisx*F.lnormy,F.gnormy=F.lnormx*r.axisx+F.lnormy*r.axisy,F.gprojection=r.posx*F.gnormx+r.posy*F.gnormy+F.lprojection,F.tp0=H.y*F.gnormx-H.x*F.gnormy,F.tp1=ee.y*F.gnormx-ee.x*F.gnormy}let C=i,L=o,O=x,I=b;var m;if(C.type==0&&L.type==0){let j=C.circle,S=L.circle;var z;let q=0,$=0;q=S.worldCOMx-j.worldCOMx,$=S.worldCOMy-j.worldCOMy;let X=Math.sqrt(q*q+$*$);if(z=X-(j.radius+S.radius),z<1e100){if(X==0)q=1,$=0;else{let F=1/X;q*=F,$*=F}let H=j.radius;O.x=j.worldCOMx+q*H,O.y=j.worldCOMy+$*H;let ee=-S.radius;I.x=S.worldCOMx+q*ee,I.y=S.worldCOMy+$*ee,_.x=q,_.y=$}m=z}else{let j=!1;if(C.type==0&&L.type==1){let S=C;C=L,L=S;let q=O;O=I,I=q,j=!0}if(C.type==1&&L.type==0){let S=C.polygon,q=L.circle,$=-1e100,X=null,H=S.edges.head;for(;H!=null;){let ee=H.elt,F=ee.gnormx*q.worldCOMx+ee.gnormy*q.worldCOMy-ee.gprojection-q.radius;if(F>1e100){$=F;break}F>0?F>$&&($=F,X=ee):$<0&&F>$&&($=F,X=ee),H=H.next}if($<1e100){let ee=X.gp0,F=X.gp1,D=q.worldCOMy*X.gnormx-q.worldCOMx*X.gnormy;if(D<=ee.y*X.gnormx-ee.x*X.gnormy){let B=0,V=0;B=q.worldCOMx-ee.x,V=q.worldCOMy-ee.y;let J=Math.sqrt(B*B+V*V);if($=J-q.radius,$<1e100){if(J==0)B=1,V=0;else{let ne=1/J;B*=ne,V*=ne}let Q=0;O.x=ee.x+B*Q,O.y=ee.y+V*Q;let K=-q.radius;I.x=q.worldCOMx+B*K,I.y=q.worldCOMy+V*K,_.x=B,_.y=V}}else if(D>=F.y*X.gnormx-F.x*X.gnormy){let B=0,V=0;B=q.worldCOMx-F.x,V=q.worldCOMy-F.y;let J=Math.sqrt(B*B+V*V);if($=J-q.radius,$<1e100){if(J==0)B=1,V=0;else{let ne=1/J;B*=ne,V*=ne}let Q=0;O.x=F.x+B*Q,O.y=F.y+V*Q;let K=-q.radius;I.x=q.worldCOMx+B*K,I.y=q.worldCOMy+V*K,_.x=B,_.y=V}}else{let B=-q.radius;I.x=q.worldCOMx+X.gnormx*B,I.y=q.worldCOMy+X.gnormy*B;let V=-$;O.x=I.x+X.gnormx*V,O.y=I.y+X.gnormy*V,_.x=X.gnormx,_.y=X.gnormy}}j&&(_.x=-_.x,_.y=-_.y),m=$}else{let S=C.polygon,q=L.polygon,$=-1e100,X=null,H=null,ee=0,F=S.edges.head;for(;F!=null;){let D=F.elt,B=1e100,V=q.gverts.next;for(;V!=null;){let J=V,Q=D.gnormx*J.x+D.gnormy*J.y;Q<B&&(B=Q),V=V.next}if(B-=D.gprojection,B>1e100){$=B;break}B>0?B>$&&($=B,X=D,ee=1):$<0&&B>$&&($=B,X=D,ee=1),F=F.next}if($<1e100){let D=q.edges.head;for(;D!=null;){let B=D.elt,V=1e100,J=S.gverts.next;for(;J!=null;){let Q=J,K=B.gnormx*Q.x+B.gnormy*Q.y;K<V&&(V=K),J=J.next}if(V-=B.gprojection,V>1e100){$=V;break}V>0?V>$&&($=V,H=B,ee=2):$<0&&V>$&&($=V,H=B,ee=2),D=D.next}if($<1e100){var Z,y,w;if(ee==1)Z=S,y=q,w=X;else{Z=q,y=S,w=H;let Q=O;O=I,I=Q,j=!j}let B=null,V=1e100,J=y.edges.head;for(;J!=null;){let Q=J.elt,K=w.gnormx*Q.gnormx+w.gnormy*Q.gnormy;K<V&&(V=K,B=Q),J=J.next}if(j?(_.x=-w.gnormx,_.y=-w.gnormy):(_.x=w.gnormx,_.y=w.gnormy),$>=0){let Q=w.gp0,K=w.gp1,ne=B.gp0,re=B.gp1,se=0,ie=0,oe=0,ce=0;se=K.x-Q.x,ie=K.y-Q.y,oe=re.x-ne.x,ce=re.y-ne.y;let pe=1/(se*se+ie*ie),ae=1/(oe*oe+ce*ce),_e=-(se*(Q.x-ne.x)+ie*(Q.y-ne.y))*pe,te=-(se*(Q.x-re.x)+ie*(Q.y-re.y))*pe,he=-(oe*(ne.x-Q.x)+ce*(ne.y-Q.y))*ae,me=-(oe*(ne.x-K.x)+ce*(ne.y-K.y))*ae;_e<0?_e=0:_e>1&&(_e=1),te<0?te=0:te>1&&(te=1),he<0?he=0:he>1&&(he=1),me<0?me=0:me>1&&(me=1);let ue=0,Pe=0,Se=_e;ue=Q.x+se*Se,Pe=Q.y+ie*Se;let Te=0,Ke=0,He=te;Te=Q.x+se*He,Ke=Q.y+ie*He;let Qe=0,Fe=0,wt=he;Qe=ne.x+oe*wt,Fe=ne.y+ce*wt;let Et=0,ut=0,xt=me;Et=ne.x+oe*xt,ut=ne.y+ce*xt;let ht=0,Ye=0;ht=ue-ne.x,Ye=Pe-ne.y;let vt=ht*ht+Ye*Ye,Gt=0,Kt=0;Gt=Te-re.x,Kt=Ke-re.y;let It=Gt*Gt+Kt*Kt,jt=0,vn=0;jt=Qe-Q.x,vn=Fe-Q.y;let Qt=jt*jt+vn*vn,mn=0,hn=0;mn=Et-K.x,hn=ut-K.y;let bn=mn*mn+hn*hn,$t=0,gn=0,en=null;vt<It?($t=ue,gn=Pe,en=ne):($t=Te,gn=Ke,en=re,vt=It);let fn=0,Yt=0,tn=null;if(Qt<bn?(fn=Qe,Yt=Fe,tn=Q):(fn=Et,Yt=ut,tn=K,Qt=bn),vt<Qt?(O.x=$t,O.y=gn,I.x=en.x,I.y=en.y,$=Math.sqrt(vt)):(I.x=fn,I.y=Yt,O.x=tn.x,O.y=tn.y,$=Math.sqrt(Qt)),$!=0){_.x=I.x-O.x,_.y=I.y-O.y;let un=1/$;_.x*=un,_.y*=un,j&&(_.x=-_.x,_.y=-_.y)}m=$}else{let Q=0,K=0;Q=B.gp0.x,K=B.gp0.y;let ne=0,re=0;ne=B.gp1.x,re=B.gp1.y;let se=0,ie=0;se=ne-Q,ie=re-K;let oe=w.gnormy*Q-w.gnormx*K,ce=w.gnormy*ne-w.gnormx*re,pe=1/(ce-oe),ae=(-w.tp1-oe)*pe;if(ae>s.Config.epsilon){let me=ae;Q+=se*me,K+=ie*me}let _e=(-w.tp0-ce)*pe;if(_e<-s.Config.epsilon){let me=_e;ne+=se*me,re+=ie*me}let te=Q*w.gnormx+K*w.gnormy-w.gprojection,he=ne*w.gnormx+re*w.gnormy-w.gprojection;if(te<he){I.x=Q,I.y=K;let me=-te;O.x=I.x+w.gnormx*me,O.y=I.y+w.gnormy*me,m=te}else{I.x=ne,I.y=re;let me=-he;O.x=I.x+w.gnormx*me,O.y=I.y+w.gnormy*me,m=he}}}else m=1e100}else m=1e100}}let T=m+l,W=p*_.x+c*_.y;if(T<s.Config.distanceThresholdCCD){let j=0,S=0;j=x.x-r.posx,S=x.y-r.posy;let q=W-r.sweep_angvel*(_.y*j-_.x*S);if(q>0&&(e.slipped=!0),q<=0||T<s.Config.distanceThresholdCCD*.5)break}let R=(h-W)*t;if(R<=0){d=-1;break}let G=T/R;if(G<1e-6&&(G=1e-6),d+=G,d>=1){d=1;let j=d*t,S=j-r.sweepTime;if(S!=0){r.sweepTime=j;let D=S;if(r.posx+=r.velx*D,r.posy+=r.vely*D,r.angvel!=0){let B=r.sweep_angvel*S;if(r.rot+=B,B*B>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let V=B*B,J=1-.5*V,Q=1-V*V/8,K=(J*r.axisx+B*r.axisy)*Q;r.axisy=(J*r.axisy-B*r.axisx)*Q,r.axisx=K}}}if(i.type==0)i.worldCOMx=r.posx+(r.axisy*i.localCOMx-r.axisx*i.localCOMy),i.worldCOMy=r.posy+(i.localCOMx*r.axisx+i.localCOMy*r.axisy);else{let D=i.polygon,B=D.lverts.next,V=D.gverts.next;for(;V!=null;){let se=V,ie=B;B=B.next,se.x=r.posx+(r.axisy*ie.x-r.axisx*ie.y),se.y=r.posy+(ie.x*r.axisx+ie.y*r.axisy),V=V.next}let J=D.edges.head,Q=D.gverts.next,K=Q;for(Q=Q.next;Q!=null;){let se=Q,ie=J.elt;J=J.next,ie.gnormx=r.axisy*ie.lnormx-r.axisx*ie.lnormy,ie.gnormy=ie.lnormx*r.axisx+ie.lnormy*r.axisy,ie.gprojection=r.posx*ie.gnormx+r.posy*ie.gnormy+ie.lprojection,ie.tp0=K.y*ie.gnormx-K.x*ie.gnormy,ie.tp1=se.y*ie.gnormx-se.x*ie.gnormy,K=se,Q=Q.next}let ne=D.gverts.next,re=J.elt;J=J.next,re.gnormx=r.axisy*re.lnormx-r.axisx*re.lnormy,re.gnormy=re.lnormx*r.axisx+re.lnormy*r.axisy,re.gprojection=r.posx*re.gnormx+r.posy*re.gnormy+re.lprojection,re.tp0=K.y*re.gnormx-K.x*re.gnormy,re.tp1=ne.y*re.gnormx-ne.x*re.gnormy}let q=i,$=o,X=x,H=b;var v;if(q.type==0&&$.type==0){let D=q.circle,B=$.circle;var P;let V=0,J=0;V=B.worldCOMx-D.worldCOMx,J=B.worldCOMy-D.worldCOMy;let Q=Math.sqrt(V*V+J*J);if(P=Q-(D.radius+B.radius),P<1e100){if(Q==0)V=1,J=0;else{let re=1/Q;V*=re,J*=re}let K=D.radius;X.x=D.worldCOMx+V*K,X.y=D.worldCOMy+J*K;let ne=-B.radius;H.x=B.worldCOMx+V*ne,H.y=B.worldCOMy+J*ne,_.x=V,_.y=J}v=P}else{let D=!1;if(q.type==0&&$.type==1){let B=q;q=$,$=B;let V=X;X=H,H=V,D=!0}if(q.type==1&&$.type==0){let B=q.polygon,V=$.circle,J=-1e100,Q=null,K=B.edges.head;for(;K!=null;){let ne=K.elt,re=ne.gnormx*V.worldCOMx+ne.gnormy*V.worldCOMy-ne.gprojection-V.radius;if(re>1e100){J=re;break}re>0?re>J&&(J=re,Q=ne):J<0&&re>J&&(J=re,Q=ne),K=K.next}if(J<1e100){let ne=Q.gp0,re=Q.gp1,se=V.worldCOMy*Q.gnormx-V.worldCOMx*Q.gnormy;if(se<=ne.y*Q.gnormx-ne.x*Q.gnormy){let ie=0,oe=0;ie=V.worldCOMx-ne.x,oe=V.worldCOMy-ne.y;let ce=Math.sqrt(ie*ie+oe*oe);if(J=ce-V.radius,J<1e100){if(ce==0)ie=1,oe=0;else{let _e=1/ce;ie*=_e,oe*=_e}let pe=0;X.x=ne.x+ie*pe,X.y=ne.y+oe*pe;let ae=-V.radius;H.x=V.worldCOMx+ie*ae,H.y=V.worldCOMy+oe*ae,_.x=ie,_.y=oe}}else if(se>=re.y*Q.gnormx-re.x*Q.gnormy){let ie=0,oe=0;ie=V.worldCOMx-re.x,oe=V.worldCOMy-re.y;let ce=Math.sqrt(ie*ie+oe*oe);if(J=ce-V.radius,J<1e100){if(ce==0)ie=1,oe=0;else{let _e=1/ce;ie*=_e,oe*=_e}let pe=0;X.x=re.x+ie*pe,X.y=re.y+oe*pe;let ae=-V.radius;H.x=V.worldCOMx+ie*ae,H.y=V.worldCOMy+oe*ae,_.x=ie,_.y=oe}}else{let ie=-V.radius;H.x=V.worldCOMx+Q.gnormx*ie,H.y=V.worldCOMy+Q.gnormy*ie;let oe=-J;X.x=H.x+Q.gnormx*oe,X.y=H.y+Q.gnormy*oe,_.x=Q.gnormx,_.y=Q.gnormy}}D&&(_.x=-_.x,_.y=-_.y),v=J}else{let B=q.polygon,V=$.polygon,J=-1e100,Q=null,K=null,ne=0,re=B.edges.head;for(;re!=null;){let se=re.elt,ie=1e100,oe=V.gverts.next;for(;oe!=null;){let ce=oe,pe=se.gnormx*ce.x+se.gnormy*ce.y;pe<ie&&(ie=pe),oe=oe.next}if(ie-=se.gprojection,ie>1e100){J=ie;break}ie>0?ie>J&&(J=ie,Q=se,ne=1):J<0&&ie>J&&(J=ie,Q=se,ne=1),re=re.next}if(J<1e100){let se=V.edges.head;for(;se!=null;){let ie=se.elt,oe=1e100,ce=B.gverts.next;for(;ce!=null;){let pe=ce,ae=ie.gnormx*pe.x+ie.gnormy*pe.y;ae<oe&&(oe=ae),ce=ce.next}if(oe-=ie.gprojection,oe>1e100){J=oe;break}oe>0?oe>J&&(J=oe,K=ie,ne=2):J<0&&oe>J&&(J=oe,K=ie,ne=2),se=se.next}if(J<1e100){var g,k,N;if(ne==1)g=B,k=V,N=Q;else{g=V,k=B,N=K;let pe=X;X=H,H=pe,D=!D}let ie=null,oe=1e100,ce=k.edges.head;for(;ce!=null;){let pe=ce.elt,ae=N.gnormx*pe.gnormx+N.gnormy*pe.gnormy;ae<oe&&(oe=ae,ie=pe),ce=ce.next}if(D?(_.x=-N.gnormx,_.y=-N.gnormy):(_.x=N.gnormx,_.y=N.gnormy),J>=0){let pe=N.gp0,ae=N.gp1,_e=ie.gp0,te=ie.gp1,he=0,me=0,ue=0,Pe=0;he=ae.x-pe.x,me=ae.y-pe.y,ue=te.x-_e.x,Pe=te.y-_e.y;let Se=1/(he*he+me*me),Te=1/(ue*ue+Pe*Pe),Ke=-(he*(pe.x-_e.x)+me*(pe.y-_e.y))*Se,He=-(he*(pe.x-te.x)+me*(pe.y-te.y))*Se,Qe=-(ue*(_e.x-pe.x)+Pe*(_e.y-pe.y))*Te,Fe=-(ue*(_e.x-ae.x)+Pe*(_e.y-ae.y))*Te;Ke<0?Ke=0:Ke>1&&(Ke=1),He<0?He=0:He>1&&(He=1),Qe<0?Qe=0:Qe>1&&(Qe=1),Fe<0?Fe=0:Fe>1&&(Fe=1);let wt=0,Et=0,ut=Ke;wt=pe.x+he*ut,Et=pe.y+me*ut;let xt=0,ht=0,Ye=He;xt=pe.x+he*Ye,ht=pe.y+me*Ye;let vt=0,Gt=0,Kt=Qe;vt=_e.x+ue*Kt,Gt=_e.y+Pe*Kt;let It=0,jt=0,vn=Fe;It=_e.x+ue*vn,jt=_e.y+Pe*vn;let Qt=0,mn=0;Qt=wt-_e.x,mn=Et-_e.y;let hn=Qt*Qt+mn*mn,bn=0,$t=0;bn=xt-te.x,$t=ht-te.y;let gn=bn*bn+$t*$t,en=0,fn=0;en=vt-pe.x,fn=Gt-pe.y;let Yt=en*en+fn*fn,tn=0,un=0;tn=It-ae.x,un=jt-ae.y;let ii=tn*tn+un*un,Dn=0,jn=0,Bn=null;hn<gn?(Dn=wt,jn=Et,Bn=_e):(Dn=xt,jn=ht,Bn=te,hn=gn);let Ri=0,qi=0,Wi=null;if(Yt<ii?(Ri=vt,qi=Gt,Wi=pe):(Ri=It,qi=jt,Wi=ae,Yt=ii),hn<Yt?(X.x=Dn,X.y=jn,H.x=Bn.x,H.y=Bn.y,J=Math.sqrt(hn)):(H.x=Ri,H.y=qi,X.x=Wi.x,X.y=Wi.y,J=Math.sqrt(Yt)),J!=0){_.x=H.x-X.x,_.y=H.y-X.y;let ds=1/J;_.x*=ds,_.y*=ds,D&&(_.x=-_.x,_.y=-_.y)}v=J}else{let pe=0,ae=0;pe=ie.gp0.x,ae=ie.gp0.y;let _e=0,te=0;_e=ie.gp1.x,te=ie.gp1.y;let he=0,me=0;he=_e-pe,me=te-ae;let ue=N.gnormy*pe-N.gnormx*ae,Pe=N.gnormy*_e-N.gnormx*te,Se=1/(Pe-ue),Te=(-N.tp1-ue)*Se;if(Te>s.Config.epsilon){let Fe=Te;pe+=he*Fe,ae+=me*Fe}let Ke=(-N.tp0-Pe)*Se;if(Ke<-s.Config.epsilon){let Fe=Ke;_e+=he*Fe,te+=me*Fe}let He=pe*N.gnormx+ae*N.gnormy-N.gprojection,Qe=_e*N.gnormx+te*N.gnormy-N.gprojection;if(He<Qe){H.x=pe,H.y=ae;let Fe=-He;X.x=H.x+N.gnormx*Fe,X.y=H.y+N.gnormy*Fe,v=He}else{H.x=_e,H.y=te;let Fe=-Qe;X.x=H.x+N.gnormx*Fe,X.y=H.y+N.gnormy*Fe,v=Qe}}}else v=1e100}else v=1e100}}let ee=v+l,F=p*_.x+c*_.y;if(ee<s.Config.distanceThresholdCCD){let D=0,B=0;D=x.x-r.posx,B=x.y-r.posy;let V=F-r.sweep_angvel*(_.y*D-_.x*B);if(V>0&&(e.slipped=!0),V<=0||ee<s.Config.distanceThresholdCCD*.5)break}d=-1;break}if(++f>=40){T>l&&(e.failed=!0);break}}e.toi=d}static distanceBody(e,t,n,l){let s=ye(),i;le.zpp_pool==null?i=new le:(i=le.zpp_pool,le.zpp_pool=i.next,i.next=null),i.weak=!1;let o;le.zpp_pool==null?o=new le:(o=le.zpp_pool,le.zpp_pool=o.next,o.next=null),o.weak=!1;let r;le.zpp_pool==null?r=new le:(r=le.zpp_pool,le.zpp_pool=r.next,r.next=null),r.weak=!1;let a=1e100,p=e.shapes.head;for(;p!=null;){let m=p.elt,z=t.shapes.head;for(;z!=null;){let Z=z.elt,y=m,w=Z,v=i,P=o,g=a;g==null&&(g=1e100);var c;if(y.type==0&&w.type==0){let k=y.circle,N=w.circle;var u;let E=0,M=0;E=N.worldCOMx-k.worldCOMx,M=N.worldCOMy-k.worldCOMy;let C=Math.sqrt(E*E+M*M);if(u=C-(k.radius+N.radius),u<g){if(C==0)E=1,M=0;else{let I=1/C;E*=I,M*=I}let L=k.radius;v.x=k.worldCOMx+E*L,v.y=k.worldCOMy+M*L;let O=-N.radius;P.x=N.worldCOMx+E*O,P.y=N.worldCOMy+M*O,r.x=E,r.y=M}c=u}else{let k=!1;if(y.type==0&&w.type==1){let N=y;y=w,w=N;let E=v;v=P,P=E,k=!0}if(y.type==1&&w.type==0){let N=y.polygon,E=w.circle,M=-1e100,C=null,L=N.edges.head;for(;L!=null;){let O=L.elt,I=O.gnormx*E.worldCOMx+O.gnormy*E.worldCOMy-O.gprojection-E.radius;if(I>g){M=I;break}I>0?I>M&&(M=I,C=O):M<0&&I>M&&(M=I,C=O),L=L.next}if(M<g){let O=C.gp0,I=C.gp1,T=E.worldCOMy*C.gnormx-E.worldCOMx*C.gnormy;if(T<=O.y*C.gnormx-O.x*C.gnormy){let W=0,R=0;W=E.worldCOMx-O.x,R=E.worldCOMy-O.y;let G=Math.sqrt(W*W+R*R);if(M=G-E.radius,M<g){if(G==0)W=1,R=0;else{let q=1/G;W*=q,R*=q}let j=0;v.x=O.x+W*j,v.y=O.y+R*j;let S=-E.radius;P.x=E.worldCOMx+W*S,P.y=E.worldCOMy+R*S,r.x=W,r.y=R}}else if(T>=I.y*C.gnormx-I.x*C.gnormy){let W=0,R=0;W=E.worldCOMx-I.x,R=E.worldCOMy-I.y;let G=Math.sqrt(W*W+R*R);if(M=G-E.radius,M<g){if(G==0)W=1,R=0;else{let q=1/G;W*=q,R*=q}let j=0;v.x=I.x+W*j,v.y=I.y+R*j;let S=-E.radius;P.x=E.worldCOMx+W*S,P.y=E.worldCOMy+R*S,r.x=W,r.y=R}}else{let W=-E.radius;P.x=E.worldCOMx+C.gnormx*W,P.y=E.worldCOMy+C.gnormy*W;let R=-M;v.x=P.x+C.gnormx*R,v.y=P.y+C.gnormy*R,r.x=C.gnormx,r.y=C.gnormy}}k&&(r.x=-r.x,r.y=-r.y),c=M}else{let N=y.polygon,E=w.polygon,M=-1e100,C=null,L=null,O=0,I=N.edges.head;for(;I!=null;){let T=I.elt,W=1e100,R=E.gverts.next;for(;R!=null;){let G=R,j=T.gnormx*G.x+T.gnormy*G.y;j<W&&(W=j),R=R.next}if(W-=T.gprojection,W>g){M=W;break}W>0?W>M&&(M=W,C=T,O=1):M<0&&W>M&&(M=W,C=T,O=1),I=I.next}if(M<g){let T=E.edges.head;for(;T!=null;){let W=T.elt,R=1e100,G=N.gverts.next;for(;G!=null;){let j=G,S=W.gnormx*j.x+W.gnormy*j.y;S<R&&(R=S),G=G.next}if(R-=W.gprojection,R>g){M=R;break}R>0?R>M&&(M=R,L=W,O=2):M<0&&R>M&&(M=R,L=W,O=2),T=T.next}if(M<g){var h,x,b;if(O==1)h=N,x=E,b=C;else{h=E,x=N,b=L;let j=v;v=P,P=j,k=!k}let W=null,R=1e100,G=x.edges.head;for(;G!=null;){let j=G.elt,S=b.gnormx*j.gnormx+b.gnormy*j.gnormy;S<R&&(R=S,W=j),G=G.next}if(k?(r.x=-b.gnormx,r.y=-b.gnormy):(r.x=b.gnormx,r.y=b.gnormy),M>=0){let j=b.gp0,S=b.gp1,q=W.gp0,$=W.gp1,X=0,H=0,ee=0,F=0;X=S.x-j.x,H=S.y-j.y,ee=$.x-q.x,F=$.y-q.y;let D=1/(X*X+H*H),B=1/(ee*ee+F*F),V=-(X*(j.x-q.x)+H*(j.y-q.y))*D,J=-(X*(j.x-$.x)+H*(j.y-$.y))*D,Q=-(ee*(q.x-j.x)+F*(q.y-j.y))*B,K=-(ee*(q.x-S.x)+F*(q.y-S.y))*B;V<0?V=0:V>1&&(V=1),J<0?J=0:J>1&&(J=1),Q<0?Q=0:Q>1&&(Q=1),K<0?K=0:K>1&&(K=1);let ne=0,re=0,se=V;ne=j.x+X*se,re=j.y+H*se;let ie=0,oe=0,ce=J;ie=j.x+X*ce,oe=j.y+H*ce;let pe=0,ae=0,_e=Q;pe=q.x+ee*_e,ae=q.y+F*_e;let te=0,he=0,me=K;te=q.x+ee*me,he=q.y+F*me;let ue=0,Pe=0;ue=ne-q.x,Pe=re-q.y;let Se=ue*ue+Pe*Pe,Te=0,Ke=0;Te=ie-$.x,Ke=oe-$.y;let He=Te*Te+Ke*Ke,Qe=0,Fe=0;Qe=pe-j.x,Fe=ae-j.y;let wt=Qe*Qe+Fe*Fe,Et=0,ut=0;Et=te-S.x,ut=he-S.y;let xt=Et*Et+ut*ut,ht=0,Ye=0,vt=null;Se<He?(ht=ne,Ye=re,vt=q):(ht=ie,Ye=oe,vt=$,Se=He);let Gt=0,Kt=0,It=null;if(wt<xt?(Gt=pe,Kt=ae,It=j):(Gt=te,Kt=he,It=S,wt=xt),Se<wt?(v.x=ht,v.y=Ye,P.x=vt.x,P.y=vt.y,M=Math.sqrt(Se)):(P.x=Gt,P.y=Kt,v.x=It.x,v.y=It.y,M=Math.sqrt(wt)),M!=0){r.x=P.x-v.x,r.y=P.y-v.y;let jt=1/M;r.x*=jt,r.y*=jt,k&&(r.x=-r.x,r.y=-r.y)}c=M}else{let j=0,S=0;j=W.gp0.x,S=W.gp0.y;let q=0,$=0;q=W.gp1.x,$=W.gp1.y;let X=0,H=0;X=q-j,H=$-S;let ee=b.gnormy*j-b.gnormx*S,F=b.gnormy*q-b.gnormx*$,D=1/(F-ee),B=(-b.tp1-ee)*D;if(B>s.Config.epsilon){let K=B;j+=X*K,S+=H*K}let V=(-b.tp0-F)*D;if(V<-s.Config.epsilon){let K=V;q+=X*K,$+=H*K}let J=j*b.gnormx+S*b.gnormy-b.gprojection,Q=q*b.gnormx+$*b.gnormy-b.gprojection;if(J<Q){P.x=j,P.y=S;let K=-J;v.x=P.x+b.gnormx*K,v.y=P.y+b.gnormy*K,c=J}else{P.x=q,P.y=$;let K=-Q;v.x=P.x+b.gnormx*K,v.y=P.y+b.gnormy*K,c=Q}}}else c=g}else c=g}}c<a&&(a=c,n.x=i.x,n.y=i.y,l.x=o.x,l.y=o.y),z=z.next}p=p.next}let _=i;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=le.zpp_pool,le.zpp_pool=_;let d=o;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=le.zpp_pool,le.zpp_pool=d;let f=r;return f.outer!=null&&(f.outer.zpp_inner=null,f.outer=null),f._isimmutable=null,f._validate=null,f._invalidate=null,f.next=le.zpp_pool,le.zpp_pool=f,a}static distance(e,t,n,l,s,i){let o=ye();if(i==null&&(i=1e100),e.type==0&&t.type==0){let r=e.circle,a=t.circle,p,c=0,u=0;c=a.worldCOMx-r.worldCOMx,u=a.worldCOMy-r.worldCOMy;let h=Math.sqrt(c*c+u*u);if(p=h-(r.radius+a.radius),p<i){if(h==0)c=1,u=0;else{let _=1/h;c*=_,u*=_}let x=r.radius;n.x=r.worldCOMx+c*x,n.y=r.worldCOMy+u*x;let b=-a.radius;l.x=a.worldCOMx+c*b,l.y=a.worldCOMy+u*b,s.x=c,s.y=u}return p}else{let r=!1;if(e.type==0&&t.type==1){let a=e;e=t,t=a;let p=n;n=l,l=p,r=!0}if(e.type==1&&t.type==0){let a=e.polygon,p=t.circle,c=-1e100,u=null,h=a.edges.head;for(;h!=null;){let x=h.elt,b=x.gnormx*p.worldCOMx+x.gnormy*p.worldCOMy-x.gprojection-p.radius;if(b>i){c=b;break}b>0?b>c&&(c=b,u=x):c<0&&b>c&&(c=b,u=x),h=h.next}if(c<i){let x=u.gp0,b=u.gp1,_=p.worldCOMy*u.gnormx-p.worldCOMx*u.gnormy;if(_<=x.y*u.gnormx-x.x*u.gnormy){let d=0,f=0;d=p.worldCOMx-x.x,f=p.worldCOMy-x.y;let m=Math.sqrt(d*d+f*f);if(c=m-p.radius,c<i){if(m==0)d=1,f=0;else{let y=1/m;d*=y,f*=y}let z=0;n.x=x.x+d*z,n.y=x.y+f*z;let Z=-p.radius;l.x=p.worldCOMx+d*Z,l.y=p.worldCOMy+f*Z,s.x=d,s.y=f}}else if(_>=b.y*u.gnormx-b.x*u.gnormy){let d=0,f=0;d=p.worldCOMx-b.x,f=p.worldCOMy-b.y;let m=Math.sqrt(d*d+f*f);if(c=m-p.radius,c<i){if(m==0)d=1,f=0;else{let y=1/m;d*=y,f*=y}let z=0;n.x=b.x+d*z,n.y=b.y+f*z;let Z=-p.radius;l.x=p.worldCOMx+d*Z,l.y=p.worldCOMy+f*Z,s.x=d,s.y=f}}else{let d=-p.radius;l.x=p.worldCOMx+u.gnormx*d,l.y=p.worldCOMy+u.gnormy*d;let f=-c;n.x=l.x+u.gnormx*f,n.y=l.y+u.gnormy*f,s.x=u.gnormx,s.y=u.gnormy}}return r&&(s.x=-s.x,s.y=-s.y),c}else{let a=e.polygon,p=t.polygon,c=-1e100,u=null,h=null,x=0,b=a.edges.head;for(;b!=null;){let _=b.elt,d=1e100,f=p.gverts.next;for(;f!=null;){let m=f,z=_.gnormx*m.x+_.gnormy*m.y;z<d&&(d=z),f=f.next}if(d-=_.gprojection,d>i){c=d;break}d>0?d>c&&(c=d,u=_,x=1):c<0&&d>c&&(c=d,u=_,x=1),b=b.next}if(c<i){let _=p.edges.head;for(;_!=null;){let d=_.elt,f=1e100,m=a.gverts.next;for(;m!=null;){let z=m,Z=d.gnormx*z.x+d.gnormy*z.y;Z<f&&(f=Z),m=m.next}if(f-=d.gprojection,f>i){c=f;break}f>0?f>c&&(c=f,h=d,x=2):c<0&&f>c&&(c=f,h=d,x=2),_=_.next}if(c<i){let d,f,m;if(x==1)d=a,f=p,m=u;else{d=p,f=a,m=h;let w=n;n=l,l=w,r=!r}let z=null,Z=1e100,y=f.edges.head;for(;y!=null;){let w=y.elt,v=m.gnormx*w.gnormx+m.gnormy*w.gnormy;v<Z&&(Z=v,z=w),y=y.next}if(r?(s.x=-m.gnormx,s.y=-m.gnormy):(s.x=m.gnormx,s.y=m.gnormy),c>=0){let w=m.gp0,v=m.gp1,P=z.gp0,g=z.gp1,k=0,N=0,E=0,M=0;k=v.x-w.x,N=v.y-w.y,E=g.x-P.x,M=g.y-P.y;let C=1/(k*k+N*N),L=1/(E*E+M*M),O=-(k*(w.x-P.x)+N*(w.y-P.y))*C,I=-(k*(w.x-g.x)+N*(w.y-g.y))*C,T=-(E*(P.x-w.x)+M*(P.y-w.y))*L,W=-(E*(P.x-v.x)+M*(P.y-v.y))*L;O<0?O=0:O>1&&(O=1),I<0?I=0:I>1&&(I=1),T<0?T=0:T>1&&(T=1),W<0?W=0:W>1&&(W=1);let R=0,G=0,j=O;R=w.x+k*j,G=w.y+N*j;let S=0,q=0,$=I;S=w.x+k*$,q=w.y+N*$;let X=0,H=0,ee=T;X=P.x+E*ee,H=P.y+M*ee;let F=0,D=0,B=W;F=P.x+E*B,D=P.y+M*B;let V=0,J=0;V=R-P.x,J=G-P.y;let Q=V*V+J*J,K=0,ne=0;K=S-g.x,ne=q-g.y;let re=K*K+ne*ne,se=0,ie=0;se=X-w.x,ie=H-w.y;let oe=se*se+ie*ie,ce=0,pe=0;ce=F-v.x,pe=D-v.y;let ae=ce*ce+pe*pe,_e=0,te=0,he=null;Q<re?(_e=R,te=G,he=P):(_e=S,te=q,he=g,Q=re);let me=0,ue=0,Pe=null;if(oe<ae?(me=X,ue=H,Pe=w):(me=F,ue=D,Pe=v,oe=ae),Q<oe?(n.x=_e,n.y=te,l.x=he.x,l.y=he.y,c=Math.sqrt(Q)):(l.x=me,l.y=ue,n.x=Pe.x,n.y=Pe.y,c=Math.sqrt(oe)),c!=0){s.x=l.x-n.x,s.y=l.y-n.y;let Se=1/c;s.x*=Se,s.y*=Se,r&&(s.x=-s.x,s.y=-s.y)}return c}else{let w=0,v=0;w=z.gp0.x,v=z.gp0.y;let P=0,g=0;P=z.gp1.x,g=z.gp1.y;let k=0,N=0;k=P-w,N=g-v;let E=m.gnormy*w-m.gnormx*v,M=m.gnormy*P-m.gnormx*g,C=1/(M-E),L=(-m.tp1-E)*C;if(L>o.Config.epsilon){let W=L;w+=k*W,v+=N*W}let O=(-m.tp0-M)*C;if(O<-o.Config.epsilon){let W=O;P+=k*W,g+=N*W}let I=w*m.gnormx+v*m.gnormy-m.gprojection,T=P*m.gnormx+g*m.gnormy-m.gprojection;if(I<T){l.x=w,l.y=v;let W=-I;return n.x=l.x+m.gnormx*W,n.y=l.y+m.gnormy*W,I}else{l.x=P,l.y=g;let W=-T;return n.x=l.x+m.gnormx*W,n.y=l.y+m.gnormy*W,T}}}else return i}else return i}}}};wn.__name__=["zpp_nape","geom","ZPP_SweepDistance"];var Le=class Le{static lt(e,t){return e.y<t.y?!0:e.y==t.y?e.x<t.x:!1}static right_turn(e,t,n){let l=n.x-t.x,s=n.y-t.y,i=t.x-e.x;return(t.y-e.y)*l-i*s}static delaunay(e,t,n,l){let s=n.x-t.x,i=n.y-t.y,o=t.x-e.x,r=t.y-e.y,a,p,c;return r*s-o*i>=0?c=!0:(s=l.x-n.x,i=l.y-n.y,o=n.x-t.x,r=n.y-t.y,c=r*s-o*i>=0),c?p=!0:(s=e.x-l.x,i=e.y-l.y,o=l.x-n.x,r=l.y-n.y,p=r*s-o*i>=0),p?a=!0:(s=t.x-e.x,i=t.y-e.y,o=e.x-l.x,r=e.y-l.y,a=r*s-o*i>=0),a?!0:t.x*(n.y*l.mag-n.mag*l.y)-n.x*(t.y*l.mag-t.mag*l.y)+l.x*(t.y*n.mag-t.mag*n.y)-(e.x*(n.y*l.mag-n.mag*l.y)-n.x*(e.y*l.mag-e.mag*l.y)+l.x*(e.y*n.mag-e.mag*n.y))+(e.x*(t.y*l.mag-t.mag*l.y)-t.x*(e.y*l.mag-e.mag*l.y)+l.x*(e.y*t.mag-e.mag*t.y))-(e.x*(t.y*n.mag-t.mag*n.y)-t.x*(e.y*n.mag-e.mag*n.y)+n.x*(e.y*t.mag-e.mag*t.y))>0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let r=t;for(;;){let a=r;if(a.sort(),a.mag=a.x*a.x+a.y*a.y,r=r.next,r==n)break}}Le.edgeSet==null&&(fs.zpp_pool==null?Le.edgeSet=new fs:(Le.edgeSet=fs.zpp_pool,fs.zpp_pool=Le.edgeSet.next,Le.edgeSet.next=null),Le.edgeSet.lt=Tt.edge_lt,Le.edgeSet.swapped=Tt.edge_swap);let l;Tt.zpp_pool==null?l=new Tt:(l=Tt.zpp_pool,Tt.zpp_pool=l.next,l.next=null);let s=e.vertices,i=e.vertices;if(s!=null){let r=s;for(;;){let a=r,p=a.next;a.diagonals.reverse();let c=a.diagonals.head;for(;c!=null;){let u=c.elt;if(u.id<a.id){p=u,c=c.next;continue}let h=c.next==null?a.prev:c.next.elt;if(!Le.delaunay(a,p,u,h)){let x;Tt.zpp_pool==null?x=new Tt:(x=Tt.zpp_pool,Tt.zpp_pool=x.next,x.next=null),x.a=a,x.b=u,a.id<u.id?(x.id=a.id,x.di=u.id):(x.id=u.id,x.di=a.id);let b=x;l.add(b),b.node=Le.edgeSet.insert(b)}p=u,c=c.next}if(r=r.next,r==i)break}}for(;l.next!=null;){let r=l.pop_unsafe(),a=r.a,p=r.b,c=a.next,u=null,h=a.diagonals.head;for(;h!=null;){let b=h.elt;if(b==p){h=h.next,u=h==null?a.prev:h.elt;break}c=b,h=h.next}if(a.diagonals.remove(p),p.diagonals.remove(a),p==c.next)c.diagonals.add(u);else{let b=c.diagonals.head;for(;b!=null;){if(b.elt==p){c.diagonals.insert(b,u);break}b=b.next}}if(a==u.next)u.diagonals.add(c);else{let b=u.diagonals.head;for(;b!=null;){if(b.elt==a){u.diagonals.insert(b,c);break}b=b.next}}Le.edgeSet.remove_node(r.node);let x=r;x.a=x.b=null,x.node=null,x.next=Tt.zpp_pool,Tt.zpp_pool=x}let o=l;o.a=o.b=null,o.node=null,o.next=Tt.zpp_pool,Tt.zpp_pool=o}static triangulate(e){let t=e.vertices,n=e.vertices,l=e.vertices.next,s=e.vertices;if(l!=null){let a=l;for(;;){let p=a;if((p.y<t.y||p.y==t.y&&p.x<t.x)&&(t=p),(n.y<p.y||n.y==p.y&&n.x<p.x)&&(n=p),a=a.next,a==s)break}}Le.queue==null&&(Le.queue=new gi);let i=n.prev,o=n.next;for(Le.queue.add(n);i!=t||o!=t;)i==t||o!=t&&(i.y<o.y||i.y==o.y&&i.x<o.x)?(Le.queue.add(o),o.rightchain=!1,o=o.next):(Le.queue.add(i),i.rightchain=!0,i=i.prev);Le.queue.add(t),Le.stack==null&&(Le.stack=new gi),Le.stack.add(Le.queue.pop_unsafe());let r=Le.queue.pop_unsafe();for(Le.stack.add(r);;){let a=Le.queue.pop_unsafe();if(Le.queue.head==null)break;if(a.rightchain!=Le.stack.head.elt.rightchain){for(;;){let p=Le.stack.pop_unsafe();if(Le.stack.head==null)break;e.add_diagonal(p,a)}Le.stack.add(r)}else{let p=Le.stack.pop_unsafe();for(;Le.stack.head!=null;){let c=Le.stack.head.elt,u=a.x-p.x,h=a.y-p.y,x=p.x-c.x,_=(p.y-c.y)*u-x*h;if(a.rightchain&&_>=0||!a.rightchain&&_<=0)break;e.add_diagonal(c,a),p=c,Le.stack.pop()}Le.stack.add(p)}Le.stack.add(a),r=a}if(Le.stack.head!=null)for(Le.stack.pop();Le.stack.head!=null;){let a=Le.stack.pop_unsafe();if(Le.stack.head==null)break;e.add_diagonal(n,a)}return e}};Le.__name__=["zpp_nape","geom","ZPP_Triangular"],Le.queue=null,Le.stack=null,Le.edgeSet=null;var _i=Le;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 di=rs;var Qs=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)}};Qs.__name__=["zpp_nape","geom","ZPP_VecMath"];var yn=class yn{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;yn.initFields(this)}static initFields(e){let t=yn._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=zn.Interactor(),e.cbsets=new t.util.ZNPList_ZPP_CallbackSet,e.cbTypes=new t.util.ZNPList_ZPP_CbType}static get(e,t){let n=e.id<t.id?e.id:t.id,l=e.id<t.id?t.id:e.id,s=e.cbsets.length<t.cbsets.length?e.cbsets:t.cbsets,i=null,o=s.head;for(;o!=null;){let r=o.elt;if(r.id==n&&r.di==l){i=r;break}o=o.next}return i}static int_callback(e,t,n){let l=e.int1,s=e.int2,i,o=t.options1,r=l.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=t.options2,p=s.cbTypes;i=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else i=!1;i?(n.int1=l,n.int2=s):(n.int1=s,n.int2=l)}isShape(){return this.ishape!=null}isBody(){return this.ibody!=null}isCompound(){return this.icompound!=null}__iaddedToSpace(){this.group!=null&&this.group.interactors.add(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.add(this),e=e.next;this.alloc_cbSet()}__iremovedFromSpace(){this.group!=null&&this.group.interactors.remove(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.remove(this),e=e.next;this.dealloc_cbSet()}wake(){if(this.ishape!=null){let e=this.ishape.body;e!=null&&e.space!=null&&e.space.non_inlined_wake(e)}else this.ibody!=null?this.ibody.space!=null&&this.ibody.space.non_inlined_wake(this.ibody):this.icompound.space!=null&&this.icompound.space.wakeCompound(this.icompound)}_getSpace(){return this.ishape!=null?this.ishape.body==null?null:this.ishape.body.space:this.ibody!=null?this.ibody.space:this.icompound.space}getSpace(){return this._getSpace()}setupcbTypes(){let e=yn._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=yn._zpp;if(!this.cbTypes.has(e)){let n=this._getSpace();n!=null&&(this.dealloc_cbSet(),e.interactors.add(this));let l=null,s=this.cbTypes.head;for(;s!=null;){let a=s.elt;if(e.id<a.id)break;l=s,s=s.next}let i=this.cbTypes,o;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?o=new t.util.ZNPNode_ZPP_CbType:(o=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=o.next,o.next=null),o.elt=e;let r=o;l==null?(r.next=i.head,i.head=r):(r.next=l.next,l.next=r),i.pushmod=i.modified=!0,i.length++,n!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){let e=this._getSpace();(this.cbSet=e.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.interactors.add(this),this.cbSet.validate(),e.freshInteractorType(this))}dealloc_cbSet(){let e=this._getSpace();if(this.cbSet!=null){if(this.cbSet.interactors.remove(this),e.nullInteractorType(this),--this.cbSet.count==0){e.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=!0,t.bodylisteners.clear(),t.zip_bodylisteners=!0,t.conlisteners.clear(),t.zip_conlisteners=!0;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=Pt.zpp_pool,Pt.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=yn._nape;e.zpp_inner_i.group=this.group;let n=this.outer_i;n.zpp_inner_i.wrap_cbTypes==null&&n.zpp_inner_i.setupcbTypes();let l=n.zpp_inner_i.wrap_cbTypes;l.zpp_inner.valmod();let s=t.callbacks.CbTypeIterator.get(l);for(;;){s.zpp_inner.zpp_inner.valmod();let i=s.zpp_inner;i.zpp_inner.valmod(),i.zpp_inner.zip_length&&(i.zpp_inner.zip_length=!1,i.zpp_inner.user_length=i.zpp_inner.inner.length);let o=i.zpp_inner.user_length;s.zpp_critical=!0;let r;if(s.zpp_i<o?r=!0:(s.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=s,s.zpp_inner=null,r=!1),!r)break;s.zpp_critical=!1;let a=s.zpp_inner.at(s.zpp_i++);e.zpp_inner_i.wrap_cbTypes==null&&e.zpp_inner_i.setupcbTypes();let p=e.zpp_inner_i.wrap_cbTypes;p.zpp_inner.reverse_flag?p.push(a):p.unshift(a)}this.userData!=null&&(e.zpp_inner_i.userData=Object.assign({},this.userData))}static _init(e,t){yn._initialized||(yn._initialized=!0,yn._zpp=e,yn._nape=t)}};yn.__name__=["zpp_nape","phys","ZPP_Interactor"],yn._nape=null,yn._zpp=null,yn._initialized=!1;var Vt=yn;var Ie=class Ie{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.world=!1;this.type=0;this.compound=null;this.shapes=null;this.wrap_shapes=null;this.space=null;this.arbiters=null;this.wrap_arbiters=null;this.constraints=null;this.wrap_constraints=null;this.component=null;this.graph_depth=0;this.sweepTime=0;this.sweep_angvel=0;this.sweepFrozen=!1;this.sweepRadius=0;this.bullet=!1;this.bulletEnabled=!1;this.disableCCD=!1;this.pre_posx=0;this.pre_posy=0;this.posx=0;this.posy=0;this.wrap_pos=null;this.velx=0;this.vely=0;this.wrap_vel=null;this.forcex=0;this.forcey=0;this.wrap_force=null;this.kinvelx=0;this.kinvely=0;this.wrap_kinvel=null;this.svelx=0;this.svely=0;this.wrap_svel=null;this.wrapcvel=null;this.angvel=0;this.torque=0;this.kinangvel=0;this.pre_rot=0;this.rot=0;this.axisx=0;this.axisy=0;this.zip_axis=!1;this.kinematicDelaySleep=!1;this.mass=0;this.zip_mass=!1;this.massMode=0;this.imass=0;this.smass=0;this.cmass=0;this.nomove=!1;this.gravMass=0;this.zip_gravMass=!1;this.gravMassMode=0;this.gravMassScale=0;this.zip_gravMassScale=!1;this.inertiaMode=0;this.inertia=0;this.zip_inertia=!1;this.cinertia=0;this.iinertia=0;this.sinertia=0;this.norotate=!1;this.aabb=null;this.zip_aabb=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;let e=Ie._zpp;Vt.initFields(this),this.ibody=this,this.world=!1,this.bulletEnabled=!1,this.sweepTime=0,this.sweep_angvel=0,this.norotate=this.nomove=!1,this.disableCCD=!1,this.posx=0,this.posy=0,this.rot=0,this.axisx=0,this.axisy=1,this.svelx=0,this.svely=0,this.velx=0,this.vely=0,this.kinvelx=0,this.kinvely=0,this.forcex=0,this.forcey=0,this.torque=this.angvel=this.kinangvel=0,this.pre_posx=1/0,this.pre_posy=1/0,this.pre_rot=1/0,this.localCOMx=0,this.localCOMy=0,this.worldCOMx=0,this.worldCOMy=0,this.zip_aabb=!0;let t;be.zpp_pool==null?t=new be:(t=be.zpp_pool,be.zpp_pool=t.next,t.next=null),t.minx=0,t.miny=0,t.maxx=0,t.maxy=0,this.aabb=t,this.aabb._immutable=!0,this.aabb._validate=this.aabb_validate.bind(this),this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.arbiters=new e.util.ZNPList_ZPP_Arbiter,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.shapes=new e.util.ZNPList_ZPP_Shape,this.wrap_shapes=e.util.ZPP_ShapeList.get(this.shapes),this.wrap_shapes.zpp_inner.adder=this.shapes_adder.bind(this),this.wrap_shapes.zpp_inner.subber=this.shapes_subber.bind(this),this.wrap_shapes.zpp_inner._invalidate=this.shapes_invalidate.bind(this),this.wrap_shapes.zpp_inner._modifiable=this.shapes_modifiable.bind(this),this.kinematicDelaySleep=!1}static bodysetlt(e,t){return e.id<t.id}static __static(){let e=Ie._nape,t=Ie._zpp;t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new e.phys.BodyType,t.util.ZPP_Flags.internal=!1);let n=new e.phys.Body(t.util.ZPP_Flags.BodyType_STATIC),l=n.zpp_inner;return l.world=!0,l.wrap_shapes.zpp_inner.immutable=!0,l.smass=l.imass=l.cmass=l.mass=l.gravMass=0,l.sinertia=l.iinertia=l.cinertia=l.inertia=0,l.cbTypes.clear(),n}isStatic(){return this.type===1}isDynamic(){return this.type===2}isKinematic(){return this.type===3}invalidate_type(){this.invalidate_mass(),this.invalidate_inertia()}invalidate_shapes(){this.zip_aabb=!0,this.zip_localCOM=!0,this.zip_worldCOM=!0,this.invalidate_mass(),this.invalidate_inertia()}init_bodysetlist(){if(Ie.bodyset==null){let e=Ie._zpp;Ie.bodyset=new e.util.ZPP_Set_ZPP_Body,Ie.bodyset.lt=Ie.bodysetlt,Ie.bodystack=new e.util.ZNPList_ZPP_Body}}connectedBodies_cont(e){Ie.bodyset.try_insert_bool(e.zpp_inner)&&(Ie.bodystack.add(e.zpp_inner),e.zpp_inner.graph_depth=Ie.cur_graph_depth+1)}connectedBodies(e,t){let n=Ie._nape;Ie.bodyset==null&&this.init_bodysetlist();let l=t??new n.phys.BodyList;for(Ie.bodystack.add(this),Ie.bodyset.insert(this),this.graph_depth=0;Ie.bodystack.head!=null;){let i=Ie.bodystack.pop_unsafe();if(i.graph_depth===e)continue;Ie.cur_graph_depth=i.graph_depth;let o=i.constraints.head;for(;o!=null;)o.elt.outer.visitBodies(this.connectedBodies_cont.bind(this)),o=o.next}let s=Ie.bodyset;if(s.parent!=null){let i=s.parent;for(;i!=null;)if(i.prev!=null)i=i.prev;else if(i.next!=null)i=i.next;else{let o=i.data;if(o!==this){let p=o.outer;l.zpp_inner.reverse_flag?l.push(p):l.unshift(p)}let r=i.parent;r!=null&&(i===r.prev?r.prev=null:r.next=null,i.parent=null);let a=i;a.data=null,a.lt=null,a.next=Ie._zpp.util.ZPP_Set_ZPP_Body.zpp_pool,Ie._zpp.util.ZPP_Set_ZPP_Body.zpp_pool=a,i=r}s.parent=null}return l}interactingBodies(e,t){let n=Ie._nape,l=Ie._zpp;Ie.bodyset==null&&this.init_bodysetlist();let s=t??new n.phys.BodyList,i=this.arbiters.head;for(;i!=null;){let r=i.elt;if(!r.sleeping&&(e===4||r.type===e)){let a=r.b1===this?r.b2:r.b1;if(Ie.bodyset.try_insert_bool(a)){let p=a.outer;s.zpp_inner.reverse_flag?s.push(p):s.unshift(p)}}i=i.next}let o=Ie.bodyset;if(o.parent!=null){let r=o.parent;for(;r!=null;)if(r.prev!=null)r=r.prev;else if(r.next!=null)r=r.next;else{let a=r.parent;a!=null&&(r===a.prev?a.prev=null:a.next=null,r.parent=null);let p=r;p.data=null,p.lt=null,p.next=l.util.ZPP_Set_ZPP_Body.zpp_pool,l.util.ZPP_Set_ZPP_Body.zpp_pool=p,r=a}o.parent=null}return s}atRest(e){let t=Ie._nape;if(this.type!==2)return this.component.sleeping;let n=t.Config.linearSleepThreshold*t.Config.linearSleepThreshold,l;if(this.velx*this.velx+this.vely*this.vely>n)l=!1;else{let s=this.posx-this.pre_posx,i=this.posy-this.pre_posy;if(s*s+i*i>.25*n*e*e)l=!1;else{let o=this.aabb.maxx-this.aabb.minx,r=this.aabb.maxy-this.aabb.miny,a=o*o+r*r,p=t.Config.angularSleepThreshold*t.Config.angularSleepThreshold;if(4*this.angvel*this.angvel*a>p)l=!1;else{let c=this.rot-this.pre_rot;l=!(c*c*a>p*e*e)}}}return l||(this.component.waket=this.space.stamp),this.component.waket+t.Config.sleepDelay<this.space.stamp}refreshArbiters(){let e=this.arbiters.head;for(;e!=null;){let t=e.elt;t.invalidated=!0,e=e.next}}sweepIntegrate(e){let t=e-this.sweepTime;if(t!==0&&(this.sweepTime=e,this.posx+=this.velx*t,this.posy+=this.vely*t,this.angvel!==0)){let n=this.sweep_angvel*t;if(this.rot+=n,n*n>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let l=n*n,s=1-.5*l,i=1-l*l/8,o=(s*this.axisx+n*this.axisy)*i;this.axisy=(s*this.axisy-n*this.axisx)*i,this.axisx=o}}}sweepValidate(e){if(e.type===0)e.worldCOMx=this.posx+(this.axisy*e.localCOMx-this.axisx*e.localCOMy),e.worldCOMy=this.posy+(e.localCOMx*this.axisx+e.localCOMy*this.axisy);else{let t=e.polygon,n=t.lverts.next,l=t.gverts.next;for(;l!=null;){let p=l,c=n;n=n.next,p.x=this.posx+(this.axisy*c.x-this.axisx*c.y),p.y=this.posy+(c.x*this.axisx+c.y*this.axisy),l=l.next}let s=t.edges.head,i=t.gverts.next,o=i;for(i=i.next;i!=null;){let p=i,c=s.elt;s=s.next,c.gnormx=this.axisy*c.lnormx-this.axisx*c.lnormy,c.gnormy=c.lnormx*this.axisx+c.lnormy*this.axisy,c.gprojection=this.posx*c.gnormx+this.posy*c.gnormy+c.lprojection,c.tp0=o.y*c.gnormx-o.x*c.gnormy,c.tp1=p.y*c.gnormx-p.x*c.gnormy,o=p,i=i.next}let r=t.gverts.next,a=s.elt;a.gnormx=this.axisy*a.lnormx-this.axisx*a.lnormy,a.gnormy=a.lnormx*this.axisx+a.lnormy*this.axisy,a.gprojection=this.posx*a.gnormx+this.posy*a.gnormy+a.lprojection,a.tp0=o.y*a.gnormx-o.x*a.gnormy,a.tp1=r.y*a.gnormx-r.x*a.gnormy}}invalidate_pos(){let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}pos_invalidate(e){if(this.immutable_midstep("Body::position"),this.type===1&&this.space!=null)throw new Error("Error: Cannot move a static object once inside a Space");this.posx===e.x&&this.posy===e.y||(this.posx=e.x,this.posy=e.y,this.invalidate_pos(),this.wake())}pos_validate(){this.wrap_pos.zpp_inner.x=this.posx,this.wrap_pos.zpp_inner.y=this.posy}vel_invalidate(e){if(this.type===1)throw new Error("Error: Static body cannot have its velocity set.");this.velx=e.x,this.vely=e.y,this.wake()}vel_validate(){this.wrap_vel.zpp_inner.x=this.velx,this.wrap_vel.zpp_inner.y=this.vely}kinvel_invalidate(e){this.kinvelx=e.x,this.kinvely=e.y,this.wake()}kinvel_validate(){this.wrap_kinvel.zpp_inner.x=this.kinvelx,this.wrap_kinvel.zpp_inner.y=this.kinvely}svel_invalidate(e){this.svelx=e.x,this.svely=e.y,this.wake()}svel_validate(){this.wrap_svel.zpp_inner.x=this.svelx,this.wrap_svel.zpp_inner.y=this.svely}force_invalidate(e){if(this.type!==2)throw new Error("Error: Non-dynamic body cannot have force applied.");this.forcex=e.x,this.forcey=e.y,this.wake()}force_validate(){this.wrap_force.zpp_inner.x=this.forcex,this.wrap_force.zpp_inner.y=this.forcey}_setupVec2Wrapper(e,t,n,l){let s=Ie._nape;if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(xe.poolVec2==null?i=new s.geom.Vec2:(i=xe.poolVec2,xe.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i===xe.nextVec2&&(xe.nextVec2=null)),i.zpp_inner==null){let o;le.zpp_pool==null?o=new le:(o=le.zpp_pool,le.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=e,o.y=t,i.zpp_inner=o,i.zpp_inner.outer=i}else{if(i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=i.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let r;i.zpp_inner._validate!=null&&i.zpp_inner._validate(),i.zpp_inner.x===e?(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),r=i.zpp_inner.y===t):r=!1,r||(i.zpp_inner.x=e,i.zpp_inner.y=t,i.zpp_inner._invalidate!=null&&i.zpp_inner._invalidate(i.zpp_inner))}return i.zpp_inner.weak=!1,i}setupPosition(){this.wrap_pos=this._setupVec2Wrapper(this.posx,this.posy,null,null),this.wrap_pos.zpp_inner._inuse=!0,this.world?this.wrap_pos.zpp_inner._immutable=!0:(this.wrap_pos.zpp_inner._invalidate=this.pos_invalidate.bind(this),this.wrap_pos.zpp_inner._validate=this.pos_validate.bind(this))}setupVelocity(){this.wrap_vel=this._setupVec2Wrapper(this.velx,this.vely,null,null),this.wrap_vel.zpp_inner._inuse=!0,this.world?this.wrap_vel.zpp_inner._immutable=!0:(this.wrap_vel.zpp_inner._invalidate=this.vel_invalidate.bind(this),this.wrap_vel.zpp_inner._validate=this.vel_validate.bind(this))}setupkinvel(){this.wrap_kinvel=this._setupVec2Wrapper(this.kinvelx,this.kinvely,null,null),this.wrap_kinvel.zpp_inner._inuse=!0,this.world?this.wrap_kinvel.zpp_inner._immutable=!0:(this.wrap_kinvel.zpp_inner._invalidate=this.kinvel_invalidate.bind(this),this.wrap_kinvel.zpp_inner._validate=this.kinvel_validate.bind(this))}setupsvel(){this.wrap_svel=this._setupVec2Wrapper(this.svelx,this.svely,null,null),this.wrap_svel.zpp_inner._inuse=!0,this.world?this.wrap_svel.zpp_inner._immutable=!0:(this.wrap_svel.zpp_inner._invalidate=this.svel_invalidate.bind(this),this.wrap_svel.zpp_inner._validate=this.svel_validate.bind(this))}setupForce(){this.wrap_force=this._setupVec2Wrapper(this.forcex,this.forcey,null,null),this.wrap_force.zpp_inner._inuse=!0,this.world?this.wrap_force.zpp_inner._immutable=!0:(this.wrap_force.zpp_inner._invalidate=this.force_invalidate.bind(this),this.wrap_force.zpp_inner._validate=this.force_validate.bind(this))}cvel_validate(){this.wrapcvel.zpp_inner.x=this.velx+this.kinvelx,this.wrapcvel.zpp_inner.y=this.vely+this.kinvely}setup_cvel(){this.wrapcvel=this._setupVec2Wrapper(this.velx+this.kinvelx,this.vely+this.kinvely,null,null),this.wrapcvel.zpp_inner._inuse=!0,this.wrapcvel.zpp_inner._immutable=!0,this.wrapcvel.zpp_inner._validate=this.cvel_validate.bind(this)}invalidate_rot(){this.zip_axis=!0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}validate_axis(){this.zip_axis&&(this.zip_axis=!1,this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}quick_validate_axis(){this.zip_axis&&(this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}delta_rot(e){if(e*e>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let t=e*e,n=1-.5*t,l=1-t*t/8,s=(n*this.axisx+e*this.axisy)*l;this.axisy=(n*this.axisy-e*this.axisx)*l,this.axisx=s}this.zip_axis=!1}invalidate_mass(){this.zip_mass=!0,this.invalidate_gravMass()}validate_mass(){if(this.zip_mass||this.massMode===0&&!1){if(this.zip_mass=!1,this.massMode===0){this.cmass=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cmass+=n.area*n.material.density,t=t.next}}this.type===2&&!this.nomove?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0)}}invalidate_gravMass(){this.gravMassMode!==1&&(this.zip_gravMass=!0),this.gravMassMode!==2&&(this.zip_gravMassScale=!0),this.wake()}validate_gravMass(){this.zip_gravMass&&(this.zip_gravMass=!1,this.validate_mass(),this.gravMassMode===0?(this.validate_mass(),this.gravMass=this.cmass):this.gravMassMode===2&&(this.validate_mass(),this.gravMass=this.cmass*this.gravMassScale))}invalidate_gravMassScale(){this.gravMassMode!==2?this.zip_gravMassScale=!0:this.invalidate_gravMass()}validate_gravMassScale(){this.zip_gravMassScale&&(this.zip_gravMassScale=!1,this.gravMassMode===0?this.gravMassScale=1:this.gravMassMode===1&&(this.validate_mass(),this.gravMassScale=this.gravMass/this.cmass))}invalidate_inertia(){this.zip_inertia=!0,this.wake()}validate_inertia(){if(this.zip_inertia||this.inertiaMode===0&&!1){if(this.zip_inertia=!1,this.inertiaMode===0){this.cinertia=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cinertia+=n.inertia*n.area*n.material.density,t=t.next}}this.type===2&&!this.norotate?(this.inertia=this.cinertia,this.sinertia=this.iinertia=1/this.inertia):(this.inertia=1/0,this.sinertia=this.iinertia=0)}}invalidate_wake(){this.wake()}invalidate_aabb(){this.zip_aabb=!0}validate_aabb(){if(this.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(this.zip_aabb){this.zip_aabb=!1,this.aabb.minx=1/0,this.aabb.miny=1/0,this.aabb.maxx=-1/0,this.aabb.maxy=-1/0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.zip_aabb&&t.body!=null&&(t.zip_aabb=!1,t.type===0?this._validateCircleAABB(t.circle):this._validatePolygonAABB(t.polygon)),t.aabb.minx<this.aabb.minx&&(this.aabb.minx=t.aabb.minx),t.aabb.maxx>this.aabb.maxx&&(this.aabb.maxx=t.aabb.maxx),t.aabb.miny<this.aabb.miny&&(this.aabb.miny=t.aabb.miny),t.aabb.maxy>this.aabb.maxy&&(this.aabb.maxy=t.aabb.maxy),e=e.next}}}_validateCircleAABB(e){e.zip_worldCOM&&e.body!=null&&(e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type===1&&this._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)),this.validate_axis(),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy));let t=e.radius;e.aabb.minx=e.worldCOMx-t,e.aabb.miny=e.worldCOMy-t,e.aabb.maxx=e.worldCOMx+t,e.aabb.maxy=e.worldCOMy+t}_validatePolygonAABB(e){if(e.zip_gverts&&e.body!=null){e.zip_gverts=!1,e.validate_lverts(),this.validate_axis();let l=e.lverts.next,s=e.gverts.next;for(;s!=null;){let i=s,o=l;l=l.next,i.x=e.body.posx+(e.body.axisy*o.x-e.body.axisx*o.y),i.y=e.body.posy+(o.x*e.body.axisx+o.y*e.body.axisy),s=s.next}}if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let t=e.gverts.next;e.aabb.minx=t.x,e.aabb.miny=t.y,e.aabb.maxx=t.x,e.aabb.maxy=t.y;let n=e.gverts.next.next;for(;n!=null;){let l=n;l.x<e.aabb.minx&&(e.aabb.minx=l.x),l.x>e.aabb.maxx&&(e.aabb.maxx=l.x),l.y<e.aabb.miny&&(e.aabb.miny=l.y),l.y>e.aabb.maxy&&(e.aabb.maxy=l.y),n=n.next}}aabb_validate(){if(this.shapes.head==null)throw new Error("Error: bounds only makes sense when Body has shapes");this.validate_aabb()}invalidate_localCOM(){this.zip_localCOM=!0,this.zip_worldCOM=!0}invalidate_worldCOM(){this.zip_worldCOM=!0}_computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y,e.localCOMx+=e.lverts.next.next.x,e.localCOMy+=e.lverts.next.next.y,e.localCOMx*=.5,e.localCOMy*=.5;else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,l=n;n=n.next;let s=n;for(n=n.next;n!=null;){let p=n;t+=s.x*(p.y-l.y);let c=p.y*s.x-p.x*s.y;e.localCOMx+=(s.x+p.x)*c,e.localCOMy+=(s.y+p.y)*c,l=s,s=p,n=n.next}n=e.lverts.next;let i=n;t+=s.x*(i.y-l.y);let o=i.y*s.x-i.x*s.y;e.localCOMx+=(s.x+i.x)*o,e.localCOMy+=(s.y+i.y)*o,l=s,s=i,n=n.next;let r=n;t+=s.x*(r.y-l.y);let a=r.y*s.x-r.x*s.y;e.localCOMx+=(s.x+r.x)*a,e.localCOMy+=(s.y+r.y)*a,t=1/(3*t),e.localCOMx*=t,e.localCOMy*=t}}validate_localCOM(){if(this.zip_localCOM){this.zip_localCOM=!1;let e=0,t=0,n=0,l=this.shapes.head;for(;l!=null;){let s=l.elt;s.zip_localCOM&&(s.zip_localCOM=!1,s.type===1&&this._computePolygonLocalCOM(s.polygon),s.wrap_localCOM!=null&&(s.wrap_localCOM.zpp_inner.x=s.localCOMx,s.wrap_localCOM.zpp_inner.y=s.localCOMy)),s.validate_area_inertia();let i=s.area*s.material.density;e+=s.localCOMx*i,t+=s.localCOMy*i,n+=s.area*s.material.density,l=l.next}if(n!==0){let s=1/n;this.localCOMx=e*s,this.localCOMy=t*s}this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy),this.zip_mass&&this.massMode===0&&(this.zip_mass=!1,this.cmass=n,this.type===2?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0))}}validate_worldCOM(){this.zip_worldCOM&&(this.zip_worldCOM=!1,this.validate_localCOM(),this.validate_axis(),this.worldCOMx=this.posx+(this.axisy*this.localCOMx-this.axisx*this.localCOMy),this.worldCOMy=this.posy+(this.localCOMx*this.axisx+this.localCOMy*this.axisy)),this.wrap_worldCOM!=null&&(this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy)}getlocalCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its localCOM");this.validate_localCOM()}getworldCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its worldCOM");this.validate_worldCOM()}__immutable_midstep(){if(this.world)throw new Error("Error: Space::world is immutable")}clear(){if(this.space!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a Space!");if(this.constraints.head!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a constraint!");for(;this.shapes.head!=null;){let t=this.shapes.pop_unsafe();t.removedFromBody(),t.body=null}this.invalidate_shapes(),this.pre_posx=0,this.pre_posy=0,this.posx=0,this.posy=0,this.velx=0,this.vely=0,this.forcex=0,this.forcey=0,this.kinvelx=0,this.kinvely=0,this.svelx=0,this.svely=0,this.angvel=this.torque=this.kinangvel=this.pre_rot=this.rot=0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}for(this.zip_worldCOM=!0,this.zip_axis=!0,e=this.shapes.head;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0,this.axisx=0,this.axisy=1,this.zip_axis=!1,this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.norotate=!1,this.nomove=!1}shapes_adder(e){if(e.zpp_inner.body!==this){if(e.zpp_inner.body!=null&&e.zpp_inner.body.wrap_shapes.remove(e),e.zpp_inner.body=this,e.zpp_inner.addedToBody(),this.space!=null){let t=this.space,n=e.zpp_inner,l=n.body;l.world||(l.component.waket=t.stamp+(t.midstep?0:1),l.type===3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&t.really_wake(l,!1)),t.bphase.insert(n),n.addedToSpace()}return e.zpp_inner.type===1&&(e.zpp_inner.polygon.invalidate_gaxi(),e.zpp_inner.polygon.invalidate_gverts()),!0}else return!1}shapes_subber(e){this.space!=null&&this.space.removed_shape(e.zpp_inner),e.zpp_inner.body=null,e.zpp_inner.removedFromBody()}shapes_invalidate(e){this.invalidate_shapes()}shapes_modifiable(){if(this.immutable_midstep("Body::shapes"),this.type===1&&this.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}addedToSpace(){let e=Ie._zpp,t;e.space.ZPP_Component.zpp_pool==null?t=new e.space.ZPP_Component:(t=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t.next,t.next=null),t.isBody=!0,t.body=this,this.component=t,this.__iaddedToSpace()}removedFromSpace(){let e=Ie._zpp;for(;this.arbiters.head!=null;){let n=this.arbiters.pop_unsafe(),l=this.space;n.cleared=!0,n.b2===this&&this._removeArbiterFromList(n.b1.arbiters,n,e),n.b1===this&&this._removeArbiterFromList(n.b2.arbiters,n,e),n.pair!=null&&(n.pair.arb=null,n.pair=null),n.active=!1,l.f_arbiters.modified=!0}let t=this.component;t.body=null,t.constraint=null,t.next=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t,this.component=null,this.__iremovedFromSpace()}_removeArbiterFromList(e,t,n){let l=null,s=e.head;for(;s!=null;){if(s.elt===t){let i;l==null?(i=e.head,e.head=i.next,e.head==null&&(e.pushmod=!0)):(i=l.next,l.next=i.next,i.next==null&&(e.pushmod=!0));let o=i;o.elt=null,o.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=o,e.modified=!0,e.length--,e.pushmod=!0;break}l=s,s=s.next}}copy(){let e=Ie._nape,t=new e.phys.Body().zpp_inner;t.type=this.type,t.bulletEnabled=this.bulletEnabled,t.disableCCD=this.disableCCD;let n=this.shapes.head;for(;n!=null;){let l=n.elt,s=t.outer.zpp_inner.wrap_shapes,i=l.outer.copy();s.zpp_inner.reverse_flag?s.push(i):s.unshift(i),n=n.next}if(t.posx=this.posx,t.posy=this.posy,t.velx=this.velx,t.vely=this.vely,t.forcex=this.forcex,t.forcey=this.forcey,t.rot=this.rot,t.angvel=this.angvel,t.torque=this.torque,t.kinvelx=this.kinvelx,t.kinvely=this.kinvely,t.kinangvel=this.kinangvel,t.svelx=this.svelx,t.svely=this.svely,!this.zip_axis)t.axisx=this.axisx,t.axisy=this.axisy;else{t.zip_axis=!0;let l=t.shapes.head;for(;l!=null;){let s=l.elt;s.type===1&&(s.polygon.invalidate_gverts(),s.polygon.invalidate_gaxi()),s.invalidate_worldCOM(),l=l.next}t.zip_worldCOM=!0}return t.rot=this.rot,t.massMode=this.massMode,t.gravMassMode=this.gravMassMode,t.inertiaMode=this.inertiaMode,t.norotate=this.norotate,t.nomove=this.nomove,t.cmass=this.cmass,t.cinertia=this.cinertia,this.zip_mass?t.invalidate_mass():t.mass=this.mass,this.zip_gravMass?t.invalidate_gravMass():t.gravMass=this.gravMass,this.zip_gravMassScale?t.invalidate_gravMassScale():t.gravMassScale=this.gravMassScale,this.zip_inertia?t.invalidate_inertia():t.inertia=this.inertia,this.zip_aabb?t.zip_aabb=!0:(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy),this.zip_localCOM?(t.zip_localCOM=!0,t.zip_worldCOM=!0):(t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy),this.zip_worldCOM?t.zip_worldCOM=!0:(t.worldCOMx=this.worldCOMx,t.worldCOMy=this.worldCOMy),this.copyto(t.outer),t.outer}static _init(e,t){if(!Ie._initialized){Ie._initialized=!0,Ie._zpp=e,Ie._nape=t,Ie.__super__=Vt;for(let n of Object.getOwnPropertyNames(Vt.prototype))n!=="constructor"&&n!=="__class__"&&!(n in Ie.prototype)&&(Ie.prototype[n]=Vt.prototype[n])}}static _initEnums(e,t){let n=()=>{t.internal=!0;let l=new e.phys.BodyType;return t.internal=!1,l};t.BodyType_STATIC==null&&(t.BodyType_STATIC=n()),t.BodyType_DYNAMIC==null&&(t.BodyType_DYNAMIC=n()),t.BodyType_KINEMATIC==null&&(t.BodyType_KINEMATIC=n()),Ie.types=[null,t.BodyType_STATIC,t.BodyType_DYNAMIC,t.BodyType_KINEMATIC]}};Ie.__name__=["zpp_nape","phys","ZPP_Body"],Ie.__super__=null,Ie._nape=null,Ie._zpp=null,Ie.types=[],Ie.bodystack=null,Ie.bodyset=null,Ie.cur_graph_depth=0,Ie._initialized=!1;var En=Ie;var Dt=class Dt{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=Dt._zpp;Vt.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=Dt._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=Dt._zppOf(e);t.compound=null,this.space!=null&&this.space.remBody(t)}bodies_modifiable(){this.immutable_midstep("Compound::bodies")}constraints_adder(e){let t=Dt._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=Dt._zppOf(e);t.compound=null,this.space!=null&&this.space.remConstraint(t)}constraints_modifiable(){this.immutable_midstep("Compound::constraints")}compounds_adder(e){let t=Dt._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=Dt._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=Dt._nape,l=Dt._zpp,s=e==null;e==null&&(e=[]),t==null&&(t=[]);let i=new n.phys.Compound,o=this.compounds.head;for(;o!=null;){let c=o.elt.copy(e,t);if(c.zpp_inner.immutable_midstep("Compound::compound"),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==i&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_compounds.remove(c),i!=null)){let u=i.zpp_inner.wrap_compounds;u.zpp_inner.reverse_flag?u.push(c):u.unshift(c)}o=o.next}let r=this.bodies.head;for(;r!=null;){let p=r.elt,c=p.outer.copy();if(e.push(l.constraint.ZPP_CopyHelper.dict(p.id,c)),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==i&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_bodies.remove(c),i!=null)){let u=i.zpp_inner.wrap_bodies;u.zpp_inner.reverse_flag?u.push(c):u.unshift(c)}r=r.next}let a=this.constraints.head;for(;a!=null;){let c=a.elt.copy(e,t);if((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==i&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_constraints.remove(c),i!=null)){let u=i.zpp_inner.wrap_constraints;u.zpp_inner.reverse_flag?u.push(c):u.unshift(c)}a=a.next}if(s)for(;t.length>0;){let p=t.pop();for(let c=0;c<e.length;c++){let u=e[c];if(u.id===p.id){p.cb(u.bc);break}}}return this.copyto(i),i}static _init(){Dt.__super__=Vt;for(let e of Object.getOwnPropertyNames(Vt.prototype))e!=="constructor"&&e!=="__class__"&&!Object.prototype.hasOwnProperty.call(Dt.prototype,e)&&(Dt.prototype[e]=Vt.prototype[e])}};Dt.__name__=["zpp_nape","phys","ZPP_Compound"],Dt.__super__=null,Dt._nape=null,Dt._zpp=null,Dt._wrapFn=null;var Wn=Dt;var At=class At{constructor(){this.viscosity=1;this.density=1;this.gravityx=0;this.gravityy=0;this.wrap_gravity=null;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new At._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(At._wrapFn)this.outer=At._wrapFn(this);else{this.outer=new At._nape.phys.FluidProperties;let e=this.outer.zpp_inner;e.outer=null,e.next=At.zpp_pool,At.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new At._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return At.zpp_pool==null?e=new At:(e=At.zpp_pool,At.zpp_pool=e.next,e.next=null),e.viscosity=this.viscosity,e.density=this.density,e}gravity_invalidate(e){this.gravityx=e.x,this.gravityy=e.y,this.invalidate()}gravity_validate(){this.wrap_gravity.zpp_inner.x=this.gravityx,this.wrap_gravity.zpp_inner.y=this.gravityy}getgravity(){let e=At._zpp,t=At._nape,n=this.gravityx??0,l=this.gravityy??0;if(n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let s;if(e.util.ZPP_PubPool.poolVec2==null?s=new t.geom.Vec2:(s=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;e.geom.ZPP_Vec2.zpp_pool==null?i=new e.geom.ZPP_Vec2:(i=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),n!==n||l!==l)throw new Error("Error: Vec2 components cannot be NaN");let o=!1;i._validate!=null&&i._validate(),(i.x!==n||i.y!==l)&&(o=!0),o&&(i.x=n,i.y=l,i._invalidate!=null&&i._invalidate(i))}s.zpp_inner.weak=!1,this.wrap_gravity=s,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=this.gravity_invalidate.bind(this),this.wrap_gravity.zpp_inner._validate=this.gravity_validate.bind(this)}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_fluidprops(),e=e.next}};At.zpp_pool=null,At.__name__=["zpp_nape","phys","ZPP_FluidProperties"],At._nape=null,At._zpp=null,At._wrapFn=null;var Nn=At;var Ft=class Ft{constructor(){this.elasticity=0;this.dynamicFriction=1;this.staticFriction=2;this.density=.001;this.rollingFriction=.01;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new Ft._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Ft._wrapFn)this.outer=Ft._wrapFn(this);else{this.outer=new Ft._nape.phys.Material;let e=this.outer.zpp_inner;e.outer=null,e.next=Ft.zpp_pool,Ft.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Ft._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e=new Ft;return e.dynamicFriction=this.dynamicFriction,e.staticFriction=this.staticFriction,e.density=this.density,e.elasticity=this.elasticity,e.rollingFriction=this.rollingFriction,e}set(e){this.dynamicFriction=e.dynamicFriction,this.staticFriction=e.staticFriction,this.density=e.density,this.elasticity=e.elasticity,this.rollingFriction=e.rollingFriction}invalidate(e){let t=this.shapes.head;for(;t!=null;)t.elt.invalidate_material(e),t=t.next}};Ft.zpp_pool=null,Ft.WAKE=1,Ft.PROPS=2,Ft.ANGDRAG=4,Ft.ARBITERS=8,Ft.__name__=["zpp_nape","phys","ZPP_Material"],Ft._nape=null,Ft._zpp=null,Ft._wrapFn=null;var Ae=Ft;var rn=class rn{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()),rn.types=[t.ShapeType_CIRCLE,t.ShapeType_POLYGON]}_initShape(e){let t=rn._zpp;Vt.initFields(this),this.pairs=new t.util.ZNPList_ZPP_AABBPair,this.ishape=this,this.type=e;let n;be.zpp_pool==null?n=new be:(n=be.zpp_pool,be.zpp_pool=n.next,n.next=null),n.minx=0,n.miny=0,n.maxx=0,n.maxy=0,this.aabb=n,this.aabb._immutable=!0,this.aabb._validate=this.aabb_validate.bind(this),this.zip_area_inertia=this.zip_angDrag=this.zip_localCOM=this.zip_sweepRadius=!0,this.localCOMx=0,this.localCOMy=0,this.worldCOMx=0,this.worldCOMy=0,this.fluidEnabled=!1,this.sensorEnabled=!1,this.fluidProperties=null,this.body=null,this.refmaterial=new Ae,this.sweepRadius=this.sweepCoef=0}static _init(){if(!rn._initialized){rn._initialized=!0,rn.__super__=Vt;for(let e of Object.getOwnPropertyNames(Vt.prototype))e!=="constructor"&&e!=="__class__"&&!Object.prototype.hasOwnProperty.call(rn.prototype,e)&&(rn.prototype[e]=Vt.prototype[e])}}isCircle(){return this.type===0}isPolygon(){return this.type===1}invalidate_sweepRadius(){this.zip_sweepRadius=!0}validate_sweepRadius(){this.zip_sweepRadius&&(this.zip_sweepRadius=!1,this.type===0?this.circle.__validate_sweepRadius():this.polygon.__validate_sweepRadius())}clear(){this.type===0?this.circle.__clear():this.polygon.__clear()}validate_aabb(){this.zip_aabb&&this.body!=null&&(this.zip_aabb=!1,this.type===0?this.circle.__validate_aabb():this.polygon.__validate_aabb())}force_validate_aabb(){this.type===0?this.circle._force_validate_aabb():this.polygon._force_validate_aabb()}invalidate_aabb(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}validate_area_inertia(){this.zip_area_inertia&&(this.zip_area_inertia=!1,this.type===0?this.circle.__validate_area_inertia():this.polygon.__validate_area_inertia())}validate_angDrag(){(this.zip_angDrag||this.refmaterial.dynamicFriction!==this.material.dynamicFriction)&&(this.zip_angDrag=!1,this.refmaterial.dynamicFriction=this.material.dynamicFriction,this.type===0?this.circle.__validate_angDrag():this.polygon.__validate_angDrag())}validate_localCOM(){this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy))}validate_worldCOM(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.validate_localCOM();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy)}}getworldCOM(){if(this.body==null)throw new Error("Error: worldCOM only makes sense when Shape belongs to a Body");this.validate_worldCOM(),this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy}invalidate_area_inertia(){this.zip_area_inertia=!0,this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia())}invalidate_angDrag(){this.zip_angDrag=!0}invalidate_localCOM(){this.zip_localCOM=!0,this.invalidate_area_inertia(),this.type===0&&(this.zip_sweepRadius=!0),this.invalidate_angDrag(),this.invalidate_worldCOM(),this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0)}invalidate_worldCOM(){this.zip_worldCOM=!0,this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}invalidate_material(e){(e&Ae.WAKE)!==0&&this.wake(),(e&Ae.ARBITERS)!==0&&this.body!=null&&this.body.refreshArbiters(),(e&Ae.PROPS)!==0&&this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia()),(e&Ae.ANGDRAG)!==0&&this.invalidate_angDrag(),this.refmaterial.set(this.material)}invalidate_filter(){this.wake()}invalidate_fluidprops(){this.fluidEnabled&&this.wake()}aabb_validate(){if(this.body==null)throw new Error("Error: bounds only makes sense when Shape belongs to a Body");this.validate_aabb()}setMaterial(e){this.material!==e&&(this.body!=null&&this.body.space!=null&&this.material!=null&&this.material.shapes.remove(this),this.material=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake(),this.body!=null&&this.body.refreshArbiters())}setFilter(e){this.filter!==e&&(this.body!=null&&this.body.space!=null&&this.filter!=null&&this.filter.shapes.remove(this),this.filter=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake())}setFluid(e){this.fluidProperties!==e&&(this.body!=null&&this.body.space!=null&&this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this),this.fluidProperties=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.fluidEnabled&&this.wake())}__immutable_midstep(e){if(this.body!=null&&this.body.space!=null&&this.body.space.midstep)throw new Error("Error: "+e+" cannot be set during a space step()")}addedToBody(){this.invalidate_worldCOM(),this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}removedFromBody(){}addedToSpace(){this.__iaddedToSpace(),this.material.shapes.add(this),this.filter.shapes.add(this),this.fluidProperties!=null&&this.fluidProperties.shapes.add(this)}removedFromSpace(){this.__iremovedFromSpace(),this.material.shapes.remove(this),this.filter.shapes.remove(this),this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this)}copy(){let e=rn._zpp,t=this.type===0?this.circle.__copy():this.polygon.__copy();this.zip_area_inertia?t.invalidate_area_inertia():(t.area=this.area,t.inertia=this.inertia),this.zip_sweepRadius?t.zip_sweepRadius=!0:(t.sweepRadius=this.sweepRadius,t.sweepCoef=this.sweepCoef),this.zip_angDrag?t.invalidate_angDrag():t.angDrag=this.angDrag,this.zip_aabb?(t.zip_aabb=!0,t.body!=null&&(t.body.zip_aabb=!0)):(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy);let n=t.material;n.outer=null,n.next=Ae.zpp_pool,Ae.zpp_pool=n;let 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}};rn.__name__=["zpp_nape","shape","ZPP_Shape"],rn.__super__=null,rn._nape=null,rn._zpp=null,rn.types=[],rn._initialized=!1;var yi=rn;var an=class an{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(an._initialized)return;an._initialized=!0;let e=an._zpp;an.__super__=e.shape.ZPP_Shape;let t=e.shape.ZPP_Shape.prototype,n=an.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=an._zpp,t=an._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=an._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=an._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}};an.__name__=["zpp_nape","shape","ZPP_Circle"],an.__super__=null,an._nape=null,an._zpp=null,an._initialized=!1;var Qn=an;var Xt=class Xt{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&&(Xt._wrapFn?this.outer=Xt._wrapFn(this):(Xt.internal=!0,this.outer=new Xt._nape.shape.Edge,Xt.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=Xt._zpp,t=Xt._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=Xt._zpp,t=Xt._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)}};Xt.__name__=["zpp_nape","shape","ZPP_Edge"],Xt.zpp_pool=null,Xt.internal=!1,Xt._nape=null,Xt._zpp=null,Xt._wrapFn=null;var at=Xt;var pt=class pt{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=pt._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(pt._initialized)return;pt._initialized=!0;let e=pt._zpp;pt.__super__=e.shape.ZPP_Shape;let t=e.shape.ZPP_Shape.prototype,n=pt.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=pt._zpp;e.zpp_inner._invalidate=this.lverts_pa_invalidate.bind(this),e.zpp_inner._isimmutable=this.lverts_pa_immutable.bind(this);let n=null,l=null,s=this.lverts.next;for(;s!=null&&s!==e.zpp_inner;)n=n==null?this.gverts.next:n.next,l=l==null?this.edges.head:l.next,s=s.next;let i;if(t.geom.ZPP_Vec2.zpp_pool==null?i=new t.geom.ZPP_Vec2:(i=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!0,i.x=0,i.y=0,this.gverts.insert(n,i),this.lverts.next.next!=null)if(this.lverts.next.next.next==null){let o;at.zpp_pool==null?o=new at:(o=at.zpp_pool,at.zpp_pool=o.next,o.next=null),o.polygon=this,this.edges.add(o);let r;at.zpp_pool==null?r=new at:(r=at.zpp_pool,at.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.add(r),this.edgeCnt+=2}else{let o;at.zpp_pool==null?o=new at:(o=at.zpp_pool,at.zpp_pool=o.next,o.next=null),o.polygon=this,this.edges.insert(l,o),this.edgeCnt++}i._validate=this.gverts_pa_validate.bind(this)}lverts_subber(e){this.cleanup_lvert(e.zpp_inner)}lverts_invalidate(e){this.invalidate_lverts()}lverts_validate(){this.validate_lverts()}lverts_modifiable(){if(this.immutable_midstep("Polygon::localVerts"),this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}gverts_validate(){this._validateGverts()}edges_validate(){this.validate_lverts()}getlverts(){let e=pt._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=pt._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=pt._zpp;this.wrap_edges=e.util.ZPP_EdgeList.get(this.edges,!0),this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag,this.wrap_edges.zpp_inner._validate=this.edges_validate.bind(this)}invalidate_lverts(){this.invalidate_laxi(),this.invalidate_area_inertia(),this.invalidate_angDrag(),this.invalidate_localCOM(),this.invalidate_gverts(),this.zip_lverts=!0,this.zip_valid=!0,this.zip_sanitation=!0,this.body!=null&&this.body.wake()}invalidate_laxi(){this.invalidate_gaxi(),this.zip_sweepRadius=!0,this.zip_laxi=!0}invalidate_gverts(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0),this.zip_gverts=!0}invalidate_gaxi(){this.zip_gaxi=!0}validate_lverts(){this.zip_lverts&&(this.zip_lverts=!1,this.lverts.length>2&&(this.validate_area_inertia(),this.area<0&&(this.reverse_vertices(),this.area=-this.area)))}validate_laxi(){if(this.zip_laxi){this.zip_laxi=!1,this.validate_lverts();let t=this.edges.head,n=this.lverts.next,l=n;for(n=n.next;n!=null;){let u=n,h=t.elt;t=t.next,h.lp0=l,h.lp1=u;let x=l.x-u.x,b=l.y-u.y,_=Math.sqrt(x*x+b*b);h.length=_;let d=1/_;x*=d,b*=d;let f=x;x=-b,b=f,h.lprojection=x*l.x+b*l.y,h.lnormx=x,h.lnormy=b,h.wrap_lnorm!=null&&(h.wrap_lnorm.zpp_inner.x=x,h.wrap_lnorm.zpp_inner.y=b),l=u,n=n.next}let s=this.lverts.next,i=t.elt;i.lp0=l,i.lp1=s;let o=l.x-s.x,r=l.y-s.y,a=Math.sqrt(o*o+r*r);i.length=a;let p=1/a;o*=p,r*=p;let c=o;o=-r,r=c,i.lprojection=o*l.x+r*l.y,i.lnormx=o,i.lnormy=r,i.wrap_lnorm!=null&&(i.wrap_lnorm.zpp_inner.x=o,i.wrap_lnorm.zpp_inner.y=r)}}validate_gverts(){this._validateGverts()}validate_gaxi(){if(this.zip_gaxi&&this.body!=null){this.zip_gaxi=!1,this.validate_laxi();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this._validateGverts();let t=this.edges.head,n=this.gverts.next,l=n;for(n=n.next;n!=null;){let o=n,r=t.elt;t=t.next,r.gp0=l,r.gp1=o,r.gnormx=e.axisy*r.lnormx-e.axisx*r.lnormy,r.gnormy=r.lnormx*e.axisx+r.lnormy*e.axisy,r.gprojection=e.posx*r.gnormx+e.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy,l=o,n=n.next}let s=this.gverts.next,i=t.elt;i.gp0=l,i.gp1=s,i.gnormx=e.axisy*i.lnormx-e.axisx*i.lnormy,i.gnormy=i.lnormx*e.axisx+i.lnormy*e.axisy,i.gprojection=e.posx*i.gnormx+e.posy*i.gnormy+i.lprojection,i.wrap_gnorm!=null&&(i.wrap_gnorm.zpp_inner.x=i.gnormx,i.wrap_gnorm.zpp_inner.y=i.gnormy),i.tp0=i.gp0.y*i.gnormx-i.gp0.x*i.gnormy,i.tp1=i.gp1.y*i.gnormx-i.gp1.x*i.gnormy}}_validateGverts(){if(this.zip_gverts&&this.body!=null){this.zip_gverts=!1,this.validate_lverts();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let t=this.lverts.next,n=this.gverts.next;for(;n!=null;){let l=n,s=t;t=t.next,l.x=e.posx+(e.axisy*s.x-e.axisx*s.y),l.y=e.posy+(s.x*e.axisx+s.y*e.axisy),n=n.next}}}cleanup_lvert(e){let t=pt._zpp,n=null,l=null,s=this.lverts.next;for(;s!=null&&s!==e;)n=n==null?this.gverts.next:n.next,l=l==null?this.edges.head:l.next,s=s.next;let i=n==null?this.gverts.next:n.next;this.gverts.erase(n);let o=i;if(o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=o,this.edgeCnt===2){let r=this.edges.pop_unsafe();r.polygon=null,r.next=at.zpp_pool,at.zpp_pool=r,r=this.edges.pop_unsafe(),r.polygon=null,r.next=at.zpp_pool,at.zpp_pool=r,this.edgeCnt=0}else if(this.edgeCnt!==0){let r=l==null?this.edges.head.elt:l.next.elt;this.edges.erase(l),r.polygon=null,r.next=at.zpp_pool,at.zpp_pool=r,this.edgeCnt--}}splice_collinear(){this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real())}splice_collinear_real(){let e=pt._nape;if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)return;let t=null,n=this.lverts.next;for(;n!=null;){let s=n.next==null?this.lverts.next:n.next,i=n.x-s.x,o=n.y-s.y;i*i+o*o<e.Config.epsilon*e.Config.epsilon?(this.cleanup_lvert(n),n=this.lverts.erase(t)):(t=n,n=n.next)}if(this.lverts.next==null)return;let l;for(;;){l=!1;let s=this.lverts.next;for(;s!=null;){let i=s.next==null?this.lverts.next:s.next,o=i.next==null?this.lverts.next:i.next,r=i.x-s.x,a=i.y-s.y,p=o.x-i.x,u=(o.y-i.y)*r-p*a;u*u>=e.Config.epsilon*e.Config.epsilon||(this.cleanup_lvert(i),this.lverts.erase(s.next==null?null:s),l=!0),s=s.next}if(!l)break}}reverse_vertices(){this.lverts.reverse(),this.gverts.reverse(),this.edges.reverse();let e=this.edges.iterator_at(this.edgeCnt-1),t=this.edges.pop_unsafe();this.edges.insert(e,t),this.reverse_flag=!this.reverse_flag,this.wrap_lverts!=null&&(this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_gverts!=null&&(this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_edges!=null&&(this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag)}valid(){let e=pt._nape,t=pt._zpp;if(this.zip_valid){if(this.zip_valid=!1,this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real()),this.lverts.length<3)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;if(this.validate_lverts(),this.validate_area_inertia(),this.area<e.Config.epsilon)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;{let n=!1,l=!1,s=!0,i=this.lverts.next,o=i;i=i.next;let r=i;for(i=i.next;i!=null;){let a=i,p=a.x-r.x,c=a.y-r.y,u=r.x-o.x,x=(r.y-o.y)*p-u*c;if(x>e.Config.epsilon?l=!0:x<-e.Config.epsilon&&(n=!0),l&&n){s=!1;break}o=r,r=a,i=i.next}if(s){i=this.lverts.next;let a=i,p=a.x-r.x,c=a.y-r.y,u=r.x-o.x,x=(r.y-o.y)*p-u*c;if(x>e.Config.epsilon?l=!0:x<-e.Config.epsilon&&(n=!0),!(l&&n)){o=r,r=a,i=i.next;let b=i,_=b.x-r.x,d=b.y-r.y,f=r.x-o.x,z=(r.y-o.y)*_-f*d;z>e.Config.epsilon?l=!0:z<-e.Config.epsilon&&(n=!0)}}if(l&&n)return t.util.ZPP_Flags.ValidationResult_CONCAVE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_CONCAVE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_CONCAVE;{let a=!0,p=this.lverts.next,c=p;for(p=p.next;p!=null&&a;){let u=p,h=this.lverts.next,x=h.next;for(;x!=null&&a;){let b=x;c!==h&&c!==b&&u!==h&&u!==b&&(a=this._checkNoIntersection(c,u,h,b,e)),h=b,x=x.next}if(a){let b=this.lverts.next;c!==h&&c!==b&&u!==h&&u!==b&&(a=this._checkNoIntersection(c,u,h,b,e))}c=u,p=p.next}if(a){let u=this.lverts.next,h=this.lverts.next,x=h.next;for(;x!=null&&a;){let b=x;c!==h&&c!==b&&u!==h&&u!==b&&(a=this._checkNoIntersection(c,u,h,b,e)),h=b,x=x.next}if(a){let b=this.lverts.next;c!==h&&c!==b&&u!==h&&u!==b&&(a=this._checkNoIntersection(c,u,h,b,e))}}return a?(t.util.ZPP_Flags.ValidationResult_VALID==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_VALID=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_VALID):(t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING)}}}else return this.validation}_checkNoIntersection(e,t,n,l,s){let i=e.x-n.x,o=e.y-n.y,r=t.x-e.x,a=t.y-e.y,p=l.x-n.x,c=l.y-n.y,u=a*p-r*c;if(u*u>s.Config.epsilon){u=1/u;let h=(c*i-p*o)*u;if(h>s.Config.epsilon&&h<1-s.Config.epsilon){let x=(a*i-r*o)*u;if(x>s.Config.epsilon&&x<1-s.Config.epsilon)return!1}}return!0}__validate_aabb(){if(this._validateGverts(),this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let e=this.gverts.next;this.aabb.minx=e.x,this.aabb.miny=e.y,this.aabb.maxx=e.x,this.aabb.maxy=e.y;let t=this.gverts.next.next;for(;t!=null;){let n=t;n.x<this.aabb.minx&&(this.aabb.minx=n.x),n.x>this.aabb.maxx&&(this.aabb.maxx=n.x),n.y<this.aabb.miny&&(this.aabb.miny=n.y),n.y>this.aabb.maxy&&(this.aabb.maxy=n.y),t=t.next}}_force_validate_aabb(){let e=this.body,t=this.lverts.next,n=this.gverts.next,l=t;t=t.next,n.x=e.posx+(e.axisy*l.x-e.axisx*l.y),n.y=e.posy+(l.x*e.axisx+l.y*e.axisy),this.aabb.minx=n.x,this.aabb.miny=n.y,this.aabb.maxx=n.x,this.aabb.maxy=n.y;let s=this.gverts.next.next;for(;s!=null;){let i=s,o=t;t=t.next,i.x=e.posx+(e.axisy*o.x-e.axisx*o.y),i.y=e.posy+(o.x*e.axisx+o.y*e.axisy),i.x<this.aabb.minx&&(this.aabb.minx=i.x),i.x>this.aabb.maxx&&(this.aabb.maxx=i.x),i.y<this.aabb.miny&&(this.aabb.miny=i.y),i.y>this.aabb.maxy&&(this.aabb.maxy=i.y),s=s.next}}__validate_sweepRadius(){let e=0,t=0;this.validate_laxi();let n=this.lverts.next;for(;n!=null;){let s=n,i=s.x*s.x+s.y*s.y;i>e&&(e=i),n=n.next}let l=this.edges.head;for(;l!=null;){let s=l.elt;if(s.lprojection<t&&(t=s.lprojection,t<0))break;l=l.next}t<0&&(t=0),this.sweepRadius=Math.sqrt(e),this.sweepCoef=this.sweepRadius-t}__validate_area_inertia(){if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)this.area=0,this.inertia=0;else{this.area=0;let e=0,t=0,n=this.lverts.next,l=n;n=n.next;let s=n;for(n=n.next;n!=null;){let p=n,c=s.y*l.x-s.x*l.y,u=s.x*s.x+s.y*s.y+(s.x*l.x+s.y*l.y)+(l.x*l.x+l.y*l.y);e+=c*u,t+=c,this.area+=s.x*(p.y-l.y),l=s,s=p,n=n.next}n=this.lverts.next;let i=n,o=s.y*l.x-s.x*l.y,r=s.x*s.x+s.y*s.y+(s.x*l.x+s.y*l.y)+(l.x*l.x+l.y*l.y);e+=o*r,t+=o,this.area+=s.x*(i.y-l.y),l=s,s=i,n=n.next;let a=n;o=s.y*l.x-s.x*l.y,r=s.x*s.x+s.y*s.y+(s.x*l.x+s.y*l.y)+(l.x*l.x+l.y*l.y),e+=o*r,t+=o,this.area+=s.x*(a.y-l.y),this.inertia=e/(6*t),this.area*=.5,this.area<0&&(this.area=-this.area,this.reverse_vertices())}}__validate_angDrag(){let e=pt._nape;if(this.lverts.length<3)throw new Error("Error: Polygon's with less than 3 vertices have no meaningful angDrag");this.validate_area_inertia(),this.validate_laxi();let t=0,n=this.edges.head,l=0,s=this.lverts.next,i=s,o=s.next;for(;o!=null;){let r=o,a=n.elt;n=n.next,l+=a.length;let p=r.x-i.x,c=r.y-i.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let u=-(i.y*a.lnormx-i.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(u>0){let h=u>1?1:u,x=i.x,b=i.y;x+=p*h,b+=c*h;let _=a.lnormy*i.x-a.lnormx*i.y,d=a.lnormy*x-a.lnormx*b,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*h*a.length*e.Config.fluidAngularDrag}if(u<1){let h=u<0?0:u,x=i.x,b=i.y;x+=p*h,b+=c*h;let _=a.lnormy*x-a.lnormx*b,d=a.lnormy*r.x-a.lnormx*r.y,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*e.Config.fluidVacuumDrag*(1-h)*a.length*e.Config.fluidAngularDrag}i=r,o=o.next}{let r=this.lverts.next,a=n.elt;l+=a.length;let p=r.x-i.x,c=r.y-i.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let u=-(i.y*a.lnormx-i.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(u>0){let h=u>1?1:u,x=i.x,b=i.y;x+=p*h,b+=c*h;let _=a.lnormy*i.x-a.lnormx*i.y,d=a.lnormy*x-a.lnormx*b,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*h*a.length*e.Config.fluidAngularDrag}if(u<1){let h=u<0?0:u,x=i.x,b=i.y;x+=p*h,b+=c*h;let _=a.lnormy*x-a.lnormx*b,d=a.lnormy*r.x-a.lnormx*r.y,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*e.Config.fluidVacuumDrag*(1-h)*a.length*e.Config.fluidAngularDrag}}this.angDrag=t/(this.inertia*l)}__validate_localCOM(){if(this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(this.lverts.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y;else if(this.lverts.next.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y,this.localCOMx+=this.lverts.next.next.x,this.localCOMy+=this.lverts.next.next.y,this.localCOMx*=.5,this.localCOMy*=.5;else{this.localCOMx=0,this.localCOMy=0;let e=0,t=this.lverts.next,n=t;t=t.next;let l=t;for(t=t.next;t!=null;){let r=t;e+=l.x*(r.y-n.y);let a=r.y*l.x-r.x*l.y;this.localCOMx+=(l.x+r.x)*a,this.localCOMy+=(l.y+r.y)*a,n=l,l=r,t=t.next}t=this.lverts.next;let s=t;e+=l.x*(s.y-n.y);let i=s.y*l.x-s.x*l.y;this.localCOMx+=(l.x+s.x)*i,this.localCOMy+=(l.y+s.y)*i,n=l,l=s,t=t.next;let o=t;e+=l.x*(o.y-n.y),i=o.y*l.x-o.x*l.y,this.localCOMx+=(l.x+o.x)*i,this.localCOMy+=(l.y+o.y)*i,e=1/(3*e),this.localCOMx*=e,this.localCOMy*=e}}localCOM_validate(){if(this.lverts.next==null)throw new Error("Error: An empty polygon does not have any meaningful localCOM");this.validate_localCOM()}localCOM_invalidate(e){this.validate_localCOM();let t=e.x-this.localCOMx,n=e.y-this.localCOMy,l=this.lverts.next;for(;l!=null;)l.x+=t,l.y+=n,l=l.next;this.invalidate_lverts()}setupLocalCOM(){let e=pt._zpp,t=pt._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=pt._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}};pt.__name__=["zpp_nape","shape","ZPP_Polygon"],pt.__super__=null,pt._nape=null,pt._zpp=null,pt._initialized=!1;var $n=pt;var mi=class mi{constructor(){this.space=null;this.is_sweep=!1;this.sweep=null;this.dynab=null;this.aabbShape=null;this.matrix=null;this.circShape=null}static _initFields(e){e.space=null,e.is_sweep=!1,e.sweep=null,e.dynab=null,e.aabbShape=null,e.matrix=null,e.circShape=null}insert(e){this.is_sweep?this.sweep.__insert(e):this.dynab.__insert(e)}remove(e){this.is_sweep?this.sweep.__remove(e):this.dynab.__remove(e)}sync(e){if(this.is_sweep){if(!this.sweep.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let i=t.polygon;if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(i.lverts.next.next==null)i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;else if(i.lverts.next.next.next==null){i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;let o=1;i.localCOMx+=i.lverts.next.next.x*o,i.localCOMy+=i.lverts.next.next.y*o;let r=.5;i.localCOMx*=r,i.localCOMy*=r}else{i.localCOMx=0,i.localCOMy=0;let o=0,r=i.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let _=r;o+=p.x*(_.y-a.y);let d=_.y*p.x-_.x*p.y;i.localCOMx+=(p.x+_.x)*d,i.localCOMy+=(p.y+_.y)*d,a=p,p=_,r=r.next}r=i.lverts.next;let c=r;o+=p.x*(c.y-a.y);let u=c.y*p.x-c.x*p.y;i.localCOMx+=(p.x+c.x)*u,i.localCOMy+=(p.y+c.y)*u,a=p,p=c,r=r.next;let h=r;o+=p.x*(h.y-a.y);let x=h.y*p.x-h.x*p.y;i.localCOMx+=(p.x+h.x)*x,i.localCOMy+=(p.y+h.y)*x,o=1/(3*o);let b=o;i.localCOMx*=b,i.localCOMy*=b}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=i;i=i.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}}else{let t=this.dynab,n=e.node;if(!n.synced){if(!t.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let s=e.circle;if(s.zip_worldCOM&&s.body!=null){if(s.zip_worldCOM=!1,s.zip_localCOM){if(s.zip_localCOM=!1,s.type==1){let a=s.polygon;if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(a.lverts.next.next==null)a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;else if(a.lverts.next.next.next==null){a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;let p=1;a.localCOMx+=a.lverts.next.next.x*p,a.localCOMy+=a.lverts.next.next.y*p;let c=.5;a.localCOMx*=c,a.localCOMy*=c}else{a.localCOMx=0,a.localCOMy=0;let p=0,c=a.lverts.next,u=c;c=c.next;let h=c;for(c=c.next;c!=null;){let m=c;p+=h.x*(m.y-u.y);let z=m.y*h.x-m.x*h.y;a.localCOMx+=(h.x+m.x)*z,a.localCOMy+=(h.y+m.y)*z,u=h,h=m,c=c.next}c=a.lverts.next;let x=c;p+=h.x*(x.y-u.y);let b=x.y*h.x-x.x*h.y;a.localCOMx+=(h.x+x.x)*b,a.localCOMy+=(h.y+x.y)*b,u=h,h=x,c=c.next;let _=c;p+=h.x*(_.y-u.y);let d=_.y*h.x-_.x*h.y;a.localCOMx+=(h.x+_.x)*d,a.localCOMy+=(h.y+_.y)*d,p=1/(3*p);let f=p;a.localCOMx*=f,a.localCOMy*=f}}s.wrap_localCOM!=null&&(s.wrap_localCOM.zpp_inner.x=s.localCOMx,s.wrap_localCOM.zpp_inner.y=s.localCOMy)}let r=s.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),s.worldCOMx=s.body.posx+(s.body.axisy*s.localCOMx-s.body.axisx*s.localCOMy),s.worldCOMy=s.body.posy+(s.localCOMx*s.body.axisx+s.localCOMy*s.body.axisy)}let i=s.radius,o=s.radius;s.aabb.minx=s.worldCOMx-i,s.aabb.miny=s.worldCOMy-o,s.aabb.maxx=s.worldCOMx+i,s.aabb.maxy=s.worldCOMy+o}else{let s=e.polygon;if(s.zip_gverts&&s.body!=null){s.zip_gverts=!1,s.validate_lverts();let r=s.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let a=s.lverts.next,p=s.gverts.next;for(;p!=null;){let c=p,u=a;a=a.next,c.x=s.body.posx+(s.body.axisy*u.x-s.body.axisx*u.y),c.y=s.body.posy+(u.x*s.body.axisx+u.y*s.body.axisy),p=p.next}}if(s.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let i=s.gverts.next;s.aabb.minx=i.x,s.aabb.miny=i.y,s.aabb.maxx=i.x,s.aabb.maxy=i.y;let o=s.gverts.next.next;for(;o!=null;){let r=o;r.x<s.aabb.minx&&(s.aabb.minx=r.x),r.x>s.aabb.maxx&&(s.aabb.maxx=r.x),r.y<s.aabb.miny&&(s.aabb.miny=r.y),r.y>s.aabb.maxy&&(s.aabb.maxy=r.y),o=o.next}}let l;if(n.dyn==(e.body.type==1?!1:!e.body.component.sleeping)){let s=n.aabb,i=e.aabb;l=!(i.minx>=s.minx&&i.miny>=s.miny&&i.maxx<=s.maxx&&i.maxy<=s.maxy)}else l=!0;l&&(n.synced=!0,n.snext=t.syncs,t.syncs=n)}}}broadphase(e,t){}clear(){}shapesUnderPoint(e,t,n,l){return null}bodiesUnderPoint(e,t,n,l){return null}updateAABBShape(e){let t=mi._zpp,n=mi._nape;if(this.aabbShape==null){t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new n.phys.BodyType,t.util.ZPP_Flags.internal=!1);let o=new n.phys.Body(t.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,r=this.aabbShape=new n.shape.Polygon(n.shape.Polygon.rect(e.minx,e.miny,e.maxx-e.minx,e.maxy-e.miny));o.zpp_inner.reverse_flag?o.push(r):o.unshift(r)}else{let i=this.aabbShape.zpp_inner.aabb,o=(e.maxx-e.minx)/(i.maxx-i.minx),r=(e.maxy-e.miny)/(i.maxy-i.miny);this.matrix==null&&(this.matrix=new n.geom.Mat23);let a=this.matrix;if(o!==o)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=o;let p=a.zpp_inner;p._invalidate!=null&&p._invalidate();let c=this.matrix,u=this.matrix;u.zpp_inner.c=0;let h=u.zpp_inner;h._invalidate!=null&&h._invalidate();let x=u.zpp_inner.c;if(x!==x)throw new Error("Error: Mat23::b cannot be NaN");c.zpp_inner.b=x;let b=c.zpp_inner;b._invalidate!=null&&b._invalidate();let _=this.matrix;if(r!==r)throw new Error("Error: Mat23::d cannot be NaN");_.zpp_inner.d=r;let d=_.zpp_inner;d._invalidate!=null&&d._invalidate();let f=this.matrix,m=e.minx-o*i.minx;if(m!==m)throw new Error("Error: Mat23::tx cannot be NaN");f.zpp_inner.tx=m;let z=f.zpp_inner;z._invalidate!=null&&z._invalidate();let Z=this.matrix,y=e.miny-r*i.miny;if(y!==y)throw new Error("Error: Mat23::ty cannot be NaN");Z.zpp_inner.ty=y;let w=Z.zpp_inner;w._invalidate!=null&&w._invalidate(),this.aabbShape.transform(this.matrix)}let l=this.aabbShape.zpp_inner;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let i=l.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=!1,i.zip_localCOM){if(i.zip_localCOM=!1,i.type==1){let p=i.polygon;if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(p.lverts.next.next==null)p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;else if(p.lverts.next.next.next==null){p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;let c=1;p.localCOMx+=p.lverts.next.next.x*c,p.localCOMy+=p.lverts.next.next.y*c;let u=.5;p.localCOMx*=u,p.localCOMy*=u}else{p.localCOMx=0,p.localCOMy=0;let c=0,u=p.lverts.next,h=u;u=u.next;let x=u;for(u=u.next;u!=null;){let z=u;c+=x.x*(z.y-h.y);let Z=z.y*x.x-z.x*x.y;p.localCOMx+=(x.x+z.x)*Z,p.localCOMy+=(x.y+z.y)*Z,h=x,x=z,u=u.next}u=p.lverts.next;let b=u;c+=x.x*(b.y-h.y);let _=b.y*x.x-b.x*x.y;p.localCOMx+=(x.x+b.x)*_,p.localCOMy+=(x.y+b.y)*_,h=x,x=b,u=u.next;let d=u;c+=x.x*(d.y-h.y);let f=d.y*x.x-d.x*x.y;p.localCOMx+=(x.x+d.x)*f,p.localCOMy+=(x.y+d.y)*f,c=1/(3*c);let m=c;p.localCOMx*=m,p.localCOMy*=m}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let o=i.radius,r=i.radius;i.aabb.minx=i.worldCOMx-o,i.aabb.miny=i.worldCOMy-r,i.aabb.maxx=i.worldCOMx+o,i.aabb.maxy=i.worldCOMy+r}else{let i=l.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=i.lverts.next,c=i.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=i.body.posx+(i.body.axisy*h.x-i.body.axisx*h.y),u.y=i.body.posy+(h.x*i.body.axisx+h.y*i.body.axisy),c=c.next}}if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let o=i.gverts.next;i.aabb.minx=o.x,i.aabb.miny=o.y,i.aabb.maxx=o.x,i.aabb.maxy=o.y;let r=i.gverts.next.next;for(;r!=null;){let a=r;a.x<i.aabb.minx&&(i.aabb.minx=a.x),a.x>i.aabb.maxx&&(i.aabb.maxx=a.x),a.y<i.aabb.miny&&(i.aabb.miny=a.y),a.y>i.aabb.maxy&&(i.aabb.maxy=a.y),r=r.next}}let s=this.aabbShape.zpp_inner.polygon;if(s.zip_gaxi&&s.body!=null){s.zip_gaxi=!1,s.validate_laxi();let i=s.body;if(i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),s.zip_gverts&&s.body!=null){s.zip_gverts=!1,s.validate_lverts();let u=s.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let h=s.lverts.next,x=s.gverts.next;for(;x!=null;){let b=x,_=h;h=h.next,b.x=s.body.posx+(s.body.axisy*_.x-s.body.axisx*_.y),b.y=s.body.posy+(_.x*s.body.axisx+_.y*s.body.axisy),x=x.next}}let o=s.edges.head,r=s.gverts.next,a=r;for(r=r.next;r!=null;){let u=r,h=o.elt;o=o.next,h.gp0=a,h.gp1=u,h.gnormx=s.body.axisy*h.lnormx-s.body.axisx*h.lnormy,h.gnormy=h.lnormx*s.body.axisx+h.lnormy*s.body.axisy,h.gprojection=s.body.posx*h.gnormx+s.body.posy*h.gnormy+h.lprojection,h.wrap_gnorm!=null&&(h.wrap_gnorm.zpp_inner.x=h.gnormx,h.wrap_gnorm.zpp_inner.y=h.gnormy),h.tp0=h.gp0.y*h.gnormx-h.gp0.x*h.gnormy,h.tp1=h.gp1.y*h.gnormx-h.gp1.x*h.gnormy,a=u,r=r.next}let p=s.gverts.next,c=o.elt;o=o.next,c.gp0=a,c.gp1=p,c.gnormx=s.body.axisy*c.lnormx-s.body.axisx*c.lnormy,c.gnormy=c.lnormx*s.body.axisx+c.lnormy*s.body.axisy,c.gprojection=s.body.posx*c.gnormx+s.body.posy*c.gnormy+c.lprojection,c.wrap_gnorm!=null&&(c.wrap_gnorm.zpp_inner.x=c.gnormx,c.wrap_gnorm.zpp_inner.y=c.gnormy),c.tp0=c.gp0.y*c.gnormx-c.gp0.x*c.gnormy,c.tp1=c.gp1.y*c.gnormx-c.gp1.x*c.gnormy}}shapesInAABB(e,t,n,l,s){return null}bodiesInAABB(e,t,n,l,s){return null}updateCircShape(e,t,n){let l=mi._zpp,s=mi._nape;if(this.circShape==null){l.util.ZPP_Flags.BodyType_STATIC==null&&(l.util.ZPP_Flags.internal=!0,l.util.ZPP_Flags.BodyType_STATIC=new s.phys.BodyType,l.util.ZPP_Flags.internal=!1);let r=new s.phys.Body(l.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,a=e,p=t;if(p==null&&(p=0),a==null&&(a=0),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let c;if(l.util.ZPP_PubPool.poolVec2==null?c=new s.geom.Vec2:(c=l.util.ZPP_PubPool.poolVec2,l.util.ZPP_PubPool.poolVec2=c.zpp_pool,c.zpp_pool=null,c.zpp_disp=!1,c==l.util.ZPP_PubPool.nextVec2&&(l.util.ZPP_PubPool.nextVec2=null)),c.zpp_inner==null){let h;l.geom.ZPP_Vec2.zpp_pool==null?h=new l.geom.ZPP_Vec2:(h=l.geom.ZPP_Vec2.zpp_pool,l.geom.ZPP_Vec2.zpp_pool=h.next,h.next=null),h.weak=!1,h._immutable=!1,h.x=a,h.y=p,c.zpp_inner=h,c.zpp_inner.outer=c}else{if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=c.zpp_inner;if(h._immutable)throw new Error("Error: Vec2 is immutable");if(h._isimmutable!=null&&h._isimmutable(),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let x;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let b=c.zpp_inner;if(b._validate!=null&&b._validate(),c.zpp_inner.x==a){if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let _=c.zpp_inner;_._validate!=null&&_._validate(),x=c.zpp_inner.y==p}else x=!1;if(!x){c.zpp_inner.x=a,c.zpp_inner.y=p;let _=c.zpp_inner;_._invalidate!=null&&_._invalidate(_)}}c.zpp_inner.weak=!1;let u=this.circShape=new s.shape.Circle(n,c);r.zpp_inner.reverse_flag?r.push(u):r.unshift(u)}else{let o=this.circShape.zpp_inner.circle,r=n/o.radius;this.matrix==null&&(this.matrix=new s.geom.Mat23);let a=this.matrix,p=this.matrix;if(r!==r)throw new Error("Error: Mat23::d cannot be NaN");p.zpp_inner.d=r;let c=p.zpp_inner;c._invalidate!=null&&c._invalidate();let u=p.zpp_inner.d;if(u!==u)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=u;let h=a.zpp_inner;h._invalidate!=null&&h._invalidate();let x=this.matrix,b=this.matrix;b.zpp_inner.c=0;let _=b.zpp_inner;_._invalidate!=null&&_._invalidate();let d=b.zpp_inner.c;if(d!==d)throw new Error("Error: Mat23::b cannot be NaN");x.zpp_inner.b=d;let f=x.zpp_inner;f._invalidate!=null&&f._invalidate();let m=this.matrix,z=e-r*o.localCOMx;if(z!==z)throw new Error("Error: Mat23::tx cannot be NaN");m.zpp_inner.tx=z;let Z=m.zpp_inner;Z._invalidate!=null&&Z._invalidate();let y=this.matrix,w=t-r*o.localCOMy;if(w!==w)throw new Error("Error: Mat23::ty cannot be NaN");y.zpp_inner.ty=w;let v=y.zpp_inner;v._invalidate!=null&&v._invalidate(),this.circShape.transform(this.matrix)}let i=this.circShape.zpp_inner;if(i.zip_aabb&&i.body!=null)if(i.zip_aabb=!1,i.type==0){let o=i.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let b=h;for(h=h.next;h!=null;){let Z=h;u+=b.x*(Z.y-x.y);let y=Z.y*b.x-Z.x*b.y;c.localCOMx+=(b.x+Z.x)*y,c.localCOMy+=(b.y+Z.y)*y,x=b,b=Z,h=h.next}h=c.lverts.next;let _=h;u+=b.x*(_.y-x.y);let d=_.y*b.x-_.x*b.y;c.localCOMx+=(b.x+_.x)*d,c.localCOMy+=(b.y+_.y)*d,x=b,b=_,h=h.next;let f=h;u+=b.x*(f.y-x.y);let m=f.y*b.x-f.x*b.y;c.localCOMx+=(b.x+f.x)*m,c.localCOMy+=(b.y+f.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else{let o=i.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,u=o.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),h.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}}shapesInCircle(e,t,n,l,s,i){return null}bodiesInCircle(e,t,n,l,s,i){return null}validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=t.body.posx+(t.body.axisy*h.x-t.body.axisx*h.y),u.y=t.body.posy+(h.x*t.body.axisx+h.y*t.body.axisy),c=c.next}}let l=t.edges.head,s=t.gverts.next,i=s;for(s=s.next;s!=null;){let a=s,p=l.elt;l=l.next,p.gp0=i,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,i=a,s=s.next}let o=t.gverts.next,r=l.elt;l=l.next,r.gp0=i,r.gp1=o,r.gnormx=t.body.axisy*r.lnormx-t.body.axisx*r.lnormy,r.gnormy=r.lnormx*t.body.axisx+r.lnormy*t.body.axisy,r.gprojection=t.body.posx*r.gnormx+t.body.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let i=t.polygon;if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(i.lverts.next.next==null)i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;else if(i.lverts.next.next.next==null){i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;let o=1;i.localCOMx+=i.lverts.next.next.x*o,i.localCOMy+=i.lverts.next.next.y*o;let r=.5;i.localCOMx*=r,i.localCOMy*=r}else{i.localCOMx=0,i.localCOMy=0;let o=0,r=i.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let _=r;o+=p.x*(_.y-a.y);let d=_.y*p.x-_.x*p.y;i.localCOMx+=(p.x+_.x)*d,i.localCOMy+=(p.y+_.y)*d,a=p,p=_,r=r.next}r=i.lverts.next;let c=r;o+=p.x*(c.y-a.y);let u=c.y*p.x-c.x*p.y;i.localCOMx+=(p.x+c.x)*u,i.localCOMy+=(p.y+c.y)*u,a=p,p=c,r=r.next;let h=r;o+=p.x*(h.y-a.y);let x=h.y*p.x-h.x*p.y;i.localCOMx+=(p.x+h.x)*x,i.localCOMy+=(p.y+h.y)*x,o=1/(3*o);let b=o;i.localCOMx*=b,i.localCOMy*=b}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=i;i=i.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let l=1;n.localCOMx+=n.lverts.next.next.x*l,n.localCOMy+=n.lverts.next.next.y*l;let s=.5;n.localCOMx*=s,n.localCOMy*=s}else{n.localCOMx=0,n.localCOMy=0;let l=0,s=n.lverts.next,i=s;s=s.next;let o=s;for(s=s.next;s!=null;){let h=s;l+=o.x*(h.y-i.y);let x=h.y*o.x-h.x*o.y;n.localCOMx+=(o.x+h.x)*x,n.localCOMy+=(o.y+h.y)*x,i=o,o=h,s=s.next}s=n.lverts.next;let r=s;l+=o.x*(r.y-i.y);let a=r.y*o.x-r.x*o.y;n.localCOMx+=(o.x+r.x)*a,n.localCOMy+=(o.y+r.y)*a,i=o,o=r,s=s.next;let p=s;l+=o.x*(p.y-i.y);let c=p.y*o.x-p.x*o.y;n.localCOMx+=(o.x+p.x)*c,n.localCOMy+=(o.y+p.y)*c,l=1/(3*l);let u=l;n.localCOMx*=u,n.localCOMy*=u}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}shapesInShape(e,t,n,l){return null}bodiesInShape(e,t,n,l){return null}rayCast(e,t,n){return null}rayMultiCast(e,t,n,l){return null}};mi.__name__=["zpp_nape","space","ZPP_Broadphase"],mi._zpp=null,mi._nape=null;var ji=mi;var Oe=class{constructor(){this.aabb=null;this.shape=null;this.dyn=!1;this.parent=null;this.child1=null;this.child2=null;this.height=-1;this.rayt=0;this.next=null;this.mnext=null;this.moved=!1;this.snext=null;this.synced=!1;this.first_sync=!1}alloc(){be.zpp_pool==null?this.aabb=new be:(this.aabb=be.zpp_pool,be.zpp_pool=this.aabb.next,this.aabb.next=null),this.moved=!1,this.synced=!1,this.first_sync=!1}free(){this.height=-1;let e=this.aabb;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e.wrap_min=e.wrap_max=null,e._invalidate=null,e._validate=null,e.next=be.zpp_pool,be.zpp_pool=e,this.child1=this.child2=this.parent=null,this.next=null,this.snext=null,this.mnext=null}isLeaf(){return this.child1==null}};Oe.__name__=["zpp_nape","space","ZPP_AABBNode"],Oe.zpp_pool=null;var tt=class{constructor(){this.n1=null;this.n2=null;this.first=!1;this.sleeping=!1;this.id=0;this.di=0;this.arb=null;this.next=null}alloc(){}free(){this.n1=this.n2=null,this.sleeping=!1}};tt.__name__=["zpp_nape","space","ZPP_AABBPair"],tt.zpp_pool=null;var kt=class kt{constructor(){this.root=null}static _initStatics(){kt.tmpaabb=new be}clear(){if(this.root==null)return;let e=null;for(this.root.next=e,e=this.root;e!=null;){let t=e;e=t.next,t.next=null;let n=t;n.child1==null?(n.shape.node=null,n.shape.removedFromSpace(),n.shape=null):(n.child1!=null&&(n.child1.next=e,e=n.child1),n.child2!=null&&(n.child2.next=e,e=n.child2));let l=n;l.height=-1;let s=l.aabb;s.outer!=null&&(s.outer.zpp_inner=null,s.outer=null),s.wrap_min=s.wrap_max=null,s._invalidate=null,s._validate=null,s.next=be.zpp_pool,be.zpp_pool=s,l.child1=l.child2=l.parent=null,l.next=null,l.snext=null,l.mnext=null,l.next=Oe.zpp_pool,Oe.zpp_pool=l}this.root=null}insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else{let t=e.aabb,n=this.root;for(;n.child1!=null;){let a=n.child1,p=n.child2,c=n.aabb,u=(c.maxx-c.minx+(c.maxy-c.miny))*2,h=kt.tmpaabb,x=n.aabb;h.minx=x.minx<t.minx?x.minx:t.minx,h.miny=x.miny<t.miny?x.miny:t.miny,h.maxx=x.maxx>t.maxx?x.maxx:t.maxx,h.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let b=kt.tmpaabb,_=(b.maxx-b.minx+(b.maxy-b.miny))*2,d=2*_,f=2*(_-u),m=kt.tmpaabb,z=a.aabb;m.minx=t.minx<z.minx?t.minx:z.minx,m.miny=t.miny<z.miny?t.miny:z.miny,m.maxx=t.maxx>z.maxx?t.maxx:z.maxx,m.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let Z;if(a.child1==null){let P=kt.tmpaabb;Z=(P.maxx-P.minx+(P.maxy-P.miny))*2+f}else{let P=a.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,k=kt.tmpaabb;Z=(k.maxx-k.minx+(k.maxy-k.miny))*2-g+f}let y=kt.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=kt.tmpaabb;v=(P.maxx-P.minx+(P.maxy-P.miny))*2+f}else{let P=p.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,k=kt.tmpaabb;v=(k.maxx-k.minx+(k.maxy-k.miny))*2-g+f}if(d<Z&&d<v)break;n=Z<v?a:p}let l=n,s=l.parent,i;Oe.zpp_pool==null?i=new Oe:(i=Oe.zpp_pool,Oe.zpp_pool=i.next,i.next=null),be.zpp_pool==null?i.aabb=new be:(i.aabb=be.zpp_pool,be.zpp_pool=i.aabb.next,i.aabb.next=null),i.moved=!1,i.synced=!1,i.first_sync=!1,i.parent=s;let o=i.aabb,r=l.aabb;for(o.minx=t.minx<r.minx?t.minx:r.minx,o.miny=t.miny<r.miny?t.miny:r.miny,o.maxx=t.maxx>r.maxx?t.maxx:r.maxx,o.maxy=t.maxy>r.maxy?t.maxy:r.maxy,i.height=l.height+1,s!=null?(s.child1==l?s.child1=i:s.child2=i,i.child1=l,i.child2=e,l.parent=i,e.parent=i):(i.child1=l,i.child2=e,l.parent=i,e.parent=i,this.root=i),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let _=n.child1,d=n.child2,f=d.height-_.height;if(f>1){let m=d.child1,z=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,n.child2=z,z.parent=n;let Z=n.aabb,y=_.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=z.height;n.height=1+(k>N?k:N);let E=n.height,M=m.height;d.height=1+(E>M?E:M)}else{d.child2=z,n.child2=m,m.parent=n;let Z=n.aabb,y=_.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=m.height;n.height=1+(k>N?k:N);let E=n.height,M=z.height;d.height=1+(E>M?E:M)}n=d}else if(f<-1){let m=_.child1,z=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,n.child1=z,z.parent=n;let Z=n.aabb,y=d.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=z.height;n.height=1+(k>N?k:N);let E=n.height,M=m.height;_.height=1+(E>M?E:M)}else{_.child2=z,n.child1=m,m.parent=n;let Z=n.aabb,y=d.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=m.height;n.height=1+(k>N?k:N);let E=n.height,M=z.height;_.height=1+(E>M?E:M)}n=_}else n=n}let a=n.child1,p=n.child2,c=a.height,u=p.height;n.height=1+(c>u?c:u);let h=n.aabb,x=a.aabb,b=p.aabb;h.minx=x.minx<b.minx?x.minx:b.minx,h.miny=x.miny<b.miny?x.miny:b.miny,h.maxx=x.maxx>b.maxx?x.maxx:b.maxx,h.maxy=x.maxy>b.maxy?x.maxy:b.maxy,n=n.parent}}}inlined_insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else{let t=e.aabb,n=this.root;for(;n.child1!=null;){let a=n.child1,p=n.child2,c=n.aabb,u=(c.maxx-c.minx+(c.maxy-c.miny))*2,h=kt.tmpaabb,x=n.aabb;h.minx=x.minx<t.minx?x.minx:t.minx,h.miny=x.miny<t.miny?x.miny:t.miny,h.maxx=x.maxx>t.maxx?x.maxx:t.maxx,h.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let b=kt.tmpaabb,_=(b.maxx-b.minx+(b.maxy-b.miny))*2,d=2*_,f=2*(_-u),m=kt.tmpaabb,z=a.aabb;m.minx=t.minx<z.minx?t.minx:z.minx,m.miny=t.miny<z.miny?t.miny:z.miny,m.maxx=t.maxx>z.maxx?t.maxx:z.maxx,m.maxy=t.maxy>z.maxy?t.maxy:z.maxy;let Z;if(a.child1==null){let P=kt.tmpaabb;Z=(P.maxx-P.minx+(P.maxy-P.miny))*2+f}else{let P=a.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,k=kt.tmpaabb;Z=(k.maxx-k.minx+(k.maxy-k.miny))*2-g+f}let y=kt.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=kt.tmpaabb;v=(P.maxx-P.minx+(P.maxy-P.miny))*2+f}else{let P=p.aabb,g=(P.maxx-P.minx+(P.maxy-P.miny))*2,k=kt.tmpaabb;v=(k.maxx-k.minx+(k.maxy-k.miny))*2-g+f}if(d<Z&&d<v)break;n=Z<v?a:p}let l=n,s=l.parent,i;Oe.zpp_pool==null?i=new Oe:(i=Oe.zpp_pool,Oe.zpp_pool=i.next,i.next=null),be.zpp_pool==null?i.aabb=new be:(i.aabb=be.zpp_pool,be.zpp_pool=i.aabb.next,i.aabb.next=null),i.moved=!1,i.synced=!1,i.first_sync=!1,i.parent=s;let o=i.aabb,r=l.aabb;for(o.minx=t.minx<r.minx?t.minx:r.minx,o.miny=t.miny<r.miny?t.miny:r.miny,o.maxx=t.maxx>r.maxx?t.maxx:r.maxx,o.maxy=t.maxy>r.maxy?t.maxy:r.maxy,i.height=l.height+1,s!=null?(s.child1==l?s.child1=i:s.child2=i,i.child1=l,i.child2=e,l.parent=i,e.parent=i):(i.child1=l,i.child2=e,l.parent=i,e.parent=i,this.root=i),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let _=n.child1,d=n.child2,f=d.height-_.height;if(f>1){let m=d.child1,z=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,n.child2=z,z.parent=n;let Z=n.aabb,y=_.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=z.height;n.height=1+(k>N?k:N);let E=n.height,M=m.height;d.height=1+(E>M?E:M)}else{d.child2=z,n.child2=m,m.parent=n;let Z=n.aabb,y=_.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=m.height;n.height=1+(k>N?k:N);let E=n.height,M=z.height;d.height=1+(E>M?E:M)}n=d}else if(f<-1){let m=_.child1,z=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,n.child1=z,z.parent=n;let Z=n.aabb,y=d.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=z.height;n.height=1+(k>N?k:N);let E=n.height,M=m.height;_.height=1+(E>M?E:M)}else{_.child2=z,n.child1=m,m.parent=n;let Z=n.aabb,y=d.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=n.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=m.height;n.height=1+(k>N?k:N);let E=n.height,M=z.height;_.height=1+(E>M?E:M)}n=_}else n=n}let a=n.child1,p=n.child2,c=a.height,u=p.height;n.height=1+(c>u?c:u);let h=n.aabb,x=a.aabb,b=p.aabb;h.minx=x.minx<b.minx?x.minx:b.minx,h.miny=x.miny<b.miny?x.miny:b.miny,h.maxx=x.maxx>b.maxx?x.maxx:b.maxx,h.maxy=x.maxy>b.maxy?x.maxy:b.maxy,n=n.parent}}}removeLeaf(e){if(e==this.root)this.root=null;else{let t=e.parent,n=t.parent,l=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=l:n.child2=l,l.parent=n;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let _=o.child1,d=o.child2,f=d.height-_.height;if(f>1){let m=d.child1,z=d.child2;if(d.child1=o,d.parent=o.parent,o.parent=d,d.parent!=null?d.parent.child1==o?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,o.child2=z,z.parent=o;let Z=o.aabb,y=_.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=o.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=z.height;o.height=1+(k>N?k:N);let E=o.height,M=m.height;d.height=1+(E>M?E:M)}else{d.child2=z,o.child2=m,m.parent=o;let Z=o.aabb,y=_.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=o.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=m.height;o.height=1+(k>N?k:N);let E=o.height,M=z.height;d.height=1+(E>M?E:M)}o=d}else if(f<-1){let m=_.child1,z=_.child2;if(_.child1=o,_.parent=o.parent,o.parent=_,_.parent!=null?_.parent.child1==o?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,o.child1=z,z.parent=o;let Z=o.aabb,y=d.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=o.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=z.height;o.height=1+(k>N?k:N);let E=o.height,M=m.height;_.height=1+(E>M?E:M)}else{_.child2=z,o.child1=m,m.parent=o;let Z=o.aabb,y=d.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=o.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=m.height;o.height=1+(k>N?k:N);let E=o.height,M=z.height;_.height=1+(E>M?E:M)}o=_}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,u=a.aabb,h=p.aabb;c.minx=u.minx<h.minx?u.minx:h.minx,c.miny=u.miny<h.miny?u.miny:h.miny,c.maxx=u.maxx>h.maxx?u.maxx:h.maxx,c.maxy=u.maxy>h.maxy?u.maxy:h.maxy;let x=a.height,b=p.height;r.height=1+(x>b?x:b),o=r.parent}}else{this.root=l,l.parent=null;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s}}}inlined_removeLeaf(e){if(e==this.root){this.root=null;return}else{let t=e.parent,n=t.parent,l=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=l:n.child2=l,l.parent=n;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let _=o.child1,d=o.child2,f=d.height-_.height;if(f>1){let m=d.child1,z=d.child2;if(d.child1=o,d.parent=o.parent,o.parent=d,d.parent!=null?d.parent.child1==o?d.parent.child1=d:d.parent.child2=d:this.root=d,m.height>z.height){d.child2=m,o.child2=z,z.parent=o;let Z=o.aabb,y=_.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=o.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=z.height;o.height=1+(k>N?k:N);let E=o.height,M=m.height;d.height=1+(E>M?E:M)}else{d.child2=z,o.child2=m,m.parent=o;let Z=o.aabb,y=_.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=d.aabb,P=o.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=_.height,N=m.height;o.height=1+(k>N?k:N);let E=o.height,M=z.height;d.height=1+(E>M?E:M)}o=d}else if(f<-1){let m=_.child1,z=_.child2;if(_.child1=o,_.parent=o.parent,o.parent=_,_.parent!=null?_.parent.child1==o?_.parent.child1=_:_.parent.child2=_:this.root=_,m.height>z.height){_.child2=m,o.child1=z,z.parent=o;let Z=o.aabb,y=d.aabb,w=z.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=o.aabb,g=m.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=z.height;o.height=1+(k>N?k:N);let E=o.height,M=m.height;_.height=1+(E>M?E:M)}else{_.child2=z,o.child1=m,m.parent=o;let Z=o.aabb,y=d.aabb,w=m.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy;let v=_.aabb,P=o.aabb,g=z.aabb;v.minx=P.minx<g.minx?P.minx:g.minx,v.miny=P.miny<g.miny?P.miny:g.miny,v.maxx=P.maxx>g.maxx?P.maxx:g.maxx,v.maxy=P.maxy>g.maxy?P.maxy:g.maxy;let k=d.height,N=m.height;o.height=1+(k>N?k:N);let E=o.height,M=z.height;_.height=1+(E>M?E:M)}o=_}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,u=a.aabb,h=p.aabb;c.minx=u.minx<h.minx?u.minx:h.minx,c.miny=u.miny<h.miny?u.miny:h.miny,c.maxx=u.maxx>h.maxx?u.maxx:h.maxx,c.maxy=u.maxy>h.maxy?u.maxy:h.maxy;let x=a.height,b=p.height;r.height=1+(x>b?x:b),o=r.parent}}else{this.root=l,l.parent=null;let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s}}}balance(e){if(e.child1==null||e.height<2)return e;{let t=e.child1,n=e.child2,l=n.height-t.height;if(l>1){let s=n.child1,i=n.child2;if(n.child1=e,n.parent=e.parent,e.parent=n,n.parent!=null?n.parent.child1==e?n.parent.child1=n:n.parent.child2=n:this.root=n,s.height>i.height){n.child2=s,e.child2=i,i.parent=e;let o=e.aabb,r=t.aabb,a=i.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=n.aabb,c=e.aabb,u=s.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=t.height,x=i.height;e.height=1+(h>x?h:x);let b=e.height,_=s.height;n.height=1+(b>_?b:_)}else{n.child2=i,e.child2=s,s.parent=e;let o=e.aabb,r=t.aabb,a=s.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=n.aabb,c=e.aabb,u=i.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=t.height,x=s.height;e.height=1+(h>x?h:x);let b=e.height,_=i.height;n.height=1+(b>_?b:_)}return n}else if(l<-1){let s=t.child1,i=t.child2;if(t.child1=e,t.parent=e.parent,e.parent=t,t.parent!=null?t.parent.child1==e?t.parent.child1=t:t.parent.child2=t:this.root=t,s.height>i.height){t.child2=s,e.child1=i,i.parent=e;let o=e.aabb,r=n.aabb,a=i.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=t.aabb,c=e.aabb,u=s.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=n.height,x=i.height;e.height=1+(h>x?h:x);let b=e.height,_=s.height;t.height=1+(b>_?b:_)}else{t.child2=i,e.child1=s,s.parent=e;let o=e.aabb,r=n.aabb,a=s.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=t.aabb,c=e.aabb,u=i.aabb;p.minx=c.minx<u.minx?c.minx:u.minx,p.miny=c.miny<u.miny?c.miny:u.miny,p.maxx=c.maxx>u.maxx?c.maxx:u.maxx,p.maxy=c.maxy>u.maxy?c.maxy:u.maxy;let h=n.height,x=s.height;e.height=1+(h>x?h:x);let b=e.height,_=i.height;t.height=1+(b>_?b:_)}return t}else return e}}};kt.__name__=["zpp_nape","space","ZPP_AABBTree"],kt.tmpaabb=null;var nt=kt;var fe=class fe{constructor(e){this.pairs=null;this.syncs=null;this.moves=null;this.treeStack=null;this.treeStack2=null;this.failed=null;this.openlist=null;this.space=null;this.is_sweep=!1;this.sweep=null;this.dynab=null;this.aabbShape=null;this.matrix=null;this.circShape=null;this.__class__=fe;ji._initFields(this),this.space=e,this.is_sweep=!1,this.dynab=this,this.stree=new nt,this.dtree=new nt}static _init(){fe.__super__=fe._zpp.space.ZPP_Broadphase;let e=fe._zpp.space.ZPP_Broadphase.prototype;Object.getOwnPropertyNames(e).forEach(t=>{t!=="constructor"&&!(t in fe.prototype)&&(fe.prototype[t]=e[t])})}dyn(e){return e.body.type==1?!1:!e.body.component.sleeping}__insert(e){let t;Oe.zpp_pool==null?t=new Oe:(t=Oe.zpp_pool,Oe.zpp_pool=t.next,t.next=null),be.zpp_pool==null?t.aabb=new be:(t.aabb=be.zpp_pool,be.zpp_pool=t.aabb.next,t.aabb.next=null),t.moved=!1,t.synced=!1,t.first_sync=!1,t.shape=e,e.node=t,t.synced=!0,t.first_sync=!0,t.snext=this.syncs,this.syncs=t}__remove(e){let t=e.node;if(t.first_sync||(t.dyn?this.dtree.removeLeaf(t):this.stree.removeLeaf(t)),e.node=null,t.synced){let o=null,r=this.syncs;for(;r!=null&&r!=t;)o=r,r=r.snext;o==null?this.syncs=r.snext:o.snext=r.snext,r.snext=null,t.synced=!1}if(t.moved){let o=null,r=this.moves;for(;r!=null&&r!=t;)o=r,r=r.mnext;o==null?this.moves=r.mnext:o.mnext=r.mnext,r.mnext=null,t.moved=!1}let n=null,l=this.pairs;for(;l!=null;){let o=l.next;if(l.n1==t||l.n2==t){n==null?this.pairs=o:n.next=o,l.arb!=null&&(l.arb.pair=null),l.arb=null,l.n1.shape.pairs.remove(l),l.n2.shape.pairs.remove(l);let r=l;r.n1=r.n2=null,r.sleeping=!1,r.next=tt.zpp_pool,tt.zpp_pool=r,l=o;continue}n=l,l=o}for(;e.pairs.head!=null;){let o=e.pairs.pop_unsafe();o.n1==t?o.n2.shape.pairs.remove(o):o.n1.shape.pairs.remove(o),o.arb!=null&&(o.arb.pair=null),o.arb=null;let r=o;r.n1=r.n2=null,r.sleeping=!1,r.next=tt.zpp_pool,tt.zpp_pool=r}let s=t;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Oe.zpp_pool,Oe.zpp_pool=s}__sync(e){let t=e.node;if(!t.synced){if(!this.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let l=e.circle;if(l.zip_worldCOM&&l.body!=null){if(l.zip_worldCOM=!1,l.zip_localCOM){if(l.zip_localCOM=!1,l.type==1){let r=l.polygon;if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(r.lverts.next.next==null)r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;else if(r.lverts.next.next.next==null){r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;let a=1;r.localCOMx+=r.lverts.next.next.x*a,r.localCOMy+=r.lverts.next.next.y*a;let p=.5;r.localCOMx*=p,r.localCOMy*=p}else{r.localCOMx=0,r.localCOMy=0;let a=0,p=r.lverts.next,c=p;p=p.next;let u=p;for(p=p.next;p!=null;){let f=p;a+=u.x*(f.y-c.y);let m=f.y*u.x-f.x*u.y;r.localCOMx+=(u.x+f.x)*m,r.localCOMy+=(u.y+f.y)*m,c=u,u=f,p=p.next}p=r.lverts.next;let h=p;a+=u.x*(h.y-c.y);let x=h.y*u.x-h.x*u.y;r.localCOMx+=(u.x+h.x)*x,r.localCOMy+=(u.y+h.y)*x,c=u,u=h,p=p.next;let b=p;a+=u.x*(b.y-c.y);let _=b.y*u.x-b.x*u.y;r.localCOMx+=(u.x+b.x)*_,r.localCOMy+=(u.y+b.y)*_,a=1/(3*a);let d=a;r.localCOMx*=d,r.localCOMy*=d}}l.wrap_localCOM!=null&&(l.wrap_localCOM.zpp_inner.x=l.localCOMx,l.wrap_localCOM.zpp_inner.y=l.localCOMy)}let o=l.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),l.worldCOMx=l.body.posx+(l.body.axisy*l.localCOMx-l.body.axisx*l.localCOMy),l.worldCOMy=l.body.posy+(l.localCOMx*l.body.axisx+l.localCOMy*l.body.axisy)}let s=l.radius,i=l.radius;l.aabb.minx=l.worldCOMx-s,l.aabb.miny=l.worldCOMy-i,l.aabb.maxx=l.worldCOMx+s,l.aabb.maxy=l.worldCOMy+i}else{let l=e.polygon;if(l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let o=l.body;o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot));let r=l.lverts.next,a=l.gverts.next;for(;a!=null;){let p=a,c=r;r=r.next,p.x=l.body.posx+(l.body.axisy*c.x-l.body.axisx*c.y),p.y=l.body.posy+(c.x*l.body.axisx+c.y*l.body.axisy),a=a.next}}if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let s=l.gverts.next;l.aabb.minx=s.x,l.aabb.miny=s.y,l.aabb.maxx=s.x,l.aabb.maxy=s.y;let i=l.gverts.next.next;for(;i!=null;){let o=i;o.x<l.aabb.minx&&(l.aabb.minx=o.x),o.x>l.aabb.maxx&&(l.aabb.maxx=o.x),o.y<l.aabb.miny&&(l.aabb.miny=o.y),o.y>l.aabb.maxy&&(l.aabb.maxy=o.y),i=i.next}}let n;if(t.dyn==(e.body.type==1?!1:!e.body.component.sleeping)){let l=t.aabb,s=e.aabb;n=!(s.minx>=l.minx&&s.miny>=l.miny&&s.maxx<=l.maxx&&s.maxy<=l.maxy)}else n=!0;n&&(t.synced=!0,t.snext=this.syncs,this.syncs=t)}}sync_broadphase(){if(this.space.validation(),this.syncs!=null)if(this.moves==null){let e=this.syncs;for(;e!=null;){let n=e.shape;if(e.first_sync)e.first_sync=!1;else{let o=e.dyn?this.dtree:this.stree;if(e==o.root)o.root=null;else{let r=e.parent,a=r.parent,p=r.child1==e?r.child2:r.child1;if(a!=null){a.child1==r?a.child1=p:a.child2=p,p.parent=a;let c=r;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Oe.zpp_pool,Oe.zpp_pool=c;let h=a;for(;h!=null;){if(h.child1==null||h.height<2)h=h;else{let Z=h.child1,y=h.child2,w=y.height-Z.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=h,y.parent=h.parent,h.parent=y,y.parent!=null?y.parent.child1==h?y.parent.child1=y:y.parent.child2=y:o.root=y,v.height>P.height){y.child2=v,h.child2=P,P.parent=h;let g=h.aabb,k=Z.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=h.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=Z.height,O=P.height;h.height=1+(L>O?L:O);let I=h.height,T=v.height;y.height=1+(I>T?I:T)}else{y.child2=P,h.child2=v,v.parent=h;let g=h.aabb,k=Z.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=h.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=Z.height,O=v.height;h.height=1+(L>O?L:O);let I=h.height,T=P.height;y.height=1+(I>T?I:T)}h=y}else if(w<-1){let v=Z.child1,P=Z.child2;if(Z.child1=h,Z.parent=h.parent,h.parent=Z,Z.parent!=null?Z.parent.child1==h?Z.parent.child1=Z:Z.parent.child2=Z:o.root=Z,v.height>P.height){Z.child2=v,h.child1=P,P.parent=h;let g=h.aabb,k=y.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=h.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=y.height,O=P.height;h.height=1+(L>O?L:O);let I=h.height,T=v.height;Z.height=1+(I>T?I:T)}else{Z.child2=P,h.child1=v,v.parent=h;let g=h.aabb,k=y.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=h.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=y.height,O=v.height;h.height=1+(L>O?L:O);let I=h.height,T=P.height;Z.height=1+(I>T?I:T)}h=Z}else h=h}let x=h.child1,b=h.child2,_=h.aabb,d=x.aabb,f=b.aabb;_.minx=d.minx<f.minx?d.minx:f.minx,_.miny=d.miny<f.miny?d.miny:f.miny,_.maxx=d.maxx>f.maxx?d.maxx:f.maxx,_.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let m=x.height,z=b.height;h.height=1+(m>z?m:z),h=h.parent}}else{o.root=p,p.parent=null;let c=r;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Oe.zpp_pool,Oe.zpp_pool=c}}}let l=e.aabb;if(!this.space.continuous&&n.zip_aabb&&n.body!=null)if(n.zip_aabb=!1,n.type==0){let o=n.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let b=h;for(h=h.next;h!=null;){let Z=h;u+=b.x*(Z.y-x.y);let y=Z.y*b.x-Z.x*b.y;c.localCOMx+=(b.x+Z.x)*y,c.localCOMy+=(b.y+Z.y)*y,x=b,b=Z,h=h.next}h=c.lverts.next;let _=h;u+=b.x*(_.y-x.y);let d=_.y*b.x-_.x*b.y;c.localCOMx+=(b.x+_.x)*d,c.localCOMy+=(b.y+_.y)*d,x=b,b=_,h=h.next;let f=h;u+=b.x*(f.y-x.y);let m=f.y*b.x-f.x*b.y;c.localCOMx+=(b.x+f.x)*m,c.localCOMy+=(b.y+f.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else{let o=n.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,u=o.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),h.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}let s=n.aabb;l.minx=s.minx-3,l.miny=s.miny-3,l.maxx=s.maxx+3,l.maxy=s.maxy+3;let i=(e.dyn=n.body.type==1?!1:!n.body.component.sleeping)?this.dtree:this.stree;if(i.root==null)i.root=e,i.root.parent=null;else{let o=e.aabb,r=i.root;for(;r.child1!=null;){let x=r.child1,b=r.child2,_=r.aabb,d=(_.maxx-_.minx+(_.maxy-_.miny))*2,f=nt.tmpaabb,m=r.aabb;f.minx=m.minx<o.minx?m.minx:o.minx,f.miny=m.miny<o.miny?m.miny:o.miny,f.maxx=m.maxx>o.maxx?m.maxx:o.maxx,f.maxy=m.maxy>o.maxy?m.maxy:o.maxy;let z=nt.tmpaabb,Z=(z.maxx-z.minx+(z.maxy-z.miny))*2,y=2*Z,w=2*(Z-d),v=nt.tmpaabb,P=x.aabb;v.minx=o.minx<P.minx?o.minx:P.minx,v.miny=o.miny<P.miny?o.miny:P.miny,v.maxx=o.maxx>P.maxx?o.maxx:P.maxx,v.maxy=o.maxy>P.maxy?o.maxy:P.maxy;let g;if(x.child1==null){let M=nt.tmpaabb;g=(M.maxx-M.minx+(M.maxy-M.miny))*2+w}else{let M=x.aabb,C=(M.maxx-M.minx+(M.maxy-M.miny))*2,L=nt.tmpaabb;g=(L.maxx-L.minx+(L.maxy-L.miny))*2-C+w}let k=nt.tmpaabb,N=b.aabb;k.minx=o.minx<N.minx?o.minx:N.minx,k.miny=o.miny<N.miny?o.miny:N.miny,k.maxx=o.maxx>N.maxx?o.maxx:N.maxx,k.maxy=o.maxy>N.maxy?o.maxy:N.maxy;let E;if(b.child1==null){let M=nt.tmpaabb;E=(M.maxx-M.minx+(M.maxy-M.miny))*2+w}else{let M=b.aabb,C=(M.maxx-M.minx+(M.maxy-M.miny))*2,L=nt.tmpaabb;E=(L.maxx-L.minx+(L.maxy-L.miny))*2-C+w}if(y<g&&y<E)break;r=g<E?x:b}let a=r,p=a.parent,c;Oe.zpp_pool==null?c=new Oe:(c=Oe.zpp_pool,Oe.zpp_pool=c.next,c.next=null),be.zpp_pool==null?c.aabb=new be:(c.aabb=be.zpp_pool,be.zpp_pool=c.aabb.next,c.aabb.next=null),c.moved=!1,c.synced=!1,c.first_sync=!1,c.parent=p;let u=c.aabb,h=a.aabb;for(u.minx=o.minx<h.minx?o.minx:h.minx,u.miny=o.miny<h.miny?o.miny:h.miny,u.maxx=o.maxx>h.maxx?o.maxx:h.maxx,u.maxy=o.maxy>h.maxy?o.maxy:h.maxy,c.height=a.height+1,p!=null?(p.child1==a?p.child1=c:p.child2=c,c.child1=a,c.child2=e,a.parent=c,e.parent=c):(c.child1=a,c.child2=e,a.parent=c,e.parent=c,i.root=c),r=e.parent;r!=null;){if(r.child1==null||r.height<2)r=r;else{let Z=r.child1,y=r.child2,w=y.height-Z.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=r,y.parent=r.parent,r.parent=y,y.parent!=null?y.parent.child1==r?y.parent.child1=y:y.parent.child2=y:i.root=y,v.height>P.height){y.child2=v,r.child2=P,P.parent=r;let g=r.aabb,k=Z.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=r.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=Z.height,O=P.height;r.height=1+(L>O?L:O);let I=r.height,T=v.height;y.height=1+(I>T?I:T)}else{y.child2=P,r.child2=v,v.parent=r;let g=r.aabb,k=Z.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=r.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=Z.height,O=v.height;r.height=1+(L>O?L:O);let I=r.height,T=P.height;y.height=1+(I>T?I:T)}r=y}else if(w<-1){let v=Z.child1,P=Z.child2;if(Z.child1=r,Z.parent=r.parent,r.parent=Z,Z.parent!=null?Z.parent.child1==r?Z.parent.child1=Z:Z.parent.child2=Z:i.root=Z,v.height>P.height){Z.child2=v,r.child1=P,P.parent=r;let g=r.aabb,k=y.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=r.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=y.height,O=P.height;r.height=1+(L>O?L:O);let I=r.height,T=v.height;Z.height=1+(I>T?I:T)}else{Z.child2=P,r.child1=v,v.parent=r;let g=r.aabb,k=y.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=r.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=y.height,O=v.height;r.height=1+(L>O?L:O);let I=r.height,T=P.height;Z.height=1+(I>T?I:T)}r=Z}else r=r}let x=r.child1,b=r.child2,_=x.height,d=b.height;r.height=1+(_>d?_:d);let f=r.aabb,m=x.aabb,z=b.aabb;f.minx=m.minx<z.minx?m.minx:z.minx,f.miny=m.miny<z.miny?m.miny:z.miny,f.maxx=m.maxx>z.maxx?m.maxx:z.maxx,f.maxy=m.maxy>z.maxy?m.maxy:z.maxy,r=r.parent}}e.synced=!1,e.moved=!0,e.mnext=e.snext,e.snext=null,e=e.mnext}let t=this.syncs;this.syncs=this.moves,this.moves=t}else for(;this.syncs!=null;){let e=this.syncs;this.syncs=e.snext,e.snext=null;let t=e,n=t.shape;if(t.first_sync)t.first_sync=!1;else{let o=t.dyn?this.dtree:this.stree;if(t==o.root)o.root=null;else{let r=t.parent,a=r.parent,p=r.child1==t?r.child2:r.child1;if(a!=null){a.child1==r?a.child1=p:a.child2=p,p.parent=a;let c=r;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Oe.zpp_pool,Oe.zpp_pool=c;let h=a;for(;h!=null;){if(h.child1==null||h.height<2)h=h;else{let Z=h.child1,y=h.child2,w=y.height-Z.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=h,y.parent=h.parent,h.parent=y,y.parent!=null?y.parent.child1==h?y.parent.child1=y:y.parent.child2=y:o.root=y,v.height>P.height){y.child2=v,h.child2=P,P.parent=h;let g=h.aabb,k=Z.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=h.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=Z.height,O=P.height;h.height=1+(L>O?L:O);let I=h.height,T=v.height;y.height=1+(I>T?I:T)}else{y.child2=P,h.child2=v,v.parent=h;let g=h.aabb,k=Z.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=h.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=Z.height,O=v.height;h.height=1+(L>O?L:O);let I=h.height,T=P.height;y.height=1+(I>T?I:T)}h=y}else if(w<-1){let v=Z.child1,P=Z.child2;if(Z.child1=h,Z.parent=h.parent,h.parent=Z,Z.parent!=null?Z.parent.child1==h?Z.parent.child1=Z:Z.parent.child2=Z:o.root=Z,v.height>P.height){Z.child2=v,h.child1=P,P.parent=h;let g=h.aabb,k=y.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=h.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=y.height,O=P.height;h.height=1+(L>O?L:O);let I=h.height,T=v.height;Z.height=1+(I>T?I:T)}else{Z.child2=P,h.child1=v,v.parent=h;let g=h.aabb,k=y.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=h.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=y.height,O=v.height;h.height=1+(L>O?L:O);let I=h.height,T=P.height;Z.height=1+(I>T?I:T)}h=Z}else h=h}let x=h.child1,b=h.child2,_=h.aabb,d=x.aabb,f=b.aabb;_.minx=d.minx<f.minx?d.minx:f.minx,_.miny=d.miny<f.miny?d.miny:f.miny,_.maxx=d.maxx>f.maxx?d.maxx:f.maxx,_.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let m=x.height,z=b.height;h.height=1+(m>z?m:z),h=h.parent}}else{o.root=p,p.parent=null;let c=r;c.height=-1;let u=c.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,c.child1=c.child2=c.parent=null,c.next=null,c.snext=null,c.mnext=null,c.next=Oe.zpp_pool,Oe.zpp_pool=c}}}let l=t.aabb;if(!this.space.continuous&&n.zip_aabb&&n.body!=null)if(n.zip_aabb=!1,n.type==0){let o=n.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let b=h;for(h=h.next;h!=null;){let Z=h;u+=b.x*(Z.y-x.y);let y=Z.y*b.x-Z.x*b.y;c.localCOMx+=(b.x+Z.x)*y,c.localCOMy+=(b.y+Z.y)*y,x=b,b=Z,h=h.next}h=c.lverts.next;let _=h;u+=b.x*(_.y-x.y);let d=_.y*b.x-_.x*b.y;c.localCOMx+=(b.x+_.x)*d,c.localCOMy+=(b.y+_.y)*d,x=b,b=_,h=h.next;let f=h;u+=b.x*(f.y-x.y);let m=f.y*b.x-f.x*b.y;c.localCOMx+=(b.x+f.x)*m,c.localCOMy+=(b.y+f.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else{let o=n.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,u=o.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),h.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}let s=n.aabb;l.minx=s.minx-3,l.miny=s.miny-3,l.maxx=s.maxx+3,l.maxy=s.maxy+3;let i=(t.dyn=n.body.type==1?!1:!n.body.component.sleeping)?this.dtree:this.stree;if(i.root==null)i.root=t,i.root.parent=null;else{let o=t.aabb,r=i.root;for(;r.child1!=null;){let x=r.child1,b=r.child2,_=r.aabb,d=(_.maxx-_.minx+(_.maxy-_.miny))*2,f=nt.tmpaabb,m=r.aabb;f.minx=m.minx<o.minx?m.minx:o.minx,f.miny=m.miny<o.miny?m.miny:o.miny,f.maxx=m.maxx>o.maxx?m.maxx:o.maxx,f.maxy=m.maxy>o.maxy?m.maxy:o.maxy;let z=nt.tmpaabb,Z=(z.maxx-z.minx+(z.maxy-z.miny))*2,y=2*Z,w=2*(Z-d),v=nt.tmpaabb,P=x.aabb;v.minx=o.minx<P.minx?o.minx:P.minx,v.miny=o.miny<P.miny?o.miny:P.miny,v.maxx=o.maxx>P.maxx?o.maxx:P.maxx,v.maxy=o.maxy>P.maxy?o.maxy:P.maxy;let g;if(x.child1==null){let M=nt.tmpaabb;g=(M.maxx-M.minx+(M.maxy-M.miny))*2+w}else{let M=x.aabb,C=(M.maxx-M.minx+(M.maxy-M.miny))*2,L=nt.tmpaabb;g=(L.maxx-L.minx+(L.maxy-L.miny))*2-C+w}let k=nt.tmpaabb,N=b.aabb;k.minx=o.minx<N.minx?o.minx:N.minx,k.miny=o.miny<N.miny?o.miny:N.miny,k.maxx=o.maxx>N.maxx?o.maxx:N.maxx,k.maxy=o.maxy>N.maxy?o.maxy:N.maxy;let E;if(b.child1==null){let M=nt.tmpaabb;E=(M.maxx-M.minx+(M.maxy-M.miny))*2+w}else{let M=b.aabb,C=(M.maxx-M.minx+(M.maxy-M.miny))*2,L=nt.tmpaabb;E=(L.maxx-L.minx+(L.maxy-L.miny))*2-C+w}if(y<g&&y<E)break;r=g<E?x:b}let a=r,p=a.parent,c;Oe.zpp_pool==null?c=new Oe:(c=Oe.zpp_pool,Oe.zpp_pool=c.next,c.next=null),be.zpp_pool==null?c.aabb=new be:(c.aabb=be.zpp_pool,be.zpp_pool=c.aabb.next,c.aabb.next=null),c.moved=!1,c.synced=!1,c.first_sync=!1,c.parent=p;let u=c.aabb,h=a.aabb;for(u.minx=o.minx<h.minx?o.minx:h.minx,u.miny=o.miny<h.miny?o.miny:h.miny,u.maxx=o.maxx>h.maxx?o.maxx:h.maxx,u.maxy=o.maxy>h.maxy?o.maxy:h.maxy,c.height=a.height+1,p!=null?(p.child1==a?p.child1=c:p.child2=c,c.child1=a,c.child2=t,a.parent=c,t.parent=c):(c.child1=a,c.child2=t,a.parent=c,t.parent=c,i.root=c),r=t.parent;r!=null;){if(r.child1==null||r.height<2)r=r;else{let Z=r.child1,y=r.child2,w=y.height-Z.height;if(w>1){let v=y.child1,P=y.child2;if(y.child1=r,y.parent=r.parent,r.parent=y,y.parent!=null?y.parent.child1==r?y.parent.child1=y:y.parent.child2=y:i.root=y,v.height>P.height){y.child2=v,r.child2=P,P.parent=r;let g=r.aabb,k=Z.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=r.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=Z.height,O=P.height;r.height=1+(L>O?L:O);let I=r.height,T=v.height;y.height=1+(I>T?I:T)}else{y.child2=P,r.child2=v,v.parent=r;let g=r.aabb,k=Z.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=y.aabb,M=r.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=Z.height,O=v.height;r.height=1+(L>O?L:O);let I=r.height,T=P.height;y.height=1+(I>T?I:T)}r=y}else if(w<-1){let v=Z.child1,P=Z.child2;if(Z.child1=r,Z.parent=r.parent,r.parent=Z,Z.parent!=null?Z.parent.child1==r?Z.parent.child1=Z:Z.parent.child2=Z:i.root=Z,v.height>P.height){Z.child2=v,r.child1=P,P.parent=r;let g=r.aabb,k=y.aabb,N=P.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=r.aabb,C=v.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=y.height,O=P.height;r.height=1+(L>O?L:O);let I=r.height,T=v.height;Z.height=1+(I>T?I:T)}else{Z.child2=P,r.child1=v,v.parent=r;let g=r.aabb,k=y.aabb,N=v.aabb;g.minx=k.minx<N.minx?k.minx:N.minx,g.miny=k.miny<N.miny?k.miny:N.miny,g.maxx=k.maxx>N.maxx?k.maxx:N.maxx,g.maxy=k.maxy>N.maxy?k.maxy:N.maxy;let E=Z.aabb,M=r.aabb,C=P.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=y.height,O=v.height;r.height=1+(L>O?L:O);let I=r.height,T=P.height;Z.height=1+(I>T?I:T)}r=Z}else r=r}let x=r.child1,b=r.child2,_=x.height,d=b.height;r.height=1+(_>d?_:d);let f=r.aabb,m=x.aabb,z=b.aabb;f.minx=m.minx<z.minx?m.minx:z.minx,f.miny=m.miny<z.miny?m.miny:z.miny,f.maxx=m.maxx>z.maxx?m.maxx:z.maxx,f.maxy=m.maxy>z.maxy?m.maxy:z.maxy,r=r.parent}}t.synced=!1,t.moved||(t.moved=!0,t.mnext=this.moves,this.moves=t)}}broadphase(e,t){let n=this.syncs;for(;n!=null;){let i=n.shape;if(n.first_sync)n.first_sync=!1;else{let p=n.dyn?this.dtree:this.stree;if(n==p.root)p.root=null;else{let c=n.parent,u=c.parent,h=c.child1==n?c.child2:c.child1;if(u!=null){u.child1==c?u.child1=h:u.child2=h,h.parent=u;let x=c;x.height=-1;let b=x.aabb;b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b.wrap_min=b.wrap_max=null,b._invalidate=null,b._validate=null,b.next=be.zpp_pool,be.zpp_pool=b,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Oe.zpp_pool,Oe.zpp_pool=x;let _=u;for(;_!=null;){if(_.child1==null||_.height<2)_=_;else{let v=_.child1,P=_.child2,g=P.height-v.height;if(g>1){let k=P.child1,N=P.child2;if(P.child1=_,P.parent=_.parent,_.parent=P,P.parent!=null?P.parent.child1==_?P.parent.child1=P:P.parent.child2=P:p.root=P,k.height>N.height){P.child2=k,_.child2=N,N.parent=_;let E=_.aabb,M=v.aabb,C=N.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=P.aabb,O=_.aabb,I=k.aabb;L.minx=O.minx<I.minx?O.minx:I.minx,L.miny=O.miny<I.miny?O.miny:I.miny,L.maxx=O.maxx>I.maxx?O.maxx:I.maxx,L.maxy=O.maxy>I.maxy?O.maxy:I.maxy;let T=v.height,W=N.height;_.height=1+(T>W?T:W);let R=_.height,G=k.height;P.height=1+(R>G?R:G)}else{P.child2=N,_.child2=k,k.parent=_;let E=_.aabb,M=v.aabb,C=k.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=P.aabb,O=_.aabb,I=N.aabb;L.minx=O.minx<I.minx?O.minx:I.minx,L.miny=O.miny<I.miny?O.miny:I.miny,L.maxx=O.maxx>I.maxx?O.maxx:I.maxx,L.maxy=O.maxy>I.maxy?O.maxy:I.maxy;let T=v.height,W=k.height;_.height=1+(T>W?T:W);let R=_.height,G=N.height;P.height=1+(R>G?R:G)}_=P}else if(g<-1){let k=v.child1,N=v.child2;if(v.child1=_,v.parent=_.parent,_.parent=v,v.parent!=null?v.parent.child1==_?v.parent.child1=v:v.parent.child2=v:p.root=v,k.height>N.height){v.child2=k,_.child1=N,N.parent=_;let E=_.aabb,M=P.aabb,C=N.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=v.aabb,O=_.aabb,I=k.aabb;L.minx=O.minx<I.minx?O.minx:I.minx,L.miny=O.miny<I.miny?O.miny:I.miny,L.maxx=O.maxx>I.maxx?O.maxx:I.maxx,L.maxy=O.maxy>I.maxy?O.maxy:I.maxy;let T=P.height,W=N.height;_.height=1+(T>W?T:W);let R=_.height,G=k.height;v.height=1+(R>G?R:G)}else{v.child2=N,_.child1=k,k.parent=_;let E=_.aabb,M=P.aabb,C=k.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=v.aabb,O=_.aabb,I=N.aabb;L.minx=O.minx<I.minx?O.minx:I.minx,L.miny=O.miny<I.miny?O.miny:I.miny,L.maxx=O.maxx>I.maxx?O.maxx:I.maxx,L.maxy=O.maxy>I.maxy?O.maxy:I.maxy;let T=P.height,W=k.height;_.height=1+(T>W?T:W);let R=_.height,G=N.height;v.height=1+(R>G?R:G)}_=v}else _=_}let d=_.child1,f=_.child2,m=_.aabb,z=d.aabb,Z=f.aabb;m.minx=z.minx<Z.minx?z.minx:Z.minx,m.miny=z.miny<Z.miny?z.miny:Z.miny,m.maxx=z.maxx>Z.maxx?z.maxx:Z.maxx,m.maxy=z.maxy>Z.maxy?z.maxy:Z.maxy;let y=d.height,w=f.height;_.height=1+(y>w?y:w),_=_.parent}}else{p.root=h,h.parent=null;let x=c;x.height=-1;let b=x.aabb;b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b.wrap_min=b.wrap_max=null,b._invalidate=null,b._validate=null,b.next=be.zpp_pool,be.zpp_pool=b,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Oe.zpp_pool,Oe.zpp_pool=x}}}let o=n.aabb;if(!e.continuous&&i.zip_aabb&&i.body!=null)if(i.zip_aabb=!1,i.type==0){let p=i.circle;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=!1,p.zip_localCOM){if(p.zip_localCOM=!1,p.type==1){let x=p.polygon;if(x.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(x.lverts.next.next==null)x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;else if(x.lverts.next.next.next==null){x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;let b=1;x.localCOMx+=x.lverts.next.next.x*b,x.localCOMy+=x.lverts.next.next.y*b;let _=.5;x.localCOMx*=_,x.localCOMy*=_}else{x.localCOMx=0,x.localCOMy=0;let b=0,_=x.lverts.next,d=_;_=_.next;let f=_;for(_=_.next;_!=null;){let v=_;b+=f.x*(v.y-d.y);let P=v.y*f.x-v.x*f.y;x.localCOMx+=(f.x+v.x)*P,x.localCOMy+=(f.y+v.y)*P,d=f,f=v,_=_.next}_=x.lverts.next;let m=_;b+=f.x*(m.y-d.y);let z=m.y*f.x-m.x*f.y;x.localCOMx+=(f.x+m.x)*z,x.localCOMy+=(f.y+m.y)*z,d=f,f=m,_=_.next;let Z=_;b+=f.x*(Z.y-d.y);let y=Z.y*f.x-Z.x*f.y;x.localCOMx+=(f.x+Z.x)*y,x.localCOMy+=(f.y+Z.y)*y,b=1/(3*b);let w=b;x.localCOMx*=w,x.localCOMy*=w}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let h=p.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy)}let c=p.radius,u=p.radius;p.aabb.minx=p.worldCOMx-c,p.aabb.miny=p.worldCOMy-u,p.aabb.maxx=p.worldCOMx+c,p.aabb.maxy=p.worldCOMy+u}else{let p=i.polygon;if(p.zip_gverts&&p.body!=null){p.zip_gverts=!1,p.validate_lverts();let h=p.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot));let x=p.lverts.next,b=p.gverts.next;for(;b!=null;){let _=b,d=x;x=x.next,_.x=p.body.posx+(p.body.axisy*d.x-p.body.axisx*d.y),_.y=p.body.posy+(d.x*p.body.axisx+d.y*p.body.axisy),b=b.next}}if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let c=p.gverts.next;p.aabb.minx=c.x,p.aabb.miny=c.y,p.aabb.maxx=c.x,p.aabb.maxy=c.y;let u=p.gverts.next.next;for(;u!=null;){let h=u;h.x<p.aabb.minx&&(p.aabb.minx=h.x),h.x>p.aabb.maxx&&(p.aabb.maxx=h.x),h.y<p.aabb.miny&&(p.aabb.miny=h.y),h.y>p.aabb.maxy&&(p.aabb.maxy=h.y),u=u.next}}let r=i.aabb;o.minx=r.minx-3,o.miny=r.miny-3,o.maxx=r.maxx+3,o.maxy=r.maxy+3;let a=(n.dyn=i.body.type==1?!1:!i.body.component.sleeping)?this.dtree:this.stree;if(a.root==null)a.root=n,a.root.parent=null;else{let p=n.aabb,c=a.root;for(;c.child1!=null;){let d=c.child1,f=c.child2,m=c.aabb,z=(m.maxx-m.minx+(m.maxy-m.miny))*2,Z=nt.tmpaabb,y=c.aabb;Z.minx=y.minx<p.minx?y.minx:p.minx,Z.miny=y.miny<p.miny?y.miny:p.miny,Z.maxx=y.maxx>p.maxx?y.maxx:p.maxx,Z.maxy=y.maxy>p.maxy?y.maxy:p.maxy;let w=nt.tmpaabb,v=(w.maxx-w.minx+(w.maxy-w.miny))*2,P=2*v,g=2*(v-z),k=nt.tmpaabb,N=d.aabb;k.minx=p.minx<N.minx?p.minx:N.minx,k.miny=p.miny<N.miny?p.miny:N.miny,k.maxx=p.maxx>N.maxx?p.maxx:N.maxx,k.maxy=p.maxy>N.maxy?p.maxy:N.maxy;let E;if(d.child1==null){let O=nt.tmpaabb;E=(O.maxx-O.minx+(O.maxy-O.miny))*2+g}else{let O=d.aabb,I=(O.maxx-O.minx+(O.maxy-O.miny))*2,T=nt.tmpaabb;E=(T.maxx-T.minx+(T.maxy-T.miny))*2-I+g}let M=nt.tmpaabb,C=f.aabb;M.minx=p.minx<C.minx?p.minx:C.minx,M.miny=p.miny<C.miny?p.miny:C.miny,M.maxx=p.maxx>C.maxx?p.maxx:C.maxx,M.maxy=p.maxy>C.maxy?p.maxy:C.maxy;let L;if(f.child1==null){let O=nt.tmpaabb;L=(O.maxx-O.minx+(O.maxy-O.miny))*2+g}else{let O=f.aabb,I=(O.maxx-O.minx+(O.maxy-O.miny))*2,T=nt.tmpaabb;L=(T.maxx-T.minx+(T.maxy-T.miny))*2-I+g}if(P<E&&P<L)break;c=E<L?d:f}let u=c,h=u.parent,x;Oe.zpp_pool==null?x=new Oe:(x=Oe.zpp_pool,Oe.zpp_pool=x.next,x.next=null),be.zpp_pool==null?x.aabb=new be:(x.aabb=be.zpp_pool,be.zpp_pool=x.aabb.next,x.aabb.next=null),x.moved=!1,x.synced=!1,x.first_sync=!1,x.parent=h;let b=x.aabb,_=u.aabb;for(b.minx=p.minx<_.minx?p.minx:_.minx,b.miny=p.miny<_.miny?p.miny:_.miny,b.maxx=p.maxx>_.maxx?p.maxx:_.maxx,b.maxy=p.maxy>_.maxy?p.maxy:_.maxy,x.height=u.height+1,h!=null?(h.child1==u?h.child1=x:h.child2=x,x.child1=u,x.child2=n,u.parent=x,n.parent=x):(x.child1=u,x.child2=n,u.parent=x,n.parent=x,a.root=x),c=n.parent;c!=null;){if(c.child1==null||c.height<2)c=c;else{let v=c.child1,P=c.child2,g=P.height-v.height;if(g>1){let k=P.child1,N=P.child2;if(P.child1=c,P.parent=c.parent,c.parent=P,P.parent!=null?P.parent.child1==c?P.parent.child1=P:P.parent.child2=P:a.root=P,k.height>N.height){P.child2=k,c.child2=N,N.parent=c;let E=c.aabb,M=v.aabb,C=N.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=P.aabb,O=c.aabb,I=k.aabb;L.minx=O.minx<I.minx?O.minx:I.minx,L.miny=O.miny<I.miny?O.miny:I.miny,L.maxx=O.maxx>I.maxx?O.maxx:I.maxx,L.maxy=O.maxy>I.maxy?O.maxy:I.maxy;let T=v.height,W=N.height;c.height=1+(T>W?T:W);let R=c.height,G=k.height;P.height=1+(R>G?R:G)}else{P.child2=N,c.child2=k,k.parent=c;let E=c.aabb,M=v.aabb,C=k.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=P.aabb,O=c.aabb,I=N.aabb;L.minx=O.minx<I.minx?O.minx:I.minx,L.miny=O.miny<I.miny?O.miny:I.miny,L.maxx=O.maxx>I.maxx?O.maxx:I.maxx,L.maxy=O.maxy>I.maxy?O.maxy:I.maxy;let T=v.height,W=k.height;c.height=1+(T>W?T:W);let R=c.height,G=N.height;P.height=1+(R>G?R:G)}c=P}else if(g<-1){let k=v.child1,N=v.child2;if(v.child1=c,v.parent=c.parent,c.parent=v,v.parent!=null?v.parent.child1==c?v.parent.child1=v:v.parent.child2=v:a.root=v,k.height>N.height){v.child2=k,c.child1=N,N.parent=c;let E=c.aabb,M=P.aabb,C=N.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=v.aabb,O=c.aabb,I=k.aabb;L.minx=O.minx<I.minx?O.minx:I.minx,L.miny=O.miny<I.miny?O.miny:I.miny,L.maxx=O.maxx>I.maxx?O.maxx:I.maxx,L.maxy=O.maxy>I.maxy?O.maxy:I.maxy;let T=P.height,W=N.height;c.height=1+(T>W?T:W);let R=c.height,G=k.height;v.height=1+(R>G?R:G)}else{v.child2=N,c.child1=k,k.parent=c;let E=c.aabb,M=P.aabb,C=k.aabb;E.minx=M.minx<C.minx?M.minx:C.minx,E.miny=M.miny<C.miny?M.miny:C.miny,E.maxx=M.maxx>C.maxx?M.maxx:C.maxx,E.maxy=M.maxy>C.maxy?M.maxy:C.maxy;let L=v.aabb,O=c.aabb,I=N.aabb;L.minx=O.minx<I.minx?O.minx:I.minx,L.miny=O.miny<I.miny?O.miny:I.miny,L.maxx=O.maxx>I.maxx?O.maxx:I.maxx,L.maxy=O.maxy>I.maxy?O.maxy:I.maxy;let T=P.height,W=k.height;c.height=1+(T>W?T:W);let R=c.height,G=N.height;v.height=1+(R>G?R:G)}c=v}else c=c}let d=c.child1,f=c.child2,m=d.height,z=f.height;c.height=1+(m>z?m:z);let Z=c.aabb,y=d.aabb,w=f.aabb;Z.minx=y.minx<w.minx?y.minx:w.minx,Z.miny=y.miny<w.miny?y.miny:w.miny,Z.maxx=y.maxx>w.maxx?y.maxx:w.maxx,Z.maxy=y.maxy>w.maxy?y.maxy:w.maxy,c=c.parent}}n.synced=!1,n=n.snext}for(;this.syncs!=null;){let i=this.syncs;this.syncs=i.snext,i.snext=null;let o=i;if(o.moved)continue;o.moved=!1;let r=o.shape;if(r.body.component.sleeping)continue;let p=o.aabb,c=null;for(this.dtree.root!=null&&(this.dtree.root.next=c,c=this.dtree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=o)if(h.child1==null){let x=h.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let b=h.aabb;if(b.miny<=p.maxy&&p.miny<=b.maxy&&b.minx<=p.maxx&&p.minx<=b.maxx){let _,d;r.id<x.id?(_=r.id,d=x.id):(_=x.id,d=r.id);let f=r.pairs.length<x.pairs.length?r:x,m=null,z=f.pairs.head;for(;z!=null;){let k=z.elt;if(k.id==_&&k.di==d){m=k;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}tt.zpp_pool==null?m=new tt:(m=tt.zpp_pool,tt.zpp_pool=m.next,m.next=null),m.n1=o,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let Z=r.pairs,y;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(y=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++;let v=x.pairs,P;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(P=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=o)if(h.child1==null){let x=h.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let b=h.aabb;if(b.miny<=p.maxy&&p.miny<=b.maxy&&b.minx<=p.maxx&&p.minx<=b.maxx){let _,d;r.id<x.id?(_=r.id,d=x.id):(_=x.id,d=r.id);let f=r.pairs.length<x.pairs.length?r:x,m=null,z=f.pairs.head;for(;z!=null;){let k=z.elt;if(k.id==_&&k.di==d){m=k;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}tt.zpp_pool==null?m=new tt:(m=tt.zpp_pool,tt.zpp_pool=m.next,m.next=null),m.n1=o,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let Z=r.pairs,y;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(y=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++;let v=x.pairs,P;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(P=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}}for(;this.moves!=null;){let i=this.moves;this.moves=i.mnext,i.mnext=null;let o=i;o.moved=!1;let r=o.shape;if(r.body.component.sleeping)continue;let p=o.aabb,c=null;for(this.dtree.root!=null&&(this.dtree.root.next=c,c=this.dtree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=o)if(h.child1==null){let x=h.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let b=h.aabb;if(b.miny<=p.maxy&&p.miny<=b.maxy&&b.minx<=p.maxx&&p.minx<=b.maxx){let _,d;r.id<x.id?(_=r.id,d=x.id):(_=x.id,d=r.id);let f=r.pairs.length<x.pairs.length?r:x,m=null,z=f.pairs.head;for(;z!=null;){let k=z.elt;if(k.id==_&&k.di==d){m=k;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}tt.zpp_pool==null?m=new tt:(m=tt.zpp_pool,tt.zpp_pool=m.next,m.next=null),m.n1=o,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let Z=r.pairs,y;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(y=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++;let v=x.pairs,P;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(P=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let u=c;c=u.next,u.next=null;let h=u;if(h!=o)if(h.child1==null){let x=h.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let b=h.aabb;if(b.miny<=p.maxy&&p.miny<=b.maxy&&b.minx<=p.maxx&&p.minx<=b.maxx){let _,d;r.id<x.id?(_=r.id,d=x.id):(_=x.id,d=r.id);let f=r.pairs.length<x.pairs.length?r:x,m=null,z=f.pairs.head;for(;z!=null;){let k=z.elt;if(k.id==_&&k.di==d){m=k;break}z=z.next}if(m!=null){m.sleeping&&(m.sleeping=!1,m.next=this.pairs,this.pairs=m,m.first=!0);continue}tt.zpp_pool==null?m=new tt:(m=tt.zpp_pool,tt.zpp_pool=m.next,m.next=null),m.n1=o,m.n2=h,m.id=_,m.di=d,m.next=this.pairs,this.pairs=m,m.first=!0;let Z=r.pairs,y;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?y=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(y=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=y.next,y.next=null),y.elt=m;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++;let v=x.pairs,P;fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new fe._zpp.util.ZNPNode_ZPP_AABBPair:(P=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=m;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++}}}else{let x=h.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(h.child1!=null&&(h.child1.next=c,c=h.child1),h.child2!=null&&(h.child2.next=c,c=h.child2))}}}let l=null,s=this.pairs;for(;s!=null;){let i;if(s.first)i=!1;else{let h=s.n1.aabb,x=s.n2.aabb;i=!(x.miny<=h.maxy&&h.miny<=x.maxy&&x.minx<=h.maxx&&h.minx<=x.maxx)}if(i){l==null?this.pairs=s.next:l.next=s.next;let h=s.n1.shape.pairs,x=null,b=h.head,_=!1;for(;b!=null;){if(b.elt==s){let w,v;x==null?(w=h.head,v=w.next,h.head=v,h.head==null&&(h.pushmod=!0)):(w=x.next,v=w.next,x.next=v,v==null&&(h.pushmod=!0));let P=w;P.elt=null,P.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P,h.modified=!0,h.length--,h.pushmod=!0,_=!0;break}x=b,b=b.next}let d=s.n2.shape.pairs,f=null,m=d.head,z=!1;for(;m!=null;){if(m.elt==s){let w,v;f==null?(w=d.head,v=w.next,d.head=v,d.head==null&&(d.pushmod=!0)):(w=f.next,v=w.next,f.next=v,v==null&&(d.pushmod=!0));let P=w;P.elt=null,P.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P,d.modified=!0,d.length--,d.pushmod=!0,z=!0;break}f=m,m=m.next}let Z=s.next;s.arb!=null&&(s.arb.pair=null),s.arb=null;let y=s;y.n1=y.n2=null,y.sleeping=!1,y.next=tt.zpp_pool,tt.zpp_pool=y,s=Z;continue}let o=s.n1.shape,r=o.body,a=s.n2.shape,p=a.body;if(!s.first&&(r.component.sleeping||r.type==1)&&(p.component.sleeping||p.type==1)){s.sleeping=!0,l==null?this.pairs=s.next:l.next=s.next,s=s.next;continue}s.first=!1;let c=o.aabb,u=a.aabb;if(u.miny<=c.maxy&&c.miny<=u.maxy&&u.minx<=c.maxx&&c.minx<=u.maxx){let h=s.arb;t?s.arb=e.narrowPhase(o,a,r.type!=2||p.type!=2,s.arb,!1):s.arb=e.continuousEvent(o,a,r.type!=2||p.type!=2,s.arb,!1),s.arb==null?h!=null&&(h.pair=null):s.arb.pair=s}l=s,s=s.next}}clear(){for(;this.syncs!=null;){let e=this.syncs.snext;this.syncs.snext=null,this.syncs.first_sync&&(this.syncs.shape.node=null,this.syncs.shape.removedFromSpace(),this.syncs.shape=null),this.syncs=e}for(;this.moves!=null;){let e=this.moves.mnext;this.moves.mnext=null,this.moves.first_sync&&(this.moves.shape.node=null,this.moves.shape.removedFromSpace(),this.moves.shape=null),this.moves=e}for(;this.pairs!=null;){let e=this.pairs.next;this.pairs.arb!=null&&(this.pairs.arb.pair=null),this.pairs.arb=null;let t=this.pairs.n1.shape.pairs,n=this.pairs,l=null,s=t.head,i=!1;for(;s!=null;){if(s.elt==n){let h,x;l==null?(h=t.head,x=h.next,t.head=x,t.head==null&&(t.pushmod=!0)):(h=l.next,x=h.next,l.next=x,x==null&&(t.pushmod=!0));let b=h;b.elt=null,b.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b,t.modified=!0,t.length--,t.pushmod=!0,i=!0;break}l=s,s=s.next}let o=this.pairs.n2.shape.pairs,r=this.pairs,a=null,p=o.head,c=!1;for(;p!=null;){if(p.elt==r){let h,x;a==null?(h=o.head,x=h.next,o.head=x,o.head==null&&(o.pushmod=!0)):(h=a.next,x=h.next,a.next=x,x==null&&(o.pushmod=!0));let b=h;b.elt=null,b.next=fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b,o.modified=!0,o.length--,o.pushmod=!0,c=!0;break}a=p,p=p.next}let u=this.pairs;u.n1=u.n2=null,u.sleeping=!1,u.next=tt.zpp_pool,tt.zpp_pool=u,this.pairs=e}this.dtree.clear(),this.stree.clear()}shapesUnderPoint(e,t,n,l){this.sync_broadphase();let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,o=l??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c;if(n!=null){let u=a.shape.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(a.shape.type==0?Ee.circleContains(a.shape.circle,i)&&o.push(a.shape.outer):Ee.polyContains(a.shape.polygon,i)&&o.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c;if(n!=null){let u=a.shape.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(a.shape.type==0?Ee.circleContains(a.shape.circle,i)&&o.push(a.shape.outer):Ee.polyContains(a.shape.polygon,i)&&o.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}let r=i;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=le.zpp_pool,le.zpp_pool=r,o}bodiesUnderPoint(e,t,n,l){this.sync_broadphase();let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,o=l??new fe._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c=a.shape.body.outer;if(!o.has(c)){let u;if(n!=null){let h=a.shape.filter;u=(h.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(a.shape.type==0?Ee.circleContains(a.shape.circle,i)&&o.push(c):Ee.polyContains(a.shape.polygon,i)&&o.push(c))}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(i.x>=p.minx&&i.x<=p.maxx&&i.y>=p.miny&&i.y<=p.maxy)if(a.child1==null){let c=a.shape.body.outer;if(!o.has(c)){let u;if(n!=null){let h=a.shape.filter;u=(h.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(a.shape.type==0?Ee.circleContains(a.shape.circle,i)&&o.push(c):Ee.polyContains(a.shape.polygon,i)&&o.push(c))}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}let r=i;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=le.zpp_pool,le.zpp_pool=r,o}shapesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,o=s??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(r.child1==null){let p;if(l!=null){let c=r.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;p&&o.push(r.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;c&&o.push(p.shape.outer)}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=r.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(r.child1==null){let c;if(l!=null){let u=r.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c)if(t)if(n)Ee.containTest(this.aabbShape.zpp_inner,r.shape)&&o.push(r.shape.outer);else{let u=r.shape.aabb;(u.minx>=i.minx&&u.miny>=i.miny&&u.maxx<=i.maxx&&u.maxy<=i.maxy||Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner))&&o.push(r.shape.outer)}else{let u;if(n){let h=r.shape.aabb;u=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy}else u=!0;u&&o.push(r.shape.outer)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(r.child1==null){let p;if(l!=null){let c=r.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;p&&o.push(r.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;c&&o.push(p.shape.outer)}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=r.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(r.child1==null){let c;if(l!=null){let u=r.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c)if(t)if(n)Ee.containTest(this.aabbShape.zpp_inner,r.shape)&&o.push(r.shape.outer);else{let u=r.shape.aabb;(u.minx>=i.minx&&u.miny>=i.miny&&u.maxx<=i.maxx&&u.maxy<=i.maxy||Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner))&&o.push(r.shape.outer)}else{let u;if(n){let h=r.shape.aabb;u=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy}else u=!0;u&&o.push(r.shape.outer)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}return o}bodiesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,o=s??new fe._nape.phys.BodyList;if(this.failed==null&&(this.failed=new fe._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(r.child1==null){let p;if(l!=null){let c=r.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;if(p){let c=r.shape.body.outer;o.has(c)||o.push(c)}}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c){let u=p.shape.body.outer;o.has(u)||o.push(u)}}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=r.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(r.child1==null){let c=r.shape.body.outer,u;if(l!=null){let h=r.shape.filter;u=(h.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(t)if(n){if(!this.failed.has(c)){let h=Ee.containTest(this.aabbShape.zpp_inner,r.shape);!o.has(c)&&h?o.push(c):h||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner)&&o.push(c);else if(n){if(!this.failed.has(c)){let h=r.shape.aabb,x=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy;!o.has(c)&&x?o.push(c):x||(o.remove(c),this.failed.push(c))}}else{let h;if(o.has(c))h=!1;else{let x=r.shape.aabb;h=x.minx>=i.minx&&x.miny>=i.miny&&x.maxx<=i.maxx&&x.maxy<=i.maxy}h&&o.push(c)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(a.minx>=i.minx&&a.miny>=i.miny&&a.maxx<=i.maxx&&a.maxy<=i.maxy)if(r.child1==null){let p;if(l!=null){let c=r.shape.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;if(p){let c=r.shape.body.outer;o.has(c)||o.push(c)}}else for(this.treeStack2==null&&(this.treeStack2=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);this.treeStack2.head!=null;){let p=this.treeStack2.pop_unsafe();if(p.child1==null){let c;if(l!=null){let u=p.shape.filter;c=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else c=!0;if(c){let u=p.shape.body.outer;o.has(u)||o.push(u)}}else p.child1!=null&&this.treeStack2.add(p.child1),p.child2!=null&&this.treeStack2.add(p.child2)}else{let p=r.aabb;if(i.miny<=p.maxy&&p.miny<=i.maxy&&i.minx<=p.maxx&&p.minx<=i.maxx)if(r.child1==null){let c=r.shape.body.outer,u;if(l!=null){let h=r.shape.filter;u=(h.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(t)if(n){if(!this.failed.has(c)){let h=Ee.containTest(this.aabbShape.zpp_inner,r.shape);!o.has(c)&&h?o.push(c):h||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner)&&o.push(c);else if(n){if(!this.failed.has(c)){let h=r.shape.aabb,x=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy;!o.has(c)&&x?o.push(c):x||(o.remove(c),this.failed.push(c))}}else{let h;if(o.has(c))h=!1;else{let x=r.shape.aabb;h=x.minx>=i.minx&&x.miny>=i.miny&&x.maxx<=i.maxx&&x.maxy<=i.maxy}h&&o.push(c)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}return this.failed.clear(),o}shapesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let o=this.circShape.zpp_inner.aabb,r=i??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx)if(a.child1==null){let c;if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(l?Ee.containTest(this.circShape.zpp_inner,a.shape)&&r.push(a.shape.outer):Ee.testCollide_safe(a.shape,this.circShape.zpp_inner)&&r.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx)if(a.child1==null){let c;if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(l?Ee.containTest(this.circShape.zpp_inner,a.shape)&&r.push(a.shape.outer):Ee.testCollide_safe(a.shape,this.circShape.zpp_inner)&&r.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return r}bodiesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let o=this.circShape.zpp_inner.aabb,r=i??new fe._nape.phys.BodyList;if(this.failed==null&&(this.failed=new fe._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx)if(a.child1==null){let c=a.shape.body.outer,u;if(s!=null){let h=a.shape.filter;u=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(l){if(!this.failed.has(c)){let h=Ee.containTest(this.circShape.zpp_inner,a.shape);!r.has(c)&&h?r.push(c):h||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ee.testCollide_safe(a.shape,this.circShape.zpp_inner)&&r.push(c)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx)if(a.child1==null){let c=a.shape.body.outer,u;if(s!=null){let h=a.shape.filter;u=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(l){if(!this.failed.has(c)){let h=Ee.containTest(this.circShape.zpp_inner,a.shape);!r.has(c)&&h?r.push(c):h||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ee.testCollide_safe(a.shape,this.circShape.zpp_inner)&&r.push(c)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return this.failed.clear(),r}shapesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new fe._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx)if(o.child1==null){let a;if(n!=null){let p=o.shape.filter;a=(p.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&p.collisionGroup)!=0}else a=!0;a&&(t?Ee.containTest(e,o.shape)&&i.push(o.shape.outer):Ee.testCollide_safe(o.shape,e)&&i.push(o.shape.outer))}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx)if(o.child1==null){let a;if(n!=null){let p=o.shape.filter;a=(p.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&p.collisionGroup)!=0}else a=!0;a&&(t?Ee.containTest(e,o.shape)&&i.push(o.shape.outer):Ee.testCollide_safe(o.shape,e)&&i.push(o.shape.outer))}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}return i}bodiesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new fe._nape.phys.BodyList;if(this.failed==null&&(this.failed=new fe._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx)if(o.child1==null){let a=o.shape.body.outer,p;if(n!=null){let c=o.shape.filter;p=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else p=!0;if(p)if(t){if(!this.failed.has(a)){let c=Ee.containTest(e,o.shape);!i.has(a)&&c?i.push(a):c||(i.remove(a),this.failed.push(a))}}else!i.has(a)&&Ee.testCollide_safe(o.shape,e)&&i.push(a)}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx)if(o.child1==null){let a=o.shape.body.outer,p;if(n!=null){let c=o.shape.filter;p=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else p=!0;if(p)if(t){if(!this.failed.has(a)){let c=Ee.containTest(e,o.shape);!i.has(a)&&c?i.push(a):c||(i.remove(a),this.failed.push(a))}}else!i.has(a)&&Ee.testCollide_safe(o.shape,e)&&i.push(a)}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2)}return this.failed.clear(),i}rayCast(e,t,n){this.openlist==null&&(this.openlist=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),e.validate_dir();let l=e.maxdist;if(this.dtree.root!=null&&e.aabbtest(this.dtree.root.aabb)){let i=e.aabbsect(this.dtree.root.aabb);if(i>=0&&i<l){this.dtree.root.rayt=i;let o=null,r=this.openlist.head;for(;r!=null;){let h=r.elt;if(this.dtree.root.rayt<h.rayt)break;o=r,r=r.next}let a=this.openlist,p=this.dtree.root,c;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?c=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(c=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=c.next,c.next=null),c.elt=p;let u=c;o==null?(u.next=a.head,a.head=u):(u.next=o.next,o.next=u),a.pushmod=a.modified=!0,a.length++}}if(this.stree.root!=null&&e.aabbtest(this.stree.root.aabb)){let i=e.aabbsect(this.stree.root.aabb);if(i>=0&&i<l){this.stree.root.rayt=i;let o=null,r=this.openlist.head;for(;r!=null;){let h=r.elt;if(this.stree.root.rayt<h.rayt)break;o=r,r=r.next}let a=this.openlist,p=this.stree.root,c;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?c=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(c=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=c.next,c.next=null),c.elt=p;let u=c;o==null?(u.next=a.head,a.head=u):(u.next=o.next,o.next=u),a.pushmod=a.modified=!0,a.length++}}let s=null;for(;this.openlist.head!=null;){let i=this.openlist.pop_unsafe();if(i.rayt>=l)break;if(i.child1==null){let o=i.shape,r;if(n!=null){let a=o.filter;r=(a.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&a.collisionGroup)!=0}else r=!0;if(r){let a=o.type==0?e.circlesect(o.circle,t,l):e.aabbtest(o.aabb)?e.polysect(o.polygon,t,l):null;if(a!=null){if(a.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=a.zpp_inner.toiDistance,s!=null){if(s.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");s.zpp_inner.free()}s=a}}}else{if(i.child1!=null&&e.aabbtest(i.child1.aabb)){let o=e.aabbsect(i.child1.aabb);if(o>=0&&o<l){i.child1.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(i.child1.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=i.child1,u;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(u=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=c;let h=u;r==null?(h.next=p.head,p.head=h):(h.next=r.next,r.next=h),p.pushmod=p.modified=!0,p.length++}}if(i.child2!=null&&e.aabbtest(i.child2.aabb)){let o=e.aabbsect(i.child2.aabb);if(o>=0&&o<l){i.child2.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(i.child2.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=i.child2,u;fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new fe._zpp.util.ZNPNode_ZPP_AABBNode:(u=fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,fe._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=c;let h=u;r==null?(h.next=p.head,p.head=h):(h.next=r.next,r.next=h),p.pushmod=p.modified=!0,p.length++}}}}return this.openlist.clear(),s}rayMultiCast(e,t,n,l){this.openlist==null&&(this.openlist=new fe._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),e.validate_dir();let s=e.maxdist>=1/0,i=l??new fe._nape.geom.RayResultList;if(this.dtree.root!=null&&e.aabbtest(this.dtree.root.aabb))if(s)this.openlist.add(this.dtree.root);else{let o=e.aabbsect(this.dtree.root.aabb);o>=0&&o<e.maxdist&&this.openlist.add(this.dtree.root)}if(this.stree.root!=null&&e.aabbtest(this.stree.root.aabb))if(s)this.openlist.add(this.stree.root);else{let o=e.aabbsect(this.stree.root.aabb);o>=0&&o<e.maxdist&&this.openlist.add(this.stree.root)}for(;this.openlist.head!=null;){let o=this.openlist.pop_unsafe();if(o.child1==null){let r=o.shape,a;if(n!=null){let p=r.filter;a=(p.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&p.collisionGroup)!=0}else a=!0;a&&(r.type==0?e.circlesect2(r.circle,t,i):e.aabbtest(r.aabb)&&e.polysect2(r.polygon,t,i))}else{if(o.child1!=null&&e.aabbtest(o.child1.aabb))if(s)this.openlist.add(o.child1);else{let r=e.aabbsect(o.child1.aabb);r>=0&&r<e.maxdist&&this.openlist.add(o.child1)}if(o.child2!=null&&e.aabbtest(o.child2.aabb))if(s)this.openlist.add(o.child2);else{let r=e.aabbsect(o.child2.aabb);r>=0&&r<e.maxdist&&this.openlist.add(o.child2)}}}return this.openlist.clear(),i}};fe.__name__=["zpp_nape","space","ZPP_DynAABBPhase"],fe.__super__=null,fe._zpp=null,fe._nape=null,fe.FATTEN=3,fe.VEL_STEPS=2;var as=fe;var Es=class Es{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 Es._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}};Es.__name__=["zpp_nape","space","ZPP_Island"],Es.zpp_pool=null,Es._zpp=null;var bt=Es;var Ns=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}};Ns.__name__=["zpp_nape","space","ZPP_Component"],Ns.zpp_pool=null;var On=class On{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 On._zpp.util.ZNPList_ZPP_Arbiter}static get(e,t){let n;return On.zpp_pool==null?n=new On:(n=On.zpp_pool,On.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=On._zpp.util.ZNPNode_ZPP_Arbiter;i.zpp_pool==null?s=new i:(s=i.zpp_pool,i.zpp_pool=s.next,s.next=null),s.elt=e;let o=s;return o.next=l.head,l.head=o,l.modified=!0,l.length++,!0}}try_remove_arb(e){let t=this.arbiters,n=null,l=t.head,s=!1;for(;l!=null;){if(l.elt==e){let i,o;n==null?(i=t.head,o=i.next,t.head=o,t.head==null&&(t.pushmod=!0)):(i=n.next,o=i.next,n.next=o,o==null&&(t.pushmod=!0));let r=i;r.elt=null;let a=On._zpp.util.ZNPNode_ZPP_Arbiter;r.next=a.zpp_pool,a.zpp_pool=r,t.modified=!0,t.length--,t.pushmod=!0,s=!0;break}n=l,l=l.next}return s}remove_arb(e){let t=this.arbiters,n=null,l=t.head;for(;l!=null;){if(l.elt==e){let s,i;n==null?(s=t.head,i=s.next,t.head=i,t.head==null&&(t.pushmod=!0)):(s=n.next,i=s.next,n.next=i,i==null&&(t.pushmod=!0));let o=s;o.elt=null;let r=On._zpp.util.ZNPNode_ZPP_Arbiter;o.next=r.zpp_pool,r.zpp_pool=o,t.modified=!0,t.length--,t.pushmod=!0;break}n=l,l=l.next}}empty_arb(e){let t=!0,n=this.arbiters.head;for(;n!=null;)if((n.elt.type&e)==0){n=n.next;continue}else{t=!1;break}return t}really_empty(){return this.arbiters.head==null}sleeping(){let e=!0,t=this.arbiters.head;for(;t!=null;)if(t.elt.sleeping){t=t.next;continue}else{e=!1;break}return e}};On.__name__=["zpp_nape","space","ZPP_CallbackSet"],On.zpp_pool=null,On._zpp=null;var Ht=On;var ei=class ei{constructor(e){this.cbsets=null;this.space=null;let t=ei._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=ei._zpp.callbacks.ZPP_CbSet.setlt,this.space=e}get(e){if(e.head==null)return null;let t=ei._zpp.callbacks.ZPP_CbSet,n;t.zpp_pool==null?n=new t:(n=t.zpp_pool,t.zpp_pool=n.next,n.next=null);let l=n.cbTypes;n.cbTypes=e;let s=this.cbsets.find_weak(n),i;if(s!=null)i=s.data;else{let r=t.get(e);this.cbsets.insert(r),r.manager=this,i=r}n.cbTypes=l;let o=n;for(o.listeners.clear(),o.zip_listeners=!0,o.bodylisteners.clear(),o.zip_bodylisteners=!0,o.conlisteners.clear(),o.zip_conlisteners=!0;o.cbTypes.head!=null;)o.cbTypes.pop_unsafe().cbsets.remove(o);return o.next=t.zpp_pool,t.zpp_pool=o,i}remove(e){let t=ei._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=ei._zpp.callbacks.ZPP_CbSet,l=ei._zpp.callbacks.ZPP_CbSetPair,s=null,o=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;o!=null;){let r=o.elt;if(r.a==e&&r.b==t||r.a==t&&r.b==e){s=r;break}o=o.next}if(s==null){let r;l.zpp_pool==null?r=new l:(r=l.zpp_pool,l.zpp_pool=r.next,r.next=null),r.zip_listeners=!0,n.setlt(e,t)?(r.a=e,r.b=t):(r.a=t,r.b=e),s=r,e.cbpairs.add(s),t!=e&&t.cbpairs.add(s)}return s.zip_listeners&&(s.zip_listeners=!1,s.__validate()),s}valid_listener(e){return e.space==this.space}};ei.__name__=["zpp_nape","space","ZPP_CbSetManager"],ei._zpp=null;var ps=ei;var A=class A{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__=A;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 A._zpp.util.ZNPList_ZPP_ToiEvent,this.global_lin_drag=.015,this.global_ang_drag=.015,Rt.internal=!0,this.precb=Rt._createPreCb(),this.precb.zpp_inner=new Rt,Rt.internal=!1,this.sortcontacts=!0,this.pre_dt=0;let n;t!=null?(U.Broadphase_DYNAMIC_AABB_TREE==null&&(U.internal=!0,U.Broadphase_DYNAMIC_AABB_TREE=new A._nape.space.Broadphase,U.internal=!1),n=t==U.Broadphase_DYNAMIC_AABB_TREE):n=!0,n?this.bphase=new A._zpp.space.ZPP_DynAABBPhase(this):(U.Broadphase_SWEEP_AND_PRUNE==null&&(U.internal=!0,U.Broadphase_SWEEP_AND_PRUNE=new A._nape.space.Broadphase,U.internal=!1),t==U.Broadphase_SWEEP_AND_PRUNE&&(this.bphase=new A._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 A._zpp.util.ZNPList_ZPP_Body,this.wrap_bodies=A._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 A._zpp.util.ZNPList_ZPP_Compound,this.wrap_compounds=A._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 A._zpp.util.ZNPList_ZPP_Body,this.c_arbiters_true=new A._zpp.util.ZNPList_ZPP_ColArbiter,this.c_arbiters_false=new A._zpp.util.ZNPList_ZPP_ColArbiter,this.f_arbiters=new A._zpp.util.ZNPList_ZPP_FluidArbiter,this.s_arbiters=new A._zpp.util.ZNPList_ZPP_SensorArbiter,this.islands=new bt,this.live=new A._zpp.util.ZNPList_ZPP_Body,this.wrap_live=A._zpp.util.ZPP_BodyList.get(this.live,!0),this.staticsleep=new A._zpp.util.ZNPList_ZPP_Body,this.constraints=new A._zpp.util.ZNPList_ZPP_Constraint,this.wrap_constraints=A._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 A._zpp.util.ZNPList_ZPP_Constraint,this.wrap_livecon=A._zpp.util.ZPP_ConstraintList.get(this.live_constraints,!0),this.__static=En.__static(),this.__static.zpp_inner.space=this,this.callbacks=new Rt,this.midstep=!1,this.listeners=new A._zpp.util.ZNPList_ZPP_Listener,this.wrap_listeners=A._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 Ht,this.mrca1=new A._zpp.util.ZNPList_ZPP_Interactor,this.mrca2=new A._zpp.util.ZNPList_ZPP_Interactor,this.prelisteners=new A._zpp.util.ZNPList_ZPP_InteractionListener,this.cbsets=new ps(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(A._zpp.util.ZPP_PubPool.poolVec2==null?n=new A._nape.geom.Vec2:(n=A._zpp.util.ZPP_PubPool.poolVec2,A._zpp.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==A._zpp.util.ZPP_PubPool.nextVec2&&(A._zpp.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=e,l.y=t,n.zpp_inner=l,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=n.zpp_inner;if(i._validate!=null&&i._validate(),n.zpp_inner.x==e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),s=n.zpp_inner.y==t}else s=!1;if(!s){n.zpp_inner.x=e,n.zpp_inner.y=t;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.wrap_gravity=n,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=l=>this.gravity_invalidate(l),this.wrap_gravity.zpp_inner._validate=()=>this.gravity_validate()}gravity_invalidate(e){if(this.midstep)throw new Error("Error: Space::gravity cannot be set during space step");this.gravityx=e.x,this.gravityy=e.y;let t=new A._zpp.util.ZNPList_ZPP_Compound,n=this.bodies.head;for(;n!=null;){let i=n.elt;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1)),n=n.next}let l=this.compounds.head;for(;l!=null;){let s=l.elt;t.add(s),l=l.next}for(;t.head!=null;){let s=t.pop_unsafe(),i=s.bodies.head;for(;i!=null;){let a=i.elt;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1)),i=i.next}let o=s.compounds.head;for(;o!=null;){let r=o.elt;t.add(r),o=o.next}}}gravity_validate(){this.wrap_gravity.zpp_inner.x=this.gravityx,this.wrap_gravity.zpp_inner.y=this.gravityy}clear(){for(;this.listeners.head!=null;){let t=this.listeners.pop_unsafe();this.remListener(t)}for(;this.callbackset_list.next!=null;){let t=this.callbackset_list.pop_unsafe();t.arbiters.clear();let n=t;n.int1=n.int2=null,n.id=n.di=-1,n.freed=!0,n.next=Ht.zpp_pool,Ht.zpp_pool=n}for(;this.c_arbiters_true.head!=null;){let t=this.c_arbiters_true.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,o=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,o=!0;break}s=i,i=i.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=r.head,h=u.next,r.head=h,r.head==null&&(r.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(r.pushmod=!0));let x=u;x.elt=null,x.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let l=t.contacts,s=l.next;l.pop();let i=s;i.arbiter=null,i.next=ve.zpp_pool,ve.zpp_pool=i;let o=t.innards,r=o.next;o.next=r.next,r._inuse=!1,o.next==null&&(o.pushmod=!0),o.modified=!0,o.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=dt.zpp_pool,dt.zpp_pool=n,t.pre_dt=-1}for(;this.c_arbiters_false.head!=null;){let t=this.c_arbiters_false.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,o=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,o=!0;break}s=i,i=i.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=r.head,h=u.next,r.head=h,r.head==null&&(r.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(r.pushmod=!0));let x=u;x.elt=null,x.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let l=t.contacts,s=l.next;l.pop();let i=s;i.arbiter=null,i.next=ve.zpp_pool,ve.zpp_pool=i;let o=t.innards,r=o.next;o.next=r.next,r._inuse=!1,o.next==null&&(o.pushmod=!0),o.modified=!0,o.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=dt.zpp_pool,dt.zpp_pool=n,t.pre_dt=-1}for(;this.s_arbiters.head!=null;){let t=this.s_arbiters.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,o=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,o=!0;break}s=i,i=i.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=r.head,h=u.next,r.head=h,r.head==null&&(r.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(r.pushmod=!0));let x=u;x.elt=null,x.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}t.b1=t.b2=null,t.active=!1,t.intchange=!1;let n=t;n.next=Bt.zpp_pool,Bt.zpp_pool=n}for(;this.f_arbiters.head!=null;){let t=this.f_arbiters.pop_unsafe();if(!t.cleared){let l=t.b1.arbiters,s=null,i=l.head,o=!1;for(;i!=null;){if(i.elt==t){let u,h;s==null?(u=l.head,h=u.next,l.head=h,l.head==null&&(l.pushmod=!0)):(u=s.next,h=u.next,s.next=h,h==null&&(l.pushmod=!0));let x=u;x.elt=null,x.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,l.modified=!0,l.length--,l.pushmod=!0,o=!0;break}s=i,i=i.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let u,h;a==null?(u=r.head,h=u.next,r.head=h,r.head==null&&(r.pushmod=!0)):(u=a.next,h=u.next,a.next=h,h==null&&(r.pushmod=!0));let x=u;x.elt=null,x.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}t.b1=t.b2=null,t.active=!1,t.intchange=!1;let n=t;n.next=Mt.zpp_pool,Mt.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=bt.zpp_pool,bt.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=bt.zpp_pool,bt.zpp_pool=l}}t.removedFromSpace(),t.space=null}this.kinematics.clear();let e=new A._zpp.util.ZNPList_ZPP_Compound;for(;this.compounds.head!=null;){let t=this.compounds.pop_unsafe();e.add(t)}for(;e.head!=null;){let t=e.pop_unsafe();t.removedFromSpace(),t.space=null;let n=t.bodies.head;for(;n!=null;){let i=n.elt;if(i.component!=null){let o=i.component.island;if(o!=null){for(;o.comps.head!=null;){let a=o.comps.pop_unsafe();a.sleeping=!1,a.island=null,a.parent=a,a.rank=0}let r=o;r.next=bt.zpp_pool,bt.zpp_pool=r}}i.removedFromSpace(),i.space=null,n=n.next}let l=t.constraints.head;for(;l!=null;){let i=l.elt;if(i.component!=null){let o=i.component.island;if(o!=null){for(;o.comps.head!=null;){let a=o.comps.pop_unsafe();a.sleeping=!1,a.island=null,a.parent=a,a.rank=0}let r=o;r.next=bt.zpp_pool,bt.zpp_pool=r}}i.removedFromSpace(),i.space=null,l=l.next}let s=t.compounds.head;for(;s!=null;){let i=s.elt;e.add(i),s=s.next}}this.staticsleep.clear(),this.live.clear(),this.live_constraints.clear(),this.stamp=0,this.time=0,this.mrca1.clear(),this.mrca2.clear(),this.prelisteners.clear(),this.cbsets.clear()}bodies_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_bodies.remove(e),this.addBody(e.zpp_inner),!0):!1}bodies_subber(e){this.remBody(e.zpp_inner)}bodies_modifiable(){if(this.midstep)throw new Error("Error: Space::bodies cannot be set during space step()")}compounds_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.wrap_compounds.remove(e),this.addCompound(e.zpp_inner),!0):!1}compounds_subber(e){this.remCompound(e.zpp_inner)}compounds_modifiable(){if(this.midstep)throw new Error("Error: Space::compounds cannot be set during space step()")}constraints_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_constraints.remove(e),this.addConstraint(e.zpp_inner),!0):!1}constraints_subber(e){this.remConstraint(e.zpp_inner)}constraints_modifiable(){if(this.midstep)throw new Error("Error: Space::constraints cannot be set during space step()")}listeners_adder(e){return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_listeners.remove(e),this.addListener(e.zpp_inner),!0):!1}listeners_subber(e){this.remListener(e.zpp_inner)}listeners_modifiable(){if(this.midstep)throw new Error("Error: Space::listeners cannot be set during space step()")}revoke_listener(e){}unrevoke_listener(e){}addListener(e){e.space=this,e.addedToSpace();let t=e.interaction!=null}remListener(e){let t=e.interaction!=null;e.removedFromSpace(),e.space=null}add_callbackset(e){let t=e.int1.cbsets,n;A._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?n=new A._zpp.util.ZNPNode_ZPP_CallbackSet:(n=A._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,A._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;A._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?i=new A._zpp.util.ZNPNode_ZPP_CallbackSet:(i=A._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,A._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=i.next,i.next=null),i.elt=e;let o=i;o.next=s.head,s.head=o,s.modified=!0,s.length++;let r=this.callbackset_list;e._inuse=!0;let a=e;a.next=r.next,r.next=a,r.modified=!0,r.length++}remove_callbackset(e){e.lazydel=!0;let t=e.int1.cbsets,n=null,l=t.head,s=!1;for(;l!=null;){if(l.elt==e){let p,c;n==null?(p=t.head,c=p.next,t.head=c,t.head==null&&(t.pushmod=!0)):(p=n.next,c=p.next,n.next=c,c==null&&(t.pushmod=!0));let u=p;u.elt=null,u.next=A._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,A._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=u,t.modified=!0,t.length--,t.pushmod=!0,s=!0;break}n=l,l=l.next}let i=e.int2.cbsets,o=null,r=i.head,a=!1;for(;r!=null;){if(r.elt==e){let p,c;o==null?(p=i.head,c=p.next,i.head=c,i.head==null&&(i.pushmod=!0)):(p=o.next,c=p.next,o.next=c,c==null&&(i.pushmod=!0));let u=p;u.elt=null,u.next=A._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,A._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=u,i.modified=!0,i.length--,i.pushmod=!0,a=!0;break}o=r,r=r.next}}transmitType(e,t){let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!1)),e.type==2?this.live.remove(e):e.type==3?(this.kinematics.remove(e),this.staticsleep.remove(e)):e.type==1&&this.staticsleep.remove(e),e.type=t,e.type==3&&this.kinematics.add(e),e.type==1&&this.static_validation(e),e.component.sleeping=!0;let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0))}added_shape(e,t){if(t==null&&(t=!1),!t){let n=e.body;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!1))}this.bphase.insert(e),e.addedToSpace()}removed_shape(e,t){t==null&&(t=!1);let n=this,l=e.body;t||l.wake();let s=null,i=l.arbiters.head;for(;i!=null;){let o=i.elt;if(o.ws1==e||o.ws2==e){if(o.present!=0){this.MRCA_chains(o.ws1,o.ws2);let a=this.mrca1.head;for(;a!=null;){let p=a.elt,c=this.mrca2.head;for(;c!=null;){let u=c.elt,h=p.cbSet,x=u.cbSet;h.validate(),x.validate();let b=h.manager,_=null,f=(h.cbpairs.length<x.cbpairs.length?h.cbpairs:x.cbpairs).head;for(;f!=null;){let P=f.elt;if(P.a==h&&P.b==x||P.a==x&&P.b==h){_=P;break}f=f.next}if(_==null){let P;Ne.zpp_pool==null?P=new Ne:(P=Ne.zpp_pool,Ne.zpp_pool=P.next,P.next=null),P.zip_listeners=!0,Pt.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=A._zpp.phys.ZPP_Interactor.get(p,u);m.remove_arb(o),o.present--;let z=h.manager,Z=null,w=(h.cbpairs.length<x.cbpairs.length?h.cbpairs:x.cbpairs).head;for(;w!=null;){let P=w.elt;if(P.a==h&&P.b==x||P.a==x&&P.b==h){Z=P;break}w=w.next}if(Z==null){let P;Ne.zpp_pool==null?P=new Ne:(P=Ne.zpp_pool,Ne.zpp_pool=P.next,P.next=null),P.zip_listeners=!0,Pt.setlt(h,x)?(P.a=h,P.b=x):(P.a=x,P.b=h),Z=P,h.cbpairs.add(Z),x!=h&&x.cbpairs.add(Z)}Z.zip_listeners&&(Z.zip_listeners=!1,Z.__validate());let v=Z.listeners.head;for(;v!=null;){let P=v.elt;if(P.event==1&&(P.itype&o.type)!=0&&m.empty_arb(P.itype)){let g=n.push_callback(P);g.event=1;let k=m.int1,N=m.int2,E,M=P.options1,C=k.cbTypes;if(M.nonemptyintersection(C,M.includes)&&!M.nonemptyintersection(C,M.excludes)){let L=P.options2,O=N.cbTypes;E=L.nonemptyintersection(O,L.includes)&&!L.nonemptyintersection(O,L.excludes)}else E=!1;E?(g.int1=k,g.int2=N):(g.int1=N,g.int2=k),g.set=m}v=v.next}m.arbiters.head==null&&this.remove_callbackset(m),c=c.next}a=a.next}}if(o.b1!=l&&o.b1.type==2){let a=o.b1;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(o.b2!=l&&o.b2.type==2){let a=o.b2;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(o.cleared=!0,l==null||o.b2==l){let a=o.b1.arbiters,p=null,c=a.head,u=!1;for(;c!=null;){if(c.elt==o){let h,x;p==null?(h=a.head,x=h.next,a.head=x,a.head==null&&(a.pushmod=!0)):(h=p.next,x=h.next,p.next=x,x==null&&(a.pushmod=!0));let b=h;b.elt=null,b.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,a.modified=!0,a.length--,a.pushmod=!0,u=!0;break}p=c,c=c.next}}if(l==null||o.b1==l){let a=o.b2.arbiters,p=null,c=a.head,u=!1;for(;c!=null;){if(c.elt==o){let h,x;p==null?(h=a.head,x=h.next,a.head=x,a.head==null&&(a.pushmod=!0)):(h=p.next,x=h.next,p.next=x,x==null&&(a.pushmod=!0));let b=h;b.elt=null,b.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b,a.modified=!0,a.length--,a.pushmod=!0,u=!0;break}p=c,c=c.next}}o.pair!=null&&(o.pair.arb=null,o.pair=null),o.active=!1,this.f_arbiters.modified=!0,i=l.arbiters.erase(s);continue}s=i,i=i.next}this.bphase.remove(e),e.removedFromSpace()}addConstraint(e){e.space=this,e.addedToSpace(),e.active&&(e.component.sleeping=!0,this.wake_constraint(e,!0))}remConstraint(e){e.active&&(this.wake_constraint(e,!0),this.live_constraints.remove(e)),e.removedFromSpace(),e.space=null}addCompound(e){e.space=this,e.addedToSpace();let t=e.bodies.head;for(;t!=null;){let s=t.elt;this.addBody(s),t=t.next}let n=e.constraints.head;for(;n!=null;){let s=n.elt;this.addConstraint(s),n=n.next}let l=e.compounds.head;for(;l!=null;){let s=l.elt;this.addCompound(s),l=l.next}}remCompound(e){let t=e.bodies.head;for(;t!=null;){let s=t.elt;this.remBody(s),t=t.next}let n=e.constraints.head;for(;n!=null;){let s=n.elt;this.remConstraint(s),n=n.next}let l=e.compounds.head;for(;l!=null;){let s=l.elt;this.remCompound(s),l=l.next}e.removedFromSpace(),e.space=null}addBody(e,t){t==null&&(t=-1),e.space=this,e.addedToSpace(),e.component.sleeping=!0;let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!0));let l=e.shapes.head;for(;l!=null;){let s=l.elt,i=!0;if(i==null&&(i=!1),!i){let o=s.body;o.world||(o.component.waket=this.stamp+(this.midstep?0:1),o.type==3&&(o.kinematicDelaySleep=!0),o.component.sleeping&&this.really_wake(o,!1))}this.bphase.insert(s),s.addedToSpace(),l=l.next}e.type==1?this.static_validation(e):e.type!=2&&t!=3&&this.kinematics.add(e)}remBody(e,t){if(t==null&&(t=-1),e.type==1){let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0)),this.staticsleep.remove(e)}else if(e.type==2){let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0)),this.live.remove(e)}else{t!=3&&this.kinematics.remove(e);let l=e;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!0)),this.staticsleep.remove(e)}let n=e.shapes.head;for(;n!=null;){let l=n.elt;this.removed_shape(l,!0),n=n.next}e.removedFromSpace(),e.space=null}shapesUnderPoint(e,t,n,l){return this.bphase.shapesUnderPoint(e,t,n,l)}bodiesUnderPoint(e,t,n,l){return this.bphase.bodiesUnderPoint(e,t,n,l)}shapesInAABB(e,t,n,l,s){return this.bphase.shapesInAABB(e.zpp_inner,t,n,l,s)}bodiesInAABB(e,t,n,l,s){return this.bphase.bodiesInAABB(e.zpp_inner,t,n,l,s)}shapesInCircle(e,t,n,l,s){let i=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;o._validate!=null&&o._validate();let r=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=e.zpp_inner;return a._validate!=null&&a._validate(),i.shapesInCircle(r,e.zpp_inner.y,t,n,l,s)}bodiesInCircle(e,t,n,l,s){let i=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;o._validate!=null&&o._validate();let r=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=e.zpp_inner;return a._validate!=null&&a._validate(),i.bodiesInCircle(r,e.zpp_inner.y,t,n,l,s)}shapesInShape(e,t,n,l){return this.bphase.shapesInShape(e,t,n,l)}bodiesInShape(e,t,n,l){return this.bphase.bodiesInShape(e,t,n,l)}rayCast(e,t,n){return this.bphase.rayCast(e.zpp_inner,t,n==null?null:n.zpp_inner)}rayMultiCast(e,t,n,l){return this.bphase.rayMultiCast(e.zpp_inner,t,n==null?null:n.zpp_inner,l)}convexCast(e,t,n,l){let s;if(A._zpp.geom.ZPP_ToiEvent.zpp_pool==null?s=new A._zpp.geom.ZPP_ToiEvent:(s=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._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 T=O.polygon;if(T.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(T.lverts.next.next==null)T.localCOMx=T.lverts.next.x,T.localCOMy=T.lverts.next.y;else if(T.lverts.next.next.next==null){T.localCOMx=T.lverts.next.x,T.localCOMy=T.lverts.next.y;let W=1;T.localCOMx+=T.lverts.next.next.x*W,T.localCOMy+=T.lverts.next.next.y*W;let R=.5;T.localCOMx*=R,T.localCOMy*=R}else{T.localCOMx=0,T.localCOMy=0;let W=0,R=T.lverts.next,G=R;R=R.next;let j=R;for(R=R.next;R!=null;){let ee=R;W+=j.x*(ee.y-G.y);let F=ee.y*j.x-ee.x*j.y;T.localCOMx+=(j.x+ee.x)*F,T.localCOMy+=(j.y+ee.y)*F,G=j,j=ee,R=R.next}R=T.lverts.next;let S=R;W+=j.x*(S.y-G.y);let q=S.y*j.x-S.x*j.y;T.localCOMx+=(j.x+S.x)*q,T.localCOMy+=(j.y+S.y)*q,G=j,j=S,R=R.next;let $=R;W+=j.x*($.y-G.y);let X=$.y*j.x-$.x*j.y;T.localCOMx+=(j.x+$.x)*X,T.localCOMy+=(j.y+$.y)*X,W=1/(3*W);let H=W;T.localCOMx*=H,T.localCOMy*=H}}O.wrap_localCOM!=null&&(O.wrap_localCOM.zpp_inner.x=O.localCOMx,O.wrap_localCOM.zpp_inner.y=O.localCOMy)}let I=O.body;I.zip_axis&&(I.zip_axis=!1,I.axisx=Math.sin(I.rot),I.axisy=Math.cos(I.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 I=O.body;if(I.zip_axis&&(I.zip_axis=!1,I.axisx=Math.sin(I.rot),I.axisy=Math.cos(I.rot)),O.zip_gverts&&O.body!=null){O.zip_gverts=!1,O.validate_lverts();let S=O.body;S.zip_axis&&(S.zip_axis=!1,S.axisx=Math.sin(S.rot),S.axisy=Math.cos(S.rot));let q=O.lverts.next,$=O.gverts.next;for(;$!=null;){let X=$,H=q;q=q.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 T=O.edges.head,W=O.gverts.next,R=W;for(W=W.next;W!=null;){let S=W,q=T.elt;T=T.next,q.gp0=R,q.gp1=S,q.gnormx=O.body.axisy*q.lnormx-O.body.axisx*q.lnormy,q.gnormy=q.lnormx*O.body.axisx+q.lnormy*O.body.axisy,q.gprojection=O.body.posx*q.gnormx+O.body.posy*q.gnormy+q.lprojection,q.wrap_gnorm!=null&&(q.wrap_gnorm.zpp_inner.x=q.gnormx,q.wrap_gnorm.zpp_inner.y=q.gnormy),q.tp0=q.gp0.y*q.gnormx-q.gp0.x*q.gnormy,q.tp1=q.gp1.y*q.gnormx-q.gp1.x*q.gnormy,R=S,W=W.next}let G=O.gverts.next,j=T.elt;T=T.next,j.gp0=R,j.gp1=G,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}}let i=e.body,o=i.posx,r=i.posy;i.sweepTime=0,i.sweep_angvel=i.angvel;let a=t-i.sweepTime;if(a!=0){i.sweepTime=t;let O=a;if(i.posx+=i.velx*O,i.posy+=i.vely*O,i.angvel!=0){let I=i.sweep_angvel*a;if(i.rot+=I,I*I>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let T=I*I,W=1-.5*T,R=1-T*T/8,G=(W*i.axisx+I*i.axisy)*R;i.axisy=(W*i.axisy-I*i.axisx)*R,i.axisx=G}}}let p=i.posx,c=i.posy;e.validate_sweepRadius();let u=e.sweepRadius,h;be.zpp_pool==null?h=new be:(h=be.zpp_pool,be.zpp_pool=h.next,h.next=null);let x=o,b=p;h.minx=(x<b?x:b)-u;let _=o,d=p;h.maxx=(_>d?_:d)+u;let f=r,m=c;h.miny=(f<m?f:m)-u;let z=r,Z=c;h.maxy=(z>Z?z:Z)+u;let y=this.convexShapeList=this.bphase.shapesInAABB(h,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),w=h;w.outer!=null&&(w.outer.zpp_inner=null,w.outer=null),w.wrap_min=w.wrap_max=null,w._invalidate=null,w._validate=null,w.next=be.zpp_pool,be.zpp_pool=w;let v=0,P=0;v=0,P=0;let g=0,k=0;g=0,k=0;let N=null,E=t+1;y.zpp_inner.valmod();let M=A._nape.shape.ShapeIterator.get(y);for(;;){M.zpp_inner.zpp_inner.valmod();let O=M.zpp_inner;O.zpp_inner.valmod(),O.zpp_inner.zip_length&&(O.zpp_inner.zip_length=!1,O.zpp_inner.user_length=O.zpp_inner.inner.length);let I=O.zpp_inner.user_length;M.zpp_critical=!0;let T;if(M.zpp_i<I?T=!0:(M.zpp_next=A._nape.shape.ShapeIterator.zpp_pool,A._nape.shape.ShapeIterator.zpp_pool=M,M.zpp_inner=null,T=!1),!T)break;M.zpp_critical=!1;let W=M.zpp_inner.at(M.zpp_i++);if(W!=e.outer&&(W.zpp_inner.body!=null?W.zpp_inner.body.outer:null)!=i.outer){if(s.s1=e,s.s2=W.zpp_inner,l){W.zpp_inner.validate_sweepRadius(),(W.zpp_inner.body!=null?W.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(W.zpp_inner.body!=null?W.zpp_inner.body.outer:null).zpp_inner.angvel,(W.zpp_inner.body!=null?W.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,wn.dynamicSweep(s,t,0,0,!0);let R=(W.zpp_inner.body!=null?W.zpp_inner.body.outer:null).zpp_inner,G=0-R.sweepTime;if(G!=0){R.sweepTime=0;let q=G;if(R.posx+=R.velx*q,R.posy+=R.vely*q,R.angvel!=0){let $=R.sweep_angvel*G;if(R.rot+=$,$*$>1e-4)R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.rot);else{let X=$*$,H=1-.5*X,ee=1-X*X/8,F=(H*R.axisx+$*R.axisy)*ee;R.axisy=(H*R.axisy-$*R.axisx)*ee,R.axisx=F}}}let j=(W.zpp_inner.body!=null?W.zpp_inner.body.outer:null).zpp_inner,S=W.zpp_inner;if(S.type==0)S.worldCOMx=j.posx+(j.axisy*S.localCOMx-j.axisx*S.localCOMy),S.worldCOMy=j.posy+(S.localCOMx*j.axisx+S.localCOMy*j.axisy);else{let q=S.polygon,$=q.lverts.next,X=q.gverts.next;for(;X!=null;){let V=X,J=$;$=$.next,V.x=j.posx+(j.axisy*J.x-j.axisx*J.y),V.y=j.posy+(J.x*j.axisx+J.y*j.axisy),X=X.next}let H=q.edges.head,ee=q.gverts.next,F=ee;for(ee=ee.next;ee!=null;){let V=ee,J=H.elt;H=H.next,J.gnormx=j.axisy*J.lnormx-j.axisx*J.lnormy,J.gnormy=J.lnormx*j.axisx+J.lnormy*j.axisy,J.gprojection=j.posx*J.gnormx+j.posy*J.gnormy+J.lprojection,J.tp0=F.y*J.gnormx-F.x*J.gnormy,J.tp1=V.y*J.gnormx-V.x*J.gnormy,F=V,ee=ee.next}let D=q.gverts.next,B=H.elt;H=H.next,B.gnormx=j.axisy*B.lnormx-j.axisx*B.lnormy,B.gnormy=B.lnormx*j.axisx+B.lnormy*j.axisy,B.gprojection=j.posx*B.gnormx+j.posy*B.gnormy+B.lprojection,B.tp0=F.y*B.gnormx-F.x*B.gnormy,B.tp1=D.y*B.gnormx-D.x*B.gnormy}}else wn.staticSweep(s,t,0,0);s.toi*=t,s.toi>0&&s.toi<E&&(E=s.toi,v=s.axis.x,P=s.axis.y,g=s.c2.x,k=s.c2.y,N=W)}}y.clear();let C=s;C.next=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._zpp.geom.ZPP_ToiEvent.zpp_pool=C;let L=0-i.sweepTime;if(L!=0){i.sweepTime=0;let O=L;if(i.posx+=i.velx*O,i.posy+=i.vely*O,i.angvel!=0){let I=i.sweep_angvel*L;if(i.rot+=I,I*I>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let T=I*I,W=1-.5*T,R=1-T*T/8,G=(W*i.axisx+I*i.axisy)*R;i.axisy=(W*i.axisy-I*i.axisx)*R,i.axisx=G}}}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,I=O.lverts.next,T=O.gverts.next;for(;T!=null;){let q=T,$=I;I=I.next,q.x=i.posx+(i.axisy*$.x-i.axisx*$.y),q.y=i.posy+($.x*i.axisx+$.y*i.axisy),T=T.next}let W=O.edges.head,R=O.gverts.next,G=R;for(R=R.next;R!=null;){let q=R,$=W.elt;W=W.next,$.gnormx=i.axisy*$.lnormx-i.axisx*$.lnormy,$.gnormy=$.lnormx*i.axisx+$.lnormy*i.axisy,$.gprojection=i.posx*$.gnormx+i.posy*$.gnormy+$.lprojection,$.tp0=G.y*$.gnormx-G.x*$.gnormy,$.tp1=q.y*$.gnormx-q.x*$.gnormy,G=q,R=R.next}let j=O.gverts.next,S=W.elt;W=W.next,S.gnormx=i.axisy*S.lnormx-i.axisx*S.lnormy,S.gnormy=S.lnormx*i.axisx+S.lnormy*i.axisy,S.gprojection=i.posx*S.gnormx+i.posy*S.gnormy+S.lprojection,S.tp0=G.y*S.gnormx-G.x*S.gnormy,S.tp1=j.y*S.gnormx-j.x*S.gnormy}if(E<=t){let O=-v,I=-P;if(I==null&&(I=0),O==null&&(O=0),O!=O||I!=I)throw new Error("Error: Vec2 components cannot be NaN");let T;if(A._zpp.util.ZPP_PubPool.poolVec2==null?T=new A._nape.geom.Vec2:(T=A._zpp.util.ZPP_PubPool.poolVec2,A._zpp.util.ZPP_PubPool.poolVec2=T.zpp_pool,T.zpp_pool=null,T.zpp_disp=!1,T==A._zpp.util.ZPP_PubPool.nextVec2&&(A._zpp.util.ZPP_PubPool.nextVec2=null)),T.zpp_inner==null){let j;le.zpp_pool==null?j=new le:(j=le.zpp_pool,le.zpp_pool=j.next,j.next=null),j.weak=!1,j._immutable=!1,j.x=O,j.y=I,T.zpp_inner=j,T.zpp_inner.outer=T}else{if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let j=T.zpp_inner;if(j._immutable)throw new Error("Error: Vec2 is immutable");if(j._isimmutable!=null&&j._isimmutable(),O!=O||I!=I)throw new Error("Error: Vec2 components cannot be NaN");let S;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let q=T.zpp_inner;if(q._validate!=null&&q._validate(),T.zpp_inner.x==O){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let $=T.zpp_inner;$._validate!=null&&$._validate(),S=T.zpp_inner.y==I}else S=!1;if(!S){T.zpp_inner.x=O,T.zpp_inner.y=I;let $=T.zpp_inner;$._invalidate!=null&&$._invalidate($)}}T.zpp_inner.weak=!1;let W=g,R=k;if(R==null&&(R=0),W==null&&(W=0),W!=W||R!=R)throw new Error("Error: Vec2 components cannot be NaN");let G;if(A._zpp.util.ZPP_PubPool.poolVec2==null?G=new A._nape.geom.Vec2:(G=A._zpp.util.ZPP_PubPool.poolVec2,A._zpp.util.ZPP_PubPool.poolVec2=G.zpp_pool,G.zpp_pool=null,G.zpp_disp=!1,G==A._zpp.util.ZPP_PubPool.nextVec2&&(A._zpp.util.ZPP_PubPool.nextVec2=null)),G.zpp_inner==null){let j;le.zpp_pool==null?j=new le:(j=le.zpp_pool,le.zpp_pool=j.next,j.next=null),j.weak=!1,j._immutable=!1,j.x=W,j.y=R,G.zpp_inner=j,G.zpp_inner.outer=G}else{if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let j=G.zpp_inner;if(j._immutable)throw new Error("Error: Vec2 is immutable");if(j._isimmutable!=null&&j._isimmutable(),W!=W||R!=R)throw new Error("Error: Vec2 components cannot be NaN");let S;if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let q=G.zpp_inner;if(q._validate!=null&&q._validate(),G.zpp_inner.x==W){if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let $=G.zpp_inner;$._validate!=null&&$._validate(),S=G.zpp_inner.y==R}else S=!1;if(!S){G.zpp_inner.x=W,G.zpp_inner.y=R;let $=G.zpp_inner;$._invalidate!=null&&$._invalidate($)}}return G.zpp_inner.weak=!1,A._zpp.geom.ZPP_ConvexRayResult.getConvex(T,G,E,N)}else return null}prepareCast(e){if(e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let s=1;l.localCOMx+=l.lverts.next.next.x*s,l.localCOMy+=l.lverts.next.next.y*s;let i=.5;l.localCOMx*=i,l.localCOMy*=i}else{l.localCOMx=0,l.localCOMy=0;let s=0,i=l.lverts.next,o=i;i=i.next;let r=i;for(i=i.next;i!=null;){let x=i;s+=r.x*(x.y-o.y);let b=x.y*r.x-x.x*r.y;l.localCOMx+=(r.x+x.x)*b,l.localCOMy+=(r.y+x.y)*b,o=r,r=x,i=i.next}i=l.lverts.next;let a=i;s+=r.x*(a.y-o.y);let p=a.y*r.x-a.x*r.y;l.localCOMx+=(r.x+a.x)*p,l.localCOMy+=(r.y+a.y)*p,o=r,r=a,i=i.next;let c=i;s+=r.x*(c.y-o.y);let u=c.y*r.x-c.x*r.y;l.localCOMx+=(r.x+c.x)*u,l.localCOMy+=(r.y+c.y)*u,s=1/(3*s);let h=s;l.localCOMx*=h,l.localCOMy*=h}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let n=t.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}}else{let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let u=c,h=p;p=p.next,u.x=t.body.posx+(t.body.axisy*h.x-t.body.axisx*h.y),u.y=t.body.posy+(h.x*t.body.axisx+h.y*t.body.axisy),c=c.next}}let l=t.edges.head,s=t.gverts.next,i=s;for(s=s.next;s!=null;){let a=s,p=l.elt;l=l.next,p.gp0=i,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,i=a,s=s.next}let o=t.gverts.next,r=l.elt;l=l.next,r.gp0=i,r.gp1=o,r.gnormx=t.body.axisy*r.lnormx-t.body.axisx*r.lnormy,r.gnormy=r.lnormx*t.body.axisx+r.lnormy*t.body.axisy,r.gprojection=t.body.posx*r.gnormx+t.body.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy}}}convexMultiCast(e,t,n,l,s){let i;if(A._zpp.geom.ZPP_ToiEvent.zpp_pool==null?i=new A._zpp.geom.ZPP_ToiEvent:(i=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._zpp.geom.ZPP_ToiEvent.zpp_pool=i.next,i.next=null),i.failed=!1,i.s1=i.s2=null,i.arbiter=null,e.type==0){let E=e.circle;if(E.zip_worldCOM&&E.body!=null){if(E.zip_worldCOM=!1,E.zip_localCOM){if(E.zip_localCOM=!1,E.type==1){let C=E.polygon;if(C.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(C.lverts.next.next==null)C.localCOMx=C.lverts.next.x,C.localCOMy=C.lverts.next.y;else if(C.lverts.next.next.next==null){C.localCOMx=C.lverts.next.x,C.localCOMy=C.lverts.next.y;let L=1;C.localCOMx+=C.lverts.next.next.x*L,C.localCOMy+=C.lverts.next.next.y*L;let O=.5;C.localCOMx*=O,C.localCOMy*=O}else{C.localCOMx=0,C.localCOMy=0;let L=0,O=C.lverts.next,I=O;O=O.next;let T=O;for(O=O.next;O!=null;){let q=O;L+=T.x*(q.y-I.y);let $=q.y*T.x-q.x*T.y;C.localCOMx+=(T.x+q.x)*$,C.localCOMy+=(T.y+q.y)*$,I=T,T=q,O=O.next}O=C.lverts.next;let W=O;L+=T.x*(W.y-I.y);let R=W.y*T.x-W.x*T.y;C.localCOMx+=(T.x+W.x)*R,C.localCOMy+=(T.y+W.y)*R,I=T,T=W,O=O.next;let G=O;L+=T.x*(G.y-I.y);let j=G.y*T.x-G.x*T.y;C.localCOMx+=(T.x+G.x)*j,C.localCOMy+=(T.y+G.y)*j,L=1/(3*L);let S=L;C.localCOMx*=S,C.localCOMy*=S}}E.wrap_localCOM!=null&&(E.wrap_localCOM.zpp_inner.x=E.localCOMx,E.wrap_localCOM.zpp_inner.y=E.localCOMy)}let M=E.body;M.zip_axis&&(M.zip_axis=!1,M.axisx=Math.sin(M.rot),M.axisy=Math.cos(M.rot)),E.worldCOMx=E.body.posx+(E.body.axisy*E.localCOMx-E.body.axisx*E.localCOMy),E.worldCOMy=E.body.posy+(E.localCOMx*E.body.axisx+E.localCOMy*E.body.axisy)}}else{let E=e.polygon;if(E.zip_gaxi&&E.body!=null){E.zip_gaxi=!1,E.validate_laxi();let M=E.body;if(M.zip_axis&&(M.zip_axis=!1,M.axisx=Math.sin(M.rot),M.axisy=Math.cos(M.rot)),E.zip_gverts&&E.body!=null){E.zip_gverts=!1,E.validate_lverts();let W=E.body;W.zip_axis&&(W.zip_axis=!1,W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot));let R=E.lverts.next,G=E.gverts.next;for(;G!=null;){let j=G,S=R;R=R.next,j.x=E.body.posx+(E.body.axisy*S.x-E.body.axisx*S.y),j.y=E.body.posy+(S.x*E.body.axisx+S.y*E.body.axisy),G=G.next}}let C=E.edges.head,L=E.gverts.next,O=L;for(L=L.next;L!=null;){let W=L,R=C.elt;C=C.next,R.gp0=O,R.gp1=W,R.gnormx=E.body.axisy*R.lnormx-E.body.axisx*R.lnormy,R.gnormy=R.lnormx*E.body.axisx+R.lnormy*E.body.axisy,R.gprojection=E.body.posx*R.gnormx+E.body.posy*R.gnormy+R.lprojection,R.wrap_gnorm!=null&&(R.wrap_gnorm.zpp_inner.x=R.gnormx,R.wrap_gnorm.zpp_inner.y=R.gnormy),R.tp0=R.gp0.y*R.gnormx-R.gp0.x*R.gnormy,R.tp1=R.gp1.y*R.gnormx-R.gp1.x*R.gnormy,O=W,L=L.next}let I=E.gverts.next,T=C.elt;C=C.next,T.gp0=O,T.gp1=I,T.gnormx=E.body.axisy*T.lnormx-E.body.axisx*T.lnormy,T.gnormy=T.lnormx*E.body.axisx+T.lnormy*E.body.axisy,T.gprojection=E.body.posx*T.gnormx+E.body.posy*T.gnormy+T.lprojection,T.wrap_gnorm!=null&&(T.wrap_gnorm.zpp_inner.x=T.gnormx,T.wrap_gnorm.zpp_inner.y=T.gnormy),T.tp0=T.gp0.y*T.gnormx-T.gp0.x*T.gnormy,T.tp1=T.gp1.y*T.gnormx-T.gp1.x*T.gnormy}}let o=e.body,r=o.posx,a=o.posy;o.sweepTime=0,o.sweep_angvel=o.angvel;let p=t-o.sweepTime;if(p!=0){o.sweepTime=t;let E=p;if(o.posx+=o.velx*E,o.posy+=o.vely*E,o.angvel!=0){let M=o.sweep_angvel*p;if(o.rot+=M,M*M>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let C=M*M,L=1-.5*C,O=1-C*C/8,I=(L*o.axisx+M*o.axisy)*O;o.axisy=(L*o.axisy-M*o.axisx)*O,o.axisx=I}}}let c=o.posx,u=o.posy;e.validate_sweepRadius();let h=e.sweepRadius,x;be.zpp_pool==null?x=new be:(x=be.zpp_pool,be.zpp_pool=x.next,x.next=null);let b=r,_=c;x.minx=(b<_?b:_)-h;let d=r,f=c;x.maxx=(d>f?d:f)+h;let m=a,z=u;x.miny=(m<z?m:z)-h;let Z=a,y=u;x.maxy=(Z>y?Z:y)+h;let w=this.convexShapeList=this.bphase.shapesInAABB(x,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),v=x;v.outer!=null&&(v.outer.zpp_inner=null,v.outer=null),v.wrap_min=v.wrap_max=null,v._invalidate=null,v._validate=null,v.next=be.zpp_pool,be.zpp_pool=v;let P=s??new A._nape.geom.ConvexResultList;w.zpp_inner.valmod();let g=A._nape.shape.ShapeIterator.get(w);for(;;){g.zpp_inner.zpp_inner.valmod();let E=g.zpp_inner;E.zpp_inner.valmod(),E.zpp_inner.zip_length&&(E.zpp_inner.zip_length=!1,E.zpp_inner.user_length=E.zpp_inner.inner.length);let M=E.zpp_inner.user_length;g.zpp_critical=!0;let C;if(g.zpp_i<M?C=!0:(g.zpp_next=A._nape.shape.ShapeIterator.zpp_pool,A._nape.shape.ShapeIterator.zpp_pool=g,g.zpp_inner=null,C=!1),!C)break;g.zpp_critical=!1;let L=g.zpp_inner.at(g.zpp_i++);if(L!=e.outer&&(L.zpp_inner.body!=null?L.zpp_inner.body.outer:null)!=o.outer){if(i.s1=e,i.s2=L.zpp_inner,l){L.zpp_inner.validate_sweepRadius(),(L.zpp_inner.body!=null?L.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(L.zpp_inner.body!=null?L.zpp_inner.body.outer:null).zpp_inner.angvel,(L.zpp_inner.body!=null?L.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,wn.dynamicSweep(i,t,0,0,!0);let O=(L.zpp_inner.body!=null?L.zpp_inner.body.outer:null).zpp_inner,I=0-O.sweepTime;if(I!=0){O.sweepTime=0;let R=I;if(O.posx+=O.velx*R,O.posy+=O.vely*R,O.angvel!=0){let G=O.sweep_angvel*I;if(O.rot+=G,G*G>1e-4)O.axisx=Math.sin(O.rot),O.axisy=Math.cos(O.rot);else{let j=G*G,S=1-.5*j,q=1-j*j/8,$=(S*O.axisx+G*O.axisy)*q;O.axisy=(S*O.axisy-G*O.axisx)*q,O.axisx=$}}}let T=(L.zpp_inner.body!=null?L.zpp_inner.body.outer:null).zpp_inner,W=L.zpp_inner;if(W.type==0)W.worldCOMx=T.posx+(T.axisy*W.localCOMx-T.axisx*W.localCOMy),W.worldCOMy=T.posy+(W.localCOMx*T.axisx+W.localCOMy*T.axisy);else{let R=W.polygon,G=R.lverts.next,j=R.gverts.next;for(;j!=null;){let ee=j,F=G;G=G.next,ee.x=T.posx+(T.axisy*F.x-T.axisx*F.y),ee.y=T.posy+(F.x*T.axisx+F.y*T.axisy),j=j.next}let S=R.edges.head,q=R.gverts.next,$=q;for(q=q.next;q!=null;){let ee=q,F=S.elt;S=S.next,F.gnormx=T.axisy*F.lnormx-T.axisx*F.lnormy,F.gnormy=F.lnormx*T.axisx+F.lnormy*T.axisy,F.gprojection=T.posx*F.gnormx+T.posy*F.gnormy+F.lprojection,F.tp0=$.y*F.gnormx-$.x*F.gnormy,F.tp1=ee.y*F.gnormx-ee.x*F.gnormy,$=ee,q=q.next}let X=R.gverts.next,H=S.elt;S=S.next,H.gnormx=T.axisy*H.lnormx-T.axisx*H.lnormy,H.gnormy=H.lnormx*T.axisx+H.lnormy*T.axisy,H.gprojection=T.posx*H.gnormx+T.posy*H.gnormy+H.lprojection,H.tp0=$.y*H.gnormx-$.x*H.gnormy,H.tp1=X.y*H.gnormx-X.x*H.gnormy}}else wn.staticSweep(i,t,0,0);if(i.toi*=t,i.toi>0){let O=-i.axis.x,I=-i.axis.y;if(I==null&&(I=0),O==null&&(O=0),O!=O||I!=I)throw new Error("Error: Vec2 components cannot be NaN");let T;if(A._zpp.util.ZPP_PubPool.poolVec2==null?T=new A._nape.geom.Vec2:(T=A._zpp.util.ZPP_PubPool.poolVec2,A._zpp.util.ZPP_PubPool.poolVec2=T.zpp_pool,T.zpp_pool=null,T.zpp_disp=!1,T==A._zpp.util.ZPP_PubPool.nextVec2&&(A._zpp.util.ZPP_PubPool.nextVec2=null)),T.zpp_inner==null){let ee;le.zpp_pool==null?ee=new le:(ee=le.zpp_pool,le.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=O,ee.y=I,T.zpp_inner=ee,T.zpp_inner.outer=T}else{if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=T.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),O!=O||I!=I)throw new Error("Error: Vec2 components cannot be NaN");let F;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=T.zpp_inner;if(D._validate!=null&&D._validate(),T.zpp_inner.x==O){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let B=T.zpp_inner;B._validate!=null&&B._validate(),F=T.zpp_inner.y==I}else F=!1;if(!F){T.zpp_inner.x=O,T.zpp_inner.y=I;let B=T.zpp_inner;B._invalidate!=null&&B._invalidate(B)}}T.zpp_inner.weak=!1;let W=i.c2.x,R=i.c2.y;if(R==null&&(R=0),W==null&&(W=0),W!=W||R!=R)throw new Error("Error: Vec2 components cannot be NaN");let G;if(A._zpp.util.ZPP_PubPool.poolVec2==null?G=new A._nape.geom.Vec2:(G=A._zpp.util.ZPP_PubPool.poolVec2,A._zpp.util.ZPP_PubPool.poolVec2=G.zpp_pool,G.zpp_pool=null,G.zpp_disp=!1,G==A._zpp.util.ZPP_PubPool.nextVec2&&(A._zpp.util.ZPP_PubPool.nextVec2=null)),G.zpp_inner==null){let ee;le.zpp_pool==null?ee=new le:(ee=le.zpp_pool,le.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=W,ee.y=R,G.zpp_inner=ee,G.zpp_inner.outer=G}else{if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=G.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),W!=W||R!=R)throw new Error("Error: Vec2 components cannot be NaN");let F;if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=G.zpp_inner;if(D._validate!=null&&D._validate(),G.zpp_inner.x==W){if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let B=G.zpp_inner;B._validate!=null&&B._validate(),F=G.zpp_inner.y==R}else F=!1;if(!F){G.zpp_inner.x=W,G.zpp_inner.y=R;let B=G.zpp_inner;B._invalidate!=null&&B._invalidate(B)}}G.zpp_inner.weak=!1;let j=A._zpp.geom.ZPP_ConvexRayResult.getConvex(T,G,i.toi,L),S=null,q=P.zpp_inner.inner.head;for(;q!=null;){let ee=q.elt;if(j.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(ee.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(j.zpp_inner.toiDistance<ee.zpp_inner.toiDistance)break;S=q,q=q.next}let $=P.zpp_inner.inner,X;A._zpp.util.ZNPNode_ConvexResult.zpp_pool==null?X=new A._zpp.util.ZNPNode_ConvexResult:(X=A._zpp.util.ZNPNode_ConvexResult.zpp_pool,A._zpp.util.ZNPNode_ConvexResult.zpp_pool=X.next,X.next=null),X.elt=j;let H=X;S==null?(H.next=$.head,$.head=H):(H.next=S.next,S.next=H),$.pushmod=$.modified=!0,$.length++}}}w.clear();let k=i;k.next=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._zpp.geom.ZPP_ToiEvent.zpp_pool=k;let N=0-o.sweepTime;if(N!=0){o.sweepTime=0;let E=N;if(o.posx+=o.velx*E,o.posy+=o.vely*E,o.angvel!=0){let M=o.sweep_angvel*N;if(o.rot+=M,M*M>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let C=M*M,L=1-.5*C,O=1-C*C/8,I=(L*o.axisx+M*o.axisy)*O;o.axisy=(L*o.axisy-M*o.axisx)*O,o.axisx=I}}}if(e.type==0)e.worldCOMx=o.posx+(o.axisy*e.localCOMx-o.axisx*e.localCOMy),e.worldCOMy=o.posy+(e.localCOMx*o.axisx+e.localCOMy*o.axisy);else{let E=e.polygon,M=E.lverts.next,C=E.gverts.next;for(;C!=null;){let R=C,G=M;M=M.next,R.x=o.posx+(o.axisy*G.x-o.axisx*G.y),R.y=o.posy+(G.x*o.axisx+G.y*o.axisy),C=C.next}let L=E.edges.head,O=E.gverts.next,I=O;for(O=O.next;O!=null;){let R=O,G=L.elt;L=L.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=I.y*G.gnormx-I.x*G.gnormy,G.tp1=R.y*G.gnormx-R.x*G.gnormy,I=R,O=O.next}let T=E.gverts.next,W=L.elt;L=L.next,W.gnormx=o.axisy*W.lnormx-o.axisx*W.lnormy,W.gnormy=W.lnormx*o.axisx+W.lnormy*o.axisy,W.gprojection=o.posx*W.gnormx+o.posy*W.gnormy+W.lprojection,W.tp0=I.y*W.gnormx-I.x*W.gnormy,W.tp1=T.y*W.gnormx-T.x*W.gnormy}return P}push_callback(e){let t;return Rt.zpp_pool==null?t=new Rt:(t=Rt.zpp_pool,Rt.zpp_pool=t.next,t.next=null),this.callbacks.push(t),t.listener=e,t}step(e,t,n){let l=this;if(this.midstep)throw new Error("Error: ... REALLY?? you're going to call space.step() inside of space.step()? COME ON!!");if(this.time+=e,this.pre_dt=e,this.midstep=!0,this.stamp++,this.validation(),this.bphase.broadphase(this,!0),this.prestep(e),this.sortcontacts){let h=this.c_arbiters_false;if(h.head!=null&&h.head.next!=null){let x=h.head,b=null,_=null,d=null,f=null,m=1,z,Z,y;for(;;){for(z=0,_=x,x=null,b=x;_!=null;){for(++z,d=_,Z=0,y=m;d!=null&&Z<m;)++Z,d=d.next;for(;Z>0||y>0&&d!=null;)Z==0?(f=d,d=d.next,--y):y==0||d==null||!(_.elt.active&&d.elt.active)||_.elt.oc1.dist<d.elt.oc1.dist?(f=_,_=_.next,--Z):(f=d,d=d.next,--y),b!=null?b.next=f:x=f,b=f;_=d}if(b.next=null,m<<=1,!(z>1))break}h.head=x,h.modified=!0,h.pushmod=!0}}this.updateVel(e),this.warmStart(),this.iterateVel(t);let s=this.kinematics.head;for(;s!=null;){let h=s.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,s=s.next}let i=this.live.head;for(;i!=null;){let h=i.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,i=i.next}this.updatePos(e),this.continuous=!0,this.continuousCollisions(e),this.continuous=!1,this.iteratePos(n);let o=this.kinematics.head;for(;o!=null;){let h=o.elt,x=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),b=h.pre_rot!=h.rot;if(x){let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}if(b){h.zip_axis=!0;let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}o=o.next}let r=this.live.head;for(;r!=null;){let h=r.elt,x=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),b=h.pre_rot!=h.rot;if(x){let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}if(b){h.zip_axis=!0;let _=h.shapes.head;for(;_!=null;){let d=_.elt;d.type==1&&(d.polygon.invalidate_gverts(),d.polygon.invalidate_gaxi()),d.invalidate_worldCOM(),_=_.next}h.zip_worldCOM=!0}r=r.next}let a=null,p=this.staticsleep.head;for(;p!=null;){let h=p.elt;if(h.type!=3||h.velx==0&&h.vely==0&&h.angvel==0){if(h.kinematicDelaySleep){h.kinematicDelaySleep=!1,p=p.next;continue}h.component.sleeping=!0;let x=this.staticsleep,b,_;a==null?(b=x.head,_=b.next,x.head=_,x.head==null&&(x.pushmod=!0)):(b=a.next,_=b.next,a.next=_,_==null&&(x.pushmod=!0));let d=b;d.elt=null,d.next=A._zpp.util.ZNPNode_ZPP_Body.zpp_pool,A._zpp.util.ZNPNode_ZPP_Body.zpp_pool=d,x.modified=!0,x.length--,x.pushmod=!0,p=_;continue}a=p,p=p.next}this.doForests(e),this.sleepArbiters(),this.midstep=!1;let c=null,u=this.callbackset_list.next;for(;u!=null;){let h=u;if(h.arbiters.head==null){let v=this.callbackset_list,P,g;c==null?(P=v.next,g=P.next,v.next=g,v.next==null&&(v.pushmod=!0)):(P=c.next,g=P.next,c.next=g,g==null&&(v.pushmod=!0)),P._inuse=!1,v.modified=!0,v.length--,v.pushmod=!0,u=g;let k=h;k.int1=k.int2=null,k.id=k.di=-1,k.freed=!0,k.next=Ht.zpp_pool,Ht.zpp_pool=k;continue}let x;x=!0;let b=h.arbiters.head;for(;b!=null;)if(b.elt.sleeping){b=b.next;continue}else{x=!1;break}let _=x,d=h.int1.cbSet,f=h.int2.cbSet,m=d.manager,z=null,y=(d.cbpairs.length<f.cbpairs.length?d.cbpairs:f.cbpairs).head;for(;y!=null;){let v=y.elt;if(v.a==d&&v.b==f||v.a==f&&v.b==d){z=v;break}y=y.next}if(z==null){let v;Ne.zpp_pool==null?v=new Ne:(v=Ne.zpp_pool,Ne.zpp_pool=v.next,v.next=null),v.zip_listeners=!0,Pt.setlt(d,f)?(v.a=d,v.b=f):(v.a=f,v.b=d),z=v,d.cbpairs.add(z),f!=d&&f.cbpairs.add(z)}z.zip_listeners&&(z.zip_listeners=!1,z.__validate());let w=z.listeners.head;for(;w!=null;){let v=w.elt;if(v.event==6&&(!_||v.allowSleepingCallbacks)&&!h.empty_arb(v.itype)){let P=l.push_callback(v);P.event=6;let g=h.int1,k=h.int2,N,E=v.options1,M=g.cbTypes;if(E.nonemptyintersection(M,E.includes)&&!E.nonemptyintersection(M,E.excludes)){let C=v.options2,L=k.cbTypes;N=C.nonemptyintersection(L,C.includes)&&!C.nonemptyintersection(L,C.excludes)}else N=!1;N?(P.int1=g,P.int2=k):(P.int1=k,P.int2=g),P.set=h}w=w.next}c=u,u=u.next}for(;!this.callbacks.empty();){let h=this.callbacks.pop();h.listener.type==0?h.listener.body.handler(h.wrapper_body()):h.listener.type==1?h.listener.constraint.handler(h.wrapper_con()):h.listener.type==2&&h.listener.interaction.handleri(h.wrapper_int());let x=h;x.int1=x.int2=null,x.body=null,x.constraint=null,x.listener=null,x.wrap_arbiters!=null&&(x.wrap_arbiters.zpp_inner.inner=null),x.set=null,x.next=Rt.zpp_pool,Rt.zpp_pool=x}}continuousCollisions(e){let t=2*Math.PI/e;this.bphase.broadphase(this,!1);let n=0;for(;n<1&&this.toiEvents.head!=null;){let i=null,o=2,r=!1,a=null,p=null,c=this.toiEvents.head;for(;c!=null;){let d=c.elt,f=d.s1.body,m=d.s2.body;if(f.sweepFrozen&&m.sweepFrozen)if(d.toi!=0&&Ee.testCollide_safe(d.s1,d.s2))d.toi=0;else{c=this.toiEvents.erase(p);let z=d;z.next=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._zpp.geom.ZPP_ToiEvent.zpp_pool=z;continue}if(d.frozen1!=f.sweepFrozen||d.frozen2!=m.sweepFrozen)if(d.kinematic){c=this.toiEvents.erase(p);let z=d;z.next=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._zpp.geom.ZPP_ToiEvent.zpp_pool=z;continue}else{if(d.frozen1=f.sweepFrozen,d.frozen2=m.sweepFrozen,d.frozen1){let z=d.s1;d.s1=d.s2,d.s2=z,d.frozen1=!1,d.frozen2=!0}if(wn.staticSweep(d,e,0,A._nape.Config.collisionSlopCCD),d.toi<0){c=this.toiEvents.erase(p);let z=d;z.next=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._zpp.geom.ZPP_ToiEvent.zpp_pool=z;continue}}d.toi>=0&&(d.toi<o||!r&&d.kinematic)&&(i=d,o=d.toi,r=d.kinematic,a=p),p=c,c=c.next}if(i==null)break;this.toiEvents.erase(a),n=i.toi;let u=i.s1.body,h=i.s2.body;if(!u.sweepFrozen){let d=n*e,f=d-u.sweepTime;if(f!=0){u.sweepTime=d;let z=f;if(u.posx+=u.velx*z,u.posy+=u.vely*z,u.angvel!=0){let Z=u.sweep_angvel*f;if(u.rot+=Z,Z*Z>1e-4)u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot);else{let y=Z*Z,w=1-.5*y,v=1-y*y/8,P=(w*u.axisx+Z*u.axisy)*v;u.axisy=(w*u.axisy-Z*u.axisx)*v,u.axisx=P}}}let m=i.s1;if(m.type==0)m.worldCOMx=u.posx+(u.axisy*m.localCOMx-u.axisx*m.localCOMy),m.worldCOMy=u.posy+(m.localCOMx*u.axisx+m.localCOMy*u.axisy);else{let z=m.polygon,Z=z.lverts.next,y=z.gverts.next;for(;y!=null;){let N=y,E=Z;Z=Z.next,N.x=u.posx+(u.axisy*E.x-u.axisx*E.y),N.y=u.posy+(E.x*u.axisx+E.y*u.axisy),y=y.next}let w=z.edges.head,v=z.gverts.next,P=v;for(v=v.next;v!=null;){let N=v,E=w.elt;w=w.next,E.gnormx=u.axisy*E.lnormx-u.axisx*E.lnormy,E.gnormy=E.lnormx*u.axisx+E.lnormy*u.axisy,E.gprojection=u.posx*E.gnormx+u.posy*E.gnormy+E.lprojection,E.tp0=P.y*E.gnormx-P.x*E.gnormy,E.tp1=N.y*E.gnormx-N.x*E.gnormy,P=N,v=v.next}let g=z.gverts.next,k=w.elt;w=w.next,k.gnormx=u.axisy*k.lnormx-u.axisx*k.lnormy,k.gnormy=k.lnormx*u.axisx+k.lnormy*u.axisy,k.gprojection=u.posx*k.gnormx+u.posy*k.gnormy+k.lprojection,k.tp0=P.y*k.gnormx-P.x*k.gnormy,k.tp1=g.y*k.gnormx-g.x*k.gnormy}}if(!h.sweepFrozen){let d=n*e,f=d-h.sweepTime;if(f!=0){h.sweepTime=d;let z=f;if(h.posx+=h.velx*z,h.posy+=h.vely*z,h.angvel!=0){let Z=h.sweep_angvel*f;if(h.rot+=Z,Z*Z>1e-4)h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot);else{let y=Z*Z,w=1-.5*y,v=1-y*y/8,P=(w*h.axisx+Z*h.axisy)*v;h.axisy=(w*h.axisy-Z*h.axisx)*v,h.axisx=P}}}let m=i.s2;if(m.type==0)m.worldCOMx=h.posx+(h.axisy*m.localCOMx-h.axisx*m.localCOMy),m.worldCOMy=h.posy+(m.localCOMx*h.axisx+m.localCOMy*h.axisy);else{let z=m.polygon,Z=z.lverts.next,y=z.gverts.next;for(;y!=null;){let N=y,E=Z;Z=Z.next,N.x=h.posx+(h.axisy*E.x-h.axisx*E.y),N.y=h.posy+(E.x*h.axisx+E.y*h.axisy),y=y.next}let w=z.edges.head,v=z.gverts.next,P=v;for(v=v.next;v!=null;){let N=v,E=w.elt;w=w.next,E.gnormx=h.axisy*E.lnormx-h.axisx*E.lnormy,E.gnormy=E.lnormx*h.axisx+E.lnormy*h.axisy,E.gprojection=h.posx*E.gnormx+h.posy*E.gnormy+E.lprojection,E.tp0=P.y*E.gnormx-P.x*E.gnormy,E.tp1=N.y*E.gnormx-N.x*E.gnormy,P=N,v=v.next}let g=z.gverts.next,k=w.elt;w=w.next,k.gnormx=h.axisy*k.lnormx-h.axisx*k.lnormy,k.gnormy=k.lnormx*h.axisx+k.lnormy*h.axisy,k.gprojection=h.posx*k.gnormx+h.posy*k.gnormy+k.lprojection,k.tp0=P.y*k.gnormx-P.x*k.gnormy,k.tp1=g.y*k.gnormx-g.x*k.gnormy}}let x=i.arbiter==null,b=this.narrowPhase(i.s1,i.s2,!0,i.arbiter,!0);if(b==null)i.arbiter!=null&&i.arbiter.pair!=null&&(i.arbiter.pair.arb=null,i.arbiter.pair=null);else if(!this.presteparb(b,e,!0)&&b.type==Ve.COL&&b.active&&(b.immState&1)!=0){let d=b.colarb,f=d.nx*d.c1.jnAcc-d.ny*d.c1.jtAcc,m=d.ny*d.c1.jnAcc+d.nx*d.c1.jtAcc,z=d.b1.imass;d.b1.velx-=f*z,d.b1.vely-=m*z,d.b1.angvel-=d.b1.iinertia*(m*d.c1.r1x-f*d.c1.r1y);let Z=d.b2.imass;if(d.b2.velx+=f*Z,d.b2.vely+=m*Z,d.b2.angvel+=d.b2.iinertia*(m*d.c1.r2x-f*d.c1.r2y),d.hc2){let ce=d.nx*d.c2.jnAcc-d.ny*d.c2.jtAcc,pe=d.ny*d.c2.jnAcc+d.nx*d.c2.jtAcc,ae=d.b1.imass;d.b1.velx-=ce*ae,d.b1.vely-=pe*ae,d.b1.angvel-=d.b1.iinertia*(pe*d.c2.r1x-ce*d.c2.r1y);let _e=d.b2.imass;d.b2.velx+=ce*_e,d.b2.vely+=pe*_e,d.b2.angvel+=d.b2.iinertia*(pe*d.c2.r2x-ce*d.c2.r2y)}d.b2.angvel+=d.jrAcc*d.b2.iinertia,d.b1.angvel-=d.jrAcc*d.b1.iinertia;let y=b.colarb,w=y.k1x+y.b2.velx-y.c1.r2y*y.b2.angvel-(y.b1.velx-y.c1.r1y*y.b1.angvel),v=y.k1y+y.b2.vely+y.c1.r2x*y.b2.angvel-(y.b1.vely+y.c1.r1x*y.b1.angvel),P=(v*y.nx-w*y.ny+y.surfacex)*y.c1.tMass,g=y.c1.friction*y.c1.jnAcc,k=y.c1.jtAcc,N=k-P;N>g?N=g:N<-g&&(N=-g),P=N-k,y.c1.jtAcc=N;let E=-y.ny*P,M=y.nx*P;if(y.b2.velx+=E*y.b2.imass,y.b2.vely+=M*y.b2.imass,y.b1.velx-=E*y.b1.imass,y.b1.vely-=M*y.b1.imass,y.b2.angvel+=y.rt1b*P*y.b2.iinertia,y.b1.angvel-=y.rt1a*P*y.b1.iinertia,y.hc2){let ce=y.k2x+y.b2.velx-y.c2.r2y*y.b2.angvel-(y.b1.velx-y.c2.r1y*y.b1.angvel),pe=y.k2y+y.b2.vely+y.c2.r2x*y.b2.angvel-(y.b1.vely+y.c2.r1x*y.b1.angvel);P=(pe*y.nx-ce*y.ny+y.surfacex)*y.c2.tMass,g=y.c2.friction*y.c2.jnAcc,k=y.c2.jtAcc,N=k-P,N>g?N=g:N<-g&&(N=-g),P=N-k,y.c2.jtAcc=N,E=-y.ny*P,M=y.nx*P,y.b2.velx+=E*y.b2.imass,y.b2.vely+=M*y.b2.imass,y.b1.velx-=E*y.b1.imass,y.b1.vely-=M*y.b1.imass,y.b2.angvel+=y.rt2b*P*y.b2.iinertia,y.b1.angvel-=y.rt2a*P*y.b1.iinertia,w=y.k1x+y.b2.velx-y.c1.r2y*y.b2.angvel-(y.b1.velx-y.c1.r1y*y.b1.angvel),v=y.k1y+y.b2.vely+y.c1.r2x*y.b2.angvel-(y.b1.vely+y.c1.r1x*y.b1.angvel),ce=y.k2x+y.b2.velx-y.c2.r2y*y.b2.angvel-(y.b1.velx-y.c2.r1y*y.b1.angvel),pe=y.k2y+y.b2.vely+y.c2.r2x*y.b2.angvel-(y.b1.vely+y.c2.r1x*y.b1.angvel);let ae=y.c1.jnAcc,_e=y.c2.jnAcc,te=w*y.nx+v*y.ny+y.surfacey+y.c1.bounce-(y.Ka*ae+y.Kb*_e),he=ce*y.nx+pe*y.ny+y.surfacey+y.c2.bounce-(y.Kb*ae+y.Kc*_e),me=-(y.kMassa*te+y.kMassb*he),ue=-(y.kMassb*te+y.kMassc*he);me>=0&&ue>=0?(te=me-ae,he=ue-_e,y.c1.jnAcc=me,y.c2.jnAcc=ue):(me=-y.c1.nMass*te,me>=0&&y.Kb*me+he>=0?(te=me-ae,he=-_e,y.c1.jnAcc=me,y.c2.jnAcc=0):(ue=-y.c2.nMass*he,ue>=0&&y.Kb*ue+te>=0?(te=-ae,he=ue-_e,y.c1.jnAcc=0,y.c2.jnAcc=ue):te>=0&&he>=0?(te=-ae,he=-_e,y.c1.jnAcc=y.c2.jnAcc=0):(te=0,he=0))),P=te+he,E=y.nx*P,M=y.ny*P,y.b2.velx+=E*y.b2.imass,y.b2.vely+=M*y.b2.imass,y.b1.velx-=E*y.b1.imass,y.b1.vely-=M*y.b1.imass,y.b2.angvel+=(y.rn1b*te+y.rn2b*he)*y.b2.iinertia,y.b1.angvel-=(y.rn1a*te+y.rn2a*he)*y.b1.iinertia}else y.radius!=0&&(P=(y.b2.angvel-y.b1.angvel)*y.rMass,g=y.rfric*y.c1.jnAcc,k=y.jrAcc,y.jrAcc-=P,y.jrAcc>g?y.jrAcc=g:y.jrAcc<-g&&(y.jrAcc=-g),P=y.jrAcc-k,y.b2.angvel+=P*y.b2.iinertia,y.b1.angvel-=P*y.b1.iinertia),w=y.k1x+y.b2.velx-y.c1.r2y*y.b2.angvel-(y.b1.velx-y.c1.r1y*y.b1.angvel),v=y.k1y+y.b2.vely+y.c1.r2x*y.b2.angvel-(y.b1.vely+y.c1.r1x*y.b1.angvel),P=(y.c1.bounce+(y.nx*w+y.ny*v)+y.surfacey)*y.c1.nMass,k=y.c1.jnAcc,N=k-P,N<0&&(N=0),P=N-k,y.c1.jnAcc=N,E=y.nx*P,M=y.ny*P,y.b2.velx+=E*y.b2.imass,y.b2.vely+=M*y.b2.imass,y.b1.velx-=E*y.b1.imass,y.b1.vely-=M*y.b1.imass,y.b2.angvel+=y.rn1b*P*y.b2.iinertia,y.b1.angvel-=y.rn1a*P*y.b1.iinertia;let C=b.colarb,L=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),I=(O*C.nx-L*C.ny+C.surfacex)*C.c1.tMass,T=C.c1.friction*C.c1.jnAcc,W=C.c1.jtAcc,R=W-I;R>T?R=T:R<-T&&(R=-T),I=R-W,C.c1.jtAcc=R;let G=-C.ny*I,j=C.nx*I;if(C.b2.velx+=G*C.b2.imass,C.b2.vely+=j*C.b2.imass,C.b1.velx-=G*C.b1.imass,C.b1.vely-=j*C.b1.imass,C.b2.angvel+=C.rt1b*I*C.b2.iinertia,C.b1.angvel-=C.rt1a*I*C.b1.iinertia,C.hc2){let ce=C.k2x+C.b2.velx-C.c2.r2y*C.b2.angvel-(C.b1.velx-C.c2.r1y*C.b1.angvel),pe=C.k2y+C.b2.vely+C.c2.r2x*C.b2.angvel-(C.b1.vely+C.c2.r1x*C.b1.angvel);I=(pe*C.nx-ce*C.ny+C.surfacex)*C.c2.tMass,T=C.c2.friction*C.c2.jnAcc,W=C.c2.jtAcc,R=W-I,R>T?R=T:R<-T&&(R=-T),I=R-W,C.c2.jtAcc=R,G=-C.ny*I,j=C.nx*I,C.b2.velx+=G*C.b2.imass,C.b2.vely+=j*C.b2.imass,C.b1.velx-=G*C.b1.imass,C.b1.vely-=j*C.b1.imass,C.b2.angvel+=C.rt2b*I*C.b2.iinertia,C.b1.angvel-=C.rt2a*I*C.b1.iinertia,L=C.k1x+C.b2.velx-C.c1.r2y*C.b2.angvel-(C.b1.velx-C.c1.r1y*C.b1.angvel),O=C.k1y+C.b2.vely+C.c1.r2x*C.b2.angvel-(C.b1.vely+C.c1.r1x*C.b1.angvel),ce=C.k2x+C.b2.velx-C.c2.r2y*C.b2.angvel-(C.b1.velx-C.c2.r1y*C.b1.angvel),pe=C.k2y+C.b2.vely+C.c2.r2x*C.b2.angvel-(C.b1.vely+C.c2.r1x*C.b1.angvel);let ae=C.c1.jnAcc,_e=C.c2.jnAcc,te=L*C.nx+O*C.ny+C.surfacey+C.c1.bounce-(C.Ka*ae+C.Kb*_e),he=ce*C.nx+pe*C.ny+C.surfacey+C.c2.bounce-(C.Kb*ae+C.Kc*_e),me=-(C.kMassa*te+C.kMassb*he),ue=-(C.kMassb*te+C.kMassc*he);me>=0&&ue>=0?(te=me-ae,he=ue-_e,C.c1.jnAcc=me,C.c2.jnAcc=ue):(me=-C.c1.nMass*te,me>=0&&C.Kb*me+he>=0?(te=me-ae,he=-_e,C.c1.jnAcc=me,C.c2.jnAcc=0):(ue=-C.c2.nMass*he,ue>=0&&C.Kb*ue+te>=0?(te=-ae,he=ue-_e,C.c1.jnAcc=0,C.c2.jnAcc=ue):te>=0&&he>=0?(te=-ae,he=-_e,C.c1.jnAcc=C.c2.jnAcc=0):(te=0,he=0))),I=te+he,G=C.nx*I,j=C.ny*I,C.b2.velx+=G*C.b2.imass,C.b2.vely+=j*C.b2.imass,C.b1.velx-=G*C.b1.imass,C.b1.vely-=j*C.b1.imass,C.b2.angvel+=(C.rn1b*te+C.rn2b*he)*C.b2.iinertia,C.b1.angvel-=(C.rn1a*te+C.rn2a*he)*C.b1.iinertia}else C.radius!=0&&(I=(C.b2.angvel-C.b1.angvel)*C.rMass,T=C.rfric*C.c1.jnAcc,W=C.jrAcc,C.jrAcc-=I,C.jrAcc>T?C.jrAcc=T:C.jrAcc<-T&&(C.jrAcc=-T),I=C.jrAcc-W,C.b2.angvel+=I*C.b2.iinertia,C.b1.angvel-=I*C.b1.iinertia),L=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),I=(C.c1.bounce+(C.nx*L+C.ny*O)+C.surfacey)*C.c1.nMass,W=C.c1.jnAcc,R=W-I,R<0&&(R=0),I=R-W,C.c1.jnAcc=R,G=C.nx*I,j=C.ny*I,C.b2.velx+=G*C.b2.imass,C.b2.vely+=j*C.b2.imass,C.b1.velx-=G*C.b1.imass,C.b1.vely-=j*C.b1.imass,C.b2.angvel+=C.rn1b*I*C.b2.iinertia,C.b1.angvel-=C.rn1a*I*C.b1.iinertia;let S=b.colarb,q=S.k1x+S.b2.velx-S.c1.r2y*S.b2.angvel-(S.b1.velx-S.c1.r1y*S.b1.angvel),$=S.k1y+S.b2.vely+S.c1.r2x*S.b2.angvel-(S.b1.vely+S.c1.r1x*S.b1.angvel),X=($*S.nx-q*S.ny+S.surfacex)*S.c1.tMass,H=S.c1.friction*S.c1.jnAcc,ee=S.c1.jtAcc,F=ee-X;F>H?F=H:F<-H&&(F=-H),X=F-ee,S.c1.jtAcc=F;let D=-S.ny*X,B=S.nx*X;if(S.b2.velx+=D*S.b2.imass,S.b2.vely+=B*S.b2.imass,S.b1.velx-=D*S.b1.imass,S.b1.vely-=B*S.b1.imass,S.b2.angvel+=S.rt1b*X*S.b2.iinertia,S.b1.angvel-=S.rt1a*X*S.b1.iinertia,S.hc2){let ce=S.k2x+S.b2.velx-S.c2.r2y*S.b2.angvel-(S.b1.velx-S.c2.r1y*S.b1.angvel),pe=S.k2y+S.b2.vely+S.c2.r2x*S.b2.angvel-(S.b1.vely+S.c2.r1x*S.b1.angvel);X=(pe*S.nx-ce*S.ny+S.surfacex)*S.c2.tMass,H=S.c2.friction*S.c2.jnAcc,ee=S.c2.jtAcc,F=ee-X,F>H?F=H:F<-H&&(F=-H),X=F-ee,S.c2.jtAcc=F,D=-S.ny*X,B=S.nx*X,S.b2.velx+=D*S.b2.imass,S.b2.vely+=B*S.b2.imass,S.b1.velx-=D*S.b1.imass,S.b1.vely-=B*S.b1.imass,S.b2.angvel+=S.rt2b*X*S.b2.iinertia,S.b1.angvel-=S.rt2a*X*S.b1.iinertia,q=S.k1x+S.b2.velx-S.c1.r2y*S.b2.angvel-(S.b1.velx-S.c1.r1y*S.b1.angvel),$=S.k1y+S.b2.vely+S.c1.r2x*S.b2.angvel-(S.b1.vely+S.c1.r1x*S.b1.angvel),ce=S.k2x+S.b2.velx-S.c2.r2y*S.b2.angvel-(S.b1.velx-S.c2.r1y*S.b1.angvel),pe=S.k2y+S.b2.vely+S.c2.r2x*S.b2.angvel-(S.b1.vely+S.c2.r1x*S.b1.angvel);let ae=S.c1.jnAcc,_e=S.c2.jnAcc,te=q*S.nx+$*S.ny+S.surfacey+S.c1.bounce-(S.Ka*ae+S.Kb*_e),he=ce*S.nx+pe*S.ny+S.surfacey+S.c2.bounce-(S.Kb*ae+S.Kc*_e),me=-(S.kMassa*te+S.kMassb*he),ue=-(S.kMassb*te+S.kMassc*he);me>=0&&ue>=0?(te=me-ae,he=ue-_e,S.c1.jnAcc=me,S.c2.jnAcc=ue):(me=-S.c1.nMass*te,me>=0&&S.Kb*me+he>=0?(te=me-ae,he=-_e,S.c1.jnAcc=me,S.c2.jnAcc=0):(ue=-S.c2.nMass*he,ue>=0&&S.Kb*ue+te>=0?(te=-ae,he=ue-_e,S.c1.jnAcc=0,S.c2.jnAcc=ue):te>=0&&he>=0?(te=-ae,he=-_e,S.c1.jnAcc=S.c2.jnAcc=0):(te=0,he=0))),X=te+he,D=S.nx*X,B=S.ny*X,S.b2.velx+=D*S.b2.imass,S.b2.vely+=B*S.b2.imass,S.b1.velx-=D*S.b1.imass,S.b1.vely-=B*S.b1.imass,S.b2.angvel+=(S.rn1b*te+S.rn2b*he)*S.b2.iinertia,S.b1.angvel-=(S.rn1a*te+S.rn2a*he)*S.b1.iinertia}else S.radius!=0&&(X=(S.b2.angvel-S.b1.angvel)*S.rMass,H=S.rfric*S.c1.jnAcc,ee=S.jrAcc,S.jrAcc-=X,S.jrAcc>H?S.jrAcc=H:S.jrAcc<-H&&(S.jrAcc=-H),X=S.jrAcc-ee,S.b2.angvel+=X*S.b2.iinertia,S.b1.angvel-=X*S.b1.iinertia),q=S.k1x+S.b2.velx-S.c1.r2y*S.b2.angvel-(S.b1.velx-S.c1.r1y*S.b1.angvel),$=S.k1y+S.b2.vely+S.c1.r2x*S.b2.angvel-(S.b1.vely+S.c1.r1x*S.b1.angvel),X=(S.c1.bounce+(S.nx*q+S.ny*$)+S.surfacey)*S.c1.nMass,ee=S.c1.jnAcc,F=ee-X,F<0&&(F=0),X=F-ee,S.c1.jnAcc=F,D=S.nx*X,B=S.ny*X,S.b2.velx+=D*S.b2.imass,S.b2.vely+=B*S.b2.imass,S.b1.velx-=D*S.b1.imass,S.b1.vely-=B*S.b1.imass,S.b2.angvel+=S.rn1b*X*S.b2.iinertia,S.b1.angvel-=S.rn1a*X*S.b1.iinertia;let V=b.colarb,J=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),K=(Q*V.nx-J*V.ny+V.surfacex)*V.c1.tMass,ne=V.c1.friction*V.c1.jnAcc,re=V.c1.jtAcc,se=re-K;se>ne?se=ne:se<-ne&&(se=-ne),K=se-re,V.c1.jtAcc=se;let ie=-V.ny*K,oe=V.nx*K;if(V.b2.velx+=ie*V.b2.imass,V.b2.vely+=oe*V.b2.imass,V.b1.velx-=ie*V.b1.imass,V.b1.vely-=oe*V.b1.imass,V.b2.angvel+=V.rt1b*K*V.b2.iinertia,V.b1.angvel-=V.rt1a*K*V.b1.iinertia,V.hc2){let ce=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),pe=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);K=(pe*V.nx-ce*V.ny+V.surfacex)*V.c2.tMass,ne=V.c2.friction*V.c2.jnAcc,re=V.c2.jtAcc,se=re-K,se>ne?se=ne:se<-ne&&(se=-ne),K=se-re,V.c2.jtAcc=se,ie=-V.ny*K,oe=V.nx*K,V.b2.velx+=ie*V.b2.imass,V.b2.vely+=oe*V.b2.imass,V.b1.velx-=ie*V.b1.imass,V.b1.vely-=oe*V.b1.imass,V.b2.angvel+=V.rt2b*K*V.b2.iinertia,V.b1.angvel-=V.rt2a*K*V.b1.iinertia,J=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),ce=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),pe=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);let ae=V.c1.jnAcc,_e=V.c2.jnAcc,te=J*V.nx+Q*V.ny+V.surfacey+V.c1.bounce-(V.Ka*ae+V.Kb*_e),he=ce*V.nx+pe*V.ny+V.surfacey+V.c2.bounce-(V.Kb*ae+V.Kc*_e),me=-(V.kMassa*te+V.kMassb*he),ue=-(V.kMassb*te+V.kMassc*he);me>=0&&ue>=0?(te=me-ae,he=ue-_e,V.c1.jnAcc=me,V.c2.jnAcc=ue):(me=-V.c1.nMass*te,me>=0&&V.Kb*me+he>=0?(te=me-ae,he=-_e,V.c1.jnAcc=me,V.c2.jnAcc=0):(ue=-V.c2.nMass*he,ue>=0&&V.Kb*ue+te>=0?(te=-ae,he=ue-_e,V.c1.jnAcc=0,V.c2.jnAcc=ue):te>=0&&he>=0?(te=-ae,he=-_e,V.c1.jnAcc=V.c2.jnAcc=0):(te=0,he=0))),K=te+he,ie=V.nx*K,oe=V.ny*K,V.b2.velx+=ie*V.b2.imass,V.b2.vely+=oe*V.b2.imass,V.b1.velx-=ie*V.b1.imass,V.b1.vely-=oe*V.b1.imass,V.b2.angvel+=(V.rn1b*te+V.rn2b*he)*V.b2.iinertia,V.b1.angvel-=(V.rn1a*te+V.rn2a*he)*V.b1.iinertia}else V.radius!=0&&(K=(V.b2.angvel-V.b1.angvel)*V.rMass,ne=V.rfric*V.c1.jnAcc,re=V.jrAcc,V.jrAcc-=K,V.jrAcc>ne?V.jrAcc=ne:V.jrAcc<-ne&&(V.jrAcc=-ne),K=V.jrAcc-re,V.b2.angvel+=K*V.b2.iinertia,V.b1.angvel-=K*V.b1.iinertia),J=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),K=(V.c1.bounce+(V.nx*J+V.ny*Q)+V.surfacey)*V.c1.nMass,re=V.c1.jnAcc,se=re-K,se<0&&(se=0),K=se-re,V.c1.jnAcc=se,ie=V.nx*K,oe=V.ny*K,V.b2.velx+=ie*V.b2.imass,V.b2.vely+=oe*V.b2.imass,V.b1.velx-=ie*V.b1.imass,V.b1.vely-=oe*V.b1.imass,V.b2.angvel+=V.rn1b*K*V.b2.iinertia,V.b1.angvel-=V.rn1a*K*V.b1.iinertia;u.sweep_angvel=u.angvel%t,h.sweep_angvel=h.angvel%t}if(b!=null&&b.active&&(b.immState&1)!=0&&b.type==Ve.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*=A._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*=A._nape.Config.angularCCDSlipScale,h.angvel=d.sweep_angvel}else h.angvel=h.sweep_angvel}let _=i;_.next=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._zpp.geom.ZPP_ToiEvent.zpp_pool=_}for(;this.toiEvents.head!=null;){let o=this.toiEvents.pop_unsafe();o.next=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._zpp.geom.ZPP_ToiEvent.zpp_pool=o}let l=this.kinematics.head;for(;l!=null;){let i=l.elt,o=e-i.sweepTime;if(o!=0){i.sweepTime=e;let r=o;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let a=i.sweep_angvel*o;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let p=a*a,c=1-.5*p,u=1-p*p/8,h=(c*i.axisx+a*i.axisy)*u;i.axisy=(c*i.axisy-a*i.axisx)*u,i.axisx=h}}}i.sweepTime=0,l=l.next}let s=this.live.head;for(;s!=null;){let i=s.elt;if(!i.sweepFrozen){let o=e-i.sweepTime;if(o!=0){i.sweepTime=e;let r=o;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let a=i.sweep_angvel*o;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let p=a*a,c=1-.5*p,u=1-p*p/8,h=(c*i.axisx+a*i.axisy)*u;i.axisy=(c*i.axisy-a*i.axisx)*u,i.axisx=h}}}}i.sweepTime=0,s=s.next}}continuousEvent(e,t,n,l,s){if(e.body.sweepFrozen&&t.body.sweepFrozen||e.body.disableCCD||t.body.disableCCD)return l;let i;if(l!=null&&l.colarb==null)i=!0;else{let a=e.body,p=t.body,c;c=!1;let u=a.constraints.head;for(;u!=null;){let b=u.elt;if(b.ignore&&b.pair_exists(a.id,p.id)){c=!0;break}u=u.next}let h,x;if(c)x=!1;else{let b=e;for(;b!=null&&b.group==null;)b.ishape!=null?b=b.ishape.body:b.icompound!=null?b=b.icompound.compound:b=b.ibody.compound;let _=b==null?null:b.group,d;if(_==null)d=!1;else{let f=t;for(;f!=null&&f.group==null;)f.ishape!=null?f=f.ishape.body:f.icompound!=null?f=f.icompound.compound:f=f.ibody.compound;let m=f==null?null:f.group;if(m==null)d=!1;else{let z=!1;for(;_!=null&&m!=null;){if(_==m){z=_.ignore;break}_.depth<m.depth?m=m.group:_=_.group}d=z}}x=!d}if(x){let b;if(e.sensorEnabled||t.sensorEnabled){let _=e.filter,d=t.filter;b=(_.sensorMask&d.sensorGroup)!=0&&(d.sensorMask&_.sensorGroup)!=0}else b=!1;if(b)h=2;else{let _;if(e.fluidEnabled||t.fluidEnabled){let d=e.filter,f=t.filter;_=(d.fluidMask&f.fluidGroup)!=0&&(f.fluidMask&d.fluidGroup)!=0}else _=!1;if(_&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0))h=0;else{let d=e.filter,f=t.filter;h=(d.collisionMask&f.collisionGroup)!=0&&(f.collisionMask&d.collisionGroup)!=0&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0)?1:-1}}}else h=-1;i=h<=0}if(i)return l;let o=e.body,r=t.body;if(n||o.bullet||r.bullet){let a;A._zpp.geom.ZPP_ToiEvent.zpp_pool==null?a=new A._zpp.geom.ZPP_ToiEvent:(a=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._zpp.geom.ZPP_ToiEvent.zpp_pool=a.next,a.next=null),a.failed=!1,a.s1=a.s2=null,a.arbiter=null;let p=o.type==3||r.type==3;if(n&&!p)e.body.type!=2?(a.s2=e,a.s1=t):(a.s1=e,a.s2=t),a.kinematic=!1,wn.staticSweep(a,this.pre_dt,0,A._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}wn.staticSweep(a,this.pre_dt,0,A._nape.Config.collisionSlopCCD)}else wn.dynamicSweep(a,this.pre_dt,0,A._nape.Config.collisionSlopCCD,!1);if(n&&a.toi<0||a.failed){let c=a;c.next=A._zpp.geom.ZPP_ToiEvent.zpp_pool,A._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 A._zpp.util.ZNPList_ZPP_Interactor,l=e.interactors.head;for(;l!=null;){let s=l.elt;n.add(s),l=l.next}if(e!=t){let s=t.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next}}for(;n.head!=null;){let s=n.pop_unsafe();if(s.icompound!=null){let i=s.icompound,o=i.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=i.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let i=s.ibody!=null?s.ibody:s.ishape.body,o=s.ishape!=null?s.ishape:null,r=i.arbiters.head;for(;r!=null;){let a=r.elt;if(a.present==0){r=r.next;continue}if(o!=null&&!(a.ws1==o||a.ws2==o)){r=r.next;continue}this.MRCA_chains(a.ws1,a.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let u=this.mrca2.head;for(;u!=null;){let h=u.elt;if(c.cbSet==e&&h.cbSet!=t||c.cbSet==t&&h.cbSet!=e){u=u.next;continue}let x=A._zpp.phys.ZPP_Interactor.get(c,h);if(x!=null){for(;x.arbiters.head!=null;){let b=x.arbiters.pop_unsafe();b.present--}this.remove_callbackset(x)}u=u.next}p=p.next}r=r.next}}}}nullInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,l=n.bodies.head;for(;l!=null;){let i=l.elt;this.nullInteractorType(i,t),l=l.next}let s=n.compounds.head;for(;s!=null;){let i=s.elt;this.nullInteractorType(i,t),s=s.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,l=e.ishape!=null?e.ishape:null,s=n.arbiters.head;for(;s!=null;){let i=s.elt;if(i.present==0){s=s.next;continue}if(l!=null&&!(i.ws1==l||i.ws2==l)){s=s.next;continue}this.MRCA_chains(i.ws1,i.ws2);let o=this.mrca1.head;for(;o!=null;){let r=o.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(r!=t&&p!=t){a=a.next;continue}let c=A._zpp.phys.ZPP_Interactor.get(r,p);c!=null&&(i.present--,c.remove_arb(i),c.arbiters.head==null&&this.remove_callbackset(c)),a=a.next}o=o.next}s=s.next}}}freshListenerType(e,t){let n=new A._zpp.util.ZNPList_ZPP_Interactor,l=e.interactors.head;for(;l!=null;){let s=l.elt;n.add(s),l=l.next}if(e!=t){let s=t.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next}}for(;n.head!=null;){let s=n.pop_unsafe();if(s.icompound!=null){let i=s.icompound,o=i.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=i.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let i=s.ibody!=null?s.ibody:s.ishape.body,o=s.ishape!=null?s.ishape:null,r=i.arbiters.head;for(;r!=null;){let a=r.elt;if(!a.presentable){r=r.next;continue}if(o!=null&&!(a.ws1==o||a.ws2==o)){r=r.next;continue}this.MRCA_chains(a.ws1,a.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let u=this.mrca2.head;for(;u!=null;){let h=u.elt;if(c.cbSet==e&&h.cbSet!=t||c.cbSet==t&&h.cbSet!=e){u=u.next;continue}let x=A._zpp.phys.ZPP_Interactor.get(c,h);x==null&&(x=Ht.get(c,h),this.add_callbackset(x));let b,_;_=!1;let d=x.arbiters.head;for(;d!=null;){if(d.elt==a){_=!0;break}d=d.next}if(_)b=!1;else{let f=x.arbiters,m;A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?m=new A._zpp.util.ZNPNode_ZPP_Arbiter:(m=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=m.next,m.next=null),m.elt=a;let z=m;z.next=f.head,f.head=z,f.modified=!0,f.length++,b=!0}b&&a.present++,u=u.next}p=p.next}r=r.next}}}}freshInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,l=n.bodies.head;for(;l!=null;){let i=l.elt;this.freshInteractorType(i,t),l=l.next}let s=n.compounds.head;for(;s!=null;){let i=s.elt;this.freshInteractorType(i,t),s=s.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,l=e.ishape!=null?e.ishape:null,s=n.arbiters.head;for(;s!=null;){let i=s.elt;if(!i.presentable){s=s.next;continue}if(l!=null&&!(i.ws1==l||i.ws2==l)){s=s.next;continue}this.MRCA_chains(i.ws1,i.ws2);let o=this.mrca1.head;for(;o!=null;){let r=o.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(r!=t&&p!=t){a=a.next;continue}let c=r.cbSet,u=p.cbSet;c.validate(),u.validate();let h=c.manager,x=null,_=(c.cbpairs.length<u.cbpairs.length?c.cbpairs:u.cbpairs).head;for(;_!=null;){let d=_.elt;if(d.a==c&&d.b==u||d.a==u&&d.b==c){x=d;break}_=_.next}if(x==null){let d;Ne.zpp_pool==null?d=new Ne:(d=Ne.zpp_pool,Ne.zpp_pool=d.next,d.next=null),d.zip_listeners=!0,Pt.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=A._zpp.phys.ZPP_Interactor.get(r,p);d==null&&(d=Ht.get(r,p),this.add_callbackset(d));let f,m;m=!1;let z=d.arbiters.head;for(;z!=null;){if(z.elt==i){m=!0;break}z=z.next}if(m)f=!1;else{let Z=d.arbiters,y;A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?y=new A._zpp.util.ZNPNode_ZPP_Arbiter:(y=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y.next,y.next=null),y.elt=i;let w=y;w.next=Z.head,Z.head=w,Z.modified=!0,Z.length++,f=!0}f&&i.present++}a=a.next}o=o.next}s=s.next}}}wakeCompound(e){let t=e.bodies.head;for(;t!=null;){let i=t.elt;i.world||(i.component.waket=this.stamp+(this.midstep?0:1),i.type==3&&(i.kinematicDelaySleep=!0),i.component.sleeping&&this.really_wake(i,!1)),t=t.next}let n=e.constraints.head;for(;n!=null;){let s=n.elt;this.wake_constraint(s),n=n.next}let l=e.compounds.head;for(;l!=null;){let s=l.elt;this.wakeCompound(s),l=l.next}}wakeIsland(e){for(;e.comps.head!=null;){let n=e.comps.pop_unsafe();if(n.waket=this.stamp+(this.midstep?0:1),n.isBody){let l=n.body;this.live.add(l);let s=l.arbiters.head;for(;s!=null;){let i=s.elt;if(i.sleeping)if(i.sleeping=!1,i.up_stamp+=this.stamp-i.sleep_stamp,i.type==Ve.COL){let o=i.colarb;if(o.stat){let r=this.c_arbiters_true,a;A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new A._zpp.util.ZNPNode_ZPP_ColArbiter:(a=A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}else{let r=this.c_arbiters_false,a;A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new A._zpp.util.ZNPNode_ZPP_ColArbiter:(a=A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}}else if(i.type==Ve.FLUID){let o=this.f_arbiters,r=i.fluidarb,a;A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?a=new A._zpp.util.ZNPNode_ZPP_FluidArbiter:(a=A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}else{let o=this.s_arbiters,r=i.sensorarb,a;A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?a=new A._zpp.util.ZNPNode_ZPP_SensorArbiter:(a=A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}s=s.next}if(this.bodyCbWake(l),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0,l.type!=1){let i=l.shapes.head;for(;i!=null;){let o=i.elt;o.node!=null&&this.bphase.sync(o),i=i.next}}}else{let l=n.constraint,s=this.live_constraints,i;A._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?i=new A._zpp.util.ZNPNode_ZPP_Constraint:(i=A._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,A._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=i.next,i.next=null),i.elt=l;let o=i;o.next=s.head,s.head=o,s.modified=!0,s.length++,this.constraintCbWake(l),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0}}let t=e;t.next=bt.zpp_pool,bt.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;A._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?i=new A._zpp.util.ZNPNode_ZPP_Body:(i=A._zpp.util.ZNPNode_ZPP_Body.zpp_pool,A._zpp.util.ZNPNode_ZPP_Body.zpp_pool=i.next,i.next=null),i.elt=e;let o=i;o.next=s.head,s.head=o,s.modified=!0,s.length++}else{let s=this.live,i;A._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?i=new A._zpp.util.ZNPNode_ZPP_Body:(i=A._zpp.util.ZNPNode_ZPP_Body.zpp_pool,A._zpp.util.ZNPNode_ZPP_Body.zpp_pool=i.next,i.next=null),i.elt=e;let o=i;o.next=s.head,s.head=o,s.modified=!0,s.length++}let n=e.constraints.head;for(;n!=null;){let s=n.elt;s.space==this&&this.wake_constraint(s),n=n.next}let l=e.arbiters.head;for(;l!=null;){let s=l.elt;if(s.sleeping)if(s.sleeping=!1,s.up_stamp+=this.stamp+(this.midstep?0:1)-s.sleep_stamp,s.type==Ve.COL){let i=s.colarb;if(i.stat){let o=this.c_arbiters_true,r;A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new A._zpp.util.ZNPNode_ZPP_ColArbiter:(r=A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=i;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}else{let o=this.c_arbiters_false,r;A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new A._zpp.util.ZNPNode_ZPP_ColArbiter:(r=A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=i;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}}else if(s.type==Ve.FLUID){let i=this.f_arbiters,o=s.fluidarb,r;A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?r=new A._zpp.util.ZNPNode_ZPP_FluidArbiter:(r=A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=i.head,i.head=a,i.modified=!0,i.length++}else{let i=this.s_arbiters,o=s.sensorarb,r;A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?r=new A._zpp.util.ZNPNode_ZPP_SensorArbiter:(r=A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=i.head,i.head=a,i.modified=!0,i.length++}if(s.type!=Ve.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;A._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?l=new A._zpp.util.ZNPNode_ZPP_Constraint:(l=A._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,A._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=l.next,l.next=null),l.elt=e;let s=l;s.next=n.head,n.head=s,n.modified=!0,n.length++,e.wake_connected(),t||this.constraintCbWake(e)}else this.wakeIsland(e.component.island);return!0}else return!1;else return!1}doForests(e){let t=this.c_arbiters_false.head;for(;t!=null;){let s=t.elt;if(!s.cleared&&s.up_stamp==this.stamp&&(s.immState&1)!=0&&s.b1.type==2&&s.b2.type==2){let i;if(s.b1.component==s.b1.component.parent)i=s.b1.component;else{let r=s.b1.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}i=r}let o;if(s.b2.component==s.b2.component.parent)o=s.b2.component;else{let r=s.b2.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}o=r}i!=o&&(i.rank<o.rank?i.parent=o:i.rank>o.rank?o.parent=i:(o.parent=i,i.rank++))}t=t.next}let n=this.f_arbiters.head;for(;n!=null;){let s=n.elt;if(!s.cleared&&s.up_stamp==this.stamp&&(s.immState&1)!=0&&s.b1.type==2&&s.b2.type==2){let i;if(s.b1.component==s.b1.component.parent)i=s.b1.component;else{let r=s.b1.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}i=r}let o;if(s.b2.component==s.b2.component.parent)o=s.b2.component;else{let r=s.b2.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}o=r}i!=o&&(i.rank<o.rank?i.parent=o:i.rank>o.rank?o.parent=i:(o.parent=i,i.rank++))}n=n.next}let l=this.live_constraints.head;for(;l!=null;)l.elt.forest(),l=l.next;for(;this.live.head!=null;){let s=this.live,i=s.head.elt;s.pop();let o=i,r=o.component,a;if(r==r.parent)a=r;else{let x=r,b=null;for(;x!=x.parent;){let _=x.parent;x.parent=b,b=x,x=_}for(;b!=null;){let _=b.parent;b.parent=x,b=_}a=x}if(a.island==null){bt.zpp_pool==null?a.island=new bt:(a.island=bt.zpp_pool,bt.zpp_pool=a.island.next,a.island.next=null),a.island.waket=0;let x=this.islands,b=a.island;b._inuse=!0;let _=b;_.next=x.next,x.next=_,x.modified=!0,x.length++,a.island.sleep=!0}r.island=a.island;let p=r.island.comps,c;A._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new A._zpp.util.ZNPNode_ZPP_Component:(c=A._zpp.util.ZNPNode_ZPP_Component.zpp_pool,A._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=r;let u=c;u.next=p.head,p.head=u,p.modified=!0,p.length++;let h=o.atRest(e);r.island.sleep=r.island.sleep&&h,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.live_constraints.head!=null;){let s=this.live_constraints,i=s.head.elt;s.pop();let r=i.component,a;if(r==r.parent)a=r;else{let h=r,x=null;for(;h!=h.parent;){let b=h.parent;h.parent=x,x=h,h=b}for(;x!=null;){let b=x.parent;x.parent=h,x=b}a=h}r.island=a.island;let p=r.island.comps,c;A._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new A._zpp.util.ZNPNode_ZPP_Component:(c=A._zpp.util.ZNPNode_ZPP_Component.zpp_pool,A._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=r;let u=c;u.next=p.head,p.head=u,p.modified=!0,p.length++,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.islands.next!=null;){let s=this.islands,i=s.next;s.pop();let o=i;if(o.sleep){let r=o.comps.head;for(;r!=null;){let a=r.elt;if(a.isBody){let p=a.body;p.velx=0,p.vely=0,p.angvel=0,a.sleeping=!0;let c=p.shapes.head;for(;c!=null;){let u=c.elt;this.bphase.sync(u),c=c.next}this.bodyCbSleep(p)}else{let p=a.constraint;this.constraintCbSleep(p),a.sleeping=!0}r=r.next}}else{for(;o.comps.head!=null;){let a=o.comps,p=a.head.elt;a.pop();let c=p;if(c.waket=o.waket,c.isBody){let u=this.live,h=c.body,x;A._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?x=new A._zpp.util.ZNPNode_ZPP_Body:(x=A._zpp.util.ZNPNode_ZPP_Body.zpp_pool,A._zpp.util.ZNPNode_ZPP_Body.zpp_pool=x.next,x.next=null),x.elt=h;let b=x;b.next=u.head,u.head=b,u.modified=!0,u.length++}else{let u=this.live_constraints,h=c.constraint,x;A._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?x=new A._zpp.util.ZNPNode_ZPP_Constraint:(x=A._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,A._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=x.next,x.next=null),x.elt=h;let b=x;b.next=u.head,u.head=b,u.modified=!0,u.length++}c.sleeping=!1,c.island=null,c.parent=c,c.rank=0}let r=o;r.next=bt.zpp_pool,bt.zpp_pool=r}}}sleepArbiters(){let e=null,t=this.c_arbiters_true,n=t.head,l=this.c_arbiters_false!=null;for(l&&n==null&&(l=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);n!=null;){let h=n.elt;if(h.b1.component.sleeping&&h.b2.component.sleeping){h.sleep_stamp=this.stamp,h.sleeping=!0;let x,b;e==null?(x=t.head,b=x.next,t.head=b,t.head==null&&(t.pushmod=!0)):(x=e.next,b=x.next,e.next=b,b==null&&(t.pushmod=!0));let _=x;_.elt=null,_.next=A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=_,t.modified=!0,t.length--,t.pushmod=!0,n=b,l&&n==null&&(l=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);continue}e=n,n=n.next,l&&n==null&&(l=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null)}let s=null,i=this.f_arbiters,o=i.head,r=!1;for(r&&o==null&&(r=!1,i=null,s=null);o!=null;){let h=o.elt;if(h.b1.component.sleeping&&h.b2.component.sleeping){h.sleep_stamp=this.stamp,h.sleeping=!0;let x,b;s==null?(x=i.head,b=x.next,i.head=b,i.head==null&&(i.pushmod=!0)):(x=s.next,b=x.next,s.next=b,b==null&&(i.pushmod=!0));let _=x;_.elt=null,_.next=A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=_,i.modified=!0,i.length--,i.pushmod=!0,o=b,r&&o==null&&(r=!1,i=null,s=null);continue}s=o,o=o.next,r&&o==null&&(r=!1,i=null,s=null)}let a=null,p=this.s_arbiters,c=p.head,u=!1;for(u&&c==null&&(u=!1,p=null,a=null);c!=null;){let h=c.elt;if(h.b1.component.sleeping&&h.b2.component.sleeping){h.sleep_stamp=this.stamp,h.sleeping=!0;let x,b;a==null?(x=p.head,b=x.next,p.head=b,p.head==null&&(p.pushmod=!0)):(x=a.next,b=x.next,a.next=b,b==null&&(p.pushmod=!0));let _=x;_.elt=null,_.next=A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=_,p.modified=!0,p.length--,p.pushmod=!0,c=b,u&&c==null&&(u=!1,p=null,a=null);continue}a=c,c=c.next,u&&c==null&&(u=!1,p=null,a=null)}}static_validation(e){if(e.shapes.head!=null){if(e.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(e.zip_aabb){e.zip_aabb=!1,e.aabb.minx=1/0,e.aabb.miny=1/0,e.aabb.maxx=-1/0,e.aabb.maxy=-1/0;let n=e.shapes.head;for(;n!=null;){let l=n.elt;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let o=l.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let u=1;c.localCOMx+=c.lverts.next.next.x*u,c.localCOMy+=c.lverts.next.next.y*u;let h=.5;c.localCOMx*=h,c.localCOMy*=h}else{c.localCOMx=0,c.localCOMy=0;let u=0,h=c.lverts.next,x=h;h=h.next;let b=h;for(h=h.next;h!=null;){let Z=h;u+=b.x*(Z.y-x.y);let y=Z.y*b.x-Z.x*b.y;c.localCOMx+=(b.x+Z.x)*y,c.localCOMy+=(b.y+Z.y)*y,x=b,b=Z,h=h.next}h=c.lverts.next;let _=h;u+=b.x*(_.y-x.y);let d=_.y*b.x-_.x*b.y;c.localCOMx+=(b.x+_.x)*d,c.localCOMy+=(b.y+_.y)*d,x=b,b=_,h=h.next;let f=h;u+=b.x*(f.y-x.y);let m=f.y*b.x-f.x*b.y;c.localCOMx+=(b.x+f.x)*m,c.localCOMy+=(b.y+f.y)*m,u=1/(3*u);let z=u;c.localCOMx*=z,c.localCOMy*=z}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else{let o=l.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,u=o.gverts.next;for(;u!=null;){let h=u,x=c;c=c.next,h.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),h.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),u=u.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}let s=e.aabb,i=l.aabb;i.minx<s.minx&&(s.minx=i.minx),i.maxx>s.maxx&&(s.maxx=i.maxx),i.miny<s.miny&&(s.miny=i.miny),i.maxy>s.maxy&&(s.maxy=i.maxy),n=n.next}}}if(e.validate_mass(),e.validate_inertia(),e.velx!=0||e.vely!=0||e.angvel!=0)throw new Error("Error: Static body cannot have any real velocity, only kinematic or surface velocities");let t=e.shapes.head;for(;t!=null;){let n=t.elt;if(n.type==1){let l=n.polygon;l.zip_sanitation&&(l.zip_sanitation=!1,l.splice_collinear_real());let s=n.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new A._nape.shape.ValidationResult,U.internal=!1),s!=U.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+n.polygon.outer.toString()+" is invalid : "+s.toString());let i=n.polygon;if(i.zip_gaxi&&i.body!=null){i.zip_gaxi=!1,i.validate_laxi();let o=i.body;if(o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let h=i.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot));let x=i.lverts.next,b=i.gverts.next;for(;b!=null;){let _=b,d=x;x=x.next,_.x=i.body.posx+(i.body.axisy*d.x-i.body.axisx*d.y),_.y=i.body.posy+(d.x*i.body.axisx+d.y*i.body.axisy),b=b.next}}let r=i.edges.head,a=i.gverts.next,p=a;for(a=a.next;a!=null;){let h=a,x=r.elt;r=r.next,x.gp0=p,x.gp1=h,x.gnormx=i.body.axisy*x.lnormx-i.body.axisx*x.lnormy,x.gnormy=x.lnormx*i.body.axisx+x.lnormy*i.body.axisy,x.gprojection=i.body.posx*x.gnormx+i.body.posy*x.gnormy+x.lprojection,x.wrap_gnorm!=null&&(x.wrap_gnorm.zpp_inner.x=x.gnormx,x.wrap_gnorm.zpp_inner.y=x.gnormy),x.tp0=x.gp0.y*x.gnormx-x.gp0.x*x.gnormy,x.tp1=x.gp1.y*x.gnormx-x.gp1.x*x.gnormy,p=h,a=a.next}let c=i.gverts.next,u=r.elt;r=r.next,u.gp0=p,u.gp1=c,u.gnormx=i.body.axisy*u.lnormx-i.body.axisx*u.lnormy,u.gnormy=u.lnormx*i.body.axisx+u.lnormy*i.body.axisy,u.gprojection=i.body.posx*u.gnormx+i.body.posy*u.gnormy+u.lprojection,u.wrap_gnorm!=null&&(u.wrap_gnorm.zpp_inner.x=u.gnormx,u.wrap_gnorm.zpp_inner.y=u.gnormy),u.tp0=u.gp0.y*u.gnormx-u.gp0.x*u.gnormy,u.tp1=u.gp1.y*u.gnormx-u.gp1.x*u.gnormy}}t=t.next}e.sweepFrozen=!0}validation(){let e=this.cbsets;if(!e.cbsets.empty()){let s=e.cbsets.parent;for(;s.prev!=null;)s=s.prev;for(;s!=null;)if(s.data.validate(),s.next!=null)for(s=s.next;s.prev!=null;)s=s.prev;else{for(;s.parent!=null&&s==s.parent.next;)s=s.parent;s=s.parent}}let t=this.live.head;for(;t!=null;){let s=t.elt;s.sweepRadius=0;let i=s.shapes.head;for(;i!=null;){let r=i.elt;if(r.type==1){let a=r.polygon;a.zip_sanitation&&(a.zip_sanitation=!1,a.splice_collinear_real());let p=r.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new A._nape.shape.ValidationResult,U.internal=!1),p!=U.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+r.polygon.outer.toString()+" is invalid : "+p.toString());let c=r.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=!1,c.validate_laxi();let u=c.body;if(u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let f=c.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let m=c.lverts.next,z=c.gverts.next;for(;z!=null;){let Z=z,y=m;m=m.next,Z.x=c.body.posx+(c.body.axisy*y.x-c.body.axisx*y.y),Z.y=c.body.posy+(y.x*c.body.axisx+y.y*c.body.axisy),z=z.next}}let h=c.edges.head,x=c.gverts.next,b=x;for(x=x.next;x!=null;){let f=x,m=h.elt;h=h.next,m.gp0=b,m.gp1=f,m.gnormx=c.body.axisy*m.lnormx-c.body.axisx*m.lnormy,m.gnormy=m.lnormx*c.body.axisx+m.lnormy*c.body.axisy,m.gprojection=c.body.posx*m.gnormx+c.body.posy*m.gnormy+m.lprojection,m.wrap_gnorm!=null&&(m.wrap_gnorm.zpp_inner.x=m.gnormx,m.wrap_gnorm.zpp_inner.y=m.gnormy),m.tp0=m.gp0.y*m.gnormx-m.gp0.x*m.gnormy,m.tp1=m.gp1.y*m.gnormx-m.gp1.x*m.gnormy,b=f,x=x.next}let _=c.gverts.next,d=h.elt;h=h.next,d.gp0=b,d.gp1=_,d.gnormx=c.body.axisy*d.lnormx-c.body.axisx*d.lnormy,d.gnormy=d.lnormx*c.body.axisx+d.lnormy*c.body.axisy,d.gprojection=c.body.posx*d.gnormx+c.body.posy*d.gnormy+d.lprojection,d.wrap_gnorm!=null&&(d.wrap_gnorm.zpp_inner.x=d.gnormx,d.wrap_gnorm.zpp_inner.y=d.gnormy),d.tp0=d.gp0.y*d.gnormx-d.gp0.x*d.gnormy,d.tp1=d.gp1.y*d.gnormx-d.gp1.x*d.gnormy}}r.validate_sweepRadius(),r.sweepRadius>s.sweepRadius&&(s.sweepRadius=r.sweepRadius),i=i.next}if(s.validate_mass(),s.validate_inertia(),s.shapes.head!=null){if(s.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(s.zip_aabb){s.zip_aabb=!1,s.aabb.minx=1/0,s.aabb.miny=1/0,s.aabb.maxx=-1/0,s.aabb.maxy=-1/0;let r=s.shapes.head;for(;r!=null;){let a=r.elt;if(a.zip_aabb&&a.body!=null)if(a.zip_aabb=!1,a.type==0){let u=a.circle;if(u.zip_worldCOM&&u.body!=null){if(u.zip_worldCOM=!1,u.zip_localCOM){if(u.zip_localCOM=!1,u.type==1){let _=u.polygon;if(_.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(_.lverts.next.next==null)_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;else if(_.lverts.next.next.next==null){_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;let d=1;_.localCOMx+=_.lverts.next.next.x*d,_.localCOMy+=_.lverts.next.next.y*d;let f=.5;_.localCOMx*=f,_.localCOMy*=f}else{_.localCOMx=0,_.localCOMy=0;let d=0,f=_.lverts.next,m=f;f=f.next;let z=f;for(f=f.next;f!=null;){let g=f;d+=z.x*(g.y-m.y);let k=g.y*z.x-g.x*z.y;_.localCOMx+=(z.x+g.x)*k,_.localCOMy+=(z.y+g.y)*k,m=z,z=g,f=f.next}f=_.lverts.next;let Z=f;d+=z.x*(Z.y-m.y);let y=Z.y*z.x-Z.x*z.y;_.localCOMx+=(z.x+Z.x)*y,_.localCOMy+=(z.y+Z.y)*y,m=z,z=Z,f=f.next;let w=f;d+=z.x*(w.y-m.y);let v=w.y*z.x-w.x*z.y;_.localCOMx+=(z.x+w.x)*v,_.localCOMy+=(z.y+w.y)*v,d=1/(3*d);let P=d;_.localCOMx*=P,_.localCOMy*=P}}u.wrap_localCOM!=null&&(u.wrap_localCOM.zpp_inner.x=u.localCOMx,u.wrap_localCOM.zpp_inner.y=u.localCOMy)}let b=u.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot)),u.worldCOMx=u.body.posx+(u.body.axisy*u.localCOMx-u.body.axisx*u.localCOMy),u.worldCOMy=u.body.posy+(u.localCOMx*u.body.axisx+u.localCOMy*u.body.axisy)}let h=u.radius,x=u.radius;u.aabb.minx=u.worldCOMx-h,u.aabb.miny=u.worldCOMy-x,u.aabb.maxx=u.worldCOMx+h,u.aabb.maxy=u.worldCOMy+x}else{let u=a.polygon;if(u.zip_gverts&&u.body!=null){u.zip_gverts=!1,u.validate_lverts();let b=u.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot));let _=u.lverts.next,d=u.gverts.next;for(;d!=null;){let f=d,m=_;_=_.next,f.x=u.body.posx+(u.body.axisy*m.x-u.body.axisx*m.y),f.y=u.body.posy+(m.x*u.body.axisx+m.y*u.body.axisy),d=d.next}}if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let h=u.gverts.next;u.aabb.minx=h.x,u.aabb.miny=h.y,u.aabb.maxx=h.x,u.aabb.maxy=h.y;let x=u.gverts.next.next;for(;x!=null;){let b=x;b.x<u.aabb.minx&&(u.aabb.minx=b.x),b.x>u.aabb.maxx&&(u.aabb.maxx=b.x),b.y<u.aabb.miny&&(u.aabb.miny=b.y),b.y>u.aabb.maxy&&(u.aabb.maxy=b.y),x=x.next}}let p=s.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),r=r.next}}s.validate_worldCOM()}if(s.validate_gravMass(),s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),!s.nomove&&s.type==2&&s.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!s.norotate&&s.type==2&&s.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");if(s.component.woken&&s.cbSet!=null){let r=s.cbSet.bodylisteners.head;for(;r!=null;){let a=r.elt;if(a.event!=2){r=r.next;continue}let p=this.push_callback(a);p.event=2,p.body=s,r=r.next}}s.component.woken=!1;let o=s.shapes.head;for(;o!=null;){let r=o.elt;this.bphase.sync(r),o=o.next}t=t.next}let n=this.kinematics.head;for(;n!=null;){let s=n.elt;s.sweepRadius=0;let i=s.shapes.head;for(;i!=null;){let r=i.elt;if(r.type==1){let a=r.polygon;a.zip_sanitation&&(a.zip_sanitation=!1,a.splice_collinear_real());let p=r.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new A._nape.shape.ValidationResult,U.internal=!1),p!=U.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+r.polygon.outer.toString()+" is invalid : "+p.toString());let c=r.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=!1,c.validate_laxi();let u=c.body;if(u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let f=c.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let m=c.lverts.next,z=c.gverts.next;for(;z!=null;){let Z=z,y=m;m=m.next,Z.x=c.body.posx+(c.body.axisy*y.x-c.body.axisx*y.y),Z.y=c.body.posy+(y.x*c.body.axisx+y.y*c.body.axisy),z=z.next}}let h=c.edges.head,x=c.gverts.next,b=x;for(x=x.next;x!=null;){let f=x,m=h.elt;h=h.next,m.gp0=b,m.gp1=f,m.gnormx=c.body.axisy*m.lnormx-c.body.axisx*m.lnormy,m.gnormy=m.lnormx*c.body.axisx+m.lnormy*c.body.axisy,m.gprojection=c.body.posx*m.gnormx+c.body.posy*m.gnormy+m.lprojection,m.wrap_gnorm!=null&&(m.wrap_gnorm.zpp_inner.x=m.gnormx,m.wrap_gnorm.zpp_inner.y=m.gnormy),m.tp0=m.gp0.y*m.gnormx-m.gp0.x*m.gnormy,m.tp1=m.gp1.y*m.gnormx-m.gp1.x*m.gnormy,b=f,x=x.next}let _=c.gverts.next,d=h.elt;h=h.next,d.gp0=b,d.gp1=_,d.gnormx=c.body.axisy*d.lnormx-c.body.axisx*d.lnormy,d.gnormy=d.lnormx*c.body.axisx+d.lnormy*c.body.axisy,d.gprojection=c.body.posx*d.gnormx+c.body.posy*d.gnormy+d.lprojection,d.wrap_gnorm!=null&&(d.wrap_gnorm.zpp_inner.x=d.gnormx,d.wrap_gnorm.zpp_inner.y=d.gnormy),d.tp0=d.gp0.y*d.gnormx-d.gp0.x*d.gnormy,d.tp1=d.gp1.y*d.gnormx-d.gp1.x*d.gnormy}}r.validate_sweepRadius(),r.sweepRadius>s.sweepRadius&&(s.sweepRadius=r.sweepRadius),i=i.next}if(s.validate_mass(),s.validate_inertia(),s.shapes.head!=null){if(s.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(s.zip_aabb){s.zip_aabb=!1,s.aabb.minx=1/0,s.aabb.miny=1/0,s.aabb.maxx=-1/0,s.aabb.maxy=-1/0;let r=s.shapes.head;for(;r!=null;){let a=r.elt;if(a.zip_aabb&&a.body!=null)if(a.zip_aabb=!1,a.type==0){let u=a.circle;if(u.zip_worldCOM&&u.body!=null){if(u.zip_worldCOM=!1,u.zip_localCOM){if(u.zip_localCOM=!1,u.type==1){let _=u.polygon;if(_.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(_.lverts.next.next==null)_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;else if(_.lverts.next.next.next==null){_.localCOMx=_.lverts.next.x,_.localCOMy=_.lverts.next.y;let d=1;_.localCOMx+=_.lverts.next.next.x*d,_.localCOMy+=_.lverts.next.next.y*d;let f=.5;_.localCOMx*=f,_.localCOMy*=f}else{_.localCOMx=0,_.localCOMy=0;let d=0,f=_.lverts.next,m=f;f=f.next;let z=f;for(f=f.next;f!=null;){let g=f;d+=z.x*(g.y-m.y);let k=g.y*z.x-g.x*z.y;_.localCOMx+=(z.x+g.x)*k,_.localCOMy+=(z.y+g.y)*k,m=z,z=g,f=f.next}f=_.lverts.next;let Z=f;d+=z.x*(Z.y-m.y);let y=Z.y*z.x-Z.x*z.y;_.localCOMx+=(z.x+Z.x)*y,_.localCOMy+=(z.y+Z.y)*y,m=z,z=Z,f=f.next;let w=f;d+=z.x*(w.y-m.y);let v=w.y*z.x-w.x*z.y;_.localCOMx+=(z.x+w.x)*v,_.localCOMy+=(z.y+w.y)*v,d=1/(3*d);let P=d;_.localCOMx*=P,_.localCOMy*=P}}u.wrap_localCOM!=null&&(u.wrap_localCOM.zpp_inner.x=u.localCOMx,u.wrap_localCOM.zpp_inner.y=u.localCOMy)}let b=u.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot)),u.worldCOMx=u.body.posx+(u.body.axisy*u.localCOMx-u.body.axisx*u.localCOMy),u.worldCOMy=u.body.posy+(u.localCOMx*u.body.axisx+u.localCOMy*u.body.axisy)}let h=u.radius,x=u.radius;u.aabb.minx=u.worldCOMx-h,u.aabb.miny=u.worldCOMy-x,u.aabb.maxx=u.worldCOMx+h,u.aabb.maxy=u.worldCOMy+x}else{let u=a.polygon;if(u.zip_gverts&&u.body!=null){u.zip_gverts=!1,u.validate_lverts();let b=u.body;b.zip_axis&&(b.zip_axis=!1,b.axisx=Math.sin(b.rot),b.axisy=Math.cos(b.rot));let _=u.lverts.next,d=u.gverts.next;for(;d!=null;){let f=d,m=_;_=_.next,f.x=u.body.posx+(u.body.axisy*m.x-u.body.axisx*m.y),f.y=u.body.posy+(m.x*u.body.axisx+m.y*u.body.axisy),d=d.next}}if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let h=u.gverts.next;u.aabb.minx=h.x,u.aabb.miny=h.y,u.aabb.maxx=h.x,u.aabb.maxy=h.y;let x=u.gverts.next.next;for(;x!=null;){let b=x;b.x<u.aabb.minx&&(u.aabb.minx=b.x),b.x>u.aabb.maxx&&(u.aabb.maxx=b.x),b.y<u.aabb.miny&&(u.aabb.miny=b.y),b.y>u.aabb.maxy&&(u.aabb.maxy=b.y),x=x.next}}let p=s.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),r=r.next}}s.validate_worldCOM()}if(s.validate_gravMass(),s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),!s.nomove&&s.type==2&&s.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!s.norotate&&s.type==2&&s.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");let o=s.shapes.head;for(;o!=null;){let r=o.elt;this.bphase.sync(r),o=o.next}n=n.next}let l=this.live_constraints.head;for(;l!=null;){let s=l.elt;if(s.active){if(s.validate(),s.component.woken&&s.cbSet!=null){let i=s.cbSet.conlisteners.head;for(;i!=null;){let o=i.elt;if(o.event!=2){i=i.next;continue}let r=this.push_callback(o);r.event=2,r.constraint=s,i=i.next}}s.component.woken=!1}l=l.next}}updateVel(e){let t=null,n=1-e*this.global_lin_drag,l=1-e*this.global_ang_drag,s=this.live.head;for(;s!=null;){let i=s.elt;if(i.smass!=0){let o=e*i.imass;i.velx=n*i.velx+(i.forcex+this.gravityx*i.gravMass)*o,i.vely=n*i.vely+(i.forcey+this.gravityy*i.gravMass)*o}if(i.sinertia!=0){let o=0,r=0;o=i.worldCOMx-i.posx,r=i.worldCOMy-i.posy;let a=i.torque+(this.gravityy*o-this.gravityx*r)*i.gravMass;i.angvel=l*i.angvel+a*e*i.iinertia}t=s,s=s.next}}updatePos(e){let t=2*Math.PI/e,n=this.live.head;for(;n!=null;){let s=n.elt;s.pre_posx=s.posx,s.pre_posy=s.posy,s.pre_rot=s.rot,s.sweepTime=0,s.sweep_angvel=s.angvel%t;let i=e-s.sweepTime;if(i!=0){s.sweepTime=e;let o=i;if(s.posx+=s.velx*o,s.posy+=s.vely*o,s.angvel!=0){let r=s.sweep_angvel*i;if(s.rot+=r,r*r>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,u=(p*s.axisx+r*s.axisy)*c;s.axisy=(p*s.axisy-r*s.axisx)*c,s.axisx=u}}}if(s.disableCCD)s.sweepFrozen=!0,s.bullet=!1;else{let o=A._nape.Config.staticCCDLinearThreshold*s.sweepRadius,r=A._nape.Config.staticCCDAngularThreshold;if((s.velx*s.velx+s.vely*s.vely)*e*e>o*o||s.angvel*s.angvel*e*e>r*r||s.type==3){let a=s.sweep_angvel;a<0&&(a=-a);let p=1/a,c=s.shapes.head;for(;c!=null;){let u=c.elt,h=u.aabb,x=h.minx,b=h.miny,_=h.maxx,d=h.maxy,f=a*e*u.sweepCoef*.008333333333333333|0;f>8&&(f=8);let m=a*e/f,z=e-s.sweepTime;if(z!=0){s.sweepTime=e;let w=z;if(s.posx+=s.velx*w,s.posy+=s.vely*w,s.angvel!=0){let v=s.sweep_angvel*z;if(s.rot+=v,v*v>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let P=v*v,g=1-.5*P,k=1-P*P/8,N=(g*s.axisx+v*s.axisy)*k;s.axisy=(g*s.axisy-v*s.axisx)*k,s.axisx=N}}}if(u.type==0){let w=u.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else{let w=u.polygon,v=w.lverts.next,P=w.gverts.next,g=v;v=v.next,P.x=w.body.posx+(w.body.axisy*g.x-w.body.axisx*g.y),P.y=w.body.posy+(g.x*w.body.axisx+g.y*w.body.axisy),w.aabb.minx=P.x,w.aabb.miny=P.y,w.aabb.maxx=P.x,w.aabb.maxy=P.y;let k=w.gverts.next.next;for(;k!=null;){let N=k,E=v;v=v.next,N.x=w.body.posx+(w.body.axisy*E.x-w.body.axisx*E.y),N.y=w.body.posy+(E.x*w.body.axisx+E.y*w.body.axisy),N.x<w.aabb.minx&&(w.aabb.minx=N.x),N.x>w.aabb.maxx&&(w.aabb.maxx=N.x),N.y<w.aabb.miny&&(w.aabb.miny=N.y),N.y>w.aabb.maxy&&(w.aabb.maxy=N.y),k=k.next}}x<h.minx?h.minx=x:x=h.minx,b<h.miny?h.miny=b:b=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy;let Z=1,y=f;for(;Z<y;){let w=Z++,v=m*w*p,P=v-s.sweepTime;if(P!=0){s.sweepTime=v;let g=P;if(s.posx+=s.velx*g,s.posy+=s.vely*g,s.angvel!=0){let k=s.sweep_angvel*P;if(s.rot+=k,k*k>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let N=k*k,E=1-.5*N,M=1-N*N/8,C=(E*s.axisx+k*s.axisy)*M;s.axisy=(E*s.axisy-k*s.axisx)*M,s.axisx=C}}}if(u.type==0){let g=u.circle;g.worldCOMx=g.body.posx+(g.body.axisy*g.localCOMx-g.body.axisx*g.localCOMy),g.worldCOMy=g.body.posy+(g.localCOMx*g.body.axisx+g.localCOMy*g.body.axisy),g.aabb.minx=g.worldCOMx-g.radius,g.aabb.miny=g.worldCOMy-g.radius,g.aabb.maxx=g.worldCOMx+g.radius,g.aabb.maxy=g.worldCOMy+g.radius}else{let g=u.polygon,k=g.lverts.next,N=g.gverts.next,E=k;k=k.next,N.x=g.body.posx+(g.body.axisy*E.x-g.body.axisx*E.y),N.y=g.body.posy+(E.x*g.body.axisx+E.y*g.body.axisy),g.aabb.minx=N.x,g.aabb.miny=N.y,g.aabb.maxx=N.x,g.aabb.maxy=N.y;let M=g.gverts.next.next;for(;M!=null;){let C=M,L=k;k=k.next,C.x=g.body.posx+(g.body.axisy*L.x-g.body.axisx*L.y),C.y=g.body.posy+(L.x*g.body.axisx+L.y*g.body.axisy),C.x<g.aabb.minx&&(g.aabb.minx=C.x),C.x>g.aabb.maxx&&(g.aabb.maxx=C.x),C.y<g.aabb.miny&&(g.aabb.miny=C.y),C.y>g.aabb.maxy&&(g.aabb.maxy=C.y),M=M.next}}x<h.minx?h.minx=x:x=h.minx,b<h.miny?h.miny=b:b=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy}this.bphase.sync(u),c=c.next}if(s.sweepFrozen=!1,s.type==2&&s.bulletEnabled){let u=A._nape.Config.bulletCCDLinearThreshold*s.sweepRadius,h=A._nape.Config.bulletCCDAngularThreshold;((s.velx*s.velx+s.vely*s.vely)*e*e>u*u||s.angvel*s.angvel*e*e>h*h)&&(s.bullet=!0)}}else s.sweepFrozen=!0,s.bullet=!1}n=n.next}let l=this.kinematics.head;for(;l!=null;){let s=l.elt;s.pre_posx=s.posx,s.pre_posy=s.posy,s.pre_rot=s.rot,s.sweepTime=0,s.sweep_angvel=s.angvel%t;let i=e-s.sweepTime;if(i!=0){s.sweepTime=e;let o=i;if(s.posx+=s.velx*o,s.posy+=s.vely*o,s.angvel!=0){let r=s.sweep_angvel*i;if(s.rot+=r,r*r>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,u=(p*s.axisx+r*s.axisy)*c;s.axisy=(p*s.axisy-r*s.axisx)*c,s.axisx=u}}}if(s.disableCCD)s.sweepFrozen=!0,s.bullet=!1;else{let o=A._nape.Config.staticCCDLinearThreshold*s.sweepRadius,r=A._nape.Config.staticCCDAngularThreshold;if((s.velx*s.velx+s.vely*s.vely)*e*e>o*o||s.angvel*s.angvel*e*e>r*r||s.type==3){let a=s.sweep_angvel;a<0&&(a=-a);let p=1/a,c=s.shapes.head;for(;c!=null;){let u=c.elt,h=u.aabb,x=h.minx,b=h.miny,_=h.maxx,d=h.maxy,f=a*e*u.sweepCoef*.008333333333333333|0;f>8&&(f=8);let m=a*e/f,z=e-s.sweepTime;if(z!=0){s.sweepTime=e;let w=z;if(s.posx+=s.velx*w,s.posy+=s.vely*w,s.angvel!=0){let v=s.sweep_angvel*z;if(s.rot+=v,v*v>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let P=v*v,g=1-.5*P,k=1-P*P/8,N=(g*s.axisx+v*s.axisy)*k;s.axisy=(g*s.axisy-v*s.axisx)*k,s.axisx=N}}}if(u.type==0){let w=u.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else{let w=u.polygon,v=w.lverts.next,P=w.gverts.next,g=v;v=v.next,P.x=w.body.posx+(w.body.axisy*g.x-w.body.axisx*g.y),P.y=w.body.posy+(g.x*w.body.axisx+g.y*w.body.axisy),w.aabb.minx=P.x,w.aabb.miny=P.y,w.aabb.maxx=P.x,w.aabb.maxy=P.y;let k=w.gverts.next.next;for(;k!=null;){let N=k,E=v;v=v.next,N.x=w.body.posx+(w.body.axisy*E.x-w.body.axisx*E.y),N.y=w.body.posy+(E.x*w.body.axisx+E.y*w.body.axisy),N.x<w.aabb.minx&&(w.aabb.minx=N.x),N.x>w.aabb.maxx&&(w.aabb.maxx=N.x),N.y<w.aabb.miny&&(w.aabb.miny=N.y),N.y>w.aabb.maxy&&(w.aabb.maxy=N.y),k=k.next}}x<h.minx?h.minx=x:x=h.minx,b<h.miny?h.miny=b:b=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy;let Z=1,y=f;for(;Z<y;){let w=Z++,v=m*w*p,P=v-s.sweepTime;if(P!=0){s.sweepTime=v;let g=P;if(s.posx+=s.velx*g,s.posy+=s.vely*g,s.angvel!=0){let k=s.sweep_angvel*P;if(s.rot+=k,k*k>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else{let N=k*k,E=1-.5*N,M=1-N*N/8,C=(E*s.axisx+k*s.axisy)*M;s.axisy=(E*s.axisy-k*s.axisx)*M,s.axisx=C}}}if(u.type==0){let g=u.circle;g.worldCOMx=g.body.posx+(g.body.axisy*g.localCOMx-g.body.axisx*g.localCOMy),g.worldCOMy=g.body.posy+(g.localCOMx*g.body.axisx+g.localCOMy*g.body.axisy),g.aabb.minx=g.worldCOMx-g.radius,g.aabb.miny=g.worldCOMy-g.radius,g.aabb.maxx=g.worldCOMx+g.radius,g.aabb.maxy=g.worldCOMy+g.radius}else{let g=u.polygon,k=g.lverts.next,N=g.gverts.next,E=k;k=k.next,N.x=g.body.posx+(g.body.axisy*E.x-g.body.axisx*E.y),N.y=g.body.posy+(E.x*g.body.axisx+E.y*g.body.axisy),g.aabb.minx=N.x,g.aabb.miny=N.y,g.aabb.maxx=N.x,g.aabb.maxy=N.y;let M=g.gverts.next.next;for(;M!=null;){let C=M,L=k;k=k.next,C.x=g.body.posx+(g.body.axisy*L.x-g.body.axisx*L.y),C.y=g.body.posy+(L.x*g.body.axisx+L.y*g.body.axisy),C.x<g.aabb.minx&&(g.aabb.minx=C.x),C.x>g.aabb.maxx&&(g.aabb.maxx=C.x),C.y<g.aabb.miny&&(g.aabb.miny=C.y),C.y>g.aabb.maxy&&(g.aabb.maxy=C.y),M=M.next}}x<h.minx?h.minx=x:x=h.minx,b<h.miny?h.miny=b:b=h.miny,_>h.maxx?h.maxx=_:_=h.maxx,d>h.maxy?h.maxy=d:d=h.maxy}this.bphase.sync(u),c=c.next}if(s.sweepFrozen=!1,s.type==2&&s.bulletEnabled){let u=A._nape.Config.bulletCCDLinearThreshold*s.sweepRadius,h=A._nape.Config.bulletCCDAngularThreshold;((s.velx*s.velx+s.vely*s.vely)*e*e>u*u||s.angvel*s.angvel*e*e>h*h)&&(s.bullet=!0)}}else s.sweepFrozen=!0,s.bullet=!1}l=l.next}}presteparb(e,t,n){n==null&&(n=!1);let l=this;if(!e.cleared&&e.b1.component.sleeping&&e.b2.component.sleeping)return e.sleep_stamp=this.stamp,e.sleeping=!0,!0;if(!e.cleared||e.present!=0||e.intchange){let i=!n&&e.up_stamp==this.stamp-1&&!e.cleared&&!e.intchange,o=e.fresh&&!e.cleared&&!e.intchange;if(i&&(e.endGenerated=this.stamp),o||i||e.cleared||e.intchange){let r=e.ws1,a=e.ws2,p=this.mrca1;for(;p.head!=null;){let b=p.head;p.head=b.next;let _=b;_.elt=null,_.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_,p.head==null&&(p.pushmod=!0),p.modified=!0,p.length--}p.pushmod=!0;let c=this.mrca2;for(;c.head!=null;){let b=c.head;c.head=b.next;let _=b;_.elt=null,_.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_,c.head==null&&(c.pushmod=!0),c.modified=!0,c.length--}if(c.pushmod=!0,r.cbSet!=null){let b=this.mrca1,_;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new A._zpp.util.ZNPNode_ZPP_Interactor:(_=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=r;let d=_;d.next=b.head,b.head=d,b.modified=!0,b.length++}if(r.body.cbSet!=null){let b=this.mrca1,_=r.body,d;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new A._zpp.util.ZNPNode_ZPP_Interactor:(d=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=_;let f=d;f.next=b.head,b.head=f,b.modified=!0,b.length++}if(a.cbSet!=null){let b=this.mrca2,_;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new A._zpp.util.ZNPNode_ZPP_Interactor:(_=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=a;let d=_;d.next=b.head,b.head=d,b.modified=!0,b.length++}if(a.body.cbSet!=null){let b=this.mrca2,_=a.body,d;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new A._zpp.util.ZNPNode_ZPP_Interactor:(d=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=_;let f=d;f.next=b.head,b.head=f,b.modified=!0,b.length++}let u=r.body.compound,h=a.body.compound;for(;u!=h;){let b=u==null?0:u.depth,_=h==null?0:h.depth;if(b<_){if(h.cbSet!=null){let d=this.mrca2,f;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?f=new A._zpp.util.ZNPNode_ZPP_Interactor:(f=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=f.next,f.next=null),f.elt=h;let m=f;m.next=d.head,d.head=m,d.modified=!0,d.length++}h=h.compound}else{if(u.cbSet!=null){let d=this.mrca1,f;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?f=new A._zpp.util.ZNPNode_ZPP_Interactor:(f=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=f.next,f.next=null),f.elt=u;let m=f;m.next=d.head,d.head=m,d.modified=!0,d.length++}u=u.compound}}let x=this.mrca1.head;for(;x!=null;){let b=x.elt,_=this.mrca2.head;for(;_!=null;){let d=_.elt,f=b.cbSet,m=d.cbSet,z=f.manager,Z=null,w=(f.cbpairs.length<m.cbpairs.length?f.cbpairs:m.cbpairs).head;for(;w!=null;){let P=w.elt;if(P.a==f&&P.b==m||P.a==m&&P.b==f){Z=P;break}w=w.next}if(Z==null){let P;Ne.zpp_pool==null?P=new Ne:(P=Ne.zpp_pool,Ne.zpp_pool=P.next,P.next=null),P.zip_listeners=!0,Pt.setlt(f,m)?(P.a=f,P.b=m):(P.a=m,P.b=f),Z=P,f.cbpairs.add(Z),m!=f&&m.cbpairs.add(Z)}if(Z.zip_listeners&&(Z.zip_listeners=!1,Z.__validate()),Z.listeners.head==null){_=_.next;continue}let v=A._zpp.phys.ZPP_Interactor.get(b,d);if(o||e.intchange){v==null&&(v=Ht.get(b,d),this.add_callbackset(v));let P=f.manager,g=null,N=(f.cbpairs.length<m.cbpairs.length?f.cbpairs:m.cbpairs).head;for(;N!=null;){let O=N.elt;if(O.a==f&&O.b==m||O.a==m&&O.b==f){g=O;break}N=N.next}if(g==null){let O;Ne.zpp_pool==null?O=new Ne:(O=Ne.zpp_pool,Ne.zpp_pool=O.next,O.next=null),O.zip_listeners=!0,Pt.setlt(f,m)?(O.a=f,O.b=m):(O.a=m,O.b=f),g=O,f.cbpairs.add(g),m!=f&&m.cbpairs.add(g)}g.zip_listeners&&(g.zip_listeners=!1,g.__validate());let E=g.listeners.head;for(;E!=null;){let O=E.elt;if(O.event==0&&(O.itype&e.type)!=0&&v.empty_arb(O.itype)){let I=l.push_callback(O);I.event=0;let T=v.int1,W=v.int2,R,G=O.options1,j=T.cbTypes;if(G.nonemptyintersection(j,G.includes)&&!G.nonemptyintersection(j,G.excludes)){let S=O.options2,q=W.cbTypes;R=S.nonemptyintersection(q,S.includes)&&!S.nonemptyintersection(q,S.excludes)}else R=!1;R?(I.int1=T,I.int2=W):(I.int1=W,I.int2=T),I.set=v}E=E.next}let M,C;C=!1;let L=v.arbiters.head;for(;L!=null;){if(L.elt==e){C=!0;break}L=L.next}if(C)M=!1;else{let O=v.arbiters,I;A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?I=new A._zpp.util.ZNPNode_ZPP_Arbiter:(I=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=I.next,I.next=null),I.elt=e;let T=I;T.next=O.head,O.head=T,O.modified=!0,O.length++,M=!0}M&&e.present++}else{e.present--,v.remove_arb(e);let P=f.manager,g=null,N=(f.cbpairs.length<m.cbpairs.length?f.cbpairs:m.cbpairs).head;for(;N!=null;){let M=N.elt;if(M.a==f&&M.b==m||M.a==m&&M.b==f){g=M;break}N=N.next}if(g==null){let M;Ne.zpp_pool==null?M=new Ne:(M=Ne.zpp_pool,Ne.zpp_pool=M.next,M.next=null),M.zip_listeners=!0,Pt.setlt(f,m)?(M.a=f,M.b=m):(M.a=m,M.b=f),g=M,f.cbpairs.add(g),m!=f&&m.cbpairs.add(g)}g.zip_listeners&&(g.zip_listeners=!1,g.__validate());let E=g.listeners.head;for(;E!=null;){let M=E.elt;if(M.event==1&&(M.itype&e.type)!=0&&v.empty_arb(M.itype)){let C=l.push_callback(M);C.event=1;let L=v.int1,O=v.int2,I,T=M.options1,W=L.cbTypes;if(T.nonemptyintersection(W,T.includes)&&!T.nonemptyintersection(W,T.excludes)){let R=M.options2,G=O.cbTypes;I=R.nonemptyintersection(G,R.includes)&&!R.nonemptyintersection(G,R.excludes)}else I=!1;I?(C.int1=L,C.int2=O):(C.int1=O,C.int2=L),C.set=v}E=E.next}v.arbiters.head==null&&this.remove_callbackset(v)}_=_.next}x=x.next}}e.fresh=!1,e.intchange=!1}if(e.cleared||e.up_stamp+(e.type==Ve.COL?A._nape.Config.arbiterExpirationDelay:0)<this.stamp){if(e.type==Ve.SENSOR){let i=e.sensorarb;if(!i.cleared){let r=i.b1.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==i){let _,d;a==null?(_=r.head,d=_.next,r.head=d,r.head==null&&(r.pushmod=!0)):(_=a.next,d=_.next,a.next=d,d==null&&(r.pushmod=!0));let f=_;f.elt=null,f.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}let u=i.b2.arbiters,h=null,x=u.head,b=!1;for(;x!=null;){if(x.elt==i){let _,d;h==null?(_=u.head,d=_.next,u.head=d,u.head==null&&(u.pushmod=!0)):(_=h.next,d=_.next,h.next=d,d==null&&(u.pushmod=!0));let f=_;f.elt=null,f.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,u.modified=!0,u.length--,u.pushmod=!0,b=!0;break}h=x,x=x.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let o=i;o.next=Bt.zpp_pool,Bt.zpp_pool=o}else if(e.type==Ve.FLUID){let i=e.fluidarb;if(!i.cleared){let r=i.b1.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==i){let _,d;a==null?(_=r.head,d=_.next,r.head=d,r.head==null&&(r.pushmod=!0)):(_=a.next,d=_.next,a.next=d,d==null&&(r.pushmod=!0));let f=_;f.elt=null,f.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}let u=i.b2.arbiters,h=null,x=u.head,b=!1;for(;x!=null;){if(x.elt==i){let _,d;h==null?(_=u.head,d=_.next,u.head=d,u.head==null&&(u.pushmod=!0)):(_=h.next,d=_.next,h.next=d,d==null&&(u.pushmod=!0));let f=_;f.elt=null,f.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,u.modified=!0,u.length--,u.pushmod=!0,b=!0;break}h=x,x=x.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let o=i;o.next=Mt.zpp_pool,Mt.zpp_pool=o,i.pre_dt=-1}else{let i=e.colarb;if(!i.cleared){let r=i.b1.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==i){let _,d;a==null?(_=r.head,d=_.next,r.head=d,r.head==null&&(r.pushmod=!0)):(_=a.next,d=_.next,a.next=d,d==null&&(r.pushmod=!0));let f=_;f.elt=null,f.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}let u=i.b2.arbiters,h=null,x=u.head,b=!1;for(;x!=null;){if(x.elt==i){let _,d;h==null?(_=u.head,d=_.next,u.head=d,u.head==null&&(u.pushmod=!0)):(_=h.next,d=_.next,h.next=d,d==null&&(u.pushmod=!0));let f=_;f.elt=null,f.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f,u.modified=!0,u.length--,u.pushmod=!0,b=!0;break}h=x,x=x.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}for(i.b1=i.b2=null,i.active=!1,i.intchange=!1;i.contacts.next!=null;){let r=i.contacts,a=r.next;r.pop();let p=a;p.arbiter=null,p.next=ve.zpp_pool,ve.zpp_pool=p;let c=i.innards,u=c.next;c.next=u.next,u._inuse=!1,c.next==null&&(c.pushmod=!0),c.modified=!0,c.length--}let o=i;o.userdef_dyn_fric=!1,o.userdef_stat_fric=!1,o.userdef_restitution=!1,o.userdef_rfric=!1,o.__ref_edge1=o.__ref_edge2=null,o.next=dt.zpp_pool,dt.zpp_pool=o,i.pre_dt=-1}return!0}let s=e.active;if(e.active=e.presentable=e.up_stamp==this.stamp,(e.immState&1)!=0){if(e.active&&e.type!=Ve.SENSOR)if(e.colarb!=null){let i=e.colarb;i.invalidated&&(i.invalidated=!1,i.userdef_restitution||(i.s1.material.elasticity<=-1/0||i.s2.material.elasticity<=-1/0?i.restitution=0:i.s1.material.elasticity>=1/0||i.s2.material.elasticity>=1/0?i.restitution=1:i.restitution=(i.s1.material.elasticity+i.s2.material.elasticity)/2,i.restitution<0&&(i.restitution=0),i.restitution>1&&(i.restitution=1)),i.userdef_dyn_fric||(i.dyn_fric=Math.sqrt(i.s1.material.dynamicFriction*i.s2.material.dynamicFriction)),i.userdef_stat_fric||(i.stat_fric=Math.sqrt(i.s1.material.staticFriction*i.s2.material.staticFriction)),i.userdef_rfric||(i.rfric=Math.sqrt(i.s1.material.rollingFriction*i.s2.material.rollingFriction))),i.pre_dt==-1&&(i.pre_dt=t);let o=t/i.pre_dt;i.pre_dt=t;let r=i.b1.smass+i.b2.smass;i.hc2=!1;let a=!0,c=i.b1.type!=2||i.b2.type!=2?i.continuous?A._nape.Config.contactContinuousStaticBiasCoef:A._nape.Config.contactStaticBiasCoef:i.continuous?A._nape.Config.contactContinuousBiasCoef:A._nape.Config.contactBiasCoef;i.biasCoef=c,i.continuous=!1;let u=null,h=null,x=i.innards.next,b=i.contacts.next;for(;b!=null;){let d=b;if(d.stamp+A._nape.Config.arbiterExpirationDelay<i.stamp){let z=i.contacts,Z,y;u==null?(Z=z.next,y=Z.next,z.next=y,z.next==null&&(z.pushmod=!0)):(Z=u.next,y=Z.next,u.next=y,y==null&&(z.pushmod=!0)),Z._inuse=!1,z.modified=!0,z.length--,z.pushmod=!0,b=y;let w=i.innards,v,P;h==null?(v=w.next,P=v.next,w.next=P,w.next==null&&(w.pushmod=!0)):(v=h.next,P=v.next,h.next=P,P==null&&(w.pushmod=!0)),v._inuse=!1,w.modified=!0,w.length--,w.pushmod=!0,x=P;let g=d;g.arbiter=null,g.next=ve.zpp_pool,ve.zpp_pool=g;continue}let f=d.inner,m=d.active;if(d.active=d.stamp==i.stamp,d.active){a?(a=!1,i.c1=f,i.oc1=d):(i.hc2=!0,i.c2=f,i.oc2=d),f.r2x=d.px-i.b2.posx,f.r2y=d.py-i.b2.posy,f.r1x=d.px-i.b1.posx,f.r1y=d.py-i.b1.posy;let z=f.r2x*i.nx+f.r2y*i.ny,Z=r+i.b2.sinertia*(z*z),y=f.r1x*i.nx+f.r1y*i.ny;Z+=i.b1.sinertia*(y*y),f.tMass=Z<A._nape.Config.epsilon*A._nape.Config.epsilon?0:1/Z;let w=i.ny*f.r2x-i.nx*f.r2y,v=r+i.b2.sinertia*(w*w),P=i.ny*f.r1x-i.nx*f.r1y;v+=i.b1.sinertia*(P*P),f.nMass=v<A._nape.Config.epsilon*A._nape.Config.epsilon?0:1/v;let g=0,k=0,N=i.b2.angvel+i.b2.kinangvel;g=i.b2.velx+i.b2.kinvelx-f.r2y*N,k=i.b2.vely+i.b2.kinvely+f.r2x*N,N=i.b1.angvel+i.b1.kinangvel,g-=i.b1.velx+i.b1.kinvelx-f.r1y*N,k-=i.b1.vely+i.b1.kinvely+f.r1x*N;let E=i.nx*g+i.ny*k;d.elasticity=i.restitution,f.bounce=E*d.elasticity,f.bounce>-A._nape.Config.elasticThreshold&&(f.bounce=0),E=k*i.nx-g*i.ny;let M=A._nape.Config.staticFrictionThreshold;E*E>M*M?f.friction=i.dyn_fric:f.friction=i.stat_fric,f.jnAcc*=o,f.jtAcc*=o}m!=d.active&&(i.contacts.modified=!0),u=b,h=x,x=x.next,b=b.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let d=i.c1;i.c1=i.c2,i.c2=d;let f=i.oc1;i.oc1=i.oc2,i.oc2=f,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(a=!0)}else i.hpc2=!1;if(i.jrAcc*=o,a||(i.rn1a=i.ny*i.c1.r1x-i.nx*i.c1.r1y,i.rt1a=i.c1.r1x*i.nx+i.c1.r1y*i.ny,i.rn1b=i.ny*i.c1.r2x-i.nx*i.c1.r2y,i.rt1b=i.c1.r2x*i.nx+i.c1.r2y*i.ny,i.k1x=i.b2.kinvelx-i.c1.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c1.r1y*i.b1.kinangvel),i.k1y=i.b2.kinvely+i.c1.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c1.r1x*i.b1.kinangvel)),i.hc2)if(i.rn2a=i.ny*i.c2.r1x-i.nx*i.c2.r1y,i.rt2a=i.c2.r1x*i.nx+i.c2.r1y*i.ny,i.rn2b=i.ny*i.c2.r2x-i.nx*i.c2.r2y,i.rt2b=i.c2.r2x*i.nx+i.c2.r2y*i.ny,i.k2x=i.b2.kinvelx-i.c2.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c2.r1y*i.b1.kinangvel),i.k2y=i.b2.kinvely+i.c2.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c2.r1x*i.b1.kinangvel),i.kMassa=r+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=r+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=r+i.b1.sinertia*i.rn2a*i.rn2a+i.b2.sinertia*i.rn2b*i.rn2b,i.kMassa*i.kMassa+2*i.kMassb*i.kMassb+i.kMassc*i.kMassc<A._nape.Config.illConditionedThreshold*(i.kMassa*i.kMassc-i.kMassb*i.kMassb)){i.Ka=i.kMassa,i.Kb=i.kMassb,i.Kc=i.kMassc;let f=i.kMassa*i.kMassc-i.kMassb*i.kMassb;if(f!=f)i.kMassa=i.kMassb=i.kMassc=0;else if(f==0){let m=0;i.kMassa!=0?i.kMassa=1/i.kMassa:(i.kMassa=0,m|=1),i.kMassc!=0?i.kMassc=1/i.kMassc:(i.kMassc=0,m|=2),i.kMassb=0}else{f=1/f;let m=i.kMassc*f;i.kMassc=i.kMassa*f,i.kMassa=m,i.kMassb*=-f}}else{if(i.hc2=!1,i.oc2.dist<i.oc1.dist){let f=i.c1;i.c1=i.c2,i.c2=f}i.oc2.active=!1,i.contacts.modified=!0}i.surfacex=i.b2.svelx,i.surfacey=i.b2.svely;let _=1;i.surfacex+=i.b1.svelx*_,i.surfacey+=i.b1.svely*_,i.surfacex=-i.surfacex,i.surfacey=-i.surfacey,i.rMass=i.b1.sinertia+i.b2.sinertia,i.rMass!=0&&(i.rMass=1/i.rMass),a&&(e.active=!1)}else{let i=e.fluidarb;i.pre_dt==-1&&(i.pre_dt=t);let o=t/i.pre_dt;i.pre_dt=t,i.r1x=i.centroidx-i.b1.posx,i.r1y=i.centroidy-i.b1.posy,i.r2x=i.centroidx-i.b2.posx,i.r2y=i.centroidy-i.b2.posy;let r=0,a=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(r=i.ws1.fluidProperties.gravityx,a=i.ws1.fluidProperties.gravityy):(r=this.gravityx,a=this.gravityy);let p=0,c=0;i.ws2.fluidEnabled&&i.ws2.fluidProperties.wrap_gravity!=null?(p=i.ws2.fluidProperties.gravityx,c=i.ws2.fluidProperties.gravityy):(p=this.gravityx,c=this.gravityy);let u=0,h=0;if(i.ws1.fluidEnabled&&i.ws2.fluidEnabled){let _=i.overlap*i.ws1.fluidProperties.density,d=i.overlap*i.ws2.fluidProperties.density;if(_>d){let f=_+d;u-=r*f,h-=a*f}else if(_<d){let f=_+d;u+=p*f,h+=c*f}else{let f=0,m=0;f=r+p,m=a+c;let z=.5;if(f*=z,m*=z,i.ws1.worldCOMx*f+i.ws1.worldCOMy*m>i.ws2.worldCOMx*f+i.ws2.worldCOMy*m){let Z=_+d;u-=f*Z,h-=m*Z}else{let Z=_+d;u+=f*Z,h+=m*Z}}}else if(i.ws1.fluidEnabled){let d=i.overlap*i.ws1.fluidProperties.density;u-=r*d,h-=a*d}else if(i.ws2.fluidEnabled){let d=i.overlap*i.ws2.fluidProperties.density;u+=p*d,h+=c*d}let x=t;if(u*=x,h*=x,i.buoyx=u,i.buoyy=h,i.b1.type==2){let _=i.b1.imass;i.b1.velx-=u*_,i.b1.vely-=h*_,i.b1.angvel-=(h*i.r1x-u*i.r1y)*i.b1.iinertia}if(i.b2.type==2){let _=i.b2.imass;i.b2.velx+=u*_,i.b2.vely+=h*_,i.b2.angvel+=(h*i.r2x-u*i.r2y)*i.b2.iinertia}if((!i.ws1.fluidEnabled||i.ws1.fluidProperties.viscosity==0)&&(!i.ws2.fluidEnabled||i.ws2.fluidProperties.viscosity==0))i.nodrag=!0,i.dampx=0,i.dampy=0,i.adamp=0;else{i.nodrag=!1;let _=0;if(i.ws1.fluidEnabled&&(i.ws2.validate_angDrag(),_+=i.ws1.fluidProperties.viscosity*i.ws2.angDrag*i.overlap/i.ws2.area),i.ws2.fluidEnabled&&(i.ws1.validate_angDrag(),_+=i.ws2.fluidProperties.viscosity*i.ws1.angDrag*i.overlap/i.ws1.area),_!=0){let z=i.b1.sinertia+i.b2.sinertia;z!=0?i.wMass=1/z:i.wMass=0,_*=4e-4;let Z=2*Math.PI*_;i.agamma=1/(t*Z*(2+Z*t));let y=1/(1+i.agamma),w=t*Z*Z*i.agamma;i.agamma*=y,i.wMass*=y}else i.wMass=0,i.agamma=0;let d=i.b2.velx+i.b2.kinvelx-i.r2y*(i.b2.angvel+i.b2.kinangvel)-(i.b1.velx+i.b1.kinvelx-i.r1y*(i.b2.angvel+i.b2.kinangvel)),f=i.b2.vely+i.b2.kinvely+i.r2x*(i.b2.angvel+i.b2.kinangvel)-(i.b1.vely+i.b1.kinvely+i.r1x*(i.b1.angvel+i.b1.kinangvel));if(!(d*d+f*f<A._nape.Config.epsilon*A._nape.Config.epsilon)){let z=d*d+f*f,y=1/Math.sqrt(z);d*=y,f*=y,i.nx=d,i.ny=f}let m=0;if(i.ws1.fluidEnabled){let z=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)m-=z*i.ws2.circle.radius*A._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else{let Z=i.ws2.polygon,y=0,w=0,v=Z.edges.head;for(;v!=null;){let P=v.elt;y+=P.length;let g=z*P.length*(P.gnormx*i.nx+P.gnormy*i.ny);g>0&&(g*=-A._nape.Config.fluidVacuumDrag,g=g),w-=g*.5*A._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*A._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else{let Z=i.ws1.polygon,y=0,w=0,v=Z.edges.head;for(;v!=null;){let P=v.elt;y+=P.length;let g=z*P.length*(P.gnormx*i.nx+P.gnormy*i.ny);g>0&&(g*=-A._nape.Config.fluidVacuumDrag,g=g),w-=g*.5*A._nape.Config.fluidLinearDrag,v=v.next}m+=w/y}}if(m!=0){let z=i.b1.smass+i.b2.smass,Z=0,y=0,w=0;if(Z=z,y=0,w=z,i.b1.sinertia!=0){let E=i.r1x*i.b1.sinertia,M=i.r1y*i.b1.sinertia;Z+=M*i.r1y,y+=-M*i.r1x,w+=E*i.r1x}if(i.b2.sinertia!=0){let E=i.r2x*i.b2.sinertia,M=i.r2y*i.b2.sinertia;Z+=M*i.r2y,y+=-M*i.r2x,w+=E*i.r2x}let v=Z*w-y*y;if(v!=v)w=0,y=w,Z=y;else if(v==0){let E=0;Z!=0?Z=1/Z:(Z=0,E|=1),w!=0?w=1/w:(w=0,E|=2),y=0}else{v=1/v;let E=w*v;w=Z*v,Z=E,y*=-v}i.vMassa=Z,i.vMassb=y,i.vMassc=w;let P,g=2*Math.PI*m;i.lgamma=1/(t*g*(2+g*t));let k=1/(1+i.lgamma);P=t*g*g*i.lgamma,i.lgamma*=k;let N=k;i.vMassa*=N,i.vMassb*=N,i.vMassc*=N}else i.vMassa=0,i.vMassb=0,i.vMassc=0,i.lgamma=0}let b=o;i.dampx*=b,i.dampy*=b,i.adamp*=o}}else if(e.colarb!=null){let i=e.colarb,o=!0,r=null,a=null,p=i.innards.next;i.hc2=!1;let c=i.contacts.next;for(;c!=null;){let u=c;if(u.stamp+A._nape.Config.arbiterExpirationDelay<i.stamp){let b=i.contacts,_,d;r==null?(_=b.next,d=_.next,b.next=d,b.next==null&&(b.pushmod=!0)):(_=r.next,d=_.next,r.next=d,d==null&&(b.pushmod=!0)),_._inuse=!1,b.modified=!0,b.length--,b.pushmod=!0,c=d;let f=i.innards,m,z;a==null?(m=f.next,z=m.next,f.next=z,f.next==null&&(f.pushmod=!0)):(m=a.next,z=m.next,a.next=z,z==null&&(f.pushmod=!0)),m._inuse=!1,f.modified=!0,f.length--,f.pushmod=!0,p=z;let Z=u;Z.arbiter=null,Z.next=ve.zpp_pool,ve.zpp_pool=Z;continue}let h=u.inner,x=u.active;u.active=u.stamp==i.stamp,u.active&&(o?(o=!1,i.c1=h,i.oc1=u):(i.hc2=!0,i.c2=h,i.oc2=u)),x!=u.active&&(i.contacts.modified=!0),r=c,a=p,p=p.next,c=c.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let u=i.c1;i.c1=i.c2,i.c2=u;let h=i.oc1;i.oc1=i.oc2,i.oc2=h,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(o=!0)}else i.hpc2=!1;o&&(e.active=!1)}return s!=e.active&&(e.b1.arbiters.modified=!0,e.b2.arbiters.modified=!0,this.c_arbiters_true.modified=this.c_arbiters_false.modified=!0,this.s_arbiters.modified=this.f_arbiters.modified=!0),!1}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let _=n.elt;if(_.preStep(e)){n=this.live_constraints.erase(t),_.broken(),this.constraintCbBreak(_),_.removeOnBreak?(_.component.sleeping=!0,this.midstep=!1,_.compound!=null?_.compound.wrap_constraints.remove(_.outer):this.wrap_constraints.remove(_.outer),this.midstep=!0):_.active=!1,_.clearcache();continue}t=n,n=n.next}let l=null,s=this.c_arbiters_true,i=s.head,o=this.c_arbiters_false!=null;for(o&&i==null&&(o=!1,i=this.c_arbiters_false.head,s=this.c_arbiters_false,l=null);i!=null;){let _=i.elt;if(this.presteparb(_,e)){let d,f;l==null?(d=s.head,f=d.next,s.head=f,s.head==null&&(s.pushmod=!0)):(d=l.next,f=d.next,l.next=f,f==null&&(s.pushmod=!0));let m=d;m.elt=null,m.next=A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=m,s.modified=!0,s.length--,s.pushmod=!0,i=f,o&&i==null&&(o=!1,i=this.c_arbiters_false.head,s=this.c_arbiters_false,l=null);continue}l=i,i=i.next,o&&i==null&&(o=!1,i=this.c_arbiters_false.head,s=this.c_arbiters_false,l=null)}let r=null,a=this.f_arbiters,p=a.head,c=!1;for(c&&p==null&&(c=!1,a=null,r=null);p!=null;){let _=p.elt;if(this.presteparb(_,e)){let d,f;r==null?(d=a.head,f=d.next,a.head=f,a.head==null&&(a.pushmod=!0)):(d=r.next,f=d.next,r.next=f,f==null&&(a.pushmod=!0));let m=d;m.elt=null,m.next=A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=m,a.modified=!0,a.length--,a.pushmod=!0,p=f,c&&p==null&&(c=!1,a=null,r=null);continue}r=p,p=p.next,c&&p==null&&(c=!1,a=null,r=null)}let u=null,h=this.s_arbiters,x=h.head,b=!1;for(b&&x==null&&(b=!1,h=null,u=null);x!=null;){let _=x.elt;if(this.presteparb(_,e)){let d,f;u==null?(d=h.head,f=d.next,h.head=f,h.head==null&&(h.pushmod=!0)):(d=u.next,f=d.next,u.next=f,f==null&&(h.pushmod=!0));let m=d;m.elt=null,m.next=A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=m,h.modified=!0,h.length--,h.pushmod=!0,x=f,b&&x==null&&(b=!1,h=null,u=null);continue}u=x,x=x.next,b&&x==null&&(b=!1,h=null,u=null)}}warmStart(){let e=this.f_arbiters.head;for(;e!=null;){let s=e.elt;if(s.active&&(s.immState&1)!=0){let i=s.b1.imass;s.b1.velx-=s.dampx*i,s.b1.vely-=s.dampy*i;let o=s.b2.imass;s.b2.velx+=s.dampx*o,s.b2.vely+=s.dampy*o,s.b1.angvel-=s.b1.iinertia*(s.dampy*s.r1x-s.dampx*s.r1y),s.b2.angvel+=s.b2.iinertia*(s.dampy*s.r2x-s.dampx*s.r2y),s.b1.angvel-=s.adamp*s.b1.iinertia,s.b2.angvel+=s.adamp*s.b2.iinertia}e=e.next}let t=this.c_arbiters_false.head,n=!0;for(t==null&&(t=this.c_arbiters_true.head,n=!1);t!=null;){let s=t.elt;if(s.active&&(s.immState&1)!=0){let i=s.nx*s.c1.jnAcc-s.ny*s.c1.jtAcc,o=s.ny*s.c1.jnAcc+s.nx*s.c1.jtAcc,r=s.b1.imass;s.b1.velx-=i*r,s.b1.vely-=o*r,s.b1.angvel-=s.b1.iinertia*(o*s.c1.r1x-i*s.c1.r1y);let a=s.b2.imass;if(s.b2.velx+=i*a,s.b2.vely+=o*a,s.b2.angvel+=s.b2.iinertia*(o*s.c1.r2x-i*s.c1.r2y),s.hc2){let p=s.nx*s.c2.jnAcc-s.ny*s.c2.jtAcc,c=s.ny*s.c2.jnAcc+s.nx*s.c2.jtAcc,u=s.b1.imass;s.b1.velx-=p*u,s.b1.vely-=c*u,s.b1.angvel-=s.b1.iinertia*(c*s.c2.r1x-p*s.c2.r1y);let h=s.b2.imass;s.b2.velx+=p*h,s.b2.vely+=c*h,s.b2.angvel+=s.b2.iinertia*(c*s.c2.r2x-p*s.c2.r2y)}s.b2.angvel+=s.jrAcc*s.b2.iinertia,s.b1.angvel-=s.jrAcc*s.b1.iinertia}t=t.next,n&&t==null&&(t=this.c_arbiters_true.head,n=!1)}let l=this.live_constraints.head;for(;l!=null;)l.elt.warmStart(),l=l.next}iterateVel(e){let t=0,n=e;for(;t<n;){let l=t++,s=this.f_arbiters.head;for(;s!=null;){let p=s.elt;if(p.active&&(p.immState&1)!=0&&!p.nodrag){let c=p.b1.angvel+p.b1.kinangvel,u=p.b2.angvel+p.b2.kinangvel,h=p.b1.velx+p.b1.kinvelx-p.r1y*c-(p.b2.velx+p.b2.kinvelx-p.r2y*u),x=p.b1.vely+p.b1.kinvely+p.r1x*c-(p.b2.vely+p.b2.kinvely+p.r2x*u),b=p.vMassa*h+p.vMassb*x;x=p.vMassb*h+p.vMassc*x,h=b;let _=p.lgamma;h-=p.dampx*_,x-=p.dampy*_;let d=1;p.dampx+=h*d,p.dampy+=x*d;let f=p.b1.imass;p.b1.velx-=h*f,p.b1.vely-=x*f;let m=p.b2.imass;p.b2.velx+=h*m,p.b2.vely+=x*m,p.b1.angvel-=p.b1.iinertia*(x*p.r1x-h*p.r1y),p.b2.angvel+=p.b2.iinertia*(x*p.r2x-h*p.r2y);let z=(c-u)*p.wMass-p.adamp*p.agamma;p.adamp+=z,p.b1.angvel-=z*p.b1.iinertia,p.b2.angvel+=z*p.b2.iinertia}s=s.next}let i=null,o=this.live_constraints.head;for(;o!=null;){let p=o.elt;if(p.applyImpulseVel()){o=this.live_constraints.erase(i),p.broken(),this.constraintCbBreak(p),p.removeOnBreak?(p.component.sleeping=!0,this.midstep=!1,p.compound!=null?p.compound.wrap_constraints.remove(p.outer):this.wrap_constraints.remove(p.outer),this.midstep=!0):p.active=!1,p.clearcache();continue}i=o,o=o.next}let r=this.c_arbiters_false.head,a=!0;for(r==null&&(r=this.c_arbiters_true.head,a=!1);r!=null;){let p=r.elt;if(p.active&&(p.immState&1)!=0){let c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),u=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),h=(u*p.nx-c*p.ny+p.surfacex)*p.c1.tMass,x=p.c1.friction*p.c1.jnAcc,b=p.c1.jtAcc,_=b-h;_>x?_=x:_<-x&&(_=-x),h=_-b,p.c1.jtAcc=_;let d=-p.ny*h,f=p.nx*h;if(p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rt1b*h*p.b2.iinertia,p.b1.angvel-=p.rt1a*h*p.b1.iinertia,p.hc2){let m=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),z=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);h=(z*p.nx-m*p.ny+p.surfacex)*p.c2.tMass,x=p.c2.friction*p.c2.jnAcc,b=p.c2.jtAcc,_=b-h,_>x?_=x:_<-x&&(_=-x),h=_-b,p.c2.jtAcc=_,d=-p.ny*h,f=p.nx*h,p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rt2b*h*p.b2.iinertia,p.b1.angvel-=p.rt2a*h*p.b1.iinertia,c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),u=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),m=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),z=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);let Z=p.c1.jnAcc,y=p.c2.jnAcc,w=c*p.nx+u*p.ny+p.surfacey+p.c1.bounce-(p.Ka*Z+p.Kb*y),v=m*p.nx+z*p.ny+p.surfacey+p.c2.bounce-(p.Kb*Z+p.Kc*y),P=-(p.kMassa*w+p.kMassb*v),g=-(p.kMassb*w+p.kMassc*v);P>=0&&g>=0?(w=P-Z,v=g-y,p.c1.jnAcc=P,p.c2.jnAcc=g):(P=-p.c1.nMass*w,P>=0&&p.Kb*P+v>=0?(w=P-Z,v=-y,p.c1.jnAcc=P,p.c2.jnAcc=0):(g=-p.c2.nMass*v,g>=0&&p.Kb*g+w>=0?(w=-Z,v=g-y,p.c1.jnAcc=0,p.c2.jnAcc=g):w>=0&&v>=0?(w=-Z,v=-y,p.c1.jnAcc=p.c2.jnAcc=0):(w=0,v=0))),h=w+v,d=p.nx*h,f=p.ny*h,p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=(p.rn1b*w+p.rn2b*v)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*w+p.rn2a*v)*p.b1.iinertia}else p.radius!=0&&(h=(p.b2.angvel-p.b1.angvel)*p.rMass,x=p.rfric*p.c1.jnAcc,b=p.jrAcc,p.jrAcc-=h,p.jrAcc>x?p.jrAcc=x:p.jrAcc<-x&&(p.jrAcc=-x),h=p.jrAcc-b,p.b2.angvel+=h*p.b2.iinertia,p.b1.angvel-=h*p.b1.iinertia),c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),u=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),h=(p.c1.bounce+(p.nx*c+p.ny*u)+p.surfacey)*p.c1.nMass,b=p.c1.jnAcc,_=b-h,_<0&&(_=0),h=_-b,p.c1.jnAcc=_,d=p.nx*h,f=p.ny*h,p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rn1b*h*p.b2.iinertia,p.b1.angvel-=p.rn1a*h*p.b1.iinertia}r=r.next,a&&r==null&&(r=this.c_arbiters_true.head,a=!1)}}}iteratePos(e){let t=0,n=e;for(;t<n;){let l=t++,s=null,i=this.live_constraints.head;for(;i!=null;){let a=i.elt;if(!a.__velocity&&a.stiff&&a.applyImpulsePos()){i=this.live_constraints.erase(s),a.broken(),this.constraintCbBreak(a),a.removeOnBreak?(a.component.sleeping=!0,this.midstep=!1,a.compound!=null?a.compound.wrap_constraints.remove(a.outer):this.wrap_constraints.remove(a.outer),this.midstep=!0):a.active=!1,a.clearcache();continue}s=i,i=i.next}let o=this.c_arbiters_false.head,r=!0;for(o==null&&(o=this.c_arbiters_true.head,r=!1);o!=null;){let a=o.elt;if(a.active&&(a.immState&1)!=0)if(a.ptype==2){let p=a.c1,c=0,u=0;c=a.b2.axisy*p.lr2x-a.b2.axisx*p.lr2y,u=p.lr2x*a.b2.axisx+p.lr2y*a.b2.axisy;let h=1;c+=a.b2.posx*h,u+=a.b2.posy*h;let x=0,b=0;x=a.b1.axisy*p.lr1x-a.b1.axisx*p.lr1y,b=p.lr1x*a.b1.axisx+p.lr1y*a.b1.axisy;let _=1;x+=a.b1.posx*_,b+=a.b1.posy*_;let d=0,f=0;d=c-x,f=u-b;let m=Math.sqrt(d*d+f*f),z=a.radius-A._nape.Config.collisionSlop,Z=m-z;if(d*a.nx+f*a.ny<0&&(d=-d,f=-f,Z-=a.radius),Z<0)if(m<A._nape.Config.epsilon)a.b1.smass!=0?a.b1.posx+=A._nape.Config.epsilon*10:a.b2.posx+=A._nape.Config.epsilon*10;else{let y=1/m;d*=y,f*=y;let w=.5*(x+c),v=.5*(b+u),P=m-z;x=w-a.b1.posx,b=v-a.b1.posy,c=w-a.b2.posx,u=v-a.b2.posy;let g=f*x-d*b,k=f*c-d*u,N=a.b2.smass+k*k*a.b2.sinertia+a.b1.smass+g*g*a.b1.sinertia;if(N!=0){let E=-a.biasCoef*P/N,M=0,C=0,L=E;M=d*L,C=f*L;let O=a.b1.imass;a.b1.posx-=M*O,a.b1.posy-=C*O;let I=a.b1,T=-g*a.b1.iinertia*E;if(I.rot+=T,T*T>1e-4)I.axisx=Math.sin(I.rot),I.axisy=Math.cos(I.rot);else{let j=T*T,S=1-.5*j,q=1-j*j/8,$=(S*I.axisx+T*I.axisy)*q;I.axisy=(S*I.axisy-T*I.axisx)*q,I.axisx=$}let W=a.b2.imass;a.b2.posx+=M*W,a.b2.posy+=C*W;let R=a.b2,G=k*a.b2.iinertia*E;if(R.rot+=G,G*G>1e-4)R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.rot);else{let j=G*G,S=1-.5*j,q=1-j*j/8,$=(S*R.axisx+G*R.axisy)*q;R.axisy=(S*R.axisy-G*R.axisx)*q,R.axisx=$}}}}else{let p=0,c=0,u,h=0,x=0,b=0,_=0;if(a.ptype==0){p=a.b1.axisy*a.lnormx-a.b1.axisx*a.lnormy,c=a.lnormx*a.b1.axisx+a.lnormy*a.b1.axisy,u=a.lproj+(p*a.b1.posx+c*a.b1.posy),h=a.b2.axisy*a.c1.lr1x-a.b2.axisx*a.c1.lr1y,x=a.c1.lr1x*a.b2.axisx+a.c1.lr1y*a.b2.axisy;let m=1;if(h+=a.b2.posx*m,x+=a.b2.posy*m,a.hpc2){b=a.b2.axisy*a.c2.lr1x-a.b2.axisx*a.c2.lr1y,_=a.c2.lr1x*a.b2.axisx+a.c2.lr1y*a.b2.axisy;let z=1;b+=a.b2.posx*z,_+=a.b2.posy*z}}else{p=a.b2.axisy*a.lnormx-a.b2.axisx*a.lnormy,c=a.lnormx*a.b2.axisx+a.lnormy*a.b2.axisy,u=a.lproj+(p*a.b2.posx+c*a.b2.posy),h=a.b1.axisy*a.c1.lr1x-a.b1.axisx*a.c1.lr1y,x=a.c1.lr1x*a.b1.axisx+a.c1.lr1y*a.b1.axisy;let m=1;if(h+=a.b1.posx*m,x+=a.b1.posy*m,a.hpc2){b=a.b1.axisy*a.c2.lr1x-a.b1.axisx*a.c2.lr1y,_=a.c2.lr1x*a.b1.axisx+a.c2.lr1y*a.b1.axisy;let z=1;b+=a.b1.posx*z,_+=a.b1.posy*z}}let d=h*p+x*c-u-a.radius;d+=A._nape.Config.collisionSlop;let f=0;if(a.hpc2&&(f=b*p+_*c-u-a.radius,f+=A._nape.Config.collisionSlop),d<0||f<0){a.rev&&(p=-p,c=-c);let m=0,z=0;m=h-a.b1.posx,z=x-a.b1.posy;let Z=0,y=0;Z=h-a.b2.posx,y=x-a.b2.posy;let w=0,v=0,P=0,g=0;if(a.hpc2){w=b-a.b1.posx,v=_-a.b1.posy,P=b-a.b2.posx,g=_-a.b2.posy;let k=c*m-p*z,N=c*Z-p*y,E=c*w-p*v,M=c*P-p*g,C=a.b1.smass+a.b2.smass;a.kMassa=C+a.b1.sinertia*k*k+a.b2.sinertia*N*N,a.kMassb=C+a.b1.sinertia*k*E+a.b2.sinertia*N*M,a.kMassc=C+a.b1.sinertia*E*E+a.b2.sinertia*M*M;let L=0,O=0,I=0;L=a.kMassa,O=a.kMassb,I=a.kMassc;let T=d*a.biasCoef,W=f*a.biasCoef;for(;;){let R=0,G=0;R=T,G=W,R=-R,G=-G;let j=a.kMassa*a.kMassc-a.kMassb*a.kMassb;if(j!=j)G=0,R=G;else if(j==0)a.kMassa!=0?R/=a.kMassa:R=0,a.kMassc!=0?G/=a.kMassc:G=0;else{j=1/j;let $=j*(a.kMassc*R-a.kMassb*G);G=j*(a.kMassa*G-a.kMassb*R),R=$}if(R>=0&&G>=0){let $=(R+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let X=a.b1,H=-a.b1.iinertia*(k*R+E*G);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let B=H*H,V=1-.5*B,J=1-B*B/8,Q=(V*X.axisx+H*X.axisy)*J;X.axisy=(V*X.axisy-H*X.axisx)*J,X.axisx=Q}let ee=(R+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let F=a.b2,D=a.b2.iinertia*(N*R+M*G);if(F.rot+=D,D*D>1e-4)F.axisx=Math.sin(F.rot),F.axisy=Math.cos(F.rot);else{let B=D*D,V=1-.5*B,J=1-B*B/8,Q=(V*F.axisx+D*F.axisy)*J;F.axisy=(V*F.axisy-D*F.axisx)*J,F.axisx=Q}break}R=-T/L,G=0;let S=O*R+W;if(R>=0&&S>=0){let $=(R+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let X=a.b1,H=-a.b1.iinertia*(k*R+E*G);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let B=H*H,V=1-.5*B,J=1-B*B/8,Q=(V*X.axisx+H*X.axisy)*J;X.axisy=(V*X.axisy-H*X.axisx)*J,X.axisx=Q}let ee=(R+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let F=a.b2,D=a.b2.iinertia*(N*R+M*G);if(F.rot+=D,D*D>1e-4)F.axisx=Math.sin(F.rot),F.axisy=Math.cos(F.rot);else{let B=D*D,V=1-.5*B,J=1-B*B/8,Q=(V*F.axisx+D*F.axisy)*J;F.axisy=(V*F.axisy-D*F.axisx)*J,F.axisx=Q}break}R=0,G=-W/I;let q=O*G+T;if(G>=0&&q>=0){let $=(R+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let X=a.b1,H=-a.b1.iinertia*(k*R+E*G);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let B=H*H,V=1-.5*B,J=1-B*B/8,Q=(V*X.axisx+H*X.axisy)*J;X.axisy=(V*X.axisy-H*X.axisx)*J,X.axisx=Q}let ee=(R+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let F=a.b2,D=a.b2.iinertia*(N*R+M*G);if(F.rot+=D,D*D>1e-4)F.axisx=Math.sin(F.rot),F.axisy=Math.cos(F.rot);else{let B=D*D,V=1-.5*B,J=1-B*B/8,Q=(V*F.axisx+D*F.axisy)*J;F.axisy=(V*F.axisy-D*F.axisx)*J,F.axisx=Q}break}break}}else{let k=c*m-p*z,N=c*Z-p*y,E=a.b2.smass+N*N*a.b2.sinertia+a.b1.smass+k*k*a.b1.sinertia;if(E!=0){let M=-a.biasCoef*d/E,C=0,L=0,O=M;C=p*O,L=c*O;let I=a.b1.imass;a.b1.posx-=C*I,a.b1.posy-=L*I;let T=a.b1,W=-k*a.b1.iinertia*M;if(T.rot+=W,W*W>1e-4)T.axisx=Math.sin(T.rot),T.axisy=Math.cos(T.rot);else{let S=W*W,q=1-.5*S,$=1-S*S/8,X=(q*T.axisx+W*T.axisy)*$;T.axisy=(q*T.axisy-W*T.axisx)*$,T.axisx=X}let R=a.b2.imass;a.b2.posx+=C*R,a.b2.posy+=L*R;let G=a.b2,j=N*a.b2.iinertia*M;if(G.rot+=j,j*j>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else{let S=j*j,q=1-.5*S,$=1-S*S/8,X=(q*G.axisx+j*G.axisy)*$;G.axisy=(q*G.axisy-j*G.axisx)*$,G.axisx=X}}}}}o=o.next,r&&o==null&&(o=this.c_arbiters_true.head,r=!1)}}}group_ignore(e,t){let n=e;for(;n!=null&&n.group==null;)n.ishape!=null?n=n.ishape.body:n.icompound!=null?n=n.icompound.compound:n=n.ibody.compound;let l=n==null?null:n.group;if(l==null)return!1;{let s=t;for(;s!=null&&s.group==null;)s.ishape!=null?s=s.ishape.body:s.icompound!=null?s=s.icompound.compound:s=s.ibody.compound;let i=s==null?null:s.group;if(i==null)return!1;{let o=!1;for(;l!=null&&i!=null;){if(l==i){o=l.ignore;break}l.depth<i.depth?i=i.group:l=l.group}return o}}}interactionType(e,t,n,l){let s;s=!1;let i=n.constraints.head;for(;i!=null;){let r=i.elt;if(r.ignore&&r.pair_exists(n.id,l.id)){s=!0;break}i=i.next}let o;if(s)o=!1;else{let r=e;for(;r!=null&&r.group==null;)r.ishape!=null?r=r.ishape.body:r.icompound!=null?r=r.icompound.compound:r=r.ibody.compound;let a=r==null?null:r.group,p;if(a==null)p=!1;else{let c=t;for(;c!=null&&c.group==null;)c.ishape!=null?c=c.ishape.body:c.icompound!=null?c=c.icompound.compound:c=c.ibody.compound;let u=c==null?null:c.group;if(u==null)p=!1;else{let h=!1;for(;a!=null&&u!=null;){if(a==u){h=a.ignore;break}a.depth<u.depth?u=u.group:a=a.group}p=h}}o=!p}if(o){let r;if(e.sensorEnabled||t.sensorEnabled){let a=e.filter,p=t.filter;r=(a.sensorMask&p.sensorGroup)!=0&&(p.sensorMask&a.sensorGroup)!=0}else r=!1;if(r)return 2;{let a;if(e.fluidEnabled||t.fluidEnabled){let p=e.filter,c=t.filter;a=(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0}else a=!1;if(a&&!(n.imass==0&&l.imass==0&&n.iinertia==0&&l.iinertia==0))return 0;{let p=e.filter,c=t.filter;return(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!(n.imass==0&&l.imass==0&&n.iinertia==0&&l.iinertia==0)?1:-1}}}else return-1}narrowPhase(e,t,n,l,s){let i=this,o=null,r=e.body,a=t.body,p;p=!1;let c=r.constraints.head;for(;c!=null;){let x=c.elt;if(x.ignore&&x.pair_exists(r.id,a.id)){p=!0;break}c=c.next}let u,h;if(p)h=!1;else{let x=e;for(;x!=null&&x.group==null;)x.ishape!=null?x=x.ishape.body:x.icompound!=null?x=x.icompound.compound:x=x.ibody.compound;let b=x==null?null:x.group,_;if(b==null)_=!1;else{let d=t;for(;d!=null&&d.group==null;)d.ishape!=null?d=d.ishape.body:d.icompound!=null?d=d.icompound.compound:d=d.ibody.compound;let f=d==null?null:d.group;if(f==null)_=!1;else{let m=!1;for(;b!=null&&f!=null;){if(b==f){m=b.ignore;break}b.depth<f.depth?f=f.group:b=b.group}_=m}}h=!_}if(h){let x;if(e.sensorEnabled||t.sensorEnabled){let b=e.filter,_=t.filter;x=(b.sensorMask&_.sensorGroup)!=0&&(_.sensorMask&b.sensorGroup)!=0}else x=!1;if(x)u=2;else{let b;if(e.fluidEnabled||t.fluidEnabled){let _=e.filter,d=t.filter;b=(_.fluidMask&d.fluidGroup)!=0&&(d.fluidMask&_.fluidGroup)!=0}else b=!1;if(b&&!(r.imass==0&&a.imass==0&&r.iinertia==0&&a.iinertia==0))u=0;else{let _=e.filter,d=t.filter;u=(_.collisionMask&d.collisionGroup)!=0&&(d.collisionMask&_.collisionGroup)!=0&&!(r.imass==0&&a.imass==0&&r.iinertia==0&&a.iinertia==0)?1:-1}}}else u=-1;if(u!=-1){let x,b;e.type>t.type?(x=t,b=e):e.type==t.type?e.id<t.id?(x=e,b=t):(b=e,x=t):(x=e,b=t);let _=x==t;if(u==0){let d;if(l==null){let y=null,v=(r.arbiters.length<a.arbiters.length?r:a).arbiters.head;for(;v!=null;){let P=v.elt;if(P.id==x.id&&P.di==b.id){y=P;break}v=v.next}d=y}else d=l;let f=d==null,m,z=!1;if(f)Mt.zpp_pool==null?m=new Mt:(m=Mt.zpp_pool,Mt.zpp_pool=m.next,m.next=null);else if(d.fluidarb==null){d.cleared=!0;{let w=d.b1.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let k,N;v==null?(k=w.head,N=k.next,w.head=N,w.head==null&&(w.pushmod=!0)):(k=v.next,N=k.next,v.next=N,N==null&&(w.pushmod=!0));let E=k;E.elt=null,E.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}{let w=d.b2.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let k,N;v==null?(k=w.head,N=k.next,w.head=N,w.head==null&&(w.pushmod=!0)):(k=v.next,N=k.next,v.next=N,N==null&&(w.pushmod=!0));let E=k;E.elt=null,E.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Mt.zpp_pool==null?m=new Mt:(m=Mt.zpp_pool,Mt.zpp_pool=m.next,m.next=null),m.intchange=!0,f=!0,z=!0}else m=d.fluidarb;let Z=4;if(f||m.stamp!=this.stamp||s)if(m.stamp=this.stamp,Ee.flowCollide(x,b,m)){if(f){let y=b.id;m.b1=e.body,m.ws1=e,m.b2=t.body,m.ws2=t,m.id=x.id,m.di=y;let w=m.b1.arbiters,v;A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?v=new A._zpp.util.ZNPNode_ZPP_Arbiter:(v=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=v.next,v.next=null),v.elt=m;let P=v;P.next=w.head,w.head=P,w.modified=!0,w.length++;let g=m.b2.arbiters,k;A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?k=new A._zpp.util.ZNPNode_ZPP_Arbiter:(k=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k.next,k.next=null),k.elt=m;let N=k;N.next=g.head,g.head=N,g.modified=!0,g.length++,m.active=!0,m.present=0,m.cleared=!1,m.sleeping=!1,m.fresh=!1,m.presentable=!1,m.nx=0,m.ny=1,m.dampx=0,m.dampy=0,m.adamp=0;let E=this.f_arbiters,M;A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?M=new A._zpp.util.ZNPNode_ZPP_FluidArbiter:(M=A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=M.next,M.next=null),M.elt=m;let C=M;C.next=E.head,E.head=C,E.modified=!0,E.length++,m.fresh=!z}else m.fresh=m.up_stamp<this.stamp-1||m.endGenerated==this.stamp&&s;if(m.up_stamp=m.stamp,m.fresh||(m.immState&4)==0){m.immState=1;let y=!1,w=m.ws1.id>m.ws2.id?m.ws2:m.ws1,v=m.ws1.id>m.ws2.id?m.ws1:m.ws2,P=this.mrca1;for(;P.head!=null;){let M=P.head;P.head=M.next;let C=M;C.elt=null,C.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}P.pushmod=!0;let g=this.mrca2;for(;g.head!=null;){let M=g.head;g.head=M.next;let C=M;C.elt=null,C.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}if(g.pushmod=!0,w.cbSet!=null){let M=this.mrca1,C;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new A._zpp.util.ZNPNode_ZPP_Interactor:(C=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=w;let L=C;L.next=M.head,M.head=L,M.modified=!0,M.length++}if(w.body.cbSet!=null){let M=this.mrca1,C=w.body,L;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?L=new A._zpp.util.ZNPNode_ZPP_Interactor:(L=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=L.next,L.next=null),L.elt=C;let O=L;O.next=M.head,M.head=O,M.modified=!0,M.length++}if(v.cbSet!=null){let M=this.mrca2,C;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new A._zpp.util.ZNPNode_ZPP_Interactor:(C=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=v;let L=C;L.next=M.head,M.head=L,M.modified=!0,M.length++}if(v.body.cbSet!=null){let M=this.mrca2,C=v.body,L;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?L=new A._zpp.util.ZNPNode_ZPP_Interactor:(L=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=L.next,L.next=null),L.elt=C;let O=L;O.next=M.head,M.head=O,M.modified=!0,M.length++}let k=w.body.compound,N=v.body.compound;for(;k!=N;){let M=k==null?0:k.depth,C=N==null?0:N.depth;if(M<C){if(N.cbSet!=null){let L=this.mrca2,O;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new A._zpp.util.ZNPNode_ZPP_Interactor:(O=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=N;let I=O;I.next=L.head,L.head=I,L.modified=!0,L.length++}N=N.compound}else{if(k.cbSet!=null){let L=this.mrca1,O;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new A._zpp.util.ZNPNode_ZPP_Interactor:(O=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=k;let I=O;I.next=L.head,L.head=I,L.modified=!0,L.length++}k=k.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,C=this.mrca2.head;for(;C!=null;){let L=C.elt,O=M.cbSet,I=L.cbSet,T=O.manager,W=null,G=(O.cbpairs.length<I.cbpairs.length?O.cbpairs:I.cbpairs).head;for(;G!=null;){let B=G.elt;if(B.a==O&&B.b==I||B.a==I&&B.b==O){W=B;break}G=G.next}if(W==null){let B;Ne.zpp_pool==null?B=new Ne:(B=Ne.zpp_pool,Ne.zpp_pool=B.next,B.next=null),B.zip_listeners=!0,Pt.setlt(O,I)?(B.a=O,B.b=I):(B.a=I,B.b=O),W=B,O.cbpairs.add(W),I!=O&&I.cbpairs.add(W)}if(W.zip_listeners&&(W.zip_listeners=!1,W.__validate()),W.listeners.head==null){C=C.next;continue}let j=null,S=null,q=this.prelisteners;for(;q.head!=null;){let B=q.head;q.head=B.next;let V=B;V.elt=null,V.next=A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=V,q.head==null&&(q.pushmod=!0),q.modified=!0,q.length--}q.pushmod=!0;let $=null,X=O.manager,H=null,F=(O.cbpairs.length<I.cbpairs.length?O.cbpairs:I.cbpairs).head;for(;F!=null;){let B=F.elt;if(B.a==O&&B.b==I||B.a==I&&B.b==O){H=B;break}F=F.next}if(H==null){let B;Ne.zpp_pool==null?B=new Ne:(B=Ne.zpp_pool,Ne.zpp_pool=B.next,B.next=null),B.zip_listeners=!0,Pt.setlt(O,I)?(B.a=O,B.b=I):(B.a=I,B.b=O),H=B,O.cbpairs.add(H),I!=O&&I.cbpairs.add(H)}H.zip_listeners&&(H.zip_listeners=!1,H.__validate());let D=H.listeners.head;for(;D!=null;){let B=D.elt;if(B.event==5&&(B.itype&Z)!=0){let V=i.prelisteners,J;A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?J=new A._zpp.util.ZNPNode_ZPP_InteractionListener:(J=A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=J.next,J.next=null),J.elt=B;let Q=J;$==null?(Q.next=V.head,V.head=Q):(Q.next=$.next,$.next=Q),V.pushmod=V.modified=!0,V.length++,$=Q,y=y||!B.pure}D=D.next}if(this.prelisteners.head==null){C=C.next;continue}if(j=A._zpp.phys.ZPP_Interactor.get(M,L),j==null&&(S=Ht.get(M,L),this.add_callbackset(S)),j==null||(j.FLUIDstamp!=this.stamp||s)&&(j.FLUIDstate&4)==0){if(S!=null&&(j=S),j!=null){let Q=this.prelisteners.head;for(;Q!=null;)Q.elt.itype==7?(j.COLLISIONstamp=this.stamp,j.SENSORstamp=this.stamp,j.FLUIDstamp=this.stamp):j.FLUIDstamp=this.stamp,Q=Q.next}m.mutable=!0,m.wrap_position!=null&&(m.wrap_position.zpp_inner._immutable=!1);let B=m.active;m.active=!0;let V=!1;this.precb.zpp_inner.pre_arbiter=m,this.precb.zpp_inner.set=j;let J=this.prelisteners.head;for(;J!=null;){let Q=J.elt;this.precb.zpp_inner.listener=Q;let K=this.precb.zpp_inner,ne=j.int1,re=j.int2,se,ie=Q.options1,oe=ne.cbTypes;if(ie.nonemptyintersection(oe,ie.includes)&&!ie.nonemptyintersection(oe,ie.excludes)){let pe=Q.options2,ae=re.cbTypes;se=pe.nonemptyintersection(ae,pe.includes)&&!pe.nonemptyintersection(ae,pe.excludes)}else se=!1;se?(K.int1=ne,K.int2=re):(K.int1=re,K.int2=ne),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let ce=Q.handlerp(this.precb);if(ce!=null){let pe;U.PreFlag_ACCEPT==null&&(U.internal=!0,U.PreFlag_ACCEPT=new A._nape.callbacks.PreFlag,U.internal=!1),ce==U.PreFlag_ACCEPT?pe=5:(U.PreFlag_ACCEPT_ONCE==null&&(U.internal=!0,U.PreFlag_ACCEPT_ONCE=new A._nape.callbacks.PreFlag,U.internal=!1),ce==U.PreFlag_ACCEPT_ONCE?pe=1:(U.PreFlag_IGNORE==null&&(U.internal=!0,U.PreFlag_IGNORE=new A._nape.callbacks.PreFlag,U.internal=!1),pe=ce==U.PreFlag_IGNORE?6:2)),m.immState=pe}J=J.next}if(m.mutable=!1,m.wrap_position!=null&&(m.wrap_position.zpp_inner._immutable=!0),m.active=B,j!=null){let Q=this.prelisteners.head;for(;Q!=null;)Q.elt.itype==7&&(j.COLLISIONstate=m.immState,j.SENSORstate=m.immState),j.FLUIDstate=m.immState,Q=Q.next}}else j==null?(m.immState&4)==0&&(m.immState=1):m.immState=j.FLUIDstate;C=C.next}E=E.next}if(y&&(m.immState&4)==0){if(m.b1.type==2){let M=m.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}if(m.b1.type==2){let M=m.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}}}if((m.immState&1)!=0){if(m.b1.type==2&&m.b1.component.sleeping){let y=m.b1;y.world||(y.component.waket=this.stamp+(this.midstep?0:1),y.type==3&&(y.kinematicDelaySleep=!0),y.component.sleeping&&this.really_wake(y,!1))}if(m.b2.type==2&&m.b2.component.sleeping){let y=m.b2;y.world||(y.component.waket=this.stamp+(this.midstep?0:1),y.type==3&&(y.kinematicDelaySleep=!0),y.component.sleeping&&this.really_wake(y,!1))}}if(m.sleeping){m.sleeping=!1;let y=this.f_arbiters,w;A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?w=new A._zpp.util.ZNPNode_ZPP_FluidArbiter:(w=A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=w.next,w.next=null),w.elt=m;let v=w;v.next=y.head,y.head=v,y.modified=!0,y.length++}o=m}else if(f){let y=m;y.next=Mt.zpp_pool,Mt.zpp_pool=y,o=null}else o=m;else o=m}else if(u==1){let d=n?this.c_arbiters_true:this.c_arbiters_false,f;if(l==null){let w=null,P=(r.arbiters.length<a.arbiters.length?r:a).arbiters.head;for(;P!=null;){let g=P.elt;if(g.id==x.id&&g.di==b.id){w=g;break}P=P.next}f=w}else f=l;let m=f==null,z,Z=!1;if(m)dt.zpp_pool==null?z=new dt:(z=dt.zpp_pool,dt.zpp_pool=z.next,z.next=null),z.stat=n;else if(f.colarb==null){f.cleared=!0;{let v=f.b1.arbiters,P=null,g=v.head,k=!1;for(;g!=null;){if(g.elt==f){let N,E;P==null?(N=v.head,E=N.next,v.head=E,v.head==null&&(v.pushmod=!0)):(N=P.next,E=N.next,P.next=E,E==null&&(v.pushmod=!0));let M=N;M.elt=null,M.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,v.modified=!0,v.length--,v.pushmod=!0,k=!0;break}P=g,g=g.next}}{let v=f.b2.arbiters,P=null,g=v.head,k=!1;for(;g!=null;){if(g.elt==f){let N,E;P==null?(N=v.head,E=N.next,v.head=E,v.head==null&&(v.pushmod=!0)):(N=P.next,E=N.next,P.next=E,E==null&&(v.pushmod=!0));let M=N;M.elt=null,M.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,v.modified=!0,v.length--,v.pushmod=!0,k=!0;break}P=g,g=g.next}}f.pair!=null&&(f.pair.arb=null,f.pair=null),f.active=!1,this.f_arbiters.modified=!0,dt.zpp_pool==null?z=new dt:(z=dt.zpp_pool,dt.zpp_pool=z.next,z.next=null),z.intchange=!0,z.stat=n,m=!0,Z=!0}else z=f.colarb,_=x!=z.s1,z.stat!=n&&(z.stat=n,z.sleeping||((n?this.c_arbiters_false:this.c_arbiters_true).remove(z),d.add(z)));let y=1;if(m||z.stamp!=this.stamp||s)if(z.stamp=this.stamp,Ee.contactCollide(x,b,z,_)){if(m){let w=b.id;z.b1=e.body,z.ws1=e,z.b2=t.body,z.ws2=t,z.id=x.id,z.di=w;let v=z.b1.arbiters,P;A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?P=new A._zpp.util.ZNPNode_ZPP_Arbiter:(P=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=P.next,P.next=null),P.elt=z;let g=P;g.next=v.head,v.head=g,v.modified=!0,v.length++;let k=z.b2.arbiters,N;A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?N=new A._zpp.util.ZNPNode_ZPP_Arbiter:(N=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=N.next,N.next=null),N.elt=z;let E=N;E.next=k.head,k.head=E,k.modified=!0,k.length++,z.active=!0,z.present=0,z.cleared=!1,z.sleeping=!1,z.fresh=!1,z.presentable=!1,z.s1=e,z.s2=t,z.userdef_restitution||(z.s1.material.elasticity<=-1/0||z.s2.material.elasticity<=-1/0?z.restitution=0:z.s1.material.elasticity>=1/0||z.s2.material.elasticity>=1/0?z.restitution=1:z.restitution=(z.s1.material.elasticity+z.s2.material.elasticity)/2,z.restitution<0&&(z.restitution=0),z.restitution>1&&(z.restitution=1)),z.userdef_dyn_fric||(z.dyn_fric=Math.sqrt(z.s1.material.dynamicFriction*z.s2.material.dynamicFriction)),z.userdef_stat_fric||(z.stat_fric=Math.sqrt(z.s1.material.staticFriction*z.s2.material.staticFriction)),z.userdef_rfric||(z.rfric=Math.sqrt(z.s1.material.rollingFriction*z.s2.material.rollingFriction));let M;A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?M=new A._zpp.util.ZNPNode_ZPP_ColArbiter:(M=A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=M.next,M.next=null),M.elt=z;let C=M;C.next=d.head,d.head=C,d.modified=!0,d.length++,z.fresh=!Z}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&s;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let w=!1,v=z.ws1.id>z.ws2.id?z.ws2:z.ws1,P=z.ws1.id>z.ws2.id?z.ws1:z.ws2,g=this.mrca1;for(;g.head!=null;){let C=g.head;g.head=C.next;let L=C;L.elt=null,L.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=L,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}g.pushmod=!0;let k=this.mrca2;for(;k.head!=null;){let C=k.head;k.head=C.next;let L=C;L.elt=null,L.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=L,k.head==null&&(k.pushmod=!0),k.modified=!0,k.length--}if(k.pushmod=!0,v.cbSet!=null){let C=this.mrca1,L;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?L=new A._zpp.util.ZNPNode_ZPP_Interactor:(L=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=L.next,L.next=null),L.elt=v;let O=L;O.next=C.head,C.head=O,C.modified=!0,C.length++}if(v.body.cbSet!=null){let C=this.mrca1,L=v.body,O;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new A._zpp.util.ZNPNode_ZPP_Interactor:(O=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=L;let I=O;I.next=C.head,C.head=I,C.modified=!0,C.length++}if(P.cbSet!=null){let C=this.mrca2,L;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?L=new A._zpp.util.ZNPNode_ZPP_Interactor:(L=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=L.next,L.next=null),L.elt=P;let O=L;O.next=C.head,C.head=O,C.modified=!0,C.length++}if(P.body.cbSet!=null){let C=this.mrca2,L=P.body,O;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new A._zpp.util.ZNPNode_ZPP_Interactor:(O=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=L;let I=O;I.next=C.head,C.head=I,C.modified=!0,C.length++}let N=v.body.compound,E=P.body.compound;for(;N!=E;){let C=N==null?0:N.depth,L=E==null?0:E.depth;if(C<L){if(E.cbSet!=null){let O=this.mrca2,I;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?I=new A._zpp.util.ZNPNode_ZPP_Interactor:(I=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=I.next,I.next=null),I.elt=E;let T=I;T.next=O.head,O.head=T,O.modified=!0,O.length++}E=E.compound}else{if(N.cbSet!=null){let O=this.mrca1,I;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?I=new A._zpp.util.ZNPNode_ZPP_Interactor:(I=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=I.next,I.next=null),I.elt=N;let T=I;T.next=O.head,O.head=T,O.modified=!0,O.length++}N=N.compound}}let M=this.mrca1.head;for(;M!=null;){let C=M.elt,L=this.mrca2.head;for(;L!=null;){let O=L.elt,I=C.cbSet,T=O.cbSet,W=I.manager,R=null,j=(I.cbpairs.length<T.cbpairs.length?I.cbpairs:T.cbpairs).head;for(;j!=null;){let V=j.elt;if(V.a==I&&V.b==T||V.a==T&&V.b==I){R=V;break}j=j.next}if(R==null){let V;Ne.zpp_pool==null?V=new Ne:(V=Ne.zpp_pool,Ne.zpp_pool=V.next,V.next=null),V.zip_listeners=!0,Pt.setlt(I,T)?(V.a=I,V.b=T):(V.a=T,V.b=I),R=V,I.cbpairs.add(R),T!=I&&T.cbpairs.add(R)}if(R.zip_listeners&&(R.zip_listeners=!1,R.__validate()),R.listeners.head==null){L=L.next;continue}let S=null,q=null,$=this.prelisteners;for(;$.head!=null;){let V=$.head;$.head=V.next;let J=V;J.elt=null,J.next=A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=J,$.head==null&&($.pushmod=!0),$.modified=!0,$.length--}$.pushmod=!0;let X=null,H=I.manager,ee=null,D=(I.cbpairs.length<T.cbpairs.length?I.cbpairs:T.cbpairs).head;for(;D!=null;){let V=D.elt;if(V.a==I&&V.b==T||V.a==T&&V.b==I){ee=V;break}D=D.next}if(ee==null){let V;Ne.zpp_pool==null?V=new Ne:(V=Ne.zpp_pool,Ne.zpp_pool=V.next,V.next=null),V.zip_listeners=!0,Pt.setlt(I,T)?(V.a=I,V.b=T):(V.a=T,V.b=I),ee=V,I.cbpairs.add(ee),T!=I&&T.cbpairs.add(ee)}ee.zip_listeners&&(ee.zip_listeners=!1,ee.__validate());let B=ee.listeners.head;for(;B!=null;){let V=B.elt;if(V.event==5&&(V.itype&y)!=0){let J=i.prelisteners,Q;A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?Q=new A._zpp.util.ZNPNode_ZPP_InteractionListener:(Q=A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=Q.next,Q.next=null),Q.elt=V;let K=Q;X==null?(K.next=J.head,J.head=K):(K.next=X.next,X.next=K),J.pushmod=J.modified=!0,J.length++,X=K,w=w||!V.pure}B=B.next}if(this.prelisteners.head==null){L=L.next;continue}if(S=A._zpp.phys.ZPP_Interactor.get(C,O),S==null&&(q=Ht.get(C,O),this.add_callbackset(q)),S==null||(S.COLLISIONstamp!=this.stamp||s)&&(S.COLLISIONstate&4)==0){if(q!=null&&(S=q),S!=null){let oe=this.prelisteners.head;for(;oe!=null;)oe.elt.itype==7?(S.COLLISIONstamp=this.stamp,S.SENSORstamp=this.stamp,S.FLUIDstamp=this.stamp):S.COLLISIONstamp=this.stamp,oe=oe.next}z.mutable=!0,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!1),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!1);let V=z.active;z.active=!0;let J=!1,Q=!0,K=null,ne=null,re=z.innards.next;z.hc2=!1;let se=z.contacts.next;for(;se!=null;){let oe=se;if(oe.stamp+A._nape.Config.arbiterExpirationDelay<z.stamp){let ae=z.contacts,_e,te;K==null?(_e=ae.next,te=_e.next,ae.next=te,ae.next==null&&(ae.pushmod=!0)):(_e=K.next,te=_e.next,K.next=te,te==null&&(ae.pushmod=!0)),_e._inuse=!1,ae.modified=!0,ae.length--,ae.pushmod=!0,se=te;let he=z.innards,me,ue;ne==null?(me=he.next,ue=me.next,he.next=ue,he.next==null&&(he.pushmod=!0)):(me=ne.next,ue=me.next,ne.next=ue,ue==null&&(he.pushmod=!0)),me._inuse=!1,he.modified=!0,he.length--,he.pushmod=!0,re=ue;let Pe=oe;Pe.arbiter=null,Pe.next=ve.zpp_pool,ve.zpp_pool=Pe;continue}let ce=oe.inner,pe=oe.active;oe.active=oe.stamp==z.stamp,oe.active&&(Q?(Q=!1,z.c1=ce,z.oc1=oe):(z.hc2=!0,z.c2=ce,z.oc2=oe)),pe!=oe.active&&(z.contacts.modified=!0),K=se,ne=re,re=re.next,se=se.next}if(z.hc2){if(z.hpc2=!0,z.oc1.posOnly){let oe=z.c1;z.c1=z.c2,z.c2=oe;let ce=z.oc1;z.oc1=z.oc2,z.oc2=ce,z.hc2=!1}else z.oc2.posOnly&&(z.hc2=!1);z.oc1.posOnly&&(Q=!0)}else z.hpc2=!1;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=S;let ie=this.prelisteners.head;for(;ie!=null;){let oe=ie.elt;this.precb.zpp_inner.listener=oe;let ce=this.precb.zpp_inner,pe=S.int1,ae=S.int2,_e,te=oe.options1,he=pe.cbTypes;if(te.nonemptyintersection(he,te.includes)&&!te.nonemptyintersection(he,te.excludes)){let ue=oe.options2,Pe=ae.cbTypes;_e=ue.nonemptyintersection(Pe,ue.includes)&&!ue.nonemptyintersection(Pe,ue.excludes)}else _e=!1;_e?(ce.int1=pe,ce.int2=ae):(ce.int1=ae,ce.int2=pe),this.precb.zpp_inner.pre_swapped=C!=this.precb.zpp_inner.int1;let me=oe.handlerp(this.precb);if(me!=null){let ue;U.PreFlag_ACCEPT==null&&(U.internal=!0,U.PreFlag_ACCEPT=new A._nape.callbacks.PreFlag,U.internal=!1),me==U.PreFlag_ACCEPT?ue=5:(U.PreFlag_ACCEPT_ONCE==null&&(U.internal=!0,U.PreFlag_ACCEPT_ONCE=new A._nape.callbacks.PreFlag,U.internal=!1),me==U.PreFlag_ACCEPT_ONCE?ue=1:(U.PreFlag_IGNORE==null&&(U.internal=!0,U.PreFlag_IGNORE=new A._nape.callbacks.PreFlag,U.internal=!1),ue=me==U.PreFlag_IGNORE?6:2)),z.immState=ue}ie=ie.next}if(z.mutable=!1,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!0),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!0),z.active=V,S!=null){let oe=this.prelisteners.head;for(;oe!=null;)oe.elt.itype==7?(S.COLLISIONstate=z.immState,S.SENSORstate=z.immState,S.FLUIDstate=z.immState):S.COLLISIONstate=z.immState,oe=oe.next}}else S==null?(z.immState&4)==0&&(z.immState=1):z.immState=S.COLLISIONstate;L=L.next}M=M.next}if(w&&(z.immState&4)==0){if(z.b1.type==2){let C=z.b1;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}if(z.b1.type==2){let C=z.b2;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}}}if((z.immState&1)!=0){if(z.b1.type==2&&z.b1.component.sleeping){let w=z.b1;w.world||(w.component.waket=this.stamp+(this.midstep?0:1),w.type==3&&(w.kinematicDelaySleep=!0),w.component.sleeping&&this.really_wake(w,!1))}if(z.b2.type==2&&z.b2.component.sleeping){let w=z.b2;w.world||(w.component.waket=this.stamp+(this.midstep?0:1),w.type==3&&(w.kinematicDelaySleep=!0),w.component.sleeping&&this.really_wake(w,!1))}}if(z.sleeping){z.sleeping=!1;let w;A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?w=new A._zpp.util.ZNPNode_ZPP_ColArbiter:(w=A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=w.next,w.next=null),w.elt=z;let v=w;v.next=d.head,d.head=v,d.modified=!0,d.length++}o=z}else if(m){let w=z;w.userdef_dyn_fric=!1,w.userdef_stat_fric=!1,w.userdef_restitution=!1,w.userdef_rfric=!1,w.__ref_edge1=w.__ref_edge2=null,w.next=dt.zpp_pool,dt.zpp_pool=w,o=null}else o=z;else o=z}else{let d;if(l==null){let y=null,v=(r.arbiters.length<a.arbiters.length?r:a).arbiters.head;for(;v!=null;){let P=v.elt;if(P.id==x.id&&P.di==b.id){y=P;break}v=v.next}d=y}else d=l;let f=d==null,m,z=!1;if(f)Bt.zpp_pool==null?m=new Bt:(m=Bt.zpp_pool,Bt.zpp_pool=m.next,m.next=null);else if(d.sensorarb==null){d.cleared=!0;{let w=d.b1.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let k,N;v==null?(k=w.head,N=k.next,w.head=N,w.head==null&&(w.pushmod=!0)):(k=v.next,N=k.next,v.next=N,N==null&&(w.pushmod=!0));let E=k;E.elt=null,E.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}{let w=d.b2.arbiters,v=null,P=w.head,g=!1;for(;P!=null;){if(P.elt==d){let k,N;v==null?(k=w.head,N=k.next,w.head=N,w.head==null&&(w.pushmod=!0)):(k=v.next,N=k.next,v.next=N,N==null&&(w.pushmod=!0));let E=k;E.elt=null,E.next=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,w.modified=!0,w.length--,w.pushmod=!0,g=!0;break}v=P,P=P.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,Bt.zpp_pool==null?m=new Bt:(m=Bt.zpp_pool,Bt.zpp_pool=m.next,m.next=null),m.intchange=!0,f=!0,z=!0}else m=d.sensorarb;let Z=2;if(f||m.stamp!=this.stamp||s)if(m.stamp=this.stamp,Ee.testCollide(x,b)){if(f){let y=b.id;m.b1=e.body,m.ws1=e,m.b2=t.body,m.ws2=t,m.id=x.id,m.di=y;let w=m.b1.arbiters,v;A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?v=new A._zpp.util.ZNPNode_ZPP_Arbiter:(v=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=v.next,v.next=null),v.elt=m;let P=v;P.next=w.head,w.head=P,w.modified=!0,w.length++;let g=m.b2.arbiters,k;A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?k=new A._zpp.util.ZNPNode_ZPP_Arbiter:(k=A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k.next,k.next=null),k.elt=m;let N=k;N.next=g.head,g.head=N,g.modified=!0,g.length++,m.active=!0,m.present=0,m.cleared=!1,m.sleeping=!1,m.fresh=!1,m.presentable=!1;let E=this.s_arbiters,M;A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?M=new A._zpp.util.ZNPNode_ZPP_SensorArbiter:(M=A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=M.next,M.next=null),M.elt=m;let C=M;C.next=E.head,E.head=C,E.modified=!0,E.length++,m.fresh=!z}else m.fresh=m.up_stamp<this.stamp-1||m.endGenerated==this.stamp&&s;if(m.up_stamp=m.stamp,m.fresh||(m.immState&4)==0){m.immState=1;let y=!1,w=m.ws1.id>m.ws2.id?m.ws2:m.ws1,v=m.ws1.id>m.ws2.id?m.ws1:m.ws2,P=this.mrca1;for(;P.head!=null;){let M=P.head;P.head=M.next;let C=M;C.elt=null,C.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}P.pushmod=!0;let g=this.mrca2;for(;g.head!=null;){let M=g.head;g.head=M.next;let C=M;C.elt=null,C.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}if(g.pushmod=!0,w.cbSet!=null){let M=this.mrca1,C;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new A._zpp.util.ZNPNode_ZPP_Interactor:(C=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=w;let L=C;L.next=M.head,M.head=L,M.modified=!0,M.length++}if(w.body.cbSet!=null){let M=this.mrca1,C=w.body,L;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?L=new A._zpp.util.ZNPNode_ZPP_Interactor:(L=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=L.next,L.next=null),L.elt=C;let O=L;O.next=M.head,M.head=O,M.modified=!0,M.length++}if(v.cbSet!=null){let M=this.mrca2,C;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new A._zpp.util.ZNPNode_ZPP_Interactor:(C=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=v;let L=C;L.next=M.head,M.head=L,M.modified=!0,M.length++}if(v.body.cbSet!=null){let M=this.mrca2,C=v.body,L;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?L=new A._zpp.util.ZNPNode_ZPP_Interactor:(L=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=L.next,L.next=null),L.elt=C;let O=L;O.next=M.head,M.head=O,M.modified=!0,M.length++}let k=w.body.compound,N=v.body.compound;for(;k!=N;){let M=k==null?0:k.depth,C=N==null?0:N.depth;if(M<C){if(N.cbSet!=null){let L=this.mrca2,O;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new A._zpp.util.ZNPNode_ZPP_Interactor:(O=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=N;let I=O;I.next=L.head,L.head=I,L.modified=!0,L.length++}N=N.compound}else{if(k.cbSet!=null){let L=this.mrca1,O;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new A._zpp.util.ZNPNode_ZPP_Interactor:(O=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=k;let I=O;I.next=L.head,L.head=I,L.modified=!0,L.length++}k=k.compound}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,C=this.mrca2.head;for(;C!=null;){let L=C.elt,O=M.cbSet,I=L.cbSet,T=O.manager,W=null,G=(O.cbpairs.length<I.cbpairs.length?O.cbpairs:I.cbpairs).head;for(;G!=null;){let B=G.elt;if(B.a==O&&B.b==I||B.a==I&&B.b==O){W=B;break}G=G.next}if(W==null){let B;Ne.zpp_pool==null?B=new Ne:(B=Ne.zpp_pool,Ne.zpp_pool=B.next,B.next=null),B.zip_listeners=!0,Pt.setlt(O,I)?(B.a=O,B.b=I):(B.a=I,B.b=O),W=B,O.cbpairs.add(W),I!=O&&I.cbpairs.add(W)}if(W.zip_listeners&&(W.zip_listeners=!1,W.__validate()),W.listeners.head==null){C=C.next;continue}let j=null,S=null,q=this.prelisteners;for(;q.head!=null;){let B=q.head;q.head=B.next;let V=B;V.elt=null,V.next=A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=V,q.head==null&&(q.pushmod=!0),q.modified=!0,q.length--}q.pushmod=!0;let $=null,X=O.manager,H=null,F=(O.cbpairs.length<I.cbpairs.length?O.cbpairs:I.cbpairs).head;for(;F!=null;){let B=F.elt;if(B.a==O&&B.b==I||B.a==I&&B.b==O){H=B;break}F=F.next}if(H==null){let B;Ne.zpp_pool==null?B=new Ne:(B=Ne.zpp_pool,Ne.zpp_pool=B.next,B.next=null),B.zip_listeners=!0,Pt.setlt(O,I)?(B.a=O,B.b=I):(B.a=I,B.b=O),H=B,O.cbpairs.add(H),I!=O&&I.cbpairs.add(H)}H.zip_listeners&&(H.zip_listeners=!1,H.__validate());let D=H.listeners.head;for(;D!=null;){let B=D.elt;if(B.event==5&&(B.itype&Z)!=0){let V=i.prelisteners,J;A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?J=new A._zpp.util.ZNPNode_ZPP_InteractionListener:(J=A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,A._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=J.next,J.next=null),J.elt=B;let Q=J;$==null?(Q.next=V.head,V.head=Q):(Q.next=$.next,$.next=Q),V.pushmod=V.modified=!0,V.length++,$=Q,y=y||!B.pure}D=D.next}if(this.prelisteners.head==null){C=C.next;continue}if(j=A._zpp.phys.ZPP_Interactor.get(M,L),j==null&&(S=Ht.get(M,L),this.add_callbackset(S)),j==null||(j.SENSORstamp!=this.stamp||s)&&(j.SENSORstate&4)==0){if(S!=null&&(j=S),j!=null){let Q=this.prelisteners.head;for(;Q!=null;)Q.elt.itype==7?(j.COLLISIONstamp=this.stamp,j.SENSORstamp=this.stamp,j.FLUIDstamp=this.stamp):j.SENSORstamp=this.stamp,Q=Q.next}let B=m.active;m.active=!0;let V=!1;this.precb.zpp_inner.pre_arbiter=m,this.precb.zpp_inner.set=j;let J=this.prelisteners.head;for(;J!=null;){let Q=J.elt;this.precb.zpp_inner.listener=Q;let K=this.precb.zpp_inner,ne=j.int1,re=j.int2,se,ie=Q.options1,oe=ne.cbTypes;if(ie.nonemptyintersection(oe,ie.includes)&&!ie.nonemptyintersection(oe,ie.excludes)){let pe=Q.options2,ae=re.cbTypes;se=pe.nonemptyintersection(ae,pe.includes)&&!pe.nonemptyintersection(ae,pe.excludes)}else se=!1;se?(K.int1=ne,K.int2=re):(K.int1=re,K.int2=ne),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let ce=Q.handlerp(this.precb);if(ce!=null){let pe;U.PreFlag_ACCEPT==null&&(U.internal=!0,U.PreFlag_ACCEPT=new A._nape.callbacks.PreFlag,U.internal=!1),ce==U.PreFlag_ACCEPT?pe=5:(U.PreFlag_ACCEPT_ONCE==null&&(U.internal=!0,U.PreFlag_ACCEPT_ONCE=new A._nape.callbacks.PreFlag,U.internal=!1),ce==U.PreFlag_ACCEPT_ONCE?pe=1:(U.PreFlag_IGNORE==null&&(U.internal=!0,U.PreFlag_IGNORE=new A._nape.callbacks.PreFlag,U.internal=!1),pe=ce==U.PreFlag_IGNORE?6:2)),m.immState=pe}J=J.next}if(m.active=B,j!=null){let Q=this.prelisteners.head;for(;Q!=null;)Q.elt.itype==7?(j.COLLISIONstate=m.immState,j.SENSORstate=m.immState,j.FLUIDstate=m.immState):j.SENSORstate=m.immState,Q=Q.next}}else j==null?(m.immState&4)==0&&(m.immState=1):m.immState=j.SENSORstate;C=C.next}E=E.next}if(y&&(m.immState&4)==0){if(m.b1.type!=1){let M=m.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}if(m.b2.type!=1){let M=m.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=!0),M.component.sleeping&&this.really_wake(M,!1))}}}if(m.sleeping){m.sleeping=!1;let y=this.s_arbiters,w;A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?w=new A._zpp.util.ZNPNode_ZPP_SensorArbiter:(w=A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,A._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=w.next,w.next=null),w.elt=m;let v=w;v.next=y.head,y.head=v,y.modified=!0,y.length++}o=m}else if(f){let y=m;y.next=Bt.zpp_pool,Bt.zpp_pool=y,o=null}else o=m;else o=m}}return o}MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let o=n.head;n.head=o.next;let r=o;r.elt=null,r.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let l=this.mrca2;for(;l.head!=null;){let o=l.head;l.head=o.next;let r=o;r.elt=null,r.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,l.head==null&&(l.pushmod=!0),l.modified=!0,l.length--}if(l.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new A._zpp.util.ZNPNode_ZPP_Interactor:(r=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=e;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(e.body.cbSet!=null){let o=this.mrca1,r=e.body,a;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new A._zpp.util.ZNPNode_ZPP_Interactor:(a=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}if(t.cbSet!=null){let o=this.mrca2,r;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new A._zpp.util.ZNPNode_ZPP_Interactor:(r=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=t;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(t.body.cbSet!=null){let o=this.mrca2,r=t.body,a;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new A._zpp.util.ZNPNode_ZPP_Interactor:(a=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let s=e.body.compound,i=t.body.compound;for(;s!=i;){let o=s==null?0:s.depth,r=i==null?0:i.depth;if(o<r){if(i.cbSet!=null){let a=this.mrca2,p;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new A._zpp.util.ZNPNode_ZPP_Interactor:(p=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._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;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new A._zpp.util.ZNPNode_ZPP_Interactor:(p=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=s;let c=p;c.next=a.head,a.head=c,a.modified=!0,a.length++}s=s.compound}}}inlined_MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let o=n.head;n.head=o.next;let r=o;r.elt=null,r.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let l=this.mrca2;for(;l.head!=null;){let o=l.head;l.head=o.next;let r=o;r.elt=null,r.next=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,l.head==null&&(l.pushmod=!0),l.modified=!0,l.length--}if(l.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new A._zpp.util.ZNPNode_ZPP_Interactor:(r=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=e;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(e.body.cbSet!=null){let o=this.mrca1,r=e.body,a;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new A._zpp.util.ZNPNode_ZPP_Interactor:(a=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}if(t.cbSet!=null){let o=this.mrca2,r;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new A._zpp.util.ZNPNode_ZPP_Interactor:(r=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=t;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(t.body.cbSet!=null){let o=this.mrca2,r=t.body,a;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new A._zpp.util.ZNPNode_ZPP_Interactor:(a=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let s=e.body.compound,i=t.body.compound;for(;s!=i;){let o=s==null?0:s.depth,r=i==null?0:i.depth;if(o<r){if(i.cbSet!=null){let a=this.mrca2,p;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new A._zpp.util.ZNPNode_ZPP_Interactor:(p=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._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;A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new A._zpp.util.ZNPNode_ZPP_Interactor:(p=A._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,A._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}}}};A.__name__=["zpp_nape","space","ZPP_Space"],A._zpp=null,A._nape=null;var bi=A;var Sn=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}};Sn.__name__=["zpp_nape","space","ZPP_SweepData"],Sn.zpp_pool=null;var ct=class ct{constructor(e){this.failed=null;this.list=null;this.space=null;this.is_sweep=!1;this.sweep=null;this.__class__=ct;ct._zpp.space.ZPP_Broadphase._initFields(this),this.space=e,this.is_sweep=!0,this.sweep=this}static _init(){ct.__super__=ct._zpp.space.ZPP_Broadphase;let e=ct._zpp.space.ZPP_Broadphase.prototype;Object.getOwnPropertyNames(e).forEach(t=>{t!=="constructor"&&!(t in ct.prototype)&&(ct.prototype[t]=e[t])})}__insert(e){let t;Sn.zpp_pool==null?t=new Sn:(t=Sn.zpp_pool,Sn.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=Sn.zpp_pool,Sn.zpp_pool=n}__sync(e){if(!this.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let i=t.polygon;if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(i.lverts.next.next==null)i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;else if(i.lverts.next.next.next==null){i.localCOMx=i.lverts.next.x,i.localCOMy=i.lverts.next.y;let o=1;i.localCOMx+=i.lverts.next.next.x*o,i.localCOMy+=i.lverts.next.next.y*o;let r=.5;i.localCOMx*=r,i.localCOMy*=r}else{i.localCOMx=0,i.localCOMy=0;let o=0,r=i.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let _=r;o+=p.x*(_.y-a.y);let d=_.y*p.x-_.x*p.y;i.localCOMx+=(p.x+_.x)*d,i.localCOMy+=(p.y+_.y)*d,a=p,p=_,r=r.next}r=i.lverts.next;let c=r;o+=p.x*(c.y-a.y);let u=c.y*p.x-c.x*p.y;i.localCOMx+=(p.x+c.x)*u,i.localCOMy+=(p.y+c.y)*u,a=p,p=c,r=r.next;let h=r;o+=p.x*(h.y-a.y);let x=h.y*p.x-h.x*p.y;i.localCOMx+=(p.x+h.x)*x,i.localCOMy+=(p.y+h.y)*x,o=1/(3*o);let b=o;i.localCOMx*=b,i.localCOMy*=b}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,l=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-l,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+l}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let s=t.body;s.zip_axis&&(s.zip_axis=!1,s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot));let i=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=i;i=i.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let l=t.gverts.next.next;for(;l!=null;){let s=l;s.x<t.aabb.minx&&(t.aabb.minx=s.x),s.x>t.aabb.maxx&&(t.aabb.maxx=s.x),s.y<t.aabb.miny&&(t.aabb.miny=s.y),s.y>t.aabb.maxy&&(t.aabb.maxy=s.y),l=l.next}}}sync_broadphase(){if(this.space.validation(),this.list!=null){let e=this.list.next;for(;e!=null;){let t=e.next,n=e.prev;if(n!=null&&e.aabb.minx>n.aabb.minx){e=t;continue}for(;n.prev!=null&&n.prev.aabb.minx>e.aabb.minx;)n=n.prev;let l=e.prev;l.next=e.next,e.next!=null&&(e.next.prev=l),n.prev==null?(e.prev=null,this.list=e,e.next=n,n.prev=e):(e.prev=n.prev,n.prev=e,e.prev.next=e,e.next=n),e=t}}}sync_broadphase_fast(){let e=this.list.next;for(;e!=null;){let t=e.next,n=e.prev;if(n!=null&&e.aabb.minx>n.aabb.minx){e=t;continue}for(;n.prev!=null&&n.prev.aabb.minx>e.aabb.minx;)n=n.prev;let l=e.prev;l.next=e.next,e.next!=null&&(e.next.prev=l),n.prev==null?(e.prev=null,this.list=e,e.next=n,n.prev=e):(e.prev=n.prev,n.prev=e,e.prev.next=e,e.next=n),e=t}}broadphase(e,t){if(this.list!=null){let n=this.list.next;for(;n!=null;){let s=n.next,i=n.prev;if(i!=null&&n.aabb.minx>i.aabb.minx){n=s;continue}for(;i.prev!=null&&i.prev.aabb.minx>n.aabb.minx;)i=i.prev;let o=n.prev;o.next=n.next,n.next!=null&&(n.next.prev=o),i.prev==null?(n.prev=null,this.list=n,n.next=i,i.prev=n):(n.prev=i.prev,i.prev=n,n.prev.next=n,n.next=i),n=s}let l=this.list;for(;l!=null;){let s=l.next,i=l.shape,o=i.body,r=l.aabb.maxx;for(;s!=null&&!(s.aabb.minx>r);){let a=s.shape,p=a.body;if(p==o){s=s.next;continue}if(o.type==1&&p.type==1){s=s.next;continue}if(o.component.sleeping&&p.component.sleeping){s=s.next;continue}let c=i.aabb,u=a.aabb;u.miny>c.maxy||c.miny>u.maxy||(t?e.narrowPhase(i,a,o.type!=2||p.type!=2,null,!1):e.continuousEvent(i,a,o.type!=2||p.type!=2,null,!1)),s=s.next}l=l.next}}}clear(){for(;this.list!=null;)this.list.shape.removedFromSpace(),this.__remove(this.list.shape)}shapesUnderPoint(e,t,n,l){this.sync_broadphase();let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,o=l??new ct._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.minx>e;)r=r.next;for(;r!=null&&r.aabb.minx<=e;){if(r.aabb.maxx>=e&&r.aabb.miny<=t&&r.aabb.maxy>=t){let p=r.shape,c;if(n!=null){let u=p.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;c&&(p.type==0?Ee.circleContains(p.circle,i)&&o.push(p.outer):Ee.polyContains(p.polygon,i)&&o.push(p.outer))}r=r.next}let a=i;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=le.zpp_pool,le.zpp_pool=a,o}bodiesUnderPoint(e,t,n,l){this.sync_broadphase();let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t;let i=s,o=l??new ct._nape.phys.BodyList,r=this.list;for(;r!=null&&r.aabb.minx>e;)r=r.next;for(;r!=null&&r.aabb.minx<=e;){if(r.aabb.maxx>=e&&r.aabb.miny<=t&&r.aabb.maxy>=t){let p=r.shape,c=p.body.outer;if(!o.has(c)){let u;if(n!=null){let h=p.filter;u=(h.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(p.type==0?Ee.circleContains(p.circle,i)&&o.push(c):Ee.polyContains(p.polygon,i)&&o.push(c))}}r=r.next}let a=i;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=le.zpp_pool,le.zpp_pool=a,o}shapesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,o=s??new ct._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.maxx<i.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=i.maxx;){let a=r.shape,p;if(l!=null){let c=a.filter;p=(c.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&c.collisionGroup)!=0}else p=!0;if(p)if(t)if(n)Ee.containTest(this.aabbShape.zpp_inner,a)&&o.push(a.outer);else{let c=r.aabb;if(c.minx>=i.minx&&c.miny>=i.miny&&c.maxx<=i.maxx&&c.maxy<=i.maxy)o.push(a.outer);else{let u=r.aabb;i.miny<=u.maxy&&u.miny<=i.maxy&&i.minx<=u.maxx&&u.minx<=i.maxx&&Ee.testCollide_safe(a,this.aabbShape.zpp_inner)&&o.push(a.outer)}}else{let c;if(n){let u=r.aabb;c=u.minx>=i.minx&&u.miny>=i.miny&&u.maxx<=i.maxx&&u.maxy<=i.maxy}else{let u=r.aabb;c=i.miny<=u.maxy&&u.miny<=i.maxy&&i.minx<=u.maxx&&u.minx<=i.maxx}c&&o.push(a.outer)}r=r.next}return o}bodiesInAABB(e,t,n,l,s){this.sync_broadphase(),this.updateAABBShape(e);let i=this.aabbShape.zpp_inner.aabb,o=s??new ct._nape.phys.BodyList;this.failed==null&&(this.failed=new ct._nape.phys.BodyList);let r=this.list;for(;r!=null&&r.aabb.maxx<i.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=i.maxx;){let a=r.shape,p=a.body.outer,c=r.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx){let u;if(l!=null){let h=a.filter;u=(h.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&h.collisionGroup)!=0}else u=!0;if(u)if(t)if(n){if(!this.failed.has(p)){let h=Ee.containTest(this.aabbShape.zpp_inner,a);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ee.testCollide_safe(a,this.aabbShape.zpp_inner)&&o.push(p);else if(n){if(!this.failed.has(p)){let h=a.aabb,x=h.minx>=i.minx&&h.miny>=i.miny&&h.maxx<=i.maxx&&h.maxy<=i.maxy;!o.has(p)&&x?o.push(p):x||(o.remove(p),this.failed.push(p))}}else{let h;if(o.has(p))h=!1;else{let x=a.aabb;h=x.minx>=i.minx&&x.miny>=i.miny&&x.maxx<=i.maxx&&x.maxy<=i.maxy}h&&o.push(p)}}r=r.next}return this.failed.clear(),o}shapesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let o=this.circShape.zpp_inner.aabb,r=i??new ct._nape.shape.ShapeList,a=this.list;for(;a!=null&&a.aabb.maxx<o.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=o.maxx;){let p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx){let c=a.shape,u;if(s!=null){let h=c.filter;u=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else u=!0;u&&(l?Ee.containTest(this.circShape.zpp_inner,c)&&r.push(c.outer):Ee.testCollide_safe(c,this.circShape.zpp_inner)&&r.push(c.outer))}a=a.next}return r}bodiesInCircle(e,t,n,l,s,i){this.sync_broadphase(),this.updateCircShape(e,t,n);let o=this.circShape.zpp_inner.aabb,r=i??new ct._nape.phys.BodyList;this.failed==null&&(this.failed=new ct._nape.phys.BodyList);let a=this.list;for(;a!=null&&a.aabb.maxx<o.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=o.maxx;){let p=a.aabb;if(o.miny<=p.maxy&&p.miny<=o.maxy&&o.minx<=p.maxx&&p.minx<=o.maxx){let c=a.shape,u=c.body.outer,h;if(s!=null){let x=c.filter;h=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else h=!0;if(h)if(l){if(!this.failed.has(u)){let x=Ee.containTest(this.circShape.zpp_inner,c);!r.has(u)&&x?r.push(u):x||(r.remove(u),this.failed.push(u))}}else!r.has(u)&&Ee.testCollide_safe(c,this.circShape.zpp_inner)&&r.push(u)}a=a.next}return this.failed.clear(),r}shapesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new ct._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.maxx<s.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=s.maxx;){let r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx){let a=o.shape,p;if(n!=null){let c=a.filter;p=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(t?Ee.containTest(e,a)&&i.push(a.outer):Ee.testCollide_safe(a,e)&&i.push(a.outer))}o=o.next}return i}bodiesInShape(e,t,n,l){this.sync_broadphase(),this.validateShape(e);let s=e.aabb,i=l??new ct._nape.phys.BodyList;this.failed==null&&(this.failed=new ct._nape.phys.BodyList);let o=this.list;for(;o!=null&&o.aabb.maxx<s.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=s.maxx;){let r=o.aabb;if(s.miny<=r.maxy&&r.miny<=s.maxy&&s.minx<=r.maxx&&r.minx<=s.maxx){let a=o.shape,p=a.body.outer,c;if(n!=null){let u=a.filter;c=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else c=!0;if(c)if(t){if(!this.failed.has(p)){let u=Ee.containTest(e,a);!i.has(p)&&u?i.push(p):u||(i.remove(p),this.failed.push(p))}}else!i.has(p)&&Ee.testCollide_safe(e,a)&&i.push(p)}o=o.next}return this.failed.clear(),i}rayCast(e,t,n){this.sync_broadphase(),e.validate_dir();let l=e.rayAABB(),s=e.maxdist,i=null;if(e.dirx==0){let r=this.list;for(;r!=null&&r.aabb.minx<=l.minx;){let a,p=r.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx)if(n!=null){let c=r.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;if(a){let c=e.aabbsect(r.aabb);if(c>=0&&c<s){let u=r.shape.type==0?e.circlesect(r.shape.circle,t,s):e.polysect(r.shape.polygon,t,s);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(s=u.zpp_inner.toiDistance,i!=null){if(i.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");i.zpp_inner.free()}i=u}}}r=r.next}}else if(e.dirx<0){let r=this.list,a=null;for(;r!=null&&r.aabb.minx<=l.maxx;)a=r,r=r.next;for(r=a;r!=null;){let p,c=r.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(n!=null){let u=r.shape.filter;p=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else p=!0;else p=!1;if(p){let u=e.aabbsect(r.aabb);if(u>=0&&u<s){let h=r.shape.type==0?e.circlesect(r.shape.circle,t,s):e.polysect(r.shape.polygon,t,s);if(h!=null){if(h.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(s=h.zpp_inner.toiDistance,i!=null){if(i.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");i.zpp_inner.free()}i=h}}}r=r.prev}}else{let r=this.list;for(;r!=null&&r.aabb.minx<=l.maxx&&r.aabb.minx<e.originx+e.dirx*s;){let a,p=r.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx)if(n!=null){let c=r.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;if(a){let c=e.aabbsect(r.aabb);if(c>=0&&c<s){let u=r.shape.type==0?e.circlesect(r.shape.circle,t,s):e.polysect(r.shape.polygon,t,s);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(s=u.zpp_inner.toiDistance,i!=null){if(i.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");i.zpp_inner.free()}i=u}}}r=r.next}}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=be.zpp_pool,be.zpp_pool=o,i}rayMultiCast(e,t,n,l){this.sync_broadphase(),e.validate_dir();let s=e.rayAABB(),i=l??new ct._nape.geom.RayResultList;if(e.dirx==0){let r=this.list;for(;r!=null&&r.aabb.minx<=s.minx;){let a,p=r.aabb;if(s.miny<=p.maxy&&p.miny<=s.maxy&&s.minx<=p.maxx&&p.minx<=s.maxx)if(n!=null){let c=r.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;a&&e.aabbsect(r.aabb)>=0&&(r.shape.type==0?e.circlesect2(r.shape.circle,t,i):e.polysect2(r.shape.polygon,t,i)),r=r.next}}else if(e.dirx<0){let r=this.list,a=null;for(;r!=null&&r.aabb.minx<=s.maxx;)a=r,r=r.next;for(r=a;r!=null;){let p,c=r.aabb;if(s.miny<=c.maxy&&c.miny<=s.maxy&&s.minx<=c.maxx&&c.minx<=s.maxx)if(n!=null){let u=r.shape.filter;p=(u.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&u.collisionGroup)!=0}else p=!0;else p=!1;p&&e.aabbsect(r.aabb)>=0&&(r.shape.type==0?e.circlesect2(r.shape.circle,t,i):e.polysect2(r.shape.polygon,t,i)),r=r.prev}}else{let r=this.list;for(;r!=null&&r.aabb.minx<=s.maxx;){let a,p=r.aabb;if(s.miny<=p.maxy&&p.miny<=s.maxy&&s.minx<=p.maxx&&p.minx<=s.maxx)if(n!=null){let c=r.shape.filter;a=(c.collisionMask&n.collisionGroup)!=0&&(n.collisionMask&c.collisionGroup)!=0}else a=!0;else a=!1;a&&e.aabbsect(r.aabb)>=0&&(r.shape.type==0?e.circlesect2(r.shape.circle,t,i):e.polysect2(r.shape.polygon,t,i)),r=r.next}}let o=s;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=be.zpp_pool,be.zpp_pool=o,i}};ct.__name__=["zpp_nape","space","ZPP_SweepPhase"],ct.__super__=null,ct._zpp=null,ct._nape=null;var cs=ct;function to(){let Y={},e={};return Y.callbacks={},Y.constraint={},Y.dynamics={},Y.geom={},Y.phys={},Y.shape={},Y.space={},Y.util={},e.ZPP_Const=si,e.ZPP_ID=zn,e.callbacks||(e.callbacks={}),Rt._nape=Y,Rt._zpp=e,e.callbacks.ZPP_Callback=Rt,Pt._zpp=e,e.callbacks.ZPP_CbSet=Pt,Ne._zpp=e,e.callbacks.ZPP_CbSetPair=Ne,e.util||(e.util={}),eo(e),Cn._zpp=e,e.callbacks.ZPP_CbType=Cn,e.util.ZPP_Flags=U,Wt._nape=Y,Wt._zpp=e,e.callbacks.ZPP_Listener=Wt,e.callbacks.ZPP_BodyListener=Rs,e.callbacks.ZPP_ConstraintListener=qs,e.callbacks.ZPP_InteractionListener=yl,zs._nape=Y,zs._zpp=e,e.callbacks.ZPP_OptionType=zs,e.constraint||(e.constraint={}),ge._nape=Y,ge._zpp=e,e.constraint.ZPP_Constraint=ge,e.constraint.ZPP_Constraint.__name__=ge.__name__,e.constraint.ZPP_AngleJoint=qe,e.constraint.ZPP_AngleJoint.__name__=qe.__name__,e.constraint.ZPP_CopyHelper=Rn,e.constraint.ZPP_DistanceJoint=oi,e.constraint.ZPP_DistanceJoint.__name__=oi.__name__,e.constraint.ZPP_LineJoint=ri,e.constraint.ZPP_LineJoint.__name__=ri.__name__,e.constraint.ZPP_MotorJoint=ai,e.constraint.ZPP_MotorJoint.__name__=ai.__name__,e.constraint.ZPP_PivotJoint=pi,e.constraint.ZPP_PivotJoint.__name__=pi.__name__,e.constraint.ZPP_PulleyJoint=ci,e.constraint.ZPP_PulleyJoint.__name__=ci.__name__,e.constraint.ZPP_UserConstraint=Us,e.constraint.ZPP_UserConstraint.__name__=Us.__name__,e.constraint.ZPP_UserBody=ns,e.constraint.ZPP_WeldJoint=hi,e.constraint.ZPP_WeldJoint.__name__=hi.__name__,e.dynamics||(e.dynamics={}),Ve._nape=Y,Ve._zpp=e,e.dynamics.ZPP_Arbiter=Ve,e.dynamics.ZPP_SensorArbiter=Bt,Mt._nape=Y,Mt._zpp=e,e.dynamics.ZPP_FluidArbiter=Mt,dt._nape=Y,dt._zpp=e,e.dynamics.ZPP_ColArbiter=dt,e.dynamics.ZPP_IContact=ui,ve._nape=Y,ve._zpp=e,e.dynamics.ZPP_Contact=ve,yt._nape=Y,yt._zpp=e,e.dynamics.ZPP_InteractionFilter=yt,Ks._zpp=e,e.dynamics.ZPP_InteractionGroup=Ks,qn._nape=Y,qn._zpp=e,e.dynamics.ZPP_SpaceArbiterList=qn,e.geom||(e.geom={}),be._nape=Y,be._zpp=e,e.geom.ZPP_AABB=be,e.geom.ZPP_Collide=Ee,e.geom.ZPP_Convex=vs,e.geom.ZPP_ConvexRayResult=Pn,e.geom.ZPP_CutVert=$e,e.geom.ZPP_CutInt=rt,e.geom.ZPP_Cutter=gs,e.geom.ZPP_Geom=Ms,e.geom.ZPP_GeomVert=we,we._createVec2Fn=function(){return new Y.geom.Vec2},e.geom.ZPP_GeomPoly=os,e.geom.ZPP_MarchSpan=Mn,e.geom.ZPP_MarchPair=Zn,Xs._init(e,Y),e.geom.ZPP_MarchingSquares=Xs,Hs._nape=Y,e.geom.ZPP_Mat23=Hs,e.geom.ZPP_MatMN=ki,e.geom.ZPP_Monotone=Ut,e.geom.ZPP_PartitionVertex=Ge,e.geom.ZPP_PartitionedPoly=Ue,e.geom.ZPP_Ray=ml,e.geom.ZPP_SimpleVert=ke,e.geom.ZPP_SimpleSeg=Lt,e.geom.ZPP_SimpleEvent=Me,e.geom.ZPP_SimpleSweep=Si,e.geom.ZPP_Simple=Vi,e.geom.ZPP_SimplifyV=kn,e.geom.ZPP_SimplifyP=Be,e.geom.ZPP_Simplify=Zs,e.geom.ZPP_ToiEvent=ks,e.geom.ZPP_SweepDistance=wn,e.geom.ZPP_PartitionPair=Tt,e.geom.ZPP_Triangular=_i,e.geom.ZPP_Vec2=le,di._zpp=e,e.geom.ZPP_Vec3=di,e.geom.ZPP_VecMath=Qs,e.phys||(e.phys={}),e.phys.ZPP_Interactor=Vt,Vt._init(e,Y),En._init(e,Y),e.phys.ZPP_Body=En,Wn._nape=Y,Wn._zpp=e,Wn._init(),e.phys.ZPP_Compound=Wn,Nn._nape=Y,Nn._zpp=e,e.phys.ZPP_FluidProperties=Nn,Ae._nape=Y,Ae._zpp=e,e.phys.ZPP_Material=Ae,e.shape||(e.shape={}),yi._nape=Y,yi._zpp=e,yi._init(),e.shape.ZPP_Shape=yi,Qn._nape=Y,Qn._zpp=e,Qn._init(),e.shape.ZPP_Circle=Qn,at._nape=Y,at._zpp=e,e.shape.ZPP_Edge=at,$n._nape=Y,$n._zpp=e,$n._init(),e.shape.ZPP_Polygon=$n,e.space||(e.space={}),ji._zpp=e,ji._nape=Y,e.space.ZPP_Broadphase=ji,e.space.ZPP_AABBNode=Oe,e.space.ZPP_AABBPair=tt,e.space.ZPP_AABBTree=nt,as._zpp=e,as._nape=Y,as._init(),e.space.ZPP_DynAABBPhase=as,bt._zpp=e,e.space.ZPP_Island=bt,e.space.ZPP_Component=Ns,Ht._zpp=e,e.space.ZPP_CallbackSet=Ht,ps._zpp=e,e.space.ZPP_CbSetManager=ps,bi._zpp=e,bi._nape=Y,e.space.ZPP_Space=bi,e.space.ZPP_SweepData=Sn,cs._zpp=e,cs._nape=Y,cs._init(),e.space.ZPP_SweepPhase=cs,e.util.ZNPArray2_Float=Ji,e.util.ZNPArray2_ZPP_GeomVert=Ui,e.util.ZNPArray2_ZPP_MarchPair=Ki,e.util.Hashable2_Boolfalse=je,e.util.FastHash2_Hashable2_Boolfalse=Hi,e.util.ZPP_Math=Ls,e.util.ZPP_PubPool=xe,e.callbacks.ZPP_InteractionListener._initStatics(e),e.geom.ZPP_Collide._initStatics(e),e.space.ZPP_AABBTree._initStatics(),Y.__zpp=e,Y}var bl;function ye(){return bl||(bl=to()),bl}var no=!1;function fl(){if(no)return;let Y=bl;if(!Y?.callbacks?.CbEvent||!Y?.callbacks?.CbType||!Y?.callbacks?.ListenerType||!Y?.dynamics?.ArbiterType||!Y?.phys?.BodyType||!Y?.shape?.ShapeType)return;no=!0;let e=Y.__zpp;e.callbacks.ZPP_CbType._initEnums(Y),e.callbacks.ZPP_Listener._initEnums(Y,e.util.ZPP_Flags),e.dynamics.ZPP_Arbiter._initEnums(Y,e.util.ZPP_Flags),e.phys.ZPP_Body._initEnums(Y,e.util.ZPP_Flags),e.shape.ZPP_Shape._initEnums(Y,e.util.ZPP_Flags)}var io=new WeakMap;function Ze(Y,e){if(!Y)return null;let t=io.get(Y);return t||(t=e(Y),io.set(Y,t)),t}var Re=class Re{constructor(e=0,t=0){this.zpp_pool=null;this.zpp_disp=!1;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;le.zpp_pool==null?n=new le:(n=le.zpp_pool,le.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,this.zpp_inner=n,n.outer=this}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}_checkImmutable(){this.zpp_inner.immutable()}_validate(){this.zpp_inner.validate()}_invalidate(){this.zpp_inner.invalidate()}static _disposeWeak(e){e.zpp_inner.weak&&e.dispose()}_setXY(e,t){if(this._checkDisposed(),this._checkImmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");this._validate(),(this.zpp_inner.x!==e||this.zpp_inner.y!==t)&&(this.zpp_inner.x=e,this.zpp_inner.y=t,this._invalidate())}static _poolGet(e,t,n){let l;if(xe.poolVec2==null?l=new Re:(l=xe.poolVec2,xe.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===xe.nextVec2&&(xe.nextVec2=null)),l.zpp_inner==null){let s;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,l.zpp_inner=s,s.outer=l}else l.zpp_inner.immutable(),l.zpp_inner.validate(),(l.zpp_inner.x!==e||l.zpp_inner.y!==t)&&(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner.invalidate());return l.zpp_inner.weak=n,l}static _wrap(e){return e instanceof Re?e:e?e instanceof le?Ze(e,t=>{let n=Object.create(Re.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?Re._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=!1){if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");return Re._poolGet(e,t,n)}static weak(e=0,t=0){if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");return Re._poolGet(e,t,!0)}static fromPolar(e,t,n=!1){if(e!==e)throw new Error("Error: Vec2::length cannot be NaN");if(t!==t)throw new Error("Error: Vec2::angle cannot be NaN");let l=e*Math.cos(t),s=e*Math.sin(t);return Re._poolGet(l,s,n)}static fromAngle(e,t=!1){return Re.fromPolar(1,e,t)}static lerp(e,t,n,l=!1){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot lerp with null Vec2");if(n!==n)throw new Error("Error: Cannot lerp with NaN t");e.zpp_inner.validate(),t.zpp_inner.validate();let s=e.zpp_inner.x+n*(t.zpp_inner.x-e.zpp_inner.x),i=e.zpp_inner.y+n*(t.zpp_inner.y-e.zpp_inner.y),o=Re._poolGet(s,i,l);return Re._disposeWeak(e),Re._disposeWeak(t),o}static eq(e,t,n=0){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null){let o=e==null&&t==null;return e!=null&&Re._disposeWeak(e),t!=null&&Re._disposeWeak(t),o}e.zpp_inner.validate(),t.zpp_inner.validate();let l=e.zpp_inner.x-t.zpp_inner.x,s=e.zpp_inner.y-t.zpp_inner.y,i=(l<0?-l:l)<=n&&(s<0?-s:s)<=n;return Re._disposeWeak(e),Re._disposeWeak(t),i}static dsq(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,l=e.zpp_inner.y;t.zpp_inner.validate();let s=t.zpp_inner.x,i=t.zpp_inner.y,o=n-s,r=l-i,a=o*o+r*r;return Re._disposeWeak(e),Re._disposeWeak(t),a}static distance(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,l=e.zpp_inner.y;t.zpp_inner.validate();let s=t.zpp_inner.x,i=t.zpp_inner.y,o=n-s,r=l-i,a=Math.sqrt(o*o+r*r);return Re._disposeWeak(e),Re._disposeWeak(t),a}get x(){return this._checkDisposed(),this._validate(),this.zpp_inner.x}set x(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.x!==e){if(e!==e)throw new Error("Error: Vec2::x cannot be NaN");this.zpp_inner.x=e,this._invalidate()}}get y(){return this._checkDisposed(),this._validate(),this.zpp_inner.y}set y(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.y!==e){if(e!==e)throw new Error("Error: Vec2::y cannot be NaN");this.zpp_inner.y=e,this._invalidate()}}get length(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return Math.sqrt(e*e+t*t)}set length(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::length cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,l=t*t+n*n;if(l===0)throw new Error("Error: Cannot set length of a zero vector");let s=e/Math.sqrt(l);this._setXY(t*s,n*s),this._invalidate()}get angle(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e===t&&e===0?0:Math.atan2(t,e)}set angle(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::angle cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,l=Math.sqrt(t*t+n*n),s=l*Math.cos(e),i=l*Math.sin(e);this._setXY(s,i)}lsq(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e*e+t*t}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");e.zpp_inner.validate();let t=e.zpp_inner.x,n=e.zpp_inner.y;return this._setXY(t,n),Re._disposeWeak(e),this}setxy(e,t){return this._checkDisposed(),this._checkImmutable(),this._setXY(e,t),this}clone(){return this.copy()}equals(e,t=0){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)return!1;this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,l=this.zpp_inner.y-e.zpp_inner.y;return(n<0?-n:n)<=t&&(l<0?-l:l)<=t}copy(e=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y;return Re._poolGet(t,n,e)}rotate(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Cannot rotate Vec2 by NaN");if(e%(Math.PI*2)!==0){let t=Math.sin(e),n=Math.cos(e),l=n*this.zpp_inner.x-t*this.zpp_inner.y;this.zpp_inner.y=this.zpp_inner.x*t+this.zpp_inner.y*n,this.zpp_inner.x=l,this._invalidate()}return this}reflect(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this._validate();let n=this.zpp_inner.x,l=this.zpp_inner.y;if(Math.sqrt(n*n+l*l)===0)throw new Error("Error: Cannot reflect in zero vector");let s=Re._poolGet(n,l,!0);s.normalise();let i=e.sub(s.muleq(2*s.dot(e)),t);return Re._disposeWeak(e),i}normalise(){this._checkDisposed(),this._checkImmutable(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y,n=e*e+t*t;if(Math.sqrt(n)===0)throw new Error("Error: Cannot normalise vector of length 0");let l=1/Math.sqrt(n);return this._setXY(e*l,t*l),this._invalidate(),this}unit(e=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,l=t*t+n*n;if(Math.sqrt(l)===0)throw new Error("Error: Cannot normalise vector of length 0");let s=1/Math.sqrt(l);return Re._poolGet(t*s,n*s,e)}add(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x+e.zpp_inner.x,l=this.zpp_inner.y+e.zpp_inner.y,s=Re._poolGet(n,l,t);return Re._disposeWeak(e),s}addMul(e,t,n=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let l=this.zpp_inner.x+e.zpp_inner.x*t,s=this.zpp_inner.y+e.zpp_inner.y*t,i=Re._poolGet(l,s,n);return Re._disposeWeak(e),i}sub(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot subtract null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,l=this.zpp_inner.y-e.zpp_inner.y,s=Re._poolGet(n,l,t);return Re._disposeWeak(e),s}mul(e,t=!1){if(this._checkDisposed(),e!==e)throw new Error("Error: Cannot multiply with NaN");this._validate();let n=this.zpp_inner.x*e,l=this.zpp_inner.y*e;return Re._poolGet(n,l,t)}addeq(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x+e.zpp_inner.x,n=this.zpp_inner.y+e.zpp_inner.y;return this._setXY(t,n),Re._disposeWeak(e),this}subeq(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot subtract null vectors");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x-e.zpp_inner.x,n=this.zpp_inner.y-e.zpp_inner.y;return this._setXY(t,n),Re._disposeWeak(e),this}muleq(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Cannot multiply with NaN");this._validate();let t=this.zpp_inner.x*e,n=this.zpp_inner.y*e;return this._setXY(t,n),this}dot(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot take dot product with null vector");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x*e.zpp_inner.x+this.zpp_inner.y*e.zpp_inner.y;return Re._disposeWeak(e),t}cross(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot take cross product with null vector");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x*e.zpp_inner.y-this.zpp_inner.y*e.zpp_inner.x;return Re._disposeWeak(e),t}perp(e=!1){this._checkDisposed(),this._validate();let t=-this.zpp_inner.y,n=this.zpp_inner.x;return Re._poolGet(t,n,e)}dispose(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),this.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let e=this.zpp_inner;e.outer=null,this.zpp_inner=null,this.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=this:xe.poolVec2=this,xe.nextVec2=this,this.zpp_disp=!0,e.free(),e.next=le.zpp_pool,le.zpp_pool=e}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};Re.__name__=["nape","geom","Vec2"];var ot=Re;le._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(ot.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var ko=ye();ko.geom.Vec2=ot;var Bi=class Bi{constructor(e=0,t=0,n=0){this.zpp_pool=null;this.zpp_disp=!1;let l=new di;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 Bi?e:e?e instanceof di?Ze(e,t=>{let n=Object.create(Bi.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?Bi._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=0){let l;return xe.poolVec3==null?l=new Bi:(l=xe.poolVec3,xe.poolVec3=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===xe.nextVec3&&(xe.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(),Bi.get(this.zpp_inner.x,this.zpp_inner.y,this.zpp_inner.z)}xy(e=!1){return this._checkDisposed(),this.zpp_inner.validate(),ot.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,xe.nextVec3!=null?xe.nextVec3.zpp_pool=this:xe.poolVec3=this,xe.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+" }"}};Bi.__name__=["nape","geom","Vec3"];var fi=Bi;di._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(fi.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var zi=class zi{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 ki(e,t),this.zpp_inner.outer=this}static _wrap(e){return e instanceof zi?e:e?e instanceof ki?Ze(e,t=>{let n=Object.create(zi.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?zi._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 zi(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 zi(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 zi(this.zpp_inner.m,t.zpp_inner.n);for(let l=0;l<this.zpp_inner.m;l++)for(let s=0;s<t.zpp_inner.n;s++){let i=0;for(let o=0;o<this.zpp_inner.n;o++)i+=this.zpp_inner.x[l*this.zpp_inner.n+o]*t.zpp_inner.x[o*t.zpp_inner.n+s];n.zpp_inner.x[l*n.zpp_inner.n+s]=i}return n}};zi.__name__=["nape","geom","MatMN"];var $s=zi,Eo=ye();Eo.geom.MatMN=$s;var hs=class hs{get _inner(){return this}constructor(e=0,t=0,n=0,l=0){if(e!==e||t!==t)throw new Error("Error: AABB position cannot be NaN");if(n!==n||l!==l)throw new Error("Error: AABB dimensions cannot be NaN");let s;be.zpp_pool==null?s=new be:(s=be.zpp_pool,be.zpp_pool=s.next,s.next=null),s.minx=e,s.miny=t,s.maxx=e+n,s.maxy=t+l,this.zpp_inner=s,s.outer=this}static fromPoints(e){if(e==null||e.length===0)throw new Error("Error: AABB::fromPoints requires at least one point");let t=e[0];if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");t.zpp_inner.validate();let n=t.zpp_inner.x,l=t.zpp_inner.y,s=n,i=l;for(let o=1;o<e.length;o++){let r=e[o];if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(r==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");r.zpp_inner.validate();let a=r.zpp_inner.x,p=r.zpp_inner.y;a<n&&(n=a),p<l&&(l=p),a>s&&(s=a),p>i&&(i=p)}return new hs(n,l,s-n,i-l)}static _wrap(e){return e instanceof hs?e:e?e instanceof be?Ze(e,t=>{let n=Object.create(hs.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?hs._wrap(e.zpp_inner):null:null}get x(){return this.zpp_inner.validate(),this.zpp_inner.minx}set x(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::x cannot be NaN");this.zpp_inner.maxx+=e-this.zpp_inner.minx,this.zpp_inner.minx=e,this.zpp_inner.invalidate()}}get y(){return this.zpp_inner.validate(),this.zpp_inner.miny}set y(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::y cannot be NaN");this.zpp_inner.maxy+=e-this.zpp_inner.miny,this.zpp_inner.miny=e,this.zpp_inner.invalidate()}}get width(){return this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx}set width(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::width cannot be NaN");if(e<0)throw new Error("Error: AABB::width ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxx=this.zpp_inner.minx+e,this.zpp_inner.invalidate()}}get height(){return this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny}set height(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::height cannot be NaN");if(e<0)throw new Error("Error: AABB::height ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxy=this.zpp_inner.miny+e,this.zpp_inner.invalidate()}}get min(){return this.zpp_inner.getmin(),this.zpp_inner.wrap_min}set min(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::min");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::min components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::min components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.x;this.zpp_inner.getmax();let s=this.zpp_inner.wrap_max;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l>s.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let i=e.zpp_inner.y;this.zpp_inner.getmin();let o=this.zpp_inner.wrap_max;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(o.zpp_inner._validate!=null&&o.zpp_inner._validate(),i>o.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let r=this.zpp_inner.wrap_min;this._assignVec2(r,e),e.zpp_inner.weak&&this._disposeVec2(e)}get max(){return this.zpp_inner.getmax(),this.zpp_inner.wrap_max}set max(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::max");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::max components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::max components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.x;this.zpp_inner.getmin();let s=this.zpp_inner.wrap_min;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l<s.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let i=e.zpp_inner.y;this.zpp_inner.getmin();let o=this.zpp_inner.wrap_min;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(o.zpp_inner._validate!=null&&o.zpp_inner._validate(),i<o.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let r=this.zpp_inner.wrap_max;this._assignVec2(r,e),e.zpp_inner.weak&&this._disposeVec2(e)}_assignVec2(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=e.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t==null)throw new Error("Error: Cannot assign null Vec2");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let l=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let s=t.zpp_inner.y;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=e.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),l!=l||s!=s)throw new Error("Error: Vec2 components cannot be NaN");let o;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e.zpp_inner._validate!=null&&e.zpp_inner._validate(),e.zpp_inner.x==l){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate(),o=e.zpp_inner.y==s}else o=!1;o||(e.zpp_inner.x=l,e.zpp_inner.y=s,e.zpp_inner._invalidate!=null&&e.zpp_inner._invalidate(e.zpp_inner))}_disposeVec2(e){let n=ye().zpp_nape;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let s=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let i=e;i.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=i:n.util.ZPP_PubPool.poolVec2=i,n.util.ZPP_PubPool.nextVec2=i,i.zpp_disp=!0;let o=s;o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o}clone(){return this.copy()}equals(e,t=0){if(e==null)return!1;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.minx-e.zpp_inner.minx,l=this.zpp_inner.miny-e.zpp_inner.miny,s=this.zpp_inner.maxx-e.zpp_inner.maxx,i=this.zpp_inner.maxy-e.zpp_inner.maxy;return(n<0?-n:n)<=t&&(l<0?-l:l)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t}copy(){this.zpp_inner.validate();let e=this.zpp_inner;return be.get(e.minx,e.miny,e.maxx,e.maxy).wrapper()}toString(){return this.zpp_inner.validate(),this.zpp_inner.toString()}};hs.__name__=["nape","geom","AABB"];var us=hs;be._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(us.prototype);return t.zpp_inner=e,e.outer=t,t});var Os=class Os{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate Winding derp!")}static get UNDEFINED(){return U.Winding_UNDEFINED==null&&(U.internal=!0,U.Winding_UNDEFINED=new Os,U.internal=!1),U.Winding_UNDEFINED}static get CLOCKWISE(){return U.Winding_CLOCKWISE==null&&(U.internal=!0,U.Winding_CLOCKWISE=new Os,U.internal=!1),U.Winding_CLOCKWISE}static get ANTICLOCKWISE(){return U.Winding_ANTICLOCKWISE==null&&(U.internal=!0,U.Winding_ANTICLOCKWISE=new Os,U.internal=!1),U.Winding_ANTICLOCKWISE}toString(){return this===U.Winding_UNDEFINED?"UNDEFINED":this===U.Winding_CLOCKWISE?"CLOCKWISE":this===U.Winding_ANTICLOCKWISE?"ANTICLOCKWISE":""}};Os.__name__=["nape","geom","Winding"];var Vl=Os,No=ye();No.geom.Winding=Vl;var Jn=class Jn{constructor(){this.ptr=null;this.start=null;this.first=!1;this.forward=!1;this.outer=null;this.next=null;Jn.internal=!0;let e=ye();this.outer=new e.geom.GeomVertexIterator,Jn.internal=!1}static get(e,t){let n;return Jn.zpp_pool==null?n=new Jn:(n=Jn.zpp_pool,Jn.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(){}};Jn.__name__=["zpp_nape","geom","ZPP_GeomVertexIterator"],Jn.zpp_pool=null,Jn.internal=!1;var Ss=Jn;var Xe=class Xe{constructor(e){this.zpp_pool=null;this.zpp_disp=!1;this.zpp_inner=new os(this),e!=null&&(Xe._addVertices(this,e),this.skipForward(1),Xe._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 we.zpp_pool==null?n=new we:(n=we.zpp_pool,we.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=we.zpp_pool,we.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=ye();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 ot))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 o=i.zpp_inner.x;i.zpp_inner.validate();let r=i.zpp_inner.y,a=Xe._createVert(o,r);Xe._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 o=s.zpp_inner.y,r=Xe._createVert(i,o);Xe._pushVert(e,r)}}else if(t instanceof Xe){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=Xe._createVert(s.x,s.y);Xe._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 ye().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 xe.poolGeomPoly==null?t=new Xe:(t=xe.poolGeomPoly,xe.poolGeomPoly=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t===xe.nextGeomPoly&&(xe.nextGeomPoly=null)),e!=null&&(Xe._addVertices(t,e),t.skipForward(1),Xe._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(),Ss.get(this.zpp_inner.vertices,!0)}forwardIterator(){return this._checkDisposed(),Ss.get(this.zpp_inner.vertices,!0)}backwardsIterator(){return this._checkDisposed(),Ss.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=Xe._createVert(t,n);return Xe._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 Xe._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=Xe._createVert(t,n);return Xe._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 Xe._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),Xe._freeVert(t)}return this}clear(){for(this._checkDisposed();this.zpp_inner.vertices!=null;){let e=this._shiftHead();Xe._freeVert(e)}return this}copy(){this._checkDisposed();let e=Xe.get();return this._forEachVert(t=>{let n=Xe._createVert(t.x,t.y);Xe._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,xe.nextGeomPoly!=null?xe.nextGeomPoly.zpp_pool=this:xe.poolGeomPoly=this,xe.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 U.Winding_UNDEFINED==null&&(U.internal=!0,U.Winding_UNDEFINED=new(ye()).geom.Winding,U.internal=!1),U.Winding_UNDEFINED;let e=0;this._forEachVert(n=>{e+=n.x*(n.next.y-n.prev.y)});let t=e*.5;return t>0?(U.Winding_CLOCKWISE==null&&(U.internal=!0,U.Winding_CLOCKWISE=new(ye()).geom.Winding,U.internal=!1),U.Winding_CLOCKWISE):t===0?(U.Winding_UNDEFINED==null&&(U.internal=!0,U.Winding_UNDEFINED=new(ye()).geom.Winding,U.internal=!1),U.Winding_UNDEFINED):(U.Winding_ANTICLOCKWISE==null&&(U.internal=!0,U.Winding_ANTICLOCKWISE=new(ye()).geom.Winding,U.internal=!1),U.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 U.Winding_CLOCKWISE==null&&(U.internal=!0,U.Winding_CLOCKWISE=new(ye()).geom.Winding,U.internal=!1),e===U.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,o=i.prev,r=i.next,a=r.x-i.x,p=r.y-i.y,c=i.x-o.x,h=(i.y-o.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:Vi.isSimple(this.zpp_inner.vertices)}isMonotone(){return this._checkDisposed(),this._isDegenRing()?!0:Ut.isMonotone(this.zpp_inner.vertices)}isDegenerate(){return this._checkDisposed(),this._isDegenRing()?!0:this.area()<ye().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=Zs.simplify(this.zpp_inner.vertices,e),n=Xe.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=ye(),n=this.zpp_inner.vertices;Ue.sharedGVList==null&&(Ue.sharedGVList=new Fn);let l=Vi.decompose(n,Ue.sharedGVList),s=e??new t.geom.GeomPolyList;for(;l.head!=null;){let i=l.pop_unsafe(),o=Xe.get();o.zpp_inner.vertices=i,s.zpp_inner.reverse_flag?s.push(o):s.unshift(o)}return s}monotoneDecomposition(e){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let t=ye(),n=this.zpp_inner.vertices;Ut.sharedPPoly==null&&(Ut.sharedPPoly=new Ue);let l=Ut.decompose(n,Ut.sharedPPoly);Ue.sharedGVList==null&&(Ue.sharedGVList=new Fn);let s=l.extract(Ue.sharedGVList),i=e??new t.geom.GeomPolyList;for(;s.head!=null;){let o=s.pop_unsafe(),r=Xe.get();r.zpp_inner.vertices=o,i.zpp_inner.reverse_flag?i.push(r):i.unshift(r)}return i}convexDecomposition(e=!1,t){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let n=ye(),l=this.zpp_inner.vertices;Ut.sharedPPoly==null&&(Ut.sharedPPoly=new Ue);let s=Ut.decompose(l,Ut.sharedPPoly);Ue.sharedPPList==null&&(Ue.sharedPPList=new Qi);let i=s.extract_partitions(Ue.sharedPPList),o=t??new n.geom.GeomPolyList;for(;i.head!=null;){let r=i.pop_unsafe();_i.triangulate(r),e&&_i.optimise(r),vs.optimise(r),Ue.sharedGVList==null&&(Ue.sharedGVList=new Fn);let a=r.extract(Ue.sharedGVList),p=r;for(p.next=Ue.zpp_pool,Ue.zpp_pool=p;a.head!=null;){let c=a.pop_unsafe(),u=Xe.get();u.zpp_inner.vertices=c,o.zpp_inner.reverse_flag?o.push(u):o.unshift(u)}}return o}triangularDecomposition(e=!1,t){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let n=ye(),l=this.zpp_inner.vertices;Ut.sharedPPoly==null&&(Ut.sharedPPoly=new Ue);let s=Ut.decompose(l,Ut.sharedPPoly);Ue.sharedPPList==null&&(Ue.sharedPPList=new Qi);let i=s.extract_partitions(Ue.sharedPPList),o=t??new n.geom.GeomPolyList;for(;i.head!=null;){let r=i.pop_unsafe();_i.triangulate(r),e&&_i.optimise(r),Ue.sharedGVList==null&&(Ue.sharedGVList=new Fn);let a=r.extract(Ue.sharedGVList),p=r;for(p.next=Ue.zpp_pool,Ue.zpp_pool=p;a.head!=null;){let c=a.pop_unsafe(),u=Xe.get();u.zpp_inner.vertices=c,o.zpp_inner.reverse_flag?o.push(u):o.unshift(u)}}return o}inflate(e){this._checkDisposed();let t=Xe.get();return this.isClockwise()&&(e=-e),this._forEachVert(n=>{let l=n.prev,s=n.next,i=n.x-l.x,o=n.y-l.y,r=s.x-n.x,a=s.y-n.y,p=Math.sqrt(i*i+o*o),c=-o/p*e,u=i/p*e,h=Math.sqrt(r*r+a*a),x=-a/h*e,b=r/h*e,_=x-c,d=b-u,f=a*_-r*d,m=f===0?0:f/(a*i-r*o),z=n.x+c+i*m,Z=n.y+u+o*m,y=ot.get(z,Z);t.push(y)}),t.skipForward(1)}cut(e,t,n=!1,l=!1,s){if(this._checkDisposed(),!(this._isDegenRing()||Vi.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=gs.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 us(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+"]"}};Xe.__name__=["nape","geom","GeomPoly"];var so=Xe;var el,tl,nl;function lo(Y){el=Y}function Ax(Y){tl=Y}function Ix(Y){nl=Y}var il=class il{constructor(){this._inner=void 0,this.zpp_inner_i=null}static _wrap(e){return e?e instanceof il?e:e.isBody&&e.isBody()&&el?el(e):e.isShape&&e.isShape()&&tl?tl(e):e.isCompound&&e.isCompound()&&nl?nl(e):Ze(e,t=>{let n=Object.create(il.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 el?el(e):e}return null}get castShape(){if(this.zpp_inner_i.ishape!=null){let e=this.zpp_inner_i.ishape.outer;return tl?tl(e):e}return null}get castCompound(){if(this.zpp_inner_i.icompound!=null){let e=this.zpp_inner_i.icompound.outer;return nl?nl(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""}};il.zpp_internalAlloc=!1;var ti=il;var zl=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(Nn.zpp_pool==null?n=new Nn:(n=Nn.zpp_pool,Nn.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 Nn?Ze(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=ye().zpp_nape;if(e==null){if(this.zpp_inner.wrap_gravity!=null){this.zpp_inner.wrap_gravity.zpp_inner._inuse=!1;let l=this.zpp_inner.wrap_gravity;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),l.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let i=l.zpp_inner;l.zpp_inner.outer=null,l.zpp_inner=null;let o=l;o.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=o:n.util.ZPP_PubPool.poolVec2=o,n.util.ZPP_PubPool.nextVec2=o,o.zpp_disp=!0;let r=i;r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r,this.zpp_inner.wrap_gravity=null}}else{if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity();let l=this.zpp_inner.wrap_gravity;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=l.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=e.zpp_inner;i._validate!=null&&i._validate();let o=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=e.zpp_inner;r._validate!=null&&r._validate();let a=e.zpp_inner.y;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),o!=o||a!=a)throw new Error("Error: Vec2 components cannot be NaN");let c;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=l.zpp_inner;if(u._validate!=null&&u._validate(),l.zpp_inner.x==o){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=l.zpp_inner;h._validate!=null&&h._validate(),c=l.zpp_inner.y==a}else c=!1;if(!c){l.zpp_inner.x=o,l.zpp_inner.y=a;let h=l.zpp_inner;h._invalidate!=null&&h._invalidate(h)}if(e.zpp_inner.weak){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=e.zpp_inner;if(h._immutable)throw new Error("Error: Vec2 is immutable");if(h._isimmutable!=null&&h._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let x=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let b=e;b.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=b:n.util.ZPP_PubPool.poolVec2=b,n.util.ZPP_PubPool.nextVec2=b,b.zpp_disp=!0;let _=x;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=_}}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get shapes(){if(this.zpp_inner.wrap_shapes==null){let e=ye();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=ye().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 o=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let r=s;r.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=r:t.util.ZPP_PubPool.poolVec2=r,t.util.ZPP_PubPool.nextVec2=r,r.zpp_disp=!0;let a=o;a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=a,n.zpp_inner.wrap_gravity=null}}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");n.zpp_inner.wrap_gravity==null&&n.zpp_inner.getgravity();let s=n.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),l==null)throw new Error("Error: Cannot assign null Vec2");if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;o._validate!=null&&o._validate();let r=l.zpp_inner.x;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;a._validate!=null&&a._validate();let p=l.zpp_inner.y;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=s.zpp_inner;if(c._immutable)throw new Error("Error: Vec2 is immutable");if(c._isimmutable!=null&&c._isimmutable(),r!=r||p!=p)throw new Error("Error: Vec2 components cannot be NaN");let u;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=s.zpp_inner;if(h._validate!=null&&h._validate(),s.zpp_inner.x==r){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=s.zpp_inner;x._validate!=null&&x._validate(),u=s.zpp_inner.y==p}else u=!1;if(!u){s.zpp_inner.x=r,s.zpp_inner.y=p;let x=s.zpp_inner;x._invalidate!=null&&x._invalidate(x)}if(l.zpp_inner.weak){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=l.zpp_inner;if(x._immutable)throw new Error("Error: Vec2 is immutable");if(x._isimmutable!=null&&x._isimmutable(),l.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let b=l.zpp_inner;l.zpp_inner.outer=null,l.zpp_inner=null;let _=l;_.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=_:t.util.ZPP_PubPool.poolVec2=_,t.util.ZPP_PubPool.nextVec2=_,_.zpp_disp=!0;let d=b;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=d}}return n}toString(){return"{ density: "+this.zpp_inner.density*1e3+" viscosity: "+this.zpp_inner.viscosity+" gravity: "+String(this.zpp_inner.wrap_gravity)+" }"}};xs.__name__=["nape","phys","FluidProperties"];var Pi=xs;Nn._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(Pi.prototype);return t.zpp_inner=e,e.outer=t,t});var Oo=ye();Oo.phys.FluidProperties=Pi;var sl=class sl{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate ShapeType derp!")}static get CIRCLE(){return U.ShapeType_CIRCLE==null&&(U.internal=!0,U.ShapeType_CIRCLE=new sl,U.internal=!1),U.ShapeType_CIRCLE}static get POLYGON(){return U.ShapeType_POLYGON==null&&(U.internal=!0,U.ShapeType_POLYGON=new sl,U.internal=!1),U.ShapeType_POLYGON}toString(){return this===U.ShapeType_CIRCLE?"CIRCLE":this===U.ShapeType_POLYGON?"POLYGON":""}};sl.__name__=["nape","shape","ShapeType"];var Al=sl,So=ye();So.shape.ShapeType=Al;fl();var ll,ol;function oo(Y){ll=Y}function ro(Y){ol=Y}var ni=class Y extends ti{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&&ll?ll(e):t===1&&ol?ol(e):e.outer?e.outer:Ze(e,n=>{let l=Object.create(Y.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 yi.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 ll?ll(t):t}return null}get castPolygon(){let e=this.zpp_inner;if(e.type===1){let t=e.polygon.outer_zn;return ol?ol(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 Pi().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 Pi().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 Pi;t.setFluid(n.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new Pi().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=ye();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");Ms.validateShape(t);let n=e.zpp_inner;n._validate!=null&&n._validate();let l=Ee.shapeContains(t,n);return n.weak&&e.dispose(),l}copy(){let e=this.zpp_inner.copy();return e instanceof Y?e:Y._wrap(e)}toString(){return(this.zpp_inner.type===0?"Circle":"Polygon")+"#"+this.zpp_inner_i.id}_setupWorldCOM(){let e=ye(),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(xe.poolVec2==null?s=new e.geom.Vec2:(s=xe.poolVec2,xe.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===xe.nextVec2&&(xe.nextVec2=null)),s.zpp_inner==null){let i;le.zpp_pool==null?i=new le:(i=le.zpp_pool,le.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=n,i.y=l,s.zpp_inner=i,s.zpp_inner.outer=s}else s.zpp_inner.x=n,s.zpp_inner.y=l;s.zpp_inner.weak=!1,t.wrap_worldCOM=s,t.wrap_worldCOM.zpp_inner._inuse=!0,t.wrap_worldCOM.zpp_inner._immutable=!0,t.wrap_worldCOM.zpp_inner._validate=t.getworldCOM.bind(t)}};var Ti={SHAPES:1,JOINTS:2,CONTACTS:4,AABB:8,CENTER_OF_MASS:16,VELOCITIES:32,ALL:63};var Il=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 Vn(Y,e,t,n){let l=ye(),s=l.__zpp;class i extends Il{constructor(){super(),this.inner=new s.util[Y]}static get(r,a=!1){let p=new l[e][t];return p.zpp_inner.inner=r,a&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}}return i.internal=!1,i.__name__=["zpp_nape","util",n],i.prototype.__class__=i,s.util[n]=i,i}var jl=null,Vo=null,Bl=null;jl=Vn("ZNPList_ZPP_Constraint","constraint","ConstraintList","ZPP_ConstraintList");Vn("ZNPList_ZPP_Body","phys","BodyList","ZPP_BodyList");Vo=Vn("ZNPList_ZPP_Interactor","phys","InteractorList","ZPP_InteractorList");Vn("ZNPList_ZPP_Compound","phys","CompoundList","ZPP_CompoundList");Vn("ZNPList_ZPP_Listener","callbacks","ListenerList","ZPP_ListenerList");Vn("ZNPList_ZPP_CbType","callbacks","CbTypeList","ZPP_CbTypeList");Vn("ZNPList_ZPP_GeomPoly","geom","GeomPolyList","ZPP_GeomPolyList");Vn("ZNPList_RayResult","geom","RayResultList","ZPP_RayResultList");Vn("ZNPList_ConvexResult","geom","ConvexResultList","ZPP_ConvexResultList");Vn("ZNPList_ZPP_Edge","shape","EdgeList","ZPP_EdgeList");Vn("ZNPList_ZPP_Shape","shape","ShapeList","ZPP_ShapeList");Vn("ZNPList_ZPP_InteractionGroup","dynamics","InteractionGroupList","ZPP_InteractionGroupList");Bl=Vn("ZNPList_ZPP_Arbiter","dynamics","ArbiterList","ZPP_ArbiterList");function Un(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Kn(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Ln(Y){if(Y!=null&&Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}function An(Y){Y.zpp_inner.weak&&Y.dispose()}function Vs(Y,e,t,n,l){if(Ln(t),t==null)throw new Error("Error: Body::"+Y+" cannot be null");return e==null&&n!=null&&(n(),e=l()),e.set(t),e}function Pl(Y,e,t){return ot.get(Y,e,t)}function pn(Y,e){return U[Y]==null&&(U.internal=!0,U[Y]=e(),U.internal=!1),U[Y]}var Li=class Li extends ti{constructor(t,n){super();this.debugDraw=!0;let l=new En;this.zpp_inner=l,l.outer=this,l.outer_i=this,this.zpp_inner_i=l,this._inner=this,n!=null?(Ln(n),l.posx=Un(n),l.posy=Kn(n)):(l.posx=0,l.posy=0);let s=ye(),i;if(t==null?i=pn("BodyType_DYNAMIC",()=>new s.phys.BodyType):i=t,l.immutable_midstep("Body::type"),l.world)throw new Error("Error: Space::world is immutable");if(En.types[l.type]!==i){if(i==null)throw new Error("Error: Cannot use null BodyType");let o=ao(i,s);o===1&&l.space!=null&&(l.velx=0,l.vely=0,l.angvel=0),l.invalidate_type(),l.space!=null?l.space.transmitType(l,o):l.type=o}n!=null&&An(n),l.insert_cbtype(Cn.ANY_BODY.zpp_inner)}static _wrap(t){return t?t instanceof Li?t:t instanceof En?Ze(t,n=>{let l=Object.create(Li.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?Li._wrap(t.zpp_inner):Ze(t,n=>{let l=Object.create(Li.prototype);return l._inner=n,l}):null}get type(){return En.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(En.types[n.type]!==t){if(t==null)throw new Error("Error: Cannot use null BodyType");let l=ye(),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){Vs("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){Vs("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){Vs("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){Vs("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){Vs("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 zl(this.zpp_inner.wrap_shapes,ni._wrap)}get space(){return this.zpp_inner.space==null?null:As._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 us._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=ot.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=ot.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=ye(),n=pn("MassMode_DEFAULT",()=>new t.phys.MassMode),l=pn("MassMode_FIXED",()=>new t.phys.MassMode);return[n,l][this.zpp_inner.massMode]}set massMode(t){let n=ye();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=pn("MassMode_DEFAULT",()=>new n.phys.MassMode);this.zpp_inner.massMode=t===l?0:1,this.zpp_inner.invalidate_mass()}get inertiaMode(){let t=ye(),n=pn("InertiaMode_DEFAULT",()=>new t.phys.InertiaMode),l=pn("InertiaMode_FIXED",()=>new t.phys.InertiaMode);return[n,l][this.zpp_inner.inertiaMode]}set inertiaMode(t){let n=ye();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=pn("InertiaMode_FIXED",()=>new n.phys.InertiaMode);this.zpp_inner.inertiaMode=t===l?1:0,this.zpp_inner.invalidate_inertia()}get gravMassMode(){let t=ye(),n=pn("GravMassMode_DEFAULT",()=>new t.phys.GravMassMode),l=pn("GravMassMode_FIXED",()=>new t.phys.GravMassMode),s=pn("GravMassMode_SCALED",()=>new t.phys.GravMassMode);return[n,l,s][this.zpp_inner.gravMassMode]}set gravMassMode(t){let n=ye();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=pn("GravMassMode_SCALED",()=>new n.phys.GravMassMode);if(t===l)this.zpp_inner.gravMassMode=2;else{let s=pn("GravMassMode_DEFAULT",()=>new n.phys.GravMassMode);this.zpp_inner.gravMassMode=t===s?0:1}this.zpp_inner.invalidate_gravMass()}copy(){if(this.zpp_inner.world)throw new Error("Error: Space::world cannot be copied");return this.zpp_inner.copy()}toString(){let t=this.zpp_inner;return(t.world?"(space::world":"("+(t.type===2?"dynamic":t.type===1?"static":"kinematic"))+")#"+this.zpp_inner_i.id}integrate(t){if(t!==t)throw new Error("Cannot integrate by NaN time");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t===0)return this;let n=this.zpp_inner;n.sweepTime=0,n.sweep_angvel=n.angvel;let l=t-n.sweepTime;if(l!==0&&(n.sweepTime=t,n.posx+=n.velx*l,n.posy+=n.vely*l,n.angvel!==0)){let s=n.sweep_angvel*l;if(n.rot+=s,s*s>1e-4)n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot);else{let i=s*s,o=1-.5*i,r=1-i*i/8,a=(o*n.axisx+s*n.axisy)*r;n.axisy=(o*n.axisy-s*n.axisx)*r,n.axisx=a}}return po(n),n.zip_worldCOM=!0,n.zip_axis=!0,po(n),n.zip_worldCOM=!0,n.sweepTime=0,this}localPointToWorld(t,n=!1){if(Ln(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let l=Un(t),s=Kn(t),i=this.zpp_inner.axisy*l-this.zpp_inner.axisx*s,o=l*this.zpp_inner.axisx+s*this.zpp_inner.axisy;return An(t),Pl(i+this.zpp_inner.posx,o+this.zpp_inner.posy,n)}worldPointToLocal(t,n=!1){if(Ln(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let l=Un(t)-this.zpp_inner.posx,s=Kn(t)-this.zpp_inner.posy,i=l*this.zpp_inner.axisy+s*this.zpp_inner.axisx,o=s*this.zpp_inner.axisy-l*this.zpp_inner.axisx;return An(t),Pl(i,o,n)}localVectorToWorld(t,n=!1){if(Ln(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let l=Un(t),s=Kn(t),i=this.zpp_inner.axisy*l-this.zpp_inner.axisx*s,o=l*this.zpp_inner.axisx+s*this.zpp_inner.axisy;return An(t),Pl(i,o,n)}worldVectorToLocal(t,n=!1){if(Ln(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let l=Un(t),s=Kn(t),i=l*this.zpp_inner.axisy+s*this.zpp_inner.axisx,o=s*this.zpp_inner.axisy-l*this.zpp_inner.axisx;return An(t),Pl(i,o,n)}applyImpulse(t,n,l=!1){if(Ln(t),n!=null&&Ln(n),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot apply null impulse to Body");if(l&&this.isSleeping)return An(t),n!=null&&An(n),this;this.zpp_inner.validate_mass();let s=this.zpp_inner.imass,i=Un(t),o=Kn(t);if(this.zpp_inner.velx+=i*s,this.zpp_inner.vely+=o*s,n!=null){let r=Un(n)-this.zpp_inner.posx,a=Kn(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(o*r-i*a)*this.zpp_inner.iinertia,An(n)}return l||this.zpp_inner.type===2&&this.zpp_inner.wake(),An(t),this}applyAngularImpulse(t,n=!1){if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");return n&&this.isSleeping?this:(this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=t*this.zpp_inner.iinertia,n||this.zpp_inner.type===2&&this.zpp_inner.wake(),this)}setVelocityFromTarget(t,n,l){if(Ln(t),t==null)throw new Error("Cannot set velocity for null target position");if(l===0)throw new Error("deltaTime cannot be 0 for setVelocityFromTarget");let s=1/l;this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity(),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let i=t.sub(this.zpp_inner.wrap_pos,!0).muleq(s);this.zpp_inner.wrap_vel.set(i);let o=(n-this.zpp_inner.rot)*s;if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.angvel!==o){if(o!==o)throw new Error("Error: Body::angularVel cannot be NaN");if(this.zpp_inner.type===1)throw new Error("Error: A static object cannot be given a velocity");this.zpp_inner.angvel=o,this.zpp_inner.wake()}return An(t),this}translateShapes(t){if(this.zpp_inner.immutable_midstep("Body::translateShapes()"),Ln(t),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot displace by null Vec2");let n=t.zpp_inner.weak;t.zpp_inner.weak=!1;let l=this.zpp_inner.shapes.head;for(;l!=null;)l.elt.outer.translate(t),l=l.next;return t.zpp_inner.weak=n,An(t),this}rotateShapes(t){if(this.zpp_inner.immutable_midstep("Body::rotateShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.rotate(t),n=n.next;return this}scaleShapes(t,n){if(this.zpp_inner.immutable_midstep("Body::scaleShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let l=this.zpp_inner.shapes.head;for(;l!=null;)l.elt.outer.scale(t,n),l=l.next;return this}transformShapes(t){if(this.zpp_inner.immutable_midstep("Body::transformShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.transform(t),n=n.next;return this}align(){if(this.zpp_inner.immutable_midstep("Body::align()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.shapes.head==null)throw new Error("Error: Cannot align empty Body");this.zpp_inner.validate_localCOM();let t=ot.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-=Un(n),this.zpp_inner.pre_posy-=Kn(n)),t.dispose(),n.dispose(),this}rotate(t,n){if(Ln(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);Vs("position",this.zpp_inner.wrap_pos,i,()=>this.zpp_inner.setupPosition(),()=>this.zpp_inner.wrap_pos),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),s.dispose();{let o=this.zpp_inner.rot+n,r=this.zpp_inner;if(r.immutable_midstep("Body::rotation"),r.world)throw new Error("Error: Space::world is immutable");if(r.type===1&&r.space!=null)throw new Error("Error: Static objects cannot be rotated once inside a Space");if(r.rot!==o){if(o!==o)throw new Error("Error: Body::rotation cannot be NaN");r.rot=o,r.invalidate_rot(),r.wake()}}return t.zpp_inner.weak=l,An(t),this}setShapeMaterials(t){if(this.zpp_inner.immutable_midstep("Body::setShapeMaterials()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let l=n.elt.outer;if(l.zpp_inner.immutable_midstep("Shape::material"),t==null)throw new Error("Error: Cannot assign null as Shape material");l.zpp_inner.setMaterial(t.zpp_inner),l.zpp_inner.material.wrapper(),n=n.next}return this}setShapeFilters(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFilters()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let l=n.elt.outer;if(l.zpp_inner.immutable_midstep("Shape::filter"),t==null)throw new Error("Error: Cannot assign null as Shape filter");l.zpp_inner.setFilter(t.zpp_inner),l.zpp_inner.filter.wrapper(),n=n.next}return this}setShapeFluidProperties(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFluidProperties()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=ye(),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(Ln(t),t==null)throw new Error("Error: Cannot check containment of null point");let n=t.zpp_inner.weak;t.zpp_inner.weak=!1;let l=!1,s=this.zpp_inner.shapes.head;for(;s!=null;){if(s.elt.outer.contains(t)){l=!0;break}s=s.next}return t.zpp_inner.weak=n,An(t),l}connectedBodies(t=-1,n=null){return this.zpp_inner.connectedBodies(t,n)}interactingBodies(t=null,n=-1,l=null){let s;if(t==null)s=Ve.COL|Ve.SENSOR|Ve.FLUID;else{let i=ye(),o=pn("InteractionType_COLLISION",()=>new i.callbacks.InteractionType);if(t===o)s=Ve.COL;else{let r=pn("InteractionType_SENSOR",()=>new i.callbacks.InteractionType);s=t===r?Ve.SENSOR:Ve.FLUID}}return this.zpp_inner.interactingBodies(s,l)}normalImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ve.COL,l=>l.collisionArbiter.normalImpulse(this,n),t)}tangentImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ve.COL,l=>l.collisionArbiter.tangentImpulse(this,n),t)}totalContactsImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ve.COL,l=>l.collisionArbiter.totalImpulse(this,n),t)}rollingImpulse(t=null,n=!1){let l=0,i=this._getArbiters().iterator();for(;;){i.zpp_inner.zpp_inner.valmod();let o=i.zpp_inner.zpp_gl();if(i.zpp_critical=!0,i.zpp_i>=o){i.zpp_next=ye().dynamics.ArbiterIterator.zpp_pool,ye().dynamics.ArbiterIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1;let r=i.zpp_inner.at(i.zpp_i++),a=r.zpp_inner;a.type===Ve.COL&&(t!=null&&a.b2!==t.zpp_inner&&a.b1!==t.zpp_inner||(l+=r.collisionArbiter.rollingImpulse(this,n)))}return l}buoyancyImpulse(t=null){return this._arbiterImpulseQuery(Ve.FLUID,n=>n.fluidArbiter.buoyancyImpulse(this),t)}dragImpulse(t=null){return this._arbiterImpulseQuery(Ve.FLUID,n=>n.fluidArbiter.dragImpulse(this),t)}totalFluidImpulse(t=null){return this._arbiterImpulseQuery(Ve.FLUID,n=>n.fluidArbiter.totalImpulse(this),t)}constraintsImpulse(){let t=0,n=0,l=0,s=this.zpp_inner.constraints.head;for(;s!=null;){let o=s.elt.outer.bodyImpulse(this),r=o.zpp_inner;r._validate!=null&&r._validate(),t+=r.x,r._validate!=null&&r._validate(),n+=r.y,r._validate!=null&&r._validate(),l+=r.z,o.dispose(),s=s.next}return fi.get(t,n,l)}totalImpulse(t=null,n=!1){let l=0,s=0,i=0,r=this._getArbiters().iterator();for(;;){r.zpp_inner.zpp_inner.valmod();let p=r.zpp_inner.zpp_gl();if(r.zpp_critical=!0,r.zpp_i>=p){r.zpp_next=ye().dynamics.ArbiterIterator.zpp_pool,ye().dynamics.ArbiterIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let u=r.zpp_inner.at(r.zpp_i++).zpp_inner;if(u.type===Ve.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 fi.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=ot.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=ye().dynamics.ArbiterIterator.zpp_pool,ye().dynamics.ArbiterIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1;let _=s.zpp_inner.at(s.zpp_i++).totalImpulse(this),d=_.xy();n.addeq(d);let f=Un(d),m=Kn(d);t+=Math.sqrt(f*f+m*m),d.dispose(),_.dispose()}let o=this._getConstraints();o.zpp_inner.valmod();let r=ye().constraint.ConstraintIterator.get(o);for(;;){r.zpp_inner.zpp_inner.valmod();let x=r.zpp_inner;x.zpp_inner.valmod(),x.zpp_inner.zip_length&&(x.zpp_inner.zip_length=!1,x.zpp_inner.user_length=x.zpp_inner.inner.length);let b=x.zpp_inner.user_length;if(r.zpp_critical=!0,r.zpp_i>=b){r.zpp_next=ye().constraint.ConstraintIterator.zpp_pool,ye().constraint.ConstraintIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let d=r.zpp_inner.at(r.zpp_i++).bodyImpulse(this),f=d.xy();n.addeq(f);let m=Un(f),z=Kn(f);t+=Math.sqrt(m*m+z*z),f.dispose(),d.dispose()}let a=Un(n),p=Kn(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=Bl.get(this.zpp_inner.arbiters,!0)),this.zpp_inner.wrap_arbiters}_getConstraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=jl.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}_arbiterImpulseQuery(t,n,l){let s=0,i=0,o=0,a=this._getArbiters().iterator();for(;;){a.zpp_inner.zpp_inner.valmod();let p=a.zpp_inner.zpp_gl();if(a.zpp_critical=!0,a.zpp_i>=p){a.zpp_next=ye().dynamics.ArbiterIterator.zpp_pool,ye().dynamics.ArbiterIterator.zpp_pool=a,a.zpp_inner=null;break}a.zpp_critical=!1;let c=a.zpp_inner.at(a.zpp_i++),u=c.zpp_inner;if(u.type!==t||l!=null&&u.b2!==l.zpp_inner&&u.b1!==l.zpp_inner)continue;let h=n(c),x=h.zpp_inner;x._validate!=null&&x._validate(),s+=x.x,x._validate!=null&&x._validate(),i+=x.y,x._validate!=null&&x._validate(),o+=x.z,h.dispose()}return fi.get(s,i,o)}};Li.__name__=["nape","phys","Body"],Li.__super__=ti;var lt=Li;function ao(Y,e){let t=pn("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(Y===t)return 2;let n=pn("BodyType_KINEMATIC",()=>new e.phys.BodyType);return Y===n?3:1}function po(Y){let e=Y.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 Ao=ye();Ao.phys.Body=lt;lo(Y=>lt._wrap(Y));var As=class Y{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 bi(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 Y?e:e instanceof bi?e.outer?e.outer:Ze(e,t=>{let n=Object.create(Y.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?.outer?e.zpp_inner.outer:Ze(e,t=>{let n=Object.create(Y.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?(U.Broadphase_SWEEP_AND_PRUNE==null&&(U.internal=!0,U.Broadphase_SWEEP_AND_PRUNE=new(ye()).space.Broadphase,U.internal=!1),U.Broadphase_SWEEP_AND_PRUNE):(U.Broadphase_DYNAMIC_AABB_TREE==null&&(U.internal=!0,U.Broadphase_DYNAMIC_AABB_TREE=new(ye()).space.Broadphase,U.internal=!1),U.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 lt._wrap(this.zpp_inner.__static)}get arbiters(){if(this.zpp_inner.wrap_arbiters==null){let e=new qn;e.space=this.zpp_inner,this.zpp_inner.wrap_arbiters=e}return this.zpp_inner.wrap_arbiters}get listeners(){return this.zpp_inner.wrap_listeners}get timeStamp(){return this.zpp_inner.stamp}get elapsedTime(){return this.zpp_inner.time}step(e,t=10,n=10){if(e!==e)throw new Error("Error: deltaTime cannot be NaN");if(e<=0)throw new Error("Error: deltaTime must be strictly positive");if(t<=0)throw new Error("Error: must use atleast one velocity iteration");if(n<=0)throw new Error("Error: must use atleast one position iteration");this.zpp_inner.step(e,t,n)}clear(){if(this.zpp_inner.midstep)throw new Error("Error: Space::clear() cannot be called during space step()");this.zpp_inner.clear()}visitBodies(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitBodies");let t=ye(),n=this.zpp_inner.wrap_bodies;n.zpp_inner.valmod();let l=t.phys.BodyIterator.get(n);for(;;){l.zpp_inner.zpp_inner.valmod();let o=l.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=r){l.zpp_next=t.phys.BodyIterator.zpp_pool,t.phys.BodyIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,e(l.zpp_inner.at(l.zpp_i++))}let s=this.zpp_inner.wrap_compounds;s.zpp_inner.valmod();let i=t.phys.CompoundIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let o=i.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(i.zpp_critical=!0,i.zpp_i>=r){i.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1,i.zpp_inner.at(i.zpp_i++).visitBodies(e)}}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitConstraints");let t=ye(),n=this.zpp_inner.wrap_constraints;n.zpp_inner.valmod();let l=t.constraint.ConstraintIterator.get(n);for(;;){l.zpp_inner.zpp_inner.valmod();let o=l.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=r){l.zpp_next=t.constraint.ConstraintIterator.zpp_pool,t.constraint.ConstraintIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,e(l.zpp_inner.at(l.zpp_i++))}let s=this.zpp_inner.wrap_compounds;s.zpp_inner.valmod();let i=t.phys.CompoundIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let o=i.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(i.zpp_critical=!0,i.zpp_i>=r){i.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1,i.zpp_inner.at(i.zpp_i++).visitConstraints(e)}}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitCompounds");let t=ye(),n=this.zpp_inner.wrap_compounds;n.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(n);for(;;){l.zpp_inner.zpp_inner.valmod();let s=l.zpp_inner;s.zpp_inner.valmod(),s.zpp_inner.zip_length&&(s.zpp_inner.zip_length=!1,s.zpp_inner.user_length=s.zpp_inner.inner.length);let i=s.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=i){l.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1;let o=l.zpp_inner.at(l.zpp_i++);e(o),o.visitCompounds(e)}}interactionType(e,t){if(e==null||t==null)throw new Error("Error: Cannot evaluate interaction type for null shapes");let n=e.zpp_inner,l=t.zpp_inner;if((n.body!=null?n.body.outer:null)==null||(l.body!=null?l.body.outer:null)==null)throw new Error("Error: Cannot evaluate interaction type for shapes not part of a Body");let s=n.body,i=l.body;if(s.type==1&&i.type==1||s.outer==i.outer)return null;let o=!1,r=s.constraints.head;for(;r!=null;){let h=r.elt;if(h.ignore&&h.pair_exists(s.id,i.id)){o=!0;break}r=r.next}let a;if(o)a=!1;else{let h=n;for(;h!=null&&h.group==null;)h.ishape!=null?h=h.ishape.body:h.icompound!=null?h=h.icompound.compound:h=h.ibody.compound;let x=h==null?null:h.group,b;if(x==null)b=!1;else{let _=l;for(;_!=null&&_.group==null;)_.ishape!=null?_=_.ishape.body:_.icompound!=null?_=_.icompound.compound:_=_.ibody.compound;let d=_==null?null:_.group;if(d==null)b=!1;else{let f=!1;for(;x!=null&&d!=null;){if(x==d){f=x.ignore;break}x.depth<d.depth?d=d.group:x=x.group}b=f}}a=!b}if(!a)return null;let p=n.filter,c=l.filter,u=s.imass==0&&i.imass==0&&s.iinertia==0&&i.iinertia==0;return(n.sensorEnabled||l.sensorEnabled)&&(p.sensorMask&c.sensorGroup)!=0&&(c.sensorMask&p.sensorGroup)!=0?(U.InteractionType_SENSOR==null&&(U.internal=!0,U.InteractionType_SENSOR=new(ye()).callbacks.InteractionType,U.internal=!1),U.InteractionType_SENSOR):(n.fluidEnabled||l.fluidEnabled)&&(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0&&!u?(U.InteractionType_FLUID==null&&(U.internal=!0,U.InteractionType_FLUID=new(ye()).callbacks.InteractionType,U.internal=!1),U.InteractionType_FLUID):(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!u?(U.InteractionType_COLLISION==null&&(U.internal=!0,U.InteractionType_COLLISION=new(ye()).callbacks.InteractionType,U.internal=!1),U.InteractionType_COLLISION):null}shapesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes under a null point :)");let l=e.zpp_inner;l._validate!=null&&l._validate();let s=l.x;l._validate!=null&&l._validate();let i=l.y,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.shapesUnderPoint(s,i,o,n);return l.weak&&e.dispose(),r}bodiesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects under a null point :)");let l=e.zpp_inner;l._validate!=null&&l._validate();let s=l.x;l._validate!=null&&l._validate();let i=l.y,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.bodiesUnderPoint(s,i,o,n);return l.weak&&e.dispose(),r}shapesInAABB(e,t=!1,n=!0,l,s){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null AABB :)");let i=e.zpp_inner;if(i._validate!=null&&i._validate(),i.maxx-i.minx==0||i.maxy-i.miny==0)throw new Error("Error: Cannot evaluate shapes in degenerate AABB :/");let o=l==null?null:l.zpp_inner??l;return this.zpp_inner.shapesInAABB(e,n,t,o,s)}bodiesInAABB(e,t=!1,n=!0,l,s){if(e==null)throw new Error("Error: Cannot evaluate objects in a null AABB :)");let i=e.zpp_inner;if(i._validate!=null&&i._validate(),i.maxx-i.minx==0||i.maxy-i.miny==0)throw new Error("Error: Cannot evaluate objects in degenerate AABB :/");let o=l==null?null:l.zpp_inner??l;return this.zpp_inner.bodiesInAABB(e,n,t,o,s)}shapesInCircle(e,t,n=!1,l,s){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let i=l==null?null:l.zpp_inner??l,o=this.zpp_inner.shapesInCircle(e,t,n,i,s);return e.zpp_inner?.weak&&e.dispose(),o}bodiesInCircle(e,t,n=!1,l,s){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let i=l==null?null:l.zpp_inner??l,o=this.zpp_inner.bodiesInCircle(e,t,n,i,s);return e.zpp_inner?.weak&&e.dispose(),o}shapesInShape(e,t=!1,n,l){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null shapes :)");let s=e.zpp_inner;if((s.body!=null?s.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(s.type==1){let o=s.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new(ye()).shape.ValidationResult,U.internal=!1),o!=U.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.toString())}let i=n==null?null:n.zpp_inner??n;return this.zpp_inner.shapesInShape(s,t,i,l)}bodiesInShape(e,t=!1,n,l){if(e==null)throw new Error("Error: Cannot evaluate bodies in a null shapes :)");let s=e.zpp_inner;if((s.body!=null?s.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(s.type==1){let o=s.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new(ye()).shape.ValidationResult,U.internal=!1),o!=U.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.toString())}let i=n==null?null:n.zpp_inner??n;return this.zpp_inner.bodiesInShape(s,t,i,l)}shapesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let l=ye(),s=n??new l.shape.ShapeList,i=e.zpp_inner.wrap_shapes;i.zpp_inner.valmod();let o=l.shape.ShapeIterator.get(i);for(;;){o.zpp_inner.zpp_inner.valmod();let r=o.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=a){o.zpp_next=l.shape.ShapeIterator.zpp_pool,l.shape.ShapeIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let p=o.zpp_inner.at(o.zpp_i++);this.shapesInShape(p,!1,t,s)}return s}bodiesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let l=ye(),s=n??new l.phys.BodyList,i=e.zpp_inner.wrap_shapes;i.zpp_inner.valmod();let o=l.shape.ShapeIterator.get(i);for(;;){o.zpp_inner.zpp_inner.valmod();let r=o.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=a){o.zpp_next=l.shape.ShapeIterator.zpp_pool,l.shape.ShapeIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let p=o.zpp_inner.at(o.zpp_i++);this.bodiesInShape(p,!1,t,s)}return s}convexCast(e,t,n=!1,l){if(e==null)throw new Error("Error: Cannot cast null shape :)");let s=e.zpp_inner;if((s.body!=null?s.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexCast(s,t,l,n)}convexMultiCast(e,t,n=!1,l,s){if(e==null)throw new Error("Error: Cannot cast null shape :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexMultiCast(i,t,l,n,s)}rayCast(e,t=!1,n){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayCast(e,t,n)}rayMultiCast(e,t=!1,n,l){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayMultiCast(e,t,n,l)}debugDraw(e,t=Ti.ALL){if(e==null)throw new Error("Error: drawer cannot be null for Space::debugDraw");let n=(t&Ti.SHAPES)!==0,l=(t&Ti.JOINTS)!==0,s=(t&Ti.CONTACTS)!==0,i=(t&Ti.AABB)!==0,o=(t&Ti.CENTER_OF_MASS)!==0,r=(t&Ti.VELOCITIES)!==0,a=4283417591,p=4287669422,c=4294948685,u=4289058471,h=4293874512,x=1157627903,b=4294961979,_=4291728344;if(this.visitBodies(d=>{let f=d.zpp_inner,m=f.type===2,Z=f.type===1?p:m?a:c;if(n){let y=f.shapes.head;for(;y!=null;){let w=y.elt;if(w.type===0){let v=w.circle;w.zip_worldCOM&&w.validate_worldCOM();let P=w.worldCOMx,g=w.worldCOMy,k=v.radius,N=f.rot,E=P+Math.cos(N)*k,M=g+Math.sin(N)*k,C={x:P,y:g},L={x:E,y:M};m?e.drawSolidCircle(C,k,L,Z):e.drawCircle(C,k,Z)}else if(w.type===1){let v=w.polygon;v.zip_gverts&&v.validate_gverts();let P=[],g=v.gverts.next;for(;g!=null;)P.push({x:g.x,y:g.y}),g=g.next;P.length>=3&&(m?e.drawSolidPolygon(P,Z):e.drawPolygon(P,Z))}y=y.next}}if(i&&!f.world){let y=f.aabb,w=y.minx,v=y.miny,P=y.maxx,g=y.maxy;e.drawSegment({x:w,y:v},{x:P,y:v},x),e.drawSegment({x:P,y:v},{x:P,y:g},x),e.drawSegment({x:P,y:g},{x:w,y:g},x),e.drawSegment({x:w,y:g},{x:w,y:v},x)}if(o&&!f.world&&(f.validate_worldCOM(),e.drawPoint({x:f.worldCOMx,y:f.worldCOMy},b)),r&&!f.world&&m){let y=f.posx,w=f.posy;e.drawSegment({x:y,y:w},{x:y+f.velx,y:w+f.vely},_)}}),l&&this.visitConstraints(d=>{if(!d.debugDraw)return;let f=d.zpp_inner,m=f.b1,z=f.b2,Z=f.a1worldx??(m!=null?m.posx:0),y=f.a1worldy??(m!=null?m.posy:0),w=f.a2worldx??(z!=null?z.posx:0),v=f.a2worldy??(z!=null?z.posy:0);e.drawSegment({x:Z,y},{x:w,y:v},u),e.drawPoint({x:Z,y},u),e.drawPoint({x:w,y:v},u)}),s){let d=f=>{if(f==null)return;let m=f.head;for(;m!=null;){let z=m.elt;if(z!=null){let Z=z.nx,y=z.ny,w=z.contacts?.next;for(;w!=null;){let v=w.px,P=w.py;e.drawPoint({x:v,y:P},h),e.drawSegment({x:v,y:P},{x:v+Z*8,y:P+y*8},h),w=w.next}}m=m.next}};d(this.zpp_inner.c_arbiters_true),d(this.zpp_inner.c_arbiters_false)}}toString(){return`Space(bodies=${this.bodies.length})`}};var Is=class Is{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate BodyType derp!")}static get STATIC(){return U.BodyType_STATIC==null&&(U.internal=!0,U.BodyType_STATIC=new Is,U.internal=!1),U.BodyType_STATIC}static get DYNAMIC(){return U.BodyType_DYNAMIC==null&&(U.internal=!0,U.BodyType_DYNAMIC=new Is,U.internal=!1),U.BodyType_DYNAMIC}static get KINEMATIC(){return U.BodyType_KINEMATIC==null&&(U.internal=!0,U.BodyType_KINEMATIC=new Is,U.internal=!1),U.BodyType_KINEMATIC}toString(){return this===U.BodyType_STATIC?"STATIC":this===U.BodyType_DYNAMIC?"DYNAMIC":this===U.BodyType_KINEMATIC?"KINEMATIC":""}};Is.__name__=["nape","phys","BodyType"];var Tl=Is,Io=ye();Io.phys.BodyType=Tl;fl();var Di=class Di extends ti{constructor(){super();let e=new Wn;this.zpp_inner=e,e.outer=this,e.outer_i=this,this.zpp_inner_i=e,this._inner=this,e.insert_cbtype(Cn.ANY_COMPOUND.zpp_inner)}static _wrap(e){return e?e instanceof Di?e:e instanceof Wn?Ze(e,t=>{let n=Object.create(Di.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?Di._wrap(e.zpp_inner):Ze(e,t=>{let n=Object.create(Di.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:As._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 ot(0,0),n=0;if(this.visitBodies(l=>{if(l.zpp_inner.wrap_shapes.zpp_inner.inner.head!=null){if(l.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");l.zpp_inner.wrap_worldCOM==null&&l.zpp_inner.getworldCOM();let i=l.zpp_inner.wrap_worldCOM;if(l.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(l.zpp_inner.validate_mass(),l.zpp_inner.massMode==0&&l.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");let o=l.zpp_inner.cmass;t.addeq(i.mul(o,!0)),n+=o}}),n===0)throw new Error("Error: COM of an empty Compound is undefined silly");return t.muleq(1/n),e&&(t.zpp_inner.weak=!0),t}translate(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot translate by null Vec2");let t=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(n=>{n.zpp_inner.wrap_pos==null&&n.zpp_inner.setupPosition(),n.zpp_inner.wrap_pos.addeq(e)}),e.zpp_inner.weak=t,e.zpp_inner.weak&&e.dispose(),this}rotate(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot rotate about a null Vec2");if(t!==t)throw new Error("Error: Cannot rotate by NaN radians");let n=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(l=>{l.rotate(e,t)}),e.zpp_inner.weak=n,e.zpp_inner.weak&&e.dispose(),this}toString(){return"Compound"+this.zpp_inner.id}};Di.__name__=["nape","phys","Compound"],Di.__super__=ti;var js=Di;Wn._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(js.prototype);return t.zpp_inner=e,e.outer=t,e.outer_i=t,t.zpp_inner_i=e,t._inner=t,t});Object.defineProperty(js.prototype,"bodies",{get:function(){return this.zpp_inner.wrap_bodies},configurable:!0});Object.defineProperty(js.prototype,"constraints",{get:function(){return this.zpp_inner.wrap_constraints},configurable:!0});Object.defineProperty(js.prototype,"compounds",{get:function(){return this.zpp_inner.wrap_compounds},configurable:!0});var In=class In{get _inner(){return this}constructor(e=0,t=1,n=2,l=1,s=.001){let i;if(Ae.zpp_pool==null?i=new Ae:(i=Ae.zpp_pool,Ae.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(Ae.WAKE|Ae.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(Ae.WAKE|Ae.ANGDRAG|Ae.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(Ae.WAKE|Ae.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(Ae.WAKE|Ae.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(Ae.WAKE|Ae.ARBITERS)}}static _wrap(e){return e instanceof In?e:e?e instanceof Ae?Ze(e,t=>{let n=Object.create(In.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?In._wrap(e.zpp_inner):null:null}get elasticity(){return this.zpp_inner.elasticity}set elasticity(e){if(e!==this.zpp_inner.elasticity){if(e!==e)throw new Error("Error: Material::elasticity cannot be NaN");this.zpp_inner.elasticity=e,this.zpp_inner.invalidate(Ae.WAKE|Ae.ARBITERS)}}get dynamicFriction(){return this.zpp_inner.dynamicFriction}set dynamicFriction(e){if(e!==this.zpp_inner.dynamicFriction){if(e!==e)throw new Error("Error: Material::dynamicFriction cannot be NaN");if(e<0)throw new Error("Error: Material::dynamicFriction cannot be negative");this.zpp_inner.dynamicFriction=e,this.zpp_inner.invalidate(Ae.WAKE|Ae.ANGDRAG|Ae.ARBITERS)}}get staticFriction(){return this.zpp_inner.staticFriction}set staticFriction(e){if(e!==this.zpp_inner.staticFriction){if(e!==e)throw new Error("Error: Material::staticFriction cannot be NaN");if(e<0)throw new Error("Error: Material::staticFriction cannot be negative");this.zpp_inner.staticFriction=e,this.zpp_inner.invalidate(Ae.WAKE|Ae.ARBITERS)}}get density(){return this.zpp_inner.density*1e3}set density(e){if(e!==this.zpp_inner.density*1e3){if(e!==e)throw new Error("Error: Material::density cannot be NaN");if(e<0)throw new Error("Error: Material::density must be positive");this.zpp_inner.density=e/1e3,this.zpp_inner.invalidate(Ae.WAKE|Ae.PROPS)}}get rollingFriction(){return this.zpp_inner.rollingFriction}set rollingFriction(e){if(e!==this.zpp_inner.rollingFriction){if(e!==e)throw new Error("Error: Material::rollingFriction cannot be NaN");if(e<0)throw new Error("Error: Material::rollingFriction cannot be negative");this.zpp_inner.rollingFriction=e,this.zpp_inner.invalidate(Ae.WAKE|Ae.ARBITERS)}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}copy(){let e=new In(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 In(.4,.2,.38,.7,.005)}static steel(){return new In(.2,.57,.74,7.8,.001)}static ice(){return new In(.3,.03,.1,.9,1e-4)}static rubber(){return new In(.8,1,1.4,1.5,.01)}static glass(){return new In(.4,.4,.94,2.6,.002)}static sand(){return new In(-1,.45,.6,1.6,16)}};In.__name__=["nape","phys","Material"];var Ll=In;Ae._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(Ll.prototype);return t.zpp_inner=e,e.outer=t,t});var Bs=class Bs{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate GravMassMode derp!")}static get DEFAULT(){return U.GravMassMode_DEFAULT==null&&(U.internal=!0,U.GravMassMode_DEFAULT=new Bs,U.internal=!1),U.GravMassMode_DEFAULT}static get FIXED(){return U.GravMassMode_FIXED==null&&(U.internal=!0,U.GravMassMode_FIXED=new Bs,U.internal=!1),U.GravMassMode_FIXED}static get SCALED(){return U.GravMassMode_SCALED==null&&(U.internal=!0,U.GravMassMode_SCALED=new Bs,U.internal=!1),U.GravMassMode_SCALED}toString(){return this===U.GravMassMode_DEFAULT?"DEFAULT":this===U.GravMassMode_FIXED?"FIXED":this===U.GravMassMode_SCALED?"SCALED":""}};Bs.__name__=["nape","phys","GravMassMode"];var Dl=Bs,jo=ye();jo.phys.GravMassMode=Dl;var rl=class rl{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate InertiaMode derp!")}static get DEFAULT(){return U.InertiaMode_DEFAULT==null&&(U.internal=!0,U.InertiaMode_DEFAULT=new rl,U.internal=!1),U.InertiaMode_DEFAULT}static get FIXED(){return U.InertiaMode_FIXED==null&&(U.internal=!0,U.InertiaMode_FIXED=new rl,U.internal=!1),U.InertiaMode_FIXED}toString(){return this===U.InertiaMode_DEFAULT?"DEFAULT":this===U.InertiaMode_FIXED?"FIXED":""}};rl.__name__=["nape","phys","InertiaMode"];var Fl=rl,Bo=ye();Bo.phys.InertiaMode=Fl;var al=class al{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate MassMode derp!")}static get DEFAULT(){return U.MassMode_DEFAULT==null&&(U.internal=!0,U.MassMode_DEFAULT=new al,U.internal=!1),U.MassMode_DEFAULT}static get FIXED(){return U.MassMode_FIXED==null&&(U.internal=!0,U.MassMode_FIXED=new al,U.internal=!1),U.MassMode_FIXED}toString(){return this===U.MassMode_DEFAULT?"DEFAULT":this===U.MassMode_FIXED?"FIXED":""}};al.__name__=["nape","phys","MassMode"];var Gl=al,To=ye();To.phys.MassMode=Gl;var Fi=class Fi extends ni{constructor(e=50,t,n,l){super();let s=ye(),i=new Qn;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>si.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");i.radius=e,i.invalidate_radius()}if(t!=null){if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=t.zpp_inner;o._validate!=null&&o._validate(),i.localCOMx=o.x,o._validate!=null&&o._validate(),i.localCOMy=o.y,o.weak&&t.dispose()}else i.localCOMx=0,i.localCOMy=0;n==null?Ae.zpp_pool!=null?(i.material=Ae.zpp_pool,Ae.zpp_pool=i.material.next,i.material.next=null):i.material=new Ae:(i.immutable_midstep("Shape::material"),i.setMaterial(n.zpp_inner),i.material.wrapper()),l==null?yt.zpp_pool!=null?(i.filter=yt.zpp_pool,yt.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new yt:(i.immutable_midstep("Shape::filter"),i.setFilter(l.zpp_inner),i.filter.wrapper()),i.insert_cbtype(Cn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof Fi?e:e instanceof Qn?Ze(e,t=>{let n=Object.create(Fi.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?Fi._wrap(e.zpp_inner_zn):Ze(e,t=>{let n=Object.create(Fi.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=ye();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>si.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}};Fi.__name__=["nape","shape","Circle"],Fi.__super__=ni;var wl=Fi;oo(Y=>wl._wrap(Y));var Lo=ye();Lo.shape.Circle=wl;var wi=class wi extends ni{constructor(e,t,n){super();let l=ye();if(e==null)throw new Error("Error: localVerts cannot be null");let s=new $n;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 ot))throw new Error("Error: Array<Vec2> contains non Vec2 objects");if(i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");s.wrap_lverts==null&&s.getlverts();let o=i.zpp_inner;o._validate!=null&&o._validate();let r=o.x;o._validate!=null&&o._validate();let a=o.y,p=new ot(r,a);s.wrap_lverts.push(p)}for(let i=e.length-1;i>=0;i--)e[i].zpp_inner?.weak&&(e[i].dispose(),e.splice(i,1))}else if(e instanceof l.geom.Vec2List){let i=e,o=i.iterator();for(;;){o.zpp_inner.zpp_inner.valmod();let c=o.zpp_inner.zpp_gl();if(o.zpp_critical=!0,o.zpp_i>=c){o.zpp_next=l.geom.Vec2Iterator.zpp_pool,l.geom.Vec2Iterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let u=o.zpp_inner.at(o.zpp_i++);if(u==null)throw new Error("Error: Vec2List contains null objects");if(u.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");s.wrap_lverts==null&&s.getlverts();let h=u.zpp_inner;h._validate!=null&&h._validate();let x=h.x;h._validate!=null&&h._validate();let b=h.y,_=new ot(x,b);s.wrap_lverts.push(_)}i.zpp_inner._validate!=null&&i.zpp_inner._validate();let r=i.zpp_inner.inner,a=null,p=r.head;for(;p!=null;){let c=p.elt;c.outer?.zpp_inner?.weak?(p=r.erase(a),c.outer.zpp_inner.weak&&c.outer.dispose()):(a=p,p=p.next)}}else if(e instanceof l.geom.GeomPoly){let i=e.zpp_inner.vertices;if(i!=null){let o=i;do{s.wrap_lverts==null&&s.getlverts();let r=new ot(o.x,o.y);s.wrap_lverts.push(r),o=o.next}while(o!==i)}}else throw new Error("Error: Invalid type for polygon object, should be Array<Vec2>, Vec2List, GeomPoly or for flash10+ flash.Vector<Vec2>");t==null?Ae.zpp_pool!=null?(s.material=Ae.zpp_pool,Ae.zpp_pool=s.material.next,s.material.next=null):s.material=new Ae:(s.immutable_midstep("Shape::material"),s.setMaterial(t.zpp_inner),s.material.wrapper()),n==null?yt.zpp_pool!=null?(s.filter=yt.zpp_pool,yt.zpp_pool=s.filter.next,s.filter.next=null):s.filter=new yt:(s.immutable_midstep("Shape::filter"),s.setFilter(n.zpp_inner),s.filter.wrapper()),s.insert_cbtype(Cn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof wi?e:e instanceof $n?Ze(e,t=>{let n=Object.create(wi.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?wi._wrap(e.zpp_inner_zn):Ze(e,t=>{let n=Object.create(wi.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 ot(e,t);i.zpp_inner.weak=s;let o=new ot(e+n,t);o.zpp_inner.weak=s;let r=new ot(e+n,t+l);r.zpp_inner.weak=s;let a=new ot(e,t+l);return a.zpp_inner.weak=s,[i,o,r,a]}static box(e,t=e,n=!1){if(e!==e||t!==t)throw new Error("Error: Polygon.box cannot accept NaN arguments");return wi.rect(-e/2,-t/2,e,t,n)}static regular(e,t,n,l=0,s=!1){if(e!==e||t!==t||l!==l)throw new Error("Error: Polygon.regular cannot accept NaN arguments");let i=[],o=Math.PI*2/n;for(let r=0;r<n;r++){let a=r*o+l,p=Math.cos(a)*e,c=Math.sin(a)*t,u=new ot(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()}};wi.__name__=["nape","shape","Polygon"],wi.__super__=ni;var vl=wi;ro(Y=>vl._wrap(Y));var Do=ye();Do.shape.Polygon=vl;var pl=class pl{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate Broadphase derp!")}static get DYNAMIC_AABB_TREE(){return U.Broadphase_DYNAMIC_AABB_TREE==null&&(U.internal=!0,U.Broadphase_DYNAMIC_AABB_TREE=new pl,U.internal=!1),U.Broadphase_DYNAMIC_AABB_TREE}static get SWEEP_AND_PRUNE(){return U.Broadphase_SWEEP_AND_PRUNE==null&&(U.internal=!0,U.Broadphase_SWEEP_AND_PRUNE=new pl,U.internal=!1),U.Broadphase_SWEEP_AND_PRUNE}toString(){return this===U.Broadphase_DYNAMIC_AABB_TREE?"DYNAMIC_AABB_TREE":this===U.Broadphase_SWEEP_AND_PRUNE?"SWEEP_AND_PRUNE":""}};pl.__name__=["nape","space","Broadphase"];var co=pl;var _s=class _s{get _inner(){return this}constructor(e=1,t=-1,n=1,l=-1,s=1,i=-1){let o;yt.zpp_pool==null?o=new yt:(o=yt.zpp_pool,yt.zpp_pool=o.next,o.next=null),this.zpp_inner=o,o.outer=this,o.collisionGroup!=e&&(o.collisionGroup=e,o.invalidate()),o.collisionMask!=t&&(o.collisionMask=t,o.invalidate()),o.sensorGroup!=n&&(o.sensorGroup=n,o.invalidate()),o.sensorMask!=l&&(o.sensorMask=l,o.invalidate()),o.fluidGroup!=s&&(o.fluidGroup=s,o.invalidate()),o.fluidMask!=i&&(o.fluidMask=i,o.invalidate())}static _wrap(e){return e instanceof _s?e:e?e instanceof yt?Ze(e,t=>{let n=Object.create(_s.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?_s._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=ye();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 _s(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)+" }"}};_s.__name__=["nape","dynamics","InteractionFilter"];var Rl=_s;yt._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(Rl.prototype);return t.zpp_inner=e,e.outer=t,t});var Gi=class Gi{constructor(){this.debugDraw=!0;this._inner=this}static _wrap(e){return e==null?null:e instanceof Gi?e:e.zpp_inner?.outer instanceof Gi?e.zpp_inner.outer:Ze(e,t=>{let n=Object.create(Gi.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 Gi._wrap(this.zpp_inner.copy())}toString(){return"{Constraint}"}};Gi.__name__=["nape","constraint","Constraint"],Gi.zpp_internalAlloc=!1;var cn=Gi;var ql=class Y extends cn{constructor(e,t,n,l,s=1){super();let i=new qe;if(this.zpp_inner=i,i.outer=this,i.outer_zn=this,this._setBody1(e),this._setBody2(t),this.zpp_inner.immutable_midstep("AngleJoint::jointMin"),n!==n)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(i.jointMin!=n&&(i.jointMin=n,i.wake()),this.zpp_inner.immutable_midstep("AngleJoint::jointMax"),l!==l)throw new Error("Error: AngleJoint::jointMax cannot be NaN");if(i.jointMax!=l&&(i.jointMax=l,i.wake()),this.zpp_inner.immutable_midstep("AngleJoint::ratio"),s!==s)throw new Error("Error: AngleJoint::ratio cannot be NaN");i.ratio!=s&&(i.ratio=s,i.wake())}static _wrap(e){return e==null?null:e instanceof Y?e:e.zpp_inner?.outer instanceof Y?e.zpp_inner.outer:e instanceof qe?Ze(e,t=>{let n=Object.create(Y.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(Y.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:lt._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:lt._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=ye(),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=ye();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};qe._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(ql.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function ho(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.x}function uo(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.y}function gl(Y){Y.zpp_inner.weak&&Y.dispose()}var Wl=class Y extends cn{constructor(e,t,n,l,s,i){super();let o=new oi;if(this.zpp_inner=o,o.outer=this,o.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");let r=ho(n),a=uo(n);if(o.a1localx=r,o.a1localy=a,gl(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=ho(l),c=uo(l);if(o.a2localx=p,o.a2localy=c,gl(l),this.zpp_inner.immutable_midstep("DistanceJoint::jointMin"),s!==s)throw new Error("Error: DistanceJoint::jointMin cannot be NaN");if(s<0)throw new Error("Error: DistanceJoint::jointMin must be >= 0");if(o.jointMin!=s&&(o.jointMin=s,o.wake()),this.zpp_inner.immutable_midstep("DistanceJoint::jointMax"),i!==i)throw new Error("Error: DistanceJoint::jointMax cannot be NaN");if(i<0)throw new Error("Error: DistanceJoint::jointMax must be >= 0");o.jointMax!=i&&(o.jointMax=i,o.wake())}static _wrap(e){return e==null?null:e instanceof Y?e:e.zpp_inner?.outer instanceof Y?e.zpp_inner.outer:e instanceof oi?Ze(e,t=>{let n=Object.create(Y.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(Y.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:lt._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:lt._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),gl(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),gl(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=ye(),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=ye();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}};oi._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(Wl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Jl(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Ul(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Ts(Y){Y.zpp_inner.weak&&Y.dispose()}var Kl=class Y extends cn{constructor(e,t,n,l,s,i,o){super();let r=new ri;if(this.zpp_inner=r,r.outer=this,r.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(r.a1localx=Jl(n),r.a1localy=Ul(n),Ts(n),l?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(l==null)throw new Error("Error: Constraint::anchor2 cannot be null");if(r.a2localx=Jl(l),r.a2localy=Ul(l),Ts(l),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::direction cannot be null");if(r.nlocalx=Jl(s),r.nlocaly=Ul(s),r.zip_n=!0,Ts(s),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),i!==i)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(r.jointMin!=i&&(r.jointMin=i,r.wake()),this.zpp_inner.immutable_midstep("LineJoint::jointMax"),o!==o)throw new Error("Error: AngleJoint::jointMax cannot be NaN");r.jointMax!=o&&(r.jointMax=o,r.wake())}static _wrap(e){return e==null?null:e instanceof Y?e:e.zpp_inner?.outer instanceof Y?e.zpp_inner.outer:e instanceof ri?Ze(e,t=>{let n=Object.create(Y.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(Y.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:lt._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:lt._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),Ts(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),Ts(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),Ts(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=ye(),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=ye();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};ri._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(Kl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var Yl=class Y extends cn{constructor(e,t,n=0,l=1){super();let s=new ai;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 Y?e:e.zpp_inner?.outer instanceof Y?e.zpp_inner.outer:e instanceof ai?Ze(e,t=>{let n=Object.create(Y.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(Y.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:lt._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:lt._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=ye(),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=ye();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}};ai._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(Yl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function xo(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.x}function _o(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Cl(Y){Y.zpp_inner.weak&&Y.dispose()}var Xl=class Y extends cn{constructor(e,t,n,l){super();let s=new pi;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=xo(n),s.a1localy=_o(n),Cl(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=xo(l),s.a2localy=_o(l),Cl(l)}static _wrap(e){return e==null?null:e instanceof Y?e:e.zpp_inner?.outer instanceof Y?e.zpp_inner.outer:e instanceof pi?Ze(e,t=>{let n=Object.create(Y.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(Y.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:lt._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:lt._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),Cl(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),Cl(e)}impulse(){let e=ye(),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=ye();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,l=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=l)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};pi._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(Xl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function cl(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.x}function hl(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.y}function ul(Y){Y.zpp_inner.weak&&Y.dispose()}var Hl=class Y extends cn{constructor(e,t,n,l,s,i,o,r,a,p,c=1){super();let u=new ci;if(this.zpp_inner=u,u.outer=this,u.outer_zn=this,this._setBody1(e),this._setBody2(t),this._setBody3(n),this._setBody4(l),this._setAnchorInit(s,"anchor1",(h,x)=>{u.a1localx=h,u.a1localy=x}),this._setAnchorInit(i,"anchor2",(h,x)=>{u.a2localx=h,u.a2localy=x}),this._setAnchorInit(o,"anchor3",(h,x)=>{u.a3localx=h,u.a3localy=x}),this._setAnchorInit(r,"anchor4",(h,x)=>{u.a4localx=h,u.a4localy=x}),u.immutable_midstep("PulleyJoint::jointMin"),a!==a)throw new Error("Error: PulleyJoint::jointMin cannot be NaN");if(a<0)throw new Error("Error: PulleyJoint::jointMin must be >= 0");if(u.jointMin!=a&&(u.jointMin=a,u.wake()),u.immutable_midstep("PulleyJoint::jointMax"),p!==p)throw new Error("Error: PulleyJoint::jointMax cannot be NaN");if(p<0)throw new Error("Error: PulleyJoint::jointMax must be >= 0");if(u.jointMax!=p&&(u.jointMax=p,u.wake()),u.immutable_midstep("PulleyJoint::ratio"),c!==c)throw new Error("Error: PulleyJoint::ratio cannot be NaN");u.ratio!=c&&(u.ratio=c,u.wake())}_setAnchorInit(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::"+t+" cannot be null");n(cl(e),hl(e)),ul(e)}static _wrap(e){return e==null?null:e instanceof Y?e:e.zpp_inner?.outer instanceof Y?e.zpp_inner.outer:e instanceof ci?Ze(e,t=>{let n=Object.create(Y.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(Y.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:lt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}get body2(){return this.zpp_inner.b2==null?null:lt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}get body3(){return this.zpp_inner.b3==null?null:lt._wrap(this.zpp_inner.b3)}set body3(e){this._setBody3(e)}get body4(){return this.zpp_inner.b4==null?null:lt._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(),cl(e),hl(e),this.zpp_inner.wrap_a1.set(e),ul(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(),cl(e),hl(e),this.zpp_inner.wrap_a2.set(e),ul(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(),cl(e),hl(e),this.zpp_inner.wrap_a3.set(e),ul(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(),cl(e),hl(e),this.zpp_inner.wrap_a4.set(e),ul(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 $s(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):fi.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}};ci._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(Hl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function yo(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.x}function mo(Y){if(Y.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=Y.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Ml(Y){Y.zpp_inner.weak&&Y.dispose()}var Ql=class Y extends cn{constructor(e,t,n,l,s=0){super();let i=new hi;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=yo(n),i.a1localy=mo(n),Ml(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=yo(l),i.a2localy=mo(l),Ml(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 Y?e:e.zpp_inner?.outer instanceof Y?e.zpp_inner.outer:e instanceof hi?Ze(e,t=>{let n=Object.create(Y.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(Y.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:lt._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:lt._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),Ml(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),Ml(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=ye(),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=ye();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}};hi._wrapFn=Y=>Ze(Y,e=>{let t=Object.create(Ql.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});export{U as a,xe as b,fo as c,Rt as d,Cn as e,Wt as f,Rs as g,qs as h,yl as i,zs as j,qe as k,le as l,oi as m,ri as n,ai as o,pi as p,ci as q,Us as r,hi as s,Ve as t,ve as u,Ks as v,Ee as w,Pn as x,Ms as y,Xs as z,Hs as A,ml as B,wn as C,at as D,ye as E,fl as F,Ze as G,ot as H,fi as I,$s as J,us as K,Vl as L,Ss as M,so as N,lo as O,Ax as P,Ix as Q,ti as R,zl as S,Pi as T,Al as U,ni as V,Ti as W,As as X,jl as Y,Vo as Z,lt as _,Tl as $,js as aa,Ll as ba,Dl as ca,Fl as da,Gl as ea,wl as fa,vl as ga,co as ha,Rl as ia,cn as ja,ql as ka,Wl as la,Kl as ma,Yl as na,Xl as oa,Hl as pa,Ql as qa};
|
|
2
|
-
//# sourceMappingURL=chunk-3TXNIYBK.js.map
|