UNPKG

the-world-engine

Version:

three.js based, unity like game engine for browser

1 lines 369 kB
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define("B2D",["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).B2D={})}(this,(function(t){"use strict";class b2Color{constructor(t=.5,s=.5,i=.5,e=1){this.r=t,this.g=s,this.b=i,this.a=e}Clone(){return(new b2Color).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 0===this.r&&0===this.g&&0===this.b&&0===this.a}Set(t,s,i,e=this.a){this.SetRGBA(t,s,i,e)}SetByteRGB(t,s,i){return this.r=t/255,this.g=s/255,this.b=i/255,this}SetByteRGBA(t,s,i,e){return this.r=t/255,this.g=s/255,this.b=i/255,this.a=e/255,this}SetRGB(t,s,i){return this.r=t,this.g=s,this.b=i,this}SetRGBA(t,s,i,e){return this.r=t,this.g=s,this.b=i,this.a=e,this}SelfAdd(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this.a+=t.a,this}Add(t,s){return s.r=this.r+t.r,s.g=this.g+t.g,s.b=this.b+t.b,s.a=this.a+t.a,s}SelfSub(t){return this.r-=t.r,this.g-=t.g,this.b-=t.b,this.a-=t.a,this}Sub(t,s){return s.r=this.r-t.r,s.g=this.g-t.g,s.b=this.b-t.b,s.a=this.a-t.a,s}SelfMul(t){return this.r*=t,this.g*=t,this.b*=t,this.a*=t,this}Mul(t,s){return s.r=this.r*t,s.g=this.g*t,s.b=this.b*t,s.a=this.a*t,s}Mix(t,s){b2Color.MixColors(this,t,s)}static MixColors(t,s,i){const e=i*(s.r-t.r),h=i*(s.g-t.g),n=i*(s.b-t.b),r=i*(s.a-t.a);t.r+=e,t.g+=h,t.b+=n,t.a+=r,s.r-=e,s.g-=h,s.b-=n,s.a-=r}MakeStyleString(t=this.a){return b2Color.MakeStyleString(this.r,this.g,this.b,t)}static MakeStyleString(t,s,i,e=1){return t*=255,s*=255,i*=255,e<1?`rgba(${t},${s},${i},${e})`:`rgb(${t},${s},${i})`}}b2Color.ZERO=new b2Color(0,0,0,0),b2Color.RED=new b2Color(1,0,0),b2Color.GREEN=new b2Color(0,1,0),b2Color.BLUE=new b2Color(0,0,1);class b2TypedColor{constructor(...t){if(t[0]instanceof Float32Array){if(4!==t[0].length)throw new Error;this.data=t[0]}else{const s="number"==typeof t[0]?t[0]:.5,i="number"==typeof t[1]?t[1]:.5,e="number"==typeof t[2]?t[2]:.5,h="number"==typeof t[3]?t[3]:1;this.data=new Float32Array([s,i,e,h])}}get r(){return this.data[0]}set r(t){this.data[0]=t}get g(){return this.data[1]}set g(t){this.data[1]=t}get b(){return this.data[2]}set b(t){this.data[2]=t}get a(){return this.data[3]}set a(t){this.data[3]=t}Clone(){return new b2TypedColor(new Float32Array(this.data))}Copy(t){return t instanceof b2TypedColor?this.data.set(t.data):(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 0===this.r&&0===this.g&&0===this.b&&0===this.a}Set(t,s,i,e=this.a){this.SetRGBA(t,s,i,e)}SetByteRGB(t,s,i){return this.r=t/255,this.g=s/255,this.b=i/255,this}SetByteRGBA(t,s,i,e){return this.r=t/255,this.g=s/255,this.b=i/255,this.a=e/255,this}SetRGB(t,s,i){return this.r=t,this.g=s,this.b=i,this}SetRGBA(t,s,i,e){return this.r=t,this.g=s,this.b=i,this.a=e,this}SelfAdd(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this.a+=t.a,this}Add(t,s){return s.r=this.r+t.r,s.g=this.g+t.g,s.b=this.b+t.b,s.a=this.a+t.a,s}SelfSub(t){return this.r-=t.r,this.g-=t.g,this.b-=t.b,this.a-=t.a,this}Sub(t,s){return s.r=this.r-t.r,s.g=this.g-t.g,s.b=this.b-t.b,s.a=this.a-t.a,s}SelfMul(t){return this.r*=t,this.g*=t,this.b*=t,this.a*=t,this}Mul(t,s){return s.r=this.r*t,s.g=this.g*t,s.b=this.b*t,s.a=this.a*t,s}Mix(t,s){b2Color.MixColors(this,t,s)}MakeStyleString(t=this.a){return b2Color.MakeStyleString(this.r,this.g,this.b,t)}}t.DrawFlags=void 0,function(t){t[t.e_none=0]="e_none",t[t.e_shapeBit=1]="e_shapeBit",t[t.e_jointBit=2]="e_jointBit",t[t.e_aabbBit=4]="e_aabbBit",t[t.e_pairBit=8]="e_pairBit",t[t.e_centerOfMassBit=16]="e_centerOfMassBit",t[t.e_particleBit=32]="e_particleBit",t[t.e_controllerBit=64]="e_controllerBit",t[t.e_all=63]="e_all"}(t.DrawFlags||(t.DrawFlags={}));function b2Maybe(t,s){return void 0!==t?t:s}const s=1e37,i=1e-5,e=i*i,h=3.14159265359,n=.1,r=.005,o=2/180*h,c=2*r,b=.2,l=8/180*h,a=.5*h,u=a*a,V=-1,f=.75,w=.25,d=256,S=.01,y=2/180*h;class b2Version{constructor(t=0,s=0,i=0){this.major=0,this.minor=0,this.revision=0,this.major=t,this.minor=s,this.revision=i}toString(){return this.major+"."+this.minor+"."+this.revision}}const m=new b2Version(2,4,1);function b2MakeArray(t,s){const i=new Array(t);for(let e=0;e<t;++e)i[e]=s(e);return i}function b2MakeNumberArray(t,s=0){const i=new Array(t);for(let e=0;e<t;++e)i[e]=s;return i}class b2GrowableStack{constructor(t){this.m_stack=[],this.m_count=0,this.m_stack=b2MakeArray(t,(t=>null)),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 C=h/180,P=180/h,p=2*h,M=Math.abs;function b2Min(t,s){return t<s?t:s}function b2Max(t,s){return t>s?t:s}function b2Clamp(t,s,i){return t<s?s:t>i?i:t}const g=isFinite;function b2Sq(t){return t*t}function b2InvSqrt(t){return 1/Math.sqrt(t)}const G=Math.sqrt,A=Math.pow;const x=Math.cos,J=Math.sin,R=Math.acos,T=Math.asin,D=Math.atan2;class b2Vec2{constructor(t=0,s=0){this.x=t,this.y=s}Clone(){return new b2Vec2(this.x,this.y)}SetZero(){return this.x=0,this.y=0,this}Set(t,s){return this.x=t,this.y=s,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,s){return this.x+=t,this.y+=s,this}SelfSub(t){return this.x-=t.x,this.y-=t.y,this}SelfSubXY(t,s){return this.x-=t,this.y-=s,this}SelfMul(t){return this.x*=t,this.y*=t,this}SelfMulAdd(t,s){return this.x+=t*s.x,this.y+=t*s.y,this}SelfMulSub(t,s){return this.x-=t*s.x,this.y-=t*s.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,s=this.y;return Math.sqrt(t*t+s*s)}LengthSquared(){const t=this.x,s=this.y;return t*t+s*s}Normalize(){const t=this.Length();if(t>=i){const s=1/t;this.x*=s,this.y*=s}return t}SelfNormalize(){const t=this.Length();if(t>=i){const s=1/t;this.x*=s,this.y*=s}return this}SelfRotate(t){const s=Math.cos(t),i=Math.sin(t),e=this.x;return this.x=s*e-i*this.y,this.y=i*e+s*this.y,this}SelfRotateCosSin(t,s){const i=this.x;return this.x=t*i-s*this.y,this.y=s*i+t*this.y,this}IsValid(){return isFinite(this.x)&&isFinite(this.y)}SelfCrossVS(t){const s=this.x;return this.x=t*this.y,this.y=-t*s,this}SelfCrossSV(t){const s=this.x;return this.x=-t*this.y,this.y=t*s,this}SelfMinV(t){return this.x=b2Min(this.x,t.x),this.y=b2Min(this.y,t.y),this}SelfMaxV(t){return this.x=b2Max(this.x,t.x),this.y=b2Max(this.y,t.y),this}SelfAbs(){return this.x=M(this.x),this.y=M(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 b2MakeArray(t,(t=>new b2Vec2))}static AbsV(t,s){return s.x=M(t.x),s.y=M(t.y),s}static MinV(t,s,i){return i.x=b2Min(t.x,s.x),i.y=b2Min(t.y,s.y),i}static MaxV(t,s,i){return i.x=b2Max(t.x,s.x),i.y=b2Max(t.y,s.y),i}static ClampV(t,s,i,e){return e.x=b2Clamp(t.x,s.x,i.x),e.y=b2Clamp(t.y,s.y,i.y),e}static RotateV(t,s,i){const e=t.x,h=t.y,n=Math.cos(s),r=Math.sin(s);return i.x=n*e-r*h,i.y=r*e+n*h,i}static DotVV(t,s){return t.x*s.x+t.y*s.y}static CrossVV(t,s){return t.x*s.y-t.y*s.x}static CrossVS(t,s,i){const e=t.x;return i.x=s*t.y,i.y=-s*e,i}static CrossVOne(t,s){const i=t.x;return s.x=t.y,s.y=-i,s}static CrossSV(t,s,i){const e=s.x;return i.x=-t*s.y,i.y=t*e,i}static CrossOneV(t,s){const i=t.x;return s.x=-t.y,s.y=i,s}static AddVV(t,s,i){return i.x=t.x+s.x,i.y=t.y+s.y,i}static SubVV(t,s,i){return i.x=t.x-s.x,i.y=t.y-s.y,i}static MulSV(t,s,i){return i.x=s.x*t,i.y=s.y*t,i}static MulVS(t,s,i){return i.x=t.x*s,i.y=t.y*s,i}static AddVMulSV(t,s,i,e){return e.x=t.x+s*i.x,e.y=t.y+s*i.y,e}static SubVMulSV(t,s,i,e){return e.x=t.x-s*i.x,e.y=t.y-s*i.y,e}static AddVCrossSV(t,s,i,e){const h=i.x;return e.x=t.x-s*i.y,e.y=t.y+s*h,e}static MidVV(t,s,i){return i.x=.5*(t.x+s.x),i.y=.5*(t.y+s.y),i}static ExtVV(t,s,i){return i.x=.5*(s.x-t.x),i.y=.5*(s.y-t.y),i}static IsEqualToV(t,s){return t.x===s.x&&t.y===s.y}static DistanceVV(t,s){const i=t.x-s.x,e=t.y-s.y;return Math.sqrt(i*i+e*e)}static DistanceSquaredVV(t,s){const i=t.x-s.x,e=t.y-s.y;return i*i+e*e}static NegV(t,s){return s.x=-t.x,s.y=-t.y,s}}b2Vec2.ZERO=new b2Vec2(0,0),b2Vec2.UNITX=new b2Vec2(1,0),b2Vec2.UNITY=new b2Vec2(0,1),b2Vec2.s_t0=new b2Vec2,b2Vec2.s_t1=new b2Vec2,b2Vec2.s_t2=new b2Vec2,b2Vec2.s_t3=new b2Vec2;const v=new b2Vec2(0,0);class b2TypedVec2{constructor(...t){if(t[0]instanceof Float32Array){if(2!==t[0].length)throw new Error;this.data=t[0]}else{const s="number"==typeof t[0]?t[0]:0,i="number"==typeof t[1]?t[1]:0;this.data=new Float32Array([s,i])}}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}Clone(){return new b2TypedVec2(new Float32Array(this.data))}SetZero(){return this.x=0,this.y=0,this}Set(t,s){return this.x=t,this.y=s,this}Copy(t){return t instanceof b2TypedVec2?this.data.set(t.data):(this.x=t.x,this.y=t.y),this}SelfAdd(t){return this.x+=t.x,this.y+=t.y,this}SelfAddXY(t,s){return this.x+=t,this.y+=s,this}SelfSub(t){return this.x-=t.x,this.y-=t.y,this}SelfSubXY(t,s){return this.x-=t,this.y-=s,this}SelfMul(t){return this.x*=t,this.y*=t,this}SelfMulAdd(t,s){return this.x+=t*s.x,this.y+=t*s.y,this}SelfMulSub(t,s){return this.x-=t*s.x,this.y-=t*s.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,s=this.y;return Math.sqrt(t*t+s*s)}LengthSquared(){const t=this.x,s=this.y;return t*t+s*s}Normalize(){const t=this.Length();if(t>=i){const s=1/t;this.x*=s,this.y*=s}return t}SelfNormalize(){const t=this.Length();if(t>=i){const s=1/t;this.x*=s,this.y*=s}return this}SelfRotate(t){const s=Math.cos(t),i=Math.sin(t),e=this.x;return this.x=s*e-i*this.y,this.y=i*e+s*this.y,this}SelfRotateCosSin(t,s){const i=this.x;return this.x=t*i-s*this.y,this.y=s*i+t*this.y,this}IsValid(){return isFinite(this.x)&&isFinite(this.y)}SelfCrossVS(t){const s=this.x;return this.x=t*this.y,this.y=-t*s,this}SelfCrossSV(t){const s=this.x;return this.x=-t*this.y,this.y=t*s,this}SelfMinV(t){return this.x=b2Min(this.x,t.x),this.y=b2Min(this.y,t.y),this}SelfMaxV(t){return this.x=b2Max(this.x,t.x),this.y=b2Max(this.y,t.y),this}SelfAbs(){return this.x=M(this.x),this.y=M(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}}class b2Vec3{constructor(...t){if(t[0]instanceof Float32Array){if(3!==t[0].length)throw new Error;this.data=t[0]}else{const s="number"==typeof t[0]?t[0]:0,i="number"==typeof t[1]?t[1]:0,e="number"==typeof t[2]?t[2]:0;this.data=new Float32Array([s,i,e])}}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 b2Vec3(this.x,this.y,this.z)}SetZero(){return this.x=0,this.y=0,this.z=0,this}SetXYZ(t,s,i){return this.x=t,this.y=s,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,s,i){return this.x+=t,this.y+=s,this.z+=i,this}SelfSub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}SelfSubXYZ(t,s,i){return this.x-=t,this.y-=s,this.z-=i,this}SelfMul(t){return this.x*=t,this.y*=t,this.z*=t,this}static DotV3V3(t,s){return t.x*s.x+t.y*s.y+t.z*s.z}static CrossV3V3(t,s,i){const e=t.x,h=t.y,n=t.z,r=s.x,o=s.y,c=s.z;return i.x=h*c-n*o,i.y=n*r-e*c,i.z=e*o-h*r,i}}b2Vec3.ZERO=new b2Vec3(0,0,0),b2Vec3.s_t0=new b2Vec3;class b2Mat22{constructor(){this.ex=new b2Vec2(1,0),this.ey=new b2Vec2(0,1)}Clone(){return(new b2Mat22).Copy(this)}static FromVV(t,s){return(new b2Mat22).SetVV(t,s)}static FromSSSS(t,s,i,e){return(new b2Mat22).SetSSSS(t,s,i,e)}static FromAngle(t){return(new b2Mat22).SetAngle(t)}SetSSSS(t,s,i,e){return this.ex.Set(t,i),this.ey.Set(s,e),this}SetVV(t,s){return this.ex.Copy(t),this.ey.Copy(s),this}SetAngle(t){const s=Math.cos(t),i=Math.sin(t);return this.ex.Set(s,i),this.ey.Set(-i,s),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 s=this.ex.x,i=this.ey.x,e=this.ex.y,h=this.ey.y;let n=s*h-i*e;return 0!==n&&(n=1/n),t.ex.x=n*h,t.ey.x=-n*i,t.ex.y=-n*e,t.ey.y=n*s,t}Solve(t,s,i){const e=this.ex.x,h=this.ey.x,n=this.ex.y,r=this.ey.y;let o=e*r-h*n;return 0!==o&&(o=1/o),i.x=o*(r*t-h*s),i.y=o*(e*s-n*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,s){const i=t.ex,e=t.ey;return s.ex.x=M(i.x),s.ex.y=M(i.y),s.ey.x=M(e.x),s.ey.y=M(e.y),s}static MulMV(t,s,i){const e=t.ex,h=t.ey,n=s.x,r=s.y;return i.x=e.x*n+h.x*r,i.y=e.y*n+h.y*r,i}static MulTMV(t,s,i){const e=t.ex,h=t.ey,n=s.x,r=s.y;return i.x=e.x*n+e.y*r,i.y=h.x*n+h.y*r,i}static AddMM(t,s,i){const e=t.ex,h=t.ey,n=s.ex,r=s.ey;return i.ex.x=e.x+n.x,i.ex.y=e.y+n.y,i.ey.x=h.x+r.x,i.ey.y=h.y+r.y,i}static MulMM(t,s,i){const e=t.ex.x,h=t.ex.y,n=t.ey.x,r=t.ey.y,o=s.ex.x,c=s.ex.y,b=s.ey.x,l=s.ey.y;return i.ex.x=e*o+n*c,i.ex.y=h*o+r*c,i.ey.x=e*b+n*l,i.ey.y=h*b+r*l,i}static MulTMM(t,s,i){const e=t.ex.x,h=t.ex.y,n=t.ey.x,r=t.ey.y,o=s.ex.x,c=s.ex.y,b=s.ey.x,l=s.ey.y;return i.ex.x=e*o+h*c,i.ex.y=n*o+r*c,i.ey.x=e*b+h*l,i.ey.y=n*b+r*l,i}}b2Mat22.IDENTITY=new b2Mat22;class b2Mat33{constructor(){this.data=new Float32Array([1,0,0,0,1,0,0,0,1]),this.ex=new b2Vec3(this.data.subarray(0,3)),this.ey=new b2Vec3(this.data.subarray(3,6)),this.ez=new b2Vec3(this.data.subarray(6,9))}Clone(){return(new b2Mat33).Copy(this)}SetVVV(t,s,i){return this.ex.Copy(t),this.ey.Copy(s),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,s,i,e){const h=this.ex.x,n=this.ex.y,r=this.ex.z,o=this.ey.x,c=this.ey.y,b=this.ey.z,l=this.ez.x,a=this.ez.y,u=this.ez.z;let V=h*(c*u-b*a)+n*(b*l-o*u)+r*(o*a-c*l);return 0!==V&&(V=1/V),e.x=V*(t*(c*u-b*a)+s*(b*l-o*u)+i*(o*a-c*l)),e.y=V*(h*(s*u-i*a)+n*(i*l-t*u)+r*(t*a-s*l)),e.z=V*(h*(c*i-b*s)+n*(b*t-o*i)+r*(o*s-c*t)),e}Solve22(t,s,i){const e=this.ex.x,h=this.ey.x,n=this.ex.y,r=this.ey.y;let o=e*r-h*n;return 0!==o&&(o=1/o),i.x=o*(r*t-h*s),i.y=o*(e*s-n*t),i}GetInverse22(t){const s=this.ex.x,i=this.ey.x,e=this.ex.y,h=this.ey.y;let n=s*h-i*e;0!==n&&(n=1/n),t.ex.x=n*h,t.ey.x=-n*i,t.ex.z=0,t.ex.y=-n*e,t.ey.y=n*s,t.ey.z=0,t.ez.x=0,t.ez.y=0,t.ez.z=0}GetSymInverse33(t){let s=b2Vec3.DotV3V3(this.ex,b2Vec3.CrossV3V3(this.ey,this.ez,b2Vec3.s_t0));0!==s&&(s=1/s);const i=this.ex.x,e=this.ey.x,h=this.ez.x,n=this.ey.y,r=this.ez.y,o=this.ez.z;t.ex.x=s*(n*o-r*r),t.ex.y=s*(h*r-e*o),t.ex.z=s*(e*r-h*n),t.ey.x=t.ex.y,t.ey.y=s*(i*o-h*h),t.ey.z=s*(h*e-i*r),t.ez.x=t.ex.z,t.ez.y=t.ey.z,t.ez.z=s*(i*n-e*e)}static MulM33V3(t,s,i){const e=s.x,h=s.y,n=s.z;return i.x=t.ex.x*e+t.ey.x*h+t.ez.x*n,i.y=t.ex.y*e+t.ey.y*h+t.ez.y*n,i.z=t.ex.z*e+t.ey.z*h+t.ez.z*n,i}static MulM33XYZ(t,s,i,e,h){return h.x=t.ex.x*s+t.ey.x*i+t.ez.x*e,h.y=t.ex.y*s+t.ey.y*i+t.ez.y*e,h.z=t.ex.z*s+t.ey.z*i+t.ez.z*e,h}static MulM33V2(t,s,i){const e=s.x,h=s.y;return i.x=t.ex.x*e+t.ey.x*h,i.y=t.ex.y*e+t.ey.y*h,i}static MulM33XY(t,s,i,e){return e.x=t.ex.x*s+t.ey.x*i,e.y=t.ex.y*s+t.ey.y*i,e}}b2Mat33.IDENTITY=new b2Mat33;class b2Rot{constructor(t=0){this.s=0,this.c=1,t&&(this.s=Math.sin(t),this.c=Math.cos(t))}Clone(){return(new b2Rot).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,s,i){const e=t.c,h=t.s,n=s.c,r=s.s;return i.s=h*n+e*r,i.c=e*n-h*r,i}static MulTRR(t,s,i){const e=t.c,h=t.s,n=s.c,r=s.s;return i.s=e*r-h*n,i.c=e*n+h*r,i}static MulRV(t,s,i){const e=t.c,h=t.s,n=s.x,r=s.y;return i.x=e*n-h*r,i.y=h*n+e*r,i}static MulTRV(t,s,i){const e=t.c,h=t.s,n=s.x,r=s.y;return i.x=e*n+h*r,i.y=-h*n+e*r,i}}b2Rot.IDENTITY=new b2Rot;class b2Transform{constructor(){this.p=new b2Vec2,this.q=new b2Rot}Clone(){return(new b2Transform).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,s){return this.p.Copy(t),this.q.Copy(s),this}SetPositionAngle(t,s){return this.p.Copy(t),this.q.SetAngle(s),this}SetPosition(t){return this.p.Copy(t),this}SetPositionXY(t,s){return this.p.Set(t,s),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,s,i){const e=t.q.c,h=t.q.s,n=s.x,r=s.y;return i.x=e*n-h*r+t.p.x,i.y=h*n+e*r+t.p.y,i}static MulTXV(t,s,i){const e=t.q.c,h=t.q.s,n=s.x-t.p.x,r=s.y-t.p.y;return i.x=e*n+h*r,i.y=-h*n+e*r,i}static MulXX(t,s,i){return b2Rot.MulRR(t.q,s.q,i.q),b2Vec2.AddVV(b2Rot.MulRV(t.q,s.p,i.p),t.p,i.p),i}static MulTXX(t,s,i){return b2Rot.MulTRR(t.q,s.q,i.q),b2Rot.MulTRV(t.q,b2Vec2.SubVV(s.p,t.p,i.p),i.p),i}}b2Transform.IDENTITY=new b2Transform;class b2Sweep{constructor(){this.localCenter=new b2Vec2,this.c0=new b2Vec2,this.c=new b2Vec2,this.a0=0,this.a=0,this.alpha0=0}Clone(){return(new b2Sweep).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,s){t.p.x=(1-s)*this.c0.x+s*this.c.x,t.p.y=(1-s)*this.c0.y+s*this.c.y;const i=(1-s)*this.a0+s*this.a;return t.q.SetAngle(i),t.p.SelfSub(b2Rot.MulRV(t.q,this.localCenter,b2Vec2.s_t0)),t}Advance(t){const s=(t-this.alpha0)/(1-this.alpha0),i=1-s;this.c0.x=i*this.c0.x+s*this.c.x,this.c0.y=i*this.c0.y+s*this.c.y,this.a0=i*this.a0+s*this.a,this.alpha0=t}Normalize(){const t=p*Math.floor(this.a0/p);this.a0-=t,this.a-=t}}class b2Timer{constructor(){this.m_start=Date.now()}Reset(){return this.m_start=Date.now(),this}GetMilliseconds(){return Date.now()-this.m_start}}class b2DistanceProxy{constructor(){this.m_buffer=b2Vec2.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,s){t.SetupDistanceProxy(this,s)}SetVerticesRadius(t,s,i){this.m_vertices=t,this.m_count=s,this.m_radius=i}GetSupport(t){let s=0,i=b2Vec2.DotVV(this.m_vertices[0],t);for(let e=1;e<this.m_count;++e){const h=b2Vec2.DotVV(this.m_vertices[e],t);h>i&&(s=e,i=h)}return s}GetSupportVertex(t){let s=0,i=b2Vec2.DotVV(this.m_vertices[0],t);for(let e=1;e<this.m_count;++e){const h=b2Vec2.DotVV(this.m_vertices[e],t);h>i&&(s=e,i=h)}return this.m_vertices[s]}GetVertexCount(){return this.m_count}GetVertex(t){return this.m_vertices[t]}}class b2SimplexCache{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 b2DistanceInput{constructor(){this.proxyA=new b2DistanceProxy,this.proxyB=new b2DistanceProxy,this.transformA=new b2Transform,this.transformB=new b2Transform,this.useRadii=!1}Reset(){return this.proxyA.Reset(),this.proxyB.Reset(),this.transformA.SetIdentity(),this.transformB.SetIdentity(),this.useRadii=!1,this}}class b2DistanceOutput{constructor(){this.pointA=new b2Vec2,this.pointB=new b2Vec2,this.distance=0,this.iterations=0}Reset(){return this.pointA.SetZero(),this.pointB.SetZero(),this.distance=0,this.iterations=0,this}}t.gjkCalls=0,t.gjkIters=0,t.gjkMaxIters=0;class b2SimplexVertex{constructor(){this.wA=new b2Vec2,this.wB=new b2Vec2,this.w=new b2Vec2,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 b2Simplex{constructor(){this.m_v1=new b2SimplexVertex,this.m_v2=new b2SimplexVertex,this.m_v3=new b2SimplexVertex,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,s,e,h,n){this.m_count=t.count;const r=this.m_vertices;for(let i=0;i<this.m_count;++i){const o=r[i];o.indexA=t.indexA[i],o.indexB=t.indexB[i];const c=s.GetVertex(o.indexA),b=h.GetVertex(o.indexB);b2Transform.MulXV(e,c,o.wA),b2Transform.MulXV(n,b,o.wB),b2Vec2.SubVV(o.wB,o.wA,o.w),o.a=0}if(this.m_count>1){const s=t.metric,e=this.GetMetric();(e<.5*s||2*s<e||e<i)&&(this.m_count=0)}if(0===this.m_count){const t=r[0];t.indexA=0,t.indexB=0;const i=s.GetVertex(0),o=h.GetVertex(0);b2Transform.MulXV(e,i,t.wA),b2Transform.MulXV(n,o,t.wB),b2Vec2.SubVV(t.wB,t.wA,t.w),t.a=1,this.m_count=1}}WriteCache(t){t.metric=this.GetMetric(),t.count=this.m_count;const s=this.m_vertices;for(let i=0;i<this.m_count;++i)t.indexA[i]=s[i].indexA,t.indexB[i]=s[i].indexB}GetSearchDirection(t){switch(this.m_count){case 1:return b2Vec2.NegV(this.m_v1.w,t);case 2:{const s=b2Vec2.SubVV(this.m_v2.w,this.m_v1.w,t);return b2Vec2.CrossVV(s,b2Vec2.NegV(this.m_v1.w,b2Vec2.s_t0))>0?b2Vec2.CrossOneV(s,t):b2Vec2.CrossVOne(s,t)}default:return t.SetZero()}}GetClosestPoint(t){switch(this.m_count){case 0:case 3:default: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)}}GetWitnessPoints(t,s){switch(this.m_count){case 0:break;case 1:t.Copy(this.m_v1.wA),s.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,s.x=this.m_v1.a*this.m_v1.wB.x+this.m_v2.a*this.m_v2.wB.x,s.y=this.m_v1.a*this.m_v1.wB.y+this.m_v2.a*this.m_v2.wB.y;break;case 3:s.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,s.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}}GetMetric(){switch(this.m_count){case 0:case 1:default:return 0;case 2:return b2Vec2.DistanceVV(this.m_v1.w,this.m_v2.w);case 3:return b2Vec2.CrossVV(b2Vec2.SubVV(this.m_v2.w,this.m_v1.w,b2Vec2.s_t0),b2Vec2.SubVV(this.m_v3.w,this.m_v1.w,b2Vec2.s_t1))}}Solve2(){const t=this.m_v1.w,s=this.m_v2.w,i=b2Vec2.SubVV(s,t,b2Simplex.s_e12),e=-b2Vec2.DotVV(t,i);if(e<=0)return this.m_v1.a=1,void(this.m_count=1);const h=b2Vec2.DotVV(s,i);if(h<=0)return this.m_v2.a=1,this.m_count=1,void this.m_v1.Copy(this.m_v2);const n=1/(h+e);this.m_v1.a=h*n,this.m_v2.a=e*n,this.m_count=2}Solve3(){const t=this.m_v1.w,s=this.m_v2.w,i=this.m_v3.w,e=b2Vec2.SubVV(s,t,b2Simplex.s_e12),h=b2Vec2.DotVV(t,e),n=b2Vec2.DotVV(s,e),r=-h,o=b2Vec2.SubVV(i,t,b2Simplex.s_e13),c=b2Vec2.DotVV(t,o),b=b2Vec2.DotVV(i,o),l=-c,a=b2Vec2.SubVV(i,s,b2Simplex.s_e23),u=b2Vec2.DotVV(s,a),V=b2Vec2.DotVV(i,a),f=-u,w=b2Vec2.CrossVV(e,o),d=w*b2Vec2.CrossVV(s,i),S=w*b2Vec2.CrossVV(i,t),y=w*b2Vec2.CrossVV(t,s);if(r<=0&&l<=0)return this.m_v1.a=1,void(this.m_count=1);if(n>0&&r>0&&y<=0){const t=1/(n+r);return this.m_v1.a=n*t,this.m_v2.a=r*t,void(this.m_count=2)}if(b>0&&l>0&&S<=0){const t=1/(b+l);return this.m_v1.a=b*t,this.m_v3.a=l*t,this.m_count=2,void this.m_v2.Copy(this.m_v3)}if(n<=0&&f<=0)return this.m_v2.a=1,this.m_count=1,void this.m_v1.Copy(this.m_v2);if(b<=0&&V<=0)return this.m_v3.a=1,this.m_count=1,void this.m_v1.Copy(this.m_v3);if(V>0&&f>0&&d<=0){const t=1/(V+f);return this.m_v2.a=V*t,this.m_v3.a=f*t,this.m_count=2,void this.m_v1.Copy(this.m_v3)}const m=1/(d+S+y);this.m_v1.a=d*m,this.m_v2.a=S*m,this.m_v3.a=y*m,this.m_count=3}}b2Simplex.s_e12=new b2Vec2,b2Simplex.s_e13=new b2Vec2,b2Simplex.s_e23=new b2Vec2;const B=new b2Simplex,_=[0,0,0],F=[0,0,0],I=new b2Vec2,k=new b2Vec2,E=new b2Vec2,W=new b2Vec2,L=new b2Vec2;function b2Distance(s,h,n){++t.gjkCalls;const r=n.proxyA,o=n.proxyB,c=n.transformA,b=n.transformB,l=B;l.ReadCache(h,r,c,o,b);const a=l.m_vertices,u=_,V=F;let f=0,w=0;for(;w<20;){f=l.m_count;for(let t=0;t<f;++t)u[t]=a[t].indexA,V[t]=a[t].indexB;switch(l.m_count){case 1:break;case 2:l.Solve2();break;case 3:l.Solve3()}if(3===l.m_count)break;const s=l.GetSearchDirection(k);if(s.LengthSquared()<e)break;const i=a[l.m_count];i.indexA=r.GetSupport(b2Rot.MulTRV(c.q,b2Vec2.NegV(s,b2Vec2.s_t0),W)),b2Transform.MulXV(c,r.GetVertex(i.indexA),i.wA),i.indexB=o.GetSupport(b2Rot.MulTRV(b.q,s,L)),b2Transform.MulXV(b,o.GetVertex(i.indexB),i.wB),b2Vec2.SubVV(i.wB,i.wA,i.w),++w,++t.gjkIters;let h=!1;for(let t=0;t<f;++t)if(i.indexA===u[t]&&i.indexB===V[t]){h=!0;break}if(h)break;++l.m_count}if(t.gjkMaxIters=b2Max(t.gjkMaxIters,w),l.GetWitnessPoints(s.pointA,s.pointB),s.distance=b2Vec2.DistanceVV(s.pointA,s.pointB),s.iterations=w,l.WriteCache(h),n.useRadii){const t=r.m_radius,e=o.m_radius;if(s.distance>t+e&&s.distance>i){s.distance-=t+e;const i=b2Vec2.SubVV(s.pointB,s.pointA,E);i.Normalize(),s.pointA.SelfMulAdd(t,i),s.pointB.SelfMulSub(e,i)}else{const t=b2Vec2.MidVV(s.pointA,s.pointB,I);s.pointA.Copy(t),s.pointB.Copy(t),s.distance=0}}}const j=new b2Vec2,O=new b2Simplex,N=new b2Vec2,q=new b2Vec2,U=new b2Vec2,Q=new b2Vec2,z=new b2Vec2,X=new b2Vec2;t.ContactFeatureType=void 0,function(t){t[t.e_vertex=0]="e_vertex",t[t.e_face=1]="e_face"}(t.ContactFeatureType||(t.ContactFeatureType={}));class b2ContactFeature{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=255&this._key,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 b2ContactID{constructor(){this.cf=new b2ContactFeature}Copy(t){return this.key=t.key,this}Clone(){return(new b2ContactID).Copy(this)}get key(){return this.cf.key}set key(t){this.cf.key=t}}class b2ManifoldPoint{constructor(){this.localPoint=new b2Vec2,this.normalImpulse=0,this.tangentImpulse=0,this.id=new b2ContactID}static MakeArray(t){return b2MakeArray(t,(t=>new b2ManifoldPoint))}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}}t.ManifoldType=void 0,function(t){t[t.e_unknown=-1]="e_unknown",t[t.e_circles=0]="e_circles",t[t.e_faceA=1]="e_faceA",t[t.e_faceB=2]="e_faceB"}(t.ManifoldType||(t.ManifoldType={}));class b2Manifold{constructor(){this.points=b2ManifoldPoint.MakeArray(2),this.localNormal=new b2Vec2,this.localPoint=new b2Vec2,this.type=t.ManifoldType.e_unknown,this.pointCount=0}Reset(){for(let t=0;t<2;++t)this.points[t].Reset();this.localNormal.SetZero(),this.localPoint.SetZero(),this.type=t.ManifoldType.e_unknown,this.pointCount=0}Copy(t){this.pointCount=t.pointCount;for(let s=0;s<2;++s)this.points[s].Copy(t.points[s]);return this.localNormal.Copy(t.localNormal),this.localPoint.Copy(t.localPoint),this.type=t.type,this}Clone(){return(new b2Manifold).Copy(this)}}class b2WorldManifold{constructor(){this.normal=new b2Vec2,this.points=b2Vec2.MakeArray(2),this.separations=b2MakeNumberArray(2)}Initialize(s,i,h,n,r){if(0!==s.pointCount)switch(s.type){case t.ManifoldType.e_circles:{this.normal.Set(1,0);const t=b2Transform.MulXV(i,s.localPoint,b2WorldManifold.Initialize_s_pointA),o=b2Transform.MulXV(n,s.points[0].localPoint,b2WorldManifold.Initialize_s_pointB);b2Vec2.DistanceSquaredVV(t,o)>e&&b2Vec2.SubVV(o,t,this.normal).SelfNormalize();const c=b2Vec2.AddVMulSV(t,h,this.normal,b2WorldManifold.Initialize_s_cA),b=b2Vec2.SubVMulSV(o,r,this.normal,b2WorldManifold.Initialize_s_cB);b2Vec2.MidVV(c,b,this.points[0]),this.separations[0]=b2Vec2.DotVV(b2Vec2.SubVV(b,c,b2Vec2.s_t0),this.normal);break}case t.ManifoldType.e_faceA:{b2Rot.MulRV(i.q,s.localNormal,this.normal);const t=b2Transform.MulXV(i,s.localPoint,b2WorldManifold.Initialize_s_planePoint);for(let i=0;i<s.pointCount;++i){const e=b2Transform.MulXV(n,s.points[i].localPoint,b2WorldManifold.Initialize_s_clipPoint),o=h-b2Vec2.DotVV(b2Vec2.SubVV(e,t,b2Vec2.s_t0),this.normal),c=b2Vec2.AddVMulSV(e,o,this.normal,b2WorldManifold.Initialize_s_cA),b=b2Vec2.SubVMulSV(e,r,this.normal,b2WorldManifold.Initialize_s_cB);b2Vec2.MidVV(c,b,this.points[i]),this.separations[i]=b2Vec2.DotVV(b2Vec2.SubVV(b,c,b2Vec2.s_t0),this.normal)}break}case t.ManifoldType.e_faceB:{b2Rot.MulRV(n.q,s.localNormal,this.normal);const t=b2Transform.MulXV(n,s.localPoint,b2WorldManifold.Initialize_s_planePoint);for(let e=0;e<s.pointCount;++e){const n=b2Transform.MulXV(i,s.points[e].localPoint,b2WorldManifold.Initialize_s_clipPoint),o=r-b2Vec2.DotVV(b2Vec2.SubVV(n,t,b2Vec2.s_t0),this.normal),c=b2Vec2.AddVMulSV(n,o,this.normal,b2WorldManifold.Initialize_s_cB),b=b2Vec2.SubVMulSV(n,h,this.normal,b2WorldManifold.Initialize_s_cA);b2Vec2.MidVV(b,c,this.points[e]),this.separations[e]=b2Vec2.DotVV(b2Vec2.SubVV(b,c,b2Vec2.s_t0),this.normal)}this.normal.SelfNeg();break}}}}b2WorldManifold.Initialize_s_pointA=new b2Vec2,b2WorldManifold.Initialize_s_pointB=new b2Vec2,b2WorldManifold.Initialize_s_cA=new b2Vec2,b2WorldManifold.Initialize_s_cB=new b2Vec2,b2WorldManifold.Initialize_s_planePoint=new b2Vec2,b2WorldManifold.Initialize_s_clipPoint=new b2Vec2,t.PointState=void 0,function(t){t[t.b2_nullState=0]="b2_nullState",t[t.b2_addState=1]="b2_addState",t[t.b2_persistState=2]="b2_persistState",t[t.b2_removeState=3]="b2_removeState"}(t.PointState||(t.PointState={}));class b2ClipVertex{constructor(){this.v=new b2Vec2,this.id=new b2ContactID}static MakeArray(t){return b2MakeArray(t,(t=>new b2ClipVertex))}Copy(t){return this.v.Copy(t.v),this.id.Copy(t.id),this}}class b2RayCastInput{constructor(){this.p1=new b2Vec2,this.p2=new b2Vec2,this.maxFraction=1}Copy(t){return this.p1.Copy(t.p1),this.p2.Copy(t.p2),this.maxFraction=t.maxFraction,this}}class b2RayCastOutput{constructor(){this.normal=new b2Vec2,this.fraction=0}Copy(t){return this.normal.Copy(t.normal),this.fraction=t.fraction,this}}class b2AABB{constructor(){this.lowerBound=new b2Vec2,this.upperBound=new b2Vec2,this.m_cache_center=new b2Vec2,this.m_cache_extent=new b2Vec2}Copy(t){return this.lowerBound.Copy(t.lowerBound),this.upperBound.Copy(t.upperBound),this}IsValid(){return!!this.lowerBound.IsValid()&&(!!this.upperBound.IsValid()&&(!(this.upperBound.x<this.lowerBound.x)&&!(this.upperBound.y<this.lowerBound.y)))}GetCenter(){return b2Vec2.MidVV(this.lowerBound,this.upperBound,this.m_cache_center)}GetExtents(){return b2Vec2.ExtVV(this.lowerBound,this.upperBound,this.m_cache_extent)}GetPerimeter(){return 2*(this.upperBound.x-this.lowerBound.x+(this.upperBound.y-this.lowerBound.y))}Combine1(t){return this.lowerBound.x=b2Min(this.lowerBound.x,t.lowerBound.x),this.lowerBound.y=b2Min(this.lowerBound.y,t.lowerBound.y),this.upperBound.x=b2Max(this.upperBound.x,t.upperBound.x),this.upperBound.y=b2Max(this.upperBound.y,t.upperBound.y),this}Combine2(t,s){return this.lowerBound.x=b2Min(t.lowerBound.x,s.lowerBound.x),this.lowerBound.y=b2Min(t.lowerBound.y,s.lowerBound.y),this.upperBound.x=b2Max(t.upperBound.x,s.upperBound.x),this.upperBound.y=b2Max(t.upperBound.y,s.upperBound.y),this}static Combine(t,s,i){return i.Combine2(t,s),i}Contains(t){let s=!0;return s=s&&this.lowerBound.x<=t.lowerBound.x,s=s&&this.lowerBound.y<=t.lowerBound.y,s=s&&t.upperBound.x<=this.upperBound.x,s=s&&t.upperBound.y<=this.upperBound.y,s}RayCast(t,e){let h=-s,n=s;const r=e.p1.x,o=e.p1.y,c=e.p2.x-e.p1.x,b=e.p2.y-e.p1.y,l=M(c),a=M(b),u=t.normal;if(l<i){if(r<this.lowerBound.x||this.upperBound.x<r)return!1}else{const t=1/c;let s=(this.lowerBound.x-r)*t,i=(this.upperBound.x-r)*t,e=-1;if(s>i){const t=s;s=i,i=t,e=1}if(s>h&&(u.x=e,u.y=0,h=s),n=b2Min(n,i),h>n)return!1}if(a<i){if(o<this.lowerBound.y||this.upperBound.y<o)return!1}else{const t=1/b;let s=(this.lowerBound.y-o)*t,i=(this.upperBound.y-o)*t,e=-1;if(s>i){const t=s;s=i,i=t,e=1}if(s>h&&(u.x=0,u.y=e,h=s),n=b2Min(n,i),h>n)return!1}return!(h<0||e.maxFraction<h)&&(t.fraction=h,!0)}TestContain(t){return!(t.x<this.lowerBound.x||this.upperBound.x<t.x)&&!(t.y<this.lowerBound.y||this.upperBound.y<t.y)}TestOverlap(t){return!(this.upperBound.x<t.lowerBound.x)&&(!(this.upperBound.y<t.lowerBound.y)&&(!(t.upperBound.x<this.lowerBound.x)&&!(t.upperBound.y<this.lowerBound.y)))}}function b2TestOverlapAABB(t,s){return!(t.upperBound.x<s.lowerBound.x)&&(!(t.upperBound.y<s.lowerBound.y)&&(!(s.upperBound.x<t.lowerBound.x)&&!(s.upperBound.y<t.lowerBound.y)))}function b2ClipSegmentToLine(s,i,e,h,n){let r=0;const o=i[0],c=i[1],b=b2Vec2.DotVV(e,o.v)-h,l=b2Vec2.DotVV(e,c.v)-h;if(b<=0&&s[r++].Copy(o),l<=0&&s[r++].Copy(c),b*l<0){const i=b/(b-l),e=s[r].v;e.x=o.v.x+i*(c.v.x-o.v.x),e.y=o.v.y+i*(c.v.y-o.v.y);const h=s[r].id;h.cf.indexA=n,h.cf.indexB=o.id.cf.indexB,h.cf.typeA=t.ContactFeatureType.e_vertex,h.cf.typeB=t.ContactFeatureType.e_face,++r}return r}const Z=new b2DistanceInput,H=new b2SimplexCache,Y=new b2DistanceOutput;function b2TestOverlapShape(t,s,e,h,n,r){const o=Z.Reset();o.proxyA.SetShape(t,s),o.proxyB.SetShape(e,h),o.transformA.Copy(n),o.transformB.Copy(r),o.useRadii=!0;const c=H.Reset();c.count=0;const b=Y.Reset();return b2Distance(b,c,o),b.distance<10*i}function verify(t){if(null===t)throw new Error;return t}class b2TreeNode{constructor(t=0){this.m_id=0,this.aabb=new b2AABB,this._userData=null,this.parent=null,this.child1=null,this.child2=null,this.height=0,this.moved=!1,this.m_id=t}get userData(){if(null===this._userData)throw new Error;return this._userData}set userData(t){if(null!==this._userData)throw new Error;this._userData=t}Reset(){this._userData=null}IsLeaf(){return null===this.child1}}class b2DynamicTree{constructor(){this.m_root=null,this.m_freeList=null,this.m_insertionCount=0,this.m_stack=new b2GrowableStack(256)}Query(t,s){const i=this.m_stack.Reset();for(i.Push(this.m_root);i.GetCount()>0;){const e=i.Pop();if(null!==e&&e.aabb.TestOverlap(t))if(e.IsLeaf()){if(!s(e))return}else i.Push(e.child1),i.Push(e.child2)}}QueryPoint(t,s){const i=this.m_stack.Reset();for(i.Push(this.m_root);i.GetCount()>0;){const e=i.Pop();if(null!==e&&e.aabb.TestContain(t))if(e.IsLeaf()){if(!s(e))return}else i.Push(e.child1),i.Push(e.child2)}}RayCast(t,s){const i=t.p1,e=t.p2,h=b2Vec2.SubVV(e,i,b2DynamicTree.s_r);h.Normalize();const n=b2Vec2.CrossOneV(h,b2DynamicTree.s_v),r=b2Vec2.AbsV(n,b2DynamicTree.s_abs_v);let o=t.maxFraction;const c=b2DynamicTree.s_segmentAABB;let b=i.x+o*(e.x-i.x),l=i.y+o*(e.y-i.y);c.lowerBound.x=b2Min(i.x,b),c.lowerBound.y=b2Min(i.y,l),c.upperBound.x=b2Max(i.x,b),c.upperBound.y=b2Max(i.y,l);const a=this.m_stack.Reset();for(a.Push(this.m_root);a.GetCount()>0;){const h=a.Pop();if(null===h)continue;if(!b2TestOverlapAABB(h.aabb,c))continue;const u=h.aabb.GetCenter(),V=h.aabb.GetExtents();if(!(M(b2Vec2.DotVV(n,b2Vec2.SubVV(i,u,b2Vec2.s_t0)))-b2Vec2.DotVV(r,V)>0))if(h.IsLeaf()){const n=b2DynamicTree.s_subInput;n.p1.Copy(t.p1),n.p2.Copy(t.p2),n.maxFraction=o;const r=s(n,h);if(0===r)return;r>0&&(o=r,b=i.x+o*(e.x-i.x),l=i.y+o*(e.y-i.y),c.lowerBound.x=b2Min(i.x,b),c.lowerBound.y=b2Min(i.y,l),c.upperBound.x=b2Max(i.x,b),c.upperBound.y=b2Max(i.y,l))}else a.Push(h.child1),a.Push(h.child2)}}AllocateNode(){if(null!==this.m_freeList){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 b2TreeNode(b2DynamicTree.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,s){const i=this.AllocateNode();return i.aabb.lowerBound.x=t.lowerBound.x-.1,i.aabb.lowerBound.y=t.lowerBound.y-.1,i.aabb.upperBound.x=t.upperBound.x+.1,i.aabb.upperBound.y=t.upperBound.y+.1,i.userData=s,i.height=0,i.moved=!0,this.InsertLeaf(i),i}DestroyProxy(t){this.RemoveLeaf(t),this.FreeNode(t)}MoveProxy(t,s,i){const e=b2DynamicTree.MoveProxy_s_fatAABB,h=n,r=n;e.lowerBound.x=s.lowerBound.x-h,e.lowerBound.y=s.lowerBound.y-r,e.upperBound.x=s.upperBound.x+h,e.upperBound.y=s.upperBound.y+r;const o=4*i.x,c=4*i.y;o<0?e.lowerBound.x+=o:e.upperBound.x+=o,c<0?e.lowerBound.y+=c:e.upperBound.y+=c;const b=t.aabb;if(b.Contains(s)){const t=b2DynamicTree.MoveProxy_s_hugeAABB;if(t.lowerBound.x=e.lowerBound.x-.4,t.lowerBound.y=e.lowerBound.y-.4,t.upperBound.x=e.upperBound.x+.4,t.upperBound.y=e.upperBound.y+.4,t.Contains(b))return!1}return this.RemoveLeaf(t),t.aabb.Copy(e),this.InsertLeaf(t),t.moved=!0,!0}InsertLeaf(t){if(++this.m_insertionCount,null===this.m_root)return this.m_root=t,void(this.m_root.parent=null);const s=t.aabb;let i=this.m_root;for(;!i.IsLeaf();){const t=verify(i.child1),e=verify(i.child2),h=i.aabb.GetPerimeter(),n=b2DynamicTree.s_combinedAABB;n.Combine2(i.aabb,s);const r=n.GetPerimeter(),o=2*r,c=2*(r-h);let b;const l=b2DynamicTree.s_aabb;let a,u,V;if(t.IsLeaf()?(l.Combine2(s,t.aabb),b=l.GetPerimeter()+c):(l.Combine2(s,t.aabb),a=t.aabb.GetPerimeter(),u=l.GetPerimeter(),b=u-a+c),e.IsLeaf()?(l.Combine2(s,e.aabb),V=l.GetPerimeter()+c):(l.Combine2(s,e.aabb),a=e.aabb.GetPerimeter(),u=l.GetPerimeter(),V=u-a+c),o<b&&o<V)break;i=b<V?t:e}const e=i.parent,h=this.AllocateNode();h.parent=e,h.aabb.Combine2(s,i.aabb),h.height=i.height+1,null!==e?(e.child1===i?e.child1=h:e.child2=h,h.child1=i,h.child2=t,i.parent=h,t.parent=h):(h.child1=i,h.child2=t,i.parent=h,t.parent=h,this.m_root=h);let n=t.parent;for(;null!==n;){n=this.Balance(n);const t=verify(n.child1),s=verify(n.child2);n.height=1+b2Max(t.height,s.height),n.aabb.Combine2(t.aabb,s.aabb),n=n.parent}}RemoveLeaf(t){if(t===this.m_root)return void(this.m_root=null);const s=verify(t.parent),i=s&&s.parent,e=verify(s.child1===t?s.child2:s.child1);if(null!==i){i.child1===s?i.child1=e:i.child2=e,e.parent=i,this.FreeNode(s);let t=i;for(;null!==t;){t=this.Balance(t);const s=verify(t.child1),i=verify(t.child2);t.aabb.Combine2(s.aabb,i.aabb),t.height=1+b2Max(s.height,i.height),t=t.parent}}else this.m_root=e,e.parent=null,this.FreeNode(s)}Balance(t){if(t.IsLeaf()||t.height<2)return t;const s=verify(t.child1),i=verify(t.child2),e=i.height-s.height;if(e>1){const e=verify(i.child1),h=verify(i.child2);return i.child1=t,i.parent=t.parent,t.parent=i,null!==i.parent?i.parent.child1===t?i.parent.child1=i:i.parent.child2=i:this.m_root=i,e.height>h.height?(i.child2=e,t.child2=h,h.parent=t,t.aabb.Combine2(s.aabb,h.aabb),i.aabb.Combine2(t.aabb,e.aabb),t.height=1+b2Max(s.height,h.height),i.height=1+b2Max(t.height,e.height)):(i.child2=h,t.child2=e,e.parent=t,t.aabb.Combine2(s.aabb,e.aabb),i.aabb.Combine2(t.aabb,h.aabb),t.height=1+b2Max(s.height,e.height),i.height=1+b2Max(t.height,h.height)),i}if(e<-1){const e=verify(s.child1),h=verify(s.child2);return s.child1=t,s.parent=t.parent,t.parent=s,null!==s.parent?s.parent.child1===t?s.parent.child1=s:s.parent.child2=s:this.m_root=s,e.height>h.height?(s.child2=e,t.child1=h,h.parent=t,t.aabb.Combine2(i.aabb,h.aabb),s.aabb.Combine2(t.aabb,e.aabb),t.height=1+b2Max(i.height,h.height),s.height=1+b2Max(t.height,e.height)):(s.child2=h,t.child1=e,e.parent=t,t.aabb.Combine2(i.aabb,e.aabb),s.aabb.Combine2(t.aabb,h.aabb),t.height=1+b2Max(i.height,e.height),s.height=1+b2Max(t.height,h.height)),s}return t}GetHeight(){return null===this.m_root?0:this.m_root.height}static GetAreaNode(t){if(null===t)return 0;if(t.IsLeaf())return 0;let s=t.aabb.GetPerimeter();return s+=b2DynamicTree.GetAreaNode(t.child1),s+=b2DynamicTree.GetAreaNode(t.child2),s}GetAreaRatio(){if(null===this.m_root)return 0;const t=this.m_root.aabb.GetPerimeter();return b2DynamicTree.GetAreaNode(this.m_root)/t}static ComputeHeightNode(t){if(null===t)return 0;if(t.IsLeaf())return 0;return 1+b2Max(b2DynamicTree.ComputeHeightNode(t.child1),b2DynamicTree.ComputeHeightNode(t.child2))}ComputeHeight(){return b2DynamicTree.ComputeHeightNode(this.m_root)}ValidateStructure(t){if(null===t)return;if(this.m_root,t.IsLeaf())return;const s=verify(t.child1),i=verify(t.child2);this.ValidateStructure(s),this.ValidateStructure(i)}ValidateMetrics(t){if(null===t)return;if(t.IsLeaf())return;const s=verify(t.child1),i=verify(t.child2);b2DynamicTree.s_aabb.Combine2(s.aabb,i.aabb),this.ValidateMetrics(s),this.ValidateMetrics(i)}Validate(){}static GetMaxBalanceNode(t,s){if(null===t)return s;if(t.height<=1)return s;const i=verify(t.child1),e=verify(t.child2);return b2Max(s,M(e.height-i.height))}GetMaxBalance(){return b2DynamicTree.GetMaxBalanceNode(this.m_root,0)}RebuildBottomUp(){this.Validate()}static ShiftOriginNode(t,s){if(null===t)return;if(t.height<=1)return;const i=t.child1,e=t.child2;b2DynamicTree.ShiftOriginNode(i,s),b2DynamicTree.ShiftOriginNode(e,s),t.aabb.lowerBound.SelfSub(s),t.aabb.upperBound.SelfSub(s)}ShiftOrigin(t){b2DynamicTree.ShiftOriginNode(this.m_root,t)}}b2DynamicTree.s_r=new b2Vec2,b2DynamicTree.s_v=new b2Vec2,b2DynamicTree.s_abs_v=new b2Vec2,b2DynamicTree.s_segmentAABB=new b2AABB,b2DynamicTree.s_subInput=new b2RayCastInput,b2DynamicTree.s_combinedAABB=new b2AABB,b2DynamicTree.s_aabb=new b2AABB,b2DynamicTree.s_node_id=0,b2DynamicTree.MoveProxy_s_fatAABB=new b2AABB,b2DynamicTree.MoveProxy_s_hugeAABB=new b2AABB;class b2Pair{constructor(t,s){this.proxyA=t,this.proxyB=s}}class b2BroadPhase{constructor(){this.m_tree=new b2DynamicTree,this.m_proxyCount=0,this.m_moveCount=0,this.m_moveBuffer=[],this.m_pairCount=0,this.m_pairBuffer=[]}CreateProxy(t,s){const i=this.m_tree.CreateProxy(t,s);return++this.m_proxyCount,this.BufferMove(i),i}DestroyProxy(t){this.UnBufferMove(t),--this.m_proxyCount,this.m_tree.DestroyProxy(t)}MoveProxy(t,s,i){this.m_tree.MoveProxy(t,s,i)&&this.BufferMove(t)}TouchProxy(t){this.BufferMove(t)}GetProxyCount(){return this.m_proxyCount}UpdatePairs(t){this.m_pairCount=0;for(let t=0;t<this.m_moveCount;++t){const s=this.m_moveBuffer[t];if(null===s)continue;const i=s.aabb;this.m_tree.Query(i,(t=>{if(t.m_id===s.m_id)return!0;if(t.moved&&t.m_id>s.m_id)return!0;let i,e;if(t.m_id<s.m_id?(i=t,e=s):(i=s,e=t),this.m_pairCount===this.m_pairBuffer.length)this.m_pairBuffer[this.m_pairCount]=new b2Pair(i,e);else{const t=this.m_pairBuffer[this.m_pairCount];t.proxyA=i,t.proxyB=e}return++this.m_pairCount,!0}))}for(let s=0;s<this.m_pairCount;++s){const i=this.m_pairBuffer[s];t(i.proxyA.userData,i.proxyB.userData)}for(let t=0;t<this.m_moveCount;++t){const s=this.m_moveBuffer[t];null!==s&&(s.moved=!1)}this.m_moveCount=0}Query(t,s){this.m_tree.Query(t,s)}QueryPoint(t,s){this.m_tree.QueryPoint(t,s)}RayCast(t,s){this.m_tree.RayCast(t,s)}GetTreeHeight(){return this.m_tree.GetHeight()}GetTreeBalance(){return this.m_tree.GetMaxBalance()}GetTreeQuality(){return this.m_tree.GetAreaRatio()}ShiftOrigin(t){this.m_tree.ShiftOrigin(t)}BufferMove(t){this.m_moveBuffer[this.m_moveCount]=t,++this.m_moveCount}UnBufferMove(t){for(let s=0;s<this.m_moveCount;++s)this.m_moveBuffer[s]===t&&(this.m_moveBuffer[s]=null)}}class b2MassData{constructor(){this.mass=0,this.center=new b2Vec2(0,0),this.I=0}}t.ShapeType=void 0,function(t){t[t.e_unknown=-1]="e_unknown",t[t.e_circleShape=0]="e_circleShape",t[t.e_edgeShape=1]="e_edgeShape",t[t.e_polygonShape=2]="e_polygonShape",t[t.e_chainShape=3]="e_chainShape",t[t.e_shapeTypeCount=4]="e_shapeTypeCount"}(t.ShapeType||(t.ShapeType={}));class b2Shape{constructor(s,i){this.m_type=t.ShapeType.e_unknown,this.m_radius=0,this.m_type=s,this.m_radius=i}Copy(t){return this.m_radius=t.m_radius,this}GetType(){return this.m_type}}class b2EdgeShape extends b2Shape{constructor(){super(t.ShapeType.e_edgeShape,c),this.m_vertex1=new b2Vec2,this.m_vertex2=new b2Vec2,this.m_vertex0=new b2Vec2,this.m_vertex3=new b2Vec2,this.m_oneSided=!1}SetOneSided(t,s,i,e){return this.m_vertex0.Copy(t),this.m_vertex1.Copy(s),this.m_vertex2.Copy(i),this.m_vertex3.Copy(e),this.m_oneSided=!0,this}SetTwoSided(t,s){return this.m_vertex1.Copy(t),this.m_vertex2.Copy(s),this.m_oneSided=!1,this}Clone(){return(new b2EdgeShape).Copy(this)}Copy(t){return super.Copy(t),this.m_vertex1.Copy(t.m_vertex1),this.m_vertex2.Copy(t.m_vertex2),this.m_vertex0.Copy(t.m_vertex0),this.m_vertex3.Copy(t.m_vertex3),this.m_oneSided=t.m_oneSided,this}GetChildCount(){return 1}TestPoint(t,s){return!1}ComputeDistance(t,s,i,e){const h=b2Transform.MulXV(t,this.m_vertex1,b2EdgeShape.ComputeDistance_s_v1),n=b2Transform.MulXV(t,this.m_vertex2,b2EdgeShape.ComputeDistance_s_v2),r=b2Vec2.SubVV(s,h,b2EdgeShape.ComputeDistance_s_d),o=b2Vec2.SubVV(n,h,b2EdgeShape.ComputeDistance_s_s),c=b2Vec2.DotVV(r,o);if(c>0){const t=b2Vec2.DotVV(o,o);c>t?b2Vec2.SubVV(s,n,r):r.SelfMulSub(c/t,o)}return i.Copy(r),i.Normalize()}RayCast(t,s,i,e){const h=b2Transform.MulTXV(i,s.p1,b2EdgeShape.RayCast_s_p1),n=b2Transform.MulTXV(i,s.p2,b2EdgeShape.RayCast_s_p2),r=b2Vec2.SubVV(n,h,b2EdgeShape.RayCast_s_d),o=this.m_vertex1,c=this.m_vertex2,b=b2Vec2.SubVV(c,o,b2EdgeShape.RayCast_s_e),l=t.normal.Set(b.y,-b.x).SelfNormalize(),a=b2Vec2.DotVV(l,b2Vec2.SubVV(o,h,b2Vec2.s_t0));if(this.m_oneSided&&a>0)return!1;const u=b2Vec2.DotVV(l,r);if(0===u)return!1;const V=a/u;if(V<0||s.maxFraction<V)return!1;const f=b2Vec2.AddVMulSV(h,V,r,b2EdgeShape.RayCast_s_q),w=b2Vec2.SubVV(c,o,b2EdgeShape.RayCast_s_r),d=b2Vec2.DotVV(w,w);if(0===d)return!1;const S=b2Vec2.DotVV(b2Vec2.SubVV(f,o,b2Vec2.s_t0),w)/d;return!(S<0||1<S)&&(t.fraction=V,b2Rot.MulRV(i.q,t.normal,t.normal),a>0&&t.normal.SelfNeg(),!0)}ComputeAABB(t,s,i){const e=b2Transform.MulXV(s,this.m_vertex1,b2EdgeShape.ComputeAABB_s_v1),h=b2Transform.MulXV(s,this.m_vertex2,b2EdgeShape.ComputeAABB_s_v2);b2Vec2.MinV(e,h,t.lowerBound),b2Vec2.MaxV(e,h,t.upperBound);const n=this.m_radius;t.lowerBound.SelfSubXY(n,n),t.upperBound.SelfAddXY(n,n)}ComputeMass(t,s){t.mass=0,b2Vec2.MidVV(this.m_vertex1,this.m_vertex2,t.center),t.I=0}SetupDistanceProxy(t,s){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,s,i,e){return e.SetZero(),0}Dump(t){t(" const shape: b2EdgeShape = new b2EdgeShape();\n"),t(" shape.m_radius = %.15f;\n",this.m_radius),t(" shape.m_vertex0.Set(%.15f, %.15f);\n",this.m_vertex0.x,this.m_vertex0.y),t(" shape.m_vertex1.Set(%.15f, %.15f);\n",this.m_vertex1.x,this.m_vertex1.y),t(" shape.m_vertex2.Set(%.15f, %.15f);\n",this.m_vertex2.x,this.m_vertex2.y),t(" shape.m_vertex3.Set(%.15f, %.15f);\n",this.m_vertex3.x,this.m_vertex3.y),t(" shape.m_oneSided = %s;\n",this.m_oneSided)}}b2EdgeShape.ComputeDistance_s_v1=new b2Vec2,b2EdgeShape.ComputeDistance_s_v2=new b2Vec2,b2EdgeShape.ComputeDistance_s_d=new b2Vec2,b2EdgeShape.ComputeDistance_s_s=new b2Vec2,b2EdgeShape.RayCast_s_p1=new b2Vec2,b2EdgeShape.RayCast_s_p2=new b2Vec2,b2EdgeShape.RayCast_s_d=new b2Vec2,b2EdgeShape.RayCast_s_e=new b2Vec2,b2EdgeShape.RayCast_s_q=new b2Vec2,b2EdgeShape.RayCast_s_r=new b2Vec2,b2EdgeShape.ComputeAABB_s_v1=new b2Vec2,b2EdgeShape.ComputeAABB_s_v2=new b2Vec2;class b2ChainShape extends b2Shape{constructor(){super(t.ShapeType.e_chainShape,c),this.m_vertices=[],this.m_count=0,this.m_prevVertex=new b2Vec2,this.m_nextVertex=new b2Vec2}CreateLoop(...t){if("number"==typeof t[0][0]){const s=t[0];if(s.length%2!=0)throw new Error;return this._CreateLoop((t=>({x:s[2*t],y:s[2*t+1]})),s.length/2)}{const s=t[0];return this._CreateLoop((t=>s[t]),s.length)}}_CreateLoop(t,s){if(s<3)return this;this.m_count=s+1,this.m_vertices=b2Vec2.MakeArray(this.m_count);for(let i=0;i<s;++i)this.m_vertices[i].Copy(t(i));return this.m_vertices[s].Copy(this.m_vertices[0]),this.m_prevVertex.Copy(this.m_vertices[this.m_count-2]),this.m_nextVertex.Copy(this.m_vertices[1]),this}CreateChain(...t){if("number"==typeof t[0][0]){const s=t[0],i=t[1],e=t[2];if(s.length%2!=0)throw new Error;return this._CreateChain((t=>({x:s[2*t],y:s[2*t+1]})),s.length/2,i,e)}{const s=t[0],i=t[1],e=t[2];return this._CreateChain((t=>s[t]),s.length,i,e)}}_CreateChain(t,s,i,e){this.m_count=s,this.m_vertices=b2Vec2.MakeArray(s);for(let i=0;i<s;++i)this.m_vertices[i].Copy(t(i));return this.m_prevVertex.Copy(i),this.m_nextVertex.Copy(e),this}Clone(){return(new b2ChainShape).Copy(this)}Copy(t){return super.Copy(t),this._CreateChain((s=>t.m_vertices[s]),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,s){t.m_radius=this.m_radius,t.m_vertex1.Copy(this.m_vertices[s]),t.m_vertex2.Copy(this.m_vertices[s+1]),t.m_oneSided=!0,s>0?t.m_vertex0.Copy(this.m_vertices[s-1]):t.m_vertex0.Copy(this.m_prevVertex),s<this.m_count-2?t.m_vertex3.Copy(this.m_vertices[s+2]):t.m_vertex3.Copy(this.m_nextVertex)}TestPoint(t,s){return!1}ComputeDistance(t,s,i,e){const h=b2ChainShape.ComputeDistance_s_edgeShape;return this.GetChildEdge(h,e),h.ComputeDistance(t,s,i,0)}RayCast(t,s,i,e){const h=b2ChainShape.RayCast_s_edgeShape;return h.m_vertex1.Copy(this.m_vertices[e]),h.m_vertex2.Copy(this.m_vertices[(e+1)%this.m_count]),h.RayCast(t,s,i,0)}ComputeAABB(t,s,i){const e=this.m_vertices[i],h=this.m_vertices[(i+1)%this.m_count],n=b2Transform.MulXV(s,e,b2ChainShape.ComputeAABB_s_v1),r=b2Transform.MulXV(s,h,b2ChainShape.ComputeAABB_s_v2),o=b2Vec2.MinV(n,r,b2ChainShape.ComputeAABB_s_lower),c=b2Vec2.MaxV(n,r,b2ChainShape.ComputeAABB_s_upper);t.lowerBound.x=o.x-this.m_radius,t.lowerBound.y=o.y-this.m_rad