@newkrok/nape-js 3.19.0 → 3.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-KHH45HMB.cjs +2 -0
- package/dist/chunk-SNMC46IS.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/serialization/index.cjs +1 -1
- package/dist/serialization/index.js +1 -1
- package/dist/worker/index.cjs +4 -3
- package/dist/worker/index.js +3 -2
- package/package.json +3 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var ci=class{static POSINF(){return 1/0}static NEGINF(){return -1/0}};ci.FMAX=1e100;var gt=class gt{static Constraint(){return gt._Constraint++}static Interactor(){return gt._Interactor++}static CbType(){return gt._CbType++}static CbSet(){return gt._CbSet++}static Listener(){return gt._Listener++}static ZPP_SimpleVert(){return gt._ZPP_SimpleVert++}static ZPP_SimpleSeg(){return gt._ZPP_SimpleSeg++}static Space(){return gt._Space++}static InteractionGroup(){return gt._InteractionGroup++}};gt._Constraint=0,gt._Interactor=0,gt._CbType=0,gt._CbSet=0,gt._Listener=0,gt._ZPP_SimpleVert=0,gt._ZPP_SimpleSeg=0,gt._Space=0,gt._InteractionGroup=0;var yn=gt;var J=class{};J.GravMassMode_DEFAULT=null,J.GravMassMode_FIXED=null,J.GravMassMode_SCALED=null,J.InertiaMode_DEFAULT=null,J.InertiaMode_FIXED=null,J.MassMode_DEFAULT=null,J.MassMode_FIXED=null,J.BodyType_STATIC=null,J.BodyType_DYNAMIC=null,J.BodyType_KINEMATIC=null,J.ListenerType_BODY=null,J.ListenerType_CONSTRAINT=null,J.ListenerType_INTERACTION=null,J.ListenerType_PRE=null,J.PreFlag_ACCEPT=null,J.PreFlag_IGNORE=null,J.PreFlag_ACCEPT_ONCE=null,J.PreFlag_IGNORE_ONCE=null,J.CbEvent_BEGIN=null,J.CbEvent_ONGOING=null,J.CbEvent_END=null,J.CbEvent_WAKE=null,J.CbEvent_SLEEP=null,J.CbEvent_BREAK=null,J.CbEvent_PRE=null,J.InteractionType_COLLISION=null,J.InteractionType_SENSOR=null,J.InteractionType_FLUID=null,J.InteractionType_ANY=null,J.Winding_UNDEFINED=null,J.Winding_CLOCKWISE=null,J.Winding_ANTICLOCKWISE=null,J.ValidationResult_VALID=null,J.ValidationResult_DEGENERATE=null,J.ValidationResult_CONCAVE=null,J.ValidationResult_SELF_INTERSECTING=null,J.ShapeType_CIRCLE=null,J.ShapeType_POLYGON=null,J.ShapeType_CAPSULE=null,J.Broadphase_DYNAMIC_AABB_TREE=null,J.Broadphase_SWEEP_AND_PRUNE=null,J.Broadphase_SPATIAL_HASH=null,J.ArbiterType_COLLISION=null,J.ArbiterType_SENSOR=null,J.ArbiterType_FLUID=null,J.internal=false,J.id_ImmState_ACCEPT=1,J.id_ImmState_IGNORE=2,J.id_ImmState_ALWAYS=4,J.id_GravMassMode_DEFAULT=0,J.id_GravMassMode_FIXED=1,J.id_GravMassMode_SCALED=2,J.id_InertiaMode_DEFAULT=0,J.id_InertiaMode_FIXED=1,J.id_MassMode_DEFAULT=0,J.id_MassMode_FIXED=1,J.id_BodyType_STATIC=1,J.id_BodyType_DYNAMIC=2,J.id_BodyType_KINEMATIC=3,J.id_ListenerType_BODY=0,J.id_ListenerType_CONSTRAINT=1,J.id_ListenerType_INTERACTION=2,J.id_ListenerType_PRE=3,J.id_PreFlag_ACCEPT=1,J.id_PreFlag_IGNORE=2,J.id_PreFlag_ACCEPT_ONCE=3,J.id_PreFlag_IGNORE_ONCE=4,J.id_CbEvent_BEGIN=0,J.id_CbEvent_END=1,J.id_CbEvent_WAKE=2,J.id_CbEvent_SLEEP=3,J.id_CbEvent_BREAK=4,J.id_CbEvent_PRE=5,J.id_CbEvent_ONGOING=6,J.id_InteractionType_COLLISION=1,J.id_InteractionType_SENSOR=2,J.id_InteractionType_FLUID=4,J.id_InteractionType_ANY=7,J.id_Winding_UNDEFINED=0,J.id_Winding_CLOCKWISE=1,J.id_Winding_ANTICLOCKWISE=2,J.id_ValidationResult_VALID=0,J.id_ValidationResult_DEGENERATE=1,J.id_ValidationResult_CONCAVE=2,J.id_ValidationResult_SELF_INTERSECTING=3,J.id_ShapeType_CIRCLE=0,J.id_ShapeType_POLYGON=1,J.id_ShapeType_CAPSULE=2,J.id_Broadphase_DYNAMIC_AABB_TREE=0,J.id_Broadphase_SWEEP_AND_PRUNE=1,J.id_Broadphase_SPATIAL_HASH=2,J.id_ArbiterType_COLLISION=1,J.id_ArbiterType_SENSOR=2,J.id_ArbiterType_FLUID=4;var Us=class{static sqrt(e){return Math.sqrt(e)}static invsqrt(e){return 1/Math.sqrt(e)}static sqr(e){return e*e}static clamp2(e,t){let n=-t;return e<n?n:e>t?t:e}static clamp(e,t,n){return e<t?t:e>n?n:e}};var xe=class{};xe.poolGeomPoly=null,xe.nextGeomPoly=null,xe.poolVec2=null,xe.nextVec2=null,xe.poolVec3=null,xe.nextVec3=null;var ys=class{constructor(e,t){this.list=[];this.width=0;this.width=e,this.list=[];}resize(e,t,n){this.width=e;let s=e*t;for(let i=0;i<s;i++)this.list[i]=n;}get(e,t){return this.list[t*this.width+e]}set(e,t,n){return this.list[t*this.width+e]=n}},Ui=class extends ys{},Ki=class extends ys{},Yi=class extends ys{};var wn=class wn{constructor(){this.value=false;this.next=null;this.hnext=null;this.id=0;this.di=0;}static _alloc(){if(wn.zpp_pool==null)return new wn;let e=wn.zpp_pool;return wn.zpp_pool=e.next,e.next=null,e}static get(e,t,n){let s=wn._alloc();return s.id=e,s.di=t,s.value=n,s}static getpersist(e,t){let n=wn._alloc();return n.id=e,n.di=t,n}static ordered_get(e,t,n){if(e<=t){let s=wn._alloc();return s.id=e,s.di=t,s.value=n,s}else {let s=wn._alloc();return s.id=t,s.di=e,s.value=n,s}}static ordered_get_persist(e,t){if(e<=t){let n=wn._alloc();return n.id=e,n.di=t,n}else {let n=wn._alloc();return n.id=t,n.di=e,n}}free(){}alloc(){}};wn.zpp_pool=null;var Be=wn;var to=1048576,ki=1048575,Ei=106039,Ni=class{constructor(){this.cnt=0;this.cnt=0,this.table=new Array(to).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*Ei+t&ki];if(n==null)return null;if(n.id==e&&n.di==t)return n;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n}ordered_get(e,t){if(e>t){let s=e;e=t,t=s;}let n=this.table[e*Ei+t&ki];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*Ei+t&ki];if(n==null)return false;if(n.id==e&&n.di==t)return true;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n!=null}maybeAdd(e){let t=e.id*Ei+e.di&ki,n=this.table[t];n==null?(this.table[t]=e,e.hnext=null):(e.hnext=n.hnext,n.hnext=e),this.cnt++;}add(e){let t=e.id*Ei+e.di&ki,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*Ei+e.di&ki,n=this.table[t];if(n==e)this.table[t]=n.hnext;else if(n!=null){let s;for(;s=n,n=n.hnext,n!=null&&n!=e;);s.hnext=n.hnext;}e.hnext=null,this.cnt--;}hash(e,t){return e*Ei+t&ki}};var ms=class{constructor(){this.elt=null;this.next=null;}alloc(){}free(){this.elt=null;}elem(){return this.elt}};ms.zpp_pool=null;var _t=class{constructor(){this.head=null;this.length=0;this.modified=false;this.pushmod=false;}_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=true,this.pushmod=true;}add(e){let t=this._allocNode();return t.elt=e,t.next=this.head,this.head=t,this.modified=true,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=true,this.length++,n}pop(){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=true),this.modified=true,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=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),this._freeNode(t),this.modified=true,this.length--,this.pushmod=true,n}remove(e){let t=null,n=this.head;for(;n!=null;){if(n.elt==e){this.erase(t);break}t=n,n=n.next;}}try_remove(e){let t=null,n=this.head,s=false;for(;n!=null;){if(n.elt==e){this.erase(t),s=true;break}t=n,n=n.next;}return s}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){for(;this.head!=null;){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=true),this.modified=true,this.length--;}this.pushmod=true;}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=true,this.pushmod=true;}empty(){return this.head==null}size(){return this.length}has(e){let t=this.head;for(;t!=null;){if(t.elt==e)return true;t=t.next;}return false}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}};_t.prototype.inlined_add=_t.prototype.add;_t.prototype.inlined_insert=_t.prototype.insert;_t.prototype.inlined_pop=_t.prototype.pop;_t.prototype.inlined_pop_unsafe=_t.prototype.pop_unsafe;_t.prototype.inlined_erase=_t.prototype.erase;_t.prototype.inlined_remove=_t.prototype.remove;_t.prototype.inlined_try_remove=_t.prototype.try_remove;_t.prototype.inlined_clear=_t.prototype.clear;_t.prototype.inlined_has=_t.prototype.has;var bs=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=true;if(!this.empty()){let s=this.parent;for(;s.prev!=null;)s=s.prev;for(;s!=null;){let i=s.data;if(n){if(t==i)n=false;else if(!this.lt(i,t)&&this.lt(t,i))return false}else if(!this.lt(t,i)&&this.lt(i,t))return false;if(s.next!=null)for(s=s.next;s.prev!=null;)s=s.prev;else {for(;s.parent!=null&&s==s.parent.next;)s=s.parent;s=s.parent;}}}if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else {for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent;}}}return true}empty(){return this.parent==null}singular(){return this.parent!=null&&this.parent.prev==null?this.parent.next==null:false}size(){let e=0;if(!this.empty()){let t=this.parent;for(;t.prev!=null;)t=t.prev;for(;t!=null;)if(++e,t.next!=null)for(t=t.next;t.prev!=null;)t=t.prev;else {for(;t.parent!=null&&t==t.parent.next;)t=t.parent;t=t.parent;}}return e}has(e){return this.find(e)!=null}find(e){let t=this.parent;for(;t!=null&&t.data!=e;)this.lt(e,t.data)?t=t.prev:t=t.next;return t}has_weak(e){return this.find_weak(e)!=null}find_weak(e){let t=this.parent;for(;t!=null;)if(this.lt(e,t.data))t=t.prev;else if(this.lt(t.data,e))t=t.next;else break;return t}lower_bound(e){let t=null;if(!this.empty()){let n=this.parent;for(;n.prev!=null;)n=n.prev;for(;n!=null;){if(!this.lt(n.data,e)){t=n.data;break}if(n.next!=null)for(n=n.next;n.prev!=null;)n=n.prev;else {for(;n.parent!=null&&n==n.parent.next;)n=n.parent;n=n.parent;}}}return t}first(){let e=this.parent;for(;e.prev!=null;)e=e.prev;return e.data}pop_front(){let e=this.parent;for(;e.prev!=null;)e=e.prev;let t=e.data;return this.remove_node(e),t}remove(e){this.remove_node(this.find(e));}successor_node(e){if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else {let t=e;for(e=e.parent;e!=null&&e.prev!=t;)t=e,e=e.parent;}return e}predecessor_node(e){if(e.prev!=null)for(e=e.prev;e.next!=null;)e=e.next;else {let t=e;for(e=e.parent;e!=null&&e.next!=t;)t=e,e=e.parent;}return e}successor(e){let t=this.successor_node(this.find(e));return t==null?null:t.data}predecessor(e){let t=this.predecessor_node(this.find(e));return t==null?null:t.data}remove_node(e){if(e.next!=null&&e.prev!=null){let s=e.next;for(;s.prev!=null;)s=s.prev;let i=e.data;e.data=s.data,s.data=i,this.swapped!=null&&this.swapped(e.data,s.data),e=s;}let t=e.prev==null?e.next:e.prev;if(e.colour==1){if(e.prev!=null||e.next!=null)t.colour=1;else if(e.parent!=null){let s=e.parent;for(;;){s.colour++,s.prev.colour--,s.next.colour--;let i=s.prev;if(i.colour==-1){this.__fix_neg_red(i);break}else if(i.colour==0){if(i.prev!=null&&i.prev.colour==0){this.__fix_dbl_red(i.prev);break}if(i.next!=null&&i.next.colour==0){this.__fix_dbl_red(i.next);break}}let l=s.next;if(l.colour==-1){this.__fix_neg_red(l);break}else if(l.colour==0){if(l.prev!=null&&l.prev.colour==0){this.__fix_dbl_red(l.prev);break}if(l.next!=null&&l.next.colour==0){this.__fix_dbl_red(l.next);break}}if(s.colour==2)if(s.parent==null)s.colour=1;else {s=s.parent;continue}break}}}let n=e.parent;n==null?this.parent=t:n.prev==e?n.prev=t:n.next=t,t!=null&&(t.parent=n),e.parent=e.prev=e.next=null,this._freeNode(e);}clear(){if(this.parent!=null){let e=this.parent;for(;e!=null;)if(e.prev!=null)e=e.prev;else if(e.next!=null)e=e.next;else {let t=e.parent;t!=null&&(e==t.prev?t.prev=null:t.next=null,e.parent=null),this._freeNode(e),e=t;}this.parent=null;}}clear_with(e){if(this.parent==null)return;let t=this.parent;for(;t!=null;)if(t.prev!=null)t=t.prev;else if(t.next!=null)t=t.next;else {e(t.data);let n=t.parent;n!=null&&(t==n.prev?n.prev=null:n.next=null,t.parent=null),this._freeNode(t),t=n;}this.parent=null;}clear_node(e,t){t(e.data);let n=e.parent;return n!=null&&(e==n.prev?n.prev=null:n.next=null,e.parent=null),this._freeNode(e),n}__fix_neg_red(e){let t=e.parent,n;if(t.prev==e){let s=e.prev,i=e.next,l=i.prev,r=i.next;s.colour=0,e.colour=t.colour=1,e.next=l,l!=null&&(l.parent=e);let o=t.data;t.data=i.data,i.data=o,this.swapped!=null&&this.swapped(t.data,i.data),i.prev=r,r!=null&&(r.parent=i),i.next=t.next,t.next!=null&&(t.next.parent=i),t.next=i,i!=null&&(i.parent=t),n=s;}else {let s=e.next,i=e.prev,l=i.next,r=i.prev;s.colour=0,e.colour=t.colour=1,e.prev=l,l!=null&&(l.parent=e);let o=t.data;t.data=i.data,i.data=o,this.swapped!=null&&this.swapped(t.data,i.data),i.next=r,r!=null&&(r.parent=i),i.prev=t.prev,t.prev!=null&&(t.prev.parent=i),t.prev=i,i!=null&&(i.parent=t),n=s;}n.prev!=null&&n.prev.colour==0?this.__fix_dbl_red(n.prev):n.next!=null&&n.next.colour==0&&this.__fix_dbl_red(n.next);}__fix_dbl_red(e){for(;;){let t=e.parent,n=t.parent;if(n==null){t.colour=1;break}let s,i,l,r,o,a,p;t==n.prev?(l=n,p=n.next,e==t.prev?(s=e,i=t,r=e.prev,o=e.next,a=t.next):(s=t,i=e,r=t.prev,o=e.prev,a=e.next)):(s=n,r=n.prev,e==t.prev?(i=e,l=t,o=e.prev,a=e.next,p=t.next):(i=t,l=e,o=t.prev,a=e.prev,p=e.next));let c=n.parent;if(c==null?this.parent=i:c.prev==n?c.prev=i:c.next=i,i!=null&&(i.parent=c),s.prev=r,r!=null&&(r.parent=s),s.next=o,o!=null&&(o.parent=s),i.prev=s,s!=null&&(s.parent=i),i.next=l,l!=null&&(l.parent=i),l.prev=a,a!=null&&(a.parent=l),l.next=p,p!=null&&(p.parent=l),i.colour=n.colour-1,s.colour=1,l.colour=1,i==this.parent)this.parent.colour=1;else if(i.colour==0&&i.parent.colour==0){e=i;continue}break}}try_insert_bool(e){let t=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else {let n=this.parent;for(;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break}return t==null?false:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),true)}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}};bs.zpp_pool=null;var ui=null,Oi=null,Gn=null,xl=null;exports.c=null;var _l=null,Hi=null,en=null,Xi=null,Kn=null,Qi=null,$i=null,dl=null;function qe(j){let e=class extends ms{};return e.zpp_pool=null,e}function We(j,e){let t=class extends _t{};return t._NodeClass=e,t}function hi(j){let e=class extends bs{};return e.zpp_pool=null,e}function jl(j){j.util||(j.util={}),j.util.ZNPNode_ZPP_CbType=qe(),j.util.ZNPNode_ZPP_CallbackSet=qe(),j.util.ZNPNode_ZPP_Shape=qe(),j.util.ZNPNode_ZPP_Body=qe(),j.util.ZNPNode_ZPP_Constraint=qe(),j.util.ZNPNode_ZPP_Compound=qe(),j.util.ZNPNode_ZPP_Arbiter=qe(),j.util.ZNPNode_ZPP_InteractionListener=qe(),j.util.ZNPNode_ZPP_CbSet=qe(),j.util.ZNPNode_ZPP_Interactor=qe(),j.util.ZNPNode_ZPP_BodyListener=qe(),j.util.ZNPNode_ZPP_CbSetPair=qe(),j.util.ZNPNode_ZPP_ConstraintListener=qe(),j.util.ZNPNode_ZPP_CutInt=qe(),j.util.ZNPNode_ZPP_CutVert=qe(),j.util.ZNPNode_ZPP_PartitionVertex=qe(),j.util.ZNPNode_ZPP_SimplifyP=qe(),j.util.ZNPNode_ZPP_PartitionedPoly=qe(),j.util.ZNPNode_ZPP_GeomVert=qe(),j.util.ZNPNode_ZPP_SimpleVert=qe(),j.util.ZNPNode_ZPP_SimpleEvent=qe(),j.util.ZNPNode_ZPP_Vec2=qe(),j.util.ZNPNode_ZPP_AABBPair=qe(),j.util.ZNPNode_ZPP_Edge=qe(),j.util.ZNPNode_ZPP_AABBNode=qe(),j.util.ZNPNode_ZPP_Component=qe(),j.util.ZNPNode_ZPP_FluidArbiter=qe(),j.util.ZNPNode_ZPP_SensorArbiter=qe(),j.util.ZNPNode_ZPP_Listener=qe(),j.util.ZNPNode_ZPP_ColArbiter=qe(),j.util.ZNPNode_ZPP_InteractionGroup=qe(),j.util.ZNPNode_ZPP_ToiEvent=qe(),j.util.ZNPNode_ConvexResult=qe(),j.util.ZNPNode_ZPP_GeomPoly=qe(),j.util.ZNPNode_RayResult=qe();let e=j.util;j.util.ZNPList_ZPP_InteractionListener=We("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),j.util.ZNPList_ZPP_BodyListener=We("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),j.util.ZNPList_ZPP_ConstraintListener=We("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),j.util.ZNPList_ZPP_Constraint=We("ZPP_Constraint",e.ZNPNode_ZPP_Constraint),j.util.ZNPList_ZPP_Interactor=We("ZPP_Interactor",e.ZNPNode_ZPP_Interactor),j.util.ZNPList_ZPP_CbSet=We("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),j.util.ZNPList_ZPP_CbType=We("ZPP_CbType",e.ZNPNode_ZPP_CbType),j.util.ZNPList_ZPP_Vec2=We("ZPP_Vec2",e.ZNPNode_ZPP_Vec2),exports.c=j.util.ZNPList_ZPP_Vec2,j.util.ZNPList_ZPP_CallbackSet=We("ZPP_CallbackSet",e.ZNPNode_ZPP_CallbackSet),j.util.ZNPList_ZPP_Shape=We("ZPP_Shape",e.ZNPNode_ZPP_Shape),j.util.ZNPList_ZPP_Body=We("ZPP_Body",e.ZNPNode_ZPP_Body),j.util.ZNPList_ZPP_Compound=We("ZPP_Compound",e.ZNPNode_ZPP_Compound),j.util.ZNPList_ZPP_Arbiter=We("ZPP_Arbiter",e.ZNPNode_ZPP_Arbiter),j.util.ZNPList_ZPP_CbSetPair=We("ZPP_CbSetPair",e.ZNPNode_ZPP_CbSetPair),j.util.ZNPList_ZPP_CutInt=We("ZPP_CutInt",e.ZNPNode_ZPP_CutInt),j.util.ZNPList_ZPP_CutVert=We("ZPP_CutVert",e.ZNPNode_ZPP_CutVert),j.util.ZNPList_ZPP_PartitionVertex=We("ZPP_PartitionVertex",e.ZNPNode_ZPP_PartitionVertex),ui=j.util.ZNPList_ZPP_PartitionVertex,j.util.ZNPList_ZPP_SimplifyP=We("ZPP_SimplifyP",e.ZNPNode_ZPP_SimplifyP),xl=j.util.ZNPList_ZPP_SimplifyP,j.util.ZNPList_ZPP_PartitionedPoly=We("ZPP_PartitionedPoly",e.ZNPNode_ZPP_PartitionedPoly),Oi=j.util.ZNPList_ZPP_PartitionedPoly,j.util.ZNPList_ZPP_GeomVert=We("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),Gn=j.util.ZNPList_ZPP_GeomVert,j.util.ZNPList_ZPP_SimpleVert=We("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),dl=j.util.ZNPList_ZPP_SimpleEvent=We("ZPP_SimpleEvent",e.ZNPNode_ZPP_SimpleEvent),j.util.ZNPList_ZPP_AABBPair=We("ZPP_AABBPair",e.ZNPNode_ZPP_AABBPair),j.util.ZNPList_ZPP_Edge=We("ZPP_Edge",e.ZNPNode_ZPP_Edge),j.util.ZNPList_ZPP_AABBNode=We("ZPP_AABBNode",e.ZNPNode_ZPP_AABBNode),j.util.ZNPList_ZPP_Component=We("ZPP_Component",e.ZNPNode_ZPP_Component),j.util.ZNPList_ZPP_FluidArbiter=We("ZPP_FluidArbiter",e.ZNPNode_ZPP_FluidArbiter),j.util.ZNPList_ZPP_SensorArbiter=We("ZPP_SensorArbiter",e.ZNPNode_ZPP_SensorArbiter),j.util.ZNPList_ZPP_Listener=We("ZPP_Listener",e.ZNPNode_ZPP_Listener),j.util.ZNPList_ZPP_ColArbiter=We("ZPP_ColArbiter",e.ZNPNode_ZPP_ColArbiter),j.util.ZNPList_ZPP_InteractionGroup=We("ZPP_InteractionGroup",e.ZNPNode_ZPP_InteractionGroup),j.util.ZNPList_ZPP_ToiEvent=We("ZPP_ToiEvent",e.ZNPNode_ZPP_ToiEvent),j.util.ZNPList_ConvexResult=We("ConvexResult",e.ZNPNode_ConvexResult),j.util.ZNPList_ZPP_GeomPoly=We("ZPP_GeomPoly",e.ZNPNode_ZPP_GeomPoly),j.util.ZNPList_RayResult=We("RayResult",e.ZNPNode_RayResult),Hi=j.util.ZNPNode_RayResult,_l=j.util.ZNPList_ZPP_SimpleVert,j.util.ZPP_Set_ZPP_Body=hi(),j.util.ZPP_Set_ZPP_CbSetPair=hi(),j.util.ZPP_Set_ZPP_PartitionVertex=hi(),Qi=j.util.ZPP_Set_ZPP_PartitionVertex,j.util.ZPP_Set_ZPP_PartitionPair=hi(),$i=j.util.ZPP_Set_ZPP_PartitionPair,j.util.ZPP_Set_ZPP_SimpleVert=hi(),en=j.util.ZPP_Set_ZPP_SimpleVert,j.util.ZPP_Set_ZPP_SimpleSeg=hi(),Xi=j.util.ZPP_Set_ZPP_SimpleSeg,j.util.ZPP_Set_ZPP_SimpleEvent=hi(),Kn=j.util.ZPP_Set_ZPP_SimpleEvent,j.util.ZPP_Set_ZPP_CbSet=hi();}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=false;this.body=null;this.constraint=null;}wrapper_body(){return this.outer_body==null&&(zt.internal=true,this.outer_body=zt._createBodyCb(),zt.internal=false,this.outer_body.zpp_inner=this),this.outer_body}wrapper_con(){return this.outer_con==null&&(zt.internal=true,this.outer_con=zt._createConCb(),zt.internal=false,this.outer_con.zpp_inner=this),this.outer_con}wrapper_int(){let e=zt._zpp;return this.outer_int==null&&(zt.internal=true,this.outer_int=zt._createIntCb(),zt.internal=false,this.outer_int.zpp_inner=this),this.wrap_arbiters==null?this.wrap_arbiters=e.util.ZPP_ArbiterList.get(this.set.arbiters,true):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=true,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,true):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=true,this.wrap_arbiters.zpp_inner.at_ite=null;}};zt._nape=null,zt._zpp=null,zt.internal=false,zt.zpp_pool=null,zt._createBodyCb=null,zt._createConCb=null,zt._createIntCb=null,zt._createPreCb=null;var Tt=zt;var Jt=class Jt{constructor(){this.count=0;this.next=null;this.id=0;this.manager=null;this.cbpairs=null;this.zip_listeners=false;this.zip_bodylisteners=false;this.zip_conlisteners=false;this.interactors=null;this.wrap_interactors=null;this.constraints=null;this.wrap_constraints=null;let e=Jt._zpp;this.cbTypes=new e.util.ZNPList_ZPP_CbType,this.listeners=new e.util.ZNPList_ZPP_InteractionListener,this.zip_listeners=true,this.bodylisteners=new e.util.ZNPList_ZPP_BodyListener,this.zip_bodylisteners=true,this.conlisteners=new e.util.ZNPList_ZPP_ConstraintListener,this.zip_conlisteners=true,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.interactors=new e.util.ZNPList_ZPP_Interactor,this.id=e.ZPP_ID.CbSet(),this.cbpairs=new e.util.ZNPList_ZPP_CbSetPair;}static setlt(e,t){let n=e.cbTypes.head,s=t.cbTypes.head;for(;n!=null&&s!=null;){let i=n.elt,l=s.elt;if(i.id<l.id)return true;if(l.id<i.id)return false;n=n.next,s=s.next;}return s!=null?n==null:false}static get(e){let t;Jt.zpp_pool==null?t=new Jt:(t=Jt.zpp_pool,Jt.zpp_pool=t.next,t.next=null);let n=null,s=e.head;for(;s!=null;){let i=s.elt;n=t.cbTypes.insert(n,i),i.cbsets.add(t),s=s.next;}return t}static compatible(e,t,n){let s,i=e.options1,l=t.cbTypes;if(i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)){let r=e.options2,o=n.cbTypes;s=r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.excludes);}else s=false;if(s)return true;{let r=e.options2,o=t.cbTypes;if(r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.excludes)){let a=e.options1,p=n.cbTypes;return a.nonemptyintersection(p,a.includes)?!a.nonemptyintersection(p,a.excludes):false}else return false}}static findOrCreatePair(e,t){let n=Jt._zpp,s=null,l=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;l!=null;){let r=l.elt;if(r.a==e&&r.b==t||r.a==t&&r.b==e){s=r;break}l=l.next;}if(s==null){let r;n.callbacks.ZPP_CbSetPair.zpp_pool==null?r=new n.callbacks.ZPP_CbSetPair:(r=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=r.next,r.next=null),r.zip_listeners=true,Jt.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=false,s.__validate()),s}static empty_intersection(e,t){return Jt.findOrCreatePair(e,t).listeners.head==null}static single_intersection(e,t,n){let i=Jt.findOrCreatePair(e,t).listeners.head;return i!=null&&i.elt==n?i.next==null:false}static find_all(e,t,n,s){let l=Jt.findOrCreatePair(e,t).listeners.head;for(;l!=null;){let r=l.elt;r.event==n&&s(r),l=l.next;}}increment(){this.count++;}decrement(){return --this.count==0}invalidate_pairs(){let e=this.cbpairs.head;for(;e!=null;){let t=e.elt;t.zip_listeners=true,e=e.next;}}invalidate_listeners(){this.zip_listeners=true,this.invalidate_pairs();}validate_listeners(){this.zip_listeners&&(this.zip_listeners=false,this.realvalidate_listeners());}realvalidate_listeners(){let e=Jt._zpp;this.listeners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.listeners.head,l=n.listeners.head;for(;l!=null;){let r=l.elt;if(i!=null&&i.elt==r)l=l.next,s=i,i=i.next;else {let o;if(i!=null){let a=i.elt;o=r.precedence>a.precedence||r.precedence==a.precedence&&r.id>a.id;}else o=true;if(o){if(r.space==this.manager.space){let a=this.listeners,p;e.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?p=new e.util.ZNPNode_ZPP_InteractionListener:(p=e.util.ZNPNode_ZPP_InteractionListener.zpp_pool,e.util.ZNPNode_ZPP_InteractionListener.zpp_pool=p.next,p.next=null),p.elt=r;let c=p;s==null?(c.next=a.head,a.head=c):(c.next=s.next,s.next=c),a.pushmod=a.modified=true,a.length++,s=c;}l=l.next;}else s=i,i=i.next;}}t=t.next;}}invalidate_bodylisteners(){this.zip_bodylisteners=true;}validate_bodylisteners(){this.zip_bodylisteners&&(this.zip_bodylisteners=false,this.realvalidate_bodylisteners());}realvalidate_bodylisteners(){let e=Jt._zpp;this.bodylisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.bodylisteners.head,l=n.bodylisteners.head;for(;l!=null;){let r=l.elt;if(i!=null&&i.elt==r)l=l.next,s=i,i=i.next;else {let o;if(i!=null){let a=i.elt;o=r.precedence>a.precedence||r.precedence==a.precedence&&r.id>a.id;}else o=true;if(o){let a=r.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&r.space==this.manager.space){let p=this.bodylisteners,c;e.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_BodyListener:(c=e.util.ZNPNode_ZPP_BodyListener.zpp_pool,e.util.ZNPNode_ZPP_BodyListener.zpp_pool=c.next,c.next=null),c.elt=r;let h=c;s==null?(h.next=p.head,p.head=h):(h.next=s.next,s.next=h),p.pushmod=p.modified=true,p.length++,s=h;}l=l.next;}else s=i,i=i.next;}}t=t.next;}}invalidate_conlisteners(){this.zip_conlisteners=true;}validate_conlisteners(){this.zip_conlisteners&&(this.zip_conlisteners=false,this.realvalidate_conlisteners());}realvalidate_conlisteners(){let e=Jt._zpp;this.conlisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.conlisteners.head,l=n.conlisteners.head;for(;l!=null;){let r=l.elt;if(i!=null&&i.elt==r)l=l.next,s=i,i=i.next;else {let o;if(i!=null){let a=i.elt;o=r.precedence>a.precedence||r.precedence==a.precedence&&r.id>a.id;}else o=true;if(o){let a=r.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&r.space==this.manager.space){let p=this.conlisteners,c;e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_ConstraintListener:(c=e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=c.next,c.next=null),c.elt=r;let h=c;s==null?(h.next=p.head,p.head=h):(h.next=s.next,s.next=h),p.pushmod=p.modified=true,p.length++,s=h;}l=l.next;}else s=i,i=i.next;}}t=t.next;}}validate(){this.zip_listeners&&(this.zip_listeners=false,this.realvalidate_listeners()),this.zip_bodylisteners&&(this.zip_bodylisteners=false,this.realvalidate_bodylisteners()),this.zip_conlisteners&&(this.zip_conlisteners=false,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=true,this.bodylisteners.clear(),this.zip_bodylisteners=true,this.conlisteners.clear(),this.zip_conlisteners=true;this.cbTypes.head!=null;)this.cbTypes.pop_unsafe().cbsets.remove(this);}alloc(){}};Jt._zpp=null,Jt.zpp_pool=null;var dt=Jt;var Rn=class Rn{constructor(){this.a=null;this.b=null;this.next=null;this.zip_listeners=false;this.listeners=null;let e=Rn._zpp;this.listeners=new e.util.ZNPList_ZPP_InteractionListener;}static get(e,t){let n=Rn._zpp,s;return Rn.zpp_pool==null?s=new Rn:(s=Rn.zpp_pool,Rn.zpp_pool=s.next,s.next=null),s.zip_listeners=true,n.callbacks.ZPP_CbSet.setlt(e,t)?(s.a=e,s.b=t):(s.a=t,s.b=e),s}static setlt(e,t){let n=Rn._zpp;return n.callbacks.ZPP_CbSet.setlt(e.a,t.a)?true:e.a==t.a?n.callbacks.ZPP_CbSet.setlt(e.b,t.b):false}free(){this.a=this.b=null,this.listeners.clear();}alloc(){this.zip_listeners=true;}compatible(e){let t,n=e.options1,s=this.a.cbTypes;if(n.nonemptyintersection(s,n.includes)&&!n.nonemptyintersection(s,n.excludes)){let i=e.options2,l=this.b.cbTypes;t=i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes);}else t=false;if(t)return true;{let i=e.options2,l=this.a.cbTypes;if(i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)){let r=e.options1,o=this.b.cbTypes;return r.nonemptyintersection(o,r.includes)?!r.nonemptyintersection(o,r.excludes):false}else return false}}invalidate(){this.zip_listeners=true;}validate(){this.zip_listeners&&(this.zip_listeners=false,this.__validate());}__validate(){this.listeners.clear();let e=this.a.listeners.head,t=this.b.listeners.head;for(;e!=null&&t!=null;){let n=e.elt,s=t.elt;if(n==s){let i,l,r=n.options1,o=this.a.cbTypes;if(r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.excludes)){let a=n.options2,p=this.b.cbTypes;l=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes);}else l=false;if(l)i=true;else {let a=n.options2,p=this.a.cbTypes;if(a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)){let c=n.options1,h=this.b.cbTypes;i=c.nonemptyintersection(h,c.includes)&&!c.nonemptyintersection(h,c.excludes);}else i=false;}i&&this.listeners.add(n),e=e.next,t=t.next;}else n.precedence>s.precedence||n.precedence==s.precedence&&n.id>s.id?e=e.next:t=t.next;}}empty_intersection(){return this.listeners.head==null}single_intersection(e){let t=this.listeners.head;return t!=null&&t.elt==e?t.next==null:false}forall(e,t){let n=this.listeners.head;for(;n!=null;){let s=n.elt;s.event==e&&t(s),n=n.next;}}};Rn._zpp=null,Rn.zpp_pool=null;var Ne=Rn;var pn=class pn{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=pn._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){pn.ANY_SHAPE=new e.callbacks.CbType,pn.ANY_BODY=new e.callbacks.CbType,pn.ANY_COMPOUND=new e.callbacks.CbType,pn.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=pn._zpp,n=null,s=this.listeners.head;for(;s!=null;){let o=s.elt;if(e.precedence>o.precedence||e.precedence===o.precedence&&e.id>o.id)break;n=s,s=s.next;}let i=this.listeners,l;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_InteractionListener:(l=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=true,i.length++;let r=this.cbsets.head;for(;r!=null;)r.elt.zip_listeners=true,r.elt.invalidate_pairs(),r=r.next;}removeint(e){this.listeners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_listeners=true,t.elt.invalidate_pairs(),t=t.next;}invalidateint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_listeners=true,e.elt.invalidate_pairs(),e=e.next;}addbody(e){let t=pn._zpp,n=null,s=this.bodylisteners.head;for(;s!=null;){let o=s.elt;if(e.precedence>o.precedence||e.precedence===o.precedence&&e.id>o.id)break;n=s,s=s.next;}let i=this.bodylisteners,l;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_BodyListener:(l=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=true,i.length++;let r=this.cbsets.head;for(;r!=null;)r.elt.zip_bodylisteners=true,r=r.next;}removebody(e){this.bodylisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_bodylisteners=true,t=t.next;}invalidatebody(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_bodylisteners=true,e=e.next;}addconstraint(e){let t=pn._zpp,n=null,s=this.conlisteners.head;for(;s!=null;){let o=s.elt;if(e.precedence>o.precedence||e.precedence===o.precedence&&e.id>o.id)break;n=s,s=s.next;}let i=this.conlisteners,l;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_ConstraintListener:(l=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=true,i.length++;let r=this.cbsets.head;for(;r!=null;)r.elt.zip_conlisteners=true,r=r.next;}removeconstraint(e){this.conlisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_conlisteners=true,t=t.next;}invalidateconstraint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_conlisteners=true,e=e.next;}};pn._zpp=null,pn.ANY_SHAPE=null,pn.ANY_BODY=null,pn.ANY_COMPOUND=null,pn.ANY_CONSTRAINT=null;var cn=pn;var ti=class ti{constructor(){this.space=null;this.interaction=null;this.constraint=null;this.body=null;this.precedence=0;this.event=0;this.type=0;this.id=0;this.outer=null;this.id=yn.Listener();}static setlt(e,t){return e.precedence<=t.precedence?e.precedence==t.precedence?e.id>t.id:false:true}swapEvent(e){}invalidate_precedence(){}addedToSpace(){}removedFromSpace(){}static _initEnums(e,t){let n=()=>{t.internal=true;let i=new e.callbacks.ListenerType;return t.internal=false,i};t.ListenerType_BODY==null&&(t.ListenerType_BODY=n()),t.ListenerType_CONSTRAINT==null&&(t.ListenerType_CONSTRAINT=n()),t.ListenerType_INTERACTION==null&&(t.ListenerType_INTERACTION=n()),t.ListenerType_PRE==null&&(t.ListenerType_PRE=n()),ti.types=[t.ListenerType_BODY,t.ListenerType_CONSTRAINT,t.ListenerType_INTERACTION,t.ListenerType_PRE];let s=()=>{t.internal=true;let i=new e.callbacks.CbEvent;return t.internal=false,i};t.CbEvent_BEGIN==null&&(t.CbEvent_BEGIN=s()),t.CbEvent_END==null&&(t.CbEvent_END=s()),t.CbEvent_WAKE==null&&(t.CbEvent_WAKE=s()),t.CbEvent_SLEEP==null&&(t.CbEvent_SLEEP=s()),t.CbEvent_BREAK==null&&(t.CbEvent_BREAK=s()),t.CbEvent_PRE==null&&(t.CbEvent_PRE=s()),t.CbEvent_ONGOING==null&&(t.CbEvent_ONGOING=s()),ti.events=[t.CbEvent_BEGIN,t.CbEvent_END,t.CbEvent_WAKE,t.CbEvent_SLEEP,t.CbEvent_BREAK,t.CbEvent_PRE,t.CbEvent_ONGOING];}};ti._nape=null,ti._zpp=null,ti.internal=false,ti.types=[],ti.events=[];var Lt=ti;var Ks=class extends Lt{constructor(t,n,s){super();this.handler=null;this.options=null;this.outer_zn=null;this.event=n,this.handler=s,this.body=this,this.type=0,this.options=t.zpp_inner;}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=Lt._zpp;this.options.handler=(s,i,l)=>this.cbtype_change(s,i,l);let n=this.options.includes.head;for(;n!=null;){let s=n.elt,i=null,l=s.bodylisteners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next;}let r=s.bodylisteners,o;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?o=new t.util.ZNPNode_ZPP_BodyListener:(o=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=o.next,o.next=null),o.elt=this;let a=o;i==null?(a.next=r.head,r.head=a):(a.next=i.next,i.next=a),r.pushmod=r.modified=true,r.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_bodylisteners=true,p=p.next;}n=n.next;}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.bodylisteners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_bodylisteners=true,s=s.next;}t=t.next;}this.options.handler=null;}cbtype_change(t,n,s){this.removedFromSpace();let i=this.options;n?s?i.effect_change(t,true,true):i.includes.remove(t):s?i.effect_change(t,false,true):i.excludes.remove(t),this.addedToSpace();}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace());}swapEvent(t){if(t!=2&&t!=3)throw new Error("Error: BodyListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace();}};var Ys=class extends Lt{constructor(t,n,s){super();this.handler=null;this.options=null;this.outer_zn=null;this.event=n,this.handler=s,this.constraint=this,this.type=1,this.options=t.zpp_inner;}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=Lt._zpp;this.options.handler=(s,i,l)=>this.cbtype_change(s,i,l);let n=this.options.includes.head;for(;n!=null;){let s=n.elt,i=null,l=s.conlisteners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next;}let r=s.conlisteners,o;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?o=new t.util.ZNPNode_ZPP_ConstraintListener:(o=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=o.next,o.next=null),o.elt=this;let a=o;i==null?(a.next=r.head,r.head=a):(a.next=i.next,i.next=a),r.pushmod=r.modified=true,r.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_conlisteners=true,p=p.next;}n=n.next;}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.conlisteners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_conlisteners=true,s=s.next;}t=t.next;}this.options.handler=null;}cbtype_change(t,n,s){this.removedFromSpace();let i=this.options;n?s?i.effect_change(t,true,true):i.includes.remove(t):s?i.effect_change(t,false,true):i.excludes.remove(t),this.addedToSpace();}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace());}swapEvent(t){if(t!=2&&t!=3&&t!=4)throw new Error("Error: ConstraintListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace();}};var Ct=class Ct extends Lt{constructor(t,n,s,i){super();this.outer_zni=null;this.outer_znp=null;this.itype=0;this.handleri=null;this.allowSleepingCallbacks=false;this.pure=false;this.handlerp=null;this.type=i,this.interaction=this,this.event=s,this.options1=t.zpp_inner,this.options2=n.zpp_inner,this.allowSleepingCallbacks=false;}setInteractionType(t){this.itype=t;}wake(){let t=this.options1.includes.head,n=this.options2.includes.head;for(;t!=null&&n!=null;){let s=t.elt,i=n.elt;if(s==i){let l=s.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;t=t.next,n=n.next;}else if(s.id<i.id){let l=s.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;t=t.next;}else {let l=i.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;n=n.next;}}for(;t!=null;){let s=t.elt.interactors.head;for(;s!=null;)s.elt.wake(),s=s.next;t=t.next;}for(;n!=null;){let s=n.elt.interactors.head;for(;s!=null;)s.elt.wake(),s=s.next;n=n.next;}}CbSetset(t,n,s){let i=Lt._zpp,l=Ct.UCbSet,r=Ct.VCbSet,o=Ct.WCbSet,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,h=p.elt;if(c==h){let u=this._allocCbSetNode(i);u.elt=c,u.next=o.head,o.head=u,o.modified=true,o.length++,a=a.next,p=p.next;}else if(i.callbacks.ZPP_CbSet.setlt(c,h)){let u=this._allocCbSetNode(i);u.elt=c,u.next=l.head,l.head=u,l.modified=true,l.length++,a=a.next;}else {let u=this._allocCbSetNode(i);u.elt=h,u.next=r.head,r.head=u,r.modified=true,r.length++,p=p.next;}}for(;a!=null;){let c=this._allocCbSetNode(i);c.elt=a.elt,c.next=l.head,l.head=c,l.modified=true,l.length++,a=a.next;}for(;p!=null;){let c=this._allocCbSetNode(i);c.elt=p.elt,c.next=r.head,r.head=c,r.modified=true,r.length++,p=p.next;}for(;l.head!=null;){let c=l.pop_unsafe(),h=n.head;for(;h!=null;)s(c,h.elt),h=h.next;}for(;r.head!=null;){let c=r.pop_unsafe(),h=o.head;for(;h!=null;)s(c,h.elt),h=h.next;}for(;o.head!=null;){let c=o.pop_unsafe();s(c,c);let h=o.head;for(;h!=null;)s(c,h.elt),h=h.next;}}CbTypeset(t,n,s){let i=Lt._zpp,l=Ct.UCbType,r=Ct.VCbType,o=Ct.WCbType,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,h=p.elt;if(c==h){let u=this._allocCbTypeNode(i);u.elt=c,u.next=o.head,o.head=u,o.modified=true,o.length++,a=a.next,p=p.next;}else if(c.id<h.id){let u=this._allocCbTypeNode(i);u.elt=c,u.next=l.head,l.head=u,l.modified=true,l.length++,a=a.next;}else {let u=this._allocCbTypeNode(i);u.elt=h,u.next=r.head,r.head=u,r.modified=true,r.length++,p=p.next;}}for(;a!=null;){let c=this._allocCbTypeNode(i);c.elt=a.elt,c.next=l.head,l.head=c,l.modified=true,l.length++,a=a.next;}for(;p!=null;){let c=this._allocCbTypeNode(i);c.elt=p.elt,c.next=r.head,r.head=c,r.modified=true,r.length++,p=p.next;}for(;l.head!=null;){let c=l.pop_unsafe(),h=n.head;for(;h!=null;)s(c,h.elt),h=h.next;}for(;r.head!=null;){let c=r.pop_unsafe(),h=o.head;for(;h!=null;)s(c,h.elt),h=h.next;}for(;o.head!=null;){let c=o.pop_unsafe();s(c,c);let h=o.head;for(;h!=null;)s(c,h.elt),h=h.next;}}with_uniquesets(t){let n=Lt._zpp,s;if(n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool==null?s=new n.util.ZPP_Set_ZPP_CbSetPair:(s=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=s.next,s.next=null),s.lt=n.callbacks.ZPP_CbSetPair.setlt,this.CbTypeset(this.options1.includes,this.options2.includes,(l,r)=>{this.CbSetset(l.cbsets,r.cbsets,(o,a)=>{if(o.validate(),a.validate(),n.callbacks.ZPP_CbSet.single_intersection(o,a,this)){let p;n.callbacks.ZPP_CbSetPair.zpp_pool==null?p=new n.callbacks.ZPP_CbSetPair:(p=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=p.next,p.next=null),p.zip_listeners=true,n.callbacks.ZPP_CbSet.setlt(o,a)?(p.a=o,p.b=a):(p.a=a,p.b=o),s.try_insert(p);}});}),s.parent!=null){let l=s.parent;for(;l!=null;)if(l.prev!=null)l=l.prev;else if(l.next!=null)l=l.next;else {let r=l.data;t?this.space.freshListenerType(r.a,r.b):this.space.nullListenerType(r.a,r.b);let o=r;o.a=o.b=null,o.listeners.clear(),o.next=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=o;let a=l.parent;a!=null&&(l==a.prev?a.prev=null:a.next=null,l.parent=null);let p=l;p.data=null,p.lt=null,p.swapped=null,p.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=p,l=a;}s.parent=null;}let i=s;i.data=null,i.lt=null,i.swapped=null,i.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=i;}with_union(t){let n=this.options1.includes.head,s=this.options2.includes.head;for(;n!=null&&s!=null;){let i=n.elt,l=s.elt;i==l?(t(i),n=n.next,s=s.next):i.id<l.id?(t(i),n=n.next):(t(l),s=s.next);}for(;n!=null;)t(n.elt),n=n.next;for(;s!=null;)t(s.elt),s=s.next;}addedToSpace(){let t=Lt._zpp,n=this.type==3;this.with_union(s=>{let i=null,l=s.listeners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next;}let r=s.listeners,o;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?o=new t.util.ZNPNode_ZPP_InteractionListener:(o=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=o.next,o.next=null),o.elt=this;let a=o;i==null?(a.next=r.head,r.head=a):(a.next=i.next,i.next=a),r.pushmod=r.modified=true,r.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_listeners=true,c.invalidate_pairs(),p=p.next;}if(n){let c=s.interactors.head;for(;c!=null;)c.elt.wake(),c=c.next;}}),this.options1.handler=(s,i,l)=>this.cbtype_change1(s,i,l),this.options2.handler=(s,i,l)=>this.cbtype_change2(s,i,l),this.with_uniquesets(true);}removedFromSpace(){this.with_uniquesets(false);let t=this.type==3;this.with_union(n=>{n.listeners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_listeners=true,i.invalidate_pairs(),s=s.next;}if(t){let i=n.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next;}}),this.options1.handler=null,this.options2.handler=null;}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace());}cbtype_change1(t,n,s){this.cbtype_change(this.options1,t,n,s);}cbtype_change2(t,n,s){this.cbtype_change(this.options2,t,n,s);}cbtype_change(t,n,s,i){this.removedFromSpace(),s?i?t.effect_change(n,true,true):t.includes.remove(n):i?t.effect_change(n,false,true):t.excludes.remove(n),this.addedToSpace();}swapEvent(t){if(this.type==3)throw new Error("Error: PreListener event can only be PRE");if(t!=0&&t!=1&&t!=6)throw new Error("Error: InteractionListener event must be either BEGIN, END, ONGOING");this.removedFromSpace(),this.event=t,this.addedToSpace();}_allocCbSetNode(t){let n;return t.util.ZNPNode_ZPP_CbSet.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbSet:(n=t.util.ZNPNode_ZPP_CbSet.zpp_pool,t.util.ZNPNode_ZPP_CbSet.zpp_pool=n.next,n.next=null),n}_allocCbTypeNode(t){let n;return t.util.ZNPNode_ZPP_CbType.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbType:(n=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=n.next,n.next=null),n}static _initStatics(t){Ct.UCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.VCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.WCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.UCbType=new t.util.ZNPList_ZPP_CbType,Ct.VCbType=new t.util.ZNPList_ZPP_CbType,Ct.WCbType=new t.util.ZNPList_ZPP_CbType;}};Ct.UCbSet=null,Ct.VCbSet=null,Ct.WCbSet=null,Ct.UCbType=null,Ct.VCbType=null,Ct.WCbType=null;var Hs=Ct;var Yn=class Yn{constructor(){this.outer=null;this.handler=null;this.includes=null;this.excludes=null;this.wrap_includes=null;this.wrap_excludes=null;let e=Yn._zpp;this.includes=new e.util.ZNPList_ZPP_CbType,this.excludes=new e.util.ZNPList_ZPP_CbType;}static argument(e){let t=Yn._nape;return e==null?new t.callbacks.OptionType:e instanceof t.callbacks.OptionType?e:new t.callbacks.OptionType().including(e)}setup_includes(){let e=Yn._zpp;this.wrap_includes=e.util.ZPP_CbTypeList.get(this.includes,true);}setup_excludes(){let e=Yn._zpp;this.wrap_excludes=e.util.ZPP_CbTypeList.get(this.excludes,true);}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):false}nonemptyintersection(e,t){let n=false,s=e.head,i=t.head;for(;i!=null&&s!=null;){let l=i.elt,r=s.elt;if(l===r){n=true;break}else l.id<r.id?i=i.next:s=s.next;}return n}insertOrdered(e,t){let n=Yn._zpp,s=null,i=e.head;for(;i!=null;){let r=i.elt;if(t.id<r.id)break;s=i,i=i.next;}let l;n.util.ZNPNode_ZPP_CbType.zpp_pool==null?l=new n.util.ZNPNode_ZPP_CbType:(l=n.util.ZNPNode_ZPP_CbType.zpp_pool,n.util.ZNPNode_ZPP_CbType.zpp_pool=l.next,l.next=null),l.elt=t,s==null?(l.next=e.head,e.head=l):(l.next=s.next,s.next=l),e.pushmod=e.modified=true,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,false,false):this.excludes.remove(t):this.handler!=null?this.handler(t,true,true):this.insertOrdered(this.includes,t)):this.excludes.has(t)||(this.includes.has(t)?this.handler!=null?this.handler(t,true,false):this.includes.remove(t):this.handler!=null?this.handler(t,false,true):this.insertOrdered(this.excludes,t));}set(e){if(e!==this){for(;this.includes.head!=null;)this.append_type(this.excludes,this.includes.head.elt);for(;this.excludes.head!=null;)this.append_type(this.includes,this.excludes.head.elt);let t=e.excludes.head;for(;t!=null;){let s=t.elt;this.append_type(this.excludes,s),t=t.next;}let n=e.includes.head;for(;n!=null;){let s=n.elt;this.append_type(this.includes,s),n=n.next;}}return this}append(e,t){let n=Yn._nape;if(t==null)throw new Error("Error: Cannot append null, only CbType and CbType list values");if(t instanceof n.callbacks.CbType){let s=t;this.append_type(e,s.zpp_inner);}else if(t instanceof n.callbacks.CbTypeList){let s=t;s.zpp_inner.valmod();let i=n.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let l=i.zpp_inner;l.zpp_inner.valmod(),l.zpp_inner.zip_length&&(l.zpp_inner.zip_length=false,l.zpp_inner.user_length=l.zpp_inner.inner.length);let r=l.zpp_inner.user_length;i.zpp_critical=true;let o;if(i.zpp_i<r?o=true:(i.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,o=false),!o)break;i.zpp_critical=false;let a=i.zpp_inner.at(i.zpp_i++);this.append_type(e,a.zpp_inner);}}else if(t instanceof Array){let s=t,i=0;for(;i<s.length;){let l=s[i];if(++i,!(l instanceof n.callbacks.CbType))throw new Error("Error: Cannot append non-CbType or CbType list value");let r=l;this.append_type(e,r.zpp_inner);}}else throw new Error("Error: Cannot append non-CbType or CbType list value")}};Yn._nape=null,Yn._zpp=null;var es=Yn;var vn=class vn{constructor(){this.outer=null;this.id=0;this.userData=null;this.compound=null;this.space=null;this.active=false;this.stiff=false;this.frequency=0;this.damping=0;this.maxForce=0;this.maxError=0;this.breakUnderForce=false;this.breakUnderError=false;this.removeOnBreak=false;this.component=null;this.ignore=false;this.__velocity=false;this.cbTypes=null;this.cbSet=null;this.wrap_cbTypes=null;this.pre_dt=-1;this._initBase();}_initBase(){let e=vn._zpp;this.id=yn.Constraint(),this.stiff=true,this.active=true,this.ignore=false,this.frequency=10,this.damping=1,this.maxForce=1/0,this.maxError=1/0,this.breakUnderForce=false,this.removeOnBreak=true,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 false}preStep(e){return false}applyImpulseVel(){return false}applyImpulsePos(){return false}copy(e,t){return null}immutable_midstep(e){if(this.space!=null&&this.space.midstep)throw new Error("Error: Constraint::"+e+" cannot be set during space step()")}setupcbTypes(){let e=vn._zpp;this.wrap_cbTypes=e.util.ZPP_CbTypeList.get(this.cbTypes),this.wrap_cbTypes.zpp_inner.adder=this.wrap_cbTypes_adder.bind(this),this.wrap_cbTypes.zpp_inner.subber=this.wrap_cbTypes_subber.bind(this),this.wrap_cbTypes.zpp_inner.dontremove=true,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),false}insert_cbtype(e){let t=vn._zpp;if(!this.cbTypes.has(e)){this.space!=null&&(this.dealloc_cbSet(),e.constraints.add(this));let n=null,s=this.cbTypes.head;for(;s!=null;){let o=s.elt;if(e.id<o.id)break;n=s,s=s.next;}let i=this.cbTypes,l;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?l=new t.util.ZNPNode_ZPP_CbType:(l=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;n==null?(r.next=i.head,i.head=r):(r.next=n.next,n.next=r),i.pushmod=i.modified=true,i.length++,this.space!=null&&(this.alloc_cbSet(),this.wake());}}alloc_cbSet(){(this.cbSet=this.space.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.constraints.add(this));}dealloc_cbSet(){let e=vn._zpp;if(this.cbSet!=null){if(this.cbSet.constraints.remove(this),--this.cbSet.count==0){this.space.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=true,t.bodylisteners.clear(),t.zip_bodylisteners=true,t.conlisteners.clear(),t.zip_conlisteners=true;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=e.callbacks.ZPP_CbSet.zpp_pool,e.callbacks.ZPP_CbSet.zpp_pool=t;}this.cbSet=null;}}activate(){this.space!=null&&this.activeInSpace();}deactivate(){this.space!=null&&this.inactiveOrOutSpace();}addedToSpace(){this.active&&this.activeInSpace(),this.activeBodies();let e=this.cbTypes.head;for(;e!=null;)e.elt.constraints.add(this),e=e.next;}removedFromSpace(){this.active&&this.inactiveOrOutSpace(),this.inactiveBodies();let e=this.cbTypes.head;for(;e!=null;)e.elt.constraints.remove(this),e=e.next;}activeInSpace(){let e=vn._zpp;this.alloc_cbSet(),e.space.ZPP_Component.zpp_pool==null?this.component=new e.space.ZPP_Component:(this.component=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=this.component.next,this.component.next=null),this.component.isBody=false,this.component.constraint=this;}inactiveOrOutSpace(){let e=vn._zpp;this.dealloc_cbSet();let t=this.component;t.body=null,t.constraint=null,t.next=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t,this.component=null;}wake(){this.space!=null&&this.space.wake_constraint(this);}copyto(e){let t=vn._nape,n=this.outer;n.zpp_inner.wrap_cbTypes==null&&n.zpp_inner.setupcbTypes();let s=n.zpp_inner.wrap_cbTypes;s.zpp_inner.valmod();let i=t.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let m=i.zpp_inner;m.zpp_inner.valmod(),m.zpp_inner.zip_length&&(m.zpp_inner.zip_length=false,m.zpp_inner.user_length=m.zpp_inner.inner.length);let _=m.zpp_inner.user_length;i.zpp_critical=true;let y;if(i.zpp_i<_?y=true:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,y=false),!y)break;i.zpp_critical=false;let z=i.zpp_inner.at(i.zpp_i++);e.zpp_inner.wrap_cbTypes==null&&e.zpp_inner.setupcbTypes();let b=e.zpp_inner.wrap_cbTypes;b.zpp_inner.reverse_flag?b.push(z):b.unshift(z);}e.zpp_inner.removeOnBreak=n.zpp_inner.removeOnBreak;let l=n.zpp_inner.breakUnderError;e.zpp_inner.breakUnderError!=l&&(e.zpp_inner.breakUnderError=l,e.zpp_inner.wake());let r=n.zpp_inner.breakUnderForce;e.zpp_inner.breakUnderForce!=r&&(e.zpp_inner.breakUnderForce=r,e.zpp_inner.wake());let o=n.zpp_inner.maxError;if(o!==o)throw new Error("Error: Constraint::maxError cannot be NaN");if(o<0)throw new Error("Error: Constraint::maxError must be >=0");e.zpp_inner.maxError!=o&&(e.zpp_inner.maxError=o,e.zpp_inner.wake());let a=n.zpp_inner.maxForce;if(a!==a)throw new Error("Error: Constraint::maxForce cannot be NaN");if(a<0)throw new Error("Error: Constraint::maxForce must be >=0");e.zpp_inner.maxForce!=a&&(e.zpp_inner.maxForce=a,e.zpp_inner.wake());let p=n.zpp_inner.damping;if(p!==p)throw new Error("Error: Constraint::Damping cannot be Nan");if(p<0)throw new Error("Error: Constraint::Damping must be >=0");e.zpp_inner.damping!=p&&(e.zpp_inner.damping=p,e.zpp_inner.stiff||e.zpp_inner.wake());let c=n.zpp_inner.frequency;if(c!==c)throw new Error("Error: Constraint::Frequency cannot be NaN");if(c<=0)throw new Error("Error: Constraint::Frequency must be >0");e.zpp_inner.frequency!=c&&(e.zpp_inner.frequency=c,e.zpp_inner.stiff||e.zpp_inner.wake());let h=n.zpp_inner.stiff;e.zpp_inner.stiff!=h&&(e.zpp_inner.stiff=h,e.zpp_inner.wake());let u=n.zpp_inner.ignore;e.zpp_inner.ignore!=u&&(e.zpp_inner.ignore=u,e.zpp_inner.wake());let x=n.zpp_inner.active;e.zpp_inner.active!=x&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.woken=false),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=true),e.zpp_inner.space.wake_constraint(e.zpp_inner,true))):(e.zpp_inner.space!=null&&(e.zpp_inner.wake(),e.zpp_inner.space.live_constraints.remove(e.zpp_inner)),e.zpp_inner.active=x,e.zpp_inner.deactivate()));}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let s=t.parent;t.parent=n,n=t,t=s;}for(;n!=null;){let s=n.parent;n.parent=t,n=s;}return t}static _unionComponents(e,t){let n=vn._findRoot(e),s=vn._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++));}};vn._nape=null,vn._zpp=null;var Ze=vn;var qn=class j{constructor(){this.id=0;this.bc=null;this.cb=null;}static dict(e,t){let n=new j;return n.id=e,n.bc=t,n}static todo(e,t){let n=new j;return n.id=e,n.cb=t,n}};var fs=class fs extends Ze{constructor(){super();this.outer_zn=null;this.ratio=0;this.jointMin=0;this.jointMax=0;this.slack=false;this.equal=false;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=false;this.ratio=1,this.jAcc=0,this.slack=false,this.jMax=1/0,this.stepped=false;}is_slack(){let t=this.ratio*this.b2.rot-this.b1.rot;return this.equal?(this.scale=1,false):t<this.jointMin?(this.scale=-1,false):t>this.jointMax?(this.scale=1,false):(this.scale=0,true)}bodyImpulse(t){let n=_e();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.scale*this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.scale*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this);}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this);}copy(t,n){let s=fs._createFn(null,null,this.jointMin,this.jointMax,this.ratio);if(this.copyto(s),t!=null&&this.b1!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b1.id){i=r.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(qn.todo(this.b1.id,r=>{s.zpp_inner.b1=r.zpp_inner;}));}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b2.id){i=r.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(qn.todo(this.b2.id,r=>{s.zpp_inner.b2=r.zpp_inner;}));}return s}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: AngleJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: AngleJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake();}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else {let s=this.b1.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l;}for(;i!=null;){let l=i.parent;i.parent=s,i=l;}t=s;}let n;if(this.component==this.component.parent)n=this.component;else {let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l;}for(;i!=null;){let l=i.parent;i.parent=s,i=l;}n=s;}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++));}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else {let s=this.b2.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l;}for(;i!=null;){let l=i.parent;i.parent=s,i=l;}t=s;}let n;if(this.component==this.component.parent)n=this.component;else {let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l;}for(;i!=null;){let l=i.parent;i.parent=s,i=l;}n=s;}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++));}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?true:this.b1.id==n?this.b2.id==t:false}clearcache(){this.jAcc=0,this.pre_dt=-1,this.slack=false;}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=true,this.equal=this.jointMin==this.jointMax;let s=this.ratio*this.b2.rot-this.b1.rot;this.equal?(s-=this.jointMax,this.slack=false,this.scale=1):s<this.jointMin?(s=this.jointMin-s,this.scale=-1,this.slack=false):s>this.jointMax?(s-=this.jointMax,this.scale=1,this.slack=false):(this.scale=0,s=0,this.slack=true);let i=s;if(!this.slack){if(this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else {if(this.breakUnderError&&i*i>this.maxError*this.maxError)return true;let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let r=1/(1+this.gamma),o=t*l*l*this.gamma;this.gamma*=r,this.kMass*=r,this.bias=-i*o,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError);}this.jAcc*=n,this.jMax=this.maxForce*t;}return false}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 false;let t=this.scale*(this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel),n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;return this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&(this.jAcc>this.jMax||this.jAcc<-this.jMax)?true:(this.stiff||(this.jAcc>this.jMax?this.jAcc=this.jMax:this.jAcc<-this.jMax&&(this.jAcc=-this.jMax)),n=this.jAcc-s,this.b1.angvel-=this.scale*this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*n,false)}applyImpulsePos(){let t=this.ratio*this.b2.rot-this.b1.rot,n;this.equal?(t-=this.jointMax,n=false,this.scale=1):t<this.jointMin?(t=this.jointMin-t,this.scale=-1,n=false):t>this.jointMax?(t-=this.jointMax,this.scale=1,n=false):(this.scale=0,t=0,n=true);let s=t;if(!n){if(this.breakUnderError&&s*s>this.maxError*this.maxError)return true;let l=-(s*.5)*this.kMass;if(this.equal||l<0){let r=this.b1,o=-this.scale*l*this.b1.iinertia;if(r.rot+=o,o*o>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else {let c=o*o,h=1-.5*c,u=1-c*c/8,x=(h*r.axisx+o*r.axisy)*u;r.axisy=(h*r.axisy-o*r.axisx)*u,r.axisx=x;}let a=this.b2,p=this.ratio*this.scale*l*this.b2.iinertia;if(a.rot+=p,p*p>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else {let c=p*p,h=1-.5*c,u=1-c*c/8,x=(h*a.axisx+p*a.axisy)*u;a.axisy=(h*a.axisy-p*a.axisx)*u,a.axisx=x;}}}return false}draw(t){}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else {let s=n*n,i=1-.5*s,l=1-s*s/8,r=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=r;}}static _copyBody(t,n,s,i,l){if(t!=null&&s!=null){let r=null;for(let o=0;o<t.length;o++){let a=t[o];if(a.id==s.id){r=a.bc;break}}r!=null?i.zpp_inner_zn[l]=r.zpp_inner:n.push(qn.todo(s.id,function(o){i.zpp_inner_zn[l]=o.zpp_inner;}));}}};fs._wrapFn=null,fs._createFn=null;var Re=fs;var Nt=class Nt{constructor(){this.x=0;this.y=0;this.next=null;this.length=0;this.modified=false;this.pushmod=false;this._inuse=false;this.weak=false;this.outer=null;this._immutable=false;this._isimmutable=null;this._validate=null;this._invalidate=null;}static get(e,t,n){n==null&&(n=false);let s;return Nt.zpp_pool==null?s=new Nt:(s=Nt.zpp_pool,Nt.zpp_pool=s.next,s.next=null),s.weak=false,s._immutable=n,s.x=e,s.y=t,s}validate(){this._validate!=null&&this._validate();}invalidate(){this._invalidate!=null&&this._invalidate(this);}immutable(){if(this._immutable)throw new Error("Error: Vec2 is immutable");this._isimmutable!=null&&this._isimmutable();}wrapper(){if(this.outer==null)if(Nt._wrapFn)this.outer=Nt._wrapFn(this);else {this.outer=new Nt._nape.geom.Vec2;let e=this.outer.zpp_inner;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e._isimmutable=null,e._validate=null,e._invalidate=null,e.next=Nt.zpp_pool,Nt.zpp_pool=e,this.outer.zpp_inner=this;}return this.outer}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this._isimmutable=null,this._validate=null,this._invalidate=null;}alloc(){this.weak=false;}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=true,this.pushmod=true;}add(e){return e._inuse=true,e.next=this.next,this.next=e,this.modified=true,this.length++,e}inlined_add(e){return e._inuse=true,e.next=this.next,this.next=e,this.modified=true,this.length++,e}addAll(e){let t=e.next;for(;t!=null;)this.add(t),t=t.next;}insert(e,t){return t._inuse=true,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=true,this.length++,t}inlined_insert(e,t){return t._inuse=true,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=true,this.length++,t}pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let s;t==null?(s=this.next,this.next=s.next,this.next==null&&(this.pushmod=true)):(s=t.next,t.next=s.next,s.next==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;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),true;t=n,n=n.next;}return false}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let s;t==null?(s=this.next,this.next=s.next,this.next==null&&(this.pushmod=true)):(s=t.next,t.next=s.next,s.next==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}inlined_try_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let s;return t==null?(s=this.next,this.next=s.next,this.next==null&&(this.pushmod=true)):(s=t.next,t.next=s.next,s.next==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true,true}t=n,n=n.next;}return false}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,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=true,this.pushmod=true;}empty(){return this.next==null}size(){return this.length}has(e){let t=this.next;for(;t!=null;){if(t===e)return true;t=t.next;}return false}inlined_has(e){let t=this.next;for(;t!=null;){if(t===e)return true;t=t.next;}return false}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=false,n._immutable=false,n.x=e,n.y=t,n}toString(){return "{ x: "+this.x+" y: "+this.y+" }"}};Nt.zpp_pool=null,Nt._nape=null,Nt._zpp=null,Nt._wrapFn=null;var ae=Nt;var Si=class Si extends Ze{constructor(){super();this.outer_zn=null;this.jointMin=0;this.jointMax=0;this.slack=false;this.equal=false;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=false;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=false,this.cx1=this.cx2=0;}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=n*n+s*s;return i<Ze._nape.Config.epsilon?t=true:(i=Math.sqrt(i),this.equal||i<this.jointMin||i>this.jointMax?t=false:t=true),t}bodyImpulse(t){let n=Ze._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAcc*this.nx,-this.jAcc*this.ny,-this.cx1*this.jAcc):n.geom.Vec3.get(this.jAcc*this.nx,this.jAcc*this.ny,this.cx2*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this);}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this);}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy;}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake();}setup_a1(){this.wrap_a1=Si._setupAnchorVec2(this.a1localx,this.a1localy,this.validate_a1.bind(this),this.invalidate_a1.bind(this));}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy;}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake();}setup_a2(){this.wrap_a2=Si._setupAnchorVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this));}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=Si._createFn(null,null,i,l.zpp_inner_zn.wrap_a2,this.jointMin,this.jointMax);return this.copyto(r),Re._copyBody(t,n,this.b1,r,"b1"),Re._copyBody(t,n,this.b2,r,"b2"),r}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: DistanceJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake();}forest(){this.b1.type==2&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component);}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?true:this.b1.id==n?this.b2.id==t:false}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=true,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.nx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.ny=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely);let s=this.nx*this.nx+this.ny*this.ny;if(s<Ze._nape.Config.epsilon)this.nx=0,this.ny=0,s=0,this.slack=true;else {s=Math.sqrt(s);let l=1/s;this.nx*=l,this.ny*=l,this.equal?(s-=this.jointMax,this.slack=false):s<this.jointMin?(s=this.jointMin-s,this.nx=-this.nx,this.ny=-this.ny,this.slack=false):s>this.jointMax?(s-=this.jointMax,this.slack=false):(this.nx=0,this.ny=0,s=0,this.slack=true);}let i=s;if(!this.slack){if(this.cx1=this.ny*this.a1relx-this.nx*this.a1rely,this.cx2=this.ny*this.a2relx-this.nx*this.a2rely,this.kMass=this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else {if(this.breakUnderError&&i*i>this.maxError*this.maxError)return true;let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let r=1/(1+this.gamma),o=t*l*l*this.gamma;this.gamma*=r,this.kMass*=r,this.bias=-i*o,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError);}this.jAcc*=n,this.jMax=this.maxForce*t;}return false}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 false;let t=this.nx*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.ny*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return true;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-s;let i=this.b1.imass*n;this.b1.velx-=this.nx*i,this.b1.vely-=this.ny*i;let l=this.b2.imass*n;return this.b2.velx+=this.nx*l,this.b2.vely+=this.ny*l,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,false}applyImpulsePos(){let t,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r,o=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s),p=o*o+a*a;if(p<Ze._nape.Config.epsilon)o=0,a=0,p=0,r=true;else {p=Math.sqrt(p);let h=1/p;o*=h,a*=h,this.equal?(p-=this.jointMax,r=false):p<this.jointMin?(p=this.jointMin-p,o=-o,a=-a,r=false):p>this.jointMax?(p-=this.jointMax,r=false):(o=0,a=0,p=0,r=true);}let c=p;if(!r){if(this.breakUnderError&&c*c>this.maxError*this.maxError)return true;if(c*c<Ze._nape.Config.constraintLinearSlop*Ze._nape.Config.constraintLinearSlop)return false;if(c*=.5,c*c>6){let m=this.b1.smass+this.b2.smass;if(m>Ze._nape.Config.epsilon){let _=.75/m;if(t=-c*_,this.equal||t<0){let y=t*this.b1.imass;this.b1.posx-=o*y,this.b1.posy-=a*y;let z=t*this.b2.imass;this.b2.posx+=o*z,this.b2.posy+=a*z,o=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s);let b=o*o+a*a;if(b<Ze._nape.Config.epsilon)o=0,a=0,b=0;else {b=Math.sqrt(b);let w=1/b;o*=w,a*=w,this.equal?b-=this.jointMax:b<this.jointMin?(b=this.jointMin-b,o=-o,a=-a):b>this.jointMax?b-=this.jointMax:(o=0,a=0,b=0);}c=b,c*=.5;}}}let h=a*n-o*s,u=a*i-o*l,x=this.b1.smass+this.b2.smass+h*h*this.b1.sinertia+u*u*this.b2.sinertia;if(x!=0&&(x=1/x),t=-c*x,this.equal||t<0){let m=this.b1.imass*t;this.b1.posx-=o*m,this.b1.posy-=a*m;let _=this.b2.imass*t;this.b2.posx+=o*_,this.b2.posy+=a*_,Re._rotateBody(this.b1,-h*this.b1.iinertia*t),Re._rotateBody(this.b2,u*this.b2.iinertia*t);}}return false}draw(t){}static _setupAnchorVec2(t,n,s,i){let l=Ze._nape,r=t,o=n;if(o==null&&(o=0),r==null&&(r=0),r!=r||o!=o)throw new Error("Error: Vec2 components cannot be NaN");let a;if(xe.poolVec2==null?a=new l.geom.Vec2:(a=xe.poolVec2,xe.poolVec2=a.zpp_pool,a.zpp_pool=null,a.zpp_disp=false,a==xe.nextVec2&&(xe.nextVec2=null)),a.zpp_inner==null){let p;ae.zpp_pool==null?p=new ae:(p=ae.zpp_pool,ae.zpp_pool=p.next,p.next=null),p.weak=false,p._immutable=false,p.x=r,p.y=o,a.zpp_inner=p,a.zpp_inner.outer=a;}else {if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=a.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),r!=r||o!=o)throw new Error("Error: Vec2 components cannot be NaN");let c;if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=a.zpp_inner;if(h._validate!=null&&h._validate(),a.zpp_inner.x==r){if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=a.zpp_inner;u._validate!=null&&u._validate(),c=a.zpp_inner.y==o;}else c=false;if(!c){a.zpp_inner.x=r,a.zpp_inner.y=o;let u=a.zpp_inner;u._invalidate!=null&&u._invalidate(u);}}return a.zpp_inner.weak=false,a.zpp_inner._inuse=true,a.zpp_inner._validate=s,a.zpp_inner._invalidate=i,a}};Si._wrapFn=null,Si._createFn=null;var xi=Si;var zs=class zs extends Ze{constructor(){super();this.outer_zn=null;this.scale=0;this.jointMin=0;this.jointMax=0;this.equal=false;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=false;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=false;}_setupVec2(t,n,s,i){let l=Ze._nape,r=Ze._zpp;if(n==null&&(n=0),t==null&&(t=0),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");let o;if(r.util.ZPP_PubPool.poolVec2==null?o=new l.geom.Vec2:(o=r.util.ZPP_PubPool.poolVec2,r.util.ZPP_PubPool.poolVec2=o.zpp_pool,o.zpp_pool=null,o.zpp_disp=false,o==r.util.ZPP_PubPool.nextVec2&&(r.util.ZPP_PubPool.nextVec2=null)),o.zpp_inner==null){let a;r.geom.ZPP_Vec2.zpp_pool==null?a=new r.geom.ZPP_Vec2:(a=r.geom.ZPP_Vec2.zpp_pool,r.geom.ZPP_Vec2.zpp_pool=a.next,a.next=null),a.weak=false,a._immutable=false,a.x=t,a.y=n,o.zpp_inner=a,o.zpp_inner.outer=o;}else {if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=o.zpp_inner;if(a._immutable)throw new Error("Error: Vec2 is immutable");if(a._isimmutable!=null&&a._isimmutable(),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=o.zpp_inner;p._validate!=null&&p._validate();let c;if(o.zpp_inner.x==t){if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=o.zpp_inner;h._validate!=null&&h._validate(),c=o.zpp_inner.y==n;}else c=false;if(!c){o.zpp_inner.x=t,o.zpp_inner.y=n;let h=o.zpp_inner;h._invalidate!=null&&h._invalidate(h);}}return o.zpp_inner.weak=false,o.zpp_inner._inuse=true,o.zpp_inner._validate=s,o.zpp_inner._invalidate=i,o}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy;}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake();}setup_a1(){this.wrap_a1=this._setupVec2(this.a1localx,this.a1localy,this.validate_a1.bind(this),this.invalidate_a1.bind(this));}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy;}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake();}setup_a2(){this.wrap_a2=this._setupVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this));}validate_n(){this.wrap_n.zpp_inner.x=this.nlocalx,this.wrap_n.zpp_inner.y=this.nlocaly;}invalidate_n(t){this.immutable_midstep("Constraint::n"),this.nlocalx=t.x,this.nlocaly=t.y,this.zip_n=true,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=false;let t=this.nlocalx*this.nlocalx+this.nlocaly*this.nlocaly,s=1/Math.sqrt(t);this.nlocalx*=s,this.nlocaly*=s;}}bodyImpulse(t){let n=Ze._nape;if(this.stepped){let s=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,i=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy;return t==this.b1?n.geom.Vec3.get(-s,-i,this.scale*this.cx1*i-this.dot1*s):n.geom.Vec3.get(s,i,this.scale*this.cx1*i-this.dot1*s)}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this);}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this);}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=l.zpp_inner_zn.wrap_a2,o=this.outer_zn;o.zpp_inner_zn.wrap_n==null&&o.zpp_inner_zn.setup_n();let a=zs._createFn(null,null,i,r,o.zpp_inner_zn.wrap_n,this.jointMin,this.jointMax);return this.copyto(a),Re._copyBody(t,n,this.b1,a,"b1"),Re._copyBody(t,n,this.b2,a,"b2"),a}validate(){let t=Ze._nape;if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.nlocalx*this.nlocalx+this.nlocaly*this.nlocaly<t.Config.epsilon)throw new Error("Error: DistanceJoint direction must be non-degenerate");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake();}forest(){this.b1.type==2&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component);}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?true:this.b1.id==n?this.b2.id==t:false}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=true,this.validate_norm(),this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.nrelx=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,this.nrely=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b2.posx+this.a2relx-this.b1.posx-this.a1relx,i=this.b2.posy+this.a2rely-this.b1.posy-this.a1rely,l=i*this.nrelx-s*this.nrely,r=this.nrelx*s+this.nrely*i;this.equal?(r-=this.jointMin,this.scale=1):r>this.jointMax?(r-=this.jointMax,this.scale=1):r<this.jointMin?(r=this.jointMin-r,this.scale=-1):(r=0,this.scale=0);let o=s+this.a1relx,a=i+this.a1rely;this.dot1=this.nrelx*o+this.nrely*a,this.cx1=a*this.nrelx-o*this.nrely,this.dot2=this.nrelx*this.a2relx+this.nrely*this.a2rely,this.cx2=this.a2rely*this.nrelx-this.a2relx*this.nrely,this.kMassa=this.b1.smass+this.b2.smass+this.dot1*this.dot1*this.b1.sinertia+this.dot2*this.dot2*this.b2.sinertia,this.kMassb=-this.scale*(this.dot1*this.cx1*this.b1.sinertia+this.dot2*this.cx2*this.b2.sinertia),this.kMassc=this.scale*this.scale*(this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia);let p=this.kMassa*this.kMassc-this.kMassb*this.kMassb,c;if(p!==p)this.kMassa=this.kMassb=this.kMassc=0,c=3;else if(p==0){let u=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,u|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,u|=2),this.kMassb=0,c=u;}else {let u=1/p,x=this.kMassc*u;this.kMassc=this.kMassa*u,this.kMassa=x,this.kMassb*=-u,c=0;}if((c&1)!=0&&(this.jAccx=0),(c&2)!=0&&(this.jAccy=0),this.stiff)this.gamma=0,this.biasx=0,this.biasy=0;else {if(this.breakUnderError&&l*l+r*r>this.maxError*this.maxError)return true;let u=2*Math.PI*this.frequency;this.gamma=1/(t*u*(2*this.damping+u*t));let x=1/(1+this.gamma),m=t*u*u*this.gamma;this.gamma*=x;let _=x;this.kMassa*=_,this.kMassb*=_,this.kMassc*=_,this.biasx=l,this.biasy=r;let y=-m;this.biasx*=y,this.biasy*=y;let z=this.maxError,b=this.biasx*this.biasx+this.biasy*this.biasy;if(b>z*z){let w=z*(1/Math.sqrt(b));this.biasx*=w,this.biasy*=w;}}let h=n;return this.jAccx*=h,this.jAccy*=h,this.jMax=this.maxForce*t,false}warmStart(){let t=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,n=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy,s=this.b1.imass;this.b1.velx-=t*s,this.b1.vely-=n*s;let i=this.b2.imass;this.b2.velx+=t*i,this.b2.vely+=n*i,this.b1.angvel+=(this.scale*this.cx1*this.jAccy-this.dot1*this.jAccx)*this.b1.iinertia,this.b2.angvel+=(this.dot2*this.jAccx-this.scale*this.cx2*this.jAccy)*this.b2.iinertia;}applyImpulseVel(){let t=this.b2.velx-this.b1.velx,n=this.b2.vely-this.b1.vely;t+=this.b2.kinvelx-this.b1.kinvelx,n+=this.b2.kinvely-this.b1.kinvely;let s=n*this.nrelx-t*this.nrely+(this.b2.angvel+this.b2.kinangvel)*this.dot2-(this.b1.angvel+this.b1.kinangvel)*this.dot1,i=this.scale*(this.nrelx*t+this.nrely*n-(this.b2.angvel+this.b2.kinangvel)*this.cx2+(this.b1.angvel+this.b1.kinangvel)*this.cx1),l=this.biasx-s,r=this.biasy-i,o=this.kMassa*l+this.kMassb*r;r=this.kMassb*l+this.kMassc*r,l=o;let a=this.gamma;l-=this.jAccx*a,r-=this.jAccy*a;let p=this.jAccx,c=this.jAccy;if(this.jAccx+=l,this.jAccy+=r,this.jAccy>0&&(this.jAccy=0),this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return true}else if(!this.stiff){let z=this.jMax,b=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(b>z*z){let w=z*(1/Math.sqrt(b));this.jAccx*=w,this.jAccy*=w;}}let h=this.jAccx-p,u=this.jAccy-c,x=this.scale*this.nrelx*u-this.nrely*h,m=this.nrelx*h+this.scale*this.nrely*u,_=this.b1.imass;this.b1.velx-=x*_,this.b1.vely-=m*_;let y=this.b2.imass;return this.b2.velx+=x*y,this.b2.vely+=m*y,this.b1.angvel+=(this.scale*this.cx1*u-this.dot1*h)*this.b1.iinertia,this.b2.angvel+=(this.dot2*h-this.scale*this.cx2*u)*this.b2.iinertia,false}applyImpulsePos(){let t=Ze._nape,n=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,s=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,i=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,r=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,o=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,a=this.b2.posx+r-this.b1.posx-i,p=this.b2.posy+o-this.b1.posy-l,c,h=p*n-a*s,u=n*a+s*p;if(this.equal?(u-=this.jointMin,c=1):u>this.jointMax?(u-=this.jointMax,c=1):u<this.jointMin?(u=this.jointMin-u,c=-1):(u=0,c=0),this.breakUnderError&&h*h+u*u>this.maxError*this.maxError)return true;if(h*h+u*u<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return false;let x,m,_=.5;if(h*=_,u*=_,h*h+u*u>6){let C=this.b1.smass+this.b2.smass;if(C>t.Config.epsilon){let S=.8/C,O=S*(s*h-c*n*u),F=S*(n*h*c-s*h),T=this.b1.imass;this.b1.posx-=O*T,this.b1.posy-=F*T;let R=this.b2.imass;this.b2.posx+=O*R,this.b2.posy+=F*R,a=this.b2.posx+r-this.b1.posx-i,p=this.b2.posy+o-this.b1.posy-l,h=p*n-a*s,u=n*a+s*p,this.equal?(u-=this.jointMin,c=1):u>this.jointMax?(u-=this.jointMax,c=1):u<this.jointMin?(u=this.jointMin-u,c=-1):(u=0,c=0);let W=.5;h*=W,u*=W;}}let y=a+i,z=p+l,b=n*y+s*z,w=z*n-y*s,Z=n*r+s*o,d=o*n-r*s,f=this.b1.smass+this.b2.smass+b*b*this.b1.sinertia+Z*Z*this.b2.sinertia,g=-c*(b*w*this.b1.sinertia+Z*d*this.b2.sinertia),P=c*c*(this.b1.smass+this.b2.smass+w*w*this.b1.sinertia+d*d*this.b2.sinertia);x=-h,m=-u;let v=f*P-g*g;if(v!==v)m=0,x=m;else if(v==0)f!=0?x/=f:x=0,P!=0?m/=P:m=0;else {let C=1/v,S=C*(P*x-g*m);m=C*(f*m-g*x),x=S;}m>0&&(m=0);let N=c*n*m-s*x,E=n*x+c*s*m,M=this.b1.imass;this.b1.posx-=N*M,this.b1.posy-=E*M;let k=this.b2.imass;return this.b2.posx+=N*k,this.b2.posy+=E*k,Re._rotateBody(this.b1,(c*w*m-b*x)*this.b1.iinertia),Re._rotateBody(this.b2,(Z*x-c*d*m)*this.b2.iinertia),false}draw(t){}};zs._wrapFn=null,zs._createFn=null;var _i=zs;var Ps=class Ps extends Ze{constructor(){super();this.outer_zn=null;this.ratio=0;this.rate=0;this.b1=null;this.b2=null;this.kMass=0;this.jAcc=0;this.jMax=0;this.stepped=false;this.jAcc=0,this.stepped=false,this.__velocity=true;}bodyImpulse(t){let n=_e();return this.stepped?t==this.b1?n.geom.Vec3.get(0,0,-this.jAcc):n.geom.Vec3.get(0,0,this.ratio*this.jAcc):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this);}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this);}copy(t,n){let s=Ps._createFn(null,null,this.rate,this.ratio);if(this.copyto(s),t!=null&&this.b1!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b1.id){i=r.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(qn.todo(this.b1.id,r=>{s.zpp_inner.b1=r.zpp_inner;}));}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let r=t[l];if(++l,r.id==this.b2.id){i=r.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(qn.todo(this.b2.id,r=>{s.zpp_inner.b2=r.zpp_inner;}));}return s}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: MotorJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake();}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else {let s=this.b1.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l;}for(;i!=null;){let l=i.parent;i.parent=s,i=l;}t=s;}let n;if(this.component==this.component.parent)n=this.component;else {let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l;}for(;i!=null;){let l=i.parent;i.parent=s,i=l;}n=s;}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++));}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else {let s=this.b2.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l;}for(;i!=null;){let l=i.parent;i.parent=s,i=l;}t=s;}let n;if(this.component==this.component.parent)n=this.component;else {let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l;}for(;i!=null;){let l=i.parent;i.parent=s,i=l;}n=s;}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++));}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?true:this.b1.id==n?this.b2.id==t:false}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=true,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,false}warmStart(){this.b1.angvel-=this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.b2.iinertia*this.jAcc;}applyImpulseVel(){let t=this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel-this.rate,n=-this.kMass*t,s=this.jAcc;if(this.jAcc+=n,this.breakUnderForce){if(this.jAcc>this.jMax||this.jAcc<-this.jMax)return true}else this.jAcc<-this.jMax?this.jAcc=-this.jMax:this.jAcc>this.jMax&&(this.jAcc=this.jMax);return n=this.jAcc-s,this.b1.angvel-=this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.b2.iinertia*n,false}applyImpulsePos(){return false}};Ps._wrapFn=null,Ps._createFn=null;var di=Ps;var ws=class ws extends Ze{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.jAccx=0;this.jAccy=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.stepped=false;this.stepped=false,this.jAccx=0,this.jAccy=0,this.jMax=1/0,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0;}bodyImpulse(t){let n=Ze._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAccx,-this.jAccy,-(this.jAccy*this.a1relx-this.jAccx*this.a1rely)):n.geom.Vec3.get(this.jAccx,this.jAccy,this.jAccy*this.a2relx-this.jAccx*this.a2rely):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this);}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this);}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy;}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake();}setup_a1(){let t=Ze._nape,n=Ze._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),o=l.zpp_inner.y==i;}else o=false;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p);}}l.zpp_inner.weak=false,this.wrap_a1=l,this.wrap_a1.zpp_inner._inuse=true,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this);}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy;}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake();}setup_a2(){let t=Ze._nape,n=Ze._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),o=l.zpp_inner.y==i;}else o=false;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p);}}l.zpp_inner.weak=false,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=true,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this);}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=ws._createFn(null,null,i,l.zpp_inner_zn.wrap_a2);return this.copyto(r),Re._copyBody(t,n,this.b1,r,"b1"),Re._copyBody(t,n,this.b2,r,"b2"),r}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: PivotJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: PivotJoint cannot be simulated with body1 == body2 (body1=body2="+this.b1.outer.toString()+")");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake();}forest(){this.b1.type==2&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component);}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?true:this.b1.id==n?this.b2.id==t:false}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=true,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b1.smass+this.b2.smass;if(this.kMassa=s,this.kMassb=0,this.kMassc=s,this.b1.sinertia!=0){let o=this.a1relx*this.b1.sinertia,a=this.a1rely*this.b1.sinertia;this.kMassa+=a*this.a1rely,this.kMassb+=-a*this.a1relx,this.kMassc+=o*this.a1relx;}if(this.b2.sinertia!=0){let o=this.a2relx*this.b2.sinertia,a=this.a2rely*this.b2.sinertia;this.kMassa+=a*this.a2rely,this.kMassb+=-a*this.a2relx,this.kMassc+=o*this.a2relx;}let i=this.kMassa*this.kMassc-this.kMassb*this.kMassb,l;if(i!=i)this.kMassa=this.kMassb=this.kMassc=0,l=3;else if(i==0){let o=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,o|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,o|=2),this.kMassb=0,l=o;}else {let o=1/i,a=this.kMassc*o;this.kMassc=this.kMassa*o,this.kMassa=a,this.kMassb*=-o,l=0;}if((l&1)!=0&&(this.jAccx=0),(l&2)!=0&&(this.jAccy=0),this.stiff)this.biasx=0,this.biasy=0,this.gamma=0;else {let o=2*Math.PI*this.frequency;this.gamma=1/(t*o*(2*this.damping+o*t));let a=1/(1+this.gamma),p=t*o*o*this.gamma;this.gamma*=a;let c=a;if(this.kMassa*=c,this.kMassb*=c,this.kMassc*=c,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy>this.maxError*this.maxError)return true;let h=-p;this.biasx*=h,this.biasy*=h;let u=this.maxError,x=this.biasx*this.biasx+this.biasy*this.biasy;if(x>u*u){let m=u*(1/Math.sqrt(x));this.biasx*=m,this.biasy*=m;}}let r=n;return this.jAccx*=r,this.jAccy*=r,this.jMax=this.maxForce*t,false}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely)*this.b2.iinertia;}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),s=this.biasx-t,i=this.biasy-n,l=this.kMassa*s+this.kMassb*i;i=this.kMassb*s+this.kMassc*i,s=l;let r=this.gamma;s-=this.jAccx*r,i-=this.jAccy*r;let o=this.jAccx,a=this.jAccy,p=1;if(this.jAccx+=s*p,this.jAccy+=i*p,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return true}else if(!this.stiff){let u=this.jMax,x=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(x>u*u){let m=u*(1/Math.sqrt(x));this.jAccx*=m,this.jAccy*=m;}}s=this.jAccx-o,i=this.jAccy-a;let c=this.b1.imass;this.b1.velx-=s*c,this.b1.vely-=i*c;let h=this.b2.imass;return this.b2.velx+=s*h,this.b2.vely+=i*h,this.b1.angvel-=(i*this.a1relx-s*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(i*this.a2relx-s*this.a2rely)*this.b2.iinertia,false}applyImpulsePos(){let t=Ze._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s);if(this.breakUnderError&&r*r+o*o>this.maxError*this.maxError)return true;if(r*r+o*o<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return false;let a=.5;r*=a,o*=a;let p,c;if(r*r+o*o>6){let f=this.b1.smass+this.b2.smass;if(f>t.Config.epsilon){let g=.75/f;p=-r*g,c=-o*g;let P=20,v=p*p+c*c;if(v>P*P){let k=P*(1/Math.sqrt(v));p*=k,c*=k;}let N=this.b1.imass;this.b1.posx-=p*N,this.b1.posy-=c*N;let E=this.b2.imass;this.b2.posx+=p*E,this.b2.posy+=c*E,r=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s);let M=.5;r*=M,o*=M;}}let h=this.b1.smass+this.b2.smass,u=h,x=0,m=h;if(this.b1.sinertia!=0){let f=n*this.b1.sinertia,g=s*this.b1.sinertia;u+=g*s,x+=-g*n,m+=f*n;}if(this.b2.sinertia!=0){let f=i*this.b2.sinertia,g=l*this.b2.sinertia;u+=g*l,x+=-g*i,m+=f*i;}p=-r,c=-o;let _=6,y=p*p+c*c;if(y>_*_){let f=_*(1/Math.sqrt(y));p*=f,c*=f;}let z=u*m-x*x;if(z!=z)c=0,p=0;else if(z==0)u!=0?p/=u:p=0,m!=0?c/=m:c=0;else {let f=1/z,g=f*(m*p-x*c);c=f*(u*c-x*p),p=g;}let b=this.b1.imass;this.b1.posx-=p*b,this.b1.posy-=c*b;let w=this.b2.imass;this.b2.posx+=p*w,this.b2.posy+=c*w;let Z=-(c*n-p*s)*this.b1.iinertia;Re._rotateBody(this.b1,Z);let d=(c*i-p*l)*this.b2.iinertia;return Re._rotateBody(this.b2,d),false}draw(t){}};ws._wrapFn=null,ws._createFn=null;var yi=ws;var vs=class vs extends Ze{constructor(){super();this.outer_zn=null;this.ratio=1;this.jointMin=0;this.jointMax=0;this.slack=false;this.equal=false;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=false;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=false,this.cx1=this.cx2=this.cx3=this.cx4=0;}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),l=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),r=Math.sqrt(n*n+s*s),o=Math.sqrt(i*i+l*l),a=r+this.ratio*o;return this.equal||a<this.jointMin||a>this.jointMax?t=false:t=true,t}bodyImpulse(t){let n=Ze._nape;if(this.stepped){let s=n.geom.Vec3.get();return t==this.b1&&(s.zpp_inner.x=s.zpp_inner.x-this.jAcc*this.n12x,s.zpp_inner.y=s.zpp_inner.y-this.jAcc*this.n12y,s.zpp_inner.z=s.zpp_inner.z-this.cx1*this.jAcc),t==this.b2&&(s.zpp_inner.x=s.zpp_inner.x+this.jAcc*this.n12x,s.zpp_inner.y=s.zpp_inner.y+this.jAcc*this.n12y,s.zpp_inner.z=s.zpp_inner.z+this.cx2*this.jAcc),t==this.b3&&(s.zpp_inner.x=s.zpp_inner.x-this.jAcc*this.n34x,s.zpp_inner.y=s.zpp_inner.y-this.jAcc*this.n34y,s.zpp_inner.z=s.zpp_inner.z-this.cx3*this.jAcc),t==this.b4&&(s.zpp_inner.x=s.zpp_inner.x+this.jAcc*this.n34x,s.zpp_inner.y=s.zpp_inner.y+this.jAcc*this.n34y,s.zpp_inner.z=s.zpp_inner.z+this.cx4*this.jAcc),s}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this),this.b3!=this.b1&&this.b3!=this.b2&&this.b3!=null&&this.b3.constraints.add(this),this.b4!=this.b1&&this.b4!=this.b2&&this.b4!=this.b3&&this.b4!=null&&this.b4.constraints.add(this);}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this),this.b3!=this.b1&&this.b3!=this.b2&&this.b3!=null&&this.b3.constraints.remove(this),this.b4!=this.b1&&this.b4!=this.b2&&this.b4!=this.b3&&this.b4!=null&&this.b4.constraints.remove(this);}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy;}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake();}setup_a1(){let t=Ze._nape,n=Ze._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),o=l.zpp_inner.y==i;}else o=false;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p);}}l.zpp_inner.weak=false,this.wrap_a1=l,this.wrap_a1.zpp_inner._inuse=true,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this);}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy;}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake();}setup_a2(){let t=Ze._nape,n=Ze._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),o=l.zpp_inner.y==i;}else o=false;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p);}}l.zpp_inner.weak=false,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=true,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this);}validate_a3(){this.wrap_a3.zpp_inner.x=this.a3localx,this.wrap_a3.zpp_inner.y=this.a3localy;}invalidate_a3(t){this.immutable_midstep("Constraint::a3"),this.a3localx=t.x,this.a3localy=t.y,this.wake();}setup_a3(){let t=Ze._nape,n=Ze._zpp,s=this.a3localx,i=this.a3localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),o=l.zpp_inner.y==i;}else o=false;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p);}}l.zpp_inner.weak=false,this.wrap_a3=l,this.wrap_a3.zpp_inner._inuse=true,this.wrap_a3.zpp_inner._validate=this.validate_a3.bind(this),this.wrap_a3.zpp_inner._invalidate=this.invalidate_a3.bind(this);}validate_a4(){this.wrap_a4.zpp_inner.x=this.a4localx,this.wrap_a4.zpp_inner.y=this.a4localy;}invalidate_a4(t){this.immutable_midstep("Constraint::a4"),this.a4localx=t.x,this.a4localy=t.y,this.wake();}setup_a4(){let t=Ze._nape,n=Ze._zpp,s=this.a4localx,i=this.a4localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),o=l.zpp_inner.y==i;}else o=false;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p);}}l.zpp_inner.weak=false,this.wrap_a4=l,this.wrap_a4.zpp_inner._inuse=true,this.wrap_a4.zpp_inner._validate=this.validate_a4.bind(this),this.wrap_a4.zpp_inner._invalidate=this.invalidate_a4.bind(this);}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=l.zpp_inner_zn.wrap_a2,o=this.outer_zn;o.zpp_inner_zn.wrap_a3==null&&o.zpp_inner_zn.setup_a3();let a=o.zpp_inner_zn.wrap_a3,p=this.outer_zn;p.zpp_inner_zn.wrap_a4==null&&p.zpp_inner_zn.setup_a4();let c=vs._createFn(null,null,null,null,i,r,a,p.zpp_inner_zn.wrap_a4,this.jointMin,this.jointMax,this.ratio);return this.copyto(c),Re._copyBody(t,n,this.b1,c,"b1"),Re._copyBody(t,n,this.b2,c,"b2"),Re._copyBody(t,n,this.b3,c,"b3"),Re._copyBody(t,n,this.b4,c,"b4"),c}validate(){if(this.b1==null||this.b2==null||this.b3==null||this.b4==null)throw new Error("Error: PulleyJoint cannot be simulated with null bodies");if(this.b1==this.b2||this.b3==this.b4)throw new Error("Error: PulleyJoint cannot have body1==body2 or body3==body4");if(this.b1.space!=this.space||this.b2.space!=this.space||this.b3.space!=this.space||this.b4.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: PulleyJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: PulleyJoint cannot have both bodies in a linked pair non-dynamic");if(this.b3.type!=2&&this.b4.type!=2)throw new Error("Error: PulleyJoint cannot have both bodies in a linked pair non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake(),this.b3!=null&&this.b3.type==2&&this.b3.wake(),this.b4!=null&&this.b4.type==2&&this.b4.wake();}forest(){this.b1.type==2&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component),this.b3.type==2&&Ze._unionComponents(this.b3.component,this.component),this.b4.type==2&&Ze._unionComponents(this.b4.component,this.component);}pair_exists(t,n){return this.b1.id==t&&(this.b2.id==n||this.b3.id==n||this.b4.id==n)||this.b2.id==t&&(this.b3.id==n||this.b4.id==n||this.b1.id==n)||this.b3.id==t&&(this.b4.id==n||this.b1.id==n||this.b2.id==n)?true:this.b4.id==t?this.b1.id==n||this.b2.id==n?true:this.b3.id==n:false}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=true,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let s=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),i=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),l=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),r=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),o=Math.sqrt(s*s+i*i),a=Math.sqrt(l*l+r*r);if(o!=0){let h=1/o;this.n12x=s*h,this.n12y=i*h;}if(a!=0){let h=1/a;this.n34x=l*h,this.n34y=r*h;let u=this.ratio;this.n34x*=u,this.n34y*=u;}else {let h=this.ratio/Math.sqrt(this.n34x*this.n34x+this.n34y*this.n34y);this.n34x*=h,this.n34y*=h;}let p=o+this.ratio*a;this.equal?(p-=this.jointMax,this.slack=false):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=false):p>this.jointMax?(p-=this.jointMax,this.slack=false):(this.n12x=0,this.n12y=0,this.n34x=0,this.n34y=0,p=0,this.slack=true);let c=p;if(!this.slack){this.cx1=this.n12y*this.a1relx-this.n12x*this.a1rely,this.cx2=this.n12y*this.a2relx-this.n12x*this.a2rely,this.cx3=this.n34y*this.a3relx-this.n34x*this.a3rely,this.cx4=this.n34y*this.a4relx-this.n34x*this.a4rely;let h=this.ratio*this.ratio,u=this.b1.smass+this.b2.smass+h*(this.b3.smass+this.b4.smass)+this.b1.sinertia*this.cx1*this.cx1+this.b2.sinertia*this.cx2*this.cx2+this.b3.sinertia*this.cx3*this.cx3+this.b4.sinertia*this.cx4*this.cx4;if(this.b1==this.b4&&(u-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx4*this.b1.sinertia)),this.b1==this.b3&&(u+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx3*this.b1.sinertia)),this.b2==this.b3&&(u-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx3*this.b2.sinertia)),this.b2==this.b4&&(u+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx4*this.b2.sinertia)),this.kMass=u,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else {if(this.breakUnderError&&c*c>this.maxError*this.maxError)return true;let x=2*Math.PI*this.frequency;this.gamma=1/(t*x*(2*this.damping+x*t));let m=1/(1+this.gamma),_=t*x*x*this.gamma;this.gamma*=m,this.kMass*=m,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 false}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.n12x*t,this.b1.vely-=this.n12y*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.n12x*n,this.b2.vely+=this.n12y*n;let s=this.b3.imass*this.jAcc;this.b3.velx-=this.n34x*s,this.b3.vely-=this.n34y*s;let i=this.b4.imass*this.jAcc;this.b4.velx+=this.n34x*i,this.b4.vely+=this.n34y*i,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc,this.b3.angvel-=this.cx3*this.b3.iinertia*this.jAcc,this.b4.angvel+=this.cx4*this.b4.iinertia*this.jAcc;}}applyImpulseVel(){if(this.slack)return false;let t=this.n12x*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.n12y*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+this.n34x*(this.b4.velx+this.b4.kinvelx-this.b3.velx-this.b3.kinvelx)+this.n34y*(this.b4.vely+this.b4.kinvely-this.b3.vely-this.b3.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1+(this.b4.angvel+this.b4.kinangvel)*this.cx4-(this.b3.angvel+this.b3.kinangvel)*this.cx3,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return true;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-s;let i=this.b1.imass*n;this.b1.velx-=this.n12x*i,this.b1.vely-=this.n12y*i;let l=this.b2.imass*n;this.b2.velx+=this.n12x*l,this.b2.vely+=this.n12y*l;let r=this.b3.imass*n;this.b3.velx-=this.n34x*r,this.b3.vely-=this.n34y*r;let o=this.b4.imass*n;return this.b4.velx+=this.n34x*o,this.b4.vely+=this.n34y*o,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,this.b3.angvel-=this.cx3*this.b3.iinertia*n,this.b4.angvel+=this.cx4*this.b4.iinertia*n,false}applyImpulsePos(){let t=Ze._nape,n,s=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,i=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,l=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,r=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,a=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,p=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,c=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy,h,u=this.n12x,x=this.n12y,m=this.n34x,_=this.n34y,y=this.b2.posx+l-(this.b1.posx+s),z=this.b2.posy+r-(this.b1.posy+i),b=this.b4.posx+p-(this.b3.posx+o),w=this.b4.posy+c-(this.b3.posy+a),Z=Math.sqrt(y*y+z*z),d=Math.sqrt(b*b+w*w);if(Z!=0){let P=1/Z;u=y*P,x=z*P;}if(d!=0){let P=1/d;m=b*P,_=w*P;let v=this.ratio;m*=v,_*=v;}else {let P=this.ratio/Math.sqrt(m*m+_*_);m*=P,_*=P;}let f=Z+this.ratio*d;this.equal?(f-=this.jointMax,h=false):f<this.jointMin?(f=this.jointMin-f,u=-u,x=-x,m=-m,_=-_,h=false):f>this.jointMax?(f-=this.jointMax,h=false):(u=0,x=0,m=0,_=0,f=0,h=true);let g=f;if(!h){if(this.breakUnderError&&g*g>this.maxError*this.maxError)return true;if(g*g<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return false;if(g*=.5,g*g>6){let S=this.b1.smass+this.b2.smass;if(S>t.Config.epsilon){let O=.75/S;if(n=-g*O,this.equal||n<0){let F=n*this.b1.imass;this.b1.posx-=u*F,this.b1.posy-=x*F;let T=n*this.b2.imass;this.b2.posx+=u*T,this.b2.posy+=x*T;let R=n*this.b3.imass;this.b3.posx-=m*R,this.b3.posy-=_*R;let W=n*this.b4.imass;this.b4.posx+=m*W,this.b4.posy+=_*W;let G=this.b2.posx+l-(this.b1.posx+s),B=this.b2.posy+r-(this.b1.posy+i),A=this.b4.posx+p-(this.b3.posx+o),Y=this.b4.posy+c-(this.b3.posy+a),$=Math.sqrt(G*G+B*B),H=Math.sqrt(A*A+Y*Y);if($!=0){let ee=1/$;u=G*ee,x=B*ee;}if(H!=0){let ee=1/H;m=A*ee,_=Y*ee;let q=this.ratio;m*=q,_*=q;}else {let ee=this.ratio/Math.sqrt(m*m+_*_);m*=ee,_*=ee;}let X=$+this.ratio*H;this.equal?X-=this.jointMax:X<this.jointMin?(X=this.jointMin-X,u=-u,x=-x,m=-m,_=-_):X>this.jointMax?X-=this.jointMax:(u=0,x=0,m=0,_=0,X=0),g=X,g*=.5;}}}let P=x*s-u*i,v=x*l-u*r,N=_*o-m*a,E=_*p-m*c,M=this.ratio*this.ratio,k=this.b1.smass+this.b2.smass+M*(this.b3.smass+this.b4.smass)+this.b1.sinertia*P*P+this.b2.sinertia*v*v+this.b3.sinertia*N*N+this.b4.sinertia*E*E;this.b1==this.b4&&(k-=2*((u*m+x*_)*this.b1.smass+P*E*this.b1.sinertia)),this.b1==this.b3&&(k+=2*((u*m+x*_)*this.b1.smass+P*N*this.b1.sinertia)),this.b2==this.b3&&(k-=2*((u*m+x*_)*this.b2.smass+v*N*this.b2.sinertia)),this.b2==this.b4&&(k+=2*((u*m+x*_)*this.b2.smass+v*E*this.b2.sinertia));let C=k;if(C!=0&&(C=1/C),n=-g*C,this.equal||n<0){let S=this.b1.imass*n;this.b1.posx-=u*S,this.b1.posy-=x*S;let O=this.b2.imass*n;this.b2.posx+=u*O,this.b2.posy+=x*O;let F=this.b3.imass*n;this.b3.posx-=m*F,this.b3.posy-=_*F;let T=this.b4.imass*n;this.b4.posx+=m*T,this.b4.posy+=_*T,Re._rotateBody(this.b1,-P*this.b1.iinertia*n),Re._rotateBody(this.b2,v*this.b2.iinertia*n),Re._rotateBody(this.b3,-N*this.b3.iinertia*n),Re._rotateBody(this.b4,E*this.b4.iinertia*n);}}return false}draw(t){}};vs._wrapFn=null,vs._createFn=null;var mi=vs;var ts=class{constructor(e,t){this.cnt=0;this.body=null;this.cnt=e,this.body=t;}};var Xs=class extends Ze{constructor(t,n){super();this.outer_zn=null;this.bodies=null;this.dim=0;this.jAcc=null;this.bias=null;this.stepped=false;this.L=null;this.y=null;this.soft=0;this.gamma=0;this.velonly=false;this.jMax=0;this.Keff=null;this.vec3=null;this.J=null;this.jOld=null;this.bodies=[],this.dim=t,this.velonly=n,this.jAcc=[],this.bias=[],this.L=[],this.J=[],this.jOld=[],this.y=[],this.Keff=[],this.vec3=Ze._nape.geom.Vec3.get(0,0,0);for(let s=0;s<t;s++){let i=this.bias[s]=this.J[s]=this.jOld[s]=this.y[s]=0;this.jAcc[s]=i;for(let l=0;l<t;l++)this.L[s*t+l]=0;}this.stepped=false;}bindVec2_invalidate(t){this.outer_zn.__invalidate();}addBody(t){let n=null;for(let s of this.bodies)if(s.body===t){n=s;break}n===null?(this.bodies.push(new ts(1,t)),this.active&&this.space!=null&&t?.constraints.add(this)):n.cnt++;}remBody(t){let n=null,s=this.bodies.length|0,i=0;for(;i<s;){let l=this.bodies[i];if(l.body===t){l.cnt--,l.cnt===0&&(s>0&&(this.bodies[i]=this.bodies[s-1]),this.bodies.pop(),this.active&&this.space!=null&&t?.constraints.remove(this)),n=l;break}++i;}return n!=null}bodyImpulse(t){for(let s=0;s<this.dim;s++)this.J[s]=this.jAcc[s];let n=Ze._nape.geom.Vec3.get(0,0,0);return this.stepped&&this.outer_zn.__impulse(this.J,t.outer,n),n}activeBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.add(this);}inactiveBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.remove(this);}copy(t,n){let s=this.outer_zn.__copy();throw this.copyto(s),new Error("not done yet")}validate(){for(let t of this.bodies)if(t.body.space!==this.space)throw new Error("Error: Constraints must have each body within the same sapce to which the constraint has been assigned");this.outer_zn.__validate();}wake_connected(){for(let t of this.bodies)t.body.type===2&&t.body.wake();}forest(){for(let t of this.bodies)if(t.body.type===2){let n;if(t.body.component===t.body.component.parent)n=t.body.component;else {let i=t.body.component,l=null;for(;i!==i.parent;){let r=i.parent;i.parent=l,l=i,i=r;}for(;l!=null;){let r=l.parent;l.parent=i,l=r;}n=i;}let s;if(this.component===this.component.parent)s=this.component;else {let i=this.component,l=null;for(;i!==i.parent;){let r=i.parent;i.parent=l,l=i,i=r;}for(;l!=null;){let r=l.parent;l.parent=i,l=r;}s=i;}n!==s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++));}}pair_exists(t,n){let s=false,i=this.bodies.length|0;for(let l=0;l<i;l++){let r=this.bodies[l].body;for(let o=l+1;o<i;o++){let a=this.bodies[o].body;if(r.id===t&&a.id===n||r.id===n&&a.id===t){s=true;break}}if(s)break}return s}broken(){this.outer_zn.__broken();}clearcache(){for(let t=0;t<this.dim;t++)this.jAcc[t]=0;this.pre_dt=-1;}lsq(t){let n=0;for(let s=0;s<this.dim;s++)n+=t[s]*t[s];return n}_clamp(t,n){let s=this.lsq(t);if(s>n*n){let i=n/Math.sqrt(s);for(let l=0;l<this.dim;l++)t[l]*=i;}}solve(t){let n=0;for(let s=0;s<this.dim;s++){let i=0;for(let r=0;r<s-1;r++)i+=this.L[s*this.dim+r]*this.L[s*this.dim+r];let l=Math.sqrt(t[n++]-i);if(this.L[s*this.dim+s]=l,l!==0){l=1/l;for(let r=s+1;r<this.dim;r++){let o=0;for(let a=0;a<s-1;a++)o+=this.L[r*this.dim+a]*this.L[s*this.dim+a];this.L[r*this.dim+s]=l*(t[n++]-o);}}else {for(let r=s+1;r<this.dim;r++)this.L[r*this.dim+s]=0;n+=this.dim-s-1;}}return this.L}transform(t,n){for(let s=0;s<this.dim;s++){let i=n[s],l=t[s*this.dim+s];if(l!==0){for(let r=0;r<s;r++)i-=t[s*this.dim+r]*this.y[r];this.y[s]=i/l;}else this.y[s]=0;}for(let s=0;s<this.dim;s++){let i=this.dim-1-s,l=t[i*this.dim+i];if(l!==0){let r=this.y[i];for(let o=i+1;o<this.dim;o++)r-=t[o*this.dim+i]*n[o];n[i]=r/l;}else n[i]=0;}}preStep(t){this.pre_dt===-1&&(this.pre_dt=t);let n=t/this.pre_dt;if(this.pre_dt=t,this.stepped=true,this.outer_zn.__prepare(),this.outer_zn.__eff_mass(this.Keff),this.L=this.solve(this.Keff),!this.stiff&&!this.velonly){let s=2*Math.PI*this.frequency;this.gamma=1/(t*s*(2*this.damping+s*t));let i=1/(1+this.gamma),l=t*s*s*this.gamma;if(this.gamma*=i,this.soft=i,this.outer_zn.__position(this.bias),this.breakUnderError&&this.lsq(this.bias)>this.maxError*this.maxError)return true;for(let r=0;r<this.dim;r++)this.bias[r]*=-l;this._clamp(this.bias,this.maxError);}else {for(let s=0;s<this.dim;s++)this.bias[s]=0;this.gamma=0,this.soft=1;}for(let s=0;s<this.dim;s++)this.jAcc[s]*=n;return this.jMax=this.maxForce*t,false}warmStart(){for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.jAcc,n.outer,this.vec3);let s=n.imass,i=n,l=i.velx,r=this.vec3;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let o=r.zpp_inner;o._validate!=null&&o._validate(),i.velx=l+r.zpp_inner.x*s;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let h=c.zpp_inner;h._validate!=null&&h._validate(),a.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=m.zpp_inner;_._validate!=null&&_._validate(),u.angvel=x+m.zpp_inner.z*n.iinertia;}}applyImpulseVel(){this.outer_zn.__velocity(this.J);for(let t=0;t<this.dim;t++)this.J[t]=this.bias[t]-this.J[t];this.transform(this.L,this.J);for(let t=0;t<this.dim;t++)this.jOld[t]=this.jAcc[t],this.jAcc[t]+=this.J[t]=this.J[t]*this.soft-this.jAcc[t]*this.gamma;if(this.outer_zn.__clamp(this.jAcc),(this.breakUnderForce||!this.stiff)&&this.lsq(this.jAcc)>this.jMax*this.jMax){if(this.breakUnderForce)return true;this.stiff||this._clamp(this.jAcc,this.jMax);}for(let t=0;t<this.dim;t++)this.J[t]=this.jAcc[t]-this.jOld[t];for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.J,n.outer,this.vec3);let s=n.imass,i=n,l=i.velx,r=this.vec3;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let o=r.zpp_inner;o._validate!=null&&o._validate(),i.velx=l+r.zpp_inner.x*s;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let h=c.zpp_inner;h._validate!=null&&h._validate(),a.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=m.zpp_inner;_._validate!=null&&_._validate(),u.angvel=x+m.zpp_inner.z*n.iinertia;}return false}applyImpulsePos(){if(this.velonly)return false;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 true;if(t<Ze._nape.Config.constraintLinearSlop*Ze._nape.Config.constraintLinearSlop)return false;for(let n=0;n<this.dim;n++)this.J[n]*=-1;this.outer_zn.__eff_mass(this.Keff),this.transform(this.solve(this.Keff),this.J),this.outer_zn.__clamp(this.J);for(let n of this.bodies){let s=n.body;this.outer_zn.__impulse(this.J,s.outer,this.vec3);let i=s.imass,l=s,r=l.posx,o=this.vec3;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let a=o.zpp_inner;a._validate!=null&&a._validate(),l.posx=r+o.zpp_inner.x*i;let p=s,c=p.posy,h=this.vec3;if(h!=null&&h.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let u=h.zpp_inner;u._validate!=null&&u._validate(),p.posy=c+h.zpp_inner.y*i;let x=this.vec3;if(x!=null&&x.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let m=x.zpp_inner;m._validate!=null&&m._validate();let _=x.zpp_inner.z*s.iinertia;if(s.rot+=_,_*_>1e-4)s.axisx=Math.sin(s.rot),s.axisy=Math.cos(s.rot);else {let y=_*_,z=1-.5*y,b=1-y*y/8,w=(z*s.axisx+_*s.axisy)*b;s.axisy=(z*s.axisy-_*s.axisx)*b,s.axisx=w;}}return false}draw(t){this.outer_zn.__draw(t);}};var gs=class gs extends Ze{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.phase=0;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.kMassd=0;this.kMasse=0;this.kMassf=0;this.jAccx=0;this.jAccy=0;this.jAccz=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.biasz=0;this.stepped=false;this.phase=0,this.jAccx=0,this.jAccy=0,this.jAccz=0,this.jMax=1/0,this.stepped=false,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0;}bodyImpulse(t){let n=Ze._nape;return this.stepped?t==this.b1?n.geom.Vec3.get(-this.jAccx,-this.jAccy,-(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)):n.geom.Vec3.get(this.jAccx,this.jAccy,this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz):n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this);}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this);}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy;}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake();}setup_a1(){let t=Ze._nape,n=Ze._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),o=l.zpp_inner.y==i;}else o=false;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p);}}l.zpp_inner.weak=false,this.wrap_a1=l,this.wrap_a1.zpp_inner._inuse=true,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this);}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy;}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake();}setup_a2(){let t=Ze._nape,n=Ze._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;n.geom.ZPP_Vec2.zpp_pool==null?r=new n.geom.ZPP_Vec2:(r=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),o=l.zpp_inner.y==i;}else o=false;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p);}}l.zpp_inner.weak=false,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=true,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this);}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let r=gs._createFn(null,null,i,l.zpp_inner_zn.wrap_a2);return this.copyto(r),Re._copyBody(t,n,this.b1,r,"b1"),Re._copyBody(t,n,this.b2,r,"b2"),r}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: WeldJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake();}forest(){this.b1.type==2&&Ze._unionComponents(this.b1.component,this.component),this.b2.type==2&&Ze._unionComponents(this.b2.component,this.component);}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?true:this.b1.id==n?this.b2.id==t:false}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=true,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b1.smass+this.b2.smass;if(this.kMassa=s,this.kMassb=0,this.kMassd=s,this.kMassc=0,this.kMasse=0,this.kMassf=0,this.b1.sinertia!=0){let r=this.a1relx*this.b1.sinertia,o=this.a1rely*this.b1.sinertia;this.kMassa+=o*this.a1rely,this.kMassb+=-o*this.a1relx,this.kMassd+=r*this.a1relx,this.kMassc+=-o,this.kMasse+=r,this.kMassf+=this.b1.sinertia;}if(this.b2.sinertia!=0){let r=this.a2relx*this.b2.sinertia,o=this.a2rely*this.b2.sinertia;this.kMassa+=o*this.a2rely,this.kMassb+=-o*this.a2relx,this.kMassd+=r*this.a2relx,this.kMassc+=-o,this.kMasse+=r,this.kMassf+=this.b2.sinertia;}let i=this.kMassa*(this.kMassd*this.kMassf-this.kMasse*this.kMasse)+this.kMassb*(this.kMassc*this.kMasse-this.kMassb*this.kMassf)+this.kMassc*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),l;if(i!=i)this.kMassa=0,this.kMassb=0,this.kMassd=0,this.kMassc=0,this.kMasse=0,this.kMassf=0,l=7;else if(i==0){let r=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,r|=1),this.kMassd!=0?this.kMassd=1/this.kMassd:(this.kMassd=0,r|=2),this.kMassf!=0?this.kMassf=1/this.kMassf:(this.kMassf=0,r|=4),this.kMassb=this.kMassc=this.kMasse=0,l=r;}else {let r=1/i,o=r*(this.kMassd*this.kMassf-this.kMasse*this.kMasse),a=r*(this.kMasse*this.kMassc-this.kMassb*this.kMassf),p=r*(this.kMassa*this.kMassf-this.kMassc*this.kMassc),c=r*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),h=r*(this.kMassb*this.kMassc-this.kMassa*this.kMasse),u=r*(this.kMassa*this.kMassd-this.kMassb*this.kMassb);this.kMassa=o,this.kMassb=a,this.kMassd=p,this.kMassc=c,this.kMasse=h,this.kMassf=u,l=0;}if((l&1)!=0&&(this.jAccx=0),(l&2)!=0&&(this.jAccy=0),(l&4)!=0&&(this.jAccz=0),this.stiff)this.biasx=0,this.biasy=0,this.biasz=0,this.gamma=0;else {let r=2*Math.PI*this.frequency;this.gamma=1/(t*r*(2*this.damping+r*t));let o=1/(1+this.gamma),a=t*r*r*this.gamma;this.gamma*=o;let p=o;if(this.kMassa*=p,this.kMassb*=p,this.kMassd*=p,this.kMassc*=p,this.kMasse*=p,this.kMassf*=p,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.biasz=this.b2.rot-this.b1.rot-this.phase,this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz>this.maxError*this.maxError)return true;let c=-a;this.biasx*=c,this.biasy*=c,this.biasz*=c;let h=this.maxError,u=this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz;if(u>h*h){let x=h*(1/Math.sqrt(u));this.biasx*=x,this.biasy*=x,this.biasz*=x;}}return this.jAccx*=n,this.jAccy*=n,this.jAccz*=n,this.jMax=this.maxForce*t,false}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz)*this.b2.iinertia;}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),s=this.b2.angvel+this.b2.kinangvel-this.b1.angvel-this.b1.kinangvel,i=this.biasx-t,l=this.biasy-n,r=this.biasz-s,o=this.kMassa*i+this.kMassb*l+this.kMassc*r,a=this.kMassb*i+this.kMassd*l+this.kMasse*r;r=this.kMassc*i+this.kMasse*l+this.kMassf*r,i=o,l=a,i-=this.jAccx*this.gamma,l-=this.jAccy*this.gamma,r-=this.jAccz*this.gamma;let p=this.jAccx,c=this.jAccy,h=this.jAccz;if(this.jAccx+=i,this.jAccy+=l,this.jAccz+=r,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz>this.jMax*this.jMax)return true}else if(!this.stiff){let m=this.jMax,_=this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz;if(_>m*m){let y=m*(1/Math.sqrt(_));this.jAccx*=y,this.jAccy*=y,this.jAccz*=y;}}i=this.jAccx-p,l=this.jAccy-c,r=this.jAccz-h;let u=this.b1.imass;this.b1.velx-=i*u,this.b1.vely-=l*u;let x=this.b2.imass;return this.b2.velx+=i*x,this.b2.vely+=l*x,this.b1.angvel-=(l*this.a1relx-i*this.a1rely+r)*this.b1.iinertia,this.b2.angvel+=(l*this.a2relx-i*this.a2rely+r)*this.b2.iinertia,false}applyImpulsePos(){let t=Ze._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,p,c,h;if(this.breakUnderError&&r*r+o*o+a*a>this.maxError*this.maxError)return true;let u=true;r*r+o*o<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(u=false,r=0,o=0);let x=t.Config.constraintAngularSlop;if(a*a<x*x)if(u)a=0;else return false;if(r*=.5,o*=.5,a*=.5,r*r+o*o>6){let O=this.b1.smass+this.b2.smass;if(O>t.Config.epsilon){let F=.75/O;p=-r*F,c=-o*F;let T=20,R=p*p+c*c;if(R>T*T){let B=T*(1/Math.sqrt(R));p*=B,c*=B;}let W=this.b1.imass;this.b1.posx-=p*W,this.b1.posy-=c*W;let G=this.b2.imass;this.b2.posx+=p*G,this.b2.posy+=c*G,r=this.b2.posx+i-(this.b1.posx+n),o=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,r*=.5,o*=.5,a*=.5;}}let m=this.b1.smass+this.b2.smass,_=m,y=0,z=m,b=0,w=0,Z=0;if(this.b1.sinertia!=0){let O=n*this.b1.sinertia,F=s*this.b1.sinertia;_+=F*s,y+=-F*n,z+=O*n,b+=-F,w+=O,Z+=this.b1.sinertia;}if(this.b2.sinertia!=0){let O=i*this.b2.sinertia,F=l*this.b2.sinertia;_+=F*l,y+=-F*i,z+=O*i,b+=-F,w+=O,Z+=this.b2.sinertia;}p=-r,c=-o,h=-a;let d=6,f=p*p+c*c;if(f>d*d){let O=d*(1/Math.sqrt(f));p*=O,c*=O;}let v=_*(z*Z-w*w)+y*(b*w-y*Z)+b*(y*w-b*z);if(v!=v)h=0,c=h,p=c;else if(v==0)_!=0?p/=_:p=0,z!=0?c/=z:c=0,Z!=0?h/=Z:h=0;else {let O=1/v,F=w*b-y*Z,T=y*w-b*z,R=y*b-_*w,W=O*(p*(z*Z-w*w)+c*F+h*T),G=O*(p*F+c*(_*Z-b*b)+h*R);h=O*(p*T+c*R+h*(_*z-y*y)),p=W,c=G;}let N=this.b1.imass;this.b1.posx-=p*N,this.b1.posy-=c*N;let E=this.b2.imass;this.b2.posx+=p*E,this.b2.posy+=c*E;let M=this.b1,k=-(c*n-p*s+h)*this.b1.iinertia;Re._rotateBody(M,k);let C=this.b2,S=(c*i-p*l+h)*this.b2.iinertia;return Re._rotateBody(C,S),false}draw(t){}};gs._wrapFn=null,gs._createFn=null;var bi=gs;var it=class it{constructor(){this.outer=null;this.hnext=null;this.id=0;this.di=0;this.stamp=0;this.up_stamp=0;this.sleep_stamp=0;this.endGenerated=0;this.active=false;this.cleared=false;this.sleeping=false;this.present=0;this.intchange=false;this.presentable=false;this.continuous=false;this.fresh=false;this.immState=0;this.invalidated=false;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=false,this.immState=0,this.fresh=false,this.continuous=false,this.presentable=false,this.intchange=false,this.present=0,this.sleeping=false,this.cleared=false,this.active=false,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=true;let s=new e.dynamics.ArbiterType;return t.internal=false,s};t.ArbiterType_COLLISION==null&&(t.ArbiterType_COLLISION=n()),t.ArbiterType_SENSOR==null&&(t.ArbiterType_SENSOR=n()),t.ArbiterType_FLUID==null&&(t.ArbiterType_FLUID=n()),it.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID];}wrapper(){if(this.outer==null){let e=it._nape;it.internal=true,this.type==it.COL?(this.colarb.outer_zn=it._createColArb(),this.outer=this.colarb.outer_zn):this.type==it.FLUID?(this.fluidarb.outer_zn=it._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,it.internal=false;}return this.outer}inactiveme(){return !this.active}acting(){return this.active?(this.immState&1)!=0:false}swap_features(){let e=this.b1;this.b1=this.b2,this.b2=e,e=this.ws1,this.ws1=this.ws2,this.ws2=e,e=this.colarb.s1,this.colarb.s1=this.colarb.s2,this.colarb.s2=e;}lazyRetire(e,t){let n=it._zpp;this.cleared=true,(t==null||this.b2==t)&&it._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&it._removeFromArbiterList(this.b2.arbiters,this,n),this.pair!=null&&(this.pair.arb=null,this.pair=null),this.active=false,e.f_arbiters.modified=true;}sup_assign(e,t,n,s){let i=it._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=s,it._addToArbiterList(this.b1.arbiters,this,i),it._addToArbiterList(this.b2.arbiters,this,i),this.active=true,this.present=0,this.cleared=false,this.sleeping=false,this.fresh=false,this.presentable=false;}sup_retire(){let e=it._zpp;this.cleared||(it._removeFromArbiterList(this.b1.arbiters,this,e),it._removeFromArbiterList(this.b2.arbiters,this,e),this.pair!=null&&(this.pair.arb=null,this.pair=null)),this.b1=this.b2=null,this.active=false,this.intchange=false;}static _removeFromArbiterList(e,t,n){let s=null,i=e.head;for(;i!=null;){if(i.elt==t){let l,r;s==null?(l=e.head,r=l.next,e.head=r,e.head==null&&(e.pushmod=true)):(l=s.next,r=l.next,s.next=r,r==null&&(e.pushmod=true));let o=l;o.elt=null,o.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=o,e.modified=true,e.length--,e.pushmod=true;break}s=i,i=i.next;}}static _addToArbiterList(e,t,n){let s;n.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?s=new n.util.ZNPNode_ZPP_Arbiter:(s=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=s.next,s.next=null),s.elt=t;let i=s;i.next=e.head,e.head=i,e.modified=true,e.length++;}};it._nape=null,it._zpp=null,it.internal=false,it._createColArb=null,it._createFluidArb=null,it.COL=1,it.FLUID=4,it.SENSOR=2,it.types=[];var Ie=it;var Cs=class Cs extends Ie{constructor(){super(),this.next=null,this.type=Ie.SENSOR,this.sensorarb=this;}alloc(){}free(){}assign(e,t,n,s){this.sup_assign(e,t,n,s);}retire(){this.sup_retire(),this.next=Cs.zpp_pool,Cs.zpp_pool=this;}makemutable(){}makeimmutable(){}};Cs.zpp_pool=null;var Ot=Cs;var Ms=class Ms extends Ie{constructor(){super();this.outer_zn=null;this.centroidx=0;this.centroidy=0;this.overlap=0;this.r1x=0;this.r1y=0;this.r2x=0;this.r2y=0;this.nodrag=false;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=false;this.pre_dt=0;this.pre_dt=0,this.mutable=false,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=false,this.r2y=0,this.r2x=0,this.r1y=0,this.r1x=0,this.overlap=0,this.centroidy=0,this.centroidx=0,this.next=null,this.outer_zn=null,this.type=Ie.FLUID,this.fluidarb=this,this.buoyx=0,this.buoyy=0,this.pre_dt=-1;}alloc(){}free(){}position_validate(){if(!this.active)throw new Error("Error: Arbiter not currently in use");this.wrap_position.zpp_inner.x=this.centroidx,this.wrap_position.zpp_inner.y=this.centroidy;}position_invalidate(t){this.centroidx=t.x,this.centroidy=t.y;}getposition(){let t=Ie._zpp,n=Ie._nape,s;if(t.util.ZPP_PubPool.poolVec2==null?s=new n.geom.Vec2:(s=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=false,s==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;t.geom.ZPP_Vec2.zpp_pool==null?i=new t.geom.ZPP_Vec2:(i=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=false,i._immutable=false,i.x=0,i.y=0,s.zpp_inner=i,s.zpp_inner.outer=s;}else {if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");i._isimmutable!=null&&i._isimmutable();let l;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=s.zpp_inner;if(r._validate!=null&&r._validate(),s.zpp_inner.x==0){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=s.zpp_inner;o._validate!=null&&o._validate(),l=s.zpp_inner.y==0;}else l=false;if(!l){s.zpp_inner.x=0,s.zpp_inner.y=0;let o=s.zpp_inner;o._invalidate!=null&&o._invalidate(o);}}s.zpp_inner.weak=false,this.wrap_position=s,this.wrap_position.zpp_inner._inuse=true,this.wrap_position.zpp_inner._immutable=!this.mutable,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this),this.wrap_position.zpp_inner._invalidate=this.position_invalidate.bind(this);}assign(t,n,s,i){this.sup_assign(t,n,s,i),this.nx=0,this.ny=1,this.dampx=0,this.dampy=0,this.adamp=0;}retire(){this.sup_retire(),this.next=Ms.zpp_pool,Ms.zpp_pool=this,this.pre_dt=-1;}makemutable(){this.mutable=true,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=false);}makeimmutable(){this.mutable=false,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=true);}inject(t,n,s){this.overlap=t,this.centroidx=n,this.centroidy=s;}preStep(t,n){let s=Ie._nape;this.pre_dt==-1&&(this.pre_dt=n);let i=n/this.pre_dt;this.pre_dt=n,this.r1x=this.centroidx-this.b1.posx,this.r1y=this.centroidy-this.b1.posy,this.r2x=this.centroidx-this.b2.posx,this.r2y=this.centroidy-this.b2.posy;let l,r;this.ws1.fluidEnabled&&this.ws1.fluidProperties.wrap_gravity!=null?(l=this.ws1.fluidProperties.gravityx,r=this.ws1.fluidProperties.gravityy):(l=t.gravityx,r=t.gravityy);let o,a;this.ws2.fluidEnabled&&this.ws2.fluidProperties.wrap_gravity!=null?(o=this.ws2.fluidProperties.gravityx,a=this.ws2.fluidProperties.gravityy):(o=t.gravityx,a=t.gravityy);let p=0,c=0;if(this.ws1.fluidEnabled&&this.ws2.fluidEnabled){let h=this.overlap*this.ws1.fluidProperties.density,u=this.overlap*this.ws2.fluidProperties.density;if(h>u){let x=h+u;p-=l*x,c-=r*x;}else if(h<u){let x=h+u;p+=o*x,c+=a*x;}else {let x=l+o,m=r+a,_=.5;if(x*=_,m*=_,this.ws1.worldCOMx*x+this.ws1.worldCOMy*m>this.ws2.worldCOMx*x+this.ws2.worldCOMy*m){let y=h+u;p-=x*y,c-=m*y;}else {let y=h+u;p+=x*y,c+=m*y;}}}else if(this.ws1.fluidEnabled){let h=this.overlap*this.ws1.fluidProperties.density;p-=l*h,c-=r*h;}else if(this.ws2.fluidEnabled){let h=this.overlap*this.ws2.fluidProperties.density;p+=o*h,c+=a*h;}if(p*=n,c*=n,this.buoyx=p,this.buoyy=c,this.b1.type==2&&(this.b1.velx-=p*this.b1.imass,this.b1.vely-=c*this.b1.imass,this.b1.angvel-=(c*this.r1x-p*this.r1y)*this.b1.iinertia),this.b2.type==2&&(this.b2.velx+=p*this.b2.imass,this.b2.vely+=c*this.b2.imass,this.b2.angvel+=(c*this.r2x-p*this.r2y)*this.b2.iinertia),(!this.ws1.fluidEnabled||this.ws1.fluidProperties.viscosity==0)&&(!this.ws2.fluidEnabled||this.ws2.fluidProperties.viscosity==0))this.nodrag=true,this.dampx=0,this.dampy=0,this.adamp=0;else {this.nodrag=false;let h=0;if(this.ws1.fluidEnabled&&(this.ws2.validate_angDrag(),h+=this.ws1.fluidProperties.viscosity*this.ws2.angDrag*this.overlap/this.ws2.area),this.ws2.fluidEnabled&&(this.ws1.validate_angDrag(),h+=this.ws2.fluidProperties.viscosity*this.ws1.angDrag*this.overlap/this.ws1.area),h!=0){let _=this.b1.sinertia+this.b2.sinertia;_!=0?this.wMass=1/_:this.wMass=0,h*=4e-4;let y=2*Math.PI*h;this.agamma=1/(n*y*(2+y*n));let z=1/(1+this.agamma);this.agamma*=z,this.wMass*=z;}else this.wMass=0,this.agamma=0;let u=this.b2.velx+this.b2.kinvelx-this.r2y*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.r1y*(this.b2.angvel+this.b2.kinangvel)),x=this.b2.vely+this.b2.kinvely+this.r2x*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.r1x*(this.b1.angvel+this.b1.kinangvel));if(!(u*u+x*x<s.Config.epsilon*s.Config.epsilon)){let _=u*u+x*x,y=1/Math.sqrt(_);this.nx=u*y,this.ny=x*y;}let m=0;if(this.ws1.fluidEnabled){let _=-this.ws1.fluidProperties.viscosity*this.overlap/this.ws2.area;if(this.ws2.type==0)m-=_*this.ws2.circle.radius*s.Config.fluidLinearDrag/(2*this.ws2.circle.radius*Math.PI);else {let y=this.ws2.polygon,z=0,b=0,w=y.edges.head;for(;w!=null;){let Z=w.elt;z+=Z.length;let d=_*Z.length*(Z.gnormx*this.nx+Z.gnormy*this.ny);d>0&&(d*=-s.Config.fluidVacuumDrag),b-=d*.5*s.Config.fluidLinearDrag,w=w.next;}m+=b/z;}}if(this.ws2.fluidEnabled){let _=-this.ws2.fluidProperties.viscosity*this.overlap/this.ws1.area;if(this.ws1.type==0)m-=_*this.ws1.circle.radius*s.Config.fluidLinearDrag/(2*this.ws1.circle.radius*Math.PI);else {let y=this.ws1.polygon,z=0,b=0,w=y.edges.head;for(;w!=null;){let Z=w.elt;z+=Z.length;let d=_*Z.length*(Z.gnormx*this.nx+Z.gnormy*this.ny);d>0&&(d*=-s.Config.fluidVacuumDrag),b-=d*.5*s.Config.fluidLinearDrag,w=w.next;}m+=b/z;}}if(m!=0){let _=this.b1.smass+this.b2.smass,y=_,z=0,b=_;if(this.b1.sinertia!=0){let f=this.r1x*this.b1.sinertia,g=this.r1y*this.b1.sinertia;y+=g*this.r1y,z+=-g*this.r1x,b+=f*this.r1x;}if(this.b2.sinertia!=0){let f=this.r2x*this.b2.sinertia,g=this.r2y*this.b2.sinertia;y+=g*this.r2y,z+=-g*this.r2x,b+=f*this.r2x;}let w=y*b-z*z;if(w!==w)b=0,z=b,y=z;else if(w==0)y!=0?y=1/y:y=0,b!=0?b=1/b:b=0,z=0;else {let f=1/w,g=b*f;b=y*f,y=g,z*=-f;}this.vMassa=y,this.vMassb=z,this.vMassc=b;let Z=2*Math.PI*m;this.lgamma=1/(n*Z*(2+Z*n));let d=1/(1+this.lgamma);this.lgamma*=d,this.vMassa*=d,this.vMassb*=d,this.vMassc*=d;}else this.vMassa=0,this.vMassb=0,this.vMassc=0,this.lgamma=0;}this.dampx*=i,this.dampy*=i,this.adamp*=i;}warmStart(){this.b1.velx-=this.dampx*this.b1.imass,this.b1.vely-=this.dampy*this.b1.imass,this.b2.velx+=this.dampx*this.b2.imass,this.b2.vely+=this.dampy*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(this.dampy*this.r1x-this.dampx*this.r1y),this.b2.angvel+=this.b2.iinertia*(this.dampy*this.r2x-this.dampx*this.r2y),this.b1.angvel-=this.adamp*this.b1.iinertia,this.b2.angvel+=this.adamp*this.b2.iinertia;}applyImpulseVel(){if(!this.nodrag){let t=this.b1.angvel+this.b1.kinangvel,n=this.b2.angvel+this.b2.kinangvel,s=this.b1.velx+this.b1.kinvelx-this.r1y*t-(this.b2.velx+this.b2.kinvelx-this.r2y*n),i=this.b1.vely+this.b1.kinvely+this.r1x*t-(this.b2.vely+this.b2.kinvely+this.r2x*n),l=this.vMassa*s+this.vMassb*i;i=this.vMassb*s+this.vMassc*i,s=l,s-=this.dampx*this.lgamma,i-=this.dampy*this.lgamma,this.dampx+=s,this.dampy+=i,this.b1.velx-=s*this.b1.imass,this.b1.vely-=i*this.b1.imass,this.b2.velx+=s*this.b2.imass,this.b2.vely+=i*this.b2.imass,this.b1.angvel-=this.b1.iinertia*(i*this.r1x-s*this.r1y),this.b2.angvel+=this.b2.iinertia*(i*this.r2x-s*this.r2y);let r=(t-n)*this.wMass-this.adamp*this.agamma;this.adamp+=r,this.b1.angvel-=r*this.b1.iinertia,this.b2.angvel+=r*this.b2.iinertia;}}};Ms.zpp_pool=null;var Pt=Ms;var fi=class{constructor(){this.length=0;this.pushmod=false;this.modified=false;this._inuse=false;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=true,this.pushmod=true;}add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,this.length++,e}inlined_add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,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=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}inlined_insert(e,t){t._inuse=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){this.erase(t),s=true;break}t=n,n=n.next;}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}inlined_try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=true)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=true)),i._inuse=false,this.modified=true,this.length--,this.pushmod=true,s=true;break}t=n,n=n.next;}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,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=true,this.pushmod=true;}empty(){return this.next==null}size(){return this.length}has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;break}n=n.next;}return t}inlined_has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;break}n=n.next;}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};var mn=class mn{constructor(){this.outer=null;this.px=0;this.py=0;this.wrap_position=null;this.arbiter=null;this.active=false;this.posOnly=false;this.stamp=0;this.hash=0;this.fresh=false;this.dist=0;this.elasticity=0;this.length=0;this.pushmod=false;this.modified=false;this._inuse=false;this.next=null;this.length=0,this.pushmod=false,this.modified=false,this._inuse=false,this.next=null,this.elasticity=0,this.dist=0,this.fresh=false,this.hash=0,this.stamp=0,this.posOnly=false,this.active=false,this.inner=null,this.arbiter=null,this.wrap_position=null,this.py=0,this.px=0,this.outer=null,this.inner=new fi;}wrapper(){return this.outer==null&&(mn._wrapFn?this.outer=mn._wrapFn(this):(mn.internal=true,this.outer=new mn._nape.dynamics.Contact,mn.internal=false,this.outer.zpp_inner=this)),this.outer}position_validate(){if(this.inactiveme())throw new Error("Error: Contact not currently in use");this.wrap_position.zpp_inner.x=this.px,this.wrap_position.zpp_inner.y=this.py;}getposition(){let e=mn._zpp,t=mn._nape,n;if(e.util.ZPP_PubPool.poolVec2==null?n=new t.geom.Vec2:(n=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=false,n==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let s;e.geom.ZPP_Vec2.zpp_pool==null?s=new e.geom.ZPP_Vec2:(s=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=s.next,s.next=null),s.weak=false,s._immutable=false,s.x=0,s.y=0,n.zpp_inner=s,n.zpp_inner.outer=n;}else {if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y==0;}else i=false;if(!i){n.zpp_inner.x=0,n.zpp_inner.y=0;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r);}}n.zpp_inner.weak=false,this.wrap_position=n,this.wrap_position.zpp_inner._inuse=true,this.wrap_position.zpp_inner._immutable=true,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=true,this.pushmod=true;}add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,this.length++,e}inlined_add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,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=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}inlined_insert(e,t){t._inuse=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){this.erase(t),s=true;break}t=n,n=n.next;}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}inlined_try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=true)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=true)),i._inuse=false,this.modified=true,this.length--,this.pushmod=true,s=true;break}t=n,n=n.next;}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,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=true,this.pushmod=true;}empty(){return this.next==null}size(){return this.length}has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;break}n=n.next;}return t}inlined_has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;break}n=n.next;}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};mn._nape=null,mn._zpp=null,mn.zpp_pool=null,mn.internal=false,mn._wrapFn=null;var we=mn;var wt=class wt extends Ie{constructor(){super();this.outer_zn=null;this.dyn_fric=0;this.stat_fric=0;this.restitution=0;this.rfric=0;this.userdef_dyn_fric=false;this.userdef_stat_fric=false;this.userdef_restitution=false;this.userdef_rfric=false;this.s1=null;this.s2=null;this.wrap_contacts=null;this.nx=0;this.ny=0;this.wrap_normal=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.Ka=0;this.Kb=0;this.Kc=0;this.rMass=0;this.jrAcc=0;this.rn1a=0;this.rt1a=0;this.rn1b=0;this.rt1b=0;this.rn2a=0;this.rt2a=0;this.rn2b=0;this.rt2b=0;this.k1x=0;this.k1y=0;this.k2x=0;this.k2y=0;this.surfacex=0;this.surfacey=0;this.ptype=0;this.lnormx=0;this.lnormy=0;this.lproj=0;this.radius=0;this.rev=false;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=false;this.hpc2=false;this.stat=false;this.mutable=false;this.pre_dt=0;this.pre_dt=0,this.mutable=false,this.stat=false,this.next=null,this.hpc2=false,this.hc2=false,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=false,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=false,this.userdef_restitution=false,this.userdef_stat_fric=false,this.userdef_dyn_fric=false,this.rfric=0,this.restitution=0,this.stat_fric=0,this.dyn_fric=0,this.outer_zn=null,this.pre_dt=-1,this.contacts=new we,this.innards=new fi,this.type=Ie.COL,this.colarb=this;}alloc(){}free(){this.userdef_dyn_fric=false,this.userdef_stat_fric=false,this.userdef_restitution=false,this.userdef_rfric=false,this.__ref_edge1=this.__ref_edge2=null;}normal_validate(){if(this.cleared)throw new Error("Error: Arbiter not currently in use");this.wrap_normal.zpp_inner.x=this.nx,this.wrap_normal.zpp_inner.y=this.ny,this.ws1.id>this.ws2.id&&(this.wrap_normal.zpp_inner.x=-this.wrap_normal.zpp_inner.x,this.wrap_normal.zpp_inner.y=-this.wrap_normal.zpp_inner.y);}getnormal(){let t=Ie._zpp,n=Ie._nape,s=0,i=0,l;if(t.util.ZPP_PubPool.poolVec2==null?l=new n.geom.Vec2:(l=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let r;t.geom.ZPP_Vec2.zpp_pool==null?r=new t.geom.ZPP_Vec2:(r=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=s,r.y=i,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),i!==i);let o;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),o=l.zpp_inner.y==i;}else o=false;if(!o){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p);}}l.zpp_inner.weak=false,this.wrap_normal=l,this.wrap_normal.zpp_inner._immutable=true,this.wrap_normal.zpp_inner._inuse=true,this.wrap_normal.zpp_inner._validate=this.normal_validate.bind(this);}injectContact(t,n,s,i,l,r,o=false){let a=null,p=this.contacts.next;for(;p!=null;){if(r==p.hash){a=p;break}p=p.next;}if(a==null){we.zpp_pool==null?a=new we:(a=we.zpp_pool,we.zpp_pool=a.next,a.next=null);let c=a.inner;c.jnAcc=c.jtAcc=0,a.hash=r,a.fresh=true,a.arbiter=this,this.jrAcc=0,a._inuse=true,a.next=this.contacts.next,this.contacts.next=a,this.contacts.modified=true,this.contacts.length++,this.innards.add(c);}else a.fresh=false;return a.px=t,a.py=n,this.nx=s,this.ny=i,a.dist=l,a.stamp=this.stamp,a.posOnly=o,a}assign(t,n,s,i){this.sup_assign(t,n,s,i),this.s1=t,this.s2=n,this._calcFrictionRestitution();}calcProperties(){this._calcFrictionRestitution();}validate_props(){this.invalidated&&(this.invalidated=false,this._calcFrictionRestitution());}_calcFrictionRestitution(){this.userdef_restitution||(this.s1.material.elasticity<=-1/0||this.s2.material.elasticity<=-1/0?this.restitution=0:this.s1.material.elasticity>=1/0||this.s2.material.elasticity>=1/0?this.restitution=1:this.restitution=(this.s1.material.elasticity+this.s2.material.elasticity)/2,this.restitution<0&&(this.restitution=0),this.restitution>1&&(this.restitution=1)),this.userdef_dyn_fric||(this.dyn_fric=Math.sqrt(this.s1.material.dynamicFriction*this.s2.material.dynamicFriction)),this.userdef_stat_fric||(this.stat_fric=Math.sqrt(this.s1.material.staticFriction*this.s2.material.staticFriction)),this.userdef_rfric||(this.rfric=Math.sqrt(this.s1.material.rollingFriction*this.s2.material.rollingFriction));}retire(){for(this.sup_retire();this.contacts.next!=null;){let t=this.contacts.next;this.contacts.pop(),t.arbiter=null,t.next=we.zpp_pool,we.zpp_pool=t;let n=this.innards.next;this.innards.next=n.next,n._inuse=false,this.innards.next==null&&(this.innards.pushmod=true),this.innards.modified=true,this.innards.length--;}this.free(),this.next=wt.zpp_pool,wt.zpp_pool=this,this.pre_dt=-1;}makemutable(){this.mutable=true,this.wrap_normal!=null&&(this.wrap_normal.zpp_inner._immutable=false),this.wrap_contacts!=null&&(this.wrap_contacts.zpp_inner.immutable=false);}makeimmutable(){this.mutable=false,this.wrap_normal!=null&&(this.wrap_normal.zpp_inner._immutable=true),this.wrap_contacts!=null&&(this.wrap_contacts.zpp_inner.immutable=true);}contacts_adder(t){throw new Error("Error: Cannot add new contacts, information required is far too specific and detailed :)")}contacts_subber(t){let n=null,s=null,i=this.innards.next,l=this.contacts.next;for(;l!=null;){if(l==t.zpp_inner){this.contacts.erase(n),this.innards.erase(s),l.arbiter=null,l.next=we.zpp_pool,we.zpp_pool=l;break}n=l,s=i,i=i.next,l=l.next;}}setupcontacts(){let t=Ie._zpp;this.wrap_contacts=t.util.ZPP_ContactList.get(this.contacts,true),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=true,this.wrap_contacts.zpp_inner.subber=this.contacts_subber.bind(this);}cleanupContacts(){let t=Ie._nape,n=true,s=null,i=null,l=this.innards.next;this.hc2=false;let r=this.contacts.next;for(;r!=null;){let o=r;if(o.stamp+t.Config.arbiterExpirationDelay<this.stamp){r=wt._eraseFromList(this.contacts,s),l=wt._eraseFromList(this.innards,i),o.arbiter=null,o.next=we.zpp_pool,we.zpp_pool=o;continue}let a=o.inner,p=o.active;o.active=o.stamp==this.stamp,o.active&&(n?(n=false,this.c1=a,this.oc1=o):(this.hc2=true,this.c2=a,this.oc2=o)),p!=o.active&&(this.contacts.modified=true),s=r,i=l,l=l.next,r=r.next;}if(this.hc2){if(this.hpc2=true,this.oc1.posOnly){let o=this.c1;this.c1=this.c2,this.c2=o,o=this.oc1,this.oc1=this.oc2,this.oc2=o,this.hc2=false;}else this.oc2.posOnly&&(this.hc2=false);this.oc1.posOnly&&(n=true);}else this.hpc2=false;return n}preStep(t){let n=Ie._nape;this.validate_props(),this.pre_dt==-1&&(this.pre_dt=t);let s=t/this.pre_dt;this.pre_dt=t;let i=this.b1.smass+this.b2.smass;this.hc2=false;let l=true,o=this.b1.type!=2||this.b2.type!=2?this.continuous?n.Config.contactContinuousStaticBiasCoef:n.Config.contactStaticBiasCoef:this.continuous?n.Config.contactContinuousBiasCoef:n.Config.contactBiasCoef;this.biasCoef=o,this.continuous=false;let a=null,p=null,c=this.innards.next,h=this.contacts.next;for(;h!=null;){let u=h;if(u.stamp+n.Config.arbiterExpirationDelay<this.stamp){h=wt._eraseFromList(this.contacts,a),c=wt._eraseFromList(this.innards,p),u.arbiter=null,u.next=we.zpp_pool,we.zpp_pool=u;continue}let x=u.inner,m=u.active;if(u.active=u.stamp==this.stamp,u.active){l?(l=false,this.c1=x,this.oc1=u):(this.hc2=true,this.c2=x,this.oc2=u),x.r2x=u.px-this.b2.posx,x.r2y=u.py-this.b2.posy,x.r1x=u.px-this.b1.posx,x.r1y=u.py-this.b1.posy;let _=x.r2x*this.nx+x.r2y*this.ny,y=i+this.b2.sinertia*(_*_);_=x.r1x*this.nx+x.r1y*this.ny,y+=this.b1.sinertia*(_*_),x.tMass=y<n.Config.epsilon*n.Config.epsilon?0:1/y,_=this.ny*x.r2x-this.nx*x.r2y;let z=i+this.b2.sinertia*(_*_);_=this.ny*x.r1x-this.nx*x.r1y,z+=this.b1.sinertia*(_*_),x.nMass=z<n.Config.epsilon*n.Config.epsilon?0:1/z;let b=this.b2.angvel+this.b2.kinangvel,w=this.b2.velx+this.b2.kinvelx-x.r2y*b,Z=this.b2.vely+this.b2.kinvely+x.r2x*b;b=this.b1.angvel+this.b1.kinangvel,w-=this.b1.velx+this.b1.kinvelx-x.r1y*b,Z-=this.b1.vely+this.b1.kinvely+x.r1x*b;let d=this.nx*w+this.ny*Z;u.elasticity=this.restitution,x.bounce=d*u.elasticity,x.bounce>-n.Config.elasticThreshold&&(x.bounce=0);let f=Z*this.nx-w*this.ny,g=n.Config.staticFrictionThreshold;f*f>g*g?x.friction=this.dyn_fric:x.friction=this.stat_fric,x.jnAcc*=s,x.jtAcc*=s;}m!=u.active&&(this.contacts.modified=true),a=h,p=c,c=c.next,h=h.next;}if(this.hc2){if(this.hpc2=true,this.oc1.posOnly){let u=this.c1;this.c1=this.c2,this.c2=u,u=this.oc1,this.oc1=this.oc2,this.oc2=u,this.hc2=false;}else this.oc2.posOnly&&(this.hc2=false);this.oc1.posOnly&&(l=true);}else this.hpc2=false;if(this.jrAcc*=s,l||(this.rn1a=this.ny*this.c1.r1x-this.nx*this.c1.r1y,this.rt1a=this.c1.r1x*this.nx+this.c1.r1y*this.ny,this.rn1b=this.ny*this.c1.r2x-this.nx*this.c1.r2y,this.rt1b=this.c1.r2x*this.nx+this.c1.r2y*this.ny,this.k1x=this.b2.kinvelx-this.c1.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c1.r1y*this.b1.kinangvel),this.k1y=this.b2.kinvely+this.c1.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c1.r1x*this.b1.kinangvel)),this.hc2)if(this.rn2a=this.ny*this.c2.r1x-this.nx*this.c2.r1y,this.rt2a=this.c2.r1x*this.nx+this.c2.r1y*this.ny,this.rn2b=this.ny*this.c2.r2x-this.nx*this.c2.r2y,this.rt2b=this.c2.r2x*this.nx+this.c2.r2y*this.ny,this.k2x=this.b2.kinvelx-this.c2.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c2.r1y*this.b1.kinangvel),this.k2y=this.b2.kinvely+this.c2.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c2.r1x*this.b1.kinangvel),this.kMassa=i+this.b1.sinertia*this.rn1a*this.rn1a+this.b2.sinertia*this.rn1b*this.rn1b,this.kMassb=i+this.b1.sinertia*this.rn1a*this.rn2a+this.b2.sinertia*this.rn1b*this.rn2b,this.kMassc=i+this.b1.sinertia*this.rn2a*this.rn2a+this.b2.sinertia*this.rn2b*this.rn2b,this.kMassa*this.kMassa+2*this.kMassb*this.kMassb+this.kMassc*this.kMassc<n.Config.illConditionedThreshold*(this.kMassa*this.kMassc-this.kMassb*this.kMassb)){this.Ka=this.kMassa,this.Kb=this.kMassb,this.Kc=this.kMassc;let x=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(x!==x)this.kMassa=this.kMassb=this.kMassc=0;else if(x==0)this.kMassa!=0?this.kMassa=1/this.kMassa:this.kMassa=0,this.kMassc!=0?this.kMassc=1/this.kMassc:this.kMassc=0,this.kMassb=0;else {let m=1/x,_=this.kMassc*m;this.kMassc=this.kMassa*m,this.kMassa=_,this.kMassb*=-m;}}else {if(this.hc2=false,this.oc2.dist<this.oc1.dist){let x=this.c1;this.c1=this.c2,this.c2=x;}this.oc2.active=false,this.contacts.modified=true;}return this.surfacex=this.b2.svelx,this.surfacey=this.b2.svely,this.surfacex+=this.b1.svelx,this.surfacey+=this.b1.svely,this.surfacex=-this.surfacex,this.surfacey=-this.surfacey,this.rMass=this.b1.sinertia+this.b2.sinertia,this.rMass!=0&&(this.rMass=1/this.rMass),l}warmStart(){let t=this.nx*this.c1.jnAcc-this.ny*this.c1.jtAcc,n=this.ny*this.c1.jnAcc+this.nx*this.c1.jtAcc;this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c1.r1x-t*this.c1.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c1.r2x-t*this.c1.r2y),this.hc2&&(t=this.nx*this.c2.jnAcc-this.ny*this.c2.jtAcc,n=this.ny*this.c2.jnAcc+this.nx*this.c2.jtAcc,this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c2.r1x-t*this.c2.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c2.r2x-t*this.c2.r2y)),this.b2.angvel+=this.jrAcc*this.b2.iinertia,this.b1.angvel-=this.jrAcc*this.b1.iinertia;}applyImpulseVel(){let t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),s=(n*this.nx-t*this.ny+this.surfacex)*this.c1.tMass,i=this.c1.friction*this.c1.jnAcc,l=this.c1.jtAcc,r=l-s;r>i?r=i:r<-i&&(r=-i),s=r-l,this.c1.jtAcc=r;let o=-this.ny*s,a=this.nx*s;if(this.b2.velx+=o*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=o*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rt1b*s*this.b2.iinertia,this.b1.angvel-=this.rt1a*s*this.b1.iinertia,this.hc2){let p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);s=(c*this.nx-p*this.ny+this.surfacex)*this.c2.tMass,i=this.c2.friction*this.c2.jnAcc,l=this.c2.jtAcc,r=l-s,r>i?r=i:r<-i&&(r=-i),s=r-l,this.c2.jtAcc=r,o=-this.ny*s,a=this.nx*s,this.b2.velx+=o*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=o*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rt2b*s*this.b2.iinertia,this.b1.angvel-=this.rt2a*s*this.b1.iinertia,t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);let h=this.c1.jnAcc,u=this.c2.jnAcc,x=t*this.nx+n*this.ny+this.surfacey+this.c1.bounce-(this.Ka*h+this.Kb*u),m=p*this.nx+c*this.ny+this.surfacey+this.c2.bounce-(this.Kb*h+this.Kc*u),_=-(this.kMassa*x+this.kMassb*m),y=-(this.kMassb*x+this.kMassc*m);_>=0&&y>=0?(x=_-h,m=y-u,this.c1.jnAcc=_,this.c2.jnAcc=y):(_=-this.c1.nMass*x,_>=0&&this.Kb*_+m>=0?(x=_-h,m=-u,this.c1.jnAcc=_,this.c2.jnAcc=0):(y=-this.c2.nMass*m,y>=0&&this.Kb*y+x>=0?(x=-h,m=y-u,this.c1.jnAcc=0,this.c2.jnAcc=y):x>=0&&m>=0?(x=-h,m=-u,this.c1.jnAcc=this.c2.jnAcc=0):(x=0,m=0))),s=x+m,o=this.nx*s,a=this.ny*s,this.b2.velx+=o*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=o*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=(this.rn1b*x+this.rn2b*m)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*x+this.rn2a*m)*this.b1.iinertia;}else this.radius!=0&&(s=(this.b2.angvel-this.b1.angvel)*this.rMass,i=this.rfric*this.c1.jnAcc,l=this.jrAcc,this.jrAcc-=s,this.jrAcc>i?this.jrAcc=i:this.jrAcc<-i&&(this.jrAcc=-i),s=this.jrAcc-l,this.b2.angvel+=s*this.b2.iinertia,this.b1.angvel-=s*this.b1.iinertia),t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),s=(this.c1.bounce+(this.nx*t+this.ny*n)+this.surfacey)*this.c1.nMass,l=this.c1.jnAcc,r=l-s,r<0&&(r=0),s=r-l,this.c1.jnAcc=r,o=this.nx*s,a=this.ny*s,this.b2.velx+=o*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=o*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rn1b*s*this.b2.iinertia,this.b1.angvel-=this.rn1a*s*this.b1.iinertia;}applyImpulsePos(){let t=Ie._nape;this.ptype==2?this._applyImpulsePosCircle(t):this._applyImpulsePosEdge(t);}_applyImpulsePosCircle(t){let n=this.c1,s=this.b2.axisy*n.lr2x-this.b2.axisx*n.lr2y,i=n.lr2x*this.b2.axisx+n.lr2y*this.b2.axisy;s+=this.b2.posx,i+=this.b2.posy;let l=this.b1.axisy*n.lr1x-this.b1.axisx*n.lr1y,r=n.lr1x*this.b1.axisx+n.lr1y*this.b1.axisy;l+=this.b1.posx,r+=this.b1.posy;let o=s-l,a=i-r,p=Math.sqrt(o*o+a*a),c=this.radius-t.Config.collisionSlop,h=p-c;if(o*this.nx+a*this.ny<0&&(o=-o,a=-a,h-=this.radius),h<0)if(p<t.Config.epsilon)this.b1.smass!=0?this.b1.posx+=t.Config.epsilon*10:this.b2.posx+=t.Config.epsilon*10;else {let u=1/p;o*=u,a*=u;let x=.5*(l+s),m=.5*(r+i),_=p-c;l=x-this.b1.posx,r=m-this.b1.posy,s=x-this.b2.posx,i=m-this.b2.posy;let y=a*l-o*r,z=a*s-o*i,b=this.b2.smass+z*z*this.b2.sinertia+this.b1.smass+y*y*this.b1.sinertia;if(b!=0){let w=-this.biasCoef*_/b,Z=o*w,d=a*w;this.b1.posx-=Z*this.b1.imass,this.b1.posy-=d*this.b1.imass,wt._rotateBody(this.b1,-y*this.b1.iinertia*w),this.b2.posx+=Z*this.b2.imass,this.b2.posy+=d*this.b2.imass,wt._rotateBody(this.b2,z*this.b2.iinertia*w);}}}_applyImpulsePosEdge(t){let n,s,i,l,r,o=0,a=0;this.ptype==0?(n=this.b1.axisy*this.lnormx-this.b1.axisx*this.lnormy,s=this.lnormx*this.b1.axisx+this.lnormy*this.b1.axisy,i=this.lproj+(n*this.b1.posx+s*this.b1.posy),l=this.b2.axisy*this.c1.lr1x-this.b2.axisx*this.c1.lr1y,r=this.c1.lr1x*this.b2.axisx+this.c1.lr1y*this.b2.axisy,l+=this.b2.posx,r+=this.b2.posy,this.hpc2&&(o=this.b2.axisy*this.c2.lr1x-this.b2.axisx*this.c2.lr1y,a=this.c2.lr1x*this.b2.axisx+this.c2.lr1y*this.b2.axisy,o+=this.b2.posx,a+=this.b2.posy)):(n=this.b2.axisy*this.lnormx-this.b2.axisx*this.lnormy,s=this.lnormx*this.b2.axisx+this.lnormy*this.b2.axisy,i=this.lproj+(n*this.b2.posx+s*this.b2.posy),l=this.b1.axisy*this.c1.lr1x-this.b1.axisx*this.c1.lr1y,r=this.c1.lr1x*this.b1.axisx+this.c1.lr1y*this.b1.axisy,l+=this.b1.posx,r+=this.b1.posy,this.hpc2&&(o=this.b1.axisy*this.c2.lr1x-this.b1.axisx*this.c2.lr1y,a=this.c2.lr1x*this.b1.axisx+this.c2.lr1y*this.b1.axisy,o+=this.b1.posx,a+=this.b1.posy));let p=l*n+r*s-i-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=o*n+a*s-i-this.radius,c+=t.Config.collisionSlop),p<0||c<0){this.rev&&(n=-n,s=-s);let h=l-this.b1.posx,u=r-this.b1.posy,x=l-this.b2.posx,m=r-this.b2.posy;if(this.hpc2){let _=o-this.b1.posx,y=a-this.b1.posy,z=o-this.b2.posx,b=a-this.b2.posy,w=s*h-n*u,Z=s*x-n*m,d=s*_-n*y,f=s*z-n*b,g=this.b1.smass+this.b2.smass;this.kMassa=g+this.b1.sinertia*w*w+this.b2.sinertia*Z*Z,this.kMassb=g+this.b1.sinertia*w*d+this.b2.sinertia*Z*f,this.kMassc=g+this.b1.sinertia*d*d+this.b2.sinertia*f*f;let P=this.kMassa,v=this.kMassb,N=this.kMassc,E=p*this.biasCoef,M=c*this.biasCoef;for(;;){let k=-E,C=-M,S=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(S!==S)k=0,C=0;else if(S==0)this.kMassa!=0?k/=this.kMassa:k=0,this.kMassc!=0?C/=this.kMassc:C=0;else {let O=1/S,F=O*(this.kMassc*k-this.kMassb*C);C=O*(this.kMassa*C-this.kMassb*k),k=F;}if(k>=0&&C>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,k,C,w,d,Z,f);break}if(k=-E/P,C=0,k>=0&&v*k+M>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,k,C,w,d,Z,f);break}if(k=0,C=-M/N,C>=0&&v*C+E>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,k,C,w,d,Z,f);break}break}}else {let _=s*h-n*u,y=s*x-n*m,z=this.b2.smass+y*y*this.b2.sinertia+this.b1.smass+_*_*this.b1.sinertia;if(z!=0){let b=-this.biasCoef*p/z,w=n*b,Z=s*b;this.b1.posx-=w*this.b1.imass,this.b1.posy-=Z*this.b1.imass,wt._rotateBody(this.b1,-_*this.b1.iinertia*b),this.b2.posx+=w*this.b2.imass,this.b2.posy+=Z*this.b2.imass,wt._rotateBody(this.b2,y*this.b2.iinertia*b);}}}}static _eraseFromList(t,n){let s,i;return n==null?(s=t.next,i=s.next,t.next=i,t.next==null&&(t.pushmod=true)):(s=n.next,i=s.next,n.next=i,i==null&&(t.pushmod=true)),s._inuse=false,t.modified=true,t.length--,t.pushmod=true,i}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else {let s=n*n,i=1-.5*s,l=1-s*s/8,r=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=r;}}static _applyPosImpulse2(t,n,s,i,l,r,o,a,p,c){let h=(l+r)*t.imass;t.posx-=s*h,t.posy-=i*h,wt._rotateBody(t,-t.iinertia*(o*l+a*r));let u=(l+r)*n.imass;n.posx+=s*u,n.posy+=i*u,wt._rotateBody(n,n.iinertia*(p*l+c*r));}};wt.FACE1=0,wt.FACE2=1,wt.CIRCLE=2,wt.zpp_pool=null;var ut=wt;var Ut=class Ut{constructor(){this.collisionGroup=1;this.collisionMask=-1;this.sensorGroup=1;this.sensorMask=-1;this.fluidGroup=1;this.fluidMask=-1;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new Ut._zpp.util.ZNPList_ZPP_Shape;}wrapper(){if(this.outer==null)if(Ut._wrapFn)this.outer=Ut._wrapFn(this);else {this.outer=new Ut._nape.dynamics.InteractionFilter;let e=this.outer.zpp_inner;e.outer=null,e.next=Ut.zpp_pool,Ut.zpp_pool=e,this.outer.zpp_inner=this;}return this.outer}free(){this.outer=null;}alloc(){}feature_cons(){this.shapes=new Ut._zpp.util.ZNPList_ZPP_Shape;}addShape(e){this.shapes.add(e);}remShape(e){this.shapes.remove(e);}copy(){let e;return Ut.zpp_pool==null?e=new Ut:(e=Ut.zpp_pool,Ut.zpp_pool=e.next,e.next=null),e.collisionGroup=this.collisionGroup,e.collisionMask=this.collisionMask,e.sensorGroup=this.sensorGroup,e.sensorMask=this.sensorMask,e.fluidGroup=this.fluidGroup,e.fluidMask=this.fluidMask,e}shouldCollide(e){return (this.collisionMask&e.collisionGroup)!==0&&(e.collisionMask&this.collisionGroup)!==0}shouldSense(e){return (this.sensorMask&e.sensorGroup)!==0&&(e.sensorMask&this.sensorGroup)!==0}shouldFlow(e){return (this.fluidMask&e.fluidGroup)!==0&&(e.fluidMask&this.fluidGroup)!==0}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_filter(),e=e.next;}};Ut.zpp_pool=null,Ut._nape=null,Ut._zpp=null,Ut._wrapFn=null;var st=Ut;var Ai=class Ai{constructor(){this.outer=null;this.ignore=false;this.group=null;this.groups=null;this.wrap_groups=null;this.interactors=null;this.wrap_interactors=null;this.depth=0;let e=Ai._zpp;this.groups=new e.util.ZNPList_ZPP_InteractionGroup,this.interactors=new e.util.ZNPList_ZPP_Interactor;}setGroup(e){this.group!==e&&(this.group!=null&&(this.group.groups.remove(this),this.depth=0,this.group.invalidate(true)),this.group=e,e!=null?(e.groups.add(this),this.depth=e.depth+1,e.invalidate(true)):this.invalidate(true));}invalidate(e){if(e==null&&(e=false),!(e||this.ignore))return;let t=this.interactors.head;for(;t!=null;){let s=t.elt;s.ibody!=null?s.ibody.wake():s.ishape!=null?s.ishape.body.wake():s.icompound.wake(),t=t.next;}let n=this.groups.head;for(;n!=null;)n.elt.invalidate(e),n=n.next;}addGroup(e){this.groups.add(e),e.depth=this.depth+1;}remGroup(e){this.groups.remove(e),e.depth=0;}addInteractor(e){this.interactors.add(e);}remInteractor(e,t){this.interactors.remove(e);}};Ai.SHAPE=1,Ai.BODY=2,Ai._zpp=null,Ai._wrapFn=null;var Zs=Ai;var Hn=class{constructor(){this.zpp_inner=null;this.space=null;this._length=0;this.zip_length=false;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=true,this._length=0,this.lengths=[],this.lengths.push(0),this.lengths.push(0),this.lengths.push(0),this.lengths.push(0);}zpp_gl(){if(this.zpp_vm(),this.zip_length){this._length=0;let e=0,t=0,n=this.space.c_arbiters_true.head;for(;n!=null;)n.elt.active&&++t,n=n.next;this.lengths[e++]=t,this._length+=t;let s=0,i=this.space.c_arbiters_false.head;for(;i!=null;)i.elt.active&&++s,i=i.next;this.lengths[e++]=s,this._length+=s;let l=0,r=this.space.f_arbiters.head;for(;r!=null;)r.elt.active&&++l,r=r.next;this.lengths[e++]=l,this._length+=l;let o=0,a=this.space.s_arbiters.head;for(;a!=null;)a.elt.active&&++o,a=a.next;this.lengths[e++]=o,this._length+=o,this.zip_length=false;}return this._length}zpp_vm(){let e=false;this.space.c_arbiters_true.modified&&(e=true,this.space.c_arbiters_true.modified=false),this.space.c_arbiters_false.modified&&(e=true,this.space.c_arbiters_false.modified=false),this.space.f_arbiters.modified&&(e=true,this.space.f_arbiters.modified=false),this.space.s_arbiters.modified&&(e=true,this.space.s_arbiters.modified=false),e&&(this.zip_length=true,this._length=0,this.ite_0=null,this.ite_1=null,this.ite_2=null,this.ite_3=null);}push(e){throw new Error("Error: ArbiterList is immutable")}pop(){throw new Error("Error: ArbiterList is immutable")}unshift(e){throw new Error("Error: ArbiterList is immutable")}shift(){throw new Error("Error: ArbiterList is immutable")}remove(e){throw new Error("Error: ArbiterList is immutable")}clear(){throw new Error("Error: ArbiterList is immutable")}at(e){if(this.zpp_vm(),e<0||e>=this.zpp_gl())throw new Error("Error: Index out of bounds");let t=null,n=0;if(t==null)if(e<n+this.lengths[0]){let s=e-n;if(s<this.at_index_0||this.ite_0==null)for(this.at_index_0=0,this.ite_0=this.space.c_arbiters_true.head;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;for(;this.at_index_0!=s;)for(this.at_index_0++,this.ite_0=this.ite_0.next;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;t=this.ite_0.elt.wrapper();}else n+=this.lengths[0];if(t==null)if(e<n+this.lengths[1]){let s=e-n;if(s<this.at_index_1||this.ite_1==null)for(this.at_index_1=0,this.ite_1=this.space.c_arbiters_false.head;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;for(;this.at_index_1!=s;)for(this.at_index_1++,this.ite_1=this.ite_1.next;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;t=this.ite_1.elt.wrapper();}else n+=this.lengths[1];if(t==null)if(e<n+this.lengths[2]){let s=e-n;if(s<this.at_index_2||this.ite_2==null)for(this.at_index_2=0,this.ite_2=this.space.f_arbiters.head;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;for(;this.at_index_2!=s;)for(this.at_index_2++,this.ite_2=this.ite_2.next;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;t=this.ite_2.elt.wrapper();}else n+=this.lengths[2];if(t==null)if(e<n+this.lengths[3]){let s=e-n;if(s<this.at_index_3||this.ite_3==null)for(this.at_index_3=0,this.ite_3=this.space.s_arbiters.head;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;for(;this.at_index_3!=s;)for(this.at_index_3++,this.ite_3=this.ite_3.next;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;t=this.ite_3.elt.wrapper();}else n+=this.lengths[3];return t}};Hn._nape=null,Hn._zpp=null;var Mt=class Mt{constructor(){this._invalidate=null;this._validate=null;this._immutable=false;this.outer=null;this.next=null;this.minx=0;this.miny=0;this.maxx=0;this.maxy=0;this.wrap_min=null;this.wrap_max=null;}static get(e,t,n,s){let i;return Mt.zpp_pool==null?i=new Mt:(i=Mt.zpp_pool,Mt.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=t,i.maxx=n,i.maxy=s,i}validate(){this._validate!=null&&this._validate();}invalidate(){this._invalidate!=null&&this._invalidate(this);}wrapper(){if(this.outer==null)if(Mt._wrapFn)this.outer=Mt._wrapFn(this);else {this.outer=new Mt._nape.geom.AABB;let e=this.outer.zpp_inner;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e.wrap_min=e.wrap_max=null,e._invalidate=null,e._validate=null,e.next=Mt.zpp_pool,Mt.zpp_pool=e,this.outer.zpp_inner=this;}return this.outer}alloc(){}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this.wrap_min=this.wrap_max=null,this._invalidate=null,this._validate=null;}copy(){return Mt.get(this.minx,this.miny,this.maxx,this.maxy)}width(){return this.maxx-this.minx}height(){return this.maxy-this.miny}perimeter(){return (this.maxx-this.minx+(this.maxy-this.miny))*2}static _makeVec2Wrapper(e,t){let n=Mt._zpp,s=Mt._nape;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new s.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=false,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;n.geom.ZPP_Vec2.zpp_pool==null?l=new n.geom.ZPP_Vec2:(l=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=false,l.x=e,l.y=t,i.zpp_inner=l,i.zpp_inner.outer=i;}else {if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");l._validate!=null&&l._validate(),(l.x!==e||l.y!==t)&&(l.x=e,l.y=t,l._invalidate!=null&&l._invalidate(l));}return i.zpp_inner.weak=false,i}getmin(){this.wrap_min==null&&(this.wrap_min=Mt._makeVec2Wrapper(this.minx,this.miny),this.wrap_min.zpp_inner._inuse=true,this._immutable?this.wrap_min.zpp_inner._immutable=true:this.wrap_min.zpp_inner._invalidate=this.mod_min.bind(this),this.wrap_min.zpp_inner._validate=this.dom_min.bind(this));}dom_min(){this._validate!=null&&this._validate(),this.wrap_min.zpp_inner.x=this.minx,this.wrap_min.zpp_inner.y=this.miny;}mod_min(e){(e.x!==this.minx||e.y!==this.miny)&&(this.minx=e.x,this.miny=e.y,this._invalidate!=null&&this._invalidate(this));}getmax(){this.wrap_max==null&&(this.wrap_max=Mt._makeVec2Wrapper(this.maxx,this.maxy),this.wrap_max.zpp_inner._inuse=true,this._immutable?this.wrap_max.zpp_inner._immutable=true:this.wrap_max.zpp_inner._invalidate=this.mod_max.bind(this),this.wrap_max.zpp_inner._validate=this.dom_max.bind(this));}dom_max(){this._validate!=null&&this._validate(),this.wrap_max.zpp_inner.x=this.maxx,this.wrap_max.zpp_inner.y=this.maxy;}mod_max(e){(e.x!==this.maxx||e.y!==this.maxy)&&(this.maxx=e.x,this.maxy=e.y,this._invalidate!=null&&this._invalidate(this));}intersectX(e){return !(e.minx>this.maxx||this.minx>e.maxx)}intersectY(e){return !(e.miny>this.maxy||this.miny>e.maxy)}intersect(e){return e.miny<=this.maxy&&this.miny<=e.maxy&&e.minx<=this.maxx&&this.minx<=e.maxx}combine(e){e.minx<this.minx&&(this.minx=e.minx),e.maxx>this.maxx&&(this.maxx=e.maxx),e.miny<this.miny&&(this.miny=e.miny),e.maxy>this.maxy&&(this.maxy=e.maxy);}contains(e){return e.minx>=this.minx&&e.miny>=this.miny&&e.maxx<=this.maxx&&e.maxy<=this.maxy}containsPoint(e){return e.x>=this.minx&&e.x<=this.maxx&&e.y>=this.miny&&e.y<=this.maxy}setCombine(e,t){this.minx=e.minx<t.minx?e.minx:t.minx,this.miny=e.miny<t.miny?e.miny:t.miny,this.maxx=e.maxx>t.maxx?e.maxx:t.maxx,this.maxy=e.maxy>t.maxy?e.maxy:t.maxy;}setExpand(e,t){this.minx=e.minx-t,this.miny=e.miny-t,this.maxx=e.maxx+t,this.maxy=e.maxy+t;}setExpandPoint(e,t){e<this.minx&&(this.minx=e),e>this.maxx&&(this.maxx=e),t<this.miny&&(this.miny=t),t>this.maxy&&(this.maxy=t);}toString(){return "{ x: "+this.minx+" y: "+this.miny+" w: "+(this.maxx-this.minx)+" h: "+(this.maxy-this.miny)+" }"}};Mt.zpp_pool=null,Mt._nape=null,Mt._zpp=null,Mt._wrapFn=null;var be=Mt;var Me=class Me{static _initStatics(e){Me.flowpoly=new e.util.ZNPList_ZPP_Vec2,Me.flowsegs=new e.util.ZNPList_ZPP_Vec2;}static circleContains(e,t){let n=t.x-e.worldCOMx,s=t.y-e.worldCOMy;return n*n+s*s<e.radius*e.radius}static polyContains(e,t){let n;n=true;let s=e.edges.head;for(;s!=null;){let i=s.elt;if(i.gnormx*t.x+i.gnormy*t.y<=i.gprojection){s=s.next;continue}else {n=false;break}}return n}static shapeContains(e,t){return e.type==0?Me.circleContains(e.circle,t):Me.polyContains(e.polygon,t)}static bodyContains(e,t){let n;n=false;let s=e.shapes.head;for(;s!=null;){let i=s.elt;if(Me.shapeContains(i,t)){n=true;break}s=s.next;}return n}static containTest(e,t){let n=e.aabb,s=t.aabb;if(s.minx>=n.minx&&s.miny>=n.miny&&s.maxx<=n.maxx&&s.maxy<=n.maxy)if(e.type==0)if(t.type==0){let i=e.circle.radius+-t.circle.radius,l=t.circle.worldCOMx-e.circle.worldCOMx,r=t.circle.worldCOMy-e.circle.worldCOMy;return l*l+r*r<=i*i}else {let i;i=true;let l=t.polygon.gverts.next;for(;l!=null;){let r=l,o=e.circle.radius,a=r.x-e.circle.worldCOMx,p=r.y-e.circle.worldCOMy;if(a*a+p*p<=o*o){l=l.next;continue}else {i=false;break}}return i}else if(t.type==0){let i;i=true;let l=e.polygon.edges.head;for(;l!=null;){let r=l.elt;if(r.gnormx*t.circle.worldCOMx+r.gnormy*t.circle.worldCOMy+t.circle.radius<=r.gprojection){l=l.next;continue}else {i=false;break}}return i}else {let i;i=true;let l=e.polygon.edges.head;for(;l!=null;){let r=l.elt,o=-1e100,a=t.polygon.gverts.next;for(;a!=null;){let p=a,c=r.gnormx*p.x+r.gnormy*p.y;c>o&&(o=c),a=a.next;}if(o<=r.gprojection){l=l.next;continue}else {i=false;break}}return i}else return false}static contactCollide(e,t,n,s){let i=_e();if(t.type==1)if(e.type==1){let l=true,r=-1e100,a=-1,p=null,c=null,h=e.polygon.edges.head;for(;h!=null;){let u=h.elt,x=1e100,m=t.polygon.gverts.next;for(;m!=null;){let _=m,y=u.gnormx*_.x+u.gnormy*_.y;if(y<x&&(x=y),x-u.gprojection<=r)break;m=m.next;}if(x-=u.gprojection,x>=0){l=false;break}x>r&&(r=x,p=u,a=1),h=h.next;}if(l){let u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,m=1e100,_=e.polygon.gverts.next;for(;_!=null;){let y=_,z=x.gnormx*y.x+x.gnormy*y.y;if(z<m&&(m=z),m-x.gprojection<=r)break;_=_.next;}if(m-=x.gprojection,m>=0){l=false;break}m>r&&(r=m,c=x,a=2),u=u.next;}if(l){let m,_,y;a==1?(e.polygon,m=t.polygon,_=p,y=1):(t.polygon,m=e.polygon,_=c,y=-1);let z=null,b=1e100,w=m.edges.head;for(;w!=null;){let W=w.elt,G=_.gnormx*W.gnormx+_.gnormy*W.gnormy;G<b&&(b=G,z=W),w=w.next;}let Z=z.gp0.x,d=z.gp0.y,f=z.gp1.x,g=z.gp1.y,P=f-Z,v=g-d,N=_.gnormy*Z-_.gnormx*d,E=_.gnormy*f-_.gnormx*g,M=1/(E-N),k=(-_.tp1-N)*M;if(k>i.Config.epsilon){let W=k;Z+=P*W,d+=v*W;}let C=(-_.tp0-E)*M;if(C<-i.Config.epsilon){let W=C;f+=P*W,g+=v*W;}let S=y,O=_.gnormx*S,F=_.gnormy*S;n.lnormx=_.lnormx,n.lnormy=_.lnormy,n.lproj=_.lprojection,n.radius=0,n.rev=s!=(y==-1),n.ptype=n.rev?1:0;let T=Z*_.gnormx+d*_.gnormy-_.gprojection,R=f*_.gnormx+g*_.gnormy-_.gprojection;if(T>0&&R>0)return false;{s&&(O=-O,F=-F);let W=Z-_.gnormx*T*.5,G=d-_.gnormy*T*.5,B=n.rev?1:0,A=T>0;A==null&&(A=false);let Y=null,$=n.contacts.next;for(;$!=null;){let K=$;if(B==K.hash){Y=K;break}$=$.next;}if(Y==null){we.zpp_pool==null?Y=new we:(Y=we.zpp_pool,we.zpp_pool=Y.next,Y.next=null);let K=Y.inner;K.jnAcc=K.jtAcc=0,Y.hash=B,Y.fresh=true,Y.arbiter=n,n.jrAcc=0;let ie=n.contacts;Y._inuse=true;let oe=Y;oe.next=ie.next,ie.next=oe,ie.modified=true,ie.length++,n.innards.add(K);}else Y.fresh=false;Y.px=W,Y.py=G,n.nx=O,n.ny=F,Y.dist=T,Y.stamp=n.stamp,Y.posOnly=A;let H=Y,X=1;Z-=m.body.posx*X,d-=m.body.posy*X,H.inner.lr1x=Z*m.body.axisy+d*m.body.axisx,H.inner.lr1y=d*m.body.axisy-Z*m.body.axisx;let ee=f-_.gnormx*R*.5,q=g-_.gnormy*R*.5,D=n.rev?0:1,L=R>0;L==null&&(L=false);let V=null,U=n.contacts.next;for(;U!=null;){let K=U;if(D==K.hash){V=K;break}U=U.next;}if(V==null){we.zpp_pool==null?V=new we:(V=we.zpp_pool,we.zpp_pool=V.next,V.next=null);let K=V.inner;K.jnAcc=K.jtAcc=0,V.hash=D,V.fresh=true,V.arbiter=n,n.jrAcc=0;let ie=n.contacts;V._inuse=true;let oe=V;oe.next=ie.next,ie.next=oe,ie.modified=true,ie.length++,n.innards.add(K);}else V.fresh=false;V.px=ee,V.py=q,n.nx=O,n.ny=F,V.dist=R,V.stamp=n.stamp,V.posOnly=L,H=V;let Q=1;return f-=m.body.posx*Q,g-=m.body.posy*Q,H.inner.lr1x=f*m.body.axisy+g*m.body.axisx,H.inner.lr1y=g*m.body.axisy-f*m.body.axisx,a==1?(n.__ref_edge1=_,n.__ref_edge2=z):(n.__ref_edge2=_,n.__ref_edge1=z),true}}else return false}else return false}else {let l=-1e100,o=true,a=null,p=null,c=t.polygon.gverts.next,h=t.polygon.edges.head;for(;h!=null;){let u=h.elt,x=u.gnormx*e.circle.worldCOMx+u.gnormy*e.circle.worldCOMy-u.gprojection-e.circle.radius;if(x>0){o=false;break}x>l&&(l=x,a=u,p=c),c=c.next,h=h.next;}if(o){let u=p,x=p.next==null?t.polygon.gverts.next:p.next,m=e.circle.worldCOMy*a.gnormx-e.circle.worldCOMx*a.gnormy;if(m<=u.y*a.gnormx-u.x*a.gnormy){let _=e.circle.radius,y=u.x-e.circle.worldCOMx,z=u.y-e.circle.worldCOMy,b=y*y+z*z,w;if(b>_*_)w=null;else if(b<i.Config.epsilon*i.Config.epsilon){let Z=e.circle.worldCOMx,d=e.circle.worldCOMy,f=null,g=n.contacts.next;for(;g!=null;){let P=g;if(P.hash==0){f=P;break}g=g.next;}if(f==null){we.zpp_pool==null?f=new we:(f=we.zpp_pool,we.zpp_pool=f.next,f.next=null);let P=f.inner;P.jnAcc=P.jtAcc=0,f.hash=0,f.fresh=true,f.arbiter=n,n.jrAcc=0;let v=n.contacts;f._inuse=true;let N=f;N.next=v.next,v.next=N,v.modified=true,v.length++,n.innards.add(P);}else f.fresh=false;f.px=Z,f.py=d,n.nx=1,n.ny=0,f.dist=-_,f.stamp=n.stamp,f.posOnly=false,w=f;}else {let Z=1/Math.sqrt(b),d=Z<i.Config.epsilon?1e100:1/Z,f=.5+(e.circle.radius-.5*_)*Z;if(s){let g=e.circle.worldCOMx+y*f,P=e.circle.worldCOMy+z*f,v=null,N=n.contacts.next;for(;N!=null;){let E=N;if(E.hash==0){v=E;break}N=N.next;}if(v==null){we.zpp_pool==null?v=new we:(v=we.zpp_pool,we.zpp_pool=v.next,v.next=null);let E=v.inner;E.jnAcc=E.jtAcc=0,v.hash=0,v.fresh=true,v.arbiter=n,n.jrAcc=0;let M=n.contacts;v._inuse=true;let k=v;k.next=M.next,M.next=k,M.modified=true,M.length++,n.innards.add(E);}else v.fresh=false;v.px=g,v.py=P,n.nx=-y*Z,n.ny=-z*Z,v.dist=d-_,v.stamp=n.stamp,v.posOnly=false,w=v;}else {let g=e.circle.worldCOMx+y*f,P=e.circle.worldCOMy+z*f,v=null,N=n.contacts.next;for(;N!=null;){let E=N;if(E.hash==0){v=E;break}N=N.next;}if(v==null){we.zpp_pool==null?v=new we:(v=we.zpp_pool,we.zpp_pool=v.next,v.next=null);let E=v.inner;E.jnAcc=E.jtAcc=0,v.hash=0,v.fresh=true,v.arbiter=n,n.jrAcc=0;let M=n.contacts;v._inuse=true;let k=v;k.next=M.next,M.next=k,M.modified=true,M.length++,n.innards.add(E);}else v.fresh=false;v.px=g,v.py=P,n.nx=y*Z,n.ny=z*Z,v.dist=d-_,v.stamp=n.stamp,v.posOnly=false,w=v;}}if(w!=null){let Z=w.inner;n.ptype=2;let d=u.x-t.polygon.body.posx,f=u.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=-1,s?(Z.lr1x=d*t.polygon.body.axisy+f*t.polygon.body.axisx,Z.lr1y=f*t.polygon.body.axisy-d*t.polygon.body.axisx,Z.lr2x=e.circle.localCOMx,Z.lr2y=e.circle.localCOMy):(Z.lr2x=d*t.polygon.body.axisy+f*t.polygon.body.axisx,Z.lr2y=f*t.polygon.body.axisy-d*t.polygon.body.axisx,Z.lr1x=e.circle.localCOMx,Z.lr1y=e.circle.localCOMy),n.radius=e.circle.radius;}return w!=null}else if(m>=x.y*a.gnormx-x.x*a.gnormy){let _=e.circle.radius,y=x.x-e.circle.worldCOMx,z=x.y-e.circle.worldCOMy,b=y*y+z*z,w;if(b>_*_)w=null;else if(b<i.Config.epsilon*i.Config.epsilon){let Z=e.circle.worldCOMx,d=e.circle.worldCOMy,f=null,g=n.contacts.next;for(;g!=null;){let P=g;if(P.hash==0){f=P;break}g=g.next;}if(f==null){we.zpp_pool==null?f=new we:(f=we.zpp_pool,we.zpp_pool=f.next,f.next=null);let P=f.inner;P.jnAcc=P.jtAcc=0,f.hash=0,f.fresh=true,f.arbiter=n,n.jrAcc=0;let v=n.contacts;f._inuse=true;let N=f;N.next=v.next,v.next=N,v.modified=true,v.length++,n.innards.add(P);}else f.fresh=false;f.px=Z,f.py=d,n.nx=1,n.ny=0,f.dist=-_,f.stamp=n.stamp,f.posOnly=false,w=f;}else {let Z=1/Math.sqrt(b),d=Z<i.Config.epsilon?1e100:1/Z,f=.5+(e.circle.radius-.5*_)*Z;if(s){let g=e.circle.worldCOMx+y*f,P=e.circle.worldCOMy+z*f,v=null,N=n.contacts.next;for(;N!=null;){let E=N;if(E.hash==0){v=E;break}N=N.next;}if(v==null){we.zpp_pool==null?v=new we:(v=we.zpp_pool,we.zpp_pool=v.next,v.next=null);let E=v.inner;E.jnAcc=E.jtAcc=0,v.hash=0,v.fresh=true,v.arbiter=n,n.jrAcc=0;let M=n.contacts;v._inuse=true;let k=v;k.next=M.next,M.next=k,M.modified=true,M.length++,n.innards.add(E);}else v.fresh=false;v.px=g,v.py=P,n.nx=-y*Z,n.ny=-z*Z,v.dist=d-_,v.stamp=n.stamp,v.posOnly=false,w=v;}else {let g=e.circle.worldCOMx+y*f,P=e.circle.worldCOMy+z*f,v=null,N=n.contacts.next;for(;N!=null;){let E=N;if(E.hash==0){v=E;break}N=N.next;}if(v==null){we.zpp_pool==null?v=new we:(v=we.zpp_pool,we.zpp_pool=v.next,v.next=null);let E=v.inner;E.jnAcc=E.jtAcc=0,v.hash=0,v.fresh=true,v.arbiter=n,n.jrAcc=0;let M=n.contacts;v._inuse=true;let k=v;k.next=M.next,M.next=k,M.modified=true,M.length++,n.innards.add(E);}else v.fresh=false;v.px=g,v.py=P,n.nx=y*Z,n.ny=z*Z,v.dist=d-_,v.stamp=n.stamp,v.posOnly=false,w=v;}}if(w!=null){let Z=w.inner;n.ptype=2;let d=x.x-t.polygon.body.posx,f=x.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=1,s?(Z.lr1x=d*t.polygon.body.axisy+f*t.polygon.body.axisx,Z.lr1y=f*t.polygon.body.axisy-d*t.polygon.body.axisx,Z.lr2x=e.circle.localCOMx,Z.lr2y=e.circle.localCOMy):(Z.lr2x=d*t.polygon.body.axisy+f*t.polygon.body.axisx,Z.lr2y=f*t.polygon.body.axisy-d*t.polygon.body.axisx,Z.lr1x=e.circle.localCOMx,Z.lr1y=e.circle.localCOMy),n.radius=e.circle.radius;}return w!=null}else {let _=e.circle.radius+l*.5,y=a.gnormx*_,z=a.gnormy*_,b=e.circle.worldCOMx-y,w=e.circle.worldCOMy-z,Z;if(s){let d=a.gnormx,f=a.gnormy,g=null,P=n.contacts.next;for(;P!=null;){let v=P;if(v.hash==0){g=v;break}P=P.next;}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let v=g.inner;v.jnAcc=v.jtAcc=0,g.hash=0,g.fresh=true,g.arbiter=n,n.jrAcc=0;let N=n.contacts;g._inuse=true;let E=g;E.next=N.next,N.next=E,N.modified=true,N.length++,n.innards.add(v);}else g.fresh=false;g.px=b,g.py=w,n.nx=d,n.ny=f,g.dist=l,g.stamp=n.stamp,g.posOnly=false,Z=g;}else {let d=-a.gnormx,f=-a.gnormy,g=null,P=n.contacts.next;for(;P!=null;){let v=P;if(v.hash==0){g=v;break}P=P.next;}if(g==null){we.zpp_pool==null?g=new we:(g=we.zpp_pool,we.zpp_pool=g.next,g.next=null);let v=g.inner;v.jnAcc=v.jtAcc=0,g.hash=0,g.fresh=true,g.arbiter=n,n.jrAcc=0;let N=n.contacts;g._inuse=true;let E=g;E.next=N.next,N.next=E,N.modified=true,N.length++,n.innards.add(v);}else g.fresh=false;g.px=b,g.py=w,n.nx=d,n.ny=f,g.dist=l,g.stamp=n.stamp,g.posOnly=false,Z=g;}return n.ptype=s?0:1,n.lnormx=a.lnormx,n.lnormy=a.lnormy,n.rev=!s,n.lproj=a.lprojection,n.radius=e.circle.radius,Z.inner.lr1x=e.circle.localCOMx,Z.inner.lr1y=e.circle.localCOMy,n.__ref_edge1=a,n.__ref_vertex=0,true}}else return false}else {let l=e.circle.radius+t.circle.radius,r=t.circle.worldCOMx-e.circle.worldCOMx,o=t.circle.worldCOMy-e.circle.worldCOMy,a=r*r+o*o,p;if(a>l*l)p=null;else if(a<i.Config.epsilon*i.Config.epsilon){let c=e.circle.worldCOMx,h=e.circle.worldCOMy,u=null,x=n.contacts.next;for(;x!=null;){let m=x;if(m.hash==0){u=m;break}x=x.next;}if(u==null){we.zpp_pool==null?u=new we:(u=we.zpp_pool,we.zpp_pool=u.next,u.next=null);let m=u.inner;m.jnAcc=m.jtAcc=0,u.hash=0,u.fresh=true,u.arbiter=n,n.jrAcc=0;let _=n.contacts;u._inuse=true;let y=u;y.next=_.next,_.next=y,_.modified=true,_.length++,n.innards.add(m);}else u.fresh=false;u.px=c,u.py=h,n.nx=1,n.ny=0,u.dist=-l,u.stamp=n.stamp,u.posOnly=false,p=u;}else {let c=1/Math.sqrt(a),h=c<i.Config.epsilon?1e100:1/c,u=.5+(e.circle.radius-.5*l)*c;if(s){let x=e.circle.worldCOMx+r*u,m=e.circle.worldCOMy+o*u,_=null,y=n.contacts.next;for(;y!=null;){let z=y;if(z.hash==0){_=z;break}y=y.next;}if(_==null){we.zpp_pool==null?_=new we:(_=we.zpp_pool,we.zpp_pool=_.next,_.next=null);let z=_.inner;z.jnAcc=z.jtAcc=0,_.hash=0,_.fresh=true,_.arbiter=n,n.jrAcc=0;let b=n.contacts;_._inuse=true;let w=_;w.next=b.next,b.next=w,b.modified=true,b.length++,n.innards.add(z);}else _.fresh=false;_.px=x,_.py=m,n.nx=-r*c,n.ny=-o*c,_.dist=h-l,_.stamp=n.stamp,_.posOnly=false,p=_;}else {let x=e.circle.worldCOMx+r*u,m=e.circle.worldCOMy+o*u,_=null,y=n.contacts.next;for(;y!=null;){let z=y;if(z.hash==0){_=z;break}y=y.next;}if(_==null){we.zpp_pool==null?_=new we:(_=we.zpp_pool,we.zpp_pool=_.next,_.next=null);let z=_.inner;z.jnAcc=z.jtAcc=0,_.hash=0,_.fresh=true,_.arbiter=n,n.jrAcc=0;let b=n.contacts;_._inuse=true;let w=_;w.next=b.next,b.next=w,b.modified=true,b.length++,n.innards.add(z);}else _.fresh=false;_.px=x,_.py=m,n.nx=r*c,n.ny=o*c,_.dist=h-l,_.stamp=n.stamp,_.posOnly=false,p=_;}}if(p!=null){let c=p.inner;return s?(c.lr1x=t.circle.localCOMx,c.lr1y=t.circle.localCOMy,c.lr2x=e.circle.localCOMx,c.lr2y=e.circle.localCOMy):(c.lr1x=e.circle.localCOMx,c.lr1y=e.circle.localCOMy,c.lr2x=t.circle.localCOMx,c.lr2y=t.circle.localCOMy),n.radius=e.circle.radius+t.circle.radius,n.ptype=2,true}else return false}}static testCollide_safe(e,t){_e();if(e.type>t.type){let s=e;e=t,t=s;}return Me.testCollide(e,t)}static testCollide(e,t){_e();if(t.type==1)if(e.type==1){let s=true,i=e.polygon.edges.head;for(;i!=null;){let l=i.elt,r=1e100,o=t.polygon.gverts.next;for(;o!=null;){let a=o,p=l.gnormx*a.x+l.gnormy*a.y;p<r&&(r=p),o=o.next;}if(r-=l.gprojection,r>0){s=false;break}i=i.next;}if(s){let l=t.polygon.edges.head;for(;l!=null;){let r=l.elt,o=1e100,a=e.polygon.gverts.next;for(;a!=null;){let p=a,c=r.gnormx*p.x+r.gnormy*p.y;c<o&&(o=c),a=a.next;}if(o-=r.gprojection,o>0){s=false;break}l=l.next;}return s}else return false}else {let s=null,i=null,l=true,r=-1e100,o=t.polygon.gverts.next,a=t.polygon.edges.head;for(;a!=null;){let p=a.elt,c=p.gnormx*e.circle.worldCOMx+p.gnormy*e.circle.worldCOMy-p.gprojection-e.circle.radius;if(c>0){l=false;break}c>r&&(r=c,s=p,i=o),o=o.next,a=a.next;}if(l){let p=i,c=i.next==null?t.polygon.gverts.next:i.next,h=e.circle.worldCOMy*s.gnormx-e.circle.worldCOMx*s.gnormy;if(h<=p.y*s.gnormx-p.x*s.gnormy){let u=e.circle.radius,x=p.x-e.circle.worldCOMx,m=p.y-e.circle.worldCOMy;return x*x+m*m<=u*u}else if(h>=c.y*s.gnormx-c.x*s.gnormy){let u=e.circle.radius,x=c.x-e.circle.worldCOMx,m=c.y-e.circle.worldCOMy;return x*x+m*m<=u*u}else return true}else return false}else {let s=e.circle.radius+t.circle.radius,i=t.circle.worldCOMx-e.circle.worldCOMx,l=t.circle.worldCOMy-e.circle.worldCOMy;return i*i+l*l<=s*s}}static flowCollide(e,t,n){let s=_e();if(t.type==1)if(e.type==1){let i=[],l=[],r=true,o=true,a=e.polygon.edges.head;for(;a!=null;){let p=a.elt,c=1e100,h=0,u=t.polygon.gverts.next;for(;u!=null;){let x=u,m=p.gnormx*x.x+p.gnormy*x.y;m<c&&(c=m),m>=p.gprojection+s.Config.epsilon&&(l[h]=true,o=false),++h,u=u.next;}if(c-=p.gprojection,c>0){r=false;break}a=a.next;}if(o){let p=t.polygon;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=false,p.zip_localCOM){if(p.zip_localCOM=false,p.type==1){let h=p.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let u=1;h.localCOMx+=h.lverts.next.next.x*u,h.localCOMy+=h.lverts.next.next.y*u;let x=.5;h.localCOMx*=x,h.localCOMy*=x;}else {h.localCOMx=0,h.localCOMy=0;let u=0,x=h.lverts.next,m=x;x=x.next;let _=x;for(x=x.next;x!=null;){let d=x;u+=_.x*(d.y-m.y);let f=d.y*_.x-d.x*_.y;h.localCOMx+=(_.x+d.x)*f,h.localCOMy+=(_.y+d.y)*f,m=_,_=d,x=x.next;}x=h.lverts.next;let y=x;u+=_.x*(y.y-m.y);let z=y.y*_.x-y.x*_.y;h.localCOMx+=(_.x+y.x)*z,h.localCOMy+=(_.y+y.y)*z,m=_,_=y,x=x.next;let b=x;u+=_.x*(b.y-m.y);let w=b.y*_.x-b.x*_.y;h.localCOMx+=(_.x+b.x)*w,h.localCOMy+=(_.y+b.y)*w,u=1/(3*u);let Z=u;h.localCOMx*=Z,h.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=false,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,true}else if(r){o=true;let p=t.polygon.edges.head;for(;p!=null;){let c=p.elt,h=1e100,u=0,x=e.polygon.gverts.next;for(;x!=null;){let m=x,_=c.gnormx*m.x+c.gnormy*m.y;_<h&&(h=_),_>=c.gprojection+s.Config.epsilon&&(i[u]=true,o=false),++u,x=x.next;}if(h-=c.gprojection,h>0){r=false;break}p=p.next;}if(o){let c=e.polygon;if(c.zip_worldCOM&&c.body!=null){if(c.zip_worldCOM=false,c.zip_localCOM){if(c.zip_localCOM=false,c.type==1){let u=c.polygon;if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(u.lverts.next.next==null)u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;else if(u.lverts.next.next.next==null){u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;let x=1;u.localCOMx+=u.lverts.next.next.x*x,u.localCOMy+=u.lverts.next.next.y*x;let m=.5;u.localCOMx*=m,u.localCOMy*=m;}else {u.localCOMx=0,u.localCOMy=0;let x=0,m=u.lverts.next,_=m;m=m.next;let y=m;for(m=m.next;m!=null;){let f=m;x+=y.x*(f.y-_.y);let g=f.y*y.x-f.x*y.y;u.localCOMx+=(y.x+f.x)*g,u.localCOMy+=(y.y+f.y)*g,_=y,y=f,m=m.next;}m=u.lverts.next;let z=m;x+=y.x*(z.y-_.y);let b=z.y*y.x-z.x*y.y;u.localCOMx+=(y.x+z.x)*b,u.localCOMy+=(y.y+z.y)*b,_=y,y=z,m=m.next;let w=m;x+=y.x*(w.y-_.y);let Z=w.y*y.x-w.x*y.y;u.localCOMx+=(y.x+w.x)*Z,u.localCOMy+=(y.y+w.y)*Z,x=1/(3*x);let d=x;u.localCOMx*=d,u.localCOMy*=d;}}c.wrap_localCOM!=null&&(c.wrap_localCOM.zpp_inner.x=c.localCOMx,c.wrap_localCOM.zpp_inner.y=c.localCOMy);}let h=c.body;h.zip_axis&&(h.zip_axis=false,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.worldCOMx=c.body.posx+(c.body.axisy*c.localCOMx-c.body.axisx*c.localCOMy),c.worldCOMy=c.body.posy+(c.localCOMx*c.body.axisx+c.localCOMy*c.body.axisy);}return n.overlap=e.polygon.area,n.centroidx=e.polygon.worldCOMx,n.centroidy=e.polygon.worldCOMy,true}else if(r){for(;Me.flowpoly.head!=null;){let w=Me.flowpoly.pop_unsafe();if(!w._inuse){let Z=w;Z.outer!=null&&(Z.outer.zpp_inner=null,Z.outer=null),Z._isimmutable=null,Z._validate=null,Z._invalidate=null,Z.next=ae.zpp_pool,ae.zpp_pool=Z;}}let c=null,h=false,u=e.polygon.gverts.next,x=0,m=t.polygon.gverts.next,_=0,y=0,z=t.polygon.edgeCnt;for(;y<z;){let w=y++;if(l[w])m=m.next;else {_=w;break}}if(m==null){m=t.polygon.gverts.next,h=true;let w=0,Z=e.polygon.edgeCnt;for(;w<Z;){let d=w++;if(i[d])u=u.next;else {x=d;break}}u==null?u=e.polygon.gverts.next:(Me.flowpoly.add(u),c=Me.flowpoly.head.elt);}else Me.flowpoly.add(m),c=Me.flowpoly.head.elt;let b=1;if(Me.flowpoly.head==null){let w=true,Z=e.polygon.gverts.next,d=Z,f=Z.next;for(;f!=null;){let g=f,P=2,N=t.polygon.gverts.next,E=N,M=N.next;for(;M!=null;){let k=M,C=0,S=d.x-E.x,O=d.y-E.y,F=g.x-d.x,T=g.y-d.y,R=k.x-E.x,W=k.y-E.y,G=T*R-F*W,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let A=(W*S-R*O)*G;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let Y=(T*S-F*O)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(C=A,B=true):B=false;}else B=false;}else B=false;B&&C<P&&(P=C,m=N),N=M,E=k,M=M.next;}for(;;){M=t.polygon.gverts.next;let k=M,C=0,S=d.x-E.x,O=d.y-E.y,F=g.x-d.x,T=g.y-d.y,R=k.x-E.x,W=k.y-E.y,G=T*R-F*W,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let A=(W*S-R*O)*G;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let Y=(T*S-F*O)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(C=A,B=true):B=false;}else B=false;}else B=false;B&&C<P&&(P=C,m=N);break}if(P!=2){let k=P,C=d.x+(g.x-d.x)*k,S=d.y+(g.y-d.y)*k;c=ae.get(C,S),Me.flowpoly.add(c),h=true,u=Z,w=false;break}Z=f,d=g,f=f.next;}if(w)for(;;){f=e.polygon.gverts.next;let g=f,P=2,N=t.polygon.gverts.next,E=N,M=N.next;for(;M!=null;){let k=M,C=0,S=d.x-E.x,O=d.y-E.y,F=g.x-d.x,T=g.y-d.y,R=k.x-E.x,W=k.y-E.y,G=T*R-F*W,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let A=(W*S-R*O)*G;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let Y=(T*S-F*O)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(C=A,B=true):B=false;}else B=false;}else B=false;B&&C<P&&(P=C,m=N),N=M,E=k,M=M.next;}for(;;){M=t.polygon.gverts.next;let k=M,C=0,S=d.x-E.x,O=d.y-E.y,F=g.x-d.x,T=g.y-d.y,R=k.x-E.x,W=k.y-E.y,G=T*R-F*W,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let A=(W*S-R*O)*G;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let Y=(T*S-F*O)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(C=A,B=true):B=false;}else B=false;}else B=false;B&&C<P&&(P=C,m=N);break}if(P!=2){let k=P,C=d.x+(g.x-d.x)*k,S=d.y+(g.y-d.y)*k;c=ae.get(C,S),Me.flowpoly.add(c),h=true,u=Z;break}break}b=2;}for(;;)if(h)if(u=u.next,++x,u==null&&(u=e.polygon.gverts.next,x=0),i[x]){let w=Me.flowpoly.head.elt,Z=u,d=m,f=m.next;f==null&&(f=t.polygon.gverts.next);let g=-1,P=null,v=0,N=0,E=f,M=f;for(;;){let B=M,A=0,Y=d.x-w.x,$=d.y-w.y,H=B.x-d.x,X=B.y-d.y,ee=Z.x-w.x,q=Z.y-w.y,D=X*ee-H*q,L;if(D*D>s.Config.epsilon*s.Config.epsilon){D=1/D;let V=(q*Y-ee*$)*D;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let U=(X*Y-H*$)*D;U>s.Config.epsilon&&U<1-s.Config.epsilon?(A=V,L=true):L=false;}else L=false;}else L=false;if(L&&A>=g)if(P=m,v=_,++N==b){g=A,M=E;break}else g=A;d=B,m=M,++_,_>=t.polygon.edgeCnt&&(_=0),M=M.next,M==null&&(M=t.polygon.gverts.next);break}for(;M!=E;){let B=M,A=0,Y=d.x-w.x,$=d.y-w.y,H=B.x-d.x,X=B.y-d.y,ee=Z.x-w.x,q=Z.y-w.y,D=X*ee-H*q,L;if(D*D>s.Config.epsilon*s.Config.epsilon){D=1/D;let V=(q*Y-ee*$)*D;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let U=(X*Y-H*$)*D;U>s.Config.epsilon&&U<1-s.Config.epsilon?(A=V,L=true):L=false;}else L=false;}else L=false;if(L&&A>=g)if(P=m,v=_,++N==b){g=A;break}else g=A;d=B,m=M,++_,_>=t.polygon.edgeCnt&&(_=0),M=M.next,M==null&&(M=t.polygon.gverts.next);}if(P==null)break;let k=P,C=P.next;C==null&&(C=t.polygon.gverts.next);let S=C,O=g,F=k.x+(S.x-k.x)*O,T=k.y+(S.y-k.y)*O,R;if(c!=null){let B=F-c.x,A=T-c.y;R=B*B+A*A<s.Config.epsilon;}else R=false;if(R)break;let W=Me.flowpoly,G=ae.get(F,T);W.add(G),c==null&&(c=Me.flowpoly.head.elt),m=P,_=v,h=!h,b=2;}else {let w=u,Z;if(c!=null){let d=w.x-c.x,f=w.y-c.y;Z=d*d+f*f<s.Config.epsilon;}else Z=false;if(Z)break;Me.flowpoly.add(w),c==null&&(c=Me.flowpoly.head.elt),b=1;}else if(m=m.next,++_,m==null&&(m=t.polygon.gverts.next,_=0),l[_]){let w=Me.flowpoly.head.elt,Z=m,d=u,f=u.next;f==null&&(f=e.polygon.gverts.next);let g=-1,P=null,v=0,N=0,E=f,M=f;for(;;){let B=M,A=0,Y=d.x-w.x,$=d.y-w.y,H=B.x-d.x,X=B.y-d.y,ee=Z.x-w.x,q=Z.y-w.y,D=X*ee-H*q,L;if(D*D>s.Config.epsilon*s.Config.epsilon){D=1/D;let V=(q*Y-ee*$)*D;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let U=(X*Y-H*$)*D;U>s.Config.epsilon&&U<1-s.Config.epsilon?(A=V,L=true):L=false;}else L=false;}else L=false;if(L&&A>=g)if(P=u,v=x,++N==b){g=A,M=E;break}else g=A;d=B,u=M,++x,x>=e.polygon.edgeCnt&&(x=0),M=M.next,M==null&&(M=e.polygon.gverts.next);break}for(;M!=E;){let B=M,A=0,Y=d.x-w.x,$=d.y-w.y,H=B.x-d.x,X=B.y-d.y,ee=Z.x-w.x,q=Z.y-w.y,D=X*ee-H*q,L;if(D*D>s.Config.epsilon*s.Config.epsilon){D=1/D;let V=(q*Y-ee*$)*D;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let U=(X*Y-H*$)*D;U>s.Config.epsilon&&U<1-s.Config.epsilon?(A=V,L=true):L=false;}else L=false;}else L=false;if(L&&A>=g)if(P=u,v=x,++N==b){g=A;break}else g=A;d=B,u=M,++x,x>=e.polygon.edgeCnt&&(x=0),M=M.next,M==null&&(M=e.polygon.gverts.next);}if(P==null)break;let k=P,C=P.next;C==null&&(C=e.polygon.gverts.next);let S=C,O=g,F=k.x+(S.x-k.x)*O,T=k.y+(S.y-k.y)*O,R;if(c!=null){let B=F-c.x,A=T-c.y;R=B*B+A*A<s.Config.epsilon;}else R=false;if(R)break;let W=Me.flowpoly,G=ae.get(F,T);W.add(G),c==null&&(c=Me.flowpoly.head.elt),u=P,x=v,h=!h,b=2;}else {let w=m,Z;if(c!=null){let d=w.x-c.x,f=w.y-c.y;Z=d*d+f*f<s.Config.epsilon;}else Z=false;if(Z)break;Me.flowpoly.add(w),c==null&&(c=Me.flowpoly.head.elt),b=1;}if(Me.flowpoly.head!=null&&Me.flowpoly.head.next!=null&&Me.flowpoly.head.next.next!=null){let w=0,Z=0,d=0,f=Me.flowpoly.head,g=f.elt;f=f.next;let P=f.elt;for(f=f.next;f!=null;){let S=f.elt;w+=P.x*(S.y-g.y);let O=S.y*P.x-S.x*P.y;Z+=(P.x+S.x)*O,d+=(P.y+S.y)*O,g=P,P=S,f=f.next;}f=Me.flowpoly.head;let v=f.elt;w+=P.x*(v.y-g.y);let N=v.y*P.x-v.x*P.y;Z+=(P.x+v.x)*N,d+=(P.y+v.y)*N,g=P,P=v,f=f.next;let E=f.elt;w+=P.x*(E.y-g.y);let M=E.y*P.x-E.x*P.y;Z+=(P.x+E.x)*M,d+=(P.y+E.y)*M,w*=.5;let C=1/(6*w);return Z*=C,d*=C,n.overlap=-w,n.centroidx=Z,n.centroidy=d,true}else return false}else return false}else return false}else {let i=[],l=true,r=null,o=null,a=-1e100,p=true,c=t.polygon.gverts.next,h=0,u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,m=x.gnormx*e.circle.worldCOMx+x.gnormy*e.circle.worldCOMy;if(m>x.gprojection+e.circle.radius){p=false;break}else m+e.circle.radius>x.gprojection+s.Config.epsilon&&(l=false,i[h]=true);m-=x.gprojection+e.circle.radius,m>a&&(a=m,r=x,o=c),c=c.next,++h,u=u.next;}if(p){if(l)return n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,true;{let x=o,m=o.next==null?t.polygon.gverts.next:o.next,_=e.circle.worldCOMy*r.gnormx-e.circle.worldCOMx*r.gnormy,y;if(_<=x.y*r.gnormx-x.x*r.gnormy){let z=e.circle.radius,b=x.x-e.circle.worldCOMx,w=x.y-e.circle.worldCOMy;y=b*b+w*w<=z*z;}else if(_>=m.y*r.gnormx-m.x*r.gnormy){let z=e.circle.radius,b=m.x-e.circle.worldCOMx,w=m.y-e.circle.worldCOMy;y=b*b+w*w<=z*z;}else y=true;if(y){let z=[],b=0,w=true,Z=null,d=0,f=t.polygon.gverts.next;for(;f!=null;){let g=f,P=g.x-e.circle.worldCOMx,v=g.y-e.circle.worldCOMy,N=P*P+v*v;(z[b]=N<=e.circle.radius*e.circle.radius)?(d=b,Z=f):w=false,++b,f=f.next;}if(w){let g=t.polygon;if(g.zip_worldCOM&&g.body!=null){if(g.zip_worldCOM=false,g.zip_localCOM){if(g.zip_localCOM=false,g.type==1){let v=g.polygon;if(v.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(v.lverts.next.next==null)v.localCOMx=v.lverts.next.x,v.localCOMy=v.lverts.next.y;else if(v.lverts.next.next.next==null){v.localCOMx=v.lverts.next.x,v.localCOMy=v.lverts.next.y;let N=1;v.localCOMx+=v.lverts.next.next.x*N,v.localCOMy+=v.lverts.next.next.y*N;let E=.5;v.localCOMx*=E,v.localCOMy*=E;}else {v.localCOMx=0,v.localCOMy=0;let N=0,E=v.lverts.next,M=E;E=E.next;let k=E;for(E=E.next;E!=null;){let R=E;N+=k.x*(R.y-M.y);let W=R.y*k.x-R.x*k.y;v.localCOMx+=(k.x+R.x)*W,v.localCOMy+=(k.y+R.y)*W,M=k,k=R,E=E.next;}E=v.lverts.next;let C=E;N+=k.x*(C.y-M.y);let S=C.y*k.x-C.x*k.y;v.localCOMx+=(k.x+C.x)*S,v.localCOMy+=(k.y+C.y)*S,M=k,k=C,E=E.next;let O=E;N+=k.x*(O.y-M.y);let F=O.y*k.x-O.x*k.y;v.localCOMx+=(k.x+O.x)*F,v.localCOMy+=(k.y+O.y)*F,N=1/(3*N);let T=N;v.localCOMx*=T,v.localCOMy*=T;}}g.wrap_localCOM!=null&&(g.wrap_localCOM.zpp_inner.x=g.localCOMx,g.wrap_localCOM.zpp_inner.y=g.localCOMy);}let P=g.body;P.zip_axis&&(P.zip_axis=false,P.axisx=Math.sin(P.rot),P.axisy=Math.cos(P.rot)),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);}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,true}else {for(;Me.flowpoly.head!=null;){let v=Me.flowpoly.pop_unsafe();if(!v._inuse){let N=v;N.outer!=null&&(N.outer.zpp_inner=null,N.outer=null),N._isimmutable=null,N._validate=null,N._invalidate=null,N.next=ae.zpp_pool,ae.zpp_pool=N;}}Me.flowsegs.clear();let g=null,P=1;for(Z==null?(Z=t.polygon.gverts.next,P=2):(g=Z,Me.flowpoly.add(g));P!=0;)if(P==1)if(Z=Z.next,Z==null&&(Z=t.polygon.gverts.next),++d,d>=t.polygon.edgeCnt&&(d=0),z[d]){let v=g.x-Z.x,N=g.y-Z.y;if(v*v+N*N<s.Config.epsilon)break;Me.flowpoly.add(Z);}else {let v=Me.flowpoly.head.elt,N=Z,E=N.x-v.x,M=N.y-v.y,k=v.x-e.circle.worldCOMx,C=v.y-e.circle.worldCOMy,S=E*E+M*M,O=2*(k*E+C*M),F=k*k+C*C-e.circle.radius*e.circle.radius,T=Math.sqrt(O*O-4*S*F);S=1/(2*S);let R=(-O-T)*S,W=R<s.Config.epsilon?(-O+T)*S:R,G=0,B=0,A=W;G=v.x+(N.x-v.x)*A,B=v.y+(N.y-v.y)*A;let Y=g.x-G,$=g.y-B;if(Y*Y+$*$<s.Config.epsilon)break;let H=Me.flowpoly,X=ae.get(G,B);H.add(X),P=2;}else if(P==2){let v=Z.next;v==null&&(v=t.polygon.gverts.next);let N=Z;P=0;let E=v,M=v;for(;;){let k=M,C=d+1;if(C==t.polygon.edgeCnt&&(C=0),i[d])if(z[C]){let S=k.x-N.x,O=k.y-N.y,F=N.x-e.circle.worldCOMx,T=N.y-e.circle.worldCOMy,R=S*S+O*O,W=2*(F*S+T*O),G=F*F+T*T-e.circle.radius*e.circle.radius,B=Math.sqrt(W*W-4*R*G);R=1/(2*R);let A=(-W-B)*R,Y=A<s.Config.epsilon?(-W+B)*R:A,$=0,H=0,X=Y;$=N.x+(k.x-N.x)*X,H=N.y+(k.y-N.y)*X;let ee=g.x-$,q=g.y-H;if(ee*ee+q*q<s.Config.epsilon){P=0,M=E;break}let L=ae.get($,H);Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(L),Me.flowpoly.add(L),P=1,M=E;break}else {let S=0,O=0,F=k.x-N.x,T=k.y-N.y,R=N.x-e.circle.worldCOMx,W=N.y-e.circle.worldCOMy,G=F*F+T*T,B=2*(R*F+W*T),A=R*R+W*W-e.circle.radius*e.circle.radius,Y=B*B-4*G*A,$;if(Y*Y<s.Config.epsilon?(Y<0?S=10:(O=-B/(2*G),S=O),$=false):(Y=Math.sqrt(Y),G=1/(2*G),S=(-B-Y)*G,O=(-B+Y)*G,$=true),S<1-s.Config.epsilon&&O>s.Config.epsilon){let H=0,X=0,ee=S;H=N.x+(k.x-N.x)*ee,X=N.y+(k.y-N.y)*ee;let q;if(g!=null){let V=g.x-H,U=g.y-X;q=V*V+U*U<s.Config.epsilon;}else q=false;if(q){P=0,M=E;break}let L=ae.get(H,X);if(Me.flowpoly.head!=null&&(Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(L)),Me.flowpoly.add(L),g==null&&(g=Me.flowpoly.head.elt),$){let V=0,U=0,Q=O;V=N.x+(k.x-N.x)*Q,U=N.y+(k.y-N.y)*Q;let K=Me.flowpoly,ie=ae.get(V,U);K.add(ie);}}}N=k,Z=M,d=C,M=M.next,M==null&&(M=t.polygon.gverts.next);break}for(;M!=E;){let k=M,C=d+1;if(C==t.polygon.edgeCnt&&(C=0),i[d])if(z[C]){let S=k.x-N.x,O=k.y-N.y,F=N.x-e.circle.worldCOMx,T=N.y-e.circle.worldCOMy,R=S*S+O*O,W=2*(F*S+T*O),G=F*F+T*T-e.circle.radius*e.circle.radius,B=Math.sqrt(W*W-4*R*G);R=1/(2*R);let A=(-W-B)*R,Y=A<s.Config.epsilon?(-W+B)*R:A,$=0,H=0,X=Y;$=N.x+(k.x-N.x)*X,H=N.y+(k.y-N.y)*X;let ee=g.x-$,q=g.y-H;if(ee*ee+q*q<s.Config.epsilon){P=0,M=E;break}let L=ae.get($,H);Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(L),Me.flowpoly.add(L),P=1,M=E;break}else {let S=0,O=0,F=k.x-N.x,T=k.y-N.y,R=N.x-e.circle.worldCOMx,W=N.y-e.circle.worldCOMy,G=F*F+T*T,B=2*(R*F+W*T),A=R*R+W*W-e.circle.radius*e.circle.radius,Y=B*B-4*G*A,$;if(Y*Y<s.Config.epsilon?(Y<0?S=10:(O=-B/(2*G),S=O),$=false):(Y=Math.sqrt(Y),G=1/(2*G),S=(-B-Y)*G,O=(-B+Y)*G,$=true),S<1-s.Config.epsilon&&O>s.Config.epsilon){let H=0,X=0,ee=S;H=N.x+(k.x-N.x)*ee,X=N.y+(k.y-N.y)*ee;let q;if(g!=null){let V=g.x-H,U=g.y-X;q=V*V+U*U<s.Config.epsilon;}else q=false;if(q){P=0,M=E;break}let L=ae.get(H,X);if(Me.flowpoly.head!=null&&(Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(L)),Me.flowpoly.add(L),g==null&&(g=Me.flowpoly.head.elt),$){let V=0,U=0,Q=O;V=N.x+(k.x-N.x)*Q,U=N.y+(k.y-N.y)*Q;let K=Me.flowpoly,ie=ae.get(V,U);K.add(ie);}}}N=k,Z=M,d=C,M=M.next,M==null&&(M=t.polygon.gverts.next);}}if(Me.flowpoly.head==null)return false;if(Me.flowpoly.head.next==null){let v=true,N=t.polygon.edges.head;for(;N!=null;){let E=N.elt;if(E.gnormx*e.circle.worldCOMx+E.gnormy*e.circle.worldCOMy>E.gprojection){v=false;break}N=N.next;}return v?(n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,true):false}else {let v=0,N=0,E=0;if(Me.flowpoly.head.next.next!=null){let k=0,C=0,S=0;k=0;let O=Me.flowpoly.head,F=O.elt;O=O.next;let T=O.elt;for(O=O.next;O!=null;){let H=O.elt;k+=T.x*(H.y-F.y);let X=H.y*T.x-H.x*T.y;C+=(T.x+H.x)*X,S+=(T.y+H.y)*X,F=T,T=H,O=O.next;}O=Me.flowpoly.head;let R=O.elt;k+=T.x*(R.y-F.y);let W=R.y*T.x-R.x*T.y;C+=(T.x+R.x)*W,S+=(T.y+R.y)*W,F=T,T=R,O=O.next;let G=O.elt;k+=T.x*(G.y-F.y);let B=G.y*T.x-G.x*T.y;C+=(T.x+G.x)*B,S+=(T.y+G.y)*B,k*=.5;let Y=1/(6*k);C*=Y,S*=Y;let $=-k;v+=C*$,N+=S*$,E-=k;}else Me.flowsegs.add(Me.flowpoly.head.elt),Me.flowsegs.add(Me.flowpoly.head.next.elt);for(;Me.flowsegs.head!=null;){let k=Me.flowsegs.pop_unsafe(),C=Me.flowsegs.pop_unsafe(),S=C.x-k.x,O=C.y-k.y,F=S,T=O,R=F*F+T*T,G=1/Math.sqrt(R);F*=G,T*=G;let B=F;F=-T,T=B;let A=k.x+C.x,Y=k.y+C.y,$=.5;A*=$,Y*=$;let H=1;A-=e.circle.worldCOMx*H,Y-=e.circle.worldCOMy*H;let X=F*A+T*Y,ee=0,q=0,D=X,L=D/e.circle.radius,V=Math.sqrt(1-L*L),U=Math.acos(L);ee=e.circle.radius*(e.circle.radius*U-D*V),q=.6666666666666666*e.circle.radius*V*V*V/(U-L*V),A=e.circle.worldCOMx,Y=e.circle.worldCOMy;let Q=q;A+=F*Q,Y+=T*Q;let K=ee;v+=A*K,N+=Y*K,E+=ee;}let M=1/E;return v*=M,N*=M,n.overlap=E,n.centroidx=v,n.centroidy=N,true}}}else return false}}else return false}else {let i=e.circle,l=t.circle,r=l.worldCOMx-i.worldCOMx,o=l.worldCOMy-i.worldCOMy,a=i.radius+l.radius,p=r*r+o*o;if(p>a*a)return false;if(p<s.Config.epsilon*s.Config.epsilon)return i.radius<l.radius?(n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy):(n.overlap=l.area,n.centroidx=l.worldCOMx,n.centroidy=l.worldCOMy),true;{let c=Math.sqrt(p),h=1/c,u=.5*(c-(l.radius*l.radius-i.radius*i.radius)*h);if(u<=-i.radius)n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy;else {let x=c-u;if(x<=-l.radius)n.overlap=l.area,n.centroidx=l.worldCOMx,n.centroidy=l.worldCOMy;else {let m=0,_=0,y=0,z=0,b=u,w=b/i.radius,Z=Math.sqrt(1-w*w),d=Math.acos(w);m=i.radius*(i.radius*d-b*Z),_=.6666666666666666*i.radius*Z*Z*Z/(d-w*Z);let f=x,g=f/l.radius,P=Math.sqrt(1-g*g),v=Math.acos(g);y=l.radius*(l.radius*v-f*P),z=.6666666666666666*l.radius*P*P*P/(v-g*P);let N=m+y,E=(_*m+(c-z)*y)/N*h;n.overlap=N,n.centroidx=i.worldCOMx+r*E,n.centroidy=i.worldCOMy+o*E;}}return true}}}};Me.flowpoly=null,Me.flowsegs=null;var ge=Me;var ns=class j{static isinner(e,t,n){let s=e.x-t.x,i=e.y-t.y,l=n.x-t.x;return (n.y-t.y)*s-l*i>=0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}let s=e.vertices,i=e.vertices;if(s!=null){let l=s;for(;;){let r=l,o=r.prev,a=null,p=r.diagonals.head;for(;p!=null;){let c=p.elt,h=p.next==null?r.next:p.next.elt;if(!j.isinner(h,r,o)){a=p,o=c,p=p.next;continue}let u=true,x=c,m=x.prev,_=null,y=x.diagonals.head;for(;y!=null;){let z=y.elt;if(z==r){let b=y.next==null?x.next:y.next.elt;u=j.isinner(b,x,m);break}m=z,_=y,y=y.next;}if(u){p=r.diagonals.erase(a),x.diagonals.erase(_);continue}o=c,a=p,p=p.next;}if(l=l.next,l==i)break}}}};var tt=class tt{constructor(){this.normal=null;this.shape=null;this.convex=null;this.position=null;this.ray=null;this.inner=false;this.next=null;this.toiDistance=0;}static getRay(e,t,n,s){let i;tt.rayPool==null?(tt.internal=true,i=tt._createRayResult(),i.zpp_inner=new tt,i.zpp_inner.ray=i,tt.internal=false):(i=tt.rayPool.ray,tt.rayPool=tt.rayPool.next,i.zpp_inner.next=null);let l=i.zpp_inner;return l.normal=e,e.zpp_inner._immutable=true,l.toiDistance=t,l.inner=n,l.shape=s,i}static getConvex(e,t,n,s){let i;tt.convexPool==null?(tt.internal=true,i=tt._createConvexResult(),i.zpp_inner=new tt,i.zpp_inner.convex=i,tt.internal=false):(i=tt.convexPool.convex,tt.convexPool=tt.convexPool.next,i.zpp_inner.next=null);let l=i.zpp_inner;return l.normal=e,l.position=t,e.zpp_inner._immutable=true,t.zpp_inner._immutable=true,l.toiDistance=n,l.shape=s,i}disposed(){if(this.next!=null)throw new Error("Error: This object has been disposed of and cannot be used")}free(){tt._disposeVec2(this.normal),this.position!=null&&tt._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=tt.convexPool,tt.convexPool=this):(this.next=tt.rayPool,tt.rayPool=this);}static _disposeVec2(e){if(e.zpp_inner._immutable=false,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=true,n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=ae.zpp_pool,ae.zpp_pool=n;}};tt.rayPool=null,tt.convexPool=null,tt.internal=false,tt._createRayResult=null,tt._createConvexResult=null;var bn=tt;var Vi=class Vi{constructor(){this.prev=null;this.next=null;this.posx=0;this.posy=0;this.vert=null;this.value=0;this.positive=false;this.parent=null;this.rank=0;this.used=false;}static path(e){let t;return Vi.zpp_pool==null?t=new Vi:(t=Vi.zpp_pool,Vi.zpp_pool=t.next,t.next=null),t.vert=e,t.parent=t,t.rank=0,t.used=false,t}alloc(){}free(){this.vert=null,this.parent=null;}};Vi.zpp_pool=null;var Xe=Vi;var Ii=class Ii{constructor(){this.next=null;this.time=0;this.virtualint=false;this.vertex=false;this.path0=null;this.end=null;this.start=null;this.path1=null;}static get(e,t,n,s,i,l=false,r=false){let o;return Ii.zpp_pool==null?o=new Ii:(o=Ii.zpp_pool,Ii.zpp_pool=o.next,o.next=null),o.virtualint=l,o.end=t,o.start=n,o.path0=s,o.path1=i,o.time=e,o.vertex=r,o}alloc(){}free(){this.end=this.start=null,this.path0=this.path1=null;}};Ii.zpp_pool=null;var ot=Ii;var ni=class ni{constructor(){this.x=0;this.y=0;this.prev=null;this.next=null;this.wrap=null;this.forced=false;}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.forced=false,n.x=e,n.y=t,n}alloc(){this.forced=false;}free(){if(this.wrap!=null){this.wrap.zpp_inner._inuse=false;let e=this.wrap;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=e.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");if(t._isimmutable!=null&&t._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let n=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let s=e;s.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=s:xe.poolVec2=s,xe.nextVec2=s,s.zpp_disp=true;let i=n;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i._isimmutable=null,i._validate=null,i._invalidate=null,i.next=ae.zpp_pool,ae.zpp_pool=i,this.wrap=null;}this.prev=this.next=null;}wrapper(){if(this.wrap==null){let e=this.x,t=this.y;if(t==null&&(t=0),e==null&&(e=0),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(xe.poolVec2==null?n=ni._createVec2Fn():(n=xe.poolVec2,xe.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=false,n===xe.nextVec2&&(xe.nextVec2=null)),n.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.zpp_pool=s.next,s.next=null),s.weak=false,s._immutable=false,s.x=e,s.y=t,n.zpp_inner=s,n.zpp_inner.outer=n;}else {if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x===e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y===t;}else i=false;if(!i){n.zpp_inner.x=e,n.zpp_inner.y=t;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r);}}n.zpp_inner.weak=false,this.wrap=n,this.wrap.zpp_inner._inuse=true,this.wrap.zpp_inner._invalidate=s=>this.modwrap(s),this.wrap.zpp_inner._validate=()=>this.getwrap();}return this.wrap}modwrap(e){this.x=e.x,this.y=e.y;}getwrap(){this.wrap.zpp_inner.x=this.x,this.wrap.zpp_inner.y=this.y;}};ni.zpp_pool=null,ni._createVec2Fn=null;var Pe=ni;var $e=class $e{static run(e,t,n,s,i,l){let r=_e(),o=r.__zpp;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=t.zpp_inner;a._validate!=null&&a._validate();let p=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=t.zpp_inner;c._validate!=null&&c._validate();let h=t.zpp_inner.y;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=n.zpp_inner;u._validate!=null&&u._validate();let x=n.zpp_inner.x-p;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let m=n.zpp_inner;m._validate!=null&&m._validate();let _=n.zpp_inner.y-h,y=s?0:-1/0,z=i?1:1/0,b=-(h*x-p*_),w=null,Z=false,d=e;for(;;){let B;Xe.zpp_pool==null?B=new Xe:(B=Xe.zpp_pool,Xe.zpp_pool=B.next,B.next=null),B.vert=d,B.posx=d.x,B.posy=d.y,B.value=B.posy*x-B.posx*_+b,B.positive=B.value>0,B.value==0&&(Z=true);let A=B;if(w==null?A.prev=A.next=A:(A.prev=w,A.next=w.next,w.next.prev=A,w.next=A),w=A,d=d.next,d==e)break}if(Z){let B=null,A=w,Y=w;if(A!=null){let U=A;for(;;){let Q=U;if(Q.value!=0){B=Q;break}if(U=U.next,U==Y)break}}let $,H;$=x,H=_;let X=$*$+H*H,q=1/Math.sqrt(X);$*=q,H*=q;let D=$;$=-H,H=D;let L=null,V=B;for(;;){if(V.value!=0&&(L==null||V==L.next)){if(L=V,V=V.next,V==B)break;continue}let U=L.value*V.value;if(U==0){if(V=V.next,V==B)break;continue}let Q=L.next,K;if(U>0)K=L.positive;else {let se=Q.next,ne,re;ne=Q.posx+se.posx,re=Q.posy+se.posy;let le=.5;ne*=le,re*=le;let he=ne+$*1e-8,pe=re+H*1e-8,ce=false,te=e,ue=e;if(te!=null){let de=te;for(;;){let me=de,ve=me.prev;if((me.y<pe&&ve.y>=pe||ve.y<pe&&me.y>=pe)&&(me.x<=he||ve.x<=he)&&me.x+(pe-me.y)/(ve.y-me.y)*(ve.x-me.x)<he&&(ce=!ce),de=de.next,de==ue)break}}K=ce;}let ie=Q,oe=V;if(ie!=null){let se=ie;for(;;){let ne=se;if(ne.positive=K,se=se.next,se==oe)break}}if(L=V,V=V.next,V==B)break}for(;!(V.value!=0&&(L==null||V==L.next));){let U=L.value*V.value;if(U==0)break;let Q=L.next,K;if(U>0)K=L.positive;else {let se=Q.next,ne,re;ne=Q.posx+se.posx,re=Q.posy+se.posy;let le=.5;ne*=le,re*=le;let he=ne+$*1e-8,pe=re+H*1e-8,ce=false,te=e,ue=e;if(te!=null){let de=te;for(;;){let me=de,ve=me.prev;if((me.y<pe&&ve.y>=pe||ve.y<pe&&me.y>=pe)&&(me.x<=he||ve.x<=he)&&me.x+(pe-me.y)/(ve.y-me.y)*(ve.x-me.x)<he&&(ce=!ce),de=de.next,de==ue)break}}K=ce;}let ie=Q,oe=V;if(ie!=null){let se=ie;for(;;){let ne=se;if(ne.positive=K,se=se.next,se==oe)break}}break}}$e.ints==null&&($e.ints=new o.util.ZNPList_ZPP_CutInt),$e.paths==null&&($e.paths=new o.util.ZNPList_ZPP_CutVert);let f=null,g=w.posx,P=w.posy,v;Pe.zpp_pool==null?v=new Pe:(v=Pe.zpp_pool,Pe.zpp_pool=v.next,v.next=null),v.forced=false,v.x=g,v.y=P;let N=v;N.prev=N.next=N,f=N;let E=f,M;Xe.zpp_pool==null?M=new Xe:(M=Xe.zpp_pool,Xe.zpp_pool=M.next,M.next=null),M.vert=f,M.parent=M,M.rank=0,M.used=false;let k=M;$e.paths.add(k);let C=w;for(;;){let B=C.next,A=B.posx,Y=B.posy,$;Pe.zpp_pool==null?$=new Pe:($=Pe.zpp_pool,Pe.zpp_pool=$.next,$.next=null),$.forced=false,$.x=A,$.y=Y;let H=$;if(C.positive==B.positive){let X=H;f==null?(X.prev=X.next=X,f=X):(X.next=f,X.prev=f.prev,f.prev.next=X,f.prev=X);}else {let X=B.posx-C.posx,ee=B.posy-C.posy,q=_*X-x*ee;q=1/q;let D=p-C.posx,L=h-C.posy,V=(ee*D-X*L)*q;if(V<y||V>z){let U=$e.ints,Q=true;let K;ot.zpp_pool==null?K=new ot:(K=ot.zpp_pool,ot.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=false,U.add(K);let ie=H;f==null?(ie.prev=ie.next=ie,f=ie):(ie.next=f,ie.prev=f.prev,f.prev.next=ie,f.prev=ie);}else if(C.value==0){let U=f.prev;f=null;let Q=U.x,K=U.y,ie;Pe.zpp_pool==null?ie=new Pe:(ie=Pe.zpp_pool,Pe.zpp_pool=ie.next,ie.next=null),ie.forced=false,ie.x=Q,ie.y=K;let oe=ie;oe.prev=oe.next=oe,f=oe;let se=H;f==null?(se.prev=se.next=se,f=se):(se.next=f,se.prev=f.prev,f.prev.next=se,f.prev=se);let ne=$e.paths.head.elt,re=$e.paths,le;Xe.zpp_pool==null?le=new Xe:(le=Xe.zpp_pool,Xe.zpp_pool=le.next,le.next=null),le.vert=f,le.parent=le,le.rank=0,le.used=false,re.add(le);let he=$e.paths.head.elt,pe=$e.ints,ce=true;let te;ot.zpp_pool==null?te=new ot:(te=ot.zpp_pool,ot.zpp_pool=te.next,te.next=null),te.virtualint=ce,te.end=U,te.start=f,te.path0=ne,te.path1=he,te.time=V,te.vertex=false,pe.add(te);}else if(B.value==0){let U=H;f==null?(U.prev=U.next=U,f=U):(U.next=f,U.prev=f.prev,f.prev.next=U,f.prev=U);let Q=f.prev;f=null;let K=B.posx,ie=B.posy,oe;Pe.zpp_pool==null?oe=new Pe:(oe=Pe.zpp_pool,Pe.zpp_pool=oe.next,oe.next=null),oe.forced=false,oe.x=K,oe.y=ie;let se=oe;se.prev=se.next=se,f=se;let ne=$e.paths.head.elt,re=$e.paths,le;Xe.zpp_pool==null?le=new Xe:(le=Xe.zpp_pool,Xe.zpp_pool=le.next,le.next=null),le.vert=f,le.parent=le,le.rank=0,le.used=false,re.add(le);let he=$e.paths.head.elt,pe=$e.ints,ce=true;let te;ot.zpp_pool==null?te=new ot:(te=ot.zpp_pool,ot.zpp_pool=te.next,te.next=null),te.virtualint=ce,te.end=Q,te.start=f,te.path0=ne,te.path1=he,te.time=V,te.vertex=false,pe.add(te);}else {let U=(_*D-x*L)*q,Q,K;Q=C.posx,K=C.posy;let ie=U;Q+=X*ie,K+=ee*ie;let oe;Pe.zpp_pool==null?oe=new Pe:(oe=Pe.zpp_pool,Pe.zpp_pool=oe.next,oe.next=null),oe.forced=false,oe.x=Q,oe.y=K;let se=oe;f==null?(se.prev=se.next=se,f=se):(se.next=f,se.prev=f.prev,f.prev.next=se,f.prev=se);let ne=f.prev;f=null;let re;Pe.zpp_pool==null?re=new Pe:(re=Pe.zpp_pool,Pe.zpp_pool=re.next,re.next=null),re.forced=false,re.x=Q,re.y=K;let le=re;le.prev=le.next=le,f=le;let he=H;f==null?(he.prev=he.next=he,f=he):(he.next=f,he.prev=f.prev,f.prev.next=he,f.prev=he);let pe=$e.paths.head.elt,ce=$e.paths,te;Xe.zpp_pool==null?te=new Xe:(te=Xe.zpp_pool,Xe.zpp_pool=te.next,te.next=null),te.vert=f,te.parent=te,te.rank=0,te.used=false,ce.add(te);let ue=$e.paths.head.elt,de=$e.ints,me=false;let ve;ot.zpp_pool==null?ve=new ot:(ve=ot.zpp_pool,ot.zpp_pool=ve.next,ve.next=null),ve.virtualint=me,ve.end=ne,ve.start=f,ve.path0=pe,ve.path1=ue,ve.time=V,ve.vertex=false,de.add(ve);}}if(C=C.next,C==w)break}let S=f.prev;S.next.prev=E.prev,E.prev.next=S.next,S.next=E,E.prev=S;let O=$e.paths.head.elt,F;if(k==k.parent)F=k;else {let B=k,A=null;for(;B!=B.parent;){let Y=B.parent;B.parent=A,A=B,B=Y;}for(;A!=null;){let Y=A.parent;A.parent=B,A=Y;}F=B;}let T;if(O==O.parent)T=O;else {let B=O,A=null;for(;B!=B.parent;){let Y=B.parent;B.parent=A,A=B,B=Y;}for(;A!=null;){let Y=A.parent;A.parent=B,A=Y;}T=B;}F!=T&&(F.rank<T.rank?F.parent=T:F.rank>T.rank?T.parent=F:(T.parent=F,F.rank++));let R=$e.ints;if(R.head!=null&&R.head.next!=null){let B=R.head,A,Y,$,H,X=1,ee,q,D;for(;;){for(ee=0,Y=B,B=null,A=B;Y!=null;){for(++ee,$=Y,q=0,D=X;$!=null&&q<X;)++q,$=$.next;for(;q>0||D>0&&$!=null;)q==0?(H=$,$=$.next,--D):D==0||$==null||Y.elt.time<$.elt.time?(H=Y,Y=Y.next,--q):(H=$,$=$.next,--D),A!=null?A.next=H:B=H,A=H;Y=$;}if(A.next=null,X<<=1,!(ee>1))break}R.head=B,R.modified=true,R.pushmod=true;}for(;$e.ints.head!=null;){let B=$e.ints.pop_unsafe(),A=$e.ints.pop_unsafe();if(!B.virtualint&&!A.virtualint){B.end.next.prev=A.start.prev,A.start.prev.next=B.end.next,B.end.next=A.start,A.start.prev=B.end,A.end.next.prev=B.start.prev,B.start.prev.next=A.end.next,A.end.next=B.start,B.start.prev=A.end;let H;if(B.path0==B.path0.parent)H=B.path0;else {let D=B.path0,L=null;for(;D!=D.parent;){let V=D.parent;D.parent=L,L=D,D=V;}for(;L!=null;){let V=L.parent;L.parent=D,L=V;}H=D;}let X;if(A.path1==A.path1.parent)X=A.path1;else {let D=A.path1,L=null;for(;D!=D.parent;){let V=D.parent;D.parent=L,L=D,D=V;}for(;L!=null;){let V=L.parent;L.parent=D,L=V;}X=D;}H!=X&&(H.rank<X.rank?H.parent=X:H.rank>X.rank?X.parent=H:(X.parent=H,H.rank++));let ee;if(B.path1==B.path1.parent)ee=B.path1;else {let D=B.path1,L=null;for(;D!=D.parent;){let V=D.parent;D.parent=L,L=D,D=V;}for(;L!=null;){let V=L.parent;L.parent=D,L=V;}ee=D;}let q;if(A.path0==A.path0.parent)q=A.path0;else {let D=A.path0,L=null;for(;D!=D.parent;){let V=D.parent;D.parent=L,L=D,D=V;}for(;L!=null;){let V=L.parent;L.parent=D,L=V;}q=D;}ee!=q&&(ee.rank<q.rank?ee.parent=q:ee.rank>q.rank?q.parent=ee:(q.parent=ee,ee.rank++));}else if(B.virtualint&&!A.virtualint){let H;if(A.end!=null&&A.end.prev==A.end){A.end.next=A.end.prev=null;let q=A.end;if(q.wrap!=null){q.wrap.zpp_inner._inuse=false;let D=q.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=D.zpp_inner;if(L._immutable)throw new Error("Error: Vec2 is immutable");if(L._isimmutable!=null&&L._isimmutable(),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 U=D;U.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=U:xe.poolVec2=U,xe.nextVec2=U,U.zpp_disp=true;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=ae.zpp_pool,ae.zpp_pool=Q,q.wrap=null;}q.prev=q.next=null,q.next=Pe.zpp_pool,Pe.zpp_pool=q,H=null;}else {let q=A.end.prev;A.end.prev.next=A.end.next,A.end.next.prev=A.end.prev,A.end.next=A.end.prev=null;let D=A.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=false;let L=D.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=L.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let Q=L;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=true;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=ae.zpp_pool,ae.zpp_pool=K,D.wrap=null;}D.prev=D.next=null,D.next=Pe.zpp_pool,Pe.zpp_pool=D,A.end=null,H=q;}if(A.end=H,!A.vertex)if(A.end!=A.path0.vert){A.start.x=A.end.x,A.start.y=A.end.y;let q;if(A.end!=null&&A.end.prev==A.end){A.end.next=A.end.prev=null;let D=A.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=false;let L=D.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=L.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let Q=L;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=true;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=ae.zpp_pool,ae.zpp_pool=K,D.wrap=null;}D.prev=D.next=null,D.next=Pe.zpp_pool,Pe.zpp_pool=D,q=null;}else {let D=A.end.prev;A.end.prev.next=A.end.next,A.end.next.prev=A.end.prev,A.end.next=A.end.prev=null;let L=A.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=false;let V=L.wrap;if(V!=null&&V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let U=V.zpp_inner;if(U._immutable)throw new Error("Error: Vec2 is immutable");if(U._isimmutable!=null&&U._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=true;let ie=Q;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=ae.zpp_pool,ae.zpp_pool=ie,L.wrap=null;}L.prev=L.next=null,L.next=Pe.zpp_pool,Pe.zpp_pool=L,A.end=null,q=D;}A.end=q;}else {let q=A.start.next;if(A.start.x=q.x,A.start.y=q.y,q!=null&&q.prev==q){q.next=q.prev=null;let D=q;if(D.wrap!=null){D.wrap.zpp_inner._inuse=false;let L=D.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=L.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let Q=L;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=true;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=ae.zpp_pool,ae.zpp_pool=K,D.wrap=null;}D.prev=D.next=null,D.next=Pe.zpp_pool,Pe.zpp_pool=D;}else {q.prev.next=q.next,q.next.prev=q.prev,q.next=q.prev=null;let D=q;if(D.wrap!=null){D.wrap.zpp_inner._inuse=false;let L=D.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=L.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let Q=L;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=true;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=ae.zpp_pool,ae.zpp_pool=K,D.wrap=null;}D.prev=D.next=null,D.next=Pe.zpp_pool,Pe.zpp_pool=D;}}A.end.next.prev=A.start.prev,A.start.prev.next=A.end.next,A.end.next=A.start,A.start.prev=A.end;let X;if(A.path0==A.path0.parent)X=A.path0;else {let q=A.path0,D=null;for(;q!=q.parent;){let L=q.parent;q.parent=D,D=q,q=L;}for(;D!=null;){let L=D.parent;D.parent=q,D=L;}X=q;}let ee;if(A.path1==A.path1.parent)ee=A.path1;else {let q=A.path1,D=null;for(;q!=q.parent;){let L=q.parent;q.parent=D,D=q,q=L;}for(;D!=null;){let L=D.parent;D.parent=q,D=L;}ee=q;}X!=ee&&(X.rank<ee.rank?X.parent=ee:X.rank>ee.rank?ee.parent=X:(ee.parent=X,X.rank++));}else if(A.virtualint&&!B.virtualint){let H;if(B.end!=null&&B.end.prev==B.end){B.end.next=B.end.prev=null;let q=B.end;if(q.wrap!=null){q.wrap.zpp_inner._inuse=false;let D=q.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=D.zpp_inner;if(L._immutable)throw new Error("Error: Vec2 is immutable");if(L._isimmutable!=null&&L._isimmutable(),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 U=D;U.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=U:xe.poolVec2=U,xe.nextVec2=U,U.zpp_disp=true;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=ae.zpp_pool,ae.zpp_pool=Q,q.wrap=null;}q.prev=q.next=null,q.next=Pe.zpp_pool,Pe.zpp_pool=q,H=null;}else {let q=B.end.prev;B.end.prev.next=B.end.next,B.end.next.prev=B.end.prev,B.end.next=B.end.prev=null;let D=B.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=false;let L=D.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=L.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let Q=L;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=true;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=ae.zpp_pool,ae.zpp_pool=K,D.wrap=null;}D.prev=D.next=null,D.next=Pe.zpp_pool,Pe.zpp_pool=D,B.end=null,H=q;}if(B.end=H,!B.vertex)if(B.end!=B.path0.vert){B.start.x=B.end.x,B.start.y=B.end.y;let q;if(B.end!=null&&B.end.prev==B.end){B.end.next=B.end.prev=null;let D=B.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=false;let L=D.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=L.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let Q=L;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=true;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=ae.zpp_pool,ae.zpp_pool=K,D.wrap=null;}D.prev=D.next=null,D.next=Pe.zpp_pool,Pe.zpp_pool=D,q=null;}else {let D=B.end.prev;B.end.prev.next=B.end.next,B.end.next.prev=B.end.prev,B.end.next=B.end.prev=null;let L=B.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=false;let V=L.wrap;if(V!=null&&V.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let U=V.zpp_inner;if(U._immutable)throw new Error("Error: Vec2 is immutable");if(U._isimmutable!=null&&U._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=true;let ie=Q;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=ae.zpp_pool,ae.zpp_pool=ie,L.wrap=null;}L.prev=L.next=null,L.next=Pe.zpp_pool,Pe.zpp_pool=L,B.end=null,q=D;}B.end=q;}else {let q=B.start.next;if(B.start.x=q.x,B.start.y=q.y,q!=null&&q.prev==q){q.next=q.prev=null;let D=q;if(D.wrap!=null){D.wrap.zpp_inner._inuse=false;let L=D.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=L.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let Q=L;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=true;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=ae.zpp_pool,ae.zpp_pool=K,D.wrap=null;}D.prev=D.next=null,D.next=Pe.zpp_pool,Pe.zpp_pool=D;}else {q.prev.next=q.next,q.next.prev=q.prev,q.next=q.prev=null;let D=q;if(D.wrap!=null){D.wrap.zpp_inner._inuse=false;let L=D.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let V=L.zpp_inner;if(V._immutable)throw new Error("Error: Vec2 is immutable");if(V._isimmutable!=null&&V._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let U=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let Q=L;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=true;let K=U;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=ae.zpp_pool,ae.zpp_pool=K,D.wrap=null;}D.prev=D.next=null,D.next=Pe.zpp_pool,Pe.zpp_pool=D;}}B.end.next.prev=B.start.prev,B.start.prev.next=B.end.next,B.end.next=B.start,B.start.prev=B.end;let X;if(B.path0==B.path0.parent)X=B.path0;else {let q=B.path0,D=null;for(;q!=q.parent;){let L=q.parent;q.parent=D,D=q,q=L;}for(;D!=null;){let L=D.parent;D.parent=q,D=L;}X=q;}let ee;if(B.path1==B.path1.parent)ee=B.path1;else {let q=B.path1,D=null;for(;q!=q.parent;){let L=q.parent;q.parent=D,D=q,q=L;}for(;D!=null;){let L=D.parent;D.parent=q,D=L;}ee=q;}X!=ee&&(X.rank<ee.rank?X.parent=ee:X.rank>ee.rank?ee.parent=X:(ee.parent=X,X.rank++));}let Y=B;Y.end=Y.start=null,Y.path0=Y.path1=null,Y.next=ot.zpp_pool,ot.zpp_pool=Y;let $=A;$.end=$.start=null,$.path0=$.path1=null,$.next=ot.zpp_pool,ot.zpp_pool=$;}let W=l??new r.geom.GeomPolyList,G=$e.paths.head;for(;G!=null;){let B=G.elt,A;if(B==B.parent)A=B;else {let H=B,X=null;for(;H!=H.parent;){let ee=H.parent;H.parent=X,X=H,H=ee;}for(;X!=null;){let ee=X.parent;X.parent=H,X=ee;}A=H;}if(A.used){G=G.next;continue}A.used=true;let Y=A.vert,$=true;for(;A.vert!=null&&($||Y!=A.vert);)if($=false,Y.x==Y.next.x&&Y.y==Y.next.y)if(Y==A.vert&&(A.vert=Y.next==Y?null:Y.next,$=true),Y!=null&&Y.prev==Y)Y.next=Y.prev=null,Y=null;else {let H=Y.next;Y.prev.next=Y.next,Y.next.prev=Y.prev,Y.next=Y.prev=null,Y=H;}else Y=Y.next;if(A.vert!=null){let H=r.geom.GeomPoly.get();H.zpp_inner.vertices=A.vert,W.zpp_inner.reverse_flag?W.push(H):W.unshift(H);}G=G.next;}for(;$e.paths.head!=null;){let A=$e.paths.pop_unsafe();A.vert=null,A.parent=null,A.next=Xe.zpp_pool,Xe.zpp_pool=A;}for(;w!=null;)if(w!=null&&w.prev==w){w.next=w.prev=null;let B=w;B.vert=null,B.parent=null,B.next=Xe.zpp_pool,Xe.zpp_pool=B,w=null;}else {let B=w.next;w.prev.next=w.next,w.next.prev=w.prev,w.next=w.prev=null;let A=w;A.vert=null,A.parent=null,A.next=Xe.zpp_pool,Xe.zpp_pool=A,w=B;}return W}};$e.ints=null,$e.paths=null;var is=$e;var ss=class j{static validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=false,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=false,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=false,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=false,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=t.body.posx+(t.body.axisy*u.x-t.body.axisx*u.y),h.y=t.body.posy+(u.x*t.body.axisx+u.y*t.body.axisy),c=c.next;}}let s=t.edges.head,i=t.gverts.next,l=i;for(i=i.next;i!=null;){let a=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,l=a,i=i.next;}let r=t.gverts.next,o=s.elt;o.gp0=l,o.gp1=r,o.gnormx=t.body.axisy*o.lnormx-t.body.axisx*o.lnormy,o.gnormy=o.lnormx*t.body.axisx+o.lnormy*t.body.axisy,o.gprojection=t.body.posx*o.gnormx+t.body.posy*o.gnormy+o.lprojection,o.wrap_gnorm!=null&&(o.wrap_gnorm.zpp_inner.x=o.gnormx,o.wrap_gnorm.zpp_inner.y=o.gnormy),o.tp0=o.gp0.y*o.gnormx-o.gp0.x*o.gnormy,o.tp1=o.gp1.y*o.gnormx-o.gp1.x*o.gnormy;}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=false,e.type==0){let t=e.circle;j._validateWorldCOM(t);let n=t.radius,s=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-s,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+s;}else {let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=false,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=false,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,r=t.gverts.next;for(;r!=null;){let o=r,a=l;l=l.next,o.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),o.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),r=r.next;}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next;}}if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=false,e.zip_localCOM&&(e.zip_localCOM=false,e.type==1&&j._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=false,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=false,e.zip_localCOM&&(e.zip_localCOM=false,e.type==1&&j._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=false,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy);}}static _computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null){e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;let t=1;e.localCOMx+=e.lverts.next.next.x*t,e.localCOMy+=e.lverts.next.next.y*t;let n=.5;e.localCOMx*=n,e.localCOMy*=n;}else {e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let c=n;t+=i.x*(c.y-s.y);let h=c.y*i.x-c.x*i.y;e.localCOMx+=(i.x+c.x)*h,e.localCOMy+=(i.y+c.y)*h,s=i,i=c,n=n.next;}n=e.lverts.next;let l=n;t+=i.x*(l.y-s.y);let r=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*r,e.localCOMy+=(i.y+l.y)*r,s=i,i=l,n=n.next;let o=n;t+=i.x*(o.y-s.y);let a=o.y*i.x-o.x*i.y;e.localCOMx+=(i.x+o.x)*a,e.localCOMy+=(i.y+o.y)*a,t=1/(3*t);let p=t;e.localCOMx*=p,e.localCOMy*=p;}}};var ls=class{constructor(e=null){this.outer=null;this.vertices=null;this.outer=e;}};var In=class{constructor(){this.rank=0;this.out=false;this.next=null;this.parent=this;}free(){this.parent=this;}alloc(){this.out=false,this.rank=0;}};In.zpp_pool=null;var jn=class{constructor(){this.p1=null;this.key1=0;this.okey1=0;this.p2=null;this.key2=0;this.okey2=0;this.pr=null;this.keyr=0;this.okeyr=0;this.pd=null;this.span1=null;this.span2=null;this.spanr=null;this.next=null;}free(){this.p1=this.p2=this.pr=this.pd=null,this.span1=this.span2=this.spanr=null;}alloc(){}};jn.zpp_pool=null;var fe=class fe{static _init(e,t){fe._zpp=e,fe._nape=t,fe.me=new fe,fe.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 Pe.zpp_pool==null?n=new Pe:(n=Pe.zpp_pool,Pe.zpp_pool=n.next,n.next=null),n.forced=false,n.x=e,n.y=t,n}static _freeVert(e){if(e.wrap!=null){e.wrap.zpp_inner._inuse=false;let t=e.wrap;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=t.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let s=t.zpp_inner;t.zpp_inner.outer=null,t.zpp_inner=null;let i=t;i.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=i:xe.poolVec2=i,xe.nextVec2=i,i.zpp_disp=true;let l=s;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l._isimmutable=null,l._validate=null,l._invalidate=null,l.next=ae.zpp_pool,ae.zpp_pool=l,e.wrap=null;}e.prev=e.next=null,e.next=Pe.zpp_pool,Pe.zpp_pool=e;}static _allocSpan(){let e;return In.zpp_pool==null?e=new In:(e=In.zpp_pool,In.zpp_pool=e.next,e.next=null),e.out=false,e.rank=0,e}static _allocPair(){let e;return jn.zpp_pool==null?e=new jn:(e=jn.zpp_pool,jn.zpp_pool=e.next,e.next=null),e}static _freePair(e){e.p1=e.p2=e.pr=e.pd=null,e.span1=e.span2=e.spanr=null,e.next=jn.zpp_pool,jn.zpp_pool=e;}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let s=t.parent;t.parent=n,n=t,t=s;}for(;n!=null;){let s=n.parent;n.parent=t,n=s;}return t}static _union(e,t){let n=fe._findRoot(e),s=fe._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++));}static _pushVert(e,t){return e==null?t.prev=t.next=t:(t.prev=e,t.next=e.next,e.next.prev=t,e.next=t),t}static _isDegenKey(e){return e==1||e==4||e==16||e==64||e==3||e==12||e==48||e==192||e==129||e==6||e==24||e==96||e==5||e==20||e==80||e==65||e==17||e==68}static ISO(e,t,n){return e(t,n)}static run(e,t,n,s,i,l,r,o,a){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate();let c=(s-t)/l.zpp_inner.x,h=c|0;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");p=l.zpp_inner,p._validate!=null&&p._validate();let u=(i-n)/l.zpp_inner.y,x=u|0;c!=h&&++h,u!=x&&++x,o&&(fe.map==null?fe.map=new Yi(h,x):fe.map.resize(h,x,null)),fe.isos==null?fe.isos=new Ui(h+1,x+1):fe.isos.resize(h+1,x+1,0);for(let y=0;y<x+1;y++){let z;if(y==0)z=n;else if(y<=x){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let b=l.zpp_inner;b._validate!=null&&b._validate(),z=n+l.zpp_inner.y*y;}else z=i;for(let b=0;b<h+1;b++){let w;if(b==0)w=t;else if(b<=h){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let f=l.zpp_inner;f._validate!=null&&f._validate(),w=t+l.zpp_inner.x*b;}else w=s;let Z=fe.isos,d=e(w,z);Z.list[y*Z.width+b]=d;}}fe.ints==null?fe.ints=new Ki(h+1,(x<<1)+1):fe.ints.resize(h+1,(x<<1)+1,null);let m=null;o&&(m=fe._allocSpan(),m.next=null);let _=n;for(let y=0;y<x;y++){let z=_,b;if(y==x-1)b=i;else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let d=l.zpp_inner;d._validate!=null&&d._validate(),b=n+l.zpp_inner.y*(y+1);}_=b;let w=t,Z=null;for(let d=0;d<h;d++){let f=w,g;if(d==h-1)g=s;else {if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let k=l.zpp_inner;k._validate!=null&&k._validate(),g=t+l.zpp_inner.x*(d+1);}w=g;let P=d==0||!o,v=y==0||!o,N=d==h-1||!o,E=y==x-1||!o,M=fe.me.marchSquare(e,fe.isos,fe.ints,f,z,g,b,d,y,P,v,N,E,r);if(M==null){Z=null;continue}if(o){let k=M.p2!=null&&M.okey2!=14?M.p2:M.p1;M.pd=((k==M.p2?M.okey2:M.okey1)&128)==0?k.prev:k.prev.prev;let C=fe.map;C.list[y*C.width+d]=M;let S;if(Z!=null){let T=M.key1,R=T&1|(T&192)>>5,W=0;(R&1)!=0&&++W,(R&2)!=0&&++W,(R&4)!=0&&++W,S=W>=2;}else S=false;S?(fe.me.combLR(Z,M),M.span1=Z.spanr):(M.span1=fe._allocSpan(),M.span1.next=m,m=M.span1),M.p2!=null?(M.span2=fe._allocSpan(),M.span2.next=m,m=M.span2,M.spanr=M.span2):M.spanr=M.span1;let O=(M.keyr&28)>>2,F=0;(O&1)!=0&&++F,(O&2)!=0&&++F,(O&4)!=0&&++F,F>=2?Z=M:Z=null;}else fe.me.output(a,M.p1),M.p2!=null&&fe.me.output(a,M.p2),fe._freePair(M);}}if(o){for(let y=1;y<x;y++){let z=null;for(let b=0;b<h;b++){let w=fe.map,Z=w.list[y*w.width+b];if(Z==null){z=null;continue}let f=(Z.p2!=null&&Z.okey2==14?Z.okey2:Z.okey1)&7,g=0;if((f&1)!=0&&++g,(f&2)!=0&&++g,(f&4)!=0&&++g,g<2){z=null;continue}let P=fe.map,v=P.list[(y-1)*P.width+b];if(v==null){z=null;continue}let E=((v.p2!=null&&v.okey2==56?v.okey2:v.okey1)&112)>>4,M=0;if((E&1)!=0&&++M,(E&2)!=0&&++M,(E&4)!=0&&++M,M<2){z=null;continue}let k=v.p2!=null&&v.okey2==56?v.span2:v.span1,C=Z.p2!=null&&Z.okey2==14?Z.span2:Z.span1,S=fe._findRoot(k),O=fe._findRoot(C);S==O?z!=C&&fe.me.combUD_virtual(v,Z):(fe._union(k,C),fe.me.combUD(v,Z)),z=((C==Z.span2?Z.okey2:Z.okey1)&4)!=0?C:null;}}for(let y=0;y<x;y++)for(let z=0;z<h;z++){let b=fe.map,w=b.list[y*b.width+z];if(w==null)continue;let Z=fe._findRoot(w.span1);Z.out||(Z.out=true,fe.me.output(a,w.p1)),w.p2!=null&&(Z=fe._findRoot(w.span2),Z.out||(Z.out=true,fe.me.output(a,w.p2))),fe._freePair(w),b.list[y*b.width+z]=null;}for(;m!=null;){let y=m;m=y.next;let z=y;z.parent=z,z.next=In.zpp_pool,In.zpp_pool=z;}}}output(e,t){let n=fe._nape,s;if(t==null||t.next==t||t.next==t.prev)s=true;else {let r=0,o=t,a=t;if(o!=null){let c=o;for(;;){let h=c;if(r+=h.x*(h.next.y-h.prev.y),c=c.next,c==a)break}}let p=r*.5;s=p*p<n.Config.epsilon*n.Config.epsilon;}if(s){for(;t!=null;)if(t!=null&&t.prev==t)t.next=t.prev=null,t=null;else {let r=t.next;t.prev.next=t.next,t.next.prev=t.prev,t.next=t.prev=null,t=r;}return}let i=n.geom.GeomPoly.get();i.zpp_inner.vertices=t;let l=e;l.zpp_inner.reverse_flag?l.push(i):l.unshift(i);}linkright(e,t){let n=t&7;return n==0?e:n==3?e.next.next:e.next}linkleft(e,t){return (t&1)==0?e.prev:e}linkdown(e,t){return (t&128)==0?e.prev:e.prev.prev}linkup(e,t){return e}combLR(e,t){let n=e.pr,s=e.okeyr&7,i=s==0?n:s==3?n.next.next:n.next,l=t.p1,r=(t.okey1&1)==0?l.prev:l,o=i.next,a=r.prev;(e.keyr&4)!=0?(t.pr==t.p1&&(t.pr=i.prev),t.p1=i.prev,i.prev.next=r.next,r.next.prev=i.prev,fe._freeVert(i)):(i.next=r.next,r.next.prev=i),fe._freeVert(r),(e.keyr&16)!=0?(t.pd=o.next,o.next.prev=a.prev,a.prev.next=o.next,fe._freeVert(o)):(o.prev=a.prev,a.prev.next=o),fe._freeVert(a);}combUD(e,t){let n=e.pd,s=t.p2!=null&&t.key2==14?t.p2:t.p1,i=n.prev,l=s.next;s.next=n.next,n.next.prev=s,fe._freeVert(n),l.prev=i.prev,i.prev.next=l,i==e.p1&&(e.p1=l),fe._freeVert(i);}combUD_virtual(e,t){let n=e.pd,s=t.p2!=null&&t.key2==14?t.p2:t.p1,i=n.prev,l=s.next;n.forced=s.forced=i.forced=l.forced=true;}combLeft(e){let t=e&1|(e&192)>>5,n=0;return (t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combRight(e){let t=(e&28)>>2,n=0;return (t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combUp(e){let t=e&7,n=0;return (t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combDown(e){let t=(e&112)>>4,n=0;return (t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}comb(e){let t=0;return (e&1)!=0&&++t,(e&2)!=0&&++t,(e&4)!=0&&++t,t>=2}_buildPoly(e,t,n,s,i,l,r,o,a,p,c,h,u,x,m,_,y,z,b){let w=null;for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let d;if(Z==0)d=fe._allocVert(s,i),(x||m)&&(d.forced=true);else if(Z==2)d=fe._allocVert(l,i),(_||m)&&(d.forced=true);else if(Z==4)d=fe._allocVert(l,r),(_||y)&&(d.forced=true);else if(Z==6)d=fe._allocVert(s,r),(x||y)&&(d.forced=true);else if(Z==1){if(d=n.list[(a<<1)*n.width+o],d==null){let f=this.xlerp(s,l,i,p,c,z,b);d=fe._allocVert(f,i),n.list[(a<<1)*n.width+o]=d;}else d=fe._allocVert(d.x,d.y);m&&(d.forced=true),(d.x==s||d.x==l)&&(d.x==s&&(e&1)!=0||d.x==l&&(e&4)!=0)&&(e^=2);}else if(Z==5){if(d=n.list[((a<<1)+2)*n.width+o],d==null){let f=this.xlerp(s,l,r,u,h,z,b);d=fe._allocVert(f,r),n.list[((a<<1)+2)*n.width+o]=d;}else d=fe._allocVert(d.x,d.y);y&&(d.forced=true),(d.x==s||d.x==l)&&(d.x==s&&(e&64)!=0||d.x==l&&(e&16)!=0)&&(e^=32);}else if(Z==3){if(d=n.list[((a<<1)+1)*n.width+(o+1)],d==null){let f=this.ylerp(i,r,l,c,h,z,b);d=fe._allocVert(l,f),n.list[((a<<1)+1)*n.width+(o+1)]=d;}else d=fe._allocVert(d.x,d.y);_&&(d.forced=true),(d.y==i||d.y==r)&&(d.y==i&&(e&4)!=0||d.y==r&&(e&16)!=0)&&(e^=8);}else {if(d=n.list[((a<<1)+1)*n.width+o],d==null){let f=this.ylerp(i,r,s,p,u,z,b);d=fe._allocVert(s,f),n.list[((a<<1)+1)*n.width+o]=d;}else d=fe._allocVert(d.x,d.y);x&&(d.forced=true),(d.y==i||d.y==r)&&(d.y==i&&(e&1)!=0||d.y==r&&(e&64)!=0)&&(e^=128);}w=fe._pushVert(w,d);}return w!=null&&(w=w.next),{head:w,val:e}}marchSquare(e,t,n,s,i,l,r,o,a,p,c,h,u,x){let m=0,_=t.list[a*t.width+o];_<0&&(m|=8);let y=t.list[a*t.width+(o+1)];y<0&&(m|=4);let z=t.list[(a+1)*t.width+(o+1)];z<0&&(m|=2);let b=t.list[(a+1)*t.width+o];if(b<0&&(m|=1),m==0)return null;let w=fe._allocPair();if(m!=10&&m!=5){let Z=fe.look_march[m];w.okey1=Z;let d=this._buildPoly(Z,t,n,s,i,l,r,o,a,_,y,z,b,p,c,h,u,e,x);w.p1=d.head,Z=d.val,w.key1=Z,fe._isDegenKey(Z)&&(Z=0,w.key1=0,w.p1=null),Z==0?w=null:(w.pr=w.p1,w.okeyr=w.okey1,w.keyr=w.key1);}else {let Z=e(.5*(s+l),.5*(i+r))<0;if(m==10)if(Z){let d=187;w.okey1=d;let f=this._buildPoly(d,t,n,s,i,l,r,o,a,_,y,z,b,p,c,h,u,e,x);w.p1=f.head,d=f.val,w.key1=d,fe._isDegenKey(d)&&(d=0,w.key1=0,w.p1=null),d==0?w=null:(w.pr=w.p1,w.okeyr=w.okey1,w.keyr=w.key1);}else {let d=131;w.okey1=d;let f=this._buildPoly(d,t,n,s,i,l,r,o,a,_,y,z,b,p,c,h,u,e,x);if(w.p1=f.head,d=f.val,w.key1=d,fe._isDegenKey(d)&&(d=0,w.key1=0,w.p1=null),d!=0){let g=56;w.okey2=g,g=this._buildPoly2(g,t,n,s,i,l,r,o,a,_,y,z,b,p,c,h,u,e,x,w).val,w.key2=g,fe._isDegenKey(g)&&(g=0,w.key2=0,w.p2=null),g==0?(w.pr=w.p1,w.okeyr=w.okey1,w.keyr=w.key1):(w.pr=w.p2,w.okeyr=w.okey2,w.keyr=w.key2);}else {let g=56;w.okey1=g;let P=this._buildPoly(g,t,n,s,i,l,r,o,a,_,y,z,b,p,c,h,u,e,x);w.p1=P.head,g=P.val,w.key1=g,fe._isDegenKey(g)&&(g=0,w.key1=0,w.p1=null),g==0?w=null:(w.pr=w.p1,w.okeyr=w.okey1,w.keyr=w.key1);}}else if(Z){let d=238;w.okey1=d;let f=this._buildPoly(d,t,n,s,i,l,r,o,a,_,y,z,b,p,c,h,u,e,x);w.p1=f.head,d=f.val,w.key1=d,fe._isDegenKey(d)&&(d=0,w.key1=0,w.p1=null),d==0?w=null:(w.pr=w.p1,w.okeyr=w.okey1,w.keyr=w.key1);}else {let d=224;w.okey1=d;let f=this._buildPoly(d,t,n,s,i,l,r,o,a,_,y,z,b,p,c,h,u,e,x);if(w.p1=f.head,d=f.val,w.key1=d,fe._isDegenKey(d)&&(d=0,w.key1=0,w.p1=null),d!=0){let g=14;w.okey2=g,g=this._buildPoly2(g,t,n,s,i,l,r,o,a,_,y,z,b,p,c,h,u,e,x,w).val,w.key2=g,fe._isDegenKey(g)&&(g=0,w.key2=0,w.p2=null),g==0?(w.pr=w.p1,w.okeyr=w.okey1,w.keyr=w.key1):(w.pr=w.p2,w.okeyr=w.okey2,w.keyr=w.key2);}else {let g=14;w.okey1=g;let P=this._buildPoly(g,t,n,s,i,l,r,o,a,_,y,z,b,p,c,h,u,e,x);w.p1=P.head,g=P.val,w.key1=g,fe._isDegenKey(g)&&(g=0,w.key1=0,w.p1=null),g==0?w=null:(w.pr=w.p1,w.okeyr=w.okey1,w.keyr=w.key1);}}}return w}_buildPoly2(e,t,n,s,i,l,r,o,a,p,c,h,u,x,m,_,y,z,b,w){for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let d;if(Z==0)d=fe._allocVert(s,i),(x||m)&&(d.forced=true);else if(Z==2)d=fe._allocVert(l,i),(_||m)&&(d.forced=true);else if(Z==4)d=fe._allocVert(l,r),(_||y)&&(d.forced=true);else if(Z==6)d=fe._allocVert(s,r),(x||y)&&(d.forced=true);else if(Z==1){if(d=n.list[(a<<1)*n.width+o],d==null){let g=this.xlerp(s,l,i,p,c,z,b);d=fe._allocVert(g,i),n.list[(a<<1)*n.width+o]=d;}else d=fe._allocVert(d.x,d.y);m&&(d.forced=true),(d.x==s||d.x==l)&&(d.x==s&&(e&1)!=0||d.x==l&&(e&4)!=0)&&(e^=2);}else if(Z==5){if(d=n.list[((a<<1)+2)*n.width+o],d==null){let g=this.xlerp(s,l,r,u,h,z,b);d=fe._allocVert(g,r),n.list[((a<<1)+2)*n.width+o]=d;}else d=fe._allocVert(d.x,d.y);y&&(d.forced=true),(d.x==s||d.x==l)&&(d.x==s&&(e&64)!=0||d.x==l&&(e&16)!=0)&&(e^=32);}else if(Z==3){if(d=n.list[((a<<1)+1)*n.width+(o+1)],d==null){let g=this.ylerp(i,r,l,c,h,z,b);d=fe._allocVert(l,g),n.list[((a<<1)+1)*n.width+(o+1)]=d;}else d=fe._allocVert(d.x,d.y);_&&(d.forced=true),(d.y==i||d.y==r)&&(d.y==i&&(e&4)!=0||d.y==r&&(e&16)!=0)&&(e^=8);}else {if(d=n.list[((a<<1)+1)*n.width+o],d==null){let g=this.ylerp(i,r,s,p,u,z,b);d=fe._allocVert(s,g),n.list[((a<<1)+1)*n.width+o]=d;}else d=fe._allocVert(d.x,d.y);x&&(d.forced=true),(d.y==i||d.y==r)&&(d.y==i&&(e&1)!=0||d.y==r&&(e&64)!=0)&&(e^=128);}let f=d;w.p2==null?w.p2=f.prev=f.next=f:(f.prev=w.p2,f.next=w.p2.next,w.p2.next.prev=f,w.p2.next=f),w.p2=f;}return w.p2!=null&&(w.p2=w.p2.next),{val:e}}lerp(e,t,n,s){let i=fe._nape;if(n==0)return e;if(s==0)return t;{let l=n-s,r=l*l<i.Config.epsilon*i.Config.epsilon?.5:n/l;return r<0?r=0:r>1&&(r=1),e+r*(t-e)}}xlerp(e,t,n,s,i,l,r){let o=fe._nape,a;if(s==0)a=e;else if(i==0)a=t;else {let p=s-i,c=p*p<o.Config.epsilon*o.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e);}for(;r--!=0&&e<a&&a<t;){let p=l(a,n);if(p==0)break;if(s*p<0?(t=a,i=p):(e=a,s=p),s==0)a=e;else if(i==0)a=t;else {let c=s-i,h=c*c<o.Config.epsilon*o.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),a=e+h*(t-e);}}return a}ylerp(e,t,n,s,i,l,r){let o=fe._nape,a;if(s==0)a=e;else if(i==0)a=t;else {let p=s-i,c=p*p<o.Config.epsilon*o.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e);}for(;r--!=0&&e<a&&a<t;){let p=l(n,a);if(p==0)break;if(s*p<0?(t=a,i=p):(e=a,s=p),s==0)a=e;else if(i==0)a=t;else {let c=s-i,h=c*c<o.Config.epsilon*o.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),a=e+h*(t-e);}}return a}};fe.isos=null,fe.ints=null,fe.map=null,fe._zpp=null,fe._nape=null;var ks=fe;var hn=class hn{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 hn.zpp_pool==null?e=new hn:(e=hn.zpp_pool,hn.zpp_pool=e.next,e.next=null),e}static identity(){let e=hn.get();return e.setas(1,0,0,1,0,0),e}wrapper(){if(this.outer==null)if(hn._wrapFn)this.outer=hn._wrapFn(this);else {this.outer=new hn._nape.geom.Mat23;let e=this.outer.zpp_inner;e.next=hn.zpp_pool,hn.zpp_pool=e,this.outer.zpp_inner=this;}return this.outer}invalidate(){this._invalidate!=null&&this._invalidate();}set(e){this.setas(e.a,e.b,e.c,e.d,e.tx,e.ty);}setas(e,t,n,s,i,l){this.tx=i,this.ty=l,this.a=e,this.b=t,this.c=n,this.d=s;}free(){}alloc(){}};hn._nape=null,hn._wrapFn=null,hn.zpp_pool=null;var Es=hn;var ji=class{constructor(e,t){this.outer=null;this.m=0;this.n=0;this.m=e,this.n=t,this.x=[];let n=0,s=e*t;for(;n<s;)n++,this.x.push(0);}};var yt=class yt{constructor(){this.node=null;this.prev=null;this.next=null;this.rightchain=false;this.helper=null;this.type=0;this.diagonals=null;this.forced=false;this.y=0;this.x=0;this.mag=0;this.id=0;this.id=yt.nextId++,this.diagonals=new ui;}static get(e){let t;return yt.zpp_pool==null?t=new yt:(t=yt.zpp_pool,yt.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t}static rightdistance(e,t){let n=e.next.y>e.y,s=e.next.x-e.x,i=e.next.y-e.y,l=t.x-e.x,r=t.y-e.y;return (n?-1:1)*(r*s-l*i)}static vert_lt(e,t){if(t==e||t==e.next)return true;if(e.y==e.next.y){let n=e.x,s=e.next.x;return (n<s?n:s)<=t.x}else return yt.rightdistance(e,t)<=0}static edge_swap(e,t){let n=e.node;e.node=t.node,t.node=n;}static edge_lt(e,t){if(e==t&&e.next==t.next)return false;if(e==t.next)return !yt.vert_lt(e,t);if(t==e.next)return yt.vert_lt(t,e);if(e.y==e.next.y)if(t.y==t.next.y){let n=e.x,s=e.next.x,i=t.x,l=t.next.x;return (n>s?n:s)>(i>l?i:l)}else return yt.rightdistance(t,e)>0?true:yt.rightdistance(t,e.next)>0;else {let n=yt.rightdistance(e,t),s=yt.rightdistance(e,t.next);if(n==0&&s==0){let r=e.x,o=e.next.x,a=t.x,p=t.next.x;return (r>o?r:o)>(a>p?a:p)}if(n*s>=0)return n<0?true:s<0;let i=yt.rightdistance(t,e),l=yt.rightdistance(t,e.next);return i*l>=0?i>0?true:l>0:false}}alloc(){}free(){this.helper=null;}copy(){let e;return yt.zpp_pool==null?e=new yt:(e=yt.zpp_pool,yt.zpp_pool=e.next,e.next=null),e.x=this.x,e.y=this.y,e.forced=this.forced,e}sort(){let e=this.prev.x-this.x,t=this.prev.y-this.y,n=this.next.x-this.x,s=this.next.y-this.y,i=s*e-n*t,l=i>0?-1:i==0?0:1,r=this.diagonals;if(r.head!=null&&r.head.next!=null){let o=r.head,a,p,c,h,u=1,x,m,_;for(;;){for(x=0,p=o,o=null,a=o;p!=null;){for(++x,c=p,m=0,_=u;c!=null&&m<u;)++m,c=c.next;for(;m>0||_>0&&c!=null;){if(m==0)h=c,c=c.next,--_;else if(_==0||c==null)h=p,p=p.next,--m;else {let y;if(l==1){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,s=c.elt.y-this.y;let z=s*e-n*t;y=(z>0?-1:z==0?0:1)==1;}else {e=this.prev.x-this.x,t=this.prev.y-this.y,n=p.elt.x-this.x,s=p.elt.y-this.y;let z=s*e-n*t,b=z>0?-1:z==0?0:1;e=this.prev.x-this.x,t=this.prev.y-this.y,n=c.elt.x-this.x,s=c.elt.y-this.y;let w=s*e-n*t,Z=w>0?-1:w==0?0:1;if(b*Z==1||b*Z==0&&(b==1||Z==1)){e=p.elt.x-this.x,t=p.elt.y-this.y,n=c.elt.x-this.x,s=c.elt.y-this.y;let d=s*e-n*t;y=(d>0?-1:d==0?0:1)==1;}else if(b==-1||Z==-1)y=Z==-1;else if(b==0&&Z==0){e=this.x-this.prev.x,t=this.y-this.prev.y,n=p.elt.x-this.x,s=p.elt.y-this.y;let d=e*n+t*s;n=c.elt.x-this.x,s=c.elt.y-this.y;let f=e*n+t*s;y=d<0&&f>0?true:!(f<0&&d>0);}else y=true;}y?(h=p,p=p.next,--m):(h=c,c=c.next,--_);}a!=null?a.next=h:o=h,a=h;}p=c;}if(a.next=null,u<<=1,!(x>1))break}r.head=o,r.modified=true,r.pushmod=true;}}};yt.zpp_pool=null,yt.nextId=0;var Ge=yt;var un=class un{constructor(e){this.next=null;this.vertices=null;this.init(e);}static getSharedPP(){return un.sharedPPList==null&&(un.sharedPPList=new Oi),un.sharedPPList}static getShared(){return un.sharedGVList==null&&(un.sharedGVList=new Gn),un.sharedGVList}eq(e,t){let n=e.x-t.x,s=e.y-t.y;return n*n+s*s<_e().Config.epsilon*_e().Config.epsilon}alloc(){}free(){}init(e){if(e==null)return;let t=0,n=e,s=e;if(n!=null){let r=n;for(;;){let o=r;if(t+=o.x*(o.next.y-o.prev.y),r=r.next,r==s)break}}let i=t*.5>0,l=e;for(;;){let r;if(i){let o;Ge.zpp_pool==null?o=new Ge:(o=Ge.zpp_pool,Ge.zpp_pool=o.next,o.next=null),o.x=l.x,o.y=l.y;let a=o;this.vertices==null?this.vertices=a.prev=a.next=a:(a.prev=this.vertices,a.next=this.vertices.next,this.vertices.next.prev=a,this.vertices.next=a),r=a;}else {let o;Ge.zpp_pool==null?o=new Ge:(o=Ge.zpp_pool,Ge.zpp_pool=o.next,o.next=null),o.x=l.x,o.y=l.y;let a=o;this.vertices==null?this.vertices=a.prev=a.next=a:(a.next=this.vertices,a.prev=this.vertices.prev,this.vertices.prev.next=a,this.vertices.prev=a),r=a;}if(this.vertices=r,this.vertices.forced=l.forced,l=l.next,l==e)break}this.remove_collinear_vertices();}remove_collinear_vertices(){let e=this.vertices,t=true;for(;t||e!=this.vertices;)if(t=false,this.eq(e,e.next)){if(e==this.vertices&&(this.vertices=e.next,t=true),e.forced&&(e.next.forced=true),e!=null&&e.prev==e){e.next=e.prev=null;let s=e;s.helper=null,s.next=Ge.zpp_pool,Ge.zpp_pool=s,e=null,e=null;}else {let s=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let i=e;i.helper=null,i.next=Ge.zpp_pool,Ge.zpp_pool=i,e=s;}if(e==null){this.vertices=null;break}}else e=e.next;if(this.vertices==null)return true;let n;for(;;){for(n=false,e=this.vertices,t=true;t||e!=this.vertices;){t=false;let s=e.prev,i=e.x-s.x,l=e.y-s.y,r=e.next.x-e.x,a=(e.next.y-e.y)*i-r*l;if(a*a>=_e().Config.epsilon*_e().Config.epsilon)e=e.next;else {if(e==this.vertices&&(this.vertices=e.next,t=true),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=true,e==null){n=false,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=true;}extract_partitions(e){if(e==null&&(e=new Oi),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}for(this.pull_partitions(this.vertices,e);this.vertices!=null;){let l;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let r=this.vertices;r.helper=null,r.next=Ge.zpp_pool,Ge.zpp_pool=r,l=this.vertices=null;}else {let r=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let o=this.vertices;o.helper=null,o.next=Ge.zpp_pool,Ge.zpp_pool=o,this.vertices=null,l=r;}this.vertices=l;}let s=null,i=e.head;for(;i!=null;){if(i.elt.remove_collinear_vertices()){e.erase(s);continue}s=i,i=i.next;}}return e}pull_partitions(e,t){let n;un.zpp_pool==null?n=new un:(n=un.zpp_pool,un.zpp_pool=n.next,n.next=null);let s=e;for(;;){let o;Ge.zpp_pool==null?o=new Ge:(o=Ge.zpp_pool,Ge.zpp_pool=o.next,o.next=null),o.x=s.x,o.y=s.y,o.forced=s.forced;let a=o;if(n.vertices==null?n.vertices=a.prev=a.next=a:(a.prev=n.vertices,a.next=n.vertices.next,n.vertices.next.prev=a,n.vertices.next=a),n.vertices=a,n.vertices.forced=s.forced,s.diagonals.head!=null){let p=s.diagonals,c=p.head.elt;if(p.pop(),c==e)break;s=this.pull_partitions(s,t);}else s=s.next;if(s==e)break}let i=0,l=n.vertices,r=n.vertices;if(l!=null){let o=l;for(;;){let a=o;if(i+=a.x*(a.next.y-a.prev.y),o=o.next,o==r)break}}return i*.5!=0&&t.add(n),s}extract(e){if(e==null&&(e=new Gn),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let s=t;for(;s.sort(),s=s.next,s!=n;);}for(this.pull(this.vertices,e);this.vertices!=null;){let s;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let i=this.vertices;i.helper=null,i.next=Ge.zpp_pool,Ge.zpp_pool=i,s=this.vertices=null;}else {let i=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let l=this.vertices;l.helper=null,l.next=Ge.zpp_pool,Ge.zpp_pool=l,this.vertices=null,s=i;}this.vertices=s;}}return e}pull(e,t){let n=null,s=e;for(;;){let a=s.x,p=s.y,c;Pe.zpp_pool==null?c=new Pe:(c=Pe.zpp_pool,Pe.zpp_pool=c.next,c.next=null),c.forced=false,c.x=a,c.y=p;let h=c;if(n==null?h.prev=h.next=h:(h.prev=n,h.next=n.next,n.next.prev=h,n.next=h),n=h,n.forced=s.forced,s.diagonals.head!=null){let u=s.diagonals,x=u.head.elt;if(u.pop(),x==e)break;s=this.pull(s,t);}else s=s.next;if(s==e)break}let i=0,l=n,r=n;if(l!=null){let a=l;for(;;){let p=a;if(i+=p.x*(p.next.y-p.prev.y),a=a.next,a==r)break}}let o=i*.5;if(o*o>=_e().Config.epsilon*_e().Config.epsilon){let a=n,p=true;for(;p||a!=n;){p=false;let c=a.x-a.next.x,h=a.y-a.next.y;if(c*c+h*h<_e().Config.epsilon*_e().Config.epsilon){if(a==n&&(n=a.next,p=true),a.forced&&(a.next.forced=true),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else {let u=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=u;}if(a==null){n=null;break}}else a=a.next;}if(n!=null){let c;for(;;){for(c=false,a=n,p=true;p||a!=n;){p=false;let h=a.prev,u=a.x-h.x,x=a.y-h.y,m=a.next.x-a.x,y=(a.next.y-a.y)*u-m*x;if(y*y>=_e().Config.epsilon*_e().Config.epsilon)a=a.next;else {if(a==n&&(n=a.next,p=true),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else {let z=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=z;}if(c=true,a==null){c=false,n=null;break}}}if(!c)break}}n!=null&&t.add(n);}return s}};un.zpp_pool=null,un.sharedPPList=null,un.sharedGVList=null;var Je=un;var De=class De{static bisector(e){let t=e.prev,n=e.next,s=e.x-t.x,i=e.y-t.y,l=n.x-e.x,r=n.y-e.y,o;ae.zpp_pool==null?o=new ae:(o=ae.zpp_pool,ae.zpp_pool=o.next,o.next=null),o.weak=false,o._immutable=false,o.x=-i-r,o.y=s+l;let a=o,p=a.x*a.x+a.y*a.y,h=1/Math.sqrt(p);return a.x*=h,a.y*=h,r*s-l*i<0&&(a.x=-a.x,a.y=-a.y),a}static below(e,t){if(e.y<t.y)return true;if(e.y>t.y)return false;if(e.x<t.x)return true;if(e.x>t.x)return false;{let n=De.bisector(e),s=De.bisector(t),i=1;n.x+=e.x*i,n.y+=e.y*i;let l=1;s.x+=t.x*l,s.y+=t.y*l;let r=n.x<s.x||n.x==s.x&&n.y<s.y;return n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=ae.zpp_pool,ae.zpp_pool=n,s.outer!=null&&(s.outer.zpp_inner=null,s.outer=null),s._isimmutable=null,s._validate=null,s._invalidate=null,s.next=ae.zpp_pool,ae.zpp_pool=s,r}}static above(e,t){return De.below(t,e)}static left_vertex(e){let t=e.prev;return t.y>e.y?true:t.y==e.y?e.next.y<e.y:false}static isMonotone(e){let t=e,n=e,s=e.next,i=e;if(s!=null){let o=s;for(;;){let a=o;if(a.y<t.y&&(t=a),a.y>n.y&&(n=a),o=o.next,o==i)break}}let l=true,r=t;if(n!=t.next){let o=t.next,a=n;if(o!=null){let p=o;for(;;){let c=p;if(c.y<r.y){l=false;break}if(r=c,p=p.next,p==a)break}}}if(!l)return false;if(r=t,n!=t.prev){let o=t.prev,a=n;if(o!=null){let p=o;for(;;){let c=p;if(c.y<r.y){l=false;break}if(r=c,p=p.prev,p==a)break}}}return l}static getShared(){return De.sharedPPoly==null&&(De.sharedPPoly=new Je),De.sharedPPoly}static decompose(e,t){if(t==null?t=new Je(e):t.init(e),t.vertices==null)return t;De.queue==null&&(De.queue=new ui);let n=t.vertices,s=t.vertices;if(n!=null){let l=n;for(;;){let r=l;De.queue.add(r);let o=r.next.x-r.x,a=r.next.y-r.y,p=r.prev.x-r.x,h=(r.prev.y-r.y)*o-p*a>0;if(r.type=De.below(r.prev,r)?De.below(r.next,r)?h?0:3:4:De.below(r,r.next)?h?1:2:4,l=l.next,l==s)break}}let i=De.queue;if(i.head!=null&&i.head.next!=null){let l=i.head,r,o,a,p,c=1,h,u,x;for(;;){for(h=0,o=l,l=null,r=l;o!=null;){for(++h,a=o,u=0,x=c;a!=null&&u<c;)++u,a=a.next;for(;u>0||x>0&&a!=null;)u==0?(p=a,a=a.next,--x):x==0||a==null||De.above(o.elt,a.elt)?(p=o,o=o.next,--u):(p=a,a=a.next,--x),r!=null?r.next=p:l=p,r=p;o=a;}if(r.next=null,c<<=1,!(h>1))break}i.head=l,i.modified=true,i.pushmod=true;}for(De.edges==null&&(Qi.zpp_pool==null?De.edges=new Qi:(De.edges=Qi.zpp_pool,Qi.zpp_pool=De.edges.next,De.edges.next=null),De.edges.lt=Ge.edge_lt,De.edges.swapped=Ge.edge_swap);De.queue.head!=null;){let l=De.queue.pop_unsafe();switch(l.type){case 0:l.helper=l,l.node=De.edges.insert(l);break;case 1:{let r=l.prev;if(r.helper==null)throw new Error("Fatal error (1): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),De.edges.remove_node(r.node),r.helper=null;break}case 2:{let r=l.prev;if(r.helper==null)throw new Error("Fatal error (3): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),De.edges.remove_node(r.node),r.helper=null;let o=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){o=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else {for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent;}}}let a=o;if(a!=null){if(a.helper==null)throw new Error("Fatal error (4): Polygon is not weakly-simple and clockwise");a.helper.type==2&&t.add_diagonal(l,a.helper),a.helper=l;}break}case 3:{let r=null;if(!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,l)){r=p;break}if(a.next!=null)for(a=a.next;a.prev!=null;)a=a.prev;else {for(;a.parent!=null&&a==a.parent.next;)a=a.parent;a=a.parent;}}}let o=r;if(o!=null){if(o.helper==null)throw new Error("Fatal error (2): Polygon is not weakly-simple and clockwise");t.add_diagonal(l,o.helper),o.helper=l;}l.node=De.edges.insert(l),l.helper=l;break}case 4:{let r=l.prev;if(De.left_vertex(l)){if(r.helper==null)throw new Error("Fatal error (5): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),De.edges.remove_node(r.node),r.helper=null,l.node=De.edges.insert(l),l.helper=l;}else {let o=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){o=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else {for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent;}}}let a=o;if(a==null||a.helper==null)throw new Error("Fatal error (6): Polygon is not weakly-simple and clockwise");a.helper.type==2&&t.add_diagonal(l,a.helper),a.helper=l;}break}}}return t}};De.queue=null,De.edges=null,De.sharedPPoly=null;var Dt=De;var Bi=class Bi{constructor(){this.node=null;this.di=0;this.id=0;this.b=null;this.a=null;this.length=0;this.pushmod=false;this.modified=false;this._inuse=false;this.next=null;}static get(e,t){let n;return Bi.zpp_pool==null?n=new Bi:(n=Bi.zpp_pool,Bi.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:false:true}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=true,this.pushmod=true;}add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,this.length++,e}inlined_add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,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=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}inlined_insert(e,t){t._inuse=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){this.erase(t),s=true;break}t=n,n=n.next;}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}inlined_try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=true)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=true)),i._inuse=false,this.modified=true,this.length--,this.pushmod=true,s=true;break}t=n,n=n.next;}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,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=true,this.pushmod=true;}empty(){return this.next==null}size(){return this.length}has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;break}n=n.next;}return t}inlined_has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;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(){}};Bi.zpp_pool=null;var St=Bi;var At=class At{constructor(){this.zip_dir=false;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=_e(),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=false,t==xe.nextVec2&&(xe.nextVec2=null)),t.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.zpp_pool=s.next,s.next=null),s.weak=false,s._immutable=false,s.x=0,s.y=0,t.zpp_inner=s,t.zpp_inner.outer=t;}else {if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=t.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=t.zpp_inner;if(l._validate!=null&&l._validate(),t.zpp_inner.x==0){if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=t.zpp_inner;r._validate!=null&&r._validate(),i=t.zpp_inner.y==0;}else i=false;if(!i){t.zpp_inner.x=0,t.zpp_inner.y=0;let r=t.zpp_inner;r._invalidate!=null&&r._invalidate(r);}}t.zpp_inner.weak=false,this.origin=t,this.origin.zpp_inner._invalidate=s=>this.origin_invalidate(s);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=false,n==xe.nextVec2&&(xe.nextVec2=null)),n.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.zpp_pool=s.next,s.next=null),s.weak=false,s._immutable=false,s.x=0,s.y=0,n.zpp_inner=s,n.zpp_inner.outer=n;}else {if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y==0;}else i=false;if(!i){n.zpp_inner.x=0,n.zpp_inner.y=0;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r);}}n.zpp_inner.weak=false,this.direction=n,this.direction.zpp_inner._invalidate=s=>this.direction_invalidate(s),this.originx=0,this.originy=0,this.dirx=0,this.diry=0,this.zip_dir=false;}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=true;}invalidate_dir(){this.zip_dir=true;}validate_dir(){if(this.zip_dir){this.zip_dir=false;let e=_e();if(this.dirx*this.dirx+this.diry*this.diry<e.Config.epsilon)throw new Error("Error: Ray::direction is degenerate");let t=this.dirx*this.dirx+this.diry*this.diry,n=1/Math.sqrt(t);this.dirx*=n,this.diry*=n,this.idirx=1/this.dirx,this.idiry=1/this.diry,this.normalx=-this.diry,this.normaly=this.dirx;let s=this.normalx;this.absnormalx=s<0?-s:s;let i=this.normaly;this.absnormaly=i<0?-i:i;}}rayAABB(){let e=this.originx,t=e,n=this.originy,s=n;if(this.maxdist>=1/0?(this.dirx>0?t=1/0:this.dirx<0&&(t=-1/0),this.diry>0?s=1/0:this.diry<0&&(s=-1/0)):(t+=this.maxdist*this.dirx,s+=this.maxdist*this.diry),t<e){let l=e;e=t,t=l;}if(s<n){let l=n;n=s,s=l;}let i;return be.zpp_pool==null?i=new be:(i=be.zpp_pool,be.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=n,i.maxx=t,i.maxy=s,i}aabbtest(e){let t=this.normalx*(this.originx-.5*(e.minx+e.maxx))+this.normaly*(this.originy-.5*(e.miny+e.maxy)),n=this.absnormalx*.5*(e.maxx-e.minx)+this.absnormaly*.5*(e.maxy-e.miny),s=t;return (s<0?-s:s)<n}aabbsect(e){let t=this.originx>=e.minx&&this.originx<=e.maxx,n=this.originy>=e.miny&&this.originy<=e.maxy;if(t&&n)return 0;{let s=-1;for(;!(this.dirx>=0&&this.originx>=e.maxx)&&!(this.dirx<=0&&this.originx<=e.minx||this.diry>=0&&this.originy>=e.maxy||this.diry<=0&&this.originy<=e.miny);){if(this.dirx>0){let i=(e.minx-this.originx)*this.idirx;if(i>=0&&i<=this.maxdist){let l=this.originy+i*this.diry;if(l>=e.miny&&l<=e.maxy){s=i;break}}}else if(this.dirx<0){let i=(e.maxx-this.originx)*this.idirx;if(i>=0&&i<=this.maxdist){let l=this.originy+i*this.diry;if(l>=e.miny&&l<=e.maxy){s=i;break}}}if(this.diry>0){let i=(e.miny-this.originy)*this.idiry;if(i>=0&&i<=this.maxdist){let l=this.originx+i*this.dirx;if(l>=e.minx&&l<=e.maxx){s=i;break}}}else if(this.diry<0){let i=(e.maxy-this.originy)*this.idiry;if(i>=0&&i<=this.maxdist){let l=this.originx+i*this.dirx;if(l>=e.minx&&l<=e.maxx){s=i;break}}}break}return s}}static _allocVec2(e,t){let n=_e();if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let s;if(xe.poolVec2==null?s=new n.geom.Vec2:(s=xe.poolVec2,xe.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=false,s==xe.nextVec2&&(xe.nextVec2=null)),s.zpp_inner==null){let i;ae.zpp_pool==null?i=new ae:(i=ae.zpp_pool,ae.zpp_pool=i.next,i.next=null),i.weak=false,i._immutable=false,i.x=e,i.y=t,s.zpp_inner=i,s.zpp_inner.outer=s;}else {if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;s.zpp_inner._validate!=null&&s.zpp_inner._validate(),s.zpp_inner.x==e?(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l=s.zpp_inner.y==t):l=false,l||(s.zpp_inner.x=e,s.zpp_inner.y=t,s.zpp_inner._invalidate!=null&&s.zpp_inner._invalidate(s.zpp_inner));}return s.zpp_inner.weak=false,s}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=false,e.zip_localCOM){if(e.zip_localCOM=false,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let s=1;n.localCOMx+=n.lverts.next.next.x*s,n.localCOMy+=n.lverts.next.next.y*s;let i=.5;n.localCOMx*=i,n.localCOMy*=i;}else {n.localCOMx=0,n.localCOMy=0;let s=0,i=n.lverts.next,l=i;i=i.next;let r=i;for(i=i.next;i!=null;){let u=i;s+=r.x*(u.y-l.y);let x=u.y*r.x-u.x*r.y;n.localCOMx+=(r.x+u.x)*x,n.localCOMy+=(r.y+u.y)*x,l=r,r=u,i=i.next;}i=n.lverts.next;let o=i;s+=r.x*(o.y-l.y);let a=o.y*r.x-o.x*r.y;n.localCOMx+=(r.x+o.x)*a,n.localCOMy+=(r.y+o.y)*a,l=r,r=o,i=i.next;let p=i;s+=r.x*(p.y-l.y);let c=p.y*r.x-p.x*r.y;n.localCOMx+=(r.x+p.x)*c,n.localCOMy+=(r.y+p.y)*c,s=1/(3*s);let h=s;n.localCOMx*=h,n.localCOMy*=h;}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy);}let t=e.body;t.zip_axis&&(t.zip_axis=false,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy);}}_circleNormal(e,t,n){let s=this.originx+this.dirx*e,i=this.originy+this.diry*e;s-=t.worldCOMx,i-=t.worldCOMy;let l=s*s+i*i,r=1/Math.sqrt(l);return s*=r,i*=r,n&&(s=-s,i=-i),{nx:s,ny:i}}static _insertSorted(e,t){let n=null,s=e.zpp_inner.inner.head;for(;s!=null;){let r=s.elt;if(t.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(t.zpp_inner.toiDistance<r.zpp_inner.toiDistance)break;n=s,s=s.next;}let i=e.zpp_inner.inner,l;Hi.zpp_pool==null?l=new Hi:(l=Hi.zpp_pool,Hi.zpp_pool=l.next,l.next=null),l.elt=t,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=true,i.length++;}circlesect(e,t,n){At._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,r=2*(s*this.dirx+i*this.diry),o=s*s+i*i-e.radius*e.radius,a=r*r-4*l*o;if(a==0){let p=-r/2*l;if((!t||o>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,o<=0),h=At._allocVec2(c.nx,c.ny);return bn.getRay(h,p,o<=0,e.outer)}else return null}else {a=Math.sqrt(a),l=1/(2*l);let p=(-r-a)*l,c=(-r+a)*l;if(p>0)if(p<n&&p<=this.maxdist){let h=this._circleNormal(p,e,false),u=At._allocVec2(h.nx,h.ny);return bn.getRay(u,p,false,e.outer)}else return null;else if(c>0&&t)if(c<n&&c<=this.maxdist){let h=this._circleNormal(c,e,true),u=At._allocVec2(h.nx,h.ny);return bn.getRay(u,c,true,e.outer)}else return null;else return null}}circlesect2(e,t,n){At._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,r=2*(s*this.dirx+i*this.diry),o=s*s+i*i-e.radius*e.radius,a=r*r-4*l*o;if(a==0){let p=-r/2*l;if((!t||o>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,o<=0),h=At._allocVec2(c.nx,c.ny),u=bn.getRay(h,p,o<=0,e.outer);At._insertSorted(n,u);}}else {a=Math.sqrt(a),l=1/(2*l);let p=(-r-a)*l,c=(-r+a)*l;if(p>0&&p<=this.maxdist){let h=this._circleNormal(p,e,false),u=At._allocVec2(h.nx,h.ny),x=bn.getRay(u,p,false,e.outer);At._insertSorted(n,x);}if(c>0&&c<=this.maxdist&&t){let h=this._circleNormal(c,e,true),u=At._allocVec2(h.nx,h.ny),x=bn.getRay(u,c,true,e.outer);At._insertSorted(n,x);}}}polysect(e,t,n){let s=_e(),i=n,l=null,r=e.edges.head,a=e.gverts.next,p=a,c=a.next;for(;c!=null;){let h=c,u=r.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,m=h.y-p.y,_=p.x-this.originx,y=p.y-this.originy,z=m*this.dirx-x*this.diry;if(z*z>s.Config.epsilon){z=1/z;let b=(m*_-x*y)*z;if(b>0&&b<i&&b<=this.maxdist){let w=(this.diry*_-this.dirx*y)*z;w>-s.Config.epsilon&&w<1+s.Config.epsilon&&(i=b,l=r.elt);}}}r=r.next,p=h,c=c.next;}{c=e.gverts.next;let h=c,u=r.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,m=h.y-p.y,_=p.x-this.originx,y=p.y-this.originy,z=m*this.dirx-x*this.diry;if(z*z>s.Config.epsilon){z=1/z;let b=(m*_-x*y)*z;if(b>0&&b<i&&b<=this.maxdist){let w=(this.diry*_-this.dirx*y)*z;w>-s.Config.epsilon&&w<1+s.Config.epsilon&&(i=b,l=r.elt);}}}}if(l!=null){let h=l.gnormx,u=l.gnormy,x=h*this.dirx+u*this.diry>0;x&&(h=-h,u=-u);let m=At._allocVec2(h,u);return bn.getRay(m,i,x,e.outer)}else return null}polysect2(e,t,n){let s=_e(),i=1/0,l=-1,r=null,o=null,a=e.edges.head,c=e.gverts.next,h=c,u=c.next;for(;u!=null;){let x=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let _=x.x-h.x,y=x.y-h.y,z=h.x-this.originx,b=h.y-this.originy,w=y*this.dirx-_*this.diry;if(w*w>s.Config.epsilon){w=1/w;let Z=(y*z-_*b)*w;if(Z>0&&Z<=this.maxdist&&(Z<i||Z>l)){let d=(this.diry*z-this.dirx*b)*w;d>-s.Config.epsilon&&d<1+s.Config.epsilon&&(Z<i&&(i=Z,r=a.elt),Z>l&&(l=Z,o=a.elt));}}}a=a.next,h=x,u=u.next;}{u=e.gverts.next;let x=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let _=x.x-h.x,y=x.y-h.y,z=h.x-this.originx,b=h.y-this.originy,w=y*this.dirx-_*this.diry;if(w*w>s.Config.epsilon){w=1/w;let Z=(y*z-_*b)*w;if(Z>0&&Z<=this.maxdist&&(Z<i||Z>l)){let d=(this.diry*z-this.dirx*b)*w;d>-s.Config.epsilon&&d<1+s.Config.epsilon&&(Z<i&&(i=Z,r=a.elt),Z>l&&(l=Z,o=a.elt));}}}}if(r!=null){let x=r.gnormx,m=r.gnormy,_=x*this.dirx+m*this.diry>0;_&&(x=-x,m=-m);let y=At._allocVec2(x,m),z=bn.getRay(y,i,_,e.outer);At._insertSorted(n,z);}if(o!=null&&r!=o){let x=o.gnormx,m=o.gnormy,_=x*this.dirx+m*this.diry>0;_&&(x=-x,m=-m);let y=At._allocVec2(x,m),z=bn.getRay(y,l,_,e.outer);At._insertSorted(n,z);}}};At.internal=false;var Qs=At;var zi=class zi{constructor(){this.forced=false;this.x=0;this.y=0;this.links=null;this.id=0;this.next=null;this.node=null;this.id=yn.ZPP_SimpleVert(),en.zpp_pool==null?this.links=new en:(this.links=en.zpp_pool,en.zpp_pool=this.links.next,this.links.next=null),this.links.lt=zi.less_xy;}static less_xy(e,t){return e.y<t.y?true:e.y==t.y?e.x<t.x:false}static swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n;}static get(e,t){let n;return zi.zpp_pool==null?n=new zi:(n=zi.zpp_pool,zi.zpp_pool=n.next,n.next=null),n.x=e,n.y=t,n}free(){this.links.clear(),this.node=null,this.forced=false;}alloc(){}};zi.zpp_pool=null;var Ee=zi;var Ti=class Ti{constructor(){this.left=null;this.right=null;this.vertices=null;this.id=0;this.next=null;this.prev=null;this.node=null;this.id=yn.ZPP_SimpleSeg(),en.zpp_pool==null?this.vertices=new en:(this.vertices=en.zpp_pool,en.zpp_pool=this.vertices.next,this.vertices.next=null),this.vertices.lt=(e,t)=>this.less_xy(e,t);}static get(e,t){let n;return Ti.zpp_pool==null?n=new Ti:(n=Ti.zpp_pool,Ti.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?true:e.x==t.x?e.y<t.y:false}};Ti.zpp_pool=null;var Vt=Ti;var Li=class Li{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?true:e.vertex.x>t.vertex.x?false:e.vertex.y<t.vertex.y?true:e.vertex.y>t.vertex.y?false:e.type<t.type}static get(e){let t;return Li.zpp_pool==null?t=new Li:(t=Li.zpp_pool,Li.zpp_pool=t.next,t.next=null),t.vertex=e,t}free(){this.vertex=null,this.segment=this.segment2=null,this.node=null;}alloc(){}};Li.zpp_pool=null;var Ce=Li;var Di=class{constructor(){this.sweepx=0;this.tree=null;Xi.zpp_pool==null?this.tree=new Xi:(this.tree=Xi.zpp_pool,Xi.zpp_pool=this.tree.next,this.tree.next=null),this.tree.lt=(e,t)=>this.edge_lt(e,t),this.tree.swapped=(e,t)=>this.swap_nodes(e,t);}swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n;}edge_lt(e,t){let n=e.left,s=e.right,i=t.left,l=t.right,r,o,a,p,c;if(e.left==t.left&&e.right==t.right)return false;if(e.left==t.right)return n.x==s.x?n.y<s.y?n.y>i.y:s.y>i.y:(c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?o*a-r*p:p*r-a*o)<0);if(e.right==t.left){let h;return i.x==l.x?h=i.y<l.y?i.y>n.y:l.y>n.y:(c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=n.x-i.x,p=n.y-i.y,h=(c?o*a-r*p:p*r-a*o)<0),!h}else {if(e.left==t.left)return n.x==s.x?n.y<s.y?n.y>l.y:s.y>l.y:(c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=l.x-n.x,p=l.y-n.y,(c?o*a-r*p:p*r-a*o)<0);if(e.right==t.right)return n.x==s.x?n.y<s.y?n.y>i.y:s.y>i.y:(c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?o*a-r*p:p*r-a*o)<0)}if(n.x==s.x)if(i.x==l.x){let h=n.y<s.y?s:n,u=i.y<l.y?l:i;return h.y>u.y}else {c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let h=c?o*a-r*p:p*r-a*o;c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let u=c?o*a-r*p:p*r-a*o;return h*u>=0?h>=0:this.sweepx>=n.x}else if(i.x==l.x){c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=c?o*a-r*p:p*r-a*o;c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=c?o*a-r*p:p*r-a*o;return h*u>=0?h<0:this.sweepx<i.x}else {c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=(c?o*a-r*p:p*r-a*o)<0;c=s.x<n.x,r=s.x-n.x,o=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=(c?o*a-r*p:p*r-a*o)<0;if(h==u)return h;{c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let x=(c?o*a-r*p:p*r-a*o)>=0;c=l.x<i.x,r=l.x-i.x,o=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let m=(c?o*a-r*p:p*r-a*o)>=0;if(x==m)return x;let _=(this.sweepx-n.x)/(s.x-n.x)*(s.y-n.y)+n.y,y=(this.sweepx-i.x)/(l.x-i.x)*(l.y-i.y)+i.y;return _>y}}}clear(){this.tree.clear();}add(e){e.node=this.tree.insert(e);let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);return t!=null&&(e.next=t.data,t.data.prev=e),n!=null&&(e.prev=n.data,n.data.next=e),e}remove(e){let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);t!=null&&(t.data.prev=e.prev),n!=null&&(n.data.next=e.next),this.tree.remove_node(e.node),e.node=null;}intersect(e,t){if(e==null||t==null)return false;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return false;{let n=e.left,s=e.right,i=t.left,l=t.right,r=(i.x-n.x)*(s.y-n.y)-(s.x-n.x)*(i.y-n.y),o=(l.x-n.x)*(s.y-n.y)-(s.x-n.x)*(l.y-n.y);if(r*o>0)return false;{let a=(n.x-i.x)*(l.y-i.y)-(l.x-i.x)*(n.y-i.y),p=(s.x-i.x)*(l.y-i.y)-(l.x-i.x)*(s.y-i.y);return !(a*p>0)}}}intersection(e,t){if(e==null||t==null)return null;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return null;{let n=e.left,s=e.right,i=t.left,l=t.right,r=s.x-n.x,o=s.y-n.y,a=l.x-i.x,p=l.y-i.y,c=p*r-a*o;if(c==0)return null;c=1/c;let h=i.x-n.x,u=i.y-n.y,x=(p*h-a*u)*c;if(x<0||x>1)return null;let m=(o*h-r*u)*c;if(m<0||m>1)return null;let _;if(m==0||m==1||x==0||x==1){let b=m==0;if(m==1&&b)throw new Error("corner case 1a");if(m==1&&(b=true),x==0&&b)throw new Error("corner case 1b");if(x==0&&(b=true),x==1&&b)throw new Error("corner case 1c");_=m==0?i:m==1?l:x==0?n:s;}else {let b=.5*(n.x+r*x+i.x+a*m),w=.5*(n.y+o*x+i.y+p*m),Z;Ee.zpp_pool==null?Z=new Ee:(Z=Ee.zpp_pool,Ee.zpp_pool=Z.next,Z.next=null),Z.x=b,Z.y=w,_=Z;}let y;Ce.zpp_pool==null?y=new Ce:(y=Ce.zpp_pool,Ce.zpp_pool=y.next,y.next=null),y.vertex=_;let z=y;return z.type=0,z.segment=e,z.segment2=t,z}}};var ye=class ye{static decompose(e,t){ye.sweep==null&&(ye.sweep=new Di,ye.inthash=new Ni),ye.vertices==null&&(en.zpp_pool==null?ye.vertices=new en:(ye.vertices=en.zpp_pool,en.zpp_pool=ye.vertices.next,ye.vertices.next=null),ye.vertices.lt=Ee.less_xy,ye.vertices.swapped=Ee.swap_nodes),ye.queue==null&&(Kn.zpp_pool==null?ye.queue=new Kn:(ye.queue=Kn.zpp_pool,Kn.zpp_pool=ye.queue.next,ye.queue.next=null),ye.queue.lt=Ce.less_xy,ye.queue.swapped=Ce.swap_nodes);let n=null,s=null,i=e,l=e;if(i!=null){let x=i;for(;;){let m=x,_=m.x,y=m.y,z;Ee.zpp_pool==null?z=new Ee:(z=Ee.zpp_pool,Ee.zpp_pool=z.next,z.next=null),z.x=_,z.y=y;let b=z,w=ye.vertices.parent;for(;w!=null;)if(ye.vertices.lt(b,w.data))w=w.prev;else if(ye.vertices.lt(w.data,b))w=w.next;else break;let Z=w;if(Z!=null){let d=b;d.links.clear(),d.node=null,d.forced=false,d.next=Ee.zpp_pool,Ee.zpp_pool=d,b=Z.data;}else b.node=ye.vertices.insert(b);if(s!=null){let d;Ce.zpp_pool==null?d=new Ce:(d=Ce.zpp_pool,Ce.zpp_pool=d.next,d.next=null),d.vertex=s;let f=d,g;Ce.zpp_pool==null?g=new Ce:(g=Ce.zpp_pool,Ce.zpp_pool=g.next,g.next=null),g.vertex=b;let P=g,v;Ce.less_xy(f,P)?(f.type=1,P.type=2,v=Vt.get(s,b)):(f.type=2,P.type=1,v=Vt.get(b,s)),f.segment=P.segment=v,ye.queue.insert(f),ye.queue.insert(P),s.links.insert(b),b.links.insert(s);}if(s=b,n==null&&(n=b),x=x.next,x==l)break}}let r;Ce.zpp_pool==null?r=new Ce:(r=Ce.zpp_pool,Ce.zpp_pool=r.next,r.next=null),r.vertex=s;let o=r,a;Ce.zpp_pool==null?a=new Ce:(a=Ce.zpp_pool,Ce.zpp_pool=a.next,a.next=null),a.vertex=n;let p=a,c;for(Ce.less_xy(o,p)?(o.type=1,p.type=2,c=Vt.get(s,n)):(o.type=2,p.type=1,c=Vt.get(n,s)),o.segment=p.segment=c,ye.queue.insert(o),ye.queue.insert(p),s.links.insert(n),n.links.insert(s),ye.ints==null&&(Kn.zpp_pool==null?ye.ints=new Kn:(ye.ints=Kn.zpp_pool,Kn.zpp_pool=ye.ints.next,ye.ints.next=null),ye.ints.lt=Ce.less_xy);!ye.queue.empty();){let x=ye.queue.pop_front();if(ye.sweep.sweepx=x.vertex.x,x.type==1){let _=x.segment;if(ye.sweep.add(_),_.next!=null&&_!=null&&!(_.next.id<_.id?ye.inthash.has(_.next.id,_.id):ye.inthash.has(_.id,_.next.id))){let y=ye.sweep.intersection(_.next,_);if(y!=null)if(y.vertex.x>=ye.sweep.sweepx){let z=ye.queue.parent;for(;z!=null;)if(ye.queue.lt(y,z.data))z=z.prev;else if(ye.queue.lt(z.data,y))z=z.next;else break;let b=z;if(b==null){let w=ye.ints.parent;for(;w!=null;)if(ye.ints.lt(y,w.data))w=w.prev;else if(ye.ints.lt(w.data,y))w=w.next;else break;let Z=w;if(Z!=null){let d=y.vertex;d.links.clear(),d.node=null,d.forced=false,d.next=Ee.zpp_pool,Ee.zpp_pool=d,y.vertex=Z.data.vertex,Z.data=y,ye.queue.insert(y);}else ye.queue.insert(y),ye.ints.insert(y);if(_.next.id<_.id){let d=ye.inthash,f=_.next.id,g=_.id,P;Be.zpp_pool==null?P=new Be:(P=Be.zpp_pool,Be.zpp_pool=P.next,P.next=null),P.id=f,P.di=g;let v=P;v.value=true,d.add(v);}else {let d=ye.inthash,f=_.id,g=_.next.id,P;Be.zpp_pool==null?P=new Be:(P=Be.zpp_pool,Be.zpp_pool=P.next,P.next=null),P.id=f,P.di=g;let v=P;v.value=true,d.add(v);}}else {let w=b.data;if(w.segment!=y.segment||y.segment2!=w.segment2)throw new Error("corner case 2, shiiiit.");let Z=y.vertex;Z.links.clear(),Z.node=null,Z.forced=false,Z.next=Ee.zpp_pool,Ee.zpp_pool=Z;let d=y;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Ce.zpp_pool,Ce.zpp_pool=d;}}else {let z=y.vertex;z.links.clear(),z.node=null,z.forced=false,z.next=Ee.zpp_pool,Ee.zpp_pool=z;let b=y;b.vertex=null,b.segment=b.segment2=null,b.node=null,b.next=Ce.zpp_pool,Ce.zpp_pool=b;}}if(_!=null&&_.prev!=null&&!(_.id<_.prev.id?ye.inthash.has(_.id,_.prev.id):ye.inthash.has(_.prev.id,_.id))){let y=ye.sweep.intersection(_,_.prev);if(y!=null)if(y.vertex.x>=ye.sweep.sweepx){let z=ye.queue.parent;for(;z!=null;)if(ye.queue.lt(y,z.data))z=z.prev;else if(ye.queue.lt(z.data,y))z=z.next;else break;let b=z;if(b==null){let w=ye.ints.parent;for(;w!=null;)if(ye.ints.lt(y,w.data))w=w.prev;else if(ye.ints.lt(w.data,y))w=w.next;else break;let Z=w;if(Z!=null){let d=y.vertex;d.links.clear(),d.node=null,d.forced=false,d.next=Ee.zpp_pool,Ee.zpp_pool=d,y.vertex=Z.data.vertex,Z.data=y,ye.queue.insert(y);}else ye.queue.insert(y),ye.ints.insert(y);if(_.id<_.prev.id){let d=ye.inthash,f=_.id,g=_.prev.id,P;Be.zpp_pool==null?P=new Be:(P=Be.zpp_pool,Be.zpp_pool=P.next,P.next=null),P.id=f,P.di=g;let v=P;v.value=true,d.add(v);}else {let d=ye.inthash,f=_.prev.id,g=_.id,P;Be.zpp_pool==null?P=new Be:(P=Be.zpp_pool,Be.zpp_pool=P.next,P.next=null),P.id=f,P.di=g;let v=P;v.value=true,d.add(v);}}else {let w=b.data;if(w.segment!=y.segment||y.segment2!=w.segment2)throw new Error("corner case 2, shiiiit.");let Z=y.vertex;Z.links.clear(),Z.node=null,Z.forced=false,Z.next=Ee.zpp_pool,Ee.zpp_pool=Z;let d=y;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Ce.zpp_pool,Ce.zpp_pool=d;}}else {let z=y.vertex;z.links.clear(),z.node=null,z.forced=false,z.next=Ee.zpp_pool,Ee.zpp_pool=z;let b=y;b.vertex=null,b.segment=b.segment2=null,b.node=null,b.next=Ce.zpp_pool,Ce.zpp_pool=b;}}}else if(x.type==2){let _=x.segment;if(_.node!=null){let y=_.next,z=_.prev;ye.sweep.remove(_);let b=_;if(b.left=b.right=null,b.prev=null,b.node=null,b.vertices.clear(),b.next=Vt.zpp_pool,Vt.zpp_pool=b,y!=null&&z!=null&&!(y.id<z.id?ye.inthash.has(y.id,z.id):ye.inthash.has(z.id,y.id))){let w=ye.sweep.intersection(y,z);if(w!=null)if(w.vertex.x>=ye.sweep.sweepx){let Z=ye.queue.parent;for(;Z!=null;)if(ye.queue.lt(w,Z.data))Z=Z.prev;else if(ye.queue.lt(Z.data,w))Z=Z.next;else break;let d=Z;if(d==null){let f=ye.ints.parent;for(;f!=null;)if(ye.ints.lt(w,f.data))f=f.prev;else if(ye.ints.lt(f.data,w))f=f.next;else break;let g=f;if(g!=null){let P=w.vertex;P.links.clear(),P.node=null,P.forced=false,P.next=Ee.zpp_pool,Ee.zpp_pool=P,w.vertex=g.data.vertex,g.data=w,ye.queue.insert(w);}else ye.queue.insert(w),ye.ints.insert(w);if(y.id<z.id){let P=ye.inthash,v=y.id,N=z.id,E;Be.zpp_pool==null?E=new Be:(E=Be.zpp_pool,Be.zpp_pool=E.next,E.next=null),E.id=v,E.di=N;let M=E;M.value=true,P.add(M);}else {let P=ye.inthash,v=z.id,N=y.id,E;Be.zpp_pool==null?E=new Be:(E=Be.zpp_pool,Be.zpp_pool=E.next,E.next=null),E.id=v,E.di=N;let M=E;M.value=true,P.add(M);}}else {let f=d.data;if(f.segment!=w.segment||w.segment2!=f.segment2)throw new Error("corner case 2, shiiiit.");let g=w.vertex;g.links.clear(),g.node=null,g.forced=false,g.next=Ee.zpp_pool,Ee.zpp_pool=g;let P=w;P.vertex=null,P.segment=P.segment2=null,P.node=null,P.next=Ce.zpp_pool,Ce.zpp_pool=P;}}else {let Z=w.vertex;Z.links.clear(),Z.node=null,Z.forced=false,Z.next=Ee.zpp_pool,Ee.zpp_pool=Z;let d=w;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Ce.zpp_pool,Ce.zpp_pool=d;}}}}else {let _=x.vertex,y=_.node==null,z=x.segment,b=x.segment2;if(b.next!=z){let g=z;z=b,b=g;}let w=z.vertices.parent;for(;w!=null;)if(z.vertices.lt(_,w.data))w=w.prev;else if(z.vertices.lt(w.data,_))w=w.next;else break;let Z=w==null,d=b.vertices.parent;for(;d!=null;)if(b.vertices.lt(_,d.data))d=d.prev;else if(b.vertices.lt(d.data,_))d=d.next;else break;let f=d==null;if(Z){let g=z.vertices.insert(_),P=_==z.left?_:z.vertices.predecessor_node(g).data,v=_==z.right?_:z.vertices.successor_node(g).data;P.links.remove(v),_!=P&&P.links.insert(_),v.links.remove(P),_!=v&&v.links.insert(_),_!=P&&_.links.insert(P),_!=v&&_.links.insert(v);}if(f){let g=b.vertices.insert(_),P=_==b.left?_:b.vertices.predecessor_node(g).data,v=_==b.right?_:b.vertices.successor_node(g).data;P.links.remove(v),_!=P&&P.links.insert(_),v.links.remove(P),_!=v&&v.links.insert(_),_!=P&&_.links.insert(P),_!=v&&_.links.insert(v);}if(y&&(_.node=ye.vertices.insert(_)),_.forced=true,y){let g=z.node,P=b.node;g.data=b,P.data=z,z.node=P,b.node=g,b.next=z.next,z.next=b,z.prev=b.prev,b.prev=z,z.prev!=null&&(z.prev.next=z),b.next!=null&&(b.next.prev=b);}if(b.next!=null&&b!=null&&!(b.next.id<b.id?ye.inthash.has(b.next.id,b.id):ye.inthash.has(b.id,b.next.id))){let g=ye.sweep.intersection(b.next,b);if(g!=null)if(g.vertex.x>=ye.sweep.sweepx){let P=ye.queue.parent;for(;P!=null;)if(ye.queue.lt(g,P.data))P=P.prev;else if(ye.queue.lt(P.data,g))P=P.next;else break;let v=P;if(v==null){let N=ye.ints.parent;for(;N!=null;)if(ye.ints.lt(g,N.data))N=N.prev;else if(ye.ints.lt(N.data,g))N=N.next;else break;let E=N;if(E!=null){let M=g.vertex;M.links.clear(),M.node=null,M.forced=false,M.next=Ee.zpp_pool,Ee.zpp_pool=M,g.vertex=E.data.vertex,E.data=g,ye.queue.insert(g);}else ye.queue.insert(g),ye.ints.insert(g);if(b.next.id<b.id){let M=ye.inthash,k=b.next.id,C=b.id,S;Be.zpp_pool==null?S=new Be:(S=Be.zpp_pool,Be.zpp_pool=S.next,S.next=null),S.id=k,S.di=C;let O=S;O.value=true,M.add(O);}else {let M=ye.inthash,k=b.id,C=b.next.id,S;Be.zpp_pool==null?S=new Be:(S=Be.zpp_pool,Be.zpp_pool=S.next,S.next=null),S.id=k,S.di=C;let O=S;O.value=true,M.add(O);}}else {let N=v.data;if(N.segment!=g.segment||g.segment2!=N.segment2)throw new Error("corner case 2, shiiiit.");let E=g.vertex;E.links.clear(),E.node=null,E.forced=false,E.next=Ee.zpp_pool,Ee.zpp_pool=E;let M=g;M.vertex=null,M.segment=M.segment2=null,M.node=null,M.next=Ce.zpp_pool,Ce.zpp_pool=M;}}else {let P=g.vertex;P.links.clear(),P.node=null,P.forced=false,P.next=Ee.zpp_pool,Ee.zpp_pool=P;let v=g;v.vertex=null,v.segment=v.segment2=null,v.node=null,v.next=Ce.zpp_pool,Ce.zpp_pool=v;}}if(z!=null&&z.prev!=null&&!(z.id<z.prev.id?ye.inthash.has(z.id,z.prev.id):ye.inthash.has(z.prev.id,z.id))){let g=ye.sweep.intersection(z,z.prev);if(g!=null)if(g.vertex.x>=ye.sweep.sweepx){let P=ye.queue.parent;for(;P!=null;)if(ye.queue.lt(g,P.data))P=P.prev;else if(ye.queue.lt(P.data,g))P=P.next;else break;let v=P;if(v==null){let N=ye.ints.parent;for(;N!=null;)if(ye.ints.lt(g,N.data))N=N.prev;else if(ye.ints.lt(N.data,g))N=N.next;else break;let E=N;if(E!=null){let M=g.vertex;M.links.clear(),M.node=null,M.forced=false,M.next=Ee.zpp_pool,Ee.zpp_pool=M,g.vertex=E.data.vertex,E.data=g,ye.queue.insert(g);}else ye.queue.insert(g),ye.ints.insert(g);if(z.id<z.prev.id){let M=ye.inthash,k=z.id,C=z.prev.id,S;Be.zpp_pool==null?S=new Be:(S=Be.zpp_pool,Be.zpp_pool=S.next,S.next=null),S.id=k,S.di=C;let O=S;O.value=true,M.add(O);}else {let M=ye.inthash,k=z.prev.id,C=z.id,S;Be.zpp_pool==null?S=new Be:(S=Be.zpp_pool,Be.zpp_pool=S.next,S.next=null),S.id=k,S.di=C;let O=S;O.value=true,M.add(O);}}else {let N=v.data;if(N.segment!=g.segment||g.segment2!=N.segment2)throw new Error("corner case 2, shiiiit.");let E=g.vertex;E.links.clear(),E.node=null,E.forced=false,E.next=Ee.zpp_pool,Ee.zpp_pool=E;let M=g;M.vertex=null,M.segment=M.segment2=null,M.node=null,M.next=Ce.zpp_pool,Ce.zpp_pool=M;}}else {let P=g.vertex;P.links.clear(),P.node=null,P.forced=false,P.next=Ee.zpp_pool,Ee.zpp_pool=P;let v=g;v.vertex=null,v.segment=v.segment2=null,v.node=null,v.next=Ce.zpp_pool,Ce.zpp_pool=v;}}ye.ints.remove(x);}let m=x;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Ce.zpp_pool,Ce.zpp_pool=m;}let h=0,u=ye.inthash.table.length;for(;h<u;){let x=h++,m=ye.inthash.table[x];if(m!=null){for(;m!=null;){let _=m.hnext;m.hnext=null;let y=m;y.next=Be.zpp_pool,Be.zpp_pool=y,m=_;}ye.inthash.table[x]=null;}}for(t==null&&(t=new Gn);!ye.vertices.empty();)ye.clip_polygon(ye.vertices,t);return t}static clip_polygon(e,t){let n=null,s=e.first(),i=s,l=s.links.parent,r=l.prev==null?l.next:l.prev,o=l.data,a=r.data,p=s.x-o.x,c=s.y-o.y,h=a.x-s.x;(a.y-s.y)*p-h*c<0&&(a=o);let x=s.x,m=s.y,_;Pe.zpp_pool==null?_=new Pe:(_=Pe.zpp_pool,Pe.zpp_pool=_.next,_.next=null),_.forced=false,_.x=x,_.y=m;let y=_;if(n==null)y.prev=y.next=y;else {let b=n,w=b.next;y.prev=b,y.next=w,w.prev=y,b.next=y;}for(n=y,n.forced=s.forced;;){if(s.links.remove(a),a.links.remove(s),a==i){if(s.links.empty()){e.remove(s);let f=s;f.links.clear(),f.node=null,f.forced=false,f.next=Ee.zpp_pool,Ee.zpp_pool=f;}break}let b=a.x,w=a.y,Z;Pe.zpp_pool==null?Z=new Pe:(Z=Pe.zpp_pool,Pe.zpp_pool=Z.next,Z.next=null),Z.forced=false,Z.x=b,Z.y=w;let d=Z;if(n==null)d.prev=d.next=d;else {let f=n,g=f.next;d.prev=f,d.next=g,g.prev=d,f.next=d;}if(n=d,n.forced=a.forced,a.links.singular()){if(s.links.empty()){e.remove(s);let f=s;f.links.clear(),f.node=null,f.forced=false,f.next=Ee.zpp_pool,Ee.zpp_pool=f;}s=a,a=a.links.parent.data;}else {let f=null,g=0;if(!a.links.empty()){let P=a.links.parent;for(;P.prev!=null;)P=P.prev;for(;P!=null;){let v=P.data;if(f==null){f=v;let N=a.x-s.x,E=a.y-s.y,M=v.x-a.x;g=(v.y-a.y)*N-M*E;}else {let N=a.x-s.x,E=a.y-s.y,M=v.x-a.x,C=(v.y-a.y)*N-M*E;if(C>0&&g<=0)f=v,g=C;else if(g*C>=0){let S=a.x-v.x,O=a.y-v.y,F=f.x-a.x;(f.y-a.y)*S-F*O>0&&(f=v,g=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(s.links.empty()){e.remove(s);let P=s;P.links.clear(),P.node=null,P.forced=false,P.next=Ee.zpp_pool,Ee.zpp_pool=P;}s=a,a=f;}}e.remove(i);let z=i;z.links.clear(),z.node=null,z.forced=false,z.next=Ee.zpp_pool,Ee.zpp_pool=z,t.add(n);}static isSimple(e){ye.sweep==null&&(ye.sweep=new Di,ye.inthash=new Ni);let t=ye.list_vertices;t==null&&(t=ye.list_vertices=new _l);let n=e,s=e;if(n!=null){let _=n;for(;;){let y=_,z=y.x,b=y.y,w;if(Ee.zpp_pool==null?w=new Ee:(w=Ee.zpp_pool,Ee.zpp_pool=w.next,w.next=null),w.x=z,w.y=b,t.add(w),_=_.next,_==s)break}}let i=ye.list_queue;i==null&&(i=ye.list_queue=new dl);let l=t.head,r=l.elt;for(l=l.next;l!=null;){let _=l.elt,y;Ce.zpp_pool==null?y=new Ce:(y=Ce.zpp_pool,Ce.zpp_pool=y.next,y.next=null),y.vertex=r;let z=i.add(y),b;Ce.zpp_pool==null?b=new Ce:(b=Ce.zpp_pool,Ce.zpp_pool=b.next,b.next=null),b.vertex=_;let w=i.add(b),Z;Ce.less_xy(z,w)?(z.type=1,w.type=2,Z=Vt.get(r,_)):(z.type=2,w.type=1,Z=Vt.get(_,r)),z.segment=w.segment=Z,r=_,l=l.next;}let o=t.head.elt,a;Ce.zpp_pool==null?a=new Ce:(a=Ce.zpp_pool,Ce.zpp_pool=a.next,a.next=null),a.vertex=r;let p=i.add(a),c;Ce.zpp_pool==null?c=new Ce:(c=Ce.zpp_pool,Ce.zpp_pool=c.next,c.next=null),c.vertex=o;let h=i.add(c),u;Ce.less_xy(p,h)?(p.type=1,h.type=2,u=Vt.get(r,o)):(p.type=2,h.type=1,u=Vt.get(o,r)),p.segment=h.segment=u;let x=i;if(x.head!=null&&x.head.next!=null){let _=x.head,y,z,b,w,Z=1,d,f,g;for(;;){for(d=0,z=_,_=null,y=null;z!=null;){for(++d,b=z,f=0,g=Z;b!=null&&f<Z;)++f,b=b.next;for(;f>0||g>0&&b!=null;)f==0?(w=b,b=b.next,--g):g==0||b==null||Ce.less_xy(z.elt,b.elt)?(w=z,z=z.next,--f):(w=b,b=b.next,--g),y!=null?y.next=w:_=w,y=w;z=b;}if(y.next=null,Z<<=1,!(d>1))break}x.head=_,x.modified=true,x.pushmod=true;}let m=true;for(;i.head!=null;){let _=i.pop_unsafe(),y=_.segment;if(_.type==1){if(ye.sweep.add(y),ye.sweep.intersect(y,y.next)||ye.sweep.intersect(y,y.prev)){m=false;break}}else if(_.type==2){if(ye.sweep.intersect(y.prev,y.next)){m=false;break}ye.sweep.remove(y);let b=y;b.left=b.right=null,b.prev=null,b.node=null,b.vertices.clear(),b.next=Vt.zpp_pool,Vt.zpp_pool=b;}let z=_;z.vertex=null,z.segment=z.segment2=null,z.node=null,z.next=Ce.zpp_pool,Ce.zpp_pool=z;}for(;i.head!=null;){let _=i.pop_unsafe();if(_.type==2){let z=_.segment;z.left=z.right=null,z.prev=null,z.node=null,z.vertices.clear(),z.next=Vt.zpp_pool,Vt.zpp_pool=z;}let y=_;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Ce.zpp_pool,Ce.zpp_pool=y;}for(ye.sweep.clear();t.head!=null;){let _=t.pop_unsafe();_.links.clear(),_.node=null,_.forced=false,_.next=Ee.zpp_pool,Ee.zpp_pool=_;}return m}};ye.sweep=null,ye.inthash=null,ye.vertices=null,ye.queue=null,ye.ints=null,ye.list_vertices=null,ye.list_queue=null;var Pi=ye;var Fi=class Fi{constructor(){this.x=0;this.y=0;this.next=null;this.prev=null;this.flag=false;this.forced=false;}static get(e){let t;return Fi.zpp_pool==null?t=new Fi:(t=Fi.zpp_pool,Fi.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t.flag=false,t}free(){}alloc(){}};Fi.zpp_pool=null;var gn=Fi;var Gi=class Gi{constructor(){this.next=null;this.min=null;this.max=null;}static get(e,t){let n;return Gi.zpp_pool==null?n=new Gi:(n=Gi.zpp_pool,Gi.zpp_pool=n.next,n.next=null),n.min=e,n.max=t,n}free(){this.min=null,this.max=null;}alloc(){}};Gi.zpp_pool=null;var Te=Gi;var It=class It{static lessval(e,t){return e.x-t.x+(e.y-t.y)}static less(e,t){return e.x-t.x+(e.y-t.y)<0}static distance(e,t,n){let s=n.x-t.x,i=n.y-t.y,l=e.x-t.x,r=e.y-t.y;if(s*s+i*i==0)return l*l+r*r;{let a=(l*s+r*i)/(s*s+i*i);if(a<=0)return l*l+r*r;if(a>=1){let p=e.x-n.x,c=e.y-n.y;return p*p+c*c}else {let p=a;return l-=s*p,r-=i*p,l*l+r*r}}}static simplify(e,t){let n=null,s=null,i=null;t*=t,It.stack==null&&(It.stack=new xl);let l=null,r=null,o=e;for(;;){let p;gn.zpp_pool==null?p=new gn:(p=gn.zpp_pool,gn.zpp_pool=p.next,p.next=null),p.x=o.x,p.y=o.y,p.flag=false;let c=p;if(c.forced=o.forced,c.forced){if(c.flag=true,l!=null){let u=It.stack,x;Te.zpp_pool==null?x=new Te:(x=Te.zpp_pool,Te.zpp_pool=x.next,x.next=null),x.min=l,x.max=c,u.add(x);}else r=c;l=c;}let h=c;if(n==null?h.prev=h.next=h:(h.prev=n,h.next=n.next,n.next.prev=h,n.next=h),n=h,s==null?(s=n,i=n):(n.x-s.x+(n.y-s.y)<0&&(s=n),i.x-n.x+(i.y-n.y)<0&&(i=n)),o=o.next,o==e)break}if(It.stack.head==null)if(r==null){s.flag=i.flag=true;let p=It.stack,c;Te.zpp_pool==null?c=new Te:(c=Te.zpp_pool,Te.zpp_pool=c.next,c.next=null),c.min=s,c.max=i,p.add(c);let h=It.stack,u;Te.zpp_pool==null?u=new Te:(u=Te.zpp_pool,Te.zpp_pool=u.next,u.next=null),u.min=i,u.max=s,h.add(u);}else {let p=s.x-r.x+(s.y-r.y);p<0&&(p=-p);let c=i.x-r.x+(i.y-r.y);if(c<0&&(c=-c),p>c){s.flag=r.flag=true;let h=It.stack,u;Te.zpp_pool==null?u=new Te:(u=Te.zpp_pool,Te.zpp_pool=u.next,u.next=null),u.min=s,u.max=r,h.add(u);let x=It.stack,m;Te.zpp_pool==null?m=new Te:(m=Te.zpp_pool,Te.zpp_pool=m.next,m.next=null),m.min=r,m.max=s,x.add(m);}else {i.flag=r.flag=true;let h=It.stack,u;Te.zpp_pool==null?u=new Te:(u=Te.zpp_pool,Te.zpp_pool=u.next,u.next=null),u.min=i,u.max=r,h.add(u);let x=It.stack,m;Te.zpp_pool==null?m=new Te:(m=Te.zpp_pool,Te.zpp_pool=m.next,m.next=null),m.min=r,m.max=i,x.add(m);}}else {let p=It.stack,c;Te.zpp_pool==null?c=new Te:(c=Te.zpp_pool,Te.zpp_pool=c.next,c.next=null),c.min=l,c.max=r,p.add(c);}for(;It.stack.head!=null;){let p=It.stack.pop_unsafe(),c=p.min,h=p.max,u=p;u.min=u.max=null,u.next=Te.zpp_pool,Te.zpp_pool=u;let x=t,m=null,_=c.next;for(;_!=h;){let y=It.distance(_,c,h);y>x&&(x=y,m=_),_=_.next;}if(m!=null){m.flag=true;let y=It.stack,z;Te.zpp_pool==null?z=new Te:(z=Te.zpp_pool,Te.zpp_pool=z.next,z.next=null),z.min=c,z.max=m,y.add(z);let b=It.stack,w;Te.zpp_pool==null?w=new Te:(w=Te.zpp_pool,Te.zpp_pool=w.next,w.next=null),w.min=m,w.max=h,b.add(w);}}let a=null;for(;n!=null;){if(n.flag){let p=n.x,c=n.y,h;Pe.zpp_pool==null?h=new Pe:(h=Pe.zpp_pool,Pe.zpp_pool=h.next,h.next=null),h.forced=false,h.x=p,h.y=c;let u=h;a==null?u.prev=u.next=u:(u.prev=a,u.next=a.next,a.next.prev=u,a.next=u),a=u,a.forced=n.forced;}if(n!=null&&n.prev==n)n.next=n.prev=null,n.next=gn.zpp_pool,gn.zpp_pool=n,n=null;else {let p=n.next;n.prev.next=n.next,n.next.prev=n.prev,n.next=n.prev=null,n.next=gn.zpp_pool,gn.zpp_pool=n,n=p;}}return a}};It.stack=null;var os=It;var Ns=class{constructor(){this.next=null;this.toi=0;this.s1=null;this.s2=null;this.arbiter=null;this.frozen1=false;this.frozen2=false;this.slipped=false;this.failed=false;this.kinematic=false;this.c1=ae.get(0,0),this.c2=ae.get(0,0),this.axis=ae.get(0,0);}alloc(){this.failed=false,this.s1=this.s2=null,this.arbiter=null;}free(){}};Ns.zpp_pool=null;function pt(j){return j.type===0}function Ft(j){return j.circle.radius}var Cn=class{static dynamicSweep(e,t,n,s,i){let l=_e();i==null&&(i=false);let r=e.s1,o=e.s2,a=r.body,p=o.body,c=0,h=0;c=p.velx-a.velx,h=p.vely-a.vely;let u=a.angvel;u<0&&(u=-u);let x=p.angvel;x<0&&(x=-x);let m=r.sweepCoef*u+o.sweepCoef*x;if(!i&&!e.kinematic&&c*c+h*h<l.Config.dynamicSweepLinearThreshold*l.Config.dynamicSweepLinearThreshold&&m<l.Config.dynamicSweepAngularThreshold){e.toi=-1,e.failed=true;return}let _=e.c1,y=e.c2,z=e.axis,b=n,w=0;for(;;){let C=b*t,S=C-a.sweepTime;if(S!=0){a.sweepTime=C;let H=S;if(a.posx+=a.velx*H,a.posy+=a.vely*H,a.angvel!=0){let X=a.sweep_angvel*S;if(a.rot+=X,X*X>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else {let ee=X*X,q=1-.5*ee,D=1-ee*ee/8,L=(q*a.axisx+X*a.axisy)*D;a.axisy=(q*a.axisy-X*a.axisx)*D,a.axisx=L;}}}if(r.type==0)r.worldCOMx=a.posx+(a.axisy*r.localCOMx-a.axisx*r.localCOMy),r.worldCOMy=a.posy+(r.localCOMx*a.axisx+r.localCOMy*a.axisy);else {let H=r.polygon,X=H.lverts.next,ee=H.gverts.next;for(;ee!=null;){let Q=ee,K=X;X=X.next,Q.x=a.posx+(a.axisy*K.x-a.axisx*K.y),Q.y=a.posy+(K.x*a.axisx+K.y*a.axisy),ee=ee.next;}let q=H.edges.head,D=H.gverts.next,L=D;for(D=D.next;D!=null;){let Q=D,K=q.elt;q=q.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=L.y*K.gnormx-L.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,L=Q,D=D.next;}let V=H.gverts.next,U=q.elt;q=q.next,U.gnormx=a.axisy*U.lnormx-a.axisx*U.lnormy,U.gnormy=U.lnormx*a.axisx+U.lnormy*a.axisy,U.gprojection=a.posx*U.gnormx+a.posy*U.gnormy+U.lprojection,U.tp0=L.y*U.gnormx-L.x*U.gnormy,U.tp1=V.y*U.gnormx-V.x*U.gnormy;}let O=b*t,F=O-p.sweepTime;if(F!=0){p.sweepTime=O;let H=F;if(p.posx+=p.velx*H,p.posy+=p.vely*H,p.angvel!=0){let X=p.sweep_angvel*F;if(p.rot+=X,X*X>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else {let ee=X*X,q=1-.5*ee,D=1-ee*ee/8,L=(q*p.axisx+X*p.axisy)*D;p.axisy=(q*p.axisy-X*p.axisx)*D,p.axisx=L;}}}if(o.type==0)o.worldCOMx=p.posx+(p.axisy*o.localCOMx-p.axisx*o.localCOMy),o.worldCOMy=p.posy+(o.localCOMx*p.axisx+o.localCOMy*p.axisy);else {let H=o.polygon,X=H.lverts.next,ee=H.gverts.next;for(;ee!=null;){let Q=ee,K=X;X=X.next,Q.x=p.posx+(p.axisy*K.x-p.axisx*K.y),Q.y=p.posy+(K.x*p.axisx+K.y*p.axisy),ee=ee.next;}let q=H.edges.head,D=H.gverts.next,L=D;for(D=D.next;D!=null;){let Q=D,K=q.elt;q=q.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=L.y*K.gnormx-L.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,L=Q,D=D.next;}let V=H.gverts.next,U=q.elt;q=q.next,U.gnormx=p.axisy*U.lnormx-p.axisx*U.lnormy,U.gnormy=U.lnormx*p.axisx+U.lnormy*p.axisy,U.gprojection=p.posx*U.gnormx+p.posy*U.gnormy+U.lprojection,U.tp0=L.y*U.gnormx-L.x*U.gnormy,U.tp1=V.y*U.gnormx-V.x*U.gnormy;}let T=r,R=o,W=_,G=y;var Z;if(pt(T)&&pt(R)){let H=T.circle||T.capsule,X=R.circle||R.capsule,ee=Ft(T),q=Ft(R);var d;let D=0,L=0;D=X.worldCOMx-H.worldCOMx,L=X.worldCOMy-H.worldCOMy;let V=Math.sqrt(D*D+L*L);if(d=V-(ee+q),d<1e100){if(V==0)D=1,L=0;else {let K=1/V;D*=K,L*=K;}let U=ee;W.x=H.worldCOMx+D*U,W.y=H.worldCOMy+L*U;let Q=-q;G.x=X.worldCOMx+D*Q,G.y=X.worldCOMy+L*Q,z.x=D,z.y=L;}Z=d;}else {let H=false;if(pt(T)&&R.type==1){let X=T;T=R,R=X;let ee=W;W=G,G=ee,H=true;}if(T.type==1&&pt(R)){let X=T.polygon,ee=R.circle||R.capsule,q=Ft(R),D=-1e100,L=null,V=X.edges.head;for(;V!=null;){let U=V.elt,Q=U.gnormx*ee.worldCOMx+U.gnormy*ee.worldCOMy-U.gprojection-q;if(Q>1e100){D=Q;break}Q>0?Q>D&&(D=Q,L=U):D<0&&Q>D&&(D=Q,L=U),V=V.next;}if(D<1e100){let U=L.gp0,Q=L.gp1,K=ee.worldCOMy*L.gnormx-ee.worldCOMx*L.gnormy;if(K<=U.y*L.gnormx-U.x*L.gnormy){let ie=0,oe=0;ie=ee.worldCOMx-U.x,oe=ee.worldCOMy-U.y;let se=Math.sqrt(ie*ie+oe*oe);if(D=se-q,D<1e100){if(se==0)ie=1,oe=0;else {let le=1/se;ie*=le,oe*=le;}let ne=0;W.x=U.x+ie*ne,W.y=U.y+oe*ne;let re=-q;G.x=ee.worldCOMx+ie*re,G.y=ee.worldCOMy+oe*re,z.x=ie,z.y=oe;}}else if(K>=Q.y*L.gnormx-Q.x*L.gnormy){let ie=0,oe=0;ie=ee.worldCOMx-Q.x,oe=ee.worldCOMy-Q.y;let se=Math.sqrt(ie*ie+oe*oe);if(D=se-q,D<1e100){if(se==0)ie=1,oe=0;else {let le=1/se;ie*=le,oe*=le;}let ne=0;W.x=Q.x+ie*ne,W.y=Q.y+oe*ne;let re=-q;G.x=ee.worldCOMx+ie*re,G.y=ee.worldCOMy+oe*re,z.x=ie,z.y=oe;}}else {let ie=-q;G.x=ee.worldCOMx+L.gnormx*ie,G.y=ee.worldCOMy+L.gnormy*ie;let oe=-D;W.x=G.x+L.gnormx*oe,W.y=G.y+L.gnormy*oe,z.x=L.gnormx,z.y=L.gnormy;}}H&&(z.x=-z.x,z.y=-z.y),Z=D;}else {let X=T.polygon,ee=R.polygon,q=-1e100,D=null,L=null,V=0,U=X.edges.head;for(;U!=null;){let Q=U.elt,K=1e100,ie=ee.gverts.next;for(;ie!=null;){let oe=ie,se=Q.gnormx*oe.x+Q.gnormy*oe.y;se<K&&(K=se),ie=ie.next;}if(K-=Q.gprojection,K>1e100){q=K;break}K>0?K>q&&(q=K,D=Q,V=1):q<0&&K>q&&(q=K,D=Q,V=1),U=U.next;}if(q<1e100){let Q=ee.edges.head;for(;Q!=null;){let K=Q.elt,ie=1e100,oe=X.gverts.next;for(;oe!=null;){let se=oe,ne=K.gnormx*se.x+K.gnormy*se.y;ne<ie&&(ie=ne),oe=oe.next;}if(ie-=K.gprojection,ie>1e100){q=ie;break}ie>0?ie>q&&(q=ie,L=K,V=2):q<0&&ie>q&&(q=ie,L=K,V=2),Q=Q.next;}if(q<1e100){var g,P;if(V==1)g=ee,P=D;else {g=X,P=L;let se=W;W=G,G=se,H=!H;}let K=null,ie=1e100,oe=g.edges.head;for(;oe!=null;){let se=oe.elt,ne=P.gnormx*se.gnormx+P.gnormy*se.gnormy;ne<ie&&(ie=ne,K=se),oe=oe.next;}if(H?(z.x=-P.gnormx,z.y=-P.gnormy):(z.x=P.gnormx,z.y=P.gnormy),q>=0){let se=P.gp0,ne=P.gp1,re=K.gp0,le=K.gp1,he=0,pe=0,ce=0,te=0;he=ne.x-se.x,pe=ne.y-se.y,ce=le.x-re.x,te=le.y-re.y;let ue=1/(he*he+pe*pe),de=1/(ce*ce+te*te),me=-(he*(se.x-re.x)+pe*(se.y-re.y))*ue,ve=-(he*(se.x-le.x)+pe*(se.y-le.y))*ue,Se=-(ce*(re.x-se.x)+te*(re.y-se.y))*de,Ve=-(ce*(re.x-ne.x)+te*(re.y-ne.y))*de;me<0?me=0:me>1&&(me=1),ve<0?ve=0:ve>1&&(ve=1),Se<0?Se=0:Se>1&&(Se=1),Ve<0?Ve=0:Ve>1&&(Ve=1);let Ue=0,Ye=0,He=me;Ue=se.x+he*He,Ye=se.y+pe*He;let Fe=0,bt=0,vt=ve;Fe=se.x+he*vt,bt=se.y+pe*vt;let ct=0,ht=0,at=Se;ct=re.x+ce*at,ht=re.y+te*at;let Ke=0,ft=0,Bt=Ve;Ke=re.x+ce*Bt,ft=re.y+te*Bt;let qt=0,kt=0;qt=Ue-re.x,kt=Ye-re.y;let Et=qt*qt+kt*kt,zn=0,Ht=0;zn=Fe-le.x,Ht=bt-le.y;let xn=zn*zn+Ht*Ht,rn=0,_n=0;rn=ct-se.x,_n=ht-se.y;let Xt=rn*rn+_n*_n,Pn=0,Qt=0;Pn=Ke-ne.x,Qt=ft-ne.y;let dn=Pn*Pn+Qt*Qt,Wt=0,$t=0,an=null;Et<xn?(Wt=Ue,$t=Ye,an=re):(Wt=Fe,$t=bt,an=le,Et=xn);let ei=0,Fn=0,An=null;if(Xt<dn?(ei=ct,Fn=ht,An=se):(ei=Ke,Fn=ft,An=ne,Xt=dn),Et<Xt?(W.x=Wt,W.y=$t,G.x=an.x,G.y=an.y,q=Math.sqrt(Et)):(G.x=ei,G.y=Fn,W.x=An.x,W.y=An.y,q=Math.sqrt(Xt)),q!=0){z.x=G.x-W.x,z.y=G.y-W.y;let Vn=1/q;z.x*=Vn,z.y*=Vn,H&&(z.x=-z.x,z.y=-z.y);}Z=q;}else {let se=0,ne=0;se=K.gp0.x,ne=K.gp0.y;let re=0,le=0;re=K.gp1.x,le=K.gp1.y;let he=0,pe=0;he=re-se,pe=le-ne;let ce=P.gnormy*se-P.gnormx*ne,te=P.gnormy*re-P.gnormx*le,ue=1/(te-ce),de=(-P.tp1-ce)*ue;if(de>l.Config.epsilon){let Ve=de;se+=he*Ve,ne+=pe*Ve;}let me=(-P.tp0-te)*ue;if(me<-l.Config.epsilon){let Ve=me;re+=he*Ve,le+=pe*Ve;}let ve=se*P.gnormx+ne*P.gnormy-P.gprojection,Se=re*P.gnormx+le*P.gnormy-P.gprojection;if(ve<Se){G.x=se,G.y=ne;let Ve=-ve;W.x=G.x+P.gnormx*Ve,W.y=G.y+P.gnormy*Ve,Z=ve;}else {G.x=re,G.y=le;let Ve=-Se;W.x=G.x+P.gnormx*Ve,W.y=G.y+P.gnormy*Ve,Z=Se;}}}else Z=1e100;}else Z=1e100;}}let B=Z+s,A=c*z.x+h*z.y;if(B<l.Config.distanceThresholdCCD){if(i)break;let H=0,X=0;H=_.x-a.posx,X=_.y-a.posy;let ee=0,q=0;ee=y.x-p.posx,q=y.y-p.posy;let D=A-a.sweep_angvel*(z.y*H-z.x*X)+p.sweep_angvel*(z.y*ee-z.x*q);if(D>0&&(e.slipped=true),D<=0||B<l.Config.distanceThresholdCCD*.5)break}let Y=(m-A)*t;if(Y<=0){b=-1;break}let $=B/Y;if($<1e-6&&($=1e-6),b+=$,b>=1){b=1;let H=b*t,X=H-a.sweepTime;if(X!=0){a.sweepTime=H;let ie=X;if(a.posx+=a.velx*ie,a.posy+=a.vely*ie,a.angvel!=0){let oe=a.sweep_angvel*X;if(a.rot+=oe,oe*oe>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else {let se=oe*oe,ne=1-.5*se,re=1-se*se/8,le=(ne*a.axisx+oe*a.axisy)*re;a.axisy=(ne*a.axisy-oe*a.axisx)*re,a.axisx=le;}}}if(r.type==0)r.worldCOMx=a.posx+(a.axisy*r.localCOMx-a.axisx*r.localCOMy),r.worldCOMy=a.posy+(r.localCOMx*a.axisx+r.localCOMy*a.axisy);else {let ie=r.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ce=se,te=oe;oe=oe.next,ce.x=a.posx+(a.axisy*te.x-a.axisx*te.y),ce.y=a.posy+(te.x*a.axisx+te.y*a.axisy),se=se.next;}let ne=ie.edges.head,re=ie.gverts.next,le=re;for(re=re.next;re!=null;){let ce=re,te=ne.elt;ne=ne.next,te.gnormx=a.axisy*te.lnormx-a.axisx*te.lnormy,te.gnormy=te.lnormx*a.axisx+te.lnormy*a.axisy,te.gprojection=a.posx*te.gnormx+a.posy*te.gnormy+te.lprojection,te.tp0=le.y*te.gnormx-le.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,le=ce,re=re.next;}let he=ie.gverts.next,pe=ne.elt;ne=ne.next,pe.gnormx=a.axisy*pe.lnormx-a.axisx*pe.lnormy,pe.gnormy=pe.lnormx*a.axisx+pe.lnormy*a.axisy,pe.gprojection=a.posx*pe.gnormx+a.posy*pe.gnormy+pe.lprojection,pe.tp0=le.y*pe.gnormx-le.x*pe.gnormy,pe.tp1=he.y*pe.gnormx-he.x*pe.gnormy;}let ee=b*t,q=ee-p.sweepTime;if(q!=0){p.sweepTime=ee;let ie=q;if(p.posx+=p.velx*ie,p.posy+=p.vely*ie,p.angvel!=0){let oe=p.sweep_angvel*q;if(p.rot+=oe,oe*oe>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else {let se=oe*oe,ne=1-.5*se,re=1-se*se/8,le=(ne*p.axisx+oe*p.axisy)*re;p.axisy=(ne*p.axisy-oe*p.axisx)*re,p.axisx=le;}}}if(o.type==0)o.worldCOMx=p.posx+(p.axisy*o.localCOMx-p.axisx*o.localCOMy),o.worldCOMy=p.posy+(o.localCOMx*p.axisx+o.localCOMy*p.axisy);else {let ie=o.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ce=se,te=oe;oe=oe.next,ce.x=p.posx+(p.axisy*te.x-p.axisx*te.y),ce.y=p.posy+(te.x*p.axisx+te.y*p.axisy),se=se.next;}let ne=ie.edges.head,re=ie.gverts.next,le=re;for(re=re.next;re!=null;){let ce=re,te=ne.elt;ne=ne.next,te.gnormx=p.axisy*te.lnormx-p.axisx*te.lnormy,te.gnormy=te.lnormx*p.axisx+te.lnormy*p.axisy,te.gprojection=p.posx*te.gnormx+p.posy*te.gnormy+te.lprojection,te.tp0=le.y*te.gnormx-le.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,le=ce,re=re.next;}let he=ie.gverts.next,pe=ne.elt;ne=ne.next,pe.gnormx=p.axisy*pe.lnormx-p.axisx*pe.lnormy,pe.gnormy=pe.lnormx*p.axisx+pe.lnormy*p.axisy,pe.gprojection=p.posx*pe.gnormx+p.posy*pe.gnormy+pe.lprojection,pe.tp0=le.y*pe.gnormx-le.x*pe.gnormy,pe.tp1=he.y*pe.gnormx-he.x*pe.gnormy;}let D=r,L=o,V=_,U=y;var v;if(pt(D)&&pt(L)){let ie=D.circle||D.capsule,oe=L.circle||L.capsule,se=Ft(D),ne=Ft(L);var N;let re=0,le=0;re=oe.worldCOMx-ie.worldCOMx,le=oe.worldCOMy-ie.worldCOMy;let he=Math.sqrt(re*re+le*le);if(N=he-(se+ne),N<1e100){if(he==0)re=1,le=0;else {let te=1/he;re*=te,le*=te;}let pe=se;V.x=ie.worldCOMx+re*pe,V.y=ie.worldCOMy+le*pe;let ce=-ne;U.x=oe.worldCOMx+re*ce,U.y=oe.worldCOMy+le*ce,z.x=re,z.y=le;}v=N;}else {let ie=false;if(pt(D)&&L.type==1){let oe=D;D=L,L=oe;let se=V;V=U,U=se,ie=true;}if(D.type==1&&pt(L)){let oe=D.polygon,se=L.circle||L.capsule,ne=Ft(L),re=-1e100,le=null,he=oe.edges.head;for(;he!=null;){let pe=he.elt,ce=pe.gnormx*se.worldCOMx+pe.gnormy*se.worldCOMy-pe.gprojection-ne;if(ce>1e100){re=ce;break}ce>0?ce>re&&(re=ce,le=pe):re<0&&ce>re&&(re=ce,le=pe),he=he.next;}if(re<1e100){let pe=le.gp0,ce=le.gp1,te=se.worldCOMy*le.gnormx-se.worldCOMx*le.gnormy;if(te<=pe.y*le.gnormx-pe.x*le.gnormy){let ue=0,de=0;ue=se.worldCOMx-pe.x,de=se.worldCOMy-pe.y;let me=Math.sqrt(ue*ue+de*de);if(re=me-ne,re<1e100){if(me==0)ue=1,de=0;else {let Ve=1/me;ue*=Ve,de*=Ve;}let ve=0;V.x=pe.x+ue*ve,V.y=pe.y+de*ve;let Se=-ne;U.x=se.worldCOMx+ue*Se,U.y=se.worldCOMy+de*Se,z.x=ue,z.y=de;}}else if(te>=ce.y*le.gnormx-ce.x*le.gnormy){let ue=0,de=0;ue=se.worldCOMx-ce.x,de=se.worldCOMy-ce.y;let me=Math.sqrt(ue*ue+de*de);if(re=me-ne,re<1e100){if(me==0)ue=1,de=0;else {let Ve=1/me;ue*=Ve,de*=Ve;}let ve=0;V.x=ce.x+ue*ve,V.y=ce.y+de*ve;let Se=-ne;U.x=se.worldCOMx+ue*Se,U.y=se.worldCOMy+de*Se,z.x=ue,z.y=de;}}else {let ue=-ne;U.x=se.worldCOMx+le.gnormx*ue,U.y=se.worldCOMy+le.gnormy*ue;let de=-re;V.x=U.x+le.gnormx*de,V.y=U.y+le.gnormy*de,z.x=le.gnormx,z.y=le.gnormy;}}ie&&(z.x=-z.x,z.y=-z.y),v=re;}else {let oe=D.polygon,se=L.polygon,ne=-1e100,re=null,le=null,he=0,pe=oe.edges.head;for(;pe!=null;){let ce=pe.elt,te=1e100,ue=se.gverts.next;for(;ue!=null;){let de=ue,me=ce.gnormx*de.x+ce.gnormy*de.y;me<te&&(te=me),ue=ue.next;}if(te-=ce.gprojection,te>1e100){ne=te;break}te>0?te>ne&&(ne=te,re=ce,he=1):ne<0&&te>ne&&(ne=te,re=ce,he=1),pe=pe.next;}if(ne<1e100){let ce=se.edges.head;for(;ce!=null;){let te=ce.elt,ue=1e100,de=oe.gverts.next;for(;de!=null;){let me=de,ve=te.gnormx*me.x+te.gnormy*me.y;ve<ue&&(ue=ve),de=de.next;}if(ue-=te.gprojection,ue>1e100){ne=ue;break}ue>0?ue>ne&&(ne=ue,le=te,he=2):ne<0&&ue>ne&&(ne=ue,le=te,he=2),ce=ce.next;}if(ne<1e100){var M,k;if(he==1)M=se,k=re;else {M=oe,k=le;let me=V;V=U,U=me,ie=!ie;}let te=null,ue=1e100,de=M.edges.head;for(;de!=null;){let me=de.elt,ve=k.gnormx*me.gnormx+k.gnormy*me.gnormy;ve<ue&&(ue=ve,te=me),de=de.next;}if(ie?(z.x=-k.gnormx,z.y=-k.gnormy):(z.x=k.gnormx,z.y=k.gnormy),ne>=0){let me=k.gp0,ve=k.gp1,Se=te.gp0,Ve=te.gp1,Ue=0,Ye=0,He=0,Fe=0;Ue=ve.x-me.x,Ye=ve.y-me.y,He=Ve.x-Se.x,Fe=Ve.y-Se.y;let bt=1/(Ue*Ue+Ye*Ye),vt=1/(He*He+Fe*Fe),ct=-(Ue*(me.x-Se.x)+Ye*(me.y-Se.y))*bt,ht=-(Ue*(me.x-Ve.x)+Ye*(me.y-Ve.y))*bt,at=-(He*(Se.x-me.x)+Fe*(Se.y-me.y))*vt,Ke=-(He*(Se.x-ve.x)+Fe*(Se.y-ve.y))*vt;ct<0?ct=0:ct>1&&(ct=1),ht<0?ht=0:ht>1&&(ht=1),at<0?at=0:at>1&&(at=1),Ke<0?Ke=0:Ke>1&&(Ke=1);let ft=0,Bt=0,qt=ct;ft=me.x+Ue*qt,Bt=me.y+Ye*qt;let kt=0,Et=0,zn=ht;kt=me.x+Ue*zn,Et=me.y+Ye*zn;let Ht=0,xn=0,rn=at;Ht=Se.x+He*rn,xn=Se.y+Fe*rn;let _n=0,Xt=0,Pn=Ke;_n=Se.x+He*Pn,Xt=Se.y+Fe*Pn;let Qt=0,dn=0;Qt=ft-Se.x,dn=Bt-Se.y;let Wt=Qt*Qt+dn*dn,$t=0,an=0;$t=kt-Ve.x,an=Et-Ve.y;let ei=$t*$t+an*an,Fn=0,An=0;Fn=Ht-me.x,An=xn-me.y;let Vn=Fn*Fn+An*An,Ci=0,Mi=0;Ci=_n-ve.x,Mi=Xt-ve.y;let Zi=Ci*Ci+Mi*Mi,Ji=0,cl=0,Ws=null;Wt<ei?(Ji=ft,cl=Bt,Ws=Se):(Ji=kt,cl=Et,Ws=Ve,Wt=ei);let hl=0,ul=0,Js=null;if(Vn<Zi?(hl=Ht,ul=xn,Js=me):(hl=_n,ul=Xt,Js=ve,Vn=Zi),Wt<Vn?(V.x=Ji,V.y=cl,U.x=Ws.x,U.y=Ws.y,ne=Math.sqrt(Wt)):(U.x=hl,U.y=ul,V.x=Js.x,V.y=Js.y,ne=Math.sqrt(Vn)),ne!=0){z.x=U.x-V.x,z.y=U.y-V.y;let Il=1/ne;z.x*=Il,z.y*=Il,ie&&(z.x=-z.x,z.y=-z.y);}v=ne;}else {let me=0,ve=0;me=te.gp0.x,ve=te.gp0.y;let Se=0,Ve=0;Se=te.gp1.x,Ve=te.gp1.y;let Ue=0,Ye=0;Ue=Se-me,Ye=Ve-ve;let He=k.gnormy*me-k.gnormx*ve,Fe=k.gnormy*Se-k.gnormx*Ve,bt=1/(Fe-He),vt=(-k.tp1-He)*bt;if(vt>l.Config.epsilon){let Ke=vt;me+=Ue*Ke,ve+=Ye*Ke;}let ct=(-k.tp0-Fe)*bt;if(ct<-l.Config.epsilon){let Ke=ct;Se+=Ue*Ke,Ve+=Ye*Ke;}let ht=me*k.gnormx+ve*k.gnormy-k.gprojection,at=Se*k.gnormx+Ve*k.gnormy-k.gprojection;if(ht<at){U.x=me,U.y=ve;let Ke=-ht;V.x=U.x+k.gnormx*Ke,V.y=U.y+k.gnormy*Ke,v=ht;}else {U.x=Se,U.y=Ve;let Ke=-at;V.x=U.x+k.gnormx*Ke,V.y=U.y+k.gnormy*Ke,v=at;}}}else v=1e100;}else v=1e100;}}let Q=v+s,K=c*z.x+h*z.y;if(Q<l.Config.distanceThresholdCCD){if(i)break;let ie=0,oe=0;ie=_.x-a.posx,oe=_.y-a.posy;let se=0,ne=0;se=y.x-p.posx,ne=y.y-p.posy;let re=K-a.sweep_angvel*(z.y*ie-z.x*oe)+p.sweep_angvel*(z.y*se-z.x*ne);if(re>0&&(e.slipped=true),re<=0||Q<l.Config.distanceThresholdCCD*.5)break}b=-1;break}if(++w>=40){B>s&&(e.failed=true);break}}e.toi=b;}static staticSweep(e,t,n,s){let i=_e(),l=e.s1,r=e.s2,o=l.body;r.body;let p=0,c=0;p=-o.velx,c=-o.vely;let h=o.sweep_angvel;h<0&&(h=-h);let u=l.sweepCoef*h,x=e.c1,m=e.c2,_=e.axis,y=n,z=0;for(;;){let M=y*t,k=M-o.sweepTime;if(k!=0){o.sweepTime=M;let B=k;if(o.posx+=o.velx*B,o.posy+=o.vely*B,o.angvel!=0){let A=o.sweep_angvel*k;if(o.rot+=A,A*A>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else {let Y=A*A,$=1-.5*Y,H=1-Y*Y/8,X=($*o.axisx+A*o.axisy)*H;o.axisy=($*o.axisy-A*o.axisx)*H,o.axisx=X;}}}if(l.type==0)l.worldCOMx=o.posx+(o.axisy*l.localCOMx-o.axisx*l.localCOMy),l.worldCOMy=o.posy+(l.localCOMx*o.axisx+l.localCOMy*o.axisy);else {let B=l.polygon,A=B.lverts.next,Y=B.gverts.next;for(;Y!=null;){let D=Y,L=A;A=A.next,D.x=o.posx+(o.axisy*L.x-o.axisx*L.y),D.y=o.posy+(L.x*o.axisx+L.y*o.axisy),Y=Y.next;}let $=B.edges.head,H=B.gverts.next,X=H;for(H=H.next;H!=null;){let D=H,L=$.elt;$=$.next,L.gnormx=o.axisy*L.lnormx-o.axisx*L.lnormy,L.gnormy=L.lnormx*o.axisx+L.lnormy*o.axisy,L.gprojection=o.posx*L.gnormx+o.posy*L.gnormy+L.lprojection,L.tp0=X.y*L.gnormx-X.x*L.gnormy,L.tp1=D.y*L.gnormx-D.x*L.gnormy,X=D,H=H.next;}let ee=B.gverts.next,q=$.elt;$=$.next,q.gnormx=o.axisy*q.lnormx-o.axisx*q.lnormy,q.gnormy=q.lnormx*o.axisx+q.lnormy*o.axisy,q.gprojection=o.posx*q.gnormx+o.posy*q.gnormy+q.lprojection,q.tp0=X.y*q.gnormx-X.x*q.gnormy,q.tp1=ee.y*q.gnormx-ee.x*q.gnormy;}let C=l,S=r,O=x,F=m;var b;if(pt(C)&&pt(S)){let B=C.circle||C.capsule,A=S.circle||S.capsule;Ft(C);Ft(S);var w;let H=0,X=0;H=A.worldCOMx-B.worldCOMx,X=A.worldCOMy-B.worldCOMy;let ee=Math.sqrt(H*H+X*X);if(w=ee-(B.radius+A.radius),w<1e100){if(ee==0)H=1,X=0;else {let L=1/ee;H*=L,X*=L;}let q=B.radius;O.x=B.worldCOMx+H*q,O.y=B.worldCOMy+X*q;let D=-A.radius;F.x=A.worldCOMx+H*D,F.y=A.worldCOMy+X*D,_.x=H,_.y=X;}b=w;}else {let B=false;if(pt(C)&&S.type==1){let A=C;C=S,S=A;let Y=O;O=F,F=Y,B=true;}if(C.type==1&&pt(S)){let A=C.polygon,Y=S.circle||S.capsule,$=Ft(S),H=-1e100,X=null,ee=A.edges.head;for(;ee!=null;){let q=ee.elt,D=q.gnormx*Y.worldCOMx+q.gnormy*Y.worldCOMy-q.gprojection-$;if(D>1e100){H=D;break}D>0?D>H&&(H=D,X=q):H<0&&D>H&&(H=D,X=q),ee=ee.next;}if(H<1e100){let q=X.gp0,D=X.gp1,L=Y.worldCOMy*X.gnormx-Y.worldCOMx*X.gnormy;if(L<=q.y*X.gnormx-q.x*X.gnormy){let V=0,U=0;V=Y.worldCOMx-q.x,U=Y.worldCOMy-q.y;let Q=Math.sqrt(V*V+U*U);if(H=Q-$,H<1e100){if(Q==0)V=1,U=0;else {let oe=1/Q;V*=oe,U*=oe;}let K=0;O.x=q.x+V*K,O.y=q.y+U*K;let ie=-$;F.x=Y.worldCOMx+V*ie,F.y=Y.worldCOMy+U*ie,_.x=V,_.y=U;}}else if(L>=D.y*X.gnormx-D.x*X.gnormy){let V=0,U=0;V=Y.worldCOMx-D.x,U=Y.worldCOMy-D.y;let Q=Math.sqrt(V*V+U*U);if(H=Q-$,H<1e100){if(Q==0)V=1,U=0;else {let oe=1/Q;V*=oe,U*=oe;}let K=0;O.x=D.x+V*K,O.y=D.y+U*K;let ie=-$;F.x=Y.worldCOMx+V*ie,F.y=Y.worldCOMy+U*ie,_.x=V,_.y=U;}}else {let V=-$;F.x=Y.worldCOMx+X.gnormx*V,F.y=Y.worldCOMy+X.gnormy*V;let U=-H;O.x=F.x+X.gnormx*U,O.y=F.y+X.gnormy*U,_.x=X.gnormx,_.y=X.gnormy;}}B&&(_.x=-_.x,_.y=-_.y),b=H;}else {let A=C.polygon,Y=S.polygon,$=-1e100,H=null,X=null,ee=0,q=A.edges.head;for(;q!=null;){let D=q.elt,L=1e100,V=Y.gverts.next;for(;V!=null;){let U=V,Q=D.gnormx*U.x+D.gnormy*U.y;Q<L&&(L=Q),V=V.next;}if(L-=D.gprojection,L>1e100){$=L;break}L>0?L>$&&($=L,H=D,ee=1):$<0&&L>$&&($=L,H=D,ee=1),q=q.next;}if($<1e100){let D=Y.edges.head;for(;D!=null;){let L=D.elt,V=1e100,U=A.gverts.next;for(;U!=null;){let Q=U,K=L.gnormx*Q.x+L.gnormy*Q.y;K<V&&(V=K),U=U.next;}if(V-=L.gprojection,V>1e100){$=V;break}V>0?V>$&&($=V,X=L,ee=2):$<0&&V>$&&($=V,X=L,ee=2),D=D.next;}if($<1e100){var d,f;if(ee==1)d=Y,f=H;else {d=A,f=X;let Q=O;O=F,F=Q,B=!B;}let L=null,V=1e100,U=d.edges.head;for(;U!=null;){let Q=U.elt,K=f.gnormx*Q.gnormx+f.gnormy*Q.gnormy;K<V&&(V=K,L=Q),U=U.next;}if(B?(_.x=-f.gnormx,_.y=-f.gnormy):(_.x=f.gnormx,_.y=f.gnormy),$>=0){let Q=f.gp0,K=f.gp1,ie=L.gp0,oe=L.gp1,se=0,ne=0,re=0,le=0;se=K.x-Q.x,ne=K.y-Q.y,re=oe.x-ie.x,le=oe.y-ie.y;let he=1/(se*se+ne*ne),pe=1/(re*re+le*le),ce=-(se*(Q.x-ie.x)+ne*(Q.y-ie.y))*he,te=-(se*(Q.x-oe.x)+ne*(Q.y-oe.y))*he,ue=-(re*(ie.x-Q.x)+le*(ie.y-Q.y))*pe,de=-(re*(ie.x-K.x)+le*(ie.y-K.y))*pe;ce<0?ce=0:ce>1&&(ce=1),te<0?te=0:te>1&&(te=1),ue<0?ue=0:ue>1&&(ue=1),de<0?de=0:de>1&&(de=1);let me=0,ve=0,Se=ce;me=Q.x+se*Se,ve=Q.y+ne*Se;let Ve=0,Ue=0,Ye=te;Ve=Q.x+se*Ye,Ue=Q.y+ne*Ye;let He=0,Fe=0,bt=ue;He=ie.x+re*bt,Fe=ie.y+le*bt;let vt=0,ct=0,ht=de;vt=ie.x+re*ht,ct=ie.y+le*ht;let at=0,Ke=0;at=me-ie.x,Ke=ve-ie.y;let ft=at*at+Ke*Ke,Bt=0,qt=0;Bt=Ve-oe.x,qt=Ue-oe.y;let kt=Bt*Bt+qt*qt,Et=0,zn=0;Et=He-Q.x,zn=Fe-Q.y;let Ht=Et*Et+zn*zn,xn=0,rn=0;xn=vt-K.x,rn=ct-K.y;let _n=xn*xn+rn*rn,Xt=0,Pn=0,Qt=null;ft<kt?(Xt=me,Pn=ve,Qt=ie):(Xt=Ve,Pn=Ue,Qt=oe,ft=kt);let dn=0,Wt=0,$t=null;if(Ht<_n?(dn=He,Wt=Fe,$t=Q):(dn=vt,Wt=ct,$t=K,Ht=_n),ft<Ht?(O.x=Xt,O.y=Pn,F.x=Qt.x,F.y=Qt.y,$=Math.sqrt(ft)):(F.x=dn,F.y=Wt,O.x=$t.x,O.y=$t.y,$=Math.sqrt(Ht)),$!=0){_.x=F.x-O.x,_.y=F.y-O.y;let an=1/$;_.x*=an,_.y*=an,B&&(_.x=-_.x,_.y=-_.y);}b=$;}else {let Q=0,K=0;Q=L.gp0.x,K=L.gp0.y;let ie=0,oe=0;ie=L.gp1.x,oe=L.gp1.y;let se=0,ne=0;se=ie-Q,ne=oe-K;let re=f.gnormy*Q-f.gnormx*K,le=f.gnormy*ie-f.gnormx*oe,he=1/(le-re),pe=(-f.tp1-re)*he;if(pe>i.Config.epsilon){let de=pe;Q+=se*de,K+=ne*de;}let ce=(-f.tp0-le)*he;if(ce<-i.Config.epsilon){let de=ce;ie+=se*de,oe+=ne*de;}let te=Q*f.gnormx+K*f.gnormy-f.gprojection,ue=ie*f.gnormx+oe*f.gnormy-f.gprojection;if(te<ue){F.x=Q,F.y=K;let de=-te;O.x=F.x+f.gnormx*de,O.y=F.y+f.gnormy*de,b=te;}else {F.x=ie,F.y=oe;let de=-ue;O.x=F.x+f.gnormx*de,O.y=F.y+f.gnormy*de,b=ue;}}}else b=1e100;}else b=1e100;}}let T=b+s,R=p*_.x+c*_.y;if(T<i.Config.distanceThresholdCCD){let B=0,A=0;B=x.x-o.posx,A=x.y-o.posy;let Y=R-o.sweep_angvel*(_.y*B-_.x*A);if(Y>0&&(e.slipped=true),Y<=0||T<i.Config.distanceThresholdCCD*.5)break}let W=(u-R)*t;if(W<=0){y=-1;break}let G=T/W;if(G<1e-6&&(G=1e-6),y+=G,y>=1){y=1;let B=y*t,A=B-o.sweepTime;if(A!=0){o.sweepTime=B;let D=A;if(o.posx+=o.velx*D,o.posy+=o.vely*D,o.angvel!=0){let L=o.sweep_angvel*A;if(o.rot+=L,L*L>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else {let V=L*L,U=1-.5*V,Q=1-V*V/8,K=(U*o.axisx+L*o.axisy)*Q;o.axisy=(U*o.axisy-L*o.axisx)*Q,o.axisx=K;}}}if(l.type==0)l.worldCOMx=o.posx+(o.axisy*l.localCOMx-o.axisx*l.localCOMy),l.worldCOMy=o.posy+(l.localCOMx*o.axisx+l.localCOMy*o.axisy);else {let D=l.polygon,L=D.lverts.next,V=D.gverts.next;for(;V!=null;){let se=V,ne=L;L=L.next,se.x=o.posx+(o.axisy*ne.x-o.axisx*ne.y),se.y=o.posy+(ne.x*o.axisx+ne.y*o.axisy),V=V.next;}let U=D.edges.head,Q=D.gverts.next,K=Q;for(Q=Q.next;Q!=null;){let se=Q,ne=U.elt;U=U.next,ne.gnormx=o.axisy*ne.lnormx-o.axisx*ne.lnormy,ne.gnormy=ne.lnormx*o.axisx+ne.lnormy*o.axisy,ne.gprojection=o.posx*ne.gnormx+o.posy*ne.gnormy+ne.lprojection,ne.tp0=K.y*ne.gnormx-K.x*ne.gnormy,ne.tp1=se.y*ne.gnormx-se.x*ne.gnormy,K=se,Q=Q.next;}let ie=D.gverts.next,oe=U.elt;U=U.next,oe.gnormx=o.axisy*oe.lnormx-o.axisx*oe.lnormy,oe.gnormy=oe.lnormx*o.axisx+oe.lnormy*o.axisy,oe.gprojection=o.posx*oe.gnormx+o.posy*oe.gnormy+oe.lprojection,oe.tp0=K.y*oe.gnormx-K.x*oe.gnormy,oe.tp1=ie.y*oe.gnormx-ie.x*oe.gnormy;}let Y=l,$=r,H=x,X=m;var g;if(pt(Y)&&pt($)){let D=Y.circle||Y.capsule,L=$.circle||$.capsule,V=Ft(Y),U=Ft($);var P;let Q=0,K=0;Q=L.worldCOMx-D.worldCOMx,K=L.worldCOMy-D.worldCOMy;let ie=Math.sqrt(Q*Q+K*K);if(P=ie-(V+U),P<1e100){if(ie==0)Q=1,K=0;else {let ne=1/ie;Q*=ne,K*=ne;}let oe=V;H.x=D.worldCOMx+Q*oe,H.y=D.worldCOMy+K*oe;let se=-U;X.x=L.worldCOMx+Q*se,X.y=L.worldCOMy+K*se,_.x=Q,_.y=K;}g=P;}else {let D=false;if(pt(Y)&&$.type==1){let L=Y;Y=$,$=L;let V=H;H=X,X=V,D=true;}if(Y.type==1&&pt($)){let L=Y.polygon,V=$.circle||$.capsule,U=Ft($),Q=-1e100,K=null,ie=L.edges.head;for(;ie!=null;){let oe=ie.elt,se=oe.gnormx*V.worldCOMx+oe.gnormy*V.worldCOMy-oe.gprojection-U;if(se>1e100){Q=se;break}se>0?se>Q&&(Q=se,K=oe):Q<0&&se>Q&&(Q=se,K=oe),ie=ie.next;}if(Q<1e100){let oe=K.gp0,se=K.gp1,ne=V.worldCOMy*K.gnormx-V.worldCOMx*K.gnormy;if(ne<=oe.y*K.gnormx-oe.x*K.gnormy){let re=0,le=0;re=V.worldCOMx-oe.x,le=V.worldCOMy-oe.y;let he=Math.sqrt(re*re+le*le);if(Q=he-U,Q<1e100){if(he==0)re=1,le=0;else {let te=1/he;re*=te,le*=te;}let pe=0;H.x=oe.x+re*pe,H.y=oe.y+le*pe;let ce=-U;X.x=V.worldCOMx+re*ce,X.y=V.worldCOMy+le*ce,_.x=re,_.y=le;}}else if(ne>=se.y*K.gnormx-se.x*K.gnormy){let re=0,le=0;re=V.worldCOMx-se.x,le=V.worldCOMy-se.y;let he=Math.sqrt(re*re+le*le);if(Q=he-U,Q<1e100){if(he==0)re=1,le=0;else {let te=1/he;re*=te,le*=te;}let pe=0;H.x=se.x+re*pe,H.y=se.y+le*pe;let ce=-U;X.x=V.worldCOMx+re*ce,X.y=V.worldCOMy+le*ce,_.x=re,_.y=le;}}else {let re=-U;X.x=V.worldCOMx+K.gnormx*re,X.y=V.worldCOMy+K.gnormy*re;let le=-Q;H.x=X.x+K.gnormx*le,H.y=X.y+K.gnormy*le,_.x=K.gnormx,_.y=K.gnormy;}}D&&(_.x=-_.x,_.y=-_.y),g=Q;}else {let L=Y.polygon,V=$.polygon,U=-1e100,Q=null,K=null,ie=0,oe=L.edges.head;for(;oe!=null;){let se=oe.elt,ne=1e100,re=V.gverts.next;for(;re!=null;){let le=re,he=se.gnormx*le.x+se.gnormy*le.y;he<ne&&(ne=he),re=re.next;}if(ne-=se.gprojection,ne>1e100){U=ne;break}ne>0?ne>U&&(U=ne,Q=se,ie=1):U<0&&ne>U&&(U=ne,Q=se,ie=1),oe=oe.next;}if(U<1e100){let se=V.edges.head;for(;se!=null;){let ne=se.elt,re=1e100,le=L.gverts.next;for(;le!=null;){let he=le,pe=ne.gnormx*he.x+ne.gnormy*he.y;pe<re&&(re=pe),le=le.next;}if(re-=ne.gprojection,re>1e100){U=re;break}re>0?re>U&&(U=re,K=ne,ie=2):U<0&&re>U&&(U=re,K=ne,ie=2),se=se.next;}if(U<1e100){var N,E;if(ie==1)N=V,E=Q;else {N=L,E=K;let he=H;H=X,X=he,D=!D;}let ne=null,re=1e100,le=N.edges.head;for(;le!=null;){let he=le.elt,pe=E.gnormx*he.gnormx+E.gnormy*he.gnormy;pe<re&&(re=pe,ne=he),le=le.next;}if(D?(_.x=-E.gnormx,_.y=-E.gnormy):(_.x=E.gnormx,_.y=E.gnormy),U>=0){let he=E.gp0,pe=E.gp1,ce=ne.gp0,te=ne.gp1,ue=0,de=0,me=0,ve=0;ue=pe.x-he.x,de=pe.y-he.y,me=te.x-ce.x,ve=te.y-ce.y;let Se=1/(ue*ue+de*de),Ve=1/(me*me+ve*ve),Ue=-(ue*(he.x-ce.x)+de*(he.y-ce.y))*Se,Ye=-(ue*(he.x-te.x)+de*(he.y-te.y))*Se,He=-(me*(ce.x-he.x)+ve*(ce.y-he.y))*Ve,Fe=-(me*(ce.x-pe.x)+ve*(ce.y-pe.y))*Ve;Ue<0?Ue=0:Ue>1&&(Ue=1),Ye<0?Ye=0:Ye>1&&(Ye=1),He<0?He=0:He>1&&(He=1),Fe<0?Fe=0:Fe>1&&(Fe=1);let bt=0,vt=0,ct=Ue;bt=he.x+ue*ct,vt=he.y+de*ct;let ht=0,at=0,Ke=Ye;ht=he.x+ue*Ke,at=he.y+de*Ke;let ft=0,Bt=0,qt=He;ft=ce.x+me*qt,Bt=ce.y+ve*qt;let kt=0,Et=0,zn=Fe;kt=ce.x+me*zn,Et=ce.y+ve*zn;let Ht=0,xn=0;Ht=bt-ce.x,xn=vt-ce.y;let rn=Ht*Ht+xn*xn,_n=0,Xt=0;_n=ht-te.x,Xt=at-te.y;let Pn=_n*_n+Xt*Xt,Qt=0,dn=0;Qt=ft-he.x,dn=Bt-he.y;let Wt=Qt*Qt+dn*dn,$t=0,an=0;$t=kt-pe.x,an=Et-pe.y;let ei=$t*$t+an*an,Fn=0,An=0,Vn=null;rn<Pn?(Fn=bt,An=vt,Vn=ce):(Fn=ht,An=at,Vn=te,rn=Pn);let Ci=0,Mi=0,Zi=null;if(Wt<ei?(Ci=ft,Mi=Bt,Zi=he):(Ci=kt,Mi=Et,Zi=pe,Wt=ei),rn<Wt?(H.x=Fn,H.y=An,X.x=Vn.x,X.y=Vn.y,U=Math.sqrt(rn)):(X.x=Ci,X.y=Mi,H.x=Zi.x,H.y=Zi.y,U=Math.sqrt(Wt)),U!=0){_.x=X.x-H.x,_.y=X.y-H.y;let Ji=1/U;_.x*=Ji,_.y*=Ji,D&&(_.x=-_.x,_.y=-_.y);}g=U;}else {let he=0,pe=0;he=ne.gp0.x,pe=ne.gp0.y;let ce=0,te=0;ce=ne.gp1.x,te=ne.gp1.y;let ue=0,de=0;ue=ce-he,de=te-pe;let me=E.gnormy*he-E.gnormx*pe,ve=E.gnormy*ce-E.gnormx*te,Se=1/(ve-me),Ve=(-E.tp1-me)*Se;if(Ve>i.Config.epsilon){let Fe=Ve;he+=ue*Fe,pe+=de*Fe;}let Ue=(-E.tp0-ve)*Se;if(Ue<-i.Config.epsilon){let Fe=Ue;ce+=ue*Fe,te+=de*Fe;}let Ye=he*E.gnormx+pe*E.gnormy-E.gprojection,He=ce*E.gnormx+te*E.gnormy-E.gprojection;if(Ye<He){X.x=he,X.y=pe;let Fe=-Ye;H.x=X.x+E.gnormx*Fe,H.y=X.y+E.gnormy*Fe,g=Ye;}else {X.x=ce,X.y=te;let Fe=-He;H.x=X.x+E.gnormx*Fe,H.y=X.y+E.gnormy*Fe,g=He;}}}else g=1e100;}else g=1e100;}}let ee=g+s,q=p*_.x+c*_.y;if(ee<i.Config.distanceThresholdCCD){let D=0,L=0;D=x.x-o.posx,L=x.y-o.posy;let V=q-o.sweep_angvel*(_.y*D-_.x*L);if(V>0&&(e.slipped=true),V<=0||ee<i.Config.distanceThresholdCCD*.5)break}y=-1;break}if(++z>=40){T>s&&(e.failed=true);break}}e.toi=y;}static distanceBody(e,t,n,s){let i=_e(),l=ae.get(0,0),r=ae.get(0,0),o=ae.get(0,0),a=1e100,p=e.shapes.head;for(;p!=null;){let b=p.elt,w=t.shapes.head;for(;w!=null;){let Z=w.elt,d=b,f=Z,g=l,P=r,v=a;v==null&&(v=1e100);var c;if(pt(d)&&pt(f)){let N=d.circle||d.capsule,E=f.circle||f.capsule,M=Ft(d),k=Ft(f);var h;let C=0,S=0;C=E.worldCOMx-N.worldCOMx,S=E.worldCOMy-N.worldCOMy;let O=Math.sqrt(C*C+S*S);if(h=O-(M+k),h<v){if(O==0)C=1,S=0;else {let R=1/O;C*=R,S*=R;}let F=M;g.x=N.worldCOMx+C*F,g.y=N.worldCOMy+S*F;let T=-k;P.x=E.worldCOMx+C*T,P.y=E.worldCOMy+S*T,o.x=C,o.y=S;}c=h;}else {let N=false;if(pt(d)&&f.type==1){let E=d;d=f,f=E;let M=g;g=P,P=M,N=true;}if(d.type==1&&pt(f)){let E=d.polygon,M=f.circle||f.capsule,k=Ft(f),C=-1e100,S=null,O=E.edges.head;for(;O!=null;){let F=O.elt,T=F.gnormx*M.worldCOMx+F.gnormy*M.worldCOMy-F.gprojection-k;if(T>v){C=T;break}T>0?T>C&&(C=T,S=F):C<0&&T>C&&(C=T,S=F),O=O.next;}if(C<v){let F=S.gp0,T=S.gp1,R=M.worldCOMy*S.gnormx-M.worldCOMx*S.gnormy;if(R<=F.y*S.gnormx-F.x*S.gnormy){let W=0,G=0;W=M.worldCOMx-F.x,G=M.worldCOMy-F.y;let B=Math.sqrt(W*W+G*G);if(C=B-k,C<v){if(B==0)W=1,G=0;else {let $=1/B;W*=$,G*=$;}let A=0;g.x=F.x+W*A,g.y=F.y+G*A;let Y=-k;P.x=M.worldCOMx+W*Y,P.y=M.worldCOMy+G*Y,o.x=W,o.y=G;}}else if(R>=T.y*S.gnormx-T.x*S.gnormy){let W=0,G=0;W=M.worldCOMx-T.x,G=M.worldCOMy-T.y;let B=Math.sqrt(W*W+G*G);if(C=B-k,C<v){if(B==0)W=1,G=0;else {let $=1/B;W*=$,G*=$;}let A=0;g.x=T.x+W*A,g.y=T.y+G*A;let Y=-k;P.x=M.worldCOMx+W*Y,P.y=M.worldCOMy+G*Y,o.x=W,o.y=G;}}else {let W=-k;P.x=M.worldCOMx+S.gnormx*W,P.y=M.worldCOMy+S.gnormy*W;let G=-C;g.x=P.x+S.gnormx*G,g.y=P.y+S.gnormy*G,o.x=S.gnormx,o.y=S.gnormy;}}N&&(o.x=-o.x,o.y=-o.y),c=C;}else {let E=d.polygon,M=f.polygon,k=-1e100,C=null,S=null,O=0,F=E.edges.head;for(;F!=null;){let T=F.elt,R=1e100,W=M.gverts.next;for(;W!=null;){let G=W,B=T.gnormx*G.x+T.gnormy*G.y;B<R&&(R=B),W=W.next;}if(R-=T.gprojection,R>v){k=R;break}R>0?R>k&&(k=R,C=T,O=1):k<0&&R>k&&(k=R,C=T,O=1),F=F.next;}if(k<v){let T=M.edges.head;for(;T!=null;){let R=T.elt,W=1e100,G=E.gverts.next;for(;G!=null;){let B=G,A=R.gnormx*B.x+R.gnormy*B.y;A<W&&(W=A),G=G.next;}if(W-=R.gprojection,W>v){k=W;break}W>0?W>k&&(k=W,S=R,O=2):k<0&&W>k&&(k=W,S=R,O=2),T=T.next;}if(k<v){var x,m;if(O==1)x=M,m=C;else {x=E,m=S;let B=g;g=P,P=B,N=!N;}let R=null,W=1e100,G=x.edges.head;for(;G!=null;){let B=G.elt,A=m.gnormx*B.gnormx+m.gnormy*B.gnormy;A<W&&(W=A,R=B),G=G.next;}if(N?(o.x=-m.gnormx,o.y=-m.gnormy):(o.x=m.gnormx,o.y=m.gnormy),k>=0){let B=m.gp0,A=m.gp1,Y=R.gp0,$=R.gp1,H=0,X=0,ee=0,q=0;H=A.x-B.x,X=A.y-B.y,ee=$.x-Y.x,q=$.y-Y.y;let D=1/(H*H+X*X),L=1/(ee*ee+q*q),V=-(H*(B.x-Y.x)+X*(B.y-Y.y))*D,U=-(H*(B.x-$.x)+X*(B.y-$.y))*D,Q=-(ee*(Y.x-B.x)+q*(Y.y-B.y))*L,K=-(ee*(Y.x-A.x)+q*(Y.y-A.y))*L;V<0?V=0:V>1&&(V=1),U<0?U=0:U>1&&(U=1),Q<0?Q=0:Q>1&&(Q=1),K<0?K=0:K>1&&(K=1);let ie=0,oe=0,se=V;ie=B.x+H*se,oe=B.y+X*se;let ne=0,re=0,le=U;ne=B.x+H*le,re=B.y+X*le;let he=0,pe=0,ce=Q;he=Y.x+ee*ce,pe=Y.y+q*ce;let te=0,ue=0,de=K;te=Y.x+ee*de,ue=Y.y+q*de;let me=0,ve=0;me=ie-Y.x,ve=oe-Y.y;let Se=me*me+ve*ve,Ve=0,Ue=0;Ve=ne-$.x,Ue=re-$.y;let Ye=Ve*Ve+Ue*Ue,He=0,Fe=0;He=he-B.x,Fe=pe-B.y;let bt=He*He+Fe*Fe,vt=0,ct=0;vt=te-A.x,ct=ue-A.y;let ht=vt*vt+ct*ct,at=0,Ke=0,ft=null;Se<Ye?(at=ie,Ke=oe,ft=Y):(at=ne,Ke=re,ft=$,Se=Ye);let Bt=0,qt=0,kt=null;if(bt<ht?(Bt=he,qt=pe,kt=B):(Bt=te,qt=ue,kt=A,bt=ht),Se<bt?(g.x=at,g.y=Ke,P.x=ft.x,P.y=ft.y,k=Math.sqrt(Se)):(P.x=Bt,P.y=qt,g.x=kt.x,g.y=kt.y,k=Math.sqrt(bt)),k!=0){o.x=P.x-g.x,o.y=P.y-g.y;let Et=1/k;o.x*=Et,o.y*=Et,N&&(o.x=-o.x,o.y=-o.y);}c=k;}else {let B=0,A=0;B=R.gp0.x,A=R.gp0.y;let Y=0,$=0;Y=R.gp1.x,$=R.gp1.y;let H=0,X=0;H=Y-B,X=$-A;let ee=m.gnormy*B-m.gnormx*A,q=m.gnormy*Y-m.gnormx*$,D=1/(q-ee),L=(-m.tp1-ee)*D;if(L>i.Config.epsilon){let K=L;B+=H*K,A+=X*K;}let V=(-m.tp0-q)*D;if(V<-i.Config.epsilon){let K=V;Y+=H*K,$+=X*K;}let U=B*m.gnormx+A*m.gnormy-m.gprojection,Q=Y*m.gnormx+$*m.gnormy-m.gprojection;if(U<Q){P.x=B,P.y=A;let K=-U;g.x=P.x+m.gnormx*K,g.y=P.y+m.gnormy*K,c=U;}else {P.x=Y,P.y=$;let K=-Q;g.x=P.x+m.gnormx*K,g.y=P.y+m.gnormy*K,c=Q;}}}else c=v;}else c=v;}}c<a&&(a=c,n.x=l.x,n.y=l.y,s.x=r.x,s.y=r.y),w=w.next;}p=p.next;}let _=l;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=ae.zpp_pool,ae.zpp_pool=_;let y=r;y.outer!=null&&(y.outer.zpp_inner=null,y.outer=null),y._isimmutable=null,y._validate=null,y._invalidate=null,y.next=ae.zpp_pool,ae.zpp_pool=y;let z=o;return z.outer!=null&&(z.outer.zpp_inner=null,z.outer=null),z._isimmutable=null,z._validate=null,z._invalidate=null,z.next=ae.zpp_pool,ae.zpp_pool=z,a}static distance(e,t,n,s,i,l){let r=_e();if(l==null&&(l=1e100),pt(e)&&pt(t)){let o=e.circle||e.capsule,a=t.circle||t.capsule,p=Ft(e),c=Ft(t),h,u=0,x=0;u=a.worldCOMx-o.worldCOMx,x=a.worldCOMy-o.worldCOMy;let m=Math.sqrt(u*u+x*x);if(h=m-(p+c),h<l){if(m==0)u=1,x=0;else {let z=1/m;u*=z,x*=z;}let _=p;n.x=o.worldCOMx+u*_,n.y=o.worldCOMy+x*_;let y=-c;s.x=a.worldCOMx+u*y,s.y=a.worldCOMy+x*y,i.x=u,i.y=x;}return h}else {let o=false;if(pt(e)&&t.type==1){let a=e;e=t,t=a;let p=n;n=s,s=p,o=true;}if(e.type==1&&pt(t)){let a=e.polygon,p=t.circle||t.capsule,c=Ft(t),h=-1e100,u=null,x=a.edges.head;for(;x!=null;){let m=x.elt,_=m.gnormx*p.worldCOMx+m.gnormy*p.worldCOMy-m.gprojection-c;if(_>l){h=_;break}_>0?_>h&&(h=_,u=m):h<0&&_>h&&(h=_,u=m),x=x.next;}if(h<l){let m=u.gp0,_=u.gp1,y=p.worldCOMy*u.gnormx-p.worldCOMx*u.gnormy;if(y<=m.y*u.gnormx-m.x*u.gnormy){let z=0,b=0;z=p.worldCOMx-m.x,b=p.worldCOMy-m.y;let w=Math.sqrt(z*z+b*b);if(h=w-c,h<l){if(w==0)z=1,b=0;else {let f=1/w;z*=f,b*=f;}let Z=0;n.x=m.x+z*Z,n.y=m.y+b*Z;let d=-c;s.x=p.worldCOMx+z*d,s.y=p.worldCOMy+b*d,i.x=z,i.y=b;}}else if(y>=_.y*u.gnormx-_.x*u.gnormy){let z=0,b=0;z=p.worldCOMx-_.x,b=p.worldCOMy-_.y;let w=Math.sqrt(z*z+b*b);if(h=w-c,h<l){if(w==0)z=1,b=0;else {let f=1/w;z*=f,b*=f;}let Z=0;n.x=_.x+z*Z,n.y=_.y+b*Z;let d=-c;s.x=p.worldCOMx+z*d,s.y=p.worldCOMy+b*d,i.x=z,i.y=b;}}else {let z=-c;s.x=p.worldCOMx+u.gnormx*z,s.y=p.worldCOMy+u.gnormy*z;let b=-h;n.x=s.x+u.gnormx*b,n.y=s.y+u.gnormy*b,i.x=u.gnormx,i.y=u.gnormy;}}return o&&(i.x=-i.x,i.y=-i.y),h}else {let a=e.polygon,p=t.polygon,c=-1e100,h=null,u=null,x=0,m=a.edges.head;for(;m!=null;){let _=m.elt,y=1e100,z=p.gverts.next;for(;z!=null;){let b=z,w=_.gnormx*b.x+_.gnormy*b.y;w<y&&(y=w),z=z.next;}if(y-=_.gprojection,y>l){c=y;break}y>0?y>c&&(c=y,h=_,x=1):c<0&&y>c&&(c=y,h=_,x=1),m=m.next;}if(c<l){let _=p.edges.head;for(;_!=null;){let y=_.elt,z=1e100,b=a.gverts.next;for(;b!=null;){let w=b,Z=y.gnormx*w.x+y.gnormy*w.y;Z<z&&(z=Z),b=b.next;}if(z-=y.gprojection,z>l){c=z;break}z>0?z>c&&(c=z,u=y,x=2):c<0&&z>c&&(c=z,u=y,x=2),_=_.next;}if(c<l){let z,b;if(x==1)z=p,b=h;else {z=a,b=u;let f=n;n=s,s=f,o=!o;}let w=null,Z=1e100,d=z.edges.head;for(;d!=null;){let f=d.elt,g=b.gnormx*f.gnormx+b.gnormy*f.gnormy;g<Z&&(Z=g,w=f),d=d.next;}if(o?(i.x=-b.gnormx,i.y=-b.gnormy):(i.x=b.gnormx,i.y=b.gnormy),c>=0){let f=b.gp0,g=b.gp1,P=w.gp0,v=w.gp1,N=0,E=0,M=0,k=0;N=g.x-f.x,E=g.y-f.y,M=v.x-P.x,k=v.y-P.y;let C=1/(N*N+E*E),S=1/(M*M+k*k),O=-(N*(f.x-P.x)+E*(f.y-P.y))*C,F=-(N*(f.x-v.x)+E*(f.y-v.y))*C,T=-(M*(P.x-f.x)+k*(P.y-f.y))*S,R=-(M*(P.x-g.x)+k*(P.y-g.y))*S;O<0?O=0:O>1&&(O=1),F<0?F=0:F>1&&(F=1),T<0?T=0:T>1&&(T=1),R<0?R=0:R>1&&(R=1);let W=0,G=0,B=O;W=f.x+N*B,G=f.y+E*B;let A=0,Y=0,$=F;A=f.x+N*$,Y=f.y+E*$;let H=0,X=0,ee=T;H=P.x+M*ee,X=P.y+k*ee;let q=0,D=0,L=R;q=P.x+M*L,D=P.y+k*L;let V=0,U=0;V=W-P.x,U=G-P.y;let Q=V*V+U*U,K=0,ie=0;K=A-v.x,ie=Y-v.y;let oe=K*K+ie*ie,se=0,ne=0;se=H-f.x,ne=X-f.y;let re=se*se+ne*ne,le=0,he=0;le=q-g.x,he=D-g.y;let pe=le*le+he*he,ce=0,te=0,ue=null;Q<oe?(ce=W,te=G,ue=P):(ce=A,te=Y,ue=v,Q=oe);let de=0,me=0,ve=null;if(re<pe?(de=H,me=X,ve=f):(de=q,me=D,ve=g,re=pe),Q<re?(n.x=ce,n.y=te,s.x=ue.x,s.y=ue.y,c=Math.sqrt(Q)):(s.x=de,s.y=me,n.x=ve.x,n.y=ve.y,c=Math.sqrt(re)),c!=0){i.x=s.x-n.x,i.y=s.y-n.y;let Se=1/c;i.x*=Se,i.y*=Se,o&&(i.x=-i.x,i.y=-i.y);}return c}else {let f=0,g=0;f=w.gp0.x,g=w.gp0.y;let P=0,v=0;P=w.gp1.x,v=w.gp1.y;let N=0,E=0;N=P-f,E=v-g;let M=b.gnormy*f-b.gnormx*g,k=b.gnormy*P-b.gnormx*v,C=1/(k-M),S=(-b.tp1-M)*C;if(S>r.Config.epsilon){let R=S;f+=N*R,g+=E*R;}let O=(-b.tp0-k)*C;if(O<-r.Config.epsilon){let R=O;P+=N*R,v+=E*R;}let F=f*b.gnormx+g*b.gnormy-b.gprojection,T=P*b.gnormx+v*b.gnormy-b.gprojection;if(F<T){s.x=f,s.y=g;let R=-F;return n.x=s.x+b.gnormx*R,n.y=s.y+b.gnormy*R,F}else {s.x=P,s.y=v;let R=-T;return n.x=s.x+b.gnormx*R,n.y=s.y+b.gnormy*R,T}}}else return l}else return l}}}};var Le=class Le{static lt(e,t){return e.y<t.y?true:e.y==t.y?e.x<t.x:false}static right_turn(e,t,n){let s=n.x-t.x,i=n.y-t.y,l=t.x-e.x;return (t.y-e.y)*s-l*i}static delaunay(e,t,n,s){let i=n.x-t.x,l=n.y-t.y,r=t.x-e.x,o=t.y-e.y,a,p,c;return o*i-r*l>=0?c=true:(i=s.x-n.x,l=s.y-n.y,r=n.x-t.x,o=n.y-t.y,c=o*i-r*l>=0),c?p=true:(i=e.x-s.x,l=e.y-s.y,r=s.x-n.x,o=s.y-n.y,p=o*i-r*l>=0),p?a=true:(i=t.x-e.x,l=t.y-e.y,r=e.x-s.x,o=e.y-s.y,a=o*i-r*l>=0),a?true:t.x*(n.y*s.mag-n.mag*s.y)-n.x*(t.y*s.mag-t.mag*s.y)+s.x*(t.y*n.mag-t.mag*n.y)-(e.x*(n.y*s.mag-n.mag*s.y)-n.x*(e.y*s.mag-e.mag*s.y)+s.x*(e.y*n.mag-e.mag*n.y))+(e.x*(t.y*s.mag-t.mag*s.y)-t.x*(e.y*s.mag-e.mag*s.y)+s.x*(e.y*t.mag-e.mag*t.y))-(e.x*(t.y*n.mag-t.mag*n.y)-t.x*(e.y*n.mag-e.mag*n.y)+n.x*(e.y*t.mag-e.mag*t.y))>0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let o=t;for(;;){let a=o;if(a.sort(),a.mag=a.x*a.x+a.y*a.y,o=o.next,o==n)break}}Le.edgeSet==null&&($i.zpp_pool==null?Le.edgeSet=new $i:(Le.edgeSet=$i.zpp_pool,$i.zpp_pool=Le.edgeSet.next,Le.edgeSet.next=null),Le.edgeSet.lt=St.edge_lt,Le.edgeSet.swapped=St.edge_swap);let s;St.zpp_pool==null?s=new St:(s=St.zpp_pool,St.zpp_pool=s.next,s.next=null);let i=e.vertices,l=e.vertices;if(i!=null){let o=i;for(;;){let a=o,p=a.next;a.diagonals.reverse();let c=a.diagonals.head;for(;c!=null;){let h=c.elt;if(h.id<a.id){p=h,c=c.next;continue}let u=c.next==null?a.prev:c.next.elt;if(!Le.delaunay(a,p,h,u)){let x;St.zpp_pool==null?x=new St:(x=St.zpp_pool,St.zpp_pool=x.next,x.next=null),x.a=a,x.b=h,a.id<h.id?(x.id=a.id,x.di=h.id):(x.id=h.id,x.di=a.id);let m=x;s.add(m),m.node=Le.edgeSet.insert(m);}p=h,c=c.next;}if(o=o.next,o==l)break}}for(;s.next!=null;){let o=s.pop_unsafe(),a=o.a,p=o.b,c=a.next,h=null,u=a.diagonals.head;for(;u!=null;){let m=u.elt;if(m==p){u=u.next,h=u==null?a.prev:u.elt;break}c=m,u=u.next;}if(a.diagonals.remove(p),p.diagonals.remove(a),p==c.next)c.diagonals.add(h);else {let m=c.diagonals.head;for(;m!=null;){if(m.elt==p){c.diagonals.insert(m,h);break}m=m.next;}}if(a==h.next)h.diagonals.add(c);else {let m=h.diagonals.head;for(;m!=null;){if(m.elt==a){h.diagonals.insert(m,c);break}m=m.next;}}Le.edgeSet.remove_node(o.node);let x=o;x.a=x.b=null,x.node=null,x.next=St.zpp_pool,St.zpp_pool=x;}let r=s;r.a=r.b=null,r.node=null,r.next=St.zpp_pool,St.zpp_pool=r;}static triangulate(e){let t=e.vertices,n=e.vertices,s=e.vertices.next,i=e.vertices;if(s!=null){let a=s;for(;;){let p=a;if((p.y<t.y||p.y==t.y&&p.x<t.x)&&(t=p),(n.y<p.y||n.y==p.y&&n.x<p.x)&&(n=p),a=a.next,a==i)break}}Le.queue==null&&(Le.queue=new ui);let l=n.prev,r=n.next;for(Le.queue.add(n);l!=t||r!=t;)l==t||r!=t&&(l.y<r.y||l.y==r.y&&l.x<r.x)?(Le.queue.add(r),r.rightchain=false,r=r.next):(Le.queue.add(l),l.rightchain=true,l=l.prev);Le.queue.add(t),Le.stack==null&&(Le.stack=new ui),Le.stack.add(Le.queue.pop_unsafe());let o=Le.queue.pop_unsafe();for(Le.stack.add(o);;){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(o);}else {let p=Le.stack.pop_unsafe();for(;Le.stack.head!=null;){let c=Le.stack.head.elt,h=a.x-p.x,u=a.y-p.y,x=p.x-c.x,_=(p.y-c.y)*h-x*u;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),o=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.queue=null,Le.stack=null,Le.edgeSet=null;var ii=Le;var rs=class rs{constructor(){this.outer=null;this.x=0;this.y=0;this.z=0;this.immutable=false;this._validate=null;}validate(){this._validate!=null&&this._validate();}wrapper(){return this.outer==null&&rs._wrapFn&&(this.outer=rs._wrapFn(this)),this.outer}};rs._zpp=null,rs._wrapFn=null;var si=rs;var $s=class{static vec_dsq(e,t,n,s){let i=e-n,l=t-s;return i*i+l*l}static vec_distance(e,t,n,s){let i=e-n,l=t-s;return Math.sqrt(i*i+l*l)}};var fn=class fn{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;fn.initFields(this);}static initFields(e){let t=fn._zpp;e.wrap_cbTypes=null,e.cbSet=null,e.cbTypes=null,e.group=null,e.cbsets=null,e.icompound=null,e.ibody=null,e.ishape=null,e.userData=null,e.id=0,e.outer_i=null,e.id=yn.Interactor(),e.cbsets=new t.util.ZNPList_ZPP_CallbackSet,e.cbTypes=new t.util.ZNPList_ZPP_CbType;}static get(e,t){let n=e.id<t.id?e.id:t.id,s=e.id<t.id?t.id:e.id,i=e.cbsets.length<t.cbsets.length?e.cbsets:t.cbsets,l=null,r=i.head;for(;r!=null;){let o=r.elt;if(o.id==n&&o.di==s){l=o;break}r=r.next;}return l}static int_callback(e,t,n){let s=e.int1,i=e.int2,l,r=t.options1,o=s.cbTypes;if(r.nonemptyintersection(o,r.includes)&&!r.nonemptyintersection(o,r.excludes)){let a=t.options2,p=i.cbTypes;l=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes);}else l=false;l?(n.int1=s,n.int2=i):(n.int1=i,n.int2=s);}isShape(){return this.ishape!=null}isBody(){return this.ibody!=null}isCompound(){return this.icompound!=null}__iaddedToSpace(){this.group!=null&&this.group.interactors.add(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.add(this),e=e.next;this.alloc_cbSet();}__iremovedFromSpace(){this.group!=null&&this.group.interactors.remove(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.remove(this),e=e.next;this.dealloc_cbSet();}wake(){if(this.ishape!=null){let e=this.ishape.body;e!=null&&e.space!=null&&e.space.non_inlined_wake(e);}else this.ibody!=null?this.ibody.space!=null&&this.ibody.space.non_inlined_wake(this.ibody):this.icompound.space!=null&&this.icompound.space.wakeCompound(this.icompound);}_getSpace(){return this.ishape!=null?this.ishape.body==null?null:this.ishape.body.space:this.ibody!=null?this.ibody.space:this.icompound.space}getSpace(){return this._getSpace()}setupcbTypes(){let e=fn._zpp;this.wrap_cbTypes=e.util.ZPP_CbTypeList.get(this.cbTypes),this.wrap_cbTypes.zpp_inner.adder=this.wrap_cbTypes_adder.bind(this),this.wrap_cbTypes.zpp_inner.subber=this.wrap_cbTypes_subber.bind(this),this.wrap_cbTypes.zpp_inner.dontremove=true,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),false}insert_cbtype(e){let t=fn._zpp;if(!this.cbTypes.has(e)){let n=this._getSpace();n!=null&&(this.dealloc_cbSet(),e.interactors.add(this));let s=null,i=this.cbTypes.head;for(;i!=null;){let a=i.elt;if(e.id<a.id)break;s=i,i=i.next;}let l=this.cbTypes,r;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?r=new t.util.ZNPNode_ZPP_CbType:(r=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=r.next,r.next=null),r.elt=e;let o=r;s==null?(o.next=l.head,l.head=o):(o.next=s.next,s.next=o),l.pushmod=l.modified=true,l.length++,n!=null&&(this.alloc_cbSet(),this.wake());}}alloc_cbSet(){let e=this._getSpace();(this.cbSet=e.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.interactors.add(this),this.cbSet.validate(),e.freshInteractorType(this));}dealloc_cbSet(){let e=this._getSpace();if(this.cbSet!=null){if(this.cbSet.interactors.remove(this),e.nullInteractorType(this),--this.cbSet.count==0){e.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=true,t.bodylisteners.clear(),t.zip_bodylisteners=true,t.conlisteners.clear(),t.zip_conlisteners=true;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=dt.zpp_pool,dt.zpp_pool=t;}this.cbSet=null;}}setGroup(e){if(this.group!=e){let t=this._getSpace()!=null;t&&this.group!=null&&this.group.interactors.remove(this),this.group=e,t&&e!=null&&e.interactors.add(this),t&&(this.ishape!=null?this.ishape.body.wake():this.ibody!=null?this.ibody.wake():this.icompound.wake());}}immutable_midstep(e){if(this.ibody!=null){let t=this.ibody;if(t.space!=null&&t.space.midstep)throw new Error("Error: "+e+" cannot be set during a space step()")}else this.ishape!=null?this.ishape.__immutable_midstep(e):this.icompound.__imutable_midstep(e);}lookup_group(){let e=this;for(;e!=null&&e.group==null;)e.ishape!=null?e=e.ishape.body:e.icompound!=null?e=e.icompound.compound:e=e.ibody.compound;return e==null?null:e.group}copyto(e){let t=fn._nape;e.zpp_inner_i.group=this.group;let n=this.outer_i;n.zpp_inner_i.wrap_cbTypes==null&&n.zpp_inner_i.setupcbTypes();let s=n.zpp_inner_i.wrap_cbTypes;s.zpp_inner.valmod();let i=t.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let l=i.zpp_inner;l.zpp_inner.valmod(),l.zpp_inner.zip_length&&(l.zpp_inner.zip_length=false,l.zpp_inner.user_length=l.zpp_inner.inner.length);let r=l.zpp_inner.user_length;i.zpp_critical=true;let o;if(i.zpp_i<r?o=true:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,o=false),!o)break;i.zpp_critical=false;let a=i.zpp_inner.at(i.zpp_i++);e.zpp_inner_i.wrap_cbTypes==null&&e.zpp_inner_i.setupcbTypes();let p=e.zpp_inner_i.wrap_cbTypes;p.zpp_inner.reverse_flag?p.push(a):p.unshift(a);}this.userData!=null&&(e.zpp_inner_i.userData=Object.assign({},this.userData));}static _init(e,t){fn._initialized||(fn._initialized=true,fn._zpp=e,fn._nape=t);}};fn._nape=null,fn._zpp=null,fn._initialized=false;var Kt=fn;var je=class je{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.world=false;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=false;this.sweepRadius=0;this.bullet=false;this.bulletEnabled=false;this.disableCCD=false;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=false;this.kinematicDelaySleep=false;this.mass=0;this.zip_mass=false;this.massMode=0;this.imass=0;this.smass=0;this.cmass=0;this.nomove=false;this.gravMass=0;this.zip_gravMass=false;this.gravMassMode=0;this.gravMassScale=0;this.zip_gravMassScale=false;this.inertiaMode=0;this.inertia=0;this.zip_inertia=false;this.cinertia=0;this.iinertia=0;this.sinertia=0;this.norotate=false;this.aabb=null;this.zip_aabb=false;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=false;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=false;this.wrap_localCOM=null;this.wrap_worldCOM=null;let e=je._zpp;Kt.initFields(this),this.ibody=this,this.world=false,this.bulletEnabled=false,this.sweepTime=0,this.sweep_angvel=0,this.norotate=this.nomove=false,this.disableCCD=false,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=true;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=true,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=false;}static bodysetlt(e,t){return e.id<t.id}static __static(){let e=je._nape,t=je._zpp;t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=true,t.util.ZPP_Flags.BodyType_STATIC=new e.phys.BodyType,t.util.ZPP_Flags.internal=false);let n=new e.phys.Body(t.util.ZPP_Flags.BodyType_STATIC),s=n.zpp_inner;return s.world=true,s.wrap_shapes.zpp_inner.immutable=true,s.smass=s.imass=s.cmass=s.mass=s.gravMass=0,s.sinertia=s.iinertia=s.cinertia=s.inertia=0,s.cbTypes.clear(),n}isStatic(){return this.type===1}isDynamic(){return this.type===2}isKinematic(){return this.type===3}invalidate_type(){this.invalidate_mass(),this.invalidate_inertia();}invalidate_shapes(){this.zip_aabb=true,this.zip_localCOM=true,this.zip_worldCOM=true,this.invalidate_mass(),this.invalidate_inertia();}init_bodysetlist(){if(je.bodyset==null){let e=je._zpp;je.bodyset=new e.util.ZPP_Set_ZPP_Body,je.bodyset.lt=je.bodysetlt,je.bodystack=new e.util.ZNPList_ZPP_Body;}}connectedBodies_cont(e){je.bodyset.try_insert_bool(e.zpp_inner)&&(je.bodystack.add(e.zpp_inner),e.zpp_inner.graph_depth=je.cur_graph_depth+1);}connectedBodies(e,t){let n=je._nape;je.bodyset==null&&this.init_bodysetlist();let s=t??new n.phys.BodyList;for(je.bodystack.add(this),je.bodyset.insert(this),this.graph_depth=0;je.bodystack.head!=null;){let l=je.bodystack.pop_unsafe();if(l.graph_depth===e)continue;je.cur_graph_depth=l.graph_depth;let r=l.constraints.head;for(;r!=null;)r.elt.outer.visitBodies(this.connectedBodies_cont.bind(this)),r=r.next;}let i=je.bodyset;if(i.parent!=null){let l=i.parent;for(;l!=null;)if(l.prev!=null)l=l.prev;else if(l.next!=null)l=l.next;else {let r=l.data;if(r!==this){let p=r.outer;s.zpp_inner.reverse_flag?s.push(p):s.unshift(p);}let o=l.parent;o!=null&&(l===o.prev?o.prev=null:o.next=null,l.parent=null);let a=l;a.data=null,a.lt=null,a.next=je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool,je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool=a,l=o;}i.parent=null;}return s}interactingBodies(e,t){let n=je._nape,s=je._zpp;je.bodyset==null&&this.init_bodysetlist();let i=t??new n.phys.BodyList,l=this.arbiters.head;for(;l!=null;){let o=l.elt;if(!o.sleeping&&(e===4||o.type===e)){let a=o.b1===this?o.b2:o.b1;if(je.bodyset.try_insert_bool(a)){let p=a.outer;i.zpp_inner.reverse_flag?i.push(p):i.unshift(p);}}l=l.next;}let r=je.bodyset;if(r.parent!=null){let o=r.parent;for(;o!=null;)if(o.prev!=null)o=o.prev;else if(o.next!=null)o=o.next;else {let a=o.parent;a!=null&&(o===a.prev?a.prev=null:a.next=null,o.parent=null);let p=o;p.data=null,p.lt=null,p.next=s.util.ZPP_Set_ZPP_Body.zpp_pool,s.util.ZPP_Set_ZPP_Body.zpp_pool=p,o=a;}r.parent=null;}return i}atRest(e){let t=je._nape;if(this.type!==2)return this.component.sleeping;let n=t.Config.linearSleepThreshold*t.Config.linearSleepThreshold,s;if(this.velx*this.velx+this.vely*this.vely>n)s=false;else {let i=this.posx-this.pre_posx,l=this.posy-this.pre_posy;if(i*i+l*l>.25*n*e*e)s=false;else {let r=this.aabb.maxx-this.aabb.minx,o=this.aabb.maxy-this.aabb.miny,a=r*r+o*o,p=t.Config.angularSleepThreshold*t.Config.angularSleepThreshold;if(4*this.angvel*this.angvel*a>p)s=false;else {let c=this.rot-this.pre_rot;s=!(c*c*a>p*e*e);}}}return s||(this.component.waket=this.space.stamp),this.component.waket+t.Config.sleepDelay<this.space.stamp}refreshArbiters(){let e=this.arbiters.head;for(;e!=null;){let t=e.elt;t.invalidated=true,e=e.next;}}sweepIntegrate(e){let t=e-this.sweepTime;if(t!==0&&(this.sweepTime=e,this.posx+=this.velx*t,this.posy+=this.vely*t,this.angvel!==0)){let n=this.sweep_angvel*t;if(this.rot+=n,n*n>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else {let s=n*n,i=1-.5*s,l=1-s*s/8,r=(i*this.axisx+n*this.axisy)*l;this.axisy=(i*this.axisy-n*this.axisx)*l,this.axisx=r;}}}sweepValidate(e){if(e.type===0)e.worldCOMx=this.posx+(this.axisy*e.localCOMx-this.axisx*e.localCOMy),e.worldCOMy=this.posy+(e.localCOMx*this.axisx+e.localCOMy*this.axisy);else {let t=e.polygon,n=t.lverts.next,s=t.gverts.next;for(;s!=null;){let p=s,c=n;n=n.next,p.x=this.posx+(this.axisy*c.x-this.axisx*c.y),p.y=this.posy+(c.x*this.axisx+c.y*this.axisy),s=s.next;}let i=t.edges.head,l=t.gverts.next,r=l;for(l=l.next;l!=null;){let p=l,c=i.elt;i=i.next,c.gnormx=this.axisy*c.lnormx-this.axisx*c.lnormy,c.gnormy=c.lnormx*this.axisx+c.lnormy*this.axisy,c.gprojection=this.posx*c.gnormx+this.posy*c.gnormy+c.lprojection,c.tp0=r.y*c.gnormx-r.x*c.gnormy,c.tp1=p.y*c.gnormx-p.x*c.gnormy,r=p,l=l.next;}let o=t.gverts.next,a=i.elt;a.gnormx=this.axisy*a.lnormx-this.axisx*a.lnormy,a.gnormy=a.lnormx*this.axisx+a.lnormy*this.axisy,a.gprojection=this.posx*a.gnormx+this.posy*a.gnormy+a.lprojection,a.tp0=r.y*a.gnormx-r.x*a.gnormy,a.tp1=o.y*a.gnormx-o.x*a.gnormy;}}invalidate_pos(){let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next;}this.zip_worldCOM=true;}pos_invalidate(e){if(this.immutable_midstep("Body::position"),this.type===1&&this.space!=null)throw new Error("Error: Cannot move a static object once inside a Space");this.posx===e.x&&this.posy===e.y||(this.posx=e.x,this.posy=e.y,this.invalidate_pos(),this.wake());}pos_validate(){this.wrap_pos.zpp_inner.x=this.posx,this.wrap_pos.zpp_inner.y=this.posy;}vel_invalidate(e){if(this.type===1)throw new Error("Error: Static body cannot have its velocity set.");this.velx=e.x,this.vely=e.y,this.wake();}vel_validate(){this.wrap_vel.zpp_inner.x=this.velx,this.wrap_vel.zpp_inner.y=this.vely;}kinvel_invalidate(e){this.kinvelx=e.x,this.kinvely=e.y,this.wake();}kinvel_validate(){this.wrap_kinvel.zpp_inner.x=this.kinvelx,this.wrap_kinvel.zpp_inner.y=this.kinvely;}svel_invalidate(e){this.svelx=e.x,this.svely=e.y,this.wake();}svel_validate(){this.wrap_svel.zpp_inner.x=this.svelx,this.wrap_svel.zpp_inner.y=this.svely;}force_invalidate(e){if(this.type!==2)throw new Error("Error: Non-dynamic body cannot have force applied.");this.forcex=e.x,this.forcey=e.y,this.wake();}force_validate(){this.wrap_force.zpp_inner.x=this.forcex,this.wrap_force.zpp_inner.y=this.forcey;}_setupVec2Wrapper(e,t,n,s){let i=je._nape;if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;if(xe.poolVec2==null?l=new i.geom.Vec2:(l=xe.poolVec2,xe.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=false,l===xe.nextVec2&&(xe.nextVec2=null)),l.zpp_inner==null){let r;ae.zpp_pool==null?r=new ae:(r=ae.zpp_pool,ae.zpp_pool=r.next,r.next=null),r.weak=false,r._immutable=false,r.x=e,r.y=t,l.zpp_inner=r,l.zpp_inner.outer=l;}else {if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let o;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x===e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),o=l.zpp_inner.y===t):o=false,o||(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner._invalidate!=null&&l.zpp_inner._invalidate(l.zpp_inner));}return l.zpp_inner.weak=false,l}setupPosition(){this.wrap_pos=this._setupVec2Wrapper(this.posx,this.posy,null,null),this.wrap_pos.zpp_inner._inuse=true,this.world?this.wrap_pos.zpp_inner._immutable=true:(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=true,this.world?this.wrap_vel.zpp_inner._immutable=true:(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=true,this.world?this.wrap_kinvel.zpp_inner._immutable=true:(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=true,this.world?this.wrap_svel.zpp_inner._immutable=true:(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=true,this.world?this.wrap_force.zpp_inner._immutable=true:(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=true,this.wrapcvel.zpp_inner._immutable=true,this.wrapcvel.zpp_inner._validate=this.cvel_validate.bind(this);}invalidate_rot(){this.zip_axis=true;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=true;}validate_axis(){this.zip_axis&&(this.zip_axis=false,this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot));}quick_validate_axis(){this.zip_axis&&(this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot));}delta_rot(e){if(e*e>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else {let t=e*e,n=1-.5*t,s=1-t*t/8,i=(n*this.axisx+e*this.axisy)*s;this.axisy=(n*this.axisy-e*this.axisx)*s,this.axisx=i;}this.zip_axis=false;}invalidate_mass(){this.zip_mass=true,this.invalidate_gravMass();}validate_mass(){if(this.zip_mass||this.massMode===0&&false){if(this.zip_mass=false,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=true),this.gravMassMode!==2&&(this.zip_gravMassScale=true),this.wake();}validate_gravMass(){this.zip_gravMass&&(this.zip_gravMass=false,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=true:this.invalidate_gravMass();}validate_gravMassScale(){this.zip_gravMassScale&&(this.zip_gravMassScale=false,this.gravMassMode===0?this.gravMassScale=1:this.gravMassMode===1&&(this.validate_mass(),this.gravMassScale=this.gravMass/this.cmass));}invalidate_inertia(){this.zip_inertia=true,this.wake();}validate_inertia(){if(this.zip_inertia||this.inertiaMode===0&&false){if(this.zip_inertia=false,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=true;}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=false,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=false,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=false,e.zip_localCOM&&(e.zip_localCOM=false,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=false,e.validate_lverts(),this.validate_axis();let s=e.lverts.next,i=e.gverts.next;for(;i!=null;){let l=i,r=s;s=s.next,l.x=e.body.posx+(e.body.axisy*r.x-e.body.axisx*r.y),l.y=e.body.posy+(r.x*e.body.axisx+r.y*e.body.axisy),i=i.next;}}if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let t=e.gverts.next;e.aabb.minx=t.x,e.aabb.miny=t.y,e.aabb.maxx=t.x,e.aabb.maxy=t.y;let n=e.gverts.next.next;for(;n!=null;){let s=n;s.x<e.aabb.minx&&(e.aabb.minx=s.x),s.x>e.aabb.maxx&&(e.aabb.maxx=s.x),s.y<e.aabb.miny&&(e.aabb.miny=s.y),s.y>e.aabb.maxy&&(e.aabb.maxy=s.y),n=n.next;}}aabb_validate(){if(this.shapes.head==null)throw new Error("Error: bounds only makes sense when Body has shapes");this.validate_aabb();}invalidate_localCOM(){this.zip_localCOM=true,this.zip_worldCOM=true;}invalidate_worldCOM(){this.zip_worldCOM=true;}_computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y,e.localCOMx+=e.lverts.next.next.x,e.localCOMy+=e.lverts.next.next.y,e.localCOMx*=.5,e.localCOMy*=.5;else {e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let p=n;t+=i.x*(p.y-s.y);let c=p.y*i.x-p.x*i.y;e.localCOMx+=(i.x+p.x)*c,e.localCOMy+=(i.y+p.y)*c,s=i,i=p,n=n.next;}n=e.lverts.next;let l=n;t+=i.x*(l.y-s.y);let r=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*r,e.localCOMy+=(i.y+l.y)*r,s=i,i=l,n=n.next;let o=n;t+=i.x*(o.y-s.y);let a=o.y*i.x-o.x*i.y;e.localCOMx+=(i.x+o.x)*a,e.localCOMy+=(i.y+o.y)*a,t=1/(3*t),e.localCOMx*=t,e.localCOMy*=t;}}validate_localCOM(){if(this.zip_localCOM){this.zip_localCOM=false;let e=0,t=0,n=0,s=this.shapes.head;for(;s!=null;){let i=s.elt;i.zip_localCOM&&(i.zip_localCOM=false,i.type===1&&this._computePolygonLocalCOM(i.polygon),i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)),i.validate_area_inertia();let l=i.area*i.material.density;e+=i.localCOMx*l,t+=i.localCOMy*l,n+=i.area*i.material.density,s=s.next;}if(n!==0){let i=1/n;this.localCOMx=e*i,this.localCOMy=t*i;}this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy),this.zip_mass&&this.massMode===0&&(this.zip_mass=false,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=false,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=true,this.zip_axis=true,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=true,this.axisx=0,this.axisy=1,this.zip_axis=false,this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.norotate=false,this.nomove=false;}shapes_adder(e){if(e.zpp_inner.body!==this){if(e.zpp_inner.body!=null&&e.zpp_inner.body.wrap_shapes.remove(e),e.zpp_inner.body=this,e.zpp_inner.addedToBody(),this.space!=null){let t=this.space,n=e.zpp_inner,s=n.body;s.world||(s.component.waket=t.stamp+(t.midstep?0:1),s.type===3&&(s.kinematicDelaySleep=true),s.component.sleeping&&t.really_wake(s,false)),t.bphase.insert(n),n.addedToSpace();}return e.zpp_inner.type===1&&(e.zpp_inner.polygon.invalidate_gaxi(),e.zpp_inner.polygon.invalidate_gverts()),true}else return false}shapes_subber(e){this.space!=null&&this.space.removed_shape(e.zpp_inner),e.zpp_inner.body=null,e.zpp_inner.removedFromBody();}shapes_invalidate(e){this.invalidate_shapes();}shapes_modifiable(){if(this.immutable_midstep("Body::shapes"),this.type===1&&this.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}addedToSpace(){let e=je._zpp,t;e.space.ZPP_Component.zpp_pool==null?t=new e.space.ZPP_Component:(t=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t.next,t.next=null),t.isBody=true,t.body=this,this.component=t,this.__iaddedToSpace();}removedFromSpace(){let e=je._zpp;for(;this.arbiters.head!=null;){let n=this.arbiters.pop_unsafe(),s=this.space;n.cleared=true,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=false,s.f_arbiters.modified=true;}let t=this.component;t.body=null,t.constraint=null,t.next=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t,this.component=null,this.__iremovedFromSpace();}_removeArbiterFromList(e,t,n){let s=null,i=e.head;for(;i!=null;){if(i.elt===t){let l;s==null?(l=e.head,e.head=l.next,e.head==null&&(e.pushmod=true)):(l=s.next,s.next=l.next,l.next==null&&(e.pushmod=true));let r=l;r.elt=null,r.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=r,e.modified=true,e.length--,e.pushmod=true;break}s=i,i=i.next;}}copy(){let e=je._nape,t=new e.phys.Body().zpp_inner;t.type=this.type,t.bulletEnabled=this.bulletEnabled,t.disableCCD=this.disableCCD;let n=this.shapes.head;for(;n!=null;){let s=n.elt,i=t.outer.zpp_inner.wrap_shapes,l=s.outer.copy();i.zpp_inner.reverse_flag?i.push(l):i.unshift(l),n=n.next;}if(t.posx=this.posx,t.posy=this.posy,t.velx=this.velx,t.vely=this.vely,t.forcex=this.forcex,t.forcey=this.forcey,t.rot=this.rot,t.angvel=this.angvel,t.torque=this.torque,t.kinvelx=this.kinvelx,t.kinvely=this.kinvely,t.kinangvel=this.kinangvel,t.svelx=this.svelx,t.svely=this.svely,!this.zip_axis)t.axisx=this.axisx,t.axisy=this.axisy;else {t.zip_axis=true;let s=t.shapes.head;for(;s!=null;){let i=s.elt;i.type===1&&(i.polygon.invalidate_gverts(),i.polygon.invalidate_gaxi()),i.invalidate_worldCOM(),s=s.next;}t.zip_worldCOM=true;}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=true:(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=true,t.zip_worldCOM=true):(t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy),this.zip_worldCOM?t.zip_worldCOM=true:(t.worldCOMx=this.worldCOMx,t.worldCOMy=this.worldCOMy),this.copyto(t.outer),t.outer}static _init(e,t){if(!je._initialized){je._initialized=true,je._zpp=e,je._nape=t;for(let n of Object.getOwnPropertyNames(Kt.prototype))n!=="constructor"&&!(n in je.prototype)&&(je.prototype[n]=Kt.prototype[n]);}}static _initEnums(e,t){let n=()=>{t.internal=true;let s=new e.phys.BodyType;return t.internal=false,s};t.BodyType_STATIC==null&&(t.BodyType_STATIC=n()),t.BodyType_DYNAMIC==null&&(t.BodyType_DYNAMIC=n()),t.BodyType_KINEMATIC==null&&(t.BodyType_KINEMATIC=n()),je.types=[null,t.BodyType_STATIC,t.BodyType_DYNAMIC,t.BodyType_KINEMATIC];}};je._nape=null,je._zpp=null,je.types=[],je.bodystack=null,je.bodyset=null,je.cur_graph_depth=0,je._initialized=false;var Mn=je;var tn=class tn{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.bodies=null;this.constraints=null;this.compounds=null;this.wrap_bodies=null;this.wrap_constraints=null;this.wrap_compounds=null;this.depth=0;this.compound=null;this.space=null;let e=tn._zpp;Kt.initFields(this),this.icompound=this,this.depth=1,this.bodies=new e.util.ZNPList_ZPP_Body,this.wrap_bodies=e.util.ZPP_BodyList.get(this.bodies),this.wrap_bodies.zpp_inner.adder=this.bodies_adder.bind(this),this.wrap_bodies.zpp_inner.subber=this.bodies_subber.bind(this),this.wrap_bodies.zpp_inner._modifiable=this.bodies_modifiable.bind(this),this.constraints=new e.util.ZNPList_ZPP_Constraint,this.wrap_constraints=e.util.ZPP_ConstraintList.get(this.constraints),this.wrap_constraints.zpp_inner.adder=this.constraints_adder.bind(this),this.wrap_constraints.zpp_inner.subber=this.constraints_subber.bind(this),this.wrap_constraints.zpp_inner._modifiable=this.constraints_modifiable.bind(this),this.compounds=new e.util.ZNPList_ZPP_Compound,this.wrap_compounds=e.util.ZPP_CompoundList.get(this.compounds),this.wrap_compounds.zpp_inner.adder=this.compounds_adder.bind(this),this.wrap_compounds.zpp_inner.subber=this.compounds_subber.bind(this),this.wrap_compounds.zpp_inner._modifiable=this.compounds_modifiable.bind(this);}__imutable_midstep(e){if(this.space!=null&&this.space.midstep)throw new Error("Error: "+e+" cannot be set during space step()")}addedToSpace(){this.__iaddedToSpace();}removedFromSpace(){this.__iremovedFromSpace();}breakApart(){for(this.space!=null&&(this.__iremovedFromSpace(),this.space.nullInteractorType(this)),this.compound!=null?this.compound.compounds.remove(this):this.space!=null&&this.space.compounds.remove(this);this.bodies.head!=null;){let e=this.bodies.pop_unsafe();(e.compound=this.compound)!=null?this.compound.bodies.add(e):this.space!=null&&this.space.bodies.add(e),this.space!=null&&this.space.freshInteractorType(e);}for(;this.constraints.head!=null;){let e=this.constraints.pop_unsafe();(e.compound=this.compound)!=null?this.compound.constraints.add(e):this.space!=null&&this.space.constraints.add(e);}for(;this.compounds.head!=null;){let e=this.compounds.pop_unsafe();(e.compound=this.compound)!=null?this.compound.compounds.add(e):this.space!=null&&this.space.compounds.add(e),this.space!=null&&this.space.freshInteractorType(e);}this.compound=null,this.space=null;}static _zppOf(e){return e.zpp_inner??e._inner?.zpp_inner??e._inner}bodies_adder(e){let t=tn._zppOf(e);return t.compound!==this?(t.compound!=null?t.compound.wrap_bodies.remove(e):t.space!=null&&t.space.wrap_bodies.remove(e),t.compound=this,this.space!=null&&this.space.addBody(t),true):false}bodies_subber(e){let t=tn._zppOf(e);t.compound=null,this.space!=null&&this.space.remBody(t);}bodies_modifiable(){this.immutable_midstep("Compound::bodies");}constraints_adder(e){let t=tn._zppOf(e);return t.compound!==this?(t.compound!=null?t.compound.wrap_constraints.remove(e):t.space!=null&&t.space.wrap_constraints.remove(e),t.compound=this,this.space!=null&&this.space.addConstraint(t),true):false}constraints_subber(e){let t=tn._zppOf(e);t.compound=null,this.space!=null&&this.space.remConstraint(t);}constraints_modifiable(){this.immutable_midstep("Compound::constraints");}compounds_adder(e){let t=tn._zppOf(e),n=this;for(;n!=null&&n!==t;)n=n.compound;if(n===t)throw new Error("Error: Assignment would cause a cycle in the Compound tree: assigning "+e.toString()+".compound = "+this.outer.toString());return t.compound!==this?(t.compound!=null?t.compound.wrap_compounds.remove(e):t.space!=null&&t.space.wrap_compounds.remove(e),t.compound=this,t.depth=this.depth+1,this.space!=null&&this.space.addCompound(t),true):false}compounds_subber(e){let t=tn._zppOf(e);t.compound=null,t.depth=1,this.space!=null&&this.space.remCompound(t);}compounds_modifiable(){this.immutable_midstep("Compound::compounds");}copy(e,t){let n=tn._nape,s=tn._zpp,i=e==null;e==null&&(e=[]),t==null&&(t=[]);let l=new n.phys.Compound,r=this.compounds.head;for(;r!=null;){let c=r.elt.copy(e,t);if(c.zpp_inner.immutable_midstep("Compound::compound"),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_compounds.remove(c),l!=null)){let h=l.zpp_inner.wrap_compounds;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c);}r=r.next;}let o=this.bodies.head;for(;o!=null;){let p=o.elt,c=p.outer.copy();if(e.push(s.constraint.ZPP_CopyHelper.dict(p.id,c)),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_bodies.remove(c),l!=null)){let h=l.zpp_inner.wrap_bodies;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c);}o=o.next;}let a=this.constraints.head;for(;a!=null;){let c=a.elt.copy(e,t);if((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_constraints.remove(c),l!=null)){let h=l.zpp_inner.wrap_constraints;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c);}a=a.next;}if(i)for(;t.length>0;){let p=t.pop();for(let c=0;c<e.length;c++){let h=e[c];if(h.id===p.id){p.cb(h.bc);break}}}return this.copyto(l),l}static _init(){for(let e of Object.getOwnPropertyNames(Kt.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(tn.prototype,e)&&(tn.prototype[e]=Kt.prototype[e]);}};tn._nape=null,tn._zpp=null,tn._wrapFn=null;var Wn=tn;var jt=class jt{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 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.phys.FluidProperties;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.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=jt._zpp,t=jt._nape,n=this.gravityx??0,s=this.gravityy??0;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=false,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=false,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i;}else {if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let r=false;l._validate!=null&&l._validate(),(l.x!==n||l.y!==s)&&(r=true),r&&(l.x=n,l.y=s,l._invalidate!=null&&l._invalidate(l));}i.zpp_inner.weak=false,this.wrap_gravity=i,this.wrap_gravity.zpp_inner._inuse=true,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;}};jt.zpp_pool=null,jt._nape=null,jt._zpp=null,jt._wrapFn=null;var Zn=jt;var Gt=class Gt{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 Gt._zpp.util.ZNPList_ZPP_Shape;}wrapper(){if(this.outer==null)if(Gt._wrapFn)this.outer=Gt._wrapFn(this);else {this.outer=new Gt._nape.phys.Material;let e=this.outer.zpp_inner;e.outer=null,e.next=Gt.zpp_pool,Gt.zpp_pool=e,this.outer.zpp_inner=this;}return this.outer}free(){this.outer=null;}alloc(){}feature_cons(){this.shapes=new Gt._zpp.util.ZNPList_ZPP_Shape;}addShape(e){this.shapes.add(e);}remShape(e){this.shapes.remove(e);}copy(){let e=new Gt;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;}};Gt.zpp_pool=null,Gt.WAKE=1,Gt.PROPS=2,Gt.ANGDRAG=4,Gt.ARBITERS=8,Gt._nape=null,Gt._zpp=null,Gt._wrapFn=null;var Oe=Gt;var kn=class kn{constructor(e){this.outer=null;this.body=null;this.type=0;this.area=0;this.zip_area_inertia=false;this.inertia=0;this.angDrag=0;this.zip_angDrag=false;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=false;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=false;this.wrap_localCOM=null;this.wrap_worldCOM=null;this.sweepRadius=0;this.zip_sweepRadius=false;this.sweepCoef=0;this.circle=null;this.polygon=null;this.refmaterial=null;this.material=null;this.filter=null;this.fluidProperties=null;this.fluidEnabled=false;this.sensorEnabled=false;this.sweep=null;this.node=null;this.pairs=null;this.aabb=null;this.zip_aabb=false;this.ishape=null;this.userData=null;e!==void 0&&this._initShape(e);}static _initEnums(e,t){let n=()=>{t.internal=true;let s=new e.shape.ShapeType;return t.internal=false,s};t.ShapeType_CIRCLE==null&&(t.ShapeType_CIRCLE=n()),t.ShapeType_POLYGON==null&&(t.ShapeType_POLYGON=n()),t.ShapeType_CAPSULE==null&&(t.ShapeType_CAPSULE=n()),kn.types=[t.ShapeType_CIRCLE,t.ShapeType_POLYGON,t.ShapeType_CAPSULE];}_initShape(e){let t=kn._zpp;Kt.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=true,this.aabb._validate=this.aabb_validate.bind(this),this.zip_area_inertia=this.zip_angDrag=this.zip_localCOM=this.zip_sweepRadius=true,this.localCOMx=0,this.localCOMy=0,this.worldCOMx=0,this.worldCOMy=0,this.fluidEnabled=false,this.sensorEnabled=false,this.fluidProperties=null,this.body=null,this.refmaterial=new Oe,this.sweepRadius=this.sweepCoef=0;}static _init(){if(!kn._initialized){kn._initialized=true;for(let e of Object.getOwnPropertyNames(Kt.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(kn.prototype,e)&&(kn.prototype[e]=Kt.prototype[e]);}}isCircle(){return this.type===0}isPolygon(){return this.type===1}isCapsule(){return !!this._isCapsule}invalidate_sweepRadius(){this.zip_sweepRadius=true;}validate_sweepRadius(){this.zip_sweepRadius&&(this.zip_sweepRadius=false,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=false,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=true,this.body!=null&&(this.body.zip_aabb=true);}validate_area_inertia(){this.zip_area_inertia&&(this.zip_area_inertia=false,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=false,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=false,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=false,this.validate_localCOM();let e=this.body;e.zip_axis&&(e.zip_axis=false,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=true,this.body!=null&&(this.body.zip_localCOM=true,this.body.zip_worldCOM=true,this.body.invalidate_mass(),this.body.invalidate_inertia());}invalidate_angDrag(){this.zip_angDrag=true;}invalidate_localCOM(){this.zip_localCOM=true,this.invalidate_area_inertia(),this.type===0&&(this.zip_sweepRadius=true),this.invalidate_angDrag(),this.invalidate_worldCOM(),this.body!=null&&(this.body.zip_localCOM=true,this.body.zip_worldCOM=true);}invalidate_worldCOM(){this.zip_worldCOM=true,this.zip_aabb=true,this.body!=null&&(this.body.zip_aabb=true);}invalidate_material(e){(e&Oe.WAKE)!==0&&this.wake(),(e&Oe.ARBITERS)!==0&&this.body!=null&&this.body.refreshArbiters(),(e&Oe.PROPS)!==0&&this.body!=null&&(this.body.zip_localCOM=true,this.body.zip_worldCOM=true,this.body.invalidate_mass(),this.body.invalidate_inertia()),(e&Oe.ANGDRAG)!==0&&this.invalidate_angDrag(),this.refmaterial.set(this.material);}invalidate_filter(){this.wake();}invalidate_fluidprops(){this.fluidEnabled&&this.wake();}aabb_validate(){if(this.body==null)throw new Error("Error: bounds only makes sense when Shape belongs to a Body");this.validate_aabb();}setMaterial(e){this.material!==e&&(this.body!=null&&this.body.space!=null&&this.material!=null&&this.material.shapes.remove(this),this.material=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake(),this.body!=null&&this.body.refreshArbiters());}setFilter(e){this.filter!==e&&(this.body!=null&&this.body.space!=null&&this.filter!=null&&this.filter.shapes.remove(this),this.filter=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake());}setFluid(e){this.fluidProperties!==e&&(this.body!=null&&this.body.space!=null&&this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this),this.fluidProperties=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.fluidEnabled&&this.wake());}__immutable_midstep(e){if(this.body!=null&&this.body.space!=null&&this.body.space.midstep)throw new Error("Error: "+e+" cannot be set during a space step()")}addedToBody(){this.invalidate_worldCOM(),this.zip_aabb=true,this.body!=null&&(this.body.zip_aabb=true);}removedFromBody(){}addedToSpace(){this.__iaddedToSpace(),this.material.shapes.add(this),this.filter.shapes.add(this),this.fluidProperties!=null&&this.fluidProperties.shapes.add(this);}removedFromSpace(){this.__iremovedFromSpace(),this.material.shapes.remove(this),this.filter.shapes.remove(this),this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this);}copy(){let e=kn._zpp,t=this.type===0?this.circle.__copy():this.polygon.__copy();this.zip_area_inertia?t.invalidate_area_inertia():(t.area=this.area,t.inertia=this.inertia),this.zip_sweepRadius?t.zip_sweepRadius=true:(t.sweepRadius=this.sweepRadius,t.sweepCoef=this.sweepCoef),this.zip_angDrag?t.invalidate_angDrag():t.angDrag=this.angDrag,this.zip_aabb?(t.zip_aabb=true,t.body!=null&&(t.body.zip_aabb=true)):(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy);let n=t.material;n.outer=null,n.next=Oe.zpp_pool,Oe.zpp_pool=n;let s=t.filter;return s.outer=null,s.next=e.dynamics.ZPP_InteractionFilter.zpp_pool,e.dynamics.ZPP_InteractionFilter.zpp_pool=s,t.material=this.material,t.filter=this.filter,this.fluidProperties!=null&&(t.fluidProperties=this.fluidProperties),t.fluidEnabled=this.fluidEnabled,t.sensorEnabled=this.sensorEnabled,this.userData!=null&&(t.userData=Object.assign({},this.userData)),this.copyto(t.outer),t.outer}};kn._nape=null,kn._zpp=null,kn.types=[],kn._initialized=false;var li=kn;var En=class En{constructor(){this.radius=0;this.outer_zn=null;this.radius=0,this.outer_zn=null,this._initShape(0),this.circle=this,this.zip_localCOM=false;}static _init(){if(En._initialized)return;En._initialized=true;let t=En._zpp.shape.ZPP_Shape.prototype,n=En.prototype;for(let s in t)Object.prototype.hasOwnProperty.call(n,s)||(n[s]=t[s]);for(let s of Object.getOwnPropertyNames(t))s!=="constructor"&&!Object.prototype.hasOwnProperty.call(n,s)&&(n[s]=t[s]);}__clear(){}invalidate_radius(){this.invalidate_area_inertia(),this.invalidate_angDrag(),this.zip_aabb=true,this.body!=null&&(this.body.zip_aabb=true),this.body!=null&&this.body.wake();}localCOM_validate(){this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy;}localCOM_invalidate(e){this.localCOMx=e.x,this.localCOMy=e.y,this.invalidate_localCOM(),this.body!=null&&this.body.wake();}localCOM_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify localCOM of Circle added to a static Body whilst within a Space")}setupLocalCOM(){let e=En._zpp,t=En._nape,n=this.localCOMx,s=this.localCOMy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=false,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=false,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i;}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=false,this.wrap_localCOM=i,this.wrap_localCOM.zpp_inner._inuse=true,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=false,this.zip_localCOM&&(this.zip_localCOM=false,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=false,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),this.worldCOMx=n.posx+(n.axisy*this.localCOMx-n.axisx*this.localCOMy),this.worldCOMy=n.posy+(this.localCOMx*n.axisx+this.localCOMy*n.axisy);}let e=this.radius,t=this.radius;this.aabb.minx=this.worldCOMx-e,this.aabb.miny=this.worldCOMy-t,this.aabb.maxx=this.worldCOMx+e,this.aabb.maxy=this.worldCOMy+t;}_force_validate_aabb(){let e=this.body;this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy),this.aabb.minx=this.worldCOMx-this.radius,this.aabb.miny=this.worldCOMy-this.radius,this.aabb.maxx=this.worldCOMx+this.radius,this.aabb.maxy=this.worldCOMy+this.radius;}__validate_sweepRadius(){this.sweepCoef=Math.sqrt(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy),this.sweepRadius=this.sweepCoef+this.radius;}__validate_area_inertia(){let e=this.radius*this.radius;this.area=e*Math.PI,this.inertia=e*.5+(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy);}__validate_angDrag(){let e=En._nape,t=this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy,n=this.radius*this.radius,s=this.material.dynamicFriction*e.Config.fluidAngularDragFriction;this.angDrag=(t+2*n)*s+.5*e.Config.fluidAngularDrag*(1+e.Config.fluidVacuumDrag)*t,this.angDrag/=2*(t+.5*n);}__scale(e,t){let n=((e<0?-e:e)+(t<0?-t:t))/2;this.radius*=n<0?-n:n,this.invalidate_radius(),this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0&&(this.localCOMx*=e,this.localCOMy*=t,this.invalidate_localCOM());}__translate(e,t){this.localCOMx+=e,this.localCOMy+=t,this.invalidate_localCOM();}__rotate(e,t){if(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0){let n=t*this.localCOMx-e*this.localCOMy,s=this.localCOMx*e+this.localCOMy*t;this.localCOMx=n,this.localCOMy=s,this.invalidate_localCOM();}}__transform(e){let t=e.zpp_inner.a*e.zpp_inner.d-e.zpp_inner.b*e.zpp_inner.c;t<0&&(t=-t),this.radius*=Math.sqrt(t);let n=e.zpp_inner.a*this.localCOMx+e.zpp_inner.b*this.localCOMy+e.zpp_inner.tx;this.localCOMy=e.zpp_inner.c*this.localCOMx+e.zpp_inner.d*this.localCOMy+e.zpp_inner.ty,this.localCOMx=n,this.invalidate_radius(),this.invalidate_localCOM();}__copy(){let e=En._nape,t=new e.shape.Circle(this.radius).zpp_inner_zn;return t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy,t.zip_localCOM=false,t}};En._nape=null,En._zpp=null,En._initialized=false;var Xn=En;var nn=class nn{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&&(nn._wrapFn?this.outer=nn._wrapFn(this):(nn.internal=true,this.outer=new nn._nape.shape.Edge,nn.internal=false,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=nn._zpp,t=nn._nape,n=this.lnormx,s=this.lnormy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=false,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=false,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i;}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=false,this.wrap_lnorm=i,this.wrap_lnorm.zpp_inner._immutable=true,this.wrap_lnorm.zpp_inner._validate=this.lnorm_validate.bind(this);}getgnorm(){let e=nn._zpp,t=nn._nape,n=this.gnormx,s=this.gnormy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=false,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=false,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i;}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=false,this.wrap_gnorm=i,this.wrap_gnorm.zpp_inner._immutable=true,this.wrap_gnorm.zpp_inner._validate=this.gnorm_validate.bind(this);}};nn.zpp_pool=null,nn.internal=false,nn._nape=null,nn._zpp=null,nn._wrapFn=null;var rt=nn;var mt=class mt{constructor(){this.outer_zn=null;this.lverts=null;this.wrap_lverts=null;this.gverts=null;this.wrap_gverts=null;this.edges=null;this.wrap_edges=null;this.edgeCnt=0;this.reverse_flag=false;this.zip_lverts=false;this.zip_laxi=false;this.zip_gverts=false;this.zip_gaxi=false;this.zip_valid=false;this.zip_sanitation=false;this.validation=null;this.zip_sanitation=false,this.zip_valid=false,this.zip_gaxi=false,this.zip_gverts=false,this.zip_laxi=false,this.zip_lverts=false,this.reverse_flag=false,this.edgeCnt=0,this.wrap_edges=null,this.edges=null,this.wrap_gverts=null,this.gverts=null,this.wrap_lverts=null,this.lverts=null,this.outer_zn=null;let e=mt._zpp;this._initShape(1),this.polygon=this,this.lverts=new e.geom.ZPP_Vec2,this.gverts=new e.geom.ZPP_Vec2,this.edges=new e.util.ZNPList_ZPP_Edge,this.edgeCnt=0;}static _init(){if(mt._initialized)return;mt._initialized=true;let t=mt._zpp.shape.ZPP_Shape.prototype,n=mt.prototype;for(let s in t)Object.prototype.hasOwnProperty.call(n,s)||(n[s]=t[s]);for(let s of Object.getOwnPropertyNames(t))s!=="constructor"&&!Object.prototype.hasOwnProperty.call(n,s)&&(n[s]=t[s]);}__clear(){}lverts_pa_invalidate(e){this.invalidate_lverts();}lverts_pa_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify local vertex of Polygon added to a static body whilst within a Space")}gverts_pa_validate(){if(this.body==null)throw new Error("Error: World vertex only makes sense when Polygon is contained in a rigid body");this._validateGverts();}lverts_post_adder(e){let t=mt._zpp;e.zpp_inner._invalidate=this.lverts_pa_invalidate.bind(this),e.zpp_inner._isimmutable=this.lverts_pa_immutable.bind(this);let n=null,s=null,i=this.lverts.next;for(;i!=null&&i!==e.zpp_inner;)n=n==null?this.gverts.next:n.next,s=s==null?this.edges.head:s.next,i=i.next;let l;if(t.geom.ZPP_Vec2.zpp_pool==null?l=new t.geom.ZPP_Vec2:(l=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=true,l.x=0,l.y=0,this.gverts.insert(n,l),this.lverts.next.next!=null)if(this.lverts.next.next.next==null){let r;rt.zpp_pool==null?r=new rt:(r=rt.zpp_pool,rt.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.add(r);let o;rt.zpp_pool==null?o=new rt:(o=rt.zpp_pool,rt.zpp_pool=o.next,o.next=null),o.polygon=this,this.edges.add(o),this.edgeCnt+=2;}else {let r;rt.zpp_pool==null?r=new rt:(r=rt.zpp_pool,rt.zpp_pool=r.next,r.next=null),r.polygon=this,this.edges.insert(s,r),this.edgeCnt++;}l._validate=this.gverts_pa_validate.bind(this);}lverts_subber(e){this.cleanup_lvert(e.zpp_inner);}lverts_invalidate(e){this.invalidate_lverts();}lverts_validate(){this.validate_lverts();}lverts_modifiable(){if(this.immutable_midstep("Polygon::localVerts"),this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}gverts_validate(){this._validateGverts();}edges_validate(){this.validate_lverts();}getlverts(){let e=mt._zpp;this.wrap_lverts=e.util.ZPP_MixVec2List.get(this.lverts),this.wrap_lverts.zpp_inner.post_adder=this.lverts_post_adder.bind(this),this.wrap_lverts.zpp_inner.subber=this.lverts_subber.bind(this),this.wrap_lverts.zpp_inner._invalidate=this.lverts_invalidate.bind(this),this.wrap_lverts.zpp_inner._validate=this.lverts_validate.bind(this),this.wrap_lverts.zpp_inner._modifiable=this.lverts_modifiable.bind(this),this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag;}getgverts(){let e=mt._zpp;this.wrap_gverts=e.util.ZPP_MixVec2List.get(this.gverts,true),this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag,this.wrap_gverts.zpp_inner._validate=this.gverts_validate.bind(this);}getedges(){let e=mt._zpp;this.wrap_edges=e.util.ZPP_EdgeList.get(this.edges,true),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=true,this.zip_valid=true,this.zip_sanitation=true,this.body!=null&&this.body.wake();}invalidate_laxi(){this.invalidate_gaxi(),this.zip_sweepRadius=true,this.zip_laxi=true;}invalidate_gverts(){this.zip_aabb=true,this.body!=null&&(this.body.zip_aabb=true),this.zip_gverts=true;}invalidate_gaxi(){this.zip_gaxi=true;}validate_lverts(){this.zip_lverts&&(this.zip_lverts=false,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=false,this.validate_lverts();let t=this.edges.head,n=this.lverts.next,s=n;for(n=n.next;n!=null;){let h=n,u=t.elt;t=t.next,u.lp0=s,u.lp1=h;let x=s.x-h.x,m=s.y-h.y,_=Math.sqrt(x*x+m*m);u.length=_;let y=1/_;x*=y,m*=y;let z=x;x=-m,m=z,u.lprojection=x*s.x+m*s.y,u.lnormx=x,u.lnormy=m,u.wrap_lnorm!=null&&(u.wrap_lnorm.zpp_inner.x=x,u.wrap_lnorm.zpp_inner.y=m),s=h,n=n.next;}let i=this.lverts.next,l=t.elt;l.lp0=s,l.lp1=i;let r=s.x-i.x,o=s.y-i.y,a=Math.sqrt(r*r+o*o);l.length=a;let p=1/a;r*=p,o*=p;let c=r;r=-o,o=c,l.lprojection=r*s.x+o*s.y,l.lnormx=r,l.lnormy=o,l.wrap_lnorm!=null&&(l.wrap_lnorm.zpp_inner.x=r,l.wrap_lnorm.zpp_inner.y=o);}}validate_gverts(){this._validateGverts();}validate_gaxi(){if(this.zip_gaxi&&this.body!=null){this.zip_gaxi=false,this.validate_laxi();let e=this.body;e.zip_axis&&(e.zip_axis=false,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this._validateGverts();let t=this.edges.head,n=this.gverts.next,s=n;for(n=n.next;n!=null;){let r=n,o=t.elt;t=t.next,o.gp0=s,o.gp1=r,o.gnormx=e.axisy*o.lnormx-e.axisx*o.lnormy,o.gnormy=o.lnormx*e.axisx+o.lnormy*e.axisy,o.gprojection=e.posx*o.gnormx+e.posy*o.gnormy+o.lprojection,o.wrap_gnorm!=null&&(o.wrap_gnorm.zpp_inner.x=o.gnormx,o.wrap_gnorm.zpp_inner.y=o.gnormy),o.tp0=o.gp0.y*o.gnormx-o.gp0.x*o.gnormy,o.tp1=o.gp1.y*o.gnormx-o.gp1.x*o.gnormy,s=r,n=n.next;}let i=this.gverts.next,l=t.elt;l.gp0=s,l.gp1=i,l.gnormx=e.axisy*l.lnormx-e.axisx*l.lnormy,l.gnormy=l.lnormx*e.axisx+l.lnormy*e.axisy,l.gprojection=e.posx*l.gnormx+e.posy*l.gnormy+l.lprojection,l.wrap_gnorm!=null&&(l.wrap_gnorm.zpp_inner.x=l.gnormx,l.wrap_gnorm.zpp_inner.y=l.gnormy),l.tp0=l.gp0.y*l.gnormx-l.gp0.x*l.gnormy,l.tp1=l.gp1.y*l.gnormx-l.gp1.x*l.gnormy;}}_validateGverts(){if(this.zip_gverts&&this.body!=null){this.zip_gverts=false,this.validate_lverts();let e=this.body;e.zip_axis&&(e.zip_axis=false,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let t=this.lverts.next,n=this.gverts.next;for(;n!=null;){let s=n,i=t;t=t.next,s.x=e.posx+(e.axisy*i.x-e.axisx*i.y),s.y=e.posy+(i.x*e.axisx+i.y*e.axisy),n=n.next;}}}cleanup_lvert(e){let t=mt._zpp,n=null,s=null,i=this.lverts.next;for(;i!=null&&i!==e;)n=n==null?this.gverts.next:n.next,s=s==null?this.edges.head:s.next,i=i.next;let l=n==null?this.gverts.next:n.next;this.gverts.erase(n);let r=l;if(r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=r,this.edgeCnt===2){let o=this.edges.pop_unsafe();o.polygon=null,o.next=rt.zpp_pool,rt.zpp_pool=o,o=this.edges.pop_unsafe(),o.polygon=null,o.next=rt.zpp_pool,rt.zpp_pool=o,this.edgeCnt=0;}else if(this.edgeCnt!==0){let o=s==null?this.edges.head.elt:s.next.elt;this.edges.erase(s),o.polygon=null,o.next=rt.zpp_pool,rt.zpp_pool=o,this.edgeCnt--;}}splice_collinear(){this.zip_sanitation&&(this.zip_sanitation=false,this.splice_collinear_real());}splice_collinear_real(){let e=mt._nape;if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)return;let t=null,n=this.lverts.next;for(;n!=null;){let i=n.next==null?this.lverts.next:n.next,l=n.x-i.x,r=n.y-i.y;l*l+r*r<e.Config.epsilon*e.Config.epsilon?(this.cleanup_lvert(n),n=this.lverts.erase(t)):(t=n,n=n.next);}if(this.lverts.next==null)return;let s;for(;;){s=false;let i=this.lverts.next;for(;i!=null;){let l=i.next==null?this.lverts.next:i.next,r=l.next==null?this.lverts.next:l.next,o=l.x-i.x,a=l.y-i.y,p=r.x-l.x,h=(r.y-l.y)*o-p*a;h*h>=e.Config.epsilon*e.Config.epsilon||(this.cleanup_lvert(l),this.lverts.erase(i.next==null?null:i),s=true),i=i.next;}if(!s)break}}reverse_vertices(){this.lverts.reverse(),this.gverts.reverse(),this.edges.reverse();let e=this.edges.iterator_at(this.edgeCnt-1),t=this.edges.pop_unsafe();this.edges.insert(e,t),this.reverse_flag=!this.reverse_flag,this.wrap_lverts!=null&&(this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_gverts!=null&&(this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_edges!=null&&(this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag);}valid(){let e=mt._nape,t=mt._zpp;if(this.zip_valid){if(this.zip_valid=false,this.zip_sanitation&&(this.zip_sanitation=false,this.splice_collinear_real()),this.lverts.length<3)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=true,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=false),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=true,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=false),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;{let n=false,s=false,i=true,l=this.lverts.next,r=l;l=l.next;let o=l;for(l=l.next;l!=null;){let a=l,p=a.x-o.x,c=a.y-o.y,h=o.x-r.x,x=(o.y-r.y)*p-h*c;if(x>e.Config.epsilon?s=true:x<-e.Config.epsilon&&(n=true),s&&n){i=false;break}r=o,o=a,l=l.next;}if(i){l=this.lverts.next;let a=l,p=a.x-o.x,c=a.y-o.y,h=o.x-r.x,x=(o.y-r.y)*p-h*c;if(x>e.Config.epsilon?s=true:x<-e.Config.epsilon&&(n=true),!(s&&n)){r=o,o=a,l=l.next;let m=l,_=m.x-o.x,y=m.y-o.y,z=o.x-r.x,w=(o.y-r.y)*_-z*y;w>e.Config.epsilon?s=true:w<-e.Config.epsilon&&(n=true);}}if(s&&n)return t.util.ZPP_Flags.ValidationResult_CONCAVE==null&&(t.util.ZPP_Flags.internal=true,t.util.ZPP_Flags.ValidationResult_CONCAVE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=false),this.validation=t.util.ZPP_Flags.ValidationResult_CONCAVE;{let a=true,p=this.lverts.next,c=p;for(p=p.next;p!=null&&a;){let h=p,u=this.lverts.next,x=u.next;for(;x!=null&&a;){let m=x;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,x=x.next;}if(a){let m=this.lverts.next;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e));}c=h,p=p.next;}if(a){let h=this.lverts.next,u=this.lverts.next,x=u.next;for(;x!=null&&a;){let m=x;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,x=x.next;}if(a){let m=this.lverts.next;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e));}}return a?(t.util.ZPP_Flags.ValidationResult_VALID==null&&(t.util.ZPP_Flags.internal=true,t.util.ZPP_Flags.ValidationResult_VALID=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=false),this.validation=t.util.ZPP_Flags.ValidationResult_VALID):(t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING==null&&(t.util.ZPP_Flags.internal=true,t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=false),this.validation=t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING)}}}else return this.validation}_checkNoIntersection(e,t,n,s,i){let l=e.x-n.x,r=e.y-n.y,o=t.x-e.x,a=t.y-e.y,p=s.x-n.x,c=s.y-n.y,h=a*p-o*c;if(h*h>i.Config.epsilon){h=1/h;let u=(c*l-p*r)*h;if(u>i.Config.epsilon&&u<1-i.Config.epsilon){let x=(a*l-o*r)*h;if(x>i.Config.epsilon&&x<1-i.Config.epsilon)return false}}return true}__validate_aabb(){if(this._validateGverts(),this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let e=this.gverts.next;this.aabb.minx=e.x,this.aabb.miny=e.y,this.aabb.maxx=e.x,this.aabb.maxy=e.y;let t=this.gverts.next.next;for(;t!=null;){let n=t;n.x<this.aabb.minx&&(this.aabb.minx=n.x),n.x>this.aabb.maxx&&(this.aabb.maxx=n.x),n.y<this.aabb.miny&&(this.aabb.miny=n.y),n.y>this.aabb.maxy&&(this.aabb.maxy=n.y),t=t.next;}}_force_validate_aabb(){let e=this.body,t=this.lverts.next,n=this.gverts.next,s=t;t=t.next,n.x=e.posx+(e.axisy*s.x-e.axisx*s.y),n.y=e.posy+(s.x*e.axisx+s.y*e.axisy),this.aabb.minx=n.x,this.aabb.miny=n.y,this.aabb.maxx=n.x,this.aabb.maxy=n.y;let i=this.gverts.next.next;for(;i!=null;){let l=i,r=t;t=t.next,l.x=e.posx+(e.axisy*r.x-e.axisx*r.y),l.y=e.posy+(r.x*e.axisx+r.y*e.axisy),l.x<this.aabb.minx&&(this.aabb.minx=l.x),l.x>this.aabb.maxx&&(this.aabb.maxx=l.x),l.y<this.aabb.miny&&(this.aabb.miny=l.y),l.y>this.aabb.maxy&&(this.aabb.maxy=l.y),i=i.next;}}__validate_sweepRadius(){let e=0,t=0;this.validate_laxi();let n=this.lverts.next;for(;n!=null;){let i=n,l=i.x*i.x+i.y*i.y;l>e&&(e=l),n=n.next;}let s=this.edges.head;for(;s!=null;){let i=s.elt;if(i.lprojection<t&&(t=i.lprojection,t<0))break;s=s.next;}t<0&&(t=0),this.sweepRadius=Math.sqrt(e),this.sweepCoef=this.sweepRadius-t;}__validate_area_inertia(){if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)this.area=0,this.inertia=0;else {this.area=0;let e=0,t=0,n=this.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let p=n,c=i.y*s.x-i.x*s.y,h=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y);e+=c*h,t+=c,this.area+=i.x*(p.y-s.y),s=i,i=p,n=n.next;}n=this.lverts.next;let l=n,r=i.y*s.x-i.x*s.y,o=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y);e+=r*o,t+=r,this.area+=i.x*(l.y-s.y),s=i,i=l,n=n.next;let a=n;r=i.y*s.x-i.x*s.y,o=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y),e+=r*o,t+=r,this.area+=i.x*(a.y-s.y),this.inertia=e/(6*t),this.area*=.5,this.area<0&&(this.area=-this.area,this.reverse_vertices());}}__validate_angDrag(){let e=mt._nape;if(this.lverts.length<3)throw new Error("Error: Polygon's with less than 3 vertices have no meaningful angDrag");this.validate_area_inertia(),this.validate_laxi();let t=0,n=this.edges.head,s=0,i=this.lverts.next,l=i,r=i.next;for(;r!=null;){let o=r,a=n.elt;n=n.next,s+=a.length;let p=o.x-l.x,c=o.y-l.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let h=-(l.y*a.lnormx-l.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(h>0){let u=h>1?1:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let _=a.lnormy*l.x-a.lnormx*l.y,y=a.lnormy*x-a.lnormx*m,z=(y*y*y-_*_*_)/(3*(y-_));t+=z*u*a.length*e.Config.fluidAngularDrag;}if(h<1){let u=h<0?0:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let _=a.lnormy*x-a.lnormx*m,y=a.lnormy*o.x-a.lnormx*o.y,z=(y*y*y-_*_*_)/(3*(y-_));t+=z*e.Config.fluidVacuumDrag*(1-u)*a.length*e.Config.fluidAngularDrag;}l=o,r=r.next;}{let o=this.lverts.next,a=n.elt;s+=a.length;let p=o.x-l.x,c=o.y-l.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let h=-(l.y*a.lnormx-l.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(h>0){let u=h>1?1:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let _=a.lnormy*l.x-a.lnormx*l.y,y=a.lnormy*x-a.lnormx*m,z=(y*y*y-_*_*_)/(3*(y-_));t+=z*u*a.length*e.Config.fluidAngularDrag;}if(h<1){let u=h<0?0:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let _=a.lnormy*x-a.lnormx*m,y=a.lnormy*o.x-a.lnormx*o.y,z=(y*y*y-_*_*_)/(3*(y-_));t+=z*e.Config.fluidVacuumDrag*(1-u)*a.length*e.Config.fluidAngularDrag;}}this.angDrag=t/(this.inertia*s);}__validate_localCOM(){if(this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(this.lverts.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y;else if(this.lverts.next.next.next==null)this.localCOMx=this.lverts.next.x,this.localCOMy=this.lverts.next.y,this.localCOMx+=this.lverts.next.next.x,this.localCOMy+=this.lverts.next.next.y,this.localCOMx*=.5,this.localCOMy*=.5;else {this.localCOMx=0,this.localCOMy=0;let e=0,t=this.lverts.next,n=t;t=t.next;let s=t;for(t=t.next;t!=null;){let o=t;e+=s.x*(o.y-n.y);let a=o.y*s.x-o.x*s.y;this.localCOMx+=(s.x+o.x)*a,this.localCOMy+=(s.y+o.y)*a,n=s,s=o,t=t.next;}t=this.lverts.next;let i=t;e+=s.x*(i.y-n.y);let l=i.y*s.x-i.x*s.y;this.localCOMx+=(s.x+i.x)*l,this.localCOMy+=(s.y+i.y)*l,n=s,s=i,t=t.next;let r=t;e+=s.x*(r.y-n.y),l=r.y*s.x-r.x*s.y,this.localCOMx+=(s.x+r.x)*l,this.localCOMy+=(s.y+r.y)*l,e=1/(3*e),this.localCOMx*=e,this.localCOMy*=e;}}localCOM_validate(){if(this.lverts.next==null)throw new Error("Error: An empty polygon does not have any meaningful localCOM");this.validate_localCOM();}localCOM_invalidate(e){this.validate_localCOM();let t=e.x-this.localCOMx,n=e.y-this.localCOMy,s=this.lverts.next;for(;s!=null;)s.x+=t,s.y+=n,s=s.next;this.invalidate_lverts();}setupLocalCOM(){let e=mt._zpp,t=mt._nape,n=this.localCOMx,s=this.localCOMy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=false,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=false,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i;}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=false,this.wrap_localCOM=i,this.wrap_localCOM.zpp_inner._inuse=true,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this);}__translate(e,t){let n=this.lverts.next;for(;n!=null;)n.x+=e,n.y+=t,n=n.next;this.invalidate_lverts();}__scale(e,t){let n=this.lverts.next;for(;n!=null;)n.x*=e,n.y*=t,n=n.next;this.invalidate_lverts();let s=this;if(s._isCapsule){let i=((e<0?-e:e)+(t<0?-t:t))/2;s._capsuleRadius*=i,s._capsuleHalfLength*=i;}}__rotate(e,t){let n=this.lverts.next;for(;n!=null;){let s=t*n.x-e*n.y,i=n.x*e+n.y*t;n.x=s,n.y=i,n=n.next;}this.invalidate_lverts();}__transform(e){let t=this.lverts.next;for(;t!=null;){let n=e.zpp_inner.a*t.x+e.zpp_inner.b*t.y+e.zpp_inner.tx;t.y=e.zpp_inner.c*t.x+e.zpp_inner.d*t.y+e.zpp_inner.ty,t.x=n,t=t.next;}this.invalidate_lverts();}__copy(){let e=mt._nape,t=this;if(t._isCapsule){let r=2*(t._capsuleHalfLength+t._capsuleRadius),o=2*t._capsuleRadius;this.validate_localCOM();let a=this.localCOMx,p=this.localCOMy,c;return (a!==0||p!==0)&&(c=new e.geom.Vec2(a,p),c.zpp_inner.weak=true),new e.shape.Capsule(r,o,c).zpp_inner_zn}this.outer_zn.zpp_inner_zn.wrap_lverts==null&&this.outer_zn.zpp_inner_zn.getlverts();let n=this.outer_zn.zpp_inner_zn.wrap_lverts,s=[],i=n.iterator();for(;i.hasNext();)s.push(i.next());return new e.shape.Polygon(s).zpp_inner_zn}};mt._nape=null,mt._zpp=null,mt._initialized=false;var Nn=mt;var wi=class wi{constructor(){this.space=null;this.is_sweep=false;this.is_spatial_hash=false;this.sweep=null;this.dynab=null;this.aabbShape=null;this.matrix=null;this.circShape=null;}static _initFields(e){e.space=null,e.is_sweep=false,e.is_spatial_hash=false,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=false,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=false,t.zip_localCOM){if(t.zip_localCOM=false,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let r=1;l.localCOMx+=l.lverts.next.next.x*r,l.localCOMy+=l.lverts.next.next.y*r;let o=.5;l.localCOMx*=o,l.localCOMy*=o;}else {l.localCOMx=0,l.localCOMy=0;let r=0,o=l.lverts.next,a=o;o=o.next;let p=o;for(o=o.next;o!=null;){let _=o;r+=p.x*(_.y-a.y);let y=_.y*p.x-_.x*p.y;l.localCOMx+=(p.x+_.x)*y,l.localCOMy+=(p.y+_.y)*y,a=p,p=_,o=o.next;}o=l.lverts.next;let c=o;r+=p.x*(c.y-a.y);let h=c.y*p.x-c.x*p.y;l.localCOMx+=(p.x+c.x)*h,l.localCOMy+=(p.y+c.y)*h,a=p,p=c,o=o.next;let u=o;r+=p.x*(u.y-a.y);let x=u.y*p.x-u.x*p.y;l.localCOMx+=(p.x+u.x)*x,l.localCOMy+=(p.y+u.y)*x,r=1/(3*r);let m=r;l.localCOMx*=m,l.localCOMy*=m;}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy);}let i=t.body;i.zip_axis&&(i.zip_axis=false,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy);}let n=t.radius,s=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-s,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+s;}else {let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=false,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=false,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,r=t.gverts.next;for(;r!=null;){let o=r,a=l;l=l.next,o.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),o.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),r=r.next;}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next;}}}else {let t=this.dynab,n=e.node;if(!n.synced){if(!t.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=false,e.type==0){let i=e.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=false,i.zip_localCOM){if(i.zip_localCOM=false,i.type==1){let a=i.polygon;if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(a.lverts.next.next==null)a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;else if(a.lverts.next.next.next==null){a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;let p=1;a.localCOMx+=a.lverts.next.next.x*p,a.localCOMy+=a.lverts.next.next.y*p;let c=.5;a.localCOMx*=c,a.localCOMy*=c;}else {a.localCOMx=0,a.localCOMy=0;let p=0,c=a.lverts.next,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let b=c;p+=u.x*(b.y-h.y);let w=b.y*u.x-b.x*u.y;a.localCOMx+=(u.x+b.x)*w,a.localCOMy+=(u.y+b.y)*w,h=u,u=b,c=c.next;}c=a.lverts.next;let x=c;p+=u.x*(x.y-h.y);let m=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*m,a.localCOMy+=(u.y+x.y)*m,h=u,u=x,c=c.next;let _=c;p+=u.x*(_.y-h.y);let y=_.y*u.x-_.x*u.y;a.localCOMx+=(u.x+_.x)*y,a.localCOMy+=(u.y+_.y)*y,p=1/(3*p);let z=p;a.localCOMx*=z,a.localCOMy*=z;}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy);}let o=i.body;o.zip_axis&&(o.zip_axis=false,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy);}let l=i.radius,r=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-r,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+r;}else {let i=e.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=false,i.validate_lverts();let o=i.body;o.zip_axis&&(o.zip_axis=false,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot));let a=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=a;a=a.next,c.x=i.body.posx+(i.body.axisy*h.x-i.body.axisx*h.y),c.y=i.body.posy+(h.x*i.body.axisx+h.y*i.body.axisy),p=p.next;}}if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let l=i.gverts.next;i.aabb.minx=l.x,i.aabb.miny=l.y,i.aabb.maxx=l.x,i.aabb.maxy=l.y;let r=i.gverts.next.next;for(;r!=null;){let o=r;o.x<i.aabb.minx&&(i.aabb.minx=o.x),o.x>i.aabb.maxx&&(i.aabb.maxx=o.x),o.y<i.aabb.miny&&(i.aabb.miny=o.y),o.y>i.aabb.maxy&&(i.aabb.maxy=o.y),r=r.next;}}let s;if(n.dyn==(e.body.type==1?false:!e.body.component.sleeping)){let i=n.aabb,l=e.aabb;s=!(l.minx>=i.minx&&l.miny>=i.miny&&l.maxx<=i.maxx&&l.maxy<=i.maxy);}else s=true;s&&(n.synced=true,n.snext=t.syncs,t.syncs=n);}}}broadphase(e,t){}clear(){}shapesUnderPoint(e,t,n,s){return null}bodiesUnderPoint(e,t,n,s){return null}updateAABBShape(e){let t=wi._zpp,n=wi._nape;if(this.aabbShape==null){t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=true,t.util.ZPP_Flags.BodyType_STATIC=new n.phys.BodyType,t.util.ZPP_Flags.internal=false);let r=new n.phys.Body(t.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,o=this.aabbShape=new n.shape.Polygon(n.shape.Polygon.rect(e.minx,e.miny,e.maxx-e.minx,e.maxy-e.miny));r.zpp_inner.reverse_flag?r.push(o):r.unshift(o);}else {let l=this.aabbShape.zpp_inner.aabb,r=(e.maxx-e.minx)/(l.maxx-l.minx),o=(e.maxy-e.miny)/(l.maxy-l.miny);this.matrix==null&&(this.matrix=new n.geom.Mat23);let a=this.matrix;if(r!==r)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=r;let p=a.zpp_inner;p._invalidate!=null&&p._invalidate();let c=this.matrix,h=this.matrix;h.zpp_inner.c=0;let u=h.zpp_inner;u._invalidate!=null&&u._invalidate();let x=h.zpp_inner.c;if(x!==x)throw new Error("Error: Mat23::b cannot be NaN");c.zpp_inner.b=x;let m=c.zpp_inner;m._invalidate!=null&&m._invalidate();let _=this.matrix;if(o!==o)throw new Error("Error: Mat23::d cannot be NaN");_.zpp_inner.d=o;let y=_.zpp_inner;y._invalidate!=null&&y._invalidate();let z=this.matrix,b=e.minx-r*l.minx;if(b!==b)throw new Error("Error: Mat23::tx cannot be NaN");z.zpp_inner.tx=b;let w=z.zpp_inner;w._invalidate!=null&&w._invalidate();let Z=this.matrix,d=e.miny-o*l.miny;if(d!==d)throw new Error("Error: Mat23::ty cannot be NaN");Z.zpp_inner.ty=d;let f=Z.zpp_inner;f._invalidate!=null&&f._invalidate(),this.aabbShape.transform(this.matrix);}let s=this.aabbShape.zpp_inner;if(s.zip_aabb&&s.body!=null)if(s.zip_aabb=false,s.type==0){let l=s.circle;if(l.zip_worldCOM&&l.body!=null){if(l.zip_worldCOM=false,l.zip_localCOM){if(l.zip_localCOM=false,l.type==1){let p=l.polygon;if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(p.lverts.next.next==null)p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;else if(p.lverts.next.next.next==null){p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;let c=1;p.localCOMx+=p.lverts.next.next.x*c,p.localCOMy+=p.lverts.next.next.y*c;let h=.5;p.localCOMx*=h,p.localCOMy*=h;}else {p.localCOMx=0,p.localCOMy=0;let c=0,h=p.lverts.next,u=h;h=h.next;let x=h;for(h=h.next;h!=null;){let w=h;c+=x.x*(w.y-u.y);let Z=w.y*x.x-w.x*x.y;p.localCOMx+=(x.x+w.x)*Z,p.localCOMy+=(x.y+w.y)*Z,u=x,x=w,h=h.next;}h=p.lverts.next;let m=h;c+=x.x*(m.y-u.y);let _=m.y*x.x-m.x*x.y;p.localCOMx+=(x.x+m.x)*_,p.localCOMy+=(x.y+m.y)*_,u=x,x=m,h=h.next;let y=h;c+=x.x*(y.y-u.y);let z=y.y*x.x-y.x*x.y;p.localCOMx+=(x.x+y.x)*z,p.localCOMy+=(x.y+y.y)*z,c=1/(3*c);let b=c;p.localCOMx*=b,p.localCOMy*=b;}}l.wrap_localCOM!=null&&(l.wrap_localCOM.zpp_inner.x=l.localCOMx,l.wrap_localCOM.zpp_inner.y=l.localCOMy);}let a=l.body;a.zip_axis&&(a.zip_axis=false,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot)),l.worldCOMx=l.body.posx+(l.body.axisy*l.localCOMx-l.body.axisx*l.localCOMy),l.worldCOMy=l.body.posy+(l.localCOMx*l.body.axisx+l.localCOMy*l.body.axisy);}let r=l.radius,o=l.radius;l.aabb.minx=l.worldCOMx-r,l.aabb.miny=l.worldCOMy-o,l.aabb.maxx=l.worldCOMx+r,l.aabb.maxy=l.worldCOMy+o;}else {let l=s.polygon;if(l.zip_gverts&&l.body!=null){l.zip_gverts=false,l.validate_lverts();let a=l.body;a.zip_axis&&(a.zip_axis=false,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=l.lverts.next,c=l.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=l.body.posx+(l.body.axisy*u.x-l.body.axisx*u.y),h.y=l.body.posy+(u.x*l.body.axisx+u.y*l.body.axisy),c=c.next;}}if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=l.gverts.next;l.aabb.minx=r.x,l.aabb.miny=r.y,l.aabb.maxx=r.x,l.aabb.maxy=r.y;let o=l.gverts.next.next;for(;o!=null;){let a=o;a.x<l.aabb.minx&&(l.aabb.minx=a.x),a.x>l.aabb.maxx&&(l.aabb.maxx=a.x),a.y<l.aabb.miny&&(l.aabb.miny=a.y),a.y>l.aabb.maxy&&(l.aabb.maxy=a.y),o=o.next;}}let i=this.aabbShape.zpp_inner.polygon;if(i.zip_gaxi&&i.body!=null){i.zip_gaxi=false,i.validate_laxi();let l=i.body;if(l.zip_axis&&(l.zip_axis=false,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot)),i.zip_gverts&&i.body!=null){i.zip_gverts=false,i.validate_lverts();let h=i.body;h.zip_axis&&(h.zip_axis=false,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot));let u=i.lverts.next,x=i.gverts.next;for(;x!=null;){let m=x,_=u;u=u.next,m.x=i.body.posx+(i.body.axisy*_.x-i.body.axisx*_.y),m.y=i.body.posy+(_.x*i.body.axisx+_.y*i.body.axisy),x=x.next;}}let r=i.edges.head,o=i.gverts.next,a=o;for(o=o.next;o!=null;){let h=o,u=r.elt;r=r.next,u.gp0=a,u.gp1=h,u.gnormx=i.body.axisy*u.lnormx-i.body.axisx*u.lnormy,u.gnormy=u.lnormx*i.body.axisx+u.lnormy*i.body.axisy,u.gprojection=i.body.posx*u.gnormx+i.body.posy*u.gnormy+u.lprojection,u.wrap_gnorm!=null&&(u.wrap_gnorm.zpp_inner.x=u.gnormx,u.wrap_gnorm.zpp_inner.y=u.gnormy),u.tp0=u.gp0.y*u.gnormx-u.gp0.x*u.gnormy,u.tp1=u.gp1.y*u.gnormx-u.gp1.x*u.gnormy,a=h,o=o.next;}let p=i.gverts.next,c=r.elt;r=r.next,c.gp0=a,c.gp1=p,c.gnormx=i.body.axisy*c.lnormx-i.body.axisx*c.lnormy,c.gnormy=c.lnormx*i.body.axisx+c.lnormy*i.body.axisy,c.gprojection=i.body.posx*c.gnormx+i.body.posy*c.gnormy+c.lprojection,c.wrap_gnorm!=null&&(c.wrap_gnorm.zpp_inner.x=c.gnormx,c.wrap_gnorm.zpp_inner.y=c.gnormy),c.tp0=c.gp0.y*c.gnormx-c.gp0.x*c.gnormy,c.tp1=c.gp1.y*c.gnormx-c.gp1.x*c.gnormy;}}shapesInAABB(e,t,n,s,i){return null}bodiesInAABB(e,t,n,s,i){return null}updateCircShape(e,t,n){let s=wi._zpp,i=wi._nape;if(this.circShape==null){s.util.ZPP_Flags.BodyType_STATIC==null&&(s.util.ZPP_Flags.internal=true,s.util.ZPP_Flags.BodyType_STATIC=new i.phys.BodyType,s.util.ZPP_Flags.internal=false);let o=new i.phys.Body(s.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,a=e,p=t;if(p==null&&(p=0),a==null&&(a=0),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let c;if(s.util.ZPP_PubPool.poolVec2==null?c=new i.geom.Vec2:(c=s.util.ZPP_PubPool.poolVec2,s.util.ZPP_PubPool.poolVec2=c.zpp_pool,c.zpp_pool=null,c.zpp_disp=false,c==s.util.ZPP_PubPool.nextVec2&&(s.util.ZPP_PubPool.nextVec2=null)),c.zpp_inner==null){let u;s.geom.ZPP_Vec2.zpp_pool==null?u=new s.geom.ZPP_Vec2:(u=s.geom.ZPP_Vec2.zpp_pool,s.geom.ZPP_Vec2.zpp_pool=u.next,u.next=null),u.weak=false,u._immutable=false,u.x=a,u.y=p,c.zpp_inner=u,c.zpp_inner.outer=c;}else {if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=c.zpp_inner;if(u._immutable)throw new Error("Error: Vec2 is immutable");if(u._isimmutable!=null&&u._isimmutable(),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let x;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let m=c.zpp_inner;if(m._validate!=null&&m._validate(),c.zpp_inner.x==a){if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let _=c.zpp_inner;_._validate!=null&&_._validate(),x=c.zpp_inner.y==p;}else x=false;if(!x){c.zpp_inner.x=a,c.zpp_inner.y=p;let _=c.zpp_inner;_._invalidate!=null&&_._invalidate(_);}}c.zpp_inner.weak=false;let h=this.circShape=new i.shape.Circle(n,c);o.zpp_inner.reverse_flag?o.push(h):o.unshift(h);}else {let r=this.circShape.zpp_inner.circle,o=n/r.radius;this.matrix==null&&(this.matrix=new i.geom.Mat23);let a=this.matrix,p=this.matrix;if(o!==o)throw new Error("Error: Mat23::d cannot be NaN");p.zpp_inner.d=o;let c=p.zpp_inner;c._invalidate!=null&&c._invalidate();let h=p.zpp_inner.d;if(h!==h)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=h;let u=a.zpp_inner;u._invalidate!=null&&u._invalidate();let x=this.matrix,m=this.matrix;m.zpp_inner.c=0;let _=m.zpp_inner;_._invalidate!=null&&_._invalidate();let y=m.zpp_inner.c;if(y!==y)throw new Error("Error: Mat23::b cannot be NaN");x.zpp_inner.b=y;let z=x.zpp_inner;z._invalidate!=null&&z._invalidate();let b=this.matrix,w=e-o*r.localCOMx;if(w!==w)throw new Error("Error: Mat23::tx cannot be NaN");b.zpp_inner.tx=w;let Z=b.zpp_inner;Z._invalidate!=null&&Z._invalidate();let d=this.matrix,f=t-o*r.localCOMy;if(f!==f)throw new Error("Error: Mat23::ty cannot be NaN");d.zpp_inner.ty=f;let g=d.zpp_inner;g._invalidate!=null&&g._invalidate(),this.circShape.transform(this.matrix);}let l=this.circShape.zpp_inner;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=false,l.type==0){let r=l.circle;if(r.zip_worldCOM&&r.body!=null){if(r.zip_worldCOM=false,r.zip_localCOM){if(r.zip_localCOM=false,r.type==1){let c=r.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let h=1;c.localCOMx+=c.lverts.next.next.x*h,c.localCOMy+=c.lverts.next.next.y*h;let u=.5;c.localCOMx*=u,c.localCOMy*=u;}else {c.localCOMx=0,c.localCOMy=0;let h=0,u=c.lverts.next,x=u;u=u.next;let m=u;for(u=u.next;u!=null;){let Z=u;h+=m.x*(Z.y-x.y);let d=Z.y*m.x-Z.x*m.y;c.localCOMx+=(m.x+Z.x)*d,c.localCOMy+=(m.y+Z.y)*d,x=m,m=Z,u=u.next;}u=c.lverts.next;let _=u;h+=m.x*(_.y-x.y);let y=_.y*m.x-_.x*m.y;c.localCOMx+=(m.x+_.x)*y,c.localCOMy+=(m.y+_.y)*y,x=m,m=_,u=u.next;let z=u;h+=m.x*(z.y-x.y);let b=z.y*m.x-z.x*m.y;c.localCOMx+=(m.x+z.x)*b,c.localCOMy+=(m.y+z.y)*b,h=1/(3*h);let w=h;c.localCOMx*=w,c.localCOMy*=w;}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy);}let p=r.body;p.zip_axis&&(p.zip_axis=false,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),r.worldCOMx=r.body.posx+(r.body.axisy*r.localCOMx-r.body.axisx*r.localCOMy),r.worldCOMy=r.body.posy+(r.localCOMx*r.body.axisx+r.localCOMy*r.body.axisy);}let o=r.radius,a=r.radius;r.aabb.minx=r.worldCOMx-o,r.aabb.miny=r.worldCOMy-a,r.aabb.maxx=r.worldCOMx+o,r.aabb.maxy=r.worldCOMy+a;}else {let r=l.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=false,r.validate_lverts();let p=r.body;p.zip_axis&&(p.zip_axis=false,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=r.lverts.next,h=r.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=r.body.posx+(r.body.axisy*x.x-r.body.axisx*x.y),u.y=r.body.posy+(x.x*r.body.axisx+x.y*r.body.axisy),h=h.next;}}if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let o=r.gverts.next;r.aabb.minx=o.x,r.aabb.miny=o.y,r.aabb.maxx=o.x,r.aabb.maxy=o.y;let a=r.gverts.next.next;for(;a!=null;){let p=a;p.x<r.aabb.minx&&(r.aabb.minx=p.x),p.x>r.aabb.maxx&&(r.aabb.maxx=p.x),p.y<r.aabb.miny&&(r.aabb.miny=p.y),p.y>r.aabb.maxy&&(r.aabb.maxy=p.y),a=a.next;}}}shapesInCircle(e,t,n,s,i,l){return null}bodiesInCircle(e,t,n,s,i,l){return null}validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=false,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=false,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=false,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=false,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=t.body.posx+(t.body.axisy*u.x-t.body.axisx*u.y),h.y=t.body.posy+(u.x*t.body.axisx+u.y*t.body.axisy),c=c.next;}}let s=t.edges.head,i=t.gverts.next,l=i;for(i=i.next;i!=null;){let a=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,l=a,i=i.next;}let r=t.gverts.next,o=s.elt;s=s.next,o.gp0=l,o.gp1=r,o.gnormx=t.body.axisy*o.lnormx-t.body.axisx*o.lnormy,o.gnormy=o.lnormx*t.body.axisx+o.lnormy*t.body.axisy,o.gprojection=t.body.posx*o.gnormx+t.body.posy*o.gnormy+o.lprojection,o.wrap_gnorm!=null&&(o.wrap_gnorm.zpp_inner.x=o.gnormx,o.wrap_gnorm.zpp_inner.y=o.gnormy),o.tp0=o.gp0.y*o.gnormx-o.gp0.x*o.gnormy,o.tp1=o.gp1.y*o.gnormx-o.gp1.x*o.gnormy;}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=false,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=false,t.zip_localCOM){if(t.zip_localCOM=false,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let r=1;l.localCOMx+=l.lverts.next.next.x*r,l.localCOMy+=l.lverts.next.next.y*r;let o=.5;l.localCOMx*=o,l.localCOMy*=o;}else {l.localCOMx=0,l.localCOMy=0;let r=0,o=l.lverts.next,a=o;o=o.next;let p=o;for(o=o.next;o!=null;){let _=o;r+=p.x*(_.y-a.y);let y=_.y*p.x-_.x*p.y;l.localCOMx+=(p.x+_.x)*y,l.localCOMy+=(p.y+_.y)*y,a=p,p=_,o=o.next;}o=l.lverts.next;let c=o;r+=p.x*(c.y-a.y);let h=c.y*p.x-c.x*p.y;l.localCOMx+=(p.x+c.x)*h,l.localCOMy+=(p.y+c.y)*h,a=p,p=c,o=o.next;let u=o;r+=p.x*(u.y-a.y);let x=u.y*p.x-u.x*p.y;l.localCOMx+=(p.x+u.x)*x,l.localCOMy+=(p.y+u.y)*x,r=1/(3*r);let m=r;l.localCOMx*=m,l.localCOMy*=m;}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy);}let i=t.body;i.zip_axis&&(i.zip_axis=false,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy);}let n=t.radius,s=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-s,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+s;}else {let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=false,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=false,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,r=t.gverts.next;for(;r!=null;){let o=r,a=l;l=l.next,o.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),o.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),r=r.next;}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next;}}if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=false,e.zip_localCOM){if(e.zip_localCOM=false,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let s=1;n.localCOMx+=n.lverts.next.next.x*s,n.localCOMy+=n.lverts.next.next.y*s;let i=.5;n.localCOMx*=i,n.localCOMy*=i;}else {n.localCOMx=0,n.localCOMy=0;let s=0,i=n.lverts.next,l=i;i=i.next;let r=i;for(i=i.next;i!=null;){let u=i;s+=r.x*(u.y-l.y);let x=u.y*r.x-u.x*r.y;n.localCOMx+=(r.x+u.x)*x,n.localCOMy+=(r.y+u.y)*x,l=r,r=u,i=i.next;}i=n.lverts.next;let o=i;s+=r.x*(o.y-l.y);let a=o.y*r.x-o.x*r.y;n.localCOMx+=(r.x+o.x)*a,n.localCOMy+=(r.y+o.y)*a,l=r,r=o,i=i.next;let p=i;s+=r.x*(p.y-l.y);let c=p.y*r.x-p.x*r.y;n.localCOMx+=(r.x+p.x)*c,n.localCOMy+=(r.y+p.y)*c,s=1/(3*s);let h=s;n.localCOMx*=h,n.localCOMy*=h;}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy);}let t=e.body;t.zip_axis&&(t.zip_axis=false,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy);}}shapesInShape(e,t,n,s){return null}bodiesInShape(e,t,n,s){return null}rayCast(e,t,n){return null}rayMultiCast(e,t,n,s){return null}};wi._zpp=null,wi._nape=null;var Bn=wi;var Ae=class{constructor(){this.aabb=null;this.shape=null;this.dyn=false;this.parent=null;this.child1=null;this.child2=null;this.height=-1;this.rayt=0;this.next=null;this.mnext=null;this.moved=false;this.snext=null;this.synced=false;this.first_sync=false;}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=false,this.synced=false,this.first_sync=false;}free(){this.height=-1;let e=this.aabb;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e.wrap_min=e.wrap_max=null,e._invalidate=null,e._validate=null,e.next=be.zpp_pool,be.zpp_pool=e,this.child1=this.child2=this.parent=null,this.next=null,this.snext=null,this.mnext=null;}isLeaf(){return this.child1==null}};Ae.zpp_pool=null;var lt=class{constructor(){this.n1=null;this.n2=null;this.first=false;this.sleeping=false;this.id=0;this.di=0;this.arb=null;this.next=null;this.gprev=null;}alloc(){}free(){this.n1=this.n2=null,this.sleeping=false,this.gprev=null;}};lt.zpp_pool=null;var Zt=class Zt{constructor(){this.root=null;}static _initStatics(){Zt.tmpaabb=new be;}clear(){if(this.root==null)return;let e=null;for(this.root.next=e,e=this.root;e!=null;){let t=e;e=t.next,t.next=null;let n=t;n.child1==null?(n.shape.node=null,n.shape.removedFromSpace(),n.shape=null):(n.child1!=null&&(n.child1.next=e,e=n.child1),n.child2!=null&&(n.child2.next=e,e=n.child2));let s=n;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Ae.zpp_pool,Ae.zpp_pool=s;}this.root=null;}insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else {let t=e.aabb,n=this.root;for(;n.child1!=null;){let a=n.child1,p=n.child2,c=n.aabb,h=(c.maxx-c.minx+(c.maxy-c.miny))*2,u=Zt.tmpaabb,x=n.aabb;u.minx=x.minx<t.minx?x.minx:t.minx,u.miny=x.miny<t.miny?x.miny:t.miny,u.maxx=x.maxx>t.maxx?x.maxx:t.maxx,u.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let m=Zt.tmpaabb,_=(m.maxx-m.minx+(m.maxy-m.miny))*2,y=2*_,z=2*(_-h),b=Zt.tmpaabb,w=a.aabb;b.minx=t.minx<w.minx?t.minx:w.minx,b.miny=t.miny<w.miny?t.miny:w.miny,b.maxx=t.maxx>w.maxx?t.maxx:w.maxx,b.maxy=t.maxy>w.maxy?t.maxy:w.maxy;let Z;if(a.child1==null){let P=Zt.tmpaabb;Z=(P.maxx-P.minx+(P.maxy-P.miny))*2+z;}else {let P=a.aabb,v=(P.maxx-P.minx+(P.maxy-P.miny))*2,N=Zt.tmpaabb;Z=(N.maxx-N.minx+(N.maxy-N.miny))*2-v+z;}let d=Zt.tmpaabb,f=p.aabb;d.minx=t.minx<f.minx?t.minx:f.minx,d.miny=t.miny<f.miny?t.miny:f.miny,d.maxx=t.maxx>f.maxx?t.maxx:f.maxx,d.maxy=t.maxy>f.maxy?t.maxy:f.maxy;let g;if(p.child1==null){let P=Zt.tmpaabb;g=(P.maxx-P.minx+(P.maxy-P.miny))*2+z;}else {let P=p.aabb,v=(P.maxx-P.minx+(P.maxy-P.miny))*2,N=Zt.tmpaabb;g=(N.maxx-N.minx+(N.maxy-N.miny))*2-v+z;}if(y<Z&&y<g)break;n=Z<g?a:p;}let s=n,i=s.parent,l;Ae.zpp_pool==null?l=new Ae:(l=Ae.zpp_pool,Ae.zpp_pool=l.next,l.next=null),be.zpp_pool==null?l.aabb=new be:(l.aabb=be.zpp_pool,be.zpp_pool=l.aabb.next,l.aabb.next=null),l.moved=false,l.synced=false,l.first_sync=false,l.parent=i;let r=l.aabb,o=s.aabb;for(r.minx=t.minx<o.minx?t.minx:o.minx,r.miny=t.miny<o.miny?t.miny:o.miny,r.maxx=t.maxx>o.maxx?t.maxx:o.maxx,r.maxy=t.maxy>o.maxy?t.maxy:o.maxy,l.height=s.height+1,i!=null?(i.child1==s?i.child1=l:i.child2=l,l.child1=s,l.child2=e,s.parent=l,e.parent=l):(l.child1=s,l.child2=e,s.parent=l,e.parent=l,this.root=l),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else {let _=n.child1,y=n.child2,z=y.height-_.height;if(z>1){let b=y.child1,w=y.child2;if(y.child1=n,y.parent=n.parent,n.parent=y,y.parent!=null?y.parent.child1==n?y.parent.child1=y:y.parent.child2=y:this.root=y,b.height>w.height){y.child2=b,n.child2=w,w.parent=n;let Z=n.aabb,d=_.aabb,f=w.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=y.aabb,P=n.aabb,v=b.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=_.height,E=w.height;n.height=1+(N>E?N:E);let M=n.height,k=b.height;y.height=1+(M>k?M:k);}else {y.child2=w,n.child2=b,b.parent=n;let Z=n.aabb,d=_.aabb,f=b.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=y.aabb,P=n.aabb,v=w.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=_.height,E=b.height;n.height=1+(N>E?N:E);let M=n.height,k=w.height;y.height=1+(M>k?M:k);}n=y;}else if(z<-1){let b=_.child1,w=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,b.height>w.height){_.child2=b,n.child1=w,w.parent=n;let Z=n.aabb,d=y.aabb,f=w.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=_.aabb,P=n.aabb,v=b.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=y.height,E=w.height;n.height=1+(N>E?N:E);let M=n.height,k=b.height;_.height=1+(M>k?M:k);}else {_.child2=w,n.child1=b,b.parent=n;let Z=n.aabb,d=y.aabb,f=b.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=_.aabb,P=n.aabb,v=w.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=y.height,E=b.height;n.height=1+(N>E?N:E);let M=n.height,k=w.height;_.height=1+(M>k?M:k);}n=_;}else n=n;}let a=n.child1,p=n.child2,c=a.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=a.aabb,m=p.aabb;u.minx=x.minx<m.minx?x.minx:m.minx,u.miny=x.miny<m.miny?x.miny:m.miny,u.maxx=x.maxx>m.maxx?x.maxx:m.maxx,u.maxy=x.maxy>m.maxy?x.maxy:m.maxy,n=n.parent;}}}inlined_insertLeaf(e){if(this.root==null)this.root=e,this.root.parent=null;else {let t=e.aabb,n=this.root;for(;n.child1!=null;){let a=n.child1,p=n.child2,c=n.aabb,h=(c.maxx-c.minx+(c.maxy-c.miny))*2,u=Zt.tmpaabb,x=n.aabb;u.minx=x.minx<t.minx?x.minx:t.minx,u.miny=x.miny<t.miny?x.miny:t.miny,u.maxx=x.maxx>t.maxx?x.maxx:t.maxx,u.maxy=x.maxy>t.maxy?x.maxy:t.maxy;let m=Zt.tmpaabb,_=(m.maxx-m.minx+(m.maxy-m.miny))*2,y=2*_,z=2*(_-h),b=Zt.tmpaabb,w=a.aabb;b.minx=t.minx<w.minx?t.minx:w.minx,b.miny=t.miny<w.miny?t.miny:w.miny,b.maxx=t.maxx>w.maxx?t.maxx:w.maxx,b.maxy=t.maxy>w.maxy?t.maxy:w.maxy;let Z;if(a.child1==null){let P=Zt.tmpaabb;Z=(P.maxx-P.minx+(P.maxy-P.miny))*2+z;}else {let P=a.aabb,v=(P.maxx-P.minx+(P.maxy-P.miny))*2,N=Zt.tmpaabb;Z=(N.maxx-N.minx+(N.maxy-N.miny))*2-v+z;}let d=Zt.tmpaabb,f=p.aabb;d.minx=t.minx<f.minx?t.minx:f.minx,d.miny=t.miny<f.miny?t.miny:f.miny,d.maxx=t.maxx>f.maxx?t.maxx:f.maxx,d.maxy=t.maxy>f.maxy?t.maxy:f.maxy;let g;if(p.child1==null){let P=Zt.tmpaabb;g=(P.maxx-P.minx+(P.maxy-P.miny))*2+z;}else {let P=p.aabb,v=(P.maxx-P.minx+(P.maxy-P.miny))*2,N=Zt.tmpaabb;g=(N.maxx-N.minx+(N.maxy-N.miny))*2-v+z;}if(y<Z&&y<g)break;n=Z<g?a:p;}let s=n,i=s.parent,l;Ae.zpp_pool==null?l=new Ae:(l=Ae.zpp_pool,Ae.zpp_pool=l.next,l.next=null),be.zpp_pool==null?l.aabb=new be:(l.aabb=be.zpp_pool,be.zpp_pool=l.aabb.next,l.aabb.next=null),l.moved=false,l.synced=false,l.first_sync=false,l.parent=i;let r=l.aabb,o=s.aabb;for(r.minx=t.minx<o.minx?t.minx:o.minx,r.miny=t.miny<o.miny?t.miny:o.miny,r.maxx=t.maxx>o.maxx?t.maxx:o.maxx,r.maxy=t.maxy>o.maxy?t.maxy:o.maxy,l.height=s.height+1,i!=null?(i.child1==s?i.child1=l:i.child2=l,l.child1=s,l.child2=e,s.parent=l,e.parent=l):(l.child1=s,l.child2=e,s.parent=l,e.parent=l,this.root=l),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else {let _=n.child1,y=n.child2,z=y.height-_.height;if(z>1){let b=y.child1,w=y.child2;if(y.child1=n,y.parent=n.parent,n.parent=y,y.parent!=null?y.parent.child1==n?y.parent.child1=y:y.parent.child2=y:this.root=y,b.height>w.height){y.child2=b,n.child2=w,w.parent=n;let Z=n.aabb,d=_.aabb,f=w.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=y.aabb,P=n.aabb,v=b.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=_.height,E=w.height;n.height=1+(N>E?N:E);let M=n.height,k=b.height;y.height=1+(M>k?M:k);}else {y.child2=w,n.child2=b,b.parent=n;let Z=n.aabb,d=_.aabb,f=b.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=y.aabb,P=n.aabb,v=w.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=_.height,E=b.height;n.height=1+(N>E?N:E);let M=n.height,k=w.height;y.height=1+(M>k?M:k);}n=y;}else if(z<-1){let b=_.child1,w=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,b.height>w.height){_.child2=b,n.child1=w,w.parent=n;let Z=n.aabb,d=y.aabb,f=w.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=_.aabb,P=n.aabb,v=b.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=y.height,E=w.height;n.height=1+(N>E?N:E);let M=n.height,k=b.height;_.height=1+(M>k?M:k);}else {_.child2=w,n.child1=b,b.parent=n;let Z=n.aabb,d=y.aabb,f=b.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=_.aabb,P=n.aabb,v=w.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=y.height,E=b.height;n.height=1+(N>E?N:E);let M=n.height,k=w.height;_.height=1+(M>k?M:k);}n=_;}else n=n;}let a=n.child1,p=n.child2,c=a.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=a.aabb,m=p.aabb;u.minx=x.minx<m.minx?x.minx:m.minx,u.miny=x.miny<m.miny?x.miny:m.miny,u.maxx=x.maxx>m.maxx?x.maxx:m.maxx,u.maxy=x.maxy>m.maxy?x.maxy:m.maxy,n=n.parent;}}}removeLeaf(e){if(e==this.root)this.root=null;else {let t=e.parent,n=t.parent,s=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=s:n.child2=s,s.parent=n;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=be.zpp_pool,be.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Ae.zpp_pool,Ae.zpp_pool=i;let r=n;for(;r!=null;){if(r.child1==null||r.height<2)r=r;else {let _=r.child1,y=r.child2,z=y.height-_.height;if(z>1){let b=y.child1,w=y.child2;if(y.child1=r,y.parent=r.parent,r.parent=y,y.parent!=null?y.parent.child1==r?y.parent.child1=y:y.parent.child2=y:this.root=y,b.height>w.height){y.child2=b,r.child2=w,w.parent=r;let Z=r.aabb,d=_.aabb,f=w.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=y.aabb,P=r.aabb,v=b.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=_.height,E=w.height;r.height=1+(N>E?N:E);let M=r.height,k=b.height;y.height=1+(M>k?M:k);}else {y.child2=w,r.child2=b,b.parent=r;let Z=r.aabb,d=_.aabb,f=b.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=y.aabb,P=r.aabb,v=w.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=_.height,E=b.height;r.height=1+(N>E?N:E);let M=r.height,k=w.height;y.height=1+(M>k?M:k);}r=y;}else if(z<-1){let b=_.child1,w=_.child2;if(_.child1=r,_.parent=r.parent,r.parent=_,_.parent!=null?_.parent.child1==r?_.parent.child1=_:_.parent.child2=_:this.root=_,b.height>w.height){_.child2=b,r.child1=w,w.parent=r;let Z=r.aabb,d=y.aabb,f=w.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=_.aabb,P=r.aabb,v=b.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=y.height,E=w.height;r.height=1+(N>E?N:E);let M=r.height,k=b.height;_.height=1+(M>k?M:k);}else {_.child2=w,r.child1=b,b.parent=r;let Z=r.aabb,d=y.aabb,f=b.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=_.aabb,P=r.aabb,v=w.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=y.height,E=b.height;r.height=1+(N>E?N:E);let M=r.height,k=w.height;_.height=1+(M>k?M:k);}r=_;}else r=r;}let o=r,a=o.child1,p=o.child2,c=o.aabb,h=a.aabb,u=p.aabb;c.minx=h.minx<u.minx?h.minx:u.minx,c.miny=h.miny<u.miny?h.miny:u.miny,c.maxx=h.maxx>u.maxx?h.maxx:u.maxx,c.maxy=h.maxy>u.maxy?h.maxy:u.maxy;let x=a.height,m=p.height;o.height=1+(x>m?x:m),r=o.parent;}}else {this.root=s,s.parent=null;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=be.zpp_pool,be.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Ae.zpp_pool,Ae.zpp_pool=i;}}}inlined_removeLeaf(e){if(e==this.root){this.root=null;return}else {let t=e.parent,n=t.parent,s=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=s:n.child2=s,s.parent=n;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=be.zpp_pool,be.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Ae.zpp_pool,Ae.zpp_pool=i;let r=n;for(;r!=null;){if(r.child1==null||r.height<2)r=r;else {let _=r.child1,y=r.child2,z=y.height-_.height;if(z>1){let b=y.child1,w=y.child2;if(y.child1=r,y.parent=r.parent,r.parent=y,y.parent!=null?y.parent.child1==r?y.parent.child1=y:y.parent.child2=y:this.root=y,b.height>w.height){y.child2=b,r.child2=w,w.parent=r;let Z=r.aabb,d=_.aabb,f=w.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=y.aabb,P=r.aabb,v=b.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=_.height,E=w.height;r.height=1+(N>E?N:E);let M=r.height,k=b.height;y.height=1+(M>k?M:k);}else {y.child2=w,r.child2=b,b.parent=r;let Z=r.aabb,d=_.aabb,f=b.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=y.aabb,P=r.aabb,v=w.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=_.height,E=b.height;r.height=1+(N>E?N:E);let M=r.height,k=w.height;y.height=1+(M>k?M:k);}r=y;}else if(z<-1){let b=_.child1,w=_.child2;if(_.child1=r,_.parent=r.parent,r.parent=_,_.parent!=null?_.parent.child1==r?_.parent.child1=_:_.parent.child2=_:this.root=_,b.height>w.height){_.child2=b,r.child1=w,w.parent=r;let Z=r.aabb,d=y.aabb,f=w.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=_.aabb,P=r.aabb,v=b.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=y.height,E=w.height;r.height=1+(N>E?N:E);let M=r.height,k=b.height;_.height=1+(M>k?M:k);}else {_.child2=w,r.child1=b,b.parent=r;let Z=r.aabb,d=y.aabb,f=b.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy;let g=_.aabb,P=r.aabb,v=w.aabb;g.minx=P.minx<v.minx?P.minx:v.minx,g.miny=P.miny<v.miny?P.miny:v.miny,g.maxx=P.maxx>v.maxx?P.maxx:v.maxx,g.maxy=P.maxy>v.maxy?P.maxy:v.maxy;let N=y.height,E=b.height;r.height=1+(N>E?N:E);let M=r.height,k=w.height;_.height=1+(M>k?M:k);}r=_;}else r=r;}let o=r,a=o.child1,p=o.child2,c=o.aabb,h=a.aabb,u=p.aabb;c.minx=h.minx<u.minx?h.minx:u.minx,c.miny=h.miny<u.miny?h.miny:u.miny,c.maxx=h.maxx>u.maxx?h.maxx:u.maxx,c.maxy=h.maxy>u.maxy?h.maxy:u.maxy;let x=a.height,m=p.height;o.height=1+(x>m?x:m),r=o.parent;}}else {this.root=s,s.parent=null;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=be.zpp_pool,be.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Ae.zpp_pool,Ae.zpp_pool=i;}}}balance(e){if(e.child1==null||e.height<2)return e;{let t=e.child1,n=e.child2,s=n.height-t.height;if(s>1){let i=n.child1,l=n.child2;if(n.child1=e,n.parent=e.parent,e.parent=n,n.parent!=null?n.parent.child1==e?n.parent.child1=n:n.parent.child2=n:this.root=n,i.height>l.height){n.child2=i,e.child2=l,l.parent=e;let r=e.aabb,o=t.aabb,a=l.aabb;r.minx=o.minx<a.minx?o.minx:a.minx,r.miny=o.miny<a.miny?o.miny:a.miny,r.maxx=o.maxx>a.maxx?o.maxx:a.maxx,r.maxy=o.maxy>a.maxy?o.maxy:a.maxy;let p=n.aabb,c=e.aabb,h=i.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=t.height,x=l.height;e.height=1+(u>x?u:x);let m=e.height,_=i.height;n.height=1+(m>_?m:_);}else {n.child2=l,e.child2=i,i.parent=e;let r=e.aabb,o=t.aabb,a=i.aabb;r.minx=o.minx<a.minx?o.minx:a.minx,r.miny=o.miny<a.miny?o.miny:a.miny,r.maxx=o.maxx>a.maxx?o.maxx:a.maxx,r.maxy=o.maxy>a.maxy?o.maxy:a.maxy;let p=n.aabb,c=e.aabb,h=l.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=t.height,x=i.height;e.height=1+(u>x?u:x);let m=e.height,_=l.height;n.height=1+(m>_?m:_);}return n}else if(s<-1){let i=t.child1,l=t.child2;if(t.child1=e,t.parent=e.parent,e.parent=t,t.parent!=null?t.parent.child1==e?t.parent.child1=t:t.parent.child2=t:this.root=t,i.height>l.height){t.child2=i,e.child1=l,l.parent=e;let r=e.aabb,o=n.aabb,a=l.aabb;r.minx=o.minx<a.minx?o.minx:a.minx,r.miny=o.miny<a.miny?o.miny:a.miny,r.maxx=o.maxx>a.maxx?o.maxx:a.maxx,r.maxy=o.maxy>a.maxy?o.maxy:a.maxy;let p=t.aabb,c=e.aabb,h=i.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=n.height,x=l.height;e.height=1+(u>x?u:x);let m=e.height,_=i.height;t.height=1+(m>_?m:_);}else {t.child2=l,e.child1=i,i.parent=e;let r=e.aabb,o=n.aabb,a=i.aabb;r.minx=o.minx<a.minx?o.minx:a.minx,r.miny=o.miny<a.miny?o.miny:a.miny,r.maxx=o.maxx>a.maxx?o.maxx:a.maxx,r.maxy=o.maxy>a.maxy?o.maxy:a.maxy;let p=t.aabb,c=e.aabb,h=l.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=n.height,x=i.height;e.height=1+(u>x?u:x);let m=e.height,_=l.height;t.height=1+(m>_?m:_);}return t}else return e}}};Zt.tmpaabb=null;var Qe=Zt;var ze=class ze extends Bn{constructor(t){super();this.pairs=null;this.syncs=null;this.moves=null;this.treeStack=null;this.treeStack2=null;this.failed=null;this.openlist=null;this.space=t,this.is_sweep=false,this.dynab=this,this.stree=new Qe,this.dtree=new Qe;}_linkPair(t){t.gprev=null,t.next=this.pairs,this.pairs!=null&&(this.pairs.gprev=t),this.pairs=t;}_unlinkPair(t){t.gprev!=null?t.gprev.next=t.next:this.pairs=t.next,t.next!=null&&(t.next.gprev=t.gprev),t.gprev=null,t.next=null;}dyn(t){return t.body.type==1?false:!t.body.component.sleeping}__insert(t){let n;Ae.zpp_pool==null?n=new Ae:(n=Ae.zpp_pool,Ae.zpp_pool=n.next,n.next=null),be.zpp_pool==null?n.aabb=new be:(n.aabb=be.zpp_pool,be.zpp_pool=n.aabb.next,n.aabb.next=null),n.moved=false,n.synced=false,n.first_sync=false,n.shape=t,t.node=n,n.synced=true,n.first_sync=true,n.snext=this.syncs,this.syncs=n;}__remove(t){let n=t.node;if(n.first_sync||(n.dyn?this.dtree.removeLeaf(n):this.stree.removeLeaf(n)),t.node=null,n.synced){let l=null,r=this.syncs;for(;r!=null&&r!=n;)l=r,r=r.snext;l==null?this.syncs=r.snext:l.snext=r.snext,r.snext=null,n.synced=false;}if(n.moved){let l=null,r=this.moves;for(;r!=null&&r!=n;)l=r,r=r.mnext;l==null?this.moves=r.mnext:l.mnext=r.mnext,r.mnext=null,n.moved=false;}for(;t.pairs.head!=null;){let l=t.pairs.pop_unsafe();l.sleeping||this._unlinkPair(l),l.n1==n?l.n2.shape.pairs.remove(l):l.n1.shape.pairs.remove(l),l.arb!=null&&(l.arb.pair=null),l.arb=null,l.n1=l.n2=null,l.sleeping=false,l.gprev=null,l.next=lt.zpp_pool,lt.zpp_pool=l;}let s=n;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=be.zpp_pool,be.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Ae.zpp_pool,Ae.zpp_pool=s;}__sync(t){let n=t.node;if(!n.synced){if(!this.space.continuous&&t.zip_aabb&&t.body!=null)if(t.zip_aabb=false,t.type==0){let i=t.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=false,i.zip_localCOM){if(i.zip_localCOM=false,i.type==1){let a=i.polygon;if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(a.lverts.next.next==null)a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;else if(a.lverts.next.next.next==null){a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;let p=1;a.localCOMx+=a.lverts.next.next.x*p,a.localCOMy+=a.lverts.next.next.y*p;let c=.5;a.localCOMx*=c,a.localCOMy*=c;}else {a.localCOMx=0,a.localCOMy=0;let p=0,c=a.lverts.next,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let b=c;p+=u.x*(b.y-h.y);let w=b.y*u.x-b.x*u.y;a.localCOMx+=(u.x+b.x)*w,a.localCOMy+=(u.y+b.y)*w,h=u,u=b,c=c.next;}c=a.lverts.next;let x=c;p+=u.x*(x.y-h.y);let m=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*m,a.localCOMy+=(u.y+x.y)*m,h=u,u=x,c=c.next;let _=c;p+=u.x*(_.y-h.y);let y=_.y*u.x-_.x*u.y;a.localCOMx+=(u.x+_.x)*y,a.localCOMy+=(u.y+_.y)*y,p=1/(3*p);let z=p;a.localCOMx*=z,a.localCOMy*=z;}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy);}let o=i.body;o.zip_axis&&(o.zip_axis=false,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy);}let l=i.radius,r=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-r,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+r;}else {let i=t.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=false,i.validate_lverts();let o=i.body;o.zip_axis&&(o.zip_axis=false,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot));let a=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=a;a=a.next,c.x=i.body.posx+(i.body.axisy*h.x-i.body.axisx*h.y),c.y=i.body.posy+(h.x*i.body.axisx+h.y*i.body.axisy),p=p.next;}}if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let l=i.gverts.next;i.aabb.minx=l.x,i.aabb.miny=l.y,i.aabb.maxx=l.x,i.aabb.maxy=l.y;let r=i.gverts.next.next;for(;r!=null;){let o=r;o.x<i.aabb.minx&&(i.aabb.minx=o.x),o.x>i.aabb.maxx&&(i.aabb.maxx=o.x),o.y<i.aabb.miny&&(i.aabb.miny=o.y),o.y>i.aabb.maxy&&(i.aabb.maxy=o.y),r=r.next;}}let s;if(n.dyn==(t.body.type==1?false:!t.body.component.sleeping)){let i=n.aabb,l=t.aabb;s=!(l.minx>=i.minx&&l.miny>=i.miny&&l.maxx<=i.maxx&&l.maxy<=i.maxy);}else s=true;s&&(n.synced=true,n.snext=this.syncs,this.syncs=n);}}sync_broadphase(){if(this.space.validation(),this.syncs!=null)if(this.moves==null){let t=this.syncs;for(;t!=null;){let s=t.shape;if(t.first_sync)t.first_sync=false;else {let o=t.dyn?this.dtree:this.stree;if(t==o.root)o.root=null;else {let a=t.parent,p=a.parent,c=a.child1==t?a.child2:a.child1;if(p!=null){p.child1==a?p.child1=c:p.child2=c,c.parent=p;let h=a;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Ae.zpp_pool,Ae.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else {let d=x.child1,f=x.child2,g=f.height-d.height;if(g>1){let P=f.child1,v=f.child2;if(f.child1=x,f.parent=x.parent,x.parent=f,f.parent!=null?f.parent.child1==x?f.parent.child1=f:f.parent.child2=f:o.root=f,P.height>v.height){f.child2=P,x.child2=v,v.parent=x;let N=x.aabb,E=d.aabb,M=v.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=f.aabb,C=x.aabb,S=P.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=d.height,F=v.height;x.height=1+(O>F?O:F);let T=x.height,R=P.height;f.height=1+(T>R?T:R);}else {f.child2=v,x.child2=P,P.parent=x;let N=x.aabb,E=d.aabb,M=P.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=f.aabb,C=x.aabb,S=v.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=d.height,F=P.height;x.height=1+(O>F?O:F);let T=x.height,R=v.height;f.height=1+(T>R?T:R);}x=f;}else if(g<-1){let P=d.child1,v=d.child2;if(d.child1=x,d.parent=x.parent,x.parent=d,d.parent!=null?d.parent.child1==x?d.parent.child1=d:d.parent.child2=d:o.root=d,P.height>v.height){d.child2=P,x.child1=v,v.parent=x;let N=x.aabb,E=f.aabb,M=v.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=d.aabb,C=x.aabb,S=P.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=f.height,F=v.height;x.height=1+(O>F?O:F);let T=x.height,R=P.height;d.height=1+(T>R?T:R);}else {d.child2=v,x.child1=P,P.parent=x;let N=x.aabb,E=f.aabb,M=P.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=d.aabb,C=x.aabb,S=v.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=f.height,F=P.height;x.height=1+(O>F?O:F);let T=x.height,R=v.height;d.height=1+(T>R?T:R);}x=d;}else x=x;}let m=x.child1,_=x.child2,y=x.aabb,z=m.aabb,b=_.aabb;y.minx=z.minx<b.minx?z.minx:b.minx,y.miny=z.miny<b.miny?z.miny:b.miny,y.maxx=z.maxx>b.maxx?z.maxx:b.maxx,y.maxy=z.maxy>b.maxy?z.maxy:b.maxy;let w=m.height,Z=_.height;x.height=1+(w>Z?w:Z),x=x.parent;}}else {o.root=c,c.parent=null;let h=a;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Ae.zpp_pool,Ae.zpp_pool=h;}}}let i=t.aabb;if(!this.space.continuous&&s.zip_aabb&&s.body!=null)if(s.zip_aabb=false,s.type==0){let o=s.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=false,o.zip_localCOM){if(o.zip_localCOM=false,o.type==1){let h=o.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let u=1;h.localCOMx+=h.lverts.next.next.x*u,h.localCOMy+=h.lverts.next.next.y*u;let x=.5;h.localCOMx*=x,h.localCOMy*=x;}else {h.localCOMx=0,h.localCOMy=0;let u=0,x=h.lverts.next,m=x;x=x.next;let _=x;for(x=x.next;x!=null;){let d=x;u+=_.x*(d.y-m.y);let f=d.y*_.x-d.x*_.y;h.localCOMx+=(_.x+d.x)*f,h.localCOMy+=(_.y+d.y)*f,m=_,_=d,x=x.next;}x=h.lverts.next;let y=x;u+=_.x*(y.y-m.y);let z=y.y*_.x-y.x*_.y;h.localCOMx+=(_.x+y.x)*z,h.localCOMy+=(_.y+y.y)*z,m=_,_=y,x=x.next;let b=x;u+=_.x*(b.y-m.y);let w=b.y*_.x-b.x*_.y;h.localCOMx+=(_.x+b.x)*w,h.localCOMy+=(_.y+b.y)*w,u=1/(3*u);let Z=u;h.localCOMx*=Z,h.localCOMy*=Z;}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy);}let c=o.body;c.zip_axis&&(c.zip_axis=false,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy);}let a=o.radius,p=o.radius;o.aabb.minx=o.worldCOMx-a,o.aabb.miny=o.worldCOMy-p,o.aabb.maxx=o.worldCOMx+a,o.aabb.maxy=o.worldCOMy+p;}else {let o=s.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=false,o.validate_lverts();let c=o.body;c.zip_axis&&(c.zip_axis=false,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=o.lverts.next,u=o.gverts.next;for(;u!=null;){let x=u,m=h;h=h.next,x.x=o.body.posx+(o.body.axisy*m.x-o.body.axisx*m.y),x.y=o.body.posy+(m.x*o.body.axisx+m.y*o.body.axisy),u=u.next;}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let a=o.gverts.next;o.aabb.minx=a.x,o.aabb.miny=a.y,o.aabb.maxx=a.x,o.aabb.maxy=a.y;let p=o.gverts.next.next;for(;p!=null;){let c=p;c.x<o.aabb.minx&&(o.aabb.minx=c.x),c.x>o.aabb.maxx&&(o.aabb.maxx=c.x),c.y<o.aabb.miny&&(o.aabb.miny=c.y),c.y>o.aabb.maxy&&(o.aabb.maxy=c.y),p=p.next;}}let l=s.aabb;i.minx=l.minx-3,i.miny=l.miny-3,i.maxx=l.maxx+3,i.maxy=l.maxy+3;let r=(t.dyn=s.body.type==1?false:!s.body.component.sleeping)?this.dtree:this.stree;if(r.root==null)r.root=t,r.root.parent=null;else {let o=t.aabb,a=r.root;for(;a.child1!=null;){let m=a.child1,_=a.child2,y=a.aabb,z=(y.maxx-y.minx+(y.maxy-y.miny))*2,b=Qe.tmpaabb,w=a.aabb;b.minx=w.minx<o.minx?w.minx:o.minx,b.miny=w.miny<o.miny?w.miny:o.miny,b.maxx=w.maxx>o.maxx?w.maxx:o.maxx,b.maxy=w.maxy>o.maxy?w.maxy:o.maxy;let Z=Qe.tmpaabb,d=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,f=2*d,g=2*(d-z),P=Qe.tmpaabb,v=m.aabb;P.minx=o.minx<v.minx?o.minx:v.minx,P.miny=o.miny<v.miny?o.miny:v.miny,P.maxx=o.maxx>v.maxx?o.maxx:v.maxx,P.maxy=o.maxy>v.maxy?o.maxy:v.maxy;let N;if(m.child1==null){let C=Qe.tmpaabb;N=(C.maxx-C.minx+(C.maxy-C.miny))*2+g;}else {let C=m.aabb,S=(C.maxx-C.minx+(C.maxy-C.miny))*2,O=Qe.tmpaabb;N=(O.maxx-O.minx+(O.maxy-O.miny))*2-S+g;}let E=Qe.tmpaabb,M=_.aabb;E.minx=o.minx<M.minx?o.minx:M.minx,E.miny=o.miny<M.miny?o.miny:M.miny,E.maxx=o.maxx>M.maxx?o.maxx:M.maxx,E.maxy=o.maxy>M.maxy?o.maxy:M.maxy;let k;if(_.child1==null){let C=Qe.tmpaabb;k=(C.maxx-C.minx+(C.maxy-C.miny))*2+g;}else {let C=_.aabb,S=(C.maxx-C.minx+(C.maxy-C.miny))*2,O=Qe.tmpaabb;k=(O.maxx-O.minx+(O.maxy-O.miny))*2-S+g;}if(f<N&&f<k)break;a=N<k?m:_;}let p=a,c=p.parent,h;Ae.zpp_pool==null?h=new Ae:(h=Ae.zpp_pool,Ae.zpp_pool=h.next,h.next=null),be.zpp_pool==null?h.aabb=new be:(h.aabb=be.zpp_pool,be.zpp_pool=h.aabb.next,h.aabb.next=null),h.moved=false,h.synced=false,h.first_sync=false,h.parent=c;let u=h.aabb,x=p.aabb;for(u.minx=o.minx<x.minx?o.minx:x.minx,u.miny=o.miny<x.miny?o.miny:x.miny,u.maxx=o.maxx>x.maxx?o.maxx:x.maxx,u.maxy=o.maxy>x.maxy?o.maxy:x.maxy,h.height=p.height+1,c!=null?(c.child1==p?c.child1=h:c.child2=h,h.child1=p,h.child2=t,p.parent=h,t.parent=h):(h.child1=p,h.child2=t,p.parent=h,t.parent=h,r.root=h),a=t.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else {let d=a.child1,f=a.child2,g=f.height-d.height;if(g>1){let P=f.child1,v=f.child2;if(f.child1=a,f.parent=a.parent,a.parent=f,f.parent!=null?f.parent.child1==a?f.parent.child1=f:f.parent.child2=f:r.root=f,P.height>v.height){f.child2=P,a.child2=v,v.parent=a;let N=a.aabb,E=d.aabb,M=v.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=f.aabb,C=a.aabb,S=P.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=d.height,F=v.height;a.height=1+(O>F?O:F);let T=a.height,R=P.height;f.height=1+(T>R?T:R);}else {f.child2=v,a.child2=P,P.parent=a;let N=a.aabb,E=d.aabb,M=P.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=f.aabb,C=a.aabb,S=v.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=d.height,F=P.height;a.height=1+(O>F?O:F);let T=a.height,R=v.height;f.height=1+(T>R?T:R);}a=f;}else if(g<-1){let P=d.child1,v=d.child2;if(d.child1=a,d.parent=a.parent,a.parent=d,d.parent!=null?d.parent.child1==a?d.parent.child1=d:d.parent.child2=d:r.root=d,P.height>v.height){d.child2=P,a.child1=v,v.parent=a;let N=a.aabb,E=f.aabb,M=v.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=d.aabb,C=a.aabb,S=P.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=f.height,F=v.height;a.height=1+(O>F?O:F);let T=a.height,R=P.height;d.height=1+(T>R?T:R);}else {d.child2=v,a.child1=P,P.parent=a;let N=a.aabb,E=f.aabb,M=P.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=d.aabb,C=a.aabb,S=v.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=f.height,F=P.height;a.height=1+(O>F?O:F);let T=a.height,R=v.height;d.height=1+(T>R?T:R);}a=d;}else a=a;}let m=a.child1,_=a.child2,y=m.height,z=_.height;a.height=1+(y>z?y:z);let b=a.aabb,w=m.aabb,Z=_.aabb;b.minx=w.minx<Z.minx?w.minx:Z.minx,b.miny=w.miny<Z.miny?w.miny:Z.miny,b.maxx=w.maxx>Z.maxx?w.maxx:Z.maxx,b.maxy=w.maxy>Z.maxy?w.maxy:Z.maxy,a=a.parent;}}t.synced=false,t.moved=true,t.mnext=t.snext,t.snext=null,t=t.mnext;}let n=this.syncs;this.syncs=this.moves,this.moves=n;}else for(;this.syncs!=null;){let t=this.syncs;this.syncs=t.snext,t.snext=null;let n=t,s=n.shape;if(n.first_sync)n.first_sync=false;else {let o=n.dyn?this.dtree:this.stree;if(n==o.root)o.root=null;else {let a=n.parent,p=a.parent,c=a.child1==n?a.child2:a.child1;if(p!=null){p.child1==a?p.child1=c:p.child2=c,c.parent=p;let h=a;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Ae.zpp_pool,Ae.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else {let d=x.child1,f=x.child2,g=f.height-d.height;if(g>1){let P=f.child1,v=f.child2;if(f.child1=x,f.parent=x.parent,x.parent=f,f.parent!=null?f.parent.child1==x?f.parent.child1=f:f.parent.child2=f:o.root=f,P.height>v.height){f.child2=P,x.child2=v,v.parent=x;let N=x.aabb,E=d.aabb,M=v.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=f.aabb,C=x.aabb,S=P.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=d.height,F=v.height;x.height=1+(O>F?O:F);let T=x.height,R=P.height;f.height=1+(T>R?T:R);}else {f.child2=v,x.child2=P,P.parent=x;let N=x.aabb,E=d.aabb,M=P.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=f.aabb,C=x.aabb,S=v.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=d.height,F=P.height;x.height=1+(O>F?O:F);let T=x.height,R=v.height;f.height=1+(T>R?T:R);}x=f;}else if(g<-1){let P=d.child1,v=d.child2;if(d.child1=x,d.parent=x.parent,x.parent=d,d.parent!=null?d.parent.child1==x?d.parent.child1=d:d.parent.child2=d:o.root=d,P.height>v.height){d.child2=P,x.child1=v,v.parent=x;let N=x.aabb,E=f.aabb,M=v.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=d.aabb,C=x.aabb,S=P.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=f.height,F=v.height;x.height=1+(O>F?O:F);let T=x.height,R=P.height;d.height=1+(T>R?T:R);}else {d.child2=v,x.child1=P,P.parent=x;let N=x.aabb,E=f.aabb,M=P.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=d.aabb,C=x.aabb,S=v.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=f.height,F=P.height;x.height=1+(O>F?O:F);let T=x.height,R=v.height;d.height=1+(T>R?T:R);}x=d;}else x=x;}let m=x.child1,_=x.child2,y=x.aabb,z=m.aabb,b=_.aabb;y.minx=z.minx<b.minx?z.minx:b.minx,y.miny=z.miny<b.miny?z.miny:b.miny,y.maxx=z.maxx>b.maxx?z.maxx:b.maxx,y.maxy=z.maxy>b.maxy?z.maxy:b.maxy;let w=m.height,Z=_.height;x.height=1+(w>Z?w:Z),x=x.parent;}}else {o.root=c,c.parent=null;let h=a;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=be.zpp_pool,be.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Ae.zpp_pool,Ae.zpp_pool=h;}}}let i=n.aabb;if(!this.space.continuous&&s.zip_aabb&&s.body!=null)if(s.zip_aabb=false,s.type==0){let o=s.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=false,o.zip_localCOM){if(o.zip_localCOM=false,o.type==1){let h=o.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let u=1;h.localCOMx+=h.lverts.next.next.x*u,h.localCOMy+=h.lverts.next.next.y*u;let x=.5;h.localCOMx*=x,h.localCOMy*=x;}else {h.localCOMx=0,h.localCOMy=0;let u=0,x=h.lverts.next,m=x;x=x.next;let _=x;for(x=x.next;x!=null;){let d=x;u+=_.x*(d.y-m.y);let f=d.y*_.x-d.x*_.y;h.localCOMx+=(_.x+d.x)*f,h.localCOMy+=(_.y+d.y)*f,m=_,_=d,x=x.next;}x=h.lverts.next;let y=x;u+=_.x*(y.y-m.y);let z=y.y*_.x-y.x*_.y;h.localCOMx+=(_.x+y.x)*z,h.localCOMy+=(_.y+y.y)*z,m=_,_=y,x=x.next;let b=x;u+=_.x*(b.y-m.y);let w=b.y*_.x-b.x*_.y;h.localCOMx+=(_.x+b.x)*w,h.localCOMy+=(_.y+b.y)*w,u=1/(3*u);let Z=u;h.localCOMx*=Z,h.localCOMy*=Z;}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy);}let c=o.body;c.zip_axis&&(c.zip_axis=false,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy);}let a=o.radius,p=o.radius;o.aabb.minx=o.worldCOMx-a,o.aabb.miny=o.worldCOMy-p,o.aabb.maxx=o.worldCOMx+a,o.aabb.maxy=o.worldCOMy+p;}else {let o=s.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=false,o.validate_lverts();let c=o.body;c.zip_axis&&(c.zip_axis=false,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=o.lverts.next,u=o.gverts.next;for(;u!=null;){let x=u,m=h;h=h.next,x.x=o.body.posx+(o.body.axisy*m.x-o.body.axisx*m.y),x.y=o.body.posy+(m.x*o.body.axisx+m.y*o.body.axisy),u=u.next;}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let a=o.gverts.next;o.aabb.minx=a.x,o.aabb.miny=a.y,o.aabb.maxx=a.x,o.aabb.maxy=a.y;let p=o.gverts.next.next;for(;p!=null;){let c=p;c.x<o.aabb.minx&&(o.aabb.minx=c.x),c.x>o.aabb.maxx&&(o.aabb.maxx=c.x),c.y<o.aabb.miny&&(o.aabb.miny=c.y),c.y>o.aabb.maxy&&(o.aabb.maxy=c.y),p=p.next;}}let l=s.aabb;i.minx=l.minx-3,i.miny=l.miny-3,i.maxx=l.maxx+3,i.maxy=l.maxy+3;let r=(n.dyn=s.body.type==1?false:!s.body.component.sleeping)?this.dtree:this.stree;if(r.root==null)r.root=n,r.root.parent=null;else {let o=n.aabb,a=r.root;for(;a.child1!=null;){let m=a.child1,_=a.child2,y=a.aabb,z=(y.maxx-y.minx+(y.maxy-y.miny))*2,b=Qe.tmpaabb,w=a.aabb;b.minx=w.minx<o.minx?w.minx:o.minx,b.miny=w.miny<o.miny?w.miny:o.miny,b.maxx=w.maxx>o.maxx?w.maxx:o.maxx,b.maxy=w.maxy>o.maxy?w.maxy:o.maxy;let Z=Qe.tmpaabb,d=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,f=2*d,g=2*(d-z),P=Qe.tmpaabb,v=m.aabb;P.minx=o.minx<v.minx?o.minx:v.minx,P.miny=o.miny<v.miny?o.miny:v.miny,P.maxx=o.maxx>v.maxx?o.maxx:v.maxx,P.maxy=o.maxy>v.maxy?o.maxy:v.maxy;let N;if(m.child1==null){let C=Qe.tmpaabb;N=(C.maxx-C.minx+(C.maxy-C.miny))*2+g;}else {let C=m.aabb,S=(C.maxx-C.minx+(C.maxy-C.miny))*2,O=Qe.tmpaabb;N=(O.maxx-O.minx+(O.maxy-O.miny))*2-S+g;}let E=Qe.tmpaabb,M=_.aabb;E.minx=o.minx<M.minx?o.minx:M.minx,E.miny=o.miny<M.miny?o.miny:M.miny,E.maxx=o.maxx>M.maxx?o.maxx:M.maxx,E.maxy=o.maxy>M.maxy?o.maxy:M.maxy;let k;if(_.child1==null){let C=Qe.tmpaabb;k=(C.maxx-C.minx+(C.maxy-C.miny))*2+g;}else {let C=_.aabb,S=(C.maxx-C.minx+(C.maxy-C.miny))*2,O=Qe.tmpaabb;k=(O.maxx-O.minx+(O.maxy-O.miny))*2-S+g;}if(f<N&&f<k)break;a=N<k?m:_;}let p=a,c=p.parent,h;Ae.zpp_pool==null?h=new Ae:(h=Ae.zpp_pool,Ae.zpp_pool=h.next,h.next=null),be.zpp_pool==null?h.aabb=new be:(h.aabb=be.zpp_pool,be.zpp_pool=h.aabb.next,h.aabb.next=null),h.moved=false,h.synced=false,h.first_sync=false,h.parent=c;let u=h.aabb,x=p.aabb;for(u.minx=o.minx<x.minx?o.minx:x.minx,u.miny=o.miny<x.miny?o.miny:x.miny,u.maxx=o.maxx>x.maxx?o.maxx:x.maxx,u.maxy=o.maxy>x.maxy?o.maxy:x.maxy,h.height=p.height+1,c!=null?(c.child1==p?c.child1=h:c.child2=h,h.child1=p,h.child2=n,p.parent=h,n.parent=h):(h.child1=p,h.child2=n,p.parent=h,n.parent=h,r.root=h),a=n.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else {let d=a.child1,f=a.child2,g=f.height-d.height;if(g>1){let P=f.child1,v=f.child2;if(f.child1=a,f.parent=a.parent,a.parent=f,f.parent!=null?f.parent.child1==a?f.parent.child1=f:f.parent.child2=f:r.root=f,P.height>v.height){f.child2=P,a.child2=v,v.parent=a;let N=a.aabb,E=d.aabb,M=v.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=f.aabb,C=a.aabb,S=P.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=d.height,F=v.height;a.height=1+(O>F?O:F);let T=a.height,R=P.height;f.height=1+(T>R?T:R);}else {f.child2=v,a.child2=P,P.parent=a;let N=a.aabb,E=d.aabb,M=P.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=f.aabb,C=a.aabb,S=v.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=d.height,F=P.height;a.height=1+(O>F?O:F);let T=a.height,R=v.height;f.height=1+(T>R?T:R);}a=f;}else if(g<-1){let P=d.child1,v=d.child2;if(d.child1=a,d.parent=a.parent,a.parent=d,d.parent!=null?d.parent.child1==a?d.parent.child1=d:d.parent.child2=d:r.root=d,P.height>v.height){d.child2=P,a.child1=v,v.parent=a;let N=a.aabb,E=f.aabb,M=v.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=d.aabb,C=a.aabb,S=P.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=f.height,F=v.height;a.height=1+(O>F?O:F);let T=a.height,R=P.height;d.height=1+(T>R?T:R);}else {d.child2=v,a.child1=P,P.parent=a;let N=a.aabb,E=f.aabb,M=P.aabb;N.minx=E.minx<M.minx?E.minx:M.minx,N.miny=E.miny<M.miny?E.miny:M.miny,N.maxx=E.maxx>M.maxx?E.maxx:M.maxx,N.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let k=d.aabb,C=a.aabb,S=v.aabb;k.minx=C.minx<S.minx?C.minx:S.minx,k.miny=C.miny<S.miny?C.miny:S.miny,k.maxx=C.maxx>S.maxx?C.maxx:S.maxx,k.maxy=C.maxy>S.maxy?C.maxy:S.maxy;let O=f.height,F=P.height;a.height=1+(O>F?O:F);let T=a.height,R=v.height;d.height=1+(T>R?T:R);}a=d;}else a=a;}let m=a.child1,_=a.child2,y=m.height,z=_.height;a.height=1+(y>z?y:z);let b=a.aabb,w=m.aabb,Z=_.aabb;b.minx=w.minx<Z.minx?w.minx:Z.minx,b.miny=w.miny<Z.miny?w.miny:Z.miny,b.maxx=w.maxx>Z.maxx?w.maxx:Z.maxx,b.maxy=w.maxy>Z.maxy?w.maxy:Z.maxy,a=a.parent;}}n.synced=false,n.moved||(n.moved=true,n.mnext=this.moves,this.moves=n);}}broadphase(t,n){let s=this.syncs;for(;s!=null;){let l=s.shape;if(s.first_sync)s.first_sync=false;else {let p=s.dyn?this.dtree:this.stree;if(s==p.root)p.root=null;else {let c=s.parent,h=c.parent,u=c.child1==s?c.child2:c.child1;if(h!=null){h.child1==c?h.child1=u:h.child2=u,u.parent=h;let x=c;x.height=-1;let m=x.aabb;m.outer!=null&&(m.outer.zpp_inner=null,m.outer=null),m.wrap_min=m.wrap_max=null,m._invalidate=null,m._validate=null,m.next=be.zpp_pool,be.zpp_pool=m,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ae.zpp_pool,Ae.zpp_pool=x;let _=h;for(;_!=null;){if(_.child1==null||_.height<2)_=_;else {let g=_.child1,P=_.child2,v=P.height-g.height;if(v>1){let N=P.child1,E=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,N.height>E.height){P.child2=N,_.child2=E,E.parent=_;let M=_.aabb,k=g.aabb,C=E.aabb;M.minx=k.minx<C.minx?k.minx:C.minx,M.miny=k.miny<C.miny?k.miny:C.miny,M.maxx=k.maxx>C.maxx?k.maxx:C.maxx,M.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let S=P.aabb,O=_.aabb,F=N.aabb;S.minx=O.minx<F.minx?O.minx:F.minx,S.miny=O.miny<F.miny?O.miny:F.miny,S.maxx=O.maxx>F.maxx?O.maxx:F.maxx,S.maxy=O.maxy>F.maxy?O.maxy:F.maxy;let T=g.height,R=E.height;_.height=1+(T>R?T:R);let W=_.height,G=N.height;P.height=1+(W>G?W:G);}else {P.child2=E,_.child2=N,N.parent=_;let M=_.aabb,k=g.aabb,C=N.aabb;M.minx=k.minx<C.minx?k.minx:C.minx,M.miny=k.miny<C.miny?k.miny:C.miny,M.maxx=k.maxx>C.maxx?k.maxx:C.maxx,M.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let S=P.aabb,O=_.aabb,F=E.aabb;S.minx=O.minx<F.minx?O.minx:F.minx,S.miny=O.miny<F.miny?O.miny:F.miny,S.maxx=O.maxx>F.maxx?O.maxx:F.maxx,S.maxy=O.maxy>F.maxy?O.maxy:F.maxy;let T=g.height,R=N.height;_.height=1+(T>R?T:R);let W=_.height,G=E.height;P.height=1+(W>G?W:G);}_=P;}else if(v<-1){let N=g.child1,E=g.child2;if(g.child1=_,g.parent=_.parent,_.parent=g,g.parent!=null?g.parent.child1==_?g.parent.child1=g:g.parent.child2=g:p.root=g,N.height>E.height){g.child2=N,_.child1=E,E.parent=_;let M=_.aabb,k=P.aabb,C=E.aabb;M.minx=k.minx<C.minx?k.minx:C.minx,M.miny=k.miny<C.miny?k.miny:C.miny,M.maxx=k.maxx>C.maxx?k.maxx:C.maxx,M.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let S=g.aabb,O=_.aabb,F=N.aabb;S.minx=O.minx<F.minx?O.minx:F.minx,S.miny=O.miny<F.miny?O.miny:F.miny,S.maxx=O.maxx>F.maxx?O.maxx:F.maxx,S.maxy=O.maxy>F.maxy?O.maxy:F.maxy;let T=P.height,R=E.height;_.height=1+(T>R?T:R);let W=_.height,G=N.height;g.height=1+(W>G?W:G);}else {g.child2=E,_.child1=N,N.parent=_;let M=_.aabb,k=P.aabb,C=N.aabb;M.minx=k.minx<C.minx?k.minx:C.minx,M.miny=k.miny<C.miny?k.miny:C.miny,M.maxx=k.maxx>C.maxx?k.maxx:C.maxx,M.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let S=g.aabb,O=_.aabb,F=E.aabb;S.minx=O.minx<F.minx?O.minx:F.minx,S.miny=O.miny<F.miny?O.miny:F.miny,S.maxx=O.maxx>F.maxx?O.maxx:F.maxx,S.maxy=O.maxy>F.maxy?O.maxy:F.maxy;let T=P.height,R=N.height;_.height=1+(T>R?T:R);let W=_.height,G=E.height;g.height=1+(W>G?W:G);}_=g;}else _=_;}let y=_.child1,z=_.child2,b=_.aabb,w=y.aabb,Z=z.aabb;b.minx=w.minx<Z.minx?w.minx:Z.minx,b.miny=w.miny<Z.miny?w.miny:Z.miny,b.maxx=w.maxx>Z.maxx?w.maxx:Z.maxx,b.maxy=w.maxy>Z.maxy?w.maxy:Z.maxy;let d=y.height,f=z.height;_.height=1+(d>f?d:f),_=_.parent;}}else {p.root=u,u.parent=null;let x=c;x.height=-1;let m=x.aabb;m.outer!=null&&(m.outer.zpp_inner=null,m.outer=null),m.wrap_min=m.wrap_max=null,m._invalidate=null,m._validate=null,m.next=be.zpp_pool,be.zpp_pool=m,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ae.zpp_pool,Ae.zpp_pool=x;}}}let r=s.aabb;if(!t.continuous&&l.zip_aabb&&l.body!=null)if(l.zip_aabb=false,l.type==0){let p=l.circle;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=false,p.zip_localCOM){if(p.zip_localCOM=false,p.type==1){let x=p.polygon;if(x.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(x.lverts.next.next==null)x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;else if(x.lverts.next.next.next==null){x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;let m=1;x.localCOMx+=x.lverts.next.next.x*m,x.localCOMy+=x.lverts.next.next.y*m;let _=.5;x.localCOMx*=_,x.localCOMy*=_;}else {x.localCOMx=0,x.localCOMy=0;let m=0,_=x.lverts.next,y=_;_=_.next;let z=_;for(_=_.next;_!=null;){let g=_;m+=z.x*(g.y-y.y);let P=g.y*z.x-g.x*z.y;x.localCOMx+=(z.x+g.x)*P,x.localCOMy+=(z.y+g.y)*P,y=z,z=g,_=_.next;}_=x.lverts.next;let b=_;m+=z.x*(b.y-y.y);let w=b.y*z.x-b.x*z.y;x.localCOMx+=(z.x+b.x)*w,x.localCOMy+=(z.y+b.y)*w,y=z,z=b,_=_.next;let Z=_;m+=z.x*(Z.y-y.y);let d=Z.y*z.x-Z.x*z.y;x.localCOMx+=(z.x+Z.x)*d,x.localCOMy+=(z.y+Z.y)*d,m=1/(3*m);let f=m;x.localCOMx*=f,x.localCOMy*=f;}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy);}let u=p.body;u.zip_axis&&(u.zip_axis=false,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy);}let c=p.radius,h=p.radius;p.aabb.minx=p.worldCOMx-c,p.aabb.miny=p.worldCOMy-h,p.aabb.maxx=p.worldCOMx+c,p.aabb.maxy=p.worldCOMy+h;}else {let p=l.polygon;if(p.zip_gverts&&p.body!=null){p.zip_gverts=false,p.validate_lverts();let u=p.body;u.zip_axis&&(u.zip_axis=false,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let x=p.lverts.next,m=p.gverts.next;for(;m!=null;){let _=m,y=x;x=x.next,_.x=p.body.posx+(p.body.axisy*y.x-p.body.axisx*y.y),_.y=p.body.posy+(y.x*p.body.axisx+y.y*p.body.axisy),m=m.next;}}if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let c=p.gverts.next;p.aabb.minx=c.x,p.aabb.miny=c.y,p.aabb.maxx=c.x,p.aabb.maxy=c.y;let h=p.gverts.next.next;for(;h!=null;){let u=h;u.x<p.aabb.minx&&(p.aabb.minx=u.x),u.x>p.aabb.maxx&&(p.aabb.maxx=u.x),u.y<p.aabb.miny&&(p.aabb.miny=u.y),u.y>p.aabb.maxy&&(p.aabb.maxy=u.y),h=h.next;}}let o=l.aabb;r.minx=o.minx-3,r.miny=o.miny-3,r.maxx=o.maxx+3,r.maxy=o.maxy+3;let a=(s.dyn=l.body.type==1?false:!l.body.component.sleeping)?this.dtree:this.stree;if(a.root==null)a.root=s,a.root.parent=null;else {let p=s.aabb,c=a.root;for(;c.child1!=null;){let y=c.child1,z=c.child2,b=c.aabb,w=(b.maxx-b.minx+(b.maxy-b.miny))*2,Z=Qe.tmpaabb,d=c.aabb;Z.minx=d.minx<p.minx?d.minx:p.minx,Z.miny=d.miny<p.miny?d.miny:p.miny,Z.maxx=d.maxx>p.maxx?d.maxx:p.maxx,Z.maxy=d.maxy>p.maxy?d.maxy:p.maxy;let f=Qe.tmpaabb,g=(f.maxx-f.minx+(f.maxy-f.miny))*2,P=2*g,v=2*(g-w),N=Qe.tmpaabb,E=y.aabb;N.minx=p.minx<E.minx?p.minx:E.minx,N.miny=p.miny<E.miny?p.miny:E.miny,N.maxx=p.maxx>E.maxx?p.maxx:E.maxx,N.maxy=p.maxy>E.maxy?p.maxy:E.maxy;let M;if(y.child1==null){let O=Qe.tmpaabb;M=(O.maxx-O.minx+(O.maxy-O.miny))*2+v;}else {let O=y.aabb,F=(O.maxx-O.minx+(O.maxy-O.miny))*2,T=Qe.tmpaabb;M=(T.maxx-T.minx+(T.maxy-T.miny))*2-F+v;}let k=Qe.tmpaabb,C=z.aabb;k.minx=p.minx<C.minx?p.minx:C.minx,k.miny=p.miny<C.miny?p.miny:C.miny,k.maxx=p.maxx>C.maxx?p.maxx:C.maxx,k.maxy=p.maxy>C.maxy?p.maxy:C.maxy;let S;if(z.child1==null){let O=Qe.tmpaabb;S=(O.maxx-O.minx+(O.maxy-O.miny))*2+v;}else {let O=z.aabb,F=(O.maxx-O.minx+(O.maxy-O.miny))*2,T=Qe.tmpaabb;S=(T.maxx-T.minx+(T.maxy-T.miny))*2-F+v;}if(P<M&&P<S)break;c=M<S?y:z;}let h=c,u=h.parent,x;Ae.zpp_pool==null?x=new Ae:(x=Ae.zpp_pool,Ae.zpp_pool=x.next,x.next=null),be.zpp_pool==null?x.aabb=new be:(x.aabb=be.zpp_pool,be.zpp_pool=x.aabb.next,x.aabb.next=null),x.moved=false,x.synced=false,x.first_sync=false,x.parent=u;let m=x.aabb,_=h.aabb;for(m.minx=p.minx<_.minx?p.minx:_.minx,m.miny=p.miny<_.miny?p.miny:_.miny,m.maxx=p.maxx>_.maxx?p.maxx:_.maxx,m.maxy=p.maxy>_.maxy?p.maxy:_.maxy,x.height=h.height+1,u!=null?(u.child1==h?u.child1=x:u.child2=x,x.child1=h,x.child2=s,h.parent=x,s.parent=x):(x.child1=h,x.child2=s,h.parent=x,s.parent=x,a.root=x),c=s.parent;c!=null;){if(c.child1==null||c.height<2)c=c;else {let g=c.child1,P=c.child2,v=P.height-g.height;if(v>1){let N=P.child1,E=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,N.height>E.height){P.child2=N,c.child2=E,E.parent=c;let M=c.aabb,k=g.aabb,C=E.aabb;M.minx=k.minx<C.minx?k.minx:C.minx,M.miny=k.miny<C.miny?k.miny:C.miny,M.maxx=k.maxx>C.maxx?k.maxx:C.maxx,M.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let S=P.aabb,O=c.aabb,F=N.aabb;S.minx=O.minx<F.minx?O.minx:F.minx,S.miny=O.miny<F.miny?O.miny:F.miny,S.maxx=O.maxx>F.maxx?O.maxx:F.maxx,S.maxy=O.maxy>F.maxy?O.maxy:F.maxy;let T=g.height,R=E.height;c.height=1+(T>R?T:R);let W=c.height,G=N.height;P.height=1+(W>G?W:G);}else {P.child2=E,c.child2=N,N.parent=c;let M=c.aabb,k=g.aabb,C=N.aabb;M.minx=k.minx<C.minx?k.minx:C.minx,M.miny=k.miny<C.miny?k.miny:C.miny,M.maxx=k.maxx>C.maxx?k.maxx:C.maxx,M.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let S=P.aabb,O=c.aabb,F=E.aabb;S.minx=O.minx<F.minx?O.minx:F.minx,S.miny=O.miny<F.miny?O.miny:F.miny,S.maxx=O.maxx>F.maxx?O.maxx:F.maxx,S.maxy=O.maxy>F.maxy?O.maxy:F.maxy;let T=g.height,R=N.height;c.height=1+(T>R?T:R);let W=c.height,G=E.height;P.height=1+(W>G?W:G);}c=P;}else if(v<-1){let N=g.child1,E=g.child2;if(g.child1=c,g.parent=c.parent,c.parent=g,g.parent!=null?g.parent.child1==c?g.parent.child1=g:g.parent.child2=g:a.root=g,N.height>E.height){g.child2=N,c.child1=E,E.parent=c;let M=c.aabb,k=P.aabb,C=E.aabb;M.minx=k.minx<C.minx?k.minx:C.minx,M.miny=k.miny<C.miny?k.miny:C.miny,M.maxx=k.maxx>C.maxx?k.maxx:C.maxx,M.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let S=g.aabb,O=c.aabb,F=N.aabb;S.minx=O.minx<F.minx?O.minx:F.minx,S.miny=O.miny<F.miny?O.miny:F.miny,S.maxx=O.maxx>F.maxx?O.maxx:F.maxx,S.maxy=O.maxy>F.maxy?O.maxy:F.maxy;let T=P.height,R=E.height;c.height=1+(T>R?T:R);let W=c.height,G=N.height;g.height=1+(W>G?W:G);}else {g.child2=E,c.child1=N,N.parent=c;let M=c.aabb,k=P.aabb,C=N.aabb;M.minx=k.minx<C.minx?k.minx:C.minx,M.miny=k.miny<C.miny?k.miny:C.miny,M.maxx=k.maxx>C.maxx?k.maxx:C.maxx,M.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let S=g.aabb,O=c.aabb,F=E.aabb;S.minx=O.minx<F.minx?O.minx:F.minx,S.miny=O.miny<F.miny?O.miny:F.miny,S.maxx=O.maxx>F.maxx?O.maxx:F.maxx,S.maxy=O.maxy>F.maxy?O.maxy:F.maxy;let T=P.height,R=N.height;c.height=1+(T>R?T:R);let W=c.height,G=E.height;g.height=1+(W>G?W:G);}c=g;}else c=c;}let y=c.child1,z=c.child2,b=y.height,w=z.height;c.height=1+(b>w?b:w);let Z=c.aabb,d=y.aabb,f=z.aabb;Z.minx=d.minx<f.minx?d.minx:f.minx,Z.miny=d.miny<f.miny?d.miny:f.miny,Z.maxx=d.maxx>f.maxx?d.maxx:f.maxx,Z.maxy=d.maxy>f.maxy?d.maxy:f.maxy,c=c.parent;}}s.synced=false,s=s.snext;}for(;this.syncs!=null;){let l=this.syncs;this.syncs=l.snext,l.snext=null;let r=l;if(r.moved)continue;r.moved=false;let o=r.shape;if(o.body.component.sleeping)continue;let p=r.aabb,c=null;for(this.dtree.root!=null&&(this.dtree.root.next=c,c=this.dtree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=r)if(u.child1==null){let x=u.shape;if(x.body!=o.body&&!(x.body.type==1&&o.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let _,y;o.id<x.id?(_=o.id,y=x.id):(_=x.id,y=o.id);let z=o.pairs.length<x.pairs.length?o:x,b=null,w=z.pairs.head;for(;w!=null;){let N=w.elt;if(N.id==_&&N.di==y){b=N;break}w=w.next;}if(b!=null){b.sleeping&&(b.sleeping=false,this._linkPair(b),b.first=true);continue}lt.zpp_pool==null?b=new lt:(b=lt.zpp_pool,lt.zpp_pool=b.next,b.next=null),b.n1=r,b.n2=u,b.id=_,b.di=y,this._linkPair(b),b.first=true;let Z=o.pairs,d;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(d=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=b;let f=d;f.next=Z.head,Z.head=f,Z.modified=true,Z.length++;let g=x.pairs,P;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(P=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=b;let v=P;v.next=g.head,g.head=v,g.modified=true,g.length++;}}}else {let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2));}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=r)if(u.child1==null){let x=u.shape;if(x.body!=o.body&&!(x.body.type==1&&o.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let _,y;o.id<x.id?(_=o.id,y=x.id):(_=x.id,y=o.id);let z=o.pairs.length<x.pairs.length?o:x,b=null,w=z.pairs.head;for(;w!=null;){let N=w.elt;if(N.id==_&&N.di==y){b=N;break}w=w.next;}if(b!=null){b.sleeping&&(b.sleeping=false,this._linkPair(b),b.first=true);continue}lt.zpp_pool==null?b=new lt:(b=lt.zpp_pool,lt.zpp_pool=b.next,b.next=null),b.n1=r,b.n2=u,b.id=_,b.di=y,this._linkPair(b),b.first=true;let Z=o.pairs,d;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(d=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=b;let f=d;f.next=Z.head,Z.head=f,Z.modified=true,Z.length++;let g=x.pairs,P;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(P=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=b;let v=P;v.next=g.head,g.head=v,g.modified=true,g.length++;}}}else {let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2));}}}for(;this.moves!=null;){let l=this.moves;this.moves=l.mnext,l.mnext=null;let r=l;r.moved=false;let o=r.shape;if(o.body.component.sleeping)continue;let p=r.aabb,c=null;for(this.dtree.root!=null&&(this.dtree.root.next=c,c=this.dtree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=r)if(u.child1==null){let x=u.shape;if(x.body!=o.body&&!(x.body.type==1&&o.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let _,y;o.id<x.id?(_=o.id,y=x.id):(_=x.id,y=o.id);let z=o.pairs.length<x.pairs.length?o:x,b=null,w=z.pairs.head;for(;w!=null;){let N=w.elt;if(N.id==_&&N.di==y){b=N;break}w=w.next;}if(b!=null){b.sleeping&&(b.sleeping=false,this._linkPair(b),b.first=true);continue}lt.zpp_pool==null?b=new lt:(b=lt.zpp_pool,lt.zpp_pool=b.next,b.next=null),b.n1=r,b.n2=u,b.id=_,b.di=y,this._linkPair(b),b.first=true;let Z=o.pairs,d;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(d=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=b;let f=d;f.next=Z.head,Z.head=f,Z.modified=true,Z.length++;let g=x.pairs,P;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(P=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=b;let v=P;v.next=g.head,g.head=v,g.modified=true,g.length++;}}}else {let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2));}}for(this.stree.root!=null&&(this.stree.root.next=c,c=this.stree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=r)if(u.child1==null){let x=u.shape;if(x.body!=o.body&&!(x.body.type==1&&o.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let _,y;o.id<x.id?(_=o.id,y=x.id):(_=x.id,y=o.id);let z=o.pairs.length<x.pairs.length?o:x,b=null,w=z.pairs.head;for(;w!=null;){let N=w.elt;if(N.id==_&&N.di==y){b=N;break}w=w.next;}if(b!=null){b.sleeping&&(b.sleeping=false,this._linkPair(b),b.first=true);continue}lt.zpp_pool==null?b=new lt:(b=lt.zpp_pool,lt.zpp_pool=b.next,b.next=null),b.n1=r,b.n2=u,b.id=_,b.di=y,this._linkPair(b),b.first=true;let Z=o.pairs,d;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(d=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=b;let f=d;f.next=Z.head,Z.head=f,Z.modified=true,Z.length++;let g=x.pairs,P;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(P=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=b;let v=P;v.next=g.head,g.head=v,g.modified=true,g.length++;}}}else {let x=u.aabb;x.miny<=p.maxy&&p.miny<=x.maxy&&x.minx<=p.maxx&&p.minx<=x.maxx&&(u.child1!=null&&(u.child1.next=c,c=u.child1),u.child2!=null&&(u.child2.next=c,c=u.child2));}}}let i=this.pairs;for(;i!=null;){let l;if(i.first)l=false;else {let u=i.n1.aabb,x=i.n2.aabb;l=!(x.miny<=u.maxy&&u.miny<=x.maxy&&x.minx<=u.maxx&&u.minx<=x.maxx);}if(l){let u=i.next;this._unlinkPair(i),i.n1.shape.pairs.remove(i),i.n2.shape.pairs.remove(i),i.arb!=null&&(i.arb.pair=null),i.arb=null,i.n1=i.n2=null,i.sleeping=false,i.gprev=null,i.next=lt.zpp_pool,lt.zpp_pool=i,i=u;continue}let r=i.n1.shape,o=r.body,a=i.n2.shape,p=a.body;if(!i.first&&(o.component.sleeping||o.type==1)&&(p.component.sleeping||p.type==1)){i.sleeping=true;let u=i.next;this._unlinkPair(i),i=u;continue}i.first=false;let c=r.aabb,h=a.aabb;if(h.miny<=c.maxy&&c.miny<=h.maxy&&h.minx<=c.maxx&&c.minx<=h.maxx){let u=i.arb;n?i.arb=t.narrowPhase(r,a,o.type!=2||p.type!=2,i.arb,false):i.arb=t.continuousEvent(r,a,o.type!=2||p.type!=2,i.arb,false),i.arb==null?u!=null&&(u.pair=null):i.arb.pair=i;}i=i.next;}}clear(){for(;this.syncs!=null;){let t=this.syncs.snext;this.syncs.snext=null,this.syncs.first_sync&&(this.syncs.shape.node=null,this.syncs.shape.removedFromSpace(),this.syncs.shape=null),this.syncs=t;}for(;this.moves!=null;){let t=this.moves.mnext;this.moves.mnext=null,this.moves.first_sync&&(this.moves.shape.node=null,this.moves.shape.removedFromSpace(),this.moves.shape=null),this.moves=t;}for(;this.pairs!=null;){let t=this.pairs.next,n=this.pairs;n.arb!=null&&(n.arb.pair=null),n.arb=null,n.n1.shape.pairs.remove(n),n.n2.shape.pairs.remove(n),n.n1=n.n2=null,n.sleeping=false,n.gprev=null,n.next=lt.zpp_pool,lt.zpp_pool=n,this.pairs=t;}this.dtree.clear(),this.stree.clear();}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l;ae.zpp_pool==null?l=new ae:(l=ae.zpp_pool,ae.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=false,l.x=t,l.y=n;let r=l,o=i??new ze._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h;if(s!=null){let u=p.shape.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else h=true;h&&(p.shape.type==0?ge.circleContains(p.shape.circle,r)&&o.push(p.shape.outer):ge.polyContains(p.shape.polygon,r)&&o.push(p.shape.outer));}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2);}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h;if(s!=null){let u=p.shape.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else h=true;h&&(p.shape.type==0?ge.circleContains(p.shape.circle,r)&&o.push(p.shape.outer):ge.polyContains(p.shape.polygon,r)&&o.push(p.shape.outer));}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2);}let a=r;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,o}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l;ae.zpp_pool==null?l=new ae:(l=ae.zpp_pool,ae.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=false,l.x=t,l.y=n;let r=l,o=i??new ze._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!o.has(h)){let u;if(s!=null){let x=p.shape.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0;}else u=true;u&&(p.shape.type==0?ge.circleContains(p.shape.circle,r)&&o.push(h):ge.polyContains(p.shape.polygon,r)&&o.push(h));}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2);}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.x>=c.minx&&r.x<=c.maxx&&r.y>=c.miny&&r.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!o.has(h)){let u;if(s!=null){let x=p.shape.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0;}else u=true;u&&(p.shape.type==0?ge.circleContains(p.shape.circle,r)&&o.push(h):ge.polyContains(p.shape.polygon,r)&&o.push(h));}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2);}let a=r;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,o}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new ze._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(p.minx>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0;}else c=true;c&&o.push(a.shape.outer);}else for(this.treeStack2==null&&(this.treeStack2=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0;}else h=true;h&&o.push(c.shape.outer);}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2);}else {let c=a.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(a.child1==null){let h;if(i!=null){let u=a.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0;}else h=true;if(h)if(n)if(s)ge.containTest(this.aabbShape.zpp_inner,a.shape)&&o.push(a.shape.outer);else {let u=a.shape.aabb;(u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy||ge.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&o.push(a.shape.outer);}else {let u;if(s){let x=a.shape.aabb;u=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy;}else u=true;u&&o.push(a.shape.outer);}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2);}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(p.minx>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0;}else c=true;c&&o.push(a.shape.outer);}else for(this.treeStack2==null&&(this.treeStack2=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0;}else h=true;h&&o.push(c.shape.outer);}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2);}else {let c=a.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(a.child1==null){let h;if(i!=null){let u=a.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0;}else h=true;if(h)if(n)if(s)ge.containTest(this.aabbShape.zpp_inner,a.shape)&&o.push(a.shape.outer);else {let u=a.shape.aabb;(u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy||ge.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&o.push(a.shape.outer);}else {let u;if(s){let x=a.shape.aabb;u=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy;}else u=true;u&&o.push(a.shape.outer);}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2);}}return o}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new ze._nape.phys.BodyList;if(this.failed==null&&(this.failed=new ze._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(p.minx>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0;}else c=true;if(c){let h=a.shape.body.outer;o.has(h)||o.push(h);}}else for(this.treeStack2==null&&(this.treeStack2=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0;}else h=true;if(h){let u=c.shape.body.outer;o.has(u)||o.push(u);}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2);}else {let c=a.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let x=a.shape.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0;}else u=true;if(u)if(n)if(s){if(!this.failed.has(h)){let x=ge.containTest(this.aabbShape.zpp_inner,a.shape);!o.has(h)&&x?o.push(h):x||(o.remove(h),this.failed.push(h));}}else !o.has(h)&&ge.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&o.push(h);else if(s){if(!this.failed.has(h)){let x=a.shape.aabb,m=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy;!o.has(h)&&m?o.push(h):m||(o.remove(h),this.failed.push(h));}}else {let x;if(o.has(h))x=false;else {let m=a.shape.aabb;x=m.minx>=r.minx&&m.miny>=r.miny&&m.maxx<=r.maxx&&m.maxy<=r.maxy;}x&&o.push(h);}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2);}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(p.minx>=r.minx&&p.miny>=r.miny&&p.maxx<=r.maxx&&p.maxy<=r.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0;}else c=true;if(c){let h=a.shape.body.outer;o.has(h)||o.push(h);}}else for(this.treeStack2==null&&(this.treeStack2=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0;}else h=true;if(h){let u=c.shape.body.outer;o.has(u)||o.push(u);}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2);}else {let c=a.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let x=a.shape.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0;}else u=true;if(u)if(n)if(s){if(!this.failed.has(h)){let x=ge.containTest(this.aabbShape.zpp_inner,a.shape);!o.has(h)&&x?o.push(h):x||(o.remove(h),this.failed.push(h));}}else !o.has(h)&&ge.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&o.push(h);else if(s){if(!this.failed.has(h)){let x=a.shape.aabb,m=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy;!o.has(h)&&m?o.push(h):m||(o.remove(h),this.failed.push(h));}}else {let x;if(o.has(h))x=false;else {let m=a.shape.aabb;x=m.minx>=r.minx&&m.miny>=r.miny&&m.maxx<=r.maxx&&m.maxy<=r.maxy;}x&&o.push(h);}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2);}}return this.failed.clear(),o}shapesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new ze._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(p.child1==null){let h;if(l!=null){let u=p.shape.filter;h=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0;}else h=true;h&&(i?ge.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):ge.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(p.shape.outer));}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2);}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(p.child1==null){let h;if(l!=null){let u=p.shape.filter;h=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0;}else h=true;h&&(i?ge.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):ge.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(p.shape.outer));}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2);}return a}bodiesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new ze._nape.phys.BodyList;if(this.failed==null&&(this.failed=new ze._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(p.child1==null){let h=p.shape.body.outer,u;if(l!=null){let x=p.shape.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0;}else u=true;if(u)if(i){if(!this.failed.has(h)){let x=ge.containTest(this.circShape.zpp_inner,p.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h));}}else !a.has(h)&&ge.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(h);}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2);}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(p.child1==null){let h=p.shape.body.outer,u;if(l!=null){let x=p.shape.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0;}else u=true;if(u)if(i){if(!this.failed.has(h)){let x=ge.containTest(this.circShape.zpp_inner,p.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h));}}else !a.has(h)&&ge.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(h);}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2);}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new ze._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(o.child1==null){let p;if(s!=null){let c=o.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0;}else p=true;p&&(n?ge.containTest(t,o.shape)&&r.push(o.shape.outer):ge.testCollide_safe(o.shape,t)&&r.push(o.shape.outer));}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2);}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(o.child1==null){let p;if(s!=null){let c=o.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0;}else p=true;p&&(n?ge.containTest(t,o.shape)&&r.push(o.shape.outer):ge.testCollide_safe(o.shape,t)&&r.push(o.shape.outer));}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2);}return r}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new ze._nape.phys.BodyList;if(this.failed==null&&(this.failed=new ze._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(o.child1==null){let p=o.shape.body.outer,c;if(s!=null){let h=o.shape.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0;}else c=true;if(c)if(n){if(!this.failed.has(p)){let h=ge.containTest(t,o.shape);!r.has(p)&&h?r.push(p):h||(r.remove(p),this.failed.push(p));}}else !r.has(p)&&ge.testCollide_safe(o.shape,t)&&r.push(p);}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2);}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let o=this.treeStack.pop_unsafe(),a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(o.child1==null){let p=o.shape.body.outer,c;if(s!=null){let h=o.shape.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0;}else c=true;if(c)if(n){if(!this.failed.has(p)){let h=ge.containTest(t,o.shape);!r.has(p)&&h?r.push(p):h||(r.remove(p),this.failed.push(p));}}else !r.has(p)&&ge.testCollide_safe(o.shape,t)&&r.push(p);}else o.child1!=null&&this.treeStack.add(o.child1),o.child2!=null&&this.treeStack.add(o.child2);}return this.failed.clear(),r}rayCast(t,n,s){this.openlist==null&&(this.openlist=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let i=t.maxdist;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb)){let r=t.aabbsect(this.dtree.root.aabb);if(r>=0&&r<i){this.dtree.root.rayt=r;let o=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(this.dtree.root.rayt<x.rayt)break;o=a,a=a.next;}let p=this.openlist,c=this.dtree.root,h;ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new ze._zpp.util.ZNPNode_ZPP_AABBNode:(h=ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;o==null?(u.next=p.head,p.head=u):(u.next=o.next,o.next=u),p.pushmod=p.modified=true,p.length++;}}if(this.stree.root!=null&&t.aabbtest(this.stree.root.aabb)){let r=t.aabbsect(this.stree.root.aabb);if(r>=0&&r<i){this.stree.root.rayt=r;let o=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(this.stree.root.rayt<x.rayt)break;o=a,a=a.next;}let p=this.openlist,c=this.stree.root,h;ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new ze._zpp.util.ZNPNode_ZPP_AABBNode:(h=ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;o==null?(u.next=p.head,p.head=u):(u.next=o.next,o.next=u),p.pushmod=p.modified=true,p.length++;}}let l=null;for(;this.openlist.head!=null;){let r=this.openlist.pop_unsafe();if(r.rayt>=i)break;if(r.child1==null){let o=r.shape,a;if(s!=null){let p=o.filter;a=(p.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&p.collisionGroup)!=0;}else a=true;if(a){let p=o.type==0?t.circlesect(o.circle,n,i):t.aabbtest(o.aabb)?t.polysect(o.polygon,n,i):null;if(p!=null){if(p.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(i=p.zpp_inner.toiDistance,l!=null){if(l.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");l.zpp_inner.free();}l=p;}}}else {if(r.child1!=null&&t.aabbtest(r.child1.aabb)){let o=t.aabbsect(r.child1.aabb);if(o>=0&&o<i){r.child1.rayt=o;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(r.child1.rayt<m.rayt)break;a=p,p=p.next;}let c=this.openlist,h=r.child1,u;ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new ze._zpp.util.ZNPNode_ZPP_AABBNode:(u=ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;a==null?(x.next=c.head,c.head=x):(x.next=a.next,a.next=x),c.pushmod=c.modified=true,c.length++;}}if(r.child2!=null&&t.aabbtest(r.child2.aabb)){let o=t.aabbsect(r.child2.aabb);if(o>=0&&o<i){r.child2.rayt=o;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(r.child2.rayt<m.rayt)break;a=p,p=p.next;}let c=this.openlist,h=r.child2,u;ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new ze._zpp.util.ZNPNode_ZPP_AABBNode:(u=ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;a==null?(x.next=c.head,c.head=x):(x.next=a.next,a.next=x),c.pushmod=c.modified=true,c.length++;}}}}return this.openlist.clear(),l}rayMultiCast(t,n,s,i){this.openlist==null&&(this.openlist=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let l=t.maxdist>=1/0,r=i??new ze._nape.geom.RayResultList;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb))if(l)this.openlist.add(this.dtree.root);else {let o=t.aabbsect(this.dtree.root.aabb);o>=0&&o<t.maxdist&&this.openlist.add(this.dtree.root);}if(this.stree.root!=null&&t.aabbtest(this.stree.root.aabb))if(l)this.openlist.add(this.stree.root);else {let o=t.aabbsect(this.stree.root.aabb);o>=0&&o<t.maxdist&&this.openlist.add(this.stree.root);}for(;this.openlist.head!=null;){let o=this.openlist.pop_unsafe();if(o.child1==null){let a=o.shape,p;if(s!=null){let c=a.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0;}else p=true;p&&(a.type==0?t.circlesect2(a.circle,n,r):t.aabbtest(a.aabb)&&t.polysect2(a.polygon,n,r));}else {if(o.child1!=null&&t.aabbtest(o.child1.aabb))if(l)this.openlist.add(o.child1);else {let a=t.aabbsect(o.child1.aabb);a>=0&&a<t.maxdist&&this.openlist.add(o.child1);}if(o.child2!=null&&t.aabbtest(o.child2.aabb))if(l)this.openlist.add(o.child2);else {let a=t.aabbsect(o.child2.aabb);a>=0&&a<t.maxdist&&this.openlist.add(o.child2);}}}return this.openlist.clear(),r}};ze._zpp=null,ze._nape=null,ze.FATTEN=3,ze.VEL_STEPS=2;var as=ze;var Os=class Os{constructor(){this.length=0;this.pushmod=false;this.modified=false;this._inuse=false;this.next=null;this.comps=null;this.sleep=false;this.waket=0;this.comps=new Os._zpp.util.ZNPList_ZPP_Component;}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=true,this.pushmod=true;}add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,this.length++,e}inlined_add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,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=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}inlined_insert(e,t){t._inuse=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){this.erase(t),s=true;break}t=n,n=n.next;}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}inlined_try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=true)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=true)),i._inuse=false,this.modified=true,this.length--,this.pushmod=true,s=true;break}t=n,n=n.next;}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,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=true,this.pushmod=true;}empty(){return this.next==null}size(){return this.length}has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;break}n=n.next;}return t}inlined_has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;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;}};Os.zpp_pool=null,Os._zpp=null;var xt=Os;var Ss=class{constructor(){this.next=null;this.parent=this;this.rank=0;this.isBody=false;this.body=null;this.constraint=null;this.island=null;this.sleeping=false;this.waket=0;this.woken=false;this._inuse=false;}free(){this.body=null,this.constraint=null;}alloc(){}reset(){this.sleeping=false,this.island=null,this.parent=this,this.rank=0;}};Ss.zpp_pool=null;var Tn=class Tn{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=false;this.modified=false;this._inuse=false;this.next=null;this.freed=false;this.lazydel=false;this.arbiters=new Tn._zpp.util.ZNPList_ZPP_Arbiter;}static get(e,t){let n;return Tn.zpp_pool==null?n=new Tn:(n=Tn.zpp_pool,Tn.zpp_pool=n.next,n.next=null),n.freed=false,n.lazydel=false,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=true,this.pushmod=true;}add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,this.length++,e}inlined_add(e){e._inuse=true;let t=e;return t.next=this.next,this.next=t,this.modified=true,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=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}inlined_insert(e,t){t._inuse=true;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=true,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=false,this.next==null&&(this.pushmod=true),this.modified=true,this.length--;}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){this.erase(t),s=true;break}t=n,n=n.next;}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=true)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=true)),s._inuse=false,this.modified=true,this.length--,this.pushmod=true;break}t=n,n=n.next;}}inlined_try_remove(e){let t=null,n=this.next,s=false;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=true)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=true)),i._inuse=false,this.modified=true,this.length--,this.pushmod=true,s=true;break}t=n,n=n.next;}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=true)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=true)),t._inuse=false,this.modified=true,this.length--,this.pushmod=true,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=true,this.pushmod=true;}empty(){return this.next==null}size(){return this.length}has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;break}n=n.next;}return t}inlined_has(e){let t=false,n=this.next;for(;n!=null;){if(n==e){t=true;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=true;}alloc(){this.freed=false,this.lazydel=false,this.COLLISIONstate=1,this.COLLISIONstamp=0,this.SENSORstate=1,this.SENSORstamp=0,this.FLUIDstate=1,this.FLUIDstamp=0;}add_arb(e){let t=false,n=this.arbiters.head;for(;n!=null;){if(n.elt==e){t=true;break}n=n.next;}if(t)return false;{let s=this.arbiters,i,l=Tn._zpp.util.ZNPNode_ZPP_Arbiter;l.zpp_pool==null?i=new l:(i=l.zpp_pool,l.zpp_pool=i.next,i.next=null),i.elt=e;let r=i;return r.next=s.head,s.head=r,s.modified=true,s.length++,true}}try_remove_arb(e){let t=this.arbiters,n=null,s=t.head,i=false;for(;s!=null;){if(s.elt==e){let l,r;n==null?(l=t.head,r=l.next,t.head=r,t.head==null&&(t.pushmod=true)):(l=n.next,r=l.next,n.next=r,r==null&&(t.pushmod=true));let o=l;o.elt=null;let a=Tn._zpp.util.ZNPNode_ZPP_Arbiter;o.next=a.zpp_pool,a.zpp_pool=o,t.modified=true,t.length--,t.pushmod=true,i=true;break}n=s,s=s.next;}return i}remove_arb(e){let t=this.arbiters,n=null,s=t.head;for(;s!=null;){if(s.elt==e){let i,l;n==null?(i=t.head,l=i.next,t.head=l,t.head==null&&(t.pushmod=true)):(i=n.next,l=i.next,n.next=l,l==null&&(t.pushmod=true));let r=i;r.elt=null;let o=Tn._zpp.util.ZNPNode_ZPP_Arbiter;r.next=o.zpp_pool,o.zpp_pool=r,t.modified=true,t.length--,t.pushmod=true;break}n=s,s=s.next;}}empty_arb(e){let t=true,n=this.arbiters.head;for(;n!=null;)if((n.elt.type&e)==0){n=n.next;continue}else {t=false;break}return t}really_empty(){return this.arbiters.head==null}sleeping(){let e=true,t=this.arbiters.head;for(;t!=null;)if(t.elt.sleeping){t=t.next;continue}else {e=false;break}return e}};Tn.zpp_pool=null,Tn._zpp=null;var Yt=Tn;var oi=class oi{constructor(e){this.cbsets=null;this.space=null;let t=oi._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=oi._zpp.callbacks.ZPP_CbSet.setlt,this.space=e;}get(e){if(e.head==null)return null;let t=oi._zpp.callbacks.ZPP_CbSet,n;t.zpp_pool==null?n=new t:(n=t.zpp_pool,t.zpp_pool=n.next,n.next=null);let s=n.cbTypes;n.cbTypes=e;let i=this.cbsets.find_weak(n),l;if(i!=null)l=i.data;else {let o=t.get(e);this.cbsets.insert(o),o.manager=this,l=o;}n.cbTypes=s;let r=n;for(r.listeners.clear(),r.zip_listeners=true,r.bodylisteners.clear(),r.zip_bodylisteners=true,r.conlisteners.clear(),r.zip_conlisteners=true;r.cbTypes.head!=null;)r.cbTypes.pop_unsafe().cbsets.remove(r);return r.next=t.zpp_pool,t.zpp_pool=r,l}remove(e){let t=oi._zpp.callbacks.ZPP_CbSetPair;for(this.cbsets.remove(e);e.cbpairs.head!=null;){let n=e.cbpairs.pop_unsafe();n.a!=n.b&&(e==n.a?n.b.cbpairs.remove(n):n.a.cbpairs.remove(n));let s=n;s.a=s.b=null,s.listeners.clear(),s.next=t.zpp_pool,t.zpp_pool=s;}e.manager=null;}clear(){}validate(){if(!this.cbsets.empty()){let e=this.cbsets.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;)if(e.data.validate(),e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else {for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent;}}}pair(e,t){let n=oi._zpp.callbacks.ZPP_CbSet,s=oi._zpp.callbacks.ZPP_CbSetPair,i=null,r=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;r!=null;){let o=r.elt;if(o.a==e&&o.b==t||o.a==t&&o.b==e){i=o;break}r=r.next;}if(i==null){let o;s.zpp_pool==null?o=new s:(o=s.zpp_pool,s.zpp_pool=o.next,o.next=null),o.zip_listeners=true,n.setlt(e,t)?(o.a=e,o.b=t):(o.a=t,o.b=e),i=o,e.cbpairs.add(i),t!=e&&t.cbpairs.add(i);}return i.zip_listeners&&(i.zip_listeners=false,i.__validate()),i}valid_listener(e){return e.space==this.space}};oi._zpp=null;var Ri=oi;var I=class I{constructor(e,t){this.outer=null;this.userData=null;this.gravityx=0;this.gravityy=0;this.wrap_gravity=null;this.bodies=null;this.wrap_bodies=null;this.compounds=null;this.wrap_compounds=null;this.constraints=null;this.wrap_constraints=null;this.kinematics=null;this.bphase=null;this.__static=null;this.global_lin_drag=0;this.global_ang_drag=0;this.stamp=0;this.midstep=false;this.time=0;this.sortcontacts=false;this.deterministic=false;this.subSteps=1;this.c_arbiters_true=null;this.c_arbiters_false=null;this.f_arbiters=null;this.s_arbiters=null;this.wrap_arbiters=null;this.live=null;this.wrap_live=null;this.live_constraints=null;this.wrap_livecon=null;this.staticsleep=null;this.islands=null;this.listeners=null;this.wrap_listeners=null;this.callbacks=null;this.callbackset_list=null;this.cbsets=null;this.convexShapeList=null;this.pre_dt=0;this.toiEvents=null;this.continuous=false;this.precb=null;this.prelisteners=null;this.mrca1=null;this.mrca2=null;this.prelisteners=null,this.precb=null,this.continuous=false,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=false,this.deterministic=false,this.time=0,this.midstep=false,this.stamp=0,this.global_ang_drag=0,this.global_lin_drag=0,this.__static=null,this.bphase=null,this.kinematics=null,this.wrap_constraints=null,this.constraints=null,this.wrap_compounds=null,this.compounds=null,this.wrap_bodies=null,this.bodies=null,this.wrap_gravity=null,this.gravityy=0,this.gravityx=0,this.userData=null,this.outer=null,this.toiEvents=new I._zpp.util.ZNPList_ZPP_ToiEvent,this.global_lin_drag=.015,this.global_ang_drag=.015,Tt.internal=true,this.precb=Tt._createPreCb(),this.precb.zpp_inner=new Tt,Tt.internal=false,this.sortcontacts=true,this.pre_dt=0;let n;t!=null?(J.Broadphase_DYNAMIC_AABB_TREE==null&&(J.internal=true,J.Broadphase_DYNAMIC_AABB_TREE=new I._nape.space.Broadphase,J.internal=false),n=t==J.Broadphase_DYNAMIC_AABB_TREE):n=true,n?this.bphase=new I._zpp.space.ZPP_DynAABBPhase(this):(J.Broadphase_SPATIAL_HASH==null&&(J.internal=true,J.Broadphase_SPATIAL_HASH=new I._nape.space.Broadphase,J.internal=false),t==J.Broadphase_SPATIAL_HASH?this.bphase=new I._zpp.space.ZPP_SpatialHashPhase(this):(J.Broadphase_SWEEP_AND_PRUNE==null&&(J.internal=true,J.Broadphase_SWEEP_AND_PRUNE=new I._nape.space.Broadphase,J.internal=false),t==J.Broadphase_SWEEP_AND_PRUNE&&(this.bphase=new I._zpp.space.ZPP_SweepPhase(this)))),this.time=0;e!=null?(this.gravityx=e.x,this.gravityy=e.y):(this.gravityx=0,this.gravityy=0),this.bodies=new I._zpp.util.ZNPList_ZPP_Body,this.wrap_bodies=I._zpp.util.ZPP_BodyList.get(this.bodies),this.wrap_bodies.zpp_inner.adder=i=>this.bodies_adder(i),this.wrap_bodies.zpp_inner.subber=i=>this.bodies_subber(i),this.wrap_bodies.zpp_inner._modifiable=()=>this.bodies_modifiable(),this.compounds=new I._zpp.util.ZNPList_ZPP_Compound,this.wrap_compounds=I._zpp.util.ZPP_CompoundList.get(this.compounds),this.wrap_compounds.zpp_inner.adder=i=>this.compounds_adder(i),this.wrap_compounds.zpp_inner.subber=i=>this.compounds_subber(i),this.wrap_compounds.zpp_inner._modifiable=()=>this.compounds_modifiable(),this.kinematics=new I._zpp.util.ZNPList_ZPP_Body,this.c_arbiters_true=new I._zpp.util.ZNPList_ZPP_ColArbiter,this.c_arbiters_false=new I._zpp.util.ZNPList_ZPP_ColArbiter,this.f_arbiters=new I._zpp.util.ZNPList_ZPP_FluidArbiter,this.s_arbiters=new I._zpp.util.ZNPList_ZPP_SensorArbiter,this.islands=new xt,this.live=new I._zpp.util.ZNPList_ZPP_Body,this.wrap_live=I._zpp.util.ZPP_BodyList.get(this.live,true),this.staticsleep=new I._zpp.util.ZNPList_ZPP_Body,this.constraints=new I._zpp.util.ZNPList_ZPP_Constraint,this.wrap_constraints=I._zpp.util.ZPP_ConstraintList.get(this.constraints),this.wrap_constraints.zpp_inner.adder=i=>this.constraints_adder(i),this.wrap_constraints.zpp_inner.subber=i=>this.constraints_subber(i),this.wrap_constraints.zpp_inner._modifiable=()=>this.constraints_modifiable(),this.live_constraints=new I._zpp.util.ZNPList_ZPP_Constraint,this.wrap_livecon=I._zpp.util.ZPP_ConstraintList.get(this.live_constraints,true),this.__static=Mn.__static(),this.__static.zpp_inner.space=this,this.callbacks=new Tt,this.midstep=false,this.listeners=new I._zpp.util.ZNPList_ZPP_Listener,this.wrap_listeners=I._zpp.util.ZPP_ListenerList.get(this.listeners),this.wrap_listeners.zpp_inner.adder=i=>this.listeners_adder(i),this.wrap_listeners.zpp_inner.subber=i=>this.listeners_subber(i),this.wrap_listeners.zpp_inner._modifiable=()=>this.listeners_modifiable(),this.callbackset_list=new Yt,this.mrca1=new I._zpp.util.ZNPList_ZPP_Interactor,this.mrca2=new I._zpp.util.ZNPList_ZPP_Interactor,this.prelisteners=new I._zpp.util.ZNPList_ZPP_InteractionListener,this.cbsets=new Ri(this);}getgravity(){let e=this.gravityx,t=this.gravityy;if(t==null&&(t=0),e==null&&(e=0),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(I._zpp.util.ZPP_PubPool.poolVec2==null?n=new I._nape.geom.Vec2:(n=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=false,n==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let s;ae.zpp_pool==null?s=new ae:(s=ae.zpp_pool,ae.zpp_pool=s.next,s.next=null),s.weak=false,s._immutable=false,s.x=e,s.y=t,n.zpp_inner=s,n.zpp_inner.outer=n;}else {if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=n.zpp_inner;r._validate!=null&&r._validate(),i=n.zpp_inner.y==t;}else i=false;if(!i){n.zpp_inner.x=e,n.zpp_inner.y=t;let r=n.zpp_inner;r._invalidate!=null&&r._invalidate(r);}}n.zpp_inner.weak=false,this.wrap_gravity=n,this.wrap_gravity.zpp_inner._inuse=true,this.wrap_gravity.zpp_inner._invalidate=s=>this.gravity_invalidate(s),this.wrap_gravity.zpp_inner._validate=()=>this.gravity_validate();}gravity_invalidate(e){if(this.midstep)throw new Error("Error: Space::gravity cannot be set during space step");this.gravityx=e.x,this.gravityy=e.y;let t=new I._zpp.util.ZNPList_ZPP_Compound,n=this.bodies.head;for(;n!=null;){let l=n.elt;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=true),l.component.sleeping&&this.really_wake(l,false)),n=n.next;}let s=this.compounds.head;for(;s!=null;){let i=s.elt;t.add(i),s=s.next;}for(;t.head!=null;){let i=t.pop_unsafe(),l=i.bodies.head;for(;l!=null;){let a=l.elt;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=true),a.component.sleeping&&this.really_wake(a,false)),l=l.next;}let r=i.compounds.head;for(;r!=null;){let o=r.elt;t.add(o),r=r.next;}}}gravity_validate(){this.wrap_gravity.zpp_inner.x=this.gravityx,this.wrap_gravity.zpp_inner.y=this.gravityy;}clear(){for(;this.listeners.head!=null;){let t=this.listeners.pop_unsafe();this.remListener(t);}for(;this.callbackset_list.next!=null;){let t=this.callbackset_list.pop_unsafe();t.arbiters.clear();let n=t;n.int1=n.int2=null,n.id=n.di=-1,n.freed=true,n.next=Yt.zpp_pool,Yt.zpp_pool=n;}for(;this.c_arbiters_true.head!=null;){let t=this.c_arbiters_true.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=true)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=true,s.length--,s.pushmod=true;break}i=l,l=l.next;}let o=t.b2.arbiters,a=null,p=o.head;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=true)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,o.modified=true,o.length--,o.pushmod=true;break}a=p,p=p.next;}t.pair!=null&&(t.pair.arb=null,t.pair=null);}for(t.b1=t.b2=null,t.active=false,t.intchange=false;t.contacts.next!=null;){let s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=we.zpp_pool,we.zpp_pool=l;let r=t.innards,o=r.next;r.next=o.next,o._inuse=false,r.next==null&&(r.pushmod=true),r.modified=true,r.length--;}let n=t;n.userdef_dyn_fric=false,n.userdef_stat_fric=false,n.userdef_restitution=false,n.userdef_rfric=false,n.__ref_edge1=n.__ref_edge2=null,n.next=ut.zpp_pool,ut.zpp_pool=n,t.pre_dt=-1;}for(;this.c_arbiters_false.head!=null;){let t=this.c_arbiters_false.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=true)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=true,s.length--,s.pushmod=true;break}i=l,l=l.next;}let o=t.b2.arbiters,a=null,p=o.head;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=true)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,o.modified=true,o.length--,o.pushmod=true;break}a=p,p=p.next;}t.pair!=null&&(t.pair.arb=null,t.pair=null);}for(t.b1=t.b2=null,t.active=false,t.intchange=false;t.contacts.next!=null;){let s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=we.zpp_pool,we.zpp_pool=l;let r=t.innards,o=r.next;r.next=o.next,o._inuse=false,r.next==null&&(r.pushmod=true),r.modified=true,r.length--;}let n=t;n.userdef_dyn_fric=false,n.userdef_stat_fric=false,n.userdef_restitution=false,n.userdef_rfric=false,n.__ref_edge1=n.__ref_edge2=null,n.next=ut.zpp_pool,ut.zpp_pool=n,t.pre_dt=-1;}for(;this.s_arbiters.head!=null;){let t=this.s_arbiters.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=true)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=true,s.length--,s.pushmod=true;break}i=l,l=l.next;}let o=t.b2.arbiters,a=null,p=o.head;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=true)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,o.modified=true,o.length--,o.pushmod=true;break}a=p,p=p.next;}t.pair!=null&&(t.pair.arb=null,t.pair=null);}t.b1=t.b2=null,t.active=false,t.intchange=false;let n=t;n.next=Ot.zpp_pool,Ot.zpp_pool=n;}for(;this.f_arbiters.head!=null;){let t=this.f_arbiters.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=true)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=true,s.length--,s.pushmod=true;break}i=l,l=l.next;}let o=t.b2.arbiters,a=null,p=o.head;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=true)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,o.modified=true,o.length--,o.pushmod=true;break}a=p,p=p.next;}t.pair!=null&&(t.pair.arb=null,t.pair=null);}t.b1=t.b2=null,t.active=false,t.intchange=false;let n=t;n.next=Pt.zpp_pool,Pt.zpp_pool=n,t.pre_dt=-1;}for(this.bphase.clear();this.bodies.head!=null;){let t=this.bodies.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let i=n.comps.pop_unsafe();i.sleeping=false,i.island=null,i.parent=i,i.rank=0;}let s=n;s.next=xt.zpp_pool,xt.zpp_pool=s;}}t.removedFromSpace(),t.space=null;}for(;this.constraints.head!=null;){let t=this.constraints.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let i=n.comps.pop_unsafe();i.sleeping=false,i.island=null,i.parent=i,i.rank=0;}let s=n;s.next=xt.zpp_pool,xt.zpp_pool=s;}}t.removedFromSpace(),t.space=null;}this.kinematics.clear();let e=new I._zpp.util.ZNPList_ZPP_Compound;for(;this.compounds.head!=null;){let t=this.compounds.pop_unsafe();e.add(t);}for(;e.head!=null;){let t=e.pop_unsafe();t.removedFromSpace(),t.space=null;let n=t.bodies.head;for(;n!=null;){let l=n.elt;if(l.component!=null){let r=l.component.island;if(r!=null){for(;r.comps.head!=null;){let a=r.comps.pop_unsafe();a.sleeping=false,a.island=null,a.parent=a,a.rank=0;}let o=r;o.next=xt.zpp_pool,xt.zpp_pool=o;}}l.removedFromSpace(),l.space=null,n=n.next;}let s=t.constraints.head;for(;s!=null;){let l=s.elt;if(l.component!=null){let r=l.component.island;if(r!=null){for(;r.comps.head!=null;){let a=r.comps.pop_unsafe();a.sleeping=false,a.island=null,a.parent=a,a.rank=0;}let o=r;o.next=xt.zpp_pool,xt.zpp_pool=o;}}l.removedFromSpace(),l.space=null,s=s.next;}let i=t.compounds.head;for(;i!=null;){let l=i.elt;e.add(l),i=i.next;}}this.staticsleep.clear(),this.live.clear(),this.live_constraints.clear(),this.stamp=0,this.time=0,this.mrca1.clear(),this.mrca2.clear(),this.prelisteners.clear(),this.cbsets.clear();}bodies_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_bodies.remove(e),this.addBody(e.zpp_inner),true):false}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),true):false}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),true):false}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),true):false}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();e.interaction!=null;}remListener(e){e.interaction!=null;e.removedFromSpace(),e.space=null;}add_callbackset(e){let t=e.int1.cbsets,n;I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?n=new I._zpp.util.ZNPNode_ZPP_CallbackSet:(n=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=n.next,n.next=null),n.elt=e;let s=n;s.next=t.head,t.head=s,t.modified=true,t.length++;let i=e.int2.cbsets,l;I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool==null?l=new I._zpp.util.ZNPNode_ZPP_CallbackSet:(l=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;r.next=i.head,i.head=r,i.modified=true,i.length++;let o=this.callbackset_list;e._inuse=true;let a=e;a.next=o.next,o.next=a,o.modified=true,o.length++;}remove_callbackset(e){e.lazydel=true;let t=e.int1.cbsets,n=null,s=t.head;for(;s!=null;){if(s.elt==e){let p,c;n==null?(p=t.head,c=p.next,t.head=c,t.head==null&&(t.pushmod=true)):(p=n.next,c=p.next,n.next=c,c==null&&(t.pushmod=true));let h=p;h.elt=null,h.next=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=h,t.modified=true,t.length--,t.pushmod=true;break}n=s,s=s.next;}let l=e.int2.cbsets,r=null,o=l.head;for(;o!=null;){if(o.elt==e){let p,c;r==null?(p=l.head,c=p.next,l.head=c,l.head==null&&(l.pushmod=true)):(p=r.next,c=p.next,r.next=c,c==null&&(l.pushmod=true));let h=p;h.elt=null,h.next=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=h,l.modified=true,l.length--,l.pushmod=true;break}r=o,o=o.next;}}transmitType(e,t){let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=true),n.component.sleeping&&this.really_wake(n,false)),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=true;let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=true),s.component.sleeping&&this.really_wake(s,true));}added_shape(e,t){if(t==null&&(t=false),!t){let n=e.body;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=true),n.component.sleeping&&this.really_wake(n,false));}this.bphase.insert(e),e.addedToSpace();}removed_shape(e,t){t==null&&(t=false);let n=e.body;t||n.wake();let s=null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(l.ws1==e||l.ws2==e){if(l.present!=0){this.MRCA_chains(l.ws1,l.ws2);let o=this.mrca1.head;for(;o!=null;){let a=o.elt,p=this.mrca2.head;for(;p!=null;){let c=p.elt,h=a.cbSet,u=c.cbSet;h.validate(),u.validate();h.manager;let m=null,y=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;y!=null;){let g=y.elt;if(g.a==h&&g.b==u||g.a==u&&g.b==h){m=g;break}y=y.next;}if(m==null){let g;Ne.zpp_pool==null?g=new Ne:(g=Ne.zpp_pool,Ne.zpp_pool=g.next,g.next=null),g.zip_listeners=true,dt.setlt(h,u)?(g.a=h,g.b=u):(g.a=u,g.b=h),m=g,h.cbpairs.add(m),u!=h&&u.cbpairs.add(m);}if(m.zip_listeners&&(m.zip_listeners=false,m.__validate()),m.listeners.head==null){p=p.next;continue}let z=I._zpp.phys.ZPP_Interactor.get(a,c);z.remove_arb(l),l.present--;h.manager;let w=null,d=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;d!=null;){let g=d.elt;if(g.a==h&&g.b==u||g.a==u&&g.b==h){w=g;break}d=d.next;}if(w==null){let g;Ne.zpp_pool==null?g=new Ne:(g=Ne.zpp_pool,Ne.zpp_pool=g.next,g.next=null),g.zip_listeners=true,dt.setlt(h,u)?(g.a=h,g.b=u):(g.a=u,g.b=h),w=g,h.cbpairs.add(w),u!=h&&u.cbpairs.add(w);}w.zip_listeners&&(w.zip_listeners=false,w.__validate());let f=w.listeners.head;for(;f!=null;){let g=f.elt;if(g.event==1&&(g.itype&l.type)!=0&&z.empty_arb(g.itype)){let P=this.push_callback(g);P.event=1;let v=z.int1,N=z.int2,E,M=g.options1,k=v.cbTypes;if(M.nonemptyintersection(k,M.includes)&&!M.nonemptyintersection(k,M.excludes)){let C=g.options2,S=N.cbTypes;E=C.nonemptyintersection(S,C.includes)&&!C.nonemptyintersection(S,C.excludes);}else E=false;E?(P.int1=v,P.int2=N):(P.int1=N,P.int2=v),P.set=z;}f=f.next;}z.arbiters.head==null&&this.remove_callbackset(z),p=p.next;}o=o.next;}}if(l.b1!=n&&l.b1.type==2){let o=l.b1;o.world||(o.component.waket=this.stamp+(this.midstep?0:1),o.type==3&&(o.kinematicDelaySleep=true),o.component.sleeping&&this.really_wake(o,false));}if(l.b2!=n&&l.b2.type==2){let o=l.b2;o.world||(o.component.waket=this.stamp+(this.midstep?0:1),o.type==3&&(o.kinematicDelaySleep=true),o.component.sleeping&&this.really_wake(o,false));}if(l.cleared=true,n==null||l.b2==n){let o=l.b1.arbiters,a=null,p=o.head;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=true)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,o.modified=true,o.length--,o.pushmod=true;break}a=p,p=p.next;}}if(n==null||l.b1==n){let o=l.b2.arbiters,a=null,p=o.head;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=o.head,u=h.next,o.head=u,o.head==null&&(o.pushmod=true)):(h=a.next,u=h.next,a.next=u,u==null&&(o.pushmod=true));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,o.modified=true,o.length--,o.pushmod=true;break}a=p,p=p.next;}}l.pair!=null&&(l.pair.arb=null,l.pair=null),l.active=false,this.f_arbiters.modified=true,i=n.arbiters.erase(s);continue}s=i,i=i.next;}this.bphase.remove(e),e.removedFromSpace();}addConstraint(e){e.space=this,e.addedToSpace(),e.active&&(e.component.sleeping=true,this.wake_constraint(e,true));}remConstraint(e){e.active&&(this.wake_constraint(e,true),this.live_constraints.remove(e)),e.removedFromSpace(),e.space=null;}addCompound(e){e.space=this,e.addedToSpace();let t=e.bodies.head;for(;t!=null;){let i=t.elt;this.addBody(i),t=t.next;}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.addConstraint(i),n=n.next;}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.addCompound(i),s=s.next;}}remCompound(e){let t=e.bodies.head;for(;t!=null;){let i=t.elt;this.remBody(i),t=t.next;}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.remConstraint(i),n=n.next;}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.remCompound(i),s=s.next;}e.removedFromSpace(),e.space=null;}addBody(e,t){t==null&&(t=-1),e.space=this,e.addedToSpace(),e.component.sleeping=true;let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=true),n.component.sleeping&&this.really_wake(n,true));let s=e.shapes.head;for(;s!=null;){let i=s.elt;this.bphase.insert(i),i.addedToSpace(),s=s.next;}e.type==1?this.static_validation(e):e.type!=2&&t!=3&&this.kinematics.add(e);}remBody(e,t){if(t==null&&(t=-1),e.type==1){let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=true),s.component.sleeping&&this.really_wake(s,true)),this.staticsleep.remove(e);}else if(e.type==2){let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=true),s.component.sleeping&&this.really_wake(s,true)),this.live.remove(e);}else {t!=3&&this.kinematics.remove(e);let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=true),s.component.sleeping&&this.really_wake(s,true)),this.staticsleep.remove(e);}let n=e.shapes.head;for(;n!=null;){let s=n.elt;this.removed_shape(s,true),n=n.next;}e.removedFromSpace(),e.space=null;}shapesUnderPoint(e,t,n,s){return this.bphase.shapesUnderPoint(e,t,n,s)}bodiesUnderPoint(e,t,n,s){return this.bphase.bodiesUnderPoint(e,t,n,s)}shapesInAABB(e,t,n,s,i){return this.bphase.shapesInAABB(e.zpp_inner,t,n,s,i)}bodiesInAABB(e,t,n,s,i){return this.bphase.bodiesInAABB(e.zpp_inner,t,n,s,i)}shapesInCircle(e,t,n,s,i){let l=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=e.zpp_inner;r._validate!=null&&r._validate();let o=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=e.zpp_inner;return a._validate!=null&&a._validate(),l.shapesInCircle(o,e.zpp_inner.y,t,n,s,i)}bodiesInCircle(e,t,n,s,i){let l=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=e.zpp_inner;r._validate!=null&&r._validate();let o=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=e.zpp_inner;return a._validate!=null&&a._validate(),l.bodiesInCircle(o,e.zpp_inner.y,t,n,s,i)}shapesInShape(e,t,n,s){return this.bphase.shapesInShape(e,t,n,s)}bodiesInShape(e,t,n,s){return this.bphase.bodiesInShape(e,t,n,s)}rayCast(e,t,n){return this.bphase.rayCast(e.zpp_inner,t,n==null?null:n.zpp_inner)}rayMultiCast(e,t,n,s){return this.bphase.rayMultiCast(e.zpp_inner,t,n==null?null:n.zpp_inner,s)}convexCast(e,t,n,s){let i;if(I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?i=new I._zpp.geom.ZPP_ToiEvent:(i=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=i.next,i.next=null),i.failed=false,i.s1=i.s2=null,i.arbiter=null,e.type==0){let O=e.circle;if(O.zip_worldCOM&&O.body!=null){if(O.zip_worldCOM=false,O.zip_localCOM){if(O.zip_localCOM=false,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 R=1;T.localCOMx+=T.lverts.next.next.x*R,T.localCOMy+=T.lverts.next.next.y*R;let W=.5;T.localCOMx*=W,T.localCOMy*=W;}else {T.localCOMx=0,T.localCOMy=0;let R=0,W=T.lverts.next,G=W;W=W.next;let B=W;for(W=W.next;W!=null;){let ee=W;R+=B.x*(ee.y-G.y);let q=ee.y*B.x-ee.x*B.y;T.localCOMx+=(B.x+ee.x)*q,T.localCOMy+=(B.y+ee.y)*q,G=B,B=ee,W=W.next;}W=T.lverts.next;let A=W;R+=B.x*(A.y-G.y);let Y=A.y*B.x-A.x*B.y;T.localCOMx+=(B.x+A.x)*Y,T.localCOMy+=(B.y+A.y)*Y,G=B,B=A,W=W.next;let $=W;R+=B.x*($.y-G.y);let H=$.y*B.x-$.x*B.y;T.localCOMx+=(B.x+$.x)*H,T.localCOMy+=(B.y+$.y)*H,R=1/(3*R);let X=R;T.localCOMx*=X,T.localCOMy*=X;}}O.wrap_localCOM!=null&&(O.wrap_localCOM.zpp_inner.x=O.localCOMx,O.wrap_localCOM.zpp_inner.y=O.localCOMy);}let F=O.body;F.zip_axis&&(F.zip_axis=false,F.axisx=Math.sin(F.rot),F.axisy=Math.cos(F.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=false,O.validate_laxi();let F=O.body;if(F.zip_axis&&(F.zip_axis=false,F.axisx=Math.sin(F.rot),F.axisy=Math.cos(F.rot)),O.zip_gverts&&O.body!=null){O.zip_gverts=false,O.validate_lverts();let A=O.body;A.zip_axis&&(A.zip_axis=false,A.axisx=Math.sin(A.rot),A.axisy=Math.cos(A.rot));let Y=O.lverts.next,$=O.gverts.next;for(;$!=null;){let H=$,X=Y;Y=Y.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),$=$.next;}}let T=O.edges.head,R=O.gverts.next,W=R;for(R=R.next;R!=null;){let A=R,Y=T.elt;T=T.next,Y.gp0=W,Y.gp1=A,Y.gnormx=O.body.axisy*Y.lnormx-O.body.axisx*Y.lnormy,Y.gnormy=Y.lnormx*O.body.axisx+Y.lnormy*O.body.axisy,Y.gprojection=O.body.posx*Y.gnormx+O.body.posy*Y.gnormy+Y.lprojection,Y.wrap_gnorm!=null&&(Y.wrap_gnorm.zpp_inner.x=Y.gnormx,Y.wrap_gnorm.zpp_inner.y=Y.gnormy),Y.tp0=Y.gp0.y*Y.gnormx-Y.gp0.x*Y.gnormy,Y.tp1=Y.gp1.y*Y.gnormx-Y.gp1.x*Y.gnormy,W=A,R=R.next;}let G=O.gverts.next,B=T.elt;T=T.next,B.gp0=W,B.gp1=G,B.gnormx=O.body.axisy*B.lnormx-O.body.axisx*B.lnormy,B.gnormy=B.lnormx*O.body.axisx+B.lnormy*O.body.axisy,B.gprojection=O.body.posx*B.gnormx+O.body.posy*B.gnormy+B.lprojection,B.wrap_gnorm!=null&&(B.wrap_gnorm.zpp_inner.x=B.gnormx,B.wrap_gnorm.zpp_inner.y=B.gnormy),B.tp0=B.gp0.y*B.gnormx-B.gp0.x*B.gnormy,B.tp1=B.gp1.y*B.gnormx-B.gp1.x*B.gnormy;}}let l=e.body,r=l.posx,o=l.posy;l.sweepTime=0,l.sweep_angvel=l.angvel;let a=t-l.sweepTime;if(a!=0){l.sweepTime=t;let O=a;if(l.posx+=l.velx*O,l.posy+=l.vely*O,l.angvel!=0){let F=l.sweep_angvel*a;if(l.rot+=F,F*F>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else {let T=F*F,R=1-.5*T,W=1-T*T/8,G=(R*l.axisx+F*l.axisy)*W;l.axisy=(R*l.axisy-F*l.axisx)*W,l.axisx=G;}}}let p=l.posx,c=l.posy;e.validate_sweepRadius();let h=e.sweepRadius,u;be.zpp_pool==null?u=new be:(u=be.zpp_pool,be.zpp_pool=u.next,u.next=null);let x=r,m=p;u.minx=(x<m?x:m)-h;let _=r,y=p;u.maxx=(_>y?_:y)+h;let z=o,b=c;u.miny=(z<b?z:b)-h;let w=o,Z=c;u.maxy=(w>Z?w:Z)+h;let d=this.convexShapeList=this.bphase.shapesInAABB(u,false,false,n==null?null:n.zpp_inner,this.convexShapeList),f=u;f.outer!=null&&(f.outer.zpp_inner=null,f.outer=null),f.wrap_min=f.wrap_max=null,f._invalidate=null,f._validate=null,f.next=be.zpp_pool,be.zpp_pool=f;let g=0,P=0;g=0,P=0;let v=0,N=0;v=0,N=0;let E=null,M=t+1;d.zpp_inner.valmod();let k=I._nape.shape.ShapeIterator.get(d);for(;;){k.zpp_inner.zpp_inner.valmod();let O=k.zpp_inner;O.zpp_inner.valmod(),O.zpp_inner.zip_length&&(O.zpp_inner.zip_length=false,O.zpp_inner.user_length=O.zpp_inner.inner.length);let F=O.zpp_inner.user_length;k.zpp_critical=true;let T;if(k.zpp_i<F?T=true:(k.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=k,k.zpp_inner=null,T=false),!T)break;k.zpp_critical=false;let R=k.zpp_inner.at(k.zpp_i++);if(R!=e.outer&&(R.zpp_inner.body!=null?R.zpp_inner.body.outer:null)!=l.outer){if(i.s1=e,i.s2=R.zpp_inner,s){R.zpp_inner.validate_sweepRadius(),(R.zpp_inner.body!=null?R.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(R.zpp_inner.body!=null?R.zpp_inner.body.outer:null).zpp_inner.angvel,(R.zpp_inner.body!=null?R.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,Cn.dynamicSweep(i,t,0,0,true);let W=(R.zpp_inner.body!=null?R.zpp_inner.body.outer:null).zpp_inner,G=0-W.sweepTime;if(G!=0){W.sweepTime=0;let Y=G;if(W.posx+=W.velx*Y,W.posy+=W.vely*Y,W.angvel!=0){let $=W.sweep_angvel*G;if(W.rot+=$,$*$>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else {let H=$*$,X=1-.5*H,ee=1-H*H/8,q=(X*W.axisx+$*W.axisy)*ee;W.axisy=(X*W.axisy-$*W.axisx)*ee,W.axisx=q;}}}let B=(R.zpp_inner.body!=null?R.zpp_inner.body.outer:null).zpp_inner,A=R.zpp_inner;if(A.type==0)A.worldCOMx=B.posx+(B.axisy*A.localCOMx-B.axisx*A.localCOMy),A.worldCOMy=B.posy+(A.localCOMx*B.axisx+A.localCOMy*B.axisy);else {let Y=A.polygon,$=Y.lverts.next,H=Y.gverts.next;for(;H!=null;){let V=H,U=$;$=$.next,V.x=B.posx+(B.axisy*U.x-B.axisx*U.y),V.y=B.posy+(U.x*B.axisx+U.y*B.axisy),H=H.next;}let X=Y.edges.head,ee=Y.gverts.next,q=ee;for(ee=ee.next;ee!=null;){let V=ee,U=X.elt;X=X.next,U.gnormx=B.axisy*U.lnormx-B.axisx*U.lnormy,U.gnormy=U.lnormx*B.axisx+U.lnormy*B.axisy,U.gprojection=B.posx*U.gnormx+B.posy*U.gnormy+U.lprojection,U.tp0=q.y*U.gnormx-q.x*U.gnormy,U.tp1=V.y*U.gnormx-V.x*U.gnormy,q=V,ee=ee.next;}let D=Y.gverts.next,L=X.elt;X=X.next,L.gnormx=B.axisy*L.lnormx-B.axisx*L.lnormy,L.gnormy=L.lnormx*B.axisx+L.lnormy*B.axisy,L.gprojection=B.posx*L.gnormx+B.posy*L.gnormy+L.lprojection,L.tp0=q.y*L.gnormx-q.x*L.gnormy,L.tp1=D.y*L.gnormx-D.x*L.gnormy;}}else Cn.staticSweep(i,t,0,0);i.toi*=t,i.toi>0&&i.toi<M&&(M=i.toi,g=i.axis.x,P=i.axis.y,v=i.c2.x,N=i.c2.y,E=R);}}d.clear();let C=i;C.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=C;let S=0-l.sweepTime;if(S!=0){l.sweepTime=0;let O=S;if(l.posx+=l.velx*O,l.posy+=l.vely*O,l.angvel!=0){let F=l.sweep_angvel*S;if(l.rot+=F,F*F>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else {let T=F*F,R=1-.5*T,W=1-T*T/8,G=(R*l.axisx+F*l.axisy)*W;l.axisy=(R*l.axisy-F*l.axisx)*W,l.axisx=G;}}}if(e.type==0)e.worldCOMx=l.posx+(l.axisy*e.localCOMx-l.axisx*e.localCOMy),e.worldCOMy=l.posy+(e.localCOMx*l.axisx+e.localCOMy*l.axisy);else {let O=e.polygon,F=O.lverts.next,T=O.gverts.next;for(;T!=null;){let Y=T,$=F;F=F.next,Y.x=l.posx+(l.axisy*$.x-l.axisx*$.y),Y.y=l.posy+($.x*l.axisx+$.y*l.axisy),T=T.next;}let R=O.edges.head,W=O.gverts.next,G=W;for(W=W.next;W!=null;){let Y=W,$=R.elt;R=R.next,$.gnormx=l.axisy*$.lnormx-l.axisx*$.lnormy,$.gnormy=$.lnormx*l.axisx+$.lnormy*l.axisy,$.gprojection=l.posx*$.gnormx+l.posy*$.gnormy+$.lprojection,$.tp0=G.y*$.gnormx-G.x*$.gnormy,$.tp1=Y.y*$.gnormx-Y.x*$.gnormy,G=Y,W=W.next;}let B=O.gverts.next,A=R.elt;R=R.next,A.gnormx=l.axisy*A.lnormx-l.axisx*A.lnormy,A.gnormy=A.lnormx*l.axisx+A.lnormy*l.axisy,A.gprojection=l.posx*A.gnormx+l.posy*A.gnormy+A.lprojection,A.tp0=G.y*A.gnormx-G.x*A.gnormy,A.tp1=B.y*A.gnormx-B.x*A.gnormy;}if(M<=t){let O=-g,F=-P;if(F==null&&(F=0),O==null&&(O=0),O!=O||F!=F)throw new Error("Error: Vec2 components cannot be NaN");let T;if(I._zpp.util.ZPP_PubPool.poolVec2==null?T=new I._nape.geom.Vec2:(T=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=T.zpp_pool,T.zpp_pool=null,T.zpp_disp=false,T==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),T.zpp_inner==null){let B;ae.zpp_pool==null?B=new ae:(B=ae.zpp_pool,ae.zpp_pool=B.next,B.next=null),B.weak=false,B._immutable=false,B.x=O,B.y=F,T.zpp_inner=B,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 B=T.zpp_inner;if(B._immutable)throw new Error("Error: Vec2 is immutable");if(B._isimmutable!=null&&B._isimmutable(),O!=O||F!=F)throw new Error("Error: Vec2 components cannot be NaN");let A;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Y=T.zpp_inner;if(Y._validate!=null&&Y._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(),A=T.zpp_inner.y==F;}else A=false;if(!A){T.zpp_inner.x=O,T.zpp_inner.y=F;let $=T.zpp_inner;$._invalidate!=null&&$._invalidate($);}}T.zpp_inner.weak=false;let R=v,W=N;if(W==null&&(W=0),R==null&&(R=0),R!=R||W!=W)throw new Error("Error: Vec2 components cannot be NaN");let G;if(I._zpp.util.ZPP_PubPool.poolVec2==null?G=new I._nape.geom.Vec2:(G=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=G.zpp_pool,G.zpp_pool=null,G.zpp_disp=false,G==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),G.zpp_inner==null){let B;ae.zpp_pool==null?B=new ae:(B=ae.zpp_pool,ae.zpp_pool=B.next,B.next=null),B.weak=false,B._immutable=false,B.x=R,B.y=W,G.zpp_inner=B,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 B=G.zpp_inner;if(B._immutable)throw new Error("Error: Vec2 is immutable");if(B._isimmutable!=null&&B._isimmutable(),R!=R||W!=W)throw new Error("Error: Vec2 components cannot be NaN");let A;if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Y=G.zpp_inner;if(Y._validate!=null&&Y._validate(),G.zpp_inner.x==R){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(),A=G.zpp_inner.y==W;}else A=false;if(!A){G.zpp_inner.x=R,G.zpp_inner.y=W;let $=G.zpp_inner;$._invalidate!=null&&$._invalidate($);}}return G.zpp_inner.weak=false,I._zpp.geom.ZPP_ConvexRayResult.getConvex(T,G,M,E)}else return null}prepareCast(e){if(e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=false,t.zip_localCOM){if(t.zip_localCOM=false,t.type==1){let s=t.polygon;if(s.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(s.lverts.next.next==null)s.localCOMx=s.lverts.next.x,s.localCOMy=s.lverts.next.y;else if(s.lverts.next.next.next==null){s.localCOMx=s.lverts.next.x,s.localCOMy=s.lverts.next.y;let i=1;s.localCOMx+=s.lverts.next.next.x*i,s.localCOMy+=s.lverts.next.next.y*i;let l=.5;s.localCOMx*=l,s.localCOMy*=l;}else {s.localCOMx=0,s.localCOMy=0;let i=0,l=s.lverts.next,r=l;l=l.next;let o=l;for(l=l.next;l!=null;){let x=l;i+=o.x*(x.y-r.y);let m=x.y*o.x-x.x*o.y;s.localCOMx+=(o.x+x.x)*m,s.localCOMy+=(o.y+x.y)*m,r=o,o=x,l=l.next;}l=s.lverts.next;let a=l;i+=o.x*(a.y-r.y);let p=a.y*o.x-a.x*o.y;s.localCOMx+=(o.x+a.x)*p,s.localCOMy+=(o.y+a.y)*p,r=o,o=a,l=l.next;let c=l;i+=o.x*(c.y-r.y);let h=c.y*o.x-c.x*o.y;s.localCOMx+=(o.x+c.x)*h,s.localCOMy+=(o.y+c.y)*h,i=1/(3*i);let u=i;s.localCOMx*=u,s.localCOMy*=u;}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy);}let n=t.body;n.zip_axis&&(n.zip_axis=false,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=false,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=false,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=false,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=false,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=t.body.posx+(t.body.axisy*u.x-t.body.axisx*u.y),h.y=t.body.posy+(u.x*t.body.axisx+u.y*t.body.axisy),c=c.next;}}let s=t.edges.head,i=t.gverts.next,l=i;for(i=i.next;i!=null;){let a=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,l=a,i=i.next;}let r=t.gverts.next,o=s.elt;s=s.next,o.gp0=l,o.gp1=r,o.gnormx=t.body.axisy*o.lnormx-t.body.axisx*o.lnormy,o.gnormy=o.lnormx*t.body.axisx+o.lnormy*t.body.axisy,o.gprojection=t.body.posx*o.gnormx+t.body.posy*o.gnormy+o.lprojection,o.wrap_gnorm!=null&&(o.wrap_gnorm.zpp_inner.x=o.gnormx,o.wrap_gnorm.zpp_inner.y=o.gnormy),o.tp0=o.gp0.y*o.gnormx-o.gp0.x*o.gnormy,o.tp1=o.gp1.y*o.gnormx-o.gp1.x*o.gnormy;}}}convexMultiCast(e,t,n,s,i){let l;if(I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?l=new I._zpp.geom.ZPP_ToiEvent:(l=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=l.next,l.next=null),l.failed=false,l.s1=l.s2=null,l.arbiter=null,e.type==0){let M=e.circle;if(M.zip_worldCOM&&M.body!=null){if(M.zip_worldCOM=false,M.zip_localCOM){if(M.zip_localCOM=false,M.type==1){let C=M.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 S=1;C.localCOMx+=C.lverts.next.next.x*S,C.localCOMy+=C.lverts.next.next.y*S;let O=.5;C.localCOMx*=O,C.localCOMy*=O;}else {C.localCOMx=0,C.localCOMy=0;let S=0,O=C.lverts.next,F=O;O=O.next;let T=O;for(O=O.next;O!=null;){let Y=O;S+=T.x*(Y.y-F.y);let $=Y.y*T.x-Y.x*T.y;C.localCOMx+=(T.x+Y.x)*$,C.localCOMy+=(T.y+Y.y)*$,F=T,T=Y,O=O.next;}O=C.lverts.next;let R=O;S+=T.x*(R.y-F.y);let W=R.y*T.x-R.x*T.y;C.localCOMx+=(T.x+R.x)*W,C.localCOMy+=(T.y+R.y)*W,F=T,T=R,O=O.next;let G=O;S+=T.x*(G.y-F.y);let B=G.y*T.x-G.x*T.y;C.localCOMx+=(T.x+G.x)*B,C.localCOMy+=(T.y+G.y)*B,S=1/(3*S);let A=S;C.localCOMx*=A,C.localCOMy*=A;}}M.wrap_localCOM!=null&&(M.wrap_localCOM.zpp_inner.x=M.localCOMx,M.wrap_localCOM.zpp_inner.y=M.localCOMy);}let k=M.body;k.zip_axis&&(k.zip_axis=false,k.axisx=Math.sin(k.rot),k.axisy=Math.cos(k.rot)),M.worldCOMx=M.body.posx+(M.body.axisy*M.localCOMx-M.body.axisx*M.localCOMy),M.worldCOMy=M.body.posy+(M.localCOMx*M.body.axisx+M.localCOMy*M.body.axisy);}}else {let M=e.polygon;if(M.zip_gaxi&&M.body!=null){M.zip_gaxi=false,M.validate_laxi();let k=M.body;if(k.zip_axis&&(k.zip_axis=false,k.axisx=Math.sin(k.rot),k.axisy=Math.cos(k.rot)),M.zip_gverts&&M.body!=null){M.zip_gverts=false,M.validate_lverts();let R=M.body;R.zip_axis&&(R.zip_axis=false,R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.rot));let W=M.lverts.next,G=M.gverts.next;for(;G!=null;){let B=G,A=W;W=W.next,B.x=M.body.posx+(M.body.axisy*A.x-M.body.axisx*A.y),B.y=M.body.posy+(A.x*M.body.axisx+A.y*M.body.axisy),G=G.next;}}let C=M.edges.head,S=M.gverts.next,O=S;for(S=S.next;S!=null;){let R=S,W=C.elt;C=C.next,W.gp0=O,W.gp1=R,W.gnormx=M.body.axisy*W.lnormx-M.body.axisx*W.lnormy,W.gnormy=W.lnormx*M.body.axisx+W.lnormy*M.body.axisy,W.gprojection=M.body.posx*W.gnormx+M.body.posy*W.gnormy+W.lprojection,W.wrap_gnorm!=null&&(W.wrap_gnorm.zpp_inner.x=W.gnormx,W.wrap_gnorm.zpp_inner.y=W.gnormy),W.tp0=W.gp0.y*W.gnormx-W.gp0.x*W.gnormy,W.tp1=W.gp1.y*W.gnormx-W.gp1.x*W.gnormy,O=R,S=S.next;}let F=M.gverts.next,T=C.elt;C=C.next,T.gp0=O,T.gp1=F,T.gnormx=M.body.axisy*T.lnormx-M.body.axisx*T.lnormy,T.gnormy=T.lnormx*M.body.axisx+T.lnormy*M.body.axisy,T.gprojection=M.body.posx*T.gnormx+M.body.posy*T.gnormy+T.lprojection,T.wrap_gnorm!=null&&(T.wrap_gnorm.zpp_inner.x=T.gnormx,T.wrap_gnorm.zpp_inner.y=T.gnormy),T.tp0=T.gp0.y*T.gnormx-T.gp0.x*T.gnormy,T.tp1=T.gp1.y*T.gnormx-T.gp1.x*T.gnormy;}}let r=e.body,o=r.posx,a=r.posy;r.sweepTime=0,r.sweep_angvel=r.angvel;let p=t-r.sweepTime;if(p!=0){r.sweepTime=t;let M=p;if(r.posx+=r.velx*M,r.posy+=r.vely*M,r.angvel!=0){let k=r.sweep_angvel*p;if(r.rot+=k,k*k>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else {let C=k*k,S=1-.5*C,O=1-C*C/8,F=(S*r.axisx+k*r.axisy)*O;r.axisy=(S*r.axisy-k*r.axisx)*O,r.axisx=F;}}}let c=r.posx,h=r.posy;e.validate_sweepRadius();let u=e.sweepRadius,x;be.zpp_pool==null?x=new be:(x=be.zpp_pool,be.zpp_pool=x.next,x.next=null);let m=o,_=c;x.minx=(m<_?m:_)-u;let y=o,z=c;x.maxx=(y>z?y:z)+u;let b=a,w=h;x.miny=(b<w?b:w)-u;let Z=a,d=h;x.maxy=(Z>d?Z:d)+u;let f=this.convexShapeList=this.bphase.shapesInAABB(x,false,false,n==null?null:n.zpp_inner,this.convexShapeList),g=x;g.outer!=null&&(g.outer.zpp_inner=null,g.outer=null),g.wrap_min=g.wrap_max=null,g._invalidate=null,g._validate=null,g.next=be.zpp_pool,be.zpp_pool=g;let P=i??new I._nape.geom.ConvexResultList;f.zpp_inner.valmod();let v=I._nape.shape.ShapeIterator.get(f);for(;;){v.zpp_inner.zpp_inner.valmod();let M=v.zpp_inner;M.zpp_inner.valmod(),M.zpp_inner.zip_length&&(M.zpp_inner.zip_length=false,M.zpp_inner.user_length=M.zpp_inner.inner.length);let k=M.zpp_inner.user_length;v.zpp_critical=true;let C;if(v.zpp_i<k?C=true:(v.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=v,v.zpp_inner=null,C=false),!C)break;v.zpp_critical=false;let S=v.zpp_inner.at(v.zpp_i++);if(S!=e.outer&&(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null)!=r.outer){if(l.s1=e,l.s2=S.zpp_inner,s){S.zpp_inner.validate_sweepRadius(),(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner.angvel,(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,Cn.dynamicSweep(l,t,0,0,true);let O=(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner,F=0-O.sweepTime;if(F!=0){O.sweepTime=0;let W=F;if(O.posx+=O.velx*W,O.posy+=O.vely*W,O.angvel!=0){let G=O.sweep_angvel*F;if(O.rot+=G,G*G>1e-4)O.axisx=Math.sin(O.rot),O.axisy=Math.cos(O.rot);else {let B=G*G,A=1-.5*B,Y=1-B*B/8,$=(A*O.axisx+G*O.axisy)*Y;O.axisy=(A*O.axisy-G*O.axisx)*Y,O.axisx=$;}}}let T=(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner,R=S.zpp_inner;if(R.type==0)R.worldCOMx=T.posx+(T.axisy*R.localCOMx-T.axisx*R.localCOMy),R.worldCOMy=T.posy+(R.localCOMx*T.axisx+R.localCOMy*T.axisy);else {let W=R.polygon,G=W.lverts.next,B=W.gverts.next;for(;B!=null;){let ee=B,q=G;G=G.next,ee.x=T.posx+(T.axisy*q.x-T.axisx*q.y),ee.y=T.posy+(q.x*T.axisx+q.y*T.axisy),B=B.next;}let A=W.edges.head,Y=W.gverts.next,$=Y;for(Y=Y.next;Y!=null;){let ee=Y,q=A.elt;A=A.next,q.gnormx=T.axisy*q.lnormx-T.axisx*q.lnormy,q.gnormy=q.lnormx*T.axisx+q.lnormy*T.axisy,q.gprojection=T.posx*q.gnormx+T.posy*q.gnormy+q.lprojection,q.tp0=$.y*q.gnormx-$.x*q.gnormy,q.tp1=ee.y*q.gnormx-ee.x*q.gnormy,$=ee,Y=Y.next;}let H=W.gverts.next,X=A.elt;A=A.next,X.gnormx=T.axisy*X.lnormx-T.axisx*X.lnormy,X.gnormy=X.lnormx*T.axisx+X.lnormy*T.axisy,X.gprojection=T.posx*X.gnormx+T.posy*X.gnormy+X.lprojection,X.tp0=$.y*X.gnormx-$.x*X.gnormy,X.tp1=H.y*X.gnormx-H.x*X.gnormy;}}else Cn.staticSweep(l,t,0,0);if(l.toi*=t,l.toi>0){let O=-l.axis.x,F=-l.axis.y;if(F==null&&(F=0),O==null&&(O=0),O!=O||F!=F)throw new Error("Error: Vec2 components cannot be NaN");let T;if(I._zpp.util.ZPP_PubPool.poolVec2==null?T=new I._nape.geom.Vec2:(T=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=T.zpp_pool,T.zpp_pool=null,T.zpp_disp=false,T==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),T.zpp_inner==null){let ee;ae.zpp_pool==null?ee=new ae:(ee=ae.zpp_pool,ae.zpp_pool=ee.next,ee.next=null),ee.weak=false,ee._immutable=false,ee.x=O,ee.y=F,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||F!=F)throw new Error("Error: Vec2 components cannot be NaN");let q;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 L=T.zpp_inner;L._validate!=null&&L._validate(),q=T.zpp_inner.y==F;}else q=false;if(!q){T.zpp_inner.x=O,T.zpp_inner.y=F;let L=T.zpp_inner;L._invalidate!=null&&L._invalidate(L);}}T.zpp_inner.weak=false;let R=l.c2.x,W=l.c2.y;if(W==null&&(W=0),R==null&&(R=0),R!=R||W!=W)throw new Error("Error: Vec2 components cannot be NaN");let G;if(I._zpp.util.ZPP_PubPool.poolVec2==null?G=new I._nape.geom.Vec2:(G=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=G.zpp_pool,G.zpp_pool=null,G.zpp_disp=false,G==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),G.zpp_inner==null){let ee;ae.zpp_pool==null?ee=new ae:(ee=ae.zpp_pool,ae.zpp_pool=ee.next,ee.next=null),ee.weak=false,ee._immutable=false,ee.x=R,ee.y=W,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(),R!=R||W!=W)throw new Error("Error: Vec2 components cannot be NaN");let q;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==R){if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=G.zpp_inner;L._validate!=null&&L._validate(),q=G.zpp_inner.y==W;}else q=false;if(!q){G.zpp_inner.x=R,G.zpp_inner.y=W;let L=G.zpp_inner;L._invalidate!=null&&L._invalidate(L);}}G.zpp_inner.weak=false;let B=I._zpp.geom.ZPP_ConvexRayResult.getConvex(T,G,l.toi,S),A=null,Y=P.zpp_inner.inner.head;for(;Y!=null;){let ee=Y.elt;if(B.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(ee.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(B.zpp_inner.toiDistance<ee.zpp_inner.toiDistance)break;A=Y,Y=Y.next;}let $=P.zpp_inner.inner,H;I._zpp.util.ZNPNode_ConvexResult.zpp_pool==null?H=new I._zpp.util.ZNPNode_ConvexResult:(H=I._zpp.util.ZNPNode_ConvexResult.zpp_pool,I._zpp.util.ZNPNode_ConvexResult.zpp_pool=H.next,H.next=null),H.elt=B;let X=H;A==null?(X.next=$.head,$.head=X):(X.next=A.next,A.next=X),$.pushmod=$.modified=true,$.length++;}}}f.clear();let N=l;N.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=N;let E=0-r.sweepTime;if(E!=0){r.sweepTime=0;let M=E;if(r.posx+=r.velx*M,r.posy+=r.vely*M,r.angvel!=0){let k=r.sweep_angvel*E;if(r.rot+=k,k*k>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else {let C=k*k,S=1-.5*C,O=1-C*C/8,F=(S*r.axisx+k*r.axisy)*O;r.axisy=(S*r.axisy-k*r.axisx)*O,r.axisx=F;}}}if(e.type==0)e.worldCOMx=r.posx+(r.axisy*e.localCOMx-r.axisx*e.localCOMy),e.worldCOMy=r.posy+(e.localCOMx*r.axisx+e.localCOMy*r.axisy);else {let M=e.polygon,k=M.lverts.next,C=M.gverts.next;for(;C!=null;){let W=C,G=k;k=k.next,W.x=r.posx+(r.axisy*G.x-r.axisx*G.y),W.y=r.posy+(G.x*r.axisx+G.y*r.axisy),C=C.next;}let S=M.edges.head,O=M.gverts.next,F=O;for(O=O.next;O!=null;){let W=O,G=S.elt;S=S.next,G.gnormx=r.axisy*G.lnormx-r.axisx*G.lnormy,G.gnormy=G.lnormx*r.axisx+G.lnormy*r.axisy,G.gprojection=r.posx*G.gnormx+r.posy*G.gnormy+G.lprojection,G.tp0=F.y*G.gnormx-F.x*G.gnormy,G.tp1=W.y*G.gnormx-W.x*G.gnormy,F=W,O=O.next;}let T=M.gverts.next,R=S.elt;S=S.next,R.gnormx=r.axisy*R.lnormx-r.axisx*R.lnormy,R.gnormy=R.lnormx*r.axisx+R.lnormy*r.axisy,R.gprojection=r.posx*R.gnormx+r.posy*R.gnormy+R.lprojection,R.tp0=F.y*R.gnormx-F.x*R.gnormy,R.tp1=T.y*R.gnormx-T.x*R.gnormy;}return P}push_callback(e){let t;return Tt.zpp_pool==null?t=new Tt:(t=Tt.zpp_pool,Tt.zpp_pool=t.next,t.next=null),this.callbacks.push(t),t.listener=e,t}_invalidateBodyList(e){let t=e.head;for(;t!=null;){let n=t.elt,s=!(n.posx==n.pre_posx&&n.posy==n.pre_posy),i=n.pre_rot!=n.rot;if(s||i){i&&(n.zip_axis=true);let l=n.shapes.head;for(;l!=null;){let r=l.elt;r.type==1&&(r.polygon.invalidate_gverts(),r.polygon.invalidate_gaxi()),r.invalidate_worldCOM(),l=l.next;}n.zip_worldCOM=true;}t=t.next;}}_sortLinkedList(e,t){if(e.head==null||e.head.next==null)return;let n=e.head,s=1;for(;;){let i=0,l=n;n=null;let r=null;for(;l!=null;){i++;let o=l,a=0,p=s;for(;o!=null&&a<s;)a++,o=o.next;for(;a>0||p>0&&o!=null;){let c;a==0?(c=o,o=o.next,p--):p==0||o==null||t(l.elt)<=t(o.elt)?(c=l,l=l.next,a--):(c=o,o=o.next,p--),r!=null?r.next=c:n=c,r=c;}l=o;}if(r.next=null,s<<=1,i<=1)break}e.head=n,e.modified=true,e.pushmod=true;}_arbiterSortKey(e){let t=e.s1!=null?e.s1.id:0,n=e.s2!=null?e.s2.id:0,s=t<n?t:n,i=t<n?n:t;return s*1e6+i}_ensureDeterministicOrder(){this.deterministic&&(this._sortLinkedList(this.live,e=>e.id),this._sortLinkedList(this.live_constraints,e=>e.id),this._sortLinkedList(this.c_arbiters_false,e=>this._arbiterSortKey(e)),this._sortLinkedList(this.c_arbiters_true,e=>this._arbiterSortKey(e)),this._sortLinkedList(this.f_arbiters,e=>this._arbiterSortKey(e)));}step(e,t,n){if(this.midstep)throw new Error("Error: ... REALLY?? you're going to call space.step() inside of space.step()? COME ON!!");this.time+=e,this.midstep=true,this.stamp++;let s=this.subSteps,i=e/s;try{for(let o=0;o<s;o++){if(this.pre_dt=i,this.validation(),this.bphase.broadphase(this,!0),this._ensureDeterministicOrder(),this.prestep(i),this.sortcontacts){let u=this.c_arbiters_false;if(u.head!=null&&u.head.next!=null){let x=u.head,m=null,_=null,y=null,z=null,b=1,w,Z,d;for(;;){for(w=0,_=x,x=null,m=x;_!=null;){for(++w,y=_,Z=0,d=b;y!=null&&Z<b;)++Z,y=y.next;for(;Z>0||d>0&&y!=null;)Z==0?(z=y,y=y.next,--d):d==0||y==null||(_.elt.active&&y.elt.active?_.elt.oc1.dist<y.elt.oc1.dist:!this.deterministic||this._arbiterSortKey(_.elt)<=this._arbiterSortKey(y.elt))?(z=_,_=_.next,--Z):(z=y,y=y.next,--d),m!=null?m.next=z:x=z,m=z;_=y;}if(m.next=null,b<<=1,!(w>1))break}u.head=x,u.modified=!0,u.pushmod=!0;}}this.updateVel(i),this.warmStart(),this.iterateVel(t);let a=this.kinematics.head;for(;a!=null;){let u=a.elt;u.pre_posx=u.posx,u.pre_posy=u.posy,u.pre_rot=u.rot,a=a.next;}let p=this.live.head;for(;p!=null;){let u=p.elt;u.pre_posx=u.posx,u.pre_posy=u.posy,u.pre_rot=u.rot,p=p.next;}this.updatePos(i),this.continuous=!0,this.continuousCollisions(i),this.continuous=!1,this.iteratePos(n),this._invalidateBodyList(this.kinematics),this._invalidateBodyList(this.live);let c=null,h=this.staticsleep.head;for(;h!=null;){let u=h.elt;if(u.type!=3||u.velx==0&&u.vely==0&&u.angvel==0){if(u.kinematicDelaySleep){u.kinematicDelaySleep=!1,h=h.next;continue}u.component.sleeping=!0;let x=this.staticsleep,m,_;c==null?(m=x.head,_=m.next,x.head=_,x.head==null&&(x.pushmod=!0)):(m=c.next,_=m.next,c.next=_,_==null&&(x.pushmod=!0));let y=m;y.elt=null,y.next=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=y,x.modified=!0,x.length--,x.pushmod=!0,h=_;continue}c=h,h=h.next;}this.doForests(i),this.sleepArbiters();}}finally{this.midstep=false;}let l=null,r=this.callbackset_list.next;for(;r!=null;){let o=r;if(o.arbiters.head==null){let b=this.callbackset_list,w,Z;l==null?(w=b.next,Z=w.next,b.next=Z,b.next==null&&(b.pushmod=true)):(w=l.next,Z=w.next,l.next=Z,Z==null&&(b.pushmod=true)),w._inuse=false,b.modified=true,b.length--,b.pushmod=true,r=Z;let d=o;d.int1=d.int2=null,d.id=d.di=-1,d.freed=true,d.next=Yt.zpp_pool,Yt.zpp_pool=d;continue}let a;a=true;let p=o.arbiters.head;for(;p!=null;)if(p.elt.sleeping){p=p.next;continue}else {a=false;break}let c=a,h=o.int1.cbSet,u=o.int2.cbSet;h.manager;let m=null,y=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;y!=null;){let b=y.elt;if(b.a==h&&b.b==u||b.a==u&&b.b==h){m=b;break}y=y.next;}if(m==null){let b;Ne.zpp_pool==null?b=new Ne:(b=Ne.zpp_pool,Ne.zpp_pool=b.next,b.next=null),b.zip_listeners=true,dt.setlt(h,u)?(b.a=h,b.b=u):(b.a=u,b.b=h),m=b,h.cbpairs.add(m),u!=h&&u.cbpairs.add(m);}m.zip_listeners&&(m.zip_listeners=false,m.__validate());let z=m.listeners.head;for(;z!=null;){let b=z.elt;if(b.event==6&&(!c||b.allowSleepingCallbacks)&&!o.empty_arb(b.itype)){let w=this.push_callback(b);w.event=6;let Z=o.int1,d=o.int2,f,g=b.options1,P=Z.cbTypes;if(g.nonemptyintersection(P,g.includes)&&!g.nonemptyintersection(P,g.excludes)){let v=b.options2,N=d.cbTypes;f=v.nonemptyintersection(N,v.includes)&&!v.nonemptyintersection(N,v.excludes);}else f=false;f?(w.int1=Z,w.int2=d):(w.int1=d,w.int2=Z),w.set=o;}z=z.next;}l=r,r=r.next;}for(;!this.callbacks.empty();){let o=this.callbacks.pop();o.listener.type==0?o.listener.body.handler(o.wrapper_body()):o.listener.type==1?o.listener.constraint.handler(o.wrapper_con()):o.listener.type==2&&o.listener.interaction.handleri(o.wrapper_int());let a=o;a.int1=a.int2=null,a.body=null,a.constraint=null,a.listener=null,a.wrap_arbiters!=null&&(a.wrap_arbiters.zpp_inner.inner=null),a.set=null,a.next=Tt.zpp_pool,Tt.zpp_pool=a;}}continuousCollisions(e){let t=2*Math.PI/e;this.bphase.broadphase(this,false);let n=0;for(;n<1&&this.toiEvents.head!=null;){let l=null,r=2,o=false,a=null,p=null,c=this.toiEvents.head;for(;c!=null;){let y=c.elt,z=y.s1.body,b=y.s2.body;if(z.sweepFrozen&&b.sweepFrozen)if(y.toi!=0&&ge.testCollide_safe(y.s1,y.s2))y.toi=0;else {c=this.toiEvents.erase(p);let w=y;w.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=w;continue}if(y.frozen1!=z.sweepFrozen||y.frozen2!=b.sweepFrozen)if(y.kinematic){c=this.toiEvents.erase(p);let w=y;w.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=w;continue}else {if(y.frozen1=z.sweepFrozen,y.frozen2=b.sweepFrozen,y.frozen1){let w=y.s1;y.s1=y.s2,y.s2=w,y.frozen1=false,y.frozen2=true;}if(Cn.staticSweep(y,e,0,I._nape.Config.collisionSlopCCD),y.toi<0){c=this.toiEvents.erase(p);let w=y;w.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=w;continue}}y.toi>=0&&(y.toi<r||!o&&y.kinematic)&&(l=y,r=y.toi,o=y.kinematic,a=p),p=c,c=c.next;}if(l==null)break;this.toiEvents.erase(a),n=l.toi;let h=l.s1.body,u=l.s2.body;if(!h.sweepFrozen){let y=n*e,z=y-h.sweepTime;if(z!=0){h.sweepTime=y;let w=z;if(h.posx+=h.velx*w,h.posy+=h.vely*w,h.angvel!=0){let Z=h.sweep_angvel*z;if(h.rot+=Z,Z*Z>1e-4)h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot);else {let d=Z*Z,f=1-.5*d,g=1-d*d/8,P=(f*h.axisx+Z*h.axisy)*g;h.axisy=(f*h.axisy-Z*h.axisx)*g,h.axisx=P;}}}let b=l.s1;if(b.type==0)b.worldCOMx=h.posx+(h.axisy*b.localCOMx-h.axisx*b.localCOMy),b.worldCOMy=h.posy+(b.localCOMx*h.axisx+b.localCOMy*h.axisy);else {let w=b.polygon,Z=w.lverts.next,d=w.gverts.next;for(;d!=null;){let E=d,M=Z;Z=Z.next,E.x=h.posx+(h.axisy*M.x-h.axisx*M.y),E.y=h.posy+(M.x*h.axisx+M.y*h.axisy),d=d.next;}let f=w.edges.head,g=w.gverts.next,P=g;for(g=g.next;g!=null;){let E=g,M=f.elt;f=f.next,M.gnormx=h.axisy*M.lnormx-h.axisx*M.lnormy,M.gnormy=M.lnormx*h.axisx+M.lnormy*h.axisy,M.gprojection=h.posx*M.gnormx+h.posy*M.gnormy+M.lprojection,M.tp0=P.y*M.gnormx-P.x*M.gnormy,M.tp1=E.y*M.gnormx-E.x*M.gnormy,P=E,g=g.next;}let v=w.gverts.next,N=f.elt;f=f.next,N.gnormx=h.axisy*N.lnormx-h.axisx*N.lnormy,N.gnormy=N.lnormx*h.axisx+N.lnormy*h.axisy,N.gprojection=h.posx*N.gnormx+h.posy*N.gnormy+N.lprojection,N.tp0=P.y*N.gnormx-P.x*N.gnormy,N.tp1=v.y*N.gnormx-v.x*N.gnormy;}}if(!u.sweepFrozen){let y=n*e,z=y-u.sweepTime;if(z!=0){u.sweepTime=y;let w=z;if(u.posx+=u.velx*w,u.posy+=u.vely*w,u.angvel!=0){let Z=u.sweep_angvel*z;if(u.rot+=Z,Z*Z>1e-4)u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot);else {let d=Z*Z,f=1-.5*d,g=1-d*d/8,P=(f*u.axisx+Z*u.axisy)*g;u.axisy=(f*u.axisy-Z*u.axisx)*g,u.axisx=P;}}}let b=l.s2;if(b.type==0)b.worldCOMx=u.posx+(u.axisy*b.localCOMx-u.axisx*b.localCOMy),b.worldCOMy=u.posy+(b.localCOMx*u.axisx+b.localCOMy*u.axisy);else {let w=b.polygon,Z=w.lverts.next,d=w.gverts.next;for(;d!=null;){let E=d,M=Z;Z=Z.next,E.x=u.posx+(u.axisy*M.x-u.axisx*M.y),E.y=u.posy+(M.x*u.axisx+M.y*u.axisy),d=d.next;}let f=w.edges.head,g=w.gverts.next,P=g;for(g=g.next;g!=null;){let E=g,M=f.elt;f=f.next,M.gnormx=u.axisy*M.lnormx-u.axisx*M.lnormy,M.gnormy=M.lnormx*u.axisx+M.lnormy*u.axisy,M.gprojection=u.posx*M.gnormx+u.posy*M.gnormy+M.lprojection,M.tp0=P.y*M.gnormx-P.x*M.gnormy,M.tp1=E.y*M.gnormx-E.x*M.gnormy,P=E,g=g.next;}let v=w.gverts.next,N=f.elt;f=f.next,N.gnormx=u.axisy*N.lnormx-u.axisx*N.lnormy,N.gnormy=N.lnormx*u.axisx+N.lnormy*u.axisy,N.gprojection=u.posx*N.gnormx+u.posy*N.gnormy+N.lprojection,N.tp0=P.y*N.gnormx-P.x*N.gnormy,N.tp1=v.y*N.gnormx-v.x*N.gnormy;}}l.arbiter==null;let m=this.narrowPhase(l.s1,l.s2,true,l.arbiter,true);if(m==null)l.arbiter!=null&&l.arbiter.pair!=null&&(l.arbiter.pair.arb=null,l.arbiter.pair=null);else if(!this.presteparb(m,e,true)&&m.type==Ie.COL&&m.active&&(m.immState&1)!=0){let y=m.colarb,z=y.nx*y.c1.jnAcc-y.ny*y.c1.jtAcc,b=y.ny*y.c1.jnAcc+y.nx*y.c1.jtAcc,w=y.b1.imass;y.b1.velx-=z*w,y.b1.vely-=b*w,y.b1.angvel-=y.b1.iinertia*(b*y.c1.r1x-z*y.c1.r1y);let Z=y.b2.imass;if(y.b2.velx+=z*Z,y.b2.vely+=b*Z,y.b2.angvel+=y.b2.iinertia*(b*y.c1.r2x-z*y.c1.r2y),y.hc2){let le=y.nx*y.c2.jnAcc-y.ny*y.c2.jtAcc,he=y.ny*y.c2.jnAcc+y.nx*y.c2.jtAcc,pe=y.b1.imass;y.b1.velx-=le*pe,y.b1.vely-=he*pe,y.b1.angvel-=y.b1.iinertia*(he*y.c2.r1x-le*y.c2.r1y);let ce=y.b2.imass;y.b2.velx+=le*ce,y.b2.vely+=he*ce,y.b2.angvel+=y.b2.iinertia*(he*y.c2.r2x-le*y.c2.r2y);}y.b2.angvel+=y.jrAcc*y.b2.iinertia,y.b1.angvel-=y.jrAcc*y.b1.iinertia;let d=m.colarb,f=d.k1x+d.b2.velx-d.c1.r2y*d.b2.angvel-(d.b1.velx-d.c1.r1y*d.b1.angvel),g=d.k1y+d.b2.vely+d.c1.r2x*d.b2.angvel-(d.b1.vely+d.c1.r1x*d.b1.angvel),P=(g*d.nx-f*d.ny+d.surfacex)*d.c1.tMass,v=d.c1.friction*d.c1.jnAcc,N=d.c1.jtAcc,E=N-P;E>v?E=v:E<-v&&(E=-v),P=E-N,d.c1.jtAcc=E;let M=-d.ny*P,k=d.nx*P;if(d.b2.velx+=M*d.b2.imass,d.b2.vely+=k*d.b2.imass,d.b1.velx-=M*d.b1.imass,d.b1.vely-=k*d.b1.imass,d.b2.angvel+=d.rt1b*P*d.b2.iinertia,d.b1.angvel-=d.rt1a*P*d.b1.iinertia,d.hc2){let le=d.k2x+d.b2.velx-d.c2.r2y*d.b2.angvel-(d.b1.velx-d.c2.r1y*d.b1.angvel),he=d.k2y+d.b2.vely+d.c2.r2x*d.b2.angvel-(d.b1.vely+d.c2.r1x*d.b1.angvel);P=(he*d.nx-le*d.ny+d.surfacex)*d.c2.tMass,v=d.c2.friction*d.c2.jnAcc,N=d.c2.jtAcc,E=N-P,E>v?E=v:E<-v&&(E=-v),P=E-N,d.c2.jtAcc=E,M=-d.ny*P,k=d.nx*P,d.b2.velx+=M*d.b2.imass,d.b2.vely+=k*d.b2.imass,d.b1.velx-=M*d.b1.imass,d.b1.vely-=k*d.b1.imass,d.b2.angvel+=d.rt2b*P*d.b2.iinertia,d.b1.angvel-=d.rt2a*P*d.b1.iinertia,f=d.k1x+d.b2.velx-d.c1.r2y*d.b2.angvel-(d.b1.velx-d.c1.r1y*d.b1.angvel),g=d.k1y+d.b2.vely+d.c1.r2x*d.b2.angvel-(d.b1.vely+d.c1.r1x*d.b1.angvel),le=d.k2x+d.b2.velx-d.c2.r2y*d.b2.angvel-(d.b1.velx-d.c2.r1y*d.b1.angvel),he=d.k2y+d.b2.vely+d.c2.r2x*d.b2.angvel-(d.b1.vely+d.c2.r1x*d.b1.angvel);let pe=d.c1.jnAcc,ce=d.c2.jnAcc,te=f*d.nx+g*d.ny+d.surfacey+d.c1.bounce-(d.Ka*pe+d.Kb*ce),ue=le*d.nx+he*d.ny+d.surfacey+d.c2.bounce-(d.Kb*pe+d.Kc*ce),de=-(d.kMassa*te+d.kMassb*ue),me=-(d.kMassb*te+d.kMassc*ue);de>=0&&me>=0?(te=de-pe,ue=me-ce,d.c1.jnAcc=de,d.c2.jnAcc=me):(de=-d.c1.nMass*te,de>=0&&d.Kb*de+ue>=0?(te=de-pe,ue=-ce,d.c1.jnAcc=de,d.c2.jnAcc=0):(me=-d.c2.nMass*ue,me>=0&&d.Kb*me+te>=0?(te=-pe,ue=me-ce,d.c1.jnAcc=0,d.c2.jnAcc=me):te>=0&&ue>=0?(te=-pe,ue=-ce,d.c1.jnAcc=d.c2.jnAcc=0):(te=0,ue=0))),P=te+ue,M=d.nx*P,k=d.ny*P,d.b2.velx+=M*d.b2.imass,d.b2.vely+=k*d.b2.imass,d.b1.velx-=M*d.b1.imass,d.b1.vely-=k*d.b1.imass,d.b2.angvel+=(d.rn1b*te+d.rn2b*ue)*d.b2.iinertia,d.b1.angvel-=(d.rn1a*te+d.rn2a*ue)*d.b1.iinertia;}else d.radius!=0&&(P=(d.b2.angvel-d.b1.angvel)*d.rMass,v=d.rfric*d.c1.jnAcc,N=d.jrAcc,d.jrAcc-=P,d.jrAcc>v?d.jrAcc=v:d.jrAcc<-v&&(d.jrAcc=-v),P=d.jrAcc-N,d.b2.angvel+=P*d.b2.iinertia,d.b1.angvel-=P*d.b1.iinertia),f=d.k1x+d.b2.velx-d.c1.r2y*d.b2.angvel-(d.b1.velx-d.c1.r1y*d.b1.angvel),g=d.k1y+d.b2.vely+d.c1.r2x*d.b2.angvel-(d.b1.vely+d.c1.r1x*d.b1.angvel),P=(d.c1.bounce+(d.nx*f+d.ny*g)+d.surfacey)*d.c1.nMass,N=d.c1.jnAcc,E=N-P,E<0&&(E=0),P=E-N,d.c1.jnAcc=E,M=d.nx*P,k=d.ny*P,d.b2.velx+=M*d.b2.imass,d.b2.vely+=k*d.b2.imass,d.b1.velx-=M*d.b1.imass,d.b1.vely-=k*d.b1.imass,d.b2.angvel+=d.rn1b*P*d.b2.iinertia,d.b1.angvel-=d.rn1a*P*d.b1.iinertia;let C=m.colarb,S=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),F=(O*C.nx-S*C.ny+C.surfacex)*C.c1.tMass,T=C.c1.friction*C.c1.jnAcc,R=C.c1.jtAcc,W=R-F;W>T?W=T:W<-T&&(W=-T),F=W-R,C.c1.jtAcc=W;let G=-C.ny*F,B=C.nx*F;if(C.b2.velx+=G*C.b2.imass,C.b2.vely+=B*C.b2.imass,C.b1.velx-=G*C.b1.imass,C.b1.vely-=B*C.b1.imass,C.b2.angvel+=C.rt1b*F*C.b2.iinertia,C.b1.angvel-=C.rt1a*F*C.b1.iinertia,C.hc2){let le=C.k2x+C.b2.velx-C.c2.r2y*C.b2.angvel-(C.b1.velx-C.c2.r1y*C.b1.angvel),he=C.k2y+C.b2.vely+C.c2.r2x*C.b2.angvel-(C.b1.vely+C.c2.r1x*C.b1.angvel);F=(he*C.nx-le*C.ny+C.surfacex)*C.c2.tMass,T=C.c2.friction*C.c2.jnAcc,R=C.c2.jtAcc,W=R-F,W>T?W=T:W<-T&&(W=-T),F=W-R,C.c2.jtAcc=W,G=-C.ny*F,B=C.nx*F,C.b2.velx+=G*C.b2.imass,C.b2.vely+=B*C.b2.imass,C.b1.velx-=G*C.b1.imass,C.b1.vely-=B*C.b1.imass,C.b2.angvel+=C.rt2b*F*C.b2.iinertia,C.b1.angvel-=C.rt2a*F*C.b1.iinertia,S=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),le=C.k2x+C.b2.velx-C.c2.r2y*C.b2.angvel-(C.b1.velx-C.c2.r1y*C.b1.angvel),he=C.k2y+C.b2.vely+C.c2.r2x*C.b2.angvel-(C.b1.vely+C.c2.r1x*C.b1.angvel);let pe=C.c1.jnAcc,ce=C.c2.jnAcc,te=S*C.nx+O*C.ny+C.surfacey+C.c1.bounce-(C.Ka*pe+C.Kb*ce),ue=le*C.nx+he*C.ny+C.surfacey+C.c2.bounce-(C.Kb*pe+C.Kc*ce),de=-(C.kMassa*te+C.kMassb*ue),me=-(C.kMassb*te+C.kMassc*ue);de>=0&&me>=0?(te=de-pe,ue=me-ce,C.c1.jnAcc=de,C.c2.jnAcc=me):(de=-C.c1.nMass*te,de>=0&&C.Kb*de+ue>=0?(te=de-pe,ue=-ce,C.c1.jnAcc=de,C.c2.jnAcc=0):(me=-C.c2.nMass*ue,me>=0&&C.Kb*me+te>=0?(te=-pe,ue=me-ce,C.c1.jnAcc=0,C.c2.jnAcc=me):te>=0&&ue>=0?(te=-pe,ue=-ce,C.c1.jnAcc=C.c2.jnAcc=0):(te=0,ue=0))),F=te+ue,G=C.nx*F,B=C.ny*F,C.b2.velx+=G*C.b2.imass,C.b2.vely+=B*C.b2.imass,C.b1.velx-=G*C.b1.imass,C.b1.vely-=B*C.b1.imass,C.b2.angvel+=(C.rn1b*te+C.rn2b*ue)*C.b2.iinertia,C.b1.angvel-=(C.rn1a*te+C.rn2a*ue)*C.b1.iinertia;}else C.radius!=0&&(F=(C.b2.angvel-C.b1.angvel)*C.rMass,T=C.rfric*C.c1.jnAcc,R=C.jrAcc,C.jrAcc-=F,C.jrAcc>T?C.jrAcc=T:C.jrAcc<-T&&(C.jrAcc=-T),F=C.jrAcc-R,C.b2.angvel+=F*C.b2.iinertia,C.b1.angvel-=F*C.b1.iinertia),S=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),F=(C.c1.bounce+(C.nx*S+C.ny*O)+C.surfacey)*C.c1.nMass,R=C.c1.jnAcc,W=R-F,W<0&&(W=0),F=W-R,C.c1.jnAcc=W,G=C.nx*F,B=C.ny*F,C.b2.velx+=G*C.b2.imass,C.b2.vely+=B*C.b2.imass,C.b1.velx-=G*C.b1.imass,C.b1.vely-=B*C.b1.imass,C.b2.angvel+=C.rn1b*F*C.b2.iinertia,C.b1.angvel-=C.rn1a*F*C.b1.iinertia;let A=m.colarb,Y=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),$=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),H=($*A.nx-Y*A.ny+A.surfacex)*A.c1.tMass,X=A.c1.friction*A.c1.jnAcc,ee=A.c1.jtAcc,q=ee-H;q>X?q=X:q<-X&&(q=-X),H=q-ee,A.c1.jtAcc=q;let D=-A.ny*H,L=A.nx*H;if(A.b2.velx+=D*A.b2.imass,A.b2.vely+=L*A.b2.imass,A.b1.velx-=D*A.b1.imass,A.b1.vely-=L*A.b1.imass,A.b2.angvel+=A.rt1b*H*A.b2.iinertia,A.b1.angvel-=A.rt1a*H*A.b1.iinertia,A.hc2){let le=A.k2x+A.b2.velx-A.c2.r2y*A.b2.angvel-(A.b1.velx-A.c2.r1y*A.b1.angvel),he=A.k2y+A.b2.vely+A.c2.r2x*A.b2.angvel-(A.b1.vely+A.c2.r1x*A.b1.angvel);H=(he*A.nx-le*A.ny+A.surfacex)*A.c2.tMass,X=A.c2.friction*A.c2.jnAcc,ee=A.c2.jtAcc,q=ee-H,q>X?q=X:q<-X&&(q=-X),H=q-ee,A.c2.jtAcc=q,D=-A.ny*H,L=A.nx*H,A.b2.velx+=D*A.b2.imass,A.b2.vely+=L*A.b2.imass,A.b1.velx-=D*A.b1.imass,A.b1.vely-=L*A.b1.imass,A.b2.angvel+=A.rt2b*H*A.b2.iinertia,A.b1.angvel-=A.rt2a*H*A.b1.iinertia,Y=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),$=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),le=A.k2x+A.b2.velx-A.c2.r2y*A.b2.angvel-(A.b1.velx-A.c2.r1y*A.b1.angvel),he=A.k2y+A.b2.vely+A.c2.r2x*A.b2.angvel-(A.b1.vely+A.c2.r1x*A.b1.angvel);let pe=A.c1.jnAcc,ce=A.c2.jnAcc,te=Y*A.nx+$*A.ny+A.surfacey+A.c1.bounce-(A.Ka*pe+A.Kb*ce),ue=le*A.nx+he*A.ny+A.surfacey+A.c2.bounce-(A.Kb*pe+A.Kc*ce),de=-(A.kMassa*te+A.kMassb*ue),me=-(A.kMassb*te+A.kMassc*ue);de>=0&&me>=0?(te=de-pe,ue=me-ce,A.c1.jnAcc=de,A.c2.jnAcc=me):(de=-A.c1.nMass*te,de>=0&&A.Kb*de+ue>=0?(te=de-pe,ue=-ce,A.c1.jnAcc=de,A.c2.jnAcc=0):(me=-A.c2.nMass*ue,me>=0&&A.Kb*me+te>=0?(te=-pe,ue=me-ce,A.c1.jnAcc=0,A.c2.jnAcc=me):te>=0&&ue>=0?(te=-pe,ue=-ce,A.c1.jnAcc=A.c2.jnAcc=0):(te=0,ue=0))),H=te+ue,D=A.nx*H,L=A.ny*H,A.b2.velx+=D*A.b2.imass,A.b2.vely+=L*A.b2.imass,A.b1.velx-=D*A.b1.imass,A.b1.vely-=L*A.b1.imass,A.b2.angvel+=(A.rn1b*te+A.rn2b*ue)*A.b2.iinertia,A.b1.angvel-=(A.rn1a*te+A.rn2a*ue)*A.b1.iinertia;}else A.radius!=0&&(H=(A.b2.angvel-A.b1.angvel)*A.rMass,X=A.rfric*A.c1.jnAcc,ee=A.jrAcc,A.jrAcc-=H,A.jrAcc>X?A.jrAcc=X:A.jrAcc<-X&&(A.jrAcc=-X),H=A.jrAcc-ee,A.b2.angvel+=H*A.b2.iinertia,A.b1.angvel-=H*A.b1.iinertia),Y=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),$=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),H=(A.c1.bounce+(A.nx*Y+A.ny*$)+A.surfacey)*A.c1.nMass,ee=A.c1.jnAcc,q=ee-H,q<0&&(q=0),H=q-ee,A.c1.jnAcc=q,D=A.nx*H,L=A.ny*H,A.b2.velx+=D*A.b2.imass,A.b2.vely+=L*A.b2.imass,A.b1.velx-=D*A.b1.imass,A.b1.vely-=L*A.b1.imass,A.b2.angvel+=A.rn1b*H*A.b2.iinertia,A.b1.angvel-=A.rn1a*H*A.b1.iinertia;let V=m.colarb,U=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-U*V.ny+V.surfacex)*V.c1.tMass,ie=V.c1.friction*V.c1.jnAcc,oe=V.c1.jtAcc,se=oe-K;se>ie?se=ie:se<-ie&&(se=-ie),K=se-oe,V.c1.jtAcc=se;let ne=-V.ny*K,re=V.nx*K;if(V.b2.velx+=ne*V.b2.imass,V.b2.vely+=re*V.b2.imass,V.b1.velx-=ne*V.b1.imass,V.b1.vely-=re*V.b1.imass,V.b2.angvel+=V.rt1b*K*V.b2.iinertia,V.b1.angvel-=V.rt1a*K*V.b1.iinertia,V.hc2){let le=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),he=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);K=(he*V.nx-le*V.ny+V.surfacex)*V.c2.tMass,ie=V.c2.friction*V.c2.jnAcc,oe=V.c2.jtAcc,se=oe-K,se>ie?se=ie:se<-ie&&(se=-ie),K=se-oe,V.c2.jtAcc=se,ne=-V.ny*K,re=V.nx*K,V.b2.velx+=ne*V.b2.imass,V.b2.vely+=re*V.b2.imass,V.b1.velx-=ne*V.b1.imass,V.b1.vely-=re*V.b1.imass,V.b2.angvel+=V.rt2b*K*V.b2.iinertia,V.b1.angvel-=V.rt2a*K*V.b1.iinertia,U=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),le=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),he=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);let pe=V.c1.jnAcc,ce=V.c2.jnAcc,te=U*V.nx+Q*V.ny+V.surfacey+V.c1.bounce-(V.Ka*pe+V.Kb*ce),ue=le*V.nx+he*V.ny+V.surfacey+V.c2.bounce-(V.Kb*pe+V.Kc*ce),de=-(V.kMassa*te+V.kMassb*ue),me=-(V.kMassb*te+V.kMassc*ue);de>=0&&me>=0?(te=de-pe,ue=me-ce,V.c1.jnAcc=de,V.c2.jnAcc=me):(de=-V.c1.nMass*te,de>=0&&V.Kb*de+ue>=0?(te=de-pe,ue=-ce,V.c1.jnAcc=de,V.c2.jnAcc=0):(me=-V.c2.nMass*ue,me>=0&&V.Kb*me+te>=0?(te=-pe,ue=me-ce,V.c1.jnAcc=0,V.c2.jnAcc=me):te>=0&&ue>=0?(te=-pe,ue=-ce,V.c1.jnAcc=V.c2.jnAcc=0):(te=0,ue=0))),K=te+ue,ne=V.nx*K,re=V.ny*K,V.b2.velx+=ne*V.b2.imass,V.b2.vely+=re*V.b2.imass,V.b1.velx-=ne*V.b1.imass,V.b1.vely-=re*V.b1.imass,V.b2.angvel+=(V.rn1b*te+V.rn2b*ue)*V.b2.iinertia,V.b1.angvel-=(V.rn1a*te+V.rn2a*ue)*V.b1.iinertia;}else V.radius!=0&&(K=(V.b2.angvel-V.b1.angvel)*V.rMass,ie=V.rfric*V.c1.jnAcc,oe=V.jrAcc,V.jrAcc-=K,V.jrAcc>ie?V.jrAcc=ie:V.jrAcc<-ie&&(V.jrAcc=-ie),K=V.jrAcc-oe,V.b2.angvel+=K*V.b2.iinertia,V.b1.angvel-=K*V.b1.iinertia),U=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*U+V.ny*Q)+V.surfacey)*V.c1.nMass,oe=V.c1.jnAcc,se=oe-K,se<0&&(se=0),K=se-oe,V.c1.jnAcc=se,ne=V.nx*K,re=V.ny*K,V.b2.velx+=ne*V.b2.imass,V.b2.vely+=re*V.b2.imass,V.b1.velx-=ne*V.b1.imass,V.b1.vely-=re*V.b1.imass,V.b2.angvel+=V.rn1b*K*V.b2.iinertia,V.b1.angvel-=V.rn1a*K*V.b1.iinertia;h.sweep_angvel=h.angvel%t,u.sweep_angvel=u.angvel%t;}if(m!=null&&m.active&&(m.immState&1)!=0&&m.type==Ie.COL){if(!h.sweepFrozen&&h.type!=3)if(h.sweepFrozen=true,l.failed)h.angvel=h.sweep_angvel=0;else if(l.slipped){let y=h;y.sweep_angvel*=I._nape.Config.angularCCDSlipScale,h.angvel=y.sweep_angvel;}else h.angvel=h.sweep_angvel;if(!u.sweepFrozen&&u.type!=3)if(u.sweepFrozen=true,l.failed)u.angvel=u.sweep_angvel=0;else if(l.slipped){let y=u;y.sweep_angvel*=I._nape.Config.angularCCDSlipScale,u.angvel=y.sweep_angvel;}else u.angvel=u.sweep_angvel;}let _=l;_.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=_;}for(;this.toiEvents.head!=null;){let r=this.toiEvents.pop_unsafe();r.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=r;}let s=this.kinematics.head;for(;s!=null;){let l=s.elt,r=e-l.sweepTime;if(r!=0){l.sweepTime=e;let o=r;if(l.posx+=l.velx*o,l.posy+=l.vely*o,l.angvel!=0){let a=l.sweep_angvel*r;if(l.rot+=a,a*a>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else {let p=a*a,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+a*l.axisy)*h;l.axisy=(c*l.axisy-a*l.axisx)*h,l.axisx=u;}}}l.sweepTime=0,s=s.next;}let i=this.live.head;for(;i!=null;){let l=i.elt;if(!l.sweepFrozen){let r=e-l.sweepTime;if(r!=0){l.sweepTime=e;let o=r;if(l.posx+=l.velx*o,l.posy+=l.vely*o,l.angvel!=0){let a=l.sweep_angvel*r;if(l.rot+=a,a*a>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else {let p=a*a,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+a*l.axisy)*h;l.axisy=(c*l.axisy-a*l.axisx)*h,l.axisx=u;}}}}l.sweepTime=0,i=i.next;}}continuousEvent(e,t,n,s,i){if(e.body.sweepFrozen&&t.body.sweepFrozen||e.body.disableCCD||t.body.disableCCD)return s;let l;if(s!=null&&s.colarb==null)l=true;else {let a=e.body,p=t.body,c;c=false;let h=a.constraints.head;for(;h!=null;){let m=h.elt;if(m.ignore&&m.pair_exists(a.id,p.id)){c=true;break}h=h.next;}let u,x;if(c)x=false;else {let m=e;for(;m!=null&&m.group==null;)m.ishape!=null?m=m.ishape.body:m.icompound!=null?m=m.icompound.compound:m=m.ibody.compound;let _=m==null?null:m.group,y;if(_==null)y=false;else {let z=t;for(;z!=null&&z.group==null;)z.ishape!=null?z=z.ishape.body:z.icompound!=null?z=z.icompound.compound:z=z.ibody.compound;let b=z==null?null:z.group;if(b==null)y=false;else {let w=false;for(;_!=null&&b!=null;){if(_==b){w=_.ignore;break}_.depth<b.depth?b=b.group:_=_.group;}y=w;}}x=!y;}if(x){let m;if(e.sensorEnabled||t.sensorEnabled){let _=e.filter,y=t.filter;m=(_.sensorMask&y.sensorGroup)!=0&&(y.sensorMask&_.sensorGroup)!=0;}else m=false;if(m)u=2;else {let _;if(e.fluidEnabled||t.fluidEnabled){let y=e.filter,z=t.filter;_=(y.fluidMask&z.fluidGroup)!=0&&(z.fluidMask&y.fluidGroup)!=0;}else _=false;if(_&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0))u=0;else {let y=e.filter,z=t.filter;u=(y.collisionMask&z.collisionGroup)!=0&&(z.collisionMask&y.collisionGroup)!=0&&!(a.imass==0&&p.imass==0&&a.iinertia==0&&p.iinertia==0)?1:-1;}}}else u=-1;l=u<=0;}if(l)return s;let r=e.body,o=t.body;if(n||r.bullet||o.bullet){let a;I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?a=new I._zpp.geom.ZPP_ToiEvent:(a=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=a.next,a.next=null),a.failed=false,a.s1=a.s2=null,a.arbiter=null;let p=r.type==3||o.type==3;if(n&&!p)e.body.type!=2?(a.s2=e,a.s1=t):(a.s1=e,a.s2=t),a.kinematic=false,Cn.staticSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD);else if(a.s1=e,a.s2=t,a.kinematic=p,a.s1.body.sweepFrozen||a.s2.body.sweepFrozen){if(a.s1.body.sweepFrozen){let c=a.s1;a.s1=a.s2,a.s2=c,a.frozen1=false,a.frozen2=true;}Cn.staticSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD);}else Cn.dynamicSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD,false);if(n&&a.toi<0||a.failed){let c=a;c.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=c;}else this.toiEvents.add(a),a.frozen1=a.s1.body.sweepFrozen,a.frozen2=a.s2.body.sweepFrozen,a.arbiter=s!=null?s.colarb:null;}return s}bodyCbWake(e){if(e.type==2&&e.cbSet!=null)if(this.midstep){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let s=this.push_callback(n);s.event=2,s.body=e,t=t.next;}}else e.component.woken=true;}bodyCbSleep(e){if(e.type==2&&e.cbSet!=null){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let s=this.push_callback(n);s.event=3,s.body=e,t=t.next;}}}constraintCbWake(e){if(e.cbSet!=null)if(this.midstep){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let s=this.push_callback(n);s.event=2,s.constraint=e,t=t.next;}}else e.component.woken=true;}constraintCbSleep(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let s=this.push_callback(n);s.event=3,s.constraint=e,t=t.next;}}}constraintCbBreak(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=4){t=t.next;continue}let s=this.push_callback(n);s.event=4,s.constraint=e,t=t.next;}}}nullListenerType(e,t){let n=new I._zpp.util.ZNPList_ZPP_Interactor,s=e.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next;}if(e!=t){let i=t.interactors.head;for(;i!=null;){let l=i.elt;n.add(l),i=i.next;}}for(;n.head!=null;){let i=n.pop_unsafe();if(i.icompound!=null){let l=i.icompound,r=l.bodies.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next;}let o=l.compounds.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next;}}else {let l=i.ibody!=null?i.ibody:i.ishape.body,r=i.ishape!=null?i.ishape:null,o=l.arbiters.head;for(;o!=null;){let a=o.elt;if(a.present==0){o=o.next;continue}if(r!=null&&!(a.ws1==r||a.ws2==r)){o=o.next;continue}this.MRCA_chains(a.ws1,a.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let h=this.mrca2.head;for(;h!=null;){let u=h.elt;if(c.cbSet==e&&u.cbSet!=t||c.cbSet==t&&u.cbSet!=e){h=h.next;continue}let x=I._zpp.phys.ZPP_Interactor.get(c,u);if(x!=null){for(;x.arbiters.head!=null;){let m=x.arbiters.pop_unsafe();m.present--;}this.remove_callbackset(x);}h=h.next;}p=p.next;}o=o.next;}}}}nullInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,s=n.bodies.head;for(;s!=null;){let l=s.elt;this.nullInteractorType(l,t),s=s.next;}let i=n.compounds.head;for(;i!=null;){let l=i.elt;this.nullInteractorType(l,t),i=i.next;}}else {let n=e.ibody!=null?e.ibody:e.ishape.body,s=e.ishape!=null?e.ishape:null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(l.present==0){i=i.next;continue}if(s!=null&&!(l.ws1==s||l.ws2==s)){i=i.next;continue}this.MRCA_chains(l.ws1,l.ws2);let r=this.mrca1.head;for(;r!=null;){let o=r.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(o!=t&&p!=t){a=a.next;continue}let c=I._zpp.phys.ZPP_Interactor.get(o,p);c!=null&&(l.present--,c.remove_arb(l),c.arbiters.head==null&&this.remove_callbackset(c)),a=a.next;}r=r.next;}i=i.next;}}}freshListenerType(e,t){let n=new I._zpp.util.ZNPList_ZPP_Interactor,s=e.interactors.head;for(;s!=null;){let i=s.elt;n.add(i),s=s.next;}if(e!=t){let i=t.interactors.head;for(;i!=null;){let l=i.elt;n.add(l),i=i.next;}}for(;n.head!=null;){let i=n.pop_unsafe();if(i.icompound!=null){let l=i.icompound,r=l.bodies.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next;}let o=l.compounds.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next;}}else {let l=i.ibody!=null?i.ibody:i.ishape.body,r=i.ishape!=null?i.ishape:null,o=l.arbiters.head;for(;o!=null;){let a=o.elt;if(!a.presentable){o=o.next;continue}if(r!=null&&!(a.ws1==r||a.ws2==r)){o=o.next;continue}this.MRCA_chains(a.ws1,a.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let h=this.mrca2.head;for(;h!=null;){let u=h.elt;if(c.cbSet==e&&u.cbSet!=t||c.cbSet==t&&u.cbSet!=e){h=h.next;continue}let x=I._zpp.phys.ZPP_Interactor.get(c,u);x==null&&(x=Yt.get(c,u),this.add_callbackset(x));let m,_;_=false;let y=x.arbiters.head;for(;y!=null;){if(y.elt==a){_=true;break}y=y.next;}if(_)m=false;else {let z=x.arbiters,b;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?b=new I._zpp.util.ZNPNode_ZPP_Arbiter:(b=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=b.next,b.next=null),b.elt=a;let w=b;w.next=z.head,z.head=w,z.modified=true,z.length++,m=true;}m&&a.present++,h=h.next;}p=p.next;}o=o.next;}}}}freshInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,s=n.bodies.head;for(;s!=null;){let l=s.elt;this.freshInteractorType(l,t),s=s.next;}let i=n.compounds.head;for(;i!=null;){let l=i.elt;this.freshInteractorType(l,t),i=i.next;}}else {let n=e.ibody!=null?e.ibody:e.ishape.body,s=e.ishape!=null?e.ishape:null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(!l.presentable){i=i.next;continue}if(s!=null&&!(l.ws1==s||l.ws2==s)){i=i.next;continue}this.MRCA_chains(l.ws1,l.ws2);let r=this.mrca1.head;for(;r!=null;){let o=r.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(o!=t&&p!=t){a=a.next;continue}let c=o.cbSet,h=p.cbSet;c.validate(),h.validate();c.manager;let x=null,_=(c.cbpairs.length<h.cbpairs.length?c.cbpairs:h.cbpairs).head;for(;_!=null;){let y=_.elt;if(y.a==c&&y.b==h||y.a==h&&y.b==c){x=y;break}_=_.next;}if(x==null){let y;Ne.zpp_pool==null?y=new Ne:(y=Ne.zpp_pool,Ne.zpp_pool=y.next,y.next=null),y.zip_listeners=true,dt.setlt(c,h)?(y.a=c,y.b=h):(y.a=h,y.b=c),x=y,c.cbpairs.add(x),h!=c&&h.cbpairs.add(x);}if(x.zip_listeners&&(x.zip_listeners=false,x.__validate()),x.listeners.head!=null){let y=I._zpp.phys.ZPP_Interactor.get(o,p);y==null&&(y=Yt.get(o,p),this.add_callbackset(y));let z,b;b=false;let w=y.arbiters.head;for(;w!=null;){if(w.elt==l){b=true;break}w=w.next;}if(b)z=false;else {let Z=y.arbiters,d;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_Arbiter:(d=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=d.next,d.next=null),d.elt=l;let f=d;f.next=Z.head,Z.head=f,Z.modified=true,Z.length++,z=true;}z&&l.present++;}a=a.next;}r=r.next;}i=i.next;}}}wakeCompound(e){let t=e.bodies.head;for(;t!=null;){let l=t.elt;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=true),l.component.sleeping&&this.really_wake(l,false)),t=t.next;}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.wake_constraint(i),n=n.next;}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.wakeCompound(i),s=s.next;}}wakeIsland(e){for(;e.comps.head!=null;){let n=e.comps.pop_unsafe();if(n.waket=this.stamp+(this.midstep?0:1),n.isBody){let s=n.body;this.live.add(s);let i=s.arbiters.head;for(;i!=null;){let l=i.elt;if(l.sleeping)if(l.sleeping=false,l.up_stamp+=this.stamp-l.sleep_stamp,l.type==Ie.COL){let r=l.colarb;if(r.stat){let o=this.c_arbiters_true,a;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(a=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=true,o.length++;}else {let o=this.c_arbiters_false,a;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(a=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=r;let p=a;p.next=o.head,o.head=p,o.modified=true,o.length++;}}else if(l.type==Ie.FLUID){let r=this.f_arbiters,o=l.fluidarb,a;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(a=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=true,r.length++;}else {let r=this.s_arbiters,o=l.sensorarb,a;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(a=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=true,r.length++;}i=i.next;}if(this.bodyCbWake(s),n.sleeping=false,n.island=null,n.parent=n,n.rank=0,s.type!=1){let l=s.shapes.head;for(;l!=null;){let r=l.elt;r.node!=null&&this.bphase.sync(r),l=l.next;}}}else {let s=n.constraint,i=this.live_constraints,l;I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?l=new I._zpp.util.ZNPNode_ZPP_Constraint:(l=I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=l.next,l.next=null),l.elt=s;let r=l;r.next=i.head,i.head=r,i.modified=true,i.length++,this.constraintCbWake(s),n.sleeping=false,n.island=null,n.parent=n,n.rank=0;}}let t=e;t.next=xt.zpp_pool,xt.zpp_pool=t;}non_inlined_wake(e,t){t==null&&(t=false);let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=true),n.component.sleeping&&this.really_wake(n,t));}really_wake(e,t){if(t==null&&(t=false),e.component.island==null){if(e.component.sleeping=false,e.type==3||e.type==1){let i=this.staticsleep,l;I._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?l=new I._zpp.util.ZNPNode_ZPP_Body:(l=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;r.next=i.head,i.head=r,i.modified=true,i.length++;}else {let i=this.live,l;I._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?l=new I._zpp.util.ZNPNode_ZPP_Body:(l=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=l.next,l.next=null),l.elt=e;let r=l;r.next=i.head,i.head=r,i.modified=true,i.length++;}let n=e.constraints.head;for(;n!=null;){let i=n.elt;i.space==this&&this.wake_constraint(i),n=n.next;}let s=e.arbiters.head;for(;s!=null;){let i=s.elt;if(i.sleeping)if(i.sleeping=false,i.up_stamp+=this.stamp+(this.midstep?0:1)-i.sleep_stamp,i.type==Ie.COL){let l=i.colarb;if(l.stat){let r=this.c_arbiters_true,o;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(o=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=o.next,o.next=null),o.elt=l;let a=o;a.next=r.head,r.head=a,r.modified=true,r.length++;}else {let r=this.c_arbiters_false,o;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(o=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=o.next,o.next=null),o.elt=l;let a=o;a.next=r.head,r.head=a,r.modified=true,r.length++;}}else if(i.type==Ie.FLUID){let l=this.f_arbiters,r=i.fluidarb,o;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(o=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=o.next,o.next=null),o.elt=r;let a=o;a.next=l.head,l.head=a,l.modified=true,l.length++;}else {let l=this.s_arbiters,r=i.sensorarb,o;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(o=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=o.next,o.next=null),o.elt=r;let a=o;a.next=l.head,l.head=a,l.modified=true,l.length++;}if(i.type!=Ie.SENSOR&&!i.cleared&&i.up_stamp>=this.stamp&&(i.immState&1)!=0){if(i.b1.type==2&&i.b1.component.sleeping){let l=i.b1;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=true),l.component.sleeping&&this.really_wake(l,false));}if(i.b2.type==2&&i.b2.component.sleeping){let l=i.b2;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=true),l.component.sleeping&&this.really_wake(l,false));}}s=s.next;}if(!t&&e.type==2&&this.bodyCbWake(e),!t&&!this.bphase.is_sweep&&e.type!=1){let i=e.shapes.head;for(;i!=null;){let l=i.elt;l.node!=null&&this.bphase.sync(l),i=i.next;}}}else this.wakeIsland(e.component.island);}wake_constraint(e,t){if(t==null&&(t=false),e.active)if(e.component.waket=this.stamp+(this.midstep?0:1),e.component.sleeping){if(e.component.island==null){e.component.sleeping=false;let n=this.live_constraints,s;I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?s=new I._zpp.util.ZNPNode_ZPP_Constraint:(s=I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=s.next,s.next=null),s.elt=e;let i=s;i.next=n.head,n.head=i,n.modified=true,n.length++,e.wake_connected(),t||this.constraintCbWake(e);}else this.wakeIsland(e.component.island);return true}else return false;else return false}doForests(e){let t=this.c_arbiters_false.head;for(;t!=null;){let i=t.elt;if(!i.cleared&&i.up_stamp==this.stamp&&(i.immState&1)!=0&&i.b1.type==2&&i.b2.type==2){let l;if(i.b1.component==i.b1.component.parent)l=i.b1.component;else {let o=i.b1.component,a=null;for(;o!=o.parent;){let p=o.parent;o.parent=a,a=o,o=p;}for(;a!=null;){let p=a.parent;a.parent=o,a=p;}l=o;}let r;if(i.b2.component==i.b2.component.parent)r=i.b2.component;else {let o=i.b2.component,a=null;for(;o!=o.parent;){let p=o.parent;o.parent=a,a=o,o=p;}for(;a!=null;){let p=a.parent;a.parent=o,a=p;}r=o;}l!=r&&(l.rank<r.rank?l.parent=r:l.rank>r.rank?r.parent=l:(r.parent=l,l.rank++));}t=t.next;}let n=this.f_arbiters.head;for(;n!=null;){let i=n.elt;if(!i.cleared&&i.up_stamp==this.stamp&&(i.immState&1)!=0&&i.b1.type==2&&i.b2.type==2){let l;if(i.b1.component==i.b1.component.parent)l=i.b1.component;else {let o=i.b1.component,a=null;for(;o!=o.parent;){let p=o.parent;o.parent=a,a=o,o=p;}for(;a!=null;){let p=a.parent;a.parent=o,a=p;}l=o;}let r;if(i.b2.component==i.b2.component.parent)r=i.b2.component;else {let o=i.b2.component,a=null;for(;o!=o.parent;){let p=o.parent;o.parent=a,a=o,o=p;}for(;a!=null;){let p=a.parent;a.parent=o,a=p;}r=o;}l!=r&&(l.rank<r.rank?l.parent=r:l.rank>r.rank?r.parent=l:(r.parent=l,l.rank++));}n=n.next;}let s=this.live_constraints.head;for(;s!=null;)s.elt.forest(),s=s.next;for(;this.live.head!=null;){let i=this.live,l=i.head.elt;i.pop();let r=l,o=r.component,a;if(o==o.parent)a=o;else {let x=o,m=null;for(;x!=x.parent;){let _=x.parent;x.parent=m,m=x,x=_;}for(;m!=null;){let _=m.parent;m.parent=x,m=_;}a=x;}if(a.island==null){xt.zpp_pool==null?a.island=new xt:(a.island=xt.zpp_pool,xt.zpp_pool=a.island.next,a.island.next=null),a.island.waket=0;let x=this.islands,m=a.island;m._inuse=true;let _=m;_.next=x.next,x.next=_,x.modified=true,x.length++,a.island.sleep=true;}o.island=a.island;let p=o.island.comps,c;I._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new I._zpp.util.ZNPNode_ZPP_Component:(c=I._zpp.util.ZNPNode_ZPP_Component.zpp_pool,I._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=o;let h=c;h.next=p.head,p.head=h,p.modified=true,p.length++;let u=r.atRest(e);o.island.sleep=o.island.sleep&&u,o.waket>o.island.waket&&(o.island.waket=o.waket);}for(;this.live_constraints.head!=null;){let i=this.live_constraints,l=i.head.elt;i.pop();let o=l.component,a;if(o==o.parent)a=o;else {let u=o,x=null;for(;u!=u.parent;){let m=u.parent;u.parent=x,x=u,u=m;}for(;x!=null;){let m=x.parent;x.parent=u,x=m;}a=u;}o.island=a.island;let p=o.island.comps,c;I._zpp.util.ZNPNode_ZPP_Component.zpp_pool==null?c=new I._zpp.util.ZNPNode_ZPP_Component:(c=I._zpp.util.ZNPNode_ZPP_Component.zpp_pool,I._zpp.util.ZNPNode_ZPP_Component.zpp_pool=c.next,c.next=null),c.elt=o;let h=c;h.next=p.head,p.head=h,p.modified=true,p.length++,o.waket>o.island.waket&&(o.island.waket=o.waket);}for(;this.islands.next!=null;){let i=this.islands,l=i.next;i.pop();let r=l;if(this.deterministic&&this._sortLinkedList(r.comps,o=>o.isBody?o.body.id:o.constraint.id+1e9),r.sleep){let o=r.comps.head;for(;o!=null;){let a=o.elt;if(a.isBody){let p=a.body;p.velx=0,p.vely=0,p.angvel=0,a.sleeping=true;let c=p.shapes.head;for(;c!=null;){let h=c.elt;this.bphase.sync(h),c=c.next;}this.bodyCbSleep(p);}else {let p=a.constraint;this.constraintCbSleep(p),a.sleeping=true;}o=o.next;}}else {for(;r.comps.head!=null;){let a=r.comps,p=a.head.elt;a.pop();let c=p;if(c.waket=r.waket,c.isBody){let h=this.live,u=c.body,x;I._zpp.util.ZNPNode_ZPP_Body.zpp_pool==null?x=new I._zpp.util.ZNPNode_ZPP_Body:(x=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=x.next,x.next=null),x.elt=u;let m=x;m.next=h.head,h.head=m,h.modified=true,h.length++;}else {let h=this.live_constraints,u=c.constraint,x;I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool==null?x=new I._zpp.util.ZNPNode_ZPP_Constraint:(x=I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool,I._zpp.util.ZNPNode_ZPP_Constraint.zpp_pool=x.next,x.next=null),x.elt=u;let m=x;m.next=h.head,h.head=m,h.modified=true,h.length++;}c.sleeping=false,c.island=null,c.parent=c,c.rank=0;}let o=r;o.next=xt.zpp_pool,xt.zpp_pool=o;}}}sleepArbiters(){let e=null,t=this.c_arbiters_true,n=t.head,s=this.c_arbiters_false!=null;for(s&&n==null&&(s=false,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);n!=null;){let u=n.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=true;let x,m;e==null?(x=t.head,m=x.next,t.head=m,t.head==null&&(t.pushmod=true)):(x=e.next,m=x.next,e.next=m,m==null&&(t.pushmod=true));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=_,t.modified=true,t.length--,t.pushmod=true,n=m,s&&n==null&&(s=false,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);continue}e=n,n=n.next,s&&n==null&&(s=false,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);}let i=null,l=this.f_arbiters,r=l.head,o=false;for(o;r!=null;){let u=r.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=true;let x,m;i==null?(x=l.head,m=x.next,l.head=m,l.head==null&&(l.pushmod=true)):(x=i.next,m=x.next,i.next=m,m==null&&(l.pushmod=true));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=_,l.modified=true,l.length--,l.pushmod=true,r=m;continue}i=r,r=r.next;}let a=null,p=this.s_arbiters,c=p.head,h=false;for(h;c!=null;){let u=c.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=true;let x,m;a==null?(x=p.head,m=x.next,p.head=m,p.head==null&&(p.pushmod=true)):(x=a.next,m=x.next,a.next=m,m==null&&(p.pushmod=true));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=_,p.modified=true,p.length--,p.pushmod=true,c=m;continue}a=c,c=c.next;}}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=false,e.aabb.minx=1/0,e.aabb.miny=1/0,e.aabb.maxx=-1/0,e.aabb.maxy=-1/0;let n=e.shapes.head;for(;n!=null;){let s=n.elt;if(s.zip_aabb&&s.body!=null)if(s.zip_aabb=false,s.type==0){let r=s.circle;if(r.zip_worldCOM&&r.body!=null){if(r.zip_worldCOM=false,r.zip_localCOM){if(r.zip_localCOM=false,r.type==1){let c=r.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let h=1;c.localCOMx+=c.lverts.next.next.x*h,c.localCOMy+=c.lverts.next.next.y*h;let u=.5;c.localCOMx*=u,c.localCOMy*=u;}else {c.localCOMx=0,c.localCOMy=0;let h=0,u=c.lverts.next,x=u;u=u.next;let m=u;for(u=u.next;u!=null;){let Z=u;h+=m.x*(Z.y-x.y);let d=Z.y*m.x-Z.x*m.y;c.localCOMx+=(m.x+Z.x)*d,c.localCOMy+=(m.y+Z.y)*d,x=m,m=Z,u=u.next;}u=c.lverts.next;let _=u;h+=m.x*(_.y-x.y);let y=_.y*m.x-_.x*m.y;c.localCOMx+=(m.x+_.x)*y,c.localCOMy+=(m.y+_.y)*y,x=m,m=_,u=u.next;let z=u;h+=m.x*(z.y-x.y);let b=z.y*m.x-z.x*m.y;c.localCOMx+=(m.x+z.x)*b,c.localCOMy+=(m.y+z.y)*b,h=1/(3*h);let w=h;c.localCOMx*=w,c.localCOMy*=w;}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy);}let p=r.body;p.zip_axis&&(p.zip_axis=false,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),r.worldCOMx=r.body.posx+(r.body.axisy*r.localCOMx-r.body.axisx*r.localCOMy),r.worldCOMy=r.body.posy+(r.localCOMx*r.body.axisx+r.localCOMy*r.body.axisy);}let o=r.radius,a=r.radius;r.aabb.minx=r.worldCOMx-o,r.aabb.miny=r.worldCOMy-a,r.aabb.maxx=r.worldCOMx+o,r.aabb.maxy=r.worldCOMy+a;}else {let r=s.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=false,r.validate_lverts();let p=r.body;p.zip_axis&&(p.zip_axis=false,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=r.lverts.next,h=r.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=r.body.posx+(r.body.axisy*x.x-r.body.axisx*x.y),u.y=r.body.posy+(x.x*r.body.axisx+x.y*r.body.axisy),h=h.next;}}if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let o=r.gverts.next;r.aabb.minx=o.x,r.aabb.miny=o.y,r.aabb.maxx=o.x,r.aabb.maxy=o.y;let a=r.gverts.next.next;for(;a!=null;){let p=a;p.x<r.aabb.minx&&(r.aabb.minx=p.x),p.x>r.aabb.maxx&&(r.aabb.maxx=p.x),p.y<r.aabb.miny&&(r.aabb.miny=p.y),p.y>r.aabb.maxy&&(r.aabb.maxy=p.y),a=a.next;}}let i=e.aabb,l=s.aabb;l.minx<i.minx&&(i.minx=l.minx),l.maxx>i.maxx&&(i.maxx=l.maxx),l.miny<i.miny&&(i.miny=l.miny),l.maxy>i.maxy&&(i.maxy=l.maxy),n=n.next;}}}if(e.validate_mass(),e.validate_inertia(),e.velx!=0||e.vely!=0||e.angvel!=0)throw new Error("Error: Static body cannot have any real velocity, only kinematic or surface velocities");let t=e.shapes.head;for(;t!=null;){let n=t.elt;if(n.type==1){let s=n.polygon;s.zip_sanitation&&(s.zip_sanitation=false,s.splice_collinear_real());let i=n.polygon.valid();if(J.ValidationResult_VALID==null&&(J.internal=true,J.ValidationResult_VALID=new I._nape.shape.ValidationResult,J.internal=false),i!=J.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+n.polygon.outer.toString()+" is invalid : "+i.toString());let l=n.polygon;if(l.zip_gaxi&&l.body!=null){l.zip_gaxi=false,l.validate_laxi();let r=l.body;if(r.zip_axis&&(r.zip_axis=false,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),l.zip_gverts&&l.body!=null){l.zip_gverts=false,l.validate_lverts();let u=l.body;u.zip_axis&&(u.zip_axis=false,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let x=l.lverts.next,m=l.gverts.next;for(;m!=null;){let _=m,y=x;x=x.next,_.x=l.body.posx+(l.body.axisy*y.x-l.body.axisx*y.y),_.y=l.body.posy+(y.x*l.body.axisx+y.y*l.body.axisy),m=m.next;}}let o=l.edges.head,a=l.gverts.next,p=a;for(a=a.next;a!=null;){let u=a,x=o.elt;o=o.next,x.gp0=p,x.gp1=u,x.gnormx=l.body.axisy*x.lnormx-l.body.axisx*x.lnormy,x.gnormy=x.lnormx*l.body.axisx+x.lnormy*l.body.axisy,x.gprojection=l.body.posx*x.gnormx+l.body.posy*x.gnormy+x.lprojection,x.wrap_gnorm!=null&&(x.wrap_gnorm.zpp_inner.x=x.gnormx,x.wrap_gnorm.zpp_inner.y=x.gnormy),x.tp0=x.gp0.y*x.gnormx-x.gp0.x*x.gnormy,x.tp1=x.gp1.y*x.gnormx-x.gp1.x*x.gnormy,p=u,a=a.next;}let c=l.gverts.next,h=o.elt;o=o.next,h.gp0=p,h.gp1=c,h.gnormx=l.body.axisy*h.lnormx-l.body.axisx*h.lnormy,h.gnormy=h.lnormx*l.body.axisx+h.lnormy*l.body.axisy,h.gprojection=l.body.posx*h.gnormx+l.body.posy*h.gnormy+h.lprojection,h.wrap_gnorm!=null&&(h.wrap_gnorm.zpp_inner.x=h.gnormx,h.wrap_gnorm.zpp_inner.y=h.gnormy),h.tp0=h.gp0.y*h.gnormx-h.gp0.x*h.gnormy,h.tp1=h.gp1.y*h.gnormx-h.gp1.x*h.gnormy;}}t=t.next;}e.sweepFrozen=true;}validation(){let e=this.cbsets;if(!e.cbsets.empty()){let i=e.cbsets.parent;for(;i.prev!=null;)i=i.prev;for(;i!=null;)if(i.data.validate(),i.next!=null)for(i=i.next;i.prev!=null;)i=i.prev;else {for(;i.parent!=null&&i==i.parent.next;)i=i.parent;i=i.parent;}}let t=this.live.head;for(;t!=null;){let i=t.elt;i.sweepRadius=0;let l=i.shapes.head;for(;l!=null;){let o=l.elt;if(o.type==1){let a=o.polygon;a.zip_sanitation&&(a.zip_sanitation=false,a.splice_collinear_real());let p=o.polygon.valid();if(J.ValidationResult_VALID==null&&(J.internal=true,J.ValidationResult_VALID=new I._nape.shape.ValidationResult,J.internal=false),p!=J.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+o.polygon.outer.toString()+" is invalid : "+p.toString());let c=o.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=false,c.validate_laxi();let h=c.body;if(h.zip_axis&&(h.zip_axis=false,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=false,c.validate_lverts();let z=c.body;z.zip_axis&&(z.zip_axis=false,z.axisx=Math.sin(z.rot),z.axisy=Math.cos(z.rot));let b=c.lverts.next,w=c.gverts.next;for(;w!=null;){let Z=w,d=b;b=b.next,Z.x=c.body.posx+(c.body.axisy*d.x-c.body.axisx*d.y),Z.y=c.body.posy+(d.x*c.body.axisx+d.y*c.body.axisy),w=w.next;}}let u=c.edges.head,x=c.gverts.next,m=x;for(x=x.next;x!=null;){let z=x,b=u.elt;u=u.next,b.gp0=m,b.gp1=z,b.gnormx=c.body.axisy*b.lnormx-c.body.axisx*b.lnormy,b.gnormy=b.lnormx*c.body.axisx+b.lnormy*c.body.axisy,b.gprojection=c.body.posx*b.gnormx+c.body.posy*b.gnormy+b.lprojection,b.wrap_gnorm!=null&&(b.wrap_gnorm.zpp_inner.x=b.gnormx,b.wrap_gnorm.zpp_inner.y=b.gnormy),b.tp0=b.gp0.y*b.gnormx-b.gp0.x*b.gnormy,b.tp1=b.gp1.y*b.gnormx-b.gp1.x*b.gnormy,m=z,x=x.next;}let _=c.gverts.next,y=u.elt;u=u.next,y.gp0=m,y.gp1=_,y.gnormx=c.body.axisy*y.lnormx-c.body.axisx*y.lnormy,y.gnormy=y.lnormx*c.body.axisx+y.lnormy*c.body.axisy,y.gprojection=c.body.posx*y.gnormx+c.body.posy*y.gnormy+y.lprojection,y.wrap_gnorm!=null&&(y.wrap_gnorm.zpp_inner.x=y.gnormx,y.wrap_gnorm.zpp_inner.y=y.gnormy),y.tp0=y.gp0.y*y.gnormx-y.gp0.x*y.gnormy,y.tp1=y.gp1.y*y.gnormx-y.gp1.x*y.gnormy;}}o.validate_sweepRadius(),o.sweepRadius>i.sweepRadius&&(i.sweepRadius=o.sweepRadius),l=l.next;}if(i.validate_mass(),i.validate_inertia(),i.shapes.head!=null){if(i.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(i.zip_aabb){i.zip_aabb=false,i.aabb.minx=1/0,i.aabb.miny=1/0,i.aabb.maxx=-1/0,i.aabb.maxy=-1/0;let o=i.shapes.head;for(;o!=null;){let a=o.elt;if(a.zip_aabb&&a.body!=null)if(a.zip_aabb=false,a.type==0){let h=a.circle;if(h.zip_worldCOM&&h.body!=null){if(h.zip_worldCOM=false,h.zip_localCOM){if(h.zip_localCOM=false,h.type==1){let _=h.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 y=1;_.localCOMx+=_.lverts.next.next.x*y,_.localCOMy+=_.lverts.next.next.y*y;let z=.5;_.localCOMx*=z,_.localCOMy*=z;}else {_.localCOMx=0,_.localCOMy=0;let y=0,z=_.lverts.next,b=z;z=z.next;let w=z;for(z=z.next;z!=null;){let v=z;y+=w.x*(v.y-b.y);let N=v.y*w.x-v.x*w.y;_.localCOMx+=(w.x+v.x)*N,_.localCOMy+=(w.y+v.y)*N,b=w,w=v,z=z.next;}z=_.lverts.next;let Z=z;y+=w.x*(Z.y-b.y);let d=Z.y*w.x-Z.x*w.y;_.localCOMx+=(w.x+Z.x)*d,_.localCOMy+=(w.y+Z.y)*d,b=w,w=Z,z=z.next;let f=z;y+=w.x*(f.y-b.y);let g=f.y*w.x-f.x*w.y;_.localCOMx+=(w.x+f.x)*g,_.localCOMy+=(w.y+f.y)*g,y=1/(3*y);let P=y;_.localCOMx*=P,_.localCOMy*=P;}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy);}let m=h.body;m.zip_axis&&(m.zip_axis=false,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot)),h.worldCOMx=h.body.posx+(h.body.axisy*h.localCOMx-h.body.axisx*h.localCOMy),h.worldCOMy=h.body.posy+(h.localCOMx*h.body.axisx+h.localCOMy*h.body.axisy);}let u=h.radius,x=h.radius;h.aabb.minx=h.worldCOMx-u,h.aabb.miny=h.worldCOMy-x,h.aabb.maxx=h.worldCOMx+u,h.aabb.maxy=h.worldCOMy+x;}else {let h=a.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=false,h.validate_lverts();let m=h.body;m.zip_axis&&(m.zip_axis=false,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot));let _=h.lverts.next,y=h.gverts.next;for(;y!=null;){let z=y,b=_;_=_.next,z.x=h.body.posx+(h.body.axisy*b.x-h.body.axisx*b.y),z.y=h.body.posy+(b.x*h.body.axisx+b.y*h.body.axisy),y=y.next;}}if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let u=h.gverts.next;h.aabb.minx=u.x,h.aabb.miny=u.y,h.aabb.maxx=u.x,h.aabb.maxy=u.y;let x=h.gverts.next.next;for(;x!=null;){let m=x;m.x<h.aabb.minx&&(h.aabb.minx=m.x),m.x>h.aabb.maxx&&(h.aabb.maxx=m.x),m.y<h.aabb.miny&&(h.aabb.miny=m.y),m.y>h.aabb.maxy&&(h.aabb.maxy=m.y),x=x.next;}}let p=i.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),o=o.next;}}i.validate_worldCOM();}if(i.validate_gravMass(),i.zip_axis&&(i.zip_axis=false,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),!i.nomove&&i.type==2&&i.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!i.norotate&&i.type==2&&i.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");if(i.component.woken&&i.cbSet!=null){let o=i.cbSet.bodylisteners.head;for(;o!=null;){let a=o.elt;if(a.event!=2){o=o.next;continue}let p=this.push_callback(a);p.event=2,p.body=i,o=o.next;}}i.component.woken=false;let r=i.shapes.head;for(;r!=null;){let o=r.elt;this.bphase.sync(o),r=r.next;}t=t.next;}let n=this.kinematics.head;for(;n!=null;){let i=n.elt;i.sweepRadius=0;let l=i.shapes.head;for(;l!=null;){let o=l.elt;if(o.type==1){let a=o.polygon;a.zip_sanitation&&(a.zip_sanitation=false,a.splice_collinear_real());let p=o.polygon.valid();if(J.ValidationResult_VALID==null&&(J.internal=true,J.ValidationResult_VALID=new I._nape.shape.ValidationResult,J.internal=false),p!=J.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+o.polygon.outer.toString()+" is invalid : "+p.toString());let c=o.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=false,c.validate_laxi();let h=c.body;if(h.zip_axis&&(h.zip_axis=false,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=false,c.validate_lverts();let z=c.body;z.zip_axis&&(z.zip_axis=false,z.axisx=Math.sin(z.rot),z.axisy=Math.cos(z.rot));let b=c.lverts.next,w=c.gverts.next;for(;w!=null;){let Z=w,d=b;b=b.next,Z.x=c.body.posx+(c.body.axisy*d.x-c.body.axisx*d.y),Z.y=c.body.posy+(d.x*c.body.axisx+d.y*c.body.axisy),w=w.next;}}let u=c.edges.head,x=c.gverts.next,m=x;for(x=x.next;x!=null;){let z=x,b=u.elt;u=u.next,b.gp0=m,b.gp1=z,b.gnormx=c.body.axisy*b.lnormx-c.body.axisx*b.lnormy,b.gnormy=b.lnormx*c.body.axisx+b.lnormy*c.body.axisy,b.gprojection=c.body.posx*b.gnormx+c.body.posy*b.gnormy+b.lprojection,b.wrap_gnorm!=null&&(b.wrap_gnorm.zpp_inner.x=b.gnormx,b.wrap_gnorm.zpp_inner.y=b.gnormy),b.tp0=b.gp0.y*b.gnormx-b.gp0.x*b.gnormy,b.tp1=b.gp1.y*b.gnormx-b.gp1.x*b.gnormy,m=z,x=x.next;}let _=c.gverts.next,y=u.elt;u=u.next,y.gp0=m,y.gp1=_,y.gnormx=c.body.axisy*y.lnormx-c.body.axisx*y.lnormy,y.gnormy=y.lnormx*c.body.axisx+y.lnormy*c.body.axisy,y.gprojection=c.body.posx*y.gnormx+c.body.posy*y.gnormy+y.lprojection,y.wrap_gnorm!=null&&(y.wrap_gnorm.zpp_inner.x=y.gnormx,y.wrap_gnorm.zpp_inner.y=y.gnormy),y.tp0=y.gp0.y*y.gnormx-y.gp0.x*y.gnormy,y.tp1=y.gp1.y*y.gnormx-y.gp1.x*y.gnormy;}}o.validate_sweepRadius(),o.sweepRadius>i.sweepRadius&&(i.sweepRadius=o.sweepRadius),l=l.next;}if(i.validate_mass(),i.validate_inertia(),i.shapes.head!=null){if(i.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(i.zip_aabb){i.zip_aabb=false,i.aabb.minx=1/0,i.aabb.miny=1/0,i.aabb.maxx=-1/0,i.aabb.maxy=-1/0;let o=i.shapes.head;for(;o!=null;){let a=o.elt;if(a.zip_aabb&&a.body!=null)if(a.zip_aabb=false,a.type==0){let h=a.circle;if(h.zip_worldCOM&&h.body!=null){if(h.zip_worldCOM=false,h.zip_localCOM){if(h.zip_localCOM=false,h.type==1){let _=h.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 y=1;_.localCOMx+=_.lverts.next.next.x*y,_.localCOMy+=_.lverts.next.next.y*y;let z=.5;_.localCOMx*=z,_.localCOMy*=z;}else {_.localCOMx=0,_.localCOMy=0;let y=0,z=_.lverts.next,b=z;z=z.next;let w=z;for(z=z.next;z!=null;){let v=z;y+=w.x*(v.y-b.y);let N=v.y*w.x-v.x*w.y;_.localCOMx+=(w.x+v.x)*N,_.localCOMy+=(w.y+v.y)*N,b=w,w=v,z=z.next;}z=_.lverts.next;let Z=z;y+=w.x*(Z.y-b.y);let d=Z.y*w.x-Z.x*w.y;_.localCOMx+=(w.x+Z.x)*d,_.localCOMy+=(w.y+Z.y)*d,b=w,w=Z,z=z.next;let f=z;y+=w.x*(f.y-b.y);let g=f.y*w.x-f.x*w.y;_.localCOMx+=(w.x+f.x)*g,_.localCOMy+=(w.y+f.y)*g,y=1/(3*y);let P=y;_.localCOMx*=P,_.localCOMy*=P;}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy);}let m=h.body;m.zip_axis&&(m.zip_axis=false,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot)),h.worldCOMx=h.body.posx+(h.body.axisy*h.localCOMx-h.body.axisx*h.localCOMy),h.worldCOMy=h.body.posy+(h.localCOMx*h.body.axisx+h.localCOMy*h.body.axisy);}let u=h.radius,x=h.radius;h.aabb.minx=h.worldCOMx-u,h.aabb.miny=h.worldCOMy-x,h.aabb.maxx=h.worldCOMx+u,h.aabb.maxy=h.worldCOMy+x;}else {let h=a.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=false,h.validate_lverts();let m=h.body;m.zip_axis&&(m.zip_axis=false,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot));let _=h.lverts.next,y=h.gverts.next;for(;y!=null;){let z=y,b=_;_=_.next,z.x=h.body.posx+(h.body.axisy*b.x-h.body.axisx*b.y),z.y=h.body.posy+(b.x*h.body.axisx+b.y*h.body.axisy),y=y.next;}}if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let u=h.gverts.next;h.aabb.minx=u.x,h.aabb.miny=u.y,h.aabb.maxx=u.x,h.aabb.maxy=u.y;let x=h.gverts.next.next;for(;x!=null;){let m=x;m.x<h.aabb.minx&&(h.aabb.minx=m.x),m.x>h.aabb.maxx&&(h.aabb.maxx=m.x),m.y<h.aabb.miny&&(h.aabb.miny=m.y),m.y>h.aabb.maxy&&(h.aabb.maxy=m.y),x=x.next;}}let p=i.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),o=o.next;}}i.validate_worldCOM();}if(i.validate_gravMass(),i.zip_axis&&(i.zip_axis=false,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),!i.nomove&&i.type==2&&i.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!i.norotate&&i.type==2&&i.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");let r=i.shapes.head;for(;r!=null;){let o=r.elt;this.bphase.sync(o),r=r.next;}n=n.next;}let s=this.live_constraints.head;for(;s!=null;){let i=s.elt;if(i.active){if(i.validate(),i.component.woken&&i.cbSet!=null){let l=i.cbSet.conlisteners.head;for(;l!=null;){let r=l.elt;if(r.event!=2){l=l.next;continue}let o=this.push_callback(r);o.event=2,o.constraint=i,l=l.next;}}i.component.woken=false;}s=s.next;}}updateVel(e){let n=1-e*this.global_lin_drag,s=1-e*this.global_ang_drag,i=this.live.head;for(;i!=null;){let l=i.elt;if(l.smass!=0){let r=e*l.imass;l.velx=n*l.velx+(l.forcex+this.gravityx*l.gravMass)*r,l.vely=n*l.vely+(l.forcey+this.gravityy*l.gravMass)*r;}if(l.sinertia!=0){let r=0,o=0;r=l.worldCOMx-l.posx,o=l.worldCOMy-l.posy;let a=l.torque+(this.gravityy*r-this.gravityx*o)*l.gravMass;l.angvel=s*l.angvel+a*e*l.iinertia;}i=i.next;}}updatePos(e){let t=2*Math.PI/e,n=this.live.head;for(;n!=null;){let i=n.elt;i.pre_posx=i.posx,i.pre_posy=i.posy,i.pre_rot=i.rot,i.sweepTime=0,i.sweep_angvel=i.angvel%t;let l=e-i.sweepTime;if(l!=0){i.sweepTime=e;let r=l;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let o=i.sweep_angvel*l;if(i.rot+=o,o*o>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else {let a=o*o,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+o*i.axisy)*c;i.axisy=(p*i.axisy-o*i.axisx)*c,i.axisx=h;}}}if(i.disableCCD)i.sweepFrozen=true,i.bullet=false;else {let r=I._nape.Config.staticCCDLinearThreshold*i.sweepRadius,o=I._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>r*r||i.angvel*i.angvel*e*e>o*o||i.type==3){let a=i.sweep_angvel;a<0&&(a=-a);let p=1/a,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,m=u.miny,_=u.maxx,y=u.maxy,z=a*e*h.sweepCoef*.008333333333333333|0;z>8&&(z=8);let b=a*e/z,w=e-i.sweepTime;if(w!=0){i.sweepTime=e;let f=w;if(i.posx+=i.velx*f,i.posy+=i.vely*f,i.angvel!=0){let g=i.sweep_angvel*w;if(i.rot+=g,g*g>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else {let P=g*g,v=1-.5*P,N=1-P*P/8,E=(v*i.axisx+g*i.axisy)*N;i.axisy=(v*i.axisy-g*i.axisx)*N,i.axisx=E;}}}if(h.type==0){let f=h.circle;f.worldCOMx=f.body.posx+(f.body.axisy*f.localCOMx-f.body.axisx*f.localCOMy),f.worldCOMy=f.body.posy+(f.localCOMx*f.body.axisx+f.localCOMy*f.body.axisy),f.aabb.minx=f.worldCOMx-f.radius,f.aabb.miny=f.worldCOMy-f.radius,f.aabb.maxx=f.worldCOMx+f.radius,f.aabb.maxy=f.worldCOMy+f.radius;}else {let f=h.polygon,g=f.lverts.next,P=f.gverts.next,v=g;g=g.next,P.x=f.body.posx+(f.body.axisy*v.x-f.body.axisx*v.y),P.y=f.body.posy+(v.x*f.body.axisx+v.y*f.body.axisy),f.aabb.minx=P.x,f.aabb.miny=P.y,f.aabb.maxx=P.x,f.aabb.maxy=P.y;let N=f.gverts.next.next;for(;N!=null;){let E=N,M=g;g=g.next,E.x=f.body.posx+(f.body.axisy*M.x-f.body.axisx*M.y),E.y=f.body.posy+(M.x*f.body.axisx+M.y*f.body.axisy),E.x<f.aabb.minx&&(f.aabb.minx=E.x),E.x>f.aabb.maxx&&(f.aabb.maxx=E.x),E.y<f.aabb.miny&&(f.aabb.miny=E.y),E.y>f.aabb.maxy&&(f.aabb.maxy=E.y),N=N.next;}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,_>u.maxx?u.maxx=_:_=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;let Z=1,d=z;for(;Z<d;){let f=Z++,g=b*f*p,P=g-i.sweepTime;if(P!=0){i.sweepTime=g;let v=P;if(i.posx+=i.velx*v,i.posy+=i.vely*v,i.angvel!=0){let N=i.sweep_angvel*P;if(i.rot+=N,N*N>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else {let E=N*N,M=1-.5*E,k=1-E*E/8,C=(M*i.axisx+N*i.axisy)*k;i.axisy=(M*i.axisy-N*i.axisx)*k,i.axisx=C;}}}if(h.type==0){let v=h.circle;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),v.aabb.minx=v.worldCOMx-v.radius,v.aabb.miny=v.worldCOMy-v.radius,v.aabb.maxx=v.worldCOMx+v.radius,v.aabb.maxy=v.worldCOMy+v.radius;}else {let v=h.polygon,N=v.lverts.next,E=v.gverts.next,M=N;N=N.next,E.x=v.body.posx+(v.body.axisy*M.x-v.body.axisx*M.y),E.y=v.body.posy+(M.x*v.body.axisx+M.y*v.body.axisy),v.aabb.minx=E.x,v.aabb.miny=E.y,v.aabb.maxx=E.x,v.aabb.maxy=E.y;let k=v.gverts.next.next;for(;k!=null;){let C=k,S=N;N=N.next,C.x=v.body.posx+(v.body.axisy*S.x-v.body.axisx*S.y),C.y=v.body.posy+(S.x*v.body.axisx+S.y*v.body.axisy),C.x<v.aabb.minx&&(v.aabb.minx=C.x),C.x>v.aabb.maxx&&(v.aabb.maxx=C.x),C.y<v.aabb.miny&&(v.aabb.miny=C.y),C.y>v.aabb.maxy&&(v.aabb.maxy=C.y),k=k.next;}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,_>u.maxx?u.maxx=_:_=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;}this.bphase.sync(h),c=c.next;}if(i.sweepFrozen=false,i.type==2&&i.bulletEnabled){let h=I._nape.Config.bulletCCDLinearThreshold*i.sweepRadius,u=I._nape.Config.bulletCCDAngularThreshold;((i.velx*i.velx+i.vely*i.vely)*e*e>h*h||i.angvel*i.angvel*e*e>u*u)&&(i.bullet=true);}}else i.sweepFrozen=true,i.bullet=false;}n=n.next;}let s=this.kinematics.head;for(;s!=null;){let i=s.elt;i.pre_posx=i.posx,i.pre_posy=i.posy,i.pre_rot=i.rot,i.sweepTime=0,i.sweep_angvel=i.angvel%t;let l=e-i.sweepTime;if(l!=0){i.sweepTime=e;let r=l;if(i.posx+=i.velx*r,i.posy+=i.vely*r,i.angvel!=0){let o=i.sweep_angvel*l;if(i.rot+=o,o*o>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else {let a=o*o,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+o*i.axisy)*c;i.axisy=(p*i.axisy-o*i.axisx)*c,i.axisx=h;}}}if(i.disableCCD)i.sweepFrozen=true,i.bullet=false;else {let r=I._nape.Config.staticCCDLinearThreshold*i.sweepRadius,o=I._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>r*r||i.angvel*i.angvel*e*e>o*o||i.type==3){let a=i.sweep_angvel;a<0&&(a=-a);let p=1/a,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,m=u.miny,_=u.maxx,y=u.maxy,z=a*e*h.sweepCoef*.008333333333333333|0;z>8&&(z=8);let b=a*e/z,w=e-i.sweepTime;if(w!=0){i.sweepTime=e;let f=w;if(i.posx+=i.velx*f,i.posy+=i.vely*f,i.angvel!=0){let g=i.sweep_angvel*w;if(i.rot+=g,g*g>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else {let P=g*g,v=1-.5*P,N=1-P*P/8,E=(v*i.axisx+g*i.axisy)*N;i.axisy=(v*i.axisy-g*i.axisx)*N,i.axisx=E;}}}if(h.type==0){let f=h.circle;f.worldCOMx=f.body.posx+(f.body.axisy*f.localCOMx-f.body.axisx*f.localCOMy),f.worldCOMy=f.body.posy+(f.localCOMx*f.body.axisx+f.localCOMy*f.body.axisy),f.aabb.minx=f.worldCOMx-f.radius,f.aabb.miny=f.worldCOMy-f.radius,f.aabb.maxx=f.worldCOMx+f.radius,f.aabb.maxy=f.worldCOMy+f.radius;}else {let f=h.polygon,g=f.lverts.next,P=f.gverts.next,v=g;g=g.next,P.x=f.body.posx+(f.body.axisy*v.x-f.body.axisx*v.y),P.y=f.body.posy+(v.x*f.body.axisx+v.y*f.body.axisy),f.aabb.minx=P.x,f.aabb.miny=P.y,f.aabb.maxx=P.x,f.aabb.maxy=P.y;let N=f.gverts.next.next;for(;N!=null;){let E=N,M=g;g=g.next,E.x=f.body.posx+(f.body.axisy*M.x-f.body.axisx*M.y),E.y=f.body.posy+(M.x*f.body.axisx+M.y*f.body.axisy),E.x<f.aabb.minx&&(f.aabb.minx=E.x),E.x>f.aabb.maxx&&(f.aabb.maxx=E.x),E.y<f.aabb.miny&&(f.aabb.miny=E.y),E.y>f.aabb.maxy&&(f.aabb.maxy=E.y),N=N.next;}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,_>u.maxx?u.maxx=_:_=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;let Z=1,d=z;for(;Z<d;){let f=Z++,g=b*f*p,P=g-i.sweepTime;if(P!=0){i.sweepTime=g;let v=P;if(i.posx+=i.velx*v,i.posy+=i.vely*v,i.angvel!=0){let N=i.sweep_angvel*P;if(i.rot+=N,N*N>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else {let E=N*N,M=1-.5*E,k=1-E*E/8,C=(M*i.axisx+N*i.axisy)*k;i.axisy=(M*i.axisy-N*i.axisx)*k,i.axisx=C;}}}if(h.type==0){let v=h.circle;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),v.aabb.minx=v.worldCOMx-v.radius,v.aabb.miny=v.worldCOMy-v.radius,v.aabb.maxx=v.worldCOMx+v.radius,v.aabb.maxy=v.worldCOMy+v.radius;}else {let v=h.polygon,N=v.lverts.next,E=v.gverts.next,M=N;N=N.next,E.x=v.body.posx+(v.body.axisy*M.x-v.body.axisx*M.y),E.y=v.body.posy+(M.x*v.body.axisx+M.y*v.body.axisy),v.aabb.minx=E.x,v.aabb.miny=E.y,v.aabb.maxx=E.x,v.aabb.maxy=E.y;let k=v.gverts.next.next;for(;k!=null;){let C=k,S=N;N=N.next,C.x=v.body.posx+(v.body.axisy*S.x-v.body.axisx*S.y),C.y=v.body.posy+(S.x*v.body.axisx+S.y*v.body.axisy),C.x<v.aabb.minx&&(v.aabb.minx=C.x),C.x>v.aabb.maxx&&(v.aabb.maxx=C.x),C.y<v.aabb.miny&&(v.aabb.miny=C.y),C.y>v.aabb.maxy&&(v.aabb.maxy=C.y),k=k.next;}}x<u.minx?u.minx=x:x=u.minx,m<u.miny?u.miny=m:m=u.miny,_>u.maxx?u.maxx=_:_=u.maxx,y>u.maxy?u.maxy=y:y=u.maxy;}this.bphase.sync(h),c=c.next;}if(i.sweepFrozen=false,i.type==2&&i.bulletEnabled){let h=I._nape.Config.bulletCCDLinearThreshold*i.sweepRadius,u=I._nape.Config.bulletCCDAngularThreshold;((i.velx*i.velx+i.vely*i.vely)*e*e>h*h||i.angvel*i.angvel*e*e>u*u)&&(i.bullet=true);}}else i.sweepFrozen=true,i.bullet=false;}s=s.next;}}presteparb(e,t,n){if(n==null&&(n=false),!e.cleared&&e.b1.component.sleeping&&e.b2.component.sleeping)return e.sleep_stamp=this.stamp,e.sleeping=true,true;if(!e.cleared||e.present!=0||e.intchange){let i=!n&&e.up_stamp==this.stamp-1&&!e.cleared&&!e.intchange,l=e.fresh&&!e.cleared&&!e.intchange;if(i&&(e.endGenerated=this.stamp),l||i||e.cleared||e.intchange){let r=e.ws1,o=e.ws2,a=this.mrca1;for(;a.head!=null;){let x=a.head;a.head=x.next;let m=x;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m,a.head==null&&(a.pushmod=true),a.modified=true,a.length--;}a.pushmod=true;let p=this.mrca2;for(;p.head!=null;){let x=p.head;p.head=x.next;let m=x;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m,p.head==null&&(p.pushmod=true),p.modified=true,p.length--;}if(p.pushmod=true,r.cbSet!=null){let x=this.mrca1,m;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?m=new I._zpp.util.ZNPNode_ZPP_Interactor:(m=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m.next,m.next=null),m.elt=r;let _=m;_.next=x.head,x.head=_,x.modified=true,x.length++;}if(r.body.cbSet!=null){let x=this.mrca1,m=r.body,_;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new I._zpp.util.ZNPNode_ZPP_Interactor:(_=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=m;let y=_;y.next=x.head,x.head=y,x.modified=true,x.length++;}if(o.cbSet!=null){let x=this.mrca2,m;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?m=new I._zpp.util.ZNPNode_ZPP_Interactor:(m=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m.next,m.next=null),m.elt=o;let _=m;_.next=x.head,x.head=_,x.modified=true,x.length++;}if(o.body.cbSet!=null){let x=this.mrca2,m=o.body,_;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?_=new I._zpp.util.ZNPNode_ZPP_Interactor:(_=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=_.next,_.next=null),_.elt=m;let y=_;y.next=x.head,x.head=y,x.modified=true,x.length++;}let c=r.body.compound,h=o.body.compound;for(;c!=h;){let x=c==null?0:c.depth,m=h==null?0:h.depth;if(x<m){if(h.cbSet!=null){let _=this.mrca2,y;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?y=new I._zpp.util.ZNPNode_ZPP_Interactor:(y=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y.next,y.next=null),y.elt=h;let z=y;z.next=_.head,_.head=z,_.modified=true,_.length++;}h=h.compound;}else {if(c.cbSet!=null){let _=this.mrca1,y;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?y=new I._zpp.util.ZNPNode_ZPP_Interactor:(y=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y.next,y.next=null),y.elt=c;let z=y;z.next=_.head,_.head=z,_.modified=true,_.length++;}c=c.compound;}}let u=this.mrca1.head;for(;u!=null;){let x=u.elt,m=this.mrca2.head;for(;m!=null;){let _=m.elt,y=x.cbSet,z=_.cbSet;y.manager;let w=null,d=(y.cbpairs.length<z.cbpairs.length?y.cbpairs:z.cbpairs).head;for(;d!=null;){let g=d.elt;if(g.a==y&&g.b==z||g.a==z&&g.b==y){w=g;break}d=d.next;}if(w==null){let g;Ne.zpp_pool==null?g=new Ne:(g=Ne.zpp_pool,Ne.zpp_pool=g.next,g.next=null),g.zip_listeners=true,dt.setlt(y,z)?(g.a=y,g.b=z):(g.a=z,g.b=y),w=g,y.cbpairs.add(w),z!=y&&z.cbpairs.add(w);}if(w.zip_listeners&&(w.zip_listeners=false,w.__validate()),w.listeners.head==null){m=m.next;continue}let f=I._zpp.phys.ZPP_Interactor.get(x,_);if(l||e.intchange){f==null&&(f=Yt.get(x,_),this.add_callbackset(f));y.manager;let P=null,N=(y.cbpairs.length<z.cbpairs.length?y.cbpairs:z.cbpairs).head;for(;N!=null;){let S=N.elt;if(S.a==y&&S.b==z||S.a==z&&S.b==y){P=S;break}N=N.next;}if(P==null){let S;Ne.zpp_pool==null?S=new Ne:(S=Ne.zpp_pool,Ne.zpp_pool=S.next,S.next=null),S.zip_listeners=true,dt.setlt(y,z)?(S.a=y,S.b=z):(S.a=z,S.b=y),P=S,y.cbpairs.add(P),z!=y&&z.cbpairs.add(P);}P.zip_listeners&&(P.zip_listeners=false,P.__validate());let E=P.listeners.head;for(;E!=null;){let S=E.elt;if(S.event==0&&(S.itype&e.type)!=0&&f.empty_arb(S.itype)){let O=this.push_callback(S);O.event=0;let F=f.int1,T=f.int2,R,W=S.options1,G=F.cbTypes;if(W.nonemptyintersection(G,W.includes)&&!W.nonemptyintersection(G,W.excludes)){let B=S.options2,A=T.cbTypes;R=B.nonemptyintersection(A,B.includes)&&!B.nonemptyintersection(A,B.excludes);}else R=false;R?(O.int1=F,O.int2=T):(O.int1=T,O.int2=F),O.set=f;}E=E.next;}let M,k;k=false;let C=f.arbiters.head;for(;C!=null;){if(C.elt==e){k=true;break}C=C.next;}if(k)M=false;else {let S=f.arbiters,O;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Arbiter:(O=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=O.next,O.next=null),O.elt=e;let F=O;F.next=S.head,S.head=F,S.modified=true,S.length++,M=true;}M&&e.present++;}else {e.present--,f.remove_arb(e);y.manager;let P=null,N=(y.cbpairs.length<z.cbpairs.length?y.cbpairs:z.cbpairs).head;for(;N!=null;){let M=N.elt;if(M.a==y&&M.b==z||M.a==z&&M.b==y){P=M;break}N=N.next;}if(P==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=true,dt.setlt(y,z)?(M.a=y,M.b=z):(M.a=z,M.b=y),P=M,y.cbpairs.add(P),z!=y&&z.cbpairs.add(P);}P.zip_listeners&&(P.zip_listeners=false,P.__validate());let E=P.listeners.head;for(;E!=null;){let M=E.elt;if(M.event==1&&(M.itype&e.type)!=0&&f.empty_arb(M.itype)){let k=this.push_callback(M);k.event=1;let C=f.int1,S=f.int2,O,F=M.options1,T=C.cbTypes;if(F.nonemptyintersection(T,F.includes)&&!F.nonemptyintersection(T,F.excludes)){let R=M.options2,W=S.cbTypes;O=R.nonemptyintersection(W,R.includes)&&!R.nonemptyintersection(W,R.excludes);}else O=false;O?(k.int1=C,k.int2=S):(k.int1=S,k.int2=C),k.set=f;}E=E.next;}f.arbiters.head==null&&this.remove_callbackset(f);}m=m.next;}u=u.next;}}e.fresh=false,e.intchange=false;}if(e.cleared||e.up_stamp+(e.type==Ie.COL?I._nape.Config.arbiterExpirationDelay:0)<this.stamp){if(e.type==Ie.SENSOR){let i=e.sensorarb;if(!i.cleared){let r=i.b1.arbiters,o=null,a=r.head;for(;a!=null;){if(a.elt==i){let m,_;o==null?(m=r.head,_=m.next,r.head=_,r.head==null&&(r.pushmod=true)):(m=o.next,_=m.next,o.next=_,_==null&&(r.pushmod=true));let y=m;y.elt=null,y.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,r.modified=true,r.length--,r.pushmod=true;break}o=a,a=a.next;}let c=i.b2.arbiters,h=null,u=c.head;for(;u!=null;){if(u.elt==i){let m,_;h==null?(m=c.head,_=m.next,c.head=_,c.head==null&&(c.pushmod=true)):(m=h.next,_=m.next,h.next=_,_==null&&(c.pushmod=true));let y=m;y.elt=null,y.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,c.modified=true,c.length--,c.pushmod=true;break}h=u,u=u.next;}i.pair!=null&&(i.pair.arb=null,i.pair=null);}i.b1=i.b2=null,i.active=false,i.intchange=false;let l=i;l.next=Ot.zpp_pool,Ot.zpp_pool=l;}else if(e.type==Ie.FLUID){let i=e.fluidarb;if(!i.cleared){let r=i.b1.arbiters,o=null,a=r.head;for(;a!=null;){if(a.elt==i){let m,_;o==null?(m=r.head,_=m.next,r.head=_,r.head==null&&(r.pushmod=true)):(m=o.next,_=m.next,o.next=_,_==null&&(r.pushmod=true));let y=m;y.elt=null,y.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,r.modified=true,r.length--,r.pushmod=true;break}o=a,a=a.next;}let c=i.b2.arbiters,h=null,u=c.head;for(;u!=null;){if(u.elt==i){let m,_;h==null?(m=c.head,_=m.next,c.head=_,c.head==null&&(c.pushmod=true)):(m=h.next,_=m.next,h.next=_,_==null&&(c.pushmod=true));let y=m;y.elt=null,y.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,c.modified=true,c.length--,c.pushmod=true;break}h=u,u=u.next;}i.pair!=null&&(i.pair.arb=null,i.pair=null);}i.b1=i.b2=null,i.active=false,i.intchange=false;let l=i;l.next=Pt.zpp_pool,Pt.zpp_pool=l,i.pre_dt=-1;}else {let i=e.colarb;if(!i.cleared){let r=i.b1.arbiters,o=null,a=r.head;for(;a!=null;){if(a.elt==i){let m,_;o==null?(m=r.head,_=m.next,r.head=_,r.head==null&&(r.pushmod=true)):(m=o.next,_=m.next,o.next=_,_==null&&(r.pushmod=true));let y=m;y.elt=null,y.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,r.modified=true,r.length--,r.pushmod=true;break}o=a,a=a.next;}let c=i.b2.arbiters,h=null,u=c.head;for(;u!=null;){if(u.elt==i){let m,_;h==null?(m=c.head,_=m.next,c.head=_,c.head==null&&(c.pushmod=true)):(m=h.next,_=m.next,h.next=_,_==null&&(c.pushmod=true));let y=m;y.elt=null,y.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=y,c.modified=true,c.length--,c.pushmod=true;break}h=u,u=u.next;}i.pair!=null&&(i.pair.arb=null,i.pair=null);}for(i.b1=i.b2=null,i.active=false,i.intchange=false;i.contacts.next!=null;){let r=i.contacts,o=r.next;r.pop();let a=o;a.arbiter=null,a.next=we.zpp_pool,we.zpp_pool=a;let p=i.innards,c=p.next;p.next=c.next,c._inuse=false,p.next==null&&(p.pushmod=true),p.modified=true,p.length--;}let l=i;l.userdef_dyn_fric=false,l.userdef_stat_fric=false,l.userdef_restitution=false,l.userdef_rfric=false,l.__ref_edge1=l.__ref_edge2=null,l.next=ut.zpp_pool,ut.zpp_pool=l,i.pre_dt=-1;}return true}let s=e.active;if(e.active=e.presentable=e.up_stamp==this.stamp,(e.immState&1)!=0){if(e.active&&e.type!=Ie.SENSOR)if(e.colarb!=null){let i=e.colarb;i.invalidated&&(i.invalidated=false,i.userdef_restitution||(i.s1.material.elasticity<=-1/0||i.s2.material.elasticity<=-1/0?i.restitution=0:i.s1.material.elasticity>=1/0||i.s2.material.elasticity>=1/0?i.restitution=1:i.restitution=(i.s1.material.elasticity+i.s2.material.elasticity)/2,i.restitution<0&&(i.restitution=0),i.restitution>1&&(i.restitution=1)),i.userdef_dyn_fric||(i.dyn_fric=Math.sqrt(i.s1.material.dynamicFriction*i.s2.material.dynamicFriction)),i.userdef_stat_fric||(i.stat_fric=Math.sqrt(i.s1.material.staticFriction*i.s2.material.staticFriction)),i.userdef_rfric||(i.rfric=Math.sqrt(i.s1.material.rollingFriction*i.s2.material.rollingFriction))),i.pre_dt==-1&&(i.pre_dt=t);let l=t/i.pre_dt;i.pre_dt=t;let r=i.b1.smass+i.b2.smass;i.hc2=false;let o=true,p=i.b1.type!=2||i.b2.type!=2?i.continuous?I._nape.Config.contactContinuousStaticBiasCoef:I._nape.Config.contactStaticBiasCoef:i.continuous?I._nape.Config.contactContinuousBiasCoef:I._nape.Config.contactBiasCoef;i.biasCoef=p,i.continuous=false;let c=null,h=null,u=i.innards.next,x=i.contacts.next;for(;x!=null;){let _=x;if(_.stamp+I._nape.Config.arbiterExpirationDelay<i.stamp){let b=i.contacts,w,Z;c==null?(w=b.next,Z=w.next,b.next=Z,b.next==null&&(b.pushmod=true)):(w=c.next,Z=w.next,c.next=Z,Z==null&&(b.pushmod=true)),w._inuse=false,b.modified=true,b.length--,b.pushmod=true,x=Z;let d=i.innards,f,g;h==null?(f=d.next,g=f.next,d.next=g,d.next==null&&(d.pushmod=true)):(f=h.next,g=f.next,h.next=g,g==null&&(d.pushmod=true)),f._inuse=false,d.modified=true,d.length--,d.pushmod=true,u=g;let P=_;P.arbiter=null,P.next=we.zpp_pool,we.zpp_pool=P;continue}let y=_.inner,z=_.active;if(_.active=_.stamp==i.stamp,_.active){o?(o=false,i.c1=y,i.oc1=_):(i.hc2=true,i.c2=y,i.oc2=_),y.r2x=_.px-i.b2.posx,y.r2y=_.py-i.b2.posy,y.r1x=_.px-i.b1.posx,y.r1y=_.py-i.b1.posy;let b=y.r2x*i.nx+y.r2y*i.ny,w=r+i.b2.sinertia*(b*b),Z=y.r1x*i.nx+y.r1y*i.ny;w+=i.b1.sinertia*(Z*Z),y.tMass=w<I._nape.Config.epsilon*I._nape.Config.epsilon?0:1/w;let d=i.ny*y.r2x-i.nx*y.r2y,f=r+i.b2.sinertia*(d*d),g=i.ny*y.r1x-i.nx*y.r1y;f+=i.b1.sinertia*(g*g),y.nMass=f<I._nape.Config.epsilon*I._nape.Config.epsilon?0:1/f;let P=0,v=0,N=i.b2.angvel+i.b2.kinangvel;P=i.b2.velx+i.b2.kinvelx-y.r2y*N,v=i.b2.vely+i.b2.kinvely+y.r2x*N,N=i.b1.angvel+i.b1.kinangvel,P-=i.b1.velx+i.b1.kinvelx-y.r1y*N,v-=i.b1.vely+i.b1.kinvely+y.r1x*N;let E=i.nx*P+i.ny*v;_.elasticity=i.restitution,y.bounce=E*_.elasticity,y.bounce>-I._nape.Config.elasticThreshold&&(y.bounce=0),E=v*i.nx-P*i.ny;let M=I._nape.Config.staticFrictionThreshold;E*E>M*M?y.friction=i.dyn_fric:y.friction=i.stat_fric,y.jnAcc*=l,y.jtAcc*=l;}z!=_.active&&(i.contacts.modified=true),c=x,h=u,u=u.next,x=x.next;}if(i.hc2){if(i.hpc2=true,i.oc1.posOnly){let _=i.c1;i.c1=i.c2,i.c2=_;let y=i.oc1;i.oc1=i.oc2,i.oc2=y,i.hc2=false;}else i.oc2.posOnly&&(i.hc2=false);i.oc1.posOnly&&(o=true);}else i.hpc2=false;if(i.jrAcc*=l,o||(i.rn1a=i.ny*i.c1.r1x-i.nx*i.c1.r1y,i.rt1a=i.c1.r1x*i.nx+i.c1.r1y*i.ny,i.rn1b=i.ny*i.c1.r2x-i.nx*i.c1.r2y,i.rt1b=i.c1.r2x*i.nx+i.c1.r2y*i.ny,i.k1x=i.b2.kinvelx-i.c1.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c1.r1y*i.b1.kinangvel),i.k1y=i.b2.kinvely+i.c1.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c1.r1x*i.b1.kinangvel)),i.hc2)if(i.rn2a=i.ny*i.c2.r1x-i.nx*i.c2.r1y,i.rt2a=i.c2.r1x*i.nx+i.c2.r1y*i.ny,i.rn2b=i.ny*i.c2.r2x-i.nx*i.c2.r2y,i.rt2b=i.c2.r2x*i.nx+i.c2.r2y*i.ny,i.k2x=i.b2.kinvelx-i.c2.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c2.r1y*i.b1.kinangvel),i.k2y=i.b2.kinvely+i.c2.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c2.r1x*i.b1.kinangvel),i.kMassa=r+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=r+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=r+i.b1.sinertia*i.rn2a*i.rn2a+i.b2.sinertia*i.rn2b*i.rn2b,i.kMassa*i.kMassa+2*i.kMassb*i.kMassb+i.kMassc*i.kMassc<I._nape.Config.illConditionedThreshold*(i.kMassa*i.kMassc-i.kMassb*i.kMassb)){i.Ka=i.kMassa,i.Kb=i.kMassb,i.Kc=i.kMassc;let y=i.kMassa*i.kMassc-i.kMassb*i.kMassb;if(y!=y)i.kMassa=i.kMassb=i.kMassc=0;else if(y==0){let z=0;i.kMassa!=0?i.kMassa=1/i.kMassa:(i.kMassa=0,z|=1),i.kMassc!=0?i.kMassc=1/i.kMassc:(i.kMassc=0,z|=2),i.kMassb=0;}else {y=1/y;let z=i.kMassc*y;i.kMassc=i.kMassa*y,i.kMassa=z,i.kMassb*=-y;}}else {if(i.hc2=false,i.oc2.dist<i.oc1.dist){let y=i.c1;i.c1=i.c2,i.c2=y;}i.oc2.active=false,i.contacts.modified=true;}i.surfacex=i.b2.svelx,i.surfacey=i.b2.svely;let m=1;i.surfacex+=i.b1.svelx*m,i.surfacey+=i.b1.svely*m,i.surfacex=-i.surfacex,i.surfacey=-i.surfacey,i.rMass=i.b1.sinertia+i.b2.sinertia,i.rMass!=0&&(i.rMass=1/i.rMass),o&&(e.active=false);}else {let i=e.fluidarb;i.pre_dt==-1&&(i.pre_dt=t);let l=t/i.pre_dt;i.pre_dt=t,i.r1x=i.centroidx-i.b1.posx,i.r1y=i.centroidy-i.b1.posy,i.r2x=i.centroidx-i.b2.posx,i.r2y=i.centroidy-i.b2.posy;let r=0,o=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(r=i.ws1.fluidProperties.gravityx,o=i.ws1.fluidProperties.gravityy):(r=this.gravityx,o=this.gravityy);let a=0,p=0;i.ws2.fluidEnabled&&i.ws2.fluidProperties.wrap_gravity!=null?(a=i.ws2.fluidProperties.gravityx,p=i.ws2.fluidProperties.gravityy):(a=this.gravityx,p=this.gravityy);let c=0,h=0;if(i.ws1.fluidEnabled&&i.ws2.fluidEnabled){let m=i.overlap*i.ws1.fluidProperties.density,_=i.overlap*i.ws2.fluidProperties.density;if(m>_){let y=m+_;c-=r*y,h-=o*y;}else if(m<_){let y=m+_;c+=a*y,h+=p*y;}else {let y=0,z=0;y=r+a,z=o+p;let b=.5;if(y*=b,z*=b,i.ws1.worldCOMx*y+i.ws1.worldCOMy*z>i.ws2.worldCOMx*y+i.ws2.worldCOMy*z){let w=m+_;c-=y*w,h-=z*w;}else {let w=m+_;c+=y*w,h+=z*w;}}}else if(i.ws1.fluidEnabled){let _=i.overlap*i.ws1.fluidProperties.density;c-=r*_,h-=o*_;}else if(i.ws2.fluidEnabled){let _=i.overlap*i.ws2.fluidProperties.density;c+=a*_,h+=p*_;}let u=t;if(c*=u,h*=u,i.buoyx=c,i.buoyy=h,i.b1.type==2){let m=i.b1.imass;i.b1.velx-=c*m,i.b1.vely-=h*m,i.b1.angvel-=(h*i.r1x-c*i.r1y)*i.b1.iinertia;}if(i.b2.type==2){let m=i.b2.imass;i.b2.velx+=c*m,i.b2.vely+=h*m,i.b2.angvel+=(h*i.r2x-c*i.r2y)*i.b2.iinertia;}if((!i.ws1.fluidEnabled||i.ws1.fluidProperties.viscosity==0)&&(!i.ws2.fluidEnabled||i.ws2.fluidProperties.viscosity==0))i.nodrag=true,i.dampx=0,i.dampy=0,i.adamp=0;else {i.nodrag=false;let m=0;if(i.ws1.fluidEnabled&&(i.ws2.validate_angDrag(),m+=i.ws1.fluidProperties.viscosity*i.ws2.angDrag*i.overlap/i.ws2.area),i.ws2.fluidEnabled&&(i.ws1.validate_angDrag(),m+=i.ws2.fluidProperties.viscosity*i.ws1.angDrag*i.overlap/i.ws1.area),m!=0){let b=i.b1.sinertia+i.b2.sinertia;b!=0?i.wMass=1/b:i.wMass=0,m*=4e-4;let w=2*Math.PI*m;i.agamma=1/(t*w*(2+w*t));let Z=1/(1+i.agamma);t*w*w*i.agamma;i.agamma*=Z,i.wMass*=Z;}else i.wMass=0,i.agamma=0;let _=i.b2.velx+i.b2.kinvelx-i.r2y*(i.b2.angvel+i.b2.kinangvel)-(i.b1.velx+i.b1.kinvelx-i.r1y*(i.b2.angvel+i.b2.kinangvel)),y=i.b2.vely+i.b2.kinvely+i.r2x*(i.b2.angvel+i.b2.kinangvel)-(i.b1.vely+i.b1.kinvely+i.r1x*(i.b1.angvel+i.b1.kinangvel));if(!(_*_+y*y<I._nape.Config.epsilon*I._nape.Config.epsilon)){let b=_*_+y*y,Z=1/Math.sqrt(b);_*=Z,y*=Z,i.nx=_,i.ny=y;}let z=0;if(i.ws1.fluidEnabled){let b=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)z-=b*i.ws2.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else {let w=i.ws2.polygon,Z=0,d=0,f=w.edges.head;for(;f!=null;){let g=f.elt;Z+=g.length;let P=b*g.length*(g.gnormx*i.nx+g.gnormy*i.ny);P>0&&(P*=-I._nape.Config.fluidVacuumDrag,P=P),d-=P*.5*I._nape.Config.fluidLinearDrag,f=f.next;}z+=d/Z;}}if(i.ws2.fluidEnabled){let b=-i.ws2.fluidProperties.viscosity*i.overlap/i.ws1.area;if(i.ws1.type==0)z-=b*i.ws1.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else {let w=i.ws1.polygon,Z=0,d=0,f=w.edges.head;for(;f!=null;){let g=f.elt;Z+=g.length;let P=b*g.length*(g.gnormx*i.nx+g.gnormy*i.ny);P>0&&(P*=-I._nape.Config.fluidVacuumDrag,P=P),d-=P*.5*I._nape.Config.fluidLinearDrag,f=f.next;}z+=d/Z;}}if(z!=0){let b=i.b1.smass+i.b2.smass,w=0,Z=0,d=0;if(w=b,Z=0,d=b,i.b1.sinertia!=0){let E=i.r1x*i.b1.sinertia,M=i.r1y*i.b1.sinertia;w+=M*i.r1y,Z+=-M*i.r1x,d+=E*i.r1x;}if(i.b2.sinertia!=0){let E=i.r2x*i.b2.sinertia,M=i.r2y*i.b2.sinertia;w+=M*i.r2y,Z+=-M*i.r2x,d+=E*i.r2x;}let f=w*d-Z*Z;if(f!=f)d=0,Z=d,w=Z;else if(f==0){let E=0;w!=0?w=1/w:(w=0,E|=1),d!=0?d=1/d:(d=0,E|=2),Z=0;}else {f=1/f;let E=d*f;d=w*f,w=E,Z*=-f;}i.vMassa=w,i.vMassb=Z,i.vMassc=d;let P=2*Math.PI*z;i.lgamma=1/(t*P*(2+P*t));let v=1/(1+i.lgamma);t*P*P*i.lgamma,i.lgamma*=v;let N=v;i.vMassa*=N,i.vMassb*=N,i.vMassc*=N;}else i.vMassa=0,i.vMassb=0,i.vMassc=0,i.lgamma=0;}let x=l;i.dampx*=x,i.dampy*=x,i.adamp*=l;}}else if(e.colarb!=null){let i=e.colarb,l=true,r=null,o=null,a=i.innards.next;i.hc2=false;let p=i.contacts.next;for(;p!=null;){let c=p;if(c.stamp+I._nape.Config.arbiterExpirationDelay<i.stamp){let x=i.contacts,m,_;r==null?(m=x.next,_=m.next,x.next=_,x.next==null&&(x.pushmod=true)):(m=r.next,_=m.next,r.next=_,_==null&&(x.pushmod=true)),m._inuse=false,x.modified=true,x.length--,x.pushmod=true,p=_;let y=i.innards,z,b;o==null?(z=y.next,b=z.next,y.next=b,y.next==null&&(y.pushmod=true)):(z=o.next,b=z.next,o.next=b,b==null&&(y.pushmod=true)),z._inuse=false,y.modified=true,y.length--,y.pushmod=true,a=b;let w=c;w.arbiter=null,w.next=we.zpp_pool,we.zpp_pool=w;continue}let h=c.inner,u=c.active;c.active=c.stamp==i.stamp,c.active&&(l?(l=false,i.c1=h,i.oc1=c):(i.hc2=true,i.c2=h,i.oc2=c)),u!=c.active&&(i.contacts.modified=true),r=p,o=a,a=a.next,p=p.next;}if(i.hc2){if(i.hpc2=true,i.oc1.posOnly){let c=i.c1;i.c1=i.c2,i.c2=c;let h=i.oc1;i.oc1=i.oc2,i.oc2=h,i.hc2=false;}else i.oc2.posOnly&&(i.hc2=false);i.oc1.posOnly&&(l=true);}else i.hpc2=false;l&&(e.active=false);}return s!=e.active&&(e.b1.arbiters.modified=true,e.b2.arbiters.modified=true,this.c_arbiters_true.modified=this.c_arbiters_false.modified=true,this.s_arbiters.modified=this.f_arbiters.modified=true),false}_prestepArbiterList(e,t,n){let s=null,i=e.head;for(;i!=null;){let l=i.elt;if(this.presteparb(l,n)){let r,o;s==null?(r=e.head,o=r.next,e.head=o,e.head==null&&(e.pushmod=true)):(r=s.next,o=r.next,s.next=o,o==null&&(e.pushmod=true)),r.elt=null,r.next=t.zpp_pool,t.zpp_pool=r,e.modified=true,e.length--,e.pushmod=true,i=o;continue}s=i,i=i.next;}}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let o=n.elt;if(o.preStep(e)){n=this.live_constraints.erase(t),o.broken(),this.constraintCbBreak(o),o.removeOnBreak?(o.component.sleeping=true,this.midstep=false,o.compound!=null?o.compound.wrap_constraints.remove(o.outer):this.wrap_constraints.remove(o.outer),this.midstep=true):o.active=false,o.clearcache();continue}t=n,n=n.next;}let s=null,i=this.c_arbiters_true,l=i.head,r=this.c_arbiters_false!=null;for(r&&l==null&&(r=false,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);l!=null;){let o=l.elt;if(this.presteparb(o,e)){let a,p;s==null?(a=i.head,p=a.next,i.head=p,i.head==null&&(i.pushmod=true)):(a=s.next,p=a.next,s.next=p,p==null&&(i.pushmod=true));let c=a;c.elt=null,c.next=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=c,i.modified=true,i.length--,i.pushmod=true,l=p,r&&l==null&&(r=false,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);continue}s=l,l=l.next,r&&l==null&&(r=false,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);}this._prestepArbiterList(this.f_arbiters,I._zpp.util.ZNPNode_ZPP_FluidArbiter,e),this._prestepArbiterList(this.s_arbiters,I._zpp.util.ZNPNode_ZPP_SensorArbiter,e);}warmStart(){let e=this.f_arbiters.head;for(;e!=null;){let i=e.elt;if(i.active&&(i.immState&1)!=0){let l=i.b1.imass;i.b1.velx-=i.dampx*l,i.b1.vely-=i.dampy*l;let r=i.b2.imass;i.b2.velx+=i.dampx*r,i.b2.vely+=i.dampy*r,i.b1.angvel-=i.b1.iinertia*(i.dampy*i.r1x-i.dampx*i.r1y),i.b2.angvel+=i.b2.iinertia*(i.dampy*i.r2x-i.dampx*i.r2y),i.b1.angvel-=i.adamp*i.b1.iinertia,i.b2.angvel+=i.adamp*i.b2.iinertia;}e=e.next;}let t=this.c_arbiters_false.head,n=true;for(t==null&&(t=this.c_arbiters_true.head,n=false);t!=null;){let i=t.elt;if(i.active&&(i.immState&1)!=0){let l=i.nx*i.c1.jnAcc-i.ny*i.c1.jtAcc,r=i.ny*i.c1.jnAcc+i.nx*i.c1.jtAcc,o=i.b1.imass;i.b1.velx-=l*o,i.b1.vely-=r*o,i.b1.angvel-=i.b1.iinertia*(r*i.c1.r1x-l*i.c1.r1y);let a=i.b2.imass;if(i.b2.velx+=l*a,i.b2.vely+=r*a,i.b2.angvel+=i.b2.iinertia*(r*i.c1.r2x-l*i.c1.r2y),i.hc2){let p=i.nx*i.c2.jnAcc-i.ny*i.c2.jtAcc,c=i.ny*i.c2.jnAcc+i.nx*i.c2.jtAcc,h=i.b1.imass;i.b1.velx-=p*h,i.b1.vely-=c*h,i.b1.angvel-=i.b1.iinertia*(c*i.c2.r1x-p*i.c2.r1y);let u=i.b2.imass;i.b2.velx+=p*u,i.b2.vely+=c*u,i.b2.angvel+=i.b2.iinertia*(c*i.c2.r2x-p*i.c2.r2y);}i.b2.angvel+=i.jrAcc*i.b2.iinertia,i.b1.angvel-=i.jrAcc*i.b1.iinertia;}t=t.next,n&&t==null&&(t=this.c_arbiters_true.head,n=false);}let s=this.live_constraints.head;for(;s!=null;)s.elt.warmStart(),s=s.next;}iterateVel(e){let t=0,n=e;for(;t<n;){t++;let i=this.f_arbiters.head;for(;i!=null;){let p=i.elt;if(p.active&&(p.immState&1)!=0&&!p.nodrag){let c=p.b1.angvel+p.b1.kinangvel,h=p.b2.angvel+p.b2.kinangvel,u=p.b1.velx+p.b1.kinvelx-p.r1y*c-(p.b2.velx+p.b2.kinvelx-p.r2y*h),x=p.b1.vely+p.b1.kinvely+p.r1x*c-(p.b2.vely+p.b2.kinvely+p.r2x*h),m=p.vMassa*u+p.vMassb*x;x=p.vMassb*u+p.vMassc*x,u=m;let _=p.lgamma;u-=p.dampx*_,x-=p.dampy*_;let y=1;p.dampx+=u*y,p.dampy+=x*y;let z=p.b1.imass;p.b1.velx-=u*z,p.b1.vely-=x*z;let b=p.b2.imass;p.b2.velx+=u*b,p.b2.vely+=x*b,p.b1.angvel-=p.b1.iinertia*(x*p.r1x-u*p.r1y),p.b2.angvel+=p.b2.iinertia*(x*p.r2x-u*p.r2y);let w=(c-h)*p.wMass-p.adamp*p.agamma;p.adamp+=w,p.b1.angvel-=w*p.b1.iinertia,p.b2.angvel+=w*p.b2.iinertia;}i=i.next;}let l=null,r=this.live_constraints.head;for(;r!=null;){let p=r.elt;if(p.applyImpulseVel()){r=this.live_constraints.erase(l),p.broken(),this.constraintCbBreak(p),p.removeOnBreak?(p.component.sleeping=true,this.midstep=false,p.compound!=null?p.compound.wrap_constraints.remove(p.outer):this.wrap_constraints.remove(p.outer),this.midstep=true):p.active=false,p.clearcache();continue}l=r,r=r.next;}let o=this.c_arbiters_false.head,a=true;for(o==null&&(o=this.c_arbiters_true.head,a=false);o!=null;){let p=o.elt;if(p.active&&(p.immState&1)!=0){let c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),h=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),u=(h*p.nx-c*p.ny+p.surfacex)*p.c1.tMass,x=p.c1.friction*p.c1.jnAcc,m=p.c1.jtAcc,_=m-u;_>x?_=x:_<-x&&(_=-x),u=_-m,p.c1.jtAcc=_;let y=-p.ny*u,z=p.nx*u;if(p.b2.velx+=y*p.b2.imass,p.b2.vely+=z*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=z*p.b1.imass,p.b2.angvel+=p.rt1b*u*p.b2.iinertia,p.b1.angvel-=p.rt1a*u*p.b1.iinertia,p.hc2){let b=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),w=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);u=(w*p.nx-b*p.ny+p.surfacex)*p.c2.tMass,x=p.c2.friction*p.c2.jnAcc,m=p.c2.jtAcc,_=m-u,_>x?_=x:_<-x&&(_=-x),u=_-m,p.c2.jtAcc=_,y=-p.ny*u,z=p.nx*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=z*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=z*p.b1.imass,p.b2.angvel+=p.rt2b*u*p.b2.iinertia,p.b1.angvel-=p.rt2a*u*p.b1.iinertia,c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),h=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),b=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),w=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,d=p.c2.jnAcc,f=c*p.nx+h*p.ny+p.surfacey+p.c1.bounce-(p.Ka*Z+p.Kb*d),g=b*p.nx+w*p.ny+p.surfacey+p.c2.bounce-(p.Kb*Z+p.Kc*d),P=-(p.kMassa*f+p.kMassb*g),v=-(p.kMassb*f+p.kMassc*g);P>=0&&v>=0?(f=P-Z,g=v-d,p.c1.jnAcc=P,p.c2.jnAcc=v):(P=-p.c1.nMass*f,P>=0&&p.Kb*P+g>=0?(f=P-Z,g=-d,p.c1.jnAcc=P,p.c2.jnAcc=0):(v=-p.c2.nMass*g,v>=0&&p.Kb*v+f>=0?(f=-Z,g=v-d,p.c1.jnAcc=0,p.c2.jnAcc=v):f>=0&&g>=0?(f=-Z,g=-d,p.c1.jnAcc=p.c2.jnAcc=0):(f=0,g=0))),u=f+g,y=p.nx*u,z=p.ny*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=z*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=z*p.b1.imass,p.b2.angvel+=(p.rn1b*f+p.rn2b*g)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*f+p.rn2a*g)*p.b1.iinertia;}else p.radius!=0&&(u=(p.b2.angvel-p.b1.angvel)*p.rMass,x=p.rfric*p.c1.jnAcc,m=p.jrAcc,p.jrAcc-=u,p.jrAcc>x?p.jrAcc=x:p.jrAcc<-x&&(p.jrAcc=-x),u=p.jrAcc-m,p.b2.angvel+=u*p.b2.iinertia,p.b1.angvel-=u*p.b1.iinertia),c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),h=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),u=(p.c1.bounce+(p.nx*c+p.ny*h)+p.surfacey)*p.c1.nMass,m=p.c1.jnAcc,_=m-u,_<0&&(_=0),u=_-m,p.c1.jnAcc=_,y=p.nx*u,z=p.ny*u,p.b2.velx+=y*p.b2.imass,p.b2.vely+=z*p.b2.imass,p.b1.velx-=y*p.b1.imass,p.b1.vely-=z*p.b1.imass,p.b2.angvel+=p.rn1b*u*p.b2.iinertia,p.b1.angvel-=p.rn1a*u*p.b1.iinertia;}o=o.next,a&&o==null&&(o=this.c_arbiters_true.head,a=false);}}}iteratePos(e){let t=0,n=e;for(;t<n;){t++;let i=null,l=this.live_constraints.head;for(;l!=null;){let a=l.elt;if(!a.__velocity&&a.stiff&&a.applyImpulsePos()){l=this.live_constraints.erase(i),a.broken(),this.constraintCbBreak(a),a.removeOnBreak?(a.component.sleeping=true,this.midstep=false,a.compound!=null?a.compound.wrap_constraints.remove(a.outer):this.wrap_constraints.remove(a.outer),this.midstep=true):a.active=false,a.clearcache();continue}i=l,l=l.next;}let r=this.c_arbiters_false.head,o=true;for(r==null&&(r=this.c_arbiters_true.head,o=false);r!=null;){let a=r.elt;if(a.active&&(a.immState&1)!=0)if(a.ptype==2){let p=a.c1,c=0,h=0;c=a.b2.axisy*p.lr2x-a.b2.axisx*p.lr2y,h=p.lr2x*a.b2.axisx+p.lr2y*a.b2.axisy;let u=1;c+=a.b2.posx*u,h+=a.b2.posy*u;let x=0,m=0;x=a.b1.axisy*p.lr1x-a.b1.axisx*p.lr1y,m=p.lr1x*a.b1.axisx+p.lr1y*a.b1.axisy;let _=1;x+=a.b1.posx*_,m+=a.b1.posy*_;let y=0,z=0;y=c-x,z=h-m;let b=Math.sqrt(y*y+z*z),w=a.radius-I._nape.Config.collisionSlop,Z=b-w;if(y*a.nx+z*a.ny<0&&(y=-y,z=-z,Z-=a.radius),Z<0)if(b<I._nape.Config.epsilon)a.b1.smass!=0?a.b1.posx+=I._nape.Config.epsilon*10:a.b2.posx+=I._nape.Config.epsilon*10;else {let d=1/b;y*=d,z*=d;let f=.5*(x+c),g=.5*(m+h),P=b-w;x=f-a.b1.posx,m=g-a.b1.posy,c=f-a.b2.posx,h=g-a.b2.posy;let v=z*x-y*m,N=z*c-y*h,E=a.b2.smass+N*N*a.b2.sinertia+a.b1.smass+v*v*a.b1.sinertia;if(E!=0){let M=-a.biasCoef*P/E,k=0,C=0,S=M;k=y*S,C=z*S;let O=a.b1.imass;a.b1.posx-=k*O,a.b1.posy-=C*O;let F=a.b1,T=-v*a.b1.iinertia*M;if(F.rot+=T,T*T>1e-4)F.axisx=Math.sin(F.rot),F.axisy=Math.cos(F.rot);else {let B=T*T,A=1-.5*B,Y=1-B*B/8,$=(A*F.axisx+T*F.axisy)*Y;F.axisy=(A*F.axisy-T*F.axisx)*Y,F.axisx=$;}let R=a.b2.imass;a.b2.posx+=k*R,a.b2.posy+=C*R;let W=a.b2,G=N*a.b2.iinertia*M;if(W.rot+=G,G*G>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else {let B=G*G,A=1-.5*B,Y=1-B*B/8,$=(A*W.axisx+G*W.axisy)*Y;W.axisy=(A*W.axisy-G*W.axisx)*Y,W.axisx=$;}}}}else {let p=0,c=0,h,u=0,x=0,m=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,h=a.lproj+(p*a.b1.posx+c*a.b1.posy),u=a.b2.axisy*a.c1.lr1x-a.b2.axisx*a.c1.lr1y,x=a.c1.lr1x*a.b2.axisx+a.c1.lr1y*a.b2.axisy;let b=1;if(u+=a.b2.posx*b,x+=a.b2.posy*b,a.hpc2){m=a.b2.axisy*a.c2.lr1x-a.b2.axisx*a.c2.lr1y,_=a.c2.lr1x*a.b2.axisx+a.c2.lr1y*a.b2.axisy;let w=1;m+=a.b2.posx*w,_+=a.b2.posy*w;}}else {p=a.b2.axisy*a.lnormx-a.b2.axisx*a.lnormy,c=a.lnormx*a.b2.axisx+a.lnormy*a.b2.axisy,h=a.lproj+(p*a.b2.posx+c*a.b2.posy),u=a.b1.axisy*a.c1.lr1x-a.b1.axisx*a.c1.lr1y,x=a.c1.lr1x*a.b1.axisx+a.c1.lr1y*a.b1.axisy;let b=1;if(u+=a.b1.posx*b,x+=a.b1.posy*b,a.hpc2){m=a.b1.axisy*a.c2.lr1x-a.b1.axisx*a.c2.lr1y,_=a.c2.lr1x*a.b1.axisx+a.c2.lr1y*a.b1.axisy;let w=1;m+=a.b1.posx*w,_+=a.b1.posy*w;}}let y=u*p+x*c-h-a.radius;y+=I._nape.Config.collisionSlop;let z=0;if(a.hpc2&&(z=m*p+_*c-h-a.radius,z+=I._nape.Config.collisionSlop),y<0||z<0){a.rev&&(p=-p,c=-c);let b=0,w=0;b=u-a.b1.posx,w=x-a.b1.posy;let Z=0,d=0;Z=u-a.b2.posx,d=x-a.b2.posy;let f=0,g=0,P=0,v=0;if(a.hpc2){f=m-a.b1.posx,g=_-a.b1.posy,P=m-a.b2.posx,v=_-a.b2.posy;let N=c*b-p*w,E=c*Z-p*d,M=c*f-p*g,k=c*P-p*v,C=a.b1.smass+a.b2.smass;a.kMassa=C+a.b1.sinertia*N*N+a.b2.sinertia*E*E,a.kMassb=C+a.b1.sinertia*N*M+a.b2.sinertia*E*k,a.kMassc=C+a.b1.sinertia*M*M+a.b2.sinertia*k*k;let S=0,O=0,F=0;S=a.kMassa,O=a.kMassb,F=a.kMassc;let T=y*a.biasCoef,R=z*a.biasCoef;for(;;){let W=0,G=0;W=T,G=R,W=-W,G=-G;let B=a.kMassa*a.kMassc-a.kMassb*a.kMassb;if(B!=B)G=0,W=G;else if(B==0)a.kMassa!=0?W/=a.kMassa:W=0,a.kMassc!=0?G/=a.kMassc:G=0;else {B=1/B;let $=B*(a.kMassc*W-a.kMassb*G);G=B*(a.kMassa*G-a.kMassb*W),W=$;}if(W>=0&&G>=0){let $=(W+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let H=a.b1,X=-a.b1.iinertia*(N*W+M*G);if(H.rot+=X,X*X>1e-4)H.axisx=Math.sin(H.rot),H.axisy=Math.cos(H.rot);else {let L=X*X,V=1-.5*L,U=1-L*L/8,Q=(V*H.axisx+X*H.axisy)*U;H.axisy=(V*H.axisy-X*H.axisx)*U,H.axisx=Q;}let ee=(W+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let q=a.b2,D=a.b2.iinertia*(E*W+k*G);if(q.rot+=D,D*D>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else {let L=D*D,V=1-.5*L,U=1-L*L/8,Q=(V*q.axisx+D*q.axisy)*U;q.axisy=(V*q.axisy-D*q.axisx)*U,q.axisx=Q;}break}W=-T/S,G=0;let A=O*W+R;if(W>=0&&A>=0){let $=(W+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let H=a.b1,X=-a.b1.iinertia*(N*W+M*G);if(H.rot+=X,X*X>1e-4)H.axisx=Math.sin(H.rot),H.axisy=Math.cos(H.rot);else {let L=X*X,V=1-.5*L,U=1-L*L/8,Q=(V*H.axisx+X*H.axisy)*U;H.axisy=(V*H.axisy-X*H.axisx)*U,H.axisx=Q;}let ee=(W+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let q=a.b2,D=a.b2.iinertia*(E*W+k*G);if(q.rot+=D,D*D>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else {let L=D*D,V=1-.5*L,U=1-L*L/8,Q=(V*q.axisx+D*q.axisy)*U;q.axisy=(V*q.axisy-D*q.axisx)*U,q.axisx=Q;}break}W=0,G=-R/F;let Y=O*G+T;if(G>=0&&Y>=0){let $=(W+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let H=a.b1,X=-a.b1.iinertia*(N*W+M*G);if(H.rot+=X,X*X>1e-4)H.axisx=Math.sin(H.rot),H.axisy=Math.cos(H.rot);else {let L=X*X,V=1-.5*L,U=1-L*L/8,Q=(V*H.axisx+X*H.axisy)*U;H.axisy=(V*H.axisy-X*H.axisx)*U,H.axisx=Q;}let ee=(W+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let q=a.b2,D=a.b2.iinertia*(E*W+k*G);if(q.rot+=D,D*D>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else {let L=D*D,V=1-.5*L,U=1-L*L/8,Q=(V*q.axisx+D*q.axisy)*U;q.axisy=(V*q.axisy-D*q.axisx)*U,q.axisx=Q;}break}break}}else {let N=c*b-p*w,E=c*Z-p*d,M=a.b2.smass+E*E*a.b2.sinertia+a.b1.smass+N*N*a.b1.sinertia;if(M!=0){let k=-a.biasCoef*y/M,C=0,S=0,O=k;C=p*O,S=c*O;let F=a.b1.imass;a.b1.posx-=C*F,a.b1.posy-=S*F;let T=a.b1,R=-N*a.b1.iinertia*k;if(T.rot+=R,R*R>1e-4)T.axisx=Math.sin(T.rot),T.axisy=Math.cos(T.rot);else {let A=R*R,Y=1-.5*A,$=1-A*A/8,H=(Y*T.axisx+R*T.axisy)*$;T.axisy=(Y*T.axisy-R*T.axisx)*$,T.axisx=H;}let W=a.b2.imass;a.b2.posx+=C*W,a.b2.posy+=S*W;let G=a.b2,B=E*a.b2.iinertia*k;if(G.rot+=B,B*B>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else {let A=B*B,Y=1-.5*A,$=1-A*A/8,H=(Y*G.axisx+B*G.axisy)*$;G.axisy=(Y*G.axisy-B*G.axisx)*$,G.axisx=H;}}}}}r=r.next,o&&r==null&&(r=this.c_arbiters_true.head,o=false);}}}group_ignore(e,t){let n=e;for(;n!=null&&n.group==null;)n.ishape!=null?n=n.ishape.body:n.icompound!=null?n=n.icompound.compound:n=n.ibody.compound;let s=n==null?null:n.group;if(s==null)return false;{let i=t;for(;i!=null&&i.group==null;)i.ishape!=null?i=i.ishape.body:i.icompound!=null?i=i.icompound.compound:i=i.ibody.compound;let l=i==null?null:i.group;if(l==null)return false;{let r=false;for(;s!=null&&l!=null;){if(s==l){r=s.ignore;break}s.depth<l.depth?l=l.group:s=s.group;}return r}}}interactionType(e,t,n,s){let i;i=false;let l=n.constraints.head;for(;l!=null;){let o=l.elt;if(o.ignore&&o.pair_exists(n.id,s.id)){i=true;break}l=l.next;}let r;if(i)r=false;else {let o=e;for(;o!=null&&o.group==null;)o.ishape!=null?o=o.ishape.body:o.icompound!=null?o=o.icompound.compound:o=o.ibody.compound;let a=o==null?null:o.group,p;if(a==null)p=false;else {let c=t;for(;c!=null&&c.group==null;)c.ishape!=null?c=c.ishape.body:c.icompound!=null?c=c.icompound.compound:c=c.ibody.compound;let h=c==null?null:c.group;if(h==null)p=false;else {let u=false;for(;a!=null&&h!=null;){if(a==h){u=a.ignore;break}a.depth<h.depth?h=h.group:a=a.group;}p=u;}}r=!p;}if(r){let o;if(e.sensorEnabled||t.sensorEnabled){let a=e.filter,p=t.filter;o=(a.sensorMask&p.sensorGroup)!=0&&(p.sensorMask&a.sensorGroup)!=0;}else o=false;if(o)return 2;{let a;if(e.fluidEnabled||t.fluidEnabled){let p=e.filter,c=t.filter;a=(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0;}else a=false;if(a&&!(n.imass==0&&s.imass==0&&n.iinertia==0&&s.iinertia==0))return 0;{let p=e.filter,c=t.filter;return (p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!(n.imass==0&&s.imass==0&&n.iinertia==0&&s.iinertia==0)?1:-1}}}else return -1}narrowPhase(e,t,n,s,i){let l=null,r=e.body,o=t.body,a;a=false;let p=r.constraints.head;for(;p!=null;){let u=p.elt;if(u.ignore&&u.pair_exists(r.id,o.id)){a=true;break}p=p.next;}let c,h;if(a)h=false;else {let u=e;for(;u!=null&&u.group==null;)u.ishape!=null?u=u.ishape.body:u.icompound!=null?u=u.icompound.compound:u=u.ibody.compound;let x=u==null?null:u.group,m;if(x==null)m=false;else {let _=t;for(;_!=null&&_.group==null;)_.ishape!=null?_=_.ishape.body:_.icompound!=null?_=_.icompound.compound:_=_.ibody.compound;let y=_==null?null:_.group;if(y==null)m=false;else {let z=false;for(;x!=null&&y!=null;){if(x==y){z=x.ignore;break}x.depth<y.depth?y=y.group:x=x.group;}m=z;}}h=!m;}if(h){let u;if(e.sensorEnabled||t.sensorEnabled){let x=e.filter,m=t.filter;u=(x.sensorMask&m.sensorGroup)!=0&&(m.sensorMask&x.sensorGroup)!=0;}else u=false;if(u)c=2;else {let x;if(e.fluidEnabled||t.fluidEnabled){let m=e.filter,_=t.filter;x=(m.fluidMask&_.fluidGroup)!=0&&(_.fluidMask&m.fluidGroup)!=0;}else x=false;if(x&&!(r.imass==0&&o.imass==0&&r.iinertia==0&&o.iinertia==0))c=0;else {let m=e.filter,_=t.filter;c=(m.collisionMask&_.collisionGroup)!=0&&(_.collisionMask&m.collisionGroup)!=0&&!(r.imass==0&&o.imass==0&&r.iinertia==0&&o.iinertia==0)?1:-1;}}}else c=-1;if(c!=-1){let u,x;e.type>t.type?(u=t,x=e):e.type==t.type?e.id<t.id?(u=e,x=t):(x=e,u=t):(u=e,x=t);let m=u==t;if(c==0){let _;if(s==null){let Z=null,f=(r.arbiters.length<o.arbiters.length?r:o).arbiters.head;for(;f!=null;){let g=f.elt;if(g.id==u.id&&g.di==x.id){Z=g;break}f=f.next;}_=Z;}else _=s;let y=_==null,z,b=false;if(y)Pt.zpp_pool==null?z=new Pt:(z=Pt.zpp_pool,Pt.zpp_pool=z.next,z.next=null);else if(_.fluidarb==null){_.cleared=true;{let d=_.b1.arbiters,f=null,g=d.head;for(;g!=null;){if(g.elt==_){let v,N;f==null?(v=d.head,N=v.next,d.head=N,d.head==null&&(d.pushmod=true)):(v=f.next,N=v.next,f.next=N,N==null&&(d.pushmod=true));let E=v;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,d.modified=true,d.length--,d.pushmod=true;break}f=g,g=g.next;}}{let d=_.b2.arbiters,f=null,g=d.head;for(;g!=null;){if(g.elt==_){let v,N;f==null?(v=d.head,N=v.next,d.head=N,d.head==null&&(d.pushmod=true)):(v=f.next,N=v.next,f.next=N,N==null&&(d.pushmod=true));let E=v;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,d.modified=true,d.length--,d.pushmod=true;break}f=g,g=g.next;}}_.pair!=null&&(_.pair.arb=null,_.pair=null),_.active=false,this.f_arbiters.modified=true,Pt.zpp_pool==null?z=new Pt:(z=Pt.zpp_pool,Pt.zpp_pool=z.next,z.next=null),z.intchange=true,y=true,b=true;}else z=_.fluidarb;let w=4;if(y||z.stamp!=this.stamp||i)if(z.stamp=this.stamp,ge.flowCollide(u,x,z)){if(y){let Z=x.id;z.b1=e.body,z.ws1=e,z.b2=t.body,z.ws2=t,z.id=u.id,z.di=Z;let d=z.b1.arbiters,f;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?f=new I._zpp.util.ZNPNode_ZPP_Arbiter:(f=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f.next,f.next=null),f.elt=z;let g=f;g.next=d.head,d.head=g,d.modified=true,d.length++;let P=z.b2.arbiters,v;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?v=new I._zpp.util.ZNPNode_ZPP_Arbiter:(v=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=v.next,v.next=null),v.elt=z;let N=v;N.next=P.head,P.head=N,P.modified=true,P.length++,z.active=true,z.present=0,z.cleared=false,z.sleeping=false,z.fresh=false,z.presentable=false,z.nx=0,z.ny=1,z.dampx=0,z.dampy=0,z.adamp=0;let E=this.f_arbiters,M;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?M=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(M=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=M.next,M.next=null),M.elt=z;let k=M;k.next=E.head,E.head=k,E.modified=true,E.length++,z.fresh=!b;}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&i;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let Z=false,d=z.ws1.id>z.ws2.id?z.ws2:z.ws1,f=z.ws1.id>z.ws2.id?z.ws1:z.ws2,g=this.mrca1;for(;g.head!=null;){let M=g.head;g.head=M.next;let k=M;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k,g.head==null&&(g.pushmod=true),g.modified=true,g.length--;}g.pushmod=true;let P=this.mrca2;for(;P.head!=null;){let M=P.head;P.head=M.next;let k=M;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k,P.head==null&&(P.pushmod=true),P.modified=true,P.length--;}if(P.pushmod=true,d.cbSet!=null){let M=this.mrca1,k;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?k=new I._zpp.util.ZNPNode_ZPP_Interactor:(k=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k.next,k.next=null),k.elt=d;let C=k;C.next=M.head,M.head=C,M.modified=true,M.length++;}if(d.body.cbSet!=null){let M=this.mrca1,k=d.body,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=k;let S=C;S.next=M.head,M.head=S,M.modified=true,M.length++;}if(f.cbSet!=null){let M=this.mrca2,k;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?k=new I._zpp.util.ZNPNode_ZPP_Interactor:(k=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k.next,k.next=null),k.elt=f;let C=k;C.next=M.head,M.head=C,M.modified=true,M.length++;}if(f.body.cbSet!=null){let M=this.mrca2,k=f.body,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=k;let S=C;S.next=M.head,M.head=S,M.modified=true,M.length++;}let v=d.body.compound,N=f.body.compound;for(;v!=N;){let M=v==null?0:v.depth,k=N==null?0:N.depth;if(M<k){if(N.cbSet!=null){let C=this.mrca2,S;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new I._zpp.util.ZNPNode_ZPP_Interactor:(S=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=N;let O=S;O.next=C.head,C.head=O,C.modified=true,C.length++;}N=N.compound;}else {if(v.cbSet!=null){let C=this.mrca1,S;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new I._zpp.util.ZNPNode_ZPP_Interactor:(S=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=v;let O=S;O.next=C.head,C.head=O,C.modified=true,C.length++;}v=v.compound;}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,k=this.mrca2.head;for(;k!=null;){let C=k.elt,S=M.cbSet,O=C.cbSet;S.manager;let T=null,W=(S.cbpairs.length<O.cbpairs.length?S.cbpairs:O.cbpairs).head;for(;W!=null;){let D=W.elt;if(D.a==S&&D.b==O||D.a==O&&D.b==S){T=D;break}W=W.next;}if(T==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=true,dt.setlt(S,O)?(D.a=S,D.b=O):(D.a=O,D.b=S),T=D,S.cbpairs.add(T),O!=S&&O.cbpairs.add(T);}if(T.zip_listeners&&(T.zip_listeners=false,T.__validate()),T.listeners.head==null){k=k.next;continue}let G=null,B=null,A=this.prelisteners;for(;A.head!=null;){let D=A.head;A.head=D.next;let L=D;L.elt=null,L.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=L,A.head==null&&(A.pushmod=true),A.modified=true,A.length--;}A.pushmod=true;let Y=null;S.manager;let H=null,ee=(S.cbpairs.length<O.cbpairs.length?S.cbpairs:O.cbpairs).head;for(;ee!=null;){let D=ee.elt;if(D.a==S&&D.b==O||D.a==O&&D.b==S){H=D;break}ee=ee.next;}if(H==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=true,dt.setlt(S,O)?(D.a=S,D.b=O):(D.a=O,D.b=S),H=D,S.cbpairs.add(H),O!=S&&O.cbpairs.add(H);}H.zip_listeners&&(H.zip_listeners=false,H.__validate());let q=H.listeners.head;for(;q!=null;){let D=q.elt;if(D.event==5&&(D.itype&w)!=0){let L=this.prelisteners,V;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?V=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(V=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=V.next,V.next=null),V.elt=D;let U=V;Y==null?(U.next=L.head,L.head=U):(U.next=Y.next,Y.next=U),L.pushmod=L.modified=true,L.length++,Y=U,Z=Z||!D.pure;}q=q.next;}if(this.prelisteners.head==null){k=k.next;continue}if(G=I._zpp.phys.ZPP_Interactor.get(M,C),G==null&&(B=Yt.get(M,C),this.add_callbackset(B)),G==null||(G.FLUIDstamp!=this.stamp||i)&&(G.FLUIDstate&4)==0){if(B!=null&&(G=B),G!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(G.COLLISIONstamp=this.stamp,G.SENSORstamp=this.stamp,G.FLUIDstamp=this.stamp):G.FLUIDstamp=this.stamp,U=U.next;}z.mutable=true,z.wrap_position!=null&&(z.wrap_position.zpp_inner._immutable=false);let D=z.active;z.active=true;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=G;let V=this.prelisteners.head;for(;V!=null;){let U=V.elt;this.precb.zpp_inner.listener=U;let Q=this.precb.zpp_inner,K=G.int1,ie=G.int2,oe,se=U.options1,ne=K.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=U.options2,he=ie.cbTypes;oe=le.nonemptyintersection(he,le.includes)&&!le.nonemptyintersection(he,le.excludes);}else oe=false;oe?(Q.int1=K,Q.int2=ie):(Q.int1=ie,Q.int2=K),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let re=U.handlerp(this.precb);if(re!=null){let le;J.PreFlag_ACCEPT==null&&(J.internal=true,J.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,J.internal=false),re==J.PreFlag_ACCEPT?le=5:(J.PreFlag_ACCEPT_ONCE==null&&(J.internal=true,J.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,J.internal=false),re==J.PreFlag_ACCEPT_ONCE?le=1:(J.PreFlag_IGNORE==null&&(J.internal=true,J.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,J.internal=false),le=re==J.PreFlag_IGNORE?6:2)),z.immState=le;}V=V.next;}if(z.mutable=false,z.wrap_position!=null&&(z.wrap_position.zpp_inner._immutable=true),z.active=D,G!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7&&(G.COLLISIONstate=z.immState,G.SENSORstate=z.immState),G.FLUIDstate=z.immState,U=U.next;}}else G==null?(z.immState&4)==0&&(z.immState=1):z.immState=G.FLUIDstate;k=k.next;}E=E.next;}if(Z&&(z.immState&4)==0){if(z.b1.type==2){let M=z.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=true),M.component.sleeping&&this.really_wake(M,false));}if(z.b1.type==2){let M=z.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=true),M.component.sleeping&&this.really_wake(M,false));}}}if((z.immState&1)!=0){if(z.b1.type==2&&z.b1.component.sleeping){let Z=z.b1;Z.world||(Z.component.waket=this.stamp+(this.midstep?0:1),Z.type==3&&(Z.kinematicDelaySleep=true),Z.component.sleeping&&this.really_wake(Z,false));}if(z.b2.type==2&&z.b2.component.sleeping){let Z=z.b2;Z.world||(Z.component.waket=this.stamp+(this.midstep?0:1),Z.type==3&&(Z.kinematicDelaySleep=true),Z.component.sleeping&&this.really_wake(Z,false));}}if(z.sleeping){z.sleeping=false;let Z=this.f_arbiters,d;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(d=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=d.next,d.next=null),d.elt=z;let f=d;f.next=Z.head,Z.head=f,Z.modified=true,Z.length++;}l=z;}else if(y){let Z=z;Z.next=Pt.zpp_pool,Pt.zpp_pool=Z,l=null;}else l=z;else l=z;}else if(c==1){let _=n?this.c_arbiters_true:this.c_arbiters_false,y;if(s==null){let d=null,g=(r.arbiters.length<o.arbiters.length?r:o).arbiters.head;for(;g!=null;){let P=g.elt;if(P.id==u.id&&P.di==x.id){d=P;break}g=g.next;}y=d;}else y=s;let z=y==null,b,w=false;if(z)ut.zpp_pool==null?b=new ut:(b=ut.zpp_pool,ut.zpp_pool=b.next,b.next=null),b.stat=n;else if(y.colarb==null){y.cleared=true;{let f=y.b1.arbiters,g=null,P=f.head;for(;P!=null;){if(P.elt==y){let N,E;g==null?(N=f.head,E=N.next,f.head=E,f.head==null&&(f.pushmod=true)):(N=g.next,E=N.next,g.next=E,E==null&&(f.pushmod=true));let M=N;M.elt=null,M.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,f.modified=true,f.length--,f.pushmod=true;break}g=P,P=P.next;}}{let f=y.b2.arbiters,g=null,P=f.head;for(;P!=null;){if(P.elt==y){let N,E;g==null?(N=f.head,E=N.next,f.head=E,f.head==null&&(f.pushmod=true)):(N=g.next,E=N.next,g.next=E,E==null&&(f.pushmod=true));let M=N;M.elt=null,M.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=M,f.modified=true,f.length--,f.pushmod=true;break}g=P,P=P.next;}}y.pair!=null&&(y.pair.arb=null,y.pair=null),y.active=false,this.f_arbiters.modified=true,ut.zpp_pool==null?b=new ut:(b=ut.zpp_pool,ut.zpp_pool=b.next,b.next=null),b.intchange=true,b.stat=n,z=true,w=true;}else b=y.colarb,m=u!=b.s1,b.stat!=n&&(b.stat=n,b.sleeping||((n?this.c_arbiters_false:this.c_arbiters_true).remove(b),_.add(b)));let Z=1;if(z||b.stamp!=this.stamp||i)if(b.stamp=this.stamp,ge.contactCollide(u,x,b,m)){if(z){let d=x.id;b.b1=e.body,b.ws1=e,b.b2=t.body,b.ws2=t,b.id=u.id,b.di=d;let f=b.b1.arbiters,g;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?g=new I._zpp.util.ZNPNode_ZPP_Arbiter:(g=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=g.next,g.next=null),g.elt=b;let P=g;P.next=f.head,f.head=P,f.modified=true,f.length++;let v=b.b2.arbiters,N;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?N=new I._zpp.util.ZNPNode_ZPP_Arbiter:(N=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=N.next,N.next=null),N.elt=b;let E=N;E.next=v.head,v.head=E,v.modified=true,v.length++,b.active=true,b.present=0,b.cleared=false,b.sleeping=false,b.fresh=false,b.presentable=false,b.s1=e,b.s2=t,b.userdef_restitution||(b.s1.material.elasticity<=-1/0||b.s2.material.elasticity<=-1/0?b.restitution=0:b.s1.material.elasticity>=1/0||b.s2.material.elasticity>=1/0?b.restitution=1:b.restitution=(b.s1.material.elasticity+b.s2.material.elasticity)/2,b.restitution<0&&(b.restitution=0),b.restitution>1&&(b.restitution=1)),b.userdef_dyn_fric||(b.dyn_fric=Math.sqrt(b.s1.material.dynamicFriction*b.s2.material.dynamicFriction)),b.userdef_stat_fric||(b.stat_fric=Math.sqrt(b.s1.material.staticFriction*b.s2.material.staticFriction)),b.userdef_rfric||(b.rfric=Math.sqrt(b.s1.material.rollingFriction*b.s2.material.rollingFriction));let M;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?M=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(M=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=M.next,M.next=null),M.elt=b;let k=M;k.next=_.head,_.head=k,_.modified=true,_.length++,b.fresh=!w;}else b.fresh=b.up_stamp<this.stamp-1||b.endGenerated==this.stamp&&i;if(b.up_stamp=b.stamp,b.fresh||(b.immState&4)==0){b.immState=1;let d=false,f=b.ws1.id>b.ws2.id?b.ws2:b.ws1,g=b.ws1.id>b.ws2.id?b.ws1:b.ws2,P=this.mrca1;for(;P.head!=null;){let k=P.head;P.head=k.next;let C=k;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,P.head==null&&(P.pushmod=true),P.modified=true,P.length--;}P.pushmod=true;let v=this.mrca2;for(;v.head!=null;){let k=v.head;v.head=k.next;let C=k;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C,v.head==null&&(v.pushmod=true),v.modified=true,v.length--;}if(v.pushmod=true,f.cbSet!=null){let k=this.mrca1,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=f;let S=C;S.next=k.head,k.head=S,k.modified=true,k.length++;}if(f.body.cbSet!=null){let k=this.mrca1,C=f.body,S;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new I._zpp.util.ZNPNode_ZPP_Interactor:(S=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=C;let O=S;O.next=k.head,k.head=O,k.modified=true,k.length++;}if(g.cbSet!=null){let k=this.mrca2,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=g;let S=C;S.next=k.head,k.head=S,k.modified=true,k.length++;}if(g.body.cbSet!=null){let k=this.mrca2,C=g.body,S;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new I._zpp.util.ZNPNode_ZPP_Interactor:(S=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=C;let O=S;O.next=k.head,k.head=O,k.modified=true,k.length++;}let N=f.body.compound,E=g.body.compound;for(;N!=E;){let k=N==null?0:N.depth,C=E==null?0:E.depth;if(k<C){if(E.cbSet!=null){let S=this.mrca2,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=E;let F=O;F.next=S.head,S.head=F,S.modified=true,S.length++;}E=E.compound;}else {if(N.cbSet!=null){let S=this.mrca1,O;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?O=new I._zpp.util.ZNPNode_ZPP_Interactor:(O=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=O.next,O.next=null),O.elt=N;let F=O;F.next=S.head,S.head=F,S.modified=true,S.length++;}N=N.compound;}}let M=this.mrca1.head;for(;M!=null;){let k=M.elt,C=this.mrca2.head;for(;C!=null;){let S=C.elt,O=k.cbSet,F=S.cbSet;O.manager;let R=null,G=(O.cbpairs.length<F.cbpairs.length?O.cbpairs:F.cbpairs).head;for(;G!=null;){let L=G.elt;if(L.a==O&&L.b==F||L.a==F&&L.b==O){R=L;break}G=G.next;}if(R==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=true,dt.setlt(O,F)?(L.a=O,L.b=F):(L.a=F,L.b=O),R=L,O.cbpairs.add(R),F!=O&&F.cbpairs.add(R);}if(R.zip_listeners&&(R.zip_listeners=false,R.__validate()),R.listeners.head==null){C=C.next;continue}let B=null,A=null,Y=this.prelisteners;for(;Y.head!=null;){let L=Y.head;Y.head=L.next;let V=L;V.elt=null,V.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=V,Y.head==null&&(Y.pushmod=true),Y.modified=true,Y.length--;}Y.pushmod=true;let $=null;O.manager;let X=null,q=(O.cbpairs.length<F.cbpairs.length?O.cbpairs:F.cbpairs).head;for(;q!=null;){let L=q.elt;if(L.a==O&&L.b==F||L.a==F&&L.b==O){X=L;break}q=q.next;}if(X==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=true,dt.setlt(O,F)?(L.a=O,L.b=F):(L.a=F,L.b=O),X=L,O.cbpairs.add(X),F!=O&&F.cbpairs.add(X);}X.zip_listeners&&(X.zip_listeners=false,X.__validate());let D=X.listeners.head;for(;D!=null;){let L=D.elt;if(L.event==5&&(L.itype&Z)!=0){let V=this.prelisteners,U;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?U=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(U=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=U.next,U.next=null),U.elt=L;let Q=U;$==null?(Q.next=V.head,V.head=Q):(Q.next=$.next,$.next=Q),V.pushmod=V.modified=true,V.length++,$=Q,d=d||!L.pure;}D=D.next;}if(this.prelisteners.head==null){C=C.next;continue}if(B=I._zpp.phys.ZPP_Interactor.get(k,S),B==null&&(A=Yt.get(k,S),this.add_callbackset(A)),B==null||(B.COLLISIONstamp!=this.stamp||i)&&(B.COLLISIONstate&4)==0){if(A!=null&&(B=A),B!=null){let ne=this.prelisteners.head;for(;ne!=null;)ne.elt.itype==7?(B.COLLISIONstamp=this.stamp,B.SENSORstamp=this.stamp,B.FLUIDstamp=this.stamp):B.COLLISIONstamp=this.stamp,ne=ne.next;}b.mutable=true,b.wrap_normal!=null&&(b.wrap_normal.zpp_inner._immutable=false),b.wrap_contacts!=null&&(b.wrap_contacts.zpp_inner.immutable=false);let L=b.active;b.active=true;let U=true,Q=null,K=null,ie=b.innards.next;b.hc2=false;let oe=b.contacts.next;for(;oe!=null;){let ne=oe;if(ne.stamp+I._nape.Config.arbiterExpirationDelay<b.stamp){let he=b.contacts,pe,ce;Q==null?(pe=he.next,ce=pe.next,he.next=ce,he.next==null&&(he.pushmod=true)):(pe=Q.next,ce=pe.next,Q.next=ce,ce==null&&(he.pushmod=true)),pe._inuse=false,he.modified=true,he.length--,he.pushmod=true,oe=ce;let te=b.innards,ue,de;K==null?(ue=te.next,de=ue.next,te.next=de,te.next==null&&(te.pushmod=true)):(ue=K.next,de=ue.next,K.next=de,de==null&&(te.pushmod=true)),ue._inuse=false,te.modified=true,te.length--,te.pushmod=true,ie=de;let me=ne;me.arbiter=null,me.next=we.zpp_pool,we.zpp_pool=me;continue}let re=ne.inner,le=ne.active;ne.active=ne.stamp==b.stamp,ne.active&&(U?(U=false,b.c1=re,b.oc1=ne):(b.hc2=true,b.c2=re,b.oc2=ne)),le!=ne.active&&(b.contacts.modified=true),Q=oe,K=ie,ie=ie.next,oe=oe.next;}if(b.hc2){if(b.hpc2=true,b.oc1.posOnly){let ne=b.c1;b.c1=b.c2,b.c2=ne;let re=b.oc1;b.oc1=b.oc2,b.oc2=re,b.hc2=false;}else b.oc2.posOnly&&(b.hc2=false);b.oc1.posOnly&&(U=true);}else b.hpc2=false;this.precb.zpp_inner.pre_arbiter=b,this.precb.zpp_inner.set=B;let se=this.prelisteners.head;for(;se!=null;){let ne=se.elt;this.precb.zpp_inner.listener=ne;let re=this.precb.zpp_inner,le=B.int1,he=B.int2,pe,ce=ne.options1,te=le.cbTypes;if(ce.nonemptyintersection(te,ce.includes)&&!ce.nonemptyintersection(te,ce.excludes)){let de=ne.options2,me=he.cbTypes;pe=de.nonemptyintersection(me,de.includes)&&!de.nonemptyintersection(me,de.excludes);}else pe=false;pe?(re.int1=le,re.int2=he):(re.int1=he,re.int2=le),this.precb.zpp_inner.pre_swapped=k!=this.precb.zpp_inner.int1;let ue=ne.handlerp(this.precb);if(ue!=null){let de;J.PreFlag_ACCEPT==null&&(J.internal=true,J.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,J.internal=false),ue==J.PreFlag_ACCEPT?de=5:(J.PreFlag_ACCEPT_ONCE==null&&(J.internal=true,J.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,J.internal=false),ue==J.PreFlag_ACCEPT_ONCE?de=1:(J.PreFlag_IGNORE==null&&(J.internal=true,J.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,J.internal=false),de=ue==J.PreFlag_IGNORE?6:2)),b.immState=de;}se=se.next;}if(b.mutable=false,b.wrap_normal!=null&&(b.wrap_normal.zpp_inner._immutable=true),b.wrap_contacts!=null&&(b.wrap_contacts.zpp_inner.immutable=true),b.active=L,B!=null){let ne=this.prelisteners.head;for(;ne!=null;)ne.elt.itype==7?(B.COLLISIONstate=b.immState,B.SENSORstate=b.immState,B.FLUIDstate=b.immState):B.COLLISIONstate=b.immState,ne=ne.next;}}else B==null?(b.immState&4)==0&&(b.immState=1):b.immState=B.COLLISIONstate;C=C.next;}M=M.next;}if(d&&(b.immState&4)==0){if(b.b1.type==2){let k=b.b1;k.world||(k.component.waket=this.stamp+(this.midstep?0:1),k.type==3&&(k.kinematicDelaySleep=true),k.component.sleeping&&this.really_wake(k,false));}if(b.b1.type==2){let k=b.b2;k.world||(k.component.waket=this.stamp+(this.midstep?0:1),k.type==3&&(k.kinematicDelaySleep=true),k.component.sleeping&&this.really_wake(k,false));}}}if((b.immState&1)!=0){if(b.b1.type==2&&b.b1.component.sleeping){let d=b.b1;d.world||(d.component.waket=this.stamp+(this.midstep?0:1),d.type==3&&(d.kinematicDelaySleep=true),d.component.sleeping&&this.really_wake(d,false));}if(b.b2.type==2&&b.b2.component.sleeping){let d=b.b2;d.world||(d.component.waket=this.stamp+(this.midstep?0:1),d.type==3&&(d.kinematicDelaySleep=true),d.component.sleeping&&this.really_wake(d,false));}}if(b.sleeping){b.sleeping=false;let d;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(d=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=d.next,d.next=null),d.elt=b;let f=d;f.next=_.head,_.head=f,_.modified=true,_.length++;}l=b;}else if(z){let d=b;d.userdef_dyn_fric=false,d.userdef_stat_fric=false,d.userdef_restitution=false,d.userdef_rfric=false,d.__ref_edge1=d.__ref_edge2=null,d.next=ut.zpp_pool,ut.zpp_pool=d,l=null;}else l=b;else l=b;}else {let _;if(s==null){let Z=null,f=(r.arbiters.length<o.arbiters.length?r:o).arbiters.head;for(;f!=null;){let g=f.elt;if(g.id==u.id&&g.di==x.id){Z=g;break}f=f.next;}_=Z;}else _=s;let y=_==null,z,b=false;if(y)Ot.zpp_pool==null?z=new Ot:(z=Ot.zpp_pool,Ot.zpp_pool=z.next,z.next=null);else if(_.sensorarb==null){_.cleared=true;{let d=_.b1.arbiters,f=null,g=d.head;for(;g!=null;){if(g.elt==_){let v,N;f==null?(v=d.head,N=v.next,d.head=N,d.head==null&&(d.pushmod=true)):(v=f.next,N=v.next,f.next=N,N==null&&(d.pushmod=true));let E=v;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,d.modified=true,d.length--,d.pushmod=true;break}f=g,g=g.next;}}{let d=_.b2.arbiters,f=null,g=d.head;for(;g!=null;){if(g.elt==_){let v,N;f==null?(v=d.head,N=v.next,d.head=N,d.head==null&&(d.pushmod=true)):(v=f.next,N=v.next,f.next=N,N==null&&(d.pushmod=true));let E=v;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=E,d.modified=true,d.length--,d.pushmod=true;break}f=g,g=g.next;}}_.pair!=null&&(_.pair.arb=null,_.pair=null),_.active=false,this.f_arbiters.modified=true,Ot.zpp_pool==null?z=new Ot:(z=Ot.zpp_pool,Ot.zpp_pool=z.next,z.next=null),z.intchange=true,y=true,b=true;}else z=_.sensorarb;let w=2;if(y||z.stamp!=this.stamp||i)if(z.stamp=this.stamp,ge.testCollide(u,x)){if(y){let Z=x.id;z.b1=e.body,z.ws1=e,z.b2=t.body,z.ws2=t,z.id=u.id,z.di=Z;let d=z.b1.arbiters,f;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?f=new I._zpp.util.ZNPNode_ZPP_Arbiter:(f=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=f.next,f.next=null),f.elt=z;let g=f;g.next=d.head,d.head=g,d.modified=true,d.length++;let P=z.b2.arbiters,v;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?v=new I._zpp.util.ZNPNode_ZPP_Arbiter:(v=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=v.next,v.next=null),v.elt=z;let N=v;N.next=P.head,P.head=N,P.modified=true,P.length++,z.active=true,z.present=0,z.cleared=false,z.sleeping=false,z.fresh=false,z.presentable=false;let E=this.s_arbiters,M;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?M=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(M=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=M.next,M.next=null),M.elt=z;let k=M;k.next=E.head,E.head=k,E.modified=true,E.length++,z.fresh=!b;}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&i;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let Z=false,d=z.ws1.id>z.ws2.id?z.ws2:z.ws1,f=z.ws1.id>z.ws2.id?z.ws1:z.ws2,g=this.mrca1;for(;g.head!=null;){let M=g.head;g.head=M.next;let k=M;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k,g.head==null&&(g.pushmod=true),g.modified=true,g.length--;}g.pushmod=true;let P=this.mrca2;for(;P.head!=null;){let M=P.head;P.head=M.next;let k=M;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k,P.head==null&&(P.pushmod=true),P.modified=true,P.length--;}if(P.pushmod=true,d.cbSet!=null){let M=this.mrca1,k;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?k=new I._zpp.util.ZNPNode_ZPP_Interactor:(k=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k.next,k.next=null),k.elt=d;let C=k;C.next=M.head,M.head=C,M.modified=true,M.length++;}if(d.body.cbSet!=null){let M=this.mrca1,k=d.body,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=k;let S=C;S.next=M.head,M.head=S,M.modified=true,M.length++;}if(f.cbSet!=null){let M=this.mrca2,k;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?k=new I._zpp.util.ZNPNode_ZPP_Interactor:(k=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=k.next,k.next=null),k.elt=f;let C=k;C.next=M.head,M.head=C,M.modified=true,M.length++;}if(f.body.cbSet!=null){let M=this.mrca2,k=f.body,C;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Interactor:(C=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=C.next,C.next=null),C.elt=k;let S=C;S.next=M.head,M.head=S,M.modified=true,M.length++;}let v=d.body.compound,N=f.body.compound;for(;v!=N;){let M=v==null?0:v.depth,k=N==null?0:N.depth;if(M<k){if(N.cbSet!=null){let C=this.mrca2,S;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new I._zpp.util.ZNPNode_ZPP_Interactor:(S=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=N;let O=S;O.next=C.head,C.head=O,C.modified=true,C.length++;}N=N.compound;}else {if(v.cbSet!=null){let C=this.mrca1,S;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?S=new I._zpp.util.ZNPNode_ZPP_Interactor:(S=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=S.next,S.next=null),S.elt=v;let O=S;O.next=C.head,C.head=O,C.modified=true,C.length++;}v=v.compound;}}let E=this.mrca1.head;for(;E!=null;){let M=E.elt,k=this.mrca2.head;for(;k!=null;){let C=k.elt,S=M.cbSet,O=C.cbSet;S.manager;let T=null,W=(S.cbpairs.length<O.cbpairs.length?S.cbpairs:O.cbpairs).head;for(;W!=null;){let D=W.elt;if(D.a==S&&D.b==O||D.a==O&&D.b==S){T=D;break}W=W.next;}if(T==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=true,dt.setlt(S,O)?(D.a=S,D.b=O):(D.a=O,D.b=S),T=D,S.cbpairs.add(T),O!=S&&O.cbpairs.add(T);}if(T.zip_listeners&&(T.zip_listeners=false,T.__validate()),T.listeners.head==null){k=k.next;continue}let G=null,B=null,A=this.prelisteners;for(;A.head!=null;){let D=A.head;A.head=D.next;let L=D;L.elt=null,L.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=L,A.head==null&&(A.pushmod=true),A.modified=true,A.length--;}A.pushmod=true;let Y=null;S.manager;let H=null,ee=(S.cbpairs.length<O.cbpairs.length?S.cbpairs:O.cbpairs).head;for(;ee!=null;){let D=ee.elt;if(D.a==S&&D.b==O||D.a==O&&D.b==S){H=D;break}ee=ee.next;}if(H==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=true,dt.setlt(S,O)?(D.a=S,D.b=O):(D.a=O,D.b=S),H=D,S.cbpairs.add(H),O!=S&&O.cbpairs.add(H);}H.zip_listeners&&(H.zip_listeners=false,H.__validate());let q=H.listeners.head;for(;q!=null;){let D=q.elt;if(D.event==5&&(D.itype&w)!=0){let L=this.prelisteners,V;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?V=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(V=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=V.next,V.next=null),V.elt=D;let U=V;Y==null?(U.next=L.head,L.head=U):(U.next=Y.next,Y.next=U),L.pushmod=L.modified=true,L.length++,Y=U,Z=Z||!D.pure;}q=q.next;}if(this.prelisteners.head==null){k=k.next;continue}if(G=I._zpp.phys.ZPP_Interactor.get(M,C),G==null&&(B=Yt.get(M,C),this.add_callbackset(B)),G==null||(G.SENSORstamp!=this.stamp||i)&&(G.SENSORstate&4)==0){if(B!=null&&(G=B),G!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(G.COLLISIONstamp=this.stamp,G.SENSORstamp=this.stamp,G.FLUIDstamp=this.stamp):G.SENSORstamp=this.stamp,U=U.next;}let D=z.active;z.active=true;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=G;let V=this.prelisteners.head;for(;V!=null;){let U=V.elt;this.precb.zpp_inner.listener=U;let Q=this.precb.zpp_inner,K=G.int1,ie=G.int2,oe,se=U.options1,ne=K.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=U.options2,he=ie.cbTypes;oe=le.nonemptyintersection(he,le.includes)&&!le.nonemptyintersection(he,le.excludes);}else oe=false;oe?(Q.int1=K,Q.int2=ie):(Q.int1=ie,Q.int2=K),this.precb.zpp_inner.pre_swapped=M!=this.precb.zpp_inner.int1;let re=U.handlerp(this.precb);if(re!=null){let le;J.PreFlag_ACCEPT==null&&(J.internal=true,J.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,J.internal=false),re==J.PreFlag_ACCEPT?le=5:(J.PreFlag_ACCEPT_ONCE==null&&(J.internal=true,J.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,J.internal=false),re==J.PreFlag_ACCEPT_ONCE?le=1:(J.PreFlag_IGNORE==null&&(J.internal=true,J.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,J.internal=false),le=re==J.PreFlag_IGNORE?6:2)),z.immState=le;}V=V.next;}if(z.active=D,G!=null){let U=this.prelisteners.head;for(;U!=null;)U.elt.itype==7?(G.COLLISIONstate=z.immState,G.SENSORstate=z.immState,G.FLUIDstate=z.immState):G.SENSORstate=z.immState,U=U.next;}}else G==null?(z.immState&4)==0&&(z.immState=1):z.immState=G.SENSORstate;k=k.next;}E=E.next;}if(Z&&(z.immState&4)==0){if(z.b1.type!=1){let M=z.b1;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=true),M.component.sleeping&&this.really_wake(M,false));}if(z.b2.type!=1){let M=z.b2;M.world||(M.component.waket=this.stamp+(this.midstep?0:1),M.type==3&&(M.kinematicDelaySleep=true),M.component.sleeping&&this.really_wake(M,false));}}}if(z.sleeping){z.sleeping=false;let Z=this.s_arbiters,d;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(d=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=d.next,d.next=null),d.elt=z;let f=d;f.next=Z.head,Z.head=f,Z.modified=true,Z.length++;}l=z;}else if(y){let Z=z;Z.next=Ot.zpp_pool,Ot.zpp_pool=Z,l=null;}else l=z;else l=z;}}return l}MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let r=n.head;n.head=r.next;let o=r;o.elt=null,o.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,n.head==null&&(n.pushmod=true),n.modified=true,n.length--;}n.pushmod=true;let s=this.mrca2;for(;s.head!=null;){let r=s.head;s.head=r.next;let o=r;o.elt=null,o.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,s.head==null&&(s.pushmod=true),s.modified=true,s.length--;}if(s.pushmod=true,e.cbSet!=null){let r=this.mrca1,o;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_Interactor:(o=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=e;let a=o;a.next=r.head,r.head=a,r.modified=true,r.length++;}if(e.body.cbSet!=null){let r=this.mrca1,o=e.body,a;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=true,r.length++;}if(t.cbSet!=null){let r=this.mrca2,o;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_Interactor:(o=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=t;let a=o;a.next=r.head,r.head=a,r.modified=true,r.length++;}if(t.body.cbSet!=null){let r=this.mrca2,o=t.body,a;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=true,r.length++;}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let r=i==null?0:i.depth,o=l==null?0:l.depth;if(r<o){if(l.cbSet!=null){let a=this.mrca2,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=l;let c=p;c.next=a.head,a.head=c,a.modified=true,a.length++;}l=l.compound;}else {if(i.cbSet!=null){let a=this.mrca1,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=i;let c=p;c.next=a.head,a.head=c,a.modified=true,a.length++;}i=i.compound;}}}inlined_MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let r=n.head;n.head=r.next;let o=r;o.elt=null,o.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,n.head==null&&(n.pushmod=true),n.modified=true,n.length--;}n.pushmod=true;let s=this.mrca2;for(;s.head!=null;){let r=s.head;s.head=r.next;let o=r;o.elt=null,o.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o,s.head==null&&(s.pushmod=true),s.modified=true,s.length--;}if(s.pushmod=true,e.cbSet!=null){let r=this.mrca1,o;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_Interactor:(o=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=e;let a=o;a.next=r.head,r.head=a,r.modified=true,r.length++;}if(e.body.cbSet!=null){let r=this.mrca1,o=e.body,a;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=true,r.length++;}if(t.cbSet!=null){let r=this.mrca2,o;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?o=new I._zpp.util.ZNPNode_ZPP_Interactor:(o=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=o.next,o.next=null),o.elt=t;let a=o;a.next=r.head,r.head=a,r.modified=true,r.length++;}if(t.body.cbSet!=null){let r=this.mrca2,o=t.body,a;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_Interactor:(a=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a.next,a.next=null),a.elt=o;let p=a;p.next=r.head,r.head=p,r.modified=true,r.length++;}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let r=i==null?0:i.depth,o=l==null?0:l.depth;if(r<o){if(l.cbSet!=null){let a=this.mrca2,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=l;let c=p;c.next=a.head,a.head=c,a.modified=true,a.length++;}l=l.compound;}else {if(i.cbSet!=null){let a=this.mrca1,p;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?p=new I._zpp.util.ZNPNode_ZPP_Interactor:(p=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=p.next,p.next=null),p.elt=i;let c=p;c.next=a.head,a.head=c,a.modified=true,a.length++;}i=i.compound;}}}};I._zpp=null,I._nape=null;var ri=I;var Ln=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}};Ln.zpp_pool=null;var sn=class sn extends Bn{constructor(t){super();this.failed=null;this.list=null;this.space=t,this.is_sweep=true,this.sweep=this;}__insert(t){let n;Ln.zpp_pool==null?n=new Ln:(n=Ln.zpp_pool,Ln.zpp_pool=n.next,n.next=null),t.sweep=n,n.shape=t,n.aabb=t.aabb,n.next=this.list,this.list!=null&&(this.list.prev=n),this.list=n;}__remove(t){let n=t.sweep;n.prev==null?this.list=n.next:n.prev.next=n.next,n.next!=null&&(n.next.prev=n.prev),t.sweep=null;let s=n;s.prev=null,s.shape=null,s.aabb=null,s.next=Ln.zpp_pool,Ln.zpp_pool=s;}__sync(t){if(!this.space.continuous&&t.zip_aabb&&t.body!=null)if(t.zip_aabb=false,t.type==0){let n=t.circle;if(n.zip_worldCOM&&n.body!=null){if(n.zip_worldCOM=false,n.zip_localCOM){if(n.zip_localCOM=false,n.type==1){let r=n.polygon;if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(r.lverts.next.next==null)r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;else if(r.lverts.next.next.next==null){r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;let o=1;r.localCOMx+=r.lverts.next.next.x*o,r.localCOMy+=r.lverts.next.next.y*o;let a=.5;r.localCOMx*=a,r.localCOMy*=a;}else {r.localCOMx=0,r.localCOMy=0;let o=0,a=r.lverts.next,p=a;a=a.next;let c=a;for(a=a.next;a!=null;){let y=a;o+=c.x*(y.y-p.y);let z=y.y*c.x-y.x*c.y;r.localCOMx+=(c.x+y.x)*z,r.localCOMy+=(c.y+y.y)*z,p=c,c=y,a=a.next;}a=r.lverts.next;let h=a;o+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;r.localCOMx+=(c.x+h.x)*u,r.localCOMy+=(c.y+h.y)*u,p=c,c=h,a=a.next;let x=a;o+=c.x*(x.y-p.y);let m=x.y*c.x-x.x*c.y;r.localCOMx+=(c.x+x.x)*m,r.localCOMy+=(c.y+x.y)*m,o=1/(3*o);let _=o;r.localCOMx*=_,r.localCOMy*=_;}}n.wrap_localCOM!=null&&(n.wrap_localCOM.zpp_inner.x=n.localCOMx,n.wrap_localCOM.zpp_inner.y=n.localCOMy);}let l=n.body;l.zip_axis&&(l.zip_axis=false,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot)),n.worldCOMx=n.body.posx+(n.body.axisy*n.localCOMx-n.body.axisx*n.localCOMy),n.worldCOMy=n.body.posy+(n.localCOMx*n.body.axisx+n.localCOMy*n.body.axisy);}let s=n.radius,i=n.radius;n.aabb.minx=n.worldCOMx-s,n.aabb.miny=n.worldCOMy-i,n.aabb.maxx=n.worldCOMx+s,n.aabb.maxy=n.worldCOMy+i;}else {let n=t.polygon;if(n.zip_gverts&&n.body!=null){n.zip_gverts=false,n.validate_lverts();let l=n.body;l.zip_axis&&(l.zip_axis=false,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot));let r=n.lverts.next,o=n.gverts.next;for(;o!=null;){let a=o,p=r;r=r.next,a.x=n.body.posx+(n.body.axisy*p.x-n.body.axisx*p.y),a.y=n.body.posy+(p.x*n.body.axisx+p.y*n.body.axisy),o=o.next;}}if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let s=n.gverts.next;n.aabb.minx=s.x,n.aabb.miny=s.y,n.aabb.maxx=s.x,n.aabb.maxy=s.y;let i=n.gverts.next.next;for(;i!=null;){let l=i;l.x<n.aabb.minx&&(n.aabb.minx=l.x),l.x>n.aabb.maxx&&(n.aabb.maxx=l.x),l.y<n.aabb.miny&&(n.aabb.miny=l.y),l.y>n.aabb.maxy&&(n.aabb.maxy=l.y),i=i.next;}}}sync_broadphase(){if(this.space.validation(),this.list!=null){let t=this.list.next;for(;t!=null;){let n=t.next,s=t.prev;if(s!=null&&t.aabb.minx>s.aabb.minx){t=n;continue}for(;s.prev!=null&&s.prev.aabb.minx>t.aabb.minx;)s=s.prev;let i=t.prev;i.next=t.next,t.next!=null&&(t.next.prev=i),s.prev==null?(t.prev=null,this.list=t,t.next=s,s.prev=t):(t.prev=s.prev,s.prev=t,t.prev.next=t,t.next=s),t=n;}}}sync_broadphase_fast(){let t=this.list.next;for(;t!=null;){let n=t.next,s=t.prev;if(s!=null&&t.aabb.minx>s.aabb.minx){t=n;continue}for(;s.prev!=null&&s.prev.aabb.minx>t.aabb.minx;)s=s.prev;let i=t.prev;i.next=t.next,t.next!=null&&(t.next.prev=i),s.prev==null?(t.prev=null,this.list=t,t.next=s,s.prev=t):(t.prev=s.prev,s.prev=t,t.prev.next=t,t.next=s),t=n;}}broadphase(t,n){if(this.list!=null){let s=this.list.next;for(;s!=null;){let l=s.next,r=s.prev;if(r!=null&&s.aabb.minx>r.aabb.minx){s=l;continue}for(;r.prev!=null&&r.prev.aabb.minx>s.aabb.minx;)r=r.prev;let o=s.prev;o.next=s.next,s.next!=null&&(s.next.prev=o),r.prev==null?(s.prev=null,this.list=s,s.next=r,r.prev=s):(s.prev=r.prev,r.prev=s,s.prev.next=s,s.next=r),s=l;}let i=this.list;for(;i!=null;){let l=i.next,r=i.shape,o=r.body,a=i.aabb.maxx;for(;l!=null&&!(l.aabb.minx>a);){let p=l.shape,c=p.body;if(c==o){l=l.next;continue}if(o.type==1&&c.type==1){l=l.next;continue}if(o.component.sleeping&&c.component.sleeping){l=l.next;continue}let h=r.aabb,u=p.aabb;u.miny>h.maxy||h.miny>u.maxy||(n?t.narrowPhase(r,p,o.type!=2||c.type!=2,null,false):t.continuousEvent(r,p,o.type!=2||c.type!=2,null,false)),l=l.next;}i=i.next;}}}clear(){for(;this.list!=null;)this.list.shape.removedFromSpace(),this.__remove(this.list.shape);}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l=ae.get(t,n),r=i??new sn._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.minx>t;)o=o.next;for(;o!=null&&o.aabb.minx<=t;){if(o.aabb.maxx>=t&&o.aabb.miny<=n&&o.aabb.maxy>=n){let p=o.shape,c;if(s!=null){let h=p.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0;}else c=true;c&&(p.type==0?ge.circleContains(p.circle,l)&&r.push(p.outer):ge.polyContains(p.polygon,l)&&r.push(p.outer));}o=o.next;}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,r}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l=ae.get(t,n),r=i??new sn._nape.phys.BodyList,o=this.list;for(;o!=null&&o.aabb.minx>t;)o=o.next;for(;o!=null&&o.aabb.minx<=t;){if(o.aabb.maxx>=t&&o.aabb.miny<=n&&o.aabb.maxy>=n){let p=o.shape,c=p.body.outer;if(!r.has(c)){let h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else h=true;h&&(p.type==0?ge.circleContains(p.circle,l)&&r.push(c):ge.polyContains(p.polygon,l)&&r.push(c));}}o=o.next;}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=ae.zpp_pool,ae.zpp_pool=a,r}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new sn._nape.shape.ShapeList,a=this.list;for(;a!=null&&a.aabb.maxx<r.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=r.maxx;){let p=a.shape,c;if(i!=null){let h=p.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0;}else c=true;if(c)if(n)if(s)ge.containTest(this.aabbShape.zpp_inner,p)&&o.push(p.outer);else {let h=a.aabb;if(h.minx>=r.minx&&h.miny>=r.miny&&h.maxx<=r.maxx&&h.maxy<=r.maxy)o.push(p.outer);else {let u=a.aabb;r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx&&ge.testCollide_safe(p,this.aabbShape.zpp_inner)&&o.push(p.outer);}}else {let h;if(s){let u=a.aabb;h=u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy;}else {let u=a.aabb;h=r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx;}h&&o.push(p.outer);}a=a.next;}return o}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new sn._nape.phys.BodyList;this.failed==null&&(this.failed=new sn._nape.phys.BodyList);let a=this.list;for(;a!=null&&a.aabb.maxx<r.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=r.maxx;){let p=a.shape,c=p.body.outer,h=a.aabb;if(r.miny<=h.maxy&&h.miny<=r.maxy&&r.minx<=h.maxx&&h.minx<=r.maxx){let u;if(i!=null){let x=p.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0;}else u=true;if(u)if(n)if(s){if(!this.failed.has(c)){let x=ge.containTest(this.aabbShape.zpp_inner,p);!o.has(c)&&x?o.push(c):x||(o.remove(c),this.failed.push(c));}}else !o.has(c)&&ge.testCollide_safe(p,this.aabbShape.zpp_inner)&&o.push(c);else if(s){if(!this.failed.has(c)){let x=p.aabb,m=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy;!o.has(c)&&m?o.push(c):m||(o.remove(c),this.failed.push(c));}}else {let x;if(o.has(c))x=false;else {let m=p.aabb;x=m.minx>=r.minx&&m.miny>=r.miny&&m.maxx<=r.maxx&&m.maxy<=r.maxy;}x&&o.push(c);}}a=a.next;}return this.failed.clear(),o}shapesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new sn._nape.shape.ShapeList,p=this.list;for(;p!=null&&p.aabb.maxx<o.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=o.maxx;){let c=p.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx){let h=p.shape,u;if(l!=null){let x=h.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0;}else u=true;u&&(i?ge.containTest(this.circShape.zpp_inner,h)&&a.push(h.outer):ge.testCollide_safe(h,this.circShape.zpp_inner)&&a.push(h.outer));}p=p.next;}return a}bodiesInCircle(t,n,s,i,l,r){this.sync_broadphase(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new sn._nape.phys.BodyList;this.failed==null&&(this.failed=new sn._nape.phys.BodyList);let p=this.list;for(;p!=null&&p.aabb.maxx<o.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=o.maxx;){let c=p.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx){let h=p.shape,u=h.body.outer,x;if(l!=null){let m=h.filter;x=(m.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&m.collisionGroup)!=0;}else x=true;if(x)if(i){if(!this.failed.has(u)){let m=ge.containTest(this.circShape.zpp_inner,h);!a.has(u)&&m?a.push(u):m||(a.remove(u),this.failed.push(u));}}else !a.has(u)&&ge.testCollide_safe(h,this.circShape.zpp_inner)&&a.push(u);}p=p.next;}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new sn._nape.shape.ShapeList,o=this.list;for(;o!=null&&o.aabb.maxx<l.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=l.maxx;){let a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=o.shape,c;if(s!=null){let h=p.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0;}else c=true;c&&(n?ge.containTest(t,p)&&r.push(p.outer):ge.testCollide_safe(p,t)&&r.push(p.outer));}o=o.next;}return r}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,r=i??new sn._nape.phys.BodyList;this.failed==null&&(this.failed=new sn._nape.phys.BodyList);let o=this.list;for(;o!=null&&o.aabb.maxx<l.minx;)o=o.next;for(;o!=null&&o.aabb.minx<=l.maxx;){let a=o.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=o.shape,c=p.body.outer,h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else h=true;if(h)if(n){if(!this.failed.has(c)){let u=ge.containTest(t,p);!r.has(c)&&u?r.push(c):u||(r.remove(c),this.failed.push(c));}}else !r.has(c)&&ge.testCollide_safe(t,p)&&r.push(c);}o=o.next;}return this.failed.clear(),r}rayCast(t,n,s){this.sync_broadphase(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,r=null;if(t.dirx==0){let a=this.list;for(;a!=null&&a.aabb.minx<=i.minx;){let p,c=a.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0;}else p=true;else p=false;if(p){let h=t.aabbsect(a.aabb);if(h>=0&&h<l){let u=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.shape.polygon,n,l);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=u.zpp_inner.toiDistance,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free();}r=u;}}}a=a.next;}}else if(t.dirx<0){let a=this.list,p=null;for(;a!=null&&a.aabb.minx<=i.maxx;)p=a,a=a.next;for(a=p;a!=null;){let c,h=a.aabb;if(i.miny<=h.maxy&&h.miny<=i.maxy&&i.minx<=h.maxx&&h.minx<=i.maxx)if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else c=true;else c=false;if(c){let u=t.aabbsect(a.aabb);if(u>=0&&u<l){let x=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.shape.polygon,n,l);if(x!=null){if(x.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=x.zpp_inner.toiDistance,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free();}r=x;}}}a=a.prev;}}else {let a=this.list;for(;a!=null&&a.aabb.minx<=i.maxx&&a.aabb.minx<t.originx+t.dirx*l;){let p,c=a.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0;}else p=true;else p=false;if(p){let h=t.aabbsect(a.aabb);if(h>=0&&h<l){let u=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.shape.polygon,n,l);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=u.zpp_inner.toiDistance,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free();}r=u;}}}a=a.next;}}let o=i;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=be.zpp_pool,be.zpp_pool=o,r}rayMultiCast(t,n,s,i){this.sync_broadphase(),t.validate_dir();let l=t.rayAABB(),r=i??new sn._nape.geom.RayResultList;if(t.dirx==0){let a=this.list;for(;a!=null&&a.aabb.minx<=l.minx;){let p,c=a.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0;}else p=true;else p=false;p&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,r):t.polysect2(a.shape.polygon,n,r)),a=a.next;}}else if(t.dirx<0){let a=this.list,p=null;for(;a!=null&&a.aabb.minx<=l.maxx;)p=a,a=a.next;for(a=p;a!=null;){let c,h=a.aabb;if(l.miny<=h.maxy&&h.miny<=l.maxy&&l.minx<=h.maxx&&h.minx<=l.maxx)if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else c=true;else c=false;c&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,r):t.polysect2(a.shape.polygon,n,r)),a=a.prev;}}else {let a=this.list;for(;a!=null&&a.aabb.minx<=l.maxx;){let p,c=a.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0;}else p=true;else p=false;p&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,r):t.polysect2(a.shape.polygon,n,r)),a=a.next;}}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=be.zpp_pool,be.zpp_pool=o,r}};sn._zpp=null,sn._nape=null;var ps=sn;function ho(j){j.length=0,this.push(j);}var Rt=class Rt extends Bn{constructor(t,n){super();this.failed=null;this.shapes=[];this.grid=new Map;this.cellPool=[];this.testedPairs=new Set;this.frameCount=0;this.space=t,this.is_sweep=true,this.is_spatial_hash=true,this.sweep=this,n!=null&&n>0?(this.cellSize=n,this.fixedCellSize=true):(this.cellSize=64,this.fixedCellSize=false),this.invCellSize=1/this.cellSize;}cellKey(t,n){return t*73856093^n*19349663}__insert(t){this.shapes.push(t),t.__shIdx=this.shapes.length-1;}__remove(t){let n=t.__shIdx,s=this.shapes.length-1;if(n!==s){let i=this.shapes[s];this.shapes[n]=i,i.__shIdx=n;}this.shapes.pop(),t.__shIdx=void 0;}__sync(t){if(!this.space.continuous&&t.zip_aabb&&t.body!=null)if(t.zip_aabb=false,t.type==0){let n=t.circle;if(n.zip_worldCOM&&n.body!=null){if(n.zip_worldCOM=false,n.zip_localCOM){if(n.zip_localCOM=false,n.type==1){let r=n.polygon;if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(r.lverts.next.next==null)r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;else if(r.lverts.next.next.next==null){r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;let o=1;r.localCOMx+=r.lverts.next.next.x*o,r.localCOMy+=r.lverts.next.next.y*o;let a=.5;r.localCOMx*=a,r.localCOMy*=a;}else {r.localCOMx=0,r.localCOMy=0;let o=0,a=r.lverts.next,p=a;a=a.next;let c=a;for(a=a.next;a!=null;){let y=a;o+=c.x*(y.y-p.y);let z=y.y*c.x-y.x*c.y;r.localCOMx+=(c.x+y.x)*z,r.localCOMy+=(c.y+y.y)*z,p=c,c=y,a=a.next;}a=r.lverts.next;let h=a;o+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;r.localCOMx+=(c.x+h.x)*u,r.localCOMy+=(c.y+h.y)*u,p=c,c=h,a=a.next;let x=a;o+=c.x*(x.y-p.y);let m=x.y*c.x-x.x*c.y;r.localCOMx+=(c.x+x.x)*m,r.localCOMy+=(c.y+x.y)*m,o=1/(3*o);let _=o;r.localCOMx*=_,r.localCOMy*=_;}}n.wrap_localCOM!=null&&(n.wrap_localCOM.zpp_inner.x=n.localCOMx,n.wrap_localCOM.zpp_inner.y=n.localCOMy);}let l=n.body;l.zip_axis&&(l.zip_axis=false,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot)),n.worldCOMx=n.body.posx+(n.body.axisy*n.localCOMx-n.body.axisx*n.localCOMy),n.worldCOMy=n.body.posy+(n.localCOMx*n.body.axisx+n.localCOMy*n.body.axisy);}let s=n.radius,i=n.radius;n.aabb.minx=n.worldCOMx-s,n.aabb.miny=n.worldCOMy-i,n.aabb.maxx=n.worldCOMx+s,n.aabb.maxy=n.worldCOMy+i;}else {let n=t.polygon;if(n.zip_gverts&&n.body!=null){n.zip_gverts=false,n.validate_lverts();let l=n.body;l.zip_axis&&(l.zip_axis=false,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot));let r=n.lverts.next,o=n.gverts.next;for(;o!=null;){let a=o,p=r;r=r.next,a.x=n.body.posx+(n.body.axisy*p.x-n.body.axisx*p.y),a.y=n.body.posy+(p.x*n.body.axisx+p.y*n.body.axisy),o=o.next;}}if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let s=n.gverts.next;n.aabb.minx=s.x,n.aabb.miny=s.y,n.aabb.maxx=s.x,n.aabb.maxy=s.y;let i=n.gverts.next.next;for(;i!=null;){let l=i;l.x<n.aabb.minx&&(n.aabb.minx=l.x),l.x>n.aabb.maxx&&(n.aabb.maxx=l.x),l.y<n.aabb.miny&&(n.aabb.miny=l.y),l.y>n.aabb.maxy&&(n.aabb.maxy=l.y),i=i.next;}}}autoTuneCellSize(){if(this.fixedCellSize||this.shapes.length===0)return;let t=0,n=0,s=0;for(let r=0;r<this.shapes.length;r++){let o=this.shapes[r].aabb;o!=null&&(t+=o.maxx-o.minx,n+=o.maxy-o.miny,s++);}if(s===0)return;let i=(t+n)/(2*s),l=Math.max(i*2,8);this.cellSize=l,this.invCellSize=1/l;}broadphase(t,n){let s=this.shapes.length;if(s===0)return;this.frameCount++,(this.frameCount===1||!this.fixedCellSize&&this.frameCount%Rt.TUNE_INTERVAL===0)&&this.autoTuneCellSize();let i=this.invCellSize,l=this.grid,r=this.cellPool;l.forEach(ho,r),l.clear();let o=this.testedPairs;o.clear();for(let a=0;a<s;a++){let p=this.shapes[a],c=p.aabb,h=p.__shIdx,u=c.minx*i|0,x=c.miny*i|0,m=c.maxx*i|0,_=c.maxy*i|0;if(u===m&&x===_){let z=u*73856093^x*19349663,b=l.get(z);b===void 0&&(b=r.length>0?r.pop():[],l.set(z,b));let w=b.length,Z=p.body,d=Z.type,f=Z.component.sleeping;for(let g=0;g<w;g++){let P=b[g],v=P.body;if(v===Z||d===1&&v.type===1||f&&v.component.sleeping)continue;let N=P.aabb;N.miny>c.maxy||c.miny>N.maxy||N.minx>c.maxx||c.minx>N.maxx||(n?t.narrowPhase(p,P,d!==2||v.type!==2,null,false):t.continuousEvent(p,P,d!==2||v.type!==2,null,false));}b.push(p);}else for(let z=u;z<=m;z++)for(let b=x;b<=_;b++){let w=z*73856093^b*19349663,Z=l.get(w);Z===void 0&&(Z=r.length>0?r.pop():[],l.set(w,Z));let d=Z.length,f=p.body,g=f.type,P=f.component.sleeping;for(let v=0;v<d;v++){let N=Z[v],E=N.body;if(E===f||g===1&&E.type===1||P&&E.component.sleeping)continue;let M=N.__shIdx,k=h<M?h:M,C=h<M?M:h,S=C*C+k;if(o.has(S))continue;o.add(S);let O=N.aabb;O.miny>c.maxy||c.miny>O.maxy||O.minx>c.maxx||c.minx>O.maxx||(n?t.narrowPhase(p,N,g!==2||E.type!==2,null,false):t.continuousEvent(p,N,g!==2||E.type!==2,null,false));}Z.push(p);}}}clear(){for(;this.shapes.length>0;){let t=this.shapes[this.shapes.length-1];t.removedFromSpace(),this.__remove(t);}this.grid.clear(),this.cellPool.length=0,this.testedPairs.clear();}shapesUnderPoint(t,n,s,i){this.space.validation();let l=ae.get(t,n),r=i??new Rt._nape.shape.ShapeList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb;if(c.minx<=t&&c.maxx>=t&&c.miny<=n&&c.maxy>=n){let h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else h=true;h&&(p.type==0?ge.circleContains(p.circle,l)&&r.push(p.outer):ge.polyContains(p.polygon,l)&&r.push(p.outer));}}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=ae.zpp_pool,ae.zpp_pool=o,r}bodiesUnderPoint(t,n,s,i){this.space.validation();let l=ae.get(t,n),r=i??new Rt._nape.phys.BodyList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb;if(c.minx<=t&&c.maxx>=t&&c.miny<=n&&c.maxy>=n){let h=p.body.outer;if(!r.has(h)){let u;if(s!=null){let x=p.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0;}else u=true;u&&(p.type==0?ge.circleContains(p.circle,l)&&r.push(h):ge.polyContains(p.polygon,l)&&r.push(h));}}}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=ae.zpp_pool,ae.zpp_pool=o,r}shapesInAABB(t,n,s,i,l){this.space.validation(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new Rt._nape.shape.ShapeList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c;if(i!=null){let h=p.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0;}else c=true;if(c)if(n)if(s)ge.containTest(this.aabbShape.zpp_inner,p)&&o.push(p.outer);else {let h=p.aabb;if(h.minx>=r.minx&&h.miny>=r.miny&&h.maxx<=r.maxx&&h.maxy<=r.maxy)o.push(p.outer);else {let u=p.aabb;r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx&&ge.testCollide_safe(p,this.aabbShape.zpp_inner)&&o.push(p.outer);}}else {let h;if(s){let u=p.aabb;h=u.minx>=r.minx&&u.miny>=r.miny&&u.maxx<=r.maxx&&u.maxy<=r.maxy;}else {let u=p.aabb;h=r.miny<=u.maxy&&u.miny<=r.maxy&&r.minx<=u.maxx&&u.minx<=r.maxx;}h&&o.push(p.outer);}}return o}bodiesInAABB(t,n,s,i,l){this.space.validation(),this.updateAABBShape(t);let r=this.aabbShape.zpp_inner.aabb,o=l??new Rt._nape.phys.BodyList;this.failed==null&&(this.failed=new Rt._nape.phys.BodyList);for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.body.outer,h=p.aabb;if(r.miny<=h.maxy&&h.miny<=r.maxy&&r.minx<=h.maxx&&h.minx<=r.maxx){let u;if(i!=null){let x=p.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0;}else u=true;if(u)if(n)if(s){if(!this.failed.has(c)){let x=ge.containTest(this.aabbShape.zpp_inner,p);!o.has(c)&&x?o.push(c):x||(o.remove(c),this.failed.push(c));}}else !o.has(c)&&ge.testCollide_safe(p,this.aabbShape.zpp_inner)&&o.push(c);else if(s){if(!this.failed.has(c)){let x=p.aabb,m=x.minx>=r.minx&&x.miny>=r.miny&&x.maxx<=r.maxx&&x.maxy<=r.maxy;!o.has(c)&&m?o.push(c):m||(o.remove(c),this.failed.push(c));}}else {let x;if(o.has(c))x=false;else {let m=p.aabb;x=m.minx>=r.minx&&m.miny>=r.miny&&m.maxx<=r.maxx&&m.maxy<=r.maxy;}x&&o.push(c);}}}return this.failed.clear(),o}shapesInCircle(t,n,s,i,l,r){this.space.validation(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new Rt._nape.shape.ShapeList;for(let p=0;p<this.shapes.length;p++){let c=this.shapes[p],h=c.aabb;if(o.miny<=h.maxy&&h.miny<=o.maxy&&o.minx<=h.maxx&&h.minx<=o.maxx){let u;if(l!=null){let x=c.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0;}else u=true;u&&(i?ge.containTest(this.circShape.zpp_inner,c)&&a.push(c.outer):ge.testCollide_safe(c,this.circShape.zpp_inner)&&a.push(c.outer));}}return a}bodiesInCircle(t,n,s,i,l,r){this.space.validation(),this.updateCircShape(t,n,s);let o=this.circShape.zpp_inner.aabb,a=r??new Rt._nape.phys.BodyList;this.failed==null&&(this.failed=new Rt._nape.phys.BodyList);for(let p=0;p<this.shapes.length;p++){let c=this.shapes[p],h=c.aabb;if(o.miny<=h.maxy&&h.miny<=o.maxy&&o.minx<=h.maxx&&h.minx<=o.maxx){let u=c.body.outer,x;if(l!=null){let m=c.filter;x=(m.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&m.collisionGroup)!=0;}else x=true;if(x)if(i){if(!this.failed.has(u)){let m=ge.containTest(this.circShape.zpp_inner,c);!a.has(u)&&m?a.push(u):m||(a.remove(u),this.failed.push(u));}}else !a.has(u)&&ge.testCollide_safe(c,this.circShape.zpp_inner)&&a.push(u);}}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.space.validation(),this.validateShape(t);let l=t.aabb,r=i??new Rt._nape.shape.ShapeList;for(let o=0;o<this.shapes.length;o++){let a=this.shapes[o],p=a.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx){let c;if(s!=null){let h=a.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0;}else c=true;c&&(n?ge.containTest(t,a)&&r.push(a.outer):ge.testCollide_safe(a,t)&&r.push(a.outer));}}return r}bodiesInShape(t,n,s,i){this.space.validation(),this.validateShape(t);let l=t.aabb,r=i??new Rt._nape.phys.BodyList;this.failed==null&&(this.failed=new Rt._nape.phys.BodyList);for(let o=0;o<this.shapes.length;o++){let a=this.shapes[o],p=a.aabb;if(l.miny<=p.maxy&&p.miny<=l.maxy&&l.minx<=p.maxx&&p.minx<=l.maxx){let c=a.body.outer,h;if(s!=null){let u=a.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else h=true;if(h)if(n){if(!this.failed.has(c)){let u=ge.containTest(t,a);!r.has(c)&&u?r.push(c):u||(r.remove(c),this.failed.push(c));}}else !r.has(c)&&ge.testCollide_safe(t,a)&&r.push(c);}}return this.failed.clear(),r}rayCast(t,n,s){this.space.validation(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,r=null;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb,h;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else h=true;else h=false;if(h){let u=t.aabbsect(c);if(u>=0&&u<l){let x=p.type==0?t.circlesect(p.circle,n,l):t.polysect(p.polygon,n,l);if(x!=null){if(x.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=x.zpp_inner.toiDistance,r!=null){if(r.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");r.zpp_inner.free();}r=x;}}}}let o=i;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=be.zpp_pool,be.zpp_pool=o,r}rayMultiCast(t,n,s,i){this.space.validation(),t.validate_dir();let l=t.rayAABB(),r=i??new Rt._nape.geom.RayResultList;for(let a=0;a<this.shapes.length;a++){let p=this.shapes[a],c=p.aabb,h;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0;}else h=true;else h=false;h&&t.aabbsect(c)>=0&&(p.type==0?t.circlesect2(p.circle,n,r):t.polysect2(p.polygon,n,r));}let o=l;return o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=be.zpp_pool,be.zpp_pool=o,r}};Rt._zpp=null,Rt._nape=null,Rt.TUNE_INTERVAL=120;var cs=Rt;function Bl(){let j={},e={};return j.callbacks={},j.constraint={},j.dynamics={},j.geom={},j.phys={},j.shape={},j.space={},j.util={},e.ZPP_Const=ci,e.ZPP_ID=yn,e.callbacks||(e.callbacks={}),Tt._nape=j,Tt._zpp=e,e.callbacks.ZPP_Callback=Tt,dt._zpp=e,e.callbacks.ZPP_CbSet=dt,Ne._zpp=e,e.callbacks.ZPP_CbSetPair=Ne,e.util||(e.util={}),jl(e),cn._zpp=e,e.callbacks.ZPP_CbType=cn,e.util.ZPP_Flags=J,Lt._nape=j,Lt._zpp=e,e.callbacks.ZPP_Listener=Lt,e.callbacks.ZPP_BodyListener=Ks,e.callbacks.ZPP_ConstraintListener=Ys,e.callbacks.ZPP_InteractionListener=Hs,es._nape=j,es._zpp=e,e.callbacks.ZPP_OptionType=es,e.constraint||(e.constraint={}),Ze._nape=j,Ze._zpp=e,e.constraint.ZPP_Constraint=Ze,e.constraint.ZPP_AngleJoint=Re,e.constraint.ZPP_CopyHelper=qn,e.constraint.ZPP_DistanceJoint=xi,e.constraint.ZPP_LineJoint=_i,e.constraint.ZPP_MotorJoint=di,e.constraint.ZPP_PivotJoint=yi,e.constraint.ZPP_PulleyJoint=mi,e.constraint.ZPP_UserConstraint=Xs,e.constraint.ZPP_UserBody=ts,e.constraint.ZPP_WeldJoint=bi,e.dynamics||(e.dynamics={}),Ie._nape=j,Ie._zpp=e,e.dynamics.ZPP_Arbiter=Ie,e.dynamics.ZPP_SensorArbiter=Ot,Pt._nape=j,Pt._zpp=e,e.dynamics.ZPP_FluidArbiter=Pt,ut._nape=j,ut._zpp=e,e.dynamics.ZPP_ColArbiter=ut,e.dynamics.ZPP_IContact=fi,we._nape=j,we._zpp=e,e.dynamics.ZPP_Contact=we,st._nape=j,st._zpp=e,e.dynamics.ZPP_InteractionFilter=st,Zs._zpp=e,e.dynamics.ZPP_InteractionGroup=Zs,Hn._nape=j,Hn._zpp=e,e.dynamics.ZPP_SpaceArbiterList=Hn,e.geom||(e.geom={}),be._nape=j,be._zpp=e,e.geom.ZPP_AABB=be,e.geom.ZPP_Collide=ge,e.geom.ZPP_Convex=ns,e.geom.ZPP_ConvexRayResult=bn,e.geom.ZPP_CutVert=Xe,e.geom.ZPP_CutInt=ot,e.geom.ZPP_Cutter=is,e.geom.ZPP_Geom=ss,e.geom.ZPP_GeomVert=Pe,Pe._createVec2Fn=function(){return new j.geom.Vec2},e.geom.ZPP_GeomPoly=ls,e.geom.ZPP_MarchSpan=In,e.geom.ZPP_MarchPair=jn,ks._init(e,j),e.geom.ZPP_MarchingSquares=ks,Es._nape=j,e.geom.ZPP_Mat23=Es,e.geom.ZPP_MatMN=ji,e.geom.ZPP_Monotone=Dt,e.geom.ZPP_PartitionVertex=Ge,e.geom.ZPP_PartitionedPoly=Je,e.geom.ZPP_Ray=Qs,e.geom.ZPP_SimpleVert=Ee,e.geom.ZPP_SimpleSeg=Vt,e.geom.ZPP_SimpleEvent=Ce,e.geom.ZPP_SimpleSweep=Di,e.geom.ZPP_Simple=Pi,e.geom.ZPP_SimplifyV=gn,e.geom.ZPP_SimplifyP=Te,e.geom.ZPP_Simplify=os,e.geom.ZPP_ToiEvent=Ns,e.geom.ZPP_SweepDistance=Cn,e.geom.ZPP_PartitionPair=St,e.geom.ZPP_Triangular=ii,e.geom.ZPP_Vec2=ae,si._zpp=e,e.geom.ZPP_Vec3=si,e.geom.ZPP_VecMath=$s,e.phys||(e.phys={}),e.phys.ZPP_Interactor=Kt,Kt._init(e,j),Mn._init(e,j),e.phys.ZPP_Body=Mn,Wn._nape=j,Wn._zpp=e,Wn._init(),e.phys.ZPP_Compound=Wn,Zn._nape=j,Zn._zpp=e,e.phys.ZPP_FluidProperties=Zn,Oe._nape=j,Oe._zpp=e,e.phys.ZPP_Material=Oe,e.shape||(e.shape={}),li._nape=j,li._zpp=e,li._init(),e.shape.ZPP_Shape=li,Xn._nape=j,Xn._zpp=e,Xn._init(),e.shape.ZPP_Circle=Xn,rt._nape=j,rt._zpp=e,e.shape.ZPP_Edge=rt,Nn._nape=j,Nn._zpp=e,Nn._init(),e.shape.ZPP_Polygon=Nn,e.space||(e.space={}),Bn._zpp=e,Bn._nape=j,e.space.ZPP_Broadphase=Bn,e.space.ZPP_AABBNode=Ae,e.space.ZPP_AABBPair=lt,e.space.ZPP_AABBTree=Qe,as._zpp=e,as._nape=j,e.space.ZPP_DynAABBPhase=as,xt._zpp=e,e.space.ZPP_Island=xt,e.space.ZPP_Component=Ss,Yt._zpp=e,e.space.ZPP_CallbackSet=Yt,Ri._zpp=e,e.space.ZPP_CbSetManager=Ri,ri._zpp=e,ri._nape=j,e.space.ZPP_Space=ri,e.space.ZPP_SweepData=Ln,ps._zpp=e,ps._nape=j,e.space.ZPP_SweepPhase=ps,cs._zpp=e,cs._nape=j,e.space.ZPP_SpatialHashPhase=cs,e.util.ZNPArray2_Float=Ui,e.util.ZNPArray2_ZPP_GeomVert=Ki,e.util.ZNPArray2_ZPP_MarchPair=Yi,e.util.Hashable2_Boolfalse=Be,e.util.FastHash2_Hashable2_Boolfalse=Ni,e.util.ZPP_Math=Us,e.util.ZPP_PubPool=xe,e.callbacks.ZPP_InteractionListener._initStatics(e),e.geom.ZPP_Collide._initStatics(e),e.space.ZPP_AABBTree._initStatics(),j.__zpp=e,j}var el;function _e(){return el||(el=Bl()),el}var Tl=false;function tl(){if(Tl)return;let j=el;if(!j?.callbacks?.CbEvent||!j?.callbacks?.CbType||!j?.callbacks?.ListenerType||!j?.dynamics?.ArbiterType||!j?.phys?.BodyType||!j?.shape?.ShapeType)return;Tl=true;let e=j.__zpp;e.callbacks.ZPP_CbType._initEnums(j),e.callbacks.ZPP_Listener._initEnums(j,e.util.ZPP_Flags),e.dynamics.ZPP_Arbiter._initEnums(j,e.util.ZPP_Flags),e.phys.ZPP_Body._initEnums(j,e.util.ZPP_Flags),e.shape.ZPP_Shape._initEnums(j,e.util.ZPP_Flags);}var Ll=new WeakMap;function ke(j,e){if(!j)return null;let t=Ll.get(j);return t||(t=e(j),Ll.set(j,t)),t}var et=class j{constructor(e=0,t=0){this.zpp_pool=null;this.zpp_disp=false;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;ae.zpp_pool==null?n=new ae:(n=ae.zpp_pool,ae.zpp_pool=n.next,n.next=null),n.weak=false,n._immutable=false,n.x=e,n.y=t,this.zpp_inner=n,n.outer=this;}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}_checkImmutable(){this.zpp_inner.immutable();}_validate(){this.zpp_inner.validate();}_invalidate(){this.zpp_inner.invalidate();}static _disposeWeak(e){e.zpp_inner.weak&&e.dispose();}_setXY(e,t){if(this._checkDisposed(),this._checkImmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");this._validate(),(this.zpp_inner.x!==e||this.zpp_inner.y!==t)&&(this.zpp_inner.x=e,this.zpp_inner.y=t,this._invalidate());}static _poolGet(e,t,n){let s;if(xe.poolVec2==null?s=new j:(s=xe.poolVec2,xe.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=false,s===xe.nextVec2&&(xe.nextVec2=null)),s.zpp_inner==null){let i;ae.zpp_pool==null?i=new ae:(i=ae.zpp_pool,ae.zpp_pool=i.next,i.next=null),i.weak=false,i._immutable=false,i.x=e,i.y=t,s.zpp_inner=i,i.outer=s;}else s.zpp_inner.immutable(),s.zpp_inner.validate(),(s.zpp_inner.x!==e||s.zpp_inner.y!==t)&&(s.zpp_inner.x=e,s.zpp_inner.y=t,s.zpp_inner.invalidate());return s.zpp_inner.weak=n,s}static _wrap(e){return e instanceof j?e:e?e instanceof ae?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=false,t.outer=n,n}):e.zpp_inner?j._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=false){if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");return j._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 j._poolGet(e,t,true)}static fromPolar(e,t,n=false){if(e!==e)throw new Error("Error: Vec2::length cannot be NaN");if(t!==t)throw new Error("Error: Vec2::angle cannot be NaN");let s=e*Math.cos(t),i=e*Math.sin(t);return j._poolGet(s,i,n)}static fromAngle(e,t=false){return j.fromPolar(1,e,t)}static lerp(e,t,n,s=false){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot lerp with null Vec2");if(n!==n)throw new Error("Error: Cannot lerp with NaN t");e.zpp_inner.validate(),t.zpp_inner.validate();let i=e.zpp_inner.x+n*(t.zpp_inner.x-e.zpp_inner.x),l=e.zpp_inner.y+n*(t.zpp_inner.y-e.zpp_inner.y),r=j._poolGet(i,l,s);return j._disposeWeak(e),j._disposeWeak(t),r}static eq(e,t,n=0){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null){let r=e==null&&t==null;return e!=null&&j._disposeWeak(e),t!=null&&j._disposeWeak(t),r}e.zpp_inner.validate(),t.zpp_inner.validate();let s=e.zpp_inner.x-t.zpp_inner.x,i=e.zpp_inner.y-t.zpp_inner.y,l=(s<0?-s:s)<=n&&(i<0?-i:i)<=n;return j._disposeWeak(e),j._disposeWeak(t),l}static dsq(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,s=e.zpp_inner.y;t.zpp_inner.validate();let i=t.zpp_inner.x,l=t.zpp_inner.y,r=n-i,o=s-l,a=r*r+o*o;return j._disposeWeak(e),j._disposeWeak(t),a}static distance(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot compute squared distance between null Vec2");e.zpp_inner.validate();let n=e.zpp_inner.x,s=e.zpp_inner.y;t.zpp_inner.validate();let i=t.zpp_inner.x,l=t.zpp_inner.y,r=n-i,o=s-l,a=Math.sqrt(r*r+o*o);return j._disposeWeak(e),j._disposeWeak(t),a}get x(){return this._checkDisposed(),this._validate(),this.zpp_inner.x}set x(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.x!==e){if(e!==e)throw new Error("Error: Vec2::x cannot be NaN");this.zpp_inner.x=e,this._invalidate();}}get y(){return this._checkDisposed(),this._validate(),this.zpp_inner.y}set y(e){if(this._checkDisposed(),this._checkImmutable(),this._validate(),this.zpp_inner.y!==e){if(e!==e)throw new Error("Error: Vec2::y cannot be NaN");this.zpp_inner.y=e,this._invalidate();}}get length(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return Math.sqrt(e*e+t*t)}set length(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::length cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,s=t*t+n*n;if(s===0)throw new Error("Error: Cannot set length of a zero vector");let i=e/Math.sqrt(s);this._setXY(t*i,n*i),this._invalidate();}get angle(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e===t&&e===0?0:Math.atan2(t,e)}set angle(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Vec2::angle cannot be NaN");this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,s=Math.sqrt(t*t+n*n),i=s*Math.cos(e),l=s*Math.sin(e);this._setXY(i,l);}lsq(){this._checkDisposed(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y;return e*e+t*t}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");e.zpp_inner.validate();let t=e.zpp_inner.x,n=e.zpp_inner.y;return this._setXY(t,n),j._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 false;this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,s=this.zpp_inner.y-e.zpp_inner.y;return (n<0?-n:n)<=t&&(s<0?-s:s)<=t}copy(e=false){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y;return j._poolGet(t,n,e)}rotate(e){if(this._checkDisposed(),this._checkImmutable(),e!==e)throw new Error("Error: Cannot rotate Vec2 by NaN");if(e%(Math.PI*2)!==0){let t=Math.sin(e),n=Math.cos(e),s=n*this.zpp_inner.x-t*this.zpp_inner.y;this.zpp_inner.y=this.zpp_inner.x*t+this.zpp_inner.y*n,this.zpp_inner.x=s,this._invalidate();}return this}reflect(e,t=false){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this._validate();let n=this.zpp_inner.x,s=this.zpp_inner.y;if(Math.sqrt(n*n+s*s)===0)throw new Error("Error: Cannot reflect in zero vector");let i=j._poolGet(n,s,true);i.normalise();let l=e.sub(i.muleq(2*i.dot(e)),t);return j._disposeWeak(e),l}normalise(){this._checkDisposed(),this._checkImmutable(),this._validate();let e=this.zpp_inner.x,t=this.zpp_inner.y,n=e*e+t*t;if(Math.sqrt(n)===0)throw new Error("Error: Cannot normalise vector of length 0");let s=1/Math.sqrt(n);return this._setXY(e*s,t*s),this._invalidate(),this}unit(e=false){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,s=t*t+n*n;if(Math.sqrt(s)===0)throw new Error("Error: Cannot normalise vector of length 0");let i=1/Math.sqrt(s);return j._poolGet(t*i,n*i,e)}add(e,t=false){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x+e.zpp_inner.x,s=this.zpp_inner.y+e.zpp_inner.y,i=j._poolGet(n,s,t);return j._disposeWeak(e),i}addMul(e,t,n=false){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let s=this.zpp_inner.x+e.zpp_inner.x*t,i=this.zpp_inner.y+e.zpp_inner.y*t,l=j._poolGet(s,i,n);return j._disposeWeak(e),l}sub(e,t=false){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot subtract null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,s=this.zpp_inner.y-e.zpp_inner.y,i=j._poolGet(n,s,t);return j._disposeWeak(e),i}mul(e,t=false){if(this._checkDisposed(),e!==e)throw new Error("Error: Cannot multiply with NaN");this._validate();let n=this.zpp_inner.x*e,s=this.zpp_inner.y*e;return j._poolGet(n,s,t)}addeq(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let t=this.zpp_inner.x+e.zpp_inner.x,n=this.zpp_inner.y+e.zpp_inner.y;return this._setXY(t,n),j._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),j._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 j._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 j._disposeWeak(e),t}perp(e=false){this._checkDisposed(),this._validate();let t=-this.zpp_inner.y,n=this.zpp_inner.x;return j._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=true,e.free(),e.next=ae.zpp_pool,ae.zpp_pool=e;}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};ae._wrapFn=j=>ke(j,e=>{let t=Object.create(et.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=false,e.outer=t,t});var uo=_e();uo.geom.Vec2=et;var ai=class j{constructor(e=0,t=0,n=0){this.zpp_pool=null;this.zpp_disp=false;let s=new si;this.zpp_inner=s,s.outer=this,s.x=e,s.y=t,s.z=n;}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!")}_checkImmutable(){if(this.zpp_inner.immutable)throw new Error("Error: Vec3 is immutable")}static _wrap(e){return e instanceof j?e:e?e instanceof si?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=false,t.outer=n,n}):e.zpp_inner?j._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=0){let s;return xe.poolVec3==null?s=new j:(s=xe.poolVec3,xe.poolVec3=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=false,s===xe.nextVec3&&(xe.nextVec3=null)),s.setxyz(e,t,n),s.zpp_inner.immutable=false,s.zpp_inner._validate=null,s}get x(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.x}set x(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e;}get y(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.y}set y(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.y=e;}get z(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.z}set z(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.z=e;}get length(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return Math.sqrt(e*e+t*t+n*n)}set length(e){if(this._checkDisposed(),e!==e)throw new Error("Error: Vec3::length cannot be NaN");this.zpp_inner.validate();let{x:t,y:n,z:s}=this.zpp_inner,i=t*t+n*n+s*s;if(i===0)throw new Error("Error: Cannot set length of a zero vector");let l=e/Math.sqrt(i);this._checkImmutable(),this.zpp_inner.x=t*l,this.zpp_inner.y=n*l,this.zpp_inner.z=s*l;}lsq(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return e*e+t*t+n*n}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot assign null Vec3");return e.zpp_inner.validate(),this.setxyz(e.zpp_inner.x,e.zpp_inner.y,e.zpp_inner.z)}setxyz(e,t,n){return this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e,this._checkImmutable(),this.zpp_inner.y=t,this._checkImmutable(),this.zpp_inner.z=n,this}equals(e,t=0){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)return false;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,s=this.zpp_inner.y-e.zpp_inner.y,i=this.zpp_inner.z-e.zpp_inner.z;return (n<0?-n:n)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t}clone(){return this._checkDisposed(),this.zpp_inner.validate(),j.get(this.zpp_inner.x,this.zpp_inner.y,this.zpp_inner.z)}xy(e=false){return this._checkDisposed(),this.zpp_inner.validate(),et.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=true;}toString(){return this._checkDisposed(),this.zpp_inner.validate(),"{ x: "+this.zpp_inner.x+" y: "+this.zpp_inner.y+" z: "+this.zpp_inner.z+" }"}};si._wrapFn=j=>ke(j,e=>{let t=Object.create(ai.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=false,e.outer=t,t});var As=class j{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 ji(e,t),this.zpp_inner.outer=this;}static _wrap(e){return e instanceof j?e:e?e instanceof ji?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?j._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 false;for(let n=0;n<this.zpp_inner.x.length;n++){let s=this.zpp_inner.x[n]-e.zpp_inner.x[n];if((s<0?-s:s)>t)return false}return true}clone(){let e=new j(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=true;for(let n=0;n<this.zpp_inner.m;n++){t||(e+="; "),t=false;for(let s=0;s<this.zpp_inner.n;s++){if(n<0||s<0||n>=this.zpp_inner.m||s>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");e+=this.zpp_inner.x[n*this.zpp_inner.n+s]+" ";}}return e+="}",e}transpose(){let e=new j(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 j(this.zpp_inner.m,t.zpp_inner.n);for(let s=0;s<this.zpp_inner.m;s++)for(let i=0;i<t.zpp_inner.n;i++){let l=0;for(let r=0;r<this.zpp_inner.n;r++)l+=this.zpp_inner.x[s*this.zpp_inner.n+r]*t.zpp_inner.x[r*t.zpp_inner.n+i];n.zpp_inner.x[s*n.zpp_inner.n+i]=l;}return n}},xo=_e();xo.geom.MatMN=As;var qi=class j{get _inner(){return this}constructor(e=0,t=0,n=0,s=0){if(e!==e||t!==t)throw new Error("Error: AABB position cannot be NaN");if(n!==n||s!==s)throw new Error("Error: AABB dimensions cannot be NaN");let i;be.zpp_pool==null?i=new be:(i=be.zpp_pool,be.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=t,i.maxx=e+n,i.maxy=t+s,this.zpp_inner=i,i.outer=this;}static fromPoints(e){if(e==null||e.length===0)throw new Error("Error: AABB::fromPoints requires at least one point");let t=e[0];if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");t.zpp_inner.validate();let n=t.zpp_inner.x,s=t.zpp_inner.y,i=n,l=s;for(let r=1;r<e.length;r++){let o=e[r];if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(o==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");o.zpp_inner.validate();let a=o.zpp_inner.x,p=o.zpp_inner.y;a<n&&(n=a),p<s&&(s=p),a>i&&(i=a),p>l&&(l=p);}return new j(n,s,i-n,l-s)}static _wrap(e){return e instanceof j?e:e?e instanceof be?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?j._wrap(e.zpp_inner):null:null}get x(){return this.zpp_inner.validate(),this.zpp_inner.minx}set x(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::x cannot be NaN");this.zpp_inner.maxx+=e-this.zpp_inner.minx,this.zpp_inner.minx=e,this.zpp_inner.invalidate();}}get y(){return this.zpp_inner.validate(),this.zpp_inner.miny}set y(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::y cannot be NaN");this.zpp_inner.maxy+=e-this.zpp_inner.miny,this.zpp_inner.miny=e,this.zpp_inner.invalidate();}}get width(){return this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx}set width(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxx-this.zpp_inner.minx!=e){if(e!==e)throw new Error("Error: AABB::width cannot be NaN");if(e<0)throw new Error("Error: AABB::width ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxx=this.zpp_inner.minx+e,this.zpp_inner.invalidate();}}get height(){return this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny}set height(e){if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(this.zpp_inner.validate(),this.zpp_inner.maxy-this.zpp_inner.miny!=e){if(e!==e)throw new Error("Error: AABB::height cannot be NaN");if(e<0)throw new Error("Error: AABB::height ("+e+") must be >= 0");this.zpp_inner.validate(),this.zpp_inner.maxy=this.zpp_inner.miny+e,this.zpp_inner.invalidate();}}get min(){return this.zpp_inner.getmin(),this.zpp_inner.wrap_min}set min(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::min");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::min components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::min components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let s=e.zpp_inner.x;this.zpp_inner.getmax();let i=this.zpp_inner.wrap_max;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),s>i.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.y;this.zpp_inner.getmin();let r=this.zpp_inner.wrap_max;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(r.zpp_inner._validate!=null&&r.zpp_inner._validate(),l>r.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let o=this.zpp_inner.wrap_min;this._assignVec2(o,e),e.zpp_inner.weak&&this._disposeVec2(e);}get max(){return this.zpp_inner.getmax(),this.zpp_inner.wrap_max}set max(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::max");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::max components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::max components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let s=e.zpp_inner.x;this.zpp_inner.getmin();let i=this.zpp_inner.wrap_min;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),s<i.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.y;this.zpp_inner.getmin();let r=this.zpp_inner.wrap_min;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(r.zpp_inner._validate!=null&&r.zpp_inner._validate(),l<r.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let o=this.zpp_inner.wrap_max;this._assignVec2(o,e),e.zpp_inner.weak&&this._disposeVec2(e);}_assignVec2(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=e.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t==null)throw new Error("Error: Cannot assign null Vec2");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let s=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let i=t.zpp_inner.y;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e.zpp_inner._validate!=null&&e.zpp_inner._validate(),e.zpp_inner.x==s){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate(),r=e.zpp_inner.y==i;}else r=false;r||(e.zpp_inner.x=s,e.zpp_inner.y=i,e.zpp_inner._invalidate!=null&&e.zpp_inner._invalidate(e.zpp_inner));}_disposeVec2(e){let n=_e().zpp_nape;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=e.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let i=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let l=e;l.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=l:n.util.ZPP_PubPool.poolVec2=l,n.util.ZPP_PubPool.nextVec2=l,l.zpp_disp=true;let r=i;r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r;}clone(){return this.copy()}equals(e,t=0){if(e==null)return false;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.minx-e.zpp_inner.minx,s=this.zpp_inner.miny-e.zpp_inner.miny,i=this.zpp_inner.maxx-e.zpp_inner.maxx,l=this.zpp_inner.maxy-e.zpp_inner.maxy;return (n<0?-n:n)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t&&(l<0?-l:l)<=t}copy(){this.zpp_inner.validate();let e=this.zpp_inner;return be.get(e.minx,e.miny,e.maxx,e.maxy).wrapper()}toString(){return this.zpp_inner.validate(),this.zpp_inner.toString()}};be._wrapFn=j=>ke(j,e=>{let t=Object.create(qi.prototype);return t.zpp_inner=e,e.outer=t,t});var yl=class j{constructor(){if(!J.internal)throw new Error("Error: Cannot instantiate Winding derp!")}static get UNDEFINED(){return J.Winding_UNDEFINED==null&&(J.internal=true,J.Winding_UNDEFINED=new j,J.internal=false),J.Winding_UNDEFINED}static get CLOCKWISE(){return J.Winding_CLOCKWISE==null&&(J.internal=true,J.Winding_CLOCKWISE=new j,J.internal=false),J.Winding_CLOCKWISE}static get ANTICLOCKWISE(){return J.Winding_ANTICLOCKWISE==null&&(J.internal=true,J.Winding_ANTICLOCKWISE=new j,J.internal=false),J.Winding_ANTICLOCKWISE}toString(){return this===J.Winding_UNDEFINED?"UNDEFINED":this===J.Winding_CLOCKWISE?"CLOCKWISE":this===J.Winding_ANTICLOCKWISE?"ANTICLOCKWISE":""}},_o=_e();_o.geom.Winding=yl;var Qn=class Qn{constructor(){this.ptr=null;this.start=null;this.first=false;this.forward=false;this.outer=null;this.next=null;Qn.internal=true;let e=_e();this.outer=new e.geom.GeomVertexIterator,Qn.internal=false;}static get(e,t){let n;return Qn.zpp_pool==null?n=new Qn:(n=Qn.zpp_pool,Qn.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(){}};Qn.zpp_pool=null,Qn.internal=false;var hs=Qn;var Dl=class j{constructor(e){this.zpp_pool=null;this.zpp_disp=false;this.zpp_inner=new ls(this),e!=null&&(j._addVertices(this,e),this.skipForward(1),j._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 Pe.zpp_pool==null?n=new Pe:(n=Pe.zpp_pool,Pe.zpp_pool=n.next,n.next=null),n.forced=false,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=Pe.zpp_pool,Pe.zpp_pool=e;}_popHead(){let e=this.zpp_inner.vertices;if(e.prev===e)e.next=e.prev=null,this.zpp_inner.vertices=null;else {let t=e.prev;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null,this.zpp_inner.vertices=t;}return e}_shiftHead(){let e=this.zpp_inner.vertices;if(e.prev===e)e.next=e.prev=null,this.zpp_inner.vertices=null;else {let t=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null,this.zpp_inner.vertices=t;}return e}_isDegenRing(){let e=this.zpp_inner.vertices;return e==null||e.next==null||e.prev===e.next}_forEachVert(e){let t=this.zpp_inner.vertices;if(t!=null){let n=t;do e(n),n=n.next;while(n!==t)}}_extremalVert(e,t){if(this._checkDisposed(),this.zpp_inner.vertices==null){let i=t?e==="y"?"topmost":"leftmost":e==="y"?"bottommost":"rightmost";throw new Error("Error: empty GeomPoly has no defineable "+i+" vertex")}let n=this.zpp_inner.vertices,s=n.next;for(;s!==this.zpp_inner.vertices;)(t?s[e]<n[e]:s[e]>n[e])&&(n=s),s=s.next;return n.wrapper()}static _addVertices(e,t){let n=_e();if(t instanceof Array)for(let s=0;s<t.length;s++){let i=t[s];if(i==null)throw new Error("Error: Array<Vec2> contains null objects");if(!(i instanceof et))throw new Error("Error: Array<Vec2> contains non Vec2 objects");let l=i;if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");l.zpp_inner.validate();let r=l.zpp_inner.x;l.zpp_inner.validate();let o=l.zpp_inner.y,a=j._createVert(r,o);j._pushVert(e,a);}else if(t instanceof n.geom.Vec2List){let s=t.iterator();for(;s.hasNext();){let i=s.next();if(i==null)throw new Error("Error: Vec2List contains null objects");if(i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.zpp_inner.validate();let l=i.zpp_inner.x;i.zpp_inner.validate();let r=i.zpp_inner.y,o=j._createVert(l,r);j._pushVert(e,o);}}else if(t instanceof j){if(t.zpp_disp)throw new Error("Error: GeomPoly has been disposed and cannot be used!");let s=t.zpp_inner.vertices;if(s!=null){let i=s;do{let l=j._createVert(i.x,i.y);j._pushVert(e,l),i=i.next;}while(i!==s)}}else throw new Error("Error: Invalid type for polygon object, should be Array<Vec2>, Vec2List, GeomPoly or for flash10+ flash.Vector<Vec2>")}static _disposeWeakInputs(e){if(e instanceof Array){let t=0;for(;t<e.length;){let n=e[t];n.zpp_inner&&n.zpp_inner.weak?(n.dispose(),e.splice(t,1)):t++;}}else if(e instanceof _e().geom.Vec2List){let t=e;t.zpp_inner._validate!=null&&t.zpp_inner._validate();let n=t.zpp_inner.inner,s=null,i=n.head;for(;i!=null;){let l=i.elt;l.outer&&l.outer.zpp_inner&&l.outer.zpp_inner.weak?(i=n.erase(s),l.outer.zpp_inner.weak&&l.outer.dispose()):(s=i,i=i.next);}}}static get(e){let t;return xe.poolGeomPoly==null?t=new j:(t=xe.poolGeomPoly,xe.poolGeomPoly=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=false,t===xe.nextGeomPoly&&(xe.nextGeomPoly=null)),e!=null&&(j._addVertices(t,e),t.skipForward(1),j._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(),hs.get(this.zpp_inner.vertices,true)}forwardIterator(){return this._checkDisposed(),hs.get(this.zpp_inner.vertices,true)}backwardsIterator(){return this._checkDisposed(),hs.get(this.zpp_inner.vertices,false)}current(){if(this._checkDisposed(),this.zpp_inner.vertices==null)throw new Error("Error: GeomPoly is empty");return this.zpp_inner.vertices.wrapper()}push(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot push null vertex");e.zpp_inner.validate();let t=e.zpp_inner.x;e.zpp_inner.validate();let n=e.zpp_inner.y,s=j._createVert(t,n);return j._pushVert(this,s),e.zpp_inner.weak&&e.dispose(),this}pop(){if(this._checkDisposed(),this.zpp_inner.vertices==null)throw new Error("Error: Cannot pop from empty polygon");let e=this._popHead();return j._freeVert(e),this}unshift(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot unshift null vertex");e.zpp_inner.validate();let t=e.zpp_inner.x;e.zpp_inner.validate();let n=e.zpp_inner.y,s=j._createVert(t,n);return j._unshiftVert(this,s),e.zpp_inner.weak&&e.dispose(),this}shift(){if(this._checkDisposed(),this.zpp_inner.vertices==null)throw new Error("Error: Cannot shift from empty polygon");let e=this._shiftHead();return j._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),j._freeVert(t);}return this}clear(){for(this._checkDisposed();this.zpp_inner.vertices!=null;){let e=this._shiftHead();j._freeVert(e);}return this}copy(){this._checkDisposed();let e=j.get();return this._forEachVert(t=>{let n=j._createVert(t.x,t.y);j._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=true;}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 J.Winding_UNDEFINED==null&&(J.internal=true,J.Winding_UNDEFINED=new(_e()).geom.Winding,J.internal=false),J.Winding_UNDEFINED;let e=0;this._forEachVert(n=>{e+=n.x*(n.next.y-n.prev.y);});let t=e*.5;return t>0?(J.Winding_CLOCKWISE==null&&(J.internal=true,J.Winding_CLOCKWISE=new(_e()).geom.Winding,J.internal=false),J.Winding_CLOCKWISE):t===0?(J.Winding_UNDEFINED==null&&(J.internal=true,J.Winding_UNDEFINED=new(_e()).geom.Winding,J.internal=false),J.Winding_UNDEFINED):(J.Winding_ANTICLOCKWISE==null&&(J.internal=true,J.Winding_ANTICLOCKWISE=new(_e()).geom.Winding,J.internal=false),J.Winding_ANTICLOCKWISE)}contains(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: GeomPoly::contains point cannot be null");e.zpp_inner.validate();let t=e.zpp_inner.x;e.zpp_inner.validate();let n=e.zpp_inner.y,s=false;return this._forEachVert(i=>{let l=i.prev;(i.y<n&&l.y>=n||l.y<n&&i.y>=n)&&(i.x<=t||l.x<=t)&&i.x+(n-i.y)/(l.y-i.y)*(l.x-i.x)<t&&(s=!s);}),e.zpp_inner.weak&&e.dispose(),s}isClockwise(){let e=this.winding();return J.Winding_CLOCKWISE==null&&(J.internal=true,J.Winding_CLOCKWISE=new(_e()).geom.Winding,J.internal=false),e===J.Winding_CLOCKWISE}isConvex(){if(this._checkDisposed(),this._isDegenRing())return true;let e=false,t=false,n=true,s=this.zpp_inner.vertices,i=s;do{let l=i,r=l.prev,o=l.next,a=o.x-l.x,p=o.y-l.y,c=l.x-r.x,u=(l.y-r.y)*a-c*p;if(u>0?t=true:u<0&&(e=true),t&&e){n=false;break}i=i.next;}while(i!==s);return n}isSimple(){return this._checkDisposed(),this._isDegenRing()?true:Pi.isSimple(this.zpp_inner.vertices)}isMonotone(){return this._checkDisposed(),this._isDegenRing()?true:Dt.isMonotone(this.zpp_inner.vertices)}isDegenerate(){return this._checkDisposed(),this._isDegenRing()?true:this.area()<_e().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=os.simplify(this.zpp_inner.vertices,e),n=j.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=_e(),n=this.zpp_inner.vertices;Je.sharedGVList==null&&(Je.sharedGVList=new Gn);let s=Pi.decompose(n,Je.sharedGVList),i=e??new t.geom.GeomPolyList;for(;s.head!=null;){let l=s.pop_unsafe(),r=j.get();r.zpp_inner.vertices=l,i.zpp_inner.reverse_flag?i.push(r):i.unshift(r);}return i}monotoneDecomposition(e){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let t=_e(),n=this.zpp_inner.vertices;Dt.sharedPPoly==null&&(Dt.sharedPPoly=new Je);let s=Dt.decompose(n,Dt.sharedPPoly);Je.sharedGVList==null&&(Je.sharedGVList=new Gn);let i=s.extract(Je.sharedGVList),l=e??new t.geom.GeomPolyList;for(;i.head!=null;){let r=i.pop_unsafe(),o=j.get();o.zpp_inner.vertices=r,l.zpp_inner.reverse_flag?l.push(o):l.unshift(o);}return l}convexDecomposition(e=false,t){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let n=_e(),s=this.zpp_inner.vertices;Dt.sharedPPoly==null&&(Dt.sharedPPoly=new Je);let i=Dt.decompose(s,Dt.sharedPPoly);Je.sharedPPList==null&&(Je.sharedPPList=new Oi);let l=i.extract_partitions(Je.sharedPPList),r=t??new n.geom.GeomPolyList;for(;l.head!=null;){let o=l.pop_unsafe();ii.triangulate(o),e&&ii.optimise(o),ns.optimise(o),Je.sharedGVList==null&&(Je.sharedGVList=new Gn);let a=o.extract(Je.sharedGVList),p=o;for(p.next=Je.zpp_pool,Je.zpp_pool=p;a.head!=null;){let c=a.pop_unsafe(),h=j.get();h.zpp_inner.vertices=c,r.zpp_inner.reverse_flag?r.push(h):r.unshift(h);}}return r}triangularDecomposition(e=false,t){if(this._checkDisposed(),this._isDegenRing())throw new Error("Error: Cannot decompose a degenerate polygon");let n=_e(),s=this.zpp_inner.vertices;Dt.sharedPPoly==null&&(Dt.sharedPPoly=new Je);let i=Dt.decompose(s,Dt.sharedPPoly);Je.sharedPPList==null&&(Je.sharedPPList=new Oi);let l=i.extract_partitions(Je.sharedPPList),r=t??new n.geom.GeomPolyList;for(;l.head!=null;){let o=l.pop_unsafe();ii.triangulate(o),e&&ii.optimise(o),Je.sharedGVList==null&&(Je.sharedGVList=new Gn);let a=o.extract(Je.sharedGVList),p=o;for(p.next=Je.zpp_pool,Je.zpp_pool=p;a.head!=null;){let c=a.pop_unsafe(),h=j.get();h.zpp_inner.vertices=c,r.zpp_inner.reverse_flag?r.push(h):r.unshift(h);}}return r}inflate(e){this._checkDisposed();let t=j.get();return this.isClockwise()&&(e=-e),this._forEachVert(n=>{let s=n.prev,i=n.next,l=n.x-s.x,r=n.y-s.y,o=i.x-n.x,a=i.y-n.y,p=Math.sqrt(l*l+r*r),c=-r/p*e,h=l/p*e,u=Math.sqrt(o*o+a*a),x=-a/u*e,m=o/u*e,_=x-c,y=m-h,z=a*_-o*y,b=z===0?0:z/(a*l-o*r),w=n.x+c+l*b,Z=n.y+h+r*b,d=et.get(w,Z);t.push(d);}),t.skipForward(1)}cut(e,t,n=false,s=false,i){if(this._checkDisposed(),!(this._isDegenRing()||Pi.isSimple(this.zpp_inner.vertices)))throw new Error("Error: Cut requires a truly simple polygon");if(e==null||t==null)throw new Error("Error: Cannot cut with null start/end's");if(e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=is.run(this.zpp_inner.vertices,e,t,n,s,i);return e.zpp_inner.weak&&e.dispose(),t.zpp_inner.weak&&t.dispose(),l}transform(e){if(this._checkDisposed(),e==null)throw new Error("Error: Cannot transform by null matrix");return this._forEachVert(t=>{let n=e.zpp_inner.a*t.x+e.zpp_inner.b*t.y+e.zpp_inner.tx;t.y=e.zpp_inner.c*t.x+e.zpp_inner.d*t.y+e.zpp_inner.ty,t.x=n;}),this}bounds(){if(this._checkDisposed(),this.zpp_inner.vertices==null)throw new Error("Error: empty GeomPoly has no defineable bounds");let e=1e100,t=1e100,n=-1e100,s=-1e100;return this._forEachVert(i=>{i.x<e&&(e=i.x),i.y<t&&(t=i.y),i.x>n&&(n=i.x),i.y>s&&(s=i.y);}),new qi(e,t,n-e,s-t)}top(){return this._extremalVert("y",true)}bottom(){return this._extremalVert("y",false)}left(){return this._extremalVert("x",true)}right(){return this._extremalVert("x",false)}toString(){let e="GeomPoly[",t=this.zpp_inner.vertices;if(t!=null){let n=t;do n!==t&&(e+=","),e+="{"+n.x+","+n.y+"}",n=n.next;while(n!==t)}return e+"]"}};var Vs,Is,js;function Fl(j){Vs=j;}function kx(j){Is=j;}function Ex(j){js=j;}var Bs=class Bs{constructor(){this._inner=void 0,this.zpp_inner_i=null;}static _wrap(e){return e?e instanceof Bs?e:e.isBody&&e.isBody()&&Vs?Vs(e):e.isShape&&e.isShape()&&Is?Is(e):e.isCompound&&e.isCompound()&&js?js(e):ke(e,t=>{let n=Object.create(Bs.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 Vs?Vs(e):e}return null}get castShape(){if(this.zpp_inner_i.ishape!=null){let e=this.zpp_inner_i.ishape.outer;return Is?Is(e):e}return null}get castCompound(){if(this.zpp_inner_i.icompound!=null){let e=this.zpp_inner_i.icompound.outer;return js?js(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 ""}};Bs.zpp_internalAlloc=false;var vi=Bs;var nl=class{constructor(e,t){this._inner=e,this._wrap=t;}get length(){return this._inner.length}at(e){return this._wrap(this._inner.at(e))}add(e){this._inner.add(e._inner??e);}remove(e){this._inner.remove(e._inner??e);}has(e){return this._inner.has(e._inner??e)}clear(){this._inner.clear();}get empty(){return this._inner.empty()}push(e){this._inner.push(e._inner??e);}pop(){return this._wrap(this._inner.pop())}shift(){return this._wrap(this._inner.shift())}unshift(e){this._inner.unshift(e._inner??e);}*[Symbol.iterator](){for(let e=0;e<this.length;e++)yield this.at(e);}toArray(){return [...this]}forEach(e){for(let t=0;t<this.length;t++)e(this.at(t),t);}toString(){return this._inner.toString()}};var pi=class j{get _inner(){return this}constructor(e=1,t=1){let n;if(Zn.zpp_pool==null?n=new Zn:(n=Zn.zpp_pool,Zn.zpp_pool=n.next,n.next=null),this.zpp_inner=n,n.outer=this,e!=n.density*1e3){if(e!==e)throw new Error("Error: FluidProperties::density cannot be NaN");n.density=e/1e3,n.invalidate();}if(t!=n.viscosity){if(t!==t)throw new Error("Error: FluidProperties::viscosity cannot be NaN");if(t<0)throw new Error("Error: FluidProperties::viscosity ("+t+") must be >= 0");n.viscosity=t/1,n.invalidate();}}static _wrap(e){return e instanceof j?e:e?e instanceof Zn?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?j._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=_e().zpp_nape;if(e==null){if(this.zpp_inner.wrap_gravity!=null){this.zpp_inner.wrap_gravity.zpp_inner._inuse=false;let s=this.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),s.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let l=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let r=s;r.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=r:n.util.ZPP_PubPool.poolVec2=r,n.util.ZPP_PubPool.nextVec2=r,r.zpp_disp=true;let o=l;o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o,this.zpp_inner.wrap_gravity=null;}}else {if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity();let s=this.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;l._validate!=null&&l._validate();let r=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;o._validate!=null&&o._validate();let a=e.zpp_inner.y;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=s.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),r!=r||a!=a)throw new Error("Error: Vec2 components cannot be NaN");let c;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=s.zpp_inner;if(h._validate!=null&&h._validate(),s.zpp_inner.x==r){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=s.zpp_inner;u._validate!=null&&u._validate(),c=s.zpp_inner.y==a;}else c=false;if(!c){s.zpp_inner.x=r,s.zpp_inner.y=a;let u=s.zpp_inner;u._invalidate!=null&&u._invalidate(u);}if(e.zpp_inner.weak){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=e.zpp_inner;if(u._immutable)throw new Error("Error: Vec2 is immutable");if(u._isimmutable!=null&&u._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let x=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let m=e;m.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=m:n.util.ZPP_PubPool.poolVec2=m,n.util.ZPP_PubPool.nextVec2=m,m.zpp_disp=true;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=_e();this.zpp_inner.wrap_shapes=e.zpp_nape.util.ZPP_ShapeList.get(this.zpp_inner.shapes,true);}return this.zpp_inner.wrap_shapes}copy(){let t=_e().zpp_nape,n=new j(this.zpp_inner.density*1e3,this.zpp_inner.viscosity);this.zpp_inner.userData!=null&&(n.zpp_inner.userData={...this.zpp_inner.userData});let s=this.zpp_inner.wrap_gravity;if(s==null){if(n.zpp_inner.wrap_gravity!=null){n.zpp_inner.wrap_gravity.zpp_inner._inuse=false;let i=n.zpp_inner.wrap_gravity;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),i.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let r=i.zpp_inner;i.zpp_inner.outer=null,i.zpp_inner=null;let o=i;o.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=o:t.util.ZPP_PubPool.poolVec2=o,t.util.ZPP_PubPool.nextVec2=o,o.zpp_disp=true;let a=r;a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=a,n.zpp_inner.wrap_gravity=null;}}else {if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");n.zpp_inner.wrap_gravity==null&&n.zpp_inner.getgravity();let i=n.zpp_inner.wrap_gravity;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),s==null)throw new Error("Error: Cannot assign null Vec2");if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=s.zpp_inner;r._validate!=null&&r._validate();let o=s.zpp_inner.x;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=s.zpp_inner;a._validate!=null&&a._validate();let p=s.zpp_inner.y;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=i.zpp_inner;if(c._immutable)throw new Error("Error: Vec2 is immutable");if(c._isimmutable!=null&&c._isimmutable(),o!=o||p!=p)throw new Error("Error: Vec2 components cannot be NaN");let h;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=i.zpp_inner;if(u._validate!=null&&u._validate(),i.zpp_inner.x==o){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=i.zpp_inner;x._validate!=null&&x._validate(),h=i.zpp_inner.y==p;}else h=false;if(!h){i.zpp_inner.x=o,i.zpp_inner.y=p;let x=i.zpp_inner;x._invalidate!=null&&x._invalidate(x);}if(s.zpp_inner.weak){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=s.zpp_inner;if(x._immutable)throw new Error("Error: Vec2 is immutable");if(x._isimmutable!=null&&x._isimmutable(),s.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let m=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let _=s;_.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=true;let y=m;y.outer!=null&&(y.outer.zpp_inner=null,y.outer=null),y._isimmutable=null,y._validate=null,y._invalidate=null,y.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=y;}}return n}toString(){return "{ density: "+this.zpp_inner.density*1e3+" viscosity: "+this.zpp_inner.viscosity+" gravity: "+String(this.zpp_inner.wrap_gravity)+" }"}};Zn._wrapFn=j=>ke(j,e=>{let t=Object.create(pi.prototype);return t.zpp_inner=e,e.outer=t,t});var yo=_e();yo.phys.FluidProperties=pi;var Ts=class j{constructor(){if(!J.internal)throw new Error("Error: Cannot instantiate ShapeType derp!")}static get CIRCLE(){return J.ShapeType_CIRCLE==null&&(J.internal=true,J.ShapeType_CIRCLE=new j,J.internal=false),J.ShapeType_CIRCLE}static get POLYGON(){return J.ShapeType_POLYGON==null&&(J.internal=true,J.ShapeType_POLYGON=new j,J.internal=false),J.ShapeType_POLYGON}static get CAPSULE(){return J.ShapeType_CAPSULE==null&&(J.internal=true,J.ShapeType_CAPSULE=new j,J.internal=false),J.ShapeType_CAPSULE}toString(){return this===J.ShapeType_CIRCLE?"CIRCLE":this===J.ShapeType_POLYGON?"POLYGON":this===J.ShapeType_CAPSULE?"CAPSULE":""}},mo=_e();mo.shape.ShapeType=Ts;tl();var Ls,Ds,Fs;function Gl(j){Ls=j;}function Rl(j){Ds=j;}function ql(j){Fs=j;}var $n=class j extends vi{constructor(){super();}static _wrap(e){if(!e)return null;let t=e.zpp_inner??e;if(t._isCapsule&&Fs)return Fs(e);let n=e.isCircle?e.isCircle()?0:e.isPolygon?.()?1:t.type??-1:t.type??-1;return n===0&&Ls?Ls(e):n===1&&Ds?Ds(e):e.outer?e.outer:ke(e,s=>{let i=Object.create(j.prototype);return i._inner=s,i.zpp_inner=s.zpp_inner??s,i.zpp_inner_i=s.zpp_inner_i??s,i})}get type(){return li.types[this.zpp_inner.type]}isCircle(){return this.zpp_inner.type===0}isPolygon(){return this.zpp_inner.type===1}isCapsule(){return !!this.zpp_inner._isCapsule}get body(){let e=this.zpp_inner;return e.body!=null?e.body.outer:null}set body(e){let t=this.zpp_inner;t.immutable_midstep("Shape::body");let n=t.body!=null?t.body.outer:null;if(n!==e&&(t.body!=null&&n.zpp_inner.wrap_shapes.remove(this),e!=null)){let s=e.zpp_inner.wrap_shapes;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this);}}get castCircle(){let e=this.zpp_inner;if(e.type===0){let t=e.circle.outer_zn;return Ls?Ls(t):t}return null}get castPolygon(){let e=this.zpp_inner;if(e.type===1){let t=e.polygon.outer_zn;return Ds?Ds(t):t}return null}get castCapsule(){let e=this.zpp_inner;if(e._isCapsule){let t=e.outer;return Fs?Fs(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 s=n.x;n._validate!=null&&n._validate();let i=n.y;(t.type===0?t.circle:t.type===1?t.polygon:t.capsule).__translate(s,i);}return e.zpp_inner.weak&&e.dispose(),this}scale(e,t){let n=this.zpp_inner,s=_e();if(n.immutable_midstep("Shape::scale()"),n.body!=null&&n.body.space!=null&&n.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e!==e||t!==t)throw new Error("Error: Cannot scale Shape by NaN");if(e===0||t===0)throw new Error("Error: Cannot Scale shape by a factor of 0");if(n.type===0){let i=e*e-t*t;if(i*i<s.Config.epsilon*s.Config.epsilon)n.circle.__scale(e,t);else throw new Error("Error: Cannot perform a non equal scaling on a Circle")}else n.type===1?n.polygon.__scale(e,t):n.capsule.__scale(e,t);return this}rotate(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::rotate()"),t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e!==e)throw new Error("Error: Cannot rotate Shape by NaN");if(e%(2*Math.PI)!==0){let s=Math.cos(e),i=Math.sin(e);t.type===0?t.circle.__rotate(i,s):t.type===1?t.polygon.__rotate(i,s):t.capsule.__rotate(i,s);}return this}transform(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::transform()"),t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Cannot transform Shape by null matrix");let n=e._inner??e;if(n.singular())throw new Error("Error: Cannot transform Shape by a singular matrix");if(t.type===0)if(n.equiorthogonal())t.circle.__transform(n);else throw new Error("Error: Cannot transform Circle by a non equiorthogonal matrix");else t.type===1?t.polygon.__transform(n):t.capsule.__transform(n);return this}contains(e){let t=this.zpp_inner;if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Cannot check null point for containment");if((t.body!=null?t.body.outer:null)==null)throw new Error("Error: Shape is not well defined without a Body");ss.validateShape(t);let n=e.zpp_inner;n._validate!=null&&n._validate();let s=ge.shapeContains(t,n);return n.weak&&e.dispose(),s}copy(){let e=this.zpp_inner.copy();return e instanceof j?e:j._wrap(e)}toString(){let e=this.zpp_inner;return (e.type===0?"Circle":e.type===1?"Polygon":"Capsule")+"#"+this.zpp_inner_i.id}_setupWorldCOM(){let e=_e(),t=this.zpp_inner,n=t.worldCOMx,s=t.worldCOMy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(xe.poolVec2==null?i=new e.geom.Vec2:(i=xe.poolVec2,xe.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=false,i===xe.nextVec2&&(xe.nextVec2=null)),i.zpp_inner==null){let l;ae.zpp_pool==null?l=new ae:(l=ae.zpp_pool,ae.zpp_pool=l.next,l.next=null),l.weak=false,l._immutable=false,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i;}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=false,t.wrap_worldCOM=i,t.wrap_worldCOM.zpp_inner._inuse=true,t.wrap_worldCOM.zpp_inner._immutable=true,t.wrap_worldCOM.zpp_inner._validate=t.getworldCOM.bind(t);}};var gi={SHAPES:1,JOINTS:2,CONTACTS:4,AABB:8,CENTER_OF_MASS:16,VELOCITIES:32,ALL:63};var ml=class{constructor(){this.user_length=0;this.zip_length=false;this.push_ite=null;this.at_ite=null;this.at_index=0;this.reverse_flag=false;this.dontremove=false;this.subber=null;this.post_adder=null;this.adder=null;this._modifiable=null;this._validate=null;this._invalidate=null;this._invalidated=false;this.immutable=false;this.inner=null;this.outer=null;this._invalidated=true;}valmod(){this.validate(),this.inner.modified&&(this.inner.pushmod&&(this.push_ite=null),this.at_ite=null,this.inner.modified=false,this.inner.pushmod=false,this.zip_length=true);}modified(){this.zip_length=true,this.at_ite=null,this.push_ite=null;}modify_test(){this._modifiable!=null&&this._modifiable();}validate(){this._invalidated&&(this._invalidated=false,this._validate!=null&&this._validate());}invalidate(){this._invalidated=true,this._invalidate!=null&&this._invalidate(this);}};function On(j,e,t,n){let s=_e(),i=s.__zpp;class l extends ml{constructor(){super(),this.inner=new i.util[j];}static get(o,a=false){let p=new s[e][t];return p.zpp_inner.inner=o,a&&(p.zpp_inner.immutable=true),p.zpp_inner.zip_length=true,p}}return l.internal=false,i.util[n]=l,l}exports.Y=null;exports.Z=null;var fl=null;exports.Y=On("ZNPList_ZPP_Constraint","constraint","ConstraintList","ZPP_ConstraintList");On("ZNPList_ZPP_Body","phys","BodyList","ZPP_BodyList");exports.Z=On("ZNPList_ZPP_Interactor","phys","InteractorList","ZPP_InteractorList");On("ZNPList_ZPP_Compound","phys","CompoundList","ZPP_CompoundList");On("ZNPList_ZPP_Listener","callbacks","ListenerList","ZPP_ListenerList");On("ZNPList_ZPP_CbType","callbacks","CbTypeList","ZPP_CbTypeList");On("ZNPList_ZPP_GeomPoly","geom","GeomPolyList","ZPP_GeomPolyList");On("ZNPList_RayResult","geom","RayResultList","ZPP_RayResultList");On("ZNPList_ConvexResult","geom","ConvexResultList","ZPP_ConvexResultList");On("ZNPList_ZPP_Edge","shape","EdgeList","ZPP_EdgeList");On("ZNPList_ZPP_Shape","shape","ShapeList","ZPP_ShapeList");On("ZNPList_ZPP_InteractionGroup","dynamics","InteractionGroupList","ZPP_InteractionGroupList");fl=On("ZNPList_ZPP_Arbiter","dynamics","ArbiterList","ZPP_ArbiterList");function Jn(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Un(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Dn(j){if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}function Sn(j){j.zpp_inner.weak&&j.dispose();}function us(j,e,t,n,s){if(Dn(t),t==null)throw new Error("Error: Body::"+j+" cannot be null");return e==null&&n!=null&&(n(),e=s()),e.set(t),e}function il(j,e,t){return et.get(j,e,t)}function ln(j,e){return J[j]==null&&(J.internal=true,J[j]=e(),J.internal=false),J[j]}var nt=class j extends vi{constructor(t,n){super();this.debugDraw=true;let s=new Mn;this.zpp_inner=s,s.outer=this,s.outer_i=this,this.zpp_inner_i=s,this._inner=this,n!=null?(Dn(n),s.posx=Jn(n),s.posy=Un(n)):(s.posx=0,s.posy=0);let i=_e(),l;if(t==null?l=ln("BodyType_DYNAMIC",()=>new i.phys.BodyType):l=t,s.immutable_midstep("Body::type"),s.world)throw new Error("Error: Space::world is immutable");if(Mn.types[s.type]!==l){if(l==null)throw new Error("Error: Cannot use null BodyType");let r=Wl(l,i);r===1&&s.space!=null&&(s.velx=0,s.vely=0,s.angvel=0),s.invalidate_type(),s.space!=null?s.space.transmitType(s,r):s.type=r;}n!=null&&Sn(n),s.insert_cbtype(cn.ANY_BODY.zpp_inner);}static _wrap(t){return t?t instanceof j?t:t instanceof Mn?ke(t,n=>{let s=Object.create(j.prototype);return s.zpp_inner=n,n.outer=s,n.outer_i=s,s.zpp_inner_i=n,s._inner=s,s.debugDraw=true,s}):t.zpp_inner?j._wrap(t.zpp_inner):ke(t,n=>{let s=Object.create(j.prototype);return s._inner=n,s}):null}get type(){return Mn.types[this.zpp_inner.type]}set type(t){let n=this.zpp_inner;if(n.immutable_midstep("Body::type"),n.world)throw new Error("Error: Space::world is immutable");if(Mn.types[n.type]!==t){if(t==null)throw new Error("Error: Cannot use null BodyType");let s=_e(),i=Wl(t,s);i===1&&n.space!=null&&(n.velx=0,n.vely=0,n.angvel=0),n.invalidate_type(),n.space!=null?n.space.transmitType(n,i):n.type=i;}}isStatic(){return this.zpp_inner.type===1}isDynamic(){return this.zpp_inner.type===2}isKinematic(){return this.zpp_inner.type===3}get position(){return this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),this.zpp_inner.wrap_pos}set position(t){us("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){us("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){us("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){us("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){us("force",this.zpp_inner.wrap_force,t,()=>this.zpp_inner.setupForce(),()=>this.zpp_inner.wrap_force),this.zpp_inner.wrap_force==null&&this.zpp_inner.setupForce();}get torque(){return this.zpp_inner.torque}set torque(t){let n=this.zpp_inner;if(n.world)throw new Error("Error: Space::world is immutable");if(n.type!==2)throw new Error("Error: Non-dynamic body cannot have torque applied.");if(t!==t)throw new Error("Error: Body::torque cannot be NaN");n.torque!==t&&(n.torque=t,n.wake());}get mass(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(this.zpp_inner.validate_mass(),this.zpp_inner.massMode===0&&this.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");return this.zpp_inner.cmass}set mass(t){if(this.zpp_inner.immutable_midstep("Body::mass"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: Mass cannot be NaN");if(t<=0)throw new Error("Error: Mass must be strictly positive");if(t>=1/0)throw new Error("Error: Mass cannot be infinite, use allowMovement = false instead");this.zpp_inner.massMode=1,this.zpp_inner.cmass=t,this.zpp_inner.invalidate_mass();}get inertia(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no inertia");if(this.zpp_inner.validate_inertia(),this.zpp_inner.inertiaMode===0&&this.zpp_inner.shapes.head==null)throw new Error("Error: Given current inertia mode flag, Body::inertia only makes sense if Body contains Shapes");return this.zpp_inner.cinertia}set inertia(t){if(this.zpp_inner.immutable_midstep("Body::inertia"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: Inertia cannot be NaN");if(t<=0)throw new Error("Error: Inertia must be strictly positive");if(t>=1/0)throw new Error("Error: Inertia cannot be infinite, use allowRotation = false instead");this.zpp_inner.inertiaMode=1,this.zpp_inner.cinertia=t,this.zpp_inner.invalidate_inertia();}get constraintMass(){return this.zpp_inner.world||this.zpp_inner.validate_mass(),this.zpp_inner.smass}get constraintInertia(){return this.zpp_inner.world||this.zpp_inner.validate_inertia(),this.zpp_inner.sinertia}get gravMass(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no gravMass");if(this.zpp_inner.validate_gravMass(),this.zpp_inner.shapes.head==null&&this.zpp_inner.massMode===0&&this.zpp_inner.gravMassMode!==1)throw new Error("Error: Given current mass/gravMass modes; Body::gravMass only makes sense if it contains Shapes");return this.zpp_inner.gravMass}set gravMass(t){if(this.zpp_inner.immutable_midstep("Body::gravMass"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: gravMass cannot be NaN");this.zpp_inner.gravMassMode=1,this.zpp_inner.gravMass=t,this.zpp_inner.invalidate_gravMass();}get gravMassScale(){if(this.zpp_inner.validate_gravMassScale(),this.zpp_inner.shapes.head==null&&this.zpp_inner.massMode===0&&this.zpp_inner.gravMassMode!==2)throw new Error("Error: Given current mass/gravMass modes; Body::gravMassScale only makes sense if it contains Shapes");return this.zpp_inner.gravMassScale}set gravMassScale(t){if(this.zpp_inner.immutable_midstep("Body::gravMassScale"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t!==t)throw new Error("Error: gravMassScale cannot be NaN");this.zpp_inner.gravMassMode=2,this.zpp_inner.gravMassScale=t,this.zpp_inner.invalidate_gravMassScale();}get isBullet(){return this.zpp_inner.bulletEnabled}set isBullet(t){this.zpp_inner.bulletEnabled=t;}get disableCCD(){return this.zpp_inner.disableCCD}set disableCCD(t){this.zpp_inner.disableCCD=t;}get allowMovement(){return !this.zpp_inner.nomove}set allowMovement(t){this.zpp_inner.immutable_midstep("Body::"+(t==null?"null":""+t)),!this.zpp_inner.nomove!==t&&(this.zpp_inner.nomove=!t,this.zpp_inner.invalidate_mass());}get allowRotation(){return !this.zpp_inner.norotate}set allowRotation(t){this.zpp_inner.immutable_midstep("Body::"+(t==null?"null":""+t)),!this.zpp_inner.norotate!==t&&(this.zpp_inner.norotate=!t,this.zpp_inner.invalidate_inertia());}get isSleeping(){if(this.zpp_inner.space==null)throw new Error("Error: isSleeping makes no sense if the object is not contained within a Space");return this.zpp_inner.component.sleeping}get shapes(){return new nl(this.zpp_inner.wrap_shapes,$n._wrap)}get space(){return this.zpp_inner.space==null?null:xs._wrap(this.zpp_inner.space.outer)}set space(t){let n=t!=null?t._inner??t:null;if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let s=this.zpp_inner.space==null?null:this.zpp_inner.space.outer;if(s!==n&&(s!=null&&(this.zpp_inner.component.woken=false,s.zpp_inner.wrap_bodies.remove(this)),n!=null)){let i=n.zpp_inner.wrap_bodies;i.zpp_inner.reverse_flag?i.push(this):i.unshift(this);}}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(t){let n=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(n!==t&&(n?.zpp_inner.wrap_bodies.remove(this),t!=null)){let s=t.zpp_inner.wrap_bodies;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this);}}get bounds(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no bounds");return qi._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=et.get(this.zpp_inner.localCOMx,this.zpp_inner.localCOMy);this.zpp_inner.wrap_localCOM=t,t.zpp_inner._inuse=true,t.zpp_inner._immutable=true,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=et.get(this.zpp_inner.worldCOMx,this.zpp_inner.worldCOMy);this.zpp_inner.wrap_worldCOM=t,t.zpp_inner._inuse=true,t.zpp_inner._immutable=true,t.zpp_inner._validate=()=>this.zpp_inner.getworldCOM();}return this.zpp_inner.wrap_worldCOM}get massMode(){let t=_e(),n=ln("MassMode_DEFAULT",()=>new t.phys.MassMode),s=ln("MassMode_FIXED",()=>new t.phys.MassMode);return [n,s][this.zpp_inner.massMode]}set massMode(t){let n=_e();if(this.zpp_inner.immutable_midstep("Body::massMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: cannot use null massMode");let s=ln("MassMode_DEFAULT",()=>new n.phys.MassMode);this.zpp_inner.massMode=t===s?0:1,this.zpp_inner.invalidate_mass();}get inertiaMode(){let t=_e(),n=ln("InertiaMode_DEFAULT",()=>new t.phys.InertiaMode),s=ln("InertiaMode_FIXED",()=>new t.phys.InertiaMode);return [n,s][this.zpp_inner.inertiaMode]}set inertiaMode(t){let n=_e();if(this.zpp_inner.immutable_midstep("Body::inertiaMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot use null InertiaMode");let s=ln("InertiaMode_FIXED",()=>new n.phys.InertiaMode);this.zpp_inner.inertiaMode=t===s?1:0,this.zpp_inner.invalidate_inertia();}get gravMassMode(){let t=_e(),n=ln("GravMassMode_DEFAULT",()=>new t.phys.GravMassMode),s=ln("GravMassMode_FIXED",()=>new t.phys.GravMassMode),i=ln("GravMassMode_SCALED",()=>new t.phys.GravMassMode);return [n,s,i][this.zpp_inner.gravMassMode]}set gravMassMode(t){let n=_e();if(this.zpp_inner.immutable_midstep("Body::gravMassMode"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot use null gravMassMode");let s=ln("GravMassMode_SCALED",()=>new n.phys.GravMassMode);if(t===s)this.zpp_inner.gravMassMode=2;else {let i=ln("GravMassMode_DEFAULT",()=>new n.phys.GravMassMode);this.zpp_inner.gravMassMode=t===i?0:1;}this.zpp_inner.invalidate_gravMass();}copy(){if(this.zpp_inner.world)throw new Error("Error: Space::world cannot be copied");return this.zpp_inner.copy()}toString(){let t=this.zpp_inner;return (t.world?"(space::world":"("+(t.type===2?"dynamic":t.type===1?"static":"kinematic"))+")#"+this.zpp_inner_i.id}integrate(t){if(t!==t)throw new Error("Cannot integrate by NaN time");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t===0)return this;let n=this.zpp_inner;n.sweepTime=0,n.sweep_angvel=n.angvel;let s=t-n.sweepTime;if(s!==0&&(n.sweepTime=t,n.posx+=n.velx*s,n.posy+=n.vely*s,n.angvel!==0)){let i=n.sweep_angvel*s;if(n.rot+=i,i*i>1e-4)n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot);else {let l=i*i,r=1-.5*l,o=1-l*l/8,a=(r*n.axisx+i*n.axisy)*o;n.axisy=(r*n.axisy-i*n.axisx)*o,n.axisx=a;}}return Jl(n),n.zip_worldCOM=true,n.zip_axis=true,Jl(n),n.zip_worldCOM=true,n.sweepTime=0,this}localPointToWorld(t,n=false){if(Dn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Jn(t),i=Un(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,r=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return Sn(t),il(l+this.zpp_inner.posx,r+this.zpp_inner.posy,n)}worldPointToLocal(t,n=false){if(Dn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Jn(t)-this.zpp_inner.posx,i=Un(t)-this.zpp_inner.posy,l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,r=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return Sn(t),il(l,r,n)}localVectorToWorld(t,n=false){if(Dn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Jn(t),i=Un(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,r=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return Sn(t),il(l,r,n)}worldVectorToLocal(t,n=false){if(Dn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Jn(t),i=Un(t),l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,r=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return Sn(t),il(l,r,n)}applyImpulse(t,n,s=false){if(Dn(t),n!=null&&Dn(n),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot apply null impulse to Body");if(s&&this.isSleeping)return Sn(t),n!=null&&Sn(n),this;this.zpp_inner.validate_mass();let i=this.zpp_inner.imass,l=Jn(t),r=Un(t);if(this.zpp_inner.velx+=l*i,this.zpp_inner.vely+=r*i,n!=null){let o=Jn(n)-this.zpp_inner.posx,a=Un(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(r*o-l*a)*this.zpp_inner.iinertia,Sn(n);}return s||this.zpp_inner.type===2&&this.zpp_inner.wake(),Sn(t),this}applyAngularImpulse(t,n=false){if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");return n&&this.isSleeping?this:(this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=t*this.zpp_inner.iinertia,n||this.zpp_inner.type===2&&this.zpp_inner.wake(),this)}setVelocityFromTarget(t,n,s){if(Dn(t),t==null)throw new Error("Cannot set velocity for null target position");if(s===0)throw new Error("deltaTime cannot be 0 for setVelocityFromTarget");let i=1/s;this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity(),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let l=t.sub(this.zpp_inner.wrap_pos,true).muleq(i);this.zpp_inner.wrap_vel.set(l);let r=(n-this.zpp_inner.rot)*i;if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.angvel!==r){if(r!==r)throw new Error("Error: Body::angularVel cannot be NaN");if(this.zpp_inner.type===1)throw new Error("Error: A static object cannot be given a velocity");this.zpp_inner.angvel=r,this.zpp_inner.wake();}return Sn(t),this}translateShapes(t){if(this.zpp_inner.immutable_midstep("Body::translateShapes()"),Dn(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=false;let s=this.zpp_inner.shapes.head;for(;s!=null;)s.elt.outer.translate(t),s=s.next;return t.zpp_inner.weak=n,Sn(t),this}rotateShapes(t){if(this.zpp_inner.immutable_midstep("Body::rotateShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.rotate(t),n=n.next;return this}scaleShapes(t,n){if(this.zpp_inner.immutable_midstep("Body::scaleShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let s=this.zpp_inner.shapes.head;for(;s!=null;)s.elt.outer.scale(t,n),s=s.next;return this}transformShapes(t){if(this.zpp_inner.immutable_midstep("Body::transformShapes()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;)n.elt.outer.transform(t),n=n.next;return this}align(){if(this.zpp_inner.immutable_midstep("Body::align()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.shapes.head==null)throw new Error("Error: Cannot align empty Body");this.zpp_inner.validate_localCOM();let t=et.get(-this.zpp_inner.localCOMx,-this.zpp_inner.localCOMy);this.translateShapes(t);let n=this.localVectorToWorld(t);return this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),this.zpp_inner.wrap_pos.subeq(n),this.zpp_inner.pre_posx<1/0&&(this.zpp_inner.pre_posx-=Jn(n),this.zpp_inner.pre_posy-=Un(n)),t.dispose(),n.dispose(),this}rotate(t,n){if(Dn(t),t==null)throw new Error("Error: Cannot rotate about a null Vec2");if(n!==n)throw new Error("Error: Cannot rotate by NaN radians");let s=t.zpp_inner.weak;t.zpp_inner.weak=false,this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let i=this.zpp_inner.wrap_pos.sub(t);i.rotate(n);let l=t.add(i,true);us("position",this.zpp_inner.wrap_pos,l,()=>this.zpp_inner.setupPosition(),()=>this.zpp_inner.wrap_pos),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition(),i.dispose();{let r=this.zpp_inner.rot+n,o=this.zpp_inner;if(o.immutable_midstep("Body::rotation"),o.world)throw new Error("Error: Space::world is immutable");if(o.type===1&&o.space!=null)throw new Error("Error: Static objects cannot be rotated once inside a Space");if(o.rot!==r){if(r!==r)throw new Error("Error: Body::rotation cannot be NaN");o.rot=r,o.invalidate_rot(),o.wake();}}return t.zpp_inner.weak=s,Sn(t),this}setShapeMaterials(t){if(this.zpp_inner.immutable_midstep("Body::setShapeMaterials()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let s=n.elt.outer;if(s.zpp_inner.immutable_midstep("Shape::material"),t==null)throw new Error("Error: Cannot assign null as Shape material");s.zpp_inner.setMaterial(t.zpp_inner),s.zpp_inner.material.wrapper(),n=n.next;}return this}setShapeFilters(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFilters()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=this.zpp_inner.shapes.head;for(;n!=null;){let s=n.elt.outer;if(s.zpp_inner.immutable_midstep("Shape::filter"),t==null)throw new Error("Error: Cannot assign null as Shape filter");s.zpp_inner.setFilter(t.zpp_inner),s.zpp_inner.filter.wrapper(),n=n.next;}return this}setShapeFluidProperties(t){if(this.zpp_inner.immutable_midstep("Body::setShapeFluidProperties()"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");let n=_e(),s=this.zpp_inner.shapes.head;for(;s!=null;){let i=s.elt.outer;if(t==null)throw new Error("Error: Cannot assign null as Shape fluidProperties, disable fluids by setting fluidEnabled to false");i.zpp_inner.setFluid(t.zpp_inner),i.zpp_inner.immutable_midstep("Shape::fluidProperties"),i.zpp_inner.fluidProperties==null&&i.zpp_inner.setFluid(new n.phys.FluidProperties().zpp_inner),i.zpp_inner.fluidProperties.wrapper(),s=s.next;}return this}contains(t){if(Dn(t),t==null)throw new Error("Error: Cannot check containment of null point");let n=t.zpp_inner.weak;t.zpp_inner.weak=false;let s=false,i=this.zpp_inner.shapes.head;for(;i!=null;){if(i.elt.outer.contains(t)){s=true;break}i=i.next;}return t.zpp_inner.weak=n,Sn(t),s}connectedBodies(t=-1,n=null){return this.zpp_inner.connectedBodies(t,n)}interactingBodies(t=null,n=-1,s=null){let i;if(t==null)i=Ie.COL|Ie.SENSOR|Ie.FLUID;else {let l=_e(),r=ln("InteractionType_COLLISION",()=>new l.callbacks.InteractionType);if(t===r)i=Ie.COL;else {let o=ln("InteractionType_SENSOR",()=>new l.callbacks.InteractionType);i=t===o?Ie.SENSOR:Ie.FLUID;}}return this.zpp_inner.interactingBodies(i,s)}normalImpulse(t=null,n=false){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.normalImpulse(this,n),t)}tangentImpulse(t=null,n=false){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.tangentImpulse(this,n),t)}totalContactsImpulse(t=null,n=false){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.totalImpulse(this,n),t)}rollingImpulse(t=null,n=false){let s=0,l=this._getArbiters().iterator();for(;;){l.zpp_inner.zpp_inner.valmod();let r=l.zpp_inner.zpp_gl();if(l.zpp_critical=true,l.zpp_i>=r){l.zpp_next=_e().dynamics.ArbiterIterator.zpp_pool,_e().dynamics.ArbiterIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=false;let o=l.zpp_inner.at(l.zpp_i++),a=o.zpp_inner;a.type===Ie.COL&&(t!=null&&a.b2!==t.zpp_inner&&a.b1!==t.zpp_inner||(s+=o.collisionArbiter.rollingImpulse(this,n)));}return s}buoyancyImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.buoyancyImpulse(this),t)}dragImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.dragImpulse(this),t)}totalFluidImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.totalImpulse(this),t)}constraintsImpulse(){let t=0,n=0,s=0,i=this.zpp_inner.constraints.head;for(;i!=null;){let r=i.elt.outer.bodyImpulse(this),o=r.zpp_inner;o._validate!=null&&o._validate(),t+=o.x,o._validate!=null&&o._validate(),n+=o.y,o._validate!=null&&o._validate(),s+=o.z,r.dispose(),i=i.next;}return ai.get(t,n,s)}totalImpulse(t=null,n=false){let s=0,i=0,l=0,o=this._getArbiters().iterator();for(;;){o.zpp_inner.zpp_inner.valmod();let p=o.zpp_inner.zpp_gl();if(o.zpp_critical=true,o.zpp_i>=p){o.zpp_next=_e().dynamics.ArbiterIterator.zpp_pool,_e().dynamics.ArbiterIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=false;let h=o.zpp_inner.at(o.zpp_i++).zpp_inner;if(h.type===Ie.SENSOR||t!=null&&h.b2!==t.zpp_inner&&h.b1!==t.zpp_inner)continue;let u=h.wrapper().totalImpulse(this,n),x=u.zpp_inner;x._validate!=null&&x._validate(),s+=x.x,x._validate!=null&&x._validate(),i+=x.y,x._validate!=null&&x._validate(),l+=x.z,u.dispose();}let a=this.zpp_inner.constraints.head;for(;a!=null;){let p=a.elt;if(p.outer.active){let c=p.outer.bodyImpulse(this),h=c.zpp_inner;h._validate!=null&&h._validate(),s+=h.x,h._validate!=null&&h._validate(),i+=h.y,h._validate!=null&&h._validate(),l+=h.z,c.dispose();}a=a.next;}return ai.get(s,i,l)}crushFactor(){if(this.zpp_inner.space==null)throw new Error("Error: Makes no sense to see how much an object not taking part in a simulation is being crushed");let t=0,n=et.get(0,0),i=this._getArbiters().iterator();for(;;){i.zpp_inner.zpp_inner.valmod();let x=i.zpp_inner.zpp_gl();if(i.zpp_critical=true,i.zpp_i>=x){i.zpp_next=_e().dynamics.ArbiterIterator.zpp_pool,_e().dynamics.ArbiterIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=false;let _=i.zpp_inner.at(i.zpp_i++).totalImpulse(this),y=_.xy();n.addeq(y);let z=Jn(y),b=Un(y);t+=Math.sqrt(z*z+b*b),y.dispose(),_.dispose();}let r=this._getConstraints();r.zpp_inner.valmod();let o=_e().constraint.ConstraintIterator.get(r);for(;;){o.zpp_inner.zpp_inner.valmod();let x=o.zpp_inner;x.zpp_inner.valmod(),x.zpp_inner.zip_length&&(x.zpp_inner.zip_length=false,x.zpp_inner.user_length=x.zpp_inner.inner.length);let m=x.zpp_inner.user_length;if(o.zpp_critical=true,o.zpp_i>=m){o.zpp_next=_e().constraint.ConstraintIterator.zpp_pool,_e().constraint.ConstraintIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=false;let y=o.zpp_inner.at(o.zpp_i++).bodyImpulse(this),z=y.xy();n.addeq(z);let b=Jn(z),w=Un(z);t+=Math.sqrt(b*b+w*w),z.dispose(),y.dispose();}let a=Jn(n),p=Un(n),c=Math.sqrt(a*a+p*p),h=this.mass,u=(t-c)/(h*this.zpp_inner.space.pre_dt);return n.dispose(),u}_getArbiters(){return this.zpp_inner.wrap_arbiters==null&&(this.zpp_inner.wrap_arbiters=fl.get(this.zpp_inner.arbiters,true)),this.zpp_inner.wrap_arbiters}_getConstraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=exports.Y.get(this.zpp_inner.constraints,true)),this.zpp_inner.wrap_constraints}_arbiterImpulseQuery(t,n,s){let i=0,l=0,r=0,a=this._getArbiters().iterator();for(;;){a.zpp_inner.zpp_inner.valmod();let p=a.zpp_inner.zpp_gl();if(a.zpp_critical=true,a.zpp_i>=p){a.zpp_next=_e().dynamics.ArbiterIterator.zpp_pool,_e().dynamics.ArbiterIterator.zpp_pool=a,a.zpp_inner=null;break}a.zpp_critical=false;let c=a.zpp_inner.at(a.zpp_i++),h=c.zpp_inner;if(h.type!==t||s!=null&&h.b2!==s.zpp_inner&&h.b1!==s.zpp_inner)continue;let u=n(c),x=u.zpp_inner;x._validate!=null&&x._validate(),i+=x.x,x._validate!=null&&x._validate(),l+=x.y,x._validate!=null&&x._validate(),r+=x.z,u.dispose();}return ai.get(i,l,r)}};function Wl(j,e){let t=ln("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(j===t)return 2;let n=ln("BodyType_KINEMATIC",()=>new e.phys.BodyType);return j===n?3:1}function Jl(j){let e=j.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 fo=_e();fo.phys.Body=nt;Fl(j=>nt._wrap(j));var xs=class j{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 ri(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 j?e:e instanceof ri?e.outer?e.outer:ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?.outer?e.zpp_inner.outer:ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n}):null}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get gravity(){return this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity(),this.zpp_inner.wrap_gravity}set gravity(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Space::gravity cannot be null");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity(),this.zpp_inner.wrap_gravity.set(e),e.zpp_inner?.weak&&e.dispose();}get broadphase(){return this.zpp_inner.bphase.is_spatial_hash?(J.Broadphase_SPATIAL_HASH==null&&(J.internal=true,J.Broadphase_SPATIAL_HASH=new(_e()).space.Broadphase,J.internal=false),J.Broadphase_SPATIAL_HASH):this.zpp_inner.bphase.is_sweep?(J.Broadphase_SWEEP_AND_PRUNE==null&&(J.internal=true,J.Broadphase_SWEEP_AND_PRUNE=new(_e()).space.Broadphase,J.internal=false),J.Broadphase_SWEEP_AND_PRUNE):(J.Broadphase_DYNAMIC_AABB_TREE==null&&(J.internal=true,J.Broadphase_DYNAMIC_AABB_TREE=new(_e()).space.Broadphase,J.internal=false),J.Broadphase_DYNAMIC_AABB_TREE)}get sortContacts(){return this.zpp_inner.sortcontacts}set sortContacts(e){this.zpp_inner.sortcontacts=e;}get deterministic(){return this.zpp_inner.deterministic}set deterministic(e){this.zpp_inner.deterministic=e,e&&(this.zpp_inner.sortcontacts=true);}get subSteps(){return this.zpp_inner.subSteps}set subSteps(e){if(e!==e)throw new Error("Error: Space::subSteps cannot be NaN");if(e<1)throw new Error("Error: Space::subSteps must be at least 1");this.zpp_inner.subSteps=Math.floor(e);}get worldAngularDrag(){return this.zpp_inner.global_ang_drag}set worldAngularDrag(e){if(e!==e)throw new Error("Error: Space::worldAngularDrag cannot be NaN");this.zpp_inner.global_ang_drag=e;}get worldLinearDrag(){return this.zpp_inner.global_lin_drag}set worldLinearDrag(e){if(e!==e)throw new Error("Error: Space::worldLinearDrag cannot be NaN");this.zpp_inner.global_lin_drag=e;}get compounds(){return this.zpp_inner.wrap_compounds}get bodies(){return this.zpp_inner.wrap_bodies}get liveBodies(){return this.zpp_inner.wrap_live}get constraints(){return this.zpp_inner.wrap_constraints}get liveConstraints(){return this.zpp_inner.wrap_livecon}get world(){return nt._wrap(this.zpp_inner.__static)}get arbiters(){if(this.zpp_inner.wrap_arbiters==null){let e=new Hn;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=_e(),n=this.zpp_inner.wrap_bodies;n.zpp_inner.valmod();let s=t.phys.BodyIterator.get(n);for(;;){s.zpp_inner.zpp_inner.valmod();let r=s.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=false,r.zpp_inner.user_length=r.zpp_inner.inner.length);let o=r.zpp_inner.user_length;if(s.zpp_critical=true,s.zpp_i>=o){s.zpp_next=t.phys.BodyIterator.zpp_pool,t.phys.BodyIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=false,e(s.zpp_inner.at(s.zpp_i++));}let i=this.zpp_inner.wrap_compounds;i.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(i);for(;;){l.zpp_inner.zpp_inner.valmod();let r=l.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=false,r.zpp_inner.user_length=r.zpp_inner.inner.length);let o=r.zpp_inner.user_length;if(l.zpp_critical=true,l.zpp_i>=o){l.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=false,l.zpp_inner.at(l.zpp_i++).visitBodies(e);}}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitConstraints");let t=_e(),n=this.zpp_inner.wrap_constraints;n.zpp_inner.valmod();let s=t.constraint.ConstraintIterator.get(n);for(;;){s.zpp_inner.zpp_inner.valmod();let r=s.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=false,r.zpp_inner.user_length=r.zpp_inner.inner.length);let o=r.zpp_inner.user_length;if(s.zpp_critical=true,s.zpp_i>=o){s.zpp_next=t.constraint.ConstraintIterator.zpp_pool,t.constraint.ConstraintIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=false,e(s.zpp_inner.at(s.zpp_i++));}let i=this.zpp_inner.wrap_compounds;i.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(i);for(;;){l.zpp_inner.zpp_inner.valmod();let r=l.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=false,r.zpp_inner.user_length=r.zpp_inner.inner.length);let o=r.zpp_inner.user_length;if(l.zpp_critical=true,l.zpp_i>=o){l.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=false,l.zpp_inner.at(l.zpp_i++).visitConstraints(e);}}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitCompounds");let t=_e(),n=this.zpp_inner.wrap_compounds;n.zpp_inner.valmod();let s=t.phys.CompoundIterator.get(n);for(;;){s.zpp_inner.zpp_inner.valmod();let i=s.zpp_inner;i.zpp_inner.valmod(),i.zpp_inner.zip_length&&(i.zpp_inner.zip_length=false,i.zpp_inner.user_length=i.zpp_inner.inner.length);let l=i.zpp_inner.user_length;if(s.zpp_critical=true,s.zpp_i>=l){s.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=false;let r=s.zpp_inner.at(s.zpp_i++);e(r),r.visitCompounds(e);}}interactionType(e,t){if(e==null||t==null)throw new Error("Error: Cannot evaluate interaction type for null shapes");let n=e.zpp_inner,s=t.zpp_inner;if((n.body!=null?n.body.outer:null)==null||(s.body!=null?s.body.outer:null)==null)throw new Error("Error: Cannot evaluate interaction type for shapes not part of a Body");let i=n.body,l=s.body;if(i.type==1&&l.type==1||i.outer==l.outer)return null;let r=false,o=i.constraints.head;for(;o!=null;){let u=o.elt;if(u.ignore&&u.pair_exists(i.id,l.id)){r=true;break}o=o.next;}let a;if(r)a=false;else {let u=n;for(;u!=null&&u.group==null;)u.ishape!=null?u=u.ishape.body:u.icompound!=null?u=u.icompound.compound:u=u.ibody.compound;let x=u==null?null:u.group,m;if(x==null)m=false;else {let _=s;for(;_!=null&&_.group==null;)_.ishape!=null?_=_.ishape.body:_.icompound!=null?_=_.icompound.compound:_=_.ibody.compound;let y=_==null?null:_.group;if(y==null)m=false;else {let z=false;for(;x!=null&&y!=null;){if(x==y){z=x.ignore;break}x.depth<y.depth?y=y.group:x=x.group;}m=z;}}a=!m;}if(!a)return null;let p=n.filter,c=s.filter,h=i.imass==0&&l.imass==0&&i.iinertia==0&&l.iinertia==0;return (n.sensorEnabled||s.sensorEnabled)&&(p.sensorMask&c.sensorGroup)!=0&&(c.sensorMask&p.sensorGroup)!=0?(J.InteractionType_SENSOR==null&&(J.internal=true,J.InteractionType_SENSOR=new(_e()).callbacks.InteractionType,J.internal=false),J.InteractionType_SENSOR):(n.fluidEnabled||s.fluidEnabled)&&(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0&&!h?(J.InteractionType_FLUID==null&&(J.internal=true,J.InteractionType_FLUID=new(_e()).callbacks.InteractionType,J.internal=false),J.InteractionType_FLUID):(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!h?(J.InteractionType_COLLISION==null&&(J.internal=true,J.InteractionType_COLLISION=new(_e()).callbacks.InteractionType,J.internal=false),J.InteractionType_COLLISION):null}shapesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes under a null point :)");let s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,r=t==null?null:t.zpp_inner??t,o=this.zpp_inner.shapesUnderPoint(i,l,r,n);return s.weak&&e.dispose(),o}bodiesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects under a null point :)");let s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,r=t==null?null:t.zpp_inner??t,o=this.zpp_inner.bodiesUnderPoint(i,l,r,n);return s.weak&&e.dispose(),o}shapesInAABB(e,t=false,n=true,s,i){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null AABB :)");let l=e.zpp_inner;if(l._validate!=null&&l._validate(),l.maxx-l.minx==0||l.maxy-l.miny==0)throw new Error("Error: Cannot evaluate shapes in degenerate AABB :/");let r=s==null?null:s.zpp_inner??s;return this.zpp_inner.shapesInAABB(e,n,t,r,i)}bodiesInAABB(e,t=false,n=true,s,i){if(e==null)throw new Error("Error: Cannot evaluate objects in a null AABB :)");let l=e.zpp_inner;if(l._validate!=null&&l._validate(),l.maxx-l.minx==0||l.maxy-l.miny==0)throw new Error("Error: Cannot evaluate objects in degenerate AABB :/");let r=s==null?null:s.zpp_inner??s;return this.zpp_inner.bodiesInAABB(e,n,t,r,i)}shapesInCircle(e,t,n=false,s,i){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let l=s==null?null:s.zpp_inner??s,r=this.zpp_inner.shapesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),r}bodiesInCircle(e,t,n=false,s,i){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let l=s==null?null:s.zpp_inner??s,r=this.zpp_inner.bodiesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),r}shapesInShape(e,t=false,n,s){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null shapes :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(i.type==1){let r=i.polygon.valid();if(J.ValidationResult_VALID==null&&(J.internal=true,J.ValidationResult_VALID=new(_e()).shape.ValidationResult,J.internal=false),r!=J.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+r.toString())}let l=n==null?null:n.zpp_inner??n;return this.zpp_inner.shapesInShape(i,t,l,s)}bodiesInShape(e,t=false,n,s){if(e==null)throw new Error("Error: Cannot evaluate bodies in a null shapes :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(i.type==1){let r=i.polygon.valid();if(J.ValidationResult_VALID==null&&(J.internal=true,J.ValidationResult_VALID=new(_e()).shape.ValidationResult,J.internal=false),r!=J.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+r.toString())}let l=n==null?null:n.zpp_inner??n;return this.zpp_inner.bodiesInShape(i,t,l,s)}shapesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let s=_e(),i=n??new s.shape.ShapeList,l=e.zpp_inner.wrap_shapes;l.zpp_inner.valmod();let r=s.shape.ShapeIterator.get(l);for(;;){r.zpp_inner.zpp_inner.valmod();let o=r.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=false,o.zpp_inner.user_length=o.zpp_inner.inner.length);let a=o.zpp_inner.user_length;if(r.zpp_critical=true,r.zpp_i>=a){r.zpp_next=s.shape.ShapeIterator.zpp_pool,s.shape.ShapeIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=false;let p=r.zpp_inner.at(r.zpp_i++);this.shapesInShape(p,false,t,i);}return i}bodiesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let s=_e(),i=n??new s.phys.BodyList,l=e.zpp_inner.wrap_shapes;l.zpp_inner.valmod();let r=s.shape.ShapeIterator.get(l);for(;;){r.zpp_inner.zpp_inner.valmod();let o=r.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=false,o.zpp_inner.user_length=o.zpp_inner.inner.length);let a=o.zpp_inner.user_length;if(r.zpp_critical=true,r.zpp_i>=a){r.zpp_next=s.shape.ShapeIterator.zpp_pool,s.shape.ShapeIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=false;let p=r.zpp_inner.at(r.zpp_i++);this.bodiesInShape(p,false,t,i);}return i}convexCast(e,t,n=false,s){if(e==null)throw new Error("Error: Cannot cast null shape :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexCast(i,t,s,n)}convexMultiCast(e,t,n=false,s,i){if(e==null)throw new Error("Error: Cannot cast null shape :)");let l=e.zpp_inner;if((l.body!=null?l.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexMultiCast(l,t,s,n,i)}rayCast(e,t=false,n){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayCast(e,t,n)}rayMultiCast(e,t=false,n,s){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayMultiCast(e,t,n,s)}debugDraw(e,t=gi.ALL){if(e==null)throw new Error("Error: drawer cannot be null for Space::debugDraw");let n=(t&gi.SHAPES)!==0,s=(t&gi.JOINTS)!==0,i=(t&gi.CONTACTS)!==0,l=(t&gi.AABB)!==0,r=(t&gi.CENTER_OF_MASS)!==0,o=(t&gi.VELOCITIES)!==0,a=4283417591,p=4287669422,c=4294948685,h=4289058471,u=4293874512,x=1157627903,m=4294961979,_=4291728344;if(this.visitBodies(y=>{let z=y.zpp_inner,b=z.type===2,Z=z.type===1?p:b?a:c;if(n){let d=z.shapes.head;for(;d!=null;){let f=d.elt;if(f.type===0){let g=f.circle;f.zip_worldCOM&&f.validate_worldCOM();let P=f.worldCOMx,v=f.worldCOMy,N=g.radius,E=z.rot,M=P+Math.cos(E)*N,k=v+Math.sin(E)*N,C={x:P,y:v},S={x:M,y:k};b?e.drawSolidCircle(C,N,S,Z):e.drawCircle(C,N,Z);}else if(f.type===1){let g=f.polygon;g.zip_gverts&&g.validate_gverts();let P=[],v=g.gverts.next;for(;v!=null;)P.push({x:v.x,y:v.y}),v=v.next;P.length>=3&&(b?e.drawSolidPolygon(P,Z):e.drawPolygon(P,Z));}d=d.next;}}if(l&&!z.world){let d=z.aabb,f=d.minx,g=d.miny,P=d.maxx,v=d.maxy;e.drawSegment({x:f,y:g},{x:P,y:g},x),e.drawSegment({x:P,y:g},{x:P,y:v},x),e.drawSegment({x:P,y:v},{x:f,y:v},x),e.drawSegment({x:f,y:v},{x:f,y:g},x);}if(r&&!z.world&&(z.validate_worldCOM(),e.drawPoint({x:z.worldCOMx,y:z.worldCOMy},m)),o&&!z.world&&b){let d=z.posx,f=z.posy;e.drawSegment({x:d,y:f},{x:d+z.velx,y:f+z.vely},_);}}),s&&this.visitConstraints(y=>{if(!y.debugDraw)return;let z=y.zpp_inner,b=z.b1,w=z.b2,Z=z.a1worldx??(b!=null?b.posx:0),d=z.a1worldy??(b!=null?b.posy:0),f=z.a2worldx??(w!=null?w.posx:0),g=z.a2worldy??(w!=null?w.posy:0);e.drawSegment({x:Z,y:d},{x:f,y:g},h),e.drawPoint({x:Z,y:d},h),e.drawPoint({x:f,y:g},h);}),i){let y=z=>{if(z==null)return;let b=z.head;for(;b!=null;){let w=b.elt;if(w!=null){let Z=w.nx,d=w.ny,f=w.contacts?.next;for(;f!=null;){let g=f.px,P=f.py;e.drawPoint({x:g,y:P},u),e.drawSegment({x:g,y:P},{x:g+Z*8,y:P+d*8},u),f=f.next;}}b=b.next;}};y(this.zpp_inner.c_arbiters_true),y(this.zpp_inner.c_arbiters_false);}}toString(){return `Space(bodies=${this.bodies.length})`}};var zl=class j{constructor(){if(!J.internal)throw new Error("Error: Cannot instantiate BodyType derp!")}static get STATIC(){return J.BodyType_STATIC==null&&(J.internal=true,J.BodyType_STATIC=new j,J.internal=false),J.BodyType_STATIC}static get DYNAMIC(){return J.BodyType_DYNAMIC==null&&(J.internal=true,J.BodyType_DYNAMIC=new j,J.internal=false),J.BodyType_DYNAMIC}static get KINEMATIC(){return J.BodyType_KINEMATIC==null&&(J.internal=true,J.BodyType_KINEMATIC=new j,J.internal=false),J.BodyType_KINEMATIC}toString(){return this===J.BodyType_STATIC?"STATIC":this===J.BodyType_DYNAMIC?"DYNAMIC":this===J.BodyType_KINEMATIC?"KINEMATIC":""}},zo=_e();zo.phys.BodyType=zl;tl();var _s=class j extends vi{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 j?e:e instanceof Wn?ke(e,t=>{let n=Object.create(j.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?j._wrap(e.zpp_inner):ke(e,t=>{let n=Object.create(j.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:xs._wrap(this.zpp_inner.space.outer)}set space(e){if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");this.zpp_inner.immutable_midstep("Compound::space");let t=this.zpp_inner.space==null?null:this.zpp_inner.space.outer;if(t!==e?._inner&&(t?.zpp_inner.wrap_compounds.remove(this),e!=null)){let n=e._inner.zpp_inner.wrap_compounds;n.zpp_inner.reverse_flag?n.push(this):n.unshift(this);}}copy(){return this.zpp_inner.copy()}breakApart(){this.zpp_inner.breakApart();}visitBodies(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitBodies");let t=this.zpp_inner.wrap_bodies,n=t.length;for(let l=0;l<n;l++)e(t.at(l));let s=this.zpp_inner.wrap_compounds,i=s.length;for(let l=0;l<i;l++)s.at(l).visitBodies(e);}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitConstraints");let t=this.zpp_inner.wrap_constraints,n=t.length;for(let l=0;l<n;l++)e(t.at(l));let s=this.zpp_inner.wrap_compounds,i=s.length;for(let l=0;l<i;l++)s.at(l).visitConstraints(e);}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Compound::visitConstraints");let t=this.zpp_inner.wrap_compounds,n=t.length;for(let s=0;s<n;s++){let i=t.at(s);e(i),i.visitCompounds(e);}}COM(e=false){let t=new et(0,0),n=0;if(this.visitBodies(s=>{if(s.zpp_inner.wrap_shapes.zpp_inner.inner.head!=null){if(s.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");s.zpp_inner.wrap_worldCOM==null&&s.zpp_inner.getworldCOM();let l=s.zpp_inner.wrap_worldCOM;if(s.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(s.zpp_inner.validate_mass(),s.zpp_inner.massMode==0&&s.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");let r=s.zpp_inner.cmass;t.addeq(l.mul(r,true)),n+=r;}}),n===0)throw new Error("Error: COM of an empty Compound is undefined silly");return t.muleq(1/n),e&&(t.zpp_inner.weak=true),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=false,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=false,this.visitBodies(s=>{s.rotate(e,t);}),e.zpp_inner.weak=n,e.zpp_inner.weak&&e.dispose(),this}toString(){return "Compound"+this.zpp_inner.id}};Wn._wrapFn=j=>ke(j,e=>{let t=Object.create(_s.prototype);return t.zpp_inner=e,e.outer=t,e.outer_i=t,t.zpp_inner_i=e,t._inner=t,t});Object.defineProperty(_s.prototype,"bodies",{get:function(){return this.zpp_inner.wrap_bodies},configurable:true});Object.defineProperty(_s.prototype,"constraints",{get:function(){return this.zpp_inner.wrap_constraints},configurable:true});Object.defineProperty(_s.prototype,"compounds",{get:function(){return this.zpp_inner.wrap_compounds},configurable:true});var Pl=class j{get _inner(){return this}constructor(e=0,t=1,n=2,s=1,i=.001){let l;if(Oe.zpp_pool==null?l=new Oe:(l=Oe.zpp_pool,Oe.zpp_pool=l.next,l.next=null),this.zpp_inner=l,l.outer=this,e!==l.elasticity){if(e!==e)throw new Error("Error: Material::elasticity cannot be NaN");l.elasticity=e,l.invalidate(Oe.WAKE|Oe.ARBITERS);}if(t!==l.dynamicFriction){if(t!==t)throw new Error("Error: Material::dynamicFriction cannot be NaN");if(t<0)throw new Error("Error: Material::dynamicFriction cannot be negative");l.dynamicFriction=t,l.invalidate(Oe.WAKE|Oe.ANGDRAG|Oe.ARBITERS);}if(n!==l.staticFriction){if(n!==n)throw new Error("Error: Material::staticFriction cannot be NaN");if(n<0)throw new Error("Error: Material::staticFriction cannot be negative");l.staticFriction=n,l.invalidate(Oe.WAKE|Oe.ARBITERS);}if(s!==l.density*1e3){if(s!==s)throw new Error("Error: Material::density cannot be NaN");if(s<0)throw new Error("Error: Material::density must be positive");l.density=s/1e3,l.invalidate(Oe.WAKE|Oe.PROPS);}if(i!==l.rollingFriction){if(i!==i)throw new Error("Error: Material::rollingFriction cannot be NaN");if(i<0)throw new Error("Error: Material::rollingFriction cannot be negative");l.rollingFriction=i,l.invalidate(Oe.WAKE|Oe.ARBITERS);}}static _wrap(e){return e instanceof j?e:e?e instanceof Oe?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?j._wrap(e.zpp_inner):null:null}get elasticity(){return this.zpp_inner.elasticity}set elasticity(e){if(e!==this.zpp_inner.elasticity){if(e!==e)throw new Error("Error: Material::elasticity cannot be NaN");this.zpp_inner.elasticity=e,this.zpp_inner.invalidate(Oe.WAKE|Oe.ARBITERS);}}get dynamicFriction(){return this.zpp_inner.dynamicFriction}set dynamicFriction(e){if(e!==this.zpp_inner.dynamicFriction){if(e!==e)throw new Error("Error: Material::dynamicFriction cannot be NaN");if(e<0)throw new Error("Error: Material::dynamicFriction cannot be negative");this.zpp_inner.dynamicFriction=e,this.zpp_inner.invalidate(Oe.WAKE|Oe.ANGDRAG|Oe.ARBITERS);}}get staticFriction(){return this.zpp_inner.staticFriction}set staticFriction(e){if(e!==this.zpp_inner.staticFriction){if(e!==e)throw new Error("Error: Material::staticFriction cannot be NaN");if(e<0)throw new Error("Error: Material::staticFriction cannot be negative");this.zpp_inner.staticFriction=e,this.zpp_inner.invalidate(Oe.WAKE|Oe.ARBITERS);}}get density(){return this.zpp_inner.density*1e3}set density(e){if(e!==this.zpp_inner.density*1e3){if(e!==e)throw new Error("Error: Material::density cannot be NaN");if(e<0)throw new Error("Error: Material::density must be positive");this.zpp_inner.density=e/1e3,this.zpp_inner.invalidate(Oe.WAKE|Oe.PROPS);}}get rollingFriction(){return this.zpp_inner.rollingFriction}set rollingFriction(e){if(e!==this.zpp_inner.rollingFriction){if(e!==e)throw new Error("Error: Material::rollingFriction cannot be NaN");if(e<0)throw new Error("Error: Material::rollingFriction cannot be negative");this.zpp_inner.rollingFriction=e,this.zpp_inner.invalidate(Oe.WAKE|Oe.ARBITERS);}}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}copy(){let e=new j(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 j(.4,.2,.38,.7,.005)}static steel(){return new j(.2,.57,.74,7.8,.001)}static ice(){return new j(.3,.03,.1,.9,1e-4)}static rubber(){return new j(.8,1,1.4,1.5,.01)}static glass(){return new j(.4,.4,.94,2.6,.002)}static sand(){return new j(-1,.45,.6,1.6,16)}};Oe._wrapFn=j=>ke(j,e=>{let t=Object.create(Pl.prototype);return t.zpp_inner=e,e.outer=t,t});var wl=class j{constructor(){if(!J.internal)throw new Error("Error: Cannot instantiate GravMassMode derp!")}static get DEFAULT(){return J.GravMassMode_DEFAULT==null&&(J.internal=true,J.GravMassMode_DEFAULT=new j,J.internal=false),J.GravMassMode_DEFAULT}static get FIXED(){return J.GravMassMode_FIXED==null&&(J.internal=true,J.GravMassMode_FIXED=new j,J.internal=false),J.GravMassMode_FIXED}static get SCALED(){return J.GravMassMode_SCALED==null&&(J.internal=true,J.GravMassMode_SCALED=new j,J.internal=false),J.GravMassMode_SCALED}toString(){return this===J.GravMassMode_DEFAULT?"DEFAULT":this===J.GravMassMode_FIXED?"FIXED":this===J.GravMassMode_SCALED?"SCALED":""}},Po=_e();Po.phys.GravMassMode=wl;var vl=class j{constructor(){if(!J.internal)throw new Error("Error: Cannot instantiate InertiaMode derp!")}static get DEFAULT(){return J.InertiaMode_DEFAULT==null&&(J.internal=true,J.InertiaMode_DEFAULT=new j,J.internal=false),J.InertiaMode_DEFAULT}static get FIXED(){return J.InertiaMode_FIXED==null&&(J.internal=true,J.InertiaMode_FIXED=new j,J.internal=false),J.InertiaMode_FIXED}toString(){return this===J.InertiaMode_DEFAULT?"DEFAULT":this===J.InertiaMode_FIXED?"FIXED":""}},wo=_e();wo.phys.InertiaMode=vl;var gl=class j{constructor(){if(!J.internal)throw new Error("Error: Cannot instantiate MassMode derp!")}static get DEFAULT(){return J.MassMode_DEFAULT==null&&(J.internal=true,J.MassMode_DEFAULT=new j,J.internal=false),J.MassMode_DEFAULT}static get FIXED(){return J.MassMode_FIXED==null&&(J.internal=true,J.MassMode_FIXED=new j,J.internal=false),J.MassMode_FIXED}toString(){return this===J.MassMode_DEFAULT?"DEFAULT":this===J.MassMode_FIXED?"FIXED":""}},vo=_e();vo.phys.MassMode=gl;var sl=class j extends $n{constructor(e=50,t,n,s){super();let i=_e(),l=new Xn;if(this.zpp_inner_zn=l,this.zpp_inner=l,this.zpp_inner_i=l,l.outer=this,l.outer_zn=this,l.outer_i=this,this._inner=this,e!==l.radius){if(e!==e)throw new Error("Error: Circle::radius cannot be NaN");if(e<i.Config.epsilon)throw new Error("Error: Circle::radius ("+e+") must be > Config.epsilon");if(e>ci.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");l.radius=e,l.invalidate_radius();}if(t!=null){if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=t.zpp_inner;r._validate!=null&&r._validate(),l.localCOMx=r.x,r._validate!=null&&r._validate(),l.localCOMy=r.y,r.weak&&t.dispose();}else l.localCOMx=0,l.localCOMy=0;n==null?Oe.zpp_pool!=null?(l.material=Oe.zpp_pool,Oe.zpp_pool=l.material.next,l.material.next=null):l.material=new Oe:(l.immutable_midstep("Shape::material"),l.setMaterial(n.zpp_inner),l.material.wrapper()),s==null?st.zpp_pool!=null?(l.filter=st.zpp_pool,st.zpp_pool=l.filter.next,l.filter.next=null):l.filter=new st:(l.immutable_midstep("Shape::filter"),l.setFilter(s.zpp_inner),l.filter.wrapper()),l.insert_cbtype(cn.ANY_SHAPE.zpp_inner);}static _wrap(e){return e?e instanceof j?e:e instanceof Xn?ke(e,t=>{let n=Object.create(j.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?j._wrap(e.zpp_inner_zn):ke(e,t=>{let n=Object.create(j.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=_e();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>ci.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius();}}};Gl(j=>sl._wrap(j));var go=_e();go.shape.Circle=sl;var ll=class j extends $n{constructor(e,t,n){super();let s=_e();if(e==null)throw new Error("Error: localVerts cannot be null");let i=new Nn;if(this.zpp_inner_zn=i,this.zpp_inner=i,this.zpp_inner_i=i,i.outer=this,i.outer_zn=this,i.outer_i=this,this._inner=this,Array.isArray(e)){for(let l of e){if(l==null)throw new Error("Error: Array<Vec2> contains null objects");if(!(l instanceof et))throw new Error("Error: Array<Vec2> contains non Vec2 objects");if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.wrap_lverts==null&&i.getlverts();let r=l.zpp_inner;r._validate!=null&&r._validate();let o=r.x;r._validate!=null&&r._validate();let a=r.y,p=new et(o,a);i.wrap_lverts.push(p);}for(let l=e.length-1;l>=0;l--)e[l].zpp_inner?.weak&&(e[l].dispose(),e.splice(l,1));}else if(e instanceof s.geom.Vec2List){let l=e,r=l.iterator();for(;;){r.zpp_inner.zpp_inner.valmod();let c=r.zpp_inner.zpp_gl();if(r.zpp_critical=true,r.zpp_i>=c){r.zpp_next=s.geom.Vec2Iterator.zpp_pool,s.geom.Vec2Iterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=false;let h=r.zpp_inner.at(r.zpp_i++);if(h==null)throw new Error("Error: Vec2List contains null objects");if(h.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.wrap_lverts==null&&i.getlverts();let u=h.zpp_inner;u._validate!=null&&u._validate();let x=u.x;u._validate!=null&&u._validate();let m=u.y,_=new et(x,m);i.wrap_lverts.push(_);}l.zpp_inner._validate!=null&&l.zpp_inner._validate();let o=l.zpp_inner.inner,a=null,p=o.head;for(;p!=null;){let c=p.elt;c.outer?.zpp_inner?.weak?(p=o.erase(a),c.outer.zpp_inner.weak&&c.outer.dispose()):(a=p,p=p.next);}}else if(e instanceof s.geom.GeomPoly){let l=e.zpp_inner.vertices;if(l!=null){let r=l;do{i.wrap_lverts==null&&i.getlverts();let o=new et(r.x,r.y);i.wrap_lverts.push(o),r=r.next;}while(r!==l)}}else throw new Error("Error: Invalid type for polygon object, should be Array<Vec2>, Vec2List, GeomPoly or for flash10+ flash.Vector<Vec2>");t==null?Oe.zpp_pool!=null?(i.material=Oe.zpp_pool,Oe.zpp_pool=i.material.next,i.material.next=null):i.material=new Oe:(i.immutable_midstep("Shape::material"),i.setMaterial(t.zpp_inner),i.material.wrapper()),n==null?st.zpp_pool!=null?(i.filter=st.zpp_pool,st.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new st:(i.immutable_midstep("Shape::filter"),i.setFilter(n.zpp_inner),i.filter.wrapper()),i.insert_cbtype(cn.ANY_SHAPE.zpp_inner);}static _wrap(e){return e?e instanceof j?e:e instanceof Nn?ke(e,t=>{let n=Object.create(j.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?j._wrap(e.zpp_inner_zn):ke(e,t=>{let n=Object.create(j.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i,n}):null}static rect(e,t,n,s,i=false){if(e!==e||t!==t||n!==n||s!==s)throw new Error("Error: Polygon.rect cannot accept NaN arguments");let l=new et(e,t);l.zpp_inner.weak=i;let r=new et(e+n,t);r.zpp_inner.weak=i;let o=new et(e+n,t+s);o.zpp_inner.weak=i;let a=new et(e,t+s);return a.zpp_inner.weak=i,[l,r,o,a]}static box(e,t=e,n=false){if(e!==e||t!==t)throw new Error("Error: Polygon.box cannot accept NaN arguments");return j.rect(-e/2,-t/2,e,t,n)}static regular(e,t,n,s=0,i=false){if(e!==e||t!==t||s!==s)throw new Error("Error: Polygon.regular cannot accept NaN arguments");let l=[],r=Math.PI*2/n;for(let o=0;o<n;o++){let a=o*r+s,p=Math.cos(a)*e,c=Math.sin(a)*t,h=new et(p,c);h.zpp_inner.weak=i,l.push(h);}return l}get localVerts(){return this.zpp_inner_zn.wrap_lverts==null&&this.zpp_inner_zn.getlverts(),this.zpp_inner_zn.wrap_lverts}get worldVerts(){return this.zpp_inner_zn.wrap_gverts==null&&this.zpp_inner_zn.getgverts(),this.zpp_inner_zn.wrap_gverts}get edges(){return this.zpp_inner_zn.wrap_edges==null&&this.zpp_inner_zn.getedges(),this.zpp_inner_zn.wrap_edges}validity(){return this.zpp_inner_zn.valid()}};Rl(j=>ll._wrap(j));var Co=_e();Co.shape.Polygon=ll;var Mo=8;function Ul(j,e,t=Mo){let n=[];for(let s=0;s<=t;s++){let i=-Math.PI/2+Math.PI*s/t;n.push({x:j+e*Math.cos(i),y:e*Math.sin(i)});}for(let s=0;s<=t;s++){let i=Math.PI/2+Math.PI*s/t;n.push({x:-j+e*Math.cos(i),y:e*Math.sin(i)});}return n}var ol=class j extends $n{constructor(e=100,t=40,n,s,i){if(super(),e!==e||t!==t)throw new Error("Error: Capsule dimensions cannot be NaN");if(t<=0)throw new Error("Error: Capsule height ("+t+") must be > 0");if(e<t)throw new Error("Error: Capsule width ("+e+") must be >= height ("+t+")");let l=t/2,r=(e-t)/2;this._radius=l,this._halfLength=r;let o=new Nn;this.zpp_inner_zn=o,this.zpp_inner=o,this.zpp_inner_i=o,o.outer=this,o.outer_zn=this,o.outer_i=this,this._inner=this,o._isCapsule=true,o._capsuleRadius=l,o._capsuleHalfLength=r;let a=0,p=0;if(n!=null){if(n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=n.zpp_inner;h._validate!=null&&h._validate(),a=h.x,h._validate!=null&&h._validate(),p=h.y,h.weak&&n.dispose();}let c=Ul(r,l);o.wrap_lverts==null&&o.getlverts();for(let h of c){let u=new et(h.x+a,h.y+p);o.wrap_lverts.push(u);}s==null?Oe.zpp_pool!=null?(o.material=Oe.zpp_pool,Oe.zpp_pool=o.material.next,o.material.next=null):o.material=new Oe:(o.immutable_midstep("Shape::material"),o.setMaterial(s.zpp_inner),o.material.wrapper()),i==null?st.zpp_pool!=null?(o.filter=st.zpp_pool,st.zpp_pool=o.filter.next,o.filter.next=null):o.filter=new st:(o.immutable_midstep("Shape::filter"),o.setFilter(i.zpp_inner),o.filter.wrapper()),o.insert_cbtype(cn.ANY_SHAPE.zpp_inner);}static _wrap(e){return e?e instanceof j?e:e instanceof Nn&&e._isCapsule?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner_zn=t,n.zpp_inner=t,n.zpp_inner_i=t,n._radius=t._capsuleRadius??0,n._halfLength=t._capsuleHalfLength??0,t.outer=n,t.outer_zn=n,t.outer_i=n,n._inner=n,n}):e.zpp_inner_zn?j._wrap(e.zpp_inner_zn):ke(e,t=>{let n=Object.create(j.prototype);return n._inner=t,n.zpp_inner_i=t.zpp_inner_i,n._radius=t._capsuleRadius??0,n._halfLength=t._capsuleHalfLength??0,n}):null}get type(){return Ts.CAPSULE}isPolygon(){return false}isCapsule(){return true}get radius(){return this.zpp_inner_zn._capsuleRadius??this._radius}set radius(e){let t=this.zpp_inner_zn,n=_e();if(this.zpp_inner.immutable_midstep("Capsule::radius"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modify radius of Capsule contained in static object once added to space");if(e!==this._radius){if(e!==e)throw new Error("Error: Capsule::radius cannot be NaN");if(e<n.Config.epsilon)throw new Error("Error: Capsule::radius ("+e+") must be > Config.epsilon");this._radius=e,t._capsuleRadius=e,this._regenerateVertices();}}get halfLength(){return this.zpp_inner_zn._capsuleHalfLength??this._halfLength}set halfLength(e){let t=this.zpp_inner_zn;if(this.zpp_inner.immutable_midstep("Capsule::halfLength"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modify halfLength of Capsule contained in static object once added to space");if(e!==this._halfLength){if(e!==e)throw new Error("Error: Capsule::halfLength cannot be NaN");if(e<0)throw new Error("Error: Capsule::halfLength ("+e+") must be >= 0");this._halfLength=e,t._capsuleHalfLength=e,this._regenerateVertices();}}_regenerateVertices(){let e=this.zpp_inner_zn;e.validate_localCOM();let t=e.localCOMx,n=e.localCOMy;for(e.wrap_lverts==null&&e.getlverts();e.wrap_lverts.length>0;)e.wrap_lverts.pop();let s=Ul(this._halfLength,this._radius);for(let i of s){let l=new et(i.x+t,i.y+n);e.wrap_lverts.push(l);}}get width(){return 2*(this.halfLength+this.radius)}get height(){return 2*this.radius}};ql(j=>ol._wrap(j));var Zo=_e();Zo.shape.Capsule=ol;var Kl=class j{constructor(){if(!J.internal)throw new Error("Error: Cannot instantiate Broadphase derp!")}static get DYNAMIC_AABB_TREE(){return J.Broadphase_DYNAMIC_AABB_TREE==null&&(J.internal=true,J.Broadphase_DYNAMIC_AABB_TREE=new j,J.internal=false),J.Broadphase_DYNAMIC_AABB_TREE}static get SWEEP_AND_PRUNE(){return J.Broadphase_SWEEP_AND_PRUNE==null&&(J.internal=true,J.Broadphase_SWEEP_AND_PRUNE=new j,J.internal=false),J.Broadphase_SWEEP_AND_PRUNE}static get SPATIAL_HASH(){return J.Broadphase_SPATIAL_HASH==null&&(J.internal=true,J.Broadphase_SPATIAL_HASH=new j,J.internal=false),J.Broadphase_SPATIAL_HASH}toString(){return this===J.Broadphase_DYNAMIC_AABB_TREE?"DYNAMIC_AABB_TREE":this===J.Broadphase_SWEEP_AND_PRUNE?"SWEEP_AND_PRUNE":this===J.Broadphase_SPATIAL_HASH?"SPATIAL_HASH":""}};var Cl=class j{get _inner(){return this}constructor(e=1,t=-1,n=1,s=-1,i=1,l=-1){let r;st.zpp_pool==null?r=new st:(r=st.zpp_pool,st.zpp_pool=r.next,r.next=null),this.zpp_inner=r,r.outer=this,r.collisionGroup!=e&&(r.collisionGroup=e,r.invalidate()),r.collisionMask!=t&&(r.collisionMask=t,r.invalidate()),r.sensorGroup!=n&&(r.sensorGroup=n,r.invalidate()),r.sensorMask!=s&&(r.sensorMask=s,r.invalidate()),r.fluidGroup!=i&&(r.fluidGroup=i,r.invalidate()),r.fluidMask!=l&&(r.fluidMask=l,r.invalidate());}static _wrap(e){return e instanceof j?e:e?e instanceof st?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?j._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=_e();this.zpp_inner.wrap_shapes=e.zpp_nape.util.ZPP_ShapeList.get(this.zpp_inner.shapes,true);}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 j(this.zpp_inner.collisionGroup,this.zpp_inner.collisionMask,this.zpp_inner.sensorGroup,this.zpp_inner.sensorMask,this.zpp_inner.fluidGroup,this.zpp_inner.fluidMask)}toString(){let e=(t,n)=>{let s="",i="0123456789ABCDEF",l=t;do s=i.charAt(l&15)+s,l>>>=4;while(l>0);for(;s.length<n;)s="0"+s;return s};return "{ collision: "+e(this.zpp_inner.collisionGroup,8)+"~"+e(this.zpp_inner.collisionMask,8)+" sensor: "+e(this.zpp_inner.sensorGroup,8)+"~"+e(this.zpp_inner.sensorMask,8)+" fluid: "+e(this.zpp_inner.fluidGroup,8)+"~"+e(this.zpp_inner.fluidMask,8)+" }"}};st._wrapFn=j=>ke(j,e=>{let t=Object.create(Cl.prototype);return t.zpp_inner=e,e.outer=t,t});var Wi=class Wi{constructor(){this.debugDraw=true;this._inner=this;}static _wrap(e){return e==null?null:e instanceof Wi?e:e.zpp_inner?.outer instanceof Wi?e.zpp_inner.outer:ke(e,t=>{let n=Object.create(Wi.prototype);return n.zpp_inner=t.zpp_inner??t,n._inner=t,n.zpp_inner.outer=n,n.debugDraw=t.debugDraw??true,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=false),this.zpp_inner.clearcache(),this.zpp_inner.space!=null&&this.zpp_inner.space.wrap_constraints.remove(this),e!=null){let s=(e._inner?.zpp_inner??e.zpp_inner).wrap_constraints;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this);}else this.zpp_inner.space=null;}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(e){let t=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(t!=e&&(t?.zpp_inner.wrap_constraints.remove(this),e!=null)){let s=e.zpp_inner.wrap_constraints;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this);}}get active(){return this.zpp_inner.active}set active(e){this.zpp_inner.active!=e&&(this.zpp_inner.component!=null&&(this.zpp_inner.component.woken=false),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=true),this.zpp_inner.space.wake_constraint(this.zpp_inner,true))):(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 Wi._wrap(this.zpp_inner.copy())}toString(){return "{Constraint}"}};Wi.zpp_internalAlloc=false;var on=Wi;var Ml=class j extends on{constructor(e,t,n,s,i=1){super();let l=new Re;if(this.zpp_inner=l,l.outer=this,l.outer_zn=this,this._setBody1(e),this._setBody2(t),this.zpp_inner.immutable_midstep("AngleJoint::jointMin"),n!==n)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(l.jointMin!=n&&(l.jointMin=n,l.wake()),this.zpp_inner.immutable_midstep("AngleJoint::jointMax"),s!==s)throw new Error("Error: AngleJoint::jointMax cannot be NaN");if(l.jointMax!=s&&(l.jointMax=s,l.wake()),this.zpp_inner.immutable_midstep("AngleJoint::ratio"),i!==i)throw new Error("Error: AngleJoint::ratio cannot be NaN");l.ratio!=i&&(l.ratio=i,l.wake());}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof Re?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=true,n}):ke(e,t=>{let n=Object.create(j.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:nt._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:nt._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=_e(),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=_e();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n);}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e;}};Re._wrapFn=j=>ke(j,e=>{let t=Object.create(Ml.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=true,t});function Yl(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Hl(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.y}function rl(j){j.zpp_inner.weak&&j.dispose();}var Zl=class j extends on{constructor(e,t,n,s,i,l){super();let r=new xi;if(this.zpp_inner=r,r.outer=this,r.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");let o=Yl(n),a=Hl(n);if(r.a1localx=o,r.a1localy=a,rl(n),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::anchor2 cannot be null");let p=Yl(s),c=Hl(s);if(r.a2localx=p,r.a2localy=c,rl(s),this.zpp_inner.immutable_midstep("DistanceJoint::jointMin"),i!==i)throw new Error("Error: DistanceJoint::jointMin cannot be NaN");if(i<0)throw new Error("Error: DistanceJoint::jointMin must be >= 0");if(r.jointMin!=i&&(r.jointMin=i,r.wake()),this.zpp_inner.immutable_midstep("DistanceJoint::jointMax"),l!==l)throw new Error("Error: DistanceJoint::jointMax cannot be NaN");if(l<0)throw new Error("Error: DistanceJoint::jointMax must be >= 0");r.jointMax!=l&&(r.jointMax=l,r.wake());}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof xi?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=true,n}):ke(e,t=>{let n=Object.create(j.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:nt._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:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e);}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()));}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),rl(e);}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),rl(e);}get 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=_e(),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=_e();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n);}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e;}};xi._wrapFn=j=>ke(j,e=>{let t=Object.create(Zl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=true,t});function kl(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.x}function El(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.y}function ds(j){j.zpp_inner.weak&&j.dispose();}var Nl=class j extends on{constructor(e,t,n,s,i,l,r){super();let o=new _i;if(this.zpp_inner=o,o.outer=this,o.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(o.a1localx=kl(n),o.a1localy=El(n),ds(n),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::anchor2 cannot be null");if(o.a2localx=kl(s),o.a2localy=El(s),ds(s),i?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i==null)throw new Error("Error: Constraint::direction cannot be null");if(o.nlocalx=kl(i),o.nlocaly=El(i),o.zip_n=true,ds(i),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),l!==l)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(o.jointMin!=l&&(o.jointMin=l,o.wake()),this.zpp_inner.immutable_midstep("LineJoint::jointMax"),r!==r)throw new Error("Error: AngleJoint::jointMax cannot be NaN");o.jointMax!=r&&(o.jointMax=r,o.wake());}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof _i?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=true,n}):ke(e,t=>{let n=Object.create(j.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:nt._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:nt._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),ds(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),ds(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),ds(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=_e(),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=_e();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n);}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e;}};_i._wrapFn=j=>ke(j,e=>{let t=Object.create(Nl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=true,t});var Ol=class j extends on{constructor(e,t,n=0,s=1){super();let i=new di;if(this.zpp_inner=i,i.outer=this,i.outer_zn=this,this._setBody1(e),this._setBody2(t),this.zpp_inner.immutable_midstep("MotorJoint::rate"),n!==n)throw new Error("Error: MotorJoint::rate cannot be NaN");if(i.rate!=n&&(i.rate=n,i.wake()),this.zpp_inner.immutable_midstep("MotorJoint::ratio"),s!==s)throw new Error("Error: MotorJoint::ratio cannot be NaN");i.ratio!=s&&(i.ratio=s,i.wake());}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof di?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=true,n}):ke(e,t=>{let n=Object.create(j.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:nt._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:nt._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=_e(),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=_e();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n);}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e;}};di._wrapFn=j=>ke(j,e=>{let t=Object.create(Ol.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=true,t});function Xl(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Ql(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.y}function al(j){j.zpp_inner.weak&&j.dispose();}var Sl=class j extends on{constructor(e,t,n,s){super();let i=new yi;if(this.zpp_inner=i,i.outer=this,i.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(i.a1localx=Xl(n),i.a1localy=Ql(n),al(n),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::anchor2 cannot be null");i.a2localx=Xl(s),i.a2localy=Ql(s),al(s);}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof yi?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=true,n}):ke(e,t=>{let n=Object.create(j.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:nt._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:nt._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),al(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),al(e);}impulse(){let e=_e(),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=_e();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n);}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e;}};yi._wrapFn=j=>ke(j,e=>{let t=Object.create(Sl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=true,t});function Gs(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Rs(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.y}function qs(j){j.zpp_inner.weak&&j.dispose();}var Al=class j extends on{constructor(e,t,n,s,i,l,r,o,a,p,c=1){super();let h=new mi;if(this.zpp_inner=h,h.outer=this,h.outer_zn=this,this._setBody1(e),this._setBody2(t),this._setBody3(n),this._setBody4(s),this._setAnchorInit(i,"anchor1",(u,x)=>{h.a1localx=u,h.a1localy=x;}),this._setAnchorInit(l,"anchor2",(u,x)=>{h.a2localx=u,h.a2localy=x;}),this._setAnchorInit(r,"anchor3",(u,x)=>{h.a3localx=u,h.a3localy=x;}),this._setAnchorInit(o,"anchor4",(u,x)=>{h.a4localx=u,h.a4localy=x;}),h.immutable_midstep("PulleyJoint::jointMin"),a!==a)throw new Error("Error: PulleyJoint::jointMin cannot be NaN");if(a<0)throw new Error("Error: PulleyJoint::jointMin must be >= 0");if(h.jointMin!=a&&(h.jointMin=a,h.wake()),h.immutable_midstep("PulleyJoint::jointMax"),p!==p)throw new Error("Error: PulleyJoint::jointMax cannot be NaN");if(p<0)throw new Error("Error: PulleyJoint::jointMax must be >= 0");if(h.jointMax!=p&&(h.jointMax=p,h.wake()),h.immutable_midstep("PulleyJoint::ratio"),c!==c)throw new Error("Error: PulleyJoint::ratio cannot be NaN");h.ratio!=c&&(h.ratio=c,h.wake());}_setAnchorInit(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::"+t+" cannot be null");n(Gs(e),Rs(e)),qs(e);}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof mi?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=true,n}):ke(e,t=>{let n=Object.create(j.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:nt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e);}get body2(){return this.zpp_inner.b2==null?null:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e);}get body3(){return this.zpp_inner.b3==null?null:nt._wrap(this.zpp_inner.b3)}set body3(e){this._setBody3(e);}get body4(){return this.zpp_inner.b4==null?null:nt._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(),Gs(e),Rs(e),this.zpp_inner.wrap_a1.set(e),qs(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(),Gs(e),Rs(e),this.zpp_inner.wrap_a2.set(e),qs(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(),Gs(e),Rs(e),this.zpp_inner.wrap_a3.set(e),qs(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(),Gs(e),Rs(e),this.zpp_inner.wrap_a4.set(e),qs(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 As(1,1);if(0>=e.zpp_inner.m||0>=e.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return e.zpp_inner.x[0*e.zpp_inner.n]=this.zpp_inner.jAcc,e}bodyImpulse(e){if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let t=this.zpp_inner.b1?.outer??null,n=this.zpp_inner.b2?.outer??null,s=this.zpp_inner.b3?.outer??null,i=this.zpp_inner.b4?.outer??null;if(e!=t&&e!=n&&e!=s&&e!=i)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):ai.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1?.outer??null,n=this.zpp_inner.b2?.outer??null,s=this.zpp_inner.b3?.outer??null,i=this.zpp_inner.b4?.outer??null;t!=null&&e(t),n!=null&&n!=t&&e(n),s!=null&&s!=t&&s!=n&&e(s),i!=null&&i!=t&&i!=n&&i!=s&&e(i);}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e;}};mi._wrapFn=j=>ke(j,e=>{let t=Object.create(Al.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=true,t});function $l(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.x}function eo(j){if(j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=j.zpp_inner;return e._validate!=null&&e._validate(),e.y}function pl(j){j.zpp_inner.weak&&j.dispose();}var Vl=class j extends on{constructor(e,t,n,s,i=0){super();let l=new bi;if(this.zpp_inner=l,l.outer=this,l.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(l.a1localx=$l(n),l.a1localy=eo(n),pl(n),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::anchor2 cannot be null");if(l.a2localx=$l(s),l.a2localy=eo(s),pl(s),this.zpp_inner.immutable_midstep("WeldJoint::phase"),i!==i)throw new Error("Error: WeldJoint::phase cannot be NaN");l.phase!=i&&(l.phase=i,l.wake());}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof bi?ke(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=true,n}):ke(e,t=>{let n=Object.create(j.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:nt._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:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e);}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()));}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),pl(e);}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),pl(e);}get 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=_e(),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=_e();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n);}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e;}};bi._wrapFn=j=>ke(j,e=>{let t=Object.create(Vl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=true,t});exports.$=zl;exports.A=Es;exports.B=Qs;exports.C=Cn;exports.D=rt;exports.E=_e;exports.F=tl;exports.G=ke;exports.H=et;exports.I=ai;exports.J=As;exports.K=qi;exports.L=yl;exports.M=hs;exports.N=Dl;exports.O=Fl;exports.P=kx;exports.Q=Ex;exports.R=vi;exports.S=nl;exports.T=pi;exports.U=Ts;exports.V=$n;exports.W=gi;exports.X=xs;exports._=nt;exports.a=J;exports.aa=_s;exports.b=xe;exports.ba=Pl;exports.ca=wl;exports.d=Tt;exports.da=vl;exports.e=cn;exports.ea=gl;exports.f=Lt;exports.fa=sl;exports.g=Ks;exports.ga=ll;exports.h=Ys;exports.ha=ol;exports.i=Hs;exports.ia=Kl;exports.j=es;exports.ja=Cl;exports.k=Re;exports.ka=on;exports.l=ae;exports.la=Ml;exports.m=xi;exports.ma=Zl;exports.n=_i;exports.na=Nl;exports.o=di;exports.oa=Ol;exports.p=yi;exports.pa=Sl;exports.q=mi;exports.qa=Al;exports.r=Xs;exports.ra=Vl;exports.s=bi;exports.t=Ie;exports.u=we;exports.v=Zs;exports.w=ge;exports.x=bn;exports.y=ss;exports.z=ks;//# sourceMappingURL=chunk-KHH45HMB.cjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-KHH45HMB.cjs.map
|