var box2d=window.box2d=function(_){"use strict";class D{}class O{constructor(t=.5,e=.5,i=.5,n=1){this.r=t,this.g=e,this.b=i,this.a=n}Clone(){return new O().Copy(this)}Copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this.a=t.a,this}IsEqual(t){return this.r===t.r&&this.g===t.g&&this.b===t.b&&this.a===t.a}IsZero(){return this.r===0&&this.g===0&&this.b===0&&this.a===0}Set(t,e,i,n=this.a){this.SetRGBA(t,e,i,n)}SetByteRGB(t,e,i){return this.r=t/255,this.g=e/255,this.b=i/255,this}SetByteRGBA(t,e,i,n){return this.r=t/255,this.g=e/255,this.b=i/255,this.a=n/255,this}SetRGB(t,e,i){return this.r=t,this.g=e,this.b=i,this}SetRGBA(t,e,i,n){return this.r=t,this.g=e,this.b=i,this.a=n,this}SelfAdd(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this.a+=t.a,this}Add(t,e){return e.r=this.r+t.r,e.g=this.g+t.g,e.b=this.b+t.b,e.a=this.a+t.a,e}SelfSub(t){return this.r-=t.r,this.g-=t.g,this.b-=t.b,this.a-=t.a,this}Sub(t,e){return e.r=this.r-t.r,e.g=this.g-t.g,e.b=this.b-t.b,e.a=this.a-t.a,e}SelfMul(t){return this.r*=t,this.g*=t,this.b*=t,this.a*=t,this}Mul(t,e){return e.r=this.r*t,e.g=this.g*t,e.b=this.b*t,e.a=this.a*t,e}Mix(t,e){O.MixColors(this,t,e)}static MixColors(t,e,i){const n=i*(e.r-t.r),o=i*(e.g-t.g),r=i*(e.b-t.b),h=i*(e.a-t.a);t.r+=n,t.g+=o,t.b+=r,t.a+=h,e.r-=n,e.g-=o,e.b-=r,e.a-=h}MakeStyleString(t=this.a){return O.MakeStyleString(this.r,this.g,this.b,t)}static MakeStyleString(t,e,i,n=1){return t*=255,e*=255,i*=255,n<1?`rgba(${t},${e},${i},${n})`:`rgb(${t},${e},${i})`}}O.ZERO=new O(0,0,0,0),O.RED=new O(1,0,0),O.GREEN=new O(0,1,0),O.BLUE=new O(0,0,1),_.b2DrawFlags=void 0,function(d){d[d.e_none=0]="e_none",d[d.e_shapeBit=1]="e_shapeBit",d[d.e_jointBit=2]="e_jointBit",d[d.e_aabbBit=4]="e_aabbBit",d[d.e_pairBit=8]="e_pairBit",d[d.e_centerOfMassBit=16]="e_centerOfMassBit",d[d.e_all=63]="e_all"}(_.b2DrawFlags||(_.b2DrawFlags={}));class zt{constructor(){this.m_drawFlags=0}SetFlags(t){this.m_drawFlags=t}GetFlags(){return this.m_drawFlags}AppendFlags(t){this.m_drawFlags|=t}ClearFlags(t){this.m_drawFlags&=~t}}function nt(d,...t){if(!d)throw new Error(...t)}function T(d,t){return d!==void 0?d:t}const M=1e37,ft=1e-5,rs=ft*ft,ut=3.14159265359,Ft=1,us=8,H=2,Kt=.1*Ft,xt=4,Q=.005*Ft,Dt=2/180*ut,Ct=2*Q,Qt=8,Nt=32,kt=.2*Ft,qt=8/180*ut,jt=2*Ft,Zt=jt*jt,Vt=.5*ut,p=Vt*Vt,w=.2,g=.75,L=.5,F=.01*Ft,K=2/180*ut;class wt{constructor(t=0,e=0,i=0){this.major=0,this.minor=0,this.revision=0,this.major=t,this.minor=e,this.revision=i}toString(){return this.major+"."+this.minor+"."+this.revision}}const Bt=new wt(2,4,1),hs="master",Js="9ebbbcd960ad424e03e5de6e66a40764c16f51bc";function Ne(d){return parseInt(d,10)}function Ze(d){return Math.abs(parseInt(d,10))}function Ut(d,t){const e=new Array(d);for(let i=0;inull),this.m_count=0}Reset(){return this.m_count=0,this}Push(t){this.m_stack[this.m_count]=t,this.m_count++}Pop(){this.m_count--;const t=this.m_stack[this.m_count];return this.m_stack[this.m_count]=null,t}GetCount(){return this.m_count}}const pe=ut/180,ye=180/ut,Ns=2*ut,ot=Math.abs;function at(d,t){return dt?d:t}function vt(d,t,e){return de?e:d}function We(d,t){const e=d[0];d[0]=t[0],t[0]=e}const He=isFinite;function ds(d){return d*d}function $e(d){return 1/Math.sqrt(d)}const ws=Math.sqrt,fe=Math.pow;function ti(d){return d*pe}function si(d){return d*ye}const ei=Math.cos,ii=Math.sin,ni=Math.acos,Ae=Math.asin,Gs=Math.atan2;function oi(d){return d|=d>>1&2147483647,d|=d>>2&1073741823,d|=d>>4&268435455,d|=d>>8&16777215,d|=d>>16&65535,d+1}function ri(d){return d>0&&(d&d-1)===0}function hi(){return Math.random()*2-1}function li(d,t){return(t-d)*Math.random()+d}class s{constructor(t=0,e=0){this.x=t,this.y=e}Clone(){return new s(this.x,this.y)}SetZero(){return this.x=0,this.y=0,this}Set(t,e){return this.x=t,this.y=e,this}Copy(t){return this.x=t.x,this.y=t.y,this}SelfAdd(t){return this.x+=t.x,this.y+=t.y,this}SelfAddXY(t,e){return this.x+=t,this.y+=e,this}SelfSub(t){return this.x-=t.x,this.y-=t.y,this}SelfSubXY(t,e){return this.x-=t,this.y-=e,this}SelfMul(t){return this.x*=t,this.y*=t,this}SelfMulAdd(t,e){return this.x+=t*e.x,this.y+=t*e.y,this}SelfMulSub(t,e){return this.x-=t*e.x,this.y-=t*e.y,this}Dot(t){return this.x*t.x+this.y*t.y}Cross(t){return this.x*t.y-this.y*t.x}Length(){const t=this.x,e=this.y;return Math.sqrt(t*t+e*e)}LengthSquared(){const t=this.x,e=this.y;return t*t+e*e}Normalize(){const t=this.Length();if(t>=ft){const e=1/t;this.x*=e,this.y*=e}return t}SelfNormalize(){const t=this.Length();if(t>=ft){const e=1/t;this.x*=e,this.y*=e}return this}SelfRotate(t){const e=Math.cos(t),i=Math.sin(t),n=this.x;return this.x=e*n-i*this.y,this.y=i*n+e*this.y,this}SelfRotateCosSin(t,e){const i=this.x;return this.x=t*i-e*this.y,this.y=e*i+t*this.y,this}IsValid(){return isFinite(this.x)&&isFinite(this.y)}SelfCrossVS(t){const e=this.x;return this.x=t*this.y,this.y=-t*e,this}SelfCrossSV(t){const e=this.x;return this.x=-t*this.y,this.y=t*e,this}SelfMinV(t){return this.x=at(this.x,t.x),this.y=at(this.y,t.y),this}SelfMaxV(t){return this.x=E(this.x,t.x),this.y=E(this.y,t.y),this}SelfAbs(){return this.x=ot(this.x),this.y=ot(this.y),this}SelfNeg(){return this.x=-this.x,this.y=-this.y,this}SelfSkew(){const t=this.x;return this.x=-this.y,this.y=t,this}static MakeArray(t){return Ut(t,e=>new s)}static AbsV(t,e){return e.x=ot(t.x),e.y=ot(t.y),e}static MinV(t,e,i){return i.x=at(t.x,e.x),i.y=at(t.y,e.y),i}static MaxV(t,e,i){return i.x=E(t.x,e.x),i.y=E(t.y,e.y),i}static ClampV(t,e,i,n){return n.x=vt(t.x,e.x,i.x),n.y=vt(t.y,e.y,i.y),n}static RotateV(t,e,i){const n=t.x,o=t.y,r=Math.cos(e),h=Math.sin(e);return i.x=r*n-h*o,i.y=h*n+r*o,i}static DotVV(t,e){return t.x*e.x+t.y*e.y}static CrossVV(t,e){return t.x*e.y-t.y*e.x}static CrossVS(t,e,i){const n=t.x;return i.x=e*t.y,i.y=-e*n,i}static CrossVOne(t,e){const i=t.x;return e.x=t.y,e.y=-i,e}static CrossSV(t,e,i){const n=e.x;return i.x=-t*e.y,i.y=t*n,i}static CrossOneV(t,e){const i=t.x;return e.x=-t.y,e.y=i,e}static AddVV(t,e,i){return i.x=t.x+e.x,i.y=t.y+e.y,i}static SubVV(t,e,i){return i.x=t.x-e.x,i.y=t.y-e.y,i}static MulSV(t,e,i){return i.x=e.x*t,i.y=e.y*t,i}static MulVS(t,e,i){return i.x=t.x*e,i.y=t.y*e,i}static AddVMulSV(t,e,i,n){return n.x=t.x+e*i.x,n.y=t.y+e*i.y,n}static SubVMulSV(t,e,i,n){return n.x=t.x-e*i.x,n.y=t.y-e*i.y,n}static AddVCrossSV(t,e,i,n){const o=i.x;return n.x=t.x-e*i.y,n.y=t.y+e*o,n}static MidVV(t,e,i){return i.x=(t.x+e.x)*.5,i.y=(t.y+e.y)*.5,i}static ExtVV(t,e,i){return i.x=(e.x-t.x)*.5,i.y=(e.y-t.y)*.5,i}static IsEqualToV(t,e){return t.x===e.x&&t.y===e.y}static DistanceVV(t,e){const i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)}static DistanceSquaredVV(t,e){const i=t.x-e.x,n=t.y-e.y;return i*i+n*n}static NegV(t,e){return e.x=-t.x,e.y=-t.y,e}}s.ZERO=new s(0,0),s.UNITX=new s(1,0),s.UNITY=new s(0,1),s.s_t0=new s,s.s_t1=new s,s.s_t2=new s,s.s_t3=new s;const _i=new s(0,0);class bt{constructor(...t){if(t[0]instanceof Float32Array){if(t[0].length!==3)throw new Error;this.data=t[0]}else{const e=typeof t[0]=="number"?t[0]:0,i=typeof t[1]=="number"?t[1]:0,n=typeof t[2]=="number"?t[2]:0;this.data=new Float32Array([e,i,n])}}get x(){return this.data[0]}set x(t){this.data[0]=t}get y(){return this.data[1]}set y(t){this.data[1]=t}get z(){return this.data[2]}set z(t){this.data[2]=t}Clone(){return new bt(this.x,this.y,this.z)}SetZero(){return this.x=0,this.y=0,this.z=0,this}SetXYZ(t,e,i){return this.x=t,this.y=e,this.z=i,this}Copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}SelfNeg(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}SelfAdd(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}SelfAddXYZ(t,e,i){return this.x+=t,this.y+=e,this.z+=i,this}SelfSub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}SelfSubXYZ(t,e,i){return this.x-=t,this.y-=e,this.z-=i,this}SelfMul(t){return this.x*=t,this.y*=t,this.z*=t,this}static DotV3V3(t,e){return t.x*e.x+t.y*e.y+t.z*e.z}static CrossV3V3(t,e,i){const n=t.x,o=t.y,r=t.z,h=e.x,l=e.y,y=e.z;return i.x=o*y-r*l,i.y=r*h-n*y,i.z=n*l-o*h,i}}bt.ZERO=new bt(0,0,0),bt.s_t0=new bt;class lt{constructor(){this.ex=new s(1,0),this.ey=new s(0,1)}Clone(){return new lt().Copy(this)}static FromVV(t,e){return new lt().SetVV(t,e)}static FromSSSS(t,e,i,n){return new lt().SetSSSS(t,e,i,n)}static FromAngle(t){return new lt().SetAngle(t)}SetSSSS(t,e,i,n){return this.ex.Set(t,i),this.ey.Set(e,n),this}SetVV(t,e){return this.ex.Copy(t),this.ey.Copy(e),this}SetAngle(t){const e=Math.cos(t),i=Math.sin(t);return this.ex.Set(e,i),this.ey.Set(-i,e),this}Copy(t){return this.ex.Copy(t.ex),this.ey.Copy(t.ey),this}SetIdentity(){return this.ex.Set(1,0),this.ey.Set(0,1),this}SetZero(){return this.ex.SetZero(),this.ey.SetZero(),this}GetAngle(){return Math.atan2(this.ex.y,this.ex.x)}GetInverse(t){const e=this.ex.x,i=this.ey.x,n=this.ex.y,o=this.ey.y;let r=e*o-i*n;return r!==0&&(r=1/r),t.ex.x=r*o,t.ey.x=-r*i,t.ex.y=-r*n,t.ey.y=r*e,t}Solve(t,e,i){const n=this.ex.x,o=this.ey.x,r=this.ex.y,h=this.ey.y;let l=n*h-o*r;return l!==0&&(l=1/l),i.x=l*(h*t-o*e),i.y=l*(n*e-r*t),i}SelfAbs(){return this.ex.SelfAbs(),this.ey.SelfAbs(),this}SelfInv(){return this.GetInverse(this),this}SelfAddM(t){return this.ex.SelfAdd(t.ex),this.ey.SelfAdd(t.ey),this}SelfSubM(t){return this.ex.SelfSub(t.ex),this.ey.SelfSub(t.ey),this}static AbsM(t,e){const i=t.ex,n=t.ey;return e.ex.x=ot(i.x),e.ex.y=ot(i.y),e.ey.x=ot(n.x),e.ey.y=ot(n.y),e}static MulMV(t,e,i){const n=t.ex,o=t.ey,r=e.x,h=e.y;return i.x=n.x*r+o.x*h,i.y=n.y*r+o.y*h,i}static MulTMV(t,e,i){const n=t.ex,o=t.ey,r=e.x,h=e.y;return i.x=n.x*r+n.y*h,i.y=o.x*r+o.y*h,i}static AddMM(t,e,i){const n=t.ex,o=t.ey,r=e.ex,h=e.ey;return i.ex.x=n.x+r.x,i.ex.y=n.y+r.y,i.ey.x=o.x+h.x,i.ey.y=o.y+h.y,i}static MulMM(t,e,i){const n=t.ex.x,o=t.ex.y,r=t.ey.x,h=t.ey.y,l=e.ex.x,y=e.ex.y,c=e.ey.x,m=e.ey.y;return i.ex.x=n*l+r*y,i.ex.y=o*l+h*y,i.ey.x=n*c+r*m,i.ey.y=o*c+h*m,i}static MulTMM(t,e,i){const n=t.ex.x,o=t.ex.y,r=t.ey.x,h=t.ey.y,l=e.ex.x,y=e.ex.y,c=e.ey.x,m=e.ey.y;return i.ex.x=n*l+o*y,i.ex.y=r*l+h*y,i.ey.x=n*c+o*m,i.ey.y=r*c+h*m,i}}lt.IDENTITY=new lt;class Yt{constructor(){this.data=new Float32Array([1,0,0,0,1,0,0,0,1]),this.ex=new bt(this.data.subarray(0,3)),this.ey=new bt(this.data.subarray(3,6)),this.ez=new bt(this.data.subarray(6,9))}Clone(){return new Yt().Copy(this)}SetVVV(t,e,i){return this.ex.Copy(t),this.ey.Copy(e),this.ez.Copy(i),this}Copy(t){return this.ex.Copy(t.ex),this.ey.Copy(t.ey),this.ez.Copy(t.ez),this}SetIdentity(){return this.ex.SetXYZ(1,0,0),this.ey.SetXYZ(0,1,0),this.ez.SetXYZ(0,0,1),this}SetZero(){return this.ex.SetZero(),this.ey.SetZero(),this.ez.SetZero(),this}SelfAddM(t){return this.ex.SelfAdd(t.ex),this.ey.SelfAdd(t.ey),this.ez.SelfAdd(t.ez),this}Solve33(t,e,i,n){const o=this.ex.x,r=this.ex.y,h=this.ex.z,l=this.ey.x,y=this.ey.y,c=this.ey.z,m=this.ez.x,a=this.ez.y,u=this.ez.z;let f=o*(y*u-c*a)+r*(c*m-l*u)+h*(l*a-y*m);return f!==0&&(f=1/f),n.x=f*(t*(y*u-c*a)+e*(c*m-l*u)+i*(l*a-y*m)),n.y=f*(o*(e*u-i*a)+r*(i*m-t*u)+h*(t*a-e*m)),n.z=f*(o*(y*i-c*e)+r*(c*t-l*i)+h*(l*e-y*t)),n}Solve22(t,e,i){const n=this.ex.x,o=this.ey.x,r=this.ex.y,h=this.ey.y;let l=n*h-o*r;return l!==0&&(l=1/l),i.x=l*(h*t-o*e),i.y=l*(n*e-r*t),i}GetInverse22(t){const e=this.ex.x,i=this.ey.x,n=this.ex.y,o=this.ey.y;let r=e*o-i*n;r!==0&&(r=1/r),t.ex.x=r*o,t.ey.x=-r*i,t.ex.z=0,t.ex.y=-r*n,t.ey.y=r*e,t.ey.z=0,t.ez.x=0,t.ez.y=0,t.ez.z=0}GetSymInverse33(t){let e=bt.DotV3V3(this.ex,bt.CrossV3V3(this.ey,this.ez,bt.s_t0));e!==0&&(e=1/e);const i=this.ex.x,n=this.ey.x,o=this.ez.x,r=this.ey.y,h=this.ez.y,l=this.ez.z;t.ex.x=e*(r*l-h*h),t.ex.y=e*(o*h-n*l),t.ex.z=e*(n*h-o*r),t.ey.x=t.ex.y,t.ey.y=e*(i*l-o*o),t.ey.z=e*(o*n-i*h),t.ez.x=t.ex.z,t.ez.y=t.ey.z,t.ez.z=e*(i*r-n*n)}static MulM33V3(t,e,i){const n=e.x,o=e.y,r=e.z;return i.x=t.ex.x*n+t.ey.x*o+t.ez.x*r,i.y=t.ex.y*n+t.ey.y*o+t.ez.y*r,i.z=t.ex.z*n+t.ey.z*o+t.ez.z*r,i}static MulM33XYZ(t,e,i,n,o){return o.x=t.ex.x*e+t.ey.x*i+t.ez.x*n,o.y=t.ex.y*e+t.ey.y*i+t.ez.y*n,o.z=t.ex.z*e+t.ey.z*i+t.ez.z*n,o}static MulM33V2(t,e,i){const n=e.x,o=e.y;return i.x=t.ex.x*n+t.ey.x*o,i.y=t.ex.y*n+t.ey.y*o,i}static MulM33XY(t,e,i,n){return n.x=t.ex.x*e+t.ey.x*i,n.y=t.ex.y*e+t.ey.y*i,n}}Yt.IDENTITY=new Yt;class C{constructor(t=0){this.s=0,this.c=1,t&&(this.s=Math.sin(t),this.c=Math.cos(t))}Clone(){return new C().Copy(this)}Copy(t){return this.s=t.s,this.c=t.c,this}SetAngle(t){return this.s=Math.sin(t),this.c=Math.cos(t),this}SetIdentity(){return this.s=0,this.c=1,this}GetAngle(){return Math.atan2(this.s,this.c)}GetXAxis(t){return t.x=this.c,t.y=this.s,t}GetYAxis(t){return t.x=-this.s,t.y=this.c,t}static MulRR(t,e,i){const n=t.c,o=t.s,r=e.c,h=e.s;return i.s=o*r+n*h,i.c=n*r-o*h,i}static MulTRR(t,e,i){const n=t.c,o=t.s,r=e.c,h=e.s;return i.s=n*h-o*r,i.c=n*r+o*h,i}static MulRV(t,e,i){const n=t.c,o=t.s,r=e.x,h=e.y;return i.x=n*r-o*h,i.y=o*r+n*h,i}static MulTRV(t,e,i){const n=t.c,o=t.s,r=e.x,h=e.y;return i.x=n*r+o*h,i.y=-o*r+n*h,i}}C.IDENTITY=new C;class I{constructor(){this.p=new s,this.q=new C}Clone(){return new I().Copy(this)}Copy(t){return this.p.Copy(t.p),this.q.Copy(t.q),this}SetIdentity(){return this.p.SetZero(),this.q.SetIdentity(),this}SetPositionRotation(t,e){return this.p.Copy(t),this.q.Copy(e),this}SetPositionAngle(t,e){return this.p.Copy(t),this.q.SetAngle(e),this}SetPosition(t){return this.p.Copy(t),this}SetPositionXY(t,e){return this.p.Set(t,e),this}SetRotation(t){return this.q.Copy(t),this}SetRotationAngle(t){return this.q.SetAngle(t),this}GetPosition(){return this.p}GetRotation(){return this.q}GetRotationAngle(){return this.q.GetAngle()}GetAngle(){return this.q.GetAngle()}static MulXV(t,e,i){const n=t.q.c,o=t.q.s,r=e.x,h=e.y;return i.x=n*r-o*h+t.p.x,i.y=o*r+n*h+t.p.y,i}static MulTXV(t,e,i){const n=t.q.c,o=t.q.s,r=e.x-t.p.x,h=e.y-t.p.y;return i.x=n*r+o*h,i.y=-o*r+n*h,i}static MulXX(t,e,i){return C.MulRR(t.q,e.q,i.q),s.AddVV(C.MulRV(t.q,e.p,i.p),t.p,i.p),i}static MulTXX(t,e,i){return C.MulTRR(t.q,e.q,i.q),C.MulTRV(t.q,s.SubVV(e.p,t.p,i.p),i.p),i}}I.IDENTITY=new I;class Gt{constructor(){this.localCenter=new s,this.c0=new s,this.c=new s,this.a0=0,this.a=0,this.alpha0=0}Clone(){return new Gt().Copy(this)}Copy(t){return this.localCenter.Copy(t.localCenter),this.c0.Copy(t.c0),this.c.Copy(t.c),this.a0=t.a0,this.a=t.a,this.alpha0=t.alpha0,this}GetTransform(t,e){t.p.x=(1-e)*this.c0.x+e*this.c.x,t.p.y=(1-e)*this.c0.y+e*this.c.y;const i=(1-e)*this.a0+e*this.a;return t.q.SetAngle(i),t.p.SelfSub(C.MulRV(t.q,this.localCenter,s.s_t0)),t}Advance(t){const e=(t-this.alpha0)/(1-this.alpha0);this.c0.SelfMulAdd(e,this.c.Clone().SelfSub(this.c0)),this.a0+=e*(this.a-this.a0),this.alpha0=t}Normalize(){const t=Ns*Math.floor(this.a0/Ns);this.a0-=t,this.a-=t}}class ai{}class ps{constructor(){this.m_start=Date.now()}Reset(){return this.m_start=Date.now(),this}GetMilliseconds(){return Date.now()-this.m_start}}class mi{constructor(){this.m_count=0,this.m_min_count=0,this.m_max_count=0}GetCount(){return this.m_count}GetMinCount(){return this.m_min_count}GetMaxCount(){return this.m_max_count}ResetCount(){const t=this.m_count;return this.m_count=0,t}ResetMinCount(){this.m_min_count=0}ResetMaxCount(){this.m_max_count=0}Increment(){this.m_count++,this.m_max_countthis.m_count&&(this.m_min_count=this.m_count)}}class Ls{constructor(){this.mass=0,this.center=new s(0,0),this.I=0}}_.b2ShapeType=void 0,function(d){d[d.e_unknown=-1]="e_unknown",d[d.e_circleShape=0]="e_circleShape",d[d.e_edgeShape=1]="e_edgeShape",d[d.e_polygonShape=2]="e_polygonShape",d[d.e_chainShape=3]="e_chainShape",d[d.e_shapeTypeCount=4]="e_shapeTypeCount"}(_.b2ShapeType||(_.b2ShapeType={}));class ls{constructor(t,e){this.m_type=_.b2ShapeType.e_unknown,this.m_radius=0,this.m_type=t,this.m_radius=e}Copy(t){return this.m_radius=t.m_radius,this}GetType(){return this.m_type}}class _s{constructor(){this.m_buffer=s.MakeArray(2),this.m_vertices=this.m_buffer,this.m_count=0,this.m_radius=0}Copy(t){return t.m_vertices===t.m_buffer?(this.m_vertices=this.m_buffer,this.m_buffer[0].Copy(t.m_buffer[0]),this.m_buffer[1].Copy(t.m_buffer[1])):this.m_vertices=t.m_vertices,this.m_count=t.m_count,this.m_radius=t.m_radius,this}Reset(){return this.m_vertices=this.m_buffer,this.m_count=0,this.m_radius=0,this}SetShape(t,e){t.SetupDistanceProxy(this,e)}SetVerticesRadius(t,e,i){this.m_vertices=t,this.m_count=e,this.m_radius=i}Set(...t){t[0]instanceof ls?this.SetShape(t[0],t[1]):this.SetVerticesRadius(t[0],t[1],t[2])}GetSupport(t){let e=0,i=s.DotVV(this.m_vertices[0],t);for(let n=1;ni&&(e=n,i=o)}return e}GetSupportVertex(t){let e=0,i=s.DotVV(this.m_vertices[0],t);for(let n=1;ni&&(e=n,i=o)}return this.m_vertices[e]}GetVertexCount(){return this.m_count}GetVertex(t){return this.m_vertices[t]}}class Zs{constructor(){this.metric=0,this.count=0,this.indexA=[0,0,0],this.indexB=[0,0,0]}Reset(){return this.metric=0,this.count=0,this}}class Us{constructor(){this.proxyA=new _s,this.proxyB=new _s,this.transformA=new I,this.transformB=new I,this.useRadii=!1}Reset(){return this.proxyA.Reset(),this.proxyB.Reset(),this.transformA.SetIdentity(),this.transformB.SetIdentity(),this.useRadii=!1,this}}class Ys{constructor(){this.pointA=new s,this.pointB=new s,this.distance=0,this.iterations=0}Reset(){return this.pointA.SetZero(),this.pointB.SetZero(),this.distance=0,this.iterations=0,this}}class ci{constructor(){this.proxyA=new _s,this.proxyB=new _s,this.transformA=new I,this.transformB=new I,this.translationB=new s}}class ui{constructor(){this.point=new s,this.normal=new s,this.lambda=0,this.iterations=0}}_.b2_gjkCalls=0,_.b2_gjkIters=0,_.b2_gjkMaxIters=0;function di(){_.b2_gjkCalls=0,_.b2_gjkIters=0,_.b2_gjkMaxIters=0}class Rs{constructor(){this.wA=new s,this.wB=new s,this.w=new s,this.a=0,this.indexA=0,this.indexB=0}Copy(t){return this.wA.Copy(t.wA),this.wB.Copy(t.wB),this.w.Copy(t.w),this.a=t.a,this.indexA=t.indexA,this.indexB=t.indexB,this}}class Jt{constructor(){this.m_v1=new Rs,this.m_v2=new Rs,this.m_v3=new Rs,this.m_vertices=[],this.m_count=0,this.m_vertices[0]=this.m_v1,this.m_vertices[1]=this.m_v2,this.m_vertices[2]=this.m_v3}ReadCache(t,e,i,n,o){this.m_count=t.count;const r=this.m_vertices;for(let h=0;h1){const h=t.metric,l=this.GetMetric();(l<.5*h||2*h0?s.CrossOneV(e,t):s.CrossVOne(e,t)}default:return t.SetZero()}}GetClosestPoint(t){switch(this.m_count){case 0:return t.SetZero();case 1:return t.Copy(this.m_v1.w);case 2:return t.Set(this.m_v1.a*this.m_v1.w.x+this.m_v2.a*this.m_v2.w.x,this.m_v1.a*this.m_v1.w.y+this.m_v2.a*this.m_v2.w.y);case 3:return t.SetZero();default:return t.SetZero()}}GetWitnessPoints(t,e){switch(this.m_count){case 0:break;case 1:t.Copy(this.m_v1.wA),e.Copy(this.m_v1.wB);break;case 2:t.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x,t.y=this.m_v1.a*this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y,e.x=this.m_v1.a*this.m_v1.wB.x+this.m_v2.a*this.m_v2.wB.x,e.y=this.m_v1.a*this.m_v1.wB.y+this.m_v2.a*this.m_v2.wB.y;break;case 3:e.x=t.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x+this.m_v3.a*this.m_v3.wA.x,e.y=t.y=this.m_v1.a*this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y+this.m_v3.a*this.m_v3.wA.y;break}}GetMetric(){switch(this.m_count){case 0:return 0;case 1:return 0;case 2:return s.DistanceVV(this.m_v1.w,this.m_v2.w);case 3:return s.CrossVV(s.SubVV(this.m_v2.w,this.m_v1.w,s.s_t0),s.SubVV(this.m_v3.w,this.m_v1.w,s.s_t1));default:return 0}}Solve2(){const t=this.m_v1.w,e=this.m_v2.w,i=s.SubVV(e,t,Jt.s_e12),n=-s.DotVV(t,i);if(n<=0){this.m_v1.a=1,this.m_count=1;return}const o=s.DotVV(e,i);if(o<=0){this.m_v2.a=1,this.m_count=1,this.m_v1.Copy(this.m_v2);return}const r=1/(o+n);this.m_v1.a=o*r,this.m_v2.a=n*r,this.m_count=2}Solve3(){const t=this.m_v1.w,e=this.m_v2.w,i=this.m_v3.w,n=s.SubVV(e,t,Jt.s_e12),o=s.DotVV(t,n),h=s.DotVV(e,n),l=-o,y=s.SubVV(i,t,Jt.s_e13),c=s.DotVV(t,y),a=s.DotVV(i,y),u=-c,f=s.SubVV(i,e,Jt.s_e23),A=s.DotVV(e,f),b=s.DotVV(i,f),B=-A,x=s.CrossVV(n,y),v=x*s.CrossVV(e,i),V=x*s.CrossVV(i,t),k=x*s.CrossVV(t,e);if(l<=0&&u<=0){this.m_v1.a=1,this.m_count=1;return}if(h>0&&l>0&&k<=0){const q=1/(h+l);this.m_v1.a=h*q,this.m_v2.a=l*q,this.m_count=2;return}if(a>0&&u>0&&V<=0){const q=1/(a+u);this.m_v1.a=a*q,this.m_v3.a=u*q,this.m_count=2,this.m_v2.Copy(this.m_v3);return}if(h<=0&&B<=0){this.m_v2.a=1,this.m_count=1,this.m_v1.Copy(this.m_v2);return}if(a<=0&&b<=0){this.m_v3.a=1,this.m_count=1,this.m_v1.Copy(this.m_v3);return}if(b>0&&B>0&&v<=0){const q=1/(b+B);this.m_v2.a=b*q,this.m_v3.a=B*q,this.m_count=2,this.m_v1.Copy(this.m_v3);return}const P=1/(v+V+k);this.m_v1.a=v*P,this.m_v2.a=V*P,this.m_v3.a=k*P,this.m_count=3}}Jt.s_e12=new s,Jt.s_e13=new s,Jt.s_e23=new s;const pi=new Jt,yi=[0,0,0],fi=[0,0,0],Ai=new s,Si=new s,wi=new s,Bi=new s,bi=new s;function Ks(d,t,e){++_.b2_gjkCalls;const i=e.proxyA,n=e.proxyB,o=e.transformA,r=e.transformB,h=pi;h.ReadCache(t,i,o,n,r);const l=h.m_vertices,y=20,c=yi,m=fi;let a=0,u=0;for(;uf+A&&d.distance>ft){d.distance-=f+A;const S=s.SubVV(d.pointB,d.pointA,wi);S.Normalize(),d.pointA.SelfMulAdd(f,S),d.pointB.SelfMulSub(A,S)}else{const S=s.MidVV(d.pointA,d.pointB,Ai);d.pointA.Copy(S),d.pointB.Copy(S),d.distance=0}}}const xi=new s,Ci=new Jt,Se=new s,we=new s,Vi=new s,vi=new s,gi=new s,Mi=new s;function Ii(d,t){d.iterations=0,d.lambda=1,d.normal.SetZero(),d.point.SetZero();const e=t.proxyA,i=t.proxyB,n=E(e.m_radius,Ct),o=E(i.m_radius,Ct),r=n+o,h=t.transformA,l=t.transformB,y=t.translationB,c=xi.Set(0,0);let m=0;const a=Ci;a.m_count=0;const u=a.m_vertices;let f=e.GetSupport(C.MulTRV(h.q,s.NegV(y,s.s_t1),s.s_t0)),A=I.MulXV(h,e.GetVertex(f),Se),S=i.GetSupport(C.MulTRV(l.q,y,s.s_t0)),b=I.MulXV(l,i.GetVertex(S),we);const B=s.SubVV(A,b,Vi),x=E(Ct,r-Ct),v=.5*Q,V=20;let k=0;for(;kv;){d.iterations+=1,f=e.GetSupport(C.MulTRV(h.q,s.NegV(B,s.s_t1),s.s_t0)),A=I.MulXV(h,e.GetVertex(f),Se),S=i.GetSupport(C.MulTRV(l.q,B,s.s_t0)),b=I.MulXV(l,i.GetVertex(S),we);const z=s.SubVV(A,b,vi);B.Normalize();const j=s.DotVV(B,z),Y=s.DotVV(B,y);if(j-x>m*Y){if(Y<=0||(m=(j-x)/Y,m>1))return!1;c.Copy(B).SelfNeg(),a.m_count=0}const R=u[a.m_count];switch(R.indexA=S,R.wA.Copy(b).SelfMulAdd(m,y),R.indexB=f,R.wB.Copy(A),R.w.Copy(R.wB).SelfSub(R.wA),R.a=1,a.m_count+=1,a.m_count){case 1:break;case 2:a.Solve2();break;case 3:a.Solve3();break}if(a.m_count===3)return!1;a.GetClosestPoint(B),++k}if(k===0)return!1;const P=gi,q=Mi;return a.GetWitnessPoints(P,q),B.LengthSquared()>0&&(c.Copy(B).SelfNeg(),c.Normalize()),d.normal.Copy(c),d.lambda=m,d.iterations=k,!0}_.b2ContactFeatureType=void 0,function(d){d[d.e_vertex=0]="e_vertex",d[d.e_face=1]="e_face"}(_.b2ContactFeatureType||(_.b2ContactFeatureType={}));class Be{constructor(){this._key=0,this._key_invalid=!1,this._indexA=0,this._indexB=0,this._typeA=0,this._typeB=0}get key(){return this._key_invalid&&(this._key_invalid=!1,this._key=this._indexA|this._indexB<<8|this._typeA<<16|this._typeB<<24),this._key}set key(t){this._key=t,this._key_invalid=!1,this._indexA=this._key&255,this._indexB=this._key>>8&255,this._typeA=this._key>>16&255,this._typeB=this._key>>24&255}get indexA(){return this._indexA}set indexA(t){this._indexA=t,this._key_invalid=!0}get indexB(){return this._indexB}set indexB(t){this._indexB=t,this._key_invalid=!0}get typeA(){return this._typeA}set typeA(t){this._typeA=t,this._key_invalid=!0}get typeB(){return this._typeB}set typeB(t){this._typeB=t,this._key_invalid=!0}}class ys{constructor(){this.cf=new Be}Copy(t){return this.key=t.key,this}Clone(){return new ys().Copy(this)}get key(){return this.cf.key}set key(t){this.cf.key=t}}class Fs{constructor(){this.localPoint=new s,this.normalImpulse=0,this.tangentImpulse=0,this.id=new ys}static MakeArray(t){return Ut(t,e=>new Fs)}Reset(){this.localPoint.SetZero(),this.normalImpulse=0,this.tangentImpulse=0,this.id.key=0}Copy(t){return this.localPoint.Copy(t.localPoint),this.normalImpulse=t.normalImpulse,this.tangentImpulse=t.tangentImpulse,this.id.Copy(t.id),this}}_.b2ManifoldType=void 0,function(d){d[d.e_unknown=-1]="e_unknown",d[d.e_circles=0]="e_circles",d[d.e_faceA=1]="e_faceA",d[d.e_faceB=2]="e_faceB"}(_.b2ManifoldType||(_.b2ManifoldType={}));class Bs{constructor(){this.points=Fs.MakeArray(H),this.localNormal=new s,this.localPoint=new s,this.type=_.b2ManifoldType.e_unknown,this.pointCount=0}Reset(){for(let t=0;trs&&s.SubVV(h,r,this.normal).SelfNormalize();const l=s.AddVMulSV(r,i,this.normal,dt.Initialize_s_cA),y=s.SubVMulSV(h,o,this.normal,dt.Initialize_s_cB);s.MidVV(l,y,this.points[0]),this.separations[0]=s.DotVV(s.SubVV(y,l,s.s_t0),this.normal);break}case _.b2ManifoldType.e_faceA:{C.MulRV(e.q,t.localNormal,this.normal);const r=I.MulXV(e,t.localPoint,dt.Initialize_s_planePoint);for(let h=0;hnew gt)}Copy(t){return this.v.Copy(t.v),this.id.Copy(t.id),this}}class ks{constructor(){this.p1=new s,this.p2=new s,this.maxFraction=1}Copy(t){return this.p1.Copy(t.p1),this.p2.Copy(t.p2),this.maxFraction=t.maxFraction,this}}class be{constructor(){this.normal=new s,this.fraction=0}Copy(t){return this.normal.Copy(t.normal),this.fraction=t.fraction,this}}class Et{constructor(){this.lowerBound=new s,this.upperBound=new s,this.m_cache_center=new s,this.m_cache_extent=new s}Copy(t){return this.lowerBound.Copy(t.lowerBound),this.upperBound.Copy(t.upperBound),this}IsValid(){return!(!this.lowerBound.IsValid()||!this.upperBound.IsValid()||this.upperBound.xf){const S=u;u=f,f=S,A=1}if(u>i&&(m.x=A,m.y=0,i=u),n=at(n,f),i>n)return!1}if(cf){const S=u;u=f,f=S,A=1}if(u>i&&(m.x=0,m.y=A,i=u),n=at(n,f),i>n)return!1}return i<0||e.maxFraction0;){const o=n.Pop();if(o!==null&&o.aabb.TestOverlap(e))if(o.IsLeaf()){if(!i(o))return}else n.Push(o.child1),n.Push(o.child2)}}QueryPoint(t,e){const i=this.m_stack.Reset();for(i.Push(this.m_root);i.GetCount()>0;){const n=i.Pop();if(n!==null&&n.aabb.TestContain(t))if(n.IsLeaf()){if(!e(n))return}else i.Push(n.child1),i.Push(n.child2)}}RayCast(...t){let e,i;t[0]instanceof ks?(i=t[0],e=t[1]):(i=t[1],e=t[0]);const n=i.p1,o=i.p2,r=s.SubVV(o,n,et.s_r);r.Normalize();const h=s.CrossOneV(r,et.s_v),l=s.AbsV(h,et.s_abs_v);let y=i.maxFraction;const c=et.s_segmentAABB;let m=n.x+y*(o.x-n.x),a=n.y+y*(o.y-n.y);c.lowerBound.x=at(n.x,m),c.lowerBound.y=at(n.y,a),c.upperBound.x=E(n.x,m),c.upperBound.y=E(n.y,a);const u=this.m_stack.Reset();for(u.Push(this.m_root);u.GetCount()>0;){const f=u.Pop();if(f===null||!Qs(f.aabb,c))continue;const A=f.aabb.GetCenter(),S=f.aabb.GetExtents();if(!(ot(s.DotVV(h,s.SubVV(n,A,s.s_t0)))-s.DotVV(l,S)>0))if(f.IsLeaf()){const B=et.s_subInput;B.p1.Copy(i.p1),B.p2.Copy(i.p2),B.maxFraction=y;const x=e(B,f);if(x===0)return;x>0&&(y=x,m=n.x+y*(o.x-n.x),a=n.y+y*(o.y-n.y),c.lowerBound.x=at(n.x,m),c.lowerBound.y=at(n.y,a),c.upperBound.x=E(n.x,m),c.upperBound.y=E(n.y,a))}else u.Push(f.child1),u.Push(f.child2)}}AllocateNode(){if(this.m_freeList!==null){const t=this.m_freeList;return this.m_freeList=t.parent,t.parent=null,t.child1=null,t.child2=null,t.height=0,t.moved=!1,t}return new xe(et.s_node_id++)}FreeNode(t){t.parent=this.m_freeList,t.child1=null,t.child2=null,t.height=-1,t.Reset(),this.m_freeList=t}CreateProxy(t,e){const i=this.AllocateNode(),n=Kt,o=Kt;return i.aabb.lowerBound.x=t.lowerBound.x-n,i.aabb.lowerBound.y=t.lowerBound.y-o,i.aabb.upperBound.x=t.upperBound.x+n,i.aabb.upperBound.y=t.upperBound.y+o,i.userData=e,i.height=0,i.moved=!0,this.InsertLeaf(i),i}DestroyProxy(t){this.RemoveLeaf(t),this.FreeNode(t)}MoveProxy(t,e,i){const n=et.MoveProxy_s_fatAABB,o=Kt,r=Kt;n.lowerBound.x=e.lowerBound.x-o,n.lowerBound.y=e.lowerBound.y-r,n.upperBound.x=e.upperBound.x+o,n.upperBound.y=e.upperBound.y+r;const h=xt*i.x,l=xt*i.y;h<0?n.lowerBound.x+=h:n.upperBound.x+=h,l<0?n.lowerBound.y+=l:n.upperBound.y+=l;const y=t.aabb;if(y.Contains(e)){const c=et.MoveProxy_s_hugeAABB;if(c.lowerBound.x=n.lowerBound.x-4*o,c.lowerBound.y=n.lowerBound.y-4*r,c.upperBound.x=n.upperBound.x+4*o,c.upperBound.y=n.upperBound.y+4*r,c.Contains(y))return!1}return this.RemoveLeaf(t),t.aabb.Copy(n),this.InsertLeaf(t),t.moved=!0,!0}InsertLeaf(t){if(++this.m_insertionCount,this.m_root===null){this.m_root=t,this.m_root.parent=null;return}const e=t.aabb;let i=this.m_root;for(;!i.IsLeaf();){const h=yt(i.child1),l=yt(i.child2),y=i.aabb.GetPerimeter(),c=et.s_combinedAABB;c.Combine2(i.aabb,e);const m=c.GetPerimeter(),a=2*m,u=2*(m-y);let f;const A=et.s_aabb;let S,b;h.IsLeaf()?(A.Combine2(e,h.aabb),f=A.GetPerimeter()+u):(A.Combine2(e,h.aabb),S=h.aabb.GetPerimeter(),b=A.GetPerimeter(),f=b-S+u);let B;if(l.IsLeaf()?(A.Combine2(e,l.aabb),B=A.GetPerimeter()+u):(A.Combine2(e,l.aabb),S=l.aabb.GetPerimeter(),b=A.GetPerimeter(),B=b-S+u),a1){const o=yt(i.child1),r=yt(i.child2);return i.child1=t,i.parent=t.parent,t.parent=i,i.parent!==null?i.parent.child1===t?i.parent.child1=i:i.parent.child2=i:this.m_root=i,o.height>r.height?(i.child2=o,t.child2=r,r.parent=t,t.aabb.Combine2(e.aabb,r.aabb),i.aabb.Combine2(t.aabb,o.aabb),t.height=1+E(e.height,r.height),i.height=1+E(t.height,o.height)):(i.child2=r,t.child2=o,o.parent=t,t.aabb.Combine2(e.aabb,o.aabb),i.aabb.Combine2(t.aabb,r.aabb),t.height=1+E(e.height,o.height),i.height=1+E(t.height,r.height)),i}if(n<-1){const o=yt(e.child1),r=yt(e.child2);return e.child1=t,e.parent=t.parent,t.parent=e,e.parent!==null?e.parent.child1===t?e.parent.child1=e:e.parent.child2=e:this.m_root=e,o.height>r.height?(e.child2=o,t.child1=r,r.parent=t,t.aabb.Combine2(i.aabb,r.aabb),e.aabb.Combine2(t.aabb,o.aabb),t.height=1+E(i.height,r.height),e.height=1+E(t.height,o.height)):(e.child2=r,t.child1=o,o.parent=t,t.aabb.Combine2(i.aabb,o.aabb),e.aabb.Combine2(t.aabb,r.aabb),t.height=1+E(i.height,o.height),e.height=1+E(t.height,r.height)),e}return t}GetHeight(){return this.m_root===null?0:this.m_root.height}static GetAreaNode(t){if(t===null||t.IsLeaf())return 0;let e=t.aabb.GetPerimeter();return e+=et.GetAreaNode(t.child1),e+=et.GetAreaNode(t.child2),e}GetAreaRatio(){if(this.m_root===null)return 0;const e=this.m_root.aabb.GetPerimeter();return et.GetAreaNode(this.m_root)/e}static ComputeHeightNode(t){if(t===null||t.IsLeaf())return 0;const e=et.ComputeHeightNode(t.child1),i=et.ComputeHeightNode(t.child2);return 1+E(e,i)}ComputeHeight(){return et.ComputeHeightNode(this.m_root)}ValidateStructure(t){if(t===null||(this.m_root,t.IsLeaf()))return;const e=yt(t.child1),i=yt(t.child2);this.ValidateStructure(e),this.ValidateStructure(i)}ValidateMetrics(t){if(t===null||t.IsLeaf())return;const e=yt(t.child1),i=yt(t.child2);et.s_aabb.Combine2(e.aabb,i.aabb),this.ValidateMetrics(e),this.ValidateMetrics(i)}Validate(){}static GetMaxBalanceNode(t,e){if(t===null||t.height<=1)return e;const i=yt(t.child1),n=yt(t.child2),o=ot(n.height-i.height);return E(e,o)}GetMaxBalance(){return et.GetMaxBalanceNode(this.m_root,0)}RebuildBottomUp(){this.Validate()}static ShiftOriginNode(t,e){if(t===null||t.height<=1)return;const i=t.child1,n=t.child2;et.ShiftOriginNode(i,e),et.ShiftOriginNode(n,e),t.aabb.lowerBound.SelfSub(e),t.aabb.upperBound.SelfSub(e)}ShiftOrigin(t){et.ShiftOriginNode(this.m_root,t)}}et.s_r=new s,et.s_v=new s,et.s_abs_v=new s,et.s_segmentAABB=new Et,et.s_subInput=new ks,et.s_combinedAABB=new Et,et.s_aabb=new Et,et.s_node_id=0,et.MoveProxy_s_fatAABB=new Et,et.MoveProxy_s_hugeAABB=new Et;class Ce{constructor(t,e){this.proxyA=t,this.proxyB=e}}class Ve{constructor(){this.m_tree=new et,this.m_proxyCount=0,this.m_moveCount=0,this.m_moveBuffer=[],this.m_pairCount=0,this.m_pairBuffer=[]}CreateProxy(t,e){const i=this.m_tree.CreateProxy(t,e);return++this.m_proxyCount,this.BufferMove(i),i}DestroyProxy(t){this.UnBufferMove(t),--this.m_proxyCount,this.m_tree.DestroyProxy(t)}MoveProxy(t,e,i){this.m_tree.MoveProxy(t,e,i)&&this.BufferMove(t)}TouchProxy(t){this.BufferMove(t)}GetProxyCount(){return this.m_proxyCount}UpdatePairs(t){this.m_pairCount=0;for(let e=0;e{if(o.m_id===i.m_id||o.moved&&o.m_id>i.m_id)return!0;let h,l;if(o.m_id0)return!1;const u=s.DotVV(m,h);if(u===0)return!1;const f=a/u;if(f<0||e.maxFraction0&&t.normal.SelfNeg(),!0)}ComputeAABB(t,e,i){const n=I.MulXV(e,this.m_vertex1,mt.ComputeAABB_s_v1),o=I.MulXV(e,this.m_vertex2,mt.ComputeAABB_s_v2);s.MinV(n,o,t.lowerBound),s.MaxV(n,o,t.upperBound);const r=this.m_radius;t.lowerBound.SelfSubXY(r,r),t.upperBound.SelfAddXY(r,r)}ComputeMass(t,e){t.mass=0,s.MidVV(this.m_vertex1,this.m_vertex2,t.center),t.I=0}SetupDistanceProxy(t,e){t.m_vertices=t.m_buffer,t.m_vertices[0].Copy(this.m_vertex1),t.m_vertices[1].Copy(this.m_vertex2),t.m_count=2,t.m_radius=this.m_radius}ComputeSubmergedArea(t,e,i,n){return n.SetZero(),0}Dump(t){t(` const shape: b2EdgeShape = new b2EdgeShape(); `),t(` shape.m_radius = %.15f; `,this.m_radius),t(` shape.m_vertex0.Set(%.15f, %.15f); `,this.m_vertex0.x,this.m_vertex0.y),t(` shape.m_vertex1.Set(%.15f, %.15f); `,this.m_vertex1.x,this.m_vertex1.y),t(` shape.m_vertex2.Set(%.15f, %.15f); `,this.m_vertex2.x,this.m_vertex2.y),t(` shape.m_vertex3.Set(%.15f, %.15f); `,this.m_vertex3.x,this.m_vertex3.y),t(` shape.m_oneSided = %s; `,this.m_oneSided)}}mt.RayCast_s_p1=new s,mt.RayCast_s_p2=new s,mt.RayCast_s_d=new s,mt.RayCast_s_e=new s,mt.RayCast_s_q=new s,mt.RayCast_s_r=new s,mt.ComputeAABB_s_v1=new s,mt.ComputeAABB_s_v2=new s;class Lt extends ls{constructor(){super(_.b2ShapeType.e_chainShape,Ct),this.m_vertices=[],this.m_count=0,this.m_prevVertex=new s,this.m_nextVertex=new s}CreateLoop(...t){if(typeof t[0][0]=="number"){const e=t[0];if(e.length%2!==0)throw new Error;return this._CreateLoop(i=>({x:e[i*2],y:e[i*2+1]}),e.length/2)}else{const e=t[0],i=t[1]||e.length;return this._CreateLoop(n=>e[n],i)}}_CreateLoop(t,e){if(e<3)return this;this.m_count=e+1,this.m_vertices=s.MakeArray(this.m_count);for(let i=0;i({x:e[o*2],y:e[o*2+1]}),e.length/2,i,n)}else{const e=t[0],i=t[1]||e.length,n=t[2],o=t[3];return this._CreateChain(r=>e[r],i,n,o)}}_CreateChain(t,e,i,n){this.m_count=e,this.m_vertices=s.MakeArray(e);for(let o=0;ot.m_vertices[e],t.m_count,t.m_prevVertex,t.m_nextVertex),this.m_prevVertex.Copy(t.m_prevVertex),this.m_nextVertex.Copy(t.m_nextVertex),this}GetChildCount(){return this.m_count-1}GetChildEdge(t,e){t.m_radius=this.m_radius,t.m_vertex1.Copy(this.m_vertices[e]),t.m_vertex2.Copy(this.m_vertices[e+1]),t.m_oneSided=!0,e>0?t.m_vertex0.Copy(this.m_vertices[e-1]):t.m_vertex0.Copy(this.m_prevVertex),ethis.m_radius)return n.Copy(o),ut*this.m_radius*this.m_radius;const h=this.m_radius*this.m_radius,l=r*r,y=h*(Ae(r/this.m_radius)+ut/2)+r*ws(h-l),c=-2/3*fe(h-l,1.5)/y;return n.x=o.x+t.x*c,n.y=o.y+t.y*c,y}Dump(t){t(` const shape: b2CircleShape = new b2CircleShape(); `),t(` shape.m_radius = %.15f; `,this.m_radius),t(` shape.m_p.Set(%.15f, %.15f); `,this.m_p.x,this.m_p.y)}}Mt.TestPoint_s_center=new s,Mt.TestPoint_s_d=new s,Mt.RayCast_s_position=new s,Mt.RayCast_s_s=new s,Mt.RayCast_s_r=new s,Mt.ComputeAABB_s_p=new s;const Li=new s,Ri=new s;function ve(d,t,e,i,n){d.pointCount=0;const o=I.MulXV(e,t.m_p,Li),r=I.MulXV(n,i.m_p,Ri),h=s.DistanceSquaredVV(o,r),l=t.m_radius+i.m_radius;h>l*l||(d.type=_.b2ManifoldType.e_circles,d.localPoint.Copy(t.m_p),d.localNormal.SetZero(),d.pointCount=1,d.points[0].localPoint.Copy(i.m_p),d.points[0].id.key=0)}const Fi=new s,ki=new s,qi=new s;function ge(d,t,e,i,n){d.pointCount=0;const o=I.MulXV(n,i.m_p,Fi),r=I.MulTXV(e,o,ki);let h=0,l=-M;const y=t.m_radius+i.m_radius,c=t.m_count,m=t.m_vertices,a=t.m_normals;for(let x=0;xy)return;v>l&&(l=v,h=x)}const u=h,f=(u+1)%c,A=m[u],S=m[f];if(ly*y)return;d.pointCount=1,d.type=_.b2ManifoldType.e_faceA,s.SubVV(r,A,d.localNormal).SelfNormalize(),d.localPoint.Copy(A),d.points[0].localPoint.Copy(i.m_p),d.points[0].id.key=0}else if(B<=0){if(s.DistanceSquaredVV(r,S)>y*y)return;d.pointCount=1,d.type=_.b2ManifoldType.e_faceA,s.SubVV(r,S,d.localNormal).SelfNormalize(),d.localPoint.Copy(S),d.points[0].localPoint.Copy(i.m_p),d.points[0].id.key=0}else{const x=s.MidVV(A,S,qi);if(s.DotVV(s.SubVV(r,x,s.s_t1),a[u])>y)return;d.pointCount=1,d.type=_.b2ManifoldType.e_faceA,d.localNormal.Copy(a[u]).SelfNormalize(),d.localPoint.Copy(x),d.points[0].localPoint.Copy(i.m_p),d.points[0].id.key=0}}const ji=new s,Ei=new s,Hs=new s,Oi=new s,Xi=new s,zi=new s,Ji=new s,Ni=new ys;function $s(d,t,e,i,n){d.pointCount=0;const o=I.MulTXV(e,I.MulXV(n,i.m_p,s.s_t0),ji),r=t.m_vertex1,h=t.m_vertex2,l=s.SubVV(h,r,Ei),y=Ji.Set(l.y,-l.x),c=s.DotVV(y,s.SubVV(o,r,s.s_t0));if(t.m_oneSided&&c<0)return;const a=s.DotVV(l,s.SubVV(h,o,s.s_t0)),u=s.DotVV(l,s.SubVV(o,r,s.s_t0)),f=t.m_radius+i.m_radius,A=Ni;if(A.cf.indexB=0,A.cf.typeB=_.b2ContactFeatureType.e_vertex,u<=0){const v=r,V=s.SubVV(o,v,Hs);if(s.DotVV(V,V)>f*f)return;if(t.m_oneSided){const P=t.m_vertex0,q=r,z=s.SubVV(q,P,Oi);if(s.DotVV(z,s.SubVV(q,o,s.s_t0))>0)return}A.cf.indexA=0,A.cf.typeA=_.b2ContactFeatureType.e_vertex,d.pointCount=1,d.type=_.b2ManifoldType.e_circles,d.localNormal.SetZero(),d.localPoint.Copy(v),d.points[0].id.Copy(A),d.points[0].localPoint.Copy(i.m_p);return}if(a<=0){const v=h,V=s.SubVV(o,v,Hs);if(s.DotVV(V,V)>f*f)return;if(t.m_oneSided){const P=t.m_vertex3,q=h,z=s.SubVV(P,q,Xi);if(s.DotVV(z,s.SubVV(o,q,s.s_t0))>0)return}A.cf.indexA=1,A.cf.typeA=_.b2ContactFeatureType.e_vertex,d.pointCount=1,d.type=_.b2ManifoldType.e_circles,d.localNormal.SetZero(),d.localPoint.Copy(v),d.points[0].id.Copy(A),d.points[0].localPoint.Copy(i.m_p);return}const S=s.DotVV(l,l),b=zi;b.x=1/S*(a*r.x+u*h.x),b.y=1/S*(a*r.y+u*h.y);const B=s.SubVV(o,b,Hs);s.DotVV(B,B)>f*f||(c<0&&y.Set(-y.x,-y.y),y.Normalize(),A.cf.indexA=0,A.cf.typeA=_.b2ContactFeatureType.e_face,d.pointCount=1,d.type=_.b2ManifoldType.e_faceA,d.localNormal.Copy(y),d.localPoint.Copy(r),d.points[0].id.Copy(A),d.points[0].localPoint.Copy(i.m_p))}var Wt;(function(d){d[d.e_unknown=0]="e_unknown",d[d.e_edgeA=1]="e_edgeA",d[d.e_edgeB=2]="e_edgeB"})(Wt||(Wt={}));class Me{constructor(){this.normal=new s,this.type=Wt.e_unknown,this.index=0,this.separation=0}}class Zi{constructor(){this.vertices=[],this.normals=[],this.count=0}}class Ui{constructor(){this.i1=0,this.i2=0,this.v1=new s,this.v2=new s,this.normal=new s,this.sideNormal1=new s,this.sideOffset1=0,this.sideNormal2=new s,this.sideOffset2=0}}const Yi=new Me,Ki=[new s,new s];function Qi(d,t,e){const i=Yi;i.type=Wt.e_edgeA,i.index=-1,i.separation=-Number.MAX_VALUE,i.normal.SetZero();const n=Ki;n[0].Copy(e),n[1].Copy(e).SelfNeg();for(let o=0;o<2;++o){let r=Number.MAX_VALUE;for(let h=0;hi.separation&&(i.index=o,i.separation=r,i.normal.Copy(n[o]))}return i}const Wi=new Me,Hi=new s;function $i(d,t,e){const i=Wi;i.type=Wt.e_unknown,i.index=-1,i.separation=-Number.MAX_VALUE,i.normal.SetZero();for(let n=0;ni.separation&&(i.type=Wt.e_edgeB,i.index=n,i.separation=l,i.normal.Copy(o))}return i}const tn=new I,sn=new s,en=new s,nn=new s,on=new s,rn=new s,hn=new s,ln=new s,_n=new Zi,an=new Ui,mn=[new gt,new gt],cn=[new gt,new gt],un=[new gt,new gt];function te(d,t,e,i,n){d.pointCount=0;const o=I.MulTXX(e,n,tn),r=I.MulXV(o,i.m_centroid,sn),h=t.m_vertex1,l=t.m_vertex2,y=s.SubVV(l,h,en);y.Normalize();const c=nn.Set(y.y,-y.x),m=s.DotVV(c,s.SubVV(r,h,s.s_t0)),a=t.m_oneSided;if(a&&m<0)return;const u=_n;u.count=i.m_count;for(let j=0;jf)return;const S=$i(u,h,l);if(S.separation>f)return;const b=.98,B=.001;let x;if(S.separation-f>b*(A.separation-f)+B?x=S:x=A,a){const j=s.SubVV(h,t.m_vertex0,on);j.Normalize();const Y=rn.Set(j.y,-j.x),R=s.CrossVV(j,y)>=0,G=s.SubVV(t.m_vertex3,l,hn);G.Normalize();const Z=ln.Set(G.y,-G.x),U=s.CrossVV(y,G)>=0,it=.1;if(s.DotVV(x.normal,y)<=0)if(R){if(s.CrossVV(x.normal,Y)>it)return}else x=A;else if(U){if(s.CrossVV(Z,x.normal)>it)return}else x=A}const v=mn,V=an;if(x.type===Wt.e_edgeA){d.type=_.b2ManifoldType.e_faceA;let j=0,Y=s.DotVV(x.normal,u.normals[0]);for(let Z=1;Za&&(a=S,m=u)}return d[0]=m,a}const fn=new s;function An(d,t,e,i,n,o){const r=t.m_normals,h=n.m_count,l=n.m_vertices,y=n.m_normals,c=C.MulTRV(o.q,C.MulRV(e.q,r[i],s.s_t0),fn);let m=0,a=M;for(let x=0;xo)return;const l=xn;l[0]=0;const y=Ie(l,i,n,t,e);if(y>o)return;let c,m,a,u,f=0,A=0;const S=.1*Q;y>h+S?(c=i,m=t,a=n,u=e,f=l[0],d.type=_.b2ManifoldType.e_faceB,A=1):(c=t,m=i,a=e,u=n,f=r[0],d.type=_.b2ManifoldType.e_faceA,A=0);const b=Sn;An(b,c,a,f,m,u);const B=c.m_count,x=c.m_vertices,v=f,V=f+1({x:e[i*2],y:e[i*2+1]}),e.length/2)}else{const e=t[0],i=t[1]||e.length;return this._Set(n=>e[n],i)}}_Set(t,e){if(e<3)return this.SetAsBox(1,1);let i=e;const n=[];for(let c=0;cr||m===r&&n[c].ya.LengthSquared()&&(c=m)}if(++l,y=c,c===o)break}this.m_count=l,this.m_vertices=s.MakeArray(this.m_count),this.m_normals=s.MakeArray(this.m_count);for(let c=0;c0)return!1;return!0}RayCast(t,e,i,n){const o=I.MulTXV(i,e.p1,J.RayCast_s_p1),r=I.MulTXV(i,e.p2,J.RayCast_s_p2),h=s.SubVV(r,o,J.RayCast_s_d);let l=0,y=e.maxFraction,c=-1;for(let m=0;m0&&a=0?(t.fraction=l,C.MulRV(i.q,this.m_normals[c],t.normal),!0):!1}ComputeAABB(t,e,i){const n=I.MulXV(e,this.m_vertices[0],t.lowerBound),o=t.upperBound.Copy(n);for(let h=0;h0&&(q?m||(y=P-1,l++):m&&(c=P-1,l++)),m=q}switch(l){case 0:if(m){const P=J.ComputeSubmergedArea_s_md;return this.ComputeMass(P,1),I.MulXV(i,P.center,n),P.mass}else return 0;case 1:y===-1?y=this.m_count-1:c=this.m_count-1;break}const a=(y+1)%this.m_count,u=(c+1)%this.m_count,f=(0-h[y])/(h[a]-h[y]),A=(0-h[c])/(h[u]-h[c]),S=J.ComputeSubmergedArea_s_intoVec.Set(this.m_vertices[y].x*(1-f)+this.m_vertices[a].x*f,this.m_vertices[y].y*(1-f)+this.m_vertices[a].y*f),b=J.ComputeSubmergedArea_s_outoVec.Set(this.m_vertices[c].x*(1-A)+this.m_vertices[u].x*A,this.m_vertices[c].y*(1-A)+this.m_vertices[u].y*A);let B=0;const x=J.ComputeSubmergedArea_s_center.SetZero();let v=this.m_vertices[a],V,k=a;for(;k!==u;){k=(k+1)%this.m_count,k===u?V=b:V=this.m_vertices[k];const P=.5*((v.x-S.x)*(V.y-S.y)-(v.y-S.y)*(V.x-S.x));B+=P,x.x+=P*(S.x+v.x+V.x)/3,x.y+=P*(S.y+v.y+V.y)/3,v=V}return x.SelfMul(1/B),I.MulXV(i,x,n),B}Dump(t){t(` const shape: b2PolygonShape = new b2PolygonShape(); `),t(` const vs: b2Vec2[] = []; `);for(let e=0;ec+m){d.state=_.b2TOIOutputState.e_separated,d.t=l,k=!0;break}if(Y>c-m){a=P;break}let R=V.Evaluate(z[0],j[0],a);if(Rc?(Z=it,R=rt):(U=it,Y=rt),G===50)break}if(_.b2_toiMaxRootIters=E(_.b2_toiMaxRootIters,G),++q,q===o)break}if(++f,++_.b2_toiIters,k)break;if(f===u){d.state=_.b2TOIOutputState.e_failed,d.t=a;break}}_.b2_toiMaxIters=E(_.b2_toiMaxIters,f);const b=e.GetMilliseconds();_.b2_toiMaxTime=E(_.b2_toiMaxTime,b),_.b2_toiTime+=b}_.b2JointType=void 0,function(d){d[d.e_unknownJoint=0]="e_unknownJoint",d[d.e_revoluteJoint=1]="e_revoluteJoint",d[d.e_prismaticJoint=2]="e_prismaticJoint",d[d.e_distanceJoint=3]="e_distanceJoint",d[d.e_pulleyJoint=4]="e_pulleyJoint",d[d.e_mouseJoint=5]="e_mouseJoint",d[d.e_gearJoint=6]="e_gearJoint",d[d.e_wheelJoint=7]="e_wheelJoint",d[d.e_weldJoint=8]="e_weldJoint",d[d.e_frictionJoint=9]="e_frictionJoint",d[d.e_ropeJoint=10]="e_ropeJoint",d[d.e_motorJoint=11]="e_motorJoint",d[d.e_areaJoint=12]="e_areaJoint"}(_.b2JointType||(_.b2JointType={}));class Xn{constructor(){this.linear=new s,this.angularA=0,this.angularB=0}SetZero(){return this.linear.SetZero(),this.angularA=0,this.angularB=0,this}Set(t,e,i){return this.linear.Copy(t),this.angularA=e,this.angularB=i,this}}class ne{constructor(t){this._other=null,this.prev=null,this.next=null,this.joint=t}get other(){if(this._other===null)throw new Error;return this._other}set other(t){if(this._other!==null)throw new Error;this._other=t}Reset(){this._other=null,this.prev=null,this.next=null}}class Ot{constructor(t){this.type=_.b2JointType.e_unknownJoint,this.userData=null,this.collideConnected=!1,this.type=t}}function zn(d,t,e,i,n){const o=i.GetMass(),r=n.GetMass();let h;o>0&&r>0?h=o*r/(o+r):o>0?h=o:h=r;const l=2*ut*t;d.stiffness=h*l*l,d.damping=2*h*e*l}function Jn(d,t,e,i,n){const o=i.GetInertia(),r=n.GetInertia();let h;o>0&&r>0?h=o*r/(o+r):o>0?h=o:h=r;const l=2*ut*t;d.stiffness=h*l*l,d.damping=2*h*e*l}class pt{constructor(t){this.m_type=_.b2JointType.e_unknownJoint,this.m_prev=null,this.m_next=null,this.m_edgeA=new ne(this),this.m_edgeB=new ne(this),this.m_index=0,this.m_islandFlag=!1,this.m_collideConnected=!1,this.m_userData=null,this.m_type=t.type,this.m_edgeA.other=t.bodyB,this.m_edgeB.other=t.bodyA,this.m_bodyA=t.bodyA,this.m_bodyB=t.bodyB,this.m_collideConnected=T(t.collideConnected,!1),this.m_userData=T(t.userData,null)}GetType(){return this.m_type}GetBodyA(){return this.m_bodyA}GetBodyB(){return this.m_bodyB}GetNext(){return this.m_next}GetUserData(){return this.m_userData}SetUserData(t){this.m_userData=t}IsEnabled(){return this.m_bodyA.IsEnabled()&&this.m_bodyB.IsEnabled()}GetCollideConnected(){return this.m_collideConnected}Dump(t){t(`// Dump is not supported for this joint type. `)}ShiftOrigin(t){}Draw(t){const e=this.m_bodyA.GetTransform(),i=this.m_bodyB.GetTransform(),n=e.p,o=i.p,r=this.GetAnchorA(pt.Draw_s_p1),h=this.GetAnchorB(pt.Draw_s_p2),l=pt.Draw_s_color.SetRGB(.5,.8,.8);switch(this.m_type){case _.b2JointType.e_distanceJoint:t.DrawSegment(r,h,l);break;case _.b2JointType.e_pulleyJoint:{const y=this,c=y.GetGroundAnchorA(),m=y.GetGroundAnchorB();t.DrawSegment(c,r,l),t.DrawSegment(m,h,l),t.DrawSegment(c,m,l)}break;case _.b2JointType.e_mouseJoint:{const y=pt.Draw_s_c;y.Set(0,1,0),t.DrawPoint(r,4,y),t.DrawPoint(h,4,y),y.Set(.8,.8,.8),t.DrawSegment(r,h,y)}break;default:t.DrawSegment(n,r,l),t.DrawSegment(r,h,l),t.DrawSegment(o,h,l)}}}pt.Draw_s_p1=new s,pt.Draw_s_p2=new s,pt.Draw_s_color=new O(.5,.8,.8),pt.Draw_s_c=new O;class Le extends Ot{constructor(){super(_.b2JointType.e_distanceJoint),this.localAnchorA=new s,this.localAnchorB=new s,this.length=1,this.minLength=0,this.maxLength=M,this.stiffness=0,this.damping=0}Initialize(t,e,i,n){this.bodyA=t,this.bodyB=e,this.bodyA.GetLocalPoint(i,this.localAnchorA),this.bodyB.GetLocalPoint(n,this.localAnchorB),this.length=E(s.DistanceVV(i,n),Q),this.minLength=this.length,this.maxLength=this.length}}class W extends pt{constructor(t){super(t),this.m_stiffness=0,this.m_damping=0,this.m_bias=0,this.m_length=0,this.m_minLength=0,this.m_maxLength=0,this.m_localAnchorA=new s,this.m_localAnchorB=new s,this.m_gamma=0,this.m_impulse=0,this.m_lowerImpulse=0,this.m_upperImpulse=0,this.m_indexA=0,this.m_indexB=0,this.m_u=new s,this.m_rA=new s,this.m_rB=new s,this.m_localCenterA=new s,this.m_localCenterB=new s,this.m_currentLength=0,this.m_invMassA=0,this.m_invMassB=0,this.m_invIA=0,this.m_invIB=0,this.m_softMass=0,this.m_mass=0,this.m_qA=new C,this.m_qB=new C,this.m_lalcA=new s,this.m_lalcB=new s,this.m_localAnchorA.Copy(T(t.localAnchorA,s.ZERO)),this.m_localAnchorB.Copy(T(t.localAnchorB,s.ZERO)),this.m_length=E(T(t.length,this.GetCurrentLength()),Q),this.m_minLength=E(T(t.minLength,this.m_length),Q),this.m_maxLength=E(T(t.maxLength,this.m_length),this.m_minLength),this.m_stiffness=T(t.stiffness,0),this.m_damping=T(t.damping,0)}GetAnchorA(t){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA,t)}GetAnchorB(t){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB,t)}GetReactionForce(t,e){return e.x=t*(this.m_impulse+this.m_lowerImpulse-this.m_upperImpulse)*this.m_u.x,e.y=t*(this.m_impulse+this.m_lowerImpulse-this.m_upperImpulse)*this.m_u.y,e}GetReactionTorque(t){return 0}GetLocalAnchorA(){return this.m_localAnchorA}GetLocalAnchorB(){return this.m_localAnchorB}SetLength(t){return this.m_impulse=0,this.m_length=E(Q,t),this.m_length}GetLength(){return this.m_length}SetMinLength(t){return this.m_lowerImpulse=0,this.m_minLength=vt(t,Q,this.m_maxLength),this.m_minLength}SetMaxLength(t){return this.m_upperImpulse=0,this.m_maxLength=E(t,this.m_minLength),this.m_maxLength}GetCurrentLength(){const t=this.m_bodyA.GetWorldPoint(this.m_localAnchorA,new s),e=this.m_bodyB.GetWorldPoint(this.m_localAnchorB,new s);return s.DistanceVV(t,e)}SetStiffness(t){this.m_stiffness=t}GetStiffness(){return this.m_stiffness}SetDamping(t){this.m_damping=t}GetDamping(){return this.m_damping}Dump(t){const e=this.m_bodyA.m_islandIndex,i=this.m_bodyB.m_islandIndex;t(` const jd: b2DistanceJointDef = new b2DistanceJointDef(); `),t(` jd.bodyA = bodies[%d]; `,e),t(` jd.bodyB = bodies[%d]; `,i),t(` jd.collideConnected = %s; `,this.m_collideConnected?"true":"false"),t(` jd.localAnchorA.Set(%.15f, %.15f); `,this.m_localAnchorA.x,this.m_localAnchorA.y),t(` jd.localAnchorB.Set(%.15f, %.15f); `,this.m_localAnchorB.x,this.m_localAnchorB.y),t(` jd.length = %.15f; `,this.m_length),t(` jd.minLength = %.15f; `,this.m_minLength),t(` jd.maxLength = %.15f; `,this.m_maxLength),t(` jd.stiffness = %.15f; `,this.m_stiffness),t(` jd.damping = %.15f; `,this.m_damping),t(` joints[%d] = this.m_world.CreateJoint(jd); `,this.m_index)}InitVelocityConstraints(t){this.m_indexA=this.m_bodyA.m_islandIndex,this.m_indexB=this.m_bodyB.m_islandIndex,this.m_localCenterA.Copy(this.m_bodyA.m_sweep.localCenter),this.m_localCenterB.Copy(this.m_bodyB.m_sweep.localCenter),this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;const e=t.positions[this.m_indexA].c,i=t.positions[this.m_indexA].a,n=t.velocities[this.m_indexA].v;let o=t.velocities[this.m_indexA].w;const r=t.positions[this.m_indexB].c,h=t.positions[this.m_indexB].a,l=t.velocities[this.m_indexB].v;let y=t.velocities[this.m_indexB].w;const c=this.m_qA.SetAngle(i),m=this.m_qB.SetAngle(h);s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA),C.MulRV(c,this.m_lalcA,this.m_rA),s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB),C.MulRV(m,this.m_lalcB,this.m_rB),this.m_u.x=r.x+this.m_rB.x-e.x-this.m_rA.x,this.m_u.y=r.y+this.m_rB.y-e.y-this.m_rA.y,this.m_currentLength=this.m_u.Length(),this.m_currentLength>Q?this.m_u.SelfMul(1/this.m_currentLength):(this.m_u.SetZero(),this.m_mass=0,this.m_impulse=0,this.m_lowerImpulse=0,this.m_upperImpulse=0);const a=s.CrossVV(this.m_rA,this.m_u),u=s.CrossVV(this.m_rB,this.m_u);let f=this.m_invMassA+this.m_invIA*a*a+this.m_invMassB+this.m_invIB*u*u;if(this.m_mass=f!==0?1/f:0,this.m_stiffness>0&&this.m_minLength0){const r=s.AddVCrossSV(e,i,this.m_rA,W.SolveVelocityConstraints_s_vpA),h=s.AddVCrossSV(n,o,this.m_rB,W.SolveVelocityConstraints_s_vpB),l=s.DotVV(this.m_u,s.SubVV(h,r,s.s_t0)),y=-this.m_softMass*(l+this.m_bias+this.m_gamma*this.m_impulse);this.m_impulse+=y;const c=s.MulSV(y,this.m_u,W.SolveVelocityConstraints_s_P);e.SelfMulSub(this.m_invMassA,c),i-=this.m_invIA*s.CrossVV(this.m_rA,c),n.SelfMulAdd(this.m_invMassB,c),o+=this.m_invIB*s.CrossVV(this.m_rB,c)}{const r=this.m_currentLength-this.m_minLength,h=E(0,r)*t.step.inv_dt,l=s.AddVCrossSV(e,i,this.m_rA,W.SolveVelocityConstraints_s_vpA),y=s.AddVCrossSV(n,o,this.m_rB,W.SolveVelocityConstraints_s_vpB),c=s.DotVV(this.m_u,s.SubVV(y,l,s.s_t0));let m=-this.m_mass*(c+h);const a=this.m_lowerImpulse;this.m_lowerImpulse=E(0,this.m_lowerImpulse+m),m=this.m_lowerImpulse-a;const u=s.MulSV(m,this.m_u,W.SolveVelocityConstraints_s_P);e.SelfMulSub(this.m_invMassA,u),i-=this.m_invIA*s.CrossVV(this.m_rA,u),n.SelfMulAdd(this.m_invMassB,u),o+=this.m_invIB*s.CrossVV(this.m_rB,u)}{const r=this.m_maxLength-this.m_currentLength,h=E(0,r)*t.step.inv_dt,l=s.AddVCrossSV(e,i,this.m_rA,W.SolveVelocityConstraints_s_vpA),y=s.AddVCrossSV(n,o,this.m_rB,W.SolveVelocityConstraints_s_vpB),c=s.DotVV(this.m_u,s.SubVV(l,y,s.s_t0));let m=-this.m_mass*(c+h);const a=this.m_upperImpulse;this.m_upperImpulse=E(0,this.m_upperImpulse+m),m=this.m_upperImpulse-a;const u=s.MulSV(-m,this.m_u,W.SolveVelocityConstraints_s_P);e.SelfMulSub(this.m_invMassA,u),i-=this.m_invIA*s.CrossVV(this.m_rA,u),n.SelfMulAdd(this.m_invMassB,u),o+=this.m_invIB*s.CrossVV(this.m_rB,u)}}else{const r=s.AddVCrossSV(e,i,this.m_rA,W.SolveVelocityConstraints_s_vpA),h=s.AddVCrossSV(n,o,this.m_rB,W.SolveVelocityConstraints_s_vpB),l=s.DotVV(this.m_u,s.SubVV(h,r,s.s_t0)),y=-this.m_mass*l;this.m_impulse+=y;const c=s.MulSV(y,this.m_u,W.SolveVelocityConstraints_s_P);e.SelfMulSub(this.m_invMassA,c),i-=this.m_invIA*s.CrossVV(this.m_rA,c),n.SelfMulAdd(this.m_invMassB,c),o+=this.m_invIB*s.CrossVV(this.m_rB,c)}t.velocities[this.m_indexA].w=i,t.velocities[this.m_indexB].w=o}SolvePositionConstraints(t){const e=t.positions[this.m_indexA].c;let i=t.positions[this.m_indexA].a;const n=t.positions[this.m_indexB].c;let o=t.positions[this.m_indexB].a;const r=this.m_qA.SetAngle(i),h=this.m_qB.SetAngle(o),l=C.MulRV(r,this.m_lalcA,this.m_rA),y=C.MulRV(h,this.m_lalcB,this.m_rB),c=this.m_u;c.x=n.x+y.x-e.x-l.x,c.y=n.y+y.y-e.y-l.y;const m=this.m_u.Normalize();let a;if(this.m_minLength==this.m_maxLength)a=m-this.m_minLength;else if(mQ){const a=s.AddVMulSV(n,this.m_minLength,r,W.Draw_s_pMin);t.DrawPoint(a,4,l)}if(this.m_maxLengthds(kt)&&m.SelfMul(kt/ws(a)),a>ds(Q)&&(r=!1),y.x+=m.x,y.y+=m.y}return r}}class os{constructor(){this.categoryBits=1,this.maskBits=65535,this.groupIndex=0}Clone(){return new os().Copy(this)}Copy(t){return this.categoryBits=t.categoryBits,this.maskBits=t.maskBits,this.groupIndex=t.groupIndex||0,this}}os.DEFAULT=new os;class Fe{constructor(){this.userData=null,this.friction=.2,this.restitution=0,this.restitutionThreshold=1*Ft,this.density=0,this.isSensor=!1,this.filter=new os}}class ts{constructor(t,e){this.aabb=new Et,this.childIndex=0,this.fixture=t,this.childIndex=e,this.fixture.m_shape.ComputeAABB(this.aabb,this.fixture.m_body.GetTransform(),e),this.treeNode=this.fixture.m_body.m_world.m_contactManager.m_broadPhase.CreateProxy(this.aabb,this)}Reset(){this.fixture.m_body.m_world.m_contactManager.m_broadPhase.DestroyProxy(this.treeNode)}Touch(){this.fixture.m_body.m_world.m_contactManager.m_broadPhase.TouchProxy(this.treeNode)}Synchronize(t,e){if(t===e)this.fixture.m_shape.ComputeAABB(this.aabb,t,this.childIndex),this.fixture.m_body.m_world.m_contactManager.m_broadPhase.MoveProxy(this.treeNode,this.aabb,s.ZERO);else{const i=ts.Synchronize_s_aabb1,n=ts.Synchronize_s_aabb2;this.fixture.m_shape.ComputeAABB(i,t,this.childIndex),this.fixture.m_shape.ComputeAABB(n,e,this.childIndex),this.aabb.Combine2(i,n);const o=ts.Synchronize_s_displacement;o.Copy(n.GetCenter()).SelfSub(i.GetCenter()),this.fixture.m_body.m_world.m_contactManager.m_broadPhase.MoveProxy(this.treeNode,this.aabb,o)}}}ts.Synchronize_s_aabb1=new Et,ts.Synchronize_s_aabb2=new Et,ts.Synchronize_s_displacement=new s;class ke{constructor(t,e){this.m_density=0,this.m_next=null,this.m_friction=0,this.m_restitution=0,this.m_restitutionThreshold=1*Ft,this.m_proxies=[],this.m_filter=new os,this.m_isSensor=!1,this.m_userData=null,this.m_body=t,this.m_shape=e.shape.Clone(),this.m_userData=T(e.userData,null),this.m_friction=T(e.friction,.2),this.m_restitution=T(e.restitution,0),this.m_restitutionThreshold=T(e.restitutionThreshold,0),this.m_filter.Copy(T(e.filter,os.DEFAULT)),this.m_isSensor=T(e.isSensor,!1),this.m_density=T(e.density,0)}get m_proxyCount(){return this.m_proxies.length}Create(t,e,i){}Destroy(){}Reset(){}GetType(){return this.m_shape.GetType()}GetShape(){return this.m_shape}SetSensor(t){t!==this.m_isSensor&&(this.m_body.SetAwake(!0),this.m_isSensor=t)}IsSensor(){return this.m_isSensor}SetFilterData(t){this.m_filter.Copy(t),this.Refilter()}GetFilterData(){return this.m_filter}Refilter(){let t=this.m_body.GetContactList();for(;t;){const e=t.contact,i=e.GetFixtureA(),n=e.GetFixtureB();(i===this||n===this)&&e.FlagForFiltering(),t=t.next}this.TouchProxies()}GetBody(){return this.m_body}GetNext(){return this.m_next}GetUserData(){return this.m_userData}SetUserData(t){this.m_userData=t}TestPoint(t){return this.m_shape.TestPoint(this.m_body.GetTransform(),t)}RayCast(t,e,i){return this.m_shape.RayCast(t,e,this.m_body.GetTransform(),i)}GetMassData(t=new Ls){return this.m_shape.ComputeMass(t,this.m_density),t}SetDensity(t){this.m_density=t}GetDensity(){return this.m_density}GetFriction(){return this.m_friction}SetFriction(t){this.m_friction=t}GetRestitution(){return this.m_restitution}SetRestitution(t){this.m_restitution=t}GetRestitutionThreshold(){return this.m_restitutionThreshold}SetRestitutionThreshold(t){this.m_restitutionThreshold=t}GetAABB(t){return this.m_proxies[t].aabb}Dump(t,e){t(` const fd: b2FixtureDef = new b2FixtureDef(); `),t(` fd.friction = %.15f; `,this.m_friction),t(` fd.restitution = %.15f; `,this.m_restitution),t(` fd.restitutionThreshold = %.15f; `,this.m_restitutionThreshold),t(` fd.density = %.15f; `,this.m_density),t(` fd.isSensor = %s; `,this.m_isSensor?"true":"false"),t(` fd.filter.categoryBits = %d; `,this.m_filter.categoryBits),t(` fd.filter.maskBits = %d; `,this.m_filter.maskBits),t(` fd.filter.groupIndex = %d; `,this.m_filter.groupIndex),this.m_shape.Dump(t),t(` `),t(` fd.shape = shape; `),t(` `),t(` bodies[%d].CreateFixture(fd); `,e)}CreateProxies(){if(this.m_proxies.length!==0)throw new Error;for(let t=0;t0&&this.ResetMassData(),this.m_world.m_newContacts=!0,e}CreateFixtureShapeDensity(t,e=0){const i=It.CreateFixtureShapeDensity_s_def;return i.shape=t,i.density=e,this.CreateFixtureDef(i)}DestroyFixture(t){if(this.m_world.IsLocked())throw new Error;let e=this.m_fixtureList,i=null;for(;e!==null;){if(e===t){i?i.m_next=t.m_next:this.m_fixtureList=t.m_next;break}i=e,e=e.m_next}let n=this.m_contactList;for(;n;){const o=n.contact;n=n.next;const r=o.GetFixtureA(),h=o.GetFixtureB();(t===r||t===h)&&this.m_world.m_contactManager.Destroy(o)}this.m_enabledFlag&&t.DestroyProxies(),t.m_next=null,t.Reset(),--this.m_fixtureCount,this.ResetMassData()}SetTransformVec(t,e){this.SetTransformXY(t.x,t.y,e)}SetTransformXY(t,e,i){if(this.m_world.IsLocked())throw new Error;this.m_xf.q.SetAngle(i),this.m_xf.p.Set(t,e),I.MulXV(this.m_xf,this.m_sweep.localCenter,this.m_sweep.c),this.m_sweep.a=i,this.m_sweep.c0.Copy(this.m_sweep.c),this.m_sweep.a0=i;for(let n=this.m_fixtureList;n;n=n.m_next)n.SynchronizeProxies(this.m_xf,this.m_xf);this.m_world.m_newContacts=!0}SetTransform(t,e){this.SetTransformXY(t.x,t.y,e)}GetTransform(){return this.m_xf}GetPosition(){return this.m_xf.p}SetPosition(t){this.SetTransformVec(t,this.GetAngle())}SetPositionXY(t,e){this.SetTransformXY(t,e,this.GetAngle())}GetAngle(){return this.m_sweep.a}SetAngle(t){this.SetTransformVec(this.GetPosition(),t)}GetWorldCenter(){return this.m_sweep.c}GetLocalCenter(){return this.m_sweep.localCenter}SetLinearVelocity(t){this.m_type!==_.b2BodyType.b2_staticBody&&(s.DotVV(t,t)>0&&this.SetAwake(!0),this.m_linearVelocity.Copy(t))}GetLinearVelocity(){return this.m_linearVelocity}SetAngularVelocity(t){this.m_type!==_.b2BodyType.b2_staticBody&&(t*t>0&&this.SetAwake(!0),this.m_angularVelocity=t)}GetAngularVelocity(){return this.m_angularVelocity}GetDefinition(t){return t.type=this.GetType(),t.allowSleep=this.m_autoSleepFlag,t.angle=this.GetAngle(),t.angularDamping=this.m_angularDamping,t.gravityScale=this.m_gravityScale,t.angularVelocity=this.m_angularVelocity,t.fixedRotation=this.m_fixedRotationFlag,t.bullet=this.m_bulletFlag,t.awake=this.m_awakeFlag,t.linearDamping=this.m_linearDamping,t.linearVelocity.Copy(this.GetLinearVelocity()),t.position.Copy(this.GetPosition()),t.userData=this.GetUserData(),t}ApplyForce(t,e,i=!0){this.m_type===_.b2BodyType.b2_dynamicBody&&(i&&!this.m_awakeFlag&&this.SetAwake(!0),this.m_awakeFlag&&(this.m_force.x+=t.x,this.m_force.y+=t.y,this.m_torque+=(e.x-this.m_sweep.c.x)*t.y-(e.y-this.m_sweep.c.y)*t.x))}ApplyForceToCenter(t,e=!0){this.m_type===_.b2BodyType.b2_dynamicBody&&(e&&!this.m_awakeFlag&&this.SetAwake(!0),this.m_awakeFlag&&(this.m_force.x+=t.x,this.m_force.y+=t.y))}ApplyTorque(t,e=!0){this.m_type===_.b2BodyType.b2_dynamicBody&&(e&&!this.m_awakeFlag&&this.SetAwake(!0),this.m_awakeFlag&&(this.m_torque+=t))}ApplyLinearImpulse(t,e,i=!0){this.m_type===_.b2BodyType.b2_dynamicBody&&(i&&!this.m_awakeFlag&&this.SetAwake(!0),this.m_awakeFlag&&(this.m_linearVelocity.x+=this.m_invMass*t.x,this.m_linearVelocity.y+=this.m_invMass*t.y,this.m_angularVelocity+=this.m_invI*((e.x-this.m_sweep.c.x)*t.y-(e.y-this.m_sweep.c.y)*t.x)))}ApplyLinearImpulseToCenter(t,e=!0){this.m_type===_.b2BodyType.b2_dynamicBody&&(e&&!this.m_awakeFlag&&this.SetAwake(!0),this.m_awakeFlag&&(this.m_linearVelocity.x+=this.m_invMass*t.x,this.m_linearVelocity.y+=this.m_invMass*t.y))}ApplyAngularImpulse(t,e=!0){this.m_type===_.b2BodyType.b2_dynamicBody&&(e&&!this.m_awakeFlag&&this.SetAwake(!0),this.m_awakeFlag&&(this.m_angularVelocity+=this.m_invI*t))}GetMass(){return this.m_mass}GetInertia(){return this.m_I+this.m_mass*s.DotVV(this.m_sweep.localCenter,this.m_sweep.localCenter)}GetMassData(t){return t.mass=this.m_mass,t.I=this.m_I+this.m_mass*s.DotVV(this.m_sweep.localCenter,this.m_sweep.localCenter),t.center.Copy(this.m_sweep.localCenter),t}SetMassData(t){if(this.m_world.IsLocked())throw new Error;if(this.m_type!==_.b2BodyType.b2_dynamicBody)return;this.m_invMass=0,this.m_I=0,this.m_invI=0,this.m_mass=t.mass,this.m_mass<=0&&(this.m_mass=1),this.m_invMass=1/this.m_mass,t.I>0&&!this.m_fixedRotationFlag&&(this.m_I=t.I-this.m_mass*s.DotVV(t.center,t.center),this.m_invI=1/this.m_I);const e=It.SetMassData_s_oldCenter.Copy(this.m_sweep.c);this.m_sweep.localCenter.Copy(t.center),I.MulXV(this.m_xf,this.m_sweep.localCenter,this.m_sweep.c),this.m_sweep.c0.Copy(this.m_sweep.c),s.AddVCrossSV(this.m_linearVelocity,this.m_angularVelocity,s.SubVV(this.m_sweep.c,e,s.s_t0),this.m_linearVelocity)}ResetMassData(){if(this.m_mass=0,this.m_invMass=0,this.m_I=0,this.m_invI=0,this.m_sweep.localCenter.SetZero(),this.m_type===_.b2BodyType.b2_staticBody||this.m_type===_.b2BodyType.b2_kinematicBody){this.m_sweep.c0.Copy(this.m_xf.p),this.m_sweep.c.Copy(this.m_xf.p),this.m_sweep.a0=this.m_sweep.a;return}const t=It.ResetMassData_s_localCenter.SetZero();for(let i=this.m_fixtureList;i;i=i.m_next){if(i.m_density===0)continue;const n=i.GetMassData(It.ResetMassData_s_massData);this.m_mass+=n.mass,t.x+=n.center.x*n.mass,t.y+=n.center.y*n.mass,this.m_I+=n.I}this.m_mass>0&&(this.m_invMass=1/this.m_mass,t.x*=this.m_invMass,t.y*=this.m_invMass),this.m_I>0&&!this.m_fixedRotationFlag?(this.m_I-=this.m_mass*s.DotVV(t,t),this.m_invI=1/this.m_I):(this.m_I=0,this.m_invI=0);const e=It.ResetMassData_s_oldCenter.Copy(this.m_sweep.c);this.m_sweep.localCenter.Copy(t),I.MulXV(this.m_xf,this.m_sweep.localCenter,this.m_sweep.c),this.m_sweep.c0.Copy(this.m_sweep.c),s.AddVCrossSV(this.m_linearVelocity,this.m_angularVelocity,s.SubVV(this.m_sweep.c,e,s.s_t0),this.m_linearVelocity)}GetWorldPoint(t,e){return I.MulXV(this.m_xf,t,e)}GetWorldVector(t,e){return C.MulRV(this.m_xf.q,t,e)}GetLocalPoint(t,e){return I.MulTXV(this.m_xf,t,e)}GetLocalVector(t,e){return C.MulTRV(this.m_xf.q,t,e)}GetLinearVelocityFromWorldPoint(t,e){return s.AddVCrossSV(this.m_linearVelocity,this.m_angularVelocity,s.SubVV(t,this.m_sweep.c,s.s_t0),e)}GetLinearVelocityFromLocalPoint(t,e){return this.GetLinearVelocityFromWorldPoint(this.GetWorldPoint(t,e),e)}GetLinearDamping(){return this.m_linearDamping}SetLinearDamping(t){this.m_linearDamping=t}GetAngularDamping(){return this.m_angularDamping}SetAngularDamping(t){this.m_angularDamping=t}GetGravityScale(){return this.m_gravityScale}SetGravityScale(t){this.m_gravityScale=t}SetType(t){if(this.m_world.IsLocked())throw new Error;if(this.m_type===t)return;this.m_type=t,this.ResetMassData(),this.m_type===_.b2BodyType.b2_staticBody&&(this.m_linearVelocity.SetZero(),this.m_angularVelocity=0,this.m_sweep.a0=this.m_sweep.a,this.m_sweep.c0.Copy(this.m_sweep.c),this.m_awakeFlag=!1,this.SynchronizeFixtures()),this.SetAwake(!0),this.m_force.SetZero(),this.m_torque=0;let e=this.m_contactList;for(;e;){const i=e;e=e.next,this.m_world.m_contactManager.Destroy(i.contact)}this.m_contactList=null;for(let i=this.m_fixtureList;i;i=i.m_next)i.TouchProxies()}GetType(){return this.m_type}SetBullet(t){this.m_bulletFlag=t}IsBullet(){return this.m_bulletFlag}SetSleepingAllowed(t){this.m_autoSleepFlag=t,t||this.SetAwake(!0)}IsSleepingAllowed(){return this.m_autoSleepFlag}SetAwake(t){this.m_type!==_.b2BodyType.b2_staticBody&&(t?(this.m_awakeFlag=!0,this.m_sleepTime=0):(this.m_awakeFlag=!1,this.m_sleepTime=0,this.m_linearVelocity.SetZero(),this.m_angularVelocity=0,this.m_force.SetZero(),this.m_torque=0))}IsAwake(){return this.m_awakeFlag}SetEnabled(t){if(this.m_world.IsLocked())throw new Error;if(t!==this.IsEnabled())if(this.m_enabledFlag=t,t){for(let e=this.m_fixtureList;e;e=e.m_next)e.CreateProxies();this.m_world.m_newContacts=!0}else{for(let i=this.m_fixtureList;i;i=i.m_next)i.DestroyProxies();let e=this.m_contactList;for(;e;){const i=e;e=e.next,this.m_world.m_contactManager.Destroy(i.contact)}this.m_contactList=null}}IsEnabled(){return this.m_enabledFlag}SetFixedRotation(t){this.m_fixedRotationFlag!==t&&(this.m_fixedRotationFlag=t,this.m_angularVelocity=0,this.ResetMassData())}IsFixedRotation(){return this.m_fixedRotationFlag}GetFixtureList(){return this.m_fixtureList}GetJointList(){return this.m_jointList}GetContactList(){return this.m_contactList}GetNext(){return this.m_next}GetUserData(){return this.m_userData}SetUserData(t){this.m_userData=t}GetWorld(){return this.m_world}Dump(t){const e=this.m_islandIndex;t(`{ `),t(` const bd: b2BodyDef = new b2BodyDef(); `);let i="";switch(this.m_type){case _.b2BodyType.b2_staticBody:i="b2BodyType.b2_staticBody";break;case _.b2BodyType.b2_kinematicBody:i="b2BodyType.b2_kinematicBody";break;case _.b2BodyType.b2_dynamicBody:i="b2BodyType.b2_dynamicBody";break}t(` bd.type = %s; `,i),t(` bd.position.Set(%.15f, %.15f); `,this.m_xf.p.x,this.m_xf.p.y),t(` bd.angle = %.15f; `,this.m_sweep.a),t(` bd.linearVelocity.Set(%.15f, %.15f); `,this.m_linearVelocity.x,this.m_linearVelocity.y),t(` bd.angularVelocity = %.15f; `,this.m_angularVelocity),t(` bd.linearDamping = %.15f; `,this.m_linearDamping),t(` bd.angularDamping = %.15f; `,this.m_angularDamping),t(` bd.allowSleep = %s; `,this.m_autoSleepFlag?"true":"false"),t(` bd.awake = %s; `,this.m_awakeFlag?"true":"false"),t(` bd.fixedRotation = %s; `,this.m_fixedRotationFlag?"true":"false"),t(` bd.bullet = %s; `,this.m_bulletFlag?"true":"false"),t(` bd.active = %s; `,this.m_enabledFlag?"true":"false"),t(` bd.gravityScale = %.15f; `,this.m_gravityScale),t(` `),t(` bodies[%d] = this.m_world.CreateBody(bd); `,this.m_islandIndex),t(` `);for(let n=this.m_fixtureList;n;n=n.m_next)t(` { `),n.Dump(t,e),t(` } `);t(`} `)}SynchronizeFixtures(){if(this.m_awakeFlag){const t=It.SynchronizeFixtures_s_xf1;t.q.SetAngle(this.m_sweep.a0),C.MulRV(t.q,this.m_sweep.localCenter,t.p),s.SubVV(this.m_sweep.c0,t.p,t.p);for(let e=this.m_fixtureList;e;e=e.m_next)e.SynchronizeProxies(t,this.m_xf)}else for(let t=this.m_fixtureList;t;t=t.m_next)t.SynchronizeProxies(this.m_xf,this.m_xf)}SynchronizeTransform(){this.m_xf.q.SetAngle(this.m_sweep.a),C.MulRV(this.m_xf.q,this.m_sweep.localCenter,this.m_xf.p),s.SubVV(this.m_sweep.c,this.m_xf.p,this.m_xf.p)}ShouldCollide(t){return this.m_type===_.b2BodyType.b2_staticBody&&t.m_type===_.b2BodyType.b2_staticBody?!1:this.ShouldCollideConnected(t)}ShouldCollideConnected(t){for(let e=this.m_jointList;e;e=e.next)if(e.other===t&&!e.joint.m_collideConnected)return!1;return!0}Advance(t){this.m_sweep.Advance(t),this.m_sweep.c.Copy(this.m_sweep.c0),this.m_sweep.a=this.m_sweep.a0,this.m_xf.q.SetAngle(this.m_sweep.a),C.MulRV(this.m_xf.q,this.m_sweep.localCenter,this.m_xf.p),s.SubVV(this.m_sweep.c,this.m_xf.p,this.m_xf.p)}}It.CreateFixtureShapeDensity_s_def=new Fe,It.SetMassData_s_oldCenter=new s,It.ResetMassData_s_localCenter=new s,It.ResetMassData_s_oldCenter=new s,It.ResetMassData_s_massData=new Ls,It.SynchronizeFixtures_s_xf1=new I;function oe(d,t){return ws(d*t)}function re(d,t){return d>t?d:t}function he(d,t){return d0;for(let a=0;a0:(o.maskBits&r.categoryBits)!==0&&(o.categoryBits&r.maskBits)!==0}}Es.b2_defaultFilter=new Es;class Ee{constructor(){this.normalImpulses=Ss(H),this.tangentImpulses=Ss(H),this.count=0}}class Os{BeginContact(t){}EndContact(t){}PreSolve(t,e){}PostSolve(t,e){}}Os.b2_defaultListener=new Os;class Ms{ReportFixture(t){return!0}}class Oe{ReportFixture(t,e,i,n){return n}}class Xe{constructor(){this.m_broadPhase=new Ve,this.m_contactList=null,this.m_contactCount=0,this.m_contactFilter=Es.b2_defaultFilter,this.m_contactListener=Os.b2_defaultListener,this.m_contactFactory=new je}AddPair(t,e){let i=t.fixture,n=e.fixture,o=t.childIndex,r=e.childIndex,h=i.GetBody(),l=n.GetBody();if(h===l)return;let y=l.GetContactList();for(;y;){if(y.other===h){const m=y.contact.GetFixtureA(),a=y.contact.GetFixtureB(),u=y.contact.GetChildIndexA(),f=y.contact.GetChildIndexB();if(m===i&&a===n&&u===o&&f===r||m===n&&a===i&&u===r&&f===o)return}y=y.next}if(this.m_contactFilter&&!this.m_contactFilter.ShouldCollide(i,n))return;const c=this.m_contactFactory.Create(i,o,n,r);c!==null&&(i=c.GetFixtureA(),n=c.GetFixtureB(),o=c.GetChildIndexA(),r=c.GetChildIndexB(),h=i.m_body,l=n.m_body,c.m_prev=null,c.m_next=this.m_contactList,this.m_contactList!==null&&(this.m_contactList.m_prev=c),this.m_contactList=c,c.m_nodeA.other=l,c.m_nodeA.prev=null,c.m_nodeA.next=h.m_contactList,h.m_contactList!==null&&(h.m_contactList.prev=c.m_nodeA),h.m_contactList=c.m_nodeA,c.m_nodeB.other=h,c.m_nodeB.prev=null,c.m_nodeB.next=l.m_contactList,l.m_contactList!==null&&(l.m_contactList.prev=c.m_nodeB),l.m_contactList=c.m_nodeB,++this.m_contactCount)}FindNewContacts(){this.m_broadPhase.UpdatePairs((t,e)=>{this.AddPair(t,e)})}Destroy(t){const e=t.GetFixtureA(),i=t.GetFixtureB(),n=e.GetBody(),o=i.GetBody();this.m_contactListener&&t.IsTouching()&&this.m_contactListener.EndContact(t),t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),t===this.m_contactList&&(this.m_contactList=t.m_next),t.m_nodeA.prev&&(t.m_nodeA.prev.next=t.m_nodeA.next),t.m_nodeA.next&&(t.m_nodeA.next.prev=t.m_nodeA.prev),t.m_nodeA===n.m_contactList&&(n.m_contactList=t.m_nodeA.next),t.m_nodeB.prev&&(t.m_nodeB.prev.next=t.m_nodeB.next),t.m_nodeB.next&&(t.m_nodeB.next.prev=t.m_nodeB.prev),t.m_nodeB===o.m_contactList&&(o.m_contactList=t.m_nodeB.next),t.m_manifold.pointCount>0&&!e.IsSensor()&&!i.IsSensor()&&(e.GetBody().SetAwake(!0),i.GetBody().SetAwake(!0)),this.m_contactFactory.Destroy(t),--this.m_contactCount}Collide(){let t=this.m_contactList;for(;t;){const e=t.GetFixtureA(),i=t.GetFixtureB(),n=t.GetChildIndexA(),o=t.GetChildIndexB(),r=e.GetBody(),h=i.GetBody();if(t.m_filterFlag){if(this.m_contactFilter&&!this.m_contactFilter.ShouldCollide(e,i)){const u=t;t=u.m_next,this.Destroy(u);continue}t.m_filterFlag=!1}const l=r.IsAwake()&&r.m_type!==_.b2BodyType.b2_staticBody,y=h.IsAwake()&&h.m_type!==_.b2BodyType.b2_staticBody;if(!l&&!y){t=t.m_next;continue}const c=e.m_proxies[n].treeNode,m=i.m_proxies[o].treeNode;if(!Qs(c.aabb,m.aabb)){const u=t;t=u.m_next,this.Destroy(u);continue}t.Update(this.m_contactListener),t=t.m_next}}}class _e{constructor(){this.step=0,this.collide=0,this.solve=0,this.solveInit=0,this.solveVelocity=0,this.solvePosition=0,this.broadphase=0,this.solveTOI=0}Reset(){return this.step=0,this.collide=0,this.solve=0,this.solveInit=0,this.solveVelocity=0,this.solvePosition=0,this.broadphase=0,this.solveTOI=0,this}}class As{constructor(){this.dt=0,this.inv_dt=0,this.dtRatio=0,this.velocityIterations=0,this.positionIterations=0,this.warmStarting=!1}Copy(t){return this.dt=t.dt,this.inv_dt=t.inv_dt,this.dtRatio=t.dtRatio,this.positionIterations=t.positionIterations,this.velocityIterations=t.velocityIterations,this.warmStarting=t.warmStarting,this}}class Is{constructor(){this.c=new s,this.a=0}static MakeArray(t){return Ut(t,e=>new Is)}}class Ds{constructor(){this.v=new s,this.w=0}static MakeArray(t){return Ut(t,e=>new Ds)}}class ze{constructor(){this.step=new As}}_.g_blockSolve=!0;function Yn(){return _.g_blockSolve}function Kn(d){_.g_blockSolve=d}class Xs{constructor(){this.rA=new s,this.rB=new s,this.normalImpulse=0,this.tangentImpulse=0,this.normalMass=0,this.tangentMass=0,this.velocityBias=0}static MakeArray(t){return Ut(t,e=>new Xs)}}class Ts{constructor(){this.points=Xs.MakeArray(H),this.normal=new s,this.tangent=new s,this.normalMass=new lt,this.K=new lt,this.indexA=0,this.indexB=0,this.invMassA=0,this.invMassB=0,this.invIA=0,this.invIB=0,this.friction=0,this.restitution=0,this.threshold=0,this.tangentSpeed=0,this.pointCount=0,this.contactIndex=0}static MakeArray(t){return Ut(t,e=>new Ts)}}class Ps{constructor(){this.localPoints=s.MakeArray(H),this.localNormal=new s,this.localPoint=new s,this.indexA=0,this.indexB=0,this.invMassA=0,this.invMassB=0,this.localCenterA=new s,this.localCenterB=new s,this.invIA=0,this.invIB=0,this.type=_.b2ManifoldType.e_unknown,this.radiusA=0,this.radiusB=0,this.pointCount=0}static MakeArray(t){return Ut(t,e=>new Ps)}}class Je{constructor(){this.step=new As,this.count=0}}class Xt{constructor(){this.normal=new s,this.point=new s,this.separation=0}Initialize(t,e,i,n){const o=Xt.Initialize_s_pointA,r=Xt.Initialize_s_pointB,h=Xt.Initialize_s_planePoint,l=Xt.Initialize_s_clipPoint;switch(t.type){case _.b2ManifoldType.e_circles:{I.MulXV(e,t.localPoint,o),I.MulXV(i,t.localPoints[0],r),s.SubVV(r,o,this.normal).SelfNormalize(),s.MidVV(o,r,this.point),this.separation=s.DotVV(s.SubVV(r,o,s.s_t0),this.normal)-t.radiusA-t.radiusB;break}case _.b2ManifoldType.e_faceA:{C.MulRV(e.q,t.localNormal,this.normal),I.MulXV(e,t.localPoint,h),I.MulXV(i,t.localPoints[n],l),this.separation=s.DotVV(s.SubVV(l,h,s.s_t0),this.normal)-t.radiusA-t.radiusB,this.point.Copy(l);break}case _.b2ManifoldType.e_faceB:{C.MulRV(i.q,t.localNormal,this.normal),I.MulXV(i,t.localPoint,h),I.MulXV(e,t.localPoints[n],l),this.separation=s.DotVV(s.SubVV(l,h,s.s_t0),this.normal)-t.radiusA-t.radiusB,this.point.Copy(l),this.normal.SelfNeg();break}}}}Xt.Initialize_s_pointA=new s,Xt.Initialize_s_pointB=new s,Xt.Initialize_s_planePoint=new s,Xt.Initialize_s_clipPoint=new s;class X{constructor(){this.m_step=new As,this.m_positionConstraints=Ps.MakeArray(1024),this.m_velocityConstraints=Ts.MakeArray(1024),this.m_count=0}Initialize(t){if(this.m_step.Copy(t.step),this.m_count=t.count,this.m_positionConstraints.length0?1/it:0;const rt=r.tangent,St=s.CrossVV(G.rA,rt),Tt=s.CrossVV(G.rB,rt),Pt=u+f+A*St*St+S*Tt*Tt;G.tangentMass=Pt>0?1/Pt:0,G.velocityBias=0;const ns=s.DotVV(r.normal,s.SubVV(s.AddVCrossSV(z,j,G.rB,s.s_t0),s.AddVCrossSV(V,k,G.rA,s.s_t1),s.s_t0));ns<-r.threshold&&(G.velocityBias+=-r.restitution*ns)}if(r.pointCount===2&&_.g_blockSolve){const R=r.points[0],G=r.points[1],Z=s.CrossVV(R.rA,r.normal),U=s.CrossVV(R.rB,r.normal),it=s.CrossVV(G.rA,r.normal),rt=s.CrossVV(G.rB,r.normal),St=u+f+A*Z*Z+S*U*U,Tt=u+f+A*it*it+S*rt*rt,Pt=u+f+A*Z*it+S*U*rt;St*St=0&&h.y>=0){s.SubVV(h,o,l),s.MulSV(l.x,z,y),s.MulSV(l.y,z,c),s.AddVV(y,c,m),V.SelfMulSub(S,m),k-=b*(s.CrossVV(R.rA,y)+s.CrossVV(G.rA,c)),P.SelfMulAdd(B,m),q+=x*(s.CrossVV(R.rB,y)+s.CrossVV(G.rB,c)),R.normalImpulse=h.x,G.normalImpulse=h.y;break}if(h.x=-R.normalMass*r.x,h.y=0,Z=0,U=u.K.ex.y*h.x+r.y,h.x>=0&&U>=0){s.SubVV(h,o,l),s.MulSV(l.x,z,y),s.MulSV(l.y,z,c),s.AddVV(y,c,m),V.SelfMulSub(S,m),k-=b*(s.CrossVV(R.rA,y)+s.CrossVV(G.rA,c)),P.SelfMulAdd(B,m),q+=x*(s.CrossVV(R.rB,y)+s.CrossVV(G.rB,c)),R.normalImpulse=h.x,G.normalImpulse=h.y;break}if(h.x=0,h.y=-G.normalMass*r.y,Z=u.K.ey.x*h.y+r.x,U=0,h.y>=0&&Z>=0){s.SubVV(h,o,l),s.MulSV(l.x,z,y),s.MulSV(l.y,z,c),s.AddVV(y,c,m),V.SelfMulSub(S,m),k-=b*(s.CrossVV(R.rA,y)+s.CrossVV(G.rA,c)),P.SelfMulAdd(B,m),q+=x*(s.CrossVV(R.rB,y)+s.CrossVV(G.rB,c)),R.normalImpulse=h.x,G.normalImpulse=h.y;break}if(h.x=0,h.y=0,Z=r.x,U=r.y,Z>=0&&U>=0){s.SubVV(h,o,l),s.MulSV(l.x,z,y),s.MulSV(l.y,z,c),s.AddVV(y,c,m),V.SelfMulSub(S,m),k-=b*(s.CrossVV(R.rA,y)+s.CrossVV(G.rA,c)),P.SelfMulAdd(B,m),q+=x*(s.CrossVV(R.rB,y)+s.CrossVV(G.rB,c)),R.normalImpulse=h.x,G.normalImpulse=h.y;break}break}}this.m_velocities[f].w=k,this.m_velocities[A].w=q}}StoreImpulses(){for(let t=0;t0?-Y/Z:0;s.MulSV(U,q,r),x.SelfMulSub(u,r),v-=f*s.CrossVV(n,r),V.SelfMulAdd(S,r),k+=b*s.CrossVV(o,r)}this.m_positions[c].a=v,this.m_positions[m].a=k}return h>-3*Q}SolveTOIPositionConstraints(t,e){const i=X.SolveTOIPositionConstraints_s_xfA,n=X.SolveTOIPositionConstraints_s_xfB,o=X.SolveTOIPositionConstraints_s_psm,r=X.SolveTOIPositionConstraints_s_rA,h=X.SolveTOIPositionConstraints_s_rB,l=X.SolveTOIPositionConstraints_s_P;let y=0;for(let c=0;c0?-G/it:0;s.MulSV(rt,j,l),V.SelfMulSub(b,l),k-=B*s.CrossVV(r,l),P.SelfMulAdd(x,l),q+=v*s.CrossVV(h,l)}this.m_positions[a].a=k,this.m_positions[u].a=q}return y>=-1.5*Q}}X.InitializeVelocityConstraints_s_xfA=new I,X.InitializeVelocityConstraints_s_xfB=new I,X.InitializeVelocityConstraints_s_worldManifold=new dt,X.WarmStart_s_P=new s,X.SolveVelocityConstraints_s_dv=new s,X.SolveVelocityConstraints_s_dv1=new s,X.SolveVelocityConstraints_s_dv2=new s,X.SolveVelocityConstraints_s_P=new s,X.SolveVelocityConstraints_s_a=new s,X.SolveVelocityConstraints_s_b=new s,X.SolveVelocityConstraints_s_x=new s,X.SolveVelocityConstraints_s_d=new s,X.SolveVelocityConstraints_s_P1=new s,X.SolveVelocityConstraints_s_P2=new s,X.SolveVelocityConstraints_s_P1P2=new s,X.SolvePositionConstraints_s_xfA=new I,X.SolvePositionConstraints_s_xfB=new I,X.SolvePositionConstraints_s_psm=new Xt,X.SolvePositionConstraints_s_rA=new s,X.SolvePositionConstraints_s_rB=new s,X.SolvePositionConstraints_s_P=new s,X.SolveTOIPositionConstraints_s_xfA=new I,X.SolveTOIPositionConstraints_s_xfB=new I,X.SolveTOIPositionConstraints_s_psm=new Xt,X.SolveTOIPositionConstraints_s_rA=new s,X.SolveTOIPositionConstraints_s_rB=new s,X.SolveTOIPositionConstraints_s_P=new s;class Qn extends Ot{constructor(){super(_.b2JointType.e_frictionJoint),this.localAnchorA=new s,this.localAnchorB=new s,this.maxForce=0,this.maxTorque=0}Initialize(t,e,i){this.bodyA=t,this.bodyB=e,this.bodyA.GetLocalPoint(i,this.localAnchorA),this.bodyB.GetLocalPoint(i,this.localAnchorB)}}class ss extends pt{constructor(t){super(t),this.m_localAnchorA=new s,this.m_localAnchorB=new s,this.m_linearImpulse=new s,this.m_angularImpulse=0,this.m_maxForce=0,this.m_maxTorque=0,this.m_indexA=0,this.m_indexB=0,this.m_rA=new s,this.m_rB=new s,this.m_localCenterA=new s,this.m_localCenterB=new s,this.m_invMassA=0,this.m_invMassB=0,this.m_invIA=0,this.m_invIB=0,this.m_linearMass=new lt,this.m_angularMass=0,this.m_qA=new C,this.m_qB=new C,this.m_lalcA=new s,this.m_lalcB=new s,this.m_K=new lt,this.m_localAnchorA.Copy(T(t.localAnchorA,s.ZERO)),this.m_localAnchorB.Copy(T(t.localAnchorB,s.ZERO)),this.m_linearImpulse.SetZero(),this.m_maxForce=T(t.maxForce,0),this.m_maxTorque=T(t.maxTorque,0),this.m_linearMass.SetZero()}InitVelocityConstraints(t){this.m_indexA=this.m_bodyA.m_islandIndex,this.m_indexB=this.m_bodyB.m_islandIndex,this.m_localCenterA.Copy(this.m_bodyA.m_sweep.localCenter),this.m_localCenterB.Copy(this.m_bodyB.m_sweep.localCenter),this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;const e=t.positions[this.m_indexA].a,i=t.velocities[this.m_indexA].v;let n=t.velocities[this.m_indexA].w;const o=t.positions[this.m_indexB].a,r=t.velocities[this.m_indexB].v;let h=t.velocities[this.m_indexB].w;const l=this.m_qA.SetAngle(e),y=this.m_qB.SetAngle(o);s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA);const c=C.MulRV(l,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB);const m=C.MulRV(y,this.m_lalcB,this.m_rB),a=this.m_invMassA,u=this.m_invMassB,f=this.m_invIA,A=this.m_invIB,S=this.m_K;if(S.ex.x=a+u+f*c.y*c.y+A*m.y*m.y,S.ex.y=-f*c.x*c.y-A*m.x*m.y,S.ey.x=S.ex.y,S.ey.y=a+u+f*c.x*c.x+A*m.x*m.x,S.GetInverse(this.m_linearMass),this.m_angularMass=f+A,this.m_angularMass>0&&(this.m_angularMass=1/this.m_angularMass),t.step.warmStarting){this.m_linearImpulse.SelfMul(t.step.dtRatio),this.m_angularImpulse*=t.step.dtRatio;const b=this.m_linearImpulse;i.SelfMulSub(a,b),n-=f*(s.CrossVV(this.m_rA,b)+this.m_angularImpulse),r.SelfMulAdd(u,b),h+=A*(s.CrossVV(this.m_rB,b)+this.m_angularImpulse)}else this.m_linearImpulse.SetZero(),this.m_angularImpulse=0;t.velocities[this.m_indexA].w=n,t.velocities[this.m_indexB].w=h}SolveVelocityConstraints(t){const e=t.velocities[this.m_indexA].v;let i=t.velocities[this.m_indexA].w;const n=t.velocities[this.m_indexB].v;let o=t.velocities[this.m_indexB].w;const r=this.m_invMassA,h=this.m_invMassB,l=this.m_invIA,y=this.m_invIB,c=t.step.dt;{const m=o-i;let a=-this.m_angularMass*m;const u=this.m_angularImpulse,f=c*this.m_maxTorque;this.m_angularImpulse=vt(this.m_angularImpulse+a,-f,f),a=this.m_angularImpulse-u,i-=l*a,o+=y*a}{const m=s.SubVV(s.AddVCrossSV(n,o,this.m_rB,s.s_t0),s.AddVCrossSV(e,i,this.m_rA,s.s_t1),ss.SolveVelocityConstraints_s_Cdot_v2),a=lt.MulMV(this.m_linearMass,m,ss.SolveVelocityConstraints_s_impulseV).SelfNeg(),u=ss.SolveVelocityConstraints_s_oldImpulseV.Copy(this.m_linearImpulse);this.m_linearImpulse.SelfAdd(a);const f=c*this.m_maxForce;this.m_linearImpulse.LengthSquared()>f*f&&(this.m_linearImpulse.Normalize(),this.m_linearImpulse.SelfMul(f)),s.SubVV(this.m_linearImpulse,u,a),e.SelfMulSub(r,a),i-=l*s.CrossVV(this.m_rA,a),n.SelfMulAdd(h,a),o+=y*s.CrossVV(this.m_rB,a)}t.velocities[this.m_indexA].w=i,t.velocities[this.m_indexB].w=o}SolvePositionConstraints(t){return!0}GetAnchorA(t){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA,t)}GetAnchorB(t){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB,t)}GetReactionForce(t,e){return e.x=t*this.m_linearImpulse.x,e.y=t*this.m_linearImpulse.y,e}GetReactionTorque(t){return t*this.m_angularImpulse}GetLocalAnchorA(){return this.m_localAnchorA}GetLocalAnchorB(){return this.m_localAnchorB}SetMaxForce(t){this.m_maxForce=t}GetMaxForce(){return this.m_maxForce}SetMaxTorque(t){this.m_maxTorque=t}GetMaxTorque(){return this.m_maxTorque}Dump(t){const e=this.m_bodyA.m_islandIndex,i=this.m_bodyB.m_islandIndex;t(` const jd: b2FrictionJointDef = new b2FrictionJointDef(); `),t(` jd.bodyA = bodies[%d]; `,e),t(` jd.bodyB = bodies[%d]; `,i),t(` jd.collideConnected = %s; `,this.m_collideConnected?"true":"false"),t(` jd.localAnchorA.Set(%.15f, %.15f); `,this.m_localAnchorA.x,this.m_localAnchorA.y),t(` jd.localAnchorB.Set(%.15f, %.15f); `,this.m_localAnchorB.x,this.m_localAnchorB.y),t(` jd.maxForce = %.15f; `,this.m_maxForce),t(` jd.maxTorque = %.15f; `,this.m_maxTorque),t(` joints[%d] = this.m_world.CreateJoint(jd); `,this.m_index)}}ss.SolveVelocityConstraints_s_Cdot_v2=new s,ss.SolveVelocityConstraints_s_impulseV=new s,ss.SolveVelocityConstraints_s_oldImpulseV=new s;class Wn extends Ot{constructor(){super(_.b2JointType.e_gearJoint),this.ratio=1}}class ht extends pt{constructor(t){super(t),this.m_typeA=_.b2JointType.e_unknownJoint,this.m_typeB=_.b2JointType.e_unknownJoint,this.m_localAnchorA=new s,this.m_localAnchorB=new s,this.m_localAnchorC=new s,this.m_localAnchorD=new s,this.m_localAxisC=new s,this.m_localAxisD=new s,this.m_referenceAngleA=0,this.m_referenceAngleB=0,this.m_constant=0,this.m_ratio=0,this.m_impulse=0,this.m_indexA=0,this.m_indexB=0,this.m_indexC=0,this.m_indexD=0,this.m_lcA=new s,this.m_lcB=new s,this.m_lcC=new s,this.m_lcD=new s,this.m_mA=0,this.m_mB=0,this.m_mC=0,this.m_mD=0,this.m_iA=0,this.m_iB=0,this.m_iC=0,this.m_iD=0,this.m_JvAC=new s,this.m_JvBD=new s,this.m_JwA=0,this.m_JwB=0,this.m_JwC=0,this.m_JwD=0,this.m_mass=0,this.m_qA=new C,this.m_qB=new C,this.m_qC=new C,this.m_qD=new C,this.m_lalcA=new s,this.m_lalcB=new s,this.m_lalcC=new s,this.m_lalcD=new s,this.m_joint1=t.joint1,this.m_joint2=t.joint2,this.m_typeA=this.m_joint1.GetType(),this.m_typeB=this.m_joint2.GetType();let e,i;this.m_bodyC=this.m_joint1.GetBodyA(),this.m_bodyA=this.m_joint1.GetBodyB();const n=this.m_bodyA.m_xf,o=this.m_bodyA.m_sweep.a,r=this.m_bodyC.m_xf,h=this.m_bodyC.m_sweep.a;if(this.m_typeA===_.b2JointType.e_revoluteJoint){const a=t.joint1;this.m_localAnchorC.Copy(a.m_localAnchorA),this.m_localAnchorA.Copy(a.m_localAnchorB),this.m_referenceAngleA=a.m_referenceAngle,this.m_localAxisC.SetZero(),e=o-h-this.m_referenceAngleA}else{const a=t.joint1;this.m_localAnchorC.Copy(a.m_localAnchorA),this.m_localAnchorA.Copy(a.m_localAnchorB),this.m_referenceAngleA=a.m_referenceAngle,this.m_localAxisC.Copy(a.m_localXAxisA);const u=this.m_localAnchorC,f=C.MulTRV(r.q,s.AddVV(C.MulRV(n.q,this.m_localAnchorA,s.s_t0),s.SubVV(n.p,r.p,s.s_t1),s.s_t0),s.s_t0);e=s.DotVV(s.SubVV(f,u,s.s_t0),this.m_localAxisC)}this.m_bodyD=this.m_joint2.GetBodyA(),this.m_bodyB=this.m_joint2.GetBodyB();const l=this.m_bodyB.m_xf,y=this.m_bodyB.m_sweep.a,c=this.m_bodyD.m_xf,m=this.m_bodyD.m_sweep.a;if(this.m_typeB===_.b2JointType.e_revoluteJoint){const a=t.joint2;this.m_localAnchorD.Copy(a.m_localAnchorA),this.m_localAnchorB.Copy(a.m_localAnchorB),this.m_referenceAngleB=a.m_referenceAngle,this.m_localAxisD.SetZero(),i=y-m-this.m_referenceAngleB}else{const a=t.joint2;this.m_localAnchorD.Copy(a.m_localAnchorA),this.m_localAnchorB.Copy(a.m_localAnchorB),this.m_referenceAngleB=a.m_referenceAngle,this.m_localAxisD.Copy(a.m_localXAxisA);const u=this.m_localAnchorD,f=C.MulTRV(c.q,s.AddVV(C.MulRV(l.q,this.m_localAnchorB,s.s_t0),s.SubVV(l.p,c.p,s.s_t1),s.s_t0),s.s_t0);i=s.DotVV(s.SubVV(f,u,s.s_t0),this.m_localAxisD)}this.m_ratio=T(t.ratio,1),this.m_constant=e+this.m_ratio*i,this.m_impulse=0}InitVelocityConstraints(t){this.m_indexA=this.m_bodyA.m_islandIndex,this.m_indexB=this.m_bodyB.m_islandIndex,this.m_indexC=this.m_bodyC.m_islandIndex,this.m_indexD=this.m_bodyD.m_islandIndex,this.m_lcA.Copy(this.m_bodyA.m_sweep.localCenter),this.m_lcB.Copy(this.m_bodyB.m_sweep.localCenter),this.m_lcC.Copy(this.m_bodyC.m_sweep.localCenter),this.m_lcD.Copy(this.m_bodyD.m_sweep.localCenter),this.m_mA=this.m_bodyA.m_invMass,this.m_mB=this.m_bodyB.m_invMass,this.m_mC=this.m_bodyC.m_invMass,this.m_mD=this.m_bodyD.m_invMass,this.m_iA=this.m_bodyA.m_invI,this.m_iB=this.m_bodyB.m_invI,this.m_iC=this.m_bodyC.m_invI,this.m_iD=this.m_bodyD.m_invI;const e=t.positions[this.m_indexA].a,i=t.velocities[this.m_indexA].v;let n=t.velocities[this.m_indexA].w;const o=t.positions[this.m_indexB].a,r=t.velocities[this.m_indexB].v;let h=t.velocities[this.m_indexB].w;const l=t.positions[this.m_indexC].a,y=t.velocities[this.m_indexC].v;let c=t.velocities[this.m_indexC].w;const m=t.positions[this.m_indexD].a,a=t.velocities[this.m_indexD].v;let u=t.velocities[this.m_indexD].w;const f=this.m_qA.SetAngle(e),A=this.m_qB.SetAngle(o),S=this.m_qC.SetAngle(l),b=this.m_qD.SetAngle(m);if(this.m_mass=0,this.m_typeA===_.b2JointType.e_revoluteJoint)this.m_JvAC.SetZero(),this.m_JwA=1,this.m_JwC=1,this.m_mass+=this.m_iA+this.m_iC;else{const B=C.MulRV(S,this.m_localAxisC,ht.InitVelocityConstraints_s_u);s.SubVV(this.m_localAnchorC,this.m_lcC,this.m_lalcC);const x=C.MulRV(S,this.m_lalcC,ht.InitVelocityConstraints_s_rC);s.SubVV(this.m_localAnchorA,this.m_lcA,this.m_lalcA);const v=C.MulRV(f,this.m_lalcA,ht.InitVelocityConstraints_s_rA);this.m_JvAC.Copy(B),this.m_JwC=s.CrossVV(x,B),this.m_JwA=s.CrossVV(v,B),this.m_mass+=this.m_mC+this.m_mA+this.m_iC*this.m_JwC*this.m_JwC+this.m_iA*this.m_JwA*this.m_JwA}if(this.m_typeB===_.b2JointType.e_revoluteJoint)this.m_JvBD.SetZero(),this.m_JwB=this.m_ratio,this.m_JwD=this.m_ratio,this.m_mass+=this.m_ratio*this.m_ratio*(this.m_iB+this.m_iD);else{const B=C.MulRV(b,this.m_localAxisD,ht.InitVelocityConstraints_s_u);s.SubVV(this.m_localAnchorD,this.m_lcD,this.m_lalcD);const x=C.MulRV(b,this.m_lalcD,ht.InitVelocityConstraints_s_rD);s.SubVV(this.m_localAnchorB,this.m_lcB,this.m_lalcB);const v=C.MulRV(A,this.m_lalcB,ht.InitVelocityConstraints_s_rB);s.MulSV(this.m_ratio,B,this.m_JvBD),this.m_JwD=this.m_ratio*s.CrossVV(x,B),this.m_JwB=this.m_ratio*s.CrossVV(v,B),this.m_mass+=this.m_ratio*this.m_ratio*(this.m_mD+this.m_mB)+this.m_iD*this.m_JwD*this.m_JwD+this.m_iB*this.m_JwB*this.m_JwB}this.m_mass=this.m_mass>0?1/this.m_mass:0,t.step.warmStarting?(i.SelfMulAdd(this.m_mA*this.m_impulse,this.m_JvAC),n+=this.m_iA*this.m_impulse*this.m_JwA,r.SelfMulAdd(this.m_mB*this.m_impulse,this.m_JvBD),h+=this.m_iB*this.m_impulse*this.m_JwB,y.SelfMulSub(this.m_mC*this.m_impulse,this.m_JvAC),c-=this.m_iC*this.m_impulse*this.m_JwC,a.SelfMulSub(this.m_mD*this.m_impulse,this.m_JvBD),u-=this.m_iD*this.m_impulse*this.m_JwD):this.m_impulse=0,t.velocities[this.m_indexA].w=n,t.velocities[this.m_indexB].w=h,t.velocities[this.m_indexC].w=c,t.velocities[this.m_indexD].w=u}SolveVelocityConstraints(t){const e=t.velocities[this.m_indexA].v;let i=t.velocities[this.m_indexA].w;const n=t.velocities[this.m_indexB].v;let o=t.velocities[this.m_indexB].w;const r=t.velocities[this.m_indexC].v;let h=t.velocities[this.m_indexC].w;const l=t.velocities[this.m_indexD].v;let y=t.velocities[this.m_indexD].w,c=s.DotVV(this.m_JvAC,s.SubVV(e,r,s.s_t0))+s.DotVV(this.m_JvBD,s.SubVV(n,l,s.s_t0));c+=this.m_JwA*i-this.m_JwC*h+(this.m_JwB*o-this.m_JwD*y);const m=-this.m_mass*c;this.m_impulse+=m,e.SelfMulAdd(this.m_mA*m,this.m_JvAC),i+=this.m_iA*m*this.m_JwA,n.SelfMulAdd(this.m_mB*m,this.m_JvBD),o+=this.m_iB*m*this.m_JwB,r.SelfMulSub(this.m_mC*m,this.m_JvAC),h-=this.m_iC*m*this.m_JwC,l.SelfMulSub(this.m_mD*m,this.m_JvBD),y-=this.m_iD*m*this.m_JwD,t.velocities[this.m_indexA].w=i,t.velocities[this.m_indexB].w=o,t.velocities[this.m_indexC].w=h,t.velocities[this.m_indexD].w=y}SolvePositionConstraints(t){const e=t.positions[this.m_indexA].c;let i=t.positions[this.m_indexA].a;const n=t.positions[this.m_indexB].c;let o=t.positions[this.m_indexB].a;const r=t.positions[this.m_indexC].c;let h=t.positions[this.m_indexC].a;const l=t.positions[this.m_indexD].c;let y=t.positions[this.m_indexD].a;const c=this.m_qA.SetAngle(i),m=this.m_qB.SetAngle(o),a=this.m_qC.SetAngle(h),u=this.m_qD.SetAngle(y),f=0;let A,S;const b=this.m_JvAC,B=this.m_JvBD;let x,v,V,k,P=0;if(this.m_typeA===_.b2JointType.e_revoluteJoint)b.SetZero(),x=1,V=1,P+=this.m_iA+this.m_iC,A=i-h-this.m_referenceAngleA;else{const j=C.MulRV(a,this.m_localAxisC,ht.SolvePositionConstraints_s_u),Y=C.MulRV(a,this.m_lalcC,ht.SolvePositionConstraints_s_rC),R=C.MulRV(c,this.m_lalcA,ht.SolvePositionConstraints_s_rA);b.Copy(j),V=s.CrossVV(Y,j),x=s.CrossVV(R,j),P+=this.m_mC+this.m_mA+this.m_iC*V*V+this.m_iA*x*x;const G=this.m_lalcC,Z=C.MulTRV(a,s.AddVV(R,s.SubVV(e,r,s.s_t0),s.s_t0),s.s_t0);A=s.DotVV(s.SubVV(Z,G,s.s_t0),this.m_localAxisC)}if(this.m_typeB===_.b2JointType.e_revoluteJoint)B.SetZero(),v=this.m_ratio,k=this.m_ratio,P+=this.m_ratio*this.m_ratio*(this.m_iB+this.m_iD),S=o-y-this.m_referenceAngleB;else{const j=C.MulRV(u,this.m_localAxisD,ht.SolvePositionConstraints_s_u),Y=C.MulRV(u,this.m_lalcD,ht.SolvePositionConstraints_s_rD),R=C.MulRV(m,this.m_lalcB,ht.SolvePositionConstraints_s_rB);s.MulSV(this.m_ratio,j,B),k=this.m_ratio*s.CrossVV(Y,j),v=this.m_ratio*s.CrossVV(R,j),P+=this.m_ratio*this.m_ratio*(this.m_mD+this.m_mB)+this.m_iD*k*k+this.m_iB*v*v;const G=this.m_lalcD,Z=C.MulTRV(u,s.AddVV(R,s.SubVV(n,l,s.s_t0),s.s_t0),s.s_t0);S=s.DotVV(s.SubVV(Z,G,s.s_t0),this.m_localAxisD)}const q=A+this.m_ratio*S-this.m_constant;let z=0;return P>0&&(z=-q/P),e.SelfMulAdd(this.m_mA*z,b),i+=this.m_iA*z*x,n.SelfMulAdd(this.m_mB*z,B),o+=this.m_iB*z*v,r.SelfMulSub(this.m_mC*z,b),h-=this.m_iC*z*V,l.SelfMulSub(this.m_mD*z,B),y-=this.m_iD*z*k,t.positions[this.m_indexA].a=i,t.positions[this.m_indexB].a=o,t.positions[this.m_indexC].a=h,t.positions[this.m_indexD].a=y,fZt){const B=jt/S.Length();f.SelfMul(B)}const b=r*A;if(b*b>p){const B=Vt/ot(b);A*=B}a.x+=r*f.x,a.y+=r*f.y,u+=r*A,this.m_positions[m].a=u,this.m_velocities[m].w=A}o.Reset();let c=!1;for(let m=0;mu||s.DotVV(A.m_linearVelocity,A.m_linearVelocity)>a?(A.m_sleepTime=0,m=0):(A.m_sleepTime+=r,m=at(m,A.m_sleepTime)))}if(m>=L&&c)for(let f=0;fZt){const A=jt/a.Length();c.SelfMul(A)}const u=r*m;if(u*u>p){const A=Vt/ot(u);m*=A}l.SelfMulAdd(r,c),y+=r*m,this.m_positions[h].a=y,this.m_velocities[h].w=m;const f=this.m_bodies[h];f.m_sweep.c.Copy(l),f.m_sweep.a=y,f.m_linearVelocity.Copy(c),f.m_angularVelocity=m,f.SynchronizeTransform()}this.Report(o.m_velocityConstraints)}Report(t){if(this.m_listener!==null)for(let e=0;e0&&(this.m_angularMass=1/this.m_angularMass),s.SubVV(s.AddVV(r,u,s.s_t0),s.AddVV(e,a,s.s_t1),this.m_linearError),this.m_angularError=h-i-this.m_angularOffset,t.step.warmStarting){this.m_linearImpulse.SelfMul(t.step.dtRatio),this.m_angularImpulse*=t.step.dtRatio;const x=this.m_linearImpulse;n.SelfMulSub(f,x),o-=S*(s.CrossVV(a,x)+this.m_angularImpulse),l.SelfMulAdd(A,x),y+=b*(s.CrossVV(u,x)+this.m_angularImpulse)}else this.m_linearImpulse.SetZero(),this.m_angularImpulse=0;t.velocities[this.m_indexA].w=o,t.velocities[this.m_indexB].w=y}SolveVelocityConstraints(t){const e=t.velocities[this.m_indexA].v;let i=t.velocities[this.m_indexA].w;const n=t.velocities[this.m_indexB].v;let o=t.velocities[this.m_indexB].w;const r=this.m_invMassA,h=this.m_invMassB,l=this.m_invIA,y=this.m_invIB,c=t.step.dt,m=t.step.inv_dt;{const a=o-i+m*this.m_correctionFactor*this.m_angularError;let u=-this.m_angularMass*a;const f=this.m_angularImpulse,A=c*this.m_maxTorque;this.m_angularImpulse=vt(this.m_angularImpulse+u,-A,A),u=this.m_angularImpulse-f,i-=l*u,o+=y*u}{const a=this.m_rA,u=this.m_rB,f=s.AddVV(s.SubVV(s.AddVV(n,s.CrossSV(o,u,s.s_t0),s.s_t0),s.AddVV(e,s.CrossSV(i,a,s.s_t1),s.s_t1),s.s_t2),s.MulSV(m*this.m_correctionFactor,this.m_linearError,s.s_t3),es.SolveVelocityConstraints_s_Cdot_v2),A=lt.MulMV(this.m_linearMass,f,es.SolveVelocityConstraints_s_impulse_v2).SelfNeg(),S=es.SolveVelocityConstraints_s_oldImpulse_v2.Copy(this.m_linearImpulse);this.m_linearImpulse.SelfAdd(A);const b=c*this.m_maxForce;this.m_linearImpulse.LengthSquared()>b*b&&(this.m_linearImpulse.Normalize(),this.m_linearImpulse.SelfMul(b)),s.SubVV(this.m_linearImpulse,S,A),e.SelfMulSub(r,A),i-=l*s.CrossVV(a,A),n.SelfMulAdd(h,A),o+=y*s.CrossVV(u,A)}t.velocities[this.m_indexA].w=i,t.velocities[this.m_indexB].w=o}SolvePositionConstraints(t){return!0}Dump(t){const e=this.m_bodyA.m_islandIndex,i=this.m_bodyB.m_islandIndex;t(` const jd: b2MotorJointDef = new b2MotorJointDef(); `),t(` jd.bodyA = bodies[%d]; `,e),t(` jd.bodyB = bodies[%d]; `,i),t(` jd.collideConnected = %s; `,this.m_collideConnected?"true":"false"),t(` jd.linearOffset.Set(%.15f, %.15f); `,this.m_linearOffset.x,this.m_linearOffset.y),t(` jd.angularOffset = %.15f; `,this.m_angularOffset),t(` jd.maxForce = %.15f; `,this.m_maxForce),t(` jd.maxTorque = %.15f; `,this.m_maxTorque),t(` jd.correctionFactor = %.15f; `,this.m_correctionFactor),t(` joints[%d] = this.m_world.CreateJoint(jd); `,this.m_index)}}es.SolveVelocityConstraints_s_Cdot_v2=new s,es.SolveVelocityConstraints_s_impulse_v2=new s,es.SolveVelocityConstraints_s_oldImpulse_v2=new s;class $n extends Ot{constructor(){super(_.b2JointType.e_mouseJoint),this.target=new s,this.maxForce=0,this.stiffness=5,this.damping=.7}}class is extends pt{constructor(t){super(t),this.m_localAnchorB=new s,this.m_targetA=new s,this.m_stiffness=0,this.m_damping=0,this.m_beta=0,this.m_impulse=new s,this.m_maxForce=0,this.m_gamma=0,this.m_indexA=0,this.m_indexB=0,this.m_rB=new s,this.m_localCenterB=new s,this.m_invMassB=0,this.m_invIB=0,this.m_mass=new lt,this.m_C=new s,this.m_qB=new C,this.m_lalcB=new s,this.m_K=new lt,this.m_targetA.Copy(T(t.target,s.ZERO)),I.MulTXV(this.m_bodyB.GetTransform(),this.m_targetA,this.m_localAnchorB),this.m_maxForce=T(t.maxForce,0),this.m_impulse.SetZero(),this.m_stiffness=T(t.stiffness,0),this.m_damping=T(t.damping,0),this.m_beta=0,this.m_gamma=0}SetTarget(t){this.m_bodyB.IsAwake()||this.m_bodyB.SetAwake(!0),this.m_targetA.Copy(t)}GetTarget(){return this.m_targetA}SetMaxForce(t){this.m_maxForce=t}GetMaxForce(){return this.m_maxForce}SetStiffness(t){this.m_stiffness=t}GetStiffness(){return this.m_stiffness}SetDamping(t){this.m_damping=t}GetDamping(){return this.m_damping}InitVelocityConstraints(t){this.m_indexB=this.m_bodyB.m_islandIndex,this.m_localCenterB.Copy(this.m_bodyB.m_sweep.localCenter),this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIB=this.m_bodyB.m_invI;const e=t.positions[this.m_indexB].c,i=t.positions[this.m_indexB].a,n=t.velocities[this.m_indexB].v;let o=t.velocities[this.m_indexB].w;const r=this.m_qB.SetAngle(i),h=this.m_bodyB.GetMass(),l=2*ut*this.m_stiffness,y=2*h*this.m_damping*l,c=h*(l*l),m=t.step.dt;this.m_gamma=m*(y+m*c),this.m_gamma!==0&&(this.m_gamma=1/this.m_gamma),this.m_beta=m*c*this.m_gamma,s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB),C.MulRV(r,this.m_lalcB,this.m_rB);const a=this.m_K;a.ex.x=this.m_invMassB+this.m_invIB*this.m_rB.y*this.m_rB.y+this.m_gamma,a.ex.y=-this.m_invIB*this.m_rB.x*this.m_rB.y,a.ey.x=a.ex.y,a.ey.y=this.m_invMassB+this.m_invIB*this.m_rB.x*this.m_rB.x+this.m_gamma,a.GetInverse(this.m_mass),this.m_C.x=e.x+this.m_rB.x-this.m_targetA.x,this.m_C.y=e.y+this.m_rB.y-this.m_targetA.y,this.m_C.SelfMul(this.m_beta),o*=.98,t.step.warmStarting?(this.m_impulse.SelfMul(t.step.dtRatio),n.x+=this.m_invMassB*this.m_impulse.x,n.y+=this.m_invMassB*this.m_impulse.y,o+=this.m_invIB*s.CrossVV(this.m_rB,this.m_impulse)):this.m_impulse.SetZero(),t.velocities[this.m_indexB].w=o}SolveVelocityConstraints(t){const e=t.velocities[this.m_indexB].v;let i=t.velocities[this.m_indexB].w;const n=s.AddVCrossSV(e,i,this.m_rB,is.SolveVelocityConstraints_s_Cdot),o=lt.MulMV(this.m_mass,s.AddVV(n,s.AddVV(this.m_C,s.MulSV(this.m_gamma,this.m_impulse,s.s_t0),s.s_t0),s.s_t0).SelfNeg(),is.SolveVelocityConstraints_s_impulse),r=is.SolveVelocityConstraints_s_oldImpulse.Copy(this.m_impulse);this.m_impulse.SelfAdd(o);const h=t.step.dt*this.m_maxForce;this.m_impulse.LengthSquared()>h*h&&this.m_impulse.SelfMul(h/this.m_impulse.Length()),s.SubVV(this.m_impulse,r,o),e.SelfMulAdd(this.m_invMassB,o),i+=this.m_invIB*s.CrossVV(this.m_rB,o),t.velocities[this.m_indexB].w=i}SolvePositionConstraints(t){return!0}GetAnchorA(t){return t.x=this.m_targetA.x,t.y=this.m_targetA.y,t}GetAnchorB(t){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB,t)}GetReactionForce(t,e){return s.MulSV(t,this.m_impulse,e)}GetReactionTorque(t){return 0}Dump(t){t(`Mouse joint dumping is not supported. `)}ShiftOrigin(t){this.m_targetA.SelfSub(t)}}is.SolveVelocityConstraints_s_Cdot=new s,is.SolveVelocityConstraints_s_impulse=new s,is.SolveVelocityConstraints_s_oldImpulse=new s;class to extends Ot{constructor(){super(_.b2JointType.e_prismaticJoint),this.localAnchorA=new s,this.localAnchorB=new s,this.localAxisA=new s(1,0),this.referenceAngle=0,this.enableLimit=!1,this.lowerTranslation=0,this.upperTranslation=0,this.enableMotor=!1,this.maxMotorForce=0,this.motorSpeed=0}Initialize(t,e,i,n){this.bodyA=t,this.bodyB=e,this.bodyA.GetLocalPoint(i,this.localAnchorA),this.bodyB.GetLocalPoint(i,this.localAnchorB),this.bodyA.GetLocalVector(n,this.localAxisA),this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()}}class N extends pt{constructor(t){super(t),this.m_localAnchorA=new s,this.m_localAnchorB=new s,this.m_localXAxisA=new s,this.m_localYAxisA=new s,this.m_referenceAngle=0,this.m_impulse=new s(0,0),this.m_motorImpulse=0,this.m_lowerImpulse=0,this.m_upperImpulse=0,this.m_lowerTranslation=0,this.m_upperTranslation=0,this.m_maxMotorForce=0,this.m_motorSpeed=0,this.m_enableLimit=!1,this.m_enableMotor=!1,this.m_indexA=0,this.m_indexB=0,this.m_localCenterA=new s,this.m_localCenterB=new s,this.m_invMassA=0,this.m_invMassB=0,this.m_invIA=0,this.m_invIB=0,this.m_axis=new s(0,0),this.m_perp=new s(0,0),this.m_s1=0,this.m_s2=0,this.m_a1=0,this.m_a2=0,this.m_K=new lt,this.m_K3=new Yt,this.m_K2=new lt,this.m_translation=0,this.m_axialMass=0,this.m_qA=new C,this.m_qB=new C,this.m_lalcA=new s,this.m_lalcB=new s,this.m_rA=new s,this.m_rB=new s,this.m_localAnchorA.Copy(T(t.localAnchorA,s.ZERO)),this.m_localAnchorB.Copy(T(t.localAnchorB,s.ZERO)),this.m_localXAxisA.Copy(T(t.localAxisA,new s(1,0))).SelfNormalize(),s.CrossOneV(this.m_localXAxisA,this.m_localYAxisA),this.m_referenceAngle=T(t.referenceAngle,0),this.m_lowerTranslation=T(t.lowerTranslation,0),this.m_upperTranslation=T(t.upperTranslation,0),this.m_maxMotorForce=T(t.maxMotorForce,0),this.m_motorSpeed=T(t.motorSpeed,0),this.m_enableLimit=T(t.enableLimit,!1),this.m_enableMotor=T(t.enableMotor,!1)}InitVelocityConstraints(t){this.m_indexA=this.m_bodyA.m_islandIndex,this.m_indexB=this.m_bodyB.m_islandIndex,this.m_localCenterA.Copy(this.m_bodyA.m_sweep.localCenter),this.m_localCenterB.Copy(this.m_bodyB.m_sweep.localCenter),this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;const e=t.positions[this.m_indexA].c,i=t.positions[this.m_indexA].a,n=t.velocities[this.m_indexA].v;let o=t.velocities[this.m_indexA].w;const r=t.positions[this.m_indexB].c,h=t.positions[this.m_indexB].a,l=t.velocities[this.m_indexB].v;let y=t.velocities[this.m_indexB].w;const c=this.m_qA.SetAngle(i),m=this.m_qB.SetAngle(h);s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA);const a=C.MulRV(c,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB);const u=C.MulRV(m,this.m_lalcB,this.m_rB),f=s.AddVV(s.SubVV(r,e,s.s_t0),s.SubVV(u,a,s.s_t1),N.InitVelocityConstraints_s_d),A=this.m_invMassA,S=this.m_invMassB,b=this.m_invIA,B=this.m_invIB;if(C.MulRV(c,this.m_localXAxisA,this.m_axis),this.m_a1=s.CrossVV(s.AddVV(f,a,s.s_t0),this.m_axis),this.m_a2=s.CrossVV(u,this.m_axis),this.m_axialMass=A+S+b*this.m_a1*this.m_a1+B*this.m_a2*this.m_a2,this.m_axialMass>0&&(this.m_axialMass=1/this.m_axialMass),C.MulRV(c,this.m_localYAxisA,this.m_perp),this.m_s1=s.CrossVV(s.AddVV(f,a,s.s_t0),this.m_perp),this.m_s2=s.CrossVV(u,this.m_perp),this.m_K.ex.x=A+S+b*this.m_s1*this.m_s1+B*this.m_s2*this.m_s2,this.m_K.ex.y=b*this.m_s1+B*this.m_s2,this.m_K.ey.x=this.m_K.ex.y,this.m_K.ey.y=b+B,this.m_K.ey.y===0&&(this.m_K.ey.y=1),this.m_enableLimit?this.m_translation=s.DotVV(this.m_axis,f):(this.m_lowerImpulse=0,this.m_upperImpulse=0),this.m_enableMotor||(this.m_motorImpulse=0),t.step.warmStarting){this.m_impulse.SelfMul(t.step.dtRatio),this.m_motorImpulse*=t.step.dtRatio,this.m_lowerImpulse*=t.step.dtRatio,this.m_upperImpulse*=t.step.dtRatio;const x=this.m_motorImpulse+this.m_lowerImpulse-this.m_upperImpulse,v=s.AddVV(s.MulSV(this.m_impulse.x,this.m_perp,s.s_t0),s.MulSV(x,this.m_axis,s.s_t1),N.InitVelocityConstraints_s_P),V=this.m_impulse.x*this.m_s1+this.m_impulse.y+x*this.m_a1,k=this.m_impulse.x*this.m_s2+this.m_impulse.y+x*this.m_a2;n.SelfMulSub(A,v),o-=b*V,l.SelfMulAdd(S,v),y+=B*k}else this.m_impulse.SetZero(),this.m_motorImpulse=0,this.m_lowerImpulse=0,this.m_upperImpulse=0;t.velocities[this.m_indexA].w=o,t.velocities[this.m_indexB].w=y}SolveVelocityConstraints(t){const e=t.velocities[this.m_indexA].v;let i=t.velocities[this.m_indexA].w;const n=t.velocities[this.m_indexB].v;let o=t.velocities[this.m_indexB].w;const r=this.m_invMassA,h=this.m_invMassB,l=this.m_invIA,y=this.m_invIB;if(this.m_enableMotor){const c=s.DotVV(this.m_axis,s.SubVV(n,e,s.s_t0))+this.m_a2*o-this.m_a1*i;let m=this.m_axialMass*(this.m_motorSpeed-c);const a=this.m_motorImpulse,u=t.step.dt*this.m_maxMotorForce;this.m_motorImpulse=vt(this.m_motorImpulse+m,-u,u),m=this.m_motorImpulse-a;const f=s.MulSV(m,this.m_axis,N.SolveVelocityConstraints_s_P),A=m*this.m_a1,S=m*this.m_a2;e.SelfMulSub(r,f),i-=l*A,n.SelfMulAdd(h,f),o+=y*S}if(this.m_enableLimit){{const c=this.m_translation-this.m_lowerTranslation,m=s.DotVV(this.m_axis,s.SubVV(n,e,s.s_t0))+this.m_a2*o-this.m_a1*i;let a=-this.m_axialMass*(m+E(c,0)*t.step.inv_dt);const u=this.m_lowerImpulse;this.m_lowerImpulse=E(this.m_lowerImpulse+a,0),a=this.m_lowerImpulse-u;const f=s.MulSV(a,this.m_axis,N.SolveVelocityConstraints_s_P),A=a*this.m_a1,S=a*this.m_a2;e.SelfMulSub(r,f),i-=l*A,n.SelfMulAdd(h,f),o+=y*S}{const c=this.m_upperTranslation-this.m_translation,m=s.DotVV(this.m_axis,s.SubVV(e,n,s.s_t0))+this.m_a1*i-this.m_a2*o;let a=-this.m_axialMass*(m+E(c,0)*t.step.inv_dt);const u=this.m_upperImpulse;this.m_upperImpulse=E(this.m_upperImpulse+a,0),a=this.m_upperImpulse-u;const f=s.MulSV(a,this.m_axis,N.SolveVelocityConstraints_s_P),A=a*this.m_a1,S=a*this.m_a2;e.SelfMulAdd(r,f),i+=l*A,n.SelfMulSub(h,f),o-=y*S}}{const c=s.DotVV(this.m_perp,s.SubVV(n,e,s.s_t0))+this.m_s2*o-this.m_s1*i,m=o-i,a=this.m_K.Solve(-c,-m,N.SolveVelocityConstraints_s_df);this.m_impulse.SelfAdd(a);const u=s.MulSV(a.x,this.m_perp,N.SolveVelocityConstraints_s_P),f=a.x*this.m_s1+a.y,A=a.x*this.m_s2+a.y;e.SelfMulSub(r,u),i-=l*f,n.SelfMulAdd(h,u),o+=y*A}t.velocities[this.m_indexA].w=i,t.velocities[this.m_indexB].w=o}SolvePositionConstraints(t){const e=t.positions[this.m_indexA].c;let i=t.positions[this.m_indexA].a;const n=t.positions[this.m_indexB].c;let o=t.positions[this.m_indexB].a;const r=this.m_qA.SetAngle(i),h=this.m_qB.SetAngle(o),l=this.m_invMassA,y=this.m_invMassB,c=this.m_invIA,m=this.m_invIB,a=C.MulRV(r,this.m_lalcA,this.m_rA),u=C.MulRV(h,this.m_lalcB,this.m_rB),f=s.SubVV(s.AddVV(n,u,s.s_t0),s.AddVV(e,a,s.s_t1),N.SolvePositionConstraints_s_d),A=C.MulRV(r,this.m_localXAxisA,this.m_axis),S=s.CrossVV(s.AddVV(f,a,s.s_t0),A),b=s.CrossVV(u,A),B=C.MulRV(r,this.m_localYAxisA,this.m_perp),x=s.CrossVV(s.AddVV(f,a,s.s_t0),B),v=s.CrossVV(u,B);let V=N.SolvePositionConstraints_s_impulse;const k=s.DotVV(B,f),P=o-i-this.m_referenceAngle;let q=ot(k);const z=ot(P);let j=!1,Y=0;if(this.m_enableLimit){const U=s.DotVV(A,f);ot(this.m_upperTranslation-this.m_lowerTranslation)<2*Q?(Y=U,q=E(q,ot(U)),j=!0):U<=this.m_lowerTranslation?(Y=at(U-this.m_lowerTranslation,0),q=E(q,this.m_lowerTranslation-U),j=!0):U>=this.m_upperTranslation&&(Y=E(U-this.m_upperTranslation,0),q=E(q,U-this.m_upperTranslation),j=!0)}if(j){const U=l+y+c*x*x+m*v*v,it=c*x+m*v,rt=c*x*S+m*v*b;let St=c+m;St===0&&(St=1);const Tt=c*S+m*b,Pt=l+y+c*S*S+m*b*b,ns=this.m_K3;ns.ex.SetXYZ(U,it,rt),ns.ey.SetXYZ(it,St,Tt),ns.ez.SetXYZ(rt,Tt,Pt),V=ns.Solve33(-k,-P,-Y,V)}else{const U=l+y+c*x*x+m*v*v,it=c*x+m*v;let rt=c+m;rt===0&&(rt=1);const St=this.m_K2;St.ex.Set(U,it),St.ey.Set(it,rt);const Tt=St.Solve(-k,-P,N.SolvePositionConstraints_s_impulse1);V.x=Tt.x,V.y=Tt.y,V.z=0}const R=s.AddVV(s.MulSV(V.x,B,s.s_t0),s.MulSV(V.z,A,s.s_t1),N.SolvePositionConstraints_s_P),G=V.x*x+V.y+V.z*S,Z=V.x*v+V.y+V.z*b;return e.SelfMulSub(l,R),i-=c*G,n.SelfMulAdd(y,R),o+=m*Z,t.positions[this.m_indexA].a=i,t.positions[this.m_indexB].a=o,q<=Q&&z<=Dt}GetAnchorA(t){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA,t)}GetAnchorB(t){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB,t)}GetReactionForce(t,e){return e.x=t*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_lowerImpulse-this.m_upperImpulse)*this.m_axis.x),e.y=t*(this.m_impulse.y*this.m_perp.y+(this.m_motorImpulse+this.m_lowerImpulse-this.m_upperImpulse)*this.m_axis.y),e}GetReactionTorque(t){return t*this.m_impulse.y}GetLocalAnchorA(){return this.m_localAnchorA}GetLocalAnchorB(){return this.m_localAnchorB}GetLocalAxisA(){return this.m_localXAxisA}GetReferenceAngle(){return this.m_referenceAngle}GetJointTranslation(){const t=this.m_bodyA.GetWorldPoint(this.m_localAnchorA,N.GetJointTranslation_s_pA),e=this.m_bodyB.GetWorldPoint(this.m_localAnchorB,N.GetJointTranslation_s_pB),i=s.SubVV(e,t,N.GetJointTranslation_s_d),n=this.m_bodyA.GetWorldVector(this.m_localXAxisA,N.GetJointTranslation_s_axis);return s.DotVV(i,n)}GetJointSpeed(){const t=this.m_bodyA,e=this.m_bodyB;s.SubVV(this.m_localAnchorA,t.m_sweep.localCenter,this.m_lalcA);const i=C.MulRV(t.m_xf.q,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,e.m_sweep.localCenter,this.m_lalcB);const n=C.MulRV(e.m_xf.q,this.m_lalcB,this.m_rB),o=s.AddVV(t.m_sweep.c,i,s.s_t0),r=s.AddVV(e.m_sweep.c,n,s.s_t1),h=s.SubVV(r,o,s.s_t2),l=t.GetWorldVector(this.m_localXAxisA,this.m_axis),y=t.m_linearVelocity,c=e.m_linearVelocity,m=t.m_angularVelocity,a=e.m_angularVelocity;return s.DotVV(h,s.CrossSV(m,l,s.s_t0))+s.DotVV(l,s.SubVV(s.AddVCrossSV(c,a,n,s.s_t0),s.AddVCrossSV(y,m,i,s.s_t1),s.s_t0))}IsLimitEnabled(){return this.m_enableLimit}EnableLimit(t){t!==this.m_enableLimit&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableLimit=t,this.m_lowerImpulse=0,this.m_upperImpulse=0)}GetLowerLimit(){return this.m_lowerTranslation}GetUpperLimit(){return this.m_upperTranslation}SetLimits(t,e){(t!==this.m_lowerTranslation||e!==this.m_upperTranslation)&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_lowerTranslation=t,this.m_upperTranslation=e,this.m_lowerImpulse=0,this.m_upperImpulse=0)}IsMotorEnabled(){return this.m_enableMotor}EnableMotor(t){t!==this.m_enableMotor&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableMotor=t)}SetMotorSpeed(t){t!==this.m_motorSpeed&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_motorSpeed=t)}GetMotorSpeed(){return this.m_motorSpeed}SetMaxMotorForce(t){t!==this.m_maxMotorForce&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_maxMotorForce=t)}GetMaxMotorForce(){return this.m_maxMotorForce}GetMotorForce(t){return t*this.m_motorImpulse}Dump(t){const e=this.m_bodyA.m_islandIndex,i=this.m_bodyB.m_islandIndex;t(` const jd: b2PrismaticJointDef = new b2PrismaticJointDef(); `),t(` jd.bodyA = bodies[%d]; `,e),t(` jd.bodyB = bodies[%d]; `,i),t(` jd.collideConnected = %s; `,this.m_collideConnected?"true":"false"),t(` jd.localAnchorA.Set(%.15f, %.15f); `,this.m_localAnchorA.x,this.m_localAnchorA.y),t(` jd.localAnchorB.Set(%.15f, %.15f); `,this.m_localAnchorB.x,this.m_localAnchorB.y),t(` jd.localAxisA.Set(%.15f, %.15f); `,this.m_localXAxisA.x,this.m_localXAxisA.y),t(` jd.referenceAngle = %.15f; `,this.m_referenceAngle),t(` jd.enableLimit = %s; `,this.m_enableLimit?"true":"false"),t(` jd.lowerTranslation = %.15f; `,this.m_lowerTranslation),t(` jd.upperTranslation = %.15f; `,this.m_upperTranslation),t(` jd.enableMotor = %s; `,this.m_enableMotor?"true":"false"),t(` jd.motorSpeed = %.15f; `,this.m_motorSpeed),t(` jd.maxMotorForce = %.15f; `,this.m_maxMotorForce),t(` joints[%d] = this.m_world.CreateJoint(jd); `,this.m_index)}Draw(t){const e=this.m_bodyA.GetTransform(),i=this.m_bodyB.GetTransform(),n=I.MulXV(e,this.m_localAnchorA,N.Draw_s_pA),o=I.MulXV(i,this.m_localAnchorB,N.Draw_s_pB),r=C.MulRV(e.q,this.m_localXAxisA,N.Draw_s_axis),h=N.Draw_s_c1,l=N.Draw_s_c2,y=N.Draw_s_c3,c=N.Draw_s_c4,m=N.Draw_s_c5;if(t.DrawSegment(n,o,m),this.m_enableLimit){const a=s.AddVMulSV(n,this.m_lowerTranslation,r,N.Draw_s_lower),u=s.AddVMulSV(n,this.m_upperTranslation,r,N.Draw_s_upper),f=C.MulRV(e.q,this.m_localYAxisA,N.Draw_s_perp);t.DrawSegment(a,u,h),t.DrawSegment(s.AddVMulSV(a,-.5,f,s.s_t0),s.AddVMulSV(a,.5,f,s.s_t1),l),t.DrawSegment(s.AddVMulSV(u,-.5,f,s.s_t0),s.AddVMulSV(u,.5,f,s.s_t1),y)}else t.DrawSegment(s.AddVMulSV(n,-1,r,s.s_t0),s.AddVMulSV(n,1,r,s.s_t1),h);t.DrawPoint(n,5,h),t.DrawPoint(o,5,c)}}N.InitVelocityConstraints_s_d=new s,N.InitVelocityConstraints_s_P=new s,N.SolveVelocityConstraints_s_P=new s,N.SolveVelocityConstraints_s_df=new s,N.SolvePositionConstraints_s_d=new s,N.SolvePositionConstraints_s_impulse=new bt,N.SolvePositionConstraints_s_impulse1=new s,N.SolvePositionConstraints_s_P=new s,N.GetJointTranslation_s_pA=new s,N.GetJointTranslation_s_pB=new s,N.GetJointTranslation_s_d=new s,N.GetJointTranslation_s_axis=new s,N.Draw_s_pA=new s,N.Draw_s_pB=new s,N.Draw_s_axis=new s,N.Draw_s_c1=new O(.7,.7,.7),N.Draw_s_c2=new O(.3,.9,.3),N.Draw_s_c3=new O(.9,.3,.3),N.Draw_s_c4=new O(.3,.3,.9),N.Draw_s_c5=new O(.4,.4,.4),N.Draw_s_lower=new s,N.Draw_s_upper=new s,N.Draw_s_perp=new s;const so=2;class eo extends Ot{constructor(){super(_.b2JointType.e_pulleyJoint),this.groundAnchorA=new s(-1,1),this.groundAnchorB=new s(1,1),this.localAnchorA=new s(-1,0),this.localAnchorB=new s(1,0),this.lengthA=0,this.lengthB=0,this.ratio=1,this.collideConnected=!0}Initialize(t,e,i,n,o,r,h){this.bodyA=t,this.bodyB=e,this.groundAnchorA.Copy(i),this.groundAnchorB.Copy(n),this.bodyA.GetLocalPoint(o,this.localAnchorA),this.bodyB.GetLocalPoint(r,this.localAnchorB),this.lengthA=s.DistanceVV(o,i),this.lengthB=s.DistanceVV(r,n),this.ratio=h}}class _t extends pt{constructor(t){super(t),this.m_groundAnchorA=new s,this.m_groundAnchorB=new s,this.m_lengthA=0,this.m_lengthB=0,this.m_localAnchorA=new s,this.m_localAnchorB=new s,this.m_constant=0,this.m_ratio=0,this.m_impulse=0,this.m_indexA=0,this.m_indexB=0,this.m_uA=new s,this.m_uB=new s,this.m_rA=new s,this.m_rB=new s,this.m_localCenterA=new s,this.m_localCenterB=new s,this.m_invMassA=0,this.m_invMassB=0,this.m_invIA=0,this.m_invIB=0,this.m_mass=0,this.m_qA=new C,this.m_qB=new C,this.m_lalcA=new s,this.m_lalcB=new s,this.m_groundAnchorA.Copy(T(t.groundAnchorA,new s(-1,1))),this.m_groundAnchorB.Copy(T(t.groundAnchorB,new s(1,0))),this.m_localAnchorA.Copy(T(t.localAnchorA,new s(-1,0))),this.m_localAnchorB.Copy(T(t.localAnchorB,new s(1,0))),this.m_lengthA=T(t.lengthA,0),this.m_lengthB=T(t.lengthB,0),this.m_ratio=T(t.ratio,1),this.m_constant=T(t.lengthA,0)+this.m_ratio*T(t.lengthB,0),this.m_impulse=0}InitVelocityConstraints(t){this.m_indexA=this.m_bodyA.m_islandIndex,this.m_indexB=this.m_bodyB.m_islandIndex,this.m_localCenterA.Copy(this.m_bodyA.m_sweep.localCenter),this.m_localCenterB.Copy(this.m_bodyB.m_sweep.localCenter),this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;const e=t.positions[this.m_indexA].c,i=t.positions[this.m_indexA].a,n=t.velocities[this.m_indexA].v;let o=t.velocities[this.m_indexA].w;const r=t.positions[this.m_indexB].c,h=t.positions[this.m_indexB].a,l=t.velocities[this.m_indexB].v;let y=t.velocities[this.m_indexB].w;const c=this.m_qA.SetAngle(i),m=this.m_qB.SetAngle(h);s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA),C.MulRV(c,this.m_lalcA,this.m_rA),s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB),C.MulRV(m,this.m_lalcB,this.m_rB),this.m_uA.Copy(e).SelfAdd(this.m_rA).SelfSub(this.m_groundAnchorA),this.m_uB.Copy(r).SelfAdd(this.m_rB).SelfSub(this.m_groundAnchorB);const a=this.m_uA.Length(),u=this.m_uB.Length();a>10*Q?this.m_uA.SelfMul(1/a):this.m_uA.SetZero(),u>10*Q?this.m_uB.SelfMul(1/u):this.m_uB.SetZero();const f=s.CrossVV(this.m_rA,this.m_uA),A=s.CrossVV(this.m_rB,this.m_uB),S=this.m_invMassA+this.m_invIA*f*f,b=this.m_invMassB+this.m_invIB*A*A;if(this.m_mass=S+this.m_ratio*this.m_ratio*b,this.m_mass>0&&(this.m_mass=1/this.m_mass),t.step.warmStarting){this.m_impulse*=t.step.dtRatio;const B=s.MulSV(-this.m_impulse,this.m_uA,_t.InitVelocityConstraints_s_PA),x=s.MulSV(-this.m_ratio*this.m_impulse,this.m_uB,_t.InitVelocityConstraints_s_PB);n.SelfMulAdd(this.m_invMassA,B),o+=this.m_invIA*s.CrossVV(this.m_rA,B),l.SelfMulAdd(this.m_invMassB,x),y+=this.m_invIB*s.CrossVV(this.m_rB,x)}else this.m_impulse=0;t.velocities[this.m_indexA].w=o,t.velocities[this.m_indexB].w=y}SolveVelocityConstraints(t){const e=t.velocities[this.m_indexA].v;let i=t.velocities[this.m_indexA].w;const n=t.velocities[this.m_indexB].v;let o=t.velocities[this.m_indexB].w;const r=s.AddVCrossSV(e,i,this.m_rA,_t.SolveVelocityConstraints_s_vpA),h=s.AddVCrossSV(n,o,this.m_rB,_t.SolveVelocityConstraints_s_vpB),l=-s.DotVV(this.m_uA,r)-this.m_ratio*s.DotVV(this.m_uB,h),y=-this.m_mass*l;this.m_impulse+=y;const c=s.MulSV(-y,this.m_uA,_t.SolveVelocityConstraints_s_PA),m=s.MulSV(-this.m_ratio*y,this.m_uB,_t.SolveVelocityConstraints_s_PB);e.SelfMulAdd(this.m_invMassA,c),i+=this.m_invIA*s.CrossVV(this.m_rA,c),n.SelfMulAdd(this.m_invMassB,m),o+=this.m_invIB*s.CrossVV(this.m_rB,m),t.velocities[this.m_indexA].w=i,t.velocities[this.m_indexB].w=o}SolvePositionConstraints(t){const e=t.positions[this.m_indexA].c;let i=t.positions[this.m_indexA].a;const n=t.positions[this.m_indexB].c;let o=t.positions[this.m_indexB].a;const r=this.m_qA.SetAngle(i),h=this.m_qB.SetAngle(o);s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA);const l=C.MulRV(r,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB);const y=C.MulRV(h,this.m_lalcB,this.m_rB),c=this.m_uA.Copy(e).SelfAdd(l).SelfSub(this.m_groundAnchorA),m=this.m_uB.Copy(n).SelfAdd(y).SelfSub(this.m_groundAnchorB),a=c.Length(),u=m.Length();a>10*Q?c.SelfMul(1/a):c.SetZero(),u>10*Q?m.SelfMul(1/u):m.SetZero();const f=s.CrossVV(l,c),A=s.CrossVV(y,m),S=this.m_invMassA+this.m_invIA*f*f,b=this.m_invMassB+this.m_invIB*A*A;let B=S+this.m_ratio*this.m_ratio*b;B>0&&(B=1/B);const x=this.m_constant-a-this.m_ratio*u,v=ot(x),V=-B*x,k=s.MulSV(-V,c,_t.SolvePositionConstraints_s_PA),P=s.MulSV(-this.m_ratio*V,m,_t.SolvePositionConstraints_s_PB);return e.SelfMulAdd(this.m_invMassA,k),i+=this.m_invIA*s.CrossVV(l,k),n.SelfMulAdd(this.m_invMassB,P),o+=this.m_invIB*s.CrossVV(y,P),t.positions[this.m_indexA].a=i,t.positions[this.m_indexB].a=o,v0?(this.m_axialMass=1/this.m_axialMass,f=!1):f=!0,this.m_angle=o-e-this.m_referenceAngle,(this.m_enableLimit===!1||f)&&(this.m_lowerImpulse=0,this.m_upperImpulse=0),(this.m_enableMotor===!1||f)&&(this.m_motorImpulse=0),t.step.warmStarting){this.m_impulse.SelfMul(t.step.dtRatio),this.m_motorImpulse*=t.step.dtRatio,this.m_lowerImpulse*=t.step.dtRatio,this.m_upperImpulse*=t.step.dtRatio;const A=this.m_motorImpulse+this.m_lowerImpulse-this.m_upperImpulse,S=st.InitVelocityConstraints_s_P.Set(this.m_impulse.x,this.m_impulse.y);i.SelfMulSub(c,S),n-=a*(s.CrossVV(this.m_rA,S)+A),r.SelfMulAdd(m,S),h+=u*(s.CrossVV(this.m_rB,S)+A)}else this.m_impulse.SetZero(),this.m_motorImpulse=0,this.m_lowerImpulse=0,this.m_upperImpulse=0;t.velocities[this.m_indexA].w=n,t.velocities[this.m_indexB].w=h}SolveVelocityConstraints(t){const e=t.velocities[this.m_indexA].v;let i=t.velocities[this.m_indexA].w;const n=t.velocities[this.m_indexB].v;let o=t.velocities[this.m_indexB].w;const r=this.m_invMassA,h=this.m_invMassB,l=this.m_invIA,y=this.m_invIB,c=l+y===0;if(this.m_enableMotor&&!c){const m=o-i-this.m_motorSpeed;let a=-this.m_axialMass*m;const u=this.m_motorImpulse,f=t.step.dt*this.m_maxMotorTorque;this.m_motorImpulse=vt(this.m_motorImpulse+a,-f,f),a=this.m_motorImpulse-u,i-=l*a,o+=y*a}if(this.m_enableLimit&&!c){{const m=this.m_angle-this.m_lowerAngle,a=o-i;let u=-this.m_axialMass*(a+E(m,0)*t.step.inv_dt);const f=this.m_lowerImpulse;this.m_lowerImpulse=E(this.m_lowerImpulse+u,0),u=this.m_lowerImpulse-f,i-=l*u,o+=y*u}{const m=this.m_upperAngle-this.m_angle,a=i-o;let u=-this.m_axialMass*(a+E(m,0)*t.step.inv_dt);const f=this.m_upperImpulse;this.m_upperImpulse=E(this.m_upperImpulse+u,0),u=this.m_upperImpulse-f,i+=l*u,o-=y*u}}{const m=s.SubVV(s.AddVCrossSV(n,o,this.m_rB,s.s_t0),s.AddVCrossSV(e,i,this.m_rA,s.s_t1),st.SolveVelocityConstraints_s_Cdot_v2),a=this.m_K.Solve(-m.x,-m.y,st.SolveVelocityConstraints_s_impulse_v2);this.m_impulse.x+=a.x,this.m_impulse.y+=a.y,e.SelfMulSub(r,a),i-=l*s.CrossVV(this.m_rA,a),n.SelfMulAdd(h,a),o+=y*s.CrossVV(this.m_rB,a)}t.velocities[this.m_indexA].w=i,t.velocities[this.m_indexB].w=o}SolvePositionConstraints(t){const e=t.positions[this.m_indexA].c;let i=t.positions[this.m_indexA].a;const n=t.positions[this.m_indexB].c;let o=t.positions[this.m_indexB].a;const r=this.m_qA.SetAngle(i),h=this.m_qB.SetAngle(o);let l=0,y=0;const c=this.m_invIA+this.m_invIB===0;if(this.m_enableLimit&&!c){const m=o-i-this.m_referenceAngle;let a=0;ot(this.m_upperAngle-this.m_lowerAngle)<2*Dt?a=vt(m-this.m_lowerAngle,-qt,qt):m<=this.m_lowerAngle?a=vt(m-this.m_lowerAngle+Dt,-qt,0):m>=this.m_upperAngle&&(a=vt(m-this.m_upperAngle-Dt,0,qt));const u=-this.m_axialMass*a;i-=this.m_invIA*u,o+=this.m_invIB*u,l=ot(a)}{r.SetAngle(i),h.SetAngle(o),s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA);const m=C.MulRV(r,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB);const a=C.MulRV(h,this.m_lalcB,this.m_rB),u=s.SubVV(s.AddVV(n,a,s.s_t0),s.AddVV(e,m,s.s_t1),st.SolvePositionConstraints_s_C_v2);y=u.Length();const f=this.m_invMassA,A=this.m_invMassB,S=this.m_invIA,b=this.m_invIB,B=this.m_K;B.ex.x=f+A+S*m.y*m.y+b*a.y*a.y,B.ex.y=-S*m.x*m.y-b*a.x*a.y,B.ey.x=B.ex.y,B.ey.y=f+A+S*m.x*m.x+b*a.x*a.x;const x=B.Solve(u.x,u.y,st.SolvePositionConstraints_s_impulse).SelfNeg();e.SelfMulSub(f,x),i-=S*s.CrossVV(m,x),n.SelfMulAdd(A,x),o+=b*s.CrossVV(a,x)}return t.positions[this.m_indexA].a=i,t.positions[this.m_indexB].a=o,y<=Q&&l<=Dt}GetAnchorA(t){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA,t)}GetAnchorB(t){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB,t)}GetReactionForce(t,e){return e.x=t*this.m_impulse.x,e.y=t*this.m_impulse.y,e}GetReactionTorque(t){return t*(this.m_lowerImpulse-this.m_upperImpulse)}GetLocalAnchorA(){return this.m_localAnchorA}GetLocalAnchorB(){return this.m_localAnchorB}GetReferenceAngle(){return this.m_referenceAngle}GetJointAngle(){return this.m_bodyB.m_sweep.a-this.m_bodyA.m_sweep.a-this.m_referenceAngle}GetJointSpeed(){return this.m_bodyB.m_angularVelocity-this.m_bodyA.m_angularVelocity}IsMotorEnabled(){return this.m_enableMotor}EnableMotor(t){t!==this.m_enableMotor&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableMotor=t)}GetMotorTorque(t){return t*this.m_motorImpulse}GetMotorSpeed(){return this.m_motorSpeed}SetMaxMotorTorque(t){t!==this.m_maxMotorTorque&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_maxMotorTorque=t)}GetMaxMotorTorque(){return this.m_maxMotorTorque}IsLimitEnabled(){return this.m_enableLimit}EnableLimit(t){t!==this.m_enableLimit&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableLimit=t,this.m_lowerImpulse=0,this.m_upperImpulse=0)}GetLowerLimit(){return this.m_lowerAngle}GetUpperLimit(){return this.m_upperAngle}SetLimits(t,e){(t!==this.m_lowerAngle||e!==this.m_upperAngle)&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_lowerImpulse=0,this.m_upperImpulse=0,this.m_lowerAngle=t,this.m_upperAngle=e)}SetMotorSpeed(t){t!==this.m_motorSpeed&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_motorSpeed=t)}Dump(t){const e=this.m_bodyA.m_islandIndex,i=this.m_bodyB.m_islandIndex;t(` const jd: b2RevoluteJointDef = new b2RevoluteJointDef(); `),t(` jd.bodyA = bodies[%d]; `,e),t(` jd.bodyB = bodies[%d]; `,i),t(` jd.collideConnected = %s; `,this.m_collideConnected?"true":"false"),t(` jd.localAnchorA.Set(%.15f, %.15f); `,this.m_localAnchorA.x,this.m_localAnchorA.y),t(` jd.localAnchorB.Set(%.15f, %.15f); `,this.m_localAnchorB.x,this.m_localAnchorB.y),t(` jd.referenceAngle = %.15f; `,this.m_referenceAngle),t(` jd.enableLimit = %s; `,this.m_enableLimit?"true":"false"),t(` jd.lowerAngle = %.15f; `,this.m_lowerAngle),t(` jd.upperAngle = %.15f; `,this.m_upperAngle),t(` jd.enableMotor = %s; `,this.m_enableMotor?"true":"false"),t(` jd.motorSpeed = %.15f; `,this.m_motorSpeed),t(` jd.maxMotorTorque = %.15f; `,this.m_maxMotorTorque),t(` joints[%d] = this.m_world.CreateJoint(jd); `,this.m_index)}Draw(t){const e=this.m_bodyA.GetTransform(),i=this.m_bodyB.GetTransform(),n=I.MulXV(e,this.m_localAnchorA,st.Draw_s_pA),o=I.MulXV(i,this.m_localAnchorB,st.Draw_s_pB),r=st.Draw_s_c1,h=st.Draw_s_c2,l=st.Draw_s_c3,y=st.Draw_s_c4,c=st.Draw_s_c5;t.DrawPoint(n,5,y),t.DrawPoint(o,5,c);const m=this.m_bodyA.GetAngle(),u=this.m_bodyB.GetAngle()-m-this.m_referenceAngle,f=.5,A=st.Draw_s_r.Set(f*Math.cos(u),f*Math.sin(u));if(t.DrawSegment(o,s.AddVV(o,A,s.s_t0),r),t.DrawCircle(o,f,r),this.m_enableLimit){const b=st.Draw_s_rlo.Set(f*Math.cos(this.m_lowerAngle),f*Math.sin(this.m_lowerAngle)),B=st.Draw_s_rhi.Set(f*Math.cos(this.m_upperAngle),f*Math.sin(this.m_upperAngle));t.DrawSegment(o,s.AddVV(o,b,s.s_t0),h),t.DrawSegment(o,s.AddVV(o,B,s.s_t0),l)}const S=st.Draw_s_color_;t.DrawSegment(e.p,n,S),t.DrawSegment(n,o,S),t.DrawSegment(i.p,o,S)}}st.InitVelocityConstraints_s_P=new s,st.SolveVelocityConstraints_s_Cdot_v2=new s,st.SolveVelocityConstraints_s_impulse_v2=new s,st.SolvePositionConstraints_s_C_v2=new s,st.SolvePositionConstraints_s_impulse=new s,st.Draw_s_pA=new s,st.Draw_s_pB=new s,st.Draw_s_c1=new O(.7,.7,.7),st.Draw_s_c2=new O(.3,.9,.3),st.Draw_s_c3=new O(.9,.3,.3),st.Draw_s_c4=new O(.3,.3,.9),st.Draw_s_c5=new O(.4,.4,.4),st.Draw_s_color_=new O(.5,.8,.8),st.Draw_s_r=new s,st.Draw_s_rlo=new s,st.Draw_s_rhi=new s;class no extends Ot{constructor(){super(_.b2JointType.e_weldJoint),this.localAnchorA=new s,this.localAnchorB=new s,this.referenceAngle=0,this.stiffness=0,this.damping=0}Initialize(t,e,i){this.bodyA=t,this.bodyB=e,this.bodyA.GetLocalPoint(i,this.localAnchorA),this.bodyB.GetLocalPoint(i,this.localAnchorB),this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()}}class ct extends pt{constructor(t){super(t),this.m_stiffness=0,this.m_damping=0,this.m_bias=0,this.m_localAnchorA=new s,this.m_localAnchorB=new s,this.m_referenceAngle=0,this.m_gamma=0,this.m_impulse=new bt(0,0,0),this.m_indexA=0,this.m_indexB=0,this.m_rA=new s,this.m_rB=new s,this.m_localCenterA=new s,this.m_localCenterB=new s,this.m_invMassA=0,this.m_invMassB=0,this.m_invIA=0,this.m_invIB=0,this.m_mass=new Yt,this.m_qA=new C,this.m_qB=new C,this.m_lalcA=new s,this.m_lalcB=new s,this.m_K=new Yt,this.m_stiffness=T(t.stiffness,0),this.m_damping=T(t.damping,0),this.m_localAnchorA.Copy(T(t.localAnchorA,s.ZERO)),this.m_localAnchorB.Copy(T(t.localAnchorB,s.ZERO)),this.m_referenceAngle=T(t.referenceAngle,0),this.m_impulse.SetZero()}InitVelocityConstraints(t){this.m_indexA=this.m_bodyA.m_islandIndex,this.m_indexB=this.m_bodyB.m_islandIndex,this.m_localCenterA.Copy(this.m_bodyA.m_sweep.localCenter),this.m_localCenterB.Copy(this.m_bodyB.m_sweep.localCenter),this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;const e=t.positions[this.m_indexA].a,i=t.velocities[this.m_indexA].v;let n=t.velocities[this.m_indexA].w;const o=t.positions[this.m_indexB].a,r=t.velocities[this.m_indexB].v;let h=t.velocities[this.m_indexB].w;const l=this.m_qA.SetAngle(e),y=this.m_qB.SetAngle(o);s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA),C.MulRV(l,this.m_lalcA,this.m_rA),s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB),C.MulRV(y,this.m_lalcB,this.m_rB);const c=this.m_invMassA,m=this.m_invMassB,a=this.m_invIA,u=this.m_invIB,f=this.m_K;if(f.ex.x=c+m+this.m_rA.y*this.m_rA.y*a+this.m_rB.y*this.m_rB.y*u,f.ey.x=-this.m_rA.y*this.m_rA.x*a-this.m_rB.y*this.m_rB.x*u,f.ez.x=-this.m_rA.y*a-this.m_rB.y*u,f.ex.y=f.ey.x,f.ey.y=c+m+this.m_rA.x*this.m_rA.x*a+this.m_rB.x*this.m_rB.x*u,f.ez.y=this.m_rA.x*a+this.m_rB.x*u,f.ex.z=f.ez.x,f.ey.z=f.ez.y,f.ez.z=a+u,this.m_stiffness>0){f.GetInverse22(this.m_mass);let A=a+u;const S=o-e-this.m_referenceAngle,b=this.m_damping,B=this.m_stiffness,x=t.step.dt;this.m_gamma=x*(b+x*B),this.m_gamma=this.m_gamma!==0?1/this.m_gamma:0,this.m_bias=S*x*B*this.m_gamma,A+=this.m_gamma,this.m_mass.ez.z=A!==0?1/A:0}else f.GetSymInverse33(this.m_mass),this.m_gamma=0,this.m_bias=0;if(t.step.warmStarting){this.m_impulse.SelfMul(t.step.dtRatio);const A=ct.InitVelocityConstraints_s_P.Set(this.m_impulse.x,this.m_impulse.y);i.SelfMulSub(c,A),n-=a*(s.CrossVV(this.m_rA,A)+this.m_impulse.z),r.SelfMulAdd(m,A),h+=u*(s.CrossVV(this.m_rB,A)+this.m_impulse.z)}else this.m_impulse.SetZero();t.velocities[this.m_indexA].w=n,t.velocities[this.m_indexB].w=h}SolveVelocityConstraints(t){const e=t.velocities[this.m_indexA].v;let i=t.velocities[this.m_indexA].w;const n=t.velocities[this.m_indexB].v;let o=t.velocities[this.m_indexB].w;const r=this.m_invMassA,h=this.m_invMassB,l=this.m_invIA,y=this.m_invIB;if(this.m_stiffness>0){const c=o-i,m=-this.m_mass.ez.z*(c+this.m_bias+this.m_gamma*this.m_impulse.z);this.m_impulse.z+=m,i-=l*m,o+=y*m;const a=s.SubVV(s.AddVCrossSV(n,o,this.m_rB,s.s_t0),s.AddVCrossSV(e,i,this.m_rA,s.s_t1),ct.SolveVelocityConstraints_s_Cdot1),u=Yt.MulM33XY(this.m_mass,a.x,a.y,ct.SolveVelocityConstraints_s_impulse1).SelfNeg();this.m_impulse.x+=u.x,this.m_impulse.y+=u.y;const f=u;e.SelfMulSub(r,f),i-=l*s.CrossVV(this.m_rA,f),n.SelfMulAdd(h,f),o+=y*s.CrossVV(this.m_rB,f)}else{const c=s.SubVV(s.AddVCrossSV(n,o,this.m_rB,s.s_t0),s.AddVCrossSV(e,i,this.m_rA,s.s_t1),ct.SolveVelocityConstraints_s_Cdot1),m=o-i,a=Yt.MulM33XYZ(this.m_mass,c.x,c.y,m,ct.SolveVelocityConstraints_s_impulse).SelfNeg();this.m_impulse.SelfAdd(a);const u=ct.SolveVelocityConstraints_s_P.Set(a.x,a.y);e.SelfMulSub(r,u),i-=l*(s.CrossVV(this.m_rA,u)+a.z),n.SelfMulAdd(h,u),o+=y*(s.CrossVV(this.m_rB,u)+a.z)}t.velocities[this.m_indexA].w=i,t.velocities[this.m_indexB].w=o}SolvePositionConstraints(t){const e=t.positions[this.m_indexA].c;let i=t.positions[this.m_indexA].a;const n=t.positions[this.m_indexB].c;let o=t.positions[this.m_indexB].a;const r=this.m_qA.SetAngle(i),h=this.m_qB.SetAngle(o),l=this.m_invMassA,y=this.m_invMassB,c=this.m_invIA,m=this.m_invIB;s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA);const a=C.MulRV(r,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB);const u=C.MulRV(h,this.m_lalcB,this.m_rB);let f,A;const S=this.m_K;if(S.ex.x=l+y+a.y*a.y*c+u.y*u.y*m,S.ey.x=-a.y*a.x*c-u.y*u.x*m,S.ez.x=-a.y*c-u.y*m,S.ex.y=S.ey.x,S.ey.y=l+y+a.x*a.x*c+u.x*u.x*m,S.ez.y=a.x*c+u.x*m,S.ex.z=S.ez.x,S.ey.z=S.ez.y,S.ez.z=c+m,this.m_stiffness>0){const b=s.SubVV(s.AddVV(n,u,s.s_t0),s.AddVV(e,a,s.s_t1),ct.SolvePositionConstraints_s_C1);f=b.Length(),A=0;const B=S.Solve22(b.x,b.y,ct.SolvePositionConstraints_s_P).SelfNeg();e.SelfMulSub(l,B),i-=c*s.CrossVV(a,B),n.SelfMulAdd(y,B),o+=m*s.CrossVV(u,B)}else{const b=s.SubVV(s.AddVV(n,u,s.s_t0),s.AddVV(e,a,s.s_t1),ct.SolvePositionConstraints_s_C1),B=o-i-this.m_referenceAngle;f=b.Length(),A=ot(B);const x=S.Solve33(b.x,b.y,B,ct.SolvePositionConstraints_s_impulse).SelfNeg(),v=ct.SolvePositionConstraints_s_P.Set(x.x,x.y);e.SelfMulSub(l,v),i-=c*(s.CrossVV(this.m_rA,v)+x.z),n.SelfMulAdd(y,v),o+=m*(s.CrossVV(this.m_rB,v)+x.z)}return t.positions[this.m_indexA].a=i,t.positions[this.m_indexB].a=o,f<=Q&&A<=Dt}GetAnchorA(t){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA,t)}GetAnchorB(t){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB,t)}GetReactionForce(t,e){return e.x=t*this.m_impulse.x,e.y=t*this.m_impulse.y,e}GetReactionTorque(t){return t*this.m_impulse.z}GetLocalAnchorA(){return this.m_localAnchorA}GetLocalAnchorB(){return this.m_localAnchorB}GetReferenceAngle(){return this.m_referenceAngle}SetStiffness(t){this.m_stiffness=t}GetStiffness(){return this.m_stiffness}SetDamping(t){this.m_damping=t}GetDamping(){return this.m_damping}Dump(t){const e=this.m_bodyA.m_islandIndex,i=this.m_bodyB.m_islandIndex;t(` const jd: b2WeldJointDef = new b2WeldJointDef(); `),t(` jd.bodyA = bodies[%d]; `,e),t(` jd.bodyB = bodies[%d]; `,i),t(` jd.collideConnected = %s; `,this.m_collideConnected?"true":"false"),t(` jd.localAnchorA.Set(%.15f, %.15f); `,this.m_localAnchorA.x,this.m_localAnchorA.y),t(` jd.localAnchorB.Set(%.15f, %.15f); `,this.m_localAnchorB.x,this.m_localAnchorB.y),t(` jd.referenceAngle = %.15f; `,this.m_referenceAngle),t(` jd.stiffness = %.15f; `,this.m_stiffness),t(` jd.damping = %.15f; `,this.m_damping),t(` joints[%d] = this.m_world.CreateJoint(jd); `,this.m_index)}}ct.InitVelocityConstraints_s_P=new s,ct.SolveVelocityConstraints_s_Cdot1=new s,ct.SolveVelocityConstraints_s_impulse1=new s,ct.SolveVelocityConstraints_s_impulse=new bt,ct.SolveVelocityConstraints_s_P=new s,ct.SolvePositionConstraints_s_C1=new s,ct.SolvePositionConstraints_s_P=new s,ct.SolvePositionConstraints_s_impulse=new bt;class oo extends Ot{constructor(){super(_.b2JointType.e_wheelJoint),this.localAnchorA=new s(0,0),this.localAnchorB=new s(0,0),this.localAxisA=new s(1,0),this.enableLimit=!1,this.lowerTranslation=0,this.upperTranslation=0,this.enableMotor=!1,this.maxMotorTorque=0,this.motorSpeed=0,this.stiffness=0,this.damping=0}Initialize(t,e,i,n){this.bodyA=t,this.bodyB=e,this.bodyA.GetLocalPoint(i,this.localAnchorA),this.bodyB.GetLocalPoint(i,this.localAnchorB),this.bodyA.GetLocalVector(n,this.localAxisA)}}class $ extends pt{constructor(t){super(t),this.m_localAnchorA=new s,this.m_localAnchorB=new s,this.m_localXAxisA=new s,this.m_localYAxisA=new s,this.m_impulse=0,this.m_motorImpulse=0,this.m_springImpulse=0,this.m_lowerImpulse=0,this.m_upperImpulse=0,this.m_translation=0,this.m_lowerTranslation=0,this.m_upperTranslation=0,this.m_maxMotorTorque=0,this.m_motorSpeed=0,this.m_enableLimit=!1,this.m_enableMotor=!1,this.m_stiffness=0,this.m_damping=0,this.m_indexA=0,this.m_indexB=0,this.m_localCenterA=new s,this.m_localCenterB=new s,this.m_invMassA=0,this.m_invMassB=0,this.m_invIA=0,this.m_invIB=0,this.m_ax=new s,this.m_ay=new s,this.m_sAx=0,this.m_sBx=0,this.m_sAy=0,this.m_sBy=0,this.m_mass=0,this.m_motorMass=0,this.m_axialMass=0,this.m_springMass=0,this.m_bias=0,this.m_gamma=0,this.m_qA=new C,this.m_qB=new C,this.m_lalcA=new s,this.m_lalcB=new s,this.m_rA=new s,this.m_rB=new s,this.m_localAnchorA.Copy(T(t.localAnchorA,s.ZERO)),this.m_localAnchorB.Copy(T(t.localAnchorB,s.ZERO)),this.m_localXAxisA.Copy(T(t.localAxisA,s.UNITX)),s.CrossOneV(this.m_localXAxisA,this.m_localYAxisA),this.m_lowerTranslation=T(t.lowerTranslation,0),this.m_upperTranslation=T(t.upperTranslation,0),this.m_enableLimit=T(t.enableLimit,!1),this.m_maxMotorTorque=T(t.maxMotorTorque,0),this.m_motorSpeed=T(t.motorSpeed,0),this.m_enableMotor=T(t.enableMotor,!1),this.m_ax.SetZero(),this.m_ay.SetZero(),this.m_stiffness=T(t.stiffness,0),this.m_damping=T(t.damping,0)}GetMotorSpeed(){return this.m_motorSpeed}GetMaxMotorTorque(){return this.m_maxMotorTorque}SetStiffness(t){this.m_stiffness=t}GetStiffness(){return this.m_stiffness}SetDamping(t){this.m_damping=t}GetDamping(){return this.m_damping}InitVelocityConstraints(t){this.m_indexA=this.m_bodyA.m_islandIndex,this.m_indexB=this.m_bodyB.m_islandIndex,this.m_localCenterA.Copy(this.m_bodyA.m_sweep.localCenter),this.m_localCenterB.Copy(this.m_bodyB.m_sweep.localCenter),this.m_invMassA=this.m_bodyA.m_invMass,this.m_invMassB=this.m_bodyB.m_invMass,this.m_invIA=this.m_bodyA.m_invI,this.m_invIB=this.m_bodyB.m_invI;const e=this.m_invMassA,i=this.m_invMassB,n=this.m_invIA,o=this.m_invIB,r=t.positions[this.m_indexA].c,h=t.positions[this.m_indexA].a,l=t.velocities[this.m_indexA].v;let y=t.velocities[this.m_indexA].w;const c=t.positions[this.m_indexB].c,m=t.positions[this.m_indexB].a,a=t.velocities[this.m_indexB].v;let u=t.velocities[this.m_indexB].w;const f=this.m_qA.SetAngle(h),A=this.m_qB.SetAngle(m);s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA);const S=C.MulRV(f,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB);const b=C.MulRV(A,this.m_lalcB,this.m_rB),B=s.SubVV(s.AddVV(c,b,s.s_t0),s.AddVV(r,S,s.s_t1),$.InitVelocityConstraints_s_d);C.MulRV(f,this.m_localYAxisA,this.m_ay),this.m_sAy=s.CrossVV(s.AddVV(B,S,s.s_t0),this.m_ay),this.m_sBy=s.CrossVV(b,this.m_ay),this.m_mass=e+i+n*this.m_sAy*this.m_sAy+o*this.m_sBy*this.m_sBy,this.m_mass>0&&(this.m_mass=1/this.m_mass),C.MulRV(f,this.m_localXAxisA,this.m_ax),this.m_sAx=s.CrossVV(s.AddVV(B,S,s.s_t0),this.m_ax),this.m_sBx=s.CrossVV(b,this.m_ax);const x=e+i+n*this.m_sAx*this.m_sAx+o*this.m_sBx*this.m_sBx;if(x>0?this.m_axialMass=1/x:this.m_axialMass=0,this.m_springMass=0,this.m_bias=0,this.m_gamma=0,this.m_stiffness>0&&x>0){this.m_springMass=1/x;const v=s.DotVV(B,this.m_ax),V=t.step.dt;this.m_gamma=V*(this.m_damping+V*this.m_stiffness),this.m_gamma>0&&(this.m_gamma=1/this.m_gamma),this.m_bias=v*V*this.m_stiffness*this.m_gamma,this.m_springMass=x+this.m_gamma,this.m_springMass>0&&(this.m_springMass=1/this.m_springMass)}else this.m_springImpulse=0;if(this.m_enableLimit?this.m_translation=s.DotVV(this.m_ax,B):(this.m_lowerImpulse=0,this.m_upperImpulse=0),this.m_enableMotor?(this.m_motorMass=n+o,this.m_motorMass>0&&(this.m_motorMass=1/this.m_motorMass)):(this.m_motorMass=0,this.m_motorImpulse=0),t.step.warmStarting){this.m_impulse*=t.step.dtRatio,this.m_springImpulse*=t.step.dtRatio,this.m_motorImpulse*=t.step.dtRatio;const v=this.m_springImpulse+this.m_lowerImpulse-this.m_upperImpulse,V=s.AddVV(s.MulSV(this.m_impulse,this.m_ay,s.s_t0),s.MulSV(v,this.m_ax,s.s_t1),$.InitVelocityConstraints_s_P),k=this.m_impulse*this.m_sAy+v*this.m_sAx+this.m_motorImpulse,P=this.m_impulse*this.m_sBy+v*this.m_sBx+this.m_motorImpulse;l.SelfMulSub(this.m_invMassA,V),y-=this.m_invIA*k,a.SelfMulAdd(this.m_invMassB,V),u+=this.m_invIB*P}else this.m_impulse=0,this.m_springImpulse=0,this.m_motorImpulse=0,this.m_lowerImpulse=0,this.m_upperImpulse=0;t.velocities[this.m_indexA].w=y,t.velocities[this.m_indexB].w=u}SolveVelocityConstraints(t){const e=this.m_invMassA,i=this.m_invMassB,n=this.m_invIA,o=this.m_invIB,r=t.velocities[this.m_indexA].v;let h=t.velocities[this.m_indexA].w;const l=t.velocities[this.m_indexB].v;let y=t.velocities[this.m_indexB].w;{const c=s.DotVV(this.m_ax,s.SubVV(l,r,s.s_t0))+this.m_sBx*y-this.m_sAx*h,m=-this.m_springMass*(c+this.m_bias+this.m_gamma*this.m_springImpulse);this.m_springImpulse+=m;const a=s.MulSV(m,this.m_ax,$.SolveVelocityConstraints_s_P),u=m*this.m_sAx,f=m*this.m_sBx;r.SelfMulSub(e,a),h-=n*u,l.SelfMulAdd(i,a),y+=o*f}{const c=y-h-this.m_motorSpeed;let m=-this.m_motorMass*c;const a=this.m_motorImpulse,u=t.step.dt*this.m_maxMotorTorque;this.m_motorImpulse=vt(this.m_motorImpulse+m,-u,u),m=this.m_motorImpulse-a,h-=n*m,y+=o*m}if(this.m_enableLimit){{const c=this.m_translation-this.m_lowerTranslation,m=s.DotVV(this.m_ax,s.SubVV(l,r,s.s_t0))+this.m_sBx*y-this.m_sAx*h;let a=-this.m_axialMass*(m+E(c,0)*t.step.inv_dt);const u=this.m_lowerImpulse;this.m_lowerImpulse=E(this.m_lowerImpulse+a,0),a=this.m_lowerImpulse-u;const f=s.MulSV(a,this.m_ax,$.SolveVelocityConstraints_s_P),A=a*this.m_sAx,S=a*this.m_sBx;r.SelfMulSub(e,f),h-=n*A,l.SelfMulAdd(i,f),y+=o*S}{const c=this.m_upperTranslation-this.m_translation,m=s.DotVV(this.m_ax,s.SubVV(r,l,s.s_t0))+this.m_sAx*h-this.m_sBx*y;let a=-this.m_axialMass*(m+E(c,0)*t.step.inv_dt);const u=this.m_upperImpulse;this.m_upperImpulse=E(this.m_upperImpulse+a,0),a=this.m_upperImpulse-u;const f=s.MulSV(a,this.m_ax,$.SolveVelocityConstraints_s_P),A=a*this.m_sAx,S=a*this.m_sBx;r.SelfMulAdd(e,f),h+=n*A,l.SelfMulSub(i,f),y-=o*S}}{const c=s.DotVV(this.m_ay,s.SubVV(l,r,s.s_t0))+this.m_sBy*y-this.m_sAy*h,m=-this.m_mass*c;this.m_impulse+=m;const a=s.MulSV(m,this.m_ay,$.SolveVelocityConstraints_s_P),u=m*this.m_sAy,f=m*this.m_sBy;r.SelfMulSub(e,a),h-=n*u,l.SelfMulAdd(i,a),y+=o*f}t.velocities[this.m_indexA].w=h,t.velocities[this.m_indexB].w=y}SolvePositionConstraints(t){const e=t.positions[this.m_indexA].c;let i=t.positions[this.m_indexA].a;const n=t.positions[this.m_indexB].c;let o=t.positions[this.m_indexB].a,r=0;if(this.m_enableLimit){const h=this.m_qA.SetAngle(i),l=this.m_qB.SetAngle(o);s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA);const y=C.MulRV(h,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB);const c=C.MulRV(l,this.m_lalcB,this.m_rB),m=s.AddVV(s.SubVV(n,e,s.s_t0),s.SubVV(c,y,s.s_t1),$.SolvePositionConstraints_s_d),a=C.MulRV(h,this.m_localXAxisA,this.m_ax),u=s.CrossVV(s.AddVV(m,y,s.s_t0),this.m_ax),f=s.CrossVV(c,this.m_ax);let A=0;const S=s.DotVV(a,m);if(ot(this.m_upperTranslation-this.m_lowerTranslation)<2*Q?A=S:S<=this.m_lowerTranslation?A=at(S-this.m_lowerTranslation,0):S>=this.m_upperTranslation&&(A=E(S-this.m_upperTranslation,0)),A!==0){const b=this.m_invMassA+this.m_invMassB+this.m_invIA*u*u+this.m_invIB*f*f;let B=0;b!==0&&(B=-A/b);const x=s.MulSV(B,a,$.SolvePositionConstraints_s_P),v=B*u,V=B*f;e.SelfMulSub(this.m_invMassA,x),i-=this.m_invIA*v,n.SelfMulAdd(this.m_invMassB,x),o+=this.m_invIB*V,r=ot(A)}}{const h=this.m_qA.SetAngle(i),l=this.m_qB.SetAngle(o);s.SubVV(this.m_localAnchorA,this.m_localCenterA,this.m_lalcA);const y=C.MulRV(h,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,this.m_localCenterB,this.m_lalcB);const c=C.MulRV(l,this.m_lalcB,this.m_rB),m=s.AddVV(s.SubVV(n,e,s.s_t0),s.SubVV(c,y,s.s_t1),$.SolvePositionConstraints_s_d),a=C.MulRV(h,this.m_localYAxisA,this.m_ay),u=s.CrossVV(s.AddVV(m,y,s.s_t0),a),f=s.CrossVV(c,a),A=s.DotVV(m,a),S=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_sAy*this.m_sAy+this.m_invIB*this.m_sBy*this.m_sBy;let b=0;S!==0&&(b=-A/S);const B=s.MulSV(b,a,$.SolvePositionConstraints_s_P),x=b*u,v=b*f;e.SelfMulSub(this.m_invMassA,B),i-=this.m_invIA*x,n.SelfMulAdd(this.m_invMassB,B),o+=this.m_invIB*v,r=E(r,ot(A))}return t.positions[this.m_indexA].a=i,t.positions[this.m_indexB].a=o,r<=Q}GetDefinition(t){return t}GetAnchorA(t){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA,t)}GetAnchorB(t){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB,t)}GetReactionForce(t,e){return e.x=t*(this.m_impulse*this.m_ay.x+(this.m_springImpulse+this.m_lowerImpulse-this.m_upperImpulse)*this.m_ax.x),e.y=t*(this.m_impulse*this.m_ay.y+(this.m_springImpulse+this.m_lowerImpulse-this.m_upperImpulse)*this.m_ax.y),e}GetReactionTorque(t){return t*this.m_motorImpulse}GetLocalAnchorA(){return this.m_localAnchorA}GetLocalAnchorB(){return this.m_localAnchorB}GetLocalAxisA(){return this.m_localXAxisA}GetJointTranslation(){return this.GetPrismaticJointTranslation()}GetJointLinearSpeed(){return this.GetPrismaticJointSpeed()}GetJointAngle(){return this.GetRevoluteJointAngle()}GetJointAngularSpeed(){return this.GetRevoluteJointSpeed()}GetPrismaticJointTranslation(){const t=this.m_bodyA,e=this.m_bodyB,i=t.GetWorldPoint(this.m_localAnchorA,new s),n=e.GetWorldPoint(this.m_localAnchorB,new s),o=s.SubVV(n,i,new s),r=t.GetWorldVector(this.m_localXAxisA,new s);return s.DotVV(o,r)}GetPrismaticJointSpeed(){const t=this.m_bodyA,e=this.m_bodyB;s.SubVV(this.m_localAnchorA,t.m_sweep.localCenter,this.m_lalcA);const i=C.MulRV(t.m_xf.q,this.m_lalcA,this.m_rA);s.SubVV(this.m_localAnchorB,e.m_sweep.localCenter,this.m_lalcB);const n=C.MulRV(e.m_xf.q,this.m_lalcB,this.m_rB),o=s.AddVV(t.m_sweep.c,i,s.s_t0),r=s.AddVV(e.m_sweep.c,n,s.s_t1),h=s.SubVV(r,o,s.s_t2),l=t.GetWorldVector(this.m_localXAxisA,new s),y=t.m_linearVelocity,c=e.m_linearVelocity,m=t.m_angularVelocity,a=e.m_angularVelocity;return s.DotVV(h,s.CrossSV(m,l,s.s_t0))+s.DotVV(l,s.SubVV(s.AddVCrossSV(c,a,n,s.s_t0),s.AddVCrossSV(y,m,i,s.s_t1),s.s_t0))}GetRevoluteJointAngle(){return this.m_bodyB.m_sweep.a-this.m_bodyA.m_sweep.a}GetRevoluteJointSpeed(){const t=this.m_bodyA.m_angularVelocity;return this.m_bodyB.m_angularVelocity-t}IsMotorEnabled(){return this.m_enableMotor}EnableMotor(t){t!==this.m_enableMotor&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableMotor=t)}SetMotorSpeed(t){t!==this.m_motorSpeed&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_motorSpeed=t)}SetMaxMotorTorque(t){t!==this.m_maxMotorTorque&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_maxMotorTorque=t)}GetMotorTorque(t){return t*this.m_motorImpulse}IsLimitEnabled(){return this.m_enableLimit}EnableLimit(t){t!==this.m_enableLimit&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_enableLimit=t,this.m_lowerImpulse=0,this.m_upperImpulse=0)}GetLowerLimit(){return this.m_lowerTranslation}GetUpperLimit(){return this.m_upperTranslation}SetLimits(t,e){(t!==this.m_lowerTranslation||e!==this.m_upperTranslation)&&(this.m_bodyA.SetAwake(!0),this.m_bodyB.SetAwake(!0),this.m_lowerTranslation=t,this.m_upperTranslation=e,this.m_lowerImpulse=0,this.m_upperImpulse=0)}Dump(t){const e=this.m_bodyA.m_islandIndex,i=this.m_bodyB.m_islandIndex;t(` const jd: b2WheelJointDef = new b2WheelJointDef(); `),t(` jd.bodyA = bodies[%d]; `,e),t(` jd.bodyB = bodies[%d]; `,i),t(` jd.collideConnected = %s; `,this.m_collideConnected?"true":"false"),t(` jd.localAnchorA.Set(%.15f, %.15f); `,this.m_localAnchorA.x,this.m_localAnchorA.y),t(` jd.localAnchorB.Set(%.15f, %.15f); `,this.m_localAnchorB.x,this.m_localAnchorB.y),t(` jd.localAxisA.Set(%.15f, %.15f); `,this.m_localXAxisA.x,this.m_localXAxisA.y),t(` jd.enableMotor = %s; `,this.m_enableMotor?"true":"false"),t(` jd.motorSpeed = %.15f; `,this.m_motorSpeed),t(` jd.maxMotorTorque = %.15f; `,this.m_maxMotorTorque),t(` jd.stiffness = %.15f; `,this.m_stiffness),t(` jd.damping = %.15f; `,this.m_damping),t(` joints[%d] = this.m_world.CreateJoint(jd); `,this.m_index)}Draw(t){const e=this.m_bodyA.GetTransform(),i=this.m_bodyB.GetTransform(),n=I.MulXV(e,this.m_localAnchorA,$.Draw_s_pA),o=I.MulXV(i,this.m_localAnchorB,$.Draw_s_pB),r=C.MulRV(e.q,this.m_localXAxisA,$.Draw_s_axis),h=$.Draw_s_c1,l=$.Draw_s_c2,y=$.Draw_s_c3,c=$.Draw_s_c4,m=$.Draw_s_c5;if(t.DrawSegment(n,o,m),this.m_enableLimit){const a=s.AddVMulSV(n,this.m_lowerTranslation,r,$.Draw_s_lower),u=s.AddVMulSV(n,this.m_upperTranslation,r,$.Draw_s_upper),f=C.MulRV(e.q,this.m_localYAxisA,$.Draw_s_perp);t.DrawSegment(a,u,h),t.DrawSegment(s.AddVMulSV(a,-.5,f,s.s_t0),s.AddVMulSV(a,.5,f,s.s_t1),l),t.DrawSegment(s.AddVMulSV(u,-.5,f,s.s_t0),s.AddVMulSV(u,.5,f,s.s_t1),y)}else t.DrawSegment(s.AddVMulSV(n,-1,r,s.s_t0),s.AddVMulSV(n,1,r,s.s_t1),h);t.DrawPoint(n,5,h),t.DrawPoint(o,5,c)}}$.InitVelocityConstraints_s_d=new s,$.InitVelocityConstraints_s_P=new s,$.SolveVelocityConstraints_s_P=new s,$.SolvePositionConstraints_s_d=new s,$.SolvePositionConstraints_s_P=new s,$.Draw_s_pA=new s,$.Draw_s_pB=new s,$.Draw_s_axis=new s,$.Draw_s_c1=new O(.7,.7,.7),$.Draw_s_c2=new O(.3,.9,.3),$.Draw_s_c3=new O(.9,.3,.3),$.Draw_s_c4=new O(.3,.3,.9),$.Draw_s_c5=new O(.4,.4,.4),$.Draw_s_lower=new s,$.Draw_s_upper=new s,$.Draw_s_perp=new s;class tt{constructor(t){this.m_contactManager=new Xe,this.m_bodyList=null,this.m_jointList=null,this.m_bodyCount=0,this.m_jointCount=0,this.m_gravity=new s,this.m_allowSleep=!0,this.m_destructionListener=null,this.m_debugDraw=null,this.m_inv_dt0=0,this.m_newContacts=!1,this.m_locked=!1,this.m_clearForces=!0,this.m_warmStarting=!0,this.m_continuousPhysics=!0,this.m_subStepping=!1,this.m_stepComplete=!0,this.m_profile=new _e,this.m_island=new At,this.s_stack=[],this.m_gravity.Copy(t)}SetDestructionListener(t){this.m_destructionListener=t}SetContactFilter(t){this.m_contactManager.m_contactFilter=t}SetContactListener(t){this.m_contactManager.m_contactListener=t}SetDebugDraw(t){this.m_debugDraw=t}CreateBody(t={}){if(this.IsLocked())throw new Error;const e=new It(t,this);return e.m_prev=null,e.m_next=this.m_bodyList,this.m_bodyList&&(this.m_bodyList.m_prev=e),this.m_bodyList=e,++this.m_bodyCount,e}DestroyBody(t){if(this.IsLocked())throw new Error;let e=t.m_jointList;for(;e;){const o=e;e=e.next,this.m_destructionListener&&this.m_destructionListener.SayGoodbyeJoint(o.joint),this.DestroyJoint(o.joint),t.m_jointList=e}t.m_jointList=null;let i=t.m_contactList;for(;i;){const o=i;i=i.next,this.m_contactManager.Destroy(o.contact)}t.m_contactList=null;let n=t.m_fixtureList;for(;n;){const o=n;n=n.m_next,this.m_destructionListener&&this.m_destructionListener.SayGoodbyeFixture(o),o.DestroyProxies(),o.Reset(),t.m_fixtureList=n,t.m_fixtureCount-=1}t.m_fixtureList=null,t.m_fixtureCount=0,t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),t===this.m_bodyList&&(this.m_bodyList=t.m_next),--this.m_bodyCount}static _Joint_Create(t){switch(t.type){case _.b2JointType.e_distanceJoint:return new W(t);case _.b2JointType.e_mouseJoint:return new is(t);case _.b2JointType.e_prismaticJoint:return new N(t);case _.b2JointType.e_revoluteJoint:return new st(t);case _.b2JointType.e_pulleyJoint:return new _t(t);case _.b2JointType.e_gearJoint:return new ht(t);case _.b2JointType.e_wheelJoint:return new $(t);case _.b2JointType.e_weldJoint:return new ct(t);case _.b2JointType.e_frictionJoint:return new ss(t);case _.b2JointType.e_motorJoint:return new es(t);case _.b2JointType.e_areaJoint:return new Re(t)}throw new Error}static _Joint_Destroy(t){}CreateJoint(t){if(this.IsLocked())throw new Error;const e=tt._Joint_Create(t);e.m_prev=null,e.m_next=this.m_jointList,this.m_jointList&&(this.m_jointList.m_prev=e),this.m_jointList=e,++this.m_jointCount,e.m_edgeA.prev=null,e.m_edgeA.next=e.m_bodyA.m_jointList,e.m_bodyA.m_jointList&&(e.m_bodyA.m_jointList.prev=e.m_edgeA),e.m_bodyA.m_jointList=e.m_edgeA,e.m_edgeB.prev=null,e.m_edgeB.next=e.m_bodyB.m_jointList,e.m_bodyB.m_jointList&&(e.m_bodyB.m_jointList.prev=e.m_edgeB),e.m_bodyB.m_jointList=e.m_edgeB;const i=e.m_bodyA,n=e.m_bodyB;if(!e.m_collideConnected){let r=n.GetContactList();for(;r;)r.other===i&&r.contact.FlagForFiltering(),r=r.next}return e}DestroyJoint(t){if(this.IsLocked())throw new Error;t.m_prev&&(t.m_prev.m_next=t.m_next),t.m_next&&(t.m_next.m_prev=t.m_prev),t===this.m_jointList&&(this.m_jointList=t.m_next);const e=t.m_bodyA,i=t.m_bodyB,n=t.m_collideConnected;if(e.SetAwake(!0),i.SetAwake(!0),t.m_edgeA.prev&&(t.m_edgeA.prev.next=t.m_edgeA.next),t.m_edgeA.next&&(t.m_edgeA.next.prev=t.m_edgeA.prev),t.m_edgeA===e.m_jointList&&(e.m_jointList=t.m_edgeA.next),t.m_edgeA.Reset(),t.m_edgeB.prev&&(t.m_edgeB.prev.next=t.m_edgeB.next),t.m_edgeB.next&&(t.m_edgeB.next.prev=t.m_edgeB.prev),t.m_edgeB===i.m_jointList&&(i.m_jointList=t.m_edgeB.next),t.m_edgeB.Reset(),tt._Joint_Destroy(t),--this.m_jointCount,!n){let o=i.GetContactList();for(;o;)o.other===e&&o.contact.FlagForFiltering(),o=o.next}}Step(t,e,i){const n=tt.Step_s_stepTimer.Reset();this.m_newContacts&&(this.m_contactManager.FindNewContacts(),this.m_newContacts=!1),this.m_locked=!0;const o=tt.Step_s_step;o.dt=t,o.velocityIterations=e,o.positionIterations=i,t>0?o.inv_dt=1/t:o.inv_dt=0,o.dtRatio=this.m_inv_dt0*t,o.warmStarting=this.m_warmStarting;const r=tt.Step_s_timer.Reset();if(this.m_contactManager.Collide(),this.m_profile.collide=r.GetMilliseconds(),this.m_stepComplete&&o.dt>0){const h=tt.Step_s_timer.Reset();this.Solve(o),this.m_profile.solve=h.GetMilliseconds()}if(this.m_continuousPhysics&&o.dt>0){const h=tt.Step_s_timer.Reset();this.SolveTOI(o),this.m_profile.solveTOI=h.GetMilliseconds()}o.dt>0&&(this.m_inv_dt0=o.inv_dt),this.m_clearForces&&this.ClearForces(),this.m_locked=!1,this.m_profile.step=n.GetMilliseconds()}ClearForces(){for(let t=this.m_bodyList;t;t=t.m_next)t.m_force.SetZero(),t.m_torque=0}DebugDraw(){if(this.m_debugDraw===null)return;const t=this.m_debugDraw.GetFlags(),e=tt.DebugDraw_s_color.SetRGB(0,0,0);if(t&_.b2DrawFlags.e_shapeBit)for(let i=this.m_bodyList;i;i=i.m_next){const n=i.m_xf;this.m_debugDraw.PushTransform(n);for(let o=i.GetFixtureList();o;o=o.m_next)i.GetType()===_.b2BodyType.b2_dynamicBody&&i.m_mass===0?this.DrawShape(o,new O(1,0,0)):i.IsEnabled()?i.GetType()===_.b2BodyType.b2_staticBody?(e.SetRGB(.5,.9,.5),this.DrawShape(o,e)):i.GetType()===_.b2BodyType.b2_kinematicBody?(e.SetRGB(.5,.5,.9),this.DrawShape(o,e)):i.IsAwake()?(e.SetRGB(.9,.7,.7),this.DrawShape(o,e)):(e.SetRGB(.6,.6,.6),this.DrawShape(o,e)):(e.SetRGB(.5,.5,.3),this.DrawShape(o,e));this.m_debugDraw.PopTransform(n)}if(t&_.b2DrawFlags.e_jointBit)for(let i=this.m_jointList;i;i=i.m_next)i.Draw(this.m_debugDraw);if(t&_.b2DrawFlags.e_pairBit){e.SetRGB(.3,.9,.9);for(let i=this.m_contactManager.m_contactList;i;i=i.m_next){const n=i.GetFixtureA(),o=i.GetFixtureB(),r=i.GetChildIndexA(),h=i.GetChildIndexB(),l=n.GetAABB(r).GetCenter(),y=o.GetAABB(h).GetCenter();this.m_debugDraw.DrawSegment(l,y,e)}}if(t&_.b2DrawFlags.e_aabbBit){e.SetRGB(.9,.3,.9);const i=tt.DebugDraw_s_vs;for(let n=this.m_bodyList;n;n=n.m_next)if(n.IsEnabled())for(let o=n.GetFixtureList();o;o=o.m_next)for(let r=0;r{const r=n.userData.fixture;return t?t.ReportFixture(r):i?i(r):!0})}QueryAllAABB(t,e=[]){return this.QueryAABB(t,i=>(e.push(i),!0)),e}QueryPointAABB(...t){t[0]instanceof Ms?this._QueryPointAABB(t[0],t[1]):this._QueryPointAABB(null,t[0],t[1])}_QueryPointAABB(t,e,i){this.m_contactManager.m_broadPhase.QueryPoint(e,n=>{const r=n.userData.fixture;return t?t.ReportFixture(r):i?i(r):!0})}QueryAllPointAABB(t,e=[]){return this.QueryPointAABB(t,i=>(e.push(i),!0)),e}QueryFixtureShape(...t){t[0]instanceof Ms?this._QueryFixtureShape(t[0],t[1],t[2],t[3]):this._QueryFixtureShape(null,t[0],t[1],t[2],t[3])}_QueryFixtureShape(t,e,i,n,o){const r=tt.QueryFixtureShape_s_aabb;e.ComputeAABB(r,n,i),this.m_contactManager.m_broadPhase.Query(r,h=>{const l=h.userData,y=l.fixture;if(Ws(e,i,y.GetShape(),l.childIndex,n,y.GetBody().GetTransform())){if(t)return t.ReportFixture(y);if(o)return o(y)}return!0})}QueryAllFixtureShape(t,e,i,n=[]){return this.QueryFixtureShape(t,e,i,o=>(n.push(o),!0)),n}QueryFixturePoint(...t){t[0]instanceof Ms?this._QueryFixturePoint(t[0],t[1]):this._QueryFixturePoint(null,t[0],t[1])}_QueryFixturePoint(t,e,i){this.m_contactManager.m_broadPhase.QueryPoint(e,n=>{const r=n.userData.fixture;if(r.TestPoint(e)){if(t)return t.ReportFixture(r);if(i)return i(r)}return!0})}QueryAllFixturePoint(t,e=[]){return this.QueryFixturePoint(t,i=>(e.push(i),!0)),e}RayCast(...t){t[0]instanceof Oe?this._RayCast(t[0],t[1],t[2]):this._RayCast(null,t[0],t[1],t[2])}_RayCast(t,e,i,n){const o=tt.RayCast_s_input;o.maxFraction=1,o.p1.Copy(e),o.p2.Copy(i),this.m_contactManager.m_broadPhase.RayCast(o,(r,h)=>{const l=h.userData,y=l.fixture,c=l.childIndex,m=tt.RayCast_s_output;if(y.RayCast(m,r,c)){const u=m.fraction,f=tt.RayCast_s_point;if(f.Set((1-u)*e.x+u*i.x,(1-u)*e.y+u*i.y),t)return t.ReportFixture(y,f,m.normal,u);if(n)return n(y,f,m.normal,u)}return r.maxFraction})}RayCastOne(t,e){let i=null,n=1;return this.RayCast(t,e,(o,r,h,l)=>(l(i.push(n),1)),i}GetBodyList(){return this.m_bodyList}GetJointList(){return this.m_jointList}GetContactList(){return this.m_contactManager.m_contactList}SetAllowSleeping(t){if(t!==this.m_allowSleep&&(this.m_allowSleep=t,!this.m_allowSleep))for(let e=this.m_bodyList;e;e=e.m_next)e.SetAwake(!0)}GetAllowSleeping(){return this.m_allowSleep}SetWarmStarting(t){this.m_warmStarting=t}GetWarmStarting(){return this.m_warmStarting}SetContinuousPhysics(t){this.m_continuousPhysics=t}GetContinuousPhysics(){return this.m_continuousPhysics}SetSubStepping(t){this.m_subStepping=t}GetSubStepping(){return this.m_subStepping}GetProxyCount(){return this.m_contactManager.m_broadPhase.GetProxyCount()}GetBodyCount(){return this.m_bodyCount}GetJointCount(){return this.m_jointCount}GetContactCount(){return this.m_contactManager.m_contactCount}GetTreeHeight(){return this.m_contactManager.m_broadPhase.GetTreeHeight()}GetTreeBalance(){return this.m_contactManager.m_broadPhase.GetTreeBalance()}GetTreeQuality(){return this.m_contactManager.m_broadPhase.GetTreeQuality()}SetGravity(t,e=!0){if(!s.IsEqualToV(this.m_gravity,t)&&(this.m_gravity.Copy(t),e))for(let i=this.m_bodyList;i;i=i.m_next)i.SetAwake(!0)}GetGravity(){return this.m_gravity}IsLocked(){return this.m_locked}SetAutoClearForces(t){this.m_clearForces=t}GetAutoClearForces(){return this.m_clearForces}ShiftOrigin(t){if(this.IsLocked())throw new Error;for(let e=this.m_bodyList;e;e=e.m_next)e.m_xf.p.SelfSub(t),e.m_sweep.c0.SelfSub(t),e.m_sweep.c.SelfSub(t);for(let e=this.m_jointList;e;e=e.m_next)e.ShiftOrigin(t);this.m_contactManager.m_broadPhase.ShiftOrigin(t)}GetContactManager(){return this.m_contactManager}GetProfile(){return this.m_profile}Dump(t){if(this.m_locked)return;t(`const g: b2Vec2 = new b2Vec2(%.15f, %.15f); `,this.m_gravity.x,this.m_gravity.y),t(`this.m_world.SetGravity(g); `),t(`const bodies: b2Body[] = []; `),t(`const joints: b2Joint[] = []; `);let e=0;for(let i=this.m_bodyList;i;i=i.m_next)i.m_islandIndex=e,i.Dump(t),++e;e=0;for(let i=this.m_jointList;i;i=i.m_next)i.m_index=e,++e;for(let i=this.m_jointList;i;i=i.m_next)i.m_type!==_.b2JointType.e_gearJoint&&(t(`{ `),i.Dump(t),t(`} `));for(let i=this.m_jointList;i;i=i.m_next)i.m_type===_.b2JointType.e_gearJoint&&(t(`{ `),i.Dump(t),t(`} `))}DrawShape(t,e){if(this.m_debugDraw===null)return;const i=t.GetShape();switch(i.m_type){case _.b2ShapeType.e_circleShape:{const n=i,o=n.m_p,r=n.m_radius,h=s.UNITX;this.m_debugDraw.DrawSolidCircle(o,r,h,e);break}case _.b2ShapeType.e_edgeShape:{const n=i,o=n.m_vertex1,r=n.m_vertex2;this.m_debugDraw.DrawSegment(o,r,e),n.m_oneSided===!1&&(this.m_debugDraw.DrawPoint(o,4,e),this.m_debugDraw.DrawPoint(r,4,e));break}case _.b2ShapeType.e_chainShape:{const n=i,o=n.m_count,r=n.m_vertices;let h=r[0];for(let l=1;l0;){const l=i[--r];if(!l)throw new Error;if(e.AddBody(l),l.GetType()!==_.b2BodyType.b2_staticBody){l.m_awakeFlag=!0;for(let y=l.m_contactList;y;y=y.next){const c=y.contact;if(c.m_islandFlag||!c.IsEnabled()||!c.IsTouching())continue;const m=c.m_fixtureA.m_isSensor,a=c.m_fixtureB.m_isSensor;if(m||a)continue;e.AddContact(c),c.m_islandFlag=!0;const u=y.other;u.m_islandFlag||(i[r++]=u,u.m_islandFlag=!0)}for(let y=l.m_jointList;y;y=y.next){if(y.joint.m_islandFlag)continue;const c=y.other;c.IsEnabled()&&(e.AddJoint(y.joint),y.joint.m_islandFlag=!0,!c.m_islandFlag&&(i[r++]=c,c.m_islandFlag=!0))}}}const h=new _e;e.Solve(h,t,this.m_gravity,this.m_allowSleep),this.m_profile.solveInit+=h.solveInit,this.m_profile.solveVelocity+=h.solveVelocity,this.m_profile.solvePosition+=h.solvePosition;for(let l=0;lQt)continue;let u=1;if(a.m_toiFlag)u=a.m_toi;else{const f=a.GetFixtureA(),A=a.GetFixtureB();if(f.IsSensor()||A.IsSensor())continue;const S=f.GetBody(),b=A.GetBody(),B=S.m_type,x=b.m_type,v=S.IsAwake()&&B!==_.b2BodyType.b2_staticBody,V=b.IsAwake()&&x!==_.b2BodyType.b2_staticBody;if(!v&&!V)continue;const k=S.IsBullet()||B!==_.b2BodyType.b2_dynamicBody,P=b.IsBullet()||x!==_.b2BodyType.b2_dynamicBody;if(!k&&!P)continue;let q=S.m_sweep.alpha0;S.m_sweep.alpha0new s),e(this.m_ps,this.m_count,()=>new s),e(this.m_p0s,this.m_count,()=>new s),e(this.m_vs,this.m_count,()=>new s),e(this.m_invMasses,this.m_count,()=>0);for(let i=0;i0?this.m_invMasses[i]=1/n:this.m_invMasses[i]=0}this.m_stretchCount=this.m_count-1,this.m_bendCount=this.m_count-2,e(this.m_stretchConstraints,this.m_stretchCount,()=>new ho),e(this.m_bendConstraints,this.m_bendCount,()=>new lo);for(let i=0;i0?(this.m_vs[r].x*=o,this.m_vs[r].y*=o,this.m_vs[r].x+=t*this.m_gravity.x,this.m_vs[r].y+=t*this.m_gravity.y):(this.m_vs[r].x=n*(this.m_bindPositions[r].x+i.x-this.m_p0s[r].x),this.m_vs[r].y=n*(this.m_bindPositions[r].y+i.y-this.m_p0s[r].y));this.m_tuning.bendingModel===_.b2BendingModel.b2_springAngleBendingModel&&this.ApplyBendForces(t);for(let r=0;r0?n:i;t.DrawPoint(this.m_ps[r],5,h)}const o=this.m_invMasses[this.m_count-1]>0?n:i;t.DrawPoint(this.m_ps[this.m_count-1],5,o)}SolveStretch_PBD(){const t=this.m_tuning.stretchStiffness;for(let e=0;e.033&&(p=.033),this.world.Step(p,this.velocityIterations,this.positionIterations,3);var w=this._eventList.length;if(w>0){for(var g=0;g=0&&(w.maxLength=this._maxLength/M.PIXEL_RATIO),this._minLength>=0&&(w.minLength=this._minLength/M.PIXEL_RATIO),this._joint=M.I._createJoint(w)}}get length(){return this._length}set length(p){this._length=p,this._joint&&this._joint.SetLength(p/M.PIXEL_RATIO)}get minLength(){return this._minLength}set minLength(p){this._minLength=p,this._joint&&this._joint.SetMinLength(p/M.PIXEL_RATIO)}get maxLength(){return this._maxLength}set maxLength(p){this._maxLength=p,this._joint&&this._joint.SetMaxLength(p/M.PIXEL_RATIO)}get frequency(){return this._frequency}set frequency(p){if(this._frequency=p,this._joint){let w={},g=window.box2d,L=this.otherBody?this.otherBody.getBody():M.I._emptyBody,F=this.selfBody.getBody();g.b2LinearStiffness(w,this._frequency,this._dampingRatio,L,F),this._joint.SetStiffness(w.stiffness),this._joint.SetDamping(w.damping)}}get damping(){return this._dampingRatio}set damping(p){if(this._dampingRatio=p,this._joint){let w={},g=window.box2d,L=this.otherBody?this.otherBody.getBody():M.I._emptyBody,F=this.selfBody.getBody();g.b2LinearStiffness(w,this._frequency,this._dampingRatio,L,F),this._joint.SetDamping(w.damping)}}}D.ClassUtils.regClass("laya.physics.joint.DistanceJoint",Q),D.ClassUtils.regClass("Laya.DistanceJoint",Q);class Dt extends xt{constructor(){super(...arguments),this.collideConnected=!1,this._ratio=1}_createJoint(){if(!this._joint){if(!this.joint1)throw"Joint1 can not be empty";if(!this.joint2)throw"Joint2 can not be empty";var p=window.box2d,w=Dt._temp||(Dt._temp=new p.b2GearJointDef);w.bodyA=this.joint1.owner.getComponent(nt).getBody(),w.bodyB=this.joint2.owner.getComponent(nt).getBody(),w.joint1=this.joint1.joint,w.joint2=this.joint2.joint,w.ratio=this._ratio,w.collideConnected=this.collideConnected,this._joint=M.I._createJoint(w)}}get ratio(){return this._ratio}set ratio(p){this._ratio=p,this._joint&&this._joint.SetRatio(p)}}D.ClassUtils.regClass("laya.physics.joint.GearJoint",Dt),D.ClassUtils.regClass("Laya.GearJoint",Dt);class Ct extends xt{constructor(){super(...arguments),this.collideConnected=!1,this._linearOffset=[0,0],this._angularOffset=0,this._maxForce=1e3,this._maxTorque=1e3,this._correctionFactor=.3}_createJoint(){if(!this._joint){if(!this.otherBody)throw"otherBody can not be empty";if(this.selfBody=this.selfBody||this.owner.getComponent(nt),!this.selfBody)throw"selfBody can not be empty";var p=window.box2d,w=Ct._temp||(Ct._temp=new p.b2MotorJointDef);w.Initialize(this.otherBody.getBody(),this.selfBody.getBody()),w.linearOffset=new p.b2Vec2(this._linearOffset[0]/M.PIXEL_RATIO,this._linearOffset[1]/M.PIXEL_RATIO),w.angularOffset=this._angularOffset,w.maxForce=this._maxForce,w.maxTorque=this._maxTorque,w.correctionFactor=this._correctionFactor,w.collideConnected=this.collideConnected,this._joint=M.I._createJoint(w)}}get linearOffset(){return this._linearOffset}set linearOffset(p){this._linearOffset=p,this._joint&&this._joint.SetLinearOffset(new window.box2d.b2Vec2(p[0]/M.PIXEL_RATIO,p[1]/M.PIXEL_RATIO))}get angularOffset(){return this._angularOffset}set angularOffset(p){this._angularOffset=p,this._joint&&this._joint.SetAngularOffset(p)}get maxForce(){return this._maxForce}set maxForce(p){this._maxForce=p,this._joint&&this._joint.SetMaxForce(p)}get maxTorque(){return this._maxTorque}set maxTorque(p){this._maxTorque=p,this._joint&&this._joint.SetMaxTorque(p)}get correctionFactor(){return this._correctionFactor}set correctionFactor(p){this._correctionFactor=p,this._joint&&this._joint.SetCorrectionFactor(p)}}D.ClassUtils.regClass("laya.physics.joint.MotorJoint",Ct),D.ClassUtils.regClass("Laya.MotorJoint",Ct);class Qt extends xt{constructor(){super(...arguments),this._maxForce=1e4,this._frequency=5,this._dampingRatio=.7}_onEnable(){this.owner.on(D.Event.MOUSE_DOWN,this,this.onMouseDown)}_onAwake(){}onMouseDown(){this._createJoint(),D.Laya.stage.on(D.Event.MOUSE_MOVE,this,this.onMouseMove),D.Laya.stage.once(D.Event.MOUSE_UP,this,this.onStageMouseUp),D.Laya.stage.once(D.Event.MOUSE_OUT,this,this.onStageMouseUp)}_createJoint(){if(!this._joint){if(this.selfBody=this.selfBody||this.owner.getComponent(nt),!this.selfBody)throw"selfBody can not be empty";var p=window.box2d,w=Qt._temp||(Qt._temp=new p.b2MouseJointDef);if(this.anchor)var g=this.selfBody.owner.localToGlobal(D.Point.TEMP.setTo(this.anchor[0],this.anchor[1]),!1,M.I.worldRoot);else g=M.I.worldRoot.globalToLocal(D.Point.TEMP.setTo(D.Laya.stage.mouseX,D.Laya.stage.mouseY));var L=new p.b2Vec2(g.x/M.PIXEL_RATIO,g.y/M.PIXEL_RATIO);w.bodyA=M.I._emptyBody,w.bodyB=this.selfBody.getBody(),w.target=L,p.b2LinearStiffness(w,this._frequency,this._dampingRatio,w.bodyA,w.bodyB),w.maxForce=this._maxForce,this._joint=M.I._createJoint(w)}}onStageMouseUp(){D.Laya.stage.off(D.Event.MOUSE_MOVE,this,this.onMouseMove),D.Laya.stage.off(D.Event.MOUSE_UP,this,this.onStageMouseUp),D.Laya.stage.off(D.Event.MOUSE_OUT,this,this.onStageMouseUp),super._onDisable()}onMouseMove(){this._joint.SetTarget(new window.box2d.b2Vec2(M.I.worldRoot.mouseX/M.PIXEL_RATIO,M.I.worldRoot.mouseY/M.PIXEL_RATIO))}_onDisable(){this.owner.off(D.Event.MOUSE_DOWN,this,this.onMouseDown),super._onDisable()}get maxForce(){return this._maxForce}set maxForce(p){this._maxForce=p,this._joint&&this._joint.SetMaxForce(p)}get frequency(){return this._frequency}set frequency(p){if(this._frequency=p,this._joint){let w={},g=window.box2d,L=M.I._emptyBody,F=this.selfBody.getBody();g.b2LinearStiffness(w,this._frequency,this._dampingRatio,L,F),this._joint.SetStiffness(w.stiffness),this._joint.SetDamping(w.damping)}}get damping(){return this._dampingRatio}set damping(p){if(this._dampingRatio=p,this._joint){let w={},g=window.box2d,L=M.I._emptyBody,F=this.selfBody.getBody();g.b2LinearStiffness(w,this._frequency,this._dampingRatio,L,F),this._joint.SetDamping(w.damping)}}}D.ClassUtils.regClass("laya.physics.joint.MouseJoint",Qt),D.ClassUtils.regClass("Laya.MouseJoint",Qt);class Nt extends xt{constructor(){super(...arguments),this.anchor=[0,0],this.axis=[1,0],this.collideConnected=!1,this._enableMotor=!1,this._motorSpeed=0,this._maxMotorForce=1e4,this._enableLimit=!1,this._lowerTranslation=0,this._upperTranslation=0}_createJoint(){if(!this._joint){if(this.selfBody=this.selfBody||this.owner.getComponent(nt),!this.selfBody)throw"selfBody can not be empty";var p=window.box2d,w=Nt._temp||(Nt._temp=new p.b2PrismaticJointDef),g=this.selfBody.owner.localToGlobal(D.Point.TEMP.setTo(this.anchor[0],this.anchor[1]),!1,M.I.worldRoot),L=new p.b2Vec2(g.x/M.PIXEL_RATIO,g.y/M.PIXEL_RATIO);w.Initialize(this.otherBody?this.otherBody.getBody():M.I._emptyBody,this.selfBody.getBody(),L,new p.b2Vec2(this.axis[0],this.axis[1])),w.enableMotor=this._enableMotor,w.motorSpeed=this._motorSpeed,w.maxMotorForce=this._maxMotorForce,w.enableLimit=this._enableLimit,w.lowerTranslation=this._lowerTranslation/M.PIXEL_RATIO,w.upperTranslation=this._upperTranslation/M.PIXEL_RATIO,w.collideConnected=this.collideConnected,this._joint=M.I._createJoint(w)}}get enableMotor(){return this._enableMotor}set enableMotor(p){this._enableMotor=p,this._joint&&this._joint.EnableMotor(p)}get motorSpeed(){return this._motorSpeed}set motorSpeed(p){this._motorSpeed=p,this._joint&&this._joint.SetMotorSpeed(p)}get maxMotorForce(){return this._maxMotorForce}set maxMotorForce(p){this._maxMotorForce=p,this._joint&&this._joint.SetMaxMotorForce(p)}get enableLimit(){return this._enableLimit}set enableLimit(p){this._enableLimit=p,this._joint&&this._joint.EnableLimit(p)}get lowerTranslation(){return this._lowerTranslation}set lowerTranslation(p){this._lowerTranslation=p,this._joint&&this._joint.SetLimits(p,this._upperTranslation)}get upperTranslation(){return this._upperTranslation}set upperTranslation(p){this._upperTranslation=p,this._joint&&this._joint.SetLimits(this._lowerTranslation,p)}}D.ClassUtils.regClass("laya.physics.joint.PrismaticJoint",Nt),D.ClassUtils.regClass("Laya.PrismaticJoint",Nt);class kt extends xt{constructor(){super(...arguments),this.selfAnchor=[0,0],this.otherAnchor=[0,0],this.selfGroundPoint=[0,0],this.otherGroundPoint=[0,0],this.ratio=1.5,this.collideConnected=!1}_createJoint(){if(!this._joint){if(!this.otherBody)throw"otherBody can not be empty";if(this.selfBody=this.selfBody||this.owner.getComponent(nt),!this.selfBody)throw"selfBody can not be empty";var p=window.box2d,w=kt._temp||(kt._temp=new p.b2PulleyJointDef),g=this.otherBody.owner.localToGlobal(D.Point.TEMP.setTo(this.otherAnchor[0],this.otherAnchor[1]),!1,M.I.worldRoot),L=new p.b2Vec2(g.x/M.PIXEL_RATIO,g.y/M.PIXEL_RATIO),F=this.selfBody.owner.localToGlobal(D.Point.TEMP.setTo(this.selfAnchor[0],this.selfAnchor[1]),!1,M.I.worldRoot),K=new p.b2Vec2(F.x/M.PIXEL_RATIO,F.y/M.PIXEL_RATIO),wt=this.otherBody.owner.localToGlobal(D.Point.TEMP.setTo(this.otherGroundPoint[0],this.otherGroundPoint[1]),!1,M.I.worldRoot),Bt=new p.b2Vec2(wt.x/M.PIXEL_RATIO,wt.y/M.PIXEL_RATIO),hs=this.selfBody.owner.localToGlobal(D.Point.TEMP.setTo(this.selfGroundPoint[0],this.selfGroundPoint[1]),!1,M.I.worldRoot),Js=new p.b2Vec2(hs.x/M.PIXEL_RATIO,hs.y/M.PIXEL_RATIO);w.Initialize(this.otherBody.getBody(),this.selfBody.getBody(),Bt,Js,L,K,this.ratio),w.collideConnected=this.collideConnected,this._joint=M.I._createJoint(w)}}}D.ClassUtils.regClass("laya.physics.joint.PulleyJoint",kt),D.ClassUtils.regClass("Laya.PulleyJoint",kt);class qt extends xt{constructor(){super(...arguments),this.anchor=[0,0],this.collideConnected=!1,this._enableMotor=!1,this._motorSpeed=0,this._maxMotorTorque=1e4,this._enableLimit=!1,this._lowerAngle=0,this._upperAngle=0}_createJoint(){if(!this._joint){if(this.selfBody=this.selfBody||this.owner.getComponent(nt),!this.selfBody)throw"selfBody can not be empty";var p=window.box2d,w=qt._temp||(qt._temp=new p.b2RevoluteJointDef),g=this.selfBody.owner.localToGlobal(D.Point.TEMP.setTo(this.anchor[0],this.anchor[1]),!1,M.I.worldRoot),L=new p.b2Vec2(g.x/M.PIXEL_RATIO,g.y/M.PIXEL_RATIO);w.Initialize(this.otherBody?this.otherBody.getBody():M.I._emptyBody,this.selfBody.getBody(),L),w.enableMotor=this._enableMotor,w.motorSpeed=this._motorSpeed,w.maxMotorTorque=this._maxMotorTorque,w.enableLimit=this._enableLimit,w.lowerAngle=this._lowerAngle,w.upperAngle=this._upperAngle,w.collideConnected=this.collideConnected,this._joint=M.I._createJoint(w)}}get enableMotor(){return this._enableMotor}set enableMotor(p){this._enableMotor=p,this._joint&&this._joint.EnableMotor(p)}get motorSpeed(){return this._motorSpeed}set motorSpeed(p){this._motorSpeed=p,this._joint&&this._joint.SetMotorSpeed(p)}get maxMotorTorque(){return this._maxMotorTorque}set maxMotorTorque(p){this._maxMotorTorque=p,this._joint&&this._joint.SetMaxMotorTorque(p)}get enableLimit(){return this._enableLimit}set enableLimit(p){this._enableLimit=p,this._joint&&this._joint.EnableLimit(p)}get lowerAngle(){return this._lowerAngle}set lowerAngle(p){this._lowerAngle=p,this._joint&&this._joint.SetLimits(p,this._upperAngle)}get upperAngle(){return this._upperAngle}set upperAngle(p){this._upperAngle=p,this._joint&&this._joint.SetLimits(this._lowerAngle,p)}}D.ClassUtils.regClass("laya.physics.joint.RevoluteJoint",qt),D.ClassUtils.regClass("Laya.RevoluteJoint",qt);class jt extends xt{constructor(){super(...arguments),this.anchor=[0,0],this.collideConnected=!1,this._frequency=5,this._dampingRatio=.7}_createJoint(){if(!this._joint){if(!this.otherBody)throw"otherBody can not be empty";if(this.selfBody=this.selfBody||this.owner.getComponent(nt),!this.selfBody)throw"selfBody can not be empty";var p=window.box2d,w=jt._temp||(jt._temp=new p.b2WeldJointDef),g=this.selfBody.owner.localToGlobal(D.Point.TEMP.setTo(this.anchor[0],this.anchor[1]),!1,M.I.worldRoot),L=new p.b2Vec2(g.x/M.PIXEL_RATIO,g.y/M.PIXEL_RATIO);w.Initialize(this.otherBody.getBody(),this.selfBody.getBody(),L),p.b2AngularStiffness(w,this._frequency,this._dampingRatio,w.bodyA,w.bodyB),w.collideConnected=this.collideConnected,this._joint=M.I._createJoint(w)}}get frequency(){return this._frequency}set frequency(p){if(this._frequency=p,this._joint){let w={},g=window.box2d,L=this.otherBody?this.otherBody.getBody():M.I._emptyBody,F=this.selfBody.getBody();g.b2AngularStiffness(w,this._frequency,this._dampingRatio,L,F),this._joint.SetStiffness(w.stiffness),this._joint.SetDamping(w.damping)}}get damping(){return this._dampingRatio}set damping(p){if(this._dampingRatio=p,this._joint){let w={},g=window.box2d,L=this.otherBody?this.otherBody.getBody():M.I._emptyBody,F=this.selfBody.getBody();g.b2AngularStiffness(w,this._frequency,this._dampingRatio,L,F),this._joint.SetDamping(w.damping)}}}D.ClassUtils.regClass("laya.physics.joint.WeldJoint",jt),D.ClassUtils.regClass("Laya.WeldJoint",jt);class Zt extends xt{constructor(){super(...arguments),this.anchor=[0,0],this.collideConnected=!1,this.axis=[1,0],this._frequency=5,this._dampingRatio=.7,this._enableMotor=!1,this._motorSpeed=0,this._maxMotorTorque=1e4,this._enableLimit=!0,this._lowerTranslation=0,this._upperTranslation=0}_createJoint(){if(!this._joint){if(!this.otherBody)throw"otherBody can not be empty";if(this.selfBody=this.selfBody||this.owner.getComponent(nt),!this.selfBody)throw"selfBody can not be empty";var p=window.box2d,w=Zt._temp||(Zt._temp=new p.b2WheelJointDef),g=this.selfBody.owner.localToGlobal(D.Point.TEMP.setTo(this.anchor[0],this.anchor[1]),!1,M.I.worldRoot),L=new p.b2Vec2(g.x/M.PIXEL_RATIO,g.y/M.PIXEL_RATIO);w.Initialize(this.otherBody.getBody(),this.selfBody.getBody(),L,new p.b2Vec2(this.axis[0],this.axis[1])),w.enableMotor=this._enableMotor,w.motorSpeed=this._motorSpeed,w.maxMotorTorque=this._maxMotorTorque,p.b2LinearStiffness(w,this._frequency,this._dampingRatio,w.bodyA,w.bodyB),w.collideConnected=this.collideConnected,w.enableLimit=this._enableLimit,w.lowerTranslation=this._lowerTranslation/M.PIXEL_RATIO,w.upperTranslation=this._upperTranslation/M.PIXEL_RATIO,this._joint=M.I._createJoint(w)}}get frequency(){return this._frequency}set frequency(p){if(this._frequency=p,this._joint){let w={},g=window.box2d,L=this.otherBody?this.otherBody.getBody():M.I._emptyBody,F=this.selfBody.getBody();g.b2LinearStiffness(w,this._frequency,this._dampingRatio,L,F),this._joint.SetStiffness(w.stiffness),this._joint.SetDamping(w.damping)}}get damping(){return this._dampingRatio}set damping(p){if(this._dampingRatio=p,this._joint){let w={},g=window.box2d,L=this.otherBody?this.otherBody.getBody():M.I._emptyBody,F=this.selfBody.getBody();g.b2LinearStiffness(w,this._frequency,this._dampingRatio,L,F),this._joint.SetDamping(w.damping)}}get enableMotor(){return this._enableMotor}set enableMotor(p){this._enableMotor=p,this._joint&&this._joint.EnableMotor(p)}get motorSpeed(){return this._motorSpeed}set motorSpeed(p){this._motorSpeed=p,this._joint&&this._joint.SetMotorSpeed(p)}get maxMotorTorque(){return this._maxMotorTorque}set maxMotorTorque(p){this._maxMotorTorque=p,this._joint&&this._joint.SetMaxMotorTorque(p)}get enableLimit(){return this._enableLimit}set enableLimit(p){this._enableLimit=p,this._joint&&this._joint.EnableLimit(p)}get lowerTranslation(){return this._lowerTranslation}set lowerTranslation(p){this._lowerTranslation=p,this._joint&&this._joint.SetLimits(p,this._upperTranslation)}get upperTranslation(){return this._upperTranslation}set upperTranslation(p){this._upperTranslation=p,this._joint&&this._joint.SetLimits(this._lowerTranslation,p)}}D.ClassUtils.regClass("laya.physics.joint.WheelJoint",Zt),D.ClassUtils.regClass("Laya.WheelJoint",Zt),_.BoxCollider=rs,_.ChainCollider=ut,_.CircleCollider=Ft,_.ColliderBase=zt,_.DestructionListener=T,_.DistanceJoint=Q,_.EdgeCollider=us,_.GearJoint=Dt,_.IPhysics=O,_.JointBase=xt,_.MotorJoint=Ct,_.MouseJoint=Qt,_.Physics=M,_.PhysicsDebugDraw=H,_.PolygonCollider=Kt,_.PrismaticJoint=Nt,_.PulleyJoint=kt,_.RevoluteJoint=qt,_.RigidBody=nt,_.WeldJoint=jt,_.WheelJoint=Zt})(window.Laya=window.Laya||{},Laya);