@newkrok/nape-js 3.13.7 → 3.13.8
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.
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var Dn=class{static POSINF(){return 1/0}static NEGINF(){return-1/0}};Dn.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 dn=gt;var U=class{};U.GravMassMode_DEFAULT=null,U.GravMassMode_FIXED=null,U.GravMassMode_SCALED=null,U.InertiaMode_DEFAULT=null,U.InertiaMode_FIXED=null,U.MassMode_DEFAULT=null,U.MassMode_FIXED=null,U.BodyType_STATIC=null,U.BodyType_DYNAMIC=null,U.BodyType_KINEMATIC=null,U.ListenerType_BODY=null,U.ListenerType_CONSTRAINT=null,U.ListenerType_INTERACTION=null,U.ListenerType_PRE=null,U.PreFlag_ACCEPT=null,U.PreFlag_IGNORE=null,U.PreFlag_ACCEPT_ONCE=null,U.PreFlag_IGNORE_ONCE=null,U.CbEvent_BEGIN=null,U.CbEvent_ONGOING=null,U.CbEvent_END=null,U.CbEvent_WAKE=null,U.CbEvent_SLEEP=null,U.CbEvent_BREAK=null,U.CbEvent_PRE=null,U.InteractionType_COLLISION=null,U.InteractionType_SENSOR=null,U.InteractionType_FLUID=null,U.InteractionType_ANY=null,U.Winding_UNDEFINED=null,U.Winding_CLOCKWISE=null,U.Winding_ANTICLOCKWISE=null,U.ValidationResult_VALID=null,U.ValidationResult_DEGENERATE=null,U.ValidationResult_CONCAVE=null,U.ValidationResult_SELF_INTERSECTING=null,U.ShapeType_CIRCLE=null,U.ShapeType_POLYGON=null,U.ShapeType_CAPSULE=null,U.Broadphase_DYNAMIC_AABB_TREE=null,U.Broadphase_SWEEP_AND_PRUNE=null,U.ArbiterType_COLLISION=null,U.ArbiterType_SENSOR=null,U.ArbiterType_FLUID=null,U.internal=!1,U.id_ImmState_ACCEPT=1,U.id_ImmState_IGNORE=2,U.id_ImmState_ALWAYS=4,U.id_GravMassMode_DEFAULT=0,U.id_GravMassMode_FIXED=1,U.id_GravMassMode_SCALED=2,U.id_InertiaMode_DEFAULT=0,U.id_InertiaMode_FIXED=1,U.id_MassMode_DEFAULT=0,U.id_MassMode_FIXED=1,U.id_BodyType_STATIC=1,U.id_BodyType_DYNAMIC=2,U.id_BodyType_KINEMATIC=3,U.id_ListenerType_BODY=0,U.id_ListenerType_CONSTRAINT=1,U.id_ListenerType_INTERACTION=2,U.id_ListenerType_PRE=3,U.id_PreFlag_ACCEPT=1,U.id_PreFlag_IGNORE=2,U.id_PreFlag_ACCEPT_ONCE=3,U.id_PreFlag_IGNORE_ONCE=4,U.id_CbEvent_BEGIN=0,U.id_CbEvent_END=1,U.id_CbEvent_WAKE=2,U.id_CbEvent_SLEEP=3,U.id_CbEvent_BREAK=4,U.id_CbEvent_PRE=5,U.id_CbEvent_ONGOING=6,U.id_InteractionType_COLLISION=1,U.id_InteractionType_SENSOR=2,U.id_InteractionType_FLUID=4,U.id_InteractionType_ANY=7,U.id_Winding_UNDEFINED=0,U.id_Winding_CLOCKWISE=1,U.id_Winding_ANTICLOCKWISE=2,U.id_ValidationResult_VALID=0,U.id_ValidationResult_DEGENERATE=1,U.id_ValidationResult_CONCAVE=2,U.id_ValidationResult_SELF_INTERSECTING=3,U.id_ShapeType_CIRCLE=0,U.id_ShapeType_POLYGON=1,U.id_ShapeType_CAPSULE=2,U.id_Broadphase_DYNAMIC_AABB_TREE=0,U.id_Broadphase_SWEEP_AND_PRUNE=1,U.id_ArbiterType_COLLISION=1,U.id_ArbiterType_SENSOR=2,U.id_ArbiterType_FLUID=4;var Js=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}},Ki=class extends ys{},Yi=class extends ys{},Xi=class extends ys{};var Pn=class Pn{constructor(){this.value=!1;this.next=null;this.hnext=null;this.id=0;this.di=0}static _alloc(){if(Pn.zpp_pool==null)return new Pn;let e=Pn.zpp_pool;return Pn.zpp_pool=e.next,e.next=null,e}static get(e,t,n){let s=Pn._alloc();return s.id=e,s.di=t,s.value=n,s}static getpersist(e,t){let n=Pn._alloc();return n.id=e,n.di=t,n}static ordered_get(e,t,n){if(e<=t){let s=Pn._alloc();return s.id=e,s.di=t,s.value=n,s}else{let s=Pn._alloc();return s.id=t,s.di=e,s.value=n,s}}static ordered_get_persist(e,t){if(e<=t){let n=Pn._alloc();return n.id=e,n.di=t,n}else{let n=Pn._alloc();return n.id=t,n.di=e,n}}free(){}alloc(){}};Pn.zpp_pool=null;var Be=Pn;var eo=1048576,Ei=1048575,Ni=106039,Oi=class{constructor(){this.cnt=0;this.cnt=0,this.table=new Array(eo).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*Ni+t&Ei];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*Ni+t&Ei];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*Ni+t&Ei];if(n==null)return!1;if(n.id==e&&n.di==t)return!0;for(;n=n.hnext,n!=null&&(n.id!=e||n.di!=t););return n!=null}maybeAdd(e){let t=e.id*Ni+e.di&Ei,n=this.table[t],s=!0;n==null?(this.table[t]=e,e.hnext=null):s&&(e.hnext=n.hnext,n.hnext=e),s&&this.cnt++}add(e){let t=e.id*Ni+e.di&Ei,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*Ni+e.di&Ei,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*Ni+t&Ei}};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=!1;this.pushmod=!1}_allocNode(){let e=this.constructor._NodeClass,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor._NodeClass;e.elt=null,e.next=t.zpp_pool,t.zpp_pool=e}begin(){return this.head}setbegin(e){this.head=e,this.modified=!0,this.pushmod=!0}add(e){let t=this._allocNode();return t.elt=e,t.next=this.head,this.head=t,this.modified=!0,this.length++,e}addAll(e){let t=e.head;for(;t!=null;)this.add(t.elt),t=t.next}insert(e,t){let n=this._allocNode();return n.elt=t,e==null?(n.next=this.head,this.head=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.head.elt;return this.pop(),e}erase(e){let t,n;return e==null?(t=this.head,n=t.next,this.head=n,this.head==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),this._freeNode(t),this.modified=!0,this.length--,this.pushmod=!0,n}remove(e){let t=null,n=this.head;for(;n!=null;){if(n.elt==e){this.erase(t);break}t=n,n=n.next}}try_remove(e){let t=null,n=this.head,s=!1;for(;n!=null;){if(n.elt==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){for(;this.head!=null;){let e=this.head;this.head=e.next,this._freeNode(e),this.head==null&&(this.pushmod=!0),this.modified=!0,this.length--}this.pushmod=!0}reverse(){let e=this.head,t=null;for(;e!=null;){let n=e.next;e.next=t,this.head=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.head==null}size(){return this.length}has(e){let t=this.head;for(;t!=null;){if(t.elt==e)return!0;t=t.next}return!1}front(){return this.head.elt}back(){let e=this.head,t=e;for(;t!=null;)e=t,t=t.next;return e.elt}iterator_at(e){let t=this.head;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t!=null?t.elt:null}};_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 fs=class{constructor(){this.colour=0;this.parent=null;this.next=null;this.prev=null;this.data=null;this.swapped=null;this.lt=null}_allocNode(){let e=this.constructor,t;return e.zpp_pool==null?t=new e:(t=e.zpp_pool,e.zpp_pool=t.next,t.next=null),t}_freeNode(e){let t=this.constructor;e.data=null,e.lt=null,e.swapped=null,e.next=t.zpp_pool,t.zpp_pool=e}free(){this.data=null,this.lt=null,this.swapped=null}alloc(){}verify(){if(!this.empty()){let e=this.parent;for(;e.prev!=null;)e=e.prev;for(;e!=null;){let t=e.data,n=!0;if(!this.empty()){let s=this.parent;for(;s.prev!=null;)s=s.prev;for(;s!=null;){let i=s.data;if(n){if(t==i)n=!1;else if(!this.lt(i,t)&&this.lt(t,i))return!1}else if(!this.lt(t,i)&&this.lt(i,t))return!1;if(s.next!=null)for(s=s.next;s.prev!=null;)s=s.prev;else{for(;s.parent!=null&&s==s.parent.next;)s=s.parent;s=s.parent}}}if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{for(;e.parent!=null&&e==e.parent.next;)e=e.parent;e=e.parent}}}return!0}empty(){return this.parent==null}singular(){return this.parent!=null&&this.parent.prev==null?this.parent.next==null:!1}size(){let e=0;if(!this.empty()){let t=this.parent;for(;t.prev!=null;)t=t.prev;for(;t!=null;)if(++e,t.next!=null)for(t=t.next;t.prev!=null;)t=t.prev;else{for(;t.parent!=null&&t==t.parent.next;)t=t.parent;t=t.parent}}return e}has(e){return this.find(e)!=null}find(e){let t=this.parent;for(;t!=null&&t.data!=e;)this.lt(e,t.data)?t=t.prev:t=t.next;return t}has_weak(e){return this.find_weak(e)!=null}find_weak(e){let t=this.parent;for(;t!=null;)if(this.lt(e,t.data))t=t.prev;else if(this.lt(t.data,e))t=t.next;else break;return t}lower_bound(e){let t=null;if(!this.empty()){let n=this.parent;for(;n.prev!=null;)n=n.prev;for(;n!=null;){if(!this.lt(n.data,e)){t=n.data;break}if(n.next!=null)for(n=n.next;n.prev!=null;)n=n.prev;else{for(;n.parent!=null&&n==n.parent.next;)n=n.parent;n=n.parent}}}return t}first(){let e=this.parent;for(;e.prev!=null;)e=e.prev;return e.data}pop_front(){let e=this.parent;for(;e.prev!=null;)e=e.prev;let t=e.data;return this.remove_node(e),t}remove(e){this.remove_node(this.find(e))}successor_node(e){if(e.next!=null)for(e=e.next;e.prev!=null;)e=e.prev;else{let t=e;for(e=e.parent;e!=null&&e.prev!=t;)t=e,e=e.parent}return e}predecessor_node(e){if(e.prev!=null)for(e=e.prev;e.next!=null;)e=e.next;else{let t=e;for(e=e.parent;e!=null&&e.next!=t;)t=e,e=e.parent}return e}successor(e){let t=this.successor_node(this.find(e));return t==null?null:t.data}predecessor(e){let t=this.predecessor_node(this.find(e));return t==null?null:t.data}remove_node(e){if(e.next!=null&&e.prev!=null){let s=e.next;for(;s.prev!=null;)s=s.prev;let i=e.data;e.data=s.data,s.data=i,this.swapped!=null&&this.swapped(e.data,s.data),e=s}let t=e.prev==null?e.next:e.prev;if(e.colour==1){if(e.prev!=null||e.next!=null)t.colour=1;else if(e.parent!=null){let s=e.parent;for(;;){s.colour++,s.prev.colour--,s.next.colour--;let i=s.prev;if(i.colour==-1){this.__fix_neg_red(i);break}else if(i.colour==0){if(i.prev!=null&&i.prev.colour==0){this.__fix_dbl_red(i.prev);break}if(i.next!=null&&i.next.colour==0){this.__fix_dbl_red(i.next);break}}let l=s.next;if(l.colour==-1){this.__fix_neg_red(l);break}else if(l.colour==0){if(l.prev!=null&&l.prev.colour==0){this.__fix_dbl_red(l.prev);break}if(l.next!=null&&l.next.colour==0){this.__fix_dbl_red(l.next);break}}if(s.colour==2)if(s.parent==null)s.colour=1;else{s=s.parent;continue}break}}}let n=e.parent;n==null?this.parent=t:n.prev==e?n.prev=t:n.next=t,t!=null&&(t.parent=n),e.parent=e.prev=e.next=null,this._freeNode(e)}clear(){if(this.parent!=null){let e=this.parent;for(;e!=null;)if(e.prev!=null)e=e.prev;else if(e.next!=null)e=e.next;else{let t=e.parent;t!=null&&(e==t.prev?t.prev=null:t.next=null,e.parent=null),this._freeNode(e),e=t}this.parent=null}}clear_with(e){if(this.parent==null)return;let t=this.parent;for(;t!=null;)if(t.prev!=null)t=t.prev;else if(t.next!=null)t=t.next;else{e(t.data);let n=t.parent;n!=null&&(t==n.prev?n.prev=null:n.next=null,t.parent=null),this._freeNode(t),t=n}this.parent=null}clear_node(e,t){t(e.data);let n=e.parent;return n!=null&&(e==n.prev?n.prev=null:n.next=null,e.parent=null),this._freeNode(e),n}__fix_neg_red(e){let t=e.parent,n;if(t.prev==e){let s=e.prev,i=e.next,l=i.prev,o=i.next;s.colour=0,e.colour=t.colour=1,e.next=l,l!=null&&(l.parent=e);let r=t.data;t.data=i.data,i.data=r,this.swapped!=null&&this.swapped(t.data,i.data),i.prev=o,o!=null&&(o.parent=i),i.next=t.next,t.next!=null&&(t.next.parent=i),t.next=i,i!=null&&(i.parent=t),n=s}else{let s=e.next,i=e.prev,l=i.next,o=i.prev;s.colour=0,e.colour=t.colour=1,e.prev=l,l!=null&&(l.parent=e);let r=t.data;t.data=i.data,i.data=r,this.swapped!=null&&this.swapped(t.data,i.data),i.next=o,o!=null&&(o.parent=i),i.prev=t.prev,t.prev!=null&&(t.prev.parent=i),t.prev=i,i!=null&&(i.parent=t),n=s}n.prev!=null&&n.prev.colour==0?this.__fix_dbl_red(n.prev):n.next!=null&&n.next.colour==0&&this.__fix_dbl_red(n.next)}__fix_dbl_red(e){for(;;){let t=e.parent,n=t.parent;if(n==null){t.colour=1;break}let s,i,l,o,r,a,p;t==n.prev?(l=n,p=n.next,e==t.prev?(s=e,i=t,o=e.prev,r=e.next,a=t.next):(s=t,i=e,o=t.prev,r=e.prev,a=e.next)):(s=n,o=n.prev,e==t.prev?(i=e,l=t,r=e.prev,a=e.next,p=t.next):(i=t,l=e,r=t.prev,a=e.prev,p=e.next));let c=n.parent;if(c==null?this.parent=i:c.prev==n?c.prev=i:c.next=i,i!=null&&(i.parent=c),s.prev=o,o!=null&&(o.parent=s),s.next=r,r!=null&&(r.parent=s),i.prev=s,s!=null&&(s.parent=i),i.next=l,l!=null&&(l.parent=i),l.prev=a,a!=null&&(a.parent=l),l.next=p,p!=null&&(p.parent=l),i.colour=n.colour-1,s.colour=1,l.colour=1,i==this.parent)this.parent.colour=1;else if(i.colour==0&&i.parent.colour==0){e=i;continue}break}}try_insert_bool(e){let t=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else{let n=this.parent;for(;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break}return t==null?!1:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),!0)}try_insert(e){let t=null,n=null;if(this.parent==null)t=this._allocNode(),t.data=e,this.parent=t;else for(n=this.parent;;)if(this.lt(e,n.data))if(n.prev==null){t=this._allocNode(),t.data=e,n.prev=t,t.parent=n;break}else n=n.prev;else if(this.lt(n.data,e))if(n.next==null){t=this._allocNode(),t.data=e,n.next=t,t.parent=n;break}else n=n.next;else break;return t==null?n:(t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t)}insert(e){let t=this._allocNode();if(t.data=e,this.parent==null)this.parent=t;else{let n=this.parent;for(;;)if(this.lt(t.data,n.data))if(n.prev==null){n.prev=t,t.parent=n;break}else n=n.prev;else if(n.next==null){n.next=t,t.parent=n;break}else n=n.next}return t.parent==null?t.colour=1:(t.colour=0,t.parent.colour==0&&this.__fix_dbl_red(t)),t}};fs.zpp_pool=null;var xi=null,Si=null,Fn=null,ul=null,to=null,xl=null,Hi=null,$t=null,Qi=null,Un=null,$i=null,es=null,_l=null,no=null,io=null,so=null,lo=null,oo=null,ro=null,ao=null,po=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 ui(j){let e=class extends fs{};return e.zpp_pool=null,e}function jl(j){j.util||(j.util={}),j.util.ZNPNode_ZPP_CbType=qe("ZPP_CbType"),j.util.ZNPNode_ZPP_CallbackSet=qe("ZPP_CallbackSet"),j.util.ZNPNode_ZPP_Shape=qe("ZPP_Shape"),j.util.ZNPNode_ZPP_Body=qe("ZPP_Body"),j.util.ZNPNode_ZPP_Constraint=qe("ZPP_Constraint"),j.util.ZNPNode_ZPP_Compound=qe("ZPP_Compound"),j.util.ZNPNode_ZPP_Arbiter=qe("ZPP_Arbiter"),j.util.ZNPNode_ZPP_InteractionListener=qe("ZPP_InteractionListener"),j.util.ZNPNode_ZPP_CbSet=qe("ZPP_CbSet"),j.util.ZNPNode_ZPP_Interactor=qe("ZPP_Interactor"),j.util.ZNPNode_ZPP_BodyListener=qe("ZPP_BodyListener"),j.util.ZNPNode_ZPP_CbSetPair=qe("ZPP_CbSetPair"),j.util.ZNPNode_ZPP_ConstraintListener=qe("ZPP_ConstraintListener"),j.util.ZNPNode_ZPP_CutInt=qe("ZPP_CutInt"),j.util.ZNPNode_ZPP_CutVert=qe("ZPP_CutVert"),j.util.ZNPNode_ZPP_PartitionVertex=qe("ZPP_PartitionVertex"),j.util.ZNPNode_ZPP_SimplifyP=qe("ZPP_SimplifyP"),j.util.ZNPNode_ZPP_PartitionedPoly=qe("ZPP_PartitionedPoly"),j.util.ZNPNode_ZPP_GeomVert=qe("ZPP_GeomVert"),j.util.ZNPNode_ZPP_SimpleVert=qe("ZPP_SimpleVert"),j.util.ZNPNode_ZPP_SimpleEvent=qe("ZPP_SimpleEvent"),j.util.ZNPNode_ZPP_Vec2=qe("ZPP_Vec2"),j.util.ZNPNode_ZPP_AABBPair=qe("ZPP_AABBPair"),j.util.ZNPNode_ZPP_Edge=qe("ZPP_Edge"),j.util.ZNPNode_ZPP_AABBNode=qe("ZPP_AABBNode"),j.util.ZNPNode_ZPP_Component=qe("ZPP_Component"),j.util.ZNPNode_ZPP_FluidArbiter=qe("ZPP_FluidArbiter"),j.util.ZNPNode_ZPP_SensorArbiter=qe("ZPP_SensorArbiter"),j.util.ZNPNode_ZPP_Listener=qe("ZPP_Listener"),j.util.ZNPNode_ZPP_ColArbiter=qe("ZPP_ColArbiter"),j.util.ZNPNode_ZPP_InteractionGroup=qe("ZPP_InteractionGroup"),j.util.ZNPNode_ZPP_ToiEvent=qe("ZPP_ToiEvent"),j.util.ZNPNode_ConvexResult=qe("ConvexResult"),j.util.ZNPNode_ZPP_GeomPoly=qe("ZPP_GeomPoly"),j.util.ZNPNode_RayResult=qe("RayResult");let e=j.util;io=j.util.ZNPList_ZPP_InteractionListener=We("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),so=j.util.ZNPList_ZPP_BodyListener=We("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),lo=j.util.ZNPList_ZPP_ConstraintListener=We("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),oo=j.util.ZNPList_ZPP_Constraint=We("ZPP_Constraint",e.ZNPNode_ZPP_Constraint),ro=j.util.ZNPList_ZPP_Interactor=We("ZPP_Interactor",e.ZNPNode_ZPP_Interactor),ao=j.util.ZNPList_ZPP_CbSet=We("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),no=j.util.ZNPList_ZPP_CbType=We("ZPP_CbType",e.ZNPNode_ZPP_CbType),j.util.ZNPList_ZPP_Vec2=We("ZPP_Vec2",e.ZNPNode_ZPP_Vec2),to=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),po=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),xi=j.util.ZNPList_ZPP_PartitionVertex,j.util.ZNPList_ZPP_SimplifyP=We("ZPP_SimplifyP",e.ZNPNode_ZPP_SimplifyP),ul=j.util.ZNPList_ZPP_SimplifyP,j.util.ZNPList_ZPP_PartitionedPoly=We("ZPP_PartitionedPoly",e.ZNPNode_ZPP_PartitionedPoly),Si=j.util.ZNPList_ZPP_PartitionedPoly,j.util.ZNPList_ZPP_GeomVert=We("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),Fn=j.util.ZNPList_ZPP_GeomVert,j.util.ZNPList_ZPP_SimpleVert=We("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),_l=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,xl=j.util.ZNPList_ZPP_SimpleVert,j.util.ZPP_Set_ZPP_Body=ui("ZPP_Body"),j.util.ZPP_Set_ZPP_CbSetPair=ui("ZPP_CbSetPair"),j.util.ZPP_Set_ZPP_PartitionVertex=ui("ZPP_PartitionVertex"),$i=j.util.ZPP_Set_ZPP_PartitionVertex,j.util.ZPP_Set_ZPP_PartitionPair=ui("ZPP_PartitionPair"),es=j.util.ZPP_Set_ZPP_PartitionPair,j.util.ZPP_Set_ZPP_SimpleVert=ui("ZPP_SimpleVert"),$t=j.util.ZPP_Set_ZPP_SimpleVert,j.util.ZPP_Set_ZPP_SimpleSeg=ui("ZPP_SimpleSeg"),Qi=j.util.ZPP_Set_ZPP_SimpleSeg,j.util.ZPP_Set_ZPP_SimpleEvent=ui("ZPP_SimpleEvent"),Un=j.util.ZPP_Set_ZPP_SimpleEvent,j.util.ZPP_Set_ZPP_CbSet=ui("ZPP_CbSet")}var zt=class zt{constructor(){this.outer_body=null;this.outer_con=null;this.outer_int=null;this.event=0;this.listener=null;this.space=null;this.index=0;this.next=null;this.prev=null;this.length=0;this.int1=null;this.int2=null;this.set=null;this.wrap_arbiters=null;this.pre_arbiter=null;this.pre_swapped=!1;this.body=null;this.constraint=null}wrapper_body(){return this.outer_body==null&&(zt.internal=!0,this.outer_body=zt._createBodyCb(),zt.internal=!1,this.outer_body.zpp_inner=this),this.outer_body}wrapper_con(){return this.outer_con==null&&(zt.internal=!0,this.outer_con=zt._createConCb(),zt.internal=!1,this.outer_con.zpp_inner=this),this.outer_con}wrapper_int(){let e=zt._zpp;return this.outer_int==null&&(zt.internal=!0,this.outer_int=zt._createIntCb(),zt.internal=!1,this.outer_int.zpp_inner=this),this.wrap_arbiters==null?this.wrap_arbiters=e.util.ZPP_ArbiterList.get(this.set.arbiters,!0):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=!0,this.wrap_arbiters.zpp_inner.at_ite=null,this.outer_int}push(e){this.prev!=null?this.prev.next=e:this.next=e,e.prev=this.prev,e.next=null,this.prev=e,this.length++}push_rev(e){this.next!=null?this.next.prev=e:this.prev=e,e.next=this.next,e.prev=null,this.next=e,this.length++}pop(){let e=this.next;return this.next=e.next,this.next==null?this.prev=null:this.next.prev=null,this.length--,e}pop_rev(){let e=this.prev;return this.prev=e.prev,this.prev==null?this.next=null:this.prev.next=null,this.length--,e}empty(){return this.next==null}clear(){for(;!this.empty();)this.pop()}splice(e){let t=e.next;return e.prev==null?(this.next=e.next,this.next!=null?this.next.prev=null:this.prev=null):(e.prev.next=e.next,e.next!=null?e.next.prev=e.prev:this.prev=e.prev),this.length--,t}rotateL(){this.push(this.pop())}rotateR(){this.push_rev(this.pop_rev())}cycleNext(e){return e.next==null?this.next:e.next}cyclePrev(e){return e.prev==null?this.prev:e.prev}at(e){let t=this.next;for(;e--!=0;)t=t.next;return t}rev_at(e){let t=this.prev;for(;e--!=0;)t=t.prev;return t}free(){this.int1=this.int2=null,this.body=null,this.constraint=null,this.listener=null,this.wrap_arbiters!=null&&(this.wrap_arbiters.zpp_inner.inner=null),this.set=null}alloc(){}genarbs(){let e=zt._zpp;this.wrap_arbiters==null?this.wrap_arbiters=e.util.ZPP_ArbiterList.get(this.set.arbiters,!0):this.wrap_arbiters.zpp_inner.inner=this.set.arbiters,this.wrap_arbiters.zpp_inner.zip_length=!0,this.wrap_arbiters.zpp_inner.at_ite=null}};zt._nape=null,zt._zpp=null,zt.internal=!1,zt.zpp_pool=null,zt._createBodyCb=null,zt._createConCb=null,zt._createIntCb=null,zt._createPreCb=null;var Tt=zt;var Wt=class Wt{constructor(){this.count=0;this.next=null;this.id=0;this.manager=null;this.cbpairs=null;this.zip_listeners=!1;this.zip_bodylisteners=!1;this.zip_conlisteners=!1;this.interactors=null;this.wrap_interactors=null;this.constraints=null;this.wrap_constraints=null;let e=Wt._zpp;this.cbTypes=new e.util.ZNPList_ZPP_CbType,this.listeners=new e.util.ZNPList_ZPP_InteractionListener,this.zip_listeners=!0,this.bodylisteners=new e.util.ZNPList_ZPP_BodyListener,this.zip_bodylisteners=!0,this.conlisteners=new e.util.ZNPList_ZPP_ConstraintListener,this.zip_conlisteners=!0,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.interactors=new e.util.ZNPList_ZPP_Interactor,this.id=e.ZPP_ID.CbSet(),this.cbpairs=new e.util.ZNPList_ZPP_CbSetPair}static setlt(e,t){let n=e.cbTypes.head,s=t.cbTypes.head;for(;n!=null&&s!=null;){let i=n.elt,l=s.elt;if(i.id<l.id)return!0;if(l.id<i.id)return!1;n=n.next,s=s.next}return s!=null?n==null:!1}static get(e){let t;Wt.zpp_pool==null?t=new Wt:(t=Wt.zpp_pool,Wt.zpp_pool=t.next,t.next=null);let n=null,s=e.head;for(;s!=null;){let i=s.elt;n=t.cbTypes.insert(n,i),i.cbsets.add(t),s=s.next}return t}static compatible(e,t,n){let s,i=e.options1,l=t.cbTypes;if(i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)){let o=e.options2,r=n.cbTypes;s=o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)}else s=!1;if(s)return!0;{let o=e.options2,r=t.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=e.options1,p=n.cbTypes;return a.nonemptyintersection(p,a.includes)?!a.nonemptyintersection(p,a.excludes):!1}else return!1}}static findOrCreatePair(e,t){let n=Wt._zpp,s=null,l=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;l!=null;){let o=l.elt;if(o.a==e&&o.b==t||o.a==t&&o.b==e){s=o;break}l=l.next}if(s==null){let o;n.callbacks.ZPP_CbSetPair.zpp_pool==null?o=new n.callbacks.ZPP_CbSetPair:(o=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=o.next,o.next=null),o.zip_listeners=!0,Wt.setlt(e,t)?(o.a=e,o.b=t):(o.a=t,o.b=e),s=o,e.cbpairs.add(s),t!=e&&t.cbpairs.add(s)}return s.zip_listeners&&(s.zip_listeners=!1,s.__validate()),s}static empty_intersection(e,t){return Wt.findOrCreatePair(e,t).listeners.head==null}static single_intersection(e,t,n){let i=Wt.findOrCreatePair(e,t).listeners.head;return i!=null&&i.elt==n?i.next==null:!1}static find_all(e,t,n,s){let l=Wt.findOrCreatePair(e,t).listeners.head;for(;l!=null;){let o=l.elt;o.event==n&&s(o),l=l.next}}increment(){this.count++}decrement(){return--this.count==0}invalidate_pairs(){let e=this.cbpairs.head;for(;e!=null;){let t=e.elt;t.zip_listeners=!0,e=e.next}}invalidate_listeners(){this.zip_listeners=!0,this.invalidate_pairs()}validate_listeners(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners())}realvalidate_listeners(){let e=Wt._zpp;this.listeners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.listeners.head,l=n.listeners.head;for(;l!=null;){let o=l.elt;if(i!=null&&i.elt==o)l=l.next,s=i,i=i.next;else{let r;if(i!=null){let a=i.elt;r=o.precedence>a.precedence||o.precedence==a.precedence&&o.id>a.id}else r=!0;if(r){if(o.space==this.manager.space){let a=this.listeners,p;e.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?p=new e.util.ZNPNode_ZPP_InteractionListener:(p=e.util.ZNPNode_ZPP_InteractionListener.zpp_pool,e.util.ZNPNode_ZPP_InteractionListener.zpp_pool=p.next,p.next=null),p.elt=o;let c=p;s==null?(c.next=a.head,a.head=c):(c.next=s.next,s.next=c),a.pushmod=a.modified=!0,a.length++,s=c}l=l.next}else s=i,i=i.next}}t=t.next}}invalidate_bodylisteners(){this.zip_bodylisteners=!0}validate_bodylisteners(){this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners())}realvalidate_bodylisteners(){let e=Wt._zpp;this.bodylisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.bodylisteners.head,l=n.bodylisteners.head;for(;l!=null;){let o=l.elt;if(i!=null&&i.elt==o)l=l.next,s=i,i=i.next;else{let r;if(i!=null){let a=i.elt;r=o.precedence>a.precedence||o.precedence==a.precedence&&o.id>a.id}else r=!0;if(r){let a=o.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&o.space==this.manager.space){let p=this.bodylisteners,c;e.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_BodyListener:(c=e.util.ZNPNode_ZPP_BodyListener.zpp_pool,e.util.ZNPNode_ZPP_BodyListener.zpp_pool=c.next,c.next=null),c.elt=o;let h=c;s==null?(h.next=p.head,p.head=h):(h.next=s.next,s.next=h),p.pushmod=p.modified=!0,p.length++,s=h}l=l.next}else s=i,i=i.next}}t=t.next}}invalidate_conlisteners(){this.zip_conlisteners=!0}validate_conlisteners(){this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}realvalidate_conlisteners(){let e=Wt._zpp;this.conlisteners.clear();let t=this.cbTypes.head;for(;t!=null;){let n=t.elt,s=null,i=this.conlisteners.head,l=n.conlisteners.head;for(;l!=null;){let o=l.elt;if(i!=null&&i.elt==o)l=l.next,s=i,i=i.next;else{let r;if(i!=null){let a=i.elt;r=o.precedence>a.precedence||o.precedence==a.precedence&&o.id>a.id}else r=!0;if(r){let a=o.options;if(!a.nonemptyintersection(this.cbTypes,a.excludes)&&o.space==this.manager.space){let p=this.conlisteners,c;e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?c=new e.util.ZNPNode_ZPP_ConstraintListener:(c=e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,e.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=c.next,c.next=null),c.elt=o;let h=c;s==null?(h.next=p.head,p.head=h):(h.next=s.next,s.next=h),p.pushmod=p.modified=!0,p.length++,s=h}l=l.next}else s=i,i=i.next}}t=t.next}}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.realvalidate_listeners()),this.zip_bodylisteners&&(this.zip_bodylisteners=!1,this.realvalidate_bodylisteners()),this.zip_conlisteners&&(this.zip_conlisteners=!1,this.realvalidate_conlisteners())}addConstraint(e){this.constraints.add(e)}addInteractor(e){this.interactors.add(e)}remConstraint(e){this.constraints.remove(e)}remInteractor(e){this.interactors.remove(e)}free(){for(this.listeners.clear(),this.zip_listeners=!0,this.bodylisteners.clear(),this.zip_bodylisteners=!0,this.conlisteners.clear(),this.zip_conlisteners=!0;this.cbTypes.head!=null;)this.cbTypes.pop_unsafe().cbsets.remove(this)}alloc(){}};Wt._zpp=null,Wt.zpp_pool=null;var dt=Wt;var Gn=class Gn{constructor(){this.a=null;this.b=null;this.next=null;this.zip_listeners=!1;this.listeners=null;let e=Gn._zpp;this.listeners=new e.util.ZNPList_ZPP_InteractionListener}static get(e,t){let n=Gn._zpp,s;return Gn.zpp_pool==null?s=new Gn:(s=Gn.zpp_pool,Gn.zpp_pool=s.next,s.next=null),s.zip_listeners=!0,n.callbacks.ZPP_CbSet.setlt(e,t)?(s.a=e,s.b=t):(s.a=t,s.b=e),s}static setlt(e,t){let n=Gn._zpp;return n.callbacks.ZPP_CbSet.setlt(e.a,t.a)?!0:e.a==t.a?n.callbacks.ZPP_CbSet.setlt(e.b,t.b):!1}free(){this.a=this.b=null,this.listeners.clear()}alloc(){this.zip_listeners=!0}compatible(e){let t,n=e.options1,s=this.a.cbTypes;if(n.nonemptyintersection(s,n.includes)&&!n.nonemptyintersection(s,n.excludes)){let i=e.options2,l=this.b.cbTypes;t=i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)}else t=!1;if(t)return!0;{let i=e.options2,l=this.a.cbTypes;if(i.nonemptyintersection(l,i.includes)&&!i.nonemptyintersection(l,i.excludes)){let o=e.options1,r=this.b.cbTypes;return o.nonemptyintersection(r,o.includes)?!o.nonemptyintersection(r,o.excludes):!1}else return!1}}invalidate(){this.zip_listeners=!0}validate(){this.zip_listeners&&(this.zip_listeners=!1,this.__validate())}__validate(){this.listeners.clear();let e=this.a.listeners.head,t=this.b.listeners.head;for(;e!=null&&t!=null;){let n=e.elt,s=t.elt;if(n==s){let i,l,o=n.options1,r=this.a.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=n.options2,p=this.b.cbTypes;l=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else l=!1;if(l)i=!0;else{let a=n.options2,p=this.a.cbTypes;if(a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)){let c=n.options1,h=this.b.cbTypes;i=c.nonemptyintersection(h,c.includes)&&!c.nonemptyintersection(h,c.excludes)}else i=!1}i&&this.listeners.add(n),e=e.next,t=t.next}else n.precedence>s.precedence||n.precedence==s.precedence&&n.id>s.id?e=e.next:t=t.next}}empty_intersection(){return this.listeners.head==null}single_intersection(e){let t=this.listeners.head;return t!=null&&t.elt==e?t.next==null:!1}forall(e,t){let n=this.listeners.head;for(;n!=null;){let s=n.elt;s.event==e&&t(s),n=n.next}}};Gn._zpp=null,Gn.zpp_pool=null;var Ne=Gn;var an=class an{constructor(){this.outer=null;this.userData=null;this.id=0;this.cbsets=null;this.interactors=null;this.wrap_interactors=null;this.constraints=null;this.wrap_constraints=null;this.listeners=null;this.bodylisteners=null;this.conlisteners=null;let e=an._zpp;this.id=e.ZPP_ID.CbType(),this.listeners=new e.util.ZNPList_ZPP_InteractionListener,this.bodylisteners=new e.util.ZNPList_ZPP_BodyListener,this.conlisteners=new e.util.ZNPList_ZPP_ConstraintListener,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.interactors=new e.util.ZNPList_ZPP_Interactor,this.cbsets=new e.util.ZNPList_ZPP_CbSet}static _initEnums(e){an.ANY_SHAPE=new e.callbacks.CbType,an.ANY_BODY=new e.callbacks.CbType,an.ANY_COMPOUND=new e.callbacks.CbType,an.ANY_CONSTRAINT=new e.callbacks.CbType}static setlt(e,t){return e.id<t.id}addInteractor(e){this.interactors.add(e)}remInteractor(e){this.interactors.remove(e)}addConstraint(e){this.constraints.add(e)}remConstraint(e){this.constraints.remove(e)}addint(e){let t=an._zpp,n=null,s=this.listeners.head;for(;s!=null;){let r=s.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.id)break;n=s,s=s.next}let i=this.listeners,l;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_InteractionListener:(l=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++;let o=this.cbsets.head;for(;o!=null;)o.elt.zip_listeners=!0,o.elt.invalidate_pairs(),o=o.next}removeint(e){this.listeners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_listeners=!0,t.elt.invalidate_pairs(),t=t.next}invalidateint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_listeners=!0,e.elt.invalidate_pairs(),e=e.next}addbody(e){let t=an._zpp,n=null,s=this.bodylisteners.head;for(;s!=null;){let r=s.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.id)break;n=s,s=s.next}let i=this.bodylisteners,l;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_BodyListener:(l=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++;let o=this.cbsets.head;for(;o!=null;)o.elt.zip_bodylisteners=!0,o=o.next}removebody(e){this.bodylisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_bodylisteners=!0,t=t.next}invalidatebody(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_bodylisteners=!0,e=e.next}addconstraint(e){let t=an._zpp,n=null,s=this.conlisteners.head;for(;s!=null;){let r=s.elt;if(e.precedence>r.precedence||e.precedence===r.precedence&&e.id>r.id)break;n=s,s=s.next}let i=this.conlisteners,l;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?l=new t.util.ZNPNode_ZPP_ConstraintListener:(l=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=l.next,l.next=null),l.elt=e,n==null?(l.next=i.head,i.head=l):(l.next=n.next,n.next=l),i.pushmod=i.modified=!0,i.length++;let o=this.cbsets.head;for(;o!=null;)o.elt.zip_conlisteners=!0,o=o.next}removeconstraint(e){this.conlisteners.remove(e);let t=this.cbsets.head;for(;t!=null;)t.elt.zip_conlisteners=!0,t=t.next}invalidateconstraint(){let e=this.cbsets.head;for(;e!=null;)e.elt.zip_conlisteners=!0,e=e.next}};an._zpp=null,an.ANY_SHAPE=null,an.ANY_BODY=null,an.ANY_COMPOUND=null,an.ANY_CONSTRAINT=null;var pn=an;var ii=class ii{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=dn.Listener()}static setlt(e,t){return e.precedence<=t.precedence?e.precedence==t.precedence?e.id>t.id:!1:!0}swapEvent(e){}invalidate_precedence(){}addedToSpace(){}removedFromSpace(){}static _initEnums(e,t){let n=()=>{t.internal=!0;let i=new e.callbacks.ListenerType;return t.internal=!1,i};t.ListenerType_BODY==null&&(t.ListenerType_BODY=n()),t.ListenerType_CONSTRAINT==null&&(t.ListenerType_CONSTRAINT=n()),t.ListenerType_INTERACTION==null&&(t.ListenerType_INTERACTION=n()),t.ListenerType_PRE==null&&(t.ListenerType_PRE=n()),ii.types=[t.ListenerType_BODY,t.ListenerType_CONSTRAINT,t.ListenerType_INTERACTION,t.ListenerType_PRE];let s=()=>{t.internal=!0;let i=new e.callbacks.CbEvent;return t.internal=!1,i};t.CbEvent_BEGIN==null&&(t.CbEvent_BEGIN=s()),t.CbEvent_END==null&&(t.CbEvent_END=s()),t.CbEvent_WAKE==null&&(t.CbEvent_WAKE=s()),t.CbEvent_SLEEP==null&&(t.CbEvent_SLEEP=s()),t.CbEvent_BREAK==null&&(t.CbEvent_BREAK=s()),t.CbEvent_PRE==null&&(t.CbEvent_PRE=s()),t.CbEvent_ONGOING==null&&(t.CbEvent_ONGOING=s()),ii.events=[t.CbEvent_BEGIN,t.CbEvent_END,t.CbEvent_WAKE,t.CbEvent_SLEEP,t.CbEvent_BREAK,t.CbEvent_PRE,t.CbEvent_ONGOING]}};ii._nape=null,ii._zpp=null,ii.internal=!1,ii.types=[],ii.events=[];var Lt=ii;var Us=class extends Lt{constructor(t,n,s){super();this.handler=null;this.options=null;this.outer_zn=null;this.event=n,this.handler=s,this.body=this,this.type=0,this.options=t.zpp_inner}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=Lt._zpp;this.options.handler=(s,i,l)=>this.cbtype_change(s,i,l);let n=this.options.includes.head;for(;n!=null;){let s=n.elt,i=null,l=s.bodylisteners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next}let o=s.bodylisteners,r;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?r=new t.util.ZNPNode_ZPP_BodyListener:(r=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=r.next,r.next=null),r.elt=this;let a=r;i==null?(a.next=o.head,o.head=a):(a.next=i.next,i.next=a),o.pushmod=o.modified=!0,o.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_bodylisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.bodylisteners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_bodylisteners=!0,s=s.next}t=t.next}this.options.handler=null}cbtype_change(t,n,s){this.removedFromSpace();let i=this.options;n?s?i.effect_change(t,!0,!0):i.includes.remove(t):s?i.effect_change(t,!1,!0):i.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3)throw new Error("Error: BodyListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};var 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.constraint=this,this.type=1,this.options=t.zpp_inner}immutable_options(){if(this.space!=null&&this.space.midstep)throw new Error("Error: Cannot change listener type options during space.step()")}addedToSpace(){let t=Lt._zpp;this.options.handler=(s,i,l)=>this.cbtype_change(s,i,l);let n=this.options.includes.head;for(;n!=null;){let s=n.elt,i=null,l=s.conlisteners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next}let o=s.conlisteners,r;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?r=new t.util.ZNPNode_ZPP_ConstraintListener:(r=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=r.next,r.next=null),r.elt=this;let a=r;i==null?(a.next=o.head,o.head=a):(a.next=i.next,i.next=a),o.pushmod=o.modified=!0,o.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_conlisteners=!0,p=p.next}n=n.next}}removedFromSpace(){let t=this.options.includes.head;for(;t!=null;){let n=t.elt;n.conlisteners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_conlisteners=!0,s=s.next}t=t.next}this.options.handler=null}cbtype_change(t,n,s){this.removedFromSpace();let i=this.options;n?s?i.effect_change(t,!0,!0):i.includes.remove(t):s?i.effect_change(t,!1,!0):i.excludes.remove(t),this.addedToSpace()}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}swapEvent(t){if(t!=2&&t!=3&&t!=4)throw new Error("Error: ConstraintListener event must be either WAKE or SLEEP only");this.removedFromSpace(),this.event=t,this.addedToSpace()}};var Ct=class Ct extends Lt{constructor(t,n,s,i){super();this.outer_zni=null;this.outer_znp=null;this.itype=0;this.handleri=null;this.allowSleepingCallbacks=!1;this.pure=!1;this.handlerp=null;this.type=i,this.interaction=this,this.event=s,this.options1=t.zpp_inner,this.options2=n.zpp_inner,this.allowSleepingCallbacks=!1}setInteractionType(t){this.itype=t}wake(){let t=this.options1.includes.head,n=this.options2.includes.head;for(;t!=null&&n!=null;){let s=t.elt,i=n.elt;if(s==i){let l=s.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;t=t.next,n=n.next}else if(s.id<i.id){let l=s.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;t=t.next}else{let l=i.interactors.head;for(;l!=null;)l.elt.wake(),l=l.next;n=n.next}}for(;t!=null;){let s=t.elt.interactors.head;for(;s!=null;)s.elt.wake(),s=s.next;t=t.next}for(;n!=null;){let s=n.elt.interactors.head;for(;s!=null;)s.elt.wake(),s=s.next;n=n.next}}CbSetset(t,n,s){let i=Lt._zpp,l=Ct.UCbSet,o=Ct.VCbSet,r=Ct.WCbSet,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,h=p.elt;if(c==h){let u=this._allocCbSetNode(i);u.elt=c,u.next=r.head,r.head=u,r.modified=!0,r.length++,a=a.next,p=p.next}else if(i.callbacks.ZPP_CbSet.setlt(c,h)){let u=this._allocCbSetNode(i);u.elt=c,u.next=l.head,l.head=u,l.modified=!0,l.length++,a=a.next}else{let u=this._allocCbSetNode(i);u.elt=h,u.next=o.head,o.head=u,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbSetNode(i);c.elt=a.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,a=a.next}for(;p!=null;){let c=this._allocCbSetNode(i);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.length++,p=p.next}for(;l.head!=null;){let c=l.pop_unsafe(),h=n.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;o.head!=null;){let c=o.pop_unsafe(),h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe();s(c,c);let h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}}CbTypeset(t,n,s){let i=Lt._zpp,l=Ct.UCbType,o=Ct.VCbType,r=Ct.WCbType,a=t.head,p=n.head;for(;a!=null&&p!=null;){let c=a.elt,h=p.elt;if(c==h){let u=this._allocCbTypeNode(i);u.elt=c,u.next=r.head,r.head=u,r.modified=!0,r.length++,a=a.next,p=p.next}else if(c.id<h.id){let u=this._allocCbTypeNode(i);u.elt=c,u.next=l.head,l.head=u,l.modified=!0,l.length++,a=a.next}else{let u=this._allocCbTypeNode(i);u.elt=h,u.next=o.head,o.head=u,o.modified=!0,o.length++,p=p.next}}for(;a!=null;){let c=this._allocCbTypeNode(i);c.elt=a.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,a=a.next}for(;p!=null;){let c=this._allocCbTypeNode(i);c.elt=p.elt,c.next=o.head,o.head=c,o.modified=!0,o.length++,p=p.next}for(;l.head!=null;){let c=l.pop_unsafe(),h=n.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;o.head!=null;){let c=o.pop_unsafe(),h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;r.head!=null;){let c=r.pop_unsafe();s(c,c);let h=r.head;for(;h!=null;)s(c,h.elt),h=h.next}}with_uniquesets(t){let n=Lt._zpp,s;if(n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool==null?s=new n.util.ZPP_Set_ZPP_CbSetPair:(s=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=s.next,s.next=null),s.lt=n.callbacks.ZPP_CbSetPair.setlt,this.CbTypeset(this.options1.includes,this.options2.includes,(l,o)=>{this.CbSetset(l.cbsets,o.cbsets,(r,a)=>{if(r.validate(),a.validate(),n.callbacks.ZPP_CbSet.single_intersection(r,a,this)){let p;n.callbacks.ZPP_CbSetPair.zpp_pool==null?p=new n.callbacks.ZPP_CbSetPair:(p=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=p.next,p.next=null),p.zip_listeners=!0,n.callbacks.ZPP_CbSet.setlt(r,a)?(p.a=r,p.b=a):(p.a=a,p.b=r),s.try_insert(p)}})}),s.parent!=null){let l=s.parent;for(;l!=null;)if(l.prev!=null)l=l.prev;else if(l.next!=null)l=l.next;else{let o=l.data;t?this.space.freshListenerType(o.a,o.b):this.space.nullListenerType(o.a,o.b);let r=o;r.a=r.b=null,r.listeners.clear(),r.next=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=r;let a=l.parent;a!=null&&(l==a.prev?a.prev=null:a.next=null,l.parent=null);let p=l;p.data=null,p.lt=null,p.swapped=null,p.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=p,l=a}s.parent=null}let i=s;i.data=null,i.lt=null,i.swapped=null,i.next=n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool,n.util.ZPP_Set_ZPP_CbSetPair.zpp_pool=i}with_union(t){let n=this.options1.includes.head,s=this.options2.includes.head;for(;n!=null&&s!=null;){let i=n.elt,l=s.elt;i==l?(t(i),n=n.next,s=s.next):i.id<l.id?(t(i),n=n.next):(t(l),s=s.next)}for(;n!=null;)t(n.elt),n=n.next;for(;s!=null;)t(s.elt),s=s.next}addedToSpace(){let t=Lt._zpp,n=this.type==3;this.with_union(s=>{let i=null,l=s.listeners.head;for(;l!=null;){let c=l.elt;if(this.precedence>c.precedence||this.precedence==c.precedence&&this.id>c.id)break;i=l,l=l.next}let o=s.listeners,r;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?r=new t.util.ZNPNode_ZPP_InteractionListener:(r=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=r.next,r.next=null),r.elt=this;let a=r;i==null?(a.next=o.head,o.head=a):(a.next=i.next,i.next=a),o.pushmod=o.modified=!0,o.length++;let p=s.cbsets.head;for(;p!=null;){let c=p.elt;c.zip_listeners=!0,c.invalidate_pairs(),p=p.next}if(n){let c=s.interactors.head;for(;c!=null;)c.elt.wake(),c=c.next}}),this.options1.handler=(s,i,l)=>this.cbtype_change1(s,i,l),this.options2.handler=(s,i,l)=>this.cbtype_change2(s,i,l),this.with_uniquesets(!0)}removedFromSpace(){this.with_uniquesets(!1);let t=this.type==3;this.with_union(n=>{n.listeners.remove(this);let s=n.cbsets.head;for(;s!=null;){let i=s.elt;i.zip_listeners=!0,i.invalidate_pairs(),s=s.next}if(t){let i=n.interactors.head;for(;i!=null;)i.elt.wake(),i=i.next}}),this.options1.handler=null,this.options2.handler=null}invalidate_precedence(){this.space!=null&&(this.removedFromSpace(),this.addedToSpace())}cbtype_change1(t,n,s){this.cbtype_change(this.options1,t,n,s)}cbtype_change2(t,n,s){this.cbtype_change(this.options2,t,n,s)}cbtype_change(t,n,s,i){this.removedFromSpace(),s?i?t.effect_change(n,!0,!0):t.includes.remove(n):i?t.effect_change(n,!1,!0):t.excludes.remove(n),this.addedToSpace()}swapEvent(t){if(this.type==3)throw new Error("Error: PreListener event can only be PRE");if(t!=0&&t!=1&&t!=6)throw new Error("Error: InteractionListener event must be either BEGIN, END, ONGOING");this.removedFromSpace(),this.event=t,this.addedToSpace()}_allocCbSetNode(t){let n;return t.util.ZNPNode_ZPP_CbSet.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbSet:(n=t.util.ZNPNode_ZPP_CbSet.zpp_pool,t.util.ZNPNode_ZPP_CbSet.zpp_pool=n.next,n.next=null),n}_allocCbTypeNode(t){let n;return t.util.ZNPNode_ZPP_CbType.zpp_pool==null?n=new t.util.ZNPNode_ZPP_CbType:(n=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=n.next,n.next=null),n}static _initStatics(t){Ct.UCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.VCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.WCbSet=new t.util.ZNPList_ZPP_CbSet,Ct.UCbType=new t.util.ZNPList_ZPP_CbType,Ct.VCbType=new t.util.ZNPList_ZPP_CbType,Ct.WCbType=new t.util.ZNPList_ZPP_CbType}};Ct.UCbSet=null,Ct.VCbSet=null,Ct.WCbSet=null,Ct.UCbType=null,Ct.VCbType=null,Ct.WCbType=null;var Ys=Ct;var Kn=class Kn{constructor(){this.outer=null;this.handler=null;this.includes=null;this.excludes=null;this.wrap_includes=null;this.wrap_excludes=null;let e=Kn._zpp;this.includes=new e.util.ZNPList_ZPP_CbType,this.excludes=new e.util.ZNPList_ZPP_CbType}static argument(e){let t=Kn._nape;return e==null?new t.callbacks.OptionType:e instanceof t.callbacks.OptionType?e:new t.callbacks.OptionType().including(e)}setup_includes(){let e=Kn._zpp;this.wrap_includes=e.util.ZPP_CbTypeList.get(this.includes,!0)}setup_excludes(){let e=Kn._zpp;this.wrap_excludes=e.util.ZPP_CbTypeList.get(this.excludes,!0)}excluded(e){return this.nonemptyintersection(e,this.excludes)}included(e){return this.nonemptyintersection(e,this.includes)}compatible(e){return this.nonemptyintersection(e,this.includes)?!this.nonemptyintersection(e,this.excludes):!1}nonemptyintersection(e,t){let n=!1,s=e.head,i=t.head;for(;i!=null&&s!=null;){let l=i.elt,o=s.elt;if(l===o){n=!0;break}else l.id<o.id?i=i.next:s=s.next}return n}insertOrdered(e,t){let n=Kn._zpp,s=null,i=e.head;for(;i!=null;){let o=i.elt;if(t.id<o.id)break;s=i,i=i.next}let l;n.util.ZNPNode_ZPP_CbType.zpp_pool==null?l=new n.util.ZNPNode_ZPP_CbType:(l=n.util.ZNPNode_ZPP_CbType.zpp_pool,n.util.ZNPNode_ZPP_CbType.zpp_pool=l.next,l.next=null),l.elt=t,s==null?(l.next=e.head,e.head=l):(l.next=s.next,s.next=l),e.pushmod=e.modified=!0,e.length++}effect_change(e,t,n){t?n?this.insertOrdered(this.includes,e):this.includes.remove(e):n?this.insertOrdered(this.excludes,e):this.excludes.remove(e)}append_type(e,t){e===this.includes?this.includes.has(t)||(this.excludes.has(t)?this.handler!=null?this.handler(t,!1,!1):this.excludes.remove(t):this.handler!=null?this.handler(t,!0,!0):this.insertOrdered(this.includes,t)):this.excludes.has(t)||(this.includes.has(t)?this.handler!=null?this.handler(t,!0,!1):this.includes.remove(t):this.handler!=null?this.handler(t,!1,!0):this.insertOrdered(this.excludes,t))}set(e){if(e!==this){for(;this.includes.head!=null;)this.append_type(this.excludes,this.includes.head.elt);for(;this.excludes.head!=null;)this.append_type(this.includes,this.excludes.head.elt);let t=e.excludes.head;for(;t!=null;){let s=t.elt;this.append_type(this.excludes,s),t=t.next}let n=e.includes.head;for(;n!=null;){let s=n.elt;this.append_type(this.includes,s),n=n.next}}return this}append(e,t){let n=Kn._nape;if(t==null)throw new Error("Error: Cannot append null, only CbType and CbType list values");if(t instanceof n.callbacks.CbType){let s=t;this.append_type(e,s.zpp_inner)}else if(t instanceof n.callbacks.CbTypeList){let s=t;s.zpp_inner.valmod();let i=n.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let l=i.zpp_inner;l.zpp_inner.valmod(),l.zpp_inner.zip_length&&(l.zpp_inner.zip_length=!1,l.zpp_inner.user_length=l.zpp_inner.inner.length);let o=l.zpp_inner.user_length;i.zpp_critical=!0;let r;if(i.zpp_i<o?r=!0:(i.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,r=!1),!r)break;i.zpp_critical=!1;let a=i.zpp_inner.at(i.zpp_i++);this.append_type(e,a.zpp_inner)}}else if(t instanceof Array){let s=t,i=0;for(;i<s.length;){let l=s[i];if(++i,!(l instanceof n.callbacks.CbType))throw new Error("Error: Cannot append non-CbType or CbType list value");let o=l;this.append_type(e,o.zpp_inner)}}else throw new Error("Error: Cannot append non-CbType or CbType list value")}};Kn._nape=null,Kn._zpp=null;var ts=Kn;var wn=class wn{constructor(){this.outer=null;this.id=0;this.userData=null;this.compound=null;this.space=null;this.active=!1;this.stiff=!1;this.frequency=0;this.damping=0;this.maxForce=0;this.maxError=0;this.breakUnderForce=!1;this.breakUnderError=!1;this.removeOnBreak=!1;this.component=null;this.ignore=!1;this.__velocity=!1;this.cbTypes=null;this.cbSet=null;this.wrap_cbTypes=null;this.pre_dt=-1;this._initBase()}_initBase(){let e=wn._zpp;this.id=dn.Constraint(),this.stiff=!0,this.active=!0,this.ignore=!1,this.frequency=10,this.damping=1,this.maxForce=1/0,this.maxError=1/0,this.breakUnderForce=!1,this.removeOnBreak=!0,this.pre_dt=-1,this.cbTypes=new e.util.ZNPList_ZPP_CbType}clear(){}activeBodies(){}inactiveBodies(){}clearcache(){}validate(){}wake_connected(){}forest(){}broken(){}warmStart(){}draw(e){}pair_exists(e,t){return!1}preStep(e){return!1}applyImpulseVel(){return!1}applyImpulsePos(){return!1}copy(e,t){return null}immutable_midstep(e){if(this.space!=null&&this.space.midstep)throw new Error("Error: Constraint::"+e+" cannot be set during space step()")}setupcbTypes(){let e=wn._zpp;this.wrap_cbTypes=e.util.ZPP_CbTypeList.get(this.cbTypes),this.wrap_cbTypes.zpp_inner.adder=this.wrap_cbTypes_adder.bind(this),this.wrap_cbTypes.zpp_inner.subber=this.wrap_cbTypes_subber.bind(this),this.wrap_cbTypes.zpp_inner.dontremove=!0,this.wrap_cbTypes.zpp_inner._modifiable=this.immutable_cbTypes.bind(this)}immutable_cbTypes(){this.immutable_midstep("Constraint::cbTypes")}wrap_cbTypes_subber(e){let t=e.zpp_inner;this.cbTypes.has(t)&&(this.space!=null&&(this.dealloc_cbSet(),t.constraints.remove(this)),this.cbTypes.remove(t),this.space!=null&&(this.alloc_cbSet(),this.wake()))}wrap_cbTypes_adder(e){return this.insert_cbtype(e.zpp_inner),!1}insert_cbtype(e){let t=wn._zpp;if(!this.cbTypes.has(e)){this.space!=null&&(this.dealloc_cbSet(),e.constraints.add(this));let n=null,s=this.cbTypes.head;for(;s!=null;){let r=s.elt;if(e.id<r.id)break;n=s,s=s.next}let i=this.cbTypes,l;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?l=new t.util.ZNPNode_ZPP_CbType:(l=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=l.next,l.next=null),l.elt=e;let o=l;n==null?(o.next=i.head,i.head=o):(o.next=n.next,n.next=o),i.pushmod=i.modified=!0,i.length++,this.space!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){(this.cbSet=this.space.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.constraints.add(this))}dealloc_cbSet(){let e=wn._zpp;if(this.cbSet!=null){if(this.cbSet.constraints.remove(this),--this.cbSet.count==0){this.space.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=!0,t.bodylisteners.clear(),t.zip_bodylisteners=!0,t.conlisteners.clear(),t.zip_conlisteners=!0;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=e.callbacks.ZPP_CbSet.zpp_pool,e.callbacks.ZPP_CbSet.zpp_pool=t}this.cbSet=null}}activate(){this.space!=null&&this.activeInSpace()}deactivate(){this.space!=null&&this.inactiveOrOutSpace()}addedToSpace(){this.active&&this.activeInSpace(),this.activeBodies();let e=this.cbTypes.head;for(;e!=null;)e.elt.constraints.add(this),e=e.next}removedFromSpace(){this.active&&this.inactiveOrOutSpace(),this.inactiveBodies();let e=this.cbTypes.head;for(;e!=null;)e.elt.constraints.remove(this),e=e.next}activeInSpace(){let e=wn._zpp;this.alloc_cbSet(),e.space.ZPP_Component.zpp_pool==null?this.component=new e.space.ZPP_Component:(this.component=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=this.component.next,this.component.next=null),this.component.isBody=!1,this.component.constraint=this}inactiveOrOutSpace(){let e=wn._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=wn._nape,n=this.outer;n.zpp_inner.wrap_cbTypes==null&&n.zpp_inner.setupcbTypes();let s=n.zpp_inner.wrap_cbTypes;s.zpp_inner.valmod();let i=t.callbacks.CbTypeIterator.get(s);for(;;){i.zpp_inner.zpp_inner.valmod();let m=i.zpp_inner;m.zpp_inner.valmod(),m.zpp_inner.zip_length&&(m.zpp_inner.zip_length=!1,m.zpp_inner.user_length=m.zpp_inner.inner.length);let _=m.zpp_inner.user_length;i.zpp_critical=!0;let y;if(i.zpp_i<_?y=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,y=!1),!y)break;i.zpp_critical=!1;let z=i.zpp_inner.at(i.zpp_i++);e.zpp_inner.wrap_cbTypes==null&&e.zpp_inner.setupcbTypes();let f=e.zpp_inner.wrap_cbTypes;f.zpp_inner.reverse_flag?f.push(z):f.unshift(z)}e.zpp_inner.removeOnBreak=n.zpp_inner.removeOnBreak;let l=n.zpp_inner.breakUnderError;e.zpp_inner.breakUnderError!=l&&(e.zpp_inner.breakUnderError=l,e.zpp_inner.wake());let o=n.zpp_inner.breakUnderForce;e.zpp_inner.breakUnderForce!=o&&(e.zpp_inner.breakUnderForce=o,e.zpp_inner.wake());let r=n.zpp_inner.maxError;if(r!==r)throw new Error("Error: Constraint::maxError cannot be NaN");if(r<0)throw new Error("Error: Constraint::maxError must be >=0");e.zpp_inner.maxError!=r&&(e.zpp_inner.maxError=r,e.zpp_inner.wake());let a=n.zpp_inner.maxForce;if(a!==a)throw new Error("Error: Constraint::maxForce cannot be NaN");if(a<0)throw new Error("Error: Constraint::maxForce must be >=0");e.zpp_inner.maxForce!=a&&(e.zpp_inner.maxForce=a,e.zpp_inner.wake());let p=n.zpp_inner.damping;if(p!==p)throw new Error("Error: Constraint::Damping cannot be Nan");if(p<0)throw new Error("Error: Constraint::Damping must be >=0");e.zpp_inner.damping!=p&&(e.zpp_inner.damping=p,e.zpp_inner.stiff||e.zpp_inner.wake());let c=n.zpp_inner.frequency;if(c!==c)throw new Error("Error: Constraint::Frequency cannot be NaN");if(c<=0)throw new Error("Error: Constraint::Frequency must be >0");e.zpp_inner.frequency!=c&&(e.zpp_inner.frequency=c,e.zpp_inner.stiff||e.zpp_inner.wake());let h=n.zpp_inner.stiff;e.zpp_inner.stiff!=h&&(e.zpp_inner.stiff=h,e.zpp_inner.wake());let u=n.zpp_inner.ignore;e.zpp_inner.ignore!=u&&(e.zpp_inner.ignore=u,e.zpp_inner.wake());let x=n.zpp_inner.active;e.zpp_inner.active!=x&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.woken=!1),e.zpp_inner.clearcache(),x?(e.zpp_inner.active=x,e.zpp_inner.activate(),e.zpp_inner.space!=null&&(e.zpp_inner.component!=null&&(e.zpp_inner.component.sleeping=!0),e.zpp_inner.space.wake_constraint(e.zpp_inner,!0))):(e.zpp_inner.space!=null&&(e.zpp_inner.wake(),e.zpp_inner.space.live_constraints.remove(e.zpp_inner)),e.zpp_inner.active=x,e.zpp_inner.deactivate()))}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let s=t.parent;t.parent=n,n=t,t=s}for(;n!=null;){let s=n.parent;n.parent=t,n=s}return t}static _unionComponents(e,t){let n=wn._findRoot(e),s=wn._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}};wn._nape=null,wn._zpp=null;var Me=wn;var Rn=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 bs=class bs extends Me{constructor(){super();this.outer_zn=null;this.ratio=0;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.scale=0;this.b1=null;this.b2=null;this.kMass=0;this.jAcc=0;this.jMax=0;this.gamma=0;this.bias=0;this.stepped=!1;this.ratio=1,this.jAcc=0,this.slack=!1,this.jMax=1/0,this.stepped=!1}is_slack(){let t=this.ratio*this.b2.rot-this.b1.rot;return this.equal?(this.scale=1,!1):t<this.jointMin?(this.scale=-1,!1):t>this.jointMax?(this.scale=1,!1):(this.scale=0,!0)}bodyImpulse(t){let n=_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=bs._createFn(null,null,this.jointMin,this.jointMax,this.ratio);if(this.copyto(s),t!=null&&this.b1!=null){let i=null,l=0;for(;l<t.length;){let o=t[l];if(++l,o.id==this.b1.id){i=o.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(Rn.todo(this.b1.id,o=>{s.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let o=t[l];if(++l,o.id==this.b2.id){i=o.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(Rn.todo(this.b2.id,o=>{s.zpp_inner.b2=o.zpp_inner}))}return s}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: AngleJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: AngleJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let s=this.b1.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let s=this.b2.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1,this.slack=!1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax;let s=this.ratio*this.b2.rot-this.b1.rot;this.equal?(s-=this.jointMax,this.slack=!1,this.scale=1):s<this.jointMin?(s=this.jointMin-s,this.scale=-1,this.slack=!1):s>this.jointMax?(s-=this.jointMax,this.scale=1,this.slack=!1):(this.scale=0,s=0,this.slack=!0);let i=s;if(!this.slack){if(this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&i*i>this.maxError*this.maxError)return!0;let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let o=1/(1+this.gamma),r=t*l*l*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-i*r,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){this.slack||(this.b1.angvel-=this.scale*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*this.jAcc)}applyImpulseVel(){if(this.slack)return!1;let t=this.scale*(this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel),n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;return this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&(this.jAcc>this.jMax||this.jAcc<-this.jMax)?!0:(this.stiff||(this.jAcc>this.jMax?this.jAcc=this.jMax:this.jAcc<-this.jMax&&(this.jAcc=-this.jMax)),n=this.jAcc-s,this.b1.angvel-=this.scale*this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.scale*this.b2.iinertia*n,!1)}applyImpulsePos(){let t=this.ratio*this.b2.rot-this.b1.rot,n;this.equal?(t-=this.jointMax,n=!1,this.scale=1):t<this.jointMin?(t=this.jointMin-t,this.scale=-1,n=!1):t>this.jointMax?(t-=this.jointMax,this.scale=1,n=!1):(this.scale=0,t=0,n=!0);let s=t;if(!n){if(this.breakUnderError&&s*s>this.maxError*this.maxError)return!0;let l=-(s*.5)*this.kMass;if(this.equal||l<0){let o=this.b1,r=-this.scale*l*this.b1.iinertia;if(o.rot+=r,r*r>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let c=r*r,h=1-.5*c,u=1-c*c/8,x=(h*o.axisx+r*o.axisy)*u;o.axisy=(h*o.axisy-r*o.axisx)*u,o.axisx=x}let a=this.b2,p=this.ratio*this.scale*l*this.b2.iinertia;if(a.rot+=p,p*p>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let c=p*p,h=1-.5*c,u=1-c*c/8,x=(h*a.axisx+p*a.axisy)*u;a.axisy=(h*a.axisy-p*a.axisx)*u,a.axisx=x}}}return!1}draw(t){}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let s=n*n,i=1-.5*s,l=1-s*s/8,o=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=o}}static _copyBody(t,n,s,i,l){if(t!=null&&s!=null){let o=null;for(let r=0;r<t.length;r++){let a=t[r];if(a.id==s.id){o=a.bc;break}}o!=null?i.zpp_inner_zn[l]=o.zpp_inner:n.push(Rn.todo(s.id,function(r){i.zpp_inner_zn[l]=r.zpp_inner}))}}};bs._wrapFn=null,bs._createFn=null;var Re=bs;var Nt=class Nt{constructor(){this.x=0;this.y=0;this.next=null;this.length=0;this.modified=!1;this.pushmod=!1;this._inuse=!1;this.weak=!1;this.outer=null;this._immutable=!1;this._isimmutable=null;this._validate=null;this._invalidate=null}static get(e,t,n){n==null&&(n=!1);let s;return Nt.zpp_pool==null?s=new Nt:(s=Nt.zpp_pool,Nt.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=n,s.x=e,s.y=t,s}validate(){this._validate!=null&&this._validate()}invalidate(){this._invalidate!=null&&this._invalidate(this)}immutable(){if(this._immutable)throw new Error("Error: Vec2 is immutable");this._isimmutable!=null&&this._isimmutable()}wrapper(){if(this.outer==null)if(Nt._wrapFn)this.outer=Nt._wrapFn(this);else{this.outer=new Nt._nape.geom.Vec2;let e=this.outer.zpp_inner;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e._isimmutable=null,e._validate=null,e._invalidate=null,e.next=Nt.zpp_pool,Nt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this._isimmutable=null,this._validate=null,this._invalidate=null}alloc(){this.weak=!1}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}inlined_add(e){return e._inuse=!0,e.next=this.next,this.next=e,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;)this.add(t),t=t.next}insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}inlined_insert(e,t){return t._inuse=!0,e==null?(t.next=this.next,this.next=t):(t.next=e.next,e.next=t),this.pushmod=this.modified=!0,this.length++,t}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let s;t==null?(s=this.next,this.next=s.next,this.next==null&&(this.pushmod=!0)):(s=t.next,t.next=s.next,s.next==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e)return this.erase(t),!0;t=n,n=n.next}return!1}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let s;t==null?(s=this.next,this.next=s.next,this.next==null&&(this.pushmod=!0)):(s=t.next,t.next=s.next,s.next==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next;for(;n!=null;){if(n===e){let s;return t==null?(s=this.next,this.next=s.next,this.next==null&&(this.pushmod=!0)):(s=t.next,t.next=s.next,s.next==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,!0}t=n,n=n.next}return!1}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=this.next;for(;t!=null;){if(t===e)return!0;t=t.next}return!1}inlined_has(e){let t=this.next;for(;t!=null;){if(t===e)return!0;t=t.next}return!1}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}copy(){let e=this.x,t=this.y,n;return Nt.zpp_pool==null?n=new Nt:(n=Nt.zpp_pool,Nt.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,n}toString(){return"{ x: "+this.x+" y: "+this.y+" }"}};Nt.zpp_pool=null,Nt._nape=null,Nt._zpp=null,Nt._wrapFn=null;var pe=Nt;var Vi=class Vi extends Me{constructor(){super();this.outer_zn=null;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.nx=0;this.ny=0;this.cx1=0;this.cx2=0;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a1=null;this.wrap_a2=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=n*n+s*s;return i<Me._nape.Config.epsilon?t=!0:(i=Math.sqrt(i),this.equal||i<this.jointMin||i>this.jointMax?t=!1:t=!0),t}bodyImpulse(t){let n=Me._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=Vi._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=Vi._setupAnchorVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let o=Vi._createFn(null,null,i,l.zpp_inner_zn.wrap_a2,this.jointMin,this.jointMax);return this.copyto(o),Re._copyBody(t,n,this.b1,o,"b1"),Re._copyBody(t,n,this.b2,o,"b2"),o}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: DistanceJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: DistanceJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.jointMin>this.jointMax)throw new Error("Error: DistanceJoint must have jointMin <= jointMax");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.nx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.ny=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely);let s=this.nx*this.nx+this.ny*this.ny;if(s<Me._nape.Config.epsilon)this.nx=0,this.ny=0,s=0,this.slack=!0;else{s=Math.sqrt(s);let l=1/s;this.nx*=l,this.ny*=l,this.equal?(s-=this.jointMax,this.slack=!1):s<this.jointMin?(s=this.jointMin-s,this.nx=-this.nx,this.ny=-this.ny,this.slack=!1):s>this.jointMax?(s-=this.jointMax,this.slack=!1):(this.nx=0,this.ny=0,s=0,this.slack=!0)}let i=s;if(!this.slack){if(this.cx1=this.ny*this.a1relx-this.nx*this.a1rely,this.cx2=this.ny*this.a2relx-this.nx*this.a2rely,this.kMass=this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&i*i>this.maxError*this.maxError)return!0;let l=2*Math.PI*this.frequency;this.gamma=1/(t*l*(2*this.damping+l*t));let o=1/(1+this.gamma),r=t*l*l*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-i*r,this.bias<-this.maxError?this.bias=-this.maxError:this.bias>this.maxError&&(this.bias=this.maxError)}this.jAcc*=n,this.jMax=this.maxForce*t}return!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.nx*t,this.b1.vely-=this.ny*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.nx*n,this.b2.vely+=this.ny*n,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.nx*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.ny*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-s;let i=this.b1.imass*n;this.b1.velx-=this.nx*i,this.b1.vely-=this.ny*i;let l=this.b2.imass*n;return this.b2.velx+=this.nx*l,this.b2.vely+=this.ny*l,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,!1}applyImpulsePos(){let t,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s),p=r*r+a*a;if(p<Me._nape.Config.epsilon)r=0,a=0,p=0,o=!0;else{p=Math.sqrt(p);let h=1/p;r*=h,a*=h,this.equal?(p-=this.jointMax,o=!1):p<this.jointMin?(p=this.jointMin-p,r=-r,a=-a,o=!1):p>this.jointMax?(p-=this.jointMax,o=!1):(r=0,a=0,p=0,o=!0)}let c=p;if(!o){if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;if(c*c<Me._nape.Config.constraintLinearSlop*Me._nape.Config.constraintLinearSlop)return!1;if(c*=.5,c*c>6){let m=this.b1.smass+this.b2.smass;if(m>Me._nape.Config.epsilon){let _=.75/m;if(t=-c*_,this.equal||t<0){let y=t*this.b1.imass;this.b1.posx-=r*y,this.b1.posy-=a*y;let z=t*this.b2.imass;this.b2.posx+=r*z,this.b2.posy+=a*z,r=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s);let f=r*r+a*a;if(f<Me._nape.Config.epsilon)r=0,a=0,f=0;else{f=Math.sqrt(f);let w=1/f;r*=w,a*=w,this.equal?f-=this.jointMax:f<this.jointMin?(f=this.jointMin-f,r=-r,a=-a):f>this.jointMax?f-=this.jointMax:(r=0,a=0,f=0)}c=f,c*=.5}}}let h=a*n-r*s,u=a*i-r*l,x=this.b1.smass+this.b2.smass+h*h*this.b1.sinertia+u*u*this.b2.sinertia;if(x!=0&&(x=1/x),t=-c*x,this.equal||t<0){let m=this.b1.imass*t;this.b1.posx-=r*m,this.b1.posy-=a*m;let _=this.b2.imass*t;this.b2.posx+=r*_,this.b2.posy+=a*_,Re._rotateBody(this.b1,-h*this.b1.iinertia*t),Re._rotateBody(this.b2,u*this.b2.iinertia*t)}}return!1}draw(t){}static _setupAnchorVec2(t,n,s,i){let l=Me._nape,o=t,r=n;if(r==null&&(r=0),o==null&&(o=0),o!=o||r!=r)throw new Error("Error: Vec2 components cannot be NaN");let a;if(xe.poolVec2==null?a=new l.geom.Vec2:(a=xe.poolVec2,xe.poolVec2=a.zpp_pool,a.zpp_pool=null,a.zpp_disp=!1,a==xe.nextVec2&&(xe.nextVec2=null)),a.zpp_inner==null){let p;pe.zpp_pool==null?p=new pe:(p=pe.zpp_pool,pe.zpp_pool=p.next,p.next=null),p.weak=!1,p._immutable=!1,p.x=o,p.y=r,a.zpp_inner=p,a.zpp_inner.outer=a}else{if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=a.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),o!=o||r!=r)throw new Error("Error: Vec2 components cannot be NaN");let c;if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=a.zpp_inner;if(h._validate!=null&&h._validate(),a.zpp_inner.x==o){if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=a.zpp_inner;u._validate!=null&&u._validate(),c=a.zpp_inner.y==r}else c=!1;if(!c){a.zpp_inner.x=o,a.zpp_inner.y=r;let u=a.zpp_inner;u._invalidate!=null&&u._invalidate(u)}}return a.zpp_inner.weak=!1,a.zpp_inner._inuse=!0,a.zpp_inner._validate=s,a.zpp_inner._invalidate=i,a}};Vi._wrapFn=null,Vi._createFn=null;var _i=Vi;var zs=class zs extends Me{constructor(){super();this.outer_zn=null;this.scale=0;this.jointMin=0;this.jointMax=0;this.equal=!1;this.dot1=0;this.dot2=0;this.cx1=0;this.cx2=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.zip_n=null;this.nlocalx=0;this.nlocaly=0;this.nrelx=0;this.nrely=0;this.wrap_n=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.jAccx=0;this.jAccy=0;this.jMax=null;this.gamma=null;this.biasx=0;this.biasy=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.nlocalx=0,this.nlocaly=0,this.nrelx=0,this.nrely=0,this.jAccx=0,this.jAccy=0,this.jMax=1/0,this.jointMin=-1/0,this.jointMax=1/0,this.stepped=!1}_setupVec2(t,n,s,i){let l=Me._nape,o=Me._zpp;if(n==null&&(n=0),t==null&&(t=0),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");let r;if(o.util.ZPP_PubPool.poolVec2==null?r=new l.geom.Vec2:(r=o.util.ZPP_PubPool.poolVec2,o.util.ZPP_PubPool.poolVec2=r.zpp_pool,r.zpp_pool=null,r.zpp_disp=!1,r==o.util.ZPP_PubPool.nextVec2&&(o.util.ZPP_PubPool.nextVec2=null)),r.zpp_inner==null){let a;o.geom.ZPP_Vec2.zpp_pool==null?a=new o.geom.ZPP_Vec2:(a=o.geom.ZPP_Vec2.zpp_pool,o.geom.ZPP_Vec2.zpp_pool=a.next,a.next=null),a.weak=!1,a._immutable=!1,a.x=t,a.y=n,r.zpp_inner=a,r.zpp_inner.outer=r}else{if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=r.zpp_inner;if(a._immutable)throw new Error("Error: Vec2 is immutable");if(a._isimmutable!=null&&a._isimmutable(),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=r.zpp_inner;p._validate!=null&&p._validate();let c;if(r.zpp_inner.x==t){if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=r.zpp_inner;h._validate!=null&&h._validate(),c=r.zpp_inner.y==n}else c=!1;if(!c){r.zpp_inner.x=t,r.zpp_inner.y=n;let h=r.zpp_inner;h._invalidate!=null&&h._invalidate(h)}}return r.zpp_inner.weak=!1,r.zpp_inner._inuse=!0,r.zpp_inner._validate=s,r.zpp_inner._invalidate=i,r}validate_a1(){this.wrap_a1.zpp_inner.x=this.a1localx,this.wrap_a1.zpp_inner.y=this.a1localy}invalidate_a1(t){this.immutable_midstep("Constraint::a1"),this.a1localx=t.x,this.a1localy=t.y,this.wake()}setup_a1(){this.wrap_a1=this._setupVec2(this.a1localx,this.a1localy,this.validate_a1.bind(this),this.invalidate_a1.bind(this))}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){this.wrap_a2=this._setupVec2(this.a2localx,this.a2localy,this.validate_a2.bind(this),this.invalidate_a2.bind(this))}validate_n(){this.wrap_n.zpp_inner.x=this.nlocalx,this.wrap_n.zpp_inner.y=this.nlocaly}invalidate_n(t){this.immutable_midstep("Constraint::n"),this.nlocalx=t.x,this.nlocaly=t.y,this.zip_n=!0,this.wake()}setup_n(){this.wrap_n=this._setupVec2(this.nlocalx,this.nlocaly,this.validate_n.bind(this),this.invalidate_n.bind(this))}validate_norm(){if(this.zip_n){this.zip_n=!1;let t=this.nlocalx*this.nlocalx+this.nlocaly*this.nlocaly,s=1/Math.sqrt(t);this.nlocalx*=s,this.nlocaly*=s}}bodyImpulse(t){let n=Me._nape;if(this.stepped){let s=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,i=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy;return t==this.b1?n.geom.Vec3.get(-s,-i,this.scale*this.cx1*i-this.dot1*s):n.geom.Vec3.get(s,i,this.scale*this.cx1*i-this.dot1*s)}else return n.geom.Vec3.get(0,0,0)}activeBodies(){this.b1!=null&&this.b1.constraints.add(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.add(this)}inactiveBodies(){this.b1!=null&&this.b1.constraints.remove(this),this.b2!=this.b1&&this.b2!=null&&this.b2.constraints.remove(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let o=l.zpp_inner_zn.wrap_a2,r=this.outer_zn;r.zpp_inner_zn.wrap_n==null&&r.zpp_inner_zn.setup_n();let a=zs._createFn(null,null,i,o,r.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=Me._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&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.equal=this.jointMin==this.jointMax,this.stepped=!0,this.validate_norm(),this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.nrelx=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,this.nrely=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b2.posx+this.a2relx-this.b1.posx-this.a1relx,i=this.b2.posy+this.a2rely-this.b1.posy-this.a1rely,l=i*this.nrelx-s*this.nrely,o=this.nrelx*s+this.nrely*i;this.equal?(o-=this.jointMin,this.scale=1):o>this.jointMax?(o-=this.jointMax,this.scale=1):o<this.jointMin?(o=this.jointMin-o,this.scale=-1):(o=0,this.scale=0);let r=s+this.a1relx,a=i+this.a1rely;this.dot1=this.nrelx*r+this.nrely*a,this.cx1=a*this.nrelx-r*this.nrely,this.dot2=this.nrelx*this.a2relx+this.nrely*this.a2rely,this.cx2=this.a2rely*this.nrelx-this.a2relx*this.nrely,this.kMassa=this.b1.smass+this.b2.smass+this.dot1*this.dot1*this.b1.sinertia+this.dot2*this.dot2*this.b2.sinertia,this.kMassb=-this.scale*(this.dot1*this.cx1*this.b1.sinertia+this.dot2*this.cx2*this.b2.sinertia),this.kMassc=this.scale*this.scale*(this.b1.smass+this.b2.smass+this.cx1*this.cx1*this.b1.sinertia+this.cx2*this.cx2*this.b2.sinertia);let p=this.kMassa*this.kMassc-this.kMassb*this.kMassb,c;if(p!==p)this.kMassa=this.kMassb=this.kMassc=0,c=3;else if(p==0){let u=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,u|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,u|=2),this.kMassb=0,c=u}else{let u=1/p,x=this.kMassc*u;this.kMassc=this.kMassa*u,this.kMassa=x,this.kMassb*=-u,c=0}if((c&1)!=0&&(this.jAccx=0),(c&2)!=0&&(this.jAccy=0),this.stiff)this.gamma=0,this.biasx=0,this.biasy=0;else{if(this.breakUnderError&&l*l+o*o>this.maxError*this.maxError)return!0;let u=2*Math.PI*this.frequency;this.gamma=1/(t*u*(2*this.damping+u*t));let x=1/(1+this.gamma),m=t*u*u*this.gamma;this.gamma*=x;let _=x;this.kMassa*=_,this.kMassb*=_,this.kMassc*=_,this.biasx=l,this.biasy=o;let y=-m;this.biasx*=y,this.biasy*=y;let z=this.maxError,f=this.biasx*this.biasx+this.biasy*this.biasy;if(f>z*z){let w=z*(1/Math.sqrt(f));this.biasx*=w,this.biasy*=w}}let h=n;return this.jAccx*=h,this.jAccy*=h,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.scale*this.nrelx*this.jAccy-this.nrely*this.jAccx,n=this.nrelx*this.jAccx+this.scale*this.nrely*this.jAccy,s=this.b1.imass;this.b1.velx-=t*s,this.b1.vely-=n*s;let i=this.b2.imass;this.b2.velx+=t*i,this.b2.vely+=n*i,this.b1.angvel+=(this.scale*this.cx1*this.jAccy-this.dot1*this.jAccx)*this.b1.iinertia,this.b2.angvel+=(this.dot2*this.jAccx-this.scale*this.cx2*this.jAccy)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx-this.b1.velx,n=this.b2.vely-this.b1.vely;t+=this.b2.kinvelx-this.b1.kinvelx,n+=this.b2.kinvely-this.b1.kinvely;let s=n*this.nrelx-t*this.nrely+(this.b2.angvel+this.b2.kinangvel)*this.dot2-(this.b1.angvel+this.b1.kinangvel)*this.dot1,i=this.scale*(this.nrelx*t+this.nrely*n-(this.b2.angvel+this.b2.kinangvel)*this.cx2+(this.b1.angvel+this.b1.kinangvel)*this.cx1),l=this.biasx-s,o=this.biasy-i,r=this.kMassa*l+this.kMassb*o;o=this.kMassb*l+this.kMassc*o,l=r;let a=this.gamma;l-=this.jAccx*a,o-=this.jAccy*a;let p=this.jAccx,c=this.jAccy;if(this.jAccx+=l,this.jAccy+=o,this.jAccy>0&&(this.jAccy=0),this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let z=this.jMax,f=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(f>z*z){let w=z*(1/Math.sqrt(f));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,!1}applyImpulsePos(){let t=Me._nape,n=this.b1.axisy*this.nlocalx-this.b1.axisx*this.nlocaly,s=this.nlocalx*this.b1.axisx+this.nlocaly*this.b1.axisy,i=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,l=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,o=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,r=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,a=this.b2.posx+o-this.b1.posx-i,p=this.b2.posy+r-this.b1.posy-l,c,h=p*n-a*s,u=n*a+s*p;if(this.equal?(u-=this.jointMin,c=1):u>this.jointMax?(u-=this.jointMax,c=1):u<this.jointMin?(u=this.jointMin-u,c=-1):(u=0,c=0),this.breakUnderError&&h*h+u*u>this.maxError*this.maxError)return!0;if(h*h+u*u<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let x,m,_=.5;if(h*=_,u*=_,h*h+u*u>6){let M=this.b1.smass+this.b2.smass;if(M>t.Config.epsilon){let S=.8/M,O=S*(s*h-c*n*u),L=S*(n*h*c-s*h),T=this.b1.imass;this.b1.posx-=O*T,this.b1.posy-=L*T;let R=this.b2.imass;this.b2.posx+=O*R,this.b2.posy+=L*R,a=this.b2.posx+o-this.b1.posx-i,p=this.b2.posy+r-this.b1.posy-l,h=p*n-a*s,u=n*a+s*p,this.equal?(u-=this.jointMin,c=1):u>this.jointMax?(u-=this.jointMax,c=1):u<this.jointMin?(u=this.jointMin-u,c=-1):(u=0,c=0);let q=.5;h*=q,u*=q}}let y=a+i,z=p+l,f=n*y+s*z,w=z*n-y*s,Z=n*o+s*r,d=r*n-o*s,b=this.b1.smass+this.b2.smass+f*f*this.b1.sinertia+Z*Z*this.b2.sinertia,g=-c*(f*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=b*P-g*g;if(v!==v)m=0,x=m;else if(v==0)b!=0?x/=b:x=0,P!=0?m/=P:m=0;else{let M=1/v,S=M*(P*x-g*m);m=M*(b*m-g*x),x=S}m>0&&(m=0);let N=c*n*m-s*x,k=n*x+c*s*m,C=this.b1.imass;this.b1.posx-=N*C,this.b1.posy-=k*C;let E=this.b2.imass;return this.b2.posx+=N*E,this.b2.posy+=k*E,Re._rotateBody(this.b1,(c*w*m-f*x)*this.b1.iinertia),Re._rotateBody(this.b2,(Z*x-c*d*m)*this.b2.iinertia),!1}draw(t){}};zs._wrapFn=null,zs._createFn=null;var di=zs;var Ps=class Ps extends Me{constructor(){super();this.outer_zn=null;this.ratio=0;this.rate=0;this.b1=null;this.b2=null;this.kMass=0;this.jAcc=0;this.jMax=0;this.stepped=!1;this.jAcc=0,this.stepped=!1,this.__velocity=!0}bodyImpulse(t){let n=_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 o=t[l];if(++l,o.id==this.b1.id){i=o.bc;break}}i!=null?s.zpp_inner.b1=i.zpp_inner:n.push(Rn.todo(this.b1.id,o=>{s.zpp_inner.b1=o.zpp_inner}))}if(t!=null&&this.b2!=null){let i=null,l=0;for(;l<t.length;){let o=t[l];if(++l,o.id==this.b2.id){i=o.bc;break}}i!=null?s.zpp_inner.b2=i.zpp_inner:n.push(Rn.todo(this.b2.id,o=>{s.zpp_inner.b2=o.zpp_inner}))}return s}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: MotorJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){if(this.b1.type==2){let t;if(this.b1.component==this.b1.component.parent)t=this.b1.component;else{let s=this.b1.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}if(this.b2.type==2){let t;if(this.b2.component==this.b2.component.parent)t=this.b2.component;else{let s=this.b2.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}t=s}let n;if(this.component==this.component.parent)n=this.component;else{let s=this.component,i=null;for(;s!=s.parent;){let l=s.parent;s.parent=i,i=s,s=l}for(;i!=null;){let l=i.parent;i.parent=s,i=l}n=s}t!=n&&(t.rank<n.rank?t.parent=n:t.rank>n.rank?n.parent=t:(n.parent=t,t.rank++))}}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;return this.pre_dt=t,this.stepped=!0,this.kMass=this.b1.sinertia+this.ratio*this.ratio*this.b2.sinertia,this.kMass=1/this.kMass,this.jAcc*=n,this.jMax=this.maxForce*t,!1}warmStart(){this.b1.angvel-=this.b1.iinertia*this.jAcc,this.b2.angvel+=this.ratio*this.b2.iinertia*this.jAcc}applyImpulseVel(){let t=this.ratio*(this.b2.angvel+this.b2.kinangvel)-this.b1.angvel-this.b1.kinangvel-this.rate,n=-this.kMass*t,s=this.jAcc;if(this.jAcc+=n,this.breakUnderForce){if(this.jAcc>this.jMax||this.jAcc<-this.jMax)return!0}else this.jAcc<-this.jMax?this.jAcc=-this.jMax:this.jAcc>this.jMax&&(this.jAcc=this.jMax);return n=this.jAcc-s,this.b1.angvel-=this.b1.iinertia*n,this.b2.angvel+=this.ratio*this.b2.iinertia*n,!1}applyImpulsePos(){return!1}};Ps._wrapFn=null,Ps._createFn=null;var yi=Ps;var ws=class ws extends Me{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.jAccx=0;this.jAccy=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.stepped=!1;this.stepped=!1,this.jAccx=0,this.jAccy=0,this.jMax=1/0,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0}bodyImpulse(t){let n=Me._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=Me._nape,n=Me._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=s,o.y=i,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),r=l.zpp_inner.y==i}else r=!1;if(!r){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a1=l,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=Me._nape,n=Me._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=s,o.y=i,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),r=l.zpp_inner.y==i}else r=!1;if(!r){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let o=ws._createFn(null,null,i,l.zpp_inner_zn.wrap_a2);return this.copyto(o),Re._copyBody(t,n,this.b1,o,"b1"),Re._copyBody(t,n,this.b2,o,"b2"),o}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: PivotJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: PivotJoint cannot be simulated with body1 == body2 (body1=body2="+this.b1.outer.toString()+")");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic (body1="+this.b1.outer.toString()+", body2="+this.b2.outer.toString()+")")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b1.smass+this.b2.smass;if(this.kMassa=s,this.kMassb=0,this.kMassc=s,this.b1.sinertia!=0){let r=this.a1relx*this.b1.sinertia,a=this.a1rely*this.b1.sinertia;this.kMassa+=a*this.a1rely,this.kMassb+=-a*this.a1relx,this.kMassc+=r*this.a1relx}if(this.b2.sinertia!=0){let r=this.a2relx*this.b2.sinertia,a=this.a2rely*this.b2.sinertia;this.kMassa+=a*this.a2rely,this.kMassb+=-a*this.a2relx,this.kMassc+=r*this.a2relx}let i=this.kMassa*this.kMassc-this.kMassb*this.kMassb,l;if(i!=i)this.kMassa=this.kMassb=this.kMassc=0,l=3;else if(i==0){let r=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,r|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,r|=2),this.kMassb=0,l=r}else{let r=1/i,a=this.kMassc*r;this.kMassc=this.kMassa*r,this.kMassa=a,this.kMassb*=-r,l=0}if((l&1)!=0&&(this.jAccx=0),(l&2)!=0&&(this.jAccy=0),this.stiff)this.biasx=0,this.biasy=0,this.gamma=0;else{let r=2*Math.PI*this.frequency;this.gamma=1/(t*r*(2*this.damping+r*t));let a=1/(1+this.gamma),p=t*r*r*this.gamma;this.gamma*=a;let c=a;if(this.kMassa*=c,this.kMassb*=c,this.kMassc*=c,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy>this.maxError*this.maxError)return!0;let h=-p;this.biasx*=h,this.biasy*=h;let u=this.maxError,x=this.biasx*this.biasx+this.biasy*this.biasy;if(x>u*u){let m=u*(1/Math.sqrt(x));this.biasx*=m,this.biasy*=m}}let o=n;return this.jAccx*=o,this.jAccy*=o,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),s=this.biasx-t,i=this.biasy-n,l=this.kMassa*s+this.kMassb*i;i=this.kMassb*s+this.kMassc*i,s=l;let o=this.gamma;s-=this.jAccx*o,i-=this.jAccy*o;let r=this.jAccx,a=this.jAccy,p=1;if(this.jAccx+=s*p,this.jAccy+=i*p,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy>this.jMax*this.jMax)return!0}else if(!this.stiff){let u=this.jMax,x=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(x>u*u){let m=u*(1/Math.sqrt(x));this.jAccx*=m,this.jAccy*=m}}s=this.jAccx-r,i=this.jAccy-a;let c=this.b1.imass;this.b1.velx-=s*c,this.b1.vely-=i*c;let h=this.b2.imass;return this.b2.velx+=s*h,this.b2.vely+=i*h,this.b1.angvel-=(i*this.a1relx-s*this.a1rely)*this.b1.iinertia,this.b2.angvel+=(i*this.a2relx-s*this.a2rely)*this.b2.iinertia,!1}applyImpulsePos(){let t=Me._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s);if(this.breakUnderError&&o*o+r*r>this.maxError*this.maxError)return!0;if(o*o+r*r<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let a=.5;o*=a,r*=a;let p,c;if(o*o+r*r>6){let b=this.b1.smass+this.b2.smass;if(b>t.Config.epsilon){let g=.75/b;p=-o*g,c=-r*g;let P=20,v=p*p+c*c;if(v>P*P){let E=P*(1/Math.sqrt(v));p*=E,c*=E}let N=this.b1.imass;this.b1.posx-=p*N,this.b1.posy-=c*N;let k=this.b2.imass;this.b2.posx+=p*k,this.b2.posy+=c*k,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s);let C=.5;o*=C,r*=C}}let h=this.b1.smass+this.b2.smass,u=h,x=0,m=h;if(this.b1.sinertia!=0){let b=n*this.b1.sinertia,g=s*this.b1.sinertia;u+=g*s,x+=-g*n,m+=b*n}if(this.b2.sinertia!=0){let b=i*this.b2.sinertia,g=l*this.b2.sinertia;u+=g*l,x+=-g*i,m+=b*i}p=-o,c=-r;let _=6,y=p*p+c*c;if(y>_*_){let b=_*(1/Math.sqrt(y));p*=b,c*=b}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 b=1/z,g=b*(m*p-x*c);c=b*(u*c-x*p),p=g}let f=this.b1.imass;this.b1.posx-=p*f,this.b1.posy-=c*f;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),!1}draw(t){}};ws._wrapFn=null,ws._createFn=null;var mi=ws;var vs=class vs extends Me{constructor(){super();this.outer_zn=null;this.ratio=1;this.jointMin=0;this.jointMax=0;this.slack=!1;this.equal=!1;this.n12x=0;this.n12y=0;this.n34x=0;this.n34y=0;this.cx1=0;this.cx2=0;this.cx3=0;this.cx4=0;this.b1=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.b2=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.b3=null;this.a3localx=0;this.a3localy=0;this.a3relx=0;this.a3rely=0;this.wrap_a3=null;this.b4=null;this.a4localx=0;this.a4localy=0;this.a4relx=0;this.a4rely=0;this.wrap_a4=null;this.kMass=0;this.jAcc=0;this.jMax=1/0;this.gamma=0;this.bias=0;this.stepped=!1;this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0,this.a3localx=0,this.a3localy=0,this.a3relx=0,this.a3rely=0,this.a4localx=0,this.a4localy=0,this.a4relx=0,this.a4rely=0,this.n12x=1,this.n12y=0,this.n34x=1,this.n34y=0,this.jAcc=0,this.jMax=1/0,this.stepped=!1,this.cx1=this.cx2=this.cx3=this.cx4=0}is_slack(){let t;this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let n=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),s=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),i=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),l=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),o=Math.sqrt(n*n+s*s),r=Math.sqrt(i*i+l*l),a=o+this.ratio*r;return this.equal||a<this.jointMin||a>this.jointMax?t=!1:t=!0,t}bodyImpulse(t){let n=Me._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=Me._nape,n=Me._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=s,o.y=i,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),r=l.zpp_inner.y==i}else r=!1;if(!r){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a1=l,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=Me._nape,n=Me._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=s,o.y=i,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),r=l.zpp_inner.y==i}else r=!1;if(!r){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}validate_a3(){this.wrap_a3.zpp_inner.x=this.a3localx,this.wrap_a3.zpp_inner.y=this.a3localy}invalidate_a3(t){this.immutable_midstep("Constraint::a3"),this.a3localx=t.x,this.a3localy=t.y,this.wake()}setup_a3(){let t=Me._nape,n=Me._zpp,s=this.a3localx,i=this.a3localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=s,o.y=i,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),r=l.zpp_inner.y==i}else r=!1;if(!r){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a3=l,this.wrap_a3.zpp_inner._inuse=!0,this.wrap_a3.zpp_inner._validate=this.validate_a3.bind(this),this.wrap_a3.zpp_inner._invalidate=this.invalidate_a3.bind(this)}validate_a4(){this.wrap_a4.zpp_inner.x=this.a4localx,this.wrap_a4.zpp_inner.y=this.a4localy}invalidate_a4(t){this.immutable_midstep("Constraint::a4"),this.a4localx=t.x,this.a4localy=t.y,this.wake()}setup_a4(){let t=Me._nape,n=Me._zpp,s=this.a4localx,i=this.a4localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=s,o.y=i,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),r=l.zpp_inner.y==i}else r=!1;if(!r){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a4=l,this.wrap_a4.zpp_inner._inuse=!0,this.wrap_a4.zpp_inner._validate=this.validate_a4.bind(this),this.wrap_a4.zpp_inner._invalidate=this.invalidate_a4.bind(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let o=l.zpp_inner_zn.wrap_a2,r=this.outer_zn;r.zpp_inner_zn.wrap_a3==null&&r.zpp_inner_zn.setup_a3();let a=r.zpp_inner_zn.wrap_a3,p=this.outer_zn;p.zpp_inner_zn.wrap_a4==null&&p.zpp_inner_zn.setup_a4();let c=vs._createFn(null,null,null,null,i,o,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&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component),this.b3.type==2&&Me._unionComponents(this.b3.component,this.component),this.b4.type==2&&Me._unionComponents(this.b4.component,this.component)}pair_exists(t,n){return this.b1.id==t&&(this.b2.id==n||this.b3.id==n||this.b4.id==n)||this.b2.id==t&&(this.b3.id==n||this.b4.id==n||this.b1.id==n)||this.b3.id==t&&(this.b4.id==n||this.b1.id==n||this.b2.id==n)?!0:this.b4.id==t?this.b1.id==n||this.b2.id==n?!0:this.b3.id==n:!1}clearcache(){this.jAcc=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.equal=this.jointMin==this.jointMax,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,this.a3relx=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,this.a3rely=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,this.a4relx=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,this.a4rely=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy;let s=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),i=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),l=this.b4.posx+this.a4relx-(this.b3.posx+this.a3relx),o=this.b4.posy+this.a4rely-(this.b3.posy+this.a3rely),r=Math.sqrt(s*s+i*i),a=Math.sqrt(l*l+o*o);if(r!=0){let h=1/r;this.n12x=s*h,this.n12y=i*h}if(a!=0){let h=1/a;this.n34x=l*h,this.n34y=o*h;let u=this.ratio;this.n34x*=u,this.n34y*=u}else{let h=this.ratio/Math.sqrt(this.n34x*this.n34x+this.n34y*this.n34y);this.n34x*=h,this.n34y*=h}let p=r+this.ratio*a;this.equal?(p-=this.jointMax,this.slack=!1):p<this.jointMin?(p=this.jointMin-p,this.n12x=-this.n12x,this.n12y=-this.n12y,this.n34x=-this.n34x,this.n34y=-this.n34y,this.slack=!1):p>this.jointMax?(p-=this.jointMax,this.slack=!1):(this.n12x=0,this.n12y=0,this.n34x=0,this.n34y=0,p=0,this.slack=!0);let c=p;if(!this.slack){this.cx1=this.n12y*this.a1relx-this.n12x*this.a1rely,this.cx2=this.n12y*this.a2relx-this.n12x*this.a2rely,this.cx3=this.n34y*this.a3relx-this.n34x*this.a3rely,this.cx4=this.n34y*this.a4relx-this.n34x*this.a4rely;let h=this.ratio*this.ratio,u=this.b1.smass+this.b2.smass+h*(this.b3.smass+this.b4.smass)+this.b1.sinertia*this.cx1*this.cx1+this.b2.sinertia*this.cx2*this.cx2+this.b3.sinertia*this.cx3*this.cx3+this.b4.sinertia*this.cx4*this.cx4;if(this.b1==this.b4&&(u-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx4*this.b1.sinertia)),this.b1==this.b3&&(u+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b1.smass+this.cx1*this.cx3*this.b1.sinertia)),this.b2==this.b3&&(u-=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx3*this.b2.sinertia)),this.b2==this.b4&&(u+=2*((this.n12x*this.n34x+this.n12y*this.n34y)*this.b2.smass+this.cx2*this.cx4*this.b2.sinertia)),this.kMass=u,this.kMass!=0?this.kMass=1/this.kMass:this.jAcc=0,this.stiff)this.bias=0,this.gamma=0;else{if(this.breakUnderError&&c*c>this.maxError*this.maxError)return!0;let x=2*Math.PI*this.frequency;this.gamma=1/(t*x*(2*this.damping+x*t));let m=1/(1+this.gamma),_=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!1}warmStart(){if(!this.slack){let t=this.b1.imass*this.jAcc;this.b1.velx-=this.n12x*t,this.b1.vely-=this.n12y*t;let n=this.b2.imass*this.jAcc;this.b2.velx+=this.n12x*n,this.b2.vely+=this.n12y*n;let s=this.b3.imass*this.jAcc;this.b3.velx-=this.n34x*s,this.b3.vely-=this.n34y*s;let i=this.b4.imass*this.jAcc;this.b4.velx+=this.n34x*i,this.b4.vely+=this.n34y*i,this.b1.angvel-=this.cx1*this.b1.iinertia*this.jAcc,this.b2.angvel+=this.cx2*this.b2.iinertia*this.jAcc,this.b3.angvel-=this.cx3*this.b3.iinertia*this.jAcc,this.b4.angvel+=this.cx4*this.b4.iinertia*this.jAcc}}applyImpulseVel(){if(this.slack)return!1;let t=this.n12x*(this.b2.velx+this.b2.kinvelx-this.b1.velx-this.b1.kinvelx)+this.n12y*(this.b2.vely+this.b2.kinvely-this.b1.vely-this.b1.kinvely)+this.n34x*(this.b4.velx+this.b4.kinvelx-this.b3.velx-this.b3.kinvelx)+this.n34y*(this.b4.vely+this.b4.kinvely-this.b3.vely-this.b3.kinvely)+(this.b2.angvel+this.b2.kinangvel)*this.cx2-(this.b1.angvel+this.b1.kinangvel)*this.cx1+(this.b4.angvel+this.b4.kinangvel)*this.cx4-(this.b3.angvel+this.b3.kinangvel)*this.cx3,n=this.kMass*(this.bias-t)-this.jAcc*this.gamma,s=this.jAcc;if(this.jAcc+=n,!this.equal&&this.jAcc>0&&(this.jAcc=0),this.breakUnderForce&&this.jAcc<-this.jMax)return!0;this.stiff||this.jAcc<-this.jMax&&(this.jAcc=-this.jMax),n=this.jAcc-s;let i=this.b1.imass*n;this.b1.velx-=this.n12x*i,this.b1.vely-=this.n12y*i;let l=this.b2.imass*n;this.b2.velx+=this.n12x*l,this.b2.vely+=this.n12y*l;let o=this.b3.imass*n;this.b3.velx-=this.n34x*o,this.b3.vely-=this.n34y*o;let r=this.b4.imass*n;return this.b4.velx+=this.n34x*r,this.b4.vely+=this.n34y*r,this.b1.angvel-=this.cx1*this.b1.iinertia*n,this.b2.angvel+=this.cx2*this.b2.iinertia*n,this.b3.angvel-=this.cx3*this.b3.iinertia*n,this.b4.angvel+=this.cx4*this.b4.iinertia*n,!1}applyImpulsePos(){let t=Me._nape,n,s=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,i=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,l=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,o=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,a=this.a3localx*this.b3.axisx+this.a3localy*this.b3.axisy,p=this.b4.axisy*this.a4localx-this.b4.axisx*this.a4localy,c=this.a4localx*this.b4.axisx+this.a4localy*this.b4.axisy,h,u=this.n12x,x=this.n12y,m=this.n34x,_=this.n34y,y=this.b2.posx+l-(this.b1.posx+s),z=this.b2.posy+o-(this.b1.posy+i),f=this.b4.posx+p-(this.b3.posx+r),w=this.b4.posy+c-(this.b3.posy+a),Z=Math.sqrt(y*y+z*z),d=Math.sqrt(f*f+w*w);if(Z!=0){let P=1/Z;u=y*P,x=z*P}if(d!=0){let P=1/d;m=f*P,_=w*P;let v=this.ratio;m*=v,_*=v}else{let P=this.ratio/Math.sqrt(m*m+_*_);m*=P,_*=P}let b=Z+this.ratio*d;this.equal?(b-=this.jointMax,h=!1):b<this.jointMin?(b=this.jointMin-b,u=-u,x=-x,m=-m,_=-_,h=!1):b>this.jointMax?(b-=this.jointMax,h=!1):(u=0,x=0,m=0,_=0,b=0,h=!0);let g=b;if(!h){if(this.breakUnderError&&g*g>this.maxError*this.maxError)return!0;if(g*g<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;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 L=n*this.b1.imass;this.b1.posx-=u*L,this.b1.posy-=x*L;let T=n*this.b2.imass;this.b2.posx+=u*T,this.b2.posy+=x*T;let R=n*this.b3.imass;this.b3.posx-=m*R,this.b3.posy-=_*R;let q=n*this.b4.imass;this.b4.posx+=m*q,this.b4.posy+=_*q;let G=this.b2.posx+l-(this.b1.posx+s),B=this.b2.posy+o-(this.b1.posy+i),V=this.b4.posx+p-(this.b3.posx+r),Y=this.b4.posy+c-(this.b3.posy+a),$=Math.sqrt(G*G+B*B),X=Math.sqrt(V*V+Y*Y);if($!=0){let ee=1/$;u=G*ee,x=B*ee}if(X!=0){let ee=1/X;m=V*ee,_=Y*ee;let W=this.ratio;m*=W,_*=W}else{let ee=this.ratio/Math.sqrt(m*m+_*_);m*=ee,_*=ee}let H=$+this.ratio*X;this.equal?H-=this.jointMax:H<this.jointMin?(H=this.jointMin-H,u=-u,x=-x,m=-m,_=-_):H>this.jointMax?H-=this.jointMax:(u=0,x=0,m=0,_=0,H=0),g=H,g*=.5}}}let P=x*s-u*i,v=x*l-u*o,N=_*r-m*a,k=_*p-m*c,C=this.ratio*this.ratio,E=this.b1.smass+this.b2.smass+C*(this.b3.smass+this.b4.smass)+this.b1.sinertia*P*P+this.b2.sinertia*v*v+this.b3.sinertia*N*N+this.b4.sinertia*k*k;this.b1==this.b4&&(E-=2*((u*m+x*_)*this.b1.smass+P*k*this.b1.sinertia)),this.b1==this.b3&&(E+=2*((u*m+x*_)*this.b1.smass+P*N*this.b1.sinertia)),this.b2==this.b3&&(E-=2*((u*m+x*_)*this.b2.smass+v*N*this.b2.sinertia)),this.b2==this.b4&&(E+=2*((u*m+x*_)*this.b2.smass+v*k*this.b2.sinertia));let M=E;if(M!=0&&(M=1/M),n=-g*M,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 L=this.b3.imass*n;this.b3.posx-=m*L,this.b3.posy-=_*L;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,k*this.b4.iinertia*n)}}return!1}draw(t){}};vs._wrapFn=null,vs._createFn=null;var fi=vs;var ns=class{constructor(e,t){this.cnt=0;this.body=null;this.cnt=e,this.body=t}};var Xs=class extends Me{constructor(t,n){super();this.outer_zn=null;this.bodies=null;this.dim=0;this.jAcc=null;this.bias=null;this.stepped=!1;this.L=null;this.y=null;this.soft=0;this.gamma=0;this.velonly=!1;this.jMax=0;this.Keff=null;this.vec3=null;this.J=null;this.jOld=null;this.bodies=[],this.dim=t,this.velonly=n,this.jAcc=[],this.bias=[],this.L=[],this.J=[],this.jOld=[],this.y=[],this.Keff=[],this.vec3=Me._nape.geom.Vec3.get(0,0,0);for(let s=0;s<t;s++){let i=this.bias[s]=this.J[s]=this.jOld[s]=this.y[s]=0;this.jAcc[s]=i;for(let l=0;l<t;l++)this.L[s*t+l]=0}this.stepped=!1}bindVec2_invalidate(t){this.outer_zn.__invalidate()}addBody(t){let n=null;for(let s of this.bodies)if(s.body===t){n=s;break}n===null?(this.bodies.push(new ns(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=Me._nape.geom.Vec3.get(0,0,0);return this.stepped&&this.outer_zn.__impulse(this.J,t.outer,n),n}activeBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.add(this)}inactiveBodies(){for(let t of this.bodies)t.body!=null&&t.body.constraints.remove(this)}copy(t,n){let s=this.outer_zn.__copy();throw this.copyto(s),new Error("not done yet")}validate(){for(let t of this.bodies)if(t.body.space!==this.space)throw new Error("Error: Constraints must have each body within the same sapce to which the constraint has been assigned");this.outer_zn.__validate()}wake_connected(){for(let t of this.bodies)t.body.type===2&&t.body.wake()}forest(){for(let t of this.bodies)if(t.body.type===2){let n;if(t.body.component===t.body.component.parent)n=t.body.component;else{let i=t.body.component,l=null;for(;i!==i.parent;){let o=i.parent;i.parent=l,l=i,i=o}for(;l!=null;){let o=l.parent;l.parent=i,l=o}n=i}let s;if(this.component===this.component.parent)s=this.component;else{let i=this.component,l=null;for(;i!==i.parent;){let o=i.parent;i.parent=l,l=i,i=o}for(;l!=null;){let o=l.parent;l.parent=i,l=o}s=i}n!==s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}}pair_exists(t,n){let s=!1,i=this.bodies.length|0;for(let l=0;l<i;l++){let o=this.bodies[l].body;for(let r=l+1;r<i;r++){let a=this.bodies[r].body;if(o.id===t&&a.id===n||o.id===n&&a.id===t){s=!0;break}}if(s)break}return s}broken(){this.outer_zn.__broken()}clearcache(){for(let t=0;t<this.dim;t++)this.jAcc[t]=0;this.pre_dt=-1}lsq(t){let n=0;for(let s=0;s<this.dim;s++)n+=t[s]*t[s];return n}_clamp(t,n){let s=this.lsq(t);if(s>n*n){let i=n/Math.sqrt(s);for(let l=0;l<this.dim;l++)t[l]*=i}}solve(t){let n=0;for(let s=0;s<this.dim;s++){let i=0;for(let o=0;o<s-1;o++)i+=this.L[s*this.dim+o]*this.L[s*this.dim+o];let l=Math.sqrt(t[n++]-i);if(this.L[s*this.dim+s]=l,l!==0){l=1/l;for(let o=s+1;o<this.dim;o++){let r=0;for(let a=0;a<s-1;a++)r+=this.L[o*this.dim+a]*this.L[s*this.dim+a];this.L[o*this.dim+s]=l*(t[n++]-r)}}else{for(let o=s+1;o<this.dim;o++)this.L[o*this.dim+s]=0;n+=this.dim-s-1}}return this.L}transform(t,n){for(let s=0;s<this.dim;s++){let i=n[s],l=t[s*this.dim+s];if(l!==0){for(let o=0;o<s;o++)i-=t[s*this.dim+o]*this.y[o];this.y[s]=i/l}else this.y[s]=0}for(let s=0;s<this.dim;s++){let i=this.dim-1-s,l=t[i*this.dim+i];if(l!==0){let o=this.y[i];for(let r=i+1;r<this.dim;r++)o-=t[r*this.dim+i]*n[r];n[i]=o/l}else n[i]=0}}preStep(t){this.pre_dt===-1&&(this.pre_dt=t);let n=t/this.pre_dt;if(this.pre_dt=t,this.stepped=!0,this.outer_zn.__prepare(),this.outer_zn.__eff_mass(this.Keff),this.L=this.solve(this.Keff),!this.stiff&&!this.velonly){let s=2*Math.PI*this.frequency;this.gamma=1/(t*s*(2*this.damping+s*t));let i=1/(1+this.gamma),l=t*s*s*this.gamma;if(this.gamma*=i,this.soft=i,this.outer_zn.__position(this.bias),this.breakUnderError&&this.lsq(this.bias)>this.maxError*this.maxError)return!0;for(let o=0;o<this.dim;o++)this.bias[o]*=-l;this._clamp(this.bias,this.maxError)}else{for(let s=0;s<this.dim;s++)this.bias[s]=0;this.gamma=0,this.soft=1}for(let s=0;s<this.dim;s++)this.jAcc[s]*=n;return this.jMax=this.maxForce*t,!1}warmStart(){for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.jAcc,n.outer,this.vec3);let s=n.imass,i=n,l=i.velx,o=this.vec3;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let r=o.zpp_inner;r._validate!=null&&r._validate(),i.velx=l+o.zpp_inner.x*s;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let h=c.zpp_inner;h._validate!=null&&h._validate(),a.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=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!0;this.stiff||this._clamp(this.jAcc,this.jMax)}for(let t=0;t<this.dim;t++)this.J[t]=this.jAcc[t]-this.jOld[t];for(let t of this.bodies){let n=t.body;this.outer_zn.__impulse(this.J,n.outer,this.vec3);let s=n.imass,i=n,l=i.velx,o=this.vec3;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let r=o.zpp_inner;r._validate!=null&&r._validate(),i.velx=l+o.zpp_inner.x*s;let a=n,p=a.vely,c=this.vec3;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let h=c.zpp_inner;h._validate!=null&&h._validate(),a.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,m=this.vec3;if(m!=null&&m.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=m.zpp_inner;_._validate!=null&&_._validate(),u.angvel=x+m.zpp_inner.z*n.iinertia}return!1}applyImpulsePos(){if(this.velonly)return!1;this.outer_zn.__prepare(),this.outer_zn.__position(this.J);let t=this.lsq(this.J);if(this.breakUnderError&&t>this.maxError*this.maxError)return!0;if(t<Me._nape.Config.constraintLinearSlop*Me._nape.Config.constraintLinearSlop)return!1;for(let n=0;n<this.dim;n++)this.J[n]*=-1;this.outer_zn.__eff_mass(this.Keff),this.transform(this.solve(this.Keff),this.J),this.outer_zn.__clamp(this.J);for(let n of this.bodies){let s=n.body;this.outer_zn.__impulse(this.J,s.outer,this.vec3);let i=s.imass,l=s,o=l.posx,r=this.vec3;if(r!=null&&r.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let a=r.zpp_inner;a._validate!=null&&a._validate(),l.posx=o+r.zpp_inner.x*i;let p=s,c=p.posy,h=this.vec3;if(h!=null&&h.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let u=h.zpp_inner;u._validate!=null&&u._validate(),p.posy=c+h.zpp_inner.y*i;let x=this.vec3;if(x!=null&&x.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let m=x.zpp_inner;m._validate!=null&&m._validate();let _=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,f=1-y*y/8,w=(z*s.axisx+_*s.axisy)*f;s.axisy=(z*s.axisy-_*s.axisx)*f,s.axisx=w}}return!1}draw(t){this.outer_zn.__draw(t)}};var gs=class gs extends Me{constructor(){super();this.outer_zn=null;this.b1=null;this.b2=null;this.a1localx=0;this.a1localy=0;this.a1relx=0;this.a1rely=0;this.wrap_a1=null;this.a2localx=0;this.a2localy=0;this.a2relx=0;this.a2rely=0;this.wrap_a2=null;this.phase=0;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.kMassd=0;this.kMasse=0;this.kMassf=0;this.jAccx=0;this.jAccy=0;this.jAccz=0;this.jMax=1/0;this.gamma=0;this.biasx=0;this.biasy=0;this.biasz=0;this.stepped=!1;this.phase=0,this.jAccx=0,this.jAccy=0,this.jAccz=0,this.jMax=1/0,this.stepped=!1,this.a1localx=0,this.a1localy=0,this.a1relx=0,this.a1rely=0,this.a2localx=0,this.a2localy=0,this.a2relx=0,this.a2rely=0}bodyImpulse(t){let n=Me._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=Me._nape,n=Me._zpp,s=this.a1localx,i=this.a1localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=s,o.y=i,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),r=l.zpp_inner.y==i}else r=!1;if(!r){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a1=l,this.wrap_a1.zpp_inner._inuse=!0,this.wrap_a1.zpp_inner._validate=this.validate_a1.bind(this),this.wrap_a1.zpp_inner._invalidate=this.invalidate_a1.bind(this)}validate_a2(){this.wrap_a2.zpp_inner.x=this.a2localx,this.wrap_a2.zpp_inner.y=this.a2localy}invalidate_a2(t){this.immutable_midstep("Constraint::a2"),this.a2localx=t.x,this.a2localy=t.y,this.wake()}setup_a2(){let t=Me._nape,n=Me._zpp,s=this.a2localx,i=this.a2localy;if(i==null&&(i=0),s==null&&(s=0),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let l;if(n.util.ZPP_PubPool.poolVec2==null?l=new t.geom.Vec2:(l=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let o;n.geom.ZPP_Vec2.zpp_pool==null?o=new n.geom.ZPP_Vec2:(o=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=s,o.y=i,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),r=l.zpp_inner.y==i}else r=!1;if(!r){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_a2=l,this.wrap_a2.zpp_inner._inuse=!0,this.wrap_a2.zpp_inner._validate=this.validate_a2.bind(this),this.wrap_a2.zpp_inner._invalidate=this.invalidate_a2.bind(this)}copy(t,n){let s=this.outer_zn;s.zpp_inner_zn.wrap_a1==null&&s.zpp_inner_zn.setup_a1();let i=s.zpp_inner_zn.wrap_a1,l=this.outer_zn;l.zpp_inner_zn.wrap_a2==null&&l.zpp_inner_zn.setup_a2();let o=gs._createFn(null,null,i,l.zpp_inner_zn.wrap_a2);return this.copyto(o),Re._copyBody(t,n,this.b1,o,"b1"),Re._copyBody(t,n,this.b2,o,"b2"),o}validate(){if(this.b1==null||this.b2==null)throw new Error("Error: AngleJoint cannot be simulated null bodies");if(this.b1==this.b2)throw new Error("Error: WeldJoint cannot be simulated with body1 == body2");if(this.b1.space!=this.space||this.b2.space!=this.space)throw new Error("Error: Constraints must have each body within the same space to which the constraint has been assigned");if(this.b1.type!=2&&this.b2.type!=2)throw new Error("Error: Constraints cannot have both bodies non-dynamic")}wake_connected(){this.b1!=null&&this.b1.type==2&&this.b1.wake(),this.b2!=null&&this.b2.type==2&&this.b2.wake()}forest(){this.b1.type==2&&Me._unionComponents(this.b1.component,this.component),this.b2.type==2&&Me._unionComponents(this.b2.component,this.component)}pair_exists(t,n){return this.b1.id==t&&this.b2.id==n?!0:this.b1.id==n?this.b2.id==t:!1}clearcache(){this.jAccx=0,this.jAccy=0,this.jAccz=0,this.pre_dt=-1}preStep(t){this.pre_dt==-1&&(this.pre_dt=t);let n=t/this.pre_dt;this.pre_dt=t,this.stepped=!0,this.a1relx=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,this.a1rely=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,this.a2relx=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,this.a2rely=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy;let s=this.b1.smass+this.b2.smass;if(this.kMassa=s,this.kMassb=0,this.kMassd=s,this.kMassc=0,this.kMasse=0,this.kMassf=0,this.b1.sinertia!=0){let o=this.a1relx*this.b1.sinertia,r=this.a1rely*this.b1.sinertia;this.kMassa+=r*this.a1rely,this.kMassb+=-r*this.a1relx,this.kMassd+=o*this.a1relx,this.kMassc+=-r,this.kMasse+=o,this.kMassf+=this.b1.sinertia}if(this.b2.sinertia!=0){let o=this.a2relx*this.b2.sinertia,r=this.a2rely*this.b2.sinertia;this.kMassa+=r*this.a2rely,this.kMassb+=-r*this.a2relx,this.kMassd+=o*this.a2relx,this.kMassc+=-r,this.kMasse+=o,this.kMassf+=this.b2.sinertia}let i=this.kMassa*(this.kMassd*this.kMassf-this.kMasse*this.kMasse)+this.kMassb*(this.kMassc*this.kMasse-this.kMassb*this.kMassf)+this.kMassc*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),l;if(i!=i)this.kMassa=0,this.kMassb=0,this.kMassd=0,this.kMassc=0,this.kMasse=0,this.kMassf=0,l=7;else if(i==0){let o=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,o|=1),this.kMassd!=0?this.kMassd=1/this.kMassd:(this.kMassd=0,o|=2),this.kMassf!=0?this.kMassf=1/this.kMassf:(this.kMassf=0,o|=4),this.kMassb=this.kMassc=this.kMasse=0,l=o}else{let o=1/i,r=o*(this.kMassd*this.kMassf-this.kMasse*this.kMasse),a=o*(this.kMasse*this.kMassc-this.kMassb*this.kMassf),p=o*(this.kMassa*this.kMassf-this.kMassc*this.kMassc),c=o*(this.kMassb*this.kMasse-this.kMassc*this.kMassd),h=o*(this.kMassb*this.kMassc-this.kMassa*this.kMasse),u=o*(this.kMassa*this.kMassd-this.kMassb*this.kMassb);this.kMassa=r,this.kMassb=a,this.kMassd=p,this.kMassc=c,this.kMasse=h,this.kMassf=u,l=0}if((l&1)!=0&&(this.jAccx=0),(l&2)!=0&&(this.jAccy=0),(l&4)!=0&&(this.jAccz=0),this.stiff)this.biasx=0,this.biasy=0,this.biasz=0,this.gamma=0;else{let o=2*Math.PI*this.frequency;this.gamma=1/(t*o*(2*this.damping+o*t));let r=1/(1+this.gamma),a=t*o*o*this.gamma;this.gamma*=r;let p=r;if(this.kMassa*=p,this.kMassb*=p,this.kMassd*=p,this.kMassc*=p,this.kMasse*=p,this.kMassf*=p,this.biasx=this.b2.posx+this.a2relx-(this.b1.posx+this.a1relx),this.biasy=this.b2.posy+this.a2rely-(this.b1.posy+this.a1rely),this.biasz=this.b2.rot-this.b1.rot-this.phase,this.breakUnderError&&this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz>this.maxError*this.maxError)return!0;let c=-a;this.biasx*=c,this.biasy*=c,this.biasz*=c;let h=this.maxError,u=this.biasx*this.biasx+this.biasy*this.biasy+this.biasz*this.biasz;if(u>h*h){let x=h*(1/Math.sqrt(u));this.biasx*=x,this.biasy*=x,this.biasz*=x}}return this.jAccx*=n,this.jAccy*=n,this.jAccz*=n,this.jMax=this.maxForce*t,!1}warmStart(){let t=this.b1.imass;this.b1.velx-=this.jAccx*t,this.b1.vely-=this.jAccy*t;let n=this.b2.imass;this.b2.velx+=this.jAccx*n,this.b2.vely+=this.jAccy*n,this.b1.angvel-=(this.jAccy*this.a1relx-this.jAccx*this.a1rely+this.jAccz)*this.b1.iinertia,this.b2.angvel+=(this.jAccy*this.a2relx-this.jAccx*this.a2rely+this.jAccz)*this.b2.iinertia}applyImpulseVel(){let t=this.b2.velx+this.b2.kinvelx-this.a2rely*(this.b2.angvel+this.b2.kinangvel)-(this.b1.velx+this.b1.kinvelx-this.a1rely*(this.b1.angvel+this.b1.kinangvel)),n=this.b2.vely+this.b2.kinvely+this.a2relx*(this.b2.angvel+this.b2.kinangvel)-(this.b1.vely+this.b1.kinvely+this.a1relx*(this.b1.angvel+this.b1.kinangvel)),s=this.b2.angvel+this.b2.kinangvel-this.b1.angvel-this.b1.kinangvel,i=this.biasx-t,l=this.biasy-n,o=this.biasz-s,r=this.kMassa*i+this.kMassb*l+this.kMassc*o,a=this.kMassb*i+this.kMassd*l+this.kMasse*o;o=this.kMassc*i+this.kMasse*l+this.kMassf*o,i=r,l=a,i-=this.jAccx*this.gamma,l-=this.jAccy*this.gamma,o-=this.jAccz*this.gamma;let p=this.jAccx,c=this.jAccy,h=this.jAccz;if(this.jAccx+=i,this.jAccy+=l,this.jAccz+=o,this.breakUnderForce){if(this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz>this.jMax*this.jMax)return!0}else if(!this.stiff){let m=this.jMax,_=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,o=this.jAccz-h;let u=this.b1.imass;this.b1.velx-=i*u,this.b1.vely-=l*u;let x=this.b2.imass;return this.b2.velx+=i*x,this.b2.vely+=l*x,this.b1.angvel-=(l*this.a1relx-i*this.a1rely+o)*this.b1.iinertia,this.b2.angvel+=(l*this.a2relx-i*this.a2rely+o)*this.b2.iinertia,!1}applyImpulsePos(){let t=Me._nape,n=this.b1.axisy*this.a1localx-this.b1.axisx*this.a1localy,s=this.a1localx*this.b1.axisx+this.a1localy*this.b1.axisy,i=this.b2.axisy*this.a2localx-this.b2.axisx*this.a2localy,l=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,p,c,h;if(this.breakUnderError&&o*o+r*r+a*a>this.maxError*this.maxError)return!0;let u=!0;o*o+r*r<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(u=!1,o=0,r=0);let x=t.Config.constraintAngularSlop;if(a*a<x*x)if(u)a=0;else return!1;if(o*=.5,r*=.5,a*=.5,o*o+r*r>6){let O=this.b1.smass+this.b2.smass;if(O>t.Config.epsilon){let L=.75/O;p=-o*L,c=-r*L;let T=20,R=p*p+c*c;if(R>T*T){let B=T*(1/Math.sqrt(R));p*=B,c*=B}let q=this.b1.imass;this.b1.posx-=p*q,this.b1.posy-=c*q;let G=this.b2.imass;this.b2.posx+=p*G,this.b2.posy+=c*G,o=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s),a=this.b2.rot-this.b1.rot-this.phase,o*=.5,r*=.5,a*=.5}}let m=this.b1.smass+this.b2.smass,_=m,y=0,z=m,f=0,w=0,Z=0;if(this.b1.sinertia!=0){let O=n*this.b1.sinertia,L=s*this.b1.sinertia;_+=L*s,y+=-L*n,z+=O*n,f+=-L,w+=O,Z+=this.b1.sinertia}if(this.b2.sinertia!=0){let O=i*this.b2.sinertia,L=l*this.b2.sinertia;_+=L*l,y+=-L*i,z+=O*i,f+=-L,w+=O,Z+=this.b2.sinertia}p=-o,c=-r,h=-a;let d=6,b=p*p+c*c;if(b>d*d){let O=d*(1/Math.sqrt(b));p*=O,c*=O}let P=h<-.25,v=_*(z*Z-w*w)+y*(f*w-y*Z)+f*(y*w-f*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,L=w*f-y*Z,T=y*w-f*z,R=y*f-_*w,q=O*(p*(z*Z-w*w)+c*L+h*T),G=O*(p*L+c*(_*Z-f*f)+h*R);h=O*(p*T+c*R+h*(_*z-y*y)),p=q,c=G}let N=this.b1.imass;this.b1.posx-=p*N,this.b1.posy-=c*N;let k=this.b2.imass;this.b2.posx+=p*k,this.b2.posy+=c*k;let C=this.b1,E=-(c*n-p*s+h)*this.b1.iinertia;Re._rotateBody(C,E);let M=this.b2,S=(c*i-p*l+h)*this.b2.iinertia;return Re._rotateBody(M,S),!1}draw(t){}};gs._wrapFn=null,gs._createFn=null;var bi=gs;var nt=class nt{constructor(){this.outer=null;this.hnext=null;this.id=0;this.di=0;this.stamp=0;this.up_stamp=0;this.sleep_stamp=0;this.endGenerated=0;this.active=!1;this.cleared=!1;this.sleeping=!1;this.present=0;this.intchange=!1;this.presentable=!1;this.continuous=!1;this.fresh=!1;this.immState=0;this.invalidated=!1;this.b1=null;this.b2=null;this.ws1=null;this.ws2=null;this.pair=null;this.type=0;this.colarb=null;this.fluidarb=null;this.sensorarb=null;this.sensorarb=null,this.fluidarb=null,this.colarb=null,this.type=0,this.pair=null,this.ws2=null,this.ws1=null,this.b2=null,this.b1=null,this.invalidated=!1,this.immState=0,this.fresh=!1,this.continuous=!1,this.presentable=!1,this.intchange=!1,this.present=0,this.sleeping=!1,this.cleared=!1,this.active=!1,this.endGenerated=0,this.sleep_stamp=0,this.up_stamp=0,this.stamp=0,this.di=0,this.id=0,this.hnext=null,this.outer=null}static _initEnums(e,t){let n=()=>{t.internal=!0;let s=new e.dynamics.ArbiterType;return t.internal=!1,s};t.ArbiterType_COLLISION==null&&(t.ArbiterType_COLLISION=n()),t.ArbiterType_SENSOR==null&&(t.ArbiterType_SENSOR=n()),t.ArbiterType_FLUID==null&&(t.ArbiterType_FLUID=n()),nt.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID]}wrapper(){if(this.outer==null){let e=nt._nape;nt.internal=!0,this.type==nt.COL?(this.colarb.outer_zn=nt._createColArb(),this.outer=this.colarb.outer_zn):this.type==nt.FLUID?(this.fluidarb.outer_zn=nt._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,nt.internal=!1}return this.outer}inactiveme(){return!this.active}acting(){return this.active?(this.immState&1)!=0:!1}swap_features(){let e=this.b1;this.b1=this.b2,this.b2=e,e=this.ws1,this.ws1=this.ws2,this.ws2=e,e=this.colarb.s1,this.colarb.s1=this.colarb.s2,this.colarb.s2=e}lazyRetire(e,t){let n=nt._zpp;this.cleared=!0,(t==null||this.b2==t)&&nt._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&nt._removeFromArbiterList(this.b2.arbiters,this,n),this.pair!=null&&(this.pair.arb=null,this.pair=null),this.active=!1,e.f_arbiters.modified=!0}sup_assign(e,t,n,s){let i=nt._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=s,nt._addToArbiterList(this.b1.arbiters,this,i),nt._addToArbiterList(this.b2.arbiters,this,i),this.active=!0,this.present=0,this.cleared=!1,this.sleeping=!1,this.fresh=!1,this.presentable=!1}sup_retire(){let e=nt._zpp;this.cleared||(nt._removeFromArbiterList(this.b1.arbiters,this,e),nt._removeFromArbiterList(this.b2.arbiters,this,e),this.pair!=null&&(this.pair.arb=null,this.pair=null)),this.b1=this.b2=null,this.active=!1,this.intchange=!1}static _removeFromArbiterList(e,t,n){let s=null,i=e.head;for(;i!=null;){if(i.elt==t){let l,o;s==null?(l=e.head,o=l.next,e.head=o,e.head==null&&(e.pushmod=!0)):(l=s.next,o=l.next,s.next=o,o==null&&(e.pushmod=!0));let r=l;r.elt=null,r.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=r,e.modified=!0,e.length--,e.pushmod=!0;break}s=i,i=i.next}}static _addToArbiterList(e,t,n){let s;n.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?s=new n.util.ZNPNode_ZPP_Arbiter:(s=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=s.next,s.next=null),s.elt=t;let i=s;i.next=e.head,e.head=i,e.modified=!0,e.length++}};nt._nape=null,nt._zpp=null,nt.internal=!1,nt._createColArb=null,nt._createFluidArb=null,nt.COL=1,nt.FLUID=4,nt.SENSOR=2,nt.types=[];var Ie=nt;var 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=!1;this.wMass=0;this.adamp=0;this.agamma=0;this.vMassa=0;this.vMassb=0;this.vMassc=0;this.dampx=0;this.dampy=0;this.lgamma=0;this.nx=0;this.ny=0;this.buoyx=0;this.buoyy=0;this.wrap_position=null;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.wrap_position=null,this.buoyy=0,this.buoyx=0,this.ny=0,this.nx=0,this.lgamma=0,this.dampy=0,this.dampx=0,this.vMassc=0,this.vMassb=0,this.vMassa=0,this.agamma=0,this.adamp=0,this.wMass=0,this.nodrag=!1,this.r2y=0,this.r2x=0,this.r1y=0,this.r1x=0,this.overlap=0,this.centroidy=0,this.centroidx=0,this.next=null,this.outer_zn=null,this.type=Ie.FLUID,this.fluidarb=this,this.buoyx=0,this.buoyy=0,this.pre_dt=-1}alloc(){}free(){}position_validate(){if(!this.active)throw new Error("Error: Arbiter not currently in use");this.wrap_position.zpp_inner.x=this.centroidx,this.wrap_position.zpp_inner.y=this.centroidy}position_invalidate(t){this.centroidx=t.x,this.centroidy=t.y}getposition(){let t=Ie._zpp,n=Ie._nape,s;if(t.util.ZPP_PubPool.poolVec2==null?s=new n.geom.Vec2:(s=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),s.zpp_inner==null){let i;t.geom.ZPP_Vec2.zpp_pool==null?i=new t.geom.ZPP_Vec2:(i=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=0,i.y=0,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");i._isimmutable!=null&&i._isimmutable();let l;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=s.zpp_inner;if(o._validate!=null&&o._validate(),s.zpp_inner.x==0){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=s.zpp_inner;r._validate!=null&&r._validate(),l=s.zpp_inner.y==0}else l=!1;if(!l){s.zpp_inner.x=0,s.zpp_inner.y=0;let r=s.zpp_inner;r._invalidate!=null&&r._invalidate(r)}}s.zpp_inner.weak=!1,this.wrap_position=s,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!this.mutable,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this),this.wrap_position.zpp_inner._invalidate=this.position_invalidate.bind(this)}assign(t,n,s,i){this.sup_assign(t,n,s,i),this.nx=0,this.ny=1,this.dampx=0,this.dampy=0,this.adamp=0}retire(){this.sup_retire(),this.next=Ms.zpp_pool,Ms.zpp_pool=this,this.pre_dt=-1}makemutable(){this.mutable=!0,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=!1)}makeimmutable(){this.mutable=!1,this.wrap_position!=null&&(this.wrap_position.zpp_inner._immutable=!0)}inject(t,n,s){this.overlap=t,this.centroidx=n,this.centroidy=s}preStep(t,n){let s=Ie._nape;this.pre_dt==-1&&(this.pre_dt=n);let i=n/this.pre_dt;this.pre_dt=n,this.r1x=this.centroidx-this.b1.posx,this.r1y=this.centroidy-this.b1.posy,this.r2x=this.centroidx-this.b2.posx,this.r2y=this.centroidy-this.b2.posy;let l,o;this.ws1.fluidEnabled&&this.ws1.fluidProperties.wrap_gravity!=null?(l=this.ws1.fluidProperties.gravityx,o=this.ws1.fluidProperties.gravityy):(l=t.gravityx,o=t.gravityy);let r,a;this.ws2.fluidEnabled&&this.ws2.fluidProperties.wrap_gravity!=null?(r=this.ws2.fluidProperties.gravityx,a=this.ws2.fluidProperties.gravityy):(r=t.gravityx,a=t.gravityy);let p=0,c=0;if(this.ws1.fluidEnabled&&this.ws2.fluidEnabled){let h=this.overlap*this.ws1.fluidProperties.density,u=this.overlap*this.ws2.fluidProperties.density;if(h>u){let x=h+u;p-=l*x,c-=o*x}else if(h<u){let x=h+u;p+=r*x,c+=a*x}else{let x=l+r,m=o+a,_=.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-=o*h}else if(this.ws2.fluidEnabled){let h=this.overlap*this.ws2.fluidProperties.density;p+=r*h,c+=a*h}if(p*=n,c*=n,this.buoyx=p,this.buoyy=c,this.b1.type==2&&(this.b1.velx-=p*this.b1.imass,this.b1.vely-=c*this.b1.imass,this.b1.angvel-=(c*this.r1x-p*this.r1y)*this.b1.iinertia),this.b2.type==2&&(this.b2.velx+=p*this.b2.imass,this.b2.vely+=c*this.b2.imass,this.b2.angvel+=(c*this.r2x-p*this.r2y)*this.b2.iinertia),(!this.ws1.fluidEnabled||this.ws1.fluidProperties.viscosity==0)&&(!this.ws2.fluidEnabled||this.ws2.fluidProperties.viscosity==0))this.nodrag=!0,this.dampx=0,this.dampy=0,this.adamp=0;else{this.nodrag=!1;let h=0;if(this.ws1.fluidEnabled&&(this.ws2.validate_angDrag(),h+=this.ws1.fluidProperties.viscosity*this.ws2.angDrag*this.overlap/this.ws2.area),this.ws2.fluidEnabled&&(this.ws1.validate_angDrag(),h+=this.ws2.fluidProperties.viscosity*this.ws1.angDrag*this.overlap/this.ws1.area),h!=0){let _=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,f=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),f-=d*.5*s.Config.fluidLinearDrag,w=w.next}m+=f/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,f=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),f-=d*.5*s.Config.fluidLinearDrag,w=w.next}m+=f/z}}if(m!=0){let _=this.b1.smass+this.b2.smass,y=_,z=0,f=_;if(this.b1.sinertia!=0){let b=this.r1x*this.b1.sinertia,g=this.r1y*this.b1.sinertia;y+=g*this.r1y,z+=-g*this.r1x,f+=b*this.r1x}if(this.b2.sinertia!=0){let b=this.r2x*this.b2.sinertia,g=this.r2y*this.b2.sinertia;y+=g*this.r2y,z+=-g*this.r2x,f+=b*this.r2x}let w=y*f-z*z;if(w!==w)f=0,z=f,y=z;else if(w==0)y!=0?y=1/y:y=0,f!=0?f=1/f:f=0,z=0;else{let b=1/w,g=f*b;f=y*b,y=g,z*=-b}this.vMassa=y,this.vMassb=z,this.vMassc=f;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 o=(t-n)*this.wMass-this.adamp*this.agamma;this.adamp+=o,this.b1.angvel-=o*this.b1.iinertia,this.b2.angvel+=o*this.b2.iinertia}}};Ms.zpp_pool=null;var Pt=Ms;var zi=class{constructor(){this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.r1x=0;this.r1y=0;this.r2x=0;this.r2y=0;this.nMass=0;this.tMass=0;this.bounce=0;this.friction=0;this.jnAcc=0;this.jtAcc=0;this.lr1x=0;this.lr1y=0;this.lr2x=0;this.lr2y=0}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};var yn=class yn{constructor(){this.outer=null;this.px=0;this.py=0;this.wrap_position=null;this.arbiter=null;this.active=!1;this.posOnly=!1;this.stamp=0;this.hash=0;this.fresh=!1;this.dist=0;this.elasticity=0;this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.length=0,this.pushmod=!1,this.modified=!1,this._inuse=!1,this.next=null,this.elasticity=0,this.dist=0,this.fresh=!1,this.hash=0,this.stamp=0,this.posOnly=!1,this.active=!1,this.inner=null,this.arbiter=null,this.wrap_position=null,this.py=0,this.px=0,this.outer=null,this.inner=new zi}wrapper(){return this.outer==null&&(yn._wrapFn?this.outer=yn._wrapFn(this):(yn.internal=!0,this.outer=new yn._nape.dynamics.Contact,yn.internal=!1,this.outer.zpp_inner=this)),this.outer}position_validate(){if(this.inactiveme())throw new Error("Error: Contact not currently in use");this.wrap_position.zpp_inner.x=this.px,this.wrap_position.zpp_inner.y=this.py}getposition(){let e=yn._zpp,t=yn._nape,n;if(e.util.ZPP_PubPool.poolVec2==null?n=new t.geom.Vec2:(n=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let s;e.geom.ZPP_Vec2.zpp_pool==null?s=new e.geom.ZPP_Vec2:(s=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){n.zpp_inner.x=0,n.zpp_inner.y=0;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.wrap_position=n,this.wrap_position.zpp_inner._inuse=!0,this.wrap_position.zpp_inner._immutable=!0,this.wrap_position.zpp_inner._validate=this.position_validate.bind(this)}inactiveme(){return!(this.active&&this.arbiter!=null&&this.arbiter.active)}free(){this.arbiter=null}alloc(){}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}};yn._nape=null,yn._zpp=null,yn.zpp_pool=null,yn.internal=!1,yn._wrapFn=null;var Pe=yn;var wt=class wt extends Ie{constructor(){super();this.outer_zn=null;this.dyn_fric=0;this.stat_fric=0;this.restitution=0;this.rfric=0;this.userdef_dyn_fric=!1;this.userdef_stat_fric=!1;this.userdef_restitution=!1;this.userdef_rfric=!1;this.s1=null;this.s2=null;this.wrap_contacts=null;this.nx=0;this.ny=0;this.wrap_normal=null;this.kMassa=0;this.kMassb=0;this.kMassc=0;this.Ka=0;this.Kb=0;this.Kc=0;this.rMass=0;this.jrAcc=0;this.rn1a=0;this.rt1a=0;this.rn1b=0;this.rt1b=0;this.rn2a=0;this.rt2a=0;this.rn2b=0;this.rt2b=0;this.k1x=0;this.k1y=0;this.k2x=0;this.k2y=0;this.surfacex=0;this.surfacey=0;this.ptype=0;this.lnormx=0;this.lnormy=0;this.lproj=0;this.radius=0;this.rev=!1;this.biasCoef=0;this.__ref_edge1=null;this.__ref_edge2=null;this.__ref_vertex=0;this.c1=null;this.oc1=null;this.c2=null;this.oc2=null;this.hc2=!1;this.hpc2=!1;this.stat=!1;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.stat=!1,this.next=null,this.hpc2=!1,this.hc2=!1,this.oc2=null,this.c2=null,this.oc1=null,this.c1=null,this.__ref_vertex=0,this.__ref_edge2=null,this.__ref_edge1=null,this.biasCoef=0,this.rev=!1,this.radius=0,this.lproj=0,this.lnormy=0,this.lnormx=0,this.surfacey=0,this.surfacex=0,this.k2y=0,this.k2x=0,this.k1y=0,this.k1x=0,this.rt2b=0,this.rn2b=0,this.rt2a=0,this.rn2a=0,this.rt1b=0,this.rn1b=0,this.rt1a=0,this.rn1a=0,this.jrAcc=0,this.rMass=0,this.Kc=0,this.Kb=0,this.Ka=0,this.kMassc=0,this.kMassb=0,this.kMassa=0,this.wrap_normal=null,this.ny=0,this.nx=0,this.innards=null,this.wrap_contacts=null,this.contacts=null,this.s2=null,this.s1=null,this.userdef_rfric=!1,this.userdef_restitution=!1,this.userdef_stat_fric=!1,this.userdef_dyn_fric=!1,this.rfric=0,this.restitution=0,this.stat_fric=0,this.dyn_fric=0,this.outer_zn=null,this.pre_dt=-1,this.contacts=new Pe,this.innards=new zi,this.type=Ie.COL,this.colarb=this}alloc(){}free(){this.userdef_dyn_fric=!1,this.userdef_stat_fric=!1,this.userdef_restitution=!1,this.userdef_rfric=!1,this.__ref_edge1=this.__ref_edge2=null}normal_validate(){if(this.cleared)throw new Error("Error: Arbiter not currently in use");this.wrap_normal.zpp_inner.x=this.nx,this.wrap_normal.zpp_inner.y=this.ny,this.ws1.id>this.ws2.id&&(this.wrap_normal.zpp_inner.x=-this.wrap_normal.zpp_inner.x,this.wrap_normal.zpp_inner.y=-this.wrap_normal.zpp_inner.y)}getnormal(){let t=Ie._zpp,n=Ie._nape,s=0,i=0,l;if(t.util.ZPP_PubPool.poolVec2==null?l=new n.geom.Vec2:(l=t.util.ZPP_PubPool.poolVec2,t.util.ZPP_PubPool.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l==t.util.ZPP_PubPool.nextVec2&&(t.util.ZPP_PubPool.nextVec2=null)),l.zpp_inner==null){let o;t.geom.ZPP_Vec2.zpp_pool==null?o=new t.geom.ZPP_Vec2:(o=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=s,o.y=i,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),s!==s||i!==i)throw new Error("Error: Vec2 components cannot be NaN");let r;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=l.zpp_inner;if(a._validate!=null&&a._validate(),l.zpp_inner.x==s){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate(),r=l.zpp_inner.y==i}else r=!1;if(!r){l.zpp_inner.x=s,l.zpp_inner.y=i;let p=l.zpp_inner;p._invalidate!=null&&p._invalidate(p)}}l.zpp_inner.weak=!1,this.wrap_normal=l,this.wrap_normal.zpp_inner._immutable=!0,this.wrap_normal.zpp_inner._inuse=!0,this.wrap_normal.zpp_inner._validate=this.normal_validate.bind(this)}injectContact(t,n,s,i,l,o,r=!1){let a=null,p=this.contacts.next;for(;p!=null;){if(o==p.hash){a=p;break}p=p.next}if(a==null){Pe.zpp_pool==null?a=new Pe:(a=Pe.zpp_pool,Pe.zpp_pool=a.next,a.next=null);let c=a.inner;c.jnAcc=c.jtAcc=0,a.hash=o,a.fresh=!0,a.arbiter=this,this.jrAcc=0,a._inuse=!0,a.next=this.contacts.next,this.contacts.next=a,this.contacts.modified=!0,this.contacts.length++,this.innards.add(c)}else a.fresh=!1;return a.px=t,a.py=n,this.nx=s,this.ny=i,a.dist=l,a.stamp=this.stamp,a.posOnly=r,a}assign(t,n,s,i){this.sup_assign(t,n,s,i),this.s1=t,this.s2=n,this._calcFrictionRestitution()}calcProperties(){this._calcFrictionRestitution()}validate_props(){this.invalidated&&(this.invalidated=!1,this._calcFrictionRestitution())}_calcFrictionRestitution(){this.userdef_restitution||(this.s1.material.elasticity<=-1/0||this.s2.material.elasticity<=-1/0?this.restitution=0:this.s1.material.elasticity>=1/0||this.s2.material.elasticity>=1/0?this.restitution=1:this.restitution=(this.s1.material.elasticity+this.s2.material.elasticity)/2,this.restitution<0&&(this.restitution=0),this.restitution>1&&(this.restitution=1)),this.userdef_dyn_fric||(this.dyn_fric=Math.sqrt(this.s1.material.dynamicFriction*this.s2.material.dynamicFriction)),this.userdef_stat_fric||(this.stat_fric=Math.sqrt(this.s1.material.staticFriction*this.s2.material.staticFriction)),this.userdef_rfric||(this.rfric=Math.sqrt(this.s1.material.rollingFriction*this.s2.material.rollingFriction))}retire(){for(this.sup_retire();this.contacts.next!=null;){let t=this.contacts.next;this.contacts.pop(),t.arbiter=null,t.next=Pe.zpp_pool,Pe.zpp_pool=t;let n=this.innards.next;this.innards.next=n.next,n._inuse=!1,this.innards.next==null&&(this.innards.pushmod=!0),this.innards.modified=!0,this.innards.length--}this.free(),this.next=wt.zpp_pool,wt.zpp_pool=this,this.pre_dt=-1}makemutable(){this.mutable=!0,this.wrap_normal!=null&&(this.wrap_normal.zpp_inner._immutable=!1),this.wrap_contacts!=null&&(this.wrap_contacts.zpp_inner.immutable=!1)}makeimmutable(){this.mutable=!1,this.wrap_normal!=null&&(this.wrap_normal.zpp_inner._immutable=!0),this.wrap_contacts!=null&&(this.wrap_contacts.zpp_inner.immutable=!0)}contacts_adder(t){throw new Error("Error: Cannot add new contacts, information required is far too specific and detailed :)")}contacts_subber(t){let n=null,s=null,i=this.innards.next,l=this.contacts.next;for(;l!=null;){if(l==t.zpp_inner){this.contacts.erase(n),this.innards.erase(s),l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;break}n=l,s=i,i=i.next,l=l.next}}setupcontacts(){let t=Ie._zpp;this.wrap_contacts=t.util.ZPP_ContactList.get(this.contacts,!0),this.wrap_contacts.zpp_inner.immutable=!this.mutable,this.wrap_contacts.zpp_inner.adder=this.contacts_adder.bind(this),this.wrap_contacts.zpp_inner.dontremove=!0,this.wrap_contacts.zpp_inner.subber=this.contacts_subber.bind(this)}cleanupContacts(){let t=Ie._nape,n=!0,s=null,i=null,l=this.innards.next;this.hc2=!1;let o=this.contacts.next;for(;o!=null;){let r=o;if(r.stamp+t.Config.arbiterExpirationDelay<this.stamp){o=wt._eraseFromList(this.contacts,s),l=wt._eraseFromList(this.innards,i),r.arbiter=null,r.next=Pe.zpp_pool,Pe.zpp_pool=r;continue}let a=r.inner,p=r.active;r.active=r.stamp==this.stamp,r.active&&(n?(n=!1,this.c1=a,this.oc1=r):(this.hc2=!0,this.c2=a,this.oc2=r)),p!=r.active&&(this.contacts.modified=!0),s=o,i=l,l=l.next,o=o.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let r=this.c1;this.c1=this.c2,this.c2=r,r=this.oc1,this.oc1=this.oc2,this.oc2=r,this.hc2=!1}else this.oc2.posOnly&&(this.hc2=!1);this.oc1.posOnly&&(n=!0)}else this.hpc2=!1;return n}preStep(t){let n=Ie._nape;this.validate_props(),this.pre_dt==-1&&(this.pre_dt=t);let s=t/this.pre_dt;this.pre_dt=t;let i=this.b1.smass+this.b2.smass;this.hc2=!1;let l=!0,r=this.b1.type!=2||this.b2.type!=2?this.continuous?n.Config.contactContinuousStaticBiasCoef:n.Config.contactStaticBiasCoef:this.continuous?n.Config.contactContinuousBiasCoef:n.Config.contactBiasCoef;this.biasCoef=r,this.continuous=!1;let a=null,p=null,c=this.innards.next,h=this.contacts.next;for(;h!=null;){let u=h;if(u.stamp+n.Config.arbiterExpirationDelay<this.stamp){h=wt._eraseFromList(this.contacts,a),c=wt._eraseFromList(this.innards,p),u.arbiter=null,u.next=Pe.zpp_pool,Pe.zpp_pool=u;continue}let x=u.inner,m=u.active;if(u.active=u.stamp==this.stamp,u.active){l?(l=!1,this.c1=x,this.oc1=u):(this.hc2=!0,this.c2=x,this.oc2=u),x.r2x=u.px-this.b2.posx,x.r2y=u.py-this.b2.posy,x.r1x=u.px-this.b1.posx,x.r1y=u.py-this.b1.posy;let _=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 f=this.b2.angvel+this.b2.kinangvel,w=this.b2.velx+this.b2.kinvelx-x.r2y*f,Z=this.b2.vely+this.b2.kinvely+x.r2x*f;f=this.b1.angvel+this.b1.kinangvel,w-=this.b1.velx+this.b1.kinvelx-x.r1y*f,Z-=this.b1.vely+this.b1.kinvely+x.r1x*f;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 b=Z*this.nx-w*this.ny,g=n.Config.staticFrictionThreshold;b*b>g*g?x.friction=this.dyn_fric:x.friction=this.stat_fric,x.jnAcc*=s,x.jtAcc*=s}m!=u.active&&(this.contacts.modified=!0),a=h,p=c,c=c.next,h=h.next}if(this.hc2){if(this.hpc2=!0,this.oc1.posOnly){let u=this.c1;this.c1=this.c2,this.c2=u,u=this.oc1,this.oc1=this.oc2,this.oc2=u,this.hc2=!1}else this.oc2.posOnly&&(this.hc2=!1);this.oc1.posOnly&&(l=!0)}else this.hpc2=!1;if(this.jrAcc*=s,l||(this.rn1a=this.ny*this.c1.r1x-this.nx*this.c1.r1y,this.rt1a=this.c1.r1x*this.nx+this.c1.r1y*this.ny,this.rn1b=this.ny*this.c1.r2x-this.nx*this.c1.r2y,this.rt1b=this.c1.r2x*this.nx+this.c1.r2y*this.ny,this.k1x=this.b2.kinvelx-this.c1.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c1.r1y*this.b1.kinangvel),this.k1y=this.b2.kinvely+this.c1.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c1.r1x*this.b1.kinangvel)),this.hc2)if(this.rn2a=this.ny*this.c2.r1x-this.nx*this.c2.r1y,this.rt2a=this.c2.r1x*this.nx+this.c2.r1y*this.ny,this.rn2b=this.ny*this.c2.r2x-this.nx*this.c2.r2y,this.rt2b=this.c2.r2x*this.nx+this.c2.r2y*this.ny,this.k2x=this.b2.kinvelx-this.c2.r2y*this.b2.kinangvel-(this.b1.kinvelx-this.c2.r1y*this.b1.kinangvel),this.k2y=this.b2.kinvely+this.c2.r2x*this.b2.kinangvel-(this.b1.kinvely+this.c2.r1x*this.b1.kinangvel),this.kMassa=i+this.b1.sinertia*this.rn1a*this.rn1a+this.b2.sinertia*this.rn1b*this.rn1b,this.kMassb=i+this.b1.sinertia*this.rn1a*this.rn2a+this.b2.sinertia*this.rn1b*this.rn2b,this.kMassc=i+this.b1.sinertia*this.rn2a*this.rn2a+this.b2.sinertia*this.rn2b*this.rn2b,this.kMassa*this.kMassa+2*this.kMassb*this.kMassb+this.kMassc*this.kMassc<n.Config.illConditionedThreshold*(this.kMassa*this.kMassc-this.kMassb*this.kMassb)){this.Ka=this.kMassa,this.Kb=this.kMassb,this.Kc=this.kMassc;let x=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(x!==x)this.kMassa=this.kMassb=this.kMassc=0;else if(x==0)this.kMassa!=0?this.kMassa=1/this.kMassa:this.kMassa=0,this.kMassc!=0?this.kMassc=1/this.kMassc:this.kMassc=0,this.kMassb=0;else{let m=1/x,_=this.kMassc*m;this.kMassc=this.kMassa*m,this.kMassa=_,this.kMassb*=-m}}else{if(this.hc2=!1,this.oc2.dist<this.oc1.dist){let x=this.c1;this.c1=this.c2,this.c2=x}this.oc2.active=!1,this.contacts.modified=!0}return this.surfacex=this.b2.svelx,this.surfacey=this.b2.svely,this.surfacex+=this.b1.svelx,this.surfacey+=this.b1.svely,this.surfacex=-this.surfacex,this.surfacey=-this.surfacey,this.rMass=this.b1.sinertia+this.b2.sinertia,this.rMass!=0&&(this.rMass=1/this.rMass),l}warmStart(){let t=this.nx*this.c1.jnAcc-this.ny*this.c1.jtAcc,n=this.ny*this.c1.jnAcc+this.nx*this.c1.jtAcc;this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c1.r1x-t*this.c1.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c1.r2x-t*this.c1.r2y),this.hc2&&(t=this.nx*this.c2.jnAcc-this.ny*this.c2.jtAcc,n=this.ny*this.c2.jnAcc+this.nx*this.c2.jtAcc,this.b1.velx-=t*this.b1.imass,this.b1.vely-=n*this.b1.imass,this.b1.angvel-=this.b1.iinertia*(n*this.c2.r1x-t*this.c2.r1y),this.b2.velx+=t*this.b2.imass,this.b2.vely+=n*this.b2.imass,this.b2.angvel+=this.b2.iinertia*(n*this.c2.r2x-t*this.c2.r2y)),this.b2.angvel+=this.jrAcc*this.b2.iinertia,this.b1.angvel-=this.jrAcc*this.b1.iinertia}applyImpulseVel(){let t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),s=(n*this.nx-t*this.ny+this.surfacex)*this.c1.tMass,i=this.c1.friction*this.c1.jnAcc,l=this.c1.jtAcc,o=l-s;o>i?o=i:o<-i&&(o=-i),s=o-l,this.c1.jtAcc=o;let r=-this.ny*s,a=this.nx*s;if(this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rt1b*s*this.b2.iinertia,this.b1.angvel-=this.rt1a*s*this.b1.iinertia,this.hc2){let p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);s=(c*this.nx-p*this.ny+this.surfacex)*this.c2.tMass,i=this.c2.friction*this.c2.jnAcc,l=this.c2.jtAcc,o=l-s,o>i?o=i:o<-i&&(o=-i),s=o-l,this.c2.jtAcc=o,r=-this.ny*s,a=this.nx*s,this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rt2b*s*this.b2.iinertia,this.b1.angvel-=this.rt2a*s*this.b1.iinertia,t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),p=this.k2x+this.b2.velx-this.c2.r2y*this.b2.angvel-(this.b1.velx-this.c2.r1y*this.b1.angvel),c=this.k2y+this.b2.vely+this.c2.r2x*this.b2.angvel-(this.b1.vely+this.c2.r1x*this.b1.angvel);let h=this.c1.jnAcc,u=this.c2.jnAcc,x=t*this.nx+n*this.ny+this.surfacey+this.c1.bounce-(this.Ka*h+this.Kb*u),m=p*this.nx+c*this.ny+this.surfacey+this.c2.bounce-(this.Kb*h+this.Kc*u),_=-(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,r=this.nx*s,a=this.ny*s,this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=(this.rn1b*x+this.rn2b*m)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*x+this.rn2a*m)*this.b1.iinertia}else this.radius!=0&&(s=(this.b2.angvel-this.b1.angvel)*this.rMass,i=this.rfric*this.c1.jnAcc,l=this.jrAcc,this.jrAcc-=s,this.jrAcc>i?this.jrAcc=i:this.jrAcc<-i&&(this.jrAcc=-i),s=this.jrAcc-l,this.b2.angvel+=s*this.b2.iinertia,this.b1.angvel-=s*this.b1.iinertia),t=this.k1x+this.b2.velx-this.c1.r2y*this.b2.angvel-(this.b1.velx-this.c1.r1y*this.b1.angvel),n=this.k1y+this.b2.vely+this.c1.r2x*this.b2.angvel-(this.b1.vely+this.c1.r1x*this.b1.angvel),s=(this.c1.bounce+(this.nx*t+this.ny*n)+this.surfacey)*this.c1.nMass,l=this.c1.jnAcc,o=l-s,o<0&&(o=0),s=o-l,this.c1.jnAcc=o,r=this.nx*s,a=this.ny*s,this.b2.velx+=r*this.b2.imass,this.b2.vely+=a*this.b2.imass,this.b1.velx-=r*this.b1.imass,this.b1.vely-=a*this.b1.imass,this.b2.angvel+=this.rn1b*s*this.b2.iinertia,this.b1.angvel-=this.rn1a*s*this.b1.iinertia}applyImpulsePos(){let t=Ie._nape;this.ptype==2?this._applyImpulsePosCircle(t):this._applyImpulsePosEdge(t)}_applyImpulsePosCircle(t){let n=this.c1,s=this.b2.axisy*n.lr2x-this.b2.axisx*n.lr2y,i=n.lr2x*this.b2.axisx+n.lr2y*this.b2.axisy;s+=this.b2.posx,i+=this.b2.posy;let l=this.b1.axisy*n.lr1x-this.b1.axisx*n.lr1y,o=n.lr1x*this.b1.axisx+n.lr1y*this.b1.axisy;l+=this.b1.posx,o+=this.b1.posy;let r=s-l,a=i-o,p=Math.sqrt(r*r+a*a),c=this.radius-t.Config.collisionSlop,h=p-c;if(r*this.nx+a*this.ny<0&&(r=-r,a=-a,h-=this.radius),h<0)if(p<t.Config.epsilon)this.b1.smass!=0?this.b1.posx+=t.Config.epsilon*10:this.b2.posx+=t.Config.epsilon*10;else{let u=1/p;r*=u,a*=u;let x=.5*(l+s),m=.5*(o+i),_=p-c;l=x-this.b1.posx,o=m-this.b1.posy,s=x-this.b2.posx,i=m-this.b2.posy;let y=a*l-r*o,z=a*s-r*i,f=this.b2.smass+z*z*this.b2.sinertia+this.b1.smass+y*y*this.b1.sinertia;if(f!=0){let w=-this.biasCoef*_/f,Z=r*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,o,r=0,a=0;this.ptype==0?(n=this.b1.axisy*this.lnormx-this.b1.axisx*this.lnormy,s=this.lnormx*this.b1.axisx+this.lnormy*this.b1.axisy,i=this.lproj+(n*this.b1.posx+s*this.b1.posy),l=this.b2.axisy*this.c1.lr1x-this.b2.axisx*this.c1.lr1y,o=this.c1.lr1x*this.b2.axisx+this.c1.lr1y*this.b2.axisy,l+=this.b2.posx,o+=this.b2.posy,this.hpc2&&(r=this.b2.axisy*this.c2.lr1x-this.b2.axisx*this.c2.lr1y,a=this.c2.lr1x*this.b2.axisx+this.c2.lr1y*this.b2.axisy,r+=this.b2.posx,a+=this.b2.posy)):(n=this.b2.axisy*this.lnormx-this.b2.axisx*this.lnormy,s=this.lnormx*this.b2.axisx+this.lnormy*this.b2.axisy,i=this.lproj+(n*this.b2.posx+s*this.b2.posy),l=this.b1.axisy*this.c1.lr1x-this.b1.axisx*this.c1.lr1y,o=this.c1.lr1x*this.b1.axisx+this.c1.lr1y*this.b1.axisy,l+=this.b1.posx,o+=this.b1.posy,this.hpc2&&(r=this.b1.axisy*this.c2.lr1x-this.b1.axisx*this.c2.lr1y,a=this.c2.lr1x*this.b1.axisx+this.c2.lr1y*this.b1.axisy,r+=this.b1.posx,a+=this.b1.posy));let p=l*n+o*s-i-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=r*n+a*s-i-this.radius,c+=t.Config.collisionSlop),p<0||c<0){this.rev&&(n=-n,s=-s);let h=l-this.b1.posx,u=o-this.b1.posy,x=l-this.b2.posx,m=o-this.b2.posy;if(this.hpc2){let _=r-this.b1.posx,y=a-this.b1.posy,z=r-this.b2.posx,f=a-this.b2.posy,w=s*h-n*u,Z=s*x-n*m,d=s*_-n*y,b=s*z-n*f,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*b,this.kMassc=g+this.b1.sinertia*d*d+this.b2.sinertia*b*b;let P=this.kMassa,v=this.kMassb,N=this.kMassc,k=p*this.biasCoef,C=c*this.biasCoef;for(;;){let E=-k,M=-C,S=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(S!==S)E=0,M=0;else if(S==0)this.kMassa!=0?E/=this.kMassa:E=0,this.kMassc!=0?M/=this.kMassc:M=0;else{let O=1/S,L=O*(this.kMassc*E-this.kMassb*M);M=O*(this.kMassa*M-this.kMassb*E),E=L}if(E>=0&&M>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,E,M,w,d,Z,b);break}if(E=-k/P,M=0,E>=0&&v*E+C>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,E,M,w,d,Z,b);break}if(E=0,M=-C/N,M>=0&&v*M+k>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,E,M,w,d,Z,b);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 f=-this.biasCoef*p/z,w=n*f,Z=s*f;this.b1.posx-=w*this.b1.imass,this.b1.posy-=Z*this.b1.imass,wt._rotateBody(this.b1,-_*this.b1.iinertia*f),this.b2.posx+=w*this.b2.imass,this.b2.posy+=Z*this.b2.imass,wt._rotateBody(this.b2,y*this.b2.iinertia*f)}}}}static _eraseFromList(t,n){let s,i;return n==null?(s=t.next,i=s.next,t.next=i,t.next==null&&(t.pushmod=!0)):(s=n.next,i=s.next,n.next=i,i==null&&(t.pushmod=!0)),s._inuse=!1,t.modified=!0,t.length--,t.pushmod=!0,i}static _rotateBody(t,n){if(t.rot+=n,n*n>1e-4)t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot);else{let s=n*n,i=1-.5*s,l=1-s*s/8,o=(i*t.axisx+n*t.axisy)*l;t.axisy=(i*t.axisy-n*t.axisx)*l,t.axisx=o}}static _applyPosImpulse2(t,n,s,i,l,o,r,a,p,c){let h=(l+o)*t.imass;t.posx-=s*h,t.posy-=i*h,wt._rotateBody(t,-t.iinertia*(r*l+a*o));let u=(l+o)*n.imass;n.posx+=s*u,n.posy+=i*u,wt._rotateBody(n,n.iinertia*(p*l+c*o))}};wt.FACE1=0,wt.FACE2=1,wt.CIRCLE=2,wt.zpp_pool=null;var ut=wt;var Jt=class Jt{constructor(){this.collisionGroup=1;this.collisionMask=-1;this.sensorGroup=1;this.sensorMask=-1;this.fluidGroup=1;this.fluidMask=-1;this.shapes=null;this.wrap_shapes=null;this.outer=null;this.userData=null;this.next=null;this.shapes=new Jt._zpp.util.ZNPList_ZPP_Shape}wrapper(){if(this.outer==null)if(Jt._wrapFn)this.outer=Jt._wrapFn(this);else{this.outer=new Jt._nape.dynamics.InteractionFilter;let e=this.outer.zpp_inner;e.outer=null,e.next=Jt.zpp_pool,Jt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}free(){this.outer=null}alloc(){}feature_cons(){this.shapes=new Jt._zpp.util.ZNPList_ZPP_Shape}addShape(e){this.shapes.add(e)}remShape(e){this.shapes.remove(e)}copy(){let e;return Jt.zpp_pool==null?e=new Jt:(e=Jt.zpp_pool,Jt.zpp_pool=e.next,e.next=null),e.collisionGroup=this.collisionGroup,e.collisionMask=this.collisionMask,e.sensorGroup=this.sensorGroup,e.sensorMask=this.sensorMask,e.fluidGroup=this.fluidGroup,e.fluidMask=this.fluidMask,e}shouldCollide(e){return(this.collisionMask&e.collisionGroup)!==0&&(e.collisionMask&this.collisionGroup)!==0}shouldSense(e){return(this.sensorMask&e.sensorGroup)!==0&&(e.sensorMask&this.sensorGroup)!==0}shouldFlow(e){return(this.fluidMask&e.fluidGroup)!==0&&(e.fluidMask&this.fluidGroup)!==0}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_filter(),e=e.next}};Jt.zpp_pool=null,Jt._nape=null,Jt._zpp=null,Jt._wrapFn=null;var it=Jt;var Ai=class Ai{constructor(){this.outer=null;this.ignore=!1;this.group=null;this.groups=null;this.wrap_groups=null;this.interactors=null;this.wrap_interactors=null;this.depth=0;let e=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(!0)),this.group=e,e!=null?(e.groups.add(this),this.depth=e.depth+1,e.invalidate(!0)):this.invalidate(!0))}invalidate(e){if(e==null&&(e=!1),!(e||this.ignore))return;let t=this.interactors.head;for(;t!=null;){let s=t.elt;s.ibody!=null?s.ibody.wake():s.ishape!=null?s.ishape.body.wake():s.icompound.wake(),t=t.next}let n=this.groups.head;for(;n!=null;)n.elt.invalidate(e),n=n.next}addGroup(e){this.groups.add(e),e.depth=this.depth+1}remGroup(e){this.groups.remove(e),e.depth=0}addInteractor(e){this.interactors.add(e)}remInteractor(e,t){this.interactors.remove(e)}};Ai.SHAPE=1,Ai.BODY=2,Ai._zpp=null,Ai._wrapFn=null;var Zs=Ai;var Yn=class{constructor(){this.zpp_inner=null;this.space=null;this._length=0;this.zip_length=!1;this.lengths=[];this.ite_0=null;this.ite_1=null;this.ite_2=null;this.ite_3=null;this.at_index_0=0;this.at_index_1=0;this.at_index_2=0;this.at_index_3=0;this.at_index_0=0,this.at_index_1=0,this.at_index_2=0,this.at_index_3=0,this.zip_length=!0,this._length=0,this.lengths=[],this.lengths.push(0),this.lengths.push(0),this.lengths.push(0),this.lengths.push(0)}zpp_gl(){if(this.zpp_vm(),this.zip_length){this._length=0;let e=0,t=0,n=this.space.c_arbiters_true.head;for(;n!=null;)n.elt.active&&++t,n=n.next;this.lengths[e++]=t,this._length+=t;let s=0,i=this.space.c_arbiters_false.head;for(;i!=null;)i.elt.active&&++s,i=i.next;this.lengths[e++]=s,this._length+=s;let l=0,o=this.space.f_arbiters.head;for(;o!=null;)o.elt.active&&++l,o=o.next;this.lengths[e++]=l,this._length+=l;let r=0,a=this.space.s_arbiters.head;for(;a!=null;)a.elt.active&&++r,a=a.next;this.lengths[e++]=r,this._length+=r,this.zip_length=!1}return this._length}zpp_vm(){let e=!1;this.space.c_arbiters_true.modified&&(e=!0,this.space.c_arbiters_true.modified=!1),this.space.c_arbiters_false.modified&&(e=!0,this.space.c_arbiters_false.modified=!1),this.space.f_arbiters.modified&&(e=!0,this.space.f_arbiters.modified=!1),this.space.s_arbiters.modified&&(e=!0,this.space.s_arbiters.modified=!1),e&&(this.zip_length=!0,this._length=0,this.ite_0=null,this.ite_1=null,this.ite_2=null,this.ite_3=null)}push(e){throw new Error("Error: ArbiterList is immutable")}pop(){throw new Error("Error: ArbiterList is immutable")}unshift(e){throw new Error("Error: ArbiterList is immutable")}shift(){throw new Error("Error: ArbiterList is immutable")}remove(e){throw new Error("Error: ArbiterList is immutable")}clear(){throw new Error("Error: ArbiterList is immutable")}at(e){if(this.zpp_vm(),e<0||e>=this.zpp_gl())throw new Error("Error: Index out of bounds");let t=null,n=0;if(t==null)if(e<n+this.lengths[0]){let s=e-n;if(s<this.at_index_0||this.ite_0==null)for(this.at_index_0=0,this.ite_0=this.space.c_arbiters_true.head;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;for(;this.at_index_0!=s;)for(this.at_index_0++,this.ite_0=this.ite_0.next;!this.ite_0.elt.active;)this.ite_0=this.ite_0.next;t=this.ite_0.elt.wrapper()}else n+=this.lengths[0];if(t==null)if(e<n+this.lengths[1]){let s=e-n;if(s<this.at_index_1||this.ite_1==null)for(this.at_index_1=0,this.ite_1=this.space.c_arbiters_false.head;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;for(;this.at_index_1!=s;)for(this.at_index_1++,this.ite_1=this.ite_1.next;!this.ite_1.elt.active;)this.ite_1=this.ite_1.next;t=this.ite_1.elt.wrapper()}else n+=this.lengths[1];if(t==null)if(e<n+this.lengths[2]){let s=e-n;if(s<this.at_index_2||this.ite_2==null)for(this.at_index_2=0,this.ite_2=this.space.f_arbiters.head;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;for(;this.at_index_2!=s;)for(this.at_index_2++,this.ite_2=this.ite_2.next;!this.ite_2.elt.active;)this.ite_2=this.ite_2.next;t=this.ite_2.elt.wrapper()}else n+=this.lengths[2];if(t==null)if(e<n+this.lengths[3]){let s=e-n;if(s<this.at_index_3||this.ite_3==null)for(this.at_index_3=0,this.ite_3=this.space.s_arbiters.head;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;for(;this.at_index_3!=s;)for(this.at_index_3++,this.ite_3=this.ite_3.next;!this.ite_3.elt.active;)this.ite_3=this.ite_3.next;t=this.ite_3.elt.wrapper()}else n+=this.lengths[3];return t}};Yn._nape=null,Yn._zpp=null;var Mt=class Mt{constructor(){this._invalidate=null;this._validate=null;this._immutable=!1;this.outer=null;this.next=null;this.minx=0;this.miny=0;this.maxx=0;this.maxy=0;this.wrap_min=null;this.wrap_max=null}static get(e,t,n,s){let i;return Mt.zpp_pool==null?i=new Mt:(i=Mt.zpp_pool,Mt.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=t,i.maxx=n,i.maxy=s,i}validate(){this._validate!=null&&this._validate()}invalidate(){this._invalidate!=null&&this._invalidate(this)}wrapper(){if(this.outer==null)if(Mt._wrapFn)this.outer=Mt._wrapFn(this);else{this.outer=new Mt._nape.geom.AABB;let e=this.outer.zpp_inner;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e.wrap_min=e.wrap_max=null,e._invalidate=null,e._validate=null,e.next=Mt.zpp_pool,Mt.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}alloc(){}free(){this.outer!=null&&(this.outer.zpp_inner=null,this.outer=null),this.wrap_min=this.wrap_max=null,this._invalidate=null,this._validate=null}copy(){return Mt.get(this.minx,this.miny,this.maxx,this.maxy)}width(){return this.maxx-this.minx}height(){return this.maxy-this.miny}perimeter(){return(this.maxx-this.minx+(this.maxy-this.miny))*2}static _makeVec2Wrapper(e,t){let n=Mt._zpp,s=Mt._nape;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n.util.ZPP_PubPool.poolVec2==null?i=new s.geom.Vec2:(i=n.util.ZPP_PubPool.poolVec2,n.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==n.util.ZPP_PubPool.nextVec2&&(n.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;n.geom.ZPP_Vec2.zpp_pool==null?l=new n.geom.ZPP_Vec2:(l=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=e,l.y=t,i.zpp_inner=l,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");l._validate!=null&&l._validate(),(l.x!==e||l.y!==t)&&(l.x=e,l.y=t,l._invalidate!=null&&l._invalidate(l))}return i.zpp_inner.weak=!1,i}getmin(){this.wrap_min==null&&(this.wrap_min=Mt._makeVec2Wrapper(this.minx,this.miny),this.wrap_min.zpp_inner._inuse=!0,this._immutable?this.wrap_min.zpp_inner._immutable=!0:this.wrap_min.zpp_inner._invalidate=this.mod_min.bind(this),this.wrap_min.zpp_inner._validate=this.dom_min.bind(this))}dom_min(){this._validate!=null&&this._validate(),this.wrap_min.zpp_inner.x=this.minx,this.wrap_min.zpp_inner.y=this.miny}mod_min(e){(e.x!==this.minx||e.y!==this.miny)&&(this.minx=e.x,this.miny=e.y,this._invalidate!=null&&this._invalidate(this))}getmax(){this.wrap_max==null&&(this.wrap_max=Mt._makeVec2Wrapper(this.maxx,this.maxy),this.wrap_max.zpp_inner._inuse=!0,this._immutable?this.wrap_max.zpp_inner._immutable=!0:this.wrap_max.zpp_inner._invalidate=this.mod_max.bind(this),this.wrap_max.zpp_inner._validate=this.dom_max.bind(this))}dom_max(){this._validate!=null&&this._validate(),this.wrap_max.zpp_inner.x=this.maxx,this.wrap_max.zpp_inner.y=this.maxy}mod_max(e){(e.x!==this.maxx||e.y!==this.maxy)&&(this.maxx=e.x,this.maxy=e.y,this._invalidate!=null&&this._invalidate(this))}intersectX(e){return!(e.minx>this.maxx||this.minx>e.maxx)}intersectY(e){return!(e.miny>this.maxy||this.miny>e.maxy)}intersect(e){return e.miny<=this.maxy&&this.miny<=e.maxy&&e.minx<=this.maxx&&this.minx<=e.maxx}combine(e){e.minx<this.minx&&(this.minx=e.minx),e.maxx>this.maxx&&(this.maxx=e.maxx),e.miny<this.miny&&(this.miny=e.miny),e.maxy>this.maxy&&(this.maxy=e.maxy)}contains(e){return e.minx>=this.minx&&e.miny>=this.miny&&e.maxx<=this.maxx&&e.maxy<=this.maxy}containsPoint(e){return e.x>=this.minx&&e.x<=this.maxx&&e.y>=this.miny&&e.y<=this.maxy}setCombine(e,t){this.minx=e.minx<t.minx?e.minx:t.minx,this.miny=e.miny<t.miny?e.miny:t.miny,this.maxx=e.maxx>t.maxx?e.maxx:t.maxx,this.maxy=e.maxy>t.maxy?e.maxy:t.maxy}setExpand(e,t){this.minx=e.minx-t,this.miny=e.miny-t,this.maxx=e.maxx+t,this.maxy=e.maxy+t}setExpandPoint(e,t){e<this.minx&&(this.minx=e),e>this.maxx&&(this.maxx=e),t<this.miny&&(this.miny=t),t>this.maxy&&(this.maxy=t)}toString(){return"{ x: "+this.minx+" y: "+this.miny+" w: "+(this.maxx-this.minx)+" h: "+(this.maxy-this.miny)+" }"}};Mt.zpp_pool=null,Mt._nape=null,Mt._zpp=null,Mt._wrapFn=null;var fe=Mt;var be=class be{static get debugCapsule(){return globalThis.__napeDebugCapsule===!0}static _initStatics(e){be.flowpoly=new e.util.ZNPList_ZPP_Vec2,be.flowsegs=new e.util.ZNPList_ZPP_Vec2}static circleContains(e,t){let n=t.x-e.worldCOMx,s=t.y-e.worldCOMy;return n*n+s*s<e.radius*e.radius}static polyContains(e,t){let n;n=!0;let s=e.edges.head;for(;s!=null;){let i=s.elt;if(i.gnormx*t.x+i.gnormy*t.y<=i.gprojection){s=s.next;continue}else{n=!1;break}}return n}static shapeContains(e,t){return e.type==0?be.circleContains(e.circle,t):e.type==1?be.polyContains(e.polygon,t):be.capsuleContains(e.capsule,t)}static bodyContains(e,t){let n;n=!1;let s=e.shapes.head;for(;s!=null;){let i=s.elt;if(be.shapeContains(i,t)){n=!0;break}s=s.next}return n}static containTest(e,t){let n=e.aabb,s=t.aabb;if(s.minx>=n.minx&&s.miny>=n.miny&&s.maxx<=n.maxx&&s.maxy<=n.maxy)if(e.type==0)if(t.type==0){let i=e.circle.radius+-t.circle.radius,l=t.circle.worldCOMx-e.circle.worldCOMx,o=t.circle.worldCOMy-e.circle.worldCOMy;return l*l+o*o<=i*i}else if(t.type==1){let i;i=!0;let l=t.polygon.gverts.next;for(;l!=null;){let o=l,r=e.circle.radius,a=o.x-e.circle.worldCOMx,p=o.y-e.circle.worldCOMy;if(a*a+p*p<=r*r){l=l.next;continue}else{i=!1;break}}return i}else{let i=t.capsule,l=e.circle.radius-i.radius;if(l<0)return!1;let o=l*l,r=i.spine1x-e.circle.worldCOMx,a=i.spine1y-e.circle.worldCOMy;if(r*r+a*a>o)return!1;let p=i.spine2x-e.circle.worldCOMx,c=i.spine2y-e.circle.worldCOMy;return p*p+c*c<=o}else if(e.type==2)if(t.type==0){let i=e.capsule,l=be._closestT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,t.circle.worldCOMx,t.circle.worldCOMy),o=i.spine1x+l*(i.spine2x-i.spine1x),r=i.spine1y+l*(i.spine2y-i.spine1y),a=i.radius-t.circle.radius;if(a<0)return!1;let p=t.circle.worldCOMx-o,c=t.circle.worldCOMy-r;return p*p+c*c<=a*a}else return!1;else if(t.type==0){let i;i=!0;let l=e.polygon.edges.head;for(;l!=null;){let o=l.elt;if(o.gnormx*t.circle.worldCOMx+o.gnormy*t.circle.worldCOMy+t.circle.radius<=o.gprojection){l=l.next;continue}else{i=!1;break}}return i}else{let i;i=!0;let l=e.polygon.edges.head;for(;l!=null;){let o=l.elt,r=-1e100,a=t.polygon.gverts.next;for(;a!=null;){let p=a,c=o.gnormx*p.x+o.gnormy*p.y;c>r&&(r=c),a=a.next}if(r<=o.gprojection){l=l.next;continue}else{i=!1;break}}return i}else return!1}static contactCollide(e,t,n,s){let i=_e();if(t.type==2)return be._capsuleContactCollide(e,t,n,s,i);if(e.type==2)return be._capsuleContactCollide(t,e,n,!s,i);if(t.type==1)if(e.type==1){let l=!0,o=-1e100,r=-1e100,a=-1,p=null,c=null,h=e.polygon.edges.head;for(;h!=null;){let u=h.elt,x=1e100,m=t.polygon.gverts.next;for(;m!=null;){let _=m,y=u.gnormx*_.x+u.gnormy*_.y;if(y<x&&(x=y),x-u.gprojection<=o)break;m=m.next}if(x-=u.gprojection,x>=0){l=!1;break}x>o&&(o=x,p=u,a=1),h=h.next}if(l){let u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,m=1e100,_=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<=o)break;_=_.next}if(m-=x.gprojection,m>=0){l=!1;break}m>o&&(o=m,c=x,a=2),u=u.next}if(l){let x,m,_,y;a==1?(x=e.polygon,m=t.polygon,_=p,y=1):(x=t.polygon,m=e.polygon,_=c,y=-1);let z=null,f=1e100,w=m.edges.head;for(;w!=null;){let q=w.elt,G=_.gnormx*q.gnormx+_.gnormy*q.gnormy;G<f&&(f=G,z=q),w=w.next}let Z=z.gp0.x,d=z.gp0.y,b=z.gp1.x,g=z.gp1.y,P=b-Z,v=g-d,N=_.gnormy*Z-_.gnormx*d,k=_.gnormy*b-_.gnormx*g,C=1/(k-N),E=(-_.tp1-N)*C;if(E>i.Config.epsilon){let q=E;Z+=P*q,d+=v*q}let M=(-_.tp0-k)*C;if(M<-i.Config.epsilon){let q=M;b+=P*q,g+=v*q}let S=y,O=_.gnormx*S,L=_.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=b*_.gnormx+g*_.gnormy-_.gprojection;if(T>0&&R>0)return!1;{s&&(O=-O,L=-L);let q=Z-_.gnormx*T*.5,G=d-_.gnormy*T*.5,B=n.rev?1:0,V=T>0;V==null&&(V=!1);let Y=null,$=n.contacts.next;for(;$!=null;){let K=$;if(B==K.hash){Y=K;break}$=$.next}if(Y==null){Pe.zpp_pool==null?Y=new Pe:(Y=Pe.zpp_pool,Pe.zpp_pool=Y.next,Y.next=null);let K=Y.inner;K.jnAcc=K.jtAcc=0,Y.hash=B,Y.fresh=!0,Y.arbiter=n,n.jrAcc=0;let ie=n.contacts;Y._inuse=!0;let oe=Y;oe.next=ie.next,ie.next=oe,ie.modified=!0,ie.length++,n.innards.add(K)}else Y.fresh=!1;Y.px=q,Y.py=G,n.nx=O,n.ny=L,Y.dist=T,Y.stamp=n.stamp,Y.posOnly=V;let X=Y,H=1;Z-=m.body.posx*H,d-=m.body.posy*H,X.inner.lr1x=Z*m.body.axisy+d*m.body.axisx,X.inner.lr1y=d*m.body.axisy-Z*m.body.axisx;let ee=b-_.gnormx*R*.5,W=g-_.gnormy*R*.5,F=n.rev?0:1,D=R>0;D==null&&(D=!1);let A=null,J=n.contacts.next;for(;J!=null;){let K=J;if(F==K.hash){A=K;break}J=J.next}if(A==null){Pe.zpp_pool==null?A=new Pe:(A=Pe.zpp_pool,Pe.zpp_pool=A.next,A.next=null);let K=A.inner;K.jnAcc=K.jtAcc=0,A.hash=F,A.fresh=!0,A.arbiter=n,n.jrAcc=0;let ie=n.contacts;A._inuse=!0;let oe=A;oe.next=ie.next,ie.next=oe,ie.modified=!0,ie.length++,n.innards.add(K)}else A.fresh=!1;A.px=ee,A.py=W,n.nx=O,n.ny=L,A.dist=R,A.stamp=n.stamp,A.posOnly=D,X=A;let Q=1;return b-=m.body.posx*Q,g-=m.body.posy*Q,X.inner.lr1x=b*m.body.axisy+g*m.body.axisx,X.inner.lr1y=g*m.body.axisy-b*m.body.axisx,a==1?(n.__ref_edge1=_,n.__ref_edge2=z):(n.__ref_edge2=_,n.__ref_edge1=z),!0}}else return!1}else return!1}else{let l=-1e100,o=-1e100,r=!0,a=null,p=null,c=t.polygon.gverts.next,h=t.polygon.edges.head;for(;h!=null;){let u=h.elt,x=u.gnormx*e.circle.worldCOMx+u.gnormy*e.circle.worldCOMy-u.gprojection-e.circle.radius;if(x>0){r=!1;break}x>l&&(l=x,a=u,p=c),c=c.next,h=h.next}if(r){let u=p,x=p.next==null?t.polygon.gverts.next:p.next,m=e.circle.worldCOMy*a.gnormx-e.circle.worldCOMx*a.gnormy;if(m<=u.y*a.gnormx-u.x*a.gnormy){let _=e.circle.radius,y=u.x-e.circle.worldCOMx,z=u.y-e.circle.worldCOMy,f=y*y+z*z,w;if(f>_*_)w=null;else if(f<i.Config.epsilon*i.Config.epsilon){let Z=e.circle.worldCOMx,d=e.circle.worldCOMy,b=null,g=n.contacts.next;for(;g!=null;){let P=g;if(P.hash==0){b=P;break}g=g.next}if(b==null){Pe.zpp_pool==null?b=new Pe:(b=Pe.zpp_pool,Pe.zpp_pool=b.next,b.next=null);let P=b.inner;P.jnAcc=P.jtAcc=0,b.hash=0,b.fresh=!0,b.arbiter=n,n.jrAcc=0;let v=n.contacts;b._inuse=!0;let N=b;N.next=v.next,v.next=N,v.modified=!0,v.length++,n.innards.add(P)}else b.fresh=!1;b.px=Z,b.py=d,n.nx=1,n.ny=0,b.dist=-_,b.stamp=n.stamp,b.posOnly=!1,w=b}else{let Z=1/Math.sqrt(f),d=Z<i.Config.epsilon?1e100:1/Z,b=.5+(e.circle.radius-.5*_)*Z;if(s){let g=e.circle.worldCOMx+y*b,P=e.circle.worldCOMy+z*b,v=null,N=n.contacts.next;for(;N!=null;){let k=N;if(k.hash==0){v=k;break}N=N.next}if(v==null){Pe.zpp_pool==null?v=new Pe:(v=Pe.zpp_pool,Pe.zpp_pool=v.next,v.next=null);let k=v.inner;k.jnAcc=k.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let C=n.contacts;v._inuse=!0;let E=v;E.next=C.next,C.next=E,C.modified=!0,C.length++,n.innards.add(k)}else v.fresh=!1;v.px=g,v.py=P,n.nx=-y*Z,n.ny=-z*Z,v.dist=d-_,v.stamp=n.stamp,v.posOnly=!1,w=v}else{let g=e.circle.worldCOMx+y*b,P=e.circle.worldCOMy+z*b,v=null,N=n.contacts.next;for(;N!=null;){let k=N;if(k.hash==0){v=k;break}N=N.next}if(v==null){Pe.zpp_pool==null?v=new Pe:(v=Pe.zpp_pool,Pe.zpp_pool=v.next,v.next=null);let k=v.inner;k.jnAcc=k.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let C=n.contacts;v._inuse=!0;let E=v;E.next=C.next,C.next=E,C.modified=!0,C.length++,n.innards.add(k)}else v.fresh=!1;v.px=g,v.py=P,n.nx=y*Z,n.ny=z*Z,v.dist=d-_,v.stamp=n.stamp,v.posOnly=!1,w=v}}if(w!=null){let Z=w.inner;n.ptype=2;let d=u.x-t.polygon.body.posx,b=u.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=-1,s?(Z.lr1x=d*t.polygon.body.axisy+b*t.polygon.body.axisx,Z.lr1y=b*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+b*t.polygon.body.axisx,Z.lr2y=b*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,f=y*y+z*z,w;if(f>_*_)w=null;else if(f<i.Config.epsilon*i.Config.epsilon){let Z=e.circle.worldCOMx,d=e.circle.worldCOMy,b=null,g=n.contacts.next;for(;g!=null;){let P=g;if(P.hash==0){b=P;break}g=g.next}if(b==null){Pe.zpp_pool==null?b=new Pe:(b=Pe.zpp_pool,Pe.zpp_pool=b.next,b.next=null);let P=b.inner;P.jnAcc=P.jtAcc=0,b.hash=0,b.fresh=!0,b.arbiter=n,n.jrAcc=0;let v=n.contacts;b._inuse=!0;let N=b;N.next=v.next,v.next=N,v.modified=!0,v.length++,n.innards.add(P)}else b.fresh=!1;b.px=Z,b.py=d,n.nx=1,n.ny=0,b.dist=-_,b.stamp=n.stamp,b.posOnly=!1,w=b}else{let Z=1/Math.sqrt(f),d=Z<i.Config.epsilon?1e100:1/Z,b=.5+(e.circle.radius-.5*_)*Z;if(s){let g=e.circle.worldCOMx+y*b,P=e.circle.worldCOMy+z*b,v=null,N=n.contacts.next;for(;N!=null;){let k=N;if(k.hash==0){v=k;break}N=N.next}if(v==null){Pe.zpp_pool==null?v=new Pe:(v=Pe.zpp_pool,Pe.zpp_pool=v.next,v.next=null);let k=v.inner;k.jnAcc=k.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let C=n.contacts;v._inuse=!0;let E=v;E.next=C.next,C.next=E,C.modified=!0,C.length++,n.innards.add(k)}else v.fresh=!1;v.px=g,v.py=P,n.nx=-y*Z,n.ny=-z*Z,v.dist=d-_,v.stamp=n.stamp,v.posOnly=!1,w=v}else{let g=e.circle.worldCOMx+y*b,P=e.circle.worldCOMy+z*b,v=null,N=n.contacts.next;for(;N!=null;){let k=N;if(k.hash==0){v=k;break}N=N.next}if(v==null){Pe.zpp_pool==null?v=new Pe:(v=Pe.zpp_pool,Pe.zpp_pool=v.next,v.next=null);let k=v.inner;k.jnAcc=k.jtAcc=0,v.hash=0,v.fresh=!0,v.arbiter=n,n.jrAcc=0;let C=n.contacts;v._inuse=!0;let E=v;E.next=C.next,C.next=E,C.modified=!0,C.length++,n.innards.add(k)}else v.fresh=!1;v.px=g,v.py=P,n.nx=y*Z,n.ny=z*Z,v.dist=d-_,v.stamp=n.stamp,v.posOnly=!1,w=v}}if(w!=null){let Z=w.inner;n.ptype=2;let d=x.x-t.polygon.body.posx,b=x.y-t.polygon.body.posy;n.__ref_edge1=a,n.__ref_vertex=1,s?(Z.lr1x=d*t.polygon.body.axisy+b*t.polygon.body.axisx,Z.lr1y=b*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+b*t.polygon.body.axisx,Z.lr2y=b*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*_,f=e.circle.worldCOMx-y,w=e.circle.worldCOMy-z,Z;if(s){let d=a.gnormx,b=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){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let v=g.inner;v.jnAcc=v.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let N=n.contacts;g._inuse=!0;let k=g;k.next=N.next,N.next=k,N.modified=!0,N.length++,n.innards.add(v)}else g.fresh=!1;g.px=f,g.py=w,n.nx=d,n.ny=b,g.dist=l,g.stamp=n.stamp,g.posOnly=!1,Z=g}else{let d=-a.gnormx,b=-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){Pe.zpp_pool==null?g=new Pe:(g=Pe.zpp_pool,Pe.zpp_pool=g.next,g.next=null);let v=g.inner;v.jnAcc=v.jtAcc=0,g.hash=0,g.fresh=!0,g.arbiter=n,n.jrAcc=0;let N=n.contacts;g._inuse=!0;let k=g;k.next=N.next,N.next=k,N.modified=!0,N.length++,n.innards.add(v)}else g.fresh=!1;g.px=f,g.py=w,n.nx=d,n.ny=b,g.dist=l,g.stamp=n.stamp,g.posOnly=!1,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,!0}}else return!1}else{let l=e.circle.radius+t.circle.radius,o=t.circle.worldCOMx-e.circle.worldCOMx,r=t.circle.worldCOMy-e.circle.worldCOMy,a=o*o+r*r,p;if(a>l*l)p=null;else if(a<i.Config.epsilon*i.Config.epsilon){let c=e.circle.worldCOMx,h=e.circle.worldCOMy,u=null,x=n.contacts.next;for(;x!=null;){let m=x;if(m.hash==0){u=m;break}x=x.next}if(u==null){Pe.zpp_pool==null?u=new Pe:(u=Pe.zpp_pool,Pe.zpp_pool=u.next,u.next=null);let m=u.inner;m.jnAcc=m.jtAcc=0,u.hash=0,u.fresh=!0,u.arbiter=n,n.jrAcc=0;let _=n.contacts;u._inuse=!0;let y=u;y.next=_.next,_.next=y,_.modified=!0,_.length++,n.innards.add(m)}else u.fresh=!1;u.px=c,u.py=h,n.nx=1,n.ny=0,u.dist=-l,u.stamp=n.stamp,u.posOnly=!1,p=u}else{let c=1/Math.sqrt(a),h=c<i.Config.epsilon?1e100:1/c,u=.5+(e.circle.radius-.5*l)*c;if(s){let x=e.circle.worldCOMx+o*u,m=e.circle.worldCOMy+r*u,_=null,y=n.contacts.next;for(;y!=null;){let z=y;if(z.hash==0){_=z;break}y=y.next}if(_==null){Pe.zpp_pool==null?_=new Pe:(_=Pe.zpp_pool,Pe.zpp_pool=_.next,_.next=null);let z=_.inner;z.jnAcc=z.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let f=n.contacts;_._inuse=!0;let w=_;w.next=f.next,f.next=w,f.modified=!0,f.length++,n.innards.add(z)}else _.fresh=!1;_.px=x,_.py=m,n.nx=-o*c,n.ny=-r*c,_.dist=h-l,_.stamp=n.stamp,_.posOnly=!1,p=_}else{let x=e.circle.worldCOMx+o*u,m=e.circle.worldCOMy+r*u,_=null,y=n.contacts.next;for(;y!=null;){let z=y;if(z.hash==0){_=z;break}y=y.next}if(_==null){Pe.zpp_pool==null?_=new Pe:(_=Pe.zpp_pool,Pe.zpp_pool=_.next,_.next=null);let z=_.inner;z.jnAcc=z.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let f=n.contacts;_._inuse=!0;let w=_;w.next=f.next,f.next=w,f.modified=!0,f.length++,n.innards.add(z)}else _.fresh=!1;_.px=x,_.py=m,n.nx=o*c,n.ny=r*c,_.dist=h-l,_.stamp=n.stamp,_.posOnly=!1,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,!0}else return!1}}static testCollide_safe(e,t){let n=_e();if(e.type>t.type){let s=e;e=t,t=s}return be.testCollide(e,t)}static testCollide(e,t){let n=_e();if(t.type==2)return be._capsuleTestCollide(e,t);if(t.type==1)if(e.type==1){let s=!0,i=e.polygon.edges.head;for(;i!=null;){let l=i.elt,o=1e100,r=t.polygon.gverts.next;for(;r!=null;){let a=r,p=l.gnormx*a.x+l.gnormy*a.y;p<o&&(o=p),r=r.next}if(o-=l.gprojection,o>0){s=!1;break}i=i.next}if(s){let l=t.polygon.edges.head;for(;l!=null;){let o=l.elt,r=1e100,a=e.polygon.gverts.next;for(;a!=null;){let p=a,c=o.gnormx*p.x+o.gnormy*p.y;c<r&&(r=c),a=a.next}if(r-=o.gprojection,r>0){s=!1;break}l=l.next}return s}else return!1}else{let s=null,i=null,l=!0,o=-1e100,r=t.polygon.gverts.next,a=t.polygon.edges.head;for(;a!=null;){let p=a.elt,c=p.gnormx*e.circle.worldCOMx+p.gnormy*e.circle.worldCOMy-p.gprojection-e.circle.radius;if(c>0){l=!1;break}c>o&&(o=c,s=p,i=r),r=r.next,a=a.next}if(l){let p=i,c=i.next==null?t.polygon.gverts.next:i.next,h=e.circle.worldCOMy*s.gnormx-e.circle.worldCOMx*s.gnormy;if(h<=p.y*s.gnormx-p.x*s.gnormy){let u=e.circle.radius,x=p.x-e.circle.worldCOMx,m=p.y-e.circle.worldCOMy;return x*x+m*m<=u*u}else if(h>=c.y*s.gnormx-c.x*s.gnormy){let u=e.circle.radius,x=c.x-e.circle.worldCOMx,m=c.y-e.circle.worldCOMy;return x*x+m*m<=u*u}else return!0}else return!1}else{let s=e.circle.radius+t.circle.radius,i=t.circle.worldCOMx-e.circle.worldCOMx,l=t.circle.worldCOMy-e.circle.worldCOMy;return i*i+l*l<=s*s}}static flowCollide(e,t,n){let s=_e();if(e.type==2||t.type==2)return be._capsuleFlowCollide(e,t,n,s);if(t.type==1)if(e.type==1){let i=[],l=[],o=!0,r=!0,a=e.polygon.edges.head;for(;a!=null;){let p=a.elt,c=1e100,h=0,u=t.polygon.gverts.next;for(;u!=null;){let x=u,m=p.gnormx*x.x+p.gnormy*x.y;m<c&&(c=m),m>=p.gprojection+s.Config.epsilon&&(l[h]=!0,r=!1),++h,u=u.next}if(c-=p.gprojection,c>0){o=!1;break}a=a.next}if(r){let p=t.polygon;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=!1,p.zip_localCOM){if(p.zip_localCOM=!1,p.type==1){let h=p.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let u=1;h.localCOMx+=h.lverts.next.next.x*u,h.localCOMy+=h.lverts.next.next.y*u;let x=.5;h.localCOMx*=x,h.localCOMy*=x}else{h.localCOMx=0,h.localCOMy=0;let u=0,x=h.lverts.next,m=x;x=x.next;let _=x;for(x=x.next;x!=null;){let d=x;u+=_.x*(d.y-m.y);let b=d.y*_.x-d.x*_.y;h.localCOMx+=(_.x+d.x)*b,h.localCOMy+=(_.y+d.y)*b,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 f=x;u+=_.x*(f.y-m.y);let w=f.y*_.x-f.x*_.y;h.localCOMx+=(_.x+f.x)*w,h.localCOMy+=(_.y+f.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=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else if(o){r=!0;let p=t.polygon.edges.head;for(;p!=null;){let c=p.elt,h=1e100,u=0,x=e.polygon.gverts.next;for(;x!=null;){let m=x,_=c.gnormx*m.x+c.gnormy*m.y;_<h&&(h=_),_>=c.gprojection+s.Config.epsilon&&(i[u]=!0,r=!1),++u,x=x.next}if(h-=c.gprojection,h>0){o=!1;break}p=p.next}if(r){let c=e.polygon;if(c.zip_worldCOM&&c.body!=null){if(c.zip_worldCOM=!1,c.zip_localCOM){if(c.zip_localCOM=!1,c.type==1){let u=c.polygon;if(u.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(u.lverts.next.next==null)u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;else if(u.lverts.next.next.next==null){u.localCOMx=u.lverts.next.x,u.localCOMy=u.lverts.next.y;let x=1;u.localCOMx+=u.lverts.next.next.x*x,u.localCOMy+=u.lverts.next.next.y*x;let m=.5;u.localCOMx*=m,u.localCOMy*=m}else{u.localCOMx=0,u.localCOMy=0;let x=0,m=u.lverts.next,_=m;m=m.next;let y=m;for(m=m.next;m!=null;){let b=m;x+=y.x*(b.y-_.y);let g=b.y*y.x-b.x*y.y;u.localCOMx+=(y.x+b.x)*g,u.localCOMy+=(y.y+b.y)*g,_=y,y=b,m=m.next}m=u.lverts.next;let z=m;x+=y.x*(z.y-_.y);let f=z.y*y.x-z.x*y.y;u.localCOMx+=(y.x+z.x)*f,u.localCOMy+=(y.y+z.y)*f,_=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=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.worldCOMx=c.body.posx+(c.body.axisy*c.localCOMx-c.body.axisx*c.localCOMy),c.worldCOMy=c.body.posy+(c.localCOMx*c.body.axisx+c.localCOMy*c.body.axisy)}return n.overlap=e.polygon.area,n.centroidx=e.polygon.worldCOMx,n.centroidy=e.polygon.worldCOMy,!0}else if(o){for(;be.flowpoly.head!=null;){let w=be.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=pe.zpp_pool,pe.zpp_pool=Z}}let c=null,h=!1,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=!0;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:(be.flowpoly.add(u),c=be.flowpoly.head.elt)}else be.flowpoly.add(m),c=be.flowpoly.head.elt;let f=1;if(be.flowpoly.head==null){let w=!0,Z=e.polygon.gverts.next,d=Z,b=Z.next;for(;b!=null;){let g=b,P=2,v=!0,N=t.polygon.gverts.next,k=N,C=N.next;for(;C!=null;){let E=C,M=0,S=d.x-k.x,O=d.y-k.y,L=g.x-d.x,T=g.y-d.y,R=E.x-k.x,q=E.y-k.y,G=T*R-L*q,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(q*S-R*O)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(T*S-L*O)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(M=V,B=!0):B=!1}else B=!1}else B=!1;B&&M<P&&(P=M,m=N),N=C,k=E,C=C.next}if(v)for(;;){C=t.polygon.gverts.next;let E=C,M=0,S=d.x-k.x,O=d.y-k.y,L=g.x-d.x,T=g.y-d.y,R=E.x-k.x,q=E.y-k.y,G=T*R-L*q,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(q*S-R*O)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(T*S-L*O)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(M=V,B=!0):B=!1}else B=!1}else B=!1;B&&M<P&&(P=M,m=N);break}if(P!=2){let E=P,M=d.x+(g.x-d.x)*E,S=d.y+(g.y-d.y)*E;c=pe.get(M,S),be.flowpoly.add(c),h=!0,u=Z,w=!1;break}Z=b,d=g,b=b.next}if(w)for(;;){b=e.polygon.gverts.next;let g=b,P=2,v=!0,N=t.polygon.gverts.next,k=N,C=N.next;for(;C!=null;){let E=C,M=0,S=d.x-k.x,O=d.y-k.y,L=g.x-d.x,T=g.y-d.y,R=E.x-k.x,q=E.y-k.y,G=T*R-L*q,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(q*S-R*O)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(T*S-L*O)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(M=V,B=!0):B=!1}else B=!1}else B=!1;B&&M<P&&(P=M,m=N),N=C,k=E,C=C.next}if(v)for(;;){C=t.polygon.gverts.next;let E=C,M=0,S=d.x-k.x,O=d.y-k.y,L=g.x-d.x,T=g.y-d.y,R=E.x-k.x,q=E.y-k.y,G=T*R-L*q,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(q*S-R*O)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(T*S-L*O)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(M=V,B=!0):B=!1}else B=!1}else B=!1;B&&M<P&&(P=M,m=N);break}if(P!=2){let E=P,M=d.x+(g.x-d.x)*E,S=d.y+(g.y-d.y)*E;c=pe.get(M,S),be.flowpoly.add(c),h=!0,u=Z;break}break}f=2}for(;;)if(h)if(u=u.next,++x,u==null&&(u=e.polygon.gverts.next,x=0),i[x]){let w=be.flowpoly.head.elt,Z=u,d=m,b=m.next;b==null&&(b=t.polygon.gverts.next);let g=-1,P=null,v=0,N=0,k=b,C=b;for(;;){let B=C,V=0,Y=d.x-w.x,$=d.y-w.y,X=B.x-d.x,H=B.y-d.y,ee=Z.x-w.x,W=Z.y-w.y,F=H*ee-X*W,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let A=(W*Y-ee*$)*F;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let J=(H*Y-X*$)*F;J>s.Config.epsilon&&J<1-s.Config.epsilon?(V=A,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=g)if(P=m,v=_,++N==f){g=V,C=k;break}else g=V;d=B,m=C,++_,_>=t.polygon.edgeCnt&&(_=0),C=C.next,C==null&&(C=t.polygon.gverts.next);break}for(;C!=k;){let B=C,V=0,Y=d.x-w.x,$=d.y-w.y,X=B.x-d.x,H=B.y-d.y,ee=Z.x-w.x,W=Z.y-w.y,F=H*ee-X*W,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let A=(W*Y-ee*$)*F;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let J=(H*Y-X*$)*F;J>s.Config.epsilon&&J<1-s.Config.epsilon?(V=A,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=g)if(P=m,v=_,++N==f){g=V;break}else g=V;d=B,m=C,++_,_>=t.polygon.edgeCnt&&(_=0),C=C.next,C==null&&(C=t.polygon.gverts.next)}if(P==null)break;let E=P,M=P.next;M==null&&(M=t.polygon.gverts.next);let S=M,O=g,L=E.x+(S.x-E.x)*O,T=E.y+(S.y-E.y)*O,R;if(c!=null){let B=L-c.x,V=T-c.y;R=B*B+V*V<s.Config.epsilon}else R=!1;if(R)break;let q=be.flowpoly,G=pe.get(L,T);q.add(G),c==null&&(c=be.flowpoly.head.elt),m=P,_=v,h=!h,f=2}else{let w=u,Z;if(c!=null){let d=w.x-c.x,b=w.y-c.y;Z=d*d+b*b<s.Config.epsilon}else Z=!1;if(Z)break;be.flowpoly.add(w),c==null&&(c=be.flowpoly.head.elt),f=1}else if(m=m.next,++_,m==null&&(m=t.polygon.gverts.next,_=0),l[_]){let w=be.flowpoly.head.elt,Z=m,d=u,b=u.next;b==null&&(b=e.polygon.gverts.next);let g=-1,P=null,v=0,N=0,k=b,C=b;for(;;){let B=C,V=0,Y=d.x-w.x,$=d.y-w.y,X=B.x-d.x,H=B.y-d.y,ee=Z.x-w.x,W=Z.y-w.y,F=H*ee-X*W,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let A=(W*Y-ee*$)*F;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let J=(H*Y-X*$)*F;J>s.Config.epsilon&&J<1-s.Config.epsilon?(V=A,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=g)if(P=u,v=x,++N==f){g=V,C=k;break}else g=V;d=B,u=C,++x,x>=e.polygon.edgeCnt&&(x=0),C=C.next,C==null&&(C=e.polygon.gverts.next);break}for(;C!=k;){let B=C,V=0,Y=d.x-w.x,$=d.y-w.y,X=B.x-d.x,H=B.y-d.y,ee=Z.x-w.x,W=Z.y-w.y,F=H*ee-X*W,D;if(F*F>s.Config.epsilon*s.Config.epsilon){F=1/F;let A=(W*Y-ee*$)*F;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let J=(H*Y-X*$)*F;J>s.Config.epsilon&&J<1-s.Config.epsilon?(V=A,D=!0):D=!1}else D=!1}else D=!1;if(D&&V>=g)if(P=u,v=x,++N==f){g=V;break}else g=V;d=B,u=C,++x,x>=e.polygon.edgeCnt&&(x=0),C=C.next,C==null&&(C=e.polygon.gverts.next)}if(P==null)break;let E=P,M=P.next;M==null&&(M=e.polygon.gverts.next);let S=M,O=g,L=E.x+(S.x-E.x)*O,T=E.y+(S.y-E.y)*O,R;if(c!=null){let B=L-c.x,V=T-c.y;R=B*B+V*V<s.Config.epsilon}else R=!1;if(R)break;let q=be.flowpoly,G=pe.get(L,T);q.add(G),c==null&&(c=be.flowpoly.head.elt),u=P,x=v,h=!h,f=2}else{let w=m,Z;if(c!=null){let d=w.x-c.x,b=w.y-c.y;Z=d*d+b*b<s.Config.epsilon}else Z=!1;if(Z)break;be.flowpoly.add(w),c==null&&(c=be.flowpoly.head.elt),f=1}if(be.flowpoly.head!=null&&be.flowpoly.head.next!=null&&be.flowpoly.head.next.next!=null){let w=0,Z=0,d=0,b=be.flowpoly.head,g=b.elt;b=b.next;let P=b.elt;for(b=b.next;b!=null;){let S=b.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,b=b.next}b=be.flowpoly.head;let v=b.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,b=b.next;let k=b.elt;w+=P.x*(k.y-g.y);let C=k.y*P.x-k.x*P.y;Z+=(P.x+k.x)*C,d+=(P.y+k.y)*C,w*=.5;let M=1/(6*w);return Z*=M,d*=M,n.overlap=-w,n.centroidx=Z,n.centroidy=d,!0}else return!1}else return!1}else return!1}else{let i=[],l=!0,o=null,r=null,a=-1e100,p=!0,c=t.polygon.gverts.next,h=0,u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,m=x.gnormx*e.circle.worldCOMx+x.gnormy*e.circle.worldCOMy;if(m>x.gprojection+e.circle.radius){p=!1;break}else m+e.circle.radius>x.gprojection+s.Config.epsilon&&(l=!1,i[h]=!0);m-=x.gprojection+e.circle.radius,m>a&&(a=m,o=x,r=c),c=c.next,++h,u=u.next}if(p){if(l)return n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0;{let x=r,m=r.next==null?t.polygon.gverts.next:r.next,_=e.circle.worldCOMy*o.gnormx-e.circle.worldCOMx*o.gnormy,y;if(_<=x.y*o.gnormx-x.x*o.gnormy){let z=e.circle.radius,f=x.x-e.circle.worldCOMx,w=x.y-e.circle.worldCOMy;y=f*f+w*w<=z*z}else if(_>=m.y*o.gnormx-m.x*o.gnormy){let z=e.circle.radius,f=m.x-e.circle.worldCOMx,w=m.y-e.circle.worldCOMy;y=f*f+w*w<=z*z}else y=!0;if(y){let z=[],f=0,w=!0,Z=null,d=0,b=t.polygon.gverts.next;for(;b!=null;){let g=b,P=g.x-e.circle.worldCOMx,v=g.y-e.circle.worldCOMy,N=P*P+v*v;(z[f]=N<=e.circle.radius*e.circle.radius)?(d=f,Z=b):w=!1,++f,b=b.next}if(w){let g=t.polygon;if(g.zip_worldCOM&&g.body!=null){if(g.zip_worldCOM=!1,g.zip_localCOM){if(g.zip_localCOM=!1,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 k=.5;v.localCOMx*=k,v.localCOMy*=k}else{v.localCOMx=0,v.localCOMy=0;let N=0,k=v.lverts.next,C=k;k=k.next;let E=k;for(k=k.next;k!=null;){let R=k;N+=E.x*(R.y-C.y);let q=R.y*E.x-R.x*E.y;v.localCOMx+=(E.x+R.x)*q,v.localCOMy+=(E.y+R.y)*q,C=E,E=R,k=k.next}k=v.lverts.next;let M=k;N+=E.x*(M.y-C.y);let S=M.y*E.x-M.x*E.y;v.localCOMx+=(E.x+M.x)*S,v.localCOMy+=(E.y+M.y)*S,C=E,E=M,k=k.next;let O=k;N+=E.x*(O.y-C.y);let L=O.y*E.x-O.x*E.y;v.localCOMx+=(E.x+O.x)*L,v.localCOMy+=(E.y+O.y)*L,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=!1,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,!0}else{for(;be.flowpoly.head!=null;){let v=be.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=pe.zpp_pool,pe.zpp_pool=N}}be.flowsegs.clear();let g=null,P=1;for(Z==null?(Z=t.polygon.gverts.next,P=2):(g=Z,be.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;be.flowpoly.add(Z)}else{let v=be.flowpoly.head.elt,N=Z,k=N.x-v.x,C=N.y-v.y,E=v.x-e.circle.worldCOMx,M=v.y-e.circle.worldCOMy,S=k*k+C*C,O=2*(E*k+M*C),L=E*E+M*M-e.circle.radius*e.circle.radius,T=Math.sqrt(O*O-4*S*L);S=1/(2*S);let R=(-O-T)*S,q=R<s.Config.epsilon?(-O+T)*S:R,G=0,B=0,V=q;G=v.x+(N.x-v.x)*V,B=v.y+(N.y-v.y)*V;let Y=g.x-G,$=g.y-B;if(Y*Y+$*$<s.Config.epsilon)break;let X=be.flowpoly,H=pe.get(G,B);X.add(H),P=2}else if(P==2){let v=Z.next;v==null&&(v=t.polygon.gverts.next);let N=Z;P=0;let k=v,C=v;for(;;){let E=C,M=d+1;if(M==t.polygon.edgeCnt&&(M=0),i[d])if(z[M]){let S=E.x-N.x,O=E.y-N.y,L=N.x-e.circle.worldCOMx,T=N.y-e.circle.worldCOMy,R=S*S+O*O,q=2*(L*S+T*O),G=L*L+T*T-e.circle.radius*e.circle.radius,B=Math.sqrt(q*q-4*R*G);R=1/(2*R);let V=(-q-B)*R,Y=V<s.Config.epsilon?(-q+B)*R:V,$=0,X=0,H=Y;$=N.x+(E.x-N.x)*H,X=N.y+(E.y-N.y)*H;let ee=g.x-$,W=g.y-X;if(ee*ee+W*W<s.Config.epsilon){P=0,C=k;break}let D=pe.get($,X);be.flowsegs.add(be.flowpoly.head.elt),be.flowsegs.add(D),be.flowpoly.add(D),P=1,C=k;break}else{let S=0,O=0,L=E.x-N.x,T=E.y-N.y,R=N.x-e.circle.worldCOMx,q=N.y-e.circle.worldCOMy,G=L*L+T*T,B=2*(R*L+q*T),V=R*R+q*q-e.circle.radius*e.circle.radius,Y=B*B-4*G*V,$;if(Y*Y<s.Config.epsilon?(Y<0?S=10:(O=-B/(2*G),S=O),$=!1):(Y=Math.sqrt(Y),G=1/(2*G),S=(-B-Y)*G,O=(-B+Y)*G,$=!0),S<1-s.Config.epsilon&&O>s.Config.epsilon){let X=0,H=0,ee=S;X=N.x+(E.x-N.x)*ee,H=N.y+(E.y-N.y)*ee;let W;if(g!=null){let A=g.x-X,J=g.y-H;W=A*A+J*J<s.Config.epsilon}else W=!1;if(W){P=0,C=k;break}let D=pe.get(X,H);if(be.flowpoly.head!=null&&(be.flowsegs.add(be.flowpoly.head.elt),be.flowsegs.add(D)),be.flowpoly.add(D),g==null&&(g=be.flowpoly.head.elt),$){let A=0,J=0,Q=O;A=N.x+(E.x-N.x)*Q,J=N.y+(E.y-N.y)*Q;let K=be.flowpoly,ie=pe.get(A,J);K.add(ie)}}}N=E,Z=C,d=M,C=C.next,C==null&&(C=t.polygon.gverts.next);break}for(;C!=k;){let E=C,M=d+1;if(M==t.polygon.edgeCnt&&(M=0),i[d])if(z[M]){let S=E.x-N.x,O=E.y-N.y,L=N.x-e.circle.worldCOMx,T=N.y-e.circle.worldCOMy,R=S*S+O*O,q=2*(L*S+T*O),G=L*L+T*T-e.circle.radius*e.circle.radius,B=Math.sqrt(q*q-4*R*G);R=1/(2*R);let V=(-q-B)*R,Y=V<s.Config.epsilon?(-q+B)*R:V,$=0,X=0,H=Y;$=N.x+(E.x-N.x)*H,X=N.y+(E.y-N.y)*H;let ee=g.x-$,W=g.y-X;if(ee*ee+W*W<s.Config.epsilon){P=0,C=k;break}let D=pe.get($,X);be.flowsegs.add(be.flowpoly.head.elt),be.flowsegs.add(D),be.flowpoly.add(D),P=1,C=k;break}else{let S=0,O=0,L=E.x-N.x,T=E.y-N.y,R=N.x-e.circle.worldCOMx,q=N.y-e.circle.worldCOMy,G=L*L+T*T,B=2*(R*L+q*T),V=R*R+q*q-e.circle.radius*e.circle.radius,Y=B*B-4*G*V,$;if(Y*Y<s.Config.epsilon?(Y<0?S=10:(O=-B/(2*G),S=O),$=!1):(Y=Math.sqrt(Y),G=1/(2*G),S=(-B-Y)*G,O=(-B+Y)*G,$=!0),S<1-s.Config.epsilon&&O>s.Config.epsilon){let X=0,H=0,ee=S;X=N.x+(E.x-N.x)*ee,H=N.y+(E.y-N.y)*ee;let W;if(g!=null){let A=g.x-X,J=g.y-H;W=A*A+J*J<s.Config.epsilon}else W=!1;if(W){P=0,C=k;break}let D=pe.get(X,H);if(be.flowpoly.head!=null&&(be.flowsegs.add(be.flowpoly.head.elt),be.flowsegs.add(D)),be.flowpoly.add(D),g==null&&(g=be.flowpoly.head.elt),$){let A=0,J=0,Q=O;A=N.x+(E.x-N.x)*Q,J=N.y+(E.y-N.y)*Q;let K=be.flowpoly,ie=pe.get(A,J);K.add(ie)}}}N=E,Z=C,d=M,C=C.next,C==null&&(C=t.polygon.gverts.next)}}if(be.flowpoly.head==null)return!1;if(be.flowpoly.head.next==null){let v=!0,N=t.polygon.edges.head;for(;N!=null;){let k=N.elt;if(k.gnormx*e.circle.worldCOMx+k.gnormy*e.circle.worldCOMy>k.gprojection){v=!1;break}N=N.next}return v?(n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0):!1}else{let v=0,N=0,k=0;if(be.flowpoly.head.next.next!=null){let E=0,M=0,S=0;E=0;let O=be.flowpoly.head,L=O.elt;O=O.next;let T=O.elt;for(O=O.next;O!=null;){let X=O.elt;E+=T.x*(X.y-L.y);let H=X.y*T.x-X.x*T.y;M+=(T.x+X.x)*H,S+=(T.y+X.y)*H,L=T,T=X,O=O.next}O=be.flowpoly.head;let R=O.elt;E+=T.x*(R.y-L.y);let q=R.y*T.x-R.x*T.y;M+=(T.x+R.x)*q,S+=(T.y+R.y)*q,L=T,T=R,O=O.next;let G=O.elt;E+=T.x*(G.y-L.y);let B=G.y*T.x-G.x*T.y;M+=(T.x+G.x)*B,S+=(T.y+G.y)*B,E*=.5;let Y=1/(6*E);M*=Y,S*=Y;let $=-E;v+=M*$,N+=S*$,k-=E}else be.flowsegs.add(be.flowpoly.head.elt),be.flowsegs.add(be.flowpoly.head.next.elt);for(;be.flowsegs.head!=null;){let E=be.flowsegs.pop_unsafe(),M=be.flowsegs.pop_unsafe(),S=M.x-E.x,O=M.y-E.y,L=S,T=O,R=L*L+T*T,G=1/Math.sqrt(R);L*=G,T*=G;let B=L;L=-T,T=B;let V=E.x+M.x,Y=E.y+M.y,$=.5;V*=$,Y*=$;let X=1;V-=e.circle.worldCOMx*X,Y-=e.circle.worldCOMy*X;let H=L*V+T*Y,ee=0,W=0,F=H,D=F/e.circle.radius,A=Math.sqrt(1-D*D),J=Math.acos(D);ee=e.circle.radius*(e.circle.radius*J-F*A),W=.6666666666666666*e.circle.radius*A*A*A/(J-D*A),V=e.circle.worldCOMx,Y=e.circle.worldCOMy;let Q=W;V+=L*Q,Y+=T*Q;let K=ee;v+=V*K,N+=Y*K,k+=ee}let C=1/k;return v*=C,N*=C,n.overlap=k,n.centroidx=v,n.centroidy=N,!0}}}else return!1}}else return!1}else{let i=e.circle,l=t.circle,o=l.worldCOMx-i.worldCOMx,r=l.worldCOMy-i.worldCOMy,a=i.radius+l.radius,p=o*o+r*r;if(p>a*a)return!1;if(p<s.Config.epsilon*s.Config.epsilon)return i.radius<l.radius?(n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy):(n.overlap=l.area,n.centroidx=l.worldCOMx,n.centroidy=l.worldCOMy),!0;{let c=Math.sqrt(p),h=1/c,u=.5*(c-(l.radius*l.radius-i.radius*i.radius)*h);if(u<=-i.radius)n.overlap=i.area,n.centroidx=i.worldCOMx,n.centroidy=i.worldCOMy;else{let x=c-u;if(x<=-l.radius)n.overlap=l.area,n.centroidx=l.worldCOMx,n.centroidy=l.worldCOMy;else{let m=0,_=0,y=0,z=0,f=u,w=f/i.radius,Z=Math.sqrt(1-w*w),d=Math.acos(w);m=i.radius*(i.radius*d-f*Z),_=.6666666666666666*i.radius*Z*Z*Z/(d-w*Z);let b=x,g=b/l.radius,P=Math.sqrt(1-g*g),v=Math.acos(g);y=l.radius*(l.radius*v-b*P),z=.6666666666666666*l.radius*P*P*P/(v-g*P);let N=m+y,k=(_*m+(c-z)*y)/N*h;n.overlap=N,n.centroidx=i.worldCOMx+o*k,n.centroidy=i.worldCOMy+r*k}}return!0}}}static capsuleContains(e,t){let n=be._closestT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.x,t.y),s=e.spine1x+n*(e.spine2x-e.spine1x),i=e.spine1y+n*(e.spine2y-e.spine1y),l=t.x-s,o=t.y-i;return l*l+o*o<e.radius*e.radius}static _closestT(e,t,n,s,i,l){let o=n-e,r=s-t,a=o*o+r*r;if(a<1e-12)return 0;let p=((i-e)*o+(l-t)*r)/a;return p<0&&(p=0),p>1&&(p=1),p}static _closestTT(e,t,n,s,i,l,o,r){let a=n-e,p=s-t,c=o-i,h=r-l,u=e-i,x=t-l,m=a*a+p*p,_=c*c+h*h,y=c*u+h*x,z,f;if(m<1e-12&&_<1e-12)return[0,0];if(m<1e-12)return z=0,f=y/_,f<0&&(f=0),f>1&&(f=1),[z,f];let w=a*u+p*x;if(_<1e-12)return f=0,z=-w/m,z<0&&(z=0),z>1&&(z=1),[z,f];let Z=a*c+p*h,d=m*_-Z*Z;if(d>1e-12)z=(Z*y-w*_)/d,z<0&&(z=0),z>1&&(z=1),f=(Z*z+y)/_,f<0?(f=0,z=-w/m,z<0&&(z=0),z>1&&(z=1)):f>1&&(f=1,z=(Z-w)/m,z<0&&(z=0),z>1&&(z=1));else{let b=1/m,g=-(a*u+p*x)*b,P=g+Z*b,v=Math.max(0,Math.min(g,P)),N=Math.min(1,Math.max(g,P));z=v<=N?(v+N)*.5:g<0?0:1,f=(Z*z+y)/_,f<0&&(f=0),f>1&&(f=1)}return[z,f]}static _getOrCreateContact(e,t,n){let s=null,i=e.contacts.next;for(;i!=null;){if(t==i.hash){s=i;break}i=i.next}if(s==null){Pe.zpp_pool==null?s=new Pe:(s=Pe.zpp_pool,Pe.zpp_pool=s.next,s.next=null);let l=s.inner;l.jnAcc=l.jtAcc=0,s.hash=t,s.fresh=!0,s.arbiter=e,e.jrAcc=0;let o=e.contacts;s._inuse=!0;let r=s;r.next=o.next,o.next=r,o.modified=!0,o.length++,e.innards.add(l)}else s.fresh=!1;return s}static _capsuleContactCollide(e,t,n,s,i){let l=t.capsule;return e.type==0?be._circleCapsuleContact(e.circle,l,n,s,i):e.type==1?be._polyCapsuleContact(e.polygon,l,n,s,i):be._capsuleCapsuleContact(e.capsule,l,n,s,i)}static _circleCapsuleContact(e,t,n,s,i){let l=be._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,e.worldCOMx,e.worldCOMy),o=t.spine1x+l*(t.spine2x-t.spine1x),r=t.spine1y+l*(t.spine2y-t.spine1y),a=e.radius+t.radius,p=e.worldCOMx-o,c=e.worldCOMy-r,h=p*p+c*c;if(h>a*a)return!1;let u;if(h<i.Config.epsilon*i.Config.epsilon){let x=(e.worldCOMx+o)*.5,m=(e.worldCOMy+r)*.5;u=be._getOrCreateContact(n,0,n.stamp),u.px=x,u.py=m,n.nx=1,n.ny=0,u.dist=-a,u.stamp=n.stamp,u.posOnly=!1}else{let x=1/Math.sqrt(h),m=x<i.Config.epsilon?1e100:1/x,_=.5+(e.radius-.5*a)*x,y=e.worldCOMx-p*_,z=e.worldCOMy-c*_;u=be._getOrCreateContact(n,0,n.stamp),u.px=y,u.py=z,s?(n.nx=p*x,n.ny=c*x):(n.nx=-p*x,n.ny=-c*x),u.dist=m-a,u.stamp=n.stamp,u.posOnly=!1}if(u!=null){let x=u.inner,m=t.localCOMx+(2*l-1)*t.halfLength;return s?(x.lr1x=m,x.lr1y=t.localCOMy,x.lr2x=e.localCOMx,x.lr2y=e.localCOMy):(x.lr1x=e.localCOMx,x.lr1y=e.localCOMy,x.lr2x=m,x.lr2y=t.localCOMy),n.radius=a,n.ptype=2,!0}return!1}static _capsuleCapsuleContact(e,t,n,s,i){let l=e.radius+t.radius,o=i.Config.epsilon,r=(z,f,w)=>{let Z=e.spine1x+f*(e.spine2x-e.spine1x),d=e.spine1y+f*(e.spine2y-e.spine1y),b=t.spine1x+w*(t.spine2x-t.spine1x),g=t.spine1y+w*(t.spine2y-t.spine1y),P=b-Z,v=g-d,N=P*P+v*v;if(N>l*l)return!1;let k=be._getOrCreateContact(n,z,n.stamp);if(N<o*o)k.px=(Z+b)*.5,k.py=(d+g)*.5,z===0&&(n.nx=1,n.ny=0),k.dist=-l;else{let S=1/Math.sqrt(N),O=1/S,L=P*S,T=v*S,R=.5+(e.radius-.5*l)*S;k.px=Z+P*R,k.py=d+v*R,z===0&&(n.nx=s?-L:L,n.ny=s?-T:T),k.dist=O-l}k.stamp=n.stamp,k.posOnly=!1;let C=k.inner,E=e.localCOMx+(2*f-1)*e.halfLength,M=t.localCOMx+(2*w-1)*t.halfLength;return s?(C.lr1x=M,C.lr1y=t.localCOMy,C.lr2x=E,C.lr2y=e.localCOMy):(C.lr1x=E,C.lr1y=e.localCOMy,C.lr2x=M,C.lr2y=t.localCOMy),!0},[a,p]=be._closestTT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine1x,t.spine1y,t.spine2x,t.spine2y);if(!r(0,a,p))return!1;if(n.radius=l,n.ptype=2,be.debugCapsule){let z=e.spine1x+a*(e.spine2x-e.spine1x),f=e.spine1y+a*(e.spine2y-e.spine1y),w=t.spine1x+p*(t.spine2x-t.spine1x),Z=t.spine1y+p*(t.spine2y-t.spine1y),d=w-z,b=Z-f,g=Math.sqrt(d*d+b*b);console.log("[capCap] nx=",n.nx.toFixed(3),"ny=",n.ny.toFixed(3),"dist=",g.toFixed(3),"minDist=",l.toFixed(3),"pen=",(g-l).toFixed(3))}let c=e.spine2x-e.spine1x,h=e.spine2y-e.spine1y,u=t.spine2x-t.spine1x,x=t.spine2y-t.spine1y,m=c*c+h*h,_=u*u+x*x,y=c*x-h*u;if(y*y<.01*m*_&&m>1e-12&&_>1e-12){let z=[[0,be._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,e.spine1x,e.spine1y)],[1,be._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,e.spine2x,e.spine2y)],[be._closestT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine1x,t.spine1y),0],[be._closestT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine2x,t.spine2y),1]],f=0,w=null;for(let[Z,d]of z){let b=Z-a,g=b*b;if(g>f+1e-6){let P=e.spine1x+Z*(e.spine2x-e.spine1x),v=e.spine1y+Z*(e.spine2y-e.spine1y),N=t.spine1x+d*(t.spine2x-t.spine1x),k=t.spine1y+d*(t.spine2y-t.spine1y),C=N-P,E=k-v;C*C+E*E<=l*l&&(f=g,w=[Z,d])}}w!=null&&r(1,w[0],w[1])}return!0}static _polyCapsuleContact(e,t,n,s,i){let l=-1e100,o=null,r=null,a=!0,p=e.gverts.next,c=e.edges.head;for(;c!=null;){let k=c.elt,C=k.gnormx*t.spine1x+k.gnormy*t.spine1y,E=k.gnormx*t.spine2x+k.gnormy*t.spine2y,S=(C<E?C:E)-k.gprojection-t.radius;if(S>0){a=!1;break}S>l&&(l=S,o=k,r=p),p=p.next,c=c.next}if(!a)return!1;let h=t.spine2x-t.spine1x,u=t.spine2y-t.spine1y,x=h*h+u*u;if(x>1e-12){let k=Math.sqrt(x),C=-u/k,E=h/k,M=C*t.spine1x+E*t.spine1y,S=1e100,O=-1e100,L=e.gverts.next;for(;L!=null;){let R=C*L.x+E*L.y;R<S&&(S=R),R>O&&(O=R),L=L.next}if((S>M+t.radius?S-(M+t.radius):O<M-t.radius?M-t.radius-O:0)>0)return!1}let m=r,_=r.next==null?e.gverts.next:r.next,y=m.y*o.gnormx-m.x*o.gnormy,z=_.y*o.gnormx-_.x*o.gnormy,f=k=>t.localCOMx+(2*k-1)*t.halfLength,w=(k,C)=>{k.lr1x=C,k.lr1y=t.localCOMy,k.lr2x=0,k.lr2y=0},Z=(k,C,E,M)=>{let O=o.gnormx*E+o.gnormy*M-o.gprojection-t.radius;if(O>0)return;let L=be._getOrCreateContact(n,k,n.stamp);L.px=E-o.gnormx*(t.radius+O*.5),L.py=M-o.gnormy*(t.radius+O*.5),L.dist=O,L.stamp=n.stamp,L.posOnly=!1,w(L.inner,f(C))},d=(k,C,E,M,S)=>{let O=M-C,L=S-E,T=O*O+L*L;if(T>t.radius*t.radius)return!1;let R=be._getOrCreateContact(n,0,n.stamp);if(n.radius=t.radius,n.ptype=0,n.__ref_edge1=o,n.__ref_vertex=0,T<i.Config.epsilon*i.Config.epsilon)R.px=C,R.py=E,n.nx=s?-o.gnormx:o.gnormx,n.ny=s?-o.gnormy:o.gnormy,R.dist=-t.radius;else{let q=1/Math.sqrt(T),G=1/q,B=O*q,V=L*q;R.px=C+B*t.radius,R.py=E+V*t.radius,n.nx=s?-B:B,n.ny=s?-V:V,R.dist=G-t.radius}return R.stamp=n.stamp,R.posOnly=!1,w(R.inner,f(k)),!0},b=t.spine1y*o.gnormx-t.spine1x*o.gnormy,g=t.spine2y*o.gnormx-t.spine2x*o.gnormy,P=b>y&&b<z,v=g>y&&g<z;if(!P&&!v){let k=o.gnormx*t.spine1x+o.gnormy*t.spine1y,C=o.gnormx*t.spine2x+o.gnormy*t.spine2y;if(k<=C){if(b<=y){if(d(0,t.spine1x,t.spine1y,m.x,m.y))return!0}else if(d(0,t.spine1x,t.spine1y,_.x,_.y))return!0}else if(g<=y){if(d(1,t.spine2x,t.spine2y,m.x,m.y))return!0}else if(d(1,t.spine2x,t.spine2y,_.x,_.y))return!0;let E=be._closestT(t.spine1x,t.spine1y,t.spine2x,t.spine2y,t.spine1x+o.gnormx*o.gprojection,t.spine1y+o.gnormy*o.gprojection),M=(y+z)*.5,S=t.spine1y*o.gnormx-t.spine1x*o.gnormy,L=t.spine2y*o.gnormx-t.spine2x*o.gnormy-S,T=Math.abs(L)>1e-12?(M-S)/L:.5;T<0&&(T=0),T>1&&(T=1);let R=t.spine1x+T*(t.spine2x-t.spine1x),q=t.spine1y+T*(t.spine2y-t.spine1y);return o.gnormx*R+o.gnormy*q-o.gprojection-t.radius>0?!1:(n.nx=s?-o.gnormx:o.gnormx,n.ny=s?-o.gnormy:o.gnormy,n.radius=t.radius,n.lproj=o.lprojection,n.lnormx=o.lnormx,n.lnormy=o.lnormy,n.ptype=s?1:0,n.rev=s,n.__ref_edge1=o,n.__ref_vertex=0,Z(0,T,R,q),n.oc1!=null&&n.oc1.stamp==n.stamp)}n.nx=s?-o.gnormx:o.gnormx,n.ny=s?-o.gnormy:o.gnormy,n.radius=t.radius,n.lproj=o.lprojection,n.lnormx=o.lnormx,n.lnormy=o.lnormy,n.ptype=s?1:0,n.rev=s,n.__ref_edge1=o,n.__ref_vertex=0;let N=0;return P&&Z(N++,0,t.spine1x,t.spine1y),v&&Z(N,1,t.spine2x,t.spine2y),be.debugCapsule&&N>0&&console.log("[polyCapsule face] nx=",n.nx.toFixed(3),"ny=",n.ny.toFixed(3),"dist=",n.oc1?.dist?.toFixed(3),"ptype=",n.ptype,"rev=",n.rev,"bestDist=",l.toFixed(3)),N>0||n.oc1!=null&&n.oc1.stamp==n.stamp}static _capsuleTestCollide(e,t){let n=t.capsule;if(e.type==0){let s=be._closestT(n.spine1x,n.spine1y,n.spine2x,n.spine2y,e.circle.worldCOMx,e.circle.worldCOMy),i=n.spine1x+s*(n.spine2x-n.spine1x),l=n.spine1y+s*(n.spine2y-n.spine1y),o=e.circle.radius+n.radius,r=e.circle.worldCOMx-i,a=e.circle.worldCOMy-l;return r*r+a*a<=o*o}else if(e.type==1){let s=e.polygon.edges.head;for(;s!=null;){let r=s.elt,a=r.gnormx*n.spine1x+r.gnormy*n.spine1y,p=r.gnormx*n.spine2x+r.gnormy*n.spine2y;if((a<p?a:p)-r.gprojection-n.radius>0)return!1;s=s.next}let i=n.spine2x-n.spine1x,l=n.spine2y-n.spine1y,o=i*i+l*l;if(o>1e-12){let r=-l,a=i,p=Math.sqrt(o),c=r/p,h=a/p,u=c*n.spine1x+h*n.spine1y,x=1e100,m=-1e100,_=e.polygon.gverts.next;for(;_!=null;){let y=c*_.x+h*_.y;y<x&&(x=y),y>m&&(m=y),_=_.next}if(x>u+n.radius||m<u-n.radius)return!1}return!0}else{let s=e.capsule,[i,l]=be._closestTT(s.spine1x,s.spine1y,s.spine2x,s.spine2y,n.spine1x,n.spine1y,n.spine2x,n.spine2y),o=s.spine1x+i*(s.spine2x-s.spine1x),r=s.spine1y+i*(s.spine2y-s.spine1y),a=n.spine1x+l*(n.spine2x-n.spine1x),p=n.spine1y+l*(n.spine2y-n.spine1y),c=s.radius+n.radius,h=a-o,u=p-r;return h*h+u*u<=c*c}}static _capsuleFlowCollide(e,t,n,s){let i=e.type==2?e.capsule:t.capsule,l=e.type==2?t:e,o=i.area||Math.PI*i.radius*i.radius+4*i.halfLength*i.radius;if(l.type==2){let u=l.capsule,[x,m]=be._closestTT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,u.spine1x,u.spine1y,u.spine2x,u.spine2y),_=i.spine1x+x*(i.spine2x-i.spine1x),y=i.spine1y+x*(i.spine2y-i.spine1y),z=u.spine1x+m*(u.spine2x-u.spine1x),f=u.spine1y+m*(u.spine2y-u.spine1y),w=z-_,Z=f-y,d=Math.sqrt(w*w+Z*Z),b=i.radius+u.radius;if(d>=b)return!1;let g=b-d;return n.overlap=g*Math.min(2*i.radius,2*u.radius)*.5,n.buoyx=(_+z)*.5,n.buoyy=(y+f)*.5,!0}if(l.type==0){let u=l.circle,x=be._closestT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,u.worldCOMx,u.worldCOMy),m=i.spine1x+x*(i.spine2x-i.spine1x),_=i.spine1y+x*(i.spine2y-i.spine1y),y=u.worldCOMx-m,z=u.worldCOMy-_,f=Math.sqrt(y*y+z*z),w=i.radius+u.radius;if(f>=w)return!1;let Z=w-f;return n.overlap=Z*Math.min(2*i.radius,2*u.radius)*.5,n.buoyx=(m+u.worldCOMx)*.5,n.buoyy=(_+u.worldCOMy)*.5,!0}let r=l.polygon,a=1e100,p=0,c=0,h=r.edges.head;for(;h!=null;){let u=h.elt,x=u.gnormx*i.spine1x+u.gnormy*i.spine1y,m=u.gnormx*i.spine2x+u.gnormy*i.spine2y,_=x<m?x:m,y=u.gprojection+i.radius-_;if(y<0)return!1;y<a&&(a=y,p=u.gnormx,c=u.gnormy),h=h.next}return n.overlap=a*2*i.radius*.5,n.buoyx=i.worldCOMx,n.buoyy=i.worldCOMy,!0}};be.flowpoly=null,be.flowsegs=null;var Ee=be;var is=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 o=l,r=o.prev,a=null,p=o.diagonals.head;for(;p!=null;){let c=p.elt,h=p.next==null?o.next:p.next.elt;if(!j.isinner(h,o,r)){a=p,r=c,p=p.next;continue}let u=!0,x=c,m=x.prev,_=null,y=x.diagonals.head;for(;y!=null;){let z=y.elt;if(z==o){let f=y.next==null?x.next:y.next.elt;u=j.isinner(f,x,m);break}m=z,_=y,y=y.next}if(u){p=o.diagonals.erase(a),x.diagonals.erase(_);continue}r=c,a=p,p=p.next}if(l=l.next,l==i)break}}}};var et=class et{constructor(){this.normal=null;this.shape=null;this.convex=null;this.position=null;this.ray=null;this.inner=!1;this.next=null;this.toiDistance=0}static getRay(e,t,n,s){let i;et.rayPool==null?(et.internal=!0,i=et._createRayResult(),i.zpp_inner=new et,i.zpp_inner.ray=i,et.internal=!1):(i=et.rayPool.ray,et.rayPool=et.rayPool.next,i.zpp_inner.next=null);let l=i.zpp_inner;return l.normal=e,e.zpp_inner._immutable=!0,l.toiDistance=t,l.inner=n,l.shape=s,i}static getConvex(e,t,n,s){let i;et.convexPool==null?(et.internal=!0,i=et._createConvexResult(),i.zpp_inner=new et,i.zpp_inner.convex=i,et.internal=!1):(i=et.convexPool.convex,et.convexPool=et.convexPool.next,i.zpp_inner.next=null);let l=i.zpp_inner;return l.normal=e,l.position=t,e.zpp_inner._immutable=!0,t.zpp_inner._immutable=!0,l.toiDistance=n,l.shape=s,i}disposed(){if(this.next!=null)throw new Error("Error: This object has been disposed of and cannot be used")}free(){et._disposeVec2(this.normal),this.position!=null&&et._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=et.convexPool,et.convexPool=this):(this.next=et.rayPool,et.rayPool=this)}static _disposeVec2(e){if(e.zpp_inner._immutable=!1,e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=e.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");if(t._isimmutable!=null&&t._isimmutable(),t._inuse)throw new Error("Error: This Vec2 is not disposable");let n=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null,e.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=e:xe.poolVec2=e,xe.nextVec2=e,e.zpp_disp=!0,n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=pe.zpp_pool,pe.zpp_pool=n}};et.rayPool=null,et.convexPool=null,et.internal=!1,et._createRayResult=null,et._createConvexResult=null;var mn=et;var Ii=class Ii{constructor(){this.prev=null;this.next=null;this.posx=0;this.posy=0;this.vert=null;this.value=0;this.positive=!1;this.parent=null;this.rank=0;this.used=!1}static path(e){let t;return Ii.zpp_pool==null?t=new Ii:(t=Ii.zpp_pool,Ii.zpp_pool=t.next,t.next=null),t.vert=e,t.parent=t,t.rank=0,t.used=!1,t}alloc(){}free(){this.vert=null,this.parent=null}};Ii.zpp_pool=null;var He=Ii;var ji=class ji{constructor(){this.next=null;this.time=0;this.virtualint=!1;this.vertex=!1;this.path0=null;this.end=null;this.start=null;this.path1=null}static get(e,t,n,s,i,l=!1,o=!1){let r;return ji.zpp_pool==null?r=new ji:(r=ji.zpp_pool,ji.zpp_pool=r.next,r.next=null),r.virtualint=l,r.end=t,r.start=n,r.path0=s,r.path1=i,r.time=e,r.vertex=o,r}alloc(){}free(){this.end=this.start=null,this.path0=this.path1=null}};ji.zpp_pool=null;var ot=ji;var si=class si{constructor(){this.x=0;this.y=0;this.prev=null;this.next=null;this.wrap=null;this.forced=!1}static get(e,t){let n;return si.zpp_pool==null?n=new si:(n=si.zpp_pool,si.zpp_pool=n.next,n.next=null),n.forced=!1,n.x=e,n.y=t,n}alloc(){this.forced=!1}free(){if(this.wrap!=null){this.wrap.zpp_inner._inuse=!1;let e=this.wrap;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=e.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");if(t._isimmutable!=null&&t._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let n=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let s=e;s.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=s:xe.poolVec2=s,xe.nextVec2=s,s.zpp_disp=!0;let i=n;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i._isimmutable=null,i._validate=null,i._invalidate=null,i.next=pe.zpp_pool,pe.zpp_pool=i,this.wrap=null}this.prev=this.next=null}wrapper(){if(this.wrap==null){let e=this.x,t=this.y;if(t==null&&(t=0),e==null&&(e=0),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(xe.poolVec2==null?n=si._createVec2Fn():(n=xe.poolVec2,xe.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n===xe.nextVec2&&(xe.nextVec2=null)),n.zpp_inner==null){let s;pe.zpp_pool==null?s=new pe:(s=pe.zpp_pool,pe.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x===e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y===t}else i=!1;if(!i){n.zpp_inner.x=e,n.zpp_inner.y=t;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.wrap=n,this.wrap.zpp_inner._inuse=!0,this.wrap.zpp_inner._invalidate=s=>this.modwrap(s),this.wrap.zpp_inner._validate=()=>this.getwrap()}return this.wrap}modwrap(e){this.x=e.x,this.y=e.y}getwrap(){this.wrap.zpp_inner.x=this.x,this.wrap.zpp_inner.y=this.y}};si.zpp_pool=null,si._createVec2Fn=null;var ve=si;var $e=class $e{static run(e,t,n,s,i,l){let o=_e(),r=o.__zpp;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=t.zpp_inner;a._validate!=null&&a._validate();let p=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=t.zpp_inner;c._validate!=null&&c._validate();let h=t.zpp_inner.y;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=n.zpp_inner;u._validate!=null&&u._validate();let x=n.zpp_inner.x-p;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let m=n.zpp_inner;m._validate!=null&&m._validate();let _=n.zpp_inner.y-h,y=s?0:-1/0,z=i?1:1/0,f=-(h*x-p*_),w=null,Z=!1,d=e;for(;;){let B;He.zpp_pool==null?B=new He:(B=He.zpp_pool,He.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*_+f,B.positive=B.value>0,B.value==0&&(Z=!0);let V=B;if(w==null?V.prev=V.next=V:(V.prev=w,V.next=w.next,w.next.prev=V,w.next=V),w=V,d=d.next,d==e)break}if(Z){let B=null,V=w,Y=w;if(V!=null){let J=V;for(;;){let Q=J;if(Q.value!=0){B=Q;break}if(J=J.next,J==Y)break}}let $,X;$=x,X=_;let H=$*$+X*X,W=1/Math.sqrt(H);$*=W,X*=W;let F=$;$=-X,X=F;let D=null,A=B;for(;;){if(A.value!=0&&(D==null||A==D.next)){if(D=A,A=A.next,A==B)break;continue}let J=D.value*A.value;if(J==0){if(A=A.next,A==B)break;continue}let Q=D.next,K;if(J>0)K=D.positive;else{let se=Q.next,ne,re;ne=Q.posx+se.posx,re=Q.posy+se.posy;let le=.5;ne*=le,re*=le;let he=ne+$*1e-8,ae=re+X*1e-8,ce=!1,te=e,ue=e;if(te!=null){let de=te;for(;;){let me=de,ge=me.prev;if((me.y<ae&&ge.y>=ae||ge.y<ae&&me.y>=ae)&&(me.x<=he||ge.x<=he)&&me.x+(ae-me.y)/(ge.y-me.y)*(ge.x-me.x)<he&&(ce=!ce),de=de.next,de==ue)break}}K=ce}let ie=Q,oe=A;if(ie!=null){let se=ie;for(;;){let ne=se;if(ne.positive=K,se=se.next,se==oe)break}}if(D=A,A=A.next,A==B)break}for(;!(A.value!=0&&(D==null||A==D.next));){let J=D.value*A.value;if(J==0)break;let Q=D.next,K;if(J>0)K=D.positive;else{let se=Q.next,ne,re;ne=Q.posx+se.posx,re=Q.posy+se.posy;let le=.5;ne*=le,re*=le;let he=ne+$*1e-8,ae=re+X*1e-8,ce=!1,te=e,ue=e;if(te!=null){let de=te;for(;;){let me=de,ge=me.prev;if((me.y<ae&&ge.y>=ae||ge.y<ae&&me.y>=ae)&&(me.x<=he||ge.x<=he)&&me.x+(ae-me.y)/(ge.y-me.y)*(ge.x-me.x)<he&&(ce=!ce),de=de.next,de==ue)break}}K=ce}let ie=Q,oe=A;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 r.util.ZNPList_ZPP_CutInt),$e.paths==null&&($e.paths=new r.util.ZNPList_ZPP_CutVert);let b=null,g=w.posx,P=w.posy,v;ve.zpp_pool==null?v=new ve:(v=ve.zpp_pool,ve.zpp_pool=v.next,v.next=null),v.forced=!1,v.x=g,v.y=P;let N=v;N.prev=N.next=N,b=N;let k=b,C;He.zpp_pool==null?C=new He:(C=He.zpp_pool,He.zpp_pool=C.next,C.next=null),C.vert=b,C.parent=C,C.rank=0,C.used=!1;let E=C;$e.paths.add(E);let M=w;for(;;){let B=M.next,V=B.posx,Y=B.posy,$;ve.zpp_pool==null?$=new ve:($=ve.zpp_pool,ve.zpp_pool=$.next,$.next=null),$.forced=!1,$.x=V,$.y=Y;let X=$;if(M.positive==B.positive){let H=X;b==null?(H.prev=H.next=H,b=H):(H.next=b,H.prev=b.prev,b.prev.next=H,b.prev=H)}else{let H=B.posx-M.posx,ee=B.posy-M.posy,W=_*H-x*ee;W=1/W;let F=p-M.posx,D=h-M.posy,A=(ee*F-H*D)*W;if(A<y||A>z){let J=$e.ints,Q=!0;Q==null&&(Q=!1);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=A,K.vertex=!1,J.add(K);let ie=X;b==null?(ie.prev=ie.next=ie,b=ie):(ie.next=b,ie.prev=b.prev,b.prev.next=ie,b.prev=ie)}else if(M.value==0){let J=b.prev;b=null;let Q=J.x,K=J.y,ie;ve.zpp_pool==null?ie=new ve:(ie=ve.zpp_pool,ve.zpp_pool=ie.next,ie.next=null),ie.forced=!1,ie.x=Q,ie.y=K;let oe=ie;oe.prev=oe.next=oe,b=oe;let se=X;b==null?(se.prev=se.next=se,b=se):(se.next=b,se.prev=b.prev,b.prev.next=se,b.prev=se);let ne=$e.paths.head.elt,re=$e.paths,le;He.zpp_pool==null?le=new He:(le=He.zpp_pool,He.zpp_pool=le.next,le.next=null),le.vert=b,le.parent=le,le.rank=0,le.used=!1,re.add(le);let he=$e.paths.head.elt,ae=$e.ints,ce=!0;ce==null&&(ce=!1);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=J,te.start=b,te.path0=ne,te.path1=he,te.time=A,te.vertex=!1,ae.add(te)}else if(B.value==0){let J=X;b==null?(J.prev=J.next=J,b=J):(J.next=b,J.prev=b.prev,b.prev.next=J,b.prev=J);let Q=b.prev;b=null;let K=B.posx,ie=B.posy,oe;ve.zpp_pool==null?oe=new ve:(oe=ve.zpp_pool,ve.zpp_pool=oe.next,oe.next=null),oe.forced=!1,oe.x=K,oe.y=ie;let se=oe;se.prev=se.next=se,b=se;let ne=$e.paths.head.elt,re=$e.paths,le;He.zpp_pool==null?le=new He:(le=He.zpp_pool,He.zpp_pool=le.next,le.next=null),le.vert=b,le.parent=le,le.rank=0,le.used=!1,re.add(le);let he=$e.paths.head.elt,ae=$e.ints,ce=!0;ce==null&&(ce=!1);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=b,te.path0=ne,te.path1=he,te.time=A,te.vertex=!1,ae.add(te)}else{let J=(_*F-x*D)*W,Q,K;Q=M.posx,K=M.posy;let ie=J;Q+=H*ie,K+=ee*ie;let oe;ve.zpp_pool==null?oe=new ve:(oe=ve.zpp_pool,ve.zpp_pool=oe.next,oe.next=null),oe.forced=!1,oe.x=Q,oe.y=K;let se=oe;b==null?(se.prev=se.next=se,b=se):(se.next=b,se.prev=b.prev,b.prev.next=se,b.prev=se);let ne=b.prev;b=null;let re;ve.zpp_pool==null?re=new ve:(re=ve.zpp_pool,ve.zpp_pool=re.next,re.next=null),re.forced=!1,re.x=Q,re.y=K;let le=re;le.prev=le.next=le,b=le;let he=X;b==null?(he.prev=he.next=he,b=he):(he.next=b,he.prev=b.prev,b.prev.next=he,b.prev=he);let ae=$e.paths.head.elt,ce=$e.paths,te;He.zpp_pool==null?te=new He:(te=He.zpp_pool,He.zpp_pool=te.next,te.next=null),te.vert=b,te.parent=te,te.rank=0,te.used=!1,ce.add(te);let ue=$e.paths.head.elt,de=$e.ints,me=!1;me==null&&(me=!1);let ge;ot.zpp_pool==null?ge=new ot:(ge=ot.zpp_pool,ot.zpp_pool=ge.next,ge.next=null),ge.virtualint=me,ge.end=ne,ge.start=b,ge.path0=ae,ge.path1=ue,ge.time=A,ge.vertex=!1,de.add(ge)}}if(M=M.next,M==w)break}let S=b.prev;S.next.prev=k.prev,k.prev.next=S.next,S.next=k,k.prev=S;let O=$e.paths.head.elt,L;if(E==E.parent)L=E;else{let B=E,V=null;for(;B!=B.parent;){let Y=B.parent;B.parent=V,V=B,B=Y}for(;V!=null;){let Y=V.parent;V.parent=B,V=Y}L=B}let T;if(O==O.parent)T=O;else{let B=O,V=null;for(;B!=B.parent;){let Y=B.parent;B.parent=V,V=B,B=Y}for(;V!=null;){let Y=V.parent;V.parent=B,V=Y}T=B}L!=T&&(L.rank<T.rank?L.parent=T:L.rank>T.rank?T.parent=L:(T.parent=L,L.rank++));let R=$e.ints;if(R.head!=null&&R.head.next!=null){let B=R.head,V,Y,$,X,H=1,ee,W,F;for(;;){for(ee=0,Y=B,B=null,V=B;Y!=null;){for(++ee,$=Y,W=0,F=H;$!=null&&W<H;)++W,$=$.next;for(;W>0||F>0&&$!=null;)W==0?(X=$,$=$.next,--F):F==0||$==null||Y.elt.time<$.elt.time?(X=Y,Y=Y.next,--W):(X=$,$=$.next,--F),V!=null?V.next=X:B=X,V=X;Y=$}if(V.next=null,H<<=1,!(ee>1))break}R.head=B,R.modified=!0,R.pushmod=!0}for(;$e.ints.head!=null;){let B=$e.ints.pop_unsafe(),V=$e.ints.pop_unsafe();if(!B.virtualint&&!V.virtualint){B.end.next.prev=V.start.prev,V.start.prev.next=B.end.next,B.end.next=V.start,V.start.prev=B.end,V.end.next.prev=B.start.prev,B.start.prev.next=V.end.next,V.end.next=B.start,B.start.prev=V.end;let X;if(B.path0==B.path0.parent)X=B.path0;else{let F=B.path0,D=null;for(;F!=F.parent;){let A=F.parent;F.parent=D,D=F,F=A}for(;D!=null;){let A=D.parent;D.parent=F,D=A}X=F}let H;if(V.path1==V.path1.parent)H=V.path1;else{let F=V.path1,D=null;for(;F!=F.parent;){let A=F.parent;F.parent=D,D=F,F=A}for(;D!=null;){let A=D.parent;D.parent=F,D=A}H=F}X!=H&&(X.rank<H.rank?X.parent=H:X.rank>H.rank?H.parent=X:(H.parent=X,X.rank++));let ee;if(B.path1==B.path1.parent)ee=B.path1;else{let F=B.path1,D=null;for(;F!=F.parent;){let A=F.parent;F.parent=D,D=F,F=A}for(;D!=null;){let A=D.parent;D.parent=F,D=A}ee=F}let W;if(V.path0==V.path0.parent)W=V.path0;else{let F=V.path0,D=null;for(;F!=F.parent;){let A=F.parent;F.parent=D,D=F,F=A}for(;D!=null;){let A=D.parent;D.parent=F,D=A}W=F}ee!=W&&(ee.rank<W.rank?ee.parent=W:ee.rank>W.rank?W.parent=ee:(W.parent=ee,ee.rank++))}else if(B.virtualint&&!V.virtualint){let X;if(V.end!=null&&V.end.prev==V.end){V.end.next=V.end.prev=null;let W=V.end;if(W.wrap!=null){W.wrap.zpp_inner._inuse=!1;let F=W.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=F.zpp_inner;if(D._immutable)throw new Error("Error: Vec2 is immutable");if(D._isimmutable!=null&&D._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let A=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let J=F;J.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=J:xe.poolVec2=J,xe.nextVec2=J,J.zpp_disp=!0;let Q=A;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=pe.zpp_pool,pe.zpp_pool=Q,W.wrap=null}W.prev=W.next=null,W.next=ve.zpp_pool,ve.zpp_pool=W,X=null}else{let W=V.end.prev;V.end.prev.next=V.end.next,V.end.next.prev=V.end.prev,V.end.next=V.end.prev=null;let F=V.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=D.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F,V.end=null,X=W}if(V.end=X,!V.vertex)if(V.end!=V.path0.vert){V.start.x=V.end.x,V.start.y=V.end.y;let W;if(V.end!=null&&V.end.prev==V.end){V.end.next=V.end.prev=null;let F=V.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=D.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F,W=null}else{let F=V.end.prev;V.end.prev.next=V.end.next,V.end.next.prev=V.end.prev,V.end.next=V.end.prev=null;let D=V.end;if(D.wrap!=null){D.wrap.zpp_inner._inuse=!1;let A=D.wrap;if(A!=null&&A.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let J=A.zpp_inner;if(J._immutable)throw new Error("Error: Vec2 is immutable");if(J._isimmutable!=null&&J._isimmutable(),A.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let Q=A.zpp_inner;A.zpp_inner.outer=null,A.zpp_inner=null;let K=A;K.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=K:xe.poolVec2=K,xe.nextVec2=K,K.zpp_disp=!0;let ie=Q;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=pe.zpp_pool,pe.zpp_pool=ie,D.wrap=null}D.prev=D.next=null,D.next=ve.zpp_pool,ve.zpp_pool=D,V.end=null,W=F}V.end=W}else{let W=V.start.next;if(V.start.x=W.x,V.start.y=W.y,W!=null&&W.prev==W){W.next=W.prev=null;let F=W;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=D.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F}else{W.prev.next=W.next,W.next.prev=W.prev,W.next=W.prev=null;let F=W;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=D.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F}}V.end.next.prev=V.start.prev,V.start.prev.next=V.end.next,V.end.next=V.start,V.start.prev=V.end;let H;if(V.path0==V.path0.parent)H=V.path0;else{let W=V.path0,F=null;for(;W!=W.parent;){let D=W.parent;W.parent=F,F=W,W=D}for(;F!=null;){let D=F.parent;F.parent=W,F=D}H=W}let ee;if(V.path1==V.path1.parent)ee=V.path1;else{let W=V.path1,F=null;for(;W!=W.parent;){let D=W.parent;W.parent=F,F=W,W=D}for(;F!=null;){let D=F.parent;F.parent=W,F=D}ee=W}H!=ee&&(H.rank<ee.rank?H.parent=ee:H.rank>ee.rank?ee.parent=H:(ee.parent=H,H.rank++))}else if(V.virtualint&&!B.virtualint){let X;if(B.end!=null&&B.end.prev==B.end){B.end.next=B.end.prev=null;let W=B.end;if(W.wrap!=null){W.wrap.zpp_inner._inuse=!1;let F=W.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=F.zpp_inner;if(D._immutable)throw new Error("Error: Vec2 is immutable");if(D._isimmutable!=null&&D._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let A=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let J=F;J.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=J:xe.poolVec2=J,xe.nextVec2=J,J.zpp_disp=!0;let Q=A;Q.outer!=null&&(Q.outer.zpp_inner=null,Q.outer=null),Q._isimmutable=null,Q._validate=null,Q._invalidate=null,Q.next=pe.zpp_pool,pe.zpp_pool=Q,W.wrap=null}W.prev=W.next=null,W.next=ve.zpp_pool,ve.zpp_pool=W,X=null}else{let W=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 F=B.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=D.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F,B.end=null,X=W}if(B.end=X,!B.vertex)if(B.end!=B.path0.vert){B.start.x=B.end.x,B.start.y=B.end.y;let W;if(B.end!=null&&B.end.prev==B.end){B.end.next=B.end.prev=null;let F=B.end;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=D.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F,W=null}else{let F=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=!1;let A=D.wrap;if(A!=null&&A.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let J=A.zpp_inner;if(J._immutable)throw new Error("Error: Vec2 is immutable");if(J._isimmutable!=null&&J._isimmutable(),A.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let Q=A.zpp_inner;A.zpp_inner.outer=null,A.zpp_inner=null;let K=A;K.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=K:xe.poolVec2=K,xe.nextVec2=K,K.zpp_disp=!0;let ie=Q;ie.outer!=null&&(ie.outer.zpp_inner=null,ie.outer=null),ie._isimmutable=null,ie._validate=null,ie._invalidate=null,ie.next=pe.zpp_pool,pe.zpp_pool=ie,D.wrap=null}D.prev=D.next=null,D.next=ve.zpp_pool,ve.zpp_pool=D,B.end=null,W=F}B.end=W}else{let W=B.start.next;if(B.start.x=W.x,B.start.y=W.y,W!=null&&W.prev==W){W.next=W.prev=null;let F=W;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=D.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F}else{W.prev.next=W.next,W.next.prev=W.prev,W.next=W.prev=null;let F=W;if(F.wrap!=null){F.wrap.zpp_inner._inuse=!1;let D=F.wrap;if(D!=null&&D.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=D.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),D.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=D.zpp_inner;D.zpp_inner.outer=null,D.zpp_inner=null;let Q=D;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=pe.zpp_pool,pe.zpp_pool=K,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F}}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 H;if(B.path0==B.path0.parent)H=B.path0;else{let W=B.path0,F=null;for(;W!=W.parent;){let D=W.parent;W.parent=F,F=W,W=D}for(;F!=null;){let D=F.parent;F.parent=W,F=D}H=W}let ee;if(B.path1==B.path1.parent)ee=B.path1;else{let W=B.path1,F=null;for(;W!=W.parent;){let D=W.parent;W.parent=F,F=W,W=D}for(;F!=null;){let D=F.parent;F.parent=W,F=D}ee=W}H!=ee&&(H.rank<ee.rank?H.parent=ee:H.rank>ee.rank?ee.parent=H:(ee.parent=H,H.rank++))}let Y=B;Y.end=Y.start=null,Y.path0=Y.path1=null,Y.next=ot.zpp_pool,ot.zpp_pool=Y;let $=V;$.end=$.start=null,$.path0=$.path1=null,$.next=ot.zpp_pool,ot.zpp_pool=$}let q=l??new o.geom.GeomPolyList,G=$e.paths.head;for(;G!=null;){let B=G.elt,V;if(B==B.parent)V=B;else{let X=B,H=null;for(;X!=X.parent;){let ee=X.parent;X.parent=H,H=X,X=ee}for(;H!=null;){let ee=H.parent;H.parent=X,H=ee}V=X}if(V.used){G=G.next;continue}V.used=!0;let Y=V.vert,$=!0;for(;V.vert!=null&&($||Y!=V.vert);)if($=!1,Y.x==Y.next.x&&Y.y==Y.next.y)if(Y==V.vert&&(V.vert=Y.next==Y?null:Y.next,$=!0),Y!=null&&Y.prev==Y)Y.next=Y.prev=null,Y=null;else{let X=Y.next;Y.prev.next=Y.next,Y.next.prev=Y.prev,Y.next=Y.prev=null,Y=X}else Y=Y.next;if(V.vert!=null){let X=o.geom.GeomPoly.get();X.zpp_inner.vertices=V.vert,q.zpp_inner.reverse_flag?q.push(X):q.unshift(X)}G=G.next}for(;$e.paths.head!=null;){let V=$e.paths.pop_unsafe();V.vert=null,V.parent=null,V.next=He.zpp_pool,He.zpp_pool=V}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=He.zpp_pool,He.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 V=w;V.vert=null,V.parent=null,V.next=He.zpp_pool,He.zpp_pool=V,w=B}return q}};$e.ints=null,$e.paths=null;var ss=$e;var ls=class j{static validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=t.body.posx+(t.body.axisy*u.x-t.body.axisx*u.y),h.y=t.body.posy+(u.x*t.body.axisx+u.y*t.body.axisy),c=c.next}}let s=t.edges.head,i=t.gverts.next,l=i;for(i=i.next;i!=null;){let a=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,l=a,i=i.next}let o=t.gverts.next,r=s.elt;r.gp0=l,r.gp1=o,r.gnormx=t.body.axisy*r.lnormx-t.body.axisx*r.lnormy,r.gnormy=r.lnormx*t.body.axisx+r.lnormy*t.body.axisy,r.gprojection=t.body.posx*r.gnormx+t.body.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;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 if(e.type==2)e.capsule.__validate_aabb();else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=l;l=l.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next}}if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type==1&&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=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type==1&&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=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}static _computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null){e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;let t=1;e.localCOMx+=e.lverts.next.next.x*t,e.localCOMy+=e.lverts.next.next.y*t;let n=.5;e.localCOMx*=n,e.localCOMy*=n}else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let c=n;t+=i.x*(c.y-s.y);let h=c.y*i.x-c.x*i.y;e.localCOMx+=(i.x+c.x)*h,e.localCOMy+=(i.y+c.y)*h,s=i,i=c,n=n.next}n=e.lverts.next;let l=n;t+=i.x*(l.y-s.y);let o=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*o,e.localCOMy+=(i.y+l.y)*o,s=i,i=l,n=n.next;let r=n;t+=i.x*(r.y-s.y);let a=r.y*i.x-r.x*i.y;e.localCOMx+=(i.x+r.x)*a,e.localCOMy+=(i.y+r.y)*a,t=1/(3*t);let p=t;e.localCOMx*=p,e.localCOMy*=p}}};var os=class{constructor(e=null){this.outer=null;this.vertices=null;this.outer=e}};var An=class{constructor(){this.rank=0;this.out=!1;this.next=null;this.parent=this}free(){this.parent=this}alloc(){this.out=!1,this.rank=0}};An.zpp_pool=null;var In=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(){}};In.zpp_pool=null;var ze=class ze{static _init(e,t){ze._zpp=e,ze._nape=t,ze.me=new ze,ze.look_march=[-1,224,56,216,14,-1,54,214,131,99,-1,91,141,109,181,85]}static _allocVert(e,t){let n;return ve.zpp_pool==null?n=new ve:(n=ve.zpp_pool,ve.zpp_pool=n.next,n.next=null),n.forced=!1,n.x=e,n.y=t,n}static _freeVert(e){if(e.wrap!=null){e.wrap.zpp_inner._inuse=!1;let t=e.wrap;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=t.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let s=t.zpp_inner;t.zpp_inner.outer=null,t.zpp_inner=null;let i=t;i.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=i:xe.poolVec2=i,xe.nextVec2=i,i.zpp_disp=!0;let l=s;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l._isimmutable=null,l._validate=null,l._invalidate=null,l.next=pe.zpp_pool,pe.zpp_pool=l,e.wrap=null}e.prev=e.next=null,e.next=ve.zpp_pool,ve.zpp_pool=e}static _allocSpan(){let e;return An.zpp_pool==null?e=new An:(e=An.zpp_pool,An.zpp_pool=e.next,e.next=null),e.out=!1,e.rank=0,e}static _allocPair(){let e;return In.zpp_pool==null?e=new In:(e=In.zpp_pool,In.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=In.zpp_pool,In.zpp_pool=e}static _findRoot(e){if(e==e.parent)return e;let t=e,n=null;for(;t!=t.parent;){let s=t.parent;t.parent=n,n=t,t=s}for(;n!=null;){let s=n.parent;n.parent=t,n=s}return t}static _union(e,t){let n=ze._findRoot(e),s=ze._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}static _pushVert(e,t){return e==null?t.prev=t.next=t:(t.prev=e,t.next=e.next,e.next.prev=t,e.next=t),t}static _isDegenKey(e){return e==1||e==4||e==16||e==64||e==3||e==12||e==48||e==192||e==129||e==6||e==24||e==96||e==5||e==20||e==80||e==65||e==17||e==68}static ISO(e,t,n){return e(t,n)}static run(e,t,n,s,i,l,o,r,a){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=l.zpp_inner;p._validate!=null&&p._validate();let c=(s-t)/l.zpp_inner.x,h=c|0;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");p=l.zpp_inner,p._validate!=null&&p._validate();let u=(i-n)/l.zpp_inner.y,x=u|0;c!=h&&++h,u!=x&&++x,r&&(ze.map==null?ze.map=new Xi(h,x):ze.map.resize(h,x,null)),ze.isos==null?ze.isos=new Ki(h+1,x+1):ze.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 f=l.zpp_inner;f._validate!=null&&f._validate(),z=n+l.zpp_inner.y*y}else z=i;for(let f=0;f<h+1;f++){let w;if(f==0)w=t;else if(f<=h){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let b=l.zpp_inner;b._validate!=null&&b._validate(),w=t+l.zpp_inner.x*f}else w=s;let Z=ze.isos,d=e(w,z);Z.list[y*Z.width+f]=d}}ze.ints==null?ze.ints=new Yi(h+1,(x<<1)+1):ze.ints.resize(h+1,(x<<1)+1,null);let m=null;r&&(m=ze._allocSpan(),m.next=null);let _=n;for(let y=0;y<x;y++){let z=_,f;if(y==x-1)f=i;else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let d=l.zpp_inner;d._validate!=null&&d._validate(),f=n+l.zpp_inner.y*(y+1)}_=f;let w=t,Z=null;for(let d=0;d<h;d++){let b=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 E=l.zpp_inner;E._validate!=null&&E._validate(),g=t+l.zpp_inner.x*(d+1)}w=g;let P=d==0||!r,v=y==0||!r,N=d==h-1||!r,k=y==x-1||!r,C=ze.me.marchSquare(e,ze.isos,ze.ints,b,z,g,f,d,y,P,v,N,k,o);if(C==null){Z=null;continue}if(r){let E=C.p2!=null&&C.okey2!=14?C.p2:C.p1;C.pd=((E==C.p2?C.okey2:C.okey1)&128)==0?E.prev:E.prev.prev;let M=ze.map;M.list[y*M.width+d]=C;let S;if(Z!=null){let T=C.key1,R=T&1|(T&192)>>5,q=0;(R&1)!=0&&++q,(R&2)!=0&&++q,(R&4)!=0&&++q,S=q>=2}else S=!1;S?(ze.me.combLR(Z,C),C.span1=Z.spanr):(C.span1=ze._allocSpan(),C.span1.next=m,m=C.span1),C.p2!=null?(C.span2=ze._allocSpan(),C.span2.next=m,m=C.span2,C.spanr=C.span2):C.spanr=C.span1;let O=(C.keyr&28)>>2,L=0;(O&1)!=0&&++L,(O&2)!=0&&++L,(O&4)!=0&&++L,L>=2?Z=C:Z=null}else ze.me.output(a,C.p1),C.p2!=null&&ze.me.output(a,C.p2),ze._freePair(C)}}if(r){for(let y=1;y<x;y++){let z=null;for(let f=0;f<h;f++){let w=ze.map,Z=w.list[y*w.width+f];if(Z==null){z=null;continue}let b=(Z.p2!=null&&Z.okey2==14?Z.okey2:Z.okey1)&7,g=0;if((b&1)!=0&&++g,(b&2)!=0&&++g,(b&4)!=0&&++g,g<2){z=null;continue}let P=ze.map,v=P.list[(y-1)*P.width+f];if(v==null){z=null;continue}let k=((v.p2!=null&&v.okey2==56?v.okey2:v.okey1)&112)>>4,C=0;if((k&1)!=0&&++C,(k&2)!=0&&++C,(k&4)!=0&&++C,C<2){z=null;continue}let E=v.p2!=null&&v.okey2==56?v.span2:v.span1,M=Z.p2!=null&&Z.okey2==14?Z.span2:Z.span1,S=ze._findRoot(E),O=ze._findRoot(M);S==O?z!=M&&ze.me.combUD_virtual(v,Z):(ze._union(E,M),ze.me.combUD(v,Z)),z=((M==Z.span2?Z.okey2:Z.okey1)&4)!=0?M:null}}for(let y=0;y<x;y++)for(let z=0;z<h;z++){let f=ze.map,w=f.list[y*f.width+z];if(w==null)continue;let Z=ze._findRoot(w.span1);Z.out||(Z.out=!0,ze.me.output(a,w.p1)),w.p2!=null&&(Z=ze._findRoot(w.span2),Z.out||(Z.out=!0,ze.me.output(a,w.p2))),ze._freePair(w),f.list[y*f.width+z]=null}for(;m!=null;){let y=m;m=y.next;let z=y;z.parent=z,z.next=An.zpp_pool,An.zpp_pool=z}}}output(e,t){let n=ze._nape,s;if(t==null||t.next==t||t.next==t.prev)s=!0;else{let o=0,r=t,a=t;if(r!=null){let c=r;for(;;){let h=c;if(o+=h.x*(h.next.y-h.prev.y),c=c.next,c==a)break}}let p=o*.5;s=p*p<n.Config.epsilon*n.Config.epsilon}if(s){for(;t!=null;)if(t!=null&&t.prev==t)t.next=t.prev=null,t=null;else{let o=t.next;t.prev.next=t.next,t.next.prev=t.prev,t.next=t.prev=null,t=o}return}let i=n.geom.GeomPoly.get();i.zpp_inner.vertices=t;let l=e;l.zpp_inner.reverse_flag?l.push(i):l.unshift(i)}linkright(e,t){let n=t&7;return n==0?e:n==3?e.next.next:e.next}linkleft(e,t){return(t&1)==0?e.prev:e}linkdown(e,t){return(t&128)==0?e.prev:e.prev.prev}linkup(e,t){return e}combLR(e,t){let n=e.pr,s=e.okeyr&7,i=s==0?n:s==3?n.next.next:n.next,l=t.p1,o=(t.okey1&1)==0?l.prev:l,r=i.next,a=o.prev;(e.keyr&4)!=0?(t.pr==t.p1&&(t.pr=i.prev),t.p1=i.prev,i.prev.next=o.next,o.next.prev=i.prev,ze._freeVert(i)):(i.next=o.next,o.next.prev=i),ze._freeVert(o),(e.keyr&16)!=0?(t.pd=r.next,r.next.prev=a.prev,a.prev.next=r.next,ze._freeVert(r)):(r.prev=a.prev,a.prev.next=r),ze._freeVert(a)}combUD(e,t){let n=e.pd,s=t.p2!=null&&t.key2==14?t.p2:t.p1,i=n.prev,l=s.next;s.next=n.next,n.next.prev=s,ze._freeVert(n),l.prev=i.prev,i.prev.next=l,i==e.p1&&(e.p1=l),ze._freeVert(i)}combUD_virtual(e,t){let n=e.pd,s=t.p2!=null&&t.key2==14?t.p2:t.p1,i=n.prev,l=s.next;n.forced=s.forced=i.forced=l.forced=!0}combLeft(e){let t=e&1|(e&192)>>5,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combRight(e){let t=(e&28)>>2,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combUp(e){let t=e&7,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combDown(e){let t=(e&112)>>4,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}comb(e){let t=0;return(e&1)!=0&&++t,(e&2)!=0&&++t,(e&4)!=0&&++t,t>=2}_buildPoly(e,t,n,s,i,l,o,r,a,p,c,h,u,x,m,_,y,z,f){let w=null;for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let d;if(Z==0)d=ze._allocVert(s,i),(x||m)&&(d.forced=!0);else if(Z==2)d=ze._allocVert(l,i),(_||m)&&(d.forced=!0);else if(Z==4)d=ze._allocVert(l,o),(_||y)&&(d.forced=!0);else if(Z==6)d=ze._allocVert(s,o),(x||y)&&(d.forced=!0);else if(Z==1){if(d=n.list[(a<<1)*n.width+r],d==null){let b=this.xlerp(s,l,i,p,c,z,f);d=ze._allocVert(b,i),n.list[(a<<1)*n.width+r]=d}else d=ze._allocVert(d.x,d.y);m&&(d.forced=!0),(d.x==s||d.x==l)&&(d.x==s&&(e&1)!=0||d.x==l&&(e&4)!=0)&&(e^=2)}else if(Z==5){if(d=n.list[((a<<1)+2)*n.width+r],d==null){let b=this.xlerp(s,l,o,u,h,z,f);d=ze._allocVert(b,o),n.list[((a<<1)+2)*n.width+r]=d}else d=ze._allocVert(d.x,d.y);y&&(d.forced=!0),(d.x==s||d.x==l)&&(d.x==s&&(e&64)!=0||d.x==l&&(e&16)!=0)&&(e^=32)}else if(Z==3){if(d=n.list[((a<<1)+1)*n.width+(r+1)],d==null){let b=this.ylerp(i,o,l,c,h,z,f);d=ze._allocVert(l,b),n.list[((a<<1)+1)*n.width+(r+1)]=d}else d=ze._allocVert(d.x,d.y);_&&(d.forced=!0),(d.y==i||d.y==o)&&(d.y==i&&(e&4)!=0||d.y==o&&(e&16)!=0)&&(e^=8)}else{if(d=n.list[((a<<1)+1)*n.width+r],d==null){let b=this.ylerp(i,o,s,p,u,z,f);d=ze._allocVert(s,b),n.list[((a<<1)+1)*n.width+r]=d}else d=ze._allocVert(d.x,d.y);x&&(d.forced=!0),(d.y==i||d.y==o)&&(d.y==i&&(e&1)!=0||d.y==o&&(e&64)!=0)&&(e^=128)}w=ze._pushVert(w,d)}return w!=null&&(w=w.next),{head:w,val:e}}marchSquare(e,t,n,s,i,l,o,r,a,p,c,h,u,x){let m=0,_=t.list[a*t.width+r];_<0&&(m|=8);let y=t.list[a*t.width+(r+1)];y<0&&(m|=4);let z=t.list[(a+1)*t.width+(r+1)];z<0&&(m|=2);let f=t.list[(a+1)*t.width+r];if(f<0&&(m|=1),m==0)return null;let w=ze._allocPair();if(m!=10&&m!=5){let Z=ze.look_march[m];w.okey1=Z;let d=this._buildPoly(Z,t,n,s,i,l,o,r,a,_,y,z,f,p,c,h,u,e,x);w.p1=d.head,Z=d.val,w.key1=Z,ze._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+o))<0;if(m==10)if(Z){let d=187;w.okey1=d;let b=this._buildPoly(d,t,n,s,i,l,o,r,a,_,y,z,f,p,c,h,u,e,x);w.p1=b.head,d=b.val,w.key1=d,ze._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 b=this._buildPoly(d,t,n,s,i,l,o,r,a,_,y,z,f,p,c,h,u,e,x);if(w.p1=b.head,d=b.val,w.key1=d,ze._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,o,r,a,_,y,z,f,p,c,h,u,e,x,w).val,w.key2=g,ze._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,o,r,a,_,y,z,f,p,c,h,u,e,x);w.p1=P.head,g=P.val,w.key1=g,ze._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 b=this._buildPoly(d,t,n,s,i,l,o,r,a,_,y,z,f,p,c,h,u,e,x);w.p1=b.head,d=b.val,w.key1=d,ze._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 b=this._buildPoly(d,t,n,s,i,l,o,r,a,_,y,z,f,p,c,h,u,e,x);if(w.p1=b.head,d=b.val,w.key1=d,ze._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,o,r,a,_,y,z,f,p,c,h,u,e,x,w).val,w.key2=g,ze._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,o,r,a,_,y,z,f,p,c,h,u,e,x);w.p1=P.head,g=P.val,w.key1=g,ze._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,o,r,a,p,c,h,u,x,m,_,y,z,f,w){for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let d;if(Z==0)d=ze._allocVert(s,i),(x||m)&&(d.forced=!0);else if(Z==2)d=ze._allocVert(l,i),(_||m)&&(d.forced=!0);else if(Z==4)d=ze._allocVert(l,o),(_||y)&&(d.forced=!0);else if(Z==6)d=ze._allocVert(s,o),(x||y)&&(d.forced=!0);else if(Z==1){if(d=n.list[(a<<1)*n.width+r],d==null){let g=this.xlerp(s,l,i,p,c,z,f);d=ze._allocVert(g,i),n.list[(a<<1)*n.width+r]=d}else d=ze._allocVert(d.x,d.y);m&&(d.forced=!0),(d.x==s||d.x==l)&&(d.x==s&&(e&1)!=0||d.x==l&&(e&4)!=0)&&(e^=2)}else if(Z==5){if(d=n.list[((a<<1)+2)*n.width+r],d==null){let g=this.xlerp(s,l,o,u,h,z,f);d=ze._allocVert(g,o),n.list[((a<<1)+2)*n.width+r]=d}else d=ze._allocVert(d.x,d.y);y&&(d.forced=!0),(d.x==s||d.x==l)&&(d.x==s&&(e&64)!=0||d.x==l&&(e&16)!=0)&&(e^=32)}else if(Z==3){if(d=n.list[((a<<1)+1)*n.width+(r+1)],d==null){let g=this.ylerp(i,o,l,c,h,z,f);d=ze._allocVert(l,g),n.list[((a<<1)+1)*n.width+(r+1)]=d}else d=ze._allocVert(d.x,d.y);_&&(d.forced=!0),(d.y==i||d.y==o)&&(d.y==i&&(e&4)!=0||d.y==o&&(e&16)!=0)&&(e^=8)}else{if(d=n.list[((a<<1)+1)*n.width+r],d==null){let g=this.ylerp(i,o,s,p,u,z,f);d=ze._allocVert(s,g),n.list[((a<<1)+1)*n.width+r]=d}else d=ze._allocVert(d.x,d.y);x&&(d.forced=!0),(d.y==i||d.y==o)&&(d.y==i&&(e&1)!=0||d.y==o&&(e&64)!=0)&&(e^=128)}let b=d;w.p2==null?w.p2=b.prev=b.next=b:(b.prev=w.p2,b.next=w.p2.next,w.p2.next.prev=b,w.p2.next=b),w.p2=b}return w.p2!=null&&(w.p2=w.p2.next),{val:e}}lerp(e,t,n,s){let i=ze._nape;if(n==0)return e;if(s==0)return t;{let l=n-s,o=l*l<i.Config.epsilon*i.Config.epsilon?.5:n/l;return o<0?o=0:o>1&&(o=1),e+o*(t-e)}}xlerp(e,t,n,s,i,l,o){let r=ze._nape,a;if(s==0)a=e;else if(i==0)a=t;else{let p=s-i,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=l(a,n);if(p==0)break;if(s*p<0?(t=a,i=p):(e=a,s=p),s==0)a=e;else if(i==0)a=t;else{let c=s-i,h=c*c<r.Config.epsilon*r.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),a=e+h*(t-e)}}return a}ylerp(e,t,n,s,i,l,o){let r=ze._nape,a;if(s==0)a=e;else if(i==0)a=t;else{let p=s-i,c=p*p<r.Config.epsilon*r.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),a=e+c*(t-e)}for(;o--!=0&&e<a&&a<t;){let p=l(n,a);if(p==0)break;if(s*p<0?(t=a,i=p):(e=a,s=p),s==0)a=e;else if(i==0)a=t;else{let c=s-i,h=c*c<r.Config.epsilon*r.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),a=e+h*(t-e)}}return a}};ze.isos=null,ze.ints=null,ze.map=null,ze._zpp=null,ze._nape=null;var ks=ze;var cn=class cn{constructor(){this.outer=null;this.a=0;this.b=0;this.c=0;this.d=0;this.tx=0;this.ty=0;this._invalidate=null;this.next=null}static get(){let e;return cn.zpp_pool==null?e=new cn:(e=cn.zpp_pool,cn.zpp_pool=e.next,e.next=null),e}static identity(){let e=cn.get();return e.setas(1,0,0,1,0,0),e}wrapper(){if(this.outer==null)if(cn._wrapFn)this.outer=cn._wrapFn(this);else{this.outer=new cn._nape.geom.Mat23;let e=this.outer.zpp_inner;e.next=cn.zpp_pool,cn.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}invalidate(){this._invalidate!=null&&this._invalidate()}set(e){this.setas(e.a,e.b,e.c,e.d,e.tx,e.ty)}setas(e,t,n,s,i,l){this.tx=i,this.ty=l,this.a=e,this.b=t,this.c=n,this.d=s}free(){}alloc(){}};cn._nape=null,cn._wrapFn=null,cn.zpp_pool=null;var Es=cn;var Bi=class{constructor(e,t){this.outer=null;this.m=0;this.n=0;this.m=e,this.n=t,this.x=[];let n=0,s=e*t;for(;n<s;)n++,this.x.push(0)}};var yt=class yt{constructor(){this.node=null;this.prev=null;this.next=null;this.rightchain=!1;this.helper=null;this.type=0;this.diagonals=null;this.forced=!1;this.y=0;this.x=0;this.mag=0;this.id=0;this.id=yt.nextId++,this.diagonals=new xi}static get(e){let t;return yt.zpp_pool==null?t=new yt:(t=yt.zpp_pool,yt.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t}static rightdistance(e,t){let n=e.next.y>e.y,s=e.next.x-e.x,i=e.next.y-e.y,l=t.x-e.x,o=t.y-e.y;return(n?-1:1)*(o*s-l*i)}static vert_lt(e,t){if(t==e||t==e.next)return!0;if(e.y==e.next.y){let n=e.x,s=e.next.x;return(n<s?n:s)<=t.x}else return yt.rightdistance(e,t)<=0}static edge_swap(e,t){let n=e.node;e.node=t.node,t.node=n}static edge_lt(e,t){if(e==t&&e.next==t.next)return!1;if(e==t.next)return!yt.vert_lt(e,t);if(t==e.next)return yt.vert_lt(t,e);if(e.y==e.next.y)if(t.y==t.next.y){let n=e.x,s=e.next.x,i=t.x,l=t.next.x;return(n>s?n:s)>(i>l?i:l)}else return yt.rightdistance(t,e)>0?!0:yt.rightdistance(t,e.next)>0;else{let n=yt.rightdistance(e,t),s=yt.rightdistance(e,t.next);if(n==0&&s==0){let o=e.x,r=e.next.x,a=t.x,p=t.next.x;return(o>r?o:r)>(a>p?a:p)}if(n*s>=0)return n<0?!0:s<0;let i=yt.rightdistance(t,e),l=yt.rightdistance(t,e.next);return i*l>=0?i>0?!0:l>0:!1}}alloc(){}free(){this.helper=null}copy(){let e;return yt.zpp_pool==null?e=new yt:(e=yt.zpp_pool,yt.zpp_pool=e.next,e.next=null),e.x=this.x,e.y=this.y,e.forced=this.forced,e}sort(){let e=this.prev.x-this.x,t=this.prev.y-this.y,n=this.next.x-this.x,s=this.next.y-this.y,i=s*e-n*t,l=i>0?-1:i==0?0:1,o=this.diagonals;if(o.head!=null&&o.head.next!=null){let r=o.head,a,p,c,h,u=1,x,m,_;for(;;){for(x=0,p=r,r=null,a=r;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,f=z>0?-1:z==0?0:1;e=this.prev.x-this.x,t=this.prev.y-this.y,n=c.elt.x-this.x,s=c.elt.y-this.y;let w=s*e-n*t,Z=w>0?-1:w==0?0:1;if(f*Z==1||f*Z==0&&(f==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(f==-1||Z==-1)y=Z==-1;else if(f==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 b=e*n+t*s;y=d<0&&b>0?!0:!(b<0&&d>0)}else y=!0}y?(h=p,p=p.next,--m):(h=c,c=c.next,--_)}a!=null?a.next=h:r=h,a=h}p=c}if(a.next=null,u<<=1,!(x>1))break}o.head=r,o.modified=!0,o.pushmod=!0}}};yt.zpp_pool=null,yt.nextId=0;var Ge=yt;var hn=class hn{constructor(e){this.next=null;this.vertices=null;this.init(e)}static getSharedPP(){return hn.sharedPPList==null&&(hn.sharedPPList=new Si),hn.sharedPPList}static getShared(){return hn.sharedGVList==null&&(hn.sharedGVList=new Fn),hn.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 o=n;for(;;){let r=o;if(t+=r.x*(r.next.y-r.prev.y),o=o.next,o==s)break}}let i=t*.5>0,l=e;for(;;){let o;if(i){let r;Ge.zpp_pool==null?r=new Ge:(r=Ge.zpp_pool,Ge.zpp_pool=r.next,r.next=null),r.x=l.x,r.y=l.y;let a=r;this.vertices==null?this.vertices=a.prev=a.next=a:(a.prev=this.vertices,a.next=this.vertices.next,this.vertices.next.prev=a,this.vertices.next=a),o=a}else{let r;Ge.zpp_pool==null?r=new Ge:(r=Ge.zpp_pool,Ge.zpp_pool=r.next,r.next=null),r.x=l.x,r.y=l.y;let a=r;this.vertices==null?this.vertices=a.prev=a.next=a:(a.next=this.vertices,a.prev=this.vertices.prev,this.vertices.prev.next=a,this.vertices.prev=a),o=a}if(this.vertices=o,this.vertices.forced=l.forced,l=l.next,l==e)break}this.remove_collinear_vertices()}remove_collinear_vertices(){let e=this.vertices,t=!0;for(;t||e!=this.vertices;)if(t=!1,this.eq(e,e.next)){if(e==this.vertices&&(this.vertices=e.next,t=!0),e.forced&&(e.next.forced=!0),e!=null&&e.prev==e){e.next=e.prev=null;let s=e;s.helper=null,s.next=Ge.zpp_pool,Ge.zpp_pool=s,e=null,e=null}else{let s=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let i=e;i.helper=null,i.next=Ge.zpp_pool,Ge.zpp_pool=i,e=s}if(e==null){this.vertices=null;break}}else e=e.next;if(this.vertices==null)return!0;let n;for(;;){for(n=!1,e=this.vertices,t=!0;t||e!=this.vertices;){t=!1;let s=e.prev,i=e.x-s.x,l=e.y-s.y,o=e.next.x-e.x,a=(e.next.y-e.y)*i-o*l;if(a*a>=_e().Config.epsilon*_e().Config.epsilon)e=e.next;else{if(e==this.vertices&&(this.vertices=e.next,t=!0),e!=null&&e.prev==e){e.next=e.prev=null;let p=e;p.helper=null,p.next=Ge.zpp_pool,Ge.zpp_pool=p,e=null,e=null}else{let p=e.next;e.prev.next=e.next,e.next.prev=e.prev,e.next=e.prev=null;let c=e;c.helper=null,c.next=Ge.zpp_pool,Ge.zpp_pool=c,e=p}if(n=!0,e==null){n=!1,this.vertices=null;break}}}if(!n)break}return this.vertices==null}add_diagonal(e,t){e.diagonals.add(t),t.diagonals.add(e),e.forced=t.forced=!0}extract_partitions(e){if(e==null&&(e=new Si),this.vertices!=null){let t=this.vertices,n=this.vertices;if(t!=null){let l=t;for(;l.sort(),l=l.next,l!=n;);}for(this.pull_partitions(this.vertices,e);this.vertices!=null;){let l;if(this.vertices!=null&&this.vertices.prev==this.vertices){this.vertices.next=this.vertices.prev=null;let o=this.vertices;o.helper=null,o.next=Ge.zpp_pool,Ge.zpp_pool=o,l=this.vertices=null}else{let o=this.vertices.next;this.vertices.prev.next=this.vertices.next,this.vertices.next.prev=this.vertices.prev,this.vertices.next=this.vertices.prev=null;let r=this.vertices;r.helper=null,r.next=Ge.zpp_pool,Ge.zpp_pool=r,this.vertices=null,l=o}this.vertices=l}let s=null,i=e.head;for(;i!=null;){if(i.elt.remove_collinear_vertices()){e.erase(s);continue}s=i,i=i.next}}return e}pull_partitions(e,t){let n;hn.zpp_pool==null?n=new hn:(n=hn.zpp_pool,hn.zpp_pool=n.next,n.next=null);let s=e;for(;;){let r;Ge.zpp_pool==null?r=new Ge:(r=Ge.zpp_pool,Ge.zpp_pool=r.next,r.next=null),r.x=s.x,r.y=s.y,r.forced=s.forced;let a=r;if(n.vertices==null?n.vertices=a.prev=a.next=a:(a.prev=n.vertices,a.next=n.vertices.next,n.vertices.next.prev=a,n.vertices.next=a),n.vertices=a,n.vertices.forced=s.forced,s.diagonals.head!=null){let p=s.diagonals,c=p.head.elt;if(p.pop(),c==e)break;s=this.pull_partitions(s,t)}else s=s.next;if(s==e)break}let i=0,l=n.vertices,o=n.vertices;if(l!=null){let r=l;for(;;){let a=r;if(i+=a.x*(a.next.y-a.prev.y),r=r.next,r==o)break}}return i*.5!=0&&t.add(n),s}extract(e){if(e==null&&(e=new Fn),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;ve.zpp_pool==null?c=new ve:(c=ve.zpp_pool,ve.zpp_pool=c.next,c.next=null),c.forced=!1,c.x=a,c.y=p;let h=c;if(n==null?h.prev=h.next=h:(h.prev=n,h.next=n.next,n.next.prev=h,n.next=h),n=h,n.forced=s.forced,s.diagonals.head!=null){let u=s.diagonals,x=u.head.elt;if(u.pop(),x==e)break;s=this.pull(s,t)}else s=s.next;if(s==e)break}let i=0,l=n,o=n;if(l!=null){let a=l;for(;;){let p=a;if(i+=p.x*(p.next.y-p.prev.y),a=a.next,a==o)break}}let r=i*.5;if(r*r>=_e().Config.epsilon*_e().Config.epsilon){let a=n,p=!0;for(;p||a!=n;){p=!1;let c=a.x-a.next.x,h=a.y-a.next.y;if(c*c+h*h<_e().Config.epsilon*_e().Config.epsilon){if(a==n&&(n=a.next,p=!0),a.forced&&(a.next.forced=!0),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else{let u=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=u}if(a==null){n=null;break}}else a=a.next}if(n!=null){let c;for(;;){for(c=!1,a=n,p=!0;p||a!=n;){p=!1;let h=a.prev,u=a.x-h.x,x=a.y-h.y,m=a.next.x-a.x,y=(a.next.y-a.y)*u-m*x;if(y*y>=_e().Config.epsilon*_e().Config.epsilon)a=a.next;else{if(a==n&&(n=a.next,p=!0),a!=null&&a.prev==a)a.next=a.prev=null,a=null;else{let z=a.next;a.prev.next=a.next,a.next.prev=a.prev,a.next=a.prev=null,a=z}if(c=!0,a==null){c=!1,n=null;break}}}if(!c)break}}n!=null&&t.add(n)}return s}};hn.zpp_pool=null,hn.sharedPPList=null,hn.sharedGVList=null;var Je=hn;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,o=n.y-e.y,r;pe.zpp_pool==null?r=new pe:(r=pe.zpp_pool,pe.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=-i-o,r.y=s+l;let a=r,p=a.x*a.x+a.y*a.y,h=1/Math.sqrt(p);return a.x*=h,a.y*=h,o*s-l*i<0&&(a.x=-a.x,a.y=-a.y),a}static below(e,t){if(e.y<t.y)return!0;if(e.y>t.y)return!1;if(e.x<t.x)return!0;if(e.x>t.x)return!1;{let n=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 o=n.x<s.x||n.x==s.x&&n.y<s.y;return n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=pe.zpp_pool,pe.zpp_pool=n,s.outer!=null&&(s.outer.zpp_inner=null,s.outer=null),s._isimmutable=null,s._validate=null,s._invalidate=null,s.next=pe.zpp_pool,pe.zpp_pool=s,o}}static above(e,t){return De.below(t,e)}static left_vertex(e){let t=e.prev;return t.y>e.y?!0:t.y==e.y?e.next.y<e.y:!1}static isMonotone(e){let t=e,n=e,s=e.next,i=e;if(s!=null){let r=s;for(;;){let a=r;if(a.y<t.y&&(t=a),a.y>n.y&&(n=a),r=r.next,r==i)break}}let l=!0,o=t;if(n!=t.next){let r=t.next,a=n;if(r!=null){let p=r;for(;;){let c=p;if(c.y<o.y){l=!1;break}if(o=c,p=p.next,p==a)break}}}if(!l)return!1;if(o=t,n!=t.prev){let r=t.prev,a=n;if(r!=null){let p=r;for(;;){let c=p;if(c.y<o.y){l=!1;break}if(o=c,p=p.prev,p==a)break}}}return l}static getShared(){return 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 xi);let n=t.vertices,s=t.vertices;if(n!=null){let l=n;for(;;){let o=l;De.queue.add(o);let r=o.next.x-o.x,a=o.next.y-o.y,p=o.prev.x-o.x,h=(o.prev.y-o.y)*r-p*a>0;if(o.type=De.below(o.prev,o)?De.below(o.next,o)?h?0:3:4:De.below(o,o.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,o,r,a,p,c=1,h,u,x;for(;;){for(h=0,r=l,l=null,o=l;r!=null;){for(++h,a=r,u=0,x=c;a!=null&&u<c;)++u,a=a.next;for(;u>0||x>0&&a!=null;)u==0?(p=a,a=a.next,--x):x==0||a==null||De.above(r.elt,a.elt)?(p=r,r=r.next,--u):(p=a,a=a.next,--x),o!=null?o.next=p:l=p,o=p;r=a}if(o.next=null,c<<=1,!(h>1))break}i.head=l,i.modified=!0,i.pushmod=!0}for(De.edges==null&&($i.zpp_pool==null?De.edges=new $i:(De.edges=$i.zpp_pool,$i.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 o=l.prev;if(o.helper==null)throw new Error("Fatal error (1): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(l,o.helper),De.edges.remove_node(o.node),o.helper=null;break}case 2:{let o=l.prev;if(o.helper==null)throw new Error("Fatal error (3): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(l,o.helper),De.edges.remove_node(o.node),o.helper=null;let r=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){r=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else{for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent}}}let a=r;if(a!=null){if(a.helper==null)throw new Error("Fatal error (4): Polygon is not weakly-simple and clockwise");a.helper.type==2&&t.add_diagonal(l,a.helper),a.helper=l}break}case 3:{let o=null;if(!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)){o=p;break}if(a.next!=null)for(a=a.next;a.prev!=null;)a=a.prev;else{for(;a.parent!=null&&a==a.parent.next;)a=a.parent;a=a.parent}}}let r=o;if(r!=null){if(r.helper==null)throw new Error("Fatal error (2): Polygon is not weakly-simple and clockwise");t.add_diagonal(l,r.helper),r.helper=l}l.node=De.edges.insert(l),l.helper=l;break}case 4:{let o=l.prev;if(De.left_vertex(l)){if(o.helper==null)throw new Error("Fatal error (5): Polygon is not weakly-simple and clockwise");o.helper.type==2&&t.add_diagonal(l,o.helper),De.edges.remove_node(o.node),o.helper=null,l.node=De.edges.insert(l),l.helper=l}else{let r=null;if(!De.edges.empty()){let p=De.edges.parent;for(;p.prev!=null;)p=p.prev;for(;p!=null;){let c=p.data;if(!Ge.vert_lt(c,l)){r=c;break}if(p.next!=null)for(p=p.next;p.prev!=null;)p=p.prev;else{for(;p.parent!=null&&p==p.parent.next;)p=p.parent;p=p.parent}}}let a=r;if(a==null||a.helper==null)throw new Error("Fatal error (6): Polygon is not weakly-simple and clockwise");a.helper.type==2&&t.add_diagonal(l,a.helper),a.helper=l}break}}}return t}};De.queue=null,De.edges=null,De.sharedPPoly=null;var Dt=De;var Ti=class Ti{constructor(){this.node=null;this.di=0;this.id=0;this.b=null;this.a=null;this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null}static get(e,t){let n;return Ti.zpp_pool==null?n=new Ti:(n=Ti.zpp_pool,Ti.zpp_pool=n.next,n.next=null),n.a=e,n.b=t,e.id<t.id?(n.id=e.id,n.di=t.id):(n.id=t.id,n.di=e.id),n}static edge_swap(e,t){let n=e.node;e.node=t.node,t.node=n}static edge_lt(e,t){return e.id>=t.id?e.id==t.id?e.di<t.di:!1:!0}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){this.a=this.b=null,this.node=null}alloc(){}};Ti.zpp_pool=null;var St=Ti;var Vt=class Vt{constructor(){this.zip_dir=!1;this.absnormaly=0;this.absnormalx=0;this.normaly=0;this.normalx=0;this.idiry=0;this.idirx=0;this.diry=0;this.dirx=0;this.originy=0;this.originx=0;this.userData=null;this.maxdist=0;this.direction=null;this.origin=null;let e=_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=!1,t==xe.nextVec2&&(xe.nextVec2=null)),t.zpp_inner==null){let s;pe.zpp_pool==null?s=new pe:(s=pe.zpp_pool,pe.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,t.zpp_inner=s,t.zpp_inner.outer=t}else{if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=t.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=t.zpp_inner;if(l._validate!=null&&l._validate(),t.zpp_inner.x==0){if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=t.zpp_inner;o._validate!=null&&o._validate(),i=t.zpp_inner.y==0}else i=!1;if(!i){t.zpp_inner.x=0,t.zpp_inner.y=0;let o=t.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}t.zpp_inner.weak=!1,this.origin=t,this.origin.zpp_inner._invalidate=s=>this.origin_invalidate(s);let n;if(xe.poolVec2==null?n=new e.geom.Vec2:(n=xe.poolVec2,xe.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==xe.nextVec2&&(xe.nextVec2=null)),n.zpp_inner==null){let s;pe.zpp_pool==null?s=new pe:(s=pe.zpp_pool,pe.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=0,s.y=0,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");s._isimmutable!=null&&s._isimmutable();let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==0){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y==0}else i=!1;if(!i){n.zpp_inner.x=0,n.zpp_inner.y=0;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.direction=n,this.direction.zpp_inner._invalidate=s=>this.direction_invalidate(s),this.originx=0,this.originy=0,this.dirx=0,this.diry=0,this.zip_dir=!1}origin_invalidate(e){this.originx=e.x,this.originy=e.y}direction_invalidate(e){this.dirx=e.x,this.diry=e.y,this.zip_dir=!0}invalidate_dir(){this.zip_dir=!0}validate_dir(){if(this.zip_dir){this.zip_dir=!1;let e=_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 fe.zpp_pool==null?i=new fe:(i=fe.zpp_pool,fe.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=n,i.maxx=t,i.maxy=s,i}aabbtest(e){let t=this.normalx*(this.originx-.5*(e.minx+e.maxx))+this.normaly*(this.originy-.5*(e.miny+e.maxy)),n=this.absnormalx*.5*(e.maxx-e.minx)+this.absnormaly*.5*(e.maxy-e.miny),s=t;return(s<0?-s:s)<n}aabbsect(e){let t=this.originx>=e.minx&&this.originx<=e.maxx,n=this.originy>=e.miny&&this.originy<=e.maxy;if(t&&n)return 0;{let s=-1;for(;!(this.dirx>=0&&this.originx>=e.maxx)&&!(this.dirx<=0&&this.originx<=e.minx||this.diry>=0&&this.originy>=e.maxy||this.diry<=0&&this.originy<=e.miny);){if(this.dirx>0){let i=(e.minx-this.originx)*this.idirx;if(i>=0&&i<=this.maxdist){let l=this.originy+i*this.diry;if(l>=e.miny&&l<=e.maxy){s=i;break}}}else if(this.dirx<0){let i=(e.maxx-this.originx)*this.idirx;if(i>=0&&i<=this.maxdist){let l=this.originy+i*this.diry;if(l>=e.miny&&l<=e.maxy){s=i;break}}}if(this.diry>0){let i=(e.miny-this.originy)*this.idiry;if(i>=0&&i<=this.maxdist){let l=this.originx+i*this.dirx;if(l>=e.minx&&l<=e.maxx){s=i;break}}}else if(this.diry<0){let i=(e.maxy-this.originy)*this.idiry;if(i>=0&&i<=this.maxdist){let l=this.originx+i*this.dirx;if(l>=e.minx&&l<=e.maxx){s=i;break}}}break}return s}}static _allocVec2(e,t){let n=_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=!1,s==xe.nextVec2&&(xe.nextVec2=null)),s.zpp_inner==null){let i;pe.zpp_pool==null?i=new pe:(i=pe.zpp_pool,pe.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=e,i.y=t,s.zpp_inner=i,s.zpp_inner.outer=s}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;s.zpp_inner._validate!=null&&s.zpp_inner._validate(),s.zpp_inner.x==e?(s.zpp_inner._validate!=null&&s.zpp_inner._validate(),l=s.zpp_inner.y==t):l=!1,l||(s.zpp_inner.x=e,s.zpp_inner.y=t,s.zpp_inner._invalidate!=null&&s.zpp_inner._invalidate(s.zpp_inner))}return s.zpp_inner.weak=!1,s}static _validateWorldCOM(e){if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let s=1;n.localCOMx+=n.lverts.next.next.x*s,n.localCOMy+=n.lverts.next.next.y*s;let i=.5;n.localCOMx*=i,n.localCOMy*=i}else{n.localCOMx=0,n.localCOMy=0;let s=0,i=n.lverts.next,l=i;i=i.next;let o=i;for(i=i.next;i!=null;){let u=i;s+=o.x*(u.y-l.y);let x=u.y*o.x-u.x*o.y;n.localCOMx+=(o.x+u.x)*x,n.localCOMy+=(o.y+u.y)*x,l=o,o=u,i=i.next}i=n.lverts.next;let r=i;s+=o.x*(r.y-l.y);let a=r.y*o.x-r.x*o.y;n.localCOMx+=(o.x+r.x)*a,n.localCOMy+=(o.y+r.y)*a,l=o,o=r,i=i.next;let p=i;s+=o.x*(p.y-l.y);let c=p.y*o.x-p.x*o.y;n.localCOMx+=(o.x+p.x)*c,n.localCOMy+=(o.y+p.y)*c,s=1/(3*s);let h=s;n.localCOMx*=h,n.localCOMy*=h}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}_circleNormal(e,t,n){let s=this.originx+this.dirx*e,i=this.originy+this.diry*e;s-=t.worldCOMx,i-=t.worldCOMy;let l=s*s+i*i,o=1/Math.sqrt(l);return s*=o,i*=o,n&&(s=-s,i=-i),{nx:s,ny:i}}static _insertSorted(e,t){let n=null,s=e.zpp_inner.inner.head;for(;s!=null;){let o=s.elt;if(t.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(t.zpp_inner.toiDistance<o.zpp_inner.toiDistance)break;n=s,s=s.next}let i=e.zpp_inner.inner,l;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=!0,i.length++}circlesect(e,t,n){Vt._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,o=2*(s*this.dirx+i*this.diry),r=s*s+i*i-e.radius*e.radius,a=o*o-4*l*r;if(a==0){let p=-o/2*l;if((!t||r>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),h=Vt._allocVec2(c.nx,c.ny);return mn.getRay(h,p,r<=0,e.outer)}else return null}else{a=Math.sqrt(a),l=1/(2*l);let p=(-o-a)*l,c=(-o+a)*l;if(p>0)if(p<n&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=Vt._allocVec2(h.nx,h.ny);return mn.getRay(u,p,!1,e.outer)}else return null;else if(c>0&&t)if(c<n&&c<=this.maxdist){let h=this._circleNormal(c,e,!0),u=Vt._allocVec2(h.nx,h.ny);return mn.getRay(u,c,!0,e.outer)}else return null;else return null}}circlesect2(e,t,n){Vt._validateWorldCOM(e);let s=this.originx-e.worldCOMx,i=this.originy-e.worldCOMy,l=this.dirx*this.dirx+this.diry*this.diry,o=2*(s*this.dirx+i*this.diry),r=s*s+i*i-e.radius*e.radius,a=o*o-4*l*r;if(a==0){let p=-o/2*l;if((!t||r>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,r<=0),h=Vt._allocVec2(c.nx,c.ny),u=mn.getRay(h,p,r<=0,e.outer);Vt._insertSorted(n,u)}}else{a=Math.sqrt(a),l=1/(2*l);let p=(-o-a)*l,c=(-o+a)*l;if(p>0&&p<=this.maxdist){let h=this._circleNormal(p,e,!1),u=Vt._allocVec2(h.nx,h.ny),x=mn.getRay(u,p,!1,e.outer);Vt._insertSorted(n,x)}if(c>0&&c<=this.maxdist&&t){let h=this._circleNormal(c,e,!0),u=Vt._allocVec2(h.nx,h.ny),x=mn.getRay(u,c,!0,e.outer);Vt._insertSorted(n,x)}}}polysect(e,t,n){let s=_e(),i=n,l=null,o=e.edges.head,r=!0,a=e.gverts.next,p=a,c=a.next;for(;c!=null;){let h=c,u=o.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,m=h.y-p.y,_=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 f=(m*_-x*y)*z;if(f>0&&f<i&&f<=this.maxdist){let w=(this.diry*_-this.dirx*y)*z;w>-s.Config.epsilon&&w<1+s.Config.epsilon&&(i=f,l=o.elt)}}}o=o.next,p=h,c=c.next}if(r){c=e.gverts.next;let h=c,u=o.elt;if(t||u.gnormx*this.dirx+u.gnormy*this.diry<0){let x=h.x-p.x,m=h.y-p.y,_=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 f=(m*_-x*y)*z;if(f>0&&f<i&&f<=this.maxdist){let w=(this.diry*_-this.dirx*y)*z;w>-s.Config.epsilon&&w<1+s.Config.epsilon&&(i=f,l=o.elt)}}}}if(l!=null){let h=l.gnormx,u=l.gnormy,x=h*this.dirx+u*this.diry>0;x&&(h=-h,u=-u);let m=Vt._allocVec2(h,u);return mn.getRay(m,i,x,e.outer)}else return null}polysect2(e,t,n){let s=_e(),i=1/0,l=-1,o=null,r=null,a=e.edges.head,p=!0,c=e.gverts.next,h=c,u=c.next;for(;u!=null;){let x=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let _=x.x-h.x,y=x.y-h.y,z=h.x-this.originx,f=h.y-this.originy,w=y*this.dirx-_*this.diry;if(w*w>s.Config.epsilon){w=1/w;let Z=(y*z-_*f)*w;if(Z>0&&Z<=this.maxdist&&(Z<i||Z>l)){let d=(this.diry*z-this.dirx*f)*w;d>-s.Config.epsilon&&d<1+s.Config.epsilon&&(Z<i&&(i=Z,o=a.elt),Z>l&&(l=Z,r=a.elt))}}}a=a.next,h=x,u=u.next}if(p){u=e.gverts.next;let x=u,m=a.elt;if(t||m.gnormx*this.dirx+m.gnormy*this.diry<0){let _=x.x-h.x,y=x.y-h.y,z=h.x-this.originx,f=h.y-this.originy,w=y*this.dirx-_*this.diry;if(w*w>s.Config.epsilon){w=1/w;let Z=(y*z-_*f)*w;if(Z>0&&Z<=this.maxdist&&(Z<i||Z>l)){let d=(this.diry*z-this.dirx*f)*w;d>-s.Config.epsilon&&d<1+s.Config.epsilon&&(Z<i&&(i=Z,o=a.elt),Z>l&&(l=Z,r=a.elt))}}}}if(o!=null){let x=o.gnormx,m=o.gnormy,_=x*this.dirx+m*this.diry>0;_&&(x=-x,m=-m);let y=Vt._allocVec2(x,m),z=mn.getRay(y,i,_,e.outer);Vt._insertSorted(n,z)}if(r!=null&&o!=r){let x=r.gnormx,m=r.gnormy,_=x*this.dirx+m*this.diry>0;_&&(x=-x,m=-m);let y=Vt._allocVec2(x,m),z=mn.getRay(y,l,_,e.outer);Vt._insertSorted(n,z)}}};Vt.internal=!1;var Hs=Vt;var Pi=class Pi{constructor(){this.forced=!1;this.x=0;this.y=0;this.links=null;this.id=0;this.next=null;this.node=null;this.id=dn.ZPP_SimpleVert(),$t.zpp_pool==null?this.links=new $t:(this.links=$t.zpp_pool,$t.zpp_pool=this.links.next,this.links.next=null),this.links.lt=Pi.less_xy}static less_xy(e,t){return e.y<t.y?!0:e.y==t.y?e.x<t.x:!1}static swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}static get(e,t){let n;return Pi.zpp_pool==null?n=new Pi:(n=Pi.zpp_pool,Pi.zpp_pool=n.next,n.next=null),n.x=e,n.y=t,n}free(){this.links.clear(),this.node=null,this.forced=!1}alloc(){}};Pi.zpp_pool=null;var ke=Pi;var Li=class Li{constructor(){this.left=null;this.right=null;this.vertices=null;this.id=0;this.next=null;this.prev=null;this.node=null;this.id=dn.ZPP_SimpleSeg(),$t.zpp_pool==null?this.vertices=new $t:(this.vertices=$t.zpp_pool,$t.zpp_pool=this.vertices.next,this.vertices.next=null),this.vertices.lt=(e,t)=>this.less_xy(e,t)}static get(e,t){let n;return Li.zpp_pool==null?n=new Li:(n=Li.zpp_pool,Li.zpp_pool=n.next,n.next=null),n.left=e,n.right=t,n.vertices.insert(e),n.vertices.insert(t),n}free(){this.left=this.right=null,this.prev=null,this.node=null,this.vertices.clear()}alloc(){}less_xy(e,t){return e.x<t.x?!0:e.x==t.x?e.y<t.y:!1}};Li.zpp_pool=null;var At=Li;var Di=class Di{constructor(){this.type=0;this.vertex=null;this.segment=null;this.segment2=null;this.node=null;this.next=null}static swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}static less_xy(e,t){return e.vertex.x<t.vertex.x?!0:e.vertex.x>t.vertex.x?!1:e.vertex.y<t.vertex.y?!0:e.vertex.y>t.vertex.y?!1:e.type<t.type}static get(e){let t;return Di.zpp_pool==null?t=new Di:(t=Di.zpp_pool,Di.zpp_pool=t.next,t.next=null),t.vertex=e,t}free(){this.vertex=null,this.segment=this.segment2=null,this.node=null}alloc(){}};Di.zpp_pool=null;var Ce=Di;var Fi=class{constructor(){this.sweepx=0;this.tree=null;Qi.zpp_pool==null?this.tree=new Qi:(this.tree=Qi.zpp_pool,Qi.zpp_pool=this.tree.next,this.tree.next=null),this.tree.lt=(e,t)=>this.edge_lt(e,t),this.tree.swapped=(e,t)=>this.swap_nodes(e,t)}swap_nodes(e,t){let n=e.node;e.node=t.node,t.node=n}edge_lt(e,t){let n=e.left,s=e.right,i=t.left,l=t.right,o,r,a,p,c;if(e.left==t.left&&e.right==t.right)return!1;if(e.left==t.right)return n.x==s.x?n.y<s.y?n.y>i.y:s.y>i.y:(c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?r*a-o*p:p*o-a*r)<0);if(e.right==t.left){let h;return i.x==l.x?h=i.y<l.y?i.y>n.y:l.y>n.y:(c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=n.x-i.x,p=n.y-i.y,h=(c?r*a-o*p:p*o-a*r)<0),!h}else{if(e.left==t.left)return n.x==s.x?n.y<s.y?n.y>l.y:s.y>l.y:(c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=l.x-n.x,p=l.y-n.y,(c?r*a-o*p:p*o-a*r)<0);if(e.right==t.right)return n.x==s.x?n.y<s.y?n.y>i.y:s.y>i.y:(c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=i.x-n.x,p=i.y-n.y,(c?r*a-o*p:p*o-a*r)<0)}if(n.x==s.x)if(i.x==l.x){let h=n.y<s.y?s:n,u=i.y<l.y?l:i;return h.y>u.y}else{c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let h=c?r*a-o*p:p*o-a*r;c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let u=c?r*a-o*p:p*o-a*r;return h*u>=0?h>=0:this.sweepx>=n.x}else if(i.x==l.x){c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=c?r*a-o*p:p*o-a*r;c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=c?r*a-o*p:p*o-a*r;return h*u>=0?h<0:this.sweepx<i.x}else{c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=i.x-n.x,p=i.y-n.y;let h=(c?r*a-o*p:p*o-a*r)<0;c=s.x<n.x,o=s.x-n.x,r=s.y-n.y,a=l.x-n.x,p=l.y-n.y;let u=(c?r*a-o*p:p*o-a*r)<0;if(h==u)return h;{c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=n.x-i.x,p=n.y-i.y;let x=(c?r*a-o*p:p*o-a*r)>=0;c=l.x<i.x,o=l.x-i.x,r=l.y-i.y,a=s.x-i.x,p=s.y-i.y;let m=(c?r*a-o*p:p*o-a*r)>=0;if(x==m)return x;let _=(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!1;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return!1;{let n=e.left,s=e.right,i=t.left,l=t.right,o=(i.x-n.x)*(s.y-n.y)-(s.x-n.x)*(i.y-n.y),r=(l.x-n.x)*(s.y-n.y)-(s.x-n.x)*(l.y-n.y);if(o*r>0)return!1;{let a=(n.x-i.x)*(l.y-i.y)-(l.x-i.x)*(n.y-i.y),p=(s.x-i.x)*(l.y-i.y)-(l.x-i.x)*(s.y-i.y);return!(a*p>0)}}}intersection(e,t){if(e==null||t==null)return null;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return null;{let n=e.left,s=e.right,i=t.left,l=t.right,o=s.x-n.x,r=s.y-n.y,a=l.x-i.x,p=l.y-i.y,c=p*o-a*r;if(c==0)return null;c=1/c;let h=i.x-n.x,u=i.y-n.y,x=(p*h-a*u)*c;if(x<0||x>1)return null;let m=(r*h-o*u)*c;if(m<0||m>1)return null;let _;if(m==0||m==1||x==0||x==1){let f=m==0;if(m==1&&f)throw new Error("corner case 1a");if(m==1&&(f=!0),x==0&&f)throw new Error("corner case 1b");if(x==0&&(f=!0),x==1&&f)throw new Error("corner case 1c");_=m==0?i:m==1?l:x==0?n:s}else{let f=.5*(n.x+o*x+i.x+a*m),w=.5*(n.y+r*x+i.y+p*m),Z;ke.zpp_pool==null?Z=new ke:(Z=ke.zpp_pool,ke.zpp_pool=Z.next,Z.next=null),Z.x=f,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 Fi,ye.inthash=new Oi),ye.vertices==null&&($t.zpp_pool==null?ye.vertices=new $t:(ye.vertices=$t.zpp_pool,$t.zpp_pool=ye.vertices.next,ye.vertices.next=null),ye.vertices.lt=ke.less_xy,ye.vertices.swapped=ke.swap_nodes),ye.queue==null&&(Un.zpp_pool==null?ye.queue=new Un:(ye.queue=Un.zpp_pool,Un.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;ke.zpp_pool==null?z=new ke:(z=ke.zpp_pool,ke.zpp_pool=z.next,z.next=null),z.x=_,z.y=y;let f=z,w=ye.vertices.parent;for(;w!=null;)if(ye.vertices.lt(f,w.data))w=w.prev;else if(ye.vertices.lt(w.data,f))w=w.next;else break;let Z=w;if(Z!=null){let d=f;d.links.clear(),d.node=null,d.forced=!1,d.next=ke.zpp_pool,ke.zpp_pool=d,f=Z.data}else f.node=ye.vertices.insert(f);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 b=d,g;Ce.zpp_pool==null?g=new Ce:(g=Ce.zpp_pool,Ce.zpp_pool=g.next,g.next=null),g.vertex=f;let P=g,v;Ce.less_xy(b,P)?(b.type=1,P.type=2,v=At.get(s,f)):(b.type=2,P.type=1,v=At.get(f,s)),b.segment=P.segment=v,ye.queue.insert(b),ye.queue.insert(P),s.links.insert(f),f.links.insert(s)}if(s=f,n==null&&(n=f),x=x.next,x==l)break}}let o;Ce.zpp_pool==null?o=new Ce:(o=Ce.zpp_pool,Ce.zpp_pool=o.next,o.next=null),o.vertex=s;let r=o,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(r,p)?(r.type=1,p.type=2,c=At.get(s,n)):(r.type=2,p.type=1,c=At.get(n,s)),r.segment=p.segment=c,ye.queue.insert(r),ye.queue.insert(p),s.links.insert(n),n.links.insert(s),ye.ints==null&&(Un.zpp_pool==null?ye.ints=new Un:(ye.ints=Un.zpp_pool,Un.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 f=z;if(f==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=!1,d.next=ke.zpp_pool,ke.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,b=_.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=b,P.di=g;let v=P;v.value=!0,d.add(v)}else{let d=ye.inthash,b=_.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=b,P.di=g;let v=P;v.value=!0,d.add(v)}}else{let w=f.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=!1,Z.next=ke.zpp_pool,ke.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=!1,z.next=ke.zpp_pool,ke.zpp_pool=z;let f=y;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Ce.zpp_pool,Ce.zpp_pool=f}}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 f=z;if(f==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=!1,d.next=ke.zpp_pool,ke.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,b=_.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=b,P.di=g;let v=P;v.value=!0,d.add(v)}else{let d=ye.inthash,b=_.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=b,P.di=g;let v=P;v.value=!0,d.add(v)}}else{let w=f.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=!1,Z.next=ke.zpp_pool,ke.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=!1,z.next=ke.zpp_pool,ke.zpp_pool=z;let f=y;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Ce.zpp_pool,Ce.zpp_pool=f}}}else if(x.type==2){let _=x.segment;if(_.node!=null){let y=_.next,z=_.prev;ye.sweep.remove(_);let f=_;if(f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=At.zpp_pool,At.zpp_pool=f,y!=null&&z!=null&&!(y.id<z.id?ye.inthash.has(y.id,z.id):ye.inthash.has(z.id,y.id))){let 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 b=ye.ints.parent;for(;b!=null;)if(ye.ints.lt(w,b.data))b=b.prev;else if(ye.ints.lt(b.data,w))b=b.next;else break;let g=b;if(g!=null){let P=w.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.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,k;Be.zpp_pool==null?k=new Be:(k=Be.zpp_pool,Be.zpp_pool=k.next,k.next=null),k.id=v,k.di=N;let C=k;C.value=!0,P.add(C)}else{let P=ye.inthash,v=z.id,N=y.id,k;Be.zpp_pool==null?k=new Be:(k=Be.zpp_pool,Be.zpp_pool=k.next,k.next=null),k.id=v,k.di=N;let C=k;C.value=!0,P.add(C)}}else{let b=d.data;if(b.segment!=w.segment||w.segment2!=b.segment2)throw new Error("corner case 2, shiiiit.");let g=w.vertex;g.links.clear(),g.node=null,g.forced=!1,g.next=ke.zpp_pool,ke.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=!1,Z.next=ke.zpp_pool,ke.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,f=x.segment2;if(f.next!=z){let g=z;z=f,f=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=f.vertices.parent;for(;d!=null;)if(f.vertices.lt(_,d.data))d=d.prev;else if(f.vertices.lt(d.data,_))d=d.next;else break;let b=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(b){let g=f.vertices.insert(_),P=_==f.left?_:f.vertices.predecessor_node(g).data,v=_==f.right?_:f.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=!0,y){let g=z.node,P=f.node;g.data=f,P.data=z,z.node=P,f.node=g,f.next=z.next,z.next=f,z.prev=f.prev,f.prev=z,z.prev!=null&&(z.prev.next=z),f.next!=null&&(f.next.prev=f)}if(f.next!=null&&f!=null&&!(f.next.id<f.id?ye.inthash.has(f.next.id,f.id):ye.inthash.has(f.id,f.next.id))){let g=ye.sweep.intersection(f.next,f);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 k=N;if(k!=null){let C=g.vertex;C.links.clear(),C.node=null,C.forced=!1,C.next=ke.zpp_pool,ke.zpp_pool=C,g.vertex=k.data.vertex,k.data=g,ye.queue.insert(g)}else ye.queue.insert(g),ye.ints.insert(g);if(f.next.id<f.id){let C=ye.inthash,E=f.next.id,M=f.id,S;Be.zpp_pool==null?S=new Be:(S=Be.zpp_pool,Be.zpp_pool=S.next,S.next=null),S.id=E,S.di=M;let O=S;O.value=!0,C.add(O)}else{let C=ye.inthash,E=f.id,M=f.next.id,S;Be.zpp_pool==null?S=new Be:(S=Be.zpp_pool,Be.zpp_pool=S.next,S.next=null),S.id=E,S.di=M;let O=S;O.value=!0,C.add(O)}}else{let N=v.data;if(N.segment!=g.segment||g.segment2!=N.segment2)throw new Error("corner case 2, shiiiit.");let k=g.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=ke.zpp_pool,ke.zpp_pool=k;let C=g;C.vertex=null,C.segment=C.segment2=null,C.node=null,C.next=Ce.zpp_pool,Ce.zpp_pool=C}}else{let P=g.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.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 k=N;if(k!=null){let C=g.vertex;C.links.clear(),C.node=null,C.forced=!1,C.next=ke.zpp_pool,ke.zpp_pool=C,g.vertex=k.data.vertex,k.data=g,ye.queue.insert(g)}else ye.queue.insert(g),ye.ints.insert(g);if(z.id<z.prev.id){let C=ye.inthash,E=z.id,M=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=E,S.di=M;let O=S;O.value=!0,C.add(O)}else{let C=ye.inthash,E=z.prev.id,M=z.id,S;Be.zpp_pool==null?S=new Be:(S=Be.zpp_pool,Be.zpp_pool=S.next,S.next=null),S.id=E,S.di=M;let O=S;O.value=!0,C.add(O)}}else{let N=v.data;if(N.segment!=g.segment||g.segment2!=N.segment2)throw new Error("corner case 2, shiiiit.");let k=g.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=ke.zpp_pool,ke.zpp_pool=k;let C=g;C.vertex=null,C.segment=C.segment2=null,C.node=null,C.next=Ce.zpp_pool,Ce.zpp_pool=C}}else{let P=g.vertex;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.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 Fn);!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,o=l.prev==null?l.next:l.prev,r=l.data,a=o.data,p=s.x-r.x,c=s.y-r.y,h=a.x-s.x;(a.y-s.y)*p-h*c<0&&(a=r);let x=s.x,m=s.y,_;ve.zpp_pool==null?_=new ve:(_=ve.zpp_pool,ve.zpp_pool=_.next,_.next=null),_.forced=!1,_.x=x,_.y=m;let y=_;if(n==null)y.prev=y.next=y;else{let f=n,w=f.next;y.prev=f,y.next=w,w.prev=y,f.next=y}for(n=y,n.forced=s.forced;;){if(s.links.remove(a),a.links.remove(s),a==i){if(s.links.empty()){e.remove(s);let b=s;b.links.clear(),b.node=null,b.forced=!1,b.next=ke.zpp_pool,ke.zpp_pool=b}break}let f=a.x,w=a.y,Z;ve.zpp_pool==null?Z=new ve:(Z=ve.zpp_pool,ve.zpp_pool=Z.next,Z.next=null),Z.forced=!1,Z.x=f,Z.y=w;let d=Z;if(n==null)d.prev=d.next=d;else{let b=n,g=b.next;d.prev=b,d.next=g,g.prev=d,b.next=d}if(n=d,n.forced=a.forced,a.links.singular()){if(s.links.empty()){e.remove(s);let b=s;b.links.clear(),b.node=null,b.forced=!1,b.next=ke.zpp_pool,ke.zpp_pool=b}s=a,a=a.links.parent.data}else{let b=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(b==null){b=v;let N=a.x-s.x,k=a.y-s.y,C=v.x-a.x;g=(v.y-a.y)*N-C*k}else{let N=a.x-s.x,k=a.y-s.y,C=v.x-a.x,M=(v.y-a.y)*N-C*k;if(M>0&&g<=0)b=v,g=M;else if(g*M>=0){let S=a.x-v.x,O=a.y-v.y,L=b.x-a.x;(b.y-a.y)*S-L*O>0&&(b=v,g=M)}}if(P.next!=null)for(P=P.next;P.prev!=null;)P=P.prev;else{for(;P.parent!=null&&P==P.parent.next;)P=P.parent;P=P.parent}}}if(s.links.empty()){e.remove(s);let P=s;P.links.clear(),P.node=null,P.forced=!1,P.next=ke.zpp_pool,ke.zpp_pool=P}s=a,a=b}}e.remove(i);let z=i;z.links.clear(),z.node=null,z.forced=!1,z.next=ke.zpp_pool,ke.zpp_pool=z,t.add(n)}static isSimple(e){ye.sweep==null&&(ye.sweep=new Fi,ye.inthash=new Oi);let t=ye.list_vertices;t==null&&(t=ye.list_vertices=new xl);let n=e,s=e;if(n!=null){let _=n;for(;;){let y=_,z=y.x,f=y.y,w;if(ke.zpp_pool==null?w=new ke:(w=ke.zpp_pool,ke.zpp_pool=w.next,w.next=null),w.x=z,w.y=f,t.add(w),_=_.next,_==s)break}}let i=ye.list_queue;i==null&&(i=ye.list_queue=new _l);let l=t.head,o=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=o;let z=i.add(y),f;Ce.zpp_pool==null?f=new Ce:(f=Ce.zpp_pool,Ce.zpp_pool=f.next,f.next=null),f.vertex=_;let w=i.add(f),Z;Ce.less_xy(z,w)?(z.type=1,w.type=2,Z=At.get(o,_)):(z.type=2,w.type=1,Z=At.get(_,o)),z.segment=w.segment=Z,o=_,l=l.next}let r=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=o;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=r;let h=i.add(c),u;Ce.less_xy(p,h)?(p.type=1,h.type=2,u=At.get(o,r)):(p.type=2,h.type=1,u=At.get(r,o)),p.segment=h.segment=u;let x=i;if(x.head!=null&&x.head.next!=null){let _=x.head,y,z,f,w,Z=1,d,b,g;for(;;){for(d=0,z=_,_=null,y=null;z!=null;){for(++d,f=z,b=0,g=Z;f!=null&&b<Z;)++b,f=f.next;for(;b>0||g>0&&f!=null;)b==0?(w=f,f=f.next,--g):g==0||f==null||Ce.less_xy(z.elt,f.elt)?(w=z,z=z.next,--b):(w=f,f=f.next,--g),y!=null?y.next=w:_=w,y=w;z=f}if(y.next=null,Z<<=1,!(d>1))break}x.head=_,x.modified=!0,x.pushmod=!0}let m=!0;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=!1;break}}else if(_.type==2){if(ye.sweep.intersect(y.prev,y.next)){m=!1;break}ye.sweep.remove(y);let f=y;f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=At.zpp_pool,At.zpp_pool=f}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=At.zpp_pool,At.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=!1,_.next=ke.zpp_pool,ke.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 wi=ye;var Gi=class Gi{constructor(){this.x=0;this.y=0;this.next=null;this.prev=null;this.flag=!1;this.forced=!1}static get(e){let t;return Gi.zpp_pool==null?t=new Gi:(t=Gi.zpp_pool,Gi.zpp_pool=t.next,t.next=null),t.x=e.x,t.y=e.y,t.flag=!1,t}free(){}alloc(){}};Gi.zpp_pool=null;var vn=Gi;var Ri=class Ri{constructor(){this.next=null;this.min=null;this.max=null}static get(e,t){let n;return Ri.zpp_pool==null?n=new Ri:(n=Ri.zpp_pool,Ri.zpp_pool=n.next,n.next=null),n.min=e,n.max=t,n}free(){this.min=null,this.max=null}alloc(){}};Ri.zpp_pool=null;var Te=Ri;var It=class It{static lessval(e,t){return e.x-t.x+(e.y-t.y)}static less(e,t){return e.x-t.x+(e.y-t.y)<0}static distance(e,t,n){let s=n.x-t.x,i=n.y-t.y,l=e.x-t.x,o=e.y-t.y;if(s*s+i*i==0)return l*l+o*o;{let a=(l*s+o*i)/(s*s+i*i);if(a<=0)return l*l+o*o;if(a>=1){let p=e.x-n.x,c=e.y-n.y;return p*p+c*c}else{let p=a;return l-=s*p,o-=i*p,l*l+o*o}}}static simplify(e,t){let n=null,s=null,i=null;t*=t,It.stack==null&&(It.stack=new ul);let l=null,o=null,r=e;for(;;){let p;vn.zpp_pool==null?p=new vn:(p=vn.zpp_pool,vn.zpp_pool=p.next,p.next=null),p.x=r.x,p.y=r.y,p.flag=!1;let c=p;if(c.forced=r.forced,c.forced){if(c.flag=!0,l!=null){let u=It.stack,x;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 o=c;l=c}let h=c;if(n==null?h.prev=h.next=h:(h.prev=n,h.next=n.next,n.next.prev=h,n.next=h),n=h,s==null?(s=n,i=n):(n.x-s.x+(n.y-s.y)<0&&(s=n),i.x-n.x+(i.y-n.y)<0&&(i=n)),r=r.next,r==e)break}if(It.stack.head==null)if(o==null){s.flag=i.flag=!0;let p=It.stack,c;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-o.x+(s.y-o.y);p<0&&(p=-p);let c=i.x-o.x+(i.y-o.y);if(c<0&&(c=-c),p>c){s.flag=o.flag=!0;let h=It.stack,u;Te.zpp_pool==null?u=new Te:(u=Te.zpp_pool,Te.zpp_pool=u.next,u.next=null),u.min=s,u.max=o,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=o,m.max=s,x.add(m)}else{i.flag=o.flag=!0;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=o,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=o,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=o,p.add(c)}for(;It.stack.head!=null;){let p=It.stack.pop_unsafe(),c=p.min,h=p.max,u=p;u.min=u.max=null,u.next=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=!0;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 f=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,f.add(w)}}let a=null;for(;n!=null;){if(n.flag){let p=n.x,c=n.y,h;ve.zpp_pool==null?h=new ve:(h=ve.zpp_pool,ve.zpp_pool=h.next,h.next=null),h.forced=!1,h.x=p,h.y=c;let u=h;a==null?u.prev=u.next=u:(u.prev=a,u.next=a.next,a.next.prev=u,a.next=u),a=u,a.forced=n.forced}if(n!=null&&n.prev==n)n.next=n.prev=null,n.next=vn.zpp_pool,vn.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=vn.zpp_pool,vn.zpp_pool=n,n=p}}return a}};It.stack=null;var rs=It;var Ns=class{constructor(){this.next=null;this.toi=0;this.s1=null;this.s2=null;this.arbiter=null;this.frozen1=!1;this.frozen2=!1;this.slipped=!1;this.failed=!1;this.kinematic=!1;this.c1=pe.get(0,0),this.c2=pe.get(0,0),this.axis=pe.get(0,0)}alloc(){this.failed=!1,this.s1=this.s2=null,this.arbiter=null}free(){}};Ns.zpp_pool=null;function pt(j){return j.type===0||j.type===2}function Ft(j){return j.type===0?j.circle.radius:j.capsule.halfLength+j.capsule.radius}var gn=class{static dynamicSweep(e,t,n,s,i){let l=_e();i==null&&(i=!1);let o=e.s1,r=e.s2,a=o.body,p=r.body,c=0,h=0;c=p.velx-a.velx,h=p.vely-a.vely;let u=a.angvel;u<0&&(u=-u);let x=p.angvel;x<0&&(x=-x);let m=o.sweepCoef*u+r.sweepCoef*x;if(!i&&!e.kinematic&&c*c+h*h<l.Config.dynamicSweepLinearThreshold*l.Config.dynamicSweepLinearThreshold&&m<l.Config.dynamicSweepAngularThreshold){e.toi=-1,e.failed=!0;return}let _=e.c1,y=e.c2,z=e.axis,f=n,w=0;for(;;){let M=f*t,S=M-a.sweepTime;if(S!=0){a.sweepTime=M;let X=S;if(a.posx+=a.velx*X,a.posy+=a.vely*X,a.angvel!=0){let H=a.sweep_angvel*S;if(a.rot+=H,H*H>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let ee=H*H,W=1-.5*ee,F=1-ee*ee/8,D=(W*a.axisx+H*a.axisy)*F;a.axisy=(W*a.axisy-H*a.axisx)*F,a.axisx=D}}}if(o.type==0||o.type===2)o.worldCOMx=a.posx+(a.axisy*o.localCOMx-a.axisx*o.localCOMy),o.worldCOMy=a.posy+(o.localCOMx*a.axisx+o.localCOMy*a.axisy);else{let X=o.polygon,H=X.lverts.next,ee=X.gverts.next;for(;ee!=null;){let Q=ee,K=H;H=H.next,Q.x=a.posx+(a.axisy*K.x-a.axisx*K.y),Q.y=a.posy+(K.x*a.axisx+K.y*a.axisy),ee=ee.next}let W=X.edges.head,F=X.gverts.next,D=F;for(F=F.next;F!=null;){let Q=F,K=W.elt;W=W.next,K.gnormx=a.axisy*K.lnormx-a.axisx*K.lnormy,K.gnormy=K.lnormx*a.axisx+K.lnormy*a.axisy,K.gprojection=a.posx*K.gnormx+a.posy*K.gnormy+K.lprojection,K.tp0=D.y*K.gnormx-D.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,D=Q,F=F.next}let A=X.gverts.next,J=W.elt;W=W.next,J.gnormx=a.axisy*J.lnormx-a.axisx*J.lnormy,J.gnormy=J.lnormx*a.axisx+J.lnormy*a.axisy,J.gprojection=a.posx*J.gnormx+a.posy*J.gnormy+J.lprojection,J.tp0=D.y*J.gnormx-D.x*J.gnormy,J.tp1=A.y*J.gnormx-A.x*J.gnormy}let O=f*t,L=O-p.sweepTime;if(L!=0){p.sweepTime=O;let X=L;if(p.posx+=p.velx*X,p.posy+=p.vely*X,p.angvel!=0){let H=p.sweep_angvel*L;if(p.rot+=H,H*H>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let ee=H*H,W=1-.5*ee,F=1-ee*ee/8,D=(W*p.axisx+H*p.axisy)*F;p.axisy=(W*p.axisy-H*p.axisx)*F,p.axisx=D}}}if(r.type==0||r.type===2)r.worldCOMx=p.posx+(p.axisy*r.localCOMx-p.axisx*r.localCOMy),r.worldCOMy=p.posy+(r.localCOMx*p.axisx+r.localCOMy*p.axisy);else{let X=r.polygon,H=X.lverts.next,ee=X.gverts.next;for(;ee!=null;){let Q=ee,K=H;H=H.next,Q.x=p.posx+(p.axisy*K.x-p.axisx*K.y),Q.y=p.posy+(K.x*p.axisx+K.y*p.axisy),ee=ee.next}let W=X.edges.head,F=X.gverts.next,D=F;for(F=F.next;F!=null;){let Q=F,K=W.elt;W=W.next,K.gnormx=p.axisy*K.lnormx-p.axisx*K.lnormy,K.gnormy=K.lnormx*p.axisx+K.lnormy*p.axisy,K.gprojection=p.posx*K.gnormx+p.posy*K.gnormy+K.lprojection,K.tp0=D.y*K.gnormx-D.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,D=Q,F=F.next}let A=X.gverts.next,J=W.elt;W=W.next,J.gnormx=p.axisy*J.lnormx-p.axisx*J.lnormy,J.gnormy=J.lnormx*p.axisx+J.lnormy*p.axisy,J.gprojection=p.posx*J.gnormx+p.posy*J.gnormy+J.lprojection,J.tp0=D.y*J.gnormx-D.x*J.gnormy,J.tp1=A.y*J.gnormx-A.x*J.gnormy}let T=o,R=r,q=_,G=y;var Z;if(pt(T)&&pt(R)){let X=T.circle||T.capsule,H=R.circle||R.capsule,ee=Ft(T),W=Ft(R);var d;let F=0,D=0;F=H.worldCOMx-X.worldCOMx,D=H.worldCOMy-X.worldCOMy;let A=Math.sqrt(F*F+D*D);if(d=A-(ee+W),d<1e100){if(A==0)F=1,D=0;else{let K=1/A;F*=K,D*=K}let J=ee;q.x=X.worldCOMx+F*J,q.y=X.worldCOMy+D*J;let Q=-W;G.x=H.worldCOMx+F*Q,G.y=H.worldCOMy+D*Q,z.x=F,z.y=D}Z=d}else{let X=!1;if(pt(T)&&R.type==1){let H=T;T=R,R=H;let ee=q;q=G,G=ee,X=!0}if(T.type==1&&pt(R)){let H=T.polygon,ee=R.circle||R.capsule,W=Ft(R),F=-1e100,D=null,A=H.edges.head;for(;A!=null;){let J=A.elt,Q=J.gnormx*ee.worldCOMx+J.gnormy*ee.worldCOMy-J.gprojection-W;if(Q>1e100){F=Q;break}Q>0?Q>F&&(F=Q,D=J):F<0&&Q>F&&(F=Q,D=J),A=A.next}if(F<1e100){let J=D.gp0,Q=D.gp1,K=ee.worldCOMy*D.gnormx-ee.worldCOMx*D.gnormy;if(K<=J.y*D.gnormx-J.x*D.gnormy){let ie=0,oe=0;ie=ee.worldCOMx-J.x,oe=ee.worldCOMy-J.y;let se=Math.sqrt(ie*ie+oe*oe);if(F=se-W,F<1e100){if(se==0)ie=1,oe=0;else{let le=1/se;ie*=le,oe*=le}let ne=0;q.x=J.x+ie*ne,q.y=J.y+oe*ne;let re=-W;G.x=ee.worldCOMx+ie*re,G.y=ee.worldCOMy+oe*re,z.x=ie,z.y=oe}}else if(K>=Q.y*D.gnormx-Q.x*D.gnormy){let ie=0,oe=0;ie=ee.worldCOMx-Q.x,oe=ee.worldCOMy-Q.y;let se=Math.sqrt(ie*ie+oe*oe);if(F=se-W,F<1e100){if(se==0)ie=1,oe=0;else{let le=1/se;ie*=le,oe*=le}let ne=0;q.x=Q.x+ie*ne,q.y=Q.y+oe*ne;let re=-W;G.x=ee.worldCOMx+ie*re,G.y=ee.worldCOMy+oe*re,z.x=ie,z.y=oe}}else{let ie=-W;G.x=ee.worldCOMx+D.gnormx*ie,G.y=ee.worldCOMy+D.gnormy*ie;let oe=-F;q.x=G.x+D.gnormx*oe,q.y=G.y+D.gnormy*oe,z.x=D.gnormx,z.y=D.gnormy}}X&&(z.x=-z.x,z.y=-z.y),Z=F}else{let H=T.polygon,ee=R.polygon,W=-1e100,F=null,D=null,A=0,J=H.edges.head;for(;J!=null;){let Q=J.elt,K=1e100,ie=ee.gverts.next;for(;ie!=null;){let oe=ie,se=Q.gnormx*oe.x+Q.gnormy*oe.y;se<K&&(K=se),ie=ie.next}if(K-=Q.gprojection,K>1e100){W=K;break}K>0?K>W&&(W=K,F=Q,A=1):W<0&&K>W&&(W=K,F=Q,A=1),J=J.next}if(W<1e100){let Q=ee.edges.head;for(;Q!=null;){let K=Q.elt,ie=1e100,oe=H.gverts.next;for(;oe!=null;){let se=oe,ne=K.gnormx*se.x+K.gnormy*se.y;ne<ie&&(ie=ne),oe=oe.next}if(ie-=K.gprojection,ie>1e100){W=ie;break}ie>0?ie>W&&(W=ie,D=K,A=2):W<0&&ie>W&&(W=ie,D=K,A=2),Q=Q.next}if(W<1e100){var b,g,P;if(A==1)b=H,g=ee,P=F;else{b=ee,g=H,P=D;let se=q;q=G,G=se,X=!X}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(X?(z.x=-P.gnormx,z.y=-P.gnormy):(z.x=P.gnormx,z.y=P.gnormy),W>=0){let se=P.gp0,ne=P.gp1,re=K.gp0,le=K.gp1,he=0,ae=0,ce=0,te=0;he=ne.x-se.x,ae=ne.y-se.y,ce=le.x-re.x,te=le.y-re.y;let ue=1/(he*he+ae*ae),de=1/(ce*ce+te*te),me=-(he*(se.x-re.x)+ae*(se.y-re.y))*ue,ge=-(he*(se.x-le.x)+ae*(se.y-le.y))*ue,Se=-(ce*(re.x-se.x)+te*(re.y-se.y))*de,Ae=-(ce*(re.x-ne.x)+te*(re.y-ne.y))*de;me<0?me=0:me>1&&(me=1),ge<0?ge=0:ge>1&&(ge=1),Se<0?Se=0:Se>1&&(Se=1),Ae<0?Ae=0:Ae>1&&(Ae=1);let Ue=0,Ye=0,Xe=me;Ue=se.x+he*Xe,Ye=se.y+ae*Xe;let Fe=0,ft=0,vt=ge;Fe=se.x+he*vt,ft=se.y+ae*vt;let ct=0,ht=0,at=Se;ct=re.x+ce*at,ht=re.y+te*at;let Ke=0,bt=0,Bt=Ae;Ke=re.x+ce*Bt,bt=re.y+te*Bt;let Rt=0,kt=0;Rt=Ue-re.x,kt=Ye-re.y;let Et=Rt*Rt+kt*kt,bn=0,Yt=0;bn=Fe-le.x,Yt=ft-le.y;let un=bn*bn+Yt*Yt,on=0,xn=0;on=ct-se.x,xn=ht-se.y;let Xt=on*on+xn*xn,zn=0,Ht=0;zn=Ke-ne.x,Ht=bt-ne.y;let _n=zn*zn+Ht*Ht,qt=0,Qt=0,rn=null;Et<un?(qt=Ue,Qt=Ye,rn=re):(qt=Fe,Qt=ft,rn=le,Et=un);let ni=0,Ln=0,Sn=null;if(Xt<_n?(ni=ct,Ln=ht,Sn=se):(ni=Ke,Ln=bt,Sn=ne,Xt=_n),Et<Xt?(q.x=qt,q.y=Qt,G.x=rn.x,G.y=rn.y,W=Math.sqrt(Et)):(G.x=ni,G.y=Ln,q.x=Sn.x,q.y=Sn.y,W=Math.sqrt(Xt)),W!=0){z.x=G.x-q.x,z.y=G.y-q.y;let Vn=1/W;z.x*=Vn,z.y*=Vn,X&&(z.x=-z.x,z.y=-z.y)}Z=W}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,ae=0;he=re-se,ae=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 Ae=de;se+=he*Ae,ne+=ae*Ae}let me=(-P.tp0-te)*ue;if(me<-l.Config.epsilon){let Ae=me;re+=he*Ae,le+=ae*Ae}let ge=se*P.gnormx+ne*P.gnormy-P.gprojection,Se=re*P.gnormx+le*P.gnormy-P.gprojection;if(ge<Se){G.x=se,G.y=ne;let Ae=-ge;q.x=G.x+P.gnormx*Ae,q.y=G.y+P.gnormy*Ae,Z=ge}else{G.x=re,G.y=le;let Ae=-Se;q.x=G.x+P.gnormx*Ae,q.y=G.y+P.gnormy*Ae,Z=Se}}}else Z=1e100}else Z=1e100}}let B=Z+s,V=c*z.x+h*z.y;if(B<l.Config.distanceThresholdCCD){if(i)break;let X=0,H=0;X=_.x-a.posx,H=_.y-a.posy;let ee=0,W=0;ee=y.x-p.posx,W=y.y-p.posy;let F=V-a.sweep_angvel*(z.y*X-z.x*H)+p.sweep_angvel*(z.y*ee-z.x*W);if(F>0&&(e.slipped=!0),F<=0||B<l.Config.distanceThresholdCCD*.5)break}let Y=(m-V)*t;if(Y<=0){f=-1;break}let $=B/Y;if($<1e-6&&($=1e-6),f+=$,f>=1){f=1;let X=f*t,H=X-a.sweepTime;if(H!=0){a.sweepTime=X;let ie=H;if(a.posx+=a.velx*ie,a.posy+=a.vely*ie,a.angvel!=0){let oe=a.sweep_angvel*H;if(a.rot+=oe,oe*oe>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let se=oe*oe,ne=1-.5*se,re=1-se*se/8,le=(ne*a.axisx+oe*a.axisy)*re;a.axisy=(ne*a.axisy-oe*a.axisx)*re,a.axisx=le}}}if(o.type==0||o.type===2)o.worldCOMx=a.posx+(a.axisy*o.localCOMx-a.axisx*o.localCOMy),o.worldCOMy=a.posy+(o.localCOMx*a.axisx+o.localCOMy*a.axisy);else{let ie=o.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ce=se,te=oe;oe=oe.next,ce.x=a.posx+(a.axisy*te.x-a.axisx*te.y),ce.y=a.posy+(te.x*a.axisx+te.y*a.axisy),se=se.next}let ne=ie.edges.head,re=ie.gverts.next,le=re;for(re=re.next;re!=null;){let ce=re,te=ne.elt;ne=ne.next,te.gnormx=a.axisy*te.lnormx-a.axisx*te.lnormy,te.gnormy=te.lnormx*a.axisx+te.lnormy*a.axisy,te.gprojection=a.posx*te.gnormx+a.posy*te.gnormy+te.lprojection,te.tp0=le.y*te.gnormx-le.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,le=ce,re=re.next}let he=ie.gverts.next,ae=ne.elt;ne=ne.next,ae.gnormx=a.axisy*ae.lnormx-a.axisx*ae.lnormy,ae.gnormy=ae.lnormx*a.axisx+ae.lnormy*a.axisy,ae.gprojection=a.posx*ae.gnormx+a.posy*ae.gnormy+ae.lprojection,ae.tp0=le.y*ae.gnormx-le.x*ae.gnormy,ae.tp1=he.y*ae.gnormx-he.x*ae.gnormy}let ee=f*t,W=ee-p.sweepTime;if(W!=0){p.sweepTime=ee;let ie=W;if(p.posx+=p.velx*ie,p.posy+=p.vely*ie,p.angvel!=0){let oe=p.sweep_angvel*W;if(p.rot+=oe,oe*oe>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let se=oe*oe,ne=1-.5*se,re=1-se*se/8,le=(ne*p.axisx+oe*p.axisy)*re;p.axisy=(ne*p.axisy-oe*p.axisx)*re,p.axisx=le}}}if(r.type==0||r.type===2)r.worldCOMx=p.posx+(p.axisy*r.localCOMx-p.axisx*r.localCOMy),r.worldCOMy=p.posy+(r.localCOMx*p.axisx+r.localCOMy*p.axisy);else{let ie=r.polygon,oe=ie.lverts.next,se=ie.gverts.next;for(;se!=null;){let ce=se,te=oe;oe=oe.next,ce.x=p.posx+(p.axisy*te.x-p.axisx*te.y),ce.y=p.posy+(te.x*p.axisx+te.y*p.axisy),se=se.next}let ne=ie.edges.head,re=ie.gverts.next,le=re;for(re=re.next;re!=null;){let ce=re,te=ne.elt;ne=ne.next,te.gnormx=p.axisy*te.lnormx-p.axisx*te.lnormy,te.gnormy=te.lnormx*p.axisx+te.lnormy*p.axisy,te.gprojection=p.posx*te.gnormx+p.posy*te.gnormy+te.lprojection,te.tp0=le.y*te.gnormx-le.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,le=ce,re=re.next}let he=ie.gverts.next,ae=ne.elt;ne=ne.next,ae.gnormx=p.axisy*ae.lnormx-p.axisx*ae.lnormy,ae.gnormy=ae.lnormx*p.axisx+ae.lnormy*p.axisy,ae.gprojection=p.posx*ae.gnormx+p.posy*ae.gnormy+ae.lprojection,ae.tp0=le.y*ae.gnormx-le.x*ae.gnormy,ae.tp1=he.y*ae.gnormx-he.x*ae.gnormy}let F=o,D=r,A=_,J=y;var v;if(pt(F)&&pt(D)){let ie=F.circle||F.capsule,oe=D.circle||D.capsule,se=Ft(F),ne=Ft(D);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 ae=se;A.x=ie.worldCOMx+re*ae,A.y=ie.worldCOMy+le*ae;let ce=-ne;J.x=oe.worldCOMx+re*ce,J.y=oe.worldCOMy+le*ce,z.x=re,z.y=le}v=N}else{let ie=!1;if(pt(F)&&D.type==1){let oe=F;F=D,D=oe;let se=A;A=J,J=se,ie=!0}if(F.type==1&&pt(D)){let oe=F.polygon,se=D.circle||D.capsule,ne=Ft(D),re=-1e100,le=null,he=oe.edges.head;for(;he!=null;){let ae=he.elt,ce=ae.gnormx*se.worldCOMx+ae.gnormy*se.worldCOMy-ae.gprojection-ne;if(ce>1e100){re=ce;break}ce>0?ce>re&&(re=ce,le=ae):re<0&&ce>re&&(re=ce,le=ae),he=he.next}if(re<1e100){let ae=le.gp0,ce=le.gp1,te=se.worldCOMy*le.gnormx-se.worldCOMx*le.gnormy;if(te<=ae.y*le.gnormx-ae.x*le.gnormy){let ue=0,de=0;ue=se.worldCOMx-ae.x,de=se.worldCOMy-ae.y;let me=Math.sqrt(ue*ue+de*de);if(re=me-ne,re<1e100){if(me==0)ue=1,de=0;else{let Ae=1/me;ue*=Ae,de*=Ae}let ge=0;A.x=ae.x+ue*ge,A.y=ae.y+de*ge;let Se=-ne;J.x=se.worldCOMx+ue*Se,J.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 Ae=1/me;ue*=Ae,de*=Ae}let ge=0;A.x=ce.x+ue*ge,A.y=ce.y+de*ge;let Se=-ne;J.x=se.worldCOMx+ue*Se,J.y=se.worldCOMy+de*Se,z.x=ue,z.y=de}}else{let ue=-ne;J.x=se.worldCOMx+le.gnormx*ue,J.y=se.worldCOMy+le.gnormy*ue;let de=-re;A.x=J.x+le.gnormx*de,A.y=J.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=F.polygon,se=D.polygon,ne=-1e100,re=null,le=null,he=0,ae=oe.edges.head;for(;ae!=null;){let ce=ae.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),ae=ae.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,ge=te.gnormx*me.x+te.gnormy*me.y;ge<ue&&(ue=ge),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 k,C,E;if(he==1)k=oe,C=se,E=re;else{k=se,C=oe,E=le;let me=A;A=J,J=me,ie=!ie}let te=null,ue=1e100,de=C.edges.head;for(;de!=null;){let me=de.elt,ge=E.gnormx*me.gnormx+E.gnormy*me.gnormy;ge<ue&&(ue=ge,te=me),de=de.next}if(ie?(z.x=-E.gnormx,z.y=-E.gnormy):(z.x=E.gnormx,z.y=E.gnormy),ne>=0){let me=E.gp0,ge=E.gp1,Se=te.gp0,Ae=te.gp1,Ue=0,Ye=0,Xe=0,Fe=0;Ue=ge.x-me.x,Ye=ge.y-me.y,Xe=Ae.x-Se.x,Fe=Ae.y-Se.y;let ft=1/(Ue*Ue+Ye*Ye),vt=1/(Xe*Xe+Fe*Fe),ct=-(Ue*(me.x-Se.x)+Ye*(me.y-Se.y))*ft,ht=-(Ue*(me.x-Ae.x)+Ye*(me.y-Ae.y))*ft,at=-(Xe*(Se.x-me.x)+Fe*(Se.y-me.y))*vt,Ke=-(Xe*(Se.x-ge.x)+Fe*(Se.y-ge.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 bt=0,Bt=0,Rt=ct;bt=me.x+Ue*Rt,Bt=me.y+Ye*Rt;let kt=0,Et=0,bn=ht;kt=me.x+Ue*bn,Et=me.y+Ye*bn;let Yt=0,un=0,on=at;Yt=Se.x+Xe*on,un=Se.y+Fe*on;let xn=0,Xt=0,zn=Ke;xn=Se.x+Xe*zn,Xt=Se.y+Fe*zn;let Ht=0,_n=0;Ht=bt-Se.x,_n=Bt-Se.y;let qt=Ht*Ht+_n*_n,Qt=0,rn=0;Qt=kt-Ae.x,rn=Et-Ae.y;let ni=Qt*Qt+rn*rn,Ln=0,Sn=0;Ln=Yt-me.x,Sn=un-me.y;let Vn=Ln*Ln+Sn*Sn,Mi=0,Zi=0;Mi=xn-ge.x,Zi=Xt-ge.y;let ki=Mi*Mi+Zi*Zi,Ui=0,pl=0,qs=null;qt<ni?(Ui=bt,pl=Bt,qs=Se):(Ui=kt,pl=Et,qs=Ae,qt=ni);let cl=0,hl=0,Ws=null;if(Vn<ki?(cl=Yt,hl=un,Ws=me):(cl=xn,hl=Xt,Ws=ge,Vn=ki),qt<Vn?(A.x=Ui,A.y=pl,J.x=qs.x,J.y=qs.y,ne=Math.sqrt(qt)):(J.x=cl,J.y=hl,A.x=Ws.x,A.y=Ws.y,ne=Math.sqrt(Vn)),ne!=0){z.x=J.x-A.x,z.y=J.y-A.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,ge=0;me=te.gp0.x,ge=te.gp0.y;let Se=0,Ae=0;Se=te.gp1.x,Ae=te.gp1.y;let Ue=0,Ye=0;Ue=Se-me,Ye=Ae-ge;let Xe=E.gnormy*me-E.gnormx*ge,Fe=E.gnormy*Se-E.gnormx*Ae,ft=1/(Fe-Xe),vt=(-E.tp1-Xe)*ft;if(vt>l.Config.epsilon){let Ke=vt;me+=Ue*Ke,ge+=Ye*Ke}let ct=(-E.tp0-Fe)*ft;if(ct<-l.Config.epsilon){let Ke=ct;Se+=Ue*Ke,Ae+=Ye*Ke}let ht=me*E.gnormx+ge*E.gnormy-E.gprojection,at=Se*E.gnormx+Ae*E.gnormy-E.gprojection;if(ht<at){J.x=me,J.y=ge;let Ke=-ht;A.x=J.x+E.gnormx*Ke,A.y=J.y+E.gnormy*Ke,v=ht}else{J.x=Se,J.y=Ae;let Ke=-at;A.x=J.x+E.gnormx*Ke,A.y=J.y+E.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=!0),re<=0||Q<l.Config.distanceThresholdCCD*.5)break}f=-1;break}if(++w>=40){B>s&&(e.failed=!0);break}}e.toi=f}static staticSweep(e,t,n,s){let i=_e(),l=e.s1,o=e.s2,r=l.body,a=o.body,p=0,c=0;p=-r.velx,c=-r.vely;let h=r.sweep_angvel;h<0&&(h=-h);let u=l.sweepCoef*h,x=e.c1,m=e.c2,_=e.axis,y=n,z=0;for(;;){let C=y*t,E=C-r.sweepTime;if(E!=0){r.sweepTime=C;let B=E;if(r.posx+=r.velx*B,r.posy+=r.vely*B,r.angvel!=0){let V=r.sweep_angvel*E;if(r.rot+=V,V*V>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let Y=V*V,$=1-.5*Y,X=1-Y*Y/8,H=($*r.axisx+V*r.axisy)*X;r.axisy=($*r.axisy-V*r.axisx)*X,r.axisx=H}}}if(l.type==0||l.type===2)l.worldCOMx=r.posx+(r.axisy*l.localCOMx-r.axisx*l.localCOMy),l.worldCOMy=r.posy+(l.localCOMx*r.axisx+l.localCOMy*r.axisy);else{let B=l.polygon,V=B.lverts.next,Y=B.gverts.next;for(;Y!=null;){let F=Y,D=V;V=V.next,F.x=r.posx+(r.axisy*D.x-r.axisx*D.y),F.y=r.posy+(D.x*r.axisx+D.y*r.axisy),Y=Y.next}let $=B.edges.head,X=B.gverts.next,H=X;for(X=X.next;X!=null;){let F=X,D=$.elt;$=$.next,D.gnormx=r.axisy*D.lnormx-r.axisx*D.lnormy,D.gnormy=D.lnormx*r.axisx+D.lnormy*r.axisy,D.gprojection=r.posx*D.gnormx+r.posy*D.gnormy+D.lprojection,D.tp0=H.y*D.gnormx-H.x*D.gnormy,D.tp1=F.y*D.gnormx-F.x*D.gnormy,H=F,X=X.next}let ee=B.gverts.next,W=$.elt;$=$.next,W.gnormx=r.axisy*W.lnormx-r.axisx*W.lnormy,W.gnormy=W.lnormx*r.axisx+W.lnormy*r.axisy,W.gprojection=r.posx*W.gnormx+r.posy*W.gnormy+W.lprojection,W.tp0=H.y*W.gnormx-H.x*W.gnormy,W.tp1=ee.y*W.gnormx-ee.x*W.gnormy}let M=l,S=o,O=x,L=m;var f;if(pt(M)&&pt(S)){let B=M.circle||M.capsule,V=S.circle||S.capsule,Y=Ft(M),$=Ft(S);var w;let X=0,H=0;X=V.worldCOMx-B.worldCOMx,H=V.worldCOMy-B.worldCOMy;let ee=Math.sqrt(X*X+H*H);if(w=ee-(B.radius+V.radius),w<1e100){if(ee==0)X=1,H=0;else{let D=1/ee;X*=D,H*=D}let W=B.radius;O.x=B.worldCOMx+X*W,O.y=B.worldCOMy+H*W;let F=-V.radius;L.x=V.worldCOMx+X*F,L.y=V.worldCOMy+H*F,_.x=X,_.y=H}f=w}else{let B=!1;if(pt(M)&&S.type==1){let V=M;M=S,S=V;let Y=O;O=L,L=Y,B=!0}if(M.type==1&&pt(S)){let V=M.polygon,Y=S.circle||S.capsule,$=Ft(S),X=-1e100,H=null,ee=V.edges.head;for(;ee!=null;){let W=ee.elt,F=W.gnormx*Y.worldCOMx+W.gnormy*Y.worldCOMy-W.gprojection-$;if(F>1e100){X=F;break}F>0?F>X&&(X=F,H=W):X<0&&F>X&&(X=F,H=W),ee=ee.next}if(X<1e100){let W=H.gp0,F=H.gp1,D=Y.worldCOMy*H.gnormx-Y.worldCOMx*H.gnormy;if(D<=W.y*H.gnormx-W.x*H.gnormy){let A=0,J=0;A=Y.worldCOMx-W.x,J=Y.worldCOMy-W.y;let Q=Math.sqrt(A*A+J*J);if(X=Q-$,X<1e100){if(Q==0)A=1,J=0;else{let oe=1/Q;A*=oe,J*=oe}let K=0;O.x=W.x+A*K,O.y=W.y+J*K;let ie=-$;L.x=Y.worldCOMx+A*ie,L.y=Y.worldCOMy+J*ie,_.x=A,_.y=J}}else if(D>=F.y*H.gnormx-F.x*H.gnormy){let A=0,J=0;A=Y.worldCOMx-F.x,J=Y.worldCOMy-F.y;let Q=Math.sqrt(A*A+J*J);if(X=Q-$,X<1e100){if(Q==0)A=1,J=0;else{let oe=1/Q;A*=oe,J*=oe}let K=0;O.x=F.x+A*K,O.y=F.y+J*K;let ie=-$;L.x=Y.worldCOMx+A*ie,L.y=Y.worldCOMy+J*ie,_.x=A,_.y=J}}else{let A=-$;L.x=Y.worldCOMx+H.gnormx*A,L.y=Y.worldCOMy+H.gnormy*A;let J=-X;O.x=L.x+H.gnormx*J,O.y=L.y+H.gnormy*J,_.x=H.gnormx,_.y=H.gnormy}}B&&(_.x=-_.x,_.y=-_.y),f=X}else{let V=M.polygon,Y=S.polygon,$=-1e100,X=null,H=null,ee=0,W=V.edges.head;for(;W!=null;){let F=W.elt,D=1e100,A=Y.gverts.next;for(;A!=null;){let J=A,Q=F.gnormx*J.x+F.gnormy*J.y;Q<D&&(D=Q),A=A.next}if(D-=F.gprojection,D>1e100){$=D;break}D>0?D>$&&($=D,X=F,ee=1):$<0&&D>$&&($=D,X=F,ee=1),W=W.next}if($<1e100){let F=Y.edges.head;for(;F!=null;){let D=F.elt,A=1e100,J=V.gverts.next;for(;J!=null;){let Q=J,K=D.gnormx*Q.x+D.gnormy*Q.y;K<A&&(A=K),J=J.next}if(A-=D.gprojection,A>1e100){$=A;break}A>0?A>$&&($=A,H=D,ee=2):$<0&&A>$&&($=A,H=D,ee=2),F=F.next}if($<1e100){var Z,d,b;if(ee==1)Z=V,d=Y,b=X;else{Z=Y,d=V,b=H;let Q=O;O=L,L=Q,B=!B}let D=null,A=1e100,J=d.edges.head;for(;J!=null;){let Q=J.elt,K=b.gnormx*Q.gnormx+b.gnormy*Q.gnormy;K<A&&(A=K,D=Q),J=J.next}if(B?(_.x=-b.gnormx,_.y=-b.gnormy):(_.x=b.gnormx,_.y=b.gnormy),$>=0){let Q=b.gp0,K=b.gp1,ie=D.gp0,oe=D.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),ae=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))*ae,de=-(re*(ie.x-K.x)+le*(ie.y-K.y))*ae;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,ge=0,Se=ce;me=Q.x+se*Se,ge=Q.y+ne*Se;let Ae=0,Ue=0,Ye=te;Ae=Q.x+se*Ye,Ue=Q.y+ne*Ye;let Xe=0,Fe=0,ft=ue;Xe=ie.x+re*ft,Fe=ie.y+le*ft;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=ge-ie.y;let bt=at*at+Ke*Ke,Bt=0,Rt=0;Bt=Ae-oe.x,Rt=Ue-oe.y;let kt=Bt*Bt+Rt*Rt,Et=0,bn=0;Et=Xe-Q.x,bn=Fe-Q.y;let Yt=Et*Et+bn*bn,un=0,on=0;un=vt-K.x,on=ct-K.y;let xn=un*un+on*on,Xt=0,zn=0,Ht=null;bt<kt?(Xt=me,zn=ge,Ht=ie):(Xt=Ae,zn=Ue,Ht=oe,bt=kt);let _n=0,qt=0,Qt=null;if(Yt<xn?(_n=Xe,qt=Fe,Qt=Q):(_n=vt,qt=ct,Qt=K,Yt=xn),bt<Yt?(O.x=Xt,O.y=zn,L.x=Ht.x,L.y=Ht.y,$=Math.sqrt(bt)):(L.x=_n,L.y=qt,O.x=Qt.x,O.y=Qt.y,$=Math.sqrt(Yt)),$!=0){_.x=L.x-O.x,_.y=L.y-O.y;let rn=1/$;_.x*=rn,_.y*=rn,B&&(_.x=-_.x,_.y=-_.y)}f=$}else{let Q=0,K=0;Q=D.gp0.x,K=D.gp0.y;let ie=0,oe=0;ie=D.gp1.x,oe=D.gp1.y;let se=0,ne=0;se=ie-Q,ne=oe-K;let re=b.gnormy*Q-b.gnormx*K,le=b.gnormy*ie-b.gnormx*oe,he=1/(le-re),ae=(-b.tp1-re)*he;if(ae>i.Config.epsilon){let de=ae;Q+=se*de,K+=ne*de}let ce=(-b.tp0-le)*he;if(ce<-i.Config.epsilon){let de=ce;ie+=se*de,oe+=ne*de}let te=Q*b.gnormx+K*b.gnormy-b.gprojection,ue=ie*b.gnormx+oe*b.gnormy-b.gprojection;if(te<ue){L.x=Q,L.y=K;let de=-te;O.x=L.x+b.gnormx*de,O.y=L.y+b.gnormy*de,f=te}else{L.x=ie,L.y=oe;let de=-ue;O.x=L.x+b.gnormx*de,O.y=L.y+b.gnormy*de,f=ue}}}else f=1e100}else f=1e100}}let T=f+s,R=p*_.x+c*_.y;if(T<i.Config.distanceThresholdCCD){let B=0,V=0;B=x.x-r.posx,V=x.y-r.posy;let Y=R-r.sweep_angvel*(_.y*B-_.x*V);if(Y>0&&(e.slipped=!0),Y<=0||T<i.Config.distanceThresholdCCD*.5)break}let q=(u-R)*t;if(q<=0){y=-1;break}let G=T/q;if(G<1e-6&&(G=1e-6),y+=G,y>=1){y=1;let B=y*t,V=B-r.sweepTime;if(V!=0){r.sweepTime=B;let F=V;if(r.posx+=r.velx*F,r.posy+=r.vely*F,r.angvel!=0){let D=r.sweep_angvel*V;if(r.rot+=D,D*D>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let A=D*D,J=1-.5*A,Q=1-A*A/8,K=(J*r.axisx+D*r.axisy)*Q;r.axisy=(J*r.axisy-D*r.axisx)*Q,r.axisx=K}}}if(l.type==0||l.type===2)l.worldCOMx=r.posx+(r.axisy*l.localCOMx-r.axisx*l.localCOMy),l.worldCOMy=r.posy+(l.localCOMx*r.axisx+l.localCOMy*r.axisy);else{let F=l.polygon,D=F.lverts.next,A=F.gverts.next;for(;A!=null;){let se=A,ne=D;D=D.next,se.x=r.posx+(r.axisy*ne.x-r.axisx*ne.y),se.y=r.posy+(ne.x*r.axisx+ne.y*r.axisy),A=A.next}let J=F.edges.head,Q=F.gverts.next,K=Q;for(Q=Q.next;Q!=null;){let se=Q,ne=J.elt;J=J.next,ne.gnormx=r.axisy*ne.lnormx-r.axisx*ne.lnormy,ne.gnormy=ne.lnormx*r.axisx+ne.lnormy*r.axisy,ne.gprojection=r.posx*ne.gnormx+r.posy*ne.gnormy+ne.lprojection,ne.tp0=K.y*ne.gnormx-K.x*ne.gnormy,ne.tp1=se.y*ne.gnormx-se.x*ne.gnormy,K=se,Q=Q.next}let ie=F.gverts.next,oe=J.elt;J=J.next,oe.gnormx=r.axisy*oe.lnormx-r.axisx*oe.lnormy,oe.gnormy=oe.lnormx*r.axisx+oe.lnormy*r.axisy,oe.gprojection=r.posx*oe.gnormx+r.posy*oe.gnormy+oe.lprojection,oe.tp0=K.y*oe.gnormx-K.x*oe.gnormy,oe.tp1=ie.y*oe.gnormx-ie.x*oe.gnormy}let Y=l,$=o,X=x,H=m;var g;if(pt(Y)&&pt($)){let F=Y.circle||Y.capsule,D=$.circle||$.capsule,A=Ft(Y),J=Ft($);var P;let Q=0,K=0;Q=D.worldCOMx-F.worldCOMx,K=D.worldCOMy-F.worldCOMy;let ie=Math.sqrt(Q*Q+K*K);if(P=ie-(A+J),P<1e100){if(ie==0)Q=1,K=0;else{let ne=1/ie;Q*=ne,K*=ne}let oe=A;X.x=F.worldCOMx+Q*oe,X.y=F.worldCOMy+K*oe;let se=-J;H.x=D.worldCOMx+Q*se,H.y=D.worldCOMy+K*se,_.x=Q,_.y=K}g=P}else{let F=!1;if(pt(Y)&&$.type==1){let D=Y;Y=$,$=D;let A=X;X=H,H=A,F=!0}if(Y.type==1&&pt($)){let D=Y.polygon,A=$.circle||$.capsule,J=Ft($),Q=-1e100,K=null,ie=D.edges.head;for(;ie!=null;){let oe=ie.elt,se=oe.gnormx*A.worldCOMx+oe.gnormy*A.worldCOMy-oe.gprojection-J;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=A.worldCOMy*K.gnormx-A.worldCOMx*K.gnormy;if(ne<=oe.y*K.gnormx-oe.x*K.gnormy){let re=0,le=0;re=A.worldCOMx-oe.x,le=A.worldCOMy-oe.y;let he=Math.sqrt(re*re+le*le);if(Q=he-J,Q<1e100){if(he==0)re=1,le=0;else{let te=1/he;re*=te,le*=te}let ae=0;X.x=oe.x+re*ae,X.y=oe.y+le*ae;let ce=-J;H.x=A.worldCOMx+re*ce,H.y=A.worldCOMy+le*ce,_.x=re,_.y=le}}else if(ne>=se.y*K.gnormx-se.x*K.gnormy){let re=0,le=0;re=A.worldCOMx-se.x,le=A.worldCOMy-se.y;let he=Math.sqrt(re*re+le*le);if(Q=he-J,Q<1e100){if(he==0)re=1,le=0;else{let te=1/he;re*=te,le*=te}let ae=0;X.x=se.x+re*ae,X.y=se.y+le*ae;let ce=-J;H.x=A.worldCOMx+re*ce,H.y=A.worldCOMy+le*ce,_.x=re,_.y=le}}else{let re=-J;H.x=A.worldCOMx+K.gnormx*re,H.y=A.worldCOMy+K.gnormy*re;let le=-Q;X.x=H.x+K.gnormx*le,X.y=H.y+K.gnormy*le,_.x=K.gnormx,_.y=K.gnormy}}F&&(_.x=-_.x,_.y=-_.y),g=Q}else{let D=Y.polygon,A=$.polygon,J=-1e100,Q=null,K=null,ie=0,oe=D.edges.head;for(;oe!=null;){let se=oe.elt,ne=1e100,re=A.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){J=ne;break}ne>0?ne>J&&(J=ne,Q=se,ie=1):J<0&&ne>J&&(J=ne,Q=se,ie=1),oe=oe.next}if(J<1e100){let se=A.edges.head;for(;se!=null;){let ne=se.elt,re=1e100,le=D.gverts.next;for(;le!=null;){let he=le,ae=ne.gnormx*he.x+ne.gnormy*he.y;ae<re&&(re=ae),le=le.next}if(re-=ne.gprojection,re>1e100){J=re;break}re>0?re>J&&(J=re,K=ne,ie=2):J<0&&re>J&&(J=re,K=ne,ie=2),se=se.next}if(J<1e100){var v,N,k;if(ie==1)v=D,N=A,k=Q;else{v=A,N=D,k=K;let he=X;X=H,H=he,F=!F}let ne=null,re=1e100,le=N.edges.head;for(;le!=null;){let he=le.elt,ae=k.gnormx*he.gnormx+k.gnormy*he.gnormy;ae<re&&(re=ae,ne=he),le=le.next}if(F?(_.x=-k.gnormx,_.y=-k.gnormy):(_.x=k.gnormx,_.y=k.gnormy),J>=0){let he=k.gp0,ae=k.gp1,ce=ne.gp0,te=ne.gp1,ue=0,de=0,me=0,ge=0;ue=ae.x-he.x,de=ae.y-he.y,me=te.x-ce.x,ge=te.y-ce.y;let Se=1/(ue*ue+de*de),Ae=1/(me*me+ge*ge),Ue=-(ue*(he.x-ce.x)+de*(he.y-ce.y))*Se,Ye=-(ue*(he.x-te.x)+de*(he.y-te.y))*Se,Xe=-(me*(ce.x-he.x)+ge*(ce.y-he.y))*Ae,Fe=-(me*(ce.x-ae.x)+ge*(ce.y-ae.y))*Ae;Ue<0?Ue=0:Ue>1&&(Ue=1),Ye<0?Ye=0:Ye>1&&(Ye=1),Xe<0?Xe=0:Xe>1&&(Xe=1),Fe<0?Fe=0:Fe>1&&(Fe=1);let ft=0,vt=0,ct=Ue;ft=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 bt=0,Bt=0,Rt=Xe;bt=ce.x+me*Rt,Bt=ce.y+ge*Rt;let kt=0,Et=0,bn=Fe;kt=ce.x+me*bn,Et=ce.y+ge*bn;let Yt=0,un=0;Yt=ft-ce.x,un=vt-ce.y;let on=Yt*Yt+un*un,xn=0,Xt=0;xn=ht-te.x,Xt=at-te.y;let zn=xn*xn+Xt*Xt,Ht=0,_n=0;Ht=bt-he.x,_n=Bt-he.y;let qt=Ht*Ht+_n*_n,Qt=0,rn=0;Qt=kt-ae.x,rn=Et-ae.y;let ni=Qt*Qt+rn*rn,Ln=0,Sn=0,Vn=null;on<zn?(Ln=ft,Sn=vt,Vn=ce):(Ln=ht,Sn=at,Vn=te,on=zn);let Mi=0,Zi=0,ki=null;if(qt<ni?(Mi=bt,Zi=Bt,ki=he):(Mi=kt,Zi=Et,ki=ae,qt=ni),on<qt?(X.x=Ln,X.y=Sn,H.x=Vn.x,H.y=Vn.y,J=Math.sqrt(on)):(H.x=Mi,H.y=Zi,X.x=ki.x,X.y=ki.y,J=Math.sqrt(qt)),J!=0){_.x=H.x-X.x,_.y=H.y-X.y;let Ui=1/J;_.x*=Ui,_.y*=Ui,F&&(_.x=-_.x,_.y=-_.y)}g=J}else{let he=0,ae=0;he=ne.gp0.x,ae=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-ae;let me=k.gnormy*he-k.gnormx*ae,ge=k.gnormy*ce-k.gnormx*te,Se=1/(ge-me),Ae=(-k.tp1-me)*Se;if(Ae>i.Config.epsilon){let Fe=Ae;he+=ue*Fe,ae+=de*Fe}let Ue=(-k.tp0-ge)*Se;if(Ue<-i.Config.epsilon){let Fe=Ue;ce+=ue*Fe,te+=de*Fe}let Ye=he*k.gnormx+ae*k.gnormy-k.gprojection,Xe=ce*k.gnormx+te*k.gnormy-k.gprojection;if(Ye<Xe){H.x=he,H.y=ae;let Fe=-Ye;X.x=H.x+k.gnormx*Fe,X.y=H.y+k.gnormy*Fe,g=Ye}else{H.x=ce,H.y=te;let Fe=-Xe;X.x=H.x+k.gnormx*Fe,X.y=H.y+k.gnormy*Fe,g=Xe}}}else g=1e100}else g=1e100}}let ee=g+s,W=p*_.x+c*_.y;if(ee<i.Config.distanceThresholdCCD){let F=0,D=0;F=x.x-r.posx,D=x.y-r.posy;let A=W-r.sweep_angvel*(_.y*F-_.x*D);if(A>0&&(e.slipped=!0),A<=0||ee<i.Config.distanceThresholdCCD*.5)break}y=-1;break}if(++z>=40){T>s&&(e.failed=!0);break}}e.toi=y}static distanceBody(e,t,n,s){let i=_e(),l=pe.get(0,0),o=pe.get(0,0),r=pe.get(0,0),a=1e100,p=e.shapes.head;for(;p!=null;){let f=p.elt,w=t.shapes.head;for(;w!=null;){let Z=w.elt,d=f,b=Z,g=l,P=o,v=a;v==null&&(v=1e100);var c;if(pt(d)&&pt(b)){let N=d.circle||d.capsule,k=b.circle||b.capsule,C=Ft(d),E=Ft(b);var h;let M=0,S=0;M=k.worldCOMx-N.worldCOMx,S=k.worldCOMy-N.worldCOMy;let O=Math.sqrt(M*M+S*S);if(h=O-(C+E),h<v){if(O==0)M=1,S=0;else{let R=1/O;M*=R,S*=R}let L=C;g.x=N.worldCOMx+M*L,g.y=N.worldCOMy+S*L;let T=-E;P.x=k.worldCOMx+M*T,P.y=k.worldCOMy+S*T,r.x=M,r.y=S}c=h}else{let N=!1;if(pt(d)&&b.type==1){let k=d;d=b,b=k;let C=g;g=P,P=C,N=!0}if(d.type==1&&pt(b)){let k=d.polygon,C=b.circle||b.capsule,E=Ft(b),M=-1e100,S=null,O=k.edges.head;for(;O!=null;){let L=O.elt,T=L.gnormx*C.worldCOMx+L.gnormy*C.worldCOMy-L.gprojection-E;if(T>v){M=T;break}T>0?T>M&&(M=T,S=L):M<0&&T>M&&(M=T,S=L),O=O.next}if(M<v){let L=S.gp0,T=S.gp1,R=C.worldCOMy*S.gnormx-C.worldCOMx*S.gnormy;if(R<=L.y*S.gnormx-L.x*S.gnormy){let q=0,G=0;q=C.worldCOMx-L.x,G=C.worldCOMy-L.y;let B=Math.sqrt(q*q+G*G);if(M=B-E,M<v){if(B==0)q=1,G=0;else{let $=1/B;q*=$,G*=$}let V=0;g.x=L.x+q*V,g.y=L.y+G*V;let Y=-E;P.x=C.worldCOMx+q*Y,P.y=C.worldCOMy+G*Y,r.x=q,r.y=G}}else if(R>=T.y*S.gnormx-T.x*S.gnormy){let q=0,G=0;q=C.worldCOMx-T.x,G=C.worldCOMy-T.y;let B=Math.sqrt(q*q+G*G);if(M=B-E,M<v){if(B==0)q=1,G=0;else{let $=1/B;q*=$,G*=$}let V=0;g.x=T.x+q*V,g.y=T.y+G*V;let Y=-E;P.x=C.worldCOMx+q*Y,P.y=C.worldCOMy+G*Y,r.x=q,r.y=G}}else{let q=-E;P.x=C.worldCOMx+S.gnormx*q,P.y=C.worldCOMy+S.gnormy*q;let G=-M;g.x=P.x+S.gnormx*G,g.y=P.y+S.gnormy*G,r.x=S.gnormx,r.y=S.gnormy}}N&&(r.x=-r.x,r.y=-r.y),c=M}else{let k=d.polygon,C=b.polygon,E=-1e100,M=null,S=null,O=0,L=k.edges.head;for(;L!=null;){let T=L.elt,R=1e100,q=C.gverts.next;for(;q!=null;){let G=q,B=T.gnormx*G.x+T.gnormy*G.y;B<R&&(R=B),q=q.next}if(R-=T.gprojection,R>v){E=R;break}R>0?R>E&&(E=R,M=T,O=1):E<0&&R>E&&(E=R,M=T,O=1),L=L.next}if(E<v){let T=C.edges.head;for(;T!=null;){let R=T.elt,q=1e100,G=k.gverts.next;for(;G!=null;){let B=G,V=R.gnormx*B.x+R.gnormy*B.y;V<q&&(q=V),G=G.next}if(q-=R.gprojection,q>v){E=q;break}q>0?q>E&&(E=q,S=R,O=2):E<0&&q>E&&(E=q,S=R,O=2),T=T.next}if(E<v){var u,x,m;if(O==1)u=k,x=C,m=M;else{u=C,x=k,m=S;let B=g;g=P,P=B,N=!N}let R=null,q=1e100,G=x.edges.head;for(;G!=null;){let B=G.elt,V=m.gnormx*B.gnormx+m.gnormy*B.gnormy;V<q&&(q=V,R=B),G=G.next}if(N?(r.x=-m.gnormx,r.y=-m.gnormy):(r.x=m.gnormx,r.y=m.gnormy),E>=0){let B=m.gp0,V=m.gp1,Y=R.gp0,$=R.gp1,X=0,H=0,ee=0,W=0;X=V.x-B.x,H=V.y-B.y,ee=$.x-Y.x,W=$.y-Y.y;let F=1/(X*X+H*H),D=1/(ee*ee+W*W),A=-(X*(B.x-Y.x)+H*(B.y-Y.y))*F,J=-(X*(B.x-$.x)+H*(B.y-$.y))*F,Q=-(ee*(Y.x-B.x)+W*(Y.y-B.y))*D,K=-(ee*(Y.x-V.x)+W*(Y.y-V.y))*D;A<0?A=0:A>1&&(A=1),J<0?J=0:J>1&&(J=1),Q<0?Q=0:Q>1&&(Q=1),K<0?K=0:K>1&&(K=1);let ie=0,oe=0,se=A;ie=B.x+X*se,oe=B.y+H*se;let ne=0,re=0,le=J;ne=B.x+X*le,re=B.y+H*le;let he=0,ae=0,ce=Q;he=Y.x+ee*ce,ae=Y.y+W*ce;let te=0,ue=0,de=K;te=Y.x+ee*de,ue=Y.y+W*de;let me=0,ge=0;me=ie-Y.x,ge=oe-Y.y;let Se=me*me+ge*ge,Ae=0,Ue=0;Ae=ne-$.x,Ue=re-$.y;let Ye=Ae*Ae+Ue*Ue,Xe=0,Fe=0;Xe=he-B.x,Fe=ae-B.y;let ft=Xe*Xe+Fe*Fe,vt=0,ct=0;vt=te-V.x,ct=ue-V.y;let ht=vt*vt+ct*ct,at=0,Ke=0,bt=null;Se<Ye?(at=ie,Ke=oe,bt=Y):(at=ne,Ke=re,bt=$,Se=Ye);let Bt=0,Rt=0,kt=null;if(ft<ht?(Bt=he,Rt=ae,kt=B):(Bt=te,Rt=ue,kt=V,ft=ht),Se<ft?(g.x=at,g.y=Ke,P.x=bt.x,P.y=bt.y,E=Math.sqrt(Se)):(P.x=Bt,P.y=Rt,g.x=kt.x,g.y=kt.y,E=Math.sqrt(ft)),E!=0){r.x=P.x-g.x,r.y=P.y-g.y;let Et=1/E;r.x*=Et,r.y*=Et,N&&(r.x=-r.x,r.y=-r.y)}c=E}else{let B=0,V=0;B=R.gp0.x,V=R.gp0.y;let Y=0,$=0;Y=R.gp1.x,$=R.gp1.y;let X=0,H=0;X=Y-B,H=$-V;let ee=m.gnormy*B-m.gnormx*V,W=m.gnormy*Y-m.gnormx*$,F=1/(W-ee),D=(-m.tp1-ee)*F;if(D>i.Config.epsilon){let K=D;B+=X*K,V+=H*K}let A=(-m.tp0-W)*F;if(A<-i.Config.epsilon){let K=A;Y+=X*K,$+=H*K}let J=B*m.gnormx+V*m.gnormy-m.gprojection,Q=Y*m.gnormx+$*m.gnormy-m.gprojection;if(J<Q){P.x=B,P.y=V;let K=-J;g.x=P.x+m.gnormx*K,g.y=P.y+m.gnormy*K,c=J}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=o.x,s.y=o.y),w=w.next}p=p.next}let _=l;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=pe.zpp_pool,pe.zpp_pool=_;let y=o;y.outer!=null&&(y.outer.zpp_inner=null,y.outer=null),y._isimmutable=null,y._validate=null,y._invalidate=null,y.next=pe.zpp_pool,pe.zpp_pool=y;let z=r;return z.outer!=null&&(z.outer.zpp_inner=null,z.outer=null),z._isimmutable=null,z._validate=null,z._invalidate=null,z.next=pe.zpp_pool,pe.zpp_pool=z,a}static distance(e,t,n,s,i,l){let o=_e();if(l==null&&(l=1e100),pt(e)&&pt(t)){let r=e.circle||e.capsule,a=t.circle||t.capsule,p=Ft(e),c=Ft(t),h,u=0,x=0;u=a.worldCOMx-r.worldCOMx,x=a.worldCOMy-r.worldCOMy;let m=Math.sqrt(u*u+x*x);if(h=m-(p+c),h<l){if(m==0)u=1,x=0;else{let z=1/m;u*=z,x*=z}let _=p;n.x=r.worldCOMx+u*_,n.y=r.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 r=!1;if(pt(e)&&t.type==1){let a=e;e=t,t=a;let p=n;n=s,s=p,r=!0}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,f=0;z=p.worldCOMx-m.x,f=p.worldCOMy-m.y;let w=Math.sqrt(z*z+f*f);if(h=w-c,h<l){if(w==0)z=1,f=0;else{let b=1/w;z*=b,f*=b}let Z=0;n.x=m.x+z*Z,n.y=m.y+f*Z;let d=-c;s.x=p.worldCOMx+z*d,s.y=p.worldCOMy+f*d,i.x=z,i.y=f}}else if(y>=_.y*u.gnormx-_.x*u.gnormy){let z=0,f=0;z=p.worldCOMx-_.x,f=p.worldCOMy-_.y;let w=Math.sqrt(z*z+f*f);if(h=w-c,h<l){if(w==0)z=1,f=0;else{let b=1/w;z*=b,f*=b}let Z=0;n.x=_.x+z*Z,n.y=_.y+f*Z;let d=-c;s.x=p.worldCOMx+z*d,s.y=p.worldCOMy+f*d,i.x=z,i.y=f}}else{let z=-c;s.x=p.worldCOMx+u.gnormx*z,s.y=p.worldCOMy+u.gnormy*z;let f=-h;n.x=s.x+u.gnormx*f,n.y=s.y+u.gnormy*f,i.x=u.gnormx,i.y=u.gnormy}}return r&&(i.x=-i.x,i.y=-i.y),h}else{let a=e.polygon,p=t.polygon,c=-1e100,h=null,u=null,x=0,m=a.edges.head;for(;m!=null;){let _=m.elt,y=1e100,z=p.gverts.next;for(;z!=null;){let f=z,w=_.gnormx*f.x+_.gnormy*f.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,f=a.gverts.next;for(;f!=null;){let w=f,Z=y.gnormx*w.x+y.gnormy*w.y;Z<z&&(z=Z),f=f.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 y,z,f;if(x==1)y=a,z=p,f=h;else{y=p,z=a,f=u;let b=n;n=s,s=b,r=!r}let w=null,Z=1e100,d=z.edges.head;for(;d!=null;){let b=d.elt,g=f.gnormx*b.gnormx+f.gnormy*b.gnormy;g<Z&&(Z=g,w=b),d=d.next}if(r?(i.x=-f.gnormx,i.y=-f.gnormy):(i.x=f.gnormx,i.y=f.gnormy),c>=0){let b=f.gp0,g=f.gp1,P=w.gp0,v=w.gp1,N=0,k=0,C=0,E=0;N=g.x-b.x,k=g.y-b.y,C=v.x-P.x,E=v.y-P.y;let M=1/(N*N+k*k),S=1/(C*C+E*E),O=-(N*(b.x-P.x)+k*(b.y-P.y))*M,L=-(N*(b.x-v.x)+k*(b.y-v.y))*M,T=-(C*(P.x-b.x)+E*(P.y-b.y))*S,R=-(C*(P.x-g.x)+E*(P.y-g.y))*S;O<0?O=0:O>1&&(O=1),L<0?L=0:L>1&&(L=1),T<0?T=0:T>1&&(T=1),R<0?R=0:R>1&&(R=1);let q=0,G=0,B=O;q=b.x+N*B,G=b.y+k*B;let V=0,Y=0,$=L;V=b.x+N*$,Y=b.y+k*$;let X=0,H=0,ee=T;X=P.x+C*ee,H=P.y+E*ee;let W=0,F=0,D=R;W=P.x+C*D,F=P.y+E*D;let A=0,J=0;A=q-P.x,J=G-P.y;let Q=A*A+J*J,K=0,ie=0;K=V-v.x,ie=Y-v.y;let oe=K*K+ie*ie,se=0,ne=0;se=X-b.x,ne=H-b.y;let re=se*se+ne*ne,le=0,he=0;le=W-g.x,he=F-g.y;let ae=le*le+he*he,ce=0,te=0,ue=null;Q<oe?(ce=q,te=G,ue=P):(ce=V,te=Y,ue=v,Q=oe);let de=0,me=0,ge=null;if(re<ae?(de=X,me=H,ge=b):(de=W,me=F,ge=g,re=ae),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=ge.x,n.y=ge.y,c=Math.sqrt(re)),c!=0){i.x=s.x-n.x,i.y=s.y-n.y;let Se=1/c;i.x*=Se,i.y*=Se,r&&(i.x=-i.x,i.y=-i.y)}return c}else{let b=0,g=0;b=w.gp0.x,g=w.gp0.y;let P=0,v=0;P=w.gp1.x,v=w.gp1.y;let N=0,k=0;N=P-b,k=v-g;let C=f.gnormy*b-f.gnormx*g,E=f.gnormy*P-f.gnormx*v,M=1/(E-C),S=(-f.tp1-C)*M;if(S>o.Config.epsilon){let R=S;b+=N*R,g+=k*R}let O=(-f.tp0-E)*M;if(O<-o.Config.epsilon){let R=O;P+=N*R,v+=k*R}let L=b*f.gnormx+g*f.gnormy-f.gprojection,T=P*f.gnormx+v*f.gnormy-f.gprojection;if(L<T){s.x=b,s.y=g;let R=-L;return n.x=s.x+f.gnormx*R,n.y=s.y+f.gnormy*R,L}else{s.x=P,s.y=v;let R=-T;return n.x=s.x+f.gnormx*R,n.y=s.y+f.gnormy*R,T}}}else return l}else return l}}}};var Le=class Le{static lt(e,t){return e.y<t.y?!0:e.y==t.y?e.x<t.x:!1}static right_turn(e,t,n){let s=n.x-t.x,i=n.y-t.y,l=t.x-e.x;return(t.y-e.y)*s-l*i}static delaunay(e,t,n,s){let i=n.x-t.x,l=n.y-t.y,o=t.x-e.x,r=t.y-e.y,a,p,c;return r*i-o*l>=0?c=!0:(i=s.x-n.x,l=s.y-n.y,o=n.x-t.x,r=n.y-t.y,c=r*i-o*l>=0),c?p=!0:(i=e.x-s.x,l=e.y-s.y,o=s.x-n.x,r=s.y-n.y,p=r*i-o*l>=0),p?a=!0:(i=t.x-e.x,l=t.y-e.y,o=e.x-s.x,r=e.y-s.y,a=r*i-o*l>=0),a?!0:t.x*(n.y*s.mag-n.mag*s.y)-n.x*(t.y*s.mag-t.mag*s.y)+s.x*(t.y*n.mag-t.mag*n.y)-(e.x*(n.y*s.mag-n.mag*s.y)-n.x*(e.y*s.mag-e.mag*s.y)+s.x*(e.y*n.mag-e.mag*n.y))+(e.x*(t.y*s.mag-t.mag*s.y)-t.x*(e.y*s.mag-e.mag*s.y)+s.x*(e.y*t.mag-e.mag*t.y))-(e.x*(t.y*n.mag-t.mag*n.y)-t.x*(e.y*n.mag-e.mag*n.y)+n.x*(e.y*t.mag-e.mag*t.y))>0}static optimise(e){let t=e.vertices,n=e.vertices;if(t!=null){let r=t;for(;;){let a=r;if(a.sort(),a.mag=a.x*a.x+a.y*a.y,r=r.next,r==n)break}}Le.edgeSet==null&&(es.zpp_pool==null?Le.edgeSet=new es:(Le.edgeSet=es.zpp_pool,es.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 r=i;for(;;){let a=r,p=a.next;a.diagonals.reverse();let c=a.diagonals.head;for(;c!=null;){let h=c.elt;if(h.id<a.id){p=h,c=c.next;continue}let u=c.next==null?a.prev:c.next.elt;if(!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(r=r.next,r==l)break}}for(;s.next!=null;){let r=s.pop_unsafe(),a=r.a,p=r.b,c=a.next,h=null,u=a.diagonals.head;for(;u!=null;){let m=u.elt;if(m==p){u=u.next,h=u==null?a.prev:u.elt;break}c=m,u=u.next}if(a.diagonals.remove(p),p.diagonals.remove(a),p==c.next)c.diagonals.add(h);else{let m=c.diagonals.head;for(;m!=null;){if(m.elt==p){c.diagonals.insert(m,h);break}m=m.next}}if(a==h.next)h.diagonals.add(c);else{let m=h.diagonals.head;for(;m!=null;){if(m.elt==a){h.diagonals.insert(m,c);break}m=m.next}}Le.edgeSet.remove_node(r.node);let x=r;x.a=x.b=null,x.node=null,x.next=St.zpp_pool,St.zpp_pool=x}let o=s;o.a=o.b=null,o.node=null,o.next=St.zpp_pool,St.zpp_pool=o}static triangulate(e){let t=e.vertices,n=e.vertices,s=e.vertices.next,i=e.vertices;if(s!=null){let a=s;for(;;){let p=a;if((p.y<t.y||p.y==t.y&&p.x<t.x)&&(t=p),(n.y<p.y||n.y==p.y&&n.x<p.x)&&(n=p),a=a.next,a==i)break}}Le.queue==null&&(Le.queue=new xi);let l=n.prev,o=n.next;for(Le.queue.add(n);l!=t||o!=t;)l==t||o!=t&&(l.y<o.y||l.y==o.y&&l.x<o.x)?(Le.queue.add(o),o.rightchain=!1,o=o.next):(Le.queue.add(l),l.rightchain=!0,l=l.prev);Le.queue.add(t),Le.stack==null&&(Le.stack=new xi),Le.stack.add(Le.queue.pop_unsafe());let r=Le.queue.pop_unsafe();for(Le.stack.add(r);;){let a=Le.queue.pop_unsafe();if(Le.queue.head==null)break;if(a.rightchain!=Le.stack.head.elt.rightchain){for(;;){let p=Le.stack.pop_unsafe();if(Le.stack.head==null)break;e.add_diagonal(p,a)}Le.stack.add(r)}else{let p=Le.stack.pop_unsafe();for(;Le.stack.head!=null;){let c=Le.stack.head.elt,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),r=a}if(Le.stack.head!=null)for(Le.stack.pop();Le.stack.head!=null;){let a=Le.stack.pop_unsafe();if(Le.stack.head==null)break;e.add_diagonal(n,a)}return e}};Le.queue=null,Le.stack=null,Le.edgeSet=null;var li=Le;var as=class as{constructor(){this.outer=null;this.x=0;this.y=0;this.z=0;this.immutable=!1;this._validate=null}validate(){this._validate!=null&&this._validate()}wrapper(){return this.outer==null&&as._wrapFn&&(this.outer=as._wrapFn(this)),this.outer}};as._zpp=null,as._wrapFn=null;var oi=as;var Qs=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=dn.Interactor(),e.cbsets=new t.util.ZNPList_ZPP_CallbackSet,e.cbTypes=new t.util.ZNPList_ZPP_CbType}static get(e,t){let n=e.id<t.id?e.id:t.id,s=e.id<t.id?t.id:e.id,i=e.cbsets.length<t.cbsets.length?e.cbsets:t.cbsets,l=null,o=i.head;for(;o!=null;){let r=o.elt;if(r.id==n&&r.di==s){l=r;break}o=o.next}return l}static int_callback(e,t,n){let s=e.int1,i=e.int2,l,o=t.options1,r=s.cbTypes;if(o.nonemptyintersection(r,o.includes)&&!o.nonemptyintersection(r,o.excludes)){let a=t.options2,p=i.cbTypes;l=a.nonemptyintersection(p,a.includes)&&!a.nonemptyintersection(p,a.excludes)}else l=!1;l?(n.int1=s,n.int2=i):(n.int1=i,n.int2=s)}isShape(){return this.ishape!=null}isBody(){return this.ibody!=null}isCompound(){return this.icompound!=null}__iaddedToSpace(){this.group!=null&&this.group.interactors.add(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.add(this),e=e.next;this.alloc_cbSet()}__iremovedFromSpace(){this.group!=null&&this.group.interactors.remove(this);let e=this.cbTypes.head;for(;e!=null;)e.elt.interactors.remove(this),e=e.next;this.dealloc_cbSet()}wake(){if(this.ishape!=null){let e=this.ishape.body;e!=null&&e.space!=null&&e.space.non_inlined_wake(e)}else this.ibody!=null?this.ibody.space!=null&&this.ibody.space.non_inlined_wake(this.ibody):this.icompound.space!=null&&this.icompound.space.wakeCompound(this.icompound)}_getSpace(){return this.ishape!=null?this.ishape.body==null?null:this.ishape.body.space:this.ibody!=null?this.ibody.space:this.icompound.space}getSpace(){return this._getSpace()}setupcbTypes(){let e=fn._zpp;this.wrap_cbTypes=e.util.ZPP_CbTypeList.get(this.cbTypes),this.wrap_cbTypes.zpp_inner.adder=this.wrap_cbTypes_adder.bind(this),this.wrap_cbTypes.zpp_inner.subber=this.wrap_cbTypes_subber.bind(this),this.wrap_cbTypes.zpp_inner.dontremove=!0,this.wrap_cbTypes.zpp_inner._modifiable=this.immutable_cbTypes.bind(this)}immutable_cbTypes(){this.immutable_midstep("Interactor::cbTypes")}wrap_cbTypes_subber(e){let t=e.zpp_inner;if(this.cbTypes.has(t)){let n=this._getSpace();n!=null&&(this.dealloc_cbSet(),t.interactors.remove(this)),this.cbTypes.remove(t),n!=null&&(this.alloc_cbSet(),this.wake())}}wrap_cbTypes_adder(e){return this.insert_cbtype(e.zpp_inner),!1}insert_cbtype(e){let t=fn._zpp;if(!this.cbTypes.has(e)){let n=this._getSpace();n!=null&&(this.dealloc_cbSet(),e.interactors.add(this));let s=null,i=this.cbTypes.head;for(;i!=null;){let a=i.elt;if(e.id<a.id)break;s=i,i=i.next}let l=this.cbTypes,o;t.util.ZNPNode_ZPP_CbType.zpp_pool==null?o=new t.util.ZNPNode_ZPP_CbType:(o=t.util.ZNPNode_ZPP_CbType.zpp_pool,t.util.ZNPNode_ZPP_CbType.zpp_pool=o.next,o.next=null),o.elt=e;let r=o;s==null?(r.next=l.head,l.head=r):(r.next=s.next,s.next=r),l.pushmod=l.modified=!0,l.length++,n!=null&&(this.alloc_cbSet(),this.wake())}}alloc_cbSet(){let e=this._getSpace();(this.cbSet=e.cbsets.get(this.cbTypes))!=null&&(this.cbSet.count++,this.cbSet.interactors.add(this),this.cbSet.validate(),e.freshInteractorType(this))}dealloc_cbSet(){let e=this._getSpace();if(this.cbSet!=null){if(this.cbSet.interactors.remove(this),e.nullInteractorType(this),--this.cbSet.count==0){e.cbsets.remove(this.cbSet);let t=this.cbSet;for(t.listeners.clear(),t.zip_listeners=!0,t.bodylisteners.clear(),t.zip_bodylisteners=!0,t.conlisteners.clear(),t.zip_conlisteners=!0;t.cbTypes.head!=null;)t.cbTypes.pop_unsafe().cbsets.remove(t);t.next=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=!1,l.zpp_inner.user_length=l.zpp_inner.inner.length);let o=l.zpp_inner.user_length;i.zpp_critical=!0;let r;if(i.zpp_i<o?r=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,r=!1),!r)break;i.zpp_critical=!1;let a=i.zpp_inner.at(i.zpp_i++);e.zpp_inner_i.wrap_cbTypes==null&&e.zpp_inner_i.setupcbTypes();let p=e.zpp_inner_i.wrap_cbTypes;p.zpp_inner.reverse_flag?p.push(a):p.unshift(a)}this.userData!=null&&(e.zpp_inner_i.userData=Object.assign({},this.userData))}static _init(e,t){fn._initialized||(fn._initialized=!0,fn._zpp=e,fn._nape=t)}};fn._nape=null,fn._zpp=null,fn._initialized=!1;var Ut=fn;var je=class je{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.world=!1;this.type=0;this.compound=null;this.shapes=null;this.wrap_shapes=null;this.space=null;this.arbiters=null;this.wrap_arbiters=null;this.constraints=null;this.wrap_constraints=null;this.component=null;this.graph_depth=0;this.sweepTime=0;this.sweep_angvel=0;this.sweepFrozen=!1;this.sweepRadius=0;this.bullet=!1;this.bulletEnabled=!1;this.disableCCD=!1;this.pre_posx=0;this.pre_posy=0;this.posx=0;this.posy=0;this.wrap_pos=null;this.velx=0;this.vely=0;this.wrap_vel=null;this.forcex=0;this.forcey=0;this.wrap_force=null;this.kinvelx=0;this.kinvely=0;this.wrap_kinvel=null;this.svelx=0;this.svely=0;this.wrap_svel=null;this.wrapcvel=null;this.angvel=0;this.torque=0;this.kinangvel=0;this.pre_rot=0;this.rot=0;this.axisx=0;this.axisy=0;this.zip_axis=!1;this.kinematicDelaySleep=!1;this.mass=0;this.zip_mass=!1;this.massMode=0;this.imass=0;this.smass=0;this.cmass=0;this.nomove=!1;this.gravMass=0;this.zip_gravMass=!1;this.gravMassMode=0;this.gravMassScale=0;this.zip_gravMassScale=!1;this.inertiaMode=0;this.inertia=0;this.zip_inertia=!1;this.cinertia=0;this.iinertia=0;this.sinertia=0;this.norotate=!1;this.aabb=null;this.zip_aabb=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;let e=je._zpp;Ut.initFields(this),this.ibody=this,this.world=!1,this.bulletEnabled=!1,this.sweepTime=0,this.sweep_angvel=0,this.norotate=this.nomove=!1,this.disableCCD=!1,this.posx=0,this.posy=0,this.rot=0,this.axisx=0,this.axisy=1,this.svelx=0,this.svely=0,this.velx=0,this.vely=0,this.kinvelx=0,this.kinvely=0,this.forcex=0,this.forcey=0,this.torque=this.angvel=this.kinangvel=0,this.pre_posx=1/0,this.pre_posy=1/0,this.pre_rot=1/0,this.localCOMx=0,this.localCOMy=0,this.worldCOMx=0,this.worldCOMy=0,this.zip_aabb=!0;let t;fe.zpp_pool==null?t=new fe:(t=fe.zpp_pool,fe.zpp_pool=t.next,t.next=null),t.minx=0,t.miny=0,t.maxx=0,t.maxy=0,this.aabb=t,this.aabb._immutable=!0,this.aabb._validate=this.aabb_validate.bind(this),this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.arbiters=new e.util.ZNPList_ZPP_Arbiter,this.constraints=new e.util.ZNPList_ZPP_Constraint,this.shapes=new e.util.ZNPList_ZPP_Shape,this.wrap_shapes=e.util.ZPP_ShapeList.get(this.shapes),this.wrap_shapes.zpp_inner.adder=this.shapes_adder.bind(this),this.wrap_shapes.zpp_inner.subber=this.shapes_subber.bind(this),this.wrap_shapes.zpp_inner._invalidate=this.shapes_invalidate.bind(this),this.wrap_shapes.zpp_inner._modifiable=this.shapes_modifiable.bind(this),this.kinematicDelaySleep=!1}static bodysetlt(e,t){return e.id<t.id}static __static(){let e=je._nape,t=je._zpp;t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new e.phys.BodyType,t.util.ZPP_Flags.internal=!1);let n=new e.phys.Body(t.util.ZPP_Flags.BodyType_STATIC),s=n.zpp_inner;return s.world=!0,s.wrap_shapes.zpp_inner.immutable=!0,s.smass=s.imass=s.cmass=s.mass=s.gravMass=0,s.sinertia=s.iinertia=s.cinertia=s.inertia=0,s.cbTypes.clear(),n}isStatic(){return this.type===1}isDynamic(){return this.type===2}isKinematic(){return this.type===3}invalidate_type(){this.invalidate_mass(),this.invalidate_inertia()}invalidate_shapes(){this.zip_aabb=!0,this.zip_localCOM=!0,this.zip_worldCOM=!0,this.invalidate_mass(),this.invalidate_inertia()}init_bodysetlist(){if(je.bodyset==null){let e=je._zpp;je.bodyset=new e.util.ZPP_Set_ZPP_Body,je.bodyset.lt=je.bodysetlt,je.bodystack=new e.util.ZNPList_ZPP_Body}}connectedBodies_cont(e){je.bodyset.try_insert_bool(e.zpp_inner)&&(je.bodystack.add(e.zpp_inner),e.zpp_inner.graph_depth=je.cur_graph_depth+1)}connectedBodies(e,t){let n=je._nape;je.bodyset==null&&this.init_bodysetlist();let s=t??new n.phys.BodyList;for(je.bodystack.add(this),je.bodyset.insert(this),this.graph_depth=0;je.bodystack.head!=null;){let l=je.bodystack.pop_unsafe();if(l.graph_depth===e)continue;je.cur_graph_depth=l.graph_depth;let o=l.constraints.head;for(;o!=null;)o.elt.outer.visitBodies(this.connectedBodies_cont.bind(this)),o=o.next}let i=je.bodyset;if(i.parent!=null){let l=i.parent;for(;l!=null;)if(l.prev!=null)l=l.prev;else if(l.next!=null)l=l.next;else{let o=l.data;if(o!==this){let p=o.outer;s.zpp_inner.reverse_flag?s.push(p):s.unshift(p)}let r=l.parent;r!=null&&(l===r.prev?r.prev=null:r.next=null,l.parent=null);let a=l;a.data=null,a.lt=null,a.next=je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool,je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool=a,l=r}i.parent=null}return s}interactingBodies(e,t){let n=je._nape,s=je._zpp;je.bodyset==null&&this.init_bodysetlist();let i=t??new n.phys.BodyList,l=this.arbiters.head;for(;l!=null;){let r=l.elt;if(!r.sleeping&&(e===4||r.type===e)){let a=r.b1===this?r.b2:r.b1;if(je.bodyset.try_insert_bool(a)){let p=a.outer;i.zpp_inner.reverse_flag?i.push(p):i.unshift(p)}}l=l.next}let o=je.bodyset;if(o.parent!=null){let r=o.parent;for(;r!=null;)if(r.prev!=null)r=r.prev;else if(r.next!=null)r=r.next;else{let a=r.parent;a!=null&&(r===a.prev?a.prev=null:a.next=null,r.parent=null);let p=r;p.data=null,p.lt=null,p.next=s.util.ZPP_Set_ZPP_Body.zpp_pool,s.util.ZPP_Set_ZPP_Body.zpp_pool=p,r=a}o.parent=null}return i}atRest(e){let t=je._nape;if(this.type!==2)return this.component.sleeping;let n=t.Config.linearSleepThreshold*t.Config.linearSleepThreshold,s;if(this.velx*this.velx+this.vely*this.vely>n)s=!1;else{let i=this.posx-this.pre_posx,l=this.posy-this.pre_posy;if(i*i+l*l>.25*n*e*e)s=!1;else{let o=this.aabb.maxx-this.aabb.minx,r=this.aabb.maxy-this.aabb.miny,a=o*o+r*r,p=t.Config.angularSleepThreshold*t.Config.angularSleepThreshold;if(4*this.angvel*this.angvel*a>p)s=!1;else{let c=this.rot-this.pre_rot;s=!(c*c*a>p*e*e)}}}return s||(this.component.waket=this.space.stamp),this.component.waket+t.Config.sleepDelay<this.space.stamp}refreshArbiters(){let e=this.arbiters.head;for(;e!=null;){let t=e.elt;t.invalidated=!0,e=e.next}}sweepIntegrate(e){let t=e-this.sweepTime;if(t!==0&&(this.sweepTime=e,this.posx+=this.velx*t,this.posy+=this.vely*t,this.angvel!==0)){let n=this.sweep_angvel*t;if(this.rot+=n,n*n>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let s=n*n,i=1-.5*s,l=1-s*s/8,o=(i*this.axisx+n*this.axisy)*l;this.axisy=(i*this.axisy-n*this.axisx)*l,this.axisx=o}}}sweepValidate(e){if(e.type===0)e.worldCOMx=this.posx+(this.axisy*e.localCOMx-this.axisx*e.localCOMy),e.worldCOMy=this.posy+(e.localCOMx*this.axisx+e.localCOMy*this.axisy);else{let t=e.polygon,n=t.lverts.next,s=t.gverts.next;for(;s!=null;){let p=s,c=n;n=n.next,p.x=this.posx+(this.axisy*c.x-this.axisx*c.y),p.y=this.posy+(c.x*this.axisx+c.y*this.axisy),s=s.next}let i=t.edges.head,l=t.gverts.next,o=l;for(l=l.next;l!=null;){let p=l,c=i.elt;i=i.next,c.gnormx=this.axisy*c.lnormx-this.axisx*c.lnormy,c.gnormy=c.lnormx*this.axisx+c.lnormy*this.axisy,c.gprojection=this.posx*c.gnormx+this.posy*c.gnormy+c.lprojection,c.tp0=o.y*c.gnormx-o.x*c.gnormy,c.tp1=p.y*c.gnormx-p.x*c.gnormy,o=p,l=l.next}let r=t.gverts.next,a=i.elt;a.gnormx=this.axisy*a.lnormx-this.axisx*a.lnormy,a.gnormy=a.lnormx*this.axisx+a.lnormy*this.axisy,a.gprojection=this.posx*a.gnormx+this.posy*a.gnormy+a.lprojection,a.tp0=o.y*a.gnormx-o.x*a.gnormy,a.tp1=r.y*a.gnormx-r.x*a.gnormy}}invalidate_pos(){let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}pos_invalidate(e){if(this.immutable_midstep("Body::position"),this.type===1&&this.space!=null)throw new Error("Error: Cannot move a static object once inside a Space");this.posx===e.x&&this.posy===e.y||(this.posx=e.x,this.posy=e.y,this.invalidate_pos(),this.wake())}pos_validate(){this.wrap_pos.zpp_inner.x=this.posx,this.wrap_pos.zpp_inner.y=this.posy}vel_invalidate(e){if(this.type===1)throw new Error("Error: Static body cannot have its velocity set.");this.velx=e.x,this.vely=e.y,this.wake()}vel_validate(){this.wrap_vel.zpp_inner.x=this.velx,this.wrap_vel.zpp_inner.y=this.vely}kinvel_invalidate(e){this.kinvelx=e.x,this.kinvely=e.y,this.wake()}kinvel_validate(){this.wrap_kinvel.zpp_inner.x=this.kinvelx,this.wrap_kinvel.zpp_inner.y=this.kinvely}svel_invalidate(e){this.svelx=e.x,this.svely=e.y,this.wake()}svel_validate(){this.wrap_svel.zpp_inner.x=this.svelx,this.wrap_svel.zpp_inner.y=this.svely}force_invalidate(e){if(this.type!==2)throw new Error("Error: Non-dynamic body cannot have force applied.");this.forcex=e.x,this.forcey=e.y,this.wake()}force_validate(){this.wrap_force.zpp_inner.x=this.forcex,this.wrap_force.zpp_inner.y=this.forcey}_setupVec2Wrapper(e,t,n,s){let i=je._nape;if(e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let l;if(xe.poolVec2==null?l=new i.geom.Vec2:(l=xe.poolVec2,xe.poolVec2=l.zpp_pool,l.zpp_pool=null,l.zpp_disp=!1,l===xe.nextVec2&&(xe.nextVec2=null)),l.zpp_inner==null){let o;pe.zpp_pool==null?o=new pe:(o=pe.zpp_pool,pe.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=e,o.y=t,l.zpp_inner=o,l.zpp_inner.outer=l}else{if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=l.zpp_inner;if(o._immutable)throw new Error("Error: Vec2 is immutable");if(o._isimmutable!=null&&o._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let r;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x===e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),r=l.zpp_inner.y===t):r=!1,r||(l.zpp_inner.x=e,l.zpp_inner.y=t,l.zpp_inner._invalidate!=null&&l.zpp_inner._invalidate(l.zpp_inner))}return l.zpp_inner.weak=!1,l}setupPosition(){this.wrap_pos=this._setupVec2Wrapper(this.posx,this.posy,null,null),this.wrap_pos.zpp_inner._inuse=!0,this.world?this.wrap_pos.zpp_inner._immutable=!0:(this.wrap_pos.zpp_inner._invalidate=this.pos_invalidate.bind(this),this.wrap_pos.zpp_inner._validate=this.pos_validate.bind(this))}setupVelocity(){this.wrap_vel=this._setupVec2Wrapper(this.velx,this.vely,null,null),this.wrap_vel.zpp_inner._inuse=!0,this.world?this.wrap_vel.zpp_inner._immutable=!0:(this.wrap_vel.zpp_inner._invalidate=this.vel_invalidate.bind(this),this.wrap_vel.zpp_inner._validate=this.vel_validate.bind(this))}setupkinvel(){this.wrap_kinvel=this._setupVec2Wrapper(this.kinvelx,this.kinvely,null,null),this.wrap_kinvel.zpp_inner._inuse=!0,this.world?this.wrap_kinvel.zpp_inner._immutable=!0:(this.wrap_kinvel.zpp_inner._invalidate=this.kinvel_invalidate.bind(this),this.wrap_kinvel.zpp_inner._validate=this.kinvel_validate.bind(this))}setupsvel(){this.wrap_svel=this._setupVec2Wrapper(this.svelx,this.svely,null,null),this.wrap_svel.zpp_inner._inuse=!0,this.world?this.wrap_svel.zpp_inner._immutable=!0:(this.wrap_svel.zpp_inner._invalidate=this.svel_invalidate.bind(this),this.wrap_svel.zpp_inner._validate=this.svel_validate.bind(this))}setupForce(){this.wrap_force=this._setupVec2Wrapper(this.forcex,this.forcey,null,null),this.wrap_force.zpp_inner._inuse=!0,this.world?this.wrap_force.zpp_inner._immutable=!0:(this.wrap_force.zpp_inner._invalidate=this.force_invalidate.bind(this),this.wrap_force.zpp_inner._validate=this.force_validate.bind(this))}cvel_validate(){this.wrapcvel.zpp_inner.x=this.velx+this.kinvelx,this.wrapcvel.zpp_inner.y=this.vely+this.kinvely}setup_cvel(){this.wrapcvel=this._setupVec2Wrapper(this.velx+this.kinvelx,this.vely+this.kinvely,null,null),this.wrapcvel.zpp_inner._inuse=!0,this.wrapcvel.zpp_inner._immutable=!0,this.wrapcvel.zpp_inner._validate=this.cvel_validate.bind(this)}invalidate_rot(){this.zip_axis=!0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0}validate_axis(){this.zip_axis&&(this.zip_axis=!1,this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}quick_validate_axis(){this.zip_axis&&(this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot))}delta_rot(e){if(e*e>1e-4)this.axisx=Math.sin(this.rot),this.axisy=Math.cos(this.rot);else{let t=e*e,n=1-.5*t,s=1-t*t/8,i=(n*this.axisx+e*this.axisy)*s;this.axisy=(n*this.axisy-e*this.axisx)*s,this.axisx=i}this.zip_axis=!1}invalidate_mass(){this.zip_mass=!0,this.invalidate_gravMass()}validate_mass(){if(this.zip_mass||this.massMode===0&&!1){if(this.zip_mass=!1,this.massMode===0){this.cmass=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cmass+=n.area*n.material.density,t=t.next}}this.type===2&&!this.nomove?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0)}}invalidate_gravMass(){this.gravMassMode!==1&&(this.zip_gravMass=!0),this.gravMassMode!==2&&(this.zip_gravMassScale=!0),this.wake()}validate_gravMass(){this.zip_gravMass&&(this.zip_gravMass=!1,this.validate_mass(),this.gravMassMode===0?(this.validate_mass(),this.gravMass=this.cmass):this.gravMassMode===2&&(this.validate_mass(),this.gravMass=this.cmass*this.gravMassScale))}invalidate_gravMassScale(){this.gravMassMode!==2?this.zip_gravMassScale=!0:this.invalidate_gravMass()}validate_gravMassScale(){this.zip_gravMassScale&&(this.zip_gravMassScale=!1,this.gravMassMode===0?this.gravMassScale=1:this.gravMassMode===1&&(this.validate_mass(),this.gravMassScale=this.gravMass/this.cmass))}invalidate_inertia(){this.zip_inertia=!0,this.wake()}validate_inertia(){if(this.zip_inertia||this.inertiaMode===0&&!1){if(this.zip_inertia=!1,this.inertiaMode===0){this.cinertia=0;let t=this.shapes.head;for(;t!=null;){let n=t.elt;n.refmaterial.density=n.material.density,n.validate_area_inertia(),this.cinertia+=n.inertia*n.area*n.material.density,t=t.next}}this.type===2&&!this.norotate?(this.inertia=this.cinertia,this.sinertia=this.iinertia=1/this.inertia):(this.inertia=1/0,this.sinertia=this.iinertia=0)}}invalidate_wake(){this.wake()}invalidate_aabb(){this.zip_aabb=!0}validate_aabb(){if(this.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(this.zip_aabb){this.zip_aabb=!1,this.aabb.minx=1/0,this.aabb.miny=1/0,this.aabb.maxx=-1/0,this.aabb.maxy=-1/0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.zip_aabb&&t.body!=null&&(t.zip_aabb=!1,t.type===0?this._validateCircleAABB(t.circle):this._validatePolygonAABB(t.polygon)),t.aabb.minx<this.aabb.minx&&(this.aabb.minx=t.aabb.minx),t.aabb.maxx>this.aabb.maxx&&(this.aabb.maxx=t.aabb.maxx),t.aabb.miny<this.aabb.miny&&(this.aabb.miny=t.aabb.miny),t.aabb.maxy>this.aabb.maxy&&(this.aabb.maxy=t.aabb.maxy),e=e.next}}}_validateCircleAABB(e){e.zip_worldCOM&&e.body!=null&&(e.zip_worldCOM=!1,e.zip_localCOM&&(e.zip_localCOM=!1,e.type===1&&this._computePolygonLocalCOM(e.polygon),e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)),this.validate_axis(),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy));let t=e.radius;e.aabb.minx=e.worldCOMx-t,e.aabb.miny=e.worldCOMy-t,e.aabb.maxx=e.worldCOMx+t,e.aabb.maxy=e.worldCOMy+t}_validatePolygonAABB(e){if(e.zip_gverts&&e.body!=null){e.zip_gverts=!1,e.validate_lverts(),this.validate_axis();let s=e.lverts.next,i=e.gverts.next;for(;i!=null;){let l=i,o=s;s=s.next,l.x=e.body.posx+(e.body.axisy*o.x-e.body.axisx*o.y),l.y=e.body.posy+(o.x*e.body.axisx+o.y*e.body.axisy),i=i.next}}if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let t=e.gverts.next;e.aabb.minx=t.x,e.aabb.miny=t.y,e.aabb.maxx=t.x,e.aabb.maxy=t.y;let n=e.gverts.next.next;for(;n!=null;){let s=n;s.x<e.aabb.minx&&(e.aabb.minx=s.x),s.x>e.aabb.maxx&&(e.aabb.maxx=s.x),s.y<e.aabb.miny&&(e.aabb.miny=s.y),s.y>e.aabb.maxy&&(e.aabb.maxy=s.y),n=n.next}}aabb_validate(){if(this.shapes.head==null)throw new Error("Error: bounds only makes sense when Body has shapes");this.validate_aabb()}invalidate_localCOM(){this.zip_localCOM=!0,this.zip_worldCOM=!0}invalidate_worldCOM(){this.zip_worldCOM=!0}_computePolygonLocalCOM(e){if(e.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(e.lverts.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y;else if(e.lverts.next.next.next==null)e.localCOMx=e.lverts.next.x,e.localCOMy=e.lverts.next.y,e.localCOMx+=e.lverts.next.next.x,e.localCOMy+=e.lverts.next.next.y,e.localCOMx*=.5,e.localCOMy*=.5;else{e.localCOMx=0,e.localCOMy=0;let t=0,n=e.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let p=n;t+=i.x*(p.y-s.y);let c=p.y*i.x-p.x*i.y;e.localCOMx+=(i.x+p.x)*c,e.localCOMy+=(i.y+p.y)*c,s=i,i=p,n=n.next}n=e.lverts.next;let l=n;t+=i.x*(l.y-s.y);let o=l.y*i.x-l.x*i.y;e.localCOMx+=(i.x+l.x)*o,e.localCOMy+=(i.y+l.y)*o,s=i,i=l,n=n.next;let r=n;t+=i.x*(r.y-s.y);let a=r.y*i.x-r.x*i.y;e.localCOMx+=(i.x+r.x)*a,e.localCOMy+=(i.y+r.y)*a,t=1/(3*t),e.localCOMx*=t,e.localCOMy*=t}}validate_localCOM(){if(this.zip_localCOM){this.zip_localCOM=!1;let e=0,t=0,n=0,s=this.shapes.head;for(;s!=null;){let i=s.elt;i.zip_localCOM&&(i.zip_localCOM=!1,i.type===1&&this._computePolygonLocalCOM(i.polygon),i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)),i.validate_area_inertia();let l=i.area*i.material.density;e+=i.localCOMx*l,t+=i.localCOMy*l,n+=i.area*i.material.density,s=s.next}if(n!==0){let i=1/n;this.localCOMx=e*i,this.localCOMy=t*i}this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy),this.zip_mass&&this.massMode===0&&(this.zip_mass=!1,this.cmass=n,this.type===2?(this.mass=this.cmass,this.imass=this.smass=1/this.mass):(this.mass=1/0,this.imass=this.smass=0))}}validate_worldCOM(){this.zip_worldCOM&&(this.zip_worldCOM=!1,this.validate_localCOM(),this.validate_axis(),this.worldCOMx=this.posx+(this.axisy*this.localCOMx-this.axisx*this.localCOMy),this.worldCOMy=this.posy+(this.localCOMx*this.axisx+this.localCOMy*this.axisy)),this.wrap_worldCOM!=null&&(this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy)}getlocalCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its localCOM");this.validate_localCOM()}getworldCOM(){if(this.shapes.head==null)throw new Error("Error: Body has no shapes so cannot compute its worldCOM");this.validate_worldCOM()}__immutable_midstep(){if(this.world)throw new Error("Error: Space::world is immutable")}clear(){if(this.space!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a Space!");if(this.constraints.head!=null)throw new Error("Error: Cannot clear a Body if it is currently being used by a constraint!");for(;this.shapes.head!=null;){let t=this.shapes.pop_unsafe();t.removedFromBody(),t.body=null}this.invalidate_shapes(),this.pre_posx=0,this.pre_posy=0,this.posx=0,this.posy=0,this.velx=0,this.vely=0,this.forcex=0,this.forcey=0,this.kinvelx=0,this.kinvely=0,this.svelx=0,this.svely=0,this.angvel=this.torque=this.kinangvel=this.pre_rot=this.rot=0;let e=this.shapes.head;for(;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}for(this.zip_worldCOM=!0,this.zip_axis=!0,e=this.shapes.head;e!=null;){let t=e.elt;t.type===1&&(t.polygon.invalidate_gverts(),t.polygon.invalidate_gaxi()),t.invalidate_worldCOM(),e=e.next}this.zip_worldCOM=!0,this.axisx=0,this.axisy=1,this.zip_axis=!1,this.massMode=0,this.gravMassMode=0,this.gravMassScale=1,this.inertiaMode=0,this.norotate=!1,this.nomove=!1}shapes_adder(e){if(e.zpp_inner.body!==this){if(e.zpp_inner.body!=null&&e.zpp_inner.body.wrap_shapes.remove(e),e.zpp_inner.body=this,e.zpp_inner.addedToBody(),this.space!=null){let t=this.space,n=e.zpp_inner,s=n.body;s.world||(s.component.waket=t.stamp+(t.midstep?0:1),s.type===3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&t.really_wake(s,!1)),t.bphase.insert(n),n.addedToSpace()}return e.zpp_inner.type===1&&(e.zpp_inner.polygon.invalidate_gaxi(),e.zpp_inner.polygon.invalidate_gverts()),!0}else return!1}shapes_subber(e){this.space!=null&&this.space.removed_shape(e.zpp_inner),e.zpp_inner.body=null,e.zpp_inner.removedFromBody()}shapes_invalidate(e){this.invalidate_shapes()}shapes_modifiable(){if(this.immutable_midstep("Body::shapes"),this.type===1&&this.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}addedToSpace(){let e=je._zpp,t;e.space.ZPP_Component.zpp_pool==null?t=new e.space.ZPP_Component:(t=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t.next,t.next=null),t.isBody=!0,t.body=this,this.component=t,this.__iaddedToSpace()}removedFromSpace(){let e=je._zpp;for(;this.arbiters.head!=null;){let n=this.arbiters.pop_unsafe(),s=this.space;n.cleared=!0,n.b2===this&&this._removeArbiterFromList(n.b1.arbiters,n,e),n.b1===this&&this._removeArbiterFromList(n.b2.arbiters,n,e),n.pair!=null&&(n.pair.arb=null,n.pair=null),n.active=!1,s.f_arbiters.modified=!0}let t=this.component;t.body=null,t.constraint=null,t.next=e.space.ZPP_Component.zpp_pool,e.space.ZPP_Component.zpp_pool=t,this.component=null,this.__iremovedFromSpace()}_removeArbiterFromList(e,t,n){let s=null,i=e.head;for(;i!=null;){if(i.elt===t){let l;s==null?(l=e.head,e.head=l.next,e.head==null&&(e.pushmod=!0)):(l=s.next,s.next=l.next,l.next==null&&(e.pushmod=!0));let o=l;o.elt=null,o.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=o,e.modified=!0,e.length--,e.pushmod=!0;break}s=i,i=i.next}}copy(){let e=je._nape,t=new e.phys.Body().zpp_inner;t.type=this.type,t.bulletEnabled=this.bulletEnabled,t.disableCCD=this.disableCCD;let n=this.shapes.head;for(;n!=null;){let s=n.elt,i=t.outer.zpp_inner.wrap_shapes,l=s.outer.copy();i.zpp_inner.reverse_flag?i.push(l):i.unshift(l),n=n.next}if(t.posx=this.posx,t.posy=this.posy,t.velx=this.velx,t.vely=this.vely,t.forcex=this.forcex,t.forcey=this.forcey,t.rot=this.rot,t.angvel=this.angvel,t.torque=this.torque,t.kinvelx=this.kinvelx,t.kinvely=this.kinvely,t.kinangvel=this.kinangvel,t.svelx=this.svelx,t.svely=this.svely,!this.zip_axis)t.axisx=this.axisx,t.axisy=this.axisy;else{t.zip_axis=!0;let s=t.shapes.head;for(;s!=null;){let i=s.elt;i.type===1&&(i.polygon.invalidate_gverts(),i.polygon.invalidate_gaxi()),i.invalidate_worldCOM(),s=s.next}t.zip_worldCOM=!0}return t.rot=this.rot,t.massMode=this.massMode,t.gravMassMode=this.gravMassMode,t.inertiaMode=this.inertiaMode,t.norotate=this.norotate,t.nomove=this.nomove,t.cmass=this.cmass,t.cinertia=this.cinertia,this.zip_mass?t.invalidate_mass():t.mass=this.mass,this.zip_gravMass?t.invalidate_gravMass():t.gravMass=this.gravMass,this.zip_gravMassScale?t.invalidate_gravMassScale():t.gravMassScale=this.gravMassScale,this.zip_inertia?t.invalidate_inertia():t.inertia=this.inertia,this.zip_aabb?t.zip_aabb=!0:(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy),this.zip_localCOM?(t.zip_localCOM=!0,t.zip_worldCOM=!0):(t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy),this.zip_worldCOM?t.zip_worldCOM=!0:(t.worldCOMx=this.worldCOMx,t.worldCOMy=this.worldCOMy),this.copyto(t.outer),t.outer}static _init(e,t){if(!je._initialized){je._initialized=!0,je._zpp=e,je._nape=t;for(let n of Object.getOwnPropertyNames(Ut.prototype))n!=="constructor"&&!(n in je.prototype)&&(je.prototype[n]=Ut.prototype[n])}}static _initEnums(e,t){let n=()=>{t.internal=!0;let s=new e.phys.BodyType;return t.internal=!1,s};t.BodyType_STATIC==null&&(t.BodyType_STATIC=n()),t.BodyType_DYNAMIC==null&&(t.BodyType_DYNAMIC=n()),t.BodyType_KINEMATIC==null&&(t.BodyType_KINEMATIC=n()),je.types=[null,t.BodyType_STATIC,t.BodyType_DYNAMIC,t.BodyType_KINEMATIC]}};je._nape=null,je._zpp=null,je.types=[],je.bodystack=null,je.bodyset=null,je.cur_graph_depth=0,je._initialized=!1;var Cn=je;var en=class en{constructor(){this.outer_i=null;this.id=0;this.userData=null;this.ishape=null;this.ibody=null;this.icompound=null;this.wrap_cbTypes=null;this.cbSet=null;this.cbTypes=null;this.group=null;this.cbsets=null;this.outer=null;this.bodies=null;this.constraints=null;this.compounds=null;this.wrap_bodies=null;this.wrap_constraints=null;this.wrap_compounds=null;this.depth=0;this.compound=null;this.space=null;let e=en._zpp;Ut.initFields(this),this.icompound=this,this.depth=1,this.bodies=new e.util.ZNPList_ZPP_Body,this.wrap_bodies=e.util.ZPP_BodyList.get(this.bodies),this.wrap_bodies.zpp_inner.adder=this.bodies_adder.bind(this),this.wrap_bodies.zpp_inner.subber=this.bodies_subber.bind(this),this.wrap_bodies.zpp_inner._modifiable=this.bodies_modifiable.bind(this),this.constraints=new e.util.ZNPList_ZPP_Constraint,this.wrap_constraints=e.util.ZPP_ConstraintList.get(this.constraints),this.wrap_constraints.zpp_inner.adder=this.constraints_adder.bind(this),this.wrap_constraints.zpp_inner.subber=this.constraints_subber.bind(this),this.wrap_constraints.zpp_inner._modifiable=this.constraints_modifiable.bind(this),this.compounds=new e.util.ZNPList_ZPP_Compound,this.wrap_compounds=e.util.ZPP_CompoundList.get(this.compounds),this.wrap_compounds.zpp_inner.adder=this.compounds_adder.bind(this),this.wrap_compounds.zpp_inner.subber=this.compounds_subber.bind(this),this.wrap_compounds.zpp_inner._modifiable=this.compounds_modifiable.bind(this)}__imutable_midstep(e){if(this.space!=null&&this.space.midstep)throw new Error("Error: "+e+" cannot be set during space step()")}addedToSpace(){this.__iaddedToSpace()}removedFromSpace(){this.__iremovedFromSpace()}breakApart(){for(this.space!=null&&(this.__iremovedFromSpace(),this.space.nullInteractorType(this)),this.compound!=null?this.compound.compounds.remove(this):this.space!=null&&this.space.compounds.remove(this);this.bodies.head!=null;){let e=this.bodies.pop_unsafe();(e.compound=this.compound)!=null?this.compound.bodies.add(e):this.space!=null&&this.space.bodies.add(e),this.space!=null&&this.space.freshInteractorType(e)}for(;this.constraints.head!=null;){let e=this.constraints.pop_unsafe();(e.compound=this.compound)!=null?this.compound.constraints.add(e):this.space!=null&&this.space.constraints.add(e)}for(;this.compounds.head!=null;){let e=this.compounds.pop_unsafe();(e.compound=this.compound)!=null?this.compound.compounds.add(e):this.space!=null&&this.space.compounds.add(e),this.space!=null&&this.space.freshInteractorType(e)}this.compound=null,this.space=null}static _zppOf(e){return e.zpp_inner??e._inner?.zpp_inner??e._inner}bodies_adder(e){let t=en._zppOf(e);return t.compound!==this?(t.compound!=null?t.compound.wrap_bodies.remove(e):t.space!=null&&t.space.wrap_bodies.remove(e),t.compound=this,this.space!=null&&this.space.addBody(t),!0):!1}bodies_subber(e){let t=en._zppOf(e);t.compound=null,this.space!=null&&this.space.remBody(t)}bodies_modifiable(){this.immutable_midstep("Compound::bodies")}constraints_adder(e){let t=en._zppOf(e);return t.compound!==this?(t.compound!=null?t.compound.wrap_constraints.remove(e):t.space!=null&&t.space.wrap_constraints.remove(e),t.compound=this,this.space!=null&&this.space.addConstraint(t),!0):!1}constraints_subber(e){let t=en._zppOf(e);t.compound=null,this.space!=null&&this.space.remConstraint(t)}constraints_modifiable(){this.immutable_midstep("Compound::constraints")}compounds_adder(e){let t=en._zppOf(e),n=this;for(;n!=null&&n!==t;)n=n.compound;if(n===t)throw new Error("Error: Assignment would cause a cycle in the Compound tree: assigning "+e.toString()+".compound = "+this.outer.toString());return t.compound!==this?(t.compound!=null?t.compound.wrap_compounds.remove(e):t.space!=null&&t.space.wrap_compounds.remove(e),t.compound=this,t.depth=this.depth+1,this.space!=null&&this.space.addCompound(t),!0):!1}compounds_subber(e){let t=en._zppOf(e);t.compound=null,t.depth=1,this.space!=null&&this.space.remCompound(t)}compounds_modifiable(){this.immutable_midstep("Compound::compounds")}copy(e,t){let n=en._nape,s=en._zpp,i=e==null;e==null&&(e=[]),t==null&&(t=[]);let l=new n.phys.Compound,o=this.compounds.head;for(;o!=null;){let c=o.elt.copy(e,t);if(c.zpp_inner.immutable_midstep("Compound::compound"),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_compounds.remove(c),l!=null)){let h=l.zpp_inner.wrap_compounds;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c)}o=o.next}let r=this.bodies.head;for(;r!=null;){let p=r.elt,c=p.outer.copy();if(e.push(s.constraint.ZPP_CopyHelper.dict(p.id,c)),(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_bodies.remove(c),l!=null)){let h=l.zpp_inner.wrap_bodies;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c)}r=r.next}let a=this.constraints.head;for(;a!=null;){let c=a.elt.copy(e,t);if((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!==l&&((c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer)!=null&&(c.zpp_inner.compound==null?null:c.zpp_inner.compound.outer).zpp_inner.wrap_constraints.remove(c),l!=null)){let h=l.zpp_inner.wrap_constraints;h.zpp_inner.reverse_flag?h.push(c):h.unshift(c)}a=a.next}if(i)for(;t.length>0;){let p=t.pop();for(let c=0;c<e.length;c++){let h=e[c];if(h.id===p.id){p.cb(h.bc);break}}}return this.copyto(l),l}static _init(){for(let e of Object.getOwnPropertyNames(Ut.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(en.prototype,e)&&(en.prototype[e]=Ut.prototype[e])}};en._nape=null,en._zpp=null,en._wrapFn=null;var qn=en;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=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else{if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let o=!1;l._validate!=null&&l._validate(),(l.x!==n||l.y!==s)&&(o=!0),o&&(l.x=n,l.y=s,l._invalidate!=null&&l._invalidate(l))}i.zpp_inner.weak=!1,this.wrap_gravity=i,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=this.gravity_invalidate.bind(this),this.wrap_gravity.zpp_inner._validate=this.gravity_validate.bind(this)}invalidate(){let e=this.shapes.head;for(;e!=null;)e.elt.invalidate_fluidprops(),e=e.next}};jt.zpp_pool=null,jt._nape=null,jt._zpp=null,jt._wrapFn=null;var Mn=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 Zn=class Zn{constructor(e){this.outer=null;this.body=null;this.type=0;this.area=0;this.zip_area_inertia=!1;this.inertia=0;this.angDrag=0;this.zip_angDrag=!1;this.localCOMx=0;this.localCOMy=0;this.zip_localCOM=!1;this.worldCOMx=0;this.worldCOMy=0;this.zip_worldCOM=!1;this.wrap_localCOM=null;this.wrap_worldCOM=null;this.sweepRadius=0;this.zip_sweepRadius=!1;this.sweepCoef=0;this.circle=null;this.polygon=null;this.capsule=null;this.refmaterial=null;this.material=null;this.filter=null;this.fluidProperties=null;this.fluidEnabled=!1;this.sensorEnabled=!1;this.sweep=null;this.node=null;this.pairs=null;this.aabb=null;this.zip_aabb=!1;this.ishape=null;this.userData=null;e!==void 0&&this._initShape(e)}static _initEnums(e,t){let n=()=>{t.internal=!0;let s=new e.shape.ShapeType;return t.internal=!1,s};t.ShapeType_CIRCLE==null&&(t.ShapeType_CIRCLE=n()),t.ShapeType_POLYGON==null&&(t.ShapeType_POLYGON=n()),t.ShapeType_CAPSULE==null&&(t.ShapeType_CAPSULE=n()),Zn.types=[t.ShapeType_CIRCLE,t.ShapeType_POLYGON,t.ShapeType_CAPSULE]}_initShape(e){let t=Zn._zpp;Ut.initFields(this),this.pairs=new t.util.ZNPList_ZPP_AABBPair,this.ishape=this,this.type=e;let n;fe.zpp_pool==null?n=new fe:(n=fe.zpp_pool,fe.zpp_pool=n.next,n.next=null),n.minx=0,n.miny=0,n.maxx=0,n.maxy=0,this.aabb=n,this.aabb._immutable=!0,this.aabb._validate=this.aabb_validate.bind(this),this.zip_area_inertia=this.zip_angDrag=this.zip_localCOM=this.zip_sweepRadius=!0,this.localCOMx=0,this.localCOMy=0,this.worldCOMx=0,this.worldCOMy=0,this.fluidEnabled=!1,this.sensorEnabled=!1,this.fluidProperties=null,this.body=null,this.refmaterial=new Oe,this.sweepRadius=this.sweepCoef=0}static _init(){if(!Zn._initialized){Zn._initialized=!0;for(let e of Object.getOwnPropertyNames(Ut.prototype))e!=="constructor"&&!Object.prototype.hasOwnProperty.call(Zn.prototype,e)&&(Zn.prototype[e]=Ut.prototype[e])}}isCircle(){return this.type===0}isPolygon(){return this.type===1}isCapsule(){return this.type===2}invalidate_sweepRadius(){this.zip_sweepRadius=!0}validate_sweepRadius(){this.zip_sweepRadius&&(this.zip_sweepRadius=!1,this.type===0?this.circle.__validate_sweepRadius():this.type===1?this.polygon.__validate_sweepRadius():this.capsule.__validate_sweepRadius())}clear(){this.type===0?this.circle.__clear():this.type===1?this.polygon.__clear():this.capsule.__clear()}validate_aabb(){this.zip_aabb&&this.body!=null&&(this.zip_aabb=!1,this.type===0?this.circle.__validate_aabb():this.type===1?this.polygon.__validate_aabb():this.capsule.__validate_aabb())}force_validate_aabb(){this.type===0?this.circle._force_validate_aabb():this.type===1?this.polygon._force_validate_aabb():this.capsule._force_validate_aabb()}invalidate_aabb(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}validate_area_inertia(){this.zip_area_inertia&&(this.zip_area_inertia=!1,this.type===0?this.circle.__validate_area_inertia():this.type===1?this.polygon.__validate_area_inertia():this.capsule.__validate_area_inertia())}validate_angDrag(){(this.zip_angDrag||this.refmaterial.dynamicFriction!==this.material.dynamicFriction)&&(this.zip_angDrag=!1,this.refmaterial.dynamicFriction=this.material.dynamicFriction,this.type===0?this.circle.__validate_angDrag():this.type===1?this.polygon.__validate_angDrag():this.capsule.__validate_angDrag())}validate_localCOM(){this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy))}validate_worldCOM(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.validate_localCOM();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy)}}getworldCOM(){if(this.body==null)throw new Error("Error: worldCOM only makes sense when Shape belongs to a Body");this.validate_worldCOM(),this.wrap_worldCOM.zpp_inner.x=this.worldCOMx,this.wrap_worldCOM.zpp_inner.y=this.worldCOMy}invalidate_area_inertia(){this.zip_area_inertia=!0,this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia())}invalidate_angDrag(){this.zip_angDrag=!0}invalidate_localCOM(){this.zip_localCOM=!0,this.invalidate_area_inertia(),(this.type===0||this.type===2)&&(this.zip_sweepRadius=!0),this.invalidate_angDrag(),this.invalidate_worldCOM(),this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0)}invalidate_worldCOM(){this.zip_worldCOM=!0,this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}invalidate_material(e){(e&Oe.WAKE)!==0&&this.wake(),(e&Oe.ARBITERS)!==0&&this.body!=null&&this.body.refreshArbiters(),(e&Oe.PROPS)!==0&&this.body!=null&&(this.body.zip_localCOM=!0,this.body.zip_worldCOM=!0,this.body.invalidate_mass(),this.body.invalidate_inertia()),(e&Oe.ANGDRAG)!==0&&this.invalidate_angDrag(),this.refmaterial.set(this.material)}invalidate_filter(){this.wake()}invalidate_fluidprops(){this.fluidEnabled&&this.wake()}aabb_validate(){if(this.body==null)throw new Error("Error: bounds only makes sense when Shape belongs to a Body");this.validate_aabb()}setMaterial(e){this.material!==e&&(this.body!=null&&this.body.space!=null&&this.material!=null&&this.material.shapes.remove(this),this.material=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake(),this.body!=null&&this.body.refreshArbiters())}setFilter(e){this.filter!==e&&(this.body!=null&&this.body.space!=null&&this.filter!=null&&this.filter.shapes.remove(this),this.filter=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.wake())}setFluid(e){this.fluidProperties!==e&&(this.body!=null&&this.body.space!=null&&this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this),this.fluidProperties=e,this.body!=null&&this.body.space!=null&&e.shapes.add(this),this.fluidEnabled&&this.wake())}__immutable_midstep(e){if(this.body!=null&&this.body.space!=null&&this.body.space.midstep)throw new Error("Error: "+e+" cannot be set during a space step()")}addedToBody(){this.invalidate_worldCOM(),this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0)}removedFromBody(){}addedToSpace(){this.__iaddedToSpace(),this.material.shapes.add(this),this.filter.shapes.add(this),this.fluidProperties!=null&&this.fluidProperties.shapes.add(this)}removedFromSpace(){this.__iremovedFromSpace(),this.material.shapes.remove(this),this.filter.shapes.remove(this),this.fluidProperties!=null&&this.fluidProperties.shapes.remove(this)}copy(){let e=Zn._zpp,t=this.type===0?this.circle.__copy():this.type===1?this.polygon.__copy():this.capsule.__copy();this.zip_area_inertia?t.invalidate_area_inertia():(t.area=this.area,t.inertia=this.inertia),this.zip_sweepRadius?t.zip_sweepRadius=!0:(t.sweepRadius=this.sweepRadius,t.sweepCoef=this.sweepCoef),this.zip_angDrag?t.invalidate_angDrag():t.angDrag=this.angDrag,this.zip_aabb?(t.zip_aabb=!0,t.body!=null&&(t.body.zip_aabb=!0)):(t.aabb.minx=this.aabb.minx,t.aabb.miny=this.aabb.miny,t.aabb.maxx=this.aabb.maxx,t.aabb.maxy=this.aabb.maxy);let n=t.material;n.outer=null,n.next=Oe.zpp_pool,Oe.zpp_pool=n;let s=t.filter;return s.outer=null,s.next=e.dynamics.ZPP_InteractionFilter.zpp_pool,e.dynamics.ZPP_InteractionFilter.zpp_pool=s,t.material=this.material,t.filter=this.filter,this.fluidProperties!=null&&(t.fluidProperties=this.fluidProperties),t.fluidEnabled=this.fluidEnabled,t.sensorEnabled=this.sensorEnabled,this.userData!=null&&(t.userData=Object.assign({},this.userData)),this.copyto(t.outer),t.outer}};Zn._nape=null,Zn._zpp=null,Zn.types=[],Zn._initialized=!1;var ri=Zn;var kn=class kn{constructor(){this.radius=0;this.outer_zn=null;this.radius=0,this.outer_zn=null,this._initShape(0),this.circle=this,this.zip_localCOM=!1}static _init(){if(kn._initialized)return;kn._initialized=!0;let t=kn._zpp.shape.ZPP_Shape.prototype,n=kn.prototype;for(let s in t)Object.prototype.hasOwnProperty.call(n,s)||(n[s]=t[s]);for(let s of Object.getOwnPropertyNames(t))s!=="constructor"&&!Object.prototype.hasOwnProperty.call(n,s)&&(n[s]=t[s])}__clear(){}invalidate_radius(){this.invalidate_area_inertia(),this.invalidate_angDrag(),this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0),this.body!=null&&this.body.wake()}localCOM_validate(){this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy}localCOM_invalidate(e){this.localCOMx=e.x,this.localCOMy=e.y,this.invalidate_localCOM(),this.body!=null&&this.body.wake()}localCOM_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify localCOM of Circle added to a static Body whilst within a Space")}setupLocalCOM(){let e=kn._zpp,t=kn._nape,n=this.localCOMx,s=this.localCOMy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,this.wrap_localCOM=i,this.wrap_localCOM.zpp_inner._inuse=!0,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this),this.wrap_localCOM.zpp_inner._isimmutable=this.localCOM_immutable.bind(this)}__validate_aabb(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.zip_localCOM&&(this.zip_localCOM=!1,this.type===1&&this.polygon.__validate_localCOM(),this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy));let n=this.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),this.worldCOMx=n.posx+(n.axisy*this.localCOMx-n.axisx*this.localCOMy),this.worldCOMy=n.posy+(this.localCOMx*n.axisx+this.localCOMy*n.axisy)}let e=this.radius,t=this.radius;this.aabb.minx=this.worldCOMx-e,this.aabb.miny=this.worldCOMy-t,this.aabb.maxx=this.worldCOMx+e,this.aabb.maxy=this.worldCOMy+t}_force_validate_aabb(){let e=this.body;this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy),this.aabb.minx=this.worldCOMx-this.radius,this.aabb.miny=this.worldCOMy-this.radius,this.aabb.maxx=this.worldCOMx+this.radius,this.aabb.maxy=this.worldCOMy+this.radius}__validate_sweepRadius(){this.sweepCoef=Math.sqrt(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy),this.sweepRadius=this.sweepCoef+this.radius}__validate_area_inertia(){let e=this.radius*this.radius;this.area=e*Math.PI,this.inertia=e*.5+(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy)}__validate_angDrag(){let e=kn._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=kn._nape,t=new e.shape.Circle(this.radius).zpp_inner_zn;return t.localCOMx=this.localCOMx,t.localCOMy=this.localCOMy,t.zip_localCOM=!1,t}};kn._nape=null,kn._zpp=null,kn._initialized=!1;var Xn=kn;var tn=class tn{constructor(){this.next=null;this.polygon=null;this.outer=null;this.lnormx=0;this.lnormy=0;this.wrap_lnorm=null;this.gnormx=0;this.gnormy=0;this.wrap_gnorm=null;this.length=0;this.lprojection=0;this.gprojection=0;this.lp0=null;this.gp0=null;this.lp1=null;this.gp1=null;this.tp0=0;this.tp1=0;this.lnormx=0,this.lnormy=0,this.gnormx=0,this.gnormy=0,this.length=0,this.lprojection=0,this.gprojection=0}free(){this.polygon=null}alloc(){}wrapper(){return this.outer==null&&(tn._wrapFn?this.outer=tn._wrapFn(this):(tn.internal=!0,this.outer=new tn._nape.shape.Edge,tn.internal=!1,this.outer.zpp_inner=this)),this.outer}lnorm_validate(){if(this.polygon==null)throw new Error("Error: Edge not currently in use");this.polygon.validate_laxi(),this.wrap_lnorm.zpp_inner.x=this.lnormx,this.wrap_lnorm.zpp_inner.y=this.lnormy}gnorm_validate(){if(this.polygon==null)throw new Error("Error: Edge not currently in use");if(this.polygon.body==null)throw new Error("Error: Edge worldNormal only makes sense if the parent Polygon is contained within a rigid body");this.polygon.validate_gaxi(),this.wrap_gnorm.zpp_inner.x=this.gnormx,this.wrap_gnorm.zpp_inner.y=this.gnormy}getlnorm(){let e=tn._zpp,t=tn._nape,n=this.lnormx,s=this.lnormy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,this.wrap_lnorm=i,this.wrap_lnorm.zpp_inner._immutable=!0,this.wrap_lnorm.zpp_inner._validate=this.lnorm_validate.bind(this)}getgnorm(){let e=tn._zpp,t=tn._nape,n=this.gnormx,s=this.gnormy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,this.wrap_gnorm=i,this.wrap_gnorm.zpp_inner._immutable=!0,this.wrap_gnorm.zpp_inner._validate=this.gnorm_validate.bind(this)}};tn.zpp_pool=null,tn.internal=!1,tn._nape=null,tn._zpp=null,tn._wrapFn=null;var rt=tn;var mt=class mt{constructor(){this.outer_zn=null;this.lverts=null;this.wrap_lverts=null;this.gverts=null;this.wrap_gverts=null;this.edges=null;this.wrap_edges=null;this.edgeCnt=0;this.reverse_flag=!1;this.zip_lverts=!1;this.zip_laxi=!1;this.zip_gverts=!1;this.zip_gaxi=!1;this.zip_valid=!1;this.zip_sanitation=!1;this.validation=null;this.zip_sanitation=!1,this.zip_valid=!1,this.zip_gaxi=!1,this.zip_gverts=!1,this.zip_laxi=!1,this.zip_lverts=!1,this.reverse_flag=!1,this.edgeCnt=0,this.wrap_edges=null,this.edges=null,this.wrap_gverts=null,this.gverts=null,this.wrap_lverts=null,this.lverts=null,this.outer_zn=null;let e=mt._zpp;this._initShape(1),this.polygon=this,this.lverts=new e.geom.ZPP_Vec2,this.gverts=new e.geom.ZPP_Vec2,this.edges=new e.util.ZNPList_ZPP_Edge,this.edgeCnt=0}static _init(){if(mt._initialized)return;mt._initialized=!0;let t=mt._zpp.shape.ZPP_Shape.prototype,n=mt.prototype;for(let s in t)Object.prototype.hasOwnProperty.call(n,s)||(n[s]=t[s]);for(let s of Object.getOwnPropertyNames(t))s!=="constructor"&&!Object.prototype.hasOwnProperty.call(n,s)&&(n[s]=t[s])}__clear(){}lverts_pa_invalidate(e){this.invalidate_lverts()}lverts_pa_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify local vertex of Polygon added to a static body whilst within a Space")}gverts_pa_validate(){if(this.body==null)throw new Error("Error: World vertex only makes sense when Polygon is contained in a rigid body");this._validateGverts()}lverts_post_adder(e){let t=mt._zpp;e.zpp_inner._invalidate=this.lverts_pa_invalidate.bind(this),e.zpp_inner._isimmutable=this.lverts_pa_immutable.bind(this);let n=null,s=null,i=this.lverts.next;for(;i!=null&&i!==e.zpp_inner;)n=n==null?this.gverts.next:n.next,s=s==null?this.edges.head:s.next,i=i.next;let l;if(t.geom.ZPP_Vec2.zpp_pool==null?l=new t.geom.ZPP_Vec2:(l=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!0,l.x=0,l.y=0,this.gverts.insert(n,l),this.lverts.next.next!=null)if(this.lverts.next.next.next==null){let o;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);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),this.edgeCnt+=2}else{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.insert(s,o),this.edgeCnt++}l._validate=this.gverts_pa_validate.bind(this)}lverts_subber(e){this.cleanup_lvert(e.zpp_inner)}lverts_invalidate(e){this.invalidate_lverts()}lverts_validate(){this.validate_lverts()}lverts_modifiable(){if(this.immutable_midstep("Polygon::localVerts"),this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modifiy shapes of static object once added to Space")}gverts_validate(){this._validateGverts()}edges_validate(){this.validate_lverts()}getlverts(){let e=mt._zpp;this.wrap_lverts=e.util.ZPP_MixVec2List.get(this.lverts),this.wrap_lverts.zpp_inner.post_adder=this.lverts_post_adder.bind(this),this.wrap_lverts.zpp_inner.subber=this.lverts_subber.bind(this),this.wrap_lverts.zpp_inner._invalidate=this.lverts_invalidate.bind(this),this.wrap_lverts.zpp_inner._validate=this.lverts_validate.bind(this),this.wrap_lverts.zpp_inner._modifiable=this.lverts_modifiable.bind(this),this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag}getgverts(){let e=mt._zpp;this.wrap_gverts=e.util.ZPP_MixVec2List.get(this.gverts,!0),this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag,this.wrap_gverts.zpp_inner._validate=this.gverts_validate.bind(this)}getedges(){let e=mt._zpp;this.wrap_edges=e.util.ZPP_EdgeList.get(this.edges,!0),this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag,this.wrap_edges.zpp_inner._validate=this.edges_validate.bind(this)}invalidate_lverts(){this.invalidate_laxi(),this.invalidate_area_inertia(),this.invalidate_angDrag(),this.invalidate_localCOM(),this.invalidate_gverts(),this.zip_lverts=!0,this.zip_valid=!0,this.zip_sanitation=!0,this.body!=null&&this.body.wake()}invalidate_laxi(){this.invalidate_gaxi(),this.zip_sweepRadius=!0,this.zip_laxi=!0}invalidate_gverts(){this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0),this.zip_gverts=!0}invalidate_gaxi(){this.zip_gaxi=!0}validate_lverts(){this.zip_lverts&&(this.zip_lverts=!1,this.lverts.length>2&&(this.validate_area_inertia(),this.area<0&&(this.reverse_vertices(),this.area=-this.area)))}validate_laxi(){if(this.zip_laxi){this.zip_laxi=!1,this.validate_lverts();let t=this.edges.head,n=this.lverts.next,s=n;for(n=n.next;n!=null;){let h=n,u=t.elt;t=t.next,u.lp0=s,u.lp1=h;let x=s.x-h.x,m=s.y-h.y,_=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 o=s.x-i.x,r=s.y-i.y,a=Math.sqrt(o*o+r*r);l.length=a;let p=1/a;o*=p,r*=p;let c=o;o=-r,r=c,l.lprojection=o*s.x+r*s.y,l.lnormx=o,l.lnormy=r,l.wrap_lnorm!=null&&(l.wrap_lnorm.zpp_inner.x=o,l.wrap_lnorm.zpp_inner.y=r)}}validate_gverts(){this._validateGverts()}validate_gaxi(){if(this.zip_gaxi&&this.body!=null){this.zip_gaxi=!1,this.validate_laxi();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot)),this._validateGverts();let t=this.edges.head,n=this.gverts.next,s=n;for(n=n.next;n!=null;){let o=n,r=t.elt;t=t.next,r.gp0=s,r.gp1=o,r.gnormx=e.axisy*r.lnormx-e.axisx*r.lnormy,r.gnormy=r.lnormx*e.axisx+r.lnormy*e.axisy,r.gprojection=e.posx*r.gnormx+e.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy,s=o,n=n.next}let i=this.gverts.next,l=t.elt;l.gp0=s,l.gp1=i,l.gnormx=e.axisy*l.lnormx-e.axisx*l.lnormy,l.gnormy=l.lnormx*e.axisx+l.lnormy*e.axisy,l.gprojection=e.posx*l.gnormx+e.posy*l.gnormy+l.lprojection,l.wrap_gnorm!=null&&(l.wrap_gnorm.zpp_inner.x=l.gnormx,l.wrap_gnorm.zpp_inner.y=l.gnormy),l.tp0=l.gp0.y*l.gnormx-l.gp0.x*l.gnormy,l.tp1=l.gp1.y*l.gnormx-l.gp1.x*l.gnormy}}_validateGverts(){if(this.zip_gverts&&this.body!=null){this.zip_gverts=!1,this.validate_lverts();let e=this.body;e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let t=this.lverts.next,n=this.gverts.next;for(;n!=null;){let s=n,i=t;t=t.next,s.x=e.posx+(e.axisy*i.x-e.axisx*i.y),s.y=e.posy+(i.x*e.axisx+i.y*e.axisy),n=n.next}}}cleanup_lvert(e){let t=mt._zpp,n=null,s=null,i=this.lverts.next;for(;i!=null&&i!==e;)n=n==null?this.gverts.next:n.next,s=s==null?this.edges.head:s.next,i=i.next;let l=n==null?this.gverts.next:n.next;this.gverts.erase(n);let o=l;if(o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=o,this.edgeCnt===2){let r=this.edges.pop_unsafe();r.polygon=null,r.next=rt.zpp_pool,rt.zpp_pool=r,r=this.edges.pop_unsafe(),r.polygon=null,r.next=rt.zpp_pool,rt.zpp_pool=r,this.edgeCnt=0}else if(this.edgeCnt!==0){let r=s==null?this.edges.head.elt:s.next.elt;this.edges.erase(s),r.polygon=null,r.next=rt.zpp_pool,rt.zpp_pool=r,this.edgeCnt--}}splice_collinear(){this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real())}splice_collinear_real(){let e=mt._nape;if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)return;let t=null,n=this.lverts.next;for(;n!=null;){let i=n.next==null?this.lverts.next:n.next,l=n.x-i.x,o=n.y-i.y;l*l+o*o<e.Config.epsilon*e.Config.epsilon?(this.cleanup_lvert(n),n=this.lverts.erase(t)):(t=n,n=n.next)}if(this.lverts.next==null)return;let s;for(;;){s=!1;let i=this.lverts.next;for(;i!=null;){let l=i.next==null?this.lverts.next:i.next,o=l.next==null?this.lverts.next:l.next,r=l.x-i.x,a=l.y-i.y,p=o.x-l.x,h=(o.y-l.y)*r-p*a;h*h>=e.Config.epsilon*e.Config.epsilon||(this.cleanup_lvert(l),this.lverts.erase(i.next==null?null:i),s=!0),i=i.next}if(!s)break}}reverse_vertices(){this.lverts.reverse(),this.gverts.reverse(),this.edges.reverse();let e=this.edges.iterator_at(this.edgeCnt-1),t=this.edges.pop_unsafe();this.edges.insert(e,t),this.reverse_flag=!this.reverse_flag,this.wrap_lverts!=null&&(this.wrap_lverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_gverts!=null&&(this.wrap_gverts.zpp_inner.reverse_flag=this.reverse_flag),this.wrap_edges!=null&&(this.wrap_edges.zpp_inner.reverse_flag=this.reverse_flag)}valid(){let e=mt._nape,t=mt._zpp;if(this.zip_valid){if(this.zip_valid=!1,this.zip_sanitation&&(this.zip_sanitation=!1,this.splice_collinear_real()),this.lverts.length<3)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;if(this.validate_lverts(),this.validate_area_inertia(),this.area<e.Config.epsilon)return t.util.ZPP_Flags.ValidationResult_DEGENERATE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_DEGENERATE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_DEGENERATE;{let n=!1,s=!1,i=!0,l=this.lverts.next,o=l;l=l.next;let r=l;for(l=l.next;l!=null;){let a=l,p=a.x-r.x,c=a.y-r.y,h=r.x-o.x,x=(r.y-o.y)*p-h*c;if(x>e.Config.epsilon?s=!0:x<-e.Config.epsilon&&(n=!0),s&&n){i=!1;break}o=r,r=a,l=l.next}if(i){l=this.lverts.next;let a=l,p=a.x-r.x,c=a.y-r.y,h=r.x-o.x,x=(r.y-o.y)*p-h*c;if(x>e.Config.epsilon?s=!0:x<-e.Config.epsilon&&(n=!0),!(s&&n)){o=r,r=a,l=l.next;let m=l,_=m.x-r.x,y=m.y-r.y,z=r.x-o.x,w=(r.y-o.y)*_-z*y;w>e.Config.epsilon?s=!0:w<-e.Config.epsilon&&(n=!0)}}if(s&&n)return t.util.ZPP_Flags.ValidationResult_CONCAVE==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_CONCAVE=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_CONCAVE;{let a=!0,p=this.lverts.next,c=p;for(p=p.next;p!=null&&a;){let h=p,u=this.lverts.next,x=u.next;for(;x!=null&&a;){let m=x;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,x=x.next}if(a){let m=this.lverts.next;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e))}c=h,p=p.next}if(a){let h=this.lverts.next,u=this.lverts.next,x=u.next;for(;x!=null&&a;){let m=x;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e)),u=m,x=x.next}if(a){let m=this.lverts.next;c!==u&&c!==m&&h!==u&&h!==m&&(a=this._checkNoIntersection(c,h,u,m,e))}}return a?(t.util.ZPP_Flags.ValidationResult_VALID==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_VALID=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_VALID):(t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING=new e.shape.ValidationResult,t.util.ZPP_Flags.internal=!1),this.validation=t.util.ZPP_Flags.ValidationResult_SELF_INTERSECTING)}}}else return this.validation}_checkNoIntersection(e,t,n,s,i){let l=e.x-n.x,o=e.y-n.y,r=t.x-e.x,a=t.y-e.y,p=s.x-n.x,c=s.y-n.y,h=a*p-r*c;if(h*h>i.Config.epsilon){h=1/h;let u=(c*l-p*o)*h;if(u>i.Config.epsilon&&u<1-i.Config.epsilon){let x=(a*l-r*o)*h;if(x>i.Config.epsilon&&x<1-i.Config.epsilon)return!1}}return!0}__validate_aabb(){if(this._validateGverts(),this.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let e=this.gverts.next;this.aabb.minx=e.x,this.aabb.miny=e.y,this.aabb.maxx=e.x,this.aabb.maxy=e.y;let t=this.gverts.next.next;for(;t!=null;){let n=t;n.x<this.aabb.minx&&(this.aabb.minx=n.x),n.x>this.aabb.maxx&&(this.aabb.maxx=n.x),n.y<this.aabb.miny&&(this.aabb.miny=n.y),n.y>this.aabb.maxy&&(this.aabb.maxy=n.y),t=t.next}}_force_validate_aabb(){let e=this.body,t=this.lverts.next,n=this.gverts.next,s=t;t=t.next,n.x=e.posx+(e.axisy*s.x-e.axisx*s.y),n.y=e.posy+(s.x*e.axisx+s.y*e.axisy),this.aabb.minx=n.x,this.aabb.miny=n.y,this.aabb.maxx=n.x,this.aabb.maxy=n.y;let i=this.gverts.next.next;for(;i!=null;){let l=i,o=t;t=t.next,l.x=e.posx+(e.axisy*o.x-e.axisx*o.y),l.y=e.posy+(o.x*e.axisx+o.y*e.axisy),l.x<this.aabb.minx&&(this.aabb.minx=l.x),l.x>this.aabb.maxx&&(this.aabb.maxx=l.x),l.y<this.aabb.miny&&(this.aabb.miny=l.y),l.y>this.aabb.maxy&&(this.aabb.maxy=l.y),i=i.next}}__validate_sweepRadius(){let e=0,t=0;this.validate_laxi();let n=this.lverts.next;for(;n!=null;){let i=n,l=i.x*i.x+i.y*i.y;l>e&&(e=l),n=n.next}let s=this.edges.head;for(;s!=null;){let i=s.elt;if(i.lprojection<t&&(t=i.lprojection,t<0))break;s=s.next}t<0&&(t=0),this.sweepRadius=Math.sqrt(e),this.sweepCoef=this.sweepRadius-t}__validate_area_inertia(){if(this.lverts.next==null||this.lverts.next.next==null||this.lverts.next.next.next==null)this.area=0,this.inertia=0;else{this.area=0;let e=0,t=0,n=this.lverts.next,s=n;n=n.next;let i=n;for(n=n.next;n!=null;){let p=n,c=i.y*s.x-i.x*s.y,h=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y);e+=c*h,t+=c,this.area+=i.x*(p.y-s.y),s=i,i=p,n=n.next}n=this.lverts.next;let l=n,o=i.y*s.x-i.x*s.y,r=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y);e+=o*r,t+=o,this.area+=i.x*(l.y-s.y),s=i,i=l,n=n.next;let a=n;o=i.y*s.x-i.x*s.y,r=i.x*i.x+i.y*i.y+(i.x*s.x+i.y*s.y)+(s.x*s.x+s.y*s.y),e+=o*r,t+=o,this.area+=i.x*(a.y-s.y),this.inertia=e/(6*t),this.area*=.5,this.area<0&&(this.area=-this.area,this.reverse_vertices())}}__validate_angDrag(){let e=mt._nape;if(this.lverts.length<3)throw new Error("Error: Polygon's with less than 3 vertices have no meaningful angDrag");this.validate_area_inertia(),this.validate_laxi();let t=0,n=this.edges.head,s=0,i=this.lverts.next,l=i,o=i.next;for(;o!=null;){let r=o,a=n.elt;n=n.next,s+=a.length;let p=r.x-l.x,c=r.y-l.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let h=-(l.y*a.lnormx-l.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(h>0){let u=h>1?1:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let _=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*r.x-a.lnormx*r.y,z=(y*y*y-_*_*_)/(3*(y-_));t+=z*e.Config.fluidVacuumDrag*(1-u)*a.length*e.Config.fluidAngularDrag}l=r,o=o.next}{let r=this.lverts.next,a=n.elt;s+=a.length;let p=r.x-l.x,c=r.y-l.y;t+=a.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*a.lprojection*a.lprojection;let h=-(l.y*a.lnormx-l.x*a.lnormy)/(c*a.lnormx-p*a.lnormy);if(h>0){let u=h>1?1:h,x=l.x,m=l.y;x+=p*u,m+=c*u;let _=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*r.x-a.lnormx*r.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 r=t;e+=s.x*(r.y-n.y);let a=r.y*s.x-r.x*s.y;this.localCOMx+=(s.x+r.x)*a,this.localCOMy+=(s.y+r.y)*a,n=s,s=r,t=t.next}t=this.lverts.next;let i=t;e+=s.x*(i.y-n.y);let l=i.y*s.x-i.x*s.y;this.localCOMx+=(s.x+i.x)*l,this.localCOMy+=(s.y+i.y)*l,n=s,s=i,t=t.next;let o=t;e+=s.x*(o.y-n.y),l=o.y*s.x-o.x*s.y,this.localCOMx+=(s.x+o.x)*l,this.localCOMy+=(s.y+o.y)*l,e=1/(3*e),this.localCOMx*=e,this.localCOMy*=e}}localCOM_validate(){if(this.lverts.next==null)throw new Error("Error: An empty polygon does not have any meaningful localCOM");this.validate_localCOM()}localCOM_invalidate(e){this.validate_localCOM();let t=e.x-this.localCOMx,n=e.y-this.localCOMy,s=this.lverts.next;for(;s!=null;)s.x+=t,s.y+=n,s=s.next;this.invalidate_lverts()}setupLocalCOM(){let e=mt._zpp,t=mt._nape,n=this.localCOMx,s=this.localCOMy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,this.wrap_localCOM=i,this.wrap_localCOM.zpp_inner._inuse=!0,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this)}__translate(e,t){let n=this.lverts.next;for(;n!=null;)n.x+=e,n.y+=t,n=n.next;this.invalidate_lverts()}__scale(e,t){let n=this.lverts.next;for(;n!=null;)n.x*=e,n.y*=t,n=n.next;this.invalidate_lverts()}__rotate(e,t){let n=this.lverts.next;for(;n!=null;){let s=t*n.x-e*n.y,i=n.x*e+n.y*t;n.x=s,n.y=i,n=n.next}this.invalidate_lverts()}__transform(e){let t=this.lverts.next;for(;t!=null;){let n=e.zpp_inner.a*t.x+e.zpp_inner.b*t.y+e.zpp_inner.tx;t.y=e.zpp_inner.c*t.x+e.zpp_inner.d*t.y+e.zpp_inner.ty,t.x=n,t=t.next}this.invalidate_lverts()}__copy(){let e=mt._nape;this.outer_zn.zpp_inner_zn.wrap_lverts==null&&this.outer_zn.zpp_inner_zn.getlverts();let t=this.outer_zn.zpp_inner_zn.wrap_lverts,n=[],s=t.iterator();for(;s.hasNext();)n.push(s.next());return new e.shape.Polygon(n).zpp_inner_zn}};mt._nape=null,mt._zpp=null,mt._initialized=!1;var Hn=mt;var En=class En{constructor(){this.radius=0;this.halfLength=0;this.outer_zn=null;this.spine1x=0;this.spine1y=0;this.spine2x=0;this.spine2y=0;this.radius=0,this.halfLength=0,this.outer_zn=null,this._initShape(2),this.capsule=this,this.zip_localCOM=!1}static _init(){if(En._initialized)return;En._initialized=!0;let t=En._zpp.shape.ZPP_Shape.prototype,n=En.prototype;for(let s in t)Object.prototype.hasOwnProperty.call(n,s)||(n[s]=t[s]);for(let s of Object.getOwnPropertyNames(t))s!=="constructor"&&!Object.prototype.hasOwnProperty.call(n,s)&&(n[s]=t[s])}__clear(){}invalidate_radius(){this.invalidate_area_inertia(),this.invalidate_angDrag(),this.zip_aabb=!0,this.body!=null&&(this.body.zip_aabb=!0,this.body.wake())}invalidate_halfLength(){this.invalidate_area_inertia(),this.invalidate_angDrag(),this.zip_aabb=!0,this.zip_sweepRadius=!0,this.body!=null&&(this.body.zip_aabb=!0,this.body.wake())}localCOM_validate(){this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy}localCOM_invalidate(e){this.localCOMx=e.x,this.localCOMy=e.y,this.invalidate_localCOM(),this.body!=null&&this.body.wake()}localCOM_immutable(){if(this.body!=null&&this.body.type===1&&this.body.space!=null)throw new Error("Error: Cannot modify localCOM of Capsule added to a static Body whilst within a Space")}setupLocalCOM(){let e=En._zpp,t=En._nape,n=this.localCOMx,s=this.localCOMy;if(n!==n||s!==s)throw new Error("Error: Vec2 components cannot be NaN");let i;if(e.util.ZPP_PubPool.poolVec2==null?i=new t.geom.Vec2:(i=e.util.ZPP_PubPool.poolVec2,e.util.ZPP_PubPool.poolVec2=i.zpp_pool,i.zpp_pool=null,i.zpp_disp=!1,i==e.util.ZPP_PubPool.nextVec2&&(e.util.ZPP_PubPool.nextVec2=null)),i.zpp_inner==null){let l;e.geom.ZPP_Vec2.zpp_pool==null?l=new e.geom.ZPP_Vec2:(l=e.geom.ZPP_Vec2.zpp_pool,e.geom.ZPP_Vec2.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,this.wrap_localCOM=i,this.wrap_localCOM.zpp_inner._inuse=!0,this.wrap_localCOM.zpp_inner._validate=this.localCOM_validate.bind(this),this.wrap_localCOM.zpp_inner._invalidate=this.localCOM_invalidate.bind(this),this.wrap_localCOM.zpp_inner._isimmutable=this.localCOM_immutable.bind(this)}__validate_aabb(){if(this.zip_worldCOM&&this.body!=null){this.zip_worldCOM=!1,this.zip_localCOM&&(this.zip_localCOM=!1,this.wrap_localCOM!=null&&(this.wrap_localCOM.zpp_inner.x=this.localCOMx,this.wrap_localCOM.zpp_inner.y=this.localCOMy));let c=this.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),this.worldCOMx=c.posx+(c.axisy*this.localCOMx-c.axisx*this.localCOMy),this.worldCOMy=c.posy+(this.localCOMx*c.axisx+this.localCOMy*c.axisy)}let e=this.body;if(e!=null){e.zip_axis&&(e.zip_axis=!1,e.axisx=Math.sin(e.rot),e.axisy=Math.cos(e.rot));let c=e.axisy*this.halfLength,h=e.axisx*this.halfLength;this.spine1x=this.worldCOMx-c,this.spine1y=this.worldCOMy-h,this.spine2x=this.worldCOMx+c,this.spine2y=this.worldCOMy+h}let t=this.radius,n=this.spine1x-t,s=this.spine2x-t,i=this.spine1y-t,l=this.spine2y-t,o=this.spine1x+t,r=this.spine2x+t,a=this.spine1y+t,p=this.spine2y+t;this.aabb.minx=n<s?n:s,this.aabb.miny=i<l?i:l,this.aabb.maxx=o>r?o:r,this.aabb.maxy=a>p?a:p}_force_validate_aabb(){let e=this.body;this.worldCOMx=e.posx+(e.axisy*this.localCOMx-e.axisx*this.localCOMy),this.worldCOMy=e.posy+(this.localCOMx*e.axisx+this.localCOMy*e.axisy);let t=e.axisy*this.halfLength,n=e.axisx*this.halfLength;this.spine1x=this.worldCOMx-t,this.spine1y=this.worldCOMy-n,this.spine2x=this.worldCOMx+t,this.spine2y=this.worldCOMy+n;let s=this.radius,i=this.spine1x-s,l=this.spine2x-s,o=this.spine1y-s,r=this.spine2y-s,a=this.spine1x+s,p=this.spine2x+s,c=this.spine1y+s,h=this.spine2y+s;this.aabb.minx=i<l?i:l,this.aabb.miny=o<r?o:r,this.aabb.maxx=a>p?a:p,this.aabb.maxy=c>h?c:h}__validate_sweepRadius(){let e=Math.sqrt(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy);this.sweepCoef=e+this.halfLength,this.sweepRadius=this.sweepCoef+this.radius}__validate_area_inertia(){let e=this.radius,t=this.halfLength,n=e*e;this.area=Math.PI*n+4*t*e;let s=2*t*(2*e)*(2*e*(2*e)+2*t*(2*t))/12,i=Math.PI*n*(n*.5+t*t);this.inertia=(s+i)/this.area+(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy)}__validate_angDrag(){let e=En._nape,t=this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy,n=this.radius*this.radius,s=this.halfLength*this.halfLength,i=this.material.dynamicFriction*e.Config.fluidAngularDragFriction;this.angDrag=(t+2*n+s)*i+.5*e.Config.fluidAngularDrag*(1+e.Config.fluidVacuumDrag)*t,this.angDrag/=2*(t+.5*n+s/3)}__scale(e,t){let n=((e<0?-e:e)+(t<0?-t:t))/2,s=n<0?-n:n;this.radius*=s,this.halfLength*=s,this.invalidate_radius(),this.invalidate_halfLength(),this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0&&(this.localCOMx*=e,this.localCOMy*=t,this.invalidate_localCOM())}__translate(e,t){this.localCOMx+=e,this.localCOMy+=t,this.invalidate_localCOM()}__rotate(e,t){if(this.localCOMx*this.localCOMx+this.localCOMy*this.localCOMy>0){let n=t*this.localCOMx-e*this.localCOMy,s=this.localCOMx*e+this.localCOMy*t;this.localCOMx=n,this.localCOMy=s,this.invalidate_localCOM()}}__transform(e){let t=e.zpp_inner.a*e.zpp_inner.d-e.zpp_inner.b*e.zpp_inner.c;t<0&&(t=-t);let n=Math.sqrt(t);this.radius*=n,this.halfLength*=n;let s=e.zpp_inner.a*this.localCOMx+e.zpp_inner.b*this.localCOMy+e.zpp_inner.tx;this.localCOMy=e.zpp_inner.c*this.localCOMx+e.zpp_inner.d*this.localCOMy+e.zpp_inner.ty,this.localCOMx=s,this.invalidate_radius(),this.invalidate_halfLength(),this.invalidate_localCOM()}__copy(){let e=En._nape,t=2*(this.halfLength+this.radius),n=2*this.radius,s=new e.shape.Capsule(t,n).zpp_inner_zn;return s.localCOMx=this.localCOMx,s.localCOMy=this.localCOMy,s.zip_localCOM=!1,s}};En._nape=null,En._zpp=null,En._initialized=!1;var Qn=En;var vi=class vi{constructor(){this.space=null;this.is_sweep=!1;this.sweep=null;this.dynab=null;this.aabbShape=null;this.matrix=null;this.circShape=null}static _initFields(e){e.space=null,e.is_sweep=!1,e.sweep=null,e.dynab=null,e.aabbShape=null,e.matrix=null,e.circShape=null}insert(e){this.is_sweep?this.sweep.__insert(e):this.dynab.__insert(e)}remove(e){this.is_sweep?this.sweep.__remove(e):this.dynab.__remove(e)}sync(e){if(this.is_sweep){if(!this.sweep.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let o=1;l.localCOMx+=l.lverts.next.next.x*o,l.localCOMy+=l.lverts.next.next.y*o;let r=.5;l.localCOMx*=r,l.localCOMy*=r}else{l.localCOMx=0,l.localCOMy=0;let o=0,r=l.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let _=r;o+=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=_,r=r.next}r=l.lverts.next;let c=r;o+=p.x*(c.y-a.y);let h=c.y*p.x-c.x*p.y;l.localCOMx+=(p.x+c.x)*h,l.localCOMy+=(p.y+c.y)*h,a=p,p=c,r=r.next;let u=r;o+=p.x*(u.y-a.y);let x=u.y*p.x-u.x*p.y;l.localCOMx+=(p.x+u.x)*x,l.localCOMy+=(p.y+u.y)*x,o=1/(3*o);let m=o;l.localCOMx*=m,l.localCOMy*=m}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,s=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-s,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+s}else if(e.type==2)e.capsule.__validate_aabb();else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=l;l=l.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next}}}else{let t=this.dynab,n=e.node;if(!n.synced){if(!t.space.continuous&&e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let i=e.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=!1,i.zip_localCOM){if(i.zip_localCOM=!1,i.type==1){let a=i.polygon;if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(a.lverts.next.next==null)a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;else if(a.lverts.next.next.next==null){a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;let p=1;a.localCOMx+=a.lverts.next.next.x*p,a.localCOMy+=a.lverts.next.next.y*p;let c=.5;a.localCOMx*=c,a.localCOMy*=c}else{a.localCOMx=0,a.localCOMy=0;let p=0,c=a.lverts.next,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let f=c;p+=u.x*(f.y-h.y);let w=f.y*u.x-f.x*u.y;a.localCOMx+=(u.x+f.x)*w,a.localCOMy+=(u.y+f.y)*w,h=u,u=f,c=c.next}c=a.lverts.next;let x=c;p+=u.x*(x.y-h.y);let m=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*m,a.localCOMy+=(u.y+x.y)*m,h=u,u=x,c=c.next;let _=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 r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let l=i.radius,o=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-o,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+o}else if(e.type==2)e.capsule.__validate_aabb();else{let i=e.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let a=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=a;a=a.next,c.x=i.body.posx+(i.body.axisy*h.x-i.body.axisx*h.y),c.y=i.body.posy+(h.x*i.body.axisx+h.y*i.body.axisy),p=p.next}}if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let l=i.gverts.next;i.aabb.minx=l.x,i.aabb.miny=l.y,i.aabb.maxx=l.x,i.aabb.maxy=l.y;let o=i.gverts.next.next;for(;o!=null;){let r=o;r.x<i.aabb.minx&&(i.aabb.minx=r.x),r.x>i.aabb.maxx&&(i.aabb.maxx=r.x),r.y<i.aabb.miny&&(i.aabb.miny=r.y),r.y>i.aabb.maxy&&(i.aabb.maxy=r.y),o=o.next}}let s;if(n.dyn==(e.body.type==1?!1:!e.body.component.sleeping)){let i=n.aabb,l=e.aabb;s=!(l.minx>=i.minx&&l.miny>=i.miny&&l.maxx<=i.maxx&&l.maxy<=i.maxy)}else s=!0;s&&(n.synced=!0,n.snext=t.syncs,t.syncs=n)}}}broadphase(e,t){}clear(){}shapesUnderPoint(e,t,n,s){return null}bodiesUnderPoint(e,t,n,s){return null}updateAABBShape(e){let t=vi._zpp,n=vi._nape;if(this.aabbShape==null){t.util.ZPP_Flags.BodyType_STATIC==null&&(t.util.ZPP_Flags.internal=!0,t.util.ZPP_Flags.BodyType_STATIC=new n.phys.BodyType,t.util.ZPP_Flags.internal=!1);let o=new n.phys.Body(t.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,r=this.aabbShape=new n.shape.Polygon(n.shape.Polygon.rect(e.minx,e.miny,e.maxx-e.minx,e.maxy-e.miny));o.zpp_inner.reverse_flag?o.push(r):o.unshift(r)}else{let l=this.aabbShape.zpp_inner.aabb,o=(e.maxx-e.minx)/(l.maxx-l.minx),r=(e.maxy-e.miny)/(l.maxy-l.miny);this.matrix==null&&(this.matrix=new n.geom.Mat23);let a=this.matrix;if(o!==o)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=o;let p=a.zpp_inner;p._invalidate!=null&&p._invalidate();let c=this.matrix,h=this.matrix;h.zpp_inner.c=0;let u=h.zpp_inner;u._invalidate!=null&&u._invalidate();let x=h.zpp_inner.c;if(x!==x)throw new Error("Error: Mat23::b cannot be NaN");c.zpp_inner.b=x;let m=c.zpp_inner;m._invalidate!=null&&m._invalidate();let _=this.matrix;if(r!==r)throw new Error("Error: Mat23::d cannot be NaN");_.zpp_inner.d=r;let y=_.zpp_inner;y._invalidate!=null&&y._invalidate();let z=this.matrix,f=e.minx-o*l.minx;if(f!==f)throw new Error("Error: Mat23::tx cannot be NaN");z.zpp_inner.tx=f;let w=z.zpp_inner;w._invalidate!=null&&w._invalidate();let Z=this.matrix,d=e.miny-r*l.miny;if(d!==d)throw new Error("Error: Mat23::ty cannot be NaN");Z.zpp_inner.ty=d;let b=Z.zpp_inner;b._invalidate!=null&&b._invalidate(),this.aabbShape.transform(this.matrix)}let s=this.aabbShape.zpp_inner;if(s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let l=s.circle;if(l.zip_worldCOM&&l.body!=null){if(l.zip_worldCOM=!1,l.zip_localCOM){if(l.zip_localCOM=!1,l.type==1){let p=l.polygon;if(p.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(p.lverts.next.next==null)p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;else if(p.lverts.next.next.next==null){p.localCOMx=p.lverts.next.x,p.localCOMy=p.lverts.next.y;let c=1;p.localCOMx+=p.lverts.next.next.x*c,p.localCOMy+=p.lverts.next.next.y*c;let h=.5;p.localCOMx*=h,p.localCOMy*=h}else{p.localCOMx=0,p.localCOMy=0;let c=0,h=p.lverts.next,u=h;h=h.next;let 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 f=c;p.localCOMx*=f,p.localCOMy*=f}}l.wrap_localCOM!=null&&(l.wrap_localCOM.zpp_inner.x=l.localCOMx,l.wrap_localCOM.zpp_inner.y=l.localCOMy)}let a=l.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot)),l.worldCOMx=l.body.posx+(l.body.axisy*l.localCOMx-l.body.axisx*l.localCOMy),l.worldCOMy=l.body.posy+(l.localCOMx*l.body.axisx+l.localCOMy*l.body.axisy)}let o=l.radius,r=l.radius;l.aabb.minx=l.worldCOMx-o,l.aabb.miny=l.worldCOMy-r,l.aabb.maxx=l.worldCOMx+o,l.aabb.maxy=l.worldCOMy+r}else{let l=s.polygon;if(l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let a=l.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=l.lverts.next,c=l.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=l.body.posx+(l.body.axisy*u.x-l.body.axisx*u.y),h.y=l.body.posy+(u.x*l.body.axisx+u.y*l.body.axisy),c=c.next}}if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let o=l.gverts.next;l.aabb.minx=o.x,l.aabb.miny=o.y,l.aabb.maxx=o.x,l.aabb.maxy=o.y;let r=l.gverts.next.next;for(;r!=null;){let a=r;a.x<l.aabb.minx&&(l.aabb.minx=a.x),a.x>l.aabb.maxx&&(l.aabb.maxx=a.x),a.y<l.aabb.miny&&(l.aabb.miny=a.y),a.y>l.aabb.maxy&&(l.aabb.maxy=a.y),r=r.next}}let i=this.aabbShape.zpp_inner.polygon;if(i.zip_gaxi&&i.body!=null){i.zip_gaxi=!1,i.validate_laxi();let l=i.body;if(l.zip_axis&&(l.zip_axis=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot)),i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let h=i.body;h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot));let u=i.lverts.next,x=i.gverts.next;for(;x!=null;){let m=x,_=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 o=i.edges.head,r=i.gverts.next,a=r;for(r=r.next;r!=null;){let h=r,u=o.elt;o=o.next,u.gp0=a,u.gp1=h,u.gnormx=i.body.axisy*u.lnormx-i.body.axisx*u.lnormy,u.gnormy=u.lnormx*i.body.axisx+u.lnormy*i.body.axisy,u.gprojection=i.body.posx*u.gnormx+i.body.posy*u.gnormy+u.lprojection,u.wrap_gnorm!=null&&(u.wrap_gnorm.zpp_inner.x=u.gnormx,u.wrap_gnorm.zpp_inner.y=u.gnormy),u.tp0=u.gp0.y*u.gnormx-u.gp0.x*u.gnormy,u.tp1=u.gp1.y*u.gnormx-u.gp1.x*u.gnormy,a=h,r=r.next}let p=i.gverts.next,c=o.elt;o=o.next,c.gp0=a,c.gp1=p,c.gnormx=i.body.axisy*c.lnormx-i.body.axisx*c.lnormy,c.gnormy=c.lnormx*i.body.axisx+c.lnormy*i.body.axisy,c.gprojection=i.body.posx*c.gnormx+i.body.posy*c.gnormy+c.lprojection,c.wrap_gnorm!=null&&(c.wrap_gnorm.zpp_inner.x=c.gnormx,c.wrap_gnorm.zpp_inner.y=c.gnormy),c.tp0=c.gp0.y*c.gnormx-c.gp0.x*c.gnormy,c.tp1=c.gp1.y*c.gnormx-c.gp1.x*c.gnormy}}shapesInAABB(e,t,n,s,i){return null}bodiesInAABB(e,t,n,s,i){return null}updateCircShape(e,t,n){let s=vi._zpp,i=vi._nape;if(this.circShape==null){s.util.ZPP_Flags.BodyType_STATIC==null&&(s.util.ZPP_Flags.internal=!0,s.util.ZPP_Flags.BodyType_STATIC=new i.phys.BodyType,s.util.ZPP_Flags.internal=!1);let r=new i.phys.Body(s.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,a=e,p=t;if(p==null&&(p=0),a==null&&(a=0),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let c;if(s.util.ZPP_PubPool.poolVec2==null?c=new i.geom.Vec2:(c=s.util.ZPP_PubPool.poolVec2,s.util.ZPP_PubPool.poolVec2=c.zpp_pool,c.zpp_pool=null,c.zpp_disp=!1,c==s.util.ZPP_PubPool.nextVec2&&(s.util.ZPP_PubPool.nextVec2=null)),c.zpp_inner==null){let u;s.geom.ZPP_Vec2.zpp_pool==null?u=new s.geom.ZPP_Vec2:(u=s.geom.ZPP_Vec2.zpp_pool,s.geom.ZPP_Vec2.zpp_pool=u.next,u.next=null),u.weak=!1,u._immutable=!1,u.x=a,u.y=p,c.zpp_inner=u,c.zpp_inner.outer=c}else{if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=c.zpp_inner;if(u._immutable)throw new Error("Error: Vec2 is immutable");if(u._isimmutable!=null&&u._isimmutable(),a!==a||p!==p)throw new Error("Error: Vec2 components cannot be NaN");let x;if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let m=c.zpp_inner;if(m._validate!=null&&m._validate(),c.zpp_inner.x==a){if(c!=null&&c.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let _=c.zpp_inner;_._validate!=null&&_._validate(),x=c.zpp_inner.y==p}else x=!1;if(!x){c.zpp_inner.x=a,c.zpp_inner.y=p;let _=c.zpp_inner;_._invalidate!=null&&_._invalidate(_)}}c.zpp_inner.weak=!1;let h=this.circShape=new i.shape.Circle(n,c);r.zpp_inner.reverse_flag?r.push(h):r.unshift(h)}else{let o=this.circShape.zpp_inner.circle,r=n/o.radius;this.matrix==null&&(this.matrix=new i.geom.Mat23);let a=this.matrix,p=this.matrix;if(r!==r)throw new Error("Error: Mat23::d cannot be NaN");p.zpp_inner.d=r;let c=p.zpp_inner;c._invalidate!=null&&c._invalidate();let h=p.zpp_inner.d;if(h!==h)throw new Error("Error: Mat23::a cannot be NaN");a.zpp_inner.a=h;let u=a.zpp_inner;u._invalidate!=null&&u._invalidate();let x=this.matrix,m=this.matrix;m.zpp_inner.c=0;let _=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 f=this.matrix,w=e-r*o.localCOMx;if(w!==w)throw new Error("Error: Mat23::tx cannot be NaN");f.zpp_inner.tx=w;let Z=f.zpp_inner;Z._invalidate!=null&&Z._invalidate();let d=this.matrix,b=t-r*o.localCOMy;if(b!==b)throw new Error("Error: Mat23::ty cannot be NaN");d.zpp_inner.ty=b;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=!1,l.type==0){let o=l.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let h=1;c.localCOMx+=c.lverts.next.next.x*h,c.localCOMy+=c.lverts.next.next.y*h;let u=.5;c.localCOMx*=u,c.localCOMy*=u}else{c.localCOMx=0,c.localCOMy=0;let h=0,u=c.lverts.next,x=u;u=u.next;let m=u;for(u=u.next;u!=null;){let 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 f=z.y*m.x-z.x*m.y;c.localCOMx+=(m.x+z.x)*f,c.localCOMy+=(m.y+z.y)*f,h=1/(3*h);let w=h;c.localCOMx*=w,c.localCOMy*=w}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else{let o=l.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,h=o.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),u.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),h=h.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}}shapesInCircle(e,t,n,s,i,l){return null}bodiesInCircle(e,t,n,s,i,l){return null}validateShape(e){if(e.type==1){let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=t.body.posx+(t.body.axisy*u.x-t.body.axisx*u.y),h.y=t.body.posy+(u.x*t.body.axisx+u.y*t.body.axisy),c=c.next}}let s=t.edges.head,i=t.gverts.next,l=i;for(i=i.next;i!=null;){let a=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,l=a,i=i.next}let o=t.gverts.next,r=s.elt;s=s.next,r.gp0=l,r.gp1=o,r.gnormx=t.body.axisy*r.lnormx-t.body.axisx*r.lnormy,r.gnormy=r.lnormx*t.body.axisx+r.lnormy*t.body.axisy,r.gprojection=t.body.posx*r.gnormx+t.body.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let l=t.polygon;if(l.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(l.lverts.next.next==null)l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;else if(l.lverts.next.next.next==null){l.localCOMx=l.lverts.next.x,l.localCOMy=l.lverts.next.y;let o=1;l.localCOMx+=l.lverts.next.next.x*o,l.localCOMy+=l.lverts.next.next.y*o;let r=.5;l.localCOMx*=r,l.localCOMy*=r}else{l.localCOMx=0,l.localCOMy=0;let o=0,r=l.lverts.next,a=r;r=r.next;let p=r;for(r=r.next;r!=null;){let _=r;o+=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=_,r=r.next}r=l.lverts.next;let c=r;o+=p.x*(c.y-a.y);let h=c.y*p.x-c.x*p.y;l.localCOMx+=(p.x+c.x)*h,l.localCOMy+=(p.y+c.y)*h,a=p,p=c,r=r.next;let u=r;o+=p.x*(u.y-a.y);let x=u.y*p.x-u.x*p.y;l.localCOMx+=(p.x+u.x)*x,l.localCOMy+=(p.y+u.y)*x,o=1/(3*o);let m=o;l.localCOMx*=m,l.localCOMy*=m}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}let n=t.radius,s=t.radius;t.aabb.minx=t.worldCOMx-n,t.aabb.miny=t.worldCOMy-s,t.aabb.maxx=t.worldCOMx+n,t.aabb.maxy=t.worldCOMy+s}else{let t=e.polygon;if(t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let i=t.body;i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot));let l=t.lverts.next,o=t.gverts.next;for(;o!=null;){let r=o,a=l;l=l.next,r.x=t.body.posx+(t.body.axisy*a.x-t.body.axisx*a.y),r.y=t.body.posy+(a.x*t.body.axisx+a.y*t.body.axisy),o=o.next}}if(t.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let n=t.gverts.next;t.aabb.minx=n.x,t.aabb.miny=n.y,t.aabb.maxx=n.x,t.aabb.maxy=n.y;let s=t.gverts.next.next;for(;s!=null;){let i=s;i.x<t.aabb.minx&&(t.aabb.minx=i.x),i.x>t.aabb.maxx&&(t.aabb.maxx=i.x),i.y<t.aabb.miny&&(t.aabb.miny=i.y),i.y>t.aabb.maxy&&(t.aabb.maxy=i.y),s=s.next}}if(e.zip_worldCOM&&e.body!=null){if(e.zip_worldCOM=!1,e.zip_localCOM){if(e.zip_localCOM=!1,e.type==1){let n=e.polygon;if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(n.lverts.next.next==null)n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;else if(n.lverts.next.next.next==null){n.localCOMx=n.lverts.next.x,n.localCOMy=n.lverts.next.y;let s=1;n.localCOMx+=n.lverts.next.next.x*s,n.localCOMy+=n.lverts.next.next.y*s;let i=.5;n.localCOMx*=i,n.localCOMy*=i}else{n.localCOMx=0,n.localCOMy=0;let s=0,i=n.lverts.next,l=i;i=i.next;let o=i;for(i=i.next;i!=null;){let u=i;s+=o.x*(u.y-l.y);let x=u.y*o.x-u.x*o.y;n.localCOMx+=(o.x+u.x)*x,n.localCOMy+=(o.y+u.y)*x,l=o,o=u,i=i.next}i=n.lverts.next;let r=i;s+=o.x*(r.y-l.y);let a=r.y*o.x-r.x*o.y;n.localCOMx+=(o.x+r.x)*a,n.localCOMy+=(o.y+r.y)*a,l=o,o=r,i=i.next;let p=i;s+=o.x*(p.y-l.y);let c=p.y*o.x-p.x*o.y;n.localCOMx+=(o.x+p.x)*c,n.localCOMy+=(o.y+p.y)*c,s=1/(3*s);let h=s;n.localCOMx*=h,n.localCOMy*=h}}e.wrap_localCOM!=null&&(e.wrap_localCOM.zpp_inner.x=e.localCOMx,e.wrap_localCOM.zpp_inner.y=e.localCOMy)}let t=e.body;t.zip_axis&&(t.zip_axis=!1,t.axisx=Math.sin(t.rot),t.axisy=Math.cos(t.rot)),e.worldCOMx=e.body.posx+(e.body.axisy*e.localCOMx-e.body.axisx*e.localCOMy),e.worldCOMy=e.body.posy+(e.localCOMx*e.body.axisx+e.localCOMy*e.body.axisy)}}shapesInShape(e,t,n,s){return null}bodiesInShape(e,t,n,s){return null}rayCast(e,t,n){return null}rayMultiCast(e,t,n,s){return null}};vi._zpp=null,vi._nape=null;var $n=vi;var Ve=class{constructor(){this.aabb=null;this.shape=null;this.dyn=!1;this.parent=null;this.child1=null;this.child2=null;this.height=-1;this.rayt=0;this.next=null;this.mnext=null;this.moved=!1;this.snext=null;this.synced=!1;this.first_sync=!1}alloc(){fe.zpp_pool==null?this.aabb=new fe:(this.aabb=fe.zpp_pool,fe.zpp_pool=this.aabb.next,this.aabb.next=null),this.moved=!1,this.synced=!1,this.first_sync=!1}free(){this.height=-1;let e=this.aabb;e.outer!=null&&(e.outer.zpp_inner=null,e.outer=null),e.wrap_min=e.wrap_max=null,e._invalidate=null,e._validate=null,e.next=fe.zpp_pool,fe.zpp_pool=e,this.child1=this.child2=this.parent=null,this.next=null,this.snext=null,this.mnext=null}isLeaf(){return this.child1==null}};Ve.zpp_pool=null;var st=class{constructor(){this.n1=null;this.n2=null;this.first=!1;this.sleeping=!1;this.id=0;this.di=0;this.arb=null;this.next=null;this.gprev=null}alloc(){}free(){this.n1=this.n2=null,this.sleeping=!1,this.gprev=null}};st.zpp_pool=null;var Zt=class Zt{constructor(){this.root=null}static _initStatics(){Zt.tmpaabb=new fe}clear(){if(this.root==null)return;let e=null;for(this.root.next=e,e=this.root;e!=null;){let t=e;e=t.next,t.next=null;let n=t;n.child1==null?(n.shape.node=null,n.shape.removedFromSpace(),n.shape=null):(n.child1!=null&&(n.child1.next=e,e=n.child1),n.child2!=null&&(n.child2.next=e,e=n.child2));let s=n;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=fe.zpp_pool,fe.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Ve.zpp_pool,Ve.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),f=Zt.tmpaabb,w=a.aabb;f.minx=t.minx<w.minx?t.minx:w.minx,f.miny=t.miny<w.miny?t.miny:w.miny,f.maxx=t.maxx>w.maxx?t.maxx:w.maxx,f.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,b=p.aabb;d.minx=t.minx<b.minx?t.minx:b.minx,d.miny=t.miny<b.miny?t.miny:b.miny,d.maxx=t.maxx>b.maxx?t.maxx:b.maxx,d.maxy=t.maxy>b.maxy?t.maxy:b.maxy;let 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;Ve.zpp_pool==null?l=new Ve:(l=Ve.zpp_pool,Ve.zpp_pool=l.next,l.next=null),fe.zpp_pool==null?l.aabb=new fe:(l.aabb=fe.zpp_pool,fe.zpp_pool=l.aabb.next,l.aabb.next=null),l.moved=!1,l.synced=!1,l.first_sync=!1,l.parent=i;let o=l.aabb,r=s.aabb;for(o.minx=t.minx<r.minx?t.minx:r.minx,o.miny=t.miny<r.miny?t.miny:r.miny,o.maxx=t.maxx>r.maxx?t.maxx:r.maxx,o.maxy=t.maxy>r.maxy?t.maxy:r.maxy,l.height=s.height+1,i!=null?(i.child1==s?i.child1=l:i.child2=l,l.child1=s,l.child2=e,s.parent=l,e.parent=l):(l.child1=s,l.child2=e,s.parent=l,e.parent=l,this.root=l),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let _=n.child1,y=n.child2,z=y.height-_.height;if(z>1){let f=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,f.height>w.height){y.child2=f,n.child2=w,w.parent=n;let Z=n.aabb,d=_.aabb,b=w.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=y.aabb,P=n.aabb,v=f.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,k=w.height;n.height=1+(N>k?N:k);let C=n.height,E=f.height;y.height=1+(C>E?C:E)}else{y.child2=w,n.child2=f,f.parent=n;let Z=n.aabb,d=_.aabb,b=f.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.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,k=f.height;n.height=1+(N>k?N:k);let C=n.height,E=w.height;y.height=1+(C>E?C:E)}n=y}else if(z<-1){let f=_.child1,w=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,f.height>w.height){_.child2=f,n.child1=w,w.parent=n;let Z=n.aabb,d=y.aabb,b=w.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=_.aabb,P=n.aabb,v=f.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,k=w.height;n.height=1+(N>k?N:k);let C=n.height,E=f.height;_.height=1+(C>E?C:E)}else{_.child2=w,n.child1=f,f.parent=n;let Z=n.aabb,d=y.aabb,b=f.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.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,k=f.height;n.height=1+(N>k?N:k);let C=n.height,E=w.height;_.height=1+(C>E?C:E)}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),f=Zt.tmpaabb,w=a.aabb;f.minx=t.minx<w.minx?t.minx:w.minx,f.miny=t.miny<w.miny?t.miny:w.miny,f.maxx=t.maxx>w.maxx?t.maxx:w.maxx,f.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,b=p.aabb;d.minx=t.minx<b.minx?t.minx:b.minx,d.miny=t.miny<b.miny?t.miny:b.miny,d.maxx=t.maxx>b.maxx?t.maxx:b.maxx,d.maxy=t.maxy>b.maxy?t.maxy:b.maxy;let 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;Ve.zpp_pool==null?l=new Ve:(l=Ve.zpp_pool,Ve.zpp_pool=l.next,l.next=null),fe.zpp_pool==null?l.aabb=new fe:(l.aabb=fe.zpp_pool,fe.zpp_pool=l.aabb.next,l.aabb.next=null),l.moved=!1,l.synced=!1,l.first_sync=!1,l.parent=i;let o=l.aabb,r=s.aabb;for(o.minx=t.minx<r.minx?t.minx:r.minx,o.miny=t.miny<r.miny?t.miny:r.miny,o.maxx=t.maxx>r.maxx?t.maxx:r.maxx,o.maxy=t.maxy>r.maxy?t.maxy:r.maxy,l.height=s.height+1,i!=null?(i.child1==s?i.child1=l:i.child2=l,l.child1=s,l.child2=e,s.parent=l,e.parent=l):(l.child1=s,l.child2=e,s.parent=l,e.parent=l,this.root=l),n=e.parent;n!=null;){if(n.child1==null||n.height<2)n=n;else{let _=n.child1,y=n.child2,z=y.height-_.height;if(z>1){let f=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,f.height>w.height){y.child2=f,n.child2=w,w.parent=n;let Z=n.aabb,d=_.aabb,b=w.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=y.aabb,P=n.aabb,v=f.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,k=w.height;n.height=1+(N>k?N:k);let C=n.height,E=f.height;y.height=1+(C>E?C:E)}else{y.child2=w,n.child2=f,f.parent=n;let Z=n.aabb,d=_.aabb,b=f.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.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,k=f.height;n.height=1+(N>k?N:k);let C=n.height,E=w.height;y.height=1+(C>E?C:E)}n=y}else if(z<-1){let f=_.child1,w=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,f.height>w.height){_.child2=f,n.child1=w,w.parent=n;let Z=n.aabb,d=y.aabb,b=w.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=_.aabb,P=n.aabb,v=f.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,k=w.height;n.height=1+(N>k?N:k);let C=n.height,E=f.height;_.height=1+(C>E?C:E)}else{_.child2=w,n.child1=f,f.parent=n;let Z=n.aabb,d=y.aabb,b=f.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.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,k=f.height;n.height=1+(N>k?N:k);let C=n.height,E=w.height;_.height=1+(C>E?C:E)}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=fe.zpp_pool,fe.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Ve.zpp_pool,Ve.zpp_pool=i;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let _=o.child1,y=o.child2,z=y.height-_.height;if(z>1){let f=y.child1,w=y.child2;if(y.child1=o,y.parent=o.parent,o.parent=y,y.parent!=null?y.parent.child1==o?y.parent.child1=y:y.parent.child2=y:this.root=y,f.height>w.height){y.child2=f,o.child2=w,w.parent=o;let Z=o.aabb,d=_.aabb,b=w.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=y.aabb,P=o.aabb,v=f.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,k=w.height;o.height=1+(N>k?N:k);let C=o.height,E=f.height;y.height=1+(C>E?C:E)}else{y.child2=w,o.child2=f,f.parent=o;let Z=o.aabb,d=_.aabb,b=f.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=y.aabb,P=o.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,k=f.height;o.height=1+(N>k?N:k);let C=o.height,E=w.height;y.height=1+(C>E?C:E)}o=y}else if(z<-1){let f=_.child1,w=_.child2;if(_.child1=o,_.parent=o.parent,o.parent=_,_.parent!=null?_.parent.child1==o?_.parent.child1=_:_.parent.child2=_:this.root=_,f.height>w.height){_.child2=f,o.child1=w,w.parent=o;let Z=o.aabb,d=y.aabb,b=w.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=_.aabb,P=o.aabb,v=f.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,k=w.height;o.height=1+(N>k?N:k);let C=o.height,E=f.height;_.height=1+(C>E?C:E)}else{_.child2=w,o.child1=f,f.parent=o;let Z=o.aabb,d=y.aabb,b=f.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=_.aabb,P=o.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,k=f.height;o.height=1+(N>k?N:k);let C=o.height,E=w.height;_.height=1+(C>E?C:E)}o=_}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,h=a.aabb,u=p.aabb;c.minx=h.minx<u.minx?h.minx:u.minx,c.miny=h.miny<u.miny?h.miny:u.miny,c.maxx=h.maxx>u.maxx?h.maxx:u.maxx,c.maxy=h.maxy>u.maxy?h.maxy:u.maxy;let x=a.height,m=p.height;r.height=1+(x>m?x:m),o=r.parent}}else{this.root=s,s.parent=null;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=fe.zpp_pool,fe.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Ve.zpp_pool,Ve.zpp_pool=i}}}inlined_removeLeaf(e){if(e==this.root){this.root=null;return}else{let t=e.parent,n=t.parent,s=t.child1==e?t.child2:t.child1;if(n!=null){n.child1==t?n.child1=s:n.child2=s,s.parent=n;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=fe.zpp_pool,fe.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Ve.zpp_pool,Ve.zpp_pool=i;let o=n;for(;o!=null;){if(o.child1==null||o.height<2)o=o;else{let _=o.child1,y=o.child2,z=y.height-_.height;if(z>1){let f=y.child1,w=y.child2;if(y.child1=o,y.parent=o.parent,o.parent=y,y.parent!=null?y.parent.child1==o?y.parent.child1=y:y.parent.child2=y:this.root=y,f.height>w.height){y.child2=f,o.child2=w,w.parent=o;let Z=o.aabb,d=_.aabb,b=w.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=y.aabb,P=o.aabb,v=f.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,k=w.height;o.height=1+(N>k?N:k);let C=o.height,E=f.height;y.height=1+(C>E?C:E)}else{y.child2=w,o.child2=f,f.parent=o;let Z=o.aabb,d=_.aabb,b=f.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=y.aabb,P=o.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,k=f.height;o.height=1+(N>k?N:k);let C=o.height,E=w.height;y.height=1+(C>E?C:E)}o=y}else if(z<-1){let f=_.child1,w=_.child2;if(_.child1=o,_.parent=o.parent,o.parent=_,_.parent!=null?_.parent.child1==o?_.parent.child1=_:_.parent.child2=_:this.root=_,f.height>w.height){_.child2=f,o.child1=w,w.parent=o;let Z=o.aabb,d=y.aabb,b=w.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=_.aabb,P=o.aabb,v=f.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,k=w.height;o.height=1+(N>k?N:k);let C=o.height,E=f.height;_.height=1+(C>E?C:E)}else{_.child2=w,o.child1=f,f.parent=o;let Z=o.aabb,d=y.aabb,b=f.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy;let g=_.aabb,P=o.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,k=f.height;o.height=1+(N>k?N:k);let C=o.height,E=w.height;_.height=1+(C>E?C:E)}o=_}else o=o}let r=o,a=r.child1,p=r.child2,c=r.aabb,h=a.aabb,u=p.aabb;c.minx=h.minx<u.minx?h.minx:u.minx,c.miny=h.miny<u.miny?h.miny:u.miny,c.maxx=h.maxx>u.maxx?h.maxx:u.maxx,c.maxy=h.maxy>u.maxy?h.maxy:u.maxy;let x=a.height,m=p.height;r.height=1+(x>m?x:m),o=r.parent}}else{this.root=s,s.parent=null;let i=t;i.height=-1;let l=i.aabb;l.outer!=null&&(l.outer.zpp_inner=null,l.outer=null),l.wrap_min=l.wrap_max=null,l._invalidate=null,l._validate=null,l.next=fe.zpp_pool,fe.zpp_pool=l,i.child1=i.child2=i.parent=null,i.next=null,i.snext=null,i.mnext=null,i.next=Ve.zpp_pool,Ve.zpp_pool=i}}}balance(e){if(e.child1==null||e.height<2)return e;{let t=e.child1,n=e.child2,s=n.height-t.height;if(s>1){let i=n.child1,l=n.child2;if(n.child1=e,n.parent=e.parent,e.parent=n,n.parent!=null?n.parent.child1==e?n.parent.child1=n:n.parent.child2=n:this.root=n,i.height>l.height){n.child2=i,e.child2=l,l.parent=e;let o=e.aabb,r=t.aabb,a=l.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=n.aabb,c=e.aabb,h=i.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=t.height,x=l.height;e.height=1+(u>x?u:x);let m=e.height,_=i.height;n.height=1+(m>_?m:_)}else{n.child2=l,e.child2=i,i.parent=e;let o=e.aabb,r=t.aabb,a=i.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=n.aabb,c=e.aabb,h=l.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=t.height,x=i.height;e.height=1+(u>x?u:x);let m=e.height,_=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 o=e.aabb,r=n.aabb,a=l.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=t.aabb,c=e.aabb,h=i.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=n.height,x=l.height;e.height=1+(u>x?u:x);let m=e.height,_=i.height;t.height=1+(m>_?m:_)}else{t.child2=l,e.child1=i,i.parent=e;let o=e.aabb,r=n.aabb,a=i.aabb;o.minx=r.minx<a.minx?r.minx:a.minx,o.miny=r.miny<a.miny?r.miny:a.miny,o.maxx=r.maxx>a.maxx?r.maxx:a.maxx,o.maxy=r.maxy>a.maxy?r.maxy:a.maxy;let p=t.aabb,c=e.aabb,h=l.aabb;p.minx=c.minx<h.minx?c.minx:h.minx,p.miny=c.miny<h.miny?c.miny:h.miny,p.maxx=c.maxx>h.maxx?c.maxx:h.maxx,p.maxy=c.maxy>h.maxy?c.maxy:h.maxy;let u=n.height,x=i.height;e.height=1+(u>x?u:x);let m=e.height,_=l.height;t.height=1+(m>_?m:_)}return t}else return e}}};Zt.tmpaabb=null;var Qe=Zt;var we=class we extends $n{constructor(t){super();this.pairs=null;this.syncs=null;this.moves=null;this.treeStack=null;this.treeStack2=null;this.failed=null;this.openlist=null;this.space=t,this.is_sweep=!1,this.dynab=this,this.stree=new 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?!1:!t.body.component.sleeping}__insert(t){let n;Ve.zpp_pool==null?n=new Ve:(n=Ve.zpp_pool,Ve.zpp_pool=n.next,n.next=null),fe.zpp_pool==null?n.aabb=new fe:(n.aabb=fe.zpp_pool,fe.zpp_pool=n.aabb.next,n.aabb.next=null),n.moved=!1,n.synced=!1,n.first_sync=!1,n.shape=t,t.node=n,n.synced=!0,n.first_sync=!0,n.snext=this.syncs,this.syncs=n}__remove(t){let n=t.node;if(n.first_sync||(n.dyn?this.dtree.removeLeaf(n):this.stree.removeLeaf(n)),t.node=null,n.synced){let l=null,o=this.syncs;for(;o!=null&&o!=n;)l=o,o=o.snext;l==null?this.syncs=o.snext:l.snext=o.snext,o.snext=null,n.synced=!1}if(n.moved){let l=null,o=this.moves;for(;o!=null&&o!=n;)l=o,o=o.mnext;l==null?this.moves=o.mnext:l.mnext=o.mnext,o.mnext=null,n.moved=!1}for(;t.pairs.head!=null;){let l=t.pairs.pop_unsafe();l.sleeping||this._unlinkPair(l),l.n1==n?l.n2.shape.pairs.remove(l):l.n1.shape.pairs.remove(l),l.arb!=null&&(l.arb.pair=null),l.arb=null,l.n1=l.n2=null,l.sleeping=!1,l.gprev=null,l.next=st.zpp_pool,st.zpp_pool=l}let s=n;s.height=-1;let i=s.aabb;i.outer!=null&&(i.outer.zpp_inner=null,i.outer=null),i.wrap_min=i.wrap_max=null,i._invalidate=null,i._validate=null,i.next=fe.zpp_pool,fe.zpp_pool=i,s.child1=s.child2=s.parent=null,s.next=null,s.snext=null,s.mnext=null,s.next=Ve.zpp_pool,Ve.zpp_pool=s}__sync(t){let n=t.node;if(!n.synced){if(!this.space.continuous&&t.zip_aabb&&t.body!=null)if(t.zip_aabb=!1,t.type==0){let i=t.circle;if(i.zip_worldCOM&&i.body!=null){if(i.zip_worldCOM=!1,i.zip_localCOM){if(i.zip_localCOM=!1,i.type==1){let a=i.polygon;if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(a.lverts.next.next==null)a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;else if(a.lverts.next.next.next==null){a.localCOMx=a.lverts.next.x,a.localCOMy=a.lverts.next.y;let p=1;a.localCOMx+=a.lverts.next.next.x*p,a.localCOMy+=a.lverts.next.next.y*p;let c=.5;a.localCOMx*=c,a.localCOMy*=c}else{a.localCOMx=0,a.localCOMy=0;let p=0,c=a.lverts.next,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let f=c;p+=u.x*(f.y-h.y);let w=f.y*u.x-f.x*u.y;a.localCOMx+=(u.x+f.x)*w,a.localCOMy+=(u.y+f.y)*w,h=u,u=f,c=c.next}c=a.lverts.next;let x=c;p+=u.x*(x.y-h.y);let m=x.y*u.x-x.x*u.y;a.localCOMx+=(u.x+x.x)*m,a.localCOMy+=(u.y+x.y)*m,h=u,u=x,c=c.next;let _=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 r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let l=i.radius,o=i.radius;i.aabb.minx=i.worldCOMx-l,i.aabb.miny=i.worldCOMy-o,i.aabb.maxx=i.worldCOMx+l,i.aabb.maxy=i.worldCOMy+o}else{let i=t.polygon;if(i.zip_gverts&&i.body!=null){i.zip_gverts=!1,i.validate_lverts();let r=i.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let a=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=a;a=a.next,c.x=i.body.posx+(i.body.axisy*h.x-i.body.axisx*h.y),c.y=i.body.posy+(h.x*i.body.axisx+h.y*i.body.axisy),p=p.next}}if(i.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let l=i.gverts.next;i.aabb.minx=l.x,i.aabb.miny=l.y,i.aabb.maxx=l.x,i.aabb.maxy=l.y;let o=i.gverts.next.next;for(;o!=null;){let r=o;r.x<i.aabb.minx&&(i.aabb.minx=r.x),r.x>i.aabb.maxx&&(i.aabb.maxx=r.x),r.y<i.aabb.miny&&(i.aabb.miny=r.y),r.y>i.aabb.maxy&&(i.aabb.maxy=r.y),o=o.next}}let s;if(n.dyn==(t.body.type==1?!1:!t.body.component.sleeping)){let i=n.aabb,l=t.aabb;s=!(l.minx>=i.minx&&l.miny>=i.miny&&l.maxx<=i.maxx&&l.maxy<=i.maxy)}else s=!0;s&&(n.synced=!0,n.snext=this.syncs,this.syncs=n)}}sync_broadphase(){if(this.space.validation(),this.syncs!=null)if(this.moves==null){let t=this.syncs;for(;t!=null;){let s=t.shape;if(t.first_sync)t.first_sync=!1;else{let r=t.dyn?this.dtree:this.stree;if(t==r.root)r.root=null;else{let a=t.parent,p=a.parent,c=a.child1==t?a.child2:a.child1;if(p!=null){p.child1==a?p.child1=c:p.child2=c,c.parent=p;let h=a;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=fe.zpp_pool,fe.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Ve.zpp_pool,Ve.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else{let d=x.child1,b=x.child2,g=b.height-d.height;if(g>1){let P=b.child1,v=b.child2;if(b.child1=x,b.parent=x.parent,x.parent=b,b.parent!=null?b.parent.child1==x?b.parent.child1=b:b.parent.child2=b:r.root=b,P.height>v.height){b.child2=P,x.child2=v,v.parent=x;let N=x.aabb,k=d.aabb,C=v.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=b.aabb,M=x.aabb,S=P.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=d.height,L=v.height;x.height=1+(O>L?O:L);let T=x.height,R=P.height;b.height=1+(T>R?T:R)}else{b.child2=v,x.child2=P,P.parent=x;let N=x.aabb,k=d.aabb,C=P.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=b.aabb,M=x.aabb,S=v.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=d.height,L=P.height;x.height=1+(O>L?O:L);let T=x.height,R=v.height;b.height=1+(T>R?T:R)}x=b}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:r.root=d,P.height>v.height){d.child2=P,x.child1=v,v.parent=x;let N=x.aabb,k=b.aabb,C=v.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=d.aabb,M=x.aabb,S=P.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=b.height,L=v.height;x.height=1+(O>L?O:L);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,k=b.aabb,C=P.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=d.aabb,M=x.aabb,S=v.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=b.height,L=P.height;x.height=1+(O>L?O:L);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,f=_.aabb;y.minx=z.minx<f.minx?z.minx:f.minx,y.miny=z.miny<f.miny?z.miny:f.miny,y.maxx=z.maxx>f.maxx?z.maxx:f.maxx,y.maxy=z.maxy>f.maxy?z.maxy:f.maxy;let w=m.height,Z=_.height;x.height=1+(w>Z?w:Z),x=x.parent}}else{r.root=c,c.parent=null;let h=a;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=fe.zpp_pool,fe.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Ve.zpp_pool,Ve.zpp_pool=h}}}let i=t.aabb;if(!this.space.continuous&&s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let r=s.circle;if(r.zip_worldCOM&&r.body!=null){if(r.zip_worldCOM=!1,r.zip_localCOM){if(r.zip_localCOM=!1,r.type==1){let h=r.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let u=1;h.localCOMx+=h.lverts.next.next.x*u,h.localCOMy+=h.lverts.next.next.y*u;let x=.5;h.localCOMx*=x,h.localCOMy*=x}else{h.localCOMx=0,h.localCOMy=0;let u=0,x=h.lverts.next,m=x;x=x.next;let _=x;for(x=x.next;x!=null;){let d=x;u+=_.x*(d.y-m.y);let b=d.y*_.x-d.x*_.y;h.localCOMx+=(_.x+d.x)*b,h.localCOMy+=(_.y+d.y)*b,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 f=x;u+=_.x*(f.y-m.y);let w=f.y*_.x-f.x*_.y;h.localCOMx+=(_.x+f.x)*w,h.localCOMy+=(_.y+f.y)*w,u=1/(3*u);let Z=u;h.localCOMx*=Z,h.localCOMy*=Z}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),r.worldCOMx=r.body.posx+(r.body.axisy*r.localCOMx-r.body.axisx*r.localCOMy),r.worldCOMy=r.body.posy+(r.localCOMx*r.body.axisx+r.localCOMy*r.body.axisy)}let a=r.radius,p=r.radius;r.aabb.minx=r.worldCOMx-a,r.aabb.miny=r.worldCOMy-p,r.aabb.maxx=r.worldCOMx+a,r.aabb.maxy=r.worldCOMy+p}else{let r=s.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=r.lverts.next,u=r.gverts.next;for(;u!=null;){let x=u,m=h;h=h.next,x.x=r.body.posx+(r.body.axisy*m.x-r.body.axisx*m.y),x.y=r.body.posy+(m.x*r.body.axisx+m.y*r.body.axisy),u=u.next}}if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let a=r.gverts.next;r.aabb.minx=a.x,r.aabb.miny=a.y,r.aabb.maxx=a.x,r.aabb.maxy=a.y;let p=r.gverts.next.next;for(;p!=null;){let c=p;c.x<r.aabb.minx&&(r.aabb.minx=c.x),c.x>r.aabb.maxx&&(r.aabb.maxx=c.x),c.y<r.aabb.miny&&(r.aabb.miny=c.y),c.y>r.aabb.maxy&&(r.aabb.maxy=c.y),p=p.next}}let l=s.aabb;i.minx=l.minx-3,i.miny=l.miny-3,i.maxx=l.maxx+3,i.maxy=l.maxy+3;let o=(t.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(o.root==null)o.root=t,o.root.parent=null;else{let r=t.aabb,a=o.root;for(;a.child1!=null;){let m=a.child1,_=a.child2,y=a.aabb,z=(y.maxx-y.minx+(y.maxy-y.miny))*2,f=Qe.tmpaabb,w=a.aabb;f.minx=w.minx<r.minx?w.minx:r.minx,f.miny=w.miny<r.miny?w.miny:r.miny,f.maxx=w.maxx>r.maxx?w.maxx:r.maxx,f.maxy=w.maxy>r.maxy?w.maxy:r.maxy;let Z=Qe.tmpaabb,d=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,b=2*d,g=2*(d-z),P=Qe.tmpaabb,v=m.aabb;P.minx=r.minx<v.minx?r.minx:v.minx,P.miny=r.miny<v.miny?r.miny:v.miny,P.maxx=r.maxx>v.maxx?r.maxx:v.maxx,P.maxy=r.maxy>v.maxy?r.maxy:v.maxy;let N;if(m.child1==null){let M=Qe.tmpaabb;N=(M.maxx-M.minx+(M.maxy-M.miny))*2+g}else{let M=m.aabb,S=(M.maxx-M.minx+(M.maxy-M.miny))*2,O=Qe.tmpaabb;N=(O.maxx-O.minx+(O.maxy-O.miny))*2-S+g}let k=Qe.tmpaabb,C=_.aabb;k.minx=r.minx<C.minx?r.minx:C.minx,k.miny=r.miny<C.miny?r.miny:C.miny,k.maxx=r.maxx>C.maxx?r.maxx:C.maxx,k.maxy=r.maxy>C.maxy?r.maxy:C.maxy;let E;if(_.child1==null){let M=Qe.tmpaabb;E=(M.maxx-M.minx+(M.maxy-M.miny))*2+g}else{let M=_.aabb,S=(M.maxx-M.minx+(M.maxy-M.miny))*2,O=Qe.tmpaabb;E=(O.maxx-O.minx+(O.maxy-O.miny))*2-S+g}if(b<N&&b<E)break;a=N<E?m:_}let p=a,c=p.parent,h;Ve.zpp_pool==null?h=new Ve:(h=Ve.zpp_pool,Ve.zpp_pool=h.next,h.next=null),fe.zpp_pool==null?h.aabb=new fe:(h.aabb=fe.zpp_pool,fe.zpp_pool=h.aabb.next,h.aabb.next=null),h.moved=!1,h.synced=!1,h.first_sync=!1,h.parent=c;let u=h.aabb,x=p.aabb;for(u.minx=r.minx<x.minx?r.minx:x.minx,u.miny=r.miny<x.miny?r.miny:x.miny,u.maxx=r.maxx>x.maxx?r.maxx:x.maxx,u.maxy=r.maxy>x.maxy?r.maxy:x.maxy,h.height=p.height+1,c!=null?(c.child1==p?c.child1=h:c.child2=h,h.child1=p,h.child2=t,p.parent=h,t.parent=h):(h.child1=p,h.child2=t,p.parent=h,t.parent=h,o.root=h),a=t.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else{let d=a.child1,b=a.child2,g=b.height-d.height;if(g>1){let P=b.child1,v=b.child2;if(b.child1=a,b.parent=a.parent,a.parent=b,b.parent!=null?b.parent.child1==a?b.parent.child1=b:b.parent.child2=b:o.root=b,P.height>v.height){b.child2=P,a.child2=v,v.parent=a;let N=a.aabb,k=d.aabb,C=v.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=b.aabb,M=a.aabb,S=P.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=d.height,L=v.height;a.height=1+(O>L?O:L);let T=a.height,R=P.height;b.height=1+(T>R?T:R)}else{b.child2=v,a.child2=P,P.parent=a;let N=a.aabb,k=d.aabb,C=P.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=b.aabb,M=a.aabb,S=v.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=d.height,L=P.height;a.height=1+(O>L?O:L);let T=a.height,R=v.height;b.height=1+(T>R?T:R)}a=b}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:o.root=d,P.height>v.height){d.child2=P,a.child1=v,v.parent=a;let N=a.aabb,k=b.aabb,C=v.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=d.aabb,M=a.aabb,S=P.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=b.height,L=v.height;a.height=1+(O>L?O:L);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,k=b.aabb,C=P.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=d.aabb,M=a.aabb,S=v.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=b.height,L=P.height;a.height=1+(O>L?O:L);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 f=a.aabb,w=m.aabb,Z=_.aabb;f.minx=w.minx<Z.minx?w.minx:Z.minx,f.miny=w.miny<Z.miny?w.miny:Z.miny,f.maxx=w.maxx>Z.maxx?w.maxx:Z.maxx,f.maxy=w.maxy>Z.maxy?w.maxy:Z.maxy,a=a.parent}}t.synced=!1,t.moved=!0,t.mnext=t.snext,t.snext=null,t=t.mnext}let n=this.syncs;this.syncs=this.moves,this.moves=n}else for(;this.syncs!=null;){let t=this.syncs;this.syncs=t.snext,t.snext=null;let n=t,s=n.shape;if(n.first_sync)n.first_sync=!1;else{let r=n.dyn?this.dtree:this.stree;if(n==r.root)r.root=null;else{let a=n.parent,p=a.parent,c=a.child1==n?a.child2:a.child1;if(p!=null){p.child1==a?p.child1=c:p.child2=c,c.parent=p;let h=a;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=fe.zpp_pool,fe.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Ve.zpp_pool,Ve.zpp_pool=h;let x=p;for(;x!=null;){if(x.child1==null||x.height<2)x=x;else{let d=x.child1,b=x.child2,g=b.height-d.height;if(g>1){let P=b.child1,v=b.child2;if(b.child1=x,b.parent=x.parent,x.parent=b,b.parent!=null?b.parent.child1==x?b.parent.child1=b:b.parent.child2=b:r.root=b,P.height>v.height){b.child2=P,x.child2=v,v.parent=x;let N=x.aabb,k=d.aabb,C=v.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=b.aabb,M=x.aabb,S=P.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=d.height,L=v.height;x.height=1+(O>L?O:L);let T=x.height,R=P.height;b.height=1+(T>R?T:R)}else{b.child2=v,x.child2=P,P.parent=x;let N=x.aabb,k=d.aabb,C=P.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=b.aabb,M=x.aabb,S=v.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=d.height,L=P.height;x.height=1+(O>L?O:L);let T=x.height,R=v.height;b.height=1+(T>R?T:R)}x=b}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:r.root=d,P.height>v.height){d.child2=P,x.child1=v,v.parent=x;let N=x.aabb,k=b.aabb,C=v.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=d.aabb,M=x.aabb,S=P.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=b.height,L=v.height;x.height=1+(O>L?O:L);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,k=b.aabb,C=P.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=d.aabb,M=x.aabb,S=v.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=b.height,L=P.height;x.height=1+(O>L?O:L);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,f=_.aabb;y.minx=z.minx<f.minx?z.minx:f.minx,y.miny=z.miny<f.miny?z.miny:f.miny,y.maxx=z.maxx>f.maxx?z.maxx:f.maxx,y.maxy=z.maxy>f.maxy?z.maxy:f.maxy;let w=m.height,Z=_.height;x.height=1+(w>Z?w:Z),x=x.parent}}else{r.root=c,c.parent=null;let h=a;h.height=-1;let u=h.aabb;u.outer!=null&&(u.outer.zpp_inner=null,u.outer=null),u.wrap_min=u.wrap_max=null,u._invalidate=null,u._validate=null,u.next=fe.zpp_pool,fe.zpp_pool=u,h.child1=h.child2=h.parent=null,h.next=null,h.snext=null,h.mnext=null,h.next=Ve.zpp_pool,Ve.zpp_pool=h}}}let i=n.aabb;if(!this.space.continuous&&s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let r=s.circle;if(r.zip_worldCOM&&r.body!=null){if(r.zip_worldCOM=!1,r.zip_localCOM){if(r.zip_localCOM=!1,r.type==1){let h=r.polygon;if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(h.lverts.next.next==null)h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;else if(h.lverts.next.next.next==null){h.localCOMx=h.lverts.next.x,h.localCOMy=h.lverts.next.y;let u=1;h.localCOMx+=h.lverts.next.next.x*u,h.localCOMy+=h.lverts.next.next.y*u;let x=.5;h.localCOMx*=x,h.localCOMy*=x}else{h.localCOMx=0,h.localCOMy=0;let u=0,x=h.lverts.next,m=x;x=x.next;let _=x;for(x=x.next;x!=null;){let d=x;u+=_.x*(d.y-m.y);let b=d.y*_.x-d.x*_.y;h.localCOMx+=(_.x+d.x)*b,h.localCOMy+=(_.y+d.y)*b,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 f=x;u+=_.x*(f.y-m.y);let w=f.y*_.x-f.x*_.y;h.localCOMx+=(_.x+f.x)*w,h.localCOMy+=(_.y+f.y)*w,u=1/(3*u);let Z=u;h.localCOMx*=Z,h.localCOMy*=Z}}r.wrap_localCOM!=null&&(r.wrap_localCOM.zpp_inner.x=r.localCOMx,r.wrap_localCOM.zpp_inner.y=r.localCOMy)}let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),r.worldCOMx=r.body.posx+(r.body.axisy*r.localCOMx-r.body.axisx*r.localCOMy),r.worldCOMy=r.body.posy+(r.localCOMx*r.body.axisx+r.localCOMy*r.body.axisy)}let a=r.radius,p=r.radius;r.aabb.minx=r.worldCOMx-a,r.aabb.miny=r.worldCOMy-p,r.aabb.maxx=r.worldCOMx+a,r.aabb.maxy=r.worldCOMy+p}else{let r=s.polygon;if(r.zip_gverts&&r.body!=null){r.zip_gverts=!1,r.validate_lverts();let c=r.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=r.lverts.next,u=r.gverts.next;for(;u!=null;){let x=u,m=h;h=h.next,x.x=r.body.posx+(r.body.axisy*m.x-r.body.axisx*m.y),x.y=r.body.posy+(m.x*r.body.axisx+m.y*r.body.axisy),u=u.next}}if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let a=r.gverts.next;r.aabb.minx=a.x,r.aabb.miny=a.y,r.aabb.maxx=a.x,r.aabb.maxy=a.y;let p=r.gverts.next.next;for(;p!=null;){let c=p;c.x<r.aabb.minx&&(r.aabb.minx=c.x),c.x>r.aabb.maxx&&(r.aabb.maxx=c.x),c.y<r.aabb.miny&&(r.aabb.miny=c.y),c.y>r.aabb.maxy&&(r.aabb.maxy=c.y),p=p.next}}let l=s.aabb;i.minx=l.minx-3,i.miny=l.miny-3,i.maxx=l.maxx+3,i.maxy=l.maxy+3;let o=(n.dyn=s.body.type==1?!1:!s.body.component.sleeping)?this.dtree:this.stree;if(o.root==null)o.root=n,o.root.parent=null;else{let r=n.aabb,a=o.root;for(;a.child1!=null;){let m=a.child1,_=a.child2,y=a.aabb,z=(y.maxx-y.minx+(y.maxy-y.miny))*2,f=Qe.tmpaabb,w=a.aabb;f.minx=w.minx<r.minx?w.minx:r.minx,f.miny=w.miny<r.miny?w.miny:r.miny,f.maxx=w.maxx>r.maxx?w.maxx:r.maxx,f.maxy=w.maxy>r.maxy?w.maxy:r.maxy;let Z=Qe.tmpaabb,d=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,b=2*d,g=2*(d-z),P=Qe.tmpaabb,v=m.aabb;P.minx=r.minx<v.minx?r.minx:v.minx,P.miny=r.miny<v.miny?r.miny:v.miny,P.maxx=r.maxx>v.maxx?r.maxx:v.maxx,P.maxy=r.maxy>v.maxy?r.maxy:v.maxy;let N;if(m.child1==null){let M=Qe.tmpaabb;N=(M.maxx-M.minx+(M.maxy-M.miny))*2+g}else{let M=m.aabb,S=(M.maxx-M.minx+(M.maxy-M.miny))*2,O=Qe.tmpaabb;N=(O.maxx-O.minx+(O.maxy-O.miny))*2-S+g}let k=Qe.tmpaabb,C=_.aabb;k.minx=r.minx<C.minx?r.minx:C.minx,k.miny=r.miny<C.miny?r.miny:C.miny,k.maxx=r.maxx>C.maxx?r.maxx:C.maxx,k.maxy=r.maxy>C.maxy?r.maxy:C.maxy;let E;if(_.child1==null){let M=Qe.tmpaabb;E=(M.maxx-M.minx+(M.maxy-M.miny))*2+g}else{let M=_.aabb,S=(M.maxx-M.minx+(M.maxy-M.miny))*2,O=Qe.tmpaabb;E=(O.maxx-O.minx+(O.maxy-O.miny))*2-S+g}if(b<N&&b<E)break;a=N<E?m:_}let p=a,c=p.parent,h;Ve.zpp_pool==null?h=new Ve:(h=Ve.zpp_pool,Ve.zpp_pool=h.next,h.next=null),fe.zpp_pool==null?h.aabb=new fe:(h.aabb=fe.zpp_pool,fe.zpp_pool=h.aabb.next,h.aabb.next=null),h.moved=!1,h.synced=!1,h.first_sync=!1,h.parent=c;let u=h.aabb,x=p.aabb;for(u.minx=r.minx<x.minx?r.minx:x.minx,u.miny=r.miny<x.miny?r.miny:x.miny,u.maxx=r.maxx>x.maxx?r.maxx:x.maxx,u.maxy=r.maxy>x.maxy?r.maxy:x.maxy,h.height=p.height+1,c!=null?(c.child1==p?c.child1=h:c.child2=h,h.child1=p,h.child2=n,p.parent=h,n.parent=h):(h.child1=p,h.child2=n,p.parent=h,n.parent=h,o.root=h),a=n.parent;a!=null;){if(a.child1==null||a.height<2)a=a;else{let d=a.child1,b=a.child2,g=b.height-d.height;if(g>1){let P=b.child1,v=b.child2;if(b.child1=a,b.parent=a.parent,a.parent=b,b.parent!=null?b.parent.child1==a?b.parent.child1=b:b.parent.child2=b:o.root=b,P.height>v.height){b.child2=P,a.child2=v,v.parent=a;let N=a.aabb,k=d.aabb,C=v.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=b.aabb,M=a.aabb,S=P.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=d.height,L=v.height;a.height=1+(O>L?O:L);let T=a.height,R=P.height;b.height=1+(T>R?T:R)}else{b.child2=v,a.child2=P,P.parent=a;let N=a.aabb,k=d.aabb,C=P.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=b.aabb,M=a.aabb,S=v.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=d.height,L=P.height;a.height=1+(O>L?O:L);let T=a.height,R=v.height;b.height=1+(T>R?T:R)}a=b}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:o.root=d,P.height>v.height){d.child2=P,a.child1=v,v.parent=a;let N=a.aabb,k=b.aabb,C=v.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=d.aabb,M=a.aabb,S=P.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=b.height,L=v.height;a.height=1+(O>L?O:L);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,k=b.aabb,C=P.aabb;N.minx=k.minx<C.minx?k.minx:C.minx,N.miny=k.miny<C.miny?k.miny:C.miny,N.maxx=k.maxx>C.maxx?k.maxx:C.maxx,N.maxy=k.maxy>C.maxy?k.maxy:C.maxy;let E=d.aabb,M=a.aabb,S=v.aabb;E.minx=M.minx<S.minx?M.minx:S.minx,E.miny=M.miny<S.miny?M.miny:S.miny,E.maxx=M.maxx>S.maxx?M.maxx:S.maxx,E.maxy=M.maxy>S.maxy?M.maxy:S.maxy;let O=b.height,L=P.height;a.height=1+(O>L?O:L);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 f=a.aabb,w=m.aabb,Z=_.aabb;f.minx=w.minx<Z.minx?w.minx:Z.minx,f.miny=w.miny<Z.miny?w.miny:Z.miny,f.maxx=w.maxx>Z.maxx?w.maxx:Z.maxx,f.maxy=w.maxy>Z.maxy?w.maxy:Z.maxy,a=a.parent}}n.synced=!1,n.moved||(n.moved=!0,n.mnext=this.moves,this.moves=n)}}broadphase(t,n){let s=this.syncs;for(;s!=null;){let l=s.shape;if(s.first_sync)s.first_sync=!1;else{let p=s.dyn?this.dtree:this.stree;if(s==p.root)p.root=null;else{let c=s.parent,h=c.parent,u=c.child1==s?c.child2:c.child1;if(h!=null){h.child1==c?h.child1=u:h.child2=u,u.parent=h;let x=c;x.height=-1;let m=x.aabb;m.outer!=null&&(m.outer.zpp_inner=null,m.outer=null),m.wrap_min=m.wrap_max=null,m._invalidate=null,m._validate=null,m.next=fe.zpp_pool,fe.zpp_pool=m,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ve.zpp_pool,Ve.zpp_pool=x;let _=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,k=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>k.height){P.child2=N,_.child2=k,k.parent=_;let C=_.aabb,E=g.aabb,M=k.aabb;C.minx=E.minx<M.minx?E.minx:M.minx,C.miny=E.miny<M.miny?E.miny:M.miny,C.maxx=E.maxx>M.maxx?E.maxx:M.maxx,C.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let S=P.aabb,O=_.aabb,L=N.aabb;S.minx=O.minx<L.minx?O.minx:L.minx,S.miny=O.miny<L.miny?O.miny:L.miny,S.maxx=O.maxx>L.maxx?O.maxx:L.maxx,S.maxy=O.maxy>L.maxy?O.maxy:L.maxy;let T=g.height,R=k.height;_.height=1+(T>R?T:R);let q=_.height,G=N.height;P.height=1+(q>G?q:G)}else{P.child2=k,_.child2=N,N.parent=_;let C=_.aabb,E=g.aabb,M=N.aabb;C.minx=E.minx<M.minx?E.minx:M.minx,C.miny=E.miny<M.miny?E.miny:M.miny,C.maxx=E.maxx>M.maxx?E.maxx:M.maxx,C.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let S=P.aabb,O=_.aabb,L=k.aabb;S.minx=O.minx<L.minx?O.minx:L.minx,S.miny=O.miny<L.miny?O.miny:L.miny,S.maxx=O.maxx>L.maxx?O.maxx:L.maxx,S.maxy=O.maxy>L.maxy?O.maxy:L.maxy;let T=g.height,R=N.height;_.height=1+(T>R?T:R);let q=_.height,G=k.height;P.height=1+(q>G?q:G)}_=P}else if(v<-1){let N=g.child1,k=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>k.height){g.child2=N,_.child1=k,k.parent=_;let C=_.aabb,E=P.aabb,M=k.aabb;C.minx=E.minx<M.minx?E.minx:M.minx,C.miny=E.miny<M.miny?E.miny:M.miny,C.maxx=E.maxx>M.maxx?E.maxx:M.maxx,C.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let S=g.aabb,O=_.aabb,L=N.aabb;S.minx=O.minx<L.minx?O.minx:L.minx,S.miny=O.miny<L.miny?O.miny:L.miny,S.maxx=O.maxx>L.maxx?O.maxx:L.maxx,S.maxy=O.maxy>L.maxy?O.maxy:L.maxy;let T=P.height,R=k.height;_.height=1+(T>R?T:R);let q=_.height,G=N.height;g.height=1+(q>G?q:G)}else{g.child2=k,_.child1=N,N.parent=_;let C=_.aabb,E=P.aabb,M=N.aabb;C.minx=E.minx<M.minx?E.minx:M.minx,C.miny=E.miny<M.miny?E.miny:M.miny,C.maxx=E.maxx>M.maxx?E.maxx:M.maxx,C.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let S=g.aabb,O=_.aabb,L=k.aabb;S.minx=O.minx<L.minx?O.minx:L.minx,S.miny=O.miny<L.miny?O.miny:L.miny,S.maxx=O.maxx>L.maxx?O.maxx:L.maxx,S.maxy=O.maxy>L.maxy?O.maxy:L.maxy;let T=P.height,R=N.height;_.height=1+(T>R?T:R);let q=_.height,G=k.height;g.height=1+(q>G?q:G)}_=g}else _=_}let y=_.child1,z=_.child2,f=_.aabb,w=y.aabb,Z=z.aabb;f.minx=w.minx<Z.minx?w.minx:Z.minx,f.miny=w.miny<Z.miny?w.miny:Z.miny,f.maxx=w.maxx>Z.maxx?w.maxx:Z.maxx,f.maxy=w.maxy>Z.maxy?w.maxy:Z.maxy;let d=y.height,b=z.height;_.height=1+(d>b?d:b),_=_.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=fe.zpp_pool,fe.zpp_pool=m,x.child1=x.child2=x.parent=null,x.next=null,x.snext=null,x.mnext=null,x.next=Ve.zpp_pool,Ve.zpp_pool=x}}}let o=s.aabb;if(!t.continuous&&l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let p=l.circle;if(p.zip_worldCOM&&p.body!=null){if(p.zip_worldCOM=!1,p.zip_localCOM){if(p.zip_localCOM=!1,p.type==1){let x=p.polygon;if(x.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(x.lverts.next.next==null)x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;else if(x.lverts.next.next.next==null){x.localCOMx=x.lverts.next.x,x.localCOMy=x.lverts.next.y;let m=1;x.localCOMx+=x.lverts.next.next.x*m,x.localCOMy+=x.lverts.next.next.y*m;let _=.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 f=_;m+=z.x*(f.y-y.y);let w=f.y*z.x-f.x*z.y;x.localCOMx+=(z.x+f.x)*w,x.localCOMy+=(z.y+f.y)*w,y=z,z=f,_=_.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 b=m;x.localCOMx*=b,x.localCOMy*=b}}p.wrap_localCOM!=null&&(p.wrap_localCOM.zpp_inner.x=p.localCOMx,p.wrap_localCOM.zpp_inner.y=p.localCOMy)}let u=p.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot)),p.worldCOMx=p.body.posx+(p.body.axisy*p.localCOMx-p.body.axisx*p.localCOMy),p.worldCOMy=p.body.posy+(p.localCOMx*p.body.axisx+p.localCOMy*p.body.axisy)}let c=p.radius,h=p.radius;p.aabb.minx=p.worldCOMx-c,p.aabb.miny=p.worldCOMy-h,p.aabb.maxx=p.worldCOMx+c,p.aabb.maxy=p.worldCOMy+h}else{let p=l.polygon;if(p.zip_gverts&&p.body!=null){p.zip_gverts=!1,p.validate_lverts();let u=p.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let 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 r=l.aabb;o.minx=r.minx-3,o.miny=r.miny-3,o.maxx=r.maxx+3,o.maxy=r.maxy+3;let a=(s.dyn=l.body.type==1?!1:!l.body.component.sleeping)?this.dtree:this.stree;if(a.root==null)a.root=s,a.root.parent=null;else{let p=s.aabb,c=a.root;for(;c.child1!=null;){let y=c.child1,z=c.child2,f=c.aabb,w=(f.maxx-f.minx+(f.maxy-f.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 b=Qe.tmpaabb,g=(b.maxx-b.minx+(b.maxy-b.miny))*2,P=2*g,v=2*(g-w),N=Qe.tmpaabb,k=y.aabb;N.minx=p.minx<k.minx?p.minx:k.minx,N.miny=p.miny<k.miny?p.miny:k.miny,N.maxx=p.maxx>k.maxx?p.maxx:k.maxx,N.maxy=p.maxy>k.maxy?p.maxy:k.maxy;let C;if(y.child1==null){let O=Qe.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2+v}else{let O=y.aabb,L=(O.maxx-O.minx+(O.maxy-O.miny))*2,T=Qe.tmpaabb;C=(T.maxx-T.minx+(T.maxy-T.miny))*2-L+v}let E=Qe.tmpaabb,M=z.aabb;E.minx=p.minx<M.minx?p.minx:M.minx,E.miny=p.miny<M.miny?p.miny:M.miny,E.maxx=p.maxx>M.maxx?p.maxx:M.maxx,E.maxy=p.maxy>M.maxy?p.maxy:M.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,L=(O.maxx-O.minx+(O.maxy-O.miny))*2,T=Qe.tmpaabb;S=(T.maxx-T.minx+(T.maxy-T.miny))*2-L+v}if(P<C&&P<S)break;c=C<S?y:z}let h=c,u=h.parent,x;Ve.zpp_pool==null?x=new Ve:(x=Ve.zpp_pool,Ve.zpp_pool=x.next,x.next=null),fe.zpp_pool==null?x.aabb=new fe:(x.aabb=fe.zpp_pool,fe.zpp_pool=x.aabb.next,x.aabb.next=null),x.moved=!1,x.synced=!1,x.first_sync=!1,x.parent=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,k=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>k.height){P.child2=N,c.child2=k,k.parent=c;let C=c.aabb,E=g.aabb,M=k.aabb;C.minx=E.minx<M.minx?E.minx:M.minx,C.miny=E.miny<M.miny?E.miny:M.miny,C.maxx=E.maxx>M.maxx?E.maxx:M.maxx,C.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let S=P.aabb,O=c.aabb,L=N.aabb;S.minx=O.minx<L.minx?O.minx:L.minx,S.miny=O.miny<L.miny?O.miny:L.miny,S.maxx=O.maxx>L.maxx?O.maxx:L.maxx,S.maxy=O.maxy>L.maxy?O.maxy:L.maxy;let T=g.height,R=k.height;c.height=1+(T>R?T:R);let q=c.height,G=N.height;P.height=1+(q>G?q:G)}else{P.child2=k,c.child2=N,N.parent=c;let C=c.aabb,E=g.aabb,M=N.aabb;C.minx=E.minx<M.minx?E.minx:M.minx,C.miny=E.miny<M.miny?E.miny:M.miny,C.maxx=E.maxx>M.maxx?E.maxx:M.maxx,C.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let S=P.aabb,O=c.aabb,L=k.aabb;S.minx=O.minx<L.minx?O.minx:L.minx,S.miny=O.miny<L.miny?O.miny:L.miny,S.maxx=O.maxx>L.maxx?O.maxx:L.maxx,S.maxy=O.maxy>L.maxy?O.maxy:L.maxy;let T=g.height,R=N.height;c.height=1+(T>R?T:R);let q=c.height,G=k.height;P.height=1+(q>G?q:G)}c=P}else if(v<-1){let N=g.child1,k=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>k.height){g.child2=N,c.child1=k,k.parent=c;let C=c.aabb,E=P.aabb,M=k.aabb;C.minx=E.minx<M.minx?E.minx:M.minx,C.miny=E.miny<M.miny?E.miny:M.miny,C.maxx=E.maxx>M.maxx?E.maxx:M.maxx,C.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let S=g.aabb,O=c.aabb,L=N.aabb;S.minx=O.minx<L.minx?O.minx:L.minx,S.miny=O.miny<L.miny?O.miny:L.miny,S.maxx=O.maxx>L.maxx?O.maxx:L.maxx,S.maxy=O.maxy>L.maxy?O.maxy:L.maxy;let T=P.height,R=k.height;c.height=1+(T>R?T:R);let q=c.height,G=N.height;g.height=1+(q>G?q:G)}else{g.child2=k,c.child1=N,N.parent=c;let C=c.aabb,E=P.aabb,M=N.aabb;C.minx=E.minx<M.minx?E.minx:M.minx,C.miny=E.miny<M.miny?E.miny:M.miny,C.maxx=E.maxx>M.maxx?E.maxx:M.maxx,C.maxy=E.maxy>M.maxy?E.maxy:M.maxy;let S=g.aabb,O=c.aabb,L=k.aabb;S.minx=O.minx<L.minx?O.minx:L.minx,S.miny=O.miny<L.miny?O.miny:L.miny,S.maxx=O.maxx>L.maxx?O.maxx:L.maxx,S.maxy=O.maxy>L.maxy?O.maxy:L.maxy;let T=P.height,R=N.height;c.height=1+(T>R?T:R);let q=c.height,G=k.height;g.height=1+(q>G?q:G)}c=g}else c=c}let y=c.child1,z=c.child2,f=y.height,w=z.height;c.height=1+(f>w?f:w);let Z=c.aabb,d=y.aabb,b=z.aabb;Z.minx=d.minx<b.minx?d.minx:b.minx,Z.miny=d.miny<b.miny?d.miny:b.miny,Z.maxx=d.maxx>b.maxx?d.maxx:b.maxx,Z.maxy=d.maxy>b.maxy?d.maxy:b.maxy,c=c.parent}}s.synced=!1,s=s.snext}for(;this.syncs!=null;){let l=this.syncs;this.syncs=l.snext,l.snext=null;let o=l;if(o.moved)continue;o.moved=!1;let r=o.shape;if(r.body.component.sleeping)continue;let p=o.aabb,c=null;for(this.dtree.root!=null&&(this.dtree.root.next=c,c=this.dtree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let _,y;r.id<x.id?(_=r.id,y=x.id):(_=x.id,y=r.id);let z=r.pairs.length<x.pairs.length?r:x,f=null,w=z.pairs.head;for(;w!=null;){let N=w.elt;if(N.id==_&&N.di==y){f=N;break}w=w.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}st.zpp_pool==null?f=new st:(f=st.zpp_pool,st.zpp_pool=f.next,f.next=null),f.n1=o,f.n2=u,f.id=_,f.di=y,this._linkPair(f),f.first=!0;let Z=r.pairs,d;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new we._zpp.util.ZNPNode_ZPP_AABBPair:(d=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=f;let b=d;b.next=Z.head,Z.head=b,Z.modified=!0,Z.length++;let g=x.pairs,P;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new we._zpp.util.ZNPNode_ZPP_AABBPair:(P=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=f;let v=P;v.next=g.head,g.head=v,g.modified=!0,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!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let _,y;r.id<x.id?(_=r.id,y=x.id):(_=x.id,y=r.id);let z=r.pairs.length<x.pairs.length?r:x,f=null,w=z.pairs.head;for(;w!=null;){let N=w.elt;if(N.id==_&&N.di==y){f=N;break}w=w.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}st.zpp_pool==null?f=new st:(f=st.zpp_pool,st.zpp_pool=f.next,f.next=null),f.n1=o,f.n2=u,f.id=_,f.di=y,this._linkPair(f),f.first=!0;let Z=r.pairs,d;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new we._zpp.util.ZNPNode_ZPP_AABBPair:(d=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=f;let b=d;b.next=Z.head,Z.head=b,Z.modified=!0,Z.length++;let g=x.pairs,P;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new we._zpp.util.ZNPNode_ZPP_AABBPair:(P=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=f;let v=P;v.next=g.head,g.head=v,g.modified=!0,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 o=l;o.moved=!1;let r=o.shape;if(r.body.component.sleeping)continue;let p=o.aabb,c=null;for(this.dtree.root!=null&&(this.dtree.root.next=c,c=this.dtree.root);c!=null;){let h=c;c=h.next,h.next=null;let u=h;if(u!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let _,y;r.id<x.id?(_=r.id,y=x.id):(_=x.id,y=r.id);let z=r.pairs.length<x.pairs.length?r:x,f=null,w=z.pairs.head;for(;w!=null;){let N=w.elt;if(N.id==_&&N.di==y){f=N;break}w=w.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}st.zpp_pool==null?f=new st:(f=st.zpp_pool,st.zpp_pool=f.next,f.next=null),f.n1=o,f.n2=u,f.id=_,f.di=y,this._linkPair(f),f.first=!0;let Z=r.pairs,d;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new we._zpp.util.ZNPNode_ZPP_AABBPair:(d=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=f;let b=d;b.next=Z.head,Z.head=b,Z.modified=!0,Z.length++;let g=x.pairs,P;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new we._zpp.util.ZNPNode_ZPP_AABBPair:(P=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=f;let v=P;v.next=g.head,g.head=v,g.modified=!0,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!=o)if(u.child1==null){let x=u.shape;if(x.body!=r.body&&!(x.body.type==1&&r.body.type==1)){let m=u.aabb;if(m.miny<=p.maxy&&p.miny<=m.maxy&&m.minx<=p.maxx&&p.minx<=m.maxx){let _,y;r.id<x.id?(_=r.id,y=x.id):(_=x.id,y=r.id);let z=r.pairs.length<x.pairs.length?r:x,f=null,w=z.pairs.head;for(;w!=null;){let N=w.elt;if(N.id==_&&N.di==y){f=N;break}w=w.next}if(f!=null){f.sleeping&&(f.sleeping=!1,this._linkPair(f),f.first=!0);continue}st.zpp_pool==null?f=new st:(f=st.zpp_pool,st.zpp_pool=f.next,f.next=null),f.n1=o,f.n2=u,f.id=_,f.di=y,this._linkPair(f),f.first=!0;let Z=r.pairs,d;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?d=new we._zpp.util.ZNPNode_ZPP_AABBPair:(d=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=d.next,d.next=null),d.elt=f;let b=d;b.next=Z.head,Z.head=b,Z.modified=!0,Z.length++;let g=x.pairs,P;we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?P=new we._zpp.util.ZNPNode_ZPP_AABBPair:(P=we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=P.next,P.next=null),P.elt=f;let v=P;v.next=g.head,g.head=v,g.modified=!0,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=!1;else{let u=i.n1.aabb,x=i.n2.aabb;l=!(x.miny<=u.maxy&&u.miny<=x.maxy&&x.minx<=u.maxx&&u.minx<=x.maxx)}if(l){let u=i.next;this._unlinkPair(i),i.n1.shape.pairs.remove(i),i.n2.shape.pairs.remove(i),i.arb!=null&&(i.arb.pair=null),i.arb=null,i.n1=i.n2=null,i.sleeping=!1,i.gprev=null,i.next=st.zpp_pool,st.zpp_pool=i,i=u;continue}let o=i.n1.shape,r=o.body,a=i.n2.shape,p=a.body;if(!i.first&&(r.component.sleeping||r.type==1)&&(p.component.sleeping||p.type==1)){i.sleeping=!0;let u=i.next;this._unlinkPair(i),i=u;continue}i.first=!1;let c=o.aabb,h=a.aabb;if(h.miny<=c.maxy&&c.miny<=h.maxy&&h.minx<=c.maxx&&c.minx<=h.maxx){let u=i.arb;n?i.arb=t.narrowPhase(o,a,r.type!=2||p.type!=2,i.arb,!1):i.arb=t.continuousEvent(o,a,r.type!=2||p.type!=2,i.arb,!1),i.arb==null?u!=null&&(u.pair=null):i.arb.pair=i}i=i.next}}clear(){for(;this.syncs!=null;){let t=this.syncs.snext;this.syncs.snext=null,this.syncs.first_sync&&(this.syncs.shape.node=null,this.syncs.shape.removedFromSpace(),this.syncs.shape=null),this.syncs=t}for(;this.moves!=null;){let t=this.moves.mnext;this.moves.mnext=null,this.moves.first_sync&&(this.moves.shape.node=null,this.moves.shape.removedFromSpace(),this.moves.shape=null),this.moves=t}for(;this.pairs!=null;){let t=this.pairs.next,n=this.pairs;n.arb!=null&&(n.arb.pair=null),n.arb=null,n.n1.shape.pairs.remove(n),n.n2.shape.pairs.remove(n),n.n1=n.n2=null,n.sleeping=!1,n.gprev=null,n.next=st.zpp_pool,st.zpp_pool=n,this.pairs=t}this.dtree.clear(),this.stree.clear()}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l;pe.zpp_pool==null?l=new pe:(l=pe.zpp_pool,pe.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,r=i??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.y<=c.maxy)if(p.child1==null){let h;if(s!=null){let u=p.shape.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.shape.type==0?Ee.circleContains(p.shape.circle,o)&&r.push(p.shape.outer):Ee.polyContains(p.shape.polygon,o)&&r.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.y<=c.maxy)if(p.child1==null){let h;if(s!=null){let u=p.shape.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.shape.type==0?Ee.circleContains(p.shape.circle,o)&&r.push(p.shape.outer):Ee.polyContains(p.shape.polygon,o)&&r.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let a=o;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=pe.zpp_pool,pe.zpp_pool=a,r}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l;pe.zpp_pool==null?l=new pe:(l=pe.zpp_pool,pe.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,r=i??new we._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!r.has(h)){let u;if(s!=null){let x=p.shape.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(p.shape.type==0?Ee.circleContains(p.shape.circle,o)&&r.push(h):Ee.polyContains(p.shape.polygon,o)&&r.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.x>=c.minx&&o.x<=c.maxx&&o.y>=c.miny&&o.y<=c.maxy)if(p.child1==null){let h=p.shape.body.outer;if(!r.has(h)){let u;if(s!=null){let x=p.shape.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(p.shape.type==0?Ee.circleContains(p.shape.circle,o)&&r.push(h):Ee.polyContains(p.shape.polygon,o)&&r.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let a=o;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=pe.zpp_pool,pe.zpp_pool=a,r}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&r.push(a.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;h&&r.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h;if(i!=null){let u=a.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n)if(s)Ee.containTest(this.aabbShape.zpp_inner,a.shape)&&r.push(a.shape.outer);else{let u=a.shape.aabb;(u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy||Ee.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&r.push(a.shape.outer)}else{let u;if(s){let x=a.shape.aabb;u=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy}else u=!0;u&&r.push(a.shape.outer)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&r.push(a.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;h&&r.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h;if(i!=null){let u=a.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n)if(s)Ee.containTest(this.aabbShape.zpp_inner,a.shape)&&r.push(a.shape.outer);else{let u=a.shape.aabb;(u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy||Ee.testCollide_safe(a.shape,this.aabbShape.zpp_inner))&&r.push(a.shape.outer)}else{let u;if(s){let x=a.shape.aabb;u=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy}else u=!0;u&&r.push(a.shape.outer)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}return r}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new we._nape.phys.BodyList;if(this.failed==null&&(this.failed=new we._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=a.shape.body.outer;r.has(h)||r.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h){let u=c.shape.body.outer;r.has(u)||r.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let x=a.shape.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(h)){let x=Ee.containTest(this.aabbShape.zpp_inner,a.shape);!r.has(h)&&x?r.push(h):x||(r.remove(h),this.failed.push(h))}}else!r.has(h)&&Ee.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&r.push(h);else if(s){if(!this.failed.has(h)){let x=a.shape.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(h)&&m?r.push(h):m||(r.remove(h),this.failed.push(h))}}else{let x;if(r.has(h))x=!1;else{let m=a.shape.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(h)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),p=a.aabb;if(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(a.child1==null){let c;if(i!=null){let h=a.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=a.shape.body.outer;r.has(h)||r.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(a);this.treeStack2.head!=null;){let c=this.treeStack2.pop_unsafe();if(c.child1==null){let h;if(i!=null){let u=c.shape.filter;h=(u.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&u.collisionGroup)!=0}else h=!0;if(h){let u=c.shape.body.outer;r.has(u)||r.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=a.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(a.child1==null){let h=a.shape.body.outer,u;if(i!=null){let x=a.shape.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(h)){let x=Ee.containTest(this.aabbShape.zpp_inner,a.shape);!r.has(h)&&x?r.push(h):x||(r.remove(h),this.failed.push(h))}}else!r.has(h)&&Ee.testCollide_safe(a.shape,this.aabbShape.zpp_inner)&&r.push(h);else if(s){if(!this.failed.has(h)){let x=a.shape.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(h)&&m?r.push(h):m||(r.remove(h),this.failed.push(h))}}else{let x;if(r.has(h))x=!1;else{let m=a.shape.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(h)}}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}}return this.failed.clear(),r}shapesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(p.child1==null){let h;if(l!=null){let u=p.shape.filter;h=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(i?Ee.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(p.child1==null){let h;if(l!=null){let u=p.shape.filter;h=(u.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(i?Ee.containTest(this.circShape.zpp_inner,p.shape)&&a.push(p.shape.outer):Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return a}bodiesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new we._nape.phys.BodyList;if(this.failed==null&&(this.failed=new we._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(p.child1==null){let h=p.shape.body.outer,u;if(l!=null){let x=p.shape.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(i){if(!this.failed.has(h)){let x=Ee.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)&&Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(h)}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx)if(p.child1==null){let h=p.shape.body.outer,u;if(l!=null){let x=p.shape.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(i){if(!this.failed.has(h)){let x=Ee.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)&&Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&a.push(h)}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new we._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p;if(s!=null){let c=r.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ee.containTest(t,r.shape)&&o.push(r.shape.outer):Ee.testCollide_safe(r.shape,t)&&o.push(r.shape.outer))}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p;if(s!=null){let c=r.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ee.containTest(t,r.shape)&&o.push(r.shape.outer):Ee.testCollide_safe(r.shape,t)&&o.push(r.shape.outer))}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}return o}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new we._nape.phys.BodyList;if(this.failed==null&&(this.failed=new we._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p=r.shape.body.outer,c;if(s!=null){let h=r.shape.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;if(c)if(n){if(!this.failed.has(p)){let h=Ee.containTest(t,r.shape);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ee.testCollide_safe(r.shape,t)&&o.push(p)}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new we._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx)if(r.child1==null){let p=r.shape.body.outer,c;if(s!=null){let h=r.shape.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;if(c)if(n){if(!this.failed.has(p)){let h=Ee.containTest(t,r.shape);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ee.testCollide_safe(r.shape,t)&&o.push(p)}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}return this.failed.clear(),o}rayCast(t,n,s){this.openlist==null&&(this.openlist=new we._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let i=t.maxdist;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb)){let o=t.aabbsect(this.dtree.root.aabb);if(o>=0&&o<i){this.dtree.root.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(this.dtree.root.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=this.dtree.root,h;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new we._zpp.util.ZNPNode_ZPP_AABBNode:(h=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;r==null?(u.next=p.head,p.head=u):(u.next=r.next,r.next=u),p.pushmod=p.modified=!0,p.length++}}if(this.stree.root!=null&&t.aabbtest(this.stree.root.aabb)){let o=t.aabbsect(this.stree.root.aabb);if(o>=0&&o<i){this.stree.root.rayt=o;let r=null,a=this.openlist.head;for(;a!=null;){let x=a.elt;if(this.stree.root.rayt<x.rayt)break;r=a,a=a.next}let p=this.openlist,c=this.stree.root,h;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new we._zpp.util.ZNPNode_ZPP_AABBNode:(h=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;r==null?(u.next=p.head,p.head=u):(u.next=r.next,r.next=u),p.pushmod=p.modified=!0,p.length++}}let l=null;for(;this.openlist.head!=null;){let o=this.openlist.pop_unsafe();if(o.rayt>=i)break;if(o.child1==null){let r=o.shape,a;if(s!=null){let p=r.filter;a=(p.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&p.collisionGroup)!=0}else a=!0;if(a){let p=r.type==0?t.circlesect(r.circle,n,i):t.aabbtest(r.aabb)?t.polysect(r.polygon,n,i):null;if(p!=null){if(p.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(i=p.zpp_inner.toiDistance,l!=null){if(l.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");l.zpp_inner.free()}l=p}}}else{if(o.child1!=null&&t.aabbtest(o.child1.aabb)){let r=t.aabbsect(o.child1.aabb);if(r>=0&&r<i){o.child1.rayt=r;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(o.child1.rayt<m.rayt)break;a=p,p=p.next}let c=this.openlist,h=o.child1,u;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new we._zpp.util.ZNPNode_ZPP_AABBNode:(u=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;a==null?(x.next=c.head,c.head=x):(x.next=a.next,a.next=x),c.pushmod=c.modified=!0,c.length++}}if(o.child2!=null&&t.aabbtest(o.child2.aabb)){let r=t.aabbsect(o.child2.aabb);if(r>=0&&r<i){o.child2.rayt=r;let a=null,p=this.openlist.head;for(;p!=null;){let m=p.elt;if(o.child2.rayt<m.rayt)break;a=p,p=p.next}let c=this.openlist,h=o.child2,u;we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new we._zpp.util.ZNPNode_ZPP_AABBNode:(u=we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,we._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;a==null?(x.next=c.head,c.head=x):(x.next=a.next,a.next=x),c.pushmod=c.modified=!0,c.length++}}}}return this.openlist.clear(),l}rayMultiCast(t,n,s,i){this.openlist==null&&(this.openlist=new we._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let l=t.maxdist>=1/0,o=i??new we._nape.geom.RayResultList;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb))if(l)this.openlist.add(this.dtree.root);else{let r=t.aabbsect(this.dtree.root.aabb);r>=0&&r<t.maxdist&&this.openlist.add(this.dtree.root)}if(this.stree.root!=null&&t.aabbtest(this.stree.root.aabb))if(l)this.openlist.add(this.stree.root);else{let r=t.aabbsect(this.stree.root.aabb);r>=0&&r<t.maxdist&&this.openlist.add(this.stree.root)}for(;this.openlist.head!=null;){let r=this.openlist.pop_unsafe();if(r.child1==null){let a=r.shape,p;if(s!=null){let c=a.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(a.type==0?t.circlesect2(a.circle,n,o):t.aabbtest(a.aabb)&&t.polysect2(a.polygon,n,o))}else{if(r.child1!=null&&t.aabbtest(r.child1.aabb))if(l)this.openlist.add(r.child1);else{let a=t.aabbsect(r.child1.aabb);a>=0&&a<t.maxdist&&this.openlist.add(r.child1)}if(r.child2!=null&&t.aabbtest(r.child2.aabb))if(l)this.openlist.add(r.child2);else{let a=t.aabbsect(r.child2.aabb);a>=0&&a<t.maxdist&&this.openlist.add(r.child2)}}}return this.openlist.clear(),o}};we._zpp=null,we._nape=null,we.FATTEN=3,we.VEL_STEPS=2;var ps=we;var Os=class Os{constructor(){this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.comps=null;this.sleep=!1;this.waket=0;this.comps=new Os._zpp.util.ZNPList_ZPP_Component}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){}alloc(){this.waket=0}};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=!1;this.body=null;this.constraint=null;this.island=null;this.sleeping=!1;this.waket=0;this.woken=!1;this._inuse=!1}free(){this.body=null,this.constraint=null}alloc(){}reset(){this.sleeping=!1,this.island=null,this.parent=this,this.rank=0}};Ss.zpp_pool=null;var jn=class jn{constructor(){this.id=0;this.di=0;this.int1=null;this.int2=null;this.arbiters=null;this.COLLISIONstate=null;this.COLLISIONstamp=null;this.SENSORstate=null;this.SENSORstamp=null;this.FLUIDstate=null;this.FLUIDstamp=null;this.length=0;this.pushmod=!1;this.modified=!1;this._inuse=!1;this.next=null;this.freed=!1;this.lazydel=!1;this.arbiters=new jn._zpp.util.ZNPList_ZPP_Arbiter}static get(e,t){let n;return jn.zpp_pool==null?n=new jn:(n=jn.zpp_pool,jn.zpp_pool=n.next,n.next=null),n.freed=!1,n.lazydel=!1,n.COLLISIONstate=1,n.COLLISIONstamp=0,n.SENSORstate=1,n.SENSORstamp=0,n.FLUIDstate=1,n.FLUIDstamp=0,e.id<t.id?(n.int1=e,n.int2=t):(n.int1=t,n.int2=e),n.id=n.int1.id,n.di=n.int2.id,n}elem(){return this}begin(){return this.next}setbegin(e){this.next=e,this.modified=!0,this.pushmod=!0}add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}inlined_add(e){e._inuse=!0;let t=e;return t.next=this.next,this.next=t,this.modified=!0,this.length++,e}addAll(e){let t=e.next;for(;t!=null;){let n=t;this.add(n),t=t.next}}insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}inlined_insert(e,t){t._inuse=!0;let n=t;return e==null?(n.next=this.next,this.next=n):(n.next=e.next,e.next=n),this.pushmod=this.modified=!0,this.length++,n}pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}inlined_pop(){let e=this.next;this.next=e.next,e._inuse=!1,this.next==null&&(this.pushmod=!0),this.modified=!0,this.length--}pop_unsafe(){let e=this.next;return this.pop(),e}inlined_pop_unsafe(){let e=this.next;return this.pop(),e}remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){this.erase(t),s=!0;break}t=n,n=n.next}return s}inlined_remove(e){let t=null,n=this.next;for(;n!=null;){if(n==e){let s,i;t==null?(s=this.next,i=s.next,this.next=i,this.next==null&&(this.pushmod=!0)):(s=t.next,i=s.next,t.next=i,i==null&&(this.pushmod=!0)),s._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0;break}t=n,n=n.next}}inlined_try_remove(e){let t=null,n=this.next,s=!1;for(;n!=null;){if(n==e){let i,l;t==null?(i=this.next,l=i.next,this.next=l,this.next==null&&(this.pushmod=!0)):(i=t.next,l=i.next,t.next=l,l==null&&(this.pushmod=!0)),i._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,s=!0;break}t=n,n=n.next}return s}erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}inlined_erase(e){let t,n;return e==null?(t=this.next,n=t.next,this.next=n,this.next==null&&(this.pushmod=!0)):(t=e.next,n=t.next,e.next=n,n==null&&(this.pushmod=!0)),t._inuse=!1,this.modified=!0,this.length--,this.pushmod=!0,n}splice(e,t){for(;t-- >0&&e.next!=null;)this.erase(e);return e.next}clear(){}inlined_clear(){}reverse(){let e=this.next,t=null;for(;e!=null;){let n=e.next;e.next=t,this.next=e,t=e,e=n}this.modified=!0,this.pushmod=!0}empty(){return this.next==null}size(){return this.length}has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}inlined_has(e){let t=!1,n=this.next;for(;n!=null;){if(n==e){t=!0;break}n=n.next}return t}front(){return this.next}back(){let e=this.next,t=e;for(;t!=null;)e=t,t=t.next;return e}iterator_at(e){let t=this.next;for(;e-- >0&&t!=null;)t=t.next;return t}at(e){let t=this.iterator_at(e);return t??null}free(){this.int1=this.int2=null,this.id=this.di=-1,this.freed=!0}alloc(){this.freed=!1,this.lazydel=!1,this.COLLISIONstate=1,this.COLLISIONstamp=0,this.SENSORstate=1,this.SENSORstamp=0,this.FLUIDstate=1,this.FLUIDstamp=0}add_arb(e){let t=!1,n=this.arbiters.head;for(;n!=null;){if(n.elt==e){t=!0;break}n=n.next}if(t)return!1;{let s=this.arbiters,i,l=jn._zpp.util.ZNPNode_ZPP_Arbiter;l.zpp_pool==null?i=new l:(i=l.zpp_pool,l.zpp_pool=i.next,i.next=null),i.elt=e;let o=i;return o.next=s.head,s.head=o,s.modified=!0,s.length++,!0}}try_remove_arb(e){let t=this.arbiters,n=null,s=t.head,i=!1;for(;s!=null;){if(s.elt==e){let l,o;n==null?(l=t.head,o=l.next,t.head=o,t.head==null&&(t.pushmod=!0)):(l=n.next,o=l.next,n.next=o,o==null&&(t.pushmod=!0));let r=l;r.elt=null;let a=jn._zpp.util.ZNPNode_ZPP_Arbiter;r.next=a.zpp_pool,a.zpp_pool=r,t.modified=!0,t.length--,t.pushmod=!0,i=!0;break}n=s,s=s.next}return i}remove_arb(e){let t=this.arbiters,n=null,s=t.head;for(;s!=null;){if(s.elt==e){let i,l;n==null?(i=t.head,l=i.next,t.head=l,t.head==null&&(t.pushmod=!0)):(i=n.next,l=i.next,n.next=l,l==null&&(t.pushmod=!0));let o=i;o.elt=null;let r=jn._zpp.util.ZNPNode_ZPP_Arbiter;o.next=r.zpp_pool,r.zpp_pool=o,t.modified=!0,t.length--,t.pushmod=!0;break}n=s,s=s.next}}empty_arb(e){let t=!0,n=this.arbiters.head;for(;n!=null;)if((n.elt.type&e)==0){n=n.next;continue}else{t=!1;break}return t}really_empty(){return this.arbiters.head==null}sleeping(){let e=!0,t=this.arbiters.head;for(;t!=null;)if(t.elt.sleeping){t=t.next;continue}else{e=!1;break}return e}};jn.zpp_pool=null,jn._zpp=null;var Kt=jn;var ai=class ai{constructor(e){this.cbsets=null;this.space=null;let t=ai._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=ai._zpp.callbacks.ZPP_CbSet.setlt,this.space=e}get(e){if(e.head==null)return null;let t=ai._zpp.callbacks.ZPP_CbSet,n;t.zpp_pool==null?n=new t:(n=t.zpp_pool,t.zpp_pool=n.next,n.next=null);let s=n.cbTypes;n.cbTypes=e;let i=this.cbsets.find_weak(n),l;if(i!=null)l=i.data;else{let r=t.get(e);this.cbsets.insert(r),r.manager=this,l=r}n.cbTypes=s;let o=n;for(o.listeners.clear(),o.zip_listeners=!0,o.bodylisteners.clear(),o.zip_bodylisteners=!0,o.conlisteners.clear(),o.zip_conlisteners=!0;o.cbTypes.head!=null;)o.cbTypes.pop_unsafe().cbsets.remove(o);return o.next=t.zpp_pool,t.zpp_pool=o,l}remove(e){let t=ai._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=ai._zpp.callbacks.ZPP_CbSet,s=ai._zpp.callbacks.ZPP_CbSetPair,i=null,o=(e.cbpairs.length<t.cbpairs.length?e.cbpairs:t.cbpairs).head;for(;o!=null;){let r=o.elt;if(r.a==e&&r.b==t||r.a==t&&r.b==e){i=r;break}o=o.next}if(i==null){let r;s.zpp_pool==null?r=new s:(r=s.zpp_pool,s.zpp_pool=r.next,r.next=null),r.zip_listeners=!0,n.setlt(e,t)?(r.a=e,r.b=t):(r.a=t,r.b=e),i=r,e.cbpairs.add(i),t!=e&&t.cbpairs.add(i)}return i.zip_listeners&&(i.zip_listeners=!1,i.__validate()),i}valid_listener(e){return e.space==this.space}};ai._zpp=null;var qi=ai;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=!1;this.time=0;this.sortcontacts=!1;this.c_arbiters_true=null;this.c_arbiters_false=null;this.f_arbiters=null;this.s_arbiters=null;this.wrap_arbiters=null;this.live=null;this.wrap_live=null;this.live_constraints=null;this.wrap_livecon=null;this.staticsleep=null;this.islands=null;this.listeners=null;this.wrap_listeners=null;this.callbacks=null;this.callbackset_list=null;this.cbsets=null;this.convexShapeList=null;this.pre_dt=0;this.toiEvents=null;this.continuous=!1;this.precb=null;this.prelisteners=null;this.mrca1=null;this.mrca2=null;this.prelisteners=null,this.precb=null,this.continuous=!1,this.toiEvents=null,this.pre_dt=0,this.convexShapeList=null,this.cbsets=null,this.callbackset_list=null,this.callbacks=null,this.wrap_listeners=null,this.listeners=null,this.islands=null,this.staticsleep=null,this.wrap_livecon=null,this.live_constraints=null,this.wrap_live=null,this.live=null,this.wrap_arbiters=null,this.s_arbiters=null,this.f_arbiters=null,this.c_arbiters_false=null,this.c_arbiters_true=null,this.sortcontacts=!1,this.time=0,this.midstep=!1,this.stamp=0,this.global_ang_drag=0,this.global_lin_drag=0,this.__static=null,this.bphase=null,this.kinematics=null,this.wrap_constraints=null,this.constraints=null,this.wrap_compounds=null,this.compounds=null,this.wrap_bodies=null,this.bodies=null,this.wrap_gravity=null,this.gravityy=0,this.gravityx=0,this.userData=null,this.outer=null,this.toiEvents=new I._zpp.util.ZNPList_ZPP_ToiEvent,this.global_lin_drag=.015,this.global_ang_drag=.015,Tt.internal=!0,this.precb=Tt._createPreCb(),this.precb.zpp_inner=new Tt,Tt.internal=!1,this.sortcontacts=!0,this.pre_dt=0;let n;t!=null?(U.Broadphase_DYNAMIC_AABB_TREE==null&&(U.internal=!0,U.Broadphase_DYNAMIC_AABB_TREE=new I._nape.space.Broadphase,U.internal=!1),n=t==U.Broadphase_DYNAMIC_AABB_TREE):n=!0,n?this.bphase=new I._zpp.space.ZPP_DynAABBPhase(this):(U.Broadphase_SWEEP_AND_PRUNE==null&&(U.internal=!0,U.Broadphase_SWEEP_AND_PRUNE=new I._nape.space.Broadphase,U.internal=!1),t==U.Broadphase_SWEEP_AND_PRUNE&&(this.bphase=new I._zpp.space.ZPP_SweepPhase(this))),this.time=0;let s=this;e!=null?(this.gravityx=e.x,this.gravityy=e.y):(this.gravityx=0,this.gravityy=0),this.bodies=new 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,!0),this.staticsleep=new I._zpp.util.ZNPList_ZPP_Body,this.constraints=new I._zpp.util.ZNPList_ZPP_Constraint,this.wrap_constraints=I._zpp.util.ZPP_ConstraintList.get(this.constraints),this.wrap_constraints.zpp_inner.adder=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,!0),this.__static=Cn.__static(),this.__static.zpp_inner.space=this,this.callbacks=new Tt,this.midstep=!1,this.listeners=new I._zpp.util.ZNPList_ZPP_Listener,this.wrap_listeners=I._zpp.util.ZPP_ListenerList.get(this.listeners),this.wrap_listeners.zpp_inner.adder=i=>this.listeners_adder(i),this.wrap_listeners.zpp_inner.subber=i=>this.listeners_subber(i),this.wrap_listeners.zpp_inner._modifiable=()=>this.listeners_modifiable(),this.callbackset_list=new Kt,this.mrca1=new 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 qi(this)}getgravity(){let e=this.gravityx,t=this.gravityy;if(t==null&&(t=0),e==null&&(e=0),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let n;if(I._zpp.util.ZPP_PubPool.poolVec2==null?n=new I._nape.geom.Vec2:(n=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=n.zpp_pool,n.zpp_pool=null,n.zpp_disp=!1,n==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),n.zpp_inner==null){let s;pe.zpp_pool==null?s=new pe:(s=pe.zpp_pool,pe.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,n.zpp_inner=s,n.zpp_inner.outer=n}else{if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let s=n.zpp_inner;if(s._immutable)throw new Error("Error: Vec2 is immutable");if(s._isimmutable!=null&&s._isimmutable(),e!=e||t!=t)throw new Error("Error: Vec2 components cannot be NaN");let i;if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=n.zpp_inner;if(l._validate!=null&&l._validate(),n.zpp_inner.x==e){if(n!=null&&n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=n.zpp_inner;o._validate!=null&&o._validate(),i=n.zpp_inner.y==t}else i=!1;if(!i){n.zpp_inner.x=e,n.zpp_inner.y=t;let o=n.zpp_inner;o._invalidate!=null&&o._invalidate(o)}}n.zpp_inner.weak=!1,this.wrap_gravity=n,this.wrap_gravity.zpp_inner._inuse=!0,this.wrap_gravity.zpp_inner._invalidate=s=>this.gravity_invalidate(s),this.wrap_gravity.zpp_inner._validate=()=>this.gravity_validate()}gravity_invalidate(e){if(this.midstep)throw new Error("Error: Space::gravity cannot be set during space step");this.gravityx=e.x,this.gravityy=e.y;let t=new 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=!0),l.component.sleeping&&this.really_wake(l,!1)),n=n.next}let s=this.compounds.head;for(;s!=null;){let i=s.elt;t.add(i),s=s.next}for(;t.head!=null;){let i=t.pop_unsafe(),l=i.bodies.head;for(;l!=null;){let a=l.elt;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1)),l=l.next}let o=i.compounds.head;for(;o!=null;){let r=o.elt;t.add(r),o=o.next}}}gravity_validate(){this.wrap_gravity.zpp_inner.x=this.gravityx,this.wrap_gravity.zpp_inner.y=this.gravityy}clear(){for(;this.listeners.head!=null;){let t=this.listeners.pop_unsafe();this.remListener(t)}for(;this.callbackset_list.next!=null;){let t=this.callbackset_list.pop_unsafe();t.arbiters.clear();let n=t;n.int1=n.int2=null,n.id=n.di=-1,n.freed=!0,n.next=Kt.zpp_pool,Kt.zpp_pool=n}for(;this.c_arbiters_true.head!=null;){let t=this.c_arbiters_true.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,o=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=!0,s.length--,s.pushmod=!0,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;let o=t.innards,r=o.next;o.next=r.next,r._inuse=!1,o.next==null&&(o.pushmod=!0),o.modified=!0,o.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=ut.zpp_pool,ut.zpp_pool=n,t.pre_dt=-1}for(;this.c_arbiters_false.head!=null;){let t=this.c_arbiters_false.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,o=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=!0,s.length--,s.pushmod=!0,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=Pe.zpp_pool,Pe.zpp_pool=l;let o=t.innards,r=o.next;o.next=r.next,r._inuse=!1,o.next==null&&(o.pushmod=!0),o.modified=!0,o.length--}let n=t;n.userdef_dyn_fric=!1,n.userdef_stat_fric=!1,n.userdef_restitution=!1,n.userdef_rfric=!1,n.__ref_edge1=n.__ref_edge2=null,n.next=ut.zpp_pool,ut.zpp_pool=n,t.pre_dt=-1}for(;this.s_arbiters.head!=null;){let t=this.s_arbiters.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,o=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=!0,s.length--,s.pushmod=!0,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}t.b1=t.b2=null,t.active=!1,t.intchange=!1;let n=t;n.next=Ot.zpp_pool,Ot.zpp_pool=n}for(;this.f_arbiters.head!=null;){let t=this.f_arbiters.pop_unsafe();if(!t.cleared){let s=t.b1.arbiters,i=null,l=s.head,o=!1;for(;l!=null;){if(l.elt==t){let h,u;i==null?(h=s.head,u=h.next,s.head=u,s.head==null&&(s.pushmod=!0)):(h=i.next,u=h.next,i.next=u,u==null&&(s.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,s.modified=!0,s.length--,s.pushmod=!0,o=!0;break}i=l,l=l.next}let r=t.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}t.b1=t.b2=null,t.active=!1,t.intchange=!1;let n=t;n.next=Pt.zpp_pool,Pt.zpp_pool=n,t.pre_dt=-1}for(this.bphase.clear();this.bodies.head!=null;){let t=this.bodies.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let i=n.comps.pop_unsafe();i.sleeping=!1,i.island=null,i.parent=i,i.rank=0}let s=n;s.next=xt.zpp_pool,xt.zpp_pool=s}}t.removedFromSpace(),t.space=null}for(;this.constraints.head!=null;){let t=this.constraints.pop_unsafe();if(t.component!=null){let n=t.component.island;if(n!=null){for(;n.comps.head!=null;){let i=n.comps.pop_unsafe();i.sleeping=!1,i.island=null,i.parent=i,i.rank=0}let s=n;s.next=xt.zpp_pool,xt.zpp_pool=s}}t.removedFromSpace(),t.space=null}this.kinematics.clear();let e=new 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 o=l.component.island;if(o!=null){for(;o.comps.head!=null;){let a=o.comps.pop_unsafe();a.sleeping=!1,a.island=null,a.parent=a,a.rank=0}let r=o;r.next=xt.zpp_pool,xt.zpp_pool=r}}l.removedFromSpace(),l.space=null,n=n.next}let s=t.constraints.head;for(;s!=null;){let l=s.elt;if(l.component!=null){let o=l.component.island;if(o!=null){for(;o.comps.head!=null;){let a=o.comps.pop_unsafe();a.sleeping=!1,a.island=null,a.parent=a,a.rank=0}let r=o;r.next=xt.zpp_pool,xt.zpp_pool=r}}l.removedFromSpace(),l.space=null,s=s.next}let i=t.compounds.head;for(;i!=null;){let l=i.elt;e.add(l),i=i.next}}this.staticsleep.clear(),this.live.clear(),this.live_constraints.clear(),this.stamp=0,this.time=0,this.mrca1.clear(),this.mrca2.clear(),this.prelisteners.clear(),this.cbsets.clear()}bodies_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Body belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_bodies.remove(e),this.addBody(e.zpp_inner),!0):!1}bodies_subber(e){this.remBody(e.zpp_inner)}bodies_modifiable(){if(this.midstep)throw new Error("Error: Space::bodies cannot be set during space step()")}compounds_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of an inner Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.wrap_compounds.remove(e),this.addCompound(e.zpp_inner),!0):!1}compounds_subber(e){this.remCompound(e.zpp_inner)}compounds_modifiable(){if(this.midstep)throw new Error("Error: Space::compounds cannot be set during space step()")}constraints_adder(e){if(e.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_constraints.remove(e),this.addConstraint(e.zpp_inner),!0):!1}constraints_subber(e){this.remConstraint(e.zpp_inner)}constraints_modifiable(){if(this.midstep)throw new Error("Error: Space::constraints cannot be set during space step()")}listeners_adder(e){return e.zpp_inner.space!=this?(e.zpp_inner.space!=null&&e.zpp_inner.space.outer.zpp_inner.wrap_listeners.remove(e),this.addListener(e.zpp_inner),!0):!1}listeners_subber(e){this.remListener(e.zpp_inner)}listeners_modifiable(){if(this.midstep)throw new Error("Error: Space::listeners cannot be set during space step()")}revoke_listener(e){}unrevoke_listener(e){}addListener(e){e.space=this,e.addedToSpace();let t=e.interaction!=null}remListener(e){let t=e.interaction!=null;e.removedFromSpace(),e.space=null}add_callbackset(e){let t=e.int1.cbsets,n;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=!0,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 o=l;o.next=i.head,i.head=o,i.modified=!0,i.length++;let r=this.callbackset_list;e._inuse=!0;let a=e;a.next=r.next,r.next=a,r.modified=!0,r.length++}remove_callbackset(e){e.lazydel=!0;let t=e.int1.cbsets,n=null,s=t.head,i=!1;for(;s!=null;){if(s.elt==e){let p,c;n==null?(p=t.head,c=p.next,t.head=c,t.head==null&&(t.pushmod=!0)):(p=n.next,c=p.next,n.next=c,c==null&&(t.pushmod=!0));let h=p;h.elt=null,h.next=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=h,t.modified=!0,t.length--,t.pushmod=!0,i=!0;break}n=s,s=s.next}let l=e.int2.cbsets,o=null,r=l.head,a=!1;for(;r!=null;){if(r.elt==e){let p,c;o==null?(p=l.head,c=p.next,l.head=c,l.head==null&&(l.pushmod=!0)):(p=o.next,c=p.next,o.next=c,c==null&&(l.pushmod=!0));let h=p;h.elt=null,h.next=I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool,I._zpp.util.ZNPNode_ZPP_CallbackSet.zpp_pool=h,l.modified=!0,l.length--,l.pushmod=!0,a=!0;break}o=r,r=r.next}}transmitType(e,t){let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!1)),e.type==2?this.live.remove(e):e.type==3?(this.kinematics.remove(e),this.staticsleep.remove(e)):e.type==1&&this.staticsleep.remove(e),e.type=t,e.type==3&&this.kinematics.add(e),e.type==1&&this.static_validation(e),e.component.sleeping=!0;let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0))}added_shape(e,t){if(t==null&&(t=!1),!t){let n=e.body;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!1))}this.bphase.insert(e),e.addedToSpace()}removed_shape(e,t){t==null&&(t=!1);let n=e.body;t||n.wake();let s=null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(l.ws1==e||l.ws2==e){if(l.present!=0){this.MRCA_chains(l.ws1,l.ws2);let r=this.mrca1.head;for(;r!=null;){let a=r.elt,p=this.mrca2.head;for(;p!=null;){let c=p.elt,h=a.cbSet,u=c.cbSet;h.validate(),u.validate();let x=h.manager,m=null,y=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;y!=null;){let 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=!0,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=!1,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--;let f=h.manager,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=!0,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=!1,w.__validate());let b=w.listeners.head;for(;b!=null;){let g=b.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,k,C=g.options1,E=v.cbTypes;if(C.nonemptyintersection(E,C.includes)&&!C.nonemptyintersection(E,C.excludes)){let M=g.options2,S=N.cbTypes;k=M.nonemptyintersection(S,M.includes)&&!M.nonemptyintersection(S,M.excludes)}else k=!1;k?(P.int1=v,P.int2=N):(P.int1=N,P.int2=v),P.set=z}b=b.next}z.arbiters.head==null&&this.remove_callbackset(z),p=p.next}r=r.next}}if(l.b1!=n&&l.b1.type==2){let r=l.b1;r.world||(r.component.waket=this.stamp+(this.midstep?0:1),r.type==3&&(r.kinematicDelaySleep=!0),r.component.sleeping&&this.really_wake(r,!1))}if(l.b2!=n&&l.b2.type==2){let r=l.b2;r.world||(r.component.waket=this.stamp+(this.midstep?0:1),r.type==3&&(r.kinematicDelaySleep=!0),r.component.sleeping&&this.really_wake(r,!1))}if(l.cleared=!0,n==null||l.b2==n){let r=l.b1.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}}if(n==null||l.b1==n){let r=l.b2.arbiters,a=null,p=r.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;a==null?(h=r.head,u=h.next,r.head=u,r.head==null&&(r.pushmod=!0)):(h=a.next,u=h.next,a.next=u,u==null&&(r.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=x,r.modified=!0,r.length--,r.pushmod=!0,c=!0;break}a=p,p=p.next}}l.pair!=null&&(l.pair.arb=null,l.pair=null),l.active=!1,this.f_arbiters.modified=!0,i=n.arbiters.erase(s);continue}s=i,i=i.next}this.bphase.remove(e),e.removedFromSpace()}addConstraint(e){e.space=this,e.addedToSpace(),e.active&&(e.component.sleeping=!0,this.wake_constraint(e,!0))}remConstraint(e){e.active&&(this.wake_constraint(e,!0),this.live_constraints.remove(e)),e.removedFromSpace(),e.space=null}addCompound(e){e.space=this,e.addedToSpace();let t=e.bodies.head;for(;t!=null;){let i=t.elt;this.addBody(i),t=t.next}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.addConstraint(i),n=n.next}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.addCompound(i),s=s.next}}remCompound(e){let t=e.bodies.head;for(;t!=null;){let i=t.elt;this.remBody(i),t=t.next}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.remConstraint(i),n=n.next}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.remCompound(i),s=s.next}e.removedFromSpace(),e.space=null}addBody(e,t){t==null&&(t=-1),e.space=this,e.addedToSpace(),e.component.sleeping=!0;let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,!0));let s=e.shapes.head;for(;s!=null;){let i=s.elt,l=!0;if(l==null&&(l=!1),!l){let o=i.body;o.world||(o.component.waket=this.stamp+(this.midstep?0:1),o.type==3&&(o.kinematicDelaySleep=!0),o.component.sleeping&&this.really_wake(o,!1))}this.bphase.insert(i),i.addedToSpace(),s=s.next}e.type==1?this.static_validation(e):e.type!=2&&t!=3&&this.kinematics.add(e)}remBody(e,t){if(t==null&&(t=-1),e.type==1){let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0)),this.staticsleep.remove(e)}else if(e.type==2){let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0)),this.live.remove(e)}else{t!=3&&this.kinematics.remove(e);let s=e;s.world||(s.component.waket=this.stamp+(this.midstep?0:1),s.type==3&&(s.kinematicDelaySleep=!0),s.component.sleeping&&this.really_wake(s,!0)),this.staticsleep.remove(e)}let n=e.shapes.head;for(;n!=null;){let s=n.elt;this.removed_shape(s,!0),n=n.next}e.removedFromSpace(),e.space=null}shapesUnderPoint(e,t,n,s){return this.bphase.shapesUnderPoint(e,t,n,s)}bodiesUnderPoint(e,t,n,s){return this.bphase.bodiesUnderPoint(e,t,n,s)}shapesInAABB(e,t,n,s,i){return this.bphase.shapesInAABB(e.zpp_inner,t,n,s,i)}bodiesInAABB(e,t,n,s,i){return this.bphase.bodiesInAABB(e.zpp_inner,t,n,s,i)}shapesInCircle(e,t,n,s,i){let l=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;o._validate!=null&&o._validate();let r=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=e.zpp_inner;return a._validate!=null&&a._validate(),l.shapesInCircle(r,e.zpp_inner.y,t,n,s,i)}bodiesInCircle(e,t,n,s,i){let l=this.bphase;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=e.zpp_inner;o._validate!=null&&o._validate();let r=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=e.zpp_inner;return a._validate!=null&&a._validate(),l.bodiesInCircle(r,e.zpp_inner.y,t,n,s,i)}shapesInShape(e,t,n,s){return this.bphase.shapesInShape(e,t,n,s)}bodiesInShape(e,t,n,s){return this.bphase.bodiesInShape(e,t,n,s)}rayCast(e,t,n){return this.bphase.rayCast(e.zpp_inner,t,n==null?null:n.zpp_inner)}rayMultiCast(e,t,n,s){return this.bphase.rayMultiCast(e.zpp_inner,t,n==null?null:n.zpp_inner,s)}convexCast(e,t,n,s){let i;if(I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?i=new I._zpp.geom.ZPP_ToiEvent:(i=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=i.next,i.next=null),i.failed=!1,i.s1=i.s2=null,i.arbiter=null,e.type==0){let O=e.circle;if(O.zip_worldCOM&&O.body!=null){if(O.zip_worldCOM=!1,O.zip_localCOM){if(O.zip_localCOM=!1,O.type==1){let T=O.polygon;if(T.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(T.lverts.next.next==null)T.localCOMx=T.lverts.next.x,T.localCOMy=T.lverts.next.y;else if(T.lverts.next.next.next==null){T.localCOMx=T.lverts.next.x,T.localCOMy=T.lverts.next.y;let R=1;T.localCOMx+=T.lverts.next.next.x*R,T.localCOMy+=T.lverts.next.next.y*R;let q=.5;T.localCOMx*=q,T.localCOMy*=q}else{T.localCOMx=0,T.localCOMy=0;let R=0,q=T.lverts.next,G=q;q=q.next;let B=q;for(q=q.next;q!=null;){let ee=q;R+=B.x*(ee.y-G.y);let W=ee.y*B.x-ee.x*B.y;T.localCOMx+=(B.x+ee.x)*W,T.localCOMy+=(B.y+ee.y)*W,G=B,B=ee,q=q.next}q=T.lverts.next;let V=q;R+=B.x*(V.y-G.y);let Y=V.y*B.x-V.x*B.y;T.localCOMx+=(B.x+V.x)*Y,T.localCOMy+=(B.y+V.y)*Y,G=B,B=V,q=q.next;let $=q;R+=B.x*($.y-G.y);let X=$.y*B.x-$.x*B.y;T.localCOMx+=(B.x+$.x)*X,T.localCOMy+=(B.y+$.y)*X,R=1/(3*R);let H=R;T.localCOMx*=H,T.localCOMy*=H}}O.wrap_localCOM!=null&&(O.wrap_localCOM.zpp_inner.x=O.localCOMx,O.wrap_localCOM.zpp_inner.y=O.localCOMy)}let L=O.body;L.zip_axis&&(L.zip_axis=!1,L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.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 if(e.type===2){let O=e.capsule;if(O.zip_worldCOM&&O.body!=null){O.zip_worldCOM=!1,O.zip_localCOM&&(O.zip_localCOM=!1,O.wrap_localCOM!=null&&(O.wrap_localCOM.zpp_inner.x=O.localCOMx,O.wrap_localCOM.zpp_inner.y=O.localCOMy));let L=O.body;L.zip_axis&&(L.zip_axis=!1,L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.rot)),O.worldCOMx=O.body.posx+(O.body.axisy*O.localCOMx-O.body.axisx*O.localCOMy),O.worldCOMy=O.body.posy+(O.localCOMx*O.body.axisx+O.localCOMy*O.body.axisy)}}else{let O=e.polygon;if(O.zip_gaxi&&O.body!=null){O.zip_gaxi=!1,O.validate_laxi();let L=O.body;if(L.zip_axis&&(L.zip_axis=!1,L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.rot)),O.zip_gverts&&O.body!=null){O.zip_gverts=!1,O.validate_lverts();let V=O.body;V.zip_axis&&(V.zip_axis=!1,V.axisx=Math.sin(V.rot),V.axisy=Math.cos(V.rot));let Y=O.lverts.next,$=O.gverts.next;for(;$!=null;){let X=$,H=Y;Y=Y.next,X.x=O.body.posx+(O.body.axisy*H.x-O.body.axisx*H.y),X.y=O.body.posy+(H.x*O.body.axisx+H.y*O.body.axisy),$=$.next}}let T=O.edges.head,R=O.gverts.next,q=R;for(R=R.next;R!=null;){let V=R,Y=T.elt;T=T.next,Y.gp0=q,Y.gp1=V,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,q=V,R=R.next}let G=O.gverts.next,B=T.elt;T=T.next,B.gp0=q,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,o=l.posx,r=l.posy;l.sweepTime=0,l.sweep_angvel=l.angvel;let a=t-l.sweepTime;if(a!=0){l.sweepTime=t;let O=a;if(l.posx+=l.velx*O,l.posy+=l.vely*O,l.angvel!=0){let L=l.sweep_angvel*a;if(l.rot+=L,L*L>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let T=L*L,R=1-.5*T,q=1-T*T/8,G=(R*l.axisx+L*l.axisy)*q;l.axisy=(R*l.axisy-L*l.axisx)*q,l.axisx=G}}}let p=l.posx,c=l.posy;e.validate_sweepRadius();let h=e.sweepRadius,u;fe.zpp_pool==null?u=new fe:(u=fe.zpp_pool,fe.zpp_pool=u.next,u.next=null);let x=o,m=p;u.minx=(x<m?x:m)-h;let _=o,y=p;u.maxx=(_>y?_:y)+h;let z=r,f=c;u.miny=(z<f?z:f)-h;let w=r,Z=c;u.maxy=(w>Z?w:Z)+h;let d=this.convexShapeList=this.bphase.shapesInAABB(u,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),b=u;b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b.wrap_min=b.wrap_max=null,b._invalidate=null,b._validate=null,b.next=fe.zpp_pool,fe.zpp_pool=b;let g=0,P=0;g=0,P=0;let v=0,N=0;v=0,N=0;let k=null,C=t+1;d.zpp_inner.valmod();let E=I._nape.shape.ShapeIterator.get(d);for(;;){E.zpp_inner.zpp_inner.valmod();let O=E.zpp_inner;O.zpp_inner.valmod(),O.zpp_inner.zip_length&&(O.zpp_inner.zip_length=!1,O.zpp_inner.user_length=O.zpp_inner.inner.length);let L=O.zpp_inner.user_length;E.zpp_critical=!0;let T;if(E.zpp_i<L?T=!0:(E.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=E,E.zpp_inner=null,T=!1),!T)break;E.zpp_critical=!1;let R=E.zpp_inner.at(E.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,gn.dynamicSweep(i,t,0,0,!0);let q=(R.zpp_inner.body!=null?R.zpp_inner.body.outer:null).zpp_inner,G=0-q.sweepTime;if(G!=0){q.sweepTime=0;let Y=G;if(q.posx+=q.velx*Y,q.posy+=q.vely*Y,q.angvel!=0){let $=q.sweep_angvel*G;if(q.rot+=$,$*$>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else{let X=$*$,H=1-.5*X,ee=1-X*X/8,W=(H*q.axisx+$*q.axisy)*ee;q.axisy=(H*q.axisy-$*q.axisx)*ee,q.axisx=W}}}let B=(R.zpp_inner.body!=null?R.zpp_inner.body.outer:null).zpp_inner,V=R.zpp_inner;if(V.type==0||V.type===2)V.worldCOMx=B.posx+(B.axisy*V.localCOMx-B.axisx*V.localCOMy),V.worldCOMy=B.posy+(V.localCOMx*B.axisx+V.localCOMy*B.axisy);else{let Y=V.polygon,$=Y.lverts.next,X=Y.gverts.next;for(;X!=null;){let A=X,J=$;$=$.next,A.x=B.posx+(B.axisy*J.x-B.axisx*J.y),A.y=B.posy+(J.x*B.axisx+J.y*B.axisy),X=X.next}let H=Y.edges.head,ee=Y.gverts.next,W=ee;for(ee=ee.next;ee!=null;){let A=ee,J=H.elt;H=H.next,J.gnormx=B.axisy*J.lnormx-B.axisx*J.lnormy,J.gnormy=J.lnormx*B.axisx+J.lnormy*B.axisy,J.gprojection=B.posx*J.gnormx+B.posy*J.gnormy+J.lprojection,J.tp0=W.y*J.gnormx-W.x*J.gnormy,J.tp1=A.y*J.gnormx-A.x*J.gnormy,W=A,ee=ee.next}let F=Y.gverts.next,D=H.elt;H=H.next,D.gnormx=B.axisy*D.lnormx-B.axisx*D.lnormy,D.gnormy=D.lnormx*B.axisx+D.lnormy*B.axisy,D.gprojection=B.posx*D.gnormx+B.posy*D.gnormy+D.lprojection,D.tp0=W.y*D.gnormx-W.x*D.gnormy,D.tp1=F.y*D.gnormx-F.x*D.gnormy}}else gn.staticSweep(i,t,0,0);i.toi*=t,i.toi>0&&i.toi<C&&(C=i.toi,g=i.axis.x,P=i.axis.y,v=i.c2.x,N=i.c2.y,k=R)}}d.clear();let M=i;M.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=M;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 L=l.sweep_angvel*S;if(l.rot+=L,L*L>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let T=L*L,R=1-.5*T,q=1-T*T/8,G=(R*l.axisx+L*l.axisy)*q;l.axisy=(R*l.axisy-L*l.axisx)*q,l.axisx=G}}}if(e.type==0||e.type===2)e.worldCOMx=l.posx+(l.axisy*e.localCOMx-l.axisx*e.localCOMy),e.worldCOMy=l.posy+(e.localCOMx*l.axisx+e.localCOMy*l.axisy);else{let O=e.polygon,L=O.lverts.next,T=O.gverts.next;for(;T!=null;){let Y=T,$=L;L=L.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,q=O.gverts.next,G=q;for(q=q.next;q!=null;){let Y=q,$=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,q=q.next}let B=O.gverts.next,V=R.elt;R=R.next,V.gnormx=l.axisy*V.lnormx-l.axisx*V.lnormy,V.gnormy=V.lnormx*l.axisx+V.lnormy*l.axisy,V.gprojection=l.posx*V.gnormx+l.posy*V.gnormy+V.lprojection,V.tp0=G.y*V.gnormx-G.x*V.gnormy,V.tp1=B.y*V.gnormx-B.x*V.gnormy}if(C<=t){let O=-g,L=-P;if(L==null&&(L=0),O==null&&(O=0),O!=O||L!=L)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=!1,T==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),T.zpp_inner==null){let B;pe.zpp_pool==null?B=new pe:(B=pe.zpp_pool,pe.zpp_pool=B.next,B.next=null),B.weak=!1,B._immutable=!1,B.x=O,B.y=L,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||L!=L)throw new Error("Error: Vec2 components cannot be NaN");let V;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let 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(),V=T.zpp_inner.y==L}else V=!1;if(!V){T.zpp_inner.x=O,T.zpp_inner.y=L;let $=T.zpp_inner;$._invalidate!=null&&$._invalidate($)}}T.zpp_inner.weak=!1;let R=v,q=N;if(q==null&&(q=0),R==null&&(R=0),R!=R||q!=q)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=!1,G==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),G.zpp_inner==null){let B;pe.zpp_pool==null?B=new pe:(B=pe.zpp_pool,pe.zpp_pool=B.next,B.next=null),B.weak=!1,B._immutable=!1,B.x=R,B.y=q,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||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let V;if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Y=G.zpp_inner;if(Y._validate!=null&&Y._validate(),G.zpp_inner.x==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(),V=G.zpp_inner.y==q}else V=!1;if(!V){G.zpp_inner.x=R,G.zpp_inner.y=q;let $=G.zpp_inner;$._invalidate!=null&&$._invalidate($)}}return G.zpp_inner.weak=!1,I._zpp.geom.ZPP_ConvexRayResult.getConvex(T,G,C,k)}else return null}prepareCast(e){if(e.type==0){let t=e.circle;if(t.zip_worldCOM&&t.body!=null){if(t.zip_worldCOM=!1,t.zip_localCOM){if(t.zip_localCOM=!1,t.type==1){let s=t.polygon;if(s.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(s.lverts.next.next==null)s.localCOMx=s.lverts.next.x,s.localCOMy=s.lverts.next.y;else if(s.lverts.next.next.next==null){s.localCOMx=s.lverts.next.x,s.localCOMy=s.lverts.next.y;let i=1;s.localCOMx+=s.lverts.next.next.x*i,s.localCOMy+=s.lverts.next.next.y*i;let l=.5;s.localCOMx*=l,s.localCOMy*=l}else{s.localCOMx=0,s.localCOMy=0;let i=0,l=s.lverts.next,o=l;l=l.next;let r=l;for(l=l.next;l!=null;){let x=l;i+=r.x*(x.y-o.y);let m=x.y*r.x-x.x*r.y;s.localCOMx+=(r.x+x.x)*m,s.localCOMy+=(r.y+x.y)*m,o=r,r=x,l=l.next}l=s.lverts.next;let a=l;i+=r.x*(a.y-o.y);let p=a.y*r.x-a.x*r.y;s.localCOMx+=(r.x+a.x)*p,s.localCOMy+=(r.y+a.y)*p,o=r,r=a,l=l.next;let c=l;i+=r.x*(c.y-o.y);let h=c.y*r.x-c.x*r.y;s.localCOMx+=(r.x+c.x)*h,s.localCOMy+=(r.y+c.y)*h,i=1/(3*i);let u=i;s.localCOMx*=u,s.localCOMy*=u}}t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy)}let n=t.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}}else if(e.type===2){let t=e.capsule;if(t.zip_worldCOM&&t.body!=null){t.zip_worldCOM=!1,t.zip_localCOM&&(t.zip_localCOM=!1,t.wrap_localCOM!=null&&(t.wrap_localCOM.zpp_inner.x=t.localCOMx,t.wrap_localCOM.zpp_inner.y=t.localCOMy));let n=t.body;n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.worldCOMx=t.body.posx+(t.body.axisy*t.localCOMx-t.body.axisx*t.localCOMy),t.worldCOMy=t.body.posy+(t.localCOMx*t.body.axisx+t.localCOMy*t.body.axisy)}}else{let t=e.polygon;if(t.zip_gaxi&&t.body!=null){t.zip_gaxi=!1,t.validate_laxi();let n=t.body;if(n.zip_axis&&(n.zip_axis=!1,n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot)),t.zip_gverts&&t.body!=null){t.zip_gverts=!1,t.validate_lverts();let a=t.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let p=t.lverts.next,c=t.gverts.next;for(;c!=null;){let h=c,u=p;p=p.next,h.x=t.body.posx+(t.body.axisy*u.x-t.body.axisx*u.y),h.y=t.body.posy+(u.x*t.body.axisx+u.y*t.body.axisy),c=c.next}}let s=t.edges.head,i=t.gverts.next,l=i;for(i=i.next;i!=null;){let a=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=a,p.gnormx=t.body.axisy*p.lnormx-t.body.axisx*p.lnormy,p.gnormy=p.lnormx*t.body.axisx+p.lnormy*t.body.axisy,p.gprojection=t.body.posx*p.gnormx+t.body.posy*p.gnormy+p.lprojection,p.wrap_gnorm!=null&&(p.wrap_gnorm.zpp_inner.x=p.gnormx,p.wrap_gnorm.zpp_inner.y=p.gnormy),p.tp0=p.gp0.y*p.gnormx-p.gp0.x*p.gnormy,p.tp1=p.gp1.y*p.gnormx-p.gp1.x*p.gnormy,l=a,i=i.next}let o=t.gverts.next,r=s.elt;s=s.next,r.gp0=l,r.gp1=o,r.gnormx=t.body.axisy*r.lnormx-t.body.axisx*r.lnormy,r.gnormy=r.lnormx*t.body.axisx+r.lnormy*t.body.axisy,r.gprojection=t.body.posx*r.gnormx+t.body.posy*r.gnormy+r.lprojection,r.wrap_gnorm!=null&&(r.wrap_gnorm.zpp_inner.x=r.gnormx,r.wrap_gnorm.zpp_inner.y=r.gnormy),r.tp0=r.gp0.y*r.gnormx-r.gp0.x*r.gnormy,r.tp1=r.gp1.y*r.gnormx-r.gp1.x*r.gnormy}}}convexMultiCast(e,t,n,s,i){let l;if(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=!1,l.s1=l.s2=null,l.arbiter=null,e.type==0){let C=e.circle;if(C.zip_worldCOM&&C.body!=null){if(C.zip_worldCOM=!1,C.zip_localCOM){if(C.zip_localCOM=!1,C.type==1){let M=C.polygon;if(M.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(M.lverts.next.next==null)M.localCOMx=M.lverts.next.x,M.localCOMy=M.lverts.next.y;else if(M.lverts.next.next.next==null){M.localCOMx=M.lverts.next.x,M.localCOMy=M.lverts.next.y;let S=1;M.localCOMx+=M.lverts.next.next.x*S,M.localCOMy+=M.lverts.next.next.y*S;let O=.5;M.localCOMx*=O,M.localCOMy*=O}else{M.localCOMx=0,M.localCOMy=0;let S=0,O=M.lverts.next,L=O;O=O.next;let T=O;for(O=O.next;O!=null;){let Y=O;S+=T.x*(Y.y-L.y);let $=Y.y*T.x-Y.x*T.y;M.localCOMx+=(T.x+Y.x)*$,M.localCOMy+=(T.y+Y.y)*$,L=T,T=Y,O=O.next}O=M.lverts.next;let R=O;S+=T.x*(R.y-L.y);let q=R.y*T.x-R.x*T.y;M.localCOMx+=(T.x+R.x)*q,M.localCOMy+=(T.y+R.y)*q,L=T,T=R,O=O.next;let G=O;S+=T.x*(G.y-L.y);let B=G.y*T.x-G.x*T.y;M.localCOMx+=(T.x+G.x)*B,M.localCOMy+=(T.y+G.y)*B,S=1/(3*S);let V=S;M.localCOMx*=V,M.localCOMy*=V}}C.wrap_localCOM!=null&&(C.wrap_localCOM.zpp_inner.x=C.localCOMx,C.wrap_localCOM.zpp_inner.y=C.localCOMy)}let E=C.body;E.zip_axis&&(E.zip_axis=!1,E.axisx=Math.sin(E.rot),E.axisy=Math.cos(E.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)}}else if(e.type===2){let C=e.capsule;if(C.zip_worldCOM&&C.body!=null){C.zip_worldCOM=!1,C.zip_localCOM&&(C.zip_localCOM=!1,C.wrap_localCOM!=null&&(C.wrap_localCOM.zpp_inner.x=C.localCOMx,C.wrap_localCOM.zpp_inner.y=C.localCOMy));let E=C.body;E.zip_axis&&(E.zip_axis=!1,E.axisx=Math.sin(E.rot),E.axisy=Math.cos(E.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)}}else{let C=e.polygon;if(C.zip_gaxi&&C.body!=null){C.zip_gaxi=!1,C.validate_laxi();let E=C.body;if(E.zip_axis&&(E.zip_axis=!1,E.axisx=Math.sin(E.rot),E.axisy=Math.cos(E.rot)),C.zip_gverts&&C.body!=null){C.zip_gverts=!1,C.validate_lverts();let R=C.body;R.zip_axis&&(R.zip_axis=!1,R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.rot));let q=C.lverts.next,G=C.gverts.next;for(;G!=null;){let B=G,V=q;q=q.next,B.x=C.body.posx+(C.body.axisy*V.x-C.body.axisx*V.y),B.y=C.body.posy+(V.x*C.body.axisx+V.y*C.body.axisy),G=G.next}}let M=C.edges.head,S=C.gverts.next,O=S;for(S=S.next;S!=null;){let R=S,q=M.elt;M=M.next,q.gp0=O,q.gp1=R,q.gnormx=C.body.axisy*q.lnormx-C.body.axisx*q.lnormy,q.gnormy=q.lnormx*C.body.axisx+q.lnormy*C.body.axisy,q.gprojection=C.body.posx*q.gnormx+C.body.posy*q.gnormy+q.lprojection,q.wrap_gnorm!=null&&(q.wrap_gnorm.zpp_inner.x=q.gnormx,q.wrap_gnorm.zpp_inner.y=q.gnormy),q.tp0=q.gp0.y*q.gnormx-q.gp0.x*q.gnormy,q.tp1=q.gp1.y*q.gnormx-q.gp1.x*q.gnormy,O=R,S=S.next}let L=C.gverts.next,T=M.elt;M=M.next,T.gp0=O,T.gp1=L,T.gnormx=C.body.axisy*T.lnormx-C.body.axisx*T.lnormy,T.gnormy=T.lnormx*C.body.axisx+T.lnormy*C.body.axisy,T.gprojection=C.body.posx*T.gnormx+C.body.posy*T.gnormy+T.lprojection,T.wrap_gnorm!=null&&(T.wrap_gnorm.zpp_inner.x=T.gnormx,T.wrap_gnorm.zpp_inner.y=T.gnormy),T.tp0=T.gp0.y*T.gnormx-T.gp0.x*T.gnormy,T.tp1=T.gp1.y*T.gnormx-T.gp1.x*T.gnormy}}let o=e.body,r=o.posx,a=o.posy;o.sweepTime=0,o.sweep_angvel=o.angvel;let p=t-o.sweepTime;if(p!=0){o.sweepTime=t;let C=p;if(o.posx+=o.velx*C,o.posy+=o.vely*C,o.angvel!=0){let E=o.sweep_angvel*p;if(o.rot+=E,E*E>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let M=E*E,S=1-.5*M,O=1-M*M/8,L=(S*o.axisx+E*o.axisy)*O;o.axisy=(S*o.axisy-E*o.axisx)*O,o.axisx=L}}}let c=o.posx,h=o.posy;e.validate_sweepRadius();let u=e.sweepRadius,x;fe.zpp_pool==null?x=new fe:(x=fe.zpp_pool,fe.zpp_pool=x.next,x.next=null);let m=r,_=c;x.minx=(m<_?m:_)-u;let y=r,z=c;x.maxx=(y>z?y:z)+u;let f=a,w=h;x.miny=(f<w?f:w)-u;let Z=a,d=h;x.maxy=(Z>d?Z:d)+u;let b=this.convexShapeList=this.bphase.shapesInAABB(x,!1,!1,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=fe.zpp_pool,fe.zpp_pool=g;let P=i??new I._nape.geom.ConvexResultList;b.zpp_inner.valmod();let v=I._nape.shape.ShapeIterator.get(b);for(;;){v.zpp_inner.zpp_inner.valmod();let C=v.zpp_inner;C.zpp_inner.valmod(),C.zpp_inner.zip_length&&(C.zpp_inner.zip_length=!1,C.zpp_inner.user_length=C.zpp_inner.inner.length);let E=C.zpp_inner.user_length;v.zpp_critical=!0;let M;if(v.zpp_i<E?M=!0:(v.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=v,v.zpp_inner=null,M=!1),!M)break;v.zpp_critical=!1;let S=v.zpp_inner.at(v.zpp_i++);if(S!=e.outer&&(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null)!=o.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,gn.dynamicSweep(l,t,0,0,!0);let O=(S.zpp_inner.body!=null?S.zpp_inner.body.outer:null).zpp_inner,L=0-O.sweepTime;if(L!=0){O.sweepTime=0;let q=L;if(O.posx+=O.velx*q,O.posy+=O.vely*q,O.angvel!=0){let G=O.sweep_angvel*L;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,V=1-.5*B,Y=1-B*B/8,$=(V*O.axisx+G*O.axisy)*Y;O.axisy=(V*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.type===2)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 q=R.polygon,G=q.lverts.next,B=q.gverts.next;for(;B!=null;){let ee=B,W=G;G=G.next,ee.x=T.posx+(T.axisy*W.x-T.axisx*W.y),ee.y=T.posy+(W.x*T.axisx+W.y*T.axisy),B=B.next}let V=q.edges.head,Y=q.gverts.next,$=Y;for(Y=Y.next;Y!=null;){let ee=Y,W=V.elt;V=V.next,W.gnormx=T.axisy*W.lnormx-T.axisx*W.lnormy,W.gnormy=W.lnormx*T.axisx+W.lnormy*T.axisy,W.gprojection=T.posx*W.gnormx+T.posy*W.gnormy+W.lprojection,W.tp0=$.y*W.gnormx-$.x*W.gnormy,W.tp1=ee.y*W.gnormx-ee.x*W.gnormy,$=ee,Y=Y.next}let X=q.gverts.next,H=V.elt;V=V.next,H.gnormx=T.axisy*H.lnormx-T.axisx*H.lnormy,H.gnormy=H.lnormx*T.axisx+H.lnormy*T.axisy,H.gprojection=T.posx*H.gnormx+T.posy*H.gnormy+H.lprojection,H.tp0=$.y*H.gnormx-$.x*H.gnormy,H.tp1=X.y*H.gnormx-X.x*H.gnormy}}else gn.staticSweep(l,t,0,0);if(l.toi*=t,l.toi>0){let O=-l.axis.x,L=-l.axis.y;if(L==null&&(L=0),O==null&&(O=0),O!=O||L!=L)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=!1,T==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),T.zpp_inner==null){let ee;pe.zpp_pool==null?ee=new pe:(ee=pe.zpp_pool,pe.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=O,ee.y=L,T.zpp_inner=ee,T.zpp_inner.outer=T}else{if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=T.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),O!=O||L!=L)throw new Error("Error: Vec2 components cannot be NaN");let W;if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=T.zpp_inner;if(F._validate!=null&&F._validate(),T.zpp_inner.x==O){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=T.zpp_inner;D._validate!=null&&D._validate(),W=T.zpp_inner.y==L}else W=!1;if(!W){T.zpp_inner.x=O,T.zpp_inner.y=L;let D=T.zpp_inner;D._invalidate!=null&&D._invalidate(D)}}T.zpp_inner.weak=!1;let R=l.c2.x,q=l.c2.y;if(q==null&&(q=0),R==null&&(R=0),R!=R||q!=q)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=!1,G==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),G.zpp_inner==null){let ee;pe.zpp_pool==null?ee=new pe:(ee=pe.zpp_pool,pe.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=R,ee.y=q,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||q!=q)throw new Error("Error: Vec2 components cannot be NaN");let W;if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=G.zpp_inner;if(F._validate!=null&&F._validate(),G.zpp_inner.x==R){if(G!=null&&G.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let D=G.zpp_inner;D._validate!=null&&D._validate(),W=G.zpp_inner.y==q}else W=!1;if(!W){G.zpp_inner.x=R,G.zpp_inner.y=q;let D=G.zpp_inner;D._invalidate!=null&&D._invalidate(D)}}G.zpp_inner.weak=!1;let B=I._zpp.geom.ZPP_ConvexRayResult.getConvex(T,G,l.toi,S),V=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;V=Y,Y=Y.next}let $=P.zpp_inner.inner,X;I._zpp.util.ZNPNode_ConvexResult.zpp_pool==null?X=new I._zpp.util.ZNPNode_ConvexResult:(X=I._zpp.util.ZNPNode_ConvexResult.zpp_pool,I._zpp.util.ZNPNode_ConvexResult.zpp_pool=X.next,X.next=null),X.elt=B;let H=X;V==null?(H.next=$.head,$.head=H):(H.next=V.next,V.next=H),$.pushmod=$.modified=!0,$.length++}}}b.clear();let N=l;N.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=N;let k=0-o.sweepTime;if(k!=0){o.sweepTime=0;let C=k;if(o.posx+=o.velx*C,o.posy+=o.vely*C,o.angvel!=0){let E=o.sweep_angvel*k;if(o.rot+=E,E*E>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let M=E*E,S=1-.5*M,O=1-M*M/8,L=(S*o.axisx+E*o.axisy)*O;o.axisy=(S*o.axisy-E*o.axisx)*O,o.axisx=L}}}if(e.type==0||e.type===2)e.worldCOMx=o.posx+(o.axisy*e.localCOMx-o.axisx*e.localCOMy),e.worldCOMy=o.posy+(e.localCOMx*o.axisx+e.localCOMy*o.axisy);else{let C=e.polygon,E=C.lverts.next,M=C.gverts.next;for(;M!=null;){let q=M,G=E;E=E.next,q.x=o.posx+(o.axisy*G.x-o.axisx*G.y),q.y=o.posy+(G.x*o.axisx+G.y*o.axisy),M=M.next}let S=C.edges.head,O=C.gverts.next,L=O;for(O=O.next;O!=null;){let q=O,G=S.elt;S=S.next,G.gnormx=o.axisy*G.lnormx-o.axisx*G.lnormy,G.gnormy=G.lnormx*o.axisx+G.lnormy*o.axisy,G.gprojection=o.posx*G.gnormx+o.posy*G.gnormy+G.lprojection,G.tp0=L.y*G.gnormx-L.x*G.gnormy,G.tp1=q.y*G.gnormx-q.x*G.gnormy,L=q,O=O.next}let T=C.gverts.next,R=S.elt;S=S.next,R.gnormx=o.axisy*R.lnormx-o.axisx*R.lnormy,R.gnormy=R.lnormx*o.axisx+R.lnormy*o.axisy,R.gprojection=o.posx*R.gnormx+o.posy*R.gnormy+R.lprojection,R.tp0=L.y*R.gnormx-L.x*R.gnormy,R.tp1=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=!0);let l=n.shapes.head;for(;l!=null;){let o=l.elt;o.type==1&&(o.polygon.invalidate_gverts(),o.polygon.invalidate_gaxi()),o.invalidate_worldCOM(),l=l.next}n.zip_worldCOM=!0}t=t.next}}step(e,t,n){if(this.midstep)throw new Error("Error: ... REALLY?? you're going to call space.step() inside of space.step()? COME ON!!");this.time+=e,this.pre_dt=e,this.midstep=!0,this.stamp++;try{if(this.validation(),this.bphase.broadphase(this,!0),this.prestep(e),this.sortcontacts){let p=this.c_arbiters_false;if(p.head!=null&&p.head.next!=null){let c=p.head,h=null,u=null,x=null,m=null,_=1,y,z,f;for(;;){for(y=0,u=c,c=null,h=c;u!=null;){for(++y,x=u,z=0,f=_;x!=null&&z<_;)++z,x=x.next;for(;z>0||f>0&&x!=null;)z==0?(m=x,x=x.next,--f):f==0||x==null||!(u.elt.active&&x.elt.active)||u.elt.oc1.dist<x.elt.oc1.dist?(m=u,u=u.next,--z):(m=x,x=x.next,--f),h!=null?h.next=m:c=m,h=m;u=x}if(h.next=null,_<<=1,!(y>1))break}p.head=c,p.modified=!0,p.pushmod=!0}}this.updateVel(e),this.warmStart(),this.iterateVel(t);let l=this.kinematics.head;for(;l!=null;){let p=l.elt;p.pre_posx=p.posx,p.pre_posy=p.posy,p.pre_rot=p.rot,l=l.next}let o=this.live.head;for(;o!=null;){let p=o.elt;p.pre_posx=p.posx,p.pre_posy=p.posy,p.pre_rot=p.rot,o=o.next}this.updatePos(e),this.continuous=!0,this.continuousCollisions(e),this.continuous=!1,this.iteratePos(n),this._invalidateBodyList(this.kinematics),this._invalidateBodyList(this.live);let r=null,a=this.staticsleep.head;for(;a!=null;){let p=a.elt;if(p.type!=3||p.velx==0&&p.vely==0&&p.angvel==0){if(p.kinematicDelaySleep){p.kinematicDelaySleep=!1,a=a.next;continue}p.component.sleeping=!0;let c=this.staticsleep,h,u;r==null?(h=c.head,u=h.next,c.head=u,c.head==null&&(c.pushmod=!0)):(h=r.next,u=h.next,r.next=u,u==null&&(c.pushmod=!0));let x=h;x.elt=null,x.next=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=x,c.modified=!0,c.length--,c.pushmod=!0,a=u;continue}r=a,a=a.next}this.doForests(e),this.sleepArbiters()}finally{this.midstep=!1}let s=null,i=this.callbackset_list.next;for(;i!=null;){let l=i;if(l.arbiters.head==null){let y=this.callbackset_list,z,f;s==null?(z=y.next,f=z.next,y.next=f,y.next==null&&(y.pushmod=!0)):(z=s.next,f=z.next,s.next=f,f==null&&(y.pushmod=!0)),z._inuse=!1,y.modified=!0,y.length--,y.pushmod=!0,i=f;let w=l;w.int1=w.int2=null,w.id=w.di=-1,w.freed=!0,w.next=Kt.zpp_pool,Kt.zpp_pool=w;continue}let o;o=!0;let r=l.arbiters.head;for(;r!=null;)if(r.elt.sleeping){r=r.next;continue}else{o=!1;break}let a=o,p=l.int1.cbSet,c=l.int2.cbSet,h=p.manager,u=null,m=(p.cbpairs.length<c.cbpairs.length?p.cbpairs:c.cbpairs).head;for(;m!=null;){let y=m.elt;if(y.a==p&&y.b==c||y.a==c&&y.b==p){u=y;break}m=m.next}if(u==null){let y;Ne.zpp_pool==null?y=new Ne:(y=Ne.zpp_pool,Ne.zpp_pool=y.next,y.next=null),y.zip_listeners=!0,dt.setlt(p,c)?(y.a=p,y.b=c):(y.a=c,y.b=p),u=y,p.cbpairs.add(u),c!=p&&c.cbpairs.add(u)}u.zip_listeners&&(u.zip_listeners=!1,u.__validate());let _=u.listeners.head;for(;_!=null;){let y=_.elt;if(y.event==6&&(!a||y.allowSleepingCallbacks)&&!l.empty_arb(y.itype)){let z=this.push_callback(y);z.event=6;let f=l.int1,w=l.int2,Z,d=y.options1,b=f.cbTypes;if(d.nonemptyintersection(b,d.includes)&&!d.nonemptyintersection(b,d.excludes)){let g=y.options2,P=w.cbTypes;Z=g.nonemptyintersection(P,g.includes)&&!g.nonemptyintersection(P,g.excludes)}else Z=!1;Z?(z.int1=f,z.int2=w):(z.int1=w,z.int2=f),z.set=l}_=_.next}s=i,i=i.next}for(;!this.callbacks.empty();){let l=this.callbacks.pop();l.listener.type==0?l.listener.body.handler(l.wrapper_body()):l.listener.type==1?l.listener.constraint.handler(l.wrapper_con()):l.listener.type==2&&l.listener.interaction.handleri(l.wrapper_int());let o=l;o.int1=o.int2=null,o.body=null,o.constraint=null,o.listener=null,o.wrap_arbiters!=null&&(o.wrap_arbiters.zpp_inner.inner=null),o.set=null,o.next=Tt.zpp_pool,Tt.zpp_pool=o}}continuousCollisions(e){let t=2*Math.PI/e;this.bphase.broadphase(this,!1);let n=0;for(;n<1&&this.toiEvents.head!=null;){let l=null,o=2,r=!1,a=null,p=null,c=this.toiEvents.head;for(;c!=null;){let y=c.elt,z=y.s1.body,f=y.s2.body;if(z.sweepFrozen&&f.sweepFrozen)if(y.toi!=0&&Ee.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!=f.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=f.sweepFrozen,y.frozen1){let w=y.s1;y.s1=y.s2,y.s2=w,y.frozen1=!1,y.frozen2=!0}if(gn.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<o||!r&&y.kinematic)&&(l=y,o=y.toi,r=y.kinematic,a=p),p=c,c=c.next}if(l==null)break;this.toiEvents.erase(a),n=l.toi;let h=l.s1.body,u=l.s2.body;if(!h.sweepFrozen){let y=n*e,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,b=1-.5*d,g=1-d*d/8,P=(b*h.axisx+Z*h.axisy)*g;h.axisy=(b*h.axisy-Z*h.axisx)*g,h.axisx=P}}}let f=l.s1;if(f.type==0||f.type===2)f.worldCOMx=h.posx+(h.axisy*f.localCOMx-h.axisx*f.localCOMy),f.worldCOMy=h.posy+(f.localCOMx*h.axisx+f.localCOMy*h.axisy);else{let w=f.polygon,Z=w.lverts.next,d=w.gverts.next;for(;d!=null;){let k=d,C=Z;Z=Z.next,k.x=h.posx+(h.axisy*C.x-h.axisx*C.y),k.y=h.posy+(C.x*h.axisx+C.y*h.axisy),d=d.next}let b=w.edges.head,g=w.gverts.next,P=g;for(g=g.next;g!=null;){let k=g,C=b.elt;b=b.next,C.gnormx=h.axisy*C.lnormx-h.axisx*C.lnormy,C.gnormy=C.lnormx*h.axisx+C.lnormy*h.axisy,C.gprojection=h.posx*C.gnormx+h.posy*C.gnormy+C.lprojection,C.tp0=P.y*C.gnormx-P.x*C.gnormy,C.tp1=k.y*C.gnormx-k.x*C.gnormy,P=k,g=g.next}let v=w.gverts.next,N=b.elt;b=b.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,b=1-.5*d,g=1-d*d/8,P=(b*u.axisx+Z*u.axisy)*g;u.axisy=(b*u.axisy-Z*u.axisx)*g,u.axisx=P}}}let f=l.s2;if(f.type==0||f.type===2)f.worldCOMx=u.posx+(u.axisy*f.localCOMx-u.axisx*f.localCOMy),f.worldCOMy=u.posy+(f.localCOMx*u.axisx+f.localCOMy*u.axisy);else{let w=f.polygon,Z=w.lverts.next,d=w.gverts.next;for(;d!=null;){let k=d,C=Z;Z=Z.next,k.x=u.posx+(u.axisy*C.x-u.axisx*C.y),k.y=u.posy+(C.x*u.axisx+C.y*u.axisy),d=d.next}let b=w.edges.head,g=w.gverts.next,P=g;for(g=g.next;g!=null;){let k=g,C=b.elt;b=b.next,C.gnormx=u.axisy*C.lnormx-u.axisx*C.lnormy,C.gnormy=C.lnormx*u.axisx+C.lnormy*u.axisy,C.gprojection=u.posx*C.gnormx+u.posy*C.gnormy+C.lprojection,C.tp0=P.y*C.gnormx-P.x*C.gnormy,C.tp1=k.y*C.gnormx-k.x*C.gnormy,P=k,g=g.next}let v=w.gverts.next,N=b.elt;b=b.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}}let x=l.arbiter==null,m=this.narrowPhase(l.s1,l.s2,!0,l.arbiter,!0);if(m==null)l.arbiter!=null&&l.arbiter.pair!=null&&(l.arbiter.pair.arb=null,l.arbiter.pair=null);else if(!this.presteparb(m,e,!0)&&m.type==Ie.COL&&m.active&&(m.immState&1)!=0){let y=m.colarb,z=y.nx*y.c1.jnAcc-y.ny*y.c1.jtAcc,f=y.ny*y.c1.jnAcc+y.nx*y.c1.jtAcc,w=y.b1.imass;y.b1.velx-=z*w,y.b1.vely-=f*w,y.b1.angvel-=y.b1.iinertia*(f*y.c1.r1x-z*y.c1.r1y);let Z=y.b2.imass;if(y.b2.velx+=z*Z,y.b2.vely+=f*Z,y.b2.angvel+=y.b2.iinertia*(f*y.c1.r2x-z*y.c1.r2y),y.hc2){let le=y.nx*y.c2.jnAcc-y.ny*y.c2.jtAcc,he=y.ny*y.c2.jnAcc+y.nx*y.c2.jtAcc,ae=y.b1.imass;y.b1.velx-=le*ae,y.b1.vely-=he*ae,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,b=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-b*d.ny+d.surfacex)*d.c1.tMass,v=d.c1.friction*d.c1.jnAcc,N=d.c1.jtAcc,k=N-P;k>v?k=v:k<-v&&(k=-v),P=k-N,d.c1.jtAcc=k;let C=-d.ny*P,E=d.nx*P;if(d.b2.velx+=C*d.b2.imass,d.b2.vely+=E*d.b2.imass,d.b1.velx-=C*d.b1.imass,d.b1.vely-=E*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,k=N-P,k>v?k=v:k<-v&&(k=-v),P=k-N,d.c2.jtAcc=k,C=-d.ny*P,E=d.nx*P,d.b2.velx+=C*d.b2.imass,d.b2.vely+=E*d.b2.imass,d.b1.velx-=C*d.b1.imass,d.b1.vely-=E*d.b1.imass,d.b2.angvel+=d.rt2b*P*d.b2.iinertia,d.b1.angvel-=d.rt2a*P*d.b1.iinertia,b=d.k1x+d.b2.velx-d.c1.r2y*d.b2.angvel-(d.b1.velx-d.c1.r1y*d.b1.angvel),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 ae=d.c1.jnAcc,ce=d.c2.jnAcc,te=b*d.nx+g*d.ny+d.surfacey+d.c1.bounce-(d.Ka*ae+d.Kb*ce),ue=le*d.nx+he*d.ny+d.surfacey+d.c2.bounce-(d.Kb*ae+d.Kc*ce),de=-(d.kMassa*te+d.kMassb*ue),me=-(d.kMassb*te+d.kMassc*ue);de>=0&&me>=0?(te=de-ae,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-ae,ue=-ce,d.c1.jnAcc=de,d.c2.jnAcc=0):(me=-d.c2.nMass*ue,me>=0&&d.Kb*me+te>=0?(te=-ae,ue=me-ce,d.c1.jnAcc=0,d.c2.jnAcc=me):te>=0&&ue>=0?(te=-ae,ue=-ce,d.c1.jnAcc=d.c2.jnAcc=0):(te=0,ue=0))),P=te+ue,C=d.nx*P,E=d.ny*P,d.b2.velx+=C*d.b2.imass,d.b2.vely+=E*d.b2.imass,d.b1.velx-=C*d.b1.imass,d.b1.vely-=E*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),b=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*b+d.ny*g)+d.surfacey)*d.c1.nMass,N=d.c1.jnAcc,k=N-P,k<0&&(k=0),P=k-N,d.c1.jnAcc=k,C=d.nx*P,E=d.ny*P,d.b2.velx+=C*d.b2.imass,d.b2.vely+=E*d.b2.imass,d.b1.velx-=C*d.b1.imass,d.b1.vely-=E*d.b1.imass,d.b2.angvel+=d.rn1b*P*d.b2.iinertia,d.b1.angvel-=d.rn1a*P*d.b1.iinertia;let M=m.colarb,S=M.k1x+M.b2.velx-M.c1.r2y*M.b2.angvel-(M.b1.velx-M.c1.r1y*M.b1.angvel),O=M.k1y+M.b2.vely+M.c1.r2x*M.b2.angvel-(M.b1.vely+M.c1.r1x*M.b1.angvel),L=(O*M.nx-S*M.ny+M.surfacex)*M.c1.tMass,T=M.c1.friction*M.c1.jnAcc,R=M.c1.jtAcc,q=R-L;q>T?q=T:q<-T&&(q=-T),L=q-R,M.c1.jtAcc=q;let G=-M.ny*L,B=M.nx*L;if(M.b2.velx+=G*M.b2.imass,M.b2.vely+=B*M.b2.imass,M.b1.velx-=G*M.b1.imass,M.b1.vely-=B*M.b1.imass,M.b2.angvel+=M.rt1b*L*M.b2.iinertia,M.b1.angvel-=M.rt1a*L*M.b1.iinertia,M.hc2){let le=M.k2x+M.b2.velx-M.c2.r2y*M.b2.angvel-(M.b1.velx-M.c2.r1y*M.b1.angvel),he=M.k2y+M.b2.vely+M.c2.r2x*M.b2.angvel-(M.b1.vely+M.c2.r1x*M.b1.angvel);L=(he*M.nx-le*M.ny+M.surfacex)*M.c2.tMass,T=M.c2.friction*M.c2.jnAcc,R=M.c2.jtAcc,q=R-L,q>T?q=T:q<-T&&(q=-T),L=q-R,M.c2.jtAcc=q,G=-M.ny*L,B=M.nx*L,M.b2.velx+=G*M.b2.imass,M.b2.vely+=B*M.b2.imass,M.b1.velx-=G*M.b1.imass,M.b1.vely-=B*M.b1.imass,M.b2.angvel+=M.rt2b*L*M.b2.iinertia,M.b1.angvel-=M.rt2a*L*M.b1.iinertia,S=M.k1x+M.b2.velx-M.c1.r2y*M.b2.angvel-(M.b1.velx-M.c1.r1y*M.b1.angvel),O=M.k1y+M.b2.vely+M.c1.r2x*M.b2.angvel-(M.b1.vely+M.c1.r1x*M.b1.angvel),le=M.k2x+M.b2.velx-M.c2.r2y*M.b2.angvel-(M.b1.velx-M.c2.r1y*M.b1.angvel),he=M.k2y+M.b2.vely+M.c2.r2x*M.b2.angvel-(M.b1.vely+M.c2.r1x*M.b1.angvel);let ae=M.c1.jnAcc,ce=M.c2.jnAcc,te=S*M.nx+O*M.ny+M.surfacey+M.c1.bounce-(M.Ka*ae+M.Kb*ce),ue=le*M.nx+he*M.ny+M.surfacey+M.c2.bounce-(M.Kb*ae+M.Kc*ce),de=-(M.kMassa*te+M.kMassb*ue),me=-(M.kMassb*te+M.kMassc*ue);de>=0&&me>=0?(te=de-ae,ue=me-ce,M.c1.jnAcc=de,M.c2.jnAcc=me):(de=-M.c1.nMass*te,de>=0&&M.Kb*de+ue>=0?(te=de-ae,ue=-ce,M.c1.jnAcc=de,M.c2.jnAcc=0):(me=-M.c2.nMass*ue,me>=0&&M.Kb*me+te>=0?(te=-ae,ue=me-ce,M.c1.jnAcc=0,M.c2.jnAcc=me):te>=0&&ue>=0?(te=-ae,ue=-ce,M.c1.jnAcc=M.c2.jnAcc=0):(te=0,ue=0))),L=te+ue,G=M.nx*L,B=M.ny*L,M.b2.velx+=G*M.b2.imass,M.b2.vely+=B*M.b2.imass,M.b1.velx-=G*M.b1.imass,M.b1.vely-=B*M.b1.imass,M.b2.angvel+=(M.rn1b*te+M.rn2b*ue)*M.b2.iinertia,M.b1.angvel-=(M.rn1a*te+M.rn2a*ue)*M.b1.iinertia}else M.radius!=0&&(L=(M.b2.angvel-M.b1.angvel)*M.rMass,T=M.rfric*M.c1.jnAcc,R=M.jrAcc,M.jrAcc-=L,M.jrAcc>T?M.jrAcc=T:M.jrAcc<-T&&(M.jrAcc=-T),L=M.jrAcc-R,M.b2.angvel+=L*M.b2.iinertia,M.b1.angvel-=L*M.b1.iinertia),S=M.k1x+M.b2.velx-M.c1.r2y*M.b2.angvel-(M.b1.velx-M.c1.r1y*M.b1.angvel),O=M.k1y+M.b2.vely+M.c1.r2x*M.b2.angvel-(M.b1.vely+M.c1.r1x*M.b1.angvel),L=(M.c1.bounce+(M.nx*S+M.ny*O)+M.surfacey)*M.c1.nMass,R=M.c1.jnAcc,q=R-L,q<0&&(q=0),L=q-R,M.c1.jnAcc=q,G=M.nx*L,B=M.ny*L,M.b2.velx+=G*M.b2.imass,M.b2.vely+=B*M.b2.imass,M.b1.velx-=G*M.b1.imass,M.b1.vely-=B*M.b1.imass,M.b2.angvel+=M.rn1b*L*M.b2.iinertia,M.b1.angvel-=M.rn1a*L*M.b1.iinertia;let V=m.colarb,Y=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),$=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),X=($*V.nx-Y*V.ny+V.surfacex)*V.c1.tMass,H=V.c1.friction*V.c1.jnAcc,ee=V.c1.jtAcc,W=ee-X;W>H?W=H:W<-H&&(W=-H),X=W-ee,V.c1.jtAcc=W;let F=-V.ny*X,D=V.nx*X;if(V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=V.rt1b*X*V.b2.iinertia,V.b1.angvel-=V.rt1a*X*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);X=(he*V.nx-le*V.ny+V.surfacex)*V.c2.tMass,H=V.c2.friction*V.c2.jnAcc,ee=V.c2.jtAcc,W=ee-X,W>H?W=H:W<-H&&(W=-H),X=W-ee,V.c2.jtAcc=W,F=-V.ny*X,D=V.nx*X,V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=V.rt2b*X*V.b2.iinertia,V.b1.angvel-=V.rt2a*X*V.b1.iinertia,Y=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),$=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),le=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),he=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);let ae=V.c1.jnAcc,ce=V.c2.jnAcc,te=Y*V.nx+$*V.ny+V.surfacey+V.c1.bounce-(V.Ka*ae+V.Kb*ce),ue=le*V.nx+he*V.ny+V.surfacey+V.c2.bounce-(V.Kb*ae+V.Kc*ce),de=-(V.kMassa*te+V.kMassb*ue),me=-(V.kMassb*te+V.kMassc*ue);de>=0&&me>=0?(te=de-ae,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-ae,ue=-ce,V.c1.jnAcc=de,V.c2.jnAcc=0):(me=-V.c2.nMass*ue,me>=0&&V.Kb*me+te>=0?(te=-ae,ue=me-ce,V.c1.jnAcc=0,V.c2.jnAcc=me):te>=0&&ue>=0?(te=-ae,ue=-ce,V.c1.jnAcc=V.c2.jnAcc=0):(te=0,ue=0))),X=te+ue,F=V.nx*X,D=V.ny*X,V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=(V.rn1b*te+V.rn2b*ue)*V.b2.iinertia,V.b1.angvel-=(V.rn1a*te+V.rn2a*ue)*V.b1.iinertia}else V.radius!=0&&(X=(V.b2.angvel-V.b1.angvel)*V.rMass,H=V.rfric*V.c1.jnAcc,ee=V.jrAcc,V.jrAcc-=X,V.jrAcc>H?V.jrAcc=H:V.jrAcc<-H&&(V.jrAcc=-H),X=V.jrAcc-ee,V.b2.angvel+=X*V.b2.iinertia,V.b1.angvel-=X*V.b1.iinertia),Y=V.k1x+V.b2.velx-V.c1.r2y*V.b2.angvel-(V.b1.velx-V.c1.r1y*V.b1.angvel),$=V.k1y+V.b2.vely+V.c1.r2x*V.b2.angvel-(V.b1.vely+V.c1.r1x*V.b1.angvel),X=(V.c1.bounce+(V.nx*Y+V.ny*$)+V.surfacey)*V.c1.nMass,ee=V.c1.jnAcc,W=ee-X,W<0&&(W=0),X=W-ee,V.c1.jnAcc=W,F=V.nx*X,D=V.ny*X,V.b2.velx+=F*V.b2.imass,V.b2.vely+=D*V.b2.imass,V.b1.velx-=F*V.b1.imass,V.b1.vely-=D*V.b1.imass,V.b2.angvel+=V.rn1b*X*V.b2.iinertia,V.b1.angvel-=V.rn1a*X*V.b1.iinertia;let A=m.colarb,J=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),Q=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),K=(Q*A.nx-J*A.ny+A.surfacex)*A.c1.tMass,ie=A.c1.friction*A.c1.jnAcc,oe=A.c1.jtAcc,se=oe-K;se>ie?se=ie:se<-ie&&(se=-ie),K=se-oe,A.c1.jtAcc=se;let ne=-A.ny*K,re=A.nx*K;if(A.b2.velx+=ne*A.b2.imass,A.b2.vely+=re*A.b2.imass,A.b1.velx-=ne*A.b1.imass,A.b1.vely-=re*A.b1.imass,A.b2.angvel+=A.rt1b*K*A.b2.iinertia,A.b1.angvel-=A.rt1a*K*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);K=(he*A.nx-le*A.ny+A.surfacex)*A.c2.tMass,ie=A.c2.friction*A.c2.jnAcc,oe=A.c2.jtAcc,se=oe-K,se>ie?se=ie:se<-ie&&(se=-ie),K=se-oe,A.c2.jtAcc=se,ne=-A.ny*K,re=A.nx*K,A.b2.velx+=ne*A.b2.imass,A.b2.vely+=re*A.b2.imass,A.b1.velx-=ne*A.b1.imass,A.b1.vely-=re*A.b1.imass,A.b2.angvel+=A.rt2b*K*A.b2.iinertia,A.b1.angvel-=A.rt2a*K*A.b1.iinertia,J=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),Q=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 ae=A.c1.jnAcc,ce=A.c2.jnAcc,te=J*A.nx+Q*A.ny+A.surfacey+A.c1.bounce-(A.Ka*ae+A.Kb*ce),ue=le*A.nx+he*A.ny+A.surfacey+A.c2.bounce-(A.Kb*ae+A.Kc*ce),de=-(A.kMassa*te+A.kMassb*ue),me=-(A.kMassb*te+A.kMassc*ue);de>=0&&me>=0?(te=de-ae,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-ae,ue=-ce,A.c1.jnAcc=de,A.c2.jnAcc=0):(me=-A.c2.nMass*ue,me>=0&&A.Kb*me+te>=0?(te=-ae,ue=me-ce,A.c1.jnAcc=0,A.c2.jnAcc=me):te>=0&&ue>=0?(te=-ae,ue=-ce,A.c1.jnAcc=A.c2.jnAcc=0):(te=0,ue=0))),K=te+ue,ne=A.nx*K,re=A.ny*K,A.b2.velx+=ne*A.b2.imass,A.b2.vely+=re*A.b2.imass,A.b1.velx-=ne*A.b1.imass,A.b1.vely-=re*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&&(K=(A.b2.angvel-A.b1.angvel)*A.rMass,ie=A.rfric*A.c1.jnAcc,oe=A.jrAcc,A.jrAcc-=K,A.jrAcc>ie?A.jrAcc=ie:A.jrAcc<-ie&&(A.jrAcc=-ie),K=A.jrAcc-oe,A.b2.angvel+=K*A.b2.iinertia,A.b1.angvel-=K*A.b1.iinertia),J=A.k1x+A.b2.velx-A.c1.r2y*A.b2.angvel-(A.b1.velx-A.c1.r1y*A.b1.angvel),Q=A.k1y+A.b2.vely+A.c1.r2x*A.b2.angvel-(A.b1.vely+A.c1.r1x*A.b1.angvel),K=(A.c1.bounce+(A.nx*J+A.ny*Q)+A.surfacey)*A.c1.nMass,oe=A.c1.jnAcc,se=oe-K,se<0&&(se=0),K=se-oe,A.c1.jnAcc=se,ne=A.nx*K,re=A.ny*K,A.b2.velx+=ne*A.b2.imass,A.b2.vely+=re*A.b2.imass,A.b1.velx-=ne*A.b1.imass,A.b1.vely-=re*A.b1.imass,A.b2.angvel+=A.rn1b*K*A.b2.iinertia,A.b1.angvel-=A.rn1a*K*A.b1.iinertia;h.sweep_angvel=h.angvel%t,u.sweep_angvel=u.angvel%t}if(m!=null&&m.active&&(m.immState&1)!=0&&m.type==Ie.COL){if(!h.sweepFrozen&&h.type!=3)if(h.sweepFrozen=!0,l.failed)h.angvel=h.sweep_angvel=0;else if(l.slipped){let y=h;y.sweep_angvel*=I._nape.Config.angularCCDSlipScale,h.angvel=y.sweep_angvel}else h.angvel=h.sweep_angvel;if(!u.sweepFrozen&&u.type!=3)if(u.sweepFrozen=!0,l.failed)u.angvel=u.sweep_angvel=0;else if(l.slipped){let y=u;y.sweep_angvel*=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 o=this.toiEvents.pop_unsafe();o.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=o}let s=this.kinematics.head;for(;s!=null;){let l=s.elt,o=e-l.sweepTime;if(o!=0){l.sweepTime=e;let r=o;if(l.posx+=l.velx*r,l.posy+=l.vely*r,l.angvel!=0){let a=l.sweep_angvel*o;if(l.rot+=a,a*a>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=a*a,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+a*l.axisy)*h;l.axisy=(c*l.axisy-a*l.axisx)*h,l.axisx=u}}}l.sweepTime=0,s=s.next}let i=this.live.head;for(;i!=null;){let l=i.elt;if(!l.sweepFrozen){let o=e-l.sweepTime;if(o!=0){l.sweepTime=e;let r=o;if(l.posx+=l.velx*r,l.posy+=l.vely*r,l.angvel!=0){let a=l.sweep_angvel*o;if(l.rot+=a,a*a>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=a*a,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+a*l.axisy)*h;l.axisy=(c*l.axisy-a*l.axisx)*h,l.axisx=u}}}}l.sweepTime=0,i=i.next}}continuousEvent(e,t,n,s,i){if(e.body.sweepFrozen&&t.body.sweepFrozen||e.body.disableCCD||t.body.disableCCD)return s;let l;if(s!=null&&s.colarb==null)l=!0;else{let a=e.body,p=t.body,c;c=!1;let h=a.constraints.head;for(;h!=null;){let m=h.elt;if(m.ignore&&m.pair_exists(a.id,p.id)){c=!0;break}h=h.next}let u,x;if(c)x=!1;else{let m=e;for(;m!=null&&m.group==null;)m.ishape!=null?m=m.ishape.body:m.icompound!=null?m=m.icompound.compound:m=m.ibody.compound;let _=m==null?null:m.group,y;if(_==null)y=!1;else{let z=t;for(;z!=null&&z.group==null;)z.ishape!=null?z=z.ishape.body:z.icompound!=null?z=z.icompound.compound:z=z.ibody.compound;let f=z==null?null:z.group;if(f==null)y=!1;else{let w=!1;for(;_!=null&&f!=null;){if(_==f){w=_.ignore;break}_.depth<f.depth?f=f.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=!1;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 _=!1;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 o=e.body,r=t.body;if(n||o.bullet||r.bullet){let a;I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?a=new I._zpp.geom.ZPP_ToiEvent:(a=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=a.next,a.next=null),a.failed=!1,a.s1=a.s2=null,a.arbiter=null;let p=o.type==3||r.type==3;if(n&&!p)e.body.type!=2?(a.s2=e,a.s1=t):(a.s1=e,a.s2=t),a.kinematic=!1,gn.staticSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD);else if(a.s1=e,a.s2=t,a.kinematic=p,a.s1.body.sweepFrozen||a.s2.body.sweepFrozen){if(a.s1.body.sweepFrozen){let c=a.s1;a.s1=a.s2,a.s2=c,a.frozen1=!1,a.frozen2=!0}gn.staticSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD)}else gn.dynamicSweep(a,this.pre_dt,0,I._nape.Config.collisionSlopCCD,!1);if(n&&a.toi<0||a.failed){let c=a;c.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=c}else this.toiEvents.add(a),a.frozen1=a.s1.body.sweepFrozen,a.frozen2=a.s2.body.sweepFrozen,a.arbiter=s!=null?s.colarb:null}return s}bodyCbWake(e){if(e.type==2&&e.cbSet!=null)if(this.midstep){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let s=this.push_callback(n);s.event=2,s.body=e,t=t.next}}else e.component.woken=!0}bodyCbSleep(e){if(e.type==2&&e.cbSet!=null){let t=e.cbSet.bodylisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let s=this.push_callback(n);s.event=3,s.body=e,t=t.next}}}constraintCbWake(e){if(e.cbSet!=null)if(this.midstep){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=2){t=t.next;continue}let s=this.push_callback(n);s.event=2,s.constraint=e,t=t.next}}else e.component.woken=!0}constraintCbSleep(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=3){t=t.next;continue}let s=this.push_callback(n);s.event=3,s.constraint=e,t=t.next}}}constraintCbBreak(e){if(e.cbSet!=null){let t=e.cbSet.conlisteners.head;for(;t!=null;){let n=t.elt;if(n.event!=4){t=t.next;continue}let s=this.push_callback(n);s.event=4,s.constraint=e,t=t.next}}}nullListenerType(e,t){let n=new 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,o=l.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=l.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,o=i.ishape!=null?i.ishape:null,r=l.arbiters.head;for(;r!=null;){let a=r.elt;if(a.present==0){r=r.next;continue}if(o!=null&&!(a.ws1==o||a.ws2==o)){r=r.next;continue}this.MRCA_chains(a.ws1,a.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let h=this.mrca2.head;for(;h!=null;){let u=h.elt;if(c.cbSet==e&&u.cbSet!=t||c.cbSet==t&&u.cbSet!=e){h=h.next;continue}let x=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}r=r.next}}}}nullInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,s=n.bodies.head;for(;s!=null;){let l=s.elt;this.nullInteractorType(l,t),s=s.next}let i=n.compounds.head;for(;i!=null;){let l=i.elt;this.nullInteractorType(l,t),i=i.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,s=e.ishape!=null?e.ishape:null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(l.present==0){i=i.next;continue}if(s!=null&&!(l.ws1==s||l.ws2==s)){i=i.next;continue}this.MRCA_chains(l.ws1,l.ws2);let o=this.mrca1.head;for(;o!=null;){let r=o.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(r!=t&&p!=t){a=a.next;continue}let c=I._zpp.phys.ZPP_Interactor.get(r,p);c!=null&&(l.present--,c.remove_arb(l),c.arbiters.head==null&&this.remove_callbackset(c)),a=a.next}o=o.next}i=i.next}}}freshListenerType(e,t){let n=new 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,o=l.bodies.head;for(;o!=null;){let a=o.elt;n.add(a),o=o.next}let r=l.compounds.head;for(;r!=null;){let a=r.elt;n.add(a),r=r.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,o=i.ishape!=null?i.ishape:null,r=l.arbiters.head;for(;r!=null;){let a=r.elt;if(!a.presentable){r=r.next;continue}if(o!=null&&!(a.ws1==o||a.ws2==o)){r=r.next;continue}this.MRCA_chains(a.ws1,a.ws2);let p=this.mrca1.head;for(;p!=null;){let c=p.elt;if(c.cbSet!=e&&c.cbSet!=t){p=p.next;continue}let h=this.mrca2.head;for(;h!=null;){let u=h.elt;if(c.cbSet==e&&u.cbSet!=t||c.cbSet==t&&u.cbSet!=e){h=h.next;continue}let x=I._zpp.phys.ZPP_Interactor.get(c,u);x==null&&(x=Kt.get(c,u),this.add_callbackset(x));let m,_;_=!1;let y=x.arbiters.head;for(;y!=null;){if(y.elt==a){_=!0;break}y=y.next}if(_)m=!1;else{let z=x.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=a;let w=f;w.next=z.head,z.head=w,z.modified=!0,z.length++,m=!0}m&&a.present++,h=h.next}p=p.next}r=r.next}}}}freshInteractorType(e,t){if(t==null&&(t=e),e.icompound!=null){let n=e.icompound,s=n.bodies.head;for(;s!=null;){let l=s.elt;this.freshInteractorType(l,t),s=s.next}let i=n.compounds.head;for(;i!=null;){let l=i.elt;this.freshInteractorType(l,t),i=i.next}}else{let n=e.ibody!=null?e.ibody:e.ishape.body,s=e.ishape!=null?e.ishape:null,i=n.arbiters.head;for(;i!=null;){let l=i.elt;if(!l.presentable){i=i.next;continue}if(s!=null&&!(l.ws1==s||l.ws2==s)){i=i.next;continue}this.MRCA_chains(l.ws1,l.ws2);let o=this.mrca1.head;for(;o!=null;){let r=o.elt,a=this.mrca2.head;for(;a!=null;){let p=a.elt;if(r!=t&&p!=t){a=a.next;continue}let c=r.cbSet,h=p.cbSet;c.validate(),h.validate();let u=c.manager,x=null,_=(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=!0,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=!1,x.__validate()),x.listeners.head!=null){let y=I._zpp.phys.ZPP_Interactor.get(r,p);y==null&&(y=Kt.get(r,p),this.add_callbackset(y));let z,f;f=!1;let w=y.arbiters.head;for(;w!=null;){if(w.elt==l){f=!0;break}w=w.next}if(f)z=!1;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 b=d;b.next=Z.head,Z.head=b,Z.modified=!0,Z.length++,z=!0}z&&l.present++}a=a.next}o=o.next}i=i.next}}}wakeCompound(e){let t=e.bodies.head;for(;t!=null;){let l=t.elt;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!1)),t=t.next}let n=e.constraints.head;for(;n!=null;){let i=n.elt;this.wake_constraint(i),n=n.next}let s=e.compounds.head;for(;s!=null;){let i=s.elt;this.wakeCompound(i),s=s.next}}wakeIsland(e){for(;e.comps.head!=null;){let n=e.comps.pop_unsafe();if(n.waket=this.stamp+(this.midstep?0:1),n.isBody){let s=n.body;this.live.add(s);let i=s.arbiters.head;for(;i!=null;){let l=i.elt;if(l.sleeping)if(l.sleeping=!1,l.up_stamp+=this.stamp-l.sleep_stamp,l.type==Ie.COL){let o=l.colarb;if(o.stat){let r=this.c_arbiters_true,a;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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}else{let r=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=o;let p=a;p.next=r.head,r.head=p,r.modified=!0,r.length++}}else if(l.type==Ie.FLUID){let o=this.f_arbiters,r=l.fluidarb,a;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}else{let o=this.s_arbiters,r=l.sensorarb,a;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}i=i.next}if(this.bodyCbWake(s),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0,s.type!=1){let l=s.shapes.head;for(;l!=null;){let o=l.elt;o.node!=null&&this.bphase.sync(o),l=l.next}}}else{let s=n.constraint,i=this.live_constraints,l;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 o=l;o.next=i.head,i.head=o,i.modified=!0,i.length++,this.constraintCbWake(s),n.sleeping=!1,n.island=null,n.parent=n,n.rank=0}}let t=e;t.next=xt.zpp_pool,xt.zpp_pool=t}non_inlined_wake(e,t){t==null&&(t=!1);let n=e;n.world||(n.component.waket=this.stamp+(this.midstep?0:1),n.type==3&&(n.kinematicDelaySleep=!0),n.component.sleeping&&this.really_wake(n,t))}really_wake(e,t){if(t==null&&(t=!1),e.component.island==null){if(e.component.sleeping=!1,e.type==3||e.type==1){let i=this.staticsleep,l;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 o=l;o.next=i.head,i.head=o,i.modified=!0,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 o=l;o.next=i.head,i.head=o,i.modified=!0,i.length++}let n=e.constraints.head;for(;n!=null;){let i=n.elt;i.space==this&&this.wake_constraint(i),n=n.next}let s=e.arbiters.head;for(;s!=null;){let i=s.elt;if(i.sleeping)if(i.sleeping=!1,i.up_stamp+=this.stamp+(this.midstep?0:1)-i.sleep_stamp,i.type==Ie.COL){let l=i.colarb;if(l.stat){let o=this.c_arbiters_true,r;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(r=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=l;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}else{let o=this.c_arbiters_false,r;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(r=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=r.next,r.next=null),r.elt=l;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}}else if(i.type==Ie.FLUID){let l=this.f_arbiters,o=i.fluidarb,r;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(r=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=l.head,l.head=a,l.modified=!0,l.length++}else{let l=this.s_arbiters,o=i.sensorarb,r;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(r=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=r.next,r.next=null),r.elt=o;let a=r;a.next=l.head,l.head=a,l.modified=!0,l.length++}if(i.type!=Ie.SENSOR&&!i.cleared&&i.up_stamp>=this.stamp&&(i.immState&1)!=0){if(i.b1.type==2&&i.b1.component.sleeping){let l=i.b1;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!1))}if(i.b2.type==2&&i.b2.component.sleeping){let l=i.b2;l.world||(l.component.waket=this.stamp+(this.midstep?0:1),l.type==3&&(l.kinematicDelaySleep=!0),l.component.sleeping&&this.really_wake(l,!1))}}s=s.next}if(!t&&e.type==2&&this.bodyCbWake(e),!t&&!this.bphase.is_sweep&&e.type!=1){let i=e.shapes.head;for(;i!=null;){let l=i.elt;l.node!=null&&this.bphase.sync(l),i=i.next}}}else this.wakeIsland(e.component.island)}wake_constraint(e,t){if(t==null&&(t=!1),e.active)if(e.component.waket=this.stamp+(this.midstep?0:1),e.component.sleeping){if(e.component.island==null){e.component.sleeping=!1;let n=this.live_constraints,s;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=!0,n.length++,e.wake_connected(),t||this.constraintCbWake(e)}else this.wakeIsland(e.component.island);return!0}else return!1;else return!1}doForests(e){let t=this.c_arbiters_false.head;for(;t!=null;){let i=t.elt;if(!i.cleared&&i.up_stamp==this.stamp&&(i.immState&1)!=0&&i.b1.type==2&&i.b2.type==2){let l;if(i.b1.component==i.b1.component.parent)l=i.b1.component;else{let r=i.b1.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}l=r}let o;if(i.b2.component==i.b2.component.parent)o=i.b2.component;else{let r=i.b2.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}o=r}l!=o&&(l.rank<o.rank?l.parent=o:l.rank>o.rank?o.parent=l:(o.parent=l,l.rank++))}t=t.next}let n=this.f_arbiters.head;for(;n!=null;){let i=n.elt;if(!i.cleared&&i.up_stamp==this.stamp&&(i.immState&1)!=0&&i.b1.type==2&&i.b2.type==2){let l;if(i.b1.component==i.b1.component.parent)l=i.b1.component;else{let r=i.b1.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}l=r}let o;if(i.b2.component==i.b2.component.parent)o=i.b2.component;else{let r=i.b2.component,a=null;for(;r!=r.parent;){let p=r.parent;r.parent=a,a=r,r=p}for(;a!=null;){let p=a.parent;a.parent=r,a=p}o=r}l!=o&&(l.rank<o.rank?l.parent=o:l.rank>o.rank?o.parent=l:(o.parent=l,l.rank++))}n=n.next}let s=this.live_constraints.head;for(;s!=null;)s.elt.forest(),s=s.next;for(;this.live.head!=null;){let i=this.live,l=i.head.elt;i.pop();let o=l,r=o.component,a;if(r==r.parent)a=r;else{let x=r,m=null;for(;x!=x.parent;){let _=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=!0;let _=m;_.next=x.next,x.next=_,x.modified=!0,x.length++,a.island.sleep=!0}r.island=a.island;let p=r.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=r;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++;let u=o.atRest(e);r.island.sleep=r.island.sleep&&u,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.live_constraints.head!=null;){let i=this.live_constraints,l=i.head.elt;i.pop();let r=l.component,a;if(r==r.parent)a=r;else{let u=r,x=null;for(;u!=u.parent;){let m=u.parent;u.parent=x,x=u,u=m}for(;x!=null;){let m=x.parent;x.parent=u,x=m}a=u}r.island=a.island;let p=r.island.comps,c;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=r;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++,r.waket>r.island.waket&&(r.island.waket=r.waket)}for(;this.islands.next!=null;){let i=this.islands,l=i.next;i.pop();let o=l;if(o.sleep){let r=o.comps.head;for(;r!=null;){let a=r.elt;if(a.isBody){let p=a.body;p.velx=0,p.vely=0,p.angvel=0,a.sleeping=!0;let c=p.shapes.head;for(;c!=null;){let h=c.elt;this.bphase.sync(h),c=c.next}this.bodyCbSleep(p)}else{let p=a.constraint;this.constraintCbSleep(p),a.sleeping=!0}r=r.next}}else{for(;o.comps.head!=null;){let a=o.comps,p=a.head.elt;a.pop();let c=p;if(c.waket=o.waket,c.isBody){let h=this.live,u=c.body,x;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=!0,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=!0,h.length++}c.sleeping=!1,c.island=null,c.parent=c,c.rank=0}let r=o;r.next=xt.zpp_pool,xt.zpp_pool=r}}}sleepArbiters(){let e=null,t=this.c_arbiters_true,n=t.head,s=this.c_arbiters_false!=null;for(s&&n==null&&(s=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);n!=null;){let u=n.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=!0;let x,m;e==null?(x=t.head,m=x.next,t.head=m,t.head==null&&(t.pushmod=!0)):(x=e.next,m=x.next,e.next=m,m==null&&(t.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=_,t.modified=!0,t.length--,t.pushmod=!0,n=m,s&&n==null&&(s=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null);continue}e=n,n=n.next,s&&n==null&&(s=!1,n=this.c_arbiters_false.head,t=this.c_arbiters_false,e=null)}let i=null,l=this.f_arbiters,o=l.head,r=!1;for(r&&o==null&&(r=!1,l=null,i=null);o!=null;){let u=o.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=!0;let x,m;i==null?(x=l.head,m=x.next,l.head=m,l.head==null&&(l.pushmod=!0)):(x=i.next,m=x.next,i.next=m,m==null&&(l.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=_,l.modified=!0,l.length--,l.pushmod=!0,o=m,r&&o==null&&(r=!1,l=null,i=null);continue}i=o,o=o.next,r&&o==null&&(r=!1,l=null,i=null)}let a=null,p=this.s_arbiters,c=p.head,h=!1;for(h&&c==null&&(h=!1,p=null,a=null);c!=null;){let u=c.elt;if(u.b1.component.sleeping&&u.b2.component.sleeping){u.sleep_stamp=this.stamp,u.sleeping=!0;let x,m;a==null?(x=p.head,m=x.next,p.head=m,p.head==null&&(p.pushmod=!0)):(x=a.next,m=x.next,a.next=m,m==null&&(p.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=_,p.modified=!0,p.length--,p.pushmod=!0,c=m,h&&c==null&&(h=!1,p=null,a=null);continue}a=c,c=c.next,h&&c==null&&(h=!1,p=null,a=null)}}static_validation(e){if(e.shapes.head!=null){if(e.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(e.zip_aabb){e.zip_aabb=!1,e.aabb.minx=1/0,e.aabb.miny=1/0,e.aabb.maxx=-1/0,e.aabb.maxy=-1/0;let n=e.shapes.head;for(;n!=null;){let s=n.elt;if(s.zip_aabb&&s.body!=null)if(s.zip_aabb=!1,s.type==0){let o=s.circle;if(o.zip_worldCOM&&o.body!=null){if(o.zip_worldCOM=!1,o.zip_localCOM){if(o.zip_localCOM=!1,o.type==1){let c=o.polygon;if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(c.lverts.next.next==null)c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;else if(c.lverts.next.next.next==null){c.localCOMx=c.lverts.next.x,c.localCOMy=c.lverts.next.y;let h=1;c.localCOMx+=c.lverts.next.next.x*h,c.localCOMy+=c.lverts.next.next.y*h;let u=.5;c.localCOMx*=u,c.localCOMy*=u}else{c.localCOMx=0,c.localCOMy=0;let h=0,u=c.lverts.next,x=u;u=u.next;let m=u;for(u=u.next;u!=null;){let 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 f=z.y*m.x-z.x*m.y;c.localCOMx+=(m.x+z.x)*f,c.localCOMy+=(m.y+z.y)*f,h=1/(3*h);let w=h;c.localCOMx*=w,c.localCOMy*=w}}o.wrap_localCOM!=null&&(o.wrap_localCOM.zpp_inner.x=o.localCOMx,o.wrap_localCOM.zpp_inner.y=o.localCOMy)}let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot)),o.worldCOMx=o.body.posx+(o.body.axisy*o.localCOMx-o.body.axisx*o.localCOMy),o.worldCOMy=o.body.posy+(o.localCOMx*o.body.axisx+o.localCOMy*o.body.axisy)}let r=o.radius,a=o.radius;o.aabb.minx=o.worldCOMx-r,o.aabb.miny=o.worldCOMy-a,o.aabb.maxx=o.worldCOMx+r,o.aabb.maxy=o.worldCOMy+a}else if(s.type===2)s.capsule.__validate_aabb();else{let o=s.polygon;if(o.zip_gverts&&o.body!=null){o.zip_gverts=!1,o.validate_lverts();let p=o.body;p.zip_axis&&(p.zip_axis=!1,p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot));let c=o.lverts.next,h=o.gverts.next;for(;h!=null;){let u=h,x=c;c=c.next,u.x=o.body.posx+(o.body.axisy*x.x-o.body.axisx*x.y),u.y=o.body.posy+(x.x*o.body.axisx+x.y*o.body.axisy),h=h.next}}if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=o.gverts.next;o.aabb.minx=r.x,o.aabb.miny=r.y,o.aabb.maxx=r.x,o.aabb.maxy=r.y;let a=o.gverts.next.next;for(;a!=null;){let p=a;p.x<o.aabb.minx&&(o.aabb.minx=p.x),p.x>o.aabb.maxx&&(o.aabb.maxx=p.x),p.y<o.aabb.miny&&(o.aabb.miny=p.y),p.y>o.aabb.maxy&&(o.aabb.maxy=p.y),a=a.next}}let i=e.aabb,l=s.aabb;l.minx<i.minx&&(i.minx=l.minx),l.maxx>i.maxx&&(i.maxx=l.maxx),l.miny<i.miny&&(i.miny=l.miny),l.maxy>i.maxy&&(i.maxy=l.maxy),n=n.next}}}if(e.validate_mass(),e.validate_inertia(),e.velx!=0||e.vely!=0||e.angvel!=0)throw new Error("Error: Static body cannot have any real velocity, only kinematic or surface velocities");let t=e.shapes.head;for(;t!=null;){let n=t.elt;if(n.type==1){let s=n.polygon;s.zip_sanitation&&(s.zip_sanitation=!1,s.splice_collinear_real());let i=n.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new I._nape.shape.ValidationResult,U.internal=!1),i!=U.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+n.polygon.outer.toString()+" is invalid : "+i.toString());let l=n.polygon;if(l.zip_gaxi&&l.body!=null){l.zip_gaxi=!1,l.validate_laxi();let o=l.body;if(o.zip_axis&&(o.zip_axis=!1,o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot)),l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let u=l.body;u.zip_axis&&(u.zip_axis=!1,u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot));let x=l.lverts.next,m=l.gverts.next;for(;m!=null;){let _=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 r=l.edges.head,a=l.gverts.next,p=a;for(a=a.next;a!=null;){let u=a,x=r.elt;r=r.next,x.gp0=p,x.gp1=u,x.gnormx=l.body.axisy*x.lnormx-l.body.axisx*x.lnormy,x.gnormy=x.lnormx*l.body.axisx+x.lnormy*l.body.axisy,x.gprojection=l.body.posx*x.gnormx+l.body.posy*x.gnormy+x.lprojection,x.wrap_gnorm!=null&&(x.wrap_gnorm.zpp_inner.x=x.gnormx,x.wrap_gnorm.zpp_inner.y=x.gnormy),x.tp0=x.gp0.y*x.gnormx-x.gp0.x*x.gnormy,x.tp1=x.gp1.y*x.gnormx-x.gp1.x*x.gnormy,p=u,a=a.next}let c=l.gverts.next,h=r.elt;r=r.next,h.gp0=p,h.gp1=c,h.gnormx=l.body.axisy*h.lnormx-l.body.axisx*h.lnormy,h.gnormy=h.lnormx*l.body.axisx+h.lnormy*l.body.axisy,h.gprojection=l.body.posx*h.gnormx+l.body.posy*h.gnormy+h.lprojection,h.wrap_gnorm!=null&&(h.wrap_gnorm.zpp_inner.x=h.gnormx,h.wrap_gnorm.zpp_inner.y=h.gnormy),h.tp0=h.gp0.y*h.gnormx-h.gp0.x*h.gnormy,h.tp1=h.gp1.y*h.gnormx-h.gp1.x*h.gnormy}}t=t.next}e.sweepFrozen=!0}validation(){let e=this.cbsets;if(!e.cbsets.empty()){let i=e.cbsets.parent;for(;i.prev!=null;)i=i.prev;for(;i!=null;)if(i.data.validate(),i.next!=null)for(i=i.next;i.prev!=null;)i=i.prev;else{for(;i.parent!=null&&i==i.parent.next;)i=i.parent;i=i.parent}}let t=this.live.head;for(;t!=null;){let i=t.elt;i.sweepRadius=0;let l=i.shapes.head;for(;l!=null;){let r=l.elt;if(r.type==1){let a=r.polygon;a.zip_sanitation&&(a.zip_sanitation=!1,a.splice_collinear_real());let p=r.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new I._nape.shape.ValidationResult,U.internal=!1),p!=U.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+r.polygon.outer.toString()+" is invalid : "+p.toString());let c=r.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=!1,c.validate_laxi();let h=c.body;if(h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let z=c.body;z.zip_axis&&(z.zip_axis=!1,z.axisx=Math.sin(z.rot),z.axisy=Math.cos(z.rot));let f=c.lverts.next,w=c.gverts.next;for(;w!=null;){let Z=w,d=f;f=f.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,f=u.elt;u=u.next,f.gp0=m,f.gp1=z,f.gnormx=c.body.axisy*f.lnormx-c.body.axisx*f.lnormy,f.gnormy=f.lnormx*c.body.axisx+f.lnormy*c.body.axisy,f.gprojection=c.body.posx*f.gnormx+c.body.posy*f.gnormy+f.lprojection,f.wrap_gnorm!=null&&(f.wrap_gnorm.zpp_inner.x=f.gnormx,f.wrap_gnorm.zpp_inner.y=f.gnormy),f.tp0=f.gp0.y*f.gnormx-f.gp0.x*f.gnormy,f.tp1=f.gp1.y*f.gnormx-f.gp1.x*f.gnormy,m=z,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}}r.validate_sweepRadius(),r.sweepRadius>i.sweepRadius&&(i.sweepRadius=r.sweepRadius),l=l.next}if(i.validate_mass(),i.validate_inertia(),i.shapes.head!=null){if(i.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(i.zip_aabb){i.zip_aabb=!1,i.aabb.minx=1/0,i.aabb.miny=1/0,i.aabb.maxx=-1/0,i.aabb.maxy=-1/0;let r=i.shapes.head;for(;r!=null;){let a=r.elt;if(a.zip_aabb&&a.body!=null)if(a.zip_aabb=!1,a.type==0){let h=a.circle;if(h.zip_worldCOM&&h.body!=null){if(h.zip_worldCOM=!1,h.zip_localCOM){if(h.zip_localCOM=!1,h.type==1){let _=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,f=z;z=z.next;let w=z;for(z=z.next;z!=null;){let v=z;y+=w.x*(v.y-f.y);let N=v.y*w.x-v.x*w.y;_.localCOMx+=(w.x+v.x)*N,_.localCOMy+=(w.y+v.y)*N,f=w,w=v,z=z.next}z=_.lverts.next;let Z=z;y+=w.x*(Z.y-f.y);let d=Z.y*w.x-Z.x*w.y;_.localCOMx+=(w.x+Z.x)*d,_.localCOMy+=(w.y+Z.y)*d,f=w,w=Z,z=z.next;let b=z;y+=w.x*(b.y-f.y);let g=b.y*w.x-b.x*w.y;_.localCOMx+=(w.x+b.x)*g,_.localCOMy+=(w.y+b.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=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot)),h.worldCOMx=h.body.posx+(h.body.axisy*h.localCOMx-h.body.axisx*h.localCOMy),h.worldCOMy=h.body.posy+(h.localCOMx*h.body.axisx+h.localCOMy*h.body.axisy)}let u=h.radius,x=h.radius;h.aabb.minx=h.worldCOMx-u,h.aabb.miny=h.worldCOMy-x,h.aabb.maxx=h.worldCOMx+u,h.aabb.maxy=h.worldCOMy+x}else if(a.type===2)a.capsule.__validate_aabb();else{let h=a.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot));let _=h.lverts.next,y=h.gverts.next;for(;y!=null;){let z=y,f=_;_=_.next,z.x=h.body.posx+(h.body.axisy*f.x-h.body.axisx*f.y),z.y=h.body.posy+(f.x*h.body.axisx+f.y*h.body.axisy),y=y.next}}if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let u=h.gverts.next;h.aabb.minx=u.x,h.aabb.miny=u.y,h.aabb.maxx=u.x,h.aabb.maxy=u.y;let x=h.gverts.next.next;for(;x!=null;){let m=x;m.x<h.aabb.minx&&(h.aabb.minx=m.x),m.x>h.aabb.maxx&&(h.aabb.maxx=m.x),m.y<h.aabb.miny&&(h.aabb.miny=m.y),m.y>h.aabb.maxy&&(h.aabb.maxy=m.y),x=x.next}}let p=i.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),r=r.next}}i.validate_worldCOM()}if(i.validate_gravMass(),i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),!i.nomove&&i.type==2&&i.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!i.norotate&&i.type==2&&i.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");if(i.component.woken&&i.cbSet!=null){let r=i.cbSet.bodylisteners.head;for(;r!=null;){let a=r.elt;if(a.event!=2){r=r.next;continue}let p=this.push_callback(a);p.event=2,p.body=i,r=r.next}}i.component.woken=!1;let o=i.shapes.head;for(;o!=null;){let r=o.elt;this.bphase.sync(r),o=o.next}t=t.next}let n=this.kinematics.head;for(;n!=null;){let i=n.elt;i.sweepRadius=0;let l=i.shapes.head;for(;l!=null;){let r=l.elt;if(r.type==1){let a=r.polygon;a.zip_sanitation&&(a.zip_sanitation=!1,a.splice_collinear_real());let p=r.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new I._nape.shape.ValidationResult,U.internal=!1),p!=U.ValidationResult_VALID)throw new Error("Error: Cannot simulate with an invalid Polygon : "+r.polygon.outer.toString()+" is invalid : "+p.toString());let c=r.polygon;if(c.zip_gaxi&&c.body!=null){c.zip_gaxi=!1,c.validate_laxi();let h=c.body;if(h.zip_axis&&(h.zip_axis=!1,h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot)),c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let z=c.body;z.zip_axis&&(z.zip_axis=!1,z.axisx=Math.sin(z.rot),z.axisy=Math.cos(z.rot));let f=c.lverts.next,w=c.gverts.next;for(;w!=null;){let Z=w,d=f;f=f.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,f=u.elt;u=u.next,f.gp0=m,f.gp1=z,f.gnormx=c.body.axisy*f.lnormx-c.body.axisx*f.lnormy,f.gnormy=f.lnormx*c.body.axisx+f.lnormy*c.body.axisy,f.gprojection=c.body.posx*f.gnormx+c.body.posy*f.gnormy+f.lprojection,f.wrap_gnorm!=null&&(f.wrap_gnorm.zpp_inner.x=f.gnormx,f.wrap_gnorm.zpp_inner.y=f.gnormy),f.tp0=f.gp0.y*f.gnormx-f.gp0.x*f.gnormy,f.tp1=f.gp1.y*f.gnormx-f.gp1.x*f.gnormy,m=z,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}}r.validate_sweepRadius(),r.sweepRadius>i.sweepRadius&&(i.sweepRadius=r.sweepRadius),l=l.next}if(i.validate_mass(),i.validate_inertia(),i.shapes.head!=null){if(i.shapes.head==null)throw new Error("Error: Body bounds only makes sense if it contains shapes");if(i.zip_aabb){i.zip_aabb=!1,i.aabb.minx=1/0,i.aabb.miny=1/0,i.aabb.maxx=-1/0,i.aabb.maxy=-1/0;let r=i.shapes.head;for(;r!=null;){let a=r.elt;if(a.zip_aabb&&a.body!=null)if(a.zip_aabb=!1,a.type==0){let h=a.circle;if(h.zip_worldCOM&&h.body!=null){if(h.zip_worldCOM=!1,h.zip_localCOM){if(h.zip_localCOM=!1,h.type==1){let _=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,f=z;z=z.next;let w=z;for(z=z.next;z!=null;){let v=z;y+=w.x*(v.y-f.y);let N=v.y*w.x-v.x*w.y;_.localCOMx+=(w.x+v.x)*N,_.localCOMy+=(w.y+v.y)*N,f=w,w=v,z=z.next}z=_.lverts.next;let Z=z;y+=w.x*(Z.y-f.y);let d=Z.y*w.x-Z.x*w.y;_.localCOMx+=(w.x+Z.x)*d,_.localCOMy+=(w.y+Z.y)*d,f=w,w=Z,z=z.next;let b=z;y+=w.x*(b.y-f.y);let g=b.y*w.x-b.x*w.y;_.localCOMx+=(w.x+b.x)*g,_.localCOMy+=(w.y+b.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=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot)),h.worldCOMx=h.body.posx+(h.body.axisy*h.localCOMx-h.body.axisx*h.localCOMy),h.worldCOMy=h.body.posy+(h.localCOMx*h.body.axisx+h.localCOMy*h.body.axisy)}let u=h.radius,x=h.radius;h.aabb.minx=h.worldCOMx-u,h.aabb.miny=h.worldCOMy-x,h.aabb.maxx=h.worldCOMx+u,h.aabb.maxy=h.worldCOMy+x}else if(a.type===2)a.capsule.__validate_aabb();else{let h=a.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let m=h.body;m.zip_axis&&(m.zip_axis=!1,m.axisx=Math.sin(m.rot),m.axisy=Math.cos(m.rot));let _=h.lverts.next,y=h.gverts.next;for(;y!=null;){let z=y,f=_;_=_.next,z.x=h.body.posx+(h.body.axisy*f.x-h.body.axisx*f.y),z.y=h.body.posy+(f.x*h.body.axisx+f.y*h.body.axisy),y=y.next}}if(h.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let u=h.gverts.next;h.aabb.minx=u.x,h.aabb.miny=u.y,h.aabb.maxx=u.x,h.aabb.maxy=u.y;let x=h.gverts.next.next;for(;x!=null;){let m=x;m.x<h.aabb.minx&&(h.aabb.minx=m.x),m.x>h.aabb.maxx&&(h.aabb.maxx=m.x),m.y<h.aabb.miny&&(h.aabb.miny=m.y),m.y>h.aabb.maxy&&(h.aabb.maxy=m.y),x=x.next}}let p=i.aabb,c=a.aabb;c.minx<p.minx&&(p.minx=c.minx),c.maxx>p.maxx&&(p.maxx=c.maxx),c.miny<p.miny&&(p.miny=c.miny),c.maxy>p.maxy&&(p.maxy=c.maxy),r=r.next}}i.validate_worldCOM()}if(i.validate_gravMass(),i.zip_axis&&(i.zip_axis=!1,i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot)),!i.nomove&&i.type==2&&i.mass==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 mass unless allowMovement is false");if(!i.norotate&&i.type==2&&i.inertia==0)throw new Error("Error: Dynamic Body cannot be simulated with 0 inertia unless allowRotation is false");let o=i.shapes.head;for(;o!=null;){let r=o.elt;this.bphase.sync(r),o=o.next}n=n.next}let s=this.live_constraints.head;for(;s!=null;){let i=s.elt;if(i.active){if(i.validate(),i.component.woken&&i.cbSet!=null){let l=i.cbSet.conlisteners.head;for(;l!=null;){let o=l.elt;if(o.event!=2){l=l.next;continue}let r=this.push_callback(o);r.event=2,r.constraint=i,l=l.next}}i.component.woken=!1}s=s.next}}updateVel(e){let t=null,n=1-e*this.global_lin_drag,s=1-e*this.global_ang_drag,i=this.live.head;for(;i!=null;){let l=i.elt;if(l.smass!=0){let o=e*l.imass;l.velx=n*l.velx+(l.forcex+this.gravityx*l.gravMass)*o,l.vely=n*l.vely+(l.forcey+this.gravityy*l.gravMass)*o}if(l.sinertia!=0){let o=0,r=0;o=l.worldCOMx-l.posx,r=l.worldCOMy-l.posy;let a=l.torque+(this.gravityy*o-this.gravityx*r)*l.gravMass;l.angvel=s*l.angvel+a*e*l.iinertia}t=i,i=i.next}}updatePos(e){let t=2*Math.PI/e,n=this.live.head;for(;n!=null;){let i=n.elt;i.pre_posx=i.posx,i.pre_posy=i.posy,i.pre_rot=i.rot,i.sweepTime=0,i.sweep_angvel=i.angvel%t;let l=e-i.sweepTime;if(l!=0){i.sweepTime=e;let o=l;if(i.posx+=i.velx*o,i.posy+=i.vely*o,i.angvel!=0){let r=i.sweep_angvel*l;if(i.rot+=r,r*r>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+r*i.axisy)*c;i.axisy=(p*i.axisy-r*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let o=I._nape.Config.staticCCDLinearThreshold*i.sweepRadius,r=I._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>o*o||i.angvel*i.angvel*e*e>r*r||i.type==3){let a=i.sweep_angvel;a<0&&(a=-a);let p=1/a,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,m=u.miny,_=u.maxx,y=u.maxy,z=a*e*h.sweepCoef*.008333333333333333|0;z>8&&(z=8);let f=a*e/z,w=e-i.sweepTime;if(w!=0){i.sweepTime=e;let b=w;if(i.posx+=i.velx*b,i.posy+=i.vely*b,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,k=(v*i.axisx+g*i.axisy)*N;i.axisy=(v*i.axisy-g*i.axisx)*N,i.axisx=k}}}if(h.type==0){let b=h.circle;b.worldCOMx=b.body.posx+(b.body.axisy*b.localCOMx-b.body.axisx*b.localCOMy),b.worldCOMy=b.body.posy+(b.localCOMx*b.body.axisx+b.localCOMy*b.body.axisy),b.aabb.minx=b.worldCOMx-b.radius,b.aabb.miny=b.worldCOMy-b.radius,b.aabb.maxx=b.worldCOMx+b.radius,b.aabb.maxy=b.worldCOMy+b.radius}else if(h.type===2)h.capsule.__validate_aabb();else{let b=h.polygon,g=b.lverts.next,P=b.gverts.next,v=g;g=g.next,P.x=b.body.posx+(b.body.axisy*v.x-b.body.axisx*v.y),P.y=b.body.posy+(v.x*b.body.axisx+v.y*b.body.axisy),b.aabb.minx=P.x,b.aabb.miny=P.y,b.aabb.maxx=P.x,b.aabb.maxy=P.y;let N=b.gverts.next.next;for(;N!=null;){let k=N,C=g;g=g.next,k.x=b.body.posx+(b.body.axisy*C.x-b.body.axisx*C.y),k.y=b.body.posy+(C.x*b.body.axisx+C.y*b.body.axisy),k.x<b.aabb.minx&&(b.aabb.minx=k.x),k.x>b.aabb.maxx&&(b.aabb.maxx=k.x),k.y<b.aabb.miny&&(b.aabb.miny=k.y),k.y>b.aabb.maxy&&(b.aabb.maxy=k.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 b=Z++,g=f*b*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 k=N*N,C=1-.5*k,E=1-k*k/8,M=(C*i.axisx+N*i.axisy)*E;i.axisy=(C*i.axisy-N*i.axisx)*E,i.axisx=M}}}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 if(h.type===2)h.capsule.__validate_aabb();else{let v=h.polygon,N=v.lverts.next,k=v.gverts.next,C=N;N=N.next,k.x=v.body.posx+(v.body.axisy*C.x-v.body.axisx*C.y),k.y=v.body.posy+(C.x*v.body.axisx+C.y*v.body.axisy),v.aabb.minx=k.x,v.aabb.miny=k.y,v.aabb.maxx=k.x,v.aabb.maxy=k.y;let E=v.gverts.next.next;for(;E!=null;){let M=E,S=N;N=N.next,M.x=v.body.posx+(v.body.axisy*S.x-v.body.axisx*S.y),M.y=v.body.posy+(S.x*v.body.axisx+S.y*v.body.axisy),M.x<v.aabb.minx&&(v.aabb.minx=M.x),M.x>v.aabb.maxx&&(v.aabb.maxx=M.x),M.y<v.aabb.miny&&(v.aabb.miny=M.y),M.y>v.aabb.maxy&&(v.aabb.maxy=M.y),E=E.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=!1,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=!0)}}else i.sweepFrozen=!0,i.bullet=!1}n=n.next}let s=this.kinematics.head;for(;s!=null;){let i=s.elt;i.pre_posx=i.posx,i.pre_posy=i.posy,i.pre_rot=i.rot,i.sweepTime=0,i.sweep_angvel=i.angvel%t;let l=e-i.sweepTime;if(l!=0){i.sweepTime=e;let o=l;if(i.posx+=i.velx*o,i.posy+=i.vely*o,i.angvel!=0){let r=i.sweep_angvel*l;if(i.rot+=r,r*r>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let a=r*r,p=1-.5*a,c=1-a*a/8,h=(p*i.axisx+r*i.axisy)*c;i.axisy=(p*i.axisy-r*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let o=I._nape.Config.staticCCDLinearThreshold*i.sweepRadius,r=I._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>o*o||i.angvel*i.angvel*e*e>r*r||i.type==3){let a=i.sweep_angvel;a<0&&(a=-a);let p=1/a,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,m=u.miny,_=u.maxx,y=u.maxy,z=a*e*h.sweepCoef*.008333333333333333|0;z>8&&(z=8);let f=a*e/z,w=e-i.sweepTime;if(w!=0){i.sweepTime=e;let b=w;if(i.posx+=i.velx*b,i.posy+=i.vely*b,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,k=(v*i.axisx+g*i.axisy)*N;i.axisy=(v*i.axisy-g*i.axisx)*N,i.axisx=k}}}if(h.type==0){let b=h.circle;b.worldCOMx=b.body.posx+(b.body.axisy*b.localCOMx-b.body.axisx*b.localCOMy),b.worldCOMy=b.body.posy+(b.localCOMx*b.body.axisx+b.localCOMy*b.body.axisy),b.aabb.minx=b.worldCOMx-b.radius,b.aabb.miny=b.worldCOMy-b.radius,b.aabb.maxx=b.worldCOMx+b.radius,b.aabb.maxy=b.worldCOMy+b.radius}else if(h.type===2)h.capsule.__validate_aabb();else{let b=h.polygon,g=b.lverts.next,P=b.gverts.next,v=g;g=g.next,P.x=b.body.posx+(b.body.axisy*v.x-b.body.axisx*v.y),P.y=b.body.posy+(v.x*b.body.axisx+v.y*b.body.axisy),b.aabb.minx=P.x,b.aabb.miny=P.y,b.aabb.maxx=P.x,b.aabb.maxy=P.y;let N=b.gverts.next.next;for(;N!=null;){let k=N,C=g;g=g.next,k.x=b.body.posx+(b.body.axisy*C.x-b.body.axisx*C.y),k.y=b.body.posy+(C.x*b.body.axisx+C.y*b.body.axisy),k.x<b.aabb.minx&&(b.aabb.minx=k.x),k.x>b.aabb.maxx&&(b.aabb.maxx=k.x),k.y<b.aabb.miny&&(b.aabb.miny=k.y),k.y>b.aabb.maxy&&(b.aabb.maxy=k.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 b=Z++,g=f*b*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 k=N*N,C=1-.5*k,E=1-k*k/8,M=(C*i.axisx+N*i.axisy)*E;i.axisy=(C*i.axisy-N*i.axisx)*E,i.axisx=M}}}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,k=v.gverts.next,C=N;N=N.next,k.x=v.body.posx+(v.body.axisy*C.x-v.body.axisx*C.y),k.y=v.body.posy+(C.x*v.body.axisx+C.y*v.body.axisy),v.aabb.minx=k.x,v.aabb.miny=k.y,v.aabb.maxx=k.x,v.aabb.maxy=k.y;let E=v.gverts.next.next;for(;E!=null;){let M=E,S=N;N=N.next,M.x=v.body.posx+(v.body.axisy*S.x-v.body.axisx*S.y),M.y=v.body.posy+(S.x*v.body.axisx+S.y*v.body.axisy),M.x<v.aabb.minx&&(v.aabb.minx=M.x),M.x>v.aabb.maxx&&(v.aabb.maxx=M.x),M.y<v.aabb.miny&&(v.aabb.miny=M.y),M.y>v.aabb.maxy&&(v.aabb.maxy=M.y),E=E.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=!1,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=!0)}}else i.sweepFrozen=!0,i.bullet=!1}s=s.next}}presteparb(e,t,n){if(n==null&&(n=!1),!e.cleared&&e.b1.component.sleeping&&e.b2.component.sleeping)return e.sleep_stamp=this.stamp,e.sleeping=!0,!0;if(!e.cleared||e.present!=0||e.intchange){let i=!n&&e.up_stamp==this.stamp-1&&!e.cleared&&!e.intchange,l=e.fresh&&!e.cleared&&!e.intchange;if(i&&(e.endGenerated=this.stamp),l||i||e.cleared||e.intchange){let o=e.ws1,r=e.ws2,a=this.mrca1;for(;a.head!=null;){let x=a.head;a.head=x.next;let m=x;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m,a.head==null&&(a.pushmod=!0),a.modified=!0,a.length--}a.pushmod=!0;let p=this.mrca2;for(;p.head!=null;){let x=p.head;p.head=x.next;let m=x;m.elt=null,m.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=m,p.head==null&&(p.pushmod=!0),p.modified=!0,p.length--}if(p.pushmod=!0,o.cbSet!=null){let x=this.mrca1,m;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=!0,x.length++}if(o.body.cbSet!=null){let x=this.mrca1,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=!0,x.length++}if(r.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=r;let _=m;_.next=x.head,x.head=_,x.modified=!0,x.length++}if(r.body.cbSet!=null){let x=this.mrca2,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=!0,x.length++}let c=o.body.compound,h=r.body.compound;for(;c!=h;){let x=c==null?0:c.depth,m=h==null?0:h.depth;if(x<m){if(h.cbSet!=null){let _=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=!0,_.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=!0,_.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,f=y.manager,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=!0,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=!1,w.__validate()),w.listeners.head==null){m=m.next;continue}let b=I._zpp.phys.ZPP_Interactor.get(x,_);if(l||e.intchange){b==null&&(b=Kt.get(x,_),this.add_callbackset(b));let g=y.manager,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=!0,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=!1,P.__validate());let k=P.listeners.head;for(;k!=null;){let S=k.elt;if(S.event==0&&(S.itype&e.type)!=0&&b.empty_arb(S.itype)){let O=this.push_callback(S);O.event=0;let L=b.int1,T=b.int2,R,q=S.options1,G=L.cbTypes;if(q.nonemptyintersection(G,q.includes)&&!q.nonemptyintersection(G,q.excludes)){let B=S.options2,V=T.cbTypes;R=B.nonemptyintersection(V,B.includes)&&!B.nonemptyintersection(V,B.excludes)}else R=!1;R?(O.int1=L,O.int2=T):(O.int1=T,O.int2=L),O.set=b}k=k.next}let C,E;E=!1;let M=b.arbiters.head;for(;M!=null;){if(M.elt==e){E=!0;break}M=M.next}if(E)C=!1;else{let S=b.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 L=O;L.next=S.head,S.head=L,S.modified=!0,S.length++,C=!0}C&&e.present++}else{e.present--,b.remove_arb(e);let g=y.manager,P=null,N=(y.cbpairs.length<z.cbpairs.length?y.cbpairs:z.cbpairs).head;for(;N!=null;){let C=N.elt;if(C.a==y&&C.b==z||C.a==z&&C.b==y){P=C;break}N=N.next}if(P==null){let C;Ne.zpp_pool==null?C=new Ne:(C=Ne.zpp_pool,Ne.zpp_pool=C.next,C.next=null),C.zip_listeners=!0,dt.setlt(y,z)?(C.a=y,C.b=z):(C.a=z,C.b=y),P=C,y.cbpairs.add(P),z!=y&&z.cbpairs.add(P)}P.zip_listeners&&(P.zip_listeners=!1,P.__validate());let k=P.listeners.head;for(;k!=null;){let C=k.elt;if(C.event==1&&(C.itype&e.type)!=0&&b.empty_arb(C.itype)){let E=this.push_callback(C);E.event=1;let M=b.int1,S=b.int2,O,L=C.options1,T=M.cbTypes;if(L.nonemptyintersection(T,L.includes)&&!L.nonemptyintersection(T,L.excludes)){let R=C.options2,q=S.cbTypes;O=R.nonemptyintersection(q,R.includes)&&!R.nonemptyintersection(q,R.excludes)}else O=!1;O?(E.int1=M,E.int2=S):(E.int1=S,E.int2=M),E.set=b}k=k.next}b.arbiters.head==null&&this.remove_callbackset(b)}m=m.next}u=u.next}}e.fresh=!1,e.intchange=!1}if(e.cleared||e.up_stamp+(e.type==Ie.COL?I._nape.Config.arbiterExpirationDelay:0)<this.stamp){if(e.type==Ie.SENSOR){let i=e.sensorarb;if(!i.cleared){let o=i.b1.arbiters,r=null,a=o.head,p=!1;for(;a!=null;){if(a.elt==i){let m,_;r==null?(m=o.head,_=m.next,o.head=_,o.head==null&&(o.pushmod=!0)):(m=r.next,_=m.next,r.next=_,_==null&&(o.pushmod=!0));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,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}r=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let m,_;h==null?(m=c.head,_=m.next,c.head=_,c.head==null&&(c.pushmod=!0)):(m=h.next,_=m.next,h.next=_,_==null&&(c.pushmod=!0));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=!0,c.length--,c.pushmod=!0,x=!0;break}h=u,u=u.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let l=i;l.next=Ot.zpp_pool,Ot.zpp_pool=l}else if(e.type==Ie.FLUID){let i=e.fluidarb;if(!i.cleared){let o=i.b1.arbiters,r=null,a=o.head,p=!1;for(;a!=null;){if(a.elt==i){let m,_;r==null?(m=o.head,_=m.next,o.head=_,o.head==null&&(o.pushmod=!0)):(m=r.next,_=m.next,r.next=_,_==null&&(o.pushmod=!0));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,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}r=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let m,_;h==null?(m=c.head,_=m.next,c.head=_,c.head==null&&(c.pushmod=!0)):(m=h.next,_=m.next,h.next=_,_==null&&(c.pushmod=!0));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=!0,c.length--,c.pushmod=!0,x=!0;break}h=u,u=u.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}i.b1=i.b2=null,i.active=!1,i.intchange=!1;let l=i;l.next=Pt.zpp_pool,Pt.zpp_pool=l,i.pre_dt=-1}else{let i=e.colarb;if(!i.cleared){let o=i.b1.arbiters,r=null,a=o.head,p=!1;for(;a!=null;){if(a.elt==i){let m,_;r==null?(m=o.head,_=m.next,o.head=_,o.head==null&&(o.pushmod=!0)):(m=r.next,_=m.next,r.next=_,_==null&&(o.pushmod=!0));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,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}r=a,a=a.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let m,_;h==null?(m=c.head,_=m.next,c.head=_,c.head==null&&(c.pushmod=!0)):(m=h.next,_=m.next,h.next=_,_==null&&(c.pushmod=!0));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=!0,c.length--,c.pushmod=!0,x=!0;break}h=u,u=u.next}i.pair!=null&&(i.pair.arb=null,i.pair=null)}for(i.b1=i.b2=null,i.active=!1,i.intchange=!1;i.contacts.next!=null;){let o=i.contacts,r=o.next;o.pop();let a=r;a.arbiter=null,a.next=Pe.zpp_pool,Pe.zpp_pool=a;let p=i.innards,c=p.next;p.next=c.next,c._inuse=!1,p.next==null&&(p.pushmod=!0),p.modified=!0,p.length--}let l=i;l.userdef_dyn_fric=!1,l.userdef_stat_fric=!1,l.userdef_restitution=!1,l.userdef_rfric=!1,l.__ref_edge1=l.__ref_edge2=null,l.next=ut.zpp_pool,ut.zpp_pool=l,i.pre_dt=-1}return!0}let s=e.active;if(e.active=e.presentable=e.up_stamp==this.stamp,(e.immState&1)!=0){if(e.active&&e.type!=Ie.SENSOR)if(e.colarb!=null){let i=e.colarb;i.invalidated&&(i.invalidated=!1,i.userdef_restitution||(i.s1.material.elasticity<=-1/0||i.s2.material.elasticity<=-1/0?i.restitution=0:i.s1.material.elasticity>=1/0||i.s2.material.elasticity>=1/0?i.restitution=1:i.restitution=(i.s1.material.elasticity+i.s2.material.elasticity)/2,i.restitution<0&&(i.restitution=0),i.restitution>1&&(i.restitution=1)),i.userdef_dyn_fric||(i.dyn_fric=Math.sqrt(i.s1.material.dynamicFriction*i.s2.material.dynamicFriction)),i.userdef_stat_fric||(i.stat_fric=Math.sqrt(i.s1.material.staticFriction*i.s2.material.staticFriction)),i.userdef_rfric||(i.rfric=Math.sqrt(i.s1.material.rollingFriction*i.s2.material.rollingFriction))),i.pre_dt==-1&&(i.pre_dt=t);let l=t/i.pre_dt;i.pre_dt=t;let o=i.b1.smass+i.b2.smass;i.hc2=!1;let r=!0,p=i.b1.type!=2||i.b2.type!=2?i.continuous?I._nape.Config.contactContinuousStaticBiasCoef:I._nape.Config.contactStaticBiasCoef:i.continuous?I._nape.Config.contactContinuousBiasCoef:I._nape.Config.contactBiasCoef;i.biasCoef=p,i.continuous=!1;let c=null,h=null,u=i.innards.next,x=i.contacts.next;for(;x!=null;){let _=x;if(_.stamp+I._nape.Config.arbiterExpirationDelay<i.stamp){let f=i.contacts,w,Z;c==null?(w=f.next,Z=w.next,f.next=Z,f.next==null&&(f.pushmod=!0)):(w=c.next,Z=w.next,c.next=Z,Z==null&&(f.pushmod=!0)),w._inuse=!1,f.modified=!0,f.length--,f.pushmod=!0,x=Z;let d=i.innards,b,g;h==null?(b=d.next,g=b.next,d.next=g,d.next==null&&(d.pushmod=!0)):(b=h.next,g=b.next,h.next=g,g==null&&(d.pushmod=!0)),b._inuse=!1,d.modified=!0,d.length--,d.pushmod=!0,u=g;let P=_;P.arbiter=null,P.next=Pe.zpp_pool,Pe.zpp_pool=P;continue}let y=_.inner,z=_.active;if(_.active=_.stamp==i.stamp,_.active){r?(r=!1,i.c1=y,i.oc1=_):(i.hc2=!0,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 f=y.r2x*i.nx+y.r2y*i.ny,w=o+i.b2.sinertia*(f*f),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,b=o+i.b2.sinertia*(d*d),g=i.ny*y.r1x-i.nx*y.r1y;b+=i.b1.sinertia*(g*g),y.nMass=b<I._nape.Config.epsilon*I._nape.Config.epsilon?0:1/b;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 k=i.nx*P+i.ny*v;_.elasticity=i.restitution,y.bounce=k*_.elasticity,y.bounce>-I._nape.Config.elasticThreshold&&(y.bounce=0),k=v*i.nx-P*i.ny;let C=I._nape.Config.staticFrictionThreshold;k*k>C*C?y.friction=i.dyn_fric:y.friction=i.stat_fric,y.jnAcc*=l,y.jtAcc*=l}z!=_.active&&(i.contacts.modified=!0),c=x,h=u,u=u.next,x=x.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let _=i.c1;i.c1=i.c2,i.c2=_;let y=i.oc1;i.oc1=i.oc2,i.oc2=y,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(r=!0)}else i.hpc2=!1;if(i.jrAcc*=l,r||(i.rn1a=i.ny*i.c1.r1x-i.nx*i.c1.r1y,i.rt1a=i.c1.r1x*i.nx+i.c1.r1y*i.ny,i.rn1b=i.ny*i.c1.r2x-i.nx*i.c1.r2y,i.rt1b=i.c1.r2x*i.nx+i.c1.r2y*i.ny,i.k1x=i.b2.kinvelx-i.c1.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c1.r1y*i.b1.kinangvel),i.k1y=i.b2.kinvely+i.c1.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c1.r1x*i.b1.kinangvel)),i.hc2)if(i.rn2a=i.ny*i.c2.r1x-i.nx*i.c2.r1y,i.rt2a=i.c2.r1x*i.nx+i.c2.r1y*i.ny,i.rn2b=i.ny*i.c2.r2x-i.nx*i.c2.r2y,i.rt2b=i.c2.r2x*i.nx+i.c2.r2y*i.ny,i.k2x=i.b2.kinvelx-i.c2.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c2.r1y*i.b1.kinangvel),i.k2y=i.b2.kinvely+i.c2.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c2.r1x*i.b1.kinangvel),i.kMassa=o+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=o+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=o+i.b1.sinertia*i.rn2a*i.rn2a+i.b2.sinertia*i.rn2b*i.rn2b,i.kMassa*i.kMassa+2*i.kMassb*i.kMassb+i.kMassc*i.kMassc<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=!1,i.oc2.dist<i.oc1.dist){let y=i.c1;i.c1=i.c2,i.c2=y}i.oc2.active=!1,i.contacts.modified=!0}i.surfacex=i.b2.svelx,i.surfacey=i.b2.svely;let m=1;i.surfacex+=i.b1.svelx*m,i.surfacey+=i.b1.svely*m,i.surfacex=-i.surfacex,i.surfacey=-i.surfacey,i.rMass=i.b1.sinertia+i.b2.sinertia,i.rMass!=0&&(i.rMass=1/i.rMass),r&&(e.active=!1)}else{let i=e.fluidarb;i.pre_dt==-1&&(i.pre_dt=t);let l=t/i.pre_dt;i.pre_dt=t,i.r1x=i.centroidx-i.b1.posx,i.r1y=i.centroidy-i.b1.posy,i.r2x=i.centroidx-i.b2.posx,i.r2y=i.centroidy-i.b2.posy;let o=0,r=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(o=i.ws1.fluidProperties.gravityx,r=i.ws1.fluidProperties.gravityy):(o=this.gravityx,r=this.gravityy);let a=0,p=0;i.ws2.fluidEnabled&&i.ws2.fluidProperties.wrap_gravity!=null?(a=i.ws2.fluidProperties.gravityx,p=i.ws2.fluidProperties.gravityy):(a=this.gravityx,p=this.gravityy);let c=0,h=0;if(i.ws1.fluidEnabled&&i.ws2.fluidEnabled){let m=i.overlap*i.ws1.fluidProperties.density,_=i.overlap*i.ws2.fluidProperties.density;if(m>_){let y=m+_;c-=o*y,h-=r*y}else if(m<_){let y=m+_;c+=a*y,h+=p*y}else{let y=0,z=0;y=o+a,z=r+p;let f=.5;if(y*=f,z*=f,i.ws1.worldCOMx*y+i.ws1.worldCOMy*z>i.ws2.worldCOMx*y+i.ws2.worldCOMy*z){let 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-=o*_,h-=r*_}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=!0,i.dampx=0,i.dampy=0,i.adamp=0;else{i.nodrag=!1;let m=0;if(i.ws1.fluidEnabled&&(i.ws2.validate_angDrag(),m+=i.ws1.fluidProperties.viscosity*i.ws2.angDrag*i.overlap/i.ws2.area),i.ws2.fluidEnabled&&(i.ws1.validate_angDrag(),m+=i.ws2.fluidProperties.viscosity*i.ws1.angDrag*i.overlap/i.ws1.area),m!=0){let f=i.b1.sinertia+i.b2.sinertia;f!=0?i.wMass=1/f:i.wMass=0,m*=4e-4;let w=2*Math.PI*m;i.agamma=1/(t*w*(2+w*t));let Z=1/(1+i.agamma),d=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 f=_*_+y*y,Z=1/Math.sqrt(f);_*=Z,y*=Z,i.nx=_,i.ny=y}let z=0;if(i.ws1.fluidEnabled){let f=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)z-=f*i.ws2.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else if(i.ws2.type===2){let w=i.ws2.capsule.radius;z-=f*w*I._nape.Config.fluidLinearDrag/(2*w*Math.PI)}else{let w=i.ws2.polygon,Z=0,d=0,b=w.edges.head;for(;b!=null;){let g=b.elt;Z+=g.length;let P=f*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,b=b.next}z+=d/Z}}if(i.ws2.fluidEnabled){let f=-i.ws2.fluidProperties.viscosity*i.overlap/i.ws1.area;if(i.ws1.type==0)z-=f*i.ws1.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else if(i.ws1.type===2){let w=i.ws1.capsule.radius;z-=f*w*I._nape.Config.fluidLinearDrag/(2*w*Math.PI)}else{let w=i.ws1.polygon,Z=0,d=0,b=w.edges.head;for(;b!=null;){let g=b.elt;Z+=g.length;let P=f*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,b=b.next}z+=d/Z}}if(z!=0){let f=i.b1.smass+i.b2.smass,w=0,Z=0,d=0;if(w=f,Z=0,d=f,i.b1.sinertia!=0){let k=i.r1x*i.b1.sinertia,C=i.r1y*i.b1.sinertia;w+=C*i.r1y,Z+=-C*i.r1x,d+=k*i.r1x}if(i.b2.sinertia!=0){let k=i.r2x*i.b2.sinertia,C=i.r2y*i.b2.sinertia;w+=C*i.r2y,Z+=-C*i.r2x,d+=k*i.r2x}let b=w*d-Z*Z;if(b!=b)d=0,Z=d,w=Z;else if(b==0){let k=0;w!=0?w=1/w:(w=0,k|=1),d!=0?d=1/d:(d=0,k|=2),Z=0}else{b=1/b;let k=d*b;d=w*b,w=k,Z*=-b}i.vMassa=w,i.vMassb=Z,i.vMassc=d;let g,P=2*Math.PI*z;i.lgamma=1/(t*P*(2+P*t));let v=1/(1+i.lgamma);g=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=!0,o=null,r=null,a=i.innards.next;i.hc2=!1;let p=i.contacts.next;for(;p!=null;){let c=p;if(c.stamp+I._nape.Config.arbiterExpirationDelay<i.stamp){let x=i.contacts,m,_;o==null?(m=x.next,_=m.next,x.next=_,x.next==null&&(x.pushmod=!0)):(m=o.next,_=m.next,o.next=_,_==null&&(x.pushmod=!0)),m._inuse=!1,x.modified=!0,x.length--,x.pushmod=!0,p=_;let y=i.innards,z,f;r==null?(z=y.next,f=z.next,y.next=f,y.next==null&&(y.pushmod=!0)):(z=r.next,f=z.next,r.next=f,f==null&&(y.pushmod=!0)),z._inuse=!1,y.modified=!0,y.length--,y.pushmod=!0,a=f;let w=c;w.arbiter=null,w.next=Pe.zpp_pool,Pe.zpp_pool=w;continue}let h=c.inner,u=c.active;c.active=c.stamp==i.stamp,c.active&&(l?(l=!1,i.c1=h,i.oc1=c):(i.hc2=!0,i.c2=h,i.oc2=c)),u!=c.active&&(i.contacts.modified=!0),o=p,r=a,a=a.next,p=p.next}if(i.hc2){if(i.hpc2=!0,i.oc1.posOnly){let c=i.c1;i.c1=i.c2,i.c2=c;let h=i.oc1;i.oc1=i.oc2,i.oc2=h,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(l=!0)}else i.hpc2=!1;l&&(e.active=!1)}return s!=e.active&&(e.b1.arbiters.modified=!0,e.b2.arbiters.modified=!0,this.c_arbiters_true.modified=this.c_arbiters_false.modified=!0,this.s_arbiters.modified=this.f_arbiters.modified=!0),!1}_prestepArbiterList(e,t,n){let s=null,i=e.head;for(;i!=null;){let l=i.elt;if(this.presteparb(l,n)){let o,r;s==null?(o=e.head,r=o.next,e.head=r,e.head==null&&(e.pushmod=!0)):(o=s.next,r=o.next,s.next=r,r==null&&(e.pushmod=!0)),o.elt=null,o.next=t.zpp_pool,t.zpp_pool=o,e.modified=!0,e.length--,e.pushmod=!0,i=r;continue}s=i,i=i.next}}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let r=n.elt;if(r.preStep(e)){n=this.live_constraints.erase(t),r.broken(),this.constraintCbBreak(r),r.removeOnBreak?(r.component.sleeping=!0,this.midstep=!1,r.compound!=null?r.compound.wrap_constraints.remove(r.outer):this.wrap_constraints.remove(r.outer),this.midstep=!0):r.active=!1,r.clearcache();continue}t=n,n=n.next}let s=null,i=this.c_arbiters_true,l=i.head,o=this.c_arbiters_false!=null;for(o&&l==null&&(o=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);l!=null;){let r=l.elt;if(this.presteparb(r,e)){let a,p;s==null?(a=i.head,p=a.next,i.head=p,i.head==null&&(i.pushmod=!0)):(a=s.next,p=a.next,s.next=p,p==null&&(i.pushmod=!0));let c=a;c.elt=null,c.next=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=c,i.modified=!0,i.length--,i.pushmod=!0,l=p,o&&l==null&&(o=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null);continue}s=l,l=l.next,o&&l==null&&(o=!1,l=this.c_arbiters_false.head,i=this.c_arbiters_false,s=null)}this._prestepArbiterList(this.f_arbiters,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 o=i.b2.imass;i.b2.velx+=i.dampx*o,i.b2.vely+=i.dampy*o,i.b1.angvel-=i.b1.iinertia*(i.dampy*i.r1x-i.dampx*i.r1y),i.b2.angvel+=i.b2.iinertia*(i.dampy*i.r2x-i.dampx*i.r2y),i.b1.angvel-=i.adamp*i.b1.iinertia,i.b2.angvel+=i.adamp*i.b2.iinertia}e=e.next}let t=this.c_arbiters_false.head,n=!0;for(t==null&&(t=this.c_arbiters_true.head,n=!1);t!=null;){let i=t.elt;if(i.active&&(i.immState&1)!=0){let l=i.nx*i.c1.jnAcc-i.ny*i.c1.jtAcc,o=i.ny*i.c1.jnAcc+i.nx*i.c1.jtAcc,r=i.b1.imass;i.b1.velx-=l*r,i.b1.vely-=o*r,i.b1.angvel-=i.b1.iinertia*(o*i.c1.r1x-l*i.c1.r1y);let a=i.b2.imass;if(i.b2.velx+=l*a,i.b2.vely+=o*a,i.b2.angvel+=i.b2.iinertia*(o*i.c1.r2x-l*i.c1.r2y),i.hc2){let p=i.nx*i.c2.jnAcc-i.ny*i.c2.jtAcc,c=i.ny*i.c2.jnAcc+i.nx*i.c2.jtAcc,h=i.b1.imass;i.b1.velx-=p*h,i.b1.vely-=c*h,i.b1.angvel-=i.b1.iinertia*(c*i.c2.r1x-p*i.c2.r1y);let u=i.b2.imass;i.b2.velx+=p*u,i.b2.vely+=c*u,i.b2.angvel+=i.b2.iinertia*(c*i.c2.r2x-p*i.c2.r2y)}i.b2.angvel+=i.jrAcc*i.b2.iinertia,i.b1.angvel-=i.jrAcc*i.b1.iinertia}t=t.next,n&&t==null&&(t=this.c_arbiters_true.head,n=!1)}let s=this.live_constraints.head;for(;s!=null;)s.elt.warmStart(),s=s.next}iterateVel(e){let t=0,n=e;for(;t<n;){let s=t++,i=this.f_arbiters.head;for(;i!=null;){let p=i.elt;if(p.active&&(p.immState&1)!=0&&!p.nodrag){let c=p.b1.angvel+p.b1.kinangvel,h=p.b2.angvel+p.b2.kinangvel,u=p.b1.velx+p.b1.kinvelx-p.r1y*c-(p.b2.velx+p.b2.kinvelx-p.r2y*h),x=p.b1.vely+p.b1.kinvely+p.r1x*c-(p.b2.vely+p.b2.kinvely+p.r2x*h),m=p.vMassa*u+p.vMassb*x;x=p.vMassb*u+p.vMassc*x,u=m;let _=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 f=p.b2.imass;p.b2.velx+=u*f,p.b2.vely+=x*f,p.b1.angvel-=p.b1.iinertia*(x*p.r1x-u*p.r1y),p.b2.angvel+=p.b2.iinertia*(x*p.r2x-u*p.r2y);let 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,o=this.live_constraints.head;for(;o!=null;){let p=o.elt;if(p.applyImpulseVel()){o=this.live_constraints.erase(l),p.broken(),this.constraintCbBreak(p),p.removeOnBreak?(p.component.sleeping=!0,this.midstep=!1,p.compound!=null?p.compound.wrap_constraints.remove(p.outer):this.wrap_constraints.remove(p.outer),this.midstep=!0):p.active=!1,p.clearcache();continue}l=o,o=o.next}let r=this.c_arbiters_false.head,a=!0;for(r==null&&(r=this.c_arbiters_true.head,a=!1);r!=null;){let p=r.elt;if(p.active&&(p.immState&1)!=0){let c=p.k1x+p.b2.velx-p.c1.r2y*p.b2.angvel-(p.b1.velx-p.c1.r1y*p.b1.angvel),h=p.k1y+p.b2.vely+p.c1.r2x*p.b2.angvel-(p.b1.vely+p.c1.r1x*p.b1.angvel),u=(h*p.nx-c*p.ny+p.surfacex)*p.c1.tMass,x=p.c1.friction*p.c1.jnAcc,m=p.c1.jtAcc,_=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 f=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-f*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),f=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,b=c*p.nx+h*p.ny+p.surfacey+p.c1.bounce-(p.Ka*Z+p.Kb*d),g=f*p.nx+w*p.ny+p.surfacey+p.c2.bounce-(p.Kb*Z+p.Kc*d),P=-(p.kMassa*b+p.kMassb*g),v=-(p.kMassb*b+p.kMassc*g);P>=0&&v>=0?(b=P-Z,g=v-d,p.c1.jnAcc=P,p.c2.jnAcc=v):(P=-p.c1.nMass*b,P>=0&&p.Kb*P+g>=0?(b=P-Z,g=-d,p.c1.jnAcc=P,p.c2.jnAcc=0):(v=-p.c2.nMass*g,v>=0&&p.Kb*v+b>=0?(b=-Z,g=v-d,p.c1.jnAcc=0,p.c2.jnAcc=v):b>=0&&g>=0?(b=-Z,g=-d,p.c1.jnAcc=p.c2.jnAcc=0):(b=0,g=0))),u=b+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*b+p.rn2b*g)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*b+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}r=r.next,a&&r==null&&(r=this.c_arbiters_true.head,a=!1)}}}iteratePos(e){let t=0,n=e;for(;t<n;){let s=t++,i=null,l=this.live_constraints.head;for(;l!=null;){let a=l.elt;if(!a.__velocity&&a.stiff&&a.applyImpulsePos()){l=this.live_constraints.erase(i),a.broken(),this.constraintCbBreak(a),a.removeOnBreak?(a.component.sleeping=!0,this.midstep=!1,a.compound!=null?a.compound.wrap_constraints.remove(a.outer):this.wrap_constraints.remove(a.outer),this.midstep=!0):a.active=!1,a.clearcache();continue}i=l,l=l.next}let o=this.c_arbiters_false.head,r=!0;for(o==null&&(o=this.c_arbiters_true.head,r=!1);o!=null;){let a=o.elt;if(a.active&&(a.immState&1)!=0)if(a.ptype==2){let p=a.c1,c=0,h=0;c=a.b2.axisy*p.lr2x-a.b2.axisx*p.lr2y,h=p.lr2x*a.b2.axisx+p.lr2y*a.b2.axisy;let u=1;c+=a.b2.posx*u,h+=a.b2.posy*u;let x=0,m=0;x=a.b1.axisy*p.lr1x-a.b1.axisx*p.lr1y,m=p.lr1x*a.b1.axisx+p.lr1y*a.b1.axisy;let _=1;x+=a.b1.posx*_,m+=a.b1.posy*_;let y=0,z=0;y=c-x,z=h-m;let f=Math.sqrt(y*y+z*z),w=a.radius-I._nape.Config.collisionSlop,Z=f-w;if(y*a.nx+z*a.ny<0&&(y=-y,z=-z,Z-=a.radius),Z<0)if(f<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/f;y*=d,z*=d;let b=.5*(x+c),g=.5*(m+h),P=f-w;x=b-a.b1.posx,m=g-a.b1.posy,c=b-a.b2.posx,h=g-a.b2.posy;let v=z*x-y*m,N=z*c-y*h,k=a.b2.smass+N*N*a.b2.sinertia+a.b1.smass+v*v*a.b1.sinertia;if(k!=0){let C=-a.biasCoef*P/k,E=0,M=0,S=C;E=y*S,M=z*S;let O=a.b1.imass;a.b1.posx-=E*O,a.b1.posy-=M*O;let L=a.b1,T=-v*a.b1.iinertia*C;if(L.rot+=T,T*T>1e-4)L.axisx=Math.sin(L.rot),L.axisy=Math.cos(L.rot);else{let B=T*T,V=1-.5*B,Y=1-B*B/8,$=(V*L.axisx+T*L.axisy)*Y;L.axisy=(V*L.axisy-T*L.axisx)*Y,L.axisx=$}let R=a.b2.imass;a.b2.posx+=E*R,a.b2.posy+=M*R;let q=a.b2,G=N*a.b2.iinertia*C;if(q.rot+=G,G*G>1e-4)q.axisx=Math.sin(q.rot),q.axisy=Math.cos(q.rot);else{let B=G*G,V=1-.5*B,Y=1-B*B/8,$=(V*q.axisx+G*q.axisy)*Y;q.axisy=(V*q.axisy-G*q.axisx)*Y,q.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 f=1;if(u+=a.b2.posx*f,x+=a.b2.posy*f,a.hpc2){m=a.b2.axisy*a.c2.lr1x-a.b2.axisx*a.c2.lr1y,_=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 f=1;if(u+=a.b1.posx*f,x+=a.b1.posy*f,a.hpc2){m=a.b1.axisy*a.c2.lr1x-a.b1.axisx*a.c2.lr1y,_=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 f=0,w=0;f=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 b=0,g=0,P=0,v=0;if(a.hpc2){b=m-a.b1.posx,g=_-a.b1.posy,P=m-a.b2.posx,v=_-a.b2.posy;let N=c*f-p*w,k=c*Z-p*d,C=c*b-p*g,E=c*P-p*v,M=a.b1.smass+a.b2.smass;a.kMassa=M+a.b1.sinertia*N*N+a.b2.sinertia*k*k,a.kMassb=M+a.b1.sinertia*N*C+a.b2.sinertia*k*E,a.kMassc=M+a.b1.sinertia*C*C+a.b2.sinertia*E*E;let S=0,O=0,L=0;S=a.kMassa,O=a.kMassb,L=a.kMassc;let T=y*a.biasCoef,R=z*a.biasCoef;for(;;){let q=0,G=0;q=T,G=R,q=-q,G=-G;let B=a.kMassa*a.kMassc-a.kMassb*a.kMassb;if(B!=B)G=0,q=G;else if(B==0)a.kMassa!=0?q/=a.kMassa:q=0,a.kMassc!=0?G/=a.kMassc:G=0;else{B=1/B;let $=B*(a.kMassc*q-a.kMassb*G);G=B*(a.kMassa*G-a.kMassb*q),q=$}if(q>=0&&G>=0){let $=(q+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let X=a.b1,H=-a.b1.iinertia*(N*q+C*G);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let D=H*H,A=1-.5*D,J=1-D*D/8,Q=(A*X.axisx+H*X.axisy)*J;X.axisy=(A*X.axisy-H*X.axisx)*J,X.axisx=Q}let ee=(q+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let W=a.b2,F=a.b2.iinertia*(k*q+E*G);if(W.rot+=F,F*F>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let D=F*F,A=1-.5*D,J=1-D*D/8,Q=(A*W.axisx+F*W.axisy)*J;W.axisy=(A*W.axisy-F*W.axisx)*J,W.axisx=Q}break}q=-T/S,G=0;let V=O*q+R;if(q>=0&&V>=0){let $=(q+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let X=a.b1,H=-a.b1.iinertia*(N*q+C*G);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let D=H*H,A=1-.5*D,J=1-D*D/8,Q=(A*X.axisx+H*X.axisy)*J;X.axisy=(A*X.axisy-H*X.axisx)*J,X.axisx=Q}let ee=(q+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let W=a.b2,F=a.b2.iinertia*(k*q+E*G);if(W.rot+=F,F*F>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let D=F*F,A=1-.5*D,J=1-D*D/8,Q=(A*W.axisx+F*W.axisy)*J;W.axisy=(A*W.axisy-F*W.axisx)*J,W.axisx=Q}break}q=0,G=-R/L;let Y=O*G+T;if(G>=0&&Y>=0){let $=(q+G)*a.b1.imass;a.b1.posx-=p*$,a.b1.posy-=c*$;let X=a.b1,H=-a.b1.iinertia*(N*q+C*G);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let D=H*H,A=1-.5*D,J=1-D*D/8,Q=(A*X.axisx+H*X.axisy)*J;X.axisy=(A*X.axisy-H*X.axisx)*J,X.axisx=Q}let ee=(q+G)*a.b2.imass;a.b2.posx+=p*ee,a.b2.posy+=c*ee;let W=a.b2,F=a.b2.iinertia*(k*q+E*G);if(W.rot+=F,F*F>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let D=F*F,A=1-.5*D,J=1-D*D/8,Q=(A*W.axisx+F*W.axisy)*J;W.axisy=(A*W.axisy-F*W.axisx)*J,W.axisx=Q}break}break}}else{let N=c*f-p*w,k=c*Z-p*d,C=a.b2.smass+k*k*a.b2.sinertia+a.b1.smass+N*N*a.b1.sinertia;if(C!=0){let E=-a.biasCoef*y/C,M=0,S=0,O=E;M=p*O,S=c*O;let L=a.b1.imass;a.b1.posx-=M*L,a.b1.posy-=S*L;let T=a.b1,R=-N*a.b1.iinertia*E;if(T.rot+=R,R*R>1e-4)T.axisx=Math.sin(T.rot),T.axisy=Math.cos(T.rot);else{let V=R*R,Y=1-.5*V,$=1-V*V/8,X=(Y*T.axisx+R*T.axisy)*$;T.axisy=(Y*T.axisy-R*T.axisx)*$,T.axisx=X}let q=a.b2.imass;a.b2.posx+=M*q,a.b2.posy+=S*q;let G=a.b2,B=k*a.b2.iinertia*E;if(G.rot+=B,B*B>1e-4)G.axisx=Math.sin(G.rot),G.axisy=Math.cos(G.rot);else{let V=B*B,Y=1-.5*V,$=1-V*V/8,X=(Y*G.axisx+B*G.axisy)*$;G.axisy=(Y*G.axisy-B*G.axisx)*$,G.axisx=X}}}}}o=o.next,r&&o==null&&(o=this.c_arbiters_true.head,r=!1)}}}group_ignore(e,t){let n=e;for(;n!=null&&n.group==null;)n.ishape!=null?n=n.ishape.body:n.icompound!=null?n=n.icompound.compound:n=n.ibody.compound;let s=n==null?null:n.group;if(s==null)return!1;{let i=t;for(;i!=null&&i.group==null;)i.ishape!=null?i=i.ishape.body:i.icompound!=null?i=i.icompound.compound:i=i.ibody.compound;let l=i==null?null:i.group;if(l==null)return!1;{let o=!1;for(;s!=null&&l!=null;){if(s==l){o=s.ignore;break}s.depth<l.depth?l=l.group:s=s.group}return o}}}interactionType(e,t,n,s){let i;i=!1;let l=n.constraints.head;for(;l!=null;){let r=l.elt;if(r.ignore&&r.pair_exists(n.id,s.id)){i=!0;break}l=l.next}let o;if(i)o=!1;else{let r=e;for(;r!=null&&r.group==null;)r.ishape!=null?r=r.ishape.body:r.icompound!=null?r=r.icompound.compound:r=r.ibody.compound;let a=r==null?null:r.group,p;if(a==null)p=!1;else{let c=t;for(;c!=null&&c.group==null;)c.ishape!=null?c=c.ishape.body:c.icompound!=null?c=c.icompound.compound:c=c.ibody.compound;let h=c==null?null:c.group;if(h==null)p=!1;else{let u=!1;for(;a!=null&&h!=null;){if(a==h){u=a.ignore;break}a.depth<h.depth?h=h.group:a=a.group}p=u}}o=!p}if(o){let r;if(e.sensorEnabled||t.sensorEnabled){let a=e.filter,p=t.filter;r=(a.sensorMask&p.sensorGroup)!=0&&(p.sensorMask&a.sensorGroup)!=0}else r=!1;if(r)return 2;{let a;if(e.fluidEnabled||t.fluidEnabled){let p=e.filter,c=t.filter;a=(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0}else a=!1;if(a&&!(n.imass==0&&s.imass==0&&n.iinertia==0&&s.iinertia==0))return 0;{let p=e.filter,c=t.filter;return(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!(n.imass==0&&s.imass==0&&n.iinertia==0&&s.iinertia==0)?1:-1}}}else return-1}narrowPhase(e,t,n,s,i){let l=null,o=e.body,r=t.body,a;a=!1;let p=o.constraints.head;for(;p!=null;){let u=p.elt;if(u.ignore&&u.pair_exists(o.id,r.id)){a=!0;break}p=p.next}let c,h;if(a)h=!1;else{let u=e;for(;u!=null&&u.group==null;)u.ishape!=null?u=u.ishape.body:u.icompound!=null?u=u.icompound.compound:u=u.ibody.compound;let x=u==null?null:u.group,m;if(x==null)m=!1;else{let _=t;for(;_!=null&&_.group==null;)_.ishape!=null?_=_.ishape.body:_.icompound!=null?_=_.icompound.compound:_=_.ibody.compound;let y=_==null?null:_.group;if(y==null)m=!1;else{let z=!1;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=!1;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=!1;if(x&&!(o.imass==0&&r.imass==0&&o.iinertia==0&&r.iinertia==0))c=0;else{let m=e.filter,_=t.filter;c=(m.collisionMask&_.collisionGroup)!=0&&(_.collisionMask&m.collisionGroup)!=0&&!(o.imass==0&&r.imass==0&&o.iinertia==0&&r.iinertia==0)?1:-1}}}else c=-1;if(c!=-1){let u,x;e.type>t.type?(u=t,x=e):e.type==t.type?e.id<t.id?(u=e,x=t):(x=e,u=t):(u=e,x=t);let m=u==t;if(c==0){let _;if(s==null){let Z=null,b=(o.arbiters.length<r.arbiters.length?o:r).arbiters.head;for(;b!=null;){let g=b.elt;if(g.id==u.id&&g.di==x.id){Z=g;break}b=b.next}_=Z}else _=s;let y=_==null,z,f=!1;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=!0;{let d=_.b1.arbiters,b=null,g=d.head,P=!1;for(;g!=null;){if(g.elt==_){let v,N;b==null?(v=d.head,N=v.next,d.head=N,d.head==null&&(d.pushmod=!0)):(v=b.next,N=v.next,b.next=N,N==null&&(d.pushmod=!0));let k=v;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,d.modified=!0,d.length--,d.pushmod=!0,P=!0;break}b=g,g=g.next}}{let d=_.b2.arbiters,b=null,g=d.head,P=!1;for(;g!=null;){if(g.elt==_){let v,N;b==null?(v=d.head,N=v.next,d.head=N,d.head==null&&(d.pushmod=!0)):(v=b.next,N=v.next,b.next=N,N==null&&(d.pushmod=!0));let k=v;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,d.modified=!0,d.length--,d.pushmod=!0,P=!0;break}b=g,g=g.next}}_.pair!=null&&(_.pair.arb=null,_.pair=null),_.active=!1,this.f_arbiters.modified=!0,Pt.zpp_pool==null?z=new Pt:(z=Pt.zpp_pool,Pt.zpp_pool=z.next,z.next=null),z.intchange=!0,y=!0,f=!0}else z=_.fluidarb;let w=4;if(y||z.stamp!=this.stamp||i)if(z.stamp=this.stamp,Ee.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,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=z;let g=b;g.next=d.head,d.head=g,d.modified=!0,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=!0,P.length++,z.active=!0,z.present=0,z.cleared=!1,z.sleeping=!1,z.fresh=!1,z.presentable=!1,z.nx=0,z.ny=1,z.dampx=0,z.dampy=0,z.adamp=0;let k=this.f_arbiters,C;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(C=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=C.next,C.next=null),C.elt=z;let E=C;E.next=k.head,k.head=E,k.modified=!0,k.length++,z.fresh=!f}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&i;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let Z=!1,d=z.ws1.id>z.ws2.id?z.ws2:z.ws1,b=z.ws1.id>z.ws2.id?z.ws1:z.ws2,g=this.mrca1;for(;g.head!=null;){let C=g.head;g.head=C.next;let E=C;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}g.pushmod=!0;let P=this.mrca2;for(;P.head!=null;){let C=P.head;P.head=C.next;let E=C;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}if(P.pushmod=!0,d.cbSet!=null){let C=this.mrca1,E;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?E=new I._zpp.util.ZNPNode_ZPP_Interactor:(E=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E.next,E.next=null),E.elt=d;let M=E;M.next=C.head,C.head=M,C.modified=!0,C.length++}if(d.body.cbSet!=null){let C=this.mrca1,E=d.body,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=E;let S=M;S.next=C.head,C.head=S,C.modified=!0,C.length++}if(b.cbSet!=null){let C=this.mrca2,E;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?E=new I._zpp.util.ZNPNode_ZPP_Interactor:(E=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E.next,E.next=null),E.elt=b;let M=E;M.next=C.head,C.head=M,C.modified=!0,C.length++}if(b.body.cbSet!=null){let C=this.mrca2,E=b.body,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=E;let S=M;S.next=C.head,C.head=S,C.modified=!0,C.length++}let v=d.body.compound,N=b.body.compound;for(;v!=N;){let C=v==null?0:v.depth,E=N==null?0:N.depth;if(C<E){if(N.cbSet!=null){let M=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=M.head,M.head=O,M.modified=!0,M.length++}N=N.compound}else{if(v.cbSet!=null){let M=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=M.head,M.head=O,M.modified=!0,M.length++}v=v.compound}}let k=this.mrca1.head;for(;k!=null;){let C=k.elt,E=this.mrca2.head;for(;E!=null;){let M=E.elt,S=C.cbSet,O=M.cbSet,L=S.manager,T=null,q=(S.cbpairs.length<O.cbpairs.length?S.cbpairs:O.cbpairs).head;for(;q!=null;){let F=q.elt;if(F.a==S&&F.b==O||F.a==O&&F.b==S){T=F;break}q=q.next}if(T==null){let F;Ne.zpp_pool==null?F=new Ne:(F=Ne.zpp_pool,Ne.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,dt.setlt(S,O)?(F.a=S,F.b=O):(F.a=O,F.b=S),T=F,S.cbpairs.add(T),O!=S&&O.cbpairs.add(T)}if(T.zip_listeners&&(T.zip_listeners=!1,T.__validate()),T.listeners.head==null){E=E.next;continue}let G=null,B=null,V=this.prelisteners;for(;V.head!=null;){let F=V.head;V.head=F.next;let D=F;D.elt=null,D.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=D,V.head==null&&(V.pushmod=!0),V.modified=!0,V.length--}V.pushmod=!0;let Y=null,$=S.manager,X=null,ee=(S.cbpairs.length<O.cbpairs.length?S.cbpairs:O.cbpairs).head;for(;ee!=null;){let F=ee.elt;if(F.a==S&&F.b==O||F.a==O&&F.b==S){X=F;break}ee=ee.next}if(X==null){let F;Ne.zpp_pool==null?F=new Ne:(F=Ne.zpp_pool,Ne.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,dt.setlt(S,O)?(F.a=S,F.b=O):(F.a=O,F.b=S),X=F,S.cbpairs.add(X),O!=S&&O.cbpairs.add(X)}X.zip_listeners&&(X.zip_listeners=!1,X.__validate());let W=X.listeners.head;for(;W!=null;){let F=W.elt;if(F.event==5&&(F.itype&w)!=0){let D=this.prelisteners,A;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?A=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(A=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=A.next,A.next=null),A.elt=F;let J=A;Y==null?(J.next=D.head,D.head=J):(J.next=Y.next,Y.next=J),D.pushmod=D.modified=!0,D.length++,Y=J,Z=Z||!F.pure}W=W.next}if(this.prelisteners.head==null){E=E.next;continue}if(G=I._zpp.phys.ZPP_Interactor.get(C,M),G==null&&(B=Kt.get(C,M),this.add_callbackset(B)),G==null||(G.FLUIDstamp!=this.stamp||i)&&(G.FLUIDstate&4)==0){if(B!=null&&(G=B),G!=null){let J=this.prelisteners.head;for(;J!=null;)J.elt.itype==7?(G.COLLISIONstamp=this.stamp,G.SENSORstamp=this.stamp,G.FLUIDstamp=this.stamp):G.FLUIDstamp=this.stamp,J=J.next}z.mutable=!0,z.wrap_position!=null&&(z.wrap_position.zpp_inner._immutable=!1);let F=z.active;z.active=!0;let D=!1;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=G;let A=this.prelisteners.head;for(;A!=null;){let J=A.elt;this.precb.zpp_inner.listener=J;let Q=this.precb.zpp_inner,K=G.int1,ie=G.int2,oe,se=J.options1,ne=K.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=J.options2,he=ie.cbTypes;oe=le.nonemptyintersection(he,le.includes)&&!le.nonemptyintersection(he,le.excludes)}else oe=!1;oe?(Q.int1=K,Q.int2=ie):(Q.int1=ie,Q.int2=K),this.precb.zpp_inner.pre_swapped=C!=this.precb.zpp_inner.int1;let re=J.handlerp(this.precb);if(re!=null){let le;U.PreFlag_ACCEPT==null&&(U.internal=!0,U.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,U.internal=!1),re==U.PreFlag_ACCEPT?le=5:(U.PreFlag_ACCEPT_ONCE==null&&(U.internal=!0,U.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,U.internal=!1),re==U.PreFlag_ACCEPT_ONCE?le=1:(U.PreFlag_IGNORE==null&&(U.internal=!0,U.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,U.internal=!1),le=re==U.PreFlag_IGNORE?6:2)),z.immState=le}A=A.next}if(z.mutable=!1,z.wrap_position!=null&&(z.wrap_position.zpp_inner._immutable=!0),z.active=F,G!=null){let J=this.prelisteners.head;for(;J!=null;)J.elt.itype==7&&(G.COLLISIONstate=z.immState,G.SENSORstate=z.immState),G.FLUIDstate=z.immState,J=J.next}}else G==null?(z.immState&4)==0&&(z.immState=1):z.immState=G.FLUIDstate;E=E.next}k=k.next}if(Z&&(z.immState&4)==0){if(z.b1.type==2){let C=z.b1;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}if(z.b1.type==2){let C=z.b2;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}}}if((z.immState&1)!=0){if(z.b1.type==2&&z.b1.component.sleeping){let Z=z.b1;Z.world||(Z.component.waket=this.stamp+(this.midstep?0:1),Z.type==3&&(Z.kinematicDelaySleep=!0),Z.component.sleeping&&this.really_wake(Z,!1))}if(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=!0),Z.component.sleeping&&this.really_wake(Z,!1))}}if(z.sleeping){z.sleeping=!1;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 b=d;b.next=Z.head,Z.head=b,Z.modified=!0,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=(o.arbiters.length<r.arbiters.length?o:r).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,f,w=!1;if(z)ut.zpp_pool==null?f=new ut:(f=ut.zpp_pool,ut.zpp_pool=f.next,f.next=null),f.stat=n;else if(y.colarb==null){y.cleared=!0;{let b=y.b1.arbiters,g=null,P=b.head,v=!1;for(;P!=null;){if(P.elt==y){let N,k;g==null?(N=b.head,k=N.next,b.head=k,b.head==null&&(b.pushmod=!0)):(N=g.next,k=N.next,g.next=k,k==null&&(b.pushmod=!0));let C=N;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=C,b.modified=!0,b.length--,b.pushmod=!0,v=!0;break}g=P,P=P.next}}{let b=y.b2.arbiters,g=null,P=b.head,v=!1;for(;P!=null;){if(P.elt==y){let N,k;g==null?(N=b.head,k=N.next,b.head=k,b.head==null&&(b.pushmod=!0)):(N=g.next,k=N.next,g.next=k,k==null&&(b.pushmod=!0));let C=N;C.elt=null,C.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=C,b.modified=!0,b.length--,b.pushmod=!0,v=!0;break}g=P,P=P.next}}y.pair!=null&&(y.pair.arb=null,y.pair=null),y.active=!1,this.f_arbiters.modified=!0,ut.zpp_pool==null?f=new ut:(f=ut.zpp_pool,ut.zpp_pool=f.next,f.next=null),f.intchange=!0,f.stat=n,z=!0,w=!0}else f=y.colarb,m=u!=f.s1,f.stat!=n&&(f.stat=n,f.sleeping||((n?this.c_arbiters_false:this.c_arbiters_true).remove(f),_.add(f)));let Z=1;if(z||f.stamp!=this.stamp||i)if(f.stamp=this.stamp,Ee.contactCollide(u,x,f,m)){if(z){let d=x.id;f.b1=e.body,f.ws1=e,f.b2=t.body,f.ws2=t,f.id=u.id,f.di=d;let b=f.b1.arbiters,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=f;let P=g;P.next=b.head,b.head=P,b.modified=!0,b.length++;let v=f.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=f;let k=N;k.next=v.head,v.head=k,v.modified=!0,v.length++,f.active=!0,f.present=0,f.cleared=!1,f.sleeping=!1,f.fresh=!1,f.presentable=!1,f.s1=e,f.s2=t,f.userdef_restitution||(f.s1.material.elasticity<=-1/0||f.s2.material.elasticity<=-1/0?f.restitution=0:f.s1.material.elasticity>=1/0||f.s2.material.elasticity>=1/0?f.restitution=1:f.restitution=(f.s1.material.elasticity+f.s2.material.elasticity)/2,f.restitution<0&&(f.restitution=0),f.restitution>1&&(f.restitution=1)),f.userdef_dyn_fric||(f.dyn_fric=Math.sqrt(f.s1.material.dynamicFriction*f.s2.material.dynamicFriction)),f.userdef_stat_fric||(f.stat_fric=Math.sqrt(f.s1.material.staticFriction*f.s2.material.staticFriction)),f.userdef_rfric||(f.rfric=Math.sqrt(f.s1.material.rollingFriction*f.s2.material.rollingFriction));let C;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(C=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=C.next,C.next=null),C.elt=f;let E=C;E.next=_.head,_.head=E,_.modified=!0,_.length++,f.fresh=!w}else f.fresh=f.up_stamp<this.stamp-1||f.endGenerated==this.stamp&&i;if(f.up_stamp=f.stamp,f.fresh||(f.immState&4)==0){f.immState=1;let d=!1,b=f.ws1.id>f.ws2.id?f.ws2:f.ws1,g=f.ws1.id>f.ws2.id?f.ws1:f.ws2,P=this.mrca1;for(;P.head!=null;){let E=P.head;P.head=E.next;let M=E;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=!0),P.modified=!0,P.length--}P.pushmod=!0;let v=this.mrca2;for(;v.head!=null;){let E=v.head;v.head=E.next;let M=E;M.elt=null,M.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=M,v.head==null&&(v.pushmod=!0),v.modified=!0,v.length--}if(v.pushmod=!0,b.cbSet!=null){let E=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=b;let S=M;S.next=E.head,E.head=S,E.modified=!0,E.length++}if(b.body.cbSet!=null){let E=this.mrca1,M=b.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=M;let O=S;O.next=E.head,E.head=O,E.modified=!0,E.length++}if(g.cbSet!=null){let E=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=g;let S=M;S.next=E.head,E.head=S,E.modified=!0,E.length++}if(g.body.cbSet!=null){let E=this.mrca2,M=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=M;let O=S;O.next=E.head,E.head=O,E.modified=!0,E.length++}let N=b.body.compound,k=g.body.compound;for(;N!=k;){let E=N==null?0:N.depth,M=k==null?0:k.depth;if(E<M){if(k.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=k;let L=O;L.next=S.head,S.head=L,S.modified=!0,S.length++}k=k.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 L=O;L.next=S.head,S.head=L,S.modified=!0,S.length++}N=N.compound}}let C=this.mrca1.head;for(;C!=null;){let E=C.elt,M=this.mrca2.head;for(;M!=null;){let S=M.elt,O=E.cbSet,L=S.cbSet,T=O.manager,R=null,G=(O.cbpairs.length<L.cbpairs.length?O.cbpairs:L.cbpairs).head;for(;G!=null;){let D=G.elt;if(D.a==O&&D.b==L||D.a==L&&D.b==O){R=D;break}G=G.next}if(R==null){let D;Ne.zpp_pool==null?D=new Ne:(D=Ne.zpp_pool,Ne.zpp_pool=D.next,D.next=null),D.zip_listeners=!0,dt.setlt(O,L)?(D.a=O,D.b=L):(D.a=L,D.b=O),R=D,O.cbpairs.add(R),L!=O&&L.cbpairs.add(R)}if(R.zip_listeners&&(R.zip_listeners=!1,R.__validate()),R.listeners.head==null){M=M.next;continue}let B=null,V=null,Y=this.prelisteners;for(;Y.head!=null;){let D=Y.head;Y.head=D.next;let A=D;A.elt=null,A.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=A,Y.head==null&&(Y.pushmod=!0),Y.modified=!0,Y.length--}Y.pushmod=!0;let $=null,X=O.manager,H=null,W=(O.cbpairs.length<L.cbpairs.length?O.cbpairs:L.cbpairs).head;for(;W!=null;){let D=W.elt;if(D.a==O&&D.b==L||D.a==L&&D.b==O){H=D;break}W=W.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=!0,dt.setlt(O,L)?(D.a=O,D.b=L):(D.a=L,D.b=O),H=D,O.cbpairs.add(H),L!=O&&L.cbpairs.add(H)}H.zip_listeners&&(H.zip_listeners=!1,H.__validate());let F=H.listeners.head;for(;F!=null;){let D=F.elt;if(D.event==5&&(D.itype&Z)!=0){let A=this.prelisteners,J;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?J=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(J=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=J.next,J.next=null),J.elt=D;let Q=J;$==null?(Q.next=A.head,A.head=Q):(Q.next=$.next,$.next=Q),A.pushmod=A.modified=!0,A.length++,$=Q,d=d||!D.pure}F=F.next}if(this.prelisteners.head==null){M=M.next;continue}if(B=I._zpp.phys.ZPP_Interactor.get(E,S),B==null&&(V=Kt.get(E,S),this.add_callbackset(V)),B==null||(B.COLLISIONstamp!=this.stamp||i)&&(B.COLLISIONstate&4)==0){if(V!=null&&(B=V),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}f.mutable=!0,f.wrap_normal!=null&&(f.wrap_normal.zpp_inner._immutable=!1),f.wrap_contacts!=null&&(f.wrap_contacts.zpp_inner.immutable=!1);let D=f.active;f.active=!0;let A=!1,J=!0,Q=null,K=null,ie=f.innards.next;f.hc2=!1;let oe=f.contacts.next;for(;oe!=null;){let ne=oe;if(ne.stamp+I._nape.Config.arbiterExpirationDelay<f.stamp){let he=f.contacts,ae,ce;Q==null?(ae=he.next,ce=ae.next,he.next=ce,he.next==null&&(he.pushmod=!0)):(ae=Q.next,ce=ae.next,Q.next=ce,ce==null&&(he.pushmod=!0)),ae._inuse=!1,he.modified=!0,he.length--,he.pushmod=!0,oe=ce;let te=f.innards,ue,de;K==null?(ue=te.next,de=ue.next,te.next=de,te.next==null&&(te.pushmod=!0)):(ue=K.next,de=ue.next,K.next=de,de==null&&(te.pushmod=!0)),ue._inuse=!1,te.modified=!0,te.length--,te.pushmod=!0,ie=de;let me=ne;me.arbiter=null,me.next=Pe.zpp_pool,Pe.zpp_pool=me;continue}let re=ne.inner,le=ne.active;ne.active=ne.stamp==f.stamp,ne.active&&(J?(J=!1,f.c1=re,f.oc1=ne):(f.hc2=!0,f.c2=re,f.oc2=ne)),le!=ne.active&&(f.contacts.modified=!0),Q=oe,K=ie,ie=ie.next,oe=oe.next}if(f.hc2){if(f.hpc2=!0,f.oc1.posOnly){let ne=f.c1;f.c1=f.c2,f.c2=ne;let re=f.oc1;f.oc1=f.oc2,f.oc2=re,f.hc2=!1}else f.oc2.posOnly&&(f.hc2=!1);f.oc1.posOnly&&(J=!0)}else f.hpc2=!1;this.precb.zpp_inner.pre_arbiter=f,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,ae,ce=ne.options1,te=le.cbTypes;if(ce.nonemptyintersection(te,ce.includes)&&!ce.nonemptyintersection(te,ce.excludes)){let de=ne.options2,me=he.cbTypes;ae=de.nonemptyintersection(me,de.includes)&&!de.nonemptyintersection(me,de.excludes)}else ae=!1;ae?(re.int1=le,re.int2=he):(re.int1=he,re.int2=le),this.precb.zpp_inner.pre_swapped=E!=this.precb.zpp_inner.int1;let ue=ne.handlerp(this.precb);if(ue!=null){let de;U.PreFlag_ACCEPT==null&&(U.internal=!0,U.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,U.internal=!1),ue==U.PreFlag_ACCEPT?de=5:(U.PreFlag_ACCEPT_ONCE==null&&(U.internal=!0,U.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,U.internal=!1),ue==U.PreFlag_ACCEPT_ONCE?de=1:(U.PreFlag_IGNORE==null&&(U.internal=!0,U.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,U.internal=!1),de=ue==U.PreFlag_IGNORE?6:2)),f.immState=de}se=se.next}if(f.mutable=!1,f.wrap_normal!=null&&(f.wrap_normal.zpp_inner._immutable=!0),f.wrap_contacts!=null&&(f.wrap_contacts.zpp_inner.immutable=!0),f.active=D,B!=null){let ne=this.prelisteners.head;for(;ne!=null;)ne.elt.itype==7?(B.COLLISIONstate=f.immState,B.SENSORstate=f.immState,B.FLUIDstate=f.immState):B.COLLISIONstate=f.immState,ne=ne.next}}else B==null?(f.immState&4)==0&&(f.immState=1):f.immState=B.COLLISIONstate;M=M.next}C=C.next}if(d&&(f.immState&4)==0){if(f.b1.type==2){let E=f.b1;E.world||(E.component.waket=this.stamp+(this.midstep?0:1),E.type==3&&(E.kinematicDelaySleep=!0),E.component.sleeping&&this.really_wake(E,!1))}if(f.b1.type==2){let E=f.b2;E.world||(E.component.waket=this.stamp+(this.midstep?0:1),E.type==3&&(E.kinematicDelaySleep=!0),E.component.sleeping&&this.really_wake(E,!1))}}}if((f.immState&1)!=0){if(f.b1.type==2&&f.b1.component.sleeping){let d=f.b1;d.world||(d.component.waket=this.stamp+(this.midstep?0:1),d.type==3&&(d.kinematicDelaySleep=!0),d.component.sleeping&&this.really_wake(d,!1))}if(f.b2.type==2&&f.b2.component.sleeping){let d=f.b2;d.world||(d.component.waket=this.stamp+(this.midstep?0:1),d.type==3&&(d.kinematicDelaySleep=!0),d.component.sleeping&&this.really_wake(d,!1))}}if(f.sleeping){f.sleeping=!1;let d;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=f;let b=d;b.next=_.head,_.head=b,_.modified=!0,_.length++}l=f}else if(z){let d=f;d.userdef_dyn_fric=!1,d.userdef_stat_fric=!1,d.userdef_restitution=!1,d.userdef_rfric=!1,d.__ref_edge1=d.__ref_edge2=null,d.next=ut.zpp_pool,ut.zpp_pool=d,l=null}else l=f;else l=f}else{let _;if(s==null){let Z=null,b=(o.arbiters.length<r.arbiters.length?o:r).arbiters.head;for(;b!=null;){let g=b.elt;if(g.id==u.id&&g.di==x.id){Z=g;break}b=b.next}_=Z}else _=s;let y=_==null,z,f=!1;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=!0;{let d=_.b1.arbiters,b=null,g=d.head,P=!1;for(;g!=null;){if(g.elt==_){let v,N;b==null?(v=d.head,N=v.next,d.head=N,d.head==null&&(d.pushmod=!0)):(v=b.next,N=v.next,b.next=N,N==null&&(d.pushmod=!0));let k=v;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,d.modified=!0,d.length--,d.pushmod=!0,P=!0;break}b=g,g=g.next}}{let d=_.b2.arbiters,b=null,g=d.head,P=!1;for(;g!=null;){if(g.elt==_){let v,N;b==null?(v=d.head,N=v.next,d.head=N,d.head==null&&(d.pushmod=!0)):(v=b.next,N=v.next,b.next=N,N==null&&(d.pushmod=!0));let k=v;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,d.modified=!0,d.length--,d.pushmod=!0,P=!0;break}b=g,g=g.next}}_.pair!=null&&(_.pair.arb=null,_.pair=null),_.active=!1,this.f_arbiters.modified=!0,Ot.zpp_pool==null?z=new Ot:(z=Ot.zpp_pool,Ot.zpp_pool=z.next,z.next=null),z.intchange=!0,y=!0,f=!0}else z=_.sensorarb;let w=2;if(y||z.stamp!=this.stamp||i)if(z.stamp=this.stamp,Ee.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,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=z;let g=b;g.next=d.head,d.head=g,d.modified=!0,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=!0,P.length++,z.active=!0,z.present=0,z.cleared=!1,z.sleeping=!1,z.fresh=!1,z.presentable=!1;let k=this.s_arbiters,C;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(C=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=C.next,C.next=null),C.elt=z;let E=C;E.next=k.head,k.head=E,k.modified=!0,k.length++,z.fresh=!f}else z.fresh=z.up_stamp<this.stamp-1||z.endGenerated==this.stamp&&i;if(z.up_stamp=z.stamp,z.fresh||(z.immState&4)==0){z.immState=1;let Z=!1,d=z.ws1.id>z.ws2.id?z.ws2:z.ws1,b=z.ws1.id>z.ws2.id?z.ws1:z.ws2,g=this.mrca1;for(;g.head!=null;){let C=g.head;g.head=C.next;let E=C;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E,g.head==null&&(g.pushmod=!0),g.modified=!0,g.length--}g.pushmod=!0;let P=this.mrca2;for(;P.head!=null;){let C=P.head;P.head=C.next;let E=C;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E,P.head==null&&(P.pushmod=!0),P.modified=!0,P.length--}if(P.pushmod=!0,d.cbSet!=null){let C=this.mrca1,E;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?E=new I._zpp.util.ZNPNode_ZPP_Interactor:(E=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E.next,E.next=null),E.elt=d;let M=E;M.next=C.head,C.head=M,C.modified=!0,C.length++}if(d.body.cbSet!=null){let C=this.mrca1,E=d.body,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=E;let S=M;S.next=C.head,C.head=S,C.modified=!0,C.length++}if(b.cbSet!=null){let C=this.mrca2,E;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?E=new I._zpp.util.ZNPNode_ZPP_Interactor:(E=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E.next,E.next=null),E.elt=b;let M=E;M.next=C.head,C.head=M,C.modified=!0,C.length++}if(b.body.cbSet!=null){let C=this.mrca2,E=b.body,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=E;let S=M;S.next=C.head,C.head=S,C.modified=!0,C.length++}let v=d.body.compound,N=b.body.compound;for(;v!=N;){let C=v==null?0:v.depth,E=N==null?0:N.depth;if(C<E){if(N.cbSet!=null){let M=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=M.head,M.head=O,M.modified=!0,M.length++}N=N.compound}else{if(v.cbSet!=null){let M=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=M.head,M.head=O,M.modified=!0,M.length++}v=v.compound}}let k=this.mrca1.head;for(;k!=null;){let C=k.elt,E=this.mrca2.head;for(;E!=null;){let M=E.elt,S=C.cbSet,O=M.cbSet,L=S.manager,T=null,q=(S.cbpairs.length<O.cbpairs.length?S.cbpairs:O.cbpairs).head;for(;q!=null;){let F=q.elt;if(F.a==S&&F.b==O||F.a==O&&F.b==S){T=F;break}q=q.next}if(T==null){let F;Ne.zpp_pool==null?F=new Ne:(F=Ne.zpp_pool,Ne.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,dt.setlt(S,O)?(F.a=S,F.b=O):(F.a=O,F.b=S),T=F,S.cbpairs.add(T),O!=S&&O.cbpairs.add(T)}if(T.zip_listeners&&(T.zip_listeners=!1,T.__validate()),T.listeners.head==null){E=E.next;continue}let G=null,B=null,V=this.prelisteners;for(;V.head!=null;){let F=V.head;V.head=F.next;let D=F;D.elt=null,D.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=D,V.head==null&&(V.pushmod=!0),V.modified=!0,V.length--}V.pushmod=!0;let Y=null,$=S.manager,X=null,ee=(S.cbpairs.length<O.cbpairs.length?S.cbpairs:O.cbpairs).head;for(;ee!=null;){let F=ee.elt;if(F.a==S&&F.b==O||F.a==O&&F.b==S){X=F;break}ee=ee.next}if(X==null){let F;Ne.zpp_pool==null?F=new Ne:(F=Ne.zpp_pool,Ne.zpp_pool=F.next,F.next=null),F.zip_listeners=!0,dt.setlt(S,O)?(F.a=S,F.b=O):(F.a=O,F.b=S),X=F,S.cbpairs.add(X),O!=S&&O.cbpairs.add(X)}X.zip_listeners&&(X.zip_listeners=!1,X.__validate());let W=X.listeners.head;for(;W!=null;){let F=W.elt;if(F.event==5&&(F.itype&w)!=0){let D=this.prelisteners,A;I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?A=new I._zpp.util.ZNPNode_ZPP_InteractionListener:(A=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=A.next,A.next=null),A.elt=F;let J=A;Y==null?(J.next=D.head,D.head=J):(J.next=Y.next,Y.next=J),D.pushmod=D.modified=!0,D.length++,Y=J,Z=Z||!F.pure}W=W.next}if(this.prelisteners.head==null){E=E.next;continue}if(G=I._zpp.phys.ZPP_Interactor.get(C,M),G==null&&(B=Kt.get(C,M),this.add_callbackset(B)),G==null||(G.SENSORstamp!=this.stamp||i)&&(G.SENSORstate&4)==0){if(B!=null&&(G=B),G!=null){let J=this.prelisteners.head;for(;J!=null;)J.elt.itype==7?(G.COLLISIONstamp=this.stamp,G.SENSORstamp=this.stamp,G.FLUIDstamp=this.stamp):G.SENSORstamp=this.stamp,J=J.next}let F=z.active;z.active=!0;let D=!1;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=G;let A=this.prelisteners.head;for(;A!=null;){let J=A.elt;this.precb.zpp_inner.listener=J;let Q=this.precb.zpp_inner,K=G.int1,ie=G.int2,oe,se=J.options1,ne=K.cbTypes;if(se.nonemptyintersection(ne,se.includes)&&!se.nonemptyintersection(ne,se.excludes)){let le=J.options2,he=ie.cbTypes;oe=le.nonemptyintersection(he,le.includes)&&!le.nonemptyintersection(he,le.excludes)}else oe=!1;oe?(Q.int1=K,Q.int2=ie):(Q.int1=ie,Q.int2=K),this.precb.zpp_inner.pre_swapped=C!=this.precb.zpp_inner.int1;let re=J.handlerp(this.precb);if(re!=null){let le;U.PreFlag_ACCEPT==null&&(U.internal=!0,U.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,U.internal=!1),re==U.PreFlag_ACCEPT?le=5:(U.PreFlag_ACCEPT_ONCE==null&&(U.internal=!0,U.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,U.internal=!1),re==U.PreFlag_ACCEPT_ONCE?le=1:(U.PreFlag_IGNORE==null&&(U.internal=!0,U.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,U.internal=!1),le=re==U.PreFlag_IGNORE?6:2)),z.immState=le}A=A.next}if(z.active=F,G!=null){let J=this.prelisteners.head;for(;J!=null;)J.elt.itype==7?(G.COLLISIONstate=z.immState,G.SENSORstate=z.immState,G.FLUIDstate=z.immState):G.SENSORstate=z.immState,J=J.next}}else G==null?(z.immState&4)==0&&(z.immState=1):z.immState=G.SENSORstate;E=E.next}k=k.next}if(Z&&(z.immState&4)==0){if(z.b1.type!=1){let C=z.b1;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}if(z.b2.type!=1){let C=z.b2;C.world||(C.component.waket=this.stamp+(this.midstep?0:1),C.type==3&&(C.kinematicDelaySleep=!0),C.component.sleeping&&this.really_wake(C,!1))}}}if(z.sleeping){z.sleeping=!1;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 b=d;b.next=Z.head,Z.head=b,Z.modified=!0,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 o=n.head;n.head=o.next;let r=o;r.elt=null,r.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let o=s.head;s.head=o.next;let r=o;r.elt=null,r.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_Interactor:(r=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=e;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(e.body.cbSet!=null){let o=this.mrca1,r=e.body,a;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}if(t.cbSet!=null){let o=this.mrca2,r;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_Interactor:(r=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=t;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(t.body.cbSet!=null){let o=this.mrca2,r=t.body,a;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let o=i==null?0:i.depth,r=l==null?0:l.depth;if(o<r){if(l.cbSet!=null){let a=this.mrca2,p;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=!0,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=!0,a.length++}i=i.compound}}}inlined_MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let o=n.head;n.head=o.next;let r=o;r.elt=null,r.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,n.head==null&&(n.pushmod=!0),n.modified=!0,n.length--}n.pushmod=!0;let s=this.mrca2;for(;s.head!=null;){let o=s.head;s.head=o.next;let r=o;r.elt=null,r.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let o=this.mrca1,r;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_Interactor:(r=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=e;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(e.body.cbSet!=null){let o=this.mrca1,r=e.body,a;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}if(t.cbSet!=null){let o=this.mrca2,r;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?r=new I._zpp.util.ZNPNode_ZPP_Interactor:(r=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=r.next,r.next=null),r.elt=t;let a=r;a.next=o.head,o.head=a,o.modified=!0,o.length++}if(t.body.cbSet!=null){let o=this.mrca2,r=t.body,a;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=r;let p=a;p.next=o.head,o.head=p,o.modified=!0,o.length++}let i=e.body.compound,l=t.body.compound;for(;i!=l;){let o=i==null?0:i.depth,r=l==null?0:l.depth;if(o<r){if(l.cbSet!=null){let a=this.mrca2,p;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=!0,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=!0,a.length++}i=i.compound}}}};I._zpp=null,I._nape=null;var pi=I;var Bn=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}};Bn.zpp_pool=null;var nn=class nn extends $n{constructor(t){super();this.failed=null;this.list=null;this.space=t,this.is_sweep=!0,this.sweep=this}__insert(t){let n;Bn.zpp_pool==null?n=new Bn:(n=Bn.zpp_pool,Bn.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=Bn.zpp_pool,Bn.zpp_pool=s}__sync(t){if(!this.space.continuous&&t.zip_aabb&&t.body!=null)if(t.zip_aabb=!1,t.type==0){let n=t.circle;if(n.zip_worldCOM&&n.body!=null){if(n.zip_worldCOM=!1,n.zip_localCOM){if(n.zip_localCOM=!1,n.type==1){let o=n.polygon;if(o.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(o.lverts.next.next==null)o.localCOMx=o.lverts.next.x,o.localCOMy=o.lverts.next.y;else if(o.lverts.next.next.next==null){o.localCOMx=o.lverts.next.x,o.localCOMy=o.lverts.next.y;let r=1;o.localCOMx+=o.lverts.next.next.x*r,o.localCOMy+=o.lverts.next.next.y*r;let a=.5;o.localCOMx*=a,o.localCOMy*=a}else{o.localCOMx=0,o.localCOMy=0;let r=0,a=o.lverts.next,p=a;a=a.next;let c=a;for(a=a.next;a!=null;){let y=a;r+=c.x*(y.y-p.y);let z=y.y*c.x-y.x*c.y;o.localCOMx+=(c.x+y.x)*z,o.localCOMy+=(c.y+y.y)*z,p=c,c=y,a=a.next}a=o.lverts.next;let h=a;r+=c.x*(h.y-p.y);let u=h.y*c.x-h.x*c.y;o.localCOMx+=(c.x+h.x)*u,o.localCOMy+=(c.y+h.y)*u,p=c,c=h,a=a.next;let x=a;r+=c.x*(x.y-p.y);let m=x.y*c.x-x.x*c.y;o.localCOMx+=(c.x+x.x)*m,o.localCOMy+=(c.y+x.y)*m,r=1/(3*r);let _=r;o.localCOMx*=_,o.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=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot)),n.worldCOMx=n.body.posx+(n.body.axisy*n.localCOMx-n.body.axisx*n.localCOMy),n.worldCOMy=n.body.posy+(n.localCOMx*n.body.axisx+n.localCOMy*n.body.axisy)}let s=n.radius,i=n.radius;n.aabb.minx=n.worldCOMx-s,n.aabb.miny=n.worldCOMy-i,n.aabb.maxx=n.worldCOMx+s,n.aabb.maxy=n.worldCOMy+i}else{let n=t.polygon;if(n.zip_gverts&&n.body!=null){n.zip_gverts=!1,n.validate_lverts();let l=n.body;l.zip_axis&&(l.zip_axis=!1,l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot));let o=n.lverts.next,r=n.gverts.next;for(;r!=null;){let a=r,p=o;o=o.next,a.x=n.body.posx+(n.body.axisy*p.x-n.body.axisx*p.y),a.y=n.body.posy+(p.x*n.body.axisx+p.y*n.body.axisy),r=r.next}}if(n.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let s=n.gverts.next;n.aabb.minx=s.x,n.aabb.miny=s.y,n.aabb.maxx=s.x,n.aabb.maxy=s.y;let i=n.gverts.next.next;for(;i!=null;){let l=i;l.x<n.aabb.minx&&(n.aabb.minx=l.x),l.x>n.aabb.maxx&&(n.aabb.maxx=l.x),l.y<n.aabb.miny&&(n.aabb.miny=l.y),l.y>n.aabb.maxy&&(n.aabb.maxy=l.y),i=i.next}}}sync_broadphase(){if(this.space.validation(),this.list!=null){let t=this.list.next;for(;t!=null;){let n=t.next,s=t.prev;if(s!=null&&t.aabb.minx>s.aabb.minx){t=n;continue}for(;s.prev!=null&&s.prev.aabb.minx>t.aabb.minx;)s=s.prev;let i=t.prev;i.next=t.next,t.next!=null&&(t.next.prev=i),s.prev==null?(t.prev=null,this.list=t,t.next=s,s.prev=t):(t.prev=s.prev,s.prev=t,t.prev.next=t,t.next=s),t=n}}}sync_broadphase_fast(){let t=this.list.next;for(;t!=null;){let n=t.next,s=t.prev;if(s!=null&&t.aabb.minx>s.aabb.minx){t=n;continue}for(;s.prev!=null&&s.prev.aabb.minx>t.aabb.minx;)s=s.prev;let i=t.prev;i.next=t.next,t.next!=null&&(t.next.prev=i),s.prev==null?(t.prev=null,this.list=t,t.next=s,s.prev=t):(t.prev=s.prev,s.prev=t,t.prev.next=t,t.next=s),t=n}}broadphase(t,n){if(this.list!=null){let s=this.list.next;for(;s!=null;){let l=s.next,o=s.prev;if(o!=null&&s.aabb.minx>o.aabb.minx){s=l;continue}for(;o.prev!=null&&o.prev.aabb.minx>s.aabb.minx;)o=o.prev;let r=s.prev;r.next=s.next,s.next!=null&&(s.next.prev=r),o.prev==null?(s.prev=null,this.list=s,s.next=o,o.prev=s):(s.prev=o.prev,o.prev=s,s.prev.next=s,s.next=o),s=l}let i=this.list;for(;i!=null;){let l=i.next,o=i.shape,r=o.body,a=i.aabb.maxx;for(;l!=null&&!(l.aabb.minx>a);){let p=l.shape,c=p.body;if(c==r){l=l.next;continue}if(r.type==1&&c.type==1){l=l.next;continue}if(r.component.sleeping&&c.component.sleeping){l=l.next;continue}let h=o.aabb,u=p.aabb;u.miny>h.maxy||h.miny>u.maxy||(n?t.narrowPhase(o,p,r.type!=2||c.type!=2,null,!1):t.continuousEvent(o,p,r.type!=2||c.type!=2,null,!1)),l=l.next}i=i.next}}}clear(){for(;this.list!=null;)this.list.shape.removedFromSpace(),this.__remove(this.list.shape)}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l=pe.get(t,n),o=i??new nn._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.minx>t;)r=r.next;for(;r!=null&&r.aabb.minx<=t;){if(r.aabb.maxx>=t&&r.aabb.miny<=n&&r.aabb.maxy>=n){let p=r.shape,c;if(s!=null){let h=p.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;c&&(p.type==0?Ee.circleContains(p.circle,l)&&o.push(p.outer):Ee.polyContains(p.polygon,l)&&o.push(p.outer))}r=r.next}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=pe.zpp_pool,pe.zpp_pool=a,o}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l=pe.get(t,n),o=i??new nn._nape.phys.BodyList,r=this.list;for(;r!=null&&r.aabb.minx>t;)r=r.next;for(;r!=null&&r.aabb.minx<=t;){if(r.aabb.maxx>=t&&r.aabb.miny<=n&&r.aabb.maxy>=n){let p=r.shape,c=p.body.outer;if(!o.has(c)){let h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(p.type==0?Ee.circleContains(p.circle,l)&&o.push(c):Ee.polyContains(p.polygon,l)&&o.push(c))}}r=r.next}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=pe.zpp_pool,pe.zpp_pool=a,o}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new nn._nape.shape.ShapeList,a=this.list;for(;a!=null&&a.aabb.maxx<o.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=o.maxx;){let p=a.shape,c;if(i!=null){let h=p.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c)if(n)if(s)Ee.containTest(this.aabbShape.zpp_inner,p)&&r.push(p.outer);else{let h=a.aabb;if(h.minx>=o.minx&&h.miny>=o.miny&&h.maxx<=o.maxx&&h.maxy<=o.maxy)r.push(p.outer);else{let u=a.aabb;o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx&&Ee.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(p.outer)}}else{let h;if(s){let u=a.aabb;h=u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy}else{let u=a.aabb;h=o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx}h&&r.push(p.outer)}a=a.next}return r}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,r=l??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._nape.phys.BodyList);let a=this.list;for(;a!=null&&a.aabb.maxx<o.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=o.maxx;){let p=a.shape,c=p.body.outer,h=a.aabb;if(o.miny<=h.maxy&&h.miny<=o.maxy&&o.minx<=h.maxx&&h.minx<=o.maxx){let u;if(i!=null){let x=p.filter;u=(x.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&x.collisionGroup)!=0}else u=!0;if(u)if(n)if(s){if(!this.failed.has(c)){let x=Ee.containTest(this.aabbShape.zpp_inner,p);!r.has(c)&&x?r.push(c):x||(r.remove(c),this.failed.push(c))}}else!r.has(c)&&Ee.testCollide_safe(p,this.aabbShape.zpp_inner)&&r.push(c);else if(s){if(!this.failed.has(c)){let x=p.aabb,m=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!r.has(c)&&m?r.push(c):m||(r.remove(c),this.failed.push(c))}}else{let x;if(r.has(c))x=!1;else{let m=p.aabb;x=m.minx>=o.minx&&m.miny>=o.miny&&m.maxx<=o.maxx&&m.maxy<=o.maxy}x&&r.push(c)}}a=a.next}return this.failed.clear(),r}shapesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new nn._nape.shape.ShapeList,p=this.list;for(;p!=null&&p.aabb.maxx<r.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=r.maxx;){let c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx){let h=p.shape,u;if(l!=null){let x=h.filter;u=(x.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(i?Ee.containTest(this.circShape.zpp_inner,h)&&a.push(h.outer):Ee.testCollide_safe(h,this.circShape.zpp_inner)&&a.push(h.outer))}p=p.next}return a}bodiesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let r=this.circShape.zpp_inner.aabb,a=o??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._nape.phys.BodyList);let p=this.list;for(;p!=null&&p.aabb.maxx<r.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=r.maxx;){let c=p.aabb;if(r.miny<=c.maxy&&c.miny<=r.maxy&&r.minx<=c.maxx&&c.minx<=r.maxx){let h=p.shape,u=h.body.outer,x;if(l!=null){let m=h.filter;x=(m.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&m.collisionGroup)!=0}else x=!0;if(x)if(i){if(!this.failed.has(u)){let m=Ee.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)&&Ee.testCollide_safe(h,this.circShape.zpp_inner)&&a.push(u)}p=p.next}return this.failed.clear(),a}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new nn._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.maxx<l.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=l.maxx;){let a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=r.shape,c;if(s!=null){let h=p.filter;c=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else c=!0;c&&(n?Ee.containTest(t,p)&&o.push(p.outer):Ee.testCollide_safe(p,t)&&o.push(p.outer))}r=r.next}return o}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new nn._nape.phys.BodyList;this.failed==null&&(this.failed=new nn._nape.phys.BodyList);let r=this.list;for(;r!=null&&r.aabb.maxx<l.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=l.maxx;){let a=r.aabb;if(l.miny<=a.maxy&&a.miny<=l.maxy&&l.minx<=a.maxx&&a.minx<=l.maxx){let p=r.shape,c=p.body.outer,h;if(s!=null){let u=p.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;if(h)if(n){if(!this.failed.has(c)){let u=Ee.containTest(t,p);!o.has(c)&&u?o.push(c):u||(o.remove(c),this.failed.push(c))}}else!o.has(c)&&Ee.testCollide_safe(t,p)&&o.push(c)}r=r.next}return this.failed.clear(),o}rayCast(t,n,s){this.sync_broadphase(),t.validate_dir();let i=t.rayAABB(),l=t.maxdist,o=null;if(t.dirx==0){let a=this.list;for(;a!=null&&a.aabb.minx<=i.minx;){let p,c=a.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;if(p){let h=t.aabbsect(a.aabb);if(h>=0&&h<l){let u=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.shape.polygon,n,l);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=u.zpp_inner.toiDistance,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=u}}}a=a.next}}else if(t.dirx<0){let a=this.list,p=null;for(;a!=null&&a.aabb.minx<=i.maxx;)p=a,a=a.next;for(a=p;a!=null;){let c,h=a.aabb;if(i.miny<=h.maxy&&h.miny<=i.maxy&&i.minx<=h.maxx&&h.minx<=i.maxx)if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;else c=!1;if(c){let u=t.aabbsect(a.aabb);if(u>=0&&u<l){let x=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.shape.polygon,n,l);if(x!=null){if(x.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=x.zpp_inner.toiDistance,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=x}}}a=a.prev}}else{let a=this.list;for(;a!=null&&a.aabb.minx<=i.maxx&&a.aabb.minx<t.originx+t.dirx*l;){let p,c=a.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;if(p){let h=t.aabbsect(a.aabb);if(h>=0&&h<l){let u=a.shape.type==0?t.circlesect(a.shape.circle,n,l):t.polysect(a.shape.polygon,n,l);if(u!=null){if(u.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");if(l=u.zpp_inner.toiDistance,o!=null){if(o.zpp_inner.next!=null)throw new Error("Error: This object has been disposed of and cannot be used");o.zpp_inner.free()}o=u}}}a=a.next}}let r=i;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r.wrap_min=r.wrap_max=null,r._invalidate=null,r._validate=null,r.next=fe.zpp_pool,fe.zpp_pool=r,o}rayMultiCast(t,n,s,i){this.sync_broadphase(),t.validate_dir();let l=t.rayAABB(),o=i??new nn._nape.geom.RayResultList;if(t.dirx==0){let a=this.list;for(;a!=null&&a.aabb.minx<=l.minx;){let p,c=a.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,o):t.polysect2(a.shape.polygon,n,o)),a=a.next}}else if(t.dirx<0){let a=this.list,p=null;for(;a!=null&&a.aabb.minx<=l.maxx;)p=a,a=a.next;for(a=p;a!=null;){let c,h=a.aabb;if(l.miny<=h.maxy&&h.miny<=l.maxy&&l.minx<=h.maxx&&h.minx<=l.maxx)if(s!=null){let u=a.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;else c=!1;c&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,o):t.polysect2(a.shape.polygon,n,o)),a=a.prev}}else{let a=this.list;for(;a!=null&&a.aabb.minx<=l.maxx;){let p,c=a.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=a.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(a.aabb)>=0&&(a.shape.type==0?t.circlesect2(a.shape.circle,n,o):t.polysect2(a.shape.polygon,n,o)),a=a.next}}let r=l;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r.wrap_min=r.wrap_max=null,r._invalidate=null,r._validate=null,r.next=fe.zpp_pool,fe.zpp_pool=r,o}};nn._zpp=null,nn._nape=null;var cs=nn;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=Dn,e.ZPP_ID=dn,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),pn._zpp=e,e.callbacks.ZPP_CbType=pn,e.util.ZPP_Flags=U,Lt._nape=j,Lt._zpp=e,e.callbacks.ZPP_Listener=Lt,e.callbacks.ZPP_BodyListener=Us,e.callbacks.ZPP_ConstraintListener=Ks,e.callbacks.ZPP_InteractionListener=Ys,ts._nape=j,ts._zpp=e,e.callbacks.ZPP_OptionType=ts,e.constraint||(e.constraint={}),Me._nape=j,Me._zpp=e,e.constraint.ZPP_Constraint=Me,e.constraint.ZPP_AngleJoint=Re,e.constraint.ZPP_CopyHelper=Rn,e.constraint.ZPP_DistanceJoint=_i,e.constraint.ZPP_LineJoint=di,e.constraint.ZPP_MotorJoint=yi,e.constraint.ZPP_PivotJoint=mi,e.constraint.ZPP_PulleyJoint=fi,e.constraint.ZPP_UserConstraint=Xs,e.constraint.ZPP_UserBody=ns,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=zi,Pe._nape=j,Pe._zpp=e,e.dynamics.ZPP_Contact=Pe,it._nape=j,it._zpp=e,e.dynamics.ZPP_InteractionFilter=it,Zs._zpp=e,e.dynamics.ZPP_InteractionGroup=Zs,Yn._nape=j,Yn._zpp=e,e.dynamics.ZPP_SpaceArbiterList=Yn,e.geom||(e.geom={}),fe._nape=j,fe._zpp=e,e.geom.ZPP_AABB=fe,e.geom.ZPP_Collide=Ee,e.geom.ZPP_Convex=is,e.geom.ZPP_ConvexRayResult=mn,e.geom.ZPP_CutVert=He,e.geom.ZPP_CutInt=ot,e.geom.ZPP_Cutter=ss,e.geom.ZPP_Geom=ls,e.geom.ZPP_GeomVert=ve,ve._createVec2Fn=function(){return new j.geom.Vec2},e.geom.ZPP_GeomPoly=os,e.geom.ZPP_MarchSpan=An,e.geom.ZPP_MarchPair=In,ks._init(e,j),e.geom.ZPP_MarchingSquares=ks,Es._nape=j,e.geom.ZPP_Mat23=Es,e.geom.ZPP_MatMN=Bi,e.geom.ZPP_Monotone=Dt,e.geom.ZPP_PartitionVertex=Ge,e.geom.ZPP_PartitionedPoly=Je,e.geom.ZPP_Ray=Hs,e.geom.ZPP_SimpleVert=ke,e.geom.ZPP_SimpleSeg=At,e.geom.ZPP_SimpleEvent=Ce,e.geom.ZPP_SimpleSweep=Fi,e.geom.ZPP_Simple=wi,e.geom.ZPP_SimplifyV=vn,e.geom.ZPP_SimplifyP=Te,e.geom.ZPP_Simplify=rs,e.geom.ZPP_ToiEvent=Ns,e.geom.ZPP_SweepDistance=gn,e.geom.ZPP_PartitionPair=St,e.geom.ZPP_Triangular=li,e.geom.ZPP_Vec2=pe,oi._zpp=e,e.geom.ZPP_Vec3=oi,e.geom.ZPP_VecMath=Qs,e.phys||(e.phys={}),e.phys.ZPP_Interactor=Ut,Ut._init(e,j),Cn._init(e,j),e.phys.ZPP_Body=Cn,qn._nape=j,qn._zpp=e,qn._init(),e.phys.ZPP_Compound=qn,Mn._nape=j,Mn._zpp=e,e.phys.ZPP_FluidProperties=Mn,Oe._nape=j,Oe._zpp=e,e.phys.ZPP_Material=Oe,e.shape||(e.shape={}),ri._nape=j,ri._zpp=e,ri._init(),e.shape.ZPP_Shape=ri,Xn._nape=j,Xn._zpp=e,Xn._init(),e.shape.ZPP_Circle=Xn,rt._nape=j,rt._zpp=e,e.shape.ZPP_Edge=rt,Hn._nape=j,Hn._zpp=e,Hn._init(),e.shape.ZPP_Polygon=Hn,Qn._nape=j,Qn._zpp=e,Qn._init(),e.shape.ZPP_Capsule=Qn,e.space||(e.space={}),$n._zpp=e,$n._nape=j,e.space.ZPP_Broadphase=$n,e.space.ZPP_AABBNode=Ve,e.space.ZPP_AABBPair=st,e.space.ZPP_AABBTree=Qe,ps._zpp=e,ps._nape=j,e.space.ZPP_DynAABBPhase=ps,xt._zpp=e,e.space.ZPP_Island=xt,e.space.ZPP_Component=Ss,Kt._zpp=e,e.space.ZPP_CallbackSet=Kt,qi._zpp=e,e.space.ZPP_CbSetManager=qi,pi._zpp=e,pi._nape=j,e.space.ZPP_Space=pi,e.space.ZPP_SweepData=Bn,cs._zpp=e,cs._nape=j,e.space.ZPP_SweepPhase=cs,e.util.ZNPArray2_Float=Ki,e.util.ZNPArray2_ZPP_GeomVert=Yi,e.util.ZNPArray2_ZPP_MarchPair=Xi,e.util.Hashable2_Boolfalse=Be,e.util.FastHash2_Hashable2_Boolfalse=Oi,e.util.ZPP_Math=Js,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 $s;function _e(){return $s||($s=Bl()),$s}var Tl=!1;function el(){if(Tl)return;let j=$s;if(!j?.callbacks?.CbEvent||!j?.callbacks?.CbType||!j?.callbacks?.ListenerType||!j?.dynamics?.ArbiterType||!j?.phys?.BodyType||!j?.shape?.ShapeType)return;Tl=!0;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 Ze(j,e){if(!j)return null;let t=Ll.get(j);return t||(t=e(j),Ll.set(j,t)),t}var lt=class j{constructor(e=0,t=0){this.zpp_pool=null;this.zpp_disp=!1;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;pe.zpp_pool==null?n=new pe:(n=pe.zpp_pool,pe.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,this.zpp_inner=n,n.outer=this}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}_checkImmutable(){this.zpp_inner.immutable()}_validate(){this.zpp_inner.validate()}_invalidate(){this.zpp_inner.invalidate()}static _disposeWeak(e){e.zpp_inner.weak&&e.dispose()}_setXY(e,t){if(this._checkDisposed(),this._checkImmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");this._validate(),(this.zpp_inner.x!==e||this.zpp_inner.y!==t)&&(this.zpp_inner.x=e,this.zpp_inner.y=t,this._invalidate())}static _poolGet(e,t,n){let s;if(xe.poolVec2==null?s=new j:(s=xe.poolVec2,xe.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===xe.nextVec2&&(xe.nextVec2=null)),s.zpp_inner==null){let i;pe.zpp_pool==null?i=new pe:(i=pe.zpp_pool,pe.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=e,i.y=t,s.zpp_inner=i,i.outer=s}else s.zpp_inner.immutable(),s.zpp_inner.validate(),(s.zpp_inner.x!==e||s.zpp_inner.y!==t)&&(s.zpp_inner.x=e,s.zpp_inner.y=t,s.zpp_inner.invalidate());return s.zpp_inner.weak=n,s}static _wrap(e){return e instanceof j?e:e?e instanceof pe?Ze(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?j._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=!1){if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");return 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,!0)}static fromPolar(e,t,n=!1){if(e!==e)throw new Error("Error: Vec2::length cannot be NaN");if(t!==t)throw new Error("Error: Vec2::angle cannot be NaN");let s=e*Math.cos(t),i=e*Math.sin(t);return j._poolGet(s,i,n)}static fromAngle(e,t=!1){return j.fromPolar(1,e,t)}static lerp(e,t,n,s=!1){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null)throw new Error("Error: Cannot lerp with null Vec2");if(n!==n)throw new Error("Error: Cannot lerp with NaN t");e.zpp_inner.validate(),t.zpp_inner.validate();let i=e.zpp_inner.x+n*(t.zpp_inner.x-e.zpp_inner.x),l=e.zpp_inner.y+n*(t.zpp_inner.y-e.zpp_inner.y),o=j._poolGet(i,l,s);return j._disposeWeak(e),j._disposeWeak(t),o}static eq(e,t,n=0){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null||t==null){let o=e==null&&t==null;return e!=null&&j._disposeWeak(e),t!=null&&j._disposeWeak(t),o}e.zpp_inner.validate(),t.zpp_inner.validate();let s=e.zpp_inner.x-t.zpp_inner.x,i=e.zpp_inner.y-t.zpp_inner.y,l=(s<0?-s:s)<=n&&(i<0?-i:i)<=n;return 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,o=n-i,r=s-l,a=o*o+r*r;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,o=n-i,r=s-l,a=Math.sqrt(o*o+r*r);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!1;this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,s=this.zpp_inner.y-e.zpp_inner.y;return(n<0?-n:n)<=t&&(s<0?-s:s)<=t}copy(e=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y;return 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=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this._validate();let n=this.zpp_inner.x,s=this.zpp_inner.y;if(Math.sqrt(n*n+s*s)===0)throw new Error("Error: Cannot reflect in zero vector");let i=j._poolGet(n,s,!0);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=!1){this._checkDisposed(),this._validate();let t=this.zpp_inner.x,n=this.zpp_inner.y,s=t*t+n*n;if(Math.sqrt(s)===0)throw new Error("Error: Cannot normalise vector of length 0");let i=1/Math.sqrt(s);return j._poolGet(t*i,n*i,e)}add(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x+e.zpp_inner.x,s=this.zpp_inner.y+e.zpp_inner.y,i=j._poolGet(n,s,t);return j._disposeWeak(e),i}addMul(e,t,n=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot add null vectors");this._validate(),e.zpp_inner.validate();let s=this.zpp_inner.x+e.zpp_inner.x*t,i=this.zpp_inner.y+e.zpp_inner.y*t,l=j._poolGet(s,i,n);return j._disposeWeak(e),l}sub(e,t=!1){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot subtract null vectors");this._validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,s=this.zpp_inner.y-e.zpp_inner.y,i=j._poolGet(n,s,t);return j._disposeWeak(e),i}mul(e,t=!1){if(this._checkDisposed(),e!==e)throw new Error("Error: Cannot multiply with NaN");this._validate();let n=this.zpp_inner.x*e,s=this.zpp_inner.y*e;return 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=!1){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=!0,e.free(),e.next=pe.zpp_pool,pe.zpp_pool=e}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};pe._wrapFn=j=>Ze(j,e=>{let t=Object.create(lt.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var co=_e();co.geom.Vec2=lt;var ci=class j{constructor(e=0,t=0,n=0){this.zpp_pool=null;this.zpp_disp=!1;let s=new oi;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 oi?Ze(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,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=!1,s===xe.nextVec3&&(xe.nextVec3=null)),s.setxyz(e,t,n),s.zpp_inner.immutable=!1,s.zpp_inner._validate=null,s}get x(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.x}set x(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e}get y(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.y}set y(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.y=e}get z(){return this._checkDisposed(),this.zpp_inner.validate(),this.zpp_inner.z}set z(e){this._checkDisposed(),this._checkImmutable(),this.zpp_inner.z=e}get length(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return Math.sqrt(e*e+t*t+n*n)}set length(e){if(this._checkDisposed(),e!==e)throw new Error("Error: Vec3::length cannot be NaN");this.zpp_inner.validate();let{x:t,y:n,z:s}=this.zpp_inner,i=t*t+n*n+s*s;if(i===0)throw new Error("Error: Cannot set length of a zero vector");let l=e/Math.sqrt(i);this._checkImmutable(),this.zpp_inner.x=t*l,this.zpp_inner.y=n*l,this.zpp_inner.z=s*l}lsq(){this._checkDisposed(),this.zpp_inner.validate();let{x:e,y:t,z:n}=this.zpp_inner;return e*e+t*t+n*n}set(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot assign null Vec3");return e.zpp_inner.validate(),this.setxyz(e.zpp_inner.x,e.zpp_inner.y,e.zpp_inner.z)}setxyz(e,t,n){return this._checkDisposed(),this._checkImmutable(),this.zpp_inner.x=e,this._checkImmutable(),this.zpp_inner.y=t,this._checkImmutable(),this.zpp_inner.z=n,this}equals(e,t=0){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(e==null)return!1;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.x-e.zpp_inner.x,s=this.zpp_inner.y-e.zpp_inner.y,i=this.zpp_inner.z-e.zpp_inner.z;return(n<0?-n:n)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t}clone(){return this._checkDisposed(),this.zpp_inner.validate(),j.get(this.zpp_inner.x,this.zpp_inner.y,this.zpp_inner.z)}xy(e=!1){return this._checkDisposed(),this.zpp_inner.validate(),lt.get(this.zpp_inner.x,this.zpp_inner.y,e)}dispose(){if(this.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");if(this.zpp_inner.immutable)throw new Error("Error: This Vec3 is not disposable");this.zpp_pool=null,xe.nextVec3!=null?xe.nextVec3.zpp_pool=this:xe.poolVec3=this,xe.nextVec3=this,this.zpp_disp=!0}toString(){return this._checkDisposed(),this.zpp_inner.validate(),"{ x: "+this.zpp_inner.x+" y: "+this.zpp_inner.y+" z: "+this.zpp_inner.z+" }"}};oi._wrapFn=j=>Ze(j,e=>{let t=Object.create(ci.prototype);return t.zpp_inner=e,t.zpp_pool=null,t.zpp_disp=!1,e.outer=t,t});var Vs=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 Bi(e,t),this.zpp_inner.outer=this}static _wrap(e){return e instanceof j?e:e?e instanceof Bi?Ze(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!1;for(let n=0;n<this.zpp_inner.x.length;n++){let s=this.zpp_inner.x[n]-e.zpp_inner.x[n];if((s<0?-s:s)>t)return!1}return!0}clone(){let e=new 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=!0;for(let n=0;n<this.zpp_inner.m;n++){t||(e+="; "),t=!1;for(let s=0;s<this.zpp_inner.n;s++){if(n<0||s<0||n>=this.zpp_inner.m||s>=this.zpp_inner.n)throw new Error("Error: MatMN indices out of range");e+=this.zpp_inner.x[n*this.zpp_inner.n+s]+" "}}return e+="}",e}transpose(){let e=new 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 o=0;o<this.zpp_inner.n;o++)l+=this.zpp_inner.x[s*this.zpp_inner.n+o]*t.zpp_inner.x[o*t.zpp_inner.n+i];n.zpp_inner.x[s*n.zpp_inner.n+i]=l}return n}},ho=_e();ho.geom.MatMN=Vs;var Wi=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;fe.zpp_pool==null?i=new fe:(i=fe.zpp_pool,fe.zpp_pool=i.next,i.next=null),i.minx=e,i.miny=t,i.maxx=e+n,i.maxy=t+s,this.zpp_inner=i,i.outer=this}static fromPoints(e){if(e==null||e.length===0)throw new Error("Error: AABB::fromPoints requires at least one point");let t=e[0];if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");t.zpp_inner.validate();let n=t.zpp_inner.x,s=t.zpp_inner.y,i=n,l=s;for(let o=1;o<e.length;o++){let r=e[o];if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(r==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");r.zpp_inner.validate();let a=r.zpp_inner.x,p=r.zpp_inner.y;a<n&&(n=a),p<s&&(s=p),a>i&&(i=a),p>l&&(l=p)}return new j(n,s,i-n,l-s)}static _wrap(e){return e instanceof j?e:e?e instanceof fe?Ze(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 o=this.zpp_inner.wrap_max;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(o.zpp_inner._validate!=null&&o.zpp_inner._validate(),l>o.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let r=this.zpp_inner.wrap_min;this._assignVec2(r,e),e.zpp_inner.weak&&this._disposeVec2(e)}get max(){return this.zpp_inner.getmax(),this.zpp_inner.wrap_max}set max(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this.zpp_inner._immutable)throw new Error("Error: AABB is immutable");if(e==null)throw new Error("Error: Cannot assign null to AABB::max");this.zpp_inner.validate();let t=this.zpp_inner.minx;if(this.zpp_inner.validate(),t!=this.zpp_inner.minx)throw new Error("Error: AABB::max components cannot be NaN");this.zpp_inner.validate();let n=this.zpp_inner.miny;if(this.zpp_inner.validate(),n!=this.zpp_inner.miny)throw new Error("Error: AABB::max components cannot be NaN");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let s=e.zpp_inner.x;this.zpp_inner.getmin();let i=this.zpp_inner.wrap_min;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(i.zpp_inner._validate!=null&&i.zpp_inner._validate(),s<i.zpp_inner.x)throw new Error("Error: Assignment would cause negative width");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate();let l=e.zpp_inner.y;this.zpp_inner.getmin();let o=this.zpp_inner.wrap_min;if(o!=null&&o.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(o.zpp_inner._validate!=null&&o.zpp_inner._validate(),l<o.zpp_inner.y)throw new Error("Error: Assignment would cause negative height");let r=this.zpp_inner.wrap_max;this._assignVec2(r,e),e.zpp_inner.weak&&this._disposeVec2(e)}_assignVec2(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let n=e.zpp_inner;if(n._immutable)throw new Error("Error: Vec2 is immutable");if(n._isimmutable!=null&&n._isimmutable(),t==null)throw new Error("Error: Cannot assign null Vec2");if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let s=t.zpp_inner.x;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");t.zpp_inner._validate!=null&&t.zpp_inner._validate();let i=t.zpp_inner.y;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),s!=s||i!=i)throw new Error("Error: Vec2 components cannot be NaN");let o;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e.zpp_inner._validate!=null&&e.zpp_inner._validate(),e.zpp_inner.x==s){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");e.zpp_inner._validate!=null&&e.zpp_inner._validate(),o=e.zpp_inner.y==i}else o=!1;o||(e.zpp_inner.x=s,e.zpp_inner.y=i,e.zpp_inner._invalidate!=null&&e.zpp_inner._invalidate(e.zpp_inner))}_disposeVec2(e){let n=_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=!0;let o=i;o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o._isimmutable=null,o._validate=null,o._invalidate=null,o.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=o}clone(){return this.copy()}equals(e,t=0){if(e==null)return!1;this.zpp_inner.validate(),e.zpp_inner.validate();let n=this.zpp_inner.minx-e.zpp_inner.minx,s=this.zpp_inner.miny-e.zpp_inner.miny,i=this.zpp_inner.maxx-e.zpp_inner.maxx,l=this.zpp_inner.maxy-e.zpp_inner.maxy;return(n<0?-n:n)<=t&&(s<0?-s:s)<=t&&(i<0?-i:i)<=t&&(l<0?-l:l)<=t}copy(){this.zpp_inner.validate();let e=this.zpp_inner;return fe.get(e.minx,e.miny,e.maxx,e.maxy).wrapper()}toString(){return this.zpp_inner.validate(),this.zpp_inner.toString()}};fe._wrapFn=j=>Ze(j,e=>{let t=Object.create(Wi.prototype);return t.zpp_inner=e,e.outer=t,t});var dl=class j{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate Winding derp!")}static get UNDEFINED(){return U.Winding_UNDEFINED==null&&(U.internal=!0,U.Winding_UNDEFINED=new j,U.internal=!1),U.Winding_UNDEFINED}static get CLOCKWISE(){return U.Winding_CLOCKWISE==null&&(U.internal=!0,U.Winding_CLOCKWISE=new j,U.internal=!1),U.Winding_CLOCKWISE}static get ANTICLOCKWISE(){return U.Winding_ANTICLOCKWISE==null&&(U.internal=!0,U.Winding_ANTICLOCKWISE=new j,U.internal=!1),U.Winding_ANTICLOCKWISE}toString(){return this===U.Winding_UNDEFINED?"UNDEFINED":this===U.Winding_CLOCKWISE?"CLOCKWISE":this===U.Winding_ANTICLOCKWISE?"ANTICLOCKWISE":""}},uo=_e();uo.geom.Winding=dl;var ei=class ei{constructor(){this.ptr=null;this.start=null;this.first=!1;this.forward=!1;this.outer=null;this.next=null;ei.internal=!0;let e=_e();this.outer=new e.geom.GeomVertexIterator,ei.internal=!1}static get(e,t){let n;return ei.zpp_pool==null?n=new ei:(n=ei.zpp_pool,ei.zpp_pool=n.next,n.next=null),n.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(){}};ei.zpp_pool=null,ei.internal=!1;var hs=ei;var Dl=class j{constructor(e){this.zpp_pool=null;this.zpp_disp=!1;this.zpp_inner=new os(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 ve.zpp_pool==null?n=new ve:(n=ve.zpp_pool,ve.zpp_pool=n.next,n.next=null),n.forced=!1,n.x=e,n.y=t,n}static _pushVert(e,t){e.zpp_inner.vertices==null?e.zpp_inner.vertices=t.prev=t.next=t:(t.prev=e.zpp_inner.vertices,t.next=e.zpp_inner.vertices.next,e.zpp_inner.vertices.next.prev=t,e.zpp_inner.vertices.next=t),e.zpp_inner.vertices=t}static _unshiftVert(e,t){e.zpp_inner.vertices==null?e.zpp_inner.vertices=t.prev=t.next=t:(t.next=e.zpp_inner.vertices,t.prev=e.zpp_inner.vertices.prev,e.zpp_inner.vertices.prev.next=t,e.zpp_inner.vertices.prev=t),e.zpp_inner.vertices=t}static _freeVert(e){e.free(),e.next=ve.zpp_pool,ve.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 lt))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 o=l.zpp_inner.x;l.zpp_inner.validate();let r=l.zpp_inner.y,a=j._createVert(o,r);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 o=i.zpp_inner.y,r=j._createVert(l,o);j._pushVert(e,r)}}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=!1,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,!0)}forwardIterator(){return this._checkDisposed(),hs.get(this.zpp_inner.vertices,!0)}backwardsIterator(){return this._checkDisposed(),hs.get(this.zpp_inner.vertices,!1)}current(){if(this._checkDisposed(),this.zpp_inner.vertices==null)throw new Error("Error: GeomPoly is empty");return this.zpp_inner.vertices.wrapper()}push(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot push null vertex");e.zpp_inner.validate();let t=e.zpp_inner.x;e.zpp_inner.validate();let n=e.zpp_inner.y,s=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=!0}area(){if(this._checkDisposed(),this._isDegenRing())return 0;let e=0;this._forEachVert(n=>{e+=n.x*(n.next.y-n.prev.y)});let t=e*.5;return t<0?-t:t}winding(){if(this._checkDisposed(),this._isDegenRing())return U.Winding_UNDEFINED==null&&(U.internal=!0,U.Winding_UNDEFINED=new(_e()).geom.Winding,U.internal=!1),U.Winding_UNDEFINED;let e=0;this._forEachVert(n=>{e+=n.x*(n.next.y-n.prev.y)});let t=e*.5;return t>0?(U.Winding_CLOCKWISE==null&&(U.internal=!0,U.Winding_CLOCKWISE=new(_e()).geom.Winding,U.internal=!1),U.Winding_CLOCKWISE):t===0?(U.Winding_UNDEFINED==null&&(U.internal=!0,U.Winding_UNDEFINED=new(_e()).geom.Winding,U.internal=!1),U.Winding_UNDEFINED):(U.Winding_ANTICLOCKWISE==null&&(U.internal=!0,U.Winding_ANTICLOCKWISE=new(_e()).geom.Winding,U.internal=!1),U.Winding_ANTICLOCKWISE)}contains(e){if(this._checkDisposed(),e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: GeomPoly::contains point cannot be null");e.zpp_inner.validate();let t=e.zpp_inner.x;e.zpp_inner.validate();let n=e.zpp_inner.y,s=!1;return this._forEachVert(i=>{let l=i.prev;(i.y<n&&l.y>=n||l.y<n&&i.y>=n)&&(i.x<=t||l.x<=t)&&i.x+(n-i.y)/(l.y-i.y)*(l.x-i.x)<t&&(s=!s)}),e.zpp_inner.weak&&e.dispose(),s}isClockwise(){let e=this.winding();return U.Winding_CLOCKWISE==null&&(U.internal=!0,U.Winding_CLOCKWISE=new(_e()).geom.Winding,U.internal=!1),e===U.Winding_CLOCKWISE}isConvex(){if(this._checkDisposed(),this._isDegenRing())return!0;let e=!1,t=!1,n=!0,s=this.zpp_inner.vertices,i=s;do{let l=i,o=l.prev,r=l.next,a=r.x-l.x,p=r.y-l.y,c=l.x-o.x,u=(l.y-o.y)*a-c*p;if(u>0?t=!0:u<0&&(e=!0),t&&e){n=!1;break}i=i.next}while(i!==s);return n}isSimple(){return this._checkDisposed(),this._isDegenRing()?!0:wi.isSimple(this.zpp_inner.vertices)}isMonotone(){return this._checkDisposed(),this._isDegenRing()?!0:Dt.isMonotone(this.zpp_inner.vertices)}isDegenerate(){return this._checkDisposed(),this._isDegenRing()?!0: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=rs.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 Fn);let s=wi.decompose(n,Je.sharedGVList),i=e??new t.geom.GeomPolyList;for(;s.head!=null;){let l=s.pop_unsafe(),o=j.get();o.zpp_inner.vertices=l,i.zpp_inner.reverse_flag?i.push(o):i.unshift(o)}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 Fn);let i=s.extract(Je.sharedGVList),l=e??new t.geom.GeomPolyList;for(;i.head!=null;){let o=i.pop_unsafe(),r=j.get();r.zpp_inner.vertices=o,l.zpp_inner.reverse_flag?l.push(r):l.unshift(r)}return l}convexDecomposition(e=!1,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 Si);let l=i.extract_partitions(Je.sharedPPList),o=t??new n.geom.GeomPolyList;for(;l.head!=null;){let r=l.pop_unsafe();li.triangulate(r),e&&li.optimise(r),is.optimise(r),Je.sharedGVList==null&&(Je.sharedGVList=new Fn);let a=r.extract(Je.sharedGVList),p=r;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,o.zpp_inner.reverse_flag?o.push(h):o.unshift(h)}}return o}triangularDecomposition(e=!1,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 Si);let l=i.extract_partitions(Je.sharedPPList),o=t??new n.geom.GeomPolyList;for(;l.head!=null;){let r=l.pop_unsafe();li.triangulate(r),e&&li.optimise(r),Je.sharedGVList==null&&(Je.sharedGVList=new Fn);let a=r.extract(Je.sharedGVList),p=r;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,o.zpp_inner.reverse_flag?o.push(h):o.unshift(h)}}return o}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,o=n.y-s.y,r=i.x-n.x,a=i.y-n.y,p=Math.sqrt(l*l+o*o),c=-o/p*e,h=l/p*e,u=Math.sqrt(r*r+a*a),x=-a/u*e,m=r/u*e,_=x-c,y=m-h,z=a*_-r*y,f=z===0?0:z/(a*l-r*o),w=n.x+c+l*f,Z=n.y+h+o*f,d=lt.get(w,Z);t.push(d)}),t.skipForward(1)}cut(e,t,n=!1,s=!1,i){if(this._checkDisposed(),!(this._isDegenRing()||wi.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=ss.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 Wi(e,t,n-e,s-t)}top(){return this._extremalVert("y",!0)}bottom(){return this._extremalVert("y",!1)}left(){return this._extremalVert("x",!0)}right(){return this._extremalVert("x",!1)}toString(){let e="GeomPoly[",t=this.zpp_inner.vertices;if(t!=null){let n=t;do n!==t&&(e+=","),e+="{"+n.x+","+n.y+"}",n=n.next;while(n!==t)}return e+"]"}};var As,Is,js;function Fl(j){As=j}function Px(j){Is=j}function wx(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()&&As?As(e):e.isShape&&e.isShape()&&Is?Is(e):e.isCompound&&e.isCompound()&&js?js(e):Ze(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 As?As(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=!1;var gi=Bs;var tl=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 hi=class j{get _inner(){return this}constructor(e=1,t=1){let n;if(Mn.zpp_pool==null?n=new Mn:(n=Mn.zpp_pool,Mn.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 Mn?Ze(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=!1;let s=this.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),s.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let l=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let o=s;o.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=o:n.util.ZPP_PubPool.poolVec2=o,n.util.ZPP_PubPool.nextVec2=o,o.zpp_disp=!0;let r=l;r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=r,this.zpp_inner.wrap_gravity=null}}else{if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");this.zpp_inner.wrap_gravity==null&&this.zpp_inner.getgravity();let s=this.zpp_inner.wrap_gravity;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let i=s.zpp_inner;if(i._immutable)throw new Error("Error: Vec2 is immutable");if(i._isimmutable!=null&&i._isimmutable(),e==null)throw new Error("Error: Cannot assign null Vec2");if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=e.zpp_inner;l._validate!=null&&l._validate();let o=e.zpp_inner.x;if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=e.zpp_inner;r._validate!=null&&r._validate();let a=e.zpp_inner.y;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=s.zpp_inner;if(p._immutable)throw new Error("Error: Vec2 is immutable");if(p._isimmutable!=null&&p._isimmutable(),o!=o||a!=a)throw new Error("Error: Vec2 components cannot be NaN");let c;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=s.zpp_inner;if(h._validate!=null&&h._validate(),s.zpp_inner.x==o){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=s.zpp_inner;u._validate!=null&&u._validate(),c=s.zpp_inner.y==a}else c=!1;if(!c){s.zpp_inner.x=o,s.zpp_inner.y=a;let u=s.zpp_inner;u._invalidate!=null&&u._invalidate(u)}if(e.zpp_inner.weak){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=e.zpp_inner;if(u._immutable)throw new Error("Error: Vec2 is immutable");if(u._isimmutable!=null&&u._isimmutable(),e.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let x=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null;let m=e;m.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=m:n.util.ZPP_PubPool.poolVec2=m,n.util.ZPP_PubPool.nextVec2=m,m.zpp_disp=!0;let _=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,!0)}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=!1;let i=n.zpp_inner.wrap_gravity;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),i.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let o=i.zpp_inner;i.zpp_inner.outer=null,i.zpp_inner=null;let r=i;r.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=r:t.util.ZPP_PubPool.poolVec2=r,t.util.ZPP_PubPool.nextVec2=r,r.zpp_disp=!0;let a=o;a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=a,n.zpp_inner.wrap_gravity=null}}else{if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");n.zpp_inner.wrap_gravity==null&&n.zpp_inner.getgravity();let i=n.zpp_inner.wrap_gravity;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let l=i.zpp_inner;if(l._immutable)throw new Error("Error: Vec2 is immutable");if(l._isimmutable!=null&&l._isimmutable(),s==null)throw new Error("Error: Cannot assign null Vec2");if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=s.zpp_inner;o._validate!=null&&o._validate();let r=s.zpp_inner.x;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let a=s.zpp_inner;a._validate!=null&&a._validate();let p=s.zpp_inner.y;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let c=i.zpp_inner;if(c._immutable)throw new Error("Error: Vec2 is immutable");if(c._isimmutable!=null&&c._isimmutable(),r!=r||p!=p)throw new Error("Error: Vec2 components cannot be NaN");let h;if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=i.zpp_inner;if(u._validate!=null&&u._validate(),i.zpp_inner.x==r){if(i!=null&&i.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=i.zpp_inner;x._validate!=null&&x._validate(),h=i.zpp_inner.y==p}else h=!1;if(!h){i.zpp_inner.x=r,i.zpp_inner.y=p;let x=i.zpp_inner;x._invalidate!=null&&x._invalidate(x)}if(s.zpp_inner.weak){if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let x=s.zpp_inner;if(x._immutable)throw new Error("Error: Vec2 is immutable");if(x._isimmutable!=null&&x._isimmutable(),s.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let m=s.zpp_inner;s.zpp_inner.outer=null,s.zpp_inner=null;let _=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=!0;let y=m;y.outer!=null&&(y.outer.zpp_inner=null,y.outer=null),y._isimmutable=null,y._validate=null,y._invalidate=null,y.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=y}}return n}toString(){return"{ density: "+this.zpp_inner.density*1e3+" viscosity: "+this.zpp_inner.viscosity+" gravity: "+String(this.zpp_inner.wrap_gravity)+" }"}};Mn._wrapFn=j=>Ze(j,e=>{let t=Object.create(hi.prototype);return t.zpp_inner=e,e.outer=t,t});var xo=_e();xo.phys.FluidProperties=hi;var yl=class j{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate ShapeType derp!")}static get CIRCLE(){return U.ShapeType_CIRCLE==null&&(U.internal=!0,U.ShapeType_CIRCLE=new j,U.internal=!1),U.ShapeType_CIRCLE}static get POLYGON(){return U.ShapeType_POLYGON==null&&(U.internal=!0,U.ShapeType_POLYGON=new j,U.internal=!1),U.ShapeType_POLYGON}static get CAPSULE(){return U.ShapeType_CAPSULE==null&&(U.internal=!0,U.ShapeType_CAPSULE=new j,U.internal=!1),U.ShapeType_CAPSULE}toString(){return this===U.ShapeType_CIRCLE?"CIRCLE":this===U.ShapeType_POLYGON?"POLYGON":this===U.ShapeType_CAPSULE?"CAPSULE":""}},_o=_e();_o.shape.ShapeType=yl;el();var Ts,Ls,Ds;function Gl(j){Ts=j}function Rl(j){Ls=j}function ql(j){Ds=j}var ti=class j extends gi{constructor(){super()}static _wrap(e){if(!e)return null;let t=e.isCircle?e.isCircle()?0:e.isPolygon?.()?1:-1:e.zpp_inner?.type??-1;return t===0&&Ts?Ts(e):t===1&&Ls?Ls(e):t===2&&Ds?Ds(e):e.outer?e.outer:Ze(e,n=>{let s=Object.create(j.prototype);return s._inner=n,s.zpp_inner=n.zpp_inner??n,s.zpp_inner_i=n.zpp_inner_i??n,s})}get type(){return ri.types[this.zpp_inner.type]}isCircle(){return this.zpp_inner.type===0}isPolygon(){return this.zpp_inner.type===1}isCapsule(){return this.zpp_inner.type===2}get body(){let e=this.zpp_inner;return e.body!=null?e.body.outer:null}set body(e){let t=this.zpp_inner;t.immutable_midstep("Shape::body");let n=t.body!=null?t.body.outer:null;if(n!==e&&(t.body!=null&&n.zpp_inner.wrap_shapes.remove(this),e!=null)){let s=e.zpp_inner.wrap_shapes;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}}get castCircle(){let e=this.zpp_inner;if(e.type===0){let t=e.circle.outer_zn;return Ts?Ts(t):t}return null}get castPolygon(){let e=this.zpp_inner;if(e.type===1){let t=e.polygon.outer_zn;return Ls?Ls(t):t}return null}get castCapsule(){let e=this.zpp_inner;if(e.type===2){let t=e.capsule.outer_zn;return Ds?Ds(t):t}return null}get worldCOM(){let e=this.zpp_inner;return e.wrap_worldCOM==null&&this._setupWorldCOM(),e.wrap_worldCOM}get localCOM(){let e=this.zpp_inner;return e.wrap_localCOM==null&&(e.type===0?e.circle.setupLocalCOM():e.type===1?e.polygon.setupLocalCOM():e.capsule.setupLocalCOM()),e.wrap_localCOM}set localCOM(e){let t=this.zpp_inner;if(t.immutable_midstep("Body::localCOM"),e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(t.body!=null&&t.body.space!=null&&t.body.type===1)throw new Error("Error: Cannot modify Shape belonging to a static Object once inside a Space");if(e==null)throw new Error("Error: Shape::localCOM cannot be null");t.wrap_localCOM==null&&(t.type===0?t.circle.setupLocalCOM():t.type===1?t.polygon.setupLocalCOM():t.capsule.setupLocalCOM()),t.wrap_localCOM.set(e),e.zpp_inner.weak&&e.dispose()}get area(){let e=this.zpp_inner;return e.validate_area_inertia(),e.area}get inertia(){let e=this.zpp_inner;return e.validate_area_inertia(),e.inertia}get angDrag(){let e=this.zpp_inner;return e.validate_angDrag(),e.angDrag}get material(){return this.zpp_inner.material.wrapper()}set material(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::material"),e==null)throw new Error("Error: Cannot assign null as Shape material");t.setMaterial(e.zpp_inner)}get filter(){return this.zpp_inner.filter.wrapper()}set filter(e){let t=this.zpp_inner;if(t.immutable_midstep("Shape::filter"),e==null)throw new Error("Error: Cannot assign null as Shape filter");t.setFilter(e.zpp_inner)}get fluidProperties(){let e=this.zpp_inner;return e.immutable_midstep("Shape::fluidProperties"),e.fluidProperties==null&&e.setFluid(new hi().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 hi().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 hi;t.setFluid(n.zpp_inner),t.immutable_midstep("Shape::fluidProperties"),t.fluidProperties==null&&t.setFluid(new hi().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");ls.validateShape(t);let n=e.zpp_inner;n._validate!=null&&n._validate();let s=Ee.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=!1,i===xe.nextVec2&&(xe.nextVec2=null)),i.zpp_inner==null){let l;pe.zpp_pool==null?l=new pe:(l=pe.zpp_pool,pe.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=n,l.y=s,i.zpp_inner=l,i.zpp_inner.outer=i}else i.zpp_inner.x=n,i.zpp_inner.y=s;i.zpp_inner.weak=!1,t.wrap_worldCOM=i,t.wrap_worldCOM.zpp_inner._inuse=!0,t.wrap_worldCOM.zpp_inner._immutable=!0,t.wrap_worldCOM.zpp_inner._validate=t.getworldCOM.bind(t)}};var Ci={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=!1;this.push_ite=null;this.at_ite=null;this.at_index=0;this.reverse_flag=!1;this.dontremove=!1;this.subber=null;this.post_adder=null;this.adder=null;this._modifiable=null;this._validate=null;this._invalidate=null;this._invalidated=!1;this.immutable=!1;this.inner=null;this.outer=null;this._invalidated=!0}valmod(){this.validate(),this.inner.modified&&(this.inner.pushmod&&(this.push_ite=null),this.at_ite=null,this.inner.modified=!1,this.inner.pushmod=!1,this.zip_length=!0)}modified(){this.zip_length=!0,this.at_ite=null,this.push_ite=null}modify_test(){this._modifiable!=null&&this._modifiable()}validate(){this._invalidated&&(this._invalidated=!1,this._validate!=null&&this._validate())}invalidate(){this._invalidated=!0,this._invalidate!=null&&this._invalidate(this)}};function Nn(j,e,t,n){let s=_e(),i=s.__zpp;class l extends ml{constructor(){super(),this.inner=new i.util[j]}static get(r,a=!1){let p=new s[e][t];return p.zpp_inner.inner=r,a&&(p.zpp_inner.immutable=!0),p.zpp_inner.zip_length=!0,p}}return l.internal=!1,i.util[n]=l,l}var fl=null,yo=null,bl=null;fl=Nn("ZNPList_ZPP_Constraint","constraint","ConstraintList","ZPP_ConstraintList");Nn("ZNPList_ZPP_Body","phys","BodyList","ZPP_BodyList");yo=Nn("ZNPList_ZPP_Interactor","phys","InteractorList","ZPP_InteractorList");Nn("ZNPList_ZPP_Compound","phys","CompoundList","ZPP_CompoundList");Nn("ZNPList_ZPP_Listener","callbacks","ListenerList","ZPP_ListenerList");Nn("ZNPList_ZPP_CbType","callbacks","CbTypeList","ZPP_CbTypeList");Nn("ZNPList_ZPP_GeomPoly","geom","GeomPolyList","ZPP_GeomPolyList");Nn("ZNPList_RayResult","geom","RayResultList","ZPP_RayResultList");Nn("ZNPList_ConvexResult","geom","ConvexResultList","ZPP_ConvexResultList");Nn("ZNPList_ZPP_Edge","shape","EdgeList","ZPP_EdgeList");Nn("ZNPList_ZPP_Shape","shape","ShapeList","ZPP_ShapeList");Nn("ZNPList_ZPP_InteractionGroup","dynamics","InteractionGroupList","ZPP_InteractionGroupList");bl=Nn("ZNPList_ZPP_Arbiter","dynamics","ArbiterList","ZPP_ArbiterList");function Wn(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 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.y}function Tn(j){if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}function On(j){j.zpp_inner.weak&&j.dispose()}function us(j,e,t,n,s){if(Tn(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 nl(j,e,t){return lt.get(j,e,t)}function sn(j,e){return U[j]==null&&(U.internal=!0,U[j]=e(),U.internal=!1),U[j]}var tt=class j extends gi{constructor(t,n){super();this.debugDraw=!0;let s=new Cn;this.zpp_inner=s,s.outer=this,s.outer_i=this,this.zpp_inner_i=s,this._inner=this,n!=null?(Tn(n),s.posx=Wn(n),s.posy=Jn(n)):(s.posx=0,s.posy=0);let i=_e(),l;if(t==null?l=sn("BodyType_DYNAMIC",()=>new i.phys.BodyType):l=t,s.immutable_midstep("Body::type"),s.world)throw new Error("Error: Space::world is immutable");if(Cn.types[s.type]!==l){if(l==null)throw new Error("Error: Cannot use null BodyType");let o=Wl(l,i);o===1&&s.space!=null&&(s.velx=0,s.vely=0,s.angvel=0),s.invalidate_type(),s.space!=null?s.space.transmitType(s,o):s.type=o}n!=null&&On(n),s.insert_cbtype(pn.ANY_BODY.zpp_inner)}static _wrap(t){return t?t instanceof j?t:t instanceof Cn?Ze(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=!0,s}):t.zpp_inner?j._wrap(t.zpp_inner):Ze(t,n=>{let s=Object.create(j.prototype);return s._inner=n,s}):null}get type(){return Cn.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(Cn.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 tl(this.zpp_inner.wrap_shapes,ti._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=!1,s.zpp_inner.wrap_bodies.remove(this)),n!=null)){let i=n.zpp_inner.wrap_bodies;i.zpp_inner.reverse_flag?i.push(this):i.unshift(this)}}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(t){let n=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(n!==t&&(n?.zpp_inner.wrap_bodies.remove(this),t!=null)){let s=t.zpp_inner.wrap_bodies;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}}get bounds(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no bounds");return Wi._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=lt.get(this.zpp_inner.localCOMx,this.zpp_inner.localCOMy);this.zpp_inner.wrap_localCOM=t,t.zpp_inner._inuse=!0,t.zpp_inner._immutable=!0,t.zpp_inner._validate=()=>this.zpp_inner.getlocalCOM()}return this.zpp_inner.wrap_localCOM}get worldCOM(){if(this.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");if(this.zpp_inner.wrap_worldCOM==null){let t=lt.get(this.zpp_inner.worldCOMx,this.zpp_inner.worldCOMy);this.zpp_inner.wrap_worldCOM=t,t.zpp_inner._inuse=!0,t.zpp_inner._immutable=!0,t.zpp_inner._validate=()=>this.zpp_inner.getworldCOM()}return this.zpp_inner.wrap_worldCOM}get massMode(){let t=_e(),n=sn("MassMode_DEFAULT",()=>new t.phys.MassMode),s=sn("MassMode_FIXED",()=>new t.phys.MassMode);return[n,s][this.zpp_inner.massMode]}set massMode(t){let n=_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=sn("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=sn("InertiaMode_DEFAULT",()=>new t.phys.InertiaMode),s=sn("InertiaMode_FIXED",()=>new t.phys.InertiaMode);return[n,s][this.zpp_inner.inertiaMode]}set inertiaMode(t){let n=_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=sn("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=sn("GravMassMode_DEFAULT",()=>new t.phys.GravMassMode),s=sn("GravMassMode_FIXED",()=>new t.phys.GravMassMode),i=sn("GravMassMode_SCALED",()=>new t.phys.GravMassMode);return[n,s,i][this.zpp_inner.gravMassMode]}set gravMassMode(t){let n=_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=sn("GravMassMode_SCALED",()=>new n.phys.GravMassMode);if(t===s)this.zpp_inner.gravMassMode=2;else{let i=sn("GravMassMode_DEFAULT",()=>new n.phys.GravMassMode);this.zpp_inner.gravMassMode=t===i?0:1}this.zpp_inner.invalidate_gravMass()}copy(){if(this.zpp_inner.world)throw new Error("Error: Space::world cannot be copied");return this.zpp_inner.copy()}toString(){let t=this.zpp_inner;return(t.world?"(space::world":"("+(t.type===2?"dynamic":t.type===1?"static":"kinematic"))+")#"+this.zpp_inner_i.id}integrate(t){if(t!==t)throw new Error("Cannot integrate by NaN time");if(this.zpp_inner.immutable_midstep("Body::space"),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t===0)return this;let n=this.zpp_inner;n.sweepTime=0,n.sweep_angvel=n.angvel;let s=t-n.sweepTime;if(s!==0&&(n.sweepTime=t,n.posx+=n.velx*s,n.posy+=n.vely*s,n.angvel!==0)){let i=n.sweep_angvel*s;if(n.rot+=i,i*i>1e-4)n.axisx=Math.sin(n.rot),n.axisy=Math.cos(n.rot);else{let l=i*i,o=1-.5*l,r=1-l*l/8,a=(o*n.axisx+i*n.axisy)*r;n.axisy=(o*n.axisy-i*n.axisx)*r,n.axisx=a}}return Jl(n),n.zip_worldCOM=!0,n.zip_axis=!0,Jl(n),n.zip_worldCOM=!0,n.sweepTime=0,this}localPointToWorld(t,n=!1){if(Tn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Wn(t),i=Jn(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,o=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return On(t),nl(l+this.zpp_inner.posx,o+this.zpp_inner.posy,n)}worldPointToLocal(t,n=!1){if(Tn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Wn(t)-this.zpp_inner.posx,i=Jn(t)-this.zpp_inner.posy,l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,o=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return On(t),nl(l,o,n)}localVectorToWorld(t,n=!1){if(Tn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Wn(t),i=Jn(t),l=this.zpp_inner.axisy*s-this.zpp_inner.axisx*i,o=s*this.zpp_inner.axisx+i*this.zpp_inner.axisy;return On(t),nl(l,o,n)}worldVectorToLocal(t,n=!1){if(Tn(t),t==null)throw new Error("Error: Cannot transform null Vec2");this.zpp_inner.validate_axis();let s=Wn(t),i=Jn(t),l=s*this.zpp_inner.axisy+i*this.zpp_inner.axisx,o=i*this.zpp_inner.axisy-s*this.zpp_inner.axisx;return On(t),nl(l,o,n)}applyImpulse(t,n,s=!1){if(Tn(t),n!=null&&Tn(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 On(t),n!=null&&On(n),this;this.zpp_inner.validate_mass();let i=this.zpp_inner.imass,l=Wn(t),o=Jn(t);if(this.zpp_inner.velx+=l*i,this.zpp_inner.vely+=o*i,n!=null){let r=Wn(n)-this.zpp_inner.posx,a=Jn(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(o*r-l*a)*this.zpp_inner.iinertia,On(n)}return s||this.zpp_inner.type===2&&this.zpp_inner.wake(),On(t),this}applyAngularImpulse(t,n=!1){if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");return n&&this.isSleeping?this:(this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=t*this.zpp_inner.iinertia,n||this.zpp_inner.type===2&&this.zpp_inner.wake(),this)}setVelocityFromTarget(t,n,s){if(Tn(t),t==null)throw new Error("Cannot set velocity for null target position");if(s===0)throw new Error("deltaTime cannot be 0 for setVelocityFromTarget");let i=1/s;this.zpp_inner.wrap_vel==null&&this.zpp_inner.setupVelocity(),this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let l=t.sub(this.zpp_inner.wrap_pos,!0).muleq(i);this.zpp_inner.wrap_vel.set(l);let o=(n-this.zpp_inner.rot)*i;if(this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(this.zpp_inner.angvel!==o){if(o!==o)throw new Error("Error: Body::angularVel cannot be NaN");if(this.zpp_inner.type===1)throw new Error("Error: A static object cannot be given a velocity");this.zpp_inner.angvel=o,this.zpp_inner.wake()}return On(t),this}translateShapes(t){if(this.zpp_inner.immutable_midstep("Body::translateShapes()"),Tn(t),this.zpp_inner.world)throw new Error("Error: Space::world is immutable");if(t==null)throw new Error("Error: Cannot displace by null Vec2");let n=t.zpp_inner.weak;t.zpp_inner.weak=!1;let s=this.zpp_inner.shapes.head;for(;s!=null;)s.elt.outer.translate(t),s=s.next;return t.zpp_inner.weak=n,On(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=lt.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-=Wn(n),this.zpp_inner.pre_posy-=Jn(n)),t.dispose(),n.dispose(),this}rotate(t,n){if(Tn(t),t==null)throw new Error("Error: Cannot rotate about a null Vec2");if(n!==n)throw new Error("Error: Cannot rotate by NaN radians");let s=t.zpp_inner.weak;t.zpp_inner.weak=!1,this.zpp_inner.wrap_pos==null&&this.zpp_inner.setupPosition();let i=this.zpp_inner.wrap_pos.sub(t);i.rotate(n);let l=t.add(i,!0);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 o=this.zpp_inner.rot+n,r=this.zpp_inner;if(r.immutable_midstep("Body::rotation"),r.world)throw new Error("Error: Space::world is immutable");if(r.type===1&&r.space!=null)throw new Error("Error: Static objects cannot be rotated once inside a Space");if(r.rot!==o){if(o!==o)throw new Error("Error: Body::rotation cannot be NaN");r.rot=o,r.invalidate_rot(),r.wake()}}return t.zpp_inner.weak=s,On(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(Tn(t),t==null)throw new Error("Error: Cannot check containment of null point");let n=t.zpp_inner.weak;t.zpp_inner.weak=!1;let s=!1,i=this.zpp_inner.shapes.head;for(;i!=null;){if(i.elt.outer.contains(t)){s=!0;break}i=i.next}return t.zpp_inner.weak=n,On(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(),o=sn("InteractionType_COLLISION",()=>new l.callbacks.InteractionType);if(t===o)i=Ie.COL;else{let r=sn("InteractionType_SENSOR",()=>new l.callbacks.InteractionType);i=t===r?Ie.SENSOR:Ie.FLUID}}return this.zpp_inner.interactingBodies(i,s)}normalImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.normalImpulse(this,n),t)}tangentImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.tangentImpulse(this,n),t)}totalContactsImpulse(t=null,n=!1){return this._arbiterImpulseQuery(Ie.COL,s=>s.collisionArbiter.totalImpulse(this,n),t)}rollingImpulse(t=null,n=!1){let s=0,l=this._getArbiters().iterator();for(;;){l.zpp_inner.zpp_inner.valmod();let o=l.zpp_inner.zpp_gl();if(l.zpp_critical=!0,l.zpp_i>=o){l.zpp_next=_e().dynamics.ArbiterIterator.zpp_pool,_e().dynamics.ArbiterIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1;let r=l.zpp_inner.at(l.zpp_i++),a=r.zpp_inner;a.type===Ie.COL&&(t!=null&&a.b2!==t.zpp_inner&&a.b1!==t.zpp_inner||(s+=r.collisionArbiter.rollingImpulse(this,n)))}return s}buoyancyImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.buoyancyImpulse(this),t)}dragImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.dragImpulse(this),t)}totalFluidImpulse(t=null){return this._arbiterImpulseQuery(Ie.FLUID,n=>n.fluidArbiter.totalImpulse(this),t)}constraintsImpulse(){let t=0,n=0,s=0,i=this.zpp_inner.constraints.head;for(;i!=null;){let o=i.elt.outer.bodyImpulse(this),r=o.zpp_inner;r._validate!=null&&r._validate(),t+=r.x,r._validate!=null&&r._validate(),n+=r.y,r._validate!=null&&r._validate(),s+=r.z,o.dispose(),i=i.next}return ci.get(t,n,s)}totalImpulse(t=null,n=!1){let s=0,i=0,l=0,r=this._getArbiters().iterator();for(;;){r.zpp_inner.zpp_inner.valmod();let p=r.zpp_inner.zpp_gl();if(r.zpp_critical=!0,r.zpp_i>=p){r.zpp_next=_e().dynamics.ArbiterIterator.zpp_pool,_e().dynamics.ArbiterIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let h=r.zpp_inner.at(r.zpp_i++).zpp_inner;if(h.type===Ie.SENSOR||t!=null&&h.b2!==t.zpp_inner&&h.b1!==t.zpp_inner)continue;let u=h.wrapper().totalImpulse(this,n),x=u.zpp_inner;x._validate!=null&&x._validate(),s+=x.x,x._validate!=null&&x._validate(),i+=x.y,x._validate!=null&&x._validate(),l+=x.z,u.dispose()}let a=this.zpp_inner.constraints.head;for(;a!=null;){let p=a.elt;if(p.outer.active){let c=p.outer.bodyImpulse(this),h=c.zpp_inner;h._validate!=null&&h._validate(),s+=h.x,h._validate!=null&&h._validate(),i+=h.y,h._validate!=null&&h._validate(),l+=h.z,c.dispose()}a=a.next}return ci.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=lt.get(0,0),i=this._getArbiters().iterator();for(;;){i.zpp_inner.zpp_inner.valmod();let x=i.zpp_inner.zpp_gl();if(i.zpp_critical=!0,i.zpp_i>=x){i.zpp_next=_e().dynamics.ArbiterIterator.zpp_pool,_e().dynamics.ArbiterIterator.zpp_pool=i,i.zpp_inner=null;break}i.zpp_critical=!1;let _=i.zpp_inner.at(i.zpp_i++).totalImpulse(this),y=_.xy();n.addeq(y);let z=Wn(y),f=Jn(y);t+=Math.sqrt(z*z+f*f),y.dispose(),_.dispose()}let o=this._getConstraints();o.zpp_inner.valmod();let r=_e().constraint.ConstraintIterator.get(o);for(;;){r.zpp_inner.zpp_inner.valmod();let x=r.zpp_inner;x.zpp_inner.valmod(),x.zpp_inner.zip_length&&(x.zpp_inner.zip_length=!1,x.zpp_inner.user_length=x.zpp_inner.inner.length);let m=x.zpp_inner.user_length;if(r.zpp_critical=!0,r.zpp_i>=m){r.zpp_next=_e().constraint.ConstraintIterator.zpp_pool,_e().constraint.ConstraintIterator.zpp_pool=r,r.zpp_inner=null;break}r.zpp_critical=!1;let y=r.zpp_inner.at(r.zpp_i++).bodyImpulse(this),z=y.xy();n.addeq(z);let f=Wn(z),w=Jn(z);t+=Math.sqrt(f*f+w*w),z.dispose(),y.dispose()}let a=Wn(n),p=Jn(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=bl.get(this.zpp_inner.arbiters,!0)),this.zpp_inner.wrap_arbiters}_getConstraints(){return this.zpp_inner.wrap_constraints==null&&(this.zpp_inner.wrap_constraints=fl.get(this.zpp_inner.constraints,!0)),this.zpp_inner.wrap_constraints}_arbiterImpulseQuery(t,n,s){let i=0,l=0,o=0,a=this._getArbiters().iterator();for(;;){a.zpp_inner.zpp_inner.valmod();let p=a.zpp_inner.zpp_gl();if(a.zpp_critical=!0,a.zpp_i>=p){a.zpp_next=_e().dynamics.ArbiterIterator.zpp_pool,_e().dynamics.ArbiterIterator.zpp_pool=a,a.zpp_inner=null;break}a.zpp_critical=!1;let c=a.zpp_inner.at(a.zpp_i++),h=c.zpp_inner;if(h.type!==t||s!=null&&h.b2!==s.zpp_inner&&h.b1!==s.zpp_inner)continue;let u=n(c),x=u.zpp_inner;x._validate!=null&&x._validate(),i+=x.x,x._validate!=null&&x._validate(),l+=x.y,x._validate!=null&&x._validate(),o+=x.z,u.dispose()}return ci.get(i,l,o)}};function Wl(j,e){let t=sn("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(j===t)return 2;let n=sn("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 mo=_e();mo.phys.Body=tt;Fl(j=>tt._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 pi(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 pi?e.outer?e.outer:Ze(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:Ze(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_sweep?(U.Broadphase_SWEEP_AND_PRUNE==null&&(U.internal=!0,U.Broadphase_SWEEP_AND_PRUNE=new(_e()).space.Broadphase,U.internal=!1),U.Broadphase_SWEEP_AND_PRUNE):(U.Broadphase_DYNAMIC_AABB_TREE==null&&(U.internal=!0,U.Broadphase_DYNAMIC_AABB_TREE=new(_e()).space.Broadphase,U.internal=!1),U.Broadphase_DYNAMIC_AABB_TREE)}get sortContacts(){return this.zpp_inner.sortcontacts}set sortContacts(e){this.zpp_inner.sortcontacts=e}get worldAngularDrag(){return this.zpp_inner.global_ang_drag}set worldAngularDrag(e){if(e!==e)throw new Error("Error: Space::worldAngularDrag cannot be NaN");this.zpp_inner.global_ang_drag=e}get worldLinearDrag(){return this.zpp_inner.global_lin_drag}set worldLinearDrag(e){if(e!==e)throw new Error("Error: Space::worldLinearDrag cannot be NaN");this.zpp_inner.global_lin_drag=e}get compounds(){return this.zpp_inner.wrap_compounds}get bodies(){return this.zpp_inner.wrap_bodies}get liveBodies(){return this.zpp_inner.wrap_live}get constraints(){return this.zpp_inner.wrap_constraints}get liveConstraints(){return this.zpp_inner.wrap_livecon}get world(){return tt._wrap(this.zpp_inner.__static)}get arbiters(){if(this.zpp_inner.wrap_arbiters==null){let e=new Yn;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 o=s.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=r){s.zpp_next=t.phys.BodyIterator.zpp_pool,t.phys.BodyIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1,e(s.zpp_inner.at(s.zpp_i++))}let i=this.zpp_inner.wrap_compounds;i.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(i);for(;;){l.zpp_inner.zpp_inner.valmod();let o=l.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=r){l.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,l.zpp_inner.at(l.zpp_i++).visitBodies(e)}}visitConstraints(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitConstraints");let t=_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 o=s.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=r){s.zpp_next=t.constraint.ConstraintIterator.zpp_pool,t.constraint.ConstraintIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1,e(s.zpp_inner.at(s.zpp_i++))}let i=this.zpp_inner.wrap_compounds;i.zpp_inner.valmod();let l=t.phys.CompoundIterator.get(i);for(;;){l.zpp_inner.zpp_inner.valmod();let o=l.zpp_inner;o.zpp_inner.valmod(),o.zpp_inner.zip_length&&(o.zpp_inner.zip_length=!1,o.zpp_inner.user_length=o.zpp_inner.inner.length);let r=o.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=r){l.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=l,l.zpp_inner=null;break}l.zpp_critical=!1,l.zpp_inner.at(l.zpp_i++).visitConstraints(e)}}visitCompounds(e){if(e==null)throw new Error("Error: lambda cannot be null for Space::visitCompounds");let t=_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=!1,i.zpp_inner.user_length=i.zpp_inner.inner.length);let l=i.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=l){s.zpp_next=t.phys.CompoundIterator.zpp_pool,t.phys.CompoundIterator.zpp_pool=s,s.zpp_inner=null;break}s.zpp_critical=!1;let o=s.zpp_inner.at(s.zpp_i++);e(o),o.visitCompounds(e)}}interactionType(e,t){if(e==null||t==null)throw new Error("Error: Cannot evaluate interaction type for null shapes");let n=e.zpp_inner,s=t.zpp_inner;if((n.body!=null?n.body.outer:null)==null||(s.body!=null?s.body.outer:null)==null)throw new Error("Error: Cannot evaluate interaction type for shapes not part of a Body");let i=n.body,l=s.body;if(i.type==1&&l.type==1||i.outer==l.outer)return null;let o=!1,r=i.constraints.head;for(;r!=null;){let u=r.elt;if(u.ignore&&u.pair_exists(i.id,l.id)){o=!0;break}r=r.next}let a;if(o)a=!1;else{let u=n;for(;u!=null&&u.group==null;)u.ishape!=null?u=u.ishape.body:u.icompound!=null?u=u.icompound.compound:u=u.ibody.compound;let x=u==null?null:u.group,m;if(x==null)m=!1;else{let _=s;for(;_!=null&&_.group==null;)_.ishape!=null?_=_.ishape.body:_.icompound!=null?_=_.icompound.compound:_=_.ibody.compound;let y=_==null?null:_.group;if(y==null)m=!1;else{let z=!1;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?(U.InteractionType_SENSOR==null&&(U.internal=!0,U.InteractionType_SENSOR=new(_e()).callbacks.InteractionType,U.internal=!1),U.InteractionType_SENSOR):(n.fluidEnabled||s.fluidEnabled)&&(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0&&!h?(U.InteractionType_FLUID==null&&(U.internal=!0,U.InteractionType_FLUID=new(_e()).callbacks.InteractionType,U.internal=!1),U.InteractionType_FLUID):(p.collisionMask&c.collisionGroup)!=0&&(c.collisionMask&p.collisionGroup)!=0&&!h?(U.InteractionType_COLLISION==null&&(U.internal=!0,U.InteractionType_COLLISION=new(_e()).callbacks.InteractionType,U.internal=!1),U.InteractionType_COLLISION):null}shapesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes under a null point :)");let s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.shapesUnderPoint(i,l,o,n);return s.weak&&e.dispose(),r}bodiesUnderPoint(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects under a null point :)");let s=e.zpp_inner;s._validate!=null&&s._validate();let i=s.x;s._validate!=null&&s._validate();let l=s.y,o=t==null?null:t.zpp_inner??t,r=this.zpp_inner.bodiesUnderPoint(i,l,o,n);return s.weak&&e.dispose(),r}shapesInAABB(e,t=!1,n=!0,s,i){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null AABB :)");let l=e.zpp_inner;if(l._validate!=null&&l._validate(),l.maxx-l.minx==0||l.maxy-l.miny==0)throw new Error("Error: Cannot evaluate shapes in degenerate AABB :/");let o=s==null?null:s.zpp_inner??s;return this.zpp_inner.shapesInAABB(e,n,t,o,i)}bodiesInAABB(e,t=!1,n=!0,s,i){if(e==null)throw new Error("Error: Cannot evaluate objects in a null AABB :)");let l=e.zpp_inner;if(l._validate!=null&&l._validate(),l.maxx-l.minx==0||l.maxy-l.miny==0)throw new Error("Error: Cannot evaluate objects in degenerate AABB :/");let o=s==null?null:s.zpp_inner??s;return this.zpp_inner.bodiesInAABB(e,n,t,o,i)}shapesInCircle(e,t,n=!1,s,i){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate shapes at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let l=s==null?null:s.zpp_inner??s,o=this.zpp_inner.shapesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),o}bodiesInCircle(e,t,n=!1,s,i){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot evaluate objects at null circle :)");if(t!==t)throw new Error("Error: Circle radius cannot be NaN");if(t<=0)throw new Error("Error: Circle radius must be strictly positive");let l=s==null?null:s.zpp_inner??s,o=this.zpp_inner.bodiesInCircle(e,t,n,l,i);return e.zpp_inner?.weak&&e.dispose(),o}shapesInShape(e,t=!1,n,s){if(e==null)throw new Error("Error: Cannot evaluate shapes in a null shapes :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(i.type==1){let o=i.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new(_e()).shape.ValidationResult,U.internal=!1),o!=U.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.toString())}let l=n==null?null:n.zpp_inner??n;return this.zpp_inner.shapesInShape(i,t,l,s)}bodiesInShape(e,t=!1,n,s){if(e==null)throw new Error("Error: Cannot evaluate bodies in a null shapes :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Query shape needs to be inside a Body to be well defined :)");if(i.type==1){let o=i.polygon.valid();if(U.ValidationResult_VALID==null&&(U.internal=!0,U.ValidationResult_VALID=new(_e()).shape.ValidationResult,U.internal=!1),o!=U.ValidationResult_VALID)throw new Error("Error: Polygon query shape is invalid : "+o.toString())}let l=n==null?null:n.zpp_inner??n;return this.zpp_inner.bodiesInShape(i,t,l,s)}shapesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let s=_e(),i=n??new s.shape.ShapeList,l=e.zpp_inner.wrap_shapes;l.zpp_inner.valmod();let o=s.shape.ShapeIterator.get(l);for(;;){o.zpp_inner.zpp_inner.valmod();let r=o.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=a){o.zpp_next=s.shape.ShapeIterator.zpp_pool,s.shape.ShapeIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let p=o.zpp_inner.at(o.zpp_i++);this.shapesInShape(p,!1,t,i)}return i}bodiesInBody(e,t,n){if(e==null)throw new Error("Error: Cannot evaluate shapes in null body");let s=_e(),i=n??new s.phys.BodyList,l=e.zpp_inner.wrap_shapes;l.zpp_inner.valmod();let o=s.shape.ShapeIterator.get(l);for(;;){o.zpp_inner.zpp_inner.valmod();let r=o.zpp_inner;r.zpp_inner.valmod(),r.zpp_inner.zip_length&&(r.zpp_inner.zip_length=!1,r.zpp_inner.user_length=r.zpp_inner.inner.length);let a=r.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=a){o.zpp_next=s.shape.ShapeIterator.zpp_pool,s.shape.ShapeIterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let p=o.zpp_inner.at(o.zpp_i++);this.bodiesInShape(p,!1,t,i)}return i}convexCast(e,t,n=!1,s){if(e==null)throw new Error("Error: Cannot cast null shape :)");let i=e.zpp_inner;if((i.body!=null?i.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexCast(i,t,s,n)}convexMultiCast(e,t,n=!1,s,i){if(e==null)throw new Error("Error: Cannot cast null shape :)");let l=e.zpp_inner;if((l.body!=null?l.body.outer:null)==null)throw new Error("Error: Shape must belong to a body to be cast.");if(t<0||t!==t)throw new Error("Error: deltaTime must be positive");return this.zpp_inner.convexMultiCast(l,t,s,n,i)}rayCast(e,t=!1,n){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayCast(e,t,n)}rayMultiCast(e,t=!1,n,s){if(e==null)throw new Error("Error: Cannot cast null ray :)");return this.zpp_inner.rayMultiCast(e,t,n,s)}debugDraw(e,t=Ci.ALL){if(e==null)throw new Error("Error: drawer cannot be null for Space::debugDraw");let n=(t&Ci.SHAPES)!==0,s=(t&Ci.JOINTS)!==0,i=(t&Ci.CONTACTS)!==0,l=(t&Ci.AABB)!==0,o=(t&Ci.CENTER_OF_MASS)!==0,r=(t&Ci.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,f=z.type===2,Z=z.type===1?p:f?a:c;if(n){let d=z.shapes.head;for(;d!=null;){let b=d.elt;if(b.type===0){let g=b.circle;b.zip_worldCOM&&b.validate_worldCOM();let P=b.worldCOMx,v=b.worldCOMy,N=g.radius,k=z.rot,C=P+Math.cos(k)*N,E=v+Math.sin(k)*N,M={x:P,y:v},S={x:C,y:E};f?e.drawSolidCircle(M,N,S,Z):e.drawCircle(M,N,Z)}else if(b.type===1){let g=b.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&&(f?e.drawSolidPolygon(P,Z):e.drawPolygon(P,Z))}else if(b.type===2){let g=b.capsule;b.zip_aabb&&b.validate_aabb();let P={x:g.spine1x,y:g.spine1y},v={x:g.spine2x,y:g.spine2y};f?e.drawSolidCapsule(P,v,g.radius,Z):e.drawCapsule(P,v,g.radius,Z)}d=d.next}}if(l&&!z.world){let d=z.aabb,b=d.minx,g=d.miny,P=d.maxx,v=d.maxy;e.drawSegment({x:b,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:b,y:v},x),e.drawSegment({x:b,y:v},{x:b,y:g},x)}if(o&&!z.world&&(z.validate_worldCOM(),e.drawPoint({x:z.worldCOMx,y:z.worldCOMy},m)),r&&!z.world&&f){let d=z.posx,b=z.posy;e.drawSegment({x:d,y:b},{x:d+z.velx,y:b+z.vely},_)}}),s&&this.visitConstraints(y=>{if(!y.debugDraw)return;let z=y.zpp_inner,f=z.b1,w=z.b2,Z=z.a1worldx??(f!=null?f.posx:0),d=z.a1worldy??(f!=null?f.posy:0),b=z.a2worldx??(w!=null?w.posx:0),g=z.a2worldy??(w!=null?w.posy:0);e.drawSegment({x:Z,y:d},{x:b,y:g},h),e.drawPoint({x:Z,y:d},h),e.drawPoint({x:b,y:g},h)}),i){let y=z=>{if(z==null)return;let f=z.head;for(;f!=null;){let w=f.elt;if(w!=null){let Z=w.nx,d=w.ny,b=w.contacts?.next;for(;b!=null;){let g=b.px,P=b.py;e.drawPoint({x:g,y:P},u),e.drawSegment({x:g,y:P},{x:g+Z*8,y:P+d*8},u),b=b.next}}f=f.next}};y(this.zpp_inner.c_arbiters_true),y(this.zpp_inner.c_arbiters_false)}}toString(){return`Space(bodies=${this.bodies.length})`}};var zl=class j{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate BodyType derp!")}static get STATIC(){return U.BodyType_STATIC==null&&(U.internal=!0,U.BodyType_STATIC=new j,U.internal=!1),U.BodyType_STATIC}static get DYNAMIC(){return U.BodyType_DYNAMIC==null&&(U.internal=!0,U.BodyType_DYNAMIC=new j,U.internal=!1),U.BodyType_DYNAMIC}static get KINEMATIC(){return U.BodyType_KINEMATIC==null&&(U.internal=!0,U.BodyType_KINEMATIC=new j,U.internal=!1),U.BodyType_KINEMATIC}toString(){return this===U.BodyType_STATIC?"STATIC":this===U.BodyType_DYNAMIC?"DYNAMIC":this===U.BodyType_KINEMATIC?"KINEMATIC":""}},fo=_e();fo.phys.BodyType=zl;el();var _s=class j extends gi{constructor(){super();let e=new qn;this.zpp_inner=e,e.outer=this,e.outer_i=this,this.zpp_inner_i=e,this._inner=this,e.insert_cbtype(pn.ANY_COMPOUND.zpp_inner)}static _wrap(e){return e?e instanceof j?e:e instanceof qn?Ze(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):Ze(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=!1){let t=new lt(0,0),n=0;if(this.visitBodies(s=>{if(s.zpp_inner.wrap_shapes.zpp_inner.inner.head!=null){if(s.zpp_inner.world)throw new Error("Error: Space::world has no worldCOM");s.zpp_inner.wrap_worldCOM==null&&s.zpp_inner.getworldCOM();let l=s.zpp_inner.wrap_worldCOM;if(s.zpp_inner.world)throw new Error("Error: Space::world has no mass");if(s.zpp_inner.validate_mass(),s.zpp_inner.massMode==0&&s.zpp_inner.shapes.head==null)throw new Error("Error: Given current mass mode, Body::mass only makes sense if it contains shapes");let o=s.zpp_inner.cmass;t.addeq(l.mul(o,!0)),n+=o}}),n===0)throw new Error("Error: COM of an empty Compound is undefined silly");return t.muleq(1/n),e&&(t.zpp_inner.weak=!0),t}translate(e){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot translate by null Vec2");let t=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(n=>{n.zpp_inner.wrap_pos==null&&n.zpp_inner.setupPosition(),n.zpp_inner.wrap_pos.addeq(e)}),e.zpp_inner.weak=t,e.zpp_inner.weak&&e.dispose(),this}rotate(e,t){if(e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Cannot rotate about a null Vec2");if(t!==t)throw new Error("Error: Cannot rotate by NaN radians");let n=e.zpp_inner.weak;return e.zpp_inner.weak=!1,this.visitBodies(s=>{s.rotate(e,t)}),e.zpp_inner.weak=n,e.zpp_inner.weak&&e.dispose(),this}toString(){return"Compound"+this.zpp_inner.id}};qn._wrapFn=j=>Ze(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:!0});Object.defineProperty(_s.prototype,"constraints",{get:function(){return this.zpp_inner.wrap_constraints},configurable:!0});Object.defineProperty(_s.prototype,"compounds",{get:function(){return this.zpp_inner.wrap_compounds},configurable:!0});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?Ze(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=>Ze(j,e=>{let t=Object.create(Pl.prototype);return t.zpp_inner=e,e.outer=t,t});var wl=class j{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate GravMassMode derp!")}static get DEFAULT(){return U.GravMassMode_DEFAULT==null&&(U.internal=!0,U.GravMassMode_DEFAULT=new j,U.internal=!1),U.GravMassMode_DEFAULT}static get FIXED(){return U.GravMassMode_FIXED==null&&(U.internal=!0,U.GravMassMode_FIXED=new j,U.internal=!1),U.GravMassMode_FIXED}static get SCALED(){return U.GravMassMode_SCALED==null&&(U.internal=!0,U.GravMassMode_SCALED=new j,U.internal=!1),U.GravMassMode_SCALED}toString(){return this===U.GravMassMode_DEFAULT?"DEFAULT":this===U.GravMassMode_FIXED?"FIXED":this===U.GravMassMode_SCALED?"SCALED":""}},bo=_e();bo.phys.GravMassMode=wl;var vl=class j{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate InertiaMode derp!")}static get DEFAULT(){return U.InertiaMode_DEFAULT==null&&(U.internal=!0,U.InertiaMode_DEFAULT=new j,U.internal=!1),U.InertiaMode_DEFAULT}static get FIXED(){return U.InertiaMode_FIXED==null&&(U.internal=!0,U.InertiaMode_FIXED=new j,U.internal=!1),U.InertiaMode_FIXED}toString(){return this===U.InertiaMode_DEFAULT?"DEFAULT":this===U.InertiaMode_FIXED?"FIXED":""}},zo=_e();zo.phys.InertiaMode=vl;var gl=class j{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate MassMode derp!")}static get DEFAULT(){return U.MassMode_DEFAULT==null&&(U.internal=!0,U.MassMode_DEFAULT=new j,U.internal=!1),U.MassMode_DEFAULT}static get FIXED(){return U.MassMode_FIXED==null&&(U.internal=!0,U.MassMode_FIXED=new j,U.internal=!1),U.MassMode_FIXED}toString(){return this===U.MassMode_DEFAULT?"DEFAULT":this===U.MassMode_FIXED?"FIXED":""}},Po=_e();Po.phys.MassMode=gl;var il=class j extends ti{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>Dn.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");l.radius=e,l.invalidate_radius()}if(t!=null){if(t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let o=t.zpp_inner;o._validate!=null&&o._validate(),l.localCOMx=o.x,o._validate!=null&&o._validate(),l.localCOMy=o.y,o.weak&&t.dispose()}else l.localCOMx=0,l.localCOMy=0;n==null?Oe.zpp_pool!=null?(l.material=Oe.zpp_pool,Oe.zpp_pool=l.material.next,l.material.next=null):l.material=new Oe:(l.immutable_midstep("Shape::material"),l.setMaterial(n.zpp_inner),l.material.wrapper()),s==null?it.zpp_pool!=null?(l.filter=it.zpp_pool,it.zpp_pool=l.filter.next,l.filter.next=null):l.filter=new it:(l.immutable_midstep("Shape::filter"),l.setFilter(s.zpp_inner),l.filter.wrapper()),l.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof j?e:e instanceof Xn?Ze(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):Ze(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>Dn.FMAX)throw new Error("Error: Circle::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}};Gl(j=>il._wrap(j));var wo=_e();wo.shape.Circle=il;var sl=class j extends ti{constructor(e,t,n){super();let s=_e();if(e==null)throw new Error("Error: localVerts cannot be null");let i=new Hn;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 lt))throw new Error("Error: Array<Vec2> contains non Vec2 objects");if(l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.wrap_lverts==null&&i.getlverts();let o=l.zpp_inner;o._validate!=null&&o._validate();let r=o.x;o._validate!=null&&o._validate();let a=o.y,p=new lt(r,a);i.wrap_lverts.push(p)}for(let l=e.length-1;l>=0;l--)e[l].zpp_inner?.weak&&(e[l].dispose(),e.splice(l,1))}else if(e instanceof s.geom.Vec2List){let l=e,o=l.iterator();for(;;){o.zpp_inner.zpp_inner.valmod();let c=o.zpp_inner.zpp_gl();if(o.zpp_critical=!0,o.zpp_i>=c){o.zpp_next=s.geom.Vec2Iterator.zpp_pool,s.geom.Vec2Iterator.zpp_pool=o,o.zpp_inner=null;break}o.zpp_critical=!1;let h=o.zpp_inner.at(o.zpp_i++);if(h==null)throw new Error("Error: Vec2List contains null objects");if(h.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");i.wrap_lverts==null&&i.getlverts();let u=h.zpp_inner;u._validate!=null&&u._validate();let x=u.x;u._validate!=null&&u._validate();let m=u.y,_=new lt(x,m);i.wrap_lverts.push(_)}l.zpp_inner._validate!=null&&l.zpp_inner._validate();let r=l.zpp_inner.inner,a=null,p=r.head;for(;p!=null;){let c=p.elt;c.outer?.zpp_inner?.weak?(p=r.erase(a),c.outer.zpp_inner.weak&&c.outer.dispose()):(a=p,p=p.next)}}else if(e instanceof s.geom.GeomPoly){let l=e.zpp_inner.vertices;if(l!=null){let o=l;do{i.wrap_lverts==null&&i.getlverts();let r=new lt(o.x,o.y);i.wrap_lverts.push(r),o=o.next}while(o!==l)}}else throw new Error("Error: Invalid type for polygon object, should be Array<Vec2>, Vec2List, GeomPoly or for flash10+ flash.Vector<Vec2>");t==null?Oe.zpp_pool!=null?(i.material=Oe.zpp_pool,Oe.zpp_pool=i.material.next,i.material.next=null):i.material=new Oe:(i.immutable_midstep("Shape::material"),i.setMaterial(t.zpp_inner),i.material.wrapper()),n==null?it.zpp_pool!=null?(i.filter=it.zpp_pool,it.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new it:(i.immutable_midstep("Shape::filter"),i.setFilter(n.zpp_inner),i.filter.wrapper()),i.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof j?e:e instanceof Hn?Ze(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):Ze(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=!1){if(e!==e||t!==t||n!==n||s!==s)throw new Error("Error: Polygon.rect cannot accept NaN arguments");let l=new lt(e,t);l.zpp_inner.weak=i;let o=new lt(e+n,t);o.zpp_inner.weak=i;let r=new lt(e+n,t+s);r.zpp_inner.weak=i;let a=new lt(e,t+s);return a.zpp_inner.weak=i,[l,o,r,a]}static box(e,t=e,n=!1){if(e!==e||t!==t)throw new Error("Error: Polygon.box cannot accept NaN arguments");return j.rect(-e/2,-t/2,e,t,n)}static regular(e,t,n,s=0,i=!1){if(e!==e||t!==t||s!==s)throw new Error("Error: Polygon.regular cannot accept NaN arguments");let l=[],o=Math.PI*2/n;for(let r=0;r<n;r++){let a=r*o+s,p=Math.cos(a)*e,c=Math.sin(a)*t,h=new lt(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=>sl._wrap(j));var vo=_e();vo.shape.Polygon=sl;var ll=class j extends ti{constructor(e=100,t=40,n,s,i){super();let l=_e();if(e!==e||t!==t)throw new Error("Error: Capsule dimensions cannot be NaN");if(t<=0)throw new Error("Error: Capsule height ("+t+") must be > 0");if(e<t)throw new Error("Error: Capsule width ("+e+") must be >= height ("+t+")");let o=t/2,r=(e-t)/2,a=new Qn;if(this.zpp_inner_zn=a,this.zpp_inner=a,this.zpp_inner_i=a,a.outer=this,a.outer_zn=this,a.outer_i=this,this._inner=this,o<l.Config.epsilon)throw new Error("Error: Capsule radius ("+o+") must be > Config.epsilon");if(o>Dn.FMAX)throw new Error("Error: Capsule radius ("+o+") must be < PR(Const).FMAX");if(a.radius=o,a.halfLength=r,a.invalidate_radius(),r>0&&a.invalidate_halfLength(),n!=null){if(n.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=n.zpp_inner;p._validate!=null&&p._validate(),a.localCOMx=p.x,p._validate!=null&&p._validate(),a.localCOMy=p.y,p.weak&&n.dispose()}else a.localCOMx=0,a.localCOMy=0;s==null?Oe.zpp_pool!=null?(a.material=Oe.zpp_pool,Oe.zpp_pool=a.material.next,a.material.next=null):a.material=new Oe:(a.immutable_midstep("Shape::material"),a.setMaterial(s.zpp_inner),a.material.wrapper()),i==null?it.zpp_pool!=null?(a.filter=it.zpp_pool,it.zpp_pool=a.filter.next,a.filter.next=null):a.filter=new it:(a.immutable_midstep("Shape::filter"),a.setFilter(i.zpp_inner),a.filter.wrapper()),a.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof j?e:e instanceof Qn?Ze(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):Ze(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("Capsule::radius"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modify radius of Capsule contained in static object once added to space");if(e!==t.radius){if(e!==e)throw new Error("Error: Capsule::radius cannot be NaN");if(e<n.Config.epsilon)throw new Error("Error: Capsule::radius ("+e+") must be > Config.epsilon");if(e>Dn.FMAX)throw new Error("Error: Capsule::radius ("+e+") must be < PR(Const).FMAX");t.radius=e,t.invalidate_radius()}}get halfLength(){return this.zpp_inner_zn.halfLength}set halfLength(e){let t=this.zpp_inner_zn;if(this.zpp_inner.immutable_midstep("Capsule::halfLength"),t.body!=null&&t.body.type===1&&t.body.space!=null)throw new Error("Error: Cannot modify halfLength of Capsule contained in static object once added to space");if(e!==t.halfLength){if(e!==e)throw new Error("Error: Capsule::halfLength cannot be NaN");if(e<0)throw new Error("Error: Capsule::halfLength ("+e+") must be >= 0");t.halfLength=e,t.invalidate_halfLength()}}get width(){return 2*(this.zpp_inner_zn.halfLength+this.zpp_inner_zn.radius)}get height(){return 2*this.zpp_inner_zn.radius}};ql(j=>ll._wrap(j));var go=_e();go.shape.Capsule=ll;var Ul=class j{constructor(){if(!U.internal)throw new Error("Error: Cannot instantiate Broadphase derp!")}static get DYNAMIC_AABB_TREE(){return U.Broadphase_DYNAMIC_AABB_TREE==null&&(U.internal=!0,U.Broadphase_DYNAMIC_AABB_TREE=new j,U.internal=!1),U.Broadphase_DYNAMIC_AABB_TREE}static get SWEEP_AND_PRUNE(){return U.Broadphase_SWEEP_AND_PRUNE==null&&(U.internal=!0,U.Broadphase_SWEEP_AND_PRUNE=new j,U.internal=!1),U.Broadphase_SWEEP_AND_PRUNE}toString(){return this===U.Broadphase_DYNAMIC_AABB_TREE?"DYNAMIC_AABB_TREE":this===U.Broadphase_SWEEP_AND_PRUNE?"SWEEP_AND_PRUNE":""}};var Cl=class j{get _inner(){return this}constructor(e=1,t=-1,n=1,s=-1,i=1,l=-1){let o;it.zpp_pool==null?o=new it:(o=it.zpp_pool,it.zpp_pool=o.next,o.next=null),this.zpp_inner=o,o.outer=this,o.collisionGroup!=e&&(o.collisionGroup=e,o.invalidate()),o.collisionMask!=t&&(o.collisionMask=t,o.invalidate()),o.sensorGroup!=n&&(o.sensorGroup=n,o.invalidate()),o.sensorMask!=s&&(o.sensorMask=s,o.invalidate()),o.fluidGroup!=i&&(o.fluidGroup=i,o.invalidate()),o.fluidMask!=l&&(o.fluidMask=l,o.invalidate())}static _wrap(e){return e instanceof j?e:e?e instanceof it?Ze(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,!0)}return this.zpp_inner.wrap_shapes}shouldCollide(e){if(e==null)throw new Error("Error: filter argument cannot be null for shouldCollide");return this.zpp_inner.shouldCollide(e.zpp_inner)}shouldSense(e){if(e==null)throw new Error("Error: filter argument cannot be null for shouldSense");return this.zpp_inner.shouldSense(e.zpp_inner)}shouldFlow(e){if(e==null)throw new Error("Error: filter argument cannot be null for shouldFlow");return this.zpp_inner.shouldFlow(e.zpp_inner)}copy(){return new 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)+" }"}};it._wrapFn=j=>Ze(j,e=>{let t=Object.create(Cl.prototype);return t.zpp_inner=e,e.outer=t,t});var Ji=class Ji{constructor(){this.debugDraw=!0;this._inner=this}static _wrap(e){return e==null?null:e instanceof Ji?e:e.zpp_inner?.outer instanceof Ji?e.zpp_inner.outer:Ze(e,t=>{let n=Object.create(Ji.prototype);return n.zpp_inner=t.zpp_inner??t,n._inner=t,n.zpp_inner.outer=n,n.debugDraw=t.debugDraw??!0,n})}get space(){return this.zpp_inner.space==null?null:this.zpp_inner.space.outer}set space(e){if(this.zpp_inner.compound!=null)throw new Error("Error: Cannot set the space of a Constraint belonging to a Compound, only the root Compound space can be set");if((this.zpp_inner.space==null?null:this.zpp_inner.space.outer)!=e)if(this.zpp_inner.component!=null&&(this.zpp_inner.component.woken=!1),this.zpp_inner.clearcache(),this.zpp_inner.space!=null&&this.zpp_inner.space.wrap_constraints.remove(this),e!=null){let s=(e._inner?.zpp_inner??e.zpp_inner).wrap_constraints;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}else this.zpp_inner.space=null}get compound(){return this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer}set compound(e){let t=this.zpp_inner.compound==null?null:this.zpp_inner.compound.outer;if(t!=e&&(t?.zpp_inner.wrap_constraints.remove(this),e!=null)){let s=e.zpp_inner.wrap_constraints;s.zpp_inner.reverse_flag?s.push(this):s.unshift(this)}}get active(){return this.zpp_inner.active}set active(e){this.zpp_inner.active!=e&&(this.zpp_inner.component!=null&&(this.zpp_inner.component.woken=!1),this.zpp_inner.clearcache(),e?(this.zpp_inner.active=e,this.zpp_inner.activate(),this.zpp_inner.space!=null&&(this.zpp_inner.component!=null&&(this.zpp_inner.component.sleeping=!0),this.zpp_inner.space.wake_constraint(this.zpp_inner,!0))):(this.zpp_inner.space!=null&&(this.zpp_inner.wake(),this.zpp_inner.space.live_constraints.remove(this.zpp_inner)),this.zpp_inner.active=e,this.zpp_inner.deactivate()))}get ignore(){return this.zpp_inner.ignore}set ignore(e){this.zpp_inner.ignore!=e&&(this.zpp_inner.ignore=e,this.zpp_inner.wake())}get stiff(){return this.zpp_inner.stiff}set stiff(e){this.zpp_inner.stiff!=e&&(this.zpp_inner.stiff=e,this.zpp_inner.wake())}get frequency(){return this.zpp_inner.frequency}set frequency(e){if(e!==e)throw new Error("Error: Constraint::Frequency cannot be NaN");if(e<=0)throw new Error("Error: Constraint::Frequency must be >0");this.zpp_inner.frequency!=e&&(this.zpp_inner.frequency=e,this.zpp_inner.stiff||this.zpp_inner.wake())}get damping(){return this.zpp_inner.damping}set damping(e){if(e!==e)throw new Error("Error: Constraint::Damping cannot be Nan");if(e<0)throw new Error("Error: Constraint::Damping must be >=0");this.zpp_inner.damping!=e&&(this.zpp_inner.damping=e,this.zpp_inner.stiff||this.zpp_inner.wake())}get maxForce(){return this.zpp_inner.maxForce}set maxForce(e){if(e!==e)throw new Error("Error: Constraint::maxForce cannot be NaN");if(e<0)throw new Error("Error: Constraint::maxForce must be >=0");this.zpp_inner.maxForce!=e&&(this.zpp_inner.maxForce=e,this.zpp_inner.wake())}get maxError(){return this.zpp_inner.maxError}set maxError(e){if(e!==e)throw new Error("Error: Constraint::maxError cannot be NaN");if(e<0)throw new Error("Error: Constraint::maxError must be >=0");this.zpp_inner.maxError!=e&&(this.zpp_inner.maxError=e,this.zpp_inner.wake())}get breakUnderForce(){return this.zpp_inner.breakUnderForce}set breakUnderForce(e){this.zpp_inner.breakUnderForce!=e&&(this.zpp_inner.breakUnderForce=e,this.zpp_inner.wake())}get breakUnderError(){return this.zpp_inner.breakUnderError}set breakUnderError(e){this.zpp_inner.breakUnderError!=e&&(this.zpp_inner.breakUnderError=e,this.zpp_inner.wake())}get removeOnBreak(){return this.zpp_inner.removeOnBreak}set removeOnBreak(e){this.zpp_inner.removeOnBreak=e}get isSleeping(){if(this.zpp_inner.space==null||!this.zpp_inner.active)throw new Error("Error: isSleeping only makes sense if constraint is active and inside a space");return this.zpp_inner.component.sleeping}get userData(){return this.zpp_inner.userData==null&&(this.zpp_inner.userData={}),this.zpp_inner.userData}get cbTypes(){return this.zpp_inner.wrap_cbTypes==null&&this.zpp_inner.setupcbTypes(),this.zpp_inner.wrap_cbTypes}impulse(){return null}bodyImpulse(e){return null}visitBodies(e){}copy(){return Ji._wrap(this.zpp_inner.copy())}toString(){return"{Constraint}"}};Ji.zpp_internalAlloc=!1;var ln=Ji;var Ml=class j extends ln{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?Ze(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(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:tt._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:tt._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=>Ze(j,e=>{let t=Object.create(Ml.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,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 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.y}function ol(j){j.zpp_inner.weak&&j.dispose()}var Zl=class j extends ln{constructor(e,t,n,s,i,l){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");let r=Kl(n),a=Yl(n);if(o.a1localx=r,o.a1localy=a,ol(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=Kl(s),c=Yl(s);if(o.a2localx=p,o.a2localy=c,ol(s),this.zpp_inner.immutable_midstep("DistanceJoint::jointMin"),i!==i)throw new Error("Error: DistanceJoint::jointMin cannot be NaN");if(i<0)throw new Error("Error: DistanceJoint::jointMin must be >= 0");if(o.jointMin!=i&&(o.jointMin=i,o.wake()),this.zpp_inner.immutable_midstep("DistanceJoint::jointMax"),l!==l)throw new Error("Error: DistanceJoint::jointMax cannot be NaN");if(l<0)throw new Error("Error: DistanceJoint::jointMax must be >= 0");o.jointMax!=l&&(o.jointMax=l,o.wake())}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof _i?Ze(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(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:tt._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:tt._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),ol(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),ol(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}};_i._wrapFn=j=>Ze(j,e=>{let t=Object.create(Zl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,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 ln{constructor(e,t,n,s,i,l,o){super();let r=new di;if(this.zpp_inner=r,r.outer=this,r.outer_zn=this,this._setBody1(e),this._setBody2(t),n?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(n==null)throw new Error("Error: Constraint::anchor1 cannot be null");if(r.a1localx=kl(n),r.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(r.a2localx=kl(s),r.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(r.nlocalx=kl(i),r.nlocaly=El(i),r.zip_n=!0,ds(i),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),l!==l)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(r.jointMin!=l&&(r.jointMin=l,r.wake()),this.zpp_inner.immutable_midstep("LineJoint::jointMax"),o!==o)throw new Error("Error: AngleJoint::jointMax cannot be NaN");r.jointMax!=o&&(r.jointMax=o,r.wake())}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof di?Ze(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(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:tt._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:tt._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}};di._wrapFn=j=>Ze(j,e=>{let t=Object.create(Nl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});var Ol=class j extends ln{constructor(e,t,n=0,s=1){super();let i=new yi;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 yi?Ze(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(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:tt._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:tt._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}};yi._wrapFn=j=>Ze(j,e=>{let t=Object.create(Ol.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,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 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 Sl=class j extends ln{constructor(e,t,n,s){super();let i=new mi;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=Hl(n),rl(n),s?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(s==null)throw new Error("Error: Constraint::anchor2 cannot be null");i.a2localx=Xl(s),i.a2localy=Hl(s),rl(s)}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof mi?Ze(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(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:tt._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:tt._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)}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}};mi._wrapFn=j=>Ze(j,e=>{let t=Object.create(Sl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});function Fs(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 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.y}function Rs(j){j.zpp_inner.weak&&j.dispose()}var Vl=class j extends ln{constructor(e,t,n,s,i,l,o,r,a,p,c=1){super();let h=new fi;if(this.zpp_inner=h,h.outer=this,h.outer_zn=this,this._setBody1(e),this._setBody2(t),this._setBody3(n),this._setBody4(s),this._setAnchorInit(i,"anchor1",(u,x)=>{h.a1localx=u,h.a1localy=x}),this._setAnchorInit(l,"anchor2",(u,x)=>{h.a2localx=u,h.a2localy=x}),this._setAnchorInit(o,"anchor3",(u,x)=>{h.a3localx=u,h.a3localy=x}),this._setAnchorInit(r,"anchor4",(u,x)=>{h.a4localx=u,h.a4localy=x}),h.immutable_midstep("PulleyJoint::jointMin"),a!==a)throw new Error("Error: PulleyJoint::jointMin cannot be NaN");if(a<0)throw new Error("Error: PulleyJoint::jointMin must be >= 0");if(h.jointMin!=a&&(h.jointMin=a,h.wake()),h.immutable_midstep("PulleyJoint::jointMax"),p!==p)throw new Error("Error: PulleyJoint::jointMax cannot be NaN");if(p<0)throw new Error("Error: PulleyJoint::jointMax must be >= 0");if(h.jointMax!=p&&(h.jointMax=p,h.wake()),h.immutable_midstep("PulleyJoint::ratio"),c!==c)throw new Error("Error: PulleyJoint::ratio cannot be NaN");h.ratio!=c&&(h.ratio=c,h.wake())}_setAnchorInit(e,t,n){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::"+t+" cannot be null");n(Fs(e),Gs(e)),Rs(e)}static _wrap(e){return e==null?null:e instanceof j?e:e.zpp_inner?.outer instanceof j?e.zpp_inner.outer:e instanceof fi?Ze(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(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:tt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}get body2(){return this.zpp_inner.b2==null?null:tt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}get body3(){return this.zpp_inner.b3==null?null:tt._wrap(this.zpp_inner.b3)}set body3(e){this._setBody3(e)}get body4(){return this.zpp_inner.b4==null?null:tt._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(),Fs(e),Gs(e),this.zpp_inner.wrap_a1.set(e),Rs(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(),Fs(e),Gs(e),this.zpp_inner.wrap_a2.set(e),Rs(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(),Fs(e),Gs(e),this.zpp_inner.wrap_a3.set(e),Rs(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(),Fs(e),Gs(e),this.zpp_inner.wrap_a4.set(e),Rs(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 Vs(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):ci.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}};fi._wrapFn=j=>Ze(j,e=>{let t=Object.create(Vl.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});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.x}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.y}function al(j){j.zpp_inner.weak&&j.dispose()}var Al=class j extends ln{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=Ql(n),l.a1localy=$l(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");if(l.a2localx=Ql(s),l.a2localy=$l(s),al(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?Ze(e,t=>{let n=Object.create(j.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(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:tt._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:tt._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)}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=>Ze(j,e=>{let t=Object.create(Al.prototype);return t.zpp_inner=e,e.outer=t,e.outer_zn=t,t.debugDraw=!0,t});export{U as a,xe as b,to as c,Tt as d,pn as e,Lt as f,Us as g,Ks as h,Ys as i,ts as j,Re as k,pe as l,_i as m,di as n,yi as o,mi as p,fi as q,Xs as r,bi as s,Ie as t,Pe as u,Zs as v,Ee as w,mn as x,ls as y,ks as z,Es as A,Hs as B,gn as C,rt as D,_e as E,el as F,Ze as G,lt as H,ci as I,Vs as J,Wi as K,dl as L,hs as M,Dl as N,Fl as O,Px as P,wx as Q,gi as R,tl as S,hi as T,yl as U,ti as V,Ci as W,xs as X,fl as Y,yo as Z,tt as _,zl as $,_s as aa,Pl as ba,wl as ca,vl as da,gl as ea,il as fa,sl as ga,ll as ha,Ul as ia,Cl as ja,ln as ka,Ml as la,Zl as ma,Nl as na,Ol as oa,Sl as pa,Vl as qa,Al as ra};
|
|
2
|
+
//# sourceMappingURL=chunk-XRRG6SPV.js.map
|