@newkrok/nape-js 3.10.3 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 a=t.data;t.data=i.data,i.data=a,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 a=t.data;t.data=i.data,i.data=a,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,a,r,p;t==n.prev?(l=n,p=n.next,e==t.prev?(s=e,i=t,o=e.prev,a=e.next,r=t.next):(s=t,i=e,o=t.prev,a=e.prev,r=e.next)):(s=n,o=n.prev,e==t.prev?(i=e,l=t,a=e.prev,r=e.next,p=t.next):(i=t,l=e,a=t.prev,r=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=a,a!=null&&(a.parent=s),i.prev=s,s!=null&&(s.parent=i),i.next=l,l!=null&&(l.parent=i),l.prev=r,r!=null&&(r.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(T){let e=class extends ms{};return e.zpp_pool=null,e}function We(T,e){let t=class extends _t{};return t._NodeClass=e,t}function ui(T){let e=class extends fs{};return e.zpp_pool=null,e}function jl(T){T.util||(T.util={}),T.util.ZNPNode_ZPP_CbType=qe("ZPP_CbType"),T.util.ZNPNode_ZPP_CallbackSet=qe("ZPP_CallbackSet"),T.util.ZNPNode_ZPP_Shape=qe("ZPP_Shape"),T.util.ZNPNode_ZPP_Body=qe("ZPP_Body"),T.util.ZNPNode_ZPP_Constraint=qe("ZPP_Constraint"),T.util.ZNPNode_ZPP_Compound=qe("ZPP_Compound"),T.util.ZNPNode_ZPP_Arbiter=qe("ZPP_Arbiter"),T.util.ZNPNode_ZPP_InteractionListener=qe("ZPP_InteractionListener"),T.util.ZNPNode_ZPP_CbSet=qe("ZPP_CbSet"),T.util.ZNPNode_ZPP_Interactor=qe("ZPP_Interactor"),T.util.ZNPNode_ZPP_BodyListener=qe("ZPP_BodyListener"),T.util.ZNPNode_ZPP_CbSetPair=qe("ZPP_CbSetPair"),T.util.ZNPNode_ZPP_ConstraintListener=qe("ZPP_ConstraintListener"),T.util.ZNPNode_ZPP_CutInt=qe("ZPP_CutInt"),T.util.ZNPNode_ZPP_CutVert=qe("ZPP_CutVert"),T.util.ZNPNode_ZPP_PartitionVertex=qe("ZPP_PartitionVertex"),T.util.ZNPNode_ZPP_SimplifyP=qe("ZPP_SimplifyP"),T.util.ZNPNode_ZPP_PartitionedPoly=qe("ZPP_PartitionedPoly"),T.util.ZNPNode_ZPP_GeomVert=qe("ZPP_GeomVert"),T.util.ZNPNode_ZPP_SimpleVert=qe("ZPP_SimpleVert"),T.util.ZNPNode_ZPP_SimpleEvent=qe("ZPP_SimpleEvent"),T.util.ZNPNode_ZPP_Vec2=qe("ZPP_Vec2"),T.util.ZNPNode_ZPP_AABBPair=qe("ZPP_AABBPair"),T.util.ZNPNode_ZPP_Edge=qe("ZPP_Edge"),T.util.ZNPNode_ZPP_AABBNode=qe("ZPP_AABBNode"),T.util.ZNPNode_ZPP_Component=qe("ZPP_Component"),T.util.ZNPNode_ZPP_FluidArbiter=qe("ZPP_FluidArbiter"),T.util.ZNPNode_ZPP_SensorArbiter=qe("ZPP_SensorArbiter"),T.util.ZNPNode_ZPP_Listener=qe("ZPP_Listener"),T.util.ZNPNode_ZPP_ColArbiter=qe("ZPP_ColArbiter"),T.util.ZNPNode_ZPP_InteractionGroup=qe("ZPP_InteractionGroup"),T.util.ZNPNode_ZPP_ToiEvent=qe("ZPP_ToiEvent"),T.util.ZNPNode_ConvexResult=qe("ConvexResult"),T.util.ZNPNode_ZPP_GeomPoly=qe("ZPP_GeomPoly"),T.util.ZNPNode_RayResult=qe("RayResult");let e=T.util;io=T.util.ZNPList_ZPP_InteractionListener=We("ZPP_InteractionListener",e.ZNPNode_ZPP_InteractionListener),so=T.util.ZNPList_ZPP_BodyListener=We("ZPP_BodyListener",e.ZNPNode_ZPP_BodyListener),lo=T.util.ZNPList_ZPP_ConstraintListener=We("ZPP_ConstraintListener",e.ZNPNode_ZPP_ConstraintListener),oo=T.util.ZNPList_ZPP_Constraint=We("ZPP_Constraint",e.ZNPNode_ZPP_Constraint),ro=T.util.ZNPList_ZPP_Interactor=We("ZPP_Interactor",e.ZNPNode_ZPP_Interactor),ao=T.util.ZNPList_ZPP_CbSet=We("ZPP_CbSet",e.ZNPNode_ZPP_CbSet),no=T.util.ZNPList_ZPP_CbType=We("ZPP_CbType",e.ZNPNode_ZPP_CbType),T.util.ZNPList_ZPP_Vec2=We("ZPP_Vec2",e.ZNPNode_ZPP_Vec2),to=T.util.ZNPList_ZPP_Vec2,T.util.ZNPList_ZPP_CallbackSet=We("ZPP_CallbackSet",e.ZNPNode_ZPP_CallbackSet),T.util.ZNPList_ZPP_Shape=We("ZPP_Shape",e.ZNPNode_ZPP_Shape),T.util.ZNPList_ZPP_Body=We("ZPP_Body",e.ZNPNode_ZPP_Body),T.util.ZNPList_ZPP_Compound=We("ZPP_Compound",e.ZNPNode_ZPP_Compound),T.util.ZNPList_ZPP_Arbiter=We("ZPP_Arbiter",e.ZNPNode_ZPP_Arbiter),po=T.util.ZNPList_ZPP_CbSetPair=We("ZPP_CbSetPair",e.ZNPNode_ZPP_CbSetPair),T.util.ZNPList_ZPP_CutInt=We("ZPP_CutInt",e.ZNPNode_ZPP_CutInt),T.util.ZNPList_ZPP_CutVert=We("ZPP_CutVert",e.ZNPNode_ZPP_CutVert),T.util.ZNPList_ZPP_PartitionVertex=We("ZPP_PartitionVertex",e.ZNPNode_ZPP_PartitionVertex),xi=T.util.ZNPList_ZPP_PartitionVertex,T.util.ZNPList_ZPP_SimplifyP=We("ZPP_SimplifyP",e.ZNPNode_ZPP_SimplifyP),ul=T.util.ZNPList_ZPP_SimplifyP,T.util.ZNPList_ZPP_PartitionedPoly=We("ZPP_PartitionedPoly",e.ZNPNode_ZPP_PartitionedPoly),Si=T.util.ZNPList_ZPP_PartitionedPoly,T.util.ZNPList_ZPP_GeomVert=We("ZPP_GeomVert",e.ZNPNode_ZPP_GeomVert),Fn=T.util.ZNPList_ZPP_GeomVert,T.util.ZNPList_ZPP_SimpleVert=We("ZPP_SimpleVert",e.ZNPNode_ZPP_SimpleVert),_l=T.util.ZNPList_ZPP_SimpleEvent=We("ZPP_SimpleEvent",e.ZNPNode_ZPP_SimpleEvent),T.util.ZNPList_ZPP_AABBPair=We("ZPP_AABBPair",e.ZNPNode_ZPP_AABBPair),T.util.ZNPList_ZPP_Edge=We("ZPP_Edge",e.ZNPNode_ZPP_Edge),T.util.ZNPList_ZPP_AABBNode=We("ZPP_AABBNode",e.ZNPNode_ZPP_AABBNode),T.util.ZNPList_ZPP_Component=We("ZPP_Component",e.ZNPNode_ZPP_Component),T.util.ZNPList_ZPP_FluidArbiter=We("ZPP_FluidArbiter",e.ZNPNode_ZPP_FluidArbiter),T.util.ZNPList_ZPP_SensorArbiter=We("ZPP_SensorArbiter",e.ZNPNode_ZPP_SensorArbiter),T.util.ZNPList_ZPP_Listener=We("ZPP_Listener",e.ZNPNode_ZPP_Listener),T.util.ZNPList_ZPP_ColArbiter=We("ZPP_ColArbiter",e.ZNPNode_ZPP_ColArbiter),T.util.ZNPList_ZPP_InteractionGroup=We("ZPP_InteractionGroup",e.ZNPNode_ZPP_InteractionGroup),T.util.ZNPList_ZPP_ToiEvent=We("ZPP_ToiEvent",e.ZNPNode_ZPP_ToiEvent),T.util.ZNPList_ConvexResult=We("ConvexResult",e.ZNPNode_ConvexResult),T.util.ZNPList_ZPP_GeomPoly=We("ZPP_GeomPoly",e.ZNPNode_ZPP_GeomPoly),T.util.ZNPList_RayResult=We("RayResult",e.ZNPNode_RayResult),Hi=T.util.ZNPNode_RayResult,xl=T.util.ZNPList_ZPP_SimpleVert,T.util.ZPP_Set_ZPP_Body=ui("ZPP_Body"),T.util.ZPP_Set_ZPP_CbSetPair=ui("ZPP_CbSetPair"),T.util.ZPP_Set_ZPP_PartitionVertex=ui("ZPP_PartitionVertex"),$i=T.util.ZPP_Set_ZPP_PartitionVertex,T.util.ZPP_Set_ZPP_PartitionPair=ui("ZPP_PartitionPair"),es=T.util.ZPP_Set_ZPP_PartitionPair,T.util.ZPP_Set_ZPP_SimpleVert=ui("ZPP_SimpleVert"),$t=T.util.ZPP_Set_ZPP_SimpleVert,T.util.ZPP_Set_ZPP_SimpleSeg=ui("ZPP_SimpleSeg"),Qi=T.util.ZPP_Set_ZPP_SimpleSeg,T.util.ZPP_Set_ZPP_SimpleEvent=ui("ZPP_SimpleEvent"),Un=T.util.ZPP_Set_ZPP_SimpleEvent,T.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,a=n.cbTypes;s=o.nonemptyintersection(a,o.includes)&&!o.nonemptyintersection(a,o.excludes)}else s=!1;if(s)return!0;{let o=e.options2,a=t.cbTypes;if(o.nonemptyintersection(a,o.includes)&&!o.nonemptyintersection(a,o.excludes)){let r=e.options1,p=n.cbTypes;return r.nonemptyintersection(p,r.includes)?!r.nonemptyintersection(p,r.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 a;if(i!=null){let r=i.elt;a=o.precedence>r.precedence||o.precedence==r.precedence&&o.id>r.id}else a=!0;if(a){if(o.space==this.manager.space){let r=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=r.head,r.head=c):(c.next=s.next,s.next=c),r.pushmod=r.modified=!0,r.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 a;if(i!=null){let r=i.elt;a=o.precedence>r.precedence||o.precedence==r.precedence&&o.id>r.id}else a=!0;if(a){let r=o.options;if(!r.nonemptyintersection(this.cbTypes,r.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 a;if(i!=null){let r=i.elt;a=o.precedence>r.precedence||o.precedence==r.precedence&&o.id>r.id}else a=!0;if(a){let r=o.options;if(!r.nonemptyintersection(this.cbTypes,r.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,a=this.b.cbTypes;return o.nonemptyintersection(a,o.includes)?!o.nonemptyintersection(a,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,a=this.a.cbTypes;if(o.nonemptyintersection(a,o.includes)&&!o.nonemptyintersection(a,o.excludes)){let r=n.options2,p=this.b.cbTypes;l=r.nonemptyintersection(p,r.includes)&&!r.nonemptyintersection(p,r.excludes)}else l=!1;if(l)i=!0;else{let r=n.options2,p=this.a.cbTypes;if(r.nonemptyintersection(p,r.includes)&&!r.nonemptyintersection(p,r.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 a=s.elt;if(e.precedence>a.precedence||e.precedence===a.precedence&&e.id>a.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 a=s.elt;if(e.precedence>a.precedence||e.precedence===a.precedence&&e.id>a.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 a=s.elt;if(e.precedence>a.precedence||e.precedence===a.precedence&&e.id>a.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,a;t.util.ZNPNode_ZPP_BodyListener.zpp_pool==null?a=new t.util.ZNPNode_ZPP_BodyListener:(a=t.util.ZNPNode_ZPP_BodyListener.zpp_pool,t.util.ZNPNode_ZPP_BodyListener.zpp_pool=a.next,a.next=null),a.elt=this;let r=a;i==null?(r.next=o.head,o.head=r):(r.next=i.next,i.next=r),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,a;t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool==null?a=new t.util.ZNPNode_ZPP_ConstraintListener:(a=t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool,t.util.ZNPNode_ZPP_ConstraintListener.zpp_pool=a.next,a.next=null),a.elt=this;let r=a;i==null?(r.next=o.head,o.head=r):(r.next=i.next,i.next=r),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,a=Ct.WCbSet,r=t.head,p=n.head;for(;r!=null&&p!=null;){let c=r.elt,h=p.elt;if(c==h){let u=this._allocCbSetNode(i);u.elt=c,u.next=a.head,a.head=u,a.modified=!0,a.length++,r=r.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++,r=r.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(;r!=null;){let c=this._allocCbSetNode(i);c.elt=r.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,r=r.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=a.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;a.head!=null;){let c=a.pop_unsafe();s(c,c);let h=a.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,a=Ct.WCbType,r=t.head,p=n.head;for(;r!=null&&p!=null;){let c=r.elt,h=p.elt;if(c==h){let u=this._allocCbTypeNode(i);u.elt=c,u.next=a.head,a.head=u,a.modified=!0,a.length++,r=r.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++,r=r.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(;r!=null;){let c=this._allocCbTypeNode(i);c.elt=r.elt,c.next=l.head,l.head=c,l.modified=!0,l.length++,r=r.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=a.head;for(;h!=null;)s(c,h.elt),h=h.next}for(;a.head!=null;){let c=a.pop_unsafe();s(c,c);let h=a.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,(a,r)=>{if(a.validate(),r.validate(),n.callbacks.ZPP_CbSet.single_intersection(a,r,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(a,r)?(p.a=a,p.b=r):(p.a=r,p.b=a),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 a=o;a.a=a.b=null,a.listeners.clear(),a.next=n.callbacks.ZPP_CbSetPair.zpp_pool,n.callbacks.ZPP_CbSetPair.zpp_pool=a;let r=l.parent;r!=null&&(l==r.prev?r.prev=null:r.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=r}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,a;t.util.ZNPNode_ZPP_InteractionListener.zpp_pool==null?a=new t.util.ZNPNode_ZPP_InteractionListener:(a=t.util.ZNPNode_ZPP_InteractionListener.zpp_pool,t.util.ZNPNode_ZPP_InteractionListener.zpp_pool=a.next,a.next=null),a.elt=this;let r=a;i==null?(r.next=o.head,o.head=r):(r.next=i.next,i.next=r),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 a;if(i.zpp_i<o?a=!0:(i.zpp_next=n.callbacks.CbTypeIterator.zpp_pool,n.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,a=!1),!a)break;i.zpp_critical=!1;let r=i.zpp_inner.at(i.zpp_i++);this.append_type(e,r.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 a=s.elt;if(e.id<a.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 y=i.zpp_inner;y.zpp_inner.valmod(),y.zpp_inner.zip_length&&(y.zpp_inner.zip_length=!1,y.zpp_inner.user_length=y.zpp_inner.inner.length);let _=y.zpp_inner.user_length;i.zpp_critical=!0;let d;if(i.zpp_i<_?d=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,d=!1),!d)break;i.zpp_critical=!1;let f=i.zpp_inner.at(i.zpp_i++);e.zpp_inner.wrap_cbTypes==null&&e.zpp_inner.setupcbTypes();let z=e.zpp_inner.wrap_cbTypes;z.zpp_inner.reverse_flag?z.push(f):z.unshift(f)}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 a=n.zpp_inner.maxError;if(a!==a)throw new Error("Error: Constraint::maxError cannot be NaN");if(a<0)throw new Error("Error: Constraint::maxError must be >=0");e.zpp_inner.maxError!=a&&(e.zpp_inner.maxError=a,e.zpp_inner.wake());let r=n.zpp_inner.maxForce;if(r!==r)throw new Error("Error: Constraint::maxForce cannot be NaN");if(r<0)throw new Error("Error: Constraint::maxForce must be >=0");e.zpp_inner.maxForce!=r&&(e.zpp_inner.maxForce=r,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 T{constructor(){this.id=0;this.bc=null;this.cb=null}static dict(e,t){let n=new T;return n.id=e,n.bc=t,n}static todo(e,t){let n=new T;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),a=t*l*l*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-i*a,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,a=-this.scale*l*this.b1.iinertia;if(o.rot+=a,a*a>1e-4)o.axisx=Math.sin(o.rot),o.axisy=Math.cos(o.rot);else{let c=a*a,h=1-.5*c,u=1-c*c/8,x=(h*o.axisx+a*o.axisy)*u;o.axisy=(h*o.axisy-a*o.axisx)*u,o.axisx=x}let r=this.b2,p=this.ratio*this.scale*l*this.b2.iinertia;if(r.rot+=p,p*p>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let c=p*p,h=1-.5*c,u=1-c*c/8,x=(h*r.axisx+p*r.axisy)*u;r.axisy=(h*r.axisy-p*r.axisx)*u,r.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 a=0;a<t.length;a++){let r=t[a];if(r.id==s.id){o=r.bc;break}}o!=null?i.zpp_inner_zn[l]=o.zpp_inner:n.push(Rn.todo(s.id,function(a){i.zpp_inner_zn[l]=a.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 le=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),a=t*l*l*this.gamma;this.gamma*=o,this.kMass*=o,this.bias=-i*a,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,a=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s),p=a*a+r*r;if(p<Me._nape.Config.epsilon)a=0,r=0,p=0,o=!0;else{p=Math.sqrt(p);let h=1/p;a*=h,r*=h,this.equal?(p-=this.jointMax,o=!1):p<this.jointMin?(p=this.jointMin-p,a=-a,r=-r,o=!1):p>this.jointMax?(p-=this.jointMax,o=!1):(a=0,r=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 y=this.b1.smass+this.b2.smass;if(y>Me._nape.Config.epsilon){let _=.75/y;if(t=-c*_,this.equal||t<0){let d=t*this.b1.imass;this.b1.posx-=a*d,this.b1.posy-=r*d;let f=t*this.b2.imass;this.b2.posx+=a*f,this.b2.posy+=r*f,a=this.b2.posx+i-(this.b1.posx+n),r=this.b2.posy+l-(this.b1.posy+s);let z=a*a+r*r;if(z<Me._nape.Config.epsilon)a=0,r=0,z=0;else{z=Math.sqrt(z);let P=1/z;a*=P,r*=P,this.equal?z-=this.jointMax:z<this.jointMin?(z=this.jointMin-z,a=-a,r=-r):z>this.jointMax?z-=this.jointMax:(a=0,r=0,z=0)}c=z,c*=.5}}}let h=r*n-a*s,u=r*i-a*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 y=this.b1.imass*t;this.b1.posx-=a*y,this.b1.posy-=r*y;let _=this.b2.imass*t;this.b2.posx+=a*_,this.b2.posy+=r*_,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,a=n;if(a==null&&(a=0),o==null&&(o=0),o!=o||a!=a)throw new Error("Error: Vec2 components cannot be NaN");let r;if(xe.poolVec2==null?r=new l.geom.Vec2:(r=xe.poolVec2,xe.poolVec2=r.zpp_pool,r.zpp_pool=null,r.zpp_disp=!1,r==xe.nextVec2&&(xe.nextVec2=null)),r.zpp_inner==null){let p;le.zpp_pool==null?p=new le:(p=le.zpp_pool,le.zpp_pool=p.next,p.next=null),p.weak=!1,p._immutable=!1,p.x=o,p.y=a,r.zpp_inner=p,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 p=r.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(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=r.zpp_inner;if(h._validate!=null&&h._validate(),r.zpp_inner.x==o){if(r!=null&&r.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let u=r.zpp_inner;u._validate!=null&&u._validate(),c=r.zpp_inner.y==a}else c=!1;if(!c){r.zpp_inner.x=o,r.zpp_inner.y=a;let u=r.zpp_inner;u._invalidate!=null&&u._invalidate(u)}}return r.zpp_inner.weak=!1,r.zpp_inner._inuse=!0,r.zpp_inner._validate=s,r.zpp_inner._invalidate=i,r}};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 a;if(o.util.ZPP_PubPool.poolVec2==null?a=new l.geom.Vec2:(a=o.util.ZPP_PubPool.poolVec2,o.util.ZPP_PubPool.poolVec2=a.zpp_pool,a.zpp_pool=null,a.zpp_disp=!1,a==o.util.ZPP_PubPool.nextVec2&&(o.util.ZPP_PubPool.nextVec2=null)),a.zpp_inner==null){let r;o.geom.ZPP_Vec2.zpp_pool==null?r=new o.geom.ZPP_Vec2:(r=o.geom.ZPP_Vec2.zpp_pool,o.geom.ZPP_Vec2.zpp_pool=r.next,r.next=null),r.weak=!1,r._immutable=!1,r.x=t,r.y=n,a.zpp_inner=r,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 r=a.zpp_inner;if(r._immutable)throw new Error("Error: Vec2 is immutable");if(r._isimmutable!=null&&r._isimmutable(),t!==t||n!==n)throw new Error("Error: Vec2 components cannot be NaN");if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let p=a.zpp_inner;p._validate!=null&&p._validate();let c;if(a.zpp_inner.x==t){if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let h=a.zpp_inner;h._validate!=null&&h._validate(),c=a.zpp_inner.y==n}else c=!1;if(!c){a.zpp_inner.x=t,a.zpp_inner.y=n;let h=a.zpp_inner;h._invalidate!=null&&h._invalidate(h)}}return a.zpp_inner.weak=!1,a.zpp_inner._inuse=!0,a.zpp_inner._validate=s,a.zpp_inner._invalidate=i,a}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,a=this.outer_zn;a.zpp_inner_zn.wrap_n==null&&a.zpp_inner_zn.setup_n();let r=zs._createFn(null,null,i,o,a.zpp_inner_zn.wrap_n,this.jointMin,this.jointMax);return this.copyto(r),Re._copyBody(t,n,this.b1,r,"b1"),Re._copyBody(t,n,this.b2,r,"b2"),r}validate(){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 a=s+this.a1relx,r=i+this.a1rely;this.dot1=this.nrelx*a+this.nrely*r,this.cx1=r*this.nrelx-a*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),y=t*u*u*this.gamma;this.gamma*=x;let _=x;this.kMassa*=_,this.kMassb*=_,this.kMassc*=_,this.biasx=l,this.biasy=o;let d=-y;this.biasx*=d,this.biasy*=d;let f=this.maxError,z=this.biasx*this.biasx+this.biasy*this.biasy;if(z>f*f){let P=f*(1/Math.sqrt(z));this.biasx*=P,this.biasy*=P}}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,a=this.kMassa*l+this.kMassb*o;o=this.kMassb*l+this.kMassc*o,l=a;let r=this.gamma;l-=this.jAccx*r,o-=this.jAccy*r;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 f=this.jMax,z=this.jAccx*this.jAccx+this.jAccy*this.jAccy;if(z>f*f){let P=f*(1/Math.sqrt(z));this.jAccx*=P,this.jAccy*=P}}let h=this.jAccx-p,u=this.jAccy-c,x=this.scale*this.nrelx*u-this.nrely*h,y=this.nrelx*h+this.scale*this.nrely*u,_=this.b1.imass;this.b1.velx-=x*_,this.b1.vely-=y*_;let d=this.b2.imass;return this.b2.velx+=x*d,this.b2.vely+=y*d,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,a=this.a2localx*this.b2.axisx+this.a2localy*this.b2.axisy,r=this.b2.posx+o-this.b1.posx-i,p=this.b2.posy+a-this.b1.posy-l,c,h=p*n-r*s,u=n*r+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,y,_=.5;if(h*=_,u*=_,h*h+u*u>6){let M=this.b1.smass+this.b2.smass;if(M>t.Config.epsilon){let N=.8/M,S=N*(s*h-c*n*u),D=N*(n*h*c-s*h),j=this.b1.imass;this.b1.posx-=S*j,this.b1.posy-=D*j;let R=this.b2.imass;this.b2.posx+=S*R,this.b2.posy+=D*R,r=this.b2.posx+o-this.b1.posx-i,p=this.b2.posy+a-this.b1.posy-l,h=p*n-r*s,u=n*r+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 d=r+i,f=p+l,z=n*d+s*f,P=f*n-d*s,Z=n*o+s*a,m=a*n-o*s,b=this.b1.smass+this.b2.smass+z*z*this.b1.sinertia+Z*Z*this.b2.sinertia,C=-c*(z*P*this.b1.sinertia+Z*m*this.b2.sinertia),v=c*c*(this.b1.smass+this.b2.smass+P*P*this.b1.sinertia+m*m*this.b2.sinertia);x=-h,y=-u;let w=b*v-C*C;if(w!==w)y=0,x=y;else if(w==0)b!=0?x/=b:x=0,v!=0?y/=v:y=0;else{let M=1/w,N=M*(v*x-C*y);y=M*(b*y-C*x),x=N}y>0&&(y=0);let O=c*n*y-s*x,k=n*x+c*s*y,g=this.b1.imass;this.b1.posx-=O*g,this.b1.posy-=k*g;let E=this.b2.imass;return this.b2.posx+=O*E,this.b2.posy+=k*E,Re._rotateBody(this.b1,(c*P*y-z*x)*this.b1.iinertia),Re._rotateBody(this.b2,(Z*x-c*m*y)*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 a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==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(),a=l.zpp_inner.y==i}else a=!1;if(!a){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 a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==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(),a=l.zpp_inner.y==i}else a=!1;if(!a){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 a=this.a1relx*this.b1.sinertia,r=this.a1rely*this.b1.sinertia;this.kMassa+=r*this.a1rely,this.kMassb+=-r*this.a1relx,this.kMassc+=a*this.a1relx}if(this.b2.sinertia!=0){let a=this.a2relx*this.b2.sinertia,r=this.a2rely*this.b2.sinertia;this.kMassa+=r*this.a2rely,this.kMassb+=-r*this.a2relx,this.kMassc+=a*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 a=0;this.kMassa!=0?this.kMassa=1/this.kMassa:(this.kMassa=0,a|=1),this.kMassc!=0?this.kMassc=1/this.kMassc:(this.kMassc=0,a|=2),this.kMassb=0,l=a}else{let a=1/i,r=this.kMassc*a;this.kMassc=this.kMassa*a,this.kMassa=r,this.kMassb*=-a,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 a=2*Math.PI*this.frequency;this.gamma=1/(t*a*(2*this.damping+a*t));let r=1/(1+this.gamma),p=t*a*a*this.gamma;this.gamma*=r;let c=r;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 y=u*(1/Math.sqrt(x));this.biasx*=y,this.biasy*=y}}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 a=this.jAccx,r=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 y=u*(1/Math.sqrt(x));this.jAccx*=y,this.jAccy*=y}}s=this.jAccx-a,i=this.jAccy-r;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),a=this.b2.posy+l-(this.b1.posy+s);if(this.breakUnderError&&o*o+a*a>this.maxError*this.maxError)return!0;if(o*o+a*a<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;let r=.5;o*=r,a*=r;let p,c;if(o*o+a*a>6){let b=this.b1.smass+this.b2.smass;if(b>t.Config.epsilon){let C=.75/b;p=-o*C,c=-a*C;let v=20,w=p*p+c*c;if(w>v*v){let E=v*(1/Math.sqrt(w));p*=E,c*=E}let O=this.b1.imass;this.b1.posx-=p*O,this.b1.posy-=c*O;let k=this.b2.imass;this.b2.posx+=p*k,this.b2.posy+=c*k,o=this.b2.posx+i-(this.b1.posx+n),a=this.b2.posy+l-(this.b1.posy+s);let g=.5;o*=g,a*=g}}let h=this.b1.smass+this.b2.smass,u=h,x=0,y=h;if(this.b1.sinertia!=0){let b=n*this.b1.sinertia,C=s*this.b1.sinertia;u+=C*s,x+=-C*n,y+=b*n}if(this.b2.sinertia!=0){let b=i*this.b2.sinertia,C=l*this.b2.sinertia;u+=C*l,x+=-C*i,y+=b*i}p=-o,c=-a;let _=6,d=p*p+c*c;if(d>_*_){let b=_*(1/Math.sqrt(d));p*=b,c*=b}let f=u*y-x*x;if(f!=f)c=0,p=0;else if(f==0)u!=0?p/=u:p=0,y!=0?c/=y:c=0;else{let b=1/f,C=b*(y*p-x*c);c=b*(u*c-x*p),p=C}let z=this.b1.imass;this.b1.posx-=p*z,this.b1.posy-=c*z;let P=this.b2.imass;this.b2.posx+=p*P,this.b2.posy+=c*P;let Z=-(c*n-p*s)*this.b1.iinertia;Re._rotateBody(this.b1,Z);let m=(c*i-p*l)*this.b2.iinertia;return Re._rotateBody(this.b2,m),!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),a=Math.sqrt(i*i+l*l),r=o+this.ratio*a;return this.equal||r<this.jointMin||r>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 a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==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(),a=l.zpp_inner.y==i}else a=!1;if(!a){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 a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==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(),a=l.zpp_inner.y==i}else a=!1;if(!a){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 a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==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(),a=l.zpp_inner.y==i}else a=!1;if(!a){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 a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==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(),a=l.zpp_inner.y==i}else a=!1;if(!a){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,a=this.outer_zn;a.zpp_inner_zn.wrap_a3==null&&a.zpp_inner_zn.setup_a3();let r=a.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,r,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),a=Math.sqrt(s*s+i*i),r=Math.sqrt(l*l+o*o);if(a!=0){let h=1/a;this.n12x=s*h,this.n12y=i*h}if(r!=0){let h=1/r;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=a+this.ratio*r;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 y=1/(1+this.gamma),_=t*x*x*this.gamma;this.gamma*=y,this.kMass*=y,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 a=this.b4.imass*n;return this.b4.velx+=this.n34x*a,this.b4.vely+=this.n34y*a,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,a=this.b3.axisy*this.a3localx-this.b3.axisx*this.a3localy,r=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,y=this.n34x,_=this.n34y,d=this.b2.posx+l-(this.b1.posx+s),f=this.b2.posy+o-(this.b1.posy+i),z=this.b4.posx+p-(this.b3.posx+a),P=this.b4.posy+c-(this.b3.posy+r),Z=Math.sqrt(d*d+f*f),m=Math.sqrt(z*z+P*P);if(Z!=0){let v=1/Z;u=d*v,x=f*v}if(m!=0){let v=1/m;y=z*v,_=P*v;let w=this.ratio;y*=w,_*=w}else{let v=this.ratio/Math.sqrt(y*y+_*_);y*=v,_*=v}let b=Z+this.ratio*m;this.equal?(b-=this.jointMax,h=!1):b<this.jointMin?(b=this.jointMin-b,u=-u,x=-x,y=-y,_=-_,h=!1):b>this.jointMax?(b-=this.jointMax,h=!1):(u=0,x=0,y=0,_=0,b=0,h=!0);let C=b;if(!h){if(this.breakUnderError&&C*C>this.maxError*this.maxError)return!0;if(C*C<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop)return!1;if(C*=.5,C*C>6){let N=this.b1.smass+this.b2.smass;if(N>t.Config.epsilon){let S=.75/N;if(n=-C*S,this.equal||n<0){let D=n*this.b1.imass;this.b1.posx-=u*D,this.b1.posy-=x*D;let j=n*this.b2.imass;this.b2.posx+=u*j,this.b2.posy+=x*j;let R=n*this.b3.imass;this.b3.posx-=y*R,this.b3.posy-=_*R;let q=n*this.b4.imass;this.b4.posx+=y*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+a),Y=this.b4.posy+c-(this.b3.posy+r),$=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;y=V*ee,_=Y*ee;let W=this.ratio;y*=W,_*=W}else{let ee=this.ratio/Math.sqrt(y*y+_*_);y*=ee,_*=ee}let H=$+this.ratio*X;this.equal?H-=this.jointMax:H<this.jointMin?(H=this.jointMin-H,u=-u,x=-x,y=-y,_=-_):H>this.jointMax?H-=this.jointMax:(u=0,x=0,y=0,_=0,H=0),C=H,C*=.5}}}let v=x*s-u*i,w=x*l-u*o,O=_*a-y*r,k=_*p-y*c,g=this.ratio*this.ratio,E=this.b1.smass+this.b2.smass+g*(this.b3.smass+this.b4.smass)+this.b1.sinertia*v*v+this.b2.sinertia*w*w+this.b3.sinertia*O*O+this.b4.sinertia*k*k;this.b1==this.b4&&(E-=2*((u*y+x*_)*this.b1.smass+v*k*this.b1.sinertia)),this.b1==this.b3&&(E+=2*((u*y+x*_)*this.b1.smass+v*O*this.b1.sinertia)),this.b2==this.b3&&(E-=2*((u*y+x*_)*this.b2.smass+w*O*this.b2.sinertia)),this.b2==this.b4&&(E+=2*((u*y+x*_)*this.b2.smass+w*k*this.b2.sinertia));let M=E;if(M!=0&&(M=1/M),n=-C*M,this.equal||n<0){let N=this.b1.imass*n;this.b1.posx-=u*N,this.b1.posy-=x*N;let S=this.b2.imass*n;this.b2.posx+=u*S,this.b2.posy+=x*S;let D=this.b3.imass*n;this.b3.posx-=y*D,this.b3.posy-=_*D;let j=this.b4.imass*n;this.b4.posx+=y*j,this.b4.posy+=_*j,Re._rotateBody(this.b1,-v*this.b1.iinertia*n),Re._rotateBody(this.b2,w*this.b2.iinertia*n),Re._rotateBody(this.b3,-O*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 a=l+1;a<i;a++){let r=this.bodies[a].body;if(o.id===t&&r.id===n||o.id===n&&r.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 a=0;for(let r=0;r<s-1;r++)a+=this.L[o*this.dim+r]*this.L[s*this.dim+r];this.L[o*this.dim+s]=l*(t[n++]-a)}}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 a=i+1;a<this.dim;a++)o-=t[a*this.dim+i]*n[a];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 a=o.zpp_inner;a._validate!=null&&a._validate(),i.velx=l+o.zpp_inner.x*s;let r=n,p=r.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(),r.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,y=this.vec3;if(y!=null&&y.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=y.zpp_inner;_._validate!=null&&_._validate(),u.angvel=x+y.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 a=o.zpp_inner;a._validate!=null&&a._validate(),i.velx=l+o.zpp_inner.x*s;let r=n,p=r.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(),r.vely=p+c.zpp_inner.y*s;let u=n,x=u.angvel,y=this.vec3;if(y!=null&&y.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let _=y.zpp_inner;_._validate!=null&&_._validate(),u.angvel=x+y.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,a=this.vec3;if(a!=null&&a.zpp_disp)throw new Error("Error: Vec3 has been disposed and cannot be used!");let r=a.zpp_inner;r._validate!=null&&r._validate(),l.posx=o+a.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 y=x.zpp_inner;y._validate!=null&&y._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 d=_*_,f=1-.5*d,z=1-d*d/8,P=(f*s.axisx+_*s.axisy)*z;s.axisy=(f*s.axisy-_*s.axisx)*z,s.axisx=P}}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 a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==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(),a=l.zpp_inner.y==i}else a=!1;if(!a){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 a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==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(),a=l.zpp_inner.y==i}else a=!1;if(!a){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,a=this.a1rely*this.b1.sinertia;this.kMassa+=a*this.a1rely,this.kMassb+=-a*this.a1relx,this.kMassd+=o*this.a1relx,this.kMassc+=-a,this.kMasse+=o,this.kMassf+=this.b1.sinertia}if(this.b2.sinertia!=0){let o=this.a2relx*this.b2.sinertia,a=this.a2rely*this.b2.sinertia;this.kMassa+=a*this.a2rely,this.kMassb+=-a*this.a2relx,this.kMassd+=o*this.a2relx,this.kMassc+=-a,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,a=o*(this.kMassd*this.kMassf-this.kMasse*this.kMasse),r=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=a,this.kMassb=r,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 a=1/(1+this.gamma),r=t*o*o*this.gamma;this.gamma*=a;let p=a;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=-r;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,a=this.kMassa*i+this.kMassb*l+this.kMassc*o,r=this.kMassb*i+this.kMassd*l+this.kMasse*o;o=this.kMassc*i+this.kMasse*l+this.kMassf*o,i=a,l=r,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 y=this.jMax,_=this.jAccx*this.jAccx+this.jAccy*this.jAccy+this.jAccz*this.jAccz;if(_>y*y){let d=y*(1/Math.sqrt(_));this.jAccx*=d,this.jAccy*=d,this.jAccz*=d}}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),a=this.b2.posy+l-(this.b1.posy+s),r=this.b2.rot-this.b1.rot-this.phase,p,c,h;if(this.breakUnderError&&o*o+a*a+r*r>this.maxError*this.maxError)return!0;let u=!0;o*o+a*a<t.Config.constraintLinearSlop*t.Config.constraintLinearSlop&&(u=!1,o=0,a=0);let x=t.Config.constraintAngularSlop;if(r*r<x*x)if(u)r=0;else return!1;if(o*=.5,a*=.5,r*=.5,o*o+a*a>6){let S=this.b1.smass+this.b2.smass;if(S>t.Config.epsilon){let D=.75/S;p=-o*D,c=-a*D;let j=20,R=p*p+c*c;if(R>j*j){let B=j*(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),a=this.b2.posy+l-(this.b1.posy+s),r=this.b2.rot-this.b1.rot-this.phase,o*=.5,a*=.5,r*=.5}}let y=this.b1.smass+this.b2.smass,_=y,d=0,f=y,z=0,P=0,Z=0;if(this.b1.sinertia!=0){let S=n*this.b1.sinertia,D=s*this.b1.sinertia;_+=D*s,d+=-D*n,f+=S*n,z+=-D,P+=S,Z+=this.b1.sinertia}if(this.b2.sinertia!=0){let S=i*this.b2.sinertia,D=l*this.b2.sinertia;_+=D*l,d+=-D*i,f+=S*i,z+=-D,P+=S,Z+=this.b2.sinertia}p=-o,c=-a,h=-r;let m=6,b=p*p+c*c;if(b>m*m){let S=m*(1/Math.sqrt(b));p*=S,c*=S}let v=h<-.25,w=_*(f*Z-P*P)+d*(z*P-d*Z)+z*(d*P-z*f);if(w!=w)h=0,c=h,p=c;else if(w==0)_!=0?p/=_:p=0,f!=0?c/=f:c=0,Z!=0?h/=Z:h=0;else{let S=1/w,D=P*z-d*Z,j=d*P-z*f,R=d*z-_*P,q=S*(p*(f*Z-P*P)+c*D+h*j),G=S*(p*D+c*(_*Z-z*z)+h*R);h=S*(p*j+c*R+h*(_*f-d*d)),p=q,c=G}let O=this.b1.imass;this.b1.posx-=p*O,this.b1.posy-=c*O;let k=this.b2.imass;this.b2.posx+=p*k,this.b2.posy+=c*k;let g=this.b1,E=-(c*n-p*s+h)*this.b1.iinertia;Re._rotateBody(g,E);let M=this.b2,N=(c*i-p*l+h)*this.b2.iinertia;return Re._rotateBody(M,N),!1}draw(t){}};gs._wrapFn=null,gs._createFn=null;var bi=gs;var it=class it{constructor(){this.outer=null;this.hnext=null;this.id=0;this.di=0;this.stamp=0;this.up_stamp=0;this.sleep_stamp=0;this.endGenerated=0;this.active=!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()),it.types=[null,t.ArbiterType_COLLISION,t.ArbiterType_SENSOR,null,t.ArbiterType_FLUID]}wrapper(){if(this.outer==null){let e=it._nape;it.internal=!0,this.type==it.COL?(this.colarb.outer_zn=it._createColArb(),this.outer=this.colarb.outer_zn):this.type==it.FLUID?(this.fluidarb.outer_zn=it._createFluidArb(),this.outer=this.fluidarb.outer_zn):this.outer=new e.dynamics.Arbiter,this.outer.zpp_inner=this,it.internal=!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=it._zpp;this.cleared=!0,(t==null||this.b2==t)&&it._removeFromArbiterList(this.b1.arbiters,this,n),(t==null||this.b1==t)&&it._removeFromArbiterList(this.b2.arbiters,this,n),this.pair!=null&&(this.pair.arb=null,this.pair=null),this.active=!1,e.f_arbiters.modified=!0}sup_assign(e,t,n,s){let i=it._zpp;this.b1=e.body,this.ws1=e,this.b2=t.body,this.ws2=t,this.id=n,this.di=s,it._addToArbiterList(this.b1.arbiters,this,i),it._addToArbiterList(this.b2.arbiters,this,i),this.active=!0,this.present=0,this.cleared=!1,this.sleeping=!1,this.fresh=!1,this.presentable=!1}sup_retire(){let e=it._zpp;this.cleared||(it._removeFromArbiterList(this.b1.arbiters,this,e),it._removeFromArbiterList(this.b2.arbiters,this,e),this.pair!=null&&(this.pair.arb=null,this.pair=null)),this.b1=this.b2=null,this.active=!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 a=l;a.elt=null,a.next=n.util.ZNPNode_ZPP_Arbiter.zpp_pool,n.util.ZNPNode_ZPP_Arbiter.zpp_pool=a,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++}};it._nape=null,it._zpp=null,it.internal=!1,it._createColArb=null,it._createFluidArb=null,it.COL=1,it.FLUID=4,it.SENSOR=2,it.types=[];var Ie=it;var Cs=class Cs extends Ie{constructor(){super(),this.next=null,this.type=Ie.SENSOR,this.sensorarb=this}alloc(){}free(){}assign(e,t,n,s){this.sup_assign(e,t,n,s)}retire(){this.sup_retire(),this.next=Cs.zpp_pool,Cs.zpp_pool=this}makemutable(){}makeimmutable(){}};Cs.zpp_pool=null;var Ot=Cs;var Ms=class Ms extends Ie{constructor(){super();this.outer_zn=null;this.centroidx=0;this.centroidy=0;this.overlap=0;this.r1x=0;this.r1y=0;this.r2x=0;this.r2y=0;this.nodrag=!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 a=s.zpp_inner;a._validate!=null&&a._validate(),l=s.zpp_inner.y==0}else l=!1;if(!l){s.zpp_inner.x=0,s.zpp_inner.y=0;let a=s.zpp_inner;a._invalidate!=null&&a._invalidate(a)}}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 a,r;this.ws2.fluidEnabled&&this.ws2.fluidProperties.wrap_gravity!=null?(a=this.ws2.fluidProperties.gravityx,r=this.ws2.fluidProperties.gravityy):(a=t.gravityx,r=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+=a*x,c+=r*x}else{let x=l+a,y=o+r,_=.5;if(x*=_,y*=_,this.ws1.worldCOMx*x+this.ws1.worldCOMy*y>this.ws2.worldCOMx*x+this.ws2.worldCOMy*y){let d=h+u;p-=x*d,c-=y*d}else{let d=h+u;p+=x*d,c+=y*d}}}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+=a*h,c+=r*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 d=2*Math.PI*h;this.agamma=1/(n*d*(2+d*n));let f=1/(1+this.agamma);this.agamma*=f,this.wMass*=f}else this.wMass=0,this.agamma=0;let 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,d=1/Math.sqrt(_);this.nx=u*d,this.ny=x*d}let y=0;if(this.ws1.fluidEnabled){let _=-this.ws1.fluidProperties.viscosity*this.overlap/this.ws2.area;if(this.ws2.type==0)y-=_*this.ws2.circle.radius*s.Config.fluidLinearDrag/(2*this.ws2.circle.radius*Math.PI);else{let d=this.ws2.polygon,f=0,z=0,P=d.edges.head;for(;P!=null;){let Z=P.elt;f+=Z.length;let m=_*Z.length*(Z.gnormx*this.nx+Z.gnormy*this.ny);m>0&&(m*=-s.Config.fluidVacuumDrag),z-=m*.5*s.Config.fluidLinearDrag,P=P.next}y+=z/f}}if(this.ws2.fluidEnabled){let _=-this.ws2.fluidProperties.viscosity*this.overlap/this.ws1.area;if(this.ws1.type==0)y-=_*this.ws1.circle.radius*s.Config.fluidLinearDrag/(2*this.ws1.circle.radius*Math.PI);else{let d=this.ws1.polygon,f=0,z=0,P=d.edges.head;for(;P!=null;){let Z=P.elt;f+=Z.length;let m=_*Z.length*(Z.gnormx*this.nx+Z.gnormy*this.ny);m>0&&(m*=-s.Config.fluidVacuumDrag),z-=m*.5*s.Config.fluidLinearDrag,P=P.next}y+=z/f}}if(y!=0){let _=this.b1.smass+this.b2.smass,d=_,f=0,z=_;if(this.b1.sinertia!=0){let b=this.r1x*this.b1.sinertia,C=this.r1y*this.b1.sinertia;d+=C*this.r1y,f+=-C*this.r1x,z+=b*this.r1x}if(this.b2.sinertia!=0){let b=this.r2x*this.b2.sinertia,C=this.r2y*this.b2.sinertia;d+=C*this.r2y,f+=-C*this.r2x,z+=b*this.r2x}let P=d*z-f*f;if(P!==P)z=0,f=z,d=f;else if(P==0)d!=0?d=1/d:d=0,z!=0?z=1/z:z=0,f=0;else{let b=1/P,C=z*b;z=d*b,d=C,f*=-b}this.vMassa=d,this.vMassb=f,this.vMassc=z;let Z=2*Math.PI*y;this.lgamma=1/(n*Z*(2+Z*n));let m=1/(1+this.lgamma);this.lgamma*=m,this.vMassa*=m,this.vMassb*=m,this.vMassc*=m}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 we=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=null;this.lnormx=0;this.lnormy=0;this.lproj=0;this.radius=0;this.rev=!1;this.biasCoef=0;this.__ref_edge1=null;this.__ref_edge2=null;this.__ref_vertex=0;this.c1=null;this.oc1=null;this.c2=null;this.oc2=null;this.hc2=!1;this.hpc2=!1;this.stat=!1;this.mutable=!1;this.pre_dt=0;this.pre_dt=0,this.mutable=!1,this.stat=!1,this.next=null,this.hpc2=!1,this.hc2=!1,this.oc2=null,this.c2=null,this.oc1=null,this.c1=null,this.__ref_vertex=0,this.__ref_edge2=null,this.__ref_edge1=null,this.biasCoef=0,this.rev=!1,this.radius=0,this.lproj=0,this.lnormy=0,this.lnormx=0,this.surfacey=0,this.surfacex=0,this.k2y=0,this.k2x=0,this.k1y=0,this.k1x=0,this.rt2b=0,this.rn2b=0,this.rt2a=0,this.rn2a=0,this.rt1b=0,this.rn1b=0,this.rt1a=0,this.rn1a=0,this.jrAcc=0,this.rMass=0,this.Kc=0,this.Kb=0,this.Ka=0,this.kMassc=0,this.kMassb=0,this.kMassa=0,this.wrap_normal=null,this.ny=0,this.nx=0,this.innards=null,this.wrap_contacts=null,this.contacts=null,this.s2=null,this.s1=null,this.userdef_rfric=!1,this.userdef_restitution=!1,this.userdef_stat_fric=!1,this.userdef_dyn_fric=!1,this.rfric=0,this.restitution=0,this.stat_fric=0,this.dyn_fric=0,this.outer_zn=null,this.pre_dt=-1,this.contacts=new we,this.innards=new 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 a;if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=l.zpp_inner;if(r._validate!=null&&r._validate(),l.zpp_inner.x==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(),a=l.zpp_inner.y==i}else a=!1;if(!a){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,a=!1){let r=null,p=this.contacts.next;for(;p!=null;){if(o==p.hash){r=p;break}p=p.next}if(r==null){we.zpp_pool==null?r=new we:(r=we.zpp_pool,we.zpp_pool=r.next,r.next=null);let c=r.inner;c.jnAcc=c.jtAcc=0,r.hash=o,r.fresh=!0,r.arbiter=this,this.jrAcc=0,r._inuse=!0,r.next=this.contacts.next,this.contacts.next=r,this.contacts.modified=!0,this.contacts.length++,this.innards.add(c)}else r.fresh=!1;return r.px=t,r.py=n,this.nx=s,this.ny=i,r.dist=l,r.stamp=this.stamp,r.posOnly=a,r}assign(t,n,s,i){this.sup_assign(t,n,s,i),this.s1=t,this.s2=n,this._calcFrictionRestitution()}calcProperties(){this._calcFrictionRestitution()}validate_props(){this.invalidated&&(this.invalidated=!1,this._calcFrictionRestitution())}_calcFrictionRestitution(){this.userdef_restitution||(this.s1.material.elasticity<=-1/0||this.s2.material.elasticity<=-1/0?this.restitution=0:this.s1.material.elasticity>=1/0||this.s2.material.elasticity>=1/0?this.restitution=1:this.restitution=(this.s1.material.elasticity+this.s2.material.elasticity)/2,this.restitution<0&&(this.restitution=0),this.restitution>1&&(this.restitution=1)),this.userdef_dyn_fric||(this.dyn_fric=Math.sqrt(this.s1.material.dynamicFriction*this.s2.material.dynamicFriction)),this.userdef_stat_fric||(this.stat_fric=Math.sqrt(this.s1.material.staticFriction*this.s2.material.staticFriction)),this.userdef_rfric||(this.rfric=Math.sqrt(this.s1.material.rollingFriction*this.s2.material.rollingFriction))}retire(){for(this.sup_retire();this.contacts.next!=null;){let t=this.contacts.next;this.contacts.pop(),t.arbiter=null,t.next=we.zpp_pool,we.zpp_pool=t;let n=this.innards.next;this.innards.next=n.next,n._inuse=!1,this.innards.next==null&&(this.innards.pushmod=!0),this.innards.modified=!0,this.innards.length--}this.free(),this.next=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=we.zpp_pool,we.zpp_pool=l;break}n=l,s=i,i=i.next,l=l.next}}setupcontacts(){let t=Ie._zpp;this.wrap_contacts=t.util.ZPP_ContactList.get(this.contacts,!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 a=o;if(a.stamp+t.Config.arbiterExpirationDelay<this.stamp){o=wt._eraseFromList(this.contacts,s),l=wt._eraseFromList(this.innards,i),a.arbiter=null,a.next=we.zpp_pool,we.zpp_pool=a;continue}let r=a.inner,p=a.active;a.active=a.stamp==this.stamp,a.active&&(n?(n=!1,this.c1=r,this.oc1=a):(this.hc2=!0,this.c2=r,this.oc2=a)),p!=a.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 a=this.c1;this.c1=this.c2,this.c2=a,a=this.oc1,this.oc1=this.oc2,this.oc2=a,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,a=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=a,this.continuous=!1;let r=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,r),c=wt._eraseFromList(this.innards,p),u.arbiter=null,u.next=we.zpp_pool,we.zpp_pool=u;continue}let x=u.inner,y=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,d=i+this.b2.sinertia*(_*_);_=x.r1x*this.nx+x.r1y*this.ny,d+=this.b1.sinertia*(_*_),x.tMass=d<n.Config.epsilon*n.Config.epsilon?0:1/d,_=this.ny*x.r2x-this.nx*x.r2y;let f=i+this.b2.sinertia*(_*_);_=this.ny*x.r1x-this.nx*x.r1y,f+=this.b1.sinertia*(_*_),x.nMass=f<n.Config.epsilon*n.Config.epsilon?0:1/f;let z=this.b2.angvel+this.b2.kinangvel,P=this.b2.velx+this.b2.kinvelx-x.r2y*z,Z=this.b2.vely+this.b2.kinvely+x.r2x*z;z=this.b1.angvel+this.b1.kinangvel,P-=this.b1.velx+this.b1.kinvelx-x.r1y*z,Z-=this.b1.vely+this.b1.kinvely+x.r1x*z;let m=this.nx*P+this.ny*Z;u.elasticity=this.restitution,x.bounce=m*u.elasticity,x.bounce>-n.Config.elasticThreshold&&(x.bounce=0);let b=Z*this.nx-P*this.ny,C=n.Config.staticFrictionThreshold;b*b>C*C?x.friction=this.dyn_fric:x.friction=this.stat_fric,x.jnAcc*=s,x.jtAcc*=s}y!=u.active&&(this.contacts.modified=!0),r=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 y=1/x,_=this.kMassc*y;this.kMassc=this.kMassa*y,this.kMassa=_,this.kMassb*=-y}}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 a=-this.ny*s,r=this.nx*s;if(this.b2.velx+=a*this.b2.imass,this.b2.vely+=r*this.b2.imass,this.b1.velx-=a*this.b1.imass,this.b1.vely-=r*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,a=-this.ny*s,r=this.nx*s,this.b2.velx+=a*this.b2.imass,this.b2.vely+=r*this.b2.imass,this.b1.velx-=a*this.b1.imass,this.b1.vely-=r*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),y=p*this.nx+c*this.ny+this.surfacey+this.c2.bounce-(this.Kb*h+this.Kc*u),_=-(this.kMassa*x+this.kMassb*y),d=-(this.kMassb*x+this.kMassc*y);_>=0&&d>=0?(x=_-h,y=d-u,this.c1.jnAcc=_,this.c2.jnAcc=d):(_=-this.c1.nMass*x,_>=0&&this.Kb*_+y>=0?(x=_-h,y=-u,this.c1.jnAcc=_,this.c2.jnAcc=0):(d=-this.c2.nMass*y,d>=0&&this.Kb*d+x>=0?(x=-h,y=d-u,this.c1.jnAcc=0,this.c2.jnAcc=d):x>=0&&y>=0?(x=-h,y=-u,this.c1.jnAcc=this.c2.jnAcc=0):(x=0,y=0))),s=x+y,a=this.nx*s,r=this.ny*s,this.b2.velx+=a*this.b2.imass,this.b2.vely+=r*this.b2.imass,this.b1.velx-=a*this.b1.imass,this.b1.vely-=r*this.b1.imass,this.b2.angvel+=(this.rn1b*x+this.rn2b*y)*this.b2.iinertia,this.b1.angvel-=(this.rn1a*x+this.rn2a*y)*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,a=this.nx*s,r=this.ny*s,this.b2.velx+=a*this.b2.imass,this.b2.vely+=r*this.b2.imass,this.b1.velx-=a*this.b1.imass,this.b1.vely-=r*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 a=s-l,r=i-o,p=Math.sqrt(a*a+r*r),c=this.radius-t.Config.collisionSlop,h=p-c;if(a*this.nx+r*this.ny<0&&(a=-a,r=-r,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;a*=u,r*=u;let x=.5*(l+s),y=.5*(o+i),_=p-c;l=x-this.b1.posx,o=y-this.b1.posy,s=x-this.b2.posx,i=y-this.b2.posy;let d=r*l-a*o,f=r*s-a*i,z=this.b2.smass+f*f*this.b2.sinertia+this.b1.smass+d*d*this.b1.sinertia;if(z!=0){let P=-this.biasCoef*_/z,Z=a*P,m=r*P;this.b1.posx-=Z*this.b1.imass,this.b1.posy-=m*this.b1.imass,wt._rotateBody(this.b1,-d*this.b1.iinertia*P),this.b2.posx+=Z*this.b2.imass,this.b2.posy+=m*this.b2.imass,wt._rotateBody(this.b2,f*this.b2.iinertia*P)}}}_applyImpulsePosEdge(t){let n,s,i,l,o,a=0,r=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&&(a=this.b2.axisy*this.c2.lr1x-this.b2.axisx*this.c2.lr1y,r=this.c2.lr1x*this.b2.axisx+this.c2.lr1y*this.b2.axisy,a+=this.b2.posx,r+=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&&(a=this.b1.axisy*this.c2.lr1x-this.b1.axisx*this.c2.lr1y,r=this.c2.lr1x*this.b1.axisx+this.c2.lr1y*this.b1.axisy,a+=this.b1.posx,r+=this.b1.posy));let p=l*n+o*s-i-this.radius;p+=t.Config.collisionSlop;let c=0;if(this.hpc2&&(c=a*n+r*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,y=o-this.b2.posy;if(this.hpc2){let _=a-this.b1.posx,d=r-this.b1.posy,f=a-this.b2.posx,z=r-this.b2.posy,P=s*h-n*u,Z=s*x-n*y,m=s*_-n*d,b=s*f-n*z,C=this.b1.smass+this.b2.smass;this.kMassa=C+this.b1.sinertia*P*P+this.b2.sinertia*Z*Z,this.kMassb=C+this.b1.sinertia*P*m+this.b2.sinertia*Z*b,this.kMassc=C+this.b1.sinertia*m*m+this.b2.sinertia*b*b;let v=this.kMassa,w=this.kMassb,O=this.kMassc,k=p*this.biasCoef,g=c*this.biasCoef;for(;;){let E=-k,M=-g,N=this.kMassa*this.kMassc-this.kMassb*this.kMassb;if(N!==N)E=0,M=0;else if(N==0)this.kMassa!=0?E/=this.kMassa:E=0,this.kMassc!=0?M/=this.kMassc:M=0;else{let S=1/N,D=S*(this.kMassc*E-this.kMassb*M);M=S*(this.kMassa*M-this.kMassb*E),E=D}if(E>=0&&M>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,E,M,P,m,Z,b);break}if(E=-k/v,M=0,E>=0&&w*E+g>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,E,M,P,m,Z,b);break}if(E=0,M=-g/O,M>=0&&w*M+k>=0){wt._applyPosImpulse2(this.b1,this.b2,n,s,E,M,P,m,Z,b);break}break}}else{let _=s*h-n*u,d=s*x-n*y,f=this.b2.smass+d*d*this.b2.sinertia+this.b1.smass+_*_*this.b1.sinertia;if(f!=0){let z=-this.biasCoef*p/f,P=n*z,Z=s*z;this.b1.posx-=P*this.b1.imass,this.b1.posy-=Z*this.b1.imass,wt._rotateBody(this.b1,-_*this.b1.iinertia*z),this.b2.posx+=P*this.b2.imass,this.b2.posy+=Z*this.b2.imass,wt._rotateBody(this.b2,d*this.b2.iinertia*z)}}}}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,a,r,p,c){let h=(l+o)*t.imass;t.posx-=s*h,t.posy-=i*h,wt._rotateBody(t,-t.iinertia*(a*l+r*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 st=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 a=0,r=this.space.s_arbiters.head;for(;r!=null;)r.elt.active&&++a,r=r.next;this.lengths[e++]=a,this._length+=a,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,a=e.circle.radius,r=o.x-e.circle.worldCOMx,p=o.y-e.circle.worldCOMy;if(r*r+p*p<=a*a){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,a=i.spine1x-e.circle.worldCOMx,r=i.spine1y-e.circle.worldCOMy;if(a*a+r*r>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),a=i.spine1y+l*(i.spine2y-i.spine1y),r=i.radius-t.circle.radius;if(r<0)return!1;let p=t.circle.worldCOMx-o,c=t.circle.worldCOMy-a;return p*p+c*c<=r*r}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,a=-1e100,r=t.polygon.gverts.next;for(;r!=null;){let p=r,c=o.gnormx*p.x+o.gnormy*p.y;c>a&&(a=c),r=r.next}if(a<=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,a=-1e100,r=-1,p=null,c=null,h=e.polygon.edges.head;for(;h!=null;){let u=h.elt,x=1e100,y=t.polygon.gverts.next;for(;y!=null;){let _=y,d=u.gnormx*_.x+u.gnormy*_.y;if(d<x&&(x=d),x-u.gprojection<=o)break;y=y.next}if(x-=u.gprojection,x>=0){l=!1;break}x>o&&(o=x,p=u,r=1),h=h.next}if(l){let u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,y=1e100,_=e.polygon.gverts.next;for(;_!=null;){let d=_,f=x.gnormx*d.x+x.gnormy*d.y;if(f<y&&(y=f),y-x.gprojection<=o)break;_=_.next}if(y-=x.gprojection,y>=0){l=!1;break}y>o&&(o=y,c=x,r=2),u=u.next}if(l){let x,y,_,d;r==1?(x=e.polygon,y=t.polygon,_=p,d=1):(x=t.polygon,y=e.polygon,_=c,d=-1);let f=null,z=1e100,P=y.edges.head;for(;P!=null;){let q=P.elt,G=_.gnormx*q.gnormx+_.gnormy*q.gnormy;G<z&&(z=G,f=q),P=P.next}let Z=f.gp0.x,m=f.gp0.y,b=f.gp1.x,C=f.gp1.y,v=b-Z,w=C-m,O=_.gnormy*Z-_.gnormx*m,k=_.gnormy*b-_.gnormx*C,g=1/(k-O),E=(-_.tp1-O)*g;if(E>i.Config.epsilon){let q=E;Z+=v*q,m+=w*q}let M=(-_.tp0-k)*g;if(M<-i.Config.epsilon){let q=M;b+=v*q,C+=w*q}let N=d,S=_.gnormx*N,D=_.gnormy*N;n.lnormx=_.lnormx,n.lnormy=_.lnormy,n.lproj=_.lprojection,n.radius=0,n.rev=s!=(d==-1),n.ptype=n.rev?1:0;let j=Z*_.gnormx+m*_.gnormy-_.gprojection,R=b*_.gnormx+C*_.gnormy-_.gprojection;if(j>0&&R>0)return!1;{s&&(S=-S,D=-D);let q=Z-_.gnormx*j*.5,G=m-_.gnormy*j*.5,B=n.rev?1:0,V=j>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){we.zpp_pool==null?Y=new we:(Y=we.zpp_pool,we.zpp_pool=Y.next,Y.next=null);let K=Y.inner;K.jnAcc=K.jtAcc=0,Y.hash=B,Y.fresh=!0,Y.arbiter=n,n.jrAcc=0;let ne=n.contacts;Y._inuse=!0;let re=Y;re.next=ne.next,ne.next=re,ne.modified=!0,ne.length++,n.innards.add(K)}else Y.fresh=!1;Y.px=q,Y.py=G,n.nx=S,n.ny=D,Y.dist=j,Y.stamp=n.stamp,Y.posOnly=V;let X=Y,H=1;Z-=y.body.posx*H,m-=y.body.posy*H,X.inner.lr1x=Z*y.body.axisy+m*y.body.axisx,X.inner.lr1y=m*y.body.axisy-Z*y.body.axisx;let ee=b-_.gnormx*R*.5,W=C-_.gnormy*R*.5,L=n.rev?0:1,F=R>0;F==null&&(F=!1);let A=null,J=n.contacts.next;for(;J!=null;){let K=J;if(L==K.hash){A=K;break}J=J.next}if(A==null){we.zpp_pool==null?A=new we:(A=we.zpp_pool,we.zpp_pool=A.next,A.next=null);let K=A.inner;K.jnAcc=K.jtAcc=0,A.hash=L,A.fresh=!0,A.arbiter=n,n.jrAcc=0;let ne=n.contacts;A._inuse=!0;let re=A;re.next=ne.next,ne.next=re,ne.modified=!0,ne.length++,n.innards.add(K)}else A.fresh=!1;A.px=ee,A.py=W,n.nx=S,n.ny=D,A.dist=R,A.stamp=n.stamp,A.posOnly=F,X=A;let Q=1;return b-=y.body.posx*Q,C-=y.body.posy*Q,X.inner.lr1x=b*y.body.axisy+C*y.body.axisx,X.inner.lr1y=C*y.body.axisy-b*y.body.axisx,r==1?(n.__ref_edge1=_,n.__ref_edge2=f):(n.__ref_edge2=_,n.__ref_edge1=f),!0}}else return!1}else return!1}else{let l=-1e100,o=-1e100,a=!0,r=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){a=!1;break}x>l&&(l=x,r=u,p=c),c=c.next,h=h.next}if(a){let u=p,x=p.next==null?t.polygon.gverts.next:p.next,y=e.circle.worldCOMy*r.gnormx-e.circle.worldCOMx*r.gnormy;if(y<=u.y*r.gnormx-u.x*r.gnormy){let _=e.circle.radius,d=u.x-e.circle.worldCOMx,f=u.y-e.circle.worldCOMy,z=d*d+f*f,P;if(z>_*_)P=null;else if(z<i.Config.epsilon*i.Config.epsilon){let Z=e.circle.worldCOMx,m=e.circle.worldCOMy,b=null,C=n.contacts.next;for(;C!=null;){let v=C;if(v.hash==0){b=v;break}C=C.next}if(b==null){we.zpp_pool==null?b=new we:(b=we.zpp_pool,we.zpp_pool=b.next,b.next=null);let v=b.inner;v.jnAcc=v.jtAcc=0,b.hash=0,b.fresh=!0,b.arbiter=n,n.jrAcc=0;let w=n.contacts;b._inuse=!0;let O=b;O.next=w.next,w.next=O,w.modified=!0,w.length++,n.innards.add(v)}else b.fresh=!1;b.px=Z,b.py=m,n.nx=1,n.ny=0,b.dist=-_,b.stamp=n.stamp,b.posOnly=!1,P=b}else{let Z=1/Math.sqrt(z),m=Z<i.Config.epsilon?1e100:1/Z,b=.5+(e.circle.radius-.5*_)*Z;if(s){let C=e.circle.worldCOMx+d*b,v=e.circle.worldCOMy+f*b,w=null,O=n.contacts.next;for(;O!=null;){let k=O;if(k.hash==0){w=k;break}O=O.next}if(w==null){we.zpp_pool==null?w=new we:(w=we.zpp_pool,we.zpp_pool=w.next,w.next=null);let k=w.inner;k.jnAcc=k.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let E=w;E.next=g.next,g.next=E,g.modified=!0,g.length++,n.innards.add(k)}else w.fresh=!1;w.px=C,w.py=v,n.nx=-d*Z,n.ny=-f*Z,w.dist=m-_,w.stamp=n.stamp,w.posOnly=!1,P=w}else{let C=e.circle.worldCOMx+d*b,v=e.circle.worldCOMy+f*b,w=null,O=n.contacts.next;for(;O!=null;){let k=O;if(k.hash==0){w=k;break}O=O.next}if(w==null){we.zpp_pool==null?w=new we:(w=we.zpp_pool,we.zpp_pool=w.next,w.next=null);let k=w.inner;k.jnAcc=k.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let E=w;E.next=g.next,g.next=E,g.modified=!0,g.length++,n.innards.add(k)}else w.fresh=!1;w.px=C,w.py=v,n.nx=d*Z,n.ny=f*Z,w.dist=m-_,w.stamp=n.stamp,w.posOnly=!1,P=w}}if(P!=null){let Z=P.inner;n.ptype=2;let m=u.x-t.polygon.body.posx,b=u.y-t.polygon.body.posy;n.__ref_edge1=r,n.__ref_vertex=-1,s?(Z.lr1x=m*t.polygon.body.axisy+b*t.polygon.body.axisx,Z.lr1y=b*t.polygon.body.axisy-m*t.polygon.body.axisx,Z.lr2x=e.circle.localCOMx,Z.lr2y=e.circle.localCOMy):(Z.lr2x=m*t.polygon.body.axisy+b*t.polygon.body.axisx,Z.lr2y=b*t.polygon.body.axisy-m*t.polygon.body.axisx,Z.lr1x=e.circle.localCOMx,Z.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return P!=null}else if(y>=x.y*r.gnormx-x.x*r.gnormy){let _=e.circle.radius,d=x.x-e.circle.worldCOMx,f=x.y-e.circle.worldCOMy,z=d*d+f*f,P;if(z>_*_)P=null;else if(z<i.Config.epsilon*i.Config.epsilon){let Z=e.circle.worldCOMx,m=e.circle.worldCOMy,b=null,C=n.contacts.next;for(;C!=null;){let v=C;if(v.hash==0){b=v;break}C=C.next}if(b==null){we.zpp_pool==null?b=new we:(b=we.zpp_pool,we.zpp_pool=b.next,b.next=null);let v=b.inner;v.jnAcc=v.jtAcc=0,b.hash=0,b.fresh=!0,b.arbiter=n,n.jrAcc=0;let w=n.contacts;b._inuse=!0;let O=b;O.next=w.next,w.next=O,w.modified=!0,w.length++,n.innards.add(v)}else b.fresh=!1;b.px=Z,b.py=m,n.nx=1,n.ny=0,b.dist=-_,b.stamp=n.stamp,b.posOnly=!1,P=b}else{let Z=1/Math.sqrt(z),m=Z<i.Config.epsilon?1e100:1/Z,b=.5+(e.circle.radius-.5*_)*Z;if(s){let C=e.circle.worldCOMx+d*b,v=e.circle.worldCOMy+f*b,w=null,O=n.contacts.next;for(;O!=null;){let k=O;if(k.hash==0){w=k;break}O=O.next}if(w==null){we.zpp_pool==null?w=new we:(w=we.zpp_pool,we.zpp_pool=w.next,w.next=null);let k=w.inner;k.jnAcc=k.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let E=w;E.next=g.next,g.next=E,g.modified=!0,g.length++,n.innards.add(k)}else w.fresh=!1;w.px=C,w.py=v,n.nx=-d*Z,n.ny=-f*Z,w.dist=m-_,w.stamp=n.stamp,w.posOnly=!1,P=w}else{let C=e.circle.worldCOMx+d*b,v=e.circle.worldCOMy+f*b,w=null,O=n.contacts.next;for(;O!=null;){let k=O;if(k.hash==0){w=k;break}O=O.next}if(w==null){we.zpp_pool==null?w=new we:(w=we.zpp_pool,we.zpp_pool=w.next,w.next=null);let k=w.inner;k.jnAcc=k.jtAcc=0,w.hash=0,w.fresh=!0,w.arbiter=n,n.jrAcc=0;let g=n.contacts;w._inuse=!0;let E=w;E.next=g.next,g.next=E,g.modified=!0,g.length++,n.innards.add(k)}else w.fresh=!1;w.px=C,w.py=v,n.nx=d*Z,n.ny=f*Z,w.dist=m-_,w.stamp=n.stamp,w.posOnly=!1,P=w}}if(P!=null){let Z=P.inner;n.ptype=2;let m=x.x-t.polygon.body.posx,b=x.y-t.polygon.body.posy;n.__ref_edge1=r,n.__ref_vertex=1,s?(Z.lr1x=m*t.polygon.body.axisy+b*t.polygon.body.axisx,Z.lr1y=b*t.polygon.body.axisy-m*t.polygon.body.axisx,Z.lr2x=e.circle.localCOMx,Z.lr2y=e.circle.localCOMy):(Z.lr2x=m*t.polygon.body.axisy+b*t.polygon.body.axisx,Z.lr2y=b*t.polygon.body.axisy-m*t.polygon.body.axisx,Z.lr1x=e.circle.localCOMx,Z.lr1y=e.circle.localCOMy),n.radius=e.circle.radius}return P!=null}else{let _=e.circle.radius+l*.5,d=r.gnormx*_,f=r.gnormy*_,z=e.circle.worldCOMx-d,P=e.circle.worldCOMy-f,Z;if(s){let m=r.gnormx,b=r.gnormy,C=null,v=n.contacts.next;for(;v!=null;){let w=v;if(w.hash==0){C=w;break}v=v.next}if(C==null){we.zpp_pool==null?C=new we:(C=we.zpp_pool,we.zpp_pool=C.next,C.next=null);let w=C.inner;w.jnAcc=w.jtAcc=0,C.hash=0,C.fresh=!0,C.arbiter=n,n.jrAcc=0;let O=n.contacts;C._inuse=!0;let k=C;k.next=O.next,O.next=k,O.modified=!0,O.length++,n.innards.add(w)}else C.fresh=!1;C.px=z,C.py=P,n.nx=m,n.ny=b,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,Z=C}else{let m=-r.gnormx,b=-r.gnormy,C=null,v=n.contacts.next;for(;v!=null;){let w=v;if(w.hash==0){C=w;break}v=v.next}if(C==null){we.zpp_pool==null?C=new we:(C=we.zpp_pool,we.zpp_pool=C.next,C.next=null);let w=C.inner;w.jnAcc=w.jtAcc=0,C.hash=0,C.fresh=!0,C.arbiter=n,n.jrAcc=0;let O=n.contacts;C._inuse=!0;let k=C;k.next=O.next,O.next=k,O.modified=!0,O.length++,n.innards.add(w)}else C.fresh=!1;C.px=z,C.py=P,n.nx=m,n.ny=b,C.dist=l,C.stamp=n.stamp,C.posOnly=!1,Z=C}return n.ptype=s?0:1,n.lnormx=r.lnormx,n.lnormy=r.lnormy,n.rev=!s,n.lproj=r.lprojection,n.radius=e.circle.radius,Z.inner.lr1x=e.circle.localCOMx,Z.inner.lr1y=e.circle.localCOMy,n.__ref_edge1=r,n.__ref_vertex=0,!0}}else return!1}else{let l=e.circle.radius+t.circle.radius,o=t.circle.worldCOMx-e.circle.worldCOMx,a=t.circle.worldCOMy-e.circle.worldCOMy,r=o*o+a*a,p;if(r>l*l)p=null;else if(r<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 y=x;if(y.hash==0){u=y;break}x=x.next}if(u==null){we.zpp_pool==null?u=new we:(u=we.zpp_pool,we.zpp_pool=u.next,u.next=null);let y=u.inner;y.jnAcc=y.jtAcc=0,u.hash=0,u.fresh=!0,u.arbiter=n,n.jrAcc=0;let _=n.contacts;u._inuse=!0;let d=u;d.next=_.next,_.next=d,_.modified=!0,_.length++,n.innards.add(y)}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(r),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,y=e.circle.worldCOMy+a*u,_=null,d=n.contacts.next;for(;d!=null;){let f=d;if(f.hash==0){_=f;break}d=d.next}if(_==null){we.zpp_pool==null?_=new we:(_=we.zpp_pool,we.zpp_pool=_.next,_.next=null);let f=_.inner;f.jnAcc=f.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let z=n.contacts;_._inuse=!0;let P=_;P.next=z.next,z.next=P,z.modified=!0,z.length++,n.innards.add(f)}else _.fresh=!1;_.px=x,_.py=y,n.nx=-o*c,n.ny=-a*c,_.dist=h-l,_.stamp=n.stamp,_.posOnly=!1,p=_}else{let x=e.circle.worldCOMx+o*u,y=e.circle.worldCOMy+a*u,_=null,d=n.contacts.next;for(;d!=null;){let f=d;if(f.hash==0){_=f;break}d=d.next}if(_==null){we.zpp_pool==null?_=new we:(_=we.zpp_pool,we.zpp_pool=_.next,_.next=null);let f=_.inner;f.jnAcc=f.jtAcc=0,_.hash=0,_.fresh=!0,_.arbiter=n,n.jrAcc=0;let z=n.contacts;_._inuse=!0;let P=_;P.next=z.next,z.next=P,z.modified=!0,z.length++,n.innards.add(f)}else _.fresh=!1;_.px=x,_.py=y,n.nx=o*c,n.ny=a*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,a=t.polygon.gverts.next;for(;a!=null;){let r=a,p=l.gnormx*r.x+l.gnormy*r.y;p<o&&(o=p),a=a.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,a=1e100,r=e.polygon.gverts.next;for(;r!=null;){let p=r,c=o.gnormx*p.x+o.gnormy*p.y;c<a&&(a=c),r=r.next}if(a-=o.gprojection,a>0){s=!1;break}l=l.next}return s}else return!1}else{let s=null,i=null,l=!0,o=-1e100,a=t.polygon.gverts.next,r=t.polygon.edges.head;for(;r!=null;){let p=r.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=a),a=a.next,r=r.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,y=p.y-e.circle.worldCOMy;return x*x+y*y<=u*u}else if(h>=c.y*s.gnormx-c.x*s.gnormy){let u=e.circle.radius,x=c.x-e.circle.worldCOMx,y=c.y-e.circle.worldCOMy;return x*x+y*y<=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,a=!0,r=e.polygon.edges.head;for(;r!=null;){let p=r.elt,c=1e100,h=0,u=t.polygon.gverts.next;for(;u!=null;){let x=u,y=p.gnormx*x.x+p.gnormy*x.y;y<c&&(c=y),y>=p.gprojection+s.Config.epsilon&&(l[h]=!0,a=!1),++h,u=u.next}if(c-=p.gprojection,c>0){o=!1;break}r=r.next}if(a){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,y=x;x=x.next;let _=x;for(x=x.next;x!=null;){let m=x;u+=_.x*(m.y-y.y);let b=m.y*_.x-m.x*_.y;h.localCOMx+=(_.x+m.x)*b,h.localCOMy+=(_.y+m.y)*b,y=_,_=m,x=x.next}x=h.lverts.next;let d=x;u+=_.x*(d.y-y.y);let f=d.y*_.x-d.x*_.y;h.localCOMx+=(_.x+d.x)*f,h.localCOMy+=(_.y+d.y)*f,y=_,_=d,x=x.next;let z=x;u+=_.x*(z.y-y.y);let P=z.y*_.x-z.x*_.y;h.localCOMx+=(_.x+z.x)*P,h.localCOMy+=(_.y+z.y)*P,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){a=!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 y=x,_=c.gnormx*y.x+c.gnormy*y.y;_<h&&(h=_),_>=c.gprojection+s.Config.epsilon&&(i[u]=!0,a=!1),++u,x=x.next}if(h-=c.gprojection,h>0){o=!1;break}p=p.next}if(a){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 y=.5;u.localCOMx*=y,u.localCOMy*=y}else{u.localCOMx=0,u.localCOMy=0;let x=0,y=u.lverts.next,_=y;y=y.next;let d=y;for(y=y.next;y!=null;){let b=y;x+=d.x*(b.y-_.y);let C=b.y*d.x-b.x*d.y;u.localCOMx+=(d.x+b.x)*C,u.localCOMy+=(d.y+b.y)*C,_=d,d=b,y=y.next}y=u.lverts.next;let f=y;x+=d.x*(f.y-_.y);let z=f.y*d.x-f.x*d.y;u.localCOMx+=(d.x+f.x)*z,u.localCOMy+=(d.y+f.y)*z,_=d,d=f,y=y.next;let P=y;x+=d.x*(P.y-_.y);let Z=P.y*d.x-P.x*d.y;u.localCOMx+=(d.x+P.x)*Z,u.localCOMy+=(d.y+P.y)*Z,x=1/(3*x);let m=x;u.localCOMx*=m,u.localCOMy*=m}}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 P=be.flowpoly.pop_unsafe();if(!P._inuse){let Z=P;Z.outer!=null&&(Z.outer.zpp_inner=null,Z.outer=null),Z._isimmutable=null,Z._validate=null,Z._invalidate=null,Z.next=le.zpp_pool,le.zpp_pool=Z}}let c=null,h=!1,u=e.polygon.gverts.next,x=0,y=t.polygon.gverts.next,_=0,d=0,f=t.polygon.edgeCnt;for(;d<f;){let P=d++;if(l[P])y=y.next;else{_=P;break}}if(y==null){y=t.polygon.gverts.next,h=!0;let P=0,Z=e.polygon.edgeCnt;for(;P<Z;){let m=P++;if(i[m])u=u.next;else{x=m;break}}u==null?u=e.polygon.gverts.next:(be.flowpoly.add(u),c=be.flowpoly.head.elt)}else be.flowpoly.add(y),c=be.flowpoly.head.elt;let z=1;if(be.flowpoly.head==null){let P=!0,Z=e.polygon.gverts.next,m=Z,b=Z.next;for(;b!=null;){let C=b,v=2,w=!0,O=t.polygon.gverts.next,k=O,g=O.next;for(;g!=null;){let E=g,M=0,N=m.x-k.x,S=m.y-k.y,D=C.x-m.x,j=C.y-m.y,R=E.x-k.x,q=E.y-k.y,G=j*R-D*q,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(q*N-R*S)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(j*N-D*S)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(M=V,B=!0):B=!1}else B=!1}else B=!1;B&&M<v&&(v=M,y=O),O=g,k=E,g=g.next}if(w)for(;;){g=t.polygon.gverts.next;let E=g,M=0,N=m.x-k.x,S=m.y-k.y,D=C.x-m.x,j=C.y-m.y,R=E.x-k.x,q=E.y-k.y,G=j*R-D*q,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(q*N-R*S)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(j*N-D*S)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(M=V,B=!0):B=!1}else B=!1}else B=!1;B&&M<v&&(v=M,y=O);break}if(v!=2){let E=v,M=m.x+(C.x-m.x)*E,N=m.y+(C.y-m.y)*E,S;le.zpp_pool==null?S=new le:(S=le.zpp_pool,le.zpp_pool=S.next,S.next=null),S.weak=!1,S._immutable=!1,S.x=M,S.y=N,c=S,be.flowpoly.add(c),h=!0,u=Z,P=!1;break}Z=b,m=C,b=b.next}if(P)for(;;){b=e.polygon.gverts.next;let C=b,v=2,w=!0,O=t.polygon.gverts.next,k=O,g=O.next;for(;g!=null;){let E=g,M=0,N=m.x-k.x,S=m.y-k.y,D=C.x-m.x,j=C.y-m.y,R=E.x-k.x,q=E.y-k.y,G=j*R-D*q,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(q*N-R*S)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(j*N-D*S)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(M=V,B=!0):B=!1}else B=!1}else B=!1;B&&M<v&&(v=M,y=O),O=g,k=E,g=g.next}if(w)for(;;){g=t.polygon.gverts.next;let E=g,M=0,N=m.x-k.x,S=m.y-k.y,D=C.x-m.x,j=C.y-m.y,R=E.x-k.x,q=E.y-k.y,G=j*R-D*q,B;if(G*G>s.Config.epsilon*s.Config.epsilon){G=1/G;let V=(q*N-R*S)*G;if(V>s.Config.epsilon&&V<1-s.Config.epsilon){let Y=(j*N-D*S)*G;Y>s.Config.epsilon&&Y<1-s.Config.epsilon?(M=V,B=!0):B=!1}else B=!1}else B=!1;B&&M<v&&(v=M,y=O);break}if(v!=2){let E=v,M=m.x+(C.x-m.x)*E,N=m.y+(C.y-m.y)*E,S;le.zpp_pool==null?S=new le:(S=le.zpp_pool,le.zpp_pool=S.next,S.next=null),S.weak=!1,S._immutable=!1,S.x=M,S.y=N,c=S,be.flowpoly.add(c),h=!0,u=Z;break}break}z=2}for(;;)if(h)if(u=u.next,++x,u==null&&(u=e.polygon.gverts.next,x=0),i[x]){let P=be.flowpoly.head.elt,Z=u,m=y,b=y.next;b==null&&(b=t.polygon.gverts.next);let C=-1,v=null,w=0,O=0,k=b,g=b;for(;;){let B=g,V=0,Y=m.x-P.x,$=m.y-P.y,X=B.x-m.x,H=B.y-m.y,ee=Z.x-P.x,W=Z.y-P.y,L=H*ee-X*W,F;if(L*L>s.Config.epsilon*s.Config.epsilon){L=1/L;let A=(W*Y-ee*$)*L;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let J=(H*Y-X*$)*L;J>s.Config.epsilon&&J<1-s.Config.epsilon?(V=A,F=!0):F=!1}else F=!1}else F=!1;if(F&&V>=C)if(v=y,w=_,++O==z){C=V,g=k;break}else C=V;m=B,y=g,++_,_>=t.polygon.edgeCnt&&(_=0),g=g.next,g==null&&(g=t.polygon.gverts.next);break}for(;g!=k;){let B=g,V=0,Y=m.x-P.x,$=m.y-P.y,X=B.x-m.x,H=B.y-m.y,ee=Z.x-P.x,W=Z.y-P.y,L=H*ee-X*W,F;if(L*L>s.Config.epsilon*s.Config.epsilon){L=1/L;let A=(W*Y-ee*$)*L;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let J=(H*Y-X*$)*L;J>s.Config.epsilon&&J<1-s.Config.epsilon?(V=A,F=!0):F=!1}else F=!1}else F=!1;if(F&&V>=C)if(v=y,w=_,++O==z){C=V;break}else C=V;m=B,y=g,++_,_>=t.polygon.edgeCnt&&(_=0),g=g.next,g==null&&(g=t.polygon.gverts.next)}if(v==null)break;let E=v,M=v.next;M==null&&(M=t.polygon.gverts.next);let N=M,S=C,D=E.x+(N.x-E.x)*S,j=E.y+(N.y-E.y)*S,R;if(c!=null){let B=D-c.x,V=j-c.y;R=B*B+V*V<s.Config.epsilon}else R=!1;if(R)break;let q=be.flowpoly,G;le.zpp_pool==null?G=new le:(G=le.zpp_pool,le.zpp_pool=G.next,G.next=null),G.weak=!1,G._immutable=!1,G.x=D,G.y=j,q.add(G),c==null&&(c=be.flowpoly.head.elt),y=v,_=w,h=!h,z=2}else{let P=u,Z;if(c!=null){let m=P.x-c.x,b=P.y-c.y;Z=m*m+b*b<s.Config.epsilon}else Z=!1;if(Z)break;be.flowpoly.add(P),c==null&&(c=be.flowpoly.head.elt),z=1}else if(y=y.next,++_,y==null&&(y=t.polygon.gverts.next,_=0),l[_]){let P=be.flowpoly.head.elt,Z=y,m=u,b=u.next;b==null&&(b=e.polygon.gverts.next);let C=-1,v=null,w=0,O=0,k=b,g=b;for(;;){let B=g,V=0,Y=m.x-P.x,$=m.y-P.y,X=B.x-m.x,H=B.y-m.y,ee=Z.x-P.x,W=Z.y-P.y,L=H*ee-X*W,F;if(L*L>s.Config.epsilon*s.Config.epsilon){L=1/L;let A=(W*Y-ee*$)*L;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let J=(H*Y-X*$)*L;J>s.Config.epsilon&&J<1-s.Config.epsilon?(V=A,F=!0):F=!1}else F=!1}else F=!1;if(F&&V>=C)if(v=u,w=x,++O==z){C=V,g=k;break}else C=V;m=B,u=g,++x,x>=e.polygon.edgeCnt&&(x=0),g=g.next,g==null&&(g=e.polygon.gverts.next);break}for(;g!=k;){let B=g,V=0,Y=m.x-P.x,$=m.y-P.y,X=B.x-m.x,H=B.y-m.y,ee=Z.x-P.x,W=Z.y-P.y,L=H*ee-X*W,F;if(L*L>s.Config.epsilon*s.Config.epsilon){L=1/L;let A=(W*Y-ee*$)*L;if(A>s.Config.epsilon&&A<1-s.Config.epsilon){let J=(H*Y-X*$)*L;J>s.Config.epsilon&&J<1-s.Config.epsilon?(V=A,F=!0):F=!1}else F=!1}else F=!1;if(F&&V>=C)if(v=u,w=x,++O==z){C=V;break}else C=V;m=B,u=g,++x,x>=e.polygon.edgeCnt&&(x=0),g=g.next,g==null&&(g=e.polygon.gverts.next)}if(v==null)break;let E=v,M=v.next;M==null&&(M=e.polygon.gverts.next);let N=M,S=C,D=E.x+(N.x-E.x)*S,j=E.y+(N.y-E.y)*S,R;if(c!=null){let B=D-c.x,V=j-c.y;R=B*B+V*V<s.Config.epsilon}else R=!1;if(R)break;let q=be.flowpoly,G;le.zpp_pool==null?G=new le:(G=le.zpp_pool,le.zpp_pool=G.next,G.next=null),G.weak=!1,G._immutable=!1,G.x=D,G.y=j,q.add(G),c==null&&(c=be.flowpoly.head.elt),u=v,x=w,h=!h,z=2}else{let P=y,Z;if(c!=null){let m=P.x-c.x,b=P.y-c.y;Z=m*m+b*b<s.Config.epsilon}else Z=!1;if(Z)break;be.flowpoly.add(P),c==null&&(c=be.flowpoly.head.elt),z=1}if(be.flowpoly.head!=null&&be.flowpoly.head.next!=null&&be.flowpoly.head.next.next!=null){let P=0,Z=0,m=0,b=be.flowpoly.head,C=b.elt;b=b.next;let v=b.elt;for(b=b.next;b!=null;){let N=b.elt;P+=v.x*(N.y-C.y);let S=N.y*v.x-N.x*v.y;Z+=(v.x+N.x)*S,m+=(v.y+N.y)*S,C=v,v=N,b=b.next}b=be.flowpoly.head;let w=b.elt;P+=v.x*(w.y-C.y);let O=w.y*v.x-w.x*v.y;Z+=(v.x+w.x)*O,m+=(v.y+w.y)*O,C=v,v=w,b=b.next;let k=b.elt;P+=v.x*(k.y-C.y);let g=k.y*v.x-k.x*v.y;Z+=(v.x+k.x)*g,m+=(v.y+k.y)*g,P*=.5;let M=1/(6*P);return Z*=M,m*=M,n.overlap=-P,n.centroidx=Z,n.centroidy=m,!0}else return!1}else return!1}else return!1}else{let i=[],l=!0,o=null,a=null,r=-1e100,p=!0,c=t.polygon.gverts.next,h=0,u=t.polygon.edges.head;for(;u!=null;){let x=u.elt,y=x.gnormx*e.circle.worldCOMx+x.gnormy*e.circle.worldCOMy;if(y>x.gprojection+e.circle.radius){p=!1;break}else y+e.circle.radius>x.gprojection+s.Config.epsilon&&(l=!1,i[h]=!0);y-=x.gprojection+e.circle.radius,y>r&&(r=y,o=x,a=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=a,y=a.next==null?t.polygon.gverts.next:a.next,_=e.circle.worldCOMy*o.gnormx-e.circle.worldCOMx*o.gnormy,d;if(_<=x.y*o.gnormx-x.x*o.gnormy){let f=e.circle.radius,z=x.x-e.circle.worldCOMx,P=x.y-e.circle.worldCOMy;d=z*z+P*P<=f*f}else if(_>=y.y*o.gnormx-y.x*o.gnormy){let f=e.circle.radius,z=y.x-e.circle.worldCOMx,P=y.y-e.circle.worldCOMy;d=z*z+P*P<=f*f}else d=!0;if(d){let f=[],z=0,P=!0,Z=null,m=0,b=t.polygon.gverts.next;for(;b!=null;){let C=b,v=C.x-e.circle.worldCOMx,w=C.y-e.circle.worldCOMy,O=v*v+w*w;(f[z]=O<=e.circle.radius*e.circle.radius)?(m=z,Z=b):P=!1,++z,b=b.next}if(P){let C=t.polygon;if(C.zip_worldCOM&&C.body!=null){if(C.zip_worldCOM=!1,C.zip_localCOM){if(C.zip_localCOM=!1,C.type==1){let w=C.polygon;if(w.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(w.lverts.next.next==null)w.localCOMx=w.lverts.next.x,w.localCOMy=w.lverts.next.y;else if(w.lverts.next.next.next==null){w.localCOMx=w.lverts.next.x,w.localCOMy=w.lverts.next.y;let O=1;w.localCOMx+=w.lverts.next.next.x*O,w.localCOMy+=w.lverts.next.next.y*O;let k=.5;w.localCOMx*=k,w.localCOMy*=k}else{w.localCOMx=0,w.localCOMy=0;let O=0,k=w.lverts.next,g=k;k=k.next;let E=k;for(k=k.next;k!=null;){let R=k;O+=E.x*(R.y-g.y);let q=R.y*E.x-R.x*E.y;w.localCOMx+=(E.x+R.x)*q,w.localCOMy+=(E.y+R.y)*q,g=E,E=R,k=k.next}k=w.lverts.next;let M=k;O+=E.x*(M.y-g.y);let N=M.y*E.x-M.x*E.y;w.localCOMx+=(E.x+M.x)*N,w.localCOMy+=(E.y+M.y)*N,g=E,E=M,k=k.next;let S=k;O+=E.x*(S.y-g.y);let D=S.y*E.x-S.x*E.y;w.localCOMx+=(E.x+S.x)*D,w.localCOMy+=(E.y+S.y)*D,O=1/(3*O);let j=O;w.localCOMx*=j,w.localCOMy*=j}}C.wrap_localCOM!=null&&(C.wrap_localCOM.zpp_inner.x=C.localCOMx,C.wrap_localCOM.zpp_inner.y=C.localCOMy)}let v=C.body;v.zip_axis&&(v.zip_axis=!1,v.axisx=Math.sin(v.rot),v.axisy=Math.cos(v.rot)),C.worldCOMx=C.body.posx+(C.body.axisy*C.localCOMx-C.body.axisx*C.localCOMy),C.worldCOMy=C.body.posy+(C.localCOMx*C.body.axisx+C.localCOMy*C.body.axisy)}return n.overlap=t.polygon.area,n.centroidx=t.polygon.worldCOMx,n.centroidy=t.polygon.worldCOMy,!0}else{for(;be.flowpoly.head!=null;){let w=be.flowpoly.pop_unsafe();if(!w._inuse){let O=w;O.outer!=null&&(O.outer.zpp_inner=null,O.outer=null),O._isimmutable=null,O._validate=null,O._invalidate=null,O.next=le.zpp_pool,le.zpp_pool=O}}be.flowsegs.clear();let C=null,v=1;for(Z==null?(Z=t.polygon.gverts.next,v=2):(C=Z,be.flowpoly.add(C));v!=0;)if(v==1)if(Z=Z.next,Z==null&&(Z=t.polygon.gverts.next),++m,m>=t.polygon.edgeCnt&&(m=0),f[m]){let w=C.x-Z.x,O=C.y-Z.y;if(w*w+O*O<s.Config.epsilon)break;be.flowpoly.add(Z)}else{let w=be.flowpoly.head.elt,O=Z,k=O.x-w.x,g=O.y-w.y,E=w.x-e.circle.worldCOMx,M=w.y-e.circle.worldCOMy,N=k*k+g*g,S=2*(E*k+M*g),D=E*E+M*M-e.circle.radius*e.circle.radius,j=Math.sqrt(S*S-4*N*D);N=1/(2*N);let R=(-S-j)*N,q=R<s.Config.epsilon?(-S+j)*N:R,G=0,B=0,V=q;G=w.x+(O.x-w.x)*V,B=w.y+(O.y-w.y)*V;let Y=C.x-G,$=C.y-B;if(Y*Y+$*$<s.Config.epsilon)break;let X=be.flowpoly,H;le.zpp_pool==null?H=new le:(H=le.zpp_pool,le.zpp_pool=H.next,H.next=null),H.weak=!1,H._immutable=!1,H.x=G,H.y=B,X.add(H),v=2}else if(v==2){let w=Z.next;w==null&&(w=t.polygon.gverts.next);let O=Z;v=0;let k=w,g=w;for(;;){let E=g,M=m+1;if(M==t.polygon.edgeCnt&&(M=0),i[m])if(f[M]){let N=E.x-O.x,S=E.y-O.y,D=O.x-e.circle.worldCOMx,j=O.y-e.circle.worldCOMy,R=N*N+S*S,q=2*(D*N+j*S),G=D*D+j*j-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;$=O.x+(E.x-O.x)*H,X=O.y+(E.y-O.y)*H;let ee=C.x-$,W=C.y-X;if(ee*ee+W*W<s.Config.epsilon){v=0,g=k;break}let L;le.zpp_pool==null?L=new le:(L=le.zpp_pool,le.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=$,L.y=X;let F=L;be.flowsegs.add(be.flowpoly.head.elt),be.flowsegs.add(F),be.flowpoly.add(F),v=1,g=k;break}else{let N=0,S=0,D=E.x-O.x,j=E.y-O.y,R=O.x-e.circle.worldCOMx,q=O.y-e.circle.worldCOMy,G=D*D+j*j,B=2*(R*D+q*j),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?N=10:(S=-B/(2*G),N=S),$=!1):(Y=Math.sqrt(Y),G=1/(2*G),N=(-B-Y)*G,S=(-B+Y)*G,$=!0),N<1-s.Config.epsilon&&S>s.Config.epsilon){let X=0,H=0,ee=N;X=O.x+(E.x-O.x)*ee,H=O.y+(E.y-O.y)*ee;let W;if(C!=null){let A=C.x-X,J=C.y-H;W=A*A+J*J<s.Config.epsilon}else W=!1;if(W){v=0,g=k;break}let L;le.zpp_pool==null?L=new le:(L=le.zpp_pool,le.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=X,L.y=H;let F=L;if(be.flowpoly.head!=null&&(be.flowsegs.add(be.flowpoly.head.elt),be.flowsegs.add(F)),be.flowpoly.add(F),C==null&&(C=be.flowpoly.head.elt),$){let A=0,J=0,Q=S;A=O.x+(E.x-O.x)*Q,J=O.y+(E.y-O.y)*Q;let K=be.flowpoly,ne;le.zpp_pool==null?ne=new le:(ne=le.zpp_pool,le.zpp_pool=ne.next,ne.next=null),ne.weak=!1,ne._immutable=!1,ne.x=A,ne.y=J,K.add(ne)}}}O=E,Z=g,m=M,g=g.next,g==null&&(g=t.polygon.gverts.next);break}for(;g!=k;){let E=g,M=m+1;if(M==t.polygon.edgeCnt&&(M=0),i[m])if(f[M]){let N=E.x-O.x,S=E.y-O.y,D=O.x-e.circle.worldCOMx,j=O.y-e.circle.worldCOMy,R=N*N+S*S,q=2*(D*N+j*S),G=D*D+j*j-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;$=O.x+(E.x-O.x)*H,X=O.y+(E.y-O.y)*H;let ee=C.x-$,W=C.y-X;if(ee*ee+W*W<s.Config.epsilon){v=0,g=k;break}let L;le.zpp_pool==null?L=new le:(L=le.zpp_pool,le.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=$,L.y=X;let F=L;be.flowsegs.add(be.flowpoly.head.elt),be.flowsegs.add(F),be.flowpoly.add(F),v=1,g=k;break}else{let N=0,S=0,D=E.x-O.x,j=E.y-O.y,R=O.x-e.circle.worldCOMx,q=O.y-e.circle.worldCOMy,G=D*D+j*j,B=2*(R*D+q*j),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?N=10:(S=-B/(2*G),N=S),$=!1):(Y=Math.sqrt(Y),G=1/(2*G),N=(-B-Y)*G,S=(-B+Y)*G,$=!0),N<1-s.Config.epsilon&&S>s.Config.epsilon){let X=0,H=0,ee=N;X=O.x+(E.x-O.x)*ee,H=O.y+(E.y-O.y)*ee;let W;if(C!=null){let A=C.x-X,J=C.y-H;W=A*A+J*J<s.Config.epsilon}else W=!1;if(W){v=0,g=k;break}let L;le.zpp_pool==null?L=new le:(L=le.zpp_pool,le.zpp_pool=L.next,L.next=null),L.weak=!1,L._immutable=!1,L.x=X,L.y=H;let F=L;if(be.flowpoly.head!=null&&(be.flowsegs.add(be.flowpoly.head.elt),be.flowsegs.add(F)),be.flowpoly.add(F),C==null&&(C=be.flowpoly.head.elt),$){let A=0,J=0,Q=S;A=O.x+(E.x-O.x)*Q,J=O.y+(E.y-O.y)*Q;let K=be.flowpoly,ne;le.zpp_pool==null?ne=new le:(ne=le.zpp_pool,le.zpp_pool=ne.next,ne.next=null),ne.weak=!1,ne._immutable=!1,ne.x=A,ne.y=J,K.add(ne)}}}O=E,Z=g,m=M,g=g.next,g==null&&(g=t.polygon.gverts.next)}}if(be.flowpoly.head==null)return!1;if(be.flowpoly.head.next==null){let w=!0,O=t.polygon.edges.head;for(;O!=null;){let k=O.elt;if(k.gnormx*e.circle.worldCOMx+k.gnormy*e.circle.worldCOMy>k.gprojection){w=!1;break}O=O.next}return w?(n.overlap=e.circle.area,n.centroidx=e.circle.worldCOMx,n.centroidy=e.circle.worldCOMy,!0):!1}else{let w=0,O=0,k=0;if(be.flowpoly.head.next.next!=null){let E=0,M=0,N=0;E=0;let S=be.flowpoly.head,D=S.elt;S=S.next;let j=S.elt;for(S=S.next;S!=null;){let X=S.elt;E+=j.x*(X.y-D.y);let H=X.y*j.x-X.x*j.y;M+=(j.x+X.x)*H,N+=(j.y+X.y)*H,D=j,j=X,S=S.next}S=be.flowpoly.head;let R=S.elt;E+=j.x*(R.y-D.y);let q=R.y*j.x-R.x*j.y;M+=(j.x+R.x)*q,N+=(j.y+R.y)*q,D=j,j=R,S=S.next;let G=S.elt;E+=j.x*(G.y-D.y);let B=G.y*j.x-G.x*j.y;M+=(j.x+G.x)*B,N+=(j.y+G.y)*B,E*=.5;let Y=1/(6*E);M*=Y,N*=Y;let $=-E;w+=M*$,O+=N*$,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(),N=M.x-E.x,S=M.y-E.y,D=N,j=S,R=D*D+j*j,G=1/Math.sqrt(R);D*=G,j*=G;let B=D;D=-j,j=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=D*V+j*Y,ee=0,W=0,L=H,F=L/e.circle.radius,A=Math.sqrt(1-F*F),J=Math.acos(F);ee=e.circle.radius*(e.circle.radius*J-L*A),W=.6666666666666666*e.circle.radius*A*A*A/(J-F*A),V=e.circle.worldCOMx,Y=e.circle.worldCOMy;let Q=W;V+=D*Q,Y+=j*Q;let K=ee;w+=V*K,O+=Y*K,k+=ee}let g=1/k;return w*=g,O*=g,n.overlap=k,n.centroidx=w,n.centroidy=O,!0}}}else return!1}}else return!1}else{let i=e.circle,l=t.circle,o=l.worldCOMx-i.worldCOMx,a=l.worldCOMy-i.worldCOMy,r=i.radius+l.radius,p=o*o+a*a;if(p>r*r)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 y=0,_=0,d=0,f=0,z=u,P=z/i.radius,Z=Math.sqrt(1-P*P),m=Math.acos(P);y=i.radius*(i.radius*m-z*Z),_=.6666666666666666*i.radius*Z*Z*Z/(m-P*Z);let b=x,C=b/l.radius,v=Math.sqrt(1-C*C),w=Math.acos(C);d=l.radius*(l.radius*w-b*v),f=.6666666666666666*l.radius*v*v*v/(w-C*v);let O=y+d,k=(_*y+(c-f)*d)/O*h;n.overlap=O,n.centroidx=i.worldCOMx+o*k,n.centroidy=i.worldCOMy+a*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,a=s-t,r=o*o+a*a;if(r<1e-12)return 0;let p=((i-e)*o+(l-t)*a)/r;return p<0&&(p=0),p>1&&(p=1),p}static _closestTT(e,t,n,s,i,l,o,a){let r=n-e,p=s-t,c=o-i,h=a-l,u=e-i,x=t-l,y=r*r+p*p,_=c*c+h*h,d=c*u+h*x,f,z;if(y<1e-12&&_<1e-12)return[0,0];if(y<1e-12)return f=0,z=d/_,z<0&&(z=0),z>1&&(z=1),[f,z];let P=r*u+p*x;if(_<1e-12)return z=0,f=-P/y,f<0&&(f=0),f>1&&(f=1),[f,z];let Z=r*c+p*h,m=y*_-Z*Z;if(m>1e-12)f=(Z*d-P*_)/m,f<0&&(f=0),f>1&&(f=1),z=(Z*f+d)/_,z<0?(z=0,f=-P/y,f<0&&(f=0),f>1&&(f=1)):z>1&&(z=1,f=(Z-P)/y,f<0&&(f=0),f>1&&(f=1));else{let b=1/y,C=-(r*u+p*x)*b,v=C+Z*b,w=Math.max(0,Math.min(C,v)),O=Math.min(1,Math.max(C,v));f=w<=O?(w+O)*.5:C<0?0:1,z=(Z*f+d)/_,z<0&&(z=0),z>1&&(z=1)}return[f,z]}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){we.zpp_pool==null?s=new we:(s=we.zpp_pool,we.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 a=s;a.next=o.next,o.next=a,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),a=t.spine1y+l*(t.spine2y-t.spine1y),r=e.radius+t.radius,p=e.worldCOMx-o,c=e.worldCOMy-a,h=p*p+c*c;if(h>r*r)return!1;let u;if(h<i.Config.epsilon*i.Config.epsilon){let x=(e.worldCOMx+o)*.5,y=(e.worldCOMy+a)*.5;u=be._getOrCreateContact(n,0,n.stamp),u.px=x,u.py=y,n.nx=1,n.ny=0,u.dist=-r,u.stamp=n.stamp,u.posOnly=!1}else{let x=1/Math.sqrt(h),y=x<i.Config.epsilon?1e100:1/x,_=.5+(e.radius-.5*r)*x,d=e.worldCOMx-p*_,f=e.worldCOMy-c*_;u=be._getOrCreateContact(n,0,n.stamp),u.px=d,u.py=f,s?(n.nx=p*x,n.ny=c*x):(n.nx=-p*x,n.ny=-c*x),u.dist=y-r,u.stamp=n.stamp,u.posOnly=!1}if(u!=null){let x=u.inner,y=t.localCOMx+(2*l-1)*t.halfLength;return s?(x.lr1x=y,x.lr1y=t.localCOMy,x.lr2x=e.localCOMx,x.lr2y=e.localCOMy):(x.lr1x=e.localCOMx,x.lr1y=e.localCOMy,x.lr2x=y,x.lr2y=t.localCOMy),n.radius=r,n.ptype=2,!0}return!1}static _capsuleCapsuleContact(e,t,n,s,i){let l=e.radius+t.radius,o=i.Config.epsilon,a=(f,z,P)=>{let Z=e.spine1x+z*(e.spine2x-e.spine1x),m=e.spine1y+z*(e.spine2y-e.spine1y),b=t.spine1x+P*(t.spine2x-t.spine1x),C=t.spine1y+P*(t.spine2y-t.spine1y),v=b-Z,w=C-m,O=v*v+w*w;if(O>l*l)return!1;let k=be._getOrCreateContact(n,f,n.stamp);if(O<o*o)k.px=(Z+b)*.5,k.py=(m+C)*.5,f===0&&(n.nx=1,n.ny=0),k.dist=-l;else{let N=1/Math.sqrt(O),S=1/N,D=v*N,j=w*N,R=.5+(e.radius-.5*l)*N;k.px=Z+v*R,k.py=m+w*R,f===0&&(n.nx=s?-D:D,n.ny=s?-j:j),k.dist=S-l}k.stamp=n.stamp,k.posOnly=!1;let g=k.inner,E=e.localCOMx+(2*z-1)*e.halfLength,M=t.localCOMx+(2*P-1)*t.halfLength;return s?(g.lr1x=M,g.lr1y=t.localCOMy,g.lr2x=E,g.lr2y=e.localCOMy):(g.lr1x=E,g.lr1y=e.localCOMy,g.lr2x=M,g.lr2y=t.localCOMy),!0},[r,p]=be._closestTT(e.spine1x,e.spine1y,e.spine2x,e.spine2y,t.spine1x,t.spine1y,t.spine2x,t.spine2y);if(!a(0,r,p))return!1;if(n.radius=l,n.ptype=2,be.debugCapsule){let f=e.spine1x+r*(e.spine2x-e.spine1x),z=e.spine1y+r*(e.spine2y-e.spine1y),P=t.spine1x+p*(t.spine2x-t.spine1x),Z=t.spine1y+p*(t.spine2y-t.spine1y),m=P-f,b=Z-z,C=Math.sqrt(m*m+b*b);console.log("[capCap] nx=",n.nx.toFixed(3),"ny=",n.ny.toFixed(3),"dist=",C.toFixed(3),"minDist=",l.toFixed(3),"pen=",(C-l).toFixed(3))}let c=e.spine2x-e.spine1x,h=e.spine2y-e.spine1y,u=t.spine2x-t.spine1x,x=t.spine2y-t.spine1y,y=c*c+h*h,_=u*u+x*x,d=c*x-h*u;if(d*d<.01*y*_&&y>1e-12&&_>1e-12){let f=[[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]],z=0,P=null;for(let[Z,m]of f){let b=Z-r,C=b*b;if(C>z+1e-6){let v=e.spine1x+Z*(e.spine2x-e.spine1x),w=e.spine1y+Z*(e.spine2y-e.spine1y),O=t.spine1x+m*(t.spine2x-t.spine1x),k=t.spine1y+m*(t.spine2y-t.spine1y),g=O-v,E=k-w;g*g+E*E<=l*l&&(z=C,P=[Z,m])}}P!=null&&a(1,P[0],P[1])}return!0}static _polyCapsuleContact(e,t,n,s,i){let l=-1e100,o=null,a=null,r=!0,p=e.gverts.next,c=e.edges.head;for(;c!=null;){let k=c.elt,g=k.gnormx*t.spine1x+k.gnormy*t.spine1y,E=k.gnormx*t.spine2x+k.gnormy*t.spine2y,N=(g<E?g:E)-k.gprojection-t.radius;if(N>0){r=!1;break}N>l&&(l=N,o=k,a=p),p=p.next,c=c.next}if(!r)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),g=-u/k,E=h/k,M=g*t.spine1x+E*t.spine1y,N=1e100,S=-1e100,D=e.gverts.next;for(;D!=null;){let R=g*D.x+E*D.y;R<N&&(N=R),R>S&&(S=R),D=D.next}if((N>M+t.radius?N-(M+t.radius):S<M-t.radius?M-t.radius-S:0)>0)return!1}let y=a,_=a.next==null?e.gverts.next:a.next,d=y.y*o.gnormx-y.x*o.gnormy,f=_.y*o.gnormx-_.x*o.gnormy,z=k=>t.localCOMx+(2*k-1)*t.halfLength,P=(k,g)=>{k.lr1x=g,k.lr1y=t.localCOMy,k.lr2x=0,k.lr2y=0},Z=(k,g,E,M)=>{let S=o.gnormx*E+o.gnormy*M-o.gprojection-t.radius;if(S>0)return;let D=be._getOrCreateContact(n,k,n.stamp);D.px=E-o.gnormx*(t.radius+S*.5),D.py=M-o.gnormy*(t.radius+S*.5),D.dist=S,D.stamp=n.stamp,D.posOnly=!1,P(D.inner,z(g))},m=(k,g,E,M,N)=>{let S=M-g,D=N-E,j=S*S+D*D;if(j>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,j<i.Config.epsilon*i.Config.epsilon)R.px=g,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(j),G=1/q,B=S*q,V=D*q;R.px=g+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,P(R.inner,z(k)),!0},b=t.spine1y*o.gnormx-t.spine1x*o.gnormy,C=t.spine2y*o.gnormx-t.spine2x*o.gnormy,v=b>d&&b<f,w=C>d&&C<f;if(!v&&!w){let k=o.gnormx*t.spine1x+o.gnormy*t.spine1y,g=o.gnormx*t.spine2x+o.gnormy*t.spine2y;if(k<=g){if(b<=d){if(m(0,t.spine1x,t.spine1y,y.x,y.y))return!0}else if(m(0,t.spine1x,t.spine1y,_.x,_.y))return!0}else if(C<=d){if(m(1,t.spine2x,t.spine2y,y.x,y.y))return!0}else if(m(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=(d+f)*.5,N=t.spine1y*o.gnormx-t.spine1x*o.gnormy,D=t.spine2y*o.gnormx-t.spine2x*o.gnormy-N,j=Math.abs(D)>1e-12?(M-N)/D:.5;j<0&&(j=0),j>1&&(j=1);let R=t.spine1x+j*(t.spine2x-t.spine1x),q=t.spine1y+j*(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,j,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 O=0;return v&&Z(O++,0,t.spine1x,t.spine1y),w&&Z(O,1,t.spine2x,t.spine2y),be.debugCapsule&&O>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)),O>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,a=e.circle.worldCOMx-i,r=e.circle.worldCOMy-l;return a*a+r*r<=o*o}else if(e.type==1){let s=e.polygon.edges.head;for(;s!=null;){let a=s.elt,r=a.gnormx*n.spine1x+a.gnormy*n.spine1y,p=a.gnormx*n.spine2x+a.gnormy*n.spine2y;if((r<p?r:p)-a.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 a=-l,r=i,p=Math.sqrt(o),c=a/p,h=r/p,u=c*n.spine1x+h*n.spine1y,x=1e100,y=-1e100,_=e.polygon.gverts.next;for(;_!=null;){let d=c*_.x+h*_.y;d<x&&(x=d),d>y&&(y=d),_=_.next}if(x>u+n.radius||y<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),a=s.spine1y+i*(s.spine2y-s.spine1y),r=n.spine1x+l*(n.spine2x-n.spine1x),p=n.spine1y+l*(n.spine2y-n.spine1y),c=s.radius+n.radius,h=r-o,u=p-a;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.type==2?l.capsule:l,[x,y]=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),d=i.spine1y+x*(i.spine2y-i.spine1y),f=u.spine1x+y*(u.spine2x-u.spine1x),z=u.spine1y+y*(u.spine2y-u.spine1y),P=f-_,Z=z-d,m=Math.sqrt(P*P+Z*Z),b=i.radius+u.radius;if(m>=b)return!1;let C=b-m;return n.overlap=C*Math.min(2*i.radius,2*u.radius)*.5,n.buoyx=(_+f)*.5,n.buoyy=(d+z)*.5,!0}if(l.type==0){let u=l.circle||l.circle,x=be._closestT(i.spine1x,i.spine1y,i.spine2x,i.spine2y,u.worldCOMx,u.worldCOMy),y=i.spine1x+x*(i.spine2x-i.spine1x),_=i.spine1y+x*(i.spine2y-i.spine1y),d=u.worldCOMx-y,f=u.worldCOMy-_,z=Math.sqrt(d*d+f*f),P=i.radius+u.radius;if(z>=P)return!1;let Z=P-z;return n.overlap=Z*Math.min(2*i.radius,2*u.radius)*.5,n.buoyx=(y+u.worldCOMx)*.5,n.buoyy=(_+u.worldCOMy)*.5,!0}let a=l.polygon||l.polygon,r=1e100,p=0,c=0,h=a.edges.head;for(;h!=null;){let u=h.elt,x=u.gnormx*i.spine1x+u.gnormy*i.spine1y,y=u.gnormx*i.spine2x+u.gnormy*i.spine2y,_=x<y?x:y,d=u.gprojection+i.radius-_;if(d<0)return!1;d<r&&(r=d,p=u.gnormx,c=u.gnormy),h=h.next}return n.overlap=r*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 T{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,a=o.prev,r=null,p=o.diagonals.head;for(;p!=null;){let c=p.elt,h=p.next==null?o.next:p.next.elt;if(!T.isinner(h,o,a)){r=p,a=c,p=p.next;continue}let u=!0,x=c,y=x.prev,_=null,d=x.diagonals.head;for(;d!=null;){let f=d.elt;if(f==o){let z=d.next==null?x.next:d.next.elt;u=T.isinner(z,x,y);break}y=f,_=d,d=d.next}if(u){p=o.diagonals.erase(r),x.diagonals.erase(_);continue}a=c,r=p,p=p.next}if(l=l.next,l==i)break}}}};var tt=class tt{constructor(){this.normal=null;this.shape=null;this.convex=null;this.position=null;this.ray=null;this.inner=!1;this.next=null;this.toiDistance=0}static getRay(e,t,n,s){let i;tt.rayPool==null?(tt.internal=!0,i=tt._createRayResult(),i.zpp_inner=new tt,i.zpp_inner.ray=i,tt.internal=!1):(i=tt.rayPool.ray,tt.rayPool=tt.rayPool.next,i.zpp_inner.next=null);let l=i.zpp_inner;return l.normal=e,e.zpp_inner._immutable=!0,l.toiDistance=t,l.inner=n,l.shape=s,i}static getConvex(e,t,n,s){let i;tt.convexPool==null?(tt.internal=!0,i=tt._createConvexResult(),i.zpp_inner=new tt,i.zpp_inner.convex=i,tt.internal=!1):(i=tt.convexPool.convex,tt.convexPool=tt.convexPool.next,i.zpp_inner.next=null);let l=i.zpp_inner;return l.normal=e,l.position=t,e.zpp_inner._immutable=!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(){tt._disposeVec2(this.normal),this.position!=null&&tt._disposeVec2(this.position),this.shape=null,this.toiDistance=0,this.convex!=null?(this.next=tt.convexPool,tt.convexPool=this):(this.next=tt.rayPool,tt.rayPool=this)}static _disposeVec2(e){if(e.zpp_inner._immutable=!1,e!=null&&e.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let t=e.zpp_inner;if(t._immutable)throw new Error("Error: Vec2 is immutable");if(t._isimmutable!=null&&t._isimmutable(),t._inuse)throw new Error("Error: This Vec2 is not disposable");let n=e.zpp_inner;e.zpp_inner.outer=null,e.zpp_inner=null,e.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=e:xe.poolVec2=e,xe.nextVec2=e,e.zpp_disp=!0,n.outer!=null&&(n.outer.zpp_inner=null,n.outer=null),n._isimmutable=null,n._validate=null,n._invalidate=null,n.next=le.zpp_pool,le.zpp_pool=n}};tt.rayPool=null,tt.convexPool=null,tt.internal=!1,tt._createRayResult=null,tt._createConvexResult=null;var mn=tt;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 a;return ji.zpp_pool==null?a=new ji:(a=ji.zpp_pool,ji.zpp_pool=a.next,a.next=null),a.virtualint=l,a.end=t,a.start=n,a.path0=s,a.path1=i,a.time=e,a.vertex=o,a}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=le.zpp_pool,le.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;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,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(),a=o.__zpp;if(t!=null&&t.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=t.zpp_inner;r._validate!=null&&r._validate();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 y=n.zpp_inner;y._validate!=null&&y._validate();let _=n.zpp_inner.y-h,d=s?0:-1/0,f=i?1:1/0,z=-(h*x-p*_),P=null,Z=!1,m=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=m,B.posx=m.x,B.posy=m.y,B.value=B.posy*x-B.posx*_+z,B.positive=B.value>0,B.value==0&&(Z=!0);let V=B;if(P==null?V.prev=V.next=V:(V.prev=P,V.next=P.next,P.next.prev=V,P.next=V),P=V,m=m.next,m==e)break}if(Z){let B=null,V=P,Y=P;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 L=$;$=-X,X=L;let F=null,A=B;for(;;){if(A.value!=0&&(F==null||A==F.next)){if(F=A,A=A.next,A==B)break;continue}let J=F.value*A.value;if(J==0){if(A=A.next,A==B)break;continue}let Q=F.next,K;if(J>0)K=F.positive;else{let se=Q.next,ie,ae;ie=Q.posx+se.posx,ae=Q.posy+se.posy;let oe=.5;ie*=oe,ae*=oe;let he=ie+$*1e-8,pe=ae+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<pe&&ge.y>=pe||ge.y<pe&&me.y>=pe)&&(me.x<=he||ge.x<=he)&&me.x+(pe-me.y)/(ge.y-me.y)*(ge.x-me.x)<he&&(ce=!ce),de=de.next,de==ue)break}}K=ce}let ne=Q,re=A;if(ne!=null){let se=ne;for(;;){let ie=se;if(ie.positive=K,se=se.next,se==re)break}}if(F=A,A=A.next,A==B)break}for(;!(A.value!=0&&(F==null||A==F.next));){let J=F.value*A.value;if(J==0)break;let Q=F.next,K;if(J>0)K=F.positive;else{let se=Q.next,ie,ae;ie=Q.posx+se.posx,ae=Q.posy+se.posy;let oe=.5;ie*=oe,ae*=oe;let he=ie+$*1e-8,pe=ae+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<pe&&ge.y>=pe||ge.y<pe&&me.y>=pe)&&(me.x<=he||ge.x<=he)&&me.x+(pe-me.y)/(ge.y-me.y)*(ge.x-me.x)<he&&(ce=!ce),de=de.next,de==ue)break}}K=ce}let ne=Q,re=A;if(ne!=null){let se=ne;for(;;){let ie=se;if(ie.positive=K,se=se.next,se==re)break}}break}}$e.ints==null&&($e.ints=new a.util.ZNPList_ZPP_CutInt),$e.paths==null&&($e.paths=new a.util.ZNPList_ZPP_CutVert);let b=null,C=P.posx,v=P.posy,w;ve.zpp_pool==null?w=new ve:(w=ve.zpp_pool,ve.zpp_pool=w.next,w.next=null),w.forced=!1,w.x=C,w.y=v;let O=w;O.prev=O.next=O,b=O;let k=b,g;He.zpp_pool==null?g=new He:(g=He.zpp_pool,He.zpp_pool=g.next,g.next=null),g.vert=b,g.parent=g,g.rank=0,g.used=!1;let E=g;$e.paths.add(E);let M=P;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 L=p-M.posx,F=h-M.posy,A=(ee*L-H*F)*W;if(A<d||A>f){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 ne=X;b==null?(ne.prev=ne.next=ne,b=ne):(ne.next=b,ne.prev=b.prev,b.prev.next=ne,b.prev=ne)}else if(M.value==0){let J=b.prev;b=null;let Q=J.x,K=J.y,ne;ve.zpp_pool==null?ne=new ve:(ne=ve.zpp_pool,ve.zpp_pool=ne.next,ne.next=null),ne.forced=!1,ne.x=Q,ne.y=K;let re=ne;re.prev=re.next=re,b=re;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 ie=$e.paths.head.elt,ae=$e.paths,oe;He.zpp_pool==null?oe=new He:(oe=He.zpp_pool,He.zpp_pool=oe.next,oe.next=null),oe.vert=b,oe.parent=oe,oe.rank=0,oe.used=!1,ae.add(oe);let he=$e.paths.head.elt,pe=$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=ie,te.path1=he,te.time=A,te.vertex=!1,pe.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,ne=B.posy,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=K,re.y=ne;let se=re;se.prev=se.next=se,b=se;let ie=$e.paths.head.elt,ae=$e.paths,oe;He.zpp_pool==null?oe=new He:(oe=He.zpp_pool,He.zpp_pool=oe.next,oe.next=null),oe.vert=b,oe.parent=oe,oe.rank=0,oe.used=!1,ae.add(oe);let he=$e.paths.head.elt,pe=$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=ie,te.path1=he,te.time=A,te.vertex=!1,pe.add(te)}else{let J=(_*L-x*F)*W,Q,K;Q=M.posx,K=M.posy;let ne=J;Q+=H*ne,K+=ee*ne;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 se=re;b==null?(se.prev=se.next=se,b=se):(se.next=b,se.prev=b.prev,b.prev.next=se,b.prev=se);let ie=b.prev;b=null;let ae;ve.zpp_pool==null?ae=new ve:(ae=ve.zpp_pool,ve.zpp_pool=ae.next,ae.next=null),ae.forced=!1,ae.x=Q,ae.y=K;let oe=ae;oe.prev=oe.next=oe,b=oe;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 pe=$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=ie,ge.start=b,ge.path0=pe,ge.path1=ue,ge.time=A,ge.vertex=!1,de.add(ge)}}if(M=M.next,M==P)break}let N=b.prev;N.next.prev=k.prev,k.prev.next=N.next,N.next=k,k.prev=N;let S=$e.paths.head.elt,D;if(E==E.parent)D=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}D=B}let j;if(S==S.parent)j=S;else{let B=S,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}j=B}D!=j&&(D.rank<j.rank?D.parent=j:D.rank>j.rank?j.parent=D:(j.parent=D,D.rank++));let R=$e.ints;if(R.head!=null&&R.head.next!=null){let B=R.head,V,Y,$,X,H=1,ee,W,L;for(;;){for(ee=0,Y=B,B=null,V=B;Y!=null;){for(++ee,$=Y,W=0,L=H;$!=null&&W<H;)++W,$=$.next;for(;W>0||L>0&&$!=null;)W==0?(X=$,$=$.next,--L):L==0||$==null||Y.elt.time<$.elt.time?(X=Y,Y=Y.next,--W):(X=$,$=$.next,--L),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 L=B.path0,F=null;for(;L!=L.parent;){let A=L.parent;L.parent=F,F=L,L=A}for(;F!=null;){let A=F.parent;F.parent=L,F=A}X=L}let H;if(V.path1==V.path1.parent)H=V.path1;else{let L=V.path1,F=null;for(;L!=L.parent;){let A=L.parent;L.parent=F,F=L,L=A}for(;F!=null;){let A=F.parent;F.parent=L,F=A}H=L}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 L=B.path1,F=null;for(;L!=L.parent;){let A=L.parent;L.parent=F,F=L,L=A}for(;F!=null;){let A=F.parent;F.parent=L,F=A}ee=L}let W;if(V.path0==V.path0.parent)W=V.path0;else{let L=V.path0,F=null;for(;L!=L.parent;){let A=L.parent;L.parent=F,F=L,L=A}for(;F!=null;){let A=F.parent;F.parent=L,F=A}W=L}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 L=W.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=L.zpp_inner;if(F._immutable)throw new Error("Error: Vec2 is immutable");if(F._isimmutable!=null&&F._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let A=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let J=L;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=le.zpp_pool,le.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 L=V.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=F.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let Q=F;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L,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 L=V.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=F.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let Q=F;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L,W=null}else{let L=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 A=F.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 ne=Q;ne.outer!=null&&(ne.outer.zpp_inner=null,ne.outer=null),ne._isimmutable=null,ne._validate=null,ne._invalidate=null,ne.next=le.zpp_pool,le.zpp_pool=ne,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F,V.end=null,W=L}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 L=W;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=F.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let Q=F;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L}else{W.prev.next=W.next,W.next.prev=W.prev,W.next=W.prev=null;let L=W;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=F.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let Q=F;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L}}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,L=null;for(;W!=W.parent;){let F=W.parent;W.parent=L,L=W,W=F}for(;L!=null;){let F=L.parent;L.parent=W,L=F}H=W}let ee;if(V.path1==V.path1.parent)ee=V.path1;else{let W=V.path1,L=null;for(;W!=W.parent;){let F=W.parent;W.parent=L,L=W,W=F}for(;L!=null;){let F=L.parent;L.parent=W,L=F}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 L=W.wrap;if(L!=null&&L.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=L.zpp_inner;if(F._immutable)throw new Error("Error: Vec2 is immutable");if(F._isimmutable!=null&&F._isimmutable(),L.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let A=L.zpp_inner;L.zpp_inner.outer=null,L.zpp_inner=null;let J=L;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=le.zpp_pool,le.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 L=B.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=F.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let Q=F;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L,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 L=B.end;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=F.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let Q=F;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L,W=null}else{let L=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 A=F.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 ne=Q;ne.outer!=null&&(ne.outer.zpp_inner=null,ne.outer=null),ne._isimmutable=null,ne._validate=null,ne._invalidate=null,ne.next=le.zpp_pool,le.zpp_pool=ne,F.wrap=null}F.prev=F.next=null,F.next=ve.zpp_pool,ve.zpp_pool=F,B.end=null,W=L}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 L=W;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=F.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let Q=F;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L}else{W.prev.next=W.next,W.next.prev=W.prev,W.next=W.prev=null;let L=W;if(L.wrap!=null){L.wrap.zpp_inner._inuse=!1;let F=L.wrap;if(F!=null&&F.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let A=F.zpp_inner;if(A._immutable)throw new Error("Error: Vec2 is immutable");if(A._isimmutable!=null&&A._isimmutable(),F.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let J=F.zpp_inner;F.zpp_inner.outer=null,F.zpp_inner=null;let Q=F;Q.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=Q:xe.poolVec2=Q,xe.nextVec2=Q,Q.zpp_disp=!0;let K=J;K.outer!=null&&(K.outer.zpp_inner=null,K.outer=null),K._isimmutable=null,K._validate=null,K._invalidate=null,K.next=le.zpp_pool,le.zpp_pool=K,L.wrap=null}L.prev=L.next=null,L.next=ve.zpp_pool,ve.zpp_pool=L}}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,L=null;for(;W!=W.parent;){let F=W.parent;W.parent=L,L=W,W=F}for(;L!=null;){let F=L.parent;L.parent=W,L=F}H=W}let ee;if(B.path1==B.path1.parent)ee=B.path1;else{let W=B.path1,L=null;for(;W!=W.parent;){let F=W.parent;W.parent=L,L=W,W=F}for(;L!=null;){let F=L.parent;L.parent=W,L=F}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(;P!=null;)if(P!=null&&P.prev==P){P.next=P.prev=null;let B=P;B.vert=null,B.parent=null,B.next=He.zpp_pool,He.zpp_pool=B,P=null}else{let B=P.next;P.prev.next=P.next,P.next.prev=P.prev,P.next=P.prev=null;let V=P;V.vert=null,V.parent=null,V.next=He.zpp_pool,He.zpp_pool=V,P=B}return q}};$e.ints=null,$e.paths=null;var ss=$e;var ls=class T{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 r=t.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.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 r=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=r,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=r,i=i.next}let o=t.gverts.next,a=s.elt;a.gp0=l,a.gp1=o,a.gnormx=t.body.axisy*a.lnormx-t.body.axisx*a.lnormy,a.gnormy=a.lnormx*t.body.axisx+a.lnormy*t.body.axisy,a.gprojection=t.body.posx*a.gnormx+t.body.posy*a.gnormy+a.lprojection,a.wrap_gnorm!=null&&(a.wrap_gnorm.zpp_inner.x=a.gnormx,a.wrap_gnorm.zpp_inner.y=a.gnormy),a.tp0=a.gp0.y*a.gnormx-a.gp0.x*a.gnormy,a.tp1=a.gp1.y*a.gnormx-a.gp1.x*a.gnormy}}if(e.zip_aabb&&e.body!=null)if(e.zip_aabb=!1,e.type==0){let t=e.circle;T._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 a=o,r=l;l=l.next,a.x=t.body.posx+(t.body.axisy*r.x-t.body.axisx*r.y),a.y=t.body.posy+(r.x*t.body.axisx+r.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&&T._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&&T._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 a=n;t+=i.x*(a.y-s.y);let r=a.y*i.x-a.x*i.y;e.localCOMx+=(i.x+a.x)*r,e.localCOMy+=(i.y+a.y)*r,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 Pe=class Pe{static _init(e,t){Pe._zpp=e,Pe._nape=t,Pe.me=new Pe,Pe.look_march=[-1,224,56,216,14,-1,54,214,131,99,-1,91,141,109,181,85]}static _allocVert(e,t){let n;return 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=le.zpp_pool,le.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=Pe._findRoot(e),s=Pe._findRoot(t);n!=s&&(n.rank<s.rank?n.parent=s:n.rank>s.rank?s.parent=n:(s.parent=n,n.rank++))}static _pushVert(e,t){return e==null?t.prev=t.next=t:(t.prev=e,t.next=e.next,e.next.prev=t,e.next=t),t}static _isDegenKey(e){return e==1||e==4||e==16||e==64||e==3||e==12||e==48||e==192||e==129||e==6||e==24||e==96||e==5||e==20||e==80||e==65||e==17||e==68}static ISO(e,t,n){return e(t,n)}static run(e,t,n,s,i,l,o,a,r){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,a&&(Pe.map==null?Pe.map=new Xi(h,x):Pe.map.resize(h,x,null)),Pe.isos==null?Pe.isos=new Ki(h+1,x+1):Pe.isos.resize(h+1,x+1,0);for(let d=0;d<x+1;d++){let f;if(d==0)f=n;else if(d<=x){if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let z=l.zpp_inner;z._validate!=null&&z._validate(),f=n+l.zpp_inner.y*d}else f=i;for(let z=0;z<h+1;z++){let P;if(z==0)P=t;else if(z<=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(),P=t+l.zpp_inner.x*z}else P=s;let Z=Pe.isos,m=e(P,f);Z.list[d*Z.width+z]=m}}Pe.ints==null?Pe.ints=new Yi(h+1,(x<<1)+1):Pe.ints.resize(h+1,(x<<1)+1,null);let y=null;a&&(y=Pe._allocSpan(),y.next=null);let _=n;for(let d=0;d<x;d++){let f=_,z;if(d==x-1)z=i;else{if(l!=null&&l.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let m=l.zpp_inner;m._validate!=null&&m._validate(),z=n+l.zpp_inner.y*(d+1)}_=z;let P=t,Z=null;for(let m=0;m<h;m++){let b=P,C;if(m==h-1)C=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(),C=t+l.zpp_inner.x*(m+1)}P=C;let v=m==0||!a,w=d==0||!a,O=m==h-1||!a,k=d==x-1||!a,g=Pe.me.marchSquare(e,Pe.isos,Pe.ints,b,f,C,z,m,d,v,w,O,k,o);if(g==null){Z=null;continue}if(a){let E=g.p2!=null&&g.okey2!=14?g.p2:g.p1;g.pd=((E==g.p2?g.okey2:g.okey1)&128)==0?E.prev:E.prev.prev;let M=Pe.map;M.list[d*M.width+m]=g;let N;if(Z!=null){let j=g.key1,R=j&1|(j&192)>>5,q=0;(R&1)!=0&&++q,(R&2)!=0&&++q,(R&4)!=0&&++q,N=q>=2}else N=!1;N?(Pe.me.combLR(Z,g),g.span1=Z.spanr):(g.span1=Pe._allocSpan(),g.span1.next=y,y=g.span1),g.p2!=null?(g.span2=Pe._allocSpan(),g.span2.next=y,y=g.span2,g.spanr=g.span2):g.spanr=g.span1;let S=(g.keyr&28)>>2,D=0;(S&1)!=0&&++D,(S&2)!=0&&++D,(S&4)!=0&&++D,D>=2?Z=g:Z=null}else Pe.me.output(r,g.p1),g.p2!=null&&Pe.me.output(r,g.p2),Pe._freePair(g)}}if(a){for(let d=1;d<x;d++){let f=null;for(let z=0;z<h;z++){let P=Pe.map,Z=P.list[d*P.width+z];if(Z==null){f=null;continue}let b=(Z.p2!=null&&Z.okey2==14?Z.okey2:Z.okey1)&7,C=0;if((b&1)!=0&&++C,(b&2)!=0&&++C,(b&4)!=0&&++C,C<2){f=null;continue}let v=Pe.map,w=v.list[(d-1)*v.width+z];if(w==null){f=null;continue}let k=((w.p2!=null&&w.okey2==56?w.okey2:w.okey1)&112)>>4,g=0;if((k&1)!=0&&++g,(k&2)!=0&&++g,(k&4)!=0&&++g,g<2){f=null;continue}let E=w.p2!=null&&w.okey2==56?w.span2:w.span1,M=Z.p2!=null&&Z.okey2==14?Z.span2:Z.span1,N=Pe._findRoot(E),S=Pe._findRoot(M);N==S?f!=M&&Pe.me.combUD_virtual(w,Z):(Pe._union(E,M),Pe.me.combUD(w,Z)),f=((M==Z.span2?Z.okey2:Z.okey1)&4)!=0?M:null}}for(let d=0;d<x;d++)for(let f=0;f<h;f++){let z=Pe.map,P=z.list[d*z.width+f];if(P==null)continue;let Z=Pe._findRoot(P.span1);Z.out||(Z.out=!0,Pe.me.output(r,P.p1)),P.p2!=null&&(Z=Pe._findRoot(P.span2),Z.out||(Z.out=!0,Pe.me.output(r,P.p2))),Pe._freePair(P),z.list[d*z.width+f]=null}for(;y!=null;){let d=y;y=d.next;let f=d;f.parent=f,f.next=An.zpp_pool,An.zpp_pool=f}}}output(e,t){let n=Pe._nape,s;if(t==null||t.next==t||t.next==t.prev)s=!0;else{let o=0,a=t,r=t;if(a!=null){let c=a;for(;;){let h=c;if(o+=h.x*(h.next.y-h.prev.y),c=c.next,c==r)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,a=i.next,r=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,Pe._freeVert(i)):(i.next=o.next,o.next.prev=i),Pe._freeVert(o),(e.keyr&16)!=0?(t.pd=a.next,a.next.prev=r.prev,r.prev.next=a.next,Pe._freeVert(a)):(a.prev=r.prev,r.prev.next=a),Pe._freeVert(r)}combUD(e,t){let n=e.pd,s=t.p2!=null&&t.key2==14?t.p2:t.p1,i=n.prev,l=s.next;s.next=n.next,n.next.prev=s,Pe._freeVert(n),l.prev=i.prev,i.prev.next=l,i==e.p1&&(e.p1=l),Pe._freeVert(i)}combUD_virtual(e,t){let n=e.pd,s=t.p2!=null&&t.key2==14?t.p2:t.p1,i=n.prev,l=s.next;n.forced=s.forced=i.forced=l.forced=!0}combLeft(e){let t=e&1|(e&192)>>5,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combRight(e){let t=(e&28)>>2,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combUp(e){let t=e&7,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}combDown(e){let t=(e&112)>>4,n=0;return(t&1)!=0&&++n,(t&2)!=0&&++n,(t&4)!=0&&++n,n>=2}comb(e){let t=0;return(e&1)!=0&&++t,(e&2)!=0&&++t,(e&4)!=0&&++t,t>=2}_buildPoly(e,t,n,s,i,l,o,a,r,p,c,h,u,x,y,_,d,f,z){let P=null;for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let m;if(Z==0)m=Pe._allocVert(s,i),(x||y)&&(m.forced=!0);else if(Z==2)m=Pe._allocVert(l,i),(_||y)&&(m.forced=!0);else if(Z==4)m=Pe._allocVert(l,o),(_||d)&&(m.forced=!0);else if(Z==6)m=Pe._allocVert(s,o),(x||d)&&(m.forced=!0);else if(Z==1){if(m=n.list[(r<<1)*n.width+a],m==null){let b=this.xlerp(s,l,i,p,c,f,z);m=Pe._allocVert(b,i),n.list[(r<<1)*n.width+a]=m}else m=Pe._allocVert(m.x,m.y);y&&(m.forced=!0),(m.x==s||m.x==l)&&(m.x==s&&(e&1)!=0||m.x==l&&(e&4)!=0)&&(e^=2)}else if(Z==5){if(m=n.list[((r<<1)+2)*n.width+a],m==null){let b=this.xlerp(s,l,o,u,h,f,z);m=Pe._allocVert(b,o),n.list[((r<<1)+2)*n.width+a]=m}else m=Pe._allocVert(m.x,m.y);d&&(m.forced=!0),(m.x==s||m.x==l)&&(m.x==s&&(e&64)!=0||m.x==l&&(e&16)!=0)&&(e^=32)}else if(Z==3){if(m=n.list[((r<<1)+1)*n.width+(a+1)],m==null){let b=this.ylerp(i,o,l,c,h,f,z);m=Pe._allocVert(l,b),n.list[((r<<1)+1)*n.width+(a+1)]=m}else m=Pe._allocVert(m.x,m.y);_&&(m.forced=!0),(m.y==i||m.y==o)&&(m.y==i&&(e&4)!=0||m.y==o&&(e&16)!=0)&&(e^=8)}else{if(m=n.list[((r<<1)+1)*n.width+a],m==null){let b=this.ylerp(i,o,s,p,u,f,z);m=Pe._allocVert(s,b),n.list[((r<<1)+1)*n.width+a]=m}else m=Pe._allocVert(m.x,m.y);x&&(m.forced=!0),(m.y==i||m.y==o)&&(m.y==i&&(e&1)!=0||m.y==o&&(e&64)!=0)&&(e^=128)}P=Pe._pushVert(P,m)}return P!=null&&(P=P.next),{head:P,val:e}}marchSquare(e,t,n,s,i,l,o,a,r,p,c,h,u,x){let y=0,_=t.list[r*t.width+a];_<0&&(y|=8);let d=t.list[r*t.width+(a+1)];d<0&&(y|=4);let f=t.list[(r+1)*t.width+(a+1)];f<0&&(y|=2);let z=t.list[(r+1)*t.width+a];if(z<0&&(y|=1),y==0)return null;let P=Pe._allocPair();if(y!=10&&y!=5){let Z=Pe.look_march[y];P.okey1=Z;let m=this._buildPoly(Z,t,n,s,i,l,o,a,r,_,d,f,z,p,c,h,u,e,x);P.p1=m.head,Z=m.val,P.key1=Z,Pe._isDegenKey(Z)&&(Z=0,P.key1=0,P.p1=null),Z==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let Z=e(.5*(s+l),.5*(i+o))<0;if(y==10)if(Z){let m=187;P.okey1=m;let b=this._buildPoly(m,t,n,s,i,l,o,a,r,_,d,f,z,p,c,h,u,e,x);P.p1=b.head,m=b.val,P.key1=m,Pe._isDegenKey(m)&&(m=0,P.key1=0,P.p1=null),m==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let m=131;P.okey1=m;let b=this._buildPoly(m,t,n,s,i,l,o,a,r,_,d,f,z,p,c,h,u,e,x);if(P.p1=b.head,m=b.val,P.key1=m,Pe._isDegenKey(m)&&(m=0,P.key1=0,P.p1=null),m!=0){let C=56;P.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,o,a,r,_,d,f,z,p,c,h,u,e,x,P).val,P.key2=C,Pe._isDegenKey(C)&&(C=0,P.key2=0,P.p2=null),C==0?(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1):(P.pr=P.p2,P.okeyr=P.okey2,P.keyr=P.key2)}else{let C=56;P.okey1=C;let v=this._buildPoly(C,t,n,s,i,l,o,a,r,_,d,f,z,p,c,h,u,e,x);P.p1=v.head,C=v.val,P.key1=C,Pe._isDegenKey(C)&&(C=0,P.key1=0,P.p1=null),C==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}}else if(Z){let m=238;P.okey1=m;let b=this._buildPoly(m,t,n,s,i,l,o,a,r,_,d,f,z,p,c,h,u,e,x);P.p1=b.head,m=b.val,P.key1=m,Pe._isDegenKey(m)&&(m=0,P.key1=0,P.p1=null),m==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}else{let m=224;P.okey1=m;let b=this._buildPoly(m,t,n,s,i,l,o,a,r,_,d,f,z,p,c,h,u,e,x);if(P.p1=b.head,m=b.val,P.key1=m,Pe._isDegenKey(m)&&(m=0,P.key1=0,P.p1=null),m!=0){let C=14;P.okey2=C,C=this._buildPoly2(C,t,n,s,i,l,o,a,r,_,d,f,z,p,c,h,u,e,x,P).val,P.key2=C,Pe._isDegenKey(C)&&(C=0,P.key2=0,P.p2=null),C==0?(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1):(P.pr=P.p2,P.okeyr=P.okey2,P.keyr=P.key2)}else{let C=14;P.okey1=C;let v=this._buildPoly(C,t,n,s,i,l,o,a,r,_,d,f,z,p,c,h,u,e,x);P.p1=v.head,C=v.val,P.key1=C,Pe._isDegenKey(C)&&(C=0,P.key1=0,P.p1=null),C==0?P=null:(P.pr=P.p1,P.okeyr=P.okey1,P.keyr=P.key1)}}}return P}_buildPoly2(e,t,n,s,i,l,o,a,r,p,c,h,u,x,y,_,d,f,z,P){for(let Z=0;Z<8;Z++)if((e&1<<Z)!=0){let m;if(Z==0)m=Pe._allocVert(s,i),(x||y)&&(m.forced=!0);else if(Z==2)m=Pe._allocVert(l,i),(_||y)&&(m.forced=!0);else if(Z==4)m=Pe._allocVert(l,o),(_||d)&&(m.forced=!0);else if(Z==6)m=Pe._allocVert(s,o),(x||d)&&(m.forced=!0);else if(Z==1){if(m=n.list[(r<<1)*n.width+a],m==null){let C=this.xlerp(s,l,i,p,c,f,z);m=Pe._allocVert(C,i),n.list[(r<<1)*n.width+a]=m}else m=Pe._allocVert(m.x,m.y);y&&(m.forced=!0),(m.x==s||m.x==l)&&(m.x==s&&(e&1)!=0||m.x==l&&(e&4)!=0)&&(e^=2)}else if(Z==5){if(m=n.list[((r<<1)+2)*n.width+a],m==null){let C=this.xlerp(s,l,o,u,h,f,z);m=Pe._allocVert(C,o),n.list[((r<<1)+2)*n.width+a]=m}else m=Pe._allocVert(m.x,m.y);d&&(m.forced=!0),(m.x==s||m.x==l)&&(m.x==s&&(e&64)!=0||m.x==l&&(e&16)!=0)&&(e^=32)}else if(Z==3){if(m=n.list[((r<<1)+1)*n.width+(a+1)],m==null){let C=this.ylerp(i,o,l,c,h,f,z);m=Pe._allocVert(l,C),n.list[((r<<1)+1)*n.width+(a+1)]=m}else m=Pe._allocVert(m.x,m.y);_&&(m.forced=!0),(m.y==i||m.y==o)&&(m.y==i&&(e&4)!=0||m.y==o&&(e&16)!=0)&&(e^=8)}else{if(m=n.list[((r<<1)+1)*n.width+a],m==null){let C=this.ylerp(i,o,s,p,u,f,z);m=Pe._allocVert(s,C),n.list[((r<<1)+1)*n.width+a]=m}else m=Pe._allocVert(m.x,m.y);x&&(m.forced=!0),(m.y==i||m.y==o)&&(m.y==i&&(e&1)!=0||m.y==o&&(e&64)!=0)&&(e^=128)}let b=m;P.p2==null?P.p2=b.prev=b.next=b:(b.prev=P.p2,b.next=P.p2.next,P.p2.next.prev=b,P.p2.next=b),P.p2=b}return P.p2!=null&&(P.p2=P.p2.next),{val:e}}lerp(e,t,n,s){let i=Pe._nape;if(n==0)return e;if(s==0)return t;{let l=n-s,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 a=Pe._nape,r;if(s==0)r=e;else if(i==0)r=t;else{let p=s-i,c=p*p<a.Config.epsilon*a.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),r=e+c*(t-e)}for(;o--!=0&&e<r&&r<t;){let p=l(r,n);if(p==0)break;if(s*p<0?(t=r,i=p):(e=r,s=p),s==0)r=e;else if(i==0)r=t;else{let c=s-i,h=c*c<a.Config.epsilon*a.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),r=e+h*(t-e)}}return r}ylerp(e,t,n,s,i,l,o){let a=Pe._nape,r;if(s==0)r=e;else if(i==0)r=t;else{let p=s-i,c=p*p<a.Config.epsilon*a.Config.epsilon?.5:s/p;c<0?c=0:c>1&&(c=1),r=e+c*(t-e)}for(;o--!=0&&e<r&&r<t;){let p=l(n,r);if(p==0)break;if(s*p<0?(t=r,i=p):(e=r,s=p),s==0)r=e;else if(i==0)r=t;else{let c=s-i,h=c*c<a.Config.epsilon*a.Config.epsilon?.5:s/c;h<0?h=0:h>1&&(h=1),r=e+h*(t-e)}}return r}};Pe.isos=null,Pe.ints=null,Pe.map=null,Pe._zpp=null,Pe._nape=null;var ks=Pe;var cn=class cn{constructor(){this.outer=null;this.a=0;this.b=0;this.c=0;this.d=0;this.tx=0;this.ty=0;this._invalidate=null;this.next=null}static get(){let e;return cn.zpp_pool==null?e=new cn:(e=cn.zpp_pool,cn.zpp_pool=e.next,e.next=null),e}static identity(){let e=cn.get();return e.setas(1,0,0,1,0,0),e}wrapper(){if(this.outer==null)if(cn._wrapFn)this.outer=cn._wrapFn(this);else{this.outer=new cn._nape.geom.Mat23;let e=this.outer.zpp_inner;e.next=cn.zpp_pool,cn.zpp_pool=e,this.outer.zpp_inner=this}return this.outer}invalidate(){this._invalidate!=null&&this._invalidate()}set(e){this.setas(e.a,e.b,e.c,e.d,e.tx,e.ty)}setas(e,t,n,s,i,l){this.tx=i,this.ty=l,this.a=e,this.b=t,this.c=n,this.d=s}free(){}alloc(){}};cn._nape=null,cn._wrapFn=null,cn.zpp_pool=null;var 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,a=e.next.x,r=t.x,p=t.next.x;return(o>a?o:a)>(r>p?r: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 a=o.head,r,p,c,h,u=1,x,y,_;for(;;){for(x=0,p=a,a=null,r=a;p!=null;){for(++x,c=p,y=0,_=u;c!=null&&y<u;)++y,c=c.next;for(;y>0||_>0&&c!=null;){if(y==0)h=c,c=c.next,--_;else if(_==0||c==null)h=p,p=p.next,--y;else{let d;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 f=s*e-n*t;d=(f>0?-1:f==0?0:1)==1}else{e=this.prev.x-this.x,t=this.prev.y-this.y,n=p.elt.x-this.x,s=p.elt.y-this.y;let f=s*e-n*t,z=f>0?-1:f==0?0:1;e=this.prev.x-this.x,t=this.prev.y-this.y,n=c.elt.x-this.x,s=c.elt.y-this.y;let P=s*e-n*t,Z=P>0?-1:P==0?0:1;if(z*Z==1||z*Z==0&&(z==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 m=s*e-n*t;d=(m>0?-1:m==0?0:1)==1}else if(z==-1||Z==-1)d=Z==-1;else if(z==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 m=e*n+t*s;n=c.elt.x-this.x,s=c.elt.y-this.y;let b=e*n+t*s;d=m<0&&b>0?!0:!(b<0&&m>0)}else d=!0}d?(h=p,p=p.next,--y):(h=c,c=c.next,--_)}r!=null?r.next=h:a=h,r=h}p=c}if(r.next=null,u<<=1,!(x>1))break}o.head=a,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 a=o;if(t+=a.x*(a.next.y-a.prev.y),o=o.next,o==s)break}}let i=t*.5>0,l=e;for(;;){let o;if(i){let a;Ge.zpp_pool==null?a=new Ge:(a=Ge.zpp_pool,Ge.zpp_pool=a.next,a.next=null),a.x=l.x,a.y=l.y;let r=a;this.vertices==null?this.vertices=r.prev=r.next=r:(r.prev=this.vertices,r.next=this.vertices.next,this.vertices.next.prev=r,this.vertices.next=r),o=r}else{let a;Ge.zpp_pool==null?a=new Ge:(a=Ge.zpp_pool,Ge.zpp_pool=a.next,a.next=null),a.x=l.x,a.y=l.y;let r=a;this.vertices==null?this.vertices=r.prev=r.next=r:(r.next=this.vertices,r.prev=this.vertices.prev,this.vertices.prev.next=r,this.vertices.prev=r),o=r}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,r=(e.next.y-e.y)*i-o*l;if(r*r>=_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 a=this.vertices;a.helper=null,a.next=Ge.zpp_pool,Ge.zpp_pool=a,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 a;Ge.zpp_pool==null?a=new Ge:(a=Ge.zpp_pool,Ge.zpp_pool=a.next,a.next=null),a.x=s.x,a.y=s.y,a.forced=s.forced;let r=a;if(n.vertices==null?n.vertices=r.prev=r.next=r:(r.prev=n.vertices,r.next=n.vertices.next,n.vertices.next.prev=r,n.vertices.next=r),n.vertices=r,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 a=l;for(;;){let r=a;if(i+=r.x*(r.next.y-r.prev.y),a=a.next,a==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 r=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=r,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 r=l;for(;;){let p=r;if(i+=p.x*(p.next.y-p.prev.y),r=r.next,r==o)break}}let a=i*.5;if(a*a>=_e().Config.epsilon*_e().Config.epsilon){let r=n,p=!0;for(;p||r!=n;){p=!1;let c=r.x-r.next.x,h=r.y-r.next.y;if(c*c+h*h<_e().Config.epsilon*_e().Config.epsilon){if(r==n&&(n=r.next,p=!0),r.forced&&(r.next.forced=!0),r!=null&&r.prev==r)r.next=r.prev=null,r=null;else{let u=r.next;r.prev.next=r.next,r.next.prev=r.prev,r.next=r.prev=null,r=u}if(r==null){n=null;break}}else r=r.next}if(n!=null){let c;for(;;){for(c=!1,r=n,p=!0;p||r!=n;){p=!1;let h=r.prev,u=r.x-h.x,x=r.y-h.y,y=r.next.x-r.x,d=(r.next.y-r.y)*u-y*x;if(d*d>=_e().Config.epsilon*_e().Config.epsilon)r=r.next;else{if(r==n&&(n=r.next,p=!0),r!=null&&r.prev==r)r.next=r.prev=null,r=null;else{let f=r.next;r.prev.next=r.next,r.next.prev=r.prev,r.next=r.prev=null,r=f}if(c=!0,r==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,a;le.zpp_pool==null?a=new le:(a=le.zpp_pool,le.zpp_pool=a.next,a.next=null),a.weak=!1,a._immutable=!1,a.x=-i-o,a.y=s+l;let r=a,p=r.x*r.x+r.y*r.y,h=1/Math.sqrt(p);return r.x*=h,r.y*=h,o*s-l*i<0&&(r.x=-r.x,r.y=-r.y),r}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=le.zpp_pool,le.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=le.zpp_pool,le.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 a=s;for(;;){let r=a;if(r.y<t.y&&(t=r),r.y>n.y&&(n=r),a=a.next,a==i)break}}let l=!0,o=t;if(n!=t.next){let a=t.next,r=n;if(a!=null){let p=a;for(;;){let c=p;if(c.y<o.y){l=!1;break}if(o=c,p=p.next,p==r)break}}}if(!l)return!1;if(o=t,n!=t.prev){let a=t.prev,r=n;if(a!=null){let p=a;for(;;){let c=p;if(c.y<o.y){l=!1;break}if(o=c,p=p.prev,p==r)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 a=o.next.x-o.x,r=o.next.y-o.y,p=o.prev.x-o.x,h=(o.prev.y-o.y)*a-p*r>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,a,r,p,c=1,h,u,x;for(;;){for(h=0,a=l,l=null,o=l;a!=null;){for(++h,r=a,u=0,x=c;r!=null&&u<c;)++u,r=r.next;for(;u>0||x>0&&r!=null;)u==0?(p=r,r=r.next,--x):x==0||r==null||De.above(a.elt,r.elt)?(p=a,a=a.next,--u):(p=r,r=r.next,--x),o!=null?o.next=p:l=p,o=p;a=r}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 a=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)){a=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 r=a;if(r!=null){if(r.helper==null)throw new Error("Fatal error (4): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),r.helper=l}break}case 3:{let o=null;if(!De.edges.empty()){let r=De.edges.parent;for(;r.prev!=null;)r=r.prev;for(;r!=null;){let p=r.data;if(!Ge.vert_lt(p,l)){o=p;break}if(r.next!=null)for(r=r.next;r.prev!=null;)r=r.prev;else{for(;r.parent!=null&&r==r.parent.next;)r=r.parent;r=r.parent}}}let a=o;if(a!=null){if(a.helper==null)throw new Error("Fatal error (2): Polygon is not weakly-simple and clockwise");t.add_diagonal(l,a.helper),a.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 a=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)){a=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 r=a;if(r==null||r.helper==null)throw new Error("Fatal error (6): Polygon is not weakly-simple and clockwise");r.helper.type==2&&t.add_diagonal(l,r.helper),r.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;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=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;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=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;le.zpp_pool==null?i=new le:(i=le.zpp_pool,le.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=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 a=i;s+=o.x*(a.y-l.y);let r=a.y*o.x-a.x*o.y;n.localCOMx+=(o.x+a.x)*r,n.localCOMy+=(o.y+a.y)*r,l=o,o=a,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),a=s*s+i*i-e.radius*e.radius,r=o*o-4*l*a;if(r==0){let p=-o/2*l;if((!t||a>0)&&p>0&&p<n&&p<=this.maxdist){let c=this._circleNormal(p,e,a<=0),h=Vt._allocVec2(c.nx,c.ny);return mn.getRay(h,p,a<=0,e.outer)}else return null}else{r=Math.sqrt(r),l=1/(2*l);let p=(-o-r)*l,c=(-o+r)*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),a=s*s+i*i-e.radius*e.radius,r=o*o-4*l*a;if(r==0){let p=-o/2*l;if((!t||a>0)&&p>0&&p<=this.maxdist){let c=this._circleNormal(p,e,a<=0),h=Vt._allocVec2(c.nx,c.ny),u=mn.getRay(h,p,a<=0,e.outer);Vt._insertSorted(n,u)}}else{r=Math.sqrt(r),l=1/(2*l);let p=(-o-r)*l,c=(-o+r)*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,a=!0,r=e.gverts.next,p=r,c=r.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,y=h.y-p.y,_=p.x-this.originx,d=p.y-this.originy,f=y*this.dirx-x*this.diry;if(f*f>s.Config.epsilon){f=1/f;let z=(y*_-x*d)*f;if(z>0&&z<i&&z<=this.maxdist){let P=(this.diry*_-this.dirx*d)*f;P>-s.Config.epsilon&&P<1+s.Config.epsilon&&(i=z,l=o.elt)}}}o=o.next,p=h,c=c.next}if(a){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,y=h.y-p.y,_=p.x-this.originx,d=p.y-this.originy,f=y*this.dirx-x*this.diry;if(f*f>s.Config.epsilon){f=1/f;let z=(y*_-x*d)*f;if(z>0&&z<i&&z<=this.maxdist){let P=(this.diry*_-this.dirx*d)*f;P>-s.Config.epsilon&&P<1+s.Config.epsilon&&(i=z,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 y=Vt._allocVec2(h,u);return mn.getRay(y,i,x,e.outer)}else return null}polysect2(e,t,n){let s=_e(),i=1/0,l=-1,o=null,a=null,r=e.edges.head,p=!0,c=e.gverts.next,h=c,u=c.next;for(;u!=null;){let x=u,y=r.elt;if(t||y.gnormx*this.dirx+y.gnormy*this.diry<0){let _=x.x-h.x,d=x.y-h.y,f=h.x-this.originx,z=h.y-this.originy,P=d*this.dirx-_*this.diry;if(P*P>s.Config.epsilon){P=1/P;let Z=(d*f-_*z)*P;if(Z>0&&Z<=this.maxdist&&(Z<i||Z>l)){let m=(this.diry*f-this.dirx*z)*P;m>-s.Config.epsilon&&m<1+s.Config.epsilon&&(Z<i&&(i=Z,o=r.elt),Z>l&&(l=Z,a=r.elt))}}}r=r.next,h=x,u=u.next}if(p){u=e.gverts.next;let x=u,y=r.elt;if(t||y.gnormx*this.dirx+y.gnormy*this.diry<0){let _=x.x-h.x,d=x.y-h.y,f=h.x-this.originx,z=h.y-this.originy,P=d*this.dirx-_*this.diry;if(P*P>s.Config.epsilon){P=1/P;let Z=(d*f-_*z)*P;if(Z>0&&Z<=this.maxdist&&(Z<i||Z>l)){let m=(this.diry*f-this.dirx*z)*P;m>-s.Config.epsilon&&m<1+s.Config.epsilon&&(Z<i&&(i=Z,o=r.elt),Z>l&&(l=Z,a=r.elt))}}}}if(o!=null){let x=o.gnormx,y=o.gnormy,_=x*this.dirx+y*this.diry>0;_&&(x=-x,y=-y);let d=Vt._allocVec2(x,y),f=mn.getRay(d,i,_,e.outer);Vt._insertSorted(n,f)}if(a!=null&&o!=a){let x=a.gnormx,y=a.gnormy,_=x*this.dirx+y*this.diry>0;_&&(x=-x,y=-y);let d=Vt._allocVec2(x,y),f=mn.getRay(d,l,_,e.outer);Vt._insertSorted(n,f)}}};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,a,r,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,a=s.y-n.y,r=i.x-n.x,p=i.y-n.y,(c?a*r-o*p:p*o-r*a)<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,a=l.y-i.y,r=n.x-i.x,p=n.y-i.y,h=(c?a*r-o*p:p*o-r*a)<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,a=s.y-n.y,r=l.x-n.x,p=l.y-n.y,(c?a*r-o*p:p*o-r*a)<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,a=s.y-n.y,r=i.x-n.x,p=i.y-n.y,(c?a*r-o*p:p*o-r*a)<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,a=l.y-i.y,r=n.x-i.x,p=n.y-i.y;let h=c?a*r-o*p:p*o-r*a;c=l.x<i.x,o=l.x-i.x,a=l.y-i.y,r=s.x-i.x,p=s.y-i.y;let u=c?a*r-o*p:p*o-r*a;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,a=s.y-n.y,r=i.x-n.x,p=i.y-n.y;let h=c?a*r-o*p:p*o-r*a;c=s.x<n.x,o=s.x-n.x,a=s.y-n.y,r=l.x-n.x,p=l.y-n.y;let u=c?a*r-o*p:p*o-r*a;return h*u>=0?h<0:this.sweepx<i.x}else{c=s.x<n.x,o=s.x-n.x,a=s.y-n.y,r=i.x-n.x,p=i.y-n.y;let h=(c?a*r-o*p:p*o-r*a)<0;c=s.x<n.x,o=s.x-n.x,a=s.y-n.y,r=l.x-n.x,p=l.y-n.y;let u=(c?a*r-o*p:p*o-r*a)<0;if(h==u)return h;{c=l.x<i.x,o=l.x-i.x,a=l.y-i.y,r=n.x-i.x,p=n.y-i.y;let x=(c?a*r-o*p:p*o-r*a)>=0;c=l.x<i.x,o=l.x-i.x,a=l.y-i.y,r=s.x-i.x,p=s.y-i.y;let y=(c?a*r-o*p:p*o-r*a)>=0;if(x==y)return x;let _=(this.sweepx-n.x)/(s.x-n.x)*(s.y-n.y)+n.y,d=(this.sweepx-i.x)/(l.x-i.x)*(l.y-i.y)+i.y;return _>d}}}clear(){this.tree.clear()}add(e){e.node=this.tree.insert(e);let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);return t!=null&&(e.next=t.data,t.data.prev=e),n!=null&&(e.prev=n.data,n.data.next=e),e}remove(e){let t=this.tree.successor_node(e.node),n=this.tree.predecessor_node(e.node);t!=null&&(t.data.prev=e.prev),n!=null&&(n.data.next=e.next),this.tree.remove_node(e.node),e.node=null}intersect(e,t){if(e==null||t==null)return!1;if(e.left==t.left||e.left==t.right||e.right==t.left||e.right==t.right)return!1;{let n=e.left,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),a=(l.x-n.x)*(s.y-n.y)-(s.x-n.x)*(l.y-n.y);if(o*a>0)return!1;{let r=(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!(r*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,a=s.y-n.y,r=l.x-i.x,p=l.y-i.y,c=p*o-r*a;if(c==0)return null;c=1/c;let h=i.x-n.x,u=i.y-n.y,x=(p*h-r*u)*c;if(x<0||x>1)return null;let y=(a*h-o*u)*c;if(y<0||y>1)return null;let _;if(y==0||y==1||x==0||x==1){let z=y==0;if(y==1&&z)throw new Error("corner case 1a");if(y==1&&(z=!0),x==0&&z)throw new Error("corner case 1b");if(x==0&&(z=!0),x==1&&z)throw new Error("corner case 1c");_=y==0?i:y==1?l:x==0?n:s}else{let z=.5*(n.x+o*x+i.x+r*y),P=.5*(n.y+a*x+i.y+p*y),Z;ke.zpp_pool==null?Z=new ke:(Z=ke.zpp_pool,ke.zpp_pool=Z.next,Z.next=null),Z.x=z,Z.y=P,_=Z}let d;Ce.zpp_pool==null?d=new Ce:(d=Ce.zpp_pool,Ce.zpp_pool=d.next,d.next=null),d.vertex=_;let f=d;return f.type=0,f.segment=e,f.segment2=t,f}}};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 y=x,_=y.x,d=y.y,f;ke.zpp_pool==null?f=new ke:(f=ke.zpp_pool,ke.zpp_pool=f.next,f.next=null),f.x=_,f.y=d;let z=f,P=ye.vertices.parent;for(;P!=null;)if(ye.vertices.lt(z,P.data))P=P.prev;else if(ye.vertices.lt(P.data,z))P=P.next;else break;let Z=P;if(Z!=null){let m=z;m.links.clear(),m.node=null,m.forced=!1,m.next=ke.zpp_pool,ke.zpp_pool=m,z=Z.data}else z.node=ye.vertices.insert(z);if(s!=null){let m;Ce.zpp_pool==null?m=new Ce:(m=Ce.zpp_pool,Ce.zpp_pool=m.next,m.next=null),m.vertex=s;let b=m,C;Ce.zpp_pool==null?C=new Ce:(C=Ce.zpp_pool,Ce.zpp_pool=C.next,C.next=null),C.vertex=z;let v=C,w;Ce.less_xy(b,v)?(b.type=1,v.type=2,w=At.get(s,z)):(b.type=2,v.type=1,w=At.get(z,s)),b.segment=v.segment=w,ye.queue.insert(b),ye.queue.insert(v),s.links.insert(z),z.links.insert(s)}if(s=z,n==null&&(n=z),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 a=o,r;Ce.zpp_pool==null?r=new Ce:(r=Ce.zpp_pool,Ce.zpp_pool=r.next,r.next=null),r.vertex=n;let p=r,c;for(Ce.less_xy(a,p)?(a.type=1,p.type=2,c=At.get(s,n)):(a.type=2,p.type=1,c=At.get(n,s)),a.segment=p.segment=c,ye.queue.insert(a),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 d=ye.sweep.intersection(_.next,_);if(d!=null)if(d.vertex.x>=ye.sweep.sweepx){let f=ye.queue.parent;for(;f!=null;)if(ye.queue.lt(d,f.data))f=f.prev;else if(ye.queue.lt(f.data,d))f=f.next;else break;let z=f;if(z==null){let P=ye.ints.parent;for(;P!=null;)if(ye.ints.lt(d,P.data))P=P.prev;else if(ye.ints.lt(P.data,d))P=P.next;else break;let Z=P;if(Z!=null){let m=d.vertex;m.links.clear(),m.node=null,m.forced=!1,m.next=ke.zpp_pool,ke.zpp_pool=m,d.vertex=Z.data.vertex,Z.data=d,ye.queue.insert(d)}else ye.queue.insert(d),ye.ints.insert(d);if(_.next.id<_.id){let m=ye.inthash,b=_.next.id,C=_.id,v;Be.zpp_pool==null?v=new Be:(v=Be.zpp_pool,Be.zpp_pool=v.next,v.next=null),v.id=b,v.di=C;let w=v;w.value=!0,m.add(w)}else{let m=ye.inthash,b=_.id,C=_.next.id,v;Be.zpp_pool==null?v=new Be:(v=Be.zpp_pool,Be.zpp_pool=v.next,v.next=null),v.id=b,v.di=C;let w=v;w.value=!0,m.add(w)}}else{let P=z.data;if(P.segment!=d.segment||d.segment2!=P.segment2)throw new Error("corner case 2, shiiiit.");let Z=d.vertex;Z.links.clear(),Z.node=null,Z.forced=!1,Z.next=ke.zpp_pool,ke.zpp_pool=Z;let m=d;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Ce.zpp_pool,Ce.zpp_pool=m}}else{let f=d.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f;let z=d;z.vertex=null,z.segment=z.segment2=null,z.node=null,z.next=Ce.zpp_pool,Ce.zpp_pool=z}}if(_!=null&&_.prev!=null&&!(_.id<_.prev.id?ye.inthash.has(_.id,_.prev.id):ye.inthash.has(_.prev.id,_.id))){let d=ye.sweep.intersection(_,_.prev);if(d!=null)if(d.vertex.x>=ye.sweep.sweepx){let f=ye.queue.parent;for(;f!=null;)if(ye.queue.lt(d,f.data))f=f.prev;else if(ye.queue.lt(f.data,d))f=f.next;else break;let z=f;if(z==null){let P=ye.ints.parent;for(;P!=null;)if(ye.ints.lt(d,P.data))P=P.prev;else if(ye.ints.lt(P.data,d))P=P.next;else break;let Z=P;if(Z!=null){let m=d.vertex;m.links.clear(),m.node=null,m.forced=!1,m.next=ke.zpp_pool,ke.zpp_pool=m,d.vertex=Z.data.vertex,Z.data=d,ye.queue.insert(d)}else ye.queue.insert(d),ye.ints.insert(d);if(_.id<_.prev.id){let m=ye.inthash,b=_.id,C=_.prev.id,v;Be.zpp_pool==null?v=new Be:(v=Be.zpp_pool,Be.zpp_pool=v.next,v.next=null),v.id=b,v.di=C;let w=v;w.value=!0,m.add(w)}else{let m=ye.inthash,b=_.prev.id,C=_.id,v;Be.zpp_pool==null?v=new Be:(v=Be.zpp_pool,Be.zpp_pool=v.next,v.next=null),v.id=b,v.di=C;let w=v;w.value=!0,m.add(w)}}else{let P=z.data;if(P.segment!=d.segment||d.segment2!=P.segment2)throw new Error("corner case 2, shiiiit.");let Z=d.vertex;Z.links.clear(),Z.node=null,Z.forced=!1,Z.next=ke.zpp_pool,ke.zpp_pool=Z;let m=d;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Ce.zpp_pool,Ce.zpp_pool=m}}else{let f=d.vertex;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f;let z=d;z.vertex=null,z.segment=z.segment2=null,z.node=null,z.next=Ce.zpp_pool,Ce.zpp_pool=z}}}else if(x.type==2){let _=x.segment;if(_.node!=null){let d=_.next,f=_.prev;ye.sweep.remove(_);let z=_;if(z.left=z.right=null,z.prev=null,z.node=null,z.vertices.clear(),z.next=At.zpp_pool,At.zpp_pool=z,d!=null&&f!=null&&!(d.id<f.id?ye.inthash.has(d.id,f.id):ye.inthash.has(f.id,d.id))){let P=ye.sweep.intersection(d,f);if(P!=null)if(P.vertex.x>=ye.sweep.sweepx){let Z=ye.queue.parent;for(;Z!=null;)if(ye.queue.lt(P,Z.data))Z=Z.prev;else if(ye.queue.lt(Z.data,P))Z=Z.next;else break;let m=Z;if(m==null){let b=ye.ints.parent;for(;b!=null;)if(ye.ints.lt(P,b.data))b=b.prev;else if(ye.ints.lt(b.data,P))b=b.next;else break;let C=b;if(C!=null){let v=P.vertex;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v,P.vertex=C.data.vertex,C.data=P,ye.queue.insert(P)}else ye.queue.insert(P),ye.ints.insert(P);if(d.id<f.id){let v=ye.inthash,w=d.id,O=f.id,k;Be.zpp_pool==null?k=new Be:(k=Be.zpp_pool,Be.zpp_pool=k.next,k.next=null),k.id=w,k.di=O;let g=k;g.value=!0,v.add(g)}else{let v=ye.inthash,w=f.id,O=d.id,k;Be.zpp_pool==null?k=new Be:(k=Be.zpp_pool,Be.zpp_pool=k.next,k.next=null),k.id=w,k.di=O;let g=k;g.value=!0,v.add(g)}}else{let b=m.data;if(b.segment!=P.segment||P.segment2!=b.segment2)throw new Error("corner case 2, shiiiit.");let C=P.vertex;C.links.clear(),C.node=null,C.forced=!1,C.next=ke.zpp_pool,ke.zpp_pool=C;let v=P;v.vertex=null,v.segment=v.segment2=null,v.node=null,v.next=Ce.zpp_pool,Ce.zpp_pool=v}}else{let Z=P.vertex;Z.links.clear(),Z.node=null,Z.forced=!1,Z.next=ke.zpp_pool,ke.zpp_pool=Z;let m=P;m.vertex=null,m.segment=m.segment2=null,m.node=null,m.next=Ce.zpp_pool,Ce.zpp_pool=m}}}}else{let _=x.vertex,d=_.node==null,f=x.segment,z=x.segment2;if(z.next!=f){let C=f;f=z,z=C}let P=f.vertices.parent;for(;P!=null;)if(f.vertices.lt(_,P.data))P=P.prev;else if(f.vertices.lt(P.data,_))P=P.next;else break;let Z=P==null,m=z.vertices.parent;for(;m!=null;)if(z.vertices.lt(_,m.data))m=m.prev;else if(z.vertices.lt(m.data,_))m=m.next;else break;let b=m==null;if(Z){let C=f.vertices.insert(_),v=_==f.left?_:f.vertices.predecessor_node(C).data,w=_==f.right?_:f.vertices.successor_node(C).data;v.links.remove(w),_!=v&&v.links.insert(_),w.links.remove(v),_!=w&&w.links.insert(_),_!=v&&_.links.insert(v),_!=w&&_.links.insert(w)}if(b){let C=z.vertices.insert(_),v=_==z.left?_:z.vertices.predecessor_node(C).data,w=_==z.right?_:z.vertices.successor_node(C).data;v.links.remove(w),_!=v&&v.links.insert(_),w.links.remove(v),_!=w&&w.links.insert(_),_!=v&&_.links.insert(v),_!=w&&_.links.insert(w)}if(d&&(_.node=ye.vertices.insert(_)),_.forced=!0,d){let C=f.node,v=z.node;C.data=z,v.data=f,f.node=v,z.node=C,z.next=f.next,f.next=z,f.prev=z.prev,z.prev=f,f.prev!=null&&(f.prev.next=f),z.next!=null&&(z.next.prev=z)}if(z.next!=null&&z!=null&&!(z.next.id<z.id?ye.inthash.has(z.next.id,z.id):ye.inthash.has(z.id,z.next.id))){let C=ye.sweep.intersection(z.next,z);if(C!=null)if(C.vertex.x>=ye.sweep.sweepx){let v=ye.queue.parent;for(;v!=null;)if(ye.queue.lt(C,v.data))v=v.prev;else if(ye.queue.lt(v.data,C))v=v.next;else break;let w=v;if(w==null){let O=ye.ints.parent;for(;O!=null;)if(ye.ints.lt(C,O.data))O=O.prev;else if(ye.ints.lt(O.data,C))O=O.next;else break;let k=O;if(k!=null){let g=C.vertex;g.links.clear(),g.node=null,g.forced=!1,g.next=ke.zpp_pool,ke.zpp_pool=g,C.vertex=k.data.vertex,k.data=C,ye.queue.insert(C)}else ye.queue.insert(C),ye.ints.insert(C);if(z.next.id<z.id){let g=ye.inthash,E=z.next.id,M=z.id,N;Be.zpp_pool==null?N=new Be:(N=Be.zpp_pool,Be.zpp_pool=N.next,N.next=null),N.id=E,N.di=M;let S=N;S.value=!0,g.add(S)}else{let g=ye.inthash,E=z.id,M=z.next.id,N;Be.zpp_pool==null?N=new Be:(N=Be.zpp_pool,Be.zpp_pool=N.next,N.next=null),N.id=E,N.di=M;let S=N;S.value=!0,g.add(S)}}else{let O=w.data;if(O.segment!=C.segment||C.segment2!=O.segment2)throw new Error("corner case 2, shiiiit.");let k=C.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=ke.zpp_pool,ke.zpp_pool=k;let g=C;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Ce.zpp_pool,Ce.zpp_pool=g}}else{let v=C.vertex;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v;let w=C;w.vertex=null,w.segment=w.segment2=null,w.node=null,w.next=Ce.zpp_pool,Ce.zpp_pool=w}}if(f!=null&&f.prev!=null&&!(f.id<f.prev.id?ye.inthash.has(f.id,f.prev.id):ye.inthash.has(f.prev.id,f.id))){let C=ye.sweep.intersection(f,f.prev);if(C!=null)if(C.vertex.x>=ye.sweep.sweepx){let v=ye.queue.parent;for(;v!=null;)if(ye.queue.lt(C,v.data))v=v.prev;else if(ye.queue.lt(v.data,C))v=v.next;else break;let w=v;if(w==null){let O=ye.ints.parent;for(;O!=null;)if(ye.ints.lt(C,O.data))O=O.prev;else if(ye.ints.lt(O.data,C))O=O.next;else break;let k=O;if(k!=null){let g=C.vertex;g.links.clear(),g.node=null,g.forced=!1,g.next=ke.zpp_pool,ke.zpp_pool=g,C.vertex=k.data.vertex,k.data=C,ye.queue.insert(C)}else ye.queue.insert(C),ye.ints.insert(C);if(f.id<f.prev.id){let g=ye.inthash,E=f.id,M=f.prev.id,N;Be.zpp_pool==null?N=new Be:(N=Be.zpp_pool,Be.zpp_pool=N.next,N.next=null),N.id=E,N.di=M;let S=N;S.value=!0,g.add(S)}else{let g=ye.inthash,E=f.prev.id,M=f.id,N;Be.zpp_pool==null?N=new Be:(N=Be.zpp_pool,Be.zpp_pool=N.next,N.next=null),N.id=E,N.di=M;let S=N;S.value=!0,g.add(S)}}else{let O=w.data;if(O.segment!=C.segment||C.segment2!=O.segment2)throw new Error("corner case 2, shiiiit.");let k=C.vertex;k.links.clear(),k.node=null,k.forced=!1,k.next=ke.zpp_pool,ke.zpp_pool=k;let g=C;g.vertex=null,g.segment=g.segment2=null,g.node=null,g.next=Ce.zpp_pool,Ce.zpp_pool=g}}else{let v=C.vertex;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v;let w=C;w.vertex=null,w.segment=w.segment2=null,w.node=null,w.next=Ce.zpp_pool,Ce.zpp_pool=w}}ye.ints.remove(x)}let y=x;y.vertex=null,y.segment=y.segment2=null,y.node=null,y.next=Ce.zpp_pool,Ce.zpp_pool=y}let h=0,u=ye.inthash.table.length;for(;h<u;){let x=h++,y=ye.inthash.table[x];if(y!=null){for(;y!=null;){let _=y.hnext;y.hnext=null;let d=y;d.next=Be.zpp_pool,Be.zpp_pool=d,y=_}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,a=l.data,r=o.data,p=s.x-a.x,c=s.y-a.y,h=r.x-s.x;(r.y-s.y)*p-h*c<0&&(r=a);let x=s.x,y=s.y,_;ve.zpp_pool==null?_=new ve:(_=ve.zpp_pool,ve.zpp_pool=_.next,_.next=null),_.forced=!1,_.x=x,_.y=y;let d=_;if(n==null)d.prev=d.next=d;else{let z=n,P=z.next;d.prev=z,d.next=P,P.prev=d,z.next=d}for(n=d,n.forced=s.forced;;){if(s.links.remove(r),r.links.remove(s),r==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 z=r.x,P=r.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=z,Z.y=P;let m=Z;if(n==null)m.prev=m.next=m;else{let b=n,C=b.next;m.prev=b,m.next=C,C.prev=m,b.next=m}if(n=m,n.forced=r.forced,r.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=r,r=r.links.parent.data}else{let b=null,C=0;if(!r.links.empty()){let v=r.links.parent;for(;v.prev!=null;)v=v.prev;for(;v!=null;){let w=v.data;if(b==null){b=w;let O=r.x-s.x,k=r.y-s.y,g=w.x-r.x;C=(w.y-r.y)*O-g*k}else{let O=r.x-s.x,k=r.y-s.y,g=w.x-r.x,M=(w.y-r.y)*O-g*k;if(M>0&&C<=0)b=w,C=M;else if(C*M>=0){let N=r.x-w.x,S=r.y-w.y,D=b.x-r.x;(b.y-r.y)*N-D*S>0&&(b=w,C=M)}}if(v.next!=null)for(v=v.next;v.prev!=null;)v=v.prev;else{for(;v.parent!=null&&v==v.parent.next;)v=v.parent;v=v.parent}}}if(s.links.empty()){e.remove(s);let v=s;v.links.clear(),v.node=null,v.forced=!1,v.next=ke.zpp_pool,ke.zpp_pool=v}s=r,r=b}}e.remove(i);let f=i;f.links.clear(),f.node=null,f.forced=!1,f.next=ke.zpp_pool,ke.zpp_pool=f,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 d=_,f=d.x,z=d.y,P;if(ke.zpp_pool==null?P=new ke:(P=ke.zpp_pool,ke.zpp_pool=P.next,P.next=null),P.x=f,P.y=z,t.add(P),_=_.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,d;Ce.zpp_pool==null?d=new Ce:(d=Ce.zpp_pool,Ce.zpp_pool=d.next,d.next=null),d.vertex=o;let f=i.add(d),z;Ce.zpp_pool==null?z=new Ce:(z=Ce.zpp_pool,Ce.zpp_pool=z.next,z.next=null),z.vertex=_;let P=i.add(z),Z;Ce.less_xy(f,P)?(f.type=1,P.type=2,Z=At.get(o,_)):(f.type=2,P.type=1,Z=At.get(_,o)),f.segment=P.segment=Z,o=_,l=l.next}let a=t.head.elt,r;Ce.zpp_pool==null?r=new Ce:(r=Ce.zpp_pool,Ce.zpp_pool=r.next,r.next=null),r.vertex=o;let p=i.add(r),c;Ce.zpp_pool==null?c=new Ce:(c=Ce.zpp_pool,Ce.zpp_pool=c.next,c.next=null),c.vertex=a;let h=i.add(c),u;Ce.less_xy(p,h)?(p.type=1,h.type=2,u=At.get(o,a)):(p.type=2,h.type=1,u=At.get(a,o)),p.segment=h.segment=u;let x=i;if(x.head!=null&&x.head.next!=null){let _=x.head,d,f,z,P,Z=1,m,b,C;for(;;){for(m=0,f=_,_=null,d=null;f!=null;){for(++m,z=f,b=0,C=Z;z!=null&&b<Z;)++b,z=z.next;for(;b>0||C>0&&z!=null;)b==0?(P=z,z=z.next,--C):C==0||z==null||Ce.less_xy(f.elt,z.elt)?(P=f,f=f.next,--b):(P=z,z=z.next,--C),d!=null?d.next=P:_=P,d=P;f=z}if(d.next=null,Z<<=1,!(m>1))break}x.head=_,x.modified=!0,x.pushmod=!0}let y=!0;for(;i.head!=null;){let _=i.pop_unsafe(),d=_.segment;if(_.type==1){if(ye.sweep.add(d),ye.sweep.intersect(d,d.next)||ye.sweep.intersect(d,d.prev)){y=!1;break}}else if(_.type==2){if(ye.sweep.intersect(d.prev,d.next)){y=!1;break}ye.sweep.remove(d);let z=d;z.left=z.right=null,z.prev=null,z.node=null,z.vertices.clear(),z.next=At.zpp_pool,At.zpp_pool=z}let f=_;f.vertex=null,f.segment=f.segment2=null,f.node=null,f.next=Ce.zpp_pool,Ce.zpp_pool=f}for(;i.head!=null;){let _=i.pop_unsafe();if(_.type==2){let f=_.segment;f.left=f.right=null,f.prev=null,f.node=null,f.vertices.clear(),f.next=At.zpp_pool,At.zpp_pool=f}let d=_;d.vertex=null,d.segment=d.segment2=null,d.node=null,d.next=Ce.zpp_pool,Ce.zpp_pool=d}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 y}};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 r=(l*s+o*i)/(s*s+i*i);if(r<=0)return l*l+o*o;if(r>=1){let p=e.x-n.x,c=e.y-n.y;return p*p+c*c}else{let p=r;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,a=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=a.x,p.y=a.y,p.flag=!1;let c=p;if(c.forced=a.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)),a=a.next,a==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,y;Te.zpp_pool==null?y=new Te:(y=Te.zpp_pool,Te.zpp_pool=y.next,y.next=null),y.min=o,y.max=s,x.add(y)}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,y;Te.zpp_pool==null?y=new Te:(y=Te.zpp_pool,Te.zpp_pool=y.next,y.next=null),y.min=o,y.max=i,x.add(y)}}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,y=null,_=c.next;for(;_!=h;){let d=It.distance(_,c,h);d>x&&(x=d,y=_),_=_.next}if(y!=null){y.flag=!0;let d=It.stack,f;Te.zpp_pool==null?f=new Te:(f=Te.zpp_pool,Te.zpp_pool=f.next,f.next=null),f.min=c,f.max=y,d.add(f);let z=It.stack,P;Te.zpp_pool==null?P=new Te:(P=Te.zpp_pool,Te.zpp_pool=P.next,P.next=null),P.min=y,P.max=h,z.add(P)}}let r=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;r==null?u.prev=u.next=u:(u.prev=r,u.next=r.next,r.next.prev=u,r.next=u),r=u,r.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 r}};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=new le,this.c2=new le,this.axis=new le}alloc(){this.failed=!1,this.s1=this.s2=null,this.arbiter=null}free(){}};Ns.zpp_pool=null;function pt(T){return T.type===0||T.type===2}function Ft(T){return T.type===0?T.circle.radius:T.capsule.halfLength+T.capsule.radius}var gn=class{static dynamicSweep(e,t,n,s,i){let l=_e();i==null&&(i=!1);let o=e.s1,a=e.s2,r=o.body,p=a.body,c=0,h=0;c=p.velx-r.velx,h=p.vely-r.vely;let u=r.angvel;u<0&&(u=-u);let x=p.angvel;x<0&&(x=-x);let y=o.sweepCoef*u+a.sweepCoef*x;if(!i&&!e.kinematic&&c*c+h*h<l.Config.dynamicSweepLinearThreshold*l.Config.dynamicSweepLinearThreshold&&y<l.Config.dynamicSweepAngularThreshold){e.toi=-1,e.failed=!0;return}let _=e.c1,d=e.c2,f=e.axis,z=n,P=0;for(;;){let M=z*t,N=M-r.sweepTime;if(N!=0){r.sweepTime=M;let X=N;if(r.posx+=r.velx*X,r.posy+=r.vely*X,r.angvel!=0){let H=r.sweep_angvel*N;if(r.rot+=H,H*H>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let ee=H*H,W=1-.5*ee,L=1-ee*ee/8,F=(W*r.axisx+H*r.axisy)*L;r.axisy=(W*r.axisy-H*r.axisx)*L,r.axisx=F}}}if(o.type==0||o.type===2)o.worldCOMx=r.posx+(r.axisy*o.localCOMx-r.axisx*o.localCOMy),o.worldCOMy=r.posy+(o.localCOMx*r.axisx+o.localCOMy*r.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=r.posx+(r.axisy*K.x-r.axisx*K.y),Q.y=r.posy+(K.x*r.axisx+K.y*r.axisy),ee=ee.next}let W=X.edges.head,L=X.gverts.next,F=L;for(L=L.next;L!=null;){let Q=L,K=W.elt;W=W.next,K.gnormx=r.axisy*K.lnormx-r.axisx*K.lnormy,K.gnormy=K.lnormx*r.axisx+K.lnormy*r.axisy,K.gprojection=r.posx*K.gnormx+r.posy*K.gnormy+K.lprojection,K.tp0=F.y*K.gnormx-F.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,F=Q,L=L.next}let A=X.gverts.next,J=W.elt;W=W.next,J.gnormx=r.axisy*J.lnormx-r.axisx*J.lnormy,J.gnormy=J.lnormx*r.axisx+J.lnormy*r.axisy,J.gprojection=r.posx*J.gnormx+r.posy*J.gnormy+J.lprojection,J.tp0=F.y*J.gnormx-F.x*J.gnormy,J.tp1=A.y*J.gnormx-A.x*J.gnormy}let S=z*t,D=S-p.sweepTime;if(D!=0){p.sweepTime=S;let X=D;if(p.posx+=p.velx*X,p.posy+=p.vely*X,p.angvel!=0){let H=p.sweep_angvel*D;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,L=1-ee*ee/8,F=(W*p.axisx+H*p.axisy)*L;p.axisy=(W*p.axisy-H*p.axisx)*L,p.axisx=F}}}if(a.type==0||a.type===2)a.worldCOMx=p.posx+(p.axisy*a.localCOMx-p.axisx*a.localCOMy),a.worldCOMy=p.posy+(a.localCOMx*p.axisx+a.localCOMy*p.axisy);else{let X=a.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,L=X.gverts.next,F=L;for(L=L.next;L!=null;){let Q=L,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=F.y*K.gnormx-F.x*K.gnormy,K.tp1=Q.y*K.gnormx-Q.x*K.gnormy,F=Q,L=L.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=F.y*J.gnormx-F.x*J.gnormy,J.tp1=A.y*J.gnormx-A.x*J.gnormy}let j=o,R=a,q=_,G=d;var Z;if(pt(j)&&pt(R)){let X=j.circle||j.capsule,H=R.circle||R.capsule,ee=Ft(j),W=Ft(R);var m;let L=0,F=0;L=H.worldCOMx-X.worldCOMx,F=H.worldCOMy-X.worldCOMy;let A=Math.sqrt(L*L+F*F);if(m=A-(ee+W),m<1e100){if(A==0)L=1,F=0;else{let K=1/A;L*=K,F*=K}let J=ee;q.x=X.worldCOMx+L*J,q.y=X.worldCOMy+F*J;let Q=-W;G.x=H.worldCOMx+L*Q,G.y=H.worldCOMy+F*Q,f.x=L,f.y=F}Z=m}else{let X=!1;if(pt(j)&&R.type==1){let H=j;j=R,R=H;let ee=q;q=G,G=ee,X=!0}if(j.type==1&&pt(R)){let H=j.polygon,ee=R.circle||R.capsule,W=Ft(R),L=-1e100,F=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){L=Q;break}Q>0?Q>L&&(L=Q,F=J):L<0&&Q>L&&(L=Q,F=J),A=A.next}if(L<1e100){let J=F.gp0,Q=F.gp1,K=ee.worldCOMy*F.gnormx-ee.worldCOMx*F.gnormy;if(K<=J.y*F.gnormx-J.x*F.gnormy){let ne=0,re=0;ne=ee.worldCOMx-J.x,re=ee.worldCOMy-J.y;let se=Math.sqrt(ne*ne+re*re);if(L=se-W,L<1e100){if(se==0)ne=1,re=0;else{let oe=1/se;ne*=oe,re*=oe}let ie=0;q.x=J.x+ne*ie,q.y=J.y+re*ie;let ae=-W;G.x=ee.worldCOMx+ne*ae,G.y=ee.worldCOMy+re*ae,f.x=ne,f.y=re}}else if(K>=Q.y*F.gnormx-Q.x*F.gnormy){let ne=0,re=0;ne=ee.worldCOMx-Q.x,re=ee.worldCOMy-Q.y;let se=Math.sqrt(ne*ne+re*re);if(L=se-W,L<1e100){if(se==0)ne=1,re=0;else{let oe=1/se;ne*=oe,re*=oe}let ie=0;q.x=Q.x+ne*ie,q.y=Q.y+re*ie;let ae=-W;G.x=ee.worldCOMx+ne*ae,G.y=ee.worldCOMy+re*ae,f.x=ne,f.y=re}}else{let ne=-W;G.x=ee.worldCOMx+F.gnormx*ne,G.y=ee.worldCOMy+F.gnormy*ne;let re=-L;q.x=G.x+F.gnormx*re,q.y=G.y+F.gnormy*re,f.x=F.gnormx,f.y=F.gnormy}}X&&(f.x=-f.x,f.y=-f.y),Z=L}else{let H=j.polygon,ee=R.polygon,W=-1e100,L=null,F=null,A=0,J=H.edges.head;for(;J!=null;){let Q=J.elt,K=1e100,ne=ee.gverts.next;for(;ne!=null;){let re=ne,se=Q.gnormx*re.x+Q.gnormy*re.y;se<K&&(K=se),ne=ne.next}if(K-=Q.gprojection,K>1e100){W=K;break}K>0?K>W&&(W=K,L=Q,A=1):W<0&&K>W&&(W=K,L=Q,A=1),J=J.next}if(W<1e100){let Q=ee.edges.head;for(;Q!=null;){let K=Q.elt,ne=1e100,re=H.gverts.next;for(;re!=null;){let se=re,ie=K.gnormx*se.x+K.gnormy*se.y;ie<ne&&(ne=ie),re=re.next}if(ne-=K.gprojection,ne>1e100){W=ne;break}ne>0?ne>W&&(W=ne,F=K,A=2):W<0&&ne>W&&(W=ne,F=K,A=2),Q=Q.next}if(W<1e100){var b,C,v;if(A==1)b=H,C=ee,v=L;else{b=ee,C=H,v=F;let se=q;q=G,G=se,X=!X}let K=null,ne=1e100,re=C.edges.head;for(;re!=null;){let se=re.elt,ie=v.gnormx*se.gnormx+v.gnormy*se.gnormy;ie<ne&&(ne=ie,K=se),re=re.next}if(X?(f.x=-v.gnormx,f.y=-v.gnormy):(f.x=v.gnormx,f.y=v.gnormy),W>=0){let se=v.gp0,ie=v.gp1,ae=K.gp0,oe=K.gp1,he=0,pe=0,ce=0,te=0;he=ie.x-se.x,pe=ie.y-se.y,ce=oe.x-ae.x,te=oe.y-ae.y;let ue=1/(he*he+pe*pe),de=1/(ce*ce+te*te),me=-(he*(se.x-ae.x)+pe*(se.y-ae.y))*ue,ge=-(he*(se.x-oe.x)+pe*(se.y-oe.y))*ue,Se=-(ce*(ae.x-se.x)+te*(ae.y-se.y))*de,Ae=-(ce*(ae.x-ie.x)+te*(ae.y-ie.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+pe*Xe;let Fe=0,ft=0,vt=ge;Fe=se.x+he*vt,ft=se.y+pe*vt;let ct=0,ht=0,at=Se;ct=ae.x+ce*at,ht=ae.y+te*at;let Ke=0,bt=0,Bt=Ae;Ke=ae.x+ce*Bt,bt=ae.y+te*Bt;let Rt=0,kt=0;Rt=Ue-ae.x,kt=Ye-ae.y;let Et=Rt*Rt+kt*kt,bn=0,Yt=0;bn=Fe-oe.x,Yt=ft-oe.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-ie.x,Ht=bt-ie.y;let _n=zn*zn+Ht*Ht,qt=0,Qt=0,rn=null;Et<un?(qt=Ue,Qt=Ye,rn=ae):(qt=Fe,Qt=ft,rn=oe,Et=un);let ni=0,Ln=0,Sn=null;if(Xt<_n?(ni=ct,Ln=ht,Sn=se):(ni=Ke,Ln=bt,Sn=ie,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){f.x=G.x-q.x,f.y=G.y-q.y;let Vn=1/W;f.x*=Vn,f.y*=Vn,X&&(f.x=-f.x,f.y=-f.y)}Z=W}else{let se=0,ie=0;se=K.gp0.x,ie=K.gp0.y;let ae=0,oe=0;ae=K.gp1.x,oe=K.gp1.y;let he=0,pe=0;he=ae-se,pe=oe-ie;let ce=v.gnormy*se-v.gnormx*ie,te=v.gnormy*ae-v.gnormx*oe,ue=1/(te-ce),de=(-v.tp1-ce)*ue;if(de>l.Config.epsilon){let Ae=de;se+=he*Ae,ie+=pe*Ae}let me=(-v.tp0-te)*ue;if(me<-l.Config.epsilon){let Ae=me;ae+=he*Ae,oe+=pe*Ae}let ge=se*v.gnormx+ie*v.gnormy-v.gprojection,Se=ae*v.gnormx+oe*v.gnormy-v.gprojection;if(ge<Se){G.x=se,G.y=ie;let Ae=-ge;q.x=G.x+v.gnormx*Ae,q.y=G.y+v.gnormy*Ae,Z=ge}else{G.x=ae,G.y=oe;let Ae=-Se;q.x=G.x+v.gnormx*Ae,q.y=G.y+v.gnormy*Ae,Z=Se}}}else Z=1e100}else Z=1e100}}let B=Z+s,V=c*f.x+h*f.y;if(B<l.Config.distanceThresholdCCD){if(i)break;let X=0,H=0;X=_.x-r.posx,H=_.y-r.posy;let ee=0,W=0;ee=d.x-p.posx,W=d.y-p.posy;let L=V-r.sweep_angvel*(f.y*X-f.x*H)+p.sweep_angvel*(f.y*ee-f.x*W);if(L>0&&(e.slipped=!0),L<=0||B<l.Config.distanceThresholdCCD*.5)break}let Y=(y-V)*t;if(Y<=0){z=-1;break}let $=B/Y;if($<1e-6&&($=1e-6),z+=$,z>=1){z=1;let X=z*t,H=X-r.sweepTime;if(H!=0){r.sweepTime=X;let ne=H;if(r.posx+=r.velx*ne,r.posy+=r.vely*ne,r.angvel!=0){let re=r.sweep_angvel*H;if(r.rot+=re,re*re>1e-4)r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot);else{let se=re*re,ie=1-.5*se,ae=1-se*se/8,oe=(ie*r.axisx+re*r.axisy)*ae;r.axisy=(ie*r.axisy-re*r.axisx)*ae,r.axisx=oe}}}if(o.type==0||o.type===2)o.worldCOMx=r.posx+(r.axisy*o.localCOMx-r.axisx*o.localCOMy),o.worldCOMy=r.posy+(o.localCOMx*r.axisx+o.localCOMy*r.axisy);else{let ne=o.polygon,re=ne.lverts.next,se=ne.gverts.next;for(;se!=null;){let ce=se,te=re;re=re.next,ce.x=r.posx+(r.axisy*te.x-r.axisx*te.y),ce.y=r.posy+(te.x*r.axisx+te.y*r.axisy),se=se.next}let ie=ne.edges.head,ae=ne.gverts.next,oe=ae;for(ae=ae.next;ae!=null;){let ce=ae,te=ie.elt;ie=ie.next,te.gnormx=r.axisy*te.lnormx-r.axisx*te.lnormy,te.gnormy=te.lnormx*r.axisx+te.lnormy*r.axisy,te.gprojection=r.posx*te.gnormx+r.posy*te.gnormy+te.lprojection,te.tp0=oe.y*te.gnormx-oe.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,oe=ce,ae=ae.next}let he=ne.gverts.next,pe=ie.elt;ie=ie.next,pe.gnormx=r.axisy*pe.lnormx-r.axisx*pe.lnormy,pe.gnormy=pe.lnormx*r.axisx+pe.lnormy*r.axisy,pe.gprojection=r.posx*pe.gnormx+r.posy*pe.gnormy+pe.lprojection,pe.tp0=oe.y*pe.gnormx-oe.x*pe.gnormy,pe.tp1=he.y*pe.gnormx-he.x*pe.gnormy}let ee=z*t,W=ee-p.sweepTime;if(W!=0){p.sweepTime=ee;let ne=W;if(p.posx+=p.velx*ne,p.posy+=p.vely*ne,p.angvel!=0){let re=p.sweep_angvel*W;if(p.rot+=re,re*re>1e-4)p.axisx=Math.sin(p.rot),p.axisy=Math.cos(p.rot);else{let se=re*re,ie=1-.5*se,ae=1-se*se/8,oe=(ie*p.axisx+re*p.axisy)*ae;p.axisy=(ie*p.axisy-re*p.axisx)*ae,p.axisx=oe}}}if(a.type==0||a.type===2)a.worldCOMx=p.posx+(p.axisy*a.localCOMx-p.axisx*a.localCOMy),a.worldCOMy=p.posy+(a.localCOMx*p.axisx+a.localCOMy*p.axisy);else{let ne=a.polygon,re=ne.lverts.next,se=ne.gverts.next;for(;se!=null;){let ce=se,te=re;re=re.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 ie=ne.edges.head,ae=ne.gverts.next,oe=ae;for(ae=ae.next;ae!=null;){let ce=ae,te=ie.elt;ie=ie.next,te.gnormx=p.axisy*te.lnormx-p.axisx*te.lnormy,te.gnormy=te.lnormx*p.axisx+te.lnormy*p.axisy,te.gprojection=p.posx*te.gnormx+p.posy*te.gnormy+te.lprojection,te.tp0=oe.y*te.gnormx-oe.x*te.gnormy,te.tp1=ce.y*te.gnormx-ce.x*te.gnormy,oe=ce,ae=ae.next}let he=ne.gverts.next,pe=ie.elt;ie=ie.next,pe.gnormx=p.axisy*pe.lnormx-p.axisx*pe.lnormy,pe.gnormy=pe.lnormx*p.axisx+pe.lnormy*p.axisy,pe.gprojection=p.posx*pe.gnormx+p.posy*pe.gnormy+pe.lprojection,pe.tp0=oe.y*pe.gnormx-oe.x*pe.gnormy,pe.tp1=he.y*pe.gnormx-he.x*pe.gnormy}let L=o,F=a,A=_,J=d;var w;if(pt(L)&&pt(F)){let ne=L.circle||L.capsule,re=F.circle||F.capsule,se=Ft(L),ie=Ft(F);var O;let ae=0,oe=0;ae=re.worldCOMx-ne.worldCOMx,oe=re.worldCOMy-ne.worldCOMy;let he=Math.sqrt(ae*ae+oe*oe);if(O=he-(se+ie),O<1e100){if(he==0)ae=1,oe=0;else{let te=1/he;ae*=te,oe*=te}let pe=se;A.x=ne.worldCOMx+ae*pe,A.y=ne.worldCOMy+oe*pe;let ce=-ie;J.x=re.worldCOMx+ae*ce,J.y=re.worldCOMy+oe*ce,f.x=ae,f.y=oe}w=O}else{let ne=!1;if(pt(L)&&F.type==1){let re=L;L=F,F=re;let se=A;A=J,J=se,ne=!0}if(L.type==1&&pt(F)){let re=L.polygon,se=F.circle||F.capsule,ie=Ft(F),ae=-1e100,oe=null,he=re.edges.head;for(;he!=null;){let pe=he.elt,ce=pe.gnormx*se.worldCOMx+pe.gnormy*se.worldCOMy-pe.gprojection-ie;if(ce>1e100){ae=ce;break}ce>0?ce>ae&&(ae=ce,oe=pe):ae<0&&ce>ae&&(ae=ce,oe=pe),he=he.next}if(ae<1e100){let pe=oe.gp0,ce=oe.gp1,te=se.worldCOMy*oe.gnormx-se.worldCOMx*oe.gnormy;if(te<=pe.y*oe.gnormx-pe.x*oe.gnormy){let ue=0,de=0;ue=se.worldCOMx-pe.x,de=se.worldCOMy-pe.y;let me=Math.sqrt(ue*ue+de*de);if(ae=me-ie,ae<1e100){if(me==0)ue=1,de=0;else{let Ae=1/me;ue*=Ae,de*=Ae}let ge=0;A.x=pe.x+ue*ge,A.y=pe.y+de*ge;let Se=-ie;J.x=se.worldCOMx+ue*Se,J.y=se.worldCOMy+de*Se,f.x=ue,f.y=de}}else if(te>=ce.y*oe.gnormx-ce.x*oe.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(ae=me-ie,ae<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=-ie;J.x=se.worldCOMx+ue*Se,J.y=se.worldCOMy+de*Se,f.x=ue,f.y=de}}else{let ue=-ie;J.x=se.worldCOMx+oe.gnormx*ue,J.y=se.worldCOMy+oe.gnormy*ue;let de=-ae;A.x=J.x+oe.gnormx*de,A.y=J.y+oe.gnormy*de,f.x=oe.gnormx,f.y=oe.gnormy}}ne&&(f.x=-f.x,f.y=-f.y),w=ae}else{let re=L.polygon,se=F.polygon,ie=-1e100,ae=null,oe=null,he=0,pe=re.edges.head;for(;pe!=null;){let ce=pe.elt,te=1e100,ue=se.gverts.next;for(;ue!=null;){let de=ue,me=ce.gnormx*de.x+ce.gnormy*de.y;me<te&&(te=me),ue=ue.next}if(te-=ce.gprojection,te>1e100){ie=te;break}te>0?te>ie&&(ie=te,ae=ce,he=1):ie<0&&te>ie&&(ie=te,ae=ce,he=1),pe=pe.next}if(ie<1e100){let ce=se.edges.head;for(;ce!=null;){let te=ce.elt,ue=1e100,de=re.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){ie=ue;break}ue>0?ue>ie&&(ie=ue,oe=te,he=2):ie<0&&ue>ie&&(ie=ue,oe=te,he=2),ce=ce.next}if(ie<1e100){var k,g,E;if(he==1)k=re,g=se,E=ae;else{k=se,g=re,E=oe;let me=A;A=J,J=me,ne=!ne}let te=null,ue=1e100,de=g.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(ne?(f.x=-E.gnormx,f.y=-E.gnormy):(f.x=E.gnormx,f.y=E.gnormy),ie>=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,ie=Math.sqrt(qt)):(J.x=cl,J.y=hl,A.x=Ws.x,A.y=Ws.y,ie=Math.sqrt(Vn)),ie!=0){f.x=J.x-A.x,f.y=J.y-A.y;let Il=1/ie;f.x*=Il,f.y*=Il,ne&&(f.x=-f.x,f.y=-f.y)}w=ie}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,w=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,w=at}}}else w=1e100}else w=1e100}}let Q=w+s,K=c*f.x+h*f.y;if(Q<l.Config.distanceThresholdCCD){if(i)break;let ne=0,re=0;ne=_.x-r.posx,re=_.y-r.posy;let se=0,ie=0;se=d.x-p.posx,ie=d.y-p.posy;let ae=K-r.sweep_angvel*(f.y*ne-f.x*re)+p.sweep_angvel*(f.y*se-f.x*ie);if(ae>0&&(e.slipped=!0),ae<=0||Q<l.Config.distanceThresholdCCD*.5)break}z=-1;break}if(++P>=40){B>s&&(e.failed=!0);break}}e.toi=z}static staticSweep(e,t,n,s){let i=_e(),l=e.s1,o=e.s2,a=l.body,r=o.body,p=0,c=0;p=-a.velx,c=-a.vely;let h=a.sweep_angvel;h<0&&(h=-h);let u=l.sweepCoef*h,x=e.c1,y=e.c2,_=e.axis,d=n,f=0;for(;;){let g=d*t,E=g-a.sweepTime;if(E!=0){a.sweepTime=g;let B=E;if(a.posx+=a.velx*B,a.posy+=a.vely*B,a.angvel!=0){let V=a.sweep_angvel*E;if(a.rot+=V,V*V>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let Y=V*V,$=1-.5*Y,X=1-Y*Y/8,H=($*a.axisx+V*a.axisy)*X;a.axisy=($*a.axisy-V*a.axisx)*X,a.axisx=H}}}if(l.type==0||l.type===2)l.worldCOMx=a.posx+(a.axisy*l.localCOMx-a.axisx*l.localCOMy),l.worldCOMy=a.posy+(l.localCOMx*a.axisx+l.localCOMy*a.axisy);else{let B=l.polygon,V=B.lverts.next,Y=B.gverts.next;for(;Y!=null;){let L=Y,F=V;V=V.next,L.x=a.posx+(a.axisy*F.x-a.axisx*F.y),L.y=a.posy+(F.x*a.axisx+F.y*a.axisy),Y=Y.next}let $=B.edges.head,X=B.gverts.next,H=X;for(X=X.next;X!=null;){let L=X,F=$.elt;$=$.next,F.gnormx=a.axisy*F.lnormx-a.axisx*F.lnormy,F.gnormy=F.lnormx*a.axisx+F.lnormy*a.axisy,F.gprojection=a.posx*F.gnormx+a.posy*F.gnormy+F.lprojection,F.tp0=H.y*F.gnormx-H.x*F.gnormy,F.tp1=L.y*F.gnormx-L.x*F.gnormy,H=L,X=X.next}let ee=B.gverts.next,W=$.elt;$=$.next,W.gnormx=a.axisy*W.lnormx-a.axisx*W.lnormy,W.gnormy=W.lnormx*a.axisx+W.lnormy*a.axisy,W.gprojection=a.posx*W.gnormx+a.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,N=o,S=x,D=y;var z;if(pt(M)&&pt(N)){let B=M.circle||M.capsule,V=N.circle||N.capsule,Y=Ft(M),$=Ft(N);var P;let X=0,H=0;X=V.worldCOMx-B.worldCOMx,H=V.worldCOMy-B.worldCOMy;let ee=Math.sqrt(X*X+H*H);if(P=ee-(B.radius+V.radius),P<1e100){if(ee==0)X=1,H=0;else{let F=1/ee;X*=F,H*=F}let W=B.radius;S.x=B.worldCOMx+X*W,S.y=B.worldCOMy+H*W;let L=-V.radius;D.x=V.worldCOMx+X*L,D.y=V.worldCOMy+H*L,_.x=X,_.y=H}z=P}else{let B=!1;if(pt(M)&&N.type==1){let V=M;M=N,N=V;let Y=S;S=D,D=Y,B=!0}if(M.type==1&&pt(N)){let V=M.polygon,Y=N.circle||N.capsule,$=Ft(N),X=-1e100,H=null,ee=V.edges.head;for(;ee!=null;){let W=ee.elt,L=W.gnormx*Y.worldCOMx+W.gnormy*Y.worldCOMy-W.gprojection-$;if(L>1e100){X=L;break}L>0?L>X&&(X=L,H=W):X<0&&L>X&&(X=L,H=W),ee=ee.next}if(X<1e100){let W=H.gp0,L=H.gp1,F=Y.worldCOMy*H.gnormx-Y.worldCOMx*H.gnormy;if(F<=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 re=1/Q;A*=re,J*=re}let K=0;S.x=W.x+A*K,S.y=W.y+J*K;let ne=-$;D.x=Y.worldCOMx+A*ne,D.y=Y.worldCOMy+J*ne,_.x=A,_.y=J}}else if(F>=L.y*H.gnormx-L.x*H.gnormy){let A=0,J=0;A=Y.worldCOMx-L.x,J=Y.worldCOMy-L.y;let Q=Math.sqrt(A*A+J*J);if(X=Q-$,X<1e100){if(Q==0)A=1,J=0;else{let re=1/Q;A*=re,J*=re}let K=0;S.x=L.x+A*K,S.y=L.y+J*K;let ne=-$;D.x=Y.worldCOMx+A*ne,D.y=Y.worldCOMy+J*ne,_.x=A,_.y=J}}else{let A=-$;D.x=Y.worldCOMx+H.gnormx*A,D.y=Y.worldCOMy+H.gnormy*A;let J=-X;S.x=D.x+H.gnormx*J,S.y=D.y+H.gnormy*J,_.x=H.gnormx,_.y=H.gnormy}}B&&(_.x=-_.x,_.y=-_.y),z=X}else{let V=M.polygon,Y=N.polygon,$=-1e100,X=null,H=null,ee=0,W=V.edges.head;for(;W!=null;){let L=W.elt,F=1e100,A=Y.gverts.next;for(;A!=null;){let J=A,Q=L.gnormx*J.x+L.gnormy*J.y;Q<F&&(F=Q),A=A.next}if(F-=L.gprojection,F>1e100){$=F;break}F>0?F>$&&($=F,X=L,ee=1):$<0&&F>$&&($=F,X=L,ee=1),W=W.next}if($<1e100){let L=Y.edges.head;for(;L!=null;){let F=L.elt,A=1e100,J=V.gverts.next;for(;J!=null;){let Q=J,K=F.gnormx*Q.x+F.gnormy*Q.y;K<A&&(A=K),J=J.next}if(A-=F.gprojection,A>1e100){$=A;break}A>0?A>$&&($=A,H=F,ee=2):$<0&&A>$&&($=A,H=F,ee=2),L=L.next}if($<1e100){var Z,m,b;if(ee==1)Z=V,m=Y,b=X;else{Z=Y,m=V,b=H;let Q=S;S=D,D=Q,B=!B}let F=null,A=1e100,J=m.edges.head;for(;J!=null;){let Q=J.elt,K=b.gnormx*Q.gnormx+b.gnormy*Q.gnormy;K<A&&(A=K,F=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,ne=F.gp0,re=F.gp1,se=0,ie=0,ae=0,oe=0;se=K.x-Q.x,ie=K.y-Q.y,ae=re.x-ne.x,oe=re.y-ne.y;let he=1/(se*se+ie*ie),pe=1/(ae*ae+oe*oe),ce=-(se*(Q.x-ne.x)+ie*(Q.y-ne.y))*he,te=-(se*(Q.x-re.x)+ie*(Q.y-re.y))*he,ue=-(ae*(ne.x-Q.x)+oe*(ne.y-Q.y))*pe,de=-(ae*(ne.x-K.x)+oe*(ne.y-K.y))*pe;ce<0?ce=0:ce>1&&(ce=1),te<0?te=0:te>1&&(te=1),ue<0?ue=0:ue>1&&(ue=1),de<0?de=0:de>1&&(de=1);let me=0,ge=0,Se=ce;me=Q.x+se*Se,ge=Q.y+ie*Se;let Ae=0,Ue=0,Ye=te;Ae=Q.x+se*Ye,Ue=Q.y+ie*Ye;let Xe=0,Fe=0,ft=ue;Xe=ne.x+ae*ft,Fe=ne.y+oe*ft;let vt=0,ct=0,ht=de;vt=ne.x+ae*ht,ct=ne.y+oe*ht;let at=0,Ke=0;at=me-ne.x,Ke=ge-ne.y;let bt=at*at+Ke*Ke,Bt=0,Rt=0;Bt=Ae-re.x,Rt=Ue-re.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=ne):(Xt=Ae,zn=Ue,Ht=re,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?(S.x=Xt,S.y=zn,D.x=Ht.x,D.y=Ht.y,$=Math.sqrt(bt)):(D.x=_n,D.y=qt,S.x=Qt.x,S.y=Qt.y,$=Math.sqrt(Yt)),$!=0){_.x=D.x-S.x,_.y=D.y-S.y;let rn=1/$;_.x*=rn,_.y*=rn,B&&(_.x=-_.x,_.y=-_.y)}z=$}else{let Q=0,K=0;Q=F.gp0.x,K=F.gp0.y;let ne=0,re=0;ne=F.gp1.x,re=F.gp1.y;let se=0,ie=0;se=ne-Q,ie=re-K;let ae=b.gnormy*Q-b.gnormx*K,oe=b.gnormy*ne-b.gnormx*re,he=1/(oe-ae),pe=(-b.tp1-ae)*he;if(pe>i.Config.epsilon){let de=pe;Q+=se*de,K+=ie*de}let ce=(-b.tp0-oe)*he;if(ce<-i.Config.epsilon){let de=ce;ne+=se*de,re+=ie*de}let te=Q*b.gnormx+K*b.gnormy-b.gprojection,ue=ne*b.gnormx+re*b.gnormy-b.gprojection;if(te<ue){D.x=Q,D.y=K;let de=-te;S.x=D.x+b.gnormx*de,S.y=D.y+b.gnormy*de,z=te}else{D.x=ne,D.y=re;let de=-ue;S.x=D.x+b.gnormx*de,S.y=D.y+b.gnormy*de,z=ue}}}else z=1e100}else z=1e100}}let j=z+s,R=p*_.x+c*_.y;if(j<i.Config.distanceThresholdCCD){let B=0,V=0;B=x.x-a.posx,V=x.y-a.posy;let Y=R-a.sweep_angvel*(_.y*B-_.x*V);if(Y>0&&(e.slipped=!0),Y<=0||j<i.Config.distanceThresholdCCD*.5)break}let q=(u-R)*t;if(q<=0){d=-1;break}let G=j/q;if(G<1e-6&&(G=1e-6),d+=G,d>=1){d=1;let B=d*t,V=B-a.sweepTime;if(V!=0){a.sweepTime=B;let L=V;if(a.posx+=a.velx*L,a.posy+=a.vely*L,a.angvel!=0){let F=a.sweep_angvel*V;if(a.rot+=F,F*F>1e-4)a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot);else{let A=F*F,J=1-.5*A,Q=1-A*A/8,K=(J*a.axisx+F*a.axisy)*Q;a.axisy=(J*a.axisy-F*a.axisx)*Q,a.axisx=K}}}if(l.type==0||l.type===2)l.worldCOMx=a.posx+(a.axisy*l.localCOMx-a.axisx*l.localCOMy),l.worldCOMy=a.posy+(l.localCOMx*a.axisx+l.localCOMy*a.axisy);else{let L=l.polygon,F=L.lverts.next,A=L.gverts.next;for(;A!=null;){let se=A,ie=F;F=F.next,se.x=a.posx+(a.axisy*ie.x-a.axisx*ie.y),se.y=a.posy+(ie.x*a.axisx+ie.y*a.axisy),A=A.next}let J=L.edges.head,Q=L.gverts.next,K=Q;for(Q=Q.next;Q!=null;){let se=Q,ie=J.elt;J=J.next,ie.gnormx=a.axisy*ie.lnormx-a.axisx*ie.lnormy,ie.gnormy=ie.lnormx*a.axisx+ie.lnormy*a.axisy,ie.gprojection=a.posx*ie.gnormx+a.posy*ie.gnormy+ie.lprojection,ie.tp0=K.y*ie.gnormx-K.x*ie.gnormy,ie.tp1=se.y*ie.gnormx-se.x*ie.gnormy,K=se,Q=Q.next}let ne=L.gverts.next,re=J.elt;J=J.next,re.gnormx=a.axisy*re.lnormx-a.axisx*re.lnormy,re.gnormy=re.lnormx*a.axisx+re.lnormy*a.axisy,re.gprojection=a.posx*re.gnormx+a.posy*re.gnormy+re.lprojection,re.tp0=K.y*re.gnormx-K.x*re.gnormy,re.tp1=ne.y*re.gnormx-ne.x*re.gnormy}let Y=l,$=o,X=x,H=y;var C;if(pt(Y)&&pt($)){let L=Y.circle||Y.capsule,F=$.circle||$.capsule,A=Ft(Y),J=Ft($);var v;let Q=0,K=0;Q=F.worldCOMx-L.worldCOMx,K=F.worldCOMy-L.worldCOMy;let ne=Math.sqrt(Q*Q+K*K);if(v=ne-(A+J),v<1e100){if(ne==0)Q=1,K=0;else{let ie=1/ne;Q*=ie,K*=ie}let re=A;X.x=L.worldCOMx+Q*re,X.y=L.worldCOMy+K*re;let se=-J;H.x=F.worldCOMx+Q*se,H.y=F.worldCOMy+K*se,_.x=Q,_.y=K}C=v}else{let L=!1;if(pt(Y)&&$.type==1){let F=Y;Y=$,$=F;let A=X;X=H,H=A,L=!0}if(Y.type==1&&pt($)){let F=Y.polygon,A=$.circle||$.capsule,J=Ft($),Q=-1e100,K=null,ne=F.edges.head;for(;ne!=null;){let re=ne.elt,se=re.gnormx*A.worldCOMx+re.gnormy*A.worldCOMy-re.gprojection-J;if(se>1e100){Q=se;break}se>0?se>Q&&(Q=se,K=re):Q<0&&se>Q&&(Q=se,K=re),ne=ne.next}if(Q<1e100){let re=K.gp0,se=K.gp1,ie=A.worldCOMy*K.gnormx-A.worldCOMx*K.gnormy;if(ie<=re.y*K.gnormx-re.x*K.gnormy){let ae=0,oe=0;ae=A.worldCOMx-re.x,oe=A.worldCOMy-re.y;let he=Math.sqrt(ae*ae+oe*oe);if(Q=he-J,Q<1e100){if(he==0)ae=1,oe=0;else{let te=1/he;ae*=te,oe*=te}let pe=0;X.x=re.x+ae*pe,X.y=re.y+oe*pe;let ce=-J;H.x=A.worldCOMx+ae*ce,H.y=A.worldCOMy+oe*ce,_.x=ae,_.y=oe}}else if(ie>=se.y*K.gnormx-se.x*K.gnormy){let ae=0,oe=0;ae=A.worldCOMx-se.x,oe=A.worldCOMy-se.y;let he=Math.sqrt(ae*ae+oe*oe);if(Q=he-J,Q<1e100){if(he==0)ae=1,oe=0;else{let te=1/he;ae*=te,oe*=te}let pe=0;X.x=se.x+ae*pe,X.y=se.y+oe*pe;let ce=-J;H.x=A.worldCOMx+ae*ce,H.y=A.worldCOMy+oe*ce,_.x=ae,_.y=oe}}else{let ae=-J;H.x=A.worldCOMx+K.gnormx*ae,H.y=A.worldCOMy+K.gnormy*ae;let oe=-Q;X.x=H.x+K.gnormx*oe,X.y=H.y+K.gnormy*oe,_.x=K.gnormx,_.y=K.gnormy}}L&&(_.x=-_.x,_.y=-_.y),C=Q}else{let F=Y.polygon,A=$.polygon,J=-1e100,Q=null,K=null,ne=0,re=F.edges.head;for(;re!=null;){let se=re.elt,ie=1e100,ae=A.gverts.next;for(;ae!=null;){let oe=ae,he=se.gnormx*oe.x+se.gnormy*oe.y;he<ie&&(ie=he),ae=ae.next}if(ie-=se.gprojection,ie>1e100){J=ie;break}ie>0?ie>J&&(J=ie,Q=se,ne=1):J<0&&ie>J&&(J=ie,Q=se,ne=1),re=re.next}if(J<1e100){let se=A.edges.head;for(;se!=null;){let ie=se.elt,ae=1e100,oe=F.gverts.next;for(;oe!=null;){let he=oe,pe=ie.gnormx*he.x+ie.gnormy*he.y;pe<ae&&(ae=pe),oe=oe.next}if(ae-=ie.gprojection,ae>1e100){J=ae;break}ae>0?ae>J&&(J=ae,K=ie,ne=2):J<0&&ae>J&&(J=ae,K=ie,ne=2),se=se.next}if(J<1e100){var w,O,k;if(ne==1)w=F,O=A,k=Q;else{w=A,O=F,k=K;let he=X;X=H,H=he,L=!L}let ie=null,ae=1e100,oe=O.edges.head;for(;oe!=null;){let he=oe.elt,pe=k.gnormx*he.gnormx+k.gnormy*he.gnormy;pe<ae&&(ae=pe,ie=he),oe=oe.next}if(L?(_.x=-k.gnormx,_.y=-k.gnormy):(_.x=k.gnormx,_.y=k.gnormy),J>=0){let he=k.gp0,pe=k.gp1,ce=ie.gp0,te=ie.gp1,ue=0,de=0,me=0,ge=0;ue=pe.x-he.x,de=pe.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-pe.x)+ge*(ce.y-pe.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-pe.x,rn=Et-pe.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=pe,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,L&&(_.x=-_.x,_.y=-_.y)}C=J}else{let he=0,pe=0;he=ie.gp0.x,pe=ie.gp0.y;let ce=0,te=0;ce=ie.gp1.x,te=ie.gp1.y;let ue=0,de=0;ue=ce-he,de=te-pe;let me=k.gnormy*he-k.gnormx*pe,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,pe+=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+pe*k.gnormy-k.gprojection,Xe=ce*k.gnormx+te*k.gnormy-k.gprojection;if(Ye<Xe){H.x=he,H.y=pe;let Fe=-Ye;X.x=H.x+k.gnormx*Fe,X.y=H.y+k.gnormy*Fe,C=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,C=Xe}}}else C=1e100}else C=1e100}}let ee=C+s,W=p*_.x+c*_.y;if(ee<i.Config.distanceThresholdCCD){let L=0,F=0;L=x.x-a.posx,F=x.y-a.posy;let A=W-a.sweep_angvel*(_.y*L-_.x*F);if(A>0&&(e.slipped=!0),A<=0||ee<i.Config.distanceThresholdCCD*.5)break}d=-1;break}if(++f>=40){j>s&&(e.failed=!0);break}}e.toi=d}static distanceBody(e,t,n,s){let i=_e(),l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1;let o;le.zpp_pool==null?o=new le:(o=le.zpp_pool,le.zpp_pool=o.next,o.next=null),o.weak=!1;let a;le.zpp_pool==null?a=new le:(a=le.zpp_pool,le.zpp_pool=a.next,a.next=null),a.weak=!1;let r=1e100,p=e.shapes.head;for(;p!=null;){let z=p.elt,P=t.shapes.head;for(;P!=null;){let Z=P.elt,m=z,b=Z,C=l,v=o,w=r;w==null&&(w=1e100);var c;if(pt(m)&&pt(b)){let O=m.circle||m.capsule,k=b.circle||b.capsule,g=Ft(m),E=Ft(b);var h;let M=0,N=0;M=k.worldCOMx-O.worldCOMx,N=k.worldCOMy-O.worldCOMy;let S=Math.sqrt(M*M+N*N);if(h=S-(g+E),h<w){if(S==0)M=1,N=0;else{let R=1/S;M*=R,N*=R}let D=g;C.x=O.worldCOMx+M*D,C.y=O.worldCOMy+N*D;let j=-E;v.x=k.worldCOMx+M*j,v.y=k.worldCOMy+N*j,a.x=M,a.y=N}c=h}else{let O=!1;if(pt(m)&&b.type==1){let k=m;m=b,b=k;let g=C;C=v,v=g,O=!0}if(m.type==1&&pt(b)){let k=m.polygon,g=b.circle||b.capsule,E=Ft(b),M=-1e100,N=null,S=k.edges.head;for(;S!=null;){let D=S.elt,j=D.gnormx*g.worldCOMx+D.gnormy*g.worldCOMy-D.gprojection-E;if(j>w){M=j;break}j>0?j>M&&(M=j,N=D):M<0&&j>M&&(M=j,N=D),S=S.next}if(M<w){let D=N.gp0,j=N.gp1,R=g.worldCOMy*N.gnormx-g.worldCOMx*N.gnormy;if(R<=D.y*N.gnormx-D.x*N.gnormy){let q=0,G=0;q=g.worldCOMx-D.x,G=g.worldCOMy-D.y;let B=Math.sqrt(q*q+G*G);if(M=B-E,M<w){if(B==0)q=1,G=0;else{let $=1/B;q*=$,G*=$}let V=0;C.x=D.x+q*V,C.y=D.y+G*V;let Y=-E;v.x=g.worldCOMx+q*Y,v.y=g.worldCOMy+G*Y,a.x=q,a.y=G}}else if(R>=j.y*N.gnormx-j.x*N.gnormy){let q=0,G=0;q=g.worldCOMx-j.x,G=g.worldCOMy-j.y;let B=Math.sqrt(q*q+G*G);if(M=B-E,M<w){if(B==0)q=1,G=0;else{let $=1/B;q*=$,G*=$}let V=0;C.x=j.x+q*V,C.y=j.y+G*V;let Y=-E;v.x=g.worldCOMx+q*Y,v.y=g.worldCOMy+G*Y,a.x=q,a.y=G}}else{let q=-E;v.x=g.worldCOMx+N.gnormx*q,v.y=g.worldCOMy+N.gnormy*q;let G=-M;C.x=v.x+N.gnormx*G,C.y=v.y+N.gnormy*G,a.x=N.gnormx,a.y=N.gnormy}}O&&(a.x=-a.x,a.y=-a.y),c=M}else{let k=m.polygon,g=b.polygon,E=-1e100,M=null,N=null,S=0,D=k.edges.head;for(;D!=null;){let j=D.elt,R=1e100,q=g.gverts.next;for(;q!=null;){let G=q,B=j.gnormx*G.x+j.gnormy*G.y;B<R&&(R=B),q=q.next}if(R-=j.gprojection,R>w){E=R;break}R>0?R>E&&(E=R,M=j,S=1):E<0&&R>E&&(E=R,M=j,S=1),D=D.next}if(E<w){let j=g.edges.head;for(;j!=null;){let R=j.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>w){E=q;break}q>0?q>E&&(E=q,N=R,S=2):E<0&&q>E&&(E=q,N=R,S=2),j=j.next}if(E<w){var u,x,y;if(S==1)u=k,x=g,y=M;else{u=g,x=k,y=N;let B=C;C=v,v=B,O=!O}let R=null,q=1e100,G=x.edges.head;for(;G!=null;){let B=G.elt,V=y.gnormx*B.gnormx+y.gnormy*B.gnormy;V<q&&(q=V,R=B),G=G.next}if(O?(a.x=-y.gnormx,a.y=-y.gnormy):(a.x=y.gnormx,a.y=y.gnormy),E>=0){let B=y.gp0,V=y.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 L=1/(X*X+H*H),F=1/(ee*ee+W*W),A=-(X*(B.x-Y.x)+H*(B.y-Y.y))*L,J=-(X*(B.x-$.x)+H*(B.y-$.y))*L,Q=-(ee*(Y.x-B.x)+W*(Y.y-B.y))*F,K=-(ee*(Y.x-V.x)+W*(Y.y-V.y))*F;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 ne=0,re=0,se=A;ne=B.x+X*se,re=B.y+H*se;let ie=0,ae=0,oe=J;ie=B.x+X*oe,ae=B.y+H*oe;let he=0,pe=0,ce=Q;he=Y.x+ee*ce,pe=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=ne-Y.x,ge=re-Y.y;let Se=me*me+ge*ge,Ae=0,Ue=0;Ae=ie-$.x,Ue=ae-$.y;let Ye=Ae*Ae+Ue*Ue,Xe=0,Fe=0;Xe=he-B.x,Fe=pe-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=ne,Ke=re,bt=Y):(at=ie,Ke=ae,bt=$,Se=Ye);let Bt=0,Rt=0,kt=null;if(ft<ht?(Bt=he,Rt=pe,kt=B):(Bt=te,Rt=ue,kt=V,ft=ht),Se<ft?(C.x=at,C.y=Ke,v.x=bt.x,v.y=bt.y,E=Math.sqrt(Se)):(v.x=Bt,v.y=Rt,C.x=kt.x,C.y=kt.y,E=Math.sqrt(ft)),E!=0){a.x=v.x-C.x,a.y=v.y-C.y;let Et=1/E;a.x*=Et,a.y*=Et,O&&(a.x=-a.x,a.y=-a.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=y.gnormy*B-y.gnormx*V,W=y.gnormy*Y-y.gnormx*$,L=1/(W-ee),F=(-y.tp1-ee)*L;if(F>i.Config.epsilon){let K=F;B+=X*K,V+=H*K}let A=(-y.tp0-W)*L;if(A<-i.Config.epsilon){let K=A;Y+=X*K,$+=H*K}let J=B*y.gnormx+V*y.gnormy-y.gprojection,Q=Y*y.gnormx+$*y.gnormy-y.gprojection;if(J<Q){v.x=B,v.y=V;let K=-J;C.x=v.x+y.gnormx*K,C.y=v.y+y.gnormy*K,c=J}else{v.x=Y,v.y=$;let K=-Q;C.x=v.x+y.gnormx*K,C.y=v.y+y.gnormy*K,c=Q}}}else c=w}else c=w}}c<r&&(r=c,n.x=l.x,n.y=l.y,s.x=o.x,s.y=o.y),P=P.next}p=p.next}let _=l;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_._isimmutable=null,_._validate=null,_._invalidate=null,_.next=le.zpp_pool,le.zpp_pool=_;let d=o;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=le.zpp_pool,le.zpp_pool=d;let f=a;return f.outer!=null&&(f.outer.zpp_inner=null,f.outer=null),f._isimmutable=null,f._validate=null,f._invalidate=null,f.next=le.zpp_pool,le.zpp_pool=f,r}static distance(e,t,n,s,i,l){let o=_e();if(l==null&&(l=1e100),pt(e)&&pt(t)){let a=e.circle||e.capsule,r=t.circle||t.capsule,p=Ft(e),c=Ft(t),h,u=0,x=0;u=r.worldCOMx-a.worldCOMx,x=r.worldCOMy-a.worldCOMy;let y=Math.sqrt(u*u+x*x);if(h=y-(p+c),h<l){if(y==0)u=1,x=0;else{let f=1/y;u*=f,x*=f}let _=p;n.x=a.worldCOMx+u*_,n.y=a.worldCOMy+x*_;let d=-c;s.x=r.worldCOMx+u*d,s.y=r.worldCOMy+x*d,i.x=u,i.y=x}return h}else{let a=!1;if(pt(e)&&t.type==1){let r=e;e=t,t=r;let p=n;n=s,s=p,a=!0}if(e.type==1&&pt(t)){let r=e.polygon,p=t.circle||t.capsule,c=Ft(t),h=-1e100,u=null,x=r.edges.head;for(;x!=null;){let y=x.elt,_=y.gnormx*p.worldCOMx+y.gnormy*p.worldCOMy-y.gprojection-c;if(_>l){h=_;break}_>0?_>h&&(h=_,u=y):h<0&&_>h&&(h=_,u=y),x=x.next}if(h<l){let y=u.gp0,_=u.gp1,d=p.worldCOMy*u.gnormx-p.worldCOMx*u.gnormy;if(d<=y.y*u.gnormx-y.x*u.gnormy){let f=0,z=0;f=p.worldCOMx-y.x,z=p.worldCOMy-y.y;let P=Math.sqrt(f*f+z*z);if(h=P-c,h<l){if(P==0)f=1,z=0;else{let b=1/P;f*=b,z*=b}let Z=0;n.x=y.x+f*Z,n.y=y.y+z*Z;let m=-c;s.x=p.worldCOMx+f*m,s.y=p.worldCOMy+z*m,i.x=f,i.y=z}}else if(d>=_.y*u.gnormx-_.x*u.gnormy){let f=0,z=0;f=p.worldCOMx-_.x,z=p.worldCOMy-_.y;let P=Math.sqrt(f*f+z*z);if(h=P-c,h<l){if(P==0)f=1,z=0;else{let b=1/P;f*=b,z*=b}let Z=0;n.x=_.x+f*Z,n.y=_.y+z*Z;let m=-c;s.x=p.worldCOMx+f*m,s.y=p.worldCOMy+z*m,i.x=f,i.y=z}}else{let f=-c;s.x=p.worldCOMx+u.gnormx*f,s.y=p.worldCOMy+u.gnormy*f;let z=-h;n.x=s.x+u.gnormx*z,n.y=s.y+u.gnormy*z,i.x=u.gnormx,i.y=u.gnormy}}return a&&(i.x=-i.x,i.y=-i.y),h}else{let r=e.polygon,p=t.polygon,c=-1e100,h=null,u=null,x=0,y=r.edges.head;for(;y!=null;){let _=y.elt,d=1e100,f=p.gverts.next;for(;f!=null;){let z=f,P=_.gnormx*z.x+_.gnormy*z.y;P<d&&(d=P),f=f.next}if(d-=_.gprojection,d>l){c=d;break}d>0?d>c&&(c=d,h=_,x=1):c<0&&d>c&&(c=d,h=_,x=1),y=y.next}if(c<l){let _=p.edges.head;for(;_!=null;){let d=_.elt,f=1e100,z=r.gverts.next;for(;z!=null;){let P=z,Z=d.gnormx*P.x+d.gnormy*P.y;Z<f&&(f=Z),z=z.next}if(f-=d.gprojection,f>l){c=f;break}f>0?f>c&&(c=f,u=d,x=2):c<0&&f>c&&(c=f,u=d,x=2),_=_.next}if(c<l){let d,f,z;if(x==1)d=r,f=p,z=h;else{d=p,f=r,z=u;let b=n;n=s,s=b,a=!a}let P=null,Z=1e100,m=f.edges.head;for(;m!=null;){let b=m.elt,C=z.gnormx*b.gnormx+z.gnormy*b.gnormy;C<Z&&(Z=C,P=b),m=m.next}if(a?(i.x=-z.gnormx,i.y=-z.gnormy):(i.x=z.gnormx,i.y=z.gnormy),c>=0){let b=z.gp0,C=z.gp1,v=P.gp0,w=P.gp1,O=0,k=0,g=0,E=0;O=C.x-b.x,k=C.y-b.y,g=w.x-v.x,E=w.y-v.y;let M=1/(O*O+k*k),N=1/(g*g+E*E),S=-(O*(b.x-v.x)+k*(b.y-v.y))*M,D=-(O*(b.x-w.x)+k*(b.y-w.y))*M,j=-(g*(v.x-b.x)+E*(v.y-b.y))*N,R=-(g*(v.x-C.x)+E*(v.y-C.y))*N;S<0?S=0:S>1&&(S=1),D<0?D=0:D>1&&(D=1),j<0?j=0:j>1&&(j=1),R<0?R=0:R>1&&(R=1);let q=0,G=0,B=S;q=b.x+O*B,G=b.y+k*B;let V=0,Y=0,$=D;V=b.x+O*$,Y=b.y+k*$;let X=0,H=0,ee=j;X=v.x+g*ee,H=v.y+E*ee;let W=0,L=0,F=R;W=v.x+g*F,L=v.y+E*F;let A=0,J=0;A=q-v.x,J=G-v.y;let Q=A*A+J*J,K=0,ne=0;K=V-w.x,ne=Y-w.y;let re=K*K+ne*ne,se=0,ie=0;se=X-b.x,ie=H-b.y;let ae=se*se+ie*ie,oe=0,he=0;oe=W-C.x,he=L-C.y;let pe=oe*oe+he*he,ce=0,te=0,ue=null;Q<re?(ce=q,te=G,ue=v):(ce=V,te=Y,ue=w,Q=re);let de=0,me=0,ge=null;if(ae<pe?(de=X,me=H,ge=b):(de=W,me=L,ge=C,ae=pe),Q<ae?(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(ae)),c!=0){i.x=s.x-n.x,i.y=s.y-n.y;let Se=1/c;i.x*=Se,i.y*=Se,a&&(i.x=-i.x,i.y=-i.y)}return c}else{let b=0,C=0;b=P.gp0.x,C=P.gp0.y;let v=0,w=0;v=P.gp1.x,w=P.gp1.y;let O=0,k=0;O=v-b,k=w-C;let g=z.gnormy*b-z.gnormx*C,E=z.gnormy*v-z.gnormx*w,M=1/(E-g),N=(-z.tp1-g)*M;if(N>o.Config.epsilon){let R=N;b+=O*R,C+=k*R}let S=(-z.tp0-E)*M;if(S<-o.Config.epsilon){let R=S;v+=O*R,w+=k*R}let D=b*z.gnormx+C*z.gnormy-z.gprojection,j=v*z.gnormx+w*z.gnormy-z.gprojection;if(D<j){s.x=b,s.y=C;let R=-D;return n.x=s.x+z.gnormx*R,n.y=s.y+z.gnormy*R,D}else{s.x=v,s.y=w;let R=-j;return n.x=s.x+z.gnormx*R,n.y=s.y+z.gnormy*R,j}}}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,a=t.y-e.y,r,p,c;return a*i-o*l>=0?c=!0:(i=s.x-n.x,l=s.y-n.y,o=n.x-t.x,a=n.y-t.y,c=a*i-o*l>=0),c?p=!0:(i=e.x-s.x,l=e.y-s.y,o=s.x-n.x,a=s.y-n.y,p=a*i-o*l>=0),p?r=!0:(i=t.x-e.x,l=t.y-e.y,o=e.x-s.x,a=e.y-s.y,r=a*i-o*l>=0),r?!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 a=t;for(;;){let r=a;if(r.sort(),r.mag=r.x*r.x+r.y*r.y,a=a.next,a==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 a=i;for(;;){let r=a,p=r.next;r.diagonals.reverse();let c=r.diagonals.head;for(;c!=null;){let h=c.elt;if(h.id<r.id){p=h,c=c.next;continue}let u=c.next==null?r.prev:c.next.elt;if(!Le.delaunay(r,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=r,x.b=h,r.id<h.id?(x.id=r.id,x.di=h.id):(x.id=h.id,x.di=r.id);let y=x;s.add(y),y.node=Le.edgeSet.insert(y)}p=h,c=c.next}if(a=a.next,a==l)break}}for(;s.next!=null;){let a=s.pop_unsafe(),r=a.a,p=a.b,c=r.next,h=null,u=r.diagonals.head;for(;u!=null;){let y=u.elt;if(y==p){u=u.next,h=u==null?r.prev:u.elt;break}c=y,u=u.next}if(r.diagonals.remove(p),p.diagonals.remove(r),p==c.next)c.diagonals.add(h);else{let y=c.diagonals.head;for(;y!=null;){if(y.elt==p){c.diagonals.insert(y,h);break}y=y.next}}if(r==h.next)h.diagonals.add(c);else{let y=h.diagonals.head;for(;y!=null;){if(y.elt==r){h.diagonals.insert(y,c);break}y=y.next}}Le.edgeSet.remove_node(a.node);let x=a;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 r=s;for(;;){let p=r;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),r=r.next,r==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 a=Le.queue.pop_unsafe();for(Le.stack.add(a);;){let r=Le.queue.pop_unsafe();if(Le.queue.head==null)break;if(r.rightchain!=Le.stack.head.elt.rightchain){for(;;){let p=Le.stack.pop_unsafe();if(Le.stack.head==null)break;e.add_diagonal(p,r)}Le.stack.add(a)}else{let p=Le.stack.pop_unsafe();for(;Le.stack.head!=null;){let c=Le.stack.head.elt,h=r.x-p.x,u=r.y-p.y,x=p.x-c.x,_=(p.y-c.y)*h-x*u;if(r.rightchain&&_>=0||!r.rightchain&&_<=0)break;e.add_diagonal(c,r),p=c,Le.stack.pop()}Le.stack.add(p)}Le.stack.add(r),a=r}if(Le.stack.head!=null)for(Le.stack.pop();Le.stack.head!=null;){let r=Le.stack.pop_unsafe();if(Le.stack.head==null)break;e.add_diagonal(n,r)}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 a=o.elt;if(a.id==n&&a.di==s){l=a;break}o=o.next}return l}static int_callback(e,t,n){let s=e.int1,i=e.int2,l,o=t.options1,a=s.cbTypes;if(o.nonemptyintersection(a,o.includes)&&!o.nonemptyintersection(a,o.excludes)){let r=t.options2,p=i.cbTypes;l=r.nonemptyintersection(p,r.includes)&&!r.nonemptyintersection(p,r.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 r=i.elt;if(e.id<r.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 a=o;s==null?(a.next=l.head,l.head=a):(a.next=s.next,s.next=a),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 a;if(i.zpp_i<o?a=!0:(i.zpp_next=t.callbacks.CbTypeIterator.zpp_pool,t.callbacks.CbTypeIterator.zpp_pool=i,i.zpp_inner=null,a=!1),!a)break;i.zpp_critical=!1;let r=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(r):p.unshift(r)}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 a=l.parent;a!=null&&(l===a.prev?a.prev=null:a.next=null,l.parent=null);let r=l;r.data=null,r.lt=null,r.next=je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool,je._zpp.util.ZPP_Set_ZPP_Body.zpp_pool=r,l=a}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 a=l.elt;if(!a.sleeping&&(e===4||a.type===e)){let r=a.b1===this?a.b2:a.b1;if(je.bodyset.try_insert_bool(r)){let p=r.outer;i.zpp_inner.reverse_flag?i.push(p):i.unshift(p)}}l=l.next}let o=je.bodyset;if(o.parent!=null){let a=o.parent;for(;a!=null;)if(a.prev!=null)a=a.prev;else if(a.next!=null)a=a.next;else{let r=a.parent;r!=null&&(a===r.prev?r.prev=null:r.next=null,a.parent=null);let p=a;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,a=r}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,a=this.aabb.maxy-this.aabb.miny,r=o*o+a*a,p=t.Config.angularSleepThreshold*t.Config.angularSleepThreshold;if(4*this.angvel*this.angvel*r>p)s=!1;else{let c=this.rot-this.pre_rot;s=!(c*c*r>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 a=t.gverts.next,r=i.elt;r.gnormx=this.axisy*r.lnormx-this.axisx*r.lnormy,r.gnormy=r.lnormx*this.axisx+r.lnormy*this.axisy,r.gprojection=this.posx*r.gnormx+this.posy*r.gnormy+r.lprojection,r.tp0=o.y*r.gnormx-o.x*r.gnormy,r.tp1=a.y*r.gnormx-a.x*r.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;le.zpp_pool==null?o=new le:(o=le.zpp_pool,le.zpp_pool=o.next,o.next=null),o.weak=!1,o._immutable=!1,o.x=e,o.y=t,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 a;l.zpp_inner._validate!=null&&l.zpp_inner._validate(),l.zpp_inner.x===e?(l.zpp_inner._validate!=null&&l.zpp_inner._validate(),a=l.zpp_inner.y===t):a=!1,a||(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 a=n;t+=i.x*(a.y-s.y);let r=a.y*i.x-a.x*i.y;e.localCOMx+=(i.x+a.x)*r,e.localCOMy+=(i.y+a.y)*r,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 a=this.bodies.head;for(;a!=null;){let p=a.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)}a=a.next}let r=this.constraints.head;for(;r!=null;){let c=r.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)}r=r.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 a;rt.zpp_pool==null?a=new rt:(a=rt.zpp_pool,rt.zpp_pool=a.next,a.next=null),a.polygon=this,this.edges.add(a),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,y=s.y-h.y,_=Math.sqrt(x*x+y*y);u.length=_;let d=1/_;x*=d,y*=d;let f=x;x=-y,y=f,u.lprojection=x*s.x+y*s.y,u.lnormx=x,u.lnormy=y,u.wrap_lnorm!=null&&(u.wrap_lnorm.zpp_inner.x=x,u.wrap_lnorm.zpp_inner.y=y),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,a=s.y-i.y,r=Math.sqrt(o*o+a*a);l.length=r;let p=1/r;o*=p,a*=p;let c=o;o=-a,a=c,l.lprojection=o*s.x+a*s.y,l.lnormx=o,l.lnormy=a,l.wrap_lnorm!=null&&(l.wrap_lnorm.zpp_inner.x=o,l.wrap_lnorm.zpp_inner.y=a)}}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,a=t.elt;t=t.next,a.gp0=s,a.gp1=o,a.gnormx=e.axisy*a.lnormx-e.axisx*a.lnormy,a.gnormy=a.lnormx*e.axisx+a.lnormy*e.axisy,a.gprojection=e.posx*a.gnormx+e.posy*a.gnormy+a.lprojection,a.wrap_gnorm!=null&&(a.wrap_gnorm.zpp_inner.x=a.gnormx,a.wrap_gnorm.zpp_inner.y=a.gnormy),a.tp0=a.gp0.y*a.gnormx-a.gp0.x*a.gnormy,a.tp1=a.gp1.y*a.gnormx-a.gp1.x*a.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 a=this.edges.pop_unsafe();a.polygon=null,a.next=rt.zpp_pool,rt.zpp_pool=a,a=this.edges.pop_unsafe(),a.polygon=null,a.next=rt.zpp_pool,rt.zpp_pool=a,this.edgeCnt=0}else if(this.edgeCnt!==0){let a=s==null?this.edges.head.elt:s.next.elt;this.edges.erase(s),a.polygon=null,a.next=rt.zpp_pool,rt.zpp_pool=a,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,a=l.x-i.x,r=l.y-i.y,p=o.x-l.x,h=(o.y-l.y)*a-p*r;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 a=l;for(l=l.next;l!=null;){let r=l,p=r.x-a.x,c=r.y-a.y,h=a.x-o.x,x=(a.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=a,a=r,l=l.next}if(i){l=this.lverts.next;let r=l,p=r.x-a.x,c=r.y-a.y,h=a.x-o.x,x=(a.y-o.y)*p-h*c;if(x>e.Config.epsilon?s=!0:x<-e.Config.epsilon&&(n=!0),!(s&&n)){o=a,a=r,l=l.next;let y=l,_=y.x-a.x,d=y.y-a.y,f=a.x-o.x,P=(a.y-o.y)*_-f*d;P>e.Config.epsilon?s=!0:P<-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 r=!0,p=this.lverts.next,c=p;for(p=p.next;p!=null&&r;){let h=p,u=this.lverts.next,x=u.next;for(;x!=null&&r;){let y=x;c!==u&&c!==y&&h!==u&&h!==y&&(r=this._checkNoIntersection(c,h,u,y,e)),u=y,x=x.next}if(r){let y=this.lverts.next;c!==u&&c!==y&&h!==u&&h!==y&&(r=this._checkNoIntersection(c,h,u,y,e))}c=h,p=p.next}if(r){let h=this.lverts.next,u=this.lverts.next,x=u.next;for(;x!=null&&r;){let y=x;c!==u&&c!==y&&h!==u&&h!==y&&(r=this._checkNoIntersection(c,h,u,y,e)),u=y,x=x.next}if(r){let y=this.lverts.next;c!==u&&c!==y&&h!==u&&h!==y&&(r=this._checkNoIntersection(c,h,u,y,e))}}return r?(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,a=t.x-e.x,r=t.y-e.y,p=s.x-n.x,c=s.y-n.y,h=r*p-a*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=(r*l-a*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,a=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*a,t+=o,this.area+=i.x*(l.y-s.y),s=i,i=l,n=n.next;let r=n;o=i.y*s.x-i.x*s.y,a=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*a,t+=o,this.area+=i.x*(r.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 a=o,r=n.elt;n=n.next,s+=r.length;let p=a.x-l.x,c=a.y-l.y;t+=r.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*r.lprojection*r.lprojection;let h=-(l.y*r.lnormx-l.x*r.lnormy)/(c*r.lnormx-p*r.lnormy);if(h>0){let u=h>1?1:h,x=l.x,y=l.y;x+=p*u,y+=c*u;let _=r.lnormy*l.x-r.lnormx*l.y,d=r.lnormy*x-r.lnormx*y,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*u*r.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,x=l.x,y=l.y;x+=p*u,y+=c*u;let _=r.lnormy*x-r.lnormx*y,d=r.lnormy*a.x-r.lnormx*a.y,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*e.Config.fluidVacuumDrag*(1-u)*r.length*e.Config.fluidAngularDrag}l=a,o=o.next}{let a=this.lverts.next,r=n.elt;s+=r.length;let p=a.x-l.x,c=a.y-l.y;t+=r.length*e.Config.fluidAngularDragFriction*this.material.dynamicFriction*r.lprojection*r.lprojection;let h=-(l.y*r.lnormx-l.x*r.lnormy)/(c*r.lnormx-p*r.lnormy);if(h>0){let u=h>1?1:h,x=l.x,y=l.y;x+=p*u,y+=c*u;let _=r.lnormy*l.x-r.lnormx*l.y,d=r.lnormy*x-r.lnormx*y,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*u*r.length*e.Config.fluidAngularDrag}if(h<1){let u=h<0?0:h,x=l.x,y=l.y;x+=p*u,y+=c*u;let _=r.lnormy*x-r.lnormx*y,d=r.lnormy*a.x-r.lnormx*a.y,f=(d*d*d-_*_*_)/(3*(d-_));t+=f*e.Config.fluidVacuumDrag*(1-u)*r.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 a=t;e+=s.x*(a.y-n.y);let r=a.y*s.x-a.x*s.y;this.localCOMx+=(s.x+a.x)*r,this.localCOMy+=(s.y+a.y)*r,n=s,s=a,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,a=this.spine2x+t,r=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>a?o:a,this.aabb.maxy=r>p?r: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,a=this.spine2y-s,r=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<a?o:a,this.aabb.maxx=r>p?r: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 a=.5;l.localCOMx*=a,l.localCOMy*=a}else{l.localCOMx=0,l.localCOMy=0;let o=0,a=l.lverts.next,r=a;a=a.next;let p=a;for(a=a.next;a!=null;){let _=a;o+=p.x*(_.y-r.y);let d=_.y*p.x-_.x*p.y;l.localCOMx+=(p.x+_.x)*d,l.localCOMy+=(p.y+_.y)*d,r=p,p=_,a=a.next}a=l.lverts.next;let c=a;o+=p.x*(c.y-r.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,r=p,p=c,a=a.next;let u=a;o+=p.x*(u.y-r.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 y=o;l.localCOMx*=y,l.localCOMy*=y}}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 a=o,r=l;l=l.next,a.x=t.body.posx+(t.body.axisy*r.x-t.body.axisx*r.y),a.y=t.body.posy+(r.x*t.body.axisx+r.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 r=i.polygon;if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(r.lverts.next.next==null)r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;else if(r.lverts.next.next.next==null){r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;let p=1;r.localCOMx+=r.lverts.next.next.x*p,r.localCOMy+=r.lverts.next.next.y*p;let c=.5;r.localCOMx*=c,r.localCOMy*=c}else{r.localCOMx=0,r.localCOMy=0;let p=0,c=r.lverts.next,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let z=c;p+=u.x*(z.y-h.y);let P=z.y*u.x-z.x*u.y;r.localCOMx+=(u.x+z.x)*P,r.localCOMy+=(u.y+z.y)*P,h=u,u=z,c=c.next}c=r.lverts.next;let x=c;p+=u.x*(x.y-h.y);let y=x.y*u.x-x.x*u.y;r.localCOMx+=(u.x+x.x)*y,r.localCOMy+=(u.y+x.y)*y,h=u,u=x,c=c.next;let _=c;p+=u.x*(_.y-h.y);let d=_.y*u.x-_.x*u.y;r.localCOMx+=(u.x+_.x)*d,r.localCOMy+=(u.y+_.y)*d,p=1/(3*p);let f=p;r.localCOMx*=f,r.localCOMy*=f}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let 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 a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let r=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=r;r=r.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 a=o;a.x<i.aabb.minx&&(i.aabb.minx=a.x),a.x>i.aabb.maxx&&(i.aabb.maxx=a.x),a.y<i.aabb.miny&&(i.aabb.miny=a.y),a.y>i.aabb.maxy&&(i.aabb.maxy=a.y),o=o.next}}let s;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,a=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(a):o.unshift(a)}else{let l=this.aabbShape.zpp_inner.aabb,o=(e.maxx-e.minx)/(l.maxx-l.minx),a=(e.maxy-e.miny)/(l.maxy-l.miny);this.matrix==null&&(this.matrix=new n.geom.Mat23);let r=this.matrix;if(o!==o)throw new Error("Error: Mat23::a cannot be NaN");r.zpp_inner.a=o;let p=r.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 y=c.zpp_inner;y._invalidate!=null&&y._invalidate();let _=this.matrix;if(a!==a)throw new Error("Error: Mat23::d cannot be NaN");_.zpp_inner.d=a;let d=_.zpp_inner;d._invalidate!=null&&d._invalidate();let f=this.matrix,z=e.minx-o*l.minx;if(z!==z)throw new Error("Error: Mat23::tx cannot be NaN");f.zpp_inner.tx=z;let P=f.zpp_inner;P._invalidate!=null&&P._invalidate();let Z=this.matrix,m=e.miny-a*l.miny;if(m!==m)throw new Error("Error: Mat23::ty cannot be NaN");Z.zpp_inner.ty=m;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 P=h;c+=x.x*(P.y-u.y);let Z=P.y*x.x-P.x*x.y;p.localCOMx+=(x.x+P.x)*Z,p.localCOMy+=(x.y+P.y)*Z,u=x,x=P,h=h.next}h=p.lverts.next;let y=h;c+=x.x*(y.y-u.y);let _=y.y*x.x-y.x*x.y;p.localCOMx+=(x.x+y.x)*_,p.localCOMy+=(x.y+y.y)*_,u=x,x=y,h=h.next;let d=h;c+=x.x*(d.y-u.y);let f=d.y*x.x-d.x*x.y;p.localCOMx+=(x.x+d.x)*f,p.localCOMy+=(x.y+d.y)*f,c=1/(3*c);let z=c;p.localCOMx*=z,p.localCOMy*=z}}l.wrap_localCOM!=null&&(l.wrap_localCOM.zpp_inner.x=l.localCOMx,l.wrap_localCOM.zpp_inner.y=l.localCOMy)}let r=l.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot)),l.worldCOMx=l.body.posx+(l.body.axisy*l.localCOMx-l.body.axisx*l.localCOMy),l.worldCOMy=l.body.posy+(l.localCOMx*l.body.axisx+l.localCOMy*l.body.axisy)}let o=l.radius,a=l.radius;l.aabb.minx=l.worldCOMx-o,l.aabb.miny=l.worldCOMy-a,l.aabb.maxx=l.worldCOMx+o,l.aabb.maxy=l.worldCOMy+a}else{let l=s.polygon;if(l.zip_gverts&&l.body!=null){l.zip_gverts=!1,l.validate_lverts();let r=l.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.rot));let 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 a=l.gverts.next.next;for(;a!=null;){let r=a;r.x<l.aabb.minx&&(l.aabb.minx=r.x),r.x>l.aabb.maxx&&(l.aabb.maxx=r.x),r.y<l.aabb.miny&&(l.aabb.miny=r.y),r.y>l.aabb.maxy&&(l.aabb.maxy=r.y),a=a.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 y=x,_=u;u=u.next,y.x=i.body.posx+(i.body.axisy*_.x-i.body.axisx*_.y),y.y=i.body.posy+(_.x*i.body.axisx+_.y*i.body.axisy),x=x.next}}let o=i.edges.head,a=i.gverts.next,r=a;for(a=a.next;a!=null;){let h=a,u=o.elt;o=o.next,u.gp0=r,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,r=h,a=a.next}let p=i.gverts.next,c=o.elt;o=o.next,c.gp0=r,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 a=new i.phys.Body(s.util.ZPP_Flags.BodyType_STATIC).zpp_inner.wrap_shapes,r=e,p=t;if(p==null&&(p=0),r==null&&(r=0),r!==r||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=r,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(),r!==r||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 y=c.zpp_inner;if(y._validate!=null&&y._validate(),c.zpp_inner.x==r){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=r,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);a.zpp_inner.reverse_flag?a.push(h):a.unshift(h)}else{let o=this.circShape.zpp_inner.circle,a=n/o.radius;this.matrix==null&&(this.matrix=new i.geom.Mat23);let r=this.matrix,p=this.matrix;if(a!==a)throw new Error("Error: Mat23::d cannot be NaN");p.zpp_inner.d=a;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");r.zpp_inner.a=h;let u=r.zpp_inner;u._invalidate!=null&&u._invalidate();let x=this.matrix,y=this.matrix;y.zpp_inner.c=0;let _=y.zpp_inner;_._invalidate!=null&&_._invalidate();let d=y.zpp_inner.c;if(d!==d)throw new Error("Error: Mat23::b cannot be NaN");x.zpp_inner.b=d;let f=x.zpp_inner;f._invalidate!=null&&f._invalidate();let z=this.matrix,P=e-a*o.localCOMx;if(P!==P)throw new Error("Error: Mat23::tx cannot be NaN");z.zpp_inner.tx=P;let Z=z.zpp_inner;Z._invalidate!=null&&Z._invalidate();let m=this.matrix,b=t-a*o.localCOMy;if(b!==b)throw new Error("Error: Mat23::ty cannot be NaN");m.zpp_inner.ty=b;let C=m.zpp_inner;C._invalidate!=null&&C._invalidate(),this.circShape.transform(this.matrix)}let l=this.circShape.zpp_inner;if(l.zip_aabb&&l.body!=null)if(l.zip_aabb=!1,l.type==0){let 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 y=u;for(u=u.next;u!=null;){let Z=u;h+=y.x*(Z.y-x.y);let m=Z.y*y.x-Z.x*y.y;c.localCOMx+=(y.x+Z.x)*m,c.localCOMy+=(y.y+Z.y)*m,x=y,y=Z,u=u.next}u=c.lverts.next;let _=u;h+=y.x*(_.y-x.y);let d=_.y*y.x-_.x*y.y;c.localCOMx+=(y.x+_.x)*d,c.localCOMy+=(y.y+_.y)*d,x=y,y=_,u=u.next;let f=u;h+=y.x*(f.y-x.y);let z=f.y*y.x-f.x*y.y;c.localCOMx+=(y.x+f.x)*z,c.localCOMy+=(y.y+f.y)*z,h=1/(3*h);let P=h;c.localCOMx*=P,c.localCOMy*=P}}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 a=o.radius,r=o.radius;o.aabb.minx=o.worldCOMx-a,o.aabb.miny=o.worldCOMy-r,o.aabb.maxx=o.worldCOMx+a,o.aabb.maxy=o.worldCOMy+r}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 a=o.gverts.next;o.aabb.minx=a.x,o.aabb.miny=a.y,o.aabb.maxx=a.x,o.aabb.maxy=a.y;let r=o.gverts.next.next;for(;r!=null;){let p=r;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),r=r.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 r=t.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.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 r=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=r,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=r,i=i.next}let o=t.gverts.next,a=s.elt;s=s.next,a.gp0=l,a.gp1=o,a.gnormx=t.body.axisy*a.lnormx-t.body.axisx*a.lnormy,a.gnormy=a.lnormx*t.body.axisx+a.lnormy*t.body.axisy,a.gprojection=t.body.posx*a.gnormx+t.body.posy*a.gnormy+a.lprojection,a.wrap_gnorm!=null&&(a.wrap_gnorm.zpp_inner.x=a.gnormx,a.wrap_gnorm.zpp_inner.y=a.gnormy),a.tp0=a.gp0.y*a.gnormx-a.gp0.x*a.gnormy,a.tp1=a.gp1.y*a.gnormx-a.gp1.x*a.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 a=.5;l.localCOMx*=a,l.localCOMy*=a}else{l.localCOMx=0,l.localCOMy=0;let o=0,a=l.lverts.next,r=a;a=a.next;let p=a;for(a=a.next;a!=null;){let _=a;o+=p.x*(_.y-r.y);let d=_.y*p.x-_.x*p.y;l.localCOMx+=(p.x+_.x)*d,l.localCOMy+=(p.y+_.y)*d,r=p,p=_,a=a.next}a=l.lverts.next;let c=a;o+=p.x*(c.y-r.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,r=p,p=c,a=a.next;let u=a;o+=p.x*(u.y-r.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 y=o;l.localCOMx*=y,l.localCOMy*=y}}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 a=o,r=l;l=l.next,a.x=t.body.posx+(t.body.axisy*r.x-t.body.axisx*r.y),a.y=t.body.posy+(r.x*t.body.axisx+r.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 a=i;s+=o.x*(a.y-l.y);let r=a.y*o.x-a.x*o.y;n.localCOMx+=(o.x+a.x)*r,n.localCOMy+=(o.y+a.y)*r,l=o,o=a,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 et=class{constructor(){this.n1=null;this.n2=null;this.first=!1;this.sleeping=!1;this.id=0;this.di=0;this.arb=null;this.next=null}alloc(){}free(){this.n1=this.n2=null,this.sleeping=!1}};et.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 r=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 y=Zt.tmpaabb,_=(y.maxx-y.minx+(y.maxy-y.miny))*2,d=2*_,f=2*(_-h),z=Zt.tmpaabb,P=r.aabb;z.minx=t.minx<P.minx?t.minx:P.minx,z.miny=t.miny<P.miny?t.miny:P.miny,z.maxx=t.maxx>P.maxx?t.maxx:P.maxx,z.maxy=t.maxy>P.maxy?t.maxy:P.maxy;let Z;if(r.child1==null){let v=Zt.tmpaabb;Z=(v.maxx-v.minx+(v.maxy-v.miny))*2+f}else{let v=r.aabb,w=(v.maxx-v.minx+(v.maxy-v.miny))*2,O=Zt.tmpaabb;Z=(O.maxx-O.minx+(O.maxy-O.miny))*2-w+f}let m=Zt.tmpaabb,b=p.aabb;m.minx=t.minx<b.minx?t.minx:b.minx,m.miny=t.miny<b.miny?t.miny:b.miny,m.maxx=t.maxx>b.maxx?t.maxx:b.maxx,m.maxy=t.maxy>b.maxy?t.maxy:b.maxy;let C;if(p.child1==null){let v=Zt.tmpaabb;C=(v.maxx-v.minx+(v.maxy-v.miny))*2+f}else{let v=p.aabb,w=(v.maxx-v.minx+(v.maxy-v.miny))*2,O=Zt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-w+f}if(d<Z&&d<C)break;n=Z<C?r: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,a=s.aabb;for(o.minx=t.minx<a.minx?t.minx:a.minx,o.miny=t.miny<a.miny?t.miny:a.miny,o.maxx=t.maxx>a.maxx?t.maxx:a.maxx,o.maxy=t.maxy>a.maxy?t.maxy:a.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,d=n.child2,f=d.height-_.height;if(f>1){let z=d.child1,P=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,z.height>P.height){d.child2=z,n.child2=P,P.parent=n;let Z=n.aabb,m=_.aabb,b=P.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=n.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,k=P.height;n.height=1+(O>k?O:k);let g=n.height,E=z.height;d.height=1+(g>E?g:E)}else{d.child2=P,n.child2=z,z.parent=n;let Z=n.aabb,m=_.aabb,b=z.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=n.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,k=z.height;n.height=1+(O>k?O:k);let g=n.height,E=P.height;d.height=1+(g>E?g:E)}n=d}else if(f<-1){let z=_.child1,P=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,z.height>P.height){_.child2=z,n.child1=P,P.parent=n;let Z=n.aabb,m=d.aabb,b=P.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=n.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,k=P.height;n.height=1+(O>k?O:k);let g=n.height,E=z.height;_.height=1+(g>E?g:E)}else{_.child2=P,n.child1=z,z.parent=n;let Z=n.aabb,m=d.aabb,b=z.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=n.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,k=z.height;n.height=1+(O>k?O:k);let g=n.height,E=P.height;_.height=1+(g>E?g:E)}n=_}else n=n}let r=n.child1,p=n.child2,c=r.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=r.aabb,y=p.aabb;u.minx=x.minx<y.minx?x.minx:y.minx,u.miny=x.miny<y.miny?x.miny:y.miny,u.maxx=x.maxx>y.maxx?x.maxx:y.maxx,u.maxy=x.maxy>y.maxy?x.maxy:y.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 r=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 y=Zt.tmpaabb,_=(y.maxx-y.minx+(y.maxy-y.miny))*2,d=2*_,f=2*(_-h),z=Zt.tmpaabb,P=r.aabb;z.minx=t.minx<P.minx?t.minx:P.minx,z.miny=t.miny<P.miny?t.miny:P.miny,z.maxx=t.maxx>P.maxx?t.maxx:P.maxx,z.maxy=t.maxy>P.maxy?t.maxy:P.maxy;let Z;if(r.child1==null){let v=Zt.tmpaabb;Z=(v.maxx-v.minx+(v.maxy-v.miny))*2+f}else{let v=r.aabb,w=(v.maxx-v.minx+(v.maxy-v.miny))*2,O=Zt.tmpaabb;Z=(O.maxx-O.minx+(O.maxy-O.miny))*2-w+f}let m=Zt.tmpaabb,b=p.aabb;m.minx=t.minx<b.minx?t.minx:b.minx,m.miny=t.miny<b.miny?t.miny:b.miny,m.maxx=t.maxx>b.maxx?t.maxx:b.maxx,m.maxy=t.maxy>b.maxy?t.maxy:b.maxy;let C;if(p.child1==null){let v=Zt.tmpaabb;C=(v.maxx-v.minx+(v.maxy-v.miny))*2+f}else{let v=p.aabb,w=(v.maxx-v.minx+(v.maxy-v.miny))*2,O=Zt.tmpaabb;C=(O.maxx-O.minx+(O.maxy-O.miny))*2-w+f}if(d<Z&&d<C)break;n=Z<C?r: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,a=s.aabb;for(o.minx=t.minx<a.minx?t.minx:a.minx,o.miny=t.miny<a.miny?t.miny:a.miny,o.maxx=t.maxx>a.maxx?t.maxx:a.maxx,o.maxy=t.maxy>a.maxy?t.maxy:a.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,d=n.child2,f=d.height-_.height;if(f>1){let z=d.child1,P=d.child2;if(d.child1=n,d.parent=n.parent,n.parent=d,d.parent!=null?d.parent.child1==n?d.parent.child1=d:d.parent.child2=d:this.root=d,z.height>P.height){d.child2=z,n.child2=P,P.parent=n;let Z=n.aabb,m=_.aabb,b=P.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=n.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,k=P.height;n.height=1+(O>k?O:k);let g=n.height,E=z.height;d.height=1+(g>E?g:E)}else{d.child2=P,n.child2=z,z.parent=n;let Z=n.aabb,m=_.aabb,b=z.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=n.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,k=z.height;n.height=1+(O>k?O:k);let g=n.height,E=P.height;d.height=1+(g>E?g:E)}n=d}else if(f<-1){let z=_.child1,P=_.child2;if(_.child1=n,_.parent=n.parent,n.parent=_,_.parent!=null?_.parent.child1==n?_.parent.child1=_:_.parent.child2=_:this.root=_,z.height>P.height){_.child2=z,n.child1=P,P.parent=n;let Z=n.aabb,m=d.aabb,b=P.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=n.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,k=P.height;n.height=1+(O>k?O:k);let g=n.height,E=z.height;_.height=1+(g>E?g:E)}else{_.child2=P,n.child1=z,z.parent=n;let Z=n.aabb,m=d.aabb,b=z.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=n.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,k=z.height;n.height=1+(O>k?O:k);let g=n.height,E=P.height;_.height=1+(g>E?g:E)}n=_}else n=n}let r=n.child1,p=n.child2,c=r.height,h=p.height;n.height=1+(c>h?c:h);let u=n.aabb,x=r.aabb,y=p.aabb;u.minx=x.minx<y.minx?x.minx:y.minx,u.miny=x.miny<y.miny?x.miny:y.miny,u.maxx=x.maxx>y.maxx?x.maxx:y.maxx,u.maxy=x.maxy>y.maxy?x.maxy:y.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,d=o.child2,f=d.height-_.height;if(f>1){let z=d.child1,P=d.child2;if(d.child1=o,d.parent=o.parent,o.parent=d,d.parent!=null?d.parent.child1==o?d.parent.child1=d:d.parent.child2=d:this.root=d,z.height>P.height){d.child2=z,o.child2=P,P.parent=o;let Z=o.aabb,m=_.aabb,b=P.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=o.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,k=P.height;o.height=1+(O>k?O:k);let g=o.height,E=z.height;d.height=1+(g>E?g:E)}else{d.child2=P,o.child2=z,z.parent=o;let Z=o.aabb,m=_.aabb,b=z.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=o.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,k=z.height;o.height=1+(O>k?O:k);let g=o.height,E=P.height;d.height=1+(g>E?g:E)}o=d}else if(f<-1){let z=_.child1,P=_.child2;if(_.child1=o,_.parent=o.parent,o.parent=_,_.parent!=null?_.parent.child1==o?_.parent.child1=_:_.parent.child2=_:this.root=_,z.height>P.height){_.child2=z,o.child1=P,P.parent=o;let Z=o.aabb,m=d.aabb,b=P.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=o.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,k=P.height;o.height=1+(O>k?O:k);let g=o.height,E=z.height;_.height=1+(g>E?g:E)}else{_.child2=P,o.child1=z,z.parent=o;let Z=o.aabb,m=d.aabb,b=z.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=o.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,k=z.height;o.height=1+(O>k?O:k);let g=o.height,E=P.height;_.height=1+(g>E?g:E)}o=_}else o=o}let a=o,r=a.child1,p=a.child2,c=a.aabb,h=r.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=r.height,y=p.height;a.height=1+(x>y?x:y),o=a.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,d=o.child2,f=d.height-_.height;if(f>1){let z=d.child1,P=d.child2;if(d.child1=o,d.parent=o.parent,o.parent=d,d.parent!=null?d.parent.child1==o?d.parent.child1=d:d.parent.child2=d:this.root=d,z.height>P.height){d.child2=z,o.child2=P,P.parent=o;let Z=o.aabb,m=_.aabb,b=P.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=o.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,k=P.height;o.height=1+(O>k?O:k);let g=o.height,E=z.height;d.height=1+(g>E?g:E)}else{d.child2=P,o.child2=z,z.parent=o;let Z=o.aabb,m=_.aabb,b=z.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=d.aabb,v=o.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=_.height,k=z.height;o.height=1+(O>k?O:k);let g=o.height,E=P.height;d.height=1+(g>E?g:E)}o=d}else if(f<-1){let z=_.child1,P=_.child2;if(_.child1=o,_.parent=o.parent,o.parent=_,_.parent!=null?_.parent.child1==o?_.parent.child1=_:_.parent.child2=_:this.root=_,z.height>P.height){_.child2=z,o.child1=P,P.parent=o;let Z=o.aabb,m=d.aabb,b=P.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=o.aabb,w=z.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,k=P.height;o.height=1+(O>k?O:k);let g=o.height,E=z.height;_.height=1+(g>E?g:E)}else{_.child2=P,o.child1=z,z.parent=o;let Z=o.aabb,m=d.aabb,b=z.aabb;Z.minx=m.minx<b.minx?m.minx:b.minx,Z.miny=m.miny<b.miny?m.miny:b.miny,Z.maxx=m.maxx>b.maxx?m.maxx:b.maxx,Z.maxy=m.maxy>b.maxy?m.maxy:b.maxy;let C=_.aabb,v=o.aabb,w=P.aabb;C.minx=v.minx<w.minx?v.minx:w.minx,C.miny=v.miny<w.miny?v.miny:w.miny,C.maxx=v.maxx>w.maxx?v.maxx:w.maxx,C.maxy=v.maxy>w.maxy?v.maxy:w.maxy;let O=d.height,k=z.height;o.height=1+(O>k?O:k);let g=o.height,E=P.height;_.height=1+(g>E?g:E)}o=_}else o=o}let a=o,r=a.child1,p=a.child2,c=a.aabb,h=r.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=r.height,y=p.height;a.height=1+(x>y?x:y),o=a.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,a=t.aabb,r=l.aabb;o.minx=a.minx<r.minx?a.minx:r.minx,o.miny=a.miny<r.miny?a.miny:r.miny,o.maxx=a.maxx>r.maxx?a.maxx:r.maxx,o.maxy=a.maxy>r.maxy?a.maxy:r.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 y=e.height,_=i.height;n.height=1+(y>_?y:_)}else{n.child2=l,e.child2=i,i.parent=e;let o=e.aabb,a=t.aabb,r=i.aabb;o.minx=a.minx<r.minx?a.minx:r.minx,o.miny=a.miny<r.miny?a.miny:r.miny,o.maxx=a.maxx>r.maxx?a.maxx:r.maxx,o.maxy=a.maxy>r.maxy?a.maxy:r.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 y=e.height,_=l.height;n.height=1+(y>_?y:_)}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,a=n.aabb,r=l.aabb;o.minx=a.minx<r.minx?a.minx:r.minx,o.miny=a.miny<r.miny?a.miny:r.miny,o.maxx=a.maxx>r.maxx?a.maxx:r.maxx,o.maxy=a.maxy>r.maxy?a.maxy:r.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 y=e.height,_=i.height;t.height=1+(y>_?y:_)}else{t.child2=l,e.child1=i,i.parent=e;let o=e.aabb,a=n.aabb,r=i.aabb;o.minx=a.minx<r.minx?a.minx:r.minx,o.miny=a.miny<r.miny?a.miny:r.miny,o.maxx=a.maxx>r.maxx?a.maxx:r.maxx,o.maxy=a.maxy>r.maxy?a.maxy:r.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 y=e.height,_=l.height;t.height=1+(y>_?y:_)}return t}else return e}}};Zt.tmpaabb=null;var Qe=Zt;var ze=class ze 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}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 a=null,r=this.syncs;for(;r!=null&&r!=n;)a=r,r=r.snext;a==null?this.syncs=r.snext:a.snext=r.snext,r.snext=null,n.synced=!1}if(n.moved){let a=null,r=this.moves;for(;r!=null&&r!=n;)a=r,r=r.mnext;a==null?this.moves=r.mnext:a.mnext=r.mnext,r.mnext=null,n.moved=!1}let s=null,i=this.pairs;for(;i!=null;){let a=i.next;if(i.n1==n||i.n2==n){s==null?this.pairs=a:s.next=a,i.arb!=null&&(i.arb.pair=null),i.arb=null,i.n1.shape.pairs.remove(i),i.n2.shape.pairs.remove(i);let r=i;r.n1=r.n2=null,r.sleeping=!1,r.next=et.zpp_pool,et.zpp_pool=r,i=a;continue}s=i,i=a}for(;t.pairs.head!=null;){let a=t.pairs.pop_unsafe();a.n1==n?a.n2.shape.pairs.remove(a):a.n1.shape.pairs.remove(a),a.arb!=null&&(a.arb.pair=null),a.arb=null;let r=a;r.n1=r.n2=null,r.sleeping=!1,r.next=et.zpp_pool,et.zpp_pool=r}let l=n;l.height=-1;let o=l.aabb;o.outer!=null&&(o.outer.zpp_inner=null,o.outer=null),o.wrap_min=o.wrap_max=null,o._invalidate=null,o._validate=null,o.next=fe.zpp_pool,fe.zpp_pool=o,l.child1=l.child2=l.parent=null,l.next=null,l.snext=null,l.mnext=null,l.next=Ve.zpp_pool,Ve.zpp_pool=l}__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 r=i.polygon;if(r.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(r.lverts.next.next==null)r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;else if(r.lverts.next.next.next==null){r.localCOMx=r.lverts.next.x,r.localCOMy=r.lverts.next.y;let p=1;r.localCOMx+=r.lverts.next.next.x*p,r.localCOMy+=r.lverts.next.next.y*p;let c=.5;r.localCOMx*=c,r.localCOMy*=c}else{r.localCOMx=0,r.localCOMy=0;let p=0,c=r.lverts.next,h=c;c=c.next;let u=c;for(c=c.next;c!=null;){let z=c;p+=u.x*(z.y-h.y);let P=z.y*u.x-z.x*u.y;r.localCOMx+=(u.x+z.x)*P,r.localCOMy+=(u.y+z.y)*P,h=u,u=z,c=c.next}c=r.lverts.next;let x=c;p+=u.x*(x.y-h.y);let y=x.y*u.x-x.x*u.y;r.localCOMx+=(u.x+x.x)*y,r.localCOMy+=(u.y+x.y)*y,h=u,u=x,c=c.next;let _=c;p+=u.x*(_.y-h.y);let d=_.y*u.x-_.x*u.y;r.localCOMx+=(u.x+_.x)*d,r.localCOMy+=(u.y+_.y)*d,p=1/(3*p);let f=p;r.localCOMx*=f,r.localCOMy*=f}}i.wrap_localCOM!=null&&(i.wrap_localCOM.zpp_inner.x=i.localCOMx,i.wrap_localCOM.zpp_inner.y=i.localCOMy)}let a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot)),i.worldCOMx=i.body.posx+(i.body.axisy*i.localCOMx-i.body.axisx*i.localCOMy),i.worldCOMy=i.body.posy+(i.localCOMx*i.body.axisx+i.localCOMy*i.body.axisy)}let 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 a=i.body;a.zip_axis&&(a.zip_axis=!1,a.axisx=Math.sin(a.rot),a.axisy=Math.cos(a.rot));let r=i.lverts.next,p=i.gverts.next;for(;p!=null;){let c=p,h=r;r=r.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 a=o;a.x<i.aabb.minx&&(i.aabb.minx=a.x),a.x>i.aabb.maxx&&(i.aabb.maxx=a.x),a.y<i.aabb.miny&&(i.aabb.miny=a.y),a.y>i.aabb.maxy&&(i.aabb.maxy=a.y),o=o.next}}let s;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 a=t.dyn?this.dtree:this.stree;if(t==a.root)a.root=null;else{let r=t.parent,p=r.parent,c=r.child1==t?r.child2:r.child1;if(p!=null){p.child1==r?p.child1=c:p.child2=c,c.parent=p;let h=r;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 m=x.child1,b=x.child2,C=b.height-m.height;if(C>1){let v=b.child1,w=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:a.root=b,v.height>w.height){b.child2=v,x.child2=w,w.parent=x;let O=x.aabb,k=m.aabb,g=w.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=b.aabb,M=x.aabb,N=v.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=m.height,D=w.height;x.height=1+(S>D?S:D);let j=x.height,R=v.height;b.height=1+(j>R?j:R)}else{b.child2=w,x.child2=v,v.parent=x;let O=x.aabb,k=m.aabb,g=v.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=b.aabb,M=x.aabb,N=w.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=m.height,D=v.height;x.height=1+(S>D?S:D);let j=x.height,R=w.height;b.height=1+(j>R?j:R)}x=b}else if(C<-1){let v=m.child1,w=m.child2;if(m.child1=x,m.parent=x.parent,x.parent=m,m.parent!=null?m.parent.child1==x?m.parent.child1=m:m.parent.child2=m:a.root=m,v.height>w.height){m.child2=v,x.child1=w,w.parent=x;let O=x.aabb,k=b.aabb,g=w.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=m.aabb,M=x.aabb,N=v.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=b.height,D=w.height;x.height=1+(S>D?S:D);let j=x.height,R=v.height;m.height=1+(j>R?j:R)}else{m.child2=w,x.child1=v,v.parent=x;let O=x.aabb,k=b.aabb,g=v.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=m.aabb,M=x.aabb,N=w.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=b.height,D=v.height;x.height=1+(S>D?S:D);let j=x.height,R=w.height;m.height=1+(j>R?j:R)}x=m}else x=x}let y=x.child1,_=x.child2,d=x.aabb,f=y.aabb,z=_.aabb;d.minx=f.minx<z.minx?f.minx:z.minx,d.miny=f.miny<z.miny?f.miny:z.miny,d.maxx=f.maxx>z.maxx?f.maxx:z.maxx,d.maxy=f.maxy>z.maxy?f.maxy:z.maxy;let P=y.height,Z=_.height;x.height=1+(P>Z?P:Z),x=x.parent}}else{a.root=c,c.parent=null;let h=r;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 a=s.circle;if(a.zip_worldCOM&&a.body!=null){if(a.zip_worldCOM=!1,a.zip_localCOM){if(a.zip_localCOM=!1,a.type==1){let h=a.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,y=x;x=x.next;let _=x;for(x=x.next;x!=null;){let m=x;u+=_.x*(m.y-y.y);let b=m.y*_.x-m.x*_.y;h.localCOMx+=(_.x+m.x)*b,h.localCOMy+=(_.y+m.y)*b,y=_,_=m,x=x.next}x=h.lverts.next;let d=x;u+=_.x*(d.y-y.y);let f=d.y*_.x-d.x*_.y;h.localCOMx+=(_.x+d.x)*f,h.localCOMy+=(_.y+d.y)*f,y=_,_=d,x=x.next;let z=x;u+=_.x*(z.y-y.y);let P=z.y*_.x-z.x*_.y;h.localCOMx+=(_.x+z.x)*P,h.localCOMy+=(_.y+z.y)*P,u=1/(3*u);let Z=u;h.localCOMx*=Z,h.localCOMy*=Z}}a.wrap_localCOM!=null&&(a.wrap_localCOM.zpp_inner.x=a.localCOMx,a.wrap_localCOM.zpp_inner.y=a.localCOMy)}let c=a.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),a.worldCOMx=a.body.posx+(a.body.axisy*a.localCOMx-a.body.axisx*a.localCOMy),a.worldCOMy=a.body.posy+(a.localCOMx*a.body.axisx+a.localCOMy*a.body.axisy)}let r=a.radius,p=a.radius;a.aabb.minx=a.worldCOMx-r,a.aabb.miny=a.worldCOMy-p,a.aabb.maxx=a.worldCOMx+r,a.aabb.maxy=a.worldCOMy+p}else{let a=s.polygon;if(a.zip_gverts&&a.body!=null){a.zip_gverts=!1,a.validate_lverts();let c=a.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=a.lverts.next,u=a.gverts.next;for(;u!=null;){let x=u,y=h;h=h.next,x.x=a.body.posx+(a.body.axisy*y.x-a.body.axisx*y.y),x.y=a.body.posy+(y.x*a.body.axisx+y.y*a.body.axisy),u=u.next}}if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=a.gverts.next;a.aabb.minx=r.x,a.aabb.miny=r.y,a.aabb.maxx=r.x,a.aabb.maxy=r.y;let p=a.gverts.next.next;for(;p!=null;){let c=p;c.x<a.aabb.minx&&(a.aabb.minx=c.x),c.x>a.aabb.maxx&&(a.aabb.maxx=c.x),c.y<a.aabb.miny&&(a.aabb.miny=c.y),c.y>a.aabb.maxy&&(a.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 a=t.aabb,r=o.root;for(;r.child1!=null;){let y=r.child1,_=r.child2,d=r.aabb,f=(d.maxx-d.minx+(d.maxy-d.miny))*2,z=Qe.tmpaabb,P=r.aabb;z.minx=P.minx<a.minx?P.minx:a.minx,z.miny=P.miny<a.miny?P.miny:a.miny,z.maxx=P.maxx>a.maxx?P.maxx:a.maxx,z.maxy=P.maxy>a.maxy?P.maxy:a.maxy;let Z=Qe.tmpaabb,m=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,b=2*m,C=2*(m-f),v=Qe.tmpaabb,w=y.aabb;v.minx=a.minx<w.minx?a.minx:w.minx,v.miny=a.miny<w.miny?a.miny:w.miny,v.maxx=a.maxx>w.maxx?a.maxx:w.maxx,v.maxy=a.maxy>w.maxy?a.maxy:w.maxy;let O;if(y.child1==null){let M=Qe.tmpaabb;O=(M.maxx-M.minx+(M.maxy-M.miny))*2+C}else{let M=y.aabb,N=(M.maxx-M.minx+(M.maxy-M.miny))*2,S=Qe.tmpaabb;O=(S.maxx-S.minx+(S.maxy-S.miny))*2-N+C}let k=Qe.tmpaabb,g=_.aabb;k.minx=a.minx<g.minx?a.minx:g.minx,k.miny=a.miny<g.miny?a.miny:g.miny,k.maxx=a.maxx>g.maxx?a.maxx:g.maxx,k.maxy=a.maxy>g.maxy?a.maxy:g.maxy;let E;if(_.child1==null){let M=Qe.tmpaabb;E=(M.maxx-M.minx+(M.maxy-M.miny))*2+C}else{let M=_.aabb,N=(M.maxx-M.minx+(M.maxy-M.miny))*2,S=Qe.tmpaabb;E=(S.maxx-S.minx+(S.maxy-S.miny))*2-N+C}if(b<O&&b<E)break;r=O<E?y:_}let p=r,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=a.minx<x.minx?a.minx:x.minx,u.miny=a.miny<x.miny?a.miny:x.miny,u.maxx=a.maxx>x.maxx?a.maxx:x.maxx,u.maxy=a.maxy>x.maxy?a.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),r=t.parent;r!=null;){if(r.child1==null||r.height<2)r=r;else{let m=r.child1,b=r.child2,C=b.height-m.height;if(C>1){let v=b.child1,w=b.child2;if(b.child1=r,b.parent=r.parent,r.parent=b,b.parent!=null?b.parent.child1==r?b.parent.child1=b:b.parent.child2=b:o.root=b,v.height>w.height){b.child2=v,r.child2=w,w.parent=r;let O=r.aabb,k=m.aabb,g=w.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=b.aabb,M=r.aabb,N=v.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=m.height,D=w.height;r.height=1+(S>D?S:D);let j=r.height,R=v.height;b.height=1+(j>R?j:R)}else{b.child2=w,r.child2=v,v.parent=r;let O=r.aabb,k=m.aabb,g=v.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=b.aabb,M=r.aabb,N=w.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=m.height,D=v.height;r.height=1+(S>D?S:D);let j=r.height,R=w.height;b.height=1+(j>R?j:R)}r=b}else if(C<-1){let v=m.child1,w=m.child2;if(m.child1=r,m.parent=r.parent,r.parent=m,m.parent!=null?m.parent.child1==r?m.parent.child1=m:m.parent.child2=m:o.root=m,v.height>w.height){m.child2=v,r.child1=w,w.parent=r;let O=r.aabb,k=b.aabb,g=w.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=m.aabb,M=r.aabb,N=v.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=b.height,D=w.height;r.height=1+(S>D?S:D);let j=r.height,R=v.height;m.height=1+(j>R?j:R)}else{m.child2=w,r.child1=v,v.parent=r;let O=r.aabb,k=b.aabb,g=v.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=m.aabb,M=r.aabb,N=w.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=b.height,D=v.height;r.height=1+(S>D?S:D);let j=r.height,R=w.height;m.height=1+(j>R?j:R)}r=m}else r=r}let y=r.child1,_=r.child2,d=y.height,f=_.height;r.height=1+(d>f?d:f);let z=r.aabb,P=y.aabb,Z=_.aabb;z.minx=P.minx<Z.minx?P.minx:Z.minx,z.miny=P.miny<Z.miny?P.miny:Z.miny,z.maxx=P.maxx>Z.maxx?P.maxx:Z.maxx,z.maxy=P.maxy>Z.maxy?P.maxy:Z.maxy,r=r.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 a=n.dyn?this.dtree:this.stree;if(n==a.root)a.root=null;else{let r=n.parent,p=r.parent,c=r.child1==n?r.child2:r.child1;if(p!=null){p.child1==r?p.child1=c:p.child2=c,c.parent=p;let h=r;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 m=x.child1,b=x.child2,C=b.height-m.height;if(C>1){let v=b.child1,w=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:a.root=b,v.height>w.height){b.child2=v,x.child2=w,w.parent=x;let O=x.aabb,k=m.aabb,g=w.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=b.aabb,M=x.aabb,N=v.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=m.height,D=w.height;x.height=1+(S>D?S:D);let j=x.height,R=v.height;b.height=1+(j>R?j:R)}else{b.child2=w,x.child2=v,v.parent=x;let O=x.aabb,k=m.aabb,g=v.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=b.aabb,M=x.aabb,N=w.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=m.height,D=v.height;x.height=1+(S>D?S:D);let j=x.height,R=w.height;b.height=1+(j>R?j:R)}x=b}else if(C<-1){let v=m.child1,w=m.child2;if(m.child1=x,m.parent=x.parent,x.parent=m,m.parent!=null?m.parent.child1==x?m.parent.child1=m:m.parent.child2=m:a.root=m,v.height>w.height){m.child2=v,x.child1=w,w.parent=x;let O=x.aabb,k=b.aabb,g=w.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=m.aabb,M=x.aabb,N=v.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=b.height,D=w.height;x.height=1+(S>D?S:D);let j=x.height,R=v.height;m.height=1+(j>R?j:R)}else{m.child2=w,x.child1=v,v.parent=x;let O=x.aabb,k=b.aabb,g=v.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=m.aabb,M=x.aabb,N=w.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=b.height,D=v.height;x.height=1+(S>D?S:D);let j=x.height,R=w.height;m.height=1+(j>R?j:R)}x=m}else x=x}let y=x.child1,_=x.child2,d=x.aabb,f=y.aabb,z=_.aabb;d.minx=f.minx<z.minx?f.minx:z.minx,d.miny=f.miny<z.miny?f.miny:z.miny,d.maxx=f.maxx>z.maxx?f.maxx:z.maxx,d.maxy=f.maxy>z.maxy?f.maxy:z.maxy;let P=y.height,Z=_.height;x.height=1+(P>Z?P:Z),x=x.parent}}else{a.root=c,c.parent=null;let h=r;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 a=s.circle;if(a.zip_worldCOM&&a.body!=null){if(a.zip_worldCOM=!1,a.zip_localCOM){if(a.zip_localCOM=!1,a.type==1){let h=a.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,y=x;x=x.next;let _=x;for(x=x.next;x!=null;){let m=x;u+=_.x*(m.y-y.y);let b=m.y*_.x-m.x*_.y;h.localCOMx+=(_.x+m.x)*b,h.localCOMy+=(_.y+m.y)*b,y=_,_=m,x=x.next}x=h.lverts.next;let d=x;u+=_.x*(d.y-y.y);let f=d.y*_.x-d.x*_.y;h.localCOMx+=(_.x+d.x)*f,h.localCOMy+=(_.y+d.y)*f,y=_,_=d,x=x.next;let z=x;u+=_.x*(z.y-y.y);let P=z.y*_.x-z.x*_.y;h.localCOMx+=(_.x+z.x)*P,h.localCOMy+=(_.y+z.y)*P,u=1/(3*u);let Z=u;h.localCOMx*=Z,h.localCOMy*=Z}}a.wrap_localCOM!=null&&(a.wrap_localCOM.zpp_inner.x=a.localCOMx,a.wrap_localCOM.zpp_inner.y=a.localCOMy)}let c=a.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot)),a.worldCOMx=a.body.posx+(a.body.axisy*a.localCOMx-a.body.axisx*a.localCOMy),a.worldCOMy=a.body.posy+(a.localCOMx*a.body.axisx+a.localCOMy*a.body.axisy)}let r=a.radius,p=a.radius;a.aabb.minx=a.worldCOMx-r,a.aabb.miny=a.worldCOMy-p,a.aabb.maxx=a.worldCOMx+r,a.aabb.maxy=a.worldCOMy+p}else{let a=s.polygon;if(a.zip_gverts&&a.body!=null){a.zip_gverts=!1,a.validate_lverts();let c=a.body;c.zip_axis&&(c.zip_axis=!1,c.axisx=Math.sin(c.rot),c.axisy=Math.cos(c.rot));let h=a.lverts.next,u=a.gverts.next;for(;u!=null;){let x=u,y=h;h=h.next,x.x=a.body.posx+(a.body.axisy*y.x-a.body.axisx*y.y),x.y=a.body.posy+(y.x*a.body.axisx+y.y*a.body.axisy),u=u.next}}if(a.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let r=a.gverts.next;a.aabb.minx=r.x,a.aabb.miny=r.y,a.aabb.maxx=r.x,a.aabb.maxy=r.y;let p=a.gverts.next.next;for(;p!=null;){let c=p;c.x<a.aabb.minx&&(a.aabb.minx=c.x),c.x>a.aabb.maxx&&(a.aabb.maxx=c.x),c.y<a.aabb.miny&&(a.aabb.miny=c.y),c.y>a.aabb.maxy&&(a.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 a=n.aabb,r=o.root;for(;r.child1!=null;){let y=r.child1,_=r.child2,d=r.aabb,f=(d.maxx-d.minx+(d.maxy-d.miny))*2,z=Qe.tmpaabb,P=r.aabb;z.minx=P.minx<a.minx?P.minx:a.minx,z.miny=P.miny<a.miny?P.miny:a.miny,z.maxx=P.maxx>a.maxx?P.maxx:a.maxx,z.maxy=P.maxy>a.maxy?P.maxy:a.maxy;let Z=Qe.tmpaabb,m=(Z.maxx-Z.minx+(Z.maxy-Z.miny))*2,b=2*m,C=2*(m-f),v=Qe.tmpaabb,w=y.aabb;v.minx=a.minx<w.minx?a.minx:w.minx,v.miny=a.miny<w.miny?a.miny:w.miny,v.maxx=a.maxx>w.maxx?a.maxx:w.maxx,v.maxy=a.maxy>w.maxy?a.maxy:w.maxy;let O;if(y.child1==null){let M=Qe.tmpaabb;O=(M.maxx-M.minx+(M.maxy-M.miny))*2+C}else{let M=y.aabb,N=(M.maxx-M.minx+(M.maxy-M.miny))*2,S=Qe.tmpaabb;O=(S.maxx-S.minx+(S.maxy-S.miny))*2-N+C}let k=Qe.tmpaabb,g=_.aabb;k.minx=a.minx<g.minx?a.minx:g.minx,k.miny=a.miny<g.miny?a.miny:g.miny,k.maxx=a.maxx>g.maxx?a.maxx:g.maxx,k.maxy=a.maxy>g.maxy?a.maxy:g.maxy;let E;if(_.child1==null){let M=Qe.tmpaabb;E=(M.maxx-M.minx+(M.maxy-M.miny))*2+C}else{let M=_.aabb,N=(M.maxx-M.minx+(M.maxy-M.miny))*2,S=Qe.tmpaabb;E=(S.maxx-S.minx+(S.maxy-S.miny))*2-N+C}if(b<O&&b<E)break;r=O<E?y:_}let p=r,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=a.minx<x.minx?a.minx:x.minx,u.miny=a.miny<x.miny?a.miny:x.miny,u.maxx=a.maxx>x.maxx?a.maxx:x.maxx,u.maxy=a.maxy>x.maxy?a.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),r=n.parent;r!=null;){if(r.child1==null||r.height<2)r=r;else{let m=r.child1,b=r.child2,C=b.height-m.height;if(C>1){let v=b.child1,w=b.child2;if(b.child1=r,b.parent=r.parent,r.parent=b,b.parent!=null?b.parent.child1==r?b.parent.child1=b:b.parent.child2=b:o.root=b,v.height>w.height){b.child2=v,r.child2=w,w.parent=r;let O=r.aabb,k=m.aabb,g=w.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=b.aabb,M=r.aabb,N=v.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=m.height,D=w.height;r.height=1+(S>D?S:D);let j=r.height,R=v.height;b.height=1+(j>R?j:R)}else{b.child2=w,r.child2=v,v.parent=r;let O=r.aabb,k=m.aabb,g=v.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=b.aabb,M=r.aabb,N=w.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=m.height,D=v.height;r.height=1+(S>D?S:D);let j=r.height,R=w.height;b.height=1+(j>R?j:R)}r=b}else if(C<-1){let v=m.child1,w=m.child2;if(m.child1=r,m.parent=r.parent,r.parent=m,m.parent!=null?m.parent.child1==r?m.parent.child1=m:m.parent.child2=m:o.root=m,v.height>w.height){m.child2=v,r.child1=w,w.parent=r;let O=r.aabb,k=b.aabb,g=w.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=m.aabb,M=r.aabb,N=v.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=b.height,D=w.height;r.height=1+(S>D?S:D);let j=r.height,R=v.height;m.height=1+(j>R?j:R)}else{m.child2=w,r.child1=v,v.parent=r;let O=r.aabb,k=b.aabb,g=v.aabb;O.minx=k.minx<g.minx?k.minx:g.minx,O.miny=k.miny<g.miny?k.miny:g.miny,O.maxx=k.maxx>g.maxx?k.maxx:g.maxx,O.maxy=k.maxy>g.maxy?k.maxy:g.maxy;let E=m.aabb,M=r.aabb,N=w.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=b.height,D=v.height;r.height=1+(S>D?S:D);let j=r.height,R=w.height;m.height=1+(j>R?j:R)}r=m}else r=r}let y=r.child1,_=r.child2,d=y.height,f=_.height;r.height=1+(d>f?d:f);let z=r.aabb,P=y.aabb,Z=_.aabb;z.minx=P.minx<Z.minx?P.minx:Z.minx,z.miny=P.miny<Z.miny?P.miny:Z.miny,z.maxx=P.maxx>Z.maxx?P.maxx:Z.maxx,z.maxy=P.maxy>Z.maxy?P.maxy:Z.maxy,r=r.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 o=s.shape;if(s.first_sync)s.first_sync=!1;else{let c=s.dyn?this.dtree:this.stree;if(s==c.root)c.root=null;else{let h=s.parent,u=h.parent,x=h.child1==s?h.child2:h.child1;if(u!=null){u.child1==h?u.child1=x:u.child2=x,x.parent=u;let y=h;y.height=-1;let _=y.aabb;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_.wrap_min=_.wrap_max=null,_._invalidate=null,_._validate=null,_.next=fe.zpp_pool,fe.zpp_pool=_,y.child1=y.child2=y.parent=null,y.next=null,y.snext=null,y.mnext=null,y.next=Ve.zpp_pool,Ve.zpp_pool=y;let d=u;for(;d!=null;){if(d.child1==null||d.height<2)d=d;else{let v=d.child1,w=d.child2,O=w.height-v.height;if(O>1){let k=w.child1,g=w.child2;if(w.child1=d,w.parent=d.parent,d.parent=w,w.parent!=null?w.parent.child1==d?w.parent.child1=w:w.parent.child2=w:c.root=w,k.height>g.height){w.child2=k,d.child2=g,g.parent=d;let E=d.aabb,M=v.aabb,N=g.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=w.aabb,D=d.aabb,j=k.aabb;S.minx=D.minx<j.minx?D.minx:j.minx,S.miny=D.miny<j.miny?D.miny:j.miny,S.maxx=D.maxx>j.maxx?D.maxx:j.maxx,S.maxy=D.maxy>j.maxy?D.maxy:j.maxy;let R=v.height,q=g.height;d.height=1+(R>q?R:q);let G=d.height,B=k.height;w.height=1+(G>B?G:B)}else{w.child2=g,d.child2=k,k.parent=d;let E=d.aabb,M=v.aabb,N=k.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=w.aabb,D=d.aabb,j=g.aabb;S.minx=D.minx<j.minx?D.minx:j.minx,S.miny=D.miny<j.miny?D.miny:j.miny,S.maxx=D.maxx>j.maxx?D.maxx:j.maxx,S.maxy=D.maxy>j.maxy?D.maxy:j.maxy;let R=v.height,q=k.height;d.height=1+(R>q?R:q);let G=d.height,B=g.height;w.height=1+(G>B?G:B)}d=w}else if(O<-1){let k=v.child1,g=v.child2;if(v.child1=d,v.parent=d.parent,d.parent=v,v.parent!=null?v.parent.child1==d?v.parent.child1=v:v.parent.child2=v:c.root=v,k.height>g.height){v.child2=k,d.child1=g,g.parent=d;let E=d.aabb,M=w.aabb,N=g.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=v.aabb,D=d.aabb,j=k.aabb;S.minx=D.minx<j.minx?D.minx:j.minx,S.miny=D.miny<j.miny?D.miny:j.miny,S.maxx=D.maxx>j.maxx?D.maxx:j.maxx,S.maxy=D.maxy>j.maxy?D.maxy:j.maxy;let R=w.height,q=g.height;d.height=1+(R>q?R:q);let G=d.height,B=k.height;v.height=1+(G>B?G:B)}else{v.child2=g,d.child1=k,k.parent=d;let E=d.aabb,M=w.aabb,N=k.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=v.aabb,D=d.aabb,j=g.aabb;S.minx=D.minx<j.minx?D.minx:j.minx,S.miny=D.miny<j.miny?D.miny:j.miny,S.maxx=D.maxx>j.maxx?D.maxx:j.maxx,S.maxy=D.maxy>j.maxy?D.maxy:j.maxy;let R=w.height,q=k.height;d.height=1+(R>q?R:q);let G=d.height,B=g.height;v.height=1+(G>B?G:B)}d=v}else d=d}let f=d.child1,z=d.child2,P=d.aabb,Z=f.aabb,m=z.aabb;P.minx=Z.minx<m.minx?Z.minx:m.minx,P.miny=Z.miny<m.miny?Z.miny:m.miny,P.maxx=Z.maxx>m.maxx?Z.maxx:m.maxx,P.maxy=Z.maxy>m.maxy?Z.maxy:m.maxy;let b=f.height,C=z.height;d.height=1+(b>C?b:C),d=d.parent}}else{c.root=x,x.parent=null;let y=h;y.height=-1;let _=y.aabb;_.outer!=null&&(_.outer.zpp_inner=null,_.outer=null),_.wrap_min=_.wrap_max=null,_._invalidate=null,_._validate=null,_.next=fe.zpp_pool,fe.zpp_pool=_,y.child1=y.child2=y.parent=null,y.next=null,y.snext=null,y.mnext=null,y.next=Ve.zpp_pool,Ve.zpp_pool=y}}}let a=s.aabb;if(!t.continuous&&o.zip_aabb&&o.body!=null)if(o.zip_aabb=!1,o.type==0){let c=o.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 y=c.polygon;if(y.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(y.lverts.next.next==null)y.localCOMx=y.lverts.next.x,y.localCOMy=y.lverts.next.y;else if(y.lverts.next.next.next==null){y.localCOMx=y.lverts.next.x,y.localCOMy=y.lverts.next.y;let _=1;y.localCOMx+=y.lverts.next.next.x*_,y.localCOMy+=y.lverts.next.next.y*_;let d=.5;y.localCOMx*=d,y.localCOMy*=d}else{y.localCOMx=0,y.localCOMy=0;let _=0,d=y.lverts.next,f=d;d=d.next;let z=d;for(d=d.next;d!=null;){let v=d;_+=z.x*(v.y-f.y);let w=v.y*z.x-v.x*z.y;y.localCOMx+=(z.x+v.x)*w,y.localCOMy+=(z.y+v.y)*w,f=z,z=v,d=d.next}d=y.lverts.next;let P=d;_+=z.x*(P.y-f.y);let Z=P.y*z.x-P.x*z.y;y.localCOMx+=(z.x+P.x)*Z,y.localCOMy+=(z.y+P.y)*Z,f=z,z=P,d=d.next;let m=d;_+=z.x*(m.y-f.y);let b=m.y*z.x-m.x*z.y;y.localCOMx+=(z.x+m.x)*b,y.localCOMy+=(z.y+m.y)*b,_=1/(3*_);let C=_;y.localCOMx*=C,y.localCOMy*=C}}c.wrap_localCOM!=null&&(c.wrap_localCOM.zpp_inner.x=c.localCOMx,c.wrap_localCOM.zpp_inner.y=c.localCOMy)}let x=c.body;x.zip_axis&&(x.zip_axis=!1,x.axisx=Math.sin(x.rot),x.axisy=Math.cos(x.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)}let h=c.radius,u=c.radius;c.aabb.minx=c.worldCOMx-h,c.aabb.miny=c.worldCOMy-u,c.aabb.maxx=c.worldCOMx+h,c.aabb.maxy=c.worldCOMy+u}else{let c=o.polygon;if(c.zip_gverts&&c.body!=null){c.zip_gverts=!1,c.validate_lverts();let x=c.body;x.zip_axis&&(x.zip_axis=!1,x.axisx=Math.sin(x.rot),x.axisy=Math.cos(x.rot));let y=c.lverts.next,_=c.gverts.next;for(;_!=null;){let d=_,f=y;y=y.next,d.x=c.body.posx+(c.body.axisy*f.x-c.body.axisx*f.y),d.y=c.body.posy+(f.x*c.body.axisx+f.y*c.body.axisy),_=_.next}}if(c.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful bounds");let h=c.gverts.next;c.aabb.minx=h.x,c.aabb.miny=h.y,c.aabb.maxx=h.x,c.aabb.maxy=h.y;let u=c.gverts.next.next;for(;u!=null;){let x=u;x.x<c.aabb.minx&&(c.aabb.minx=x.x),x.x>c.aabb.maxx&&(c.aabb.maxx=x.x),x.y<c.aabb.miny&&(c.aabb.miny=x.y),x.y>c.aabb.maxy&&(c.aabb.maxy=x.y),u=u.next}}let r=o.aabb;a.minx=r.minx-3,a.miny=r.miny-3,a.maxx=r.maxx+3,a.maxy=r.maxy+3;let p=(s.dyn=o.body.type==1?!1:!o.body.component.sleeping)?this.dtree:this.stree;if(p.root==null)p.root=s,p.root.parent=null;else{let c=s.aabb,h=p.root;for(;h.child1!=null;){let f=h.child1,z=h.child2,P=h.aabb,Z=(P.maxx-P.minx+(P.maxy-P.miny))*2,m=Qe.tmpaabb,b=h.aabb;m.minx=b.minx<c.minx?b.minx:c.minx,m.miny=b.miny<c.miny?b.miny:c.miny,m.maxx=b.maxx>c.maxx?b.maxx:c.maxx,m.maxy=b.maxy>c.maxy?b.maxy:c.maxy;let C=Qe.tmpaabb,v=(C.maxx-C.minx+(C.maxy-C.miny))*2,w=2*v,O=2*(v-Z),k=Qe.tmpaabb,g=f.aabb;k.minx=c.minx<g.minx?c.minx:g.minx,k.miny=c.miny<g.miny?c.miny:g.miny,k.maxx=c.maxx>g.maxx?c.maxx:g.maxx,k.maxy=c.maxy>g.maxy?c.maxy:g.maxy;let E;if(f.child1==null){let D=Qe.tmpaabb;E=(D.maxx-D.minx+(D.maxy-D.miny))*2+O}else{let D=f.aabb,j=(D.maxx-D.minx+(D.maxy-D.miny))*2,R=Qe.tmpaabb;E=(R.maxx-R.minx+(R.maxy-R.miny))*2-j+O}let M=Qe.tmpaabb,N=z.aabb;M.minx=c.minx<N.minx?c.minx:N.minx,M.miny=c.miny<N.miny?c.miny:N.miny,M.maxx=c.maxx>N.maxx?c.maxx:N.maxx,M.maxy=c.maxy>N.maxy?c.maxy:N.maxy;let S;if(z.child1==null){let D=Qe.tmpaabb;S=(D.maxx-D.minx+(D.maxy-D.miny))*2+O}else{let D=z.aabb,j=(D.maxx-D.minx+(D.maxy-D.miny))*2,R=Qe.tmpaabb;S=(R.maxx-R.minx+(R.maxy-R.miny))*2-j+O}if(w<E&&w<S)break;h=E<S?f:z}let u=h,x=u.parent,y;Ve.zpp_pool==null?y=new Ve:(y=Ve.zpp_pool,Ve.zpp_pool=y.next,y.next=null),fe.zpp_pool==null?y.aabb=new fe:(y.aabb=fe.zpp_pool,fe.zpp_pool=y.aabb.next,y.aabb.next=null),y.moved=!1,y.synced=!1,y.first_sync=!1,y.parent=x;let _=y.aabb,d=u.aabb;for(_.minx=c.minx<d.minx?c.minx:d.minx,_.miny=c.miny<d.miny?c.miny:d.miny,_.maxx=c.maxx>d.maxx?c.maxx:d.maxx,_.maxy=c.maxy>d.maxy?c.maxy:d.maxy,y.height=u.height+1,x!=null?(x.child1==u?x.child1=y:x.child2=y,y.child1=u,y.child2=s,u.parent=y,s.parent=y):(y.child1=u,y.child2=s,u.parent=y,s.parent=y,p.root=y),h=s.parent;h!=null;){if(h.child1==null||h.height<2)h=h;else{let v=h.child1,w=h.child2,O=w.height-v.height;if(O>1){let k=w.child1,g=w.child2;if(w.child1=h,w.parent=h.parent,h.parent=w,w.parent!=null?w.parent.child1==h?w.parent.child1=w:w.parent.child2=w:p.root=w,k.height>g.height){w.child2=k,h.child2=g,g.parent=h;let E=h.aabb,M=v.aabb,N=g.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=w.aabb,D=h.aabb,j=k.aabb;S.minx=D.minx<j.minx?D.minx:j.minx,S.miny=D.miny<j.miny?D.miny:j.miny,S.maxx=D.maxx>j.maxx?D.maxx:j.maxx,S.maxy=D.maxy>j.maxy?D.maxy:j.maxy;let R=v.height,q=g.height;h.height=1+(R>q?R:q);let G=h.height,B=k.height;w.height=1+(G>B?G:B)}else{w.child2=g,h.child2=k,k.parent=h;let E=h.aabb,M=v.aabb,N=k.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=w.aabb,D=h.aabb,j=g.aabb;S.minx=D.minx<j.minx?D.minx:j.minx,S.miny=D.miny<j.miny?D.miny:j.miny,S.maxx=D.maxx>j.maxx?D.maxx:j.maxx,S.maxy=D.maxy>j.maxy?D.maxy:j.maxy;let R=v.height,q=k.height;h.height=1+(R>q?R:q);let G=h.height,B=g.height;w.height=1+(G>B?G:B)}h=w}else if(O<-1){let k=v.child1,g=v.child2;if(v.child1=h,v.parent=h.parent,h.parent=v,v.parent!=null?v.parent.child1==h?v.parent.child1=v:v.parent.child2=v:p.root=v,k.height>g.height){v.child2=k,h.child1=g,g.parent=h;let E=h.aabb,M=w.aabb,N=g.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=v.aabb,D=h.aabb,j=k.aabb;S.minx=D.minx<j.minx?D.minx:j.minx,S.miny=D.miny<j.miny?D.miny:j.miny,S.maxx=D.maxx>j.maxx?D.maxx:j.maxx,S.maxy=D.maxy>j.maxy?D.maxy:j.maxy;let R=w.height,q=g.height;h.height=1+(R>q?R:q);let G=h.height,B=k.height;v.height=1+(G>B?G:B)}else{v.child2=g,h.child1=k,k.parent=h;let E=h.aabb,M=w.aabb,N=k.aabb;E.minx=M.minx<N.minx?M.minx:N.minx,E.miny=M.miny<N.miny?M.miny:N.miny,E.maxx=M.maxx>N.maxx?M.maxx:N.maxx,E.maxy=M.maxy>N.maxy?M.maxy:N.maxy;let S=v.aabb,D=h.aabb,j=g.aabb;S.minx=D.minx<j.minx?D.minx:j.minx,S.miny=D.miny<j.miny?D.miny:j.miny,S.maxx=D.maxx>j.maxx?D.maxx:j.maxx,S.maxy=D.maxy>j.maxy?D.maxy:j.maxy;let R=w.height,q=k.height;h.height=1+(R>q?R:q);let G=h.height,B=g.height;v.height=1+(G>B?G:B)}h=v}else h=h}let f=h.child1,z=h.child2,P=f.height,Z=z.height;h.height=1+(P>Z?P:Z);let m=h.aabb,b=f.aabb,C=z.aabb;m.minx=b.minx<C.minx?b.minx:C.minx,m.miny=b.miny<C.miny?b.miny:C.miny,m.maxx=b.maxx>C.maxx?b.maxx:C.maxx,m.maxy=b.maxy>C.maxy?b.maxy:C.maxy,h=h.parent}}s.synced=!1,s=s.snext}for(;this.syncs!=null;){let o=this.syncs;this.syncs=o.snext,o.snext=null;let a=o;if(a.moved)continue;a.moved=!1;let r=a.shape;if(r.body.component.sleeping)continue;let c=a.aabb,h=null;for(this.dtree.root!=null&&(this.dtree.root.next=h,h=this.dtree.root);h!=null;){let u=h;h=u.next,u.next=null;let x=u;if(x!=a)if(x.child1==null){let y=x.shape;if(y.body!=r.body&&!(y.body.type==1&&r.body.type==1)){let _=x.aabb;if(_.miny<=c.maxy&&c.miny<=_.maxy&&_.minx<=c.maxx&&c.minx<=_.maxx){let d,f;r.id<y.id?(d=r.id,f=y.id):(d=y.id,f=r.id);let z=r.pairs.length<y.pairs.length?r:y,P=null,Z=z.pairs.head;for(;Z!=null;){let k=Z.elt;if(k.id==d&&k.di==f){P=k;break}Z=Z.next}if(P!=null){P.sleeping&&(P.sleeping=!1,P.next=this.pairs,this.pairs=P,P.first=!0);continue}et.zpp_pool==null?P=new et:(P=et.zpp_pool,et.zpp_pool=P.next,P.next=null),P.n1=a,P.n2=x,P.id=d,P.di=f,P.next=this.pairs,this.pairs=P,P.first=!0;let m=r.pairs,b;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?b=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(b=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b.next,b.next=null),b.elt=P;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=y.pairs,w;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(w=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=P;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++}}}else{let y=x.aabb;y.miny<=c.maxy&&c.miny<=y.maxy&&y.minx<=c.maxx&&c.minx<=y.maxx&&(x.child1!=null&&(x.child1.next=h,h=x.child1),x.child2!=null&&(x.child2.next=h,h=x.child2))}}for(this.stree.root!=null&&(this.stree.root.next=h,h=this.stree.root);h!=null;){let u=h;h=u.next,u.next=null;let x=u;if(x!=a)if(x.child1==null){let y=x.shape;if(y.body!=r.body&&!(y.body.type==1&&r.body.type==1)){let _=x.aabb;if(_.miny<=c.maxy&&c.miny<=_.maxy&&_.minx<=c.maxx&&c.minx<=_.maxx){let d,f;r.id<y.id?(d=r.id,f=y.id):(d=y.id,f=r.id);let z=r.pairs.length<y.pairs.length?r:y,P=null,Z=z.pairs.head;for(;Z!=null;){let k=Z.elt;if(k.id==d&&k.di==f){P=k;break}Z=Z.next}if(P!=null){P.sleeping&&(P.sleeping=!1,P.next=this.pairs,this.pairs=P,P.first=!0);continue}et.zpp_pool==null?P=new et:(P=et.zpp_pool,et.zpp_pool=P.next,P.next=null),P.n1=a,P.n2=x,P.id=d,P.di=f,P.next=this.pairs,this.pairs=P,P.first=!0;let m=r.pairs,b;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?b=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(b=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b.next,b.next=null),b.elt=P;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=y.pairs,w;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(w=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=P;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++}}}else{let y=x.aabb;y.miny<=c.maxy&&c.miny<=y.maxy&&y.minx<=c.maxx&&c.minx<=y.maxx&&(x.child1!=null&&(x.child1.next=h,h=x.child1),x.child2!=null&&(x.child2.next=h,h=x.child2))}}}for(;this.moves!=null;){let o=this.moves;this.moves=o.mnext,o.mnext=null;let a=o;a.moved=!1;let r=a.shape;if(r.body.component.sleeping)continue;let c=a.aabb,h=null;for(this.dtree.root!=null&&(this.dtree.root.next=h,h=this.dtree.root);h!=null;){let u=h;h=u.next,u.next=null;let x=u;if(x!=a)if(x.child1==null){let y=x.shape;if(y.body!=r.body&&!(y.body.type==1&&r.body.type==1)){let _=x.aabb;if(_.miny<=c.maxy&&c.miny<=_.maxy&&_.minx<=c.maxx&&c.minx<=_.maxx){let d,f;r.id<y.id?(d=r.id,f=y.id):(d=y.id,f=r.id);let z=r.pairs.length<y.pairs.length?r:y,P=null,Z=z.pairs.head;for(;Z!=null;){let k=Z.elt;if(k.id==d&&k.di==f){P=k;break}Z=Z.next}if(P!=null){P.sleeping&&(P.sleeping=!1,P.next=this.pairs,this.pairs=P,P.first=!0);continue}et.zpp_pool==null?P=new et:(P=et.zpp_pool,et.zpp_pool=P.next,P.next=null),P.n1=a,P.n2=x,P.id=d,P.di=f,P.next=this.pairs,this.pairs=P,P.first=!0;let m=r.pairs,b;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?b=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(b=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b.next,b.next=null),b.elt=P;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=y.pairs,w;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(w=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=P;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++}}}else{let y=x.aabb;y.miny<=c.maxy&&c.miny<=y.maxy&&y.minx<=c.maxx&&c.minx<=y.maxx&&(x.child1!=null&&(x.child1.next=h,h=x.child1),x.child2!=null&&(x.child2.next=h,h=x.child2))}}for(this.stree.root!=null&&(this.stree.root.next=h,h=this.stree.root);h!=null;){let u=h;h=u.next,u.next=null;let x=u;if(x!=a)if(x.child1==null){let y=x.shape;if(y.body!=r.body&&!(y.body.type==1&&r.body.type==1)){let _=x.aabb;if(_.miny<=c.maxy&&c.miny<=_.maxy&&_.minx<=c.maxx&&c.minx<=_.maxx){let d,f;r.id<y.id?(d=r.id,f=y.id):(d=y.id,f=r.id);let z=r.pairs.length<y.pairs.length?r:y,P=null,Z=z.pairs.head;for(;Z!=null;){let k=Z.elt;if(k.id==d&&k.di==f){P=k;break}Z=Z.next}if(P!=null){P.sleeping&&(P.sleeping=!1,P.next=this.pairs,this.pairs=P,P.first=!0);continue}et.zpp_pool==null?P=new et:(P=et.zpp_pool,et.zpp_pool=P.next,P.next=null),P.n1=a,P.n2=x,P.id=d,P.di=f,P.next=this.pairs,this.pairs=P,P.first=!0;let m=r.pairs,b;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?b=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(b=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=b.next,b.next=null),b.elt=P;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=y.pairs,w;ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool==null?w=new ze._zpp.util.ZNPNode_ZPP_AABBPair:(w=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w.next,w.next=null),w.elt=P;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++}}}else{let y=x.aabb;y.miny<=c.maxy&&c.miny<=y.maxy&&y.minx<=c.maxx&&c.minx<=y.maxx&&(x.child1!=null&&(x.child1.next=h,h=x.child1),x.child2!=null&&(x.child2.next=h,h=x.child2))}}}let i=null,l=this.pairs;for(;l!=null;){let o;if(l.first)o=!1;else{let x=l.n1.aabb,y=l.n2.aabb;o=!(y.miny<=x.maxy&&x.miny<=y.maxy&&y.minx<=x.maxx&&x.minx<=y.maxx)}if(o){i==null?this.pairs=l.next:i.next=l.next;let x=l.n1.shape.pairs,y=null,_=x.head,d=!1;for(;_!=null;){if(_.elt==l){let C,v;y==null?(C=x.head,v=C.next,x.head=v,x.head==null&&(x.pushmod=!0)):(C=y.next,v=C.next,y.next=v,v==null&&(x.pushmod=!0));let w=C;w.elt=null,w.next=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w,x.modified=!0,x.length--,x.pushmod=!0,d=!0;break}y=_,_=_.next}let f=l.n2.shape.pairs,z=null,P=f.head,Z=!1;for(;P!=null;){if(P.elt==l){let C,v;z==null?(C=f.head,v=C.next,f.head=v,f.head==null&&(f.pushmod=!0)):(C=z.next,v=C.next,z.next=v,v==null&&(f.pushmod=!0));let w=C;w.elt=null,w.next=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=w,f.modified=!0,f.length--,f.pushmod=!0,Z=!0;break}z=P,P=P.next}let m=l.next;l.arb!=null&&(l.arb.pair=null),l.arb=null;let b=l;b.n1=b.n2=null,b.sleeping=!1,b.next=et.zpp_pool,et.zpp_pool=b,l=m;continue}let a=l.n1.shape,r=a.body,p=l.n2.shape,c=p.body;if(!l.first&&(r.component.sleeping||r.type==1)&&(c.component.sleeping||c.type==1)){l.sleeping=!0,i==null?this.pairs=l.next:i.next=l.next,l=l.next;continue}l.first=!1;let h=a.aabb,u=p.aabb;if(u.miny<=h.maxy&&h.miny<=u.maxy&&u.minx<=h.maxx&&h.minx<=u.maxx){let x=l.arb;n?l.arb=t.narrowPhase(a,p,r.type!=2||c.type!=2,l.arb,!1):l.arb=t.continuousEvent(a,p,r.type!=2||c.type!=2,l.arb,!1),l.arb==null?x!=null&&(x.pair=null):l.arb.pair=l}i=l,l=l.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;this.pairs.arb!=null&&(this.pairs.arb.pair=null),this.pairs.arb=null;let n=this.pairs.n1.shape.pairs,s=this.pairs,i=null,l=n.head,o=!1;for(;l!=null;){if(l.elt==s){let x,y;i==null?(x=n.head,y=x.next,n.head=y,n.head==null&&(n.pushmod=!0)):(x=i.next,y=x.next,i.next=y,y==null&&(n.pushmod=!0));let _=x;_.elt=null,_.next=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_,n.modified=!0,n.length--,n.pushmod=!0,o=!0;break}i=l,l=l.next}let a=this.pairs.n2.shape.pairs,r=this.pairs,p=null,c=a.head,h=!1;for(;c!=null;){if(c.elt==r){let x,y;p==null?(x=a.head,y=x.next,a.head=y,a.head==null&&(a.pushmod=!0)):(x=p.next,y=x.next,p.next=y,y==null&&(a.pushmod=!0));let _=x;_.elt=null,_.next=ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBPair.zpp_pool=_,a.modified=!0,a.length--,a.pushmod=!0,h=!0;break}p=c,c=c.next}let u=this.pairs;u.n1=u.n2=null,u.sleeping=!1,u.next=et.zpp_pool,et.zpp_pool=u,this.pairs=t}this.dtree.clear(),this.stree.clear()}shapesUnderPoint(t,n,s,i){this.sync_broadphase();let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,a=i??new ze._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(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)&&a.push(p.shape.outer):Ee.polyContains(p.shape.polygon,o)&&a.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.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)&&a.push(p.shape.outer):Ee.polyContains(p.shape.polygon,o)&&a.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let r=o;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=le.zpp_pool,le.zpp_pool=r,a}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,a=i??new ze._nape.phys.BodyList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(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(!a.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)&&a.push(h):Ee.polyContains(p.shape.polygon,o)&&a.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(o.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(!a.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)&&a.push(h):Ee.polyContains(p.shape.polygon,o)&&a.push(h))}}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}let r=o;return r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=le.zpp_pool,le.zpp_pool=r,a}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,a=l??new ze._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),p=r.aabb;if(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(r.child1==null){let c;if(i!=null){let h=r.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&a.push(r.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);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&&a.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=r.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(r.child1==null){let h;if(i!=null){let u=r.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,r.shape)&&a.push(r.shape.outer);else{let u=r.shape.aabb;(u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy||Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner))&&a.push(r.shape.outer)}else{let u;if(s){let x=r.shape.aabb;u=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy}else u=!0;u&&a.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 ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),p=r.aabb;if(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(r.child1==null){let c;if(i!=null){let h=r.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;c&&a.push(r.shape.outer)}else for(this.treeStack2==null&&(this.treeStack2=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);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&&a.push(c.shape.outer)}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=r.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(r.child1==null){let h;if(i!=null){let u=r.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,r.shape)&&a.push(r.shape.outer);else{let u=r.shape.aabb;(u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy||Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner))&&a.push(r.shape.outer)}else{let u;if(s){let x=r.shape.aabb;u=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy}else u=!0;u&&a.push(r.shape.outer)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}return a}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,a=l??new ze._nape.phys.BodyList;if(this.failed==null&&(this.failed=new ze._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),p=r.aabb;if(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(r.child1==null){let c;if(i!=null){let h=r.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=r.shape.body.outer;a.has(h)||a.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);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;a.has(u)||a.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=r.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(r.child1==null){let h=r.shape.body.outer,u;if(i!=null){let x=r.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,r.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner)&&a.push(h);else if(s){if(!this.failed.has(h)){let x=r.shape.aabb,y=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!a.has(h)&&y?a.push(h):y||(a.remove(h),this.failed.push(h))}}else{let x;if(a.has(h))x=!1;else{let y=r.shape.aabb;x=y.minx>=o.minx&&y.miny>=o.miny&&y.maxx<=o.maxx&&y.maxy<=o.maxy}x&&a.push(h)}}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 ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let r=this.treeStack.pop_unsafe(),p=r.aabb;if(p.minx>=o.minx&&p.miny>=o.miny&&p.maxx<=o.maxx&&p.maxy<=o.maxy)if(r.child1==null){let c;if(i!=null){let h=r.shape.filter;c=(h.collisionMask&i.collisionGroup)!=0&&(i.collisionMask&h.collisionGroup)!=0}else c=!0;if(c){let h=r.shape.body.outer;a.has(h)||a.push(h)}}else for(this.treeStack2==null&&(this.treeStack2=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack2.add(r);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;a.has(u)||a.push(u)}}else c.child1!=null&&this.treeStack2.add(c.child1),c.child2!=null&&this.treeStack2.add(c.child2)}else{let c=r.aabb;if(o.miny<=c.maxy&&c.miny<=o.maxy&&o.minx<=c.maxx&&c.minx<=o.maxx)if(r.child1==null){let h=r.shape.body.outer,u;if(i!=null){let x=r.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,r.shape);!a.has(h)&&x?a.push(h):x||(a.remove(h),this.failed.push(h))}}else!a.has(h)&&Ee.testCollide_safe(r.shape,this.aabbShape.zpp_inner)&&a.push(h);else if(s){if(!this.failed.has(h)){let x=r.shape.aabb,y=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!a.has(h)&&y?a.push(h):y||(a.remove(h),this.failed.push(h))}}else{let x;if(a.has(h))x=!1;else{let y=r.shape.aabb;x=y.minx>=o.minx&&y.miny>=o.miny&&y.maxx<=o.maxx&&y.maxy<=o.maxy}x&&a.push(h)}}else r.child1!=null&&this.treeStack.add(r.child1),r.child2!=null&&this.treeStack.add(r.child2)}}return this.failed.clear(),a}shapesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let a=this.circShape.zpp_inner.aabb,r=o??new ze._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.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)&&r.push(p.shape.outer):Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&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 ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.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)&&r.push(p.shape.outer):Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&r.push(p.shape.outer))}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return r}bodiesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let a=this.circShape.zpp_inner.aabb,r=o??new ze._nape.phys.BodyList;if(this.failed==null&&(this.failed=new ze._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.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);!r.has(h)&&x?r.push(h):x||(r.remove(h),this.failed.push(h))}}else!r.has(h)&&Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&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 ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let p=this.treeStack.pop_unsafe(),c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.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);!r.has(h)&&x?r.push(h):x||(r.remove(h),this.failed.push(h))}}else!r.has(h)&&Ee.testCollide_safe(p.shape,this.circShape.zpp_inner)&&r.push(h)}else p.child1!=null&&this.treeStack.add(p.child1),p.child2!=null&&this.treeStack.add(p.child2)}return this.failed.clear(),r}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new ze._nape.shape.ShapeList;if(this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),r=a.aabb;if(l.miny<=r.maxy&&r.miny<=l.maxy&&l.minx<=r.maxx&&r.minx<=l.maxx)if(a.child1==null){let p;if(s!=null){let c=a.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ee.containTest(t,a.shape)&&o.push(a.shape.outer):Ee.testCollide_safe(a.shape,t)&&o.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),r=a.aabb;if(l.miny<=r.maxy&&r.miny<=l.maxy&&l.minx<=r.maxx&&r.minx<=l.maxx)if(a.child1==null){let p;if(s!=null){let c=a.shape.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(n?Ee.containTest(t,a.shape)&&o.push(a.shape.outer):Ee.testCollide_safe(a.shape,t)&&o.push(a.shape.outer))}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return o}bodiesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new ze._nape.phys.BodyList;if(this.failed==null&&(this.failed=new ze._nape.phys.BodyList),this.stree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.stree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),r=a.aabb;if(l.miny<=r.maxy&&r.miny<=l.maxy&&l.minx<=r.maxx&&r.minx<=l.maxx)if(a.child1==null){let p=a.shape.body.outer,c;if(s!=null){let h=a.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,a.shape);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ee.testCollide_safe(a.shape,t)&&o.push(p)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}if(this.dtree.root!=null)for(this.treeStack==null&&(this.treeStack=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.treeStack.add(this.dtree.root);this.treeStack.head!=null;){let a=this.treeStack.pop_unsafe(),r=a.aabb;if(l.miny<=r.maxy&&r.miny<=l.maxy&&l.minx<=r.maxx&&r.minx<=l.maxx)if(a.child1==null){let p=a.shape.body.outer,c;if(s!=null){let h=a.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,a.shape);!o.has(p)&&h?o.push(p):h||(o.remove(p),this.failed.push(p))}}else!o.has(p)&&Ee.testCollide_safe(a.shape,t)&&o.push(p)}else a.child1!=null&&this.treeStack.add(a.child1),a.child2!=null&&this.treeStack.add(a.child2)}return this.failed.clear(),o}rayCast(t,n,s){this.openlist==null&&(this.openlist=new ze._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let i=t.maxdist;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb)){let o=t.aabbsect(this.dtree.root.aabb);if(o>=0&&o<i){this.dtree.root.rayt=o;let a=null,r=this.openlist.head;for(;r!=null;){let x=r.elt;if(this.dtree.root.rayt<x.rayt)break;a=r,r=r.next}let p=this.openlist,c=this.dtree.root,h;ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new ze._zpp.util.ZNPNode_ZPP_AABBNode:(h=ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;a==null?(u.next=p.head,p.head=u):(u.next=a.next,a.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 a=null,r=this.openlist.head;for(;r!=null;){let x=r.elt;if(this.stree.root.rayt<x.rayt)break;a=r,r=r.next}let p=this.openlist,c=this.stree.root,h;ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?h=new ze._zpp.util.ZNPNode_ZPP_AABBNode:(h=ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=h.next,h.next=null),h.elt=c;let u=h;a==null?(u.next=p.head,p.head=u):(u.next=a.next,a.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 a=o.shape,r;if(s!=null){let p=a.filter;r=(p.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&p.collisionGroup)!=0}else r=!0;if(r){let p=a.type==0?t.circlesect(a.circle,n,i):t.aabbtest(a.aabb)?t.polysect(a.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 a=t.aabbsect(o.child1.aabb);if(a>=0&&a<i){o.child1.rayt=a;let r=null,p=this.openlist.head;for(;p!=null;){let y=p.elt;if(o.child1.rayt<y.rayt)break;r=p,p=p.next}let c=this.openlist,h=o.child1,u;ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new ze._zpp.util.ZNPNode_ZPP_AABBNode:(u=ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;r==null?(x.next=c.head,c.head=x):(x.next=r.next,r.next=x),c.pushmod=c.modified=!0,c.length++}}if(o.child2!=null&&t.aabbtest(o.child2.aabb)){let a=t.aabbsect(o.child2.aabb);if(a>=0&&a<i){o.child2.rayt=a;let r=null,p=this.openlist.head;for(;p!=null;){let y=p.elt;if(o.child2.rayt<y.rayt)break;r=p,p=p.next}let c=this.openlist,h=o.child2,u;ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool==null?u=new ze._zpp.util.ZNPNode_ZPP_AABBNode:(u=ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool,ze._zpp.util.ZNPNode_ZPP_AABBNode.zpp_pool=u.next,u.next=null),u.elt=h;let x=u;r==null?(x.next=c.head,c.head=x):(x.next=r.next,r.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 ze._zpp.util.ZNPList_ZPP_AABBNode),this.sync_broadphase(),t.validate_dir();let l=t.maxdist>=1/0,o=i??new ze._nape.geom.RayResultList;if(this.dtree.root!=null&&t.aabbtest(this.dtree.root.aabb))if(l)this.openlist.add(this.dtree.root);else{let a=t.aabbsect(this.dtree.root.aabb);a>=0&&a<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 a=t.aabbsect(this.stree.root.aabb);a>=0&&a<t.maxdist&&this.openlist.add(this.stree.root)}for(;this.openlist.head!=null;){let a=this.openlist.pop_unsafe();if(a.child1==null){let r=a.shape,p;if(s!=null){let c=r.filter;p=(c.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&c.collisionGroup)!=0}else p=!0;p&&(r.type==0?t.circlesect2(r.circle,n,o):t.aabbtest(r.aabb)&&t.polysect2(r.polygon,n,o))}else{if(a.child1!=null&&t.aabbtest(a.child1.aabb))if(l)this.openlist.add(a.child1);else{let r=t.aabbsect(a.child1.aabb);r>=0&&r<t.maxdist&&this.openlist.add(a.child1)}if(a.child2!=null&&t.aabbtest(a.child2.aabb))if(l)this.openlist.add(a.child2);else{let r=t.aabbsect(a.child2.aabb);r>=0&&r<t.maxdist&&this.openlist.add(a.child2)}}}return this.openlist.clear(),o}};ze._zpp=null,ze._nape=null,ze.FATTEN=3,ze.VEL_STEPS=2;var ps=ze;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 a=l;a.elt=null;let r=jn._zpp.util.ZNPNode_ZPP_Arbiter;a.next=r.zpp_pool,r.zpp_pool=a,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 a=jn._zpp.util.ZNPNode_ZPP_Arbiter;o.next=a.zpp_pool,a.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 a=t.get(e);this.cbsets.insert(a),a.manager=this,l=a}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 a=o.elt;if(a.a==e&&a.b==t||a.a==t&&a.b==e){i=a;break}o=o.next}if(i==null){let a;s.zpp_pool==null?a=new s:(a=s.zpp_pool,s.zpp_pool=a.next,a.next=null),a.zip_listeners=!0,n.setlt(e,t)?(a.a=e,a.b=t):(a.a=t,a.b=e),i=a,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=null;this.gravityy=null;this.wrap_gravity=null;this.bodies=null;this.wrap_bodies=null;this.compounds=null;this.wrap_compounds=null;this.constraints=null;this.wrap_constraints=null;this.kinematics=null;this.bphase=null;this.__static=null;this.global_lin_drag=null;this.global_ang_drag=null;this.stamp=null;this.midstep=null;this.time=null;this.sortcontacts=null;this.c_arbiters_true=null;this.c_arbiters_false=null;this.f_arbiters=null;this.s_arbiters=null;this.wrap_arbiters=null;this.live=null;this.wrap_live=null;this.live_constraints=null;this.wrap_livecon=null;this.staticsleep=null;this.islands=null;this.listeners=null;this.wrap_listeners=null;this.callbacks=null;this.callbackset_list=null;this.cbsets=null;this.convexShapeList=null;this.pre_dt=null;this.toiEvents=null;this.continuous=null;this.precb=null;this.prelisteners=null;this.mrca1=null;this.mrca2=null;this.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;le.zpp_pool==null?s=new le:(s=le.zpp_pool,le.zpp_pool=s.next,s.next=null),s.weak=!1,s._immutable=!1,s.x=e,s.y=t,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 r=l.elt;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)),l=l.next}let o=i.compounds.head;for(;o!=null;){let a=o.elt;t.add(a),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 a=t.b2.arbiters,r=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;r==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=r.next,u=h.next,r.next=u,u==null&&(a.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,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}r=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=we.zpp_pool,we.zpp_pool=l;let o=t.innards,a=o.next;o.next=a.next,a._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 a=t.b2.arbiters,r=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;r==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=r.next,u=h.next,r.next=u,u==null&&(a.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,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}r=p,p=p.next}t.pair!=null&&(t.pair.arb=null,t.pair=null)}for(t.b1=t.b2=null,t.active=!1,t.intchange=!1;t.contacts.next!=null;){let s=t.contacts,i=s.next;s.pop();let l=i;l.arbiter=null,l.next=we.zpp_pool,we.zpp_pool=l;let o=t.innards,a=o.next;o.next=a.next,a._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 a=t.b2.arbiters,r=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;r==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=r.next,u=h.next,r.next=u,u==null&&(a.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,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}r=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 a=t.b2.arbiters,r=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==t){let h,u;r==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=r.next,u=h.next,r.next=u,u==null&&(a.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,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}r=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 r=o.comps.pop_unsafe();r.sleeping=!1,r.island=null,r.parent=r,r.rank=0}let a=o;a.next=xt.zpp_pool,xt.zpp_pool=a}}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 r=o.comps.pop_unsafe();r.sleeping=!1,r.island=null,r.parent=r,r.rank=0}let a=o;a.next=xt.zpp_pool,xt.zpp_pool=a}}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 a=this.callbackset_list;e._inuse=!0;let r=e;r.next=a.next,a.next=r,a.modified=!0,a.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,a=l.head,r=!1;for(;a!=null;){if(a.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,r=!0;break}o=a,a=a.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 a=this.mrca1.head;for(;a!=null;){let r=a.elt,p=this.mrca2.head;for(;p!=null;){let c=p.elt,h=r.cbSet,u=c.cbSet;h.validate(),u.validate();let x=h.manager,y=null,d=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;d!=null;){let C=d.elt;if(C.a==h&&C.b==u||C.a==u&&C.b==h){y=C;break}d=d.next}if(y==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(h,u)?(C.a=h,C.b=u):(C.a=u,C.b=h),y=C,h.cbpairs.add(y),u!=h&&u.cbpairs.add(y)}if(y.zip_listeners&&(y.zip_listeners=!1,y.__validate()),y.listeners.head==null){p=p.next;continue}let f=I._zpp.phys.ZPP_Interactor.get(r,c);f.remove_arb(l),l.present--;let z=h.manager,P=null,m=(h.cbpairs.length<u.cbpairs.length?h.cbpairs:u.cbpairs).head;for(;m!=null;){let C=m.elt;if(C.a==h&&C.b==u||C.a==u&&C.b==h){P=C;break}m=m.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(h,u)?(C.a=h,C.b=u):(C.a=u,C.b=h),P=C,h.cbpairs.add(P),u!=h&&u.cbpairs.add(P)}P.zip_listeners&&(P.zip_listeners=!1,P.__validate());let b=P.listeners.head;for(;b!=null;){let C=b.elt;if(C.event==1&&(C.itype&l.type)!=0&&f.empty_arb(C.itype)){let v=this.push_callback(C);v.event=1;let w=f.int1,O=f.int2,k,g=C.options1,E=w.cbTypes;if(g.nonemptyintersection(E,g.includes)&&!g.nonemptyintersection(E,g.excludes)){let M=C.options2,N=O.cbTypes;k=M.nonemptyintersection(N,M.includes)&&!M.nonemptyintersection(N,M.excludes)}else k=!1;k?(v.int1=w,v.int2=O):(v.int1=O,v.int2=w),v.set=f}b=b.next}f.arbiters.head==null&&this.remove_callbackset(f),p=p.next}a=a.next}}if(l.b1!=n&&l.b1.type==2){let a=l.b1;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(l.b2!=n&&l.b2.type==2){let a=l.b2;a.world||(a.component.waket=this.stamp+(this.midstep?0:1),a.type==3&&(a.kinematicDelaySleep=!0),a.component.sleeping&&this.really_wake(a,!1))}if(l.cleared=!0,n==null||l.b2==n){let a=l.b1.arbiters,r=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;r==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=r.next,u=h.next,r.next=u,u==null&&(a.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,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}r=p,p=p.next}}if(n==null||l.b1==n){let a=l.b2.arbiters,r=null,p=a.head,c=!1;for(;p!=null;){if(p.elt==l){let h,u;r==null?(h=a.head,u=h.next,a.head=u,a.head==null&&(a.pushmod=!0)):(h=r.next,u=h.next,r.next=u,u==null&&(a.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,a.modified=!0,a.length--,a.pushmod=!0,c=!0;break}r=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 a=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;return r._validate!=null&&r._validate(),l.shapesInCircle(a,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 a=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;return r._validate!=null&&r._validate(),l.bodiesInCircle(a,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 S=e.circle;if(S.zip_worldCOM&&S.body!=null){if(S.zip_worldCOM=!1,S.zip_localCOM){if(S.zip_localCOM=!1,S.type==1){let j=S.polygon;if(j.lverts.next==null)throw new Error("Error: An empty polygon has no meaningful localCOM");if(j.lverts.next.next==null)j.localCOMx=j.lverts.next.x,j.localCOMy=j.lverts.next.y;else if(j.lverts.next.next.next==null){j.localCOMx=j.lverts.next.x,j.localCOMy=j.lverts.next.y;let R=1;j.localCOMx+=j.lverts.next.next.x*R,j.localCOMy+=j.lverts.next.next.y*R;let q=.5;j.localCOMx*=q,j.localCOMy*=q}else{j.localCOMx=0,j.localCOMy=0;let R=0,q=j.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;j.localCOMx+=(B.x+ee.x)*W,j.localCOMy+=(B.y+ee.y)*W,G=B,B=ee,q=q.next}q=j.lverts.next;let V=q;R+=B.x*(V.y-G.y);let Y=V.y*B.x-V.x*B.y;j.localCOMx+=(B.x+V.x)*Y,j.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;j.localCOMx+=(B.x+$.x)*X,j.localCOMy+=(B.y+$.y)*X,R=1/(3*R);let H=R;j.localCOMx*=H,j.localCOMy*=H}}S.wrap_localCOM!=null&&(S.wrap_localCOM.zpp_inner.x=S.localCOMx,S.wrap_localCOM.zpp_inner.y=S.localCOMy)}let D=S.body;D.zip_axis&&(D.zip_axis=!1,D.axisx=Math.sin(D.rot),D.axisy=Math.cos(D.rot)),S.worldCOMx=S.body.posx+(S.body.axisy*S.localCOMx-S.body.axisx*S.localCOMy),S.worldCOMy=S.body.posy+(S.localCOMx*S.body.axisx+S.localCOMy*S.body.axisy)}}else if(e.type===2){let S=e.capsule;if(S.zip_worldCOM&&S.body!=null){S.zip_worldCOM=!1,S.zip_localCOM&&(S.zip_localCOM=!1,S.wrap_localCOM!=null&&(S.wrap_localCOM.zpp_inner.x=S.localCOMx,S.wrap_localCOM.zpp_inner.y=S.localCOMy));let D=S.body;D.zip_axis&&(D.zip_axis=!1,D.axisx=Math.sin(D.rot),D.axisy=Math.cos(D.rot)),S.worldCOMx=S.body.posx+(S.body.axisy*S.localCOMx-S.body.axisx*S.localCOMy),S.worldCOMy=S.body.posy+(S.localCOMx*S.body.axisx+S.localCOMy*S.body.axisy)}}else{let S=e.polygon;if(S.zip_gaxi&&S.body!=null){S.zip_gaxi=!1,S.validate_laxi();let D=S.body;if(D.zip_axis&&(D.zip_axis=!1,D.axisx=Math.sin(D.rot),D.axisy=Math.cos(D.rot)),S.zip_gverts&&S.body!=null){S.zip_gverts=!1,S.validate_lverts();let V=S.body;V.zip_axis&&(V.zip_axis=!1,V.axisx=Math.sin(V.rot),V.axisy=Math.cos(V.rot));let Y=S.lverts.next,$=S.gverts.next;for(;$!=null;){let X=$,H=Y;Y=Y.next,X.x=S.body.posx+(S.body.axisy*H.x-S.body.axisx*H.y),X.y=S.body.posy+(H.x*S.body.axisx+H.y*S.body.axisy),$=$.next}}let j=S.edges.head,R=S.gverts.next,q=R;for(R=R.next;R!=null;){let V=R,Y=j.elt;j=j.next,Y.gp0=q,Y.gp1=V,Y.gnormx=S.body.axisy*Y.lnormx-S.body.axisx*Y.lnormy,Y.gnormy=Y.lnormx*S.body.axisx+Y.lnormy*S.body.axisy,Y.gprojection=S.body.posx*Y.gnormx+S.body.posy*Y.gnormy+Y.lprojection,Y.wrap_gnorm!=null&&(Y.wrap_gnorm.zpp_inner.x=Y.gnormx,Y.wrap_gnorm.zpp_inner.y=Y.gnormy),Y.tp0=Y.gp0.y*Y.gnormx-Y.gp0.x*Y.gnormy,Y.tp1=Y.gp1.y*Y.gnormx-Y.gp1.x*Y.gnormy,q=V,R=R.next}let G=S.gverts.next,B=j.elt;j=j.next,B.gp0=q,B.gp1=G,B.gnormx=S.body.axisy*B.lnormx-S.body.axisx*B.lnormy,B.gnormy=B.lnormx*S.body.axisx+B.lnormy*S.body.axisy,B.gprojection=S.body.posx*B.gnormx+S.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,a=l.posy;l.sweepTime=0,l.sweep_angvel=l.angvel;let r=t-l.sweepTime;if(r!=0){l.sweepTime=t;let S=r;if(l.posx+=l.velx*S,l.posy+=l.vely*S,l.angvel!=0){let D=l.sweep_angvel*r;if(l.rot+=D,D*D>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let j=D*D,R=1-.5*j,q=1-j*j/8,G=(R*l.axisx+D*l.axisy)*q;l.axisy=(R*l.axisy-D*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,y=p;u.minx=(x<y?x:y)-h;let _=o,d=p;u.maxx=(_>d?_:d)+h;let f=a,z=c;u.miny=(f<z?f:z)-h;let P=a,Z=c;u.maxy=(P>Z?P:Z)+h;let m=this.convexShapeList=this.bphase.shapesInAABB(u,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),b=u;b.outer!=null&&(b.outer.zpp_inner=null,b.outer=null),b.wrap_min=b.wrap_max=null,b._invalidate=null,b._validate=null,b.next=fe.zpp_pool,fe.zpp_pool=b;let C=0,v=0;C=0,v=0;let w=0,O=0;w=0,O=0;let k=null,g=t+1;m.zpp_inner.valmod();let E=I._nape.shape.ShapeIterator.get(m);for(;;){E.zpp_inner.zpp_inner.valmod();let S=E.zpp_inner;S.zpp_inner.valmod(),S.zpp_inner.zip_length&&(S.zpp_inner.zip_length=!1,S.zpp_inner.user_length=S.zpp_inner.inner.length);let D=S.zpp_inner.user_length;E.zpp_critical=!0;let j;if(E.zpp_i<D?j=!0:(E.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=E,E.zpp_inner=null,j=!1),!j)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 L=Y.gverts.next,F=H.elt;H=H.next,F.gnormx=B.axisy*F.lnormx-B.axisx*F.lnormy,F.gnormy=F.lnormx*B.axisx+F.lnormy*B.axisy,F.gprojection=B.posx*F.gnormx+B.posy*F.gnormy+F.lprojection,F.tp0=W.y*F.gnormx-W.x*F.gnormy,F.tp1=L.y*F.gnormx-L.x*F.gnormy}}else gn.staticSweep(i,t,0,0);i.toi*=t,i.toi>0&&i.toi<g&&(g=i.toi,C=i.axis.x,v=i.axis.y,w=i.c2.x,O=i.c2.y,k=R)}}m.clear();let M=i;M.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=M;let N=0-l.sweepTime;if(N!=0){l.sweepTime=0;let S=N;if(l.posx+=l.velx*S,l.posy+=l.vely*S,l.angvel!=0){let D=l.sweep_angvel*N;if(l.rot+=D,D*D>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let j=D*D,R=1-.5*j,q=1-j*j/8,G=(R*l.axisx+D*l.axisy)*q;l.axisy=(R*l.axisy-D*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 S=e.polygon,D=S.lverts.next,j=S.gverts.next;for(;j!=null;){let Y=j,$=D;D=D.next,Y.x=l.posx+(l.axisy*$.x-l.axisx*$.y),Y.y=l.posy+($.x*l.axisx+$.y*l.axisy),j=j.next}let R=S.edges.head,q=S.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=S.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(g<=t){let S=-C,D=-v;if(D==null&&(D=0),S==null&&(S=0),S!=S||D!=D)throw new Error("Error: Vec2 components cannot be NaN");let j;if(I._zpp.util.ZPP_PubPool.poolVec2==null?j=new I._nape.geom.Vec2:(j=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=j.zpp_pool,j.zpp_pool=null,j.zpp_disp=!1,j==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),j.zpp_inner==null){let B;le.zpp_pool==null?B=new le:(B=le.zpp_pool,le.zpp_pool=B.next,B.next=null),B.weak=!1,B._immutable=!1,B.x=S,B.y=D,j.zpp_inner=B,j.zpp_inner.outer=j}else{if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let B=j.zpp_inner;if(B._immutable)throw new Error("Error: Vec2 is immutable");if(B._isimmutable!=null&&B._isimmutable(),S!=S||D!=D)throw new Error("Error: Vec2 components cannot be NaN");let V;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let Y=j.zpp_inner;if(Y._validate!=null&&Y._validate(),j.zpp_inner.x==S){if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let $=j.zpp_inner;$._validate!=null&&$._validate(),V=j.zpp_inner.y==D}else V=!1;if(!V){j.zpp_inner.x=S,j.zpp_inner.y=D;let $=j.zpp_inner;$._invalidate!=null&&$._invalidate($)}}j.zpp_inner.weak=!1;let R=w,q=O;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;le.zpp_pool==null?B=new le:(B=le.zpp_pool,le.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(j,G,g,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 a=l;for(l=l.next;l!=null;){let x=l;i+=a.x*(x.y-o.y);let y=x.y*a.x-x.x*a.y;s.localCOMx+=(a.x+x.x)*y,s.localCOMy+=(a.y+x.y)*y,o=a,a=x,l=l.next}l=s.lverts.next;let r=l;i+=a.x*(r.y-o.y);let p=r.y*a.x-r.x*a.y;s.localCOMx+=(a.x+r.x)*p,s.localCOMy+=(a.y+r.y)*p,o=a,a=r,l=l.next;let c=l;i+=a.x*(c.y-o.y);let h=c.y*a.x-c.x*a.y;s.localCOMx+=(a.x+c.x)*h,s.localCOMy+=(a.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 r=t.body;r.zip_axis&&(r.zip_axis=!1,r.axisx=Math.sin(r.rot),r.axisy=Math.cos(r.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 r=i,p=s.elt;s=s.next,p.gp0=l,p.gp1=r,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=r,i=i.next}let o=t.gverts.next,a=s.elt;s=s.next,a.gp0=l,a.gp1=o,a.gnormx=t.body.axisy*a.lnormx-t.body.axisx*a.lnormy,a.gnormy=a.lnormx*t.body.axisx+a.lnormy*t.body.axisy,a.gprojection=t.body.posx*a.gnormx+t.body.posy*a.gnormy+a.lprojection,a.wrap_gnorm!=null&&(a.wrap_gnorm.zpp_inner.x=a.gnormx,a.wrap_gnorm.zpp_inner.y=a.gnormy),a.tp0=a.gp0.y*a.gnormx-a.gp0.x*a.gnormy,a.tp1=a.gp1.y*a.gnormx-a.gp1.x*a.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 g=e.circle;if(g.zip_worldCOM&&g.body!=null){if(g.zip_worldCOM=!1,g.zip_localCOM){if(g.zip_localCOM=!1,g.type==1){let M=g.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 N=1;M.localCOMx+=M.lverts.next.next.x*N,M.localCOMy+=M.lverts.next.next.y*N;let S=.5;M.localCOMx*=S,M.localCOMy*=S}else{M.localCOMx=0,M.localCOMy=0;let N=0,S=M.lverts.next,D=S;S=S.next;let j=S;for(S=S.next;S!=null;){let Y=S;N+=j.x*(Y.y-D.y);let $=Y.y*j.x-Y.x*j.y;M.localCOMx+=(j.x+Y.x)*$,M.localCOMy+=(j.y+Y.y)*$,D=j,j=Y,S=S.next}S=M.lverts.next;let R=S;N+=j.x*(R.y-D.y);let q=R.y*j.x-R.x*j.y;M.localCOMx+=(j.x+R.x)*q,M.localCOMy+=(j.y+R.y)*q,D=j,j=R,S=S.next;let G=S;N+=j.x*(G.y-D.y);let B=G.y*j.x-G.x*j.y;M.localCOMx+=(j.x+G.x)*B,M.localCOMy+=(j.y+G.y)*B,N=1/(3*N);let V=N;M.localCOMx*=V,M.localCOMy*=V}}g.wrap_localCOM!=null&&(g.wrap_localCOM.zpp_inner.x=g.localCOMx,g.wrap_localCOM.zpp_inner.y=g.localCOMy)}let E=g.body;E.zip_axis&&(E.zip_axis=!1,E.axisx=Math.sin(E.rot),E.axisy=Math.cos(E.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)}}else if(e.type===2){let g=e.capsule;if(g.zip_worldCOM&&g.body!=null){g.zip_worldCOM=!1,g.zip_localCOM&&(g.zip_localCOM=!1,g.wrap_localCOM!=null&&(g.wrap_localCOM.zpp_inner.x=g.localCOMx,g.wrap_localCOM.zpp_inner.y=g.localCOMy));let E=g.body;E.zip_axis&&(E.zip_axis=!1,E.axisx=Math.sin(E.rot),E.axisy=Math.cos(E.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)}}else{let g=e.polygon;if(g.zip_gaxi&&g.body!=null){g.zip_gaxi=!1,g.validate_laxi();let E=g.body;if(E.zip_axis&&(E.zip_axis=!1,E.axisx=Math.sin(E.rot),E.axisy=Math.cos(E.rot)),g.zip_gverts&&g.body!=null){g.zip_gverts=!1,g.validate_lverts();let R=g.body;R.zip_axis&&(R.zip_axis=!1,R.axisx=Math.sin(R.rot),R.axisy=Math.cos(R.rot));let q=g.lverts.next,G=g.gverts.next;for(;G!=null;){let B=G,V=q;q=q.next,B.x=g.body.posx+(g.body.axisy*V.x-g.body.axisx*V.y),B.y=g.body.posy+(V.x*g.body.axisx+V.y*g.body.axisy),G=G.next}}let M=g.edges.head,N=g.gverts.next,S=N;for(N=N.next;N!=null;){let R=N,q=M.elt;M=M.next,q.gp0=S,q.gp1=R,q.gnormx=g.body.axisy*q.lnormx-g.body.axisx*q.lnormy,q.gnormy=q.lnormx*g.body.axisx+q.lnormy*g.body.axisy,q.gprojection=g.body.posx*q.gnormx+g.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,S=R,N=N.next}let D=g.gverts.next,j=M.elt;M=M.next,j.gp0=S,j.gp1=D,j.gnormx=g.body.axisy*j.lnormx-g.body.axisx*j.lnormy,j.gnormy=j.lnormx*g.body.axisx+j.lnormy*g.body.axisy,j.gprojection=g.body.posx*j.gnormx+g.body.posy*j.gnormy+j.lprojection,j.wrap_gnorm!=null&&(j.wrap_gnorm.zpp_inner.x=j.gnormx,j.wrap_gnorm.zpp_inner.y=j.gnormy),j.tp0=j.gp0.y*j.gnormx-j.gp0.x*j.gnormy,j.tp1=j.gp1.y*j.gnormx-j.gp1.x*j.gnormy}}let o=e.body,a=o.posx,r=o.posy;o.sweepTime=0,o.sweep_angvel=o.angvel;let p=t-o.sweepTime;if(p!=0){o.sweepTime=t;let g=p;if(o.posx+=o.velx*g,o.posy+=o.vely*g,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,N=1-.5*M,S=1-M*M/8,D=(N*o.axisx+E*o.axisy)*S;o.axisy=(N*o.axisy-E*o.axisx)*S,o.axisx=D}}}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 y=a,_=c;x.minx=(y<_?y:_)-u;let d=a,f=c;x.maxx=(d>f?d:f)+u;let z=r,P=h;x.miny=(z<P?z:P)-u;let Z=r,m=h;x.maxy=(Z>m?Z:m)+u;let b=this.convexShapeList=this.bphase.shapesInAABB(x,!1,!1,n==null?null:n.zpp_inner,this.convexShapeList),C=x;C.outer!=null&&(C.outer.zpp_inner=null,C.outer=null),C.wrap_min=C.wrap_max=null,C._invalidate=null,C._validate=null,C.next=fe.zpp_pool,fe.zpp_pool=C;let v=i??new I._nape.geom.ConvexResultList;b.zpp_inner.valmod();let w=I._nape.shape.ShapeIterator.get(b);for(;;){w.zpp_inner.zpp_inner.valmod();let g=w.zpp_inner;g.zpp_inner.valmod(),g.zpp_inner.zip_length&&(g.zpp_inner.zip_length=!1,g.zpp_inner.user_length=g.zpp_inner.inner.length);let E=g.zpp_inner.user_length;w.zpp_critical=!0;let M;if(w.zpp_i<E?M=!0:(w.zpp_next=I._nape.shape.ShapeIterator.zpp_pool,I._nape.shape.ShapeIterator.zpp_pool=w,w.zpp_inner=null,M=!1),!M)break;w.zpp_critical=!1;let N=w.zpp_inner.at(w.zpp_i++);if(N!=e.outer&&(N.zpp_inner.body!=null?N.zpp_inner.body.outer:null)!=o.outer){if(l.s1=e,l.s2=N.zpp_inner,s){N.zpp_inner.validate_sweepRadius(),(N.zpp_inner.body!=null?N.zpp_inner.body.outer:null).zpp_inner.sweep_angvel=(N.zpp_inner.body!=null?N.zpp_inner.body.outer:null).zpp_inner.angvel,(N.zpp_inner.body!=null?N.zpp_inner.body.outer:null).zpp_inner.sweepTime=0,gn.dynamicSweep(l,t,0,0,!0);let S=(N.zpp_inner.body!=null?N.zpp_inner.body.outer:null).zpp_inner,D=0-S.sweepTime;if(D!=0){S.sweepTime=0;let q=D;if(S.posx+=S.velx*q,S.posy+=S.vely*q,S.angvel!=0){let G=S.sweep_angvel*D;if(S.rot+=G,G*G>1e-4)S.axisx=Math.sin(S.rot),S.axisy=Math.cos(S.rot);else{let B=G*G,V=1-.5*B,Y=1-B*B/8,$=(V*S.axisx+G*S.axisy)*Y;S.axisy=(V*S.axisy-G*S.axisx)*Y,S.axisx=$}}}let j=(N.zpp_inner.body!=null?N.zpp_inner.body.outer:null).zpp_inner,R=N.zpp_inner;if(R.type==0||R.type===2)R.worldCOMx=j.posx+(j.axisy*R.localCOMx-j.axisx*R.localCOMy),R.worldCOMy=j.posy+(R.localCOMx*j.axisx+R.localCOMy*j.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=j.posx+(j.axisy*W.x-j.axisx*W.y),ee.y=j.posy+(W.x*j.axisx+W.y*j.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=j.axisy*W.lnormx-j.axisx*W.lnormy,W.gnormy=W.lnormx*j.axisx+W.lnormy*j.axisy,W.gprojection=j.posx*W.gnormx+j.posy*W.gnormy+W.lprojection,W.tp0=$.y*W.gnormx-$.x*W.gnormy,W.tp1=ee.y*W.gnormx-ee.x*W.gnormy,$=ee,Y=Y.next}let X=q.gverts.next,H=V.elt;V=V.next,H.gnormx=j.axisy*H.lnormx-j.axisx*H.lnormy,H.gnormy=H.lnormx*j.axisx+H.lnormy*j.axisy,H.gprojection=j.posx*H.gnormx+j.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 S=-l.axis.x,D=-l.axis.y;if(D==null&&(D=0),S==null&&(S=0),S!=S||D!=D)throw new Error("Error: Vec2 components cannot be NaN");let j;if(I._zpp.util.ZPP_PubPool.poolVec2==null?j=new I._nape.geom.Vec2:(j=I._zpp.util.ZPP_PubPool.poolVec2,I._zpp.util.ZPP_PubPool.poolVec2=j.zpp_pool,j.zpp_pool=null,j.zpp_disp=!1,j==I._zpp.util.ZPP_PubPool.nextVec2&&(I._zpp.util.ZPP_PubPool.nextVec2=null)),j.zpp_inner==null){let ee;le.zpp_pool==null?ee=new le:(ee=le.zpp_pool,le.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=S,ee.y=D,j.zpp_inner=ee,j.zpp_inner.outer=j}else{if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let ee=j.zpp_inner;if(ee._immutable)throw new Error("Error: Vec2 is immutable");if(ee._isimmutable!=null&&ee._isimmutable(),S!=S||D!=D)throw new Error("Error: Vec2 components cannot be NaN");let W;if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let L=j.zpp_inner;if(L._validate!=null&&L._validate(),j.zpp_inner.x==S){if(j!=null&&j.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let F=j.zpp_inner;F._validate!=null&&F._validate(),W=j.zpp_inner.y==D}else W=!1;if(!W){j.zpp_inner.x=S,j.zpp_inner.y=D;let F=j.zpp_inner;F._invalidate!=null&&F._invalidate(F)}}j.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;le.zpp_pool==null?ee=new le:(ee=le.zpp_pool,le.zpp_pool=ee.next,ee.next=null),ee.weak=!1,ee._immutable=!1,ee.x=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 L=G.zpp_inner;if(L._validate!=null&&L._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 F=G.zpp_inner;F._validate!=null&&F._validate(),W=G.zpp_inner.y==q}else W=!1;if(!W){G.zpp_inner.x=R,G.zpp_inner.y=q;let F=G.zpp_inner;F._invalidate!=null&&F._invalidate(F)}}G.zpp_inner.weak=!1;let B=I._zpp.geom.ZPP_ConvexRayResult.getConvex(j,G,l.toi,N),V=null,Y=v.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 $=v.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 O=l;O.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=O;let k=0-o.sweepTime;if(k!=0){o.sweepTime=0;let g=k;if(o.posx+=o.velx*g,o.posy+=o.vely*g,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,N=1-.5*M,S=1-M*M/8,D=(N*o.axisx+E*o.axisy)*S;o.axisy=(N*o.axisy-E*o.axisx)*S,o.axisx=D}}}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 g=e.polygon,E=g.lverts.next,M=g.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 N=g.edges.head,S=g.gverts.next,D=S;for(S=S.next;S!=null;){let q=S,G=N.elt;N=N.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=D.y*G.gnormx-D.x*G.gnormy,G.tp1=q.y*G.gnormx-q.x*G.gnormy,D=q,S=S.next}let j=g.gverts.next,R=N.elt;N=N.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=D.y*R.gnormx-D.x*R.gnormy,R.tp1=j.y*R.gnormx-j.x*R.gnormy}return v}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}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 h=this.c_arbiters_false;if(h.head!=null&&h.head.next!=null){let u=h.head,x=null,y=null,_=null,d=null,f=1,z,P,Z;for(;;){for(z=0,y=u,u=null,x=u;y!=null;){for(++z,_=y,P=0,Z=f;_!=null&&P<f;)++P,_=_.next;for(;P>0||Z>0&&_!=null;)P==0?(d=_,_=_.next,--Z):Z==0||_==null||!(y.elt.active&&_.elt.active)||y.elt.oc1.dist<_.elt.oc1.dist?(d=y,y=y.next,--P):(d=_,_=_.next,--Z),x!=null?x.next=d:u=d,x=d;y=_}if(x.next=null,f<<=1,!(z>1))break}h.head=u,h.modified=!0,h.pushmod=!0}}this.updateVel(e),this.warmStart(),this.iterateVel(t);let l=this.kinematics.head;for(;l!=null;){let h=l.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,l=l.next}let o=this.live.head;for(;o!=null;){let h=o.elt;h.pre_posx=h.posx,h.pre_posy=h.posy,h.pre_rot=h.rot,o=o.next}this.updatePos(e),this.continuous=!0,this.continuousCollisions(e),this.continuous=!1,this.iteratePos(n);let a=this.kinematics.head;for(;a!=null;){let h=a.elt,u=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),x=h.pre_rot!=h.rot;if(u){let y=h.shapes.head;for(;y!=null;){let _=y.elt;_.type==1&&(_.polygon.invalidate_gverts(),_.polygon.invalidate_gaxi()),_.invalidate_worldCOM(),y=y.next}h.zip_worldCOM=!0}if(x){h.zip_axis=!0;let y=h.shapes.head;for(;y!=null;){let _=y.elt;_.type==1&&(_.polygon.invalidate_gverts(),_.polygon.invalidate_gaxi()),_.invalidate_worldCOM(),y=y.next}h.zip_worldCOM=!0}a=a.next}let r=this.live.head;for(;r!=null;){let h=r.elt,u=!(h.posx==h.pre_posx&&h.posy==h.pre_posy),x=h.pre_rot!=h.rot;if(u){let y=h.shapes.head;for(;y!=null;){let _=y.elt;_.type==1&&(_.polygon.invalidate_gverts(),_.polygon.invalidate_gaxi()),_.invalidate_worldCOM(),y=y.next}h.zip_worldCOM=!0}if(x){h.zip_axis=!0;let y=h.shapes.head;for(;y!=null;){let _=y.elt;_.type==1&&(_.polygon.invalidate_gverts(),_.polygon.invalidate_gaxi()),_.invalidate_worldCOM(),y=y.next}h.zip_worldCOM=!0}r=r.next}let p=null,c=this.staticsleep.head;for(;c!=null;){let h=c.elt;if(h.type!=3||h.velx==0&&h.vely==0&&h.angvel==0){if(h.kinematicDelaySleep){h.kinematicDelaySleep=!1,c=c.next;continue}h.component.sleeping=!0;let u=this.staticsleep,x,y;p==null?(x=u.head,y=x.next,u.head=y,u.head==null&&(u.pushmod=!0)):(x=p.next,y=x.next,p.next=y,y==null&&(u.pushmod=!0));let _=x;_.elt=null,_.next=I._zpp.util.ZNPNode_ZPP_Body.zpp_pool,I._zpp.util.ZNPNode_ZPP_Body.zpp_pool=_,u.modified=!0,u.length--,u.pushmod=!0,c=y;continue}p=c,c=c.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 d=this.callbackset_list,f,z;s==null?(f=d.next,z=f.next,d.next=z,d.next==null&&(d.pushmod=!0)):(f=s.next,z=f.next,s.next=z,z==null&&(d.pushmod=!0)),f._inuse=!1,d.modified=!0,d.length--,d.pushmod=!0,i=z;let P=l;P.int1=P.int2=null,P.id=P.di=-1,P.freed=!0,P.next=Kt.zpp_pool,Kt.zpp_pool=P;continue}let o;o=!0;let a=l.arbiters.head;for(;a!=null;)if(a.elt.sleeping){a=a.next;continue}else{o=!1;break}let r=o,p=l.int1.cbSet,c=l.int2.cbSet,h=p.manager,u=null,y=(p.cbpairs.length<c.cbpairs.length?p.cbpairs:c.cbpairs).head;for(;y!=null;){let d=y.elt;if(d.a==p&&d.b==c||d.a==c&&d.b==p){u=d;break}y=y.next}if(u==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(p,c)?(d.a=p,d.b=c):(d.a=c,d.b=p),u=d,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 d=_.elt;if(d.event==6&&(!r||d.allowSleepingCallbacks)&&!l.empty_arb(d.itype)){let f=this.push_callback(d);f.event=6;let z=l.int1,P=l.int2,Z,m=d.options1,b=z.cbTypes;if(m.nonemptyintersection(b,m.includes)&&!m.nonemptyintersection(b,m.excludes)){let C=d.options2,v=P.cbTypes;Z=C.nonemptyintersection(v,C.includes)&&!C.nonemptyintersection(v,C.excludes)}else Z=!1;Z?(f.int1=z,f.int2=P):(f.int1=P,f.int2=z),f.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,a=!1,r=null,p=null,c=this.toiEvents.head;for(;c!=null;){let d=c.elt,f=d.s1.body,z=d.s2.body;if(f.sweepFrozen&&z.sweepFrozen)if(d.toi!=0&&Ee.testCollide_safe(d.s1,d.s2))d.toi=0;else{c=this.toiEvents.erase(p);let P=d;P.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}if(d.frozen1!=f.sweepFrozen||d.frozen2!=z.sweepFrozen)if(d.kinematic){c=this.toiEvents.erase(p);let P=d;P.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}else{if(d.frozen1=f.sweepFrozen,d.frozen2=z.sweepFrozen,d.frozen1){let P=d.s1;d.s1=d.s2,d.s2=P,d.frozen1=!1,d.frozen2=!0}if(gn.staticSweep(d,e,0,I._nape.Config.collisionSlopCCD),d.toi<0){c=this.toiEvents.erase(p);let P=d;P.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=P;continue}}d.toi>=0&&(d.toi<o||!a&&d.kinematic)&&(l=d,o=d.toi,a=d.kinematic,r=p),p=c,c=c.next}if(l==null)break;this.toiEvents.erase(r),n=l.toi;let h=l.s1.body,u=l.s2.body;if(!h.sweepFrozen){let d=n*e,f=d-h.sweepTime;if(f!=0){h.sweepTime=d;let P=f;if(h.posx+=h.velx*P,h.posy+=h.vely*P,h.angvel!=0){let Z=h.sweep_angvel*f;if(h.rot+=Z,Z*Z>1e-4)h.axisx=Math.sin(h.rot),h.axisy=Math.cos(h.rot);else{let m=Z*Z,b=1-.5*m,C=1-m*m/8,v=(b*h.axisx+Z*h.axisy)*C;h.axisy=(b*h.axisy-Z*h.axisx)*C,h.axisx=v}}}let z=l.s1;if(z.type==0||z.type===2)z.worldCOMx=h.posx+(h.axisy*z.localCOMx-h.axisx*z.localCOMy),z.worldCOMy=h.posy+(z.localCOMx*h.axisx+z.localCOMy*h.axisy);else{let P=z.polygon,Z=P.lverts.next,m=P.gverts.next;for(;m!=null;){let k=m,g=Z;Z=Z.next,k.x=h.posx+(h.axisy*g.x-h.axisx*g.y),k.y=h.posy+(g.x*h.axisx+g.y*h.axisy),m=m.next}let b=P.edges.head,C=P.gverts.next,v=C;for(C=C.next;C!=null;){let k=C,g=b.elt;b=b.next,g.gnormx=h.axisy*g.lnormx-h.axisx*g.lnormy,g.gnormy=g.lnormx*h.axisx+g.lnormy*h.axisy,g.gprojection=h.posx*g.gnormx+h.posy*g.gnormy+g.lprojection,g.tp0=v.y*g.gnormx-v.x*g.gnormy,g.tp1=k.y*g.gnormx-k.x*g.gnormy,v=k,C=C.next}let w=P.gverts.next,O=b.elt;b=b.next,O.gnormx=h.axisy*O.lnormx-h.axisx*O.lnormy,O.gnormy=O.lnormx*h.axisx+O.lnormy*h.axisy,O.gprojection=h.posx*O.gnormx+h.posy*O.gnormy+O.lprojection,O.tp0=v.y*O.gnormx-v.x*O.gnormy,O.tp1=w.y*O.gnormx-w.x*O.gnormy}}if(!u.sweepFrozen){let d=n*e,f=d-u.sweepTime;if(f!=0){u.sweepTime=d;let P=f;if(u.posx+=u.velx*P,u.posy+=u.vely*P,u.angvel!=0){let Z=u.sweep_angvel*f;if(u.rot+=Z,Z*Z>1e-4)u.axisx=Math.sin(u.rot),u.axisy=Math.cos(u.rot);else{let m=Z*Z,b=1-.5*m,C=1-m*m/8,v=(b*u.axisx+Z*u.axisy)*C;u.axisy=(b*u.axisy-Z*u.axisx)*C,u.axisx=v}}}let z=l.s2;if(z.type==0||z.type===2)z.worldCOMx=u.posx+(u.axisy*z.localCOMx-u.axisx*z.localCOMy),z.worldCOMy=u.posy+(z.localCOMx*u.axisx+z.localCOMy*u.axisy);else{let P=z.polygon,Z=P.lverts.next,m=P.gverts.next;for(;m!=null;){let k=m,g=Z;Z=Z.next,k.x=u.posx+(u.axisy*g.x-u.axisx*g.y),k.y=u.posy+(g.x*u.axisx+g.y*u.axisy),m=m.next}let b=P.edges.head,C=P.gverts.next,v=C;for(C=C.next;C!=null;){let k=C,g=b.elt;b=b.next,g.gnormx=u.axisy*g.lnormx-u.axisx*g.lnormy,g.gnormy=g.lnormx*u.axisx+g.lnormy*u.axisy,g.gprojection=u.posx*g.gnormx+u.posy*g.gnormy+g.lprojection,g.tp0=v.y*g.gnormx-v.x*g.gnormy,g.tp1=k.y*g.gnormx-k.x*g.gnormy,v=k,C=C.next}let w=P.gverts.next,O=b.elt;b=b.next,O.gnormx=u.axisy*O.lnormx-u.axisx*O.lnormy,O.gnormy=O.lnormx*u.axisx+O.lnormy*u.axisy,O.gprojection=u.posx*O.gnormx+u.posy*O.gnormy+O.lprojection,O.tp0=v.y*O.gnormx-v.x*O.gnormy,O.tp1=w.y*O.gnormx-w.x*O.gnormy}}let x=l.arbiter==null,y=this.narrowPhase(l.s1,l.s2,!0,l.arbiter,!0);if(y==null)l.arbiter!=null&&l.arbiter.pair!=null&&(l.arbiter.pair.arb=null,l.arbiter.pair=null);else if(!this.presteparb(y,e,!0)&&y.type==Ie.COL&&y.active&&(y.immState&1)!=0){let d=y.colarb,f=d.nx*d.c1.jnAcc-d.ny*d.c1.jtAcc,z=d.ny*d.c1.jnAcc+d.nx*d.c1.jtAcc,P=d.b1.imass;d.b1.velx-=f*P,d.b1.vely-=z*P,d.b1.angvel-=d.b1.iinertia*(z*d.c1.r1x-f*d.c1.r1y);let Z=d.b2.imass;if(d.b2.velx+=f*Z,d.b2.vely+=z*Z,d.b2.angvel+=d.b2.iinertia*(z*d.c1.r2x-f*d.c1.r2y),d.hc2){let oe=d.nx*d.c2.jnAcc-d.ny*d.c2.jtAcc,he=d.ny*d.c2.jnAcc+d.nx*d.c2.jtAcc,pe=d.b1.imass;d.b1.velx-=oe*pe,d.b1.vely-=he*pe,d.b1.angvel-=d.b1.iinertia*(he*d.c2.r1x-oe*d.c2.r1y);let ce=d.b2.imass;d.b2.velx+=oe*ce,d.b2.vely+=he*ce,d.b2.angvel+=d.b2.iinertia*(he*d.c2.r2x-oe*d.c2.r2y)}d.b2.angvel+=d.jrAcc*d.b2.iinertia,d.b1.angvel-=d.jrAcc*d.b1.iinertia;let m=y.colarb,b=m.k1x+m.b2.velx-m.c1.r2y*m.b2.angvel-(m.b1.velx-m.c1.r1y*m.b1.angvel),C=m.k1y+m.b2.vely+m.c1.r2x*m.b2.angvel-(m.b1.vely+m.c1.r1x*m.b1.angvel),v=(C*m.nx-b*m.ny+m.surfacex)*m.c1.tMass,w=m.c1.friction*m.c1.jnAcc,O=m.c1.jtAcc,k=O-v;k>w?k=w:k<-w&&(k=-w),v=k-O,m.c1.jtAcc=k;let g=-m.ny*v,E=m.nx*v;if(m.b2.velx+=g*m.b2.imass,m.b2.vely+=E*m.b2.imass,m.b1.velx-=g*m.b1.imass,m.b1.vely-=E*m.b1.imass,m.b2.angvel+=m.rt1b*v*m.b2.iinertia,m.b1.angvel-=m.rt1a*v*m.b1.iinertia,m.hc2){let oe=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);v=(he*m.nx-oe*m.ny+m.surfacex)*m.c2.tMass,w=m.c2.friction*m.c2.jnAcc,O=m.c2.jtAcc,k=O-v,k>w?k=w:k<-w&&(k=-w),v=k-O,m.c2.jtAcc=k,g=-m.ny*v,E=m.nx*v,m.b2.velx+=g*m.b2.imass,m.b2.vely+=E*m.b2.imass,m.b1.velx-=g*m.b1.imass,m.b1.vely-=E*m.b1.imass,m.b2.angvel+=m.rt2b*v*m.b2.iinertia,m.b1.angvel-=m.rt2a*v*m.b1.iinertia,b=m.k1x+m.b2.velx-m.c1.r2y*m.b2.angvel-(m.b1.velx-m.c1.r1y*m.b1.angvel),C=m.k1y+m.b2.vely+m.c1.r2x*m.b2.angvel-(m.b1.vely+m.c1.r1x*m.b1.angvel),oe=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 pe=m.c1.jnAcc,ce=m.c2.jnAcc,te=b*m.nx+C*m.ny+m.surfacey+m.c1.bounce-(m.Ka*pe+m.Kb*ce),ue=oe*m.nx+he*m.ny+m.surfacey+m.c2.bounce-(m.Kb*pe+m.Kc*ce),de=-(m.kMassa*te+m.kMassb*ue),me=-(m.kMassb*te+m.kMassc*ue);de>=0&&me>=0?(te=de-pe,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-pe,ue=-ce,m.c1.jnAcc=de,m.c2.jnAcc=0):(me=-m.c2.nMass*ue,me>=0&&m.Kb*me+te>=0?(te=-pe,ue=me-ce,m.c1.jnAcc=0,m.c2.jnAcc=me):te>=0&&ue>=0?(te=-pe,ue=-ce,m.c1.jnAcc=m.c2.jnAcc=0):(te=0,ue=0))),v=te+ue,g=m.nx*v,E=m.ny*v,m.b2.velx+=g*m.b2.imass,m.b2.vely+=E*m.b2.imass,m.b1.velx-=g*m.b1.imass,m.b1.vely-=E*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&&(v=(m.b2.angvel-m.b1.angvel)*m.rMass,w=m.rfric*m.c1.jnAcc,O=m.jrAcc,m.jrAcc-=v,m.jrAcc>w?m.jrAcc=w:m.jrAcc<-w&&(m.jrAcc=-w),v=m.jrAcc-O,m.b2.angvel+=v*m.b2.iinertia,m.b1.angvel-=v*m.b1.iinertia),b=m.k1x+m.b2.velx-m.c1.r2y*m.b2.angvel-(m.b1.velx-m.c1.r1y*m.b1.angvel),C=m.k1y+m.b2.vely+m.c1.r2x*m.b2.angvel-(m.b1.vely+m.c1.r1x*m.b1.angvel),v=(m.c1.bounce+(m.nx*b+m.ny*C)+m.surfacey)*m.c1.nMass,O=m.c1.jnAcc,k=O-v,k<0&&(k=0),v=k-O,m.c1.jnAcc=k,g=m.nx*v,E=m.ny*v,m.b2.velx+=g*m.b2.imass,m.b2.vely+=E*m.b2.imass,m.b1.velx-=g*m.b1.imass,m.b1.vely-=E*m.b1.imass,m.b2.angvel+=m.rn1b*v*m.b2.iinertia,m.b1.angvel-=m.rn1a*v*m.b1.iinertia;let M=y.colarb,N=M.k1x+M.b2.velx-M.c1.r2y*M.b2.angvel-(M.b1.velx-M.c1.r1y*M.b1.angvel),S=M.k1y+M.b2.vely+M.c1.r2x*M.b2.angvel-(M.b1.vely+M.c1.r1x*M.b1.angvel),D=(S*M.nx-N*M.ny+M.surfacex)*M.c1.tMass,j=M.c1.friction*M.c1.jnAcc,R=M.c1.jtAcc,q=R-D;q>j?q=j:q<-j&&(q=-j),D=q-R,M.c1.jtAcc=q;let G=-M.ny*D,B=M.nx*D;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*D*M.b2.iinertia,M.b1.angvel-=M.rt1a*D*M.b1.iinertia,M.hc2){let oe=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);D=(he*M.nx-oe*M.ny+M.surfacex)*M.c2.tMass,j=M.c2.friction*M.c2.jnAcc,R=M.c2.jtAcc,q=R-D,q>j?q=j:q<-j&&(q=-j),D=q-R,M.c2.jtAcc=q,G=-M.ny*D,B=M.nx*D,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*D*M.b2.iinertia,M.b1.angvel-=M.rt2a*D*M.b1.iinertia,N=M.k1x+M.b2.velx-M.c1.r2y*M.b2.angvel-(M.b1.velx-M.c1.r1y*M.b1.angvel),S=M.k1y+M.b2.vely+M.c1.r2x*M.b2.angvel-(M.b1.vely+M.c1.r1x*M.b1.angvel),oe=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 pe=M.c1.jnAcc,ce=M.c2.jnAcc,te=N*M.nx+S*M.ny+M.surfacey+M.c1.bounce-(M.Ka*pe+M.Kb*ce),ue=oe*M.nx+he*M.ny+M.surfacey+M.c2.bounce-(M.Kb*pe+M.Kc*ce),de=-(M.kMassa*te+M.kMassb*ue),me=-(M.kMassb*te+M.kMassc*ue);de>=0&&me>=0?(te=de-pe,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-pe,ue=-ce,M.c1.jnAcc=de,M.c2.jnAcc=0):(me=-M.c2.nMass*ue,me>=0&&M.Kb*me+te>=0?(te=-pe,ue=me-ce,M.c1.jnAcc=0,M.c2.jnAcc=me):te>=0&&ue>=0?(te=-pe,ue=-ce,M.c1.jnAcc=M.c2.jnAcc=0):(te=0,ue=0))),D=te+ue,G=M.nx*D,B=M.ny*D,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&&(D=(M.b2.angvel-M.b1.angvel)*M.rMass,j=M.rfric*M.c1.jnAcc,R=M.jrAcc,M.jrAcc-=D,M.jrAcc>j?M.jrAcc=j:M.jrAcc<-j&&(M.jrAcc=-j),D=M.jrAcc-R,M.b2.angvel+=D*M.b2.iinertia,M.b1.angvel-=D*M.b1.iinertia),N=M.k1x+M.b2.velx-M.c1.r2y*M.b2.angvel-(M.b1.velx-M.c1.r1y*M.b1.angvel),S=M.k1y+M.b2.vely+M.c1.r2x*M.b2.angvel-(M.b1.vely+M.c1.r1x*M.b1.angvel),D=(M.c1.bounce+(M.nx*N+M.ny*S)+M.surfacey)*M.c1.nMass,R=M.c1.jnAcc,q=R-D,q<0&&(q=0),D=q-R,M.c1.jnAcc=q,G=M.nx*D,B=M.ny*D,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*D*M.b2.iinertia,M.b1.angvel-=M.rn1a*D*M.b1.iinertia;let V=y.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 L=-V.ny*X,F=V.nx*X;if(V.b2.velx+=L*V.b2.imass,V.b2.vely+=F*V.b2.imass,V.b1.velx-=L*V.b1.imass,V.b1.vely-=F*V.b1.imass,V.b2.angvel+=V.rt1b*X*V.b2.iinertia,V.b1.angvel-=V.rt1a*X*V.b1.iinertia,V.hc2){let oe=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-oe*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,L=-V.ny*X,F=V.nx*X,V.b2.velx+=L*V.b2.imass,V.b2.vely+=F*V.b2.imass,V.b1.velx-=L*V.b1.imass,V.b1.vely-=F*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),oe=V.k2x+V.b2.velx-V.c2.r2y*V.b2.angvel-(V.b1.velx-V.c2.r1y*V.b1.angvel),he=V.k2y+V.b2.vely+V.c2.r2x*V.b2.angvel-(V.b1.vely+V.c2.r1x*V.b1.angvel);let pe=V.c1.jnAcc,ce=V.c2.jnAcc,te=Y*V.nx+$*V.ny+V.surfacey+V.c1.bounce-(V.Ka*pe+V.Kb*ce),ue=oe*V.nx+he*V.ny+V.surfacey+V.c2.bounce-(V.Kb*pe+V.Kc*ce),de=-(V.kMassa*te+V.kMassb*ue),me=-(V.kMassb*te+V.kMassc*ue);de>=0&&me>=0?(te=de-pe,ue=me-ce,V.c1.jnAcc=de,V.c2.jnAcc=me):(de=-V.c1.nMass*te,de>=0&&V.Kb*de+ue>=0?(te=de-pe,ue=-ce,V.c1.jnAcc=de,V.c2.jnAcc=0):(me=-V.c2.nMass*ue,me>=0&&V.Kb*me+te>=0?(te=-pe,ue=me-ce,V.c1.jnAcc=0,V.c2.jnAcc=me):te>=0&&ue>=0?(te=-pe,ue=-ce,V.c1.jnAcc=V.c2.jnAcc=0):(te=0,ue=0))),X=te+ue,L=V.nx*X,F=V.ny*X,V.b2.velx+=L*V.b2.imass,V.b2.vely+=F*V.b2.imass,V.b1.velx-=L*V.b1.imass,V.b1.vely-=F*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,L=V.nx*X,F=V.ny*X,V.b2.velx+=L*V.b2.imass,V.b2.vely+=F*V.b2.imass,V.b1.velx-=L*V.b1.imass,V.b1.vely-=F*V.b1.imass,V.b2.angvel+=V.rn1b*X*V.b2.iinertia,V.b1.angvel-=V.rn1a*X*V.b1.iinertia;let A=y.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,ne=A.c1.friction*A.c1.jnAcc,re=A.c1.jtAcc,se=re-K;se>ne?se=ne:se<-ne&&(se=-ne),K=se-re,A.c1.jtAcc=se;let ie=-A.ny*K,ae=A.nx*K;if(A.b2.velx+=ie*A.b2.imass,A.b2.vely+=ae*A.b2.imass,A.b1.velx-=ie*A.b1.imass,A.b1.vely-=ae*A.b1.imass,A.b2.angvel+=A.rt1b*K*A.b2.iinertia,A.b1.angvel-=A.rt1a*K*A.b1.iinertia,A.hc2){let oe=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-oe*A.ny+A.surfacex)*A.c2.tMass,ne=A.c2.friction*A.c2.jnAcc,re=A.c2.jtAcc,se=re-K,se>ne?se=ne:se<-ne&&(se=-ne),K=se-re,A.c2.jtAcc=se,ie=-A.ny*K,ae=A.nx*K,A.b2.velx+=ie*A.b2.imass,A.b2.vely+=ae*A.b2.imass,A.b1.velx-=ie*A.b1.imass,A.b1.vely-=ae*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),oe=A.k2x+A.b2.velx-A.c2.r2y*A.b2.angvel-(A.b1.velx-A.c2.r1y*A.b1.angvel),he=A.k2y+A.b2.vely+A.c2.r2x*A.b2.angvel-(A.b1.vely+A.c2.r1x*A.b1.angvel);let pe=A.c1.jnAcc,ce=A.c2.jnAcc,te=J*A.nx+Q*A.ny+A.surfacey+A.c1.bounce-(A.Ka*pe+A.Kb*ce),ue=oe*A.nx+he*A.ny+A.surfacey+A.c2.bounce-(A.Kb*pe+A.Kc*ce),de=-(A.kMassa*te+A.kMassb*ue),me=-(A.kMassb*te+A.kMassc*ue);de>=0&&me>=0?(te=de-pe,ue=me-ce,A.c1.jnAcc=de,A.c2.jnAcc=me):(de=-A.c1.nMass*te,de>=0&&A.Kb*de+ue>=0?(te=de-pe,ue=-ce,A.c1.jnAcc=de,A.c2.jnAcc=0):(me=-A.c2.nMass*ue,me>=0&&A.Kb*me+te>=0?(te=-pe,ue=me-ce,A.c1.jnAcc=0,A.c2.jnAcc=me):te>=0&&ue>=0?(te=-pe,ue=-ce,A.c1.jnAcc=A.c2.jnAcc=0):(te=0,ue=0))),K=te+ue,ie=A.nx*K,ae=A.ny*K,A.b2.velx+=ie*A.b2.imass,A.b2.vely+=ae*A.b2.imass,A.b1.velx-=ie*A.b1.imass,A.b1.vely-=ae*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,ne=A.rfric*A.c1.jnAcc,re=A.jrAcc,A.jrAcc-=K,A.jrAcc>ne?A.jrAcc=ne:A.jrAcc<-ne&&(A.jrAcc=-ne),K=A.jrAcc-re,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,re=A.c1.jnAcc,se=re-K,se<0&&(se=0),K=se-re,A.c1.jnAcc=se,ie=A.nx*K,ae=A.ny*K,A.b2.velx+=ie*A.b2.imass,A.b2.vely+=ae*A.b2.imass,A.b1.velx-=ie*A.b1.imass,A.b1.vely-=ae*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(y!=null&&y.active&&(y.immState&1)!=0&&y.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 d=h;d.sweep_angvel*=I._nape.Config.angularCCDSlipScale,h.angvel=d.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 d=u;d.sweep_angvel*=I._nape.Config.angularCCDSlipScale,u.angvel=d.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 a=o;if(l.posx+=l.velx*a,l.posy+=l.vely*a,l.angvel!=0){let r=l.sweep_angvel*o;if(l.rot+=r,r*r>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=r*r,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+r*l.axisy)*h;l.axisy=(c*l.axisy-r*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 a=o;if(l.posx+=l.velx*a,l.posy+=l.vely*a,l.angvel!=0){let r=l.sweep_angvel*o;if(l.rot+=r,r*r>1e-4)l.axisx=Math.sin(l.rot),l.axisy=Math.cos(l.rot);else{let p=r*r,c=1-.5*p,h=1-p*p/8,u=(c*l.axisx+r*l.axisy)*h;l.axisy=(c*l.axisy-r*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 r=e.body,p=t.body,c;c=!1;let h=r.constraints.head;for(;h!=null;){let y=h.elt;if(y.ignore&&y.pair_exists(r.id,p.id)){c=!0;break}h=h.next}let u,x;if(c)x=!1;else{let y=e;for(;y!=null&&y.group==null;)y.ishape!=null?y=y.ishape.body:y.icompound!=null?y=y.icompound.compound:y=y.ibody.compound;let _=y==null?null:y.group,d;if(_==null)d=!1;else{let f=t;for(;f!=null&&f.group==null;)f.ishape!=null?f=f.ishape.body:f.icompound!=null?f=f.icompound.compound:f=f.ibody.compound;let z=f==null?null:f.group;if(z==null)d=!1;else{let P=!1;for(;_!=null&&z!=null;){if(_==z){P=_.ignore;break}_.depth<z.depth?z=z.group:_=_.group}d=P}}x=!d}if(x){let y;if(e.sensorEnabled||t.sensorEnabled){let _=e.filter,d=t.filter;y=(_.sensorMask&d.sensorGroup)!=0&&(d.sensorMask&_.sensorGroup)!=0}else y=!1;if(y)u=2;else{let _;if(e.fluidEnabled||t.fluidEnabled){let d=e.filter,f=t.filter;_=(d.fluidMask&f.fluidGroup)!=0&&(f.fluidMask&d.fluidGroup)!=0}else _=!1;if(_&&!(r.imass==0&&p.imass==0&&r.iinertia==0&&p.iinertia==0))u=0;else{let d=e.filter,f=t.filter;u=(d.collisionMask&f.collisionGroup)!=0&&(f.collisionMask&d.collisionGroup)!=0&&!(r.imass==0&&p.imass==0&&r.iinertia==0&&p.iinertia==0)?1:-1}}}else u=-1;l=u<=0}if(l)return s;let o=e.body,a=t.body;if(n||o.bullet||a.bullet){let r;I._zpp.geom.ZPP_ToiEvent.zpp_pool==null?r=new I._zpp.geom.ZPP_ToiEvent:(r=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=r.next,r.next=null),r.failed=!1,r.s1=r.s2=null,r.arbiter=null;let p=o.type==3||a.type==3;if(n&&!p)e.body.type!=2?(r.s2=e,r.s1=t):(r.s1=e,r.s2=t),r.kinematic=!1,gn.staticSweep(r,this.pre_dt,0,I._nape.Config.collisionSlopCCD);else if(r.s1=e,r.s2=t,r.kinematic=p,r.s1.body.sweepFrozen||r.s2.body.sweepFrozen){if(r.s1.body.sweepFrozen){let c=r.s1;r.s1=r.s2,r.s2=c,r.frozen1=!1,r.frozen2=!0}gn.staticSweep(r,this.pre_dt,0,I._nape.Config.collisionSlopCCD)}else gn.dynamicSweep(r,this.pre_dt,0,I._nape.Config.collisionSlopCCD,!1);if(n&&r.toi<0||r.failed){let c=r;c.next=I._zpp.geom.ZPP_ToiEvent.zpp_pool,I._zpp.geom.ZPP_ToiEvent.zpp_pool=c}else this.toiEvents.add(r),r.frozen1=r.s1.body.sweepFrozen,r.frozen2=r.s2.body.sweepFrozen,r.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 r=o.elt;n.add(r),o=o.next}let a=l.compounds.head;for(;a!=null;){let r=a.elt;n.add(r),a=a.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,o=i.ishape!=null?i.ishape:null,a=l.arbiters.head;for(;a!=null;){let r=a.elt;if(r.present==0){a=a.next;continue}if(o!=null&&!(r.ws1==o||r.ws2==o)){a=a.next;continue}this.MRCA_chains(r.ws1,r.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 y=x.arbiters.pop_unsafe();y.present--}this.remove_callbackset(x)}h=h.next}p=p.next}a=a.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 a=o.elt,r=this.mrca2.head;for(;r!=null;){let p=r.elt;if(a!=t&&p!=t){r=r.next;continue}let c=I._zpp.phys.ZPP_Interactor.get(a,p);c!=null&&(l.present--,c.remove_arb(l),c.arbiters.head==null&&this.remove_callbackset(c)),r=r.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 r=o.elt;n.add(r),o=o.next}let a=l.compounds.head;for(;a!=null;){let r=a.elt;n.add(r),a=a.next}}else{let l=i.ibody!=null?i.ibody:i.ishape.body,o=i.ishape!=null?i.ishape:null,a=l.arbiters.head;for(;a!=null;){let r=a.elt;if(!r.presentable){a=a.next;continue}if(o!=null&&!(r.ws1==o||r.ws2==o)){a=a.next;continue}this.MRCA_chains(r.ws1,r.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 y,_;_=!1;let d=x.arbiters.head;for(;d!=null;){if(d.elt==r){_=!0;break}d=d.next}if(_)y=!1;else{let f=x.arbiters,z;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?z=new I._zpp.util.ZNPNode_ZPP_Arbiter:(z=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=z.next,z.next=null),z.elt=r;let P=z;P.next=f.head,f.head=P,f.modified=!0,f.length++,y=!0}y&&r.present++,h=h.next}p=p.next}a=a.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 a=o.elt,r=this.mrca2.head;for(;r!=null;){let p=r.elt;if(a!=t&&p!=t){r=r.next;continue}let c=a.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 d=_.elt;if(d.a==c&&d.b==h||d.a==h&&d.b==c){x=d;break}_=_.next}if(x==null){let d;Ne.zpp_pool==null?d=new Ne:(d=Ne.zpp_pool,Ne.zpp_pool=d.next,d.next=null),d.zip_listeners=!0,dt.setlt(c,h)?(d.a=c,d.b=h):(d.a=h,d.b=c),x=d,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 d=I._zpp.phys.ZPP_Interactor.get(a,p);d==null&&(d=Kt.get(a,p),this.add_callbackset(d));let f,z;z=!1;let P=d.arbiters.head;for(;P!=null;){if(P.elt==l){z=!0;break}P=P.next}if(z)f=!1;else{let Z=d.arbiters,m;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?m=new I._zpp.util.ZNPNode_ZPP_Arbiter:(m=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=m.next,m.next=null),m.elt=l;let b=m;b.next=Z.head,Z.head=b,Z.modified=!0,Z.length++,f=!0}f&&l.present++}r=r.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 a=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=o;let p=r;p.next=a.head,a.head=p,a.modified=!0,a.length++}else{let a=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=o;let p=r;p.next=a.head,a.head=p,a.modified=!0,a.length++}}else if(l.type==Ie.FLUID){let o=this.f_arbiters,a=l.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=a;let p=r;p.next=o.head,o.head=p,o.modified=!0,o.length++}else{let o=this.s_arbiters,a=l.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=a;let p=r;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,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=l;let r=a;r.next=o.head,o.head=r,o.modified=!0,o.length++}else{let o=this.c_arbiters_false,a;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(a=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=a.next,a.next=null),a.elt=l;let r=a;r.next=o.head,o.head=r,o.modified=!0,o.length++}}else if(i.type==Ie.FLUID){let l=this.f_arbiters,o=i.fluidarb,a;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(a=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let r=a;r.next=l.head,l.head=r,l.modified=!0,l.length++}else{let l=this.s_arbiters,o=i.sensorarb,a;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?a=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(a=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=a.next,a.next=null),a.elt=o;let r=a;r.next=l.head,l.head=r,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 a=i.b1.component,r=null;for(;a!=a.parent;){let p=a.parent;a.parent=r,r=a,a=p}for(;r!=null;){let p=r.parent;r.parent=a,r=p}l=a}let o;if(i.b2.component==i.b2.component.parent)o=i.b2.component;else{let a=i.b2.component,r=null;for(;a!=a.parent;){let p=a.parent;a.parent=r,r=a,a=p}for(;r!=null;){let p=r.parent;r.parent=a,r=p}o=a}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 a=i.b1.component,r=null;for(;a!=a.parent;){let p=a.parent;a.parent=r,r=a,a=p}for(;r!=null;){let p=r.parent;r.parent=a,r=p}l=a}let o;if(i.b2.component==i.b2.component.parent)o=i.b2.component;else{let a=i.b2.component,r=null;for(;a!=a.parent;){let p=a.parent;a.parent=r,r=a,a=p}for(;r!=null;){let p=r.parent;r.parent=a,r=p}o=a}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,a=o.component,r;if(a==a.parent)r=a;else{let x=a,y=null;for(;x!=x.parent;){let _=x.parent;x.parent=y,y=x,x=_}for(;y!=null;){let _=y.parent;y.parent=x,y=_}r=x}if(r.island==null){xt.zpp_pool==null?r.island=new xt:(r.island=xt.zpp_pool,xt.zpp_pool=r.island.next,r.island.next=null),r.island.waket=0;let x=this.islands,y=r.island;y._inuse=!0;let _=y;_.next=x.next,x.next=_,x.modified=!0,x.length++,r.island.sleep=!0}a.island=r.island;let p=a.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=a;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++;let u=o.atRest(e);a.island.sleep=a.island.sleep&&u,a.waket>a.island.waket&&(a.island.waket=a.waket)}for(;this.live_constraints.head!=null;){let i=this.live_constraints,l=i.head.elt;i.pop();let a=l.component,r;if(a==a.parent)r=a;else{let u=a,x=null;for(;u!=u.parent;){let y=u.parent;u.parent=x,x=u,u=y}for(;x!=null;){let y=x.parent;x.parent=u,x=y}r=u}a.island=r.island;let p=a.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=a;let h=c;h.next=p.head,p.head=h,p.modified=!0,p.length++,a.waket>a.island.waket&&(a.island.waket=a.waket)}for(;this.islands.next!=null;){let i=this.islands,l=i.next;i.pop();let o=l;if(o.sleep){let a=o.comps.head;for(;a!=null;){let r=a.elt;if(r.isBody){let p=r.body;p.velx=0,p.vely=0,p.angvel=0,r.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=r.constraint;this.constraintCbSleep(p),r.sleeping=!0}a=a.next}}else{for(;o.comps.head!=null;){let r=o.comps,p=r.head.elt;r.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 y=x;y.next=h.head,h.head=y,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 y=x;y.next=h.head,h.head=y,h.modified=!0,h.length++}c.sleeping=!1,c.island=null,c.parent=c,c.rank=0}let a=o;a.next=xt.zpp_pool,xt.zpp_pool=a}}}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,y;e==null?(x=t.head,y=x.next,t.head=y,t.head==null&&(t.pushmod=!0)):(x=e.next,y=x.next,e.next=y,y==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=y,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,a=!1;for(a&&o==null&&(a=!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,y;i==null?(x=l.head,y=x.next,l.head=y,l.head==null&&(l.pushmod=!0)):(x=i.next,y=x.next,i.next=y,y==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=y,a&&o==null&&(a=!1,l=null,i=null);continue}i=o,o=o.next,a&&o==null&&(a=!1,l=null,i=null)}let r=null,p=this.s_arbiters,c=p.head,h=!1;for(h&&c==null&&(h=!1,p=null,r=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,y;r==null?(x=p.head,y=x.next,p.head=y,p.head==null&&(p.pushmod=!0)):(x=r.next,y=x.next,r.next=y,y==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=y,h&&c==null&&(h=!1,p=null,r=null);continue}r=c,c=c.next,h&&c==null&&(h=!1,p=null,r=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 y=u;for(u=u.next;u!=null;){let Z=u;h+=y.x*(Z.y-x.y);let m=Z.y*y.x-Z.x*y.y;c.localCOMx+=(y.x+Z.x)*m,c.localCOMy+=(y.y+Z.y)*m,x=y,y=Z,u=u.next}u=c.lverts.next;let _=u;h+=y.x*(_.y-x.y);let d=_.y*y.x-_.x*y.y;c.localCOMx+=(y.x+_.x)*d,c.localCOMy+=(y.y+_.y)*d,x=y,y=_,u=u.next;let f=u;h+=y.x*(f.y-x.y);let z=f.y*y.x-f.x*y.y;c.localCOMx+=(y.x+f.x)*z,c.localCOMy+=(y.y+f.y)*z,h=1/(3*h);let P=h;c.localCOMx*=P,c.localCOMy*=P}}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 a=o.radius,r=o.radius;o.aabb.minx=o.worldCOMx-a,o.aabb.miny=o.worldCOMy-r,o.aabb.maxx=o.worldCOMx+a,o.aabb.maxy=o.worldCOMy+r}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 a=o.gverts.next;o.aabb.minx=a.x,o.aabb.miny=a.y,o.aabb.maxx=a.x,o.aabb.maxy=a.y;let r=o.gverts.next.next;for(;r!=null;){let p=r;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),r=r.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,y=l.gverts.next;for(;y!=null;){let _=y,d=x;x=x.next,_.x=l.body.posx+(l.body.axisy*d.x-l.body.axisx*d.y),_.y=l.body.posy+(d.x*l.body.axisx+d.y*l.body.axisy),y=y.next}}let a=l.edges.head,r=l.gverts.next,p=r;for(r=r.next;r!=null;){let u=r,x=a.elt;a=a.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,r=r.next}let c=l.gverts.next,h=a.elt;a=a.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 a=l.elt;if(a.type==1){let r=a.polygon;r.zip_sanitation&&(r.zip_sanitation=!1,r.splice_collinear_real());let p=a.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 : "+a.polygon.outer.toString()+" is invalid : "+p.toString());let c=a.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 f=c.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let z=c.lverts.next,P=c.gverts.next;for(;P!=null;){let Z=P,m=z;z=z.next,Z.x=c.body.posx+(c.body.axisy*m.x-c.body.axisx*m.y),Z.y=c.body.posy+(m.x*c.body.axisx+m.y*c.body.axisy),P=P.next}}let u=c.edges.head,x=c.gverts.next,y=x;for(x=x.next;x!=null;){let f=x,z=u.elt;u=u.next,z.gp0=y,z.gp1=f,z.gnormx=c.body.axisy*z.lnormx-c.body.axisx*z.lnormy,z.gnormy=z.lnormx*c.body.axisx+z.lnormy*c.body.axisy,z.gprojection=c.body.posx*z.gnormx+c.body.posy*z.gnormy+z.lprojection,z.wrap_gnorm!=null&&(z.wrap_gnorm.zpp_inner.x=z.gnormx,z.wrap_gnorm.zpp_inner.y=z.gnormy),z.tp0=z.gp0.y*z.gnormx-z.gp0.x*z.gnormy,z.tp1=z.gp1.y*z.gnormx-z.gp1.x*z.gnormy,y=f,x=x.next}let _=c.gverts.next,d=u.elt;u=u.next,d.gp0=y,d.gp1=_,d.gnormx=c.body.axisy*d.lnormx-c.body.axisx*d.lnormy,d.gnormy=d.lnormx*c.body.axisx+d.lnormy*c.body.axisy,d.gprojection=c.body.posx*d.gnormx+c.body.posy*d.gnormy+d.lprojection,d.wrap_gnorm!=null&&(d.wrap_gnorm.zpp_inner.x=d.gnormx,d.wrap_gnorm.zpp_inner.y=d.gnormy),d.tp0=d.gp0.y*d.gnormx-d.gp0.x*d.gnormy,d.tp1=d.gp1.y*d.gnormx-d.gp1.x*d.gnormy}}a.validate_sweepRadius(),a.sweepRadius>i.sweepRadius&&(i.sweepRadius=a.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 a=i.shapes.head;for(;a!=null;){let r=a.elt;if(r.zip_aabb&&r.body!=null)if(r.zip_aabb=!1,r.type==0){let h=r.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 d=1;_.localCOMx+=_.lverts.next.next.x*d,_.localCOMy+=_.lverts.next.next.y*d;let f=.5;_.localCOMx*=f,_.localCOMy*=f}else{_.localCOMx=0,_.localCOMy=0;let d=0,f=_.lverts.next,z=f;f=f.next;let P=f;for(f=f.next;f!=null;){let w=f;d+=P.x*(w.y-z.y);let O=w.y*P.x-w.x*P.y;_.localCOMx+=(P.x+w.x)*O,_.localCOMy+=(P.y+w.y)*O,z=P,P=w,f=f.next}f=_.lverts.next;let Z=f;d+=P.x*(Z.y-z.y);let m=Z.y*P.x-Z.x*P.y;_.localCOMx+=(P.x+Z.x)*m,_.localCOMy+=(P.y+Z.y)*m,z=P,P=Z,f=f.next;let b=f;d+=P.x*(b.y-z.y);let C=b.y*P.x-b.x*P.y;_.localCOMx+=(P.x+b.x)*C,_.localCOMy+=(P.y+b.y)*C,d=1/(3*d);let v=d;_.localCOMx*=v,_.localCOMy*=v}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy)}let y=h.body;y.zip_axis&&(y.zip_axis=!1,y.axisx=Math.sin(y.rot),y.axisy=Math.cos(y.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(r.type===2)r.capsule.__validate_aabb();else{let h=r.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let y=h.body;y.zip_axis&&(y.zip_axis=!1,y.axisx=Math.sin(y.rot),y.axisy=Math.cos(y.rot));let _=h.lverts.next,d=h.gverts.next;for(;d!=null;){let f=d,z=_;_=_.next,f.x=h.body.posx+(h.body.axisy*z.x-h.body.axisx*z.y),f.y=h.body.posy+(z.x*h.body.axisx+z.y*h.body.axisy),d=d.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 y=x;y.x<h.aabb.minx&&(h.aabb.minx=y.x),y.x>h.aabb.maxx&&(h.aabb.maxx=y.x),y.y<h.aabb.miny&&(h.aabb.miny=y.y),y.y>h.aabb.maxy&&(h.aabb.maxy=y.y),x=x.next}}let p=i.aabb,c=r.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),a=a.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 a=i.cbSet.bodylisteners.head;for(;a!=null;){let r=a.elt;if(r.event!=2){a=a.next;continue}let p=this.push_callback(r);p.event=2,p.body=i,a=a.next}}i.component.woken=!1;let o=i.shapes.head;for(;o!=null;){let a=o.elt;this.bphase.sync(a),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 a=l.elt;if(a.type==1){let r=a.polygon;r.zip_sanitation&&(r.zip_sanitation=!1,r.splice_collinear_real());let p=a.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 : "+a.polygon.outer.toString()+" is invalid : "+p.toString());let c=a.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 f=c.body;f.zip_axis&&(f.zip_axis=!1,f.axisx=Math.sin(f.rot),f.axisy=Math.cos(f.rot));let z=c.lverts.next,P=c.gverts.next;for(;P!=null;){let Z=P,m=z;z=z.next,Z.x=c.body.posx+(c.body.axisy*m.x-c.body.axisx*m.y),Z.y=c.body.posy+(m.x*c.body.axisx+m.y*c.body.axisy),P=P.next}}let u=c.edges.head,x=c.gverts.next,y=x;for(x=x.next;x!=null;){let f=x,z=u.elt;u=u.next,z.gp0=y,z.gp1=f,z.gnormx=c.body.axisy*z.lnormx-c.body.axisx*z.lnormy,z.gnormy=z.lnormx*c.body.axisx+z.lnormy*c.body.axisy,z.gprojection=c.body.posx*z.gnormx+c.body.posy*z.gnormy+z.lprojection,z.wrap_gnorm!=null&&(z.wrap_gnorm.zpp_inner.x=z.gnormx,z.wrap_gnorm.zpp_inner.y=z.gnormy),z.tp0=z.gp0.y*z.gnormx-z.gp0.x*z.gnormy,z.tp1=z.gp1.y*z.gnormx-z.gp1.x*z.gnormy,y=f,x=x.next}let _=c.gverts.next,d=u.elt;u=u.next,d.gp0=y,d.gp1=_,d.gnormx=c.body.axisy*d.lnormx-c.body.axisx*d.lnormy,d.gnormy=d.lnormx*c.body.axisx+d.lnormy*c.body.axisy,d.gprojection=c.body.posx*d.gnormx+c.body.posy*d.gnormy+d.lprojection,d.wrap_gnorm!=null&&(d.wrap_gnorm.zpp_inner.x=d.gnormx,d.wrap_gnorm.zpp_inner.y=d.gnormy),d.tp0=d.gp0.y*d.gnormx-d.gp0.x*d.gnormy,d.tp1=d.gp1.y*d.gnormx-d.gp1.x*d.gnormy}}a.validate_sweepRadius(),a.sweepRadius>i.sweepRadius&&(i.sweepRadius=a.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 a=i.shapes.head;for(;a!=null;){let r=a.elt;if(r.zip_aabb&&r.body!=null)if(r.zip_aabb=!1,r.type==0){let h=r.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 d=1;_.localCOMx+=_.lverts.next.next.x*d,_.localCOMy+=_.lverts.next.next.y*d;let f=.5;_.localCOMx*=f,_.localCOMy*=f}else{_.localCOMx=0,_.localCOMy=0;let d=0,f=_.lverts.next,z=f;f=f.next;let P=f;for(f=f.next;f!=null;){let w=f;d+=P.x*(w.y-z.y);let O=w.y*P.x-w.x*P.y;_.localCOMx+=(P.x+w.x)*O,_.localCOMy+=(P.y+w.y)*O,z=P,P=w,f=f.next}f=_.lverts.next;let Z=f;d+=P.x*(Z.y-z.y);let m=Z.y*P.x-Z.x*P.y;_.localCOMx+=(P.x+Z.x)*m,_.localCOMy+=(P.y+Z.y)*m,z=P,P=Z,f=f.next;let b=f;d+=P.x*(b.y-z.y);let C=b.y*P.x-b.x*P.y;_.localCOMx+=(P.x+b.x)*C,_.localCOMy+=(P.y+b.y)*C,d=1/(3*d);let v=d;_.localCOMx*=v,_.localCOMy*=v}}h.wrap_localCOM!=null&&(h.wrap_localCOM.zpp_inner.x=h.localCOMx,h.wrap_localCOM.zpp_inner.y=h.localCOMy)}let y=h.body;y.zip_axis&&(y.zip_axis=!1,y.axisx=Math.sin(y.rot),y.axisy=Math.cos(y.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(r.type===2)r.capsule.__validate_aabb();else{let h=r.polygon;if(h.zip_gverts&&h.body!=null){h.zip_gverts=!1,h.validate_lverts();let y=h.body;y.zip_axis&&(y.zip_axis=!1,y.axisx=Math.sin(y.rot),y.axisy=Math.cos(y.rot));let _=h.lverts.next,d=h.gverts.next;for(;d!=null;){let f=d,z=_;_=_.next,f.x=h.body.posx+(h.body.axisy*z.x-h.body.axisx*z.y),f.y=h.body.posy+(z.x*h.body.axisx+z.y*h.body.axisy),d=d.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 y=x;y.x<h.aabb.minx&&(h.aabb.minx=y.x),y.x>h.aabb.maxx&&(h.aabb.maxx=y.x),y.y<h.aabb.miny&&(h.aabb.miny=y.y),y.y>h.aabb.maxy&&(h.aabb.maxy=y.y),x=x.next}}let p=i.aabb,c=r.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),a=a.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 a=o.elt;this.bphase.sync(a),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 a=this.push_callback(o);a.event=2,a.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,a=0;o=l.worldCOMx-l.posx,a=l.worldCOMy-l.posy;let r=l.torque+(this.gravityy*o-this.gravityx*a)*l.gravMass;l.angvel=s*l.angvel+r*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 a=i.sweep_angvel*l;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let r=a*a,p=1-.5*r,c=1-r*r/8,h=(p*i.axisx+a*i.axisy)*c;i.axisy=(p*i.axisy-a*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let o=I._nape.Config.staticCCDLinearThreshold*i.sweepRadius,a=I._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>o*o||i.angvel*i.angvel*e*e>a*a||i.type==3){let r=i.sweep_angvel;r<0&&(r=-r);let p=1/r,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,y=u.miny,_=u.maxx,d=u.maxy,f=r*e*h.sweepCoef*.008333333333333333|0;f>8&&(f=8);let z=r*e/f,P=e-i.sweepTime;if(P!=0){i.sweepTime=e;let b=P;if(i.posx+=i.velx*b,i.posy+=i.vely*b,i.angvel!=0){let C=i.sweep_angvel*P;if(i.rot+=C,C*C>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let v=C*C,w=1-.5*v,O=1-v*v/8,k=(w*i.axisx+C*i.axisy)*O;i.axisy=(w*i.axisy-C*i.axisx)*O,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,C=b.lverts.next,v=b.gverts.next,w=C;C=C.next,v.x=b.body.posx+(b.body.axisy*w.x-b.body.axisx*w.y),v.y=b.body.posy+(w.x*b.body.axisx+w.y*b.body.axisy),b.aabb.minx=v.x,b.aabb.miny=v.y,b.aabb.maxx=v.x,b.aabb.maxy=v.y;let O=b.gverts.next.next;for(;O!=null;){let k=O,g=C;C=C.next,k.x=b.body.posx+(b.body.axisy*g.x-b.body.axisx*g.y),k.y=b.body.posy+(g.x*b.body.axisx+g.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),O=O.next}}x<u.minx?u.minx=x:x=u.minx,y<u.miny?u.miny=y:y=u.miny,_>u.maxx?u.maxx=_:_=u.maxx,d>u.maxy?u.maxy=d:d=u.maxy;let Z=1,m=f;for(;Z<m;){let b=Z++,C=z*b*p,v=C-i.sweepTime;if(v!=0){i.sweepTime=C;let w=v;if(i.posx+=i.velx*w,i.posy+=i.vely*w,i.angvel!=0){let O=i.sweep_angvel*v;if(i.rot+=O,O*O>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let k=O*O,g=1-.5*k,E=1-k*k/8,M=(g*i.axisx+O*i.axisy)*E;i.axisy=(g*i.axisy-O*i.axisx)*E,i.axisx=M}}}if(h.type==0){let w=h.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else if(h.type===2)h.capsule.__validate_aabb();else{let w=h.polygon,O=w.lverts.next,k=w.gverts.next,g=O;O=O.next,k.x=w.body.posx+(w.body.axisy*g.x-w.body.axisx*g.y),k.y=w.body.posy+(g.x*w.body.axisx+g.y*w.body.axisy),w.aabb.minx=k.x,w.aabb.miny=k.y,w.aabb.maxx=k.x,w.aabb.maxy=k.y;let E=w.gverts.next.next;for(;E!=null;){let M=E,N=O;O=O.next,M.x=w.body.posx+(w.body.axisy*N.x-w.body.axisx*N.y),M.y=w.body.posy+(N.x*w.body.axisx+N.y*w.body.axisy),M.x<w.aabb.minx&&(w.aabb.minx=M.x),M.x>w.aabb.maxx&&(w.aabb.maxx=M.x),M.y<w.aabb.miny&&(w.aabb.miny=M.y),M.y>w.aabb.maxy&&(w.aabb.maxy=M.y),E=E.next}}x<u.minx?u.minx=x:x=u.minx,y<u.miny?u.miny=y:y=u.miny,_>u.maxx?u.maxx=_:_=u.maxx,d>u.maxy?u.maxy=d:d=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 a=i.sweep_angvel*l;if(i.rot+=a,a*a>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let r=a*a,p=1-.5*r,c=1-r*r/8,h=(p*i.axisx+a*i.axisy)*c;i.axisy=(p*i.axisy-a*i.axisx)*c,i.axisx=h}}}if(i.disableCCD)i.sweepFrozen=!0,i.bullet=!1;else{let o=I._nape.Config.staticCCDLinearThreshold*i.sweepRadius,a=I._nape.Config.staticCCDAngularThreshold;if((i.velx*i.velx+i.vely*i.vely)*e*e>o*o||i.angvel*i.angvel*e*e>a*a||i.type==3){let r=i.sweep_angvel;r<0&&(r=-r);let p=1/r,c=i.shapes.head;for(;c!=null;){let h=c.elt,u=h.aabb,x=u.minx,y=u.miny,_=u.maxx,d=u.maxy,f=r*e*h.sweepCoef*.008333333333333333|0;f>8&&(f=8);let z=r*e/f,P=e-i.sweepTime;if(P!=0){i.sweepTime=e;let b=P;if(i.posx+=i.velx*b,i.posy+=i.vely*b,i.angvel!=0){let C=i.sweep_angvel*P;if(i.rot+=C,C*C>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let v=C*C,w=1-.5*v,O=1-v*v/8,k=(w*i.axisx+C*i.axisy)*O;i.axisy=(w*i.axisy-C*i.axisx)*O,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,C=b.lverts.next,v=b.gverts.next,w=C;C=C.next,v.x=b.body.posx+(b.body.axisy*w.x-b.body.axisx*w.y),v.y=b.body.posy+(w.x*b.body.axisx+w.y*b.body.axisy),b.aabb.minx=v.x,b.aabb.miny=v.y,b.aabb.maxx=v.x,b.aabb.maxy=v.y;let O=b.gverts.next.next;for(;O!=null;){let k=O,g=C;C=C.next,k.x=b.body.posx+(b.body.axisy*g.x-b.body.axisx*g.y),k.y=b.body.posy+(g.x*b.body.axisx+g.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),O=O.next}}x<u.minx?u.minx=x:x=u.minx,y<u.miny?u.miny=y:y=u.miny,_>u.maxx?u.maxx=_:_=u.maxx,d>u.maxy?u.maxy=d:d=u.maxy;let Z=1,m=f;for(;Z<m;){let b=Z++,C=z*b*p,v=C-i.sweepTime;if(v!=0){i.sweepTime=C;let w=v;if(i.posx+=i.velx*w,i.posy+=i.vely*w,i.angvel!=0){let O=i.sweep_angvel*v;if(i.rot+=O,O*O>1e-4)i.axisx=Math.sin(i.rot),i.axisy=Math.cos(i.rot);else{let k=O*O,g=1-.5*k,E=1-k*k/8,M=(g*i.axisx+O*i.axisy)*E;i.axisy=(g*i.axisy-O*i.axisx)*E,i.axisx=M}}}if(h.type==0){let w=h.circle;w.worldCOMx=w.body.posx+(w.body.axisy*w.localCOMx-w.body.axisx*w.localCOMy),w.worldCOMy=w.body.posy+(w.localCOMx*w.body.axisx+w.localCOMy*w.body.axisy),w.aabb.minx=w.worldCOMx-w.radius,w.aabb.miny=w.worldCOMy-w.radius,w.aabb.maxx=w.worldCOMx+w.radius,w.aabb.maxy=w.worldCOMy+w.radius}else{let w=h.polygon,O=w.lverts.next,k=w.gverts.next,g=O;O=O.next,k.x=w.body.posx+(w.body.axisy*g.x-w.body.axisx*g.y),k.y=w.body.posy+(g.x*w.body.axisx+g.y*w.body.axisy),w.aabb.minx=k.x,w.aabb.miny=k.y,w.aabb.maxx=k.x,w.aabb.maxy=k.y;let E=w.gverts.next.next;for(;E!=null;){let M=E,N=O;O=O.next,M.x=w.body.posx+(w.body.axisy*N.x-w.body.axisx*N.y),M.y=w.body.posy+(N.x*w.body.axisx+N.y*w.body.axisy),M.x<w.aabb.minx&&(w.aabb.minx=M.x),M.x>w.aabb.maxx&&(w.aabb.maxx=M.x),M.y<w.aabb.miny&&(w.aabb.miny=M.y),M.y>w.aabb.maxy&&(w.aabb.maxy=M.y),E=E.next}}x<u.minx?u.minx=x:x=u.minx,y<u.miny?u.miny=y:y=u.miny,_>u.maxx?u.maxx=_:_=u.maxx,d>u.maxy?u.maxy=d:d=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,a=e.ws2,r=this.mrca1;for(;r.head!=null;){let x=r.head;r.head=x.next;let y=x;y.elt=null,y.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y,r.head==null&&(r.pushmod=!0),r.modified=!0,r.length--}r.pushmod=!0;let p=this.mrca2;for(;p.head!=null;){let x=p.head;p.head=x.next;let y=x;y.elt=null,y.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=y,p.head==null&&(p.pushmod=!0),p.modified=!0,p.length--}if(p.pushmod=!0,o.cbSet!=null){let x=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=o;let _=y;_.next=x.head,x.head=_,x.modified=!0,x.length++}if(o.body.cbSet!=null){let x=this.mrca1,y=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=y;let d=_;d.next=x.head,x.head=d,x.modified=!0,x.length++}if(a.cbSet!=null){let x=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=a;let _=y;_.next=x.head,x.head=_,x.modified=!0,x.length++}if(a.body.cbSet!=null){let x=this.mrca2,y=a.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=y;let d=_;d.next=x.head,x.head=d,x.modified=!0,x.length++}let c=o.body.compound,h=a.body.compound;for(;c!=h;){let x=c==null?0:c.depth,y=h==null?0:h.depth;if(x<y){if(h.cbSet!=null){let _=this.mrca2,d;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_Interactor:(d=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=h;let f=d;f.next=_.head,_.head=f,_.modified=!0,_.length++}h=h.compound}else{if(c.cbSet!=null){let _=this.mrca1,d;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?d=new I._zpp.util.ZNPNode_ZPP_Interactor:(d=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=d.next,d.next=null),d.elt=c;let f=d;f.next=_.head,_.head=f,_.modified=!0,_.length++}c=c.compound}}let u=this.mrca1.head;for(;u!=null;){let x=u.elt,y=this.mrca2.head;for(;y!=null;){let _=y.elt,d=x.cbSet,f=_.cbSet,z=d.manager,P=null,m=(d.cbpairs.length<f.cbpairs.length?d.cbpairs:f.cbpairs).head;for(;m!=null;){let C=m.elt;if(C.a==d&&C.b==f||C.a==f&&C.b==d){P=C;break}m=m.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(d,f)?(C.a=d,C.b=f):(C.a=f,C.b=d),P=C,d.cbpairs.add(P),f!=d&&f.cbpairs.add(P)}if(P.zip_listeners&&(P.zip_listeners=!1,P.__validate()),P.listeners.head==null){y=y.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 C=d.manager,v=null,O=(d.cbpairs.length<f.cbpairs.length?d.cbpairs:f.cbpairs).head;for(;O!=null;){let N=O.elt;if(N.a==d&&N.b==f||N.a==f&&N.b==d){v=N;break}O=O.next}if(v==null){let N;Ne.zpp_pool==null?N=new Ne:(N=Ne.zpp_pool,Ne.zpp_pool=N.next,N.next=null),N.zip_listeners=!0,dt.setlt(d,f)?(N.a=d,N.b=f):(N.a=f,N.b=d),v=N,d.cbpairs.add(v),f!=d&&f.cbpairs.add(v)}v.zip_listeners&&(v.zip_listeners=!1,v.__validate());let k=v.listeners.head;for(;k!=null;){let N=k.elt;if(N.event==0&&(N.itype&e.type)!=0&&b.empty_arb(N.itype)){let S=this.push_callback(N);S.event=0;let D=b.int1,j=b.int2,R,q=N.options1,G=D.cbTypes;if(q.nonemptyintersection(G,q.includes)&&!q.nonemptyintersection(G,q.excludes)){let B=N.options2,V=j.cbTypes;R=B.nonemptyintersection(V,B.includes)&&!B.nonemptyintersection(V,B.excludes)}else R=!1;R?(S.int1=D,S.int2=j):(S.int1=j,S.int2=D),S.set=b}k=k.next}let g,E;E=!1;let M=b.arbiters.head;for(;M!=null;){if(M.elt==e){E=!0;break}M=M.next}if(E)g=!1;else{let N=b.arbiters,S;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?S=new I._zpp.util.ZNPNode_ZPP_Arbiter:(S=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=S.next,S.next=null),S.elt=e;let D=S;D.next=N.head,N.head=D,N.modified=!0,N.length++,g=!0}g&&e.present++}else{e.present--,b.remove_arb(e);let C=d.manager,v=null,O=(d.cbpairs.length<f.cbpairs.length?d.cbpairs:f.cbpairs).head;for(;O!=null;){let g=O.elt;if(g.a==d&&g.b==f||g.a==f&&g.b==d){v=g;break}O=O.next}if(v==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(d,f)?(g.a=d,g.b=f):(g.a=f,g.b=d),v=g,d.cbpairs.add(v),f!=d&&f.cbpairs.add(v)}v.zip_listeners&&(v.zip_listeners=!1,v.__validate());let k=v.listeners.head;for(;k!=null;){let g=k.elt;if(g.event==1&&(g.itype&e.type)!=0&&b.empty_arb(g.itype)){let E=this.push_callback(g);E.event=1;let M=b.int1,N=b.int2,S,D=g.options1,j=M.cbTypes;if(D.nonemptyintersection(j,D.includes)&&!D.nonemptyintersection(j,D.excludes)){let R=g.options2,q=N.cbTypes;S=R.nonemptyintersection(q,R.includes)&&!R.nonemptyintersection(q,R.excludes)}else S=!1;S?(E.int1=M,E.int2=N):(E.int1=N,E.int2=M),E.set=b}k=k.next}b.arbiters.head==null&&this.remove_callbackset(b)}y=y.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,a=null,r=o.head,p=!1;for(;r!=null;){if(r.elt==i){let y,_;a==null?(y=o.head,_=y.next,o.head=_,o.head==null&&(o.pushmod=!0)):(y=a.next,_=y.next,a.next=_,_==null&&(o.pushmod=!0));let d=y;d.elt=null,d.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=d,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}a=r,r=r.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let y,_;h==null?(y=c.head,_=y.next,c.head=_,c.head==null&&(c.pushmod=!0)):(y=h.next,_=y.next,h.next=_,_==null&&(c.pushmod=!0));let d=y;d.elt=null,d.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=d,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,a=null,r=o.head,p=!1;for(;r!=null;){if(r.elt==i){let y,_;a==null?(y=o.head,_=y.next,o.head=_,o.head==null&&(o.pushmod=!0)):(y=a.next,_=y.next,a.next=_,_==null&&(o.pushmod=!0));let d=y;d.elt=null,d.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=d,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}a=r,r=r.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let y,_;h==null?(y=c.head,_=y.next,c.head=_,c.head==null&&(c.pushmod=!0)):(y=h.next,_=y.next,h.next=_,_==null&&(c.pushmod=!0));let d=y;d.elt=null,d.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=d,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,a=null,r=o.head,p=!1;for(;r!=null;){if(r.elt==i){let y,_;a==null?(y=o.head,_=y.next,o.head=_,o.head==null&&(o.pushmod=!0)):(y=a.next,_=y.next,a.next=_,_==null&&(o.pushmod=!0));let d=y;d.elt=null,d.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=d,o.modified=!0,o.length--,o.pushmod=!0,p=!0;break}a=r,r=r.next}let c=i.b2.arbiters,h=null,u=c.head,x=!1;for(;u!=null;){if(u.elt==i){let y,_;h==null?(y=c.head,_=y.next,c.head=_,c.head==null&&(c.pushmod=!0)):(y=h.next,_=y.next,h.next=_,_==null&&(c.pushmod=!0));let d=y;d.elt=null,d.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=d,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,a=o.next;o.pop();let r=a;r.arbiter=null,r.next=we.zpp_pool,we.zpp_pool=r;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 a=!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 z=i.contacts,P,Z;c==null?(P=z.next,Z=P.next,z.next=Z,z.next==null&&(z.pushmod=!0)):(P=c.next,Z=P.next,c.next=Z,Z==null&&(z.pushmod=!0)),P._inuse=!1,z.modified=!0,z.length--,z.pushmod=!0,x=Z;let m=i.innards,b,C;h==null?(b=m.next,C=b.next,m.next=C,m.next==null&&(m.pushmod=!0)):(b=h.next,C=b.next,h.next=C,C==null&&(m.pushmod=!0)),b._inuse=!1,m.modified=!0,m.length--,m.pushmod=!0,u=C;let v=_;v.arbiter=null,v.next=we.zpp_pool,we.zpp_pool=v;continue}let d=_.inner,f=_.active;if(_.active=_.stamp==i.stamp,_.active){a?(a=!1,i.c1=d,i.oc1=_):(i.hc2=!0,i.c2=d,i.oc2=_),d.r2x=_.px-i.b2.posx,d.r2y=_.py-i.b2.posy,d.r1x=_.px-i.b1.posx,d.r1y=_.py-i.b1.posy;let z=d.r2x*i.nx+d.r2y*i.ny,P=o+i.b2.sinertia*(z*z),Z=d.r1x*i.nx+d.r1y*i.ny;P+=i.b1.sinertia*(Z*Z),d.tMass=P<I._nape.Config.epsilon*I._nape.Config.epsilon?0:1/P;let m=i.ny*d.r2x-i.nx*d.r2y,b=o+i.b2.sinertia*(m*m),C=i.ny*d.r1x-i.nx*d.r1y;b+=i.b1.sinertia*(C*C),d.nMass=b<I._nape.Config.epsilon*I._nape.Config.epsilon?0:1/b;let v=0,w=0,O=i.b2.angvel+i.b2.kinangvel;v=i.b2.velx+i.b2.kinvelx-d.r2y*O,w=i.b2.vely+i.b2.kinvely+d.r2x*O,O=i.b1.angvel+i.b1.kinangvel,v-=i.b1.velx+i.b1.kinvelx-d.r1y*O,w-=i.b1.vely+i.b1.kinvely+d.r1x*O;let k=i.nx*v+i.ny*w;_.elasticity=i.restitution,d.bounce=k*_.elasticity,d.bounce>-I._nape.Config.elasticThreshold&&(d.bounce=0),k=w*i.nx-v*i.ny;let g=I._nape.Config.staticFrictionThreshold;k*k>g*g?d.friction=i.dyn_fric:d.friction=i.stat_fric,d.jnAcc*=l,d.jtAcc*=l}f!=_.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 d=i.oc1;i.oc1=i.oc2,i.oc2=d,i.hc2=!1}else i.oc2.posOnly&&(i.hc2=!1);i.oc1.posOnly&&(a=!0)}else i.hpc2=!1;if(i.jrAcc*=l,a||(i.rn1a=i.ny*i.c1.r1x-i.nx*i.c1.r1y,i.rt1a=i.c1.r1x*i.nx+i.c1.r1y*i.ny,i.rn1b=i.ny*i.c1.r2x-i.nx*i.c1.r2y,i.rt1b=i.c1.r2x*i.nx+i.c1.r2y*i.ny,i.k1x=i.b2.kinvelx-i.c1.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c1.r1y*i.b1.kinangvel),i.k1y=i.b2.kinvely+i.c1.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c1.r1x*i.b1.kinangvel)),i.hc2)if(i.rn2a=i.ny*i.c2.r1x-i.nx*i.c2.r1y,i.rt2a=i.c2.r1x*i.nx+i.c2.r1y*i.ny,i.rn2b=i.ny*i.c2.r2x-i.nx*i.c2.r2y,i.rt2b=i.c2.r2x*i.nx+i.c2.r2y*i.ny,i.k2x=i.b2.kinvelx-i.c2.r2y*i.b2.kinangvel-(i.b1.kinvelx-i.c2.r1y*i.b1.kinangvel),i.k2y=i.b2.kinvely+i.c2.r2x*i.b2.kinangvel-(i.b1.kinvely+i.c2.r1x*i.b1.kinangvel),i.kMassa=o+i.b1.sinertia*i.rn1a*i.rn1a+i.b2.sinertia*i.rn1b*i.rn1b,i.kMassb=o+i.b1.sinertia*i.rn1a*i.rn2a+i.b2.sinertia*i.rn1b*i.rn2b,i.kMassc=o+i.b1.sinertia*i.rn2a*i.rn2a+i.b2.sinertia*i.rn2b*i.rn2b,i.kMassa*i.kMassa+2*i.kMassb*i.kMassb+i.kMassc*i.kMassc<I._nape.Config.illConditionedThreshold*(i.kMassa*i.kMassc-i.kMassb*i.kMassb)){i.Ka=i.kMassa,i.Kb=i.kMassb,i.Kc=i.kMassc;let d=i.kMassa*i.kMassc-i.kMassb*i.kMassb;if(d!=d)i.kMassa=i.kMassb=i.kMassc=0;else if(d==0){let f=0;i.kMassa!=0?i.kMassa=1/i.kMassa:(i.kMassa=0,f|=1),i.kMassc!=0?i.kMassc=1/i.kMassc:(i.kMassc=0,f|=2),i.kMassb=0}else{d=1/d;let f=i.kMassc*d;i.kMassc=i.kMassa*d,i.kMassa=f,i.kMassb*=-d}}else{if(i.hc2=!1,i.oc2.dist<i.oc1.dist){let d=i.c1;i.c1=i.c2,i.c2=d}i.oc2.active=!1,i.contacts.modified=!0}i.surfacex=i.b2.svelx,i.surfacey=i.b2.svely;let y=1;i.surfacex+=i.b1.svelx*y,i.surfacey+=i.b1.svely*y,i.surfacex=-i.surfacex,i.surfacey=-i.surfacey,i.rMass=i.b1.sinertia+i.b2.sinertia,i.rMass!=0&&(i.rMass=1/i.rMass),a&&(e.active=!1)}else{let i=e.fluidarb;i.pre_dt==-1&&(i.pre_dt=t);let 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,a=0;i.ws1.fluidEnabled&&i.ws1.fluidProperties.wrap_gravity!=null?(o=i.ws1.fluidProperties.gravityx,a=i.ws1.fluidProperties.gravityy):(o=this.gravityx,a=this.gravityy);let r=0,p=0;i.ws2.fluidEnabled&&i.ws2.fluidProperties.wrap_gravity!=null?(r=i.ws2.fluidProperties.gravityx,p=i.ws2.fluidProperties.gravityy):(r=this.gravityx,p=this.gravityy);let c=0,h=0;if(i.ws1.fluidEnabled&&i.ws2.fluidEnabled){let y=i.overlap*i.ws1.fluidProperties.density,_=i.overlap*i.ws2.fluidProperties.density;if(y>_){let d=y+_;c-=o*d,h-=a*d}else if(y<_){let d=y+_;c+=r*d,h+=p*d}else{let d=0,f=0;d=o+r,f=a+p;let z=.5;if(d*=z,f*=z,i.ws1.worldCOMx*d+i.ws1.worldCOMy*f>i.ws2.worldCOMx*d+i.ws2.worldCOMy*f){let P=y+_;c-=d*P,h-=f*P}else{let P=y+_;c+=d*P,h+=f*P}}}else if(i.ws1.fluidEnabled){let _=i.overlap*i.ws1.fluidProperties.density;c-=o*_,h-=a*_}else if(i.ws2.fluidEnabled){let _=i.overlap*i.ws2.fluidProperties.density;c+=r*_,h+=p*_}let u=t;if(c*=u,h*=u,i.buoyx=c,i.buoyy=h,i.b1.type==2){let y=i.b1.imass;i.b1.velx-=c*y,i.b1.vely-=h*y,i.b1.angvel-=(h*i.r1x-c*i.r1y)*i.b1.iinertia}if(i.b2.type==2){let y=i.b2.imass;i.b2.velx+=c*y,i.b2.vely+=h*y,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 y=0;if(i.ws1.fluidEnabled&&(i.ws2.validate_angDrag(),y+=i.ws1.fluidProperties.viscosity*i.ws2.angDrag*i.overlap/i.ws2.area),i.ws2.fluidEnabled&&(i.ws1.validate_angDrag(),y+=i.ws2.fluidProperties.viscosity*i.ws1.angDrag*i.overlap/i.ws1.area),y!=0){let z=i.b1.sinertia+i.b2.sinertia;z!=0?i.wMass=1/z:i.wMass=0,y*=4e-4;let P=2*Math.PI*y;i.agamma=1/(t*P*(2+P*t));let Z=1/(1+i.agamma),m=t*P*P*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)),d=i.b2.vely+i.b2.kinvely+i.r2x*(i.b2.angvel+i.b2.kinangvel)-(i.b1.vely+i.b1.kinvely+i.r1x*(i.b1.angvel+i.b1.kinangvel));if(!(_*_+d*d<I._nape.Config.epsilon*I._nape.Config.epsilon)){let z=_*_+d*d,Z=1/Math.sqrt(z);_*=Z,d*=Z,i.nx=_,i.ny=d}let f=0;if(i.ws1.fluidEnabled){let z=-i.ws1.fluidProperties.viscosity*i.overlap/i.ws2.area;if(i.ws2.type==0)f-=z*i.ws2.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws2.circle.radius*Math.PI);else if(i.ws2.type===2){let P=i.ws2.capsule.radius;f-=z*P*I._nape.Config.fluidLinearDrag/(2*P*Math.PI)}else{let P=i.ws2.polygon,Z=0,m=0,b=P.edges.head;for(;b!=null;){let C=b.elt;Z+=C.length;let v=z*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);v>0&&(v*=-I._nape.Config.fluidVacuumDrag,v=v),m-=v*.5*I._nape.Config.fluidLinearDrag,b=b.next}f+=m/Z}}if(i.ws2.fluidEnabled){let z=-i.ws2.fluidProperties.viscosity*i.overlap/i.ws1.area;if(i.ws1.type==0)f-=z*i.ws1.circle.radius*I._nape.Config.fluidLinearDrag/(2*i.ws1.circle.radius*Math.PI);else if(i.ws1.type===2){let P=i.ws1.capsule.radius;f-=z*P*I._nape.Config.fluidLinearDrag/(2*P*Math.PI)}else{let P=i.ws1.polygon,Z=0,m=0,b=P.edges.head;for(;b!=null;){let C=b.elt;Z+=C.length;let v=z*C.length*(C.gnormx*i.nx+C.gnormy*i.ny);v>0&&(v*=-I._nape.Config.fluidVacuumDrag,v=v),m-=v*.5*I._nape.Config.fluidLinearDrag,b=b.next}f+=m/Z}}if(f!=0){let z=i.b1.smass+i.b2.smass,P=0,Z=0,m=0;if(P=z,Z=0,m=z,i.b1.sinertia!=0){let k=i.r1x*i.b1.sinertia,g=i.r1y*i.b1.sinertia;P+=g*i.r1y,Z+=-g*i.r1x,m+=k*i.r1x}if(i.b2.sinertia!=0){let k=i.r2x*i.b2.sinertia,g=i.r2y*i.b2.sinertia;P+=g*i.r2y,Z+=-g*i.r2x,m+=k*i.r2x}let b=P*m-Z*Z;if(b!=b)m=0,Z=m,P=Z;else if(b==0){let k=0;P!=0?P=1/P:(P=0,k|=1),m!=0?m=1/m:(m=0,k|=2),Z=0}else{b=1/b;let k=m*b;m=P*b,P=k,Z*=-b}i.vMassa=P,i.vMassb=Z,i.vMassc=m;let C,v=2*Math.PI*f;i.lgamma=1/(t*v*(2+v*t));let w=1/(1+i.lgamma);C=t*v*v*i.lgamma,i.lgamma*=w;let O=w;i.vMassa*=O,i.vMassb*=O,i.vMassc*=O}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,a=null,r=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,y,_;o==null?(y=x.next,_=y.next,x.next=_,x.next==null&&(x.pushmod=!0)):(y=o.next,_=y.next,o.next=_,_==null&&(x.pushmod=!0)),y._inuse=!1,x.modified=!0,x.length--,x.pushmod=!0,p=_;let d=i.innards,f,z;a==null?(f=d.next,z=f.next,d.next=z,d.next==null&&(d.pushmod=!0)):(f=a.next,z=f.next,a.next=z,z==null&&(d.pushmod=!0)),f._inuse=!1,d.modified=!0,d.length--,d.pushmod=!0,r=z;let P=c;P.arbiter=null,P.next=we.zpp_pool,we.zpp_pool=P;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,a=r,r=r.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}prestep(e){let t=null,n=this.live_constraints.head;for(;n!=null;){let _=n.elt;if(_.preStep(e)){n=this.live_constraints.erase(t),_.broken(),this.constraintCbBreak(_),_.removeOnBreak?(_.component.sleeping=!0,this.midstep=!1,_.compound!=null?_.compound.wrap_constraints.remove(_.outer):this.wrap_constraints.remove(_.outer),this.midstep=!0):_.active=!1,_.clearcache();continue}t=n,n=n.next}let 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 _=l.elt;if(this.presteparb(_,e)){let d,f;s==null?(d=i.head,f=d.next,i.head=f,i.head==null&&(i.pushmod=!0)):(d=s.next,f=d.next,s.next=f,f==null&&(i.pushmod=!0));let z=d;z.elt=null,z.next=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=z,i.modified=!0,i.length--,i.pushmod=!0,l=f,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)}let a=null,r=this.f_arbiters,p=r.head,c=!1;for(c&&p==null&&(c=!1,r=null,a=null);p!=null;){let _=p.elt;if(this.presteparb(_,e)){let d,f;a==null?(d=r.head,f=d.next,r.head=f,r.head==null&&(r.pushmod=!0)):(d=a.next,f=d.next,a.next=f,f==null&&(r.pushmod=!0));let z=d;z.elt=null,z.next=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=z,r.modified=!0,r.length--,r.pushmod=!0,p=f,c&&p==null&&(c=!1,r=null,a=null);continue}a=p,p=p.next,c&&p==null&&(c=!1,r=null,a=null)}let h=null,u=this.s_arbiters,x=u.head,y=!1;for(y&&x==null&&(y=!1,u=null,h=null);x!=null;){let _=x.elt;if(this.presteparb(_,e)){let d,f;h==null?(d=u.head,f=d.next,u.head=f,u.head==null&&(u.pushmod=!0)):(d=h.next,f=d.next,h.next=f,f==null&&(u.pushmod=!0));let z=d;z.elt=null,z.next=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=z,u.modified=!0,u.length--,u.pushmod=!0,x=f,y&&x==null&&(y=!1,u=null,h=null);continue}h=x,x=x.next,y&&x==null&&(y=!1,u=null,h=null)}}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,a=i.b1.imass;i.b1.velx-=l*a,i.b1.vely-=o*a,i.b1.angvel-=i.b1.iinertia*(o*i.c1.r1x-l*i.c1.r1y);let r=i.b2.imass;if(i.b2.velx+=l*r,i.b2.vely+=o*r,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),y=p.vMassa*u+p.vMassb*x;x=p.vMassb*u+p.vMassc*x,u=y;let _=p.lgamma;u-=p.dampx*_,x-=p.dampy*_;let d=1;p.dampx+=u*d,p.dampy+=x*d;let f=p.b1.imass;p.b1.velx-=u*f,p.b1.vely-=x*f;let z=p.b2.imass;p.b2.velx+=u*z,p.b2.vely+=x*z,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 P=(c-h)*p.wMass-p.adamp*p.agamma;p.adamp+=P,p.b1.angvel-=P*p.b1.iinertia,p.b2.angvel+=P*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 a=this.c_arbiters_false.head,r=!0;for(a==null&&(a=this.c_arbiters_true.head,r=!1);a!=null;){let p=a.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,y=p.c1.jtAcc,_=y-u;_>x?_=x:_<-x&&(_=-x),u=_-y,p.c1.jtAcc=_;let d=-p.ny*u,f=p.nx*u;if(p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rt1b*u*p.b2.iinertia,p.b1.angvel-=p.rt1a*u*p.b1.iinertia,p.hc2){let z=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),P=p.k2y+p.b2.vely+p.c2.r2x*p.b2.angvel-(p.b1.vely+p.c2.r1x*p.b1.angvel);u=(P*p.nx-z*p.ny+p.surfacex)*p.c2.tMass,x=p.c2.friction*p.c2.jnAcc,y=p.c2.jtAcc,_=y-u,_>x?_=x:_<-x&&(_=-x),u=_-y,p.c2.jtAcc=_,d=-p.ny*u,f=p.nx*u,p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rt2b*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),z=p.k2x+p.b2.velx-p.c2.r2y*p.b2.angvel-(p.b1.velx-p.c2.r1y*p.b1.angvel),P=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,m=p.c2.jnAcc,b=c*p.nx+h*p.ny+p.surfacey+p.c1.bounce-(p.Ka*Z+p.Kb*m),C=z*p.nx+P*p.ny+p.surfacey+p.c2.bounce-(p.Kb*Z+p.Kc*m),v=-(p.kMassa*b+p.kMassb*C),w=-(p.kMassb*b+p.kMassc*C);v>=0&&w>=0?(b=v-Z,C=w-m,p.c1.jnAcc=v,p.c2.jnAcc=w):(v=-p.c1.nMass*b,v>=0&&p.Kb*v+C>=0?(b=v-Z,C=-m,p.c1.jnAcc=v,p.c2.jnAcc=0):(w=-p.c2.nMass*C,w>=0&&p.Kb*w+b>=0?(b=-Z,C=w-m,p.c1.jnAcc=0,p.c2.jnAcc=w):b>=0&&C>=0?(b=-Z,C=-m,p.c1.jnAcc=p.c2.jnAcc=0):(b=0,C=0))),u=b+C,d=p.nx*u,f=p.ny*u,p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=(p.rn1b*b+p.rn2b*C)*p.b2.iinertia,p.b1.angvel-=(p.rn1a*b+p.rn2a*C)*p.b1.iinertia}else p.radius!=0&&(u=(p.b2.angvel-p.b1.angvel)*p.rMass,x=p.rfric*p.c1.jnAcc,y=p.jrAcc,p.jrAcc-=u,p.jrAcc>x?p.jrAcc=x:p.jrAcc<-x&&(p.jrAcc=-x),u=p.jrAcc-y,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,y=p.c1.jnAcc,_=y-u,_<0&&(_=0),u=_-y,p.c1.jnAcc=_,d=p.nx*u,f=p.ny*u,p.b2.velx+=d*p.b2.imass,p.b2.vely+=f*p.b2.imass,p.b1.velx-=d*p.b1.imass,p.b1.vely-=f*p.b1.imass,p.b2.angvel+=p.rn1b*u*p.b2.iinertia,p.b1.angvel-=p.rn1a*u*p.b1.iinertia}a=a.next,r&&a==null&&(a=this.c_arbiters_true.head,r=!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 r=l.elt;if(!r.__velocity&&r.stiff&&r.applyImpulsePos()){l=this.live_constraints.erase(i),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}i=l,l=l.next}let o=this.c_arbiters_false.head,a=!0;for(o==null&&(o=this.c_arbiters_true.head,a=!1);o!=null;){let r=o.elt;if(r.active&&(r.immState&1)!=0)if(r.ptype==2){let p=r.c1,c=0,h=0;c=r.b2.axisy*p.lr2x-r.b2.axisx*p.lr2y,h=p.lr2x*r.b2.axisx+p.lr2y*r.b2.axisy;let u=1;c+=r.b2.posx*u,h+=r.b2.posy*u;let x=0,y=0;x=r.b1.axisy*p.lr1x-r.b1.axisx*p.lr1y,y=p.lr1x*r.b1.axisx+p.lr1y*r.b1.axisy;let _=1;x+=r.b1.posx*_,y+=r.b1.posy*_;let d=0,f=0;d=c-x,f=h-y;let z=Math.sqrt(d*d+f*f),P=r.radius-I._nape.Config.collisionSlop,Z=z-P;if(d*r.nx+f*r.ny<0&&(d=-d,f=-f,Z-=r.radius),Z<0)if(z<I._nape.Config.epsilon)r.b1.smass!=0?r.b1.posx+=I._nape.Config.epsilon*10:r.b2.posx+=I._nape.Config.epsilon*10;else{let m=1/z;d*=m,f*=m;let b=.5*(x+c),C=.5*(y+h),v=z-P;x=b-r.b1.posx,y=C-r.b1.posy,c=b-r.b2.posx,h=C-r.b2.posy;let w=f*x-d*y,O=f*c-d*h,k=r.b2.smass+O*O*r.b2.sinertia+r.b1.smass+w*w*r.b1.sinertia;if(k!=0){let g=-r.biasCoef*v/k,E=0,M=0,N=g;E=d*N,M=f*N;let S=r.b1.imass;r.b1.posx-=E*S,r.b1.posy-=M*S;let D=r.b1,j=-w*r.b1.iinertia*g;if(D.rot+=j,j*j>1e-4)D.axisx=Math.sin(D.rot),D.axisy=Math.cos(D.rot);else{let B=j*j,V=1-.5*B,Y=1-B*B/8,$=(V*D.axisx+j*D.axisy)*Y;D.axisy=(V*D.axisy-j*D.axisx)*Y,D.axisx=$}let R=r.b2.imass;r.b2.posx+=E*R,r.b2.posy+=M*R;let q=r.b2,G=O*r.b2.iinertia*g;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,y=0,_=0;if(r.ptype==0){p=r.b1.axisy*r.lnormx-r.b1.axisx*r.lnormy,c=r.lnormx*r.b1.axisx+r.lnormy*r.b1.axisy,h=r.lproj+(p*r.b1.posx+c*r.b1.posy),u=r.b2.axisy*r.c1.lr1x-r.b2.axisx*r.c1.lr1y,x=r.c1.lr1x*r.b2.axisx+r.c1.lr1y*r.b2.axisy;let z=1;if(u+=r.b2.posx*z,x+=r.b2.posy*z,r.hpc2){y=r.b2.axisy*r.c2.lr1x-r.b2.axisx*r.c2.lr1y,_=r.c2.lr1x*r.b2.axisx+r.c2.lr1y*r.b2.axisy;let P=1;y+=r.b2.posx*P,_+=r.b2.posy*P}}else{p=r.b2.axisy*r.lnormx-r.b2.axisx*r.lnormy,c=r.lnormx*r.b2.axisx+r.lnormy*r.b2.axisy,h=r.lproj+(p*r.b2.posx+c*r.b2.posy),u=r.b1.axisy*r.c1.lr1x-r.b1.axisx*r.c1.lr1y,x=r.c1.lr1x*r.b1.axisx+r.c1.lr1y*r.b1.axisy;let z=1;if(u+=r.b1.posx*z,x+=r.b1.posy*z,r.hpc2){y=r.b1.axisy*r.c2.lr1x-r.b1.axisx*r.c2.lr1y,_=r.c2.lr1x*r.b1.axisx+r.c2.lr1y*r.b1.axisy;let P=1;y+=r.b1.posx*P,_+=r.b1.posy*P}}let d=u*p+x*c-h-r.radius;d+=I._nape.Config.collisionSlop;let f=0;if(r.hpc2&&(f=y*p+_*c-h-r.radius,f+=I._nape.Config.collisionSlop),d<0||f<0){r.rev&&(p=-p,c=-c);let z=0,P=0;z=u-r.b1.posx,P=x-r.b1.posy;let Z=0,m=0;Z=u-r.b2.posx,m=x-r.b2.posy;let b=0,C=0,v=0,w=0;if(r.hpc2){b=y-r.b1.posx,C=_-r.b1.posy,v=y-r.b2.posx,w=_-r.b2.posy;let O=c*z-p*P,k=c*Z-p*m,g=c*b-p*C,E=c*v-p*w,M=r.b1.smass+r.b2.smass;r.kMassa=M+r.b1.sinertia*O*O+r.b2.sinertia*k*k,r.kMassb=M+r.b1.sinertia*O*g+r.b2.sinertia*k*E,r.kMassc=M+r.b1.sinertia*g*g+r.b2.sinertia*E*E;let N=0,S=0,D=0;N=r.kMassa,S=r.kMassb,D=r.kMassc;let j=d*r.biasCoef,R=f*r.biasCoef;for(;;){let q=0,G=0;q=j,G=R,q=-q,G=-G;let B=r.kMassa*r.kMassc-r.kMassb*r.kMassb;if(B!=B)G=0,q=G;else if(B==0)r.kMassa!=0?q/=r.kMassa:q=0,r.kMassc!=0?G/=r.kMassc:G=0;else{B=1/B;let $=B*(r.kMassc*q-r.kMassb*G);G=B*(r.kMassa*G-r.kMassb*q),q=$}if(q>=0&&G>=0){let $=(q+G)*r.b1.imass;r.b1.posx-=p*$,r.b1.posy-=c*$;let X=r.b1,H=-r.b1.iinertia*(O*q+g*G);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let F=H*H,A=1-.5*F,J=1-F*F/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)*r.b2.imass;r.b2.posx+=p*ee,r.b2.posy+=c*ee;let W=r.b2,L=r.b2.iinertia*(k*q+E*G);if(W.rot+=L,L*L>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let F=L*L,A=1-.5*F,J=1-F*F/8,Q=(A*W.axisx+L*W.axisy)*J;W.axisy=(A*W.axisy-L*W.axisx)*J,W.axisx=Q}break}q=-j/N,G=0;let V=S*q+R;if(q>=0&&V>=0){let $=(q+G)*r.b1.imass;r.b1.posx-=p*$,r.b1.posy-=c*$;let X=r.b1,H=-r.b1.iinertia*(O*q+g*G);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let F=H*H,A=1-.5*F,J=1-F*F/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)*r.b2.imass;r.b2.posx+=p*ee,r.b2.posy+=c*ee;let W=r.b2,L=r.b2.iinertia*(k*q+E*G);if(W.rot+=L,L*L>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let F=L*L,A=1-.5*F,J=1-F*F/8,Q=(A*W.axisx+L*W.axisy)*J;W.axisy=(A*W.axisy-L*W.axisx)*J,W.axisx=Q}break}q=0,G=-R/D;let Y=S*G+j;if(G>=0&&Y>=0){let $=(q+G)*r.b1.imass;r.b1.posx-=p*$,r.b1.posy-=c*$;let X=r.b1,H=-r.b1.iinertia*(O*q+g*G);if(X.rot+=H,H*H>1e-4)X.axisx=Math.sin(X.rot),X.axisy=Math.cos(X.rot);else{let F=H*H,A=1-.5*F,J=1-F*F/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)*r.b2.imass;r.b2.posx+=p*ee,r.b2.posy+=c*ee;let W=r.b2,L=r.b2.iinertia*(k*q+E*G);if(W.rot+=L,L*L>1e-4)W.axisx=Math.sin(W.rot),W.axisy=Math.cos(W.rot);else{let F=L*L,A=1-.5*F,J=1-F*F/8,Q=(A*W.axisx+L*W.axisy)*J;W.axisy=(A*W.axisy-L*W.axisx)*J,W.axisx=Q}break}break}}else{let O=c*z-p*P,k=c*Z-p*m,g=r.b2.smass+k*k*r.b2.sinertia+r.b1.smass+O*O*r.b1.sinertia;if(g!=0){let E=-r.biasCoef*d/g,M=0,N=0,S=E;M=p*S,N=c*S;let D=r.b1.imass;r.b1.posx-=M*D,r.b1.posy-=N*D;let j=r.b1,R=-O*r.b1.iinertia*E;if(j.rot+=R,R*R>1e-4)j.axisx=Math.sin(j.rot),j.axisy=Math.cos(j.rot);else{let V=R*R,Y=1-.5*V,$=1-V*V/8,X=(Y*j.axisx+R*j.axisy)*$;j.axisy=(Y*j.axisy-R*j.axisx)*$,j.axisx=X}let q=r.b2.imass;r.b2.posx+=M*q,r.b2.posy+=N*q;let G=r.b2,B=k*r.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,a&&o==null&&(o=this.c_arbiters_true.head,a=!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 a=l.elt;if(a.ignore&&a.pair_exists(n.id,s.id)){i=!0;break}l=l.next}let o;if(i)o=!1;else{let a=e;for(;a!=null&&a.group==null;)a.ishape!=null?a=a.ishape.body:a.icompound!=null?a=a.icompound.compound:a=a.ibody.compound;let r=a==null?null:a.group,p;if(r==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(;r!=null&&h!=null;){if(r==h){u=r.ignore;break}r.depth<h.depth?h=h.group:r=r.group}p=u}}o=!p}if(o){let a;if(e.sensorEnabled||t.sensorEnabled){let r=e.filter,p=t.filter;a=(r.sensorMask&p.sensorGroup)!=0&&(p.sensorMask&r.sensorGroup)!=0}else a=!1;if(a)return 2;{let r;if(e.fluidEnabled||t.fluidEnabled){let p=e.filter,c=t.filter;r=(p.fluidMask&c.fluidGroup)!=0&&(c.fluidMask&p.fluidGroup)!=0}else r=!1;if(r&&!(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,a=t.body,r;r=!1;let p=o.constraints.head;for(;p!=null;){let u=p.elt;if(u.ignore&&u.pair_exists(o.id,a.id)){r=!0;break}p=p.next}let c,h;if(r)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,y;if(x==null)y=!1;else{let _=t;for(;_!=null&&_.group==null;)_.ishape!=null?_=_.ishape.body:_.icompound!=null?_=_.icompound.compound:_=_.ibody.compound;let d=_==null?null:_.group;if(d==null)y=!1;else{let f=!1;for(;x!=null&&d!=null;){if(x==d){f=x.ignore;break}x.depth<d.depth?d=d.group:x=x.group}y=f}}h=!y}if(h){let u;if(e.sensorEnabled||t.sensorEnabled){let x=e.filter,y=t.filter;u=(x.sensorMask&y.sensorGroup)!=0&&(y.sensorMask&x.sensorGroup)!=0}else u=!1;if(u)c=2;else{let x;if(e.fluidEnabled||t.fluidEnabled){let y=e.filter,_=t.filter;x=(y.fluidMask&_.fluidGroup)!=0&&(_.fluidMask&y.fluidGroup)!=0}else x=!1;if(x&&!(o.imass==0&&a.imass==0&&o.iinertia==0&&a.iinertia==0))c=0;else{let y=e.filter,_=t.filter;c=(y.collisionMask&_.collisionGroup)!=0&&(_.collisionMask&y.collisionGroup)!=0&&!(o.imass==0&&a.imass==0&&o.iinertia==0&&a.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 y=u==t;if(c==0){let _;if(s==null){let Z=null,b=(o.arbiters.length<a.arbiters.length?o:a).arbiters.head;for(;b!=null;){let C=b.elt;if(C.id==u.id&&C.di==x.id){Z=C;break}b=b.next}_=Z}else _=s;let d=_==null,f,z=!1;if(d)Pt.zpp_pool==null?f=new Pt:(f=Pt.zpp_pool,Pt.zpp_pool=f.next,f.next=null);else if(_.fluidarb==null){_.cleared=!0;{let m=_.b1.arbiters,b=null,C=m.head,v=!1;for(;C!=null;){if(C.elt==_){let w,O;b==null?(w=m.head,O=w.next,m.head=O,m.head==null&&(m.pushmod=!0)):(w=b.next,O=w.next,b.next=O,O==null&&(m.pushmod=!0));let k=w;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,m.modified=!0,m.length--,m.pushmod=!0,v=!0;break}b=C,C=C.next}}{let m=_.b2.arbiters,b=null,C=m.head,v=!1;for(;C!=null;){if(C.elt==_){let w,O;b==null?(w=m.head,O=w.next,m.head=O,m.head==null&&(m.pushmod=!0)):(w=b.next,O=w.next,b.next=O,O==null&&(m.pushmod=!0));let k=w;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,m.modified=!0,m.length--,m.pushmod=!0,v=!0;break}b=C,C=C.next}}_.pair!=null&&(_.pair.arb=null,_.pair=null),_.active=!1,this.f_arbiters.modified=!0,Pt.zpp_pool==null?f=new Pt:(f=Pt.zpp_pool,Pt.zpp_pool=f.next,f.next=null),f.intchange=!0,d=!0,z=!0}else f=_.fluidarb;let P=4;if(d||f.stamp!=this.stamp||i)if(f.stamp=this.stamp,Ee.flowCollide(u,x,f)){if(d){let Z=x.id;f.b1=e.body,f.ws1=e,f.b2=t.body,f.ws2=t,f.id=u.id,f.di=Z;let m=f.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=f;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=f.b2.arbiters,w;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?w=new I._zpp.util.ZNPNode_ZPP_Arbiter:(w=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=w.next,w.next=null),w.elt=f;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++,f.active=!0,f.present=0,f.cleared=!1,f.sleeping=!1,f.fresh=!1,f.presentable=!1,f.nx=0,f.ny=1,f.dampx=0,f.dampy=0,f.adamp=0;let k=this.f_arbiters,g;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?g=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(g=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=g.next,g.next=null),g.elt=f;let E=g;E.next=k.head,k.head=E,k.modified=!0,k.length++,f.fresh=!z}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 Z=!1,m=f.ws1.id>f.ws2.id?f.ws2:f.ws1,b=f.ws1.id>f.ws2.id?f.ws1:f.ws2,C=this.mrca1;for(;C.head!=null;){let g=C.head;C.head=g.next;let E=g;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E,C.head==null&&(C.pushmod=!0),C.modified=!0,C.length--}C.pushmod=!0;let v=this.mrca2;for(;v.head!=null;){let g=v.head;v.head=g.next;let E=g;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E,v.head==null&&(v.pushmod=!0),v.modified=!0,v.length--}if(v.pushmod=!0,m.cbSet!=null){let g=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=m;let M=E;M.next=g.head,g.head=M,g.modified=!0,g.length++}if(m.body.cbSet!=null){let g=this.mrca1,E=m.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 N=M;N.next=g.head,g.head=N,g.modified=!0,g.length++}if(b.cbSet!=null){let g=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=g.head,g.head=M,g.modified=!0,g.length++}if(b.body.cbSet!=null){let g=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 N=M;N.next=g.head,g.head=N,g.modified=!0,g.length++}let w=m.body.compound,O=b.body.compound;for(;w!=O;){let g=w==null?0:w.depth,E=O==null?0:O.depth;if(g<E){if(O.cbSet!=null){let M=this.mrca2,N;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new I._zpp.util.ZNPNode_ZPP_Interactor:(N=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=O;let S=N;S.next=M.head,M.head=S,M.modified=!0,M.length++}O=O.compound}else{if(w.cbSet!=null){let M=this.mrca1,N;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new I._zpp.util.ZNPNode_ZPP_Interactor:(N=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=w;let S=N;S.next=M.head,M.head=S,M.modified=!0,M.length++}w=w.compound}}let k=this.mrca1.head;for(;k!=null;){let g=k.elt,E=this.mrca2.head;for(;E!=null;){let M=E.elt,N=g.cbSet,S=M.cbSet,D=N.manager,j=null,q=(N.cbpairs.length<S.cbpairs.length?N.cbpairs:S.cbpairs).head;for(;q!=null;){let L=q.elt;if(L.a==N&&L.b==S||L.a==S&&L.b==N){j=L;break}q=q.next}if(j==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=!0,dt.setlt(N,S)?(L.a=N,L.b=S):(L.a=S,L.b=N),j=L,N.cbpairs.add(j),S!=N&&S.cbpairs.add(j)}if(j.zip_listeners&&(j.zip_listeners=!1,j.__validate()),j.listeners.head==null){E=E.next;continue}let G=null,B=null,V=this.prelisteners;for(;V.head!=null;){let L=V.head;V.head=L.next;let F=L;F.elt=null,F.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=F,V.head==null&&(V.pushmod=!0),V.modified=!0,V.length--}V.pushmod=!0;let Y=null,$=N.manager,X=null,ee=(N.cbpairs.length<S.cbpairs.length?N.cbpairs:S.cbpairs).head;for(;ee!=null;){let L=ee.elt;if(L.a==N&&L.b==S||L.a==S&&L.b==N){X=L;break}ee=ee.next}if(X==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=!0,dt.setlt(N,S)?(L.a=N,L.b=S):(L.a=S,L.b=N),X=L,N.cbpairs.add(X),S!=N&&S.cbpairs.add(X)}X.zip_listeners&&(X.zip_listeners=!1,X.__validate());let W=X.listeners.head;for(;W!=null;){let L=W.elt;if(L.event==5&&(L.itype&P)!=0){let F=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=L;let J=A;Y==null?(J.next=F.head,F.head=J):(J.next=Y.next,Y.next=J),F.pushmod=F.modified=!0,F.length++,Y=J,Z=Z||!L.pure}W=W.next}if(this.prelisteners.head==null){E=E.next;continue}if(G=I._zpp.phys.ZPP_Interactor.get(g,M),G==null&&(B=Kt.get(g,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}f.mutable=!0,f.wrap_position!=null&&(f.wrap_position.zpp_inner._immutable=!1);let L=f.active;f.active=!0;let F=!1;this.precb.zpp_inner.pre_arbiter=f,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,ne=G.int2,re,se=J.options1,ie=K.cbTypes;if(se.nonemptyintersection(ie,se.includes)&&!se.nonemptyintersection(ie,se.excludes)){let oe=J.options2,he=ne.cbTypes;re=oe.nonemptyintersection(he,oe.includes)&&!oe.nonemptyintersection(he,oe.excludes)}else re=!1;re?(Q.int1=K,Q.int2=ne):(Q.int1=ne,Q.int2=K),this.precb.zpp_inner.pre_swapped=g!=this.precb.zpp_inner.int1;let ae=J.handlerp(this.precb);if(ae!=null){let oe;U.PreFlag_ACCEPT==null&&(U.internal=!0,U.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,U.internal=!1),ae==U.PreFlag_ACCEPT?oe=5:(U.PreFlag_ACCEPT_ONCE==null&&(U.internal=!0,U.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,U.internal=!1),ae==U.PreFlag_ACCEPT_ONCE?oe=1:(U.PreFlag_IGNORE==null&&(U.internal=!0,U.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,U.internal=!1),oe=ae==U.PreFlag_IGNORE?6:2)),f.immState=oe}A=A.next}if(f.mutable=!1,f.wrap_position!=null&&(f.wrap_position.zpp_inner._immutable=!0),f.active=L,G!=null){let J=this.prelisteners.head;for(;J!=null;)J.elt.itype==7&&(G.COLLISIONstate=f.immState,G.SENSORstate=f.immState),G.FLUIDstate=f.immState,J=J.next}}else G==null?(f.immState&4)==0&&(f.immState=1):f.immState=G.FLUIDstate;E=E.next}k=k.next}if(Z&&(f.immState&4)==0){if(f.b1.type==2){let g=f.b1;g.world||(g.component.waket=this.stamp+(this.midstep?0:1),g.type==3&&(g.kinematicDelaySleep=!0),g.component.sleeping&&this.really_wake(g,!1))}if(f.b1.type==2){let g=f.b2;g.world||(g.component.waket=this.stamp+(this.midstep?0:1),g.type==3&&(g.kinematicDelaySleep=!0),g.component.sleeping&&this.really_wake(g,!1))}}}if((f.immState&1)!=0){if(f.b1.type==2&&f.b1.component.sleeping){let Z=f.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(f.b2.type==2&&f.b2.component.sleeping){let Z=f.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(f.sleeping){f.sleeping=!1;let Z=this.f_arbiters,m;I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool==null?m=new I._zpp.util.ZNPNode_ZPP_FluidArbiter:(m=I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_FluidArbiter.zpp_pool=m.next,m.next=null),m.elt=f;let b=m;b.next=Z.head,Z.head=b,Z.modified=!0,Z.length++}l=f}else if(d){let Z=f;Z.next=Pt.zpp_pool,Pt.zpp_pool=Z,l=null}else l=f;else l=f}else if(c==1){let _=n?this.c_arbiters_true:this.c_arbiters_false,d;if(s==null){let m=null,C=(o.arbiters.length<a.arbiters.length?o:a).arbiters.head;for(;C!=null;){let v=C.elt;if(v.id==u.id&&v.di==x.id){m=v;break}C=C.next}d=m}else d=s;let f=d==null,z,P=!1;if(f)ut.zpp_pool==null?z=new ut:(z=ut.zpp_pool,ut.zpp_pool=z.next,z.next=null),z.stat=n;else if(d.colarb==null){d.cleared=!0;{let b=d.b1.arbiters,C=null,v=b.head,w=!1;for(;v!=null;){if(v.elt==d){let O,k;C==null?(O=b.head,k=O.next,b.head=k,b.head==null&&(b.pushmod=!0)):(O=C.next,k=O.next,C.next=k,k==null&&(b.pushmod=!0));let g=O;g.elt=null,g.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=g,b.modified=!0,b.length--,b.pushmod=!0,w=!0;break}C=v,v=v.next}}{let b=d.b2.arbiters,C=null,v=b.head,w=!1;for(;v!=null;){if(v.elt==d){let O,k;C==null?(O=b.head,k=O.next,b.head=k,b.head==null&&(b.pushmod=!0)):(O=C.next,k=O.next,C.next=k,k==null&&(b.pushmod=!0));let g=O;g.elt=null,g.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=g,b.modified=!0,b.length--,b.pushmod=!0,w=!0;break}C=v,v=v.next}}d.pair!=null&&(d.pair.arb=null,d.pair=null),d.active=!1,this.f_arbiters.modified=!0,ut.zpp_pool==null?z=new ut:(z=ut.zpp_pool,ut.zpp_pool=z.next,z.next=null),z.intchange=!0,z.stat=n,f=!0,P=!0}else z=d.colarb,y=u!=z.s1,z.stat!=n&&(z.stat=n,z.sleeping||((n?this.c_arbiters_false:this.c_arbiters_true).remove(z),_.add(z)));let Z=1;if(f||z.stamp!=this.stamp||i)if(z.stamp=this.stamp,Ee.contactCollide(u,x,z,y)){if(f){let m=x.id;z.b1=e.body,z.ws1=e,z.b2=t.body,z.ws2=t,z.id=u.id,z.di=m;let b=z.b1.arbiters,C;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?C=new I._zpp.util.ZNPNode_ZPP_Arbiter:(C=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=C.next,C.next=null),C.elt=z;let v=C;v.next=b.head,b.head=v,b.modified=!0,b.length++;let w=z.b2.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=z;let k=O;k.next=w.head,w.head=k,w.modified=!0,w.length++,z.active=!0,z.present=0,z.cleared=!1,z.sleeping=!1,z.fresh=!1,z.presentable=!1,z.s1=e,z.s2=t,z.userdef_restitution||(z.s1.material.elasticity<=-1/0||z.s2.material.elasticity<=-1/0?z.restitution=0:z.s1.material.elasticity>=1/0||z.s2.material.elasticity>=1/0?z.restitution=1:z.restitution=(z.s1.material.elasticity+z.s2.material.elasticity)/2,z.restitution<0&&(z.restitution=0),z.restitution>1&&(z.restitution=1)),z.userdef_dyn_fric||(z.dyn_fric=Math.sqrt(z.s1.material.dynamicFriction*z.s2.material.dynamicFriction)),z.userdef_stat_fric||(z.stat_fric=Math.sqrt(z.s1.material.staticFriction*z.s2.material.staticFriction)),z.userdef_rfric||(z.rfric=Math.sqrt(z.s1.material.rollingFriction*z.s2.material.rollingFriction));let g;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?g=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(g=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=g.next,g.next=null),g.elt=z;let E=g;E.next=_.head,_.head=E,_.modified=!0,_.length++,z.fresh=!P}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 m=!1,b=z.ws1.id>z.ws2.id?z.ws2:z.ws1,C=z.ws1.id>z.ws2.id?z.ws1:z.ws2,v=this.mrca1;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--}v.pushmod=!0;let w=this.mrca2;for(;w.head!=null;){let E=w.head;w.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,w.head==null&&(w.pushmod=!0),w.modified=!0,w.length--}if(w.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 N=M;N.next=E.head,E.head=N,E.modified=!0,E.length++}if(b.body.cbSet!=null){let E=this.mrca1,M=b.body,N;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new I._zpp.util.ZNPNode_ZPP_Interactor:(N=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=M;let S=N;S.next=E.head,E.head=S,E.modified=!0,E.length++}if(C.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=C;let N=M;N.next=E.head,E.head=N,E.modified=!0,E.length++}if(C.body.cbSet!=null){let E=this.mrca2,M=C.body,N;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new I._zpp.util.ZNPNode_ZPP_Interactor:(N=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=M;let S=N;S.next=E.head,E.head=S,E.modified=!0,E.length++}let O=b.body.compound,k=C.body.compound;for(;O!=k;){let E=O==null?0:O.depth,M=k==null?0:k.depth;if(E<M){if(k.cbSet!=null){let N=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=k;let D=S;D.next=N.head,N.head=D,N.modified=!0,N.length++}k=k.compound}else{if(O.cbSet!=null){let N=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=O;let D=S;D.next=N.head,N.head=D,N.modified=!0,N.length++}O=O.compound}}let g=this.mrca1.head;for(;g!=null;){let E=g.elt,M=this.mrca2.head;for(;M!=null;){let N=M.elt,S=E.cbSet,D=N.cbSet,j=S.manager,R=null,G=(S.cbpairs.length<D.cbpairs.length?S.cbpairs:D.cbpairs).head;for(;G!=null;){let F=G.elt;if(F.a==S&&F.b==D||F.a==D&&F.b==S){R=F;break}G=G.next}if(R==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,D)?(F.a=S,F.b=D):(F.a=D,F.b=S),R=F,S.cbpairs.add(R),D!=S&&D.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 F=Y.head;Y.head=F.next;let A=F;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=S.manager,H=null,W=(S.cbpairs.length<D.cbpairs.length?S.cbpairs:D.cbpairs).head;for(;W!=null;){let F=W.elt;if(F.a==S&&F.b==D||F.a==D&&F.b==S){H=F;break}W=W.next}if(H==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,D)?(F.a=S,F.b=D):(F.a=D,F.b=S),H=F,S.cbpairs.add(H),D!=S&&D.cbpairs.add(H)}H.zip_listeners&&(H.zip_listeners=!1,H.__validate());let L=H.listeners.head;for(;L!=null;){let F=L.elt;if(F.event==5&&(F.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=F;let Q=J;$==null?(Q.next=A.head,A.head=Q):(Q.next=$.next,$.next=Q),A.pushmod=A.modified=!0,A.length++,$=Q,m=m||!F.pure}L=L.next}if(this.prelisteners.head==null){M=M.next;continue}if(B=I._zpp.phys.ZPP_Interactor.get(E,N),B==null&&(V=Kt.get(E,N),this.add_callbackset(V)),B==null||(B.COLLISIONstamp!=this.stamp||i)&&(B.COLLISIONstate&4)==0){if(V!=null&&(B=V),B!=null){let ie=this.prelisteners.head;for(;ie!=null;)ie.elt.itype==7?(B.COLLISIONstamp=this.stamp,B.SENSORstamp=this.stamp,B.FLUIDstamp=this.stamp):B.COLLISIONstamp=this.stamp,ie=ie.next}z.mutable=!0,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!1),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!1);let F=z.active;z.active=!0;let A=!1,J=!0,Q=null,K=null,ne=z.innards.next;z.hc2=!1;let re=z.contacts.next;for(;re!=null;){let ie=re;if(ie.stamp+I._nape.Config.arbiterExpirationDelay<z.stamp){let he=z.contacts,pe,ce;Q==null?(pe=he.next,ce=pe.next,he.next=ce,he.next==null&&(he.pushmod=!0)):(pe=Q.next,ce=pe.next,Q.next=ce,ce==null&&(he.pushmod=!0)),pe._inuse=!1,he.modified=!0,he.length--,he.pushmod=!0,re=ce;let te=z.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,ne=de;let me=ie;me.arbiter=null,me.next=we.zpp_pool,we.zpp_pool=me;continue}let ae=ie.inner,oe=ie.active;ie.active=ie.stamp==z.stamp,ie.active&&(J?(J=!1,z.c1=ae,z.oc1=ie):(z.hc2=!0,z.c2=ae,z.oc2=ie)),oe!=ie.active&&(z.contacts.modified=!0),Q=re,K=ne,ne=ne.next,re=re.next}if(z.hc2){if(z.hpc2=!0,z.oc1.posOnly){let ie=z.c1;z.c1=z.c2,z.c2=ie;let ae=z.oc1;z.oc1=z.oc2,z.oc2=ae,z.hc2=!1}else z.oc2.posOnly&&(z.hc2=!1);z.oc1.posOnly&&(J=!0)}else z.hpc2=!1;this.precb.zpp_inner.pre_arbiter=z,this.precb.zpp_inner.set=B;let se=this.prelisteners.head;for(;se!=null;){let ie=se.elt;this.precb.zpp_inner.listener=ie;let ae=this.precb.zpp_inner,oe=B.int1,he=B.int2,pe,ce=ie.options1,te=oe.cbTypes;if(ce.nonemptyintersection(te,ce.includes)&&!ce.nonemptyintersection(te,ce.excludes)){let de=ie.options2,me=he.cbTypes;pe=de.nonemptyintersection(me,de.includes)&&!de.nonemptyintersection(me,de.excludes)}else pe=!1;pe?(ae.int1=oe,ae.int2=he):(ae.int1=he,ae.int2=oe),this.precb.zpp_inner.pre_swapped=E!=this.precb.zpp_inner.int1;let ue=ie.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)),z.immState=de}se=se.next}if(z.mutable=!1,z.wrap_normal!=null&&(z.wrap_normal.zpp_inner._immutable=!0),z.wrap_contacts!=null&&(z.wrap_contacts.zpp_inner.immutable=!0),z.active=F,B!=null){let ie=this.prelisteners.head;for(;ie!=null;)ie.elt.itype==7?(B.COLLISIONstate=z.immState,B.SENSORstate=z.immState,B.FLUIDstate=z.immState):B.COLLISIONstate=z.immState,ie=ie.next}}else B==null?(z.immState&4)==0&&(z.immState=1):z.immState=B.COLLISIONstate;M=M.next}g=g.next}if(m&&(z.immState&4)==0){if(z.b1.type==2){let E=z.b1;E.world||(E.component.waket=this.stamp+(this.midstep?0:1),E.type==3&&(E.kinematicDelaySleep=!0),E.component.sleeping&&this.really_wake(E,!1))}if(z.b1.type==2){let E=z.b2;E.world||(E.component.waket=this.stamp+(this.midstep?0:1),E.type==3&&(E.kinematicDelaySleep=!0),E.component.sleeping&&this.really_wake(E,!1))}}}if((z.immState&1)!=0){if(z.b1.type==2&&z.b1.component.sleeping){let m=z.b1;m.world||(m.component.waket=this.stamp+(this.midstep?0:1),m.type==3&&(m.kinematicDelaySleep=!0),m.component.sleeping&&this.really_wake(m,!1))}if(z.b2.type==2&&z.b2.component.sleeping){let m=z.b2;m.world||(m.component.waket=this.stamp+(this.midstep?0:1),m.type==3&&(m.kinematicDelaySleep=!0),m.component.sleeping&&this.really_wake(m,!1))}}if(z.sleeping){z.sleeping=!1;let m;I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool==null?m=new I._zpp.util.ZNPNode_ZPP_ColArbiter:(m=I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_ColArbiter.zpp_pool=m.next,m.next=null),m.elt=z;let b=m;b.next=_.head,_.head=b,_.modified=!0,_.length++}l=z}else if(f){let m=z;m.userdef_dyn_fric=!1,m.userdef_stat_fric=!1,m.userdef_restitution=!1,m.userdef_rfric=!1,m.__ref_edge1=m.__ref_edge2=null,m.next=ut.zpp_pool,ut.zpp_pool=m,l=null}else l=z;else l=z}else{let _;if(s==null){let Z=null,b=(o.arbiters.length<a.arbiters.length?o:a).arbiters.head;for(;b!=null;){let C=b.elt;if(C.id==u.id&&C.di==x.id){Z=C;break}b=b.next}_=Z}else _=s;let d=_==null,f,z=!1;if(d)Ot.zpp_pool==null?f=new Ot:(f=Ot.zpp_pool,Ot.zpp_pool=f.next,f.next=null);else if(_.sensorarb==null){_.cleared=!0;{let m=_.b1.arbiters,b=null,C=m.head,v=!1;for(;C!=null;){if(C.elt==_){let w,O;b==null?(w=m.head,O=w.next,m.head=O,m.head==null&&(m.pushmod=!0)):(w=b.next,O=w.next,b.next=O,O==null&&(m.pushmod=!0));let k=w;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,m.modified=!0,m.length--,m.pushmod=!0,v=!0;break}b=C,C=C.next}}{let m=_.b2.arbiters,b=null,C=m.head,v=!1;for(;C!=null;){if(C.elt==_){let w,O;b==null?(w=m.head,O=w.next,m.head=O,m.head==null&&(m.pushmod=!0)):(w=b.next,O=w.next,b.next=O,O==null&&(m.pushmod=!0));let k=w;k.elt=null,k.next=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=k,m.modified=!0,m.length--,m.pushmod=!0,v=!0;break}b=C,C=C.next}}_.pair!=null&&(_.pair.arb=null,_.pair=null),_.active=!1,this.f_arbiters.modified=!0,Ot.zpp_pool==null?f=new Ot:(f=Ot.zpp_pool,Ot.zpp_pool=f.next,f.next=null),f.intchange=!0,d=!0,z=!0}else f=_.sensorarb;let P=2;if(d||f.stamp!=this.stamp||i)if(f.stamp=this.stamp,Ee.testCollide(u,x)){if(d){let Z=x.id;f.b1=e.body,f.ws1=e,f.b2=t.body,f.ws2=t,f.id=u.id,f.di=Z;let m=f.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=f;let C=b;C.next=m.head,m.head=C,m.modified=!0,m.length++;let v=f.b2.arbiters,w;I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool==null?w=new I._zpp.util.ZNPNode_ZPP_Arbiter:(w=I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_Arbiter.zpp_pool=w.next,w.next=null),w.elt=f;let O=w;O.next=v.head,v.head=O,v.modified=!0,v.length++,f.active=!0,f.present=0,f.cleared=!1,f.sleeping=!1,f.fresh=!1,f.presentable=!1;let k=this.s_arbiters,g;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?g=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(g=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=g.next,g.next=null),g.elt=f;let E=g;E.next=k.head,k.head=E,k.modified=!0,k.length++,f.fresh=!z}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 Z=!1,m=f.ws1.id>f.ws2.id?f.ws2:f.ws1,b=f.ws1.id>f.ws2.id?f.ws1:f.ws2,C=this.mrca1;for(;C.head!=null;){let g=C.head;C.head=g.next;let E=g;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E,C.head==null&&(C.pushmod=!0),C.modified=!0,C.length--}C.pushmod=!0;let v=this.mrca2;for(;v.head!=null;){let g=v.head;v.head=g.next;let E=g;E.elt=null,E.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=E,v.head==null&&(v.pushmod=!0),v.modified=!0,v.length--}if(v.pushmod=!0,m.cbSet!=null){let g=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=m;let M=E;M.next=g.head,g.head=M,g.modified=!0,g.length++}if(m.body.cbSet!=null){let g=this.mrca1,E=m.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 N=M;N.next=g.head,g.head=N,g.modified=!0,g.length++}if(b.cbSet!=null){let g=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=g.head,g.head=M,g.modified=!0,g.length++}if(b.body.cbSet!=null){let g=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 N=M;N.next=g.head,g.head=N,g.modified=!0,g.length++}let w=m.body.compound,O=b.body.compound;for(;w!=O;){let g=w==null?0:w.depth,E=O==null?0:O.depth;if(g<E){if(O.cbSet!=null){let M=this.mrca2,N;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new I._zpp.util.ZNPNode_ZPP_Interactor:(N=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=O;let S=N;S.next=M.head,M.head=S,M.modified=!0,M.length++}O=O.compound}else{if(w.cbSet!=null){let M=this.mrca1,N;I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool==null?N=new I._zpp.util.ZNPNode_ZPP_Interactor:(N=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=N.next,N.next=null),N.elt=w;let S=N;S.next=M.head,M.head=S,M.modified=!0,M.length++}w=w.compound}}let k=this.mrca1.head;for(;k!=null;){let g=k.elt,E=this.mrca2.head;for(;E!=null;){let M=E.elt,N=g.cbSet,S=M.cbSet,D=N.manager,j=null,q=(N.cbpairs.length<S.cbpairs.length?N.cbpairs:S.cbpairs).head;for(;q!=null;){let L=q.elt;if(L.a==N&&L.b==S||L.a==S&&L.b==N){j=L;break}q=q.next}if(j==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=!0,dt.setlt(N,S)?(L.a=N,L.b=S):(L.a=S,L.b=N),j=L,N.cbpairs.add(j),S!=N&&S.cbpairs.add(j)}if(j.zip_listeners&&(j.zip_listeners=!1,j.__validate()),j.listeners.head==null){E=E.next;continue}let G=null,B=null,V=this.prelisteners;for(;V.head!=null;){let L=V.head;V.head=L.next;let F=L;F.elt=null,F.next=I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool,I._zpp.util.ZNPNode_ZPP_InteractionListener.zpp_pool=F,V.head==null&&(V.pushmod=!0),V.modified=!0,V.length--}V.pushmod=!0;let Y=null,$=N.manager,X=null,ee=(N.cbpairs.length<S.cbpairs.length?N.cbpairs:S.cbpairs).head;for(;ee!=null;){let L=ee.elt;if(L.a==N&&L.b==S||L.a==S&&L.b==N){X=L;break}ee=ee.next}if(X==null){let L;Ne.zpp_pool==null?L=new Ne:(L=Ne.zpp_pool,Ne.zpp_pool=L.next,L.next=null),L.zip_listeners=!0,dt.setlt(N,S)?(L.a=N,L.b=S):(L.a=S,L.b=N),X=L,N.cbpairs.add(X),S!=N&&S.cbpairs.add(X)}X.zip_listeners&&(X.zip_listeners=!1,X.__validate());let W=X.listeners.head;for(;W!=null;){let L=W.elt;if(L.event==5&&(L.itype&P)!=0){let F=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=L;let J=A;Y==null?(J.next=F.head,F.head=J):(J.next=Y.next,Y.next=J),F.pushmod=F.modified=!0,F.length++,Y=J,Z=Z||!L.pure}W=W.next}if(this.prelisteners.head==null){E=E.next;continue}if(G=I._zpp.phys.ZPP_Interactor.get(g,M),G==null&&(B=Kt.get(g,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 L=f.active;f.active=!0;let F=!1;this.precb.zpp_inner.pre_arbiter=f,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,ne=G.int2,re,se=J.options1,ie=K.cbTypes;if(se.nonemptyintersection(ie,se.includes)&&!se.nonemptyintersection(ie,se.excludes)){let oe=J.options2,he=ne.cbTypes;re=oe.nonemptyintersection(he,oe.includes)&&!oe.nonemptyintersection(he,oe.excludes)}else re=!1;re?(Q.int1=K,Q.int2=ne):(Q.int1=ne,Q.int2=K),this.precb.zpp_inner.pre_swapped=g!=this.precb.zpp_inner.int1;let ae=J.handlerp(this.precb);if(ae!=null){let oe;U.PreFlag_ACCEPT==null&&(U.internal=!0,U.PreFlag_ACCEPT=new I._nape.callbacks.PreFlag,U.internal=!1),ae==U.PreFlag_ACCEPT?oe=5:(U.PreFlag_ACCEPT_ONCE==null&&(U.internal=!0,U.PreFlag_ACCEPT_ONCE=new I._nape.callbacks.PreFlag,U.internal=!1),ae==U.PreFlag_ACCEPT_ONCE?oe=1:(U.PreFlag_IGNORE==null&&(U.internal=!0,U.PreFlag_IGNORE=new I._nape.callbacks.PreFlag,U.internal=!1),oe=ae==U.PreFlag_IGNORE?6:2)),f.immState=oe}A=A.next}if(f.active=L,G!=null){let J=this.prelisteners.head;for(;J!=null;)J.elt.itype==7?(G.COLLISIONstate=f.immState,G.SENSORstate=f.immState,G.FLUIDstate=f.immState):G.SENSORstate=f.immState,J=J.next}}else G==null?(f.immState&4)==0&&(f.immState=1):f.immState=G.SENSORstate;E=E.next}k=k.next}if(Z&&(f.immState&4)==0){if(f.b1.type!=1){let g=f.b1;g.world||(g.component.waket=this.stamp+(this.midstep?0:1),g.type==3&&(g.kinematicDelaySleep=!0),g.component.sleeping&&this.really_wake(g,!1))}if(f.b2.type!=1){let g=f.b2;g.world||(g.component.waket=this.stamp+(this.midstep?0:1),g.type==3&&(g.kinematicDelaySleep=!0),g.component.sleeping&&this.really_wake(g,!1))}}}if(f.sleeping){f.sleeping=!1;let Z=this.s_arbiters,m;I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool==null?m=new I._zpp.util.ZNPNode_ZPP_SensorArbiter:(m=I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool,I._zpp.util.ZNPNode_ZPP_SensorArbiter.zpp_pool=m.next,m.next=null),m.elt=f;let b=m;b.next=Z.head,Z.head=b,Z.modified=!0,Z.length++}l=f}else if(d){let Z=f;Z.next=Ot.zpp_pool,Ot.zpp_pool=Z,l=null}else l=f;else l=f}}return l}MRCA_chains(e,t){let n=this.mrca1;for(;n.head!=null;){let o=n.head;n.head=o.next;let a=o;a.elt=null,a.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a,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 a=o;a.elt=null,a.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let o=this.mrca1,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=e;let r=a;r.next=o.head,o.head=r,o.modified=!0,o.length++}if(e.body.cbSet!=null){let o=this.mrca1,a=e.body,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=a;let p=r;p.next=o.head,o.head=p,o.modified=!0,o.length++}if(t.cbSet!=null){let o=this.mrca2,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=t;let r=a;r.next=o.head,o.head=r,o.modified=!0,o.length++}if(t.body.cbSet!=null){let o=this.mrca2,a=t.body,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=a;let p=r;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,a=l==null?0:l.depth;if(o<a){if(l.cbSet!=null){let r=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=r.head,r.head=c,r.modified=!0,r.length++}l=l.compound}else{if(i.cbSet!=null){let r=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=r.head,r.head=c,r.modified=!0,r.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 a=o;a.elt=null,a.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a,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 a=o;a.elt=null,a.next=I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool,I._zpp.util.ZNPNode_ZPP_Interactor.zpp_pool=a,s.head==null&&(s.pushmod=!0),s.modified=!0,s.length--}if(s.pushmod=!0,e.cbSet!=null){let o=this.mrca1,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=e;let r=a;r.next=o.head,o.head=r,o.modified=!0,o.length++}if(e.body.cbSet!=null){let o=this.mrca1,a=e.body,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=a;let p=r;p.next=o.head,o.head=p,o.modified=!0,o.length++}if(t.cbSet!=null){let o=this.mrca2,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=t;let r=a;r.next=o.head,o.head=r,o.modified=!0,o.length++}if(t.body.cbSet!=null){let o=this.mrca2,a=t.body,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=a;let p=r;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,a=l==null?0:l.depth;if(o<a){if(l.cbSet!=null){let r=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=r.head,r.head=c,r.modified=!0,r.length++}l=l.compound}else{if(i.cbSet!=null){let r=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=r.head,r.head=c,r.modified=!0,r.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 a=1;o.localCOMx+=o.lverts.next.next.x*a,o.localCOMy+=o.lverts.next.next.y*a;let r=.5;o.localCOMx*=r,o.localCOMy*=r}else{o.localCOMx=0,o.localCOMy=0;let a=0,r=o.lverts.next,p=r;r=r.next;let c=r;for(r=r.next;r!=null;){let d=r;a+=c.x*(d.y-p.y);let f=d.y*c.x-d.x*c.y;o.localCOMx+=(c.x+d.x)*f,o.localCOMy+=(c.y+d.y)*f,p=c,c=d,r=r.next}r=o.lverts.next;let h=r;a+=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,r=r.next;let x=r;a+=c.x*(x.y-p.y);let y=x.y*c.x-x.x*c.y;o.localCOMx+=(c.x+x.x)*y,o.localCOMy+=(c.y+x.y)*y,a=1/(3*a);let _=a;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,a=n.gverts.next;for(;a!=null;){let r=a,p=o;o=o.next,r.x=n.body.posx+(n.body.axisy*p.x-n.body.axisx*p.y),r.y=n.body.posy+(p.x*n.body.axisx+p.y*n.body.axisy),a=a.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 a=s.prev;a.next=s.next,s.next!=null&&(s.next.prev=a),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,a=o.body,r=i.aabb.maxx;for(;l!=null&&!(l.aabb.minx>r);){let p=l.shape,c=p.body;if(c==a){l=l.next;continue}if(a.type==1&&c.type==1){l=l.next;continue}if(a.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,a.type!=2||c.type!=2,null,!1):t.continuousEvent(o,p,a.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;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,a=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 c=r.shape,h;if(s!=null){let u=c.filter;h=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else h=!0;h&&(c.type==0?Ee.circleContains(c.circle,o)&&a.push(c.outer):Ee.polyContains(c.polygon,o)&&a.push(c.outer))}r=r.next}let p=o;return p.outer!=null&&(p.outer.zpp_inner=null,p.outer=null),p._isimmutable=null,p._validate=null,p._invalidate=null,p.next=le.zpp_pool,le.zpp_pool=p,a}bodiesUnderPoint(t,n,s,i){this.sync_broadphase();let l;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=t,l.y=n;let o=l,a=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 c=r.shape,h=c.body.outer;if(!a.has(h)){let u;if(s!=null){let x=c.filter;u=(x.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&x.collisionGroup)!=0}else u=!0;u&&(c.type==0?Ee.circleContains(c.circle,o)&&a.push(h):Ee.polyContains(c.polygon,o)&&a.push(h))}}r=r.next}let p=o;return p.outer!=null&&(p.outer.zpp_inner=null,p.outer=null),p._isimmutable=null,p._validate=null,p._invalidate=null,p.next=le.zpp_pool,le.zpp_pool=p,a}shapesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,a=l??new nn._nape.shape.ShapeList,r=this.list;for(;r!=null&&r.aabb.maxx<o.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=o.maxx;){let p=r.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)&&a.push(p.outer);else{let h=r.aabb;if(h.minx>=o.minx&&h.miny>=o.miny&&h.maxx<=o.maxx&&h.maxy<=o.maxy)a.push(p.outer);else{let u=r.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)&&a.push(p.outer)}}else{let h;if(s){let u=r.aabb;h=u.minx>=o.minx&&u.miny>=o.miny&&u.maxx<=o.maxx&&u.maxy<=o.maxy}else{let u=r.aabb;h=o.miny<=u.maxy&&u.miny<=o.maxy&&o.minx<=u.maxx&&u.minx<=o.maxx}h&&a.push(p.outer)}r=r.next}return a}bodiesInAABB(t,n,s,i,l){this.sync_broadphase(),this.updateAABBShape(t);let o=this.aabbShape.zpp_inner.aabb,a=l??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<o.minx;)r=r.next;for(;r!=null&&r.aabb.minx<=o.maxx;){let p=r.shape,c=p.body.outer,h=r.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);!a.has(c)&&x?a.push(c):x||(a.remove(c),this.failed.push(c))}}else!a.has(c)&&Ee.testCollide_safe(p,this.aabbShape.zpp_inner)&&a.push(c);else if(s){if(!this.failed.has(c)){let x=p.aabb,y=x.minx>=o.minx&&x.miny>=o.miny&&x.maxx<=o.maxx&&x.maxy<=o.maxy;!a.has(c)&&y?a.push(c):y||(a.remove(c),this.failed.push(c))}}else{let x;if(a.has(c))x=!1;else{let y=p.aabb;x=y.minx>=o.minx&&y.miny>=o.miny&&y.maxx<=o.maxx&&y.maxy<=o.maxy}x&&a.push(c)}}r=r.next}return this.failed.clear(),a}shapesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let a=this.circShape.zpp_inner.aabb,r=o??new nn._nape.shape.ShapeList,p=this.list;for(;p!=null&&p.aabb.maxx<a.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=a.maxx;){let c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.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)&&r.push(h.outer):Ee.testCollide_safe(h,this.circShape.zpp_inner)&&r.push(h.outer))}p=p.next}return r}bodiesInCircle(t,n,s,i,l,o){this.sync_broadphase(),this.updateCircShape(t,n,s);let a=this.circShape.zpp_inner.aabb,r=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<a.minx;)p=p.next;for(;p!=null&&p.aabb.minx<=a.maxx;){let c=p.aabb;if(a.miny<=c.maxy&&c.miny<=a.maxy&&a.minx<=c.maxx&&c.minx<=a.maxx){let h=p.shape,u=h.body.outer,x;if(l!=null){let y=h.filter;x=(y.collisionMask&l.collisionGroup)!=0&&(l.collisionMask&y.collisionGroup)!=0}else x=!0;if(x)if(i){if(!this.failed.has(u)){let y=Ee.containTest(this.circShape.zpp_inner,h);!r.has(u)&&y?r.push(u):y||(r.remove(u),this.failed.push(u))}}else!r.has(u)&&Ee.testCollide_safe(h,this.circShape.zpp_inner)&&r.push(u)}p=p.next}return this.failed.clear(),r}shapesInShape(t,n,s,i){this.sync_broadphase(),this.validateShape(t);let l=t.aabb,o=i??new nn._nape.shape.ShapeList,a=this.list;for(;a!=null&&a.aabb.maxx<l.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=l.maxx;){let r=a.aabb;if(l.miny<=r.maxy&&r.miny<=l.maxy&&l.minx<=r.maxx&&r.minx<=l.maxx){let p=a.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))}a=a.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 a=this.list;for(;a!=null&&a.aabb.maxx<l.minx;)a=a.next;for(;a!=null&&a.aabb.minx<=l.maxx;){let r=a.aabb;if(l.miny<=r.maxy&&r.miny<=l.maxy&&l.minx<=r.maxx&&r.minx<=l.maxx){let p=a.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)}a=a.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 r=this.list;for(;r!=null&&r.aabb.minx<=i.minx;){let p,c=r.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=r.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(r.aabb);if(h>=0&&h<l){let u=r.shape.type==0?t.circlesect(r.shape.circle,n,l):t.polysect(r.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}}}r=r.next}}else if(t.dirx<0){let r=this.list,p=null;for(;r!=null&&r.aabb.minx<=i.maxx;)p=r,r=r.next;for(r=p;r!=null;){let c,h=r.aabb;if(i.miny<=h.maxy&&h.miny<=i.maxy&&i.minx<=h.maxx&&h.minx<=i.maxx)if(s!=null){let u=r.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(r.aabb);if(u>=0&&u<l){let x=r.shape.type==0?t.circlesect(r.shape.circle,n,l):t.polysect(r.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}}}r=r.prev}}else{let r=this.list;for(;r!=null&&r.aabb.minx<=i.maxx&&r.aabb.minx<t.originx+t.dirx*l;){let p,c=r.aabb;if(i.miny<=c.maxy&&c.miny<=i.maxy&&i.minx<=c.maxx&&c.minx<=i.maxx)if(s!=null){let h=r.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(r.aabb);if(h>=0&&h<l){let u=r.shape.type==0?t.circlesect(r.shape.circle,n,l):t.polysect(r.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}}}r=r.next}}let a=i;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a.wrap_min=a.wrap_max=null,a._invalidate=null,a._validate=null,a.next=fe.zpp_pool,fe.zpp_pool=a,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 r=this.list;for(;r!=null&&r.aabb.minx<=l.minx;){let p,c=r.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=r.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(r.aabb)>=0&&(r.shape.type==0?t.circlesect2(r.shape.circle,n,o):t.polysect2(r.shape.polygon,n,o)),r=r.next}}else if(t.dirx<0){let r=this.list,p=null;for(;r!=null&&r.aabb.minx<=l.maxx;)p=r,r=r.next;for(r=p;r!=null;){let c,h=r.aabb;if(l.miny<=h.maxy&&h.miny<=l.maxy&&l.minx<=h.maxx&&h.minx<=l.maxx)if(s!=null){let u=r.shape.filter;c=(u.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&u.collisionGroup)!=0}else c=!0;else c=!1;c&&t.aabbsect(r.aabb)>=0&&(r.shape.type==0?t.circlesect2(r.shape.circle,n,o):t.polysect2(r.shape.polygon,n,o)),r=r.prev}}else{let r=this.list;for(;r!=null&&r.aabb.minx<=l.maxx;){let p,c=r.aabb;if(l.miny<=c.maxy&&c.miny<=l.maxy&&l.minx<=c.maxx&&c.minx<=l.maxx)if(s!=null){let h=r.shape.filter;p=(h.collisionMask&s.collisionGroup)!=0&&(s.collisionMask&h.collisionGroup)!=0}else p=!0;else p=!1;p&&t.aabbsect(r.aabb)>=0&&(r.shape.type==0?t.circlesect2(r.shape.circle,n,o):t.polysect2(r.shape.polygon,n,o)),r=r.next}}let a=l;return a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a.wrap_min=a.wrap_max=null,a._invalidate=null,a._validate=null,a.next=fe.zpp_pool,fe.zpp_pool=a,o}};nn._zpp=null,nn._nape=null;var cs=nn;function Bl(){let T={},e={};return T.callbacks={},T.constraint={},T.dynamics={},T.geom={},T.phys={},T.shape={},T.space={},T.util={},e.ZPP_Const=Dn,e.ZPP_ID=dn,e.callbacks||(e.callbacks={}),Tt._nape=T,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=T,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=T,ts._zpp=e,e.callbacks.ZPP_OptionType=ts,e.constraint||(e.constraint={}),Me._nape=T,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=T,Ie._zpp=e,e.dynamics.ZPP_Arbiter=Ie,e.dynamics.ZPP_SensorArbiter=Ot,Pt._nape=T,Pt._zpp=e,e.dynamics.ZPP_FluidArbiter=Pt,ut._nape=T,ut._zpp=e,e.dynamics.ZPP_ColArbiter=ut,e.dynamics.ZPP_IContact=zi,we._nape=T,we._zpp=e,e.dynamics.ZPP_Contact=we,st._nape=T,st._zpp=e,e.dynamics.ZPP_InteractionFilter=st,Zs._zpp=e,e.dynamics.ZPP_InteractionGroup=Zs,Yn._nape=T,Yn._zpp=e,e.dynamics.ZPP_SpaceArbiterList=Yn,e.geom||(e.geom={}),fe._nape=T,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 T.geom.Vec2},e.geom.ZPP_GeomPoly=os,e.geom.ZPP_MarchSpan=An,e.geom.ZPP_MarchPair=In,ks._init(e,T),e.geom.ZPP_MarchingSquares=ks,Es._nape=T,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=le,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,T),Cn._init(e,T),e.phys.ZPP_Body=Cn,qn._nape=T,qn._zpp=e,qn._init(),e.phys.ZPP_Compound=qn,Mn._nape=T,Mn._zpp=e,e.phys.ZPP_FluidProperties=Mn,Oe._nape=T,Oe._zpp=e,e.phys.ZPP_Material=Oe,e.shape||(e.shape={}),ri._nape=T,ri._zpp=e,ri._init(),e.shape.ZPP_Shape=ri,Xn._nape=T,Xn._zpp=e,Xn._init(),e.shape.ZPP_Circle=Xn,rt._nape=T,rt._zpp=e,e.shape.ZPP_Edge=rt,Hn._nape=T,Hn._zpp=e,Hn._init(),e.shape.ZPP_Polygon=Hn,Qn._nape=T,Qn._zpp=e,Qn._init(),e.shape.ZPP_Capsule=Qn,e.space||(e.space={}),$n._zpp=e,$n._nape=T,e.space.ZPP_Broadphase=$n,e.space.ZPP_AABBNode=Ve,e.space.ZPP_AABBPair=et,e.space.ZPP_AABBTree=Qe,ps._zpp=e,ps._nape=T,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=T,e.space.ZPP_Space=pi,e.space.ZPP_SweepData=Bn,cs._zpp=e,cs._nape=T,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(),T.__zpp=e,T}var $s;function _e(){return $s||($s=Bl()),$s}var Tl=!1;function el(){if(Tl)return;let T=$s;if(!T?.callbacks?.CbEvent||!T?.callbacks?.CbType||!T?.callbacks?.ListenerType||!T?.dynamics?.ArbiterType||!T?.phys?.BodyType||!T?.shape?.ShapeType)return;Tl=!0;let e=T.__zpp;e.callbacks.ZPP_CbType._initEnums(T),e.callbacks.ZPP_Listener._initEnums(T,e.util.ZPP_Flags),e.dynamics.ZPP_Arbiter._initEnums(T,e.util.ZPP_Flags),e.phys.ZPP_Body._initEnums(T,e.util.ZPP_Flags),e.shape.ZPP_Shape._initEnums(T,e.util.ZPP_Flags)}var Ll=new WeakMap;function Ze(T,e){if(!T)return null;let t=Ll.get(T);return t||(t=e(T),Ll.set(T,t)),t}var lt=class T{constructor(e=0,t=0){this.zpp_pool=null;this.zpp_disp=!1;if(e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");let n;le.zpp_pool==null?n=new le:(n=le.zpp_pool,le.zpp_pool=n.next,n.next=null),n.weak=!1,n._immutable=!1,n.x=e,n.y=t,this.zpp_inner=n,n.outer=this}get _inner(){return this}_checkDisposed(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}_checkImmutable(){this.zpp_inner.immutable()}_validate(){this.zpp_inner.validate()}_invalidate(){this.zpp_inner.invalidate()}static _disposeWeak(e){e.zpp_inner.weak&&e.dispose()}_setXY(e,t){if(this._checkDisposed(),this._checkImmutable(),e!==e||t!==t)throw new Error("Error: Vec2 components cannot be NaN");this._validate(),(this.zpp_inner.x!==e||this.zpp_inner.y!==t)&&(this.zpp_inner.x=e,this.zpp_inner.y=t,this._invalidate())}static _poolGet(e,t,n){let s;if(xe.poolVec2==null?s=new T:(s=xe.poolVec2,xe.poolVec2=s.zpp_pool,s.zpp_pool=null,s.zpp_disp=!1,s===xe.nextVec2&&(xe.nextVec2=null)),s.zpp_inner==null){let i;le.zpp_pool==null?i=new le:(i=le.zpp_pool,le.zpp_pool=i.next,i.next=null),i.weak=!1,i._immutable=!1,i.x=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 T?e:e?e instanceof le?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?T._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 T._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 T._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 T._poolGet(s,i,n)}static fromAngle(e,t=!1){return T.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=T._poolGet(i,l,s);return T._disposeWeak(e),T._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&&T._disposeWeak(e),t!=null&&T._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 T._disposeWeak(e),T._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,a=s-l,r=o*o+a*a;return T._disposeWeak(e),T._disposeWeak(t),r}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,a=s-l,r=Math.sqrt(o*o+a*a);return T._disposeWeak(e),T._disposeWeak(t),r}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),T._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 T._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=T._poolGet(n,s,!0);i.normalise();let l=e.sub(i.muleq(2*i.dot(e)),t);return T._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 T._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=T._poolGet(n,s,t);return T._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=T._poolGet(s,i,n);return T._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=T._poolGet(n,s,t);return T._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 T._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),T._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),T._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 T._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 T._disposeWeak(e),t}perp(e=!1){this._checkDisposed(),this._validate();let t=-this.zpp_inner.y,n=this.zpp_inner.x;return T._poolGet(t,n,e)}dispose(){if(this.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(this._checkImmutable(),this.zpp_inner._inuse)throw new Error("Error: This Vec2 is not disposable");let e=this.zpp_inner;e.outer=null,this.zpp_inner=null,this.zpp_pool=null,xe.nextVec2!=null?xe.nextVec2.zpp_pool=this:xe.poolVec2=this,xe.nextVec2=this,this.zpp_disp=!0,e.free(),e.next=le.zpp_pool,le.zpp_pool=e}toString(){return this._checkDisposed(),this._validate(),this.zpp_inner.toString()}};le._wrapFn=T=>Ze(T,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 T{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 T?e:e?e instanceof oi?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,n.zpp_pool=null,n.zpp_disp=!1,t.outer=n,n}):e.zpp_inner?T._wrap(e.zpp_inner):null:null}static get(e=0,t=0,n=0){let s;return xe.poolVec3==null?s=new T:(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(),T.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=T=>Ze(T,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 T{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 T?e:e?e instanceof Bi?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?T._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 T(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 T(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 T(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 T{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 a=e[o];if(a!=null&&a.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(a==null)throw new Error("Error: AABB::fromPoints cannot contain null Vec2");a.zpp_inner.validate();let r=a.zpp_inner.x,p=a.zpp_inner.y;r<n&&(n=r),p<s&&(s=p),r>i&&(i=r),p>l&&(l=p)}return new T(n,s,i-n,l-s)}static _wrap(e){return e instanceof T?e:e?e instanceof fe?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?T._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 a=this.zpp_inner.wrap_min;this._assignVec2(a,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 a=this.zpp_inner.wrap_max;this._assignVec2(a,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=T=>Ze(T,e=>{let t=Object.create(Wi.prototype);return t.zpp_inner=e,e.outer=t,t});var dl=class T{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 T,U.internal=!1),U.Winding_UNDEFINED}static get CLOCKWISE(){return U.Winding_CLOCKWISE==null&&(U.internal=!0,U.Winding_CLOCKWISE=new T,U.internal=!1),U.Winding_CLOCKWISE}static get ANTICLOCKWISE(){return U.Winding_ANTICLOCKWISE==null&&(U.internal=!0,U.Winding_ANTICLOCKWISE=new T,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 T{constructor(e){this.zpp_pool=null;this.zpp_disp=!1;this.zpp_inner=new os(this),e!=null&&(T._addVertices(this,e),this.skipForward(1),T._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 a=l.zpp_inner.y,r=T._createVert(o,a);T._pushVert(e,r)}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,a=T._createVert(l,o);T._pushVert(e,a)}}else if(t instanceof T){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=T._createVert(i.x,i.y);T._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 T:(t=xe.poolGeomPoly,xe.poolGeomPoly=t.zpp_pool,t.zpp_pool=null,t.zpp_disp=!1,t===xe.nextGeomPoly&&(xe.nextGeomPoly=null)),e!=null&&(T._addVertices(t,e),t.skipForward(1),T._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=T._createVert(t,n);return T._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 T._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=T._createVert(t,n);return T._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 T._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),T._freeVert(t)}return this}clear(){for(this._checkDisposed();this.zpp_inner.vertices!=null;){let e=this._shiftHead();T._freeVert(e)}return this}copy(){this._checkDisposed();let e=T.get();return this._forEachVert(t=>{let n=T._createVert(t.x,t.y);T._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,a=l.next,r=a.x-l.x,p=a.y-l.y,c=l.x-o.x,u=(l.y-o.y)*r-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=T.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=T.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(),a=T.get();a.zpp_inner.vertices=o,l.zpp_inner.reverse_flag?l.push(a):l.unshift(a)}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 a=l.pop_unsafe();li.triangulate(a),e&&li.optimise(a),is.optimise(a),Je.sharedGVList==null&&(Je.sharedGVList=new Fn);let r=a.extract(Je.sharedGVList),p=a;for(p.next=Je.zpp_pool,Je.zpp_pool=p;r.head!=null;){let c=r.pop_unsafe(),h=T.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 a=l.pop_unsafe();li.triangulate(a),e&&li.optimise(a),Je.sharedGVList==null&&(Je.sharedGVList=new Fn);let r=a.extract(Je.sharedGVList),p=a;for(p.next=Je.zpp_pool,Je.zpp_pool=p;r.head!=null;){let c=r.pop_unsafe(),h=T.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=T.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,a=i.x-n.x,r=i.y-n.y,p=Math.sqrt(l*l+o*o),c=-o/p*e,h=l/p*e,u=Math.sqrt(a*a+r*r),x=-r/u*e,y=a/u*e,_=x-c,d=y-h,f=r*_-a*d,z=f===0?0:f/(r*l-a*o),P=n.x+c+l*z,Z=n.y+h+o*z,m=lt.get(P,Z);t.push(m)}),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(T){As=T}function Px(T){Is=T}function wx(T){js=T}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 T{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 T?e:e?e instanceof Mn?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?T._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 a=l;a.outer!=null&&(a.outer.zpp_inner=null,a.outer=null),a._isimmutable=null,a._validate=null,a._invalidate=null,a.next=n.geom.ZPP_Vec2.zpp_pool,n.geom.ZPP_Vec2.zpp_pool=a,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 a=e.zpp_inner;a._validate!=null&&a._validate();let r=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||r!=r)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==r}else c=!1;if(!c){s.zpp_inner.x=o,s.zpp_inner.y=r;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 y=e;y.zpp_pool=null,n.util.ZPP_PubPool.nextVec2!=null?n.util.ZPP_PubPool.nextVec2.zpp_pool=y:n.util.ZPP_PubPool.poolVec2=y,n.util.ZPP_PubPool.nextVec2=y,y.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 T(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 a=i;a.zpp_pool=null,t.util.ZPP_PubPool.nextVec2!=null?t.util.ZPP_PubPool.nextVec2.zpp_pool=a:t.util.ZPP_PubPool.poolVec2=a,t.util.ZPP_PubPool.nextVec2=a,a.zpp_disp=!0;let r=o;r.outer!=null&&(r.outer.zpp_inner=null,r.outer=null),r._isimmutable=null,r._validate=null,r._invalidate=null,r.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=r,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 a=s.zpp_inner.x;if(s!=null&&s.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let r=s.zpp_inner;r._validate!=null&&r._validate();let 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(),a!=a||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==a){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=a,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 y=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 d=y;d.outer!=null&&(d.outer.zpp_inner=null,d.outer=null),d._isimmutable=null,d._validate=null,d._invalidate=null,d.next=t.geom.ZPP_Vec2.zpp_pool,t.geom.ZPP_Vec2.zpp_pool=d}}return n}toString(){return"{ density: "+this.zpp_inner.density*1e3+" viscosity: "+this.zpp_inner.viscosity+" gravity: "+String(this.zpp_inner.wrap_gravity)+" }"}};Mn._wrapFn=T=>Ze(T,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 T{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 T,U.internal=!1),U.ShapeType_CIRCLE}static get POLYGON(){return U.ShapeType_POLYGON==null&&(U.internal=!0,U.ShapeType_POLYGON=new T,U.internal=!1),U.ShapeType_POLYGON}static get CAPSULE(){return U.ShapeType_CAPSULE==null&&(U.internal=!0,U.ShapeType_CAPSULE=new T,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(T){Ts=T}function Rl(T){Ls=T}function ql(T){Ds=T}var ti=class T 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(T.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 T?e:T._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;le.zpp_pool==null?l=new le:(l=le.zpp_pool,le.zpp_pool=l.next,l.next=null),l.weak=!1,l._immutable=!1,l.x=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(T,e,t,n){let s=_e(),i=s.__zpp;class l extends ml{constructor(){super(),this.inner=new i.util[T]}static get(a,r=!1){let p=new s[e][t];return p.zpp_inner.inner=a,r&&(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(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Jn(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Tn(T){if(T!=null&&T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!")}function On(T){T.zpp_inner.weak&&T.dispose()}function us(T,e,t,n,s){if(Tn(t),t==null)throw new Error("Error: Body::"+T+" cannot be null");return e==null&&n!=null&&(n(),e=s()),e.set(t),e}function nl(T,e,t){return lt.get(T,e,t)}function sn(T,e){return U[T]==null&&(U.internal=!0,U[T]=e(),U.internal=!1),U[T]}var nt=class T 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 T?t:t instanceof Cn?Ze(t,n=>{let s=Object.create(T.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?T._wrap(t.zpp_inner):Ze(t,n=>{let s=Object.create(T.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,a=1-l*l/8,r=(o*n.axisx+i*n.axisy)*a;n.axisy=(o*n.axisy-i*n.axisx)*a,n.axisx=r}}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 a=Wn(n)-this.zpp_inner.posx,r=Jn(n)-this.zpp_inner.posy;this.zpp_inner.validate_inertia(),this.zpp_inner.angvel+=(o*a-l*r)*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,a=this.zpp_inner;if(a.immutable_midstep("Body::rotation"),a.world)throw new Error("Error: Space::world is immutable");if(a.type===1&&a.space!=null)throw new Error("Error: Static objects cannot be rotated once inside a Space");if(a.rot!==o){if(o!==o)throw new Error("Error: Body::rotation cannot be NaN");a.rot=o,a.invalidate_rot(),a.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 a=sn("InteractionType_SENSOR",()=>new l.callbacks.InteractionType);i=t===a?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 a=l.zpp_inner.at(l.zpp_i++),r=a.zpp_inner;r.type===Ie.COL&&(t!=null&&r.b2!==t.zpp_inner&&r.b1!==t.zpp_inner||(s+=a.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),a=o.zpp_inner;a._validate!=null&&a._validate(),t+=a.x,a._validate!=null&&a._validate(),n+=a.y,a._validate!=null&&a._validate(),s+=a.z,o.dispose(),i=i.next}return ci.get(t,n,s)}totalImpulse(t=null,n=!1){let s=0,i=0,l=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 h=a.zpp_inner.at(a.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 r=this.zpp_inner.constraints.head;for(;r!=null;){let p=r.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()}r=r.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),d=_.xy();n.addeq(d);let f=Wn(d),z=Jn(d);t+=Math.sqrt(f*f+z*z),d.dispose(),_.dispose()}let o=this._getConstraints();o.zpp_inner.valmod();let a=_e().constraint.ConstraintIterator.get(o);for(;;){a.zpp_inner.zpp_inner.valmod();let x=a.zpp_inner;x.zpp_inner.valmod(),x.zpp_inner.zip_length&&(x.zpp_inner.zip_length=!1,x.zpp_inner.user_length=x.zpp_inner.inner.length);let y=x.zpp_inner.user_length;if(a.zpp_critical=!0,a.zpp_i>=y){a.zpp_next=_e().constraint.ConstraintIterator.zpp_pool,_e().constraint.ConstraintIterator.zpp_pool=a,a.zpp_inner=null;break}a.zpp_critical=!1;let d=a.zpp_inner.at(a.zpp_i++).bodyImpulse(this),f=d.xy();n.addeq(f);let z=Wn(f),P=Jn(f);t+=Math.sqrt(z*z+P*P),f.dispose(),d.dispose()}let r=Wn(n),p=Jn(n),c=Math.sqrt(r*r+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,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 c=r.zpp_inner.at(r.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(T,e){let t=sn("BodyType_DYNAMIC",()=>new e.phys.BodyType);if(T===t)return 2;let n=sn("BodyType_KINEMATIC",()=>new e.phys.BodyType);return T===n?3:1}function Jl(T){let e=T.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=nt;Fl(T=>nt._wrap(T));var xs=class T{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 T?e:e instanceof pi?e.outer?e.outer:Ze(e,t=>{let n=Object.create(T.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(T.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 nt._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 a=o.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=a){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 a=o.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=a){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 a=o.zpp_inner.user_length;if(s.zpp_critical=!0,s.zpp_i>=a){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 a=o.zpp_inner.user_length;if(l.zpp_critical=!0,l.zpp_i>=a){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,a=i.constraints.head;for(;a!=null;){let u=a.elt;if(u.ignore&&u.pair_exists(i.id,l.id)){o=!0;break}a=a.next}let r;if(o)r=!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,y;if(x==null)y=!1;else{let _=s;for(;_!=null&&_.group==null;)_.ishape!=null?_=_.ishape.body:_.icompound!=null?_=_.icompound.compound:_=_.ibody.compound;let d=_==null?null:_.group;if(d==null)y=!1;else{let f=!1;for(;x!=null&&d!=null;){if(x==d){f=x.ignore;break}x.depth<d.depth?d=d.group:x=x.group}y=f}}r=!y}if(!r)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,a=this.zpp_inner.shapesUnderPoint(i,l,o,n);return s.weak&&e.dispose(),a}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,a=this.zpp_inner.bodiesUnderPoint(i,l,o,n);return s.weak&&e.dispose(),a}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 a=o.zpp_inner;a.zpp_inner.valmod(),a.zpp_inner.zip_length&&(a.zpp_inner.zip_length=!1,a.zpp_inner.user_length=a.zpp_inner.inner.length);let r=a.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=r){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 a=o.zpp_inner;a.zpp_inner.valmod(),a.zpp_inner.zip_length&&(a.zpp_inner.zip_length=!1,a.zpp_inner.user_length=a.zpp_inner.inner.length);let r=a.zpp_inner.user_length;if(o.zpp_critical=!0,o.zpp_i>=r){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,a=(t&Ci.VELOCITIES)!==0,r=4283417591,p=4287669422,c=4294948685,h=4289058471,u=4293874512,x=1157627903,y=4294961979,_=4291728344;if(this.visitBodies(d=>{let f=d.zpp_inner,z=f.type===2,Z=f.type===1?p:z?r:c;if(n){let m=f.shapes.head;for(;m!=null;){let b=m.elt;if(b.type===0){let C=b.circle;b.zip_worldCOM&&b.validate_worldCOM();let v=b.worldCOMx,w=b.worldCOMy,O=C.radius,k=f.rot,g=v+Math.cos(k)*O,E=w+Math.sin(k)*O,M={x:v,y:w},N={x:g,y:E};z?e.drawSolidCircle(M,O,N,Z):e.drawCircle(M,O,Z)}else if(b.type===1){let C=b.polygon;C.zip_gverts&&C.validate_gverts();let v=[],w=C.gverts.next;for(;w!=null;)v.push({x:w.x,y:w.y}),w=w.next;v.length>=3&&(z?e.drawSolidPolygon(v,Z):e.drawPolygon(v,Z))}else if(b.type===2){let C=b.capsule;b.zip_aabb&&b.validate_aabb();let v={x:C.spine1x,y:C.spine1y},w={x:C.spine2x,y:C.spine2y};z?e.drawSolidCapsule(v,w,C.radius,Z):e.drawCapsule(v,w,C.radius,Z)}m=m.next}}if(l&&!f.world){let m=f.aabb,b=m.minx,C=m.miny,v=m.maxx,w=m.maxy;e.drawSegment({x:b,y:C},{x:v,y:C},x),e.drawSegment({x:v,y:C},{x:v,y:w},x),e.drawSegment({x:v,y:w},{x:b,y:w},x),e.drawSegment({x:b,y:w},{x:b,y:C},x)}if(o&&!f.world&&(f.validate_worldCOM(),e.drawPoint({x:f.worldCOMx,y:f.worldCOMy},y)),a&&!f.world&&z){let m=f.posx,b=f.posy;e.drawSegment({x:m,y:b},{x:m+f.velx,y:b+f.vely},_)}}),s&&this.visitConstraints(d=>{if(!d.debugDraw)return;let f=d.zpp_inner,z=f.b1,P=f.b2,Z=f.a1worldx??(z!=null?z.posx:0),m=f.a1worldy??(z!=null?z.posy:0),b=f.a2worldx??(P!=null?P.posx:0),C=f.a2worldy??(P!=null?P.posy:0);e.drawSegment({x:Z,y:m},{x:b,y:C},h),e.drawPoint({x:Z,y:m},h),e.drawPoint({x:b,y:C},h)}),i){let d=f=>{if(f==null)return;let z=f.head;for(;z!=null;){let P=z.elt;if(P!=null){let Z=P.nx,m=P.ny,b=P.contacts?.next;for(;b!=null;){let C=b.px,v=b.py;e.drawPoint({x:C,y:v},u),e.drawSegment({x:C,y:v},{x:C+Z*8,y:v+m*8},u),b=b.next}}z=z.next}};d(this.zpp_inner.c_arbiters_true),d(this.zpp_inner.c_arbiters_false)}}toString(){return`Space(bodies=${this.bodies.length})`}};var zl=class T{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 T,U.internal=!1),U.BodyType_STATIC}static get DYNAMIC(){return U.BodyType_DYNAMIC==null&&(U.internal=!0,U.BodyType_DYNAMIC=new T,U.internal=!1),U.BodyType_DYNAMIC}static get KINEMATIC(){return U.BodyType_KINEMATIC==null&&(U.internal=!0,U.BodyType_KINEMATIC=new T,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 T 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 T?e:e instanceof qn?Ze(e,t=>{let n=Object.create(T.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?T._wrap(e.zpp_inner):Ze(e,t=>{let n=Object.create(T.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=T=>Ze(T,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 T{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 T?e:e?e instanceof Oe?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?T._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 T(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 T(.4,.2,.38,.7,.005)}static steel(){return new T(.2,.57,.74,7.8,.001)}static ice(){return new T(.3,.03,.1,.9,1e-4)}static rubber(){return new T(.8,1,1.4,1.5,.01)}static glass(){return new T(.4,.4,.94,2.6,.002)}static sand(){return new T(-1,.45,.6,1.6,16)}};Oe._wrapFn=T=>Ze(T,e=>{let t=Object.create(Pl.prototype);return t.zpp_inner=e,e.outer=t,t});var wl=class T{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 T,U.internal=!1),U.GravMassMode_DEFAULT}static get FIXED(){return U.GravMassMode_FIXED==null&&(U.internal=!0,U.GravMassMode_FIXED=new T,U.internal=!1),U.GravMassMode_FIXED}static get SCALED(){return U.GravMassMode_SCALED==null&&(U.internal=!0,U.GravMassMode_SCALED=new T,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 T{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 T,U.internal=!1),U.InertiaMode_DEFAULT}static get FIXED(){return U.InertiaMode_FIXED==null&&(U.internal=!0,U.InertiaMode_FIXED=new T,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 T{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 T,U.internal=!1),U.MassMode_DEFAULT}static get FIXED(){return U.MassMode_FIXED==null&&(U.internal=!0,U.MassMode_FIXED=new T,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 T 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?st.zpp_pool!=null?(l.filter=st.zpp_pool,st.zpp_pool=l.filter.next,l.filter.next=null):l.filter=new st:(l.immutable_midstep("Shape::filter"),l.setFilter(s.zpp_inner),l.filter.wrapper()),l.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof T?e:e instanceof Xn?Ze(e,t=>{let n=Object.create(T.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?T._wrap(e.zpp_inner_zn):Ze(e,t=>{let n=Object.create(T.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(T=>il._wrap(T));var wo=_e();wo.shape.Circle=il;var sl=class T 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 a=o.x;o._validate!=null&&o._validate();let r=o.y,p=new lt(a,r);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 y=u.y,_=new lt(x,y);i.wrap_lverts.push(_)}l.zpp_inner._validate!=null&&l.zpp_inner._validate();let a=l.zpp_inner.inner,r=null,p=a.head;for(;p!=null;){let c=p.elt;c.outer?.zpp_inner?.weak?(p=a.erase(r),c.outer.zpp_inner.weak&&c.outer.dispose()):(r=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 a=new lt(o.x,o.y);i.wrap_lverts.push(a),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?st.zpp_pool!=null?(i.filter=st.zpp_pool,st.zpp_pool=i.filter.next,i.filter.next=null):i.filter=new st:(i.immutable_midstep("Shape::filter"),i.setFilter(n.zpp_inner),i.filter.wrapper()),i.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof T?e:e instanceof Hn?Ze(e,t=>{let n=Object.create(T.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?T._wrap(e.zpp_inner_zn):Ze(e,t=>{let n=Object.create(T.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 a=new lt(e+n,t+s);a.zpp_inner.weak=i;let r=new lt(e,t+s);return r.zpp_inner.weak=i,[l,o,a,r]}static box(e,t=e,n=!1){if(e!==e||t!==t)throw new Error("Error: Polygon.box cannot accept NaN arguments");return T.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 a=0;a<n;a++){let r=a*o+s,p=Math.cos(r)*e,c=Math.sin(r)*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(T=>sl._wrap(T));var vo=_e();vo.shape.Polygon=sl;var ll=class T 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,a=(e-t)/2,r=new Qn;if(this.zpp_inner_zn=r,this.zpp_inner=r,this.zpp_inner_i=r,r.outer=this,r.outer_zn=this,r.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(r.radius=o,r.halfLength=a,r.invalidate_radius(),a>0&&r.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(),r.localCOMx=p.x,p._validate!=null&&p._validate(),r.localCOMy=p.y,p.weak&&n.dispose()}else r.localCOMx=0,r.localCOMy=0;s==null?Oe.zpp_pool!=null?(r.material=Oe.zpp_pool,Oe.zpp_pool=r.material.next,r.material.next=null):r.material=new Oe:(r.immutable_midstep("Shape::material"),r.setMaterial(s.zpp_inner),r.material.wrapper()),i==null?st.zpp_pool!=null?(r.filter=st.zpp_pool,st.zpp_pool=r.filter.next,r.filter.next=null):r.filter=new st:(r.immutable_midstep("Shape::filter"),r.setFilter(i.zpp_inner),r.filter.wrapper()),r.insert_cbtype(pn.ANY_SHAPE.zpp_inner)}static _wrap(e){return e?e instanceof T?e:e instanceof Qn?Ze(e,t=>{let n=Object.create(T.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?T._wrap(e.zpp_inner_zn):Ze(e,t=>{let n=Object.create(T.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(T=>ll._wrap(T));var go=_e();go.shape.Capsule=ll;var Ul=class T{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 T,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 T,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 T{get _inner(){return this}constructor(e=1,t=-1,n=1,s=-1,i=1,l=-1){let o;st.zpp_pool==null?o=new st:(o=st.zpp_pool,st.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 T?e:e?e instanceof st?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,n}):e.zpp_inner?T._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 T(this.zpp_inner.collisionGroup,this.zpp_inner.collisionMask,this.zpp_inner.sensorGroup,this.zpp_inner.sensorMask,this.zpp_inner.fluidGroup,this.zpp_inner.fluidMask)}toString(){let e=(t,n)=>{let s="",i="0123456789ABCDEF",l=t;do s=i.charAt(l&15)+s,l>>>=4;while(l>0);for(;s.length<n;)s="0"+s;return s};return"{ collision: "+e(this.zpp_inner.collisionGroup,8)+"~"+e(this.zpp_inner.collisionMask,8)+" sensor: "+e(this.zpp_inner.sensorGroup,8)+"~"+e(this.zpp_inner.sensorMask,8)+" fluid: "+e(this.zpp_inner.fluidGroup,8)+"~"+e(this.zpp_inner.fluidMask,8)+" }"}};st._wrapFn=T=>Ze(T,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 T 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 T?e:e.zpp_inner?.outer instanceof T?e.zpp_inner.outer:e instanceof Re?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:nt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("AngleJoint::jointMin"),e!==e)throw new Error("Error: AngleJoint::jointMin cannot be NaN");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("AngleJoint::jointMax"),e!==e)throw new Error("Error: AngleJoint::jointMax cannot be NaN");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}get ratio(){return this.zpp_inner.ratio}set ratio(e){if(this.zpp_inner.immutable_midstep("AngleJoint::ratio"),e!==e)throw new Error("Error: AngleJoint::ratio cannot be NaN");this.zpp_inner.ratio!=e&&(this.zpp_inner.ratio=e,this.zpp_inner.wake())}isSlack(){if(this.zpp_inner.b1==null||this.zpp_inner.b2==null)throw new Error("Error: Cannot compute slack for AngleJoint if either body is null.");return this.zpp_inner.is_slack()}impulse(){let e=_e(),t=new e.geom.MatMN(1,1);if(0>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return t.zpp_inner.x[0*t.zpp_inner.n]=this.zpp_inner.jAcc,t}bodyImpulse(e){let t=_e();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get(0,0,0)}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};Re._wrapFn=T=>Ze(T,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(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Yl(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.y}function ol(T){T.zpp_inner.weak&&T.dispose()}var Zl=class T 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 a=Kl(n),r=Yl(n);if(o.a1localx=a,o.a1localy=r,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 T?e:e.zpp_inner?.outer instanceof T?e.zpp_inner.outer:e instanceof _i?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:nt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),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=T=>Ze(T,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(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.x}function El(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.y}function ds(T){T.zpp_inner.weak&&T.dispose()}var Nl=class T extends ln{constructor(e,t,n,s,i,l,o){super();let a=new di;if(this.zpp_inner=a,a.outer=this,a.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(a.a1localx=kl(n),a.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(a.a2localx=kl(s),a.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(a.nlocalx=kl(i),a.nlocaly=El(i),a.zip_n=!0,ds(i),this.zpp_inner.immutable_midstep("LineJoint::jointMin"),l!==l)throw new Error("Error: AngleJoint::jointMin cannot be NaN");if(a.jointMin!=l&&(a.jointMin=l,a.wake()),this.zpp_inner.immutable_midstep("LineJoint::jointMax"),o!==o)throw new Error("Error: AngleJoint::jointMax cannot be NaN");a.jointMax!=o&&(a.jointMax=o,a.wake())}static _wrap(e){return e==null?null:e instanceof T?e:e.zpp_inner?.outer instanceof T?e.zpp_inner.outer:e instanceof di?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:nt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),ds(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),ds(e)}get direction(){return this.zpp_inner.wrap_n==null&&this.zpp_inner.setup_n(),this.zpp_inner.wrap_n}set direction(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::direction cannot be null");this.zpp_inner.wrap_n==null&&this.zpp_inner.setup_n(),this.zpp_inner.wrap_n.set(e),ds(e)}get jointMin(){return this.zpp_inner.jointMin}set jointMin(e){if(this.zpp_inner.immutable_midstep("LineJoint::jointMin"),e!==e)throw new Error("Error: AngleJoint::jointMin cannot be NaN");this.zpp_inner.jointMin!=e&&(this.zpp_inner.jointMin=e,this.zpp_inner.wake())}get jointMax(){return this.zpp_inner.jointMax}set jointMax(e){if(this.zpp_inner.immutable_midstep("LineJoint::jointMax"),e!==e)throw new Error("Error: AngleJoint::jointMax cannot be NaN");this.zpp_inner.jointMax!=e&&(this.zpp_inner.jointMax=e,this.zpp_inner.wake())}impulse(){let e=_e(),t=new e.geom.MatMN(2,1);return t.zpp_inner.x[0]=this.zpp_inner.jAccx,t.zpp_inner.x[1]=this.zpp_inner.jAccy,t}bodyImpulse(e){let t=_e();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){if(e==null)throw new Error("Error: Cannot apply null lambda to bodies");let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};di._wrapFn=T=>Ze(T,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 T 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 T?e:e.zpp_inner?.outer instanceof T?e.zpp_inner.outer:e instanceof yi?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:nt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get rate(){return this.zpp_inner.rate}set rate(e){if(this.zpp_inner.immutable_midstep("MotorJoint::rate"),e!==e)throw new Error("Error: MotorJoint::rate cannot be NaN");this.zpp_inner.rate!=e&&(this.zpp_inner.rate=e,this.zpp_inner.wake())}get ratio(){return this.zpp_inner.ratio}set ratio(e){if(this.zpp_inner.immutable_midstep("MotorJoint::ratio"),e!==e)throw new Error("Error: MotorJoint::ratio cannot be NaN");this.zpp_inner.ratio!=e&&(this.zpp_inner.ratio=e,this.zpp_inner.wake())}impulse(){let e=_e(),t=new e.geom.MatMN(1,1);if(0>=t.zpp_inner.m||0>=t.zpp_inner.n)throw new Error("Error: MatMN indices out of range");return t.zpp_inner.x[0*t.zpp_inner.n]=this.zpp_inner.jAcc,t}bodyImpulse(e){let t=_e();if(e==null)throw new Error("Error: Cannot evaluate impulse on null body");let n=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer,s=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;if(e!=n&&e!=s)throw new Error("Error: Body is not linked to this constraint");return this.zpp_inner.active?this.zpp_inner.bodyImpulse(e.zpp_inner):t.geom.Vec3.get()}visitBodies(e){let t=this.zpp_inner.b1==null?null:this.zpp_inner.b1.outer;t!=null&&e(t);let n=this.zpp_inner.b2==null?null:this.zpp_inner.b2.outer;n!=null&&n!=t&&e(n)}get zpp_inner_zn(){return this.zpp_inner}set zpp_inner_zn(e){this.zpp_inner=e}};yi._wrapFn=T=>Ze(T,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(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Hl(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.y}function rl(T){T.zpp_inner.weak&&T.dispose()}var Sl=class T 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 T?e:e.zpp_inner?.outer instanceof T?e.zpp_inner.outer:e instanceof mi?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:nt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),rl(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),rl(e)}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=T=>Ze(T,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(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.x}function Gs(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.y}function Rs(T){T.zpp_inner.weak&&T.dispose()}var Vl=class T extends ln{constructor(e,t,n,s,i,l,o,a,r,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(a,"anchor4",(u,x)=>{h.a4localx=u,h.a4localy=x}),h.immutable_midstep("PulleyJoint::jointMin"),r!==r)throw new Error("Error: PulleyJoint::jointMin cannot be NaN");if(r<0)throw new Error("Error: PulleyJoint::jointMin must be >= 0");if(h.jointMin!=r&&(h.jointMin=r,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 T?e:e.zpp_inner?.outer instanceof T?e.zpp_inner.outer:e instanceof fi?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:nt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}get body2(){return this.zpp_inner.b2==null?null:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}get body3(){return this.zpp_inner.b3==null?null:nt._wrap(this.zpp_inner.b3)}set body3(e){this._setBody3(e)}get body4(){return this.zpp_inner.b4==null?null:nt._wrap(this.zpp_inner.b4)}set body4(e){this._setBody4(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b3!=this.zpp_inner.b1&&this.zpp_inner.b4!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&this.zpp_inner.b3!=t&&this.zpp_inner.b4!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b3!=this.zpp_inner.b2&&this.zpp_inner.b4!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&this.zpp_inner.b3!=t&&this.zpp_inner.b4!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}_setBody3(e){this.zpp_inner.immutable_midstep("Constraint::body3");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b3&&(this.zpp_inner.b3!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b3&&this.zpp_inner.b2!=this.zpp_inner.b3&&this.zpp_inner.b4!=this.zpp_inner.b3&&this.zpp_inner.b3.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b3.wake()),this.zpp_inner.b3=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&this.zpp_inner.b2!=t&&this.zpp_inner.b4!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}_setBody4(e){this.zpp_inner.immutable_midstep("Constraint::body4");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b4&&(this.zpp_inner.b4!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b4&&this.zpp_inner.b2!=this.zpp_inner.b4&&this.zpp_inner.b3!=this.zpp_inner.b4&&this.zpp_inner.b4.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b4.wake()),this.zpp_inner.b4=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&this.zpp_inner.b2!=t&&this.zpp_inner.b3!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),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=T=>Ze(T,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(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.x}function $l(T){if(T.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");let e=T.zpp_inner;return e._validate!=null&&e._validate(),e.y}function al(T){T.zpp_inner.weak&&T.dispose()}var Al=class T 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 T?e:e.zpp_inner?.outer instanceof T?e.zpp_inner.outer:e instanceof bi?Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t,t.outer=n,t.outer_zn=n,n.debugDraw=!0,n}):Ze(e,t=>{let n=Object.create(T.prototype);return n.zpp_inner=t.zpp_inner??t,n.zpp_inner.outer=n,n.zpp_inner.outer_zn=n,n})}get body1(){return this.zpp_inner.b1==null?null:nt._wrap(this.zpp_inner.b1)}set body1(e){this._setBody1(e)}_setBody1(e){this.zpp_inner.immutable_midstep("Constraint::body1");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b1&&(this.zpp_inner.b1!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b2!=this.zpp_inner.b1&&this.zpp_inner.b1.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b1.wake()),this.zpp_inner.b1=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b2!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get body2(){return this.zpp_inner.b2==null?null:nt._wrap(this.zpp_inner.b2)}set body2(e){this._setBody2(e)}_setBody2(e){this.zpp_inner.immutable_midstep("Constraint::body2");let t=e==null?null:e.zpp_inner;t!=this.zpp_inner.b2&&(this.zpp_inner.b2!=null&&(this.zpp_inner.space!=null&&this.zpp_inner.b1!=this.zpp_inner.b2&&this.zpp_inner.b2.constraints.remove(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&this.zpp_inner.b2.wake()),this.zpp_inner.b2=t,this.zpp_inner.space!=null&&t!=null&&this.zpp_inner.b1!=t&&t.constraints.add(this.zpp_inner),this.zpp_inner.active&&this.zpp_inner.space!=null&&(this.zpp_inner.wake(),t?.wake()))}get anchor1(){return this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1}set anchor1(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor1 cannot be null");this.zpp_inner.wrap_a1==null&&this.zpp_inner.setup_a1(),this.zpp_inner.wrap_a1.set(e),al(e)}get anchor2(){return this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2}set anchor2(e){if(e?.zpp_disp)throw new Error("Error: Vec2 has been disposed and cannot be used!");if(e==null)throw new Error("Error: Constraint::anchor2 cannot be null");this.zpp_inner.wrap_a2==null&&this.zpp_inner.setup_a2(),this.zpp_inner.wrap_a2.set(e),al(e)}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=T=>Ze(T,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,le 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,we 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,nt 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-Q5AJ7BUK.js.map