@pacedyn/mcp 1.76.0 → 1.76.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +56 -56
- package/dist/worker.js +7 -7
- package/package.json +1 -1
package/dist/worker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{parentPort as EI,workerData as YY}from"node:worker_threads";import{readFileSync as z1}from"node:fs";import{join as Y1}from"node:path";var Xu=e=>e.format!=="points"&&!e.field;var yt=e=>e?.kind==="ice";var Tv={packVoltageMax:600,segmentVoltageMax:120,powerLimitKw:80};var nt=e=>typeof e=="number"&&Number.isFinite(e);function _I(e){let{soc:t,ocv:r,r0:n}=e;if(!Array.isArray(t)||t.length<2)return"The curve needs at least two state-of-charge points.";if(!t.every(nt))return"The state-of-charge axis contains a value that is not a number.";if(t[0]<0||t[t.length-1]>1)return`The state-of-charge axis must lie within 0 to 1 (it runs ${t[0]} to ${t[t.length-1]}).`;for(let o=1;o<t.length;o++)if(!(t[o]>t[o-1]))return`The state-of-charge axis must increase (${t[o-1]} then ${t[o]}).`;if(!Array.isArray(r)||r.length!==t.length)return`The curve has ${Array.isArray(r)?r.length:0} voltages against ${t.length} state-of-charge points.`;if(!r.every(nt))return"The open-circuit voltage contains a value that is not a number.";if(r.some(o=>o<=0))return"The open-circuit voltage must be positive everywhere.";for(let o=1;o<r.length;o++)if(r[o]<r[o-1])return`The open-circuit voltage must rise with state of charge (${r[o-1]} V at ${t[o-1]} then ${r[o]} V at ${t[o]}).`;if(!Array.isArray(n)||n.length!==t.length)return`The curve has ${Array.isArray(n)?n.length:0} resistances against ${t.length} state-of-charge points.`;if(!n.every(nt))return"The resistance contains a value that is not a number.";if(n.some(o=>o<0))return"The resistance cannot be negative.";if(e.rTempC!==void 0||e.rGrid!==void 0){let o=e.rTempC,a=e.rGrid;if(!Array.isArray(o)||o.length<1)return"The resistance temperature axis needs at least one temperature.";if(!o.every(nt))return"The resistance temperature axis contains a value that is not a number.";for(let s=1;s<o.length;s++)if(!(o[s]>o[s-1]))return`The temperature axis must increase (${o[s-1]} then ${o[s]} \xB0C).`;if(!Array.isArray(a)||a.length!==o.length)return`The resistance grid has ${Array.isArray(a)?a.length:0} rows against ${o.length} temperatures.`;for(let s=0;s<a.length;s++){let i=a[s];if(!Array.isArray(i)||i.length!==t.length)return`Resistance row ${s+1} has ${Array.isArray(i)?i.length:0} values against ${t.length} state-of-charge points.`;if(!i.every(nt))return"The resistance grid contains a value that is not a number.";if(i.some(c=>c<0))return"The resistance grid contains a negative resistance."}}return null}function NI(e){return!e||typeof e!="object"?"The cell has no curve.":e.kind==="table"?_I(e):e.kind==="analytic"?!nt(e.vCut)||!nt(e.vNom)||!nt(e.vFull)?"The cut-off, nominal and full voltages must be numbers.":e.vCut<=0?"The cut-off voltage must be positive.":e.vCut<e.vNom&&e.vNom<e.vFull?!nt(e.r0)||e.r0<0?"The cell resistance must be a number and cannot be negative.":e.socAtNom!==void 0&&(!nt(e.socAtNom)||e.socAtNom<=0||e.socAtNom>=1)?"The state of charge the nominal voltage is met at must lie strictly between 0 and 1.":null:`The voltages must order cut-off < nominal < full (given ${e.vCut}, ${e.vNom}, ${e.vFull} V).`:`Unknown cell curve kind "${e.kind}".`}function qu(e){if(!e||typeof e!="object")return"Not a battery model.";let t=e.cell;if(!t||typeof t!="object")return"The model has no cell.";if(!nt(t.capacityAh)||t.capacityAh<=0)return"The cell capacity must be a positive number of amp-hours.";if(!nt(t.vMin)||t.vMin<0)return"The cut-off voltage must be a number and cannot be negative.";if(!nt(t.vMax)||t.vMax<=0)return"The maximum cell voltage must be a positive number.";if(!(t.vMin<t.vMax))return`The cut-off voltage (${t.vMin} V) must be below the maximum (${t.vMax} V).`;if(!nt(t.iMaxA)||t.iMaxA<0)return"The discharge current limit must be a number of amps, 0 for no limit.";if(t.iMaxChargeA!==void 0&&(!nt(t.iMaxChargeA)||t.iMaxChargeA<0))return"The charge current limit must be a number of amps, 0 for no limit.";if(t.massKg!==void 0&&(!nt(t.massKg)||t.massKg<0))return"The cell mass must be a number and cannot be negative.";let r=NI(t.curve);if(r)return r;let n=t.curve.kind==="table"?t.curve.ocv[t.curve.ocv.length-1]:t.curve.vFull;if(t.vMin>=n)return`The cut-off voltage (${t.vMin} V) is at or above the cell's voltage at full charge (${n} V), so no power could ever be drawn.`;let o=e.thermal;if(o!==void 0){if(!o||typeof o!="object")return"The thermal model must be an object, or absent.";if(!nt(o.heatCapacityJPerK)||o.heatCapacityJPerK<=0)return"The cell heat capacity must be a positive number of joules per kelvin.";if(!nt(o.coolingWPerK)||o.coolingWPerK<0)return"The cooling must be a number of watts per kelvin and cannot be negative.";if(o.startC!==void 0&&!nt(o.startC))return"The starting temperature must be a number.";if(o.entropicVPerK!==void 0&&!nt(o.entropicVPerK))return"The entropic coefficient must be a number.";if(o.derateFromC!==void 0){if(!nt(o.derateFromC))return"The temperature the derate starts at must be a number.";if(o.derateToC!==void 0){if(!nt(o.derateToC))return"The temperature the derate ends at must be a number.";if(!(o.derateToC>o.derateFromC))return`The derate must end above where it starts (given ${o.derateFromC} then ${o.derateToC} \xB0C).`}}else if(o.derateToC!==void 0)return"The derate has an end temperature but no start; give both or neither."}let a=e.pack;if(!a||typeof a!="object")return"The model has no pack.";if(!Number.isInteger(a.series)||a.series<1)return"The pack needs a whole number of cells in series, at least one.";if(!Number.isInteger(a.parallel)||a.parallel<1)return"The pack needs a whole number of strings in parallel, at least one.";if(!nt(a.busResistance)||a.busResistance<0)return"The busbar resistance must be a number and cannot be negative.";if(a.seriesPerSegment!==void 0&&a.seriesPerSegment!==0){if(!Number.isInteger(a.seriesPerSegment)||a.seriesPerSegment<1)return"The cells per segment must be a whole number, at least one.";if(a.seriesPerSegment>a.series)return`A segment cannot hold more cells (${a.seriesPerSegment}) than the pack has in series (${a.series}).`}return null}function Go(e,t){let r=e.length;if(r<=1)return{i:0,t:0,clamped:!1};if(t<=e[0])return{i:0,t:0,clamped:t<e[0]};if(t>=e[r-1])return{i:r-2,t:1,clamped:t>e[r-1]};let n=0,o=r-1;for(;o-n>1;){let a=n+o>>1;e[a]<=t?n=a:o=a}return{i:n,t:(t-e[n])/(e[o]-e[n]),clamped:!1}}function ot(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function Qu(e,t,r,n,o){let a=e.length,s=t.length;if(a===0||s===0)return 0;let i=Go(e,n),c=Go(t,o),l=Math.min(i.i+1,a-1),u=Math.min(c.i+1,s-1),m=r[c.i][i.i],p=r[c.i][l],d=r[u][i.i],f=r[u][l],h=m+i.t*(p-m),b=d+i.t*(f-d);return h+c.t*(b-h)}var ds=[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1],Ph={nmc:[0,.29,.4,.483,.525,.567,.608,.667,.733,.8,.892,1],lfp:[0,.478,.591,.626,.652,.67,.678,.696,.704,.722,.757,1],lipo:[0,.333,.433,.517,.575,.625,.667,.717,.775,.833,.908,1],other:[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]},Pv=[0,.05,.1,.2,.5,.8,1],Lv=[2.2,1.55,1.3,1.12,1,.97,.98];function Dv(e){return ot(Pv,Lv,e)}var Ev=[-20,-10,0,10,25,40,60],Iv=[4,2.8,2,1.4,1,.82,.75];function Lh(e){return ot(Ev,Iv,e)}var _v=.5;function Dh(e,t){let{vFull:r,vNom:n,vCut:o,r0:a}=e,s=r-o;if(!(s>0))throw new Error(`The full voltage (${r} V) must be above the cut-off (${o} V).`);let i=(n-o)/s;if(!(i>0&&i<1))throw new Error(`The nominal voltage (${n} V) must lie between the cut-off (${o} V) and full (${r} V).`);let c=Ph[t]??Ph.other,l=e.socAtNom??_v,u=ds.includes(l)?[...ds]:[...ds,l].sort((h,b)=>h-b),m=ot(ds,c,l),p=m>0&&m<1?Math.log(i)/Math.log(m):1,d=[],f=[];for(let h of u){let b=ot(ds,c,h);d.push(o+s*Math.pow(b,p)),f.push(e.constantResistance?a:a*Dv(h))}return{kind:"table",soc:u,ocv:d,r0:f}}function Eh(e){let t=e.soc,r=e.ocv,n=[0,...t.filter(a=>a>0&&a<1),1],o=0;for(let a=1;a<n.length;a++){let s=n[a-1],i=n[a];o+=(ot(t,r,s)+ot(t,r,i))/2*(i-s)}return o}var ps=25,Nv=new WeakMap;function Cn(e){let t=Nv.get(e);if(t)return t;let r=qu(e);if(r)throw new Error(r);let{cell:n,pack:o}=e,a=n.curve.kind==="table"?n.curve:Dh(n.curve,n.chemistry),s=o.series,i=o.parallel,c=s/i,l=a.rTempC,u=a.rGrid,m=i*n.capacityAh,p=s*n.vMin,d=n.iMaxA>0?i*n.iMaxA:1/0,f=n.iMaxChargeA!==void 0&&n.iMaxChargeA>0?n.iMaxChargeA:n.iMaxA/4,h=f>0?i*f:1/0,b=F=>s*ot(a.soc,a.ocv,F),g=(F,w=ps)=>{let T=l&&u?Qu(a.soc,l,u,F,w):ot(a.soc,a.r0,F)*Lh(w);return c*T+o.busResistance},y=(F,w,T)=>b(F)-w*g(F,T),x=(F,w,T)=>{if(!(F>0))return 0;let M=b(w),k=g(w,T);if(!(k>0))return F/M;let C=M*M-4*k*F;return C<0?NaN:2*F/(M+Math.sqrt(C))},R=(F,w,T)=>{if(!(F>0))return 0;let M=b(w),k=g(w,T);return k>0?2*F/(M+Math.sqrt(M*M+4*k*F)):F/M},v=F=>{let w=e.thermal;if(!w||w.derateFromC===void 0)return 1;let T=w.derateToC??w.derateFromC;return F<=w.derateFromC?1:!(T>w.derateFromC)||F>=T?0:1-(F-w.derateFromC)/(T-w.derateFromC)},S=(F,w,T=0)=>{let M=b(F),k=g(F,w),C=k>0?M/(2*k):1/0,P=G=>{if(!(k>0))return G*M;let B=Math.min(G,C);return B*(M-B*k)},L=k>0?Math.max(0,(M-p)/k):1/0,E=T>0&&Number.isFinite(T)?T:1/0,_=k>0?P(L):1/0,D=Number.isFinite(d)?P(d):1/0,I=k>0?M*M/(4*k):1/0,N=[["rules",E],["voltage-floor",_],["current",D],["matched-load",I]],O=N[0][0],V=N[0][1];for(let[G,B]of N)B<V&&(V=B,O=G);let H=v(w??ps);H<1&&(V=Number.isFinite(V)?V*H:V,O="temperature");let U=Number.isFinite(V)?x(V,F,w):1/0;return{watts:V,binding:O,rules:E,voltageFloor:_,current:D,matchedLoad:I,derate:H,amps:U,volts:Number.isFinite(U)?M-U*k:M}},A={model:e,table:a,capacityAh:m,chargeC:m*3600,energyKwh:m*(s*Eh(a))/1e3,socRange:[a.soc[0],a.soc[a.soc.length-1]],voltageAtFull:s*a.ocv[a.ocv.length-1],voltageCeiling:s*n.vMax,voltageFloor:p,currentCeiling:d,chargeCurrentCeiling:h,massKg:n.massKg!==void 0?s*i*n.massKg:null,thermal:e.thermal?{heatCapacityJPerK:s*i*e.thermal.heatCapacityJPerK,coolingWPerK:s*i*e.thermal.coolingWPerK,...e.thermal.startC!==void 0?{startC:e.thermal.startC}:{},entropicVPerK:s*(e.thermal.entropicVPerK??0)}:null,derateAt:v,ocv:b,resistance:g,terminalVoltage:y,currentFor:x,chargeCurrentFor:R,maxPower:S};return Nv.set(e,A),A}function Ih(e){return{name:e.name,chemistry:e.chemistry,capacityAh:e.capacityAh,curve:{kind:"analytic",vFull:e.vFull,vNom:e.vNom,vCut:e.vCut,r0:e.r0},iMaxA:e.iMaxA,...e.iMaxChargeA!==void 0?{iMaxChargeA:e.iMaxChargeA}:{},vMin:e.vCut,vMax:e.vFull,...e.massKg!==void 0?{massKg:e.massKg}:{}}}var Ov={name:"High-power NMC pouch 4.0 Ah",chemistry:"nmc",capacityAh:4,vCut:3,vNom:3.6,vFull:4.2,r0:.0025,iMaxA:100,iMaxChargeA:40,massKg:.09},Vv={name:"LFP prismatic 20 Ah",chemistry:"lfp",capacityAh:20,vCut:2.5,vNom:3.2,vFull:3.65,r0:.002,iMaxA:200,iMaxChargeA:60,massKg:.4},Bv={name:"NMC cylindrical 3.4 Ah",chemistry:"nmc",capacityAh:3.4,vCut:3,vNom:3.6,vFull:4.2,r0:.03,iMaxA:10,iMaxChargeA:3,massKg:.048};function _h(){return{name:"Formula Student accumulator",cell:Ih(Ov),pack:{series:140,parallel:2,busResistance:.02,seriesPerSegment:28},provenance:{source:"assumed",note:"Assumed high-power NMC pouch pack sized to the Formula Student rules; the cell curve and resistance are class-level guesses, not a measurement."}}}function Nh(){return{name:"LFP pack",cell:Ih(Vv),pack:{series:160,parallel:1,busResistance:.02,seriesPerSegment:32},provenance:{source:"assumed",note:"Assumed LFP prismatic pack; the flat plateau is the chemistry, the numbers are class-level guesses."}}}function Oh(){return{name:"Road car pack",cell:Ih(Bv),pack:{series:96,parallel:74,busResistance:.01},provenance:{source:"assumed",note:"Assumed road-electric pack of cylindrical energy cells; capacity and voltage are class-typical, the resistance is a guess."}}}function Vh(e,t,r="Constant pack"){return{name:r,cell:{name:"Constant cell",chemistry:"other",capacityAh:e,curve:{kind:"table",soc:[0,1],ocv:[t,t],r0:[0,0]},iMaxA:0,vMin:0,vMax:t},pack:{series:1,parallel:1,busResistance:0},provenance:{source:"assumed",note:"The constant pack: one open-circuit voltage, no internal resistance and no current limit \u2014 what a car carried before the battery was a model. It cannot sag, so its power never fades."}}}function Qi(e){if(e.kind==="ice"){let n=e.gearbox.efficiency;return{model:e,maxTorque:o=>o>e.limitRpm?0:ot(e.rpm,e.torque,o),efficiency:()=>n}}let t=n=>ot(e.rpm,e.torque,n),r=e.kind==="simple"?()=>e.efficiency:(n,o)=>Qu(e.effRpm,e.effTorque,e.effGrid,n,o);return{model:e,maxTorque:t,efficiency:r}}function Bh(e){let t=e.resistanceAtC??20,r=e.torqueConstant,n=e.speedLossW??0,o=e.speedLossAtRpm??0,a=e.speedLossExponent??1.5,s=e.derateFromC,i=e.derateToC,c=f=>Math.max(0,e.terminalResistanceOhm*(1+.00393*(f-t))),l=f=>n>0&&o>0?n*Math.pow(Math.max(0,f)/o,a):0,u=(f,h,b)=>{let g=r>0?Math.abs(h)/r:0;return 1.5*c(b)*g*g+l(f)},m=(f,h)=>{let b=e.coolingWPerK*(h-e.coolantC)-l(f);return!(b>0)||r<=0?0:r*Math.sqrt(b/(1.5*c(h)))},p=e.coolingWPerK>0?e.heatCapacityJPerK/e.coolingWPerK:1/0,d=Number.isFinite(p)?.25*p:1/0;return{spec:e,startC:e.startC??e.coolantC,lossW:u,step(f,h,b){if(!(b>0)||!(e.heatCapacityJPerK>0))return f;let g=Number.isFinite(d)?Math.max(1,Math.ceil(b/d)):1,y=b/g,x=f;for(let R=0;R<g;R++)x+=(h-e.coolingWPerK*(x-e.coolantC))*y/e.heatCapacityJPerK;return x},continuousTorque:m,derate(f,h,b){if(s===void 0||i===void 0||!(i>s)||!(b>0)||h<=s)return 1;let g=Math.min(1,m(f,i)/b);return h>=i?g:1-(1-g)*(h-s)/(i-s)},equilibriumC(f){return e.coolingWPerK>0?e.coolantC+f/e.coolingWPerK:1/0}}}function xt(e,t){return t==="rear"&&e.tireRateRear!==void 0?e.tireRateRear:e.tireRate}function $h(e,t){let r=e.tyreFreeRadiusRear;return(t==="rear"&&r!==void 0?r:e.tyreFreeRadius)??0}var Zu=9.81,$v=(e,t)=>e*(t*t)/2*(Math.PI/180)/1e3,Zi=(e,t)=>e+t>0?e*t/(e+t):0,Gv=.5;function Ju(e,t,r){if(!(r>0))return 1;let n=e*Zu*t*(Math.PI/180)/r;return 1/(1-Math.min(Gv,n))}function Kv(e,t,r,n){let o=r??0,a=e+t;if(!(o>0)||!Number.isFinite(o)||!(a>0))return null;let s=Math.max(0,Math.min(1,n)),i=e*t+o*a,c=a*(s*t+o)/i,l=a*((1-s)*e+o)/i;return{share:e/a*c,front:c,rear:l}}function Gh(e,t,r){return r>0?e*Zu*t/(r*r):0}function Hv(e,t,r,n,o){if(!(n>0)||!(o>0))return 1;let a=Gh(e,t,r)*(1/n+1/o);return 1/(1-Math.min(Gv,a))}function Ge(e){let t=4*e.unsprungPerCorner,r=Math.max(0,e.massTotal-t),n=r*e.frontMassFrac,o=r*(1-e.frontMassFrac),a=xt(e,"front"),s=xt(e,"rear"),i=e.wheelRateFront+(e.heaveSpringFront??0),c=e.wheelRateRear+(e.heaveSpringRear??0),l=Zi(i,a),u=Zi(c,s),m=(V,H)=>{let U=H/2;return U>0?1/(2*Math.PI)*Math.sqrt(V*1e3/U):0},p=m(l,n),d=m(u,o),f=Zi(e.wheelRateFront+e.arbFront,a),h=Zi(e.wheelRateRear+e.arbRear,s),b=$v(f,e.trackFront),g=$v(h,e.trackRear),y=b+g,x=y>0?b/y:.5,R=e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac),v=(e.cgHeight-R)/1e3,S=r*Zu*v,A=Ju(r,v,y),F=y>0?S/y*A:0,w=Kv(b,g,e.chassisTorsion,e.frontMassFrac),T=w?w.share:x,M=w?F*w.front:F,k=w?F*w.rear:F,C=e.massTotal*Zu*e.cgHeight/e.wheelbase,P=2*l,L=2*u,E=Hv(r,e.cgHeight,e.wheelbase,P,L),D=(P>0&&L>0?(C/P+C/L)/e.wheelbase*E:0)*(180/Math.PI),I=e.wheelbase*e.wheelbase*Zi(P,L)*(Math.PI/180)/1e3,N=e.damperFront??2.5,O=e.damperRear??2.5;return{sprungMass:r,sprungFront:n,sprungRear:o,rideRateFront:l,rideRateRear:u,rideFreqFront:p,rideFreqRear:d,rollRateFront:b,rollRateRear:g,rollRateTotal:y,rollWheelRateFront:f,rollWheelRateRear:h,frontRollStiffFrac:x,frontElasticShare:T,rollGradient:F,rollGradientFront:M,rollGradientRear:k,pitchGradient:D,pitchRate:I,cgRollGain:A,cgPitchGain:E,rideDampingFront:N+(e.heaveDamperFront??0),rideDampingRear:O+(e.heaveDamperRear??0),rollDampingFront:N+(e.rollDamperFront??0),rollDampingRear:O+(e.rollDamperRear??0)}}var mo=["clFront","clRear","cd"],po=e=>e.frame?.kind==="pitch";function fs(e){return po(e)?{x:e.axes.h,y:e.axes.pitch}:{x:e.axes.hFront,y:e.axes.hRear}}var em=e=>e.frame?.kind==="pitch",zv=e=>e.kind==="map";var tm=45,St=e=>typeof e=="number"&&Number.isFinite(e);function rm(e,t,r="mm",n="ride height"){if(!Array.isArray(t)||t.length<1)return`The ${e} axis needs at least one ${n}.`;if(!t.every(St))return`The ${e} axis contains a value that is not a number.`;for(let o=1;o<t.length;o++)if(!(t[o]>t[o-1]))return`The ${e} axis must increase (${t[o-1]} then ${t[o]} ${r}).`;return null}function Yv(e,t){if(t===void 0)return null;for(let r of mo){let n=t[r];if(!n||!Array.isArray(n.deg)||!Array.isArray(n.factor))return`The ${e} correction of ${r} needs degrees and factors.`;if(n.deg.length<1)return`The ${e} correction of ${r} needs at least one angle.`;if(n.deg.length!==n.factor.length)return`The ${e} correction of ${r} has ${n.factor.length} factors against ${n.deg.length} angles.`;if(!n.deg.every(St)||!n.factor.every(St))return`The ${e} correction of ${r} contains a value that is not a number.`;if(n.deg[0]<0)return`The ${e} correction of ${r} is against the absolute angle; it cannot start below zero.`;for(let o=1;o<n.deg.length;o++)if(!(n.deg[o]>n.deg[o-1]))return`The ${e} correction of ${r} must increase in angle (${n.deg[o-1]} then ${n.deg[o]}\xB0).`;if(n.factor.some(o=>o<0))return`The ${e} correction of ${r} has a negative factor.`}return null}function Wv(e,t){return t===void 0?null:!St(t.dCl)||!St(t.dBalance)||!St(t.dCd)?`The ${e} slopes must be numbers.`:!St(t.maxDeg)||!(t.maxDeg>0)?`The ${e} response needs a positive angle to be valid to.`:null}function Ji(e){if(!e||typeof e!="object")return"Not an aero model.";if(!St(e.area)||e.area<=0)return"The reference area must be a positive number of square metres.";if(e.kind==="map"){let t,r,n,o;if(e.frame==null){let i=rm("front ride-height",e.axes?.hFront);if(i)return i;let c=rm("rear ride-height",e.axes?.hRear);if(c)return c;[t,r,n,o]=[e.axes.hFront,e.axes.hRear,"front ride heights","rear ride heights"]}else if(e.frame?.kind==="pitch"){if(!St(e.frame.refX))return"The point the ride height is read at must be a number of millimetres aft of the front axle.";let i=rm("ride-height",e.axes?.h);if(i)return i;let c=rm("pitch",e.axes?.pitch,"\xB0","pitch");if(c)return c;let l=e.axes.pitch.find(u=>Math.abs(u)>=tm);if(l!==void 0)return`A pitch of ${l}\xB0 is not a car's attitude \u2014 is the axis a rake in millimetres? Pitch is in degrees.`;[t,r,n,o]=[e.axes.h,e.axes.pitch,"ride heights","pitches"]}else return`Unknown aero map frame "${e.frame.kind}".`;let a=t.length,s=r.length;for(let i of mo){let c=e[i];if(!Array.isArray(c)||c.length!==s)return`${i} has ${Array.isArray(c)?c.length:0} rows against ${s} ${o} \u2014 they must match.`;for(let l=0;l<s;l++){let u=c[l];if(!Array.isArray(u)||u.length!==a)return`${i} row ${l+1} has ${Array.isArray(u)?u.length:0} values against ${a} ${n}.`;if(!u.every(St))return`${i} contains a value that is not a number.`}}return Yv("yaw",e.attitude?.yaw)??Yv("roll",e.attitude?.roll)}if(e.kind==="sensitivity"){let t;if(e.frame==null)t=["hFront","hRear"];else if(e.frame?.kind==="pitch"){if(!St(e.frame.refX))return"The point the ride height is read at must be a number of millimetres aft of the front axle.";t=["h","pitch"]}else return`Unknown aero sensitivity frame "${e.frame.kind}".`;let r=e.ref,n=e.slope,o=e.range,a=s=>s==="pitch"?"\xB0":" mm";if(!r||!St(r[t[0]])||!St(r[t[1]]))return e.frame?"The reference ride height and pitch must be numbers.":"The reference ride heights must be numbers.";for(let s of mo){if(!e.at||!St(e.at[s]))return`${s} at the reference must be a number.`;let i=n?.[s];if(!i||!St(i[t[0]])||!St(i[t[1]]))return`The slopes of ${s} must be numbers.`}for(let s of t){let i=o?.[s],c=r[s];if(!i||!St(i[0])||!St(i[1]))return`The ${s} range must be two numbers.`;if(!(i[1]>i[0]))return`The ${s} range must run from low to high (${i[0]} to ${i[1]}${a(s)}).`;if(c<i[0]||c>i[1])return`The reference ${s} of ${c}${a(s)} lies outside its range ${i[0]}\u2013${i[1]}${a(s)}.`;if(s==="pitch"&&(Math.abs(i[0])>=tm||Math.abs(i[1])>=tm))return`A pitch range reaching ${Math.abs(i[0])>=tm?i[0]:i[1]}\xB0 is not a car's attitude. Pitch is in degrees.`}return Wv("yaw",e.attitude?.yaw)??Wv("roll",e.attitude?.roll)}return`Unknown aero model kind "${e.kind}".`}var jv=180/Math.PI;function hs(e,t,r,n){let o=(n-r)/t;return{h:r+e.refX*o,pitch:Math.atan(o)*jv}}function bs(e,t,r,n){let o=Math.tan(n/jv);return{hFront:r-e.refX*o,hRear:r+(t-e.refX)*o}}var L8=180/Math.PI,OI=["hFront","hRear"],VI=["h","pitch"],zh=e=>e?.kind==="pitch"?VI:OI,sr=(e,t)=>e[t],nm=(e,t)=>e[t],Kh=(e,t)=>({[e[0]]:t(e[0]),[e[1]]:t(e[1])});function BI(e){if(!(!e.yaw&&!e.roll))return{...e.yaw?{yaw:{...e.yaw}}:{},...e.roll?{roll:{...e.roll}}:{}}}function Yh(e){let t=zh(e.frame),r=e.balanceFront,n=e.cl*r,o=e.cl*(1-r),a=Kh(t,c=>sr(e.dCl,c)*r+e.cl*sr(e.dBalance,c)),s=Kh(t,c=>sr(e.dCl,c)*(1-r)-e.cl*sr(e.dBalance,c)),i=BI(e);return{kind:"sensitivity",name:e.name,area:e.area,...e.frame?{frame:{...e.frame}}:{},ref:{...e.ref},at:{clFront:n,clRear:o,cd:e.cd},slope:{clFront:a,clRear:s,cd:Kh(t,c=>sr(e.dCd,c))},range:{[t[0]]:[...nm(e.range,t[0])],[t[1]]:[...nm(e.range,t[1])]},provenance:{...e.provenance},...i?{attitude:i}:{}}}function om(e,t,r){let n=Math.min(Math.abs(r),t.maxDeg),o=e.clFront+e.clRear,a=o!==0?e.clFront/o:.5,s=o+t.dCl*n,i=a+t.dBalance*n,c=e.clFront!==0?s*i/e.clFront:1,l=e.clRear!==0?s*(1-i)/e.clRear:1,u=e.cd!==0?(e.cd+t.dCd*n)/e.cd:1;return{clFront:c,clRear:l,cd:u}}function Hh(e,t,r=11){let n=Array.from({length:r},(a,s)=>t.maxDeg*s/(r-1)),o=n.map(a=>om(e,t,a));return{clFront:{deg:[...n],factor:o.map(a=>a.clFront)},clRear:{deg:[...n],factor:o.map(a=>a.clRear)},cd:{deg:[...n],factor:o.map(a=>a.cd)}}}function Uv(e){if(!(!e.attitude?.yaw&&!e.attitude?.roll))return{...e.attitude.yaw?{yaw:Hh(e.at,e.attitude.yaw)}:{},...e.attitude.roll?{roll:Hh(e.at,e.attitude.roll)}:{}}}function Xv(e,t,r,n=0,o=0){let[a,s]=zh(e.frame),i=t-sr(e.ref,a),c=r-sr(e.ref,s),l={clFront:e.at.clFront+sr(e.slope.clFront,a)*i+sr(e.slope.clFront,s)*c,clRear:e.at.clRear+sr(e.slope.clRear,a)*i+sr(e.slope.clRear,s)*c,cd:e.at.cd+sr(e.slope.cd,a)*i+sr(e.slope.cd,s)*c},u=e.attitude?.yaw?om(e.at,e.attitude.yaw,n):{clFront:1,clRear:1,cd:1},m=e.attitude?.roll?om(e.at,e.attitude.roll,o):{clFront:1,clRear:1,cd:1};return{clFront:l.clFront*u.clFront*m.clFront,clRear:l.clRear*u.clRear*m.clRear,cd:l.cd*u.cd*m.cd}}function Wh(e){let[t,r]=zh(e.frame),n=[...nm(e.range,t)],o=[...nm(e.range,r)],a=i=>o.map(c=>n.map(l=>i(Xv(e,l,c)))),s=Uv(e);return{kind:"map",name:e.name,area:e.area,...e.frame?{frame:{...e.frame}}:{},axes:{[t]:n,[r]:o},clFront:a(i=>i.clFront),clRear:a(i=>i.clRear),cd:a(i=>i.cd),provenance:{...e.provenance},...s?{attitude:s}:{}}}var jh=180/Math.PI,qv=new WeakMap,Qv=new WeakMap,Uh=new WeakMap;function fo(e,t){let r=Qv.get(e);if(r)return r;let n=t?.wheelbase,o=n!==void 0?Uh.get(e)?.get(n):void 0;if(o)return o;let a=$I(e),s=a.map;if(!po(s)){let l=GI(e,a);return Qv.set(e,l),l}if(n===void 0||!Number.isFinite(n)||n<=0)throw new Error("A ride-height-and-pitch aero map is read with the car\u2019s wheelbase, and none was given.");let i=KI(e,a,s.frame,n),c=Uh.get(e);return c||(c=new Map,Uh.set(e,c)),c.set(n,i),i}function $I(e){let t=qv.get(e);if(t)return t;let r=Ji(e);if(r)throw new Error(r);let n=e.kind==="map"?e:Wh(e),{x:o,y:a}=fs(n),s=o.length,i=a.length,c=n.attitude?.yaw,l=n.attitude?.roll,u=!!(c||l),m={clFront:1,clRear:1,cd:1,clamped:!1},p=(y,x)=>{let R=Math.abs(x),v=y.clFront.deg[y.clFront.deg.length-1];return{clFront:ot(y.clFront.deg,y.clFront.factor,R),clRear:ot(y.clRear.deg,y.clRear.factor,R),cd:ot(y.cd.deg,y.cd.factor,R),clamped:R>v}},d=(y,x)=>{if(!u)return m;let R=c?p(c,y):m,v=l?p(l,x):m;return{clFront:R.clFront*v.clFront,clRear:R.clRear*v.clRear,cd:R.cd*v.cd,clamped:R.clamped||v.clamped}},f=(y,x,R=0,v=0)=>{let S=Go(o,y),A=Go(a,x),F=Math.min(S.i+1,s-1),w=Math.min(A.i+1,i-1),T=k=>{let C=k[A.i][S.i],P=k[A.i][F],L=k[w][S.i],E=k[w][F],_=C+S.t*(P-C),D=L+S.t*(E-L);return _+A.t*(D-_)},M=d(R,v);return{clFront:u?T(n.clFront)*M.clFront:T(n.clFront),clRear:u?T(n.clRear)*M.clRear:T(n.clRear),cd:u?T(n.cd)*M.cd:T(n.cd),clampedRide:S.clamped||A.clamped,clampedAttitude:M.clamped}},h={x:[o[0],o[s-1]],y:[a[0],a[i-1]]},b=(y,x,R=!1,v=0,S=0)=>{let A=d(v,S),F=Go(o,R?Math.min(Math.max(y,h.x[0]),h.x[1]):y),w=Go(a,R?Math.min(Math.max(x,h.y[0]),h.y[1]):x),T=Math.min(F.i+1,s-1),M=Math.min(w.i+1,i-1),k=T>F.i?o[T]-o[F.i]:0,C=M>w.i?a[M]-a[w.i]:0,P={};for(let L of mo){let E=n[L],_=E[w.i][F.i],D=E[w.i][T],I=E[M][F.i],N=E[M][T],O=F.clamped||k===0?0:((D-_)*(1-w.t)+(N-I)*w.t)/k,V=w.clamped||C===0?0:((I-_)*(1-F.t)+(N-D)*F.t)/C;P[L]=u?{x:O*A[L],y:V*A[L]}:{x:O,y:V}}return P},g={map:n,x:h.x,y:h.y,hasAttitude:u,factors:d,at:f,slopes:b};return qv.set(e,g),g}function GI(e,t){let r={x:t.x,y:t.y,at:t.at,toAxles:(o,a)=>({hFront:o,hRear:a}),fromAxles:(o,a)=>({x:o,y:a})},n=(o,a,s=!1,i=0,c=0)=>{let l=t.slopes(o,a,s,i,c),u={};for(let m of mo)u[m]={hFront:l[m].x,hRear:l[m].y};return u};return{model:e,map:t.map,area:t.map.area,grid:r,hasAttitude:t.hasAttitude,at:t.at,slopes:n,factors:t.factors}}function KI(e,t,r,n){let o=r.refX,a=o/n,s=(l,u,m=0,p=0)=>{let d=(u-l)/n;return t.at(l+o*d,Math.atan(d)*jh,m,p)},i=(l,u,m=!1,p=0,d=0)=>{let f=(u-l)/n,h=t.slopes(l+o*f,Math.atan(f)*jh,m,p,d),b=jh/(n*(1+f*f)),g={};for(let y of mo)g[y]={hFront:h[y].x*(1-a)-h[y].y*b,hRear:h[y].x*a+h[y].y*b};return g},c={frame:r,x:t.x,y:t.y,at:t.at,toAxles:(l,u)=>bs(r,n,l,u),fromAxles:(l,u)=>{let m=hs(r,n,l,u);return{x:m.h,y:m.pitch}}};return{model:e,map:t.map,area:t.map.area,grid:c,hasAttitude:t.hasAttitude,at:s,slopes:i,factors:t.factors}}function Xh(e){let t=e.clFront+e.clRear;return{cl:t,balanceFront:t!==0?e.clFront/t:.5}}var we=(e,t)=>e*t/100,Rt=e=>e/100,Zv={name:"Formula Student aero",area:1,cl:3,balanceFront:.45,cd:1.3,ref:{hFront:30,hRear:35},range:{hFront:[5,60],hRear:[10,70]},dCl:{hFront:we(3,-.4),hRear:we(3,.1)},dBalance:{hFront:Rt(-.3),hRear:Rt(.15)},dCd:{hFront:we(1.3,-.1),hRear:we(1.3,.05)},yaw:{dCl:we(3,-1),dBalance:Rt(-.3),dCd:we(1.3,.5),maxDeg:10},roll:{dCl:we(3,-.5),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for an undertray-and-wings Formula Student car, ride height, yaw and roll; not measured."},Jv={name:"Formula 1 aero",area:1.5,cl:3,balanceFront:.44,cd:.9,ref:{hFront:35,hRear:70},range:{hFront:[0,60],hRear:[20,100]},dCl:{hFront:we(3,-.3),hRear:we(3,-.15)},dBalance:{hFront:Rt(-.15),hRear:Rt(.15)},dCd:{hFront:we(.9,-.15),hRear:we(.9,-.05)},yaw:{dCl:we(3,-1.5),dBalance:Rt(.2),dCd:we(.9,.8),maxDeg:8},roll:{dCl:we(3,-1),dBalance:Rt(-.3),dCd:0,maxDeg:2},note:"Assumed class-level sensitivities for a ground-effect floor, ride height, yaw and roll; not measured."},ek={name:"GT car aero",area:2,cl:1.4,balanceFront:.42,cd:.42,ref:{hFront:55,hRear:75},range:{hFront:[10,90],hRear:[10,110]},dCl:{hFront:we(1.4,-.3),hRear:we(1.4,.05)},dBalance:{hFront:Rt(-.25),hRear:Rt(.15)},dCd:{hFront:we(.42,-.1),hRear:0},yaw:{dCl:we(1.4,-.8),dBalance:Rt(-.2),dCd:we(.42,.6),maxDeg:10},roll:{dCl:we(1.4,-.3),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for a splitter-and-wing GT car, ride height, yaw and roll; not measured."},tk={name:"Sports car aero",area:2.2,cl:-.1,balanceFront:.5,cd:.3,ref:{hFront:130,hRear:140},range:{hFront:[80,180],hRear:[100,200]},dCl:{hFront:-5e-4,hRear:0},dBalance:{hFront:0,hRear:0},dCd:{hFront:2e-4,hRear:0},yaw:{dCl:0,dBalance:0,dCd:we(.3,.5),maxDeg:10},note:"Assumed class-level sensitivities for a road car with no aero devices; not measured."},rk={name:"Cup car aero",area:2.1,cl:.45,balanceFront:.45,cd:.4,ref:{hFront:64,hRear:78},range:{hFront:[20,100],hRear:[30,120]},dCl:{hFront:we(.45,-.4),hRear:we(.45,.05)},dBalance:{hFront:Rt(-.25),hRear:Rt(.15)},dCd:{hFront:we(.4,-.1),hRear:0},yaw:{dCl:we(.45,-1.2),dBalance:Rt(-.2),dCd:we(.4,.6),maxDeg:10},roll:{dCl:we(.45,-.3),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for a splitter-and-wing cup hatchback, ride height, yaw and roll; not measured."},nk={name:"Stock car aero",area:2.2,cl:.6,balanceFront:.45,cd:.45,ref:{hFront:75,hRear:90},range:{hFront:[20,110],hRear:[30,130]},dCl:{hFront:we(.6,-.35),hRear:we(.6,.05)},dBalance:{hFront:Rt(-.25),hRear:Rt(.15)},dCd:{hFront:we(.45,-.1),hRear:0},yaw:{dCl:we(.6,-1),dBalance:Rt(-.2),dCd:we(.45,.6),maxDeg:10},roll:{dCl:we(.6,-.3),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for a splitter-and-spoiler stock car, ride height, yaw and roll; not measured."},ok={name:"Hill-climb prototype aero",area:1.2,cl:2.5,balanceFront:.42,cd:.9,ref:{hFront:45,hRear:55},range:{hFront:[10,80],hRear:[15,95]},dCl:{hFront:we(2.5,-.35),hRear:we(2.5,.05)},dBalance:{hFront:Rt(-.25),hRear:Rt(.15)},dCd:{hFront:we(.9,-.1),hRear:we(.9,.05)},yaw:{dCl:we(2.5,-1),dBalance:Rt(-.3),dCd:we(.9,.5),maxDeg:10},roll:{dCl:we(2.5,-.5),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for a winged sports prototype with a flat floor and diffuser, ride height, yaw and roll; not measured."},ak={name:"Race truck aero",area:6.2,cl:-.1,balanceFront:.6,cd:.65,ref:{hFront:240,hRear:240},range:{hFront:[190,290],hRear:[180,300]},dCl:{hFront:-5e-4,hRear:0},dBalance:{hFront:0,hRear:0},dCd:{hFront:2e-4,hRear:0},yaw:{dCl:0,dBalance:0,dCd:we(.65,.5),maxDeg:10},note:"Assumed class-level sensitivities for a cab-over race truck with a chin spoiler and deflectors, ride height and yaw; not measured."};function Tn(e){return Yh({name:e.name,area:e.area,cl:e.cl,balanceFront:e.balanceFront,cd:e.cd,ref:e.ref,range:e.range,dCl:e.dCl,dBalance:e.dBalance,dCd:e.dCd,...e.yaw?{yaw:e.yaw}:{},...e.roll?{roll:e.roll}:{},provenance:{source:"assumed",note:e.note}})}var qh=()=>Tn(Zv),Qh=()=>Tn(Jv),Zh=()=>Tn(ek),Jh=()=>Tn(tk),eb=()=>Tn(rk),tb=()=>Tn(nk),rb=()=>Tn(ok),nb=()=>Tn(ak);function Ko(e,t){let r=.5*e.rho*e.area*t*t,n=e.cl*r,o=e.cw*r,a=n*e.copLongFront;return{downforce:n,drag:o,downFront:a,downRear:n-a}}function am(e,t){let r=e.massTotal;if(!(r>0))return{front:0,rear:0};let n=Math.max(0,Math.min(1,e.frontMassFrac)),o=2*e.unsprungPerCorner,a=(s,i)=>i>0?Math.min(1,s/i):0;return{front:(t.sprungMass*n+o*a(t.rideRateFront,xt(e,"front")))/r,rear:(t.sprungMass*(1-n)+o*a(t.rideRateRear,xt(e,"rear")))/r}}function sm(e,t,r,n){let o=t.front*r+t.rear*n;return o===0?e:Math.max(Math.min(1,e),e-o)}function ob(e,t){return e.wheelbase>0?e.massTotal*t*9.81/e.wheelbase:0}function gs(e,t,r){let n=2*t.rideRateFront,o=2*t.rideRateRear;return!(n>0)||!(o>0)?0:Math.min(Gh(t.sprungMass,r,e.wheelbase),.5*n*o/(n+o))}function ec(e,t,r,n,o){let a=e.cgHeight,s=ob(e,r);if(n===0&&o===0&&s===0)return{height:a,forward:0,noseLoad:0,dropFront:0,dropRear:0};let i=am(e,t),c=2*t.rideRateFront,l=2*t.rideRateRear,u=a,m=0,p=0,d=0;for(let h=0;h<6;h++){d=gs(e,t,u);let b=n-s*u,g=o+s*u;if(d>0){let R=c*l-d*(c+l);m=(b*(l-d)-d*g)/R,p=(g*(c-d)-d*b)/R}else m=c>0?b/c:0,p=l>0?g/l:0;let y=sm(a,i,m,p),x=Math.abs(y-u);if(u=y,x<1e-9)break}let f=m-p;return{height:u,forward:e.wheelbase>0?u*f/e.wheelbase:0,noseLoad:d*f,dropFront:m,dropRear:p}}var ab={yawDeg:0,rollDeg:0},sk=1e-4,HI=40,ik=50;function ho(e,t,r=0){let n=e.aero?.model;if(!(!n||!fo(n,e).hasAttitude))return{yawDeg:r,rollDeg:Ge(e).rollGradient*t}}function ys(e,t){if(e.rideHeightFront!=null&&e.rideHeightRear!=null)return{hFront:e.rideHeightFront,hRear:e.rideHeightRear};let r=e.model,n=(a,s,i)=>{if(t!==void 0&&t>0)return bs(a,t,s,i);throw new Error("A ride-height-and-pitch aero model is read with the car\u2019s wheelbase, and none was given.")},o={hFront:0,hRear:0};if(r?.kind==="sensitivity")o=em(r)?n(r.frame,r.ref.h,r.ref.pitch):r.ref;else if(r){let{x:a,y:s}=fs(r),i=(a[0]+a[a.length-1])/2,c=(s[0]+s[s.length-1])/2;o=po(r)?n(r.frame,i,c):{hFront:i,hRear:c}}return{hFront:e.rideHeightFront??o.hFront,hRear:e.rideHeightRear??o.hRear}}var ck=new WeakMap;function Pn(e,t,r=0,n){let o=e.aero;if(!o?.model)return null;let a=ck.get(e);a||(a=new Map,ck.set(e,a));let s=n&&fo(o.model,e).hasAttitude?n:ab,i=s===ab?`${t}|${r}`:`${t}|${r}|${s.yawDeg.toFixed(3)}|${s.rollDeg.toFixed(3)}`,c=a.get(i);if(c)return c;let l=zI(e,o,t,r,s);return a.size>4096&&a.clear(),a.set(i,l),l}function zI(e,t,r,n,o){let a=fo(t.model,e),s=Ge(e),i=2*s.rideRateFront,c=2*s.rideRateRear,l=ys(t,e.wheelbase),u=.5*t.rho*r*r,m=a.area,p=e.wheelbase>0?t.copHeight/e.wheelbase:0,d=am(e,s),f=ob(e,n),h=(T,M)=>sm(e.cgHeight,d,l.hFront-T,l.hRear-M),b=(T,M)=>l.hFront-T-(l.hRear-M),g=(T,M)=>{let k=a.at(T,M,o.yawDeg,o.rollDeg),C=u*m*k.clFront,P=u*m*k.clRear,L=u*m*k.cd,E=L*p,_=h(T,M),D=f*_,I=gs(e,s,_)*b(T,M),N=C-D-E+I,O=P+D+E-I,V=T-l.hFront+(i>0?N/i:0),H=M-l.hRear+(c>0?O/c:0);return{c:k,downFront:C,downRear:P,drag:L,rF:V,rR:H,norm:Math.hypot(V,H)}},y=(T,M,k=!1)=>{let C=a.slopes(T,M,k,o.yawDeg,o.rollDeg),P=i>0?u*m/i:0,L=c>0?u*m/c:0;return[[P*(C.clFront.hFront-p*C.cd.hFront),P*(C.clFront.hRear-p*C.cd.hRear)],[L*(C.clRear.hFront+p*C.cd.hFront),L*(C.clRear.hRear+p*C.cd.hRear)]]},x=l.hFront,R=l.hRear,v=g(x,R),S=0;for(;v.norm>=sk&&S<HI;){S++;let T=y(x,R),M=i>0?f/i:0,k=c>0?f/c:0,C=gs(e,s,h(x,R)),P=i>0?C/i:0,L=c>0?C/c:0,E=1+T[0][0]-M*d.front-P,_=T[0][1]-M*d.rear+P,D=T[1][0]+k*d.front+L,I=1+T[1][1]+k*d.rear-L,N=E*I-_*D,O,V;Math.abs(N)>1e-9?(O=-(I*v.rF-_*v.rR)/N,V=-(-D*v.rF+E*v.rR)/N):(O=-.5*v.rF,V=-.5*v.rR);let H=Math.max(1,Math.abs(O)/ik,Math.abs(V)/ik);O/=H,V/=H;let U=1;for(let G=0;G<6;G++){let B=g(x+U*O,R+U*V);if(B.norm<=v.norm||G===5){x+=U*O,R+=U*V,v=B;break}U*=.5}}let A=y(x,R,!0),F=2+A[0][0]+A[1][1],w=(1+A[0][0])*(1+A[1][1])-A[0][1]*A[1][0];return{v:r,axG:n,hFront:x,hRear:R,cgHeight:h(x,R),cgForward:e.wheelbase>0?h(x,R)*b(x,R)/e.wheelbase:0,cgNoseLoad:gs(e,s,h(x,R))*b(x,R),clFront:v.c.clFront,clRear:v.c.clRear,cd:v.c.cd,area:m,downforce:v.downFront+v.downRear,drag:v.drag,downFront:v.downFront,downRear:v.downRear,gain:YI(A),stable:w>0&&F>0,converged:v.norm<sk,iterations:S,clampedRide:v.c.clampedRide,yawDeg:o.yawDeg,rollDeg:o.rollDeg,clampedAttitude:v.c.clampedAttitude}}function YI(e){let t=e[0][0]+e[1][1],r=e[0][0]*e[1][1]-e[0][1]*e[1][0],n=t*t-4*r;if(n>=0){let o=Math.sqrt(n);return Math.max(Math.abs((t+o)/2),Math.abs((t-o)/2))}return Math.sqrt(r)}function tc(e,t,r=0,n){let o=Pn(e,t,r,n);return o?{downforce:o.downforce,drag:o.drag,downFront:o.downFront,downRear:o.downRear}:e.aero?Ko(e.aero,t):{downforce:0,drag:0,downFront:0,downRear:0}}function WI(e,t,r,n){let o=Ko(t,r),a=Ge(e),s=ys(t,e.wheelbase),i=e.wheelbase>0?o.drag*t.copHeight/e.wheelbase:0,c=ec(e,a,n,o.downFront-i,o.downRear+i),l=o.downforce;return{v:r,axG:n,hFront:s.hFront-c.dropFront,hRear:s.hRear-c.dropRear,cgHeight:c.height,cgForward:c.forward,cgNoseLoad:c.noseLoad,clFront:t.cl*t.copLongFront,clRear:t.cl*(1-t.copLongFront),cd:t.cw,area:t.area,downforce:l,drag:o.drag,downFront:o.downFront,downRear:o.downRear,gain:0,stable:!0,converged:!0,iterations:0,clampedRide:!1,yawDeg:0,rollDeg:0,clampedAttitude:!1}}function sb(e,t,r=0,n){let o=Pn(e,t,r,n);return o||(e.aero?WI(e,e.aero,t,r):null)}function im(e,t=0,r=0,n,o){if(e.aero&&t>0){if(e.aero.model){let i=Pn(e,t,r,n);return{height:i.cgHeight,forward:i.cgForward,noseLoad:i.cgNoseLoad}}let a=Ko(e.aero,t),s=e.wheelbase>0?a.drag*e.aero.copHeight/e.wheelbase:0;return ec(e,o??Ge(e),r,a.downFront-s,a.downRear+s)}return r===0?{height:e.cgHeight,forward:0,noseLoad:0}:ec(e,o??Ge(e),r,0,0)}var lk=[0,1,0],ib=[0,0,1],ne=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],$=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Q=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],cb=e=>[-e[0],-e[1],-e[2]],Z=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],me=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],jI=e=>Z(e,e),Zr=e=>Math.sqrt(Z(e,e)),rc=(e,t)=>jI($(e,t)),Le=(e,t)=>Zr($(e,t)),ee=e=>{let t=Zr(e);return t<1e-12?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]},uk=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r];var Ln=(e,t,r)=>{let n=ee(r),o=$(e,t);return ne(t,Q(n,Z(o,n)))},mk=(e,t,r)=>Le(e,Ln(e,t,r));var XI=1e-6;function qI(e){if(e<XI){let n=e*e;return[1-n/6,.5-n/24]}let t=Math.sin(e),r=Math.cos(e);return[t/e,(1-r)/(e*e)]}function _t(e,t){let r=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(r<1e-14)return t;let[n,o]=qI(r),a=me(e,t),s=me(e,a);return ne(t,ne(Q(a,n),Q(s,o)))}function ir(e,t,r){let n=Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);if(n<1e-14)return e;let o=[t[0]/n,t[1]/n,t[2]/n];return _t(Q(o,r),e)}function Jr(e,t){let r=t.length,n=e.map(a=>a.slice()),o=t.slice();return pk(n,o,r,new Array(r).fill(0))}function dk(e,t,r){return pk(e,t,t.length,r)}function pk(e,t,r,n){let o=1/0,a=0;for(let s=0;s<r;s++){let i=s,c=Math.abs(e[s][s]);for(let u=s+1;u<r;u++){let m=Math.abs(e[u][s]);m>c&&(c=m,i=u)}if(c<1e-14){for(let u=0;u<r;u++)n[u]=NaN;return{x:n,condProxy:1/0,singular:!0}}if(o=Math.min(o,c),a=Math.max(a,c),i!==s){let u=e[s];e[s]=e[i],e[i]=u;let m=t[s];t[s]=t[i],t[i]=m}let l=e[s][s];for(let u=s+1;u<r;u++){let m=e[u][s]/l;if(m!==0){for(let p=s;p<r;p++)e[u][p]-=m*e[s][p];t[u]-=m*t[s]}}}for(let s=r-1;s>=0;s--){let i=t[s];for(let c=s+1;c<r;c++)i-=e[s][c]*n[c];n[s]=i/e[s][s]}return{x:n,condProxy:a/o,singular:!1}}var fk=e=>{let t=0;for(let r of e)t=Math.max(t,Math.abs(r));return t},hk=e=>{let t=0;for(let r of e)t+=r*r;return t},QI=Math.sqrt(Number.EPSILON);function bk(e,t,r={}){let n=r.maxIter??60,o=r.tol??1e-10,a=t.length,s=r.scales??new Array(a).fill(1),i=t.slice(),c=e(i),l=fk(c),u=hk(c),m=.001,p=1,d=c.length,f=Array.from({length:d},()=>new Array(a).fill(0)),h=Array.from({length:a},()=>new Array(a).fill(0)),b=Array.from({length:a},()=>new Array(a).fill(0)),g=new Array(a).fill(0),y=new Array(a).fill(0),x=new Array(a).fill(0),R=new Array(a).fill(0),v=new Array(a).fill(0);for(let S=0;S<n;S++){if(l<o)return{x:i,residualNorm:l,iterations:S,converged:!0,condProxy:p};for(let T=0;T<a;T++){let M=QI*Math.max(Math.abs(i[T]),s[T]);for(let C=0;C<a;C++)R[C]=i[C];R[T]+=M;let k=e(R);for(let C=0;C<d;C++)f[C][T]=(k[C]-c[C])/M}let A=0;for(let T=0;T<a;T++){for(let k=0;k<a;k++){let C=0;for(let P=0;P<d;P++)C+=f[P][T]*f[P][k];h[T][k]=C}let M=0;for(let k=0;k<d;k++)M+=f[k][T]*c[k];g[T]=M,A=Math.max(A,h[T][T])}let F=Math.max(A,1e-9),w=!1;for(let T=0;T<18;T++){let M=m*F;for(let C=0;C<a;C++){let P=h[C],L=b[C];for(let E=0;E<a;E++)L[E]=C===E?P[E]+M:P[E];y[C]=-g[C]}let k=dk(b,y,x);if(p=Math.max(p,k.condProxy),!k.singular){for(let L=0;L<a;L++)v[L]=i[L]+x[L];let C=e(v),P=hk(C);if(P<u){for(let L=0;L<a;L++)i[L]=v[L];c=C,u=P,l=fk(c),m=Math.max(m*.3,1e-12),w=!0;break}}m=Math.min(m*4,1e12)}if(!w)break}return{x:i,residualNorm:l,iterations:n,converged:l<o,condProxy:p}}function nc(e,t,r,n){let o=e*e+t*t,a=Math.sqrt(o);if(!(a>1e-12*n))return{c1:1,s1:0,c2:1,s2:0,margin:0,ok:!1,free:!0};let s=Math.abs(r),i=1-s/a;if(i<0){let l=r>=0?1:-1,u=l*e/a,m=l*t/a;return{c1:u,s1:m,c2:u,s2:m,margin:i,ok:i>=-1e-12,free:!1}}let c=Math.sqrt((a-s)*(a+s));return{c1:(e*r-t*c)/o,s1:(t*r+e*c)/o,c2:(e*r+t*c)/o,s2:(t*r-e*c)/o,margin:i,ok:!0,free:!1}}function lb(e,t){return[e[0]*t[0]-e[1]*t[1]-e[2]*t[2]-e[3]*t[3],e[0]*t[1]+e[1]*t[0]+e[2]*t[3]-e[3]*t[2],e[0]*t[2]-e[1]*t[3]+e[2]*t[0]+e[3]*t[1],e[0]*t[3]+e[1]*t[2]-e[2]*t[1]+e[3]*t[0]]}var gk=e=>[e[0],-e[1],-e[2],-e[3]];function xs(e,t){let[r,n,o,a]=e,s=2*(o*t[2]-a*t[1]),i=2*(a*t[0]-n*t[2]),c=2*(n*t[1]-o*t[0]);return[t[0]+r*s+(o*c-a*i),t[1]+r*i+(a*s-n*c),t[2]+r*c+(n*i-o*s)]}function cm(e,t){let r=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];if(1+r<1e-14){let o=Math.abs(e[0])<.6?[1,0,0]:[0,1,0],a=e[1]*o[2]-e[2]*o[1],s=e[2]*o[0]-e[0]*o[2],i=e[0]*o[1]-e[1]*o[0],c=Math.hypot(a,s,i);return[0,a/c,s/c,i/c]}let n=Math.sqrt(2*(1+r));return[(1+r)/n,(e[1]*t[2]-e[2]*t[1])/n,(e[2]*t[0]-e[0]*t[2])/n,(e[0]*t[1]-e[1]*t[0])/n]}function yk(e,t,r){let n,o;return t>=0?(n=Math.sqrt((1+t)/2),o=r/(2*n)):(o=(r>=0?1:-1)*Math.sqrt((1-t)/2),n=r/(2*o)),[n,o*e[0],o*e[1],o*e[2]]}function ub(e,t,r){let n=e[0],o=e[1],a=e[2],s=t[0],i=t[1],c=t[2],l=r[0],u=r[1],m=r[2],p=n+i+m;if(p>=n&&p>=i&&p>=m){let h=Math.sqrt(1+p),b=.5/h;return[.5*h,(c-u)*b,(l-a)*b,(o-s)*b]}if(n>=i&&n>=m){let h=Math.sqrt(1+n-i-m),b=.5/h;return[(c-u)*b,.5*h,(s+o)*b,(l+a)*b]}if(i>=m){let h=Math.sqrt(1-n+i-m),b=.5/h;return[(l-a)*b,(s+o)*b,.5*h,(u+c)*b]}let d=Math.sqrt(1-n-i+m),f=.5/d;return[(o-s)*f,(l+a)*f,(u+c)*f,.5*d]}function xk(e){let t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t===0)return[1,0,0,0];let r=Math.sin(t/2)/t;return[Math.cos(t/2),r*e[0],r*e[1],r*e[2]]}function Rk(e){let[t,r,n,o]=e;t<0&&(t=-t,r=-r,n=-n,o=-o);let a=Math.sqrt(r*r+n*n+o*o);if(a===0)return[0,0,0];let s=2*Math.atan2(a,t)/a;return[s*r,s*n,s*o]}function ZI(e){let t=Math.abs(e[0])<.6?[1,0,0]:[0,1,0],r=ee(me(e,t));return[r,me(e,r)]}function JI(e){let t=e.hardpoints,r=ee($(t.damperChassis,t.pushrodOuter)),[n,o]=ZI(r);return{top:t.damperChassis,lower0:t.pushrodOuter,axis0:r,e1:n,e2:o}}function mb(e){let t=e.hardpoints,r=t.wheelCenter,n=ee($(t.ucaRear,t.ucaFront)),o=$(t.uprightUpper,t.ucaFront),a=Z(o,n),s=$(o,Q(n,a)),i=Z(s,s),c=ee($(t.lcaRear,t.lcaFront)),l=$(t.uprightLower,t.lcaFront),u=rc(t.tieOuter,t.tieInner);return{c0:r,ucaFront:t.ucaFront,ucaDir:n,ubj0:t.uprightUpper,ubjAxial0:a,ubjRadius2:i,lcaFront:t.lcaFront,lcaDir:c,lbj0:t.uprightLower,lbjRel0:l,tro0:t.tieOuter,tieInner0:t.tieInner,tieLen2:u,rackAxis:ee(e.config.rackAxis),steerMovesRack:e.config.steerMode==="rack",ubjRadiusRef:Math.max(1,2*Math.sqrt(i)),tieLenRef:Math.max(1,2*Math.sqrt(u)),...e.config.layout==="mcpherson"?{strut:JI(e)}:{}}}function Mr(e,t,r){let n=[t[3],t[4],t[5]],o=[t[0],t[1],t[2]],a=$(r,e.c0);return ne(ne(_t(n,a),e.c0),o)}function db(e,t){return ne(e.lcaFront,ir(e.lbjRel0,e.lcaDir,t))}function Ho(e,t){return e.steerMovesRack?ne(e.tieInner0,Q(e.rackAxis,t)):e.tieInner0}function pb(e,t,r,n){let o=Mr(e,t,e.lbj0),a=db(e,r),s=o[0]-a[0],i=o[1]-a[1],c=o[2]-a[2],l,u;if(e.strut){let f=e.strut,h=[t[3],t[4],t[5]],b=$(f.top,Mr(e,t,f.lower0));l=Z(b,_t(h,f.e1)),u=Z(b,_t(h,f.e2))}else{let f=Mr(e,t,e.ubj0),h=$(f,e.ucaFront),b=Z(h,e.ucaDir),g=$(h,Q(e.ucaDir,b));l=b-e.ubjAxial0,u=(Z(g,g)-e.ubjRadius2)/e.ubjRadiusRef}let m=Mr(e,t,e.tro0),p=Ho(e,n),d=(rc(m,p)-e.tieLen2)/e.tieLenRef;return[s,i,c,l,u,d]}var oc=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]),lm=e=>{let t=oc(e);return[e[0]/t,e[1]/t,e[2]/t]},e2=(e,t)=>$(e,Q(t,Z(e,t))),fb=e=>lm(me(e,Math.abs(e[0])<.6?[1,0,0]:[0,1,0]));function t2(e,t){let r=e.ucaDir,n=ne(e.ucaFront,Q(r,e.ubjAxial0)),o=Math.sqrt(e.ubjRadius2),a=e2($(e.ubj0,e.ucaFront),r),s=oc(a)>1e-9?lm(a):fb(r),i=me(r,s),c=$(e.ubj0,e.lbj0),l=Z(c,c);if(!(l>1e-18))return"free";let u=$(n,t),m=Z(u,u),p=nc(2*o*Z(s,u),2*o*Z(i,u),l-m-o*o,2*o*Math.sqrt(m));if(p.free)return"free";let d=lm(c),f=(h,b)=>{let g=ne(n,ne(Q(s,o*h),Q(i,o*b))),y=lm($(g,t));return{q1:cm(d,y),k:y,margin:p.margin,ok:p.ok}};return p.margin>0?[f(p.c1,p.s1),f(p.c2,p.s2)]:[f(p.c1,p.s1)]}function r2(e,t,r){let n=t.axis0,o=ne(t.lower0,Q(n,Z($(e.lbj0,t.lower0),n))),a=$(o,e.lbj0),s=oc(a),i=s>1e-9?Q(a,1/s):fb(n),c=$(t.top,r),l=oc(c);if(!(l>1e-9))return"free";let u=Q(c,1/l),m=s/l,p=1-m,d=p>=0?Math.sqrt((1-m)*(1+m)):0,f=fb(u),h=b=>{let g=b*d,y=ne(Q(u,g),Q(f,Math.min(m,1))),x=$(Q(u,Math.min(m,1)),Q(f,g));return{q1:lb(ub(x,y,me(x,y)),gk(ub(i,n,me(i,n)))),k:u,margin:p,ok:p>=0}};return p>0?[h(1),h(-1)]:[h(1)]}function n2(e,t,r,n){let{k:o}=n,a=xs(n.q1,$(e.tro0,e.lbj0)),s=Z(a,o),i=$(a,Q(o,s)),c=oc(i);if(!(c>1e-9))return"free";let l=Q(i,1/c),u=me(o,l),m=ne(t,Q(o,s)),p=$(m,r),d=Z(p,p),f=nc(2*c*Z(p,l),2*c*Z(p,u),e.tieLen2-d-c*c,2*c*Math.sqrt(d));if(f.free)return"free";let h=(g,y)=>({q:lb(yk(o,g,y),n.q1)});return{roots:f.margin>0?[h(f.c1,f.s1),h(f.c2,f.s2)]:[h(f.c1,f.s1)],margin:f.margin,ok:f.ok}}function vk(e,t,r,n=[0,0,0,0,0,0]){let o=db(e,t),a=Ho(e,r),s=xk([n[3],n[4],n[5]]),i=h=>Math.abs(h[0]*s[0]+h[1]*s[1]+h[2]*s[2]+h[3]*s[3]),c=e.strut?r2(e,e.strut,o):t2(e,o);if(c==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let l=null,u=null;for(let h of c){let b=n2(e,o,a,h);if(b==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let g=Math.min(h.margin,b.margin),y=b.ok&&h.ok;for(let{q:x}of b.roots){let R=i(x);y&&(!l||R>l.near)&&(l={q:x,margin:g,near:R}),!y&&(!u||R>u.near)&&(u={q:x,margin:g,near:R})}}let{q:m,margin:p}=l??u,d=Rk(m),f=$($(o,e.c0),_t(d,$(e.lbj0,e.c0)));return{x:[f[0],f[1],f[2],d[0],d[1],d[2]],converged:l!==null,margin:p,free:!1}}function Mk(e){let t=ee($(e.rockerPivotB,e.rockerPivotA));return{pivotA:e.rockerPivotA,axis:t,rprRel0:$(e.rockerToPushrod,e.rockerPivotA),rdmRel0:$(e.rockerToDamper,e.rockerPivotA),damperChassis:e.damperChassis,rodLen2:rc(e.pushrodOuter,e.rockerToPushrod),damperLen0:Le(e.rockerToDamper,e.damperChassis)}}var o2=(e,t)=>ne(e.pivotA,ir(e.rprRel0,e.axis,t)),hb=(e,t)=>ne(e.pivotA,ir(e.rdmRel0,e.axis,t));function Rs(e,t){return{pushrod:o2(e,t),damper:hb(e,t)}}function Sk(e,t,r=0){let n=Z(e.rprRel0,e.axis),o=$(e.rprRel0,Q(e.axis,n)),a=me(e.axis,o),s=$(ne(e.pivotA,Q(e.axis,n)),t),i=Z(o,o),c=Z(s,s),l=nc(2*Z(s,o),2*Z(s,a),e.rodLen2-c-i,2*Math.sqrt(i*c));if(l.free){let d=Math.abs(e.rodLen2-c-i)<=1e-9*e.rodLen2;return{phi:r,damperLength:Le(hb(e,r),e.damperChassis),converged:d,margin:0}}let u=kk(Math.atan2(l.s1,l.c1),r),m=kk(Math.atan2(l.s2,l.c2),r),p=Math.abs(m-r)<Math.abs(u-r)?m:u;return{phi:p,damperLength:Le(hb(e,p),e.damperChassis),converged:l.ok,margin:l.margin}}function kk(e,t){let r=2*Math.PI;return e+r*Math.round((t-e)/r)}function Ak(e,t,r,n){return ne(t,_t(Q(ee(r),n),$(e,t)))}function wk(e,t,r,n){let o=ee(n),a=p=>{let d=$(p,r);return $(d,Q(o,Z(d,o)))},s=a(e),i=a(t),c=Math.hypot(s[0],s[1],s[2]),l=Math.hypot(i[0],i[1],i[2]);if(c<1e-9||l<1e-9)return 0;let u=Math.min(1,Math.max(-1,Z(s,i)/(c*l))),m=Z(me(s,i),o)/(c*l);return Math.atan2(m,u)}function Fk(e,t,r,n){return ne(t,_t(Q(ee(r),n),$(e,t)))}var um=180/Math.PI,a2=(e,t,r)=>Math.max(t,Math.min(r,e)),Ck=[NaN,NaN,NaN];function ac(e){let t=ee(e.spinAxis),r=ee($(e.uprightUpper,e.uprightLower)),n=-Math.asin(a2(t[2],-1,1))*um,o=Math.atan2(t[0],t[1])*um,a=Math.atan2(-r[0],r[2])*um,s=Math.atan2(-r[1],r[2])*um,i=ee(ne([0,0,-1],Q(t,t[2]))),c=ne(e.wheelCenter,Q(i,e.loadedRadius)),l=e.patchShift?[c[0]+e.patchShift.x,c[1]+e.patchShift.y,c[2]]:c,u=e.uprightLower,m=Math.abs(r[2])>1e-9,p=w=>ne(u,Q(r,(w-u[2])/r[2])),d=m?p(l[2]):Ck,f=m?p(e.wheelCenter[2]):Ck,h=l[1]-d[1],b=d[0]-l[0],g=ee(me(t,[0,0,1])),y=me([0,0,1],g),x=$(l,d),R=Z(x,y),v=-Z(x,g),S=e.wheelCenter[1]-f[1],A=f[0]-e.wheelCenter[0],F=mk(e.tieOuter,u,r);return{camber:n,toe:o,caster:a,kpi:s,scrubRadius:h,mechanicalTrail:b,scrubAtWheel:R,trailAtWheel:v,kingpinOffset:S,casterOffset:A,steeringArm:F,contactPatch:l,kingpinGround:d,kingpinAtHub:f}}function Tt(e){return{corner:e,inv:mb(e),rocker:Mk(e.hardpoints)}}var s2=[20,20,20,.2,.2,.2];function Pk(e,t,r,n=[0,0,0,0,0,0]){let o=vk(e,t,r,n);if(!o.free)return o;let a=i2(e,t,r,n);return{x:a.x,converged:a.converged,margin:0}}function i2(e,t,r,n=[0,0,0,0,0,0]){return bk(o=>pb(e,o,t,r),n,{scales:s2,tol:1e-10,maxIter:40})}var c2=.01,mm=1.2,zt=e=>e.ok?e.state:null,Nt=e=>e.ok?e.state:e.nearest;function Ce(e,t,r,n,o){let a=0,s=at(e,a,r,n,o);if(Math.abs(s.travel-t)<1e-4)return Tk(s,t,!1);let c=(at(e,.02,r,bb(s),o).travel-s.travel)/.02;(!Number.isFinite(c)||Math.abs(c)<1e-6)&&(c=1);let l=p=>Math.max(-mm,Math.min(mm,p)),u=l((t-s.travel)/c),m=at(e,u,r,bb(s),o);for(let p=0;p<12&&!(Math.abs(m.travel-t)<1e-4);p++){let d=m.travel-s.travel,f=Math.abs(d)<1e-9?u:u-(m.travel-t)*((u-a)/d);a=u,s=m,u=l(f),m=at(e,u,r,bb(s),o)}return Tk(m,t,Math.abs(u)===mm)}function Tk(e,t,r){let n=e.travel-t,o=Math.abs(n)<=c2,a=r&&!o;return e.converged&&o?{ok:!0,reached:!0,travelMiss:n,clamped:!1,state:e}:{ok:!1,why:e.converged?"unreached":"unconverged",reached:o,travelMiss:n,clamped:a,nearest:e}}function bb(e){return{q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle}}function l2(e,t,r,n,o){switch(e){case"upright":return Mr(t,r,o.pushrodOuter);case"upperArm":{let a=Mr(t,r,t.ubj0),s=wk(t.ubj0,a,t.ucaFront,t.ucaDir);return Fk(o.pushrodOuter,t.ucaFront,t.ucaDir,s)}default:return Ak(o.pushrodOuter,t.lcaFront,t.lcaDir,n)}}function at(e,t,r,n,o){let{inv:a,corner:s}=e,i=n?.q??[0,0,0,0,0,0],c=Pk(a,t,r,i),l=c.x,u=[l[3],l[4],l[5]],m={t:[l[0],l[1],l[2]],omega:u},p=s.hardpoints,d=s.config,f=a.strut,h=f?f.top:Mr(a,l,p.uprightUpper),b=Mr(a,l,p.uprightLower),g=Mr(a,l,p.tieOuter),y=Mr(a,l,p.wheelCenter),x=ee(_t(u,d.spinAxis)),R=l2(f?"upright":d.pushrodAttach,a,l,t,p),v=f?f.top:p.damperChassis,S=f||d.actuation==="direct"?{phi:0,damperLength:Le(R,v),converged:!0,margin:1}:Sk(e.rocker,R,n?.phi??0),A=ac({uprightUpper:h,uprightLower:b,wheelCenter:y,spinAxis:x,tieOuter:g,loadedRadius:o?.loadedRadius??d.loadedRadius,patchShift:o?.patchShift});return{pose:m,beta:t,travel:l[2],steer:r,points:{uprightUpper:h,uprightLower:b,tieOuter:g,wheelCenter:y,pushrodOuter:R,spinAxis:x,contactPatch:A.contactPatch,kingpinGround:A.kingpinGround,kingpinAtHub:A.kingpinAtHub,rockerAngle:S.phi,damperLength:S.damperLength},metrics:{camber:A.camber,toe:A.toe,caster:A.caster,kpi:A.kpi,scrubRadius:A.scrubRadius,mechanicalTrail:A.mechanicalTrail,scrubAtWheel:A.scrubAtWheel,trailAtWheel:A.trailAtWheel,kingpinOffset:A.kingpinOffset,casterOffset:A.casterOffset,steeringArm:A.steeringArm,damperLength:S.damperLength},converged:c.converged&&S.converged,margin:Math.min(c.margin,S.margin)}}var vs=e=>e==="FL"||e==="FR"?"front":"rear",Dk=e=>e==="FL"||e==="RL"?"left":"right";function Je(e,t){return e.corners?.[t]??u2(e[vs(t)],Dk(t))}function Ek(e){let t=e.config.springSplit;return e.config.actuation==="decoupled"||t===void 0||!Number.isFinite(t)||Math.abs(t)>=1?0:t}var Lk=new WeakMap;function u2(e,t){let r=Ek(e);if(r===0)return e;let n=Lk.get(e);if(!n){let o=a=>{let{springSplit:s,...i}=e.config;return{...e,config:{...i,springRate:e.config.springRate*a},...e.measured?{measured:{...e.measured,springRate:e.measured.springRate*a}}:{}}};n={left:o(1-r),right:o(1+r)},Lk.set(e,n)}return n[t]}var en=["FL","FR","RL","RR"],Qt=e=>2*e.hardpoints.wheelCenter[1],cr=(e,t)=>t?Qt(Je(e,"FL"))/2+Qt(Je(e,"FR"))/2:Qt(Je(e,"RL"))/2+Qt(Je(e,"RR"))/2;function Ue(e,t){let r=e==="FL"||e==="FR";return{axleX:r?t.frontAxleX:t.frontAxleX-t.wheelbase,sideSign:e==="FR"||e==="RR"?1:-1,isFront:r}}function st(e,t){return[t.axleX+e[0],t.sideSign*e[1],e[2]]}function Dn(e,t){return[e[0],t.sideSign*e[1],e[2]]}function bo(e){return e.frontAxleX-e.wheelbase/2}function gb(e,t,r){return t[2]+e.heave+(t[0]-r)*Math.sin(e.pitch)-t[1]*Math.sin(e.roll)}function go(e,t,r,n){let o=Ue(e,t),a=(n?cr(n,o.isFront):o.isFront?t.trackFront:t.trackRear)/2,s=o.sideSign*a,i=o.axleX-bo(t),c=-r.heave-i*Math.sin(r.pitch)+s*Math.sin(r.roll),l=o.isFront?o.sideSign*r.steer:0;return{travel:c,steer:l}}var m2={travelMin:-40,travelMax:40,steps:41,steer:0};function sc(e){return{q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle}}function ut(e,t={}){let r={...m2,...t},n=Tt(e);return ks(n,r)}function ks(e,t){let r=t.steer,n=.01,o=at(e,n,r),a=at(e,-n,r),s=(o.travel-a.travel)/(2*n);(!Number.isFinite(s)||Math.abs(s)<1e-6)&&(s=1);let i=Math.max(Math.abs(t.travelMax),Math.abs(t.travelMin)),c=Math.min(1.2,1.5*i/Math.abs(s)),l=Math.max(20,t.steps*2),u=[],m=at(e,0,r);u.push({beta:0,travel:m.travel,warm:sc(m),converged:m.converged});let p=sc(m);for(let x=1;x<=l;x++){let R=c*x/l,v=at(e,R,r,p);p=sc(v),u.push({beta:R,travel:v.travel,warm:p,converged:v.converged})}p=sc(m);for(let x=1;x<=l;x++){let R=-c*x/l,v=at(e,R,r,p);p=sc(v),u.push({beta:R,travel:v.travel,warm:p,converged:v.converged})}u.sort((x,R)=>x.beta-R.beta);let d=u[u.length-1].travel>=u[0].travel,f=!1;for(let x=1;x<u.length;x++){let R=u[x].travel-u[x-1].travel;(d&&R<-1e-6||!d&&R>1e-6)&&(f=!0)}let h=u.filter(x=>x.converged).map(x=>x.travel),b=h.length?[Math.min(...h),Math.max(...h)]:[0,0],g=h.length>0&&b[0]<=t.travelMin+1e-6&&b[1]>=t.travelMax-1e-6,y=[];for(let x=0;x<t.steps;x++){let R=t.steps===1?t.travelMin:t.travelMin+(t.travelMax-t.travelMin)*x/(t.steps-1),v=d2(u,R,d),S=p2(u,v);y.push(at(e,v,r,S))}return f2(y,e.corner.config.actuation==="decoupled"?0:e.corner.config.springRate),{samples:y,covered:g,reach:b,fold:f,unconverged:y.filter(x=>!x.converged).length}}function d2(e,t,r){let n=r?e.slice():e.slice().reverse();if(t<=n[0].travel)return n[0].beta;if(t>=n[n.length-1].travel)return n[n.length-1].beta;for(let o=1;o<n.length;o++){let a=n[o-1],s=n[o];if(t>=Math.min(a.travel,s.travel)&&t<=Math.max(a.travel,s.travel)){let i=s.travel-a.travel,c=Math.abs(i)<1e-9?0:(t-a.travel)/i;return a.beta+c*(s.beta-a.beta)}}return n[n.length-1].beta}function p2(e,t){let r=e[0],n=1/0;for(let o of e){let a=Math.abs(o.beta-t);a<n&&(n=a,r=o)}return r.warm}function yb(e,t,r){return r===0?(e[1]-e[0])/(t[1]-t[0]):r===e.length-1?(e[r]-e[r-1])/(t[r]-t[r-1]):(e[r+1]-e[r-1])/(t[r+1]-t[r-1])}function f2(e,t){if(e.length<2)return;let r=e.map(s=>s.travel),n=e.map(s=>s.metrics.camber),o=e.map(s=>s.metrics.toe),a=e.map(s=>s.metrics.damperLength);for(let s=0;s<e.length;s++){let i=yb(n,r,s),c=yb(o,r,s),l=-yb(a,r,s);e[s].metrics.camberGain=i,e[s].metrics.bumpSteer=c,e[s].metrics.motionRatio=l,e[s].metrics.wheelRate=t*l*l}}var dm=e=>e!==void 0&&Number.isFinite(e)&&e>0;function h2(e){return e&&dm(e.helperRate)&&dm(e.helperTravel)?{rate:e.helperRate,travel:e.helperTravel}:null}function xb(e,t,r){let n=t/e;return r?n+Math.min(t/r.rate,r.travel):n}function ic(e,t,r,n){if(!(e>0)||!Number.isFinite(e)||!(t>0)||!Number.isFinite(t))return null;let o=h2(n),a=-xb(e,t,o),s=Ms(r,n);return{rate:e,preload:t,helper:o,free:a,pull:null,droop:s.droop??a,droopStated:s.droop!==null,bump:s.bump,holdsLoad:!0}}function Ms(e,t){if(!Number.isFinite(e))return{droop:null,bump:null};let r=dm(t?.extended)&&t.extended>e?t.extended:null,n=r!==null&&dm(t?.stroke)?r-t.stroke:null;return{droop:r!==null?e-r:null,bump:n!==null&&n<e?e-n:null}}function Rb(e,t){if(!(e>0)||!Number.isFinite(e))return null;let r=Ms(t.length0,t.coilover),n=t.free===-1/0||t.pull!==null&&t.pull>=t.free;if(n&&r.droop===null&&r.bump===null)return null;let o=n?-1/0:t.free;return{rate:e,preload:o===-1/0?0:-e*o,helper:null,free:o,pull:n?null:t.pull,droop:r.droop??-1/0,droopStated:r.droop!==null,bump:r.bump,holdsLoad:!1}}function b2(e,t){let{rate:r,preload:n,helper:o}=e;if(!o)return t>e.free-1e-9?n+r*t:e.pull!==null&&t<e.pull+1e-9?r*(t-e.pull):0;let a=xb(r,n,o)+t;if(a<=0)return 0;let s=o.rate*o.travel;return a>=s/r+o.travel?n>=s?n+r*t:r*(a-o.travel):a*r*o.rate/(r+o.rate)}function g2(e,t){let{rate:r,preload:n,helper:o}=e;if(!o)return t>e.free-1e-9||e.pull!==null&&t<e.pull+1e-9?r:0;let a=xb(r,n,o)+t;return a<=0?0:a>=o.rate*o.travel/r+o.travel?r:r*o.rate/(r+o.rate)}function Ss(e,t){let r=b2(e,t),n=e.free;return e.holdsLoad&&t<n&&e.droop<n&&(r+=.001*e.rate*(Math.max(t,e.droop)-n)),t<e.droop&&(r+=1e3*e.rate*(t-e.droop)),e.bump!==null&&t>e.bump&&(r+=1e3*e.rate*(t-e.bump)),r}function vb(e,t){let r=g2(e,t),n=e.free;return e.holdsLoad&&t<n&&t>e.droop&&(r+=.001*e.rate),t<e.droop&&(r+=1e3*e.rate),e.bump!==null&&t>e.bump&&(r+=1e3*e.rate),r}function kb(e){let t=e.free,r=[t,e.droop];return e.helper&&r.push(e.helper.rate*e.helper.travel/e.rate+e.helper.travel+t),e.bump!==null&&r.push(e.bump),e.pull!==null&&r.push(e.pull),[...new Set(r.filter(Number.isFinite))].sort((n,o)=>n-o)}var pm={min:-60,max:60,steps:61},Mb=e=>({travel:[e.min,e.max],force:[0,0],motionRatio:[0,0],spring:null}),Ik=new WeakMap;function y2(e,t){let r=Ik.get(e.corner);r||Ik.set(e.corner,r=new Map);let n=`${t.min}|${t.max}|${t.steps}`,o=r.get(n);return o||r.set(n,o=ks(e,{travelMin:t.min,travelMax:t.max,steps:t.steps,steer:0})),o}function lc(e,t,r=pm,n=e.corner.config.coilover){let o=e.corner.config;if(o.actuation==="decoupled")return Mb(r);let a=y2(e,r),s=R2(e,o.springRate,a.samples),i=[];for(let h of a.samples){let b=h.metrics.motionRatio;!h.converged||b===void 0||!Number.isFinite(b)||!Number.isFinite(h.metrics.damperLength)||i.length>0&&h.travel<=i[i.length-1].t+1e-6||i.push({t:h.travel,L:h.metrics.damperLength,mr:b})}if(i.length<2)return Mb(r);let c=k2(i,0);if(!(Math.abs(c.mr)>1e-6))return Mb(r);let l=t/c.mr,u=ic(s,l,c.L,n),m=u?x2(i,kb(u).map(h=>c.L-h)):i,p=m.map(h=>(u?Ss(u,c.L-h.L):l+s*(c.L-h.L))*h.mr-t),d=h=>h===null?null:m.find(b=>b.L===c.L-h)?.t??null,f=u?kb(u).map(d).filter(h=>h!==null):[];return{travel:m.map(h=>h.t),force:p,motionRatio:m.map(h=>h.mr),spring:{rate:s,preload:l,length0:c.L,law:u},...u?{stops:{droop:d(u.droop),bump:d(u.bump)}}:{},...f.length?{kinks:f}:{},length:m.map(h=>h.L)}}function Sb(e,t){if(!e.spring)return null;let r=e.travel.length,n=e.length;if(n&&n.length===r&&r>=2){let s=tn(e.travel,t),i=(t-e.travel[s])/(e.travel[s+1]-e.travel[s]);return e.spring.length0-(n[s]+i*(n[s+1]-n[s]))}if(r<2)return 0;let o=64,a=0;for(let s=0;s<o;s++){let i=t*s/o,c=t*(s+1)/o;a+=(cc(e,i)+cc(e,c))/2*(c-i)}return a}function x2(e,t){let r=[...e];for(let n of t)for(let o=0;o+1<e.length;o++){let a=e[o],s=e[o+1];if(a.L===n)break;if((a.L-n)*(s.L-n)>=0)continue;let i=(n-a.L)/(s.L-a.L);r.push({t:a.t+i*(s.t-a.t),L:n,mr:a.mr+i*(s.mr-a.mr)});break}return r.sort((n,o)=>n.t-o.t),r.filter((n,o)=>o===0||n.t>r[o-1].t+1e-6)}function R2(e,t,r){let n=e.corner.compliance?.links?.pushRod;if(n===void 0||!(n>0)||!Number.isFinite(n)||!(t>0))return t;let o=e.corner.config.actuation==="direct"?n:v2(e,n,r);return!(o>0)||!Number.isFinite(o)?t:t*o/(t+o)}function v2(e,t,r){let n;for(let m of r)m.converged&&(!n||Math.abs(m.travel)<Math.abs(n.travel))&&(n=m);if(!n)return t;let o=e.corner.hardpoints,a=Rs(e.rocker,n.points.rockerAngle),s=ee($(o.rockerPivotB,o.rockerPivotA)),i=(m,p)=>Math.abs(Z(s,me($(m,o.rockerPivotA),ee($(p,m))))),c=i(a.pushrod,n.points.pushrodOuter),l=i(a.damper,o.damperChassis);if(!(l>1e-9)||!(c>1e-9))return t;let u=c/l;return t*u*u}function cc(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.motionRatio[0];let n=tn(e.travel,t),o=(t-e.travel[n])/(e.travel[n+1]-e.travel[n]);return e.motionRatio[n]+o*(e.motionRatio[n+1]-e.motionRatio[n])}function En(e,t,r){if(!e.spring)return Vr(e,t);let{rate:n,preload:o,length0:a,law:s}=e.spring,i=cc(e,0),c=a-r;return(s?Ss(s,c):o+n*c)*cc(e,t)-o*i}function k2(e,t){let r=tn(e.map(s=>s.t),t),n=e[r],o=e[r+1],a=(t-n.t)/(o.t-n.t);return{L:n.L+a*(o.L-n.L),mr:n.mr+a*(o.mr-n.mr)}}function tn(e,t){let r=e.length;if(t<=e[0])return 0;if(t>=e[r-1])return r-2;let n=0,o=r-1;for(;o-n>1;){let a=n+o>>1;e[a]<=t?n=a:o=a}return n}function Vr(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.force[0];let n=tn(e.travel,t),o=(t-e.travel[n])/(e.travel[n+1]-e.travel[n]);return e.force[n]+o*(e.force[n+1]-e.force[n])}function As(e,t){let r=e.travel.length;if(r<3)return uc(e,t);let n=tn(e.travel,t),o=(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n]),a=i=>i===0||i===r-1||e.kinks?.includes(e.travel[i])?o:(e.force[i+1]-e.force[i-1])/(e.travel[i+1]-e.travel[i-1]),s=Math.max(0,Math.min(1,(t-e.travel[n])/(e.travel[n+1]-e.travel[n])));return a(n)+s*(a(n+1)-a(n))}function uc(e,t){if(e.travel.length<2)return 0;let n=tn(e.travel,t);return(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n])}function Ne(e,t,r){let n=e.hardpoints;switch(t.attach){case"upright":{let o=$(t.outer,n.wheelCenter);return ne(ne(_t(r.pose.omega,o),n.wheelCenter),r.pose.t)}case"lowerArm":{let o=ee($(n.lcaRear,n.lcaFront));return ne(n.lcaFront,_t(Q(o,r.beta),$(t.outer,n.lcaFront)))}case"rocker":{let o=ee($(n.rockerPivotB,n.rockerPivotA));return ne(n.rockerPivotA,ir($(t.outer,n.rockerPivotA),o,r.points.rockerAngle))}}}function Br(e,t,r){return e.config.actuation==="decoupled"&&t.attach==="rocker"&&r==="coil"}function fm(e,t,r){return Br(e,t,r)?[t.inner[0],-t.inner[1],t.inner[2]]:t.inner}function zo(e,t,r){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return Ab(e,t,r.kind,ut(e,{travelMin:n,travelMax:o,steps:a}).samples)}function Ab(e,t,r,n){let o=ee($(t.outer,fm(e,t,r))),a=[],s=[],i=t.outer;for(let d of n)a.push(d.travel),s.push(Z($(Ne(e,t,d),i),o));let c=a.length,l=new Array(c).fill(0);for(let d=0;d<c;d++){let f=Math.max(0,d-1),h=Math.min(c-1,d+1),b=a[h]-a[f];l[d]=b!==0?(s[h]-s[f])/b:0}let u=l[0];for(let d=1;d<c;d++)if(a[d]>=0){let f=a[d]-a[d-1],h=f!==0?(0-a[d-1])/f:0;u=l[d-1]+h*(l[d]-l[d-1]);break}let m=l.filter(d=>Math.abs(d)>1e-9).map(Math.sign),p=m.length>0&&m.some(d=>d!==m[0]);return{travel:a,ratio:l,linkTravel:s,atDesign:u,reverses:p}}function wb(e,t){let{travel:r,ratio:n}=e,o=r.length;if(o===0)return 0;if(t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=0,s=o-1;for(;s-a>1;){let c=a+s>>1;r[c]<=t?a=c:s=c}let i=(t-r[a])/(r[s]-r[a]);return n[a]+i*(n[s]-n[a])}function Fb(e,t){let{travel:r,linkTravel:n}=e,o=r.length;if(o===0)return 0;if(t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=0,s=o-1;for(;s-a>1;){let c=a+s>>1;r[c]<=t?a=c:s=c}let i=(t-r[a])/(r[s]-r[a]);return n[a]+i*(n[s]-n[a])}var Yo=e=>e.mount??{kind:"rockerToRocker"},Vk=e=>[e[0],0,e[2]],M2=e=>2*Math.abs(e[1]),S2=(e,t)=>Math.hypot(e[0]-t[0],e[2]-t[2]);function bm(e,t){return t.kind==="chassis"?S2(e,t.anchor):M2(e)}function mc(e,t,r){if(r.kind==="chassis"){let s=[(e[0]+t[0])/2,(e[1]-t[1])/2,(e[2]+t[2])/2];return Math.hypot(s[0]-r.anchor[0],s[1],s[2]-r.anchor[2])}let n=e[0]-t[0],o=e[1]+t[1],a=e[2]-t[2];return Math.hypot(n,o,a)}function Wo(e,t,r={}){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return Cb(e,t,ut(e,{travelMin:n,travelMax:o,steps:a}).samples)}function Cb(e,t,r){let n=Yo(t),o=f=>Ne(e,{...t,inner:t.outer},r[f]),a=[],s=[],i=[];for(let f=0;f<r.length;f++)a.push(r[f].travel),i.push(bm(o(f),n));let c=Nk(a,i,0);for(let f of i)s.push(c-f);let l=a.length,u=new Array(l).fill(0);for(let f=0;f<l;f++){let h=Math.max(0,f-1),b=Math.min(l-1,f+1),g=a[b]-a[h];u[f]=g!==0?(s[b]-s[h])/g:0}let m=_k(a,20),p=_k(a,-20),d=mc(o(m),o(p),n);return{travel:a,ratio:u,springTravel:s,atDesign:Nk(a,u,0),installedLength:c,rollSensitivity:c-d}}function _k(e,t){let r=0,n=1/0;for(let o=0;o<e.length;o++){let a=Math.abs(e[o]-t);a<n&&(n=a,r=o)}return r}function Nk(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];for(let o=1;o<n;o++)if(e[o]>=r){let a=e[o]-e[o-1],s=a!==0?(r-e[o-1])/a:0;return t[o-1]+s*(t[o]-t[o-1])}return t[n-1]}function Tb(e,t,r){let n={outer:t.outer,attach:t.attach},o=ut(e,{travelMin:-5,travelMax:5,steps:3}),a=f=>Vk(Ne(e,{...n,inner:n.outer},o.samples[f])),s=a(1),i=a(2),c=a(0),l=i[0]-c[0],u=i[2]-c[2],m=Math.hypot(l,u),p=m>1e-9?[l/m,u/m]:[0,1],d=r??Math.max(80,2*Math.abs(t.outer[1])*.5);return[s[0]+p[0]*d,0,s[2]+p[1]*d]}function Pb(e,t){let r=e.hardpoints,n=r.rockerPivotA,o=Ok(hm(r.rockerPivotB,r.rockerPivotA)),a=Math.max(30,.6*Bk(hm(r.rockerToDamper,n))),s=hm(r.rockerToDamper,n),i=Ok(hm(s,A2(o,w2(s,o)))),c=F2(o,i),l=null,u=-1/0;for(let m=0;m<360;m+=10){let p=m*Math.PI/180,f={outer:[n[0]+a*(Math.cos(p)*i[0]+Math.sin(p)*c[0]),n[1]+a*(Math.cos(p)*i[1]+Math.sin(p)*c[1]),n[2]+a*(Math.cos(p)*i[2]+Math.sin(p)*c[2])],attach:"rocker"},h=t==="chassis"?{...f,mount:{kind:"chassis",anchor:Tb(e,f)}}:f,b;try{b=Wo(e,h,{travelMin:-20,travelMax:20,steps:9})}catch{continue}let g=b.atDesign/(1+4*Math.abs(b.rollSensitivity));Number.isFinite(g)&&g>u&&(u=g,l=h)}return l??{outer:r.rockerToDamper,attach:"rocker"}}var hm=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],A2=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],w2=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Bk=e=>Math.hypot(e[0],e[1],e[2]),Ok=e=>{let t=Bk(e)||1;return[e[0]/t,e[1]/t,e[2]/t]},F2=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]];var ym=.001,C2=e=>({outer:e.outer,inner:e.outer,attach:e.attach}),jk=(e,t,r)=>(bm(e.at0,t)-bm(r,t))/2,$k=(e,t)=>Z($(t,e.pickup.at0),e.axis);function xm(e,t){let r=e.length;return t.map((n,o)=>{let a=Math.max(0,o-1),s=Math.min(r-1,o+1);return(t[s]-t[a])/(e[s]-e[a])})}function Gk(e,t){let r=[0,1,2].map(n=>xm(e,t.map(o=>o[n])));return t.map((n,o)=>[r[0][o],r[1][o],r[2][o]])}function Eb(e){return{travel:e,heave:e.map(t=>t/2),heaveRatio:e.map(()=>.5),roll:[...e],rollRatio:e.map(()=>1)}}function Kk(e,t,r,n){let o=e.corner;if(!t.heave&&!t.roll&&!t.bar)return{side:Eb([n.min,n.max]),pickups:{}};let a=Nt(Ce(e,0,0)),s={};if(t.heave&&r){let b=C2(t.heave);s.heave={corner:o,link:b,at0:Ne(o,b,a)}}if(t.roll){let b=t.roll;s.roll={pickup:{corner:o,link:b,at0:Ne(o,b,a)},axis:ee($(b.outer,fm(o,b,t.rollKind??"coil")))}}if(t.bar){let b=t.bar.linkage;s.bar={pickup:{corner:o,link:b,at0:Ne(o,b,a)},axis:ee($(b.outer,fm(o,b,"ubar")))}}let i=t.roll&&Br(o,t.roll,t.rollKind??"coil")?{near:t.roll,far:{...t.roll,outer:t.roll.inner}}:null,c=ks(e,{travelMin:n.min,travelMax:n.max,steps:n.steps,steer:0}),l=[],u=[],m=[],p=[],d=[],f=[];for(let b of c.samples)!b.converged||l.length>0&&b.travel<=l[l.length-1]+1e-6||(l.push(b.travel),u.push(s.heave&&r?jk(s.heave,r,Ne(o,s.heave.link,b)):b.travel/2),m.push(s.roll?$k(s.roll,Ne(o,s.roll.pickup.link,b)):b.travel),s.bar&&p.push($k(s.bar,Ne(o,s.bar.pickup.link,b))),i&&(d.push(Ne(o,i.near,b)),f.push(Ne(o,i.far,b))));if(l.length<2)return{side:Eb([n.min,n.max]),pickups:{}};let h={travel:l,heave:u,heaveRatio:xm(l,u),roll:m,rollRatio:xm(l,m)};return s.bar&&(h.bar=p,h.barRatio=xm(l,p)),i&&(h.eyes={near:d,nearRatio:Gk(l,d),far:f,farRatio:Gk(l,f)}),{side:h,pickups:s}}function ws(e,t,r){let n=tn(e,r);return t[n]+(r-e[n])/(e[n+1]-e[n])*(t[n+1]-t[n])}function Lb(e,t,r){let n=tn(e,r);return(t[n+1]-t[n])/(e[n+1]-e[n])}function tt(e,t){let r=e.bar&&e.barRatio?{b:ws(e.travel,e.bar,t),db:ws(e.travel,e.barRatio,t),ddb:Lb(e.travel,e.barRatio,t)}:null;return{h:ws(e.travel,e.heave,t),dh:ws(e.travel,e.heaveRatio,t),ddh:Lb(e.travel,e.heaveRatio,t),r:ws(e.travel,e.roll,t),dr:ws(e.travel,e.rollRatio,t),ddr:Lb(e.travel,e.rollRatio,t),b:r?.b??0,db:r?.db??0,ddb:r?.ddb??0}}function Hk(e,t,r,n){let o=tn(e,n),a=e[o+1]-e[o],s=(n-e[o])/a,i=(u,m)=>[u[0]+s*(m[0]-u[0]),u[1]+s*(m[1]-u[1]),u[2]+s*(m[2]-u[2])],c=r[o],l=r[o+1];return{p:i(t[o],t[o+1]),d:i(c,l),dd:[(l[0]-c[0])/a,(l[1]-c[1])/a,(l[2]-c[2])/a]}}var Ib=(e,t)=>Math.hypot(e[0]-t[0],e[1]+t[1],e[2]-t[2]);function _b(e,t){let r=e.side[0].eyes,n=e.side[1].eyes;if(!r||!n)return null;let o=Hk(e.side[0].travel,r.near,r.nearRatio,t[0]),a=Hk(e.side[1].travel,n.far,n.farRatio,t[1]),s=[o.p[0]-a.p[0],o.p[1]+a.p[1],o.p[2]-a.p[2]],i=Math.hypot(s[0],s[1],s[2]),c=[s[0]/i,s[1]/i,s[2]/i],l=o.d,u=[-a.d[0],a.d[1],-a.d[2]],m=[-a.dd[0],a.dd[1],-a.dd[2]],p=Z(c,l),d=Z(c,u),f=(Z(l,u)-p*d)/i;return{L:i,dL:[p,d],ddL:[[(Z(l,l)-p*p)/i+Z(c,o.dd),f],[f,(Z(u,u)-d*d)/i+Z(c,m)]]}}var Uk=(e,t)=>e.bump!==null&&t>e.bump?e.rate*(t-e.bump):e.droop!==null&&t<e.droop?e.rate*(t-e.droop):0,T2=(e,t)=>e.bump!==null&&t>e.bump||e.droop!==null&&t<e.droop?e.rate:0;function dc(e,t,r,n,o=0){let a=e.rollStop;if(!a)return r;let s=_b(e,t);if(!s)return r;let i=Uk(a,a.length0-(n??s.L+o));return i===0?r:[r[0]-i*s.dL[0],r[1]-i*s.dL[1]]}function zk(e){if(!e.bar)return e;let{bar:t,barRatio:r,...n}=e;return n}function gm(e,t){let r=Eb(e.travel);return t==="heave"?{...e,heave:r.heave,heaveRatio:r.heaveRatio}:{...e,roll:r.roll,rollRatio:r.rollRatio}}var Fs=(e,t)=>e?e.law?Ss(e.law,t):e.preload+e.rate*t:0,Db=(e,t)=>e?e.law?vb(e.law,t):e.rate:0;function pc(e,t,r,n,o,a){let s=Fs(e.heave,n),i=Fs(e.roll,o),c=Fs(e.bar??null,a);return[s*t.dh+i*t.dr+c*t.db,s*r.dh-i*r.dr-c*r.db]}var Yk=(e,t)=>tt(e[0],t).h+tt(e[1],t).h;function P2(e,t){let r=e.gap>0?Yk(t,e.gap):0;return e.bothWays?{free:r,pull:e.gap>0?Yk(t,-e.gap):0}:{free:r,pull:null}}function L2(e,t,r){let n={...t,outer:t.inner},o=(u,m)=>{let p=zt(Ce(e[0],u,0)),d=zt(Ce(e[1],m,0));if(!p||!d)return NaN;let f=Ne(e[0].corner,t,p),h=Ne(e[1].corner,n,d);return Math.hypot(f[0]-h[0],f[1]+h[1],f[2]-h[2])},a=1,s=o(0,0),i=o(-a,a)-o(a,-a),c=tt(r[0],a).r-tt(r[1],-a).r-(tt(r[0],-a).r-tt(r[1],a).r),l=i/c;return Number.isFinite(s)&&s>0&&Number.isFinite(l)&&Math.abs(l)>ym?{length0:s,scale:l}:null}function Xk(e,t,r,n=pm){let o=r.heave?Yo(r.heave):void 0,a=Kk(e[0],r,o,n),s=e[1].corner===e[0].corner?a:Kk(e[1],r,o,n),i=[a.side,s.side],c=!!(a.pickups.heave&&s.pickups.heave),l=!!(a.pickups.roll&&s.pickups.roll),u=!!(a.pickups.bar&&s.pickups.bar&&a.side.bar&&s.side.bar),m=r.carriesLoad?void 0:r.heaveSeat,p=m?m.rate:(t[0].heaveRate+t[1].heaveRate)/2,d=(t[0].arbRate+t[1].arbRate)/2,f=i.map(N=>tt(N,0));c&&!(Math.abs(f[0].dh+f[1].dh)>ym)&&(i=[gm(i[0],"heave"),gm(i[1],"heave")],c=!1),l&&!(Math.abs(f[0].dr+f[1].dr)>ym)&&(i=[gm(i[0],"roll"),gm(i[1],"roll")],l=!1),u&&!(Math.abs(f[0].db+f[1].db)>ym)&&(u=!1),u||(i=[zk(i[0]),zk(i[1])]),f=i.map(N=>tt(N,0));let h=f[0].dh+f[1].dh,b=f[0].dr+f[1].dr,g=f[0].db+f[1].db,y=u&&r.bar?Math.max(0,r.bar.wheelRate):0,x=Math.max(0,d-y),R=p>0?2*p/(h*h):0,v=x>0?2*x/(b*b):0,S=y>0?2*y/(g*g):0,A=v+S*(g/b)**2,F=0,w=0,T=0;if(r.carriesLoad){let N=[t[0].springLoad,t[1].springLoad],O=0;if(R>0&&A>0){let H=-f[0].dh*f[1].dr-f[1].dh*f[0].dr;Math.abs(H)>1e-12&&(F=(-N[0]*f[1].dr-N[1]*f[0].dr)/H,O=(f[0].dh*N[1]-f[1].dh*N[0])/H)}else R>0?F=(N[0]+N[1])/h:A>0&&(O=(N[0]-N[1])/b);let V=A>0?v/A:1;w=V*O,S>0&&(T=(1-V)*O*(b/g))}let M={};if(c&&o){let N=[a.pickups.heave,s.pickups.heave];M.heave={pickups:N,mount:o,span0:mc(N[0].at0,N[1].at0,o)}}let k=M.heave?M.heave.span0:NaN,C=M.heave?r.coilover:void 0,P=r.carriesLoad?ic(R,F,k,C):m?Rb(R,{...P2(m,i),length0:k,coilover:C}):null,L=R>0?{rate:R,preload:F,...P?{law:P}:{}}:null;if(l&&(M.roll={pickups:[a.pickups.roll.pickup,s.pickups.roll.pickup],axes:[a.pickups.roll.axis,s.pickups.roll.axis]},r.roll&&Br(e[0].corner,r.roll,r.rollKind??"coil"))){let N=L2(e,r.roll,i);N&&(M.roll.unit=N)}let E=v>0?{rate:v,preload:w}:null,_={side:i,heave:L,roll:E,force0:[0,0],carriesLoad:r.carriesLoad,read:M};S>0&&(_.bar={rate:S,preload:T},M.bar={pickups:[a.pickups.bar.pickup,s.pickups.bar.pickup],axes:[a.pickups.bar.axis,s.pickups.bar.axis]});let D=M.roll?.unit,I=D&&A>0&&i[0].eyes&&i[1].eyes?Ms(D.length0,r.rollCoilover):null;return D&&I&&(I.droop!==null||I.bump!==null)&&(_.rollStop={length0:D.length0,rate:1e3*A/(D.scale*D.scale),...I}),_.force0=dc(_,[0,0],pc(_,f[0],f[1],f[0].h+f[1].h,f[0].r-f[1].r,f[0].b-f[1].b)),_}function fc(e,t,r){let n=tt(e.side[0],t[0]),o=tt(e.side[1],t[1]),a=r?dc(e,t,pc(e,n,o,n.h+o.h+r.heave,n.r-o.r+r.roll,n.b-o.b+(r.bar??0)),void 0,r.unit):dc(e,t,pc(e,n,o,n.h+o.h,n.r-o.r,n.b-o.b));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function Nb(e,t,r){let n=tt(e.side[0],t[0]),o=tt(e.side[1],t[1]),a=r?n.h+o.h+r.heave:n.h+o.h,s=r?n.r-o.r+r.roll:n.r-o.r,i=n.b-o.b+(r?.bar??0),c=Db(e.heave,a),l=Db(e.roll,s),u=Db(e.bar??null,i),m=Fs(e.heave,a),p=Fs(e.roll,s),d=Fs(e.bar??null,i),f=c*n.dh*o.dh-l*n.dr*o.dr-u*n.db*o.db,h=[[c*n.dh*n.dh+m*n.ddh+l*n.dr*n.dr+p*n.ddr+u*n.db*n.db+d*n.ddb,f],[f,c*o.dh*o.dh+m*o.ddh+l*o.dr*o.dr-p*o.ddr+u*o.db*o.db-d*o.ddb]],b=e.rollStop,g=b?_b(e,t):null;if(!b||!g)return h;let y=b.length0-(r?g.L+r.unit:g.L),x=T2(b,y);if(x===0)return h;let R=Uk(b,y),v=(A,F)=>x*g.dL[A]*g.dL[F]-R*g.ddL[A][F],S=f+v(0,1);return[[h[0][0]+v(0,0),S],[S,h[1][1]+v(1,1)]]}function Ob(e,t,r){let n=Nb(e,t);return n[r][0]+n[r][1]}function D2(e,t,r){let n=e.read.heave;if(!n)return tt(e.side[0],t[0]).h+tt(e.side[1],t[1]).h;let[o,a]=n.pickups;return n.span0-mc(Ne(o.corner,o.link,r[0]),Ne(a.corner,a.link,r[1]),n.mount)}function E2(e,t,r){let n=e.read.roll;if(!n)return tt(e.side[0],t[0]).r-tt(e.side[1],t[1]).r;let o=a=>Z($(Ne(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function I2(e,t,r){let n=e.read.bar;if(!n)return tt(e.side[0],t[0]).b-tt(e.side[1],t[1]).b;let o=a=>Z($(Ne(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function _2(e,t){let r=e.read.roll;if(!e.rollStop||!r)return;let[n,o]=r.pickups;return Ib(Ne(n.corner,n.link,t[0]),Ne(o.corner,{...o.link,outer:o.link.inner},t[1]))}function hc(e,t,r){let n=tt(e.side[0],t[0]),o=tt(e.side[1],t[1]),a=dc(e,t,pc(e,n,o,D2(e,t,r),E2(e,t,r),I2(e,t,r)),_2(e,r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function Vb(e,t,r,n){let o=tt(e.side[0],r),a=tt(e.side[1],r),s=e.read.heave,i=s?.pickups[t],c=s&&i&&n?2*jk(i,s.mount,Ne(i.corner,i.link,n)):o.h+a.h,l=e.rollStop&&n?e.read.roll?.pickups[t]:void 0,u=l&&n?Ib(Ne(l.corner,l.link,n),Ne(l.corner,{...l.link,outer:l.link.inner},n)):void 0;return dc(e,[r,r],pc(e,o,a,c,n?0:o.r-a.r,n?0:o.b-a.b),u)[t]-e.force0[t]}function Bb(e,t,r,n){let o=As(e,r[n]);return t?.carriesLoad?o+Ob(t,r,n):o}function qk(e,t){return tt(e.side[0],t[0]).h+tt(e.side[1],t[1]).h}function Qk(e,t){return _b(e,t)?.L??null}var $b=e=>e==="FR"||e==="RR"?1:0,Rm=(e,t)=>e.elements?.[t==="FL"||t==="FR"?"front":"rear"]??null;var Zk=e=>Number.isFinite(e)&&e>0?1/e:0;var Jk=(e,t)=>{let r=e[0][0]*e[1][1]-e[0][1]*e[1][0];return Math.abs(r)>1e-14?[(t[0]*e[1][1]-t[1]*e[0][1])/r,(e[0][0]*t[1]-e[1][0]*t[0])/r]:null},N2=(e,t)=>[e[0][0]*t[0]+e[0][1]*t[1],e[1][0]*t[0]+e[1][1]*t[1]],eM=1e-8,O2=40;function V2(e,t,r,n){return{force:(s,i)=>{if(r){let u=fc(r,s,n);return[Vr(t[0],s[0])+i[0]+u[0],Vr(t[1],s[1])+i[1]+u[1]]}let c=(s[0]+s[1])/2,l=(s[0]-s[1])/2;return[Vr(t[0],s[0])+i[0]+e[0].heaveRate*c+e[0].arbRate*l,Vr(t[1],s[1])+i[1]+e[1].heaveRate*c-e[1].arbRate*l]},stiffness:(s,i=uc)=>{if(r){let c=Nb(r,s,n);return[[i(t[0],s[0])+c[0][0],c[0][1]],[c[1][0],i(t[1],s[1])+c[1][1]]]}return[[i(t[0],s[0])+e[0].heaveRate/2+e[0].arbRate/2,e[0].heaveRate/2-e[0].arbRate/2],[e[1].heaveRate/2-e[1].arbRate/2,i(t[1],s[1])+e[1].heaveRate/2+e[1].arbRate/2]]}}}function Cs(e,t,r,n,o,a=[0,0],s=[0,0],i=null,c){let l=[Zk(r[0].tyreRate),Zk(r[1].tyreRate)],u=[r[0].staticLoad,r[1].staticLoad],m=V2(r,n,i,c),p=P=>m.force(P,a),d=m.stiffness([0,0]),f=[l[0]>0?l[0]:1/Math.max(1,Math.abs(d[0][0])),l[1]>0?l[1]:1/Math.max(1,Math.abs(d[1][1]))],h=(P,L)=>{let E=L===1?p(P):m.force(P,[a[0]*L,a[1]*L]),_=[E[0]+s[0]*L,E[1]+s[1]*L],D=[P[0]+t[0]*L+_[0]*l[0]-e[0]*L,P[1]+t[1]*L+_[1]*l[1]-e[1]*L],I=[f[0]*(u[0]+_[0]),f[1]*(u[1]+_[1])],N=[I[0]<D[0],I[1]<D[1]];return{f:_,on:D,off:I,lifted:N,r:[Math.min(D[0],I[0]),Math.min(D[1],I[1])]}},b=(P,L)=>[L[0]?[f[0]*P[0][0],f[0]*P[0][1]]:[1+P[0][0]*l[0],P[0][1]*l[0]],L[1]?[f[1]*P[1][0],f[1]*P[1][1]]:[P[1][0]*l[1],1+P[1][1]*l[1]]],g=P=>Math.max(Math.abs(P[0]),Math.abs(P[1])),y=(P,L)=>{let E=[P[0],P[1]],_=h(E,L),D=!1,I=0;for(;I<O2;I++){if(g(_.r)<eM){D=!0;break}let N=Jk(b(m.stiffness(E),_.lifted),[-_.r[0],-_.r[1]]);if(!N)break;let O=1,V=[E[0]+N[0],E[1]+N[1]],H=h(V,L);for(let U=0;U<8&&g(H.r)>g(_.r);U++)O/=2,V=[E[0]+O*N[0],E[1]+O*N[1]],H=h(V,L);E=V,_=H}return!D&&g(_.r)<eM&&(D=!0),{t:E,b:_,converged:D,it:I}},x=y(o?[o[0],o[1]]:[e[0]-t[0],e[1]-t[1]],1),R=x.it;if(!x.converged){let P=0,L=[0,0],E=.25;for(;P<1&&E>=1/256;){let _=Math.min(1,P+E),D=y(L,_);R+=D.it,D.converged?(P=_,L=D.t,_===1&&(x=D)):E/=2}}let{t:v,b:S,converged:A}=x,F=S.lifted,w=[F[0]?-u[0]:S.f[0],F[1]?-u[1]:S.f[1]],T=[F[0]?Math.max(0,S.on[0]):0,F[1]?Math.max(0,S.on[1]):0],M=m.stiffness(v,As),k=b(M,F);return{t:v,dF:w,lifted:F,clearance:T,converged:A,iterations:R,respond:(P,L,E=[0,0])=>{let _=[F[0]?-f[0]*E[0]:P[0]-L[0]-E[0]*l[0],F[1]?-f[1]*E[1]:P[1]-L[1]-E[1]*l[1]],D=Jk(k,_);if(!D)return[NaN,NaN];let I=N2(M,D);return[F[0]?0:I[0]+E[0],F[1]?0:I[1]+E[1]]}}}var jo=e=>!(Number.isFinite(e.tyreRate)&&e.tyreRate>0);function Sr(e,t,r){return t?.input.corners[r].staticLoadedRadius??e}var Gb=["FL","FR","RL","RR"],nM={front:["FL","FR"],rear:["RL","RR"]},B2=512,$2=5e-4,G2=8;function vm(e,t){let r={},n={},o=new Map;for(let s of Gb){let i=e.ctx[s],c=t.corners[s],l=c.staticLoadedRadius;n[s]=Nt(Ce(i,0,0,void 0,l===void 0?void 0:{loadedRadius:l})).points.contactPatch[2];let u=t.cornerCoilover?.[s==="FL"||s==="FR"?"front":"rear"],m=`${Gb.findIndex(d=>Je(e.vehicle,d)===Je(e.vehicle,s))}|${c.springLoad}|${u?`${u.extended}/${u.stroke}`:""}`,p=o.get(m);p?r[s]=p:(r[s]=u?lc(i,c.springLoad,void 0,u):lc(i,c.springLoad),o.set(m,r[s]))}let a={front:null,rear:null};for(let s of["front","rear"]){let i=t.elements?.[s];if(!i)continue;let c=nM[s];a[s]=Xk([e.ctx[c[0]],e.ctx[c[1]]],[t.corners[c[0]],t.corners[c[1]]],i)}return{input:t,curve:r,elements:a,ground0:n,memo:new Map}}function oM(e,t,r){if(!(r>0)||!Number.isFinite(r)||!Number.isFinite(t)||t<=0)return 0;let n=Math.min(t/r,e);return 2*Math.sqrt(Math.max(0,2*e*n-n*n))}var K2=e=>`${e.heave}|${e.pitch}|${e.roll}|${e.steer}`;function Kb(e,t,r){return{travel:r.travel,steer:r.steer,ground:r.travel,tyreDeflection:0,load:NaN,loadedRadius:Sr(Je(e.vehicle,t).config.loadedRadius,e.kc,t),lifted:!1,contactLength:0,converged:!0,rigid:!0,rideRate:NaN,wheelRateAtLoad:NaN}}var H2=e=>e?{q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle}:void 0;function tM(e,t,r,n){let o=nM[n],a=e.vehicle.config,s=o.map(w=>go(w,a,r,e.vehicle)),i=[t.input.corners[o[0]],t.input.corners[o[1]]],c=t.loadCase;if(!c&&i.every(jo))return{corners:[Kb(e,o[0],s[0]),Kb(e,o[1],s[1])],respond:null};let l=o.map(w=>t.curve[w]),u=t.elements?.[n]??null,m=o.map(w=>Sr(Je(e.vehicle,w).config.loadedRadius,t,w)),p=[s[0].travel+(c?.ground[o[0]]??0),s[1].travel+(c?.ground[o[1]]??0)],d=[c?.linkLoad[o[0]]??0,c?.linkLoad[o[1]]??0],f=[c?.patchShift[o[0]],c?.patchShift[o[1]]],h=[0,0],b=[0,0],g,y=Cs(p,h,i,l,void 0,void 0,d,u),x=[void 0,void 0],R=[!0,!0],v=[0,0],S=!1;for(let w=0;w<G2;w++){w>0&&(y=Cs(p,h,i,l,g,b,d,u)),v=[Number.isFinite(i[0].tyreRate)&&i[0].tyreRate>0?y.dF[0]/i[0].tyreRate:0,Number.isFinite(i[1].tyreRate)&&i[1].tyreRate>0?y.dF[1]/i[1].tyreRate:0];let T=[0,0],M=[0,0];for(let C=0;C<2;C++){let P=Ce(e.ctx[o[C]],y.t[C],s[C].steer,H2(x[C]),{loadedRadius:m[C]-v[C],patchShift:f[C]}),L=Nt(P);x[C]=L,R[C]=P.ok,T[C]=L.points.contactPatch[2]-t.ground0[o[C]]-y.t[C]-v[C],M[C]=En(l[C],y.t[C],L.points.damperLength)-Vr(l[C],y.t[C])}if(u){let C=hc(u,y.t,[x[0],x[1]]),P=fc(u,y.t);M[0]+=C[0]-P[0],M[1]+=C[1]-P[1]}let k=Math.max(Math.abs(T[0]-h[0]),Math.abs(T[1]-h[1]),Math.abs(M[0]-b[0])/Math.max(1,i[0].tyreRate),Math.abs(M[1]-b[1])/Math.max(1,i[1].tyreRate));if(h=T,b=M,g=y.t,k<$2){S=!0;break}}let A=y.respond([1,1],[0,0]);return{corners:[0,1].map(w=>{let T=x[w];return{travel:y.t[w],steer:s[w].steer,ground:p[w],tyreDeflection:v[w],load:i[w].staticLoad+y.dF[w],loadedRadius:m[w]-v[w],lifted:y.lifted[w],clearance:y.clearance[w],contactLength:oM(m[w]-v[w],i[w].staticLoad+y.dF[w],i[w].tyreRate),converged:y.converged&&S&&R[w],rigid:!1,state:T,solved:R[w],rideRate:A[w],wheelRateAtLoad:Bb(l[w],u,y.t,w)}}),respond:y.respond}}function aM(e,t){let r=e.kc,n=K2(t),o=r.memo.get(n);if(o)return o;let a=tM(e,r,t,"front"),s=tM(e,r,t,"rear"),i={corners:{FL:a.corners[0],FR:a.corners[1],RL:s.corners[0],RR:s.corners[1]},respond:{front:a.respond,rear:s.respond}};return r.memo.size>=B2&&r.memo.clear(),r.memo.set(n,i),i}function Zt(e,t){if(!e.kc){let r={};for(let n of Gb)r[n]=Kb(e,n,go(n,e.vehicle.config,t,e.vehicle));return r}return aM(e,t).corners}function km(e,t,r){return e.kc?aM(e,t).respond[r]:null}function bc(e,t,r,n=0){let o=e.kc;if(!o)return r;let a=o.input.corners[t];if(jo(a))return r;let s=go(t,e.vehicle.config,{heave:0,pitch:0,roll:0,steer:n},e.vehicle).steer,i=Sr(Je(e.vehicle,t).config.loadedRadius,o,t),c=o.loadCase,l=c?.linkLoad[t]??0,u=c?.patchShift[t],m=Nt(Ce(e.ctx[t],r,s,void 0,{loadedRadius:i,patchShift:u})),p=Rm(o,t),d=En(o.curve[t],r,m.points.damperLength)+(p?Vb(p,$b(t),r,m):a.heaveRate*r),h=Math.max(d+l,-a.staticLoad)/a.tyreRate;return(h===0?m:Nt(Ce(e.ctx[t],r,s,void 0,{loadedRadius:i-h,patchShift:u}))).points.contactPatch[2]-o.ground0[t]-(c?.ground[t]??0)}var z2=180/Math.PI,Y2=[0,0,1];function W2(e,t){let r=Dn(e,t),n=Q(me(Y2,r),-t.sideSign);return-Math.atan2(n[1],n[0])*z2}var sM=e=>1/Math.tan(e*Math.PI/180),iM=.05,cM=.001;function lM(e,t,r){if(!Number.isFinite(e)||!Number.isFinite(t))return NaN;if(!(Math.abs(e)<cM&&Math.abs(t)<cM))return e>0&&t>0?100*(sM(t)-sM(e))/r:NaN}function j2(e,t){let r=cr(e.vehicle,!0)/e.vehicle.config.wheelbase,n=t("FL",0).deg,o=t("FR",0).deg,a=(c,l)=>{let u=c+l>=0;return{left:u,inner:u?c:-l,outer:u?l:-c}},s,i=()=>{if(s===void 0){let c=[iM,-iM].map(l=>{let{inner:u,outer:m}=a(t("FL",l).deg-n,t("FR",l).deg-o);return lM(u,m,r)??NaN});s=(c[0]+c[1])/2}return s};return c=>{let l=t("FL",c),u=t("FR",c),{left:m,inner:p,outer:d}=a(l.deg-n,u.deg-o),f=lM(p,d,r);return{steerL:l.deg,steerR:u.deg,inner:p,outer:d,toeDiff:p-d,ackermannPct:f??i(),inside:f===void 0?null:m?"left":"right",converged:l.ok&&u.ok}}}function Hb(e,t){let r=e.vehicle.config,n={FL:Ue("FL",r),FR:Ue("FR",r)},o=t.travel??0,a=j2(e,(i,c)=>{let l=zt(Ce(e.ctx[i],o,n[i].sideSign*c));return{deg:l?W2(l.points.spinAxis,n[i]):NaN,ok:l!==null}}),s=[];for(let i=0;i<t.steps;i++){let c=t.steps===1?0:-t.steerMax+2*t.steerMax*i/(t.steps-1),{inside:l,...u}=a(c);s.push({steerInput:c,...u})}return s}var uM=35,mM=55,Ot=e=>e.rackTravel&&e.rackTravel>0?e.rackTravel:uM,zb=e=>e.rackRatio&&e.rackRatio>0?e.rackRatio:mM;var Yb=e=>({q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle});function dM(e,t,r,n,o){let a=Ce(e,n,0,void 0,o),s=Nt(a),i=a.ok?0:1,c=s.points.contactPatch[2],l={steer:s.metrics.toe,camber:s.metrics.camber,lift:0,contactPatch:s.points.contactPatch,spinAxis:s.points.spinAxis,yaw:-s.metrics.toe*Math.PI/180},u=d=>{let f=[l],h=Yb(s);for(let b=1;b<=r;b++){let g=d*(t*b)/r,y=at(e,s.beta,g,h,o),x=zt(Ce(e,n,g,Yb(y),o));if(!x||!y.converged){i++,f.push({...f[f.length-1]});continue}f.push({steer:x.metrics.toe,camber:x.metrics.camber,lift:-(y.points.contactPatch[2]-c),contactPatch:y.points.contactPatch,spinAxis:y.points.spinAxis,yaw:-y.metrics.toe*Math.PI/180}),h=Yb(y)}return f},m=u(1),p=u(-1);return{travelMm:n,unsolved:i,centre:l,positive:m,negative:p}}function U2(e,t){return e.map((r,n)=>{let o=n===0?0:n-1,a=n===e.length-1?e.length-1:n+1,s=t[a]-t[o];if(!(s>0))return{longitudinal:0,lateral:0,vertical:0,yaw:0};let i=Q($(e[a].contactPatch,e[o].contactPatch),1/s),c=ee(me(r.spinAxis,[0,0,1])),l=me([0,0,1],c);return{longitudinal:Z(i,c),lateral:Z(i,l),vertical:i[2],yaw:(e[a].yaw-e[o].yaw)/s}})}function pM(e,t,r){let n=o=>({steerDeg:o.map(a=>Math.abs(a.steer-e.centre.steer)),camberDeg:o.map(a=>a.camber-e.centre.camber),liftMm:o.map(a=>a.lift),jacobian:U2(o,t)});return{travelMm:e.travelMm,inner:n(r?e.positive:e.negative),outer:n(r?e.negative:e.positive)}}function X2(e){return e.positive[1].steer-e.centre.steer<0}function q2(e,t,r){return{meanDeg:t.map((n,o)=>.5*(r.inner.steerDeg[o]+r.outer.steerDeg[o])),innerDeg:r.inner.steerDeg,outerDeg:r.outer.steerDeg,innerCamber:r.inner.camberDeg,outerCamber:r.outer.camberDeg,innerLift:r.inner.liftMm,outerLift:r.outer.liftMm,rackRatioMmPerRev:zb(e.config),innerJacobian:r.inner.jacobian,outerJacobian:r.outer.jacobian}}function Wb(e,t,r=13,n=-40,o=40,a=5,s){let i=Tt(e),c=Array.from({length:r+1},(b,g)=>t*g/r),l=dM(i,t,r,0,s),u=X2(l),m=pM(l,c,u),p=Math.max(2,Math.floor(a)),d=Array.from({length:p},(b,g)=>n+(o-n)*g/(p-1));d.some(b=>Math.abs(b)<1e-9)||d.push(0),d.sort((b,g)=>b-g);let f=l.unsolved,h=d.map(b=>{if(Math.abs(b)<1e-9)return m;let g=dM(i,t,r,b,s);return f+=g.unsolved,pM(g,c,u)});return{...q2(e,c,m),...fM(l.unsolved),travelSurface:{rackMm:c,rows:h,...fM(f)}}}var fM=e=>e>0?{unsolved:e}:{};function rn(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function Mm(e,t,r){let n=e.length;if(n===0)return{longitudinal:0,lateral:0,vertical:0,yaw:0};let o,a;if(r<=e[0])o=a=0;else if(r>=e[n-1])o=a=n-1;else for(o=0,a=n-1;a-o>1;){let l=o+a>>1;e[l]<=r?o=l:a=l}let s=t[o];if(o===a)return{longitudinal:s.longitudinal,lateral:s.lateral,vertical:s.vertical,yaw:s.yaw};let i=t[a],c=(r-e[o])/(e[a]-e[o]);return{longitudinal:s.longitudinal+c*(i.longitudinal-s.longitudinal),lateral:s.lateral+c*(i.lateral-s.lateral),vertical:s.vertical+c*(i.vertical-s.vertical),yaw:s.yaw+c*(i.yaw-s.yaw)}}function hM(e,t){let r=e.rows;if(r.length<=1||t<=r[0].travelMm)return{lo:0,hi:0,t:0};let n=r.length-1;if(t>=r[n].travelMm)return{lo:n,hi:n,t:0};let o=0,a=n;for(;a-o>1;){let s=o+a>>1;r[s].travelMm<=t?o=s:a=s}return{lo:o,hi:a,t:(t-r[o].travelMm)/(r[a].travelMm-r[o].travelMm)}}var Uo=(e,t,r)=>e+r*(t-e);function Ts(e,t,r,n,o){let a=rn(e.rackMm,e.rows[n.lo][t][r],o);if(n.lo===n.hi)return a;let s=rn(e.rackMm,e.rows[n.hi][t][r],o);return Uo(a,s,n.t)}function bM(e,t,r,n){let o=Mm(e.rackMm,e.rows[r.lo][t].jacobian,n);if(r.lo===r.hi)return o;let a=Mm(e.rackMm,e.rows[r.hi][t].jacobian,n);return{longitudinal:Uo(o.longitudinal,a.longitudinal,r.t),lateral:Uo(o.lateral,a.lateral,r.t),vertical:Uo(o.vertical,a.vertical,r.t),yaw:Uo(o.yaw,a.yaw,r.t)}}function Ps(e,t,r,n){let o=e.travelSurface;if(!o||o.rackMm.length<2||o.rows.length===0)return Ls(e,t);let a=hM(o,r),s=hM(o,n),i=(d,f,h)=>{let b=o.rows[f.lo][d].steerDeg[h];return f.lo===f.hi?b:Uo(b,o.rows[f.hi][d].steerDeg[h],f.t)},c=new Array(o.rackMm.length);for(let d=0;d<c.length;d++)c[d]=.5*(i("inner",a,d)+i("outer",s,d));let l=Math.max(0,t),u=c.length-1,m=o.rackMm[u],p=l>c[u];if(l<=c[0])m=o.rackMm[0],p=!1;else if(!p){let d=1;for(;d<c.length-1&&c[d]<l;)d++;let f=d-1,h=c[d]-c[f],b=Math.abs(h)>1e-12?(l-c[f])/h:0;m=Uo(o.rackMm[f],o.rackMm[d],b)}return{innerDeg:Ts(o,"inner","steerDeg",a,m),outerDeg:Ts(o,"outer","steerDeg",s,m),innerCamber:Ts(o,"inner","camberDeg",a,m),outerCamber:Ts(o,"outer","camberDeg",s,m),innerLift:Ts(o,"inner","liftMm",a,m),outerLift:Ts(o,"outer","liftMm",s,m),innerJacobian:bM(o,"inner",a,m),outerJacobian:bM(o,"outer",s,m),atLock:p}}function Ls(e,t){let r=e.meanDeg.length-1;return{innerDeg:rn(e.meanDeg,e.innerDeg,t),outerDeg:rn(e.meanDeg,e.outerDeg,t),innerCamber:rn(e.meanDeg,e.innerCamber,t),outerCamber:rn(e.meanDeg,e.outerCamber,t),innerLift:e.innerLift?rn(e.meanDeg,e.innerLift,t):0,outerLift:e.outerLift?rn(e.meanDeg,e.outerLift,t):0,...e.innerJacobian&&e.outerJacobian?{innerJacobian:Mm(e.meanDeg,e.innerJacobian,t),outerJacobian:Mm(e.meanDeg,e.outerJacobian,t)}:{},atLock:r>=0&&t>e.meanDeg[r]}}var Q2=()=>({lift:{FL:0,FR:0,RL:0,RR:0},travel:{FL:0,FR:0,RL:0,RR:0},load:{FL:0,FR:0,RL:0,RR:0},rollDeg:0});function Ds(e,t,r=Ge(e),n){let o=e.steerFront;if(!o?.innerLift||!o.outerLift||o.meanDeg.length<2||Math.abs(t)<1e-12)return Q2();let a=Math.abs(t),s=t>0,i=n&&o.travelSurface?Ps(o,a,s?n.FL:n.FR,s?n.FR:n.FL):null,c=i?.innerLift??rn(o.meanDeg,o.innerLift,a),l=i?.outerLift??rn(o.meanDeg,o.outerLift,a),u=s?c:l,m=s?l:c,p=.5*(u+m),d=r.rollWheelRateFront,f=r.rollWheelRateRear,h=e.trackFront,b=e.trackRear,g=d*h*h+f*b*b,y=Z2(e,d,f,h,b);if(y){let v=(m-u)/h,S=v/(1/y.front+1/y.rear+1/y.chassis),A=v-S/y.front,F=S/y.rear,w={FL:u-p+.5*h*A,FR:m-p-.5*h*A,RL:.5*b*F,RR:-.5*b*F},T=Math.max(0,Math.min(1,e.frontMassFrac)),M=k=>-Math.atan(k)*180/Math.PI;return{lift:{FL:u,FR:m,RL:0,RR:0},travel:w,load:{FL:d*w.FL,FR:d*w.FR,RL:f*w.RL,RR:f*w.RR},rollDeg:M(T*A+(1-T)*F),ends:{front:M(A),rear:M(F)}}}let x=g>0?d*h*(m-u)/g:0,R={FL:u-p+.5*h*x,FR:m-p-.5*h*x,RL:.5*b*x,RR:-.5*b*x};return{lift:{FL:u,FR:m,RL:0,RR:0},travel:R,load:{FL:d*R.FL,FR:d*R.FR,RL:f*R.RL,RR:f*R.RR},rollDeg:x===0?0:-Math.atan(x)*180/Math.PI}}function Z2(e,t,r,n,o){let a=e.chassisTorsion??0,s=.5*t*n*n,i=.5*r*o*o;return!(a>0)||!Number.isFinite(a)||!(s>0)||!(i>0)?null:{front:s,rear:i,chassis:a*1e3*180/Math.PI}}function jb(e,t,r){let n=t/r,o=a=>1/Math.tan(a*Math.PI/180);for(let a=0;a<e.meanDeg.length;a++)if(e.outerDeg[a]>.3&&e.innerDeg[a]>.3)return 100*(o(e.outerDeg[a])-o(e.innerDeg[a]))/n;return NaN}var gc=9.81;function Es(e,t,r=0,n=0,o=0){if(!e.aero||t<=0)return{FL:0,FR:0,RL:0,RR:0};let a=e.aero.model?Pn(e,t,r,ho(e,n,o)):Ko(e.aero,t),s=a.downFront/2,i=a.downRear/2,c=a.drag*(e.aero.copHeight/1e3)/(e.wheelbase/1e3)/2;return{FL:s-c,FR:s-c,RL:i+c,RR:i+c}}function Ub(e,t,r=0,n=0,o=0){if(!e.aero?.model||t<=0)return!1;let a=Pn(e,t,r,ho(e,n,o));return a!=null&&(a.clampedRide||a.clampedAttitude)}function Xo(e){let t=e.loadFactor===void 0?e.massTotal*gc:e.massTotal*gc*e.loadFactor,r=t*e.frontMassFrac,n=t*(1-e.frontMassFrac);return{FL:r/2,FR:r/2,RL:n/2,RR:n/2}}function gM(e,t=Ge(e),r=e.cgHeight){let n=e.trackFront/1e3,o=e.trackRear/1e3,a=e.rcHeightFront/1e3,s=e.rcHeightRear/1e3,i=(e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac))/1e3,c=r/1e3-i,l=2*e.unsprungPerCorner,u=e.unsprungCgHeight/1e3,m=t.sprungMass*c*Ju(t.sprungMass,c,t.rollRateTotal),p=(m*t.frontElasticShare+t.sprungFront*a+l*u)/n,d=(m*(1-t.frontElasticShare)+t.sprungRear*s+l*u)/o;return{cf:p,cr:d}}function yc(e){let{cf:t,cr:r}=gM(e);return t+r>0?t/(t+r):.5}var yM=e=>1-e.frontMassFrac;function xM(e,t,r,n=e.cgHeight){return n-(t+(r-t)*yM(e))}function RM(e,t){if(!Number.isFinite(t.rcFront)||!Number.isFinite(t.rcRear)||!Number.isFinite(t.arm))return NaN;let r=t.arm+t.rcFront+(t.rcRear-t.rcFront)*yM(e);return yc({...e,rcHeightFront:t.rcFront,rcHeightRear:t.rcRear,cgHeight:r})}function vM(e,t,r){if(e.FL>=0&&e.FR>=0&&e.RL>=0&&e.RR>=0)return{loads:{FL:Math.max(0,e.FL),FR:Math.max(0,e.FR),RL:Math.max(0,e.RL),RR:Math.max(0,e.RR)},lifted:{FL:!1,FR:!1,RL:!1,RR:!1},overturned:!1};let n=e.FL+e.FR+e.RL+e.RR;if(!(n>0))return{loads:{FL:0,FR:0,RL:0,RR:0},lifted:{FL:!0,FR:!0,RL:!0,RR:!0},overturned:!0};let o=!1,a=e.FL+e.FR,s=e.RL+e.RR;a<0?(a=0,s=n,o=!0):s<0&&(s=0,a=n,o=!0);let i=(e.FR-e.FL)*t+(e.RR-e.RL)*r,c=Math.min(a,Math.max(-a,e.FR-e.FL)),l=Math.min(s,Math.max(-s,e.RR-e.RL)),u=i-(c*t+l*r);if(u!==0){let p=u>0?1:-1,d=(p*a-c)*t;p*u>=p*d?(c=p*a,u-=d):(c+=u/t,u=0);let f=(p*s-l)*r;u!==0&&(p*u>=p*f?(l=p*s,u-=f):(l+=u/r,u=0)),Math.abs(u)>1e-9*(Math.abs(i)+n*(t+r))&&(o=!0)}let m={FL:Math.max(0,(a-c)/2),FR:Math.max(0,(a+c)/2),RL:Math.max(0,(s-l)/2),RR:Math.max(0,(s+l)/2)};return{loads:m,lifted:{FL:m.FL===0,FR:m.FR===0,RL:m.RL===0,RR:m.RR===0},overturned:o}}function Xe(e,t,r,n=0,o=0,a=0,s,i){return Sm(e,t,r,n,o,a,s,i).loads}function Sm(e,t,r,n=0,o=0,a=0,s,i){let c=Xo(e),l=Ge(e),u=im(e,n,r,ho(e,t,o),l),{cf:m,cr:p}=gM(e,l,u.height),d=m*t*gc,f=p*t*gc,h=e.massTotal*(r*gc)*u.height/e.wheelbase-u.noseLoad,b=Es(e,n,r,t,o),g=(i??Ds(e,a,l,s)).load,y={FL:c.FL-d-h/2+b.FL+g.FL,FR:c.FR+d-h/2+b.FR+g.FR,RL:c.RL-f+h/2+b.RL+g.RL,RR:c.RR+f+h/2+b.RR+g.RR};return vM(y,e.trackFront,e.trackRear)}var Xb=Math.PI/180;function wm(e,t){let r=8*Xb,n=0,o=0;for(let a=1;a<=90;a++){let s=a*.5,i=Math.abs(e.Fy(s*Xb,t,0));if(i>n&&(n=i,r=s*Xb,o=a),a>o+12&&i<.995*n)break}return{aPeak:r,fyPeak:n}}function kM(e,t,r,n,o){if(n===t)return r;let a=(o-t)/(n-t);return a<=0?e:a>=1?r:e+a*(r-e)}var Rc=.999;function lr(e,t,r,n,o){if(t<=0)return 0;let{aPeak:a,fyPeak:s}=o??wm(e,t),i=Math.min(Math.abs(r),Rc*s),c=n?-1:1,l=(v,S)=>Math.abs(e.forces({Fz:t,kappa:c*v,alpha:S}).Fy),u=.3,m=u,p=l(u,a);if(p<i){let v=0,S=u,A=NaN,F=p;for(let w=0;w<9;w++){let T=.5*(v+S),M=l(T,a);M>=i?(v=T,A=M):(S=T,F=M)}Number.isNaN(A)&&(A=l(0,a)),m=A<i?0:kM(v,A,S,F,i)}if(m<=0)return 0;let d=v=>{if(i===0)return c*e.forces({Fz:t,kappa:c*v,alpha:0}).Fx;let S=0,A=a,F=NaN,w=NaN;for(let T=0;T<5;T++){let M=.5*(S+A),k=l(v,M);k<i?(S=M,F=k):(A=M,w=k)}return Number.isNaN(F)&&(F=l(v,0)),Number.isNaN(w)&&(w=l(v,a)),c*e.forces({Fz:t,kappa:c*v,alpha:kM(S,F,A,w,i)}).Fx},f=4,h=v=>m*v/f,b=[0],g=1;for(let v=1;v<=f;v++)b.push(d(h(v))),b[v]>b[g]&&(g=v);let[y,x]=g===f?[f-1,f-2]:b[g-1]>=b[g+1]?[g-1,g+1]:[g+1,g-1],R=r_(d,h(g-1),h(Math.min(f,g+1)),h(g),b[g],h(y),b[y],h(x),b[x],J2);return c*Math.max(0,R)}var J2=.01,e_=20,t_=(3-Math.sqrt(5))/2;function r_(e,t,r,n,o,a,s,i,c,l){o=-o,s=-s,c=-c;let u=r-t,m=0;for(let p=0;p<e_;p++){let d=l*Math.abs(n)+1e-10,f=.5*(t+r);if(Math.abs(n-f)<=2*d-.5*(r-t))break;let h=!0;if(Math.abs(u)>d){let y=(n-a)*(o-c),x=(n-i)*(o-s),R=(n-i)*x-(n-a)*y;x=2*(x-y),x>0&&(R=-R),x=Math.abs(x);let v=u;if(u=m,Math.abs(R)<Math.abs(.5*x*v)&&R>x*(t-n)&&R<x*(r-n)){m=R/x;let S=n+m;(S-t<2*d||r-S<2*d)&&(m=f>=n?d:-d),h=!1}}h&&(u=n>=f?t-n:r-n,m=t_*u);let b=Math.abs(m)>=d?n+m:n+(m>=0?d:-d),g=-e(b);g<=o?(b>=n?t=n:r=n,i=a,c=s,a=n,s=o,n=b,o=g):(b<n?t=b:r=b,g<=s||a===n?(i=a,c=s,a=b,s=g):(g<=c||i===n||i===a)&&(i=b,c=g))}return-o}function Zb(e,t,r){if(!(r<1))return 0;let n=Math.max(0,r);return wM(o=>Math.hypot(o,n)/e.reach(t,o,n)-1)}function AM(e,t,r){let n=Math.max(0,r);return wM(o=>Math.hypot(n,o)/e.reach(t,n,o)-1)}function wM(e){let t=0,r=1,n=e(t),o=e(r);if(!(n<0))return 0;if(!(o>0))return 1;let a=0;for(let s=0;s<60;s++){let i=(t*o-r*n)/(o-n),c=e(i);if(Math.abs(c)<1e-12||r-t<1e-12)return i;c>0?(r=i,o=c,a===-1&&(n/=2),a=-1):(t=i,n=c,a===1&&(o/=2),a=1)}return t-n*(r-t)/(o-n)}function Jb(e,t){return e.model?.kind==="simple"?null:FM(e,t)}var MM=new WeakMap,qb=100,SM=1.35,Qb=18,nn=41,Am=41,xc=65;function FM(e,t){let r=MM.get(e);if(r)return r;let n=Math.log(SM),o=(d,f)=>{let h=A=>Math.abs(lr(e,d,A,f)),b=h(0),g=t.muY(d)*d,y=new Float64Array(nn),x=b>0&&g>0?Math.max(1,t.muX(d)*d/b):1;if(!(b>0)||!(g>0))y.fill(1);else{let A=[],F=[];for(let T=0;T<Am;T++){let M=Math.sin(.5*Math.PI*T/(Am-1));A.push(M),F.push(T===0?1:T===Am-1?0:Math.min(F[T-1],h(M*g)/b))}let w=Am-1;for(let T=0;T<nn;T++){let M=T/(nn-1);for(;w>0&&F[w-1]<M;)w--;let k=w>0?F[w-1]-F[w]:0;y[T]=w===0?A[0]:A[w]+(k>0?(M-F[w])/k:0)*(A[w-1]-A[w])}y[0]=1,y[nn-1]=0}let R=new Float64Array(xc),v=A=>Math.atan2(y[A],A/(nn-1)/x),S=nn-2;for(let A=0;A<xc;A++){let F=.5*Math.PI*A/(xc-1),w=Math.cos(F),T=Math.sin(F);for(;S>0&&v(S)<F;)S--;let M=S/(nn-1)/x,k=y[S],C=(S+1)/(nn-1)/x,P=y[S+1],L=w*(P-k)-T*(C-M),E=Math.abs(L)>1e-12?(M*(P-k)-k*(C-M))/L:Math.hypot(M,k);R[A]=E>0?E:Math.hypot(M,k)}return{room:y,scale:x,edge:R}},a=Array.from({length:Qb},(d,f)=>qb*SM**f),s=a.map(d=>o(d,!1)),i=a.map(d=>o(d,!0)),c=(d,f)=>{let h=Math.min(1,Math.abs(f)*d.scale)*(nn-1),b=Math.min(nn-2,Math.floor(h));return d.room[b]+(h-b)*(d.room[b+1]-d.room[b])},l=d=>{let f=d>qb?Math.log(d/qb)/n:0;if(f>=Qb-1)return[Qb-2,1];let h=Math.floor(f);return[h,f-h]},u=(d,f,h)=>{if(h===0)return 1;let b=h<0?i:s,g=c(b[d],h);return f>0?g+f*(c(b[d+1],h)-g):g},m=(d,f,h)=>{let b=f<0?i:s,[g,y]=l(d),x=Math.atan2(Math.abs(h),Math.abs(f))/(.5*Math.PI)*(xc-1),R=Math.min(xc-2,Math.floor(x)),v=A=>A.edge[R]+(x-R)*(A.edge[R+1]-A.edge[R]),S=v(b[g]);return y>0?S+y*(v(b[g+1])-S):S},p={keeps(d,f){if(f===0)return 1;let[h,b]=l(d);return u(h,b,f)},atLoad(d){let[f,h]=l(d);return b=>u(f,h,b)},use(d,f,h){let b=Math.hypot(f,h);return b>0?Math.min(1,b/m(d,f,h)):0},reach:m};return MM.set(e,p),p}var n_=[["front","FL","FR"],["rear","RL","RR"]];function Is(e,t,r,n){let o={...e},a=0,s=Rc;for(let[i,c,l]of n_){let u=(R,v)=>n(i,Math.max(0,v[R])).fyPeak,m=Math.min(s,e[c]),p=Math.min(s,e[l]),d=m*u(c,r)+p*u(l,r);if(!(d>0))continue;let f=u(c,t),h=u(l,t),b=m*f+p*h,g=b>0?d/b:1/0,y=m*g,x=p*g;y<=s?x<=s||(x=s,y=f>0?(d-s*h)/f:1/0):(y=s,x=h>0?(d-s*f)/h:1/0),(!(y<=s)||!(x<=s))&&(a+=Math.max(0,d-s*(f+h)),y=Math.min(s,y),x=Math.min(s,x)),o[c]=y,o[l]=x}return{util:o,short:a}}var CM=.001,o_=1e-5,TM=100;function a_(e,t,r,n){if(!(n>CM))return r;let o=t,a=Math.abs(r-t)<TM?t+Math.sign(r-t)*TM:r;for(let s=0;s<60&&Math.abs(a-o)>o_;s++){let i=.5*(o+a);e(i)>CM?a=i:o=i}return o}function Fm(e,t,r){let n;return{at:o=>{if(n!==void 0)return r<0?Math.max(o,n):Math.min(o,n);if(!((o-t)*r>0))return o;let a=a_(e,t,o,e(o));return a!==o&&(n=a),a},edge:()=>n}}function Cm(e,t){let r=n=>{try{return Ce(e,0,n).ok}catch{return!1}};for(let n of[1,-1]){if(r(n*t))continue;let o=0;for(let a=1;a<=6;a++){let s=n*t*a/6;if(!r(s))break;o=Math.abs(s)}return{lock:t,reached:o,side:n}}return null}var eg=40;function Tm(e){return{violation:Math.max(0,e.lock-e.reached),reason:`the steering reaches only ${e.reached.toFixed(0)} mm of the ${e.lock.toFixed(0)} mm rack travel${e.side<0?" (other side)":""}`}}var PM=[0,0,0];function s_(e,t){let r=ee($(e.rockerPivotB,e.rockerPivotA)),n=ee($(e.rockerToPushrod,e.pushrodOuter)),o=ee($(e.damperChassis,e.rockerToDamper)),a=Math.abs(Z(r,me($(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(Z(r,me($(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}function Pm(e,t,r){if(e.mcpherson)return i_(e,t,r);let n=[{r:e.uprightUpper,c:e.ucaFront},{r:e.uprightUpper,c:e.ucaRear},{r:e.uprightLower,c:e.lcaFront},{r:e.uprightLower,c:e.lcaRear},{r:e.tieOuter,c:e.tieInner},{r:e.pushrodOuter,c:e.direct?e.damperChassis:e.rockerToPushrod}],o=e.wheelCenter,a=[[],[],[],[],[],[]];for(let m=0;m<6;m++){let p=ee($(n[m].c,n[m].r)),d=me($(n[m].r,o),p);a[0][m]=p[0],a[1][m]=p[1],a[2][m]=p[2],a[3][m]=d[0],a[4][m]=d[1],a[5][m]=d[2]}let s=me($(e.contactPatch,o),t),i=r??PM,c=[-t[0],-t[1],-t[2],-(s[0]+i[0]),-(s[1]+i[1]),-(s[2]+i[2])],l=Jr(a,c),u=l.x;return{ucaFront:u[0],ucaRear:u[1],lcaFront:u[2],lcaRear:u[3],tieRod:u[4],pushRod:u[5],damper:l.singular||e.decoupled?NaN:e.direct?u[5]:s_(e,u[5]),condProxy:l.condProxy,singular:l.singular}}function i_(e,t,r){let n=e.wheelCenter,o=e.damperChassis,a=[{at:e.uprightLower,dir:ee($(e.lcaFront,e.uprightLower))},{at:e.uprightLower,dir:ee($(e.lcaRear,e.uprightLower))},{at:e.tieOuter,dir:ee($(e.tieInner,e.tieOuter))},{at:o,dir:[1,0,0]},{at:o,dir:[0,1,0]},{at:o,dir:[0,0,1]}],s=[[],[],[],[],[],[]];for(let b=0;b<6;b++){let g=a[b].dir,y=me($(a[b].at,n),g);s[0][b]=g[0],s[1][b]=g[1],s[2][b]=g[2],s[3][b]=y[0],s[4][b]=y[1],s[5][b]=y[2]}let i=me($(e.contactPatch,n),t),c=r??PM,l=[-t[0],-t[1],-t[2],-(i[0]+c[0]),-(i[1]+c[1]),-(i[2]+c[2])],u=Jr(s,l),m=u.x,p=[m[3],m[4],m[5]],d=ee($(o,e.pushrodOuter)),f=Z(p,d),h=Math.hypot(p[0]-f*d[0],p[1]-f*d[1],p[2]-f*d[2]);return{ucaFront:NaN,ucaRear:NaN,lcaFront:m[0],lcaRear:m[1],tieRod:m[2],pushRod:u.singular?NaN:f,damper:u.singular?NaN:f,condProxy:u.condProxy,singular:u.singular,strutSide:u.singular?NaN:h,topMount:p}}function tg(e,t){let r=ee(e.spinAxis),n=me($(e.contactPatch,e.wheelCenter),t),o=Z(n,r);return[-o*r[0],-o*r[1],-o*r[2]]}var c_=[0,0,0];function vc(e,t,r,n){let o=e.direct?e.damperChassis:e.rockerToPushrod;if(e.mcpherson)return{...Pm(e,r,n),armResidual:0};if(t==="upright")return{...Pm(e,r,n),armResidual:0};let a=t==="lowerArm",s=a?{bj:e.uprightUpper,front:e.ucaFront,rear:e.ucaRear}:{bj:e.uprightLower,front:e.lcaFront,rear:e.lcaRear},i=a?{bj:e.uprightLower,front:e.lcaFront,rear:e.lcaRear}:{bj:e.uprightUpper,front:e.ucaFront,rear:e.ucaRear},c=e.wheelCenter,l=ee($(s.front,s.bj)),u=ee($(s.rear,s.bj)),m=ee($(e.tieInner,e.tieOuter)),p=[{at:s.bj,dir:l},{at:s.bj,dir:u},{at:e.tieOuter,dir:m},{at:i.bj,dir:[1,0,0]},{at:i.bj,dir:[0,1,0]},{at:i.bj,dir:[0,0,1]}],d=[[],[],[],[],[],[]];for(let W=0;W<6;W++){let z=p[W].dir,Y=me($(p[W].at,c),z);d[0][W]=z[0],d[1][W]=z[1],d[2][W]=z[2],d[3][W]=Y[0],d[4][W]=Y[1],d[5][W]=Y[2]}let f=me($(e.contactPatch,c),r),h=n??c_,b=[-r[0],-r[1],-r[2],-(f[0]+h[0]),-(f[1]+h[1]),-(f[2]+h[2])],g=Jr(d,b),y=g.singular,x=g.x,R=x[0],v=x[1],S=x[2],A=[x[3],x[4],x[5]],F=ee($(i.rear,i.front)),w=ee($(o,e.pushrodOuter)),T=Q(A,-1),M=(W,z)=>Z(F,me($(W,i.front),z)),k=M(e.pushrodOuter,w),C=Math.abs(k)>1e-9?-M(i.bj,T)/k:NaN,P=ne(T,Q(w,C)),L=Q(P,-1),E=ee($(i.front,i.bj)),_=ee($(i.rear,i.bj)),D=Z(E,E),I=Z(E,_),N=Z(_,_),O=Z(E,L),V=Z(_,L),H=D*N-I*I,U=NaN,G=NaN,B=NaN;if(Math.abs(H)>1e-12){U=(O*N-V*I)/H,G=(D*V-I*O)/H;let W=ne(Q(E,U),Q(_,G)),z=$(L,W);B=Math.hypot(z[0],z[1],z[2])}let q=a?{f:R,r:v}:{f:U,r:G},re=a?{f:U,r:G}:{f:R,r:v};return{ucaFront:q.f,ucaRear:q.r,lcaFront:re.f,lcaRear:re.r,tieRod:S,pushRod:C,damper:y||!Number.isFinite(C)||e.decoupled?NaN:e.direct?C:l_(e,C),condProxy:g.condProxy,singular:y,armResidual:B}}function l_(e,t){let r=ee($(e.rockerPivotB,e.rockerPivotA)),n=ee($(e.rockerToPushrod,e.pushrodOuter)),o=ee($(e.damperChassis,e.rockerToDamper)),a=Math.abs(Z(r,me($(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(Z(r,me($(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}var oU=Math.PI/180;function kc(e,t){let r=Math.min(Math.max(t,e.range[0]),e.range[1])-e.reference;return Math.max(.2,1+e.perDegC*r+e.perDegC2*r*r)}var DM=["QSX3","QSX8","QSX13","QSX14"],u_=["QSX1"],Lm=["PHY1","PHY2","PHY3","PKY6","PKY7","PVY1","PVY2","PVY3","PVY4","PEY3","PEY4","QHZ1","QHZ2","QHZ3","QHZ4","QEZ4","QEZ5","QDZ6","QDZ7","QDZ8","QDZ9","QDZ10","QDZ11","SSZ1","SSZ3","SSZ4","RBY3","RHX1","RVY1","RVY2","RVY3",...DM],m_=["PKY6","PKY7","PVY3","PVY4","PHY3","PEY4","RVY3","QBZ4","QDZ3","QHZ3","QHZ4","QEZ5","QDZ8","QDZ9","QDZ10","QDZ11","SSZ3","SSZ4"];function d_(){let e=new Set(m_),t=Lm.filter(r=>!DM.includes(r));return[...t.filter(r=>!e.has(r)),...[...e].filter(r=>!t.includes(r)),...u_]}function p_(e,t){let r={...e};for(let n of t)r[n]!==void 0&&r[n]!==0&&(r[n]=-r[n]);return r}var In=(e,t,r)=>Number.isFinite(e[t])?e[t]:r;function EM(e,t){return t!=="5.2"?In(e,"PKY6",0)*In(e,"LKYC",1):In(e,"PKY1",-15)*Math.sin(In(e,"PKY4",2)*Math.atan(1/In(e,"PKY2",2)))*In(e,"LKY",1)*In(e,"PHY3",0)+In(e,"PVY3",0)*In(e,"LMUY",1)}var LM=.1;function IM(e){if(e.fitData)return"sae";let t=EM(e.coeffs,e.version);return t>LM?"sae":t<-LM?"iso":null}function Mc(e){return e.axisSystem??IM(e)??"sae"}function Dm(e){let t=new Set,r=n=>{for(let o of n)t.has(o)?t.delete(o):t.add(o)};return Mc(e)==="iso"&&r(Lm),e.axisSystem&&e.side==="left"&&r(d_()),t.size?p_(e.coeffs,t):e.coeffs}var sU=Math.PI/180;var K=(e,t)=>Number.isFinite(e)?e:t;function NM(e){let t=Dm(e);return{PCX1:K(t.PCX1,1.65),PDX1:K(t.PDX1,1),PDX2:K(t.PDX2,0),PDX3:K(t.PDX3,0),PEX1:K(t.PEX1,0),PEX2:K(t.PEX2,0),PEX3:K(t.PEX3,0),PEX4:K(t.PEX4,0),PHX1:K(t.PHX1,0),PHX2:K(t.PHX2,0),PKX1:K(t.PKX1,20),PKX2:K(t.PKX2,0),PKX3:K(t.PKX3,0),PPX1:K(t.PPX1,0),PPX2:K(t.PPX2,0),PPX3:K(t.PPX3,0),PPX4:K(t.PPX4,0),PVX1:K(t.PVX1,0),PVX2:K(t.PVX2,0),PCY1:K(t.PCY1,1.3),PDY1:K(t.PDY1,1),PDY2:K(t.PDY2,0),PDY3:K(t.PDY3,0),PEY1:K(t.PEY1,0),PEY2:K(t.PEY2,0),PEY3:K(t.PEY3,0),PEY4:K(t.PEY4,0),PEY5:K(t.PEY5,0),PHY1:K(t.PHY1,0),PHY2:K(t.PHY2,0),PHY3:K(t.PHY3,0),PKY1:K(t.PKY1,-15),PKY2:K(t.PKY2,2),PKY3:K(t.PKY3,0),PKY4:K(t.PKY4,2),PKY5:K(t.PKY5,0),PKY6:K(t.PKY6,0),PKY7:K(t.PKY7,0),PPY1:K(t.PPY1,0),PPY2:K(t.PPY2,0),PPY3:K(t.PPY3,0),PPY4:K(t.PPY4,0),PPY5:K(t.PPY5,0),PVY1:K(t.PVY1,0),PVY2:K(t.PVY2,0),PVY3:K(t.PVY3,0),PVY4:K(t.PVY4,0),RBX1:K(t.RBX1,0),RBX2:K(t.RBX2,0),RBX3:K(t.RBX3,0),RBY1:K(t.RBY1,0),RBY2:K(t.RBY2,0),RBY3:K(t.RBY3,0),RBY4:K(t.RBY4,0),RCX1:K(t.RCX1,1),RCY1:K(t.RCY1,1),REX1:K(t.REX1,0),REX2:K(t.REX2,0),REY1:K(t.REY1,0),REY2:K(t.REY2,0),RHX1:K(t.RHX1,0),RHY1:K(t.RHY1,0),RHY2:K(t.RHY2,0),RVY1:K(t.RVY1,0),RVY2:K(t.RVY2,0),RVY3:K(t.RVY3,0),RVY4:K(t.RVY4,0),RVY5:K(t.RVY5,1),RVY6:K(t.RVY6,0),PPZ1:K(t.PPZ1,0),PPZ2:K(t.PPZ2,0),QBZ1:K(t.QBZ1,8),QBZ2:K(t.QBZ2,0),QBZ3:K(t.QBZ3,0),QBZ4:K(t.QBZ4,0),QBZ5:K(t.QBZ5,0),QBZ9:K(t.QBZ9,0),QBZ10:K(t.QBZ10,0),QCZ1:K(t.QCZ1,1.1),QDZ1:K(t.QDZ1,.1),QDZ2:K(t.QDZ2,0),QDZ3:K(t.QDZ3,0),QDZ4:K(t.QDZ4,0),QDZ6:K(t.QDZ6,0),QDZ7:K(t.QDZ7,0),QDZ8:K(t.QDZ8,0),QDZ9:K(t.QDZ9,0),QDZ10:K(t.QDZ10,0),QDZ11:K(t.QDZ11,0),QEZ1:K(t.QEZ1,0),QEZ2:K(t.QEZ2,0),QEZ3:K(t.QEZ3,0),QEZ4:K(t.QEZ4,0),QEZ5:K(t.QEZ5,0),QHZ1:K(t.QHZ1,0),QHZ2:K(t.QHZ2,0),QHZ3:K(t.QHZ3,0),QHZ4:K(t.QHZ4,0),SSZ1:K(t.SSZ1,0),SSZ2:K(t.SSZ2,0),SSZ3:K(t.SSZ3,0),SSZ4:K(t.SSZ4,0),QSX1:K(t.QSX1,0),QSX2:K(t.QSX2,0),QSX3:K(t.QSX3,0),QSX4:K(t.QSX4,0),QSX5:K(t.QSX5,0),QSX6:K(t.QSX6,0),QSX7:K(t.QSX7,0),QSX8:K(t.QSX8,0),QSX9:K(t.QSX9,0),QSX10:K(t.QSX10,0),QSX11:K(t.QSX11,0),QSX12:K(t.QSX12,0),QSX13:K(t.QSX13,0),QSX14:K(t.QSX14,0),PPMX1:K(t.PPMX1,0),QSY1:K(t.QSY1,0),QSY2:K(t.QSY2,0),QSY3:K(t.QSY3,0),QSY4:K(t.QSY4,0),QSY5:K(t.QSY5,0),QSY6:K(t.QSY6,0),QSY7:K(t.QSY7,0),QSY8:K(t.QSY8,0),LONGVL:t.LONGVL!==void 0&&t.LONGVL>0?t.LONGVL:16.7,LCX:K(t.LCX,1),LCY:K(t.LCY,1),LEX:K(t.LEX,1),LEY:K(t.LEY,1),LFZO:K(t.LFZO,1),LHX:K(t.LHX,1),LHY:K(t.LHY,1),LKX:K(t.LKX,1),LKY:K(t.LKY,1),LKYC:K(t.LKYC,1),LKZC:K(t.LKZC,1),LMUX:K(t.LMUX,1),LMUY:K(t.LMUY,1),LMX:K(t.LMX,1),LMY:K(t.LMY,1),LVMX:K(t.LVMX,1),LRES:K(t.LRES,1),LS:K(t.LS,1),LTR:K(t.LTR,1),LVX:K(t.LVX,1),LVY:K(t.LVY,1),LVYKA:K(t.LVYKA,1),LXAL:K(t.LXAL,1),LYKA:K(t.LYKA,1)}}var _M=new WeakMap;function Sc(e){let t=_M.get(e);return t===void 0&&(t=NM(e),_M.set(e,t)),t}var OM=e=>e>=0?1:-1;function Ac(e,t,r=0,n){let o=Sc(e),a=Math.max(1,t),s=r,i=o.LFZO*e.fnomin,c=(a-i)/i,l=e.nomPressure>0&&n?(n-e.nomPressure)/e.nomPressure:0,u=e.unloadedR0,m=(o.PDY1+o.PDY2*c)*(1+o.PPY3*l+o.PPY4*l*l)*(1-o.PDY3*s*s)*o.LMUY,p=o.PCY1*o.LCY,d=m*a,f=o.PKY1*i*(1+o.PPY1*l)*Math.sin(o.PKY4*Math.atan(a/((o.PKY2+o.PKY5*s*s)*(1+o.PPY2*l)*i)))*(1-o.PKY3*Math.abs(s))*o.LKY,h=e.version!=="5.2",b=a*(o.PKY6+o.PKY7*c)*(1+o.PPY5*l)*o.LKYC,g=a*(o.PVY3+o.PVY4*c)*s*o.LKYC*o.LMUY,y=Math.abs(f)>1e-6?f:1e-6*(f<0?-1:1),x=h?(o.PHY1+o.PHY2*c)*o.LHY+(b*s-g)/y:(o.PHY1+o.PHY2*c)*o.LHY+o.PHY3*s,R=h?a*(o.PVY1+o.PVY2*c)*o.LVY*o.LMUY+g:a*((o.PVY1+o.PVY2*c)*o.LVY+(o.PVY3+o.PVY4*c)*s)*o.LMUY,v=p*d!==0?f/(p*d):0;return{Fz:a,g:s,dfz:c,dpi:l,Fz0p:i,R0:u,Cy:p,Dy:d,By:v,SHy:x,SVy:R,Kya:f,muy:m,EyA:o.PEY1+o.PEY2*c,EyG:1+o.PEY5*s*s,EyS:o.PEY3+o.PEY4*s,LEY:o.LEY}}function Em(e,t,r=0,n){let o=Ac(e,t,r,n),a=Sc(e),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,muy:p,Kya:d,SVy:f,By:h,Cy:b,Dy:g,SHy:y}=o,x=(a.PHX1+a.PHX2*c)*a.LHX,R=(a.PDX1+a.PDX2*c)*(1+a.PPX3*l+a.PPX4*l*l)*(1-a.PDX3*i*i)*a.LMUX,v=a.PCX1*a.LCX,S=R*s,A=s*(a.PKX1+a.PKX2*c)*Math.exp(a.PKX3*c)*(1+a.PPX1*l+a.PPX2*l*l)*a.LKX,F=v*S!==0?A/(v*S):0,w=Math.abs(d)>1e-6?d:1e-6*(d<0?-1:1),T=e.version!=="5.2",M=s*(a.PVX1+a.PVX2*c)*a.LVX*a.LMUX,k=T&&i!==0?Ac(e,t,0,n):o,C=a.REX1+a.REX2*c;C>1&&(C=1);let P=a.REY1+a.REY2*c;return P>1&&(P=1),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,Cy:b,Dy:g,By:h,SHy:y,SVy:f,Kya:d,muy:p,EyA:o.EyA,EyG:o.EyG,EyS:o.EyS,LEY:o.LEY,SHx:x,Cx:v,Dx:S,Bx:F,SVx:M,ExA:a.PEX1+a.PEX2*c+a.PEX3*c*c,PEX4:a.PEX4,LEX:a.LEX,SHxa:a.RHX1,Bxa0:a.RBX1+a.RBX3*i*i,RBX2:a.RBX2,LXAL:a.LXAL,Cxa:a.RCX1,Exa:C,SHyk:a.RHY1+a.RHY2*c,Byk0:a.RBY1+a.RBY4*i*i,RBY2:a.RBY2,RBY3:a.RBY3,LYKA:a.LYKA,Cyk:a.RCY1,Eyk:P,DVykA:p*s*(a.RVY1+a.RVY2*c+a.RVY3*i),RVY4:a.RVY4,RVY5:a.RVY5,RVY6:a.RVY6,LVYKA:a.LVYKA,SHt:a.QHZ1+a.QHZ2*c+(a.QHZ3+a.QHZ4*c)*i,Bt:(a.QBZ1+a.QBZ2*c+a.QBZ3*c*c)*(1+a.QBZ4*i+a.QBZ5*Math.abs(i))*(a.LKY/a.LMUY),Ct:a.QCZ1,Dt:s*(m/u)*(a.QDZ1+a.QDZ2*c)*(1-a.PPZ1*l)*(1+a.QDZ3*i+a.QDZ4*i*i)*a.LTR,EtA:a.QEZ1+a.QEZ2*c+a.QEZ3*c*c,EtG:a.QEZ4+a.QEZ5*i,Br:a.QBZ9*(a.LKY/a.LMUY)+a.QBZ10*h*b,Dr:T?s*m*((a.QDZ6+a.QDZ7*c)*a.LRES+((a.QDZ8+a.QDZ9*c)*(1+a.PPZ2*l)+(a.QDZ10+a.QDZ11*c)*Math.abs(i))*i*a.LKZC)*a.LMUY:s*m*((a.QDZ6+a.QDZ7*c)*a.LRES+(a.QDZ8+a.QDZ9*c)*(1+a.PPZ2*l)*i)*a.LMUY,arOff:d!==0?f/d:0,sixOne:T,y0:k,kk:A/w*(A/w),sS0:m*(a.SSZ1+(a.SSZ3+a.SSZ4*c)*i)*a.LS,sS2:m*a.SSZ2*a.LS/u}}function qo(e,t){let r=t+e.SHy,n=e.EyA*(e.EyG-e.EyS*OM(r))*e.LEY;n>1&&(n=1);let o=e.By*r;return e.Dy*Math.sin(e.Cy*Math.atan(o-n*(o-Math.atan(o))))+e.SVy}function Im(e,t){let r=t+e.SHx,n=e.ExA*(1-e.PEX4*OM(r))*e.LEX;n>1&&(n=1);let o=e.Bx*r;return e.Dx*Math.sin(e.Cx*Math.atan(o-n*(o-Math.atan(o))))+e.SVx}function VM(e,t,r){if(r===0)return t;let n=Math.tan(t);return Math.atan(Math.sqrt(n*n+e.kk*r*r))*Math.sign(t)}function f_(e,t,r,n){let o=t+e.SHt,a=e.EtA*(1+e.EtG*(2/Math.PI)*Math.atan(e.Bt*e.Ct*o));a>1&&(a=1);let s=VM(e,o,r),i=e.Bt*s;return e.Dt*Math.cos(e.Ct*Math.atan(i-a*(i-Math.atan(i))))*n}function h_(e,t,r,n){return e.Dr*Math.cos(Math.atan(e.Br*VM(e,t+e.SHy+e.arOff,r)))*n}function BM(e,t,r,n,o,a){let s=Math.cos(t),i=f_(e,t,r,s),c=h_(e,t,r,s);return-i*a+c+(e.sS0+e.sS2*o)*n}function b_(e,t,r,n,o,a){return e.sixOne?r*(e.g===0?n:qo(e.y0,t)):o-a}function _m(e,t,r){let n=e.Bxa0*Math.cos(Math.atan(e.RBX2*t))*e.LXAL,o=r+e.SHxa,a=e.SHxa===0?1:Math.cos(e.Cxa*Math.atan(n*e.SHxa-e.Exa*(n*e.SHxa-Math.atan(n*e.SHxa))))||1;return Math.cos(e.Cxa*Math.atan(n*o-e.Exa*(n*o-Math.atan(n*o))))/a*Im(e,t)}function rg(e,t){let r=e.sS0===0&&e.sS2===0?0:_m(e,0,t),n=qo(e,t);return BM(e,t,0,r,n,e.sixOne&&e.g!==0?qo(e.y0,t):n)}function Nm(e,t,r){let n=qo(e,r),o=_m(e,t,r),a=e.Byk0*Math.cos(Math.atan(e.RBY2*(r-e.RBY3)))*e.LYKA,s=t+e.SHyk,i=e.SHyk===0?1:Math.cos(e.Cyk*Math.atan(a*e.SHyk-e.Eyk*(a*e.SHyk-Math.atan(a*e.SHyk))))||1,c=Math.cos(e.Cyk*Math.atan(a*s-e.Eyk*(a*s-Math.atan(a*s))))/i,u=e.DVykA*Math.cos(Math.atan(e.RVY4*r))*Math.sin(e.RVY5*Math.atan(e.RVY6*t))*e.LVYKA,m=c*n+u;return{Fx:o,Fy:m,Mz:BM(e,r,t,o,m,b_(e,r,c,n,m,u))}}var wc=(e,t)=>Math.max(.1,e.muY0+e.loadSensY*(t-e.nominalLoad)),Fc=(e,t)=>Math.max(.1,e.muX0+e.loadSensX*(t-e.nominalLoad)),$M=(e,t,r)=>wc(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cy*Math.atan(e.By*r)),GM=(e,t,r)=>Fc(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cx*Math.atan(e.Bx*r));function ng(e,t){let r=Math.max(1,t.Fz),n=wc(e,r)*r,o=Fc(e,r)*r,a=n*Math.sin(e.Cy*Math.atan(e.By*t.alpha)),s=o*Math.sin(e.Cx*Math.atan(e.Bx*t.kappa)),i=Math.hypot(o>0?s/o:0,n>0?a/n:0);return i>1&&(s/=i,a/=i),{Fx:s,Fy:a,Mz:0}}var _s=Math.PI/180;function yo(e){if(e.kind==="simple")return"none";let t=e.missing?.some(n=>/^aligning moment Mz\b/i.test(n))??!1,r=["QBZ1","QCZ1","QDZ1"].every(n=>Number.isFinite(e.coeffs[n]));return t||!r?"assumed":"model"}function KM(e){let t=e.thermal?.operating;if(t===void 0||!e.thermal)return e;let{lateral:r,longitudinal:n,aligning:o}=e.thermal,a=r?kc(r,t):1,s=n?kc(n,t):1,i=o?kc(o,t):1;if(a===1&&s===1&&i===1)return e;if(e.kind==="simple")return{...e,muY0:e.muY0*a,muX0:e.muX0*s};let c={...e.coeffs},l=(u,m)=>{c[u]=(c[u]??1)*m};return l("LMUY",a),l("LMUX",s),l("LTR",i),l("LRES",i),{...e,coeffs:c}}function Ns(e,t,r){let n=0,o=0;for(let s=r;s<=t;s+=r){let i=Math.abs(e(s));i>o&&(o=i,n=s)}let a=r/10;for(let s=Math.max(a,n-r);s<=n+r;s+=a)o=Math.max(o,Math.abs(e(s)));return o}var gU=Math.LN2/16;var g_=45;var y_=[];for(let e=1;e<=g_;e++){let t=[];for(let r=Math.max(.1,e-1);r<=e+1;r+=.1)t.push(r);y_[e]=t}var HM=new WeakMap;function Vm(e,t){HM.set(e,t)}function on(e){return HM.get(e)??((t,r,n,o,a)=>e.forces({Fz:t,kappa:r,alpha:n,gamma:o,p:a}).Fx)}function We(e){let t=KM(e),r=t,n=t,o=4,a=b=>{let g=[],y=[],x=[],R=[];for(let A=0;A<o;A++)g.push(null),y.push(NaN),x.push(NaN),R.push(NaN);let v=0,S=0;return(A,F,w)=>{if(g[v]!==null&&A===y[v]&&F===x[v]&&w===R[v])return g[v];for(let M=0;M<o;M++)if(g[M]!==null&&A===y[M]&&F===x[M]&&w===R[M])return v=M,g[M];let T=b(A,F,w);return g[S]=T,y[S]=A,x[S]=F,R[S]=w,v=S,S=(S+1)%o,T}},s=a((b,g,y)=>Em(r,b,g,y)),i=a((b,g,y)=>Ac(r,b,g,y)),c=b=>e.kind==="magic"?Nm(s(b.Fz,b.gamma??0,b.p),b.kappa,b.alpha):ng(n,b),l=(b,g,y=0,x)=>e.kind==="magic"?qo(i(g,y,x),b):$M(n,g,b),u=(b,g,y=0,x)=>e.kind==="magic"?Im(s(g,y,x),b):GM(n,g,b),m=(b,g,y=0,x)=>e.kind==="magic"?rg(s(g,y,x),b):c({Fz:g,kappa:0,alpha:b,gamma:y,p:x}).Mz,p=b=>e.kind==="simple"?wc(n,b):Ns(g=>l(g*_s,b),45,1)/Math.max(1,b),d=b=>e.kind==="simple"?Fc(n,b):Ns(g=>u(g,b),.6,.02)/Math.max(1,b),f=b=>{let g=.1*_s;return Math.abs((l(g,b)-l(-g,b))/(2*g))},h={model:e,forces:c,Fx:u,Fy:l,Mz:m,muX:d,muY:p,corneringStiffness:f,verticalStiffness:()=>e.verticalStiffness,rollingRadius:b=>{if(e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS"))return 0;let g=e.unloadedR0??0;if(!(g>0))return 0;let y=e.verticalStiffness*1e3;if(!(y>0))return g;let x=e.rollingFraction??.306;return g-x*Math.max(0,b)/y},relaxationLength:b=>{let g=e.relaxation;if(!g)return 0;let y=g.carcassStiffness??0;if(!(y>0))return g.sigma;let x=f(Math.max(0,b));return x>0?x/(y*1e3):g.sigma}};return e.kind==="magic"&&Vm(h,(b,g,y,x,R)=>_m(s(b,x,R),g,y)),h}function Os(e){let t=Math.max(1,e.model.kind==="magic"?e.model.fnomin:e.model.nominalLoad);return e.Fy(2*_s,t,0)-e.Fy(-2*_s,t,0)>=0?1:-1}function Cc(e,t=e.kind==="magic"?e.fnomin:e.nominalLoad){let r=We(e),n=2*_s,o=3*_s,a=r.Fy(n,t,0),s=r.Fy(n,t,o);return!Number.isFinite(a)||!Number.isFinite(s)?!1:Math.abs(s-a)>1}var x_=Math.PI/180;function Te(e,t){return e.axle?e.axle(t):e}function Bm(e,t){if(e===t)return e;let r=Os(e)*Os(t),n=(p,d)=>.5*(p+d),o=(p,d)=>p>0&&d>0?n(p,d):p>0?p:d>0?d:0,a=p=>{let d=e.forces(p),f=t.forces(p);return{Fx:n(d.Fx,f.Fx),Fy:n(d.Fy,r*f.Fy),Mz:n(d.Mz,r*f.Mz)}},s=(p,d,f=0,h)=>n(e.Fx(p,d,f,h),t.Fx(p,d,f,h)),i=(p,d,f=0,h)=>n(e.Fy(p,d,f,h),r*t.Fy(p,d,f,h)),c=(p,d,f=0,h)=>n(e.Mz(p,d,f,h),r*t.Mz(p,d,f,h)),l={model:e.model,forces:a,Fx:s,Fy:i,Mz:c,muX:p=>Ns(d=>s(d,p),.6,.02)/Math.max(1,p),muY:p=>Ns(d=>i(d*x_,p),45,1)/Math.max(1,p),corneringStiffness:p=>n(e.corneringStiffness(p),t.corneringStiffness(p)),verticalStiffness:()=>o(e.verticalStiffness(),t.verticalStiffness()),rollingRadius:p=>o(e.rollingRadius(p),t.rollingRadius(p)),relaxationLength:p=>o(e.relaxationLength(p),t.relaxationLength(p)),axle:p=>p==="front"?e:t},u=on(e),m=on(t);return Vm(l,(p,d,f,h,b)=>n(u(p,d,f,h,b),m(p,d,f,h,b))),l}function Yt(e){if(zM.has(e))return e;let t=YM.get(e);if(t)return t;let r;if(e.axle){let n=e.axle("front"),o=e.axle("rear"),a=Yt(n),s=Yt(o);r=a===n&&s===o?e:Bm(a,s)}else Os(e)>0?r=e:(r={...e,forces:n=>{let o=e.forces(n);return{Fx:o.Fx,Fy:-o.Fy,Mz:-o.Mz}},Fy:(n,o,a,s)=>-e.Fy(n,o,a,s),Mz:(n,o,a,s)=>-e.Mz(n,o,a,s)},Vm(r,on(e)));return zM.add(r),r!==e&&YM.set(e,r),r}var zM=new WeakSet,YM=new WeakMap;var $m=25*(Math.PI/180);function R_(e){let t=.6180339887,r=0,n=$m,o=n-t*(n-r),a=r+t*(n-r),s=e(o),i=e(a);for(let l=0;l<12;l++)s>i?(n=a,a=o,i=s,o=n-t*(n-r),s=e(o)):(r=o,o=a,s=i,a=r+t*(n-r),i=e(a));return{alpha:s>i?o:a,force:Math.max(s,i)}}function Tc(e,t,r,n,o=0){let a=Math.abs(t);if(!(a>0))return 0;let s=u=>Math.abs(e.Fy(u,r,0))+Math.abs(e.Fy(u,n,0)),i=0,c=$m;if(s($m)<=a){let u=R_(s);if(u.force<=a)return u.alpha;c=u.alpha}else if(o>0){let u=Math.max(0,o*.6),m=Math.min($m,o*1.6+.001);s(u)<a&&s(m)>=a&&(i=u,c=m)}let l=.001*a;for(let u=0;u<12;u++){let m=.5*(i+c),p=s(m)-a;if(p<0?i=m:c=m,Math.abs(p)<=l)return m}return c}var og={shaft:!1,trail:0,hub:[0,0,0]};function jM(e){let t=e.spinAxis,r=Math.hypot(t[0],t[1]);if(r<1e-9)return[1,0,0];let n=[-t[1]/r,t[0]/r,0];return n[0]<0?[-n[0],-n[1],0]:n}function ag(e,t,r){let n=r.shaft?tg(e,t):[0,0,0];if(r.trail!==0){let a=jM(e),s=[t[0],t[1],0],i=$(s,Q(a,Z(s,a)));n=ne(n,me(Q(a,-r.trail),i))}let o=r.hub;return(o[0]!==0||o[1]!==0||o[2]!==0)&&(n=$(n,me($(e.contactPatch,e.wheelCenter),o))),{force:ne(t,o),moment:n}}var v_=(e,t)=>{let r=e!==void 0&&e>0?1/e:0,n=t!==void 0&&t>0?1/t:0;return r+n},Gm={ucaFront:0,ucaRear:0,lcaFront:0,lcaRear:0,tieRod:0,pushRod:0,rack:0};function Qo(e){return!e.measured}function Zo(e){if(!e)return!1;let t=r=>!!r&&Object.values(r).some(n=>n!==void 0&&n>0&&Number.isFinite(n));return t(e.links)||t(e.bushings)||e.rack!==void 0&&e.rack>0}function Pc(e,t){let r=e.corner.hardpoints,n=Rs(e.rocker,t.points.rockerAngle);return{ucaFront:r.ucaFront,ucaRear:r.ucaRear,lcaFront:r.lcaFront,lcaRear:r.lcaRear,tieInner:Ho(e.inv,t.steer),rockerPivotA:r.rockerPivotA,rockerPivotB:r.rockerPivotB,damperChassis:e.inv.strut?t.points.uprightUpper:r.damperChassis,uprightUpper:t.points.uprightUpper,uprightLower:t.points.uprightLower,tieOuter:t.points.tieOuter,wheelCenter:t.points.wheelCenter,pushrodOuter:t.points.pushrodOuter,contactPatch:t.points.contactPatch,kingpinGround:t.points.kingpinGround,kingpinAtHub:t.points.kingpinAtHub,rockerToPushrod:n.pushrod,rockerToDamper:n.damper,spinAxis:t.points.spinAxis,direct:e.corner.config.actuation==="direct",decoupled:e.corner.config.actuation==="decoupled",mcpherson:e.inv.strut!==void 0,loadedRadius:e.corner.config.loadedRadius,tyreDeflection:0,load:NaN,lifted:!1,clearance:0,contactLength:0}}function sg(e,t,r=0){let n=t.links??{},o=t.bushings??{},a=(l,u,m)=>{let p=v_(u,m);return p>0&&Number.isFinite(l)?l*p:0},s=o.topMount,i=e.topMount,c=i&&s!==void 0&&s>0&&i.every(Number.isFinite)?[-i[0]/s,-i[1]/s,-i[2]/s]:void 0;return{...c?{topMount:c}:{},ucaFront:a(e.ucaFront,n.ucaFront,o.ucaFront),ucaRear:a(e.ucaRear,n.ucaRear,o.ucaRear),lcaFront:a(e.lcaFront,n.lcaFront,o.lcaFront),lcaRear:a(e.lcaRear,n.lcaRear,o.lcaRear),tieRod:a(e.tieRod,n.tieRod,o.tieInner),pushRod:a(e.pushRod,n.pushRod,void 0),rack:r}}function UM(e,t,r,n){let o=Le(e,t);if(!(o>1e-9))return{axial:r,radius2:0};let a=(r*r-n*n+o*o)/(2*o);return{axial:a,radius2:Math.max(0,r*r-a*a)}}function Lc(e,t){let r=e.corner.hardpoints,n=e.inv,o={...n};if(n.strut&&t.topMount&&t.topMount.some(i=>i!==0)&&(o.strut={...n.strut,top:ne(n.strut.top,t.topMount)}),t.ucaFront!==0||t.ucaRear!==0){let i=UM(r.ucaFront,r.ucaRear,Le(r.uprightUpper,r.ucaFront)+t.ucaFront,Le(r.uprightUpper,r.ucaRear)+t.ucaRear);o.ubjAxial0=i.axial,o.ubjRadius2=i.radius2}if(t.lcaFront!==0||t.lcaRear!==0){let i=UM(r.lcaFront,r.lcaRear,Le(r.uprightLower,r.lcaFront)+t.lcaFront,Le(r.uprightLower,r.lcaRear)+t.lcaRear),c=Z(n.lbjRel0,n.lcaDir),l=$(n.lbjRel0,Q(n.lcaDir,c)),u=Math.hypot(l[0],l[1],l[2]);o.lbjRel0=u>1e-9?ne(Q(n.lcaDir,i.axial),Q(l,Math.sqrt(i.radius2)/u)):ne(Q(n.lcaDir,i.axial),l)}if(t.tieRod!==0){let i=Math.sqrt(n.tieLen2)+t.tieRod;o.tieLen2=i*i}if(t.rack!==0&&(o.tieInner0=ne(n.tieInner0,Q(n.rackAxis,t.rack))),t.pushRod===0)return{corner:e.corner,inv:o,rocker:e.rocker};let a=Math.sqrt(e.rocker.rodLen2)+t.pushRod,s={...e.rocker,rodLen2:a*a};return{corner:e.corner,inv:o,rocker:s}}var k_=8,M_=1e-5,S_=e=>({q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle});function ig(e,t,r){let n=ag(e,r.force,r.extras??og),o=r.alignMoment?ne(n.moment,[0,0,r.alignMoment]):n.moment;return vc(e,t,n.force,o)}function Hm(e,t,r,n,o,a,s=0){let i=at(e,t,r,o,a),c=e.corner.compliance;if(!(Zo(c)&&Qo(e.corner)))return{state:i,forces:ig(Pc(e,i),e.corner.config.pushrodAttach,n),deflection:Gm,rigid:i,iterations:0,converged:!0,bypassed:!0};let u=i,m=e,p=e.corner.config.pushrodAttach,d=ig(Pc(e,i),p,n),f=Gm,h=!1,b=0;for(;b<k_;b++){let g=Pc(m,u);if(d=ig(g,p,n),d.singular)break;f=sg(d,c,s),m=Lc(e,f);let y=at(m,t,r,S_(u),a),x=Le(y.points.wheelCenter,u.points.wheelCenter);if(u=y,x<M_){h=!0;break}}return{state:u,forces:d,deflection:f,rigid:i,iterations:b+1,converged:h&&u.converged,bypassed:!1}}var Km=1e3,XM=1e5;function qM(e,t,r,n,o){let a=Hm(e,t,r,n,void 0,o);return{toe:a.state.metrics.toe,camber:a.state.metrics.camber,patch:a.state.points.contactPatch,converged:a.converged,bypassed:a.bypassed}}function zm(e,t,r,n,o){let a={force:[0,0,n]},s=(b,g=0)=>qM(e,t,r,{force:b,alignMoment:g},o),i=qM(e,t,r,a,o);if(i.bypassed)return{toePerLateral:0,camberPerLateral:0,toePerLongitudinal:0,camberPerLongitudinal:0,toePerAligning:0,lateralPatch:0,longitudinalPatch:0,bypassed:!0,converged:!0};let c=s([0,Km,n]),l=s([0,-Km,n]),u=s([Km,0,n]),m=s([-Km,0,n]),p=s([0,0,n],XM),d=s([0,0,n],-XM),f=(b,g)=>(b-g)/2,h=[i,c,l,u,m,p,d].every(b=>b.converged);return{toePerLateral:f(c.toe,l.toe),camberPerLateral:f(c.camber,l.camber),toePerLongitudinal:f(u.toe,m.toe),camberPerLongitudinal:f(u.camber,m.camber),toePerAligning:f(p.toe,d.toe),lateralPatch:f(c.patch[1],l.patch[1]),longitudinalPatch:f(u.patch[0],m.patch[0]),bypassed:!1,converged:h}}var A_=1e3;function cg(e,t=A_){if(!Zo(e.compliance)||!Qo(e))return;let r=Tt(e),n=at(r,0,0),o=zm(r,n.beta,0,t);if(!o.bypassed)return{toePerFy:o.toePerLateral/1e3,camberPerFy:o.camberPerLateral/1e3,toePerFx:o.toePerLongitudinal/1e3,camberPerFx:o.camberPerLongitudinal/1e3,toePerMz:o.toePerAligning/1e5}}function Vs(e,t=-eg,r=eg,n=21){let o=e.measured;if(o)return{travel:[...o.travel],motionRatio:[...o.motionRatio],camber:[...o.camber],toe:[...o.toe],damperLen:o.damperLen?[...o.damperLen]:o.travel.map(()=>0)};let a=ut(e,{travelMin:t,travelMax:r,steps:n}),s=cg(e);return{travel:a.samples.map(i=>i.travel),motionRatio:a.samples.map(i=>i.metrics.motionRatio??1),camber:a.samples.map(i=>i.metrics.camber),toe:a.samples.map(i=>i.metrics.toe),damperLen:a.samples.map(i=>i.metrics.damperLength),...s?{compliance:s}:{}}}function Ym(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function xo(e,t){return{motionRatio:Ym(e.travel,e.motionRatio,t),camber:Ym(e.travel,e.camber,t),toe:Ym(e.travel,e.toe,t),damperLen:Ym(e.travel,e.damperLen,t)}}var QM=Math.PI/180,w_=9.81;function Ro(e,t,r,n=0){let o=Ge(e),a=e.wheelbase*(1-e.frontMassFrac),s=e.wheelbase*e.frontMassFrac,i=Es(e,n),c=e.aero?.model?(R,v,S)=>Es(e,n,v,R,S):()=>i,l=xo(t,0),u=xo(r,0),m=e.loadFactor,p=m!==void 0&&m!==1?(m-1)*e.massTotal*w_:0,d=p*e.frontMassFrac/2,f=p*(1-e.frontMassFrac)/2,h=(R,v)=>v>0&&Number.isFinite(v)&&R+v>0?v/(R+v):1,b=xt(e,"front"),g=xt(e,"rear"),y={F:h(e.wheelRateFront+(e.heaveSpringFront??0),b),R:h(e.wheelRateRear+(e.heaveSpringRear??0),g)},x={F:h(e.wheelRateFront+e.arbFront,b),R:h(e.wheelRateRear+e.arbRear,g)};return(R,v,S=0,A=0)=>{let F=c(R,v,S),w={F:o.rollGradientFront*R,R:o.rollGradientRear*R},T=o.pitchGradient*v*QM,M=(_,D)=>{let I=D==="F"?e.trackFront:e.trackRear,N=D==="F"?o.rideRateFront:o.rideRateRear,O=(_==="R"?1:-1)*(I/2)*Math.tan(w[D]*QM),V=(D==="R"?s:-a)*Math.tan(T),H=`${D}${_}`,U=p?F[H]+(D==="F"?d:f):F[H],G=N>0?U/N:0;return{anti:O,sym:V+G}},k={FL:M("L","F"),FR:M("R","F"),RL:M("L","R"),RR:M("R","R")},C=_=>{let D=_[0];return k[_].sym*y[D]+k[_].anti*x[D]},P=Ds(e,A,o,{FL:C("FL"),FR:C("FR")}),L=P.ends?{F:w.F+P.ends.front,R:w.R+P.ends.rear}:{F:w.F+P.rollDeg,R:w.R+P.rollDeg},E=(_,D)=>{let I=D==="F"?t:r,N=D==="F"?l:u,O=`${D==="F"?"F":"R"}${_}`,V=k[O].sym+k[O].anti+P.travel[O],H=C(O)+P.travel[O]*x[D],U=V-H,G=xo(I,H),B=(_==="R"?1:-1)*G.camber;return{travel:H,tyre:U,ground:V,camber:B,camberRoad:B+L[D],toe:G.toe,bumpToe:G.toe-N.toe,damperTravel:N.damperLen-G.damperLen}};return{FL:E("L","F"),FR:E("R","F"),RL:E("L","R"),RR:E("R","R"),steeringJacking:P}}}var lg=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Jo(e){return{enabled:e?.enabled===!0,roadFeedbackGain:Math.min(2,Math.max(0,lg(e?.roadFeedbackGain,1))),turnInFrictionNm:Math.max(0,lg(e?.turnInFrictionNm,0)),columnStiffnessNmPerRad:Math.max(0,lg(e?.columnStiffnessNmPerRad,0))}}function ug(e,t,r){let n=Jo(r);if(!n.enabled)return{roadNm:e,assistanceNm:0,frictionNm:0,columnTwistDeg:0,driverNm:e};let o=e*(n.roadFeedbackGain-1),a=t===0?0:Math.sign(t)*n.turnInFrictionNm,s=e+o+a,i=n.columnStiffnessNmPerRad>0?s/n.columnStiffnessNmPerRad*(180/Math.PI):0;return{roadNm:e,assistanceNm:o,frictionNm:a,columnTwistDeg:i,driverNm:s}}var ZM=()=>({totalNm:0,aligningNm:0,lateralNm:0,longitudinalNm:0,jackingNm:0});function ea(e){let t=e.steerFront;return!!(t?.rackRatioMmPerRev&&t.innerJacobian&&t.innerJacobian.length>=2&&t.outerJacobian&&t.outerJacobian.length>=2&&t.meanDeg.length>=2)}function Dc(e,t,r,n="model",o){let a=e.steerFront;if(!ea(e)||!a)return null;let s=t<0?-1:1,c=a.rackRatioMmPerRev/(2*Math.PI)/1e3,l=t>=0,u=o&&a.travelSurface?Ps(a,Math.abs(t),l?o.FL:o.FR,l?o.FR:o.FL):Ls(a,Math.abs(t));if(!u.innerJacobian||!u.outerJacobian)return null;let m=(b,g)=>{let y=r[b],x=b==="FL"?-1:1,R=-x*y.Fy,S={aligning:1e3*(-x*y.Mz)*g.yaw,lateral:R*g.lateral,longitudinal:y.Fx*g.longitudinal,jacking:y.Fz*g.vertical},A=ZM();A.aligningNm=-s*S.aligning*c,A.lateralNm=-s*S.lateral*c,A.longitudinalNm=-s*S.longitudinal*c,A.jackingNm=-s*S.jacking*c,A.totalNm=A.aligningNm+A.lateralNm+A.longitudinalNm+A.jackingNm;let F=-s*(S.aligning+S.lateral+S.longitudinal+S.jacking);return{moment:A,rackN:F}},p=m("FL",l?u.innerJacobian:u.outerJacobian),d=m("FR",l?u.outerJacobian:u.innerJacobian),f=ZM();for(let b of[p.moment,d.moment])f.aligningNm+=b.aligningNm,f.lateralNm+=b.lateralNm,f.longitudinalNm+=b.longitudinalNm,f.jackingNm+=b.jackingNm,f.totalNm+=b.totalNm;let h=ug(f.totalNm,t,e.steeringSystem);return f.totalNm=h.driverNm,{...f,roadNm:h.roadNm,assistanceNm:h.assistanceNm,frictionNm:h.frictionNm,columnTwistDeg:h.columnTwistDeg,rackForceN:p.rackN+d.rackN,aligningSource:n,perWheel:{FL:p.moment,FR:d.moment}}}var F_=e=>"front"in e&&"rear"in e;function Bs(e,t){return F_(e)?e[t]:e}function dg(e,t,r=24){let n=Math.max(1,t),o=n/Math.max(1,r-1),a=[],s=[],i=[];for(let l=0;l<r;l++){let u=l*o;a.push(u),s.push(e.muX(u)),i.push(e.muY(u))}let c=(l,u)=>{if(!(u>0))return l[0];if(u>=n)return l[r-1];let m=Math.min(r-2,Math.floor(u/o)),p=(u-a[m])/o;return l[m]+p*(l[m+1]-l[m])};return{muX:l=>c(s,l),muY:l=>c(i,l)}}function mg(e,t){let r=Math.max(0,t.Fz);return eS(e.muX(r)*r,e.muY(r)*r,t)}function eS(e,t,r){if(!(t>0))return{fyUsed:0,fyMax:0,fyRes:0};let n=e>0?Math.min(1,Math.abs(r.Fx)/e):0,o=t*Math.sqrt(Math.max(0,1-n*n)),a=Math.abs(r.Fy);return{fyUsed:a,fyMax:o,fyRes:Math.max(0,o-a)}}function JM(e,t,r){let n=mg(e,t),o=mg(e,r);return{left:n,right:o,fyRes:n.fyRes+o.fyRes}}function _n(e,t,r){let n=JM(Bs(e,"front"),t.FL,t.FR),o=JM(Bs(e,"rear"),t.RL,t.RR),a=r.lf>0&&Number.isFinite(r.lf)?r.lf:0,s=r.lr>0&&Number.isFinite(r.lr)?r.lr:0,i=o.fyRes*s,c=n.fyRes*a,l=i-c,u=Math.max(Math.abs(i),Math.abs(c));return{stabil:i,agil:c,diff:l,rel:u>0?l/u:0,front:n,rear:o}}var Ec=[{q:"p",section:"INFLATION_PRESSURE_RANGE",min:"PRESMIN",max:"PRESMAX",what:"pressure"},{q:"fz",section:"VERTICAL_FORCE_RANGE",min:"FZMIN",max:"FZMAX",what:"load"},{q:"kappa",section:"LONG_SLIP_RANGE",min:"KPUMIN",max:"KPUMAX",what:"slip ratio"},{q:"alpha",section:"SLIP_ANGLE_RANGE",min:"ALPMIN",max:"ALPMAX",what:"slip angle"},{q:"gamma",section:"INCLINATION_ANGLE_RANGE",min:"CAMMIN",max:"CAMMAX",what:"inclination"}],T_=Ec.flatMap(e=>[e.min,e.max]);function P_(e){let t={};for(let r of Ec){let n=e[r.min],o=e[r.max],a={};Number.isFinite(n)&&(a.min=n),Number.isFinite(o)&&(a.max=o),(a.min!==void 0||a.max!==void 0)&&(t[r.q]=a)}return Object.keys(t).length?t:void 0}function Wm(e){if(e.kind==="magic")return e.range??P_(e.coeffs)}function pg(e){return Math.max(1,e.kind==="magic"?e.fnomin:e.nominalLoad)}function tS(e,t,r,n,o){let a=(r-t)/n,s=t,i=e(t);for(let c=t+a;c<=r;c+=a){let l=e(c);o(l,i)&&(i=l,s=c)}return s}function $r(e){let t=rS.get(e);if(t!==void 0)return t;let r=10*pg(e.model),{turnover:n,collapse:o}=D_(e,r),a=n??o??r;return rS.set(e,a),a}var rS=new WeakMap;function D_(e,t){let r=pg(e.model),n=m=>e.muY(m),o=m=>n(m)*m,a=80,s=t/a,i=null,c=o(s);for(let m=2;m<=a;m++){let p=o(m*s);if(p<c){i=tS(o,(m-2)*s,m*s,20,(d,f)=>d>f);break}c=p}let l=null,u=n(s);for(let m=2;m<=a;m++){let p=n(m*s);if(p>u){let d=tS(n,(m-2)*s,m*s,40,(f,h)=>f<h);n(d)<.05*n(r)&&(l=d);break}u=p}return{turnover:i,collapse:l}}var nS=.1;function jm(e,t=pg(e)){let r=We(e).muX(t);return{muX:r,none:Number.isFinite(r)&&r<nS}}var oS=["FL","FR","RL","RR"],E_=e=>e==="FL"||e==="RL",I_=e=>e==="FL"||e==="FR"?"front":"rear";function Um(e,t,r,n){if(!(e.full>e.open)||n.ayDir===0)return e.full;let o=n.halfTrack[e.axle],a={};for(let l of oS)a[l]={...t[l]};let s=l=>{let u=0;for(let p of oS)I_(p)===e.axle&&(a[p].Fx=e.sense*(p===e.strong?l-e.open/2:e.open/2),u-=(E_(p)?o:-o)*a[p].Fx);let m=_n(r,a,n.arms);return u*n.ayDir>=0?Math.abs(u)<=m.stabil:Math.abs(u)<=m.agil};if(s(e.full))return e.full;let i=e.open,c=e.full;for(let l=0;l<20&&c-i>.001*e.full;l++){let u=.5*(i+c);s(u)?i=u:c=u}return i}var __=[["PCY1","Shape factor Cfy for lateral forces",1.3],["PDY1","Lateral friction Muy",1],["PDY2","Variation of friction Muy with load",0],["PDY3","Variation of friction Muy with squared camber",0],["PEY1","Lateral curvature Efy at Fznom",0],["PEY2","Variation of curvature Efy with load",0],["PEY3","Zero order camber dependency of curvature Efy",0],["PEY4","Variation of curvature Efy with camber",0],["PEY5","Variation of curvature Efy with camber squared",0],["PKY1","Maximum value of stiffness Kfy/Fznom",-15],["PKY2","Load at which Kfy reaches maximum value",2],["PKY3","Variation of Kfy/Fznom with camber",0],["PKY4","Curvature of stiffness Kfy",2],["PKY5","Peak stiffness variation with camber squared",0],["PKY6","Fy camber stiffness factor",0],["PKY7","Vertical load dependency of camber stiffness",0],["PHY1","Horizontal shift Shy at Fznom",0],["PHY2","Variation of shift Shy with load",0],["PHY3","Variation of shift Shy with camber",0],["PVY1","Vertical shift in Svy/Fz at Fznom",0],["PVY2","Variation of shift Svy/Fz with load",0],["PVY3","Variation of shift Svy/Fz with camber",0],["PVY4","Variation of shift Svy/Fz with camber and load",0],["PPY1","Influence of inflation pressure on cornering stiffness",0],["PPY2","Influence of inflation pressure on dependency of nominal tyre load on cornering stiffness",0],["PPY3","Linear influence of inflation pressure on lateral peak friction",0],["PPY4","Quadratic influence of inflation pressure on lateral peak friction",0],["PPY5","Influence of inflation pressure on camber stiffness",0]],N_=[["PCX1","Shape factor Cfx for longitudinal force",1.65],["PDX1","Longitudinal friction Mux at Fznom",1],["PDX2","Variation of friction Mux with load",0],["PDX3","Variation of friction Mux with camber squared",0],["PEX1","Longitudinal curvature Efx at Fznom",0],["PEX2","Variation of curvature Efx with load",0],["PEX3","Variation of curvature Efx with load squared",0],["PEX4","Factor in curvature Efx while driving",0],["PKX1","Longitudinal slip stiffness Kfx/Fz at Fznom",20],["PKX2","Variation of slip stiffness Kfx/Fz with load",0],["PKX3","Exponent in slip stiffness Kfx/Fz with load",0],["PHX1","Horizontal shift Shx at Fznom",0],["PHX2","Variation of shift Shx with load",0],["PVX1","Vertical shift Svx/Fz at Fznom",0],["PVX2","Variation of shift Svx/Fz with load",0],["PPX1","Linear influence of inflation pressure on longitudinal slip stiffness",0],["PPX2","Quadratic influence of inflation pressure on longitudinal slip stiffness",0],["PPX3","Linear influence of inflation pressure on peak longitudinal friction",0],["PPX4","Quadratic influence of inflation pressure on peak longitudinal friction",0]],O_=[["QBZ1","Trail slope factor for trail Bpt at Fznom",8],["QBZ2","Variation of slope Bpt with load",0],["QBZ3","Variation of slope Bpt with load squared",0],["QBZ4","Variation of slope Bpt with camber",0],["QBZ5","Variation of slope Bpt with absolute camber",0],["QBZ9","Factor for scaling factors of slope factor Br of Mzr",0],["QBZ10","Factor for dimensionless cornering stiffness of Br of Mzr",0],["QCZ1","Shape factor Cpt for pneumatic trail",1.1],["QDZ1","Peak trail Dpt = Dpt*(Fz/Fznom*R0)",.1],["QDZ2","Variation of peak Dpt with load",0],["QDZ3","Variation of peak Dpt with camber",0],["QDZ4","Variation of peak Dpt with camber squared",0],["QDZ6","Peak residual torque Dmr = Dmr/(Fz*R0)",0],["QDZ7","Variation of peak factor Dmr with load",0],["QDZ8","Variation of peak factor Dmr with camber",0],["QDZ9","Variation of peak factor Dmr with camber and load",0],["QDZ10","Variation of peak factor Dmr with camber squared",0],["QDZ11","Variation of Dmr with camber squared and load",0],["QEZ1","Trail curvature Ept at Fznom",0],["QEZ2","Variation of curvature Ept with load",0],["QEZ3","Variation of curvature Ept with load squared",0],["QEZ4","Variation of curvature Ept with sign of Alpha-t",0],["QEZ5","Variation of Ept with camber and sign Alpha-t",0],["QHZ1","Trail horizontal shift Sht at Fznom",0],["QHZ2","Variation of shift Sht with load",0],["QHZ3","Variation of shift Sht with camber",0],["QHZ4","Variation of shift Sht with camber and load",0],["PPZ1","Effect of inflation pressure on length of pneumatic trail",0],["PPZ2","Influence of inflation pressure on residual aligning torque",0],["SSZ1","Nominal value of s/R0: effect of Fx on Mz",0],["SSZ2","Variation of distance s/R0 with Fy/Fznom",0],["SSZ3","Variation of distance s/R0 with camber",0],["SSZ4","Variation of distance s/R0 with load and camber",0]],V_=[["RBX1","Slope factor for combined slip Fx reduction",0],["RBX2","Variation of slope Fx reduction with kappa",0],["RBX3","Influence of camber on stiffness for Fx combined",0],["RCX1","Shape factor for combined slip Fx reduction",1],["REX1","Curvature factor of combined Fx",0],["REX2","Curvature factor of combined Fx with load",0],["RHX1","Shift factor for combined slip Fx reduction",0],["RBY1","Slope factor for combined Fy reduction",0],["RBY2","Variation of slope Fy reduction with alpha",0],["RBY3","Shift term for alpha in slope Fy reduction",0],["RBY4","Influence of camber on stiffness of Fy combined",0],["RCY1","Shape factor for combined Fy reduction",1],["REY1","Curvature factor of combined Fy",0],["REY2","Curvature factor of combined Fy with load",0],["RHY1","Shift factor for combined Fy reduction",0],["RHY2","Shift factor for combined Fy reduction with load",0],["RVY1","Kappa induced side force Svyk/Muy*Fz at Fznom",0],["RVY2","Variation of Svyk/Muy*Fz with load",0],["RVY3","Variation of Svyk/Muy*Fz with camber",0],["RVY4","Variation of Svyk/Muy*Fz with alpha",0],["RVY5","Variation of Svyk/Muy*Fz with kappa",1],["RVY6","Variation of Svyk/Muy*Fz with atan(kappa)",0]],B_=[["LFZO","Scale factor of nominal (rated) load",1],["LCX","Scale factor of Fx shape factor",1],["LMUX","Scale factor of Fx peak friction coefficient",1],["LEX","Scale factor of Fx curvature factor",1],["LKX","Scale factor of Fx slip stiffness",1],["LHX","Scale factor of Fx horizontal shift",1],["LVX","Scale factor of Fx vertical shift",1],["LCY","Scale factor of Fy shape factor",1],["LMUY","Scale factor of Fy peak friction coefficient",1],["LEY","Scale factor of Fy curvature factor",1],["LKY","Scale factor of Fy cornering stiffness",1],["LKYC","Scale factor of camber force stiffness",1],["LKZC","Scale factor of camber torque stiffness",1],["LHY","Scale factor of Fy horizontal shift",1],["LVY","Scale factor of Fy vertical shift",1],["LTR","Scale factor of peak of pneumatic trail",1],["LRES","Scale factor for offset of residual torque",1],["LXAL","Scale factor of alpha influence on Fx",1],["LYKA","Scale factor of kappa influence on Fy",1],["LVYKA","Scale factor of kappa induced Fy",1],["LS","Scale factor of moment arm of Fx",1]],sS=[["lateral",__],["longitudinal",N_],["aligning",O_],["combined",V_],["scaling",B_]].flatMap(([e,t])=>t.map(([r,n,o])=>({key:r,section:e,text:n,fallback:o}))),u9=new Map(sS.map(e=>[e.key,e]));var $_=/^\$\s*EDITED\s+([A-Z][A-Z0-9_]*)\s+was\s+(absent|[-+0-9.eE]+)\s*$/;function iS(e){let t={};for(let r of e.split(/\r?\n/)){let n=r.trim().match($_);if(!n)continue;let o=n[2]==="absent"?null:parseFloat(n[2]);(o===null||Number.isFinite(o))&&(t[n[1]]=o)}return Object.keys(t).length?t:void 0}var K_=/^\s*\$\s*UNLOADED_RADIUS_STAND_IN\s*=\s*([0-9.eE+-]+)/,H_=/^\$-+ written by (?:PaceDynamics|PaceLab)\b/m,z_=/^\$\s*AXIS_SYSTEM\s*=\s*(ISO-W|SAE)\b/m;function Y_(e){let t=e.match(z_);return t?{axisSystem:t[1]==="SAE"?"sae":"iso",trustSide:!0}:H_.test(e)?{axisSystem:"sae",trustSide:!1}:{axisSystem:"iso",trustSide:!0}}function W_(e){return e>=62?"6.2":e>=61?"6.1":"5.2"}var cS=new Map([["pa",1],["pascal",1],["kpa",1e3],["kilopascal",1e3],["mpa",1e6],["megapascal",1e6],["bar",1e5],["psi",6894.757293168]]);function j_(e,t,r){let n=r.PRESSURE?.trim().toLowerCase(),o=n===void 0?1:cS.get(n);if(o===void 0)return;let a=(c,l)=>l===1?c:Number((c*l).toPrecision(12)),s=e.NOMPRES??e.INFLPRES;if(s!==void 0)return a(s,o);let i=e.INFLATION_PRESSURE;if(i!==void 0)return n!==void 0?a(i,o):t.PROPERTY_FILE_FORMAT?.trim().toUpperCase()==="MF_05"?a(i,1e5):void 0}var U_=new Map([["radians",1],["radian",1],["rad",1],["degrees",Math.PI/180],["degree",Math.PI/180],["deg",Math.PI/180]]);function X_(e,t){let r=(s,i)=>s===void 0?1:i.get(s.trim().toLowerCase()),n=r(t.ANGLE,U_),o={fz:1,kappa:1,alpha:n,gamma:n,p:r(t.PRESSURE,cS)},a={};for(let s of Ec){let i=o[s.q];if(i===void 0)continue;let c={};for(let[l,u]of[["min",s.min],["max",s.max]]){let m=e[u];Number.isFinite(m)&&(c[l]=i===1?m:Number((m*i).toPrecision(12)),delete e[u])}(c.min!==void 0||c.max!==void 0)&&(a[s.q]=c)}return Object.keys(a).length?a:void 0}function Ic(e,t="imported",r={}){let n=Y_(e),o=r.axisSystem??n.axisSystem,a={},s={},i={},c="",l;for(let g of e.split(/\r?\n/)){let y=g.match(K_);y&&(l=parseFloat(y[1]));let x=g.replace(/[$!].*$/,"").trim();if(!x)continue;if(x.startsWith("[")){c=(x.match(/^\[([^\]]*)/)?.[1]??"").trim().toUpperCase();continue}let R=x.indexOf("=");if(R<0)continue;let v=x.slice(0,R).trim().toUpperCase(),S=x.slice(R+1).trim(),A=S.match(/^'([^']*)'|^"([^"]*)"/);if(A){s[v]=A[1]??A[2]??"",c==="UNITS"&&(i[v]=s[v]);continue}let F=parseFloat(S);Number.isFinite(F)&&(a[v]=F)}let u=W_(a.FITTYP??62),m=iS(e),p=m?Object.fromEntries(Object.entries(m).filter(([g])=>a[g]!==void 0)):void 0,d=a.VERTICAL_STIFFNESS??a.KZ??0,f=j_(a,s,i),h=X_(a,i),b=[];return a.UNLOADED_RADIUS===void 0&&a.R0===void 0&&b.push("UNLOADED_RADIUS"),d<=0&&b.push("VERTICAL_STIFFNESS"),a.FNOMIN===void 0&&b.push("FNOMIN"),f===void 0&&b.push("NOMPRES"),{kind:"magic",name:t,version:u,coeffs:a,axisSystem:o,side:n.trustSide?s.TYRESIDE==="RIGHT"?"right":s.TYRESIDE==="LEFT"?"left":void 0:void 0,fnomin:a.FNOMIN??5e3,unloadedR0:a.UNLOADED_RADIUS??a.R0??(l!==void 0&&l>0?l:.3),...a.WIDTH!==void 0&&a.WIDTH>0?{sectionWidth:a.WIDTH}:{},verticalStiffness:d>0?d/1e3:0,...a.FREFF!==void 0&&!a.DREFF?{rollingFraction:a.FREFF}:{},...a.LATERAL_STIFFNESS!==void 0&&a.LATERAL_STIFFNESS>0?{relaxation:{sigma:0,carcassStiffness:a.LATERAL_STIFFNESS/1e3,source:"fitted"}}:{},nomPressure:f??0,missing:b,...p&&Object.keys(p).length?{edited:p}:{},...h?{range:h}:{}}}function an(e){if(!e)return null;let t=e.unloadedR0;return t===void 0||!(t>0)||e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS")?null:t*1e3}function Xm(e){if(!e)return null;let t=e.sectionWidth;return t!==void 0&&t>0?t:null}function lS(e){if(!e||e.kind!=="magic")return null;let t=e.coeffs.RIM_RADIUS,r=e.coeffs.RIM_WIDTH;return typeof t=="number"&&t>0&&typeof r=="number"&&r>0?{diameter:2*t*1e3,width:r*1e3}:null}var R9=Math.PI/180;var A9=Math.PI/180,w9=180/Math.PI;function _c(){return{kind:"simple",name:"Simple (default)",Bx:11,Cx:1.6,muX0:1.7,loadSensX:-8e-5,By:9,Cy:1.4,muY0:1.6,loadSensY:-1e-4,nominalLoad:1500,verticalStiffness:120}}var dS=`$ AXIS_SYSTEM = SAE (authored in the evaluation frame: y right)
|
|
2
|
+
import{parentPort as II,workerData as jY}from"node:worker_threads";import{readFileSync as Y1}from"node:fs";import{join as W1}from"node:path";var qu=e=>e.format!=="points"&&!e.field;var yt=e=>e?.kind==="ice";var Pv={packVoltageMax:600,segmentVoltageMax:120,powerLimitKw:80};var nt=e=>typeof e=="number"&&Number.isFinite(e);function NI(e){let{soc:t,ocv:r,r0:n}=e;if(!Array.isArray(t)||t.length<2)return"The curve needs at least two state-of-charge points.";if(!t.every(nt))return"The state-of-charge axis contains a value that is not a number.";if(t[0]<0||t[t.length-1]>1)return`The state-of-charge axis must lie within 0 to 1 (it runs ${t[0]} to ${t[t.length-1]}).`;for(let o=1;o<t.length;o++)if(!(t[o]>t[o-1]))return`The state-of-charge axis must increase (${t[o-1]} then ${t[o]}).`;if(!Array.isArray(r)||r.length!==t.length)return`The curve has ${Array.isArray(r)?r.length:0} voltages against ${t.length} state-of-charge points.`;if(!r.every(nt))return"The open-circuit voltage contains a value that is not a number.";if(r.some(o=>o<=0))return"The open-circuit voltage must be positive everywhere.";for(let o=1;o<r.length;o++)if(r[o]<r[o-1])return`The open-circuit voltage must rise with state of charge (${r[o-1]} V at ${t[o-1]} then ${r[o]} V at ${t[o]}).`;if(!Array.isArray(n)||n.length!==t.length)return`The curve has ${Array.isArray(n)?n.length:0} resistances against ${t.length} state-of-charge points.`;if(!n.every(nt))return"The resistance contains a value that is not a number.";if(n.some(o=>o<0))return"The resistance cannot be negative.";if(e.rTempC!==void 0||e.rGrid!==void 0){let o=e.rTempC,a=e.rGrid;if(!Array.isArray(o)||o.length<1)return"The resistance temperature axis needs at least one temperature.";if(!o.every(nt))return"The resistance temperature axis contains a value that is not a number.";for(let s=1;s<o.length;s++)if(!(o[s]>o[s-1]))return`The temperature axis must increase (${o[s-1]} then ${o[s]} \xB0C).`;if(!Array.isArray(a)||a.length!==o.length)return`The resistance grid has ${Array.isArray(a)?a.length:0} rows against ${o.length} temperatures.`;for(let s=0;s<a.length;s++){let i=a[s];if(!Array.isArray(i)||i.length!==t.length)return`Resistance row ${s+1} has ${Array.isArray(i)?i.length:0} values against ${t.length} state-of-charge points.`;if(!i.every(nt))return"The resistance grid contains a value that is not a number.";if(i.some(c=>c<0))return"The resistance grid contains a negative resistance."}}return null}function OI(e){return!e||typeof e!="object"?"The cell has no curve.":e.kind==="table"?NI(e):e.kind==="analytic"?!nt(e.vCut)||!nt(e.vNom)||!nt(e.vFull)?"The cut-off, nominal and full voltages must be numbers.":e.vCut<=0?"The cut-off voltage must be positive.":e.vCut<e.vNom&&e.vNom<e.vFull?!nt(e.r0)||e.r0<0?"The cell resistance must be a number and cannot be negative.":e.socAtNom!==void 0&&(!nt(e.socAtNom)||e.socAtNom<=0||e.socAtNom>=1)?"The state of charge the nominal voltage is met at must lie strictly between 0 and 1.":null:`The voltages must order cut-off < nominal < full (given ${e.vCut}, ${e.vNom}, ${e.vFull} V).`:`Unknown cell curve kind "${e.kind}".`}function Qu(e){if(!e||typeof e!="object")return"Not a battery model.";let t=e.cell;if(!t||typeof t!="object")return"The model has no cell.";if(!nt(t.capacityAh)||t.capacityAh<=0)return"The cell capacity must be a positive number of amp-hours.";if(!nt(t.vMin)||t.vMin<0)return"The cut-off voltage must be a number and cannot be negative.";if(!nt(t.vMax)||t.vMax<=0)return"The maximum cell voltage must be a positive number.";if(!(t.vMin<t.vMax))return`The cut-off voltage (${t.vMin} V) must be below the maximum (${t.vMax} V).`;if(!nt(t.iMaxA)||t.iMaxA<0)return"The discharge current limit must be a number of amps, 0 for no limit.";if(t.iMaxChargeA!==void 0&&(!nt(t.iMaxChargeA)||t.iMaxChargeA<0))return"The charge current limit must be a number of amps, 0 for no limit.";if(t.massKg!==void 0&&(!nt(t.massKg)||t.massKg<0))return"The cell mass must be a number and cannot be negative.";let r=OI(t.curve);if(r)return r;let n=t.curve.kind==="table"?t.curve.ocv[t.curve.ocv.length-1]:t.curve.vFull;if(t.vMin>=n)return`The cut-off voltage (${t.vMin} V) is at or above the cell's voltage at full charge (${n} V), so no power could ever be drawn.`;let o=e.thermal;if(o!==void 0){if(!o||typeof o!="object")return"The thermal model must be an object, or absent.";if(!nt(o.heatCapacityJPerK)||o.heatCapacityJPerK<=0)return"The cell heat capacity must be a positive number of joules per kelvin.";if(!nt(o.coolingWPerK)||o.coolingWPerK<0)return"The cooling must be a number of watts per kelvin and cannot be negative.";if(o.startC!==void 0&&!nt(o.startC))return"The starting temperature must be a number.";if(o.entropicVPerK!==void 0&&!nt(o.entropicVPerK))return"The entropic coefficient must be a number.";if(o.derateFromC!==void 0){if(!nt(o.derateFromC))return"The temperature the derate starts at must be a number.";if(o.derateToC!==void 0){if(!nt(o.derateToC))return"The temperature the derate ends at must be a number.";if(!(o.derateToC>o.derateFromC))return`The derate must end above where it starts (given ${o.derateFromC} then ${o.derateToC} \xB0C).`}}else if(o.derateToC!==void 0)return"The derate has an end temperature but no start; give both or neither."}let a=e.pack;if(!a||typeof a!="object")return"The model has no pack.";if(!Number.isInteger(a.series)||a.series<1)return"The pack needs a whole number of cells in series, at least one.";if(!Number.isInteger(a.parallel)||a.parallel<1)return"The pack needs a whole number of strings in parallel, at least one.";if(!nt(a.busResistance)||a.busResistance<0)return"The busbar resistance must be a number and cannot be negative.";if(a.seriesPerSegment!==void 0&&a.seriesPerSegment!==0){if(!Number.isInteger(a.seriesPerSegment)||a.seriesPerSegment<1)return"The cells per segment must be a whole number, at least one.";if(a.seriesPerSegment>a.series)return`A segment cannot hold more cells (${a.seriesPerSegment}) than the pack has in series (${a.series}).`}return null}function Go(e,t){let r=e.length;if(r<=1)return{i:0,t:0,clamped:!1};if(t<=e[0])return{i:0,t:0,clamped:t<e[0]};if(t>=e[r-1])return{i:r-2,t:1,clamped:t>e[r-1]};let n=0,o=r-1;for(;o-n>1;){let a=n+o>>1;e[a]<=t?n=a:o=a}return{i:n,t:(t-e[n])/(e[o]-e[n]),clamped:!1}}function ot(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function Zu(e,t,r,n,o){let a=e.length,s=t.length;if(a===0||s===0)return 0;let i=Go(e,n),c=Go(t,o),l=Math.min(i.i+1,a-1),u=Math.min(c.i+1,s-1),m=r[c.i][i.i],p=r[c.i][l],d=r[u][i.i],f=r[u][l],h=m+i.t*(p-m),b=d+i.t*(f-d);return h+c.t*(b-h)}var ds=[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1],Lh={nmc:[0,.29,.4,.483,.525,.567,.608,.667,.733,.8,.892,1],lfp:[0,.478,.591,.626,.652,.67,.678,.696,.704,.722,.757,1],lipo:[0,.333,.433,.517,.575,.625,.667,.717,.775,.833,.908,1],other:[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1]},Lv=[0,.05,.1,.2,.5,.8,1],Dv=[2.2,1.55,1.3,1.12,1,.97,.98];function Ev(e){return ot(Lv,Dv,e)}var Iv=[-20,-10,0,10,25,40,60],_v=[4,2.8,2,1.4,1,.82,.75];function Dh(e){return ot(Iv,_v,e)}var Nv=.5;function Eh(e,t){let{vFull:r,vNom:n,vCut:o,r0:a}=e,s=r-o;if(!(s>0))throw new Error(`The full voltage (${r} V) must be above the cut-off (${o} V).`);let i=(n-o)/s;if(!(i>0&&i<1))throw new Error(`The nominal voltage (${n} V) must lie between the cut-off (${o} V) and full (${r} V).`);let c=Lh[t]??Lh.other,l=e.socAtNom??Nv,u=ds.includes(l)?[...ds]:[...ds,l].sort((h,b)=>h-b),m=ot(ds,c,l),p=m>0&&m<1?Math.log(i)/Math.log(m):1,d=[],f=[];for(let h of u){let b=ot(ds,c,h);d.push(o+s*Math.pow(b,p)),f.push(e.constantResistance?a:a*Ev(h))}return{kind:"table",soc:u,ocv:d,r0:f}}function Ih(e){let t=e.soc,r=e.ocv,n=[0,...t.filter(a=>a>0&&a<1),1],o=0;for(let a=1;a<n.length;a++){let s=n[a-1],i=n[a];o+=(ot(t,r,s)+ot(t,r,i))/2*(i-s)}return o}var ps=25,Ov=new WeakMap;function Cn(e){let t=Ov.get(e);if(t)return t;let r=Qu(e);if(r)throw new Error(r);let{cell:n,pack:o}=e,a=n.curve.kind==="table"?n.curve:Eh(n.curve,n.chemistry),s=o.series,i=o.parallel,c=s/i,l=a.rTempC,u=a.rGrid,m=i*n.capacityAh,p=s*n.vMin,d=n.iMaxA>0?i*n.iMaxA:1/0,f=n.iMaxChargeA!==void 0&&n.iMaxChargeA>0?n.iMaxChargeA:n.iMaxA/4,h=f>0?i*f:1/0,b=C=>s*ot(a.soc,a.ocv,C),g=(C,F=ps)=>{let T=l&&u?Zu(a.soc,l,u,C,F):ot(a.soc,a.r0,C)*Dh(F);return c*T+o.busResistance},y=(C,F,T)=>b(C)-F*g(C,T),x=(C,F,T)=>{if(!(C>0))return 0;let M=b(F),k=g(F,T);if(!(k>0))return C/M;let w=M*M-4*k*C;return w<0?NaN:2*C/(M+Math.sqrt(w))},R=(C,F,T)=>{if(!(C>0))return 0;let M=b(F),k=g(F,T);return k>0?2*C/(M+Math.sqrt(M*M+4*k*C)):C/M},v=C=>{let F=e.thermal;if(!F||F.derateFromC===void 0)return 1;let T=F.derateToC??F.derateFromC;return C<=F.derateFromC?1:!(T>F.derateFromC)||C>=T?0:1-(C-F.derateFromC)/(T-F.derateFromC)},S=(C,F,T=0)=>{let M=b(C),k=g(C,F),w=k>0?M/(2*k):1/0,P=G=>{if(!(k>0))return G*M;let B=Math.min(G,w);return B*(M-B*k)},L=k>0?Math.max(0,(M-p)/k):1/0,E=T>0&&Number.isFinite(T)?T:1/0,_=k>0?P(L):1/0,D=Number.isFinite(d)?P(d):1/0,I=k>0?M*M/(4*k):1/0,N=[["rules",E],["voltage-floor",_],["current",D],["matched-load",I]],O=N[0][0],V=N[0][1];for(let[G,B]of N)B<V&&(V=B,O=G);let H=v(F??ps);H<1&&(V=Number.isFinite(V)?V*H:V,O="temperature");let U=Number.isFinite(V)?x(V,C,F):1/0;return{watts:V,binding:O,rules:E,voltageFloor:_,current:D,matchedLoad:I,derate:H,amps:U,volts:Number.isFinite(U)?M-U*k:M}},A={model:e,table:a,capacityAh:m,chargeC:m*3600,energyKwh:m*(s*Ih(a))/1e3,socRange:[a.soc[0],a.soc[a.soc.length-1]],voltageAtFull:s*a.ocv[a.ocv.length-1],voltageCeiling:s*n.vMax,voltageFloor:p,currentCeiling:d,chargeCurrentCeiling:h,massKg:n.massKg!==void 0?s*i*n.massKg:null,thermal:e.thermal?{heatCapacityJPerK:s*i*e.thermal.heatCapacityJPerK,coolingWPerK:s*i*e.thermal.coolingWPerK,...e.thermal.startC!==void 0?{startC:e.thermal.startC}:{},entropicVPerK:s*(e.thermal.entropicVPerK??0)}:null,derateAt:v,ocv:b,resistance:g,terminalVoltage:y,currentFor:x,chargeCurrentFor:R,maxPower:S};return Ov.set(e,A),A}function _h(e){return{name:e.name,chemistry:e.chemistry,capacityAh:e.capacityAh,curve:{kind:"analytic",vFull:e.vFull,vNom:e.vNom,vCut:e.vCut,r0:e.r0},iMaxA:e.iMaxA,...e.iMaxChargeA!==void 0?{iMaxChargeA:e.iMaxChargeA}:{},vMin:e.vCut,vMax:e.vFull,...e.massKg!==void 0?{massKg:e.massKg}:{}}}var Vv={name:"High-power NMC pouch 4.0 Ah",chemistry:"nmc",capacityAh:4,vCut:3,vNom:3.6,vFull:4.2,r0:.0025,iMaxA:100,iMaxChargeA:40,massKg:.09},Bv={name:"LFP prismatic 20 Ah",chemistry:"lfp",capacityAh:20,vCut:2.5,vNom:3.2,vFull:3.65,r0:.002,iMaxA:200,iMaxChargeA:60,massKg:.4},$v={name:"NMC cylindrical 3.4 Ah",chemistry:"nmc",capacityAh:3.4,vCut:3,vNom:3.6,vFull:4.2,r0:.03,iMaxA:10,iMaxChargeA:3,massKg:.048};function Nh(){return{name:"Formula Student accumulator",cell:_h(Vv),pack:{series:140,parallel:2,busResistance:.02,seriesPerSegment:28},provenance:{source:"assumed",note:"Assumed high-power NMC pouch pack sized to the Formula Student rules; the cell curve and resistance are class-level guesses, not a measurement."}}}function Oh(){return{name:"LFP pack",cell:_h(Bv),pack:{series:160,parallel:1,busResistance:.02,seriesPerSegment:32},provenance:{source:"assumed",note:"Assumed LFP prismatic pack; the flat plateau is the chemistry, the numbers are class-level guesses."}}}function Vh(){return{name:"Road car pack",cell:_h($v),pack:{series:96,parallel:74,busResistance:.01},provenance:{source:"assumed",note:"Assumed road-electric pack of cylindrical energy cells; capacity and voltage are class-typical, the resistance is a guess."}}}function Bh(e,t,r="Constant pack"){return{name:r,cell:{name:"Constant cell",chemistry:"other",capacityAh:e,curve:{kind:"table",soc:[0,1],ocv:[t,t],r0:[0,0]},iMaxA:0,vMin:0,vMax:t},pack:{series:1,parallel:1,busResistance:0},provenance:{source:"assumed",note:"The constant pack: one open-circuit voltage, no internal resistance and no current limit \u2014 what a car carried before the battery was a model. It cannot sag, so its power never fades."}}}function Qi(e){if(e.kind==="ice"){let n=e.gearbox.efficiency;return{model:e,maxTorque:o=>o>e.limitRpm?0:ot(e.rpm,e.torque,o),efficiency:()=>n}}let t=n=>ot(e.rpm,e.torque,n),r=e.kind==="simple"?()=>e.efficiency:(n,o)=>Zu(e.effRpm,e.effTorque,e.effGrid,n,o);return{model:e,maxTorque:t,efficiency:r}}function $h(e){let t=e.resistanceAtC??20,r=e.torqueConstant,n=e.speedLossW??0,o=e.speedLossAtRpm??0,a=e.speedLossExponent??1.5,s=e.derateFromC,i=e.derateToC,c=f=>Math.max(0,e.terminalResistanceOhm*(1+.00393*(f-t))),l=f=>n>0&&o>0?n*Math.pow(Math.max(0,f)/o,a):0,u=(f,h,b)=>{let g=r>0?Math.abs(h)/r:0;return 1.5*c(b)*g*g+l(f)},m=(f,h)=>{let b=e.coolingWPerK*(h-e.coolantC)-l(f);return!(b>0)||r<=0?0:r*Math.sqrt(b/(1.5*c(h)))},p=e.coolingWPerK>0?e.heatCapacityJPerK/e.coolingWPerK:1/0,d=Number.isFinite(p)?.25*p:1/0;return{spec:e,startC:e.startC??e.coolantC,lossW:u,step(f,h,b){if(!(b>0)||!(e.heatCapacityJPerK>0))return f;let g=Number.isFinite(d)?Math.max(1,Math.ceil(b/d)):1,y=b/g,x=f;for(let R=0;R<g;R++)x+=(h-e.coolingWPerK*(x-e.coolantC))*y/e.heatCapacityJPerK;return x},continuousTorque:m,derate(f,h,b){if(s===void 0||i===void 0||!(i>s)||!(b>0)||h<=s)return 1;let g=Math.min(1,m(f,i)/b);return h>=i?g:1-(1-g)*(h-s)/(i-s)},equilibriumC(f){return e.coolingWPerK>0?e.coolantC+f/e.coolingWPerK:1/0}}}function xt(e,t){return t==="rear"&&e.tireRateRear!==void 0?e.tireRateRear:e.tireRate}function Gh(e,t){let r=e.tyreFreeRadiusRear;return(t==="rear"&&r!==void 0?r:e.tyreFreeRadius)??0}var Ju=9.81,Gv=(e,t)=>e*(t*t)/2*(Math.PI/180)/1e3,Zi=(e,t)=>e+t>0?e*t/(e+t):0,Kv=.5;function em(e,t,r){if(!(r>0))return 1;let n=e*Ju*t*(Math.PI/180)/r;return 1/(1-Math.min(Kv,n))}function Hv(e,t,r,n){let o=r??0,a=e+t;if(!(o>0)||!Number.isFinite(o)||!(a>0))return null;let s=Math.max(0,Math.min(1,n)),i=e*t+o*a,c=a*(s*t+o)/i,l=a*((1-s)*e+o)/i;return{share:e/a*c,front:c,rear:l}}function Kh(e,t,r){return r>0?e*Ju*t/(r*r):0}function zv(e,t,r,n,o){if(!(n>0)||!(o>0))return 1;let a=Kh(e,t,r)*(1/n+1/o);return 1/(1-Math.min(Kv,a))}function Ge(e){let t=4*e.unsprungPerCorner,r=Math.max(0,e.massTotal-t),n=r*e.frontMassFrac,o=r*(1-e.frontMassFrac),a=xt(e,"front"),s=xt(e,"rear"),i=e.wheelRateFront+(e.heaveSpringFront??0),c=e.wheelRateRear+(e.heaveSpringRear??0),l=Zi(i,a),u=Zi(c,s),m=(V,H)=>{let U=H/2;return U>0?1/(2*Math.PI)*Math.sqrt(V*1e3/U):0},p=m(l,n),d=m(u,o),f=Zi(e.wheelRateFront+e.arbFront,a),h=Zi(e.wheelRateRear+e.arbRear,s),b=Gv(f,e.trackFront),g=Gv(h,e.trackRear),y=b+g,x=y>0?b/y:.5,R=e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac),v=(e.cgHeight-R)/1e3,S=r*Ju*v,A=em(r,v,y),C=y>0?S/y*A:0,F=Hv(b,g,e.chassisTorsion,e.frontMassFrac),T=F?F.share:x,M=F?C*F.front:C,k=F?C*F.rear:C,w=e.massTotal*Ju*e.cgHeight/e.wheelbase,P=2*l,L=2*u,E=zv(r,e.cgHeight,e.wheelbase,P,L),D=(P>0&&L>0?(w/P+w/L)/e.wheelbase*E:0)*(180/Math.PI),I=e.wheelbase*e.wheelbase*Zi(P,L)*(Math.PI/180)/1e3,N=e.damperFront??2.5,O=e.damperRear??2.5;return{sprungMass:r,sprungFront:n,sprungRear:o,rideRateFront:l,rideRateRear:u,rideFreqFront:p,rideFreqRear:d,rollRateFront:b,rollRateRear:g,rollRateTotal:y,rollWheelRateFront:f,rollWheelRateRear:h,frontRollStiffFrac:x,frontElasticShare:T,rollGradient:C,rollGradientFront:M,rollGradientRear:k,pitchGradient:D,pitchRate:I,cgRollGain:A,cgPitchGain:E,rideDampingFront:N+(e.heaveDamperFront??0),rideDampingRear:O+(e.heaveDamperRear??0),rollDampingFront:N+(e.rollDamperFront??0),rollDampingRear:O+(e.rollDamperRear??0)}}var mo=["clFront","clRear","cd"],po=e=>e.frame?.kind==="pitch";function fs(e){return po(e)?{x:e.axes.h,y:e.axes.pitch}:{x:e.axes.hFront,y:e.axes.hRear}}var tm=e=>e.frame?.kind==="pitch",Yv=e=>e.kind==="map";var rm=45,St=e=>typeof e=="number"&&Number.isFinite(e);function nm(e,t,r="mm",n="ride height"){if(!Array.isArray(t)||t.length<1)return`The ${e} axis needs at least one ${n}.`;if(!t.every(St))return`The ${e} axis contains a value that is not a number.`;for(let o=1;o<t.length;o++)if(!(t[o]>t[o-1]))return`The ${e} axis must increase (${t[o-1]} then ${t[o]} ${r}).`;return null}function Wv(e,t){if(t===void 0)return null;for(let r of mo){let n=t[r];if(!n||!Array.isArray(n.deg)||!Array.isArray(n.factor))return`The ${e} correction of ${r} needs degrees and factors.`;if(n.deg.length<1)return`The ${e} correction of ${r} needs at least one angle.`;if(n.deg.length!==n.factor.length)return`The ${e} correction of ${r} has ${n.factor.length} factors against ${n.deg.length} angles.`;if(!n.deg.every(St)||!n.factor.every(St))return`The ${e} correction of ${r} contains a value that is not a number.`;if(n.deg[0]<0)return`The ${e} correction of ${r} is against the absolute angle; it cannot start below zero.`;for(let o=1;o<n.deg.length;o++)if(!(n.deg[o]>n.deg[o-1]))return`The ${e} correction of ${r} must increase in angle (${n.deg[o-1]} then ${n.deg[o]}\xB0).`;if(n.factor.some(o=>o<0))return`The ${e} correction of ${r} has a negative factor.`}return null}function jv(e,t){return t===void 0?null:!St(t.dCl)||!St(t.dBalance)||!St(t.dCd)?`The ${e} slopes must be numbers.`:!St(t.maxDeg)||!(t.maxDeg>0)?`The ${e} response needs a positive angle to be valid to.`:null}function Ji(e){if(!e||typeof e!="object")return"Not an aero model.";if(!St(e.area)||e.area<=0)return"The reference area must be a positive number of square metres.";if(e.kind==="map"){let t,r,n,o;if(e.frame==null){let i=nm("front ride-height",e.axes?.hFront);if(i)return i;let c=nm("rear ride-height",e.axes?.hRear);if(c)return c;[t,r,n,o]=[e.axes.hFront,e.axes.hRear,"front ride heights","rear ride heights"]}else if(e.frame?.kind==="pitch"){if(!St(e.frame.refX))return"The point the ride height is read at must be a number of millimetres aft of the front axle.";let i=nm("ride-height",e.axes?.h);if(i)return i;let c=nm("pitch",e.axes?.pitch,"\xB0","pitch");if(c)return c;let l=e.axes.pitch.find(u=>Math.abs(u)>=rm);if(l!==void 0)return`A pitch of ${l}\xB0 is not a car's attitude \u2014 is the axis a rake in millimetres? Pitch is in degrees.`;[t,r,n,o]=[e.axes.h,e.axes.pitch,"ride heights","pitches"]}else return`Unknown aero map frame "${e.frame.kind}".`;let a=t.length,s=r.length;for(let i of mo){let c=e[i];if(!Array.isArray(c)||c.length!==s)return`${i} has ${Array.isArray(c)?c.length:0} rows against ${s} ${o} \u2014 they must match.`;for(let l=0;l<s;l++){let u=c[l];if(!Array.isArray(u)||u.length!==a)return`${i} row ${l+1} has ${Array.isArray(u)?u.length:0} values against ${a} ${n}.`;if(!u.every(St))return`${i} contains a value that is not a number.`}}return Wv("yaw",e.attitude?.yaw)??Wv("roll",e.attitude?.roll)}if(e.kind==="sensitivity"){let t;if(e.frame==null)t=["hFront","hRear"];else if(e.frame?.kind==="pitch"){if(!St(e.frame.refX))return"The point the ride height is read at must be a number of millimetres aft of the front axle.";t=["h","pitch"]}else return`Unknown aero sensitivity frame "${e.frame.kind}".`;let r=e.ref,n=e.slope,o=e.range,a=s=>s==="pitch"?"\xB0":" mm";if(!r||!St(r[t[0]])||!St(r[t[1]]))return e.frame?"The reference ride height and pitch must be numbers.":"The reference ride heights must be numbers.";for(let s of mo){if(!e.at||!St(e.at[s]))return`${s} at the reference must be a number.`;let i=n?.[s];if(!i||!St(i[t[0]])||!St(i[t[1]]))return`The slopes of ${s} must be numbers.`}for(let s of t){let i=o?.[s],c=r[s];if(!i||!St(i[0])||!St(i[1]))return`The ${s} range must be two numbers.`;if(!(i[1]>i[0]))return`The ${s} range must run from low to high (${i[0]} to ${i[1]}${a(s)}).`;if(c<i[0]||c>i[1])return`The reference ${s} of ${c}${a(s)} lies outside its range ${i[0]}\u2013${i[1]}${a(s)}.`;if(s==="pitch"&&(Math.abs(i[0])>=rm||Math.abs(i[1])>=rm))return`A pitch range reaching ${Math.abs(i[0])>=rm?i[0]:i[1]}\xB0 is not a car's attitude. Pitch is in degrees.`}return jv("yaw",e.attitude?.yaw)??jv("roll",e.attitude?.roll)}return`Unknown aero model kind "${e.kind}".`}var Uv=180/Math.PI;function hs(e,t,r,n){let o=(n-r)/t;return{h:r+e.refX*o,pitch:Math.atan(o)*Uv}}function bs(e,t,r,n){let o=Math.tan(n/Uv);return{hFront:r-e.refX*o,hRear:r+(t-e.refX)*o}}var E8=180/Math.PI,VI=["hFront","hRear"],BI=["h","pitch"],Yh=e=>e?.kind==="pitch"?BI:VI,sr=(e,t)=>e[t],om=(e,t)=>e[t],Hh=(e,t)=>({[e[0]]:t(e[0]),[e[1]]:t(e[1])});function $I(e){if(!(!e.yaw&&!e.roll))return{...e.yaw?{yaw:{...e.yaw}}:{},...e.roll?{roll:{...e.roll}}:{}}}function Wh(e){let t=Yh(e.frame),r=e.balanceFront,n=e.cl*r,o=e.cl*(1-r),a=Hh(t,c=>sr(e.dCl,c)*r+e.cl*sr(e.dBalance,c)),s=Hh(t,c=>sr(e.dCl,c)*(1-r)-e.cl*sr(e.dBalance,c)),i=$I(e);return{kind:"sensitivity",name:e.name,area:e.area,...e.frame?{frame:{...e.frame}}:{},ref:{...e.ref},at:{clFront:n,clRear:o,cd:e.cd},slope:{clFront:a,clRear:s,cd:Hh(t,c=>sr(e.dCd,c))},range:{[t[0]]:[...om(e.range,t[0])],[t[1]]:[...om(e.range,t[1])]},provenance:{...e.provenance},...i?{attitude:i}:{}}}function am(e,t,r){let n=Math.min(Math.abs(r),t.maxDeg),o=e.clFront+e.clRear,a=o!==0?e.clFront/o:.5,s=o+t.dCl*n,i=a+t.dBalance*n,c=e.clFront!==0?s*i/e.clFront:1,l=e.clRear!==0?s*(1-i)/e.clRear:1,u=e.cd!==0?(e.cd+t.dCd*n)/e.cd:1;return{clFront:c,clRear:l,cd:u}}function zh(e,t,r=11){let n=Array.from({length:r},(a,s)=>t.maxDeg*s/(r-1)),o=n.map(a=>am(e,t,a));return{clFront:{deg:[...n],factor:o.map(a=>a.clFront)},clRear:{deg:[...n],factor:o.map(a=>a.clRear)},cd:{deg:[...n],factor:o.map(a=>a.cd)}}}function Xv(e){if(!(!e.attitude?.yaw&&!e.attitude?.roll))return{...e.attitude.yaw?{yaw:zh(e.at,e.attitude.yaw)}:{},...e.attitude.roll?{roll:zh(e.at,e.attitude.roll)}:{}}}function qv(e,t,r,n=0,o=0){let[a,s]=Yh(e.frame),i=t-sr(e.ref,a),c=r-sr(e.ref,s),l={clFront:e.at.clFront+sr(e.slope.clFront,a)*i+sr(e.slope.clFront,s)*c,clRear:e.at.clRear+sr(e.slope.clRear,a)*i+sr(e.slope.clRear,s)*c,cd:e.at.cd+sr(e.slope.cd,a)*i+sr(e.slope.cd,s)*c},u=e.attitude?.yaw?am(e.at,e.attitude.yaw,n):{clFront:1,clRear:1,cd:1},m=e.attitude?.roll?am(e.at,e.attitude.roll,o):{clFront:1,clRear:1,cd:1};return{clFront:l.clFront*u.clFront*m.clFront,clRear:l.clRear*u.clRear*m.clRear,cd:l.cd*u.cd*m.cd}}function jh(e){let[t,r]=Yh(e.frame),n=[...om(e.range,t)],o=[...om(e.range,r)],a=i=>o.map(c=>n.map(l=>i(qv(e,l,c)))),s=Xv(e);return{kind:"map",name:e.name,area:e.area,...e.frame?{frame:{...e.frame}}:{},axes:{[t]:n,[r]:o},clFront:a(i=>i.clFront),clRear:a(i=>i.clRear),cd:a(i=>i.cd),provenance:{...e.provenance},...s?{attitude:s}:{}}}var Uh=180/Math.PI,Qv=new WeakMap,Zv=new WeakMap,Xh=new WeakMap;function fo(e,t){let r=Zv.get(e);if(r)return r;let n=t?.wheelbase,o=n!==void 0?Xh.get(e)?.get(n):void 0;if(o)return o;let a=GI(e),s=a.map;if(!po(s)){let l=KI(e,a);return Zv.set(e,l),l}if(n===void 0||!Number.isFinite(n)||n<=0)throw new Error("A ride-height-and-pitch aero map is read with the car\u2019s wheelbase, and none was given.");let i=HI(e,a,s.frame,n),c=Xh.get(e);return c||(c=new Map,Xh.set(e,c)),c.set(n,i),i}function GI(e){let t=Qv.get(e);if(t)return t;let r=Ji(e);if(r)throw new Error(r);let n=e.kind==="map"?e:jh(e),{x:o,y:a}=fs(n),s=o.length,i=a.length,c=n.attitude?.yaw,l=n.attitude?.roll,u=!!(c||l),m={clFront:1,clRear:1,cd:1,clamped:!1},p=(y,x)=>{let R=Math.abs(x),v=y.clFront.deg[y.clFront.deg.length-1];return{clFront:ot(y.clFront.deg,y.clFront.factor,R),clRear:ot(y.clRear.deg,y.clRear.factor,R),cd:ot(y.cd.deg,y.cd.factor,R),clamped:R>v}},d=(y,x)=>{if(!u)return m;let R=c?p(c,y):m,v=l?p(l,x):m;return{clFront:R.clFront*v.clFront,clRear:R.clRear*v.clRear,cd:R.cd*v.cd,clamped:R.clamped||v.clamped}},f=(y,x,R=0,v=0)=>{let S=Go(o,y),A=Go(a,x),C=Math.min(S.i+1,s-1),F=Math.min(A.i+1,i-1),T=k=>{let w=k[A.i][S.i],P=k[A.i][C],L=k[F][S.i],E=k[F][C],_=w+S.t*(P-w),D=L+S.t*(E-L);return _+A.t*(D-_)},M=d(R,v);return{clFront:u?T(n.clFront)*M.clFront:T(n.clFront),clRear:u?T(n.clRear)*M.clRear:T(n.clRear),cd:u?T(n.cd)*M.cd:T(n.cd),clampedRide:S.clamped||A.clamped,clampedAttitude:M.clamped}},h={x:[o[0],o[s-1]],y:[a[0],a[i-1]]},b=(y,x,R=!1,v=0,S=0)=>{let A=d(v,S),C=Go(o,R?Math.min(Math.max(y,h.x[0]),h.x[1]):y),F=Go(a,R?Math.min(Math.max(x,h.y[0]),h.y[1]):x),T=Math.min(C.i+1,s-1),M=Math.min(F.i+1,i-1),k=T>C.i?o[T]-o[C.i]:0,w=M>F.i?a[M]-a[F.i]:0,P={};for(let L of mo){let E=n[L],_=E[F.i][C.i],D=E[F.i][T],I=E[M][C.i],N=E[M][T],O=C.clamped||k===0?0:((D-_)*(1-F.t)+(N-I)*F.t)/k,V=F.clamped||w===0?0:((I-_)*(1-C.t)+(N-D)*C.t)/w;P[L]=u?{x:O*A[L],y:V*A[L]}:{x:O,y:V}}return P},g={map:n,x:h.x,y:h.y,hasAttitude:u,factors:d,at:f,slopes:b};return Qv.set(e,g),g}function KI(e,t){let r={x:t.x,y:t.y,at:t.at,toAxles:(o,a)=>({hFront:o,hRear:a}),fromAxles:(o,a)=>({x:o,y:a})},n=(o,a,s=!1,i=0,c=0)=>{let l=t.slopes(o,a,s,i,c),u={};for(let m of mo)u[m]={hFront:l[m].x,hRear:l[m].y};return u};return{model:e,map:t.map,area:t.map.area,grid:r,hasAttitude:t.hasAttitude,at:t.at,slopes:n,factors:t.factors}}function HI(e,t,r,n){let o=r.refX,a=o/n,s=(l,u,m=0,p=0)=>{let d=(u-l)/n;return t.at(l+o*d,Math.atan(d)*Uh,m,p)},i=(l,u,m=!1,p=0,d=0)=>{let f=(u-l)/n,h=t.slopes(l+o*f,Math.atan(f)*Uh,m,p,d),b=Uh/(n*(1+f*f)),g={};for(let y of mo)g[y]={hFront:h[y].x*(1-a)-h[y].y*b,hRear:h[y].x*a+h[y].y*b};return g},c={frame:r,x:t.x,y:t.y,at:t.at,toAxles:(l,u)=>bs(r,n,l,u),fromAxles:(l,u)=>{let m=hs(r,n,l,u);return{x:m.h,y:m.pitch}}};return{model:e,map:t.map,area:t.map.area,grid:c,hasAttitude:t.hasAttitude,at:s,slopes:i,factors:t.factors}}function qh(e){let t=e.clFront+e.clRear;return{cl:t,balanceFront:t!==0?e.clFront/t:.5}}var we=(e,t)=>e*t/100,Rt=e=>e/100,Jv={name:"Formula Student aero",area:1,cl:3,balanceFront:.45,cd:1.3,ref:{hFront:30,hRear:35},range:{hFront:[5,60],hRear:[10,70]},dCl:{hFront:we(3,-.4),hRear:we(3,.1)},dBalance:{hFront:Rt(-.3),hRear:Rt(.15)},dCd:{hFront:we(1.3,-.1),hRear:we(1.3,.05)},yaw:{dCl:we(3,-1),dBalance:Rt(-.3),dCd:we(1.3,.5),maxDeg:10},roll:{dCl:we(3,-.5),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for an undertray-and-wings Formula Student car, ride height, yaw and roll; not measured."},ek={name:"Formula 1 aero",area:1.5,cl:3,balanceFront:.44,cd:.9,ref:{hFront:35,hRear:70},range:{hFront:[0,60],hRear:[20,100]},dCl:{hFront:we(3,-.3),hRear:we(3,-.15)},dBalance:{hFront:Rt(-.15),hRear:Rt(.15)},dCd:{hFront:we(.9,-.15),hRear:we(.9,-.05)},yaw:{dCl:we(3,-1.5),dBalance:Rt(.2),dCd:we(.9,.8),maxDeg:8},roll:{dCl:we(3,-1),dBalance:Rt(-.3),dCd:0,maxDeg:2},note:"Assumed class-level sensitivities for a ground-effect floor, ride height, yaw and roll; not measured."},tk={name:"GT car aero",area:2,cl:1.4,balanceFront:.42,cd:.42,ref:{hFront:55,hRear:75},range:{hFront:[10,90],hRear:[10,110]},dCl:{hFront:we(1.4,-.3),hRear:we(1.4,.05)},dBalance:{hFront:Rt(-.25),hRear:Rt(.15)},dCd:{hFront:we(.42,-.1),hRear:0},yaw:{dCl:we(1.4,-.8),dBalance:Rt(-.2),dCd:we(.42,.6),maxDeg:10},roll:{dCl:we(1.4,-.3),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for a splitter-and-wing GT car, ride height, yaw and roll; not measured."},rk={name:"Sports car aero",area:2.2,cl:-.1,balanceFront:.5,cd:.3,ref:{hFront:130,hRear:140},range:{hFront:[80,180],hRear:[100,200]},dCl:{hFront:-5e-4,hRear:0},dBalance:{hFront:0,hRear:0},dCd:{hFront:2e-4,hRear:0},yaw:{dCl:0,dBalance:0,dCd:we(.3,.5),maxDeg:10},note:"Assumed class-level sensitivities for a road car with no aero devices; not measured."},nk={name:"Cup car aero",area:2.1,cl:.45,balanceFront:.45,cd:.4,ref:{hFront:64,hRear:78},range:{hFront:[20,100],hRear:[30,120]},dCl:{hFront:we(.45,-.4),hRear:we(.45,.05)},dBalance:{hFront:Rt(-.25),hRear:Rt(.15)},dCd:{hFront:we(.4,-.1),hRear:0},yaw:{dCl:we(.45,-1.2),dBalance:Rt(-.2),dCd:we(.4,.6),maxDeg:10},roll:{dCl:we(.45,-.3),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for a splitter-and-wing cup hatchback, ride height, yaw and roll; not measured."},ok={name:"Stock car aero",area:2.2,cl:.6,balanceFront:.45,cd:.45,ref:{hFront:75,hRear:90},range:{hFront:[20,110],hRear:[30,130]},dCl:{hFront:we(.6,-.35),hRear:we(.6,.05)},dBalance:{hFront:Rt(-.25),hRear:Rt(.15)},dCd:{hFront:we(.45,-.1),hRear:0},yaw:{dCl:we(.6,-1),dBalance:Rt(-.2),dCd:we(.45,.6),maxDeg:10},roll:{dCl:we(.6,-.3),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for a splitter-and-spoiler stock car, ride height, yaw and roll; not measured."},ak={name:"Hill-climb prototype aero",area:1.2,cl:2.5,balanceFront:.42,cd:.9,ref:{hFront:45,hRear:55},range:{hFront:[10,80],hRear:[15,95]},dCl:{hFront:we(2.5,-.35),hRear:we(2.5,.05)},dBalance:{hFront:Rt(-.25),hRear:Rt(.15)},dCd:{hFront:we(.9,-.1),hRear:we(.9,.05)},yaw:{dCl:we(2.5,-1),dBalance:Rt(-.3),dCd:we(.9,.5),maxDeg:10},roll:{dCl:we(2.5,-.5),dBalance:0,dCd:0,maxDeg:3},note:"Assumed class-level sensitivities for a winged sports prototype with a flat floor and diffuser, ride height, yaw and roll; not measured."},sk={name:"Race truck aero",area:6.2,cl:-.1,balanceFront:.6,cd:.65,ref:{hFront:240,hRear:240},range:{hFront:[190,290],hRear:[180,300]},dCl:{hFront:-5e-4,hRear:0},dBalance:{hFront:0,hRear:0},dCd:{hFront:2e-4,hRear:0},yaw:{dCl:0,dBalance:0,dCd:we(.65,.5),maxDeg:10},note:"Assumed class-level sensitivities for a cab-over race truck with a chin spoiler and deflectors, ride height and yaw; not measured."};function Tn(e){return Wh({name:e.name,area:e.area,cl:e.cl,balanceFront:e.balanceFront,cd:e.cd,ref:e.ref,range:e.range,dCl:e.dCl,dBalance:e.dBalance,dCd:e.dCd,...e.yaw?{yaw:e.yaw}:{},...e.roll?{roll:e.roll}:{},provenance:{source:"assumed",note:e.note}})}var Qh=()=>Tn(Jv),Zh=()=>Tn(ek),Jh=()=>Tn(tk),eb=()=>Tn(rk),tb=()=>Tn(nk),rb=()=>Tn(ok),nb=()=>Tn(ak),ob=()=>Tn(sk);function Ko(e,t){let r=.5*e.rho*e.area*t*t,n=e.cl*r,o=e.cw*r,a=n*e.copLongFront;return{downforce:n,drag:o,downFront:a,downRear:n-a}}function sm(e,t){let r=e.massTotal;if(!(r>0))return{front:0,rear:0};let n=Math.max(0,Math.min(1,e.frontMassFrac)),o=2*e.unsprungPerCorner,a=(s,i)=>i>0?Math.min(1,s/i):0;return{front:(t.sprungMass*n+o*a(t.rideRateFront,xt(e,"front")))/r,rear:(t.sprungMass*(1-n)+o*a(t.rideRateRear,xt(e,"rear")))/r}}function im(e,t,r,n){let o=t.front*r+t.rear*n;return o===0?e:Math.max(Math.min(1,e),e-o)}function ab(e,t){return e.wheelbase>0?e.massTotal*t*9.81/e.wheelbase:0}function gs(e,t,r){let n=2*t.rideRateFront,o=2*t.rideRateRear;return!(n>0)||!(o>0)?0:Math.min(Kh(t.sprungMass,r,e.wheelbase),.5*n*o/(n+o))}function ec(e,t,r,n,o){let a=e.cgHeight,s=ab(e,r);if(n===0&&o===0&&s===0)return{height:a,forward:0,noseLoad:0,dropFront:0,dropRear:0};let i=sm(e,t),c=2*t.rideRateFront,l=2*t.rideRateRear,u=a,m=0,p=0,d=0;for(let h=0;h<6;h++){d=gs(e,t,u);let b=n-s*u,g=o+s*u;if(d>0){let R=c*l-d*(c+l);m=(b*(l-d)-d*g)/R,p=(g*(c-d)-d*b)/R}else m=c>0?b/c:0,p=l>0?g/l:0;let y=im(a,i,m,p),x=Math.abs(y-u);if(u=y,x<1e-9)break}let f=m-p;return{height:u,forward:e.wheelbase>0?u*f/e.wheelbase:0,noseLoad:d*f,dropFront:m,dropRear:p}}var sb={yawDeg:0,rollDeg:0},ik=1e-4,zI=40,ck=50;function ho(e,t,r=0){let n=e.aero?.model;if(!(!n||!fo(n,e).hasAttitude))return{yawDeg:r,rollDeg:Ge(e).rollGradient*t}}function ys(e,t){if(e.rideHeightFront!=null&&e.rideHeightRear!=null)return{hFront:e.rideHeightFront,hRear:e.rideHeightRear};let r=e.model,n=(a,s,i)=>{if(t!==void 0&&t>0)return bs(a,t,s,i);throw new Error("A ride-height-and-pitch aero model is read with the car\u2019s wheelbase, and none was given.")},o={hFront:0,hRear:0};if(r?.kind==="sensitivity")o=tm(r)?n(r.frame,r.ref.h,r.ref.pitch):r.ref;else if(r){let{x:a,y:s}=fs(r),i=(a[0]+a[a.length-1])/2,c=(s[0]+s[s.length-1])/2;o=po(r)?n(r.frame,i,c):{hFront:i,hRear:c}}return{hFront:e.rideHeightFront??o.hFront,hRear:e.rideHeightRear??o.hRear}}var lk=new WeakMap;function Pn(e,t,r=0,n){let o=e.aero;if(!o?.model)return null;let a=lk.get(e);a||(a=new Map,lk.set(e,a));let s=n&&fo(o.model,e).hasAttitude?n:sb,i=s===sb?`${t}|${r}`:`${t}|${r}|${s.yawDeg.toFixed(3)}|${s.rollDeg.toFixed(3)}`,c=a.get(i);if(c)return c;let l=YI(e,o,t,r,s);return a.size>4096&&a.clear(),a.set(i,l),l}function YI(e,t,r,n,o){let a=fo(t.model,e),s=Ge(e),i=2*s.rideRateFront,c=2*s.rideRateRear,l=ys(t,e.wheelbase),u=.5*t.rho*r*r,m=a.area,p=e.wheelbase>0?t.copHeight/e.wheelbase:0,d=sm(e,s),f=ab(e,n),h=(T,M)=>im(e.cgHeight,d,l.hFront-T,l.hRear-M),b=(T,M)=>l.hFront-T-(l.hRear-M),g=(T,M)=>{let k=a.at(T,M,o.yawDeg,o.rollDeg),w=u*m*k.clFront,P=u*m*k.clRear,L=u*m*k.cd,E=L*p,_=h(T,M),D=f*_,I=gs(e,s,_)*b(T,M),N=w-D-E+I,O=P+D+E-I,V=T-l.hFront+(i>0?N/i:0),H=M-l.hRear+(c>0?O/c:0);return{c:k,downFront:w,downRear:P,drag:L,rF:V,rR:H,norm:Math.hypot(V,H)}},y=(T,M,k=!1)=>{let w=a.slopes(T,M,k,o.yawDeg,o.rollDeg),P=i>0?u*m/i:0,L=c>0?u*m/c:0;return[[P*(w.clFront.hFront-p*w.cd.hFront),P*(w.clFront.hRear-p*w.cd.hRear)],[L*(w.clRear.hFront+p*w.cd.hFront),L*(w.clRear.hRear+p*w.cd.hRear)]]},x=l.hFront,R=l.hRear,v=g(x,R),S=0;for(;v.norm>=ik&&S<zI;){S++;let T=y(x,R),M=i>0?f/i:0,k=c>0?f/c:0,w=gs(e,s,h(x,R)),P=i>0?w/i:0,L=c>0?w/c:0,E=1+T[0][0]-M*d.front-P,_=T[0][1]-M*d.rear+P,D=T[1][0]+k*d.front+L,I=1+T[1][1]+k*d.rear-L,N=E*I-_*D,O,V;Math.abs(N)>1e-9?(O=-(I*v.rF-_*v.rR)/N,V=-(-D*v.rF+E*v.rR)/N):(O=-.5*v.rF,V=-.5*v.rR);let H=Math.max(1,Math.abs(O)/ck,Math.abs(V)/ck);O/=H,V/=H;let U=1;for(let G=0;G<6;G++){let B=g(x+U*O,R+U*V);if(B.norm<=v.norm||G===5){x+=U*O,R+=U*V,v=B;break}U*=.5}}let A=y(x,R,!0),C=2+A[0][0]+A[1][1],F=(1+A[0][0])*(1+A[1][1])-A[0][1]*A[1][0];return{v:r,axG:n,hFront:x,hRear:R,cgHeight:h(x,R),cgForward:e.wheelbase>0?h(x,R)*b(x,R)/e.wheelbase:0,cgNoseLoad:gs(e,s,h(x,R))*b(x,R),clFront:v.c.clFront,clRear:v.c.clRear,cd:v.c.cd,area:m,downforce:v.downFront+v.downRear,drag:v.drag,downFront:v.downFront,downRear:v.downRear,gain:WI(A),stable:F>0&&C>0,converged:v.norm<ik,iterations:S,clampedRide:v.c.clampedRide,yawDeg:o.yawDeg,rollDeg:o.rollDeg,clampedAttitude:v.c.clampedAttitude}}function WI(e){let t=e[0][0]+e[1][1],r=e[0][0]*e[1][1]-e[0][1]*e[1][0],n=t*t-4*r;if(n>=0){let o=Math.sqrt(n);return Math.max(Math.abs((t+o)/2),Math.abs((t-o)/2))}return Math.sqrt(r)}function tc(e,t,r=0,n){let o=Pn(e,t,r,n);return o?{downforce:o.downforce,drag:o.drag,downFront:o.downFront,downRear:o.downRear}:e.aero?Ko(e.aero,t):{downforce:0,drag:0,downFront:0,downRear:0}}function jI(e,t,r,n){let o=Ko(t,r),a=Ge(e),s=ys(t,e.wheelbase),i=e.wheelbase>0?o.drag*t.copHeight/e.wheelbase:0,c=ec(e,a,n,o.downFront-i,o.downRear+i),l=o.downforce;return{v:r,axG:n,hFront:s.hFront-c.dropFront,hRear:s.hRear-c.dropRear,cgHeight:c.height,cgForward:c.forward,cgNoseLoad:c.noseLoad,clFront:t.cl*t.copLongFront,clRear:t.cl*(1-t.copLongFront),cd:t.cw,area:t.area,downforce:l,drag:o.drag,downFront:o.downFront,downRear:o.downRear,gain:0,stable:!0,converged:!0,iterations:0,clampedRide:!1,yawDeg:0,rollDeg:0,clampedAttitude:!1}}function ib(e,t,r=0,n){let o=Pn(e,t,r,n);return o||(e.aero?jI(e,e.aero,t,r):null)}function cm(e,t=0,r=0,n,o){if(e.aero&&t>0){if(e.aero.model){let i=Pn(e,t,r,n);return{height:i.cgHeight,forward:i.cgForward,noseLoad:i.cgNoseLoad}}let a=Ko(e.aero,t),s=e.wheelbase>0?a.drag*e.aero.copHeight/e.wheelbase:0;return ec(e,o??Ge(e),r,a.downFront-s,a.downRear+s)}return r===0?{height:e.cgHeight,forward:0,noseLoad:0}:ec(e,o??Ge(e),r,0,0)}var uk=[0,1,0],cb=[0,0,1],ne=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],$=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Q=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],lb=e=>[-e[0],-e[1],-e[2]],Z=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],me=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],UI=e=>Z(e,e),Zr=e=>Math.sqrt(Z(e,e)),rc=(e,t)=>UI($(e,t)),Le=(e,t)=>Zr($(e,t)),ee=e=>{let t=Zr(e);return t<1e-12?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]},mk=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r];var Ln=(e,t,r)=>{let n=ee(r),o=$(e,t);return ne(t,Q(n,Z(o,n)))},dk=(e,t,r)=>Le(e,Ln(e,t,r));var qI=1e-6;function QI(e){if(e<qI){let n=e*e;return[1-n/6,.5-n/24]}let t=Math.sin(e),r=Math.cos(e);return[t/e,(1-r)/(e*e)]}function _t(e,t){let r=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(r<1e-14)return t;let[n,o]=QI(r),a=me(e,t),s=me(e,a);return ne(t,ne(Q(a,n),Q(s,o)))}function ir(e,t,r){let n=Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);if(n<1e-14)return e;let o=[t[0]/n,t[1]/n,t[2]/n];return _t(Q(o,r),e)}function Jr(e,t){let r=t.length,n=e.map(a=>a.slice()),o=t.slice();return fk(n,o,r,new Array(r).fill(0))}function pk(e,t,r){return fk(e,t,t.length,r)}function fk(e,t,r,n){let o=1/0,a=0;for(let s=0;s<r;s++){let i=s,c=Math.abs(e[s][s]);for(let u=s+1;u<r;u++){let m=Math.abs(e[u][s]);m>c&&(c=m,i=u)}if(c<1e-14){for(let u=0;u<r;u++)n[u]=NaN;return{x:n,condProxy:1/0,singular:!0}}if(o=Math.min(o,c),a=Math.max(a,c),i!==s){let u=e[s];e[s]=e[i],e[i]=u;let m=t[s];t[s]=t[i],t[i]=m}let l=e[s][s];for(let u=s+1;u<r;u++){let m=e[u][s]/l;if(m!==0){for(let p=s;p<r;p++)e[u][p]-=m*e[s][p];t[u]-=m*t[s]}}}for(let s=r-1;s>=0;s--){let i=t[s];for(let c=s+1;c<r;c++)i-=e[s][c]*n[c];n[s]=i/e[s][s]}return{x:n,condProxy:a/o,singular:!1}}var hk=e=>{let t=0;for(let r of e)t=Math.max(t,Math.abs(r));return t},bk=e=>{let t=0;for(let r of e)t+=r*r;return t},ZI=Math.sqrt(Number.EPSILON);function gk(e,t,r={}){let n=r.maxIter??60,o=r.tol??1e-10,a=t.length,s=r.scales??new Array(a).fill(1),i=t.slice(),c=e(i),l=hk(c),u=bk(c),m=.001,p=1,d=c.length,f=Array.from({length:d},()=>new Array(a).fill(0)),h=Array.from({length:a},()=>new Array(a).fill(0)),b=Array.from({length:a},()=>new Array(a).fill(0)),g=new Array(a).fill(0),y=new Array(a).fill(0),x=new Array(a).fill(0),R=new Array(a).fill(0),v=new Array(a).fill(0);for(let S=0;S<n;S++){if(l<o)return{x:i,residualNorm:l,iterations:S,converged:!0,condProxy:p};for(let T=0;T<a;T++){let M=ZI*Math.max(Math.abs(i[T]),s[T]);for(let w=0;w<a;w++)R[w]=i[w];R[T]+=M;let k=e(R);for(let w=0;w<d;w++)f[w][T]=(k[w]-c[w])/M}let A=0;for(let T=0;T<a;T++){for(let k=0;k<a;k++){let w=0;for(let P=0;P<d;P++)w+=f[P][T]*f[P][k];h[T][k]=w}let M=0;for(let k=0;k<d;k++)M+=f[k][T]*c[k];g[T]=M,A=Math.max(A,h[T][T])}let C=Math.max(A,1e-9),F=!1;for(let T=0;T<18;T++){let M=m*C;for(let w=0;w<a;w++){let P=h[w],L=b[w];for(let E=0;E<a;E++)L[E]=w===E?P[E]+M:P[E];y[w]=-g[w]}let k=pk(b,y,x);if(p=Math.max(p,k.condProxy),!k.singular){for(let L=0;L<a;L++)v[L]=i[L]+x[L];let w=e(v),P=bk(w);if(P<u){for(let L=0;L<a;L++)i[L]=v[L];c=w,u=P,l=hk(c),m=Math.max(m*.3,1e-12),F=!0;break}}m=Math.min(m*4,1e12)}if(!F)break}return{x:i,residualNorm:l,iterations:n,converged:l<o,condProxy:p}}function nc(e,t,r,n){let o=e*e+t*t,a=Math.sqrt(o);if(!(a>1e-12*n))return{c1:1,s1:0,c2:1,s2:0,margin:0,ok:!1,free:!0};let s=Math.abs(r),i=1-s/a;if(i<0){let l=r>=0?1:-1,u=l*e/a,m=l*t/a;return{c1:u,s1:m,c2:u,s2:m,margin:i,ok:i>=-1e-12,free:!1}}let c=Math.sqrt((a-s)*(a+s));return{c1:(e*r-t*c)/o,s1:(t*r+e*c)/o,c2:(e*r+t*c)/o,s2:(t*r-e*c)/o,margin:i,ok:!0,free:!1}}function ub(e,t){return[e[0]*t[0]-e[1]*t[1]-e[2]*t[2]-e[3]*t[3],e[0]*t[1]+e[1]*t[0]+e[2]*t[3]-e[3]*t[2],e[0]*t[2]-e[1]*t[3]+e[2]*t[0]+e[3]*t[1],e[0]*t[3]+e[1]*t[2]-e[2]*t[1]+e[3]*t[0]]}var yk=e=>[e[0],-e[1],-e[2],-e[3]];function xs(e,t){let[r,n,o,a]=e,s=2*(o*t[2]-a*t[1]),i=2*(a*t[0]-n*t[2]),c=2*(n*t[1]-o*t[0]);return[t[0]+r*s+(o*c-a*i),t[1]+r*i+(a*s-n*c),t[2]+r*c+(n*i-o*s)]}function lm(e,t){let r=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];if(1+r<1e-14){let o=Math.abs(e[0])<.6?[1,0,0]:[0,1,0],a=e[1]*o[2]-e[2]*o[1],s=e[2]*o[0]-e[0]*o[2],i=e[0]*o[1]-e[1]*o[0],c=Math.hypot(a,s,i);return[0,a/c,s/c,i/c]}let n=Math.sqrt(2*(1+r));return[(1+r)/n,(e[1]*t[2]-e[2]*t[1])/n,(e[2]*t[0]-e[0]*t[2])/n,(e[0]*t[1]-e[1]*t[0])/n]}function xk(e,t,r){let n,o;return t>=0?(n=Math.sqrt((1+t)/2),o=r/(2*n)):(o=(r>=0?1:-1)*Math.sqrt((1-t)/2),n=r/(2*o)),[n,o*e[0],o*e[1],o*e[2]]}function mb(e,t,r){let n=e[0],o=e[1],a=e[2],s=t[0],i=t[1],c=t[2],l=r[0],u=r[1],m=r[2],p=n+i+m;if(p>=n&&p>=i&&p>=m){let h=Math.sqrt(1+p),b=.5/h;return[.5*h,(c-u)*b,(l-a)*b,(o-s)*b]}if(n>=i&&n>=m){let h=Math.sqrt(1+n-i-m),b=.5/h;return[(c-u)*b,.5*h,(s+o)*b,(l+a)*b]}if(i>=m){let h=Math.sqrt(1-n+i-m),b=.5/h;return[(l-a)*b,(s+o)*b,.5*h,(u+c)*b]}let d=Math.sqrt(1-n-i+m),f=.5/d;return[(o-s)*f,(l+a)*f,(u+c)*f,.5*d]}function Rk(e){let t=Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);if(t===0)return[1,0,0,0];let r=Math.sin(t/2)/t;return[Math.cos(t/2),r*e[0],r*e[1],r*e[2]]}function vk(e){let[t,r,n,o]=e;t<0&&(t=-t,r=-r,n=-n,o=-o);let a=Math.sqrt(r*r+n*n+o*o);if(a===0)return[0,0,0];let s=2*Math.atan2(a,t)/a;return[s*r,s*n,s*o]}function JI(e){let t=Math.abs(e[0])<.6?[1,0,0]:[0,1,0],r=ee(me(e,t));return[r,me(e,r)]}function e2(e){let t=e.hardpoints,r=ee($(t.damperChassis,t.pushrodOuter)),[n,o]=JI(r);return{top:t.damperChassis,lower0:t.pushrodOuter,axis0:r,e1:n,e2:o}}function db(e){let t=e.hardpoints,r=t.wheelCenter,n=ee($(t.ucaRear,t.ucaFront)),o=$(t.uprightUpper,t.ucaFront),a=Z(o,n),s=$(o,Q(n,a)),i=Z(s,s),c=ee($(t.lcaRear,t.lcaFront)),l=$(t.uprightLower,t.lcaFront),u=rc(t.tieOuter,t.tieInner);return{c0:r,ucaFront:t.ucaFront,ucaDir:n,ubj0:t.uprightUpper,ubjAxial0:a,ubjRadius2:i,lcaFront:t.lcaFront,lcaDir:c,lbj0:t.uprightLower,lbjRel0:l,tro0:t.tieOuter,tieInner0:t.tieInner,tieLen2:u,rackAxis:ee(e.config.rackAxis),steerMovesRack:e.config.steerMode==="rack",ubjRadiusRef:Math.max(1,2*Math.sqrt(i)),tieLenRef:Math.max(1,2*Math.sqrt(u)),...e.config.layout==="mcpherson"?{strut:e2(e)}:{}}}function Mr(e,t,r){let n=[t[3],t[4],t[5]],o=[t[0],t[1],t[2]],a=$(r,e.c0);return ne(ne(_t(n,a),e.c0),o)}function pb(e,t){return ne(e.lcaFront,ir(e.lbjRel0,e.lcaDir,t))}function Ho(e,t){return e.steerMovesRack?ne(e.tieInner0,Q(e.rackAxis,t)):e.tieInner0}function fb(e,t,r,n){let o=Mr(e,t,e.lbj0),a=pb(e,r),s=o[0]-a[0],i=o[1]-a[1],c=o[2]-a[2],l,u;if(e.strut){let f=e.strut,h=[t[3],t[4],t[5]],b=$(f.top,Mr(e,t,f.lower0));l=Z(b,_t(h,f.e1)),u=Z(b,_t(h,f.e2))}else{let f=Mr(e,t,e.ubj0),h=$(f,e.ucaFront),b=Z(h,e.ucaDir),g=$(h,Q(e.ucaDir,b));l=b-e.ubjAxial0,u=(Z(g,g)-e.ubjRadius2)/e.ubjRadiusRef}let m=Mr(e,t,e.tro0),p=Ho(e,n),d=(rc(m,p)-e.tieLen2)/e.tieLenRef;return[s,i,c,l,u,d]}var oc=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]),um=e=>{let t=oc(e);return[e[0]/t,e[1]/t,e[2]/t]},t2=(e,t)=>$(e,Q(t,Z(e,t))),hb=e=>um(me(e,Math.abs(e[0])<.6?[1,0,0]:[0,1,0]));function r2(e,t){let r=e.ucaDir,n=ne(e.ucaFront,Q(r,e.ubjAxial0)),o=Math.sqrt(e.ubjRadius2),a=t2($(e.ubj0,e.ucaFront),r),s=oc(a)>1e-9?um(a):hb(r),i=me(r,s),c=$(e.ubj0,e.lbj0),l=Z(c,c);if(!(l>1e-18))return"free";let u=$(n,t),m=Z(u,u),p=nc(2*o*Z(s,u),2*o*Z(i,u),l-m-o*o,2*o*Math.sqrt(m));if(p.free)return"free";let d=um(c),f=(h,b)=>{let g=ne(n,ne(Q(s,o*h),Q(i,o*b))),y=um($(g,t));return{q1:lm(d,y),k:y,margin:p.margin,ok:p.ok}};return p.margin>0?[f(p.c1,p.s1),f(p.c2,p.s2)]:[f(p.c1,p.s1)]}function n2(e,t,r){let n=t.axis0,o=ne(t.lower0,Q(n,Z($(e.lbj0,t.lower0),n))),a=$(o,e.lbj0),s=oc(a),i=s>1e-9?Q(a,1/s):hb(n),c=$(t.top,r),l=oc(c);if(!(l>1e-9))return"free";let u=Q(c,1/l),m=s/l,p=1-m,d=p>=0?Math.sqrt((1-m)*(1+m)):0,f=hb(u),h=b=>{let g=b*d,y=ne(Q(u,g),Q(f,Math.min(m,1))),x=$(Q(u,Math.min(m,1)),Q(f,g));return{q1:ub(mb(x,y,me(x,y)),yk(mb(i,n,me(i,n)))),k:u,margin:p,ok:p>=0}};return p>0?[h(1),h(-1)]:[h(1)]}function o2(e,t,r,n){let{k:o}=n,a=xs(n.q1,$(e.tro0,e.lbj0)),s=Z(a,o),i=$(a,Q(o,s)),c=oc(i);if(!(c>1e-9))return"free";let l=Q(i,1/c),u=me(o,l),m=ne(t,Q(o,s)),p=$(m,r),d=Z(p,p),f=nc(2*c*Z(p,l),2*c*Z(p,u),e.tieLen2-d-c*c,2*c*Math.sqrt(d));if(f.free)return"free";let h=(g,y)=>({q:ub(xk(o,g,y),n.q1)});return{roots:f.margin>0?[h(f.c1,f.s1),h(f.c2,f.s2)]:[h(f.c1,f.s1)],margin:f.margin,ok:f.ok}}function kk(e,t,r,n=[0,0,0,0,0,0]){let o=pb(e,t),a=Ho(e,r),s=Rk([n[3],n[4],n[5]]),i=h=>Math.abs(h[0]*s[0]+h[1]*s[1]+h[2]*s[2]+h[3]*s[3]),c=e.strut?n2(e,e.strut,o):r2(e,o);if(c==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let l=null,u=null;for(let h of c){let b=o2(e,o,a,h);if(b==="free")return{x:n.slice(),converged:!1,margin:0,free:!0};let g=Math.min(h.margin,b.margin),y=b.ok&&h.ok;for(let{q:x}of b.roots){let R=i(x);y&&(!l||R>l.near)&&(l={q:x,margin:g,near:R}),!y&&(!u||R>u.near)&&(u={q:x,margin:g,near:R})}}let{q:m,margin:p}=l??u,d=vk(m),f=$($(o,e.c0),_t(d,$(e.lbj0,e.c0)));return{x:[f[0],f[1],f[2],d[0],d[1],d[2]],converged:l!==null,margin:p,free:!1}}function Sk(e){let t=ee($(e.rockerPivotB,e.rockerPivotA));return{pivotA:e.rockerPivotA,axis:t,rprRel0:$(e.rockerToPushrod,e.rockerPivotA),rdmRel0:$(e.rockerToDamper,e.rockerPivotA),damperChassis:e.damperChassis,rodLen2:rc(e.pushrodOuter,e.rockerToPushrod),damperLen0:Le(e.rockerToDamper,e.damperChassis)}}var a2=(e,t)=>ne(e.pivotA,ir(e.rprRel0,e.axis,t)),bb=(e,t)=>ne(e.pivotA,ir(e.rdmRel0,e.axis,t));function Rs(e,t){return{pushrod:a2(e,t),damper:bb(e,t)}}function Ak(e,t,r=0){let n=Z(e.rprRel0,e.axis),o=$(e.rprRel0,Q(e.axis,n)),a=me(e.axis,o),s=$(ne(e.pivotA,Q(e.axis,n)),t),i=Z(o,o),c=Z(s,s),l=nc(2*Z(s,o),2*Z(s,a),e.rodLen2-c-i,2*Math.sqrt(i*c));if(l.free){let d=Math.abs(e.rodLen2-c-i)<=1e-9*e.rodLen2;return{phi:r,damperLength:Le(bb(e,r),e.damperChassis),converged:d,margin:0}}let u=Mk(Math.atan2(l.s1,l.c1),r),m=Mk(Math.atan2(l.s2,l.c2),r),p=Math.abs(m-r)<Math.abs(u-r)?m:u;return{phi:p,damperLength:Le(bb(e,p),e.damperChassis),converged:l.ok,margin:l.margin}}function Mk(e,t){let r=2*Math.PI;return e+r*Math.round((t-e)/r)}function wk(e,t,r,n){return ne(t,_t(Q(ee(r),n),$(e,t)))}function Fk(e,t,r,n){let o=ee(n),a=p=>{let d=$(p,r);return $(d,Q(o,Z(d,o)))},s=a(e),i=a(t),c=Math.hypot(s[0],s[1],s[2]),l=Math.hypot(i[0],i[1],i[2]);if(c<1e-9||l<1e-9)return 0;let u=Math.min(1,Math.max(-1,Z(s,i)/(c*l))),m=Z(me(s,i),o)/(c*l);return Math.atan2(m,u)}function Ck(e,t,r,n){return ne(t,_t(Q(ee(r),n),$(e,t)))}var mm=180/Math.PI,s2=(e,t,r)=>Math.max(t,Math.min(r,e)),Tk=[NaN,NaN,NaN];function ac(e){let t=ee(e.spinAxis),r=ee($(e.uprightUpper,e.uprightLower)),n=-Math.asin(s2(t[2],-1,1))*mm,o=Math.atan2(t[0],t[1])*mm,a=Math.atan2(-r[0],r[2])*mm,s=Math.atan2(-r[1],r[2])*mm,i=ee(ne([0,0,-1],Q(t,t[2]))),c=ne(e.wheelCenter,Q(i,e.loadedRadius)),l=e.patchShift?[c[0]+e.patchShift.x,c[1]+e.patchShift.y,c[2]]:c,u=e.uprightLower,m=Math.abs(r[2])>1e-9,p=F=>ne(u,Q(r,(F-u[2])/r[2])),d=m?p(l[2]):Tk,f=m?p(e.wheelCenter[2]):Tk,h=l[1]-d[1],b=d[0]-l[0],g=ee(me(t,[0,0,1])),y=me([0,0,1],g),x=$(l,d),R=Z(x,y),v=-Z(x,g),S=e.wheelCenter[1]-f[1],A=f[0]-e.wheelCenter[0],C=dk(e.tieOuter,u,r);return{camber:n,toe:o,caster:a,kpi:s,scrubRadius:h,mechanicalTrail:b,scrubAtWheel:R,trailAtWheel:v,kingpinOffset:S,casterOffset:A,steeringArm:C,contactPatch:l,kingpinGround:d,kingpinAtHub:f}}function Tt(e){return{corner:e,inv:db(e),rocker:Sk(e.hardpoints)}}var i2=[20,20,20,.2,.2,.2];function Lk(e,t,r,n=[0,0,0,0,0,0]){let o=kk(e,t,r,n);if(!o.free)return o;let a=c2(e,t,r,n);return{x:a.x,converged:a.converged,margin:0}}function c2(e,t,r,n=[0,0,0,0,0,0]){return gk(o=>fb(e,o,t,r),n,{scales:i2,tol:1e-10,maxIter:40})}var l2=.01,dm=1.2,zt=e=>e.ok?e.state:null,Nt=e=>e.ok?e.state:e.nearest;function Ce(e,t,r,n,o){let a=0,s=at(e,a,r,n,o);if(Math.abs(s.travel-t)<1e-4)return Pk(s,t,!1);let c=(at(e,.02,r,gb(s),o).travel-s.travel)/.02;(!Number.isFinite(c)||Math.abs(c)<1e-6)&&(c=1);let l=p=>Math.max(-dm,Math.min(dm,p)),u=l((t-s.travel)/c),m=at(e,u,r,gb(s),o);for(let p=0;p<12&&!(Math.abs(m.travel-t)<1e-4);p++){let d=m.travel-s.travel,f=Math.abs(d)<1e-9?u:u-(m.travel-t)*((u-a)/d);a=u,s=m,u=l(f),m=at(e,u,r,gb(s),o)}return Pk(m,t,Math.abs(u)===dm)}function Pk(e,t,r){let n=e.travel-t,o=Math.abs(n)<=l2,a=r&&!o;return e.converged&&o?{ok:!0,reached:!0,travelMiss:n,clamped:!1,state:e}:{ok:!1,why:e.converged?"unreached":"unconverged",reached:o,travelMiss:n,clamped:a,nearest:e}}function gb(e){return{q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle}}function u2(e,t,r,n,o){switch(e){case"upright":return Mr(t,r,o.pushrodOuter);case"upperArm":{let a=Mr(t,r,t.ubj0),s=Fk(t.ubj0,a,t.ucaFront,t.ucaDir);return Ck(o.pushrodOuter,t.ucaFront,t.ucaDir,s)}default:return wk(o.pushrodOuter,t.lcaFront,t.lcaDir,n)}}function at(e,t,r,n,o){let{inv:a,corner:s}=e,i=n?.q??[0,0,0,0,0,0],c=Lk(a,t,r,i),l=c.x,u=[l[3],l[4],l[5]],m={t:[l[0],l[1],l[2]],omega:u},p=s.hardpoints,d=s.config,f=a.strut,h=f?f.top:Mr(a,l,p.uprightUpper),b=Mr(a,l,p.uprightLower),g=Mr(a,l,p.tieOuter),y=Mr(a,l,p.wheelCenter),x=ee(_t(u,d.spinAxis)),R=u2(f?"upright":d.pushrodAttach,a,l,t,p),v=f?f.top:p.damperChassis,S=f||d.actuation==="direct"?{phi:0,damperLength:Le(R,v),converged:!0,margin:1}:Ak(e.rocker,R,n?.phi??0),A=ac({uprightUpper:h,uprightLower:b,wheelCenter:y,spinAxis:x,tieOuter:g,loadedRadius:o?.loadedRadius??d.loadedRadius,patchShift:o?.patchShift});return{pose:m,beta:t,travel:l[2],steer:r,points:{uprightUpper:h,uprightLower:b,tieOuter:g,wheelCenter:y,pushrodOuter:R,spinAxis:x,contactPatch:A.contactPatch,kingpinGround:A.kingpinGround,kingpinAtHub:A.kingpinAtHub,rockerAngle:S.phi,damperLength:S.damperLength},metrics:{camber:A.camber,toe:A.toe,caster:A.caster,kpi:A.kpi,scrubRadius:A.scrubRadius,mechanicalTrail:A.mechanicalTrail,scrubAtWheel:A.scrubAtWheel,trailAtWheel:A.trailAtWheel,kingpinOffset:A.kingpinOffset,casterOffset:A.casterOffset,steeringArm:A.steeringArm,damperLength:S.damperLength},converged:c.converged&&S.converged,margin:Math.min(c.margin,S.margin)}}var vs=e=>e==="FL"||e==="FR"?"front":"rear",Ek=e=>e==="FL"||e==="RL"?"left":"right";function Je(e,t){return e.corners?.[t]??m2(e[vs(t)],Ek(t))}function Ik(e){let t=e.config.springSplit;return e.config.actuation==="decoupled"||t===void 0||!Number.isFinite(t)||Math.abs(t)>=1?0:t}var Dk=new WeakMap;function m2(e,t){let r=Ik(e);if(r===0)return e;let n=Dk.get(e);if(!n){let o=a=>{let{springSplit:s,...i}=e.config;return{...e,config:{...i,springRate:e.config.springRate*a},...e.measured?{measured:{...e.measured,springRate:e.measured.springRate*a}}:{}}};n={left:o(1-r),right:o(1+r)},Dk.set(e,n)}return n[t]}var en=["FL","FR","RL","RR"],Qt=e=>2*e.hardpoints.wheelCenter[1],cr=(e,t)=>t?Qt(Je(e,"FL"))/2+Qt(Je(e,"FR"))/2:Qt(Je(e,"RL"))/2+Qt(Je(e,"RR"))/2;function Ue(e,t){let r=e==="FL"||e==="FR";return{axleX:r?t.frontAxleX:t.frontAxleX-t.wheelbase,sideSign:e==="FR"||e==="RR"?1:-1,isFront:r}}function st(e,t){return[t.axleX+e[0],t.sideSign*e[1],e[2]]}function Dn(e,t){return[e[0],t.sideSign*e[1],e[2]]}function bo(e){return e.frontAxleX-e.wheelbase/2}function yb(e,t,r){return t[2]+e.heave+(t[0]-r)*Math.sin(e.pitch)-t[1]*Math.sin(e.roll)}function go(e,t,r,n){let o=Ue(e,t),a=(n?cr(n,o.isFront):o.isFront?t.trackFront:t.trackRear)/2,s=o.sideSign*a,i=o.axleX-bo(t),c=-r.heave-i*Math.sin(r.pitch)+s*Math.sin(r.roll),l=o.isFront?o.sideSign*r.steer:0;return{travel:c,steer:l}}var d2={travelMin:-40,travelMax:40,steps:41,steer:0};function sc(e){return{q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle}}function ut(e,t={}){let r={...d2,...t},n=Tt(e);return ks(n,r)}function ks(e,t){let r=t.steer,n=.01,o=at(e,n,r),a=at(e,-n,r),s=(o.travel-a.travel)/(2*n);(!Number.isFinite(s)||Math.abs(s)<1e-6)&&(s=1);let i=Math.max(Math.abs(t.travelMax),Math.abs(t.travelMin)),c=Math.min(1.2,1.5*i/Math.abs(s)),l=Math.max(20,t.steps*2),u=[],m=at(e,0,r);u.push({beta:0,travel:m.travel,warm:sc(m),converged:m.converged});let p=sc(m);for(let x=1;x<=l;x++){let R=c*x/l,v=at(e,R,r,p);p=sc(v),u.push({beta:R,travel:v.travel,warm:p,converged:v.converged})}p=sc(m);for(let x=1;x<=l;x++){let R=-c*x/l,v=at(e,R,r,p);p=sc(v),u.push({beta:R,travel:v.travel,warm:p,converged:v.converged})}u.sort((x,R)=>x.beta-R.beta);let d=u[u.length-1].travel>=u[0].travel,f=!1;for(let x=1;x<u.length;x++){let R=u[x].travel-u[x-1].travel;(d&&R<-1e-6||!d&&R>1e-6)&&(f=!0)}let h=u.filter(x=>x.converged).map(x=>x.travel),b=h.length?[Math.min(...h),Math.max(...h)]:[0,0],g=h.length>0&&b[0]<=t.travelMin+1e-6&&b[1]>=t.travelMax-1e-6,y=[];for(let x=0;x<t.steps;x++){let R=t.steps===1?t.travelMin:t.travelMin+(t.travelMax-t.travelMin)*x/(t.steps-1),v=p2(u,R,d),S=f2(u,v);y.push(at(e,v,r,S))}return h2(y,e.corner.config.actuation==="decoupled"?0:e.corner.config.springRate),{samples:y,covered:g,reach:b,fold:f,unconverged:y.filter(x=>!x.converged).length}}function p2(e,t,r){let n=r?e.slice():e.slice().reverse();if(t<=n[0].travel)return n[0].beta;if(t>=n[n.length-1].travel)return n[n.length-1].beta;for(let o=1;o<n.length;o++){let a=n[o-1],s=n[o];if(t>=Math.min(a.travel,s.travel)&&t<=Math.max(a.travel,s.travel)){let i=s.travel-a.travel,c=Math.abs(i)<1e-9?0:(t-a.travel)/i;return a.beta+c*(s.beta-a.beta)}}return n[n.length-1].beta}function f2(e,t){let r=e[0],n=1/0;for(let o of e){let a=Math.abs(o.beta-t);a<n&&(n=a,r=o)}return r.warm}function xb(e,t,r){return r===0?(e[1]-e[0])/(t[1]-t[0]):r===e.length-1?(e[r]-e[r-1])/(t[r]-t[r-1]):(e[r+1]-e[r-1])/(t[r+1]-t[r-1])}function h2(e,t){if(e.length<2)return;let r=e.map(s=>s.travel),n=e.map(s=>s.metrics.camber),o=e.map(s=>s.metrics.toe),a=e.map(s=>s.metrics.damperLength);for(let s=0;s<e.length;s++){let i=xb(n,r,s),c=xb(o,r,s),l=-xb(a,r,s);e[s].metrics.camberGain=i,e[s].metrics.bumpSteer=c,e[s].metrics.motionRatio=l,e[s].metrics.wheelRate=t*l*l}}var pm=e=>e!==void 0&&Number.isFinite(e)&&e>0;function b2(e){return e&&pm(e.helperRate)&&pm(e.helperTravel)?{rate:e.helperRate,travel:e.helperTravel}:null}function Rb(e,t,r){let n=t/e;return r?n+Math.min(t/r.rate,r.travel):n}function ic(e,t,r,n){if(!(e>0)||!Number.isFinite(e)||!(t>0)||!Number.isFinite(t))return null;let o=b2(n),a=-Rb(e,t,o),s=Ms(r,n);return{rate:e,preload:t,helper:o,free:a,pull:null,droop:s.droop??a,droopStated:s.droop!==null,bump:s.bump,holdsLoad:!0}}function Ms(e,t){if(!Number.isFinite(e))return{droop:null,bump:null};let r=pm(t?.extended)&&t.extended>e?t.extended:null,n=r!==null&&pm(t?.stroke)?r-t.stroke:null;return{droop:r!==null?e-r:null,bump:n!==null&&n<e?e-n:null}}function vb(e,t){if(!(e>0)||!Number.isFinite(e))return null;let r=Ms(t.length0,t.coilover),n=t.free===-1/0||t.pull!==null&&t.pull>=t.free;if(n&&r.droop===null&&r.bump===null)return null;let o=n?-1/0:t.free;return{rate:e,preload:o===-1/0?0:-e*o,helper:null,free:o,pull:n?null:t.pull,droop:r.droop??-1/0,droopStated:r.droop!==null,bump:r.bump,holdsLoad:!1}}function g2(e,t){let{rate:r,preload:n,helper:o}=e;if(!o)return t>e.free-1e-9?n+r*t:e.pull!==null&&t<e.pull+1e-9?r*(t-e.pull):0;let a=Rb(r,n,o)+t;if(a<=0)return 0;let s=o.rate*o.travel;return a>=s/r+o.travel?n>=s?n+r*t:r*(a-o.travel):a*r*o.rate/(r+o.rate)}function y2(e,t){let{rate:r,preload:n,helper:o}=e;if(!o)return t>e.free-1e-9||e.pull!==null&&t<e.pull+1e-9?r:0;let a=Rb(r,n,o)+t;return a<=0?0:a>=o.rate*o.travel/r+o.travel?r:r*o.rate/(r+o.rate)}function Ss(e,t){let r=g2(e,t),n=e.free;return e.holdsLoad&&t<n&&e.droop<n&&(r+=.001*e.rate*(Math.max(t,e.droop)-n)),t<e.droop&&(r+=1e3*e.rate*(t-e.droop)),e.bump!==null&&t>e.bump&&(r+=1e3*e.rate*(t-e.bump)),r}function kb(e,t){let r=y2(e,t),n=e.free;return e.holdsLoad&&t<n&&t>e.droop&&(r+=.001*e.rate),t<e.droop&&(r+=1e3*e.rate),e.bump!==null&&t>e.bump&&(r+=1e3*e.rate),r}function Mb(e){let t=e.free,r=[t,e.droop];return e.helper&&r.push(e.helper.rate*e.helper.travel/e.rate+e.helper.travel+t),e.bump!==null&&r.push(e.bump),e.pull!==null&&r.push(e.pull),[...new Set(r.filter(Number.isFinite))].sort((n,o)=>n-o)}var fm={min:-60,max:60,steps:61},Sb=e=>({travel:[e.min,e.max],force:[0,0],motionRatio:[0,0],spring:null}),_k=new WeakMap;function x2(e,t){let r=_k.get(e.corner);r||_k.set(e.corner,r=new Map);let n=`${t.min}|${t.max}|${t.steps}`,o=r.get(n);return o||r.set(n,o=ks(e,{travelMin:t.min,travelMax:t.max,steps:t.steps,steer:0})),o}function lc(e,t,r=fm,n=e.corner.config.coilover){let o=e.corner.config;if(o.actuation==="decoupled")return Sb(r);let a=x2(e,r),s=v2(e,o.springRate,a.samples),i=[];for(let h of a.samples){let b=h.metrics.motionRatio;!h.converged||b===void 0||!Number.isFinite(b)||!Number.isFinite(h.metrics.damperLength)||i.length>0&&h.travel<=i[i.length-1].t+1e-6||i.push({t:h.travel,L:h.metrics.damperLength,mr:b})}if(i.length<2)return Sb(r);let c=M2(i,0);if(!(Math.abs(c.mr)>1e-6))return Sb(r);let l=t/c.mr,u=ic(s,l,c.L,n),m=u?R2(i,Mb(u).map(h=>c.L-h)):i,p=m.map(h=>(u?Ss(u,c.L-h.L):l+s*(c.L-h.L))*h.mr-t),d=h=>h===null?null:m.find(b=>b.L===c.L-h)?.t??null,f=u?Mb(u).map(d).filter(h=>h!==null):[];return{travel:m.map(h=>h.t),force:p,motionRatio:m.map(h=>h.mr),spring:{rate:s,preload:l,length0:c.L,law:u},...u?{stops:{droop:d(u.droop),bump:d(u.bump)}}:{},...f.length?{kinks:f}:{},length:m.map(h=>h.L)}}function Ab(e,t){if(!e.spring)return null;let r=e.travel.length,n=e.length;if(n&&n.length===r&&r>=2){let s=tn(e.travel,t),i=(t-e.travel[s])/(e.travel[s+1]-e.travel[s]);return e.spring.length0-(n[s]+i*(n[s+1]-n[s]))}if(r<2)return 0;let o=64,a=0;for(let s=0;s<o;s++){let i=t*s/o,c=t*(s+1)/o;a+=(cc(e,i)+cc(e,c))/2*(c-i)}return a}function R2(e,t){let r=[...e];for(let n of t)for(let o=0;o+1<e.length;o++){let a=e[o],s=e[o+1];if(a.L===n)break;if((a.L-n)*(s.L-n)>=0)continue;let i=(n-a.L)/(s.L-a.L);r.push({t:a.t+i*(s.t-a.t),L:n,mr:a.mr+i*(s.mr-a.mr)});break}return r.sort((n,o)=>n.t-o.t),r.filter((n,o)=>o===0||n.t>r[o-1].t+1e-6)}function v2(e,t,r){let n=e.corner.compliance?.links?.pushRod;if(n===void 0||!(n>0)||!Number.isFinite(n)||!(t>0))return t;let o=e.corner.config.actuation==="direct"?n:k2(e,n,r);return!(o>0)||!Number.isFinite(o)?t:t*o/(t+o)}function k2(e,t,r){let n;for(let m of r)m.converged&&(!n||Math.abs(m.travel)<Math.abs(n.travel))&&(n=m);if(!n)return t;let o=e.corner.hardpoints,a=Rs(e.rocker,n.points.rockerAngle),s=ee($(o.rockerPivotB,o.rockerPivotA)),i=(m,p)=>Math.abs(Z(s,me($(m,o.rockerPivotA),ee($(p,m))))),c=i(a.pushrod,n.points.pushrodOuter),l=i(a.damper,o.damperChassis);if(!(l>1e-9)||!(c>1e-9))return t;let u=c/l;return t*u*u}function cc(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.motionRatio[0];let n=tn(e.travel,t),o=(t-e.travel[n])/(e.travel[n+1]-e.travel[n]);return e.motionRatio[n]+o*(e.motionRatio[n+1]-e.motionRatio[n])}function En(e,t,r){if(!e.spring)return Vr(e,t);let{rate:n,preload:o,length0:a,law:s}=e.spring,i=cc(e,0),c=a-r;return(s?Ss(s,c):o+n*c)*cc(e,t)-o*i}function M2(e,t){let r=tn(e.map(s=>s.t),t),n=e[r],o=e[r+1],a=(t-n.t)/(o.t-n.t);return{L:n.L+a*(o.L-n.L),mr:n.mr+a*(o.mr-n.mr)}}function tn(e,t){let r=e.length;if(t<=e[0])return 0;if(t>=e[r-1])return r-2;let n=0,o=r-1;for(;o-n>1;){let a=n+o>>1;e[a]<=t?n=a:o=a}return n}function Vr(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.force[0];let n=tn(e.travel,t),o=(t-e.travel[n])/(e.travel[n+1]-e.travel[n]);return e.force[n]+o*(e.force[n+1]-e.force[n])}function As(e,t){let r=e.travel.length;if(r<3)return uc(e,t);let n=tn(e.travel,t),o=(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n]),a=i=>i===0||i===r-1||e.kinks?.includes(e.travel[i])?o:(e.force[i+1]-e.force[i-1])/(e.travel[i+1]-e.travel[i-1]),s=Math.max(0,Math.min(1,(t-e.travel[n])/(e.travel[n+1]-e.travel[n])));return a(n)+s*(a(n+1)-a(n))}function uc(e,t){if(e.travel.length<2)return 0;let n=tn(e.travel,t);return(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n])}function Ne(e,t,r){let n=e.hardpoints;switch(t.attach){case"upright":{let o=$(t.outer,n.wheelCenter);return ne(ne(_t(r.pose.omega,o),n.wheelCenter),r.pose.t)}case"lowerArm":{let o=ee($(n.lcaRear,n.lcaFront));return ne(n.lcaFront,_t(Q(o,r.beta),$(t.outer,n.lcaFront)))}case"rocker":{let o=ee($(n.rockerPivotB,n.rockerPivotA));return ne(n.rockerPivotA,ir($(t.outer,n.rockerPivotA),o,r.points.rockerAngle))}}}function Br(e,t,r){return e.config.actuation==="decoupled"&&t.attach==="rocker"&&r==="coil"}function hm(e,t,r){return Br(e,t,r)?[t.inner[0],-t.inner[1],t.inner[2]]:t.inner}function zo(e,t,r){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return wb(e,t,r.kind,ut(e,{travelMin:n,travelMax:o,steps:a}).samples)}function wb(e,t,r,n){let o=ee($(t.outer,hm(e,t,r))),a=[],s=[],i=t.outer;for(let d of n)a.push(d.travel),s.push(Z($(Ne(e,t,d),i),o));let c=a.length,l=new Array(c).fill(0);for(let d=0;d<c;d++){let f=Math.max(0,d-1),h=Math.min(c-1,d+1),b=a[h]-a[f];l[d]=b!==0?(s[h]-s[f])/b:0}let u=l[0];for(let d=1;d<c;d++)if(a[d]>=0){let f=a[d]-a[d-1],h=f!==0?(0-a[d-1])/f:0;u=l[d-1]+h*(l[d]-l[d-1]);break}let m=l.filter(d=>Math.abs(d)>1e-9).map(Math.sign),p=m.length>0&&m.some(d=>d!==m[0]);return{travel:a,ratio:l,linkTravel:s,atDesign:u,reverses:p}}function Fb(e,t){let{travel:r,ratio:n}=e,o=r.length;if(o===0)return 0;if(t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=0,s=o-1;for(;s-a>1;){let c=a+s>>1;r[c]<=t?a=c:s=c}let i=(t-r[a])/(r[s]-r[a]);return n[a]+i*(n[s]-n[a])}function Cb(e,t){let{travel:r,linkTravel:n}=e,o=r.length;if(o===0)return 0;if(t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=0,s=o-1;for(;s-a>1;){let c=a+s>>1;r[c]<=t?a=c:s=c}let i=(t-r[a])/(r[s]-r[a]);return n[a]+i*(n[s]-n[a])}var Yo=e=>e.mount??{kind:"rockerToRocker"},Bk=e=>[e[0],0,e[2]],S2=e=>2*Math.abs(e[1]),A2=(e,t)=>Math.hypot(e[0]-t[0],e[2]-t[2]);function gm(e,t){return t.kind==="chassis"?A2(e,t.anchor):S2(e)}function mc(e,t,r){if(r.kind==="chassis"){let s=[(e[0]+t[0])/2,(e[1]-t[1])/2,(e[2]+t[2])/2];return Math.hypot(s[0]-r.anchor[0],s[1],s[2]-r.anchor[2])}let n=e[0]-t[0],o=e[1]+t[1],a=e[2]-t[2];return Math.hypot(n,o,a)}function Wo(e,t,r={}){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return Tb(e,t,ut(e,{travelMin:n,travelMax:o,steps:a}).samples)}function Tb(e,t,r){let n=Yo(t),o=f=>Ne(e,{...t,inner:t.outer},r[f]),a=[],s=[],i=[];for(let f=0;f<r.length;f++)a.push(r[f].travel),i.push(gm(o(f),n));let c=Ok(a,i,0);for(let f of i)s.push(c-f);let l=a.length,u=new Array(l).fill(0);for(let f=0;f<l;f++){let h=Math.max(0,f-1),b=Math.min(l-1,f+1),g=a[b]-a[h];u[f]=g!==0?(s[b]-s[h])/g:0}let m=Nk(a,20),p=Nk(a,-20),d=mc(o(m),o(p),n);return{travel:a,ratio:u,springTravel:s,atDesign:Ok(a,u,0),installedLength:c,rollSensitivity:c-d}}function Nk(e,t){let r=0,n=1/0;for(let o=0;o<e.length;o++){let a=Math.abs(e[o]-t);a<n&&(n=a,r=o)}return r}function Ok(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];for(let o=1;o<n;o++)if(e[o]>=r){let a=e[o]-e[o-1],s=a!==0?(r-e[o-1])/a:0;return t[o-1]+s*(t[o]-t[o-1])}return t[n-1]}function Pb(e,t,r){let n={outer:t.outer,attach:t.attach},o=ut(e,{travelMin:-5,travelMax:5,steps:3}),a=f=>Bk(Ne(e,{...n,inner:n.outer},o.samples[f])),s=a(1),i=a(2),c=a(0),l=i[0]-c[0],u=i[2]-c[2],m=Math.hypot(l,u),p=m>1e-9?[l/m,u/m]:[0,1],d=r??Math.max(80,2*Math.abs(t.outer[1])*.5);return[s[0]+p[0]*d,0,s[2]+p[1]*d]}function Lb(e,t){let r=e.hardpoints,n=r.rockerPivotA,o=Vk(bm(r.rockerPivotB,r.rockerPivotA)),a=Math.max(30,.6*$k(bm(r.rockerToDamper,n))),s=bm(r.rockerToDamper,n),i=Vk(bm(s,w2(o,F2(s,o)))),c=C2(o,i),l=null,u=-1/0;for(let m=0;m<360;m+=10){let p=m*Math.PI/180,f={outer:[n[0]+a*(Math.cos(p)*i[0]+Math.sin(p)*c[0]),n[1]+a*(Math.cos(p)*i[1]+Math.sin(p)*c[1]),n[2]+a*(Math.cos(p)*i[2]+Math.sin(p)*c[2])],attach:"rocker"},h=t==="chassis"?{...f,mount:{kind:"chassis",anchor:Pb(e,f)}}:f,b;try{b=Wo(e,h,{travelMin:-20,travelMax:20,steps:9})}catch{continue}let g=b.atDesign/(1+4*Math.abs(b.rollSensitivity));Number.isFinite(g)&&g>u&&(u=g,l=h)}return l??{outer:r.rockerToDamper,attach:"rocker"}}var bm=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],w2=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],F2=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],$k=e=>Math.hypot(e[0],e[1],e[2]),Vk=e=>{let t=$k(e)||1;return[e[0]/t,e[1]/t,e[2]/t]},C2=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]];var xm=.001,T2=e=>({outer:e.outer,inner:e.outer,attach:e.attach}),Uk=(e,t,r)=>(gm(e.at0,t)-gm(r,t))/2,Gk=(e,t)=>Z($(t,e.pickup.at0),e.axis);function Rm(e,t){let r=e.length;return t.map((n,o)=>{let a=Math.max(0,o-1),s=Math.min(r-1,o+1);return(t[s]-t[a])/(e[s]-e[a])})}function Kk(e,t){let r=[0,1,2].map(n=>Rm(e,t.map(o=>o[n])));return t.map((n,o)=>[r[0][o],r[1][o],r[2][o]])}function Ib(e){return{travel:e,heave:e.map(t=>t/2),heaveRatio:e.map(()=>.5),roll:[...e],rollRatio:e.map(()=>1)}}function Hk(e,t,r,n){let o=e.corner;if(!t.heave&&!t.roll&&!t.bar)return{side:Ib([n.min,n.max]),pickups:{}};let a=Nt(Ce(e,0,0)),s={};if(t.heave&&r){let b=T2(t.heave);s.heave={corner:o,link:b,at0:Ne(o,b,a)}}if(t.roll){let b=t.roll;s.roll={pickup:{corner:o,link:b,at0:Ne(o,b,a)},axis:ee($(b.outer,hm(o,b,t.rollKind??"coil")))}}if(t.bar){let b=t.bar.linkage;s.bar={pickup:{corner:o,link:b,at0:Ne(o,b,a)},axis:ee($(b.outer,hm(o,b,"ubar")))}}let i=t.roll&&Br(o,t.roll,t.rollKind??"coil")?{near:t.roll,far:{...t.roll,outer:t.roll.inner}}:null,c=ks(e,{travelMin:n.min,travelMax:n.max,steps:n.steps,steer:0}),l=[],u=[],m=[],p=[],d=[],f=[];for(let b of c.samples)!b.converged||l.length>0&&b.travel<=l[l.length-1]+1e-6||(l.push(b.travel),u.push(s.heave&&r?Uk(s.heave,r,Ne(o,s.heave.link,b)):b.travel/2),m.push(s.roll?Gk(s.roll,Ne(o,s.roll.pickup.link,b)):b.travel),s.bar&&p.push(Gk(s.bar,Ne(o,s.bar.pickup.link,b))),i&&(d.push(Ne(o,i.near,b)),f.push(Ne(o,i.far,b))));if(l.length<2)return{side:Ib([n.min,n.max]),pickups:{}};let h={travel:l,heave:u,heaveRatio:Rm(l,u),roll:m,rollRatio:Rm(l,m)};return s.bar&&(h.bar=p,h.barRatio=Rm(l,p)),i&&(h.eyes={near:d,nearRatio:Kk(l,d),far:f,farRatio:Kk(l,f)}),{side:h,pickups:s}}function ws(e,t,r){let n=tn(e,r);return t[n]+(r-e[n])/(e[n+1]-e[n])*(t[n+1]-t[n])}function Db(e,t,r){let n=tn(e,r);return(t[n+1]-t[n])/(e[n+1]-e[n])}function tt(e,t){let r=e.bar&&e.barRatio?{b:ws(e.travel,e.bar,t),db:ws(e.travel,e.barRatio,t),ddb:Db(e.travel,e.barRatio,t)}:null;return{h:ws(e.travel,e.heave,t),dh:ws(e.travel,e.heaveRatio,t),ddh:Db(e.travel,e.heaveRatio,t),r:ws(e.travel,e.roll,t),dr:ws(e.travel,e.rollRatio,t),ddr:Db(e.travel,e.rollRatio,t),b:r?.b??0,db:r?.db??0,ddb:r?.ddb??0}}function zk(e,t,r,n){let o=tn(e,n),a=e[o+1]-e[o],s=(n-e[o])/a,i=(u,m)=>[u[0]+s*(m[0]-u[0]),u[1]+s*(m[1]-u[1]),u[2]+s*(m[2]-u[2])],c=r[o],l=r[o+1];return{p:i(t[o],t[o+1]),d:i(c,l),dd:[(l[0]-c[0])/a,(l[1]-c[1])/a,(l[2]-c[2])/a]}}var _b=(e,t)=>Math.hypot(e[0]-t[0],e[1]+t[1],e[2]-t[2]);function Nb(e,t){let r=e.side[0].eyes,n=e.side[1].eyes;if(!r||!n)return null;let o=zk(e.side[0].travel,r.near,r.nearRatio,t[0]),a=zk(e.side[1].travel,n.far,n.farRatio,t[1]),s=[o.p[0]-a.p[0],o.p[1]+a.p[1],o.p[2]-a.p[2]],i=Math.hypot(s[0],s[1],s[2]),c=[s[0]/i,s[1]/i,s[2]/i],l=o.d,u=[-a.d[0],a.d[1],-a.d[2]],m=[-a.dd[0],a.dd[1],-a.dd[2]],p=Z(c,l),d=Z(c,u),f=(Z(l,u)-p*d)/i;return{L:i,dL:[p,d],ddL:[[(Z(l,l)-p*p)/i+Z(c,o.dd),f],[f,(Z(u,u)-d*d)/i+Z(c,m)]]}}var Xk=(e,t)=>e.bump!==null&&t>e.bump?e.rate*(t-e.bump):e.droop!==null&&t<e.droop?e.rate*(t-e.droop):0,P2=(e,t)=>e.bump!==null&&t>e.bump||e.droop!==null&&t<e.droop?e.rate:0;function dc(e,t,r,n,o=0){let a=e.rollStop;if(!a)return r;let s=Nb(e,t);if(!s)return r;let i=Xk(a,a.length0-(n??s.L+o));return i===0?r:[r[0]-i*s.dL[0],r[1]-i*s.dL[1]]}function Yk(e){if(!e.bar)return e;let{bar:t,barRatio:r,...n}=e;return n}function ym(e,t){let r=Ib(e.travel);return t==="heave"?{...e,heave:r.heave,heaveRatio:r.heaveRatio}:{...e,roll:r.roll,rollRatio:r.rollRatio}}var Fs=(e,t)=>e?e.law?Ss(e.law,t):e.preload+e.rate*t:0,Eb=(e,t)=>e?e.law?kb(e.law,t):e.rate:0;function pc(e,t,r,n,o,a){let s=Fs(e.heave,n),i=Fs(e.roll,o),c=Fs(e.bar??null,a);return[s*t.dh+i*t.dr+c*t.db,s*r.dh-i*r.dr-c*r.db]}var Wk=(e,t)=>tt(e[0],t).h+tt(e[1],t).h;function L2(e,t){let r=e.gap>0?Wk(t,e.gap):0;return e.bothWays?{free:r,pull:e.gap>0?Wk(t,-e.gap):0}:{free:r,pull:null}}function D2(e,t,r){let n={...t,outer:t.inner},o=(u,m)=>{let p=zt(Ce(e[0],u,0)),d=zt(Ce(e[1],m,0));if(!p||!d)return NaN;let f=Ne(e[0].corner,t,p),h=Ne(e[1].corner,n,d);return Math.hypot(f[0]-h[0],f[1]+h[1],f[2]-h[2])},a=1,s=o(0,0),i=o(-a,a)-o(a,-a),c=tt(r[0],a).r-tt(r[1],-a).r-(tt(r[0],-a).r-tt(r[1],a).r),l=i/c;return Number.isFinite(s)&&s>0&&Number.isFinite(l)&&Math.abs(l)>xm?{length0:s,scale:l}:null}function qk(e,t,r,n=fm){let o=r.heave?Yo(r.heave):void 0,a=Hk(e[0],r,o,n),s=e[1].corner===e[0].corner?a:Hk(e[1],r,o,n),i=[a.side,s.side],c=!!(a.pickups.heave&&s.pickups.heave),l=!!(a.pickups.roll&&s.pickups.roll),u=!!(a.pickups.bar&&s.pickups.bar&&a.side.bar&&s.side.bar),m=r.carriesLoad?void 0:r.heaveSeat,p=m?m.rate:(t[0].heaveRate+t[1].heaveRate)/2,d=(t[0].arbRate+t[1].arbRate)/2,f=i.map(N=>tt(N,0));c&&!(Math.abs(f[0].dh+f[1].dh)>xm)&&(i=[ym(i[0],"heave"),ym(i[1],"heave")],c=!1),l&&!(Math.abs(f[0].dr+f[1].dr)>xm)&&(i=[ym(i[0],"roll"),ym(i[1],"roll")],l=!1),u&&!(Math.abs(f[0].db+f[1].db)>xm)&&(u=!1),u||(i=[Yk(i[0]),Yk(i[1])]),f=i.map(N=>tt(N,0));let h=f[0].dh+f[1].dh,b=f[0].dr+f[1].dr,g=f[0].db+f[1].db,y=u&&r.bar?Math.max(0,r.bar.wheelRate):0,x=Math.max(0,d-y),R=p>0?2*p/(h*h):0,v=x>0?2*x/(b*b):0,S=y>0?2*y/(g*g):0,A=v+S*(g/b)**2,C=0,F=0,T=0;if(r.carriesLoad){let N=[t[0].springLoad,t[1].springLoad],O=0;if(R>0&&A>0){let H=-f[0].dh*f[1].dr-f[1].dh*f[0].dr;Math.abs(H)>1e-12&&(C=(-N[0]*f[1].dr-N[1]*f[0].dr)/H,O=(f[0].dh*N[1]-f[1].dh*N[0])/H)}else R>0?C=(N[0]+N[1])/h:A>0&&(O=(N[0]-N[1])/b);let V=A>0?v/A:1;F=V*O,S>0&&(T=(1-V)*O*(b/g))}let M={};if(c&&o){let N=[a.pickups.heave,s.pickups.heave];M.heave={pickups:N,mount:o,span0:mc(N[0].at0,N[1].at0,o)}}let k=M.heave?M.heave.span0:NaN,w=M.heave?r.coilover:void 0,P=r.carriesLoad?ic(R,C,k,w):m?vb(R,{...L2(m,i),length0:k,coilover:w}):null,L=R>0?{rate:R,preload:C,...P?{law:P}:{}}:null;if(l&&(M.roll={pickups:[a.pickups.roll.pickup,s.pickups.roll.pickup],axes:[a.pickups.roll.axis,s.pickups.roll.axis]},r.roll&&Br(e[0].corner,r.roll,r.rollKind??"coil"))){let N=D2(e,r.roll,i);N&&(M.roll.unit=N)}let E=v>0?{rate:v,preload:F}:null,_={side:i,heave:L,roll:E,force0:[0,0],carriesLoad:r.carriesLoad,read:M};S>0&&(_.bar={rate:S,preload:T},M.bar={pickups:[a.pickups.bar.pickup,s.pickups.bar.pickup],axes:[a.pickups.bar.axis,s.pickups.bar.axis]});let D=M.roll?.unit,I=D&&A>0&&i[0].eyes&&i[1].eyes?Ms(D.length0,r.rollCoilover):null;return D&&I&&(I.droop!==null||I.bump!==null)&&(_.rollStop={length0:D.length0,rate:1e3*A/(D.scale*D.scale),...I}),_.force0=dc(_,[0,0],pc(_,f[0],f[1],f[0].h+f[1].h,f[0].r-f[1].r,f[0].b-f[1].b)),_}function fc(e,t,r){let n=tt(e.side[0],t[0]),o=tt(e.side[1],t[1]),a=r?dc(e,t,pc(e,n,o,n.h+o.h+r.heave,n.r-o.r+r.roll,n.b-o.b+(r.bar??0)),void 0,r.unit):dc(e,t,pc(e,n,o,n.h+o.h,n.r-o.r,n.b-o.b));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function Ob(e,t,r){let n=tt(e.side[0],t[0]),o=tt(e.side[1],t[1]),a=r?n.h+o.h+r.heave:n.h+o.h,s=r?n.r-o.r+r.roll:n.r-o.r,i=n.b-o.b+(r?.bar??0),c=Eb(e.heave,a),l=Eb(e.roll,s),u=Eb(e.bar??null,i),m=Fs(e.heave,a),p=Fs(e.roll,s),d=Fs(e.bar??null,i),f=c*n.dh*o.dh-l*n.dr*o.dr-u*n.db*o.db,h=[[c*n.dh*n.dh+m*n.ddh+l*n.dr*n.dr+p*n.ddr+u*n.db*n.db+d*n.ddb,f],[f,c*o.dh*o.dh+m*o.ddh+l*o.dr*o.dr-p*o.ddr+u*o.db*o.db-d*o.ddb]],b=e.rollStop,g=b?Nb(e,t):null;if(!b||!g)return h;let y=b.length0-(r?g.L+r.unit:g.L),x=P2(b,y);if(x===0)return h;let R=Xk(b,y),v=(A,C)=>x*g.dL[A]*g.dL[C]-R*g.ddL[A][C],S=f+v(0,1);return[[h[0][0]+v(0,0),S],[S,h[1][1]+v(1,1)]]}function Vb(e,t,r){let n=Ob(e,t);return n[r][0]+n[r][1]}function E2(e,t,r){let n=e.read.heave;if(!n)return tt(e.side[0],t[0]).h+tt(e.side[1],t[1]).h;let[o,a]=n.pickups;return n.span0-mc(Ne(o.corner,o.link,r[0]),Ne(a.corner,a.link,r[1]),n.mount)}function I2(e,t,r){let n=e.read.roll;if(!n)return tt(e.side[0],t[0]).r-tt(e.side[1],t[1]).r;let o=a=>Z($(Ne(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function _2(e,t,r){let n=e.read.bar;if(!n)return tt(e.side[0],t[0]).b-tt(e.side[1],t[1]).b;let o=a=>Z($(Ne(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function N2(e,t){let r=e.read.roll;if(!e.rollStop||!r)return;let[n,o]=r.pickups;return _b(Ne(n.corner,n.link,t[0]),Ne(o.corner,{...o.link,outer:o.link.inner},t[1]))}function hc(e,t,r){let n=tt(e.side[0],t[0]),o=tt(e.side[1],t[1]),a=dc(e,t,pc(e,n,o,E2(e,t,r),I2(e,t,r),_2(e,t,r)),N2(e,r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function Bb(e,t,r,n){let o=tt(e.side[0],r),a=tt(e.side[1],r),s=e.read.heave,i=s?.pickups[t],c=s&&i&&n?2*Uk(i,s.mount,Ne(i.corner,i.link,n)):o.h+a.h,l=e.rollStop&&n?e.read.roll?.pickups[t]:void 0,u=l&&n?_b(Ne(l.corner,l.link,n),Ne(l.corner,{...l.link,outer:l.link.inner},n)):void 0;return dc(e,[r,r],pc(e,o,a,c,n?0:o.r-a.r,n?0:o.b-a.b),u)[t]-e.force0[t]}function $b(e,t,r,n){let o=As(e,r[n]);return t?.carriesLoad?o+Vb(t,r,n):o}function Qk(e,t){return tt(e.side[0],t[0]).h+tt(e.side[1],t[1]).h}function Zk(e,t){return Nb(e,t)?.L??null}var Gb=e=>e==="FR"||e==="RR"?1:0,vm=(e,t)=>e.elements?.[t==="FL"||t==="FR"?"front":"rear"]??null;var Jk=e=>Number.isFinite(e)&&e>0?1/e:0;var eM=(e,t)=>{let r=e[0][0]*e[1][1]-e[0][1]*e[1][0];return Math.abs(r)>1e-14?[(t[0]*e[1][1]-t[1]*e[0][1])/r,(e[0][0]*t[1]-e[1][0]*t[0])/r]:null},O2=(e,t)=>[e[0][0]*t[0]+e[0][1]*t[1],e[1][0]*t[0]+e[1][1]*t[1]],tM=1e-8,V2=40;function B2(e,t,r,n){return{force:(s,i)=>{if(r){let u=fc(r,s,n);return[Vr(t[0],s[0])+i[0]+u[0],Vr(t[1],s[1])+i[1]+u[1]]}let c=(s[0]+s[1])/2,l=(s[0]-s[1])/2;return[Vr(t[0],s[0])+i[0]+e[0].heaveRate*c+e[0].arbRate*l,Vr(t[1],s[1])+i[1]+e[1].heaveRate*c-e[1].arbRate*l]},stiffness:(s,i=uc)=>{if(r){let c=Ob(r,s,n);return[[i(t[0],s[0])+c[0][0],c[0][1]],[c[1][0],i(t[1],s[1])+c[1][1]]]}return[[i(t[0],s[0])+e[0].heaveRate/2+e[0].arbRate/2,e[0].heaveRate/2-e[0].arbRate/2],[e[1].heaveRate/2-e[1].arbRate/2,i(t[1],s[1])+e[1].heaveRate/2+e[1].arbRate/2]]}}}function Cs(e,t,r,n,o,a=[0,0],s=[0,0],i=null,c){let l=[Jk(r[0].tyreRate),Jk(r[1].tyreRate)],u=[r[0].staticLoad,r[1].staticLoad],m=B2(r,n,i,c),p=P=>m.force(P,a),d=m.stiffness([0,0]),f=[l[0]>0?l[0]:1/Math.max(1,Math.abs(d[0][0])),l[1]>0?l[1]:1/Math.max(1,Math.abs(d[1][1]))],h=(P,L)=>{let E=L===1?p(P):m.force(P,[a[0]*L,a[1]*L]),_=[E[0]+s[0]*L,E[1]+s[1]*L],D=[P[0]+t[0]*L+_[0]*l[0]-e[0]*L,P[1]+t[1]*L+_[1]*l[1]-e[1]*L],I=[f[0]*(u[0]+_[0]),f[1]*(u[1]+_[1])],N=[I[0]<D[0],I[1]<D[1]];return{f:_,on:D,off:I,lifted:N,r:[Math.min(D[0],I[0]),Math.min(D[1],I[1])]}},b=(P,L)=>[L[0]?[f[0]*P[0][0],f[0]*P[0][1]]:[1+P[0][0]*l[0],P[0][1]*l[0]],L[1]?[f[1]*P[1][0],f[1]*P[1][1]]:[P[1][0]*l[1],1+P[1][1]*l[1]]],g=P=>Math.max(Math.abs(P[0]),Math.abs(P[1])),y=(P,L)=>{let E=[P[0],P[1]],_=h(E,L),D=!1,I=0;for(;I<V2;I++){if(g(_.r)<tM){D=!0;break}let N=eM(b(m.stiffness(E),_.lifted),[-_.r[0],-_.r[1]]);if(!N)break;let O=1,V=[E[0]+N[0],E[1]+N[1]],H=h(V,L);for(let U=0;U<8&&g(H.r)>g(_.r);U++)O/=2,V=[E[0]+O*N[0],E[1]+O*N[1]],H=h(V,L);E=V,_=H}return!D&&g(_.r)<tM&&(D=!0),{t:E,b:_,converged:D,it:I}},x=y(o?[o[0],o[1]]:[e[0]-t[0],e[1]-t[1]],1),R=x.it;if(!x.converged){let P=0,L=[0,0],E=.25;for(;P<1&&E>=1/256;){let _=Math.min(1,P+E),D=y(L,_);R+=D.it,D.converged?(P=_,L=D.t,_===1&&(x=D)):E/=2}}let{t:v,b:S,converged:A}=x,C=S.lifted,F=[C[0]?-u[0]:S.f[0],C[1]?-u[1]:S.f[1]],T=[C[0]?Math.max(0,S.on[0]):0,C[1]?Math.max(0,S.on[1]):0],M=m.stiffness(v,As),k=b(M,C);return{t:v,dF:F,lifted:C,clearance:T,converged:A,iterations:R,respond:(P,L,E=[0,0])=>{let _=[C[0]?-f[0]*E[0]:P[0]-L[0]-E[0]*l[0],C[1]?-f[1]*E[1]:P[1]-L[1]-E[1]*l[1]],D=eM(k,_);if(!D)return[NaN,NaN];let I=O2(M,D);return[C[0]?0:I[0]+E[0],C[1]?0:I[1]+E[1]]}}}var jo=e=>!(Number.isFinite(e.tyreRate)&&e.tyreRate>0);function Sr(e,t,r){return t?.input.corners[r].staticLoadedRadius??e}var Kb=["FL","FR","RL","RR"],oM={front:["FL","FR"],rear:["RL","RR"]},$2=512,G2=5e-4,K2=8;function km(e,t){let r={},n={},o=new Map;for(let s of Kb){let i=e.ctx[s],c=t.corners[s],l=c.staticLoadedRadius;n[s]=Nt(Ce(i,0,0,void 0,l===void 0?void 0:{loadedRadius:l})).points.contactPatch[2];let u=t.cornerCoilover?.[s==="FL"||s==="FR"?"front":"rear"],m=`${Kb.findIndex(d=>Je(e.vehicle,d)===Je(e.vehicle,s))}|${c.springLoad}|${u?`${u.extended}/${u.stroke}`:""}`,p=o.get(m);p?r[s]=p:(r[s]=u?lc(i,c.springLoad,void 0,u):lc(i,c.springLoad),o.set(m,r[s]))}let a={front:null,rear:null};for(let s of["front","rear"]){let i=t.elements?.[s];if(!i)continue;let c=oM[s];a[s]=qk([e.ctx[c[0]],e.ctx[c[1]]],[t.corners[c[0]],t.corners[c[1]]],i)}return{input:t,curve:r,elements:a,ground0:n,memo:new Map}}function aM(e,t,r){if(!(r>0)||!Number.isFinite(r)||!Number.isFinite(t)||t<=0)return 0;let n=Math.min(t/r,e);return 2*Math.sqrt(Math.max(0,2*e*n-n*n))}var H2=e=>`${e.heave}|${e.pitch}|${e.roll}|${e.steer}`;function Hb(e,t,r){return{travel:r.travel,steer:r.steer,ground:r.travel,tyreDeflection:0,load:NaN,loadedRadius:Sr(Je(e.vehicle,t).config.loadedRadius,e.kc,t),lifted:!1,contactLength:0,converged:!0,rigid:!0,rideRate:NaN,wheelRateAtLoad:NaN}}var z2=e=>e?{q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle}:void 0;function rM(e,t,r,n){let o=oM[n],a=e.vehicle.config,s=o.map(F=>go(F,a,r,e.vehicle)),i=[t.input.corners[o[0]],t.input.corners[o[1]]],c=t.loadCase;if(!c&&i.every(jo))return{corners:[Hb(e,o[0],s[0]),Hb(e,o[1],s[1])],respond:null};let l=o.map(F=>t.curve[F]),u=t.elements?.[n]??null,m=o.map(F=>Sr(Je(e.vehicle,F).config.loadedRadius,t,F)),p=[s[0].travel+(c?.ground[o[0]]??0),s[1].travel+(c?.ground[o[1]]??0)],d=[c?.linkLoad[o[0]]??0,c?.linkLoad[o[1]]??0],f=[c?.patchShift[o[0]],c?.patchShift[o[1]]],h=[0,0],b=[0,0],g,y=Cs(p,h,i,l,void 0,void 0,d,u),x=[void 0,void 0],R=[!0,!0],v=[0,0],S=!1;for(let F=0;F<K2;F++){F>0&&(y=Cs(p,h,i,l,g,b,d,u)),v=[Number.isFinite(i[0].tyreRate)&&i[0].tyreRate>0?y.dF[0]/i[0].tyreRate:0,Number.isFinite(i[1].tyreRate)&&i[1].tyreRate>0?y.dF[1]/i[1].tyreRate:0];let T=[0,0],M=[0,0];for(let w=0;w<2;w++){let P=Ce(e.ctx[o[w]],y.t[w],s[w].steer,z2(x[w]),{loadedRadius:m[w]-v[w],patchShift:f[w]}),L=Nt(P);x[w]=L,R[w]=P.ok,T[w]=L.points.contactPatch[2]-t.ground0[o[w]]-y.t[w]-v[w],M[w]=En(l[w],y.t[w],L.points.damperLength)-Vr(l[w],y.t[w])}if(u){let w=hc(u,y.t,[x[0],x[1]]),P=fc(u,y.t);M[0]+=w[0]-P[0],M[1]+=w[1]-P[1]}let k=Math.max(Math.abs(T[0]-h[0]),Math.abs(T[1]-h[1]),Math.abs(M[0]-b[0])/Math.max(1,i[0].tyreRate),Math.abs(M[1]-b[1])/Math.max(1,i[1].tyreRate));if(h=T,b=M,g=y.t,k<G2){S=!0;break}}let A=y.respond([1,1],[0,0]);return{corners:[0,1].map(F=>{let T=x[F];return{travel:y.t[F],steer:s[F].steer,ground:p[F],tyreDeflection:v[F],load:i[F].staticLoad+y.dF[F],loadedRadius:m[F]-v[F],lifted:y.lifted[F],clearance:y.clearance[F],contactLength:aM(m[F]-v[F],i[F].staticLoad+y.dF[F],i[F].tyreRate),converged:y.converged&&S&&R[F],rigid:!1,state:T,solved:R[F],rideRate:A[F],wheelRateAtLoad:$b(l[F],u,y.t,F)}}),respond:y.respond}}function sM(e,t){let r=e.kc,n=H2(t),o=r.memo.get(n);if(o)return o;let a=rM(e,r,t,"front"),s=rM(e,r,t,"rear"),i={corners:{FL:a.corners[0],FR:a.corners[1],RL:s.corners[0],RR:s.corners[1]},respond:{front:a.respond,rear:s.respond}};return r.memo.size>=$2&&r.memo.clear(),r.memo.set(n,i),i}function Zt(e,t){if(!e.kc){let r={};for(let n of Kb)r[n]=Hb(e,n,go(n,e.vehicle.config,t,e.vehicle));return r}return sM(e,t).corners}function Mm(e,t,r){return e.kc?sM(e,t).respond[r]:null}function bc(e,t,r,n=0){let o=e.kc;if(!o)return r;let a=o.input.corners[t];if(jo(a))return r;let s=go(t,e.vehicle.config,{heave:0,pitch:0,roll:0,steer:n},e.vehicle).steer,i=Sr(Je(e.vehicle,t).config.loadedRadius,o,t),c=o.loadCase,l=c?.linkLoad[t]??0,u=c?.patchShift[t],m=Nt(Ce(e.ctx[t],r,s,void 0,{loadedRadius:i,patchShift:u})),p=vm(o,t),d=En(o.curve[t],r,m.points.damperLength)+(p?Bb(p,Gb(t),r,m):a.heaveRate*r),h=Math.max(d+l,-a.staticLoad)/a.tyreRate;return(h===0?m:Nt(Ce(e.ctx[t],r,s,void 0,{loadedRadius:i-h,patchShift:u}))).points.contactPatch[2]-o.ground0[t]-(c?.ground[t]??0)}var Y2=180/Math.PI,W2=[0,0,1];function j2(e,t){let r=Dn(e,t),n=Q(me(W2,r),-t.sideSign);return-Math.atan2(n[1],n[0])*Y2}var iM=e=>1/Math.tan(e*Math.PI/180),cM=.05,lM=.001;function uM(e,t,r){if(!Number.isFinite(e)||!Number.isFinite(t))return NaN;if(!(Math.abs(e)<lM&&Math.abs(t)<lM))return e>0&&t>0?100*(iM(t)-iM(e))/r:NaN}function U2(e,t){let r=cr(e.vehicle,!0)/e.vehicle.config.wheelbase,n=t("FL",0).deg,o=t("FR",0).deg,a=(c,l)=>{let u=c+l>=0;return{left:u,inner:u?c:-l,outer:u?l:-c}},s,i=()=>{if(s===void 0){let c=[cM,-cM].map(l=>{let{inner:u,outer:m}=a(t("FL",l).deg-n,t("FR",l).deg-o);return uM(u,m,r)??NaN});s=(c[0]+c[1])/2}return s};return c=>{let l=t("FL",c),u=t("FR",c),{left:m,inner:p,outer:d}=a(l.deg-n,u.deg-o),f=uM(p,d,r);return{steerL:l.deg,steerR:u.deg,inner:p,outer:d,toeDiff:p-d,ackermannPct:f??i(),inside:f===void 0?null:m?"left":"right",converged:l.ok&&u.ok}}}function zb(e,t){let r=e.vehicle.config,n={FL:Ue("FL",r),FR:Ue("FR",r)},o=t.travel??0,a=U2(e,(i,c)=>{let l=zt(Ce(e.ctx[i],o,n[i].sideSign*c));return{deg:l?j2(l.points.spinAxis,n[i]):NaN,ok:l!==null}}),s=[];for(let i=0;i<t.steps;i++){let c=t.steps===1?0:-t.steerMax+2*t.steerMax*i/(t.steps-1),{inside:l,...u}=a(c);s.push({steerInput:c,...u})}return s}var mM=35,dM=55,Ot=e=>e.rackTravel&&e.rackTravel>0?e.rackTravel:mM,Yb=e=>e.rackRatio&&e.rackRatio>0?e.rackRatio:dM;var Wb=e=>({q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle});function pM(e,t,r,n,o){let a=Ce(e,n,0,void 0,o),s=Nt(a),i=a.ok?0:1,c=s.points.contactPatch[2],l={steer:s.metrics.toe,camber:s.metrics.camber,lift:0,contactPatch:s.points.contactPatch,spinAxis:s.points.spinAxis,yaw:-s.metrics.toe*Math.PI/180},u=d=>{let f=[l],h=Wb(s);for(let b=1;b<=r;b++){let g=d*(t*b)/r,y=at(e,s.beta,g,h,o),x=zt(Ce(e,n,g,Wb(y),o));if(!x||!y.converged){i++,f.push({...f[f.length-1]});continue}f.push({steer:x.metrics.toe,camber:x.metrics.camber,lift:-(y.points.contactPatch[2]-c),contactPatch:y.points.contactPatch,spinAxis:y.points.spinAxis,yaw:-y.metrics.toe*Math.PI/180}),h=Wb(y)}return f},m=u(1),p=u(-1);return{travelMm:n,unsolved:i,centre:l,positive:m,negative:p}}function X2(e,t){return e.map((r,n)=>{let o=n===0?0:n-1,a=n===e.length-1?e.length-1:n+1,s=t[a]-t[o];if(!(s>0))return{longitudinal:0,lateral:0,vertical:0,yaw:0};let i=Q($(e[a].contactPatch,e[o].contactPatch),1/s),c=ee(me(r.spinAxis,[0,0,1])),l=me([0,0,1],c);return{longitudinal:Z(i,c),lateral:Z(i,l),vertical:i[2],yaw:(e[a].yaw-e[o].yaw)/s}})}function fM(e,t,r){let n=o=>({steerDeg:o.map(a=>Math.abs(a.steer-e.centre.steer)),camberDeg:o.map(a=>a.camber-e.centre.camber),liftMm:o.map(a=>a.lift),jacobian:X2(o,t)});return{travelMm:e.travelMm,inner:n(r?e.positive:e.negative),outer:n(r?e.negative:e.positive)}}function q2(e){return e.positive[1].steer-e.centre.steer<0}function Q2(e,t,r){return{meanDeg:t.map((n,o)=>.5*(r.inner.steerDeg[o]+r.outer.steerDeg[o])),innerDeg:r.inner.steerDeg,outerDeg:r.outer.steerDeg,innerCamber:r.inner.camberDeg,outerCamber:r.outer.camberDeg,innerLift:r.inner.liftMm,outerLift:r.outer.liftMm,rackRatioMmPerRev:Yb(e.config),innerJacobian:r.inner.jacobian,outerJacobian:r.outer.jacobian}}function jb(e,t,r=13,n=-40,o=40,a=5,s){let i=Tt(e),c=Array.from({length:r+1},(b,g)=>t*g/r),l=pM(i,t,r,0,s),u=q2(l),m=fM(l,c,u),p=Math.max(2,Math.floor(a)),d=Array.from({length:p},(b,g)=>n+(o-n)*g/(p-1));d.some(b=>Math.abs(b)<1e-9)||d.push(0),d.sort((b,g)=>b-g);let f=l.unsolved,h=d.map(b=>{if(Math.abs(b)<1e-9)return m;let g=pM(i,t,r,b,s);return f+=g.unsolved,fM(g,c,u)});return{...Q2(e,c,m),...hM(l.unsolved),travelSurface:{rackMm:c,rows:h,...hM(f)}}}var hM=e=>e>0?{unsolved:e}:{};function rn(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function Sm(e,t,r){let n=e.length;if(n===0)return{longitudinal:0,lateral:0,vertical:0,yaw:0};let o,a;if(r<=e[0])o=a=0;else if(r>=e[n-1])o=a=n-1;else for(o=0,a=n-1;a-o>1;){let l=o+a>>1;e[l]<=r?o=l:a=l}let s=t[o];if(o===a)return{longitudinal:s.longitudinal,lateral:s.lateral,vertical:s.vertical,yaw:s.yaw};let i=t[a],c=(r-e[o])/(e[a]-e[o]);return{longitudinal:s.longitudinal+c*(i.longitudinal-s.longitudinal),lateral:s.lateral+c*(i.lateral-s.lateral),vertical:s.vertical+c*(i.vertical-s.vertical),yaw:s.yaw+c*(i.yaw-s.yaw)}}function bM(e,t){let r=e.rows;if(r.length<=1||t<=r[0].travelMm)return{lo:0,hi:0,t:0};let n=r.length-1;if(t>=r[n].travelMm)return{lo:n,hi:n,t:0};let o=0,a=n;for(;a-o>1;){let s=o+a>>1;r[s].travelMm<=t?o=s:a=s}return{lo:o,hi:a,t:(t-r[o].travelMm)/(r[a].travelMm-r[o].travelMm)}}var Uo=(e,t,r)=>e+r*(t-e);function Ts(e,t,r,n,o){let a=rn(e.rackMm,e.rows[n.lo][t][r],o);if(n.lo===n.hi)return a;let s=rn(e.rackMm,e.rows[n.hi][t][r],o);return Uo(a,s,n.t)}function gM(e,t,r,n){let o=Sm(e.rackMm,e.rows[r.lo][t].jacobian,n);if(r.lo===r.hi)return o;let a=Sm(e.rackMm,e.rows[r.hi][t].jacobian,n);return{longitudinal:Uo(o.longitudinal,a.longitudinal,r.t),lateral:Uo(o.lateral,a.lateral,r.t),vertical:Uo(o.vertical,a.vertical,r.t),yaw:Uo(o.yaw,a.yaw,r.t)}}function Ps(e,t,r,n){let o=e.travelSurface;if(!o||o.rackMm.length<2||o.rows.length===0)return Ls(e,t);let a=bM(o,r),s=bM(o,n),i=(d,f,h)=>{let b=o.rows[f.lo][d].steerDeg[h];return f.lo===f.hi?b:Uo(b,o.rows[f.hi][d].steerDeg[h],f.t)},c=new Array(o.rackMm.length);for(let d=0;d<c.length;d++)c[d]=.5*(i("inner",a,d)+i("outer",s,d));let l=Math.max(0,t),u=c.length-1,m=o.rackMm[u],p=l>c[u];if(l<=c[0])m=o.rackMm[0],p=!1;else if(!p){let d=1;for(;d<c.length-1&&c[d]<l;)d++;let f=d-1,h=c[d]-c[f],b=Math.abs(h)>1e-12?(l-c[f])/h:0;m=Uo(o.rackMm[f],o.rackMm[d],b)}return{innerDeg:Ts(o,"inner","steerDeg",a,m),outerDeg:Ts(o,"outer","steerDeg",s,m),innerCamber:Ts(o,"inner","camberDeg",a,m),outerCamber:Ts(o,"outer","camberDeg",s,m),innerLift:Ts(o,"inner","liftMm",a,m),outerLift:Ts(o,"outer","liftMm",s,m),innerJacobian:gM(o,"inner",a,m),outerJacobian:gM(o,"outer",s,m),atLock:p}}function Ls(e,t){let r=e.meanDeg.length-1;return{innerDeg:rn(e.meanDeg,e.innerDeg,t),outerDeg:rn(e.meanDeg,e.outerDeg,t),innerCamber:rn(e.meanDeg,e.innerCamber,t),outerCamber:rn(e.meanDeg,e.outerCamber,t),innerLift:e.innerLift?rn(e.meanDeg,e.innerLift,t):0,outerLift:e.outerLift?rn(e.meanDeg,e.outerLift,t):0,...e.innerJacobian&&e.outerJacobian?{innerJacobian:Sm(e.meanDeg,e.innerJacobian,t),outerJacobian:Sm(e.meanDeg,e.outerJacobian,t)}:{},atLock:r>=0&&t>e.meanDeg[r]}}var Z2=()=>({lift:{FL:0,FR:0,RL:0,RR:0},travel:{FL:0,FR:0,RL:0,RR:0},load:{FL:0,FR:0,RL:0,RR:0},rollDeg:0});function Ds(e,t,r=Ge(e),n){let o=e.steerFront;if(!o?.innerLift||!o.outerLift||o.meanDeg.length<2||Math.abs(t)<1e-12)return Z2();let a=Math.abs(t),s=t>0,i=n&&o.travelSurface?Ps(o,a,s?n.FL:n.FR,s?n.FR:n.FL):null,c=i?.innerLift??rn(o.meanDeg,o.innerLift,a),l=i?.outerLift??rn(o.meanDeg,o.outerLift,a),u=s?c:l,m=s?l:c,p=.5*(u+m),d=r.rollWheelRateFront,f=r.rollWheelRateRear,h=e.trackFront,b=e.trackRear,g=d*h*h+f*b*b,y=J2(e,d,f,h,b);if(y){let v=(m-u)/h,S=v/(1/y.front+1/y.rear+1/y.chassis),A=v-S/y.front,C=S/y.rear,F={FL:u-p+.5*h*A,FR:m-p-.5*h*A,RL:.5*b*C,RR:-.5*b*C},T=Math.max(0,Math.min(1,e.frontMassFrac)),M=k=>-Math.atan(k)*180/Math.PI;return{lift:{FL:u,FR:m,RL:0,RR:0},travel:F,load:{FL:d*F.FL,FR:d*F.FR,RL:f*F.RL,RR:f*F.RR},rollDeg:M(T*A+(1-T)*C),ends:{front:M(A),rear:M(C)}}}let x=g>0?d*h*(m-u)/g:0,R={FL:u-p+.5*h*x,FR:m-p-.5*h*x,RL:.5*b*x,RR:-.5*b*x};return{lift:{FL:u,FR:m,RL:0,RR:0},travel:R,load:{FL:d*R.FL,FR:d*R.FR,RL:f*R.RL,RR:f*R.RR},rollDeg:x===0?0:-Math.atan(x)*180/Math.PI}}function J2(e,t,r,n,o){let a=e.chassisTorsion??0,s=.5*t*n*n,i=.5*r*o*o;return!(a>0)||!Number.isFinite(a)||!(s>0)||!(i>0)?null:{front:s,rear:i,chassis:a*1e3*180/Math.PI}}function Ub(e,t,r){let n=t/r,o=a=>1/Math.tan(a*Math.PI/180);for(let a=0;a<e.meanDeg.length;a++)if(e.outerDeg[a]>.3&&e.innerDeg[a]>.3)return 100*(o(e.outerDeg[a])-o(e.innerDeg[a]))/n;return NaN}var gc=9.81;function Es(e,t,r=0,n=0,o=0){if(!e.aero||t<=0)return{FL:0,FR:0,RL:0,RR:0};let a=e.aero.model?Pn(e,t,r,ho(e,n,o)):Ko(e.aero,t),s=a.downFront/2,i=a.downRear/2,c=a.drag*(e.aero.copHeight/1e3)/(e.wheelbase/1e3)/2;return{FL:s-c,FR:s-c,RL:i+c,RR:i+c}}function Xb(e,t,r=0,n=0,o=0){if(!e.aero?.model||t<=0)return!1;let a=Pn(e,t,r,ho(e,n,o));return a!=null&&(a.clampedRide||a.clampedAttitude)}function Xo(e){let t=e.loadFactor===void 0?e.massTotal*gc:e.massTotal*gc*e.loadFactor,r=t*e.frontMassFrac,n=t*(1-e.frontMassFrac);return{FL:r/2,FR:r/2,RL:n/2,RR:n/2}}function yM(e,t=Ge(e),r=e.cgHeight){let n=e.trackFront/1e3,o=e.trackRear/1e3,a=e.rcHeightFront/1e3,s=e.rcHeightRear/1e3,i=(e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac))/1e3,c=r/1e3-i,l=2*e.unsprungPerCorner,u=e.unsprungCgHeight/1e3,m=t.sprungMass*c*em(t.sprungMass,c,t.rollRateTotal),p=(m*t.frontElasticShare+t.sprungFront*a+l*u)/n,d=(m*(1-t.frontElasticShare)+t.sprungRear*s+l*u)/o;return{cf:p,cr:d}}function yc(e){let{cf:t,cr:r}=yM(e);return t+r>0?t/(t+r):.5}var xM=e=>1-e.frontMassFrac;function RM(e,t,r,n=e.cgHeight){return n-(t+(r-t)*xM(e))}function vM(e,t){if(!Number.isFinite(t.rcFront)||!Number.isFinite(t.rcRear)||!Number.isFinite(t.arm))return NaN;let r=t.arm+t.rcFront+(t.rcRear-t.rcFront)*xM(e);return yc({...e,rcHeightFront:t.rcFront,rcHeightRear:t.rcRear,cgHeight:r})}function kM(e,t,r){if(e.FL>=0&&e.FR>=0&&e.RL>=0&&e.RR>=0)return{loads:{FL:Math.max(0,e.FL),FR:Math.max(0,e.FR),RL:Math.max(0,e.RL),RR:Math.max(0,e.RR)},lifted:{FL:!1,FR:!1,RL:!1,RR:!1},overturned:!1};let n=e.FL+e.FR+e.RL+e.RR;if(!(n>0))return{loads:{FL:0,FR:0,RL:0,RR:0},lifted:{FL:!0,FR:!0,RL:!0,RR:!0},overturned:!0};let o=!1,a=e.FL+e.FR,s=e.RL+e.RR;a<0?(a=0,s=n,o=!0):s<0&&(s=0,a=n,o=!0);let i=(e.FR-e.FL)*t+(e.RR-e.RL)*r,c=Math.min(a,Math.max(-a,e.FR-e.FL)),l=Math.min(s,Math.max(-s,e.RR-e.RL)),u=i-(c*t+l*r);if(u!==0){let p=u>0?1:-1,d=(p*a-c)*t;p*u>=p*d?(c=p*a,u-=d):(c+=u/t,u=0);let f=(p*s-l)*r;u!==0&&(p*u>=p*f?(l=p*s,u-=f):(l+=u/r,u=0)),Math.abs(u)>1e-9*(Math.abs(i)+n*(t+r))&&(o=!0)}let m={FL:Math.max(0,(a-c)/2),FR:Math.max(0,(a+c)/2),RL:Math.max(0,(s-l)/2),RR:Math.max(0,(s+l)/2)};return{loads:m,lifted:{FL:m.FL===0,FR:m.FR===0,RL:m.RL===0,RR:m.RR===0},overturned:o}}function Xe(e,t,r,n=0,o=0,a=0,s,i){return Am(e,t,r,n,o,a,s,i).loads}function Am(e,t,r,n=0,o=0,a=0,s,i){let c=Xo(e),l=Ge(e),u=cm(e,n,r,ho(e,t,o),l),{cf:m,cr:p}=yM(e,l,u.height),d=m*t*gc,f=p*t*gc,h=e.massTotal*(r*gc)*u.height/e.wheelbase-u.noseLoad,b=Es(e,n,r,t,o),g=(i??Ds(e,a,l,s)).load,y={FL:c.FL-d-h/2+b.FL+g.FL,FR:c.FR+d-h/2+b.FR+g.FR,RL:c.RL-f+h/2+b.RL+g.RL,RR:c.RR+f+h/2+b.RR+g.RR};return kM(y,e.trackFront,e.trackRear)}var qb=Math.PI/180;function Fm(e,t){let r=8*qb,n=0,o=0;for(let a=1;a<=90;a++){let s=a*.5,i=Math.abs(e.Fy(s*qb,t,0));if(i>n&&(n=i,r=s*qb,o=a),a>o+12&&i<.995*n)break}return{aPeak:r,fyPeak:n}}function MM(e,t,r,n,o){if(n===t)return r;let a=(o-t)/(n-t);return a<=0?e:a>=1?r:e+a*(r-e)}var vc=.999;function lr(e,t,r,n,o){if(t<=0)return 0;let{aPeak:a,fyPeak:s}=o??Fm(e,t),i=Math.min(Math.abs(r),vc*s),c=n?-1:1,l=(v,S)=>Math.abs(e.forces({Fz:t,kappa:c*v,alpha:S}).Fy),u=.3,m=u,p=l(u,a);if(p<i){let v=0,S=u,A=NaN,C=p;for(let F=0;F<9;F++){let T=.5*(v+S),M=l(T,a);M>=i?(v=T,A=M):(S=T,C=M)}Number.isNaN(A)&&(A=l(0,a)),m=A<i?0:MM(v,A,S,C,i)}if(m<=0)return 0;let d=v=>{if(i===0)return c*e.forces({Fz:t,kappa:c*v,alpha:0}).Fx;let S=0,A=a,C=NaN,F=NaN;for(let T=0;T<5;T++){let M=.5*(S+A),k=l(v,M);k<i?(S=M,C=k):(A=M,F=k)}return Number.isNaN(C)&&(C=l(v,0)),Number.isNaN(F)&&(F=l(v,a)),c*e.forces({Fz:t,kappa:c*v,alpha:MM(S,C,A,F,i)}).Fx},f=4,h=v=>m*v/f,b=[0],g=1;for(let v=1;v<=f;v++)b.push(d(h(v))),b[v]>b[g]&&(g=v);let[y,x]=g===f?[f-1,f-2]:b[g-1]>=b[g+1]?[g-1,g+1]:[g+1,g-1],R=n_(d,h(g-1),h(Math.min(f,g+1)),h(g),b[g],h(y),b[y],h(x),b[x],e_);return c*Math.max(0,R)}var e_=.01,t_=20,r_=(3-Math.sqrt(5))/2;function n_(e,t,r,n,o,a,s,i,c,l){o=-o,s=-s,c=-c;let u=r-t,m=0;for(let p=0;p<t_;p++){let d=l*Math.abs(n)+1e-10,f=.5*(t+r);if(Math.abs(n-f)<=2*d-.5*(r-t))break;let h=!0;if(Math.abs(u)>d){let y=(n-a)*(o-c),x=(n-i)*(o-s),R=(n-i)*x-(n-a)*y;x=2*(x-y),x>0&&(R=-R),x=Math.abs(x);let v=u;if(u=m,Math.abs(R)<Math.abs(.5*x*v)&&R>x*(t-n)&&R<x*(r-n)){m=R/x;let S=n+m;(S-t<2*d||r-S<2*d)&&(m=f>=n?d:-d),h=!1}}h&&(u=n>=f?t-n:r-n,m=r_*u);let b=Math.abs(m)>=d?n+m:n+(m>=0?d:-d),g=-e(b);g<=o?(b>=n?t=n:r=n,i=a,c=s,a=n,s=o,n=b,o=g):(b<n?t=b:r=b,g<=s||a===n?(i=a,c=s,a=b,s=g):(g<=c||i===n||i===a)&&(i=b,c=g))}return-o}function Jb(e,t,r){if(!(r<1))return 0;let n=Math.max(0,r);return wM(o=>Math.hypot(o,n)/e.reach(t,o,n)-1)}function AM(e,t,r){let n=Math.max(0,r);return wM(o=>Math.hypot(n,o)/e.reach(t,n,o)-1)}function wM(e){let t=0,r=1,n=e(t),o=e(r);if(!(n<0))return 0;if(!(o>0))return 1;let a=0;for(let s=0;s<60;s++){let i=(t*o-r*n)/(o-n),c=e(i);if(Math.abs(c)<1e-12||r-t<1e-12)return i;c>0?(r=i,o=c,a===-1&&(n/=2),a=-1):(t=i,n=c,a===1&&(o/=2),a=1)}return t-n*(r-t)/(o-n)}function eg(e,t){return e.model?.kind==="simple"?null:CM(e,t)}var SM=new WeakMap,o_=8,Qb=100,FM=1.35,Zb=18,xc=Array.from({length:Zb},(e,t)=>Qb*FM**t),nn=41,wm=41,Rc=65;function CM(e,t){let r=xc.map(b=>t.muX(b)),n=xc.map(b=>t.muY(b)),o=`${r.join(",")}|${n.join(",")}`,a=SM.get(e),s=a?.get(o);if(s)return s;let i=Math.log(FM),c=(b,g)=>{let y=xc[b],x=M=>Math.abs(lr(e,y,M,g)),R=x(0),v=n[b]*y,S=new Float64Array(nn),A=R>0&&v>0?Math.max(1,r[b]*y/R):1;if(!(R>0)||!(v>0))S.fill(1);else{let M=[],k=[];for(let P=0;P<wm;P++){let L=Math.sin(.5*Math.PI*P/(wm-1));M.push(L),k.push(P===0?1:P===wm-1?0:Math.min(k[P-1],x(L*v)/R))}let w=wm-1;for(let P=0;P<nn;P++){let L=P/(nn-1);for(;w>0&&k[w-1]<L;)w--;let E=w>0?k[w-1]-k[w]:0;S[P]=w===0?M[0]:M[w]+(E>0?(L-k[w])/E:0)*(M[w-1]-M[w])}S[0]=1,S[nn-1]=0}let C=new Float64Array(Rc),F=M=>Math.atan2(S[M],M/(nn-1)/A),T=nn-2;for(let M=0;M<Rc;M++){let k=.5*Math.PI*M/(Rc-1),w=Math.cos(k),P=Math.sin(k);for(;T>0&&F(T)<k;)T--;let L=T/(nn-1)/A,E=S[T],_=(T+1)/(nn-1)/A,D=S[T+1],I=w*(D-E)-P*(_-L),N=Math.abs(I)>1e-12?(L*(D-E)-E*(_-L))/I:Math.hypot(L,E);C[M]=N>0?N:Math.hypot(L,E)}return{room:S,scale:A,edge:C}},l=xc.map((b,g)=>c(g,!1)),u=xc.map((b,g)=>c(g,!0)),m=(b,g)=>{let y=Math.min(1,Math.abs(g)*b.scale)*(nn-1),x=Math.min(nn-2,Math.floor(y));return b.room[x]+(y-x)*(b.room[x+1]-b.room[x])},p=b=>{let g=b>Qb?Math.log(b/Qb)/i:0;if(g>=Zb-1)return[Zb-2,1];let y=Math.floor(g);return[y,g-y]},d=(b,g,y)=>{if(y===0)return 1;let x=y<0?u:l,R=m(x[b],y);return g>0?R+g*(m(x[b+1],y)-R):R},f=(b,g,y)=>{let x=g<0?u:l,[R,v]=p(b),S=Math.atan2(Math.abs(y),Math.abs(g))/(.5*Math.PI)*(Rc-1),A=Math.min(Rc-2,Math.floor(S)),C=T=>T.edge[A]+(S-A)*(T.edge[A+1]-T.edge[A]),F=C(x[R]);return v>0?F+v*(C(x[R+1])-F):F},h={keeps(b,g){if(g===0)return 1;let[y,x]=p(b);return d(y,x,g)},atLoad(b){let[g,y]=p(b);return x=>d(g,y,x)},use(b,g,y){let x=Math.hypot(g,y);return x>0?Math.min(1,x/f(b,g,y)):0},reach:f};return a||SM.set(e,a=new Map),a.size>=o_&&a.clear(),a.set(o,h),h}var a_=[["front","FL","FR"],["rear","RL","RR"]];function Is(e,t,r,n){let o={...e},a=0,s=vc;for(let[i,c,l]of a_){let u=(R,v)=>n(i,Math.max(0,v[R])).fyPeak,m=Math.min(s,e[c]),p=Math.min(s,e[l]),d=m*u(c,r)+p*u(l,r);if(!(d>0))continue;let f=u(c,t),h=u(l,t),b=m*f+p*h,g=b>0?d/b:1/0,y=m*g,x=p*g;y<=s?x<=s||(x=s,y=f>0?(d-s*h)/f:1/0):(y=s,x=h>0?(d-s*f)/h:1/0),(!(y<=s)||!(x<=s))&&(a+=Math.max(0,d-s*(f+h)),y=Math.min(s,y),x=Math.min(s,x)),o[c]=y,o[l]=x}return{util:o,short:a}}var TM=.001,s_=1e-5,PM=100;function i_(e,t,r,n){if(!(n>TM))return r;let o=t,a=Math.abs(r-t)<PM?t+Math.sign(r-t)*PM:r;for(let s=0;s<60&&Math.abs(a-o)>s_;s++){let i=.5*(o+a);e(i)>TM?a=i:o=i}return o}function Cm(e,t,r){let n;return{at:o=>{if(n!==void 0)return r<0?Math.max(o,n):Math.min(o,n);if(!((o-t)*r>0))return o;let a=i_(e,t,o,e(o));return a!==o&&(n=a),a},edge:()=>n}}function Tm(e,t){let r=n=>{try{return Ce(e,0,n).ok}catch{return!1}};for(let n of[1,-1]){if(r(n*t))continue;let o=0;for(let a=1;a<=6;a++){let s=n*t*a/6;if(!r(s))break;o=Math.abs(s)}return{lock:t,reached:o,side:n}}return null}var tg=40;function Pm(e){return{violation:Math.max(0,e.lock-e.reached),reason:`the steering reaches only ${e.reached.toFixed(0)} mm of the ${e.lock.toFixed(0)} mm rack travel${e.side<0?" (other side)":""}`}}var LM=[0,0,0];function c_(e,t){let r=ee($(e.rockerPivotB,e.rockerPivotA)),n=ee($(e.rockerToPushrod,e.pushrodOuter)),o=ee($(e.damperChassis,e.rockerToDamper)),a=Math.abs(Z(r,me($(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(Z(r,me($(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}function Lm(e,t,r){if(e.mcpherson)return l_(e,t,r);let n=[{r:e.uprightUpper,c:e.ucaFront},{r:e.uprightUpper,c:e.ucaRear},{r:e.uprightLower,c:e.lcaFront},{r:e.uprightLower,c:e.lcaRear},{r:e.tieOuter,c:e.tieInner},{r:e.pushrodOuter,c:e.direct?e.damperChassis:e.rockerToPushrod}],o=e.wheelCenter,a=[[],[],[],[],[],[]];for(let m=0;m<6;m++){let p=ee($(n[m].c,n[m].r)),d=me($(n[m].r,o),p);a[0][m]=p[0],a[1][m]=p[1],a[2][m]=p[2],a[3][m]=d[0],a[4][m]=d[1],a[5][m]=d[2]}let s=me($(e.contactPatch,o),t),i=r??LM,c=[-t[0],-t[1],-t[2],-(s[0]+i[0]),-(s[1]+i[1]),-(s[2]+i[2])],l=Jr(a,c),u=l.x;return{ucaFront:u[0],ucaRear:u[1],lcaFront:u[2],lcaRear:u[3],tieRod:u[4],pushRod:u[5],damper:l.singular||e.decoupled?NaN:e.direct?u[5]:c_(e,u[5]),condProxy:l.condProxy,singular:l.singular}}function l_(e,t,r){let n=e.wheelCenter,o=e.damperChassis,a=[{at:e.uprightLower,dir:ee($(e.lcaFront,e.uprightLower))},{at:e.uprightLower,dir:ee($(e.lcaRear,e.uprightLower))},{at:e.tieOuter,dir:ee($(e.tieInner,e.tieOuter))},{at:o,dir:[1,0,0]},{at:o,dir:[0,1,0]},{at:o,dir:[0,0,1]}],s=[[],[],[],[],[],[]];for(let b=0;b<6;b++){let g=a[b].dir,y=me($(a[b].at,n),g);s[0][b]=g[0],s[1][b]=g[1],s[2][b]=g[2],s[3][b]=y[0],s[4][b]=y[1],s[5][b]=y[2]}let i=me($(e.contactPatch,n),t),c=r??LM,l=[-t[0],-t[1],-t[2],-(i[0]+c[0]),-(i[1]+c[1]),-(i[2]+c[2])],u=Jr(s,l),m=u.x,p=[m[3],m[4],m[5]],d=ee($(o,e.pushrodOuter)),f=Z(p,d),h=Math.hypot(p[0]-f*d[0],p[1]-f*d[1],p[2]-f*d[2]);return{ucaFront:NaN,ucaRear:NaN,lcaFront:m[0],lcaRear:m[1],tieRod:m[2],pushRod:u.singular?NaN:f,damper:u.singular?NaN:f,condProxy:u.condProxy,singular:u.singular,strutSide:u.singular?NaN:h,topMount:p}}function rg(e,t){let r=ee(e.spinAxis),n=me($(e.contactPatch,e.wheelCenter),t),o=Z(n,r);return[-o*r[0],-o*r[1],-o*r[2]]}var u_=[0,0,0];function kc(e,t,r,n){let o=e.direct?e.damperChassis:e.rockerToPushrod;if(e.mcpherson)return{...Lm(e,r,n),armResidual:0};if(t==="upright")return{...Lm(e,r,n),armResidual:0};let a=t==="lowerArm",s=a?{bj:e.uprightUpper,front:e.ucaFront,rear:e.ucaRear}:{bj:e.uprightLower,front:e.lcaFront,rear:e.lcaRear},i=a?{bj:e.uprightLower,front:e.lcaFront,rear:e.lcaRear}:{bj:e.uprightUpper,front:e.ucaFront,rear:e.ucaRear},c=e.wheelCenter,l=ee($(s.front,s.bj)),u=ee($(s.rear,s.bj)),m=ee($(e.tieInner,e.tieOuter)),p=[{at:s.bj,dir:l},{at:s.bj,dir:u},{at:e.tieOuter,dir:m},{at:i.bj,dir:[1,0,0]},{at:i.bj,dir:[0,1,0]},{at:i.bj,dir:[0,0,1]}],d=[[],[],[],[],[],[]];for(let W=0;W<6;W++){let z=p[W].dir,Y=me($(p[W].at,c),z);d[0][W]=z[0],d[1][W]=z[1],d[2][W]=z[2],d[3][W]=Y[0],d[4][W]=Y[1],d[5][W]=Y[2]}let f=me($(e.contactPatch,c),r),h=n??u_,b=[-r[0],-r[1],-r[2],-(f[0]+h[0]),-(f[1]+h[1]),-(f[2]+h[2])],g=Jr(d,b),y=g.singular,x=g.x,R=x[0],v=x[1],S=x[2],A=[x[3],x[4],x[5]],C=ee($(i.rear,i.front)),F=ee($(o,e.pushrodOuter)),T=Q(A,-1),M=(W,z)=>Z(C,me($(W,i.front),z)),k=M(e.pushrodOuter,F),w=Math.abs(k)>1e-9?-M(i.bj,T)/k:NaN,P=ne(T,Q(F,w)),L=Q(P,-1),E=ee($(i.front,i.bj)),_=ee($(i.rear,i.bj)),D=Z(E,E),I=Z(E,_),N=Z(_,_),O=Z(E,L),V=Z(_,L),H=D*N-I*I,U=NaN,G=NaN,B=NaN;if(Math.abs(H)>1e-12){U=(O*N-V*I)/H,G=(D*V-I*O)/H;let W=ne(Q(E,U),Q(_,G)),z=$(L,W);B=Math.hypot(z[0],z[1],z[2])}let q=a?{f:R,r:v}:{f:U,r:G},re=a?{f:U,r:G}:{f:R,r:v};return{ucaFront:q.f,ucaRear:q.r,lcaFront:re.f,lcaRear:re.r,tieRod:S,pushRod:w,damper:y||!Number.isFinite(w)||e.decoupled?NaN:e.direct?w:m_(e,w),condProxy:g.condProxy,singular:y,armResidual:B}}function m_(e,t){let r=ee($(e.rockerPivotB,e.rockerPivotA)),n=ee($(e.rockerToPushrod,e.pushrodOuter)),o=ee($(e.damperChassis,e.rockerToDamper)),a=Math.abs(Z(r,me($(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(Z(r,me($(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}var sU=Math.PI/180;function Mc(e,t){let r=Math.min(Math.max(t,e.range[0]),e.range[1])-e.reference;return Math.max(.2,1+e.perDegC*r+e.perDegC2*r*r)}var EM=["QSX3","QSX8","QSX13","QSX14"],d_=["QSX1"],Dm=["PHY1","PHY2","PHY3","PKY6","PKY7","PVY1","PVY2","PVY3","PVY4","PEY3","PEY4","QHZ1","QHZ2","QHZ3","QHZ4","QEZ4","QEZ5","QDZ6","QDZ7","QDZ8","QDZ9","QDZ10","QDZ11","SSZ1","SSZ3","SSZ4","RBY3","RHX1","RVY1","RVY2","RVY3",...EM],p_=["PKY6","PKY7","PVY3","PVY4","PHY3","PEY4","RVY3","QBZ4","QDZ3","QHZ3","QHZ4","QEZ5","QDZ8","QDZ9","QDZ10","QDZ11","SSZ3","SSZ4"];function f_(){let e=new Set(p_),t=Dm.filter(r=>!EM.includes(r));return[...t.filter(r=>!e.has(r)),...[...e].filter(r=>!t.includes(r)),...d_]}function h_(e,t){let r={...e};for(let n of t)r[n]!==void 0&&r[n]!==0&&(r[n]=-r[n]);return r}var In=(e,t,r)=>Number.isFinite(e[t])?e[t]:r;function IM(e,t){return t!=="5.2"?In(e,"PKY6",0)*In(e,"LKYC",1):In(e,"PKY1",-15)*Math.sin(In(e,"PKY4",2)*Math.atan(1/In(e,"PKY2",2)))*In(e,"LKY",1)*In(e,"PHY3",0)+In(e,"PVY3",0)*In(e,"LMUY",1)}var DM=.1;function _M(e){if(e.fitData)return"sae";let t=IM(e.coeffs,e.version);return t>DM?"sae":t<-DM?"iso":null}function Sc(e){return e.axisSystem??_M(e)??"sae"}function Em(e){let t=new Set,r=n=>{for(let o of n)t.has(o)?t.delete(o):t.add(o)};return Sc(e)==="iso"&&r(Dm),e.axisSystem&&e.side==="left"&&r(f_()),t.size?h_(e.coeffs,t):e.coeffs}var cU=Math.PI/180;var K=(e,t)=>Number.isFinite(e)?e:t;function OM(e){let t=Em(e);return{PCX1:K(t.PCX1,1.65),PDX1:K(t.PDX1,1),PDX2:K(t.PDX2,0),PDX3:K(t.PDX3,0),PEX1:K(t.PEX1,0),PEX2:K(t.PEX2,0),PEX3:K(t.PEX3,0),PEX4:K(t.PEX4,0),PHX1:K(t.PHX1,0),PHX2:K(t.PHX2,0),PKX1:K(t.PKX1,20),PKX2:K(t.PKX2,0),PKX3:K(t.PKX3,0),PPX1:K(t.PPX1,0),PPX2:K(t.PPX2,0),PPX3:K(t.PPX3,0),PPX4:K(t.PPX4,0),PVX1:K(t.PVX1,0),PVX2:K(t.PVX2,0),PCY1:K(t.PCY1,1.3),PDY1:K(t.PDY1,1),PDY2:K(t.PDY2,0),PDY3:K(t.PDY3,0),PEY1:K(t.PEY1,0),PEY2:K(t.PEY2,0),PEY3:K(t.PEY3,0),PEY4:K(t.PEY4,0),PEY5:K(t.PEY5,0),PHY1:K(t.PHY1,0),PHY2:K(t.PHY2,0),PHY3:K(t.PHY3,0),PKY1:K(t.PKY1,-15),PKY2:K(t.PKY2,2),PKY3:K(t.PKY3,0),PKY4:K(t.PKY4,2),PKY5:K(t.PKY5,0),PKY6:K(t.PKY6,0),PKY7:K(t.PKY7,0),PPY1:K(t.PPY1,0),PPY2:K(t.PPY2,0),PPY3:K(t.PPY3,0),PPY4:K(t.PPY4,0),PPY5:K(t.PPY5,0),PVY1:K(t.PVY1,0),PVY2:K(t.PVY2,0),PVY3:K(t.PVY3,0),PVY4:K(t.PVY4,0),RBX1:K(t.RBX1,0),RBX2:K(t.RBX2,0),RBX3:K(t.RBX3,0),RBY1:K(t.RBY1,0),RBY2:K(t.RBY2,0),RBY3:K(t.RBY3,0),RBY4:K(t.RBY4,0),RCX1:K(t.RCX1,1),RCY1:K(t.RCY1,1),REX1:K(t.REX1,0),REX2:K(t.REX2,0),REY1:K(t.REY1,0),REY2:K(t.REY2,0),RHX1:K(t.RHX1,0),RHY1:K(t.RHY1,0),RHY2:K(t.RHY2,0),RVY1:K(t.RVY1,0),RVY2:K(t.RVY2,0),RVY3:K(t.RVY3,0),RVY4:K(t.RVY4,0),RVY5:K(t.RVY5,1),RVY6:K(t.RVY6,0),PPZ1:K(t.PPZ1,0),PPZ2:K(t.PPZ2,0),QBZ1:K(t.QBZ1,8),QBZ2:K(t.QBZ2,0),QBZ3:K(t.QBZ3,0),QBZ4:K(t.QBZ4,0),QBZ5:K(t.QBZ5,0),QBZ9:K(t.QBZ9,0),QBZ10:K(t.QBZ10,0),QCZ1:K(t.QCZ1,1.1),QDZ1:K(t.QDZ1,.1),QDZ2:K(t.QDZ2,0),QDZ3:K(t.QDZ3,0),QDZ4:K(t.QDZ4,0),QDZ6:K(t.QDZ6,0),QDZ7:K(t.QDZ7,0),QDZ8:K(t.QDZ8,0),QDZ9:K(t.QDZ9,0),QDZ10:K(t.QDZ10,0),QDZ11:K(t.QDZ11,0),QEZ1:K(t.QEZ1,0),QEZ2:K(t.QEZ2,0),QEZ3:K(t.QEZ3,0),QEZ4:K(t.QEZ4,0),QEZ5:K(t.QEZ5,0),QHZ1:K(t.QHZ1,0),QHZ2:K(t.QHZ2,0),QHZ3:K(t.QHZ3,0),QHZ4:K(t.QHZ4,0),SSZ1:K(t.SSZ1,0),SSZ2:K(t.SSZ2,0),SSZ3:K(t.SSZ3,0),SSZ4:K(t.SSZ4,0),QSX1:K(t.QSX1,0),QSX2:K(t.QSX2,0),QSX3:K(t.QSX3,0),QSX4:K(t.QSX4,0),QSX5:K(t.QSX5,0),QSX6:K(t.QSX6,0),QSX7:K(t.QSX7,0),QSX8:K(t.QSX8,0),QSX9:K(t.QSX9,0),QSX10:K(t.QSX10,0),QSX11:K(t.QSX11,0),QSX12:K(t.QSX12,0),QSX13:K(t.QSX13,0),QSX14:K(t.QSX14,0),PPMX1:K(t.PPMX1,0),QSY1:K(t.QSY1,0),QSY2:K(t.QSY2,0),QSY3:K(t.QSY3,0),QSY4:K(t.QSY4,0),QSY5:K(t.QSY5,0),QSY6:K(t.QSY6,0),QSY7:K(t.QSY7,0),QSY8:K(t.QSY8,0),LONGVL:t.LONGVL!==void 0&&t.LONGVL>0?t.LONGVL:16.7,LCX:K(t.LCX,1),LCY:K(t.LCY,1),LEX:K(t.LEX,1),LEY:K(t.LEY,1),LFZO:K(t.LFZO,1),LHX:K(t.LHX,1),LHY:K(t.LHY,1),LKX:K(t.LKX,1),LKY:K(t.LKY,1),LKYC:K(t.LKYC,1),LKZC:K(t.LKZC,1),LMUX:K(t.LMUX,1),LMUY:K(t.LMUY,1),LMX:K(t.LMX,1),LMY:K(t.LMY,1),LVMX:K(t.LVMX,1),LRES:K(t.LRES,1),LS:K(t.LS,1),LTR:K(t.LTR,1),LVX:K(t.LVX,1),LVY:K(t.LVY,1),LVYKA:K(t.LVYKA,1),LXAL:K(t.LXAL,1),LYKA:K(t.LYKA,1)}}var NM=new WeakMap;function Ac(e){let t=NM.get(e);return t===void 0&&(t=OM(e),NM.set(e,t)),t}var VM=e=>e>=0?1:-1;function wc(e,t,r=0,n){let o=Ac(e),a=Math.max(1,t),s=r,i=o.LFZO*e.fnomin,c=(a-i)/i,l=e.nomPressure>0&&n?(n-e.nomPressure)/e.nomPressure:0,u=e.unloadedR0,m=(o.PDY1+o.PDY2*c)*(1+o.PPY3*l+o.PPY4*l*l)*(1-o.PDY3*s*s)*o.LMUY,p=o.PCY1*o.LCY,d=m*a,f=o.PKY1*i*(1+o.PPY1*l)*Math.sin(o.PKY4*Math.atan(a/((o.PKY2+o.PKY5*s*s)*(1+o.PPY2*l)*i)))*(1-o.PKY3*Math.abs(s))*o.LKY,h=e.version!=="5.2",b=a*(o.PKY6+o.PKY7*c)*(1+o.PPY5*l)*o.LKYC,g=a*(o.PVY3+o.PVY4*c)*s*o.LKYC*o.LMUY,y=Math.abs(f)>1e-6?f:1e-6*(f<0?-1:1),x=h?(o.PHY1+o.PHY2*c)*o.LHY+(b*s-g)/y:(o.PHY1+o.PHY2*c)*o.LHY+o.PHY3*s,R=h?a*(o.PVY1+o.PVY2*c)*o.LVY*o.LMUY+g:a*((o.PVY1+o.PVY2*c)*o.LVY+(o.PVY3+o.PVY4*c)*s)*o.LMUY,v=p*d!==0?f/(p*d):0;return{Fz:a,g:s,dfz:c,dpi:l,Fz0p:i,R0:u,Cy:p,Dy:d,By:v,SHy:x,SVy:R,Kya:f,muy:m,EyA:o.PEY1+o.PEY2*c,EyG:1+o.PEY5*s*s,EyS:o.PEY3+o.PEY4*s,LEY:o.LEY}}function Im(e,t,r=0,n){let o=wc(e,t,r,n),a=Ac(e),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,muy:p,Kya:d,SVy:f,By:h,Cy:b,Dy:g,SHy:y}=o,x=(a.PHX1+a.PHX2*c)*a.LHX,R=(a.PDX1+a.PDX2*c)*(1+a.PPX3*l+a.PPX4*l*l)*(1-a.PDX3*i*i)*a.LMUX,v=a.PCX1*a.LCX,S=R*s,A=s*(a.PKX1+a.PKX2*c)*Math.exp(a.PKX3*c)*(1+a.PPX1*l+a.PPX2*l*l)*a.LKX,C=v*S!==0?A/(v*S):0,F=Math.abs(d)>1e-6?d:1e-6*(d<0?-1:1),T=e.version!=="5.2",M=s*(a.PVX1+a.PVX2*c)*a.LVX*a.LMUX,k=T&&i!==0?wc(e,t,0,n):o,w=a.REX1+a.REX2*c;w>1&&(w=1);let P=a.REY1+a.REY2*c;return P>1&&(P=1),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,Cy:b,Dy:g,By:h,SHy:y,SVy:f,Kya:d,muy:p,EyA:o.EyA,EyG:o.EyG,EyS:o.EyS,LEY:o.LEY,SHx:x,Cx:v,Dx:S,Bx:C,SVx:M,ExA:a.PEX1+a.PEX2*c+a.PEX3*c*c,PEX4:a.PEX4,LEX:a.LEX,SHxa:a.RHX1,Bxa0:a.RBX1+a.RBX3*i*i,RBX2:a.RBX2,LXAL:a.LXAL,Cxa:a.RCX1,Exa:w,SHyk:a.RHY1+a.RHY2*c,Byk0:a.RBY1+a.RBY4*i*i,RBY2:a.RBY2,RBY3:a.RBY3,LYKA:a.LYKA,Cyk:a.RCY1,Eyk:P,DVykA:p*s*(a.RVY1+a.RVY2*c+a.RVY3*i),RVY4:a.RVY4,RVY5:a.RVY5,RVY6:a.RVY6,LVYKA:a.LVYKA,SHt:a.QHZ1+a.QHZ2*c+(a.QHZ3+a.QHZ4*c)*i,Bt:(a.QBZ1+a.QBZ2*c+a.QBZ3*c*c)*(1+a.QBZ4*i+a.QBZ5*Math.abs(i))*(a.LKY/a.LMUY),Ct:a.QCZ1,Dt:s*(m/u)*(a.QDZ1+a.QDZ2*c)*(1-a.PPZ1*l)*(1+a.QDZ3*i+a.QDZ4*i*i)*a.LTR,EtA:a.QEZ1+a.QEZ2*c+a.QEZ3*c*c,EtG:a.QEZ4+a.QEZ5*i,Br:a.QBZ9*(a.LKY/a.LMUY)+a.QBZ10*h*b,Dr:T?s*m*((a.QDZ6+a.QDZ7*c)*a.LRES+((a.QDZ8+a.QDZ9*c)*(1+a.PPZ2*l)+(a.QDZ10+a.QDZ11*c)*Math.abs(i))*i*a.LKZC)*a.LMUY:s*m*((a.QDZ6+a.QDZ7*c)*a.LRES+(a.QDZ8+a.QDZ9*c)*(1+a.PPZ2*l)*i)*a.LMUY,arOff:d!==0?f/d:0,sixOne:T,y0:k,kk:A/F*(A/F),sS0:m*(a.SSZ1+(a.SSZ3+a.SSZ4*c)*i)*a.LS,sS2:m*a.SSZ2*a.LS/u}}function qo(e,t){let r=t+e.SHy,n=e.EyA*(e.EyG-e.EyS*VM(r))*e.LEY;n>1&&(n=1);let o=e.By*r;return e.Dy*Math.sin(e.Cy*Math.atan(o-n*(o-Math.atan(o))))+e.SVy}function _m(e,t){let r=t+e.SHx,n=e.ExA*(1-e.PEX4*VM(r))*e.LEX;n>1&&(n=1);let o=e.Bx*r;return e.Dx*Math.sin(e.Cx*Math.atan(o-n*(o-Math.atan(o))))+e.SVx}function BM(e,t,r){if(r===0)return t;let n=Math.tan(t);return Math.atan(Math.sqrt(n*n+e.kk*r*r))*Math.sign(t)}function b_(e,t,r,n){let o=t+e.SHt,a=e.EtA*(1+e.EtG*(2/Math.PI)*Math.atan(e.Bt*e.Ct*o));a>1&&(a=1);let s=BM(e,o,r),i=e.Bt*s;return e.Dt*Math.cos(e.Ct*Math.atan(i-a*(i-Math.atan(i))))*n}function g_(e,t,r,n){return e.Dr*Math.cos(Math.atan(e.Br*BM(e,t+e.SHy+e.arOff,r)))*n}function $M(e,t,r,n,o,a){let s=Math.cos(t),i=b_(e,t,r,s),c=g_(e,t,r,s);return-i*a+c+(e.sS0+e.sS2*o)*n}function y_(e,t,r,n,o,a){return e.sixOne?r*(e.g===0?n:qo(e.y0,t)):o-a}function Nm(e,t,r){let n=e.Bxa0*Math.cos(Math.atan(e.RBX2*t))*e.LXAL,o=r+e.SHxa,a=e.SHxa===0?1:Math.cos(e.Cxa*Math.atan(n*e.SHxa-e.Exa*(n*e.SHxa-Math.atan(n*e.SHxa))))||1;return Math.cos(e.Cxa*Math.atan(n*o-e.Exa*(n*o-Math.atan(n*o))))/a*_m(e,t)}function ng(e,t){let r=e.sS0===0&&e.sS2===0?0:Nm(e,0,t),n=qo(e,t);return $M(e,t,0,r,n,e.sixOne&&e.g!==0?qo(e.y0,t):n)}function Om(e,t,r){let n=qo(e,r),o=Nm(e,t,r),a=e.Byk0*Math.cos(Math.atan(e.RBY2*(r-e.RBY3)))*e.LYKA,s=t+e.SHyk,i=e.SHyk===0?1:Math.cos(e.Cyk*Math.atan(a*e.SHyk-e.Eyk*(a*e.SHyk-Math.atan(a*e.SHyk))))||1,c=Math.cos(e.Cyk*Math.atan(a*s-e.Eyk*(a*s-Math.atan(a*s))))/i,u=e.DVykA*Math.cos(Math.atan(e.RVY4*r))*Math.sin(e.RVY5*Math.atan(e.RVY6*t))*e.LVYKA,m=c*n+u;return{Fx:o,Fy:m,Mz:$M(e,r,t,o,m,y_(e,r,c,n,m,u))}}var Fc=(e,t)=>Math.max(.1,e.muY0+e.loadSensY*(t-e.nominalLoad)),Cc=(e,t)=>Math.max(.1,e.muX0+e.loadSensX*(t-e.nominalLoad)),GM=(e,t,r)=>Fc(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cy*Math.atan(e.By*r)),KM=(e,t,r)=>Cc(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cx*Math.atan(e.Bx*r));function og(e,t){let r=Math.max(1,t.Fz),n=Fc(e,r)*r,o=Cc(e,r)*r,a=n*Math.sin(e.Cy*Math.atan(e.By*t.alpha)),s=o*Math.sin(e.Cx*Math.atan(e.Bx*t.kappa)),i=Math.hypot(o>0?s/o:0,n>0?a/n:0);return i>1&&(s/=i,a/=i),{Fx:s,Fy:a,Mz:0}}var _s=Math.PI/180;function yo(e){if(e.kind==="simple")return"none";let t=e.missing?.some(n=>/^aligning moment Mz\b/i.test(n))??!1,r=["QBZ1","QCZ1","QDZ1"].every(n=>Number.isFinite(e.coeffs[n]));return t||!r?"assumed":"model"}function HM(e){let t=e.thermal?.operating;if(t===void 0||!e.thermal)return e;let{lateral:r,longitudinal:n,aligning:o}=e.thermal,a=r?Mc(r,t):1,s=n?Mc(n,t):1,i=o?Mc(o,t):1;if(a===1&&s===1&&i===1)return e;if(e.kind==="simple")return{...e,muY0:e.muY0*a,muX0:e.muX0*s};let c={...e.coeffs},l=(u,m)=>{c[u]=(c[u]??1)*m};return l("LMUY",a),l("LMUX",s),l("LTR",i),l("LRES",i),{...e,coeffs:c}}function Ns(e,t,r){let n=0,o=0;for(let s=r;s<=t;s+=r){let i=Math.abs(e(s));i>o&&(o=i,n=s)}let a=r/10;for(let s=Math.max(a,n-r);s<=n+r;s+=a)o=Math.max(o,Math.abs(e(s)));return o}var xU=Math.LN2/16;var x_=45;var R_=[];for(let e=1;e<=x_;e++){let t=[];for(let r=Math.max(.1,e-1);r<=e+1;r+=.1)t.push(r);R_[e]=t}var zM=new WeakMap;function Bm(e,t){zM.set(e,t)}function on(e){return zM.get(e)??((t,r,n,o,a)=>e.forces({Fz:t,kappa:r,alpha:n,gamma:o,p:a}).Fx)}function We(e){let t=HM(e),r=t,n=t,o=4,a=b=>{let g=[],y=[],x=[],R=[];for(let A=0;A<o;A++)g.push(null),y.push(NaN),x.push(NaN),R.push(NaN);let v=0,S=0;return(A,C,F)=>{if(g[v]!==null&&A===y[v]&&C===x[v]&&F===R[v])return g[v];for(let M=0;M<o;M++)if(g[M]!==null&&A===y[M]&&C===x[M]&&F===R[M])return v=M,g[M];let T=b(A,C,F);return g[S]=T,y[S]=A,x[S]=C,R[S]=F,v=S,S=(S+1)%o,T}},s=a((b,g,y)=>Im(r,b,g,y)),i=a((b,g,y)=>wc(r,b,g,y)),c=b=>e.kind==="magic"?Om(s(b.Fz,b.gamma??0,b.p),b.kappa,b.alpha):og(n,b),l=(b,g,y=0,x)=>e.kind==="magic"?qo(i(g,y,x),b):GM(n,g,b),u=(b,g,y=0,x)=>e.kind==="magic"?_m(s(g,y,x),b):KM(n,g,b),m=(b,g,y=0,x)=>e.kind==="magic"?ng(s(g,y,x),b):c({Fz:g,kappa:0,alpha:b,gamma:y,p:x}).Mz,p=b=>e.kind==="simple"?Fc(n,b):Ns(g=>l(g*_s,b),45,1)/Math.max(1,b),d=b=>e.kind==="simple"?Cc(n,b):Ns(g=>u(g,b),.6,.02)/Math.max(1,b),f=b=>{let g=.1*_s;return Math.abs((l(g,b)-l(-g,b))/(2*g))},h={model:e,forces:c,Fx:u,Fy:l,Mz:m,muX:d,muY:p,corneringStiffness:f,verticalStiffness:()=>e.verticalStiffness,rollingRadius:b=>{if(e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS"))return 0;let g=e.unloadedR0??0;if(!(g>0))return 0;let y=e.verticalStiffness*1e3;if(!(y>0))return g;let x=e.rollingFraction??.306;return g-x*Math.max(0,b)/y},relaxationLength:b=>{let g=e.relaxation;if(!g)return 0;let y=g.carcassStiffness??0;if(!(y>0))return g.sigma;let x=f(Math.max(0,b));return x>0?x/(y*1e3):g.sigma}};return e.kind==="magic"&&Bm(h,(b,g,y,x,R)=>Nm(s(b,x,R),g,y)),h}function Os(e){let t=Math.max(1,e.model.kind==="magic"?e.model.fnomin:e.model.nominalLoad);return e.Fy(2*_s,t,0)-e.Fy(-2*_s,t,0)>=0?1:-1}function Tc(e,t=e.kind==="magic"?e.fnomin:e.nominalLoad){let r=We(e),n=2*_s,o=3*_s,a=r.Fy(n,t,0),s=r.Fy(n,t,o);return!Number.isFinite(a)||!Number.isFinite(s)?!1:Math.abs(s-a)>1}var v_=Math.PI/180;function Te(e,t){return e.axle?e.axle(t):e}function $m(e,t){if(e===t)return e;let r=Os(e)*Os(t),n=(p,d)=>.5*(p+d),o=(p,d)=>p>0&&d>0?n(p,d):p>0?p:d>0?d:0,a=p=>{let d=e.forces(p),f=t.forces(p);return{Fx:n(d.Fx,f.Fx),Fy:n(d.Fy,r*f.Fy),Mz:n(d.Mz,r*f.Mz)}},s=(p,d,f=0,h)=>n(e.Fx(p,d,f,h),t.Fx(p,d,f,h)),i=(p,d,f=0,h)=>n(e.Fy(p,d,f,h),r*t.Fy(p,d,f,h)),c=(p,d,f=0,h)=>n(e.Mz(p,d,f,h),r*t.Mz(p,d,f,h)),l={model:e.model,forces:a,Fx:s,Fy:i,Mz:c,muX:p=>Ns(d=>s(d,p),.6,.02)/Math.max(1,p),muY:p=>Ns(d=>i(d*v_,p),45,1)/Math.max(1,p),corneringStiffness:p=>n(e.corneringStiffness(p),t.corneringStiffness(p)),verticalStiffness:()=>o(e.verticalStiffness(),t.verticalStiffness()),rollingRadius:p=>o(e.rollingRadius(p),t.rollingRadius(p)),relaxationLength:p=>o(e.relaxationLength(p),t.relaxationLength(p)),axle:p=>p==="front"?e:t},u=on(e),m=on(t);return Bm(l,(p,d,f,h,b)=>n(u(p,d,f,h,b),m(p,d,f,h,b))),l}function Yt(e){if(YM.has(e))return e;let t=WM.get(e);if(t)return t;let r;if(e.axle){let n=e.axle("front"),o=e.axle("rear"),a=Yt(n),s=Yt(o);r=a===n&&s===o?e:$m(a,s)}else Os(e)>0?r=e:(r={...e,forces:n=>{let o=e.forces(n);return{Fx:o.Fx,Fy:-o.Fy,Mz:-o.Mz}},Fy:(n,o,a,s)=>-e.Fy(n,o,a,s),Mz:(n,o,a,s)=>-e.Mz(n,o,a,s)},Bm(r,on(e)));return YM.add(r),r!==e&&WM.set(e,r),r}var YM=new WeakSet,WM=new WeakMap;var Gm=25*(Math.PI/180);function k_(e){let t=.6180339887,r=0,n=Gm,o=n-t*(n-r),a=r+t*(n-r),s=e(o),i=e(a);for(let l=0;l<12;l++)s>i?(n=a,a=o,i=s,o=n-t*(n-r),s=e(o)):(r=o,o=a,s=i,a=r+t*(n-r),i=e(a));return{alpha:s>i?o:a,force:Math.max(s,i)}}function Pc(e,t,r,n,o=0){let a=Math.abs(t);if(!(a>0))return 0;let s=u=>Math.abs(e.Fy(u,r,0))+Math.abs(e.Fy(u,n,0)),i=0,c=Gm;if(s(Gm)<=a){let u=k_(s);if(u.force<=a)return u.alpha;c=u.alpha}else if(o>0){let u=Math.max(0,o*.6),m=Math.min(Gm,o*1.6+.001);s(u)<a&&s(m)>=a&&(i=u,c=m)}let l=.001*a;for(let u=0;u<12;u++){let m=.5*(i+c),p=s(m)-a;if(p<0?i=m:c=m,Math.abs(p)<=l)return m}return c}var ag={shaft:!1,trail:0,hub:[0,0,0]};function UM(e){let t=e.spinAxis,r=Math.hypot(t[0],t[1]);if(r<1e-9)return[1,0,0];let n=[-t[1]/r,t[0]/r,0];return n[0]<0?[-n[0],-n[1],0]:n}function sg(e,t,r){let n=r.shaft?rg(e,t):[0,0,0];if(r.trail!==0){let a=UM(e),s=[t[0],t[1],0],i=$(s,Q(a,Z(s,a)));n=ne(n,me(Q(a,-r.trail),i))}let o=r.hub;return(o[0]!==0||o[1]!==0||o[2]!==0)&&(n=$(n,me($(e.contactPatch,e.wheelCenter),o))),{force:ne(t,o),moment:n}}var M_=(e,t)=>{let r=e!==void 0&&e>0?1/e:0,n=t!==void 0&&t>0?1/t:0;return r+n},Km={ucaFront:0,ucaRear:0,lcaFront:0,lcaRear:0,tieRod:0,pushRod:0,rack:0};function Qo(e){return!e.measured}function Zo(e){if(!e)return!1;let t=r=>!!r&&Object.values(r).some(n=>n!==void 0&&n>0&&Number.isFinite(n));return t(e.links)||t(e.bushings)||e.rack!==void 0&&e.rack>0}function Lc(e,t){let r=e.corner.hardpoints,n=Rs(e.rocker,t.points.rockerAngle);return{ucaFront:r.ucaFront,ucaRear:r.ucaRear,lcaFront:r.lcaFront,lcaRear:r.lcaRear,tieInner:Ho(e.inv,t.steer),rockerPivotA:r.rockerPivotA,rockerPivotB:r.rockerPivotB,damperChassis:e.inv.strut?t.points.uprightUpper:r.damperChassis,uprightUpper:t.points.uprightUpper,uprightLower:t.points.uprightLower,tieOuter:t.points.tieOuter,wheelCenter:t.points.wheelCenter,pushrodOuter:t.points.pushrodOuter,contactPatch:t.points.contactPatch,kingpinGround:t.points.kingpinGround,kingpinAtHub:t.points.kingpinAtHub,rockerToPushrod:n.pushrod,rockerToDamper:n.damper,spinAxis:t.points.spinAxis,direct:e.corner.config.actuation==="direct",decoupled:e.corner.config.actuation==="decoupled",mcpherson:e.inv.strut!==void 0,loadedRadius:e.corner.config.loadedRadius,tyreDeflection:0,load:NaN,lifted:!1,clearance:0,contactLength:0}}function ig(e,t,r=0){let n=t.links??{},o=t.bushings??{},a=(l,u,m)=>{let p=M_(u,m);return p>0&&Number.isFinite(l)?l*p:0},s=o.topMount,i=e.topMount,c=i&&s!==void 0&&s>0&&i.every(Number.isFinite)?[-i[0]/s,-i[1]/s,-i[2]/s]:void 0;return{...c?{topMount:c}:{},ucaFront:a(e.ucaFront,n.ucaFront,o.ucaFront),ucaRear:a(e.ucaRear,n.ucaRear,o.ucaRear),lcaFront:a(e.lcaFront,n.lcaFront,o.lcaFront),lcaRear:a(e.lcaRear,n.lcaRear,o.lcaRear),tieRod:a(e.tieRod,n.tieRod,o.tieInner),pushRod:a(e.pushRod,n.pushRod,void 0),rack:r}}function XM(e,t,r,n){let o=Le(e,t);if(!(o>1e-9))return{axial:r,radius2:0};let a=(r*r-n*n+o*o)/(2*o);return{axial:a,radius2:Math.max(0,r*r-a*a)}}function Dc(e,t){let r=e.corner.hardpoints,n=e.inv,o={...n};if(n.strut&&t.topMount&&t.topMount.some(i=>i!==0)&&(o.strut={...n.strut,top:ne(n.strut.top,t.topMount)}),t.ucaFront!==0||t.ucaRear!==0){let i=XM(r.ucaFront,r.ucaRear,Le(r.uprightUpper,r.ucaFront)+t.ucaFront,Le(r.uprightUpper,r.ucaRear)+t.ucaRear);o.ubjAxial0=i.axial,o.ubjRadius2=i.radius2}if(t.lcaFront!==0||t.lcaRear!==0){let i=XM(r.lcaFront,r.lcaRear,Le(r.uprightLower,r.lcaFront)+t.lcaFront,Le(r.uprightLower,r.lcaRear)+t.lcaRear),c=Z(n.lbjRel0,n.lcaDir),l=$(n.lbjRel0,Q(n.lcaDir,c)),u=Math.hypot(l[0],l[1],l[2]);o.lbjRel0=u>1e-9?ne(Q(n.lcaDir,i.axial),Q(l,Math.sqrt(i.radius2)/u)):ne(Q(n.lcaDir,i.axial),l)}if(t.tieRod!==0){let i=Math.sqrt(n.tieLen2)+t.tieRod;o.tieLen2=i*i}if(t.rack!==0&&(o.tieInner0=ne(n.tieInner0,Q(n.rackAxis,t.rack))),t.pushRod===0)return{corner:e.corner,inv:o,rocker:e.rocker};let a=Math.sqrt(e.rocker.rodLen2)+t.pushRod,s={...e.rocker,rodLen2:a*a};return{corner:e.corner,inv:o,rocker:s}}var S_=8,A_=1e-5,w_=e=>({q:[e.pose.t[0],e.pose.t[1],e.pose.t[2],e.pose.omega[0],e.pose.omega[1],e.pose.omega[2]],phi:e.points.rockerAngle});function cg(e,t,r){let n=sg(e,r.force,r.extras??ag),o=r.alignMoment?ne(n.moment,[0,0,r.alignMoment]):n.moment;return kc(e,t,n.force,o)}function zm(e,t,r,n,o,a,s=0){let i=at(e,t,r,o,a),c=e.corner.compliance;if(!(Zo(c)&&Qo(e.corner)))return{state:i,forces:cg(Lc(e,i),e.corner.config.pushrodAttach,n),deflection:Km,rigid:i,iterations:0,converged:!0,bypassed:!0};let u=i,m=e,p=e.corner.config.pushrodAttach,d=cg(Lc(e,i),p,n),f=Km,h=!1,b=0;for(;b<S_;b++){let g=Lc(m,u);if(d=cg(g,p,n),d.singular)break;f=ig(d,c,s),m=Dc(e,f);let y=at(m,t,r,w_(u),a),x=Le(y.points.wheelCenter,u.points.wheelCenter);if(u=y,x<A_){h=!0;break}}return{state:u,forces:d,deflection:f,rigid:i,iterations:b+1,converged:h&&u.converged,bypassed:!1}}var Hm=1e3,qM=1e5;function QM(e,t,r,n,o){let a=zm(e,t,r,n,void 0,o);return{toe:a.state.metrics.toe,camber:a.state.metrics.camber,patch:a.state.points.contactPatch,converged:a.converged,bypassed:a.bypassed}}function Ym(e,t,r,n,o){let a={force:[0,0,n]},s=(b,g=0)=>QM(e,t,r,{force:b,alignMoment:g},o),i=QM(e,t,r,a,o);if(i.bypassed)return{toePerLateral:0,camberPerLateral:0,toePerLongitudinal:0,camberPerLongitudinal:0,toePerAligning:0,lateralPatch:0,longitudinalPatch:0,bypassed:!0,converged:!0};let c=s([0,Hm,n]),l=s([0,-Hm,n]),u=s([Hm,0,n]),m=s([-Hm,0,n]),p=s([0,0,n],qM),d=s([0,0,n],-qM),f=(b,g)=>(b-g)/2,h=[i,c,l,u,m,p,d].every(b=>b.converged);return{toePerLateral:f(c.toe,l.toe),camberPerLateral:f(c.camber,l.camber),toePerLongitudinal:f(u.toe,m.toe),camberPerLongitudinal:f(u.camber,m.camber),toePerAligning:f(p.toe,d.toe),lateralPatch:f(c.patch[1],l.patch[1]),longitudinalPatch:f(u.patch[0],m.patch[0]),bypassed:!1,converged:h}}var F_=1e3;function lg(e,t=F_){if(!Zo(e.compliance)||!Qo(e))return;let r=Tt(e),n=at(r,0,0),o=Ym(r,n.beta,0,t);if(!o.bypassed)return{toePerFy:o.toePerLateral/1e3,camberPerFy:o.camberPerLateral/1e3,toePerFx:o.toePerLongitudinal/1e3,camberPerFx:o.camberPerLongitudinal/1e3,toePerMz:o.toePerAligning/1e5}}function Vs(e,t=-tg,r=tg,n=21){let o=e.measured;if(o)return{travel:[...o.travel],motionRatio:[...o.motionRatio],camber:[...o.camber],toe:[...o.toe],damperLen:o.damperLen?[...o.damperLen]:o.travel.map(()=>0)};let a=ut(e,{travelMin:t,travelMax:r,steps:n}),s=lg(e);return{travel:a.samples.map(i=>i.travel),motionRatio:a.samples.map(i=>i.metrics.motionRatio??1),camber:a.samples.map(i=>i.metrics.camber),toe:a.samples.map(i=>i.metrics.toe),damperLen:a.samples.map(i=>i.metrics.damperLength),...s?{compliance:s}:{}}}function Wm(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function xo(e,t){return{motionRatio:Wm(e.travel,e.motionRatio,t),camber:Wm(e.travel,e.camber,t),toe:Wm(e.travel,e.toe,t),damperLen:Wm(e.travel,e.damperLen,t)}}var ZM=Math.PI/180,C_=9.81;function Ro(e,t,r,n=0){let o=Ge(e),a=e.wheelbase*(1-e.frontMassFrac),s=e.wheelbase*e.frontMassFrac,i=Es(e,n),c=e.aero?.model?(R,v,S)=>Es(e,n,v,R,S):()=>i,l=xo(t,0),u=xo(r,0),m=e.loadFactor,p=m!==void 0&&m!==1?(m-1)*e.massTotal*C_:0,d=p*e.frontMassFrac/2,f=p*(1-e.frontMassFrac)/2,h=(R,v)=>v>0&&Number.isFinite(v)&&R+v>0?v/(R+v):1,b=xt(e,"front"),g=xt(e,"rear"),y={F:h(e.wheelRateFront+(e.heaveSpringFront??0),b),R:h(e.wheelRateRear+(e.heaveSpringRear??0),g)},x={F:h(e.wheelRateFront+e.arbFront,b),R:h(e.wheelRateRear+e.arbRear,g)};return(R,v,S=0,A=0)=>{let C=c(R,v,S),F={F:o.rollGradientFront*R,R:o.rollGradientRear*R},T=o.pitchGradient*v*ZM,M=(_,D)=>{let I=D==="F"?e.trackFront:e.trackRear,N=D==="F"?o.rideRateFront:o.rideRateRear,O=(_==="R"?1:-1)*(I/2)*Math.tan(F[D]*ZM),V=(D==="R"?s:-a)*Math.tan(T),H=`${D}${_}`,U=p?C[H]+(D==="F"?d:f):C[H],G=N>0?U/N:0;return{anti:O,sym:V+G}},k={FL:M("L","F"),FR:M("R","F"),RL:M("L","R"),RR:M("R","R")},w=_=>{let D=_[0];return k[_].sym*y[D]+k[_].anti*x[D]},P=Ds(e,A,o,{FL:w("FL"),FR:w("FR")}),L=P.ends?{F:F.F+P.ends.front,R:F.R+P.ends.rear}:{F:F.F+P.rollDeg,R:F.R+P.rollDeg},E=(_,D)=>{let I=D==="F"?t:r,N=D==="F"?l:u,O=`${D==="F"?"F":"R"}${_}`,V=k[O].sym+k[O].anti+P.travel[O],H=w(O)+P.travel[O]*x[D],U=V-H,G=xo(I,H),B=(_==="R"?1:-1)*G.camber;return{travel:H,tyre:U,ground:V,camber:B,camberRoad:B+L[D],toe:G.toe,bumpToe:G.toe-N.toe,damperTravel:N.damperLen-G.damperLen}};return{FL:E("L","F"),FR:E("R","F"),RL:E("L","R"),RR:E("R","R"),steeringJacking:P}}}var ug=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Jo(e){return{enabled:e?.enabled===!0,roadFeedbackGain:Math.min(2,Math.max(0,ug(e?.roadFeedbackGain,1))),turnInFrictionNm:Math.max(0,ug(e?.turnInFrictionNm,0)),columnStiffnessNmPerRad:Math.max(0,ug(e?.columnStiffnessNmPerRad,0))}}function mg(e,t,r){let n=Jo(r);if(!n.enabled)return{roadNm:e,assistanceNm:0,frictionNm:0,columnTwistDeg:0,driverNm:e};let o=e*(n.roadFeedbackGain-1),a=t===0?0:Math.sign(t)*n.turnInFrictionNm,s=e+o+a,i=n.columnStiffnessNmPerRad>0?s/n.columnStiffnessNmPerRad*(180/Math.PI):0;return{roadNm:e,assistanceNm:o,frictionNm:a,columnTwistDeg:i,driverNm:s}}var JM=()=>({totalNm:0,aligningNm:0,lateralNm:0,longitudinalNm:0,jackingNm:0});function ea(e){let t=e.steerFront;return!!(t?.rackRatioMmPerRev&&t.innerJacobian&&t.innerJacobian.length>=2&&t.outerJacobian&&t.outerJacobian.length>=2&&t.meanDeg.length>=2)}function Ec(e,t,r,n="model",o){let a=e.steerFront;if(!ea(e)||!a)return null;let s=t<0?-1:1,c=a.rackRatioMmPerRev/(2*Math.PI)/1e3,l=t>=0,u=o&&a.travelSurface?Ps(a,Math.abs(t),l?o.FL:o.FR,l?o.FR:o.FL):Ls(a,Math.abs(t));if(!u.innerJacobian||!u.outerJacobian)return null;let m=(b,g)=>{let y=r[b],x=b==="FL"?-1:1,R=-x*y.Fy,S={aligning:1e3*(-x*y.Mz)*g.yaw,lateral:R*g.lateral,longitudinal:y.Fx*g.longitudinal,jacking:y.Fz*g.vertical},A=JM();A.aligningNm=-s*S.aligning*c,A.lateralNm=-s*S.lateral*c,A.longitudinalNm=-s*S.longitudinal*c,A.jackingNm=-s*S.jacking*c,A.totalNm=A.aligningNm+A.lateralNm+A.longitudinalNm+A.jackingNm;let C=-s*(S.aligning+S.lateral+S.longitudinal+S.jacking);return{moment:A,rackN:C}},p=m("FL",l?u.innerJacobian:u.outerJacobian),d=m("FR",l?u.outerJacobian:u.innerJacobian),f=JM();for(let b of[p.moment,d.moment])f.aligningNm+=b.aligningNm,f.lateralNm+=b.lateralNm,f.longitudinalNm+=b.longitudinalNm,f.jackingNm+=b.jackingNm,f.totalNm+=b.totalNm;let h=mg(f.totalNm,t,e.steeringSystem);return f.totalNm=h.driverNm,{...f,roadNm:h.roadNm,assistanceNm:h.assistanceNm,frictionNm:h.frictionNm,columnTwistDeg:h.columnTwistDeg,rackForceN:p.rackN+d.rackN,aligningSource:n,perWheel:{FL:p.moment,FR:d.moment}}}var T_=e=>"front"in e&&"rear"in e;function Bs(e,t){return T_(e)?e[t]:e}function pg(e,t,r=24){let n=Math.max(1,t),o=n/Math.max(1,r-1),a=[],s=[],i=[];for(let l=0;l<r;l++){let u=l*o;a.push(u),s.push(e.muX(u)),i.push(e.muY(u))}let c=(l,u)=>{if(!(u>0))return l[0];if(u>=n)return l[r-1];let m=Math.min(r-2,Math.floor(u/o)),p=(u-a[m])/o;return l[m]+p*(l[m+1]-l[m])};return{muX:l=>c(s,l),muY:l=>c(i,l)}}function dg(e,t){let r=Math.max(0,t.Fz);return tS(e.muX(r)*r,e.muY(r)*r,t)}function tS(e,t,r){if(!(t>0))return{fyUsed:0,fyMax:0,fyRes:0};let n=e>0?Math.min(1,Math.abs(r.Fx)/e):0,o=t*Math.sqrt(Math.max(0,1-n*n)),a=Math.abs(r.Fy);return{fyUsed:a,fyMax:o,fyRes:Math.max(0,o-a)}}function eS(e,t,r){let n=dg(e,t),o=dg(e,r);return{left:n,right:o,fyRes:n.fyRes+o.fyRes}}function _n(e,t,r){let n=eS(Bs(e,"front"),t.FL,t.FR),o=eS(Bs(e,"rear"),t.RL,t.RR),a=r.lf>0&&Number.isFinite(r.lf)?r.lf:0,s=r.lr>0&&Number.isFinite(r.lr)?r.lr:0,i=o.fyRes*s,c=n.fyRes*a,l=i-c,u=Math.max(Math.abs(i),Math.abs(c));return{stabil:i,agil:c,diff:l,rel:u>0?l/u:0,front:n,rear:o}}var Ic=[{q:"p",section:"INFLATION_PRESSURE_RANGE",min:"PRESMIN",max:"PRESMAX",what:"pressure"},{q:"fz",section:"VERTICAL_FORCE_RANGE",min:"FZMIN",max:"FZMAX",what:"load"},{q:"kappa",section:"LONG_SLIP_RANGE",min:"KPUMIN",max:"KPUMAX",what:"slip ratio"},{q:"alpha",section:"SLIP_ANGLE_RANGE",min:"ALPMIN",max:"ALPMAX",what:"slip angle"},{q:"gamma",section:"INCLINATION_ANGLE_RANGE",min:"CAMMIN",max:"CAMMAX",what:"inclination"}],L_=Ic.flatMap(e=>[e.min,e.max]);function D_(e){let t={};for(let r of Ic){let n=e[r.min],o=e[r.max],a={};Number.isFinite(n)&&(a.min=n),Number.isFinite(o)&&(a.max=o),(a.min!==void 0||a.max!==void 0)&&(t[r.q]=a)}return Object.keys(t).length?t:void 0}function jm(e){if(e.kind==="magic")return e.range??D_(e.coeffs)}function fg(e){return Math.max(1,e.kind==="magic"?e.fnomin:e.nominalLoad)}function rS(e,t,r,n,o){let a=(r-t)/n,s=t,i=e(t);for(let c=t+a;c<=r;c+=a){let l=e(c);o(l,i)&&(i=l,s=c)}return s}function $r(e){let t=nS.get(e);if(t!==void 0)return t;let r=10*fg(e.model),{turnover:n,collapse:o}=I_(e,r),a=n??o??r;return nS.set(e,a),a}var nS=new WeakMap;function I_(e,t){let r=fg(e.model),n=m=>e.muY(m),o=m=>n(m)*m,a=80,s=t/a,i=null,c=o(s);for(let m=2;m<=a;m++){let p=o(m*s);if(p<c){i=rS(o,(m-2)*s,m*s,20,(d,f)=>d>f);break}c=p}let l=null,u=n(s);for(let m=2;m<=a;m++){let p=n(m*s);if(p>u){let d=rS(n,(m-2)*s,m*s,40,(f,h)=>f<h);n(d)<.05*n(r)&&(l=d);break}u=p}return{turnover:i,collapse:l}}var oS=.1;function Um(e,t=fg(e)){let r=We(e).muX(t);return{muX:r,none:Number.isFinite(r)&&r<oS}}var aS=["FL","FR","RL","RR"],__=e=>e==="FL"||e==="RL",N_=e=>e==="FL"||e==="FR"?"front":"rear";function Xm(e,t,r,n){if(!(e.full>e.open)||n.ayDir===0)return e.full;let o=n.halfTrack[e.axle],a={};for(let l of aS)a[l]={...t[l]};let s=l=>{let u=0;for(let p of aS)N_(p)===e.axle&&(a[p].Fx=e.sense*(p===e.strong?l-e.open/2:e.open/2),u-=(__(p)?o:-o)*a[p].Fx);let m=_n(r,a,n.arms);return u*n.ayDir>=0?Math.abs(u)<=m.stabil:Math.abs(u)<=m.agil};if(s(e.full))return e.full;let i=e.open,c=e.full;for(let l=0;l<20&&c-i>.001*e.full;l++){let u=.5*(i+c);s(u)?i=u:c=u}return i}var O_=[["PCY1","Shape factor Cfy for lateral forces",1.3],["PDY1","Lateral friction Muy",1],["PDY2","Variation of friction Muy with load",0],["PDY3","Variation of friction Muy with squared camber",0],["PEY1","Lateral curvature Efy at Fznom",0],["PEY2","Variation of curvature Efy with load",0],["PEY3","Zero order camber dependency of curvature Efy",0],["PEY4","Variation of curvature Efy with camber",0],["PEY5","Variation of curvature Efy with camber squared",0],["PKY1","Maximum value of stiffness Kfy/Fznom",-15],["PKY2","Load at which Kfy reaches maximum value",2],["PKY3","Variation of Kfy/Fznom with camber",0],["PKY4","Curvature of stiffness Kfy",2],["PKY5","Peak stiffness variation with camber squared",0],["PKY6","Fy camber stiffness factor",0],["PKY7","Vertical load dependency of camber stiffness",0],["PHY1","Horizontal shift Shy at Fznom",0],["PHY2","Variation of shift Shy with load",0],["PHY3","Variation of shift Shy with camber",0],["PVY1","Vertical shift in Svy/Fz at Fznom",0],["PVY2","Variation of shift Svy/Fz with load",0],["PVY3","Variation of shift Svy/Fz with camber",0],["PVY4","Variation of shift Svy/Fz with camber and load",0],["PPY1","Influence of inflation pressure on cornering stiffness",0],["PPY2","Influence of inflation pressure on dependency of nominal tyre load on cornering stiffness",0],["PPY3","Linear influence of inflation pressure on lateral peak friction",0],["PPY4","Quadratic influence of inflation pressure on lateral peak friction",0],["PPY5","Influence of inflation pressure on camber stiffness",0]],V_=[["PCX1","Shape factor Cfx for longitudinal force",1.65],["PDX1","Longitudinal friction Mux at Fznom",1],["PDX2","Variation of friction Mux with load",0],["PDX3","Variation of friction Mux with camber squared",0],["PEX1","Longitudinal curvature Efx at Fznom",0],["PEX2","Variation of curvature Efx with load",0],["PEX3","Variation of curvature Efx with load squared",0],["PEX4","Factor in curvature Efx while driving",0],["PKX1","Longitudinal slip stiffness Kfx/Fz at Fznom",20],["PKX2","Variation of slip stiffness Kfx/Fz with load",0],["PKX3","Exponent in slip stiffness Kfx/Fz with load",0],["PHX1","Horizontal shift Shx at Fznom",0],["PHX2","Variation of shift Shx with load",0],["PVX1","Vertical shift Svx/Fz at Fznom",0],["PVX2","Variation of shift Svx/Fz with load",0],["PPX1","Linear influence of inflation pressure on longitudinal slip stiffness",0],["PPX2","Quadratic influence of inflation pressure on longitudinal slip stiffness",0],["PPX3","Linear influence of inflation pressure on peak longitudinal friction",0],["PPX4","Quadratic influence of inflation pressure on peak longitudinal friction",0]],B_=[["QBZ1","Trail slope factor for trail Bpt at Fznom",8],["QBZ2","Variation of slope Bpt with load",0],["QBZ3","Variation of slope Bpt with load squared",0],["QBZ4","Variation of slope Bpt with camber",0],["QBZ5","Variation of slope Bpt with absolute camber",0],["QBZ9","Factor for scaling factors of slope factor Br of Mzr",0],["QBZ10","Factor for dimensionless cornering stiffness of Br of Mzr",0],["QCZ1","Shape factor Cpt for pneumatic trail",1.1],["QDZ1","Peak trail Dpt = Dpt*(Fz/Fznom*R0)",.1],["QDZ2","Variation of peak Dpt with load",0],["QDZ3","Variation of peak Dpt with camber",0],["QDZ4","Variation of peak Dpt with camber squared",0],["QDZ6","Peak residual torque Dmr = Dmr/(Fz*R0)",0],["QDZ7","Variation of peak factor Dmr with load",0],["QDZ8","Variation of peak factor Dmr with camber",0],["QDZ9","Variation of peak factor Dmr with camber and load",0],["QDZ10","Variation of peak factor Dmr with camber squared",0],["QDZ11","Variation of Dmr with camber squared and load",0],["QEZ1","Trail curvature Ept at Fznom",0],["QEZ2","Variation of curvature Ept with load",0],["QEZ3","Variation of curvature Ept with load squared",0],["QEZ4","Variation of curvature Ept with sign of Alpha-t",0],["QEZ5","Variation of Ept with camber and sign Alpha-t",0],["QHZ1","Trail horizontal shift Sht at Fznom",0],["QHZ2","Variation of shift Sht with load",0],["QHZ3","Variation of shift Sht with camber",0],["QHZ4","Variation of shift Sht with camber and load",0],["PPZ1","Effect of inflation pressure on length of pneumatic trail",0],["PPZ2","Influence of inflation pressure on residual aligning torque",0],["SSZ1","Nominal value of s/R0: effect of Fx on Mz",0],["SSZ2","Variation of distance s/R0 with Fy/Fznom",0],["SSZ3","Variation of distance s/R0 with camber",0],["SSZ4","Variation of distance s/R0 with load and camber",0]],$_=[["RBX1","Slope factor for combined slip Fx reduction",0],["RBX2","Variation of slope Fx reduction with kappa",0],["RBX3","Influence of camber on stiffness for Fx combined",0],["RCX1","Shape factor for combined slip Fx reduction",1],["REX1","Curvature factor of combined Fx",0],["REX2","Curvature factor of combined Fx with load",0],["RHX1","Shift factor for combined slip Fx reduction",0],["RBY1","Slope factor for combined Fy reduction",0],["RBY2","Variation of slope Fy reduction with alpha",0],["RBY3","Shift term for alpha in slope Fy reduction",0],["RBY4","Influence of camber on stiffness of Fy combined",0],["RCY1","Shape factor for combined Fy reduction",1],["REY1","Curvature factor of combined Fy",0],["REY2","Curvature factor of combined Fy with load",0],["RHY1","Shift factor for combined Fy reduction",0],["RHY2","Shift factor for combined Fy reduction with load",0],["RVY1","Kappa induced side force Svyk/Muy*Fz at Fznom",0],["RVY2","Variation of Svyk/Muy*Fz with load",0],["RVY3","Variation of Svyk/Muy*Fz with camber",0],["RVY4","Variation of Svyk/Muy*Fz with alpha",0],["RVY5","Variation of Svyk/Muy*Fz with kappa",1],["RVY6","Variation of Svyk/Muy*Fz with atan(kappa)",0]],G_=[["LFZO","Scale factor of nominal (rated) load",1],["LCX","Scale factor of Fx shape factor",1],["LMUX","Scale factor of Fx peak friction coefficient",1],["LEX","Scale factor of Fx curvature factor",1],["LKX","Scale factor of Fx slip stiffness",1],["LHX","Scale factor of Fx horizontal shift",1],["LVX","Scale factor of Fx vertical shift",1],["LCY","Scale factor of Fy shape factor",1],["LMUY","Scale factor of Fy peak friction coefficient",1],["LEY","Scale factor of Fy curvature factor",1],["LKY","Scale factor of Fy cornering stiffness",1],["LKYC","Scale factor of camber force stiffness",1],["LKZC","Scale factor of camber torque stiffness",1],["LHY","Scale factor of Fy horizontal shift",1],["LVY","Scale factor of Fy vertical shift",1],["LTR","Scale factor of peak of pneumatic trail",1],["LRES","Scale factor for offset of residual torque",1],["LXAL","Scale factor of alpha influence on Fx",1],["LYKA","Scale factor of kappa influence on Fy",1],["LVYKA","Scale factor of kappa induced Fy",1],["LS","Scale factor of moment arm of Fx",1]],iS=[["lateral",O_],["longitudinal",V_],["aligning",B_],["combined",$_],["scaling",G_]].flatMap(([e,t])=>t.map(([r,n,o])=>({key:r,section:e,text:n,fallback:o}))),d9=new Map(iS.map(e=>[e.key,e]));var K_=/^\$\s*EDITED\s+([A-Z][A-Z0-9_]*)\s+was\s+(absent|[-+0-9.eE]+)\s*$/;function cS(e){let t={};for(let r of e.split(/\r?\n/)){let n=r.trim().match(K_);if(!n)continue;let o=n[2]==="absent"?null:parseFloat(n[2]);(o===null||Number.isFinite(o))&&(t[n[1]]=o)}return Object.keys(t).length?t:void 0}var z_=/^\s*\$\s*UNLOADED_RADIUS_STAND_IN\s*=\s*([0-9.eE+-]+)/,Y_=/^\$-+ written by (?:PaceDynamics|PaceLab)\b/m,W_=/^\$\s*AXIS_SYSTEM\s*=\s*(ISO-W|SAE)\b/m;function j_(e){let t=e.match(W_);return t?{axisSystem:t[1]==="SAE"?"sae":"iso",trustSide:!0}:Y_.test(e)?{axisSystem:"sae",trustSide:!1}:{axisSystem:"iso",trustSide:!0}}function U_(e){return e>=62?"6.2":e>=61?"6.1":"5.2"}var lS=new Map([["pa",1],["pascal",1],["kpa",1e3],["kilopascal",1e3],["mpa",1e6],["megapascal",1e6],["bar",1e5],["psi",6894.757293168]]);function X_(e,t,r){let n=r.PRESSURE?.trim().toLowerCase(),o=n===void 0?1:lS.get(n);if(o===void 0)return;let a=(c,l)=>l===1?c:Number((c*l).toPrecision(12)),s=e.NOMPRES??e.INFLPRES;if(s!==void 0)return a(s,o);let i=e.INFLATION_PRESSURE;if(i!==void 0)return n!==void 0?a(i,o):t.PROPERTY_FILE_FORMAT?.trim().toUpperCase()==="MF_05"?a(i,1e5):void 0}var q_=new Map([["radians",1],["radian",1],["rad",1],["degrees",Math.PI/180],["degree",Math.PI/180],["deg",Math.PI/180]]);function Q_(e,t){let r=(s,i)=>s===void 0?1:i.get(s.trim().toLowerCase()),n=r(t.ANGLE,q_),o={fz:1,kappa:1,alpha:n,gamma:n,p:r(t.PRESSURE,lS)},a={};for(let s of Ic){let i=o[s.q];if(i===void 0)continue;let c={};for(let[l,u]of[["min",s.min],["max",s.max]]){let m=e[u];Number.isFinite(m)&&(c[l]=i===1?m:Number((m*i).toPrecision(12)),delete e[u])}(c.min!==void 0||c.max!==void 0)&&(a[s.q]=c)}return Object.keys(a).length?a:void 0}function _c(e,t="imported",r={}){let n=j_(e),o=r.axisSystem??n.axisSystem,a={},s={},i={},c="",l;for(let g of e.split(/\r?\n/)){let y=g.match(z_);y&&(l=parseFloat(y[1]));let x=g.replace(/[$!].*$/,"").trim();if(!x)continue;if(x.startsWith("[")){c=(x.match(/^\[([^\]]*)/)?.[1]??"").trim().toUpperCase();continue}let R=x.indexOf("=");if(R<0)continue;let v=x.slice(0,R).trim().toUpperCase(),S=x.slice(R+1).trim(),A=S.match(/^'([^']*)'|^"([^"]*)"/);if(A){s[v]=A[1]??A[2]??"",c==="UNITS"&&(i[v]=s[v]);continue}let C=parseFloat(S);Number.isFinite(C)&&(a[v]=C)}let u=U_(a.FITTYP??62),m=cS(e),p=m?Object.fromEntries(Object.entries(m).filter(([g])=>a[g]!==void 0)):void 0,d=a.VERTICAL_STIFFNESS??a.KZ??0,f=X_(a,s,i),h=Q_(a,i),b=[];return a.UNLOADED_RADIUS===void 0&&a.R0===void 0&&b.push("UNLOADED_RADIUS"),d<=0&&b.push("VERTICAL_STIFFNESS"),a.FNOMIN===void 0&&b.push("FNOMIN"),f===void 0&&b.push("NOMPRES"),{kind:"magic",name:t,version:u,coeffs:a,axisSystem:o,side:n.trustSide?s.TYRESIDE==="RIGHT"?"right":s.TYRESIDE==="LEFT"?"left":void 0:void 0,fnomin:a.FNOMIN??5e3,unloadedR0:a.UNLOADED_RADIUS??a.R0??(l!==void 0&&l>0?l:.3),...a.WIDTH!==void 0&&a.WIDTH>0?{sectionWidth:a.WIDTH}:{},verticalStiffness:d>0?d/1e3:0,...a.FREFF!==void 0&&!a.DREFF?{rollingFraction:a.FREFF}:{},...a.LATERAL_STIFFNESS!==void 0&&a.LATERAL_STIFFNESS>0?{relaxation:{sigma:0,carcassStiffness:a.LATERAL_STIFFNESS/1e3,source:"fitted"}}:{},nomPressure:f??0,missing:b,...p&&Object.keys(p).length?{edited:p}:{},...h?{range:h}:{}}}function an(e){if(!e)return null;let t=e.unloadedR0;return t===void 0||!(t>0)||e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS")?null:t*1e3}function qm(e){if(!e)return null;let t=e.sectionWidth;return t!==void 0&&t>0?t:null}function uS(e){if(!e||e.kind!=="magic")return null;let t=e.coeffs.RIM_RADIUS,r=e.coeffs.RIM_WIDTH;return typeof t=="number"&&t>0&&typeof r=="number"&&r>0?{diameter:2*t*1e3,width:r*1e3}:null}var k9=Math.PI/180;var F9=Math.PI/180,C9=180/Math.PI;function Nc(){return{kind:"simple",name:"Simple (default)",Bx:11,Cx:1.6,muX0:1.7,loadSensX:-8e-5,By:9,Cy:1.4,muY0:1.6,loadSensY:-1e-4,nominalLoad:1500,verticalStiffness:120}}var pS=`$ AXIS_SYSTEM = SAE (authored in the evaluation frame: y right)
|
|
3
3
|
[MODEL]
|
|
4
4
|
FITTYP = 62
|
|
5
5
|
[DIMENSION]
|
|
@@ -108,7 +108,7 @@ QHZ1 = 0
|
|
|
108
108
|
QHZ2 = 0
|
|
109
109
|
QHZ3 = 0
|
|
110
110
|
QHZ4 = 0
|
|
111
|
-
`;function
|
|
111
|
+
`;function hg(){return _c(pS,"Example MF6.2")}var eN=Math.PI/180,fS=2,hS=2;function bS(e){let t=Math.sin(hS*Math.atan(1/fS)),r=-e.corneringStiffness/(e.Fz0*t),n=e.camberStiffness/eN/e.Fz0,o=(a,s=5)=>Number(a.toFixed(s)).toString();return`$ AXIS_SYSTEM = SAE (authored in the evaluation frame: y right, +inclination gives +Fy)
|
|
112
112
|
[MODEL]
|
|
113
113
|
FITTYP = 62
|
|
114
114
|
[DIMENSION]
|
|
@@ -170,9 +170,9 @@ PEY3 = 0.1
|
|
|
170
170
|
PEY4 = -4
|
|
171
171
|
PEY5 = 0
|
|
172
172
|
PKY1 = ${o(r)}
|
|
173
|
-
PKY2 = ${o(
|
|
173
|
+
PKY2 = ${o(fS)}
|
|
174
174
|
PKY3 = 0.8
|
|
175
|
-
PKY4 = ${o(
|
|
175
|
+
PKY4 = ${o(hS)}
|
|
176
176
|
PKY5 = 0
|
|
177
177
|
PKY6 = ${o(n)}
|
|
178
178
|
PKY7 = 0
|
|
@@ -220,7 +220,7 @@ QHZ1 = 0
|
|
|
220
220
|
QHZ2 = 0
|
|
221
221
|
QHZ3 = 0
|
|
222
222
|
QHZ4 = 0
|
|
223
|
-
`}function Nn(e){let t=Ic(hS(e),e.name);return{...t,missing:[...t.missing??[],"a particular tyre \u2014 every coefficient is derived from class-level targets stated in generic.ts, on the road; run it with grip_scale = stiffness_scale = 1"]}}var bS={name:"Formula Student 18x6-10",R0:.228,width:.1524,Fz0:950,Kz:110,pressure:83,muY:1.8,muX:1.7,muYLoad:-.2,muXLoad:-.15,corneringStiffness:26e3,slipStiffnessPerLoad:32,camberStiffness:45,Cy:1.5,Cx:1.6,RBY1:12,RBY2:12,RBX1:13,RBX2:10,trail:.08},gS={name:"Formula 1 slick 18in",R0:.36,width:.305,Fz0:5e3,Kz:300,pressure:150,muY:1.8,muX:1.7,muYLoad:-.15,muXLoad:-.12,corneringStiffness:15e4,slipStiffnessPerLoad:28,camberStiffness:260,Cy:1.45,Cx:1.6,RBY1:12,RBY2:12,RBX1:13,RBX2:10,trail:.09},yS={name:"GT slick 18in",R0:.33,width:.3,Fz0:4e3,Kz:280,pressure:180,muY:1.45,muX:1.4,muYLoad:-.12,muXLoad:-.1,corneringStiffness:11e4,slipStiffnessPerLoad:24,camberStiffness:190,Cy:1.4,Cx:1.6,RBY1:11,RBY2:11,RBX1:12,RBX2:10,trail:.09},xS={name:"Street tyre 245/40 R18",R0:.325,width:.245,Fz0:4e3,Kz:220,pressure:240,muY:1.05,muX:1,muYLoad:-.1,muXLoad:-.08,corneringStiffness:75e3,slipStiffnessPerLoad:20,camberStiffness:100,Cy:1.3,Cx:1.55,RBY1:11,RBY2:11,RBX1:12,RBX2:10,trail:.12},RS={name:"Cup slick 18in",R0:.32,width:.25,Fz0:3500,Kz:280,pressure:180,muY:1.42,muX:1.38,muYLoad:-.12,muXLoad:-.1,corneringStiffness:9e4,slipStiffnessPerLoad:24,camberStiffness:160,Cy:1.4,Cx:1.6,RBY1:11,RBY2:11,RBX1:12,RBX2:10,trail:.09},vS={name:"Stock car slick 18in",R0:.357,width:.32,Fz0:4500,Kz:320,pressure:200,muY:1.35,muX:1.3,muYLoad:-.12,muXLoad:-.1,corneringStiffness:125e3,slipStiffnessPerLoad:22,camberStiffness:170,Cy:1.4,Cx:1.6,RBY1:11,RBY2:11,RBX1:12,RBX2:10,trail:.09},kS={name:"Hill-climb slick 13in",R0:.3,width:.3,Fz0:2e3,Kz:200,pressure:150,muY:1.75,muX:1.65,muYLoad:-.18,muXLoad:-.14,corneringStiffness:6e4,slipStiffnessPerLoad:28,camberStiffness:90,Cy:1.45,Cx:1.6,RBY1:12,RBY2:12,RBX1:13,RBX2:10,trail:.085},MS={name:"Race truck tyre 315/70 R22.5",R0:.506,width:.315,Fz0:13e3,Kz:1e3,pressure:800,muY:1.1,muX:1.05,muYLoad:-.1,muXLoad:-.08,corneringStiffness:15e4,slipStiffnessPerLoad:14,camberStiffness:200,Cy:1.3,Cx:1.55,RBY1:10,RBY2:10,RBX1:11,RBX2:10,trail:.1},hg=()=>Nn(bS),bg=()=>Nn(gS),gg=()=>Nn(yS),yg=()=>Nn(xS),xg=()=>Nn(RS),Rg=()=>Nn(vS),vg=()=>Nn(kS),kg=()=>Nn(MS);var SS=e=>Number.isFinite(e)&&e>0;function qm(e,t){let r=SS(t.grip)?t.grip:1,n=SS(t.stiffness)?t.stiffness:1;if(r===1&&n===1)return e;if(e.kind==="simple"){let o=n/r;return{...e,muX0:e.muX0*r,muY0:e.muY0*r,loadSensX:e.loadSensX*r,loadSensY:e.loadSensY*r,Bx:e.Bx*o,By:e.By*o}}return{...e,coeffs:{...e.coeffs,LMUX:(e.coeffs.LMUX??1)*r,LMUY:(e.coeffs.LMUY??1)*r,LKX:(e.coeffs.LKX??1)*n,LKY:(e.coeffs.LKY??1)*n}}}var Nc={ok:!0,violation:0},ta=1e7;function On(e,t){let r;try{r=e.build(t)}catch(s){return{total:ta*2,feasible:!1,terms:[],reason:`build failed: ${String(s)}`}}let n=e.feasible(r);if(!n.ok)return{total:ta+Math.max(0,n.violation),feasible:!1,terms:[],reason:n.reason};let o;try{o=e.terms(r)}catch(s){return{total:ta*2,feasible:!1,terms:[],reason:`objective threw: ${String(s)}`}}let a=0;for(let s of o)a+=s.contribution;return Number.isFinite(a)?{total:a,feasible:!0,terms:o}:{total:ta*2,feasible:!1,terms:o,reason:"objective was not finite"}}var Oc=(e,t)=>!t||(e.feasible!==t.feasible?e.feasible:e.total<t.total);function Mg(e,t){return t.map((r,n)=>Math.min(e[n].hi,Math.max(e[n].lo,r)))}var Gr=e=>e.map(t=>t.start);function Qm(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let r=Math.imul(t^t>>>15,1|t);return r=r+Math.imul(r^r>>>7,61|r)^r,((r^r>>>14)>>>0)/4294967296}}function J_(e){let t=0;for(;t===0;)t=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}function Sg(e,t){let{budget:r}=t,n=Math.max(1,Math.floor(t.progressEvery??1)),o=e.variables,a=d=>Mg(o,d.map((f,h)=>o[h].lo+f*(o[h].hi-o[h].lo))),s=d=>d.map((f,h)=>(f-o[h].lo)/(o[h].hi-o[h].lo)),i=0,c=0,l=null,u=null,m=[];return{vars:o,denorm:a,norm:s,evaluate:d=>{if(i>=r)return l?.total??Number.POSITIVE_INFINITY;i++;let f=d.map(g=>Math.min(1,Math.max(0,g))),h=On(e,a(f));h.feasible||c++;let b=Oc(h,l)?h:l;return b===h&&(l=h,u=f),m.push(b.total),t.onProgress&&(i%n===0||i===r)&&t.onProgress({evaluations:i,budget:r,x:a(u),score:b,infeasible:c}),h.total},left:()=>r-i,result:d=>({method:d,x:u?a(u):Gr(o),score:l??On(e,Gr(o)),evaluations:i,history:m,infeasible:c})}}var Ag=(e,t,r,n=0,o)=>{let a=t?r.norm(Gr(e.variables)):e.variables.map(()=>.5);return!(n>0)||!o?a:a.map(s=>Math.min(1,Math.max(0,s+n*2*(o()-.5))))};function AS(e,t){let r=Sg(e,t),n=Qm(t.seed??1),o=e.variables.length;for(r.evaluate(Ag(e,t.warmStart!==!1,r,t.startJitter,n));r.left()>0;){let a=[];for(let s=0;s<o;s++)a.push(n());r.evaluate(a)}return r.result("random")}function $s(e,t){let r=Sg(e,t),n=e.variables.length,o=Qm(t.seed??1),a=1,s=2,i=.5,c=.5,l=Ag(e,t.warmStart!==!1,r,t.startJitter,o),u=.25;for(;r.left()>0;){let m=[{u:l,f:r.evaluate(l)}];for(let p=0;p<n&&r.left()>0;p++){let d=l.slice();d[p]+=d[p]+u>1?-u:u,m.push({u:d,f:r.evaluate(d)})}for(;r.left()>0;){m.sort((g,y)=>g.f-y.f);let p=m[n],d=new Array(n).fill(0);for(let g=0;g<n;g++)for(let y=0;y<n;y++)d[y]+=m[g].u[y]/n;let f=g=>d.map((y,x)=>y+g*(y-p.u[x])),h=f(a),b=r.evaluate(h);if(b<m[0].f){let g=f(s),y=r.evaluate(g);m[n]=y<b?{u:g,f:y}:{u:h,f:b}}else if(b<m[n-1].f)m[n]={u:h,f:b};else{let g=f(-i),y=r.evaluate(g);if(y<p.f)m[n]={u:g,f:y};else{let x=m[0],R=0;for(let v=1;v<=n;v++)for(let S=0;S<n;S++)R=Math.max(R,Math.abs(m[v].u[S]-x.u[S]));if(R<1e-4)break;for(let v=1;v<=n&&r.left()>0;v++){let S=m[v].u.map((A,F)=>x.u[F]+c*(A-x.u[F]));m[v]={u:S,f:r.evaluate(S)}}}}}m.sort((p,d)=>p.f-d.f),l=m[0].u.map(p=>Math.min(1,Math.max(0,p+.05*(o()-.5)))),u=Math.max(.02,u*.5)}return r.result("nelder-mead")}function wS(e,t){let r=Sg(e,t),n=e.variables.length,o=Qm(t.seed??1),a=4+Math.floor(3*Math.log(n)),s=Math.floor(a/2),i=[];for(let A=1;A<=s;A++)i.push(Math.log(s+.5)-Math.log(A));let c=i.reduce((A,F)=>A+F,0);for(let A=0;A<s;A++)i[A]/=c;let l=1/i.reduce((A,F)=>A+F*F,0),u=(l+2)/(n+l+5),m=1+2*Math.max(0,Math.sqrt((l-1)/(n+1))-1)+u,p=(4+l/n)/(n+4+2*l/n),d=(n+2)/3,f=Math.min(1,d*2/((n+1.3)**2+l)),h=Math.min(1-f,d*2*(l-2+1/l)/((n+2)**2+l)),b=Math.sqrt(n)*(1-1/(4*n)+1/(21*n*n)),g=Ag(e,t.warmStart!==!1,r,t.startJitter,o),y=.25,x=new Array(n).fill(1),R=new Array(n).fill(0),v=new Array(n).fill(0),S=0;for(;r.left()>0;){S++;let A=[];for(let k=0;k<a&&r.left()>0;k++){let C=[];for(let L=0;L<n;L++)C.push(J_(o));let P=g.map((L,E)=>L+y*x[E]*C[E]);A.push({z:C,u:P,f:r.evaluate(P)})}if(A.length<s)break;A.sort((k,C)=>k.f-C.f);let F=g.slice(),w=new Array(n).fill(0);g=new Array(n).fill(0);for(let k=0;k<s;k++)for(let C=0;C<n;C++)g[C]+=i[k]*A[k].u[C],w[C]+=i[k]*A[k].z[C];g=g.map(k=>Math.min(1,Math.max(0,k)));for(let k=0;k<n;k++)R[k]=(1-u)*R[k]+Math.sqrt(u*(2-u)*l)*w[k];let T=Math.sqrt(R.reduce((k,C)=>k+C*C,0)),M=T/Math.sqrt(1-(1-u)**(2*S))/b<1.4+2/(n+1)?1:0;for(let k=0;k<n;k++){let C=(g[k]-F[k])/(y*x[k]);v[k]=(1-p)*v[k]+M*Math.sqrt(p*(2-p)*l)*C}for(let k=0;k<n;k++){let C=0;for(let E=0;E<s;E++)C+=i[E]*A[E].z[k]*A[E].z[k];let P=x[k]*x[k],L=(1-f-h)*P+f*(v[k]*v[k]+(1-M)*p*(2-p)*P)+h*C*P;x[k]=Math.sqrt(Math.max(1e-12,L))}if(y*=Math.exp(u/m*(T/b-1)),y<1e-6||y>10)break}return r.result("sep-cma-es")}var Gs=[{name:"random",run:AS},{name:"nelder-mead",run:$s},{name:"sep-cma-es",run:wS}];var H9=Math.PI/180;var Zm=Math.PI/180;var j9={Fz:100,alpha:.25*Zm,kappa:.005,gamma:.5*Zm,p:6900},FS={Fz:100,alpha:1*Zm,kappa:.02,gamma:.5*Zm,p:6900};var CS=Math.PI/180,J9={t:{s:1,sec:1,ms:.001},v:{"m/s":1,"km/h":1/3.6,"km/hr":1/3.6,kph:1/3.6},alpha:{rad:1,deg:CS},gamma:{rad:1,deg:CS},p:{pa:1,kpa:1e3,bar:1e5,mpa:1e6},rl:{m:1,mm:.001,cm:.01},Fz:{n:1},Fx:{n:1},Fy:{n:1},Mz:{nm:1,"n-m":1}};var oX=Math.PI/180;var mN=Math.PI/180;var mX=3*mN;var bX=Math.PI/180;var CX=Math.PI/180;var xN={RCX1:1,RCY1:1,REX1:0,REY1:0,RBY3:0,RHX1:0,RHY1:0},LS={RBX1:15,RBX2:15,RBY1:18,RBY2:19,...xN};var BX=Math.PI/180;var SN=Math.PI/180,Jm=[{id:"alpha",symbol:"\u03B1",name:"Slip angle",group:"inputs",unit:"rad"},{id:"kappa",symbol:"\u03BA",name:"Slip ratio",group:"inputs",unit:"-"},{id:"gamma",symbol:"\u03B3",name:"Inclination",group:"inputs",unit:"rad"},{id:"Fz",symbol:"Fz",name:"Vertical load",group:"inputs",unit:"N",quantity:"force"},{id:"p",symbol:"p",name:"Inflation pressure",group:"inputs",unit:"Pa",quantity:"pressure"},{id:"V",symbol:"V",name:"Speed",group:"inputs",unit:"m/s",quantity:"speed"},{id:"Fx",symbol:"Fx",name:"Longitudinal force",group:"forces",unit:"N",quantity:"force"},{id:"Fy",symbol:"Fy",name:"Lateral force",group:"forces",unit:"N",quantity:"force"},{id:"Mx",symbol:"Mx",name:"Overturning moment",group:"moments",unit:"N\xB7m"},{id:"My",symbol:"My",name:"Rolling-resistance moment",group:"moments",unit:"N\xB7m"},{id:"Mz",symbol:"Mz",name:"Aligning moment",group:"moments",unit:"N\xB7m"},{id:"t",symbol:"t",name:"Pneumatic trail",group:"aligning",unit:"m",quantity:"length"},{id:"Mzr",symbol:"Mzr",name:"Residual aligning moment",group:"aligning",unit:"N\xB7m"},{id:"s",symbol:"s",name:"Lever arm of Fx",group:"aligning",unit:"m",quantity:"length"},{id:"muX",symbol:"\u03BCx",name:"Longitudinal friction Fx/Fz",group:"friction",unit:"-"},{id:"muY",symbol:"\u03BCy",name:"Lateral friction Fy/Fz",group:"friction",unit:"-"},{id:"use",symbol:"use",name:"Friction ellipse used",group:"friction",unit:"-"},{id:"FyRel",symbol:"Fy/Fy,peak",name:"Lateral force over its peak at this load",group:"friction",unit:"-"},{id:"FxRel",symbol:"Fx/Fx,peak",name:"Driving force over its peak at this load",group:"friction",unit:"-"},{id:"dFyda",symbol:"\u2202Fy/\u2202\u03B1",name:"Cornering stiffness at the point",group:"stiffness",unit:"N/rad"},{id:"dFxdk",symbol:"\u2202Fx/\u2202\u03BA",name:"Slip stiffness at the point",group:"stiffness",unit:"N"},{id:"dFydg",symbol:"\u2202Fy/\u2202\u03B3",name:"Camber stiffness at the point",group:"stiffness",unit:"N/rad"},{id:"kz",symbol:"kz",name:"Vertical stiffness",group:"stiffness",unit:"N/mm",quantity:"springRate",characteristic:!0},{id:"FxPeak",symbol:"Fx,peak",name:"Peak driving force",group:"characteristics",unit:"N",quantity:"force",characteristic:!0},{id:"FyPeak",symbol:"Fy,peak",name:"Peak lateral force",group:"characteristics",unit:"N",quantity:"force",characteristic:!0},{id:"muXPeak",symbol:"\u03BCx,peak",name:"Peak longitudinal friction",group:"characteristics",unit:"-",characteristic:!0},{id:"muYPeak",symbol:"\u03BCy,peak",name:"Peak lateral friction",group:"characteristics",unit:"-",characteristic:!0},{id:"kappaPeak",symbol:"\u03BA at peak",name:"Slip ratio at peak driving force",group:"characteristics",unit:"-",characteristic:!0},{id:"alphaPeak",symbol:"\u03B1 at peak",name:"Slip angle at peak lateral force",group:"characteristics",unit:"rad",characteristic:!0},{id:"Calpha",symbol:"C\u03B1",name:"Cornering stiffness at zero slip",group:"characteristics",unit:"N/rad",characteristic:!0},{id:"bestCamber",symbol:"\u03B3 best",name:"Camber for the most side force",group:"characteristics",unit:"rad",characteristic:!0},{id:"R0",symbol:"R0",name:"Free radius",group:"geometry",unit:"m",quantity:"length",characteristic:!0},{id:"Rl",symbol:"Rl",name:"Loaded radius",group:"geometry",unit:"m",quantity:"length",characteristic:!0},{id:"Re",symbol:"Re",name:"Effective rolling radius",group:"geometry",unit:"m",quantity:"length",characteristic:!0},{id:"width",symbol:"w",name:"Section width",group:"geometry",unit:"m",quantity:"length",characteristic:!0},{id:"sigmaA",symbol:"\u03C3\u03B1",name:"Lateral relaxation length",group:"transient",unit:"m",quantity:"length",characteristic:!0},{id:"Fr",symbol:"Fr",name:"Rolling-resistance force My/Re",group:"power",unit:"N",quantity:"force"},{id:"cr",symbol:"cr",name:"Rolling-resistance coefficient Fr/Fz",group:"power",unit:"-"},{id:"Pslip",symbol:"P slip",name:"Slip power |Fx\xB7Vsx| + |Fy\xB7Vsy|",group:"power",unit:"W"},{id:"Proll",symbol:"P roll",name:"Rolling power My\xB7\u03A9",group:"power",unit:"W"}],eq=new Map(Jm.map(e=>[e.id,e]));var tq=.01*SN;var ft=Math.PI/180;var IS=new Set(Jm.filter(e=>e.group!=="inputs"&&(e.unit==="N"||e.unit==="N\xB7m"||e.unit==="N/rad")).map(e=>e.id)),_S={alpha:{from:-15*ft,to:15*ft,n:61},kappa:{from:-.25,to:.25,n:61},gamma:{from:-6*ft,to:6*ft,n:49},Fz:{from:200,to:3e3,n:40,follow:!0},p:{from:5e4,to:15e4,n:21},V:{from:0,to:40,n:41,follow:!0}},Pg={alpha:{from:0,to:12*ft,n:7},kappa:{from:-.2,to:.2,n:9},gamma:{from:-4*ft,to:4*ft,n:5},Fz:{from:400,to:1600,n:5},p:{from:6e4,to:12e4,n:4},V:{from:5,to:35,n:4}};var Lg={alpha:{from:0,to:12*ft,n:25},kappa:{from:-.2,to:.2,n:25},gamma:{from:-4*ft,to:4*ft,n:17},Fz:{from:300,to:1800,n:16},p:{from:6e4,to:12e4,n:13},V:{from:5,to:35,n:13}};var Oe=(e,t,r,n={},o={})=>({id:e,form:"curves",sweep:[{input:t,..._S[t],...o}],x:t,y:r,...n}),ed=(e,[t,r],n,o,a={})=>({id:e,form:"carpet",sweep:[{input:t,...Pg[t]},{input:r,...Pg[r]}],x:n,y:[o],...a}),Vn=(e,t)=>({id:e,fixed:t}),Ar={input:"Fz",values:"car"},Tg={alpha:0,kappa:0},Jt={kappa:0},DS={alpha:0},wN={input:"Fz",values:[500,1e3,1500]},FN=[{id:"overview",name:"Overview",cards:[Vn("tyre","tyre"),Oe("fy","alpha",["Fy"],{title:"Lateral force",hold:Jt}),Oe("mz","alpha",["Mz"],{title:"Aligning moment",hold:Jt}),Oe("fx","kappa",["Fx"],{title:"Longitudinal force",hold:DS}),ed("combined-carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),Vn("ellipse","ellipse")]},{id:"lateral",name:"Lateral",cards:[Oe("fy-load","alpha",["Fy"],{title:"Lateral force per wheel load",series:Ar,hold:Jt}),Oe("muy-load","alpha",["muY"],{title:"Lateral force per unit load",series:Ar,hold:Jt}),Oe("fy-peak","alpha",["Fy"],{title:"Lateral force over its peak",series:Ar,hold:Jt,scale:{per:"peak"}},{from:0,to:15*ft,n:61}),Oe("muy-peak","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load"}),Oe("calpha","Fz",["Calpha"],{title:"Cornering stiffness over load"}),Oe("alpha-peak","Fz",["alphaPeak"],{title:"Slip angle at the peak over load"})]},{id:"aligning",name:"Aligning",cards:[Oe("mz-load","alpha",["Mz"],{title:"Aligning moment per wheel load",series:Ar,hold:Jt}),Oe("trail","alpha",["t"],{title:"Pneumatic trail",series:Ar,hold:Jt},{from:0,to:12*ft,n:49}),Oe("mzr","alpha",["Mzr"],{title:"Residual aligning moment",series:Ar,hold:Jt},{from:0,to:12*ft,n:49}),ed("gough",["alpha","Fz"],"Fy","Mz",{title:"Gough plot",hold:Jt}),Oe("steering-feel","alpha",["t"],{title:"Steering feel",x:"FyRel",series:Ar,hold:Jt},{from:0,to:12*ft,n:49})]},{id:"longitudinal",name:"Longitudinal",cards:[Oe("fx-load","kappa",["Fx"],{title:"Longitudinal force per wheel load",series:Ar,hold:DS}),Oe("mux-peak","Fz",["muXPeak"],{title:"Peak longitudinal \u03BC over load"}),Oe("kx","Fz",["dFxdk"],{title:"Slip stiffness at zero slip over load",hold:Tg}),Oe("kappa-peak","Fz",["kappaPeak"],{title:"Slip ratio at the peak over load"})]},{id:"combined",name:"Combined",cards:[ed("carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),ed("envelope-load",["kappa","alpha"],"Fy","Fx",{title:"Friction envelope per load",scale:{per:"Fz"},facet:wN}),Oe("fy-kappa","kappa",["Fy"],{title:"Side force while driving or braking",series:{input:"alpha",values:[2*ft,4*ft,8*ft]}}),Oe("fx-kappa","kappa",["Fx"],{title:"Driving force while cornering",series:{input:"alpha",values:[0,4*ft,8*ft]}}),Vn("ellipse","ellipse")]},{id:"camber",name:"Camber",cards:[Oe("fy-gamma","alpha",["Fy"],{title:"Lateral force per inclination",series:{input:"gamma",values:[-4,-2,0,2,4].map(e=>e*ft)},hold:Jt}),Oe("camber-sweep","gamma",["FyPeak","Fy"],{title:"Peak, and camber thrust at zero slip",hold:{alpha:0}}),{id:"camber-map",title:"Camber map",form:"map",sweep:[{input:"gamma",...Lg.gamma},{input:"Fz",...Lg.Fz,follow:!0}],x:"gamma",y:["Fz"],z:"muYPeak"},Oe("camber-stiffness","alpha",["dFydg"],{title:"Camber stiffness at the point",series:Ar,hold:Jt}),Oe("mx","alpha",["Mx"],{title:"Overturning moment",series:Ar,hold:Jt})]},{id:"rolling",name:"Rolling and radius",cards:[Oe("my","V",["My"],{title:"Rolling-resistance moment",series:Ar,hold:Tg}),Oe("radius","Fz",["R0","Rl","Re"],{title:"Radius over load"},{from:0}),Oe("p-roll","V",["Proll"],{title:"Rolling power",series:Ar,hold:Tg})]},{id:"transient",name:"Transient",cards:[Oe("sigma","Fz",["sigmaA"],{title:"Relaxation length over load"})]},{id:"tyres",name:"Side by side",cards:[{id:"trade-off",title:"Grip against cornering stiffness",form:"points",sweep:[],x:"Calpha",y:["muYPeak"]},{id:"pressure-family",title:"Peak \u03BCy over pressure, by family",form:"points",sweep:[],x:"p",y:["muYPeak"],family:!0},Oe("delta-fy","alpha",["Fy"],{title:"Lateral force, minus the reference",hold:Jt,scale:{delta:!0}}),Oe("delta-mu","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load, minus the reference",scale:{delta:!0}}),Oe("delta-calpha","Fz",["Calpha"],{title:"Cornering stiffness over load, minus the reference",scale:{delta:!0}})]},{id:"car",name:"Car",cards:[Vn("operating","operating"),Vn("wheels","wheels")]},{id:"fit",name:"Fit check",cards:[Vn("fitLateral","fitLateral"),Vn("fitLongitudinal","fitLongitudinal"),Vn("fitCoupling","fitCoupling"),Vn("fitEnvelope","fitEnvelope")]}];var _N=5670374e-14,Dg=273.15,VS=.95,BS=60,td=10,NN=.55,ur=25,Eg=-20,Ig=50,Bc={tempC:[20,100,200,550,650,750],factor:[.8,.92,1,1,.85,.65]},$c={discMassKg:.5,discOuterMm:220,specificHeatJPerKgK:460,emissivity:.6,coolingWPerM2K:200,padCurve:{tempC:[...Bc.tempC],factor:[...Bc.factor]}},rd={...$c,discMassKg:.4,discOuterMm:200,padCurve:{tempC:[...Bc.tempC],factor:[...Bc.factor]}};function _g(e,t){let r=t==="front"?$c:rd,n=Math.round(2*e.effRadiusMm+40);return{...r,discOuterMm:n,discMassKg:Math.round(100*r.discMassKg*(n/r.discOuterMm)**2)/100,padCurve:{tempC:[...r.padCurve.tempC],factor:[...r.padCurve.factor]}}}var ON=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},Vc=(e,t,r,n)=>Math.min(r,Math.max(t,ON(e,n)));function VN(e,t){let r=e,n=Array.isArray(r?.tempC)?r.tempC:[],o=Array.isArray(r?.factor)?r.factor:[],a=[];for(let i=0;i<Math.min(n.length,o.length);i++){let c=Number(n[i]),l=Number(o[i]);Number.isFinite(c)&&Number.isFinite(l)&&a.push([Math.min(1500,Math.max(-50,c)),Math.min(2,Math.max(.05,l))])}a.sort((i,c)=>i[0]-c[0]);let s=a.filter((i,c)=>c===0||i[0]>a[c-1][0]);return s.length?{tempC:s.map(i=>i[0]),factor:s.map(i=>i[1])}:{tempC:[...t.tempC],factor:[...t.factor]}}function Ng(e,t){return{discMassKg:Vc(e?.discMassKg,.05,20,t.discMassKg),discOuterMm:Vc(e?.discOuterMm,50,600,t.discOuterMm),specificHeatJPerKgK:Vc(e?.specificHeatJPerKgK,100,3e3,t.specificHeatJPerKgK),emissivity:Vc(e?.emissivity,.02,1,t.emissivity),coolingWPerM2K:Vc(e?.coolingWPerM2K,td,5e3,t.coolingWPerM2K),padCurve:VN(e?.padCurve,t.padCurve)}}function nd(e,t){let r=e.tempC,n=e.factor,o=Math.min(r.length,n.length);if(o===0)return 1;if(t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=1;for(;a<o-1&&r[a]<t;)a++;return n[a-1]+(t-r[a-1])/(r[a]-r[a-1])*(n[a]-n[a-1])}function Og(e,t=1){let r=e.discMassKg*e.specificHeatJPerKgK,n=e.discOuterMm*.001/2,o=2*Math.PI*n*n,a=BS/3.6,s=e.emissivity*_N*o,i=m=>td+(e.coolingWPerM2K-td)*Math.pow(Math.max(0,m)*t/a,NN),c=(m,p,d)=>{let f=m+Dg,h=d+Dg;return i(p)*o*(m-d)+s*(f**4-h**4)},l=(m,p)=>i(p)*o+4*s*Math.max(0,m+Dg)**3,u=(m,p)=>r/l(p,m);return{heatCapacityJPerK:r,areaM2:o,convectionAt:i,coolingW:c,timeConstantS:u,step(m,p,d,f,h){if(!(f>0))return m+p/r;let b=u(d,m+Math.max(0,p)/r),g=Math.max(1,Math.ceil(f/(.25*b))),y=f/g,x=p/g;for(let R=0;R<g;R++)m+=(x-c(m,d,h)*y)/r;return m},padFactor:m=>nd(e.padCurve,m),window:$S(e.padCurve)}}function od(e,t,r,n,o,a,s=ur){let i=n.length,c=new Array(i),l=new Array(i),u=new Array(i),m=VS/Math.max(1,t),p=a,d=p,f=0,h=0,b=0;for(let g=0;g<i;g++){let y=Math.max(0,r[g]??0);c[g]=p,l[g]=y*n[g],u[g]=e.padFactor(p);let x=y*(o[g]??0);f+=x,p<e.window.fromC?h+=x:p>e.window.toC&&(b+=x);let R=g+1<i?n[g+1]:n[g],v=.5*(n[g]+R),S=v>0?(o[g]??0)/v:0;p=e.step(p,m*x,v,S,s),p>d&&(d=p)}return{tempC:c,heatW:l,padFactor:u,startC:a,endC:p,maxC:d,workJ:f,coldWorkJ:h,hotWorkJ:b}}function $S(e){let t=e.tempC,r=Math.min(t.length,e.factor.length);if(r===0)return{fromC:-1/0,toC:1/0};let n=Math.max(...e.factor.slice(0,r)),o=null;for(let c=0;c<r;c++){if(e.factor[c]<n-1e-9)continue;let l=c;for(;l+1<r&&e.factor[l+1]>=n-1e-9;)l++;l>c&&(!o||t[l]-t[c]>o.toC-o.fromC)&&(o={fromC:t[c],toC:t[l]}),c=l}if(o)return o;let a=NaN,s=NaN,i=NaN;for(let c=Math.floor(t[0]);c<=Math.ceil(t[r-1])+1;c++){let l=c<=Math.ceil(t[r-1])&&nd(e,c)>=.98*n;l&&Number.isNaN(i)&&(i=c),!l&&!Number.isNaN(i)&&((Number.isNaN(a)||c-1-i>s-a)&&(a=i,s=c-1),i=NaN)}return{fromC:a,toC:s}}var Vg=e=>typeof e=="number"&&Number.isFinite(e);function ad(e){if(e==null)return null;if(typeof e!="object"||Array.isArray(e))return"disc and caliper are not readable.";let t=e;for(let[r,n]of[["discDiameter","disc diameter"],["caliperHeight","caliper height"],["caliperLength","caliper length"],["caliperWidth","caliper width"]]){let o=t[r];if(!Vg(o)||!(o>0))return`${n} must be a length above zero.`}return Vg(t.discOffset)?!Vg(t.caliperAngle)||Math.abs(t.caliperAngle)>180?"caliper angle must be between \u2212180\xB0 and 180\xB0.":null:"disc offset must be a length."}var Bg=1e5,zS=.001,ra={pedalRatio:4,pedalForceMaxN:0,barFront:.5,masterFrontMm:15.875,masterRearMm:15.875,valve:"none",valveKneeBar:20,valveSlope:.3,front:{location:"outboard",discs:2,pistonsPerSide:2,pistonDiaMm:25.4,padMu:.45,effRadiusMm:90,ratio:1},rear:{location:"outboard",discs:2,pistonsPerSide:1,pistonDiaMm:25.4,padMu:.45,effRadiusMm:80,ratio:1},adjusterPitchMm:1,barLengthMm:0},Gg={fullAtBar:10,maxPowerKw:0,fadeBelowKmh:0,distribution:"equal"};var Kg=WS(id(ra,"Formula Student brakes")),Hg=40,YS={ideal:!1,barFront:ra.barFront,pedalForceMaxN:0,testSpeedKmh:Hg,regen:Gg};function GS(e){let{heat:t,packaging:r,...n}=e;return{...n,...t?{heat:{...t,padCurve:{tempC:[...t.padCurve.tempC],factor:[...t.padCurve.factor]}}}:{},...r?{packaging:{...r}}:{}}}function WS(e){let t=(r,n)=>r.heat?r:{...r,heat:_g(r,n)};return{...e,front:t(e.front,"front"),rear:t(e.rear,"rear")}}function id(e,t){return{name:t,pedalRatio:e.pedalRatio,masterFrontMm:e.masterFrontMm,masterRearMm:e.masterRearMm,valve:e.valve,valveKneeBar:e.valveKneeBar,valveSlope:e.valveSlope,front:GS(e.front),rear:GS(e.rear),adjusterPitchMm:e.adjusterPitchMm,barLengthMm:e.barLengthMm}}function zg(e,t){return jS({...e,barFront:t.barFront,pedalForceMaxN:t.pedalForceMaxN})}function Yg(e,t){let r=$n(t),n=e?sn(e):void 0;return{mode:r.ideal?"tyre":n?"hydraulic":"balance",hydraulic:n?zg(n,r):ra,regen:r.regen}}var BN=["none","proportioning","limiter"],sd=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},At=(e,t,r,n)=>Math.min(r,Math.max(t,sd(e,n))),$N=(e,t)=>{let r=sd(e,t);return r>0?r:t};function KS(e,t,r){let n=e?.location==="inboard"?"inboard":e?.location==="outboard"?"outboard":t.location;return{location:n,discs:Math.max(1,Math.min(4,Math.round(sd(e?.discs,n==="inboard"?1:t.discs)))),pistonsPerSide:Math.max(1,Math.min(6,Math.round(sd(e?.pistonsPerSide,t.pistonsPerSide)))),pistonDiaMm:At(e?.pistonDiaMm,5,80,t.pistonDiaMm),padMu:At(e?.padMu,.05,1.5,t.padMu),effRadiusMm:At(e?.effRadiusMm,20,300,t.effRadiusMm),ratio:n==="inboard"?At(e?.ratio,1,20,t.ratio):1,...e?.heat&&typeof e.heat=="object"?{heat:Ng(e.heat,t.heat??r)}:{},...ad(e?.packaging)===null&&e?.packaging?{packaging:{...e.packaging}}:{}}}function jS(e){let t=ra;return{pedalRatio:At(e?.pedalRatio,.5,15,t.pedalRatio),pedalForceMaxN:At(e?.pedalForceMaxN,0,5e3,t.pedalForceMaxN),barFront:At(e?.barFront,.05,.95,t.barFront),masterFrontMm:At(e?.masterFrontMm,8,40,t.masterFrontMm),masterRearMm:At(e?.masterRearMm,8,40,t.masterRearMm),valve:BN.includes(e?.valve)?e?.valve:t.valve,valveKneeBar:At(e?.valveKneeBar,0,200,t.valveKneeBar),valveSlope:At(e?.valveSlope,0,1,t.valveSlope),front:KS(e?.front,t.front,$c),rear:KS(e?.rear,t.rear,rd),adjusterPitchMm:$N(e?.adjusterPitchMm,t.adjusterPitchMm),barLengthMm:At(e?.barLengthMm,0,500,t.barLengthMm)}}function GN(e){let t=Gg;return{fullAtBar:At(e?.fullAtBar,0,200,t.fullAtBar),maxPowerKw:At(e?.maxPowerKw,0,1e3,t.maxPowerKw),fadeBelowKmh:At(e?.fadeBelowKmh,0,100,t.fadeBelowKmh),distribution:e?.distribution==="wheel"?"wheel":"equal"}}function sn(e){let t=jS(e??void 0),r=typeof e?.name=="string"&&e.name.trim()?e.name:KN;return id(t,r)}function $n(e){return{ideal:e?.ideal===!0,barFront:At(e?.barFront,.05,.95,ra.barFront),pedalForceMaxN:At(e?.pedalForceMaxN,0,5e3,0),testSpeedKmh:At(e?.testSpeedKmh,5,150,Hg),regen:GN(e?.regen)}}var KN="Formula Student brakes";var $g=e=>Math.PI/4*(e*zS)**2;function vo(e,t){let r=e.pistonsPerSide*$g(e.pistonDiaMm)*Bg;return e.discs*2*e.padMu*r*e.effRadiusMm*zS*e.ratio/Math.max(.05,t)}function US(e,t){if(e.valve==="none"||t<=e.valveKneeBar)return t;let r=e.valve==="limiter"?0:e.valveSlope;return e.valveKneeBar+r*(t-e.valveKneeBar)}function Gc(e,t){let r=Math.max(0,t)*e.pedalRatio,n=e.barFront*r/$g(e.masterFrontMm)/Bg,o=(1-e.barFront)*r/$g(e.masterRearMm)/Bg;return{front:n,rearIn:o,rear:US(e,o)}}function HN(e,t){let r=Gc(e,1);return{front:vo(e.front,t)*r.front,rear:vo(e.rear,t)*r.rearIn}}function Kc(e,t){let r=HN(e,t);return r.front/Math.max(1e-12,r.front+r.rear)}function Hc(e,t){let r=[],n=[],o=[],a=e.vVehicle.length,s=Math.max(1,Math.floor(a/60));for(let c=0;c<a;c+=s)i(c);return(a-1)%s!==0&&i(a-1),{v:r,front:n,rear:o};function i(c){let l=e.vVehicle[c],u=XS(t,l),m=t.maxPowerKw>0&&l>0?t.maxPowerKw*1e3/l:1/0,p=Math.max(0,e.fFront[c]),d=Math.max(0,e.fRear[c]),f=p+d>0?Math.min(1,m/(p+d)):1;r.push(l),n.push(p*f*u),o.push(d*f*u)}}function XS(e,t){let r=e.fadeBelowKmh/3.6;return r>0?Math.max(0,Math.min(1,t/r)):1}function Bn(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]||1);return t[o]+s*(t[a]-t[o])}var HS=new WeakMap;function na(e){let t=HS.get(e);return t||(t=e.mode==="hydraulic"&&e.hydraulic?YN(e,e.hydraulic):zN(e),HS.set(e,t)),t}function zN(e){let t=Math.min(.99,Math.max(.01,e.balanceFront));return{mode:e.mode,equalLeftRight:e.mode!=="tyre",uMax:1/0,shares:{front:t,rear:1-t},demand:r=>({front:t*r,rear:(1-t)*r,regenFront:0,regenRear:0,pFront:0,pRear:0,pedalN:0}),controlFor:r=>Math.max(0,r)}}function YN(e,t){let r=vo(t.front,e.tyreRadiusM),n=vo(t.rear,e.tyreRadiusM),o=e.regen,a=(c,l)=>{let u=Gc(t,c),m=0,p=0;if(o&&u.front>0){let d=o.fullAtBar>0?Math.min(1,u.front/o.fullAtBar):1;m=d*Bn(o.v,o.front,l),p=d*Bn(o.v,o.rear,l)}return{front:r*u.front+m,rear:n*u.rear+p,regenFront:m,regenRear:p,pFront:u.front,pRear:u.rear,pedalN:c}},s=t.pedalForceMaxN>0?t.pedalForceMaxN:1/0,i=(c,l)=>{let u=a(c,l);return u.front+u.rear};return{mode:"hydraulic",equalLeftRight:!0,uMax:s,demand:a,controlFor:(c,l)=>{if(!(c>0))return 0;let u=100;for(;i(u,l)<c&&u<1e6;)u*=2;if(u=Math.min(u,s),i(u,l)<=c)return u;let m=0;for(let p=0;p<60;p++){let d=.5*(m+u);i(d,l)<c?m=d:u=d}return u}}}function Wg(e,t,r){let n=t>0?e.controlFor(t,r):0,o=e.demand(n>0?n:1,r),a=o.front+o.rear;return a>0?o.front/a:.5}var cd=Rc,WN=.1,oa=(e,t)=>e.a*Math.sqrt(Math.max(0,1-(t/Math.max(1e-9,e.b))**2));function ld(e,t,r){if(!(r>t))return t;let n=(Math.sqrt(5)-1)/2,o=t,a=r,s=a-n*(a-o),i=o+n*(a-o),c=e(s),l=e(i);for(let p=0;p<48;p++)c<l?(o=s,s=i,c=l,i=o+n*(a-o),l=e(i)):(a=i,i=s,l=c,s=a-n*(a-o),c=e(s));let u=.5*(o+a),m=e(u);for(let p of[t,r]){let d=e(p);d>m&&(u=p,m=d)}return u}function Xg(e,t,r){let n=Math.max(0,r-cd*t.b),o=Math.min(r,cd*e.b);if(!(n<=o))return;let a=(c,l)=>c.a*c.a*Math.max(0,1-(l/Math.max(1e-9,c.b))**2),s=c=>a(e,c)-a(t,r-c),i;if(s(n)<=0)i=n;else if(s(o)>=0)i=o;else{let c=n,l=o;for(let u=0;u<40;u++){let m=.5*(c+l);s(m)>0?c=m:l=m}i=.5*(c+l)}return{lo:n,hi:o,y1:i,c1:e.cap(i),c2:t.cap(r-i)}}function qg(e,t,r,n,o=0){let a=Math.max(0,r),s=Xg(e,t,a),i=s?s.c1:0,c=s?s.c2:0,l=s?Math.min(i,c):0,[u,m]=e.a<=t.a?[e,t]:[t,e],p=u.Fz/Math.max(1e-9,u.Fz+m.Fz),d=Math.max(0,Math.min(1,1-p/WN)),f=d>0&&a<cd*m.b?m.cap(a):0,h=f>l?l+d*(f-l):0,b=Math.max(0,Math.min(u.slide,u.a)),g={xNoLock:l,xLock:h,slide:b,ceiling:Math.max(0,n)},y=Math.max(0,o);if(!(y>0)||!s)return{...g,regenWheel:s?y:0,mixedMax:2*l,regenRoom:M=>2*Math.max(0,l-M)};let{lo:x,hi:R}=s,v=ld(M=>{let k=oa(e,M),C=oa(t,a-M);return Math.min(k+C,2*Math.min(k,C)+y)},x,R),S=e.cap(v),A=t.cap(a-v),F=Math.max(2*l,Math.min(S+A,2*Math.min(S,A)+y)),w=(M,k,C)=>Math.min(y,Math.max(0,M-C))+Math.min(y,Math.max(0,k-C));return{...g,regenWheel:y,mixedMax:F,regenRoom:M=>{let k=w(i,c,M);if(!(a>0))return k;let C=_=>cd*_.b*Math.sqrt(Math.max(0,1-(M/Math.max(1e-9,_.a))**2)),P=Math.max(x,a-C(t)),L=Math.min(R,C(e));if(!(P<=L))return k;let E=ld(_=>Math.min(y,oa(e,_)-M)+Math.min(y,oa(t,a-_)-M),P,L);return Math.max(k,w(e.cap(E),t.cap(a-E),M))}}}var jg=e=>Math.max(e.xNoLock,e.xLock),Ug=e=>Math.max(e.mixedMax,2*e.xLock);function Ks(e,t,r=0){let n=1e-9*Math.max(1,t),o=Math.max(0,r);if(t<=e.xNoLock+n)return Math.min(2*t+(o>0?Math.min(o,e.regenRoom(t)):0),e.ceiling);if(t<=e.xLock+n){let a=o>0?Math.min(e.regenWheel>0?Math.min(o,e.regenWheel):o/2,Math.max(0,e.xLock-t)):0;return Math.min(t+e.slide+a,e.ceiling)}return NaN}function Hs(e,t){let r=t/2,n=1e-9*Math.max(1,r);return r<=e.mixedMax/2+n?Math.min(t,e.ceiling):r<=e.xLock+n?Math.min(r+e.slide,e.ceiling):NaN}function zc(e,t,r,n){return e.shares?jN(e,e.shares,t,r,n):UN(e,t,r,n)}function qS(e,t){let r=e[0],n=t(r.u);for(let o of e.slice(1)){let a=t(o.u);a>n&&(r=o,n=a)}return{cand:r,force:n}}function jN(e,t,r,n,o){let a=Ug(r),s=Ug(n),i=Math.min(t.front>0?a/t.front:1/0,t.rear>0?s/t.rear:1/0,e.uMax),c=Number.isFinite(e.uMax)&&i>=e.uMax,l=b=>{let g=Hs(r,t.front*b),y=Hs(n,t.rear*b);return Number.isFinite(g)&&Number.isFinite(y)?g+y:-1/0},u=a>0?t.front*i/a:1/0,m=s>0?t.rear*i/s:1/0,p=[{u:i,by:c?"pedal":u>=m?"front":"rear"}];if(r.xLock>r.xNoLock){let b=t.front>0?r.mixedMax/t.front:1/0;b<i&&p.push({u:b,by:"front"})}if(n.xLock>n.xNoLock){let b=t.rear>0?n.mixedMax/t.rear:1/0;b<i&&p.push({u:b,by:"rear"})}let{cand:d,force:f}=qS(p,l),h=e.demand(d.u,o);return{force:Math.max(0,Number.isFinite(f)?f:0),control:d.u,demand:h,limitedBy:d.by,lockFront:h.front/2>r.mixedMax/2*(1+1e-9),lockRear:h.rear/2>n.mixedMax/2*(1+1e-9)}}function UN(e,t,r,n){let o=jg(t),a=jg(r),s=v=>(v.front-v.regenFront)/2,i=v=>(v.rear-v.regenRear)/2,c=v=>{let S=e.demand(v,n);return s(S)<=o*(1+1e-12)&&i(S)<=a*(1+1e-12)},l=(v,S)=>{if(v(e.demand(S,n)))return S;let A=0,F=S;for(let w=0;w<60;w++){let T=.5*(A+F);v(e.demand(T,n))?A=T:F=T}return A},u=Number.isFinite(e.uMax)?e.uMax:100;if(!Number.isFinite(e.uMax))for(;c(u)&&u<1e7;)u*=2;let m=c(u)?u:l(v=>s(v)<=o&&i(v)<=a,u),p=Number.isFinite(e.uMax)&&m>=e.uMax,d=v=>{let S=e.demand(v,n),A=Ks(t,s(S),S.regenFront),F=Ks(r,i(S),S.regenRear);return Number.isFinite(A)&&Number.isFinite(F)?A+F:-1/0},f=e.demand(m,n),h=o>0?s(f)/o:1/0,b=a>0?i(f)/a:1/0,g=[{u:m,by:p?"pedal":h>=b?"front":"rear"}];if(t.xLock>t.xNoLock){let v=l(S=>s(S)<=t.xNoLock,m);v<m&&g.push({u:v,by:"front"})}if(r.xLock>r.xNoLock){let v=l(S=>i(S)<=r.xNoLock,m);v<m&&g.push({u:v,by:"rear"})}let{cand:y,force:x}=qS(g,d),R=e.demand(y.u,n);return{force:Math.max(0,Number.isFinite(x)?x:0),control:y.u,demand:R,limitedBy:y.by,lockFront:s(R)>t.xNoLock*(1+1e-9),lockRear:i(R)>r.xNoLock*(1+1e-9)}}var Kr={regen:!0};function Gn(e,t){return{regen:(e.energy??t??Kr).regen===!0}}function Kn(e,t,r){let n=Math.max(0,Math.floor(r));if(n===0)return[];if(n===1)return[e];let o=new Array(n),a=(t-e)/(n-1);for(let s=0;s<n;s++)o[s]=e+a*s;return o[n-1]=t,o}function QS(e,t,r){let n=[],o=Math.floor((r-e)/t+1e-9);for(let a=0;a<=o;a++)n.push(e+t*a);return n}function Pt(e,t,r){let n=e.length;if(r<e[0]||r>e[n-1])return NaN;if(r===e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function ud(e,t,r){let n=e.length;if(!(r>=e[0]&&r<=e[n-1]))return NaN;if(n<3)return n===1?t[0]:t[0]+(r-e[0])/(e[1]-e[0])*(t[1]-t[0]);let o=0,a=n-1;for(;a-o>1;){let f=o+a>>1;e[f]<=r?o=f:a=f}if(o===n-1)return t[n-1];let s=f=>e[f+1]-e[f],i=f=>(t[f+1]-t[f])/s(f),c=f=>{if(f===0||f===n-1){let[y,x]=f===0?[0,1]:[n-2,n-3],R=i(y)*(1+s(y)/(s(y)+s(x)))-i(x)*(s(y)/(s(y)+s(x)));return R*i(y)<=0?0:Math.abs(R)>2*Math.abs(i(y))?2*i(y):R}let h=i(f-1),b=i(f),g=(h*s(f)+b*s(f-1))/(s(f-1)+s(f));return(Math.sign(h)+Math.sign(b))*Math.min(Math.abs(h),Math.abs(b),.5*Math.abs(g))},l=s(o),u=i(o),m=c(o),p=c(o+1),d=r-e[o];return t[o]+d*(m+d*((3*u-2*m-p)/l+d*(m+p-2*u)/(l*l)))}function Yc(e,t,r){return r.map(n=>Pt(e,t,n))}var Wc=e=>e.reduce((t,r)=>r>t?r:t,-1/0),zs=e=>e.reduce((t,r)=>r<t?r:t,1/0);var XN=[-.906179845938664,-.538469310105683,0,.538469310105683,.906179845938664],qN=[.236926885056189,.478628670499366,.568888888888889,.478628670499366,.236926885056189];function Qg(e,t,r){let n=.5*(r-t),o=.5*(t+r),a=0;for(let s=0;s<5;s++)a+=qN[s]*e(n*XN[s]+o);return n*a}var QN=Math.PI*2,ZN=.5/3.6;function jc(e,t){let r=Math.max(0,Math.round(e));if(t==="front")return{front:r,rear:0};if(t==="rear")return{front:0,rear:r};let n=Math.floor(r/2);return{front:n,rear:r-n}}function Zg(e,t,r,n,o){let a=e.rpm,s=e.torque,i=a.length,c=new Array(i),l=new Array(i);for(let g=0;g<i;g++){let y=a[g]/60*QN;c[g]=y*o/n,l[g]=s[g]*n/o}let u=Wc(c),m=Kn(zs(c),u,u/ZN),p=Yc(c,l,m),{front:d,rear:f}=jc(t,r),h=p.map(g=>g*d),b=p.map(g=>g*f);return{vVehicle:m,fFront:h,fRear:b,vMax:u}}var ZS=60/(2*Math.PI),JS=.1,eA=.08,tA=0;function Jg(e){let t=(r,n)=>r===void 0||!Number.isFinite(r)?n:Math.max(0,r);return{up:t(e.upshiftTime,JS),down:t(e.downshiftTime,eA)}}function e0(e){let t=e.driveKept;return t===void 0||!Number.isFinite(t)?tA:Math.max(0,Math.min(1,t))}function t0(e,t,r){let{primary:n,ratios:o,efficiency:a}=e.gearbox,s=t>0&&r>0&&n>0,i=(b,g)=>b/ZS*r/g,c=s?o.filter(b=>b>0).map(b=>{let g=n*b*t;return{ratio:g,vIdle:i(e.idleRpm,g),vLimit:i(e.limitRpm,g)}}):[],l=Math.max(0,Math.min(1,a)),u=Math.max(0,e.inertia),m=b=>b>e.limitRpm?0:Math.max(0,ot(e.rpm,e.torque,b)),p=(b,g)=>{let y=c[g];return y?b*y.ratio/r*ZS:0},d=(b,g)=>g===0&&c.length>0&&b<c[0].vIdle,f=(b,g)=>{let y=c[g];return y?d(b,g)?m(e.idleRpm)*y.ratio*l/r:b<y.vIdle||b>y.vLimit?0:m(p(b,g))*y.ratio*l/r:0},h=(b,g)=>{let y=c[g];return!y||d(b,g)?0:u*y.ratio*y.ratio/(r*r)};return{engine:e,gears:c,efficiency:l,rDyn:r,vMax:c.length?c[c.length-1].vLimit:0,rpm:p,torque:m,force:f,inertiaMass:h,slipping:d}}function Ys(e,t,r,n=0,o=1){let a=-1,s=-1/0;for(let i=0;i<e.gears.length;i++){let c=(o*e.force(t,i)+n)/(r+e.inertiaMass(t,i));c>=s&&(s=c,a=i)}return{gear:a,accel:s}}function r0(e,t){let r=0;for(let n=0;n<e.gears.length;n++)r=Math.max(r,e.force(t,n));return r}var rA=9.81,nA=Math.PI*2;function mr(e){let t=e.motor.rpm,r=e.motor.torque,n=t.length,o=new Array(n),a=new Array(n),s=new Array(n),i=new Array(n),c=new Array(n),l=e.gear_ratio.value,u=e.r_dyn.value;for(let v=0;v<n;v++)o[v]=r[v]*t[v]*(nA/60),a[v]=t[v]/60*nA,s[v]=a[v]*u/l,i[v]=r[v]*l,c[v]=i[v]/u;let m=Wc(s),p=m,d=.5/3.6,f=Kn(zs(s),m,m/d),h=Yc(s,c,f),b=Kn(zs(t),Wc(t),250),g=Yc(t,o,b).map(v=>v*e.power_scale.value),y,x=p,R;if(e.motorModel?.kind==="ice"){R=t0(e.motorModel,l,u);let v=Kn(0,R.vMax,Math.max(2,Math.ceil(R.vMax/d)+1)),S=v.map(w=>r0(R,w)),A=v.map(()=>0),F=e.motorPlacement==="front";y={vVehicle:v,fFront:F?S:A,fRear:F?A:S,vMax:R.vMax},x=R.vMax}else e.motorModel&&(y=Zg(e.motorModel,Math.max(1,Math.round(e.motorCount??e.driven_wheels.value)),e.motorPlacement??"rear",l,u),x=y.vMax);return{params:e,g:rA,FG:e.m.value*rA,vMax:x,vVehicle:f,fRad:h,uMotor:b,pMotor:g,vRad:s,fAxle:y,...R?{engine:R}:{}}}var dr=e=>e.motorModel?.kind==="ice"?jc(1,e.motorPlacement==="front"?"front":"rear"):jc(Math.max(1,Math.round(e.motorCount??e.driven_wheels?.value??2)),e.motorPlacement??"rear");function oA(e){let t=dr(e);return t.front>=2||t.rear>=2}function aA(e){return oA(e)?e.motorMount??"hub":"chassis"}function n0(e){if(!e.motorModel)return{front:!1,rear:!0};let t=dr(e);return{front:t.front>0,rear:t.rear>0}}function md(e){let t=dr(e),r=t.front>0,n=t.rear>0,o=e.front_mass_diss?.value??.5,a=Math.max(0,Math.min(1,o>1?o/100:o)),s=aA(e)==="chassis",i=c=>c===1||c>1&&s;return{front:r&&n?a:r?1:0,inboard:{front:i(t.front),rear:i(t.rear)}}}function Wt(e){return Yg(e.brakeModel,e.brakeSetup)}function Uc(e){return $n(e.brakeSetup).ideal?"tyre":e.brakeModel||e.brakeModelId?"hydraulic":"balance"}function dd(e){let t=Uc(e);return t==="hydraulic"?{brake_balance:"set by the balance bar and the brake hardware"}:t==="tyre"?{brake_balance:"tyre-limited brakes split as the grip does"}:{}}function sA(e,t){if(!(yt(e.motorModel)||!Gn(e).regen))return Hc(pd(mr(e)),t??Wt(e).regen)}function pd(e){return e.fAxle??{vVehicle:e.vVehicle,fFront:e.vVehicle.map(()=>0),fRear:e.fRad.map(t=>t*e.params.driven_wheels.value)}}function o0(e,t=Wt(e)){if(t.mode==="hydraulic")return Kc(t.hydraulic,e.r_dyn.value);if(t.mode==="tyre"){let r=e.front_mass_diss.value>1?e.front_mass_diss.value/100:e.front_mass_diss.value;return Math.min(.95,Math.max(.05,r+J(e,"cg_height")/Math.max(1,J(e,"wheelbase"))))}return J(e,"brake_balance")}function a0(e,t=Wt(e)){return{front:t.hydraulic.front.location==="inboard",rear:t.hydraulic.rear.location==="inboard"}}function s0(e){let t=Wt(e);return{brakeBalanceFront:o0(e,t),brakeInboard:a0(e,t)}}function iA(e,t=Wt(e)){if(t.mode==="tyre"||t.regen.distribution!=="wheel"||yt(e.motorModel))return;let r=dr(e),n={front:r.front>=2,rear:r.rear>=2};return n.front||n.rear?n:void 0}function Xc(e){let t=Wt(e),r=e.r_dyn.value,n=a0(e,t),o=o0(e,t),a=iA(e,t),s=t.mode==="hydraulic"||a?sA(e,t.regen):void 0;return{mode:t.mode,balanceFront:o,...t.mode==="hydraulic"?{hydraulic:t.hydraulic}:{},tyreRadiusM:r,inboard:n,...s?{regen:{...s,fullAtBar:t.regen.fullAtBar}}:{},...s&&a?{regenPerWheel:a}:{}}}var eO=9.81;var i0={front:0,rear:0,total:0};function c0(e,t){if(yt(e.motorModel))return()=>i0;let r=Wt(e),n=Hc(t,r.regen);if(r.mode==="hydraulic"){let a=na({mode:"hydraulic",balanceFront:Kc(r.hydraulic,e.r_dyn.value),hydraulic:r.hydraulic,tyreRadiusM:e.r_dyn.value,regen:{...n,fullAtBar:r.regen.fullAtBar}});return(s,i)=>{if(!(s>0))return i0;let c=a.demand(a.controlFor(s,i),i),l=c.regenFront+c.regenRear,u=Math.min(s,l),m=l>0?u/l:0;return{front:c.regenFront*m,rear:c.regenRear*m,total:u}}}let o=r.mode==="tyre"?tO(e):()=>Math.min(.99,Math.max(.01,J(e,"brake_balance")));return(a,s,i)=>{if(!(a>0))return i0;let c=o(s,i),l=Math.min(c*a,Bn(n.v,n.front,s)),u=Math.min((1-c)*a,Bn(n.v,n.rear,s));return{front:l,rear:u,total:l+u}}}function tO(e){let t=e.m.value*eO,r=e.front_mass_diss.value>1?e.front_mass_diss.value/100:e.front_mass_diss.value,n=J(e,"cg_height")/Math.max(1,J(e,"wheelbase")),o=1-Math.max(0,Math.min(1,J(e,"cop_long"))),a=.5*e.rho.value*e.c_l.value*e.A.value;return(s,i)=>{let c=Math.max(0,a*s*s),l=t*(r+Math.abs(i)*n)+c*o;return Math.min(.99,Math.max(.01,l/(t+c)))}}function cA(e){let t=e==="front"?"Front axle":"Rear axle";return{[`${e}.location`]:{section:t,label:"Disc location",control:"Mounting"},[`${e}.discs`]:{section:t,label:"Discs",control:"Mounting"},[`${e}.ratio`]:{section:t,label:"Reduction to the wheel",unit:": 1"},[`${e}.pistonsPerSide`]:{section:t,label:"Pistons a side"},[`${e}.pistonDiaMm`]:{section:t,label:"Piston bore",unit:"mm"},[`${e}.padMu`]:{section:t,label:"Pad friction \u03BC"},[`${e}.effRadiusMm`]:{section:t,label:"Effective radius",unit:"mm"},[`${e}.heat.discMassKg`]:{section:t,label:"Disc mass",unit:"kg"},[`${e}.heat.discOuterMm`]:{section:t,label:"Disc diameter",unit:"mm"},[`${e}.heat.specificHeatJPerKgK`]:{section:t,label:"Specific heat",unit:"J/(kg\xB7K)"},[`${e}.heat.emissivity`]:{section:t,label:"Emissivity"},[`${e}.heat.coolingWPerM2K`]:{section:t,label:"Cooling at 60 km/h",unit:"W/(m\xB2\xB7K)"},[`${e}.heat.padCurve.tempC`]:{section:t,label:"Pad curve temperature",unit:"\xB0C"},[`${e}.heat.padCurve.factor`]:{section:t,label:"Pad curve friction"}}}var l0={pedalRatio:{section:"Pedal box & bar",label:"Pedal ratio",unit:": 1"},barLengthMm:{section:"Pedal box & bar",label:"Bar length, clevis to clevis",unit:"mm"},adjusterPitchMm:{section:"Pedal box & bar",label:"Adjuster pitch",unit:"mm/turn"},masterFrontMm:{section:"Master cylinders",label:"Front bore",unit:"mm"},masterRearMm:{section:"Master cylinders",label:"Rear bore",unit:"mm"},valve:{section:"Rear valve",label:"Valve"},valveKneeBar:{section:"Rear valve",label:"Knee",unit:"bar"},valveSlope:{section:"Rear valve",label:"Gain above the knee"},...cA("front"),...cA("rear")},u0={ideal:{label:"Ideal brakes"},barFront:{label:"Balance bar"},pedalForceMaxN:{label:"Pedal force",unit:"N"},testSpeedKmh:{section:"Brake test",label:"Speed",unit:"km/h"},"regen.maxPowerKw":{section:"Regen",label:"Power ceiling",unit:"kW"},"regen.fadeBelowKmh":{section:"Regen",label:"Fades out below",unit:"km/h"},"regen.fullAtBar":{section:"Regen",label:"Full at",unit:"bar"},"regen.distribution":{section:"Regen",label:"Wheel by wheel"}};function m0(e){let t=l0[e];return`${t.label}, ${t.section}`.toLowerCase()}function d0(e){let t=u0[e];return t.section?`${t.section} ${t.label.charAt(0).toLowerCase()}${t.label.slice(1)}`:t.label}var lA=new WeakMap;function cn(e){if(e.brakes)return e.brakes;let t=lA.get(e);if(!t){let r=Math.max(.05,(e.unsprungCgHeight||230)/1e3);t=e.brakeBalanceFront!=null?{mode:"balance",balanceFront:e.brakeBalanceFront,tyreRadiusM:r}:{mode:"tyre",balanceFront:e.frontMassFrac,tyreRadiusM:r},lA.set(e,t)}return t}var Hn=e=>na(cn(e));var aO=Math.PI/180,Ws=Object.freeze({tbr:1,preloadN:0}),fd=Object.freeze({tbr:1/0,preloadN:0}),f0=e=>e.faces*e.muClutch*e.rFrictionMm/e.rRampMm;function h0(e,t){if(!(e>0)||Number.isNaN(t))return 0;let r=Math.tan(Math.min(90,t)*aO);return r>0?Math.min(1,e/r):1}function mA(e){if(e>=1)return 1/0;let t=e>0?e:0;return(1+t)/(1-t)}function hd(e){return e===1/0?1:e>1?(e-1)/(e+1):0}function aa(e,t){return e.tbr===1/0?1/0:(e.preloadN>0?e.preloadN:0)+hd(e.tbr)*Math.abs(t)}function Qc(e,t,r){let n=o=>o!==void 0&&o>0&&r>0?o/r:0;switch(e.kind){case"open":return Ws;case"spool":return fd;case"independent":return t==="hubs"?Ws:fd;case"clutch":{let o=n(e.preloadNm);return t==="hubs"?{tbr:1,preloadN:o}:{tbr:mA(h0(f0(e),t==="drive"?e.rampDriveDeg:e.rampCoastDeg)),preloadN:o}}case"torsen":{let o=n(e.preloadNm);if(t==="hubs")return{tbr:1,preloadN:o};let a=t==="drive"?e.tbrDrive:e.tbrCoast;return{tbr:a>1?a:1,preloadN:o}}}}function qc(e,t,r){let n=Math.max(0,Math.min(e,t)),o=Math.max(0,Math.max(e,t)),a=r.tbr>1?r.tbr:1,s=r.preloadN>0?r.preloadN:0;return a===1/0||s===1/0?n+o:n+Math.min(o,a*n+s*(1+a)/2)}var uA=4;function p0(e,t){let r=0;for(let a of e)r=Math.max(r,qc(a.m1,a.m2,t));let n=t.tbr>1?t.tbr:1,o=(t.preloadN>0?t.preloadN:0)*(1+n)/2;if(n===1/0||o===1/0)return r;for(let a=0;a+1<e.length;a++){let s=e[a],i=e[a+1].m1-s.m1,c=e[a+1].m2-s.m2,l=p=>{p>0&&p<1&&(r=Math.max(r,qc(s.m1+p*i,s.m2+p*c,t)))};i!==c&&l((s.m2-s.m1)/(i-c));let u=i+c-(1+n)*i,m=i+c-(1+n)*c;u!==0&&l(((1+n)*s.m1+o-s.m1-s.m2)/u),m!==0&&l(((1+n)*s.m2+o-s.m1-s.m2)/m)}return r}function Zc(e,t,r,n,o){let a=Math.max(0,o),s=n.tbr>1?n.tbr:1,i=n.preloadN>0?n.preloadN:0;if(s===1/0||i===1/0)return a;let c=Math.max(0,r),l=Xg(e,t,c),u=l?2*Math.min(l.c1,l.c2):0;if(!l||s===1&&i===0||!(a>u))return Math.min(u,a);let m=ld(b=>oa(e,b)+oa(t,c-b),l.lo,l.hi),p=[{m1:l.c1,m2:l.c2}];for(let b=1;b<=uA&&m!==l.y1;b++){let g=l.y1+(m-l.y1)*b/uA;p.push({m1:e.cap(g),m2:t.cap(c-g)})}let d=p0(p,Ws),f=p0(p,fd);if(!(f>d))return u;let h=(p0(p,{tbr:s,preloadN:i})-d)/(f-d);return Math.min(a,u+(a-u)*Math.min(1,Math.max(0,h)))}function dA(e,t,r,n,o,a){return b0(e,o,Zc(t,r,n,o,a))}function b0(e,t,r){let n=Math.max(e.xNoLock,r/2),o=t.tbr===1/0||!(e.xLock>n)?0:e.xLock;return e.regenWheel>0?{...e,xNoLock:n,xLock:o,mixedMax:Math.max(e.mixedMax,2*n)}:{...e,xNoLock:n,xLock:o,mixedMax:2*n,regenRoom:a=>2*Math.max(0,n-a)}}function g0(e,t,r,n=30){let o=t,a=e(o),s=a-o;if(!(Math.abs(s)>r))return{x:o,fx:a,evals:1};let i=a,c=e(i),l=c-i,u=2;for(;Math.abs(l)>r&&u<n;){let m=s<0!=l<0,p=l-s,d=p!==0?i-l*(i-o)/p:NaN;m?d>Math.min(o,i)&&d<Math.max(o,i)||(d=.5*(o+i)):Number.isFinite(d)?Math.abs(d-i)>10*Math.abs(l)&&(d=i+Math.sign(d-i)*10*Math.abs(l)):d=c;let f=e(d),h=f-d;if(u++,m&&h<0==l<0?s*=.5:(o=i,s=l),i=d,c=f,l=h,s<0!=l<0&&Math.abs(i-o)<=r)break}return{x:i,fx:c,evals:u}}function pA(e,t,r,n,o,a=60){let s=t,i=e(s),c=i-s,l=1;if(!(Math.abs(c)>n))return{x:s,fx:i,evals:l};let u=Math.sign(r-t),m=Math.abs(r-t),p=0;for(let d=o;l<a;d*=2){if(p=Math.min(p+d,m),p>m-n)return null;let f=t+u*p,h=e(f),b=h-f;if(l++,!(Math.abs(b)>n))return{x:f,fx:h,evals:l};if(c<0!=b<0)return hA(e,s,c,f,h,b,n,l,a);s=f,c=b}return null}function fA(e,t,r,n=60){let o=t,a=e(o),s=a-o;if(!(Math.abs(s)>r))return{x:o,fx:a,evals:1};let i=Math.sign(s),c=a;for(let l=2;;l++){let u=e(c),m=u-c;if(!(Math.abs(m)>r))return{x:c,fx:u,evals:l};if(s<0!=m<0)return hA(e,o,s,c,u,m,r,l,n);if(l>=n)return{x:c,fx:u,evals:l};let p=Math.abs(c-o),d=s!==m?m*(c-o)/(s-m):NaN,f=d*i>0?Math.min(Math.abs(d),10*Math.abs(m),2*p):2*p;o=c,s=m,c+=i*f}}function hA(e,t,r,n,o,a,s,i,c){let l=t,u=r,m=n,p=a,d=n,f=o,h=0;for(;i<c&&Math.abs(m-l)>s;){d=(l*p-m*u)/(p-u),f=e(d);let b=f-d;if(i++,!(Math.abs(b)>s))break;b<0==u<0?(l=d,u=b,h===-1&&(p*=.5),h=-1):(m=d,p=b,h===1&&(u*=.5),h=1)}return{x:d,fx:f,evals:i}}function bd(e,t){return Math.abs(e.fx-e.x)>t?e.x:e.fx}var sO=(e,t)=>{let r=e.brakes?.hydraulic?.[t];return!!r&&r.location==="inboard"&&r.discs===1};function pr(e,t,r){let n=e.driveline?.[t];if(n)return r>=0?n.drive:sO(e,t)?n.coast:n.hubs}var bA=e=>e.tbr>1||e.preloadN>0;var iO=9.81,gA=["FL","FR","RL","RR"],y0=e=>e==="FL"||e==="FR",gd=e=>y0(e)?"front":"rear",yA={front:["FL","FR"],rear:["RL","RR"]},tl=()=>({peak:new Map,freeBrake:new Map}),el=25;function Jc(e,t){let r=Math.max(0,e)/el,n=Math.floor(r),o=r-n,a=t(n);return o>0?a+o*(t(n+1)-a):a}var ko=1e-4,cO=.05;function zn(e,t,r,n=tl(),o=!1){let a=r,s=e.massTotal,i=n.peak,c=(k,C)=>{let P=`${k}:${C}`,L=i.get(P);return L||(L=wm(Te(t,k),Math.max(1,C*el)),i.set(P,L)),L},l=(k,C)=>({aPeak:Jc(C,P=>c(k,P).aPeak),fyPeak:Jc(C,P=>c(k,P).fyPeak)}),u=n.freeBrake,m=(k,C)=>{let P=`${k}:${C}`,L=u.get(P);if(L===void 0){let E=Math.max(1,C*el);L=lr(Te(t,k),E,0,!0,c(k,C)),u.set(P,L)}return L},p=(k,C)=>C>0?Jc(C,P=>m(k,P)):0,d=Hn(e),f=cn(e),h=k=>f.regen&&f.regenPerWheel?.[k]?Bn(f.regen.v,f.regen[k],a)/2:0,b=h("front"),g=h("rear"),y=(k,C,P)=>{let L=Math.max(0,C[k]),E=l(gd(k),L);return lr(Te(t,gd(k)),L,P[k]*E.fyPeak,!0,E)},x=(k,C,P,L,E=!0,_=1)=>{let D=te=>{let j=Math.max(0,C[te]),X=Te(t,k),le=l(k,j),pe={Fz:j,a:Math.abs(p(k,j)),b:le.fyPeak,slide:j>0?Math.abs(X.forces({Fz:j,kappa:-1,alpha:0}).Fx):0,cap:ue=>Math.abs(lr(X,j,ue,!0,le))};return _===1?pe:{Fz:j,a:_*pe.a,b:_*pe.b,slide:_*pe.slide,cap:ue=>_*pe.cap(ue/_)}},I=te=>_*Math.abs(P[te])*l(gd(te),Math.max(0,C[te])).fyPeak,[N,O]=yA[k],V=D(N),H=D(O),U=I(N)+I(O),G=qg(V,H,U,L,k==="front"?b:g),B=E?G:{...G,xLock:0},q=pr(e,k,-1),re=q&&bA(q)?q:void 0;if(!re)return{axle:k,eq:B,cap:B};let W=Number.isFinite(L)?L:V.cap(I(N))+H.cap(I(O)),z=dA(B,V,H,U,re,W);return{axle:k,eq:B,cap:z,law:re,strong:()=>V.cap(I(N))>=H.cap(I(O))?N:O}},R=(k,C,P,L,E=1)=>x(k,C,P,L,!0,E).cap,v=(k,C,P)=>{let L=k.demand,E=d.shares?Hs(C,L.front):Ks(C,(L.front-L.regenFront)/2,L.regenFront),_=d.shares?Hs(P,L.rear):Ks(P,(L.rear-L.regenRear)/2,L.regenRear);return{front:Number.isFinite(E)?E:0,rear:Number.isFinite(_)?_:0}},S=k=>({muX:C=>C>0?Math.abs(p(k,C))/C:0,muY:C=>C>0?l(k,C).fyPeak/C:0}),A={front:S("front"),rear:S("rear")},F={lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},w={front:e.trackFront/2e3,rear:e.trackRear/2e3},T=(k,C,P,L,E)=>{let _=L.cap,D=E.cap,I=zc(d,_,D,a),N={arms:F,halfTrack:w,ayDir:Math.sign(k)};for(let O=0;O<2;O++){let V=v(I,_,D),H={};for(let G of gA){let B=Math.max(0,C[G]);H[G]={Fz:B,Fy:Math.abs(P[G])*l(gd(G),B).fyPeak,Fx:-(y0(G)?V.front:V.rear)/2}}let U=G=>{if(!G.law||!G.strong)return G.cap;let B={axle:G.axle,strong:G.strong(),full:2*G.cap.xNoLock,open:2*G.eq.xNoLock,sense:-1};return b0(G.eq,G.law,Um(B,H,A,N))};_=U(L),D=U(E),I=zc(d,_,D,a)}return{limit:I,front:_,rear:D}};return{peakAt:l,axle:R,ceiling:(k,C,P)=>{let[L,E]=yA[k];return Math.abs(y(L,C,P)+y(E,C,P))},limitAt:(k,C,P,L=0)=>{let E={FL:0,FR:0,RL:0,RR:0},_=Xe(e,k,0,a,0,C),D,I=te=>(D?.ax!==te&&(D={ax:te,loads:Xe(e,k,(te+L)/iO,a,0,C)}),D.loads),N=Fm(te=>Is(P,I(te),_,l).short,-L,-1),O=P,V={front:0,rear:0},H,U,G=(te,j=!0)=>{let X=N.at(te);E=I(X),O=Is(P,E,_,l).util;let le=0,pe=0,ue=0;for(let ie of gA){let ke=y(ie,E,O);le+=ke,y0(ie)?pe+=ke:ue+=ke}if(V={front:Math.abs(pe),rear:Math.abs(ue)},d.mode!=="tyre"){let ie=x("front",E,O,Math.abs(pe),j),ke=x("rear",E,O,Math.abs(ue),j);if(o&&(ie.law||ke.law)){let Ie=T(k,E,O,ie,ke);H=Ie.limit,U={front:Ie.front,rear:Ie.rear}}else H=zc(d,ie.cap,ke.cap,a),U={front:ie.cap,rear:ke.cap};le=-H.force}return le/s},B=g0(G,0,ko),q=bd(B,ko),re=q;if(H?.lockFront||H?.lockRear){let te=g0(X=>G(X,!1),0,ko);re=bd(te,ko);let j=pA(G,te.x,B.x,ko,cO);j||G(B.x),q=bd(j??B,ko)}let W=N.edge(),z=W!==void 0&&q<W;z&&(q=Math.min(0,W),G(q),re=Math.max(re,q));let Y={loads:E,ceiling:V,limit:H,axles:U};return{ax:q,axUnlocked:re,...z?{edge:W}:{},...Y,split:()=>Y.limit&&Y.axles?v(Y.limit,Y.axles.front,Y.axles.rear):{...Y.ceiling}}}}}var xd=9.81;function lO(e,t,r){let n=Xe(e,0,t,r),o=Math.max(0,n.FL)+Math.max(0,n.FR),a=Math.max(0,n.RL)+Math.max(0,n.RR);return o+a>0?o/(o+a):e.frontMassFrac}var vA=(e,t)=>t.mode==="hydraulic"&&!!cn(e).regen;function js(e,t,r=0,n,o=0,a=1){if(!e.brakes&&e.brakeBalanceFront==null)return e.frontMassFrac;let s=Hn(e);if(s.shares&&s.mode!=="tyre")return s.shares.front;let i=n&&vA(e,s)?SA(e,n):void 0,c=i?kA(a):sa,l=i?MA(i,c).shares:xA.get(e);l||xA.set(e,l=new Map);let u=Math.round(Math.abs(t)/.005),m=Math.round(Math.max(0,r)/.25),p=i?Math.round(o/.01):0,d=AA(u,m,p),f=l.get(d);if(f===void 0){let h=-u*.005,b=m*.25,g=e.massTotal*Math.abs(h)*xd;if(i){let y=FA(s,wA(e,i,u,m,p,c),g,b);f=y.front+y.rear>0?y.front/(y.front+y.rear):.5}else f=s.mode==="tyre"?lO(e,h,b):Wg(s,g,b);l.size>5e4&&l.clear(),l.set(d,f)}return f}var xA=new WeakMap;function Rd(e,t,r,n,o=0,a=1){let s=Hn(e);if(!vA(e,s))return;let i=Math.round(Math.max(0,r)/(e.massTotal*xd)/.005),c=Math.round(Math.max(0,n)/.25);return FA(s,wA(e,SA(e,t),i,c,Math.round(o/.01),kA(a)),Math.max(0,r),n)}var sa=100,kA=e=>e>0&&Number.isFinite(e)?Math.max(1,Math.round(e*sa)):sa;function MA(e,t){if(t===sa)return e;let r=e.roads.get(t);return r||e.roads.set(t,r={shares:new Map,rooms:new Map}),r}var RA=new WeakMap;function SA(e,t){let r=RA.get(e);r||RA.set(e,r=new WeakMap);let n=r.get(t);return n||r.set(t,n={ev:t,tyres:tl(),shares:new Map,rooms:new Map,speeds:new Map,roads:new Map}),n}var AA=(e,t,r)=>(r*1001+e)*100003+t;function wA(e,t,r,n,o,a=sa){let s=AA(r,n,o),i=MA(t,a),c=a===sa?1:a/sa,l=i.rooms.get(s);if(!l){let u=n*.25,m=o*.01,p=t.speeds.get(n);p||(p={cap:zn(e,t.ev,u,t.tyres),dragG:-Math.max(0,tc(e,u).drag)/(e.massTotal*xd)},t.speeds.set(n,p));let{cap:d}=p,f=Xe(e,m,-r*.005+p.dragG,u),h=Math.abs(m)*e.massTotal*xd,b=x=>{let[R,v]=x==="front"?["FL","FR"]:["RL","RR"],S=h*(x==="front"?e.frontMassFrac:1-e.frontMassFrac),A=c*(d.peakAt(x,Math.max(0,f[R])).fyPeak+d.peakAt(x,Math.max(0,f[v])).fyPeak),F=S>0&&A>0?Math.min(1,S/A):0;return d.axle(x,f,{FL:F,FR:F,RL:F,RR:F},1/0,c)},g,y;l=(x,R)=>(x==="front"?g??=b("front"):y??=b("rear")).regenRoom(R),i.rooms.size>5e4&&i.rooms.clear(),i.rooms.set(s,l)}return l}function yd(e,t,r,n){let o=e.demand(r,n),a=o.front-o.regenFront,s=o.rear-o.regenRear,i=o.regenFront>0?Math.min(o.regenFront,t("front",a/2)):0,c=o.regenRear>0?Math.min(o.regenRear,t("rear",s/2)):0;return{front:i===o.regenFront?o.front:a+i,rear:c===o.regenRear?o.rear:s+c,regenFront:i,regenRear:c,demand:o}}function FA(e,t,r,n){if(!(r>0))return yd(e,t,1,n);let o=c=>c.front+c.rear,a=e.controlFor(r,n),s=yd(e,t,a,n);if(o(s)>=r||!(a<e.uMax))return s;let i=a;for(;o(s)<r&&i<e.uMax&&i<1e7;)a=i,i=Math.min(e.uMax,2*i),s=yd(e,t,i,n);if(o(s)<r)return s;for(let c=0;c<60&&i-a>1e-10*i;c++){let l=.5*(a+i),u=yd(e,t,l,n);o(u)<r?a=l:(i=l,s=u)}return s}var Us={rel:.003,abs:2,kappa:1e-5,iters:12},Xs={rel:1e-6,abs:.001,kappa:1e-12,iters:40},kd={...Xs,settle:1e-9};function Mo(e,t,r,n=Us,o,a){let s=t>=0?1:-1,i=Math.abs(t),c=Math.max(n.abs,n.rel*i),l={kappa:NaN,forces:null},u=o??(F=>{let w=e(F);return l.kappa=F,l.forces=w,w.Fx}),m=u(0);if(Math.abs(m)-i>=0)return vd(e,l,0);let p=a?s>0?a.drive:a.brake:void 0;if(p&&p.mag<i)return p.stop;let d=0,f=m,h=Math.abs(m)-i,b=Math.min(.3,Math.max(.004,Math.abs(r)||.02)),g=u(s*b),y=Math.abs(g)-i,x=NaN,R=0;for(;y<0&&b<.3;){let F=Math.min(.3,b*1.9),w=u(s*F),T=Math.abs(w);if(T<Math.abs(g)){x=F,R=w;break}d=b,f=g,h=y,b=F,g=w,y=T-i}if(y<0){let F=dO(u,s,d,f,b,g,x,R);if(F.mag<i){let w=vd(e,l,s*F.kappa);return a&&(a[s>0?"drive":"brake"]={mag:F.mag,stop:w}),w}b=F.kappa,y=F.mag-i}let v=s*b,S=n.settle;if(S!==void 0){let F=d,w=h,T=b,M=y;Math.abs(w)<Math.abs(M)&&([F,w,T,M]=[T,M,F,w]);let k=0;for(let C=0;C<n.iters&&b-d>n.kappa;C++){let P=M-w,L=k<2&&Math.abs(P)>1e-12?T-M*(T-F)/P:NaN;if(!(L>d&&L<b)){let D=y-h;L=k<2&&Math.abs(D)>1e-12?(d*y-b*h)/D:.5*(d+b),L>d&&L<b||(L=.5*(d+b)),k=0}let E=Math.abs(u(s*L))-i;v=s*L;let _=E!==M?Math.abs(E*(L-T)/(E-M)):1/0;if(Math.abs(E)<c&&(Math.abs(L-T)<=S||_<=S))break;k=Math.abs(E)>.5*Math.abs(M)?k+1:0,E<0?(d=L,h=E):(b=L,y=E),F=T,w=M,T=L,M=E}return vd(e,l,v)}let A=NaN;for(let F=0;F<n.iters&&b-d>n.kappa;F++){let w=y-h,T=Math.abs(w)>1e-12?(d*y-b*h)/w:.5*(d+b);T>d&&T<b||(T=.5*(d+b));let M=Math.abs(u(s*T))-i;if(v=s*T,Math.abs(M)<c&&(S===void 0||Math.abs(T-A)<=S))break;A=T,M<0?(d=T,h=M,y*=.5):(b=T,y=M,h*=.5)}return vd(e,l,v)}function vd(e,t,r){return t.forces!==null&&Object.is(t.kappa,r)?{kappa:r,forces:t.forces}:{kappa:r,forces:e(r===0?0:r)}}var CA=1e-6,uO=40,mO=(3-Math.sqrt(5))/2;function dO(e,t,r,n,o,a,s,i){let c,l,u,m=-Math.abs(a),p,d,f=-Math.abs(n);if(Number.isNaN(s)){c=.3;let g=.3*(1-CA),y=-Math.abs(e(t*g));if(y>=m)return{kappa:o,mag:-m};[l,p,u,d]=[o,m,r,f],o=g,m=y}else{c=s;let g=-Math.abs(i);[l,p,u,d]=g<=f?[c,g,r,f]:[r,f,c,g]}f<m&&([l,p]=[o,m],o=r,m=f);let h=c-r,b=0;for(let g=0;g<uO;g++){let y=CA*Math.abs(o)+1e-10,x=.5*(r+c);if(Math.abs(o-x)<=2*y-.5*(c-r))break;let R=!0;if(Math.abs(h)>y){let A=(o-l)*(m-d),F=(o-u)*(m-p),w=(o-u)*F-(o-l)*A;F=2*(F-A),F>0&&(w=-w),F=Math.abs(F);let T=h;if(h=b,Math.abs(w)<Math.abs(.5*F*T)&&w>F*(r-o)&&w<F*(c-o)){b=w/F;let M=o+b;(M-r<2*y||c-M<2*y)&&(b=x>=o?y:-y),R=!1}}R&&(h=o>=x?r-o:c-o,b=mO*h);let v=Math.abs(b)>=y?o+b:o+(b>=0?y:-y),S=-Math.abs(e(t*v));S<=m?(v>=o?r=o:c=o,u=l,d=p,l=o,p=m,o=v,m=S):(v<o?r=v:c=v,S<=p||l===o?(u=l,d=p,l=v,p=S):(S<=d||u===o||u===l)&&(u=v,d=S))}return{kappa:o,mag:-m}}var Md=e=>Math.max(2,.003*Math.abs(e)),pO=(e,t)=>Math.max(t.abs,t.rel*Math.abs(e)),x0=.5,fO=.03;function hO(e,t,r,n,o,a=!1){let s=bO(e,t,r,n,o,a);return{kappaM:s.kappaM,kl:s.kl,kr:s.kr,fl:e.at(s.kl),fr:t.at(s.kr)}}function bO(e,t,r,n,o,a){let s=.5*(e.vx+t.vx),i=e.fxAt??(w=>e.at(w).Fx),c=t.fxAt??(w=>t.at(w).Fx),l=w=>{let T=(1+w)*s/e.vx-1,M=(1+w)*s/t.vx-1;return{kappaM:w,kl:T,kr:M,g:i(T)+c(M)-r}},u=pO(r,o),m=Math.max(-x0,Math.min(x0,n)),p=l(m);if(Math.abs(m)>fO){let w=l(.8*m);(p.g-w.g)/(m-w.kappaM)>0||(p=l(0))}if(Math.abs(p.g)<u)return p;let d=p.g<0?1:-1,f=p,h=p,b=.004,g=p,y=p;for(let w=0;w<12;w++){let T=f.kappaM+d*b;if(Math.abs(T)>x0)break;let M=l(T);if(Math.abs(M.g)<u)return M;if(Math.abs(M.g)<Math.abs(g.g)&&(g=M),Math.sign(M.g)!==Math.sign(f.g)){h=M;break}if(d*(M.g-f.g)<=0){if(!a)return g;let k=(Math.sqrt(5)-1)/2,C=y.kappaM,P=M.kappaM,L=l(P-k*(P-C)),E=l(C+k*(P-C));for(let D=0;D<40&&Math.abs(P-C)>1e-7;D++)d*(L.g-E.g)<0?(C=L.kappaM,L=E,E=l(C+k*(P-C))):(P=E.kappaM,E=L,L=l(P-k*(P-C)));let _=d*(L.g-E.g)>0?L:E;if(Math.abs(_.g)<u||Math.sign(_.g)===Math.sign(p.g))return Math.abs(_.g)<Math.abs(g.g)?_:g;f=d*(_.kappaM-f.kappaM)>0?f:y,h=_;break}y=f,f=M,b*=1.9}if(h===p)return g;let x=f,R=h,v=x.g,S=R.g,A=Math.abs(v)<Math.abs(S)?x:R,F=Math.min(1e-7,o.kappa);for(let w=0;w<30&&Math.abs(R.kappaM-x.kappaM)>F;w++){let T=S-v,M=Math.abs(T)>1e-12?(x.kappaM*S-R.kappaM*v)/T:.5*(x.kappaM+R.kappaM),k=Math.min(x.kappaM,R.kappaM),C=Math.max(x.kappaM,R.kappaM);M>k&&M<C||(M=.5*(k+C));let P=l(M);if(A=P,Math.abs(P.g)<u)break;Math.sign(P.g)===Math.sign(v)?(x=P,v=P.g,S*=.5):(R=P,S=P.g,v*=.5)}return A}function TA(e,t,r,n){let o=(e*(1+t*n)+t*r)/(1-t*n);return e+o>=0?o:(e*(1-t*n)+t*r)/(1+t*n)}function rl(e,t,r,n,o,a=Us,s=!1){let i=hO(e,t,r,o,a,s),c=i.fr.Fx-i.fl.Fx,l=aa(n,r);if(Math.abs(c)<=l){let R=r-(i.fl.Fx+i.fr.Fx),v=Math.max(0,Math.abs(R)-Md(r))/2;return{left:{kappa:i.kl,forces:i.fl,want:i.fl.Fx+R/2,short:v},right:{kappa:i.kr,forces:i.fr,want:i.fr.Fx+R/2,short:v},locked:!0,spoolKappa:i.kappaM}}let u=Math.sign(c),m=r/2-u*l/2,p=r/2+u*l/2,d=Mo(e.at,m,e.seed||i.kl,a,e.fxAt),f=Mo(t.at,p,t.seed||i.kr,a,t.fxAt),h=Math.abs(m-d.forces.Fx)>Md(m),b=Math.abs(p-f.forces.Fx)>Md(p),g=Math.max(0,n.preloadN),y=hd(n.tbr);h&&!b?f=Mo(t.at,TA(d.forces.Fx,u,g,y),f.kappa,a,t.fxAt):b&&!h&&(d=Mo(e.at,TA(f.forces.Fx,-u,g,y),d.kappa,a,e.fxAt));let x=(R,v)=>({kappa:R.kappa,forces:R.forces,want:v,short:Math.max(0,Math.abs(v-R.forces.Fx)-Md(v))});return{left:x(d,m),right:x(f,p),locked:!1,spoolKappa:i.kappaM}}var gO={front:["FL","FR"],rear:["RL","RR"]},yO=Object.freeze({Fx:0,Fy:0,Mz:0});function Sd(e,t,r,n){let o=r;for(let a of["front","rear"]){let[s,i]=gO[a],c=r[s]+r[i],l=pr(e,a,c);if(!l||!(aa(l,c)>0))continue;let u=Te(t,a),m=n.alpha[a],p=(a==="front"?e.trackFront:e.trackRear)/2e3,d=n.grip??1,f=x=>R=>u.forces({Fz:x,kappa:R,alpha:m,gamma:0}),h=x=>R=>{let v=u.forces({Fz:x,kappa:R,alpha:m,gamma:0});return{Fx:d*v.Fx,Fy:d*v.Fy,Mz:d*v.Mz}},b=on(u),g=(x,R)=>{let v=Math.max(0,n.Fz[x]);return{at:v>0?d===1?f(v):h(v):()=>yO,fxAt:v>0?d===1?S=>b(v,S,m,0):S=>d*b(v,S,m,0):()=>0,vx:Math.max(.05,1-R*n.curvature),seed:0}},y=rl(g(s,p),g(i,-p),c,l,n.seed?.[a]??0);n.seed&&(n.seed[a]=y.spoolKappa),o===r&&(o={...r}),o[s]=y.left.want,o[i]=y.right.want}return o}var ia=["FL","FR","RL","RR"];function R0(e,t,r,n={}){let o={FL:0,FR:0,RL:0,RR:0},a={FL:!1,FR:!1,RL:!1,RR:!1},s={FL:!1,FR:!1,RL:!1,RR:!1};if(t===0&&!e.tvRearDiffN)return{want:o,held:a,left:0,atTop:s};let i=t>=0?1:-1,c=Math.abs(t),l={FL:0,FR:0,RL:0,RR:0},u={FL:1/0,FR:1/0,RL:1/0,RR:1/0};if(i>0){let f=["front","rear"].filter(h=>e.drive[h]);for(let h of f){let[b,g]=h==="front"?["FL","FR"]:["RL","RR"],y=e.drive[h],x=r[b]+r[g];y==="ideal"?(l[b]=r[b],l[g]=r[g],a[b]=a[g]=!0):l[b]=l[g]=x/2}for(let h of ia){let b=e.motorCap?.[h];b!==void 0&&(u[h]=Math.max(0,b))}}else if(e.brake.kind==="ideal")for(let f of ia)l[f]=r[f],a[f]=!0;else{let f=Math.min(1,Math.max(0,e.brake.front));l.FL=l.FR=f/2,l.RL=l.RR=(1-f)/2;for(let h of ia)a[h]=e.brake.abs;if(e.brake.abs){let h=Math.min(1,Math.max(0,e.brake.absUse??.9));if(h<1)for(let b of ia)u[b]=h*r[b]}}let m=Math.max(-1,Math.min(1,e.idealShift??0));if(m!==0){let f={front:i>0?e.drive.front==="ideal":e.brake.kind==="ideal",rear:i>0?e.drive.rear==="ideal":e.brake.kind==="ideal"};for(let h of["front","rear"]){if(!f[h])continue;let[b,g]=h==="front"?["FL","FR"]:["RL","RR"],[y,x]=(e.turn??1)>0?[b,g]:[g,b],[R,v]=m>0?[y,x]:[x,y],S=Math.abs(m)*l[R];l[R]-=S,l[v]+=S}}for(let f of ia){let h=n[f];a[f]&&h!==void 0&&(u[f]=Math.min(u[f],Math.max(0,h)))}let p=xO(c,l,u);for(let f of ia)o[f]=i*p.each[f],s[f]=l[f]>0&&Number.isFinite(u[f])&&p.each[f]>=u[f];let d=e.tvRearDiffN??0;return d&&(o.RL-=d/2,o.RR+=d/2),{want:o,held:a,left:p.left,atTop:s}}function xO(e,t,r){let n={FL:0,FR:0,RL:0,RR:0},o=ia.filter(i=>t[i]>0),a=e,s=o;for(let i=0;i<4&&s.length>0&&a>0;i++){let c=s.reduce((m,p)=>m+t[p],0),l=a/c,u=s.filter(m=>l*t[m]>=r[m]);if(u.length===0){for(let m of s)n[m]=l*t[m];a=0,s=[];break}for(let m of u)n[m]=r[m],a-=r[m];s=s.filter(m=>!u.includes(m))}return{each:n,left:Math.max(0,a)}}var De=9.81,he=Math.PI/180,RO=8,vO=.02,kO=12,PA=e=>10*Math.max(Xs.abs,Xs.rel*Math.abs(e)),LA=1e-6,jt=["FL","FR","RL","RR"],Vt=e=>e==="FL"||e==="FR",Wn=e=>Vt(e)?"front":"rear";function Qs(e,t){let r=Te(e,"front"),n=Te(e,"rear");return r===n?la(r,t):{front:la(r,t),rear:la(n,t)}}function la(e,t){return dg(e,Math.min(t,$r(e)))}var nl=e=>e==="FL"||e==="RL",DA=new WeakMap;function MO(e,t){let r=DA.get(e);r||DA.set(e,r=new Map);let n=100*Math.ceil(2*t*De/100),o=r.get(n);if(!o){let a=Qs(e,n);o="front"in a?a:{front:a,rear:a},r.set(n,o)}return o}function Zs(e,t,r=0,n,o=0,a=1){let s=t?.axG??0;if(t?.balance)return{axG:Number.isFinite(s)?s:0,fx:{FL:0,FR:0,RL:0,RR:0},balance:t.balance};let i=Number.isFinite(t?.tvRearDiffN)?t?.tvRearDiffN:0;if(!(!!s&&Number.isFinite(s))&&!i)return null;let l=e.massTotal*s*De,u=s>=0?Math.min(1,Math.max(0,t?.driveFrontFrac??0)):Math.min(.99,Math.max(.01,js(e,s,r,n,o,a))),m=l*u/2,p=l*(1-u)/2;return{axG:s,fx:{FL:m,FR:m,RL:p-i/2,RR:p+i/2}}}function F0(e,t,r,n){return Math.abs(ua(e,t,r,n!==void 0?{steerMaxDeg:n}:{}).peak.steerDeg)}function C0(e,t,r,n){let o=e.tv;if(!o?.enabled)return 0;let a=JA(o)(t,Math.abs(r),n);return r<0?-a:a}function T0(e,t,r=0,n,o=0,a=0,s,i=1){let c=Zs(e,{axG:t,driveFrontFrac:a},r,n,o,i),l=c?c.fx:{FL:0,FR:0,RL:0,RR:0};return c&&s&&n?Sd(e,n,l,s):l}var al=e=>nl(e)?-1:1,wd=(e,t,r,n,o)=>t*e.Fy(t*r,n,t*o);function A0(e){let t=e.wheelbase/1e3,r=t*(1-e.frontMassFrac),n=t*e.frontMassFrac;return{wb:t,lf:r,lr:n,m:e.massTotal}}function SO(e,t,r){let n=Math.abs(t),o=e.steerFront;if(o&&o.meanDeg.length>1){let u=t>=0,m=r&&o.travelSurface?Ps(o,n/he,u?r.FL:r.FR,u?r.FR:r.FL):Ls(o,n/he);return{innerMag:m.innerDeg*he,outerMag:m.outerDeg*he,innerCamber:m.innerCamber,outerCamber:m.outerCamber,atLock:m.atLock}}let a=e.trackFront/1e3,s=e.wheelbase/1e3,i=(e.ackermannPct??0)/100,c=n,l=n;if(n>1e-4){let u=s/Math.tan(n),m=Math.atan(s/Math.max(.05,u-a/2)),p=Math.atan(s/(u+a/2));c=n+i*(m-n),l=n+i*(p-n)}return{innerMag:c,outerMag:l,innerCamber:0,outerCamber:0,atLock:!1}}function ma(e,t,r){let n=(e.toeFrontDeg??0)*he,o=(e.toeRearDeg??0)*he,a=SO(e,t,r),s=t>=0?1:-1,i=t>=0,c=s*(i?a.innerMag:a.outerMag),l=s*(i?a.outerMag:a.innerMag);return{steer:{FL:c-n,FR:l+n,RL:-o,RR:o},camber:{FL:i?a.innerCamber:a.outerCamber,FR:i?a.outerCamber:a.innerCamber,RL:0,RR:0},atLock:a.atLock}}function Fd(e,t,r){if(r.Fz<=0)return 0;let n=Yt(Te(e,Wn(t))),o=al(t),a=Math.abs(r.kappa)<1e-12?n.Mz(o*r.slipRad,r.Fz,o*r.camberRad):n.forces({Fz:r.Fz,kappa:r.kappa,alpha:o*r.slipRad,gamma:o*r.camberRad}).Mz;return o*a}function EA(e,t,r,n){if(!ea(e))return null;let o=Yt(Te(t,"front")),a={};for(let s of["FL","FR"]){let i=n[s];a[s]={Fz:i.Fz,Fx:i.Fx,Fy:i.Fy,Mz:Fd(o,s,i)}}return Dc(e,r/he,a,yo(o.model),{FL:n.FL.travelMm,FR:n.FR.travelMm})}var IA=()=>({totalNm:[],aligningNm:[],lateralNm:[],longitudinalNm:[],jackingNm:[]});function _A(e,t){e.totalNm.push(t.totalNm),e.aligningNm.push(t.aligningNm),e.lateralNm.push(t.lateralNm),e.longitudinalNm.push(t.longitudinalNm),e.jackingNm.push(t.jackingNm)}var AO=Object.freeze({Fx:0,Fy:0,Mz:0});function NA(e,t,r){let n=t==="front"?(r?.FL??0)+(r?.FR??0):(r?.RL??0)+(r?.RR??0),o=pr(e,t,n);return o&&aa(o,n)>0?{F:n,law:o}:null}function fr(e,t,r,n,o,a,s,i,c,l){let u=s?.fx,m=s?.axG??0,{wb:p,lf:d,lr:f,m:h}=A0(e),b=NA(e,"front",u),g=NA(e,"rear",u),y=l?.spool??{front:0,rear:0},x=i!==void 0&&i>0&&Number.isFinite(i)?i:null,R=oe=>x===null?r:Math.sqrt(Math.max(0,oe)*x),v=Yt(Te(t,"front")),S=Yt(Te(t,"rear")),A=on(v),F=on(S),w=e.trackFront/2e3,T=e.trackRear/2e3,M=!!(e.kinFront&&e.kinRear),k=M&&x===null?l?.travel??Ro(e,e.kinFront,e.kinRear,r):null;l&&k&&(l.travel=k);let C=NaN,P=null,L=oe=>{if(!M)return null;if(x===null)return k;let se=R(oe);return se!==C&&(C=se,P=Ro(e,e.kinFront,e.kinRear,se)),P},E={},_=l?.kap??{FL:0,FR:0,RL:0,RR:0},D=e.kinFront?.compliance,I=e.kinRear?.compliance,N=!!(D||I),O=!!(D?.toePerMz||I?.toePerMz),V=oe=>Vt(oe)?D:I,H={FL:{fy:0,fx:0,mz:0},FR:{fy:0,fx:0,mz:0},RL:{fy:0,fx:0,mz:0},RR:{fy:0,fx:0,mz:0}},U=!1,G=s?.balance,B=0,q=0,re=0,W=G?MO(t,h):null,z=(oe,se)=>se>0&&W?W[Wn(oe)].muX(se)*se:0,Y=oe=>{let se=oe/r,xe=x===null?n+d*se/r:n+d/x,fe=x===null?n-f*se/r:n-f/x,Fe=L(oe),Re=R(oe),ae=G!==void 0,Me=ae?oe/De*Math.cos(n)+m*Math.sin(n):oe/De,be=ae?m*Math.cos(n)-oe/De*Math.sin(n):m,ge=Fe?Fe(Me,be,n/he,o/he):null,ye=ge?{FL:ge.FL.travel,FR:ge.FR.travel}:void 0,ce=Sm(e,Me,be,Re,n/he,o/he,ye,ge?.steeringJacking),Ae=ce.loads;U=ce.overturned;let Se=ma(e,o,ye),ve=Se.steer,wt=0,qe=Pe=>{let _e=Math.max(0,Ae[Pe]),He=al(Pe),Ee=Vt(Pe)?v:S,ze=V(Pe),qt=0,Ft=0;if(ze){let qr=H[Pe];qt=ze.toePerFy*qr.fy+ze.toePerFx*qr.fx+ze.toePerMz*qr.mz,Ft=ze.camberPerFy*qr.fy+ze.camberPerFx*qr.fx}let Mt=ve[Pe]+(ge?He*ge[Pe].bumpToe*he:0)+He*qt*he,ar=Mt-(Vt(Pe)?xe:fe),Ct=(ge?ge[Pe].camberRoad:0)*he+He*(Se.camber[Pe]+Ft)*he;return{Fz:_e,mir:He,t:Ee,gains:ze,complianceToe:qt,steerK:Mt,slip:ar,camberRad:Ct}},It=(Pe,_e)=>{let He=x===null?se/r:1/x,Ee=Vt(Pe)?d:-f,ze=(nl(Pe)?1:-1)*(Vt(Pe)?w:T),qt=(Math.cos(n)-ze*He)*Math.cos(_e.steerK)+(Math.sin(n)+Ee*He)*Math.sin(_e.steerK),Ft=Vt(Pe)?A:F;return{at:_e.Fz>0?Mt=>_e.t.forces({Fz:_e.Fz,kappa:Mt,alpha:_e.mir*_e.slip,gamma:_e.mir*_e.camberRad}):()=>AO,fxAt:_e.Fz>0?Mt=>Ft(_e.Fz,Mt,_e.mir*_e.slip,_e.mir*_e.camberRad):()=>0,vx:Math.max(.05,qt),seed:_[Pe]}};if(G){let Pe=h*(m*De-(G.axDrag??0)),_e=0,He=()=>({FL:qe("FL"),FR:qe("FR"),RL:qe("RL"),RR:qe("RR")}),Ee=ar=>({FL:z("FL",ar.FL.Fz),FR:z("FR",ar.FR.Fz),RL:z("RL",ar.RL.Fz),RR:z("RR",ar.RR.Fz)}),ze=N?null:He(),qt=ze?Ee(ze):null,Ft={},Mt={};for(let ar=0;ar<kO;ar++){let Ct=ze??He(),qr=qt??Ee(Ct),lo=Pe-B,$o={...G.spec,turn:o<0?-1:1,...lo<0&&G.brakeFront&&G.spec.brake.kind==="shares"?{brake:{...G.spec.brake,front:G.brakeFront(lo)}}:{}},Qe={},et=R0($o,lo,qr,Qe),kr={},wn={},ls={},uo=(Ve,Be)=>Qe[Ve]!==void 0&&Math.abs(Math.abs(Be)-Qe[Ve])<=1e-9*Math.max(1,Qe[Ve]);for(let Ve=0;Ve<5;Ve++){let Be=!1;for(let Ze of["front","rear"]){let[Ye,lt]=Ze==="front"?["FL","FR"]:["RL","RR"],Ir=et.want[Ye]+et.want[lt],Uu=pr(e,Ze,Ir);if(Uu&&aa(Uu,Ir)>0){let je=Nr=>Math.max(0,Math.abs(Ir-Nr.left.forces.Fx-Nr.right.forces.Fx)-PA(Ir)),$e=ls[Ze],_r=$e!==void 0&&uo(Ye,et.want[Ye])&&uo(lt,et.want[lt]),pt=_r?$e:rl(It(Ye,Ct[Ye]),It(lt,Ct[lt]),Ir,Uu,y[Ze],kd,!0);if(!_r&&je(pt)>0&&(y[Ze]!==0||_[Ye]!==0||_[lt]!==0)){let Nr=rl({...It(Ye,Ct[Ye]),seed:0},{...It(lt,Ct[lt]),seed:0},Ir,Uu,0,kd,!0);je(Nr)<je(pt)&&(pt=Nr)}y[Ze]=pt.spoolKappa,_[Ye]=pt.left.kappa,_[lt]=pt.right.kappa;let us=et.held[Ye]&&et.held[lt],ms=je(pt);if(us&&ms>0){let Nr=Math.abs(Ir),Or=Math.abs(pt.left.forces.Fx+pt.right.forces.Fx),Xi=et.want[Ye]*et.want[lt]>=0&&Nr>0,qi=Xi?Math.abs(et.want[Ye])*Or/Nr:Math.abs(pt.left.forces.Fx),Ch=Xi?Math.abs(et.want[lt])*Or/Nr:Math.abs(pt.right.forces.Fx);(Qe[Ye]===void 0||Qe[lt]===void 0||qi<Qe[Ye]-1e-6||Ch<Qe[lt]-1e-6)&&(Qe[Ye]=Math.min(qi,Qe[Ye]??1/0),Qe[lt]=Math.min(Ch,Qe[lt]??1/0),ls[Ze]=pt,Be=!0)}kr[Ye]={kappa:pt.left.kappa,Fx:pt.left.forces.Fx,Fy:Ct[Ye].mir*pt.left.forces.Fy,short:us?0:ms/2},kr[lt]={kappa:pt.right.kappa,Fx:pt.right.forces.Fx,Fy:Ct[lt].mir*pt.right.forces.Fy,short:us?0:ms/2};continue}for(let je of[Ye,lt]){let $e=Ct[je],_r=et.want[je];if(_r===0||$e.Fz<=0){let Fn=$e.Fz<=0&&!et.held[je]?Math.abs(_r):0;$e.Fz<=0&&et.held[je]&&_r!==0&&Qe[je]===void 0&&(Qe[je]=0,Be=!0);let Th=ze?Ft[je]??={}:null,Cv=$e.Fz>0?Th?.fy??wd($e.t,$e.mir,$e.slip,$e.Fz,$e.camberRad):0;Th&&(Th.fy=Cv),kr[je]={kappa:0,Fx:0,Fy:Cv,short:Fn};continue}let pt=Fn=>$e.t.forces({Fz:$e.Fz,kappa:Fn,alpha:$e.mir*$e.slip,gamma:$e.mir*$e.camberRad}),us=Vt(je)?A:F,ms=ze?Ft[je]??={}:null,Nr=Fn=>Fn!==0||!ms?us($e.Fz,Fn,$e.mir*$e.slip,$e.mir*$e.camberRad):ms.fx??=us($e.Fz,0,$e.mir*$e.slip,$e.mir*$e.camberRad),Or=(uo(je,_r)?wn[je]:void 0)??Mo(pt,_r,_[je],kd,Nr,ze?Mt[je]??={}:void 0);_[je]=Or.kappa;let Xi=PA(_r),qi=Math.abs(_r-Or.forces.Fx);if(qi>Xi&&Math.abs(Or.forces.Fx)<Math.abs(_r)&&et.held[je]){let Fn=Math.abs(Or.forces.Fx);(Qe[je]===void 0||Fn<Qe[je])&&(Qe[je]=Fn,wn[je]=Or,Be=!0)}kr[je]={kappa:Or.kappa,Fx:Or.forces.Fx,Fy:$e.mir*Or.forces.Fy,short:et.held[je]?0:Math.max(0,qi-Xi)}}}if(!Be)break;et=R0($o,lo,qr,Qe)}q=0,re=0;for(let Ve=0;Ve<jt.length;Ve++)(Qe[jt[Ve]]!==void 0||et.atTop[jt[Ve]])&&(q|=1<<Ve),Qe[jt[Ve]]!==void 0&&(re|=1<<Ve);let Qr=0,Dr=0;_e=0;for(let Ve of jt){let Be=Ct[Ve],Ze=kr[Ve];if(E[Ve]={Fz:Be.Fz,travelMm:ge?.[Ve].travel??0,steerRad:Be.steerK,slipRad:Be.slip,camberRad:Be.camberRad,Fy:Ze.Fy,Fx:Ze.Fx,kappa:Ze.kappa,fxShort:Ze.short+et.left/4,lifted:ce.lifted[Ve]},Be.gains){let lt=O&&Be.gains.toePerMz?Fd(Be.t,Ve,E[Ve]):0;H[Ve]={fy:-Be.mir*Ze.Fy,fx:Ze.Fx,mz:-Be.mir*lt*1e3};let Ir=H[Ve];Dr=Math.max(Dr,Math.abs(Be.gains.toePerFy*Ir.fy+Be.gains.toePerFx*Ir.fx+Be.gains.toePerMz*Ir.mz-Be.complianceToe))}let Ye=Be.steerK-n;Qr+=Ze.Fx*(Math.cos(Ye)-1)-Ze.Fy*Math.sin(Ye),_e+=Ze.Fy*Math.cos(Ye)+Ze.Fx*Math.sin(Ye)}let Er=Math.abs(Qr-B);if(B=Qr,Er<vO&&Dr<LA)break}return _e/h}for(let Pe=0;Pe<(N?RO:1);Pe++){wt=0;let _e=0,He={};for(let Ee of jt){let ze=Vt(Ee)?b:g;if(ze&&!He[Ee]){let[Dr,Er]=Vt(Ee)?["FL","FR"]:["RL","RR"],Ve=qe(Dr),Be=qe(Er),Ze=Wn(Ee),Ye=rl(It(Dr,Ve),It(Er,Be),ze.F,ze.law,y[Ze],Xs);y[Ze]=Ye.spoolKappa,He[Dr]={w:Ve,share:Ye.left},He[Er]={w:Be,share:Ye.right}}let qt=He[Ee]?.w??qe(Ee),{Fz:Ft,mir:Mt,t:ar,gains:Ct,complianceToe:qr,steerK:lo,slip:$o,camberRad:Qe}=qt,et=u?.[Ee]??0,kr,wn=0,ls=0,uo=0,Qr=He[Ee]?.share;if(Qr)_[Ee]=Qr.kappa,ls=Qr.kappa,wn=Qr.forces.Fx,uo=Qr.short,kr=Mt*Qr.forces.Fy;else if(et===0||Ft<=0)kr=wd(ar,Mt,$o,Ft,Qe),uo=Ft<=0?Math.abs(et):0;else{let Dr=Ze=>ar.forces({Fz:Ft,kappa:Ze,alpha:Mt*$o,gamma:Mt*Qe}),Er=Vt(Ee)?A:F,Ve=Ze=>Er(Ft,Ze,Mt*$o,Mt*Qe),Be=Mo(Dr,et,_[Ee],Xs,Ve);_[Ee]=Be.kappa,ls=Be.kappa,wn=Be.forces.Fx,uo=Math.max(0,Math.abs(et-wn)-Math.max(Us.abs,Us.rel*Math.abs(et))),kr=Mt*Be.forces.Fy}if(E[Ee]={Fz:Ft,travelMm:ge?.[Ee].travel??0,steerRad:lo,slipRad:$o,camberRad:Qe,Fy:kr,Fx:wn,kappa:ls,fxShort:uo,lifted:ce.lifted[Ee]},Ct){let Dr=O&&Ct.toePerMz?Fd(ar,Ee,E[Ee]):0;H[Ee]={fy:-Mt*kr,fx:wn,mz:-Mt*Dr*1e3};let Er=H[Ee];_e=Math.max(_e,Math.abs(Ct.toePerFy*Er.fy+Ct.toePerFx*Er.fx+Ct.toePerMz*Er.mz-qr))}wt+=kr*Math.cos(lo)+wn*Math.sin(lo)}if(_e<LA)break}return wt/h},te=oe=>{let se=Xe(e,0,m,oe,0,o/he);return se.FL+se.FR+se.RL+se.RR},j=Math.max(20,3.5*te(r)/h);if(x!==null){j=4*De;for(let oe=0;oe<8;oe++){let se=Math.min(40*De,3.5*te(R(j))/h);if(se<=j)break;j=se}j=Math.max(20,j)}let X=oe=>Y(oe)-oe,le=Math.max(.001,j*1e-4),pe=(oe,se,xe,fe)=>{let Fe=oe,Re=xe,ae=se,Me=fe,be=Fe;for(let ge=0;ge<40;ge++){let ye=Me-ae,ce=Math.abs(ye)>1e-12?(Fe*Me-Re*ae)/ye:.5*(Fe+Re),Ae=Math.min(Fe,Re),Se=Math.max(Fe,Re);ce>Ae&&ce<Se||(ce=.5*(Fe+Re));let ve=X(ce);if(be=ce,Math.abs(ve)<1e-4||Se-Ae<1e-6)break;ve<0==ae<0?(Fe=ce,ae=ve,Me*=.5):(Re=ce,Me=ve,ae*=.5)}return be},ue=(oe,se,xe,fe=!1)=>{let Fe=(ge,ye)=>xe>0?ge>0&&ye<0:ye>0&&ge<0,Re=oe,ae=se,Me=oe+xe*Math.min(Math.abs(se),j);if(!fe&&Math.abs(Me-oe)>le){let ge=X(Me);if(Fe(ae,ge))return{root:pe(Re,ae,Me,ge),last:Re};Re=Me,ae=ge}let be=fe?j/24:Math.max(j/24,Math.abs(Me-oe)/4);for(let ge=1;ge<=24;ge++){let ye=Re+xe*be;if(Math.abs(ye)>j)break;let ce=X(ye);if(Fe(ae,ce))return{root:pe(Re,ae,ye,ce),last:Re};if(fe&&ce*xe<0&&(ce-ae)*xe<0)break;Re=ye,ae=ce}return{root:null,last:Re}},ie=c??null;if(c===void 0&&a!==void 0&&Number.isFinite(a)&&Math.abs(a)<=j){let oe=X(a);if(Math.abs(oe)<=1e-4)X(a+le)<0&&X(a-le)>0&&(ie=a);else{let se=ue(a,oe,Math.sign(oe)).root;ie=se!==null&&(se===0||Math.sign(se)===Math.sign(a))?se:null}}let ke=ie===null;if(ie===null){let oe=X(0),se=X(le),xe=Math.abs(oe)<=1e-4,fe=xe?x!==null?1:o!==0?Math.sign(o):se>0?1:-1:Math.sign(oe),Fe=xe?fe*le:0,Re=xe?fe>0?se:X(-le):oe,ae=ue(Fe,Re,fe);ie=ae.root??(xe?0:ae.last)}let Ie=Y(ie);if(ke&&o!==0&&x===null){let oe=Math.sign(o);if(ie*oe<=0||(E.RL.Fy+E.RR.Fy)*oe<0){let se={...E},xe=U,fe=oe*Math.max(ie*oe+le,n*oe*r*r/f),Fe=null;if(fe*oe<j){let Re=X(fe);if(Re*oe>0)Fe=ue(fe,Re,oe).root;else{let ae=fe+oe*j/24,Me=X(ae);(Me-Re)*oe>0&&(Fe=ue(ae,Me,oe,Me*oe<=0).root)}}Fe!==null&&Fe*oe>0?(ie=Fe,Ie=Y(ie)):(Object.assign(E,se),U=xe)}}let Ke=d*(E.FL.Fy*Math.cos(E.FL.steerRad)+E.FR.Fy*Math.cos(E.FR.steerRad))-f*(E.RL.Fy+E.RR.Fy);if(G){Ke=0;for(let oe of jt){let se=E[oe],xe=Vt(oe)?d:-f,fe=(nl(oe)?1:-1)*(Vt(oe)?w:T),Fe=Math.cos(se.steerRad),Re=Math.sin(se.steerRad);Ke+=xe*(se.Fy*Fe+se.Fx*Re)-fe*(se.Fx*Fe-se.Fy*Re)}}else if(s||b||g){let oe=se=>(nl(se)?1:-1)*(Vt(se)?w:T);for(let se of jt){let xe=E[se],fe=Vt(se)?d:-f;Ke+=fe*xe.Fx*Math.sin(xe.steerRad)-oe(se)*xe.Fx*Math.cos(xe.steerRad)}}return l&&(l.held=q,l.ceiling=re),x!==null&&ie<-1e-6?{ay:NaN,cn:NaN,wheels:E,overturned:U,res:NaN}:{ay:ie/De,cn:Ke/(h*De*p),wheels:E,overturned:U,res:Ie-ie}}function wO(e,t,r,n,o,a,s,i=0){let c=20*he,l=.001,u=(h,b)=>{let g=fr(e,t,r,h,n,b,s);return{cn:g.cn-i,ay:g.ay*De}},m=h=>n===0||i!==0||Math.abs(h)<.05||Math.sign(h)===Math.sign(n),p=(h,b,g,y)=>{let x=u(h,y);if(Math.abs(x.cn)<1e-5)return{beta:h,trimmed:!0};let R=y===void 0?void 0:x.ay,v={pos:{b:h,cn:x.cn,ay:R},neg:{b:h,cn:x.cn,ay:R}},S=null,A=h,F=Math.abs(x.cn);for(let w=0;w<b.length&&!S;w++)for(let T of[v.pos,v.neg]){let M=T===v.pos?1:-1,k=h+M*b[w];if(Math.abs(k)>c)continue;let C=u(k,T.ay);if(Math.abs(C.cn)<F&&m(C.ay)&&(F=Math.abs(C.cn),A=k),C.cn===0&&m(C.ay))return{beta:k,trimmed:!0};if(C.cn<0!=T.cn<0){let P={lo:T.b,hi:k,ayLo:T.ay},L=OA(u,P),E=u(L,T.ay);if(Math.abs(E.cn)<l&&m(E.ay))return S=P,{beta:L,trimmed:!0}}T.b=k,T.cn=C.cn,y!==void 0&&(T.ay=C.ay)}return S?{beta:OA(u,S),trimmed:!0}:g?{beta:A,trimmed:!1}:null},d=[.25,.75,2,5].map(h=>h*he);if(o!==void 0&&Number.isFinite(o)&&Math.abs(o)<=c){let h=p(o,d,!1,a);if(h)return h;if(!s&&i===0&&a!==void 0&&Number.isFinite(a)){let b=FO(e,t,r,n,o,a,c);if(b&&m(b.ay))return{beta:b.beta,trimmed:!0,ay:b.ay}}}let f=[1,3,7,15,20].map(h=>h*he).filter(h=>h<=c);return p(0,f,!0)??{beta:0,trimmed:!1}}function OA(e,t){let{lo:r,hi:n}=t,o=t.ayLo,a=e(r,o).cn,s=e(n,o).cn,i=r;for(let c=0;c<40;c++){let l=s-a,u=Math.abs(l)>1e-12?(r*s-n*a)/l:.5*(r+n);u>Math.min(r,n)&&u<Math.max(r,n)||(u=.5*(r+n));let m=e(u,o),p=m.cn;if(o!==void 0&&(o=m.ay),i=u,Math.abs(p)<1e-5||Math.abs(n-r)<1e-5)break;p<0==a<0?(r=u,a=p,s*=.5):(n=u,s=p,a*=.5)}return i}function FO(e,t,r,n,o,a,s){let i=(p,d)=>{let f=fr(e,t,r,p,n,void 0,null,void 0,d);return{r:f.res,c:f.cn}},c=o,l=a,u=i(c,l),m=0;for(let p=0;p<CO;p++){let d=i(c+v0,l),f=i(c,l+k0),h=(d.r-u.r)/v0,b=(f.r-u.r)/k0,g=(d.c-u.c)/v0,y=(f.c-u.c)/k0,x=h*y-b*g;if(!Number.isFinite(x)||x===0||Math.abs(x)<DO*(Math.abs(h*y)+Math.abs(b*g)))return null;if(p===0)m=Math.sign(x);else if(Math.sign(x)!==m)return null;if(Math.abs(u.r)<=1e-4&&Math.abs(u.c)<=1e-5)return{beta:c,ay:l};let R=(u.c*b-u.r*y)/x,v=(u.r*g-u.c*h)/x,S=Math.min(1,TO/Math.max(Math.abs(R),1e-300),PO/Math.max(Math.abs(v),1e-300));if(c+=S*R,l+=S*v,Math.abs(c-o)>LO||Math.abs(c)>s||l*a<0)return null;u=i(c,l)}return null}var CO=8,v0=1e-5,k0=.001,TO=1*he,PO=2,LO=5*he,DO=.5;function zA(e,t,r,n,o,a,s,i){let c=fr(e,t,r,n,o,a,s,void 0,i),l=c.ay*De/r,u={},m=0;for(let f of jt){let h=c.wheels[f],b=Te(t,Wn(f)),g=$r(b),y=b.muY(Math.min(h.Fz,g)),x=b.muX(Math.min(h.Fz,g));m+=h.fxShort,u[f]={Fz:h.Fz,steerDeg:h.steerRad/he,slipDeg:h.slipRad/he,camberDeg:h.camberRad/he,Fy:h.Fy,Fx:h.Fx,Mz:Fd(b,f,h),gripUtil:y*h.Fz>0?Math.hypot(h.Fy/(y*h.Fz),x*h.Fz>0?h.Fx/(x*h.Fz):0):0,...h.Fz>g?{pastTurnover:!0}:{},lifted:h.lifted}}let p=Dc(e,o/he,u,yo(Te(t,"front").model),{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}),d=ma(e,o,e.kinFront&&e.kinRear?{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}:void 0);return{wheels:u,ay:c.ay,ax:s?.axG??0,beta:n/he,yawRate:l*180/Math.PI,steerDeg:o/he,...d.atLock?{lockDeg:(d.steer.FL+d.steer.FR)/2/he}:{},converged:!0,trimmed:!c.overturned,overturned:c.overturned,driving:!1,fxShortfall:m,...p?{steering:p}:{}}}function jn(e,t,r,n,o,a,s=0){let i=Math.max(8,r),c=ca(e,t,i,n,o,a,s);return n!==0&&o?.driving===void 0&&(c.driving=jO(e,t,i,c,a,s)),c}function ca(e,t,r,n,o,a,s){let i=n*he,c=Zs(e,a,r,t),l=o&&Number.isFinite(o.ay)?o.ay*De:void 0,u=o&&Number.isFinite(o.beta)?o.beta*he:void 0,{beta:m,trimmed:p,ay:d}=wO(e,t,r,i,u,l,c,s),f=zA(e,t,r,m,i,l,c,d),h={...f,trimmed:p&&!f.overturned};return h.driving=n===0?h.trimmed:o?.driving!==void 0&&o.driving&&h.trimmed&&Math.abs(h.beta-o.beta)<=EO,h}var EO=3;function ua(e,t,r,n={}){let o=Math.max(8,r),a=n.direction??1,s=n.yawDemandCn??0,i=n.steerMaxDeg??IO,c=typeof n.op=="function"?n.op:()=>n.op,l=typeof n.op=="function"||n.op?.balance?null:`${o}|${a}|${s}|${i}|${n.op?`${n.op.axG}|${n.op.driveFrontFrac??""}|${n.op.tvRearDiffN??""}`:""}`;if(l!==null){let S=M0.get(e)?.get(t)?.get(l);if(S)return S}let u=(S,A)=>A.trimmed&&Math.abs(A.beta-S.beta)<=Cd&&Math.abs(A.ay-S.ay)*De<=Td,m=!1,p=(S,A)=>{let F=ca(e,t,o,a*S,A,c(a*S),s);return u(A,F)?(F.driving=!0,F):(m=F.overturned,null)},d=[ca(e,t,o,0,void 0,c(0),s)],f=null,h=!1,b,g=S=>{let A=d.length-1;for(;A>1&&S.sb*(d[A].beta-d[A-1].beta)>=0;)A--;let F=a*(S.state.ay-d[A].ay)>0,w=T=>S.sb*(T.beta-S.state.beta)>0||a*T.steerDeg>=a*S.state.steerDeg||F&&a*T.ay>=a*S.state.ay;for(;d.length>Math.max(2,A)&&w(d[d.length-1]);)d.pop();b={state:S.state,stall:d[d.length-1]},d.push(S.state),f=Math.abs(S.state.steerDeg)},y=(S,A=!1)=>A||zO(d[d.length-1],S)?YO(e,t,o,a,d,S,c,s):null,x=d[0].trimmed?d[0]:null;if(!x){let S=0;for(let A=VA;A<=i&&!x;A+=VA){let F=ca(e,t,o,a*A,void 0,c(a*A),s);if(F.trimmed){let w=A;x=F;for(let T=0;T<6;T++){let M=.5*(S+w),k=ca(e,t,o,a*M,void 0,c(a*M),s);k.trimmed?(w=M,x=k):S=M}}else S=A}x&&(x.driving=!0,d.push(x))}if(x){let S=Math.abs(x.steerDeg),A=Math.min(S0,100/(o*o)),F=x;for(;S<i;){let w=Math.min(i,S+A),T=p(w,F);if(T){let L=y(T);if(L){g(L);break}if(d.push(T),w>=i||ZA(e,a*w))break;Math.abs(T.beta-F.beta)<.5*Cd&&Math.abs(T.ay-F.ay)*De<.5*Td&&(A=Math.min(S0,1.5*A)),S=w,F=T;continue}if(A>_O){A*=.5;continue}let M=m,k=!1,C=null;for(let L of NO){let E=Math.min(i,S+L);if(E<=S)continue;let _=p(E,F);if(_){if(C=y(_,!0),C)break;d.push(_),S=E,F=_,A=Math.min(S0,100/(o*o)),k=!0;break}}if(k)continue;if(C){g(C);break}f=S,h=M;let P=M?null:HO(e,t,o,a,d,c,s);P&&g(P);break}}else f=0;let R=d[0];for(let S of d)a*S.ay>a*R.ay&&(R=S);let v={states:d,foldDeg:f,rollover:h,peak:R,...b?{fold:b}:{}};if(l!==null){let S=M0.get(e);S||(S=new WeakMap,M0.set(e,S));let A=S.get(t);A||(A=new Map,S.set(t,A)),A.size>256&&A.clear(),A.set(l,v)}return v}var M0=new WeakMap,IO=90,Cd=1.5,Td=2.5,S0=5,_O=.002,NO=[.5,1],VA=2.5,YA=.01,Yn=.001,OO=.05,VO=.25,BO=5,$O=2,BA=1e-8,GO=1e-7,KO=1e-6;function WA(e,t,r,n,o,a,s){let i=n*he,c=o.ay*De,l=b=>{let g=fr(e,t,r,i,b*he,c,Zs(e,a(b),r,t));return{g:g.cn-s,ay:g.ay}},u=o.steerDeg,m=l(u),p=u+(u<0?-.001:.001),d=l(p),f=()=>d.g===0||Math.abs(p-u)<BA;for(let b=0;b<40&&Math.sign(m.g)===Math.sign(d.g)&&!f();b++){let g=(d.g-m.g)/(p-u),y=g!==0?p-d.g/g:p+2*(p-u);if(!Number.isFinite(y))return null;let x=2*Math.abs(p-u)+.001;if(y=p+Math.max(-x,Math.min(x,y-p)),u=p,m=d,p=y,d=l(p),Math.abs(p-o.steerDeg)>$O)return null}let h={x:p,ay:d.ay};if(Math.sign(m.g)!==Math.sign(d.g)){let b=u,g=m.g,y=p,x=d.g;for(let R=0;R<60&&x!==0&&Math.abs(y-b)>BA;R++){let v=(b*x-y*g)/(x-g),S=l(v);if(h={x:v,ay:S.ay},S.g===0)break;Math.sign(S.g)===Math.sign(g)?(b=v,g=S.g,x*=.5):(y=v,x=S.g,g*=.5)}}else if(!f())return null;return Math.abs(h.ay-o.ay)*De>Td?null:{steerDeg:h.x,ay:h.ay}}function ol(e,t,r,n,o){let a=zA(e,t,r,n.beta*he,n.steerDeg*he,n.ay*De,Zs(e,o(n.steerDeg),r,t));return{...a,trimmed:!a.overturned,driving:!a.overturned}}function HO(e,t,r,n,o,a,s){let i=o.length;if(i<3)return null;let c=o[i-1],l=i-2;for(;l>1&&o[l].beta===c.beta;)l--;let u=o[l],m=Math.sign(c.beta-u.beta);if(m===0||!u.driving)return null;let p=jA(e,t,r,a,s),d=p(u.beta,u),f=p(c.beta,c);if(!d||!f)return null;let h=n*f.steerDeg>=n*d.steerDeg,b=h?d:f,g=h?f:d,y=h?m:-m,x=null;for(let S=YA;Math.abs(g.beta-c.beta)<=Cd;S*=1.5){let A=p(g.beta+y*S);if(!A)return null;if(n*A.steerDeg<=n*g.steerDeg){x=A;break}b=g,g=A}if(!x)return null;let R=UA(p,n,b,g,x);if(!R)return null;let v=ol(e,t,r,R,a);return!v.trimmed||Math.abs(v.beta-c.beta)>Cd||Math.abs(v.ay-c.ay)*De>Td?null:{state:v,sb:m}}function jA(e,t,r,n,o){let a=[];return(s,i)=>{if(!i){i=a[0];for(let u of a)Math.abs(u.beta-s)<Math.abs(i.beta-s)&&(i=u)}let c=WA(e,t,r,s,i,n,o);if(!c)return null;let l={beta:s,...c};return a.push(l),l}}function zO(e,t){let r=Math.abs(t.beta-e.beta);return r>VO&&r>BO*Math.abs(t.steerDeg-e.steerDeg)}function YO(e,t,r,n,o,a,s,i){let c=o.length;if(c<2)return null;let l=o[c-1],u=c-2;for(;u>0&&o[u].beta===l.beta;)u--;let m=o[u],p=Math.sign(a.beta-l.beta);if(p===0||Math.sign(l.beta-m.beta)!==p||!m.driving)return null;let d=jA(e,t,r,s,i),f=d(m.beta,m),h=d(l.beta,l);if(!f||!h||n*h.steerDeg<n*f.steerDeg)return null;let b=f,g=h,y=null;for(let x=YA;p*(a.beta-g.beta)>0;x=Math.min(OO,1.5*x)){let R=d(p*(a.beta-g.beta)>x?g.beta+p*x:a.beta);if(!R)return null;let v=n*R.steerDeg<=n*g.steerDeg;if(!y)v&&(y=[b,g,R]);else if(!v){let S=UA(d,n,...y);if(!S)return null;let A=ol(e,t,r,S,s);return A.trimmed?{state:A,sb:p}:null}b=g,g=R}return null}function UA(e,t,r,n,o){let a=d=>-t*d.steerDeg,s=Math.min(r.beta,o.beta),i=Math.max(r.beta,o.beta),c=n,l=a(r)<=a(o)?r:o,u=l===r?o:r,m=i-s,p=0;for(let d=0;d<100;d++){let f=.5*(s+i);if(Math.abs(c.beta-f)<=2*Yn-.5*(i-s))break;let h=!0;if(Math.abs(m)>Yn){let g=(c.beta-l.beta)*(a(c)-a(u)),y=(c.beta-u.beta)*(a(c)-a(l)),x=(c.beta-u.beta)*y-(c.beta-l.beta)*g;y=2*(y-g),y>0&&(x=-x),y=Math.abs(y);let R=m;if(m=p,Math.abs(x)<Math.abs(.5*y*R)&&x>y*(s-c.beta)&&x<y*(i-c.beta)){p=x/y;let v=c.beta+p;(v-s<2*Yn||i-v<2*Yn)&&(p=f>=c.beta?Yn:-Yn),h=!1}}h&&(m=c.beta>=f?s-c.beta:i-c.beta,p=qA*m);let b=e(Math.abs(p)>=Yn?c.beta+p:c.beta+(p>=0?Yn:-Yn));if(!b)return null;a(b)<=a(c)?(b.beta>=c.beta?s=c.beta:i=c.beta,u=l,l=c,c=b):(b.beta<c.beta?s=b.beta:i=b.beta,a(b)<=a(l)||l===c?(u=l,l=b):(a(b)<=a(u)||u===c||u===l)&&(u=b))}return c}function P0(e,t,r,n,o,a,s=[n.stall]){let i=typeof o.op=="function"?o.op:()=>o.op,c=o.yawDemandCn??0,l="steerDeg"in a?b=>Math.abs(b.steerDeg)-Math.abs(a.steerDeg):b=>Math.abs(b.ay)-Math.abs(a.ayG),u=[...s,n.state].map(b=>({beta:b.beta,steerDeg:b.steerDeg,ay:b.ay})),m=u[0],p=u[u.length-1],d=l(m),f=l(p);if(d>0||f<0)return null;if(f===0)return ol(e,t,r,p,i);let h=m;for(let b=0;b<60&&Math.abs(p.beta-m.beta)>1e-9;b++){let g=(m.beta*f-p.beta*d)/(f-d),y=u[0];for(let S of u)Math.abs(S.beta-g)<Math.abs(y.beta-g)&&(y=S);let x=WA(e,t,r,g,y,i,c);if(!x)return null;let R={beta:g,...x};u.push(R),h=R;let v=l(R);if(Math.abs(v)<("steerDeg"in a?GO:KO))break;v<0?(m=R,d=v,f*=.5):(p=R,f=v,d*=.5)}return ol(e,t,r,h,i)}function WO(e,t,r,n,o,a){let s=Math.abs(o),{states:i}=n;if(s>Math.abs(i[i.length-1].steerDeg)+1e-9)return null;let c=0;for(;c<i.length-1&&Math.abs(i[c+1].steerDeg)<=s;)c++;let l=i[c];if(Math.abs(Math.abs(l.steerDeg)-s)<1e-9)return l;if(n.fold&&l===n.fold.stall)return P0(e,t,r,n.fold,a,{steerDeg:o});let u=typeof a.op=="function"?a.op(o):a.op,m=ca(e,t,r,o,l,u,a.yawDemandCn??0);return m.driving?m:null}function jO(e,t,r,n,o,a){if(!n.trimmed)return!1;let s=n.steerDeg<0?-1:1,{states:i}=ua(e,t,r,{direction:s,op:o,yawDemandCn:a}),c=Math.abs(n.steerDeg);if(c>Math.abs(i[i.length-1].steerDeg)+1e-9)return!1;let l=0;for(;l<i.length-2&&Math.abs(i[l+1].steerDeg)<c;)l++;let u=i[l],m=i[Math.min(l+1,i.length-1)],p=Math.abs(m.steerDeg)-Math.abs(u.steerDeg),d=p>0?Math.min(1,Math.max(0,(c-Math.abs(u.steerDeg))/p)):0,f=u.beta+d*(m.beta-u.beta),h=u.ay+d*(m.ay-u.ay);return Math.abs(n.beta-f)<=1&&Math.abs(n.ay-h)<=.05}function So(e,t,r,n,o){let a=Math.max(8,r),s=n>=0?1:-1,i=Math.abs(n),c=(b,g)=>jn(e,t,a,s*b,g,o),l=ua(e,t,a,{direction:s,op:o}),{fold:u}=l;if(u&&Math.abs(u.state.steerDeg)<=qs){if(i>Math.abs(u.state.ay))return GA(e,t,a,s,i,o);if(i>Math.abs(u.stall.ay)){let b=P0(e,t,a,u,{direction:s,op:o},{ayG:i});if(b)return b}}let m=l.states.filter(b=>Math.abs(b.steerDeg)<=qs),p=m[m.length-1],d=l.states.length>m.length;d&&Math.abs(p.steerDeg)<qs&&m.push(c(qs,p));let f=m.findIndex(b=>Math.abs(b.ay)>=i);if(f===0)return jn(e,t,a,0,void 0,o);if(f>0)return $A(m[f-1],m[f],i,c);let h=XA(m,c,void 0,d||l.foldDeg===null);return h.ay>=i?$A(h.below,h.state,i,c):l.foldDeg!==null&&l.foldDeg<qs?GA(e,t,a,s,i,o):h.state}var qs=20;function $A(e,t,r,n){let o={steer:Math.abs(e.steerDeg),f:Math.abs(e.ay)-r},a={steer:Math.abs(t.steerDeg),f:Math.abs(t.ay)-r},s=a.f===o.f?.5:-o.f/(a.f-o.f),i={ay:e.ay+s*(t.ay-e.ay),beta:e.beta+s*(t.beta-e.beta),driving:e.driving},c=0,l=null,u=1/0;for(let m=0;m<60;m++){let p=a.f===o.f?.5*(o.steer+a.steer):o.steer-o.f*(a.steer-o.steer)/(a.f-o.f),d=n(p,i),f=Math.abs(d.ay)-r;if(Math.abs(f)<u&&(l=d,u=Math.abs(f)),Math.abs(f)<=UO||a.steer-o.steer<=XO)break;f<0?(o={steer:p,f},c===-1&&(a.f*=.5),c=-1):(a={steer:p,f},c===1&&(o.f*=.5),c=1)}return l}var UO=1e-9,XO=1e-7;function XA(e,t,r,n=!1){let o=r??0;if(r===void 0)for(let S=1;S<e.length;S++)Math.abs(e[S].ay)>Math.abs(e[o].ay)&&(o=S);let a=e[Math.max(0,o-1)],s=Math.abs(e[o].steerDeg),i=qO/4,c,l,u,m,p,d,f,h,b=null,g;if(o>0&&o<e.length-1){let S=e[o+1];g=w=>{if(w<s)return t(w,a);let T=t(w,e[o]);return T.ay===e[o].ay?t(w,a):T},c=Math.abs(a.steerDeg),l=Math.abs(S.steerDeg),u=s,m=-Math.abs(e[o].ay);let[A,F]=Math.abs(a.ay)>=Math.abs(S.ay)?[a,S]:[S,a];p=Math.abs(A.steerDeg),d=-Math.abs(A.ay),f=Math.abs(F.steerDeg),h=-Math.abs(F.ay)}else{let S=Math.abs(e[o].lockDeg??e[o].steerDeg),A=S-QO,F=o>0&&n&&A>Math.abs(a.steerDeg)?t(A,a):null;if(!F||Math.abs(F.ay)<=Math.abs(e[o].ay)){let w=t(s,a);return{state:w,below:a,ay:Math.abs(w.ay)}}g=w=>t(w,a),c=Math.abs(a.steerDeg),l=S,u=A,m=-Math.abs(F.ay),b=F,p=S,d=-Math.abs(e[o].ay),f=c,h=-Math.abs(a.ay)}let y=l-c,x=0;for(let S=0;S<100;S++){let A=.5*(c+l);if(Math.abs(u-A)<=2*i-.5*(l-c))break;let F=!0;if(Math.abs(y)>i){let k=(u-p)*(m-h),C=(u-f)*(m-d),P=(u-f)*C-(u-p)*k;C=2*(C-k),C>0&&(P=-P),C=Math.abs(C);let L=y;if(y=x,Math.abs(P)<Math.abs(.5*C*L)&&P>C*(c-u)&&P<C*(l-u)){x=P/C;let E=u+x;(E-c<2*i||l-E<2*i)&&(x=A>=u?i:-i),F=!1}}F&&(y=u>=A?c-u:l-u,x=qA*y);let w=Math.abs(x)>=i?u+x:u+(x>=0?i:-i),T=g(w),M=-Math.abs(T.ay);M<=m?(w>=u?c=u:l=u,f=p,h=d,p=u,d=m,u=w,m=M,b=T):(w<u?c=w:l=w,M<=d||p===u?(f=p,h=d,p=w,d=M):(M<=h||f===u||f===p)&&(f=w,h=M))}let R=b??t(s,a),v=Math.abs(R.steerDeg)>s?e[o]:a;return{state:R,below:v,ay:Math.abs(R.ay)}}var qO=.001,QO=.01,qA=(3-Math.sqrt(5))/2;function GA(e,t,r,n,o,a){let s=l=>Math.abs(jn(e,t,r,n*l,void 0,a).ay),i=0,c=qs;if(s(c)<o)return jn(e,t,r,n*c,void 0,a);for(let l=0;l<28;l++){let u=.5*(i+c);s(u)<o?i=u:c=u}return jn(e,t,r,n*.5*(i+c),void 0,a)}function L0(e,t,r,n,o){let a=So(e,t,r,n,o);return a.steering?Math.abs(a.steering.totalNm):NaN}function D0(e,t,r,n,o){if(!ea(e))return NaN;let a=n<0?-1:1,s=Math.abs(n),i=So(e,t,r,a*s,o);if(!i.steering)return NaN;let c=Math.abs(i.steerDeg);for(let l of[.05,.1,.2,.4]){let u=Math.max(0,c-l),m=c+l,p=jn(e,t,r,a*u,void 0,o),d=jn(e,t,r,a*m,void 0,o),f=p.steering?Math.abs(p.steering.totalNm):NaN,h=d.steering?Math.abs(d.steering.totalNm):NaN,b=Math.abs(d.ay)-Math.abs(p.ay);if(Number.isFinite(f)&&Number.isFinite(h)&&b>=.01||l===.4&&Number.isFinite(f)&&Number.isFinite(h)&&b>.001)return(h-f)/b}return NaN}function w0(e,t,r,n,o,a,s){let i=Math.max(8,r),c=s!==void 0&&Number.isFinite(s)?s*De:void 0,l=fr(e,t,i,n*he,o*he,c,Zs(e,a,i,t)),u=0;for(let m of jt)u+=l.wheels[m].fxShort;return{ay:l.ay,cn:l.cn,fxShortfall:u}}function E0(e,t,r,n,o){let a=Math.max(8,r),s=So(e,t,a,n,o),i=.5,c=w0(e,t,a,s.beta+i,s.steerDeg,o).cn,l=w0(e,t,a,s.beta-i,s.steerDeg,o).cn;return(c-l)/(2*i*he)*e.massTotal*De*(e.wheelbase/1e3)}function I0(e,t,r,n){let o=Math.max(8,r),{branch:a,opts:s}=ZO(e,t,o,n);return QA(e,t,o,a,s)}function ZO(e,t,r,n){if(!e.tv?.enabled||n?.balance){let s=n?{op:n}:{};return{branch:ua(e,t,r,s),opts:s}}let o=F0(e,t,r),a={op:s=>{let i=C0(e,r,s,o);return i===0?n:{axG:n?.axG??0,driveFrontFrac:n?.driveFrontFrac,tvRearDiffN:i}}};return{branch:ua(e,t,r,a),opts:a}}function QA(e,t,r,n,o){let a=typeof o.op=="function"?o.op:()=>o.op,s=o.yawDemandCn??0;if(n.fold&&n.peak===n.fold.state)return ol(e,t,r,n.peak,a);let i=(l,u)=>ca(e,t,r,l,u,a(l),s),c=n.states[0].driving||!n.peak.driving?n.states:n.states.slice(1);return XA(c,i,c.indexOf(n.peak),n.foldDeg===null).state}function _0(e,t,r,n={}){let o=n.radius!==void 0&&n.radius>0&&Number.isFinite(n.radius)?n.radius:void 0,a=o===void 0?Math.max(8,r):Math.max(8,Math.sqrt(De*o)),s=(n.betaMaxDeg??10)*he,i=(n.deltaMaxDeg??10)*he,[c,l]=n.betaRangeDeg?[n.betaRangeDeg[0]*he,n.betaRangeDeg[1]*he]:[-s,s],[u,m]=n.deltaRangeDeg?[n.deltaRangeDeg[0]*he,n.deltaRangeDeg[1]*he]:[-i,i],{lf:p,lr:d}=A0(e),f=o===void 0?0:d/o,h=o===void 0?0:(p+d)/o,b=n.nLines??9,g=n.nPts??21,y=n.steering!==!1&&ea(e),x=y?yo(Te(t,"front").model):void 0,R=(O,V,H,U)=>H===1?O:O+(V-O)*U/(H-1),v=e.tv?.enabled?F0(e,t,a):0,S=O=>{let V=C0(e,a,O/he,v);return!n.axG&&V===0?null:Zs(e,{axG:n.axG??0,driveFrontFrac:n.driveFrontFrac,tvRearDiffN:V},a,t)},{lf:A,lr:F}=A0(e),w=n.reserves?Qs(t,e.massTotal*De*1.2):null,T=O=>w?_n(w,{FL:O.FL,FR:O.FR,RL:O.RL,RR:O.RR},{lf:A,lr:F}):null,M=[],k={ay:[],cn:[]},C=0;for(let O=0;O<b;O++){let V=R(u,m,b,O),H=S(V),U=[],G=[],B=[],q=[],re=w?{stabil:[],agil:[]}:void 0,W=y?IA():void 0,z;for(let j=0;j<g;j++){let X=R(c,l,g,j),le=fr(e,t,a,X,V,z,H,o);if(z=Number.isFinite(le.ay)?le.ay*De:void 0,U.push(le.ay),G.push(le.cn),B.push(X/he),q.push(V/he),re){let pe=T(le.wheels);re.stabil.push(pe.stabil),re.agil.push(pe.agil)}W&&_A(W,EA(e,t,V,le.wheels)),Math.abs(le.ay)>C&&(C=Math.abs(le.ay))}M.push({label:`\u03B4 ${(V/he).toFixed(0)}\xB0`,ay:U,cn:G,betaDeg:B,deltaDeg:q,reserve:re,steering:W});let Y=null,te=1/0;for(let j=1;j<G.length;j++){if(!Number.isFinite(G[j-1])||!Number.isFinite(G[j])||G[j-1]!==0&&G[j-1]<0==G[j]<0)continue;let X=G[j-1]===G[j]?0:G[j-1]/(G[j-1]-G[j]),le=U[j-1]+X*(U[j]-U[j-1]);if(o===void 0&&V!==0&&Math.abs(le)>=.05&&Math.sign(le)!==Math.sign(V))continue;let pe=Math.abs(B[j-1]+X*(B[j]-B[j-1])-f/he);pe<te&&(te=pe,Y=le)}Y!==null&&(k.ay.push(Y),k.cn.push(0))}let P=[];for(let O=0;O<b;O++){let V=R(c,l,b,O),H=[],U=[],G=[],B=[],q=w?{stabil:[],agil:[]}:void 0,re=y?IA():void 0,W;for(let z=0;z<g;z++){let Y=R(u,m,g,z),te=fr(e,t,a,V,Y,W,S(Y),o);if(W=Number.isFinite(te.ay)?te.ay*De:void 0,H.push(te.ay),U.push(te.cn),G.push(V/he),B.push(Y/he),q){let j=T(te.wheels);q.stabil.push(j.stabil),q.agil.push(j.agil)}re&&_A(re,EA(e,t,Y,te.wheels))}P.push({label:`\u03B2 ${(V/he).toFixed(0)}\xB0`,ay:H,cn:U,betaDeg:G,deltaDeg:B,reserve:q,steering:re})}let L=.5*he,E=S(h),_,D;if(o===void 0)_=(fr(e,t,a,f+L,h,void 0,E,o).cn-fr(e,t,a,f-L,h,void 0,E,o).cn)/(2*L),D=(fr(e,t,a,f,h+L,void 0,S(h+L),o).cn-fr(e,t,a,f,h-L,void 0,S(h-L),o).cn)/(2*L);else{let O=(U,G)=>fr(e,t,a,U,G,void 0,S(G),o).cn,V=(U,G,B)=>Number.isFinite(U)?(-3*U+4*G-B)/(2*L):(B-G)/L,H=O(f,h);_=-V(H,O(f-L,h),O(f-2*L,h)),D=V(H,O(f,h+L),O(f,h+2*L))}let I=0;if(E&&E.axG){let O=fr(e,t,a,f,h,void 0,E,o),V=0;for(let H of jt)V+=O.wheels[H].fxShort;I=V/Math.abs(e.massTotal*E.axG*De)}let N=k.ay.reduce((O,V)=>Math.max(O,Math.abs(V)),0);return{isoBeta:P,isoDelta:M,trim:k,maxAy:C,stability:_,control:D,speed:o===void 0?a:Math.sqrt(N*De*o),...o!==void 0?{radius:o}:{},axG:E?.axG??0,axShortfall:I,...x?{steeringAligningSource:x}:{}}}function ZA(e,t){return ma(e,t*he).atLock}function JO(e,t,r,n,o=zn(e,t,r)){let a=r,s=e.massTotal,i=jt.filter(g=>Vt(g)?n.drivenFront:n.drivenRear),c=o.peakAt,l={front:n.drivenFront?pr(e,"front",1):void 0,rear:n.drivenRear?pr(e,"rear",1):void 0},u=new Map,m=(g,y)=>{let x=`${g}:${y}`,R=u.get(x);if(R===void 0){let v=Math.max(1,y*el);R=lr(Te(t,g),v,0,!1,c(g,v)),u.set(x,R)}return R},p=(g,y)=>y>0?Jc(y,x=>m(g,x)):0,d=(g,y,x,R)=>{let v=Te(t,g),S=E=>{let _=Math.max(0,x[E]),D=c(g,_);return{Fz:_,a:p(g,_),b:D.fyPeak,slide:0,cap:I=>_>0?lr(v,_,I,!1,D):0}},[A,F]=g==="front"?["FL","FR"]:["RL","RR"],w=S(A),T=S(F),M=R[A]*w.b,k=R[F]*T.b,C=w.cap(M)+T.cap(k),P=Zc(w,T,M+k,y,C);return{l:A,r:F,full:P,asHeld:()=>({axle:g,strong:w.cap(M)>=T.cap(k)?A:F,full:P,open:Zc(w,T,M+k,Ws,C),sense:1})}},f=g=>({muX:y=>y>0?p(g,y)/y:0,muY:y=>y>0?c(g,y).fyPeak/y:0}),h={front:f("front"),rear:f("rear")},b=g=>({arms:{lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},halfTrack:{front:e.trackFront/2e3,rear:e.trackRear/2e3},ayDir:Math.sign(g)});return{limitAt:(g,y,x,R=0)=>{let v={FL:0,FR:0,RL:0,RR:0},S=Xe(e,g,0,a,0,y),A,F=I=>(A?.ax!==I&&(A={ax:I,loads:Xe(e,g,(I+R)/De,a,0,y)}),A.loads),w=Fm(I=>Is(x,F(I),S,c).short,-R,1),T=x,M={FL:0,FR:0,RL:0,RR:0},k,C=I=>{let N=w.at(I);v=F(N),T=Is(x,v,S,c).util;let O={FL:0,FR:0,RL:0,RR:0};M=O;let V=0,H=n.diffYaw?{fx:{FL:0,FR:0,RL:0,RR:0},axles:[]}:null;for(let U of i){let G=l[Wn(U)];if(G){if(nl(U)){let W=d(Wn(U),G,v,T);V+=W.full,O[W.l]=O[W.r]=W.full/2,H&&(H.fx[W.l]=H.fx[W.r]=W.full/2,H.axles.push(W.asHeld()))}continue}let B=Math.max(0,v[U]),q=c(Wn(U),B),re=lr(Te(t,Wn(U)),B,T[U]*q.fyPeak,!1,q);V+=re,O[U]=re,H&&(H.fx[U]=re)}if(H){let U={};for(let G of jt){let B=Math.max(0,v[G]);U[G]={Fz:B,Fy:T[G]*c(Wn(G),B).fyPeak,Fx:H.fx[G]}}for(let G of H.axles){let B=Um(G,U,h,b(g))-G.full;V+=B;let[q,re]=G.axle==="front"?["FL","FR"]:["RL","RR"];O[q]+=B/2,O[re]+=B/2}}if(k)for(let U of k){let G=0;for(let B of U.wheels)G+=O[B];G>U.cap&&(V-=G-U.cap)}return V/s},P=()=>{let I=fA(C,-R,ko).fx,N=w.edge();return N!==void 0&&I>N&&(I=N,C(I)),{ax:I,loads:v,wheels:M}},L=P(),E=n.motorCaps;if(!E)return L;if(!E.some(I=>I.wheels.reduce((N,O)=>N+L.wheels[O],0)>I.cap))return{...L,held:L.ax};k=E;let D=P();return{...L,held:D.ax,heldWheels:D.wheels}}}}var Ad=.05,KA=.001,HA=16,Pd=8;function N0(e,t,r,n){let o=Math.max(Pd,r),a=n.nSteer??7,s=e.tv?.enabled?F0(e,t,o,n.steerMaxDeg):0,i=B=>{let q=C0(e,o,B,s);return q===0?void 0:{axG:0,tvRearDiffN:q}},c=n.yawDemandCn??0,l={op:i,yawDemandCn:c,...n.steerMaxDeg!==void 0?{steerMaxDeg:n.steerMaxDeg}:{}},u=ua(e,t,o,l),m=B=>{let q={},re={};for(let W of jt)q[W]=B.wheels[W].slipDeg*he,re[W]=Math.min(1,B.wheels[W].gripUtil);return{steerDeg:B.steerDeg,ayMs:Math.max(0,B.ay*De),ayG:B.ay,slip:q,util:re,scrub:B.ay>0?eV(B,e.massTotal):0}},p=null,d=B=>{if(p&&B===p.steerDeg)return m(p);let q=WO(e,t,o,u,B,l);if(q)return m(q);let re=u.states[0];for(let W of u.states)W.steerDeg<=B&&(re=W);return m(re)},f=u.peak.driving&&u.peak.ay>0?QA(e,t,o,u,l):null,h=f?Math.max(0,f.ay*De):0,b=f?[...u.states.filter(B=>B.steerDeg<f.steerDeg),f]:u.states,g=f?b.findIndex(B=>B.ay*De>=.995*h):0,y=b[g].steerDeg,{fold:x}=u;if(f&&x&&u.peak===x.state){let B=.995*h/De,q=u.states.indexOf(x.stall),re=q-1;for(;re>0&&u.states[re].beta===x.stall.beta;)re--;let W=Math.sign(x.stall.beta-u.states[re].beta),z=q;for(;z>0&&u.states[z].ay>=B&&Math.sign(u.states[z].beta-u.states[z-1].beta)!==-W;)z--;u.states[z].ay<B&&(p=P0(e,t,o,x,l,{ayG:B},u.states.slice(z,q+1)))}if(p)y=p.steerDeg;else if(g>0){let B=b[g-1].steerDeg,q=y;for(let re=0;re<8&&q-B>.001;re++){let W=.5*(B+q);d(W).ayMs>=.995*h?q=W:B=W}y=q}let R=[];for(let B=0;B<(h>0?a:1);B++){let q=B/(a-1);R.push(d(y*(q+Math.sin(Math.PI/2*q))/2))}R[0].ayMs=0;let v=[],S=[],A=[],F=[],w=[],T=zn(e,t,o,void 0,n.diffYaw===!0),M=JO(e,t,o,n,T),k=n.axDrag??0,C=B=>{let q=T.limitAt(B.ayMs/De,B.steerDeg,B.util,k+B.scrub);return{axD:q.edge!==void 0&&q.edge>0?q.edge:q.ax,locked:q.axUnlocked-q.ax>Ad}},P=B=>{let q=M.limitAt(B.ayMs/De,B.steerDeg,B.util,k+B.scrub);return{axA:q.ax,wA:{wheels:q.wheels,held:q.held??q.ax,...q.heldWheels?{heldWheels:q.heldWheels}:{}}}},L=R.map(B=>({p:B,...P(B),...C(B)})),E=[];for(let B=0;B+1<L.length;B++){let q=L[B],re=L[B+1],W=[];q.locked!==re.locked?W.push({read:C,past:z=>z.locked===re.locked,braking:!0}):(re.axA>q.axA+Ad&&W.push({read:P,past:z=>(z.axA??-1/0)>q.axA}),-re.axD>-q.axD+Ad&&W.push({read:C,past:z=>-(z.axD??0)>-q.axD}));for(let{read:z,past:Y,braking:te}of W){let j=q.p.steerDeg,X=re.p.steerDeg,le=null,pe=q.axD,ue=re.axD;for(let ie=0;ie<HA&&X-j>KA&&!(te&&Math.abs(ue-pe)<=Ad);ie++){let ke=.5*(j+X),Ie=d(ke),Ke=z(Ie);Y(Ke)?(X=ke,le={p:Ie,r:Ke},ue=Ke.axD??ue):(j=ke,pe=Ke.axD??pe)}if(le){let{p:ie,r:ke}=le,Ie=ke.axD!==void 0&&ke.locked!==void 0?{axD:ke.axD,locked:ke.locked}:C(ie),Ke=ke.axA!==void 0&&ke.wA!==void 0?{axA:ke.axA,wA:ke.wA}:P(ie);E.push({p:ie,...Ke,...Ie})}}}L.push(...E),L.sort((B,q)=>B.p.steerDeg-q.p.steerDeg);let _=B=>B.axA+k+B.p.scrub,D=.001*Math.max(1,R[R.length-1].ayMs),I=[];for(let B=0;B+1<L.length;B++){let q=L[B],re=L[B+1];if(!(_(q)>=0&&_(re)<0))continue;let W=q.p.steerDeg,z=re.p.steerDeg,Y=null,te=null;for(let le=0;le<HA&&z-W>KA;le++){let pe=.5*(W+z),ue=d(pe),ie=P(ue);_({p:ue,axA:ie.axA})>=0?(W=pe,Y={p:ue,wA:ie.wA}):(z=pe,te={p:ue,wA:ie.wA})}let j=Y??te,X=j?.p;if(j&&X&&X.ayMs>q.p.ayMs&&X.ayMs<re.p.ayMs){let le=-(k+X.scrub);I.push({p:X,axA:le,wA:{wheels:j.wA.wheels,held:Math.min(j.wA.held,le)},steady:!0,...C(X)})}}L.push(...I),L.sort((B,q)=>B.p.steerDeg-q.p.steerDeg);let N=!1;for(let{p:B,axA:q,wA:re,axD:W,steady:z}of L){let Y=v.length-1,te=Y>=0&&(z||N?!(B.ayMs>v[Y]):B.ayMs-v[Y]<D);N=z===!0&&!te,te?(q>S[Y]&&(A[Y]=re),S[Y]=Math.max(S[Y],q),F[Y]=Math.min(F[Y],W)):(v.push(B.ayMs),S.push(q),A.push(re),F.push(W),w.push(B.scrub))}for(let B=v.length-2;B>=0;B--)S[B+1]>S[B]&&(A[B]=A[B+1]),S[B]=Math.max(S[B],S[B+1]),F[B]=Math.min(F[B],F[B+1]);let O=v[v.length-1],V=e.massTotal,H=A.map(({wheels:B})=>({FL:B.FL/V,FR:B.FR/V,RL:B.RL/V,RR:B.RR/V})),U=B=>B?{FL:B.FL/V,FR:B.FR/V,RL:B.RL/V,RR:B.RR/V}:void 0,G=n.motorCaps?{axAccelHeld:A.map(B=>B.held),axAccelWheelsHeld:A.map(B=>U(B.heldWheels))}:{};return{ayMax:O,ay:v,axAccel:S,axAccelWheels:H,...G,axDecel:F,axScrub:w,rollover:u.rollover,atLock:f!==null&&ZA(e,f.steerDeg)}}function eV(e,t){let r=e.beta*he,n=0;for(let o of jt){let a=e.wheels[o],s=a.steerDeg*he-r;n+=a.Fx*(Math.cos(s)-1)-a.Fy*Math.sin(s)}return n/t}var Pee=Math.PI/180,Lee={speeds:Array.from({length:23},(e,t)=>8+t),steerMaxDeg:14,steerSteps:29};function ew(e=150,t=300,r=18,n=25){return(o,a,s)=>{let i=Math.min(1,Math.max(0,(o-r)/(n-r))),c=s>0?Math.min(1,a/s):0;return(e+i*(t-e))*c}}var Js={enabled:!1,kp:3e3,ffLow:150,ffHigh:300,vLow:18,vHigh:25},JA=e=>ew(e.ffLow,e.ffHigh,e.vLow,e.vHigh);var ln={power_limit_kw:{value:0,label:"battery power limit (0 = none)",unit:"kW"},v_limit_endurance:{value:0,label:"endurance speed limit (0 = none)",unit:"km/h"},endurance_reserve:{value:0,label:"endurance energy reserve (0 = flat out)",unit:"%"},grip_scale:{value:1,label:"grip scale (rig \u2192 road)",unit:"-"},stiffness_scale:{value:1,label:"stiffness scale (rig \u2192 road)",unit:"-"},camber_front_deg:{value:0,label:"static camber front (\u2212 top in)",unit:"\xB0"},camber_rear_deg:{value:0,label:"static camber rear (\u2212 top in)",unit:"\xB0"},cg_height:{value:300,label:"CG height",unit:"mm"},tire_vertical_rate:{value:100,label:"tyre vertical rate",unit:"N/mm"},tire_vertical_damping:{value:0,label:"tyre vertical damping",unit:"N\xB7s/mm"},arb_front:{value:20,label:"ARB front (@wheel)",unit:"N/mm"},arb_rear:{value:15,label:"ARB rear (@wheel)",unit:"N/mm"},heave_spring_front:{value:0,label:"Heave spring front (@wheel)",unit:"N/mm"},heave_spring_rear:{value:0,label:"Heave spring rear (@wheel)",unit:"N/mm"},unsprung_mass:{value:8,label:"unsprung mass/corner",unit:"kg"},brake_balance:{value:.6,label:"brake balance (front)",unit:"-"},damper_front:{value:2.5,label:"damper front",unit:"N\xB7s/mm"},damper_rear:{value:2.5,label:"damper rear",unit:"N\xB7s/mm"},cop_long:{value:.5,label:"CoP aft of front",unit:"\xB7wb"},cop_height:{value:300,label:"CoP height",unit:"mm"},ride_height_front:{value:30,label:"static ride height front (laden)",unit:"mm"},ride_height_rear:{value:35,label:"static ride height rear (laden)",unit:"mm"},I_yaw:{value:295,label:"yaw inertia Izz",unit:"kg\xB7m\xB2"},I_roll:{value:95,label:"roll inertia Ixx",unit:"kg\xB7m\xB2"},I_pitch:{value:380,label:"pitch inertia Iyy",unit:"kg\xB7m\xB2"},chassis_torsion:{value:0,label:"chassis torsional stiffness (0 = rigid)",unit:"N\xB7m/\xB0"},I_twist_front:{value:0,label:"twist inertia, front end (0 = lumped)",unit:"kg\xB7m\xB2"},I_twist_rear:{value:0,label:"twist inertia, rear end (0 = lumped)",unit:"kg\xB7m\xB2"},I_wheel:{value:0,label:"rotating inertia per wheel",unit:"kg\xB7m\xB2"},I_rotor:{value:0,label:"driveline inertia at the motor",unit:"kg\xB7m\xB2"},ackermann_pct:{value:50,label:"Ackermann",unit:"%"},toe_front_deg:{value:0,label:"static toe front (+ in)",unit:"\xB0"},toe_rear_deg:{value:0,label:"static toe rear (+ in)",unit:"\xB0"},spring_front:{value:35,label:"spring front (@spring)",unit:"N/mm"},spring_rear:{value:40,label:"spring rear (@spring)",unit:"N/mm"},mr_front:{value:1,label:"motion ratio front",unit:"-"},mr_rear:{value:1,label:"motion ratio rear",unit:"-"},track_front:{value:1200,label:"track front",unit:"mm"},track_rear:{value:1200,label:"track rear",unit:"mm"},wheelbase:{value:1535,label:"wheelbase",unit:"mm"},rc_front:{value:30,label:"roll centre front",unit:"mm"},rc_rear:{value:40,label:"roll centre rear",unit:"mm"},tv_enabled:{value:0,label:"torque vectoring",unit:"0/1"},tv_kp:{value:3e3,label:"TV yaw-rate gain",unit:"N per rad/s"},tv_ff_low:{value:150,label:"TV feedforward, low speed",unit:"N"},tv_ff_high:{value:300,label:"TV feedforward, high speed",unit:"N"},tv_v_low:{value:18,label:"TV feedforward ramp start",unit:"m/s"},tv_v_high:{value:25,label:"TV feedforward ramp end",unit:"m/s"}},tV=["k_yaw","k_roll","k_pitch"];function sl(e){for(let t of tV)delete e[t];for(let t of Object.keys(ln)){let r=e[t];if(!r){e[t]={...ln[t]};continue}e[t]={...r,label:ln[t].label,unit:ln[t].unit}}return e}function J(e,t){return e[t]?.value??ln[t].value}function da(e){let t=J(e,"chassis_torsion");return t>0&&Number.isFinite(t)?t:void 0}function il(e,t){if(da(e)===void 0)return;let r=J(e,t==="front"?"I_twist_front":"I_twist_rear");return r>0&&Number.isFinite(r)?r:void 0}function Ld(e){let t=(r,n)=>e[r]?.value??n;return{enabled:t("tv_enabled",0)>=.5,kp:t("tv_kp",Js.kp),ffLow:t("tv_ff_low",Js.ffLow),ffHigh:t("tv_ff_high",Js.ffHigh),vLow:t("tv_v_low",Js.vLow),vHigh:t("tv_v_high",Js.vHigh)}}var tw=[10,25,50,100,200,300];function O0(e,t,r,n,o){let s=tw.map(i=>Math.round(i<=25?r*i:r*25+n*(i-25)));return{id:e,label:t,speedMmS:[...tw],reboundN:s,bumpN:s.map(i=>Math.round(i*o))}}var Dd={name:"Generic FS damper",curves:[O0("c1","Soft",1.6,1,.65),O0("c2","Medium",3,1.6,.65),O0("c3","Firm",8,2.4,.65)]};function Ed(e){let t=e.curves.length;return t>0?e.curves[Math.floor((t-1)/2)].id:""}var Ao=25;function ei(e,t){let r=e.speedMmS,n=e.forceN,o=Math.min(r.length,n.length);if(o===0||!(t>0))return 0;let a=0,s=0;for(let i=0;i<o;i++){let c=r[i],l=n[i];if(t<=c)return s+(l-s)*(t-a)/(c-a);if(i===o-1)return l+Math.max(0,(l-s)/(c-a))*(t-c);a=c,s=l}return 0}function rw(e,t){return t>=0?ei(e.rebound,t):-ei(e.bump,-t)}function nw(e,t,r){return t*rw(e,t*r)}var V0=(e,t)=>e.curves.find(r=>r.id===t);function cl(e,t){let r=V0(e,Ed(e)),n=(t&&V0(e,t.bump))??r,o=(t&&V0(e,t.rebound))??r;return{bump:{speedMmS:n?.speedMmS??[],forceN:n?.bumpN??[]},rebound:{speedMmS:o?.speedMmS??[],forceN:o?.reboundN??[]}}}var Id=5e3;function ll(e,t){let r=t>0?t:1,n=[],o=[],a=e.bump.speedMmS.map(c=>c/r).filter(c=>c<Id),s=e.rebound.speedMmS.map(c=>c/r).filter(c=>c<Id),i=c=>{n.push(c),o.push(nw(e,r,c))};i(-Id);for(let c=a.length-1;c>=0;c--)i(-a[c]);i(0);for(let c of s)i(c);return i(Id),{kind:"map",input:"velocity",x:n,y:o}}var B0=64;function ul(e,t,r){let n=t>0?t:1,o=Math.max(r,1e-6),a=0;for(let s=0;s<B0;s++){let i=Math.sin((s+.5)*Math.PI/B0),c=n*o*i;a+=n*(ei(e.rebound,c)+ei(e.bump,c))*i}return a*(Math.PI/B0)/(Math.PI*o)}function pa(e,t,r,n,o=e){let a=(c,l,u)=>{if(!c||c.curves.length===0)return;let m=cl(c,l);return{law:m,curve:ll(m,u),rate:ul(m,u,Ao)}},s=a(e,t?.front,r),i=a(o??e,t?.rear,n);return!s&&!i?null:{...s?{front:s}:{},...i?{rear:i}:{}}}var ow=(e,t)=>({...e,y:e.y.map(r=>r*t)}),rV=e=>({...e,x:e.x.map(t=>-t).reverse(),y:e.y.map(t=>-t).reverse()});function $0(e,t,r){let n=Math.abs(r)>0?Math.abs(r):1,o=cl(e,t);return{law:o,curve:ow(ll(o,n),.5),rate:ul(o,n,Ao)/2,mr:n,ratio:n,share:.5}}function G0(e,t,r,n,o){let a=n*(Math.abs(r)>0?Math.abs(r):1),s=cl(e,t),i=ow(ll(s,a),1/n);return{law:s,curve:o?rV(i):i,rate:ul(s,a,Ao)/n,mr:a/n,ratio:a,share:1/n}}function ml(e,t){let r=e.damperModelIdRear?t(e.damperModelIdRear):void 0,n=e.heaveDamperModelId?t(e.heaveDamperModelId):void 0,o=e.rollDamperModelId?t(e.rollDamperModelId):void 0;return{...r?{damperModelRear:r}:{},...n?{heaveDamperModel:n}:{},...o?{rollDamperModel:o}:{}}}var _d=["front","rear","heaveFront","heaveRear","rollFront","rollRear"];function dl(e,t){if(t?.body){let{extended:n,stroke:o,...a}=e??{},{extended:s,stroke:i}=t.body;return{coilover:{...a,extended:s,...i!==void 0?{stroke:i}:{}},source:"part",part:t}}let r=e?.extended!==void 0&&e.extended>0;return{...e?{coilover:e}:{},source:r?"suspension":"none"}}function Un(e,t){if(typeof e=="number")return e;let{x:r,y:n}=e,o=r.length;if(o===0)return 0;if(o===1||t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=0,s=o-1;for(;s-a>1;){let c=a+s>>1;r[c]<=t?a=c:s=c}let i=(t-r[a])/(r[s]-r[a]);return n[a]+i*(n[s]-n[a])}function fl(e){return e.kind==="coil"?2:1}function pl(e){let t=Math.max(0,e.od),r=Math.max(0,Math.min(e.id,t));return Math.PI*(t**4-r**4)/32}function sw(e){return pl(e)/2}function iw(e){let t=Math.max(0,e.width),r=Math.max(0,e.thickness),n=t*r**3/12,o=r*t**3/12,a=e.angleDeg*Math.PI/180;return n*Math.cos(a)**2+o*Math.sin(a)**2}function aw(e){let t=0;for(let r of e)if(Number.isFinite(r)){if(r<=0)return 0;t+=1/r}return t>0?1/t:1/0}function nV(e,t,r){let n=Math.min(e.length,t.length);if(n<2)return 0;let o=Math.abs(r);if(o<=e[0])return(t[1]-t[0])/(e[1]-e[0]);for(let a=1;a<n;a++)if(o<=e[a])return(t[a]-t[a-1])/(e[a]-e[a-1]);return(t[n-1]-t[n-2])/(e[n-1]-e[n-2])}function hl(e,t=0){let r={rateAtLink:0,contributions:{},torsional:0};switch(e.kind){case"none":return r;case"ubar":{let n=e.armLength;if(n<=0||e.barLength<=0)return r;let o=e.G*pl(e.section)/e.barLength,a=2*o/(n*n),s=sw(e.armSection??e.section),i=3*e.E*s/n**3,c=e.dropLinkRate??1/0;return{rateAtLink:aw([a,i,c]),contributions:{barTwist:a,armBending:i,dropLink:c},torsional:o}}case"blade":{let n=e.armLength;if(n<=0||e.barLength<=0)return r;let o=e.G*pl(e.section)/e.barLength,a=2*o/(n*n),s=3*e.E*iw(e.blade)/n**3,i=e.dropLinkRate??1/0;return{rateAtLink:aw([a,s,i]),contributions:{barTwist:a,armBending:s,dropLink:i},torsional:o}}case"torsionTube":{let n=e.leverArm;if(n<=0||e.length<=0)return r;let o=e.G*pl(e.section)/e.length,a=2*o/(n*n);return{rateAtLink:a,contributions:{barTwist:a},torsional:o}}case"coil":{let n=Un(e.rate,2*Math.abs(t)),o=2*Math.max(0,n);return{rateAtLink:o,contributions:{spring:o},torsional:0}}case"direct":return{rateAtLink:e.wheelRate,contributions:{},torsional:0};case"tabulated":{let n=nV(e.linkTravel,e.force,t);return{rateAtLink:Math.max(0,n),contributions:{},torsional:0}}}}function fa(e,t,r=0){if(e.kind==="none")return{wheelRate:0,motionRatio:0,rateAtLink:0};if(e.kind==="direct")return{wheelRate:Math.max(0,e.wheelRate),motionRatio:1,rateAtLink:0};let n=t?wb(t,r):1,o=t?Fb(t,r):0,a=hl(e,o).rateAtLink;return{wheelRate:Math.max(0,a*n*n),motionRatio:n,rateAtLink:a}}function bl(e,t){let r=e.damper??0;return!r||e.design.kind==="none"?0:fl(e.design)*r*t*t}var cw=150;function oV(e){return Z(e,[0,-.5,1])<-1e-9?Q(e,-1):e}function lw(e){let t=e.hardpoints,r=$(t.rockerPivotB,t.rockerPivotA),n=ne(t.rockerPivotA,Q($(t.rockerToDamper,t.rockerPivotA),.6)),o=oV(ee(me(r,$(t.rockerToDamper,t.rockerPivotA))));return{outer:n,inner:ne(n,Q(o,cw)),attach:"rocker"}}function uw(e){let t=e.hardpoints,r=$(t.lcaRear,t.lcaFront),n=ne(t.lcaFront,Q($(t.uprightLower,t.lcaFront),.6)),o=ee(me(r,$(n,t.lcaFront))),a=o[2]<0?Q(o,-1):o;return{outer:n,inner:ne(n,Q(a,cw)),attach:"lowerArm"}}function mw(e,t,r,n){let o=$(r,t),a=Zr(o);if(a<1e-9)return[...t];let s=Q(o,1/a),i=uk(t,r,.5),c=s[0]<0?-1:1,l=n!==void 0?n*c:Z($(Ln(e,t,s),i),s),u=Math.max(-a/2,Math.min(a/2,l));return ne(i,Q(s,u))}function K0(e){switch(e.kind){case"ubar":case"blade":return e.armLength;case"torsionTube":return e.leverArm;default:return}}var z0=[0,1,0];function H0(e,t,r){let n=$(r,t),o=Z(n,n);if(o<1e-12)return[...t];let a=Math.max(0,Math.min(1,Z($(e,t),n)/o));return ne(t,Q(n,a))}var aV=(e,t,r)=>Le(e,t)<=Le(e,r)?t:r,sV=2;function iV(e,t,r){let n=r.geometry,o;switch(e.attach){case"rocker":o=mw(t,n.rockerPivotA,n.rockerPivotB,e.shaftStationOuter);break;case"lowerArm":o=aV(t,H0(t,n.lcaFront,n.uprightLower),H0(t,n.lcaRear,n.uprightLower));break;case"upright":o=H0(t,n.uprightLower,n.mcpherson?n.pushrodOuter:n.uprightUpper);break}return Le(o,t)>sV?o:void 0}function cV(e,t){let r=me(z0,e),n=t?-1:1;if(Zr(r)<1e-6)return[n,0,0];let o=ee(r);return(Math.abs(o[0])>.5?o[0]*n<0:o[2]>0)?Q(o,-1):o}function dw(e,t,r,n){let o=e.linkage,a=r.placement,s=st(Ne(t,o,r.state),a),i=st(o.outer,a),c=st(o.inner,a),l=ee($(i,c)),u=Z($(s,i),l),m=cV(l,a.isFront),p=ne(c,Q(m,n)),d=Z(me(z0,Q(m,-1)),l),f=n>0&&Math.abs(d)>1e-9?u/(n*d):0,h=ne(p,ir($(c,p),z0,f)),b=iV(o,s,r);return{outer:s,...b?{mount:b}:{},tip:h,root:p,linkTravel:u,twist:f}}function hr(e,t){let r={};for(let o of en)r[o]=Tt(Je(e,o));let n={vehicle:e,ctx:r};return t&&(n.kc=vm(n,t)),n}function lV(e,t,r,n){let o=e.corner.hardpoints,a=Rs(e.rocker,t.points.rockerAngle),s=i=>st(i,r);return{ucaFront:s(o.ucaFront),ucaRear:s(o.ucaRear),lcaFront:s(o.lcaFront),lcaRear:s(o.lcaRear),tieInner:s(Ho(e.inv,t.steer)),rockerPivotA:s(o.rockerPivotA),rockerPivotB:s(o.rockerPivotB),damperChassis:s(e.inv.strut?t.points.uprightUpper:o.damperChassis),uprightUpper:s(t.points.uprightUpper),uprightLower:s(t.points.uprightLower),tieOuter:s(t.points.tieOuter),wheelCenter:s(t.points.wheelCenter),pushrodOuter:s(t.points.pushrodOuter),contactPatch:s(t.points.contactPatch),kingpinGround:s(t.points.kingpinGround),kingpinAtHub:s(t.points.kingpinAtHub),rockerToPushrod:s(a.pushrod),rockerToDamper:s(a.damper),spinAxis:Dn(t.points.spinAxis,r),direct:e.corner.config.actuation==="direct",decoupled:e.corner.config.actuation==="decoupled",mcpherson:e.inv.strut!==void 0,loadedRadius:n.loadedRadius,tyreDeflection:n.tyreDeflection,load:n.load,lifted:n.lifted,clearance:n.clearance??0,contactLength:n.contactLength}}function Nd(e,t,r,n){let o=Ue(t,e.vehicle.config),a=o.isFront?o.sideSign*n:0,s;try{s=zt(Ce(e.ctx[t],r,a))}catch{return null}if(!s)return null;let i=Je(e.vehicle,t).config.loadedRadius,c=lV(e.ctx[t],s,o,{loadedRadius:i,tyreDeflection:0,load:NaN,lifted:!1,contactLength:0});return c.wheelCenter.every(Number.isFinite)?{id:t,placement:o,solved:!0,state:s,geometry:c}:null}var Od=.5;function uV(e,t){let r=([i,c,l])=>{let u=ee($(c,i)),m=$(l,i),p=ee($(m,Q(u,Z(m,u))));return[u,p,me(u,p)]},n=r(e),o=r(t),a=[0,1,2].map(i=>[0,1,2].map(c=>o[0][i]*n[0][c]+o[1][i]*n[1][c]+o[2][i]*n[2][c]));return{rot:a,move:i=>{let c=$(i,e[0]);return ne(t[0],[0,1,2].map(l=>a[l][0]*c[0]+a[l][1]*c[1]+a[l][2]*c[2]))}}}var pw=e=>[(e[2][1]-e[1][2])/2,(e[0][2]-e[2][0])/2,(e[1][0]-e[0][1])/2];function Vd(e,t,r){let n=Ue(t,e.vehicle.config),o=e.ctx[t],a=r.rigid?void 0:{loadedRadius:r.loadedRadius},s=r.state?null:Ce(o,r.travel,r.steer,void 0,a),i=r.state??Nt(s),c=Ce(o,r.travel+Od,r.steer,void 0,a),l=Ce(o,r.travel-Od,r.steer,void 0,a),u=(s?s.ok:r.converged)&&c.ok&&l.ok,m=Nt(c),p=Nt(l),d=(T,M)=>st(T.points[M],n),f=o.inv.strut?"pushrodOuter":"uprightUpper",h=d(i,f),b=d(i,"uprightLower"),g=T=>{let M=$(b,h);return Math.hypot(...me(M,$(d(i,T),h)))/Math.hypot(...M)},y=g("tieOuter")>=g("wheelCenter")?"tieOuter":"wheelCenter",x=[h,b,d(i,y)],R=T=>uV(x,[d(T,f),d(T,"uprightLower"),d(T,y)]),v=R(m),S=R(p),A=pw(v.rot),F=pw(S.rot),w=[NaN,NaN,NaN];return{solved:u,state:i,at:T=>d(i,T),velocity:T=>u?Q($(v.move(T),S.move(T)),1/(2*Od)):w,omega:u?Q($(A,F),1/(2*Od)):w}}function Bd(e,t,r,n){let o=t[0]*-n[1]-t[1]*-n[0];if(Math.abs(o)<1e-9)return null;let a=r[0]-e[0],s=r[1]-e[1],i=(a*-n[1]-s*-n[0])/o;return[e[0]+i*t[0],e[1]+i*t[1]]}function fw(e,t,r){let n=Vd(e,t,Zt(e,r)[t]),o=n.at("contactPatch"),a=n.velocity(o);return{solved:n.solved,cp:[o[1],o[2]],vCp:[a[1],a[2]],wx:n.omega[0]}}function hw(e){let t=Math.hypot(e.vCp[0],e.vCp[1]);return Math.abs(e.wx)*1e9>t?[e.cp[0]-e.vCp[1]/e.wx,e.cp[1]+e.vCp[0]/e.wx]:null}function bw(e,t){let r=Math.hypot(e.vCp[0],e.vCp[1]);if(!(r>1e-9))return null;let n=[-e.vCp[1]/r,e.vCp[0]/r],o=t?[t[0]-e.cp[0],t[1]-e.cp[1]]:[e.cp[0]>0?-1:1,0];return n[0]*o[0]+n[1]*o[1]<0?[-n[0],-n[1]]:n}function mV(e,t,r){return Math.abs(t[0]*(r[1]-e[1])-t[1]*(r[0]-e[0]))<=1e-6*Math.max(1,Math.hypot(r[0]-e[0],r[1]-e[1]))?[(e[0]+r[0])/2,(e[1]+r[1])/2]:null}var dV=.1*Math.PI/180;function Y0(e,t,r,n,o){return Math.max(Math.hypot(e[0]-t[0],e[1]-t[1]),Math.hypot(e[0]-r[0],e[1]-r[1]))*dV<=o*n}function $d(e,t){return!e.valid||!e.cpLeft||!e.cpRight?!1:Y0([e.lateral,e.height],e.cpLeft,e.cpRight,e.sinAngle,t)}function ti(e){let t=(o,a,s)=>{let i=o&&a?[a[0]-o[0],a[1]-o[1]]:s;return!o||!i||!(Math.abs(i[0])>1e-9)?Number.NaN:o[1]-o[0]*i[1]/i[0]},r=t(e.cpLeft,e.icLeft,e.lineLeft),n=t(e.cpRight,e.icRight,e.lineRight);return Number.isFinite(r)&&Number.isFinite(n)?{left:r,right:n}:null}function ri(e){let t=ti(e);if(!t||!e.cpLeft||!e.cpRight)return null;let r=(t.left+t.right)/2,n=e.cpRight[0]-e.cpLeft[0],o=e.cpRight[1]-e.cpLeft[1],a=Math.hypot(n,o)||1;return{height:r,heightAboveGround:(0-e.cpLeft[0])*(-o/a)+(r-e.cpLeft[1])*(n/a)}}var pV=1;function gw(e){let t=ti(e);return!t||Math.abs(t.left-t.right)>pV?null:ri(e)}function ni(e){let t=(n,o,a)=>{if(!n)return Number.NaN;if(!o)return a?0:Number.NaN;let s=n[0]-o[0];return Math.abs(s)>1e-9?n[0]/s:Number.NaN},r=(t(e.cpLeft,e.icLeft,e.lineLeft)+t(e.cpRight,e.icRight,e.lineRight))/2;return e.valid&&Number.isFinite(r)?r:0}function Hr(e,t,r){let n=r==="front"?"FL":"RL",o=r==="front"?"FR":"RR",a=fw(e,n,t),s=fw(e,o,t);if(!a.solved||!s.solved)return{height:0,lateral:0,heightAboveGround:0,lateralAlongGround:0,valid:!1,unsolved:!0,icLeft:null,icRight:null,lineLeft:null,lineRight:null,sinAngle:0,cpLeft:a.cp,cpRight:s.cp};let i=hw(a),c=hw(s),l=bw(a,i),u=bw(s,c),m={height:0,lateral:0,heightAboveGround:0,lateralAlongGround:0,valid:!1,icLeft:i,icRight:c,lineLeft:l,lineRight:u,sinAngle:0,cpLeft:a.cp,cpRight:s.cp};if(!l||!u)return m;let p=i?[i[0]-a.cp[0],i[1]-a.cp[1]]:l,d=c?[c[0]-s.cp[0],c[1]-s.cp[1]]:u,f=Math.hypot(p[0],p[1]),h=Math.hypot(d[0],d[1]),b=f>0&&h>0?Math.abs(p[0]*d[1]-p[1]*d[0])/(f*h):0,g=Bd(a.cp,p,s.cp,d)??mV(a.cp,l,s.cp);if(!g)return{...m,sinAngle:b};let y=s.cp[0]-a.cp[0],x=s.cp[1]-a.cp[1],R=Math.hypot(y,x)||1,v=y/R,S=x/R,A=(a.cp[0]+s.cp[0])/2,F=(a.cp[1]+s.cp[1])/2,w=(g[0]-a.cp[0])*-S+(g[1]-a.cp[1])*v,T=(g[0]-A)*v+(g[1]-F)*S;return{lateral:g[0],height:g[1],heightAboveGround:w,lateralAlongGround:T,valid:!0,icLeft:i,icRight:c,lineLeft:l,lineRight:u,sinAngle:b,cpLeft:a.cp,cpRight:s.cp}}function Xn(e,t){return{front:Hr(e,t,"front"),rear:Hr(e,t,"rear")}}function Gd(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function fV(e,t){return{camber:Gd(e.travel,e.camber,t),toe:Gd(e.travel,e.toe,t),motionRatio:Gd(e.travel,e.motionRatio,t),damperLen:e.damperLen?Gd(e.travel,e.damperLen,t):0}}var yw=e=>fV(e,0).motionRatio;function W0(e,t){if(e.kind!=="coil")return null;let r=t??e.motionRatio,n=Un(e.rate,0)*r*r/2;return n>0&&Number.isFinite(n)?{rate:n,gap:Math.max(0,e.gap??0),bothWays:!!e.bothWays}:null}function j0(e,t){if(e.kind==="none")return 0;if(e.kind==="tabulated"){let n=a=>hV(e,a);return(n(.5)-n(-.5))/(2*.5)/2}if((e.gap??0)>0)return 0;let r=t??e.motionRatio;return Un(e.rate,0)*r*r/2}function gl(e,t){let r=e.damper??0;if(!r||e.design.kind==="none"||e.design.kind==="coil"&&(e.design.gap??0)>0)return 0;let n=t??(e.design.kind==="coil"?e.design.motionRatio:1);return r*n*n/2}function hV(e,t){let{travel:r,force:n}=e,o=r.length;if(o===0)return 0;if(t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=0,s=o-1;for(;s-a>1;){let c=a+s>>1;r[c]<=t?a=c:s=c}let i=(t-r[a])/(r[s]-r[a]);return n[a]+i*(n[s]-n[a])}var U0={kind:"coil",rate:120,motionRatio:.7,gap:5,bothWays:!1};var xw=new WeakMap;function X0(e,t){let r=xw.get(e);r||(r=new Map,xw.set(e,r));let n=`${t.attach}|${t.outer.join(",")}|${JSON.stringify(t.mount??null)}`,o=r.get(n);if(o)return o;let a=Wo(e,t);return r.set(n,a),a}var gV=32,yl=new Map,Rw=new WeakMap,yV=1;function xV(e){let t=Rw.get(e);return t===void 0&&(t=yV++,Rw.set(e,t)),t}function Kd(e,t){if(!t.linkage)return null;let r=Br(e,t.linkage,t.design.kind),n=`${xV(e)}|${r?"unit":"bar"}|${JSON.stringify(t.linkage)}`,o=yl.get(n);if(o)return o;let a=zo(e,t.linkage,{kind:t.design.kind});return yl.size>=gV&&yl.delete(yl.keys().next().value),yl.set(n,a),a}var ha=e=>e!=null&&e.design.kind!=="none"&&e.design.kind!=="coil";function mn(e,t,r){if(!(!ha(r)||!un(e)||ha(t)))return r}var xl=(e,t,r)=>r==="front"?mn(e.front,t.arbFrontDesign,t.rollBarFrontDesign):mn(e.rear,t.arbRearDesign,t.rollBarRearDesign);function Rl(e,t,r=0){let n=(a,s)=>{if(a)return a.design.kind==="none"?0:fa(a.design,Kd(s,a),r).wheelRate},o=(a,s,i)=>{let c=n(s,a),l=n(mn(a,s,i),a);return{...c!==void 0?{element:c}:{},...l!==void 0?{bar:l}:{}}};return{front:o(e.front,t.arbFrontDesign,t.rollBarFrontDesign),rear:o(e.rear,t.arbRearDesign,t.rollBarRearDesign)}}function vl(e,t,r=0){let{front:n,rear:o}=Rl(e,t,r),a=s=>s.element===void 0&&s.bar===void 0?void 0:(s.element??0)+(s.bar??0);return{front:a(n),rear:a(o)}}function ba(e,t){let r=(n,o)=>{if(!n)return;if(n.design.kind==="none")return 0;let a=n.linkage?X0(o,n.linkage).atDesign:void 0;return j0(n.design,a)};return{front:r(t.heaveFrontDesign,e.front),rear:r(t.heaveRearDesign,e.rear)}}function Aw(e,t){let r=(a,s)=>{if(!a||a.design.kind!=="coil")return;let i=a.linkage?X0(s,a.linkage).atDesign:void 0;return W0(a.design,i)??void 0},n=r(t.heaveFrontDesign,e.front),o=r(t.heaveRearDesign,e.rear);return{...n?{front:n}:{},...o?{rear:o}:{}}}function Hd(e,t){let r=(o,a)=>o?gl(o,q0(o,a)):0,n=(o,a)=>o?bl(o,Q0(o,a)):0;return{heaveFront:r(t.heaveFrontDesign,e.front),heaveRear:r(t.heaveRearDesign,e.rear),rollFront:n(t.arbFrontDesign,e.front),rollRear:n(t.arbRearDesign,e.rear)}}var q0=(e,t)=>e.linkage?X0(t,e.linkage).atDesign:void 0,Q0=(e,t)=>fa(e.design,Kd(t,e),0).motionRatio;function ww(e,t){let r=t.damperSetup,n=t.heaveDamperModel??t.damperModel,o=t.rollDamperModel??t.damperModel,a=(p,d,f)=>{if(!p||!n?.curves.length)return;let h=q0(p,d);if(gl(p,h)>0)return $0(n,r?.[f],h??(p.design.kind==="coil"?p.design.motionRatio:1))},s=(p,d,f)=>{if(!p||!o?.curves.length)return;let h=Q0(p,d);if(!(bl(p,h)>0))return;let b=Kd(d,p)!==null;return G0(o,r?.[f],h,fl(p.design),b&&h>0)},i={},c=a(t.heaveFrontDesign,e.front,"heaveFront"),l=a(t.heaveRearDesign,e.rear,"heaveRear"),u=s(t.arbFrontDesign,e.front,"rollFront"),m=s(t.arbRearDesign,e.rear,"rollRear");return c&&(i.heaveFront=c),l&&(i.heaveRear=l),u&&(i.rollFront=u),m&&(i.rollRear=m),i}function zd(e,t){let r=t.heaveDamperModel??t.damperModel,n=t.rollDamperModel??t.damperModel,o=(i,c)=>un(i)?{source:"none"}:dl(i.config.coilover,c),a=(i,c)=>{if(!i)return{source:"none"};let l=gl(i,q0(i,c))>0;return dl(i.coilover,l?r:void 0)},s=(i,c)=>{if(!i||i.design.kind!=="coil")return{source:"none"};let l=bl(i,Q0(i,c))>0;return dl(i.coilover,l?n:void 0)};return{front:o(e.front,t.damperModel),rear:o(e.rear,t.damperModelRear??t.damperModel),heaveFront:a(t.heaveFrontDesign,e.front),heaveRear:a(t.heaveRearDesign,e.rear),rollFront:s(t.arbFrontDesign,e.front),rollRear:s(t.arbRearDesign,e.rear)}}function Fw(e,t){let r=o=>!!o?.linkage&&o.design.kind!=="none"&&o.design.kind!=="direct",n=(o,a,s,i)=>{let c={};o?.linkage&&o.design.kind==="coil"&&(c.heave=o.linkage),r(a)&&(c.roll=a.linkage,c.rollKind=a.design.kind);let l=s?mn(s,a,i):void 0;return s&&r(l)&&(!a||a.design.kind==="none"?(c.roll=l.linkage,c.rollKind=l.design.kind):c.bar={linkage:l.linkage,wheelRate:fa(l.design,Kd(s,l),0).wheelRate}),c.heave||c.roll||c.bar?c:void 0};return{front:n(e.heaveFrontDesign,e.arbFrontDesign,t?.front,e.rollBarFrontDesign),rear:n(e.heaveRearDesign,e.arbRearDesign,t?.rear,e.rollBarRearDesign)}}var un=e=>e.config.actuation==="decoupled",ga="a decoupled axle damps in its heave and roll elements, set below";function Cw(e,t,r={}){let n={...t},o=(p,d)=>{let f=n[p];f&&typeof f=="object"&&"value"in f&&(n[p]={...f,value:d})},{front:a,rear:s}=vl(e,t);a!==void 0&&o("arb_front",a),s!==void 0&&o("arb_rear",s);let i=ba(e,t);i.front!==void 0&&o("heave_spring_front",i.front),i.rear!==void 0&&o("heave_spring_rear",i.rear);let c=vV(e,t,r),l=RV(e,c);n.kinFront=l.kinFront,n.kinRear=l.kinRear;let u=SV(e,c);n.steerFront=l.steerFront,Number.isFinite(u.ackermannPct)&&o("ackermann_pct",u.ackermannPct);let m=p=>un(p)?0:p.measured?.springRate??p.config.springRate;o("spring_front",m(e.front)),o("spring_rear",m(e.rear));for(let[p,d]of[[e.front,"spring_front"],[e.rear,"spring_rear"]])un(p)&&(n.readouts={...n.readouts,[d]:"a decoupled axle has no corner spring; its heave and roll elements carry the car"});for(let[p,d]of[[e.front,"damper_front"],[e.rear,"damper_rear"]])un(p)&&(o(d,0),n.readouts={...n.readouts,[d]:ga});return o("mr_front",u.mrFront),o("mr_rear",u.mrRear),o("wheelbase",u.wheelbase),o("track_front",u.trackFront),o("track_rear",u.trackRear),o("rc_front",u.rcFront),o("rc_rear",u.rcRear),n.surveyedRadiusFront=e.front.config.loadedRadius,n.surveyedRadiusRear=e.rear.config.loadedRadius,n.rcRoad={radiusFront:e.front.config.loadedRadius,radiusRear:e.rear.config.loadedRadius,gainFront:u.rcGainFront,gainRear:u.rcGainRear},n}function RV(e,t){return{kinFront:kw(e.front),kinRear:kw(e.rear),steerFront:e.front.measured?void 0:Yd(e.front,t)}}var vw=new WeakMap;function kw(e){let t=vw.get(e);return t||vw.set(e,t=Vs(e)),t}function vV(e,t,r={}){return kV(e,t,r.front,r.rear)}function kV(e,t,r,n){let o=e.front.config.loadedRadius;if(!((an(r??t.tireModel)??0)>0))return o;let a={...t,surveyedRadiusFront:o,surveyedRadiusRear:e.rear.config.loadedRadius};return Wd(a,r,n).front??o}var Mw=new WeakMap;function Yd(e,t=e.config.loadedRadius){let r=Mw.get(e);r||(r=new Map,Mw.set(e,r));let n=r.get(t);if(n)return n;let o=t===e.config.loadedRadius?void 0:{loadedRadius:t},a=Wb(e,Ot(e.config),void 0,void 0,void 0,void 0,o);return r.size>=4&&r.clear(),r.set(t,a),a}var Sw=new WeakMap;function MV(e){return ut(e,{travelMin:-1,travelMax:1,steps:3}).samples[1].metrics.motionRatio??1}var oi=e=>e.measured?yw(e.measured):MV(e);function SV(e,t=e.front.config.loadedRadius){let r=()=>e.front.measured?void 0:Yd(e.front,t);return{...AV(e),get steerFront(){return r()},get ackermannPct(){let n=r();return n?jb(n,Qt(e.front),e.config.wheelbase):Number.NaN}}}function AV(e){let t=Sw.get(e);if(t)return t;let r=e.front.measured,n=e.rear.measured,a=!r||!n?Xn(hr(e),{heave:0,pitch:0,roll:0,steer:0}):null,s={wheelbase:e.config.wheelbase,trackFront:r?r.track:Qt(e.front),trackRear:n?n.track:Qt(e.rear),mrFront:oi(e.front),mrRear:oi(e.rear),rcFront:r?r.rollCentreHeight:a&&a.front.valid?a.front.heightAboveGround:0,rcRear:n?n.rollCentreHeight:a&&a.rear.valid?a.rear.heightAboveGround:0,rcGainFront:r||!a?0:ni(a.front),rcGainRear:n||!a?0:ni(a.rear),rcFrontValid:r?!0:!!a?.front.valid,rcRearValid:n?!0:!!a?.rear.valid};return Sw.set(e,s),s}var er={open:{kind:"open"},spool:{kind:"spool"},clutch:{kind:"clutch",preloadNm:30,rampDriveDeg:40,rampCoastDeg:50,faces:6,muClutch:.1,rFrictionMm:30.4,rRampMm:36},torsen:{kind:"torsen",tbrDrive:3,tbrCoast:3}},Lw=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),dn=(e,t,r,n=1/0)=>typeof e=="number"&&Number.isFinite(e)?Math.min(n,Math.max(r,e)):t;function ya(e){if(Lw(e))switch(e.kind){case"open":case"spool":return{kind:e.kind};case"clutch":{let t=er.clutch;return{kind:"clutch",preloadNm:dn(e.preloadNm,t.preloadNm,0),rampDriveDeg:dn(e.rampDriveDeg,t.rampDriveDeg,1,90),rampCoastDeg:dn(e.rampCoastDeg,t.rampCoastDeg,1,90),faces:Math.round(dn(e.faces,t.faces,0)),muClutch:dn(e.muClutch,t.muClutch,0,1),rFrictionMm:dn(e.rFrictionMm,t.rFrictionMm,1),rRampMm:dn(e.rRampMm,t.rRampMm,1)}}case"torsen":{let t=er.torsen,r=dn(e.preloadNm,0,0);return{kind:"torsen",tbrDrive:dn(e.tbrDrive,t.tbrDrive,1),tbrCoast:dn(e.tbrCoast,t.tbrCoast,1),...r>0?{preloadNm:r}:{}}}default:return}}function jd(e){if(!Lw(e))return;let t=ya(e.front),r=ya(e.rear);return t||r?{...t?{front:t}:{},...r?{rear:r}:{}}:void 0}function xa(e){let t=dr(e),r=n=>n>=2?"independent":n===1?"diff":"none";return{front:r(t.front),rear:r(t.rear)}}function kl(e){if(!e.driveline)return;let t=xa(e),r=e.r_dyn.value,n=s=>{if(t[s]!=="diff")return;let i=ya(e.driveline?.[s]);if(!(!i||i.kind==="independent"))return{kind:i.kind,drive:Qc(i,"drive",r),coast:Qc(i,"coast",r),hubs:Qc(i,"hubs",r)}},o=n("front"),a=n("rear");return o||a?{...o?{front:o}:{},...a?{rear:a}:{}}:void 0}var wV={kind:{label:"Differential"},preloadNm:{label:"Preload",unit:"N\xB7m"},rampDriveDeg:{label:"Drive ramp",unit:"\xB0"},rampCoastDeg:{label:"Coast ramp",unit:"\xB0"},faces:{label:"Friction faces"},muClutch:{label:"Clutch friction \u03BC"},rFrictionMm:{label:"Friction radius",unit:"mm"},rRampMm:{label:"Ramp radius",unit:"mm"},tbrDrive:{label:"Drive bias ratio",unit:": 1"},tbrCoast:{label:"Coast bias ratio",unit:": 1"}},Tw=e=>{let t=e==="front"?"Front":"Rear";return Object.fromEntries(Object.entries(wV).map(([r,n])=>[`${e}.${r}`,{section:t,...n}]))},Ud={...Tw("front"),...Tw("rear")},Pw=e=>e.motorModel?.kind==="ice"?e.motorPlacement==="front"?"front":"rear":null;function Dw(e,t){let r=Pw(t);if(!(!r||Pw(e)===r||t.driveline?.[r]))return{...t.driveline,[r]:{...er.clutch}}}function wr(e,t,r,n){return e>0?!(r>0)||!Number.isFinite(r)?e:Math.max(1,e-t/r):n}function Xd(e,t,r){let n=Math.max(0,Math.min(1,r)),o=wr(e.freeRadius,e.staticLoad,e.tyreRate,e.surveyed),a=wr(t.freeRadius,t.staticLoad,t.tyreRate,t.surveyed);return n*o+(1-n)*a}function ai(e,t,r){if(t===void 0||r===void 0||!Number.isFinite(t)||!Number.isFinite(r))return e;let n=r-t;return n===0?e:Math.max(1,e+n)}function qn(e,t,r,n){if(!t||r===void 0||n===void 0||!Number.isFinite(r)||!Number.isFinite(n))return e;let o=n-r;return o===0?e:e+t*o}function Ml(e,t){if(!e)return CV(t);let r=t-xo(e,0).camber;return r?{...e,camber:e.camber.map(n=>n+r)}:e}function FV(e){return{kinFront:Ml(e.kinFront,J(e,"camber_front_deg")),kinRear:Ml(e.kinRear,J(e,"camber_rear_deg"))}}function CV(e){let t=[-40,0,40];return{travel:t,motionRatio:t.map(()=>1),camber:t.map(()=>e),toe:t.map(()=>0),damperLen:t.map(()=>0)}}var Ew=9.81,Iw=e=>e>1?e/100:e;function Ra(e,t,r){let n=t??e.tireModel??_c(),o=r??e.tireModelRear??n,a={grip:J(e,"grip_scale"),stiffness:J(e,"stiffness_scale")},s=qm(n,a);return{front:s,rear:o===n?s:qm(o,a)}}function pn(e,t,r){let n=Ra(e,t,r),o=We(n.front);return Yt(n.rear===n.front?o:Bm(o,We(n.rear)))}function Z0(e,t,r){let n=Iw(e.front_mass_diss.value),o=Ra(e,t,r),a=We(o.front),s=o.rear===o.front?a:We(o.rear),i=t??e.tireModel,c=r??e.tireModelRear??i,l=e.m.value*Ew*n/2,u=e.m.value*Ew*(1-n)/2,m=(i?a.verticalStiffness():0)||J(e,"tire_vertical_rate"),p=(c?s.verticalStiffness():0)||J(e,"tire_vertical_rate"),d=an(i)??0,f=an(c)??0,h=e.surveyedRadiusFront&&e.surveyedRadiusRear?Xd({freeRadius:d,staticLoad:l,tyreRate:m,surveyed:e.surveyedRadiusFront},{freeRadius:f,staticLoad:u,tyreRate:p,surveyed:e.surveyedRadiusRear},n):void 0,b=e.surveyedRadiusFront?wr(d,l,m,e.surveyedRadiusFront):void 0,g=e.surveyedRadiusRear?wr(f,u,p,e.surveyedRadiusRear):void 0;return{ev:a,evR:s,Wf:l,Wr:u,tireRate:m,tireRateRear:p,tyreFreeRadius:d,tyreFreeRadiusRear:f,cgStandingRadius:h,standingFront:b,standingRear:g}}function Wd(e,t,r){let n=Z0(e,t,r);return{front:n.standingFront,rear:n.standingRear}}function _w(e,t,r){return Z0(e,t,r).cgStandingRadius}function Ut(e,t,r){let n=Iw(e.front_mass_diss.value),o=J(e,"mr_front")||1,a=J(e,"mr_rear")||1,{ev:s,evR:i,Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:p,tyreFreeRadiusRear:d,cgStandingRadius:f,standingFront:h,standingRear:b}=Z0(e,t,r),g=Xc(e),y=kl(e),x=pa(e.damperModel,e.damperSetup,o,a,e.damperModelRear??e.damperModel),R=e.readouts?.damper_front===ga,v=e.readouts?.damper_rear===ga,S={rho:e.rho.value,area:e.A.value,cl:e.c_l.value,cw:e.c_w.value,copLongFront:1-Math.max(0,Math.min(1,J(e,"cop_long"))),copHeight:J(e,"cop_height"),...e.aeroModel?{model:e.aeroModel}:{},rideHeightFront:J(e,"ride_height_front"),rideHeightRear:J(e,"ride_height_rear")};return{massTotal:e.m.value,frontMassFrac:n,steeringSystem:e.steeringSystem,tv:Ld(e),cgHeight:ai(J(e,"cg_height"),e.cgReference?.standingRadius,f),...f!==void 0?{cgStandingRadius:f}:{},wheelbase:J(e,"wheelbase"),trackFront:J(e,"track_front"),trackRear:J(e,"track_rear"),wheelRateFront:J(e,"spring_front")*o*o,wheelRateRear:J(e,"spring_rear")*a*a,tireRate:u,...m!==u?{tireRateRear:m}:{},tireDamping:J(e,"tire_vertical_damping"),arbFront:J(e,"arb_front"),arbRear:J(e,"arb_rear"),...da(e)?{chassisTorsion:da(e)}:{},brakeBalanceFront:g.balanceFront,brakes:g,...y?{driveline:y}:{},heaveSpringFront:J(e,"heave_spring_front"),heaveSpringRear:J(e,"heave_spring_rear"),unsprungPerCorner:J(e,"unsprung_mass"),unsprungCgHeight:TV(e,{Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:p,tyreFreeRadiusRear:d,standingFront:h,standingRear:b}),tyreFreeRadius:p,...d!==p?{tyreFreeRadiusRear:d}:{},rcHeightFront:qn(J(e,"rc_front"),e.rcRoad?.gainFront,e.rcRoad?.radiusFront,h),rcHeightRear:qn(J(e,"rc_rear"),e.rcRoad?.gainRear,e.rcRoad?.radiusRear,b),corneringStiffnessFront:s.corneringStiffness(c),corneringStiffnessRear:i.corneringStiffness(l),damperFront:x?.front&&!R?x.front.rate:J(e,"damper_front")*o*o,damperRear:x?.rear&&!v?x.rear.rate:J(e,"damper_rear")*a*a,...x?.front&&!R?{damperCurveFront:x.front.curve}:{},...x?.rear&&!v?{damperCurveRear:x.rear.curve}:{},aero:S,ackermannPct:J(e,"ackermann_pct"),toeFrontDeg:J(e,"toe_front_deg"),toeRearDeg:J(e,"toe_rear_deg"),yawInertia:J(e,"I_yaw"),steerFront:e.steerFront,...FV(e)}}function TV(e,t){let r=(a,s,i,c)=>a??(s>0?wr(s,i,c,s):void 0),n=r(t.standingFront,t.tyreFreeRadius,t.Wf,t.tireRate),o=r(t.standingRear,t.tyreFreeRadiusRear,t.Wr,t.tireRateRear);return n!==void 0&&o!==void 0?.5*(n+o):n??o??e.r_dyn.value*1e3}var qd={capacity:"the battery model\u2019s pack charge \u2014 cells in parallel \xD7 cell capacity",ocv:"the battery model\u2019s pack voltage at full charge"};function Nw(e,t=e.batteryModel){if(!t)return e;let r=Cn(t),n=(o,a)=>({...o,value:a});return{...e,capacity:n(e.capacity,r.capacityAh),ocv:n(e.ocv,r.voltageAtFull)}}var Vw={damper_front:`the damper part sets it: its front curve at ${Ao} mm/s`,damper_rear:`the damper part sets it (the rear's own, where the car names one): its rear curve at ${Ao} mm/s`};function Qd(e){let t=!!(e.damperModelId||e.damperModel),r=t||!!(e.damperModelIdRear||e.damperModelRear);return{...t?{damper_front:Vw.damper_front}:{},...r?{damper_rear:Vw.damper_rear}:{}}}function Bw(e,t=e.damperModel,r=e.damperModelRear??t){if(!t&&!r)return e;let n=J(e,"mr_front")||1,o=J(e,"mr_rear")||1,a=pa(t,e.damperSetup,n,o,r);if(!a)return e;let s=(c,l,u)=>({...c??{label:l,unit:"N\xB7s/mm"},value:u}),i={...e};return a.front&&e.readouts?.damper_front!==ga&&(i.damper_front=s(e.damper_front,"damper front",a.front.rate/(n*n))),a.rear&&e.readouts?.damper_rear!==ga&&(i.damper_rear=s(e.damper_rear,"damper rear",a.rear.rate/(o*o))),i}var $w={how:"scripts/paramTiers.ts: each row \xB120 % (switches flipped, springs on the suspension), first car of every gallery template, largest change to any event time, % of it",templates:["fs-ev-comparison","fs-ev-single","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor","formula-1","touring-car","street-car","cup-car","stock-car","hill-climb","suspension","direct-coilover","pushrod","pullrod","third-spring","mcpherson-strut","tyre-study"],rows:{endurance_reserve:{group:"Powertrain",score:"infinite",byTemplate:{"fs-ev-comparison":"infinite","fs-ev-single":"infinite","fs-combustion":null,"fs-ev-awd":0,"fs-ev-rwd-hubs":"infinite","fs-ev-one-motor":"infinite","formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:0,"direct-coilover":null,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":null,"tyre-study":"infinite"}},gear_ratio:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":5.6255,"fs-ev-awd":5.8819,"fs-ev-rwd-hubs":11.5358,"fs-ev-one-motor":7.2758,"formula-1":.2473,"touring-car":.2195,"street-car":.0998,"cup-car":.2431,"stock-car":.0645,"hill-climb":3.1703,suspension:1.8984,"direct-coilover":.2195,pushrod:1.9001,pullrod:1.9126,"third-spring":1.9001,"mcpherson-strut":.111,"tyre-study":11.9893}},driven_wheels:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:1.9216,"direct-coilover":0,pushrod:1.9171,pullrod:1.919,"third-spring":1.9171,"mcpherson-strut":0,"tyre-study":11.9893}},power_scale:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":10.2883,"fs-ev-awd":4.2843,"fs-ev-rwd-hubs":11.6138,"fs-ev-one-motor":7.2758,"formula-1":2.6682,"touring-car":2.5337,"street-car":1.938,"cup-car":2.6155,"stock-car":1.2193,"hill-climb":1.869,suspension:1.9216,"direct-coilover":2.5337,pushrod:1.9171,pullrod:1.919,"third-spring":1.9171,"mcpherson-strut":1.9778,"tyre-study":11.9893}},grip_scale:{group:"Tyres",score:11.4886,byTemplate:{"fs-ev-comparison":10.9135,"fs-ev-single":10.9135,"fs-combustion":11.4886,"fs-ev-awd":11.3513,"fs-ev-rwd-hubs":11.3513,"fs-ev-one-motor":11.3905,"formula-1":10.9225,"touring-car":7.4484,"street-car":7.2578,"cup-car":7.1946,"stock-car":10.4642,"hill-climb":9.5384,suspension:8.3679,"direct-coilover":7.4484,pushrod:8.3929,pullrod:8.3807,"third-spring":8.3929,"mcpherson-strut":7.35,"tyre-study":10.9135}},front_mass_diss:{group:"Mass & chassis",score:10.3816,byTemplate:{"fs-ev-comparison":1.1854,"fs-ev-single":1.1854,"fs-combustion":1.5398,"fs-ev-awd":1.9682,"fs-ev-rwd-hubs":1.9682,"fs-ev-one-motor":4.5048,"formula-1":5.2182,"touring-car":1.241,"street-car":3.5067,"cup-car":.7277,"stock-car":2.2367,"hill-climb":10.3816,suspension:.5046,"direct-coilover":1.241,pushrod:.4796,pullrod:.4587,"third-spring":.4796,"mcpherson-strut":3.4131,"tyre-study":1.1854}},m:{group:"Mass & chassis",score:9.7815,byTemplate:{"fs-ev-comparison":9.7815,"fs-ev-single":9.7815,"fs-combustion":7.2245,"fs-ev-awd":5.6765,"fs-ev-rwd-hubs":9.2239,"fs-ev-one-motor":7.0296,"formula-1":5.3736,"touring-car":3.7044,"street-car":1.9146,"cup-car":2.6724,"stock-car":3.7623,"hill-climb":5.4157,suspension:3.8549,"direct-coilover":3.7044,pushrod:3.8507,pullrod:3.8527,"third-spring":3.8507,"mcpherson-strut":1.9399,"tyre-study":9.7815}},cop_long:{group:"Aerodynamics",score:6.6543,byTemplate:{"fs-ev-comparison":1.032,"fs-ev-single":1.032,"fs-combustion":1.0669,"fs-ev-awd":1.0452,"fs-ev-rwd-hubs":1.0452,"fs-ev-one-motor":1.0521,"formula-1":5.9878,"touring-car":.1327,"street-car":.0018,"cup-car":.2696,"stock-car":.6469,"hill-climb":6.6543,suspension:.3644,"direct-coilover":.1327,pushrod:.3575,pullrod:.355,"third-spring":.3575,"mcpherson-strut":.0072,"tyre-study":1.032}},front_aero_diss:{group:"Aerodynamics",score:5.2168,byTemplate:{"fs-ev-comparison":.9064,"fs-ev-single":.9064,"fs-combustion":.8657,"fs-ev-awd":.8967,"fs-ev-rwd-hubs":.8967,"fs-ev-one-motor":.8574,"formula-1":4.2912,"touring-car":.0708,"street-car":.0018,"cup-car":.2207,"stock-car":.5291,"hill-climb":5.2168,suspension:.2835,"direct-coilover":.0708,pushrod:.2831,pullrod:.2823,"third-spring":.2831,"mcpherson-strut":.0072,"tyre-study":.9064}},power_limit_kw:{group:"Powertrain",score:4.5916,byTemplate:{"fs-ev-comparison":.4828,"fs-ev-single":.4828,"fs-combustion":null,"fs-ev-awd":4.5916,"fs-ev-rwd-hubs":.5453,"fs-ev-one-motor":3.6198,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:.0626,"direct-coilover":null,pushrod:.0625,pullrod:.0626,"third-spring":.0625,"mcpherson-strut":null,"tyre-study":.4828}},soc:{group:"Powertrain",score:3.5618,byTemplate:{"fs-ev-comparison":3.2245,"fs-ev-single":3.2245,"fs-combustion":0,"fs-ev-awd":1.6179,"fs-ev-rwd-hubs":3.3095,"fs-ev-one-motor":3.5618,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.2245}},effi_pgb:{group:"Powertrain",score:3.5269,byTemplate:{"fs-ev-comparison":3.5269,"fs-ev-single":3.5269,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:.0626,"direct-coilover":0,pushrod:.0625,pullrod:.0626,"third-spring":.0625,"mcpherson-strut":0,"tyre-study":3.5269}},c_l:{group:"Aerodynamics",score:3.4342,byTemplate:{"fs-ev-comparison":.9751,"fs-ev-single":.9751,"fs-combustion":.9539,"fs-ev-awd":1.0777,"fs-ev-rwd-hubs":.9886,"fs-ev-one-motor":1.0797,"formula-1":3.4342,"touring-car":.8979,"street-car":.0715,"cup-car":.2158,"stock-car":.5467,"hill-climb":1.2705,suspension:.9751,"direct-coilover":.8979,pushrod:.9734,pullrod:.9708,"third-spring":.9734,"mcpherson-strut":.0704,"tyre-study":.9751}},ocv:{group:"Powertrain",score:3.3244,byTemplate:{"fs-ev-comparison":3.0446,"fs-ev-single":3.0446,"fs-combustion":0,"fs-ev-awd":1.4595,"fs-ev-rwd-hubs":3.1854,"fs-ev-one-motor":3.3244,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.0446}},capacity:{group:"Powertrain",score:3.3244,byTemplate:{"fs-ev-comparison":3.0446,"fs-ev-single":3.0446,"fs-combustion":0,"fs-ev-awd":1.4595,"fs-ev-rwd-hubs":3.1854,"fs-ev-one-motor":3.3244,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.0446}},A:{group:"Aerodynamics",score:2.3707,byTemplate:{"fs-ev-comparison":.802,"fs-ev-single":.802,"fs-combustion":.7928,"fs-ev-awd":.9333,"fs-ev-rwd-hubs":.7926,"fs-ev-one-motor":.961,"formula-1":2.3707,"touring-car":.6374,"street-car":.4904,"cup-car":.2428,"stock-car":.1932,"hill-climb":1.1486,suspension:.802,"direct-coilover":.6374,pushrod:.7991,pullrod:.7982,"third-spring":.7991,"mcpherson-strut":.4873,"tyre-study":.802}},rho:{group:"Aerodynamics",score:2.3707,byTemplate:{"fs-ev-comparison":.802,"fs-ev-single":.802,"fs-combustion":.7928,"fs-ev-awd":.9333,"fs-ev-rwd-hubs":.7926,"fs-ev-one-motor":.961,"formula-1":2.3707,"touring-car":.6374,"street-car":.4904,"cup-car":.2428,"stock-car":.1932,"hill-climb":0,suspension:.802,"direct-coilover":.6374,pushrod:.7991,pullrod:.7982,"third-spring":.7991,"mcpherson-strut":.4873,"tyre-study":.802}},cg_height:{group:"Mass & chassis",score:2.2005,byTemplate:{"fs-ev-comparison":1.8282,"fs-ev-single":1.8282,"fs-combustion":1.6978,"fs-ev-awd":2.2005,"fs-ev-rwd-hubs":1.8919,"fs-ev-one-motor":1.9269,"formula-1":.6248,"touring-car":1.2858,"street-car":1.4681,"cup-car":.992,"stock-car":1.2052,"hill-climb":.6037,suspension:1.8282,"direct-coilover":1.2858,pushrod:1.8142,pullrod:1.8229,"third-spring":1.8142,"mcpherson-strut":1.7176,"tyre-study":1.8282}},l_to_d_ratio:{group:"Aerodynamics",score:1.4351,byTemplate:{"fs-ev-comparison":.7905,"fs-ev-single":.7905,"fs-combustion":.6962,"fs-ev-awd":.5843,"fs-ev-rwd-hubs":.8444,"fs-ev-one-motor":.9611,"formula-1":1.4351,"touring-car":.3671,"street-car":.528,"cup-car":.5631,"stock-car":.4634,"hill-climb":.2349,suspension:.2456,"direct-coilover":.3671,pushrod:.2491,pullrod:.2456,"third-spring":.2491,"mcpherson-strut":.5265,"tyre-study":.7905}},tv_enabled:{group:"Torque vectoring",score:1.2381,byTemplate:{"fs-ev-comparison":1.2381,"fs-ev-single":1.2381,"fs-combustion":0,"fs-ev-awd":1.2293,"fs-ev-rwd-hubs":1.2293,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":.1209,"cup-car":.1617,"stock-car":0,"hill-climb":9e-4,suspension:.3086,"direct-coilover":0,pushrod:.2933,pullrod:.3089,"third-spring":.2933,"mcpherson-strut":.1326,"tyre-study":1.2381}},c_w:{group:"Aerodynamics",score:1.1499,byTemplate:{"fs-ev-comparison":.6319,"fs-ev-single":.6319,"fs-combustion":.5577,"fs-ev-awd":.462,"fs-ev-rwd-hubs":.6559,"fs-ev-one-motor":.7504,"formula-1":1.1499,"touring-car":.2914,"street-car":.4211,"cup-car":.4486,"stock-car":.3694,"hill-climb":.1625,suspension:.1945,"direct-coilover":.2914,pushrod:.1979,pullrod:.1948,"third-spring":.1979,"mcpherson-strut":.4196,"tyre-study":.6319}},brake_balance:{group:"Brakes",score:1.0132,byTemplate:{"fs-ev-comparison":.8303,"fs-ev-single":.8303,"fs-combustion":.6932,"fs-ev-awd":.9772,"fs-ev-rwd-hubs":.8148,"fs-ev-one-motor":1.0132,"formula-1":.97,"touring-car":.9585,"street-car":.7184,"cup-car":.1468,"stock-car":.0764,"hill-climb":.9096,suspension:.8303,"direct-coilover":.9585,pushrod:.8578,pullrod:.8454,"third-spring":.8578,"mcpherson-strut":.7099,"tyre-study":.8303}},stiffness_scale:{group:"Tyres",score:.871,byTemplate:{"fs-ev-comparison":.5088,"fs-ev-single":.5088,"fs-combustion":.4874,"fs-ev-awd":.3745,"fs-ev-rwd-hubs":.4753,"fs-ev-one-motor":.5706,"formula-1":.5776,"touring-car":.4346,"street-car":.1077,"cup-car":.4012,"stock-car":.1613,"hill-climb":.871,suspension:.5088,"direct-coilover":.4346,pushrod:.5253,pullrod:.5172,"third-spring":.5253,"mcpherson-strut":.1518,"tyre-study":.5088}},cop_height:{group:"Aerodynamics",score:.2837,byTemplate:{"fs-ev-comparison":.155,"fs-ev-single":.155,"fs-combustion":.1546,"fs-ev-awd":.1557,"fs-ev-rwd-hubs":.1557,"fs-ev-one-motor":.1542,"formula-1":.1173,"touring-car":.0072,"street-car":.0023,"cup-car":.0745,"stock-car":.1568,"hill-climb":.2837,suspension:.0421,"direct-coilover":.0072,pushrod:.0437,pullrod:.04,"third-spring":.0437,"mcpherson-strut":.0076,"tyre-study":.155}},spring_rear:{group:"Suspension",score:.2822,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":.0355,"touring-car":.1169,"street-car":.2242,"cup-car":.0902,"stock-car":.2822,"hill-climb":.1929,suspension:0,"direct-coilover":.1169,pushrod:.1142,pullrod:.2148,"third-spring":.1142,"mcpherson-strut":.1786,"tyre-study":0}},spring_front:{group:"Suspension",score:.2388,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":.0189,"touring-car":.0958,"street-car":.2388,"cup-car":.1462,"stock-car":.1719,"hill-climb":.1873,suspension:0,"direct-coilover":.0958,pushrod:.1257,pullrod:.0612,"third-spring":.1257,"mcpherson-strut":.1911,"tyre-study":0}},arb_front:{group:"Suspension",score:.1792,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":.0235,"touring-car":.0589,"street-car":.1792,"cup-car":.0215,"stock-car":.0926,"hill-climb":.1095,suspension:null,"direct-coilover":.0589,pushrod:.0455,pullrod:.049,"third-spring":.0455,"mcpherson-strut":.1435,"tyre-study":null}},fr_0:{group:"Tyres",score:.158,byTemplate:{"fs-ev-comparison":.158,"fs-ev-single":.158,"fs-combustion":.1097,"fs-ev-awd":.0708,"fs-ev-rwd-hubs":.1442,"fs-ev-one-motor":.1168,"formula-1":.07,"touring-car":.0492,"street-car":.1006,"cup-car":.065,"stock-car":.0262,"hill-climb":.0334,suspension:.0217,"direct-coilover":.0492,pushrod:.0229,pullrod:.0223,"third-spring":.0229,"mcpherson-strut":.0989,"tyre-study":.158}},arb_rear:{group:"Suspension",score:.1047,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":.0224,"touring-car":.0365,"street-car":.0832,"cup-car":.1047,"stock-car":.0436,"hill-climb":.0734,suspension:null,"direct-coilover":.0365,pushrod:.0411,pullrod:.0332,"third-spring":.0411,"mcpherson-strut":.0643,"tyre-study":null}},unsprung_mass:{group:"Mass & chassis",score:.102,byTemplate:{"fs-ev-comparison":.0477,"fs-ev-single":.0477,"fs-combustion":.0512,"fs-ev-awd":.0545,"fs-ev-rwd-hubs":.0514,"fs-ev-one-motor":.0799,"formula-1":.0313,"touring-car":.0471,"street-car":.102,"cup-car":.0315,"stock-car":.042,"hill-climb":.0278,suspension:.0477,"direct-coilover":.0471,pushrod:.0452,pullrod:.0468,"third-spring":.0452,"mcpherson-strut":.0876,"tyre-study":.0477}},camber_front_deg:{group:"Steering & alignment",score:.0576,byTemplate:{"fs-ev-comparison":.0065,"fs-ev-single":.0065,"fs-combustion":.008,"fs-ev-awd":.0075,"fs-ev-rwd-hubs":.0075,"fs-ev-one-motor":.0098,"formula-1":.0358,"touring-car":.0272,"street-car":.0025,"cup-car":.0191,"stock-car":.0576,"hill-climb":.0389,suspension:.0019,"direct-coilover":.0272,pushrod:.0017,pullrod:.0016,"third-spring":.0017,"mcpherson-strut":.002,"tyre-study":.0065}},camber_rear_deg:{group:"Steering & alignment",score:.0262,byTemplate:{"fs-ev-comparison":.0081,"fs-ev-single":.0081,"fs-combustion":.0085,"fs-ev-awd":.0054,"fs-ev-rwd-hubs":.0096,"fs-ev-one-motor":.0097,"formula-1":.0028,"touring-car":.0106,"street-car":8e-4,"cup-car":5e-4,"stock-car":.0035,"hill-climb":.0262,suspension:.0081,"direct-coilover":.0106,pushrod:.0082,pullrod:.0083,"third-spring":.0082,"mcpherson-strut":3e-4,"tyre-study":.0081}},I_yaw:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},I_roll:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},I_pitch:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},ride_height_front:{group:"Aerodynamics",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},ride_height_rear:{group:"Aerodynamics",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tire_vertical_rate:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tire_vertical_damping:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":0,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},r_dyn:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},damper_front:{group:"Suspension",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},damper_rear:{group:"Suspension",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_kp:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_ff_low:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_ff_high:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_v_low:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_v_high:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},wheelbase:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},track_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},track_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},rc_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},rc_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},chassis_torsion:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_twist_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_twist_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_wheel:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_rotor:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},v_limit_endurance:{group:"Powertrain",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},mr_front:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},mr_rear:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},heave_spring_front:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},heave_spring_rear:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},toe_front_deg:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},toe_rear_deg:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},ackermann_pct:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}}}};function Qn(e){return!!e&&typeof e=="object"&&"value"in e&&"label"in e}var EV={Batteriekapazit\u00E4t:"pack capacity",Rollwiderstandsbeiwert:"rolling-resistance coefficient"},Kw=e=>EV[e]??e;function Zd(e){let t=[];for(let r of Object.keys(e)){if(r==="motor"||r==="name")continue;let n=e[r];Qn(n)&&t.push({key:r,label:Kw(n.label),value:n.value,unit:n.unit})}return t}var IV=[{title:"Mass & chassis",keys:["m","front_mass_diss","cg_height","unsprung_mass","wheelbase","track_front","track_rear","rc_front","rc_rear","chassis_torsion","I_twist_front","I_twist_rear","I_yaw","I_roll","I_pitch","I_wheel","I_rotor"]},{title:"Aerodynamics",keys:["A","c_l","c_w","l_to_d_ratio","front_aero_diss","cop_long","cop_height","ride_height_front","ride_height_rear","rho"]},{title:"Tyres",keys:["grip_scale","stiffness_scale","tire_vertical_rate","tire_vertical_damping","fr_0","r_dyn"]},{title:"Powertrain",keys:["gear_ratio","driven_wheels","effi_pgb","power_scale","power_limit_kw","v_limit_endurance","endurance_reserve","capacity","ocv","soc"]},{title:"Suspension",keys:["spring_front","spring_rear","mr_front","mr_rear","arb_front","arb_rear","heave_spring_front","heave_spring_rear","damper_front","damper_rear"]},{title:"Steering & alignment",keys:["camber_front_deg","camber_rear_deg","toe_front_deg","toe_rear_deg","ackermann_pct"]},{title:"Brakes",keys:["brake_balance"]},{title:"Torque vectoring",keys:["tv_enabled","tv_kp","tv_ff_low","tv_ff_high","tv_v_low","tv_v_high"]}],_V=.5,Gw=e=>e==="infinite"?1/0:typeof e=="number"?e:null,NV=e=>/front/.test(e)?e.replace("front","rear"):/rear/.test(e)?e.replace("rear","front"):null,sne=(()=>{let e=$w.rows,t=o=>{let a=NV(o),s=Gw(e[o]?.score),i=a&&e[a]?Gw(e[a].score):null;return s==null?i:i==null?s:Math.max(s,i)},r=new Set,n=new Map;for(let[o,a]of Object.entries(e)){let s=t(o);s!=null&&(s>=_V&&r.add(o),n.set(a.group,Math.max(n.get(a.group)??0,s)))}for(let[o,a]of Object.entries(e)){let s=t(o);s!=null&&s>0&&s===n.get(a.group)&&r.add(o)}return r})();var J0={wheelbase:"set by the axle positions in Kinematics",track_front:"twice the front wheel-centre Y",track_rear:"twice the rear wheel-centre Y",rc_front:"solved from the front wishbones, on the fitted tyre",rc_rear:"solved from the rear wishbones, on the fitted tyre",mr_front:"damper travel per mm of front wheel travel, from the linkage",mr_rear:"damper travel per mm of rear wheel travel, from the linkage",spring_front:"the front corner spring rate, stored on the suspension the car runs",spring_rear:"the rear corner spring rate, stored on the suspension the car runs",ackermann_pct:"solved from the rack and tie rods, read near centre"};function Hw(e){let t=new Map;for(let a of Zd(e))t.set(a.key,a);let r=new Set,n=[];for(let a of IV){let s=[];for(let i of a.keys){let c=t.get(i);c&&(s.push(c),r.add(i))}s.length&&n.push({title:a.title,rows:s})}let o=Zd(e).filter(a=>!r.has(a.key));return o.length&&n.push({title:"Other",rows:o}),n}var ey={A:"the aero model's reference area",c_l:"read off the aero model at the ride heights",c_w:"read off the aero model at the ride heights",l_to_d_ratio:"read off the aero model at the ride heights",front_aero_diss:"the aero model's front and rear coefficients set the balance",cop_long:"the aero model's front and rear coefficients set the balance"},ty={ride_height_front:"reaches nothing until an aero model is attached at the head of the Aerodynamics group",ride_height_rear:"reaches nothing until an aero model is attached at the head of the Aerodynamics group"},zw=e=>!!(e.aeroModelId||e.aeroModel);function OV(e){let t=o=>o!=null&&o.design.kind!=="none",r=o=>o?.design.kind==="none",n={};return t(e.arbFrontDesign)&&(n.arb_front="the front anti-roll bar design sets it"),t(e.arbRearDesign)&&(n.arb_rear="the rear anti-roll bar design sets it"),!n.arb_front&&t(e.rollBarFrontDesign)&&(n.arb_front="the front anti-roll bar design sets it"),!n.arb_rear&&t(e.rollBarRearDesign)&&(n.arb_rear="the rear anti-roll bar design sets it"),!n.arb_front&&r(e.arbFrontDesign)&&(n.arb_front="the front roll element is None"),!n.arb_rear&&r(e.arbRearDesign)&&(n.arb_rear="the rear roll element is None"),t(e.heaveFrontDesign)&&(n.heave_spring_front="the front third-spring design sets it"),t(e.heaveRearDesign)&&(n.heave_spring_rear="the rear third-spring design sets it"),r(e.heaveFrontDesign)&&(n.heave_spring_front="the front heave element is None"),r(e.heaveRearDesign)&&(n.heave_spring_rear="the rear heave element is None"),n}var VV=e=>!!(e.batteryModelId||e.batteryModel),Yw={capacity:"an engine car has no pack",ocv:"an engine car has no pack",soc:"an engine car has no pack",power_limit_kw:"an engine car has no pack, and the power rule is the electric class\u2019s",endurance_reserve:"an engine car has no pack to finish with a reserve of",I_rotor:"the engine model refers its own crank through each gear"},ine=Object.keys(Yw);function ry(e){if(!(e.motorModelId||e.motorModel))return{};let t=yt(e.motorModel),r={effi_pgb:"the motor model states its own efficiency",...t?Yw:{}};return(e.motorCount!=null||t)&&(r.driven_wheels="the motor layout in Powertrain sets which wheels are driven"),r}function BV(e,t){let r={};return t.geometry&&Object.assign(r,J0,OV(e)),zw(e)&&Object.assign(r,ey),VV(e)&&Object.assign(r,qd),Object.assign(r,ry(e)),Object.assign(r,Qd(e)),Object.assign(r,dd(e)),e.readouts&&Object.assign(r,e.readouts),r}function Ww(e,t){let r=BV(e,t);return zw(e)||Object.assign(r,ty),r}function ny(e){let t=e.cop_long;return Qn(t)?1-t.value:.5}function $V(e,t){let r=e.front_aero_diss,n=e.cop_long;!Qn(r)||!Qn(n)||(t===r.label?n.value=1-r.value:t===n.label&&(r.value=1-n.value))}function GV(e,t){$V(e,t);let r=e.c_l,n=e.c_w,o=e.l_to_d_ratio;!Qn(r)||!Qn(n)||(t===r.label||t===n.label?Qn(o)&&n.value!==0&&(o.value=r.value/n.value):Qn(o)&&t===o.label&&o.value!==0&&(n.value=r.value/o.value))}function si(e,t,r){let n=!1;for(let o of Object.keys(e)){if(o==="motor"||o==="name")continue;let a=e[o];if(Qn(a)&&Kw(a.label)===t){a.value=r,n=!0;break}}return n&&GV(e,t),n}function Jd(e,t,r=0,n,o){let a=()=>({cl:e.c_l.value,cw:e.c_w.value,frontShare:ny(e),A:e.A.value,platform:null});if(!e.aeroModel)return a();let s=Pn(n??Ut(e),t,r,o);if(!s)return a();let i=s.clFront+s.clRear;return{cl:i,cw:s.cd,frontShare:i!==0?s.clFront/i:ny(e),A:s.area,platform:s}}var jw=e=>typeof e=="object"&&e!==null&&typeof e.value=="number"&&typeof e.label=="string";function Uw(e,t=e.aeroModel){if(!t)return e;let r=fo(t,{wheelbase:J(e,"wheelbase")}).at(J(e,"ride_height_front"),J(e,"ride_height_rear")),{cl:n,balanceFront:o}=Xh(r),a=(i,c,l)=>({...i??c,value:l}),s={...e,A:a(e.A,e.A,t.area),c_l:a(e.c_l,e.c_l,n),c_w:a(e.c_w,e.c_w,r.cd),front_aero_diss:a(e.front_aero_diss,e.front_aero_diss,o),cop_long:a(jw(e.cop_long)?e.cop_long:void 0,ln.cop_long,1-o)};return jw(e.l_to_d_ratio)&&(s.l_to_d_ratio={...e.l_to_d_ratio,value:r.cd!==0?n/r.cd:0}),s}var Sl={dsTarget:.25,accelStep:.25,vTol:.002,scanSteps:24,seamIters:8,fitSpacing:1},KV=32;function Xw(e,t,r){let n=Math.round(e/t);return Math.max(1,Math.min(Number.isFinite(n)?n:1,Math.floor(r/KV)||1))}function Bt(e){let t=Sl,r=(n,o,a)=>{let s=Number(n);return Number.isFinite(s)&&s>=a?s:o};return{dsTarget:r(e?.dsTarget,t.dsTarget,.001),accelStep:r(e?.accelStep,t.accelStep,.001),vTol:r(e?.vTol,t.vTol,1e-6),scanSteps:Math.max(4,Math.round(r(e?.scanSteps,t.scanSteps,4))),seamIters:Math.max(1,Math.round(r(e?.seamIters,t.seamIters,1))),fitSpacing:r(e?.fitSpacing,t.fitSpacing,0)}}var qw=Math.PI/180,ep=.02,Qw=new WeakMap;function Al(e){let t=Qw.get(e);if(t!==void 0)return t;let r=e.npts,n=new Array(r),o=new Array(r),a=!1;for(let i=0;i<r;i++){let c=(e.gradient?.[i]??0)*qw,l=(e.bank?.[i]??0)*qw,u=e.verticalCurvature?.[i]??0;n[i]=c===0&&l===0?1:Math.cos(c)*Math.cos(l),o[i]=(u-e.curvature[i]*Math.sin(l))/9.81,(n[i]!==1||o[i]!==0)&&(a=!0)}let s=a?{n0:n,k:o}:null;return Qw.set(e,s),s}function tp(e,t,r){return e.n0[t]+e.k[t]*r*r}function Zw(e,t){return e.k[t]<0?Math.sqrt(Math.max(0,e.n0[t])/-e.k[t]):1/0}function Jw(e,t){if(!e)return null;let r=1/0,n=-1/0;for(let o=0;o<e.n0.length;o++){let a=tp(e,o,t[o]??0);a<r&&(r=a),a>n&&(n=a)}return r>=1-ep&&n<=1+ep?null:{lo:r,hi:n}}var ii=[.1,.25,.5,.75,1,1.25,1.5,2,2.5];function eF(e){let t=e.lo>=1-ep?1:1-1.25*(1-e.lo)-.05,r=e.hi<=1+ep?1:1+1.25*(e.hi-1)+.05,n=[...ii].reverse().find(a=>a<=t)??ii[0],o=ii.find(a=>a>=r)??ii[ii.length-1];return ii.filter(a=>a>=n&&a<=o)}function oy(e,t,r){return r<1?Math.max(e,t):Math.min(e,t)}function tF(e,t,r,n){let o=e.n0.length;return a=>{let s=n?n(a):r,i=a%o;if(e.n0[i]===1&&e.k[i]===0)return s;let c=e.n0[i],l=e.k[i],u=d=>c+l*d*d,m=s.kappaMax===void 0?t.kappaMax:t.kappaMax===void 0?s.kappaMax:Math.min(s.kappaMax,t.kappaMax),p=m!==void 0?{kappaMax:m}:{};return n?{vMax:s.vMax,...p,axAccel:(d,f,h=1,b=1)=>s.axAccel(d,f,h,b)+t.axAccel(u(d),d,f,h,b)-r.axAccel(d,f,h,b),axDecel:(d,f,h=1,b=1)=>{let g=y=>s.axDecel(d,f,h,y)+t.axDecel(u(d),d,f,h,y)-r.axDecel(d,f,h,y);return b===1?g(1):oy(g(b),g(1),b)},ay:(d,f,h=1)=>Math.max(0,s.ay(d,f,h)+t.ay(u(d),d,f,h)-r.ay(d,f,h)),scrub:(d,f,h=1)=>(s.scrub?.(d,f,h)??0)+t.scrub(u(d),d,f,h)-(r.scrub?.(d,f,h)??0)}:{vMax:s.vMax,...p,axAccel:(d,f,h=1,b=1)=>t.axAccel(u(d),d,f,h,b),axDecel:(d,f,h=1,b=1)=>t.axDecel(u(d),d,f,h,b),ay:(d,f,h=1)=>t.ay(u(d),d,f,h),scrub:(d,f,h=1)=>t.scrub(u(d),d,f,h)}}}function rp(e,t,r,n,o){let a=e.length,s=r?a:a-1,i=F=>r?(F+1)%a:F+1,{brakeAhead:c,apexAhead:l}=HV(e,t,r),u=new Array(a),m=new Array(a),p=new Array(a),d=new Array(a).fill(0),f=0,h=0,b=0,g=Math.max(0,Math.min(1,n.kept)),y=g>=1?0:n.up,x=g>=1?0:n.down,R=4*y*(1-g),v=F=>{let{v:w,gear:T,tau:M,target:k}=F;f=0,h=0,b=0;for(let C=0;C<s;C++){let P=i(C),L=e[P];for(let D=0;M<=0&&D<n.count;D++){let I=T;if(w<L-1e-9?n.best(w)>T&&(n.rpm(w,T)>=n.limitRpm||c[C]>=w*R)?I=T+1:T>0&&w<n.vIdle(T)&&(I=T-1):L<w-1e-9&&T>0&&n.best(l[C])<T&&n.rpm(w,T-1)<=n.limitRpm&&(I=T-1),I===T)break;k=I,I>T?f++:h++,M=I>T?y:x,M<=0&&(T=k)}u[C]=w,m[C]=T+1,p[C]=n.rpm(w,T);let E=M>0;d[C]=E?1:0;let _=L;if(!E)w<L&&(_=Math.min(L,Math.sqrt(Math.max(0,w*w+2*o(C,w,n.share(w,T))*t[C]))));else if(w<L){let D=o(C,w,g>0?g*n.share(w,T):0),I=Math.min(L,Math.sqrt(Math.max(0,w*w+2*D*t[C]))),N=w+I>0?2*t[C]/(w+I):1/0;if(N<=M)_=I,b+=N,M-=N;else{let O=Math.min(L,Math.max(0,w+D*M)),V=Math.max(0,t[C]-(w+O)*.5*M);b+=M,M=0,T=k,_=Math.min(L,Math.sqrt(Math.max(0,O*O+2*o(C,O,n.share(O,T))*V)))}}else{let D=w+_>0?2*t[C]/(w+_):0;b+=Math.min(D,M),M-=D,M<=0&&(T=k)}w=_}return{v:w,gear:T,tau:M,target:k}},S=n.best(e[0]),A={v:e[0],gear:S,tau:0,target:S};if(r)for(let F=0;F<6;F++){let w=v(A),T=Math.abs(w.v-A.v)<=1e-9&&w.gear===A.gear&&w.target===A.target&&Math.abs(w.tau-A.tau)<=1e-12;if(A=w,T)break}else{let F=v(A);u[a-1]=F.v,m[a-1]=F.gear+1,p[a-1]=n.rpm(F.v,F.gear),d[a-1]=F.tau>0?1:0}return{v:u,gear:m,rpm:p,shifting:d,upshifts:f,downshifts:h,gapTime:b}}function HV(e,t,r){let n=e.length,o=new Array(n).fill(1/0),a=e.slice(),s=1/0,i=e[n-1],c=r?2*n-1:n-2;for(let l=c;l>=0;l--){let u=l%n,m=r?(u+1)%n:u+1,p=e[m]<e[u]-1e-9;s=p?0:s+t[u],i=p?Math.min(i,e[m]):e[u],l<n&&(o[u]=s,a[u]=i)}return{brakeAhead:o,apexAhead:a}}var ay=.001,sy=9.81,wl=(e,t)=>np(e?.gradient?.[t]??0);function np(e){return e===0?0:-sy*Math.sin(e*Math.PI/180)}function ci(e,t){let r=new Array(t);for(let n=0;n<t;n++)r[n]=np(e?.[n]??0);return r}function op(e,t){let r=e?.[t];return r!=null&&r>0?r:1}var wo=(e,t)=>op(e?.mu,t),va=(e,t)=>e?.bank?.[t]??0;function zV(e,t,r,n,o,a){let s=e.ay(t,r,wo(o,a)),i=va(o,a);if(!i)return s;let c=i*Math.PI/180,l=n===0?0:-Math.sign(n)*sy*Math.sin(c);return Math.max(0,(s+l)/Math.cos(c))}function mt(e,t){if(!t)return e;let r=t*Math.PI/180;return e*Math.cos(r)+sy*Math.sin(r)}function iy(e,t,r,n,o){if(r<=t)return t;if(e(r)<=0)return r;let a=(r-t)/n,s=r,i=t,c=!1;for(let l=1;l<=n;l++){let u=r-l*a;if(e(u)<=0){i=u,s=u+a,c=!0;break}}if(!c)return t;for(;s-i>o;){let l=.5*(i+s);e(l)<=0?i=l:s=l}return i}var Zn=(e,t,r)=>t?t(r):e,YV=1e-4;function WV(e,t){let r=Math.abs(t);return e.kappaMax!==void 0&&r>e.kappaMax?e.kappaMax:r}function jV(e,t,r){if(e.kappaMax===void 0&&!t)return;let n=0,o=-1,a=0;for(let i=0;i<r.npts;i++){let c=Zn(e,t,i).kappaMax,l=Math.abs(r.curvature[i]);c===void 0||!(l>c)||(n+=r.ds[i],l/c>a&&(a=l/c,o=i))}if(o<0)return;let s=Zn(e,t,o).kappaMax;return{length:n,at:r.s[o],radius:1/Math.abs(r.curvature[o]),lockRadius:1/s}}function li(e,t,r,n,o,a,s){let i=Bt(r),c=[];for(let l=0;l<t.length;l++){let u=t[l],m=Zn(e,o,l),p=WV(m,u),d=a!==void 0&&a>0?Math.min(m.vMax,a):m.vMax,f=s?Math.min(d,s(l)):d,h=p<=0?f:iy(b=>b*b*p-zV(m,b,0,u,n,l),ay,f,i.scanSteps,Math.min(i.vTol,YV));c.push({v:h,ax:0,ay:h*h*u})}return c}function UV(e,t,r,n,o,a,s=1,i=0,c=0,l){if(r.v<=t.v)return 0;let u=d=>{let f=mt(d*d*n,c),h=(l?e.axDecel(d,Math.abs(f),s,l(d)):e.axDecel(d,Math.abs(f),s))+i;return Math.sqrt(Math.max(0,d*d+2*h*o))},m=r.v;r.v=iy(d=>u(d)-t.v,ay,r.v,a.scanSteps,a.vTol),r.ay=r.v*r.v*n;let p=Math.abs(mt(r.ay,c));return r.ax=(l?e.axDecel(r.v,p,s,l(r.v)):e.axDecel(r.v,p,s))+i,m-r.v}function XV(e,t,r,n,o,a=1,s=0,i=0,c=1){if(r.v>=t.v)return 0;r.ay=r.v*r.v*n,r.ax=e.axAccel(r.v,Math.abs(mt(r.ay,i)),a,c)+s;let l=t.v;return t.v=Math.min(t.v,Math.sqrt(Math.max(0,r.v*r.v+2*r.ax*o))),l-t.v}function rF(e,t,r,n,o,a){let s=Bt(n),i=r.npts,c=0;for(let l=0;l<s.seamIters;l++){let u=0;c++;for(let m=i-1;m>=0;m--){let p=(m+1)%i;u=Math.max(u,UV(Zn(e,o,m),t[p],t[m],r.curvature[m],r.ds[m],s,wo(r,m),wl(r,m),va(r,m),a?d=>a(m,d):void 0))}if(u<=s.vTol)break}return c}function nF(e,t,r,n,o,a){let s=Bt(n),i=r.npts,c=0;for(let l=0;l<s.seamIters;l++){let u=0;c++;for(let m=0;m<i;m++){let p=(m+1)%i;u=Math.max(u,XV(Zn(e,o,m),t[p],t[m],r.curvature[m],r.ds[m],wo(r,m),wl(r,m),va(r,m),a?a[m]:1))}if(u<=s.vTol)break}return c}function qV(e,t,r){let n=r.load?Al(t):null;if(!n||!r.load)return{pick:r.envelope};let o=t.npts;return{pick:tF(n,r.load,e,r.envelope),cap:a=>Zw(n,a%o),n:(a,s)=>tp(n,a,s)}}function oF(e,t,r,n,o,a,s){return rp(n,r.ds,o,a,(i,c,l)=>{let u=c*c*r.curvature[i];return Zn(e,t,i).axAccel(c,Math.abs(mt(u,va(r,i))),wo(r,i),s?l*s[i]:l)+wl(r,i)})}function aF(e,t){return{gear:e.gear.slice(0,t),engineRpm:e.rpm.slice(0,t),shifting:e.shifting.slice(0,t)}}function sF(e,t,r,n){if(!e.scrub)return{};let o=!1,a=n.map((s,i)=>{let c=Zn(e,t,i),l=mt(s*s*r.curvature[i],va(r,i)),u=c.scrub?c.scrub(s,Math.abs(l),wo(r,i)):0;return u!==0&&(o=!0),u});return o?{axScrub:a}:{}}function tr(e,t,r,n={}){let o=Bt(r),a=t.npts,s=t.closed&&!n.standingStart,{pick:i,cap:c,n:l}=qV(e,t,n),u=n.driveDerate,m=n.brakeFade;if(!s)return QV(e,t,o,n.standingStart===!0,i,u,n.vCeiling,m,c,l,n.shifts);let p=li(e,t.curvature,o,t,i,n.vCeiling,c),d=rF(e,p,t,o,i,m),f=nF(e,p,t,o,i,u),h=n.shifts?oF(e,i,t,p.map(R=>R.v),!0,n.shifts,u):void 0;if(h)for(let R=0;R<a;R++)p[R].v=h.v[R];for(let R=0;R<a;R++){let v=p[R];v.ay=v.v*v.v*t.curvature[R];let S=p[(R+1)%a].v;v.ax=(S*S-v.v*v.v)/(2*t.ds[R])}let b=p.map(R=>R.v),g=p.map(R=>R.ax),y=p.map(R=>R.ay),x=0;for(let R=0;R<a;R++){let v=b[R]+b[(R+1)%a];v>0&&(x+=2*t.ds[R]/v)}return{states:p,v:b,ax:g,ay:y,laptime:x,sweeps:{backward:d,forward:f},...l?{loadFactor:b.map((R,v)=>l(v,R))}:{},...sF(e,i,t,b),...h?aF(h,a):{},...iF(e,i,t)}}function iF(e,t,r){let n=jV(e,t,r);return n?{pastLock:n}:{}}function QV(e,t,r,n,o,a,s,i,c,l,u){let m=t.npts,p=t.closed?m:m-1,d=p+1,f=new Array(d);for(let x=0;x<d;x++)f[x]=t.curvature[x%m];let h=li(e,f,r,t,o,s,c);n&&(h[0].v=0);for(let x=p-1;x>=0;x--){let R=h[x],v=h[x+1];if(R.v<=v.v)continue;let S=Zn(e,o,x),A=w=>{let T=mt(w*w*t.curvature[x],va(t,x)),M=(i?S.axDecel(w,Math.abs(T),wo(t,x),i(x,w)):S.axDecel(w,Math.abs(T),wo(t,x)))+wl(t,x);return Math.sqrt(Math.max(0,w*w+2*M*t.ds[x]))},F=n&&x===0?R.v:ay;R.v=iy(w=>A(w)-v.v,F,R.v,r.scanSteps,r.vTol)}for(let x=0;x<p;x++){let R=h[x],v=h[x+1];R.ay=R.v*R.v*t.curvature[x];let S=mt(R.ay,va(t,x));R.ax=Zn(e,o,x).axAccel(R.v,Math.abs(S),wo(t,x),a?a[x]:1)+wl(t,x),v.v=Math.min(v.v,Math.sqrt(Math.max(0,R.v*R.v+2*R.ax*t.ds[x])))}let b=u?oF(e,o,t,h.map(x=>x.v),!1,u,a):void 0;if(b)for(let x=0;x<d;x++)h[x].v=b.v[x];let g=0;for(let x=0;x<p;x++){let R=h[x].v+h[x+1].v;R>0&&(g+=2*t.ds[x]/R)}let y=h.slice(0,m);for(let x=0;x<m;x++){let R=y[x];R.ay=R.v*R.v*t.curvature[x];let v=x<p?h[x+1].v:R.v;R.ax=t.ds[x]>0?(v*v-R.v*R.v)/(2*t.ds[x]):0}return{states:y,v:y.map(x=>x.v),ax:y.map(x=>x.ax),ay:y.map(x=>x.ay),laptime:g,sweeps:{backward:1,forward:1},...l?{loadFactor:y.map((x,R)=>l(R,x.v))}:{},...sF(e,o,t,y.map(x=>x.v)),...b?aF(b,m):{},...iF(e,o,t)}}var cF=(e,t)=>{let r=e[t]?.value;return Number.isFinite(r)&&r>0?r:0};function ka(e,t,r){let n=e.m.value,o=e.r_dyn?.value??0,a=cF(e,"I_wheel"),s=e.motorModel?.kind==="ice"?0:cF(e,"I_rotor"),i=e.gear_ratio?.value??1;if(!(o>0)||a===0&&s===0)return{mass:n,driven:0,undriven:0,effective:n,powerFactor:1,tractionFactor:1};let c=o*o,l=(t?2:0)+(r?2:0),u=4-l,m=(l*a+s*i*i)/c,p=u*a/c,d=n+m+p;return{mass:n,driven:m,undriven:p,effective:d,powerFactor:n/d,tractionFactor:n/(n+p)}}function Ma(e){let t=e.fAxle;return{drivenFront:t?t.fFront.some(r=>r>0):!1,drivenRear:t?t.fRear.some(r=>r>0):!0}}var Fl=36e5,ly=Math.PI*2,cy=e=>Math.max(0,Math.min(1,e));function ap(e){let t=e.motorModel;if(!t){let s=e.effi_pgb?.value??.9;return()=>s}if(t.kind==="simple"){let s=t.efficiency>.01?t.efficiency:.9;return()=>s}if(t.kind==="ice"){let s=t.gearbox.efficiency>.01?t.gearbox.efficiency:.9;return()=>s}let r=Qi(t),n=e.gear_ratio.value,o=e.r_dyn.value,a=Math.max(1,Math.round(e.motorCount??e.driven_wheels.value));return(s,i)=>{let c=s*n/o*(60/ly),l=Math.max(0,i*o/(n*a)),u=r.efficiency(c,l);return u>.01?u:.5}}var lF=e=>Math.max(0,2-1/e);function ZV(e){let t=e.motorModel;if(t?.kind!=="map"){let a=lF(ap(e)(0,0));return()=>a}let r=Qi(t),n=e.gear_ratio.value,o=e.r_dyn.value;return(a,s,i)=>{let c=a*n/o*(60/ly),l=Math.max(0,s*o/(n*Math.max(1,i))),u=r.efficiency(c,l);return lF(u>.01?u:.5)}}var uF=new WeakMap;function ui(e){if(e.batteryModel)return e.batteryModel;let t=e.capacity.value,r=e.ocv.value,n=uF.get(e);if(n&&n.capacityAh===t&&n.ocv===r)return n.model;let o=Vh(t,r);return uF.set(e,{capacityAh:t,ocv:r,model:o}),o}function pF(e){let t=e.params,r=c0(t,pd(e));if(yt(t.motorModel)||Wt(t).mode!=="hydraulic")return r;let n;return(o,a,s,i=0)=>{if(!(o>0))return JV;n??=e3(e);let c=Rd(n.inp,n.ev,o,a,i);if(!c)return r(o,a,s);let l=c.regenFront+c.regenRear,u=Math.min(o,l),m=l>0?u/l:0;return{front:c.regenFront*m,rear:c.regenRear*m,total:u}}}function fF(e){let t=pF(e);return(r,n,o,a)=>t(r,n,o,a).total}var JV={front:0,rear:0,total:0},mF=new WeakMap;function e3(e){let t=e.params,r=mF.get(t);if(!r){let n=Gn(t);r={inp:Ut(n.regen?t:{...t,energy:{...n,regen:!0}}),ev:pn(t)},mF.set(t,r)}return r}var Cl=e=>e.airTempC??ur;function sp(e,t){return e.thermal?e.thermal.startC??t:ps}function dF(e,t,r,n,o,a){let s=e.thermal;if(!s||!(o>0)||!(s.heatCapacityJPerK>0))return t;let i=s.coolingWPerK*(t-a)*o,c=s.entropicVPerK!==0?-r*(t+273.15)*s.entropicVPerK*o:0;return t+(n+c-i)/s.heatCapacityJPerK}var hF=()=>({windingC:[],derate:[],lossW:[],torqueNm:[],ampsRms:[]});function t3(e){let t=e.motorModel;if(yt(t))return;let r=t?Qi(t).maxTorque:s=>ot(e.motor.rpm,e.motor.torque,s),n=e.gear_ratio.value,o=e.r_dyn.value,a=Math.max(1,Math.round(e.motorCount??e.driven_wheels.value));return{rpm:s=>s*n/o*(60/ly),peak:r,torque:(s,i,c)=>{let l=Math.min(Math.abs(s)*o/(n*a),c*r(i));return s<0?-l:l}}}function r3(e,t){let r=e.motorModel?.thermal;if(!r||!t)return;let n=r.torqueConstant;return{...t,th:Bh(r),amps:o=>n>0?Math.abs(o)/n:0}}function n3(e,t,r,n,o){let a=e.ocv(n);if(!(r>0))return{dq:t/a,lossJ:0,energyJ:t,short:!1,cutoff:!1,seconds:r};let s=e.maxPower(n,o),i=s.watts,c=t/r,l=Math.min(c,i),u=c>s.voltageFloor;if(u&&!(l>0))return{dq:1/0,lossJ:0,energyJ:0,short:!0,cutoff:u,seconds:1/0};let m=e.currentFor(l,n,o),p=u?c/l:1,d=r*p;return{dq:m*d,lossJ:m*m*e.resistance(n,o)*d,energyJ:l*d,short:c>i,cutoff:u,seconds:d}}function o3(e,t,r,n,o){let a=e.ocv(n);if(!(r>0))return{dq:t/a,lossJ:0,energyJ:t,short:!1,cutoff:!1,seconds:r};let s=e.resistance(n,o),i=e.chargeCurrentFor(t/r,n,o),c=Math.min(i,e.chargeCurrentCeiling),l=c===i?t:c*(a+c*s)*r;return{dq:c*r,lossJ:c*c*s*r,energyJ:l,short:c<i,cutoff:!1,seconds:r}}function a3(e,t,r,n,o){let a=e.resistance(n,o);return{energyJ:t*(e.ocv(n)+t*a)*r,lossJ:t*t*a*r}}function s3(e){let{drivenFront:t,drivenRear:r}=Ma(e);return ka(e.params,t,r)}function mi(e,t,r,n,o=Kr,a,s,i,c,l,u){let m=e.params,p=m.rho.value,d=m.fr_0.value,f=m.m.value,h=e.FG,b=m.aeroModel?Ut(m):void 0,g=ap(m),y=Cn(ui(m)),x=y.chargeC,R=m.motorModel?.kind==="ice",v=cy(a??(R?1:m.soc.value)),S=Cl(m),A=s??sp(y,S),F=A,w=0,T=0,M=0,k=0,C=-1,P=-1,L=-1,E=i||m.motorModel?.thermal?t3(m):void 0,_=r3(m,E),D=_?_.th.startC:0,I=D,N=0,O=1,V=-1,H=0,U=0,G=pF(e),B=ZV(m),q=dr(m),re=u?.scrub,W=s3(e),z=re?f/W.tractionFactor:0,Y=W.effective-f,te=Math.min(t.length,r.length);for(let j=0;j<te;j++){let X=r[j],le=X*X,pe=n[j]-(c?.[j]??0),{cl:ue,cw:ie,A:ke}=Jd(m,X,pe/9.81,b),Ie=.5*p*ue*ke*le,Ke=.5*p*ie*ke*le,oe=(h+Ie)*-d,se=re?-z*(re[j]??0):0,xe=oe+Ke+se+f*pe;Y>0&&(xe+=Y*n[j]);let fe=xe*t[j];l?.driveN?.push(xe>0?xe:0);let Fe=j+1<r.length?r[j+1]:X,Re=.5*(X+Fe),ae=Re>0?t[j]/Re:0,Me=0,be=v,ge=A,ye=0,ce=0,Ae=ae;if(R){xe>0&&(ce=fe/g(X,xe),w+=ce/Fl),l?.netKwh.push(w-T),l?.powerKw?.push(ae>0?ce/ae/1e3:0);continue}if(xe>0){let Se=fe/g(X,xe),ve=n3(y,Se,ae,v,A);ve.short&&C<0&&(C=j),ve.cutoff&&P<0&&(P=j);let wt=v*x,qe=Math.min(ve.dq,wt),It=ve.dq>0?qe/ve.dq:1;qe>=wt&&L<0&&(L=j),w+=ve.energyJ*It/Fl,ce=ve.energyJ*It,Ae=ve.seconds,M+=ve.lossJ*It,k+=qe,ae>0&&(ye=qe/ve.seconds),v=cy(v-qe/x),A=dF(y,A,ve.dq>0&&ae>0?qe/ae:0,ve.lossJ*It,ae,S),A>F&&(F=A),Me=xe}else if(o.regen){let Se=u?mt(u.ay[j],u.bank?.[j]??0)/9.81:0,ve=G(-xe,X,pe/9.81,Se),wt=ve.total,It=(B(X,ve.front,q.front)*ve.front+B(X,ve.rear,q.rear)*ve.rear)*t[j],Pe=o3(y,It,ae,v,A),_e=(1-v)*x,He=Math.min(Pe.dq,_e),Ee=Pe.dq>0?He/Pe.dq:1,ze=He<Pe.dq&&ae>0?a3(y,He/ae,ae,v,A):void 0,qt=ze?ze.energyJ:Pe.energyJ*Ee,Ft=ze?ze.lossJ:Pe.lossJ*Ee;T+=qt/Fl,ce=-qt,M+=Ft,k-=He,ae>0&&(ye=-He/ae),v=cy(v+He/x),A=dF(y,A,He>0&&ae>0?-He/ae:0,Ft,ae,S),A>F&&(F=A),Me=-wt*Ee}if(l?.netKwh.push(w-T),l?.powerKw?.push(ae>0?ce/Ae/1e3:0),l?.pack){let Se=l.pack;Se.soc.push(be),Se.amps.push(ye),Se.volts.push(y.ocv(be)-ye*y.resistance(be,ge)),Se.cellC.push(ge)}if(_){let Se=_.rpm(X),ve=_.th.derate(Se,D,_.peak(Se));ve<O&&(O=ve),ve<1&&V<0&&(V=j),U+=ae,ve<1&&(H+=ae);let wt=_.torque(Me,Se,ve),qe=_.th.lossW(Se,wt,D);N+=qe*ae,i&&(i.windingC.push(D),i.derate.push(ve),i.lossW.push(qe),i.torqueNm.push(wt),i.ampsRms.push(_.amps(wt))),D=_.th.step(D,qe,ae),D>I&&(I=D)}else E&&i&&i.torqueNm.push(E.torque(Me,E.rpm(X),1))}return{drive:w,regen:T,net:w-T,chargeAh:k/3600,loss:M/Fl,socEnd:v,shortAt:C,cutoffAt:P,emptyAt:L,tempEndC:A,tempMaxC:F,..._?{motorTempEndC:D,motorTempMaxC:I,motorLossKwh:N/Fl,motorDerateMin:O,motorDerateAt:V,motorDerateTimeFrac:U>0?H/U:0}:{}}}var i3=.5,c3=.02,l3=6;function bF(e,t,r,n,o,a,s,i){let c=n(),l=1,u=f=>{let h=hF(),b=mi(e,t,f.v,f.ax,r,o,a,h,s,void 0,{ay:f.ay,bank:i,...f.axScrub?{scrub:f.axScrub}:{}});return{trace:h,peak:b.motorTempMaxC??0,frac:b.motorDerateTimeFrac??0}},m=u(c);if(!m.trace.derate.length||m.frac===0)return{lap:c,solves:l,converged:!0,peakWindingC:m.peak,derateTimeFrac:m.frac};let p=m.trace.derate.slice(),d=!1;for(let f=0;f<l3;f++){let h=n(p);l++;let b=Math.abs(h.laptime-c.laptime);if(c=h,m=u(c),b<c3){d=!0;break}let g=m.trace.derate,y=new Array(p.length);for(let x=0;x<p.length;x++)y[x]=p[x]+i3*((g[x]??1)-p[x]);p=y}return{lap:c,derate:p,solves:l,converged:d,peakWindingC:m.peak,derateTimeFrac:m.frac}}var u3=.1;function gF(e){if(e.motorModel?.kind==="ice")return 0;let t=e.power_limit_kw?.value??0;return t>0?t*1e3:0}function uy(e,t,r){return e.motorModel?.kind==="ice"?1/0:Cn(ui(e)).maxPower(t??e.soc.value,r,gF(e)).watts}function ip(e,t,r,n){let o=uy(e,r,n);if(!Number.isFinite(o))return 1/0;if(o<=0)return 0;let a=Math.max(u3,t),s=ap(e),i=o*.9/a;return o*s(t,i)/a}var m3=180/Math.PI;function cp(e,t,r,n){let o=e*t,a=e*(1-t);return o/r-a/n}var lp=e=>e*9.81*m3;var d3=.1*9.81;var Qne=Math.PI/180;function up(e,t,r,n=0){let o=Xe(e,t,0,n),a=typeof r=="function"?r:r.front,s=typeof r=="function"?r:r.rear,i=.5*(a(Math.max(0,o.FL))+a(Math.max(0,o.FR))),c=.5*(s(Math.max(0,o.RL))+s(Math.max(0,o.RR))),l=i>0&&c>0?cp(e.massTotal,e.frontMassFrac,2*i,2*c):0,u=lp(l),m=u>.15?"understeer":u<-.15?"oversteer":"neutral";return{gradient:u,balance:m,cAlphaFront:i,cAlphaRear:c}}var aoe=Math.PI/180,soe=180/Math.PI;var yF=2220446049250313e-31;function h3(e){let t=e.length,r=2,n=r*r,o=!1;for(;!o;){o=!0;for(let a=0;a<t;a++){let s=0,i=0;for(let c=0;c<t;c++)c!==a&&(i+=Math.abs(e[c][a]),s+=Math.abs(e[a][c]));if(i!==0&&s!==0){let c=s/r,l=1,u=i+s;for(;i<c;)l*=r,i*=n;for(c=s*r;i>c;)l/=r,i/=n;if((i+s)/l<.95*u){o=!1;let m=1/l;for(let p=0;p<t;p++)e[a][p]*=m;for(let p=0;p<t;p++)e[p][a]*=l}}}}}function b3(e){let t=e.length;for(let r=1;r<t-1;r++){let n=0,o=r;for(let a=r;a<t;a++)Math.abs(e[a][r-1])>Math.abs(n)&&(n=e[a][r-1],o=a);if(o!==r){for(let a=r-1;a<t;a++){let s=e[o][a];e[o][a]=e[r][a],e[r][a]=s}for(let a=0;a<t;a++){let s=e[a][o];e[a][o]=e[a][r],e[a][r]=s}}if(n!==0)for(let a=r+1;a<t;a++){let s=e[a][r-1];if(s!==0){s/=n,e[a][r-1]=s;for(let i=r;i<t;i++)e[a][i]-=s*e[r][i];for(let i=0;i<t;i++)e[i][r]+=s*e[i][a]}}}for(let r=2;r<t;r++)for(let n=0;n<r-1;n++)e[r][n]=0}function g3(e){let t=e.length,r=new Array(t).fill(0),n=new Array(t).fill(0),o=0;for(let i=0;i<t;i++)for(let c=Math.max(i-1,0);c<t;c++)o+=Math.abs(e[i][c]);let a=t-1,s=0;for(;a>=0;){let i=0,c=0;do{for(c=a;c>=1;c--){let u=Math.abs(e[c-1][c-1])+Math.abs(e[c][c]);if(u===0&&(u=o),Math.abs(e[c][c-1])<=yF*u){e[c][c-1]=0;break}}let l=e[a][a];if(c===a)r[a]=l+s,n[a]=0,a--;else{let u=e[a-1][a-1],m=e[a][a-1]*e[a-1][a];if(c===a-1){let p=.5*(u-l),d=p*p+m,f=Math.sqrt(Math.abs(d));l+=s,d>=0?(f=p+(p>=0?Math.abs(f):-Math.abs(f)),r[a-1]=r[a]=l+f,f!==0&&(r[a]=l-m/f),n[a-1]=n[a]=0):(r[a-1]=r[a]=l+p,n[a]=f,n[a-1]=-f),a-=2}else{if(i===60)throw new Error("eigenvalues: QR iteration did not converge");if(i===10||i===20||i===30||i===40||i===50){s+=l;for(let g=0;g<=a;g++)e[g][g]-=l;let b=Math.abs(e[a][a-1])+Math.abs(e[a-1][a-2]);u=l=.75*b,m=-.4375*b*b}i++;let p=a-2,d=0,f=0,h=0;for(;p>=c;p--){let b=e[p][p],g=l-b,y=u-b;d=(g*y-m)/e[p+1][p]+e[p][p+1],f=e[p+1][p+1]-b-g-y,h=e[p+2][p+1];let x=Math.abs(d)+Math.abs(f)+Math.abs(h);if(d/=x,f/=x,h/=x,p===c)break;let R=Math.abs(e[p][p-1])*(Math.abs(f)+Math.abs(h)),v=Math.abs(d)*(Math.abs(e[p-1][p-1])+Math.abs(b)+Math.abs(e[p+1][p+1]));if(R<=yF*v)break}for(let b=p+2;b<=a;b++)e[b][b-2]=0,b!==p+2&&(e[b][b-3]=0);for(let b=p;b<=a-1;b++){b!==p&&(d=e[b][b-1],f=e[b+1][b-1],h=b!==a-1?e[b+2][b-1]:0,l=Math.abs(d)+Math.abs(f)+Math.abs(h),l!==0&&(d/=l,f/=l,h/=l));let g=Math.sqrt(d*d+f*f+h*h),y=d>=0?g:-g;if(y!==0){b===p?c!==p&&(e[b][b-1]=-e[b][b-1]):e[b][b-1]=-y*l,d+=y,l=d/y,u=f/y;let x=h/y;f/=d,h/=d;for(let v=b;v<=a;v++){let S=e[b][v]+f*e[b+1][v];b!==a-1&&(S+=h*e[b+2][v],e[b+2][v]-=S*x),e[b+1][v]-=S*u,e[b][v]-=S*l}let R=a<b+3?a:b+3;for(let v=c;v<=R;v++){let S=l*e[v][b]+u*e[v][b+1];b!==a-1&&(S+=x*e[v][b+2],e[v][b+2]-=S*h),e[v][b+1]-=S*f,e[v][b]-=S}}}}}}while(c<a-1&&a>=0)}return r.map((i,c)=>({re:i,im:n[c]}))}function xF(e){let t=e.length;if(t===0)return[];for(let n of e)if(n.length!==t)throw new Error("eigenvalues: matrix must be square");for(let n of e)for(let o of n)if(!Number.isFinite(o))throw new Error("eigenvalues: matrix has non-finite entries");if(t===1)return[{re:e[0][0],im:0}];let r=e.map(n=>n.slice());return h3(r),b3(r),g3(r)}function RF(e){let t=[],r=new Array(e.length).fill(!1),n=xF(e);for(let o=0;o<n.length;o++){if(r[o])continue;let{re:a,im:s}=n[o];if(s<0)continue;let i=Math.hypot(a,s);t.push({freq:i/(2*Math.PI),dampedFreq:Math.abs(s)/(2*Math.PI),dampingRatio:i>0?-a/i:0,eigenvalue:n[o]})}return t.sort((o,a)=>a.freq-o.freq)}function my(e,t){let r=e.length,n=Array.from({length:r},(c,l)=>l);for(let c=0;c<r-1;c++){let l=c,u=c,m=-1;for(let h=c;h<r;h++)for(let b=c;b<r;b++){let g=e[h][b]*e[h][b]+t[h][b]*t[h][b];g>m&&(m=g,l=h,u=b)}if(!(m>0))break;if([e[c],e[l]]=[e[l],e[c]],[t[c],t[l]]=[t[l],t[c]],u!==c){for(let h=0;h<r;h++)[e[h][c],e[h][u]]=[e[h][u],e[h][c]],[t[h][c],t[h][u]]=[t[h][u],t[h][c]];[n[c],n[u]]=[n[u],n[c]]}let p=e[c][c],d=t[c][c],f=p*p+d*d;for(let h=c+1;h<r;h++){let b=(e[h][c]*p+t[h][c]*d)/f,g=(t[h][c]*p-e[h][c]*d)/f;if(!(b===0&&g===0))for(let y=c;y<r;y++)e[h][y]-=b*e[c][y]-g*t[c][y],t[h][y]-=b*t[c][y]+g*e[c][y]}}let o=new Array(r).fill(0),a=new Array(r).fill(0);o[r-1]=1;for(let c=r-2;c>=0;c--){let l=e[c][c],u=t[c][c],m=l*l+u*u;if(!(m>0))continue;let p=0,d=0;for(let f=c+1;f<r;f++)p+=e[c][f]*o[f]-t[c][f]*a[f],d+=e[c][f]*a[f]+t[c][f]*o[f];o[c]=-(p*l+d*u)/m,a[c]=-(d*l-p*u)/m}let s=Math.sqrt(o.reduce((c,l,u)=>c+l*l+a[u]*a[u],0)),i=new Array(r);for(let c=0;c<r;c++)i[n[c]]={re:o[c]/s,im:a[c]/s};return i}function y3(e,t){let r=e.map((o,a)=>o.map((s,i)=>a===i?s-t.re:s)),n=e.map((o,a)=>o.map((s,i)=>a===i?-t.im:0));return my(r,n)}function mp(e,t=r=>y3(e,r)){return RF(e).map(r=>({...r,vector:t(r.eigenvalue)}))}function Sa(e,t,r){let n,o=-1,a,s=-1;for(let i of e){let c=t(i.vector),l=c[r];i.eigenvalue.im===0?l>s&&(a=i,s=l):l>=Math.max(...c)&&l>o&&(n=i,o=l)}return n??a}function dy(e){let t=e.sprungMass;if(!(t>0))return;let r=Math.max(.1,e.unsprungMass),n=e.springRate*1e3,o=e.damperRate*1e3,a=e.tireRate*1e3,s=(e.tireDamping??0)*1e3,i=[[0,1,0,0],[-n/t,-o/t,n/t,o/t],[0,0,0,1],[n/r,o/r,-(n+a)/r,-(o+s)/r]];if(!i.every(l=>l.every(Number.isFinite)))return;let c=l=>{let u=t*(l[0].re**2+l[0].im**2),m=r*(l[2].re**2+l[2].im**2);return u+m>0?[u/(u+m),m/(u+m)]:[0,0]};return Sa(mp(i),c,0)}function kF(e,t,r,n){return{sprungMass:(r==="front"?t.sprungFront:t.sprungRear)/2,unsprungMass:e.unsprungCornerMass??e.unsprungPerCorner,springRate:r==="front"?e.wheelRateFront+(e.heaveSpringFront??0):e.wheelRateRear+(e.heaveSpringRear??0),damperRate:n,tireRate:xt(e,r),tireDamping:e.tireDamping}}function vF(e,t,r,n){let o=kF(e,t,r,n),a=o.sprungMass;if(a<=0)return{dampingRatio:0,criticalDamping:0,naturalFreqDamped:0};let s=r==="front"?t.rideRateFront:t.rideRateRear,i=dy(o),c=2*Math.sqrt(s*1e3*a);return{dampingRatio:i?.dampingRatio??0,criticalDamping:c/1e3,naturalFreqDamped:i?.dampedFreq??0}}function dp(e,t,r){let n=Ge(e);return{front:vF(e,n,"front",t??n.rideDampingFront),rear:vF(e,n,"rear",r??n.rideDampingRear)}}var xoe=180/Math.PI;var py=["FL","FR","RL","RR"];function x3(e,t){let r=e.chassisTorsion??0;if(!(r>0)||!Number.isFinite(r))return;let n=Math.max(0,Math.min(1,e.frontMassFrac));return{stiffness:r*(180/Math.PI),inertiaFront:e.twistInertiaFront??n*t,inertiaRear:e.twistInertiaRear??(1-n)*t,massFront:n}}function R3(e){let t=e.chassis;if(!t||!(t.stiffness>0)||!(t.inertiaFront>0)||!(t.inertiaRear>0))return;let r=t.inertiaFront+t.inertiaRear,n=t.inertiaRear/r,o=-t.inertiaFront/r;return{share:[n,n,o,o],inertia:t.inertiaFront*t.inertiaRear/r,stiffness:t.stiffness,moment:t.massFront*n+(1-t.massFront)*o}}var de={zFL:0,vzFL:1,zFR:2,vzFR:3,zRL:4,vzRL:5,zRR:6,vzRR:7,zBody:8,vzBody:9,pitch:10,pitchRate:11,roll:12,rollRate:13,x:14,vx:15,y:16,vy:17,yaw:18,yawRate:19,twist:20,twistRate:21},pp=20,MF=[de.zFL,de.zFR,de.zRL,de.zRR],SF=[de.vzFL,de.vzFR,de.vzRL,de.vzRR],fn={fzFL:0,fzFR:1,fzRL:2,fzRR:3,fzBody:4,myBody:5,mxBody:6,fx:7,fy:8,mz:9},fy=10;function di(e){let t=R3(e),r=t?pp+2:pp,n=Array.from({length:r},()=>new Array(r).fill(0)),o=Array.from({length:r},()=>new Array(fy).fill(0));n[de.zFL][de.vzFL]=1,n[de.zFR][de.vzFR]=1,n[de.zRL][de.vzRL]=1,n[de.zRR][de.vzRR]=1,n[de.zBody][de.vzBody]=1,n[de.pitch][de.pitchRate]=1,n[de.roll][de.rollRate]=1,n[de.x][de.vx]=1,n[de.y][de.vy]=1,n[de.yaw][de.yawRate]=1;let{inertia:a}=e,s=[1,0,3,2],i=(c,l,u,m)=>{c[MF[l]]-=u,c[SF[l]]-=m,c[de.zBody]+=u,c[de.vzBody]+=m,c[de.pitch]-=u*e.leverX[l],c[de.pitchRate]-=m*e.leverX[l],c[de.roll]+=u*e.leverY[l],c[de.rollRate]+=m*e.leverY[l],t&&(c[de.twist]+=u*e.leverY[l]*t.share[l],c[de.twistRate]+=m*e.leverY[l]*t.share[l])};for(let c=0;c<4;c++){let l=c<2,u=w=>w?l?w.front:w.rear:0,m=e.springRate[c]+u(e.heaveSpring),p=e.springRate[c]+u(e.arb),d=e.damperRate[c]+u(e.heaveDamper),f=e.damperRate[c]+u(e.rollDamper),h=(m+p)/2,b=(m-p)/2,g=(d+f)/2,y=(d-f)/2,x=new Array(r).fill(0);i(x,c,h,g),(b!==0||y!==0)&&i(x,s[c],b,y);let R=e.wheelMass[c],v=e.leverX[c],S=e.leverY[c],A=MF[c],F=SF[c];for(let w=0;w<r;w++){let T=x[w];T!==0&&(n[F][w]+=T/R,n[de.vzBody][w]-=T/e.bodyMass,n[de.pitchRate][w]+=v*T/a.yy,n[de.rollRate][w]-=S*T/a.xx,t&&(n[de.twistRate][w]-=S*t.share[c]*T/t.inertia))}n[F][A]-=e.tyreRate[c]/R,n[F][F]-=e.tyreDamping[c]/R,o[F][fn.fzFL+c]=1/R}return o[de.vzBody][fn.fzBody]=1/e.bodyMass,o[de.pitchRate][fn.myBody]=1/a.yy,o[de.rollRate][fn.mxBody]=1/a.xx,o[de.vx][fn.fx]=1/e.totalMass,o[de.vy][fn.fy]=1/e.totalMass,o[de.yawRate][fn.mz]=1/a.zz,t?(n[de.twist][de.twistRate]=1,n[de.twistRate][de.twist]-=t.stiffness/t.inertia,o[de.twistRate][fn.mxBody]=t.moment/t.inertia,{A:n,B:o,params:e,n:r,twist:t}):{A:n,B:o,params:e,n:r}}function Tl(e){let t=e.wheelbase/1e3,r=t*(1-e.frontMassFrac),n=t*e.frontMassFrac,o=e.trackFront/2e3,a=e.trackRear/2e3,s=e.unsprungCornerMass??e.unsprungPerCorner,i=Math.max(0,e.massTotal-4*s),c=e.wheelRateFront*1e3,l=e.wheelRateRear*1e3,u=(e.damperFront??2.5)*1e3,m=(e.damperRear??2.5)*1e3,p=xt(e,"front")*1e3,d=xt(e,"rear")*1e3,f=(e.tireDamping??0)*1e3,h=e.rollInertia??i*.6*.6,b=x3(e,h);return{bodyMass:i,totalMass:e.massTotal,wheelMass:[s,s,s,s],inertia:{xx:h,yy:e.pitchInertia??i*1.2*1.2,zz:e.yawInertia??e.massTotal*1.2*1.2},...b?{chassis:b}:{},leverX:[r,r,-n,-n],leverY:[o,-o,a,-a],springRate:[c,c,l,l],damperRate:[u,u,m,m],tyreRate:[p,p,d,d],tyreDamping:[f,f,f,f],arb:{front:e.arbFront*1e3,rear:e.arbRear*1e3},heaveSpring:{front:(e.heaveSpringFront??0)*1e3,rear:(e.heaveSpringRear??0)*1e3},rollDamper:{front:(e.rollDamperFront??0)*1e3,rear:(e.rollDamperRear??0)*1e3},heaveDamper:{front:(e.heaveDamperFront??0)*1e3,rear:(e.heaveDamperRear??0)*1e3}}}function AF(e){let t=Array.from({length:de.rollRate+1},(r,n)=>n);return e.twist?[...t,de.twist,de.twistRate]:t}function fp(e){let t=e.params,r=e.twist,n=[...t.wheelMass,t.bodyMass,t.inertia.yy,t.inertia.xx,...r?[r.inertia]:[]];if(!n.every(u=>u>0))return{};let o=AF(e),a=o.map(u=>o.map(m=>e.A[u][m]));if(!a.every(u=>u.every(Number.isFinite)))return{};let i=mp(a,u=>{let m=u.re*u.re-u.im*u.im,p=2*u.re*u.im,d=n.map((h,b)=>n.map((g,y)=>(b===y?m:0)-u.re*a[2*b+1][2*y+1]-a[2*b+1][2*y])),f=n.map((h,b)=>n.map((g,y)=>(b===y?p:0)-u.im*a[2*b+1][2*y+1]));return my(d,f)}),c=u=>{let m=n.map((d,f)=>d*(u[f].re**2+u[f].im**2)),p=m.reduce((d,f)=>d+f,0)||1;return[m[0]+m[1]+m[2]+m[3],m[4],m[5],m[6],...r?[m[7]]:[]].map(d=>d/p)},l={heave:Sa(i,c,1),pitch:Sa(i,c,2),roll:Sa(i,c,3)};return r?{...l,twist:Sa(i,c,4)}:l}function v3(e){let t={value:0,enumerable:!0};return Object.create(e,{damperFront:t,damperRear:t,heaveDamperFront:t,heaveDamperRear:t,rollDamperFront:t,rollDamperRear:t,tireDamping:t})}var k3=e=>fp(di(Tl(e))),hy=e=>e&&e.dampedFreq>0?e.freq:NaN;function by(e){let t=k3(v3(e));return{heave:hy(t.heave),pitch:hy(t.pitch),roll:hy(t.roll)}}var CF=Math.SQRT2;function wF(e,t,r){let n=e?2*Math.PI*e.freq:0,o=e&&n>0?e.dampingRatio:0,a=o>0&&o<1?Math.exp(-Math.PI*o/Math.sqrt(1-o*o))*100:0,s=o>0&&n>0?4/(o*n):1/0;return{freq:n/(2*Math.PI),dampedFreq:e&&n>0?e.dampedFreq:0,dampingRatio:o,stiffness:t,inertia:r,overshoot:a,settlingTime:s}}function hp(e){let t=Ge(e),r=e.wheelbase/1e3,n=r*(1-e.frontMassFrac),o=r*e.frontMassFrac,a=t.rollRateTotal*(180/Math.PI),s=e.rollInertia??t.sprungMass*.6*.6,i=2*t.rideRateFront*1e3,c=2*t.rideRateRear*1e3,l=i*n*n+c*o*o,u=e.pitchInertia??t.sprungMass*1.2*1.2,m=di(Tl(e)),p=fp(m),d={roll:wF(p.roll,a,s),pitch:wF(p.pitch,l,u)},f=M3(m,p.twist,e);return f?{...d,twist:f}:d}function FF(e,t,r){let n=e.params,o=n.tyreRate[t]+n.springRate[t]+r;return Math.sqrt(Math.max(0,o)/n.wheelMass[t])/(2*Math.PI)}function M3(e,t,r){let n=e.twist;if(!n||!t)return;let o=FF(e,0,e.params.arb?.front??0),a=FF(e,2,e.params.arb?.rear??0),s=Math.max(o,a),i=s>0?t.freq/s:NaN;return{freq:t.freq,dampingRatio:t.dampingRatio,freeFree:Math.sqrt(n.stiffness/n.inertia)/(2*Math.PI),hopFront:o,hopRear:a,hop:s,ratio:i,meets:i>=CF,lumped:r.twistInertiaFront===void 0||r.twistInertiaRear===void 0}}var bp=9.81,Jn=Math.PI/180;function TF(e){let t=e.wheelbase/1e3,r=t*(1-e.frontMassFrac),n=t*e.frontMassFrac;return{wb:t,lf:r,lr:n,m:e.massTotal}}function pi(e,t,r,n,o){let{wb:a,lf:s,lr:i,m:c}=TF(e),l=0;for(let x=0;x<16;x++){let R=l/r,v=o-n-s*R/r,S=-n+i*R/r,A=Xe(e,l/bp,0,r),F=Math.max(0,A.FL+A.FR),w=Math.max(0,A.RL+A.RR),T=t(v,F),M=t(S,w),k=(T*Math.cos(o)+M)/c;if(l=.5*(l+k),Math.abs(k-l)<1e-4)break}let u=l/r,m=o-n-s*u/r,p=-n+i*u/r,d=Xe(e,l/bp,0,r),f=Math.max(0,d.FL+d.FR),h=Math.max(0,d.RL+d.RR),b=t(m,f),g=t(p,h),y=s*b*Math.cos(o)-i*g;return{ay:l/bp,cn:y/(c*bp*a)}}function gy(e,t,r,n={}){let o=Math.max(8,r),a=(n.betaMaxDeg??10)*Jn,s=(n.deltaMaxDeg??10)*Jn,i=n.nLines??9,c=n.nPts??21,l=(g,y,x,R)=>x===1?g:g+(y-g)*R/(x-1),u=[],m={ay:[],cn:[]},p=0;for(let g=0;g<i;g++){let y=l(-s,s,i,g),x=[],R=[],v=[],S=[];for(let A=0;A<c;A++){let F=l(-a,a,c,A),w=pi(e,t,o,F,y);x.push(w.ay),R.push(w.cn),v.push(F/Jn),S.push(y/Jn),Math.abs(w.ay)>p&&(p=Math.abs(w.ay))}u.push({label:`\u03B4 ${(y/Jn).toFixed(0)}\xB0`,ay:x,cn:R,betaDeg:v,deltaDeg:S});for(let A=1;A<R.length;A++)if(R[A-1]===0||R[A-1]<0!=R[A]<0){let F=R[A-1]===R[A]?0:R[A-1]/(R[A-1]-R[A]);m.ay.push(x[A-1]+F*(x[A]-x[A-1])),m.cn.push(0);break}}let d=[];for(let g=0;g<i;g++){let y=l(-a,a,i,g),x=[],R=[],v=[],S=[];for(let A=0;A<c;A++){let F=l(-s,s,c,A),w=pi(e,t,o,y,F);x.push(w.ay),R.push(w.cn),v.push(y/Jn),S.push(F/Jn)}d.push({label:`\u03B2 ${(y/Jn).toFixed(0)}\xB0`,ay:x,cn:R,betaDeg:v,deltaDeg:S})}let f=.5*Jn,h=(pi(e,t,o,f,0).cn-pi(e,t,o,-f,0).cn)/(2*f),b=(pi(e,t,o,0,f).cn-pi(e,t,o,0,-f).cn)/(2*f);return{isoBeta:d,isoDelta:u,trim:m,maxAy:p,stability:h,control:b,speed:o}}function S3(e){return!e.corneringStiffnessFront||!e.corneringStiffnessRear?null:{Cf:2*e.corneringStiffnessFront,Cr:2*e.corneringStiffnessRear}}function Pl(e,t){let r=S3(e);if(!r)return null;let{Cf:n,Cr:o}=r,{wb:a,lf:s,lr:i,m:c}=TF(e),l=e.yawInertia??c*1*1,u=Math.max(3,t),m=-(n+o)/(c*u),p=(-s*n+i*o)/(c*u)-u,d=(-s*n+i*o)/(l*u),f=-(s*s*n+i*i*o)/(l*u),h=m+f,b=m*f-p*d,g=h*h-4*b,y,x,R;if(g<0)y=h/2,x=Math.sqrt(Math.max(0,b)),R=x>0?-h/(2*x):1;else{let P=Math.sqrt(g);y=Math.max((h+P)/2,(h-P)/2),x=Math.sqrt(Math.abs(b)),R=x>0?-h/(2*x):1}let v=h<0&&b>0,S=cp(c,e.frontMassFrac,n,o),A=lp(S),F=A>.15?"understeer":A<-.15?"oversteer":"neutral",w=s*n-i*o,T=P=>P*3.6,M=null,k=null;w>1e-6?k=T(Math.sqrt(n*o*a*a/(c*w))):w<-1e-6&&(M=T(Math.sqrt(n*o*a*a/(c*-w))));let C=u/(a+S*u*u);return{stable:v,yawFreq:x/(2*Math.PI),dampingRatio:R,eigReal:y,understeerGradient:A,balance:F,characteristicSpeed:M,criticalSpeed:k,yawRateGain:C}}var A3={envelopeTrim:{name:"Grip envelope, trim",code:"`solvePoint` in src/core/dynamics/twoTrack.ts (`twoTrackLimitState`, `twoTrackStateAtAy`)"},envelopeLimits:{name:"Grip envelope, limits",code:"`calcGGV` in src/core/laptime/ggv.ts"},qssLap:{name:"QSS lap",code:"`solveLap` in src/core/laptime/solver.ts, with its energy (`energyOverPath`)"},tyreReadouts:{name:"Tyre readouts",code:"`lapReserves` in src/core/dynamics/lapReserve.ts"},transientPlant:{name:"Transient plant",code:"`dynamicReplay` in src/core/dynamics/dynamicReplay.ts"},plannerRequest:{name:"Optimal, the request",code:"`planCarFrom` in src/core/plan/request.ts"},ymd:{name:"Yaw moment diagram",code:"`twoTrackYMD` in src/core/dynamics/twoTrack.ts"},stepSteer:{name:"Step steer",code:"`steerRun` in src/core/dynamics/steerRun.ts"},drive:{name:"Drive",code:"`liveCar` in src/core/drive/liveCar.ts"}},yy=Object.keys(A3),Ll=["envelopeTrim","envelopeLimits","qssLap","tyreReadouts","ymd"];var w3="the longitudinal condition is set directly; what a motor could deliver is the lap solver\u2019s question",F3="no tractive force is applied at a constant speed",xy="runs a torque-vectoring controller only when the caller hands one in (`DynamicReplayOptions.vectoring`, `SteerRunOptions.vectoring`), as the app does (`lapVectoringFor`, `steerVectoringFor` in src/app/dynamics/tvCore.ts)",Ry="Drive runs no torque vectoring: its aids are ABS and traction control",PF="the readouts split the drive by room or through the diff, never by a controller",C3=[{key:"damper_front",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"damper_rear",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",tools:Ll,why:"tyre damping acts on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic (reduced planner model)"},{key:"I_yaw",tools:["envelopeTrim","envelopeLimits","tyreReadouts","ymd"],why:"inertia resists change; a steady corner has none"},{key:"I_yaw",tools:["qssLap"],why:"inertia resists change; a steady corner has none. The quasi-transient option charges it (`calcGgvFamily`)",onCar:"quasi-transient off, as in the templates"},{key:"I_roll",tools:Ll,why:"inertia resists change; a steady corner has none"},{key:"I_roll",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no roll dynamics (reduced planner model)"},{key:"I_pitch",tools:Ll,why:"inertia resists change; a steady corner has none"},{key:"I_pitch",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no pitch dynamics (reduced planner model)"},...["I_twist_front","I_twist_rear"].flatMap(e=>[{key:e,tools:Ll,why:"inertia resists change; a steady corner has none"},{key:e,tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no twist dynamics (reduced planner model)"}]),...["capacity","ocv","soc"].flatMap(e=>[{key:e,tools:["ymd"],why:"energy does not enter a single steady-state point"},{key:e,tools:yy.filter(t=>t!=="ymd"&&t!=="qssLap"),why:"the charge reaches the forces only through a battery model\u2019s power ceiling (`packPowerW`); without one it is counted by the QSS lap\u2019s energy account, and drawn on nowhere",onCar:"no battery model"}]),{key:"tv_kp",tools:Ll,why:"the feedback gain multiplies a yaw error, and a trimmed point has none \u2014 the feedforward does move this diagram"},{key:"tv_kp",tools:["transientPlant","stepSteer"],why:xy},{key:"tv_kp",tools:["plannerRequest"],why:"the planner reads only whether torque vectoring is on, for its allocation (`longitudinalAllocation`)"},{key:"tv_kp",tools:["drive"],why:Ry},{key:"tv_enabled",tools:["transientPlant","stepSteer"],why:xy},{key:"tv_enabled",tools:["drive"],why:Ry},{key:"tv_enabled",tools:["tyreReadouts"],why:PF,gap:"the envelope corners with the feedforward, the readouts split the same lap without it (rule 3)"},...["tv_ff_low","tv_ff_high","tv_v_low","tv_v_high"].flatMap(e=>[{key:e,tools:["transientPlant","stepSteer"],why:xy},{key:e,tools:["drive"],why:Ry},{key:e,tools:["tyreReadouts"],why:PF,gap:"the envelope corners with the feedforward, the readouts split the same lap without it (rule 3)"},{key:e,tools:["plannerRequest"],why:"the planner allocates by capacity when vectoring is on, with no feedforward schedule (reduced planner model)"}]),{key:"brake_balance",tools:["ymd"],why:"no braking: the diagram is drawn at constant speed",ymd:{driving:"the diagram is drawn under acceleration, not braking",liveBraking:!0}},{key:"brake_balance",tools:["stepSteer"],why:"the speed is held by the drive; the test never brakes"},...["gear_ratio","power_scale","power_limit_kw","driven_wheels","effi_pgb"].map(e=>({key:e,tools:["ymd"],why:F3,ymd:{moving:w3}})),...["gear_ratio","power_scale","power_limit_kw"].flatMap(e=>[{key:e,tools:["envelopeTrim"],why:"the trim imposes the tyres\u2019 push (`axG`); what a motor could deliver is the envelope limits\u2019 question"},{key:e,tools:["tyreReadouts"],why:"the lap\u2019s motion carries the drive the powertrain made; the readouts only split it"},{key:e,tools:["stepSteer"],why:"the speed is held by a force (a PI loop on the drive), not through the powertrain"}]),{key:"power_scale",tools:["plannerRequest"],why:"the planner\u2019s drive is the motor model\u2019s axle force (`planDriveOf`), which `power_scale` does not scale",gap:"the envelope scales its drive by `power_scale` (`calcGGV`), the planner does not: two cars (rule 1)"},{key:"power_limit_kw",tools:["plannerRequest"],why:"the planner has no pack limit (reduced planner model)"},...["I_wheel","I_rotor"].flatMap(e=>[{key:e,tools:["ymd"],why:"rotating inertia only acts where the car changes speed",ymd:{moving:"rotating inertia is longitudinal, and `ax` is set here rather than solved \u2014 nothing in this picture spins a wheel up"}},{key:e,tools:["envelopeTrim"],why:"the trim imposes the tyres\u2019 push; rotating inertia acts where the speed changes (`rotatingInertia.ts`)"},{key:e,tools:["tyreReadouts"],why:"the lap\u2019s motion carries what the inertia cost; the readouts only split the force"},{key:e,tools:["stepSteer"],why:"no wheel rotation, and the speed is held"},{key:e,tools:["plannerRequest"],why:"the planner has no rotating inertia (reduced planner model)"}]),{key:"v_limit_endurance",tools:["ymd"],why:"a limiter constrains a lap\u2019s speed profile; this diagram is drawn at one imposed speed"},{key:"v_limit_endurance",tools:yy.filter(e=>e!=="ymd"),why:"a limiter constrains a distance event\u2019s speed profile (`runTrackLap`), and is live there (`wiring.test.ts`, LAP_KEYS)"},{key:"endurance_reserve",tools:["ymd"],why:"an energy budget sets the long event\u2019s speed ceiling; this diagram is drawn at one imposed speed"},{key:"endurance_reserve",tools:yy.filter(e=>e!=="ymd"),why:"an energy budget solves a distance event\u2019s speed ceiling (`runTrackLap`), and is live there (`wiring.test.ts`, LAP_KEYS)"},{key:"fr_0",tools:["ymd"],why:"rolling resistance is longitudinal",ymd:{moving:"rolling resistance is a drag term; `ax` is what the car does, not what the tyres are handed"}},{key:"fr_0",tools:["envelopeTrim"],why:"the trim takes the tyres\u2019 push as given; rolling resistance is a drag, not a tyre force"},{key:"fr_0",tools:["tyreReadouts"],why:"the lap\u2019s motion carries the drag (`LapMotion.axDrag`), rolling resistance in it"},{key:"fr_0",tools:["stepSteer"],why:"step steer\u2019s plant has no rolling resistance (`twoTrackSimFrom` without `rollingCoeff`), and its speed is held"},{key:"r_dyn",tools:["ymd"],why:"the rolling radius only matters where a wheel is driven or braked",ymd:{moving:"the force each tyre carries is set here in newtons; a radius would only convert it to a torque"}}];function LF(e=0){let t=[],r=new Set;for(let n of C3){if(!n.tools.includes("ymd")||n.onCar||r.has(n.key)||e<0&&n.ymd?.liveBraking)continue;r.add(n.key);let o=e>0?n.ymd?.driving??n.ymd?.moving??n.why:e<0?n.ymd?.moving??n.why:n.why;t.push({key:n.key,why:o})}return t}var DF=Math.PI/180;function _F(e,t){let r=Math.abs(e);return r<.15?"no measurable body slip \u2014 the car is travelling along its own centreline":Math.abs(t)<1e-6?`${r.toFixed(1)}\xB0 of body slip (not cornering, so there is no inside or outside yet)`:e*Math.sign(t)>0?`${r.toFixed(1)}\xB0 of body slip, nose pointing OUT of the corner \u2014 running wide of the path it is on`:`${r.toFixed(1)}\xB0 of body slip, nose pointing INTO the corner \u2014 rotated inside the path it is on`}function EF(e,t,r){return e.length<2?0:t<=0?(e[1]-e[0])/r:t>=e.length-1?(e[e.length-1]-e[e.length-2])/r:(e[t+1]-e[t-1])/(2*r)}function NF(e,t,r,n){let o=e.isoDelta.length,a=e.isoDelta[0]?.ay.length??0,s=Math.max(0,Math.min(o-1,Math.floor(t))),i=Math.max(0,Math.min(a-1,Math.floor(r))),c=Math.max(0,Math.min(1,t-s)),l=Math.max(0,Math.min(1,r-i)),u=0;for(let[m,p]of[[s,1-c],[Math.min(o-1,s+1),c]])if(!(p<=0))for(let[d,f]of[[i,1-l],[Math.min(a-1,i+1),l]])f<=0||(u+=p*f*n(e.isoDelta[m],d,m));return u}function OF(e,t,r){let n=e.isoDelta[0],o=(n.betaDeg[1]-n.betaDeg[0])*DF||1,a=e.isoDelta.length>1?(e.isoDelta[1].deltaDeg[0]-e.isoDelta[0].deltaDeg[0])*DF:1,s=S=>NF(e,t,r,S),i=s((S,A)=>S.ay[A]),c=s((S,A)=>S.cn[A]),l=s((S,A)=>S.betaDeg[A]),u=s((S,A)=>S.deltaDeg[A]),m=s((S,A)=>EF(S.cn,A,o)),p=s((S,A,F)=>EF(e.isoDelta.map(w=>w.cn[A]),F,a||1)),d=Math.max(1e-6,e.maxAy),f=Math.abs(i)/d,h=Math.max(1e-6,...e.isoDelta.flatMap(S=>S.cn.filter(Number.isFinite).map(Math.abs))),b=Math.abs(c)/h,g=i===0?c:c*Math.sign(i),y=[];y.push(`${_F(l,i)}.`),b<.03?y.push("On the trim line: yaw moments balance, so this is a steady corner the car can actually hold. Only points on this line are real cornering states \u2014 everywhere else the car is still rotating."):g>0?y.push(`Not a steady state: there is a surplus yaw moment turning the car further into the corner, so it would keep rotating from here. To hold ${Math.abs(i).toFixed(2)} g the driver would have to wind ${u>=0?"off":"on"} steer until the point reaches the trim line.`):y.push("Not a steady state: the yaw moment is straightening the car out, so it would run wide from here. The car needs more steer, or more front grip, to reach the trim line at this slip angle.");let x=Math.abs(e.stability)>1e-9?m/e.stability:1;x<.15?y.push("Yaw stiffness has collapsed here: the moment resisting a change in body slip is essentially gone, so the car will not gather itself up if it steps out. Both axles are close to saturation."):x<.85?y.push(`Yaw stiffness is down to about ${(100*x).toFixed(0)} % of its straight-ahead value \u2014 the car resists a change in body slip less firmly here than it does in the linear range.`):y.push(`Yaw stiffness is near its straight-ahead value (${(100*x).toFixed(0)} %), so the car still opposes a change in body slip about as firmly as it does in a straight line.`);let R=Math.abs(e.control),v=R>1e-9?Math.abs(p)/R:1;return v<.15?y.push("The steering has stopped working here: another degree of lock buys almost no yaw moment, which is what a saturated front axle looks like. This is understeer in its literal sense \u2014 the front tyres are already at their limit."):v<.5&&y.push(`Steering response is down to about ${(100*v).toFixed(0)} % of its straight-ahead value \u2014 the front is well into the non-linear part of its curve.`),f>.97?y.push(`At the edge of the diagram: ${Math.abs(i).toFixed(2)} g is essentially all this car has at this speed.`):f<.25&&y.push("Well inside the limit \u2014 this is the linear region the handling balance is measured in."),{ay:i,cn:c,betaDeg:l,deltaDeg:u,stability:m,control:p,gripUsed:f,notes:y}}var IF=1e-4;function vy(e){let t=null,r=p=>{if(!t)return!0;let d=Math.abs(p),f=Math.abs(t.ay);return d>f*(1+IF)?!0:d<f*(1-IF)?!1:p>0&&t.ay<0};for(let p=0;p<e.isoDelta.length;p++){let d=e.isoDelta[p];for(let f=1;f<d.cn.length;f++){if(!(d.cn[f-1]===0||d.cn[f-1]<0!=d.cn[f]<0))continue;let b=d.cn[f-1]===d.cn[f]?0:d.cn[f-1]/(d.cn[f-1]-d.cn[f]),g=d.ay[f-1]+b*(d.ay[f]-d.ay[f-1]);r(g)&&(t={ay:g,d:p,b:b<.5?f-1:f})}}if(!t)return null;let n=OF(e,t.d,t.b),o=Math.abs(e.control)>1e-9?Math.abs(n.control/e.control):1,a=Math.abs(e.stability)>1e-9?n.stability/e.stability:1,s=o<.35,i=a<.35,c=s&&i?"both":s?"front":i?"rear":o<a?"front":"rear",l=e.isoDelta[t.d].betaDeg.length,u=t.b===0||t.b===l-1||t.d===0||t.d===e.isoDelta.length-1,m=t.ay<0?-1:1;return{ay:Math.abs(t.ay),turn:m,betaDeg:e.isoDelta[t.d].betaDeg[t.b]*m,deltaDeg:e.isoDelta[t.d].deltaDeg[t.b]*m,d:t.d,b:t.b,limitedBy:c,controlFrac:o,stiffnessFrac:a,onGridEdge:u}}function VF(e=0){return LF(e)}var T3=VF(0);function BF(e=0){let t="Springs and bars act through the roll-stiffness split and the camber the wheels take in roll; a heave spring reaches it too, but only faintly, through how far aero pushes the car down onto its camber curve.";if(!e)return"Steady state, lateral only: every point is a car in equilibrium at constant speed. Dampers, inertias, brake balance and the whole powertrain therefore cannot appear here \u2014 not because they are ignored, but because nothing in this picture accelerates. "+t;let r=e<0?`braking at ${Math.abs(e).toFixed(2)} g`:`accelerating at ${e.toFixed(2)} g`,n=e<0?"the brake balance decides which axle pays for it":"the driven axle pays for it";return`Steady state, ${r}: the load has moved ${e<0?"forward":"rearward"} and every tyre is spending part of its grip longitudinally, so ${n}. Dampers and inertias still cannot appear \u2014 the attitude is constant, it is simply not level. `+t}var P3=BF(0);var L3=9.81;function D3(e){let t=e.wheelbase/1e3;return{lf:t*(1-e.frontMassFrac),lr:t*e.frontMassFrac}}function Dl(e,t,r,n){let o=t.tire;if(!o)return null;let s=(r==="limit"?I0(e,o,t.speed):So(e,o,t.speed,t.ayG)).wheels;return _n(n??la(o,e.massTotal*L3*1.2),{FL:s.FL,FR:s.FR,RL:s.RL,RR:s.RR},D3(e))}function E3(e){if(!e.tire)return e.cornerStiffness;let t=Te(e.tire,"front"),r=Te(e.tire,"rear");return{front:n=>t.corneringStiffness(n),rear:n=>r.corneringStiffness(n)}}var $F=[{key:"understeer",label:"Understeer gradient",unit:"\xB0/g",compute:(e,t)=>up(e,t.ayG,E3(t),t.speed).gradient},{key:"rollGradient",label:"Roll gradient",unit:"\xB0/g",compute:e=>Ge(e).rollGradient},{key:"pitchGradient",label:"Pitch gradient",unit:"\xB0/g",compute:e=>Ge(e).pitchGradient},{key:"tlltdFront",label:"TLLTD front",unit:"%",compute:e=>100*yc(e)},{key:"rollStiffFront",label:"Front roll-stiffness",unit:"%",compute:e=>100*Ge(e).frontRollStiffFrac},{key:"rideFreqFront",label:"Ride freq front, no dampers",unit:"Hz",compute:e=>Ge(e).rideFreqFront},{key:"rideFreqRear",label:"Ride freq rear, no dampers",unit:"Hz",compute:e=>Ge(e).rideFreqRear},{key:"rollFreqNoDampers",label:"Roll-mode freq, no dampers",unit:"Hz",compute:e=>by(e).roll},{key:"pitchFreqNoDampers",label:"Pitch-mode freq, no dampers",unit:"Hz",compute:e=>by(e).pitch},{key:"rollFreq",label:"Roll-mode freq, with dampers",unit:"Hz",compute:e=>hp(e).roll.freq},{key:"pitchFreq",label:"Pitch-mode freq, with dampers",unit:"Hz",compute:e=>hp(e).pitch.freq},{key:"zetaFront",label:"Damping \u03B6 front",unit:"-",compute:e=>dp(e).front.dampingRatio},{key:"zetaRear",label:"Damping \u03B6 rear",unit:"-",compute:e=>dp(e).rear.dampingRatio},{key:"yawFreq",label:"Yaw natural freq",unit:"Hz",compute:(e,t)=>Pl(e,t.speed)?.yawFreq??NaN},{key:"yawZeta",label:"Yaw damping \u03B6",unit:"-",compute:(e,t)=>Pl(e,t.speed)?.dampingRatio??NaN},{key:"stabilitySpeed",label:"Char./critical speed",unit:"km/h",compute:(e,t)=>{let r=Pl(e,t.speed);return r?r.criticalSpeed??r.characteristicSpeed??NaN:NaN}},{key:"maxAy",label:"Max lateral accel",unit:"g",compute:(e,t)=>t.fyAxle?gy(e,t.fyAxle,t.speed,{betaMaxDeg:12,deltaMaxDeg:12}).maxAy:NaN},{key:"yawReserveRear",label:"Yaw stability reserve",unit:"N\xB7m",compute:(e,t)=>Dl(e,t,"operating")?.stabil??NaN},{key:"yawReserveFront",label:"Yaw agility reserve",unit:"N\xB7m",compute:(e,t)=>Dl(e,t,"operating")?.agil??NaN},{key:"limitBalance",label:"Limit balance (+US / \u2212OS)",unit:"-",compute:(e,t)=>Dl(e,t,"limit")?.rel??NaN},{key:"yawStiffness",label:"Yaw stiffness N_\u03B2",unit:"N\xB7m/rad",compute:(e,t)=>t.tire?E0(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorque",label:"Steering holding torque",unit:"N\xB7m",compute:(e,t)=>t.tire?L0(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorqueGradient",label:"Steering feedback gradient",unit:"N\xB7m/g",compute:(e,t)=>t.tire?D0(e,t.tire,t.speed,t.ayG):NaN}],ky=Object.fromEntries($F.map(e=>[e.key,e]));var hn=9.81;function I3(e,t,r){let n=Math.abs(e);return n>0?t>0&&(n<=t||t>=r)?n/t:r>0?1+(n-t)/r:2:0}var _3={front:!1,rear:!0};function fi(e,t,r,n){let o=e.muX(t)*t,a=e.muY(t)*t;if(!(o>0))return 0;let s=a>0?Math.min(1,r/a):1;return n&&t>0?o*Zb(n,t,s):o*Math.sqrt(1-s*s)}function GF(e,t,r,n,o,a,s,i){let c=e[t]+e[r];if(!(c>0))return;let l=fi(n,o[t],a[t],i),u=fi(n,o[r],a[r],i),m=!(l+u>0);if(m&&(l=n.muX(o[t])*o[t],u=n.muX(o[r])*o[r]),!(l+u>0))return;let p=s?.[t],d=s?.[r];if(p===void 0&&d===void 0){e[t]=c*(l/(l+u)),e[r]=c-e[t];return}let f=[Math.min(l,p??1/0),Math.min(u,d??1/0)],h=m?void 0:KF(n,o,a,t,r,l,u,s,i);if(h&&c>f[0]+f[1]){let b=Math.min(c-h.capC,h.xMax),g=Math.min(a[h.o],h.fyO(b));a[h.c]+=a[h.o]-g,a[h.o]=g,e[h.o]=b,e[h.c]=c-b;return}e[t]=HF(c,f,[l,u])[0],e[r]=c-e[t]}function KF(e,t,r,n,o,a,s,i,c){let l=i[n]??1/0,u=i[o]??1/0,m,p,d;if(l<a&&!(u<s))[m,p,d]=[n,o,s];else if(u<s&&!(l<a))[m,p,d]=[o,n,a];else return;let f=i[m],h=i[p]??1/0,b=e.muX(t[p])*t[p],g=e.muY(t[p])*t[p],y=e.muX(t[m])*t[m],x=e.muY(t[m])*t[m];if(!(b>0&&g>0&&y>0&&x>0))return;let R=(M,k)=>c?AM(c,M,k):Math.sqrt(Math.max(0,1-k*k)),v=(M,k)=>c?Zb(c,M,k):Math.sqrt(Math.max(0,1-k*k)),S=M=>g*R(t[p],M/b),A=x*R(t[m],f/y),F=r[m]+r[p]-A,w=Math.min(h,b*v(t[p],0)),T=F<=0?w:Math.max(d,Math.min(w,F<g?b*v(t[p],F/g):0));return{c:m,o:p,capC:f,xMax:T,fyO:S}}function HF(e,t,r){let n=t.reduce((a,s)=>a+s,0),o=r.reduce((a,s)=>a+s,0);return n>0&&e<=n?t.map(a=>e*a/n):o>n&&e<=o?t.map((a,s)=>a+(e-n)*(r[s]-a)/(o-n)):r.map(a=>e*a/o)}function zF(e,t,r,n,o,a={},s="open",i,c){if(!e.rear)return 1;if(!e.front)return 0;let l=(b,g,y)=>y?qc(b,g,y):s==="own"?b+g:2*Math.min(b,g),u={FL:fi(n,t.FL,r.FL,c?.front),FR:fi(n,t.FR,r.FR,c?.front),RL:fi(o,t.RL,r.RL,c?.rear),RR:fi(o,t.RR,r.RR,c?.rear)},m=(b,g)=>u[g],p=l(u.FL,u.FR,a.front),d=l(u.RL,u.RR,a.rear);if(i&&i.total>0&&p+d>0){let b=(S,A)=>Math.min(m(S,A),i.caps[A]??1/0),g=(S,A,F,w,T)=>{let M=A==="FL"?c?.front:c?.rear,k=w||s!=="own"?void 0:KF(S,t,r,A,F,m(S,A),m(S,F),i.caps,M),C=k?k.capC+k.xMax:l(b(S,A),b(S,F),w);return[C,Math.max(T,C)]},[y,x]=g(n,"FL","FR",a.front,p),[R,v]=g(o,"RL","RR",a.rear,d);return HF(i.total,[y,R],[x,v])[0]/i.total}if(p+d>0)return p/(p+d);let f=n.muX(t.FL)*t.FL+n.muX(t.FR)*t.FR,h=o.muX(t.RL)*t.RL+o.muX(t.RR)*t.RR;return f+h>0?f/(f+h):.5}function My(e,t,r,n){return{car:t?jF(t,r.loadFactor[n]):e,ayTyre:mt(r.ay[n],r.bank?.[n]??0),axCar:r.ax[n]-(r.axGrade?.[n]??0)}}function YF(e,t){if(!e.aero?.model)return 0;let r=Math.min(t.v.length,t.ax.length,t.ay.length),n=t.loadFactor?yp(e):void 0,o=0,a=0;for(let s=0;s<r;s++){let i=t.ds?.[s]??1,c=My(e,n,t,s);o+=i,Ub(c.car,t.v[s],c.axCar/hn,c.ayTyre/hn)&&(a+=i)}return o>0?a/o:0}function WF(e,t,r){let n=$r(Te(t,"front")),o=$r(Te(t,"rear")),a=Math.min(r.v.length,r.ax.length,r.ay.length),s=r.loadFactor?yp(e):void 0,i=0,c=0;for(let l=0;l<a;l++){let u=r.ds?.[l]??1,m=My(e,s,r,l);i+=u;let p=Xe(m.car,m.ayTyre/hn,m.axCar/hn,r.v[l]);(p.FL>n||p.FR>n||p.RL>o||p.RR>o)&&(c+=u)}return i>0?c/i:0}function gp(e,t,r,n={}){let o=Math.min(r.v.length,r.ax.length,r.ay.length),a=e.wheelbase/1e3,s=a*(1-e.frontMassFrac),i=a*e.frontMassFrac,c=Qs(t,e.massTotal*hn*1.2),l=Bs(c,"front"),u=Bs(c,"rear"),m={mu:1},p=G=>({muX:B=>m.mu*G.muX(B),muY:B=>m.mu*G.muY(B)}),d=r.mu?p(l):l,f=r.mu?u===l?d:p(u):u,h=r.mu?{front:d,rear:f}:c,b=Yt(Te(t,"front")),g=Yt(Te(t,"rear")),y=Jb(b,l),x=g===b?y:Jb(g,u),R={front:y,rear:x},v=n.driven??_3,S={front:pr(e,"front",1),rear:pr(e,"rear",1)},A={front:0,rear:0},F=new Array(o),w=new Array(o),T=new Array(o),M=1/0,k=0,C=0,P=$r(b),L=$r(g),E=0,_=0,D=0,I=0,N=0,O=0,V=["FL","FR","RL","RR"],H=n.perWheel?Object.fromEntries(V.map(G=>[G,{Fz:new Array(o),alpha:new Array(o),Fy:new Array(o),Fx:new Array(o),Mz:new Array(o),used:new Array(o),FxCap:new Array(o),FyCap:new Array(o)}])):void 0,U=r.loadFactor?yp(e):void 0;for(let G=0;G<o;G++){let B=My(e,U,r,G),{ayTyre:q,axCar:re}=B,W=q/hn,z=Xe(B.car,W,re/hn,r.v[G]),Y=r.mu?op(r.mu,G):1;m.mu=Y;let te=e.massTotal*q,j=te*i/a,X=te*s/a,le=Tc(b,j/Y,z.FL,z.FR,N),pe=Tc(g,X/Y,z.RL,z.RR,O);N=le,O=pe;let ue={FL:Y*Math.abs(b.Fy(le,z.FL,0)),FR:Y*Math.abs(b.Fy(le,z.FR,0)),RL:Y*Math.abs(g.Fy(pe,z.RL,0)),RR:Y*Math.abs(g.Fy(pe,z.RR,0))},ie=(re-(r.axDrag?.[G]??0)-(r.axScrub?.[G]??0))/hn,ke=r.wheelMotor,Ie=ke?Object.fromEntries(V.flatMap(be=>ke[be]?[[be,ke[be][G]*e.massTotal]]:[])):void 0,Ke=Ie?{total:ie*hn*e.massTotal,caps:Ie}:void 0,oe=ie>0&&v.front?zF(v,z,ue,d,f,S,"own",Ke,R):0,se=r.v[G]*r.v[G],xe=e.driveline?{Fz:z,alpha:{front:le,rear:pe},curvature:se>1?r.ay[G]/se:0,seed:A,...Y!==1?{grip:Y}:{}}:void 0,fe={...T0(e,ie,r.v[G],t,W,oe,xe,Y)};ie>0&&(S.front||GF(fe,"FL","FR",d,z,ue,Ie,y),S.rear||GF(fe,"RL","RR",f,z,ue,Ie,x));let Fe=!1,Re=!1;for(let be of["FL","FR","RL","RR"]){let ge=(be==="FL"||be==="FR"?d:f).muX(z[be])*z[be];Math.abs(fe[be])>ge&&(Fe=!0),z[be]>(be==="FL"||be==="FR"?P:L)&&(Re=!0)}Re&&(C+=r.ds?.[G]??1);let ae=_n(h,{FL:{Fz:z.FL,Fy:ue.FL,Fx:fe.FL},FR:{Fz:z.FR,Fy:ue.FR,Fx:fe.FR},RL:{Fz:z.RL,Fy:ue.RL,Fx:fe.RL},RR:{Fz:z.RR,Fy:ue.RR,Fx:fe.RR}},{lf:s,lr:i});if(F[G]=ae.stabil,w[G]=ae.agil,T[G]=ae.rel,H){let be=.5*(z.FL+z.FR),ge=.5*(z.RL+z.RR),ye=d.muX(be)*be,ce=f.muX(ge)*ge;for(let Ae of V){let Se=z[Ae],ve=Ae==="FL"||Ae==="FR",wt=ve?d:f,qe=wt.muY(Se)*Se,It=wt.muX(Se)*Se,Pe=H[Ae],_e=ve?le:pe;Pe.Fz[G]=Se,Pe.alpha[G]=_e,Pe.Fy[G]=ue[Ae],Pe.Fx[G]=fe[Ae],Pe.Mz[G]=Se>0?Y*(ve?b:g).Mz(_e,Se,0):0,Pe.FxCap[G]=It,Pe.FyCap[G]=qe;let He=qe>0?Math.min(1,Math.abs(ue[Ae])/qe):0,Ee=I3(fe[Ae],It,ve?ye:ce),ze=ve?y:x,qt=ze&&Se>0?ze.reach(Se,Math.sign(fe[Ae])*Ee,He):1;Pe.used[G]=Math.hypot(He,Ee)/qt}}ae.stabil<M&&(M=ae.stabil,k=G);let Me=r.ds?.[G]??1;I+=Me,ae.diff>0&&(E+=Me),Fe&&(_+=Me),Ub(B.car,r.v[G],re/hn,W)&&(D+=Me)}return{stabil:F,agil:w,rel:T,minStabil:Number.isFinite(M)?M:0,minStabilAt:k,pastTurnoverFrac:I>0?C/I:0,understeerFrac:I>0?E/I:0,beyondFrac:I>0?_/I:0,aeroOutsideFrac:I>0?D/I:0,wheels:H}}function yp(e){return Object.create(e,{loadFactor:{value:1,writable:!0,enumerable:!0}})}function jF(e,t){return e.loadFactor=t,e}var Sy=9.81;function Ay(e,t,r,n={}){let o=r.v.length,a=e.massTotal,s=Hn(e),i=s.mode==="hydraulic",c={front:new Array(o).fill(0),rear:new Array(o).fill(0),...n.regen?{regen:new Array(o).fill(0)}:{},...i?{pFront:new Array(o).fill(0),pRear:new Array(o).fill(0),pedalN:new Array(o).fill(0)}:{}};for(let l=0;l<o;l++){let u=r.v[l],m=r.ax[l]-(r.axGrade?.[l]??0),p=m-(r.axDrag?.[l]??0)-(r.axScrub?.[l]??0),d=-a*p;if(!(d>0))continue;let f=mt(r.ay[l],r.bank?.[l]??0)/Sy,h=Math.min(.99,Math.max(.01,js(e,p/Sy,u,t,f)));c.front[l]=d*h,c.rear[l]=d*(1-h);let b=i?Rd(e,t,d,u,f):void 0;if(c.regen&&n.regen&&(c.regen[l]=b?Math.min(d,b.regenFront+b.regenRear):n.regen(d,u,m/Sy)),c.regen&&b){let g=b.regenFront+b.regenRear,y=g>0?c.regen[l]/g:0;(c.regenFront??=new Array(o).fill(0))[l]=b.regenFront*y,(c.regenRear??=new Array(o).fill(0))[l]=b.regenRear*y}if(i){let g=b?b.demand:s.demand(s.controlFor(d,u),u);c.pFront[l]=g.pFront,c.pRear[l]=g.pRear,c.pedalN[l]=g.pedalN}}return c}var Vae=Math.PI/180;var Bae=py.map(al);var $ae=[de.zFL,de.zFR,de.zRL,de.zRR];var X3=9.81,q3=.001,Q3=.6,Z3=2,QF=4;function ZF(e,t,r,n=QF){let o=Math.min(e.v.length,t.npts),{ds:a,closed:s}=t,i=r.massTotal*X3*r.wheelbase,c=J3(e.ay.slice(0,o).map((m,p)=>m/Math.max(q3,e.v[p])),a,s,n),l=new Array(o).fill(0),u=new Array(o).fill(0);if(!(i>0))return{demand:l,rdot:u};for(let m=0;m<o;m++){let p=m===0?s?o-1:-1:m-1,d=m===o-1?s?0:-1:m+1;if(p<0||d<0)continue;let f=a[p]+a[m];if(!(f>0))continue;u[m]=e.v[m]*(c[d]-c[p])/f;let h=Math.sign(c[m]);l[m]=h===0?0:h*r.yawInertia*u[m]/i}return{demand:l,rdot:u}}function J3(e,t,r,n){let o=e.length;if(!(n>0)||o<3)return e;let a=new Array(o);a[0]=0;for(let c=1;c<o;c++)a[c]=a[c-1]+t[c-1];let s=r?Math.floor((o-1)/2):o-1,i=new Array(o);for(let c=0;c<o;c++){let l=r?n:Math.min(n,a[c],a[o-1]-a[c]),u=e[c],m=1,p=0;for(let d=1;d<=s&&!(!r&&c+d>=o||(p+=t[(c+d-1)%o],!(p<l)));d++){let f=1-p/l;u+=f*e[(c+d)%o],m+=f}p=0;for(let d=1;d<=s&&!(!r&&c-d<0);d++){let f=(c-d+o)%o;if(p+=t[f],!(p<l))break;let h=1-p/l;u+=h*e[f],m+=h}i[c]=u/m}return i}function JF(e,t,r,n,o={}){let a=o.maxIter??20,s=o.tol??.001,i=Math.min(1,Math.max(.001,o.relax??Q3)),c=o.smoothM??QF,l={standingStart:o.standingStart,...o.driveDerate?{driveDerate:o.driveDerate}:{},...o.brakeFade?{brakeFade:o.brakeFade}:{},...o.vCeiling?{vCeiling:o.vCeiling}:{},...o.load?{load:o.load}:{},...o.shifts?{shifts:o.shifts}:{}},u=tr(e.steady,t,n,l),m=[u.laptime],p=new Array(t.npts).fill(0),d=p.slice(),f=u,h=0,b=!1,g=0;for(let R=0;R<a;R++){h=R+1;let v=ZF(f,t,r,c);p=v.demand.map((F,w)=>p[w]+i*(F-p[w])),d=v.rdot;let S=tr(e.steady,t,n,{...l,envelope:F=>e.at(p[F]??0)});m.push(S.laptime);let A=Math.abs(S.laptime-f.laptime);if(f=S,g=A<=s?g+1:0,g>=Z3){b=!0;break}}let y=0,x=0;for(let R=0;R<t.npts;R++)x+=t.ds[R],e.clamps(p[R]??0)&&(y+=t.ds[R]);return{...f,steady:u,demand:p,rdot:d,history:m,iterations:h,converged:b,clampedFrac:x>0?y/x:0}}var Xae=Math.PI/180;var _se=180/Math.PI;function tC(e,t,r){let n=e.length-1;if(!(r<e[n]))return t[n];let o=0,a=n;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function bB(e,t,r,n,o){let a=e.grip(o),s=t.atLock?n*n/t.ayMax:e.lockRadius,i=a*r.ayMax,c=s>0&&Number.isFinite(s)?o*o/s:1/0,l=c<i,u=l?c:i,m=l&&i>0?c/i:1,{norm:p}=e,d=h=>p.map(b=>a*tC(p,h,b*m)),f=h=>m===1?h:p.map(b=>tC(p,h,b*m));return{ayMax:u,axAccelN:d(r.axAccelN),axDecelN:d(r.axDecelN),axScrubN:d(r.axScrubN),...r.motorTyreN?{motorTyreN:r.motorTyreN.map(f)}:{},...r.motorLoss?{motorLoss:f(r.motorLoss)}:{},...r.motorGain?{motorGain:r.motorGain.map(f)}:{},atLock:l}}var gB=5,wy=1;function eo(e,t,r){let n=e.length;if(n===1||r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0;for(;o<n-2&&e[o+1]<=r;)o++;let a=e[o],s=e[o+1],i=t[o],c=t[o+1];if(n===2)return i+(r-a)/(s-a)*(c-i);let l=p=>{let d=e[p];return i*(r-s)*(r-d)/((a-s)*(a-d))+c*(r-a)*(r-d)/((s-a)*(s-d))+t[p]*(r-a)*(r-s)/((d-a)*(d-s))},u=(r-a)/(s-a),m=o===0?l(2):o+1===n-1?l(o-1):(1-u)*l(o-1)+u*l(o+2);return Math.min(Math.max(i,c),Math.max(Math.min(i,c),m))}function rC(e,t,r){let n=yB(e,t);if(!r||!(t>0))return n;let o=n(t);return a=>a<t?bB(r,e[0],o,t,a):n(a)}function yB(e,t){let r=e.filter(d=>d.atLock),n=e.filter(d=>!d.atLock),o=r.length>0&&n.length>0&&r[r.length-1].v<n[0].v,a=d=>({vs:d.map(h=>h.v),ayMax:d.map(h=>h.ayMax),radius:d.map(h=>Math.max(h.v,t)**2/h.ayMax),accel:d[0].axAccelN.map((h,b)=>d.map(g=>g.axAccelN[b])),decel:d[0].axDecelN.map((h,b)=>d.map(g=>g.axDecelN[b])),scrub:d[0].axScrubN.map((h,b)=>d.map(g=>g.axScrubN[b])),motors:d.every(h=>h.motorTyreN&&h.motorLoss)?{tyreN:d[0].motorTyreN.map((h,b)=>h.map((g,y)=>d.map(x=>x.motorTyreN[b][y]))),loss:d[0].motorLoss.map((h,b)=>d.map(g=>g.motorLoss[b])),gain:d.every(h=>h.motorGain)?d[0].motorGain.map((h,b)=>h.map((g,y)=>d.map(x=>x.motorGain[b][y]))):void 0}:void 0}),s=(d,f)=>({axAccelN:d.accel.map(h=>eo(d.vs,h,f)),axDecelN:d.decel.map(h=>eo(d.vs,h,f)),axScrubN:d.scrub.map(h=>eo(d.vs,h,f)),...d.motors?{motorTyreN:d.motors.tyreN.map(h=>h.map(b=>eo(d.vs,b,f))),motorLoss:d.motors.loss.map(h=>eo(d.vs,h,f)),...d.motors.gain?{motorGain:d.motors.gain.map(h=>h.map(b=>eo(d.vs,b,f)))}:{}}:{}});if(!o){let d=a(e);return f=>({ayMax:eo(d.vs,d.ayMax,f),...s(d,f),atLock:!1})}let i=a(r),c=a(n),l=i.vs[i.vs.length-1],u=c.vs[0],m=d=>Math.max(d,t)**2/eo(i.vs,i.radius,d),p=d=>d>=u||c.vs.length<2?eo(c.vs,c.ayMax,d):c.ayMax[0]+(c.ayMax[1]-c.ayMax[0])/(c.vs[1]-c.vs[0])*(d-u);return d=>{if(d<=l)return{ayMax:m(d),...s(i,d),atLock:!0};if(d>=u)return{ayMax:p(d),...s(c,d),atLock:!1};let f=m(d),h=p(d);return f<h?{ayMax:f,...s(i,d),atLock:!0}:{ayMax:h,...s(c,d),atLock:!1}}}function xB(e,t){let r=Math.abs(e.ayMax-t.ayMax)/Math.max(t.ayMax,1),n=Math.max(Math.abs(t.axAccelN[0]),1),o=Math.max(Math.abs(t.axDecelN[0]),1);for(let a=0;a<t.axAccelN.length;a++)r=Math.max(r,Math.abs(e.axAccelN[a]-t.axAccelN[a])/n,Math.abs(e.axDecelN[a]-t.axDecelN[a])/o,Math.abs(e.axScrubN[a]-t.axScrubN[a])/n);return r}function nC(e,t,r,n,o,a){let s=r>t?Math.max(2,Math.min(gB,Math.floor(n))):1,i=[];for(let d=0;d<s;d++)i.push(e(s===1?t:t+(r-t)*d/(s-1)));let c=rC(i,t,a),l=[],u=s,m=(d,f)=>{let h=.5*(d+f),b=e(h);u++;let g=xB(c(h),b);i.splice(i.findIndex(y=>y.v>h),0,b),c=rC(i,t,a),g>o&&l.push({lo:d,hi:h,misfit:g},{lo:h,hi:f,misfit:g})},p=i.map(d=>d.v);for(let d=0;d+1<p.length&&u<n;d++)p[d+1]-p[d]>=wy&&m(p[d],p[d+1]);if(p.length>1){let d=.5*(p[0]+p[1]);if(i.some(f=>f.v===d))for(let[f,h]of[[p[0],d],[d,p[1]]]){if(u>=n||h-f<wy)break;let b=l.findIndex(g=>g.lo===f&&g.hi===h);b>=0&&l.splice(b,1),m(f,h)}}for(;u<n&&l.length>0;){let d=0;for(let g=1;g<l.length;g++)l[g].misfit>l[d].misfit&&(d=g);let{lo:f,hi:h,misfit:b}=l.splice(d,1)[0];if(b<=o)break;h-f<wy||m(f,h)}return{anchors:i,at:c}}function oC(e,t){let r=Math.abs(t);return!(r>0)||!(e>0)?1/0:e/Math.tan(Math.min(r,1.5))}function aC(e){if(!e?.meanDeg?.length)return 0;let t=0;for(let r of e.meanDeg)t=Math.max(t,Math.abs(r));return t*Math.PI/180}var RB=2,vB=.5,El=Math.PI/180,sC=21,kB={nCoarse:11,nSteer:13,nNorm:41,nAngle:45},MB={nCoarse:11,nSteer:13,nNorm:41,nAngle:61},SB=.005,AB=.05,wB=.5,Fy=e=>e<0?0:e>1?1:e;function iC(e,t,r,n){let o=e.massTotal,a=n.nSteer??7,s=(n.drivenFront?2:0)+(n.drivenRear?2:0),i=Xe(e,0,0,r),c=Math.max(1,(i.FL+i.FR+i.RL+i.RR)/4),l=8*El,u=0,m=(b,g,y)=>{for(let x=b;x<=g;x+=y){let R=Math.abs(t.Fy(x*El,c,0));R>u&&(u=R,l=x*El)}};m(1,45,1),m(Math.max(.1,l/El-1),l/El+1,.1);let p=[],d=[],f=[],h=[];for(let b=0;b<a;b++){let g=b/(a-1),y=l*(g+Math.sin(Math.PI/2*g))/2,x=Math.abs(t.Fy(y,c,0));p.push(4*x/o),d.push(s*lr(t,c,x,!1)/o),f.push(4*lr(t,c,x,!0)/o),h.push(-4*x*Math.sin(y)/o)}return p[0]=0,{ayMax:4*u/o,ay:p,axAccel:d,axDecel:f,axScrub:h,rollover:!1}}function FB(e,t,r){if(e.engine)return;let n=xa(e.params),o=dr(e.params),a=[];for(let s of["front","rear"]){if(!(s==="front"?t:r))continue;let[i,c]=s==="front"?["FL","FR"]:["RL","RR"];if(n[s]==="independent")a.push({wheels:[i],axle:s,motors:o[s]/2},{wheels:[c],axle:s,motors:o[s]/2});else if(n[s]==="diff")a.push({wheels:[i,c],axle:s,motors:o[s]});else return}return a.length>1?a:void 0}var CB=.001;function cC(e,t){let r=e.flatMap((n,o)=>n===void 0?[]:[o]);return r.length===0?e.map(()=>t):e.map((n,o)=>{if(n!==void 0)return n;let a=r[0];for(let s of r)Math.abs(s-o)<Math.abs(a-o)&&(a=s);return e[a]})}var TB=.01,PB=.05;function lC(e,t,r,n){let o=0,a=0;for(let s of e.motors){let i=r*s.tyreN[t]*e.axAccelN[t],c=s.share>0?s.share*n:0;i>c&&(o+=i-c,a+=c)}return{short:o,theirs:a}}function Il(e,t,r,n){let o=e.motors;if(!o)return 1/0;let a=n>=1?e.axDrive:n*e.axDrive,s=r*e.axAccelN[t],{short:i,theirs:c}=lC(e,t,r,a);if(!(i>0))return s;let l=e.motorLoss?.[t]??1;if(r===1&&n>=1||!o.every(f=>f.gain)){let f=r>=1?l:l/(r+l*(1-r));return Math.max(c,s-f*i)}let u=Math.min(s,uC(e,t,r,a)),m=lC(e,t,1,e.axDrive);if(!(m.short>0))return Math.max(c,u);let d=Math.max(m.theirs,e.axAccelN[t]-l*m.short)-Math.min(e.axAccelN[t],uC(e,t,1,e.axDrive));return Math.max(c,Math.min(s,u+d*(i/m.short)))}function uC(e,t,r,n){let o=e.motors,a=r*e.axAccelN[t],s=a;for(let i=0;i<=o.length+1;i++){let c=0,l=0,u=0;for(let p of o){let d=r*p.gain[t],f=r*p.tyreN[t]*e.axAccelN[t],h=p.share>0?p.share*n:0,b=f+d*(s-a);u+=Math.min(h,b),(d>0?b<=h:b<h)?(l+=d,c+=f-d*a):c+=h}if(!(u<s))return s;if(!(l<1))return 0;let m=c/(1-l);if(!(m<s))return s;s=m}return s}function Cy(e,t,r,n,o){if(!e.motors)return 1/0;let a=t.length-1;if(!(r<t[a]))return Il(e,a,n,o);let s=0,i=a;for(;i-s>1;){let u=s+i>>1;t[u]<=r?s=u:i=u}let c=(r-t[s])/(t[i]-t[s]),l=Il(e,s,n,o);return c===0?l:l+c*(Il(e,i,n,o)-l)}function bn(e,t=!1,r="twoTrack",n,o,a=0,s=1){if(a!==0&&r==="fast")throw new Error('the fast (point-mass) envelope has no yaw balance to shift; use mode "twoTrack" for a yaw-inertia demand');let i=n??(t?MB:kB),{nCoarse:c,nSteer:l,nAngle:u}=i,m=Kn(0,1,i.nNorm).map(Y=>Math.sin(Math.PI/2*Y)),p=e.params,d=p.m.value,f=p.rho.value,h=p.fr_0.value,b=p.driven_wheels.value,g=p.power_scale.value,y=e.FG,x=Ut(p);s!==1&&(x.loadFactor=s);let R=pn(p),v=QS(0,n?.vRes??(e.engine?vB:RB),e.vMax);v[v.length-1]<e.vMax&&v.push(e.vMax);let S=e.fRad.map(Y=>Y*b),A=e.fAxle,{drivenFront:F,drivenRear:w}=Ma(e),T=ka(p,F,w),M=(Y,te,j)=>{let X=Pt(Y,te,Math.max(j,Y[0]));return Number.isFinite(X)?X:1/0},k=(Y,te)=>A?M(A.vVehicle,Y,te):1/0,C=r==="fast"?void 0:FB(e,F,w),P=dr(p),L=(Y,te)=>{if(A){let X=k(A.fFront,te),le=k(A.fRear,te),pe=Y.map(ie=>(ie.axle==="front"?X:le)*(ie.motors/P[ie.axle])),ue=pe.reduce((ie,ke)=>ie+ke,0);if(Number.isFinite(ue)&&ue>0)return pe.map(ie=>ie/ue)}let j=Y.reduce((X,le)=>X+le.motors,0);return Y.map(X=>X.motors/j)},E=Y=>{let te=Y*Y,{cl:j,cw:X,A:le}=Jd(p,Y,0,x),pe=.5*f*-X*le*te,ue=.5*f*-j*le*te,ie=h*(-ue+y);return pe+ie},_=Y=>{let te=E(Y)/d*T.powerFactor,j=E(Y)/d*T.tractionFactor,X;if(e.engine){let pe=E(Y);X=Ys(e.engine,Y,T.effective,pe,g).accel-te}else if(A){let pe=0;F&&(pe+=k(A.fFront,Y)),w&&(pe+=k(A.fRear,Y)),X=g*pe/d*T.powerFactor}else{let pe=M(e.vVehicle,S,Y),ue=g*pe/d*T.powerFactor;X=Number.isFinite(ue)?ue:1/0}let le=ip(p,Y,o)/d*T.powerFactor;return{axDrag:te,axDragTyre:j,axDrive:X,axPackCap:le,axPower:Math.min(X,le)}},D=v.map(_),I=e.vMax;for(let Y=1;Y<v.length;Y++){let te=D[Y].axDrive+D[Y].axDrag;if(te>0)continue;let j=D[Y-1].axDrive+D[Y-1].axDrag;I=j>0?v[Y-1]+(v[Y]-v[Y-1])*j/(j-te):v[Y-1];break}let N=Math.min(e.vMax,(1+AB)*I),O=r==="fast"?iC:N0,V=Y=>{let te=C?_(Y).axDrive:1/0,j=C&&Number.isFinite(te)?L(C,Y).map((fe,Fe)=>({wheels:C[Fe].wheels,cap:fe*te*d/T.tractionFactor})):void 0,X=O(x,R,Y,{drivenFront:F,drivenRear:w,nSteer:l,yawDemandCn:a,axDrag:E(Y)/d,...p.diffYaw?{diffYaw:!0}:{},...j?{motorCaps:j}:{}}),le=X.ay[0],pe=X.ay[X.ay.length-1],ue=fe=>Math.min(Math.max(fe*X.ayMax,le),pe),ie=m.map(fe=>ud(X.ay,X.axAccel,ue(fe))*T.tractionFactor),ke=m.map(fe=>ud(X.ay,X.axDecel,ue(fe))),Ie=m.map(fe=>ud(X.ay,X.axScrub,ue(fe))*T.tractionFactor),Ke=X.axAccelWheels,oe=X.axAccelHeld,se=X.axAccelWheelsHeld,xe=C&&j&&Ke&&oe?(()=>{let fe=C.map(be=>X.ay.map((ge,ye)=>be.wheels.reduce((ce,Ae)=>ce+Ke[ye][Ae],0))),Fe=fe.map(be=>{let ge=be.map((ye,ce)=>ye/Math.max(X.axAccel[ce],CB));return m.map(ye=>Pt(X.ay,ge,ue(ye)))}),Re=X.ay.map((be,ge)=>{let ye=fe.reduce((ce,Ae,Se)=>ce+Math.max(0,Ae[ge]-j[Se].cap/d),0);return ye>TB?Math.max(0,X.axAccel[ge]-oe[ge])/ye:void 0}),ae=m.map(be=>Pt(X.ay,cC(Re,1),ue(be))),Me=se?C.map((be,ge)=>{let ye=X.ay.map((ce,Ae)=>{let Se=se[Ae],ve=X.axAccel[Ae]-oe[Ae];if(!(!Se||!(ve>PB)))return(fe[ge][Ae]-be.wheels.reduce((wt,qe)=>wt+Se[qe],0))/ve});return m.map(ce=>Pt(X.ay,cC(ye,0),ue(ce)))}):void 0;return{motorTyreN:Fe,motorLoss:ae,...Me?{motorGain:Me}:{}}})():void 0;return{v:Y,ayMax:X.ayMax,axAccelN:ie,axDecelN:ke,axScrubN:Ie,...xe??{},atLock:X.atLock===!0}},H=new Map,U=Y=>{let te=H.get(Y);return te||H.set(Y,te=V(Y)),te},G=r==="fast"?0:Math.min(Pd,N),B=G;if(r!=="fast"){for(let Y=G;Y<N;Y=Math.min(N,Y+wB))if(U(Y).ayMax>0){B=Y;break}}let q=(()=>{if(r==="fast"||!(B>0))return;let Y=j=>iC(x,R,j,{drivenFront:F,drivenRear:w,nSteer:2}).ayMax,te=Y(B);return{norm:m,grip:j=>te>0?Y(j)/te:1,lockRadius:oC(x.wheelbase/1e3,aC(x.steerFront))}})(),re=nC(U,B,N,c,i.anchorTol??SB,q),W=[],z=[];for(let Y=0;Y<v.length;Y++){let te=v[Y],{axDrag:j,axDragTyre:X,axDrive:le,axPackCap:pe,axPower:ue}=D[Y],{ayMax:ie,axAccelN:ke,axDecelN:Ie,axScrubN:Ke,motorTyreN:oe,motorLoss:se,motorGain:xe,atLock:fe}=re.at(te),Fe=C&&oe&&se?L(C,te):void 0,Re=C&&oe&&Fe?C.map((ye,ce)=>({wheels:ye.wheels,share:Fe[ce],tyreN:oe[ce],...xe?{gain:xe[ce]}:{}})):void 0,ae={v:te,ayMax:ie,...fe?{atLock:fe}:{},axTyreAcc:ke[0],axTyreDec:Ie[0],axDrive:le,axPackCap:pe,axPower:ue,axDrag:j,axDragTyre:X,axAccelN:ke,axDecelN:Ie,axScrubN:Ke,...Re&&se?{motors:Re,motorLoss:se}:{}};W.push(ae);let Me=[],be=[];for(let ye=0;ye<u;ye++){let ce=Math.PI*ye/(u-1),Ae=ie*Math.cos(ce),Se=Fy(Math.abs(Math.cos(ce))),ve=Math.min(Pt(m,ke,Se)+X,ue+j,Cy(ae,m,Se,1,1)+j);Me.push({ax:ve+Pt(m,Ke,Se),ay:Ae,v:te})}for(let ye=u-1;ye>=0;ye--){let ce=Math.PI*ye/(u-1),Ae=ie*Math.cos(ce),Se=Fy(Math.abs(Math.cos(ce)));be.push({ax:Pt(m,Ie,Se)+j+Pt(m,Ke,Se),ay:Ae,v:te})}let ge=(ye,ce,Ae)=>Array.from({length:sC},(Se,ve)=>({ax:ce+(Ae-ce)*(ve+1)/(sC+1),ay:ye,v:te}));z.push([...Me,...ge(-ie,Me[Me.length-1].ax,be[0].ax),...be,...ge(ie,be[be.length-1].ax,Me[0].ax)])}return{...fC(W,m),rows:W,norm:m,surf:z}}function hi(e,t){return e?.length?t.map(r=>Rp(e,r)):t.map(()=>0)}function dC(e,t){let r=e?.[0]?.motors;if(!e||!r)return;let n={};return r.forEach((o,a)=>{o.wheels.length===1&&(n[o.wheels[0]]=t.map(s=>pC(e,s,i=>i.motors&&i.motors[a].share>0?i.motors[a].share*i.axDrive:0)))}),Object.keys(n).length?n:void 0}function Rp(e,t){let r=e.length-1;if(!(t>e[0].v))return e[0].axDrag;if(t>=e[r].v)return e[r].axDrag;let n=0,o=r;for(;o-n>1;){let s=n+o>>1;e[s].v<=t?n=s:o=s}let a=(t-e[n].v)/(e[o].v-e[n].v);return e[n].axDrag+a*(e[o].axDrag-e[n].axDrag)}function pC(e,t,r){let n=e.length-1;if(!(t>e[0].v))return r(e[0]);if(t>=e[n].v)return r(e[n]);let o=0,a=n;for(;a-o>1;){let l=o+a>>1;e[l].v<=t?o=l:a=l}let s=r(e[o]),i=r(e[a]);if(!Number.isFinite(s)||!Number.isFinite(i))return Math.max(s,i);let c=(t-e[o].v)/(e[a].v-e[o].v);return s+c*(i-s)}function fC(e,t){let r=e[e.length-1].v,n=0;for(let b of e)b.atLock&&b.v>0&&b.ayMax>0&&(n=Math.max(n,b.ayMax/(b.v*b.v)));let o=b=>{if(b<=e[0].v)return{i0:0,i1:0,t:0};if(b>=r)return{i0:e.length-1,i1:e.length-1,t:0};let g=0,y=e.length-1;for(;y-g>1;){let x=g+y>>1;e[x].v<=b?g=x:y=x}return{i0:g,i1:y,t:(b-e[g].v)/(e[y].v-e[g].v)}},a=b=>{let{i0:g,i1:y,t:x}=o(b);return{a:e[g],b:e[y],t:g===y?0:x}},s=(b,g,y)=>b===0||g===y?g:g+b*(y-g),i=(b,g,y,x)=>b===0?Pt(t,g,x):s(b,Pt(t,g,x),Pt(t,y,x)),c=(b,g)=>g>=1?b.axPower:Math.min(g*b.axDrive,b.axPackCap),l=({a:b,b:g,t:y},x,R)=>b.axScrubN?R*i(y,b.axScrubN,g.axScrubN,x):0,u=b=>b.axDragTyre??b.axDrag,m=({a:b,b:g,t:y},x,R)=>{let v=R*s(y,b.ayMax,g.ayMax);return v>0?Fy(x/v):1},p=({a:b,b:g,t:y},x,R,v)=>s(y,Cy(b,t,x,R,v),y===0?0:Cy(g,t,x,R,v))+s(y,b.axDrag,g.axDrag),d=(b,g,y=1,x=1)=>{let{a:R,b:v,t:S}=b,A=m(b,g,y),F=y*i(S,R.axAccelN,v.axAccelN,A)+s(S,u(R),u(v)),w=s(S,c(R,x),S===0?0:c(v,x))+s(S,R.axDrag,v.axDrag);return R.motors?Math.min(F,w,p(b,A,y,x))+l(b,A,y):Math.min(F,w)+l(b,A,y)},f=(b,g,y=1,x=1)=>{let{a:R,b:v,t:S}=b,A=m(b,g,y),F=i(S,R.axDecelN,v.axDecelN,A);return(x===1||F>0?y*F:x*y*F)+s(S,R.axDrag,v.axDrag)+l(b,A,y)},h=({a:b,b:g,t:y},x,R=1)=>{let v=t.length-1,S=b.axAccelN,A=g.axAccelN,F=b.axDecelN,w=g.axDecelN,T=b.axScrubN,M=g.axScrubN,k=N=>S[N]+y*(A[N]-S[N]),C=N=>F[N]+y*(w[N]-F[N]),P=N=>T?R*(T[N]+y*(M[N]-T[N])):0,L=s(y,b.ayMax,g.ayMax),E=s(y,b.axDrag,g.axDrag),_=s(y,u(b),u(g)),D=s(y,b.axPower,g.axPower),I=b.motors?N=>s(y,Il(b,N,R,1),y===0?0:Il(g,N,R,1)):null;for(let N=v;N>=0;N--){let O=I?Math.min(R*k(N)+_,D+E,I(N)+E)+P(N):Math.min(R*k(N)+_,D+E)+P(N),V=R*C(N)+E+P(N);if(!(x<=O+1e-6&&x>=V-1e-6))continue;if(N===v)return t[N]*R*L;let H=(q,re,W)=>{if(W(re))return 1;let z=(q-x)/(q-re);return z>0?Math.min(z,1):0},U=q=>x<=q+1e-6,G=q=>x>=q-1e-6,B=Math.min(H(R*k(N)+_+P(N),R*k(N+1)+_+P(N+1),U),H(D+E+P(N),D+E+P(N+1),U),H(R*C(N)+E+P(N),R*C(N+1)+E+P(N+1),G),I?H(I(N)+E+P(N),I(N+1)+E+P(N+1),U):1);return(t[N]+B*(t[N+1]-t[N]))*R*L}return 0};return{vMax:r,...n>0?{kappaMax:n}:{},axAccel:(b,g,y=1,x=1)=>d(a(b),g,y,x),axDecel:(b,g,y=1,x=1)=>f(a(b),g,y,x),ay:(b,g,y=1)=>h(a(b),g,y),scrub:(b,g,y=1)=>{let x=a(b);return l(x,m(x,g,y),y)},power:(b,g,y=1)=>{let x=a(b),{a:R,b:v,t:S}=x,F=(Number.isFinite(R.axPower)&&Number.isFinite(v.axPower)?s(S,R.axPower,v.axPower):Math.max(R.axPower,v.axPower))+s(S,R.axDrag,v.axDrag);return R.motors?Math.min(F,p(x,m(x,g,y),y,1)):F}}}function LB(e,t,r){let n=e.params,o=n.m.value,{drivenFront:a,drivenRear:s}=Ma(e),i=ka(n,a,s);return c=>ip(n,c,t,r)/o*i.powerFactor}function _l(e,t,r,n){let o=LB(t,r,n),a=e.rows.map(s=>{let i=o(s.v),c=Math.min(s.axDrive,i);return c===s.axPower&&i===s.axPackCap?s:{...s,axPackCap:i,axPower:c}});return{...fC(a,e.norm),rows:a,norm:e.norm}}var DB=[-.2,-.08,0,.06,.12,.2,.3];function hC(e,t=!1,r="twoTrack",n,o,a=DB){let s=[...new Set([...a,0])].sort((f,h)=>f-h),i=s.map(f=>bn(e,t,r,n,o,f)),c=i[s.indexOf(0)],l=s[0],u=s[s.length-1],m=f=>{if(f<=l)return{i:0,t:0};if(f>=u)return{i:s.length-1,t:0};let h=0;for(;h<s.length-2&&s[h+1]<=f;)h++;return{i:h,t:(f-s[h])/(s[h+1]-s[h])}},p=f=>{let h=b=>{let{i:g,t:y}=m(b);return{a:f[g],b:f[Math.min(f.length-1,g+1)],t:y}};return b=>{let{a:g,b:y,t:x}=h(b);if(x===0)return g;let R=(S,A)=>S+x*(A-S),v=bC(g.kappaMax,y.kappaMax);return{vMax:g.vMax,...v!==void 0?{kappaMax:v}:{},axAccel:(S,A,F=1,w=1)=>R(g.axAccel(S,A,F,w),y.axAccel(S,A,F,w)),axDecel:(S,A,F=1,w=1)=>R(g.axDecel(S,A,F,w),y.axDecel(S,A,F,w)),ay:(S,A,F=1)=>R(g.ay(S,A,F),y.ay(S,A,F)),scrub:(S,A,F=1)=>R(g.scrub?.(S,A,F)??0,y.scrub?.(S,A,F)??0)}}},d=f=>f<l||f>u;return{anchors:s,steady:c,clamps:d,at:p(i),atSoc(f,h,b){let g=i.map(y=>_l(y,f,h,b));return{anchors:s,steady:g[s.indexOf(0)],clamps:d,at:p(g)}}}}function bC(e,t){return e===void 0?t:t===void 0?e:Math.min(e,t)}function gC(e,t,r,n="twoTrack",o){let a=[...new Set([...t,1])].sort((i,c)=>i-c),s=a.map(i=>i===1?r:bn(e,!1,n,o,void 0,0,i));return{...mC(a,s),atSoc:(i,c,l)=>mC(a,s.map(u=>_l(u,i,c,l)))}}function mC(e,t){let r=e.length-1,n=1,o=0,a=0,s=0,i=1,c=0,l=0,u=f=>{if(n=1,!(f>e[0]))return void(o=0);if(f>=e[r])return void(o=r);let h=0;for(;h<r-1&&e[h+1]<=f;)h++;if(o=h,f===e[h])return;a=h+1;let b=e[h],g=e[h+1];if(r<2){n=2,c=(f-b)/(g-b),i=1-c;return}s=h===0?2:h+1===r||f-e[h-1]<e[h+2]-f?h-1:h+2;let y=e[s];n=3,i=(f-g)*(f-y)/((b-g)*(b-y)),c=(f-b)*(f-y)/((g-b)*(g-y)),l=(f-b)*(f-g)/((y-b)*(y-g))},m=f=>{let h=f(t[o]);if(n===1)return h;let b=f(t[a]);if(n===2)return i*h+c*b;let g=i*h+c*b+l*f(t[s]);return Math.min(Math.max(h,b),Math.max(Math.min(h,b),g))},p=(f,h,b,g,y)=>{if(u(f),n===1||b===0)return m(v=>y(v,b));let x=m(v=>v.ay(h,0,g));if(!(x>0))return m(v=>y(v,b));let R=b/x;return m(v=>y(v,R*v.ay(h,0,g)))},d=t.reduce((f,h)=>bC(f,h.kappaMax),void 0);return{anchors:e,...d!==void 0?{kappaMax:d}:{},axAccel:(f,h,b,g=1,y=1)=>p(f,h,b,g,(x,R)=>x.axAccel(h,R,g,y)),axDecel:(f,h,b,g=1,y=1)=>{let x=R=>p(f,h,b,g,(v,S)=>v.axDecel(h,S,g,R));return y===1?x(1):oy(x(y),x(1),y)},scrub:(f,h,b,g=1)=>p(f,h,b,g,(y,x)=>y.scrub?.(h,x,g)??0),ay:(f,h,b,g=1)=>{if(u(f),n===1||b===0)return m(v=>v.ay(h,b,g));let y=v=>b>0?v.axAccel(h,0,g):-v.axDecel(h,0,g),x=m(y);if(!(x>0))return m(v=>v.ay(h,b,g));let R=b/x;return m(v=>v.ay(h,R*y(v),g))}}}var yC=new WeakMap;function Ty(e,t){let r=yC.get(e);if(!r){let n=Gn(e).regen?fF(t??mr(e)):void 0;r={inp:Ut(e),ev:pn(e),...n?{regen:n}:{}},yC.set(e,r)}return r}function Py(e,t,r){let n=Ty(e,r);return Ay(n.inp,n.ev,t,n.regen?{regen:n.regen}:{})}function Ly(e){let t=Wt(e);if(t.mode!=="hydraulic")return null;let r=a=>a.heat?{heat:Og(a.heat,a.ratio),discs:a.discs}:void 0,n=r(t.hydraulic.front),o=r(t.hydraulic.rear);return n||o?{...n?{front:n}:{},...o?{rear:o}:{}}:null}function EB(e){let t=(r,n)=>n?r.map((o,a)=>Math.max(0,o-n[a])):r;return{front:t(e.front,e.regenFront),rear:t(e.rear,e.regenRear)}}function Dy(e,t,r,n,o,a=ur){if(!e)return null;let s=EB(t);return{...e.front?{front:od(e.front.heat,e.front.discs,s.front,r,n,o.front,a)}:{},...e.rear?{rear:od(e.rear.heat,e.rear.discs,s.rear,r,n,o.rear,a)}:{}}}var IB=.5,_B=.02,NB=6,vp=9,xC=1e-9,OB={FL:0,FR:0,RL:0,RR:0};function Ey(e){return e?[...new Set([...e.padCurve.factor,1])].sort((t,r)=>t-r):[1]}function VB(e,t,r){let n=cn(e),o=n.hydraulic;return n.mode!=="hydraulic"||!o?e:{...e,brakes:{...n,hydraulic:{...o,front:{...o.front,padMu:o.front.padMu*t},rear:{...o.rear,padMu:o.rear.padMu*r}}}}}function RC(e,t){let r=e.length;if(r===1||t<=e[0])return{i:0,t:0};if(t>=e[r-1])return{i:r-2,t:1};let n=0;for(;n<r-2&&e[n+1]<=t;)n++;return{i:n,t:(t-e[n])/(e[n+1]-e[n])}}function vC(e,t,r,n,o=()=>0){let a=Array.from({length:vp},(m,p)=>r*p/(vp-1)),s=tl(),{front:i,rear:c}=n,l=a.map(m=>{let p=o(m),d=h=>zn(h,t,m,s).limitAt(0,0,OB,p).ax,f=d(e);return i.map(h=>c.map(b=>{if(h===1&&b===1)return 1;let g=f<0?d(VB(e,h,b))/f:1;return Math.abs(g-1)<xC?1:g}))}),u=a[1]-a[0];return{share(m,p,d){if(p===1&&d===1)return 1;let f=u>0?Math.min(vp-2,Math.max(0,Math.floor(m/u))):0,h=u>0?Math.min(1,Math.max(0,(m-a[f])/u)):0,b=RC(i,p),g=RC(c,d),y=R=>{let v=l[R],S=Math.min(i.length-1,b.i+1),A=Math.min(c.length-1,g.i+1),F=v[b.i][g.i]+g.t*(v[b.i][A]-v[b.i][g.i]),w=v[S][g.i]+g.t*(v[S][A]-v[S][g.i]);return F+b.t*(w-F)},x=y(f)+h*(y(Math.min(vp-1,f+1))-y(f));return Math.abs(x-1)<xC?1:x}}}function BB(e,t){let{front:r,rear:n}=t;return(o,a)=>e.share(a,r?.[o]??1,n?.[o]??1)}var $B=e=>(e.front??[]).every(t=>t===1)&&(e.rear??[]).every(t=>t===1);function kC(e,t,r){let n=e(),o=1,a=t(n);if($B(a))return{lap:n,solves:o,converged:!0};let s={...a.front?{front:a.front.slice()}:{},...a.rear?{rear:a.rear.slice()}:{}},i=!1;for(let c=0;c<NB;c++){let l=e(BB(r,s));o++;let u=Math.abs(l.laptime-n.laptime);if(n=l,u<_B){i=!0;break}a=t(n);let m=(f,h)=>f&&h?f.map((b,g)=>b+IB*((h[g]??1)-b)):f,p=m(s.front,a.front),d=m(s.rear,a.rear);s={...p?{front:p}:{},...d?{rear:d}:{}}}return{lap:n,pads:s,solves:o,converged:i}}function Fo(e,t){let r=e.engine;if(!r||r.gears.length===0||t.length===0)return;let n=e.params,{drivenFront:o,drivenRear:a}=Ma(e),s=ka(n,o,a).effective,i=n.power_scale.value,{up:c,down:l}=Jg(r.engine.gearbox),u=r.engine.idleRpm,m=(p,d,f)=>(i*r.force(p,d)+f)/(s+r.inertiaMass(p,d));return{count:r.gears.length,up:c,down:l,kept:e0(r.engine.gearbox),limitRpm:r.engine.limitRpm,best:p=>Ys(r,p,s,Rp(t,p)*s,i).gear,share:(p,d)=>{let f=Rp(t,p),h=f*s,b=Ys(r,p,s,h,i);if(d===b.gear)return 1;let g=b.accel-f;return g>0?Math.min(1,Math.max(0,(m(p,d,h)-f)/g)):0},rpm:(p,d)=>r.slipping(p,d)?u:r.rpm(p,d),vIdle:p=>r.gears[p]?.vIdle??0}}var MC=new WeakMap;function _y(e){let t=MC.get(e.ggv);return t===void 0&&(t=Fo(e.vehicle,e.ggv.rows)??null,MC.set(e.ggv,t)),t??void 0}function GB(e){return e.gear&&e.engineRpm&&e.shifting?{gear:e.gear,rpm:e.engineRpm,shifting:e.shifting}:{}}function KB(e,t){return{v:t.v,ax:t.ax,ay:t.ay,s:e.s,x:e.x,y:e.y,...e.gradient.some(r=>r!==0)?{gradient:e.gradient}:{},...e.bank.some(r=>r!==0)?{bank:e.bank}:{},...e.z.some(r=>r!==0)?{z:e.z}:{},...e.mu.some(r=>r!==1)?{mu:e.mu}:{},...t.loadFactor?{loadFactor:t.loadFactor}:{},...t.axScrub?{axScrub:t.axScrub}:{},...GB(t)}}var Mp=class extends Error{constructor(t){super(t),this.name="EventError"}};function HB(e,t){let{ggv:r}=t,n=Bt(t.numerics),o=n.accelStep,a=Math.max(1,Math.round(e.distance/o)),s=li(r,new Array(a+1).fill(0),n);s[0].v=e.vStart??0;for(let f=0;f<s.length-1;f++){let h=s[f],b=s[f+1];h.v>=b.v||(h.ax=r.axAccel(h.v,0),b.v=Math.min(r.vMax,Math.sqrt(Math.max(0,h.v*h.v+2*h.ax*o))))}let i=_y(t),c=i?rp(s.map(f=>f.v),new Array(a).fill(o),!1,i,(f,h,b)=>r.axAccel(h,0,1,b)):void 0;if(c){for(let f=0;f<=a;f++)s[f].v=c.v[f];for(let f=0;f<a;f++)s[f].ax=(s[f+1].v*s[f+1].v-s[f].v*s[f].v)/(2*o)}let l=0;for(let f=0;f<a;f++){let h=s[f].v+s[f+1].v;h>0&&(l+=2*o/h)}let u=s.slice(0,a).map(f=>f.v),m=s.slice(0,a).map(f=>f.ax),p=new Array(a).fill(o),d=p.map((f,h)=>h*o);return{id:e.id,label:e.label,kind:e.kind,time:l,distance:a*o,laps:1,lapTime:l,trace:{v:u,ax:m,ay:new Array(a).fill(0),s:d,x:d,y:new Array(a).fill(0),...c?{gear:c.gear.slice(0,a),rpm:c.rpm.slice(0,a),shifting:c.shifting.slice(0,a)}:{}},energy:DC(t,p,[...u,s[a].v],m,1)}}function zB(e,t){let r=Math.max(1,Math.round(e.laps??1)),[n]=li(t.ggv,[1/e.radius],t.numerics),o=2*Math.PI*e.radius,a=n.v>0?o/n.v:1/0,s=t.ggv.scrub?.(n.v,Math.abs(n.ay))??0,i=DC(t,[o],[n.v,n.v],[0],r,s!==0?{ay:[n.ay],scrub:[s]}:void 0);return{id:e.id,label:e.label,kind:e.kind,time:a*r,distance:o*r,laps:r,lapTime:a,energy:i}}function Sp(e,t){return e.laps!=null?Math.max(1,Math.round(e.laps)):e.distance!=null?Math.max(1,Math.ceil(e.distance/t.length)):1}function YB(e,t){let r=e.distance!=null?t.v_limit_endurance?.value??0:0;return r>0?r/3.6:void 0}function WB(e,t){if(e.distance==null||yt(t.motorModel))return 0;let r=t.endurance_reserve?.value??0;return r>0?Math.min(r,95)/100:0}var SC=1;function TC(e,t,r,n){return{v:r.v,ax:r.ax,ay:r.ay,ds:t.ds,axDrag:hi(e.ggv.rows,r.v),...r.axScrub?{axScrub:r.axScrub}:{},axGrade:n,...t.bank?{bank:t.bank}:{}}}var AC=new WeakMap;function PC(e){let t=e.vehicle.params;if(!t.brakeFade)return null;let r=AC.get(t);if(r===void 0){let n=Ly(t),o=n?Wt(t):null;if(!n||!o||o.mode!=="hydraulic")r=null;else{let a=Ty(t,e.vehicle),s=e.ggv.rows,i=vC(a.inp,a.ev,e.vehicle.vMax,{front:Ey(o.hydraulic.front.heat),rear:Ey(o.hydraulic.rear.heat)},c=>hi(s,[c])[0]);r={discs:n,table:i}}AC.set(t,r)}return r}function jB(e,t,r){let n=e.vehicle.params,{soc:o,packTempC:a,launched:s,vCeiling:i}=r,c=e.load?.atSoc(e.vehicle,o,a),l=_y(e),u=(g,y)=>e.yaw?JF(e.yaw.family.atSoc(e.vehicle,o,a),t,e.yaw.car,e.numerics,{standingStart:s,...g?{driveDerate:g}:{},...y?{brakeFade:y}:{},...i?{vCeiling:i}:{},...c?{load:c}:{},...l?{shifts:l}:{}}):tr(_l(e.ggv,e.vehicle,o,a),t,e.numerics,{standingStart:s,...g?{driveDerate:g}:{},...y?{brakeFade:y}:{},...i?{vCeiling:i}:{},...c?{load:c}:{},...l?{shifts:l}:{}}),m=ci(t.gradient,t.npts),p=g=>n.motorThermal?bF(e.vehicle,t.ds,e.energyOpts??Kr,y=>u(y,g),o,a,m,t.bank).lap:u(void 0,g),d=PC(e);if(!d)return p();let f=Cl(n),h=r.discC??{front:f,rear:f};return kC(p,g=>{let y=Dy(d.discs,Py(n,TC(e,t,g,m),e.vehicle),g.v,t.ds,h,f);return{...y?.front?{front:y.front.padFactor}:{},...y?.rear?{rear:y.rear.padFactor}:{}}},d.table).lap}function UB(e,t){let r=YB(e,t.vehicle.params),n=WB(e,t.vehicle.params);return n>0?QB(e,t,n,r):Nl(e,t,r)}function kp(e,t){let r=e.energy?.remainingFraction??0;return e.incomplete?-t-(1-e.incomplete.lapsCompleted/Math.max(1,e.incomplete.lapsAsked)):r-t}var wC=5,XB=.1,qB=.005,FC=12;function QB(e,t,r,n){let o=Nl(e,t,n),a=1,s=(f,h,b)=>({...f,energyTarget:{reserve:r,capKmh:h===void 0?null:h*3.6,met:b,solves:a}}),i=kp(o,r);if(i>=0)return s(o,n,!0);let c=Math.min(n??1/0,t.ggv.vMax),l=c/2,u=Nl(e,t,l);a++;let m=kp(u,r);for(;m<0&&l>wC&&a<FC;)c=l,i=m,l=Math.max(wC,l/2),u=Nl(e,t,l),a++,m=kp(u,r);if(m<0)return s(u,l,!1);let d=ZB(f=>{let h=Nl(e,t,f);return{run:h,margin:kp(h,r)}},{lo:l,hi:c,atLo:{run:u,margin:m},fHi:i},FC-a);return a+=d.solves,s(d.run,d.cap,!0)}function ZB(e,t,r){let{lo:n,hi:o}=t,a=t.atLo,s=a.margin,i=t.fHi,c=0,l=0;for(;l<r&&o-n>XB&&a.margin>qB;){let u=o-n,m=Math.min(o-.05*u,Math.max(n+.05*u,n+s*u/(s-i))),p=e(m);l++,p.margin>=0?(n=m,a=p,s=p.margin,c===1&&(i/=2),c=1):(o=m,i=p.margin,c===-1&&(s/=2),c=-1)}return{cap:n,run:a.run,solves:l}}function LC(e,t,r){return r===0?e:e&&!t}function Nl(e,t,r){let n=t.track;if(!n)throw new Mp(`Event "${e.id}" needs a track.`);let o=Sp(e,n),a=e.standingStart??t.standingStart??!1,s=W=>LC(a,n.closed,W),i=t.vehicle.params,c=Cn(ui(i)),l=c.capacityAh,u=yt(i.motorModel)?1:i.soc.value,m=Cl(i),p=sp(c,m),d=0,f=0,h=0,b=0,g=!yt(i.motorModel)&&(t.energyOpts??Kr).regen,y=0,x=0,R=[],v=!1,S=-1/0,A=0,F=0,w=!1,T=-1/0,M=0,k=0,C=-1/0,P=(W,z,Y=1)=>{W.tempMaxC>C&&(C=W.tempMaxC),W.motorTempMaxC!==void 0&&(v=!0,w=!0,W.motorTempMaxC>S&&(S=W.motorTempMaxC),W.motorTempMaxC>T&&(T=W.motorTempMaxC),A+=(W.motorDerateTimeFrac??0)*z,M+=(W.motorDerateTimeFrac??0)*z,F+=(W.motorLossKwh??0)/Y,k+=(W.motorLossKwh??0)/Y)},L=null,E,_=Ly(i),D={front:m,rear:m},I=null,N=PC(t)!==null,O=(W,z)=>N&&(Math.abs(W.front-z.front)>SC||Math.abs(W.rear-z.rear)>SC),V=(W,z,Y)=>{let te=uy(i,W,z);if(I&&I.launch===Y&&!t5(te,I.pw)&&!O(D,I.discC))return I.lap;let j=jB(t,n,{soc:W,packTempC:z,launched:Y,...r?{vCeiling:r}:{},...N?{discC:D}:{}});return I={pw:te,launch:Y,discC:D,lap:j},j},H=ci(n.gradient,n.npts),U=(W,z,Y)=>mi(t.vehicle,n.ds,W.v,W.ax,t.energyOpts,z,Y,void 0,H,void 0,{ay:W.ay,bank:n.bank,...W.axScrub?{scrub:W.axScrub}:{}}),G=new WeakMap,B=(W,z)=>{let Y=G.get(W);return Y||(Y=Py(i,TC(t,n,W,H),t.vehicle),G.set(W,Y)),Dy(_,Y,W.v,n.ds,z,m)},q=(W,z,Y)=>{let te=`${(100*Y/n.npts).toFixed(0)} % of the way through lap ${W+1}`,j=z.cutoffAt>=0&&z.cutoffAt<=z.emptyAt;return{lapsCompleted:W,lapsAsked:o,why:j?`the pack reached its ${c.voltageFloor.toFixed(0)} V cut-off ${te}`:`the pack ran out ${te}`}};for(let W=0;W<o;W++){if(u<=0){E={lapsCompleted:W,lapsAsked:o,why:"the pack was empty"};break}let z=s(W),Y=u,te=p;w=!1,T=-1/0,M=0,k=0,C=-1/0;let j=V(u,p,z),X=U(j,u,p);if(X.emptyAt>=0){E=q(W,X,X.emptyAt);break}let pe=V(X.socEnd,X.tempEndC,z).laptime-j.laptime,ue,ie,ke,Ie,Ke,oe,se=p,xe=-1,fe=null,Fe=1;if(pe<=Iy)ue=j.laptime,ie=X.net,ke=X.drive,Ie=X.regen,Ke=X.loss,oe=X.chargeAh,se=X.tempEndC,P(X,ue),Fe=1;else{let ae=Math.min(JB,Math.max(2,Math.ceil(pe/(2*Iy))));Fe=ae;let Me=u,be=p;ue=0,ie=0,ke=0,Ie=0,Ke=0,oe=0;for(let ge=0;ge<ae;ge++){let ye=V(Me,be,z),ce=U(ye,Me,be),Ae=ce.emptyAt>=0?ce.emptyAt/n.npts:1;if(Ae*ae<1){xe=Math.round(n.npts*(ge/ae+Ae)),fe=ce;break}if(ue+=ye.laptime/ae,P(ce,ye.laptime/ae,ae),ie+=ce.net/ae/Ae,ke+=ce.drive/ae/Ae,Ie+=ce.regen/ae/Ae,Ke+=ce.loss/ae/Ae,oe+=ce.chargeAh/ae/Ae,Me-=ce.chargeAh/ae/Ae/l,be+=(ce.tempEndC-be)/ae,Me<=0){xe=Math.round(n.npts*(ge+1)/ae),fe=ce;break}}if(se=be,xe>=0&&fe){E=q(W,fe,xe);break}u=Me}d+=ue,f+=ie,h+=ke,b+=Ie,y+=Ke,x+=oe,pe<=Iy&&(u=X.socEnd),p=se;let Re=_?B(j,D):null;Re&&(D={front:Re.front?.endC??D.front,rear:Re.rear?.endC??D.rear}),R.push({lap:W+1,time:ue,elapsed:d,entryTime:j.laptime,socStart:Y,socEnd:u,packTempStartC:te,packTempEndC:p,packTempMaxC:Number.isFinite(C)?C:te,energyKwh:ie,driveKwh:ke,...g?{regenKwh:Ie}:{},lossKwh:Ke,chargeAh:oe,launched:z,substeps:Fe,...r?{vCeiling:r}:{},...w?{motor:{peakWindingC:T,derateTimeFrac:ue>0?M/ue:0,lossKwh:k}}:{},...Re?{brakes:{...Re.front?{front:CC(Re.front)}:{},...Re.rear?{rear:CC(Re.rear)}:{}}}:{}}),L=j}if(!L){let W=_y(t);L=tr(_l(t.ggv,t.vehicle,u),n,t.numerics,{standingStart:a,...t.load?{load:t.load.atSoc(t.vehicle,u)}:{},...W?{shifts:W}:{}}),E=E??{lapsCompleted:0,lapsAsked:o,why:"the pack was empty"}}let re=R.length;return{id:e.id,label:e.label,kind:e.kind,time:d,distance:n.length*re,laps:re,lapTime:L.laptime,trace:KB(n,L),energy:{consumed:f,drive:h,...g?{regen:b}:{},loss:y,...yt(i.motorModel)?{}:{native:{value:x,unit:"Ah"}},remainingFraction:yt(i.motorModel)?1:u,...v?{motor:{peakWindingC:S,derateTimeFrac:d>0?A/d:0,lossKwh:F}}:{}},lapLog:R,...E?{incomplete:E}:{}}}var Iy=.05;function CC(e){let t=r=>e.workJ>0?r/e.workJ:0;return{startC:e.startC,endC:e.endC,maxC:e.maxC,workKj:e.workJ/1e3,coldShare:t(e.coldWorkJ),hotShare:t(e.hotWorkJ)}}var JB=4,e5=.001;function t5(e,t){return e===t?!1:!Number.isFinite(e)||!Number.isFinite(t)?!0:Math.abs(e-t)>e5*Math.max(1,Math.abs(t))}function DC(e,t,r,n,o,a){return r5(e,t,o,()=>({v:r,ax:n,...a?{lateral:a}:{}}))}function r5(e,t,r,n){let o=e.energyOpts,a=e.vehicle.params.soc.value,s=0,i=0,c=0,l=0,u=0;for(let p=0;p<r;p++){let d=n(p),f=mi(e.vehicle,t,d.v,d.ax,o,a,void 0,void 0,void 0,void 0,d.lateral);s+=f.net,i+=f.drive,c+=f.regen,l+=f.loss,u+=f.chargeAh,a=f.socEnd}if(yt(e.vehicle.params.motorModel))return{consumed:s,drive:i,loss:l,remainingFraction:1};let m=(o??Kr).regen;return{consumed:s,drive:i,...m?{regen:c}:{},loss:l,native:{value:u,unit:"Ah"},remainingFraction:a}}function EC(e,t){switch(e.kind){case"straightLineAccel":return HB(e,t);case"constantRadius":return zB(e,t);case"trackLap":return UB(e,t)}}function Ny(e,t){let r={};for(let n of e)r[n.id]=EC(n,t);return r}function IC(e,t){if(e.kind!=="trackLap")return e;let{distance:r,...n}=e;return{...n,laps:Math.max(1,Math.round(t))}}function Aa(e,t,r,n,o="twoTrack",a){let s=1/0,i=-1/0;for(let p of r){let d=Al(p);if(!d)continue;let f=Jw(d,tr(t,p,n).v);f&&(s=Math.min(s,f.lo),i=Math.max(i,f.hi))}if(!(i>=s))return;let c=eF({lo:s,hi:i}),l=c.join(","),u=a?.get(l);if(u)return u;let m=gC(e,c,t,o);return a?.set(l,m),m}var Ol=e=>e.distance/Math.max(1,e.laps);function Vl(e){let t=e.s.length,r=new Array(t);for(let n=0;n<t;n++)r[n]=(n<t-1?e.s[n+1]:e.length)-e.s[n];return r}var n5=e=>e.v.map(t=>t*3.6),o5=e=>e.ax.map(t=>t/9.81),a5=e=>e.ay.map(t=>t/9.81),s5=e=>e.ay.map((t,r)=>e.v[r]>1e-6?t/(e.v[r]*e.v[r]):0),Ap=(e,t,r)=>e?.slice()??new Array(t.s.length).fill(r),i5=e=>Ap(e.z,e,0),c5=e=>e.gradient?e.gradient.map(t=>100*Math.tan(t*Math.PI/180)):Ap(void 0,e,0),l5=e=>Ap(e.bank,e,0),u5=e=>Ap(e.mu,e,1);function m5(e){let t=e.s.length,r=Vl(e),n=new Array(t);n[0]=0;for(let o=1;o<t;o++)n[o]=n[o-1]+2*r[o-1]/(e.v[o-1]+e.v[o]);return n}var Oy=[{name:"s",unit:"m",what:"distance along the lap"},{name:"ds",unit:"m",what:"length of the segment starting at this sample"},{name:"t",unit:"s",what:"elapsed time"},{name:"v",unit:"m/s",what:"speed"},{name:"speed",unit:"km/h",what:"speed"},{name:"ax",unit:"m/s\xB2",what:"longitudinal acceleration"},{name:"ay",unit:"m/s\xB2",what:"lateral acceleration"},{name:"axg",unit:"g",what:"longitudinal acceleration"},{name:"ayg",unit:"g",what:"lateral acceleration"},{name:"curv",unit:"1/m",what:"signed curvature, ay/v\xB2"},{name:"z",unit:"m",what:"elevation of the road"},{name:"grade",unit:"%",what:"grade of the road, uphill +"},{name:"bank",unit:"\xB0",what:"bank of the road, left side up +"},{name:"grip",unit:"-",what:"grip scale of the road, 1 = the tyre\u2019s own"}];function _C(e){let t=Vl(e);return{ds:t,vars:{s:e.s,ds:t,t:m5(e),v:e.v,speed:n5(e),ax:e.ax,ay:e.ay,axg:o5(e),ayg:a5(e),curv:s5(e),z:i5(e),grade:c5(e),bank:l5(e),grip:u5(e)}}}function wp(e){let t=e.rows?dC(e.rows,e.v):void 0;return{v:e.v,ax:e.ax,ay:e.ay,ds:e.ds,...e.rows?{axDrag:hi(e.rows,e.v)}:{},...e.axScrub?{axScrub:e.axScrub}:{},axGrade:ci(e.gradient,e.v.length),...e.bank?{bank:e.bank}:{},...e.loadFactor?{loadFactor:e.loadFactor}:{},...e.mu?.some(r=>r!==1)?{mu:e.mu}:{},...t?{wheelMotor:t}:{}}}function NC(e,t){return wp({v:e.v,ax:e.ax,ay:e.ay,ds:Vl({s:e.s,length:t}),gradient:e.gradient,bank:e.bank,loadFactor:e.loadFactor})}function OC(e,t){let r=Ut(e);return{pastTurnover:WF(r,pn(e),t),...e.aeroModel?{aeroOutside:YF(r,t)}:{}}}var Fp="Flying lap";function Vy(e,t){return e.kind!=="trackLap"||e.label!==Fp?e.label:e.standingStart??t?"Run":e.label}function d5(e){let t=Ut(e);return{yawInertia:t.yawInertia??0,massTotal:t.massTotal,wheelbase:t.wheelbase/1e3}}function p5(e,t,r){let n=e.params,o=n.ggvMode??"twoTrack",a=n.quasiTransient?hC(e,!1,o):null,s=a?a.steady:bn(e,!1,o),i=t?Aa(e,s,[t],r,o):void 0;return{ggv:s,...a?{yaw:{family:a,car:d5(n)}}:{},...i?{load:i}:{}}}function f5(e,t){let r=t.lapCounts,n=t.standingStart??!1,o=!1,a=e.events.map(s=>{let i=r?.[s.id]!=null?IC(s,r[s.id]):s,c=Vy(i,n),l=c===i.label?i:{...i,label:c};return l!==s&&(o=!0),l});return o?a:e.events}function h5(e,t,r){let n=r.lapCounts;if(!(!n||!r.track))for(let o of t.events){let a=n[o.id];if(o.kind!=="trackLap"||a==null)continue;let s=Sp(o,r.track),i=Math.max(1,Math.round(a));i!==s&&e[o.id]&&(e[o.id]={...e[o.id],lapsOverridden:{asked:i,defined:s}})}}function b5(e,t){for(let[r,n]of Object.entries(e))n.trace&&(e[r]={...n,...OC(t,NC(n.trace,Ol(n)))})}function Bl(e,t,r={}){let n=mr(e),o=p5(n,r.track,r.numerics),{ggv:a}=o,s=Ny(f5(t,r),{vehicle:n,...o,track:r.track,energyOpts:Gn(e,r.energyOpts),numerics:r.numerics,standingStart:r.standingStart});return h5(s,t,r),b5(s,n.params),{name:e.name,rulesetId:t.id,events:s,ggv:a}}function By(e){return{...e,ggv:{rows:e.ggv.rows,vMax:e.ggv.vMax,surf:e.ggv.surf}}}var $y=["<","<=",">",">=","==","!="],it=class extends Error{at;constructor(t,r){super(t),this.name="ExprError",this.at=r}},$l=e=>e>="0"&&e<="9",VC=e=>/[A-Za-z_]/.test(e),g5=e=>/[A-Za-z0-9_]/.test(e);function y5(e){let t=[],r=0;for(;r<e.length;){let n=e[r];if(n===" "||n===" "||n===`
|
|
224
|
-
`||n==="\r"){r++;continue}if($l(n)||n==="."&&$l(e[r+1]??"")){let o=r;for(;r<e.length&&($l(e[r])||e[r]===".");)r++;if(e[r]==="e"||e[r]==="E"){let i=r;if(r++,(e[r]==="+"||e[r]==="-")&&r++,$l(e[r]??""))for(;r<e.length&&$l(e[r]);)r++;else r=i}let a=e.slice(o,r),s=Number(a);if(!Number.isFinite(s))throw new it(`"${a}" is not a number`,o);t.push({t:"num",value:s,at:o});continue}if(VC(n)){let o=r;for(;;){for(;r<e.length&&g5(e[r]);)r++;if(e[r]==="."&&VC(e[r+1]??""))r++;else break}t.push({t:"name",value:e.slice(o,r),at:o});continue}if("<>=!".includes(n)){let o=e.slice(r,r+2);if($y.includes(o)){t.push({t:"op",value:o,at:r}),r+=2;continue}if(n==="<"||n===">"){t.push({t:"op",value:n,at:r}),r++;continue}throw new it(n==="="?'Compare with "==", not "="':'Write not(x) rather than "!x"',r)}if("+-*/^(),".includes(n)){t.push({t:"op",value:n,at:r}),r++;continue}throw new it(`"${n}" is not something this expression can contain`,r)}return t.push({t:"end",at:e.length}),t}function Gy(e){let t=y5(e),r=0,n=()=>t[r],o=h=>{let b=n();return b.t==="op"&&b.value===h},a=h=>o(h)?(r++,!0):!1,s=(h,b)=>{if(!a(h))throw new it(`Expected ${b} here`,n().at)};function i(){let h=c(),b=n();if(b.t!=="op"||!$y.includes(b.value))return h;r++;let g={kind:"binary",op:b.value,left:h,right:c(),at:b.at},y=n();if(y.t==="op"&&$y.includes(y.value))throw new it("Comparisons do not chain \u2014 write and(a < b, b < c)",y.at);return g}function c(){let h=l();for(;;){let b=n().at;if(a("+"))h={kind:"binary",op:"+",left:h,right:l(),at:b};else if(a("-"))h={kind:"binary",op:"-",left:h,right:l(),at:b};else return h}}function l(){let h=u();for(;;){let b=n().at;if(a("*"))h={kind:"binary",op:"*",left:h,right:u(),at:b};else if(a("/"))h={kind:"binary",op:"/",left:h,right:u(),at:b};else return h}}function u(){return a("-")?{kind:"unary",op:"-",arg:u()}:a("+")?u():m()}function m(){let h=p(),b=n().at;return a("^")?{kind:"binary",op:"^",left:h,right:u(),at:b}:h}function p(){let h=n();if(h.t==="num")return r++,{kind:"num",value:h.value};if(h.t==="name"){if(r++,a("(")){let b=[];if(!o(")"))do b.push(i());while(a(","));return s(")","a closing bracket"),{kind:"call",name:h.value,args:b,at:h.at}}return{kind:"var",name:h.value,at:h.at}}if(a("(")){let b=i();return s(")","a closing bracket"),b}throw h.t==="end"?new it("The expression ends before it is finished",h.at):new it(`"${h.value}" cannot start a value`,h.at)}let d=i(),f=n();if(f.t!=="end")throw new it(`"${f.value}" is left over \u2014 check for a missing operator`,f.at);return d}function Ky(e){let t=new Set,r=n=>{n.kind==="var"?t.add(n.name):n.kind==="call"?n.args.forEach(r):n.kind==="unary"?r(n.arg):n.kind==="binary"&&(r(n.left),r(n.right))};return r(e),t}var Gl=(e,t)=>typeof e=="number"?new Array(t).fill(e):e;function x5(e){let t=1;for(let r of e)Array.isArray(r)&&(t=Math.max(t,r.length));return t}function br(e,t){if(e.every(a=>typeof a=="number"))return t(...e);let r=x5(e),n=e.map(a=>Gl(a,r)),o=new Array(r);for(let a=0;a<r;a++)o[a]=t(...n.map(s=>s[Math.min(a,s.length-1)]));return o}var ct=(e,t)=>({arity:e,call:r=>br(r,t)}),wa=e=>e!==0&&!Number.isNaN(e),gn=e=>e?1:0;function BC(e,t,r){let n=$C(t,r,"integrate"),o=n.length,a=Gl(e,o),s=new Array(o),i=0;for(let c=0;c<o;c++){s[c]=i;let l=a[Math.min(c,a.length-1)],u=a[Math.min(c+1,a.length-1)];i+=(l+u)/2*n[c]}return s}function $C(e,t,r){if(!e.ds||e.ds.length===0)throw new it(`${r}() needs to know the sample spacing, and this context has none`,t);return e.ds}var Cp={abs:ct(1,Math.abs),sqrt:ct(1,Math.sqrt),sign:ct(1,Math.sign),floor:ct(1,Math.floor),ceil:ct(1,Math.ceil),round:ct(1,Math.round),exp:ct(1,Math.exp),log:ct(1,Math.log),sin:ct(1,Math.sin),cos:ct(1,Math.cos),tan:ct(1,Math.tan),atan:ct(1,Math.atan),atan2:ct(2,Math.atan2),hypot:ct(2,Math.hypot),min:ct(2,Math.min),max:ct(2,Math.max),clamp:ct(3,(e,t,r)=>Math.min(r,Math.max(t,e))),if:ct(3,(e,t,r)=>wa(e)?t:r),and:ct(2,(e,t)=>gn(wa(e)&&wa(t))),or:ct(2,(e,t)=>gn(wa(e)||wa(t))),not:ct(1,e=>gn(!wa(e))),finite:ct(1,e=>gn(Number.isFinite(e))),peak:{arity:1,call:([e])=>{let t=Array.isArray(e)?e:[e],r=0;for(let n of t)r=Math.max(r,Math.abs(n));return r}},mean:{arity:1,call:([e])=>{let t=Array.isArray(e)?e:[e];return t.length?t.reduce((r,n)=>r+n,0)/t.length:0}},total:{arity:1,call:([e],t)=>{let r=BC(e,t,0),n=t.ds,o=Gl(e,n.length),a=n.length-1;return r[a]+(o[a]+o[0])/2*n[a]}},integrate:{arity:1,call:([e],t)=>BC(e,t,0)},cum:{arity:1,call:([e],t)=>{let r=t.ds?.length??(Array.isArray(e)?e.length:1),n=Gl(e,r),o=new Array(r),a=0;for(let s=0;s<r;s++)a+=n[Math.min(s,n.length-1)],o[s]=a;return o}},deriv:{arity:1,call:([e],t)=>{let r=$C(t,0,"deriv"),n=r.length,o=Gl(e,n),a=new Array(n);for(let s=0;s<n;s++){let i=Math.max(0,s-1),c=Math.min(n-1,s+1),l=0;for(let u=i;u<c;u++)l+=r[u];a[s]=l>0?(o[c]-o[i])/l:0}return a}}},bi={g:9.81,pi:Math.PI,e:Math.E,nan:NaN,inf:1/0},Kl={fleetmin:"min",fleetmax:"max"};function Fa(e){switch(e.kind){case"call":return Object.hasOwn(Kl,e.name)||e.args.some(Fa);case"unary":return Fa(e.arg);case"binary":return Fa(e.left)||Fa(e.right);default:return!1}}var R5=e=>typeof e=="number"?`${e}`:`between ${e[0]} and ${e[1]}`;function v5(e,t){let r=Array.from({length:t.length+1},(n,o)=>o);for(let n=1;n<=e.length;n++){let o=[n];for(let a=1;a<=t.length;a++)o[a]=Math.min(r[a]+1,o[a-1]+1,r[a-1]+(e[n-1]===t[a-1]?0:1));r=o}return r[t.length]}function k5(e,t){let r=t.map(c=>({k:c,d:v5(c,e)})).filter(c=>c.d<=Math.max(1,Math.floor(e.length/4))),n=Math.min(...r.map(c=>c.d)),o=r.filter(c=>c.d===n).map(c=>c.k).slice(0,3);if(o.length)return`"${e}" is not a name here \u2014 did you mean ${o.join(" or ")}?`;let a=e.indexOf(".");if(a>0){let c=t.filter(l=>l.startsWith(e.slice(0,a+1)));if(c.length)return`"${e}" is not a name here. ${e.slice(0,a)} has ${c.join(", ")}`}let s=new Set,i=[];for(let c of t){let l=c.indexOf(".");l>0?s.add(`${c.slice(0,l)}.\u2026`):i.push(c)}return`"${e}" is not a name here. Available: ${[...s,...i].join(", ")}`}function yn(e,t){switch(e.kind){case"num":return e.value;case"var":{if(Object.hasOwn(t.vars,e.name))return t.vars[e.name];if(Object.hasOwn(bi,e.name))return bi[e.name];let r=[...Object.keys(t.vars),...Object.keys(bi)].sort();throw new it(k5(e.name,r),e.at)}case"unary":return br([yn(e.arg,t)],r=>-r);case"binary":{let r=yn(e.left,t),n=yn(e.right,t);switch(e.op){case"+":return br([r,n],(o,a)=>o+a);case"-":return br([r,n],(o,a)=>o-a);case"*":return br([r,n],(o,a)=>o*a);case"/":return br([r,n],(o,a)=>a===0?0:o/a);case"^":return br([r,n],(o,a)=>o**a);case"<":return br([r,n],(o,a)=>gn(o<a));case"<=":return br([r,n],(o,a)=>gn(o<=a));case">":return br([r,n],(o,a)=>gn(o>a));case">=":return br([r,n],(o,a)=>gn(o>=a));case"==":return br([r,n],(o,a)=>gn(o===a));case"!=":return br([r,n],(o,a)=>gn(o!==a))}break}case"call":{let r=Object.hasOwn(Kl,e.name)?Kl[e.name]:void 0;if(r){if(!t.fleet)throw new it(`${e.name}() compares the cars in a field, so it belongs in a ruleset's KPIs, not in a channel`,e.at);if(e.args.length!==1)throw new it(`${e.name}() takes 1 argument, not ${e.args.length}`,e.at);return t.fleet(e.args[0],r,e.at)}let n=Object.hasOwn(Cp,e.name)?Cp[e.name]:void 0;if(!n){let s=[...Object.keys(Cp),...t.fleet?Object.keys(Kl):[]];throw new it(`There is no function called "${e.name}". Available: ${s.sort().join(", ")}`,e.at)}let o=typeof n.arity=="number"?n.arity:n.arity[0],a=typeof n.arity=="number"?n.arity:n.arity[1];if(e.args.length<o||e.args.length>a)throw new it(`${e.name}() takes ${R5(n.arity)} argument${o===1&&a===1?"":"s"}, not ${e.args.length}`,e.at);return n.call(e.args.map(s=>yn(s,t)),t)}}throw new it("Unreachable node",0)}var gi=e=>Number.isFinite(e)?e:NaN,Hy=[{name:"time",unit:"s",what:"the whole event, every lap",read:e=>gi(e?.time)},{name:"lapTime",unit:"s",what:"one lap \u2014 the last one completed",read:e=>gi(e?.lapTime)},{name:"distance",unit:"m",what:"distance covered",read:e=>gi(e?.distance)},{name:"laps",unit:"-",what:"laps completed",read:e=>gi(e?.laps)},{name:"energy",unit:"kWh",what:"energy drawn over the event",read:e=>gi(e?.energy?.consumed)},{name:"remaining",unit:"-",what:"share of the pack or tank left afterwards",read:e=>gi(e?.energy?.remainingFraction)},{name:"finished",unit:"-",what:"1 when the car ran the whole event, else 0",read:e=>e&&!e.incomplete?1:0}],GC=/^[A-Za-z_][A-Za-z0-9_]*$/,M5=new Set([...Object.keys(bi),...Oy.map(e=>e.name)]);function Tp(e,t,r=[]){let n=[],o=new Set(r),a=t.map(b=>b.id),s=new Set;for(let b of a)GC.test(b)?s.has(b)&&n.push({key:null,message:`Two events are called "${b}"`}):n.push({key:null,message:`Event id "${b}" must be one word to be read as ${b}.time`}),s.add(b);let i=new Map,c=new Map;for(let b of e){if(!GC.test(b.key)){n.push({key:b.key,message:`"${b.key}" must be one word \u2014 letters, digits and _`});continue}if(M5.has(b.key)||o.has(b.key)){n.push({key:b.key,message:`"${b.key}" already means something in a formula \u2014 choose another key`});continue}if(i.has(b.key)){n.push({key:b.key,message:`Two KPIs are called "${b.key}"`});continue}i.set(b.key,b),b.over!=null&&!a.includes(b.over)&&n.push({key:b.key,message:`There is no event "${b.over}" to read the lap of. Events: ${a.join(", ")}`});try{c.set(b.key,Gy(b.expr))}catch(g){let y=g;n.push({key:b.key,message:y.message,at:y.at})}}let l=new Map;for(let[b,g]of c)l.set(b,[...Ky(g)].filter(y=>i.has(y)));let u=new Set,m=[];for(;;){let b=[...c.keys()].find(g=>!u.has(g)&&l.get(g).every(y=>u.has(y)||!c.has(y)));if(!b)break;u.add(b),m.push(b)}for(let b of c.keys()){if(u.has(b))continue;let g=S5(b,l);n.push({key:b,message:g?`"${b}" depends on itself, through ${g.join(" \u2192 ")}`:`"${b}" reads a KPI that depends on itself`})}let p=(b,g,y)=>{throw new it("fleetmin() and fleetmax() cannot sit inside one another",y)},d=new Set,f={};for(let b of a)for(let g of Hy)f[`${b}.${g.name}`]=1;for(let b of o)f[b]=1;for(let b of i.keys())f[b]=1;let h={};for(let b of Oy)h[b.name]=[1,1];for(let b of m){let g=i.get(b),y=c.get(b);(Fa(y)||l.get(b).some(S=>d.has(S)))&&d.add(b);let x=g.over!=null?{...f,...h}:f,R=g.over!=null?[1,1]:void 0,v=(S,A,F)=>{let w=yn(S,{vars:x,ds:R,fleet:p});if(Array.isArray(w))throw new it("fleetmin() and fleetmax() compare one number per car \u2014 reduce the channel first, e.g. peak(v)",F);return w};try{let S=yn(y,{vars:x,ds:R,fleet:v});Array.isArray(S)&&n.push({key:b,message:"A KPI is one number per car \u2014 reduce the channel, e.g. peak(v) or mean(v)",at:0})}catch(S){let A=S;n.push({key:b,message:A.message,at:A.at})}}return n.length?{plan:null,problems:n}:{plan:{order:m.map(b=>({def:i.get(b),node:c.get(b)})),field:d,eventIds:a},problems:n}}function S5(e,t){let r=[e],n=o=>{for(let a of t.get(o)??[]){if(a===e)return!0;if(!r.includes(a)){if(r.push(a),n(a))return!0;r.pop()}}return!1};return n(e)?[...r,e]:null}function A5(e,t,r={}){let n={...r};for(let o of e.eventIds){let a=t.events[o];for(let s of Hy)n[`${o}.${s.name}`]=s.read(a)}return{vars:n,laps:new Map,events:t.events}}function KC(e,t){if(t.over==null)return{vars:e.vars};let r=e.laps.get(t.over);if(r===void 0){let n=e.events[t.over];r=n?.trace?_C({...n.trace,length:Ol(n)}):null,e.laps.set(t.over,r)}return r?{vars:{...e.vars,...r.vars},ds:r.ds}:null}var HC=e=>Array.isArray(e)?NaN:e;function zC(e,t,r,n={}){let o=Object.keys(t),a=o.map(i=>A5(e,t[i],n[i]));for(let{def:i,node:c}of e.order){let l=e.field.has(i.key);if(l&&!r){for(let p of a)p.vars[i.key]=NaN;continue}let u=new Map,m=(p,d)=>{let f=u.get(p);if(f!==void 0)return f;let h=NaN;for(let b of a){let g=KC(b,i);if(!g)continue;let y=HC(yn(p,g));Number.isFinite(y)&&(Number.isNaN(h)||(d==="min"?y<h:y>h))&&(h=y)}return u.set(p,h),h};for(let p of a){let d=KC(p,i);p.vars[i.key]=d?HC(yn(c,l?{...d,fleet:m}:d)):NaN}}let s={};return o.forEach((i,c)=>{let l={};for(let{def:u}of e.order)l[u.key]=a[c].vars[u.key];s[i]=l}),s}function Hl(e,t,r){return zC(e,t,!0,r)}function zy(e,t,r){return zC(e,{car:t},!1,r?{car:r}:void 0).car}var Pp=class extends Error{problems;constructor(t,r){super(`Ruleset "${t}" does not compile:
|
|
223
|
+
`}function Nn(e){let t=_c(bS(e),e.name);return{...t,missing:[...t.missing??[],"a particular tyre \u2014 every coefficient is derived from class-level targets stated in generic.ts, on the road; run it with grip_scale = stiffness_scale = 1"]}}var gS={name:"Formula Student 18x6-10",R0:.228,width:.1524,Fz0:950,Kz:110,pressure:83,muY:1.8,muX:1.7,muYLoad:-.2,muXLoad:-.15,corneringStiffness:26e3,slipStiffnessPerLoad:32,camberStiffness:45,Cy:1.5,Cx:1.6,RBY1:12,RBY2:12,RBX1:13,RBX2:10,trail:.08},yS={name:"Formula 1 slick 18in",R0:.36,width:.305,Fz0:5e3,Kz:300,pressure:150,muY:1.8,muX:1.7,muYLoad:-.15,muXLoad:-.12,corneringStiffness:15e4,slipStiffnessPerLoad:28,camberStiffness:260,Cy:1.45,Cx:1.6,RBY1:12,RBY2:12,RBX1:13,RBX2:10,trail:.09},xS={name:"GT slick 18in",R0:.33,width:.3,Fz0:4e3,Kz:280,pressure:180,muY:1.45,muX:1.4,muYLoad:-.12,muXLoad:-.1,corneringStiffness:11e4,slipStiffnessPerLoad:24,camberStiffness:190,Cy:1.4,Cx:1.6,RBY1:11,RBY2:11,RBX1:12,RBX2:10,trail:.09},RS={name:"Street tyre 245/40 R18",R0:.325,width:.245,Fz0:4e3,Kz:220,pressure:240,muY:1.05,muX:1,muYLoad:-.1,muXLoad:-.08,corneringStiffness:75e3,slipStiffnessPerLoad:20,camberStiffness:100,Cy:1.3,Cx:1.55,RBY1:11,RBY2:11,RBX1:12,RBX2:10,trail:.12},vS={name:"Cup slick 18in",R0:.32,width:.25,Fz0:3500,Kz:280,pressure:180,muY:1.42,muX:1.38,muYLoad:-.12,muXLoad:-.1,corneringStiffness:9e4,slipStiffnessPerLoad:24,camberStiffness:160,Cy:1.4,Cx:1.6,RBY1:11,RBY2:11,RBX1:12,RBX2:10,trail:.09},kS={name:"Stock car slick 18in",R0:.357,width:.32,Fz0:4500,Kz:320,pressure:200,muY:1.35,muX:1.3,muYLoad:-.12,muXLoad:-.1,corneringStiffness:125e3,slipStiffnessPerLoad:22,camberStiffness:170,Cy:1.4,Cx:1.6,RBY1:11,RBY2:11,RBX1:12,RBX2:10,trail:.09},MS={name:"Hill-climb slick 13in",R0:.3,width:.3,Fz0:2e3,Kz:200,pressure:150,muY:1.75,muX:1.65,muYLoad:-.18,muXLoad:-.14,corneringStiffness:6e4,slipStiffnessPerLoad:28,camberStiffness:90,Cy:1.45,Cx:1.6,RBY1:12,RBY2:12,RBX1:13,RBX2:10,trail:.085},SS={name:"Race truck tyre 315/70 R22.5",R0:.506,width:.315,Fz0:13e3,Kz:1e3,pressure:800,muY:1.1,muX:1.05,muYLoad:-.1,muXLoad:-.08,corneringStiffness:15e4,slipStiffnessPerLoad:14,camberStiffness:200,Cy:1.3,Cx:1.55,RBY1:10,RBY2:10,RBX1:11,RBX2:10,trail:.1},bg=()=>Nn(gS),gg=()=>Nn(yS),yg=()=>Nn(xS),xg=()=>Nn(RS),Rg=()=>Nn(vS),vg=()=>Nn(kS),kg=()=>Nn(MS),Mg=()=>Nn(SS);var AS=e=>Number.isFinite(e)&&e>0;function Qm(e,t){let r=AS(t.grip)?t.grip:1,n=AS(t.stiffness)?t.stiffness:1;if(r===1&&n===1)return e;if(e.kind==="simple"){let o=n/r;return{...e,muX0:e.muX0*r,muY0:e.muY0*r,loadSensX:e.loadSensX*r,loadSensY:e.loadSensY*r,Bx:e.Bx*o,By:e.By*o}}return{...e,coeffs:{...e.coeffs,LMUX:(e.coeffs.LMUX??1)*r,LMUY:(e.coeffs.LMUY??1)*r,LKX:(e.coeffs.LKX??1)*n,LKY:(e.coeffs.LKY??1)*n}}}var Oc={ok:!0,violation:0},ta=1e7;function On(e,t){let r;try{r=e.build(t)}catch(s){return{total:ta*2,feasible:!1,terms:[],reason:`build failed: ${String(s)}`}}let n=e.feasible(r);if(!n.ok)return{total:ta+Math.max(0,n.violation),feasible:!1,terms:[],reason:n.reason};let o;try{o=e.terms(r)}catch(s){return{total:ta*2,feasible:!1,terms:[],reason:`objective threw: ${String(s)}`}}let a=0;for(let s of o)a+=s.contribution;return Number.isFinite(a)?{total:a,feasible:!0,terms:o}:{total:ta*2,feasible:!1,terms:o,reason:"objective was not finite"}}var Vc=(e,t)=>!t||(e.feasible!==t.feasible?e.feasible:e.total<t.total);function Sg(e,t){return t.map((r,n)=>Math.min(e[n].hi,Math.max(e[n].lo,r)))}var Gr=e=>e.map(t=>t.start);function Zm(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let r=Math.imul(t^t>>>15,1|t);return r=r+Math.imul(r^r>>>7,61|r)^r,((r^r>>>14)>>>0)/4294967296}}function tN(e){let t=0;for(;t===0;)t=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}function Ag(e,t){let{budget:r}=t,n=Math.max(1,Math.floor(t.progressEvery??1)),o=e.variables,a=d=>Sg(o,d.map((f,h)=>o[h].lo+f*(o[h].hi-o[h].lo))),s=d=>d.map((f,h)=>(f-o[h].lo)/(o[h].hi-o[h].lo)),i=0,c=0,l=null,u=null,m=[];return{vars:o,denorm:a,norm:s,evaluate:d=>{if(i>=r)return l?.total??Number.POSITIVE_INFINITY;i++;let f=d.map(g=>Math.min(1,Math.max(0,g))),h=On(e,a(f));h.feasible||c++;let b=Vc(h,l)?h:l;return b===h&&(l=h,u=f),m.push(b.total),t.onProgress&&(i%n===0||i===r)&&t.onProgress({evaluations:i,budget:r,x:a(u),score:b,infeasible:c}),h.total},left:()=>r-i,result:d=>({method:d,x:u?a(u):Gr(o),score:l??On(e,Gr(o)),evaluations:i,history:m,infeasible:c})}}var wg=(e,t,r,n=0,o)=>{let a=t?r.norm(Gr(e.variables)):e.variables.map(()=>.5);return!(n>0)||!o?a:a.map(s=>Math.min(1,Math.max(0,s+n*2*(o()-.5))))};function wS(e,t){let r=Ag(e,t),n=Zm(t.seed??1),o=e.variables.length;for(r.evaluate(wg(e,t.warmStart!==!1,r,t.startJitter,n));r.left()>0;){let a=[];for(let s=0;s<o;s++)a.push(n());r.evaluate(a)}return r.result("random")}function $s(e,t){let r=Ag(e,t),n=e.variables.length,o=Zm(t.seed??1),a=1,s=2,i=.5,c=.5,l=wg(e,t.warmStart!==!1,r,t.startJitter,o),u=.25;for(;r.left()>0;){let m=[{u:l,f:r.evaluate(l)}];for(let p=0;p<n&&r.left()>0;p++){let d=l.slice();d[p]+=d[p]+u>1?-u:u,m.push({u:d,f:r.evaluate(d)})}for(;r.left()>0;){m.sort((g,y)=>g.f-y.f);let p=m[n],d=new Array(n).fill(0);for(let g=0;g<n;g++)for(let y=0;y<n;y++)d[y]+=m[g].u[y]/n;let f=g=>d.map((y,x)=>y+g*(y-p.u[x])),h=f(a),b=r.evaluate(h);if(b<m[0].f){let g=f(s),y=r.evaluate(g);m[n]=y<b?{u:g,f:y}:{u:h,f:b}}else if(b<m[n-1].f)m[n]={u:h,f:b};else{let g=f(-i),y=r.evaluate(g);if(y<p.f)m[n]={u:g,f:y};else{let x=m[0],R=0;for(let v=1;v<=n;v++)for(let S=0;S<n;S++)R=Math.max(R,Math.abs(m[v].u[S]-x.u[S]));if(R<1e-4)break;for(let v=1;v<=n&&r.left()>0;v++){let S=m[v].u.map((A,C)=>x.u[C]+c*(A-x.u[C]));m[v]={u:S,f:r.evaluate(S)}}}}}m.sort((p,d)=>p.f-d.f),l=m[0].u.map(p=>Math.min(1,Math.max(0,p+.05*(o()-.5)))),u=Math.max(.02,u*.5)}return r.result("nelder-mead")}function FS(e,t){let r=Ag(e,t),n=e.variables.length,o=Zm(t.seed??1),a=4+Math.floor(3*Math.log(n)),s=Math.floor(a/2),i=[];for(let A=1;A<=s;A++)i.push(Math.log(s+.5)-Math.log(A));let c=i.reduce((A,C)=>A+C,0);for(let A=0;A<s;A++)i[A]/=c;let l=1/i.reduce((A,C)=>A+C*C,0),u=(l+2)/(n+l+5),m=1+2*Math.max(0,Math.sqrt((l-1)/(n+1))-1)+u,p=(4+l/n)/(n+4+2*l/n),d=(n+2)/3,f=Math.min(1,d*2/((n+1.3)**2+l)),h=Math.min(1-f,d*2*(l-2+1/l)/((n+2)**2+l)),b=Math.sqrt(n)*(1-1/(4*n)+1/(21*n*n)),g=wg(e,t.warmStart!==!1,r,t.startJitter,o),y=.25,x=new Array(n).fill(1),R=new Array(n).fill(0),v=new Array(n).fill(0),S=0;for(;r.left()>0;){S++;let A=[];for(let k=0;k<a&&r.left()>0;k++){let w=[];for(let L=0;L<n;L++)w.push(tN(o));let P=g.map((L,E)=>L+y*x[E]*w[E]);A.push({z:w,u:P,f:r.evaluate(P)})}if(A.length<s)break;A.sort((k,w)=>k.f-w.f);let C=g.slice(),F=new Array(n).fill(0);g=new Array(n).fill(0);for(let k=0;k<s;k++)for(let w=0;w<n;w++)g[w]+=i[k]*A[k].u[w],F[w]+=i[k]*A[k].z[w];g=g.map(k=>Math.min(1,Math.max(0,k)));for(let k=0;k<n;k++)R[k]=(1-u)*R[k]+Math.sqrt(u*(2-u)*l)*F[k];let T=Math.sqrt(R.reduce((k,w)=>k+w*w,0)),M=T/Math.sqrt(1-(1-u)**(2*S))/b<1.4+2/(n+1)?1:0;for(let k=0;k<n;k++){let w=(g[k]-C[k])/(y*x[k]);v[k]=(1-p)*v[k]+M*Math.sqrt(p*(2-p)*l)*w}for(let k=0;k<n;k++){let w=0;for(let E=0;E<s;E++)w+=i[E]*A[E].z[k]*A[E].z[k];let P=x[k]*x[k],L=(1-f-h)*P+f*(v[k]*v[k]+(1-M)*p*(2-p)*P)+h*w*P;x[k]=Math.sqrt(Math.max(1e-12,L))}if(y*=Math.exp(u/m*(T/b-1)),y<1e-6||y>10)break}return r.result("sep-cma-es")}var Gs=[{name:"random",run:wS},{name:"nelder-mead",run:$s},{name:"sep-cma-es",run:FS}];var Y9=Math.PI/180;var Jm=Math.PI/180;var X9={Fz:100,alpha:.25*Jm,kappa:.005,gamma:.5*Jm,p:6900},CS={Fz:100,alpha:1*Jm,kappa:.02,gamma:.5*Jm,p:6900};var TS=Math.PI/180,tX={t:{s:1,sec:1,ms:.001},v:{"m/s":1,"km/h":1/3.6,"km/hr":1/3.6,kph:1/3.6},alpha:{rad:1,deg:TS},gamma:{rad:1,deg:TS},p:{pa:1,kpa:1e3,bar:1e5,mpa:1e6},rl:{m:1,mm:.001,cm:.01},Fz:{n:1},Fx:{n:1},Fy:{n:1},Mz:{nm:1,"n-m":1}};var sX=Math.PI/180;var pN=Math.PI/180;var pX=3*pN;var yX=Math.PI/180;var PX=Math.PI/180;var vN={RCX1:1,RCY1:1,REX1:0,REY1:0,RBY3:0,RHX1:0,RHY1:0},DS={RBX1:15,RBX2:15,RBY1:18,RBY2:19,...vN};var GX=Math.PI/180;var wN=Math.PI/180,ed=[{id:"alpha",symbol:"\u03B1",name:"Slip angle",group:"inputs",unit:"rad"},{id:"kappa",symbol:"\u03BA",name:"Slip ratio",group:"inputs",unit:"-"},{id:"gamma",symbol:"\u03B3",name:"Inclination",group:"inputs",unit:"rad"},{id:"Fz",symbol:"Fz",name:"Vertical load",group:"inputs",unit:"N",quantity:"force"},{id:"p",symbol:"p",name:"Inflation pressure",group:"inputs",unit:"Pa",quantity:"pressure"},{id:"V",symbol:"V",name:"Speed",group:"inputs",unit:"m/s",quantity:"speed"},{id:"Fx",symbol:"Fx",name:"Longitudinal force",group:"forces",unit:"N",quantity:"force"},{id:"Fy",symbol:"Fy",name:"Lateral force",group:"forces",unit:"N",quantity:"force"},{id:"Mx",symbol:"Mx",name:"Overturning moment",group:"moments",unit:"N\xB7m"},{id:"My",symbol:"My",name:"Rolling-resistance moment",group:"moments",unit:"N\xB7m"},{id:"Mz",symbol:"Mz",name:"Aligning moment",group:"moments",unit:"N\xB7m"},{id:"t",symbol:"t",name:"Pneumatic trail",group:"aligning",unit:"m",quantity:"length"},{id:"Mzr",symbol:"Mzr",name:"Residual aligning moment",group:"aligning",unit:"N\xB7m"},{id:"s",symbol:"s",name:"Lever arm of Fx",group:"aligning",unit:"m",quantity:"length"},{id:"muX",symbol:"\u03BCx",name:"Longitudinal friction Fx/Fz",group:"friction",unit:"-"},{id:"muY",symbol:"\u03BCy",name:"Lateral friction Fy/Fz",group:"friction",unit:"-"},{id:"use",symbol:"use",name:"Friction ellipse used",group:"friction",unit:"-"},{id:"FyRel",symbol:"Fy/Fy,peak",name:"Lateral force over its peak at this load",group:"friction",unit:"-"},{id:"FxRel",symbol:"Fx/Fx,peak",name:"Driving force over its peak at this load",group:"friction",unit:"-"},{id:"dFyda",symbol:"\u2202Fy/\u2202\u03B1",name:"Cornering stiffness at the point",group:"stiffness",unit:"N/rad"},{id:"dFxdk",symbol:"\u2202Fx/\u2202\u03BA",name:"Slip stiffness at the point",group:"stiffness",unit:"N"},{id:"dFydg",symbol:"\u2202Fy/\u2202\u03B3",name:"Camber stiffness at the point",group:"stiffness",unit:"N/rad"},{id:"kz",symbol:"kz",name:"Vertical stiffness",group:"stiffness",unit:"N/mm",quantity:"springRate",characteristic:!0},{id:"FxPeak",symbol:"Fx,peak",name:"Peak driving force",group:"characteristics",unit:"N",quantity:"force",characteristic:!0},{id:"FyPeak",symbol:"Fy,peak",name:"Peak lateral force",group:"characteristics",unit:"N",quantity:"force",characteristic:!0},{id:"muXPeak",symbol:"\u03BCx,peak",name:"Peak longitudinal friction",group:"characteristics",unit:"-",characteristic:!0},{id:"muYPeak",symbol:"\u03BCy,peak",name:"Peak lateral friction",group:"characteristics",unit:"-",characteristic:!0},{id:"kappaPeak",symbol:"\u03BA at peak",name:"Slip ratio at peak driving force",group:"characteristics",unit:"-",characteristic:!0},{id:"alphaPeak",symbol:"\u03B1 at peak",name:"Slip angle at peak lateral force",group:"characteristics",unit:"rad",characteristic:!0},{id:"Calpha",symbol:"C\u03B1",name:"Cornering stiffness at zero slip",group:"characteristics",unit:"N/rad",characteristic:!0},{id:"bestCamber",symbol:"\u03B3 best",name:"Camber for the most side force",group:"characteristics",unit:"rad",characteristic:!0},{id:"R0",symbol:"R0",name:"Free radius",group:"geometry",unit:"m",quantity:"length",characteristic:!0},{id:"Rl",symbol:"Rl",name:"Loaded radius",group:"geometry",unit:"m",quantity:"length",characteristic:!0},{id:"Re",symbol:"Re",name:"Effective rolling radius",group:"geometry",unit:"m",quantity:"length",characteristic:!0},{id:"width",symbol:"w",name:"Section width",group:"geometry",unit:"m",quantity:"length",characteristic:!0},{id:"sigmaA",symbol:"\u03C3\u03B1",name:"Lateral relaxation length",group:"transient",unit:"m",quantity:"length",characteristic:!0},{id:"Fr",symbol:"Fr",name:"Rolling-resistance force My/Re",group:"power",unit:"N",quantity:"force"},{id:"cr",symbol:"cr",name:"Rolling-resistance coefficient Fr/Fz",group:"power",unit:"-"},{id:"Pslip",symbol:"P slip",name:"Slip power |Fx\xB7Vsx| + |Fy\xB7Vsy|",group:"power",unit:"W"},{id:"Proll",symbol:"P roll",name:"Rolling power My\xB7\u03A9",group:"power",unit:"W"}],rq=new Map(ed.map(e=>[e.id,e]));var nq=.01*wN;var ft=Math.PI/180;var _S=new Set(ed.filter(e=>e.group!=="inputs"&&(e.unit==="N"||e.unit==="N\xB7m"||e.unit==="N/rad")).map(e=>e.id)),NS={alpha:{from:-15*ft,to:15*ft,n:61},kappa:{from:-.25,to:.25,n:61},gamma:{from:-6*ft,to:6*ft,n:49},Fz:{from:200,to:3e3,n:40,follow:!0},p:{from:5e4,to:15e4,n:21},V:{from:0,to:40,n:41,follow:!0}},Lg={alpha:{from:0,to:12*ft,n:7},kappa:{from:-.2,to:.2,n:9},gamma:{from:-4*ft,to:4*ft,n:5},Fz:{from:400,to:1600,n:5},p:{from:6e4,to:12e4,n:4},V:{from:5,to:35,n:4}};var Dg={alpha:{from:0,to:12*ft,n:25},kappa:{from:-.2,to:.2,n:25},gamma:{from:-4*ft,to:4*ft,n:17},Fz:{from:300,to:1800,n:16},p:{from:6e4,to:12e4,n:13},V:{from:5,to:35,n:13}};var Oe=(e,t,r,n={},o={})=>({id:e,form:"curves",sweep:[{input:t,...NS[t],...o}],x:t,y:r,...n}),td=(e,[t,r],n,o,a={})=>({id:e,form:"carpet",sweep:[{input:t,...Lg[t]},{input:r,...Lg[r]}],x:n,y:[o],...a}),Vn=(e,t)=>({id:e,fixed:t}),Ar={input:"Fz",values:"car"},Pg={alpha:0,kappa:0},Jt={kappa:0},ES={alpha:0},CN={input:"Fz",values:[500,1e3,1500]},TN=[{id:"overview",name:"Overview",cards:[Vn("tyre","tyre"),Oe("fy","alpha",["Fy"],{title:"Lateral force",hold:Jt}),Oe("mz","alpha",["Mz"],{title:"Aligning moment",hold:Jt}),Oe("fx","kappa",["Fx"],{title:"Longitudinal force",hold:ES}),td("combined-carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),Vn("ellipse","ellipse")]},{id:"lateral",name:"Lateral",cards:[Oe("fy-load","alpha",["Fy"],{title:"Lateral force per wheel load",series:Ar,hold:Jt}),Oe("muy-load","alpha",["muY"],{title:"Lateral force per unit load",series:Ar,hold:Jt}),Oe("fy-peak","alpha",["Fy"],{title:"Lateral force over its peak",series:Ar,hold:Jt,scale:{per:"peak"}},{from:0,to:15*ft,n:61}),Oe("muy-peak","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load"}),Oe("calpha","Fz",["Calpha"],{title:"Cornering stiffness over load"}),Oe("alpha-peak","Fz",["alphaPeak"],{title:"Slip angle at the peak over load"})]},{id:"aligning",name:"Aligning",cards:[Oe("mz-load","alpha",["Mz"],{title:"Aligning moment per wheel load",series:Ar,hold:Jt}),Oe("trail","alpha",["t"],{title:"Pneumatic trail",series:Ar,hold:Jt},{from:0,to:12*ft,n:49}),Oe("mzr","alpha",["Mzr"],{title:"Residual aligning moment",series:Ar,hold:Jt},{from:0,to:12*ft,n:49}),td("gough",["alpha","Fz"],"Fy","Mz",{title:"Gough plot",hold:Jt}),Oe("steering-feel","alpha",["t"],{title:"Steering feel",x:"FyRel",series:Ar,hold:Jt},{from:0,to:12*ft,n:49})]},{id:"longitudinal",name:"Longitudinal",cards:[Oe("fx-load","kappa",["Fx"],{title:"Longitudinal force per wheel load",series:Ar,hold:ES}),Oe("mux-peak","Fz",["muXPeak"],{title:"Peak longitudinal \u03BC over load"}),Oe("kx","Fz",["dFxdk"],{title:"Slip stiffness at zero slip over load",hold:Pg}),Oe("kappa-peak","Fz",["kappaPeak"],{title:"Slip ratio at the peak over load"})]},{id:"combined",name:"Combined",cards:[td("carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),td("envelope-load",["kappa","alpha"],"Fy","Fx",{title:"Friction envelope per load",scale:{per:"Fz"},facet:CN}),Oe("fy-kappa","kappa",["Fy"],{title:"Side force while driving or braking",series:{input:"alpha",values:[2*ft,4*ft,8*ft]}}),Oe("fx-kappa","kappa",["Fx"],{title:"Driving force while cornering",series:{input:"alpha",values:[0,4*ft,8*ft]}}),Vn("ellipse","ellipse")]},{id:"camber",name:"Camber",cards:[Oe("fy-gamma","alpha",["Fy"],{title:"Lateral force per inclination",series:{input:"gamma",values:[-4,-2,0,2,4].map(e=>e*ft)},hold:Jt}),Oe("camber-sweep","gamma",["FyPeak","Fy"],{title:"Peak, and camber thrust at zero slip",hold:{alpha:0}}),{id:"camber-map",title:"Camber map",form:"map",sweep:[{input:"gamma",...Dg.gamma},{input:"Fz",...Dg.Fz,follow:!0}],x:"gamma",y:["Fz"],z:"muYPeak"},Oe("camber-stiffness","alpha",["dFydg"],{title:"Camber stiffness at the point",series:Ar,hold:Jt}),Oe("mx","alpha",["Mx"],{title:"Overturning moment",series:Ar,hold:Jt})]},{id:"rolling",name:"Rolling and radius",cards:[Oe("my","V",["My"],{title:"Rolling-resistance moment",series:Ar,hold:Pg}),Oe("radius","Fz",["R0","Rl","Re"],{title:"Radius over load"},{from:0}),Oe("p-roll","V",["Proll"],{title:"Rolling power",series:Ar,hold:Pg})]},{id:"transient",name:"Transient",cards:[Oe("sigma","Fz",["sigmaA"],{title:"Relaxation length over load"})]},{id:"tyres",name:"Side by side",cards:[{id:"trade-off",title:"Grip against cornering stiffness",form:"points",sweep:[],x:"Calpha",y:["muYPeak"]},{id:"pressure-family",title:"Peak \u03BCy over pressure, by family",form:"points",sweep:[],x:"p",y:["muYPeak"],family:!0},Oe("delta-fy","alpha",["Fy"],{title:"Lateral force, minus the reference",hold:Jt,scale:{delta:!0}}),Oe("delta-mu","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load, minus the reference",scale:{delta:!0}}),Oe("delta-calpha","Fz",["Calpha"],{title:"Cornering stiffness over load, minus the reference",scale:{delta:!0}})]},{id:"car",name:"Car",cards:[Vn("operating","operating"),Vn("wheels","wheels")]},{id:"fit",name:"Fit check",cards:[Vn("fitLateral","fitLateral"),Vn("fitLongitudinal","fitLongitudinal"),Vn("fitCoupling","fitCoupling"),Vn("fitEnvelope","fitEnvelope")]}];var ON=5670374e-14,Eg=273.15,BS=.95,$S=60,rd=10,VN=.55,ur=25,Ig=-20,_g=50,$c={tempC:[20,100,200,550,650,750],factor:[.8,.92,1,1,.85,.65]},Gc={discMassKg:.5,discOuterMm:220,specificHeatJPerKgK:460,emissivity:.6,coolingWPerM2K:200,padCurve:{tempC:[...$c.tempC],factor:[...$c.factor]}},nd={...Gc,discMassKg:.4,discOuterMm:200,padCurve:{tempC:[...$c.tempC],factor:[...$c.factor]}};function Ng(e,t){let r=t==="front"?Gc:nd,n=Math.round(2*e.effRadiusMm+40);return{...r,discOuterMm:n,discMassKg:Math.round(100*r.discMassKg*(n/r.discOuterMm)**2)/100,padCurve:{tempC:[...r.padCurve.tempC],factor:[...r.padCurve.factor]}}}var BN=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},Bc=(e,t,r,n)=>Math.min(r,Math.max(t,BN(e,n)));function $N(e,t){let r=e,n=Array.isArray(r?.tempC)?r.tempC:[],o=Array.isArray(r?.factor)?r.factor:[],a=[];for(let i=0;i<Math.min(n.length,o.length);i++){let c=Number(n[i]),l=Number(o[i]);Number.isFinite(c)&&Number.isFinite(l)&&a.push([Math.min(1500,Math.max(-50,c)),Math.min(2,Math.max(.05,l))])}a.sort((i,c)=>i[0]-c[0]);let s=a.filter((i,c)=>c===0||i[0]>a[c-1][0]);return s.length?{tempC:s.map(i=>i[0]),factor:s.map(i=>i[1])}:{tempC:[...t.tempC],factor:[...t.factor]}}function Og(e,t){return{discMassKg:Bc(e?.discMassKg,.05,20,t.discMassKg),discOuterMm:Bc(e?.discOuterMm,50,600,t.discOuterMm),specificHeatJPerKgK:Bc(e?.specificHeatJPerKgK,100,3e3,t.specificHeatJPerKgK),emissivity:Bc(e?.emissivity,.02,1,t.emissivity),coolingWPerM2K:Bc(e?.coolingWPerM2K,rd,5e3,t.coolingWPerM2K),padCurve:$N(e?.padCurve,t.padCurve)}}function od(e,t){let r=e.tempC,n=e.factor,o=Math.min(r.length,n.length);if(o===0)return 1;if(t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=1;for(;a<o-1&&r[a]<t;)a++;return n[a-1]+(t-r[a-1])/(r[a]-r[a-1])*(n[a]-n[a-1])}function Vg(e,t=1){let r=e.discMassKg*e.specificHeatJPerKgK,n=e.discOuterMm*.001/2,o=2*Math.PI*n*n,a=$S/3.6,s=e.emissivity*ON*o,i=m=>rd+(e.coolingWPerM2K-rd)*Math.pow(Math.max(0,m)*t/a,VN),c=(m,p,d)=>{let f=m+Eg,h=d+Eg;return i(p)*o*(m-d)+s*(f**4-h**4)},l=(m,p)=>i(p)*o+4*s*Math.max(0,m+Eg)**3,u=(m,p)=>r/l(p,m);return{heatCapacityJPerK:r,areaM2:o,convectionAt:i,coolingW:c,timeConstantS:u,step(m,p,d,f,h){if(!(f>0))return m+p/r;let b=u(d,m+Math.max(0,p)/r),g=Math.max(1,Math.ceil(f/(.25*b))),y=f/g,x=p/g;for(let R=0;R<g;R++)m+=(x-c(m,d,h)*y)/r;return m},padFactor:m=>od(e.padCurve,m),window:GS(e.padCurve)}}function ad(e,t,r,n,o,a,s=ur){let i=n.length,c=new Array(i),l=new Array(i),u=new Array(i),m=BS/Math.max(1,t),p=a,d=p,f=0,h=0,b=0;for(let g=0;g<i;g++){let y=Math.max(0,r[g]??0);c[g]=p,l[g]=y*n[g],u[g]=e.padFactor(p);let x=y*(o[g]??0);f+=x,p<e.window.fromC?h+=x:p>e.window.toC&&(b+=x);let R=g+1<i?n[g+1]:n[g],v=.5*(n[g]+R),S=v>0?(o[g]??0)/v:0;p=e.step(p,m*x,v,S,s),p>d&&(d=p)}return{tempC:c,heatW:l,padFactor:u,startC:a,endC:p,maxC:d,workJ:f,coldWorkJ:h,hotWorkJ:b}}function GS(e){let t=e.tempC,r=Math.min(t.length,e.factor.length);if(r===0)return{fromC:-1/0,toC:1/0};let n=Math.max(...e.factor.slice(0,r)),o=null;for(let c=0;c<r;c++){if(e.factor[c]<n-1e-9)continue;let l=c;for(;l+1<r&&e.factor[l+1]>=n-1e-9;)l++;l>c&&(!o||t[l]-t[c]>o.toC-o.fromC)&&(o={fromC:t[c],toC:t[l]}),c=l}if(o)return o;let a=NaN,s=NaN,i=NaN;for(let c=Math.floor(t[0]);c<=Math.ceil(t[r-1])+1;c++){let l=c<=Math.ceil(t[r-1])&&od(e,c)>=.98*n;l&&Number.isNaN(i)&&(i=c),!l&&!Number.isNaN(i)&&((Number.isNaN(a)||c-1-i>s-a)&&(a=i,s=c-1),i=NaN)}return{fromC:a,toC:s}}var Bg=e=>typeof e=="number"&&Number.isFinite(e);function sd(e){if(e==null)return null;if(typeof e!="object"||Array.isArray(e))return"disc and caliper are not readable.";let t=e;for(let[r,n]of[["discDiameter","disc diameter"],["caliperHeight","caliper height"],["caliperLength","caliper length"],["caliperWidth","caliper width"]]){let o=t[r];if(!Bg(o)||!(o>0))return`${n} must be a length above zero.`}return Bg(t.discOffset)?!Bg(t.caliperAngle)||Math.abs(t.caliperAngle)>180?"caliper angle must be between \u2212180\xB0 and 180\xB0.":null:"disc offset must be a length."}var $g=1e5,YS=.001,ra={pedalRatio:4,pedalForceMaxN:0,barFront:.5,masterFrontMm:15.875,masterRearMm:15.875,valve:"none",valveKneeBar:20,valveSlope:.3,front:{location:"outboard",discs:2,pistonsPerSide:2,pistonDiaMm:25.4,padMu:.45,effRadiusMm:90,ratio:1},rear:{location:"outboard",discs:2,pistonsPerSide:1,pistonDiaMm:25.4,padMu:.45,effRadiusMm:80,ratio:1},adjusterPitchMm:1,barLengthMm:0},Kg={fullAtBar:10,maxPowerKw:0,fadeBelowKmh:0,distribution:"equal"};var Hg=jS(cd(ra,"Formula Student brakes")),zg=40,WS={ideal:!1,barFront:ra.barFront,pedalForceMaxN:0,testSpeedKmh:zg,regen:Kg};function KS(e){let{heat:t,packaging:r,...n}=e;return{...n,...t?{heat:{...t,padCurve:{tempC:[...t.padCurve.tempC],factor:[...t.padCurve.factor]}}}:{},...r?{packaging:{...r}}:{}}}function jS(e){let t=(r,n)=>r.heat?r:{...r,heat:Ng(r,n)};return{...e,front:t(e.front,"front"),rear:t(e.rear,"rear")}}function cd(e,t){return{name:t,pedalRatio:e.pedalRatio,masterFrontMm:e.masterFrontMm,masterRearMm:e.masterRearMm,valve:e.valve,valveKneeBar:e.valveKneeBar,valveSlope:e.valveSlope,front:KS(e.front),rear:KS(e.rear),adjusterPitchMm:e.adjusterPitchMm,barLengthMm:e.barLengthMm}}function Yg(e,t){return US({...e,barFront:t.barFront,pedalForceMaxN:t.pedalForceMaxN})}function Wg(e,t){let r=$n(t),n=e?sn(e):void 0;return{mode:r.ideal?"tyre":n?"hydraulic":"balance",hydraulic:n?Yg(n,r):ra,regen:r.regen}}var GN=["none","proportioning","limiter"],id=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},At=(e,t,r,n)=>Math.min(r,Math.max(t,id(e,n))),KN=(e,t)=>{let r=id(e,t);return r>0?r:t};function HS(e,t,r){let n=e?.location==="inboard"?"inboard":e?.location==="outboard"?"outboard":t.location;return{location:n,discs:Math.max(1,Math.min(4,Math.round(id(e?.discs,n==="inboard"?1:t.discs)))),pistonsPerSide:Math.max(1,Math.min(6,Math.round(id(e?.pistonsPerSide,t.pistonsPerSide)))),pistonDiaMm:At(e?.pistonDiaMm,5,80,t.pistonDiaMm),padMu:At(e?.padMu,.05,1.5,t.padMu),effRadiusMm:At(e?.effRadiusMm,20,300,t.effRadiusMm),ratio:n==="inboard"?At(e?.ratio,1,20,t.ratio):1,...e?.heat&&typeof e.heat=="object"?{heat:Og(e.heat,t.heat??r)}:{},...sd(e?.packaging)===null&&e?.packaging?{packaging:{...e.packaging}}:{}}}function US(e){let t=ra;return{pedalRatio:At(e?.pedalRatio,.5,15,t.pedalRatio),pedalForceMaxN:At(e?.pedalForceMaxN,0,5e3,t.pedalForceMaxN),barFront:At(e?.barFront,.05,.95,t.barFront),masterFrontMm:At(e?.masterFrontMm,8,40,t.masterFrontMm),masterRearMm:At(e?.masterRearMm,8,40,t.masterRearMm),valve:GN.includes(e?.valve)?e?.valve:t.valve,valveKneeBar:At(e?.valveKneeBar,0,200,t.valveKneeBar),valveSlope:At(e?.valveSlope,0,1,t.valveSlope),front:HS(e?.front,t.front,Gc),rear:HS(e?.rear,t.rear,nd),adjusterPitchMm:KN(e?.adjusterPitchMm,t.adjusterPitchMm),barLengthMm:At(e?.barLengthMm,0,500,t.barLengthMm)}}function HN(e){let t=Kg;return{fullAtBar:At(e?.fullAtBar,0,200,t.fullAtBar),maxPowerKw:At(e?.maxPowerKw,0,1e3,t.maxPowerKw),fadeBelowKmh:At(e?.fadeBelowKmh,0,100,t.fadeBelowKmh),distribution:e?.distribution==="wheel"?"wheel":"equal"}}function sn(e){let t=US(e??void 0),r=typeof e?.name=="string"&&e.name.trim()?e.name:zN;return cd(t,r)}function $n(e){return{ideal:e?.ideal===!0,barFront:At(e?.barFront,.05,.95,ra.barFront),pedalForceMaxN:At(e?.pedalForceMaxN,0,5e3,0),testSpeedKmh:At(e?.testSpeedKmh,5,150,zg),regen:HN(e?.regen)}}var zN="Formula Student brakes";var Gg=e=>Math.PI/4*(e*YS)**2;function vo(e,t){let r=e.pistonsPerSide*Gg(e.pistonDiaMm)*$g;return e.discs*2*e.padMu*r*e.effRadiusMm*YS*e.ratio/Math.max(.05,t)}function XS(e,t){if(e.valve==="none"||t<=e.valveKneeBar)return t;let r=e.valve==="limiter"?0:e.valveSlope;return e.valveKneeBar+r*(t-e.valveKneeBar)}function Kc(e,t){let r=Math.max(0,t)*e.pedalRatio,n=e.barFront*r/Gg(e.masterFrontMm)/$g,o=(1-e.barFront)*r/Gg(e.masterRearMm)/$g;return{front:n,rearIn:o,rear:XS(e,o)}}function YN(e,t){let r=Kc(e,1);return{front:vo(e.front,t)*r.front,rear:vo(e.rear,t)*r.rearIn}}function Hc(e,t){let r=YN(e,t);return r.front/Math.max(1e-12,r.front+r.rear)}function zc(e,t){let r=[],n=[],o=[],a=e.vVehicle.length,s=Math.max(1,Math.floor(a/60));for(let c=0;c<a;c+=s)i(c);return(a-1)%s!==0&&i(a-1),{v:r,front:n,rear:o};function i(c){let l=e.vVehicle[c],u=qS(t,l),m=t.maxPowerKw>0&&l>0?t.maxPowerKw*1e3/l:1/0,p=Math.max(0,e.fFront[c]),d=Math.max(0,e.fRear[c]),f=p+d>0?Math.min(1,m/(p+d)):1;r.push(l),n.push(p*f*u),o.push(d*f*u)}}function qS(e,t){let r=e.fadeBelowKmh/3.6;return r>0?Math.max(0,Math.min(1,t/r)):1}function Bn(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]||1);return t[o]+s*(t[a]-t[o])}var zS=new WeakMap;function na(e){let t=zS.get(e);return t||(t=e.mode==="hydraulic"&&e.hydraulic?jN(e,e.hydraulic):WN(e),zS.set(e,t)),t}function WN(e){let t=Math.min(.99,Math.max(.01,e.balanceFront));return{mode:e.mode,equalLeftRight:e.mode!=="tyre",uMax:1/0,shares:{front:t,rear:1-t},demand:r=>({front:t*r,rear:(1-t)*r,regenFront:0,regenRear:0,pFront:0,pRear:0,pedalN:0}),controlFor:r=>Math.max(0,r)}}function jN(e,t){let r=vo(t.front,e.tyreRadiusM),n=vo(t.rear,e.tyreRadiusM),o=e.regen,a=(c,l)=>{let u=Kc(t,c),m=0,p=0;if(o&&u.front>0){let d=o.fullAtBar>0?Math.min(1,u.front/o.fullAtBar):1;m=d*Bn(o.v,o.front,l),p=d*Bn(o.v,o.rear,l)}return{front:r*u.front+m,rear:n*u.rear+p,regenFront:m,regenRear:p,pFront:u.front,pRear:u.rear,pedalN:c}},s=t.pedalForceMaxN>0?t.pedalForceMaxN:1/0,i=(c,l)=>{let u=a(c,l);return u.front+u.rear};return{mode:"hydraulic",equalLeftRight:!0,uMax:s,demand:a,controlFor:(c,l)=>{if(!(c>0))return 0;let u=100;for(;i(u,l)<c&&u<1e6;)u*=2;if(u=Math.min(u,s),i(u,l)<=c)return u;let m=0;for(let p=0;p<60;p++){let d=.5*(m+u);i(d,l)<c?m=d:u=d}return u}}}function jg(e,t,r){let n=t>0?e.controlFor(t,r):0,o=e.demand(n>0?n:1,r),a=o.front+o.rear;return a>0?o.front/a:.5}var ld=vc,UN=.1,oa=(e,t)=>e.a*Math.sqrt(Math.max(0,1-(t/Math.max(1e-9,e.b))**2));function ud(e,t,r){if(!(r>t))return t;let n=(Math.sqrt(5)-1)/2,o=t,a=r,s=a-n*(a-o),i=o+n*(a-o),c=e(s),l=e(i);for(let p=0;p<48;p++)c<l?(o=s,s=i,c=l,i=o+n*(a-o),l=e(i)):(a=i,i=s,l=c,s=a-n*(a-o),c=e(s));let u=.5*(o+a),m=e(u);for(let p of[t,r]){let d=e(p);d>m&&(u=p,m=d)}return u}function qg(e,t,r){let n=Math.max(0,r-ld*t.b),o=Math.min(r,ld*e.b);if(!(n<=o))return;let a=(c,l)=>c.a*c.a*Math.max(0,1-(l/Math.max(1e-9,c.b))**2),s=c=>a(e,c)-a(t,r-c),i;if(s(n)<=0)i=n;else if(s(o)>=0)i=o;else{let c=n,l=o;for(let u=0;u<40;u++){let m=.5*(c+l);s(m)>0?c=m:l=m}i=.5*(c+l)}return{lo:n,hi:o,y1:i,c1:e.cap(i),c2:t.cap(r-i)}}function Qg(e,t,r,n,o=0){let a=Math.max(0,r),s=qg(e,t,a),i=s?s.c1:0,c=s?s.c2:0,l=s?Math.min(i,c):0,[u,m]=e.a<=t.a?[e,t]:[t,e],p=u.Fz/Math.max(1e-9,u.Fz+m.Fz),d=Math.max(0,Math.min(1,1-p/UN)),f=d>0&&a<ld*m.b?m.cap(a):0,h=f>l?l+d*(f-l):0,b=Math.max(0,Math.min(u.slide,u.a)),g={xNoLock:l,xLock:h,slide:b,ceiling:Math.max(0,n)},y=Math.max(0,o);if(!(y>0)||!s)return{...g,regenWheel:s?y:0,mixedMax:2*l,regenRoom:M=>2*Math.max(0,l-M)};let{lo:x,hi:R}=s,v=ud(M=>{let k=oa(e,M),w=oa(t,a-M);return Math.min(k+w,2*Math.min(k,w)+y)},x,R),S=e.cap(v),A=t.cap(a-v),C=Math.max(2*l,Math.min(S+A,2*Math.min(S,A)+y)),F=(M,k,w)=>Math.min(y,Math.max(0,M-w))+Math.min(y,Math.max(0,k-w));return{...g,regenWheel:y,mixedMax:C,regenRoom:M=>{let k=F(i,c,M);if(!(a>0))return k;let w=_=>ld*_.b*Math.sqrt(Math.max(0,1-(M/Math.max(1e-9,_.a))**2)),P=Math.max(x,a-w(t)),L=Math.min(R,w(e));if(!(P<=L))return k;let E=ud(_=>Math.min(y,oa(e,_)-M)+Math.min(y,oa(t,a-_)-M),P,L);return Math.max(k,F(e.cap(E),t.cap(a-E),M))}}}var Ug=e=>Math.max(e.xNoLock,e.xLock),Xg=e=>Math.max(e.mixedMax,2*e.xLock);function Ks(e,t,r=0){let n=1e-9*Math.max(1,t),o=Math.max(0,r);if(t<=e.xNoLock+n)return Math.min(2*t+(o>0?Math.min(o,e.regenRoom(t)):0),e.ceiling);if(t<=e.xLock+n){let a=o>0?Math.min(e.regenWheel>0?Math.min(o,e.regenWheel):o/2,Math.max(0,e.xLock-t)):0;return Math.min(t+e.slide+a,e.ceiling)}return NaN}function Hs(e,t){let r=t/2,n=1e-9*Math.max(1,r);return r<=e.mixedMax/2+n?Math.min(t,e.ceiling):r<=e.xLock+n?Math.min(r+e.slide,e.ceiling):NaN}function Yc(e,t,r,n){return e.shares?XN(e,e.shares,t,r,n):qN(e,t,r,n)}function QS(e,t){let r=e[0],n=t(r.u);for(let o of e.slice(1)){let a=t(o.u);a>n&&(r=o,n=a)}return{cand:r,force:n}}function XN(e,t,r,n,o){let a=Xg(r),s=Xg(n),i=Math.min(t.front>0?a/t.front:1/0,t.rear>0?s/t.rear:1/0,e.uMax),c=Number.isFinite(e.uMax)&&i>=e.uMax,l=b=>{let g=Hs(r,t.front*b),y=Hs(n,t.rear*b);return Number.isFinite(g)&&Number.isFinite(y)?g+y:-1/0},u=a>0?t.front*i/a:1/0,m=s>0?t.rear*i/s:1/0,p=[{u:i,by:c?"pedal":u>=m?"front":"rear"}];if(r.xLock>r.xNoLock){let b=t.front>0?r.mixedMax/t.front:1/0;b<i&&p.push({u:b,by:"front"})}if(n.xLock>n.xNoLock){let b=t.rear>0?n.mixedMax/t.rear:1/0;b<i&&p.push({u:b,by:"rear"})}let{cand:d,force:f}=QS(p,l),h=e.demand(d.u,o);return{force:Math.max(0,Number.isFinite(f)?f:0),control:d.u,demand:h,limitedBy:d.by,lockFront:h.front/2>r.mixedMax/2*(1+1e-9),lockRear:h.rear/2>n.mixedMax/2*(1+1e-9)}}function qN(e,t,r,n){let o=Ug(t),a=Ug(r),s=v=>(v.front-v.regenFront)/2,i=v=>(v.rear-v.regenRear)/2,c=v=>{let S=e.demand(v,n);return s(S)<=o*(1+1e-12)&&i(S)<=a*(1+1e-12)},l=(v,S)=>{if(v(e.demand(S,n)))return S;let A=0,C=S;for(let F=0;F<60;F++){let T=.5*(A+C);v(e.demand(T,n))?A=T:C=T}return A},u=Number.isFinite(e.uMax)?e.uMax:100;if(!Number.isFinite(e.uMax))for(;c(u)&&u<1e7;)u*=2;let m=c(u)?u:l(v=>s(v)<=o&&i(v)<=a,u),p=Number.isFinite(e.uMax)&&m>=e.uMax,d=v=>{let S=e.demand(v,n),A=Ks(t,s(S),S.regenFront),C=Ks(r,i(S),S.regenRear);return Number.isFinite(A)&&Number.isFinite(C)?A+C:-1/0},f=e.demand(m,n),h=o>0?s(f)/o:1/0,b=a>0?i(f)/a:1/0,g=[{u:m,by:p?"pedal":h>=b?"front":"rear"}];if(t.xLock>t.xNoLock){let v=l(S=>s(S)<=t.xNoLock,m);v<m&&g.push({u:v,by:"front"})}if(r.xLock>r.xNoLock){let v=l(S=>i(S)<=r.xNoLock,m);v<m&&g.push({u:v,by:"rear"})}let{cand:y,force:x}=QS(g,d),R=e.demand(y.u,n);return{force:Math.max(0,Number.isFinite(x)?x:0),control:y.u,demand:R,limitedBy:y.by,lockFront:s(R)>t.xNoLock*(1+1e-9),lockRear:i(R)>r.xNoLock*(1+1e-9)}}var Kr={regen:!0};function Gn(e,t){return{regen:(e.energy??t??Kr).regen===!0}}function Kn(e,t,r){let n=Math.max(0,Math.floor(r));if(n===0)return[];if(n===1)return[e];let o=new Array(n),a=(t-e)/(n-1);for(let s=0;s<n;s++)o[s]=e+a*s;return o[n-1]=t,o}function ZS(e,t,r){let n=[],o=Math.floor((r-e)/t+1e-9);for(let a=0;a<=o;a++)n.push(e+t*a);return n}function Pt(e,t,r){let n=e.length;if(r<e[0]||r>e[n-1])return NaN;if(r===e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function md(e,t,r){let n=e.length;if(!(r>=e[0]&&r<=e[n-1]))return NaN;if(n<3)return n===1?t[0]:t[0]+(r-e[0])/(e[1]-e[0])*(t[1]-t[0]);let o=0,a=n-1;for(;a-o>1;){let f=o+a>>1;e[f]<=r?o=f:a=f}if(o===n-1)return t[n-1];let s=f=>e[f+1]-e[f],i=f=>(t[f+1]-t[f])/s(f),c=f=>{if(f===0||f===n-1){let[y,x]=f===0?[0,1]:[n-2,n-3],R=i(y)*(1+s(y)/(s(y)+s(x)))-i(x)*(s(y)/(s(y)+s(x)));return R*i(y)<=0?0:Math.abs(R)>2*Math.abs(i(y))?2*i(y):R}let h=i(f-1),b=i(f),g=(h*s(f)+b*s(f-1))/(s(f-1)+s(f));return(Math.sign(h)+Math.sign(b))*Math.min(Math.abs(h),Math.abs(b),.5*Math.abs(g))},l=s(o),u=i(o),m=c(o),p=c(o+1),d=r-e[o];return t[o]+d*(m+d*((3*u-2*m-p)/l+d*(m+p-2*u)/(l*l)))}function Wc(e,t,r){return r.map(n=>Pt(e,t,n))}var jc=e=>e.reduce((t,r)=>r>t?r:t,-1/0),zs=e=>e.reduce((t,r)=>r<t?r:t,1/0);var QN=[-.906179845938664,-.538469310105683,0,.538469310105683,.906179845938664],ZN=[.236926885056189,.478628670499366,.568888888888889,.478628670499366,.236926885056189];function Zg(e,t,r){let n=.5*(r-t),o=.5*(t+r),a=0;for(let s=0;s<5;s++)a+=ZN[s]*e(n*QN[s]+o);return n*a}var JN=Math.PI*2,eO=.5/3.6;function Uc(e,t){let r=Math.max(0,Math.round(e));if(t==="front")return{front:r,rear:0};if(t==="rear")return{front:0,rear:r};let n=Math.floor(r/2);return{front:n,rear:r-n}}function Jg(e,t,r,n,o){let a=e.rpm,s=e.torque,i=a.length,c=new Array(i),l=new Array(i);for(let g=0;g<i;g++){let y=a[g]/60*JN;c[g]=y*o/n,l[g]=s[g]*n/o}let u=jc(c),m=Kn(zs(c),u,u/eO),p=Wc(c,l,m),{front:d,rear:f}=Uc(t,r),h=p.map(g=>g*d),b=p.map(g=>g*f);return{vVehicle:m,fFront:h,fRear:b,vMax:u}}var JS=60/(2*Math.PI),eA=.1,tA=.08,rA=0;function e0(e){let t=(r,n)=>r===void 0||!Number.isFinite(r)?n:Math.max(0,r);return{up:t(e.upshiftTime,eA),down:t(e.downshiftTime,tA)}}function t0(e){let t=e.driveKept;return t===void 0||!Number.isFinite(t)?rA:Math.max(0,Math.min(1,t))}function r0(e,t,r){let{primary:n,ratios:o,efficiency:a}=e.gearbox,s=t>0&&r>0&&n>0,i=(b,g)=>b/JS*r/g,c=s?o.filter(b=>b>0).map(b=>{let g=n*b*t;return{ratio:g,vIdle:i(e.idleRpm,g),vLimit:i(e.limitRpm,g)}}):[],l=Math.max(0,Math.min(1,a)),u=Math.max(0,e.inertia),m=b=>b>e.limitRpm?0:Math.max(0,ot(e.rpm,e.torque,b)),p=(b,g)=>{let y=c[g];return y?b*y.ratio/r*JS:0},d=(b,g)=>g===0&&c.length>0&&b<c[0].vIdle,f=(b,g)=>{let y=c[g];return y?d(b,g)?m(e.idleRpm)*y.ratio*l/r:b<y.vIdle||b>y.vLimit?0:m(p(b,g))*y.ratio*l/r:0},h=(b,g)=>{let y=c[g];return!y||d(b,g)?0:u*y.ratio*y.ratio/(r*r)};return{engine:e,gears:c,efficiency:l,rDyn:r,vMax:c.length?c[c.length-1].vLimit:0,rpm:p,torque:m,force:f,inertiaMass:h,slipping:d}}function Ys(e,t,r,n=0,o=1){let a=-1,s=-1/0;for(let i=0;i<e.gears.length;i++){let c=(o*e.force(t,i)+n)/(r+e.inertiaMass(t,i));c>=s&&(s=c,a=i)}return{gear:a,accel:s}}function n0(e,t){let r=0;for(let n=0;n<e.gears.length;n++)r=Math.max(r,e.force(t,n));return r}var nA=9.81,oA=Math.PI*2;function mr(e){let t=e.motor.rpm,r=e.motor.torque,n=t.length,o=new Array(n),a=new Array(n),s=new Array(n),i=new Array(n),c=new Array(n),l=e.gear_ratio.value,u=e.r_dyn.value;for(let v=0;v<n;v++)o[v]=r[v]*t[v]*(oA/60),a[v]=t[v]/60*oA,s[v]=a[v]*u/l,i[v]=r[v]*l,c[v]=i[v]/u;let m=jc(s),p=m,d=.5/3.6,f=Kn(zs(s),m,m/d),h=Wc(s,c,f),b=Kn(zs(t),jc(t),250),g=Wc(t,o,b).map(v=>v*e.power_scale.value),y,x=p,R;if(e.motorModel?.kind==="ice"){R=r0(e.motorModel,l,u);let v=Kn(0,R.vMax,Math.max(2,Math.ceil(R.vMax/d)+1)),S=v.map(F=>n0(R,F)),A=v.map(()=>0),C=e.motorPlacement==="front";y={vVehicle:v,fFront:C?S:A,fRear:C?A:S,vMax:R.vMax},x=R.vMax}else e.motorModel&&(y=Jg(e.motorModel,Math.max(1,Math.round(e.motorCount??e.driven_wheels.value)),e.motorPlacement??"rear",l,u),x=y.vMax);return{params:e,g:nA,FG:e.m.value*nA,vMax:x,vVehicle:f,fRad:h,uMotor:b,pMotor:g,vRad:s,fAxle:y,...R?{engine:R}:{}}}var dr=e=>e.motorModel?.kind==="ice"?Uc(1,e.motorPlacement==="front"?"front":"rear"):Uc(Math.max(1,Math.round(e.motorCount??e.driven_wheels?.value??2)),e.motorPlacement??"rear");function aA(e){let t=dr(e);return t.front>=2||t.rear>=2}function sA(e){return aA(e)?e.motorMount??"hub":"chassis"}function o0(e){if(!e.motorModel)return{front:!1,rear:!0};let t=dr(e);return{front:t.front>0,rear:t.rear>0}}function dd(e){let t=dr(e),r=t.front>0,n=t.rear>0,o=e.front_mass_diss?.value??.5,a=Math.max(0,Math.min(1,o>1?o/100:o)),s=sA(e)==="chassis",i=c=>c===1||c>1&&s;return{front:r&&n?a:r?1:0,inboard:{front:i(t.front),rear:i(t.rear)}}}function Wt(e){return Wg(e.brakeModel,e.brakeSetup)}function Xc(e){return $n(e.brakeSetup).ideal?"tyre":e.brakeModel||e.brakeModelId?"hydraulic":"balance"}function pd(e){let t=Xc(e);return t==="hydraulic"?{brake_balance:"set by the balance bar and the brake hardware"}:t==="tyre"?{brake_balance:"tyre-limited brakes split as the grip does"}:{}}function iA(e,t){if(!(yt(e.motorModel)||!Gn(e).regen))return zc(fd(mr(e)),t??Wt(e).regen)}function fd(e){return e.fAxle??{vVehicle:e.vVehicle,fFront:e.vVehicle.map(()=>0),fRear:e.fRad.map(t=>t*e.params.driven_wheels.value)}}function a0(e,t=Wt(e)){if(t.mode==="hydraulic")return Hc(t.hydraulic,e.r_dyn.value);if(t.mode==="tyre"){let r=e.front_mass_diss.value>1?e.front_mass_diss.value/100:e.front_mass_diss.value;return Math.min(.95,Math.max(.05,r+J(e,"cg_height")/Math.max(1,J(e,"wheelbase"))))}return J(e,"brake_balance")}function s0(e,t=Wt(e)){return{front:t.hydraulic.front.location==="inboard",rear:t.hydraulic.rear.location==="inboard"}}function i0(e){let t=Wt(e);return{brakeBalanceFront:a0(e,t),brakeInboard:s0(e,t)}}function cA(e,t=Wt(e)){if(t.mode==="tyre"||t.regen.distribution!=="wheel"||yt(e.motorModel))return;let r=dr(e),n={front:r.front>=2,rear:r.rear>=2};return n.front||n.rear?n:void 0}function qc(e){let t=Wt(e),r=e.r_dyn.value,n=s0(e,t),o=a0(e,t),a=cA(e,t),s=t.mode==="hydraulic"||a?iA(e,t.regen):void 0;return{mode:t.mode,balanceFront:o,...t.mode==="hydraulic"?{hydraulic:t.hydraulic}:{},tyreRadiusM:r,inboard:n,...s?{regen:{...s,fullAtBar:t.regen.fullAtBar}}:{},...s&&a?{regenPerWheel:a}:{}}}var rO=9.81;var c0={front:0,rear:0,total:0};function l0(e,t){if(yt(e.motorModel))return()=>c0;let r=Wt(e),n=zc(t,r.regen);if(r.mode==="hydraulic"){let a=na({mode:"hydraulic",balanceFront:Hc(r.hydraulic,e.r_dyn.value),hydraulic:r.hydraulic,tyreRadiusM:e.r_dyn.value,regen:{...n,fullAtBar:r.regen.fullAtBar}});return(s,i)=>{if(!(s>0))return c0;let c=a.demand(a.controlFor(s,i),i),l=c.regenFront+c.regenRear,u=Math.min(s,l),m=l>0?u/l:0;return{front:c.regenFront*m,rear:c.regenRear*m,total:u}}}let o=r.mode==="tyre"?nO(e):()=>Math.min(.99,Math.max(.01,J(e,"brake_balance")));return(a,s,i)=>{if(!(a>0))return c0;let c=o(s,i),l=Math.min(c*a,Bn(n.v,n.front,s)),u=Math.min((1-c)*a,Bn(n.v,n.rear,s));return{front:l,rear:u,total:l+u}}}function nO(e){let t=e.m.value*rO,r=e.front_mass_diss.value>1?e.front_mass_diss.value/100:e.front_mass_diss.value,n=J(e,"cg_height")/Math.max(1,J(e,"wheelbase")),o=1-Math.max(0,Math.min(1,J(e,"cop_long"))),a=.5*e.rho.value*e.c_l.value*e.A.value;return(s,i)=>{let c=Math.max(0,a*s*s),l=t*(r+Math.abs(i)*n)+c*o;return Math.min(.99,Math.max(.01,l/(t+c)))}}function lA(e){let t=e==="front"?"Front axle":"Rear axle";return{[`${e}.location`]:{section:t,label:"Disc location",control:"Mounting"},[`${e}.discs`]:{section:t,label:"Discs",control:"Mounting"},[`${e}.ratio`]:{section:t,label:"Reduction to the wheel",unit:": 1"},[`${e}.pistonsPerSide`]:{section:t,label:"Pistons a side"},[`${e}.pistonDiaMm`]:{section:t,label:"Piston bore",unit:"mm"},[`${e}.padMu`]:{section:t,label:"Pad friction \u03BC"},[`${e}.effRadiusMm`]:{section:t,label:"Effective radius",unit:"mm"},[`${e}.heat.discMassKg`]:{section:t,label:"Disc mass",unit:"kg"},[`${e}.heat.discOuterMm`]:{section:t,label:"Disc diameter",unit:"mm"},[`${e}.heat.specificHeatJPerKgK`]:{section:t,label:"Specific heat",unit:"J/(kg\xB7K)"},[`${e}.heat.emissivity`]:{section:t,label:"Emissivity"},[`${e}.heat.coolingWPerM2K`]:{section:t,label:"Cooling at 60 km/h",unit:"W/(m\xB2\xB7K)"},[`${e}.heat.padCurve.tempC`]:{section:t,label:"Pad curve temperature",unit:"\xB0C"},[`${e}.heat.padCurve.factor`]:{section:t,label:"Pad curve friction"}}}var u0={pedalRatio:{section:"Pedal box & bar",label:"Pedal ratio",unit:": 1"},barLengthMm:{section:"Pedal box & bar",label:"Bar length, clevis to clevis",unit:"mm"},adjusterPitchMm:{section:"Pedal box & bar",label:"Adjuster pitch",unit:"mm/turn"},masterFrontMm:{section:"Master cylinders",label:"Front bore",unit:"mm"},masterRearMm:{section:"Master cylinders",label:"Rear bore",unit:"mm"},valve:{section:"Rear valve",label:"Valve"},valveKneeBar:{section:"Rear valve",label:"Knee",unit:"bar"},valveSlope:{section:"Rear valve",label:"Gain above the knee"},...lA("front"),...lA("rear")},m0={ideal:{label:"Ideal brakes"},barFront:{label:"Balance bar"},pedalForceMaxN:{label:"Pedal force",unit:"N"},testSpeedKmh:{section:"Brake test",label:"Speed",unit:"km/h"},"regen.maxPowerKw":{section:"Regen",label:"Power ceiling",unit:"kW"},"regen.fadeBelowKmh":{section:"Regen",label:"Fades out below",unit:"km/h"},"regen.fullAtBar":{section:"Regen",label:"Full at",unit:"bar"},"regen.distribution":{section:"Regen",label:"Wheel by wheel"}};function d0(e){let t=u0[e];return`${t.label}, ${t.section}`.toLowerCase()}function p0(e){let t=m0[e];return t.section?`${t.section} ${t.label.charAt(0).toLowerCase()}${t.label.slice(1)}`:t.label}var uA=new WeakMap;function cn(e){if(e.brakes)return e.brakes;let t=uA.get(e);if(!t){let r=Math.max(.05,(e.unsprungCgHeight||230)/1e3);t=e.brakeBalanceFront!=null?{mode:"balance",balanceFront:e.brakeBalanceFront,tyreRadiusM:r}:{mode:"tyre",balanceFront:e.frontMassFrac,tyreRadiusM:r},uA.set(e,t)}return t}var Hn=e=>na(cn(e));var iO=Math.PI/180,Ws=Object.freeze({tbr:1,preloadN:0}),hd=Object.freeze({tbr:1/0,preloadN:0}),h0=e=>e.faces*e.muClutch*e.rFrictionMm/e.rRampMm;function b0(e,t){if(!(e>0)||Number.isNaN(t))return 0;let r=Math.tan(Math.min(90,t)*iO);return r>0?Math.min(1,e/r):1}function dA(e){if(e>=1)return 1/0;let t=e>0?e:0;return(1+t)/(1-t)}function bd(e){return e===1/0?1:e>1?(e-1)/(e+1):0}function aa(e,t){return e.tbr===1/0?1/0:(e.preloadN>0?e.preloadN:0)+bd(e.tbr)*Math.abs(t)}function Zc(e,t,r){let n=o=>o!==void 0&&o>0&&r>0?o/r:0;switch(e.kind){case"open":return Ws;case"spool":return hd;case"independent":return t==="hubs"?Ws:hd;case"clutch":{let o=n(e.preloadNm);return t==="hubs"?{tbr:1,preloadN:o}:{tbr:dA(b0(h0(e),t==="drive"?e.rampDriveDeg:e.rampCoastDeg)),preloadN:o}}case"torsen":{let o=n(e.preloadNm);if(t==="hubs")return{tbr:1,preloadN:o};let a=t==="drive"?e.tbrDrive:e.tbrCoast;return{tbr:a>1?a:1,preloadN:o}}}}function Qc(e,t,r){let n=Math.max(0,Math.min(e,t)),o=Math.max(0,Math.max(e,t)),a=r.tbr>1?r.tbr:1,s=r.preloadN>0?r.preloadN:0;return a===1/0||s===1/0?n+o:n+Math.min(o,a*n+s*(1+a)/2)}var mA=4;function f0(e,t){let r=0;for(let a of e)r=Math.max(r,Qc(a.m1,a.m2,t));let n=t.tbr>1?t.tbr:1,o=(t.preloadN>0?t.preloadN:0)*(1+n)/2;if(n===1/0||o===1/0)return r;for(let a=0;a+1<e.length;a++){let s=e[a],i=e[a+1].m1-s.m1,c=e[a+1].m2-s.m2,l=p=>{p>0&&p<1&&(r=Math.max(r,Qc(s.m1+p*i,s.m2+p*c,t)))};i!==c&&l((s.m2-s.m1)/(i-c));let u=i+c-(1+n)*i,m=i+c-(1+n)*c;u!==0&&l(((1+n)*s.m1+o-s.m1-s.m2)/u),m!==0&&l(((1+n)*s.m2+o-s.m1-s.m2)/m)}return r}function Jc(e,t,r,n,o){let a=Math.max(0,o),s=n.tbr>1?n.tbr:1,i=n.preloadN>0?n.preloadN:0;if(s===1/0||i===1/0)return a;let c=Math.max(0,r),l=qg(e,t,c),u=l?2*Math.min(l.c1,l.c2):0;if(!l||s===1&&i===0||!(a>u))return Math.min(u,a);let m=ud(b=>oa(e,b)+oa(t,c-b),l.lo,l.hi),p=[{m1:l.c1,m2:l.c2}];for(let b=1;b<=mA&&m!==l.y1;b++){let g=l.y1+(m-l.y1)*b/mA;p.push({m1:e.cap(g),m2:t.cap(c-g)})}let d=f0(p,Ws),f=f0(p,hd);if(!(f>d))return u;let h=(f0(p,{tbr:s,preloadN:i})-d)/(f-d);return Math.min(a,u+(a-u)*Math.min(1,Math.max(0,h)))}function pA(e,t,r,n,o,a){return g0(e,o,Jc(t,r,n,o,a))}function g0(e,t,r){let n=Math.max(e.xNoLock,r/2),o=t.tbr===1/0||!(e.xLock>n)?0:e.xLock;return e.regenWheel>0?{...e,xNoLock:n,xLock:o,mixedMax:Math.max(e.mixedMax,2*n)}:{...e,xNoLock:n,xLock:o,mixedMax:2*n,regenRoom:a=>2*Math.max(0,n-a)}}function y0(e,t,r,n=30){let o=t,a=e(o),s=a-o;if(!(Math.abs(s)>r))return{x:o,fx:a,evals:1};let i=a,c=e(i),l=c-i,u=2;for(;Math.abs(l)>r&&u<n;){let m=s<0!=l<0,p=l-s,d=p!==0?i-l*(i-o)/p:NaN;m?d>Math.min(o,i)&&d<Math.max(o,i)||(d=.5*(o+i)):Number.isFinite(d)?Math.abs(d-i)>10*Math.abs(l)&&(d=i+Math.sign(d-i)*10*Math.abs(l)):d=c;let f=e(d),h=f-d;if(u++,m&&h<0==l<0?s*=.5:(o=i,s=l),i=d,c=f,l=h,s<0!=l<0&&Math.abs(i-o)<=r)break}return{x:i,fx:c,evals:u}}function fA(e,t,r,n,o,a=60){let s=t,i=e(s),c=i-s,l=1;if(!(Math.abs(c)>n))return{x:s,fx:i,evals:l};let u=Math.sign(r-t),m=Math.abs(r-t),p=0;for(let d=o;l<a;d*=2){if(p=Math.min(p+d,m),p>m-n)return null;let f=t+u*p,h=e(f),b=h-f;if(l++,!(Math.abs(b)>n))return{x:f,fx:h,evals:l};if(c<0!=b<0)return bA(e,s,c,f,h,b,n,l,a);s=f,c=b}return null}function hA(e,t,r,n=60){let o=t,a=e(o),s=a-o;if(!(Math.abs(s)>r))return{x:o,fx:a,evals:1};let i=Math.sign(s),c=a;for(let l=2;;l++){let u=e(c),m=u-c;if(!(Math.abs(m)>r))return{x:c,fx:u,evals:l};if(s<0!=m<0)return bA(e,o,s,c,u,m,r,l,n);if(l>=n)return{x:c,fx:u,evals:l};let p=Math.abs(c-o),d=s!==m?m*(c-o)/(s-m):NaN,f=d*i>0?Math.min(Math.abs(d),10*Math.abs(m),2*p):2*p;o=c,s=m,c+=i*f}}function bA(e,t,r,n,o,a,s,i,c){let l=t,u=r,m=n,p=a,d=n,f=o,h=0;for(;i<c&&Math.abs(m-l)>s;){d=(l*p-m*u)/(p-u),f=e(d);let b=f-d;if(i++,!(Math.abs(b)>s))break;b<0==u<0?(l=d,u=b,h===-1&&(p*=.5),h=-1):(m=d,p=b,h===1&&(u*=.5),h=1)}return{x:d,fx:f,evals:i}}function gd(e,t){return Math.abs(e.fx-e.x)>t?e.x:e.fx}var cO=(e,t)=>{let r=e.brakes?.hydraulic?.[t];return!!r&&r.location==="inboard"&&r.discs===1};function pr(e,t,r){let n=e.driveline?.[t];if(n)return r>=0?n.drive:cO(e,t)?n.coast:n.hubs}var gA=e=>e.tbr>1||e.preloadN>0;var lO=9.81,yA=["FL","FR","RL","RR"],x0=e=>e==="FL"||e==="FR",yd=e=>x0(e)?"front":"rear",xA={front:["FL","FR"],rear:["RL","RR"]},rl=()=>({peak:new Map,freeBrake:new Map}),tl=25;function el(e,t){let r=Math.max(0,e)/tl,n=Math.floor(r),o=r-n,a=t(n);return o>0?a+o*(t(n+1)-a):a}var ko=1e-4,uO=.05;function zn(e,t,r,n=rl(),o=!1){let a=r,s=e.massTotal,i=n.peak,c=(k,w)=>{let P=`${k}:${w}`,L=i.get(P);return L||(L=Fm(Te(t,k),Math.max(1,w*tl)),i.set(P,L)),L},l=(k,w)=>({aPeak:el(w,P=>c(k,P).aPeak),fyPeak:el(w,P=>c(k,P).fyPeak)}),u=n.freeBrake,m=(k,w)=>{let P=`${k}:${w}`,L=u.get(P);if(L===void 0){let E=Math.max(1,w*tl);L=lr(Te(t,k),E,0,!0,c(k,w)),u.set(P,L)}return L},p=(k,w)=>w>0?el(w,P=>m(k,P)):0,d=Hn(e),f=cn(e),h=k=>f.regen&&f.regenPerWheel?.[k]?Bn(f.regen.v,f.regen[k],a)/2:0,b=h("front"),g=h("rear"),y=(k,w,P)=>{let L=Math.max(0,w[k]),E=l(yd(k),L);return lr(Te(t,yd(k)),L,P[k]*E.fyPeak,!0,E)},x=(k,w,P,L,E=!0,_=1)=>{let D=te=>{let j=Math.max(0,w[te]),X=Te(t,k),le=l(k,j),pe={Fz:j,a:Math.abs(p(k,j)),b:le.fyPeak,slide:j>0?Math.abs(X.forces({Fz:j,kappa:-1,alpha:0}).Fx):0,cap:ue=>Math.abs(lr(X,j,ue,!0,le))};return _===1?pe:{Fz:j,a:_*pe.a,b:_*pe.b,slide:_*pe.slide,cap:ue=>_*pe.cap(ue/_)}},I=te=>_*Math.abs(P[te])*l(yd(te),Math.max(0,w[te])).fyPeak,[N,O]=xA[k],V=D(N),H=D(O),U=I(N)+I(O),G=Qg(V,H,U,L,k==="front"?b:g),B=E?G:{...G,xLock:0},q=pr(e,k,-1),re=q&&gA(q)?q:void 0;if(!re)return{axle:k,eq:B,cap:B};let W=Number.isFinite(L)?L:V.cap(I(N))+H.cap(I(O)),z=pA(B,V,H,U,re,W);return{axle:k,eq:B,cap:z,law:re,strong:()=>V.cap(I(N))>=H.cap(I(O))?N:O}},R=(k,w,P,L,E=1)=>x(k,w,P,L,!0,E).cap,v=(k,w,P)=>{let L=k.demand,E=d.shares?Hs(w,L.front):Ks(w,(L.front-L.regenFront)/2,L.regenFront),_=d.shares?Hs(P,L.rear):Ks(P,(L.rear-L.regenRear)/2,L.regenRear);return{front:Number.isFinite(E)?E:0,rear:Number.isFinite(_)?_:0}},S=k=>({muX:w=>w>0?Math.abs(p(k,w))/w:0,muY:w=>w>0?l(k,w).fyPeak/w:0}),A={front:S("front"),rear:S("rear")},C={lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},F={front:e.trackFront/2e3,rear:e.trackRear/2e3},T=(k,w,P,L,E)=>{let _=L.cap,D=E.cap,I=Yc(d,_,D,a),N={arms:C,halfTrack:F,ayDir:Math.sign(k)};for(let O=0;O<2;O++){let V=v(I,_,D),H={};for(let G of yA){let B=Math.max(0,w[G]);H[G]={Fz:B,Fy:Math.abs(P[G])*l(yd(G),B).fyPeak,Fx:-(x0(G)?V.front:V.rear)/2}}let U=G=>{if(!G.law||!G.strong)return G.cap;let B={axle:G.axle,strong:G.strong(),full:2*G.cap.xNoLock,open:2*G.eq.xNoLock,sense:-1};return g0(G.eq,G.law,Xm(B,H,A,N))};_=U(L),D=U(E),I=Yc(d,_,D,a)}return{limit:I,front:_,rear:D}};return{peakAt:l,axle:R,ceiling:(k,w,P)=>{let[L,E]=xA[k];return Math.abs(y(L,w,P)+y(E,w,P))},limitAt:(k,w,P,L=0)=>{let E={FL:0,FR:0,RL:0,RR:0},_=Xe(e,k,0,a,0,w),D,I=te=>(D?.ax!==te&&(D={ax:te,loads:Xe(e,k,(te+L)/lO,a,0,w)}),D.loads),N=Cm(te=>Is(P,I(te),_,l).short,-L,-1),O=P,V={front:0,rear:0},H,U,G=(te,j=!0)=>{let X=N.at(te);E=I(X),O=Is(P,E,_,l).util;let le=0,pe=0,ue=0;for(let ie of yA){let ke=y(ie,E,O);le+=ke,x0(ie)?pe+=ke:ue+=ke}if(V={front:Math.abs(pe),rear:Math.abs(ue)},d.mode!=="tyre"){let ie=x("front",E,O,Math.abs(pe),j),ke=x("rear",E,O,Math.abs(ue),j);if(o&&(ie.law||ke.law)){let Ie=T(k,E,O,ie,ke);H=Ie.limit,U={front:Ie.front,rear:Ie.rear}}else H=Yc(d,ie.cap,ke.cap,a),U={front:ie.cap,rear:ke.cap};le=-H.force}return le/s},B=y0(G,0,ko),q=gd(B,ko),re=q;if(H?.lockFront||H?.lockRear){let te=y0(X=>G(X,!1),0,ko);re=gd(te,ko);let j=fA(G,te.x,B.x,ko,uO);j||G(B.x),q=gd(j??B,ko)}let W=N.edge(),z=W!==void 0&&q<W;z&&(q=Math.min(0,W),G(q),re=Math.max(re,q));let Y={loads:E,ceiling:V,limit:H,axles:U};return{ax:q,axUnlocked:re,...z?{edge:W}:{},...Y,split:()=>Y.limit&&Y.axles?v(Y.limit,Y.axles.front,Y.axles.rear):{...Y.ceiling}}}}}var Rd=9.81;function mO(e,t,r){let n=Xe(e,0,t,r),o=Math.max(0,n.FL)+Math.max(0,n.FR),a=Math.max(0,n.RL)+Math.max(0,n.RR);return o+a>0?o/(o+a):e.frontMassFrac}var kA=(e,t)=>t.mode==="hydraulic"&&!!cn(e).regen;function js(e,t,r=0,n,o=0,a=1){if(!e.brakes&&e.brakeBalanceFront==null)return e.frontMassFrac;let s=Hn(e);if(s.shares&&s.mode!=="tyre")return s.shares.front;let i=n&&kA(e,s)?AA(e,n):void 0,c=i?MA(a):sa,l=i?SA(i,c).shares:RA.get(e);l||RA.set(e,l=new Map);let u=Math.round(Math.abs(t)/.005),m=Math.round(Math.max(0,r)/.25),p=i?Math.round(o/.01):0,d=wA(u,m,p),f=l.get(d);if(f===void 0){let h=-u*.005,b=m*.25,g=e.massTotal*Math.abs(h)*Rd;if(i){let y=CA(s,FA(e,i,u,m,p,c),g,b);f=y.front+y.rear>0?y.front/(y.front+y.rear):.5}else f=s.mode==="tyre"?mO(e,h,b):jg(s,g,b);l.size>5e4&&l.clear(),l.set(d,f)}return f}var RA=new WeakMap;function vd(e,t,r,n,o=0,a=1){let s=Hn(e);if(!kA(e,s))return;let i=Math.round(Math.max(0,r)/(e.massTotal*Rd)/.005),c=Math.round(Math.max(0,n)/.25);return CA(s,FA(e,AA(e,t),i,c,Math.round(o/.01),MA(a)),Math.max(0,r),n)}var sa=100,MA=e=>e>0&&Number.isFinite(e)?Math.max(1,Math.round(e*sa)):sa;function SA(e,t){if(t===sa)return e;let r=e.roads.get(t);return r||e.roads.set(t,r={shares:new Map,rooms:new Map}),r}var vA=new WeakMap;function AA(e,t){let r=vA.get(e);r||vA.set(e,r=new WeakMap);let n=r.get(t);return n||r.set(t,n={ev:t,tyres:rl(),shares:new Map,rooms:new Map,speeds:new Map,roads:new Map}),n}var wA=(e,t,r)=>(r*1001+e)*100003+t;function FA(e,t,r,n,o,a=sa){let s=wA(r,n,o),i=SA(t,a),c=a===sa?1:a/sa,l=i.rooms.get(s);if(!l){let u=n*.25,m=o*.01,p=t.speeds.get(n);p||(p={cap:zn(e,t.ev,u,t.tyres),dragG:-Math.max(0,tc(e,u).drag)/(e.massTotal*Rd)},t.speeds.set(n,p));let{cap:d}=p,f=Xe(e,m,-r*.005+p.dragG,u),h=Math.abs(m)*e.massTotal*Rd,b=x=>{let[R,v]=x==="front"?["FL","FR"]:["RL","RR"],S=h*(x==="front"?e.frontMassFrac:1-e.frontMassFrac),A=c*(d.peakAt(x,Math.max(0,f[R])).fyPeak+d.peakAt(x,Math.max(0,f[v])).fyPeak),C=S>0&&A>0?Math.min(1,S/A):0;return d.axle(x,f,{FL:C,FR:C,RL:C,RR:C},1/0,c)},g,y;l=(x,R)=>(x==="front"?g??=b("front"):y??=b("rear")).regenRoom(R),i.rooms.size>5e4&&i.rooms.clear(),i.rooms.set(s,l)}return l}function xd(e,t,r,n){let o=e.demand(r,n),a=o.front-o.regenFront,s=o.rear-o.regenRear,i=o.regenFront>0?Math.min(o.regenFront,t("front",a/2)):0,c=o.regenRear>0?Math.min(o.regenRear,t("rear",s/2)):0;return{front:i===o.regenFront?o.front:a+i,rear:c===o.regenRear?o.rear:s+c,regenFront:i,regenRear:c,demand:o}}function CA(e,t,r,n){if(!(r>0))return xd(e,t,1,n);let o=c=>c.front+c.rear,a=e.controlFor(r,n),s=xd(e,t,a,n);if(o(s)>=r||!(a<e.uMax))return s;let i=a;for(;o(s)<r&&i<e.uMax&&i<1e7;)a=i,i=Math.min(e.uMax,2*i),s=xd(e,t,i,n);if(o(s)<r)return s;for(let c=0;c<60&&i-a>1e-10*i;c++){let l=.5*(a+i),u=xd(e,t,l,n);o(u)<r?a=l:(i=l,s=u)}return s}var Us={rel:.003,abs:2,kappa:1e-5,iters:12},Xs={rel:1e-6,abs:.001,kappa:1e-12,iters:40},Md={...Xs,settle:1e-9};function Mo(e,t,r,n=Us,o,a){let s=t>=0?1:-1,i=Math.abs(t),c=Math.max(n.abs,n.rel*i),l={kappa:NaN,forces:null},u=o??(C=>{let F=e(C);return l.kappa=C,l.forces=F,F.Fx}),m=u(0);if(Math.abs(m)-i>=0)return kd(e,l,0);let p=a?s>0?a.drive:a.brake:void 0;if(p&&p.mag<i)return p.stop;let d=0,f=m,h=Math.abs(m)-i,b=Math.min(.3,Math.max(.004,Math.abs(r)||.02)),g=u(s*b),y=Math.abs(g)-i,x=NaN,R=0;for(;y<0&&b<.3;){let C=Math.min(.3,b*1.9),F=u(s*C),T=Math.abs(F);if(T<Math.abs(g)){x=C,R=F;break}d=b,f=g,h=y,b=C,g=F,y=T-i}if(y<0){let C=fO(u,s,d,f,b,g,x,R);if(C.mag<i){let F=kd(e,l,s*C.kappa);return a&&(a[s>0?"drive":"brake"]={mag:C.mag,stop:F}),F}b=C.kappa,y=C.mag-i}let v=s*b,S=n.settle;if(S!==void 0){let C=d,F=h,T=b,M=y;Math.abs(F)<Math.abs(M)&&([C,F,T,M]=[T,M,C,F]);let k=0;for(let w=0;w<n.iters&&b-d>n.kappa;w++){let P=M-F,L=k<2&&Math.abs(P)>1e-12?T-M*(T-C)/P:NaN;if(!(L>d&&L<b)){let D=y-h;L=k<2&&Math.abs(D)>1e-12?(d*y-b*h)/D:.5*(d+b),L>d&&L<b||(L=.5*(d+b)),k=0}let E=Math.abs(u(s*L))-i;v=s*L;let _=E!==M?Math.abs(E*(L-T)/(E-M)):1/0;if(Math.abs(E)<c&&(Math.abs(L-T)<=S||_<=S))break;k=Math.abs(E)>.5*Math.abs(M)?k+1:0,E<0?(d=L,h=E):(b=L,y=E),C=T,F=M,T=L,M=E}return kd(e,l,v)}let A=NaN;for(let C=0;C<n.iters&&b-d>n.kappa;C++){let F=y-h,T=Math.abs(F)>1e-12?(d*y-b*h)/F:.5*(d+b);T>d&&T<b||(T=.5*(d+b));let M=Math.abs(u(s*T))-i;if(v=s*T,Math.abs(M)<c&&(S===void 0||Math.abs(T-A)<=S))break;A=T,M<0?(d=T,h=M,y*=.5):(b=T,y=M,h*=.5)}return kd(e,l,v)}function kd(e,t,r){return t.forces!==null&&Object.is(t.kappa,r)?{kappa:r,forces:t.forces}:{kappa:r,forces:e(r===0?0:r)}}var TA=1e-6,dO=40,pO=(3-Math.sqrt(5))/2;function fO(e,t,r,n,o,a,s,i){let c,l,u,m=-Math.abs(a),p,d,f=-Math.abs(n);if(Number.isNaN(s)){c=.3;let g=.3*(1-TA),y=-Math.abs(e(t*g));if(y>=m)return{kappa:o,mag:-m};[l,p,u,d]=[o,m,r,f],o=g,m=y}else{c=s;let g=-Math.abs(i);[l,p,u,d]=g<=f?[c,g,r,f]:[r,f,c,g]}f<m&&([l,p]=[o,m],o=r,m=f);let h=c-r,b=0;for(let g=0;g<dO;g++){let y=TA*Math.abs(o)+1e-10,x=.5*(r+c);if(Math.abs(o-x)<=2*y-.5*(c-r))break;let R=!0;if(Math.abs(h)>y){let A=(o-l)*(m-d),C=(o-u)*(m-p),F=(o-u)*C-(o-l)*A;C=2*(C-A),C>0&&(F=-F),C=Math.abs(C);let T=h;if(h=b,Math.abs(F)<Math.abs(.5*C*T)&&F>C*(r-o)&&F<C*(c-o)){b=F/C;let M=o+b;(M-r<2*y||c-M<2*y)&&(b=x>=o?y:-y),R=!1}}R&&(h=o>=x?r-o:c-o,b=pO*h);let v=Math.abs(b)>=y?o+b:o+(b>=0?y:-y),S=-Math.abs(e(t*v));S<=m?(v>=o?r=o:c=o,u=l,d=p,l=o,p=m,o=v,m=S):(v<o?r=v:c=v,S<=p||l===o?(u=l,d=p,l=v,p=S):(S<=d||u===o||u===l)&&(u=v,d=S))}return{kappa:o,mag:-m}}var Sd=e=>Math.max(2,.003*Math.abs(e)),hO=(e,t)=>Math.max(t.abs,t.rel*Math.abs(e)),R0=.5,bO=.03;function gO(e,t,r,n,o,a=!1){let s=yO(e,t,r,n,o,a);return{kappaM:s.kappaM,kl:s.kl,kr:s.kr,fl:e.at(s.kl),fr:t.at(s.kr)}}function yO(e,t,r,n,o,a){let s=.5*(e.vx+t.vx),i=e.fxAt??(F=>e.at(F).Fx),c=t.fxAt??(F=>t.at(F).Fx),l=F=>{let T=(1+F)*s/e.vx-1,M=(1+F)*s/t.vx-1;return{kappaM:F,kl:T,kr:M,g:i(T)+c(M)-r}},u=hO(r,o),m=Math.max(-R0,Math.min(R0,n)),p=l(m);if(Math.abs(m)>bO){let F=l(.8*m);(p.g-F.g)/(m-F.kappaM)>0||(p=l(0))}if(Math.abs(p.g)<u)return p;let d=p.g<0?1:-1,f=p,h=p,b=.004,g=p,y=p;for(let F=0;F<12;F++){let T=f.kappaM+d*b;if(Math.abs(T)>R0)break;let M=l(T);if(Math.abs(M.g)<u)return M;if(Math.abs(M.g)<Math.abs(g.g)&&(g=M),Math.sign(M.g)!==Math.sign(f.g)){h=M;break}if(d*(M.g-f.g)<=0){if(!a)return g;let k=(Math.sqrt(5)-1)/2,w=y.kappaM,P=M.kappaM,L=l(P-k*(P-w)),E=l(w+k*(P-w));for(let D=0;D<40&&Math.abs(P-w)>1e-7;D++)d*(L.g-E.g)<0?(w=L.kappaM,L=E,E=l(w+k*(P-w))):(P=E.kappaM,E=L,L=l(P-k*(P-w)));let _=d*(L.g-E.g)>0?L:E;if(Math.abs(_.g)<u||Math.sign(_.g)===Math.sign(p.g))return Math.abs(_.g)<Math.abs(g.g)?_:g;f=d*(_.kappaM-f.kappaM)>0?f:y,h=_;break}y=f,f=M,b*=1.9}if(h===p)return g;let x=f,R=h,v=x.g,S=R.g,A=Math.abs(v)<Math.abs(S)?x:R,C=Math.min(1e-7,o.kappa);for(let F=0;F<30&&Math.abs(R.kappaM-x.kappaM)>C;F++){let T=S-v,M=Math.abs(T)>1e-12?(x.kappaM*S-R.kappaM*v)/T:.5*(x.kappaM+R.kappaM),k=Math.min(x.kappaM,R.kappaM),w=Math.max(x.kappaM,R.kappaM);M>k&&M<w||(M=.5*(k+w));let P=l(M);if(A=P,Math.abs(P.g)<u)break;Math.sign(P.g)===Math.sign(v)?(x=P,v=P.g,S*=.5):(R=P,S=P.g,v*=.5)}return A}function PA(e,t,r,n){let o=(e*(1+t*n)+t*r)/(1-t*n);return e+o>=0?o:(e*(1-t*n)+t*r)/(1+t*n)}function nl(e,t,r,n,o,a=Us,s=!1){let i=gO(e,t,r,o,a,s),c=i.fr.Fx-i.fl.Fx,l=aa(n,r);if(Math.abs(c)<=l){let R=r-(i.fl.Fx+i.fr.Fx),v=Math.max(0,Math.abs(R)-Sd(r))/2;return{left:{kappa:i.kl,forces:i.fl,want:i.fl.Fx+R/2,short:v},right:{kappa:i.kr,forces:i.fr,want:i.fr.Fx+R/2,short:v},locked:!0,spoolKappa:i.kappaM}}let u=Math.sign(c),m=r/2-u*l/2,p=r/2+u*l/2,d=Mo(e.at,m,e.seed||i.kl,a,e.fxAt),f=Mo(t.at,p,t.seed||i.kr,a,t.fxAt),h=Math.abs(m-d.forces.Fx)>Sd(m),b=Math.abs(p-f.forces.Fx)>Sd(p),g=Math.max(0,n.preloadN),y=bd(n.tbr);h&&!b?f=Mo(t.at,PA(d.forces.Fx,u,g,y),f.kappa,a,t.fxAt):b&&!h&&(d=Mo(e.at,PA(f.forces.Fx,-u,g,y),d.kappa,a,e.fxAt));let x=(R,v)=>({kappa:R.kappa,forces:R.forces,want:v,short:Math.max(0,Math.abs(v-R.forces.Fx)-Sd(v))});return{left:x(d,m),right:x(f,p),locked:!1,spoolKappa:i.kappaM}}var xO={front:["FL","FR"],rear:["RL","RR"]},RO=Object.freeze({Fx:0,Fy:0,Mz:0});function Ad(e,t,r,n){let o=r;for(let a of["front","rear"]){let[s,i]=xO[a],c=r[s]+r[i],l=pr(e,a,c);if(!l||!(aa(l,c)>0))continue;let u=Te(t,a),m=n.alpha[a],p=(a==="front"?e.trackFront:e.trackRear)/2e3,d=n.grip??1,f=x=>R=>u.forces({Fz:x,kappa:R,alpha:m,gamma:0}),h=x=>R=>{let v=u.forces({Fz:x,kappa:R,alpha:m,gamma:0});return{Fx:d*v.Fx,Fy:d*v.Fy,Mz:d*v.Mz}},b=on(u),g=(x,R)=>{let v=Math.max(0,n.Fz[x]);return{at:v>0?d===1?f(v):h(v):()=>RO,fxAt:v>0?d===1?S=>b(v,S,m,0):S=>d*b(v,S,m,0):()=>0,vx:Math.max(.05,1-R*n.curvature),seed:0}},y=nl(g(s,p),g(i,-p),c,l,n.seed?.[a]??0);n.seed&&(n.seed[a]=y.spoolKappa),o===r&&(o={...r}),o[s]=y.left.want,o[i]=y.right.want}return o}var ia=["FL","FR","RL","RR"];function v0(e,t,r,n={}){let o={FL:0,FR:0,RL:0,RR:0},a={FL:!1,FR:!1,RL:!1,RR:!1},s={FL:!1,FR:!1,RL:!1,RR:!1};if(t===0&&!e.tvRearDiffN)return{want:o,held:a,left:0,atTop:s};let i=t>=0?1:-1,c=Math.abs(t),l={FL:0,FR:0,RL:0,RR:0},u={FL:1/0,FR:1/0,RL:1/0,RR:1/0};if(i>0){let f=["front","rear"].filter(h=>e.drive[h]);for(let h of f){let[b,g]=h==="front"?["FL","FR"]:["RL","RR"],y=e.drive[h],x=r[b]+r[g];y==="ideal"?(l[b]=r[b],l[g]=r[g],a[b]=a[g]=!0):l[b]=l[g]=x/2}for(let h of ia){let b=e.motorCap?.[h];b!==void 0&&(u[h]=Math.max(0,b))}}else if(e.brake.kind==="ideal")for(let f of ia)l[f]=r[f],a[f]=!0;else{let f=Math.min(1,Math.max(0,e.brake.front));l.FL=l.FR=f/2,l.RL=l.RR=(1-f)/2;for(let h of ia)a[h]=e.brake.abs;if(e.brake.abs){let h=Math.min(1,Math.max(0,e.brake.absUse??.9));if(h<1)for(let b of ia)u[b]=h*r[b]}}let m=Math.max(-1,Math.min(1,e.idealShift??0));if(m!==0){let f={front:i>0?e.drive.front==="ideal":e.brake.kind==="ideal",rear:i>0?e.drive.rear==="ideal":e.brake.kind==="ideal"};for(let h of["front","rear"]){if(!f[h])continue;let[b,g]=h==="front"?["FL","FR"]:["RL","RR"],[y,x]=(e.turn??1)>0?[b,g]:[g,b],[R,v]=m>0?[y,x]:[x,y],S=Math.abs(m)*l[R];l[R]-=S,l[v]+=S}}for(let f of ia){let h=n[f];a[f]&&h!==void 0&&(u[f]=Math.min(u[f],Math.max(0,h)))}let p=vO(c,l,u);for(let f of ia)o[f]=i*p.each[f],s[f]=l[f]>0&&Number.isFinite(u[f])&&p.each[f]>=u[f];let d=e.tvRearDiffN??0;return d&&(o.RL-=d/2,o.RR+=d/2),{want:o,held:a,left:p.left,atTop:s}}function vO(e,t,r){let n={FL:0,FR:0,RL:0,RR:0},o=ia.filter(i=>t[i]>0),a=e,s=o;for(let i=0;i<4&&s.length>0&&a>0;i++){let c=s.reduce((m,p)=>m+t[p],0),l=a/c,u=s.filter(m=>l*t[m]>=r[m]);if(u.length===0){for(let m of s)n[m]=l*t[m];a=0,s=[];break}for(let m of u)n[m]=r[m],a-=r[m];s=s.filter(m=>!u.includes(m))}return{each:n,left:Math.max(0,a)}}var De=9.81,he=Math.PI/180,kO=8,MO=.02,SO=12,LA=e=>10*Math.max(Xs.abs,Xs.rel*Math.abs(e)),DA=1e-6,jt=["FL","FR","RL","RR"],Vt=e=>e==="FL"||e==="FR",Wn=e=>Vt(e)?"front":"rear";function Qs(e,t){let r=Te(e,"front"),n=Te(e,"rear");return r===n?la(r,t):{front:la(r,t),rear:la(n,t)}}function la(e,t){return pg(e,Math.min(t,$r(e)))}var ol=e=>e==="FL"||e==="RL",EA=new WeakMap;function AO(e,t){let r=EA.get(e);r||EA.set(e,r=new Map);let n=100*Math.ceil(2*t*De/100),o=r.get(n);if(!o){let a=Qs(e,n);o="front"in a?a:{front:a,rear:a},r.set(n,o)}return o}function Zs(e,t,r=0,n,o=0,a=1){let s=t?.axG??0;if(t?.balance)return{axG:Number.isFinite(s)?s:0,fx:{FL:0,FR:0,RL:0,RR:0},balance:t.balance};let i=Number.isFinite(t?.tvRearDiffN)?t?.tvRearDiffN:0;if(!(!!s&&Number.isFinite(s))&&!i)return null;let l=e.massTotal*s*De,u=s>=0?Math.min(1,Math.max(0,t?.driveFrontFrac??0)):Math.min(.99,Math.max(.01,js(e,s,r,n,o,a))),m=l*u/2,p=l*(1-u)/2;return{axG:s,fx:{FL:m,FR:m,RL:p-i/2,RR:p+i/2}}}function C0(e,t,r,n){return Math.abs(ua(e,t,r,n!==void 0?{steerMaxDeg:n}:{}).peak.steerDeg)}function T0(e,t,r,n){let o=e.tv;if(!o?.enabled)return 0;let a=ew(o)(t,Math.abs(r),n);return r<0?-a:a}function P0(e,t,r=0,n,o=0,a=0,s,i=1){let c=Zs(e,{axG:t,driveFrontFrac:a},r,n,o,i),l=c?c.fx:{FL:0,FR:0,RL:0,RR:0};return c&&s&&n?Ad(e,n,l,s):l}var sl=e=>ol(e)?-1:1,Fd=(e,t,r,n,o)=>t*e.Fy(t*r,n,t*o);function w0(e){let t=e.wheelbase/1e3,r=t*(1-e.frontMassFrac),n=t*e.frontMassFrac;return{wb:t,lf:r,lr:n,m:e.massTotal}}function wO(e,t,r){let n=Math.abs(t),o=e.steerFront;if(o&&o.meanDeg.length>1){let u=t>=0,m=r&&o.travelSurface?Ps(o,n/he,u?r.FL:r.FR,u?r.FR:r.FL):Ls(o,n/he);return{innerMag:m.innerDeg*he,outerMag:m.outerDeg*he,innerCamber:m.innerCamber,outerCamber:m.outerCamber,atLock:m.atLock}}let a=e.trackFront/1e3,s=e.wheelbase/1e3,i=(e.ackermannPct??0)/100,c=n,l=n;if(n>1e-4){let u=s/Math.tan(n),m=Math.atan(s/Math.max(.05,u-a/2)),p=Math.atan(s/(u+a/2));c=n+i*(m-n),l=n+i*(p-n)}return{innerMag:c,outerMag:l,innerCamber:0,outerCamber:0,atLock:!1}}function ma(e,t,r){let n=(e.toeFrontDeg??0)*he,o=(e.toeRearDeg??0)*he,a=wO(e,t,r),s=t>=0?1:-1,i=t>=0,c=s*(i?a.innerMag:a.outerMag),l=s*(i?a.outerMag:a.innerMag);return{steer:{FL:c-n,FR:l+n,RL:-o,RR:o},camber:{FL:i?a.innerCamber:a.outerCamber,FR:i?a.outerCamber:a.innerCamber,RL:0,RR:0},atLock:a.atLock}}function Cd(e,t,r){if(r.Fz<=0)return 0;let n=Yt(Te(e,Wn(t))),o=sl(t),a=Math.abs(r.kappa)<1e-12?n.Mz(o*r.slipRad,r.Fz,o*r.camberRad):n.forces({Fz:r.Fz,kappa:r.kappa,alpha:o*r.slipRad,gamma:o*r.camberRad}).Mz;return o*a}function IA(e,t,r,n){if(!ea(e))return null;let o=Yt(Te(t,"front")),a={};for(let s of["FL","FR"]){let i=n[s];a[s]={Fz:i.Fz,Fx:i.Fx,Fy:i.Fy,Mz:Cd(o,s,i)}}return Ec(e,r/he,a,yo(o.model),{FL:n.FL.travelMm,FR:n.FR.travelMm})}var _A=()=>({totalNm:[],aligningNm:[],lateralNm:[],longitudinalNm:[],jackingNm:[]});function NA(e,t){e.totalNm.push(t.totalNm),e.aligningNm.push(t.aligningNm),e.lateralNm.push(t.lateralNm),e.longitudinalNm.push(t.longitudinalNm),e.jackingNm.push(t.jackingNm)}var FO=Object.freeze({Fx:0,Fy:0,Mz:0});function OA(e,t,r){let n=t==="front"?(r?.FL??0)+(r?.FR??0):(r?.RL??0)+(r?.RR??0),o=pr(e,t,n);return o&&aa(o,n)>0?{F:n,law:o}:null}function fr(e,t,r,n,o,a,s,i,c,l){let u=s?.fx,m=s?.axG??0,{wb:p,lf:d,lr:f,m:h}=w0(e),b=OA(e,"front",u),g=OA(e,"rear",u),y=l?.spool??{front:0,rear:0},x=i!==void 0&&i>0&&Number.isFinite(i)?i:null,R=oe=>x===null?r:Math.sqrt(Math.max(0,oe)*x),v=Yt(Te(t,"front")),S=Yt(Te(t,"rear")),A=on(v),C=on(S),F=e.trackFront/2e3,T=e.trackRear/2e3,M=!!(e.kinFront&&e.kinRear),k=M&&x===null?l?.travel??Ro(e,e.kinFront,e.kinRear,r):null;l&&k&&(l.travel=k);let w=NaN,P=null,L=oe=>{if(!M)return null;if(x===null)return k;let se=R(oe);return se!==w&&(w=se,P=Ro(e,e.kinFront,e.kinRear,se)),P},E={},_=l?.kap??{FL:0,FR:0,RL:0,RR:0},D=e.kinFront?.compliance,I=e.kinRear?.compliance,N=!!(D||I),O=!!(D?.toePerMz||I?.toePerMz),V=oe=>Vt(oe)?D:I,H={FL:{fy:0,fx:0,mz:0},FR:{fy:0,fx:0,mz:0},RL:{fy:0,fx:0,mz:0},RR:{fy:0,fx:0,mz:0}},U=!1,G=s?.balance,B=0,q=0,re=0,W=G?AO(t,h):null,z=(oe,se)=>se>0&&W?W[Wn(oe)].muX(se)*se:0,Y=oe=>{let se=oe/r,xe=x===null?n+d*se/r:n+d/x,fe=x===null?n-f*se/r:n-f/x,Fe=L(oe),Re=R(oe),ae=G!==void 0,Me=ae?oe/De*Math.cos(n)+m*Math.sin(n):oe/De,be=ae?m*Math.cos(n)-oe/De*Math.sin(n):m,ge=Fe?Fe(Me,be,n/he,o/he):null,ye=ge?{FL:ge.FL.travel,FR:ge.FR.travel}:void 0,ce=Am(e,Me,be,Re,n/he,o/he,ye,ge?.steeringJacking),Ae=ce.loads;U=ce.overturned;let Se=ma(e,o,ye),ve=Se.steer,wt=0,qe=Pe=>{let _e=Math.max(0,Ae[Pe]),He=sl(Pe),Ee=Vt(Pe)?v:S,ze=V(Pe),qt=0,Ft=0;if(ze){let qr=H[Pe];qt=ze.toePerFy*qr.fy+ze.toePerFx*qr.fx+ze.toePerMz*qr.mz,Ft=ze.camberPerFy*qr.fy+ze.camberPerFx*qr.fx}let Mt=ve[Pe]+(ge?He*ge[Pe].bumpToe*he:0)+He*qt*he,ar=Mt-(Vt(Pe)?xe:fe),Ct=(ge?ge[Pe].camberRoad:0)*he+He*(Se.camber[Pe]+Ft)*he;return{Fz:_e,mir:He,t:Ee,gains:ze,complianceToe:qt,steerK:Mt,slip:ar,camberRad:Ct}},It=(Pe,_e)=>{let He=x===null?se/r:1/x,Ee=Vt(Pe)?d:-f,ze=(ol(Pe)?1:-1)*(Vt(Pe)?F:T),qt=(Math.cos(n)-ze*He)*Math.cos(_e.steerK)+(Math.sin(n)+Ee*He)*Math.sin(_e.steerK),Ft=Vt(Pe)?A:C;return{at:_e.Fz>0?Mt=>_e.t.forces({Fz:_e.Fz,kappa:Mt,alpha:_e.mir*_e.slip,gamma:_e.mir*_e.camberRad}):()=>FO,fxAt:_e.Fz>0?Mt=>Ft(_e.Fz,Mt,_e.mir*_e.slip,_e.mir*_e.camberRad):()=>0,vx:Math.max(.05,qt),seed:_[Pe]}};if(G){let Pe=h*(m*De-(G.axDrag??0)),_e=0,He=()=>({FL:qe("FL"),FR:qe("FR"),RL:qe("RL"),RR:qe("RR")}),Ee=ar=>({FL:z("FL",ar.FL.Fz),FR:z("FR",ar.FR.Fz),RL:z("RL",ar.RL.Fz),RR:z("RR",ar.RR.Fz)}),ze=N?null:He(),qt=ze?Ee(ze):null,Ft={},Mt={};for(let ar=0;ar<SO;ar++){let Ct=ze??He(),qr=qt??Ee(Ct),lo=Pe-B,$o={...G.spec,turn:o<0?-1:1,...lo<0&&G.brakeFront&&G.spec.brake.kind==="shares"?{brake:{...G.spec.brake,front:G.brakeFront(lo)}}:{}},Qe={},et=v0($o,lo,qr,Qe),kr={},wn={},ls={},uo=(Ve,Be)=>Qe[Ve]!==void 0&&Math.abs(Math.abs(Be)-Qe[Ve])<=1e-9*Math.max(1,Qe[Ve]);for(let Ve=0;Ve<5;Ve++){let Be=!1;for(let Ze of["front","rear"]){let[Ye,lt]=Ze==="front"?["FL","FR"]:["RL","RR"],Ir=et.want[Ye]+et.want[lt],Xu=pr(e,Ze,Ir);if(Xu&&aa(Xu,Ir)>0){let je=Nr=>Math.max(0,Math.abs(Ir-Nr.left.forces.Fx-Nr.right.forces.Fx)-LA(Ir)),$e=ls[Ze],_r=$e!==void 0&&uo(Ye,et.want[Ye])&&uo(lt,et.want[lt]),pt=_r?$e:nl(It(Ye,Ct[Ye]),It(lt,Ct[lt]),Ir,Xu,y[Ze],Md,!0);if(!_r&&je(pt)>0&&(y[Ze]!==0||_[Ye]!==0||_[lt]!==0)){let Nr=nl({...It(Ye,Ct[Ye]),seed:0},{...It(lt,Ct[lt]),seed:0},Ir,Xu,0,Md,!0);je(Nr)<je(pt)&&(pt=Nr)}y[Ze]=pt.spoolKappa,_[Ye]=pt.left.kappa,_[lt]=pt.right.kappa;let us=et.held[Ye]&&et.held[lt],ms=je(pt);if(us&&ms>0){let Nr=Math.abs(Ir),Or=Math.abs(pt.left.forces.Fx+pt.right.forces.Fx),Xi=et.want[Ye]*et.want[lt]>=0&&Nr>0,qi=Xi?Math.abs(et.want[Ye])*Or/Nr:Math.abs(pt.left.forces.Fx),Th=Xi?Math.abs(et.want[lt])*Or/Nr:Math.abs(pt.right.forces.Fx);(Qe[Ye]===void 0||Qe[lt]===void 0||qi<Qe[Ye]-1e-6||Th<Qe[lt]-1e-6)&&(Qe[Ye]=Math.min(qi,Qe[Ye]??1/0),Qe[lt]=Math.min(Th,Qe[lt]??1/0),ls[Ze]=pt,Be=!0)}kr[Ye]={kappa:pt.left.kappa,Fx:pt.left.forces.Fx,Fy:Ct[Ye].mir*pt.left.forces.Fy,short:us?0:ms/2},kr[lt]={kappa:pt.right.kappa,Fx:pt.right.forces.Fx,Fy:Ct[lt].mir*pt.right.forces.Fy,short:us?0:ms/2};continue}for(let je of[Ye,lt]){let $e=Ct[je],_r=et.want[je];if(_r===0||$e.Fz<=0){let Fn=$e.Fz<=0&&!et.held[je]?Math.abs(_r):0;$e.Fz<=0&&et.held[je]&&_r!==0&&Qe[je]===void 0&&(Qe[je]=0,Be=!0);let Ph=ze?Ft[je]??={}:null,Tv=$e.Fz>0?Ph?.fy??Fd($e.t,$e.mir,$e.slip,$e.Fz,$e.camberRad):0;Ph&&(Ph.fy=Tv),kr[je]={kappa:0,Fx:0,Fy:Tv,short:Fn};continue}let pt=Fn=>$e.t.forces({Fz:$e.Fz,kappa:Fn,alpha:$e.mir*$e.slip,gamma:$e.mir*$e.camberRad}),us=Vt(je)?A:C,ms=ze?Ft[je]??={}:null,Nr=Fn=>Fn!==0||!ms?us($e.Fz,Fn,$e.mir*$e.slip,$e.mir*$e.camberRad):ms.fx??=us($e.Fz,0,$e.mir*$e.slip,$e.mir*$e.camberRad),Or=(uo(je,_r)?wn[je]:void 0)??Mo(pt,_r,_[je],Md,Nr,ze?Mt[je]??={}:void 0);_[je]=Or.kappa;let Xi=LA(_r),qi=Math.abs(_r-Or.forces.Fx);if(qi>Xi&&Math.abs(Or.forces.Fx)<Math.abs(_r)&&et.held[je]){let Fn=Math.abs(Or.forces.Fx);(Qe[je]===void 0||Fn<Qe[je])&&(Qe[je]=Fn,wn[je]=Or,Be=!0)}kr[je]={kappa:Or.kappa,Fx:Or.forces.Fx,Fy:$e.mir*Or.forces.Fy,short:et.held[je]?0:Math.max(0,qi-Xi)}}}if(!Be)break;et=v0($o,lo,qr,Qe)}q=0,re=0;for(let Ve=0;Ve<jt.length;Ve++)(Qe[jt[Ve]]!==void 0||et.atTop[jt[Ve]])&&(q|=1<<Ve),Qe[jt[Ve]]!==void 0&&(re|=1<<Ve);let Qr=0,Dr=0;_e=0;for(let Ve of jt){let Be=Ct[Ve],Ze=kr[Ve];if(E[Ve]={Fz:Be.Fz,travelMm:ge?.[Ve].travel??0,steerRad:Be.steerK,slipRad:Be.slip,camberRad:Be.camberRad,Fy:Ze.Fy,Fx:Ze.Fx,kappa:Ze.kappa,fxShort:Ze.short+et.left/4,lifted:ce.lifted[Ve]},Be.gains){let lt=O&&Be.gains.toePerMz?Cd(Be.t,Ve,E[Ve]):0;H[Ve]={fy:-Be.mir*Ze.Fy,fx:Ze.Fx,mz:-Be.mir*lt*1e3};let Ir=H[Ve];Dr=Math.max(Dr,Math.abs(Be.gains.toePerFy*Ir.fy+Be.gains.toePerFx*Ir.fx+Be.gains.toePerMz*Ir.mz-Be.complianceToe))}let Ye=Be.steerK-n;Qr+=Ze.Fx*(Math.cos(Ye)-1)-Ze.Fy*Math.sin(Ye),_e+=Ze.Fy*Math.cos(Ye)+Ze.Fx*Math.sin(Ye)}let Er=Math.abs(Qr-B);if(B=Qr,Er<MO&&Dr<DA)break}return _e/h}for(let Pe=0;Pe<(N?kO:1);Pe++){wt=0;let _e=0,He={};for(let Ee of jt){let ze=Vt(Ee)?b:g;if(ze&&!He[Ee]){let[Dr,Er]=Vt(Ee)?["FL","FR"]:["RL","RR"],Ve=qe(Dr),Be=qe(Er),Ze=Wn(Ee),Ye=nl(It(Dr,Ve),It(Er,Be),ze.F,ze.law,y[Ze],Xs);y[Ze]=Ye.spoolKappa,He[Dr]={w:Ve,share:Ye.left},He[Er]={w:Be,share:Ye.right}}let qt=He[Ee]?.w??qe(Ee),{Fz:Ft,mir:Mt,t:ar,gains:Ct,complianceToe:qr,steerK:lo,slip:$o,camberRad:Qe}=qt,et=u?.[Ee]??0,kr,wn=0,ls=0,uo=0,Qr=He[Ee]?.share;if(Qr)_[Ee]=Qr.kappa,ls=Qr.kappa,wn=Qr.forces.Fx,uo=Qr.short,kr=Mt*Qr.forces.Fy;else if(et===0||Ft<=0)kr=Fd(ar,Mt,$o,Ft,Qe),uo=Ft<=0?Math.abs(et):0;else{let Dr=Ze=>ar.forces({Fz:Ft,kappa:Ze,alpha:Mt*$o,gamma:Mt*Qe}),Er=Vt(Ee)?A:C,Ve=Ze=>Er(Ft,Ze,Mt*$o,Mt*Qe),Be=Mo(Dr,et,_[Ee],Xs,Ve);_[Ee]=Be.kappa,ls=Be.kappa,wn=Be.forces.Fx,uo=Math.max(0,Math.abs(et-wn)-Math.max(Us.abs,Us.rel*Math.abs(et))),kr=Mt*Be.forces.Fy}if(E[Ee]={Fz:Ft,travelMm:ge?.[Ee].travel??0,steerRad:lo,slipRad:$o,camberRad:Qe,Fy:kr,Fx:wn,kappa:ls,fxShort:uo,lifted:ce.lifted[Ee]},Ct){let Dr=O&&Ct.toePerMz?Cd(ar,Ee,E[Ee]):0;H[Ee]={fy:-Mt*kr,fx:wn,mz:-Mt*Dr*1e3};let Er=H[Ee];_e=Math.max(_e,Math.abs(Ct.toePerFy*Er.fy+Ct.toePerFx*Er.fx+Ct.toePerMz*Er.mz-qr))}wt+=kr*Math.cos(lo)+wn*Math.sin(lo)}if(_e<DA)break}return wt/h},te=oe=>{let se=Xe(e,0,m,oe,0,o/he);return se.FL+se.FR+se.RL+se.RR},j=Math.max(20,3.5*te(r)/h);if(x!==null){j=4*De;for(let oe=0;oe<8;oe++){let se=Math.min(40*De,3.5*te(R(j))/h);if(se<=j)break;j=se}j=Math.max(20,j)}let X=oe=>Y(oe)-oe,le=Math.max(.001,j*1e-4),pe=(oe,se,xe,fe)=>{let Fe=oe,Re=xe,ae=se,Me=fe,be=Fe;for(let ge=0;ge<40;ge++){let ye=Me-ae,ce=Math.abs(ye)>1e-12?(Fe*Me-Re*ae)/ye:.5*(Fe+Re),Ae=Math.min(Fe,Re),Se=Math.max(Fe,Re);ce>Ae&&ce<Se||(ce=.5*(Fe+Re));let ve=X(ce);if(be=ce,Math.abs(ve)<1e-4||Se-Ae<1e-6)break;ve<0==ae<0?(Fe=ce,ae=ve,Me*=.5):(Re=ce,Me=ve,ae*=.5)}return be},ue=(oe,se,xe,fe=!1)=>{let Fe=(ge,ye)=>xe>0?ge>0&&ye<0:ye>0&&ge<0,Re=oe,ae=se,Me=oe+xe*Math.min(Math.abs(se),j);if(!fe&&Math.abs(Me-oe)>le){let ge=X(Me);if(Fe(ae,ge))return{root:pe(Re,ae,Me,ge),last:Re};Re=Me,ae=ge}let be=fe?j/24:Math.max(j/24,Math.abs(Me-oe)/4);for(let ge=1;ge<=24;ge++){let ye=Re+xe*be;if(Math.abs(ye)>j)break;let ce=X(ye);if(Fe(ae,ce))return{root:pe(Re,ae,ye,ce),last:Re};if(fe&&ce*xe<0&&(ce-ae)*xe<0)break;Re=ye,ae=ce}return{root:null,last:Re}},ie=c??null;if(c===void 0&&a!==void 0&&Number.isFinite(a)&&Math.abs(a)<=j){let oe=X(a);if(Math.abs(oe)<=1e-4)X(a+le)<0&&X(a-le)>0&&(ie=a);else{let se=ue(a,oe,Math.sign(oe)).root;ie=se!==null&&(se===0||Math.sign(se)===Math.sign(a))?se:null}}let ke=ie===null;if(ie===null){let oe=X(0),se=X(le),xe=Math.abs(oe)<=1e-4,fe=xe?x!==null?1:o!==0?Math.sign(o):se>0?1:-1:Math.sign(oe),Fe=xe?fe*le:0,Re=xe?fe>0?se:X(-le):oe,ae=ue(Fe,Re,fe);ie=ae.root??(xe?0:ae.last)}let Ie=Y(ie);if(ke&&o!==0&&x===null){let oe=Math.sign(o);if(ie*oe<=0||(E.RL.Fy+E.RR.Fy)*oe<0){let se={...E},xe=U,fe=oe*Math.max(ie*oe+le,n*oe*r*r/f),Fe=null;if(fe*oe<j){let Re=X(fe);if(Re*oe>0)Fe=ue(fe,Re,oe).root;else{let ae=fe+oe*j/24,Me=X(ae);(Me-Re)*oe>0&&(Fe=ue(ae,Me,oe,Me*oe<=0).root)}}Fe!==null&&Fe*oe>0?(ie=Fe,Ie=Y(ie)):(Object.assign(E,se),U=xe)}}let Ke=d*(E.FL.Fy*Math.cos(E.FL.steerRad)+E.FR.Fy*Math.cos(E.FR.steerRad))-f*(E.RL.Fy+E.RR.Fy);if(G){Ke=0;for(let oe of jt){let se=E[oe],xe=Vt(oe)?d:-f,fe=(ol(oe)?1:-1)*(Vt(oe)?F:T),Fe=Math.cos(se.steerRad),Re=Math.sin(se.steerRad);Ke+=xe*(se.Fy*Fe+se.Fx*Re)-fe*(se.Fx*Fe-se.Fy*Re)}}else if(s||b||g){let oe=se=>(ol(se)?1:-1)*(Vt(se)?F:T);for(let se of jt){let xe=E[se],fe=Vt(se)?d:-f;Ke+=fe*xe.Fx*Math.sin(xe.steerRad)-oe(se)*xe.Fx*Math.cos(xe.steerRad)}}return l&&(l.held=q,l.ceiling=re),x!==null&&ie<-1e-6?{ay:NaN,cn:NaN,wheels:E,overturned:U,res:NaN}:{ay:ie/De,cn:Ke/(h*De*p),wheels:E,overturned:U,res:Ie-ie}}function CO(e,t,r,n,o,a,s,i=0){let c=20*he,l=.001,u=(h,b)=>{let g=fr(e,t,r,h,n,b,s);return{cn:g.cn-i,ay:g.ay*De}},m=h=>n===0||i!==0||Math.abs(h)<.05||Math.sign(h)===Math.sign(n),p=(h,b,g,y)=>{let x=u(h,y);if(Math.abs(x.cn)<1e-5)return{beta:h,trimmed:!0};let R=y===void 0?void 0:x.ay,v={pos:{b:h,cn:x.cn,ay:R},neg:{b:h,cn:x.cn,ay:R}},S=null,A=h,C=Math.abs(x.cn);for(let F=0;F<b.length&&!S;F++)for(let T of[v.pos,v.neg]){let M=T===v.pos?1:-1,k=h+M*b[F];if(Math.abs(k)>c)continue;let w=u(k,T.ay);if(Math.abs(w.cn)<C&&m(w.ay)&&(C=Math.abs(w.cn),A=k),w.cn===0&&m(w.ay))return{beta:k,trimmed:!0};if(w.cn<0!=T.cn<0){let P={lo:T.b,hi:k,ayLo:T.ay},L=VA(u,P),E=u(L,T.ay);if(Math.abs(E.cn)<l&&m(E.ay))return S=P,{beta:L,trimmed:!0}}T.b=k,T.cn=w.cn,y!==void 0&&(T.ay=w.ay)}return S?{beta:VA(u,S),trimmed:!0}:g?{beta:A,trimmed:!1}:null},d=[.25,.75,2,5].map(h=>h*he);if(o!==void 0&&Number.isFinite(o)&&Math.abs(o)<=c){let h=p(o,d,!1,a);if(h)return h;if(!s&&i===0&&a!==void 0&&Number.isFinite(a)){let b=TO(e,t,r,n,o,a,c);if(b&&m(b.ay))return{beta:b.beta,trimmed:!0,ay:b.ay}}}let f=[1,3,7,15,20].map(h=>h*he).filter(h=>h<=c);return p(0,f,!0)??{beta:0,trimmed:!1}}function VA(e,t){let{lo:r,hi:n}=t,o=t.ayLo,a=e(r,o).cn,s=e(n,o).cn,i=r;for(let c=0;c<40;c++){let l=s-a,u=Math.abs(l)>1e-12?(r*s-n*a)/l:.5*(r+n);u>Math.min(r,n)&&u<Math.max(r,n)||(u=.5*(r+n));let m=e(u,o),p=m.cn;if(o!==void 0&&(o=m.ay),i=u,Math.abs(p)<1e-5||Math.abs(n-r)<1e-5)break;p<0==a<0?(r=u,a=p,s*=.5):(n=u,s=p,a*=.5)}return i}function TO(e,t,r,n,o,a,s){let i=(p,d)=>{let f=fr(e,t,r,p,n,void 0,null,void 0,d);return{r:f.res,c:f.cn}},c=o,l=a,u=i(c,l),m=0;for(let p=0;p<PO;p++){let d=i(c+k0,l),f=i(c,l+M0),h=(d.r-u.r)/k0,b=(f.r-u.r)/M0,g=(d.c-u.c)/k0,y=(f.c-u.c)/M0,x=h*y-b*g;if(!Number.isFinite(x)||x===0||Math.abs(x)<IO*(Math.abs(h*y)+Math.abs(b*g)))return null;if(p===0)m=Math.sign(x);else if(Math.sign(x)!==m)return null;if(Math.abs(u.r)<=1e-4&&Math.abs(u.c)<=1e-5)return{beta:c,ay:l};let R=(u.c*b-u.r*y)/x,v=(u.r*g-u.c*h)/x,S=Math.min(1,LO/Math.max(Math.abs(R),1e-300),DO/Math.max(Math.abs(v),1e-300));if(c+=S*R,l+=S*v,Math.abs(c-o)>EO||Math.abs(c)>s||l*a<0)return null;u=i(c,l)}return null}var PO=8,k0=1e-5,M0=.001,LO=1*he,DO=2,EO=5*he,IO=.5;function YA(e,t,r,n,o,a,s,i){let c=fr(e,t,r,n,o,a,s,void 0,i),l=c.ay*De/r,u={},m=0;for(let f of jt){let h=c.wheels[f],b=Te(t,Wn(f)),g=$r(b),y=b.muY(Math.min(h.Fz,g)),x=b.muX(Math.min(h.Fz,g));m+=h.fxShort,u[f]={Fz:h.Fz,steerDeg:h.steerRad/he,slipDeg:h.slipRad/he,camberDeg:h.camberRad/he,Fy:h.Fy,Fx:h.Fx,Mz:Cd(b,f,h),gripUtil:y*h.Fz>0?Math.hypot(h.Fy/(y*h.Fz),x*h.Fz>0?h.Fx/(x*h.Fz):0):0,...h.Fz>g?{pastTurnover:!0}:{},lifted:h.lifted}}let p=Ec(e,o/he,u,yo(Te(t,"front").model),{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}),d=ma(e,o,e.kinFront&&e.kinRear?{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}:void 0);return{wheels:u,ay:c.ay,ax:s?.axG??0,beta:n/he,yawRate:l*180/Math.PI,steerDeg:o/he,...d.atLock?{lockDeg:(d.steer.FL+d.steer.FR)/2/he}:{},converged:!0,trimmed:!c.overturned,overturned:c.overturned,driving:!1,fxShortfall:m,...p?{steering:p}:{}}}function jn(e,t,r,n,o,a,s=0){let i=Math.max(8,r),c=ca(e,t,i,n,o,a,s);return n!==0&&o?.driving===void 0&&(c.driving=XO(e,t,i,c,a,s)),c}function ca(e,t,r,n,o,a,s){let i=n*he,c=Zs(e,a,r,t),l=o&&Number.isFinite(o.ay)?o.ay*De:void 0,u=o&&Number.isFinite(o.beta)?o.beta*he:void 0,{beta:m,trimmed:p,ay:d}=CO(e,t,r,i,u,l,c,s),f=YA(e,t,r,m,i,l,c,d),h={...f,trimmed:p&&!f.overturned};return h.driving=n===0?h.trimmed:o?.driving!==void 0&&o.driving&&h.trimmed&&Math.abs(h.beta-o.beta)<=_O,h}var _O=3;function ua(e,t,r,n={}){let o=Math.max(8,r),a=n.direction??1,s=n.yawDemandCn??0,i=n.steerMaxDeg??NO,c=typeof n.op=="function"?n.op:()=>n.op,l=typeof n.op=="function"||n.op?.balance?null:`${o}|${a}|${s}|${i}|${n.op?`${n.op.axG}|${n.op.driveFrontFrac??""}|${n.op.tvRearDiffN??""}`:""}`;if(l!==null){let S=S0.get(e)?.get(t)?.get(l);if(S)return S}let u=(S,A)=>A.trimmed&&Math.abs(A.beta-S.beta)<=Td&&Math.abs(A.ay-S.ay)*De<=Pd,m=!1,p=(S,A)=>{let C=ca(e,t,o,a*S,A,c(a*S),s);return u(A,C)?(C.driving=!0,C):(m=C.overturned,null)},d=[ca(e,t,o,0,void 0,c(0),s)],f=null,h=!1,b,g=S=>{let A=d.length-1;for(;A>1&&S.sb*(d[A].beta-d[A-1].beta)>=0;)A--;let C=a*(S.state.ay-d[A].ay)>0,F=T=>S.sb*(T.beta-S.state.beta)>0||a*T.steerDeg>=a*S.state.steerDeg||C&&a*T.ay>=a*S.state.ay;for(;d.length>Math.max(2,A)&&F(d[d.length-1]);)d.pop();b={state:S.state,stall:d[d.length-1]},d.push(S.state),f=Math.abs(S.state.steerDeg)},y=(S,A=!1)=>A||WO(d[d.length-1],S)?jO(e,t,o,a,d,S,c,s):null,x=d[0].trimmed?d[0]:null;if(!x){let S=0;for(let A=BA;A<=i&&!x;A+=BA){let C=ca(e,t,o,a*A,void 0,c(a*A),s);if(C.trimmed){let F=A;x=C;for(let T=0;T<6;T++){let M=.5*(S+F),k=ca(e,t,o,a*M,void 0,c(a*M),s);k.trimmed?(F=M,x=k):S=M}}else S=A}x&&(x.driving=!0,d.push(x))}if(x){let S=Math.abs(x.steerDeg),A=Math.min(A0,100/(o*o)),C=x;for(;S<i;){let F=Math.min(i,S+A),T=p(F,C);if(T){let L=y(T);if(L){g(L);break}if(d.push(T),F>=i||JA(e,a*F))break;Math.abs(T.beta-C.beta)<.5*Td&&Math.abs(T.ay-C.ay)*De<.5*Pd&&(A=Math.min(A0,1.5*A)),S=F,C=T;continue}if(A>OO){A*=.5;continue}let M=m,k=!1,w=null;for(let L of VO){let E=Math.min(i,S+L);if(E<=S)continue;let _=p(E,C);if(_){if(w=y(_,!0),w)break;d.push(_),S=E,C=_,A=Math.min(A0,100/(o*o)),k=!0;break}}if(k)continue;if(w){g(w);break}f=S,h=M;let P=M?null:YO(e,t,o,a,d,c,s);P&&g(P);break}}else f=0;let R=d[0];for(let S of d)a*S.ay>a*R.ay&&(R=S);let v={states:d,foldDeg:f,rollover:h,peak:R,...b?{fold:b}:{}};if(l!==null){let S=S0.get(e);S||(S=new WeakMap,S0.set(e,S));let A=S.get(t);A||(A=new Map,S.set(t,A)),A.size>256&&A.clear(),A.set(l,v)}return v}var S0=new WeakMap,NO=90,Td=1.5,Pd=2.5,A0=5,OO=.002,VO=[.5,1],BA=2.5,WA=.01,Yn=.001,BO=.05,$O=.25,GO=5,KO=2,$A=1e-8,HO=1e-7,zO=1e-6;function jA(e,t,r,n,o,a,s){let i=n*he,c=o.ay*De,l=b=>{let g=fr(e,t,r,i,b*he,c,Zs(e,a(b),r,t));return{g:g.cn-s,ay:g.ay}},u=o.steerDeg,m=l(u),p=u+(u<0?-.001:.001),d=l(p),f=()=>d.g===0||Math.abs(p-u)<$A;for(let b=0;b<40&&Math.sign(m.g)===Math.sign(d.g)&&!f();b++){let g=(d.g-m.g)/(p-u),y=g!==0?p-d.g/g:p+2*(p-u);if(!Number.isFinite(y))return null;let x=2*Math.abs(p-u)+.001;if(y=p+Math.max(-x,Math.min(x,y-p)),u=p,m=d,p=y,d=l(p),Math.abs(p-o.steerDeg)>KO)return null}let h={x:p,ay:d.ay};if(Math.sign(m.g)!==Math.sign(d.g)){let b=u,g=m.g,y=p,x=d.g;for(let R=0;R<60&&x!==0&&Math.abs(y-b)>$A;R++){let v=(b*x-y*g)/(x-g),S=l(v);if(h={x:v,ay:S.ay},S.g===0)break;Math.sign(S.g)===Math.sign(g)?(b=v,g=S.g,x*=.5):(y=v,x=S.g,g*=.5)}}else if(!f())return null;return Math.abs(h.ay-o.ay)*De>Pd?null:{steerDeg:h.x,ay:h.ay}}function al(e,t,r,n,o){let a=YA(e,t,r,n.beta*he,n.steerDeg*he,n.ay*De,Zs(e,o(n.steerDeg),r,t));return{...a,trimmed:!a.overturned,driving:!a.overturned}}function YO(e,t,r,n,o,a,s){let i=o.length;if(i<3)return null;let c=o[i-1],l=i-2;for(;l>1&&o[l].beta===c.beta;)l--;let u=o[l],m=Math.sign(c.beta-u.beta);if(m===0||!u.driving)return null;let p=UA(e,t,r,a,s),d=p(u.beta,u),f=p(c.beta,c);if(!d||!f)return null;let h=n*f.steerDeg>=n*d.steerDeg,b=h?d:f,g=h?f:d,y=h?m:-m,x=null;for(let S=WA;Math.abs(g.beta-c.beta)<=Td;S*=1.5){let A=p(g.beta+y*S);if(!A)return null;if(n*A.steerDeg<=n*g.steerDeg){x=A;break}b=g,g=A}if(!x)return null;let R=XA(p,n,b,g,x);if(!R)return null;let v=al(e,t,r,R,a);return!v.trimmed||Math.abs(v.beta-c.beta)>Td||Math.abs(v.ay-c.ay)*De>Pd?null:{state:v,sb:m}}function UA(e,t,r,n,o){let a=[];return(s,i)=>{if(!i){i=a[0];for(let u of a)Math.abs(u.beta-s)<Math.abs(i.beta-s)&&(i=u)}let c=jA(e,t,r,s,i,n,o);if(!c)return null;let l={beta:s,...c};return a.push(l),l}}function WO(e,t){let r=Math.abs(t.beta-e.beta);return r>$O&&r>GO*Math.abs(t.steerDeg-e.steerDeg)}function jO(e,t,r,n,o,a,s,i){let c=o.length;if(c<2)return null;let l=o[c-1],u=c-2;for(;u>0&&o[u].beta===l.beta;)u--;let m=o[u],p=Math.sign(a.beta-l.beta);if(p===0||Math.sign(l.beta-m.beta)!==p||!m.driving)return null;let d=UA(e,t,r,s,i),f=d(m.beta,m),h=d(l.beta,l);if(!f||!h||n*h.steerDeg<n*f.steerDeg)return null;let b=f,g=h,y=null;for(let x=WA;p*(a.beta-g.beta)>0;x=Math.min(BO,1.5*x)){let R=d(p*(a.beta-g.beta)>x?g.beta+p*x:a.beta);if(!R)return null;let v=n*R.steerDeg<=n*g.steerDeg;if(!y)v&&(y=[b,g,R]);else if(!v){let S=XA(d,n,...y);if(!S)return null;let A=al(e,t,r,S,s);return A.trimmed?{state:A,sb:p}:null}b=g,g=R}return null}function XA(e,t,r,n,o){let a=d=>-t*d.steerDeg,s=Math.min(r.beta,o.beta),i=Math.max(r.beta,o.beta),c=n,l=a(r)<=a(o)?r:o,u=l===r?o:r,m=i-s,p=0;for(let d=0;d<100;d++){let f=.5*(s+i);if(Math.abs(c.beta-f)<=2*Yn-.5*(i-s))break;let h=!0;if(Math.abs(m)>Yn){let g=(c.beta-l.beta)*(a(c)-a(u)),y=(c.beta-u.beta)*(a(c)-a(l)),x=(c.beta-u.beta)*y-(c.beta-l.beta)*g;y=2*(y-g),y>0&&(x=-x),y=Math.abs(y);let R=m;if(m=p,Math.abs(x)<Math.abs(.5*y*R)&&x>y*(s-c.beta)&&x<y*(i-c.beta)){p=x/y;let v=c.beta+p;(v-s<2*Yn||i-v<2*Yn)&&(p=f>=c.beta?Yn:-Yn),h=!1}}h&&(m=c.beta>=f?s-c.beta:i-c.beta,p=QA*m);let b=e(Math.abs(p)>=Yn?c.beta+p:c.beta+(p>=0?Yn:-Yn));if(!b)return null;a(b)<=a(c)?(b.beta>=c.beta?s=c.beta:i=c.beta,u=l,l=c,c=b):(b.beta<c.beta?s=b.beta:i=b.beta,a(b)<=a(l)||l===c?(u=l,l=b):(a(b)<=a(u)||u===c||u===l)&&(u=b))}return c}function L0(e,t,r,n,o,a,s=[n.stall]){let i=typeof o.op=="function"?o.op:()=>o.op,c=o.yawDemandCn??0,l="steerDeg"in a?b=>Math.abs(b.steerDeg)-Math.abs(a.steerDeg):b=>Math.abs(b.ay)-Math.abs(a.ayG),u=[...s,n.state].map(b=>({beta:b.beta,steerDeg:b.steerDeg,ay:b.ay})),m=u[0],p=u[u.length-1],d=l(m),f=l(p);if(d>0||f<0)return null;if(f===0)return al(e,t,r,p,i);let h=m;for(let b=0;b<60&&Math.abs(p.beta-m.beta)>1e-9;b++){let g=(m.beta*f-p.beta*d)/(f-d),y=u[0];for(let S of u)Math.abs(S.beta-g)<Math.abs(y.beta-g)&&(y=S);let x=jA(e,t,r,g,y,i,c);if(!x)return null;let R={beta:g,...x};u.push(R),h=R;let v=l(R);if(Math.abs(v)<("steerDeg"in a?HO:zO))break;v<0?(m=R,d=v,f*=.5):(p=R,f=v,d*=.5)}return al(e,t,r,h,i)}function UO(e,t,r,n,o,a){let s=Math.abs(o),{states:i}=n;if(s>Math.abs(i[i.length-1].steerDeg)+1e-9)return null;let c=0;for(;c<i.length-1&&Math.abs(i[c+1].steerDeg)<=s;)c++;let l=i[c];if(Math.abs(Math.abs(l.steerDeg)-s)<1e-9)return l;if(n.fold&&l===n.fold.stall)return L0(e,t,r,n.fold,a,{steerDeg:o});let u=typeof a.op=="function"?a.op(o):a.op,m=ca(e,t,r,o,l,u,a.yawDemandCn??0);return m.driving?m:null}function XO(e,t,r,n,o,a){if(!n.trimmed)return!1;let s=n.steerDeg<0?-1:1,{states:i}=ua(e,t,r,{direction:s,op:o,yawDemandCn:a}),c=Math.abs(n.steerDeg);if(c>Math.abs(i[i.length-1].steerDeg)+1e-9)return!1;let l=0;for(;l<i.length-2&&Math.abs(i[l+1].steerDeg)<c;)l++;let u=i[l],m=i[Math.min(l+1,i.length-1)],p=Math.abs(m.steerDeg)-Math.abs(u.steerDeg),d=p>0?Math.min(1,Math.max(0,(c-Math.abs(u.steerDeg))/p)):0,f=u.beta+d*(m.beta-u.beta),h=u.ay+d*(m.ay-u.ay);return Math.abs(n.beta-f)<=1&&Math.abs(n.ay-h)<=.05}function So(e,t,r,n,o){let a=Math.max(8,r),s=n>=0?1:-1,i=Math.abs(n),c=(b,g)=>jn(e,t,a,s*b,g,o),l=ua(e,t,a,{direction:s,op:o}),{fold:u}=l;if(u&&Math.abs(u.state.steerDeg)<=qs){if(i>Math.abs(u.state.ay))return KA(e,t,a,s,i,o);if(i>Math.abs(u.stall.ay)){let b=L0(e,t,a,u,{direction:s,op:o},{ayG:i});if(b)return b}}let m=l.states.filter(b=>Math.abs(b.steerDeg)<=qs),p=m[m.length-1],d=l.states.length>m.length;d&&Math.abs(p.steerDeg)<qs&&m.push(c(qs,p));let f=m.findIndex(b=>Math.abs(b.ay)>=i);if(f===0)return jn(e,t,a,0,void 0,o);if(f>0)return GA(m[f-1],m[f],i,c);let h=qA(m,c,void 0,d||l.foldDeg===null);return h.ay>=i?GA(h.below,h.state,i,c):l.foldDeg!==null&&l.foldDeg<qs?KA(e,t,a,s,i,o):h.state}var qs=20;function GA(e,t,r,n){let o={steer:Math.abs(e.steerDeg),f:Math.abs(e.ay)-r},a={steer:Math.abs(t.steerDeg),f:Math.abs(t.ay)-r},s=a.f===o.f?.5:-o.f/(a.f-o.f),i={ay:e.ay+s*(t.ay-e.ay),beta:e.beta+s*(t.beta-e.beta),driving:e.driving},c=0,l=null,u=1/0;for(let m=0;m<60;m++){let p=a.f===o.f?.5*(o.steer+a.steer):o.steer-o.f*(a.steer-o.steer)/(a.f-o.f),d=n(p,i),f=Math.abs(d.ay)-r;if(Math.abs(f)<u&&(l=d,u=Math.abs(f)),Math.abs(f)<=qO||a.steer-o.steer<=QO)break;f<0?(o={steer:p,f},c===-1&&(a.f*=.5),c=-1):(a={steer:p,f},c===1&&(o.f*=.5),c=1)}return l}var qO=1e-9,QO=1e-7;function qA(e,t,r,n=!1){let o=r??0;if(r===void 0)for(let S=1;S<e.length;S++)Math.abs(e[S].ay)>Math.abs(e[o].ay)&&(o=S);let a=e[Math.max(0,o-1)],s=Math.abs(e[o].steerDeg),i=ZO/4,c,l,u,m,p,d,f,h,b=null,g;if(o>0&&o<e.length-1){let S=e[o+1];g=F=>{if(F<s)return t(F,a);let T=t(F,e[o]);return T.ay===e[o].ay?t(F,a):T},c=Math.abs(a.steerDeg),l=Math.abs(S.steerDeg),u=s,m=-Math.abs(e[o].ay);let[A,C]=Math.abs(a.ay)>=Math.abs(S.ay)?[a,S]:[S,a];p=Math.abs(A.steerDeg),d=-Math.abs(A.ay),f=Math.abs(C.steerDeg),h=-Math.abs(C.ay)}else{let S=Math.abs(e[o].lockDeg??e[o].steerDeg),A=S-JO,C=o>0&&n&&A>Math.abs(a.steerDeg)?t(A,a):null;if(!C||Math.abs(C.ay)<=Math.abs(e[o].ay)){let F=t(s,a);return{state:F,below:a,ay:Math.abs(F.ay)}}g=F=>t(F,a),c=Math.abs(a.steerDeg),l=S,u=A,m=-Math.abs(C.ay),b=C,p=S,d=-Math.abs(e[o].ay),f=c,h=-Math.abs(a.ay)}let y=l-c,x=0;for(let S=0;S<100;S++){let A=.5*(c+l);if(Math.abs(u-A)<=2*i-.5*(l-c))break;let C=!0;if(Math.abs(y)>i){let k=(u-p)*(m-h),w=(u-f)*(m-d),P=(u-f)*w-(u-p)*k;w=2*(w-k),w>0&&(P=-P),w=Math.abs(w);let L=y;if(y=x,Math.abs(P)<Math.abs(.5*w*L)&&P>w*(c-u)&&P<w*(l-u)){x=P/w;let E=u+x;(E-c<2*i||l-E<2*i)&&(x=A>=u?i:-i),C=!1}}C&&(y=u>=A?c-u:l-u,x=QA*y);let F=Math.abs(x)>=i?u+x:u+(x>=0?i:-i),T=g(F),M=-Math.abs(T.ay);M<=m?(F>=u?c=u:l=u,f=p,h=d,p=u,d=m,u=F,m=M,b=T):(F<u?c=F:l=F,M<=d||p===u?(f=p,h=d,p=F,d=M):(M<=h||f===u||f===p)&&(f=F,h=M))}let R=b??t(s,a),v=Math.abs(R.steerDeg)>s?e[o]:a;return{state:R,below:v,ay:Math.abs(R.ay)}}var ZO=.001,JO=.01,QA=(3-Math.sqrt(5))/2;function KA(e,t,r,n,o,a){let s=l=>Math.abs(jn(e,t,r,n*l,void 0,a).ay),i=0,c=qs;if(s(c)<o)return jn(e,t,r,n*c,void 0,a);for(let l=0;l<28;l++){let u=.5*(i+c);s(u)<o?i=u:c=u}return jn(e,t,r,n*.5*(i+c),void 0,a)}function D0(e,t,r,n,o){let a=So(e,t,r,n,o);return a.steering?Math.abs(a.steering.totalNm):NaN}function E0(e,t,r,n,o){if(!ea(e))return NaN;let a=n<0?-1:1,s=Math.abs(n),i=So(e,t,r,a*s,o);if(!i.steering)return NaN;let c=Math.abs(i.steerDeg);for(let l of[.05,.1,.2,.4]){let u=Math.max(0,c-l),m=c+l,p=jn(e,t,r,a*u,void 0,o),d=jn(e,t,r,a*m,void 0,o),f=p.steering?Math.abs(p.steering.totalNm):NaN,h=d.steering?Math.abs(d.steering.totalNm):NaN,b=Math.abs(d.ay)-Math.abs(p.ay);if(Number.isFinite(f)&&Number.isFinite(h)&&b>=.01||l===.4&&Number.isFinite(f)&&Number.isFinite(h)&&b>.001)return(h-f)/b}return NaN}function F0(e,t,r,n,o,a,s){let i=Math.max(8,r),c=s!==void 0&&Number.isFinite(s)?s*De:void 0,l=fr(e,t,i,n*he,o*he,c,Zs(e,a,i,t)),u=0;for(let m of jt)u+=l.wheels[m].fxShort;return{ay:l.ay,cn:l.cn,fxShortfall:u}}function I0(e,t,r,n,o){let a=Math.max(8,r),s=So(e,t,a,n,o),i=.5,c=F0(e,t,a,s.beta+i,s.steerDeg,o).cn,l=F0(e,t,a,s.beta-i,s.steerDeg,o).cn;return(c-l)/(2*i*he)*e.massTotal*De*(e.wheelbase/1e3)}function _0(e,t,r,n){let o=Math.max(8,r),{branch:a,opts:s}=eV(e,t,o,n);return ZA(e,t,o,a,s)}function eV(e,t,r,n){if(!e.tv?.enabled||n?.balance){let s=n?{op:n}:{};return{branch:ua(e,t,r,s),opts:s}}let o=C0(e,t,r),a={op:s=>{let i=T0(e,r,s,o);return i===0?n:{axG:n?.axG??0,driveFrontFrac:n?.driveFrontFrac,tvRearDiffN:i}}};return{branch:ua(e,t,r,a),opts:a}}function ZA(e,t,r,n,o){let a=typeof o.op=="function"?o.op:()=>o.op,s=o.yawDemandCn??0;if(n.fold&&n.peak===n.fold.state)return al(e,t,r,n.peak,a);let i=(l,u)=>ca(e,t,r,l,u,a(l),s),c=n.states[0].driving||!n.peak.driving?n.states:n.states.slice(1);return qA(c,i,c.indexOf(n.peak),n.foldDeg===null).state}function N0(e,t,r,n={}){let o=n.radius!==void 0&&n.radius>0&&Number.isFinite(n.radius)?n.radius:void 0,a=o===void 0?Math.max(8,r):Math.max(8,Math.sqrt(De*o)),s=(n.betaMaxDeg??10)*he,i=(n.deltaMaxDeg??10)*he,[c,l]=n.betaRangeDeg?[n.betaRangeDeg[0]*he,n.betaRangeDeg[1]*he]:[-s,s],[u,m]=n.deltaRangeDeg?[n.deltaRangeDeg[0]*he,n.deltaRangeDeg[1]*he]:[-i,i],{lf:p,lr:d}=w0(e),f=o===void 0?0:d/o,h=o===void 0?0:(p+d)/o,b=n.nLines??9,g=n.nPts??21,y=n.steering!==!1&&ea(e),x=y?yo(Te(t,"front").model):void 0,R=(O,V,H,U)=>H===1?O:O+(V-O)*U/(H-1),v=e.tv?.enabled?C0(e,t,a):0,S=O=>{let V=T0(e,a,O/he,v);return!n.axG&&V===0?null:Zs(e,{axG:n.axG??0,driveFrontFrac:n.driveFrontFrac,tvRearDiffN:V},a,t)},{lf:A,lr:C}=w0(e),F=n.reserves?Qs(t,e.massTotal*De*1.2):null,T=O=>F?_n(F,{FL:O.FL,FR:O.FR,RL:O.RL,RR:O.RR},{lf:A,lr:C}):null,M=[],k={ay:[],cn:[]},w=0;for(let O=0;O<b;O++){let V=R(u,m,b,O),H=S(V),U=[],G=[],B=[],q=[],re=F?{stabil:[],agil:[]}:void 0,W=y?_A():void 0,z;for(let j=0;j<g;j++){let X=R(c,l,g,j),le=fr(e,t,a,X,V,z,H,o);if(z=Number.isFinite(le.ay)?le.ay*De:void 0,U.push(le.ay),G.push(le.cn),B.push(X/he),q.push(V/he),re){let pe=T(le.wheels);re.stabil.push(pe.stabil),re.agil.push(pe.agil)}W&&NA(W,IA(e,t,V,le.wheels)),Math.abs(le.ay)>w&&(w=Math.abs(le.ay))}M.push({label:`\u03B4 ${(V/he).toFixed(0)}\xB0`,ay:U,cn:G,betaDeg:B,deltaDeg:q,reserve:re,steering:W});let Y=null,te=1/0;for(let j=1;j<G.length;j++){if(!Number.isFinite(G[j-1])||!Number.isFinite(G[j])||G[j-1]!==0&&G[j-1]<0==G[j]<0)continue;let X=G[j-1]===G[j]?0:G[j-1]/(G[j-1]-G[j]),le=U[j-1]+X*(U[j]-U[j-1]);if(o===void 0&&V!==0&&Math.abs(le)>=.05&&Math.sign(le)!==Math.sign(V))continue;let pe=Math.abs(B[j-1]+X*(B[j]-B[j-1])-f/he);pe<te&&(te=pe,Y=le)}Y!==null&&(k.ay.push(Y),k.cn.push(0))}let P=[];for(let O=0;O<b;O++){let V=R(c,l,b,O),H=[],U=[],G=[],B=[],q=F?{stabil:[],agil:[]}:void 0,re=y?_A():void 0,W;for(let z=0;z<g;z++){let Y=R(u,m,g,z),te=fr(e,t,a,V,Y,W,S(Y),o);if(W=Number.isFinite(te.ay)?te.ay*De:void 0,H.push(te.ay),U.push(te.cn),G.push(V/he),B.push(Y/he),q){let j=T(te.wheels);q.stabil.push(j.stabil),q.agil.push(j.agil)}re&&NA(re,IA(e,t,Y,te.wheels))}P.push({label:`\u03B2 ${(V/he).toFixed(0)}\xB0`,ay:H,cn:U,betaDeg:G,deltaDeg:B,reserve:q,steering:re})}let L=.5*he,E=S(h),_,D;if(o===void 0)_=(fr(e,t,a,f+L,h,void 0,E,o).cn-fr(e,t,a,f-L,h,void 0,E,o).cn)/(2*L),D=(fr(e,t,a,f,h+L,void 0,S(h+L),o).cn-fr(e,t,a,f,h-L,void 0,S(h-L),o).cn)/(2*L);else{let O=(U,G)=>fr(e,t,a,U,G,void 0,S(G),o).cn,V=(U,G,B)=>Number.isFinite(U)?(-3*U+4*G-B)/(2*L):(B-G)/L,H=O(f,h);_=-V(H,O(f-L,h),O(f-2*L,h)),D=V(H,O(f,h+L),O(f,h+2*L))}let I=0;if(E&&E.axG){let O=fr(e,t,a,f,h,void 0,E,o),V=0;for(let H of jt)V+=O.wheels[H].fxShort;I=V/Math.abs(e.massTotal*E.axG*De)}let N=k.ay.reduce((O,V)=>Math.max(O,Math.abs(V)),0);return{isoBeta:P,isoDelta:M,trim:k,maxAy:w,stability:_,control:D,speed:o===void 0?a:Math.sqrt(N*De*o),...o!==void 0?{radius:o}:{},axG:E?.axG??0,axShortfall:I,...x?{steeringAligningSource:x}:{}}}function JA(e,t){return ma(e,t*he).atLock}function tV(e,t,r,n,o=zn(e,t,r)){let a=r,s=e.massTotal,i=jt.filter(g=>Vt(g)?n.drivenFront:n.drivenRear),c=o.peakAt,l={front:n.drivenFront?pr(e,"front",1):void 0,rear:n.drivenRear?pr(e,"rear",1):void 0},u=new Map,m=(g,y)=>{let x=`${g}:${y}`,R=u.get(x);if(R===void 0){let v=Math.max(1,y*tl);R=lr(Te(t,g),v,0,!1,c(g,v)),u.set(x,R)}return R},p=(g,y)=>y>0?el(y,x=>m(g,x)):0,d=(g,y,x,R)=>{let v=Te(t,g),S=E=>{let _=Math.max(0,x[E]),D=c(g,_);return{Fz:_,a:p(g,_),b:D.fyPeak,slide:0,cap:I=>_>0?lr(v,_,I,!1,D):0}},[A,C]=g==="front"?["FL","FR"]:["RL","RR"],F=S(A),T=S(C),M=R[A]*F.b,k=R[C]*T.b,w=F.cap(M)+T.cap(k),P=Jc(F,T,M+k,y,w);return{l:A,r:C,full:P,asHeld:()=>({axle:g,strong:F.cap(M)>=T.cap(k)?A:C,full:P,open:Jc(F,T,M+k,Ws,w),sense:1})}},f=g=>({muX:y=>y>0?p(g,y)/y:0,muY:y=>y>0?c(g,y).fyPeak/y:0}),h={front:f("front"),rear:f("rear")},b=g=>({arms:{lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},halfTrack:{front:e.trackFront/2e3,rear:e.trackRear/2e3},ayDir:Math.sign(g)});return{limitAt:(g,y,x,R=0)=>{let v={FL:0,FR:0,RL:0,RR:0},S=Xe(e,g,0,a,0,y),A,C=I=>(A?.ax!==I&&(A={ax:I,loads:Xe(e,g,(I+R)/De,a,0,y)}),A.loads),F=Cm(I=>Is(x,C(I),S,c).short,-R,1),T=x,M={FL:0,FR:0,RL:0,RR:0},k,w=I=>{let N=F.at(I);v=C(N),T=Is(x,v,S,c).util;let O={FL:0,FR:0,RL:0,RR:0};M=O;let V=0,H=n.diffYaw?{fx:{FL:0,FR:0,RL:0,RR:0},axles:[]}:null;for(let U of i){let G=l[Wn(U)];if(G){if(ol(U)){let W=d(Wn(U),G,v,T);V+=W.full,O[W.l]=O[W.r]=W.full/2,H&&(H.fx[W.l]=H.fx[W.r]=W.full/2,H.axles.push(W.asHeld()))}continue}let B=Math.max(0,v[U]),q=c(Wn(U),B),re=lr(Te(t,Wn(U)),B,T[U]*q.fyPeak,!1,q);V+=re,O[U]=re,H&&(H.fx[U]=re)}if(H){let U={};for(let G of jt){let B=Math.max(0,v[G]);U[G]={Fz:B,Fy:T[G]*c(Wn(G),B).fyPeak,Fx:H.fx[G]}}for(let G of H.axles){let B=Xm(G,U,h,b(g))-G.full;V+=B;let[q,re]=G.axle==="front"?["FL","FR"]:["RL","RR"];O[q]+=B/2,O[re]+=B/2}}if(k)for(let U of k){let G=0;for(let B of U.wheels)G+=O[B];G>U.cap&&(V-=G-U.cap)}return V/s},P=()=>{let I=hA(w,-R,ko).fx,N=F.edge();return N!==void 0&&I>N&&(I=N,w(I)),{ax:I,loads:v,wheels:M}},L=P(),E=n.motorCaps;if(!E)return L;if(!E.some(I=>I.wheels.reduce((N,O)=>N+L.wheels[O],0)>I.cap))return{...L,held:L.ax};k=E;let D=P();return{...L,held:D.ax,heldWheels:D.wheels}}}}var wd=.05,HA=.001,zA=16,Ld=8;function O0(e,t,r,n){let o=Math.max(Ld,r),a=n.nSteer??7,s=e.tv?.enabled?C0(e,t,o,n.steerMaxDeg):0,i=B=>{let q=T0(e,o,B,s);return q===0?void 0:{axG:0,tvRearDiffN:q}},c=n.yawDemandCn??0,l={op:i,yawDemandCn:c,...n.steerMaxDeg!==void 0?{steerMaxDeg:n.steerMaxDeg}:{}},u=ua(e,t,o,l),m=B=>{let q={},re={};for(let W of jt)q[W]=B.wheels[W].slipDeg*he,re[W]=Math.min(1,B.wheels[W].gripUtil);return{steerDeg:B.steerDeg,ayMs:Math.max(0,B.ay*De),ayG:B.ay,slip:q,util:re,scrub:B.ay>0?rV(B,e.massTotal):0}},p=null,d=B=>{if(p&&B===p.steerDeg)return m(p);let q=UO(e,t,o,u,B,l);if(q)return m(q);let re=u.states[0];for(let W of u.states)W.steerDeg<=B&&(re=W);return m(re)},f=u.peak.driving&&u.peak.ay>0?ZA(e,t,o,u,l):null,h=f?Math.max(0,f.ay*De):0,b=f?[...u.states.filter(B=>B.steerDeg<f.steerDeg),f]:u.states,g=f?b.findIndex(B=>B.ay*De>=.995*h):0,y=b[g].steerDeg,{fold:x}=u;if(f&&x&&u.peak===x.state){let B=.995*h/De,q=u.states.indexOf(x.stall),re=q-1;for(;re>0&&u.states[re].beta===x.stall.beta;)re--;let W=Math.sign(x.stall.beta-u.states[re].beta),z=q;for(;z>0&&u.states[z].ay>=B&&Math.sign(u.states[z].beta-u.states[z-1].beta)!==-W;)z--;u.states[z].ay<B&&(p=L0(e,t,o,x,l,{ayG:B},u.states.slice(z,q+1)))}if(p)y=p.steerDeg;else if(g>0){let B=b[g-1].steerDeg,q=y;for(let re=0;re<8&&q-B>.001;re++){let W=.5*(B+q);d(W).ayMs>=.995*h?q=W:B=W}y=q}let R=[];for(let B=0;B<(h>0?a:1);B++){let q=B/(a-1);R.push(d(y*(q+Math.sin(Math.PI/2*q))/2))}R[0].ayMs=0;let v=[],S=[],A=[],C=[],F=[],T=zn(e,t,o,void 0,n.diffYaw===!0),M=tV(e,t,o,n,T),k=n.axDrag??0,w=B=>{let q=T.limitAt(B.ayMs/De,B.steerDeg,B.util,k+B.scrub);return{axD:q.edge!==void 0&&q.edge>0?q.edge:q.ax,locked:q.axUnlocked-q.ax>wd}},P=B=>{let q=M.limitAt(B.ayMs/De,B.steerDeg,B.util,k+B.scrub);return{axA:q.ax,wA:{wheels:q.wheels,held:q.held??q.ax,...q.heldWheels?{heldWheels:q.heldWheels}:{}}}},L=R.map(B=>({p:B,...P(B),...w(B)})),E=[];for(let B=0;B+1<L.length;B++){let q=L[B],re=L[B+1],W=[];q.locked!==re.locked?W.push({read:w,past:z=>z.locked===re.locked,braking:!0}):(re.axA>q.axA+wd&&W.push({read:P,past:z=>(z.axA??-1/0)>q.axA}),-re.axD>-q.axD+wd&&W.push({read:w,past:z=>-(z.axD??0)>-q.axD}));for(let{read:z,past:Y,braking:te}of W){let j=q.p.steerDeg,X=re.p.steerDeg,le=null,pe=q.axD,ue=re.axD;for(let ie=0;ie<zA&&X-j>HA&&!(te&&Math.abs(ue-pe)<=wd);ie++){let ke=.5*(j+X),Ie=d(ke),Ke=z(Ie);Y(Ke)?(X=ke,le={p:Ie,r:Ke},ue=Ke.axD??ue):(j=ke,pe=Ke.axD??pe)}if(le){let{p:ie,r:ke}=le,Ie=ke.axD!==void 0&&ke.locked!==void 0?{axD:ke.axD,locked:ke.locked}:w(ie),Ke=ke.axA!==void 0&&ke.wA!==void 0?{axA:ke.axA,wA:ke.wA}:P(ie);E.push({p:ie,...Ke,...Ie})}}}L.push(...E),L.sort((B,q)=>B.p.steerDeg-q.p.steerDeg);let _=B=>B.axA+k+B.p.scrub,D=.001*Math.max(1,R[R.length-1].ayMs),I=[];for(let B=0;B+1<L.length;B++){let q=L[B],re=L[B+1];if(!(_(q)>=0&&_(re)<0))continue;let W=q.p.steerDeg,z=re.p.steerDeg,Y=null,te=null;for(let le=0;le<zA&&z-W>HA;le++){let pe=.5*(W+z),ue=d(pe),ie=P(ue);_({p:ue,axA:ie.axA})>=0?(W=pe,Y={p:ue,wA:ie.wA}):(z=pe,te={p:ue,wA:ie.wA})}let j=Y??te,X=j?.p;if(j&&X&&X.ayMs>q.p.ayMs&&X.ayMs<re.p.ayMs){let le=-(k+X.scrub);I.push({p:X,axA:le,wA:{wheels:j.wA.wheels,held:Math.min(j.wA.held,le)},steady:!0,...w(X)})}}L.push(...I),L.sort((B,q)=>B.p.steerDeg-q.p.steerDeg);let N=!1;for(let{p:B,axA:q,wA:re,axD:W,steady:z}of L){let Y=v.length-1,te=Y>=0&&(z||N?!(B.ayMs>v[Y]):B.ayMs-v[Y]<D);N=z===!0&&!te,te?(q>S[Y]&&(A[Y]=re),S[Y]=Math.max(S[Y],q),C[Y]=Math.min(C[Y],W)):(v.push(B.ayMs),S.push(q),A.push(re),C.push(W),F.push(B.scrub))}for(let B=v.length-2;B>=0;B--)S[B+1]>S[B]&&(A[B]=A[B+1]),S[B]=Math.max(S[B],S[B+1]),C[B]=Math.min(C[B],C[B+1]);let O=v[v.length-1],V=e.massTotal,H=A.map(({wheels:B})=>({FL:B.FL/V,FR:B.FR/V,RL:B.RL/V,RR:B.RR/V})),U=B=>B?{FL:B.FL/V,FR:B.FR/V,RL:B.RL/V,RR:B.RR/V}:void 0,G=n.motorCaps?{axAccelHeld:A.map(B=>B.held),axAccelWheelsHeld:A.map(B=>U(B.heldWheels))}:{};return{ayMax:O,ay:v,axAccel:S,axAccelWheels:H,...G,axDecel:C,axScrub:F,rollover:u.rollover,atLock:f!==null&&JA(e,f.steerDeg)}}function rV(e,t){let r=e.beta*he,n=0;for(let o of jt){let a=e.wheels[o],s=a.steerDeg*he-r;n+=a.Fx*(Math.cos(s)-1)-a.Fy*Math.sin(s)}return n/t}var Dee=Math.PI/180,Eee={speeds:Array.from({length:23},(e,t)=>8+t),steerMaxDeg:14,steerSteps:29};function tw(e=150,t=300,r=18,n=25){return(o,a,s)=>{let i=Math.min(1,Math.max(0,(o-r)/(n-r))),c=s>0?Math.min(1,a/s):0;return(e+i*(t-e))*c}}var Js={enabled:!1,kp:3e3,ffLow:150,ffHigh:300,vLow:18,vHigh:25},ew=e=>tw(e.ffLow,e.ffHigh,e.vLow,e.vHigh);var ln={power_limit_kw:{value:0,label:"battery power limit (0 = none)",unit:"kW"},v_limit_endurance:{value:0,label:"endurance speed limit (0 = none)",unit:"km/h"},endurance_reserve:{value:0,label:"endurance energy reserve (0 = flat out)",unit:"%"},grip_scale:{value:1,label:"grip scale (rig \u2192 road)",unit:"-"},stiffness_scale:{value:1,label:"stiffness scale (rig \u2192 road)",unit:"-"},camber_front_deg:{value:0,label:"static camber front (\u2212 top in)",unit:"\xB0"},camber_rear_deg:{value:0,label:"static camber rear (\u2212 top in)",unit:"\xB0"},cg_height:{value:300,label:"CG height",unit:"mm"},tire_vertical_rate:{value:100,label:"tyre vertical rate",unit:"N/mm"},tire_vertical_damping:{value:0,label:"tyre vertical damping",unit:"N\xB7s/mm"},arb_front:{value:20,label:"ARB front (@wheel)",unit:"N/mm"},arb_rear:{value:15,label:"ARB rear (@wheel)",unit:"N/mm"},heave_spring_front:{value:0,label:"Heave spring front (@wheel)",unit:"N/mm"},heave_spring_rear:{value:0,label:"Heave spring rear (@wheel)",unit:"N/mm"},unsprung_mass:{value:8,label:"unsprung mass/corner",unit:"kg"},brake_balance:{value:.6,label:"brake balance (front)",unit:"-"},damper_front:{value:2.5,label:"damper front",unit:"N\xB7s/mm"},damper_rear:{value:2.5,label:"damper rear",unit:"N\xB7s/mm"},cop_long:{value:.5,label:"CoP aft of front",unit:"\xB7wb"},cop_height:{value:300,label:"CoP height",unit:"mm"},ride_height_front:{value:30,label:"static ride height front (laden)",unit:"mm"},ride_height_rear:{value:35,label:"static ride height rear (laden)",unit:"mm"},I_yaw:{value:295,label:"yaw inertia Izz",unit:"kg\xB7m\xB2"},I_roll:{value:95,label:"roll inertia Ixx",unit:"kg\xB7m\xB2"},I_pitch:{value:380,label:"pitch inertia Iyy",unit:"kg\xB7m\xB2"},chassis_torsion:{value:0,label:"chassis torsional stiffness (0 = rigid)",unit:"N\xB7m/\xB0"},I_twist_front:{value:0,label:"twist inertia, front end (0 = lumped)",unit:"kg\xB7m\xB2"},I_twist_rear:{value:0,label:"twist inertia, rear end (0 = lumped)",unit:"kg\xB7m\xB2"},I_wheel:{value:0,label:"rotating inertia per wheel",unit:"kg\xB7m\xB2"},I_rotor:{value:0,label:"driveline inertia at the motor",unit:"kg\xB7m\xB2"},ackermann_pct:{value:50,label:"Ackermann",unit:"%"},toe_front_deg:{value:0,label:"static toe front (+ in)",unit:"\xB0"},toe_rear_deg:{value:0,label:"static toe rear (+ in)",unit:"\xB0"},spring_front:{value:35,label:"spring front (@spring)",unit:"N/mm"},spring_rear:{value:40,label:"spring rear (@spring)",unit:"N/mm"},mr_front:{value:1,label:"motion ratio front",unit:"-"},mr_rear:{value:1,label:"motion ratio rear",unit:"-"},track_front:{value:1200,label:"track front",unit:"mm"},track_rear:{value:1200,label:"track rear",unit:"mm"},wheelbase:{value:1535,label:"wheelbase",unit:"mm"},rc_front:{value:30,label:"roll centre front",unit:"mm"},rc_rear:{value:40,label:"roll centre rear",unit:"mm"},tv_enabled:{value:0,label:"torque vectoring",unit:"0/1"},tv_kp:{value:3e3,label:"TV yaw-rate gain",unit:"N per rad/s"},tv_ff_low:{value:150,label:"TV feedforward, low speed",unit:"N"},tv_ff_high:{value:300,label:"TV feedforward, high speed",unit:"N"},tv_v_low:{value:18,label:"TV feedforward ramp start",unit:"m/s"},tv_v_high:{value:25,label:"TV feedforward ramp end",unit:"m/s"}},nV=["k_yaw","k_roll","k_pitch"];function il(e){for(let t of nV)delete e[t];for(let t of Object.keys(ln)){let r=e[t];if(!r){e[t]={...ln[t]};continue}e[t]={...r,label:ln[t].label,unit:ln[t].unit}}return e}function J(e,t){return e[t]?.value??ln[t].value}function da(e){let t=J(e,"chassis_torsion");return t>0&&Number.isFinite(t)?t:void 0}function cl(e,t){if(da(e)===void 0)return;let r=J(e,t==="front"?"I_twist_front":"I_twist_rear");return r>0&&Number.isFinite(r)?r:void 0}function Dd(e){let t=(r,n)=>e[r]?.value??n;return{enabled:t("tv_enabled",0)>=.5,kp:t("tv_kp",Js.kp),ffLow:t("tv_ff_low",Js.ffLow),ffHigh:t("tv_ff_high",Js.ffHigh),vLow:t("tv_v_low",Js.vLow),vHigh:t("tv_v_high",Js.vHigh)}}var rw=[10,25,50,100,200,300];function V0(e,t,r,n,o){let s=rw.map(i=>Math.round(i<=25?r*i:r*25+n*(i-25)));return{id:e,label:t,speedMmS:[...rw],reboundN:s,bumpN:s.map(i=>Math.round(i*o))}}var Ed={name:"Generic FS damper",curves:[V0("c1","Soft",1.6,1,.65),V0("c2","Medium",3,1.6,.65),V0("c3","Firm",8,2.4,.65)]};function Id(e){let t=e.curves.length;return t>0?e.curves[Math.floor((t-1)/2)].id:""}var Ao=25;function ei(e,t){let r=e.speedMmS,n=e.forceN,o=Math.min(r.length,n.length);if(o===0||!(t>0))return 0;let a=0,s=0;for(let i=0;i<o;i++){let c=r[i],l=n[i];if(t<=c)return s+(l-s)*(t-a)/(c-a);if(i===o-1)return l+Math.max(0,(l-s)/(c-a))*(t-c);a=c,s=l}return 0}function nw(e,t){return t>=0?ei(e.rebound,t):-ei(e.bump,-t)}function ow(e,t,r){return t*nw(e,t*r)}var B0=(e,t)=>e.curves.find(r=>r.id===t);function ll(e,t){let r=B0(e,Id(e)),n=(t&&B0(e,t.bump))??r,o=(t&&B0(e,t.rebound))??r;return{bump:{speedMmS:n?.speedMmS??[],forceN:n?.bumpN??[]},rebound:{speedMmS:o?.speedMmS??[],forceN:o?.reboundN??[]}}}var _d=5e3;function ul(e,t){let r=t>0?t:1,n=[],o=[],a=e.bump.speedMmS.map(c=>c/r).filter(c=>c<_d),s=e.rebound.speedMmS.map(c=>c/r).filter(c=>c<_d),i=c=>{n.push(c),o.push(ow(e,r,c))};i(-_d);for(let c=a.length-1;c>=0;c--)i(-a[c]);i(0);for(let c of s)i(c);return i(_d),{kind:"map",input:"velocity",x:n,y:o}}var $0=64;function ml(e,t,r){let n=t>0?t:1,o=Math.max(r,1e-6),a=0;for(let s=0;s<$0;s++){let i=Math.sin((s+.5)*Math.PI/$0),c=n*o*i;a+=n*(ei(e.rebound,c)+ei(e.bump,c))*i}return a*(Math.PI/$0)/(Math.PI*o)}function pa(e,t,r,n,o=e){let a=(c,l,u)=>{if(!c||c.curves.length===0)return;let m=ll(c,l);return{law:m,curve:ul(m,u),rate:ml(m,u,Ao)}},s=a(e,t?.front,r),i=a(o??e,t?.rear,n);return!s&&!i?null:{...s?{front:s}:{},...i?{rear:i}:{}}}var aw=(e,t)=>({...e,y:e.y.map(r=>r*t)}),oV=e=>({...e,x:e.x.map(t=>-t).reverse(),y:e.y.map(t=>-t).reverse()});function G0(e,t,r){let n=Math.abs(r)>0?Math.abs(r):1,o=ll(e,t);return{law:o,curve:aw(ul(o,n),.5),rate:ml(o,n,Ao)/2,mr:n,ratio:n,share:.5}}function K0(e,t,r,n,o){let a=n*(Math.abs(r)>0?Math.abs(r):1),s=ll(e,t),i=aw(ul(s,a),1/n);return{law:s,curve:o?oV(i):i,rate:ml(s,a,Ao)/n,mr:a/n,ratio:a,share:1/n}}function dl(e,t){let r=e.damperModelIdRear?t(e.damperModelIdRear):void 0,n=e.heaveDamperModelId?t(e.heaveDamperModelId):void 0,o=e.rollDamperModelId?t(e.rollDamperModelId):void 0;return{...r?{damperModelRear:r}:{},...n?{heaveDamperModel:n}:{},...o?{rollDamperModel:o}:{}}}var Nd=["front","rear","heaveFront","heaveRear","rollFront","rollRear"];function pl(e,t){if(t?.body){let{extended:n,stroke:o,...a}=e??{},{extended:s,stroke:i}=t.body;return{coilover:{...a,extended:s,...i!==void 0?{stroke:i}:{}},source:"part",part:t}}let r=e?.extended!==void 0&&e.extended>0;return{...e?{coilover:e}:{},source:r?"suspension":"none"}}function Un(e,t){if(typeof e=="number")return e;let{x:r,y:n}=e,o=r.length;if(o===0)return 0;if(o===1||t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=0,s=o-1;for(;s-a>1;){let c=a+s>>1;r[c]<=t?a=c:s=c}let i=(t-r[a])/(r[s]-r[a]);return n[a]+i*(n[s]-n[a])}function hl(e){return e.kind==="coil"?2:1}function fl(e){let t=Math.max(0,e.od),r=Math.max(0,Math.min(e.id,t));return Math.PI*(t**4-r**4)/32}function iw(e){return fl(e)/2}function cw(e){let t=Math.max(0,e.width),r=Math.max(0,e.thickness),n=t*r**3/12,o=r*t**3/12,a=e.angleDeg*Math.PI/180;return n*Math.cos(a)**2+o*Math.sin(a)**2}function sw(e){let t=0;for(let r of e)if(Number.isFinite(r)){if(r<=0)return 0;t+=1/r}return t>0?1/t:1/0}function aV(e,t,r){let n=Math.min(e.length,t.length);if(n<2)return 0;let o=Math.abs(r);if(o<=e[0])return(t[1]-t[0])/(e[1]-e[0]);for(let a=1;a<n;a++)if(o<=e[a])return(t[a]-t[a-1])/(e[a]-e[a-1]);return(t[n-1]-t[n-2])/(e[n-1]-e[n-2])}function bl(e,t=0){let r={rateAtLink:0,contributions:{},torsional:0};switch(e.kind){case"none":return r;case"ubar":{let n=e.armLength;if(n<=0||e.barLength<=0)return r;let o=e.G*fl(e.section)/e.barLength,a=2*o/(n*n),s=iw(e.armSection??e.section),i=3*e.E*s/n**3,c=e.dropLinkRate??1/0;return{rateAtLink:sw([a,i,c]),contributions:{barTwist:a,armBending:i,dropLink:c},torsional:o}}case"blade":{let n=e.armLength;if(n<=0||e.barLength<=0)return r;let o=e.G*fl(e.section)/e.barLength,a=2*o/(n*n),s=3*e.E*cw(e.blade)/n**3,i=e.dropLinkRate??1/0;return{rateAtLink:sw([a,s,i]),contributions:{barTwist:a,armBending:s,dropLink:i},torsional:o}}case"torsionTube":{let n=e.leverArm;if(n<=0||e.length<=0)return r;let o=e.G*fl(e.section)/e.length,a=2*o/(n*n);return{rateAtLink:a,contributions:{barTwist:a},torsional:o}}case"coil":{let n=Un(e.rate,2*Math.abs(t)),o=2*Math.max(0,n);return{rateAtLink:o,contributions:{spring:o},torsional:0}}case"direct":return{rateAtLink:e.wheelRate,contributions:{},torsional:0};case"tabulated":{let n=aV(e.linkTravel,e.force,t);return{rateAtLink:Math.max(0,n),contributions:{},torsional:0}}}}function fa(e,t,r=0){if(e.kind==="none")return{wheelRate:0,motionRatio:0,rateAtLink:0};if(e.kind==="direct")return{wheelRate:Math.max(0,e.wheelRate),motionRatio:1,rateAtLink:0};let n=t?Fb(t,r):1,o=t?Cb(t,r):0,a=bl(e,o).rateAtLink;return{wheelRate:Math.max(0,a*n*n),motionRatio:n,rateAtLink:a}}function gl(e,t){let r=e.damper??0;return!r||e.design.kind==="none"?0:hl(e.design)*r*t*t}var lw=150;function sV(e){return Z(e,[0,-.5,1])<-1e-9?Q(e,-1):e}function uw(e){let t=e.hardpoints,r=$(t.rockerPivotB,t.rockerPivotA),n=ne(t.rockerPivotA,Q($(t.rockerToDamper,t.rockerPivotA),.6)),o=sV(ee(me(r,$(t.rockerToDamper,t.rockerPivotA))));return{outer:n,inner:ne(n,Q(o,lw)),attach:"rocker"}}function mw(e){let t=e.hardpoints,r=$(t.lcaRear,t.lcaFront),n=ne(t.lcaFront,Q($(t.uprightLower,t.lcaFront),.6)),o=ee(me(r,$(n,t.lcaFront))),a=o[2]<0?Q(o,-1):o;return{outer:n,inner:ne(n,Q(a,lw)),attach:"lowerArm"}}function dw(e,t,r,n){let o=$(r,t),a=Zr(o);if(a<1e-9)return[...t];let s=Q(o,1/a),i=mk(t,r,.5),c=s[0]<0?-1:1,l=n!==void 0?n*c:Z($(Ln(e,t,s),i),s),u=Math.max(-a/2,Math.min(a/2,l));return ne(i,Q(s,u))}function H0(e){switch(e.kind){case"ubar":case"blade":return e.armLength;case"torsionTube":return e.leverArm;default:return}}var Y0=[0,1,0];function z0(e,t,r){let n=$(r,t),o=Z(n,n);if(o<1e-12)return[...t];let a=Math.max(0,Math.min(1,Z($(e,t),n)/o));return ne(t,Q(n,a))}var iV=(e,t,r)=>Le(e,t)<=Le(e,r)?t:r,cV=2;function lV(e,t,r){let n=r.geometry,o;switch(e.attach){case"rocker":o=dw(t,n.rockerPivotA,n.rockerPivotB,e.shaftStationOuter);break;case"lowerArm":o=iV(t,z0(t,n.lcaFront,n.uprightLower),z0(t,n.lcaRear,n.uprightLower));break;case"upright":o=z0(t,n.uprightLower,n.mcpherson?n.pushrodOuter:n.uprightUpper);break}return Le(o,t)>cV?o:void 0}function uV(e,t){let r=me(Y0,e),n=t?-1:1;if(Zr(r)<1e-6)return[n,0,0];let o=ee(r);return(Math.abs(o[0])>.5?o[0]*n<0:o[2]>0)?Q(o,-1):o}function pw(e,t,r,n){let o=e.linkage,a=r.placement,s=st(Ne(t,o,r.state),a),i=st(o.outer,a),c=st(o.inner,a),l=ee($(i,c)),u=Z($(s,i),l),m=uV(l,a.isFront),p=ne(c,Q(m,n)),d=Z(me(Y0,Q(m,-1)),l),f=n>0&&Math.abs(d)>1e-9?u/(n*d):0,h=ne(p,ir($(c,p),Y0,f)),b=lV(o,s,r);return{outer:s,...b?{mount:b}:{},tip:h,root:p,linkTravel:u,twist:f}}function hr(e,t){let r={};for(let o of en)r[o]=Tt(Je(e,o));let n={vehicle:e,ctx:r};return t&&(n.kc=km(n,t)),n}function mV(e,t,r,n){let o=e.corner.hardpoints,a=Rs(e.rocker,t.points.rockerAngle),s=i=>st(i,r);return{ucaFront:s(o.ucaFront),ucaRear:s(o.ucaRear),lcaFront:s(o.lcaFront),lcaRear:s(o.lcaRear),tieInner:s(Ho(e.inv,t.steer)),rockerPivotA:s(o.rockerPivotA),rockerPivotB:s(o.rockerPivotB),damperChassis:s(e.inv.strut?t.points.uprightUpper:o.damperChassis),uprightUpper:s(t.points.uprightUpper),uprightLower:s(t.points.uprightLower),tieOuter:s(t.points.tieOuter),wheelCenter:s(t.points.wheelCenter),pushrodOuter:s(t.points.pushrodOuter),contactPatch:s(t.points.contactPatch),kingpinGround:s(t.points.kingpinGround),kingpinAtHub:s(t.points.kingpinAtHub),rockerToPushrod:s(a.pushrod),rockerToDamper:s(a.damper),spinAxis:Dn(t.points.spinAxis,r),direct:e.corner.config.actuation==="direct",decoupled:e.corner.config.actuation==="decoupled",mcpherson:e.inv.strut!==void 0,loadedRadius:n.loadedRadius,tyreDeflection:n.tyreDeflection,load:n.load,lifted:n.lifted,clearance:n.clearance??0,contactLength:n.contactLength}}function Od(e,t,r,n){let o=Ue(t,e.vehicle.config),a=o.isFront?o.sideSign*n:0,s;try{s=zt(Ce(e.ctx[t],r,a))}catch{return null}if(!s)return null;let i=Je(e.vehicle,t).config.loadedRadius,c=mV(e.ctx[t],s,o,{loadedRadius:i,tyreDeflection:0,load:NaN,lifted:!1,contactLength:0});return c.wheelCenter.every(Number.isFinite)?{id:t,placement:o,solved:!0,state:s,geometry:c}:null}var Vd=.5;function dV(e,t){let r=([i,c,l])=>{let u=ee($(c,i)),m=$(l,i),p=ee($(m,Q(u,Z(m,u))));return[u,p,me(u,p)]},n=r(e),o=r(t),a=[0,1,2].map(i=>[0,1,2].map(c=>o[0][i]*n[0][c]+o[1][i]*n[1][c]+o[2][i]*n[2][c]));return{rot:a,move:i=>{let c=$(i,e[0]);return ne(t[0],[0,1,2].map(l=>a[l][0]*c[0]+a[l][1]*c[1]+a[l][2]*c[2]))}}}var fw=e=>[(e[2][1]-e[1][2])/2,(e[0][2]-e[2][0])/2,(e[1][0]-e[0][1])/2];function Bd(e,t,r){let n=Ue(t,e.vehicle.config),o=e.ctx[t],a=r.rigid?void 0:{loadedRadius:r.loadedRadius},s=r.state?null:Ce(o,r.travel,r.steer,void 0,a),i=r.state??Nt(s),c=Ce(o,r.travel+Vd,r.steer,void 0,a),l=Ce(o,r.travel-Vd,r.steer,void 0,a),u=(s?s.ok:r.converged)&&c.ok&&l.ok,m=Nt(c),p=Nt(l),d=(T,M)=>st(T.points[M],n),f=o.inv.strut?"pushrodOuter":"uprightUpper",h=d(i,f),b=d(i,"uprightLower"),g=T=>{let M=$(b,h);return Math.hypot(...me(M,$(d(i,T),h)))/Math.hypot(...M)},y=g("tieOuter")>=g("wheelCenter")?"tieOuter":"wheelCenter",x=[h,b,d(i,y)],R=T=>dV(x,[d(T,f),d(T,"uprightLower"),d(T,y)]),v=R(m),S=R(p),A=fw(v.rot),C=fw(S.rot),F=[NaN,NaN,NaN];return{solved:u,state:i,at:T=>d(i,T),velocity:T=>u?Q($(v.move(T),S.move(T)),1/(2*Vd)):F,omega:u?Q($(A,C),1/(2*Vd)):F}}function $d(e,t,r,n){let o=t[0]*-n[1]-t[1]*-n[0];if(Math.abs(o)<1e-9)return null;let a=r[0]-e[0],s=r[1]-e[1],i=(a*-n[1]-s*-n[0])/o;return[e[0]+i*t[0],e[1]+i*t[1]]}function hw(e,t,r){let n=Bd(e,t,Zt(e,r)[t]),o=n.at("contactPatch"),a=n.velocity(o);return{solved:n.solved,cp:[o[1],o[2]],vCp:[a[1],a[2]],wx:n.omega[0]}}function bw(e){let t=Math.hypot(e.vCp[0],e.vCp[1]);return Math.abs(e.wx)*1e9>t?[e.cp[0]-e.vCp[1]/e.wx,e.cp[1]+e.vCp[0]/e.wx]:null}function gw(e,t){let r=Math.hypot(e.vCp[0],e.vCp[1]);if(!(r>1e-9))return null;let n=[-e.vCp[1]/r,e.vCp[0]/r],o=t?[t[0]-e.cp[0],t[1]-e.cp[1]]:[e.cp[0]>0?-1:1,0];return n[0]*o[0]+n[1]*o[1]<0?[-n[0],-n[1]]:n}function pV(e,t,r){return Math.abs(t[0]*(r[1]-e[1])-t[1]*(r[0]-e[0]))<=1e-6*Math.max(1,Math.hypot(r[0]-e[0],r[1]-e[1]))?[(e[0]+r[0])/2,(e[1]+r[1])/2]:null}var fV=.1*Math.PI/180;function W0(e,t,r,n,o){return Math.max(Math.hypot(e[0]-t[0],e[1]-t[1]),Math.hypot(e[0]-r[0],e[1]-r[1]))*fV<=o*n}function Gd(e,t){return!e.valid||!e.cpLeft||!e.cpRight?!1:W0([e.lateral,e.height],e.cpLeft,e.cpRight,e.sinAngle,t)}function ti(e){let t=(o,a,s)=>{let i=o&&a?[a[0]-o[0],a[1]-o[1]]:s;return!o||!i||!(Math.abs(i[0])>1e-9)?Number.NaN:o[1]-o[0]*i[1]/i[0]},r=t(e.cpLeft,e.icLeft,e.lineLeft),n=t(e.cpRight,e.icRight,e.lineRight);return Number.isFinite(r)&&Number.isFinite(n)?{left:r,right:n}:null}function ri(e){let t=ti(e);if(!t||!e.cpLeft||!e.cpRight)return null;let r=(t.left+t.right)/2,n=e.cpRight[0]-e.cpLeft[0],o=e.cpRight[1]-e.cpLeft[1],a=Math.hypot(n,o)||1;return{height:r,heightAboveGround:(0-e.cpLeft[0])*(-o/a)+(r-e.cpLeft[1])*(n/a)}}var hV=1;function yw(e){let t=ti(e);return!t||Math.abs(t.left-t.right)>hV?null:ri(e)}function ni(e){let t=(n,o,a)=>{if(!n)return Number.NaN;if(!o)return a?0:Number.NaN;let s=n[0]-o[0];return Math.abs(s)>1e-9?n[0]/s:Number.NaN},r=(t(e.cpLeft,e.icLeft,e.lineLeft)+t(e.cpRight,e.icRight,e.lineRight))/2;return e.valid&&Number.isFinite(r)?r:0}function Hr(e,t,r){let n=r==="front"?"FL":"RL",o=r==="front"?"FR":"RR",a=hw(e,n,t),s=hw(e,o,t);if(!a.solved||!s.solved)return{height:0,lateral:0,heightAboveGround:0,lateralAlongGround:0,valid:!1,unsolved:!0,icLeft:null,icRight:null,lineLeft:null,lineRight:null,sinAngle:0,cpLeft:a.cp,cpRight:s.cp};let i=bw(a),c=bw(s),l=gw(a,i),u=gw(s,c),m={height:0,lateral:0,heightAboveGround:0,lateralAlongGround:0,valid:!1,icLeft:i,icRight:c,lineLeft:l,lineRight:u,sinAngle:0,cpLeft:a.cp,cpRight:s.cp};if(!l||!u)return m;let p=i?[i[0]-a.cp[0],i[1]-a.cp[1]]:l,d=c?[c[0]-s.cp[0],c[1]-s.cp[1]]:u,f=Math.hypot(p[0],p[1]),h=Math.hypot(d[0],d[1]),b=f>0&&h>0?Math.abs(p[0]*d[1]-p[1]*d[0])/(f*h):0,g=$d(a.cp,p,s.cp,d)??pV(a.cp,l,s.cp);if(!g)return{...m,sinAngle:b};let y=s.cp[0]-a.cp[0],x=s.cp[1]-a.cp[1],R=Math.hypot(y,x)||1,v=y/R,S=x/R,A=(a.cp[0]+s.cp[0])/2,C=(a.cp[1]+s.cp[1])/2,F=(g[0]-a.cp[0])*-S+(g[1]-a.cp[1])*v,T=(g[0]-A)*v+(g[1]-C)*S;return{lateral:g[0],height:g[1],heightAboveGround:F,lateralAlongGround:T,valid:!0,icLeft:i,icRight:c,lineLeft:l,lineRight:u,sinAngle:b,cpLeft:a.cp,cpRight:s.cp}}function Xn(e,t){return{front:Hr(e,t,"front"),rear:Hr(e,t,"rear")}}function Kd(e,t,r){let n=e.length;if(n===0)return 0;if(r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0,a=n-1;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function bV(e,t){return{camber:Kd(e.travel,e.camber,t),toe:Kd(e.travel,e.toe,t),motionRatio:Kd(e.travel,e.motionRatio,t),damperLen:e.damperLen?Kd(e.travel,e.damperLen,t):0}}var xw=e=>bV(e,0).motionRatio;function j0(e,t){if(e.kind!=="coil")return null;let r=t??e.motionRatio,n=Un(e.rate,0)*r*r/2;return n>0&&Number.isFinite(n)?{rate:n,gap:Math.max(0,e.gap??0),bothWays:!!e.bothWays}:null}function U0(e,t){if(e.kind==="none")return 0;if(e.kind==="tabulated"){let n=a=>gV(e,a);return(n(.5)-n(-.5))/(2*.5)/2}if((e.gap??0)>0)return 0;let r=t??e.motionRatio;return Un(e.rate,0)*r*r/2}function yl(e,t){let r=e.damper??0;if(!r||e.design.kind==="none"||e.design.kind==="coil"&&(e.design.gap??0)>0)return 0;let n=t??(e.design.kind==="coil"?e.design.motionRatio:1);return r*n*n/2}function gV(e,t){let{travel:r,force:n}=e,o=r.length;if(o===0)return 0;if(t<=r[0])return n[0];if(t>=r[o-1])return n[o-1];let a=0,s=o-1;for(;s-a>1;){let c=a+s>>1;r[c]<=t?a=c:s=c}let i=(t-r[a])/(r[s]-r[a]);return n[a]+i*(n[s]-n[a])}var X0={kind:"coil",rate:120,motionRatio:.7,gap:5,bothWays:!1};var Rw=new WeakMap;function q0(e,t){let r=Rw.get(e);r||(r=new Map,Rw.set(e,r));let n=`${t.attach}|${t.outer.join(",")}|${JSON.stringify(t.mount??null)}`,o=r.get(n);if(o)return o;let a=Wo(e,t);return r.set(n,a),a}var xV=32,xl=new Map,vw=new WeakMap,RV=1;function vV(e){let t=vw.get(e);return t===void 0&&(t=RV++,vw.set(e,t)),t}function Hd(e,t){if(!t.linkage)return null;let r=Br(e,t.linkage,t.design.kind),n=`${vV(e)}|${r?"unit":"bar"}|${JSON.stringify(t.linkage)}`,o=xl.get(n);if(o)return o;let a=zo(e,t.linkage,{kind:t.design.kind});return xl.size>=xV&&xl.delete(xl.keys().next().value),xl.set(n,a),a}var ha=e=>e!=null&&e.design.kind!=="none"&&e.design.kind!=="coil";function mn(e,t,r){if(!(!ha(r)||!un(e)||ha(t)))return r}var Rl=(e,t,r)=>r==="front"?mn(e.front,t.arbFrontDesign,t.rollBarFrontDesign):mn(e.rear,t.arbRearDesign,t.rollBarRearDesign);function vl(e,t,r=0){let n=(a,s)=>{if(a)return a.design.kind==="none"?0:fa(a.design,Hd(s,a),r).wheelRate},o=(a,s,i)=>{let c=n(s,a),l=n(mn(a,s,i),a);return{...c!==void 0?{element:c}:{},...l!==void 0?{bar:l}:{}}};return{front:o(e.front,t.arbFrontDesign,t.rollBarFrontDesign),rear:o(e.rear,t.arbRearDesign,t.rollBarRearDesign)}}function kl(e,t,r=0){let{front:n,rear:o}=vl(e,t,r),a=s=>s.element===void 0&&s.bar===void 0?void 0:(s.element??0)+(s.bar??0);return{front:a(n),rear:a(o)}}function ba(e,t){let r=(n,o)=>{if(!n)return;if(n.design.kind==="none")return 0;let a=n.linkage?q0(o,n.linkage).atDesign:void 0;return U0(n.design,a)};return{front:r(t.heaveFrontDesign,e.front),rear:r(t.heaveRearDesign,e.rear)}}function ww(e,t){let r=(a,s)=>{if(!a||a.design.kind!=="coil")return;let i=a.linkage?q0(s,a.linkage).atDesign:void 0;return j0(a.design,i)??void 0},n=r(t.heaveFrontDesign,e.front),o=r(t.heaveRearDesign,e.rear);return{...n?{front:n}:{},...o?{rear:o}:{}}}function zd(e,t){let r=(o,a)=>o?yl(o,Q0(o,a)):0,n=(o,a)=>o?gl(o,Z0(o,a)):0;return{heaveFront:r(t.heaveFrontDesign,e.front),heaveRear:r(t.heaveRearDesign,e.rear),rollFront:n(t.arbFrontDesign,e.front),rollRear:n(t.arbRearDesign,e.rear)}}var Q0=(e,t)=>e.linkage?q0(t,e.linkage).atDesign:void 0,Z0=(e,t)=>fa(e.design,Hd(t,e),0).motionRatio;function Fw(e,t){let r=t.damperSetup,n=t.heaveDamperModel??t.damperModel,o=t.rollDamperModel??t.damperModel,a=(p,d,f)=>{if(!p||!n?.curves.length)return;let h=Q0(p,d);if(yl(p,h)>0)return G0(n,r?.[f],h??(p.design.kind==="coil"?p.design.motionRatio:1))},s=(p,d,f)=>{if(!p||!o?.curves.length)return;let h=Z0(p,d);if(!(gl(p,h)>0))return;let b=Hd(d,p)!==null;return K0(o,r?.[f],h,hl(p.design),b&&h>0)},i={},c=a(t.heaveFrontDesign,e.front,"heaveFront"),l=a(t.heaveRearDesign,e.rear,"heaveRear"),u=s(t.arbFrontDesign,e.front,"rollFront"),m=s(t.arbRearDesign,e.rear,"rollRear");return c&&(i.heaveFront=c),l&&(i.heaveRear=l),u&&(i.rollFront=u),m&&(i.rollRear=m),i}function Yd(e,t){let r=t.heaveDamperModel??t.damperModel,n=t.rollDamperModel??t.damperModel,o=(i,c)=>un(i)?{source:"none"}:pl(i.config.coilover,c),a=(i,c)=>{if(!i)return{source:"none"};let l=yl(i,Q0(i,c))>0;return pl(i.coilover,l?r:void 0)},s=(i,c)=>{if(!i||i.design.kind!=="coil")return{source:"none"};let l=gl(i,Z0(i,c))>0;return pl(i.coilover,l?n:void 0)};return{front:o(e.front,t.damperModel),rear:o(e.rear,t.damperModelRear??t.damperModel),heaveFront:a(t.heaveFrontDesign,e.front),heaveRear:a(t.heaveRearDesign,e.rear),rollFront:s(t.arbFrontDesign,e.front),rollRear:s(t.arbRearDesign,e.rear)}}function Cw(e,t){let r=o=>!!o?.linkage&&o.design.kind!=="none"&&o.design.kind!=="direct",n=(o,a,s,i)=>{let c={};o?.linkage&&o.design.kind==="coil"&&(c.heave=o.linkage),r(a)&&(c.roll=a.linkage,c.rollKind=a.design.kind);let l=s?mn(s,a,i):void 0;return s&&r(l)&&(!a||a.design.kind==="none"?(c.roll=l.linkage,c.rollKind=l.design.kind):c.bar={linkage:l.linkage,wheelRate:fa(l.design,Hd(s,l),0).wheelRate}),c.heave||c.roll||c.bar?c:void 0};return{front:n(e.heaveFrontDesign,e.arbFrontDesign,t?.front,e.rollBarFrontDesign),rear:n(e.heaveRearDesign,e.arbRearDesign,t?.rear,e.rollBarRearDesign)}}var un=e=>e.config.actuation==="decoupled",ga="a decoupled axle damps in its heave and roll elements, set below";function Tw(e,t,r={}){let n={...t},o=(p,d)=>{let f=n[p];f&&typeof f=="object"&&"value"in f&&(n[p]={...f,value:d})},{front:a,rear:s}=kl(e,t);a!==void 0&&o("arb_front",a),s!==void 0&&o("arb_rear",s);let i=ba(e,t);i.front!==void 0&&o("heave_spring_front",i.front),i.rear!==void 0&&o("heave_spring_rear",i.rear);let c=MV(e,t,r),l=kV(e,c);n.kinFront=l.kinFront,n.kinRear=l.kinRear;let u=wV(e,c);n.steerFront=l.steerFront,Number.isFinite(u.ackermannPct)&&o("ackermann_pct",u.ackermannPct);let m=p=>un(p)?0:p.measured?.springRate??p.config.springRate;o("spring_front",m(e.front)),o("spring_rear",m(e.rear));for(let[p,d]of[[e.front,"spring_front"],[e.rear,"spring_rear"]])un(p)&&(n.readouts={...n.readouts,[d]:"a decoupled axle has no corner spring; its heave and roll elements carry the car"});for(let[p,d]of[[e.front,"damper_front"],[e.rear,"damper_rear"]])un(p)&&(o(d,0),n.readouts={...n.readouts,[d]:ga});return o("mr_front",u.mrFront),o("mr_rear",u.mrRear),o("wheelbase",u.wheelbase),o("track_front",u.trackFront),o("track_rear",u.trackRear),o("rc_front",u.rcFront),o("rc_rear",u.rcRear),n.surveyedRadiusFront=e.front.config.loadedRadius,n.surveyedRadiusRear=e.rear.config.loadedRadius,n.rcRoad={radiusFront:e.front.config.loadedRadius,radiusRear:e.rear.config.loadedRadius,gainFront:u.rcGainFront,gainRear:u.rcGainRear},n}function kV(e,t){return{kinFront:Mw(e.front),kinRear:Mw(e.rear),steerFront:e.front.measured?void 0:Wd(e.front,t)}}var kw=new WeakMap;function Mw(e){let t=kw.get(e);return t||kw.set(e,t=Vs(e)),t}function MV(e,t,r={}){return SV(e,t,r.front,r.rear)}function SV(e,t,r,n){let o=e.front.config.loadedRadius;if(!((an(r??t.tireModel)??0)>0))return o;let a={...t,surveyedRadiusFront:o,surveyedRadiusRear:e.rear.config.loadedRadius};return jd(a,r,n).front??o}var Sw=new WeakMap;function Wd(e,t=e.config.loadedRadius){let r=Sw.get(e);r||(r=new Map,Sw.set(e,r));let n=r.get(t);if(n)return n;let o=t===e.config.loadedRadius?void 0:{loadedRadius:t},a=jb(e,Ot(e.config),void 0,void 0,void 0,void 0,o);return r.size>=4&&r.clear(),r.set(t,a),a}var Aw=new WeakMap;function AV(e){return ut(e,{travelMin:-1,travelMax:1,steps:3}).samples[1].metrics.motionRatio??1}var oi=e=>e.measured?xw(e.measured):AV(e);function wV(e,t=e.front.config.loadedRadius){let r=()=>e.front.measured?void 0:Wd(e.front,t);return{...FV(e),get steerFront(){return r()},get ackermannPct(){let n=r();return n?Ub(n,Qt(e.front),e.config.wheelbase):Number.NaN}}}function FV(e){let t=Aw.get(e);if(t)return t;let r=e.front.measured,n=e.rear.measured,a=!r||!n?Xn(hr(e),{heave:0,pitch:0,roll:0,steer:0}):null,s={wheelbase:e.config.wheelbase,trackFront:r?r.track:Qt(e.front),trackRear:n?n.track:Qt(e.rear),mrFront:oi(e.front),mrRear:oi(e.rear),rcFront:r?r.rollCentreHeight:a&&a.front.valid?a.front.heightAboveGround:0,rcRear:n?n.rollCentreHeight:a&&a.rear.valid?a.rear.heightAboveGround:0,rcGainFront:r||!a?0:ni(a.front),rcGainRear:n||!a?0:ni(a.rear),rcFrontValid:r?!0:!!a?.front.valid,rcRearValid:n?!0:!!a?.rear.valid};return Aw.set(e,s),s}var er={open:{kind:"open"},spool:{kind:"spool"},clutch:{kind:"clutch",preloadNm:30,rampDriveDeg:40,rampCoastDeg:50,faces:6,muClutch:.1,rFrictionMm:30.4,rRampMm:36},torsen:{kind:"torsen",tbrDrive:3,tbrCoast:3}},Dw=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),dn=(e,t,r,n=1/0)=>typeof e=="number"&&Number.isFinite(e)?Math.min(n,Math.max(r,e)):t;function ya(e){if(Dw(e))switch(e.kind){case"open":case"spool":return{kind:e.kind};case"clutch":{let t=er.clutch;return{kind:"clutch",preloadNm:dn(e.preloadNm,t.preloadNm,0),rampDriveDeg:dn(e.rampDriveDeg,t.rampDriveDeg,1,90),rampCoastDeg:dn(e.rampCoastDeg,t.rampCoastDeg,1,90),faces:Math.round(dn(e.faces,t.faces,0)),muClutch:dn(e.muClutch,t.muClutch,0,1),rFrictionMm:dn(e.rFrictionMm,t.rFrictionMm,1),rRampMm:dn(e.rRampMm,t.rRampMm,1)}}case"torsen":{let t=er.torsen,r=dn(e.preloadNm,0,0);return{kind:"torsen",tbrDrive:dn(e.tbrDrive,t.tbrDrive,1),tbrCoast:dn(e.tbrCoast,t.tbrCoast,1),...r>0?{preloadNm:r}:{}}}default:return}}function Ud(e){if(!Dw(e))return;let t=ya(e.front),r=ya(e.rear);return t||r?{...t?{front:t}:{},...r?{rear:r}:{}}:void 0}function xa(e){let t=dr(e),r=n=>n>=2?"independent":n===1?"diff":"none";return{front:r(t.front),rear:r(t.rear)}}function Ml(e){if(!e.driveline)return;let t=xa(e),r=e.r_dyn.value,n=s=>{if(t[s]!=="diff")return;let i=ya(e.driveline?.[s]);if(!(!i||i.kind==="independent"))return{kind:i.kind,drive:Zc(i,"drive",r),coast:Zc(i,"coast",r),hubs:Zc(i,"hubs",r)}},o=n("front"),a=n("rear");return o||a?{...o?{front:o}:{},...a?{rear:a}:{}}:void 0}var CV={kind:{label:"Differential"},preloadNm:{label:"Preload",unit:"N\xB7m"},rampDriveDeg:{label:"Drive ramp",unit:"\xB0"},rampCoastDeg:{label:"Coast ramp",unit:"\xB0"},faces:{label:"Friction faces"},muClutch:{label:"Clutch friction \u03BC"},rFrictionMm:{label:"Friction radius",unit:"mm"},rRampMm:{label:"Ramp radius",unit:"mm"},tbrDrive:{label:"Drive bias ratio",unit:": 1"},tbrCoast:{label:"Coast bias ratio",unit:": 1"}},Pw=e=>{let t=e==="front"?"Front":"Rear";return Object.fromEntries(Object.entries(CV).map(([r,n])=>[`${e}.${r}`,{section:t,...n}]))},Xd={...Pw("front"),...Pw("rear")},Lw=e=>e.motorModel?.kind==="ice"?e.motorPlacement==="front"?"front":"rear":null;function Ew(e,t){let r=Lw(t);if(!(!r||Lw(e)===r||t.driveline?.[r]))return{...t.driveline,[r]:{...er.clutch}}}function wr(e,t,r,n){return e>0?!(r>0)||!Number.isFinite(r)?e:Math.max(1,e-t/r):n}function qd(e,t,r){let n=Math.max(0,Math.min(1,r)),o=wr(e.freeRadius,e.staticLoad,e.tyreRate,e.surveyed),a=wr(t.freeRadius,t.staticLoad,t.tyreRate,t.surveyed);return n*o+(1-n)*a}function ai(e,t,r){if(t===void 0||r===void 0||!Number.isFinite(t)||!Number.isFinite(r))return e;let n=r-t;return n===0?e:Math.max(1,e+n)}function qn(e,t,r,n){if(!t||r===void 0||n===void 0||!Number.isFinite(r)||!Number.isFinite(n))return e;let o=n-r;return o===0?e:e+t*o}function Sl(e,t){if(!e)return PV(t);let r=t-xo(e,0).camber;return r?{...e,camber:e.camber.map(n=>n+r)}:e}function TV(e){return{kinFront:Sl(e.kinFront,J(e,"camber_front_deg")),kinRear:Sl(e.kinRear,J(e,"camber_rear_deg"))}}function PV(e){let t=[-40,0,40];return{travel:t,motionRatio:t.map(()=>1),camber:t.map(()=>e),toe:t.map(()=>0),damperLen:t.map(()=>0)}}var Iw=9.81,_w=e=>e>1?e/100:e;function Ra(e,t,r){let n=t??e.tireModel??Nc(),o=r??e.tireModelRear??n,a={grip:J(e,"grip_scale"),stiffness:J(e,"stiffness_scale")},s=Qm(n,a);return{front:s,rear:o===n?s:Qm(o,a)}}function pn(e,t,r){let n=Ra(e,t,r),o=We(n.front);return Yt(n.rear===n.front?o:$m(o,We(n.rear)))}function J0(e,t,r){let n=_w(e.front_mass_diss.value),o=Ra(e,t,r),a=We(o.front),s=o.rear===o.front?a:We(o.rear),i=t??e.tireModel,c=r??e.tireModelRear??i,l=e.m.value*Iw*n/2,u=e.m.value*Iw*(1-n)/2,m=(i?a.verticalStiffness():0)||J(e,"tire_vertical_rate"),p=(c?s.verticalStiffness():0)||J(e,"tire_vertical_rate"),d=an(i)??0,f=an(c)??0,h=e.surveyedRadiusFront&&e.surveyedRadiusRear?qd({freeRadius:d,staticLoad:l,tyreRate:m,surveyed:e.surveyedRadiusFront},{freeRadius:f,staticLoad:u,tyreRate:p,surveyed:e.surveyedRadiusRear},n):void 0,b=e.surveyedRadiusFront?wr(d,l,m,e.surveyedRadiusFront):void 0,g=e.surveyedRadiusRear?wr(f,u,p,e.surveyedRadiusRear):void 0;return{ev:a,evR:s,Wf:l,Wr:u,tireRate:m,tireRateRear:p,tyreFreeRadius:d,tyreFreeRadiusRear:f,cgStandingRadius:h,standingFront:b,standingRear:g}}function jd(e,t,r){let n=J0(e,t,r);return{front:n.standingFront,rear:n.standingRear}}function Nw(e,t,r){return J0(e,t,r).cgStandingRadius}function Ut(e,t,r){let n=_w(e.front_mass_diss.value),o=J(e,"mr_front")||1,a=J(e,"mr_rear")||1,{ev:s,evR:i,Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:p,tyreFreeRadiusRear:d,cgStandingRadius:f,standingFront:h,standingRear:b}=J0(e,t,r),g=qc(e),y=Ml(e),x=pa(e.damperModel,e.damperSetup,o,a,e.damperModelRear??e.damperModel),R=e.readouts?.damper_front===ga,v=e.readouts?.damper_rear===ga,S={rho:e.rho.value,area:e.A.value,cl:e.c_l.value,cw:e.c_w.value,copLongFront:1-Math.max(0,Math.min(1,J(e,"cop_long"))),copHeight:J(e,"cop_height"),...e.aeroModel?{model:e.aeroModel}:{},rideHeightFront:J(e,"ride_height_front"),rideHeightRear:J(e,"ride_height_rear")};return{massTotal:e.m.value,frontMassFrac:n,steeringSystem:e.steeringSystem,tv:Dd(e),cgHeight:ai(J(e,"cg_height"),e.cgReference?.standingRadius,f),...f!==void 0?{cgStandingRadius:f}:{},wheelbase:J(e,"wheelbase"),trackFront:J(e,"track_front"),trackRear:J(e,"track_rear"),wheelRateFront:J(e,"spring_front")*o*o,wheelRateRear:J(e,"spring_rear")*a*a,tireRate:u,...m!==u?{tireRateRear:m}:{},tireDamping:J(e,"tire_vertical_damping"),arbFront:J(e,"arb_front"),arbRear:J(e,"arb_rear"),...da(e)?{chassisTorsion:da(e)}:{},brakeBalanceFront:g.balanceFront,brakes:g,...y?{driveline:y}:{},heaveSpringFront:J(e,"heave_spring_front"),heaveSpringRear:J(e,"heave_spring_rear"),unsprungPerCorner:J(e,"unsprung_mass"),unsprungCgHeight:LV(e,{Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:p,tyreFreeRadiusRear:d,standingFront:h,standingRear:b}),tyreFreeRadius:p,...d!==p?{tyreFreeRadiusRear:d}:{},rcHeightFront:qn(J(e,"rc_front"),e.rcRoad?.gainFront,e.rcRoad?.radiusFront,h),rcHeightRear:qn(J(e,"rc_rear"),e.rcRoad?.gainRear,e.rcRoad?.radiusRear,b),corneringStiffnessFront:s.corneringStiffness(c),corneringStiffnessRear:i.corneringStiffness(l),damperFront:x?.front&&!R?x.front.rate:J(e,"damper_front")*o*o,damperRear:x?.rear&&!v?x.rear.rate:J(e,"damper_rear")*a*a,...x?.front&&!R?{damperCurveFront:x.front.curve}:{},...x?.rear&&!v?{damperCurveRear:x.rear.curve}:{},aero:S,ackermannPct:J(e,"ackermann_pct"),toeFrontDeg:J(e,"toe_front_deg"),toeRearDeg:J(e,"toe_rear_deg"),yawInertia:J(e,"I_yaw"),steerFront:e.steerFront,...TV(e)}}function LV(e,t){let r=(a,s,i,c)=>a??(s>0?wr(s,i,c,s):void 0),n=r(t.standingFront,t.tyreFreeRadius,t.Wf,t.tireRate),o=r(t.standingRear,t.tyreFreeRadiusRear,t.Wr,t.tireRateRear);return n!==void 0&&o!==void 0?.5*(n+o):n??o??e.r_dyn.value*1e3}var Qd={capacity:"the battery model\u2019s pack charge \u2014 cells in parallel \xD7 cell capacity",ocv:"the battery model\u2019s pack voltage at full charge"};function Ow(e,t=e.batteryModel){if(!t)return e;let r=Cn(t),n=(o,a)=>({...o,value:a});return{...e,capacity:n(e.capacity,r.capacityAh),ocv:n(e.ocv,r.voltageAtFull)}}var Bw={damper_front:`the damper part sets it: its front curve at ${Ao} mm/s`,damper_rear:`the damper part sets it (the rear's own, where the car names one): its rear curve at ${Ao} mm/s`};function Zd(e){let t=!!(e.damperModelId||e.damperModel),r=t||!!(e.damperModelIdRear||e.damperModelRear);return{...t?{damper_front:Bw.damper_front}:{},...r?{damper_rear:Bw.damper_rear}:{}}}function $w(e,t=e.damperModel,r=e.damperModelRear??t){if(!t&&!r)return e;let n=J(e,"mr_front")||1,o=J(e,"mr_rear")||1,a=pa(t,e.damperSetup,n,o,r);if(!a)return e;let s=(c,l,u)=>({...c??{label:l,unit:"N\xB7s/mm"},value:u}),i={...e};return a.front&&e.readouts?.damper_front!==ga&&(i.damper_front=s(e.damper_front,"damper front",a.front.rate/(n*n))),a.rear&&e.readouts?.damper_rear!==ga&&(i.damper_rear=s(e.damper_rear,"damper rear",a.rear.rate/(o*o))),i}var Gw={how:"scripts/paramTiers.ts: each row \xB120 % (switches flipped, springs on the suspension), first car of every gallery template, largest change to any event time, % of it",templates:["fs-ev-comparison","fs-ev-single","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor","formula-1","touring-car","street-car","cup-car","stock-car","hill-climb","suspension","direct-coilover","pushrod","pullrod","third-spring","mcpherson-strut","tyre-study"],rows:{endurance_reserve:{group:"Powertrain",score:"infinite",byTemplate:{"fs-ev-comparison":"infinite","fs-ev-single":"infinite","fs-combustion":null,"fs-ev-awd":0,"fs-ev-rwd-hubs":"infinite","fs-ev-one-motor":"infinite","formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:0,"direct-coilover":null,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":null,"tyre-study":"infinite"}},gear_ratio:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":5.6255,"fs-ev-awd":5.8819,"fs-ev-rwd-hubs":11.5358,"fs-ev-one-motor":7.2758,"formula-1":.2473,"touring-car":.2195,"street-car":.0998,"cup-car":.2431,"stock-car":.0645,"hill-climb":3.1703,suspension:1.8984,"direct-coilover":.2195,pushrod:1.9001,pullrod:1.9126,"third-spring":1.9001,"mcpherson-strut":.111,"tyre-study":11.9893}},driven_wheels:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:1.9216,"direct-coilover":0,pushrod:1.9171,pullrod:1.919,"third-spring":1.9171,"mcpherson-strut":0,"tyre-study":11.9893}},power_scale:{group:"Powertrain",score:11.9893,byTemplate:{"fs-ev-comparison":11.9893,"fs-ev-single":11.9893,"fs-combustion":10.2883,"fs-ev-awd":4.2843,"fs-ev-rwd-hubs":11.6138,"fs-ev-one-motor":7.2758,"formula-1":2.6682,"touring-car":2.5337,"street-car":1.938,"cup-car":2.6155,"stock-car":1.2193,"hill-climb":1.869,suspension:1.9216,"direct-coilover":2.5337,pushrod:1.9171,pullrod:1.919,"third-spring":1.9171,"mcpherson-strut":1.9778,"tyre-study":11.9893}},grip_scale:{group:"Tyres",score:11.4886,byTemplate:{"fs-ev-comparison":10.9135,"fs-ev-single":10.9135,"fs-combustion":11.4886,"fs-ev-awd":11.3513,"fs-ev-rwd-hubs":11.3513,"fs-ev-one-motor":11.3905,"formula-1":10.9225,"touring-car":7.4484,"street-car":7.2578,"cup-car":7.1946,"stock-car":10.4642,"hill-climb":9.5384,suspension:8.3679,"direct-coilover":7.4484,pushrod:8.3929,pullrod:8.3807,"third-spring":8.3929,"mcpherson-strut":7.35,"tyre-study":10.9135}},front_mass_diss:{group:"Mass & chassis",score:10.3816,byTemplate:{"fs-ev-comparison":1.1854,"fs-ev-single":1.1854,"fs-combustion":1.5398,"fs-ev-awd":1.9682,"fs-ev-rwd-hubs":1.9682,"fs-ev-one-motor":4.5048,"formula-1":5.2182,"touring-car":1.241,"street-car":3.5067,"cup-car":.7277,"stock-car":2.2367,"hill-climb":10.3816,suspension:.5046,"direct-coilover":1.241,pushrod:.4796,pullrod:.4587,"third-spring":.4796,"mcpherson-strut":3.4131,"tyre-study":1.1854}},m:{group:"Mass & chassis",score:9.7815,byTemplate:{"fs-ev-comparison":9.7815,"fs-ev-single":9.7815,"fs-combustion":7.2245,"fs-ev-awd":5.6765,"fs-ev-rwd-hubs":9.2239,"fs-ev-one-motor":7.0296,"formula-1":5.3736,"touring-car":3.7044,"street-car":1.9146,"cup-car":2.6724,"stock-car":3.7623,"hill-climb":5.4157,suspension:3.8549,"direct-coilover":3.7044,pushrod:3.8507,pullrod:3.8527,"third-spring":3.8507,"mcpherson-strut":1.9399,"tyre-study":9.7815}},cop_long:{group:"Aerodynamics",score:6.6543,byTemplate:{"fs-ev-comparison":1.032,"fs-ev-single":1.032,"fs-combustion":1.0669,"fs-ev-awd":1.0452,"fs-ev-rwd-hubs":1.0452,"fs-ev-one-motor":1.0521,"formula-1":5.9878,"touring-car":.1327,"street-car":.0018,"cup-car":.2696,"stock-car":.6469,"hill-climb":6.6543,suspension:.3644,"direct-coilover":.1327,pushrod:.3575,pullrod:.355,"third-spring":.3575,"mcpherson-strut":.0072,"tyre-study":1.032}},front_aero_diss:{group:"Aerodynamics",score:5.2168,byTemplate:{"fs-ev-comparison":.9064,"fs-ev-single":.9064,"fs-combustion":.8657,"fs-ev-awd":.8967,"fs-ev-rwd-hubs":.8967,"fs-ev-one-motor":.8574,"formula-1":4.2912,"touring-car":.0708,"street-car":.0018,"cup-car":.2207,"stock-car":.5291,"hill-climb":5.2168,suspension:.2835,"direct-coilover":.0708,pushrod:.2831,pullrod:.2823,"third-spring":.2831,"mcpherson-strut":.0072,"tyre-study":.9064}},power_limit_kw:{group:"Powertrain",score:4.5916,byTemplate:{"fs-ev-comparison":.4828,"fs-ev-single":.4828,"fs-combustion":null,"fs-ev-awd":4.5916,"fs-ev-rwd-hubs":.5453,"fs-ev-one-motor":3.6198,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:.0626,"direct-coilover":null,pushrod:.0625,pullrod:.0626,"third-spring":.0625,"mcpherson-strut":null,"tyre-study":.4828}},soc:{group:"Powertrain",score:3.5618,byTemplate:{"fs-ev-comparison":3.2245,"fs-ev-single":3.2245,"fs-combustion":0,"fs-ev-awd":1.6179,"fs-ev-rwd-hubs":3.3095,"fs-ev-one-motor":3.5618,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.2245}},effi_pgb:{group:"Powertrain",score:3.5269,byTemplate:{"fs-ev-comparison":3.5269,"fs-ev-single":3.5269,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:.0626,"direct-coilover":0,pushrod:.0625,pullrod:.0626,"third-spring":.0625,"mcpherson-strut":0,"tyre-study":3.5269}},c_l:{group:"Aerodynamics",score:3.4342,byTemplate:{"fs-ev-comparison":.9751,"fs-ev-single":.9751,"fs-combustion":.9539,"fs-ev-awd":1.0777,"fs-ev-rwd-hubs":.9886,"fs-ev-one-motor":1.0797,"formula-1":3.4342,"touring-car":.8979,"street-car":.0715,"cup-car":.2158,"stock-car":.5467,"hill-climb":1.2705,suspension:.9751,"direct-coilover":.8979,pushrod:.9734,pullrod:.9708,"third-spring":.9734,"mcpherson-strut":.0704,"tyre-study":.9751}},ocv:{group:"Powertrain",score:3.3244,byTemplate:{"fs-ev-comparison":3.0446,"fs-ev-single":3.0446,"fs-combustion":0,"fs-ev-awd":1.4595,"fs-ev-rwd-hubs":3.1854,"fs-ev-one-motor":3.3244,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.0446}},capacity:{group:"Powertrain",score:3.3244,byTemplate:{"fs-ev-comparison":3.0446,"fs-ev-single":3.0446,"fs-combustion":0,"fs-ev-awd":1.4595,"fs-ev-rwd-hubs":3.1854,"fs-ev-one-motor":3.3244,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":3.0446}},A:{group:"Aerodynamics",score:2.3707,byTemplate:{"fs-ev-comparison":.802,"fs-ev-single":.802,"fs-combustion":.7928,"fs-ev-awd":.9333,"fs-ev-rwd-hubs":.7926,"fs-ev-one-motor":.961,"formula-1":2.3707,"touring-car":.6374,"street-car":.4904,"cup-car":.2428,"stock-car":.1932,"hill-climb":1.1486,suspension:.802,"direct-coilover":.6374,pushrod:.7991,pullrod:.7982,"third-spring":.7991,"mcpherson-strut":.4873,"tyre-study":.802}},rho:{group:"Aerodynamics",score:2.3707,byTemplate:{"fs-ev-comparison":.802,"fs-ev-single":.802,"fs-combustion":.7928,"fs-ev-awd":.9333,"fs-ev-rwd-hubs":.7926,"fs-ev-one-motor":.961,"formula-1":2.3707,"touring-car":.6374,"street-car":.4904,"cup-car":.2428,"stock-car":.1932,"hill-climb":0,suspension:.802,"direct-coilover":.6374,pushrod:.7991,pullrod:.7982,"third-spring":.7991,"mcpherson-strut":.4873,"tyre-study":.802}},cg_height:{group:"Mass & chassis",score:2.2005,byTemplate:{"fs-ev-comparison":1.8282,"fs-ev-single":1.8282,"fs-combustion":1.6978,"fs-ev-awd":2.2005,"fs-ev-rwd-hubs":1.8919,"fs-ev-one-motor":1.9269,"formula-1":.6248,"touring-car":1.2858,"street-car":1.4681,"cup-car":.992,"stock-car":1.2052,"hill-climb":.6037,suspension:1.8282,"direct-coilover":1.2858,pushrod:1.8142,pullrod:1.8229,"third-spring":1.8142,"mcpherson-strut":1.7176,"tyre-study":1.8282}},l_to_d_ratio:{group:"Aerodynamics",score:1.4351,byTemplate:{"fs-ev-comparison":.7905,"fs-ev-single":.7905,"fs-combustion":.6962,"fs-ev-awd":.5843,"fs-ev-rwd-hubs":.8444,"fs-ev-one-motor":.9611,"formula-1":1.4351,"touring-car":.3671,"street-car":.528,"cup-car":.5631,"stock-car":.4634,"hill-climb":.2349,suspension:.2456,"direct-coilover":.3671,pushrod:.2491,pullrod:.2456,"third-spring":.2491,"mcpherson-strut":.5265,"tyre-study":.7905}},tv_enabled:{group:"Torque vectoring",score:1.2381,byTemplate:{"fs-ev-comparison":1.2381,"fs-ev-single":1.2381,"fs-combustion":0,"fs-ev-awd":1.2293,"fs-ev-rwd-hubs":1.2293,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":.1209,"cup-car":.1617,"stock-car":0,"hill-climb":9e-4,suspension:.3086,"direct-coilover":0,pushrod:.2933,pullrod:.3089,"third-spring":.2933,"mcpherson-strut":.1326,"tyre-study":1.2381}},c_w:{group:"Aerodynamics",score:1.1499,byTemplate:{"fs-ev-comparison":.6319,"fs-ev-single":.6319,"fs-combustion":.5577,"fs-ev-awd":.462,"fs-ev-rwd-hubs":.6559,"fs-ev-one-motor":.7504,"formula-1":1.1499,"touring-car":.2914,"street-car":.4211,"cup-car":.4486,"stock-car":.3694,"hill-climb":.1625,suspension:.1945,"direct-coilover":.2914,pushrod:.1979,pullrod:.1948,"third-spring":.1979,"mcpherson-strut":.4196,"tyre-study":.6319}},brake_balance:{group:"Brakes",score:1.0132,byTemplate:{"fs-ev-comparison":.8303,"fs-ev-single":.8303,"fs-combustion":.6932,"fs-ev-awd":.9772,"fs-ev-rwd-hubs":.8148,"fs-ev-one-motor":1.0132,"formula-1":.97,"touring-car":.9585,"street-car":.7184,"cup-car":.1468,"stock-car":.0764,"hill-climb":.9096,suspension:.8303,"direct-coilover":.9585,pushrod:.8578,pullrod:.8454,"third-spring":.8578,"mcpherson-strut":.7099,"tyre-study":.8303}},stiffness_scale:{group:"Tyres",score:.871,byTemplate:{"fs-ev-comparison":.5088,"fs-ev-single":.5088,"fs-combustion":.4874,"fs-ev-awd":.3745,"fs-ev-rwd-hubs":.4753,"fs-ev-one-motor":.5706,"formula-1":.5776,"touring-car":.4346,"street-car":.1077,"cup-car":.4012,"stock-car":.1613,"hill-climb":.871,suspension:.5088,"direct-coilover":.4346,pushrod:.5253,pullrod:.5172,"third-spring":.5253,"mcpherson-strut":.1518,"tyre-study":.5088}},cop_height:{group:"Aerodynamics",score:.2837,byTemplate:{"fs-ev-comparison":.155,"fs-ev-single":.155,"fs-combustion":.1546,"fs-ev-awd":.1557,"fs-ev-rwd-hubs":.1557,"fs-ev-one-motor":.1542,"formula-1":.1173,"touring-car":.0072,"street-car":.0023,"cup-car":.0745,"stock-car":.1568,"hill-climb":.2837,suspension:.0421,"direct-coilover":.0072,pushrod:.0437,pullrod:.04,"third-spring":.0437,"mcpherson-strut":.0076,"tyre-study":.155}},spring_rear:{group:"Suspension",score:.2822,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":.0355,"touring-car":.1169,"street-car":.2242,"cup-car":.0902,"stock-car":.2822,"hill-climb":.1929,suspension:0,"direct-coilover":.1169,pushrod:.1142,pullrod:.2148,"third-spring":.1142,"mcpherson-strut":.1786,"tyre-study":0}},spring_front:{group:"Suspension",score:.2388,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":.0189,"touring-car":.0958,"street-car":.2388,"cup-car":.1462,"stock-car":.1719,"hill-climb":.1873,suspension:0,"direct-coilover":.0958,pushrod:.1257,pullrod:.0612,"third-spring":.1257,"mcpherson-strut":.1911,"tyre-study":0}},arb_front:{group:"Suspension",score:.1792,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":.0235,"touring-car":.0589,"street-car":.1792,"cup-car":.0215,"stock-car":.0926,"hill-climb":.1095,suspension:null,"direct-coilover":.0589,pushrod:.0455,pullrod:.049,"third-spring":.0455,"mcpherson-strut":.1435,"tyre-study":null}},fr_0:{group:"Tyres",score:.158,byTemplate:{"fs-ev-comparison":.158,"fs-ev-single":.158,"fs-combustion":.1097,"fs-ev-awd":.0708,"fs-ev-rwd-hubs":.1442,"fs-ev-one-motor":.1168,"formula-1":.07,"touring-car":.0492,"street-car":.1006,"cup-car":.065,"stock-car":.0262,"hill-climb":.0334,suspension:.0217,"direct-coilover":.0492,pushrod:.0229,pullrod:.0223,"third-spring":.0229,"mcpherson-strut":.0989,"tyre-study":.158}},arb_rear:{group:"Suspension",score:.1047,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":.0224,"touring-car":.0365,"street-car":.0832,"cup-car":.1047,"stock-car":.0436,"hill-climb":.0734,suspension:null,"direct-coilover":.0365,pushrod:.0411,pullrod:.0332,"third-spring":.0411,"mcpherson-strut":.0643,"tyre-study":null}},unsprung_mass:{group:"Mass & chassis",score:.102,byTemplate:{"fs-ev-comparison":.0477,"fs-ev-single":.0477,"fs-combustion":.0512,"fs-ev-awd":.0545,"fs-ev-rwd-hubs":.0514,"fs-ev-one-motor":.0799,"formula-1":.0313,"touring-car":.0471,"street-car":.102,"cup-car":.0315,"stock-car":.042,"hill-climb":.0278,suspension:.0477,"direct-coilover":.0471,pushrod:.0452,pullrod:.0468,"third-spring":.0452,"mcpherson-strut":.0876,"tyre-study":.0477}},camber_front_deg:{group:"Steering & alignment",score:.0576,byTemplate:{"fs-ev-comparison":.0065,"fs-ev-single":.0065,"fs-combustion":.008,"fs-ev-awd":.0075,"fs-ev-rwd-hubs":.0075,"fs-ev-one-motor":.0098,"formula-1":.0358,"touring-car":.0272,"street-car":.0025,"cup-car":.0191,"stock-car":.0576,"hill-climb":.0389,suspension:.0019,"direct-coilover":.0272,pushrod:.0017,pullrod:.0016,"third-spring":.0017,"mcpherson-strut":.002,"tyre-study":.0065}},camber_rear_deg:{group:"Steering & alignment",score:.0262,byTemplate:{"fs-ev-comparison":.0081,"fs-ev-single":.0081,"fs-combustion":.0085,"fs-ev-awd":.0054,"fs-ev-rwd-hubs":.0096,"fs-ev-one-motor":.0097,"formula-1":.0028,"touring-car":.0106,"street-car":8e-4,"cup-car":5e-4,"stock-car":.0035,"hill-climb":.0262,suspension:.0081,"direct-coilover":.0106,pushrod:.0082,pullrod:.0083,"third-spring":.0082,"mcpherson-strut":3e-4,"tyre-study":.0081}},I_yaw:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},I_roll:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},I_pitch:{group:"Mass & chassis",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},ride_height_front:{group:"Aerodynamics",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},ride_height_rear:{group:"Aerodynamics",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tire_vertical_rate:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tire_vertical_damping:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":0,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},r_dyn:{group:"Tyres",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},damper_front:{group:"Suspension",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},damper_rear:{group:"Suspension",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_kp:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_ff_low:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_ff_high:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_v_low:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},tv_v_high:{group:"Torque vectoring",score:0,byTemplate:{"fs-ev-comparison":0,"fs-ev-single":0,"fs-combustion":0,"fs-ev-awd":0,"fs-ev-rwd-hubs":0,"fs-ev-one-motor":0,"formula-1":0,"touring-car":0,"street-car":0,"cup-car":0,"stock-car":0,"hill-climb":0,suspension:0,"direct-coilover":0,pushrod:0,pullrod:0,"third-spring":0,"mcpherson-strut":0,"tyre-study":0}},wheelbase:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},track_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},track_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},rc_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},rc_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},chassis_torsion:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_twist_front:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_twist_rear:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_wheel:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},I_rotor:{group:"Mass & chassis",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},v_limit_endurance:{group:"Powertrain",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},mr_front:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},mr_rear:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},heave_spring_front:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},heave_spring_rear:{group:"Suspension",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},toe_front_deg:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},toe_rear_deg:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}},ackermann_pct:{group:"Steering & alignment",score:null,byTemplate:{"fs-ev-comparison":null,"fs-ev-single":null,"fs-combustion":null,"fs-ev-awd":null,"fs-ev-rwd-hubs":null,"fs-ev-one-motor":null,"formula-1":null,"touring-car":null,"street-car":null,"cup-car":null,"stock-car":null,"hill-climb":null,suspension:null,"direct-coilover":null,pushrod:null,pullrod:null,"third-spring":null,"mcpherson-strut":null,"tyre-study":null}}}};function Qn(e){return!!e&&typeof e=="object"&&"value"in e&&"label"in e}var _V={Batteriekapazit\u00E4t:"pack capacity",Rollwiderstandsbeiwert:"rolling-resistance coefficient"},Hw=e=>_V[e]??e;function Jd(e){let t=[];for(let r of Object.keys(e)){if(r==="motor"||r==="name")continue;let n=e[r];Qn(n)&&t.push({key:r,label:Hw(n.label),value:n.value,unit:n.unit})}return t}var NV=[{title:"Mass & chassis",keys:["m","front_mass_diss","cg_height","unsprung_mass","wheelbase","track_front","track_rear","rc_front","rc_rear","chassis_torsion","I_twist_front","I_twist_rear","I_yaw","I_roll","I_pitch","I_wheel","I_rotor"]},{title:"Aerodynamics",keys:["A","c_l","c_w","l_to_d_ratio","front_aero_diss","cop_long","cop_height","ride_height_front","ride_height_rear","rho"]},{title:"Tyres",keys:["grip_scale","stiffness_scale","tire_vertical_rate","tire_vertical_damping","fr_0","r_dyn"]},{title:"Powertrain",keys:["gear_ratio","driven_wheels","effi_pgb","power_scale","power_limit_kw","v_limit_endurance","endurance_reserve","capacity","ocv","soc"]},{title:"Suspension",keys:["spring_front","spring_rear","mr_front","mr_rear","arb_front","arb_rear","heave_spring_front","heave_spring_rear","damper_front","damper_rear"]},{title:"Steering & alignment",keys:["camber_front_deg","camber_rear_deg","toe_front_deg","toe_rear_deg","ackermann_pct"]},{title:"Brakes",keys:["brake_balance"]},{title:"Torque vectoring",keys:["tv_enabled","tv_kp","tv_ff_low","tv_ff_high","tv_v_low","tv_v_high"]}],OV=.5,Kw=e=>e==="infinite"?1/0:typeof e=="number"?e:null,VV=e=>/front/.test(e)?e.replace("front","rear"):/rear/.test(e)?e.replace("rear","front"):null,cne=(()=>{let e=Gw.rows,t=o=>{let a=VV(o),s=Kw(e[o]?.score),i=a&&e[a]?Kw(e[a].score):null;return s==null?i:i==null?s:Math.max(s,i)},r=new Set,n=new Map;for(let[o,a]of Object.entries(e)){let s=t(o);s!=null&&(s>=OV&&r.add(o),n.set(a.group,Math.max(n.get(a.group)??0,s)))}for(let[o,a]of Object.entries(e)){let s=t(o);s!=null&&s>0&&s===n.get(a.group)&&r.add(o)}return r})();var ey={wheelbase:"set by the axle positions in Kinematics",track_front:"twice the front wheel-centre Y",track_rear:"twice the rear wheel-centre Y",rc_front:"solved from the front wishbones, on the fitted tyre",rc_rear:"solved from the rear wishbones, on the fitted tyre",mr_front:"damper travel per mm of front wheel travel, from the linkage",mr_rear:"damper travel per mm of rear wheel travel, from the linkage",spring_front:"the front corner spring rate, stored on the suspension the car runs",spring_rear:"the rear corner spring rate, stored on the suspension the car runs",ackermann_pct:"solved from the rack and tie rods, read near centre"};function zw(e){let t=new Map;for(let a of Jd(e))t.set(a.key,a);let r=new Set,n=[];for(let a of NV){let s=[];for(let i of a.keys){let c=t.get(i);c&&(s.push(c),r.add(i))}s.length&&n.push({title:a.title,rows:s})}let o=Jd(e).filter(a=>!r.has(a.key));return o.length&&n.push({title:"Other",rows:o}),n}var ty={A:"the aero model's reference area",c_l:"read off the aero model at the ride heights",c_w:"read off the aero model at the ride heights",l_to_d_ratio:"read off the aero model at the ride heights",front_aero_diss:"the aero model's front and rear coefficients set the balance",cop_long:"the aero model's front and rear coefficients set the balance"},ry={ride_height_front:"reaches nothing until an aero model is attached at the head of the Aerodynamics group",ride_height_rear:"reaches nothing until an aero model is attached at the head of the Aerodynamics group"},Yw=e=>!!(e.aeroModelId||e.aeroModel);function BV(e){let t=o=>o!=null&&o.design.kind!=="none",r=o=>o?.design.kind==="none",n={};return t(e.arbFrontDesign)&&(n.arb_front="the front anti-roll bar design sets it"),t(e.arbRearDesign)&&(n.arb_rear="the rear anti-roll bar design sets it"),!n.arb_front&&t(e.rollBarFrontDesign)&&(n.arb_front="the front anti-roll bar design sets it"),!n.arb_rear&&t(e.rollBarRearDesign)&&(n.arb_rear="the rear anti-roll bar design sets it"),!n.arb_front&&r(e.arbFrontDesign)&&(n.arb_front="the front roll element is None"),!n.arb_rear&&r(e.arbRearDesign)&&(n.arb_rear="the rear roll element is None"),t(e.heaveFrontDesign)&&(n.heave_spring_front="the front third-spring design sets it"),t(e.heaveRearDesign)&&(n.heave_spring_rear="the rear third-spring design sets it"),r(e.heaveFrontDesign)&&(n.heave_spring_front="the front heave element is None"),r(e.heaveRearDesign)&&(n.heave_spring_rear="the rear heave element is None"),n}var $V=e=>!!(e.batteryModelId||e.batteryModel),Ww={capacity:"an engine car has no pack",ocv:"an engine car has no pack",soc:"an engine car has no pack",power_limit_kw:"an engine car has no pack, and the power rule is the electric class\u2019s",endurance_reserve:"an engine car has no pack to finish with a reserve of",I_rotor:"the engine model refers its own crank through each gear"},lne=Object.keys(Ww);function ny(e){if(!(e.motorModelId||e.motorModel))return{};let t=yt(e.motorModel),r={effi_pgb:"the motor model states its own efficiency",...t?Ww:{}};return(e.motorCount!=null||t)&&(r.driven_wheels="the motor layout in Powertrain sets which wheels are driven"),r}function GV(e,t){let r={};return t.geometry&&Object.assign(r,ey,BV(e)),Yw(e)&&Object.assign(r,ty),$V(e)&&Object.assign(r,Qd),Object.assign(r,ny(e)),Object.assign(r,Zd(e)),Object.assign(r,pd(e)),e.readouts&&Object.assign(r,e.readouts),r}function jw(e,t){let r=GV(e,t);return Yw(e)||Object.assign(r,ry),r}function oy(e){let t=e.cop_long;return Qn(t)?1-t.value:.5}function KV(e,t){let r=e.front_aero_diss,n=e.cop_long;!Qn(r)||!Qn(n)||(t===r.label?n.value=1-r.value:t===n.label&&(r.value=1-n.value))}function HV(e,t){KV(e,t);let r=e.c_l,n=e.c_w,o=e.l_to_d_ratio;!Qn(r)||!Qn(n)||(t===r.label||t===n.label?Qn(o)&&n.value!==0&&(o.value=r.value/n.value):Qn(o)&&t===o.label&&o.value!==0&&(n.value=r.value/o.value))}function si(e,t,r){let n=!1;for(let o of Object.keys(e)){if(o==="motor"||o==="name")continue;let a=e[o];if(Qn(a)&&Hw(a.label)===t){a.value=r,n=!0;break}}return n&&HV(e,t),n}function ep(e,t,r=0,n,o){let a=()=>({cl:e.c_l.value,cw:e.c_w.value,frontShare:oy(e),A:e.A.value,platform:null});if(!e.aeroModel)return a();let s=Pn(n??Ut(e),t,r,o);if(!s)return a();let i=s.clFront+s.clRear;return{cl:i,cw:s.cd,frontShare:i!==0?s.clFront/i:oy(e),A:s.area,platform:s}}var Uw=e=>typeof e=="object"&&e!==null&&typeof e.value=="number"&&typeof e.label=="string";function Xw(e,t=e.aeroModel){if(!t)return e;let r=fo(t,{wheelbase:J(e,"wheelbase")}).at(J(e,"ride_height_front"),J(e,"ride_height_rear")),{cl:n,balanceFront:o}=qh(r),a=(i,c,l)=>({...i??c,value:l}),s={...e,A:a(e.A,e.A,t.area),c_l:a(e.c_l,e.c_l,n),c_w:a(e.c_w,e.c_w,r.cd),front_aero_diss:a(e.front_aero_diss,e.front_aero_diss,o),cop_long:a(Uw(e.cop_long)?e.cop_long:void 0,ln.cop_long,1-o)};return Uw(e.l_to_d_ratio)&&(s.l_to_d_ratio={...e.l_to_d_ratio,value:r.cd!==0?n/r.cd:0}),s}var Al={dsTarget:.25,accelStep:.25,vTol:.002,scanSteps:24,seamIters:8,fitSpacing:1},zV=32;function qw(e,t,r){let n=Math.round(e/t);return Math.max(1,Math.min(Number.isFinite(n)?n:1,Math.floor(r/zV)||1))}function Bt(e){let t=Al,r=(n,o,a)=>{let s=Number(n);return Number.isFinite(s)&&s>=a?s:o};return{dsTarget:r(e?.dsTarget,t.dsTarget,.001),accelStep:r(e?.accelStep,t.accelStep,.001),vTol:r(e?.vTol,t.vTol,1e-6),scanSteps:Math.max(4,Math.round(r(e?.scanSteps,t.scanSteps,4))),seamIters:Math.max(1,Math.round(r(e?.seamIters,t.seamIters,1))),fitSpacing:r(e?.fitSpacing,t.fitSpacing,0)}}var Qw=Math.PI/180,tp=.02,Zw=new WeakMap;function wl(e){let t=Zw.get(e);if(t!==void 0)return t;let r=e.npts,n=new Array(r),o=new Array(r),a=!1;for(let i=0;i<r;i++){let c=(e.gradient?.[i]??0)*Qw,l=(e.bank?.[i]??0)*Qw,u=e.verticalCurvature?.[i]??0;n[i]=c===0&&l===0?1:Math.cos(c)*Math.cos(l),o[i]=(u-e.curvature[i]*Math.sin(l))/9.81,(n[i]!==1||o[i]!==0)&&(a=!0)}let s=a?{n0:n,k:o}:null;return Zw.set(e,s),s}function rp(e,t,r){return e.n0[t]+e.k[t]*r*r}function Jw(e,t){return e.k[t]<0?Math.sqrt(Math.max(0,e.n0[t])/-e.k[t]):1/0}function eF(e,t){if(!e)return null;let r=1/0,n=-1/0;for(let o=0;o<e.n0.length;o++){let a=rp(e,o,t[o]??0);a<r&&(r=a),a>n&&(n=a)}return r>=1-tp&&n<=1+tp?null:{lo:r,hi:n}}var ii=[.1,.25,.5,.75,1,1.25,1.5,2,2.5];function tF(e){let t=e.lo>=1-tp?1:1-1.25*(1-e.lo)-.05,r=e.hi<=1+tp?1:1+1.25*(e.hi-1)+.05,n=[...ii].reverse().find(a=>a<=t)??ii[0],o=ii.find(a=>a>=r)??ii[ii.length-1];return ii.filter(a=>a>=n&&a<=o)}function ay(e,t,r){return r<1?Math.max(e,t):Math.min(e,t)}function rF(e,t,r,n){let o=e.n0.length;return a=>{let s=n?n(a):r,i=a%o;if(e.n0[i]===1&&e.k[i]===0)return s;let c=e.n0[i],l=e.k[i],u=d=>c+l*d*d,m=s.kappaMax===void 0?t.kappaMax:t.kappaMax===void 0?s.kappaMax:Math.min(s.kappaMax,t.kappaMax),p=m!==void 0?{kappaMax:m}:{};return n?{vMax:s.vMax,...p,axAccel:(d,f,h=1,b=1)=>s.axAccel(d,f,h,b)+t.axAccel(u(d),d,f,h,b)-r.axAccel(d,f,h,b),axDecel:(d,f,h=1,b=1)=>{let g=y=>s.axDecel(d,f,h,y)+t.axDecel(u(d),d,f,h,y)-r.axDecel(d,f,h,y);return b===1?g(1):ay(g(b),g(1),b)},ay:(d,f,h=1)=>Math.max(0,s.ay(d,f,h)+t.ay(u(d),d,f,h)-r.ay(d,f,h)),scrub:(d,f,h=1)=>(s.scrub?.(d,f,h)??0)+t.scrub(u(d),d,f,h)-(r.scrub?.(d,f,h)??0)}:{vMax:s.vMax,...p,axAccel:(d,f,h=1,b=1)=>t.axAccel(u(d),d,f,h,b),axDecel:(d,f,h=1,b=1)=>t.axDecel(u(d),d,f,h,b),ay:(d,f,h=1)=>t.ay(u(d),d,f,h),scrub:(d,f,h=1)=>t.scrub(u(d),d,f,h)}}}function np(e,t,r,n,o){let a=e.length,s=r?a:a-1,i=C=>r?(C+1)%a:C+1,{brakeAhead:c,apexAhead:l}=YV(e,t,r),u=new Array(a),m=new Array(a),p=new Array(a),d=new Array(a).fill(0),f=0,h=0,b=0,g=Math.max(0,Math.min(1,n.kept)),y=g>=1?0:n.up,x=g>=1?0:n.down,R=4*y*(1-g),v=C=>{let{v:F,gear:T,tau:M,target:k}=C;f=0,h=0,b=0;for(let w=0;w<s;w++){let P=i(w),L=e[P];for(let D=0;M<=0&&D<n.count;D++){let I=T;if(F<L-1e-9?n.best(F)>T&&(n.rpm(F,T)>=n.limitRpm||c[w]>=F*R)?I=T+1:T>0&&F<n.vIdle(T)&&(I=T-1):L<F-1e-9&&T>0&&n.best(l[w])<T&&n.rpm(F,T-1)<=n.limitRpm&&(I=T-1),I===T)break;k=I,I>T?f++:h++,M=I>T?y:x,M<=0&&(T=k)}u[w]=F,m[w]=T+1,p[w]=n.rpm(F,T);let E=M>0;d[w]=E?1:0;let _=L;if(!E)F<L&&(_=Math.min(L,Math.sqrt(Math.max(0,F*F+2*o(w,F,n.share(F,T))*t[w]))));else if(F<L){let D=o(w,F,g>0?g*n.share(F,T):0),I=Math.min(L,Math.sqrt(Math.max(0,F*F+2*D*t[w]))),N=F+I>0?2*t[w]/(F+I):1/0;if(N<=M)_=I,b+=N,M-=N;else{let O=Math.min(L,Math.max(0,F+D*M)),V=Math.max(0,t[w]-(F+O)*.5*M);b+=M,M=0,T=k,_=Math.min(L,Math.sqrt(Math.max(0,O*O+2*o(w,O,n.share(O,T))*V)))}}else{let D=F+_>0?2*t[w]/(F+_):0;b+=Math.min(D,M),M-=D,M<=0&&(T=k)}F=_}return{v:F,gear:T,tau:M,target:k}},S=n.best(e[0]),A={v:e[0],gear:S,tau:0,target:S};if(r)for(let C=0;C<6;C++){let F=v(A),T=Math.abs(F.v-A.v)<=1e-9&&F.gear===A.gear&&F.target===A.target&&Math.abs(F.tau-A.tau)<=1e-12;if(A=F,T)break}else{let C=v(A);u[a-1]=C.v,m[a-1]=C.gear+1,p[a-1]=n.rpm(C.v,C.gear),d[a-1]=C.tau>0?1:0}return{v:u,gear:m,rpm:p,shifting:d,upshifts:f,downshifts:h,gapTime:b}}function YV(e,t,r){let n=e.length,o=new Array(n).fill(1/0),a=e.slice(),s=1/0,i=e[n-1],c=r?2*n-1:n-2;for(let l=c;l>=0;l--){let u=l%n,m=r?(u+1)%n:u+1,p=e[m]<e[u]-1e-9;s=p?0:s+t[u],i=p?Math.min(i,e[m]):e[u],l<n&&(o[u]=s,a[u]=i)}return{brakeAhead:o,apexAhead:a}}var sy=.001,iy=9.81,Fl=(e,t)=>op(e?.gradient?.[t]??0);function op(e){return e===0?0:-iy*Math.sin(e*Math.PI/180)}function ci(e,t){let r=new Array(t);for(let n=0;n<t;n++)r[n]=op(e?.[n]??0);return r}function ap(e,t){let r=e?.[t];return r!=null&&r>0?r:1}var wo=(e,t)=>ap(e?.mu,t),va=(e,t)=>e?.bank?.[t]??0;function WV(e,t,r,n,o,a){let s=e.ay(t,r,wo(o,a)),i=va(o,a);if(!i)return s;let c=i*Math.PI/180,l=n===0?0:-Math.sign(n)*iy*Math.sin(c);return Math.max(0,(s+l)/Math.cos(c))}function mt(e,t){if(!t)return e;let r=t*Math.PI/180;return e*Math.cos(r)+iy*Math.sin(r)}function cy(e,t,r,n,o){if(r<=t)return t;if(e(r)<=0)return r;let a=(r-t)/n,s=r,i=t,c=!1;for(let l=1;l<=n;l++){let u=r-l*a;if(e(u)<=0){i=u,s=u+a,c=!0;break}}if(!c)return t;for(;s-i>o;){let l=.5*(i+s);e(l)<=0?i=l:s=l}return i}var Zn=(e,t,r)=>t?t(r):e,jV=1e-4;function UV(e,t){let r=Math.abs(t);return e.kappaMax!==void 0&&r>e.kappaMax?e.kappaMax:r}function XV(e,t,r){if(e.kappaMax===void 0&&!t)return;let n=0,o=-1,a=0;for(let i=0;i<r.npts;i++){let c=Zn(e,t,i).kappaMax,l=Math.abs(r.curvature[i]);c===void 0||!(l>c)||(n+=r.ds[i],l/c>a&&(a=l/c,o=i))}if(o<0)return;let s=Zn(e,t,o).kappaMax;return{length:n,at:r.s[o],radius:1/Math.abs(r.curvature[o]),lockRadius:1/s}}function li(e,t,r,n,o,a,s){let i=Bt(r),c=[];for(let l=0;l<t.length;l++){let u=t[l],m=Zn(e,o,l),p=UV(m,u),d=a!==void 0&&a>0?Math.min(m.vMax,a):m.vMax,f=s?Math.min(d,s(l)):d,h=p<=0?f:cy(b=>b*b*p-WV(m,b,0,u,n,l),sy,f,i.scanSteps,Math.min(i.vTol,jV));c.push({v:h,ax:0,ay:h*h*u})}return c}function qV(e,t,r,n,o,a,s=1,i=0,c=0,l){if(r.v<=t.v)return 0;let u=d=>{let f=mt(d*d*n,c),h=(l?e.axDecel(d,Math.abs(f),s,l(d)):e.axDecel(d,Math.abs(f),s))+i;return Math.sqrt(Math.max(0,d*d+2*h*o))},m=r.v;r.v=cy(d=>u(d)-t.v,sy,r.v,a.scanSteps,a.vTol),r.ay=r.v*r.v*n;let p=Math.abs(mt(r.ay,c));return r.ax=(l?e.axDecel(r.v,p,s,l(r.v)):e.axDecel(r.v,p,s))+i,m-r.v}function QV(e,t,r,n,o,a=1,s=0,i=0,c=1){if(r.v>=t.v)return 0;r.ay=r.v*r.v*n,r.ax=e.axAccel(r.v,Math.abs(mt(r.ay,i)),a,c)+s;let l=t.v;return t.v=Math.min(t.v,Math.sqrt(Math.max(0,r.v*r.v+2*r.ax*o))),l-t.v}function nF(e,t,r,n,o,a){let s=Bt(n),i=r.npts,c=0;for(let l=0;l<s.seamIters;l++){let u=0;c++;for(let m=i-1;m>=0;m--){let p=(m+1)%i;u=Math.max(u,qV(Zn(e,o,m),t[p],t[m],r.curvature[m],r.ds[m],s,wo(r,m),Fl(r,m),va(r,m),a?d=>a(m,d):void 0))}if(u<=s.vTol)break}return c}function oF(e,t,r,n,o,a){let s=Bt(n),i=r.npts,c=0;for(let l=0;l<s.seamIters;l++){let u=0;c++;for(let m=0;m<i;m++){let p=(m+1)%i;u=Math.max(u,QV(Zn(e,o,m),t[p],t[m],r.curvature[m],r.ds[m],wo(r,m),Fl(r,m),va(r,m),a?a[m]:1))}if(u<=s.vTol)break}return c}function ZV(e,t,r){let n=r.load?wl(t):null;if(!n||!r.load)return{pick:r.envelope};let o=t.npts;return{pick:rF(n,r.load,e,r.envelope),cap:a=>Jw(n,a%o),n:(a,s)=>rp(n,a,s)}}function aF(e,t,r,n,o,a,s){return np(n,r.ds,o,a,(i,c,l)=>{let u=c*c*r.curvature[i];return Zn(e,t,i).axAccel(c,Math.abs(mt(u,va(r,i))),wo(r,i),s?l*s[i]:l)+Fl(r,i)})}function sF(e,t){return{gear:e.gear.slice(0,t),engineRpm:e.rpm.slice(0,t),shifting:e.shifting.slice(0,t)}}function iF(e,t,r,n){if(!e.scrub)return{};let o=!1,a=n.map((s,i)=>{let c=Zn(e,t,i),l=mt(s*s*r.curvature[i],va(r,i)),u=c.scrub?c.scrub(s,Math.abs(l),wo(r,i)):0;return u!==0&&(o=!0),u});return o?{axScrub:a}:{}}function tr(e,t,r,n={}){let o=Bt(r),a=t.npts,s=t.closed&&!n.standingStart,{pick:i,cap:c,n:l}=ZV(e,t,n),u=n.driveDerate,m=n.brakeFade;if(!s)return JV(e,t,o,n.standingStart===!0,i,u,n.vCeiling,m,c,l,n.shifts);let p=li(e,t.curvature,o,t,i,n.vCeiling,c),d=nF(e,p,t,o,i,m),f=oF(e,p,t,o,i,u),h=n.shifts?aF(e,i,t,p.map(R=>R.v),!0,n.shifts,u):void 0;if(h)for(let R=0;R<a;R++)p[R].v=h.v[R];for(let R=0;R<a;R++){let v=p[R];v.ay=v.v*v.v*t.curvature[R];let S=p[(R+1)%a].v;v.ax=(S*S-v.v*v.v)/(2*t.ds[R])}let b=p.map(R=>R.v),g=p.map(R=>R.ax),y=p.map(R=>R.ay),x=0;for(let R=0;R<a;R++){let v=b[R]+b[(R+1)%a];v>0&&(x+=2*t.ds[R]/v)}return{states:p,v:b,ax:g,ay:y,laptime:x,sweeps:{backward:d,forward:f},...l?{loadFactor:b.map((R,v)=>l(v,R))}:{},...iF(e,i,t,b),...h?sF(h,a):{},...cF(e,i,t)}}function cF(e,t,r){let n=XV(e,t,r);return n?{pastLock:n}:{}}function JV(e,t,r,n,o,a,s,i,c,l,u){let m=t.npts,p=t.closed?m:m-1,d=p+1,f=new Array(d);for(let x=0;x<d;x++)f[x]=t.curvature[x%m];let h=li(e,f,r,t,o,s,c);n&&(h[0].v=0);for(let x=p-1;x>=0;x--){let R=h[x],v=h[x+1];if(R.v<=v.v)continue;let S=Zn(e,o,x),A=F=>{let T=mt(F*F*t.curvature[x],va(t,x)),M=(i?S.axDecel(F,Math.abs(T),wo(t,x),i(x,F)):S.axDecel(F,Math.abs(T),wo(t,x)))+Fl(t,x);return Math.sqrt(Math.max(0,F*F+2*M*t.ds[x]))},C=n&&x===0?R.v:sy;R.v=cy(F=>A(F)-v.v,C,R.v,r.scanSteps,r.vTol)}for(let x=0;x<p;x++){let R=h[x],v=h[x+1];R.ay=R.v*R.v*t.curvature[x];let S=mt(R.ay,va(t,x));R.ax=Zn(e,o,x).axAccel(R.v,Math.abs(S),wo(t,x),a?a[x]:1)+Fl(t,x),v.v=Math.min(v.v,Math.sqrt(Math.max(0,R.v*R.v+2*R.ax*t.ds[x])))}let b=u?aF(e,o,t,h.map(x=>x.v),!1,u,a):void 0;if(b)for(let x=0;x<d;x++)h[x].v=b.v[x];let g=0;for(let x=0;x<p;x++){let R=h[x].v+h[x+1].v;R>0&&(g+=2*t.ds[x]/R)}let y=h.slice(0,m);for(let x=0;x<m;x++){let R=y[x];R.ay=R.v*R.v*t.curvature[x];let v=x<p?h[x+1].v:R.v;R.ax=t.ds[x]>0?(v*v-R.v*R.v)/(2*t.ds[x]):0}return{states:y,v:y.map(x=>x.v),ax:y.map(x=>x.ax),ay:y.map(x=>x.ay),laptime:g,sweeps:{backward:1,forward:1},...l?{loadFactor:y.map((x,R)=>l(R,x.v))}:{},...iF(e,o,t,y.map(x=>x.v)),...b?sF(b,m):{},...cF(e,o,t)}}var lF=(e,t)=>{let r=e[t]?.value;return Number.isFinite(r)&&r>0?r:0};function ka(e,t,r){let n=e.m.value,o=e.r_dyn?.value??0,a=lF(e,"I_wheel"),s=e.motorModel?.kind==="ice"?0:lF(e,"I_rotor"),i=e.gear_ratio?.value??1;if(!(o>0)||a===0&&s===0)return{mass:n,driven:0,undriven:0,effective:n,powerFactor:1,tractionFactor:1};let c=o*o,l=(t?2:0)+(r?2:0),u=4-l,m=(l*a+s*i*i)/c,p=u*a/c,d=n+m+p;return{mass:n,driven:m,undriven:p,effective:d,powerFactor:n/d,tractionFactor:n/(n+p)}}function Ma(e){let t=e.fAxle;return{drivenFront:t?t.fFront.some(r=>r>0):!1,drivenRear:t?t.fRear.some(r=>r>0):!0}}var Cl=36e5,uy=Math.PI*2,ly=e=>Math.max(0,Math.min(1,e));function sp(e){let t=e.motorModel;if(!t){let s=e.effi_pgb?.value??.9;return()=>s}if(t.kind==="simple"){let s=t.efficiency>.01?t.efficiency:.9;return()=>s}if(t.kind==="ice"){let s=t.gearbox.efficiency>.01?t.gearbox.efficiency:.9;return()=>s}let r=Qi(t),n=e.gear_ratio.value,o=e.r_dyn.value,a=Math.max(1,Math.round(e.motorCount??e.driven_wheels.value));return(s,i)=>{let c=s*n/o*(60/uy),l=Math.max(0,i*o/(n*a)),u=r.efficiency(c,l);return u>.01?u:.5}}var uF=e=>Math.max(0,2-1/e);function e3(e){let t=e.motorModel;if(t?.kind!=="map"){let a=uF(sp(e)(0,0));return()=>a}let r=Qi(t),n=e.gear_ratio.value,o=e.r_dyn.value;return(a,s,i)=>{let c=a*n/o*(60/uy),l=Math.max(0,s*o/(n*Math.max(1,i))),u=r.efficiency(c,l);return uF(u>.01?u:.5)}}var mF=new WeakMap;function ui(e){if(e.batteryModel)return e.batteryModel;let t=e.capacity.value,r=e.ocv.value,n=mF.get(e);if(n&&n.capacityAh===t&&n.ocv===r)return n.model;let o=Bh(t,r);return mF.set(e,{capacityAh:t,ocv:r,model:o}),o}function fF(e){let t=e.params,r=l0(t,fd(e));if(yt(t.motorModel)||Wt(t).mode!=="hydraulic")return r;let n;return(o,a,s,i=0)=>{if(!(o>0))return t3;n??=r3(e);let c=vd(n.inp,n.ev,o,a,i);if(!c)return r(o,a,s);let l=c.regenFront+c.regenRear,u=Math.min(o,l),m=l>0?u/l:0;return{front:c.regenFront*m,rear:c.regenRear*m,total:u}}}function hF(e){let t=fF(e);return(r,n,o,a)=>t(r,n,o,a).total}var t3={front:0,rear:0,total:0},dF=new WeakMap;function r3(e){let t=e.params,r=dF.get(t);if(!r){let n=Gn(t);r={inp:Ut(n.regen?t:{...t,energy:{...n,regen:!0}}),ev:pn(t)},dF.set(t,r)}return r}var Tl=e=>e.airTempC??ur;function ip(e,t){return e.thermal?e.thermal.startC??t:ps}function pF(e,t,r,n,o,a){let s=e.thermal;if(!s||!(o>0)||!(s.heatCapacityJPerK>0))return t;let i=s.coolingWPerK*(t-a)*o,c=s.entropicVPerK!==0?-r*(t+273.15)*s.entropicVPerK*o:0;return t+(n+c-i)/s.heatCapacityJPerK}var bF=()=>({windingC:[],derate:[],lossW:[],torqueNm:[],ampsRms:[]});function n3(e){let t=e.motorModel;if(yt(t))return;let r=t?Qi(t).maxTorque:s=>ot(e.motor.rpm,e.motor.torque,s),n=e.gear_ratio.value,o=e.r_dyn.value,a=Math.max(1,Math.round(e.motorCount??e.driven_wheels.value));return{rpm:s=>s*n/o*(60/uy),peak:r,torque:(s,i,c)=>{let l=Math.min(Math.abs(s)*o/(n*a),c*r(i));return s<0?-l:l}}}function o3(e,t){let r=e.motorModel?.thermal;if(!r||!t)return;let n=r.torqueConstant;return{...t,th:$h(r),amps:o=>n>0?Math.abs(o)/n:0}}function a3(e,t,r,n,o){let a=e.ocv(n);if(!(r>0))return{dq:t/a,lossJ:0,energyJ:t,short:!1,cutoff:!1,seconds:r};let s=e.maxPower(n,o),i=s.watts,c=t/r,l=Math.min(c,i),u=c>s.voltageFloor;if(u&&!(l>0))return{dq:1/0,lossJ:0,energyJ:0,short:!0,cutoff:u,seconds:1/0};let m=e.currentFor(l,n,o),p=u?c/l:1,d=r*p;return{dq:m*d,lossJ:m*m*e.resistance(n,o)*d,energyJ:l*d,short:c>i,cutoff:u,seconds:d}}function s3(e,t,r,n,o){let a=e.ocv(n);if(!(r>0))return{dq:t/a,lossJ:0,energyJ:t,short:!1,cutoff:!1,seconds:r};let s=e.resistance(n,o),i=e.chargeCurrentFor(t/r,n,o),c=Math.min(i,e.chargeCurrentCeiling),l=c===i?t:c*(a+c*s)*r;return{dq:c*r,lossJ:c*c*s*r,energyJ:l,short:c<i,cutoff:!1,seconds:r}}function i3(e,t,r,n,o){let a=e.resistance(n,o);return{energyJ:t*(e.ocv(n)+t*a)*r,lossJ:t*t*a*r}}function c3(e){let{drivenFront:t,drivenRear:r}=Ma(e);return ka(e.params,t,r)}function mi(e,t,r,n,o=Kr,a,s,i,c,l,u){let m=e.params,p=m.rho.value,d=m.fr_0.value,f=m.m.value,h=e.FG,b=m.aeroModel?Ut(m):void 0,g=sp(m),y=Cn(ui(m)),x=y.chargeC,R=m.motorModel?.kind==="ice",v=ly(a??(R?1:m.soc.value)),S=Tl(m),A=s??ip(y,S),C=A,F=0,T=0,M=0,k=0,w=-1,P=-1,L=-1,E=i||m.motorModel?.thermal?n3(m):void 0,_=o3(m,E),D=_?_.th.startC:0,I=D,N=0,O=1,V=-1,H=0,U=0,G=fF(e),B=e3(m),q=dr(m),re=u?.scrub,W=c3(e),z=re?f/W.tractionFactor:0,Y=W.effective-f,te=Math.min(t.length,r.length);for(let j=0;j<te;j++){let X=r[j],le=X*X,pe=n[j]-(c?.[j]??0),{cl:ue,cw:ie,A:ke}=ep(m,X,pe/9.81,b),Ie=.5*p*ue*ke*le,Ke=.5*p*ie*ke*le,oe=(h+Ie)*-d,se=re?-z*(re[j]??0):0,xe=oe+Ke+se+f*pe;Y>0&&(xe+=Y*n[j]);let fe=xe*t[j];l?.driveN?.push(xe>0?xe:0);let Fe=j+1<r.length?r[j+1]:X,Re=.5*(X+Fe),ae=Re>0?t[j]/Re:0,Me=0,be=v,ge=A,ye=0,ce=0,Ae=ae;if(R){xe>0&&(ce=fe/g(X,xe),F+=ce/Cl),l?.netKwh.push(F-T),l?.powerKw?.push(ae>0?ce/ae/1e3:0);continue}if(xe>0){let Se=fe/g(X,xe),ve=a3(y,Se,ae,v,A);ve.short&&w<0&&(w=j),ve.cutoff&&P<0&&(P=j);let wt=v*x,qe=Math.min(ve.dq,wt),It=ve.dq>0?qe/ve.dq:1;qe>=wt&&L<0&&(L=j),F+=ve.energyJ*It/Cl,ce=ve.energyJ*It,Ae=ve.seconds,M+=ve.lossJ*It,k+=qe,ae>0&&(ye=qe/ve.seconds),v=ly(v-qe/x),A=pF(y,A,ve.dq>0&&ae>0?qe/ae:0,ve.lossJ*It,ae,S),A>C&&(C=A),Me=xe}else if(o.regen){let Se=u?mt(u.ay[j],u.bank?.[j]??0)/9.81:0,ve=G(-xe,X,pe/9.81,Se),wt=ve.total,It=(B(X,ve.front,q.front)*ve.front+B(X,ve.rear,q.rear)*ve.rear)*t[j],Pe=s3(y,It,ae,v,A),_e=(1-v)*x,He=Math.min(Pe.dq,_e),Ee=Pe.dq>0?He/Pe.dq:1,ze=He<Pe.dq&&ae>0?i3(y,He/ae,ae,v,A):void 0,qt=ze?ze.energyJ:Pe.energyJ*Ee,Ft=ze?ze.lossJ:Pe.lossJ*Ee;T+=qt/Cl,ce=-qt,M+=Ft,k-=He,ae>0&&(ye=-He/ae),v=ly(v+He/x),A=pF(y,A,He>0&&ae>0?-He/ae:0,Ft,ae,S),A>C&&(C=A),Me=-wt*Ee}if(l?.netKwh.push(F-T),l?.powerKw?.push(ae>0?ce/Ae/1e3:0),l?.pack){let Se=l.pack;Se.soc.push(be),Se.amps.push(ye),Se.volts.push(y.ocv(be)-ye*y.resistance(be,ge)),Se.cellC.push(ge)}if(_){let Se=_.rpm(X),ve=_.th.derate(Se,D,_.peak(Se));ve<O&&(O=ve),ve<1&&V<0&&(V=j),U+=ae,ve<1&&(H+=ae);let wt=_.torque(Me,Se,ve),qe=_.th.lossW(Se,wt,D);N+=qe*ae,i&&(i.windingC.push(D),i.derate.push(ve),i.lossW.push(qe),i.torqueNm.push(wt),i.ampsRms.push(_.amps(wt))),D=_.th.step(D,qe,ae),D>I&&(I=D)}else E&&i&&i.torqueNm.push(E.torque(Me,E.rpm(X),1))}return{drive:F,regen:T,net:F-T,chargeAh:k/3600,loss:M/Cl,socEnd:v,shortAt:w,cutoffAt:P,emptyAt:L,tempEndC:A,tempMaxC:C,..._?{motorTempEndC:D,motorTempMaxC:I,motorLossKwh:N/Cl,motorDerateMin:O,motorDerateAt:V,motorDerateTimeFrac:U>0?H/U:0}:{}}}var l3=.5,u3=.02,m3=6;function gF(e,t,r,n,o,a,s,i){let c=n(),l=1,u=f=>{let h=bF(),b=mi(e,t,f.v,f.ax,r,o,a,h,s,void 0,{ay:f.ay,bank:i,...f.axScrub?{scrub:f.axScrub}:{}});return{trace:h,peak:b.motorTempMaxC??0,frac:b.motorDerateTimeFrac??0}},m=u(c);if(!m.trace.derate.length||m.frac===0)return{lap:c,solves:l,converged:!0,peakWindingC:m.peak,derateTimeFrac:m.frac};let p=m.trace.derate.slice(),d=!1;for(let f=0;f<m3;f++){let h=n(p);l++;let b=Math.abs(h.laptime-c.laptime);if(c=h,m=u(c),b<u3){d=!0;break}let g=m.trace.derate,y=new Array(p.length);for(let x=0;x<p.length;x++)y[x]=p[x]+l3*((g[x]??1)-p[x]);p=y}return{lap:c,derate:p,solves:l,converged:d,peakWindingC:m.peak,derateTimeFrac:m.frac}}var d3=.1;function yF(e){if(e.motorModel?.kind==="ice")return 0;let t=e.power_limit_kw?.value??0;return t>0?t*1e3:0}function my(e,t,r){return e.motorModel?.kind==="ice"?1/0:Cn(ui(e)).maxPower(t??e.soc.value,r,yF(e)).watts}function cp(e,t,r,n){let o=my(e,r,n);if(!Number.isFinite(o))return 1/0;if(o<=0)return 0;let a=Math.max(d3,t),s=sp(e),i=o*.9/a;return o*s(t,i)/a}var p3=180/Math.PI;function lp(e,t,r,n){let o=e*t,a=e*(1-t);return o/r-a/n}var up=e=>e*9.81*p3;var f3=.1*9.81;var Jne=Math.PI/180;function mp(e,t,r,n=0){let o=Xe(e,t,0,n),a=typeof r=="function"?r:r.front,s=typeof r=="function"?r:r.rear,i=.5*(a(Math.max(0,o.FL))+a(Math.max(0,o.FR))),c=.5*(s(Math.max(0,o.RL))+s(Math.max(0,o.RR))),l=i>0&&c>0?lp(e.massTotal,e.frontMassFrac,2*i,2*c):0,u=up(l),m=u>.15?"understeer":u<-.15?"oversteer":"neutral";return{gradient:u,balance:m,cAlphaFront:i,cAlphaRear:c}}var ioe=Math.PI/180,coe=180/Math.PI;var xF=2220446049250313e-31;function g3(e){let t=e.length,r=2,n=r*r,o=!1;for(;!o;){o=!0;for(let a=0;a<t;a++){let s=0,i=0;for(let c=0;c<t;c++)c!==a&&(i+=Math.abs(e[c][a]),s+=Math.abs(e[a][c]));if(i!==0&&s!==0){let c=s/r,l=1,u=i+s;for(;i<c;)l*=r,i*=n;for(c=s*r;i>c;)l/=r,i/=n;if((i+s)/l<.95*u){o=!1;let m=1/l;for(let p=0;p<t;p++)e[a][p]*=m;for(let p=0;p<t;p++)e[p][a]*=l}}}}}function y3(e){let t=e.length;for(let r=1;r<t-1;r++){let n=0,o=r;for(let a=r;a<t;a++)Math.abs(e[a][r-1])>Math.abs(n)&&(n=e[a][r-1],o=a);if(o!==r){for(let a=r-1;a<t;a++){let s=e[o][a];e[o][a]=e[r][a],e[r][a]=s}for(let a=0;a<t;a++){let s=e[a][o];e[a][o]=e[a][r],e[a][r]=s}}if(n!==0)for(let a=r+1;a<t;a++){let s=e[a][r-1];if(s!==0){s/=n,e[a][r-1]=s;for(let i=r;i<t;i++)e[a][i]-=s*e[r][i];for(let i=0;i<t;i++)e[i][r]+=s*e[i][a]}}}for(let r=2;r<t;r++)for(let n=0;n<r-1;n++)e[r][n]=0}function x3(e){let t=e.length,r=new Array(t).fill(0),n=new Array(t).fill(0),o=0;for(let i=0;i<t;i++)for(let c=Math.max(i-1,0);c<t;c++)o+=Math.abs(e[i][c]);let a=t-1,s=0;for(;a>=0;){let i=0,c=0;do{for(c=a;c>=1;c--){let u=Math.abs(e[c-1][c-1])+Math.abs(e[c][c]);if(u===0&&(u=o),Math.abs(e[c][c-1])<=xF*u){e[c][c-1]=0;break}}let l=e[a][a];if(c===a)r[a]=l+s,n[a]=0,a--;else{let u=e[a-1][a-1],m=e[a][a-1]*e[a-1][a];if(c===a-1){let p=.5*(u-l),d=p*p+m,f=Math.sqrt(Math.abs(d));l+=s,d>=0?(f=p+(p>=0?Math.abs(f):-Math.abs(f)),r[a-1]=r[a]=l+f,f!==0&&(r[a]=l-m/f),n[a-1]=n[a]=0):(r[a-1]=r[a]=l+p,n[a]=f,n[a-1]=-f),a-=2}else{if(i===60)throw new Error("eigenvalues: QR iteration did not converge");if(i===10||i===20||i===30||i===40||i===50){s+=l;for(let g=0;g<=a;g++)e[g][g]-=l;let b=Math.abs(e[a][a-1])+Math.abs(e[a-1][a-2]);u=l=.75*b,m=-.4375*b*b}i++;let p=a-2,d=0,f=0,h=0;for(;p>=c;p--){let b=e[p][p],g=l-b,y=u-b;d=(g*y-m)/e[p+1][p]+e[p][p+1],f=e[p+1][p+1]-b-g-y,h=e[p+2][p+1];let x=Math.abs(d)+Math.abs(f)+Math.abs(h);if(d/=x,f/=x,h/=x,p===c)break;let R=Math.abs(e[p][p-1])*(Math.abs(f)+Math.abs(h)),v=Math.abs(d)*(Math.abs(e[p-1][p-1])+Math.abs(b)+Math.abs(e[p+1][p+1]));if(R<=xF*v)break}for(let b=p+2;b<=a;b++)e[b][b-2]=0,b!==p+2&&(e[b][b-3]=0);for(let b=p;b<=a-1;b++){b!==p&&(d=e[b][b-1],f=e[b+1][b-1],h=b!==a-1?e[b+2][b-1]:0,l=Math.abs(d)+Math.abs(f)+Math.abs(h),l!==0&&(d/=l,f/=l,h/=l));let g=Math.sqrt(d*d+f*f+h*h),y=d>=0?g:-g;if(y!==0){b===p?c!==p&&(e[b][b-1]=-e[b][b-1]):e[b][b-1]=-y*l,d+=y,l=d/y,u=f/y;let x=h/y;f/=d,h/=d;for(let v=b;v<=a;v++){let S=e[b][v]+f*e[b+1][v];b!==a-1&&(S+=h*e[b+2][v],e[b+2][v]-=S*x),e[b+1][v]-=S*u,e[b][v]-=S*l}let R=a<b+3?a:b+3;for(let v=c;v<=R;v++){let S=l*e[v][b]+u*e[v][b+1];b!==a-1&&(S+=x*e[v][b+2],e[v][b+2]-=S*h),e[v][b+1]-=S*f,e[v][b]-=S}}}}}}while(c<a-1&&a>=0)}return r.map((i,c)=>({re:i,im:n[c]}))}function RF(e){let t=e.length;if(t===0)return[];for(let n of e)if(n.length!==t)throw new Error("eigenvalues: matrix must be square");for(let n of e)for(let o of n)if(!Number.isFinite(o))throw new Error("eigenvalues: matrix has non-finite entries");if(t===1)return[{re:e[0][0],im:0}];let r=e.map(n=>n.slice());return g3(r),y3(r),x3(r)}function vF(e){let t=[],r=new Array(e.length).fill(!1),n=RF(e);for(let o=0;o<n.length;o++){if(r[o])continue;let{re:a,im:s}=n[o];if(s<0)continue;let i=Math.hypot(a,s);t.push({freq:i/(2*Math.PI),dampedFreq:Math.abs(s)/(2*Math.PI),dampingRatio:i>0?-a/i:0,eigenvalue:n[o]})}return t.sort((o,a)=>a.freq-o.freq)}function dy(e,t){let r=e.length,n=Array.from({length:r},(c,l)=>l);for(let c=0;c<r-1;c++){let l=c,u=c,m=-1;for(let h=c;h<r;h++)for(let b=c;b<r;b++){let g=e[h][b]*e[h][b]+t[h][b]*t[h][b];g>m&&(m=g,l=h,u=b)}if(!(m>0))break;if([e[c],e[l]]=[e[l],e[c]],[t[c],t[l]]=[t[l],t[c]],u!==c){for(let h=0;h<r;h++)[e[h][c],e[h][u]]=[e[h][u],e[h][c]],[t[h][c],t[h][u]]=[t[h][u],t[h][c]];[n[c],n[u]]=[n[u],n[c]]}let p=e[c][c],d=t[c][c],f=p*p+d*d;for(let h=c+1;h<r;h++){let b=(e[h][c]*p+t[h][c]*d)/f,g=(t[h][c]*p-e[h][c]*d)/f;if(!(b===0&&g===0))for(let y=c;y<r;y++)e[h][y]-=b*e[c][y]-g*t[c][y],t[h][y]-=b*t[c][y]+g*e[c][y]}}let o=new Array(r).fill(0),a=new Array(r).fill(0);o[r-1]=1;for(let c=r-2;c>=0;c--){let l=e[c][c],u=t[c][c],m=l*l+u*u;if(!(m>0))continue;let p=0,d=0;for(let f=c+1;f<r;f++)p+=e[c][f]*o[f]-t[c][f]*a[f],d+=e[c][f]*a[f]+t[c][f]*o[f];o[c]=-(p*l+d*u)/m,a[c]=-(d*l-p*u)/m}let s=Math.sqrt(o.reduce((c,l,u)=>c+l*l+a[u]*a[u],0)),i=new Array(r);for(let c=0;c<r;c++)i[n[c]]={re:o[c]/s,im:a[c]/s};return i}function R3(e,t){let r=e.map((o,a)=>o.map((s,i)=>a===i?s-t.re:s)),n=e.map((o,a)=>o.map((s,i)=>a===i?-t.im:0));return dy(r,n)}function dp(e,t=r=>R3(e,r)){return vF(e).map(r=>({...r,vector:t(r.eigenvalue)}))}function Sa(e,t,r){let n,o=-1,a,s=-1;for(let i of e){let c=t(i.vector),l=c[r];i.eigenvalue.im===0?l>s&&(a=i,s=l):l>=Math.max(...c)&&l>o&&(n=i,o=l)}return n??a}function py(e){let t=e.sprungMass;if(!(t>0))return;let r=Math.max(.1,e.unsprungMass),n=e.springRate*1e3,o=e.damperRate*1e3,a=e.tireRate*1e3,s=(e.tireDamping??0)*1e3,i=[[0,1,0,0],[-n/t,-o/t,n/t,o/t],[0,0,0,1],[n/r,o/r,-(n+a)/r,-(o+s)/r]];if(!i.every(l=>l.every(Number.isFinite)))return;let c=l=>{let u=t*(l[0].re**2+l[0].im**2),m=r*(l[2].re**2+l[2].im**2);return u+m>0?[u/(u+m),m/(u+m)]:[0,0]};return Sa(dp(i),c,0)}function MF(e,t,r,n){return{sprungMass:(r==="front"?t.sprungFront:t.sprungRear)/2,unsprungMass:e.unsprungCornerMass??e.unsprungPerCorner,springRate:r==="front"?e.wheelRateFront+(e.heaveSpringFront??0):e.wheelRateRear+(e.heaveSpringRear??0),damperRate:n,tireRate:xt(e,r),tireDamping:e.tireDamping}}function kF(e,t,r,n){let o=MF(e,t,r,n),a=o.sprungMass;if(a<=0)return{dampingRatio:0,criticalDamping:0,naturalFreqDamped:0};let s=r==="front"?t.rideRateFront:t.rideRateRear,i=py(o),c=2*Math.sqrt(s*1e3*a);return{dampingRatio:i?.dampingRatio??0,criticalDamping:c/1e3,naturalFreqDamped:i?.dampedFreq??0}}function pp(e,t,r){let n=Ge(e);return{front:kF(e,n,"front",t??n.rideDampingFront),rear:kF(e,n,"rear",r??n.rideDampingRear)}}var voe=180/Math.PI;var fy=["FL","FR","RL","RR"];function v3(e,t){let r=e.chassisTorsion??0;if(!(r>0)||!Number.isFinite(r))return;let n=Math.max(0,Math.min(1,e.frontMassFrac));return{stiffness:r*(180/Math.PI),inertiaFront:e.twistInertiaFront??n*t,inertiaRear:e.twistInertiaRear??(1-n)*t,massFront:n}}function k3(e){let t=e.chassis;if(!t||!(t.stiffness>0)||!(t.inertiaFront>0)||!(t.inertiaRear>0))return;let r=t.inertiaFront+t.inertiaRear,n=t.inertiaRear/r,o=-t.inertiaFront/r;return{share:[n,n,o,o],inertia:t.inertiaFront*t.inertiaRear/r,stiffness:t.stiffness,moment:t.massFront*n+(1-t.massFront)*o}}var de={zFL:0,vzFL:1,zFR:2,vzFR:3,zRL:4,vzRL:5,zRR:6,vzRR:7,zBody:8,vzBody:9,pitch:10,pitchRate:11,roll:12,rollRate:13,x:14,vx:15,y:16,vy:17,yaw:18,yawRate:19,twist:20,twistRate:21},fp=20,SF=[de.zFL,de.zFR,de.zRL,de.zRR],AF=[de.vzFL,de.vzFR,de.vzRL,de.vzRR],fn={fzFL:0,fzFR:1,fzRL:2,fzRR:3,fzBody:4,myBody:5,mxBody:6,fx:7,fy:8,mz:9},hy=10;function di(e){let t=k3(e),r=t?fp+2:fp,n=Array.from({length:r},()=>new Array(r).fill(0)),o=Array.from({length:r},()=>new Array(hy).fill(0));n[de.zFL][de.vzFL]=1,n[de.zFR][de.vzFR]=1,n[de.zRL][de.vzRL]=1,n[de.zRR][de.vzRR]=1,n[de.zBody][de.vzBody]=1,n[de.pitch][de.pitchRate]=1,n[de.roll][de.rollRate]=1,n[de.x][de.vx]=1,n[de.y][de.vy]=1,n[de.yaw][de.yawRate]=1;let{inertia:a}=e,s=[1,0,3,2],i=(c,l,u,m)=>{c[SF[l]]-=u,c[AF[l]]-=m,c[de.zBody]+=u,c[de.vzBody]+=m,c[de.pitch]-=u*e.leverX[l],c[de.pitchRate]-=m*e.leverX[l],c[de.roll]+=u*e.leverY[l],c[de.rollRate]+=m*e.leverY[l],t&&(c[de.twist]+=u*e.leverY[l]*t.share[l],c[de.twistRate]+=m*e.leverY[l]*t.share[l])};for(let c=0;c<4;c++){let l=c<2,u=F=>F?l?F.front:F.rear:0,m=e.springRate[c]+u(e.heaveSpring),p=e.springRate[c]+u(e.arb),d=e.damperRate[c]+u(e.heaveDamper),f=e.damperRate[c]+u(e.rollDamper),h=(m+p)/2,b=(m-p)/2,g=(d+f)/2,y=(d-f)/2,x=new Array(r).fill(0);i(x,c,h,g),(b!==0||y!==0)&&i(x,s[c],b,y);let R=e.wheelMass[c],v=e.leverX[c],S=e.leverY[c],A=SF[c],C=AF[c];for(let F=0;F<r;F++){let T=x[F];T!==0&&(n[C][F]+=T/R,n[de.vzBody][F]-=T/e.bodyMass,n[de.pitchRate][F]+=v*T/a.yy,n[de.rollRate][F]-=S*T/a.xx,t&&(n[de.twistRate][F]-=S*t.share[c]*T/t.inertia))}n[C][A]-=e.tyreRate[c]/R,n[C][C]-=e.tyreDamping[c]/R,o[C][fn.fzFL+c]=1/R}return o[de.vzBody][fn.fzBody]=1/e.bodyMass,o[de.pitchRate][fn.myBody]=1/a.yy,o[de.rollRate][fn.mxBody]=1/a.xx,o[de.vx][fn.fx]=1/e.totalMass,o[de.vy][fn.fy]=1/e.totalMass,o[de.yawRate][fn.mz]=1/a.zz,t?(n[de.twist][de.twistRate]=1,n[de.twistRate][de.twist]-=t.stiffness/t.inertia,o[de.twistRate][fn.mxBody]=t.moment/t.inertia,{A:n,B:o,params:e,n:r,twist:t}):{A:n,B:o,params:e,n:r}}function Pl(e){let t=e.wheelbase/1e3,r=t*(1-e.frontMassFrac),n=t*e.frontMassFrac,o=e.trackFront/2e3,a=e.trackRear/2e3,s=e.unsprungCornerMass??e.unsprungPerCorner,i=Math.max(0,e.massTotal-4*s),c=e.wheelRateFront*1e3,l=e.wheelRateRear*1e3,u=(e.damperFront??2.5)*1e3,m=(e.damperRear??2.5)*1e3,p=xt(e,"front")*1e3,d=xt(e,"rear")*1e3,f=(e.tireDamping??0)*1e3,h=e.rollInertia??i*.6*.6,b=v3(e,h);return{bodyMass:i,totalMass:e.massTotal,wheelMass:[s,s,s,s],inertia:{xx:h,yy:e.pitchInertia??i*1.2*1.2,zz:e.yawInertia??e.massTotal*1.2*1.2},...b?{chassis:b}:{},leverX:[r,r,-n,-n],leverY:[o,-o,a,-a],springRate:[c,c,l,l],damperRate:[u,u,m,m],tyreRate:[p,p,d,d],tyreDamping:[f,f,f,f],arb:{front:e.arbFront*1e3,rear:e.arbRear*1e3},heaveSpring:{front:(e.heaveSpringFront??0)*1e3,rear:(e.heaveSpringRear??0)*1e3},rollDamper:{front:(e.rollDamperFront??0)*1e3,rear:(e.rollDamperRear??0)*1e3},heaveDamper:{front:(e.heaveDamperFront??0)*1e3,rear:(e.heaveDamperRear??0)*1e3}}}function wF(e){let t=Array.from({length:de.rollRate+1},(r,n)=>n);return e.twist?[...t,de.twist,de.twistRate]:t}function hp(e){let t=e.params,r=e.twist,n=[...t.wheelMass,t.bodyMass,t.inertia.yy,t.inertia.xx,...r?[r.inertia]:[]];if(!n.every(u=>u>0))return{};let o=wF(e),a=o.map(u=>o.map(m=>e.A[u][m]));if(!a.every(u=>u.every(Number.isFinite)))return{};let i=dp(a,u=>{let m=u.re*u.re-u.im*u.im,p=2*u.re*u.im,d=n.map((h,b)=>n.map((g,y)=>(b===y?m:0)-u.re*a[2*b+1][2*y+1]-a[2*b+1][2*y])),f=n.map((h,b)=>n.map((g,y)=>(b===y?p:0)-u.im*a[2*b+1][2*y+1]));return dy(d,f)}),c=u=>{let m=n.map((d,f)=>d*(u[f].re**2+u[f].im**2)),p=m.reduce((d,f)=>d+f,0)||1;return[m[0]+m[1]+m[2]+m[3],m[4],m[5],m[6],...r?[m[7]]:[]].map(d=>d/p)},l={heave:Sa(i,c,1),pitch:Sa(i,c,2),roll:Sa(i,c,3)};return r?{...l,twist:Sa(i,c,4)}:l}function M3(e){let t={value:0,enumerable:!0};return Object.create(e,{damperFront:t,damperRear:t,heaveDamperFront:t,heaveDamperRear:t,rollDamperFront:t,rollDamperRear:t,tireDamping:t})}var S3=e=>hp(di(Pl(e))),by=e=>e&&e.dampedFreq>0?e.freq:NaN;function gy(e){let t=S3(M3(e));return{heave:by(t.heave),pitch:by(t.pitch),roll:by(t.roll)}}var TF=Math.SQRT2;function FF(e,t,r){let n=e?2*Math.PI*e.freq:0,o=e&&n>0?e.dampingRatio:0,a=o>0&&o<1?Math.exp(-Math.PI*o/Math.sqrt(1-o*o))*100:0,s=o>0&&n>0?4/(o*n):1/0;return{freq:n/(2*Math.PI),dampedFreq:e&&n>0?e.dampedFreq:0,dampingRatio:o,stiffness:t,inertia:r,overshoot:a,settlingTime:s}}function bp(e){let t=Ge(e),r=e.wheelbase/1e3,n=r*(1-e.frontMassFrac),o=r*e.frontMassFrac,a=t.rollRateTotal*(180/Math.PI),s=e.rollInertia??t.sprungMass*.6*.6,i=2*t.rideRateFront*1e3,c=2*t.rideRateRear*1e3,l=i*n*n+c*o*o,u=e.pitchInertia??t.sprungMass*1.2*1.2,m=di(Pl(e)),p=hp(m),d={roll:FF(p.roll,a,s),pitch:FF(p.pitch,l,u)},f=A3(m,p.twist,e);return f?{...d,twist:f}:d}function CF(e,t,r){let n=e.params,o=n.tyreRate[t]+n.springRate[t]+r;return Math.sqrt(Math.max(0,o)/n.wheelMass[t])/(2*Math.PI)}function A3(e,t,r){let n=e.twist;if(!n||!t)return;let o=CF(e,0,e.params.arb?.front??0),a=CF(e,2,e.params.arb?.rear??0),s=Math.max(o,a),i=s>0?t.freq/s:NaN;return{freq:t.freq,dampingRatio:t.dampingRatio,freeFree:Math.sqrt(n.stiffness/n.inertia)/(2*Math.PI),hopFront:o,hopRear:a,hop:s,ratio:i,meets:i>=TF,lumped:r.twistInertiaFront===void 0||r.twistInertiaRear===void 0}}var gp=9.81,Jn=Math.PI/180;function PF(e){let t=e.wheelbase/1e3,r=t*(1-e.frontMassFrac),n=t*e.frontMassFrac;return{wb:t,lf:r,lr:n,m:e.massTotal}}function pi(e,t,r,n,o){let{wb:a,lf:s,lr:i,m:c}=PF(e),l=0;for(let x=0;x<16;x++){let R=l/r,v=o-n-s*R/r,S=-n+i*R/r,A=Xe(e,l/gp,0,r),C=Math.max(0,A.FL+A.FR),F=Math.max(0,A.RL+A.RR),T=t(v,C),M=t(S,F),k=(T*Math.cos(o)+M)/c;if(l=.5*(l+k),Math.abs(k-l)<1e-4)break}let u=l/r,m=o-n-s*u/r,p=-n+i*u/r,d=Xe(e,l/gp,0,r),f=Math.max(0,d.FL+d.FR),h=Math.max(0,d.RL+d.RR),b=t(m,f),g=t(p,h),y=s*b*Math.cos(o)-i*g;return{ay:l/gp,cn:y/(c*gp*a)}}function yy(e,t,r,n={}){let o=Math.max(8,r),a=(n.betaMaxDeg??10)*Jn,s=(n.deltaMaxDeg??10)*Jn,i=n.nLines??9,c=n.nPts??21,l=(g,y,x,R)=>x===1?g:g+(y-g)*R/(x-1),u=[],m={ay:[],cn:[]},p=0;for(let g=0;g<i;g++){let y=l(-s,s,i,g),x=[],R=[],v=[],S=[];for(let A=0;A<c;A++){let C=l(-a,a,c,A),F=pi(e,t,o,C,y);x.push(F.ay),R.push(F.cn),v.push(C/Jn),S.push(y/Jn),Math.abs(F.ay)>p&&(p=Math.abs(F.ay))}u.push({label:`\u03B4 ${(y/Jn).toFixed(0)}\xB0`,ay:x,cn:R,betaDeg:v,deltaDeg:S});for(let A=1;A<R.length;A++)if(R[A-1]===0||R[A-1]<0!=R[A]<0){let C=R[A-1]===R[A]?0:R[A-1]/(R[A-1]-R[A]);m.ay.push(x[A-1]+C*(x[A]-x[A-1])),m.cn.push(0);break}}let d=[];for(let g=0;g<i;g++){let y=l(-a,a,i,g),x=[],R=[],v=[],S=[];for(let A=0;A<c;A++){let C=l(-s,s,c,A),F=pi(e,t,o,y,C);x.push(F.ay),R.push(F.cn),v.push(y/Jn),S.push(C/Jn)}d.push({label:`\u03B2 ${(y/Jn).toFixed(0)}\xB0`,ay:x,cn:R,betaDeg:v,deltaDeg:S})}let f=.5*Jn,h=(pi(e,t,o,f,0).cn-pi(e,t,o,-f,0).cn)/(2*f),b=(pi(e,t,o,0,f).cn-pi(e,t,o,0,-f).cn)/(2*f);return{isoBeta:d,isoDelta:u,trim:m,maxAy:p,stability:h,control:b,speed:o}}function w3(e){return!e.corneringStiffnessFront||!e.corneringStiffnessRear?null:{Cf:2*e.corneringStiffnessFront,Cr:2*e.corneringStiffnessRear}}function Ll(e,t){let r=w3(e);if(!r)return null;let{Cf:n,Cr:o}=r,{wb:a,lf:s,lr:i,m:c}=PF(e),l=e.yawInertia??c*1*1,u=Math.max(3,t),m=-(n+o)/(c*u),p=(-s*n+i*o)/(c*u)-u,d=(-s*n+i*o)/(l*u),f=-(s*s*n+i*i*o)/(l*u),h=m+f,b=m*f-p*d,g=h*h-4*b,y,x,R;if(g<0)y=h/2,x=Math.sqrt(Math.max(0,b)),R=x>0?-h/(2*x):1;else{let P=Math.sqrt(g);y=Math.max((h+P)/2,(h-P)/2),x=Math.sqrt(Math.abs(b)),R=x>0?-h/(2*x):1}let v=h<0&&b>0,S=lp(c,e.frontMassFrac,n,o),A=up(S),C=A>.15?"understeer":A<-.15?"oversteer":"neutral",F=s*n-i*o,T=P=>P*3.6,M=null,k=null;F>1e-6?k=T(Math.sqrt(n*o*a*a/(c*F))):F<-1e-6&&(M=T(Math.sqrt(n*o*a*a/(c*-F))));let w=u/(a+S*u*u);return{stable:v,yawFreq:x/(2*Math.PI),dampingRatio:R,eigReal:y,understeerGradient:A,balance:C,characteristicSpeed:M,criticalSpeed:k,yawRateGain:w}}var F3={envelopeTrim:{name:"Grip envelope, trim",code:"`solvePoint` in src/core/dynamics/twoTrack.ts (`twoTrackLimitState`, `twoTrackStateAtAy`)"},envelopeLimits:{name:"Grip envelope, limits",code:"`calcGGV` in src/core/laptime/ggv.ts"},qssLap:{name:"QSS lap",code:"`solveLap` in src/core/laptime/solver.ts, with its energy (`energyOverPath`)"},tyreReadouts:{name:"Tyre readouts",code:"`lapReserves` in src/core/dynamics/lapReserve.ts"},transientPlant:{name:"Transient plant",code:"`dynamicReplay` in src/core/dynamics/dynamicReplay.ts"},plannerRequest:{name:"Optimal, the request",code:"`planCarFrom` in src/core/plan/request.ts"},ymd:{name:"Yaw moment diagram",code:"`twoTrackYMD` in src/core/dynamics/twoTrack.ts"},stepSteer:{name:"Step steer",code:"`steerRun` in src/core/dynamics/steerRun.ts"},drive:{name:"Drive",code:"`liveCar` in src/core/drive/liveCar.ts"}},xy=Object.keys(F3),Dl=["envelopeTrim","envelopeLimits","qssLap","tyreReadouts","ymd"];var C3="the longitudinal condition is set directly; what a motor could deliver is the lap solver\u2019s question",T3="no tractive force is applied at a constant speed",Ry="runs a torque-vectoring controller only when the caller hands one in (`DynamicReplayOptions.vectoring`, `SteerRunOptions.vectoring`), as the app does (`lapVectoringFor`, `steerVectoringFor` in src/app/dynamics/tvCore.ts)",vy="Drive runs no torque vectoring: its aids are ABS and traction control",LF="the readouts split the drive by room or through the diff, never by a controller",P3=[{key:"damper_front",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"damper_rear",tools:["ymd"],why:"dampers act on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",tools:Dl,why:"tyre damping acts on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic (reduced planner model)"},{key:"I_yaw",tools:["envelopeTrim","envelopeLimits","tyreReadouts","ymd"],why:"inertia resists change; a steady corner has none"},{key:"I_yaw",tools:["qssLap"],why:"inertia resists change; a steady corner has none. The quasi-transient option charges it (`calcGgvFamily`)",onCar:"quasi-transient off, as in the templates"},{key:"I_roll",tools:Dl,why:"inertia resists change; a steady corner has none"},{key:"I_roll",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no roll dynamics (reduced planner model)"},{key:"I_pitch",tools:Dl,why:"inertia resists change; a steady corner has none"},{key:"I_pitch",tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no pitch dynamics (reduced planner model)"},...["I_twist_front","I_twist_rear"].flatMap(e=>[{key:e,tools:Dl,why:"inertia resists change; a steady corner has none"},{key:e,tools:["plannerRequest"],why:"the planner\u2019s wheel loads are algebraic: no twist dynamics (reduced planner model)"}]),...["capacity","ocv","soc"].flatMap(e=>[{key:e,tools:["ymd"],why:"energy does not enter a single steady-state point"},{key:e,tools:xy.filter(t=>t!=="ymd"&&t!=="qssLap"),why:"the charge reaches the forces only through a battery model\u2019s power ceiling (`packPowerW`); without one it is counted by the QSS lap\u2019s energy account, and drawn on nowhere",onCar:"no battery model"}]),{key:"tv_kp",tools:Dl,why:"the feedback gain multiplies a yaw error, and a trimmed point has none \u2014 the feedforward does move this diagram"},{key:"tv_kp",tools:["transientPlant","stepSteer"],why:Ry},{key:"tv_kp",tools:["plannerRequest"],why:"the planner reads only whether torque vectoring is on, for its allocation (`longitudinalAllocation`)"},{key:"tv_kp",tools:["drive"],why:vy},{key:"tv_enabled",tools:["transientPlant","stepSteer"],why:Ry},{key:"tv_enabled",tools:["drive"],why:vy},{key:"tv_enabled",tools:["tyreReadouts"],why:LF,gap:"the envelope corners with the feedforward, the readouts split the same lap without it (rule 3)"},...["tv_ff_low","tv_ff_high","tv_v_low","tv_v_high"].flatMap(e=>[{key:e,tools:["transientPlant","stepSteer"],why:Ry},{key:e,tools:["drive"],why:vy},{key:e,tools:["tyreReadouts"],why:LF,gap:"the envelope corners with the feedforward, the readouts split the same lap without it (rule 3)"},{key:e,tools:["plannerRequest"],why:"the planner allocates by capacity when vectoring is on, with no feedforward schedule (reduced planner model)"}]),{key:"brake_balance",tools:["ymd"],why:"no braking: the diagram is drawn at constant speed",ymd:{driving:"the diagram is drawn under acceleration, not braking",liveBraking:!0}},{key:"brake_balance",tools:["stepSteer"],why:"the speed is held by the drive; the test never brakes"},...["gear_ratio","power_scale","power_limit_kw","driven_wheels","effi_pgb"].map(e=>({key:e,tools:["ymd"],why:T3,ymd:{moving:C3}})),...["gear_ratio","power_scale","power_limit_kw"].flatMap(e=>[{key:e,tools:["envelopeTrim"],why:"the trim imposes the tyres\u2019 push (`axG`); what a motor could deliver is the envelope limits\u2019 question"},{key:e,tools:["tyreReadouts"],why:"the lap\u2019s motion carries the drive the powertrain made; the readouts only split it"},{key:e,tools:["stepSteer"],why:"the speed is held by a force (a PI loop on the drive), not through the powertrain"}]),{key:"power_scale",tools:["plannerRequest"],why:"the planner\u2019s drive is the motor model\u2019s axle force (`planDriveOf`), which `power_scale` does not scale",gap:"the envelope scales its drive by `power_scale` (`calcGGV`), the planner does not: two cars (rule 1)"},{key:"power_limit_kw",tools:["plannerRequest"],why:"the planner has no pack limit (reduced planner model)"},...["I_wheel","I_rotor"].flatMap(e=>[{key:e,tools:["ymd"],why:"rotating inertia only acts where the car changes speed",ymd:{moving:"rotating inertia is longitudinal, and `ax` is set here rather than solved \u2014 nothing in this picture spins a wheel up"}},{key:e,tools:["envelopeTrim"],why:"the trim imposes the tyres\u2019 push; rotating inertia acts where the speed changes (`rotatingInertia.ts`)"},{key:e,tools:["tyreReadouts"],why:"the lap\u2019s motion carries what the inertia cost; the readouts only split the force"},{key:e,tools:["stepSteer"],why:"no wheel rotation, and the speed is held"},{key:e,tools:["plannerRequest"],why:"the planner has no rotating inertia (reduced planner model)"}]),{key:"v_limit_endurance",tools:["ymd"],why:"a limiter constrains a lap\u2019s speed profile; this diagram is drawn at one imposed speed"},{key:"v_limit_endurance",tools:xy.filter(e=>e!=="ymd"),why:"a limiter constrains a distance event\u2019s speed profile (`runTrackLap`), and is live there (`wiring.test.ts`, LAP_KEYS)"},{key:"endurance_reserve",tools:["ymd"],why:"an energy budget sets the long event\u2019s speed ceiling; this diagram is drawn at one imposed speed"},{key:"endurance_reserve",tools:xy.filter(e=>e!=="ymd"),why:"an energy budget solves a distance event\u2019s speed ceiling (`runTrackLap`), and is live there (`wiring.test.ts`, LAP_KEYS)"},{key:"fr_0",tools:["ymd"],why:"rolling resistance is longitudinal",ymd:{moving:"rolling resistance is a drag term; `ax` is what the car does, not what the tyres are handed"}},{key:"fr_0",tools:["envelopeTrim"],why:"the trim takes the tyres\u2019 push as given; rolling resistance is a drag, not a tyre force"},{key:"fr_0",tools:["tyreReadouts"],why:"the lap\u2019s motion carries the drag (`LapMotion.axDrag`), rolling resistance in it"},{key:"fr_0",tools:["stepSteer"],why:"step steer\u2019s plant has no rolling resistance (`twoTrackSimFrom` without `rollingCoeff`), and its speed is held"},{key:"r_dyn",tools:["ymd"],why:"the rolling radius only matters where a wheel is driven or braked",ymd:{moving:"the force each tyre carries is set here in newtons; a radius would only convert it to a torque"}}];function DF(e=0){let t=[],r=new Set;for(let n of P3){if(!n.tools.includes("ymd")||n.onCar||r.has(n.key)||e<0&&n.ymd?.liveBraking)continue;r.add(n.key);let o=e>0?n.ymd?.driving??n.ymd?.moving??n.why:e<0?n.ymd?.moving??n.why:n.why;t.push({key:n.key,why:o})}return t}var EF=Math.PI/180;function NF(e,t){let r=Math.abs(e);return r<.15?"no measurable body slip \u2014 the car is travelling along its own centreline":Math.abs(t)<1e-6?`${r.toFixed(1)}\xB0 of body slip (not cornering, so there is no inside or outside yet)`:e*Math.sign(t)>0?`${r.toFixed(1)}\xB0 of body slip, nose pointing OUT of the corner \u2014 running wide of the path it is on`:`${r.toFixed(1)}\xB0 of body slip, nose pointing INTO the corner \u2014 rotated inside the path it is on`}function IF(e,t,r){return e.length<2?0:t<=0?(e[1]-e[0])/r:t>=e.length-1?(e[e.length-1]-e[e.length-2])/r:(e[t+1]-e[t-1])/(2*r)}function OF(e,t,r,n){let o=e.isoDelta.length,a=e.isoDelta[0]?.ay.length??0,s=Math.max(0,Math.min(o-1,Math.floor(t))),i=Math.max(0,Math.min(a-1,Math.floor(r))),c=Math.max(0,Math.min(1,t-s)),l=Math.max(0,Math.min(1,r-i)),u=0;for(let[m,p]of[[s,1-c],[Math.min(o-1,s+1),c]])if(!(p<=0))for(let[d,f]of[[i,1-l],[Math.min(a-1,i+1),l]])f<=0||(u+=p*f*n(e.isoDelta[m],d,m));return u}function VF(e,t,r){let n=e.isoDelta[0],o=(n.betaDeg[1]-n.betaDeg[0])*EF||1,a=e.isoDelta.length>1?(e.isoDelta[1].deltaDeg[0]-e.isoDelta[0].deltaDeg[0])*EF:1,s=S=>OF(e,t,r,S),i=s((S,A)=>S.ay[A]),c=s((S,A)=>S.cn[A]),l=s((S,A)=>S.betaDeg[A]),u=s((S,A)=>S.deltaDeg[A]),m=s((S,A)=>IF(S.cn,A,o)),p=s((S,A,C)=>IF(e.isoDelta.map(F=>F.cn[A]),C,a||1)),d=Math.max(1e-6,e.maxAy),f=Math.abs(i)/d,h=Math.max(1e-6,...e.isoDelta.flatMap(S=>S.cn.filter(Number.isFinite).map(Math.abs))),b=Math.abs(c)/h,g=i===0?c:c*Math.sign(i),y=[];y.push(`${NF(l,i)}.`),b<.03?y.push("On the trim line: yaw moments balance, so this is a steady corner the car can actually hold. Only points on this line are real cornering states \u2014 everywhere else the car is still rotating."):g>0?y.push(`Not a steady state: there is a surplus yaw moment turning the car further into the corner, so it would keep rotating from here. To hold ${Math.abs(i).toFixed(2)} g the driver would have to wind ${u>=0?"off":"on"} steer until the point reaches the trim line.`):y.push("Not a steady state: the yaw moment is straightening the car out, so it would run wide from here. The car needs more steer, or more front grip, to reach the trim line at this slip angle.");let x=Math.abs(e.stability)>1e-9?m/e.stability:1;x<.15?y.push("Yaw stiffness has collapsed here: the moment resisting a change in body slip is essentially gone, so the car will not gather itself up if it steps out. Both axles are close to saturation."):x<.85?y.push(`Yaw stiffness is down to about ${(100*x).toFixed(0)} % of its straight-ahead value \u2014 the car resists a change in body slip less firmly here than it does in the linear range.`):y.push(`Yaw stiffness is near its straight-ahead value (${(100*x).toFixed(0)} %), so the car still opposes a change in body slip about as firmly as it does in a straight line.`);let R=Math.abs(e.control),v=R>1e-9?Math.abs(p)/R:1;return v<.15?y.push("The steering has stopped working here: another degree of lock buys almost no yaw moment, which is what a saturated front axle looks like. This is understeer in its literal sense \u2014 the front tyres are already at their limit."):v<.5&&y.push(`Steering response is down to about ${(100*v).toFixed(0)} % of its straight-ahead value \u2014 the front is well into the non-linear part of its curve.`),f>.97?y.push(`At the edge of the diagram: ${Math.abs(i).toFixed(2)} g is essentially all this car has at this speed.`):f<.25&&y.push("Well inside the limit \u2014 this is the linear region the handling balance is measured in."),{ay:i,cn:c,betaDeg:l,deltaDeg:u,stability:m,control:p,gripUsed:f,notes:y}}var _F=1e-4;function ky(e){let t=null,r=p=>{if(!t)return!0;let d=Math.abs(p),f=Math.abs(t.ay);return d>f*(1+_F)?!0:d<f*(1-_F)?!1:p>0&&t.ay<0};for(let p=0;p<e.isoDelta.length;p++){let d=e.isoDelta[p];for(let f=1;f<d.cn.length;f++){if(!(d.cn[f-1]===0||d.cn[f-1]<0!=d.cn[f]<0))continue;let b=d.cn[f-1]===d.cn[f]?0:d.cn[f-1]/(d.cn[f-1]-d.cn[f]),g=d.ay[f-1]+b*(d.ay[f]-d.ay[f-1]);r(g)&&(t={ay:g,d:p,b:b<.5?f-1:f})}}if(!t)return null;let n=VF(e,t.d,t.b),o=Math.abs(e.control)>1e-9?Math.abs(n.control/e.control):1,a=Math.abs(e.stability)>1e-9?n.stability/e.stability:1,s=o<.35,i=a<.35,c=s&&i?"both":s?"front":i?"rear":o<a?"front":"rear",l=e.isoDelta[t.d].betaDeg.length,u=t.b===0||t.b===l-1||t.d===0||t.d===e.isoDelta.length-1,m=t.ay<0?-1:1;return{ay:Math.abs(t.ay),turn:m,betaDeg:e.isoDelta[t.d].betaDeg[t.b]*m,deltaDeg:e.isoDelta[t.d].deltaDeg[t.b]*m,d:t.d,b:t.b,limitedBy:c,controlFrac:o,stiffnessFrac:a,onGridEdge:u}}function BF(e=0){return DF(e)}var L3=BF(0);function $F(e=0){let t="Springs and bars act through the roll-stiffness split and the camber the wheels take in roll; a heave spring reaches it too, but only faintly, through how far aero pushes the car down onto its camber curve.";if(!e)return"Steady state, lateral only: every point is a car in equilibrium at constant speed. Dampers, inertias, brake balance and the whole powertrain therefore cannot appear here \u2014 not because they are ignored, but because nothing in this picture accelerates. "+t;let r=e<0?`braking at ${Math.abs(e).toFixed(2)} g`:`accelerating at ${e.toFixed(2)} g`,n=e<0?"the brake balance decides which axle pays for it":"the driven axle pays for it";return`Steady state, ${r}: the load has moved ${e<0?"forward":"rearward"} and every tyre is spending part of its grip longitudinally, so ${n}. Dampers and inertias still cannot appear \u2014 the attitude is constant, it is simply not level. `+t}var D3=$F(0);var E3=9.81;function I3(e){let t=e.wheelbase/1e3;return{lf:t*(1-e.frontMassFrac),lr:t*e.frontMassFrac}}function El(e,t,r,n){let o=t.tire;if(!o)return null;let s=(r==="limit"?_0(e,o,t.speed):So(e,o,t.speed,t.ayG)).wheels;return _n(n??la(o,e.massTotal*E3*1.2),{FL:s.FL,FR:s.FR,RL:s.RL,RR:s.RR},I3(e))}function _3(e){if(!e.tire)return e.cornerStiffness;let t=Te(e.tire,"front"),r=Te(e.tire,"rear");return{front:n=>t.corneringStiffness(n),rear:n=>r.corneringStiffness(n)}}var GF=[{key:"understeer",label:"Understeer gradient",unit:"\xB0/g",compute:(e,t)=>mp(e,t.ayG,_3(t),t.speed).gradient},{key:"rollGradient",label:"Roll gradient",unit:"\xB0/g",compute:e=>Ge(e).rollGradient},{key:"pitchGradient",label:"Pitch gradient",unit:"\xB0/g",compute:e=>Ge(e).pitchGradient},{key:"tlltdFront",label:"TLLTD front",unit:"%",compute:e=>100*yc(e)},{key:"rollStiffFront",label:"Front roll-stiffness",unit:"%",compute:e=>100*Ge(e).frontRollStiffFrac},{key:"rideFreqFront",label:"Ride freq front, no dampers",unit:"Hz",compute:e=>Ge(e).rideFreqFront},{key:"rideFreqRear",label:"Ride freq rear, no dampers",unit:"Hz",compute:e=>Ge(e).rideFreqRear},{key:"rollFreqNoDampers",label:"Roll-mode freq, no dampers",unit:"Hz",compute:e=>gy(e).roll},{key:"pitchFreqNoDampers",label:"Pitch-mode freq, no dampers",unit:"Hz",compute:e=>gy(e).pitch},{key:"rollFreq",label:"Roll-mode freq, with dampers",unit:"Hz",compute:e=>bp(e).roll.freq},{key:"pitchFreq",label:"Pitch-mode freq, with dampers",unit:"Hz",compute:e=>bp(e).pitch.freq},{key:"zetaFront",label:"Damping \u03B6 front",unit:"-",compute:e=>pp(e).front.dampingRatio},{key:"zetaRear",label:"Damping \u03B6 rear",unit:"-",compute:e=>pp(e).rear.dampingRatio},{key:"yawFreq",label:"Yaw natural freq",unit:"Hz",compute:(e,t)=>Ll(e,t.speed)?.yawFreq??NaN},{key:"yawZeta",label:"Yaw damping \u03B6",unit:"-",compute:(e,t)=>Ll(e,t.speed)?.dampingRatio??NaN},{key:"stabilitySpeed",label:"Char./critical speed",unit:"km/h",compute:(e,t)=>{let r=Ll(e,t.speed);return r?r.criticalSpeed??r.characteristicSpeed??NaN:NaN}},{key:"maxAy",label:"Max lateral accel",unit:"g",compute:(e,t)=>t.fyAxle?yy(e,t.fyAxle,t.speed,{betaMaxDeg:12,deltaMaxDeg:12}).maxAy:NaN},{key:"yawReserveRear",label:"Yaw stability reserve",unit:"N\xB7m",compute:(e,t)=>El(e,t,"operating")?.stabil??NaN},{key:"yawReserveFront",label:"Yaw agility reserve",unit:"N\xB7m",compute:(e,t)=>El(e,t,"operating")?.agil??NaN},{key:"limitBalance",label:"Limit balance (+US / \u2212OS)",unit:"-",compute:(e,t)=>El(e,t,"limit")?.rel??NaN},{key:"yawStiffness",label:"Yaw stiffness N_\u03B2",unit:"N\xB7m/rad",compute:(e,t)=>t.tire?I0(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorque",label:"Steering holding torque",unit:"N\xB7m",compute:(e,t)=>t.tire?D0(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorqueGradient",label:"Steering feedback gradient",unit:"N\xB7m/g",compute:(e,t)=>t.tire?E0(e,t.tire,t.speed,t.ayG):NaN}],My=Object.fromEntries(GF.map(e=>[e.key,e]));var hn=9.81;function N3(e,t,r){let n=Math.abs(e);return n>0?t>0&&(n<=t||t>=r)?n/t:r>0?1+(n-t)/r:2:0}var O3={front:!1,rear:!0};function fi(e,t,r,n){let o=e.muX(t)*t,a=e.muY(t)*t;if(!(o>0))return 0;let s=a>0?Math.min(1,r/a):1;return n&&t>0?o*Jb(n,t,s):o*Math.sqrt(1-s*s)}function KF(e,t,r,n,o,a,s,i){let c=e[t]+e[r];if(!(c>0))return;let l=fi(n,o[t],a[t],i),u=fi(n,o[r],a[r],i),m=!(l+u>0);if(m&&(l=n.muX(o[t])*o[t],u=n.muX(o[r])*o[r]),!(l+u>0))return;let p=s?.[t],d=s?.[r];if(p===void 0&&d===void 0){e[t]=c*(l/(l+u)),e[r]=c-e[t];return}let f=[Math.min(l,p??1/0),Math.min(u,d??1/0)],h=m?void 0:HF(n,o,a,t,r,l,u,s,i);if(h&&c>f[0]+f[1]){let b=Math.min(c-h.capC,h.xMax),g=Math.min(a[h.o],h.fyO(b));a[h.c]+=a[h.o]-g,a[h.o]=g,e[h.o]=b,e[h.c]=c-b;return}e[t]=zF(c,f,[l,u])[0],e[r]=c-e[t]}function HF(e,t,r,n,o,a,s,i,c){let l=i[n]??1/0,u=i[o]??1/0,m,p,d;if(l<a&&!(u<s))[m,p,d]=[n,o,s];else if(u<s&&!(l<a))[m,p,d]=[o,n,a];else return;let f=i[m],h=i[p]??1/0,b=e.muX(t[p])*t[p],g=e.muY(t[p])*t[p],y=e.muX(t[m])*t[m],x=e.muY(t[m])*t[m];if(!(b>0&&g>0&&y>0&&x>0))return;let R=(M,k)=>c?AM(c,M,k):Math.sqrt(Math.max(0,1-k*k)),v=(M,k)=>c?Jb(c,M,k):Math.sqrt(Math.max(0,1-k*k)),S=M=>g*R(t[p],M/b),A=x*R(t[m],f/y),C=r[m]+r[p]-A,F=Math.min(h,b*v(t[p],0)),T=C<=0?F:Math.max(d,Math.min(F,C<g?b*v(t[p],C/g):0));return{c:m,o:p,capC:f,xMax:T,fyO:S}}function zF(e,t,r){let n=t.reduce((a,s)=>a+s,0),o=r.reduce((a,s)=>a+s,0);return n>0&&e<=n?t.map(a=>e*a/n):o>n&&e<=o?t.map((a,s)=>a+(e-n)*(r[s]-a)/(o-n)):r.map(a=>e*a/o)}function YF(e,t,r,n,o,a={},s="open",i,c){if(!e.rear)return 1;if(!e.front)return 0;let l=(b,g,y)=>y?Qc(b,g,y):s==="own"?b+g:2*Math.min(b,g),u={FL:fi(n,t.FL,r.FL,c?.front),FR:fi(n,t.FR,r.FR,c?.front),RL:fi(o,t.RL,r.RL,c?.rear),RR:fi(o,t.RR,r.RR,c?.rear)},m=(b,g)=>u[g],p=l(u.FL,u.FR,a.front),d=l(u.RL,u.RR,a.rear);if(i&&i.total>0&&p+d>0){let b=(S,A)=>Math.min(m(S,A),i.caps[A]??1/0),g=(S,A,C,F,T)=>{let M=A==="FL"?c?.front:c?.rear,k=F||s!=="own"?void 0:HF(S,t,r,A,C,m(S,A),m(S,C),i.caps,M),w=k?k.capC+k.xMax:l(b(S,A),b(S,C),F);return[w,Math.max(T,w)]},[y,x]=g(n,"FL","FR",a.front,p),[R,v]=g(o,"RL","RR",a.rear,d);return zF(i.total,[y,R],[x,v])[0]/i.total}if(p+d>0)return p/(p+d);let f=n.muX(t.FL)*t.FL+n.muX(t.FR)*t.FR,h=o.muX(t.RL)*t.RL+o.muX(t.RR)*t.RR;return f+h>0?f/(f+h):.5}function Sy(e,t,r,n){return{car:t?UF(t,r.loadFactor[n]):e,ayTyre:mt(r.ay[n],r.bank?.[n]??0),axCar:r.ax[n]-(r.axGrade?.[n]??0)}}function WF(e,t){if(!e.aero?.model)return 0;let r=Math.min(t.v.length,t.ax.length,t.ay.length),n=t.loadFactor?xp(e):void 0,o=0,a=0;for(let s=0;s<r;s++){let i=t.ds?.[s]??1,c=Sy(e,n,t,s);o+=i,Xb(c.car,t.v[s],c.axCar/hn,c.ayTyre/hn)&&(a+=i)}return o>0?a/o:0}function jF(e,t,r){let n=$r(Te(t,"front")),o=$r(Te(t,"rear")),a=Math.min(r.v.length,r.ax.length,r.ay.length),s=r.loadFactor?xp(e):void 0,i=0,c=0;for(let l=0;l<a;l++){let u=r.ds?.[l]??1,m=Sy(e,s,r,l);i+=u;let p=Xe(m.car,m.ayTyre/hn,m.axCar/hn,r.v[l]);(p.FL>n||p.FR>n||p.RL>o||p.RR>o)&&(c+=u)}return i>0?c/i:0}function yp(e,t,r,n={}){let o=Math.min(r.v.length,r.ax.length,r.ay.length),a=e.wheelbase/1e3,s=a*(1-e.frontMassFrac),i=a*e.frontMassFrac,c=Qs(t,e.massTotal*hn*1.2),l=Bs(c,"front"),u=Bs(c,"rear"),m={mu:1},p=G=>({muX:B=>m.mu*G.muX(B),muY:B=>m.mu*G.muY(B)}),d=r.mu?p(l):l,f=r.mu?u===l?d:p(u):u,h=r.mu?{front:d,rear:f}:c,b=Yt(Te(t,"front")),g=Yt(Te(t,"rear")),y=eg(b,l),x=g===b?y:eg(g,u),R={front:y,rear:x},v=n.driven??O3,S={front:pr(e,"front",1),rear:pr(e,"rear",1)},A={front:0,rear:0},C=new Array(o),F=new Array(o),T=new Array(o),M=1/0,k=0,w=0,P=$r(b),L=$r(g),E=0,_=0,D=0,I=0,N=0,O=0,V=["FL","FR","RL","RR"],H=n.perWheel?Object.fromEntries(V.map(G=>[G,{Fz:new Array(o),alpha:new Array(o),Fy:new Array(o),Fx:new Array(o),Mz:new Array(o),used:new Array(o),FxCap:new Array(o),FyCap:new Array(o)}])):void 0,U=r.loadFactor?xp(e):void 0;for(let G=0;G<o;G++){let B=Sy(e,U,r,G),{ayTyre:q,axCar:re}=B,W=q/hn,z=Xe(B.car,W,re/hn,r.v[G]),Y=r.mu?ap(r.mu,G):1;m.mu=Y;let te=e.massTotal*q,j=te*i/a,X=te*s/a,le=Pc(b,j/Y,z.FL,z.FR,N),pe=Pc(g,X/Y,z.RL,z.RR,O);N=le,O=pe;let ue={FL:Y*Math.abs(b.Fy(le,z.FL,0)),FR:Y*Math.abs(b.Fy(le,z.FR,0)),RL:Y*Math.abs(g.Fy(pe,z.RL,0)),RR:Y*Math.abs(g.Fy(pe,z.RR,0))},ie=(re-(r.axDrag?.[G]??0)-(r.axScrub?.[G]??0))/hn,ke=r.wheelMotor,Ie=ke?Object.fromEntries(V.flatMap(be=>ke[be]?[[be,ke[be][G]*e.massTotal]]:[])):void 0,Ke=Ie?{total:ie*hn*e.massTotal,caps:Ie}:void 0,oe=ie>0&&v.front?YF(v,z,ue,d,f,S,"own",Ke,R):0,se=r.v[G]*r.v[G],xe=e.driveline?{Fz:z,alpha:{front:le,rear:pe},curvature:se>1?r.ay[G]/se:0,seed:A,...Y!==1?{grip:Y}:{}}:void 0,fe={...P0(e,ie,r.v[G],t,W,oe,xe,Y)};ie>0&&(S.front||KF(fe,"FL","FR",d,z,ue,Ie,y),S.rear||KF(fe,"RL","RR",f,z,ue,Ie,x));let Fe=!1,Re=!1;for(let be of["FL","FR","RL","RR"]){let ge=(be==="FL"||be==="FR"?d:f).muX(z[be])*z[be];Math.abs(fe[be])>ge&&(Fe=!0),z[be]>(be==="FL"||be==="FR"?P:L)&&(Re=!0)}Re&&(w+=r.ds?.[G]??1);let ae=_n(h,{FL:{Fz:z.FL,Fy:ue.FL,Fx:fe.FL},FR:{Fz:z.FR,Fy:ue.FR,Fx:fe.FR},RL:{Fz:z.RL,Fy:ue.RL,Fx:fe.RL},RR:{Fz:z.RR,Fy:ue.RR,Fx:fe.RR}},{lf:s,lr:i});if(C[G]=ae.stabil,F[G]=ae.agil,T[G]=ae.rel,H){let be=.5*(z.FL+z.FR),ge=.5*(z.RL+z.RR),ye=d.muX(be)*be,ce=f.muX(ge)*ge;for(let Ae of V){let Se=z[Ae],ve=Ae==="FL"||Ae==="FR",wt=ve?d:f,qe=wt.muY(Se)*Se,It=wt.muX(Se)*Se,Pe=H[Ae],_e=ve?le:pe;Pe.Fz[G]=Se,Pe.alpha[G]=_e,Pe.Fy[G]=ue[Ae],Pe.Fx[G]=fe[Ae],Pe.Mz[G]=Se>0?Y*(ve?b:g).Mz(_e,Se,0):0,Pe.FxCap[G]=It,Pe.FyCap[G]=qe;let He=qe>0?Math.min(1,Math.abs(ue[Ae])/qe):0,Ee=N3(fe[Ae],It,ve?ye:ce),ze=ve?y:x,qt=ze&&Se>0?ze.reach(Se,Math.sign(fe[Ae])*Ee,He):1;Pe.used[G]=Math.hypot(He,Ee)/qt}}ae.stabil<M&&(M=ae.stabil,k=G);let Me=r.ds?.[G]??1;I+=Me,ae.diff>0&&(E+=Me),Fe&&(_+=Me),Xb(B.car,r.v[G],re/hn,W)&&(D+=Me)}return{stabil:C,agil:F,rel:T,minStabil:Number.isFinite(M)?M:0,minStabilAt:k,pastTurnoverFrac:I>0?w/I:0,understeerFrac:I>0?E/I:0,beyondFrac:I>0?_/I:0,aeroOutsideFrac:I>0?D/I:0,wheels:H}}function xp(e){return Object.create(e,{loadFactor:{value:1,writable:!0,enumerable:!0}})}function UF(e,t){return e.loadFactor=t,e}var Ay=9.81;function wy(e,t,r,n={}){let o=r.v.length,a=e.massTotal,s=Hn(e),i=s.mode==="hydraulic",c={front:new Array(o).fill(0),rear:new Array(o).fill(0),...n.regen?{regen:new Array(o).fill(0)}:{},...i?{pFront:new Array(o).fill(0),pRear:new Array(o).fill(0),pedalN:new Array(o).fill(0)}:{}};for(let l=0;l<o;l++){let u=r.v[l],m=r.ax[l]-(r.axGrade?.[l]??0),p=m-(r.axDrag?.[l]??0)-(r.axScrub?.[l]??0),d=-a*p;if(!(d>0))continue;let f=mt(r.ay[l],r.bank?.[l]??0)/Ay,h=Math.min(.99,Math.max(.01,js(e,p/Ay,u,t,f)));c.front[l]=d*h,c.rear[l]=d*(1-h);let b=i?vd(e,t,d,u,f):void 0;if(c.regen&&n.regen&&(c.regen[l]=b?Math.min(d,b.regenFront+b.regenRear):n.regen(d,u,m/Ay)),c.regen&&b){let g=b.regenFront+b.regenRear,y=g>0?c.regen[l]/g:0;(c.regenFront??=new Array(o).fill(0))[l]=b.regenFront*y,(c.regenRear??=new Array(o).fill(0))[l]=b.regenRear*y}if(i){let g=b?b.demand:s.demand(s.controlFor(d,u),u);c.pFront[l]=g.pFront,c.pRear[l]=g.pRear,c.pedalN[l]=g.pedalN}}return c}var $ae=Math.PI/180;var Gae=fy.map(sl);var Kae=[de.zFL,de.zFR,de.zRL,de.zRR];var Q3=9.81,Z3=.001,J3=.6,eB=2,ZF=4;function JF(e,t,r,n=ZF){let o=Math.min(e.v.length,t.npts),{ds:a,closed:s}=t,i=r.massTotal*Q3*r.wheelbase,c=tB(e.ay.slice(0,o).map((m,p)=>m/Math.max(Z3,e.v[p])),a,s,n),l=new Array(o).fill(0),u=new Array(o).fill(0);if(!(i>0))return{demand:l,rdot:u};for(let m=0;m<o;m++){let p=m===0?s?o-1:-1:m-1,d=m===o-1?s?0:-1:m+1;if(p<0||d<0)continue;let f=a[p]+a[m];if(!(f>0))continue;u[m]=e.v[m]*(c[d]-c[p])/f;let h=Math.sign(c[m]);l[m]=h===0?0:h*r.yawInertia*u[m]/i}return{demand:l,rdot:u}}function tB(e,t,r,n){let o=e.length;if(!(n>0)||o<3)return e;let a=new Array(o);a[0]=0;for(let c=1;c<o;c++)a[c]=a[c-1]+t[c-1];let s=r?Math.floor((o-1)/2):o-1,i=new Array(o);for(let c=0;c<o;c++){let l=r?n:Math.min(n,a[c],a[o-1]-a[c]),u=e[c],m=1,p=0;for(let d=1;d<=s&&!(!r&&c+d>=o||(p+=t[(c+d-1)%o],!(p<l)));d++){let f=1-p/l;u+=f*e[(c+d)%o],m+=f}p=0;for(let d=1;d<=s&&!(!r&&c-d<0);d++){let f=(c-d+o)%o;if(p+=t[f],!(p<l))break;let h=1-p/l;u+=h*e[f],m+=h}i[c]=u/m}return i}function eC(e,t,r,n,o={}){let a=o.maxIter??20,s=o.tol??.001,i=Math.min(1,Math.max(.001,o.relax??J3)),c=o.smoothM??ZF,l={standingStart:o.standingStart,...o.driveDerate?{driveDerate:o.driveDerate}:{},...o.brakeFade?{brakeFade:o.brakeFade}:{},...o.vCeiling?{vCeiling:o.vCeiling}:{},...o.load?{load:o.load}:{},...o.shifts?{shifts:o.shifts}:{}},u=tr(e.steady,t,n,l),m=[u.laptime],p=new Array(t.npts).fill(0),d=p.slice(),f=u,h=0,b=!1,g=0;for(let R=0;R<a;R++){h=R+1;let v=JF(f,t,r,c);p=v.demand.map((C,F)=>p[F]+i*(C-p[F])),d=v.rdot;let S=tr(e.steady,t,n,{...l,envelope:C=>e.at(p[C]??0)});m.push(S.laptime);let A=Math.abs(S.laptime-f.laptime);if(f=S,g=A<=s?g+1:0,g>=eB){b=!0;break}}let y=0,x=0;for(let R=0;R<t.npts;R++)x+=t.ds[R],e.clamps(p[R]??0)&&(y+=t.ds[R]);return{...f,steady:u,demand:p,rdot:d,history:m,iterations:h,converged:b,clampedFrac:x>0?y/x:0}}var Qae=Math.PI/180;var Ose=180/Math.PI;function rC(e,t,r){let n=e.length-1;if(!(r<e[n]))return t[n];let o=0,a=n;for(;a-o>1;){let i=o+a>>1;e[i]<=r?o=i:a=i}let s=(r-e[o])/(e[a]-e[o]);return t[o]+s*(t[a]-t[o])}function yB(e,t,r,n,o){let a=e.grip(o),s=t.atLock?n*n/t.ayMax:e.lockRadius,i=a*r.ayMax,c=s>0&&Number.isFinite(s)?o*o/s:1/0,l=c<i,u=l?c:i,m=l&&i>0?c/i:1,{norm:p}=e,d=h=>p.map(b=>a*rC(p,h,b*m)),f=h=>m===1?h:p.map(b=>rC(p,h,b*m));return{ayMax:u,axAccelN:d(r.axAccelN),axDecelN:d(r.axDecelN),axScrubN:d(r.axScrubN),...r.motorTyreN?{motorTyreN:r.motorTyreN.map(f)}:{},...r.motorLoss?{motorLoss:f(r.motorLoss)}:{},...r.motorGain?{motorGain:r.motorGain.map(f)}:{},atLock:l}}var xB=5,Fy=1;function eo(e,t,r){let n=e.length;if(n===1||r<=e[0])return t[0];if(r>=e[n-1])return t[n-1];let o=0;for(;o<n-2&&e[o+1]<=r;)o++;let a=e[o],s=e[o+1],i=t[o],c=t[o+1];if(n===2)return i+(r-a)/(s-a)*(c-i);let l=p=>{let d=e[p];return i*(r-s)*(r-d)/((a-s)*(a-d))+c*(r-a)*(r-d)/((s-a)*(s-d))+t[p]*(r-a)*(r-s)/((d-a)*(d-s))},u=(r-a)/(s-a),m=o===0?l(2):o+1===n-1?l(o-1):(1-u)*l(o-1)+u*l(o+2);return Math.min(Math.max(i,c),Math.max(Math.min(i,c),m))}function nC(e,t,r){let n=RB(e,t);if(!r||!(t>0))return n;let o=n(t);return a=>a<t?yB(r,e[0],o,t,a):n(a)}function RB(e,t){let r=e.filter(d=>d.atLock),n=e.filter(d=>!d.atLock),o=r.length>0&&n.length>0&&r[r.length-1].v<n[0].v,a=d=>({vs:d.map(h=>h.v),ayMax:d.map(h=>h.ayMax),radius:d.map(h=>Math.max(h.v,t)**2/h.ayMax),accel:d[0].axAccelN.map((h,b)=>d.map(g=>g.axAccelN[b])),decel:d[0].axDecelN.map((h,b)=>d.map(g=>g.axDecelN[b])),scrub:d[0].axScrubN.map((h,b)=>d.map(g=>g.axScrubN[b])),motors:d.every(h=>h.motorTyreN&&h.motorLoss)?{tyreN:d[0].motorTyreN.map((h,b)=>h.map((g,y)=>d.map(x=>x.motorTyreN[b][y]))),loss:d[0].motorLoss.map((h,b)=>d.map(g=>g.motorLoss[b])),gain:d.every(h=>h.motorGain)?d[0].motorGain.map((h,b)=>h.map((g,y)=>d.map(x=>x.motorGain[b][y]))):void 0}:void 0}),s=(d,f)=>({axAccelN:d.accel.map(h=>eo(d.vs,h,f)),axDecelN:d.decel.map(h=>eo(d.vs,h,f)),axScrubN:d.scrub.map(h=>eo(d.vs,h,f)),...d.motors?{motorTyreN:d.motors.tyreN.map(h=>h.map(b=>eo(d.vs,b,f))),motorLoss:d.motors.loss.map(h=>eo(d.vs,h,f)),...d.motors.gain?{motorGain:d.motors.gain.map(h=>h.map(b=>eo(d.vs,b,f)))}:{}}:{}});if(!o){let d=a(e);return f=>({ayMax:eo(d.vs,d.ayMax,f),...s(d,f),atLock:!1})}let i=a(r),c=a(n),l=i.vs[i.vs.length-1],u=c.vs[0],m=d=>Math.max(d,t)**2/eo(i.vs,i.radius,d),p=d=>d>=u||c.vs.length<2?eo(c.vs,c.ayMax,d):c.ayMax[0]+(c.ayMax[1]-c.ayMax[0])/(c.vs[1]-c.vs[0])*(d-u);return d=>{if(d<=l)return{ayMax:m(d),...s(i,d),atLock:!0};if(d>=u)return{ayMax:p(d),...s(c,d),atLock:!1};let f=m(d),h=p(d);return f<h?{ayMax:f,...s(i,d),atLock:!0}:{ayMax:h,...s(c,d),atLock:!1}}}function vB(e,t){let r=Math.abs(e.ayMax-t.ayMax)/Math.max(t.ayMax,1),n=Math.max(Math.abs(t.axAccelN[0]),1),o=Math.max(Math.abs(t.axDecelN[0]),1);for(let a=0;a<t.axAccelN.length;a++)r=Math.max(r,Math.abs(e.axAccelN[a]-t.axAccelN[a])/n,Math.abs(e.axDecelN[a]-t.axDecelN[a])/o,Math.abs(e.axScrubN[a]-t.axScrubN[a])/n);return r}function oC(e,t,r,n,o,a){let s=r>t?Math.max(2,Math.min(xB,Math.floor(n))):1,i=[];for(let d=0;d<s;d++)i.push(e(s===1?t:t+(r-t)*d/(s-1)));let c=nC(i,t,a),l=[],u=s,m=(d,f)=>{let h=.5*(d+f),b=e(h);u++;let g=vB(c(h),b);i.splice(i.findIndex(y=>y.v>h),0,b),c=nC(i,t,a),g>o&&l.push({lo:d,hi:h,misfit:g},{lo:h,hi:f,misfit:g})},p=i.map(d=>d.v);for(let d=0;d+1<p.length&&u<n;d++)p[d+1]-p[d]>=Fy&&m(p[d],p[d+1]);if(p.length>1){let d=.5*(p[0]+p[1]);if(i.some(f=>f.v===d))for(let[f,h]of[[p[0],d],[d,p[1]]]){if(u>=n||h-f<Fy)break;let b=l.findIndex(g=>g.lo===f&&g.hi===h);b>=0&&l.splice(b,1),m(f,h)}}for(;u<n&&l.length>0;){let d=0;for(let g=1;g<l.length;g++)l[g].misfit>l[d].misfit&&(d=g);let{lo:f,hi:h,misfit:b}=l.splice(d,1)[0];if(b<=o)break;h-f<Fy||m(f,h)}return{anchors:i,at:c}}function aC(e,t){let r=Math.abs(t);return!(r>0)||!(e>0)?1/0:e/Math.tan(Math.min(r,1.5))}function sC(e){if(!e?.meanDeg?.length)return 0;let t=0;for(let r of e.meanDeg)t=Math.max(t,Math.abs(r));return t*Math.PI/180}var kB=2,MB=.5,Il=Math.PI/180,iC=21,SB={nCoarse:11,nSteer:13,nNorm:41,nAngle:45},AB={nCoarse:11,nSteer:13,nNorm:41,nAngle:61},wB=.005,FB=.05,CB=.5,Cy=e=>e<0?0:e>1?1:e;function cC(e,t,r,n){let o=e.massTotal,a=n.nSteer??7,s=(n.drivenFront?2:0)+(n.drivenRear?2:0),i=Xe(e,0,0,r),c=Math.max(1,(i.FL+i.FR+i.RL+i.RR)/4),l=8*Il,u=0,m=(b,g,y)=>{for(let x=b;x<=g;x+=y){let R=Math.abs(t.Fy(x*Il,c,0));R>u&&(u=R,l=x*Il)}};m(1,45,1),m(Math.max(.1,l/Il-1),l/Il+1,.1);let p=[],d=[],f=[],h=[];for(let b=0;b<a;b++){let g=b/(a-1),y=l*(g+Math.sin(Math.PI/2*g))/2,x=Math.abs(t.Fy(y,c,0));p.push(4*x/o),d.push(s*lr(t,c,x,!1)/o),f.push(4*lr(t,c,x,!0)/o),h.push(-4*x*Math.sin(y)/o)}return p[0]=0,{ayMax:4*u/o,ay:p,axAccel:d,axDecel:f,axScrub:h,rollover:!1}}function TB(e,t,r){if(e.engine)return;let n=xa(e.params),o=dr(e.params),a=[];for(let s of["front","rear"]){if(!(s==="front"?t:r))continue;let[i,c]=s==="front"?["FL","FR"]:["RL","RR"];if(n[s]==="independent")a.push({wheels:[i],axle:s,motors:o[s]/2},{wheels:[c],axle:s,motors:o[s]/2});else if(n[s]==="diff")a.push({wheels:[i,c],axle:s,motors:o[s]});else return}return a.length>1?a:void 0}var PB=.001;function lC(e,t){let r=e.flatMap((n,o)=>n===void 0?[]:[o]);return r.length===0?e.map(()=>t):e.map((n,o)=>{if(n!==void 0)return n;let a=r[0];for(let s of r)Math.abs(s-o)<Math.abs(a-o)&&(a=s);return e[a]})}var LB=.01,DB=.05;function uC(e,t,r,n){let o=0,a=0;for(let s of e.motors){let i=r*s.tyreN[t]*e.axAccelN[t],c=s.share>0?s.share*n:0;i>c&&(o+=i-c,a+=c)}return{short:o,theirs:a}}function _l(e,t,r,n){let o=e.motors;if(!o)return 1/0;let a=n>=1?e.axDrive:n*e.axDrive,s=r*e.axAccelN[t],{short:i,theirs:c}=uC(e,t,r,a);if(!(i>0))return s;let l=e.motorLoss?.[t]??1;if(r===1&&n>=1||!o.every(f=>f.gain)){let f=r>=1?l:l/(r+l*(1-r));return Math.max(c,s-f*i)}let u=Math.min(s,mC(e,t,r,a)),m=uC(e,t,1,e.axDrive);if(!(m.short>0))return Math.max(c,u);let d=Math.max(m.theirs,e.axAccelN[t]-l*m.short)-Math.min(e.axAccelN[t],mC(e,t,1,e.axDrive));return Math.max(c,Math.min(s,u+d*(i/m.short)))}function mC(e,t,r,n){let o=e.motors,a=r*e.axAccelN[t],s=a;for(let i=0;i<=o.length+1;i++){let c=0,l=0,u=0;for(let p of o){let d=r*p.gain[t],f=r*p.tyreN[t]*e.axAccelN[t],h=p.share>0?p.share*n:0,b=f+d*(s-a);u+=Math.min(h,b),(d>0?b<=h:b<h)?(l+=d,c+=f-d*a):c+=h}if(!(u<s))return s;if(!(l<1))return 0;let m=c/(1-l);if(!(m<s))return s;s=m}return s}function Ty(e,t,r,n,o){if(!e.motors)return 1/0;let a=t.length-1;if(!(r<t[a]))return _l(e,a,n,o);let s=0,i=a;for(;i-s>1;){let u=s+i>>1;t[u]<=r?s=u:i=u}let c=(r-t[s])/(t[i]-t[s]),l=_l(e,s,n,o);return c===0?l:l+c*(_l(e,i,n,o)-l)}function bn(e,t=!1,r="twoTrack",n,o,a=0,s=1){if(a!==0&&r==="fast")throw new Error('the fast (point-mass) envelope has no yaw balance to shift; use mode "twoTrack" for a yaw-inertia demand');let i=n??(t?AB:SB),{nCoarse:c,nSteer:l,nAngle:u}=i,m=Kn(0,1,i.nNorm).map(Y=>Math.sin(Math.PI/2*Y)),p=e.params,d=p.m.value,f=p.rho.value,h=p.fr_0.value,b=p.driven_wheels.value,g=p.power_scale.value,y=e.FG,x=Ut(p);s!==1&&(x.loadFactor=s);let R=pn(p),v=ZS(0,n?.vRes??(e.engine?MB:kB),e.vMax);v[v.length-1]<e.vMax&&v.push(e.vMax);let S=e.fRad.map(Y=>Y*b),A=e.fAxle,{drivenFront:C,drivenRear:F}=Ma(e),T=ka(p,C,F),M=(Y,te,j)=>{let X=Pt(Y,te,Math.max(j,Y[0]));return Number.isFinite(X)?X:1/0},k=(Y,te)=>A?M(A.vVehicle,Y,te):1/0,w=r==="fast"?void 0:TB(e,C,F),P=dr(p),L=(Y,te)=>{if(A){let X=k(A.fFront,te),le=k(A.fRear,te),pe=Y.map(ie=>(ie.axle==="front"?X:le)*(ie.motors/P[ie.axle])),ue=pe.reduce((ie,ke)=>ie+ke,0);if(Number.isFinite(ue)&&ue>0)return pe.map(ie=>ie/ue)}let j=Y.reduce((X,le)=>X+le.motors,0);return Y.map(X=>X.motors/j)},E=Y=>{let te=Y*Y,{cl:j,cw:X,A:le}=ep(p,Y,0,x),pe=.5*f*-X*le*te,ue=.5*f*-j*le*te,ie=h*(-ue+y);return pe+ie},_=Y=>{let te=E(Y)/d*T.powerFactor,j=E(Y)/d*T.tractionFactor,X;if(e.engine){let pe=E(Y);X=Ys(e.engine,Y,T.effective,pe,g).accel-te}else if(A){let pe=0;C&&(pe+=k(A.fFront,Y)),F&&(pe+=k(A.fRear,Y)),X=g*pe/d*T.powerFactor}else{let pe=M(e.vVehicle,S,Y),ue=g*pe/d*T.powerFactor;X=Number.isFinite(ue)?ue:1/0}let le=cp(p,Y,o)/d*T.powerFactor;return{axDrag:te,axDragTyre:j,axDrive:X,axPackCap:le,axPower:Math.min(X,le)}},D=v.map(_),I=e.vMax;for(let Y=1;Y<v.length;Y++){let te=D[Y].axDrive+D[Y].axDrag;if(te>0)continue;let j=D[Y-1].axDrive+D[Y-1].axDrag;I=j>0?v[Y-1]+(v[Y]-v[Y-1])*j/(j-te):v[Y-1];break}let N=Math.min(e.vMax,(1+FB)*I),O=r==="fast"?cC:O0,V=Y=>{let te=w?_(Y).axDrive:1/0,j=w&&Number.isFinite(te)?L(w,Y).map((fe,Fe)=>({wheels:w[Fe].wheels,cap:fe*te*d/T.tractionFactor})):void 0,X=O(x,R,Y,{drivenFront:C,drivenRear:F,nSteer:l,yawDemandCn:a,axDrag:E(Y)/d,...p.diffYaw?{diffYaw:!0}:{},...j?{motorCaps:j}:{}}),le=X.ay[0],pe=X.ay[X.ay.length-1],ue=fe=>Math.min(Math.max(fe*X.ayMax,le),pe),ie=m.map(fe=>md(X.ay,X.axAccel,ue(fe))*T.tractionFactor),ke=m.map(fe=>md(X.ay,X.axDecel,ue(fe))),Ie=m.map(fe=>md(X.ay,X.axScrub,ue(fe))*T.tractionFactor),Ke=X.axAccelWheels,oe=X.axAccelHeld,se=X.axAccelWheelsHeld,xe=w&&j&&Ke&&oe?(()=>{let fe=w.map(be=>X.ay.map((ge,ye)=>be.wheels.reduce((ce,Ae)=>ce+Ke[ye][Ae],0))),Fe=fe.map(be=>{let ge=be.map((ye,ce)=>ye/Math.max(X.axAccel[ce],PB));return m.map(ye=>Pt(X.ay,ge,ue(ye)))}),Re=X.ay.map((be,ge)=>{let ye=fe.reduce((ce,Ae,Se)=>ce+Math.max(0,Ae[ge]-j[Se].cap/d),0);return ye>LB?Math.max(0,X.axAccel[ge]-oe[ge])/ye:void 0}),ae=m.map(be=>Pt(X.ay,lC(Re,1),ue(be))),Me=se?w.map((be,ge)=>{let ye=X.ay.map((ce,Ae)=>{let Se=se[Ae],ve=X.axAccel[Ae]-oe[Ae];if(!(!Se||!(ve>DB)))return(fe[ge][Ae]-be.wheels.reduce((wt,qe)=>wt+Se[qe],0))/ve});return m.map(ce=>Pt(X.ay,lC(ye,0),ue(ce)))}):void 0;return{motorTyreN:Fe,motorLoss:ae,...Me?{motorGain:Me}:{}}})():void 0;return{v:Y,ayMax:X.ayMax,axAccelN:ie,axDecelN:ke,axScrubN:Ie,...xe??{},atLock:X.atLock===!0}},H=new Map,U=Y=>{let te=H.get(Y);return te||H.set(Y,te=V(Y)),te},G=r==="fast"?0:Math.min(Ld,N),B=G;if(r!=="fast"){for(let Y=G;Y<N;Y=Math.min(N,Y+CB))if(U(Y).ayMax>0){B=Y;break}}let q=(()=>{if(r==="fast"||!(B>0))return;let Y=j=>cC(x,R,j,{drivenFront:C,drivenRear:F,nSteer:2}).ayMax,te=Y(B);return{norm:m,grip:j=>te>0?Y(j)/te:1,lockRadius:aC(x.wheelbase/1e3,sC(x.steerFront))}})(),re=oC(U,B,N,c,i.anchorTol??wB,q),W=[],z=[];for(let Y=0;Y<v.length;Y++){let te=v[Y],{axDrag:j,axDragTyre:X,axDrive:le,axPackCap:pe,axPower:ue}=D[Y],{ayMax:ie,axAccelN:ke,axDecelN:Ie,axScrubN:Ke,motorTyreN:oe,motorLoss:se,motorGain:xe,atLock:fe}=re.at(te),Fe=w&&oe&&se?L(w,te):void 0,Re=w&&oe&&Fe?w.map((ye,ce)=>({wheels:ye.wheels,share:Fe[ce],tyreN:oe[ce],...xe?{gain:xe[ce]}:{}})):void 0,ae={v:te,ayMax:ie,...fe?{atLock:fe}:{},axTyreAcc:ke[0],axTyreDec:Ie[0],axDrive:le,axPackCap:pe,axPower:ue,axDrag:j,axDragTyre:X,axAccelN:ke,axDecelN:Ie,axScrubN:Ke,...Re&&se?{motors:Re,motorLoss:se}:{}};W.push(ae);let Me=[],be=[];for(let ye=0;ye<u;ye++){let ce=Math.PI*ye/(u-1),Ae=ie*Math.cos(ce),Se=Cy(Math.abs(Math.cos(ce))),ve=Math.min(Pt(m,ke,Se)+X,ue+j,Ty(ae,m,Se,1,1)+j);Me.push({ax:ve+Pt(m,Ke,Se),ay:Ae,v:te})}for(let ye=u-1;ye>=0;ye--){let ce=Math.PI*ye/(u-1),Ae=ie*Math.cos(ce),Se=Cy(Math.abs(Math.cos(ce)));be.push({ax:Pt(m,Ie,Se)+j+Pt(m,Ke,Se),ay:Ae,v:te})}let ge=(ye,ce,Ae)=>Array.from({length:iC},(Se,ve)=>({ax:ce+(Ae-ce)*(ve+1)/(iC+1),ay:ye,v:te}));z.push([...Me,...ge(-ie,Me[Me.length-1].ax,be[0].ax),...be,...ge(ie,be[be.length-1].ax,Me[0].ax)])}return{...hC(W,m),rows:W,norm:m,surf:z}}function hi(e,t){return e?.length?t.map(r=>vp(e,r)):t.map(()=>0)}function pC(e,t){let r=e?.[0]?.motors;if(!e||!r)return;let n={};return r.forEach((o,a)=>{o.wheels.length===1&&(n[o.wheels[0]]=t.map(s=>fC(e,s,i=>i.motors&&i.motors[a].share>0?i.motors[a].share*i.axDrive:0)))}),Object.keys(n).length?n:void 0}function vp(e,t){let r=e.length-1;if(!(t>e[0].v))return e[0].axDrag;if(t>=e[r].v)return e[r].axDrag;let n=0,o=r;for(;o-n>1;){let s=n+o>>1;e[s].v<=t?n=s:o=s}let a=(t-e[n].v)/(e[o].v-e[n].v);return e[n].axDrag+a*(e[o].axDrag-e[n].axDrag)}function fC(e,t,r){let n=e.length-1;if(!(t>e[0].v))return r(e[0]);if(t>=e[n].v)return r(e[n]);let o=0,a=n;for(;a-o>1;){let l=o+a>>1;e[l].v<=t?o=l:a=l}let s=r(e[o]),i=r(e[a]);if(!Number.isFinite(s)||!Number.isFinite(i))return Math.max(s,i);let c=(t-e[o].v)/(e[a].v-e[o].v);return s+c*(i-s)}function hC(e,t){let r=e[e.length-1].v,n=0;for(let b of e)b.atLock&&b.v>0&&b.ayMax>0&&(n=Math.max(n,b.ayMax/(b.v*b.v)));let o=b=>{if(b<=e[0].v)return{i0:0,i1:0,t:0};if(b>=r)return{i0:e.length-1,i1:e.length-1,t:0};let g=0,y=e.length-1;for(;y-g>1;){let x=g+y>>1;e[x].v<=b?g=x:y=x}return{i0:g,i1:y,t:(b-e[g].v)/(e[y].v-e[g].v)}},a=b=>{let{i0:g,i1:y,t:x}=o(b);return{a:e[g],b:e[y],t:g===y?0:x}},s=(b,g,y)=>b===0||g===y?g:g+b*(y-g),i=(b,g,y,x)=>b===0?Pt(t,g,x):s(b,Pt(t,g,x),Pt(t,y,x)),c=(b,g)=>g>=1?b.axPower:Math.min(g*b.axDrive,b.axPackCap),l=({a:b,b:g,t:y},x,R)=>b.axScrubN?R*i(y,b.axScrubN,g.axScrubN,x):0,u=b=>b.axDragTyre??b.axDrag,m=({a:b,b:g,t:y},x,R)=>{let v=R*s(y,b.ayMax,g.ayMax);return v>0?Cy(x/v):1},p=({a:b,b:g,t:y},x,R,v)=>s(y,Ty(b,t,x,R,v),y===0?0:Ty(g,t,x,R,v))+s(y,b.axDrag,g.axDrag),d=(b,g,y=1,x=1)=>{let{a:R,b:v,t:S}=b,A=m(b,g,y),C=y*i(S,R.axAccelN,v.axAccelN,A)+s(S,u(R),u(v)),F=s(S,c(R,x),S===0?0:c(v,x))+s(S,R.axDrag,v.axDrag);return R.motors?Math.min(C,F,p(b,A,y,x))+l(b,A,y):Math.min(C,F)+l(b,A,y)},f=(b,g,y=1,x=1)=>{let{a:R,b:v,t:S}=b,A=m(b,g,y),C=i(S,R.axDecelN,v.axDecelN,A);return(x===1||C>0?y*C:x*y*C)+s(S,R.axDrag,v.axDrag)+l(b,A,y)},h=({a:b,b:g,t:y},x,R=1)=>{let v=t.length-1,S=b.axAccelN,A=g.axAccelN,C=b.axDecelN,F=g.axDecelN,T=b.axScrubN,M=g.axScrubN,k=N=>S[N]+y*(A[N]-S[N]),w=N=>C[N]+y*(F[N]-C[N]),P=N=>T?R*(T[N]+y*(M[N]-T[N])):0,L=s(y,b.ayMax,g.ayMax),E=s(y,b.axDrag,g.axDrag),_=s(y,u(b),u(g)),D=s(y,b.axPower,g.axPower),I=b.motors?N=>s(y,_l(b,N,R,1),y===0?0:_l(g,N,R,1)):null;for(let N=v;N>=0;N--){let O=I?Math.min(R*k(N)+_,D+E,I(N)+E)+P(N):Math.min(R*k(N)+_,D+E)+P(N),V=R*w(N)+E+P(N);if(!(x<=O+1e-6&&x>=V-1e-6))continue;if(N===v)return t[N]*R*L;let H=(q,re,W)=>{if(W(re))return 1;let z=(q-x)/(q-re);return z>0?Math.min(z,1):0},U=q=>x<=q+1e-6,G=q=>x>=q-1e-6,B=Math.min(H(R*k(N)+_+P(N),R*k(N+1)+_+P(N+1),U),H(D+E+P(N),D+E+P(N+1),U),H(R*w(N)+E+P(N),R*w(N+1)+E+P(N+1),G),I?H(I(N)+E+P(N),I(N+1)+E+P(N+1),U):1);return(t[N]+B*(t[N+1]-t[N]))*R*L}return 0};return{vMax:r,...n>0?{kappaMax:n}:{},axAccel:(b,g,y=1,x=1)=>d(a(b),g,y,x),axDecel:(b,g,y=1,x=1)=>f(a(b),g,y,x),ay:(b,g,y=1)=>h(a(b),g,y),scrub:(b,g,y=1)=>{let x=a(b);return l(x,m(x,g,y),y)},power:(b,g,y=1)=>{let x=a(b),{a:R,b:v,t:S}=x,C=(Number.isFinite(R.axPower)&&Number.isFinite(v.axPower)?s(S,R.axPower,v.axPower):Math.max(R.axPower,v.axPower))+s(S,R.axDrag,v.axDrag);return R.motors?Math.min(C,p(x,m(x,g,y),y,1)):C}}}function EB(e,t,r){let n=e.params,o=n.m.value,{drivenFront:a,drivenRear:s}=Ma(e),i=ka(n,a,s);return c=>cp(n,c,t,r)/o*i.powerFactor}function Nl(e,t,r,n){let o=EB(t,r,n),a=e.rows.map(s=>{let i=o(s.v),c=Math.min(s.axDrive,i);return c===s.axPower&&i===s.axPackCap?s:{...s,axPackCap:i,axPower:c}});return{...hC(a,e.norm),rows:a,norm:e.norm}}var IB=[-.2,-.08,0,.06,.12,.2,.3];function bC(e,t=!1,r="twoTrack",n,o,a=IB){let s=[...new Set([...a,0])].sort((f,h)=>f-h),i=s.map(f=>bn(e,t,r,n,o,f)),c=i[s.indexOf(0)],l=s[0],u=s[s.length-1],m=f=>{if(f<=l)return{i:0,t:0};if(f>=u)return{i:s.length-1,t:0};let h=0;for(;h<s.length-2&&s[h+1]<=f;)h++;return{i:h,t:(f-s[h])/(s[h+1]-s[h])}},p=f=>{let h=b=>{let{i:g,t:y}=m(b);return{a:f[g],b:f[Math.min(f.length-1,g+1)],t:y}};return b=>{let{a:g,b:y,t:x}=h(b);if(x===0)return g;let R=(S,A)=>S+x*(A-S),v=gC(g.kappaMax,y.kappaMax);return{vMax:g.vMax,...v!==void 0?{kappaMax:v}:{},axAccel:(S,A,C=1,F=1)=>R(g.axAccel(S,A,C,F),y.axAccel(S,A,C,F)),axDecel:(S,A,C=1,F=1)=>R(g.axDecel(S,A,C,F),y.axDecel(S,A,C,F)),ay:(S,A,C=1)=>R(g.ay(S,A,C),y.ay(S,A,C)),scrub:(S,A,C=1)=>R(g.scrub?.(S,A,C)??0,y.scrub?.(S,A,C)??0)}}},d=f=>f<l||f>u;return{anchors:s,steady:c,clamps:d,at:p(i),atSoc(f,h,b){let g=i.map(y=>Nl(y,f,h,b));return{anchors:s,steady:g[s.indexOf(0)],clamps:d,at:p(g)}}}}function gC(e,t){return e===void 0?t:t===void 0?e:Math.min(e,t)}function yC(e,t,r,n="twoTrack",o){let a=[...new Set([...t,1])].sort((i,c)=>i-c),s=a.map(i=>i===1?r:bn(e,!1,n,o,void 0,0,i));return{...dC(a,s),atSoc:(i,c,l)=>dC(a,s.map(u=>Nl(u,i,c,l)))}}function dC(e,t){let r=e.length-1,n=1,o=0,a=0,s=0,i=1,c=0,l=0,u=f=>{if(n=1,!(f>e[0]))return void(o=0);if(f>=e[r])return void(o=r);let h=0;for(;h<r-1&&e[h+1]<=f;)h++;if(o=h,f===e[h])return;a=h+1;let b=e[h],g=e[h+1];if(r<2){n=2,c=(f-b)/(g-b),i=1-c;return}s=h===0?2:h+1===r||f-e[h-1]<e[h+2]-f?h-1:h+2;let y=e[s];n=3,i=(f-g)*(f-y)/((b-g)*(b-y)),c=(f-b)*(f-y)/((g-b)*(g-y)),l=(f-b)*(f-g)/((y-b)*(y-g))},m=f=>{let h=f(t[o]);if(n===1)return h;let b=f(t[a]);if(n===2)return i*h+c*b;let g=i*h+c*b+l*f(t[s]);return Math.min(Math.max(h,b),Math.max(Math.min(h,b),g))},p=(f,h,b,g,y)=>{if(u(f),n===1||b===0)return m(v=>y(v,b));let x=m(v=>v.ay(h,0,g));if(!(x>0))return m(v=>y(v,b));let R=b/x;return m(v=>y(v,R*v.ay(h,0,g)))},d=t.reduce((f,h)=>gC(f,h.kappaMax),void 0);return{anchors:e,...d!==void 0?{kappaMax:d}:{},axAccel:(f,h,b,g=1,y=1)=>p(f,h,b,g,(x,R)=>x.axAccel(h,R,g,y)),axDecel:(f,h,b,g=1,y=1)=>{let x=R=>p(f,h,b,g,(v,S)=>v.axDecel(h,S,g,R));return y===1?x(1):ay(x(y),x(1),y)},scrub:(f,h,b,g=1)=>p(f,h,b,g,(y,x)=>y.scrub?.(h,x,g)??0),ay:(f,h,b,g=1)=>{if(u(f),n===1||b===0)return m(v=>v.ay(h,b,g));let y=v=>b>0?v.axAccel(h,0,g):-v.axDecel(h,0,g),x=m(y);if(!(x>0))return m(v=>v.ay(h,b,g));let R=b/x;return m(v=>v.ay(h,R*y(v),g))}}}var xC=new WeakMap;function Py(e,t){let r=xC.get(e);if(!r){let n=Gn(e).regen?hF(t??mr(e)):void 0;r={inp:Ut(e),ev:pn(e),...n?{regen:n}:{}},xC.set(e,r)}return r}function Ly(e,t,r){let n=Py(e,r);return wy(n.inp,n.ev,t,n.regen?{regen:n.regen}:{})}function Dy(e){let t=Wt(e);if(t.mode!=="hydraulic")return null;let r=a=>a.heat?{heat:Vg(a.heat,a.ratio),discs:a.discs}:void 0,n=r(t.hydraulic.front),o=r(t.hydraulic.rear);return n||o?{...n?{front:n}:{},...o?{rear:o}:{}}:null}function _B(e){let t=(r,n)=>n?r.map((o,a)=>Math.max(0,o-n[a])):r;return{front:t(e.front,e.regenFront),rear:t(e.rear,e.regenRear)}}function Ey(e,t,r,n,o,a=ur){if(!e)return null;let s=_B(t);return{...e.front?{front:ad(e.front.heat,e.front.discs,s.front,r,n,o.front,a)}:{},...e.rear?{rear:ad(e.rear.heat,e.rear.discs,s.rear,r,n,o.rear,a)}:{}}}var NB=.5,OB=.02,VB=6,kp=9,RC=1e-9,BB={FL:0,FR:0,RL:0,RR:0};function Iy(e){return e?[...new Set([...e.padCurve.factor,1])].sort((t,r)=>t-r):[1]}function $B(e,t,r){let n=cn(e),o=n.hydraulic;return n.mode!=="hydraulic"||!o?e:{...e,brakes:{...n,hydraulic:{...o,front:{...o.front,padMu:o.front.padMu*t},rear:{...o.rear,padMu:o.rear.padMu*r}}}}}function vC(e,t){let r=e.length;if(r===1||t<=e[0])return{i:0,t:0};if(t>=e[r-1])return{i:r-2,t:1};let n=0;for(;n<r-2&&e[n+1]<=t;)n++;return{i:n,t:(t-e[n])/(e[n+1]-e[n])}}function kC(e,t,r,n,o=()=>0){let a=Array.from({length:kp},(m,p)=>r*p/(kp-1)),s=rl(),{front:i,rear:c}=n,l=a.map(m=>{let p=o(m),d=h=>zn(h,t,m,s).limitAt(0,0,BB,p).ax,f=d(e);return i.map(h=>c.map(b=>{if(h===1&&b===1)return 1;let g=f<0?d($B(e,h,b))/f:1;return Math.abs(g-1)<RC?1:g}))}),u=a[1]-a[0];return{share(m,p,d){if(p===1&&d===1)return 1;let f=u>0?Math.min(kp-2,Math.max(0,Math.floor(m/u))):0,h=u>0?Math.min(1,Math.max(0,(m-a[f])/u)):0,b=vC(i,p),g=vC(c,d),y=R=>{let v=l[R],S=Math.min(i.length-1,b.i+1),A=Math.min(c.length-1,g.i+1),C=v[b.i][g.i]+g.t*(v[b.i][A]-v[b.i][g.i]),F=v[S][g.i]+g.t*(v[S][A]-v[S][g.i]);return C+b.t*(F-C)},x=y(f)+h*(y(Math.min(kp-1,f+1))-y(f));return Math.abs(x-1)<RC?1:x}}}function GB(e,t){let{front:r,rear:n}=t;return(o,a)=>e.share(a,r?.[o]??1,n?.[o]??1)}var KB=e=>(e.front??[]).every(t=>t===1)&&(e.rear??[]).every(t=>t===1);function MC(e,t,r){let n=e(),o=1,a=t(n);if(KB(a))return{lap:n,solves:o,converged:!0};let s={...a.front?{front:a.front.slice()}:{},...a.rear?{rear:a.rear.slice()}:{}},i=!1;for(let c=0;c<VB;c++){let l=e(GB(r,s));o++;let u=Math.abs(l.laptime-n.laptime);if(n=l,u<OB){i=!0;break}a=t(n);let m=(f,h)=>f&&h?f.map((b,g)=>b+NB*((h[g]??1)-b)):f,p=m(s.front,a.front),d=m(s.rear,a.rear);s={...p?{front:p}:{},...d?{rear:d}:{}}}return{lap:n,pads:s,solves:o,converged:i}}function Fo(e,t){let r=e.engine;if(!r||r.gears.length===0||t.length===0)return;let n=e.params,{drivenFront:o,drivenRear:a}=Ma(e),s=ka(n,o,a).effective,i=n.power_scale.value,{up:c,down:l}=e0(r.engine.gearbox),u=r.engine.idleRpm,m=(p,d,f)=>(i*r.force(p,d)+f)/(s+r.inertiaMass(p,d));return{count:r.gears.length,up:c,down:l,kept:t0(r.engine.gearbox),limitRpm:r.engine.limitRpm,best:p=>Ys(r,p,s,vp(t,p)*s,i).gear,share:(p,d)=>{let f=vp(t,p),h=f*s,b=Ys(r,p,s,h,i);if(d===b.gear)return 1;let g=b.accel-f;return g>0?Math.min(1,Math.max(0,(m(p,d,h)-f)/g)):0},rpm:(p,d)=>r.slipping(p,d)?u:r.rpm(p,d),vIdle:p=>r.gears[p]?.vIdle??0}}var SC=new WeakMap;function Ny(e){let t=SC.get(e.ggv);return t===void 0&&(t=Fo(e.vehicle,e.ggv.rows)??null,SC.set(e.ggv,t)),t??void 0}function HB(e){return e.gear&&e.engineRpm&&e.shifting?{gear:e.gear,rpm:e.engineRpm,shifting:e.shifting}:{}}function zB(e,t){return{v:t.v,ax:t.ax,ay:t.ay,s:e.s,x:e.x,y:e.y,...e.gradient.some(r=>r!==0)?{gradient:e.gradient}:{},...e.bank.some(r=>r!==0)?{bank:e.bank}:{},...e.z.some(r=>r!==0)?{z:e.z}:{},...e.mu.some(r=>r!==1)?{mu:e.mu}:{},...t.loadFactor?{loadFactor:t.loadFactor}:{},...t.axScrub?{axScrub:t.axScrub}:{},...HB(t)}}var Sp=class extends Error{constructor(t){super(t),this.name="EventError"}};function YB(e,t){let{ggv:r}=t,n=Bt(t.numerics),o=n.accelStep,a=Math.max(1,Math.round(e.distance/o)),s=li(r,new Array(a+1).fill(0),n);s[0].v=e.vStart??0;for(let f=0;f<s.length-1;f++){let h=s[f],b=s[f+1];h.v>=b.v||(h.ax=r.axAccel(h.v,0),b.v=Math.min(r.vMax,Math.sqrt(Math.max(0,h.v*h.v+2*h.ax*o))))}let i=Ny(t),c=i?np(s.map(f=>f.v),new Array(a).fill(o),!1,i,(f,h,b)=>r.axAccel(h,0,1,b)):void 0;if(c){for(let f=0;f<=a;f++)s[f].v=c.v[f];for(let f=0;f<a;f++)s[f].ax=(s[f+1].v*s[f+1].v-s[f].v*s[f].v)/(2*o)}let l=0;for(let f=0;f<a;f++){let h=s[f].v+s[f+1].v;h>0&&(l+=2*o/h)}let u=s.slice(0,a).map(f=>f.v),m=s.slice(0,a).map(f=>f.ax),p=new Array(a).fill(o),d=p.map((f,h)=>h*o);return{id:e.id,label:e.label,kind:e.kind,time:l,distance:a*o,laps:1,lapTime:l,trace:{v:u,ax:m,ay:new Array(a).fill(0),s:d,x:d,y:new Array(a).fill(0),...c?{gear:c.gear.slice(0,a),rpm:c.rpm.slice(0,a),shifting:c.shifting.slice(0,a)}:{}},energy:EC(t,p,[...u,s[a].v],m,1)}}function WB(e,t){let r=Math.max(1,Math.round(e.laps??1)),[n]=li(t.ggv,[1/e.radius],t.numerics),o=2*Math.PI*e.radius,a=n.v>0?o/n.v:1/0,s=t.ggv.scrub?.(n.v,Math.abs(n.ay))??0,i=EC(t,[o],[n.v,n.v],[0],r,s!==0?{ay:[n.ay],scrub:[s]}:void 0);return{id:e.id,label:e.label,kind:e.kind,time:a*r,distance:o*r,laps:r,lapTime:a,energy:i}}function Ap(e,t){return e.laps!=null?Math.max(1,Math.round(e.laps)):e.distance!=null?Math.max(1,Math.ceil(e.distance/t.length)):1}function jB(e,t){let r=e.distance!=null?t.v_limit_endurance?.value??0:0;return r>0?r/3.6:void 0}function UB(e,t){if(e.distance==null||yt(t.motorModel))return 0;let r=t.endurance_reserve?.value??0;return r>0?Math.min(r,95)/100:0}var AC=1;function PC(e,t,r,n){return{v:r.v,ax:r.ax,ay:r.ay,ds:t.ds,axDrag:hi(e.ggv.rows,r.v),...r.axScrub?{axScrub:r.axScrub}:{},axGrade:n,...t.bank?{bank:t.bank}:{}}}var wC=new WeakMap;function LC(e){let t=e.vehicle.params;if(!t.brakeFade)return null;let r=wC.get(t);if(r===void 0){let n=Dy(t),o=n?Wt(t):null;if(!n||!o||o.mode!=="hydraulic")r=null;else{let a=Py(t,e.vehicle),s=e.ggv.rows,i=kC(a.inp,a.ev,e.vehicle.vMax,{front:Iy(o.hydraulic.front.heat),rear:Iy(o.hydraulic.rear.heat)},c=>hi(s,[c])[0]);r={discs:n,table:i}}wC.set(t,r)}return r}function XB(e,t,r){let n=e.vehicle.params,{soc:o,packTempC:a,launched:s,vCeiling:i}=r,c=e.load?.atSoc(e.vehicle,o,a),l=Ny(e),u=(g,y)=>e.yaw?eC(e.yaw.family.atSoc(e.vehicle,o,a),t,e.yaw.car,e.numerics,{standingStart:s,...g?{driveDerate:g}:{},...y?{brakeFade:y}:{},...i?{vCeiling:i}:{},...c?{load:c}:{},...l?{shifts:l}:{}}):tr(Nl(e.ggv,e.vehicle,o,a),t,e.numerics,{standingStart:s,...g?{driveDerate:g}:{},...y?{brakeFade:y}:{},...i?{vCeiling:i}:{},...c?{load:c}:{},...l?{shifts:l}:{}}),m=ci(t.gradient,t.npts),p=g=>n.motorThermal?gF(e.vehicle,t.ds,e.energyOpts??Kr,y=>u(y,g),o,a,m,t.bank).lap:u(void 0,g),d=LC(e);if(!d)return p();let f=Tl(n),h=r.discC??{front:f,rear:f};return MC(p,g=>{let y=Ey(d.discs,Ly(n,PC(e,t,g,m),e.vehicle),g.v,t.ds,h,f);return{...y?.front?{front:y.front.padFactor}:{},...y?.rear?{rear:y.rear.padFactor}:{}}},d.table).lap}function qB(e,t){let r=jB(e,t.vehicle.params),n=UB(e,t.vehicle.params);return n>0?JB(e,t,n,r):Ol(e,t,r)}function Mp(e,t){let r=e.energy?.remainingFraction??0;return e.incomplete?-t-(1-e.incomplete.lapsCompleted/Math.max(1,e.incomplete.lapsAsked)):r-t}var FC=5,QB=.1,ZB=.005,CC=12;function JB(e,t,r,n){let o=Ol(e,t,n),a=1,s=(f,h,b)=>({...f,energyTarget:{reserve:r,capKmh:h===void 0?null:h*3.6,met:b,solves:a}}),i=Mp(o,r);if(i>=0)return s(o,n,!0);let c=Math.min(n??1/0,t.ggv.vMax),l=c/2,u=Ol(e,t,l);a++;let m=Mp(u,r);for(;m<0&&l>FC&&a<CC;)c=l,i=m,l=Math.max(FC,l/2),u=Ol(e,t,l),a++,m=Mp(u,r);if(m<0)return s(u,l,!1);let d=e5(f=>{let h=Ol(e,t,f);return{run:h,margin:Mp(h,r)}},{lo:l,hi:c,atLo:{run:u,margin:m},fHi:i},CC-a);return a+=d.solves,s(d.run,d.cap,!0)}function e5(e,t,r){let{lo:n,hi:o}=t,a=t.atLo,s=a.margin,i=t.fHi,c=0,l=0;for(;l<r&&o-n>QB&&a.margin>ZB;){let u=o-n,m=Math.min(o-.05*u,Math.max(n+.05*u,n+s*u/(s-i))),p=e(m);l++,p.margin>=0?(n=m,a=p,s=p.margin,c===1&&(i/=2),c=1):(o=m,i=p.margin,c===-1&&(s/=2),c=-1)}return{cap:n,run:a.run,solves:l}}function DC(e,t,r){return r===0?e:e&&!t}function Ol(e,t,r){let n=t.track;if(!n)throw new Sp(`Event "${e.id}" needs a track.`);let o=Ap(e,n),a=e.standingStart??t.standingStart??!1,s=W=>DC(a,n.closed,W),i=t.vehicle.params,c=Cn(ui(i)),l=c.capacityAh,u=yt(i.motorModel)?1:i.soc.value,m=Tl(i),p=ip(c,m),d=0,f=0,h=0,b=0,g=!yt(i.motorModel)&&(t.energyOpts??Kr).regen,y=0,x=0,R=[],v=!1,S=-1/0,A=0,C=0,F=!1,T=-1/0,M=0,k=0,w=-1/0,P=(W,z,Y=1)=>{W.tempMaxC>w&&(w=W.tempMaxC),W.motorTempMaxC!==void 0&&(v=!0,F=!0,W.motorTempMaxC>S&&(S=W.motorTempMaxC),W.motorTempMaxC>T&&(T=W.motorTempMaxC),A+=(W.motorDerateTimeFrac??0)*z,M+=(W.motorDerateTimeFrac??0)*z,C+=(W.motorLossKwh??0)/Y,k+=(W.motorLossKwh??0)/Y)},L=null,E,_=Dy(i),D={front:m,rear:m},I=null,N=LC(t)!==null,O=(W,z)=>N&&(Math.abs(W.front-z.front)>AC||Math.abs(W.rear-z.rear)>AC),V=(W,z,Y)=>{let te=my(i,W,z);if(I&&I.launch===Y&&!n5(te,I.pw)&&!O(D,I.discC))return I.lap;let j=XB(t,n,{soc:W,packTempC:z,launched:Y,...r?{vCeiling:r}:{},...N?{discC:D}:{}});return I={pw:te,launch:Y,discC:D,lap:j},j},H=ci(n.gradient,n.npts),U=(W,z,Y)=>mi(t.vehicle,n.ds,W.v,W.ax,t.energyOpts,z,Y,void 0,H,void 0,{ay:W.ay,bank:n.bank,...W.axScrub?{scrub:W.axScrub}:{}}),G=new WeakMap,B=(W,z)=>{let Y=G.get(W);return Y||(Y=Ly(i,PC(t,n,W,H),t.vehicle),G.set(W,Y)),Ey(_,Y,W.v,n.ds,z,m)},q=(W,z,Y)=>{let te=`${(100*Y/n.npts).toFixed(0)} % of the way through lap ${W+1}`,j=z.cutoffAt>=0&&z.cutoffAt<=z.emptyAt;return{lapsCompleted:W,lapsAsked:o,why:j?`the pack reached its ${c.voltageFloor.toFixed(0)} V cut-off ${te}`:`the pack ran out ${te}`}};for(let W=0;W<o;W++){if(u<=0){E={lapsCompleted:W,lapsAsked:o,why:"the pack was empty"};break}let z=s(W),Y=u,te=p;F=!1,T=-1/0,M=0,k=0,w=-1/0;let j=V(u,p,z),X=U(j,u,p);if(X.emptyAt>=0){E=q(W,X,X.emptyAt);break}let pe=V(X.socEnd,X.tempEndC,z).laptime-j.laptime,ue,ie,ke,Ie,Ke,oe,se=p,xe=-1,fe=null,Fe=1;if(pe<=_y)ue=j.laptime,ie=X.net,ke=X.drive,Ie=X.regen,Ke=X.loss,oe=X.chargeAh,se=X.tempEndC,P(X,ue),Fe=1;else{let ae=Math.min(t5,Math.max(2,Math.ceil(pe/(2*_y))));Fe=ae;let Me=u,be=p;ue=0,ie=0,ke=0,Ie=0,Ke=0,oe=0;for(let ge=0;ge<ae;ge++){let ye=V(Me,be,z),ce=U(ye,Me,be),Ae=ce.emptyAt>=0?ce.emptyAt/n.npts:1;if(Ae*ae<1){xe=Math.round(n.npts*(ge/ae+Ae)),fe=ce;break}if(ue+=ye.laptime/ae,P(ce,ye.laptime/ae,ae),ie+=ce.net/ae/Ae,ke+=ce.drive/ae/Ae,Ie+=ce.regen/ae/Ae,Ke+=ce.loss/ae/Ae,oe+=ce.chargeAh/ae/Ae,Me-=ce.chargeAh/ae/Ae/l,be+=(ce.tempEndC-be)/ae,Me<=0){xe=Math.round(n.npts*(ge+1)/ae),fe=ce;break}}if(se=be,xe>=0&&fe){E=q(W,fe,xe);break}u=Me}d+=ue,f+=ie,h+=ke,b+=Ie,y+=Ke,x+=oe,pe<=_y&&(u=X.socEnd),p=se;let Re=_?B(j,D):null;Re&&(D={front:Re.front?.endC??D.front,rear:Re.rear?.endC??D.rear}),R.push({lap:W+1,time:ue,elapsed:d,entryTime:j.laptime,socStart:Y,socEnd:u,packTempStartC:te,packTempEndC:p,packTempMaxC:Number.isFinite(w)?w:te,energyKwh:ie,driveKwh:ke,...g?{regenKwh:Ie}:{},lossKwh:Ke,chargeAh:oe,launched:z,substeps:Fe,...r?{vCeiling:r}:{},...F?{motor:{peakWindingC:T,derateTimeFrac:ue>0?M/ue:0,lossKwh:k}}:{},...Re?{brakes:{...Re.front?{front:TC(Re.front)}:{},...Re.rear?{rear:TC(Re.rear)}:{}}}:{}}),L=j}if(!L){let W=Ny(t);L=tr(Nl(t.ggv,t.vehicle,u),n,t.numerics,{standingStart:a,...t.load?{load:t.load.atSoc(t.vehicle,u)}:{},...W?{shifts:W}:{}}),E=E??{lapsCompleted:0,lapsAsked:o,why:"the pack was empty"}}let re=R.length;return{id:e.id,label:e.label,kind:e.kind,time:d,distance:n.length*re,laps:re,lapTime:L.laptime,trace:zB(n,L),energy:{consumed:f,drive:h,...g?{regen:b}:{},loss:y,...yt(i.motorModel)?{}:{native:{value:x,unit:"Ah"}},remainingFraction:yt(i.motorModel)?1:u,...v?{motor:{peakWindingC:S,derateTimeFrac:d>0?A/d:0,lossKwh:C}}:{}},lapLog:R,...E?{incomplete:E}:{}}}var _y=.05;function TC(e){let t=r=>e.workJ>0?r/e.workJ:0;return{startC:e.startC,endC:e.endC,maxC:e.maxC,workKj:e.workJ/1e3,coldShare:t(e.coldWorkJ),hotShare:t(e.hotWorkJ)}}var t5=4,r5=.001;function n5(e,t){return e===t?!1:!Number.isFinite(e)||!Number.isFinite(t)?!0:Math.abs(e-t)>r5*Math.max(1,Math.abs(t))}function EC(e,t,r,n,o,a){return o5(e,t,o,()=>({v:r,ax:n,...a?{lateral:a}:{}}))}function o5(e,t,r,n){let o=e.energyOpts,a=e.vehicle.params.soc.value,s=0,i=0,c=0,l=0,u=0;for(let p=0;p<r;p++){let d=n(p),f=mi(e.vehicle,t,d.v,d.ax,o,a,void 0,void 0,void 0,void 0,d.lateral);s+=f.net,i+=f.drive,c+=f.regen,l+=f.loss,u+=f.chargeAh,a=f.socEnd}if(yt(e.vehicle.params.motorModel))return{consumed:s,drive:i,loss:l,remainingFraction:1};let m=(o??Kr).regen;return{consumed:s,drive:i,...m?{regen:c}:{},loss:l,native:{value:u,unit:"Ah"},remainingFraction:a}}function IC(e,t){switch(e.kind){case"straightLineAccel":return YB(e,t);case"constantRadius":return WB(e,t);case"trackLap":return qB(e,t)}}function Oy(e,t){let r={};for(let n of e)r[n.id]=IC(n,t);return r}function _C(e,t){if(e.kind!=="trackLap")return e;let{distance:r,...n}=e;return{...n,laps:Math.max(1,Math.round(t))}}function Aa(e,t,r,n,o="twoTrack",a){let s=1/0,i=-1/0;for(let p of r){let d=wl(p);if(!d)continue;let f=eF(d,tr(t,p,n).v);f&&(s=Math.min(s,f.lo),i=Math.max(i,f.hi))}if(!(i>=s))return;let c=tF({lo:s,hi:i}),l=c.join(","),u=a?.get(l);if(u)return u;let m=yC(e,c,t,o);return a?.set(l,m),m}var Vl=e=>e.distance/Math.max(1,e.laps);function Bl(e){let t=e.s.length,r=new Array(t);for(let n=0;n<t;n++)r[n]=(n<t-1?e.s[n+1]:e.length)-e.s[n];return r}var a5=e=>e.v.map(t=>t*3.6),s5=e=>e.ax.map(t=>t/9.81),i5=e=>e.ay.map(t=>t/9.81),c5=e=>e.ay.map((t,r)=>e.v[r]>1e-6?t/(e.v[r]*e.v[r]):0),wp=(e,t,r)=>e?.slice()??new Array(t.s.length).fill(r),l5=e=>wp(e.z,e,0),u5=e=>e.gradient?e.gradient.map(t=>100*Math.tan(t*Math.PI/180)):wp(void 0,e,0),m5=e=>wp(e.bank,e,0),d5=e=>wp(e.mu,e,1);function p5(e){let t=e.s.length,r=Bl(e),n=new Array(t);n[0]=0;for(let o=1;o<t;o++)n[o]=n[o-1]+2*r[o-1]/(e.v[o-1]+e.v[o]);return n}var Vy=[{name:"s",unit:"m",what:"distance along the lap"},{name:"ds",unit:"m",what:"length of the segment starting at this sample"},{name:"t",unit:"s",what:"elapsed time"},{name:"v",unit:"m/s",what:"speed"},{name:"speed",unit:"km/h",what:"speed"},{name:"ax",unit:"m/s\xB2",what:"longitudinal acceleration"},{name:"ay",unit:"m/s\xB2",what:"lateral acceleration"},{name:"axg",unit:"g",what:"longitudinal acceleration"},{name:"ayg",unit:"g",what:"lateral acceleration"},{name:"curv",unit:"1/m",what:"signed curvature, ay/v\xB2"},{name:"z",unit:"m",what:"elevation of the road"},{name:"grade",unit:"%",what:"grade of the road, uphill +"},{name:"bank",unit:"\xB0",what:"bank of the road, left side up +"},{name:"grip",unit:"-",what:"grip scale of the road, 1 = the tyre\u2019s own"}];function NC(e){let t=Bl(e);return{ds:t,vars:{s:e.s,ds:t,t:p5(e),v:e.v,speed:a5(e),ax:e.ax,ay:e.ay,axg:s5(e),ayg:i5(e),curv:c5(e),z:l5(e),grade:u5(e),bank:m5(e),grip:d5(e)}}}function Fp(e){let t=e.rows?pC(e.rows,e.v):void 0;return{v:e.v,ax:e.ax,ay:e.ay,ds:e.ds,...e.rows?{axDrag:hi(e.rows,e.v)}:{},...e.axScrub?{axScrub:e.axScrub}:{},axGrade:ci(e.gradient,e.v.length),...e.bank?{bank:e.bank}:{},...e.loadFactor?{loadFactor:e.loadFactor}:{},...e.mu?.some(r=>r!==1)?{mu:e.mu}:{},...t?{wheelMotor:t}:{}}}function OC(e,t){return Fp({v:e.v,ax:e.ax,ay:e.ay,ds:Bl({s:e.s,length:t}),gradient:e.gradient,bank:e.bank,loadFactor:e.loadFactor})}function VC(e,t){let r=Ut(e);return{pastTurnover:jF(r,pn(e),t),...e.aeroModel?{aeroOutside:WF(r,t)}:{}}}var Cp="Flying lap";function By(e,t){return e.kind!=="trackLap"||e.label!==Cp?e.label:e.standingStart??t?"Run":e.label}function f5(e){let t=Ut(e);return{yawInertia:t.yawInertia??0,massTotal:t.massTotal,wheelbase:t.wheelbase/1e3}}function h5(e,t,r){let n=e.params,o=n.ggvMode??"twoTrack",a=n.quasiTransient?bC(e,!1,o):null,s=a?a.steady:bn(e,!1,o),i=t?Aa(e,s,[t],r,o):void 0;return{ggv:s,...a?{yaw:{family:a,car:f5(n)}}:{},...i?{load:i}:{}}}function b5(e,t){let r=t.lapCounts,n=t.standingStart??!1,o=!1,a=e.events.map(s=>{let i=r?.[s.id]!=null?_C(s,r[s.id]):s,c=By(i,n),l=c===i.label?i:{...i,label:c};return l!==s&&(o=!0),l});return o?a:e.events}function g5(e,t,r){let n=r.lapCounts;if(!(!n||!r.track))for(let o of t.events){let a=n[o.id];if(o.kind!=="trackLap"||a==null)continue;let s=Ap(o,r.track),i=Math.max(1,Math.round(a));i!==s&&e[o.id]&&(e[o.id]={...e[o.id],lapsOverridden:{asked:i,defined:s}})}}function y5(e,t){for(let[r,n]of Object.entries(e))n.trace&&(e[r]={...n,...VC(t,OC(n.trace,Vl(n)))})}function $l(e,t,r={}){let n=mr(e),o=h5(n,r.track,r.numerics),{ggv:a}=o,s=Oy(b5(t,r),{vehicle:n,...o,track:r.track,energyOpts:Gn(e,r.energyOpts),numerics:r.numerics,standingStart:r.standingStart});return g5(s,t,r),y5(s,n.params),{name:e.name,rulesetId:t.id,events:s,ggv:a}}function $y(e){return{...e,ggv:{rows:e.ggv.rows,vMax:e.ggv.vMax,surf:e.ggv.surf}}}var Gy=["<","<=",">",">=","==","!="],it=class extends Error{at;constructor(t,r){super(t),this.name="ExprError",this.at=r}},Gl=e=>e>="0"&&e<="9",BC=e=>/[A-Za-z_]/.test(e),x5=e=>/[A-Za-z0-9_]/.test(e);function R5(e){let t=[],r=0;for(;r<e.length;){let n=e[r];if(n===" "||n===" "||n===`
|
|
224
|
+
`||n==="\r"){r++;continue}if(Gl(n)||n==="."&&Gl(e[r+1]??"")){let o=r;for(;r<e.length&&(Gl(e[r])||e[r]===".");)r++;if(e[r]==="e"||e[r]==="E"){let i=r;if(r++,(e[r]==="+"||e[r]==="-")&&r++,Gl(e[r]??""))for(;r<e.length&&Gl(e[r]);)r++;else r=i}let a=e.slice(o,r),s=Number(a);if(!Number.isFinite(s))throw new it(`"${a}" is not a number`,o);t.push({t:"num",value:s,at:o});continue}if(BC(n)){let o=r;for(;;){for(;r<e.length&&x5(e[r]);)r++;if(e[r]==="."&&BC(e[r+1]??""))r++;else break}t.push({t:"name",value:e.slice(o,r),at:o});continue}if("<>=!".includes(n)){let o=e.slice(r,r+2);if(Gy.includes(o)){t.push({t:"op",value:o,at:r}),r+=2;continue}if(n==="<"||n===">"){t.push({t:"op",value:n,at:r}),r++;continue}throw new it(n==="="?'Compare with "==", not "="':'Write not(x) rather than "!x"',r)}if("+-*/^(),".includes(n)){t.push({t:"op",value:n,at:r}),r++;continue}throw new it(`"${n}" is not something this expression can contain`,r)}return t.push({t:"end",at:e.length}),t}function Ky(e){let t=R5(e),r=0,n=()=>t[r],o=h=>{let b=n();return b.t==="op"&&b.value===h},a=h=>o(h)?(r++,!0):!1,s=(h,b)=>{if(!a(h))throw new it(`Expected ${b} here`,n().at)};function i(){let h=c(),b=n();if(b.t!=="op"||!Gy.includes(b.value))return h;r++;let g={kind:"binary",op:b.value,left:h,right:c(),at:b.at},y=n();if(y.t==="op"&&Gy.includes(y.value))throw new it("Comparisons do not chain \u2014 write and(a < b, b < c)",y.at);return g}function c(){let h=l();for(;;){let b=n().at;if(a("+"))h={kind:"binary",op:"+",left:h,right:l(),at:b};else if(a("-"))h={kind:"binary",op:"-",left:h,right:l(),at:b};else return h}}function l(){let h=u();for(;;){let b=n().at;if(a("*"))h={kind:"binary",op:"*",left:h,right:u(),at:b};else if(a("/"))h={kind:"binary",op:"/",left:h,right:u(),at:b};else return h}}function u(){return a("-")?{kind:"unary",op:"-",arg:u()}:a("+")?u():m()}function m(){let h=p(),b=n().at;return a("^")?{kind:"binary",op:"^",left:h,right:u(),at:b}:h}function p(){let h=n();if(h.t==="num")return r++,{kind:"num",value:h.value};if(h.t==="name"){if(r++,a("(")){let b=[];if(!o(")"))do b.push(i());while(a(","));return s(")","a closing bracket"),{kind:"call",name:h.value,args:b,at:h.at}}return{kind:"var",name:h.value,at:h.at}}if(a("(")){let b=i();return s(")","a closing bracket"),b}throw h.t==="end"?new it("The expression ends before it is finished",h.at):new it(`"${h.value}" cannot start a value`,h.at)}let d=i(),f=n();if(f.t!=="end")throw new it(`"${f.value}" is left over \u2014 check for a missing operator`,f.at);return d}function Hy(e){let t=new Set,r=n=>{n.kind==="var"?t.add(n.name):n.kind==="call"?n.args.forEach(r):n.kind==="unary"?r(n.arg):n.kind==="binary"&&(r(n.left),r(n.right))};return r(e),t}var Kl=(e,t)=>typeof e=="number"?new Array(t).fill(e):e;function v5(e){let t=1;for(let r of e)Array.isArray(r)&&(t=Math.max(t,r.length));return t}function br(e,t){if(e.every(a=>typeof a=="number"))return t(...e);let r=v5(e),n=e.map(a=>Kl(a,r)),o=new Array(r);for(let a=0;a<r;a++)o[a]=t(...n.map(s=>s[Math.min(a,s.length-1)]));return o}var ct=(e,t)=>({arity:e,call:r=>br(r,t)}),wa=e=>e!==0&&!Number.isNaN(e),gn=e=>e?1:0;function $C(e,t,r){let n=GC(t,r,"integrate"),o=n.length,a=Kl(e,o),s=new Array(o),i=0;for(let c=0;c<o;c++){s[c]=i;let l=a[Math.min(c,a.length-1)],u=a[Math.min(c+1,a.length-1)];i+=(l+u)/2*n[c]}return s}function GC(e,t,r){if(!e.ds||e.ds.length===0)throw new it(`${r}() needs to know the sample spacing, and this context has none`,t);return e.ds}var Tp={abs:ct(1,Math.abs),sqrt:ct(1,Math.sqrt),sign:ct(1,Math.sign),floor:ct(1,Math.floor),ceil:ct(1,Math.ceil),round:ct(1,Math.round),exp:ct(1,Math.exp),log:ct(1,Math.log),sin:ct(1,Math.sin),cos:ct(1,Math.cos),tan:ct(1,Math.tan),atan:ct(1,Math.atan),atan2:ct(2,Math.atan2),hypot:ct(2,Math.hypot),min:ct(2,Math.min),max:ct(2,Math.max),clamp:ct(3,(e,t,r)=>Math.min(r,Math.max(t,e))),if:ct(3,(e,t,r)=>wa(e)?t:r),and:ct(2,(e,t)=>gn(wa(e)&&wa(t))),or:ct(2,(e,t)=>gn(wa(e)||wa(t))),not:ct(1,e=>gn(!wa(e))),finite:ct(1,e=>gn(Number.isFinite(e))),peak:{arity:1,call:([e])=>{let t=Array.isArray(e)?e:[e],r=0;for(let n of t)r=Math.max(r,Math.abs(n));return r}},mean:{arity:1,call:([e])=>{let t=Array.isArray(e)?e:[e];return t.length?t.reduce((r,n)=>r+n,0)/t.length:0}},total:{arity:1,call:([e],t)=>{let r=$C(e,t,0),n=t.ds,o=Kl(e,n.length),a=n.length-1;return r[a]+(o[a]+o[0])/2*n[a]}},integrate:{arity:1,call:([e],t)=>$C(e,t,0)},cum:{arity:1,call:([e],t)=>{let r=t.ds?.length??(Array.isArray(e)?e.length:1),n=Kl(e,r),o=new Array(r),a=0;for(let s=0;s<r;s++)a+=n[Math.min(s,n.length-1)],o[s]=a;return o}},deriv:{arity:1,call:([e],t)=>{let r=GC(t,0,"deriv"),n=r.length,o=Kl(e,n),a=new Array(n);for(let s=0;s<n;s++){let i=Math.max(0,s-1),c=Math.min(n-1,s+1),l=0;for(let u=i;u<c;u++)l+=r[u];a[s]=l>0?(o[c]-o[i])/l:0}return a}}},bi={g:9.81,pi:Math.PI,e:Math.E,nan:NaN,inf:1/0},Hl={fleetmin:"min",fleetmax:"max"};function Fa(e){switch(e.kind){case"call":return Object.hasOwn(Hl,e.name)||e.args.some(Fa);case"unary":return Fa(e.arg);case"binary":return Fa(e.left)||Fa(e.right);default:return!1}}var k5=e=>typeof e=="number"?`${e}`:`between ${e[0]} and ${e[1]}`;function M5(e,t){let r=Array.from({length:t.length+1},(n,o)=>o);for(let n=1;n<=e.length;n++){let o=[n];for(let a=1;a<=t.length;a++)o[a]=Math.min(r[a]+1,o[a-1]+1,r[a-1]+(e[n-1]===t[a-1]?0:1));r=o}return r[t.length]}function S5(e,t){let r=t.map(c=>({k:c,d:M5(c,e)})).filter(c=>c.d<=Math.max(1,Math.floor(e.length/4))),n=Math.min(...r.map(c=>c.d)),o=r.filter(c=>c.d===n).map(c=>c.k).slice(0,3);if(o.length)return`"${e}" is not a name here \u2014 did you mean ${o.join(" or ")}?`;let a=e.indexOf(".");if(a>0){let c=t.filter(l=>l.startsWith(e.slice(0,a+1)));if(c.length)return`"${e}" is not a name here. ${e.slice(0,a)} has ${c.join(", ")}`}let s=new Set,i=[];for(let c of t){let l=c.indexOf(".");l>0?s.add(`${c.slice(0,l)}.\u2026`):i.push(c)}return`"${e}" is not a name here. Available: ${[...s,...i].join(", ")}`}function yn(e,t){switch(e.kind){case"num":return e.value;case"var":{if(Object.hasOwn(t.vars,e.name))return t.vars[e.name];if(Object.hasOwn(bi,e.name))return bi[e.name];let r=[...Object.keys(t.vars),...Object.keys(bi)].sort();throw new it(S5(e.name,r),e.at)}case"unary":return br([yn(e.arg,t)],r=>-r);case"binary":{let r=yn(e.left,t),n=yn(e.right,t);switch(e.op){case"+":return br([r,n],(o,a)=>o+a);case"-":return br([r,n],(o,a)=>o-a);case"*":return br([r,n],(o,a)=>o*a);case"/":return br([r,n],(o,a)=>a===0?0:o/a);case"^":return br([r,n],(o,a)=>o**a);case"<":return br([r,n],(o,a)=>gn(o<a));case"<=":return br([r,n],(o,a)=>gn(o<=a));case">":return br([r,n],(o,a)=>gn(o>a));case">=":return br([r,n],(o,a)=>gn(o>=a));case"==":return br([r,n],(o,a)=>gn(o===a));case"!=":return br([r,n],(o,a)=>gn(o!==a))}break}case"call":{let r=Object.hasOwn(Hl,e.name)?Hl[e.name]:void 0;if(r){if(!t.fleet)throw new it(`${e.name}() compares the cars in a field, so it belongs in a ruleset's KPIs, not in a channel`,e.at);if(e.args.length!==1)throw new it(`${e.name}() takes 1 argument, not ${e.args.length}`,e.at);return t.fleet(e.args[0],r,e.at)}let n=Object.hasOwn(Tp,e.name)?Tp[e.name]:void 0;if(!n){let s=[...Object.keys(Tp),...t.fleet?Object.keys(Hl):[]];throw new it(`There is no function called "${e.name}". Available: ${s.sort().join(", ")}`,e.at)}let o=typeof n.arity=="number"?n.arity:n.arity[0],a=typeof n.arity=="number"?n.arity:n.arity[1];if(e.args.length<o||e.args.length>a)throw new it(`${e.name}() takes ${k5(n.arity)} argument${o===1&&a===1?"":"s"}, not ${e.args.length}`,e.at);return n.call(e.args.map(s=>yn(s,t)),t)}}throw new it("Unreachable node",0)}var gi=e=>Number.isFinite(e)?e:NaN,zy=[{name:"time",unit:"s",what:"the whole event, every lap",read:e=>gi(e?.time)},{name:"lapTime",unit:"s",what:"one lap \u2014 the last one completed",read:e=>gi(e?.lapTime)},{name:"distance",unit:"m",what:"distance covered",read:e=>gi(e?.distance)},{name:"laps",unit:"-",what:"laps completed",read:e=>gi(e?.laps)},{name:"energy",unit:"kWh",what:"energy drawn over the event",read:e=>gi(e?.energy?.consumed)},{name:"remaining",unit:"-",what:"share of the pack or tank left afterwards",read:e=>gi(e?.energy?.remainingFraction)},{name:"finished",unit:"-",what:"1 when the car ran the whole event, else 0",read:e=>e&&!e.incomplete?1:0}],KC=/^[A-Za-z_][A-Za-z0-9_]*$/,A5=new Set([...Object.keys(bi),...Vy.map(e=>e.name)]);function Pp(e,t,r=[]){let n=[],o=new Set(r),a=t.map(b=>b.id),s=new Set;for(let b of a)KC.test(b)?s.has(b)&&n.push({key:null,message:`Two events are called "${b}"`}):n.push({key:null,message:`Event id "${b}" must be one word to be read as ${b}.time`}),s.add(b);let i=new Map,c=new Map;for(let b of e){if(!KC.test(b.key)){n.push({key:b.key,message:`"${b.key}" must be one word \u2014 letters, digits and _`});continue}if(A5.has(b.key)||o.has(b.key)){n.push({key:b.key,message:`"${b.key}" already means something in a formula \u2014 choose another key`});continue}if(i.has(b.key)){n.push({key:b.key,message:`Two KPIs are called "${b.key}"`});continue}i.set(b.key,b),b.over!=null&&!a.includes(b.over)&&n.push({key:b.key,message:`There is no event "${b.over}" to read the lap of. Events: ${a.join(", ")}`});try{c.set(b.key,Ky(b.expr))}catch(g){let y=g;n.push({key:b.key,message:y.message,at:y.at})}}let l=new Map;for(let[b,g]of c)l.set(b,[...Hy(g)].filter(y=>i.has(y)));let u=new Set,m=[];for(;;){let b=[...c.keys()].find(g=>!u.has(g)&&l.get(g).every(y=>u.has(y)||!c.has(y)));if(!b)break;u.add(b),m.push(b)}for(let b of c.keys()){if(u.has(b))continue;let g=w5(b,l);n.push({key:b,message:g?`"${b}" depends on itself, through ${g.join(" \u2192 ")}`:`"${b}" reads a KPI that depends on itself`})}let p=(b,g,y)=>{throw new it("fleetmin() and fleetmax() cannot sit inside one another",y)},d=new Set,f={};for(let b of a)for(let g of zy)f[`${b}.${g.name}`]=1;for(let b of o)f[b]=1;for(let b of i.keys())f[b]=1;let h={};for(let b of Vy)h[b.name]=[1,1];for(let b of m){let g=i.get(b),y=c.get(b);(Fa(y)||l.get(b).some(S=>d.has(S)))&&d.add(b);let x=g.over!=null?{...f,...h}:f,R=g.over!=null?[1,1]:void 0,v=(S,A,C)=>{let F=yn(S,{vars:x,ds:R,fleet:p});if(Array.isArray(F))throw new it("fleetmin() and fleetmax() compare one number per car \u2014 reduce the channel first, e.g. peak(v)",C);return F};try{let S=yn(y,{vars:x,ds:R,fleet:v});Array.isArray(S)&&n.push({key:b,message:"A KPI is one number per car \u2014 reduce the channel, e.g. peak(v) or mean(v)",at:0})}catch(S){let A=S;n.push({key:b,message:A.message,at:A.at})}}return n.length?{plan:null,problems:n}:{plan:{order:m.map(b=>({def:i.get(b),node:c.get(b)})),field:d,eventIds:a},problems:n}}function w5(e,t){let r=[e],n=o=>{for(let a of t.get(o)??[]){if(a===e)return!0;if(!r.includes(a)){if(r.push(a),n(a))return!0;r.pop()}}return!1};return n(e)?[...r,e]:null}function F5(e,t,r={}){let n={...r};for(let o of e.eventIds){let a=t.events[o];for(let s of zy)n[`${o}.${s.name}`]=s.read(a)}return{vars:n,laps:new Map,events:t.events}}function HC(e,t){if(t.over==null)return{vars:e.vars};let r=e.laps.get(t.over);if(r===void 0){let n=e.events[t.over];r=n?.trace?NC({...n.trace,length:Vl(n)}):null,e.laps.set(t.over,r)}return r?{vars:{...e.vars,...r.vars},ds:r.ds}:null}var zC=e=>Array.isArray(e)?NaN:e;function YC(e,t,r,n={}){let o=Object.keys(t),a=o.map(i=>F5(e,t[i],n[i]));for(let{def:i,node:c}of e.order){let l=e.field.has(i.key);if(l&&!r){for(let p of a)p.vars[i.key]=NaN;continue}let u=new Map,m=(p,d)=>{let f=u.get(p);if(f!==void 0)return f;let h=NaN;for(let b of a){let g=HC(b,i);if(!g)continue;let y=zC(yn(p,g));Number.isFinite(y)&&(Number.isNaN(h)||(d==="min"?y<h:y>h))&&(h=y)}return u.set(p,h),h};for(let p of a){let d=HC(p,i);p.vars[i.key]=d?zC(yn(c,l?{...d,fleet:m}:d)):NaN}}let s={};return o.forEach((i,c)=>{let l={};for(let{def:u}of e.order)l[u.key]=a[c].vars[u.key];s[i]=l}),s}function zl(e,t,r){return YC(e,t,!0,r)}function Yy(e,t,r){return YC(e,{car:t},!1,r?{car:r}:void 0).car}var Lp=class extends Error{problems;constructor(t,r){super(`Ruleset "${t}" does not compile:
|
|
225
225
|
`+r.map(n=>` ${n.key?`${n.key}: `:""}${n.message}`).join(`
|
|
226
|
-
`)),this.name="RulesetDefError",this.problems=r}},Yl=e=>typeof e=="number"&&Number.isFinite(e),zl=e=>Yl(e)&&e>0,gr=(e,t)=>e===void 0||t(e);function w5(e){let t=[],r=(o,a=null)=>t.push({key:a,message:o});if(typeof e.id!="string"||e.id===""?r("A ruleset needs an id"):/^[A-Za-z0-9_-]+$/.test(e.id)||r(`The id "${e.id}" is letters, digits, "-" and "_" only`),typeof e.label!="string"&&r("A ruleset needs a label"),typeof e.description!="string"&&r("A ruleset needs a description, even an empty one"),Array.isArray(e.events)||r("A ruleset\u2019s events are a list"),Array.isArray(e.kpis)||r("A ruleset\u2019s KPIs are a list"),t.length)return t;for(let o of e.events){let a=o,s=typeof a?.id=="string"?`Event "${a.id}"`:"An event";if(typeof a!="object"||a===null||typeof a.id!="string"||typeof a.label!="string"){r(`${s} needs an id and a label`);continue}switch(a.kind){case"straightLineAccel":zl(a.distance)||r(`${s} needs a distance above zero, in metres`),gr(a.vStart,i=>Yl(i)&&i>=0)||r(`${s}'s entry speed must be zero or more`);break;case"constantRadius":zl(a.radius)||r(`${s} needs a radius above zero, in metres`),gr(a.laps,i=>Yl(i)&&i>=1)||r(`${s} runs at least one lap`);break;case"trackLap":gr(a.laps,i=>Yl(i)&&i>=1)||r(`${s} runs at least one lap`),gr(a.distance,zl)||r(`${s}'s distance must be above zero, in metres`),gr(a.standingStart,i=>typeof i=="boolean")||r(`${s}'s standing start is yes or no`);break;default:r(`${s} is of a kind this build does not run: ${String(a.kind)}`)}}for(let o of e.kpis){let a=o;if(typeof a!="object"||a===null||typeof a.key!="string"){r("A KPI needs a key");continue}let s=a.key;typeof a.expr!="string"&&r("Needs a formula",s),typeof a.label!="string"&&r("Needs a label",s),gr(a.unit,i=>typeof i=="string")||r("Its unit is text",s),gr(a.over,i=>typeof i=="string")||r("Names its event by id",s),gr(a.format,i=>i==="time"||i==="points")||r("Is shown as a time, as points, or as a number",s),gr(a.max,Yl)||r("Its maximum is a number",s),gr(a.lowerBetter,i=>typeof i=="boolean")||r("Lower is better, or it is not",s),gr(a.hidden,i=>typeof i=="boolean")||r("Is hidden, or it is not",s)}gr(e.track?.minTurnRadius,zl)||r("The tightest turn the rules allow is a radius above zero");let n=e.battery;for(let o of["packVoltageMax","segmentVoltageMax","powerLimitKw"])gr(n?.[o],zl)||r(`The pack's ${o} must be above zero`);if(e.score!==void 0){let o=e.score?.parts;typeof e.score?.total!="string"||typeof o!="object"||o===null||Array.isArray(o)?r("The score names its total and its parts"):Object.values(o).every(a=>typeof a=="string")||r("Each part of the score names a KPI")}return t}function YC(e){let t=w5(e);if(t.length)return{plan:null,problems:t};let r=[];e.events.length===0&&r.push({key:null,message:"A ruleset runs at least one event"});let n=e.events.map(i=>i.id);e.traceEventId!=null&&!n.includes(e.traceEventId)&&r.push({key:null,message:`The plotted event "${e.traceEventId}" is not one of this ruleset's events`});let{plan:o,problems:a}=Tp(e.kpis,e.events);r.push(...a);let s=new Set(e.kpis.map(i=>i.key));if(e.score){s.has(e.score.total)||r.push({key:null,message:`The total "${e.score.total}" is not one of this ruleset's KPIs`});let i=Object.entries(e.score.parts);i.length===0&&r.push({key:null,message:"A ruleset that awards points names at least one part"});for(let[c,l]of i)s.has(l)||r.push({key:null,message:`The part "${c}" reads "${l}", which is not one of this ruleset's KPIs`})}return{plan:r.length?null:o,problems:r}}function Lp(e){return YC(e).problems}var Yy=e=>Number.isFinite(e)?e:NaN;function F5(e){return e.unit&&e.format!=="time"?`${e.label} (${e.unit})`:e.label}function Co(e){let t=structuredClone(e),{plan:r,problems:n}=YC(t);if(!r)throw new Pp(t.id,n);let o=new WeakMap,a=d=>{let f=o.get(d);return f||(f=zy(r,d),o.set(d,f)),f},s=new Map(t.kpis.map(d=>[d.key,d])),i=new Map;for(let[d,f]of Object.entries(t.score?.parts??{}))i.has(f)||i.set(f,d);let c=d=>(f,h)=>{if(!h)return NaN;let b=h.kpis?.[d];if(b!==void 0)return Yy(b);let g=h,y=i.get(d);return y!==void 0?Yy(g.parts?.[y]):d===t.score?.total?Yy(g.total):NaN},l=t.kpis.filter(d=>!d.hidden).map(d=>{let f=r.field.has(d.key);return{key:d.key,label:F5(d),lowerBetter:d.lowerBetter??!1,...d.format?{format:d.format}:{},...f?{field:!0}:{},value:f?c(d.key):h=>a(h)[d.key]}}),u=t.score,m=u?d=>{let f=Hl(r,d),h={};for(let[b,g]of Object.entries(f)){let y={},x={};for(let[R,v]of Object.entries(u.parts)){y[R]=g[v];let S=s.get(v)?.max;S!=null&&(x[R]=S)}h[b]={total:g[u.total],parts:y,...Object.keys(x).length?{maxima:x}:{},kpis:Object.fromEntries(t.kpis.map(R=>[R.key,g[R.key]]))}}return h}:void 0,p=m||(r.field.size>0?d=>{let f=Hl(r,d),h={};for(let[b,g]of Object.entries(f))h[b]={kpis:Object.fromEntries(t.kpis.map(y=>[y.key,g[y.key]]))};return h}:void 0);return{id:t.id,label:t.label,description:t.description,events:t.events,metrics:l,...t.track?{track:t.track}:{},...t.battery?{battery:t.battery}:{},...t.traceEventId?{traceEventId:t.traceEventId}:{},...m?{score:m}:{},...p?{field:p}:{},definition:t}}var zr={accel:"accel",skidpad:"skidpad",autocross:"autocross",endurance:"endurance"},WC=[{kind:"straightLineAccel",id:zr.accel,label:"Acceleration (75 m)",distance:75},{kind:"constantRadius",id:zr.skidpad,label:"Skidpad",radius:8.375},{kind:"trackLap",id:zr.autocross,label:"Autocross (1 lap)",laps:1},{kind:"trackLap",id:zr.endurance,label:"Endurance (22 km)",distance:22e3}],jC=[{key:"autocross",label:"Autocross lap",format:"time",lowerBetter:!0,expr:"autocross.time"},{key:"accel",label:"Acceleration",format:"time",lowerBetter:!0,expr:"accel.time"},{key:"skidpad",label:"Skidpad lap",format:"time",lowerBetter:!0,expr:"skidpad.lapTime"},{key:"endurance",label:"Endurance",format:"time",lowerBetter:!0,expr:"endurance.time"},{key:"energy",label:"Energy",unit:"kWh",lowerBetter:!0,expr:"endurance.energy"},{key:"overall",label:"Overall",unit:"pts",format:"points",expr:"accelPts + skidpadPts + autocrossPts + endurancePts + efficiencyPts"},{key:"endurancePts",label:"Endurance",unit:"pts",format:"points",max:250,expr:"if(finite(finishedEndurance), 0.9 * 250 * ((1.333 * fleetmin(finishedEndurance) / min(finishedEndurance, 1.333 * fleetmin(finishedEndurance)) - 1) / 0.333) + 0.1 * 250, 0)"},{key:"efficiencyPts",label:"Efficiency",unit:"pts",format:"points",max:100,expr:"if(and(finite(finishedEndurance), finishedEndurance <= 1.333 * fleetmin(finishedEndurance)), 100 * ((1.5 * fleetmin(efficiencyFactor) - min(1.5 * fleetmin(efficiencyFactor), efficiencyFactor)) / (1.5 * fleetmin(efficiencyFactor) - fleetmin(efficiencyFactor))), 0)"},{key:"finishedEndurance",label:"Endurance, if finished",unit:"s",hidden:!0,expr:"if(endurance.finished, endurance.time, nan)"},{key:"efficiencyFactor",label:"Efficiency factor",unit:"s\xB2\xB7kWh",hidden:!0,expr:"finishedEndurance ^ 2 * endurance.energy"},{key:"accelPts",label:"Acceleration",unit:"pts",format:"points",max:75,hidden:!0,expr:"0.95 * 75 * ((1.5 * fleetmin(accel) / min(accel, 1.5 * fleetmin(accel)) - 1) / 0.5) + 0.05 * 75"},{key:"skidpadPts",label:"Skidpad",unit:"pts",format:"points",max:75,hidden:!0,expr:"0.95 * 75 * (((1.25 * fleetmin(skidpad) / min(skidpad, 1.25 * fleetmin(skidpad))) ^ 2 - 1) / 0.5625) + 0.05 * 75"},{key:"autocrossPts",label:"Autocross",unit:"pts",format:"points",max:100,hidden:!0,expr:"0.95 * 100 * ((1.25 * fleetmin(autocross) / min(autocross, 1.25 * fleetmin(autocross)) - 1) / 0.25) + 0.05 * 100"}],UC={total:"overall",parts:{[zr.accel]:"accelPts",[zr.skidpad]:"skidpadPts",[zr.autocross]:"autocrossPts",[zr.endurance]:"endurancePts",efficiency:"efficiencyPts"}},XC={id:"fs-ev",label:"Formula Student \u2014 Electric",description:"The four dynamic events (acceleration, skidpad, autocross, endurance) scored on the Formula Student point table, with efficiency from battery energy.",events:WC,kpis:jC,score:UC,track:{minTurnRadius:4.5},battery:Tv,traceEventId:zr.autocross},qC={id:"fs-cv",label:"Formula Student \u2014 Combustion",description:"Same events and point table as the electric class. An engine car\u2019s efficiency is scored on the work at its crankshaft until its fuel is modelled; an electric car\u2019s on its pack.",events:WC,kpis:jC,score:UC,track:{minTurnRadius:4.5},traceEventId:zr.autocross},Wl=Co(XC),Wy=Co(qC);var jy="lap",C5=[{kind:"trackLap",id:jy,label:Fp,laps:1}],QC={id:"trackday",label:"Track day",description:"One flying lap of the selected track. Times and traces only \u2014 no scoring.",events:C5,kpis:[{key:"lap",label:"Lap time",format:"time",lowerBetter:!0,expr:"lap.time"},{key:"topSpeed",label:"Top speed",unit:"km/h",over:jy,expr:"peak(speed)"},{key:"energy",label:"Energy / lap",unit:"kWh",lowerBetter:!0,expr:"lap.energy"}],traceEventId:jy},Uy=Co(QC);function To(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(To).join(",")}]`;let t=e,r=Object.keys(t).sort(),n=[];for(let o of r)t[o]!==void 0&&n.push(`${JSON.stringify(o)}:${To(t[o])}`);return`{${n.join(",")}}`}function Ca(e){let t=To(e),r=2166136261;for(let n=0;n<t.length;n++)r^=t.charCodeAt(n),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return r.toString(16).padStart(8,"0").slice(-6)}var yi=[Wl,Wy,Uy],Ta=Wl.id,xi=e=>yi.some(t=>t.id===e),ZC=new WeakMap,jl=new Map,T5=64;function Dp(e){let t=ZC.get(e);if(t!==void 0)return t;let r=To(e),n=jl.get(r);return n===void 0&&(n=Lp(e).length?null:Co(e),jl.size>=T5&&jl.delete(jl.keys().next().value),jl.set(r,n)),ZC.set(e,n),n}function Ep(e,t=[]){if(e==null)return;if(typeof e!="string")return Dp(e)??void 0;let r=yi.find(o=>o.id===e);if(r)return r;let n=t.find(o=>o.id===e);return n?Dp(n)??void 0:void 0}function Pa(e,t=[]){return Ep(e,t)??Wl}function Xy(e=[]){let t=e.filter(r=>!xi(r.id)).map(r=>Dp(r)).filter(r=>r!==null);return[...yi,...t]}var Ul=e=>e.definition??e.id;function Ip(e,t,r){let n=e.length,o=new Array(n);for(let f=0;f<n;f++){let h=f+1<n?e[f+1]:r;o[f]=h-e[f]}let a=new Array(n).fill(0),s=new Array(n).fill(0),i=new Array(n).fill(0),c=new Array(n).fill(0);for(let f=0;f<n;f++){let h=o[(f-1+n)%n],b=o[f];a[f]=h,s[f]=2*(h+b),i[f]=b;let g=t[(f+1)%n],y=t[(f-1+n)%n];c[f]=6*((g-t[f])/b-(t[f]-y)/h)}let l=P5(a,s,i,c),u=new Array(n),m=new Array(n),p=new Array(n),d=new Array(n);for(let f=0;f<n;f++){let h=o[f],b=l[f],g=l[(f+1)%n],y=t[f],x=t[(f+1)%n];u[f]=y,p[f]=b/2,d[f]=(g-b)/(6*h),m[f]=(x-y)/h-h*(2*b+g)/6}return{n,eval:(f,h)=>u[f]+h*(m[f]+h*(p[f]+h*d[f])),d1:(f,h)=>m[f]+h*(2*p[f]+h*3*d[f]),d2:(f,h)=>2*p[f]+h*6*d[f]}}function Qy(e,t){let r=e.length,n=r-1,o=new Array(n);for(let u=0;u<n;u++)o[u]=e[u+1]-e[u];let a=new Array(r).fill(0);if(r>2){let u=r-2,m=new Array(u).fill(0),p=new Array(u).fill(0),d=new Array(u).fill(0),f=new Array(u).fill(0);for(let g=0;g<u;g++){let y=g+1;m[g]=o[y-1],p[g]=2*(o[y-1]+o[y]),d[g]=o[y],f[g]=6*((t[y+1]-t[y])/o[y]-(t[y]-t[y-1])/o[y-1])}let h=n>=3;if(h){let g=o[0]/o[1];p[0]+=o[0]*(1+g),d[0]-=o[0]*g;let y=o[n-1]/o[n-2];p[u-1]+=o[n-1]*(1+y),m[u-1]-=o[n-1]*y}let b=qy(m,p,d,f);for(let g=0;g<u;g++)a[g+1]=b[g];h&&(a[0]=(1+o[0]/o[1])*a[1]-o[0]/o[1]*a[2],a[r-1]=(1+o[n-1]/o[n-2])*a[r-2]-o[n-1]/o[n-2]*a[r-3])}let s=new Array(n),i=new Array(n),c=new Array(n),l=new Array(n);for(let u=0;u<n;u++)s[u]=t[u],c[u]=a[u]/2,l[u]=(a[u+1]-a[u])/(6*o[u]),i[u]=(t[u+1]-t[u])/o[u]-o[u]*(2*a[u]+a[u+1])/6;return{n,eval:(u,m)=>s[u]+m*(i[u]+m*(c[u]+m*l[u])),d1:(u,m)=>i[u]+m*(2*c[u]+m*3*l[u]),d2:(u,m)=>2*c[u]+m*6*l[u]}}function P5(e,t,r,n){let o=t.length;if(o===1)return[n[0]/(t[0]+e[0]+r[0])];if(o===2){let f=t[0],h=r[0]+e[0],b=e[1]+r[1],g=t[1],y=f*g-h*b;return[(n[0]*g-h*n[1])/y,(f*n[1]-n[0]*b)/y]}let a=e[0],s=r[o-1],i=-t[0]||1e-30,c=t.slice();c[0]=t[0]-i,c[o-1]=t[o-1]-a*s/i;let l=qy(e,c,r,n),u=new Array(o).fill(0);u[0]=i,u[o-1]=s;let m=qy(e,c,r,u),p=(l[0]+a*l[o-1]/i)/(1+m[0]+a*m[o-1]/i),d=new Array(o);for(let f=0;f<o;f++)d[f]=l[f]-p*m[f];return d}function qy(e,t,r,n){let o=t.length,a=new Array(o),s=new Array(o);a[0]=r[0]/t[0],s[0]=n[0]/t[0];for(let c=1;c<o;c++){let l=t[c]-e[c]*a[c-1];a[c]=r[c]/l,s[c]=(n[c]-e[c]*s[c-1])/l}let i=new Array(o);i[o-1]=s[o-1];for(let c=o-2;c>=0;c--)i[c]=s[c]-a[c]*i[c+1];return i}function Xl(e){let t=e.z;if(!Array.isArray(t)||t.length<2)return null;let r=e.closed!==!1,n=e.x.length,o=r?n:n-1,a=[0];for(let l=0;l<o;l++){let u=(l+1)%n;a.push(a[l]+Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]))}let s=a[o],i=t.length,c=i===n?a.slice(0,n):Array.from({length:i},(l,u)=>r?u/i*s:u/(i-1)*s);return{z:t,pos:c,length:s,closed:r}}function JC(e,t,r){let n=e.pos[r]-e.pos[t];return e.closed?n>e.length/2?n-e.length:n<-e.length/2?n+e.length:n:n}function eT(e,t){let[r,n,o,a,s,i]=e,c=a*i-s*s,l=o*s-n*i,u=n*s-o*a,m=r*c+n*l+o*u;if(!(Math.abs(m)>1e-12*Math.max(1,Math.abs(r*a*i))))return null;let p=r*i-o*o,d=n*o-r*s,f=r*a-n*n;return[(c*t[0]+l*t[1]+u*t[2])/m,(l*t[0]+p*t[1]+d*t[2])/m,(u*t[0]+d*t[1]+f*t[2])/m]}function tT(e){let t=e.z.length;if(t<5)return 0;let r=[];for(let a=0;a<t;a++){let s=[a-2,a-1,a+1,a+2].map(h=>e.closed?(h+t)%t:h);if(s.some(h=>h<0||h>=t))continue;let i=s.map(h=>JC(e,a,h)),c=Math.max(...i.map(Math.abs));if(!(c>0))continue;let l=i.map(h=>h/c),u=[0,0,0,0,0];for(let h of l)for(let b=0;b<5;b++)u[b]+=h**b;let m=eT([u[0],u[1],u[2],u[2],u[3],u[4]],[1,0,0]);if(!m)continue;let p=l.map(h=>m[0]+m[1]*h+m[2]*h*h),d=0,f=1;p.forEach((h,b)=>{d+=h*e.z[s[b]],f+=h*h}),r.push(Math.abs(e.z[a]-d)/Math.sqrt(f))}if(!r.length)return 0;r.sort((a,s)=>a-s);let n=r.length>>1;return 1.4826*(r.length%2?r[n]:(r[n-1]+r[n])/2)}function L5(e,t,r){let n=e.z.length,o=[t],a=[0];for(let s of[-1,1])for(let i=1;i<n;i++){let c=e.closed?((t+s*i)%n+n)%n:t+s*i;if(c<0||c>=n)break;let l=JC(e,t,c);if(Math.abs(l)>=r||Math.sign(l)!==s)break;o.push(c),a.push(l)}return{j:o,t:a}}function D5(e,t,r){let{j:n,t:o}=L5(e,t,r);if(n.length<4)return null;let a=o.map(l=>(1-Math.abs(l/r)**3)**3),s=o.map(l=>l/r),i=[0,0,0,0,0];s.forEach((l,u)=>{let m=a[u];for(let p=0;p<5;p++)i[p]+=m,m*=l});let c=eT([i[0],i[1],i[2],i[2],i[3],i[4]],[1,0,0]);return c?{j:n,value:s.map((l,u)=>a[u]*(c[0]+c[1]*l+c[2]*l*l))}:null}function Zy(e,t){return t>0?e.z.map((r,n)=>{let o=D5(e,n,t/2);return o?o.value.reduce((a,s,i)=>a+s*e.z[o.j[i]],0):r}):[...e.z]}function E5(e,t){if(!(e>0)||!(t>0))return 0;let r=(22.5*t*e*e/1e-4**2)**.2;return Math.min(100/2,r)}function _p(e){let t=Xl(e);if(!t)return 0;let r=tT(t);return r>1e-6?Math.max(10,E5(r,I5(t))):0}function I5(e){let t=[];for(let r=1;r<e.pos.length;r++)t.push(e.pos[r]-e.pos[r-1]);return e.closed&&e.pos.length&&t.push(e.length-e.pos[e.pos.length-1]+e.pos[0]),t.sort((r,n)=>r-n),t.length?t[t.length>>1]:0}function xn(e,t,r){let n=e.n;if(e.closed===!1){let a=r-t;return a===0?e.diag[t]:a===1?e.off1[t]:a===2?e.off2[t]:a===-1?e.off1[r]:a===-2?e.off2[r]:0}let o=((r-t)%n+n)%n;return o===0?e.diag[t]:o===1?e.off1[t]:o===2?e.off2[t]:o===n-1?e.off1[r]:o===n-2?e.off2[r]:0}function Op(e,t){let r=e.n,n=new Array(r).fill(0);for(let o=0;o<r;o++){let a=e.diag[o]*t[o];for(let[s,i]of[[1,e.off1],[2,e.off2]]){(o+s<r||e.closed!==!1)&&(a+=i[o]*t[(o+s)%r]);let c=(o-s+r)%r;(o-s>=0||e.closed!==!1)&&(a+=i[c]*t[c])}n[o]=a}return n}function rT(e,t){let r=new Array(e).fill(0),n=new Array(e).fill(0),o=new Array(e).fill(0);for(let a=0;a<e;a++){a>=2&&(o[a]=r[a-2]!==0?t(a,a-2)/r[a-2]:0),a>=1&&(n[a]=r[a-1]!==0?(t(a,a-1)-o[a]*n[a-1])/r[a-1]:0);let s=t(a,a)-n[a]*n[a]-o[a]*o[a];if(!(s>0)||!Number.isFinite(s))return null;r[a]=Math.sqrt(s)}return{d:r,l1:n,l2:o}}function Np(e,t){let r=t.length,n=new Array(r).fill(0);for(let a=0;a<r;a++){let s=t[a];a>=1&&(s-=e.l1[a]*n[a-1]),a>=2&&(s-=e.l2[a]*n[a-2]),n[a]=s/e.d[a]}let o=new Array(r).fill(0);for(let a=r-1;a>=0;a--){let s=n[a];a+1<r&&(s-=e.l1[a+1]*o[a+1]),a+2<r&&(s-=e.l2[a+2]*o[a+2]),o[a]=s/e.d[a]}return o}function _5(e,t){let r=e[0][0]*e[1][1]-e[0][1]*e[1][0],n=Math.max(Math.abs(e[0][0]*e[1][1]),Math.abs(e[0][1]*e[1][0]),Number.MIN_VALUE);return!Number.isFinite(r)||Math.abs(r)<1e-12*n?null:[(t[0]*e[1][1]-e[0][1]*t[1])/r,(e[0][0]*t[1]-t[0]*e[1][0])/r]}function Jy(e,t){let r=e.n;if(r<7)throw new Error(`periodic band solver needs n >= 7, got ${r}`);if(e.closed===!1){let b=rT(r,(y,x)=>xn(e,y,x));if(!b)return null;let g=Np(b,t);return g.every(Number.isFinite)?g:null}let n=r-2,a=rT(n,(b,g)=>xn(e,b,g));if(!a)return null;let s=new Array(n).fill(0),i=new Array(n).fill(0);for(let b=0;b<n;b++)s[b]=xn(e,b,r-2),i[b]=xn(e,b,r-1);let c=Np(a,t.slice(0,n)),l=Np(a,s),u=Np(a,i),m=(b,g)=>{let y=0;for(let x=0;x<b.length;x++)y+=b[x]*g[x];return y},p=[[xn(e,r-2,r-2)-m(s,l),xn(e,r-2,r-1)-m(s,u)],[xn(e,r-1,r-2)-m(i,l),xn(e,r-1,r-1)-m(i,u)]],d=[t[r-2]-m(s,c),t[r-1]-m(i,c)],f=_5(p,d);if(!f)return null;let h=new Array(r).fill(0);for(let b=0;b<n;b++)h[b]=c[b]-l[b]*f[0]-u[b]*f[1];return h[r-2]=f[0],h[r-1]=f[1],h.every(Number.isFinite)?h:null}function nT(e,t,r=0){let n=Math.max(...e.diag.map(Math.abs),1e-30),o=r>0?r:n*1e-12,a=Math.sqrt(t.reduce((s,i)=>s+i*i,0));for(let s=0;s<40;s++){let i={...e,diag:e.diag.map(l=>l+o)},c=Jy(i,t);if(c){let l=Op(i,c).map((m,p)=>m-t[p]);if(Math.sqrt(l.reduce((m,p)=>m+p*p,0))<=1e-6*Math.max(a,1e-12))return c}o=o===0?n*1e-12:o*10}return null}var oT=4,N5=8,ex=.001;function O5(e,t,r){let n=[];for(let c=1;c<e.length;c++){let l=e[c]-e[c-1];l>=ex&&n.push(l)}let o=Float64Array.from(n).sort(),a=o.length>>1,s=o.length?o.length%2?o[a]:.5*(o[a-1]+o[a]):0,i=t?n.length:n.length+1;return Math.max(3,Math.round(i/Xw(r,s,i)))}function V5(e,t){let r=e.closed!==!1,n=[],o=[],a=(F,w)=>{let T=n.length-1;T>=0&&Math.hypot(F-n[T],w-o[T])<ex||(n.push(F),o.push(w))},s=e.x.length,i=r?s:s-1,c=new Array(i+1);c[0]=0;for(let F=0;F<i;F++){let w=(F+1)%s;c[F+1]=c[F]+Math.hypot(e.x[w]-e.x[F],e.y[w]-e.y[F])}let l=c[i],u=e.fit==="interpolate",m=u?s:O5(c,r,t),p=r?m:m-1,d=0;for(let F=0;F<=p&&!(r&&F===p);F++){if(u){a(e.x[F],e.y[F]);continue}let w=F*l/p;for(;d<i-1&&c[d+1]<w;)d++;let T=c[d+1]-c[d],M=T>0?(w-c[d])/T:0,k=(d+1)%s;a(e.x[d]+M*(e.x[k]-e.x[d]),e.y[d]+M*(e.y[k]-e.y[d]))}if(r)for(;n.length>2&&Math.hypot(n[n.length-1]-n[0],o[o.length-1]-o[0])<ex;)n.pop(),o.pop();let f=n.length,h=r?f:f-1,b=new Array(h+1);b[0]=0;for(let F=1;F<=h;F++){let w=F%f,T=n[w]-n[F-1],M=o[w]-o[F-1],k=Math.sqrt(Math.hypot(T,M))||1e-9;b[F]=b[F-1]+k}let g=r?Ip(b.slice(0,f),n,b[f]):Qy(b,n),y=r?Ip(b.slice(0,f),o,b[f]):Qy(b,o),x=new Array(h);for(let F=0;F<h;F++)x[F]=b[F+1]-b[F];let R=[0],v=[0],S=[0],A=0;for(let F=0;F<h;F++){let w=x[F]/oT;for(let T=0;T<oT;T++){let M=T*w;A+=Qg(k=>Math.hypot(g.d1(F,k),y.d1(F,k)),M,M+w),R.push(A),v.push(F),S.push(M+w)}}return{closed:r,sx:g,sy:y,h:x,sTable:R,segTable:v,uTable:S,length:A,rawCum:c,rawLength:l}}function ql(e,t,r,n){if(e===void 0)return r.map(()=>t);if(typeof e=="number")return r.map(()=>e);let o=e.length;if(o===0)return r.map(()=>t);if(o===1)return r.map(()=>e[0]);let a=n.rawCum.length-1,s=o===(n.closed?a:a+1);return r.map(i=>{let c;if(s){let p=i*n.rawLength,d=0,f=a;for(;d<f;){let b=d+f+1>>1;n.rawCum[b]<=p?d=b:f=b-1}let h=d<a?n.rawCum[d+1]-n.rawCum[d]:0;c=d+(h>0?(p-n.rawCum[d])/h:0)}else c=n.closed?i*o:i*(o-1);let l=Math.min(Math.floor(c),o-1)%o,u=c-Math.floor(c),m=n.closed?(l+1)%o:Math.min(l+1,o-1);return e[l]+u*(e[m]-e[l])})}var B5=.01,$5=3,aT=10;function G5(e,t,r,n=aT){let o={step:0,uncertainty:1/0},a=e.length;if(a<8||!(r>0))return o;let s=Math.max(aT,n,6*r/a),i=(r-t[a-1])/2,c=0;for(;c<a/2&&t[c]+i<=s;)c++;let l=0;for(;l<a/2&&r-t[a-1-l]-i<=s;)l++;let u=Math.min(c,l);if(u<3)return o;let m=[],p=[],d=(x,R,v)=>{let S=x/s;m.push([1,S,S*S,S*S*S,R]),p.push(v)};for(let x=0;x<u;x++)d(t[x]+i,1,e[x]);for(let x=0;x<u;x++)d(t[a-1-x]-r+i,0,e[a-1-x]);let f=Array.from({length:5},()=>new Array(5).fill(0)),h=new Array(5).fill(0);m.forEach((x,R)=>{for(let v=0;v<5;v++){h[v]+=x[v]*p[R];for(let S=0;S<5;S++)f[v][S]+=x[v]*x[S]}});let b=Jr(f,h),g=Jr(f,[0,0,0,0,1]);if(b.singular||g.singular)return o;let y=0;return m.forEach((x,R)=>{let v=0;for(let S=0;S<5;S++)v+=x[S]*b.x[S];y+=(p[R]-v)**2}),{step:b.x[4],uncertainty:Math.sqrt(y/(m.length-5)*g.x[4])}}function K5(e,t){let r=t[t.length-1];return{pos:e===t.length-1?t.slice(0,e):Array.from({length:e},(o,a)=>a/e*r),loop:r}}function H5(e,t,r){let{pos:n,loop:o}=K5(e.length,t),{step:a,uncertainty:s}=G5(e,n,o,r);return Math.abs(a)>Math.max(B5,$5*s)?{z:e.map((i,c)=>i+a*n[c]/o),drift:-a}:{z:e,drift:0}}function z5(e,t){let{sTable:r,segTable:n,uTable:o,h:a,sx:s,sy:i}=e,c=0,l=r.length-1;for(;c<l;){let y=c+l+1>>1;r[y]<=t?c=y:l=y-1}let u=Math.min(c,r.length-2),m=r[u],p=r[u+1],d=n[u+1],f=o[u+1],h=n[u]===d?o[u]:0,b=p-m,g=b>0?h+(t-m)/b*(f-h):h;for(let y=0;y<2;y++){let x=m+Qg(v=>Math.hypot(s.d1(d,v),i.d1(d,v)),h,g),R=Math.hypot(s.d1(d,g),i.d1(d,g));if(R<1e-12)break;g-=(x-t)/R}return{seg:d,du:Math.min(Math.max(g,0),a[d])}}var Y5=3,tx=5;function W5(e,t,r,n=tx){return Bp(e,t,r,n)}function Bp(e,t,r,n,o=!1){let a=e.length;if(!(t>0)||!(n>0)||a<7)return[...e];let s=(n/(2*Math.PI*t))**4,i=new Array(a).fill(1+6*s),c=new Array(a).fill(-4*s),l=new Array(a).fill(s),u=[...e];if(!r&&(i[0]=i[a-1]=1+s,i[1]=i[a-2]=1+5*s,c[0]=c[a-2]=-2*s,o)){let m=1e9*(1+s);for(let p of[0,a-1])i[p]+=m,u[p]*=1+m}return Jy({n:a,diag:i,off1:c,off2:l,closed:r},u)??[...e]}function $t(e,t){let r=Bt(t),n=V5(e,r.fitSpacing),o=n.length,a=Math.max(N5,Math.round(o/r.dsTarget)),s=n.closed?a:a+1,i=o/a,c=new Array(s),l=new Array(s),u=new Array(s),m=new Array(s).fill(i);n.closed||(m[s-1]=0);let p=new Array(s),d=new Array(s),f=new Array(s);for(let T=0;T<s;T++){let M=T*i,{seg:k,du:C}=z5(n,M);c[T]=n.sx.eval(k,C),l[T]=n.sy.eval(k,C),u[T]=M;let P=n.sx.d1(k,C),L=n.sy.d1(k,C),E=n.sx.d2(k,C),_=n.sy.d2(k,C),D=Math.hypot(P,L),I=Math.pow(P*P+L*L,1.5);p[T]=I>0?(P*_-L*E)/I:0,d[T]=D>0?-L/D:0,f[T]=D>0?P/D:0}let h=u.map(T=>o>0?Math.min(1,T/o):0),b=Array.isArray(e.z)&&e.z.length>1,g=b&&(e.zSmoothing??0)>0?e.zSmoothing:0,y=b&&n.closed?H5(e.z,n.rawCum,g):null,x=y?y.z:e.z,R=g>0?Xl(e):null,v=R?Zy({...R,z:x},g):x,S=ql(v,0,h,n),A=new Array(s).fill(0);if(b){for(let M=0;M<s;M++){let k=n.closed?(M+1)%s:Math.min(M+1,s-1),C=n.closed?(M-1+s)%s:Math.max(M-1,0),P=n.closed?2:k-C,L=S[k]-S[C];A[M]=P>0?Math.atan2(L,P*i)*180/Math.PI:0}for(let M=0;M<s;M++){if(m[M]===0)continue;let k=n.closed?(M+1)%s:M+1,C=S[k]-S[M];m[M]=Math.hypot(i,C)}let T=0;for(let M=0;M<s;M++)u[M]=T,T+=m[M]}let F=b?m.reduce((T,M)=>T+M,0):o,w;if(b){w=new Array(s).fill(0);let T=Math.max(Y5,e.zReach??_p(e)),M=Math.max(2,Math.round(T/i));if(n.closed?s>2*M:s>2*M+1){let k=0,C=0;for(let E=-M;E<=M;E++)k+=E*E,C+=E*E*E*E;let P=2*M+1,L=C-k*k/P;for(let E=0;E<s;E++){let _=n.closed?E:Math.min(Math.max(E,M),s-1-M),D=0,I=0;for(let V=-M;V<=M;V++){let H=S[n.closed?(_+V+s)%s:_+V];D+=(V*V-k/P)*H,I+=V*H}let N=2*D/L/(i*i),O=I/k/i;w[E]=N/Math.pow(1+O*O,1.5)}}}return{name:e.name,closed:n.closed,x:c,y:l,s:u,ds:m,curvature:e.turnReach?W5(p,i,n.closed,e.turnReach):p,npts:s,length:F,nx:d,ny:f,z:S,gradient:A,...w?{verticalCurvature:w}:{},widthLeft:ql(e.widthLeft,1.5,h,n),widthRight:ql(e.widthRight,1.5,h,n),bank:ql(e.bank,0,h,n),mu:ql(e.mu,1,h,n),...y?.drift?{elevationDrift:y.drift}:{}}}function sT(e,t,r){let n=Op(e,r),o=0;for(let a=0;a<r.length;a++)o+=.5*r[a]*n[a]-t[a]*r[a];return o}function j5(e,t,r,n){let o=e.n,a=e.closed!==!1,s=(l,u)=>{let m=l+u;return a?(m%o+o)%o:m>=0&&m<o?m:null},i=[...t];for(let l=0;l<o;l++){if(r[l]==="free")continue;let u=n(l);if(u!==0)for(let m of[-2,-1,1,2]){let p=s(l,m);p!=null&&(i[p]-=xn(e,p,l)*u)}}let c={n:o,closed:e.closed,diag:[...e.diag],off1:[...e.off1],off2:[...e.off2]};for(let l=0;l<o;l++){if(r[l]==="free")continue;c.diag[l]=1,c.off1[l]=0,c.off2[l]=0;let u=s(l,-1),m=s(l,-2);u!=null&&(c.off1[u]=0),m!=null&&(c.off2[m]=0),i[l]=n(l)}return nT(c,i)}var U5=1e-4;function iT(e,t,r,n,o={}){let a=e.n,s=o.maxIter??60,i=o.tol??1e-9,c=o.bounds,l=(f,h)=>Math.min(n[h],Math.max(r[h],f)),u=r.map((f,h)=>c?.[h]==="hi"?n[h]:c?.[h]==="lo"?r[h]:l(0,h)),m=sT(e,t,u),p=new Array(a).fill("free"),d=!1;for(let f=0;f<s;f++){let h=Op(e,u).map((x,R)=>x-t[R]),b=!1;for(let x=0;x<a;x++){let R=u[x]<=r[x]+i&&h[x]>=-i?"lo":u[x]>=n[x]-i&&h[x]<=i?"hi":"free";R!==p[x]&&(p[x]=R,b=!0)}if(d&&!b)return{x:u,iterations:f+1,converged:!0,bounds:p};let g=j5(e,t,p,x=>u[x]);if(!g)return{x:u,iterations:f+1,converged:!1,bounds:p};let y=!1;for(let x=1;x>1e-12;x*=.5){let R=!1,v=u.map((F,w)=>{if(p[w]!=="free")return F;let T=F+x*(g[w]-F),M=l(T,w);return M!==T&&(R=!0),M}),S=sT(e,t,v),A=0;for(let F=0;F<a;F++)A+=h[F]*(v[F]-u[F]);if(x===1&&!R||S<m&&S<=m+U5*A){u=v,m=S,d=x===1&&!R,y=!0;break}}if(!y)return{x:u,iterations:f+1,converged:!1,bounds:p}}return{x:u,iterations:s,converged:!1,bounds:p}}var rx={lineStep:2,carHalfWidth:.75,margin:.1,foldMargin:.25,referenceReach:5,passes:40,iterations:400},X5=[1,.5,.25,.125,.0625,.03125,.015625,.0078125,.00390625,.001953125,.0009765625],q5=e=>Math.sqrt(e.reduce((t,r)=>t+r*r,0)/(e.length||1));function Ql(e,t,r=!0){let n=e.length,o=new Array(n).fill(0);for(let a=0;a<n;a++){if(!r&&(a===0||a===n-1))continue;let s=(a-1+n)%n,i=(a+1)%n,c=e[a]-e[s],l=t[a]-t[s],u=e[i]-e[a],m=t[i]-t[a],p=e[i]-e[s],d=t[i]-t[s],f=Math.hypot(c,l),h=Math.hypot(u,m),b=Math.hypot(p,d),g=f*h*b;o[a]=g>1e-12?2*(c*m-l*u)/g:0}return o}var Q5=Math.PI/180,cT=20;function Z5(e,t){let r=e.npts,n=e.closed,o=e.x.map((d,f)=>d+t[f]*e.nx[f]),a=e.y.map((d,f)=>d+t[f]*e.ny[f]),s=[0];for(let d=1;d<r;d++)s.push(s[d-1]+Math.hypot(o[d]-o[d-1],a[d]-a[d-1]));let i=n?s[r-1]+Math.hypot(o[0]-o[r-1],a[0]-a[r-1]):s[r-1],c=n?[-1,0,1]:[0],l=[],u=[];for(let d of c)for(let f=0;f<r;f++)l.push(s[f]+d*i),u.push(f+d*r);n&&(l.push(2*i),u.push(2*r));let m=[0];for(let d=1;d<l.length;d++)m.push(m[d-1]+.5*(u[d]+u[d-1])*(l[d]-l[d-1]));let p=d=>{let f=0,h=l.length-1;for(;h-f>1;){let g=f+h>>1;l[g]<=d?f=g:h=g}let b=l[h]>l[f]?(d-l[f])/(l[h]-l[f]):0;return m[f]+(l[h]-l[f])*b*(u[f]+.5*b*(u[h]-u[f]))};return s.map((d,f)=>{let h=n?cT:Math.min(cT,d,i-d);if(!(h>0))return e.z[f];let b=(p(d+h)-p(d-h))/(2*h),g=n?(b%r+r)%r:Math.min(Math.max(b,0),r-1),y=Math.min(Math.floor(g),r-1),x=n?(y+1)%r:Math.min(y+1,r-1);return e.z[y]+(g-y)*(e.z[x]-e.z[y])})}function J5(e,t,r){let n=Array.isArray(e.z)&&e.z.length>1,o=t.bank.some(i=>i!==0),a=t.mu.some(i=>i!==1),s=n?Z5(t,r):t.z;return{...n||o?{z:s.map((i,c)=>i+r[c]*Math.tan(t.bank[c]*Q5))}:{},...n?{zReach:e.zReach??_p(e)}:{},...o?{bank:[...t.bank]}:{},...a?{mu:[...t.mu]}:{}}}function lT(e,t,r=!0){let n=e.length,o=new Array(n).fill(0);for(let a=0;a<n;a++){if(!r&&(a===0||a===n-1))continue;let s=(a-1+n)%n,i=(a+1)%n;o[a]=.5*(Math.hypot(e[a]-e[s],t[a]-t[s])+Math.hypot(e[i]-e[a],t[i]-t[a]))}return o}function e$(e,t,r,n,o){let a=e.length,s=new Array(a).fill(0),i={l:new Array(a).fill(0),d:new Array(a).fill(0),r:new Array(a).fill(0)},c=(l,u,m,p)=>l*p-u*m;for(let l=0;l<a;l++){if(!o&&(l===0||l===a-1))continue;let u=(l-1+a)%a,m=(l+1)%a,p=e[l]-e[u],d=t[l]-t[u],f=e[m]-e[l],h=t[m]-t[l],b=e[m]-e[u],g=t[m]-t[u],y=Math.hypot(p,d),x=Math.hypot(f,h),R=Math.hypot(b,g),v=y*x*R;if(!(v>1e-12))continue;let S=2*c(p,d,f,h)/v,A=Math.sqrt(.5*(y+x)),F=S/(2*A),w=(p*r[u]+d*n[u])/y,T=(b*r[u]+g*n[u])/R,M=(p*r[l]+d*n[l])/y,k=(f*r[l]+h*n[l])/x,C=(f*r[m]+h*n[m])/x,P=(b*r[m]+g*n[m])/R,L=-2*c(r[u],n[u],f,h)/v+S*(w/y+T/R),E=2*c(r[l],n[l],b,g)/v-S*(M/y-k/x),_=2*c(p,d,r[m],n[m])/v-S*(C/x+P/R);s[l]=S*A,i.l[l]=A*L-F*.5*w,i.d[l]=A*E+F*.5*(M-k),i.r[l]=A*_+F*.5*C}return{res:s,jac:i}}function t$(e,t,r,n,o){let a=n-r+1,s=e.l.slice(r,n+1),i=e.d.slice(r,n+1),c=e.r.slice(r,n+1),l=t.slice(r,n+1);o||(i[0]+=s[0],s[0]=0,i[a-1]+=c[a-1],c[a-1]=0);let u=(h,b)=>o?h[(b+a)%a]:b>=0&&b<a?h[b]:0,m=new Array(a),p=new Array(a),d=new Array(a),f=new Array(a);for(let h=0;h<a;h++){let b=u(c,h-1),g=u(s,h+1);m[h]=b*b+i[h]*i[h]+g*g,p[h]=i[h]*c[h]+g*u(i,h+1),d[h]=g*u(c,h+1),f[h]=-(b*u(l,h-1)+i[h]*l[h]+g*u(l,h+1))}return{M:{n:a,closed:o,diag:m,off1:p,off2:d},b:f}}function r$(e,t){let r=e.npts,n=e.closed;if(!(t>0)||r<7)return e;let o=n?r:r-1,a=0;for(let p=0;p<o;p++){let d=(p+1)%r;a+=Math.hypot(e.x[d]-e.x[p],e.y[d]-e.y[p])}let s=a/o,i=Bp(e.x,s,n,t,!0),c=Bp(e.y,s,n,t,!0),l=new Array(r),u=new Array(r);for(let p=0;p<r;p++){let d=n?(p-1+r)%r:Math.max(p-1,0),f=n?(p+1)%r:Math.min(p+1,r-1),h=i[f]-i[d],b=c[f]-c[d],g=Math.hypot(h,b)||1;l[p]=-b/g,u[p]=h/g}let m=Ql(i,c,n);return n||(m[0]=m[1],m[r-1]=m[r-2]),{...e,x:i,y:c,nx:l,ny:u,curvature:m}}var n$=6;function o$(e,t,r,n){let o=e.npts,a=e.closed?o:o-1,s=new Array(a);for(let l=0;l<a;l++){let u=(l+1)%o,m=Math.atan2(e.nx[l]*e.ny[u]-e.ny[l]*e.nx[u],e.nx[l]*e.nx[u]+e.ny[l]*e.ny[u]),p=Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]);s[l]=p>1e-9?m/p:0}let i=Math.max(0,Math.round(n$/(e.ds[0]||1))),c=1-n;for(let l=0;l<o;l++){let u=0,m=0;for(let p=-i-1;p<=i;p++){let d=e.closed?((l+p)%o+o)%o:l+p;d<0||d>=a||(u=Math.max(u,s[d]),m=Math.max(m,-s[d]))}u>0&&(t[l]=Math.max(r[l],Math.min(t[l],c/u))),m>0&&(r[l]=Math.min(t[l],Math.max(r[l],-c/m)))}}function nx(e,t={}){let r={...rx,...t},n=$t(e,{dsTarget:r.lineStep}),o=r$(n,r.referenceReach),a=o.npts,s=M=>({x:o.x.map((k,C)=>k+o.nx[C]*M[C]),y:o.y.map((k,C)=>k+o.ny[C]*M[C])}),i=M=>{let k=Ql(M.x,M.y,o.closed),C=lT(M.x,M.y,o.closed),P=0;for(let L=0;L<k.length;L++)P+=k[L]*k[L]*C[L];return P},c=q5(n.curvature),l=lT(n.x,n.y,n.closed).reduce((M,k)=>M+k,0),u=new Array(a).fill(0),m=r.carHalfWidth+r.margin,p=new Array(a),d=new Array(a),f=0;for(let M=0;M<a;M++){let k=o.widthLeft[M]-m,C=-(o.widthRight[M]-m);if(k<C){f++;let P=(o.widthLeft[M]-o.widthRight[M])/2;p[M]=P,d[M]=P}else p[M]=k,d[M]=C}let h=[...p],b=[...d];o$(o,p,d,r.foldMargin);let g=M=>{let k=s(M),C=J5(e,o,M),P={name:`${e.name} \u2014 racing line`,x:k.x,y:k.y,closed:o.closed,widthLeft:h.map((O,V)=>Math.max(0,O-M[V])),widthRight:b.map((O,V)=>Math.max(0,M[V]-O)),...C,fit:"interpolate",turnReach:tx},L=1e-6,E=M.filter((O,V)=>O>=p[V]-L||O<=d[V]+L).length,_=Ql(k.x,k.y,o.closed),D=O=>1/Math.max(...O.map(Math.abs),1e-9),I=0,N=o.closed?k.x.length:k.x.length-1;for(let O=0;O<N;O++){let V=(O+1)%k.x.length,H=k.x[V]-k.x[O],U=k.y[V]-k.y[O];I+=C.z?Math.hypot(H,U,C.z[V]-C.z[O]):Math.hypot(H,U)}return{offset:M,s:[...o.s],asset:P,curvatureRms:{centreLine:c,racingLine:Math.sqrt(i(k)/(l||1))},infeasibleSamples:f,atBoundary:a?E/a:0,length:{centreLine:n.length,racingLine:I},worstRadius:{centreLine:D(n.curvature),racingLine:D(_)}}},y=o.closed?0:1,x=o.closed?a-1:a-2,R=x-y+1,v=new Array(R),S=new Array(R);for(let M=0;M<R;M++)v[M]=d[y+M],S[M]=p[y+M];if(!o.closed&&R>0){let M=(k,C)=>{if(v[k]=Math.max(v[k],d[C]),S[k]=Math.min(S[k],p[C]),v[k]>S[k]){let P=.5*(v[k]+S[k]);v[k]=P,S[k]=P}};M(0,0),M(R-1,a-1),v[0]=S[0]=Math.min(S[0],Math.max(v[0],0))}if(R<7)return g(u);let A=M=>{let k=s(M),P=[...Ql(k.x,k.y,o.closed).map(Math.abs)].sort((L,E)=>L-E);return{integral:i(k),tail:P[Math.floor(.99*(P.length-1))]}},F=[...u],w=A(u),T;for(let M=0;M<r.passes;M++){let k=s(F),{res:C,jac:P}=e$(k.x,k.y,o.nx,o.ny,o.closed),{M:L,b:E}=t$(P,C,y,x,o.closed),_=iT(L,E,v.map((N,O)=>N-F[y+O]),S.map((N,O)=>N-F[y+O]),{maxIter:r.iterations,bounds:T});T=_.bounds;let D=new Array(a).fill(0);for(let N=0;N<R;N++)D[y+N]=_.x[N];o.closed||(D[0]=D[1],D[a-1]=D[a-2]);let I=!1;for(let N of X5){let O=F.map((H,U)=>H+N*D[U]),V=A(O);if(V.integral<w.integral*(1-1e-6)){F=O,w=V,I=!0;break}}if(!I)break}return g(F)}function ox(e){let t=Math.max(J(e,"track_front"),J(e,"track_rear"));return(t>0?t/2e3:.6)+.1}function $p(e,t,r={}){if(!r.racingLine)return{asset:e,numerics:t,line:null};let n=r.params?ox(r.params):void 0,o=nx(e,{...r.line,...n?{carHalfWidth:n}:{}});return{asset:o.asset,numerics:{...t,fitSpacing:0},line:o}}function Zl(e,t,r={}){let n=$p(e,t,r);return{track:$t(n.asset,n.numerics),line:n.line}}function ax(e=4,t=Zl){let r=new WeakMap;return(n,o,a={})=>{let s=a.racingLine===!0,i=s?[a.params?ox(a.params):null,a.line??null]:null,c=JSON.stringify([o,s,i]),l=r.get(n);l||(l=new Map,r.set(n,l));let u=l.get(c);if(u)return l.delete(c),l.set(c,u),u;let m=t(n,o,a);return l.set(c,m),l.size>e&&l.delete(l.keys().next().value),m}}var uT={racingLine:!1,standingStart:!1},Gp=256;function Jl(e,t,r,n,o=uT,a=Zl){let s=Pa(n),{racingLine:i,standingStart:c,lapCounts:l}=o;return e.map(u=>{let{track:m}=a(t,r,{racingLine:i,params:u});return By(Bl(u,s,{track:m,numerics:r,standingStart:c,lapCounts:l}))})}function sx(e,t){let r=Pa(e),n=r.score?r.score(t):null,o=r.field===r.score?n:r.field?r.field(t):null;return{scores:n,field:o}}function ix(e,t,r){let n={};for(let o of Pa(e).metrics)n[o.key]=o.value(t,r);return n}var Kp=37;var ux=287.05287,s$=461.495,Hp=9.80665/(ux*.0065),i$=101325/(ux*288.15),c$=273.15,l$=-500,u$=6e3,m$=400,d$=1100,zp={source:"car",altitudeM:0,pressure:{kind:"standard"},humidityPct:0};function p$(e){return 101325*Math.pow(1-.0065*e/288.15,Hp)}function f$(e){return 288.15/.0065*(1-Math.pow(e/i$,1/(Hp-1)))}function h$(e){return 288.15/.0065*(1-Math.pow(e/101325,1/Hp))}function b$(e,t){return e*Math.pow(1-.0065*t/288.15,Hp)}function g$(e){return 611.21*Math.exp((18.678-e/234.5)*(e/(257.14+e)))}function y$(e,t){switch(e.kind){case"standard":return p$(t);case"qnh":return b$(e.hPa*100,t);case"station":return e.hPa*100}}function eu(e,t,r=0,n=h$(e)){let o=t+c$,a=Math.min(.5*e,Math.max(0,Math.min(100,r))/100*g$(t)),s=e-a,i=s/(ux*o)+a/(s$*o);return{altitudeM:n,p:e,pDry:s,T:o,rho:i,densityAltitudeM:f$(i)}}function mT(e,t){return eu(y$(e.pressure,e.altitudeM),t,e.humidityPct,e.altitudeM)}var cx=(e,t,r)=>Math.min(r,Math.max(t,e)),lx=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Yp(e){if(!e||typeof e!="object")return structuredClone(zp);let t=e,r=t.pressure??{},n=cx(lx(r.hPa,1013.25),m$,d$),o=r.kind==="qnh"?{kind:"qnh",hPa:n}:r.kind==="station"?{kind:"station",hPa:n}:{kind:"standard"};return{source:t.source==="venue"?"venue":"car",altitudeM:cx(lx(t.altitudeM,0),l$,u$),pressure:o,humidityPct:cx(lx(t.humidityPct,0),0,100)}}var Da=e=>e?.source==="venue",Wp="the air the session states, at its venue";var x$=Math.PI/180;function R$(){return{ucaFront:[110,245,330],ucaRear:[-110,258,335],lcaFront:[130,185,112],lcaRear:[-130,205,116],tieInner:[-92,210,132],uprightUpper:[-6,542,352],uprightLower:[4,560,120],tieOuter:[-78,556,146],wheelCenter:[0,600,230],pushrodOuter:[8,520,128],rockerPivotA:[70,380,440],rockerPivotB:[-50,383,442],rockerToPushrod:[65,478.6,419.1],rockerToDamper:[10,280,440],damperChassis:[10,275,245]}}function v$(){return{ucaFront:[120,250,340],ucaRear:[-120,262,345],lcaFront:[140,190,118],lcaRear:[-140,210,122],tieInner:[120,215,150],uprightUpper:[-4,548,360],uprightLower:[6,566,126],tieOuter:[108,560,158],wheelCenter:[0,610,232],pushrodOuter:[10,526,132],rockerPivotA:[70,385,450],rockerPivotB:[-50,388,452],rockerToPushrod:[67,484.6,429.1],rockerToDamper:[12,286,450],damperChassis:[12,281,255]}}function mx(e){let t=-e*x$;return ee([0,Math.cos(t),Math.sin(t)])}function jp(){let e={rodType:"push",pushrodAttach:"lowerArm",steerMode:"rack",spinAxis:mx(-1),loadedRadius:230,springRate:35,rackAxis:[0,1,0]};return{hardpoints:R$(),config:e}}function tu(){let e={rodType:"pull",pushrodAttach:"lowerArm",steerMode:"fixed",spinAxis:mx(-1.5),loadedRadius:232,springRate:40,rackAxis:[0,1,0]};return{hardpoints:v$(),config:e}}function Up(){let e=[-25,635,460],t=[-40,600,710],r={layout:"mcpherson",actuation:"direct",rodType:"push",pushrodAttach:"upright",steerMode:"rack",spinAxis:mx(-.5),loadedRadius:320,springRate:38,rackAxis:[0,1,0],rackTravel:70};return{hardpoints:{ucaFront:[49,426,430],ucaRear:[-99,425,431],lcaFront:[60,395,180],lcaRear:[-280,415,185],tieInner:[-150,375,256],uprightUpper:[...e],uprightLower:[0,720,145],tieOuter:[-140,705,230],wheelCenter:[0,775,320],pushrodOuter:[...e],damperChassis:[...t],rockerPivotA:[...t],rockerPivotB:[...t],rockerToPushrod:[...e],rockerToDamper:[...t]},config:r}}function dx(){return{front:jp(),rear:tu(),config:{wheelbase:1600,trackFront:1200,trackRear:1220,frontAxleX:800}}}var k$=Math.PI/180;function dT(e){let t=-e*k$;return ee([0,Math.cos(t),Math.sin(t)])}function px(e,t){let r=([l,u,m])=>[l*t.kx,u*t.ky,m*t.kz],n=e.hardpoints,o=Object.fromEntries(Object.entries(n).map(([l,u])=>[l,r(u)])),a=(l,u)=>{o[l]=[o[l][0],o[l][1],o[l][2]+u]},s=t.lowerInnerDz??0,i=t.upperInnerDz??0;a("lcaFront",s),a("lcaRear",s),a("tieInner",s),a("ucaFront",i),a("ucaRear",i);let c={...e.config,spinAxis:dT(t.camberDeg),loadedRadius:t.loadedRadius,springRate:t.springRate};if(t.actuation==="direct"){let l=o.pushrodOuter,u=[l[0],l[1]*.7,l[2]+1.3*t.loadedRadius];o.damperChassis=u,o.rockerPivotA=u,o.rockerPivotB=u,o.rockerToPushrod=l,o.rockerToDamper=u,c={...c,actuation:"direct",rodType:"push",pushrodAttach:"lowerArm"}}else c={...c,actuation:"rocker"};for(let l of Object.keys(o))o[l]=M$(o[l]);return{hardpoints:o,config:c}}function M$(e){return e.map(t=>Math.round(t*10)/10+0)}function Ea(e){return{name:e.name,front:px(jp(),e.front),rear:px(tu(),e.rear),config:{wheelbase:e.wheelbase,trackFront:e.trackFront,trackRear:e.trackRear,frontAxleX:e.wheelbase/2}}}function Ri(e,t,r){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:t}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:r}}}}var vi=600,Ia=610,ki=230,_a=232;function Na(){let e=dx();return{...e,name:"Formula Student",front:{...e.front,config:{...e.front.config,actuation:"rocker"}},rear:{...e.rear,config:{...e.rear.config,actuation:"rocker"}}}}function fx(){return Ea({name:"Formula 1",wheelbase:3600,trackFront:1600,trackRear:1600,front:{kx:1.3,ky:800/vi,kz:355/ki,lowerInnerDz:-5,upperInnerDz:0,camberDeg:-3,loadedRadius:355,springRate:200},rear:{kx:1.3,ky:800/Ia,kz:355/_a,lowerInnerDz:35,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:220}})}function ru(){return Ri(Ea({name:"GT car",wheelbase:2700,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/vi,kz:325/ki,lowerInnerDz:18,upperInnerDz:5,camberDeg:-3.5,loadedRadius:325,springRate:110,actuation:"direct"},rear:{kx:1.2,ky:825/Ia,kz:325/_a,lowerInnerDz:36,upperInnerDz:15,camberDeg:-2,loadedRadius:325,springRate:120,actuation:"direct"}}),318.6,318.6)}function nu(){return Ri(Ea({name:"Sports car",wheelbase:2750,trackFront:1550,trackRear:1550,front:{kx:1.15,ky:775/vi,kz:320/ki,lowerInnerDz:36,upperInnerDz:15,camberDeg:-.5,loadedRadius:320,springRate:55,actuation:"direct"},rear:{kx:1.15,ky:775/Ia,kz:320/_a,lowerInnerDz:57,upperInnerDz:25,camberDeg:-1,loadedRadius:320,springRate:60,actuation:"direct"}}),305.4,309)}function S$(e,t,r,n,o,a){let s=Up(),i=Object.fromEntries(Object.entries(s.hardpoints).map(([l,[u,m,p]])=>[l,[u,m+e,p]])),c=(l,u)=>{i[l]=[i[l][0],i[l][1],i[l][2]+u]};return c("lcaFront",t),c("lcaRear",t),c("tieInner",r),{hardpoints:i,config:{...s.config,spinAxis:dT(n),springRate:o,rackTravel:a}}}function pT(){return Ri({name:"Cup car",front:S$(55,-25,-23,-3.5,150,55),rear:px(tu(),{kx:1.15,ky:820/Ia,kz:320/_a,lowerInnerDz:37,upperInnerDz:12,camberDeg:-2,loadedRadius:320,springRate:130,actuation:"direct"}),config:{wheelbase:2650,trackFront:1660,trackRear:1640,frontAxleX:2650/2},chassis:{boxes:[],body:"cup"}},306.3,311.6)}function fT(){return{...Ri(Ea({name:"Stock car",wheelbase:2794,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/vi,kz:355/ki,lowerInnerDz:20,upperInnerDz:5,camberDeg:-2.5,loadedRadius:355,springRate:175,actuation:"direct"},rear:{kx:1.2,ky:825/Ia,kz:355/_a,lowerInnerDz:40,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:150,actuation:"direct"}}),343.8,345.3),chassis:{boxes:[],body:"nascar"}}}function hT(){let e=Ri(Ea({name:"Hill-climb prototype",wheelbase:2550,trackFront:1580,trackRear:1540,front:{kx:1.1,ky:790/vi,kz:300/ki,lowerInnerDz:10,upperInnerDz:5,camberDeg:-2.5,loadedRadius:300,springRate:90},rear:{kx:1.1,ky:770/Ia,kz:300/_a,lowerInnerDz:30,upperInnerDz:15,camberDeg:-1.5,loadedRadius:300,springRate:120}}),293.3,290.8);return{...e,front:{...e.front,config:{...e.front.config,rackTravel:45}},chassis:{boxes:[],body:"hillclimb"}}}function bT(){let e=Ri(Ea({name:"Race truck",wheelbase:3700,trackFront:2050,trackRear:1950,front:{kx:1.5,ky:1025/vi,kz:506/ki,lowerInnerDz:40,upperInnerDz:10,camberDeg:-.5,loadedRadius:506,springRate:200,actuation:"direct"},rear:{kx:1.5,ky:975/Ia,kz:506/_a,lowerInnerDz:60,upperInnerDz:20,camberDeg:-.25,loadedRadius:506,springRate:160,actuation:"direct"}}),490.4,495.6);return{...e,front:{...e.front,config:{...e.front.config,rackTravel:60}},chassis:{boxes:[],body:"truck"}}}var Lt=(e,t,r)=>({value:e,label:t,unit:r}),gT=(e,t)=>({...ln[e],value:t});function yT(e,t,r){let n=[],o=[];for(let a=0;a<=r;a+=500)n.push(a),o.push(a<=t?e:e*t/a);return{rpm:n,torque:o}}function Oa(e,t,r,n,o){let a=[],s=[];for(let i=0;i<=r;i+=500){a.push(i);let c=i<=t?n:Math.min(n,9549*e/i);s.push(c/o)}return{rpm:a,torque:s}}function to(e){let t={name:e.name,m:Lt(e.m,"vehicle mass (with driver)","kg"),A:Lt(e.A,"frontal area","m^2"),c_l:Lt(e.cl,"downforce coefficient","-"),c_w:Lt(e.cw,"drag coefficient","-"),l_to_d_ratio:Lt(e.cw>0?e.cl/e.cw:0,"lift-to-drag ratio","-"),driven_wheels:Lt(e.drivenWheels,"driven wheels","-"),fr_0:Lt(-.012,"rolling-resistance coefficient","-"),front_aero_diss:Lt(e.frontAero,"front aero distribution","-"),front_mass_diss:Lt(e.frontMass,"front mass distribution","-"),r_dyn:Lt(e.rDyn,"dynamic tyre radius","m"),rho:Lt(1.2,"air density","kg/m^3"),gear_ratio:Lt(e.gearRatio,"gear ratio","-"),effi_pgb:Lt(e.drivetrainEfficiency,"drivetrain efficiency","-"),capacity:Lt(e.capacityAh,"pack capacity","Ah"),soc:Lt(1,"state of charge","-"),ocv:Lt(e.ocv,"pack open-circuit voltage","V"),power_scale:Lt(1,"power scaling factor","-"),power_limit_kw:gT("power_limit_kw",e.powerLimitKw),motor:e.motor,tireModelId:e.tireModelId};e.motorCount!==void 0&&(t.motorCount=e.motorCount),e.driveline&&(t.driveline=structuredClone(e.driveline)),e.motorPlacement&&(t.motorPlacement=e.motorPlacement);for(let[r,n]of Object.entries(e.dynamics))t[r]=gT(r,n);return t}var Mi={name:"Formula Student",m:300,A:1,cl:3,cw:1.3,frontMass:.47,frontAero:.45,rDyn:.222,drivenWheels:2,gearRatio:11.5,motor:yT(25,15e3,2e4),capacityAh:12,ocv:550,drivetrainEfficiency:.95,powerLimitKw:80,tireModelId:"t3",dynamics:{grip_scale:1,stiffness_scale:1,endurance_reserve:5,cg_height:300,tire_vertical_rate:110,unsprung_mass:8,brake_balance:.62,arb_front:20,arb_rear:15,damper_front:2.5,damper_rear:2.5,spring_front:35,spring_rear:40,mr_front:.94,mr_rear:.92,cop_long:.55,cop_height:300,ride_height_front:30,ride_height_rear:35,I_yaw:140,I_roll:45,I_pitch:130,camber_front_deg:-1,camber_rear_deg:-1.5,track_front:1200,track_rear:1220,wheelbase:1600,rc_front:5,rc_rear:4}},bx={name:"Formula 1",m:798,A:1.5,cl:3,cw:.9,frontMass:.46,frontAero:.44,rDyn:.35,drivenWheels:2,gearRatio:4.9,motor:Oa(735,2e3,12500,2500,2),motorCount:1,driveline:{rear:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t4",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:290,tire_vertical_rate:300,unsprung_mass:30,brake_balance:.58,arb_front:250,arb_rear:150,damper_front:6,damper_rear:6,spring_front:200,spring_rear:220,mr_front:.95,mr_rear:.91,heave_spring_front:800,heave_spring_rear:800,tire_vertical_damping:.5,cop_long:.56,cop_height:400,ride_height_front:35,ride_height_rear:70,I_yaw:800,I_roll:150,I_pitch:800,camber_front_deg:-3,camber_rear_deg:-1.5,track_front:1600,track_rear:1600,wheelbase:3600,rc_front:-4,rc_rear:78}},Xp={name:"GT car",m:1300,A:2,cl:1.4,cw:.42,frontMass:.5,frontAero:.42,rDyn:.33,drivenWheels:2,gearRatio:3.43,motor:Oa(410,2e3,8e3,2e3,2),motorCount:1,driveline:{rear:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t5",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:450,tire_vertical_rate:280,unsprung_mass:45,brake_balance:.6,arb_front:40,arb_rear:25,damper_front:4.5,damper_rear:4.5,spring_front:110,spring_rear:120,mr_front:.79,mr_rear:.77,cop_long:.58,cop_height:500,ride_height_front:55,ride_height_rear:75,I_yaw:1800,I_roll:450,I_pitch:1800,camber_front_deg:-3.5,camber_rear_deg:-2,track_front:1650,track_rear:1650,wheelbase:2700,rc_front:48,rc_rear:80}},qp={name:"Sports car",m:1600,A:2.2,cl:-.1,cw:.3,frontMass:.55,frontAero:.5,rDyn:.32,drivenWheels:2,gearRatio:3.14,motor:Oa(220,1500,6500,1400,2),motorCount:1,driveline:{rear:er.open},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t6",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:520,tire_vertical_rate:220,unsprung_mass:50,brake_balance:.65,arb_front:25,arb_rear:12,damper_front:2.4,damper_rear:2.4,spring_front:55,spring_rear:60,mr_front:.78,mr_rear:.75,cop_long:.5,cop_height:500,ride_height_front:130,ride_height_rear:140,I_yaw:2600,I_roll:550,I_pitch:2500,camber_front_deg:-.5,camber_rear_deg:-1,track_front:1550,track_rear:1550,wheelbase:2750,rc_front:80,rc_rear:122}},gx={name:"Cup car",m:1265,A:2.1,cl:.45,cw:.4,frontMass:.62,frontAero:.45,rDyn:.31,drivenWheels:2,gearRatio:3.5,motor:Oa(250,2e3,7e3,1190,2),motorCount:1,motorPlacement:"front",driveline:{front:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t7",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:480,tire_vertical_rate:280,unsprung_mass:40,brake_balance:.68,arb_front:20,arb_rear:90,damper_front:4,damper_rear:3.5,spring_front:150,spring_rear:130,mr_front:.95,mr_rear:.76,cop_long:.55,cop_height:450,ride_height_front:64,ride_height_rear:78,I_yaw:1700,I_roll:400,I_pitch:1700,camber_front_deg:-3.5,camber_rear_deg:-2,track_front:1660,track_rear:1640,wheelbase:2650,rc_front:60,rc_rear:84}},yx={name:"Stock car",m:1620,A:2.2,cl:.6,cw:.45,frontMass:.53,frontAero:.45,rDyn:.35,drivenWheels:2,gearRatio:4.1,motor:Oa(500,2500,9e3,1680,2),motorCount:1,driveline:{rear:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t8",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:430,tire_vertical_rate:320,unsprung_mass:55,brake_balance:.6,arb_front:60,arb_rear:15,damper_front:7.5,damper_rear:6.75,spring_front:175,spring_rear:150,mr_front:.8,mr_rear:.78,cop_long:.55,cop_height:500,ride_height_front:75,ride_height_rear:90,I_yaw:2500,I_roll:550,I_pitch:2500,camber_front_deg:-2.5,camber_rear_deg:-1.5,track_front:1650,track_rear:1650,wheelbase:2794,rc_front:53,rc_rear:91}},xx={name:"Hill-climb prototype",m:650,A:1.2,cl:2.5,cw:.9,frontMass:.42,frontAero:.42,rDyn:.29,drivenWheels:2,gearRatio:4,motor:Oa(330,3e3,8500,1240,2),motorCount:1,driveline:{rear:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t9",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:280,tire_vertical_rate:200,unsprung_mass:25,brake_balance:.58,arb_front:40,arb_rear:30,damper_front:3,damper_rear:3.5,spring_front:90,spring_rear:120,mr_front:.94,mr_rear:.91,cop_long:.58,cop_height:350,ride_height_front:45,ride_height_rear:55,I_yaw:550,I_roll:120,I_pitch:550,camber_front_deg:-2.5,camber_rear_deg:-1.5,track_front:1580,track_rear:1540,wheelbase:2550,rc_front:27,rc_rear:65}},Rx={name:"Race truck",m:5300,A:6.2,cl:-.1,cw:.65,frontMass:.6,frontAero:.6,rDyn:.502,drivenWheels:2,gearRatio:3.55,motor:Oa(880,100,3e3,88e3,2),motorCount:1,driveline:{rear:er.spool},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t10",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:950,tire_vertical_rate:1e3,unsprung_mass:350,brake_balance:.75,arb_front:350,arb_rear:150,damper_front:12,damper_rear:8.5,spring_front:200,spring_rear:160,mr_front:.81,mr_rear:.8,cop_long:.4,cop_height:1500,ride_height_front:240,ride_height_rear:240,I_yaw:16e3,I_roll:3500,I_pitch:16e3,camber_front_deg:-.5,camber_rear_deg:-.25,track_front:2050,track_rear:1950,wheelbase:3700,rc_front:95,rc_rear:134}};function hx(e,t,r){return to(r({...structuredClone(e),name:t}))}var Qp={[Mi.name]:to(Mi),"Formula Student +15% downforce":hx(Mi,"Formula Student +15% downforce",e=>({...e,cl:e.cl*1.15,cw:e.cw*1.08})),"Formula Student -15 kg":hx(Mi,"Formula Student -15 kg",e=>({...e,m:e.m-15})),"Formula Student +15% power":hx(Mi,"Formula Student +15% power",e=>({...e,motor:yT(25*1.15,15e3,2e4),powerLimitKw:80*1.15})),[bx.name]:to(bx),[Xp.name]:to(Xp),[qp.name]:to(qp),[gx.name]:to(gx),[yx.name]:to(yx),[xx.name]:to(xx),[Rx.name]:to(Rx)},xT=Object.keys(Qp),vx=xT.slice(0,4),kx=[Mi.name,bx.name,Xp.name,qp.name,gx.name,yx.name,xx.name,Rx.name];var Ume={"Touring car":Xp.name,"Street car":qp.name};var A$={bg:"#11141b",panel:"#161b22",panel2:"#202d3a",border:"#334050",borderBright:"#526477",sunken:"#0b1219",ink:"#06090d"},w$={normal:"#eef3fa",dim:"#9baab9",bright:"#ffffff",white:"#ffffff"},F$={label:"#c8d2dc",grid:"#39424e",gridFaint:"#232b35",empty:"#1a2028"},C$={accent:"#6aa8ff",accentInk:"#0d1b30",warn:"#ffb454",good:"#4ec9a0",bad:"#ff6b6b",badSoft:"#ff8f8f"},T$=["#f0e442","#7b68ee","#f7a8b8","#d55e00","#d8b4fe","#b5e48c"],Zp={front:"#a6e22e",rear:"#00b4d8"},RT=["#5b4bd6","#4aa3ff","#4ec9a0","#f0e442"],Mx={power:"#ffb454",traction:"#f0845c",front:Zp.front,rear:Zp.rear,grip:"#73c9b3",braking:"#b48aff",crest:"#e88fd0",below:"rgba(214, 221, 230, 0.32)"},P$={chassis:"#4aa3ff",ballJoint:"#ffb454",arm:"#b8c3cf",tie:"#73c9b3",pushrod:"#e5c65f",rocker:"#9f91d4",kingpin:"#d8c968",arbBar:"#cf7898",arbArm:"#b96b86",arbLink:"#ffb454",heaveSpring:"#7ad7f0",wheelCentre:"#e7ecf3",contactPatch:"#ff6b6b",ground:"#15222e",groundFaint:"#0b151f"},L$={x:"#ff6b6b",y:"#57c75a",z:"#4aa3ff"},D$={line:"#b4bfcb"},E$={compression:"#b48aff",tension:"#ff6b6b"},I$={fz:"#e7ecf3",fx:"#7ad7f0",fy:"#ff54c8"},_$={drivenLine:"#4d7cff",axis:"#eef3fa",slip:"#ffe81a",drive:Mx.power,brake:Mx.braking},N$={ground:"#101920",grid:"#1a2630",gridMajor:"#26343f",horizon:"#1d2833",bridge:"#6f7a86",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},O$={chassis:"#435160",volume:"#303b47",tyre:"#435160",tyreLine:"#39424e",tyreFace:"#1c232d"},V$={centreLine:"#4aa3ff",corridorFill:"rgba(74,163,255,0.10)",boundary:"#3d4956",racingLine:"#ffb454",start:"#e7ecf3",finish:"#ff6b6b",direction:"#8b96a3"},B$={SURFACE:A$,TEXT:w$,CHART:F$,ROLE:C$,SERIES:T$,AXLE:Zp,LAP_SPEED:RT,LIMITER:Mx,RIG:P$,AXIS:L$,CONSTRUCTION:D$,FORCE:E$,TYRE_FORCE:I$,REPLAY:_$,SCENERY:N$,BODY:O$,TRACK:V$},vT=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):Object.freeze({...r})])),Jp=vT(B$),rr=Jp.SERIES,kT=(()=>{let e="#b06400",t="#d1343a",r={front:"#70bf03",rear:"#3392d0"},n={power:e,traction:"#d05a2a",front:r.front,rear:r.rear,grip:"#2a9a83",braking:"#7b55d0",crest:"#c2479f",below:"rgba(34, 39, 45, 0.28)"};return vT({SURFACE:{bg:"#f5f6f6",panel:"#fcfcfd",panel2:"#ffffff",border:"#d8dfe6",borderBright:"#b7c3ce",sunken:"#e8edf2",ink:"#ffffff"},TEXT:{normal:"#17212c",dim:"#606c79",bright:"#10171f",white:"#000000"},CHART:{label:"#3a424b",grid:"#c2c8cd",gridFaint:"#e2e5e7",empty:"#e8eae7"},ROLE:{accent:"#2162bd",accentInk:"#ffffff",warn:e,good:"#0f8a66",bad:t,badSoft:"#e2696d"},SERIES:["#b5a11a","#2844e3","#f47ec1","#9b3a1b","#764299","#58b977"],AXLE:r,LAP_SPEED:["#4b3bc4","#1a64c2","#0f8a66","#a87e00"],LIMITER:n,RIG:{chassis:"#1a64c2",ballJoint:"#c27200",arm:"#56616d",tie:"#24907b",pushrod:"#a3820f",rocker:"#6656b8",kingpin:"#8f7f10",arbBar:"#b04d77",arbArm:"#9a4767",arbLink:"#c27200",heaveSpring:"#1688ad",wheelCentre:"#15181c",contactPatch:t,ground:"#e2e6e8",groundFaint:"#edf0f1"},AXIS:{x:"#d93a3a",y:"#2f9d34",z:"#1a64c2"},CONSTRUCTION:{line:"#5a6570"},FORCE:{compression:"#7b55d0",tension:t},TYRE_FORCE:{fz:"#ffe600",fx:"#0f8fb0",fy:"#c8198f"},REPLAY:{drivenLine:"#2f5be0",axis:"#15181c",slip:"#c79a00",drive:n.power,brake:n.braking},SCENERY:{ground:"#dde3e1",grid:"#ccd3d1",gridMajor:"#b5bfbc",horizon:"#e8edf0",bridge:"#9aa3ab",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},BODY:{chassis:"#a9b3bd",volume:"#c7ced5",tyre:"#24282c",tyreLine:"#2c333a",tyreFace:"#c3cad0"},TRACK:{centreLine:"#1a64c2",corridorFill:"rgba(26,100,194,0.10)",boundary:"#a3acb4",racingLine:e,start:"#15181c",finish:t,direction:"#5c6570"}})})();var MT=e=>{let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());return t?`#${(t[1].length===3?t[1].replace(/./g,n=>n+n):t[1]).toLowerCase()}`:null},qme=(()=>{let e=new Map,t=["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION","TEXT","CHART","SCENERY","BODY","SURFACE"];for(let r of t){let n=Jp[r],o=kT[r];for(let a of Object.keys(n)){let s=MT(n[a]);s&&!e.has(s)&&e.set(s,o[a])}}return e})();var ST=(e,t)=>new Set(t.flatMap(r=>{let n=e[r];return Array.isArray(n)?[...n]:Object.values(n)}).map(MT).filter(r=>r!==null)),Qme=ST(kT,["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION"]),Zme=ST(Jp,Object.keys(Jp).filter(e=>e!=="SURFACE"));function Sx(){return{kind:"simple",name:"Simple motor",rpm:[0,16e3,2e4],torque:[21,21,14],efficiency:.95}}function Ax(){return{kind:"map",name:"Mapped motor",rpm:[0,8e3,16e3,2e4],torque:[24,24,21,16],effRpm:[1e3,5e3,9e3,13e3,17e3,2e4],effTorque:[4,8,12,16,21],effGrid:[[.78,.84,.86,.85,.82,.79],[.83,.9,.93,.92,.89,.86],[.85,.93,.96,.95,.92,.89],[.84,.92,.95,.94,.91,.88],[.82,.89,.92,.9,.87,.84]]}}function wx(){return{kind:"simple",name:"Inboard motor, axial flux (example)",rpm:[0,4e3,4500,5e3,5500,6e3],torque:[230,230,204,184,167,153],efficiency:.95}}function Fx(){return{kind:"ice",name:"600 cc four, restricted (example)",rpm:[3e3,4e3,5e3,6e3,7e3,8e3,9e3,1e4,11e3,12e3,12500],torque:[40,46,52,56,59,61,62,60,56,49,45],idleRpm:3e3,limitRpm:12500,inertia:.012,gearbox:{primary:76/36,ratios:[33/12,32/16,30/18,26/18,30/23,29/24],efficiency:.9,upshiftTime:.1,downshiftTime:.08},breathing:{induction:{kind:"natural"}}}}function Cx(){return{kind:"ice",name:"Formula 1 power unit (example)",rpm:[4e3,5e3,6e3,7e3,8e3,9e3,1e4,10500,11e3,11500,12e3,12500],torque:[896,822,773,738,712,692,675,668,638,610,585,545],idleRpm:4e3,limitRpm:12500,inertia:.02,gearbox:{primary:1,ratios:[4,3.15,2.575,2.175,1.85,1.6,1.375,1.18],efficiency:.94,upshiftTime:0,downshiftTime:0,driveKept:1},breathing:{induction:{kind:"boosted",boostKPa:350,maxPressureRatio:5}}}}function AT(){return{kind:"ice",name:"GT race engine, 4.0 l (example)",rpm:[2500,3e3,3500,4e3,4500,5e3,5500,6e3,6500,7e3,7500,8e3],torque:[380,410,440,465,485,500,515,525,530,540,522,480],idleRpm:2500,limitRpm:8e3,inertia:.15,gearbox:{primary:1,ratios:[3,2.15,1.7,1.4,1.17,.98],efficiency:.93,upshiftTime:.05,downshiftTime:.08},breathing:{induction:{kind:"natural"}}}}function wT(){return{kind:"ice",name:"Turbocharged 3.0 l six (example)",rpm:[1e3,1500,1800,2500,3500,4500,5e3,5500,6e3,6500,7e3],torque:[230,340,400,400,400,400,400,382,350,315,280],idleRpm:1e3,limitRpm:7e3,inertia:.2,gearbox:{primary:1,ratios:[3.6,2.19,1.54,1.21,1,.83],efficiency:.92,upshiftTime:.2,downshiftTime:.2,driveKept:.8},breathing:{induction:{kind:"boosted",boostKPa:220,maxPressureRatio:3}}}}function FT(){return{kind:"ice",name:"Turbocharged 2.0 l four (example)",rpm:[2e3,2500,3e3,3500,4e3,4500,5e3,5500,6e3,6500,7e3],torque:[330,400,420,420,420,420,415,410,398,365,330],idleRpm:2e3,limitRpm:7e3,inertia:.15,gearbox:{primary:1,ratios:[2.92,2.05,1.61,1.32,1.12,.97],efficiency:.93,upshiftTime:.07,downshiftTime:.08},breathing:{induction:{kind:"boosted",boostKPa:250,maxPressureRatio:3.2}}}}function CT(){return{kind:"ice",name:"Stock car V8, 5.9 l (example)",rpm:[2500,3e3,3500,4e3,4500,5e3,5500,6e3,6500,7e3,7500,8e3,8500,9e3],torque:[450,480,510,535,555,570,585,595,600,598,590,578,562,525],idleRpm:2500,limitRpm:9e3,inertia:.18,gearbox:{primary:1,ratios:[2.8,2,1.55,1.24,1],efficiency:.93,upshiftTime:.1,downshiftTime:.1},breathing:{induction:{kind:"natural"}}}}function TT(){return{kind:"ice",name:"Turbocharged 2.0 l four, hill climb (example)",rpm:[3e3,3500,4e3,4500,5e3,5500,6e3,6500,7e3,7500,8e3,8500],torque:[314,380,446,462,462,462,458,450,437,420,388,347],idleRpm:3e3,limitRpm:8500,inertia:.1,gearbox:{primary:1,ratios:[2.69,2,1.6,1.33,1.14,1],efficiency:.93,upshiftTime:.05,downshiftTime:.08},breathing:{induction:{kind:"boosted",boostKPa:250,maxPressureRatio:4.5}}}}function PT(){return{kind:"ice",name:"Race truck diesel six, 13 l (example)",rpm:[800,1e3,1200,1400,1600,1800,2e3,2200,2400,2600,2800,3e3],torque:[3e3,4e3,4900,5500,5250,4670,4200,3820,3500,3230,3e3,2700],idleRpm:800,limitRpm:3e3,inertia:1.5,gearbox:{primary:1,ratios:[16,12.44,9.67,7.51,5.84,4.54,3.53,2.74,2.13,1.66,1.29,1],efficiency:.92,upshiftTime:.35,downshiftTime:.35},breathing:{induction:{kind:"boosted",boostKPa:350,maxPressureRatio:4.3}}}}function LT(e){return Ca($$(e))}function $$(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;let t={...e};return delete t.name,delete t.parts,Array.isArray(t.vehicles)&&(t.vehicles=t.vehicles.map(r=>{if(r===null||typeof r!="object"||Array.isArray(r))return r;let n={...r};return delete n.name,n})),t}function ou(e,t){return{...t,fingerprint:LT(e)}}var DT="CC-BY-4.0",G$={title:"PaceDynamics built-in library",url:"https://pacedyn.dev/",licence:DT},ET={fidelity:"generic",licence:DT,sources:[G$]};var ef=e=>ou(e,ET);var IT=["raw.githubusercontent.com"],_T=["tum-csv"],H$=/^[0-9a-f]{64}$/;function su(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let{url:t,sha256:r,format:n}=e;if(typeof t!="string"||t.length>500||typeof r!="string"||!H$.test(r)||!_T.includes(n))return!1;try{let o=new URL(t);return o.protocol==="https:"&&IT.includes(o.hostname)&&!o.username&&!o.password&&!o.port}catch{return!1}}var tf=e=>new URL(e.url).hostname;async function NT(e){let t=await globalThis.crypto.subtle.digest("SHA-256",e);return[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0")).join("")}function z$(e){let t=new URL(e).pathname.split("/").pop()??"";return decodeURIComponent(t).replace(/\.[^.]*$/,"")||"Linked track"}function Y$(e,t){let r=[],n=[],o=[],a=[];for(let[s,i]of e.split(/\r?\n/).entries()){let c=i.trim();if(!c||c.startsWith("#"))continue;let l=c.split(",").map(u=>Number(u.trim()));if(l.length!==4||!l.every(Number.isFinite))throw new Error(`Line ${s+1} of ${t} is not four numbers.`);r.push(l[0]),n.push(l[1]),o.push(l[2]),a.push(l[3])}if(r.length<3)throw new Error(`${t} has ${r.length} points; a track needs at least 3.`);return{name:t,x:r,y:n,widthLeft:a,widthRight:o,closed:!0,fit:"interpolate"}}var W$={"tum-csv":Y$};function OT(e,t){return W$[t.format](e,z$(t.url))}async function Tx(e,t,r){let n=await NT(e);if(n!==t.sha256)throw new Error(`${tf(t)} did not return the file that was reviewed (its SHA-256 is ${n.slice(0,12)}\u2026, not ${t.sha256.slice(0,12)}\u2026).`);let o=OT(new TextDecoder().decode(e),t),a=await rf(o);if(a!==r)throw new Error(`Linked track ${r} does not convert to its name (it is ${a}).`);return o}var Px=20,U$=new RegExp(`^[0-9a-f]{${Px}}$`),iu=e=>typeof e=="string"&&U$.test(e);async function rf(e){let t=new TextEncoder().encode(To(e)),r=await globalThis.crypto.subtle.digest("SHA-256",t);return[...new Uint8Array(r)].map(n=>n.toString(16).padStart(2,"0")).join("").slice(0,Px)}var Lx=e=>`tracks/${e}.json`;var X$=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Dx(e){return{model:{name:e.name,source:e.source},...e.provenance?{provenance:e.provenance}:{}}}async function Ex(e,t){if(!X$(e)||typeof e.name!="string"||!Array.isArray(e.x)||!Array.isArray(e.y)||e.x.length!==e.y.length||e.x.length<2)throw new Error(`Catalogue track ${t} is not a track.`);let r=await rf(e);if(r!==t)throw new Error(`Catalogue track ${t} does not match its name (it is ${r}).`);return e}var Va=(e,t,r,n=[])=>({doc:e,ref:t,refs:[t,...n.map(o=>o.ref)],slots:[{key:e,ref:t,label:r},...n],label:r}),Po=[Va("suspensions","suspensionId","suspension"),Va("tires","tireModelId","tyre",[{key:"tiresRear",ref:"tireModelIdRear",label:"rear tyre"}]),Va("motors","motorModelId","motor"),Va("aeros","aeroModelId","aero map"),Va("batteries","batteryModelId","battery"),Va("brakes","brakeModelId","brakes"),Va("dampers","damperModelId","dampers",[{key:"dampersRear",ref:"damperModelIdRear",label:"rear dampers"},{key:"dampersHeave",ref:"heaveDamperModelId",label:"heave dampers"},{key:"dampersRoll",ref:"rollDamperModelId",label:"roll dampers"}])];function nf(e){let t={...e};for(let r of Po)for(let n of r.refs)delete t[n];return t}var of=rr,cu=of,Ix=of,Lo=[...rr.slice(3),...rr.slice(0,3)],Ox=[...rr.slice(1),rr[0]],_x=[...rr.slice(2),...rr.slice(0,2)],Nx=[...rr.slice(4),...rr.slice(0,4)],Vx=[...rr.slice(5),...rr.slice(0,5)],lu=[...rr.slice(2),...rr.slice(0,2)];function Bx(){let e=globalThis.crypto;return e&&typeof e.randomUUID=="function"?e.randomUUID():`p-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function $x(e,t,r){let n=Qp[e];if(!n)throw new Error(`no preset vehicle named "${e}"`);return{id:t,params:{...sl(structuredClone(n)),energy:{...Kr},suspensionId:"sus1"},visible:!0,color:cu[r%cu.length]}}function Z$(){return vx.map((e,t)=>$x(e,`v${t+1}`,t))}function J$(){return[_c(),fg(),hg(),bg(),gg(),yg(),xg(),Rg(),vg(),kg()].map((t,r)=>({id:`t${r+1}`,color:Ix[r%Ix.length],model:t}))}function eG(){return[qh(),Qh(),Zh(),Jh(),eb(),tb(),rb(),nb()].map((t,r)=>({id:`a${r+1}`,color:_x[r%_x.length],model:t}))}function tG(){return[_h(),Nh(),Oh()].map((t,r)=>({id:`b${r+1}`,color:Nx[r%Nx.length],model:t}))}function rG(){return[{id:"brk1",color:Vx[0],model:structuredClone(Kg)}]}function nG(){return[{id:"dmp1",color:lu[0],model:structuredClone(Dd)}]}function oG(){return[Sx(),Ax()].map((t,r)=>({id:`m${r+1}`,color:Lo[r%Lo.length],model:t}))}function Gx(e){let t=r=>({...r,provenance:ef(r.model)});return{...e,suspensions:e.suspensions.map(t),vehicles:e.vehicles.map(r=>({...r,provenance:ef(nf(r.params))})),tires:e.tires.map(t),motors:e.motors.map(t),aeros:e.aeros.map(t),batteries:e.batteries.map(t),brakes:e.brakes.map(t),dampers:e.dampers.map(t)}}function uu(e="Untitled project"){let t=new Date().toISOString(),r=Z$();return Gx({schemaVersion:Kp,meta:{id:Bx(),name:e,domain:"racecar",rulesetId:Ta,createdAt:t,updatedAt:t},suspensions:[{id:"sus1",color:Ox[0],model:Na()}],activeSuspensionId:"sus1",vehicles:r,activeVehicleId:r[0]?.id??null,tires:J$(),motors:oG(),aeros:eG(),batteries:tG(),brakes:rG(),dampers:nG(),tracks:[],activeTrackId:null,mathChannels:[],rulesets:[],studies:[],activeStudyId:null,loadCases:[],reportLayouts:[],tyreSheets:[],kinSheets:[],lapSheets:[],plans:[],results:[],settings:{numerics:{...Sl},ggvMode:"twoTrack",quasiTransient:!1,motorThermal:!1,brakeFade:!1,airTempC:ur,air:structuredClone(zp),diffYaw:!1,lapCounts:{},pathPlanId:null,useRacingLine:!0,standingStart:!1}})}var aG=["front","rear"],Kx=9.81,sG=Math.PI/180;var Rn="*",Hx=40,VT=.8;function zx(e){let{s:t,curvature:r}=e;if(!t?.length||t.length!==r?.length)return null;let n=0,o=0,a=0,s=0;for(let i=0;i<t.length;i++){for(;a<t.length&&t[a]<=t[i]+2.5;)s+=Math.abs(r[a++]);for(;t[o]<t[i]-2.5;)s-=Math.abs(r[o++]);let c=s/Math.max(1,a-o);c>n&&(n=c)}return n>1e-6?1/n:null}function BT(e,t,r){let n=t.rows.map(c=>c.v),o=c=>Pt(n,t.rows.map(l=>l.ayMax),Math.min(n[n.length-1],Math.max(n[0],c))),a=(c,l,u)=>({speedKmh:Math.round(c*36)/10,ayG:Math.round(l/Kx*100)/100+0,axG:Math.round(u/Kx*100)/100+0}),s=t.vMax,i=Array.from({length:41},(c,l)=>20/3.6+l*Math.max(0,s-20/3.6)/40);switch(e){case"slowCorner":{if(r===null)return a(Hx/3.6,o(Hx/3.6),0);let c=10;for(let l=0;l<30;l++)c=Math.min(s,Math.sqrt(r*o(c)));return a(c,o(c),0)}case"fastCorner":return a(VT*s,o(VT*s),0);case"braking":{let c=i.reduce((l,u)=>t.axDecel(u,0)<t.axDecel(l,0)?u:l);return a(c,0,t.axDecel(c,0))}case"traction":{let c=i.reduce((l,u)=>t.axAccel(u,0)>t.axAccel(l,0)?u:l);return a(c,0,t.axAccel(c,0))}case"topSpeed":return a(s,0,0)}}function Yx(e,t,r){let n=!1,o=e.map(a=>{if(!a.follows)return a;let s=BT(a.follows,t,r);return![s.speedKmh,s.ayG,s.axG].every(Number.isFinite)||!t.rows.some(i=>i.ayMax>0)||s.speedKmh===a.speedKmh&&s.ayG===a.ayG&&s.axG===a.axG?a:(n=!0,{...a,...s})});return n?o:e}function Wx(e,t){let r=e.speedKmh/3.6,n=e.ayG*Kx;if(!(Math.abs(n)>1e-6)||!(r>.1))return 0;let o=r*r/Math.abs(n);return Math.sign(n)*Math.atan(t/1e3/o)/sG}var $T=e=>e.ayG<0?"L":"R";function jx(e,t=aG){if(!e.length||!t.length)return null;let r=t.flatMap(i=>i==="front"?["FL","FR"]:["RL","RR"]),n=0,o=0,a=0;for(let i of e){for(let c of r){let l=i.corners[c].travel;if(!Number.isFinite(l))return null;n=Math.min(n,l),o=Math.max(o,l)}a=Math.max(a,Math.abs(i.rollDeg))}let s=5;return{travelMin:Math.min(-1,Math.floor(n-s)),travelMax:Math.max(1,Math.ceil(o+s)),rollMaxDeg:Math.max(.5,Math.ceil((a+.5)*10)/10),rollAtLimitDeg:Math.ceil(a*10)/10}}var Ux=(e,t)=>e.travelMin===t.travelMin&&e.travelMax===t.travelMax&&e.rollMaxDeg===t.rollMaxDeg&&e.rollAtLimitDeg===t.rollAtLimitDeg;var ro=Math.PI/180,iG=9.81,mu=.1,Xx=20,GT=6,YT=50;function KT(e,t,r){let n=e(0),o=0;for(let p=t;p<=r+1e-9;p+=t){let d=e(p);if(d>n)n=d,o=p;else if(p>o+3*t)break}let a=Math.max(0,o-t),s=Math.min(r,o+t),i=.6180339887498949,c=s-i*(s-a),l=a+i*(s-a),u=e(c),m=e(l);for(let p=0;p<14;p++)u>m?(s=l,l=c,m=u,c=s-i*(s-a),u=e(c)):(a=c,c=l,u=m,l=a+i*(s-a),m=e(l));return u>n?u>=m?{force:u,at:c}:{force:m,at:l}:m>n?{force:m,at:l}:{force:n,at:o}}function qx(e,t,r,n,o){let a=o*ro;if(t==="side")return KT(i=>r*e.Fy(r*i*ro,n,a),1,45);let s=t==="drive"?1:-1;return KT(i=>s*e.Fx(s*i,n,a),.02,.6)}function sf(e){let t=e?Wm(e)?.gamma:void 0,r=[t?.min,t?.max].filter(o=>o!==void 0&&Number.isFinite(o));if(!r.length)return{lo:-GT,hi:GT,stated:!1};let n=Math.max(...r.map(Math.abs))/ro;return{lo:-n,hi:n,stated:!0}}function cG(e,t,r){if(!(r>t))return t;let n=Math.max(2,Math.ceil(r-t)+1),o=(r-t)/(n-1),a=t,s=-1/0;for(let h=0;h<n;h++){let b=t+h*o,g=e(b);g>s&&(s=g,a=b)}let i=Math.max(t,a-o),c=Math.min(r,a+o),l=.6180339887498949,u=c-l*(c-i),m=i+l*(c-i),p=e(u),d=e(m);for(let h=0;h<12;h++)p>d?(c=m,m=u,d=p,u=c-l*(c-i),p=e(u)):(i=u,u=m,p=d,m=i+l*(c-i),d=e(m));let f=p>=d?{g:u,v:p}:{g:m,v:d};return f.v>s?f.g:a}var HT=250,zT=new WeakMap;function lG(e,t,r,n,o,a,s){let i=zT.get(e);i||zT.set(e,i=new Map);let c=`${t}|${n}|${o}|${s.lo}|${s.hi}`,l=i.get(c);l||i.set(c,l=new Map);let u=f=>{let h=l.get(f);if(h===void 0){let b=Math.max(50,f*HT);h=cG(g=>qx(r,n,o,b,g).force,s.lo,s.hi),l.set(f,h)}return h},m=Math.max(0,a)/HT,p=Math.floor(m),d=m-p;return d<1e-9?u(p):u(p)*(1-d)+u(p+1)*d}function Ba(e,t){return t==="front"?e.tireModel:e.tireModelRear??e.tireModel}var uG=new WeakMap,mG=new WeakMap,dG=new WeakMap,Qx=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n};function cf(e,t){let r=Ba(e,t);return r?Qx(uG,r,()=>Cc(r))?null:"This tyre\u2019s side force does not change with camber, so it wants no camber.":"The car runs the built-in simple tyre, which has no camber term."}function Zx(e,t){let r=Ba(e,t);return r?Qx(dG,r,()=>jm(r).none)?"This tyre file has no drive or brake grip.":Qx(mG,r,()=>{let n=We(r),o=r.kind==="magic"?r.fnomin:r.nominalLoad,a=n.Fx(.1,o,0),s=n.Fx(.1,o,3*ro);return Number.isFinite(a)&&Number.isFinite(s)&&Math.abs(s-a)>1})?null:"This tyre\u2019s drive and brake grip does not change with camber.":"The car runs the built-in simple tyre, which has no camber term."}function $a(e,t){return e==="side"||e==="ackermann"?Math.abs(t.ayG)>=mu?e==="ackermann"&&!(Jx(t)<=Xx)?`is a corner wider than ${Xx} m`:null:"does not corner":(e==="drive"?t.axG:-t.axG)>=mu?null:e==="drive"?"does not drive":"does not brake"}var pG=e=>e.axG>=mu?"drive":e.axG<=-mu?"brake":null;function Jx(e){let t=e.speedKmh/3.6,r=Math.abs(e.ayG)*iG;return r>1e-9?t*t/r:1/0}var af=(e,t)=>`${e==="front"?"F":"R"}${t}`,fG=e=>e==="L"?"R":"L",hG=(e,t,r)=>Math.min(r,Math.max(t,e));function eR({ev:e,params:t,input:r,state:n,pose:o}){let a=`${J(t,"grip_scale")}|${J(t,"stiffness_scale")}`,s=Jx(n),i=r.wheelbase*(1-r.frontMassFrac)/1e3,c=r.wheelbase*r.frontMassFrac/1e3,l=r.wheelbase/1e3,u=A=>(A==="front"?r.trackFront:r.trackRear)/2e3,m=(A,F,w,T,M)=>{let k=Te(e,A),C=Ba(t,A),P=Math.max(0,o.loads[F]),L=o.camber[F],E=hG(L,M.lo,M.hi),_=qx(k,w,T,P,E),D=P<YT,I=C&&!D?lG(C,a,k,w,T,P,M):E,N=D?_.force:qx(k,w,T,P,I).force,O=.05;return{corner:F,Fz:P,lifted:D,camber:L,read:E,outside:E!==L,wants:I,atEdge:!D&&(I-M.lo<O||M.hi-I<O),peak:_.force,slip:_.at,best:N}},p=(A,F,w)=>{let T=F[0].best+F[1].best,M=F[0].peak+F[1].peak;return{kind:A,wheels:F,lossCamber:T>0?Math.max(0,1-M/T):NaN,range:w}},d=new Map,f=A=>{if(d.has(A))return d.get(A)??null;let F=null;if(!$a("side",n)){let w=sf(Ba(t,A));F=[m(A,af(A,o.outer),"side",1,w),m(A,af(A,fG(o.outer)),"side",-1,w)]}return d.set(A,F),F},h=new Map,b=new Map,g=new Map,y,x=()=>{if(y!==void 0)return y;let A=f("front");if(!A||A[0].lifted||A[1].lifted)return y=null;let[F,w]=A,T=Math.sqrt(Math.max(s*s-c*c,1e-6)),M=u("front"),k=(Math.atan(l/(T-M))-Math.atan(l/(T+M)))/ro,C=S(F.corner),P=v("front",!1,C-F.slip),L=w.slip-F.slip+R("front",!0,P)-R("front",!1,P);return y={outer:C,has:S(w.corner)-C,wants:L,geometric:k}},R=(A,F,w)=>{let T=A==="front"?i:-c,M=(F?1:-1)*u(A),k=w*ro;return Math.atan2(T+s*Math.sin(k),s*Math.cos(k)-M)/ro},v=(A,F,w)=>{let T=-60,M=60;for(let k=0;k<50;k++){let C=(T+M)/2;R(A,F,C)<w?T=C:M=C}return(T+M)/2},S=A=>(n.ayG<0?-1:1)*o.steer[A];return{side(A){if(h.has(A))return h.get(A)??null;let F=cf(t,A)?null:f(A),w=F?p("side",F,sf(Ba(t,A))):null;return h.set(A,w),w},long(A){if(b.has(A))return b.get(A)??null;let F=pG(n),w=null;if(F&&!Zx(t,A)){let T=sf(Ba(t,A));w=p(F,[m(A,af(A,"L"),F,1,T),m(A,af(A,"R"),F,1,T)],T)}return b.set(A,w),w},toeLoss(A){let F=g.get(A);if(F!==void 0)return F;let w=f(A),T=NaN;if(w&&w[0].peak+w[1].peak>0){let M=Te(e,A),[k,C]=w,P=[{g:k,dt:1,inner:!1,steer:S(k.corner)},{g:C,dt:-1,inner:!0,steer:S(C.corner)}],L=N=>P.reduce((O,V)=>{let H=V.steer-R(A,V.inner,N);return O+V.dt*M.Fy(V.dt*H*ro,V.g.Fz,V.g.read*ro)},0),E=P.map(N=>N.steer-N.g.slip-R(A,N.inner,0)),_=Math.min(...E)-2,D=Math.max(...E)+2,I=bG(L,_,D,.25);T=Math.max(0,1-I/(k.peak+C.peak))}return g.set(A,T),T},ackermann(){if($a("ackermann",n))return NaN;let A=x();return!A||!(A.geometric>.001)?NaN:100*(A.has-A.wants)/A.geometric},split:x}}function bG(e,t,r,n){let o=-1/0,a=t;for(let d=t;d<=r+1e-9;d+=n){let f=e(d);f>o&&(o=f,a=d)}let s=a-n,i=a+n,c=.6180339887498949,l=i-c*(i-s),u=s+c*(i-s),m=e(l),p=e(u);for(let d=0;d<14;d++)m>p?(i=u,u=l,p=m,l=i-c*(i-s),m=e(l)):(s=l,l=u,m=p,u=s+c*(i-s),p=e(u));return Math.max(o,m,p)}var gG=9.81,WT=Math.PI/180,Si={speed:20,ayG:1.2};function tR(e,t={}){let r=t.operating??Si,n=t.assemble,o,a,s,i=new Map,c=new Map,l=new Map,u=new Map,m=new Map,p=v=>({speed:v?.speed!==void 0&&Number.isFinite(v.speed)&&v.speed>0?v.speed:r.speed,ayG:v?.ayG!==void 0&&Number.isFinite(v.ayG)?v.ayG:r.ayG}),d=()=>{if(o!==void 0)return o;if(!n)return o=null;try{o=n(e)}catch{o=null}return o},f=()=>{if(a!==void 0)return a;try{a=pn(e.params)}catch{a=null}return a},h=v=>{let S=p(v),A=`${S.speed}|${S.ayG}`,F=i.get(A);if(F!==void 0)return F;let w=f();if(!w)return i.set(A,null),null;let T={cornerStiffness:M=>w.corneringStiffness(M),ayG:S.ayG,speed:S.speed,fyAxle:(M,k)=>2*w.Fy(M,k/2),tire:w};return i.set(A,T),T},b=()=>{if(s!==void 0)return s;let v=d(),S=f();if(!v||!S)return s=null;try{s=la(S,v.massTotal*gG*1.2)}catch{s=null}return s},g=v=>{let S=p(v).speed,A=`${S}`,F=c.get(A);if(F!==void 0)return F;let w=d(),T=f(),M=null;if(w&&T)try{M=_0(w,T,S,{steering:!1})}catch{M=null}return c.set(A,M),M},y=v=>{let S=`${v.speedKmh}|${v.ayG}|${v.axG}`,A=m.get(S);if(A!==void 0)return A;let F=null,w=d();try{let T=w?.kinFront,M=w?.kinRear;if(w&&T&&M){let k=Wx(v,w.wheelbase),C=v.speedKmh/3.6,P=Ro(w,T,M,C)(v.ayG,v.axG,0,k),L={FL:P.FL.travel,FR:P.FR.travel},E=ma(w,k*WT,L),_=k?E.camber:null,D={},I={};for(let O of["FL","FR","RL","RR"]){let V=O[1]==="R"?P[O].camberRoad:0-P[O].camberRoad;D[O]=V+(_?.[O]??0),I[O]=E.steer[O]/WT+(O[1]==="R"?1:-1)*P[O].bumpToe}let N=Xe(w,v.ayG,v.axG,C,0,k,L,P.steeringJacking);F={corners:P,rollDeg:P.FL.camberRoad-P.FL.camber,steerDeg:k,camber:D,outer:$T(v),loads:N,steer:I}}}catch{F=null}return m.set(S,F),F},x=new Map;return{operating:r,dynAvailable:!!n,poseAt:y,tyreAt:v=>{let S=`${v.speedKmh}|${v.ayG}|${v.axG}`,A=x.get(S);if(A!==void 0)return A;let F=y(v),w=d(),T=f(),M=F&&w&&T?eR({ev:T,params:e.params,input:w,state:v,pose:F}):null;return x.set(S,M),M},operatingAt:p,dynInput:d,tyre:f,dynCtx:h,grip:b,ymd:g,ymdLimit:v=>{let S=`${p(v).speed}`,A=l.get(S);if(A!==void 0)return A;let F=g(v),w=F?vy(F):null;return l.set(S,w),w},reserves:(v,S)=>{let A=p(S),F=`${v}|${A.speed}|${A.ayG}`,w=u.get(F);if(w!==void 0)return w;let T=d(),M=h(S),k=null;if(T&&M)try{k=Dl(T,M,v,b()??void 0)}catch{k=null}return u.set(F,k),k}}}var jT=["widthLeft","widthRight","bank","mu"];function du(e){let t=e.x.length,r=new Array(t).fill(0);for(let n=1;n<t;n++)r[n]=r[n-1]+Math.hypot(e.x[n]-e.x[n-1],e.y[n]-e.y[n-1]);return r}function rR(e){let t=du(e),r=e.x.length;return r===0?0:e.closed===!1||r<2?t[r-1]:t[r-1]+Math.hypot(e.x[0]-e.x[r-1],e.y[0]-e.y[r-1])}function uf(e,t,r,n={}){let o=t.length,a=l=>{let u=n[l];return u&&u.length===o?u.slice():new Array(o).fill(r[l])},s={widthLeft:a("widthLeft"),widthRight:a("widthRight"),bank:a("bank"),mu:a("mu")};if(!e.length)return s;let i=[...e].sort((l,u)=>l.from-u.from),c=o?t[o-1]:0;for(let l of i){if(!(l.to>l.from))continue;let u=Math.max(0,l.ramp??0),m=l.to>=c-1e-9;for(let p of jT){let d=l[p];if(d===void 0)continue;let f=s[p],h=r[p];for(let b=0;b<o&&t[b]<l.from;b++)h=f[b];for(let b=0;b<o;b++){let g=t[b];if(g<l.from||g>=l.to&&!(m&&g>=c-1e-9))continue;let y=g-l.from;f[b]=u>0&&y<u?h+(d-h)*(y/u):d}}}return s}function mf(e,t,r){if(!t.length)return e;let n=du(e),o=n.length,a={widthLeft:lf(e.widthLeft,r.widthLeft),widthRight:lf(e.widthRight,r.widthRight),bank:lf(e.bank,r.bank),mu:lf(e.mu,r.mu)},s={};for(let c of jT){let l=e[c];Array.isArray(l)&&l.length===o&&(s[c]=l)}let i=uf(t,n,a,s);return{...e,...i}}function lf(e,t){return typeof e=="number"?e:t}var qT=1,UT=4,pf=Math.PI/180,nR=e=>e===null||!Number.isFinite(e)||e===0?0:1/e;function oR(e){return e.kind==="arc"?Math.abs(e.radius)*Math.abs(e.angle)*pf:e.length}function df(e,t){return e.kind==="straight"?0:e.kind==="arc"?nR(e.radius):t}function XT(e){return e.kind==="straight"?0:e.kind==="arc"?nR(e.radius):nR(e.endRadius)}var pu=(e,t,r,n,o)=>e+t*o+(n>0?(r-t)*o*o/(2*n):0);function fu(e,t={}){let r=Math.max(.05,t.spacing??qT),n=t.closed!==!1,o=t.start??{x:0,y:0,heading:0},a=t.base??{widthLeft:1.5,widthRight:1.5,bank:0,mu:1},s=[],i=[],c=[],l=[],u=e.reduce((k,C)=>k+oR(C),0),m=Math.max(n?3:2,Math.round(u/r)),p=u>0?u/m:r,d=o.x,f=o.y,h=o.heading*pf,b=e.length?df(e[0],0):0,g=0,y=p,x=(k,C,P)=>{s.push(k),i.push(C),c.push(P)};x(d,f,0);let R=(k,C,P,L,E)=>{let _=E-L;if(_<=0)return;if(Math.abs(C-k)<1e-12){let I=pu(h,k,k,P,L);if(Math.abs(k)<1e-12)d+=_*Math.cos(I),f+=_*Math.sin(I);else{let N=I+k*_;d+=(Math.sin(N)-Math.sin(I))/k,f+=-(Math.cos(N)-Math.cos(I))/k}return}let D=_/UT;for(let I=0;I<UT;I++){let N=L+I*D,O=pu(h,k,C,P,N),V=pu(h,k,C,P,N+D/2),H=pu(h,k,C,P,N+D);d+=D/6*(Math.cos(O)+4*Math.cos(V)+Math.cos(H)),f+=D/6*(Math.sin(O)+4*Math.sin(V)+Math.sin(H))}};for(let k of e){let C=oR(k),P=df(k,b),L=XT(k);if(l.push({from:g,to:g+C,...k.widthLeft!==void 0?{widthLeft:k.widthLeft}:{},...k.widthRight!==void 0?{widthRight:k.widthRight}:{},...k.bank!==void 0?{bank:k.bank}:{},...k.mu!==void 0?{mu:k.mu}:{},...k.ramp!==void 0?{ramp:k.ramp}:{}}),C<=0){b=L;continue}let E=0;for(;y<=g+C+1e-9;){let _=Math.min(C,y-g);R(P,L,C,E,_),E=_,x(d,f,g+_),y+=p}R(P,L,C,E,C),h=pu(h,P,L,C,C),b=L,g+=C}let v=s.length>1?Math.hypot(s[0]-s[s.length-1],i[0]-i[i.length-1]):0,S=g;n&&s.length>1&&(s.pop(),i.pop(),c.pop());let A=e.length?df(e[0],b):0,F={gap:v,headingError:yG((h-o.heading*pf)/pf),curvatureError:b-A},w=[];for(let k=0;k<e.length;k++){let C=XT(e[k]),P=k+1<e.length?e[k+1]:n?e[0]:null;if(!P)continue;let L=df(P,C);w.push({index:k,before:C,after:L,jump:Math.abs(L-C)})}let T=uf(l,c,a);return{asset:{name:t.name??"Track",x:s,y:i,fit:"interpolate",...n?{}:{closed:!1},...T},sections:l,joints:w,closure:F,length:S}}function yG(e){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t}var xG={halfWidthM:1.5,spacingM:.5};function hu(e){switch(e.kind){case"skidpad":return`${e.radiusM.toFixed(2)} m constant-radius circle`;case"acceleration":return`${e.distanceM.toFixed(0)} m straight from rest`;case"slalom":return`${e.gates} gates at ${e.pitchM.toFixed(1)} m, \xB1${e.offsetM.toFixed(2)} m`;case"curves":{let t=e.segments.filter(r=>r.kind==="arc").length;return`${t} ${t===1?"curve":"curves"} over ${ZT(e).toFixed(0)} m`}}}function ZT(e){switch(e.kind){case"skidpad":return 2*Math.PI*e.radiusM;case"acceleration":return e.distanceM;case"slalom":return e.leadInM+Math.max(1,e.gates)*e.pitchM;case"curves":return e.segments.reduce((t,r)=>t+(r.kind==="arc"?Math.abs(r.angle)*Math.PI*Math.abs(r.radius)/180:r.length),0)}}var JT=e=>e.kind==="skidpad"||e.kind==="curves"&&e.closed===!0,eP=e=>e.kind==="acceleration",tP=1.5,rP=3;function RG(e,t){let r=e.offsetM,n=e.pitchM,o=Math.max(1,e.gates)*n,a=Math.max(0,e.leadInM),s=tP*n,i=h=>{let b=Math.min(1,Math.max(0,h));return b*b*b*(b*(b*6-15)+10)},c=h=>Math.min(i(h/s),i((o-h)/s)),l=r*(Math.PI/n)**2,u=l>0?Math.max(.05,Math.min(t.spacingM,1/l*(rP*Math.PI/180))):t.spacingM,m=[],p=[],d=Math.max(1,Math.round(a/u));for(let h=0;h<d;h++)m.push(-a+a*h/d),p.push(0);let f=Math.max(8,Math.round(o/u));for(let h=0;h<=f;h++){let b=o*h/f;m.push(b),p.push(r*c(b)*Math.sin(Math.PI*b/n))}return{name:hu(e),x:m,y:p,closed:!1,widthLeft:t.halfWidthM,widthRight:t.halfWidthM,fit:"interpolate"}}function vG(e){switch(e.kind){case"skidpad":return[{kind:"arc",radius:e.radiusM,angle:360}];case"acceleration":return[{kind:"straight",length:e.distanceM}];case"curves":return e.segments;case"slalom":return null}}function aR(e,t={}){let r={...xG,...t},n=eP(e),o=vG(e);if(!o){let u=RG(e,r);return{asset:u,peakCurvature:QT(u),worstJoint:0,standingStart:n}}let a=JT(e),s=o.reduce((u,m)=>m.kind==="arc"?Math.min(u,Math.abs(m.radius)):u,1/0),i=Number.isFinite(s)?Math.max(.05,Math.min(r.spacingM,s*(rP*Math.PI/180))):r.spacingM,c=fu(o,{name:hu(e),spacing:i,closed:a,base:{widthLeft:r.halfWidthM,widthRight:r.halfWidthM,bank:0,mu:1}}),l=a?c.joints:c.joints.filter(u=>u.index<o.length-1);return{asset:c.asset,peakCurvature:QT(c.asset),worstJoint:l.reduce((u,m)=>Math.max(u,m.jump),0),standingStart:n}}function QT(e){try{return Math.max(...$t(e).curvature.map(Math.abs))}catch{return NaN}}var Ai={courses:[{id:"c1",course:{kind:"manoeuvre",spec:{kind:"skidpad",radiusM:8.375}}}],ggvMode:"twoTrack"};function sR(e){return e.course.kind==="project"?"the project\u2019s track":e.course.kind==="track"?e.course.name:hu(e.course.spec)}var hf=()=>({courses:Ai.courses.map(e=>({...e})),ggvMode:Ai.ggvMode}),nP=new WeakMap,ff=new Map;function oP(e,t,r){if(e.kind==="project"||e.kind==="track"){let i=(e.kind==="project"?t.projectTrack?.():t.libraryTrack?.(e.trackId))??null;return i?{asset:i.asset,standingStart:i.standingStart,numerics:i.numerics}:null}let n=JSON.stringify(e.spec),o=ff.get(n);if(o)return{...o,numerics:r};let a=aR(e.spec),s={asset:a.asset,standingStart:a.standingStart};return ff.size>64&&ff.clear(),ff.set(n,s),{...s,numerics:r}}function iR(e,t,r={}){let n=r.lap??Ai,o=r.simParams,a=r.numerics??{},s=n.courses.length?n.courses:Ai.courses,i,c,l,u=new Map,m=new Map,p=new Map,d=new Map,f=R=>(R?.courseId?s.find(v=>v.id===R.courseId):void 0)??s[0],h=()=>{if(i!==void 0)return i;if(!o)return i=null;try{i={...o(e),ggvMode:n.ggvMode}}catch{i=null}return i},b=R=>{let v=f(R);if(!v)return null;let S=m.get(v.id);if(S!==void 0)return S;let A=oP(v.course,r,a),F=null;if(A)try{let w=JSON.stringify(A.numerics),T=nP.get(A.asset);T||(T=new Map,nP.set(A.asset,T));let M=T.get(w);M||(M=$t(A.asset,A.numerics),T.set(w,M)),F={id:v.id,track:M,standingStart:A.standingStart,numerics:A.numerics,name:A.asset.name}}catch{F=null}return m.set(v.id,F),F},g=()=>{if(c!==void 0)return c;let R=h();if(!R)return c=null;try{l=mr(R),c=bn(l,!1,n.ggvMode)}catch{c=null}return c},y=R=>{let v=b(R);if(!v)return null;let S=p.get(v.id);if(S!==void 0)return S;let A=g(),F=null;if(A)try{let w=l?Aa(l,A,[v.track],v.numerics,n.ggvMode,u):void 0,T=l?Fo(l,A.rows):void 0;F=tr(A,v.track,v.numerics,{standingStart:v.standingStart,...w?{load:w}:{},...T?{shifts:T}:{}})}catch{F=null}return p.set(v.id,F),F};return{lapSettings:n,get lapAvailable(){return!!o&&s.some(R=>!!oP(R.course,r,a))},lapParams:h,courses:()=>s,course:b,ggv:g,lap:y,lapReserve:R=>{let v=b(R);if(!v)return null;let S=d.get(v.id);if(S!==void 0)return S;let A=y(R),F=t.dynInput(),w=t.tyre(),T=null;if(A&&F&&w)try{let M=h();T=gp(F,w,wp({...A,ds:v.track.ds,rows:g()?.rows,gradient:v.track.gradient,bank:v.track.bank,mu:v.track.mu}),M?{driven:n0(M)}:{})}catch{T=null}return d.set(v.id,T),T}}}var aP=180/Math.PI,cR={rise:0,sinPitch:0,sinRoll:0};function sP(e){let t=e.kc;return t?iP(e.vehicle,r=>t.ground0[r]):cR}function iP(e,t){let r=e.config,n=bo(r),o=0,a=0,s=0,i=0,c=0,l=0,u=0,m=0,p=0;for(let g of en){let y=Ue(g,r),x=y.axleX-n,R=y.sideSign*cr(e,y.isFront)/2,v=t(g);if(!Number.isFinite(v))return cR;o++,a+=x,s+=R,i+=v,c+=x*x,l+=R*R,u+=x*R,m+=x*v,p+=R*v}let d=o*(c*l-u*u)-a*(a*l-u*s)+s*(a*u-c*s);if(!(Math.abs(d)>1e-9))return{rise:i/o,sinPitch:0,sinRoll:0};let f=(i*(c*l-u*u)-a*(m*l-u*p)+s*(m*u-c*p))/d,h=(o*(m*l-u*p)-i*(a*l-u*s)+s*(a*p-m*s))/d,b=(o*(c*p-m*u)-a*(a*p-m*s)+i*(a*u-c*s))/d;return{rise:f,sinPitch:h,sinRoll:-b}}function bu(e,t){let r=e.kc,n=iP(e.vehicle,o=>(r?r.ground0[o]:0)+t[o]);return ee([-n.sinPitch,n.sinRoll,1])}function lR(e,t,r,n){let o=ee(Dn(e,Ue(t,r)));return-Math.asin(Math.max(-1,Math.min(1,Z(o,n))))*aP}function bf(e,t,r,n,o){let a=ee(Dn(n,Ue(t,r))),s=ee([1-a[0]*a[0],-a[0]*a[1],-a[0]*a[2]]),i=me(a,s),c=d=>[Z(d,s),Z(d,i),Z(d,a)],l=d=>ne(ne(Q(s,d[0]),Q(i,d[1])),Q(a,d[2])),u=e.points,m=c(u.spinAxis),p=ac({uprightUpper:c(u.uprightUpper),uprightLower:c(u.uprightLower),wheelCenter:c(u.wheelCenter),spinAxis:m,tieOuter:c(u.tieOuter),loadedRadius:o.loadedRadius,patchShift:o.patchShift&&kG(o.patchShift,e.metrics.toe/aP,Math.atan2(m[0],m[1]))});return{caster:p.caster,kpi:p.kpi,scrubRadius:p.scrubRadius,mechanicalTrail:p.mechanicalTrail,scrubAtWheel:p.scrubAtWheel,trailAtWheel:p.trailAtWheel,kingpinOffset:p.kingpinOffset,casterOffset:p.casterOffset,kingpinGround:l(p.kingpinGround),contactPatch:l(p.contactPatch),elbow:l([p.contactPatch[0],p.kingpinGround[1],p.kingpinGround[2]]),kingpinAtHub:l(p.kingpinAtHub)}}function kG(e,t,r){if(r===t)return e;let n=e.x*Math.cos(t)-e.y*Math.sin(t),o=e.x*Math.sin(t)+e.y*Math.cos(t);return{x:n*Math.cos(r)+o*Math.sin(r),y:o*Math.cos(r)-n*Math.sin(r)}}function gf(e,t){let r=sP(t);if(r===cR)return e;let n=o=>Math.max(-1,Math.min(1,o));return{...e,heave:e.heave-r.rise,pitch:Math.asin(n(Math.sin(e.pitch)-r.sinPitch)),roll:Math.asin(n(Math.sin(e.roll)-r.sinRoll))}}function Yr(e,t,r){let n=gf({heave:0,pitch:0,roll:0,steer:0},r);return e-gb(n,[t,0,0],bo(r.vehicle.config))}var MG=180/Math.PI;function uR(e,t){return!e.valid||!e.ic?!1:Math.hypot(e.ic[0]-e.cp[0],e.ic[1]-e.cp[1])<=t}function Dt(e,t,r){let n=Ue(t,e.vehicle.config),o=Zt(e,r),a=Vd(e,t,o[t]),s=a.at("uprightUpper"),i=a.at("uprightLower"),c=a.at("contactPatch"),l=a.at("wheelCenter"),u=C=>{let P=a.velocity(C);return[P[0],P[2]]},m=u(c),p=u(l),d=[c[0],c[2]],f=[l[0],l[2]];if(!a.solved)return{ic:null,line:null,cp:d,wc:f,road:[1,0],swingArmAngleDeg:NaN,tanTheta:NaN,tanThetaHub:NaN,valid:!1,unsolved:!0,sinAngle:0};let h=bu(e,{FL:o.FL.ground,FR:o.FR.ground,RL:o.RL.ground,RR:o.RR.ground}),b=Math.hypot(h[0],h[2]),g=[h[0]/b,h[2]/b],y=[g[1],-g[0]],x=C=>{let P=C[0]*g[0]+C[1]*g[1];return Math.abs(P)>1e-9?-(C[0]*y[0]+C[1]*y[1])/P:0},R=a.omega[1],v=Math.hypot(m[0],m[1]),S=Math.abs(R)*1e9>v?[d[0]+m[1]/R,d[1]-m[0]/R]:null,F=S?(C=>{let P=[s[0]-C[0],s[2]-C[1]],L=[i[0]-C[0],i[2]-C[1]];return Math.abs(P[0]*L[1]-P[1]*L[0])/(Math.hypot(...P)*Math.hypot(...L))})(S):0;if(!(Math.abs(m[0]*g[0]+m[1]*g[1])>1e-9))return{ic:S,line:null,cp:d,wc:f,road:y,swingArmAngleDeg:0,tanTheta:0,tanThetaHub:0,valid:!1,sinAngle:F};let w=[m[1]/v,-m[0]/v],T=S?[S[0]-d[0],S[1]-d[1]]:[n.isFront?-1:1,0],M=w[0]*T[0]+w[1]*T[1]<0?[-w[0],-w[1]]:w,k=x(m);return{ic:S,line:M,cp:d,wc:f,road:y,swingArmAngleDeg:Math.atan(k)*MG,tanTheta:k,tanThetaHub:x(p),valid:!0,sinAngle:F}}function cP(e,t,r,n){let o=r/Math.max(1e-6,n.cgHeight),a=t==="front",s=a?n.drive.front:1-n.drive.front,i=a?n.brakeBalanceFront:1-n.brakeBalanceFront,c=(a?n.drive.inboard.front:n.drive.inboard.rear)?e.tanThetaHub:e.tanTheta,l=(a?n.brakeInboard?.front:n.brakeInboard?.rear)?e.tanThetaHub:e.tanTheta,u=a?-1:1;return{brake:u*100*l*o*i,drive:u*100*c*o*s}}function yf(e){let t=Math.min(1,Math.max(0,e.frontMassFrac)),r=(1-t)*e.wheelbase,n=t*e.wheelbase;return{x:e.frontAxleX-r,z:e.cgHeight,lf:r,lr:n}}function lP(e,t,r,n,o){let a=o(e.front)&&o(e.rear),s=n>1e-9?(r-t.x)/n:0,i=e.front.height+s*(e.rear.height-e.front.height),c=e.front.lateral+s*(e.rear.lateral-e.front.lateral);return{axisHeightAtCg:i,axisLateralAtCg:c,arm:t.z-i,valid:a}}function uP(e,t,r){return r>1e-9?Math.atan2(t-e,r)*180/Math.PI:Number.NaN}function mP(e,t,r){let{left:n,right:o}=e,a=(n.height+o.height)/2,s=(n.x+o.x)/2;return{axisHeight:a,axisX:s,heightAboveGround:(n.heightAboveGround+o.heightAboveGround)/2,ahead:s-t.x,arm:t.z-a,sinAngle:Math.min(n.sinAngle,o.sinAngle),valid:r(n)&&r(o)}}function mR(e,t){return e.valid?Y0([e.x,e.height],e.front.cp,e.rear.cp,e.sinAngle,t):!1}function no(e,t){let r={x:0,height:0,heightAboveGround:0,stationAlongGround:0,valid:!1,sinAngle:0,front:e,rear:t};if(!e.valid||!t.valid||!e.line||!t.line)return r;let n=e.ic?[e.ic[0]-e.cp[0],e.ic[1]-e.cp[1]]:e.line,o=t.ic?[t.ic[0]-t.cp[0],t.ic[1]-t.cp[1]]:t.line,a=Math.hypot(n[0],n[1]),s=Math.hypot(o[0],o[1]),i=a>0&&s>0?Math.abs(n[0]*o[1]-n[1]*o[0])/(a*s):0,c=Bd(e.cp,n,t.cp,o);if(!c)return{...r,sinAngle:i};let l=e.cp[0]-t.cp[0],u=e.cp[1]-t.cp[1],m=Math.hypot(l,u)||1,p=l/m,d=u/m,f=(e.cp[0]+t.cp[0])/2,h=(e.cp[1]+t.cp[1])/2;return{x:c[0],height:c[1],heightAboveGround:(c[0]-t.cp[0])*-d+(c[1]-t.cp[1])*p,stationAlongGround:(c[0]-f)*p+(c[1]-h)*d,valid:!0,sinAngle:i,front:e,rear:t}}var AG=180/Math.PI,wG=Math.PI/180,dR=.5,xf=2,pR=.25;function bP(e,t,r,n,o){let a=t.frontMassFrac;if(a===void 0||!Number.isFinite(a))return;let s=e.vehicle.config,i=s.wheelbase,c=yf({wheelbase:i,frontAxleX:s.frontAxleX,frontMassFrac:a,cgHeight:t.cgHeight}),l=i>1e-9?(s.frontAxleX-c.x)/i:0,u=(d,f)=>d+l*(f-d),m={left:no(...o.left),right:no(...o.right)},p={...c,z:Yr(t.cgHeight,c.x,e)};return{roll:{height:u(r.rollCentreHeight,n.rollCentreHeight),arm:t.cgHeight-u(r.rollCentreHeightChassis,n.rollCentreHeightChassis),slope:uP(r.rollCentreHeight,n.rollCentreHeight,i),usable:r.rollCentreHeightUsable&&n.rollCentreHeightUsable},pitch:mP(m,p,d=>mR(d,i))}}var FG=e=>e.frontMassFrac!==void 0&&Number.isFinite(e.frontMassFrac);function CG(e,t,r){return{FL:Dt(e,"FL",t),FR:Dt(e,"FR",t),RL:Dt(e,"RL",r),RR:Dt(e,"RR",r)}}var TG={heave:0,pitch:0,roll:0,steer:0},PG={FL:"FR",FR:"FL",RL:"RR",RR:"RL"},Rf=e=>e.ok?e.state:{...e.nearest,converged:!1};function fR(e,t,r){return t.state?t.solved===!1?{...t.state,converged:!1}:t.state:Rf(Ce(e,t.travel,t.steer,void 0,r))}var dP=new WeakMap;function pP(e,t){let r=e.ctx[t],n=Je(e.vehicle,t).config.loadedRadius,o=Sr(n,e.kc,t),a=dP.get(r);a||(a=new Map,dP.set(r,a));let s=a.get(o);if(!s){let i=go(t,e.vehicle.config,TG,e.vehicle);s=Rf(Ce(r,i.travel,i.steer,void 0,o===n?void 0:{loadedRadius:o})),a.set(o,s)}return s}var vn=(e,t)=>!e||!e.lo.converged||!e.hi.converged?NaN:(t(e.hi)-t(e.lo))/(2*e.step),fP=(e,t,r)=>{if(!e||!e.lo.converged||!e.hi.converged)return NaN;let n=r(e.hi)-r(e.lo);return Math.abs(n)<1e-9?NaN:(t(e.hi)-t(e.lo))/n};function gP(e,t,r,n,o,a){let s=e.vehicle.config,i=vs(r),c=Je(e.vehicle,r),l=Ue(r,s),u=e.ctx[r],m=Zt(e,t),p=m[r],d={travel:p.travel,steer:p.steer},f=p.rigid?void 0:{loadedRadius:p.loadedRadius},h=fR(u,p,f),b=pP(e,r),g={lo:Rf(Ce(u,d.travel-dR,d.steer,void 0,f)),hi:Rf(Ce(u,d.travel+dR,d.steer,void 0,f)),step:dR},y=l.isFront?{lo:at(u,h.beta,d.steer-xf,void 0,f),hi:at(u,h.beta,d.steer+xf,void 0,f),step:xf}:null,x=z=>{let Y=Zt(e,{...t,roll:t.roll+z*wG})[r];return fR(u,Y,Y.rigid?void 0:{loadedRadius:Y.loadedRadius})},R={lo:x(-pR),hi:x(pR),step:pR},v=DG(e,t,r,l.isFront,m,y),S=st(h.points.contactPatch,l),A=st(b.points.contactPatch,l),F=Math.abs(S[1])-Math.abs(A[1]),w=PG[r],T=m[w],M=fR(e.ctx[w],T,T.rigid?void 0:{loadedRadius:T.loadedRadius}),k=M.converged?F+Math.abs(M.points.contactPatch[1])-Math.abs(pP(e,w).points.contactPatch[1]):NaN,C=M.converged?Math.abs(S[1])+Math.abs(M.points.contactPatch[1]):NaN,P=o??Hr(e,t,i),L=$d(P,Qt(c)),E=L?null:gw(P),_=ri(P),D=l.sideSign>0?P.icRight:P.icLeft,I=D?Math.hypot(D[0]-S[1],D[1]-S[2]):1/0,N=a??Dt(e,r,t),O=N.ic?Math.hypot(N.ic[0]-N.cp[0],N.ic[1]-N.cp[1]):1/0,V=cP(N,i,s.wheelbase,n),H=-vn(g,z=>z.points.damperLength),U=c.config.springRate,G=vn(R,z=>z.metrics.camber),B=bu(e,{FL:m.FL.ground,FR:m.FR.ground,RL:m.RL.ground,RR:m.RR.ground}),q=e.kc?.loadCase,re=z=>q?bf(z,r,s,B,{loadedRadius:p.loadedRadius,patchShift:q.patchShift[r]}):z.metrics,W=re(h);return{id:r,converged:h.converged,travel:h.travel,camber:h.metrics.camber,camberRoad:lR(h.points.spinAxis,r,s,B),toe:h.metrics.toe,caster:W.caster,kpi:W.kpi,scrubRadius:W.scrubRadius,mechanicalTrail:W.mechanicalTrail,scrubAtWheel:W.scrubAtWheel,trailAtWheel:W.trailAtWheel,kingpinOffset:W.kingpinOffset,casterOffset:W.casterOffset,steeringArm:h.metrics.steeringArm,camberGain:vn(g,z=>z.metrics.camber),bumpSteer:vn(g,z=>z.metrics.toe),trackScrubRate:vn(g,z=>Math.abs(st(z.points.contactPatch,l)[1])),casterGain:vn(g,z=>re(z).caster),kpiGain:vn(g,z=>re(z).kpi),scrubGain:vn(g,z=>re(z).scrubRadius),trailGain:vn(g,z=>re(z).mechanicalTrail),...l.isFront?{camberPerSteer:fP(y,z=>z.metrics.camber,z=>z.metrics.toe),steerJacking:-fP(y,z=>z.points.contactPatch[2],z=>z.metrics.toe),...v!==void 0?{steerLoad:v}:{}}:{},rollCamber:G,camberRecovery:-100*l.sideSign*G,rollSteer:l.sideSign*vn(R,z=>z.metrics.toe),halfTrackChange:F,trackChange:k,track:C,patchX:S[0],longitudinal:S[0]-A[0],rollCentreHeight:E?E.heightAboveGround:P.heightAboveGround,rollCentreHeightChassis:(E?E.height:P.height)-Yr(0,l.axleX,e),rollCentreLateral:P.lateralAlongGround,rollCentreValid:P.valid,rollCentreUsable:L,rollCentreHeightUsable:L||E!==null,transferHeight:_?_.heightAboveGround:NaN,transferHeightChassis:_?_.height-Yr(0,l.axleX,e):NaN,rollCentreSinAngle:P.sinAngle,fvsaLength:I,svsaLength:O,swingArmAngle:N.swingArmAngleDeg,svsaUsable:uR(N,s.wheelbase),svsaSinAngle:N.sinAngle,...i==="front"?{antiDive:V.brake,antiLift:V.drive}:{antiSquat:V.drive,antiLift:V.brake},decoupled:c.config.actuation==="decoupled",mcpherson:c.config.layout==="mcpherson",springRate:U,motionRatio:H,wheelRate:U*H*H,damperLength:h.points.damperLength,damperTravel:b.points.damperLength-h.points.damperLength,...LG(c,b.points.damperLength,h.points.damperLength,e.kc?.curve[r].spring?.law),rockerAngle:c.config.actuation==="direct"?0:(h.points.rockerAngle-b.points.rockerAngle)*AG,groundDisplacement:p.rigid?h.travel:p.ground,tyreDeflection:p.tyreDeflection,wheelLoad:p.load,loadedRadiusAt:p.loadedRadius,rideRate:p.rideRate,wheelRateAtLoad:p.wheelRateAtLoad,lifted:p.lifted,clearance:p.clearance??0,tyreRigid:p.rigid}}function LG(e,t,r,n){if(e.config.actuation==="decoupled")return{};let o=n?{droop:n.droopStated?n.droop:null,bump:n.bump}:Ms(t,e.config.coilover),a=t-r;return{...o.droop!==null?{damperToExtended:a-o.droop}:{},...o.bump!==null?{damperToClosed:o.bump-a}:{}}}function DG(e,t,r,n,o,a){if(!a||!n)return;let s=km(e,t,"front"),i=e.kc;if(!s||!i)return;let c=["FL","FR"],l=[0,0],u=[0,0],m={lo:[],hi:[]},p=0;for(let h=0;h<2;h++){let b=c[h],g=o[b],y=e.ctx[b],x=g.rigid?void 0:{loadedRadius:g.loadedRadius},S=(b==="FR"?1:-1)*(r==="FR"?1:-1)*xf,A=g.state?{q:[...g.state.pose.t,...g.state.pose.omega],phi:g.state.points.rockerAngle}:void 0,F=zt(Ce(y,g.travel,g.steer-S,A,x)),w=zt(Ce(y,g.travel,g.steer+S,A,x));if(!F||!w)return NaN;l[h]=w.points.contactPatch[2]-F.points.contactPatch[2],u[h]=En(i.curve[b],g.travel,w.points.damperLength)-En(i.curve[b],g.travel,F.points.damperLength),m.lo.push(F),m.hi.push(w),b===r&&(p=w.metrics.toe-F.metrics.toe)}let d=i.elements?.front;if(d){let h=[o.FL.travel,o.FR.travel],b=hc(d,h,[m.hi[0],m.hi[1]]),g=hc(d,h,[m.lo[0],m.lo[1]]);u[0]+=b[0]-g[0],u[1]+=b[1]-g[1]}return Math.abs(p)>1e-9?s([0,0],l,u)[r==="FL"?0:1]/p:NaN}function gu(e,t,r,n,o,a){return gP(e,t,r==="front"?"FL":"RL",n,o,a)}function hR(e,t,r){let n=Math.min(Math.abs(e),Math.abs(t));return r>0?Math.atan2(n,r/2)*180/Math.PI:0}function bR(e,t,r,n){let o=FG(r)?CG(e,t,t):null,a=gu(e,t,"front",r,n?.front,o?.FL),s=gu(e,t,"rear",r,n?.rear,o?.RL),i=o?bP(e,r,a,s,{left:[o.FL,o.RL],right:[o.FR,o.RR]}):void 0;return{front:a,rear:s,wheelbaseChange:a.longitudinal-s.longitudinal,wheelbase:a.patchX-s.patchX,...i?{axes:i}:{}}}function vf(e,t,r){let n=e.config.actuation==="decoupled";return{decoupled:n,heave:n&&t?.design.kind==="coil"&&t.linkage&&Yo(t.linkage).kind!=="chassis"?t:void 0,roll:n&&r?.design.kind==="coil"&&r.linkage&&Br(e,r.linkage,"coil")?r:void 0}}var yP=16,EG=50,IG=10,_G=4,NG=["upperArm","lowerArm","tieRod","rod","dropLink"],xP=["ballJoint","rodEnd"],nr=e=>typeof e=="number"&&Number.isFinite(e)&&e>0;function yR(e,t){let r=e?.rim;if(r&&nr(r.diameter)&&nr(r.width)&&Number.isFinite(r.offset)&&Number.isFinite(r.wall)&&r.wall>=0)return{...r,from:"typed"};let n=lS(t);return n?{...n,offset:null,wall:_G,from:"tyre"}:null}function gR(e,t){let r=e?.body;if(!r||!nr(r.bodyDiameter))return null;let n=nr(r.shaftDiameter)?r.shaftDiameter:r.bodyDiameter,o=nr(r.stroke)?Math.max(0,r.extended-r.stroke-t):1/0;return{bodyRadius:r.bodyDiameter/2,shaftRadius:n/2,bodyLength:o}}function OG(e){return e&&e.location==="outboard"&&e.packaging?{...e.packaging,effRadius:e.effRadiusMm}:null}function VG(e){if(!e?.linkage||e.design.kind==="none")return null;let t=e.design,r=Math.max(0,K0(t)??0),n=t.kind==="ubar"||t.kind==="blade"||t.kind==="torsionTube"?t.section.od/2:0,o=t.kind==="ubar"?(t.armSection?.od??t.section.od)/2:t.kind==="blade"?Math.max(t.blade.width,t.blade.thickness)/2:n;return{axle:e,armLength:r,barRadius:n,armRadius:o}}function BG(e,t){if(!nr(t)||!e.config||!e.front)return null;let r=e,n=Je(r,"FL"),o=Je(r,"FR");if(n.config.steerMode!=="rack"||o.config.steerMode!=="rack")return null;let a=st(n.hardpoints.tieInner,Ue("FL",r.config)),s=st(o.hardpoints.tieInner,Ue("FR",r.config)),i=Math.hypot(s[0]-a[0],s[1]-a[1],s[2]-a[2]),c=Ot(n.config);if(!(i>2*c))return null;let l=c/i,u=(m,p)=>[m[0]+(p[0]-m[0])*l,m[1]+(p[1]-m[1])*l,m[2]+(p[2]-m[2])*l];return{a:u(a,s),b:u(s,a),radius:t/2}}function $G(e,t,r){if(!r||!e.config||!r.inboard.every(Number.isFinite)||!nr(r.diameter)||!nr(r.jointDiameter)||!Number.isFinite(r.outboard))return null;let[n,o]=t==="front"?["FL","FR"]:["RL","RR"];return{inboard:{left:st(r.inboard,Ue(n,e.config)),right:st(r.inboard,Ue(o,e.config))},outboard:r.outboard,radius:r.diameter/2,reach:r.jointDiameter/2,limits:{...nr(r.innerAngle)?{innerAngle:r.innerAngle}:{},...nr(r.outerAngle)?{outerAngle:r.outerAngle}:{},...nr(r.plunge)?{plunge:r.plunge}:{}}}}var xR=e=>typeof e=="number"&&Number.isFinite(e)&&e>0&&e<90;function RP(e,t,r){let n=Object.fromEntries(NG.map(i=>[i,(nr(e?.tubes?.[i])?e.tubes[i]:yP)/2])),o=Object.fromEntries(xP.map(i=>[i,(nr(e?.housings?.[i])?e.housings[i]:EG)/2])),a=gR(t.damper,o.rodEnd),s=Object.fromEntries(xP.filter(i=>xR(e?.jointLimits?.[i])).map(i=>[i,e.jointLimits[i]]));return{tube:n,strut:a?a.bodyRadius:yP/2,housing:o,...Object.keys(s).length?{jointLimit:s}:{},uprightWall:typeof e?.uprightWall=="number"&&Number.isFinite(e.uprightWall)&&e.uprightWall>=0?e.uprightWall:IG,rim:yR(e,t.tyre),...nr(e?.tyreGrowth)?{tyreGrowth:e.tyreGrowth}:{},brake:OG(t.brake),damper:a,...GG(t,o.rodEnd,r)}}function GG(e,t,r){let n=!!e.heave?.linkage&&e.heave.design.kind!=="none",o=!!e.arb?.linkage&&e.arb.design.kind==="coil"&&(!r||!!vf(r,void 0,e.arb).roll),a=n?gR(e.heaveDamper,t):null,s=o?gR(e.rollDamper,t):null,i=[...n&&!a?["heave"]:[],...o&&!s?["roll"]:[]];return{arb:VG(r&&mn(r,e.arb,e.rollBar)||e.arb),heave:a&&e.heave?{kind:"heave",axle:e.heave,damper:a}:null,roll:s&&e.arb?{kind:"roll",axle:e.arb,damper:s}:null,...i.length?{unsized:i}:{}}}function vP(e){let t=(r,n)=>r?n?"shafts":"hubs":"undriven";return{front:t(e.front>0,e.inboard.front),rear:t(e.front<1,e.inboard.rear)}}function KG(e,t={}){let r={heaveDamper:t.unitDampers?.heave??t.dampers?.front,rollDamper:t.unitDampers?.roll??t.dampers?.front},n=RP(e.parts?.front,{tyre:t.tyres?.front,brake:t.brakes?.front,damper:t.dampers?.front,arb:t.arbs?.front,rollBar:t.rollBars?.front,heave:t.heaves?.front,...r},e.front),o=RP(e.parts?.rear,{tyre:t.tyres?.rear??t.tyres?.front,brake:t.brakes?.rear,damper:t.dampers?.rear??t.dampers?.front,arb:t.arbs?.rear,rollBar:t.rollBars?.rear,heave:t.heaves?.rear,...r},e.rear),a=(s,i)=>{let c=e.parts?.[s]?.driveshaft,l=t.drive?.[s]??"shafts",u=c&&l==="shafts"?$G(e,s,c):null;return{...i,driveshaft:u,shaftIdle:c&&l!=="shafts"?l:null}};return{front:{...a("front",n),rackHousing:BG(e,e.parts?.front?.rackHousing)},rear:a("rear",o)}}function kP(e,t,r={}){return{...e,axles:KG(t,r)}}var Ga=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],oo=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],yu=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Wr=e=>{let t=Math.hypot(e[0],e[1],e[2]);return t>0?[e[0]/t,e[1]/t,e[2]/t]:[NaN,NaN,NaN]},wP=180/Math.PI,HG=[[1,0,0],[0,1,0],[0,0,1]],MP=(e,t)=>[e[0][0]*t[0]+e[1][0]*t[1]+e[2][0]*t[2],e[0][1]*t[0]+e[1][1]*t[1]+e[2][1]*t[2],e[0][2]*t[0]+e[1][2]*t[1]+e[2][2]*t[2]],zG=(e,t)=>[oo(e[0],t),oo(e[1],t),oo(e[2],t)];function SP(e,t,r){let n=Wr(Ga(t,e)),o=Wr(yu(n,Ga(r,e)));return[n,yu(o,n),o]}function YG(e,t){let r=n=>[t[0][0]*e[0][n]+t[1][0]*e[1][n]+t[2][0]*e[2][n],t[0][1]*e[0][n]+t[1][1]*e[1][n]+t[2][1]*e[2][n],t[0][2]*e[0][n]+t[1][2]*e[1][n]+t[2][2]*e[2][n]];return[r(0),r(1),r(2)]}function RR(e,t,r,n){let o=Wr(Ga(t,e)),a=b=>{let g=Ga(b,e),y=oo(g,o);return[g[0]-y*o[0],g[1]-y*o[1],g[2]-y*o[2]]},s=Wr(a(r)),i=Wr(a(n)),c=oo(yu(s,i),o),u=oo(s,i),m=c,p=1-u,[d,f,h]=o;return[[p*d*d+u,p*d*f+m*h,p*d*h-m*f],[p*d*f-m*h,p*f*f+u,p*f*h+m*d],[p*d*h+m*f,p*f*h-m*d,p*h*h+u]]}var WG=(e,t)=>Math.acos(Math.max(-1,Math.min(1,oo(Wr(e),Wr(t)))))*wP;function jG(e,t){return{upright:YG(SP(e.uprightLower,e.tieOuter,e.wheelCenter),SP(t.uprightLower,t.tieOuter,t.wheelCenter)),uca:t.mcpherson?null:RR(t.ucaFront,t.ucaRear,e.uprightUpper,t.uprightUpper),lca:RR(t.lcaFront,t.lcaRear,e.uprightLower,t.uprightLower),rocker:t.direct?null:RR(t.rockerPivotA,t.rockerPivotB,e.rockerToPushrod,t.rockerToPushrod)}}function UG(e){let t=Wr(e[0]),r=Math.abs(t[0])<.9?[1,0,0]:[0,1,0],n=Wr(yu(t,r)),o=yu(t,n),a=e.map(h=>{let b=Wr(h);return[oo(b,n),oo(b,o)]}),s=h=>{let b=Math.cos(h),g=Math.sin(h),y=0,x=0;for(let R=0;R<a.length;R++){let v=Math.abs(a[R][0]*b+a[R][1]*g);v>y&&([y,x]=[v,R])}return{v:y,at:x}},i=Math.PI/180,c=0,l=1/0;for(let h=0;h<180;h++){let b=s(h*i).v;b<l&&([c,l]=[h*i,b])}let u=c-i,m=c+i,p=(Math.sqrt(5)-1)/2;for(let h=0;h<30;h++){let b=m-p*(m-u),g=u+p*(m-u);s(b).v<s(g).v?m=g:u=b}let d=s((u+m)/2),f=d.v<l?d:s(c);return{angle:Math.asin(Math.min(1,Math.min(l,d.v)))*wP,at:f.at}}function AP(e){let t=null;for(let r of e)Number.isFinite(r.angle)&&(!t||r.angle>t.angle)&&(t={angle:r.angle,joint:r.joint});return t}var XG={upright:"upright",lowerArm:"lca",upperArm:"uca"};function qG(e,t,r,n){let o=t.map(u=>jG(e,u)),a=Wr(Ga(e.uprightUpper,e.uprightLower)),s=(u,m,p)=>{let d=0,f=-1;for(let h=0;h<o.length;h++){let b=o[h],g=b[u]?WG(MP(b.upright,a),MP(b[u],a)):0;g>d&&([d,f]=[g,h])}return{joint:m,group:"ballJoint",angle:d,at:f,ends:p}},i=[s("lca","lower ball joint",["uprightLower","uprightUpper"])];e.mcpherson||i.push(s("uca","upper ball joint",["uprightUpper","uprightLower"]));let c=(u,m,p)=>{let d=[Ga(e[m],e[u])];for(let f=0;f<t.length;f++){let h=p(o[f]);if(!h)return null;d.push(zG(h,Ga(t[f][m],t[f][u])))}return d},l=[["tie rod, inner end",c("tieInner","tieOuter",()=>HG),["tieInner","tieOuter"]],["tie rod, outer end",c("tieInner","tieOuter",u=>u.upright),["tieOuter","tieInner"]]];e.direct||l.push([`${n}, rocker end`,c("rockerToPushrod","pushrodOuter",u=>u.rocker),["rockerToPushrod","pushrodOuter"]],[`${n}, outer end`,c("rockerToPushrod","pushrodOuter",u=>u[XG[r]]),["pushrodOuter","rockerToPushrod"]]);for(let[u,m,p]of l){if(!m)continue;let d=UG(m);i.push({joint:u,group:"rodEnd",angle:d.angle,at:d.angle>0?d.at-1:-1,ends:p})}return i}function kf(e,t,r,n){let o=qG(e,t,r,n);return{ballJoint:AP(o.filter(a=>a.group==="ballJoint")),rodEnd:AP(o.filter(a=>a.group==="rodEnd"))}}function Mf(e,t){let r=t.vehicle.config;return e.map(n=>{let o=n.axle==="front"?r.frontAxleX:r.frontAxleX-r.wheelbase,a=o+Math.min(n.xMin,n.xMax),s=o+Math.max(n.xMin,n.xMax),i=(a+s)/2;return{...n,min:[a,Math.min(n.yMin,n.yMax),Yr(Math.min(n.zMin,n.zMax),i,t)],max:[s,Math.max(n.yMin,n.yMax),Yr(Math.max(n.zMin,n.zMax),i,t)]}})}var Ka=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Fr=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Et=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Cr=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],xu=e=>Math.sqrt(Cr(e,e));function vR(e,t){return{min:e,max:t,support:r=>[r[0]>=0?t[0]:e[0],r[1]>=0?t[1]:e[1],r[2]>=0?t[2]:e[2]]}}function kR(e,t){return{min:[Math.min(e[0],t[0]),Math.min(e[1],t[1]),Math.min(e[2],t[2])],max:[Math.max(e[0],t[0]),Math.max(e[1],t[1]),Math.max(e[2],t[2])],support:r=>Cr(r,e)>=Cr(r,t)?e:t,samples:()=>Array.from({length:41},(r,n)=>Fr(e,Et(Ka(t,e),n/40)))}}function Ha(e){let t=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let n of e)for(let o=0;o<3;o++)t[o]=Math.min(t[o],n[o]),r[o]=Math.max(r[o],n[o]);return{min:t,max:r,support:n=>{let o=e[0],a=-1/0;for(let s of e){let i=Cr(n,s);i>a&&(a=i,o=s)}return o}}}function wi(e,t,r,n){let o=Et(t,1/(xu(t)||1)),a=n/2,s=o.map(i=>r*Math.sqrt(Math.max(0,1-i*i))+a*Math.abs(i));return{min:Ka(e,s),max:Fr(e,s),support:i=>{let c=Cr(i,o),l=Ka(i,Et(o,c)),u=xu(l),m=u>1e-12?Et(l,r/u):[0,0,0];return Fr(Fr(e,Et(o,c>=0?a:-a)),m)},samples:()=>{let i=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],c=Ka(i,Et(o,Cr(i,o))),l=Et(c,1/xu(c)),u=[o[1]*l[2]-o[2]*l[1],o[2]*l[0]-o[0]*l[2],o[0]*l[1]-o[1]*l[0]],m=[];for(let p of[-1,-.5,0,.5,1]){let d=Fr(e,Et(o,p*a));m.push(d);let f=Math.abs(p)===1?[.5,1]:[1];for(let h of f)for(let b=0;b<72;b++){let g=b/72*2*Math.PI;m.push(Fr(d,Fr(Et(l,h*r*Math.cos(g)),Et(u,h*r*Math.sin(g)))))}}return m}}}function QG(e){let t=e[0],r=e.slice(1).map(c=>Ka(c,t)),n=r.length;if(n===0)return{v:t,w:[1]};let o=r.map(c=>r.map(l=>Cr(c,l))),a=r.map(c=>-Cr(c,t));for(let c=0;c<n;c++){let l=c;for(let u=c+1;u<n;u++)Math.abs(o[u][c])>Math.abs(o[l][c])&&(l=u);if(Math.abs(o[l][c])<1e-12)return null;[o[c],o[l]]=[o[l],o[c]],[a[c],a[l]]=[a[l],a[c]];for(let u=0;u<n;u++){if(u===c)continue;let m=o[u][c]/o[c][c];for(let p=c;p<n;p++)o[u][p]-=m*o[c][p];a[u]-=m*a[c]}}let s=a.map((c,l)=>c/o[l][l]),i=t;for(let c=0;c<n;c++)i=Fr(i,Et(r[c],s[c]));return{v:i,w:[1-s.reduce((c,l)=>c+l,0),...s]}}function ZG(e){let t=null,r=1/0,n=e.length;for(let o=1;o<1<<n;o++){let a=e.filter((c,l)=>o&1<<l),s=QG(a.map(c=>c.w));if(!s||s.w.some(c=>c<-1e-9))continue;let i=Cr(s.v,s.v);(i<r-1e-12||Math.abs(i-r)<=1e-12&&t&&a.length<t.keep.length)&&(r=i,t={v:s.v,keep:a,weights:s.w})}return t??{v:e[0].w,keep:[e[0]],weights:[1]}}function Fi(e,t,r=1e-9){let n=i=>{let c=e.support(i),l=t.support(Et(i,-1));return{w:Ka(c,l),a:c,b:l}},o=(i,c)=>{let l=[0,0,0],u=[0,0,0];return i.keep.forEach((m,p)=>{l=Fr(l,Et(m.a,i.weights[p])),u=Fr(u,Et(m.b,i.weights[p]))}),{distance:c,onA:l,onB:u}},a=n([1,0,0]),s={v:a.w,keep:[a],weights:[1]};for(let i=0;i<64;i++){let c=s.v,l=Cr(c,c);if(l<1e-12)return o(s,0);let u=n(Et(c,-1));if(l-Cr(c,u.w)<=r*Math.max(1,l))return o(s,Math.sqrt(l));let m=ZG([...s.keep,u]);if(m.keep.length===4)return o(m,0);if(Cr(m.v,m.v)>=l-1e-12)return o(s,Math.sqrt(l));s=m}return o(s,xu(s.v))}function JG(e,t){let r=null;for(let o of t.samples?.()??[]){let a=1/0,s=0,i=0;for(let c=0;c<3;c++)o[c]-e.min[c]<a&&(a=o[c]-e.min[c],s=c,i=e.min[c]),e.max[c]-o[c]<a&&(a=e.max[c]-o[c],s=c,i=e.max[c]);a>0&&(!r||a>r.depth)&&(r={depth:a,point:o,axis:s,to:i})}if(!r)return null;let n=[...r.point];return n[r.axis]=r.to,{depth:r.depth,point:r.point,face:n}}function Sf(e,t){let r=0;for(let n=0;n<3;n++){let o=Math.max(0,e.min[n]-t.max[n],t.min[n]-e.max[n]);r+=o*o}return Math.sqrt(r)}var TP={linkRadius:8,mountAllowance:15},eK=(e,t,r)=>e.z0+e.dzdx*t+e.dzdy*r;function tK(e,t){let r=Math.sin(e.pitch);return{z0:-e.heave+t*r,dzdx:-r,dzdy:Math.sin(e.roll)}}function PP(e){return tK(gf({heave:0,pitch:0,roll:0,steer:0},e),bo(e.vehicle.config))}var rK=[{name:"upper wishbone, front leg",inboard:"ucaFront",outboard:"uprightUpper",body:"upperArm",ends:["chassis","upright"]},{name:"upper wishbone, rear leg",inboard:"ucaRear",outboard:"uprightUpper",body:"upperArm",ends:["chassis","upright"]},{name:"lower wishbone, front leg",inboard:"lcaFront",outboard:"uprightLower",body:"lowerArm",ends:["chassis","upright"]},{name:"lower wishbone, rear leg",inboard:"lcaRear",outboard:"uprightLower",body:"lowerArm",ends:["chassis","upright"]},{name:"tie rod",inboard:"tieInner",outboard:"tieOuter",body:"tieRod",ends:["chassis","upright"]},{name:"pushrod",inboard:"rockerToPushrod",outboard:"pushrodOuter",body:"rod",ends:["rocker","rodAttach"]},{name:"strut",inboard:"damperChassis",outboard:"pushrodOuter",body:"strut",ends:["chassis","upright"]}];function MR(e){return rK.filter(t=>t.name==="strut"?e.mcpherson:t.name==="pushrod"?!e.direct:!(e.mcpherson&&t.name.startsWith("upper")))}var LP=(e,t,r)=>e.every((n,o)=>n>=t.min[o]-r&&n<=t.max[o]+r);function FP(e,t,r){let n=Ka(t,e),o=xu(n);return o>1e-9?Fr(e,Et(n,r/o)):e}function SR(e,t,r){let n=Fi(e,t),o=n.distance>0?null:JG(e,t),a=n.distance>0?n.distance-r:-((o?.depth??0)+r),s=n.distance>0?{part:FP(n.onB,n.onA,r),box:n.onA}:o?{part:FP(o.point,o.face,-r),box:o.face}:{part:n.onB,box:n.onA};return{distance:a,gap:s}}function CP(e,t){let r=null;for(let{shape:n,pad:o,part:a,pose:s}of t){if(r){let c=Sf(e,n);if(c>0&&c-o>=r.distance)continue}let i=SR(e,n,o);Number.isFinite(i.distance)&&(!r||i.distance<r.distance)&&(r={distance:i.distance,part:a,corner:s.corner,travel:s.travel,rack:s.rack,gap:i.gap})}return r}function nK(e,t){let r=[];for(let c of[e.min[0],e.max[0]])for(let l of[e.min[1],e.max[1]])r.push([c,l,e.min[2]]);let n=r.map(t),o=Math.min(...n),a=r.filter((c,l)=>n[l]<=o+.5),s=new Set(a.map(c=>c[0])),i=new Set(a.map(c=>c[1]));return{height:o,lowest:{x:s.size>1||e.min[0]===e.max[0]?null:a[0][0]===e.max[0]?"front":"rear",y:i.size>1||e.min[1]===e.max[1]?null:a[0][1]===e.max[1]?"right":"left"},at:Et(a.reduce((c,l)=>Fr(c,l),[0,0,0]),1/a.length)}}function DP(e,t){return{...nK(e,r=>r[2]-eK(t,r[0],r[1])),road:t}}function EP(e,t){let r=(a,s,i)=>a[0]*(s[1]*i[2]-s[2]*i[1])-a[1]*(s[0]*i[2]-s[2]*i[0])+a[2]*(s[0]*i[1]-s[1]*i[0]),n=r(e[0],e[1],e[2]);if(Math.abs(n)<1e-12)return null;let o=a=>e.map((s,i)=>s.map((c,l)=>l===a?t[i]:c));return[r(...o(0))/n,r(...o(1))/n,r(...o(2))/n]}function oK(e,t){let r=e.map(o=>({pose:o,part:`${o.corner} tyre`,pad:0,shape:wi(o.g.wheelCenter,o.g.spinAxis,o.corner[0]==="F"?t.tyreRadius.front:t.tyreRadius.rear,t.tyreWidth)})),n=e.flatMap(o=>MR(o.g).map(a=>{let s=o.g[a.inboard],i=o.g[a.outboard];return{pose:o,part:`${o.corner} ${a.name}`,pad:t.linkRadius,inboard:s,shape:kR(s,i)}})).filter(o=>o.inboard.every(Number.isFinite)&&[o.shape.min,o.shape.max].every(a=>a.every(Number.isFinite)));return{tyres:r,links:n}}function aK(e,t,r){let n=vR(e.min,e.max),o=t.links.filter(a=>!LP(a.inboard,e,r.mountAllowance+r.linkRadius));return{tyre:CP(n,t.tyres),link:CP(n,o)}}function IP(e,t,r){let n=oK(t,r);return e.map(o=>({boxId:o.id,...aK(o,n,r)}))}var sK={r:[1,0,0,0,1,0,0,0,1],t:[0,0,0]},NP={r:[1,0,0,0,-1,0,0,0,1],t:[0,0,0]},Gt=(e,t)=>[e.r[0]*t[0]+e.r[1]*t[1]+e.r[2]*t[2]+e.t[0],e.r[3]*t[0]+e.r[4]*t[1]+e.r[5]*t[2]+e.t[1],e.r[6]*t[0]+e.r[7]*t[1]+e.r[8]*t[2]+e.t[2]],Af=(e,t)=>[e.r[0]*t[0]+e.r[1]*t[1]+e.r[2]*t[2],e.r[3]*t[0]+e.r[4]*t[1]+e.r[5]*t[2],e.r[6]*t[0]+e.r[7]*t[1]+e.r[8]*t[2]];function OP(e){let t=[e.r[0],e.r[3],e.r[6],e.r[1],e.r[4],e.r[7],e.r[2],e.r[5],e.r[8]],r=Af({r:t,t:[0,0,0]},e.t);return{r:t,t:[-r[0],-r[1],-r[2]]}}function Ru(e,t){let r=[];for(let n=0;n<3;n++)for(let o=0;o<3;o++)r.push(e.r[3*n]*t.r[o]+e.r[3*n+1]*t.r[3+o]+e.r[3*n+2]*t.r[6+o]);return{r,t:Gt(e,t.t)}}function AR(e){let t=xs(e,[1,0,0]),r=xs(e,[0,1,0]),n=xs(e,[0,0,1]);return[t[0],r[0],n[0],t[1],r[1],n[1],t[2],r[2],n[2]]}function iK(e){let r=e.map(a=>[...a]),n=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(let a=0;a<60;a++){let s=0;for(let i=0;i<4;i++)for(let c=i+1;c<4;c++)s+=r[i][c]*r[i][c];if(s<1e-30)break;for(let i=0;i<4;i++)for(let c=i+1;c<4;c++){if(Math.abs(r[i][c])<1e-300)continue;let l=(r[c][c]-r[i][i])/(2*r[i][c]),u=Math.sign(l||1)/(Math.abs(l)+Math.sqrt(l*l+1)),m=1/Math.sqrt(u*u+1),p=u*m;for(let d=0;d<4;d++){let f=r[d][i],h=r[d][c];r[d][i]=m*f-p*h,r[d][c]=p*f+m*h}for(let d=0;d<4;d++){let f=r[i][d],h=r[c][d];r[i][d]=m*f-p*h,r[c][d]=p*f+m*h}for(let d=0;d<4;d++){let f=n[d][i],h=n[d][c];n[d][i]=m*f-p*h,n[d][c]=p*f+m*h}}}let o=0;for(let a=1;a<4;a++)r[a][a]>r[o][o]&&(o=a);return[n[0][o],n[1][o],n[2][o],n[3][o]]}var _P=e=>{let t=[0,0,0];for(let r of e)for(let n=0;n<3;n++)t[n]+=r[n]/e.length;return t};function VP(e,t){let r=Math.min(e.length,t.length);if(r===0)return{iso:sK,residuals:[]};let n=_P(e.slice(0,r)),o=_P(t.slice(0,r)),a=[0,0,0,0,0,0,0,0,0];for(let S=0;S<r;S++){let A=[e[S][0]-n[0],e[S][1]-n[1],e[S][2]-n[2]],F=[t[S][0]-o[0],t[S][1]-o[1],t[S][2]-o[2]];for(let w=0;w<3;w++)for(let T=0;T<3;T++)a[3*w+T]+=A[w]*F[T]}let[s,i,c,l,u,m,p,d,f]=a,h=[[s+u+f,m-d,p-c,i-l],[m-d,s-u-f,i+l,p+c],[p-c,i+l,-s+u-f,m+d],[i-l,p+c,m+d,-s-u+f]],b=iK(h),g=Math.hypot(b[0],b[1],b[2],b[3])||1,y=AR([b[0]/g,b[1]/g,b[2]/g,b[3]/g]),x=Af({r:y,t:[0,0,0]},n),R={r:y,t:[o[0]-x[0],o[1]-x[1],o[2]-x[2]]},v=[];for(let S=0;S<r;S++){let A=Gt(R,e[S]);v.push(Math.hypot(A[0]-t[S][0],A[1]-t[S][1],A[2]-t[S][2]))}return{iso:R,residuals:v}}var Kfe=Math.PI/180;function BP(e,t,r,n){let o=(Math.sqrt(5)-1)/2,a=t,s=r,i=s-o*(s-a),c=a+o*(s-a),l=e(i),u=e(c);for(;s-a>n;)l<=u?(s=c,c=i,u=l,i=s-o*(s-a),l=e(i)):(a=i,i=c,l=u,c=a+o*(s-a),u=e(c));return l<=u?{x:i,v:l}:{x:c,v:u}}var cK=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],$P=e=>Math.hypot(e[0],e[1],e[2]);var lK=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r],GP=(...e)=>e.every(t=>t.every(Number.isFinite)),uK={rocker:"rocker",lowerArm:"lowerArm",upright:"upright"};function KP(e,t,r,n,o){if(vf(t,void 0,e.axle).roll)return[];let a=dw(e.axle,t,r,e.armLength);if(!GP(a.tip,a.outer,a.root))return[];let s=o.housing.rodEnd,i={kind:"link",corner:n},c=[{...i,id:`${n} drop link`,name:"drop link",body:"dropLink",ends:["arb",uK[e.axle.linkage.attach]],a:a.tip,b:a.outer,radius:o.tube.dropLink,housing:[s,s]}];if(e.armLength>0){c.push({...i,id:`${n} anti-roll bar arm`,name:"anti-roll bar arm",body:"arb",ends:["arb","arb"],a:a.root,b:a.tip,radius:e.armRadius,housing:[0,s]});let l=[a.root[0],-a.root[1],a.root[2]];c.push({...i,id:`${n} anti-roll bar`,name:"anti-roll bar",body:"arb",ends:["chassis","chassis"],a:a.root,b:l,radius:e.barRadius,housing:[0,0],shared:!0})}return c}function HP(e,t){return{kind:"link",id:`${t} rack housing`,name:"rack housing",corner:t,body:"rackHousing",ends:["rack","rack"],a:e.a,b:e.b,radius:e.radius,housing:[0,0],shared:!0,flat:!0}}function mK(e){let t=$P(e.spinAxis)||1,r=[e.spinAxis[0]/t,e.spinAxis[1]/t,e.spinAxis[2]/t],n=e.wheelCenter[1]>=0?1:-1;return r[1]*n<0?[-r[0],-r[1],-r[2]]:r}function dK(e,t){let r=mK(e);return[e.wheelCenter[0]-r[0]*t,e.wheelCenter[1]-r[1]*t,e.wheelCenter[2]-r[2]*t]}var pK=(e,t)=>t[1]==="L"?e.inboard.left:e.inboard.right;function zP(e,t,r){let n=pK(e,r),o=dK(t,e.outboard);return GP(n,o)?{kind:"link",id:`${r} driveshaft`,name:"driveshaft",corner:r,body:"driveshaft",ends:["chassis","upright"],a:n,b:o,radius:e.radius,housing:[e.reach,e.reach]}:null}function YP(e,t,r,n,o,a,s,i){let c=$P(cK(a.p,o.p)),l=Math.min(c,s.bodyLength),u=l>=c,m=c>1e-9?lK(o.p,a.p,l/c):o.p,p={kind:"link",corner:n,body:r},d={...p,id:`${e} body`,name:`${t} body`,ends:[o.body,u?a.body:r],endCorners:[o.corner,u?a.corner:n],a:o.p,b:m,radius:s.bodyRadius,housing:[i,u?i:0],flat:!0};return u?[d]:[d,{...p,id:`${e} shaft`,name:`${t} shaft`,ends:[r,a.body],endCorners:[n,a.corner],a:m,b:a.p,radius:s.shaftRadius,housing:[0,i]}]}var Ci=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Ff=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Do=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],wR=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Cf=e=>Math.sqrt(wR(e,e)),FR=(e,t,r)=>Ff(e,Do(Ci(t,e),r));function UP(e,t,r){let n=e.diameter/2,o=Math.max(n,t),a=r/2,s=Math.min(a,e.width/2),i=(n+o)/2,c=[];for(let l=0;l<3;l++){let u=s+(a-s)*(l+1)/3;c.push({z0:-u,z1:u,r0:n+(i-n)*l/3,r1:n+(i-n)*(l+1)/3})}return c.push({z0:-a,z1:a,r0:i,r1:o}),c}function XP(e){let t=e.diameter/2,r=fK(e),n=e.width/2,o={z0:-n,z1:n,r0:r,r1:t};if(e.offset===null)return[o];let a=Math.min(n,Math.max(-n,e.offset));return[o,{z0:a,z1:n,r0:0,r1:r}]}var fK=e=>Math.max(0,e.diameter/2-e.wall);function hK(e,t){let r=Ci(e,t.centre),n=wR(r,t.axis),o=Ci(r,Do(t.axis,n)),a=Cf(o);if(a>1e-9)return{z:n,r:a,out:Do(o,1/a)};let s=Math.abs(t.axis[0])<.9?[1,0,0]:[0,1,0],i=Ci(s,Do(t.axis,wR(s,t.axis)));return{z:n,r:0,out:Do(i,1/Cf(i))}}function WP(e,t,r){if(!(t>e.z0&&t<e.z1&&r<e.r1&&(e.r0>0?r>e.r0:r>=0))){let s=Math.min(e.z1,Math.max(e.z0,t)),i=Math.min(e.r1,Math.max(e.r0,r));return{d:Math.hypot(t-s,r-i),z:s,r:i}}let o=[{d:t-e.z0,z:e.z0,r},{d:e.z1-t,z:e.z1,r},{d:e.r1-r,z:t,r:e.r1}];e.r0>0&&o.push({d:r-e.r0,z:t,r:e.r0});let a=o.reduce((s,i)=>i.d<s.d?i:s);return{d:-a.d,z:a.z,r:a.r}}var bK=16,jP=new WeakMap;function gK(e){let t=jP.get(e);if(t)return t;let r=Int32Array.from(e.keys()).sort((s,i)=>e[s].z0-e[i].z0||s-i),n=Float64Array.from(r,s=>e[s].z0),o=new Float64Array(r.length),a=-1/0;return r.forEach((s,i)=>{a=Math.max(a,e[s].z1),o[i]=a}),t={order:r,z0:n,reach:o},jP.set(e,t),t}function vu(e,t,r){let n=hK(e,r),o={d:1/0,z:0,r:0};if(t.length<bK)for(let a of t){let s=WP(a,n.z,n.r);s.d<o.d&&(o=s)}else{let{order:a,z0:s,reach:i}=gK(t),c=1/0,l=p=>{let d=WP(t[p],n.z,n.r);(d.d<o.d||d.d===o.d&&p<c)&&(o=d,c=p)},u=0,m=a.length;for(;u<m;){let p=u+m>>1;s[p]<=n.z?u=p+1:m=p}for(let p=u-1;p>=0&&n.z-i[p]<=Math.max(0,o.d);p--){let d=n.z-t[a[p]].z1;(d<=0||d<=o.d)&&l(a[p])}for(let p=u;p<a.length&&s[p]-n.z<=o.d;p++)l(a[p])}return{distance:o.d,on:Ff(Ff(r.centre,Do(r.axis,o.z)),Do(n.out,o.r))}}var wf=(Math.sqrt(5)-1)/2;function yK(e,t,r,n){let o=t,a=r,s=a-wf*(a-o),i=o+wf*(a-o),c=e(s),l=e(i);for(;a-o>n;)c<=l?(a=i,i=s,l=c,s=a-wf*(a-o),c=e(s)):(o=s,s=i,c=l,i=o+wf*(a-o),l=e(i));return c<=l?s:i}var xK=24;function qP(e,t,r,n){let o=u=>vu(FR(e,t,u),r,n).distance,a=Cf(Ci(t,e))<1e-9?0:xK,s=0,i=o(0);for(let u=1;u<=a;u++){let m=o(u/a);m<i&&(i=m,s=u)}if(a===0)return{t:0,distance:i};let c=yK(o,Math.max(0,(s-1)/a),Math.min(1,(s+1)/a),1e-4),l=o(c);return l<i?{t:c,distance:l}:{t:s/a,distance:i}}function QP(e,t,r,n,o){let{t:a}=qP(e,t,n,o),s=FR(e,t,a),i=vu(s,n,o);return{distance:i.distance-r,onPart:JP(s,i.on,r,i.distance),onWheel:i.on}}function ZP(e,t,r,n){let o=null,a=i=>{let c=vu(i,r,n);(!o||c.distance<o.distance)&&(o={p:i,distance:c.distance,on:c.on})};for(let i of e)a(i);for(let i=0;i<e.length;i++)for(let c=i+1;c<e.length;c++){let l=qP(e[i],e[c],r,n);(!o||l.distance<o.distance)&&a(FR(e[i],e[c],l.t))}let s=o;return{distance:s.distance-t,onPart:JP(s.p,s.on,t,s.distance),onWheel:s.on}}function JP(e,t,r,n){let o=Ci(t,e),a=Cf(o);return a<1e-9||r===0?e:Ff(e,Do(o,(n>=0?r:-r)/a))}function Mu(e,t){return e&&t>0?{...e,distance:Math.max(0,e.distance-t)}:e}var Pi=e=>e.allowance??0;function Lf(e,t,r,n,o){let a=r[0]-t[0],s=r[1]-t[1],i=r[2]-t[2],c=n[0]-t[0],l=n[1]-t[1],u=n[2]-t[2],m=e[0]-t[0],p=e[1]-t[1],d=e[2]-t[2],f=a*m+s*p+i*d,h=c*m+l*p+u*d,b=(_,D,I)=>{o[0]=_,o[1]=D,o[2]=I;let N=e[0]-_,O=e[1]-D,V=e[2]-I;return N*N+O*O+V*V};if(f<=0&&h<=0)return b(t[0],t[1],t[2]);let g=e[0]-r[0],y=e[1]-r[1],x=e[2]-r[2],R=a*g+s*y+i*x,v=c*g+l*y+u*x;if(R>=0&&v<=R)return b(r[0],r[1],r[2]);let S=f*v-R*h;if(S<=0&&f>=0&&R<=0){let _=f/(f-R);return b(t[0]+_*a,t[1]+_*s,t[2]+_*i)}let A=e[0]-n[0],F=e[1]-n[1],w=e[2]-n[2],T=a*A+s*F+i*w,M=c*A+l*F+u*w;if(M>=0&&T<=M)return b(n[0],n[1],n[2]);let k=T*h-f*M;if(k<=0&&h>=0&&M<=0){let _=h/(h-M);return b(t[0]+_*c,t[1]+_*l,t[2]+_*u)}let C=R*M-T*v;if(C<=0&&v-R>=0&&T-M>=0){let _=(v-R)/(v-R+(T-M));return b(r[0]+_*(n[0]-r[0]),r[1]+_*(n[1]-r[1]),r[2]+_*(n[2]-r[2]))}let P=1/(C+k+S),L=k*P,E=S*P;return b(t[0]+a*L+c*E,t[1]+s*L+l*E,t[2]+i*L+u*E)}function CR(e,t,r,n,o,a){let s=t[0]-e[0],i=t[1]-e[1],c=t[2]-e[2],l=n[0]-r[0],u=n[1]-r[1],m=n[2]-r[2],p=e[0]-r[0],d=e[1]-r[1],f=e[2]-r[2],h=s*s+i*i+c*c,b=l*l+u*u+m*m,g=l*p+u*d+m*f,y=F=>F<0?0:F>1?1:F,x=0,R=0;if(h<=1e-12&&b<=1e-12)x=0,R=0;else if(h<=1e-12)R=y(g/b);else{let F=s*p+i*d+c*f;if(b<=1e-12)x=y(-F/h);else{let w=s*l+i*u+c*m,T=h*b-w*w;x=T>1e-12?y((w*g-F*b)/T):0,R=(w*x+g)/b,R<0?(R=0,x=y(-F/h)):R>1&&(R=1,x=y((w-F)/h))}}o[0]=e[0]+x*s,o[1]=e[1]+x*i,o[2]=e[2]+x*c,a[0]=r[0]+R*l,a[1]=r[1]+R*u,a[2]=r[2]+R*m;let v=o[0]-a[0],S=o[1]-a[1],A=o[2]-a[2];return v*v+S*S+A*A}function RK(e,t,r,n,o,a){let s=t[0]-e[0],i=t[1]-e[1],c=t[2]-e[2],l=n[0]-r[0],u=n[1]-r[1],m=n[2]-r[2],p=o[0]-r[0],d=o[1]-r[1],f=o[2]-r[2],h=i*f-c*d,b=c*p-s*f,g=s*d-i*p,y=l*h+u*b+m*g,x=Math.sqrt((s*s+i*i+c*c)*(l*l+u*u+m*m)*(p*p+d*d+f*f));if(Math.abs(y)<=1e-12*x)return!1;let R=1/y,v=e[0]-r[0],S=e[1]-r[1],A=e[2]-r[2],F=(v*h+S*b+A*g)*R;if(F<0||F>1)return!1;let w=S*m-A*u,T=A*l-v*m,M=v*u-S*l,k=(s*w+i*T+c*M)*R;if(k<0||F+k>1)return!1;let C=(p*w+d*T+f*M)*R;return C<0||C>1?!1:(a[0]=e[0]+C*s,a[1]=e[1]+C*i,a[2]=e[2]+C*c,!0)}function Df(e,t,r,n,o,a,s){if(RK(e,t,r,n,o,s))return a[0]=s[0],a[1]=s[1],a[2]=s[2],0;let i=[0,0,0],c=[0,0,0],l=Lf(e,r,n,o,s);a[0]=e[0],a[1]=e[1],a[2]=e[2];let u=(m,p,d)=>{m>=l||(l=m,a[0]=p[0],a[1]=p[1],a[2]=p[2],s[0]=d[0],s[1]=d[1],s[2]=d[2])};return u(Lf(t,r,n,o,c),t,c),u(CR(e,t,r,n,i,c),i,c),u(CR(e,t,n,o,i,c),i,c),u(CR(e,t,o,r,i,c),i,c),l}function PR(e,t,r,n){let o=e.box,a=6*t,s=0;for(let i=0;i<3;i++){let c=Math.max(0,o[a+i]-n[i],r[i]-o[a+3+i]);s+=c*c}return s}function TR(e,t,r){for(let n of r){let o=0;for(let a=0;a<3;a++){let s=Math.max(Math.abs(n.c[a]-e[t+a]),Math.abs(e[t+3+a]-n.c[a]));o+=s*s}if(o<=n.r*n.r)return!0}return!1}function Ef(e,t,r,n,o){let a=n;if(!e.nodes)return a;let s=[0],i=[t(0)];for(;s.length;){let c=s.pop();if(i.pop()>=a||o.length&&TR(e.box,6*c,o))continue;if(e.right[c]<0){let f=e.start[c]+e.size[c];for(let h=e.start[c];h<f;h++){let b=r(h,a);if(b<a&&(a=b),a<=0)return 0}continue}let u=c+1,m=e.right[c],p=t(u),d=t(m);p<=d?(d<a&&(s.push(m),i.push(d)),p<a&&(s.push(u),i.push(p))):(p<a&&(s.push(u),i.push(p)),d<a&&(s.push(m),i.push(d)))}return a}function rL(e,t,r){let n=[Math.min(t[0],r[0]),Math.min(t[1],r[1]),Math.min(t[2],r[2])],o=[Math.max(t[0],r[0]),Math.max(t[1],r[1]),Math.max(t[2],r[2])],a=r[0]-t[0],s=r[1]-t[1],i=r[2]-t[2],c=a*a+s*s+i*i,l=e.box;return u=>{let m=6*u,p=(l[m]+l[m+3])/2,d=(l[m+1]+l[m+4])/2,f=(l[m+2]+l[m+5])/2,h=(l[m+3]-l[m])/2,b=(l[m+4]-l[m+1])/2,g=(l[m+5]-l[m+2])/2,y=c>1e-12?((p-t[0])*a+(d-t[1])*s+(f-t[2])*i)/c:0;y=y<0?0:y>1?1:y;let x=p-t[0]-y*a,R=d-t[1]-y*s,v=f-t[2]-y*i,S=Math.sqrt(x*x+R*R+v*v)-Math.sqrt(h*h+b*b+g*g);return Math.max(S,Math.sqrt(PR(e,u,n,o)))}}var Xt=(e,t,r)=>{let n=9*t+3*r;return[e.tri[n],e.tri[n+1],e.tri[n+2]]};function Su(e,t,r,n=1/0,o=[]){let a=Pi(e);return Mu(vK(e,t,r,n+a,o),a)}function vK(e,t,r,n=1/0,o=[]){let a=rL(e,t,r),s=[0,0,0],i=[0,0,0],c=null,l=Ef(e,a,(u,m)=>{let p=1/0;return ao(Xt(e,u,0),Xt(e,u,1),Xt(e,u,2),o,(d,f,h)=>{let b=Math.sqrt(Df(t,r,d,f,h,s,i));b<p&&(p=b),b<m&&(!c||b<c.distance)&&(c={distance:b,onMesh:[...i],onPart:[...s]})}),p},n,o);return c&&c.distance===l?c:null}function If(e,t,r,n,o,a=1/0,s=[]){let i=Pi(e);return Mu(kK(e,t,r,n,o,a+i,s),i)}function kK(e,t,r,n,o,a=1/0,s=[]){let i=wi(t,r,n,o),c=Math.hypot(r[0],r[1],r[2])||1,l=r[0]/c,u=r[1]/c,m=r[2]/c,p=o/2,d=[t[0]-p*l,t[1]-p*u,t[2]-p*m],f=[t[0]+p*l,t[1]+p*u,t[2]+p*m],h=e.box,b=rL(e,d,f),g=S=>{let A=6*S,F=(h[A]+h[A+3])/2,w=(h[A+1]+h[A+4])/2,T=(h[A+2]+h[A+5])/2,M=(h[A+3]-h[A])/2,k=(h[A+4]-h[A+1])/2,C=(h[A+5]-h[A+2])/2,P=(F-t[0])*l+(w-t[1])*u+(T-t[2])*m,L=Math.abs(l)*M+Math.abs(u)*k+Math.abs(m)*C,E=Math.max(0,Math.abs(P)-L-p);return Math.max(E,b(S)-n,Math.sqrt(PR(e,S,i.min,i.max)))},y=[0,0,0],x=[0,0,0],R=null,v=Ef(e,g,(S,A)=>{let F=1/0;return ao(Xt(e,S,0),Xt(e,S,1),Xt(e,S,2),s,(w,T,M)=>{let k=Math.min(A,F),C=(w[0]-t[0])*l+(w[1]-t[1])*u+(w[2]-t[2])*m,P=(T[0]-t[0])*l+(T[1]-t[1])*u+(T[2]-t[2])*m,L=(M[0]-t[0])*l+(M[1]-t[1])*u+(M[2]-t[2])*m;if(Math.max(0,Math.min(C,P,L)-p,-p-Math.max(C,P,L))>=k||Math.sqrt(Df(d,f,w,T,M,y,x))-n>=k)return;let _=Fi(Ha([w,T,M]),i,1e-6);if(_.distance<k)if(_.distance>0)R={distance:_.distance,onMesh:_.onA,onPart:_.onB};else{let D=[0,0,0];Lf(t,w,T,M,D),R={distance:0,onMesh:D,onPart:D}}_.distance<F&&(F=_.distance)}),F},a,s);return R&&R.distance===v?R:null}var LR=(e,t,r)=>Su(e,t,t,r)!==null;var Tf=(e,t)=>{let r=e[0]-t.c[0],n=e[1]-t.c[1],o=e[2]-t.c[2];return r*r+n*n+o*o<=t.r*t.r},Ti=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2,(e[2]+t[2])/2],za=(e,t)=>(e[0]-t[0])**2+(e[1]-t[1])**2+(e[2]-t[2])**2,MK=1,SK=6;function ao(e,t,r,n,o,a=0){if(!n.length)return o(e,t,r);let s=[0,0,0],i=n.filter(p=>Lf(p.c,e,t,r,s)<=p.r*p.r);if(!i.length)return o(e,t,r);for(let p of i)if(Tf(e,p)&&Tf(t,p)&&Tf(r,p))return;if(Math.sqrt(Math.max(za(e,t),za(t,r),za(r,e)))<=Math.max(MK,Math.min(...i.map(p=>p.r))/8)||a>=SK){let p=[(e[0]+t[0]+r[0])/3,(e[1]+t[1]+r[1])/3,(e[2]+t[2]+r[2])/3];i.some(d=>Tf(p,d))||o(e,t,r);return}let l=Ti(e,t),u=Ti(t,r),m=Ti(r,e);ao(e,l,m,i,o,a+1),ao(l,t,u,i,o,a+1),ao(m,u,r,i,o,a+1),ao(l,u,m,i,o,a+1)}function AK(e,t,r,n){let o=[];return ao(e,t,r,n,(a,s,i)=>o.push([a,s,i])),o}var wK=e=>[Math.min(e[0][0],e[1][0],e[2][0]),Math.min(e[0][1],e[1][1],e[2][1]),Math.min(e[0][2],e[1][2],e[2][2]),Math.max(e[0][0],e[1][0],e[2][0]),Math.max(e[0][1],e[1][1],e[2][1]),Math.max(e[0][2],e[1][2],e[2][2])];function DR(e,t,r=1/0,n=[]){let o=Pi(e);return Mu(FK(e,t,r+o,n),o)}function FK(e,t,r=1/0,n=[]){let o=null,a=Ef(e,s=>Math.sqrt(PR(e,s,t.min,t.max)),(s,i)=>{let c=1/0;return ao(Xt(e,s,0),Xt(e,s,1),Xt(e,s,2),n,(l,u,m)=>{let p=Ha([l,u,m]),d=Math.min(i,c),f=0;for(let b=0;b<3;b++){let g=Math.max(0,p.min[b]-t.max[b],t.min[b]-p.max[b]);f+=g*g}if(Math.sqrt(f)>=d)return;let h=Fi(p,t,1e-6);if(h.distance<d)if(h.distance>0)o={distance:h.distance,onMesh:h.onA,onPart:h.onB};else{let b=[(l[0]+u[0]+m[0])/3,(l[1]+u[1]+m[1])/3,(l[2]+u[2]+m[2])/3];o={distance:0,onMesh:b,onPart:b}}h.distance<c&&(c=h.distance)}),c},r,n);return o&&o.distance===a?o:null}function CK(e,t,r,n,o,a,s,i){let c=[0,0,0],l=[0,0,0],u=1/0,m=(f,h,b)=>{f>=u||(u=f,s[0]=h[0],s[1]=h[1],s[2]=h[2],i[0]=b[0],i[1]=b[1],i[2]=b[2])},p=[e,t,r],d=[n,o,a];for(let f=0;f<3;f++)if(m(Df(p[f],p[(f+1)%3],n,o,a,c,l),c,l),u===0)return 0;for(let f=0;f<3;f++)if(m(Df(d[f],d[(f+1)%3],e,t,r,c,l),l,c),u===0)return 0;return u}var TK=.002;function ER(e,t,r,n=1/0,o=[]){let a=Pi(e)+Pi(t);return Mu(PK(e,t,r,n+a,o),a)}function PK(e,t,r,n=1/0,o=[]){if(!e.nodes||!t.nodes)return null;let a=new Float64Array(6*t.nodes).fill(NaN),s=x=>{let R=6*x;if(!Number.isNaN(a[R]))return R;let v=1/0,S=1/0,A=1/0,F=-1/0,w=-1/0,T=-1/0;for(let M=0;M<8;M++){let k=Gt(r,[t.box[R+(M&1?3:0)],t.box[R+1+(M&2?3:0)],t.box[R+2+(M&4?3:0)]]);k[0]<v&&(v=k[0]),k[0]>F&&(F=k[0]),k[1]<S&&(S=k[1]),k[1]>w&&(w=k[1]),k[2]<A&&(A=k[2]),k[2]>T&&(T=k[2])}return a.set([v,S,A,F,w,T],R),R},i=(x,R)=>{let v=6*x,S=s(R),A=0;for(let F=0;F<3;F++){let w=Math.max(0,e.box[v+F]-a[S+3+F],a[S+F]-e.box[v+3+F]);A+=w*w}return Math.sqrt(A)},c=(x,R)=>(x[R+3]-x[R])**2+(x[R+4]-x[R+1])**2+(x[R+5]-x[R+2])**2,l=(x,R,v)=>{let S=[Xt(x,R,0),Xt(x,R,1),Xt(x,R,2)];return v?S.map(A=>Gt(v,A)):S},u=new Map,m=new Map,p=(x,R,v,S)=>{let A=S.get(R);if(!A){A=[];let F=x.start[R]+x.size[R];for(let w=x.start[R];w<F;w++)for(let T of AK(...l(x,w,v),o))A.push({t:T,box:wK(T)});S.set(R,A)}return A},d=n,f=n,h=null,b=[0,0,0],g=[0,0,0],y=[[0,0,i(0,0)]];for(;y.length;){let[x,R,v]=y.pop();if(v>=f||o.length&&(TR(e.box,6*x,o)||TR(a,s(R),o)))continue;let S=e.right[x]<0,A=t.right[R]<0;if(S&&A){let k=p(t,R,r,m);if(!k.length)continue;for(let C of p(e,x,null,u))for(let P of k){let L=0;for(let _=0;_<3;_++){let D=Math.max(0,C.box[_]-P.box[3+_],P.box[_]-C.box[3+_]);L+=D*D}if(L>=f*f)continue;let E=Math.sqrt(CK(C.t[0],C.t[1],C.t[2],P.t[0],P.t[1],P.t[2],b,g));if(E<d&&(d=E,f=E*(1-TK),h={distance:E,onA:[...b],onB:[...g]},d<=0))return h}continue}let w=!S&&(A||c(e.box,6*x)>=c(a,s(R)))?[[x+1,R],[e.right[x],R]]:[[x,R+1],[x,t.right[R]]],T=w.map(([k,C])=>i(k,C)),M=T[0]<=T[1]?[1,0]:[0,1];for(let k of M)T[k]<f&&y.push([w[k][0],w[k][1],T[k]])}return h}function ku(e,t){let r=e[0]-t.centre[0],n=e[1]-t.centre[1],o=e[2]-t.centre[2],a=r*t.axis[0]+n*t.axis[1]+o*t.axis[2],s=r-a*t.axis[0],i=n-a*t.axis[1],c=o-a*t.axis[2];return[a,Math.sqrt(s*s+i*i+c*c)]}function eL(e,t,r,n,o){let a=1/0;for(let s of o){let i=Math.max(0,s.z0-t,e-s.z1),c=Math.max(0,s.r0-n,r-s.r1),l=Math.hypot(i,c);l<a&&(a=l)}return a}var Pf=8;function nL(e,t,r,n=1/0,o=[]){let a=Pi(e);return Mu(LK(e,t,r,n+a,o),a)}function LK(e,t,r,n=1/0,o=[]){if(!r.length)return null;let a=e.box,s=d=>{let f=6*d,h=1/0,b=-1/0,g=0;for(let S=0;S<8;S++){let[A,F]=ku([a[f+(S&1?3:0)],a[f+1+(S&2?3:0)],a[f+2+(S&4?3:0)]],t);A<h&&(h=A),A>b&&(b=A),F>g&&(g=F)}let y=(a[f+3]-a[f])/2,x=(a[f+4]-a[f+1])/2,R=(a[f+5]-a[f+2])/2,[,v]=ku([a[f]+y,a[f+1]+x,a[f+2]+R],t);return eL(h,b,Math.max(0,v-Math.sqrt(y*y+x*x+R*R)),g,r)},i=d=>vu(d,r,t),c=null,l=(d,f)=>{let h=i(d),b=Math.max(0,h.distance);return b<f&&(!c||b<c.distance)&&(c={distance:b,onMesh:d,onPart:b>0?h.on:d}),b},u=(d,f,h)=>{let b=M=>i([d[0]+(f[0]-d[0])*M,d[1]+(f[1]-d[1])*M,d[2]+(f[2]-d[2])*M]).distance,g=0,y=1/0;for(let M=1;M<Pf;M++){let k=b(M/Pf);k<y&&(y=k,g=M)}let x=(g-1)/Pf,R=(g+1)/Pf,v=(Math.sqrt(5)-1)/2,S=R-v*(R-x),A=x+v*(R-x),F=b(S),w=b(A);for(;R-x>.001;)F<=w?(R=A,A=S,w=F,S=R-v*(R-x),F=b(S)):(x=S,S=A,F=w,A=x+v*(R-x),w=b(A));let T=F<=w?S:A;return l([d[0]+(f[0]-d[0])*T,d[1]+(f[1]-d[1])*T,d[2]+(f[2]-d[2])*T],h)},m=(d,f,h,b,g)=>{let y=ku(d,t),x=ku(f,t),R=ku(h,t),v=Math.max(za(d,f),za(f,h),za(h,d)),S=Math.max(y[1],x[1],R[1]);if(eL(Math.min(y[0],x[0],R[0]),Math.max(y[0],x[0],R[0]),Math.max(0,S-Math.sqrt(v)),S,r)>=b)return 1/0;if(v>tL*tL&&g<4){let k=Ti(d,f),C=Ti(f,h),P=Ti(h,d),L=1/0;for(let[E,_,D]of[[d,k,P],[k,f,C],[P,C,h],[k,C,P]])L=Math.min(L,m(E,_,D,Math.min(b,L),g+1));return L}let F=1/0,w=[d,f,h].map(k=>{let C=l(k,Math.min(b,F));return F=Math.min(F,C),C}),T=Math.min(b,F),M=(k,C,P,L)=>(P+L-Math.sqrt(za(k,C)))/2>=T?1/0:u(k,C,T);return F=Math.min(F,M(d,f,w[0],w[1]),M(f,h,w[1],w[2]),M(h,d,w[2],w[0])),F},p=Ef(e,s,(d,f)=>{let h=1/0;return ao(Xt(e,d,0),Xt(e,d,1),Xt(e,d,2),o,(b,g,y)=>{h=Math.min(h,m(b,g,y,Math.min(f,h),0))}),h},n,o);return c&&c.distance===p?c:null}var tL=25;var NR=["upright","wheel","upperArm","lowerArm","rocker","damperBody"],OR={upright:"upright",wheel:"wheel",upperArm:"upper wishbone",lowerArm:"lower wishbone",rocker:"rocker",damperBody:"damper body"},EK=.5;function VR(e,t,r){let n=[];switch(t){case"upright":case"wheel":e.mcpherson||n.push("uprightUpper"),n.push("uprightLower","tieOuter"),(e.mcpherson||r==="upright")&&n.push("pushrodOuter");break;case"upperArm":if(e.mcpherson)return[];n.push("ucaFront","ucaRear","uprightUpper"),r==="upperArm"&&n.push("pushrodOuter");break;case"lowerArm":n.push("lcaFront","lcaRear","uprightLower"),r==="lowerArm"&&!e.mcpherson&&n.push("pushrodOuter");break;case"rocker":if(e.direct)return[];n.push("rockerPivotA","rockerPivotB","rockerToPushrod","rockerToDamper");break;case"damperBody":if(e.decoupled||e.mcpherson)return[];n.push("damperChassis",e.direct?"pushrodOuter":"rockerToDamper");break}return n.filter(o=>e[o].every(Number.isFinite))}var IK=e=>e[1]==="L"?"left":"right",_K=e=>[e[0],-e[1],e[2]];function oL(e,t,r,n,o){let a=VR(r,t,o).filter(f=>e.placedOn[f]?.every(Number.isFinite)),s=IK(n)!==e.side,i=a.map(f=>s?_K(e.placedOn[f]):e.placedOn[f]),c=a.map(f=>r[f]),l=s?NP:null;if(t==="damperBody"){if(a.length<2)return null;let f=_f(Li(i[1],i[0])),h=_f(Li(c[1],c[0])),b=AR(cm(f,h)),g=Gt({r:b,t:[0,0,0]},i[0]),y={r:b,t:Li(c[0],g)};return{iso:l?Ru(y,l):y,worst:null}}if(a.length<3)return null;let u=VP(i,c),m=Math.max(...u.residuals),p=0,d=-1;for(let f=0;f<a.length;f++){let h=0;for(let b=0;b<a.length;b++)b!==f&&(h+=Math.abs(_R(Li(i[f],i[b]))-_R(Li(c[f],c[b]))));h>d&&([p,d]=[f,h])}return{iso:l?Ru(u.iso,l):u.iso,worst:{key:a[p],by:m}}}var aL=e=>!!e&&(!e.worst||e.worst.by<=EK);var NK=1,IR=.5;function OK(e,t,r=NK){let n=_f(t.axis),o=Math.abs(n[0])<.9?[1,0,0]:[0,1,0],a=_f(Li(o,sL(n,Au(o,n)))),s=$K(n,a),i=Math.floor(e.length/9),c=new Float64Array(9*i),l=1/0,u=-1/0;for(let h=0;h<3*i;h++){let b=[e[3*h]-t.centre[0],e[3*h+1]-t.centre[1],e[3*h+2]-t.centre[2]],g=Au(b,n);c[3*h]=Au(b,a),c[3*h+1]=Au(b,s),c[3*h+2]=g,g<l&&(l=g),g>u&&(u=g)}if(!i)return[];let m=Math.max(1,Math.ceil((u-l)/r)),p=new Float64Array(m).fill(1/0),d=new Float64Array(m).fill(-1/0);for(let h=0;h<i;h++){let b=[0,1,2].map(v=>[c[9*h+3*v],c[9*h+3*v+1],c[9*h+3*v+2]]),g=Math.min(b[0][2],b[1][2],b[2][2]),y=Math.max(b[0][2],b[1][2],b[2][2]),x=Math.max(0,Math.min(m-1,Math.floor((g-l)/r))),R=Math.max(0,Math.min(m-1,Math.floor((y-l)/r)));for(let v=x;v<=R;v++){let S=VK(b,l+v*r,l+(v+1)*r);if(!S.length)continue;let A=0;for(let w of S)A=Math.max(A,Math.hypot(w[0],w[1]));let F=BK(S);F<p[v]&&(p[v]=F),A>d[v]&&(d[v]=A)}}let f=[];for(let h=0;h<m;h++){if(!(d[h]>=0))continue;let b=p[h]<IR?0:p[h],g=f[f.length-1],y=l+h*r;g&&Math.abs(g.z1-y)<1e-9&&Math.abs(g.r0-b)<=IR&&Math.abs(g.r1-d[h])<=IR?(g.z1=y+r,g.r0=Math.min(g.r0,b),g.r1=Math.max(g.r1,d[h])):f.push({z0:y,z1:y+r,r0:b,r1:d[h]})}return f}function VK(e,t,r){let n=(o,a)=>{let s=[];for(let i=0;i<o.length;i++){let c=o[i],l=o[(i+1)%o.length],u=a(c),m=a(l);if(u>=0&&s.push(c),u>=0!=m>=0){let p=u/(u-m);s.push([c[0]+(l[0]-c[0])*p,c[1]+(l[1]-c[1])*p,c[2]+(l[2]-c[2])*p])}}return s};return n(n(e,o=>o[2]-t),o=>r-o[2])}function BK(e){let t=!1,r=!1,n=1/0;for(let o=0;o<e.length;o++){let a=e[o],s=e[(o+1)%e.length],i=a[0]*s[1]-a[1]*s[0];i>1e-12?t=!0:i<-1e-12&&(r=!0);let c=s[0]-a[0],l=s[1]-a[1],u=c*c+l*l,m=u>1e-18?Math.max(0,Math.min(1,-(a[0]*c+a[1]*l)/u)):0;n=Math.min(n,Math.hypot(a[0]+m*c,a[1]+m*l))}return t!==r?0:n}var Li=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Au=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],$K=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],_R=e=>Math.sqrt(Au(e,e)),sL=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],_f=e=>sL(e,1/(_R(e)||1));function iL(e,t,r){if(!e.bands){let n=e.tree.tri,o=new Float64Array(n.length);for(let a=0;a+2<n.length;a+=3){let s=Gt(t,[n[a],n[a+1],n[a+2]]);o[a]=s[0],o[a+1]=s[1],o[a+2]=s[2]}e.bands=OK(o,r)}return e.bands}var dL=25,ht=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Tr=e=>Math.hypot(e[0],e[1],e[2]),yr=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r],$R={lowerArm:"lowerArm",upperArm:"upperArm",upright:"upright"},GK=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Wa=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],wu=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],jr=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Nf=e=>jr(e,1/(Tr(e)||1)),KK={"upper wishbone, front leg":{tube:"upperArm",joints:["ballJoint","ballJoint"]},"upper wishbone, rear leg":{tube:"upperArm",joints:["ballJoint","ballJoint"]},"lower wishbone, front leg":{tube:"lowerArm",joints:["ballJoint","ballJoint"]},"lower wishbone, rear leg":{tube:"lowerArm",joints:["ballJoint","ballJoint"]},"tie rod":{tube:"tieRod",joints:["rodEnd","rodEnd"]},pushrod:{tube:"rod",joints:["rodEnd","rodEnd"]},strut:{tube:"strut",joints:["ballJoint","ballJoint"]}},HK=(e,t)=>e.axles?.[t[0]==="F"?"front":"rear"]??null;function zK(e,t){let r=Nf(e.spinAxis),n=ht(e.uprightUpper,e.uprightLower),o=Nf(ht(n,jr(r,Wa(n,r)))),a=GK(r,o);a[0]<0&&(a=jr(a,-1));let s=t.discDiameter/2+t.caliperHeight,i=Math.max(0,Math.min(t.discDiameter/2,2*t.effRadius-t.discDiameter/2)),c=t.caliperAngle*Math.PI/180,l=Math.min(Math.PI/2,t.caliperLength/2/Math.max(1,s)),u=(p,d,f)=>wu(wu(e.wheelCenter,jr(r,f)),wu(jr(o,d*Math.cos(p)),jr(a,d*Math.sin(p)))),m=[];for(let p of[t.discOffset-t.caliperWidth/2,t.discOffset+t.caliperWidth/2]){for(let d of[-1,-.5,0,.5,1])m.push(u(c+d*l,s,p));for(let d of[-1,1])m.push(u(c+d*l,i,p))}return m}function YK(e,t){let r=[];return e.mcpherson||r.push(e.uprightUpper),r.push(e.uprightLower,e.tieOuter),(e.mcpherson||t==="upright")&&r.push(e.pushrodOuter),r.filter(n=>n.every(Number.isFinite))}function pL(e,t,r,n,o){let a=[],s=HK(n,t),i=jK(s,e,t,r),c=!!s?.rackHousing&&t[0]==="F";for(let f of MR(e)){if(f.body==="upperArm"&&i.has("upperArm")||f.body==="lowerArm"&&i.has("lowerArm"))continue;let h=e[f.inboard],b=e[f.outboard];if(![...h,...b].every(Number.isFinite))continue;let g=[c&&f.name==="tie rod"?"rack":f.ends[0],f.ends[1]==="rodAttach"?$R[r]:f.ends[1]],y=KK[f.name],x=!s||!y?n.linkRadius:y.tube==="strut"?s.strut:s.tube[y.tube],R=s&&y?[s.housing[y.joints[0]],s.housing[y.joints[1]]]:[n.jointAllowance,n.jointAllowance];a.push({kind:"link",id:`${t} ${f.name}`,name:f.name,corner:t,body:f.body,ends:g,a:h,b,radius:x,housing:R})}let l=s?.damper;if(l&&!e.decoupled&&!e.mcpherson){let f=e.damperChassis,h=e.direct?e.pushrodOuter:e.rockerToDamper,b=e.direct?$R[r]:"rocker";if([...f,...h].every(Number.isFinite)){let g=YP(`${t} damper`,"damper","damper",t,{p:f,body:"chassis",corner:t},{p:h,body:b,corner:t},l,s.housing.rodEnd);a.push(...i.has("damperBody")?g.filter(y=>y.id!==`${t} damper body`):g)}}s?.arb&&o&&a.push(...KP(s.arb,o.def,o.r,t,s)),s?.rackHousing&&t[0]==="F"&&a.push(HP(s.rackHousing,t));let u=s?.driveshaft?zP(s.driveshaft,e,t):null;u&&a.push(u);let m={centre:e.wheelCenter,axis:Nf(e.spinAxis)},p=t[0]==="F"?n.tyreRadius.front:n.tyreRadius.rear;a.push({kind:"tyre",id:`${t} tyre`,name:"tyre",corner:t,body:"wheel",centre:e.wheelCenter,axis:e.spinAxis,radius:p,width:n.tyreWidth,section:s?.rim?UP(s.rim,p,n.tyreWidth):null});let d=i.get("wheel");if(d?a.push({kind:"rim",id:`${t} rim`,name:"rim",corner:t,body:"wheel",frame:m,bands:iL(d.live,d.fit.iso,m),model:!0}):s?.rim&&a.push({kind:"rim",id:`${t} rim`,name:"rim",corner:t,body:"wheel",frame:m,bands:XP(s.rim)}),s){let f=YK(e,r);f.length&&!i.has("upright")&&a.push({kind:"hull",id:`${t} upright`,name:"upright",corner:t,body:"upright",points:f,radius:s.uprightWall}),s.brake&&a.push({kind:"hull",id:`${t} caliper`,name:"caliper",corner:t,body:"upright",points:zK(e,s.brake),radius:0})}for(let[f,h]of i)f!=="wheel"&&a.push(qK(f,h.live,h.fit,e,t,r,n,s));return a}var WK={upright:"upright",upperArm:"upperArm",lowerArm:"lowerArm",rocker:"rocker",damperBody:"damper"};function jK(e,t,r,n){let o=new Map;if(!e?.models)return o;for(let a of NR){let s=e.models[a];if(!s)continue;let i=oL(s,a,t,r,n);aL(i)&&o.set(a,{live:s,fit:i})}return o}var UK=["ucaFront","ucaRear","lcaFront","lcaRear","uprightUpper","uprightLower"];function XK(e,t,r,n){switch(t){case"uprightUpper":return e==="upright"?"upperArm":"upright";case"uprightLower":return e==="upright"?"lowerArm":"upright";case"tieOuter":return"tieRod";case"pushrodOuter":return e==="damperBody"?$R[n]:r.mcpherson?"strut":"rod";case"rockerToPushrod":return"rod";case"rockerToDamper":return e==="rocker"?"damper":"rocker";default:return"chassis"}}function qK(e,t,r,n,o,a,s,i){let c=VR(n,e,a).map(l=>({key:l,p:n[l],on:XK(e,l,n,a),reach:i?i.housing[UK.includes(l)?"ballJoint":"rodEnd"]:s.jointAllowance}));return{kind:"model",id:`${o} ${OR[e]} model`,name:`${OR[e]} model`,corner:o,body:WK[e],piece:e,tree:t.tree,iso:r.iso,inverse:OP(r.iso),ends:[...new Set(c.map(l=>l.on))],joints:c}}function QK(e,t,r){let n=e.ends[t];if(n==="chassis")return!1;let o=e.endCorners?.[t]??e.corner;return r.body===n&&r.corner===o||r.ends.some((a,s)=>a===n&&(r.endCorners?.[s]??r.corner)===o)}var cL=(e,t)=>(e.body==="rod"||e.body==="dropLink")&&e.ends[1]===t.body&&(e.endCorners?.[1]??e.corner)===t.corner,lL=(e,t)=>e.body==="damper"&&e.ends[1]===t.body;function KR(e,t,r){return e.find(({parts:[n,o]})=>n===t.name&&o===r.name||n===r.name&&o===t.name)}function fL(e,t,r=[]){let n=[],o=(m,p,d,f,h=!1)=>{let b=f?void 0:KR(r,m,p);n.push({a:m,b:p,name:`${m.name} / ${p.name}`,trim:d,skip:b?"ignored":f,...b?{reason:b.reason}:{},...h?{fixed:h}:{}})},a=e.filter(m=>m.kind==="link");for(let m=0;m<a.length;m++)for(let p=m+1;p<a.length;p++){let d=ZK(a[m],a[p],r);d&&n.push(d)}let s=e.find(m=>m.kind==="tyre"&&m.section!==null),i=e.find(m=>m.kind==="rim");for(let m of a)s&&o(m,s,[0,0,0,0],null),i&&o(m,i,[0,0,0,0],null);let c=e.filter(m=>m.kind==="hull");for(let m of c)i&&o(m,i,[0,0,0,0],null,!0);let l=c.find(m=>m.name==="caliper");if(l)for(let m of a)o(m,l,[m.ends[0]==="upright"?m.housing[0]:0,m.ends[1]==="upright"?m.housing[1]:0,0,0],null);let u=e.filter(m=>m.kind==="model");for(let m=0;m<u.length;m++){let p=u[m];for(let d of a){let f=JK(p,d,r);f&&n.push(f)}s&&p.body!=="upright"&&o(p,s,[0,0,0,0],null),i&&o(p,i,[0,0,0,0],null,p.body==="upright"),l&&p.body!=="upright"&&o(p,l,[0,0,0,0],null);for(let d=m+1;d<u.length;d++)o(p,u[d],[0,0,0,0],null)}for(let m of t)for(let p of e)p.kind==="tyre"||p.kind==="model"||p.kind==="link"&&!p.shared?o(m,p,[0,0,0,0],null):p.kind==="link"&&p.corner[1]==="L"&&m.kind==="volume"&&o(m,p,[0,0,0,0],null,!0);return n}function ZK(e,t,r=[]){if(e.body===t.body&&e.corner===t.corner)return null;let n=(i,c,l)=>QK(i,c,l)?i.housing[c]:0,o=[n(e,0,t),n(e,1,t),n(t,0,e),n(t,1,e)],a=cL(e,t)||cL(t,e)?"rod on arm":lL(e,t)||lL(t,e)?"damper on arm":null,s=a?void 0:KR(r,e,t);return{a:e,b:t,name:`${e.name} / ${t.name}`,trim:o,skip:s?"ignored":a,...s?{reason:s.reason}:{},...e.shared&&t.shared?{fixed:!0}:{}}}function JK(e,t,r=[]){if(t.body===e.body&&t.corner===e.corner)return null;let n=i=>{let c=t.ends[i];return c==="chassis"?0:(t.endCorners?.[i]??t.corner)===e.corner&&(c===e.body||e.ends.includes(c))?t.housing[i]:0},a=(t.body==="rod"||t.body==="dropLink")&&t.ends[1]===e.body&&(t.endCorners?.[1]??t.corner)===e.corner?"rod on arm":t.body==="damper"&&t.ends[1]===e.body?"damper on arm":null,s=a?void 0:KR(r,e,t);return{a:e,b:t,name:`${e.name} / ${t.name}`,trim:[0,0,n(0),n(1)],skip:s?"ignored":a,...s?{reason:s.reason}:{}}}function Fu(e,t,r,n){let o=Tr(ht(t,e));if(o<=r+n){let a=yr(e,t,.5);return[a,a]}return[yr(e,t,r/o),yr(e,t,1-n/o)]}function kn(e,t,r){let n=ht(t,e),o=Tr(n);return o>1e-9?yr(e,t,r/o):e}function uL(e,t,r,n){let o=ht(r,t),a=Tr(o),s=a>1e-12?jr(o,1/a):[1,0,0],i=Wa(ht(e,t),s),c=ht(ht(e,t),jr(s,i)),l=Tr(c),u=Math.max(0,Math.min(a,i)),m=l>n?jr(c,n/l):c,p=wu(wu(t,jr(s,u)),m);return{distance:Tr(ht(e,p)),on:p}}function hL(e,t,r,n){let o=ht(t,e),a=ht(n,r),s=ht(e,r),i=Wa(o,o),c=Wa(a,a),l=Wa(a,s),u=b=>Math.max(0,Math.min(1,b));if(i<=1e-12&&c<=1e-12)return{s:0,t:0};if(i<=1e-12)return{s:0,t:u(l/c)};let m=Wa(o,s);if(c<=1e-12)return{s:u(-m/i),t:0};let p=Wa(o,a),d=i*c-p*p,f=d>1e-12?u((p*l-m*c)/d):0,h=(p*f+l)/c;return h<0?(h=0,f=u(-m/i)):h>1&&(h=1,f=u((p-m)/i)),{s:f,t:h}}function eH(e,t,r,n,o){let{s:a,t:s}=hL(r,n,e,t);if(a>1e-9&&a<1-1e-9){let p=yr(r,n,a),d=yr(e,t,s),f=Tr(ht(d,p));if(f>=o)return{distance:f-o,onSeg:d,onCyl:kn(p,d,o)}}let i=p=>uL(yr(e,t,p),r,n,o).distance,l=[0,Tr(ht(t,e))<1e-12?0:BP(i,0,1,1e-7).x,1].reduce((p,d)=>i(d)<i(p)?d:p),u=yr(e,t,l),m=uL(u,r,n,o);return{distance:m.distance,onSeg:u,onCyl:m.on}}function GR(e,t,r){let n=ht(r,t),o=Tr(n);return!e.flat||o<1e-9?{shape:kR(t,r),pad:e.radius}:{shape:wi(yr(t,r,.5),jr(n,1/o),e.radius,o),pad:0}}function mL(e,t,r){let n=GR(e.part,e.p0,e.p1),o="part"in t?GR(t.part,t.p0,t.p1):t,a="part"in t?t.part.radius:t.radius,s=n.pad+o.pad;if(Sf(n.shape,o.shape)-s>=r)return null;let i=-(e.part.radius+a);if("part"in t&&e.part.flat!==t.part.flat){let[l,u]=e.part.flat?[t,e]:[e,t],m=eH(l.p0,l.p1,u.p0,u.p1,u.part.radius),[p,d]=e.part.flat?[m.onCyl,m.onSeg]:[m.onSeg,m.onCyl];if(m.distance<=1e-9)return{distance:i,onA:p,onB:d};let f=l.part.radius;return e.part.flat?{distance:m.distance-f,onA:p,onB:kn(d,p,f)}:{distance:m.distance-f,onA:kn(p,d,f),onB:d}}if("part"in t&&e.part.flat&&t.part.flat){let{s:l,t:u}=hL(e.p0,e.p1,t.p0,t.p1),m=p=>p>1e-9&&p<1-1e-9;if(m(l)&&m(u)){let p=yr(e.p0,e.p1,l),d=yr(t.p0,t.p1,u),f=Tr(ht(d,p));if(f>=e.part.radius+t.part.radius)return{distance:f-e.part.radius-t.part.radius,onA:kn(p,d,e.part.radius),onB:kn(d,p,t.part.radius)}}}let c=Fi(n.shape,o.shape,e.part.flat||"part"in t&&t.part.flat?1e-6:1e-9);return c.distance<=0?{distance:i,onA:c.onA,onB:c.onB}:{distance:c.distance-s,onA:kn(c.onA,c.onB,n.pad),onB:kn(c.onB,c.onA,o.pad)}}var tH=["chassis","rack"];function rH(e,t,r,n){let o,a=!1;if(t.kind==="link"){let i=[0,0];for(let m of[0,1])tH.includes(t.ends[m])&&LR(e.tree,m===0?t.a:t.b,r.mountAllowance)&&(i[m]=t.housing[m],a=!0);let[c,l]=Fu(t.a,t.b,i[0],i[1]),u=Tr(ht(l,c));if(!t.flat||u<1e-9){let m=Su(e.tree,c,l,n+t.radius);o=m&&{...m,distance:m.distance-t.radius,onPart:m.distance>1e-9?kn(m.onPart,m.onMesh,t.radius):m.onPart}}else o=If(e.tree,yr(c,l,.5),ht(l,c),t.radius,u,Math.max(0,n))}else o=If(e.tree,t.centre,t.axis,t.radius,t.width,Math.max(0,n));if(!o)return null;let s=o.distance<=0;return{distance:s?0:o.distance,onA:o.onMesh,onB:s?o.onMesh:o.onPart,...s?{touches:!0}:{},...a?{mounted:!0}:{}}}function bL(e,t,r=1/0){let{a:n,b:o}=e;if(n.kind==="model"||o.kind==="model")return oH(e,t,r);if(n.kind==="mesh"&&(o.kind==="link"||o.kind==="tyre"))return rH(n,o,t,r);if(n.kind==="link"&&o.kind==="link"){let[a,s]=Fu(n.a,n.b,e.trim[0],e.trim[1]),[i,c]=Fu(o.a,o.b,e.trim[2],e.trim[3]);return mL({part:n,p0:a,p1:s},{part:o,p0:i,p1:c},r)}if(n.kind==="volume"&&(o.kind==="link"||o.kind==="tyre")){let a=vR(n.box.min,n.box.max),s=o.kind==="link"?GR(o,o.a,o.b):null,i=s?s.shape:wi(o.centre,o.axis,o.radius,o.width),c=s?s.pad:0,l=Sf(a,i);if(l>0&&l-c>=r)return null;let u=SR(a,i,c);return{distance:u.distance,onA:u.gap.box,onB:u.gap.part}}if(n.kind==="link"&&(o.kind==="rim"||o.kind==="tyre"&&o.section)){let a=o.kind==="rim"?o.bands:o.section,s=o.kind==="rim"?o.frame:{centre:o.centre,axis:o.axis},i=QP(n.a,n.b,n.radius,a,s);return{distance:i.distance,onA:i.onPart,onB:i.onWheel}}if(n.kind==="hull"&&o.kind==="rim"){let a=ZP(n.points,n.radius,o.bands,o.frame);return{distance:a.distance,onA:a.onPart,onB:a.onWheel}}if(n.kind==="link"&&o.kind==="hull"){let[a,s]=Fu(n.a,n.b,e.trim[0],e.trim[1]);return mL({part:n,p0:a,p1:s},{shape:Ha(o.points),pad:o.radius,radius:o.radius},r)}return null}function Ya(e,t,r,n=!1){let o=e<=0;return{distance:o?0:e,onA:t,onB:o?t:r,...o?{touches:!0}:{},...n?{mounted:!0}:{}}}var nH=(e,t)=>e.joints.filter(r=>t.joints.some(n=>n.key===r.key)).map(r=>({c:r.p,r:2*r.reach})),BR=(e,t)=>t.map(r=>({c:Gt(e.inverse,r.c),r:r.r}));function oH(e,t,r){let{a:n,b:o}=e,a=(s,i)=>Gt(s.iso,i);if(n.kind==="model"&&o.kind==="link"){let[s,i]=Fu(o.a,o.b,e.trim[2],e.trim[3]),c=BR(n,[0,1].filter(d=>e.trim[2+d]>0).map(d=>({c:d===0?o.a:o.b,r:e.trim[2+d]+o.radius}))),l=Gt(n.inverse,s),u=Gt(n.inverse,i),m=Tr(ht(u,l));if(!o.flat||m<1e-9){let d=Su(n.tree,l,u,r+o.radius,c);if(!d)return null;let f=d.distance>1e-9?kn(d.onPart,d.onMesh,o.radius):d.onPart;return Ya(d.distance-o.radius,a(n,d.onMesh),a(n,f))}let p=If(n.tree,yr(l,u,.5),ht(u,l),o.radius,m,Math.max(0,r),c);return p&&Ya(p.distance,a(n,p.onMesh),a(n,p.onPart))}if(n.kind==="model"&&o.kind==="model"){let s=ER(n.tree,o.tree,Ru(n.inverse,o.iso),Math.max(0,r),BR(n,nH(n,o)));return s&&Ya(s.distance,a(n,s.onA),a(n,s.onB))}if(n.kind==="model"&&(o.kind==="rim"||o.kind==="tyre"&&o.section)){let s=o.kind==="rim"?o.bands:o.section,i=o.kind==="rim"?o.frame:{centre:o.centre,axis:o.axis},c={centre:Gt(n.inverse,i.centre),axis:Af(n.inverse,Nf(i.axis))},l=nL(n.tree,c,s,Math.max(0,r));return l&&Ya(l.distance,a(n,l.onMesh),a(n,l.onPart))}if(n.kind==="model"&&o.kind==="hull"){let s=BR(n,n.joints.filter(l=>l.on==="upright").map(l=>({c:l.p,r:l.reach}))),i=DR(n.tree,Ha(o.points.map(l=>Gt(n.inverse,l))),r+o.radius,s);if(!i)return null;let c=i.distance>1e-9?kn(i.onPart,i.onMesh,o.radius):i.onPart;return Ya(i.distance-o.radius,a(n,i.onMesh),a(n,c))}if(n.kind==="volume"&&o.kind==="model"){let{min:s,max:i}=n.box,c=[];for(let u=0;u<8;u++)c.push(Gt(o.inverse,[u&1?i[0]:s[0],u&2?i[1]:s[1],u&4?i[2]:s[2]]));let l=DR(o.tree,Ha(c),Math.max(0,r));return l&&Ya(l.distance,a(o,l.onPart),a(o,l.onMesh))}if(n.kind==="mesh"&&o.kind==="model"){let s=o.joints.filter(l=>l.on==="chassis"),i=s.some(l=>LR(n.tree,l.p,t.mountAllowance)),c=ER(n.tree,o.tree,o.iso,Math.max(0,r),s.map(l=>({c:l.p,r:2*l.reach})));return c&&Ya(c.distance,c.onA,c.onB,i)}return null}var xL=152,RL={travelSteps:9,rackSteps:5};function sH(e){let t=(r,n)=>{let o=Sr(n,e.kc,r),a=e.kc?.input.corners[r];return a&&a.tyreRate>0&&Number.isFinite(a.tyreRate)?o+Math.max(0,a.staticLoad)/a.tyreRate:o};return{front:t("FL",e.vehicle.front.config.loadedRadius),rear:t("RL",e.vehicle.rear.config.loadedRadius)}}function HR(e,t){let r=Xm(t);return{...TP,tyreRadius:sH(e),tyreWidth:r!==null?r*1e3:xL}}var gL={front:["FL","FR"],rear:["RL","RR"]},iH=e=>e.a.kind!=="volume"&&e.a.kind!=="mesh"&&(e.b.kind==="tyre"||e.b.kind==="rim"||e.b.kind==="hull");function cH(e,t,r,n,o){let a=null,s=(i,c)=>{for(let l of fL(pL(i,r,n,o),[])){if(l.skip||!iH(l)||!!l.fixed!==c)continue;let u=bL(l,o,a?.distance??1/0);u&&(!a||u.distance<a.distance)&&(a={distance:u.distance,pair:l.name})}};s(e,!0);for(let i of t)s(i,!1);return a}var yL=(e,t,r)=>r<=1||t===e?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function zR(e,t,r,n,o=RL,a={}){let s=e.vehicle,[i]=gL[t],c=Nd(e,i,0,0)?.geometry;if(!c)return null;let l=Mf(s.chassis?.boxes??[],{vehicle:s,kc:e.kc}),u=t==="front"?Ot(s.front.config):0,m=u>0?yL(-u,u,Math.max(3,o.rackSteps|1)):[0],p=yL(Math.min(0,r.min),Math.max(0,r.max),Math.max(2,o.travelSteps)),d=[];for(let R of l.length?gL[t]:[i])for(let v of p)for(let S of m){let A=Nd(e,R,v,S)?.geometry;A&&d.push({corner:R,travel:v,rack:S,g:A})}let f=null;if(l.length){for(let R of IP(l,d,HR(e,n)))for(let v of[R.tyre,R.link])v&&(!f||v.distance<f.distance)&&(f={distance:v.distance,part:v.part,boxId:R.boxId});f??={distance:NaN,part:"",boxId:""}}let h=s[t].config,b=d.filter(R=>R.corner===i).map(R=>R.g),g=kf(c,b,h.pushrodAttach,h.rodType==="pull"?"pullrod":"pushrod"),y=kP({...HR(e,n),jointAllowance:dL},s,{...a,tyres:{front:n,rear:n}}),x=y.axles[t].rim?cH(c,b,i,h.pushrodAttach,y):null;return{chassis:f,wheel:x,...g}}var ja=Math.PI/180,Di={travelSteps:9,heaveSteps:5,rollSteps:4,rackSteps:6},Cu={travelMin:-25,travelMax:25,rollMaxDeg:3,rollAtLimitDeg:2.5};function lH(e){let t=e.params,r=t.cg_height?Ut({...t,surveyedRadiusFront:e.vehicle.front.config.loadedRadius,surveyedRadiusRear:e.vehicle.rear.config.loadedRadius}):null;return{cgHeight:r?r.cgHeight:300,...s0(t),drive:md(t),...r?{frontMassFrac:r.frontMassFrac}:{}}}function YR(e,t){for(let r=1;r<e.length;r++){let n=3*t(r)+10;for(let o of["cpLeft","cpRight"]){let a=e[r-1][o],s=e[r][o];if(a&&s&&Math.hypot(s[0]-a[0],s[1]-a[1])>n)return r}}return-1}function WR(e,t=Di,r=Cu,n){let o=null,a=(D,I)=>(o||(o={violation:D,reason:I}),null),s=e.vehicle,i=D=>D==="front"?s.front:s.rear,c=null,l=null,u=()=>{if(c)return c;if(n)try{let D=n();if(D)return c=hr(s,D.kc),l=D.cgHeight,c}catch{a(500,"the car could not be stood on its tyre: its rates did not assemble")}return c=hr(s)},m=D=>D==="front"?"FL":"RL",p=D=>{let I=u();if(!I.kc)return;let N=i(D).config.loadedRadius,O=Sr(N,I.kc,m(D));return O===N?void 0:{loadedRadius:O}},d=(D,I)=>-bc(u(),m(D),I),f=new Map,h=new Map,b=new Map,g=new Map,y=new Map,x=new Map,R,v=new Map,S=new Map,A=new Map,F=new Map,w=new Map,T=null,M=()=>{if(T)return T;u();let D=lH(e);return T=l!==null&&Number.isFinite(l)?{...D,cgHeight:l}:D},k,C=()=>{let D=hR(r.travelMin,r.travelMax,s.config.wheelbase),I=2*Math.max(2,t.rollSteps)-1;return Array.from({length:I},(N,O)=>-D+2*D*O/(I-1))},P,L=()=>{if(P!==void 0)return P;let D=Cm(u().ctx.FL,Ot(s.front.config));return P=D?Tm(D):null,P},E=(D,I,N)=>{if(D.has(I))return D.get(I)??null;let O=N();return D.set(I,O),O};return{car:e,density:t,envelope:r,get failure(){return o},axisLength:(D,I)=>{let N=i(D),O=N.hardpoints;return I==="uca"&&N.config.layout==="mcpherson"?NaN:I==="uca"?Le(O.ucaFront,O.ucaRear):Le(O.lcaFront,O.lcaRear)},linkLength:D=>{let I=i(D).hardpoints;return Le(I.tieInner,I.tieOuter)},compliance:D=>E(h,D,()=>cg(i(D))??null),sweep:D=>E(f,D,()=>{let I;try{I=ut(i(D),{travelMin:r.travelMin,travelMax:r.travelMax,steps:t.travelSteps})}catch{return a(500,`the ${D} travel sweep threw`)}if(!I.covered){let O=I.samples.map(U=>U.travel),V=Math.max(...O)-Math.min(...O),H=r.travelMax-r.travelMin;return a(Math.max(0,H-V),`the ${D} linkage reaches only ${V.toFixed(0)} mm of the ${H.toFixed(0)} mm travel range`)}if(I.fold)return a(200,`the ${D} travel(beta) folds \u2014 the suspension goes over centre in range`);let N=I.samples.filter(O=>!O.converged).length;if(N>0)return a(100+10*N,`${N} of ${I.samples.length} ${D} travel solves did not converge`);if(D==="front"&&i("front").config.steerMode==="rack"){let O=L();if(O)return a(O.violation,O.reason)}return I}),rcHeave:D=>E(b,D,()=>{let I=[],N=[],O=Math.max(2,t.heaveSteps);try{for(let H=0;H<O;H++){let U=r.travelMin+(r.travelMax-r.travelMin)*H/(O-1);I.push(U),N.push(Hr(u(),{heave:d(D,U),pitch:0,roll:0,steer:0},D))}}catch{return a(500,`the ${D} roll-centre construction threw in heave`)}let V=YR(N,H=>Math.abs(I[H]-I[H-1]));return V>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[V].toFixed(0)} mm of travel`):{at:I,rc:N}}),rcRoll:D=>E(g,D,()=>{let I=[],N=[],O=Math.max(2,t.rollSteps);try{for(let H=0;H<O;H++){let U=r.rollMaxDeg*H/(O-1);I.push(U),N.push(Hr(u(),{heave:0,pitch:0,roll:U*ja,steer:0},D))}}catch{return a(500,`the ${D} roll-centre construction threw in roll`)}let V=YR(N,H=>Math.abs(N[H].cpLeft?.[0]??0)*Math.abs(I[H]-I[H-1])*ja);return V>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[V].toFixed(1)}\xB0 of roll`):{at:I,rc:N}}),rcPitch:D=>E(y,D,()=>{let I=C(),N=[];try{for(let V of I)N.push(Hr(u(),{heave:0,pitch:-V*ja,roll:0,steer:0},D))}catch{return a(500,`the ${D} roll-centre construction threw in pitch`)}let O=YR(N,V=>Math.abs(I[V]-I[V-1])*ja*s.config.wheelbase);return O>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[O].toFixed(2)}\xB0 of pitch`):{at:I,rc:N}}),pcHeave:()=>E(x,"heave",()=>{let D=[],I=[],N=Math.max(2,t.heaveSteps);try{for(let O=0;O<N;O++){let V=r.travelMin+(r.travelMax-r.travelMin)*O/(N-1);D.push(V);let H={heave:d("front",V),pitch:0,roll:0,steer:0},U={heave:d("rear",V),pitch:0,roll:0,steer:0},G=u();I.push({left:no(Dt(G,"FL",H),Dt(G,"RL",U)),right:no(Dt(G,"FR",H),Dt(G,"RR",U))})}}catch{return a(500,"the pitch-centre construction threw in heave")}return{at:D,pc:I}}),pcPitch:()=>E(x,"pitch",()=>{let D=C(),I=[];try{for(let N of D){let O={heave:0,pitch:-N*ja,roll:0,steer:0},V=u();I.push({left:no(Dt(V,"FL",O),Dt(V,"RL",O)),right:no(Dt(V,"FR",O),Dt(V,"RR",O))})}}catch{return a(500,"the pitch-centre construction threw in pitch")}return{at:D,pc:I}}),cg:()=>{if(R!==void 0)return R;let D=M();if(D.frontMassFrac===void 0||!Number.isFinite(D.frontMassFrac))return R=null;let I=s.config,N=yf({wheelbase:I.wheelbase,frontAxleX:I.frontAxleX,frontMassFrac:D.frontMassFrac,cgHeight:D.cgHeight});return R={...N,z:Yr(D.cgHeight,N.x,u())}},roadUnder:D=>{let I=v.get(D);return I===void 0&&(I=Yr(0,Ue(m(D),s.config).axleX,u()),v.set(D,I)),I},steer:()=>{if(k!==void 0)return k;try{k=Hb(u(),{steerMax:Ot(s.front.config),steps:t.rackSteps})}catch{k=a(500,"the steering sweep threw")}let D=k?.filter(I=>!I.converged).length??0;if(k&&D>0){let I=L();k=I?a(I.violation,I.reason):a(100+10*D,`${D} of ${k.length} steering solves did not converge`)}return k??null},solveAt:(D,I,N=0)=>E(S,`${D}:${I}:${N}`,()=>{try{let O=Ce(u().ctx[m(D)],I,N,void 0,p(D));return O.ok?O.state:O.why==="unconverged"?a(100,`the ${D} corner did not solve at ${I.toFixed(0)} mm of travel`):a(100+Math.abs(O.travelMiss),`the ${D} corner reaches only ${(I+O.travelMiss).toFixed(0)} of ${I.toFixed(0)} mm of travel`)}catch{return a(150,`the ${D} corner solve threw at ${I.toFixed(0)} mm of travel`)}}),readout:D=>E(F,`${D.heave}:${D.pitch}:${D.roll}:${D.steer}`,()=>{try{return bR(u(),D,M())}catch{return a(500,"the derived readout threw")}}),readoutAtTravel:(D,I)=>E(w,`${D}:${I}`,()=>{try{return gu(u(),{heave:d(D,I),pitch:0,roll:0,steer:0},D,M())}catch{return a(500,`the ${D} readout threw at ${I.toFixed(0)} mm of travel`)}}),travelAtRoll:(D,I)=>{let N=i(D).hardpoints.wheelCenter[1]*Math.sin(I*ja),O=u();if(!O.kc)return N;try{let V=Zt(O,{heave:0,pitch:0,roll:I*ja,steer:0}),H=D==="front"?Math.max(V.FL.travel,V.FR.travel):Math.max(V.RL.travel,V.RR.travel);return Number.isFinite(H)?H:N}catch{return a(500,`the ${D} axle could not be rolled on its tyre`),N}},onTyre:()=>!!u().kc,contexts:u,keepOuts:D=>E(A,D,()=>{try{let I=e.params,N=D==="front"?I.tireModel:I.tireModelRear??I.tireModel,O={min:r.travelMin,max:r.travelMax},V={brakes:I.brakeModel,dampers:{front:I.damperModel,rear:I.damperModelRear??I.damperModel},drive:vP(md(I))};return zR(u(),D,O,N,void 0,V)??a(100,`the ${D} corner did not solve at its design ride`)}catch{return a(500,`the ${D} keep-outs threw`)}})}}var uH=ax();function jR(e,t={}){let r=new Map;return{session(n){if(r.has(n))return r.get(n);let o=null,a=t.session?.();if(t.sessionParams&&a)try{let s=Ep(n,a.rulesets),i=s?.events.some(c=>c.kind==="trackLap");if(s&&(a.track||!i)){let c=t.sessionParams(e),{standingStart:l,lapCounts:u}=a.settings,m=a.track?Jl([c],a.track,a.numerics,Ul(s),a.settings,uH)[0]:Bl(c,s,{numerics:a.numerics,standingStart:l,lapCounts:u});o={};for(let p of s.metrics)Xu(p)&&(o[p.key]=p.value(m,void 0))}}catch{o=null}return r.set(n,o),o}}}var Of=.01;function mH(e,t){return t.bump!==null&&e>t.bump-Of?{at:"closed",past:Math.max(0,e-t.bump)}:t.droopStated&&e<t.droop+Of?{at:"toppedOut",past:Math.max(0,t.droop-e)}:t.seat!==null&&e<t.seat+Of?{at:"unseated",past:Math.max(0,t.seat-e)}:{at:"free",past:0}}var vL=e=>({droop:e.droop,droopStated:e.droopStated,bump:e.bump,seat:e.holdsLoad&&Number.isFinite(e.free)?e.free:null}),dH=[["front","FL","FR"],["rear","RL","RR"]];function XR(e,t){let r=[];for(let[n,o,a]of dH){let s=[t[o],t[a]];for(let m of[o,a]){let p=e.curve[m],d=p.spring?.law;if(!p.spring||!d)continue;let f=Sb(p,t[m]);f===null||!Number.isFinite(f)||r.push(UR(m,n,n,f,p.spring.length0-f,vL(d),!0))}let i=e.elements?.[n];if(!i)continue;let c=i.heave?.law;if(c){let m=qk(i,s),p=i.read.heave?.span0,d=n==="front"?"heaveFront":"heaveRear";r.push(UR(d,d,n,m,p!==void 0?p-m:null,vL(c),i.carriesLoad))}let l=i.rollStop,u=l?Qk(i,s):null;if(l&&u!==null){let m=l.length0-u,p=n==="front"?"rollFront":"rollRear",d={droop:l.droop??-1/0,droopStated:l.droop!==null,bump:l.bump,seat:null};r.push(UR(p,p,n,m,u,d,i.carriesLoad))}}return r}function UR(e,t,r,n,o,a,s){return{damper:e,place:t,axle:r,length:o,compression:n,toToppedOut:a.droopStated?n-a.droop:null,toClosed:a.bump!==null?a.bump-n:null,...mH(n,a),bumpStated:a.bump!==null,bounds:s}}var SL=Math.PI/180;function qR(e,t,r,n){let o=t.speedKmh/3.6,a=sb(e,o,t.axG,ho(e,t.ayG,0));if(!a||!e.aero)return null;let s=e.wheelbase,i=ys(e.aero,s),c=(h,b)=>Math.atan((b-h)/s)/SL,l={},u={};for(let h of en)l[h]=r.corners[h].travel,u[h]=r.corners[h].ground;let m=n.kc?XR(n.kc,l):[],p=e.aero.model,d=a.downFront+a.downRear,f=p?{balance:Math.abs(d)>1e-9?100*a.downFront/d:NaN,clA:(a.clFront+a.clRear)*a.area,cdA:a.cd*a.area,loopMargin:1-a.gain,dataMargin:AL(p,s,a.hFront,a.hRear)}:null;return{front:{height:a.hFront,...kL(m,"front")},rear:{height:a.hRear,...kL(m,"rear")},rakeDeg:c(a.hFront,a.hRear),pitchDeg:c(a.hFront,a.hRear)-c(i.hFront,i.hRear),rollDeg:Math.abs(r.rollDeg),aero:f,clearance:pH(n,u)}}function kL(e,t){let r=e.filter(o=>o.axle===t&&o.bounds),n=o=>{let a=o.filter(s=>s!==null&&Number.isFinite(s));return a.length?Math.min(...a):null};return{toBump:n(r.map(o=>o.toClosed)),toDroop:n(r.map(o=>o.toToppedOut))}}function AL(e,t,r,n){let o=(a,[s,i])=>Math.min(a-s,i-a);if(zv(e)){let{x:a,y:s}=fs(e),i=[a[0],a[a.length-1]],c=[s[0],s[s.length-1]];return po(e)?ML(e.frame,t,i,c,r,n):Math.min(o(r,i),o(n,c))}return em(e)?ML(e.frame,t,e.range.h,e.range.pitch,r,n):Math.min(o(r,e.range.hFront),o(n,e.range.hRear))}function ML(e,t,r,n,o,a){let s=hs(e,t,o,a),i=l=>t*Math.tan(l*SL),c=a-o;return Math.min(s.h-r[0],r[1]-s.h,c-i(n[0]),i(n[1])-c)}function pH(e,t){let r=e.vehicle.chassis?.boxes;if(!r?.length)return null;let n={vehicle:e.vehicle,kc:e.kc},o=e.vehicle.config,a=o.frontAxleX,s=o.frontAxleX-o.wheelbase,i=cr(e.vehicle,!0)/2,c=cr(e.vehicle,!1)/2,l={FL:[a,-i],FR:[a,i],RL:[s,-c],RR:[s,c]},u=[[0,0,0],[0,0,0],[0,0,0]],m=[0,0,0];for(let b of en){let g=[1,l[b][0],l[b][1]];for(let y=0;y<3;y++){m[y]+=g[y]*t[b];for(let x=0;x<3;x++)u[y][x]+=g[y]*g[x]}}let p=EP(u,m);if(!p)return null;let d=PP(n),f={z0:d.z0+p[0],dzdx:d.dzdx+p[1],dzdy:d.dzdy+p[2]},h=null;for(let b of Mf(r,n)){let g=DP(b,f);(!h||g.height<h.height)&&(h={height:g.height,volume:b.name})}return h}function Vf(e){return e.aeroModel?null:"The car runs on aero constants, which do not move with the platform; attach an aero model in Aerodynamics"}var fH={front:"front",rear:"rear",heaveFront:"front",heaveRear:"rear",rollFront:"front",rollRear:"rear"};function Tu(e,t,r,n){let o=zd(e,t);return _d.some(s=>{if(fH[s]!==r)return!1;let i=o[s].coilover,c=i?.extended!==void 0&&i.extended>0;return n==="droop"?c:c&&i?.stroke!==void 0&&i.stroke>0})?null:n==="droop"?`No ${r} damper states its extended length; state it on its part in Dampers, or under Elements \u203A Stops`:`No ${r} damper states its stroke; state its extended length and stroke on its part in Dampers, or under Elements \u203A Stops`}function QR(e){return e.chassis?.boxes.length?null:"This suspension has no mockup volumes to measure the ground from; draw one under Kinematics \u203A Chassis"}var Bf=Math.PI/180,$f=1e-6;function FL(e,t){let r=e.length;if(r===0)return 0;if(0<=e[0])return t[0];if(0>=e[r-1])return t[r-1];let n=0;for(;e[n+1]<0;)n++;let o=(0-e[n])/(e[n+1]-e[n]);return t[n]+o*(t[n+1]-t[n])}function Pu(e){let t=e.measured;if(t)return FL(t.travel,t.camber);let r=ee(e.config.spinAxis);return-Math.asin(Math.max(-1,Math.min(1,r[2])))/Bf}function Lu(e){let t=e.measured;if(t)return FL(t.travel,t.toe);let[r,n]=e.config.spinAxis;return Math.atan2(r,n)/Bf}function ZR(e,t){let r=Math.abs(t.camber)>=$f,n=Math.abs(t.toe)>=$f;if(!r&&!n)return e;let o=e.measured;if(o)return{...e,measured:{...o,...r?{camber:o.camber.map(d=>d+t.camber)}:{},...n?{toe:o.toe.map(d=>d+t.toe)}:{}}};let[a,s]=e.config.spinAxis,i=Math.hypot(a,s);if(!(i>0))return e;let c=(Pu(e)+t.camber)*Bf,l=(Lu(e)+t.toe)*Bf,[u,m]=n?[Math.sin(l),Math.cos(l)]:[a/i,s/i],p=[u*Math.cos(c),m*Math.cos(c),-Math.sin(c)];return{...e,config:{...e.config,spinAxis:p}}}function Gf(e){let t=e&&typeof e=="object"?e.value:void 0;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function hH(e,t){let r=t;return{front:Gf(r.camber_front_deg)??Pu(e.front),rear:Gf(r.camber_rear_deg)??Pu(e.rear)}}function bH(e,t){let r=t;return{front:Gf(r.toe_front_deg)??Lu(e.front),rear:Gf(r.toe_rear_deg)??Lu(e.rear)}}function gH(e){return{camber:{front:Pu(e.front),rear:Pu(e.rear)},toe:{front:Lu(e.front),rear:Lu(e.rear)}}}var wL=new WeakMap;function yH(e,t){let r=gH(e),n={front:{camber:t.camber.front-r.camber.front,toe:t.toe.front-r.toe.front},rear:{camber:t.camber.rear-r.camber.rear,toe:t.toe.rear-r.toe.rear}},o=u=>Math.abs(u.camber)<$f&&Math.abs(u.toe)<$f;if(o(n.front)&&o(n.rear))return e;let a=`${t.camber.front}|${t.camber.rear}|${t.toe.front}|${t.toe.rear}`,s=wL.get(e),i=s?.get(a);if(i)return i;let c=e.corners?Object.fromEntries(Object.entries(e.corners).map(([u,m])=>[u,m&&ZR(m,n[vs(u)])])):void 0,l={...e,front:ZR(e.front,n.front),rear:ZR(e.rear,n.rear),...c?{corners:c}:{}};return s||wL.set(e,s=new Map),s.size>=16&&s.clear(),s.set(a,l),l}function Ei(e,t){return t?yH(e,{camber:hH(e,t),toe:bH(e,t)}):e}var xH=9.81;function Ii(e){let t=Xo(e),r=Math.max(0,e.unsprungPerCorner)*xH,n=a=>{let s=a==="FL"||a==="FR",i=s?"front":"rear",c=xt(e,i),l=c>0?c:1/0,u=$h(e,i);return{staticLoad:t[a],springLoad:Math.max(0,t[a]-r),tyreRate:l,arbRate:s?e.arbFront:e.arbRear,heaveRate:(s?e.heaveSpringFront:e.heaveSpringRear)??0,...u>0?{staticLoadedRadius:wr(u,t[a],l,u)}:{}}},o={};for(let[a,s,i,c,l,u]of[["front",e.elementLinkagesFront,!!e.decoupledFront,e.heaveCoiloverFront,e.heaveSeatFront,e.rollCoiloverFront],["rear",e.elementLinkagesRear,!!e.decoupledRear,e.heaveCoiloverRear,e.heaveSeatRear,e.rollCoiloverRear]]){let m=!i&&!!l&&(l.gap>0||!l.bothWays);(s?.heave||s?.roll||i||m)&&(o[a]={...s,carriesLoad:i,...c?{coilover:c}:{},...l&&!i?{heaveSeat:l}:{},...u?{rollCoilover:u}:{}})}return{corners:{FL:n("FL"),FR:n("FR"),RL:n("RL"),RR:n("RR")},...o.front||o.rear?{elements:o}:{},...e.cornerCoiloverFront||e.cornerCoiloverRear?{cornerCoilover:{...e.cornerCoiloverFront?{front:e.cornerCoiloverFront}:{},...e.cornerCoiloverRear?{rear:e.cornerCoiloverRear}:{}}}:{}}}var CL=new WeakMap;function RH(e){let t=Ei(e.vehicle,e.params);if(t===e.vehicle)return e;let r=CL.get(e);return(!r||r.vehicle!==t)&&CL.set(e,r={...e,vehicle:t}),r}function Eo(e,t={}){let r=RH(e),n=tR(r,t),o=t.assemble?()=>{let m=n.dynInput();if(!m)throw new Error("the car did not assemble");return{kc:Ii(m),cgHeight:m.cgHeight}}:void 0,a=WR(r,t.density,t.envelope,o),s=iR(r,n,t),i=jR(r,t),c=t.states??[],l=new Map;return{...a,...n,...s,...i,get failure(){return a.failure},values:new Map,states:c,stateOf:m=>m===void 0?c[0]??null:c.find(p=>p.id===m)??null,platformAt:m=>{let p=`${m.speedKmh}|${m.ayG}|${m.axG}`,d=l.get(p);if(d!==void 0)return d;let f=n.poseAt(m),h=n.dynInput(),b=null;if(f&&h)try{b=qR(h,m,f,a.contexts())}catch{b=null}return l.set(p,b),b}}}var vH=["x","y","z"],kH=/^(line|plane)\((-?\d+),(-?\d+)\)([uv]?)$/,TL=Math.PI/18e3,PL=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],LL=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],MH=e=>Math.hypot(e[0],e[1],e[2]),JR=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];function e1(e){let t=MH(e);return t>1e-9?JR(e,1/t):null}function SH(e,t){let r=e*TL,n=t*TL;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}function Pr(e){let t=e.lastIndexOf(".");if(t<0)return null;let r=kH.exec(e.slice(t+1));if(!r)return null;let n=r[1];return n==="line"!=(r[4]==="")?null:{point:e.slice(0,t),shape:{kind:n,dir:SH(Number(r[2]),Number(r[3]))},coord:n==="line"?"along":r[4]}}function DL(e){let t=e1(LL([0,0,1],e))??[1,0,0];(t[0]<-1e-9||Math.abs(t[0])<=1e-9&&t[1]<0)&&(t=JR(t,-1));let r=e1(LL(e,t))??[0,1,0];return(r[2]<-1e-9||Math.abs(r[2])<=1e-9&&r[1]<0)&&(r=JR(r,-1)),[t,r]}function t1(e){if(e.coord==="along")return e.shape.dir;let[t,r]=DL(e.shape.dir);return e.coord==="u"?t:r}function EL(e,t){let r=Pr(t);if(!r)return;let n=vH.map(u=>e[`${r.point}.${u}`]);if(n.some(u=>!u))return;let o=t1(r),a=[0,1,2].filter(u=>Math.abs(o[u])>1e-12),s=u=>n.map(m=>m.read(u)),i=n[0],c=a.map(u=>n[u].supersededBy).find(Boolean),l=i.label.replace(/ x$/,"");return{id:t,group:i.group,label:r.coord==="along"?`${l} along its line`:`${l} in its plane, ${r.coord}`,...i.scope?{scope:i.scope}:{},unit:i.unit,defaultSpan:i.defaultSpan,read:u=>PL(s(u),o),write:(u,m)=>{let p=s(u),d=m-PL(p,o),f=u;for(let h of a)f=n[h].write(f,p[h]+d*o[h]);return f},...c?{supersededBy:c}:{}}}var _i=["x","y","z"];var AH=/^(?:hp\.(?:front|rear)\.\w+|(?:heave|roll|rollBar)\.(?:front|rear)\.(?:outer|inner|anchor))$/;function Ua(e){let t=e.lastIndexOf("."),r=e.slice(0,t);if(t<0||!AH.test(r))return null;let n=e.slice(t+1);if(n==="x"||n==="y"||n==="z")return{point:r,axis:n};let o=Pr(e);return o?{point:r,axis:o.coord}:null}var Du="*";function r1(e){let t={sum:"summed",min:"lowest",max:"highest",distance:"by length",harmonic:"overall"};return e?.across?`all courses, ${t[e.across]}`:"all courses"}var n1=e=>e?.reads==="speed"||e?.reads==="operating",o1=e=>e?.reads==="lateral"||e?.reads==="operating";function Xa(e){if(!e)return"";let t=[];return e.speed!==void 0&&Number.isFinite(e.speed)&&t.push(`v${e.speed}`),e.ayG!==void 0&&Number.isFinite(e.ayG)&&t.push(`a${e.ayG}`),e.courseId&&t.push(`c${e.courseId}`),e.stateId&&t.push(`s${e.stateId}`),t.join(",")}function Kf(e,t){return e?.appliesAt?t.find(r=>!e.appliesAt(r)):t[0]}function Ni(e,t,r){let n=r?.stateId?e.stateOf(r.stateId):Kf(t,e.states)??null;return n&&!t.appliesAt?.(n)?n:null}function vt(e,t,r){let n=`${t.id}@${Xa(r)}`,o=e.values.get(n);if(o!==void 0)return o;let a;try{a=r?.courseId===Du&&t.reads==="course"?wH(e,t,r):r?.stateId===Rn&&t.reads==="state"?FH(e,t,r):t.read(e,r)}catch{a=NaN}return e.values.set(n,a),a}function wH(e,t,r){if(!t.across)return NaN;let n=e.courses();if(!n.length)return NaN;let o=n.map(s=>{let i={...r,courseId:s.id};return{v:vt(e,t,i),length:e.course(i)?.track.length??NaN}});if(o.some(s=>!Number.isFinite(s.v)))return NaN;if(t.across==="sum")return o.reduce((s,i)=>s+i.v,0);if(t.across==="min")return Math.min(...o.map(s=>s.v));if(t.across==="max")return Math.max(...o.map(s=>s.v));let a=o.reduce((s,i)=>s+i.length,0);return a>0?t.across==="harmonic"?a/o.reduce((s,i)=>s+i.length/i.v,0):o.reduce((s,i)=>s+i.v*i.length,0)/a:NaN}function FH(e,t,r){let n=t.appliesAt?e.states.filter(i=>!t.appliesAt(i)):e.states;if(!t.acrossStates||!n.length)return NaN;let o=n.map(i=>({v:vt(e,t,{...r,stateId:i.id}),w:i.weight,s:i})),a=t.appliesAt?o.filter(i=>Number.isFinite(i.v)||!e.poseAt(i.s)):o;if(!a.length||a.some(i=>!Number.isFinite(i.v)))return NaN;if(t.acrossStates==="max")return Math.max(...a.map(i=>i.v));if(t.acrossStates==="min")return Math.min(...a.map(i=>i.v));if(t.acrossStates==="span")return Math.max(...a.map(i=>i.v))-Math.min(...a.map(i=>i.v));let s=a.reduce((i,c)=>i+c.w,0);return s>0?a.reduce((i,c)=>i+c.v*c.w,0)/s:NaN}function a1(e){let t={mean:"weighted mean",max:"highest",min:"lowest",span:"span"};return e?.acrossStates?`every state, ${t[e.acrossStates]}`:"every state"}function bt(e){return`${e.quantity??e.groupShort??e.group} \xB7 ${e.label}`}var CH={front:"Front",rear:"Rear"},qa={heave:0,pitch:0,roll:0,steer:0},IL="RC height (chassis) [mm]";function _L(e,t){let r=0,n=0;for(let o=1;o<e.length;o++){let a=e[o]-e[o-1];if(Math.abs(a)<1e-9)continue;let s=(t[o]-t[o-1])/a;r+=s*s,n++}return n?Math.sqrt(r/n):NaN}function KL(e,t){let r=0;for(let n=1;n<e.length;n++){let o=e[n]-e[n-1];Math.abs(o)<1e-9||(r=Math.max(r,Math.abs((t[n]-t[n-1])/o)))}return r}var Mn=e=>e.length?Math.max(...e)-Math.min(...e):NaN;function s1(e){let t=(e??[]).filter(Number.isFinite);if(!t.length)return NaN;let r=t.reduce((n,o)=>n+o,0)/t.length;return Math.abs(r)>0?(Math.max(...t)-Math.min(...t))/Math.abs(r):NaN}function NL(e,t){if(!e.length)return;let r=0;for(let n=1;n<e.length;n++)Math.abs(e[n])<Math.abs(e[r])&&(r=n);return t[r]}function Vi(e,t,r){let n=e.stateOf(t?.stateId),o=n?e.poseAt(n):null;return o?r(o):NaN}var Eu=(e,t)=>`${e==="front"?"F":"R"}${t}`,OL=e=>e==="L"?"R":"L";function VL(e){let t=CH[e],r=M=>`kin.${e}.${M}`,n=(M,k)=>{let C=M.sweep(e);return C?{x:C.samples.map(P=>P.travel),y:C.samples.map(k)}:{x:[],y:[]}},o=M=>e==="front"?M.vehicle.front:M.vehicle.rear,a=M=>M.params[e==="front"?"heaveFrontDesign":"heaveRearDesign"],s=M=>M.params[e==="front"?"arbFrontDesign":"arbRearDesign"],i=e==="front"?"the front axle":"the rear axle";function c(M){return o(M).config.actuation==="decoupled"?`${i} is decoupled, with no corner damper \u2014 read its heave and roll elements`:null}function l(M){let k=a(M);return k&&k.design.kind!=="none"?null:`${i} has no heave element`}function u(M){let k=a(M);return k?.design.kind==="coil"&&k.linkage?null:`${i} has no heave element on a linkage`}function m(M){let k=s(M);return k&&k.design.kind!=="none"?null:`${i} has no roll element`}function p(M){let k=s(M);return k?.linkage&&k.design.kind!=="none"&&k.design.kind!=="direct"?null:`${i} has no roll element on a linkage`}let d=M=>{if(u(M.car))return null;let k=M.sweep(e);return k?Cb(o(M.car),a(M.car).linkage,k.samples):null},f=M=>xl(M.vehicle,M.params,e);function h(M){return f(M)?null:un(o(M))?ha(s(M))?`${i}\u2019s roll element is itself a bar`:`${i} has no anti-roll bar beside its roll element`:`${i} is not decoupled: its anti-roll bar is its roll element`}function b(M){let k=f(M);return k?k.linkage&&k.design.kind!=="direct"?null:`${i}\u2019s anti-roll bar is stated at the wheel, on no linkage`:h(M)}let g=(M,k)=>{let C=M.sweep(e);if(!C)return null;let P=Ab(o(M.car),k.linkage,k.design.kind,C.samples),L=P.atDesign<0?-1:1;return{travel:P.travel,ratio:P.ratio.map(E=>E*L),atDesign:P.atDesign*L}},y=M=>p(M.car)?null:g(M,s(M.car)),x=M=>b(M.car)?null:g(M,f(M.car)),R=M=>M.readout(qa)?.[e],v=M=>M.readoutAtTravel(e,M.envelope.travelMax),S=M=>{let k=n(M,C=>C.metrics.camber);return k.x.length?{key:r("camberGain"),title:`${t} camber vs travel`,xLabel:"travel [mm]",yLabel:"camber [\xB0]",...k}:null},A=M=>{let k=n(M,C=>C.metrics.toe);return k.x.length?{key:r("bumpSteer"),title:`${t} toe vs travel`,xLabel:"travel [mm]",yLabel:"toe [\xB0]",...k}:null},F=[{id:r("rcStatic"),group:`${t} roll centre`,label:"static height",unit:"mm",scale:30,scope:e,cost:"cheap",read:M=>M.rcRoll(e)?.rc[0]?.heightAboveGround??NaN},{id:r("rcHeaveWorst"),group:`${t} roll centre`,label:"worst migration vs travel",unit:"mm/mm",scale:.5,scope:e,cost:"cheap",read:M=>{let k=M.rcHeave(e);return k?KL(k.at,k.rc.map(C=>C.height)):NaN},curve:M=>{let k=M.rcHeave(e);return k?{key:r("rcHeaveWorst"),title:`${t} roll-centre height vs wheel travel`,xLabel:"travel [mm]",yLabel:IL,x:k.at,y:k.rc.map(C=>C.height-M.roadUnder(e))}:null}},{id:r("rcRollSpan"),group:`${t} roll centre`,label:"height span over the roll envelope",unit:"mm",scale:15,scope:e,cost:"cheap",read:M=>{let k=M.rcRoll(e);return k?Mn(k.rc.map(C=>C.height)):NaN},curve:M=>{let k=M.rcRoll(e);return k?{key:r("rcRollSpan"),title:`${t} roll-centre height vs body roll`,xLabel:"roll [\xB0]",yLabel:IL,x:k.at,y:k.rc.map(C=>C.height-M.roadUnder(e))}:null}},{id:r("rcLateralSpan"),group:`${t} roll centre`,label:"lateral migration over roll",unit:"mm",scale:50,scope:e,cost:"cheap",read:M=>{let k=M.rcRoll(e);return k?Mn(k.rc.map(C=>C.lateral)):NaN},curve:M=>{let k=M.rcRoll(e);return k?{key:r("rcLateralSpan"),title:`${t} roll-centre lateral position vs body roll`,xLabel:"roll [\xB0]",yLabel:"RC lateral [mm]",x:k.at,y:k.rc.map(C=>C.lateral)}:null}},{id:r("minSinAngle"),group:`${t} roll centre`,label:"construction conditioning (min sinAngle)",unit:"-",scale:.04,scope:e,cost:"cheap",read:M=>{let k=M.rcHeave(e),C=M.rcRoll(e);return!k||!C?NaN:Math.min(...k.rc.map(P=>P.sinAngle),...C.rc.map(P=>P.sinAngle))},curve:M=>{let k=M.rcHeave(e);return k?{key:r("minSinAngle"),title:`${t} construction conditioning vs travel`,xLabel:"travel [mm]",yLabel:"sinAngle",x:k.at,y:k.rc.map(C=>C.sinAngle)}:null}},{id:r("fvsaLength"),group:`${t} roll centre`,label:"front-view swing-arm length",unit:"mm",scale:500,scope:e,cost:"readout",read:M=>R(M)?.fvsaLength??NaN},{id:r("complianceSteer"),group:`${t} compliance`,label:"compliance steer",unit:"\xB0/kN lateral",scale:.05,scope:e,cost:"readout",read:M=>(M.compliance(e)?.toePerFy??0)*1e3},{id:r("complianceCamber"),group:`${t} compliance`,label:"compliance camber",unit:"\xB0/kN lateral",scale:.05,scope:e,cost:"readout",read:M=>(M.compliance(e)?.camberPerFy??0)*1e3},{id:r("complianceSteerLong"),group:`${t} compliance`,label:"compliance steer under braking",unit:"\xB0/kN longitudinal",scale:.05,scope:e,cost:"readout",read:M=>(M.compliance(e)?.toePerFx??0)*1e3},{id:r("steeringCompliance"),group:`${t} compliance`,label:"steer given back under aligning torque",unit:"\xB0/100 N\xB7m",scale:.2,scope:e,cost:"readout",read:M=>(M.compliance(e)?.toePerMz??0)*1e5},{id:r("staticCamber"),group:`${t} camber & toe`,label:"static camber",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:M=>{let k=M.solveAt(e,0);return k?k.metrics.camber:NaN}},{id:r("staticToe"),group:`${t} camber & toe`,label:"static toe",unit:"\xB0",scale:.5,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.toe??NaN},{id:r("camberGainDesign"),group:`${t} camber & toe`,label:"camber gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:M=>R(M)?.camberGain??NaN,curve:M=>S(M)},{id:r("rollCamber"),group:`${t} camber & toe`,label:"camber gain in roll",unit:"\xB0/\xB0",scale:.2,scope:e,cost:"readout",read:M=>R(M)?.rollCamber??NaN},{id:r("rollCamberRecovery"),group:`${t} camber & toe`,label:"camber recovery in roll",unit:"%",scale:20,scope:e,cost:"readout",read:M=>R(M)?.camberRecovery??NaN},{id:r("bumpSteerDesign"),group:`${t} camber & toe`,label:"bump steer at design",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:M=>R(M)?.bumpSteer??NaN,curve:M=>A(M)},{id:r("rollSteer"),group:`${t} camber & toe`,label:"roll steer",unit:"\xB0/\xB0",scale:.1,scope:e,cost:"readout",read:M=>R(M)?.rollSteer??NaN},{id:r("bumpSteer"),group:`${t} camber & toe`,label:"bump steer, RMS over the travel",unit:"\xB0/mm",scale:.02,scope:e,cost:"cheap",read:M=>{let k=n(M,C=>C.metrics.toe);return k.x.length?_L(k.x,k.y):NaN},curve:M=>A(M)},{id:r("camberGain"),group:`${t} camber & toe`,label:"camber gain, RMS over the travel",unit:"\xB0/mm",scale:.02,scope:e,cost:"cheap",read:M=>{let k=n(M,C=>C.metrics.camber);return k.x.length?_L(k.x,k.y):NaN},curve:M=>S(M)},{id:r("camberSpan"),group:`${t} camber & toe`,label:"camber range over travel",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:M=>Mn(n(M,k=>k.metrics.camber).y)},{id:r("toeSpan"),group:`${t} camber & toe`,label:"toe range over travel",unit:"\xB0",scale:.5,scope:e,cost:"cheap",read:M=>Mn(n(M,k=>k.metrics.toe).y)},{id:r("camberRecovery"),group:`${t} camber & toe`,label:"outer camber at limit roll",unit:"\xB0",scale:2,scope:e,cost:"cheap",read:M=>{let k=M.solveAt(e,M.travelAtRoll(e,M.envelope.rollAtLimitDeg)),C=M.solveAt(e,0);return!k||!C?NaN:Math.abs(k.metrics.camber-C.metrics.camber+M.envelope.rollAtLimitDeg)}},{id:r("stateCamberOuter"),group:`${t} camber & toe`,label:"outer camber to the road at a state",unit:"\xB0",scale:1,scope:e,cost:"cheap",reads:"state",acrossStates:"mean",read:(M,k)=>Vi(M,k,C=>C.camber[Eu(e,C.outer)])},{id:r("stateCamberInner"),group:`${t} camber & toe`,label:"inner camber to the road at a state",unit:"\xB0",scale:1,scope:e,cost:"cheap",reads:"state",acrossStates:"mean",read:(M,k)=>Vi(M,k,C=>C.camber[Eu(e,OL(C.outer))])},{id:r("stateToeOuter"),group:`${t} camber & toe`,label:"outer toe change at a state",unit:"\xB0",scale:.2,scope:e,cost:"cheap",reads:"state",acrossStates:"mean",read:(M,k)=>Vi(M,k,C=>C.corners[Eu(e,C.outer)].bumpToe)},{id:r("caster"),group:`${t} upright`,label:"caster",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.caster??NaN},{id:r("kpi"),group:`${t} upright`,label:"kingpin inclination",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.kpi??NaN},{id:r("scrubRadius"),group:`${t} upright`,label:"scrub radius",unit:"mm",scale:20,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.scrubRadius??NaN},{id:r("mechanicalTrail"),group:`${t} upright`,label:"mechanical trail",unit:"mm",scale:20,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.mechanicalTrail??NaN},{id:r("kingpinOffset"),group:`${t} upright`,label:"kingpin offset at hub height",unit:"mm",scale:20,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.kingpinOffset??NaN},{id:r("casterOffset"),group:`${t} upright`,label:"caster offset at hub height",unit:"mm",scale:10,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.casterOffset??NaN},{id:r("steeringArm"),group:`${t} upright`,label:"steering arm",unit:"mm",scale:20,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.steeringArm??NaN},{id:r("casterGain"),group:`${t} upright`,label:"caster gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:M=>R(M)?.casterGain??NaN},{id:r("kpiGain"),group:`${t} upright`,label:"kingpin inclination gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:M=>R(M)?.kpiGain??NaN},{id:r("scrubGain"),group:`${t} upright`,label:"scrub radius gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:M=>R(M)?.scrubGain??NaN},{id:r("trailGain"),group:`${t} upright`,label:"mechanical trail gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:M=>R(M)?.trailGain??NaN},{id:r("motionRatio"),group:`${t} rates`,label:"motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:c,read:M=>{if(c(M.car))return NaN;let k=M.sweep(e);return k?NL(k.samples.map(C=>C.travel),k.samples.map(C=>C.metrics.motionRatio??NaN))??NaN:NaN},curve:M=>{if(c(M.car))return null;let k=n(M,C=>C.metrics.motionRatio??NaN);return k.x.length?{key:r("motionRatio"),title:`${t} motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",...k}:null}},{id:r("mrSpread"),group:`${t} rates`,label:"motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:c,read:M=>{if(c(M.car))return NaN;let k=M.sweep(e);if(!k)return NaN;let C=k.samples.map(L=>L.metrics.motionRatio??NaN).filter(Number.isFinite);if(!C.length)return NaN;let P=C.reduce((L,E)=>L+E,0)/C.length;return P>0?(Math.max(...C)-Math.min(...C))/P:NaN}},{id:r("wheelRate"),group:`${t} rates`,label:"wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:c,read:M=>{if(c(M.car))return NaN;let k=M.sweep(e);return k?NL(k.samples.map(C=>C.travel),k.samples.map(C=>C.metrics.wheelRate??NaN))??NaN:NaN}},{id:r("heaveMotionRatio"),group:`${t} rates`,label:"heave element motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:u,read:M=>d(M)?.atDesign??NaN,curve:M=>{let k=d(M);return k?{key:r("heaveMotionRatio"),title:`${t} heave element motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:k.travel,y:k.ratio}:null}},{id:r("heaveMrSpread"),group:`${t} rates`,label:"heave element motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:u,read:M=>s1(d(M)?.ratio)},{id:r("heaveWheelRate"),group:`${t} rates`,label:"heave element wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:l,read:M=>l(M.car)||!M.sweep(e)?NaN:ba(M.car.vehicle,M.car.params)[e]??NaN},{id:r("rollMotionRatio"),group:`${t} rates`,label:"roll element motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:p,read:M=>y(M)?.atDesign??NaN,curve:M=>{let k=y(M);return k?{key:r("rollMotionRatio"),title:`${t} roll element motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:k.travel,y:k.ratio}:null}},{id:r("rollMrSpread"),group:`${t} rates`,label:"roll element motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:p,read:M=>s1(y(M)?.ratio)},{id:r("rollWheelRate"),group:`${t} rates`,label:"roll element wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:m,read:M=>m(M.car)||!M.sweep(e)?NaN:Rl(M.car.vehicle,M.car.params)[e].element??NaN},{id:r("rollBarMotionRatio"),group:`${t} rates`,label:"anti-roll bar motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:b,read:M=>x(M)?.atDesign??NaN,curve:M=>{let k=x(M);return k?{key:r("rollBarMotionRatio"),title:`${t} anti-roll bar motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:k.travel,y:k.ratio}:null}},{id:r("rollBarMrSpread"),group:`${t} rates`,label:"anti-roll bar motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:b,read:M=>s1(x(M)?.ratio)},{id:r("rollBarWheelRate"),group:`${t} rates`,label:"anti-roll bar wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:h,read:M=>h(M.car)||!M.sweep(e)?NaN:Rl(M.car.vehicle,M.car.params)[e].bar??NaN},{id:r("ucaAxisLength"),group:`${t} package`,label:"upper arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:M=>M.axisLength(e,"uca")},{id:r("lcaAxisLength"),group:`${t} package`,label:"lower arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:M=>M.axisLength(e,"lca")},{id:r("linkLength"),group:`${t} package`,label:"tie/toe link length",unit:"mm",scale:100,scope:e,cost:"geometry",read:M=>M.linkLength(e)},{id:r("trackScrubRate"),group:`${t} package`,label:"track scrub rate",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:M=>M.readout(qa)?.[e].trackScrubRate??NaN},{id:r("trackChange"),group:`${t} package`,label:"track change at full bump",unit:"mm",scale:2,scope:e,cost:"readout",read:M=>v(M)?.trackChange??NaN},{id:r("stateTravelOuter"),group:`${t} package`,label:"outer wheel travel at a state",unit:"mm",scale:10,scope:e,cost:"cheap",reads:"state",acrossStates:"max",read:(M,k)=>Vi(M,k,C=>C.corners[Eu(e,C.outer)].travel)},{id:r("stateTravelInner"),group:`${t} package`,label:"inner wheel travel at a state",unit:"mm",scale:10,scope:e,cost:"cheap",reads:"state",acrossStates:"min",read:(M,k)=>Vi(M,k,C=>C.corners[Eu(e,OL(C.outer))].travel)},{id:r("damperStroke"),group:`${t} package`,label:"damper stroke over the travel",unit:"mm",scale:20,scope:e,cost:"cheap",unavailable:c,read:M=>c(M.car)?NaN:Mn(n(M,k=>k.metrics.damperLength).y),curve:M=>{if(c(M.car))return null;let k=n(M,C=>C.metrics.damperLength);return k.x.length?{key:r("damperStroke"),title:`${t} damper length vs travel`,xLabel:"travel [mm]",yLabel:"length [mm]",...k}:null}}];e==="front"&&F.push({id:r("camberPerSteer"),group:`${t} camber & toe`,label:"camber change with steer",unit:"\xB0/\xB0",scale:.05,scope:"front",cost:"readout",read:M=>R(M)?.camberPerSteer??NaN},{id:r("steerJacking"),group:`${t} upright`,label:"corner rise per degree of steer",unit:"mm/\xB0",scale:.05,scope:"front",cost:"readout",read:M=>R(M)?.steerJacking??NaN}),e==="front"?F.push({id:r("antiDive"),group:`${t} anti geometry`,label:"anti-dive",unit:"%",scale:20,scope:"front",cost:"readout",read:M=>M.readout(qa)?.front.antiDive??NaN}):F.push({id:r("antiSquat"),group:`${t} anti geometry`,label:"anti-squat (driving)",unit:"%",scale:20,scope:"rear",cost:"readout",read:M=>M.readout(qa)?.rear.antiSquat??NaN},{id:r("antiLift"),group:`${t} anti geometry`,label:"anti-lift (braking)",unit:"%",scale:20,scope:"rear",cost:"readout",read:M=>M.readout(qa)?.rear.antiLift??NaN});let w=M=>{let k=M.slice(t.length+1);return k.charAt(0).toUpperCase()+k.slice(1)};return[...new Set(F.map(M=>M.group))].flatMap(M=>F.filter(k=>k.group===M)).map(M=>({...M,quantity:`${t} \xB7 ${w(M.group)}`}))}function BL(e,t){let r=e.steer();if(!r)return NaN;let n=r.filter(a=>Number.isFinite(a.ackermannPct)&&a.inner>.3&&a.outer>.3);return n.length?n.reduce((a,s)=>t==="centre"?s.inner<a.inner?s:a:s.inner>a.inner?s:a).ackermannPct:NaN}var TH=[{id:"kin.front.ackermannCentre",group:"Steering",label:"Ackermann near centre",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>BL(e,"centre"),curve:e=>{let t=e.steer();if(!t)return null;let r=t.filter(n=>Number.isFinite(n.ackermannPct)&&n.inner>.3&&n.outer>.3);return r.length?{key:"kin.front.ackermann",title:"Ackermann vs steer",xLabel:"inner wheel steer [\xB0]",yLabel:"Ackermann [%]",x:r.map(n=>n.inner),y:r.map(n=>n.ackermannPct)}:null}},{id:"kin.front.ackermannLock",group:"Steering",label:"Ackermann at lock",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>BL(e,"lock")},{id:"kin.front.lockInner",group:"Steering",label:"inner wheel angle at full rack",unit:"\xB0",scale:5,scope:"front",cost:"cheap",read:e=>{let t=e.steer();return t?.length?Math.max(...t.map(r=>r.inner)):NaN}}],PH=[{id:"kin.car.trackFront",group:"Whole car",label:"front track",unit:"mm",scale:50,scope:"front",cost:"geometry",read:e=>2*e.car.vehicle.front.hardpoints.wheelCenter[1]},{id:"kin.car.trackRear",group:"Whole car",label:"rear track",unit:"mm",scale:50,scope:"rear",cost:"geometry",read:e=>2*e.car.vehicle.rear.hardpoints.wheelCenter[1]},{id:"kin.car.stateRoll",group:"Whole car",label:"body roll at a state",unit:"\xB0",scale:1,scope:"car",cost:"cheap",reads:"state",acrossStates:"max",read:(e,t)=>Vi(e,t,r=>Math.abs(r.rollDeg))},{id:"kin.car.wheelbaseChange",group:"Whole car",label:"wheelbase change at full bump",unit:"mm",scale:2,scope:"car",cost:"readout",read:e=>{let t=e.readoutAtTravel("front",e.envelope.travelMax),r=e.readoutAtTravel("rear",e.envelope.travelMax);return t&&r?t.longitudinal-r.longitudinal:NaN}}],Oi=(e,t)=>e.left.valid&&e.right.valid?(t(e.left)+t(e.right))/2:NaN,i1=(e,t)=>{let r=e.readout(qa)?.axes?.pitch;return r?.valid?t(r):NaN},$L=(e,t)=>{let r=e.readout(qa)?.axes?.roll;return r?.usable?t(r):NaN},LH=e=>(e.roadUnder("front")+e.roadUnder("rear"))/2;function GL(e){let t=e.rcRoll("front"),r=e.rcRoll("rear"),n=e.cg();if(!t||!r||!n)return null;let o=e.car.vehicle.config,a=t.rc.map((s,i)=>lP({front:s,rear:r.rc[i]},n,o.frontAxleX,o.wheelbase,()=>!0).arm);return{at:t.at,arm:a}}var DH="PC height (chassis) [mm]",EH=[{id:"kin.car.pcHeight",group:"Pitch axis",label:"pitch-centre height at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>i1(e,t=>t.heightAboveGround)},{id:"kin.car.pcAhead",group:"Pitch axis",label:"pitch centre ahead of the CG at design",unit:"mm",scale:300,scope:"car",cost:"readout",read:e=>i1(e,t=>t.ahead)},{id:"kin.car.pitchArm",group:"Pitch axis",label:"pitch arm at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>i1(e,t=>t.arm)},{id:"kin.car.pcHeaveWorst",group:"Pitch axis",label:"worst height migration vs travel",unit:"mm/mm",scale:.5,scope:"car",cost:"cheap",read:e=>{let t=e.pcHeave();return t?KL(t.at,t.pc.map(r=>Oi(r,n=>n.height))):NaN},curve:e=>{let t=e.pcHeave();if(!t)return null;let r=LH(e);return{key:"kin.car.pcHeaveWorst",title:"Pitch-centre height vs wheel travel",xLabel:"travel [mm]",yLabel:DH,x:t.at,y:t.pc.map(n=>Oi(n,o=>o.height)-r)}}},{id:"kin.car.pcPitchSpan",group:"Pitch axis",label:"height span over the pitch envelope",unit:"mm",scale:15,scope:"car",cost:"cheap",read:e=>{let t=e.pcPitch();return t?Mn(t.pc.map(r=>Oi(r,n=>n.heightAboveGround))):NaN},curve:e=>{let t=e.pcPitch();return t?{key:"kin.car.pcPitchSpan",title:"Pitch-centre height vs body pitch",xLabel:"pitch [\xB0, + nose down]",yLabel:"PC height above road [mm]",x:t.at,y:t.pc.map(r=>Oi(r,n=>n.heightAboveGround))}:null}},{id:"kin.car.pcAheadSpan",group:"Pitch axis",label:"fore-aft migration over the pitch envelope",unit:"mm",scale:300,scope:"car",cost:"cheap",read:e=>{let t=e.pcPitch();return t?Mn(t.pc.map(r=>Oi(r,n=>n.x))):NaN},curve:e=>{let t=e.pcPitch(),r=e.cg();return!t||!r?null:{key:"kin.car.pcAheadSpan",title:"Pitch centre ahead of the CG vs body pitch",xLabel:"pitch [\xB0, + nose down]",yLabel:"PC ahead of CG [mm]",x:t.at,y:t.pc.map(n=>Oi(n,o=>o.x)-r.x)}}},{id:"kin.car.pcMinSinAngle",group:"Pitch axis",label:"construction conditioning (min sinAngle)",unit:"-",scale:.01,scope:"car",cost:"cheap",read:e=>{let t=e.pcHeave(),r=e.pcPitch();return!t||!r?NaN:Math.min(...[...t.pc,...r.pc].map(n=>Math.min(n.left.sinAngle,n.right.sinAngle)))}},{id:"kin.car.rollArm",group:"Roll axis",label:"roll arm at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>$L(e,t=>t.arm)},{id:"kin.car.rollAxisSlope",group:"Roll axis",label:"slope at design (+ rising rearward)",unit:"\xB0",scale:.5,scope:"car",cost:"readout",read:e=>$L(e,t=>t.slope)},{id:"kin.car.rollArmSpan",group:"Roll axis",label:"roll-arm span over the roll envelope",unit:"mm",scale:15,scope:"car",cost:"cheap",read:e=>{let t=GL(e);return t?Mn(t.arm):NaN},curve:e=>{let t=GL(e);return t?{key:"kin.car.rollArmSpan",title:"Roll arm vs body roll",xLabel:"roll [\xB0]",yLabel:"roll arm [mm]",x:t.at,y:t.arm}:null}}],c1=[...VL("front"),...VL("rear"),...TH,...PH,...EH];var IH={front:"Front",rear:"Rear"};function YL(e){return e.chassis?.boxes.length?null:"This suspension has no mockup volumes to keep its parts out of; draw one under Kinematics \u203A Chassis"}function _H(e,t,r){let n=r==="front"?t.tireModel:t.tireModelRear??t.tireModel;return yR(e.parts?.[r],n)?null:`The ${r} axle states no rim, so its tyre and rim are not measured; state one under Kinematics \u203A Linkage \u203A Wheel`}function HL(e,t,r){let n=e.parts?.[t]?.jointLimits?.[r];return xR(n)?n:void 0}function zL(e){let t=IH[e],r=s=>`kin.${e}.${s}`,n=e==="front"?"over the travel and the rack":"over the travel",o=(s,i)=>{let c=s.keepOuts(e);return c?i(c)??NaN:NaN},a={group:`${t} keep-outs`,quantity:`${t} \xB7 Keep-outs`,scope:e,cost:"readout"};return[{...a,id:r("chassisClearance"),label:`least clearance to the chassis volumes ${n}`,unit:"mm",scale:5,unavailable:s=>YL(s.vehicle),read:s=>o(s,i=>i.chassis?.distance)},{...a,id:r("wheelClearance"),label:`least clearance inside the wheel ${n}`,unit:"mm",scale:5,unavailable:s=>_H(s.vehicle,s.params,e),read:s=>o(s,i=>i.wheel?.distance)},{...a,id:r("ballJointAngle"),label:`largest ball-joint angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.ballJoint?.angle),statedLimit:s=>HL(s.vehicle,e,"ballJoint")},{...a,id:r("rodEndAngle"),label:`largest rod-end angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.rodEnd?.angle),statedLimit:s=>HL(s.vehicle,e,"rodEnd")}]}var l1=[...zL("front"),...zL("rear")];var qL={front:"Front",rear:"Rear"},WL=e=>$a("side",e),NH=e=>$a("drive",e)&&$a("brake",e)?"neither brakes nor drives":null;function OH(e,t,r,n){let o=Ni(e,t,r),a=o?e.tyreAt(o):null;return a?n(a):NaN}function Bi(e,t){let r={...e,read:(n,o)=>OH(n,r,o,t)};return r}var jL=e=>e?100*e.lossCamber:NaN,UL=e=>e&&!e.lifted?e.camber-e.wants:NaN;function XL(e){let t=qL[e],r=s=>`tyre.${e}.${s}`,n={group:`${t} tyre`,quantity:`${t} \xB7 Tyre`,scope:e,cost:"cheap",reads:"state",acrossStates:"mean"},o={...n,appliesAt:WL,unavailable:s=>cf(s.params,e)},a=[Bi({...o,id:r("camberErrorOuter"),label:"camber error at the outer wheel",unit:"\xB0",scale:.5},s=>UL(s.side(e)?.wheels[0])),Bi({...o,id:r("camberErrorInner"),label:"camber error at the inner wheel",unit:"\xB0",scale:.5},s=>UL(s.side(e)?.wheels[1])),Bi({...o,id:r("sideLossCamber"),label:"side grip lost to camber",unit:"%",scale:1},s=>jL(s.side(e))),Bi({...n,appliesAt:WL,id:r("sideLossToe"),label:"side grip lost to the toe split",unit:"%",scale:1},s=>100*s.toeLoss(e)),Bi({...n,appliesAt:NH,unavailable:s=>Zx(s.params,e),id:r("longLossCamber"),label:"drive and brake grip lost to camber",unit:"%",scale:1},s=>jL(s.long(e)))];return e==="front"&&a.push(Bi({...n,appliesAt:s=>$a("ackermann",s),id:r("ackermannError"),label:"Ackermann against the tyre",unit:"%",scale:25},s=>s.ackermann())),a}var u1=[...XL("front"),...XL("rear")],VH=/^tyre\.(front|rear)\.(camberErrorOuter|camberErrorInner|sideLossCamber|longLossCamber)$/;function m1(e,t){let r=new Map,n=a=>a.name.charAt(0).toLowerCase()+a.name.slice(1),o=a=>`${a>0?"+":a<0?"\u2212":""}${Math.abs(a).toFixed(1)}\xB0`;for(let{m:a,at:s}of t){let i=VH.exec(a.id);if(!i)continue;let c=i[1],l=i[2]==="longLossCamber",u=s?.stateId==="*"?e.states.filter(m=>!a.appliesAt?.(m)):[Ni(e,a,s)].filter(m=>!!m);for(let m of u){let p=`${c}|${m.id}|${l}`;if(r.has(p))continue;let d=e.tyreAt(m),f=d?l?d.long(c):d.side(c):null;if(!f)continue;let{lo:h,hi:b,stated:g}=f.range,y=g?`the ${o(h)} \u2026 ${o(b)} its data covers`:`the \xB1${b.toFixed(0)}\xB0 read without a stated range`,x=A=>l?A===0?"left":"right":A===0?"outer":"inner",R=f.wheels.findIndex(A=>A.atEdge),v=f.wheels.findIndex(A=>A.outside&&!A.lifted),S=[];R>=0&&S.push(`the ${qL[c].toLowerCase()} ${x(R)} tyre wants ${o(f.wheels[R].wants)}, the edge of ${y}, and may want more`),v>=0&&S.push(`the ${x(v)} wheel has ${o(f.wheels[v].camber)}, past it, and is read at ${o(f.wheels[v].read)}`),S.length&&r.set(p,`In the ${n(m)} ${S.join("; ")}.`)}}return[...r.values()]}function d1(e,t){let r=e.appliesAt?.(t);return r?`is read at ${t.name}, which ${r}`:null}var BH={front:"Front",rear:"Rear"};function $H(e,t,r,n){let o=Ni(e,t,r),a=o?e.platformAt(o):null;return(a?n(a):null)??NaN}function Lr(e,t){let r={...e,read:(n,o)=>$H(n,r,o,t)};return r}var p1={cost:"cheap",reads:"state"},GH={unavailable:e=>Vf(e.params)};function QL(e){let t=BH[e],r=o=>`platform.${e}.${o}`,n={...p1,group:`${t} platform`,quantity:`${t} \xB7 Platform`,scope:e};return[Lr({...n,id:r("rideHeight"),label:"ride height at a state",unit:"mm",scale:5,acrossStates:"min"},o=>o[e].height),Lr({...n,id:r("toBumpStop"),label:"travel left to the bump stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>Tu(o.vehicle,o.params,e,"bump")},o=>o[e].toBump),Lr({...n,id:r("toDroopStop"),label:"travel left to the droop stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>Tu(o.vehicle,o.params,e,"droop")},o=>o[e].toDroop)]}var Hf={...p1,group:"Platform",scope:"car"},Iu={...p1,...GH,group:"Aero platform",groupShort:"Aero",scope:"car"},f1=[...QL("front"),...QL("rear"),Lr({...Hf,id:"platform.rake",label:"rake at a state",unit:"\xB0",scale:.2,acrossStates:"span"},e=>e.rakeDeg),Lr({...Hf,id:"platform.pitch",label:"pitch at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.pitchDeg),Lr({...Hf,id:"platform.roll",label:"body roll at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.rollDeg),Lr({...Hf,id:"platform.groundClearance",label:"ground clearance at a state",unit:"mm",scale:5,acrossStates:"min",unavailable:e=>QR(e.vehicle)},e=>e.clearance?.height),Lr({...Iu,id:"platform.balance",label:"balance at a state",unit:"%",scale:1,acrossStates:"span"},e=>e.aero?.balance),Lr({...Iu,id:"platform.clA",label:"downforce Cl\xB7A at a state",unit:"m\xB2",scale:.1,acrossStates:"mean"},e=>e.aero?.clA),Lr({...Iu,id:"platform.cdA",label:"drag Cd\xB7A at a state",unit:"m\xB2",scale:.05,acrossStates:"mean"},e=>e.aero?.cdA),Lr({...Iu,id:"platform.dataMargin",label:"margin to the model\u2019s data",unit:"mm",scale:5,acrossStates:"min"},e=>e.aero?.dataMargin),Lr({...Iu,id:"platform.loopMargin",label:"aero-elastic margin, 1 \u2212 loop gain",unit:"-",scale:.1,acrossStates:"min"},e=>e.aero?.loopMargin)];var ZL={understeer:"operating",yawFreq:"speed",yawZeta:"speed",yawStiffness:"operating",steeringTorque:"operating",steeringTorqueGradient:"operating"};function kt(e,t,r,n="cheap"){let o=ky[e];if(!o)throw new Error(`no DYN_METRIC "${e}"`);return{id:`dyn.${e}`,group:t,label:o.label,unit:o.unit,scale:r,scope:"car",cost:n,...ZL[e]?{reads:ZL[e]}:{},read:(a,s)=>{let i=a.dynInput(),c=a.dynCtx(s);return i&&c?o.compute(i,c):NaN}}}function JL(e,t){let r=e.dynInput();if(!r)return null;let n=t("front"),o=t("rear");if(!n||!o||n.rc.length!==o.rc.length)return null;let a=e.roadUnder("front"),s=e.roadUnder("rear"),i=n.rc.map((c,l)=>{let u=ri(c),m=ri(o.rc[l]);if(!u||!m)return NaN;let p=xM(r,u.height-a,m.height-s);return 100*RM(r,{rcFront:u.heightAboveGround,rcRear:m.heightAboveGround,arm:p})});return{at:n.at,share:i}}function h1(e,t,r,n,o){let a=`dyn.${e}`;return{id:a,group:"Handling \u2014 balance",label:t,unit:"%",scale:1,scope:"car",cost:"cheap",read:s=>{let i=JL(s,o(s));return i?Mn(i.share):NaN},curve:s=>{let i=JL(s,o(s));return i?{key:a,title:r,xLabel:n,yLabel:"TLLTD front [%]",x:i.at,y:i.share}:null}}}var KH=[kt("understeer","Handling \u2014 balance",.1),kt("tlltdFront","Handling \u2014 balance",5),h1("tlltdHeaveSpan","TLLTD span over the travel","TLLTD vs wheel travel","travel [mm]",e=>t=>e.rcHeave(t)),h1("tlltdPitchSpan","TLLTD span over the pitch envelope","TLLTD vs body pitch","pitch [\xB0, + nose down]",e=>t=>e.rcPitch(t)),h1("tlltdRollSpan","TLLTD span over the roll envelope","TLLTD vs body roll","roll [\xB0]",e=>t=>e.rcRoll(t)),kt("rollStiffFront","Handling \u2014 balance",5)],HH=[kt("yawFreq","Handling \u2014 response",.5),kt("yawZeta","Handling \u2014 response",.2),kt("stabilitySpeed","Handling \u2014 response",50),kt("yawStiffness","Handling \u2014 response",2e4,"trim")],zH=[kt("steeringTorque","Steering feel",1,"trim"),kt("steeringTorqueGradient","Steering feel",2,"trim")],YH=[kt("rollGradient","Ride & body",.5),kt("pitchGradient","Ride & body",.5),kt("rideFreqFront","Ride & body",.5),kt("rideFreqRear","Ride & body",.5),kt("rollFreqNoDampers","Ride & body",.5),kt("pitchFreqNoDampers","Ride & body",.5),kt("rollFreq","Ride & body",.5),kt("pitchFreq","Ride & body",.5),kt("zetaFront","Ride & body",.2),kt("zetaRear","Ride & body",.2)],WH=[{id:"dyn.reserveStabil",group:"What the car has left",label:"Yaw stability reserve",unit:"N\xB7m",scale:200,scope:"car",cost:"trim",reads:"operating",read:(e,t)=>e.reserves("operating",t)?.stabil??NaN},{id:"dyn.reserveAgil",group:"What the car has left",label:"Yaw agility reserve",unit:"N\xB7m",scale:200,scope:"car",cost:"trim",reads:"operating",read:(e,t)=>e.reserves("operating",t)?.agil??NaN},{id:"dyn.limitBalance",group:"What the car has left",label:"Limit balance (+US / \u2212OS)",unit:"-",scale:.5,scope:"car",cost:"trim",reads:"speed",read:(e,t)=>e.reserves("limit",t)?.rel??NaN}],jH=[{id:"dyn.ymdMaxAy",group:"Yaw-moment diagram",label:"Max lateral acceleration",unit:"g",scale:.2,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymd(t)?.maxAy??NaN},{id:"dyn.ymdStability",group:"Yaw-moment diagram",label:"Stability \u2202CN/\u2202\u03B2 at the origin",unit:"1/rad",scale:5,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymd(t)?.stability??NaN},{id:"dyn.ymdControl",group:"Yaw-moment diagram",label:"Control \u2202CN/\u2202\u03B4 at the origin",unit:"1/rad",scale:.5,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymd(t)?.control??NaN},{id:"dyn.trimAy",group:"Yaw-moment diagram",label:"Trim limit \u2014 the fastest corner it can hold",unit:"g",scale:.2,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.ay??NaN},{id:"dyn.trimBeta",group:"Yaw-moment diagram",label:"Body slip at the trim limit",unit:"\xB0",scale:2,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.betaDeg??NaN},{id:"dyn.trimDelta",group:"Yaw-moment diagram",label:"Steer at the trim limit",unit:"\xB0",scale:2,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.deltaDeg??NaN},{id:"dyn.trimControlFrac",group:"Yaw-moment diagram",label:"Control left at the trim limit",unit:"-",scale:.25,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.controlFrac??NaN},{id:"dyn.trimStiffnessFrac",group:"Yaw-moment diagram",label:"Yaw stiffness left at the trim limit",unit:"-",scale:.25,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.stiffnessFrac??NaN}],b1=[...KH,...HH,...zH,...YH,...WH,...jH];function UH(e,t){let r=e.lap(t),n=e.course(t);if(!r||!n)return NaN;let o=n.track.ds,a=0,s=0;for(let i=0;i<r.v.length-1;i++){let c=o[i]??0,l=.5*(r.v[i]+r.v[i+1]);c>0&&l>0&&(a+=c,s+=c/l)}return s>0?a/s:NaN}var g1=[{id:"lap.time",group:"Lap & manoeuvre",label:"Time",unit:"s",scale:.1,scope:"car",cost:"lap",reads:"course",across:"sum",read:(e,t)=>e.lap(t)?.laptime??NaN},{id:"lap.vMean",group:"Lap & manoeuvre",label:"Mean speed",unit:"km/h",scale:2,scope:"car",cost:"lap",reads:"course",across:"harmonic",read:(e,t)=>UH(e,t)*3.6},{id:"lap.vMin",group:"Lap & manoeuvre",label:"Minimum speed",unit:"km/h",scale:2,scope:"car",cost:"lap",reads:"course",across:"min",read:(e,t)=>{let r=e.lap(t);return r?Math.min(...r.v)*3.6:NaN}},{id:"lap.vMax",group:"Lap & manoeuvre",label:"Maximum speed",unit:"km/h",scale:5,scope:"car",cost:"lap",reads:"course",across:"max",read:(e,t)=>{let r=e.lap(t);return r?Math.max(...r.v)*3.6:NaN}},{id:"lap.ayPeak",group:"Lap & manoeuvre",label:"Peak lateral acceleration",unit:"g",scale:.1,scope:"car",cost:"lap",reads:"course",across:"max",read:(e,t)=>{let r=e.lap(t);return r?Math.max(...r.ay.map(Math.abs))/9.81:NaN}},{id:"lap.minStabil",group:"What the car had left",label:"Worst stability reserve",unit:"N\xB7m",scale:50,scope:"car",cost:"lap",reads:"course",across:"min",read:(e,t)=>e.lapReserve(t)?.minStabil??NaN},{id:"lap.understeerFrac",group:"What the car had left",label:"Lap fraction front-limited",unit:"-",scale:.1,scope:"car",cost:"lap",reads:"course",across:"distance",read:(e,t)=>e.lapReserve(t)?.understeerFrac??NaN},{id:"lap.beyondFrac",group:"What the car had left",label:"Beyond the tyre ellipse \u2014 a health warning, not a target",unit:"-",scale:.05,scope:"car",cost:"lap",reads:"course",across:"distance",read:(e,t)=>e.lapReserve(t)?.beyondFrac??NaN}];function XH(e,t){let r=/^(.*?)\s*\(([^)]+)\)\s*$/.exec(e);return r?{label:r[1],unit:r[2]}:{label:e,unit:t?"s":""}}function qH(e){return e==="s"||e==="kWh"?.1:e==="km/h"?2:1}var eD=new WeakMap;function zf(e){let t=eD.get(e);return t||(t=e.metrics.filter(Xu).map(r=>{let{label:n,unit:o}=XH(r.label,r.format==="time");return{id:`event.${e.id}.${r.key}`,group:`Events \xB7 ${e.label}`,groupShort:"Events",label:n,unit:o,scale:qH(o),scope:"car",cost:"session",read:a=>a.session(e.id)?.[r.key]??NaN}}),eD.set(e,t),t)}var y1=yi.flatMap(zf);var Yf=[...c1,...l1,...u1,...f1,...b1,...g1,...y1],$i=Object.fromEntries(Yf.map(e=>[e.id,e]));var tD={all:Yf,byId:$i},rD=new WeakMap;function xr(e=[]){if(e.length===0)return tD;let t=rD.get(e);if(t)return t;let r=Xy(e).filter(n=>!xi(n.id)).flatMap(zf);return t=r.length?{all:[...Yf,...r],byId:{...$i,...Object.fromEntries(r.map(n=>[n.id,n]))}}:tD,rD.set(e,t),t}var ZH=9.81;function Wf(e,t=e.tireModel,r=e.tireModelRear){if(!t)return e;e=JH(e,t,r);let n=e.m.value*ZH/4,o=Ra(e,t,r),a=We(o.front).rollingRadius(n),s=o.rear===o.front?a:We(o.rear).rollingRadius(n),i=e4(e,a,s);if(!(i>0))return e;let c={...e.r_dyn,value:i};return{...e,r_dyn:c,readouts:{...e.readouts,r_dyn:"the fitted tyre\u2019s rolling radius at the static load"}}}function JH(e,t,r){let n=Ra(e,t,r),o=We(n.front).verticalStiffness(),a=n.rear===n.front?o:We(n.rear).verticalStiffness();if(!(o>0&&a>0))return e;let s=o===a?"the fitted tyre\u2019s own vertical rate":`the fitted tyres\u2019 own vertical rates: front ${nD(o)}, rear ${nD(a)} N/mm`;return{...e,...e.tire_vertical_rate?{tire_vertical_rate:{...e.tire_vertical_rate,value:o}}:{},readouts:{...e.readouts,tire_vertical_rate:s}}}var nD=e=>Math.round(e*10)/10;function e4(e,t,r){switch(e.motorPlacement??"rear"){case"front":return t;case"awd":return t>0&&r>0?.5*(t+r):0;default:return r}}var _u=180/Math.PI,Gi=Math.PI/180,t4=.2;function jf(e,t){let r=$(t,e);return ee(r[0]<0?cb(r):r)}var Uf=e=>({side:Math.atan2(e[2],e[0])*_u,plan:Math.atan2(e[1],e[0])*_u}),Xf=(e,t)=>ee([1,Math.tan(t*Gi),Math.tan(e*Gi)]),Nu=e=>Math.abs(e[0])>=t4,qf=(e,t)=>Math.atan(t/Math.max(e,1))*_u,Qf=(e,t)=>Math.tan(t*Gi)*Math.max(e,1);var Io=["side","plan","clock","len"],Rr={uca:{fore:"ucaFront",aft:"ucaRear",ball:"uprightUpper"},lca:{fore:"lcaFront",aft:"lcaRear",ball:"uprightLower"}},Ou={uca:"upper arm",lca:"lower arm"},r4=1,oD=(e,t)=>jf(e[Rr[t].fore],e[Rr[t].aft]);function aD(e){let t=ee($(ib,Q(e,Z(ib,e))));return{e1:t,e2:me(e,t)}}function x1(e,t){let r=oD(e,t);if(!Nu(r))return`the ${Ou[t]}'s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it`;let n=Rr[t],o=Ln(e[n.ball],e[n.fore],r);return Math.hypot(...$(o,e[n.ball]))>=r4?null:`the ${Ou[t]}'s ball joint sits on its own pivot axis, so the arm has no length to swing on`}function so(e,t){let r=Rr[t],n=e[r.ball],o=oD(e,t),a=Ln(n,e[r.fore],o),s=$(a,n),i=Math.hypot(s[0],s[1],s[2]),{e1:c,e2:l}=aD(o),u=i>0?Q(s,1/i):c;return{...Uf(o),clock:Math.atan2(Z(u,l),Z(u,c))*_u,len:i,sFront:Z($(e[r.fore],a),o),sRear:Z($(e[r.aft],a),o)}}function R1(e,t){let r=Xf(e.side,e.plan),{e1:n,e2:o}=aD(r),a=ne(Q(n,Math.cos(e.clock*Gi)),Q(o,Math.sin(e.clock*Gi))),s=ne(t,Q(a,e.len));return{fore:ne(s,Q(r,e.sFront)),aft:ne(s,Q(r,e.sRear))}}function sD(e,t,r,n){let o=Rr[t],a={...so(e,t),[r]:n},{fore:s,aft:i}=R1(a,e[o.ball]);return{...e,[o.fore]:s,[o.aft]:i}}function iD(e,t){return t==="clock"?e.len:Math.abs(e.sFront-e.sRear)/2}function Zf(e,t,r){return t==="len"?r:qf(iD(e,t),r)}function v1(e,t,r){return t==="len"?r:Qf(iD(e,t),r)}var Qa=["side","plan","atY","atZ"],Sn={fore:"rockerPivotA",aft:"rockerPivotB"},n4=5,cD=e=>jf(e.rockerPivotA,e.rockerPivotB);function Ki(e){return Math.hypot(...$(e.rockerPivotB,e.rockerPivotA))<n4?"the rocker\u2019s two pivots are the same point, so there is no axis to describe":Nu(cD(e))?null:"the rocker\u2019s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it"}function _o(e){let t=cD(e),r=Nu(t)?t:[1,0,0],n=e.rockerPivotA,o=ne(n,Q(r,-n[0]/r[0]));return{...Uf(r),atY:o[1],atZ:o[2],sA:Z($(n,o),r),sB:Z($(e.rockerPivotB,o),r)}}function k1(e){let t=Xf(e.side,e.plan),r=[0,e.atY,e.atZ];return{a:ne(r,Q(t,e.sA)),b:ne(r,Q(t,e.sB))}}function lD(e,t,r){if(Ki(e))return e;let{a:n,b:o}=k1({..._o(e),[t]:r});return{...e,rockerPivotA:n,rockerPivotB:o}}var uD=e=>Math.abs(e.sA-e.sB)/2;function M1(e,t,r){return t==="side"||t==="plan"?qf(uD(e),r):r}function S1(e,t,r){return t==="side"||t==="plan"?Qf(uD(e),r):r}var Ur={front:"Front",rear:"Rear"},vr=["x","y","z"],rt=(e,t)=>t==="front"?e.front:e.rear,Bu=(e,t,r)=>t==="front"?{...e,front:r}:{...e,rear:r},mD=[{kind:"inboard",keys:[{key:"ucaFront",label:"UCA front pivot"},{key:"ucaRear",label:"UCA rear pivot"},{key:"lcaFront",label:"LCA front pivot"},{key:"lcaRear",label:"LCA rear pivot"},{key:"tieInner",label:"tie/toe link inner"}]},{kind:"outboard",keys:[{key:"uprightUpper",label:"upper ball joint"},{key:"uprightLower",label:"lower ball joint"},{key:"tieOuter",label:"tie/toe link outer"},{key:"wheelCenter",label:"wheel centre"}]},{kind:"actuation",keys:[{key:"pushrodOuter",label:"push/pull rod outer"},{key:"rockerPivotA",label:"rocker pivot A"},{key:"rockerPivotB",label:"rocker pivot B"},{key:"rockerToPushrod",label:"rocker \u2014 rod end"},{key:"rockerToDamper",label:"rocker \u2014 damper end"},{key:"damperChassis",label:"damper chassis mount"}]}],dD={damperChassis:"strut top mount",pushrodOuter:"strut lower mount"},Za=30;function o4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r).config.layout==="mcpherson";for(let o of mD)for(let{key:a,label:s}of o.keys){let i=n&&dD[a]||s;for(let c=0;c<3;c++)t.push({id:`hp.${r}.${a}.${vr[c]}`,group:`${Ur[r]} hardpoints \u2014 ${o.kind}`,label:`${i} ${vr[c]}`,scope:Ur[r],unit:"mm",defaultSpan:Za,read:l=>rt(l.vehicle,r).hardpoints[a][c],write:(l,u)=>{let m=rt(l.vehicle,r),p=[...m.hardpoints[a]];p[c]=u;let d={...m.hardpoints,[a]:p};return{...l,vehicle:Bu(l.vehicle,r,{...m,hardpoints:d})}}})}}return t}var a4={side:"axis side-view angle",plan:"axis plan-view angle",clock:"arm clock angle",len:"effective arm length"},s4={side:"\xB0",plan:"\xB0",clock:"\xB0",len:"mm"};function i4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r).config.layout==="mcpherson";for(let o of["uca","lca"]){let a=rt(e.vehicle,r).hardpoints,s=x1(a,o)?null:so(a,o);for(let i of Io)t.push({id:`arm.${r}.${o}.${i}`,group:`${Ur[r]} ${n?"arm axes":"wishbone axes"}`,label:`${Ou[o]} \u2014 ${a4[i]}`,scope:Ur[r],unit:s4[i],defaultSpan:s?Zf(s,i,Za):Za,read:c=>so(rt(c.vehicle,r).hardpoints,o)[i],write:(c,l)=>{let u=rt(c.vehicle,r),m=sD(u.hardpoints,o,i,l);return{...c,vehicle:Bu(c.vehicle,r,{...u,hardpoints:m})}}})}}return t}var c4={side:"pivot axis side-view angle",plan:"pivot axis plan-view angle",atY:"pivot axis outboard, at the wheel-centre plane",atZ:"pivot axis height, at the wheel-centre plane"},l4={side:"\xB0",plan:"\xB0",atY:"mm",atZ:"mm"};function u4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r).hardpoints,o=Ki(n)?null:_o(n);for(let a of Qa)t.push({id:`rocker.${r}.${a}`,group:`${Ur[r]} rocker axis`,label:`rocker \u2014 ${c4[a]}`,scope:Ur[r],unit:l4[a],defaultSpan:o?M1(o,a,Za):Za,read:s=>_o(rt(s.vehicle,r).hardpoints)[a],write:(s,i)=>{let c=rt(s.vehicle,r),l=lD(c.hardpoints,a,i);return{...s,vehicle:Bu(s.vehicle,r,{...c,hardpoints:l})}}})}return t}var Jf={front:"heaveFrontDesign",rear:"heaveRearDesign"},Hi={front:"arbFrontDesign",rear:"arbRearDesign"},Vu={front:"rollBarFrontDesign",rear:"rollBarRearDesign"};function m4(e,t){return{heave:e.config.actuation==="decoupled"?"heave element":"third spring",roll:t?.design.kind==="coil"?"roll shock":"anti-roll bar"}}var eh=e=>/^(heave|roll|rollBar)\.(front|rear)\.(outer|inner|anchor)\.[xyz]$/.test(e);function d4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r),o=e.params[Jf[r]],a=e.params[Hi[r]],s=m4(n,a),i=h=>h.params[Jf[r]],c=h=>h.params[Hi[r]],l=(h,b)=>({...h,params:{...h.params,[Jf[r]]:b}}),u=(h,b)=>({...h,params:{...h.params,[Hi[r]]:b}}),m={group:`${Ur[r]} heave & roll elements`,scope:Ur[r]},p=(h,b,g,y,x)=>{for(let R of g)t.push({...m,id:`${h}.${vr[R]}`,label:`${b} ${vr[R]}`,unit:"mm",defaultSpan:Za,read:v=>y(v)[R],write:(v,S)=>{let A=[...y(v)];return A[R]=S,x(v,A)}})},d=(h,b,g,y,x)=>{t.push({...m,id:h,label:b,unit:"N/mm",defaultSpan:Math.max(5,g*.4),read:y,write:x})};if(o?.design.kind==="coil"){if(o.linkage){let h=g=>i(g).linkage;p(`heave.${r}.outer`,`${s.heave} eye`,[0,1,2],g=>h(g).outer,(g,y)=>l(g,{...i(g),linkage:{...h(g),outer:y}})),o.linkage.mount?.kind==="chassis"&&p(`heave.${r}.anchor`,`${s.heave} chassis anchor`,[0,2],g=>h(g).mount.anchor,(g,y)=>l(g,{...i(g),linkage:{...h(g),mount:{kind:"chassis",anchor:y}}}))}if(typeof o.design.rate=="number"){let h=b=>i(b).design;d(`heave.${r}.rate`,`${s.heave} spring rate (@element)`,o.design.rate,b=>h(b).rate,(b,g)=>l(b,{...i(b),design:{...h(b),rate:g}}))}}if(a&&a.design.kind!=="none"){if(a.linkage&&a.design.kind!=="direct"){let b=R=>c(R).linkage,g=Br(n,a.linkage,a.design.kind),[y,x]=g?["left arm eye","right arm eye"]:["drop-link pickup","arm tip"];p(`roll.${r}.outer`,`${s.roll} ${y}`,[0,1,2],R=>b(R).outer,(R,v)=>u(R,{...c(R),linkage:{...b(R),outer:v}})),p(`roll.${r}.inner`,`${s.roll} ${x}`,[0,1,2],R=>b(R).inner,(R,v)=>u(R,{...c(R),linkage:{...b(R),inner:v}}))}let h=a.design;if(h.kind==="coil"&&typeof h.rate=="number"){let b=g=>c(g).design;d(`roll.${r}.rate`,`${s.roll} spring rate (@element)`,h.rate,g=>b(g).rate,(g,y)=>u(g,{...c(g),design:{kind:"coil",rate:y}}))}else h.kind==="direct"&&d(`roll.${r}.wheelRate`,`${s.roll} rate (@wheel)`,h.wheelRate,b=>c(b).design.wheelRate,(b,g)=>u(b,{...c(b),design:{kind:"direct",wheelRate:g}}))}let f=mn(n,a,e.params[Vu[r]]);if(f){let h=g=>g.params[Vu[r]],b=(g,y)=>({...g,params:{...g.params,[Vu[r]]:y}});if(f.linkage&&f.design.kind!=="direct"){let g=y=>h(y).linkage;p(`rollBar.${r}.outer`,"anti-roll bar drop-link pickup",[0,1,2],y=>g(y).outer,(y,x)=>b(y,{...h(y),linkage:{...g(y),outer:x}})),p(`rollBar.${r}.inner`,"anti-roll bar arm tip",[0,1,2],y=>g(y).inner,(y,x)=>b(y,{...h(y),linkage:{...g(y),inner:x}}))}f.design.kind==="direct"&&d(`rollBar.${r}.wheelRate`,"anti-roll bar rate (@wheel)",f.design.wheelRate,g=>h(g).design.wheelRate,(g,y)=>b(g,{...h(g),design:{kind:"direct",wheelRate:y}}))}}return t}var p4=[{axle:"front",field:"springRate",group:"Springs & bars",label:"spring rate (@spring)",unit:"N/mm",fallback:35,span:e=>Math.max(5,e*.4)},{axle:"rear",field:"springRate",group:"Springs & bars",label:"spring rate (@spring)",unit:"N/mm",fallback:40,span:e=>Math.max(5,e*.4)},{axle:"front",field:"rackTravel",group:"Steering",label:"rack travel from centre",unit:"mm",fallback:35,span:()=>15,frontOnly:!0},{axle:"front",field:"rackRatio",group:"Steering",label:"rack per steering-wheel turn",unit:"mm/rev",fallback:55,span:()=>15,frontOnly:!0},{axle:"front",field:"loadedRadius",group:"Wheel & tyre",label:"loaded radius",unit:"mm",fallback:228,span:()=>15},{axle:"rear",field:"loadedRadius",group:"Wheel & tyre",label:"loaded radius",unit:"mm",fallback:228,span:()=>15}];function f4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r).compliance;if(!n)continue;let o=(a,s,i,c)=>{let l=i(n);l===void 0||!(l>0)||!Number.isFinite(l)||t.push({id:`kc.${r}.${a}`,group:"Compliance",label:s,scope:Ur[r],unit:"N/mm",defaultSpan:Math.max(500,l*.4),read:u=>i(rt(u.vehicle,r).compliance??{})??l,write:(u,m)=>{let p=rt(u.vehicle,r),d={...p,compliance:c(p.compliance??{},Math.max(1,m))};return{...u,vehicle:Bu(u.vehicle,r,d)}}})};for(let a of["ucaFront","ucaRear","lcaFront","lcaRear","tieRod","pushRod"])o(`link.${a}`,`${h4[a]} (link)`,s=>s.links?.[a],(s,i)=>({...s,links:{...s.links,[a]:i}}));for(let a of["ucaFront","ucaRear","lcaFront","lcaRear","tieInner","topMount"])o(`bush.${a}`,`${b4[a]} (bushing)`,s=>s.bushings?.[a],(s,i)=>({...s,bushings:{...s.bushings,[a]:i}}));r==="front"&&o("rack","rack to housing",a=>a.rack,(a,s)=>({...a,rack:s}))}return t}var h4={ucaFront:"UCA front leg",ucaRear:"UCA rear leg",lcaFront:"LCA front leg",lcaRear:"LCA rear leg",tieRod:"tie rod",pushRod:"push/pull rod"},b4={ucaFront:"UCA front pickup",ucaRear:"UCA rear pickup",lcaFront:"LCA front pickup",lcaRear:"LCA rear pickup",tieInner:"tie-rod inner",topMount:"strut top mount"};function g4(){return p4.map(e=>({id:`cfg.${e.axle}.${e.field}`,group:e.group,label:e.label,scope:Ur[e.axle],unit:e.unit,defaultSpan:e.span(e.fallback),read:t=>rt(t.vehicle,e.axle).config[e.field]??e.fallback,write:(t,r)=>{let n=rt(t.vehicle,e.axle),o={...n,config:{...n.config,[e.field]:r}};return{...t,vehicle:Bu(t.vehicle,e.axle,o)}}}))}function y4(e){let t=Jo(e.params.steeringSystem);if(!t.enabled)return[];let r=(n,o,a,s,i)=>({id:`steeringSystem.${n}`,group:"Steering",label:o,unit:a,defaultSpan:s,read:c=>Jo(c.params.steeringSystem)[n],write:(c,l)=>({...c,params:{...c.params,steeringSystem:Jo({...c.params.steeringSystem,enabled:!0,[n]:i(l)})}})});return[r("roadFeedbackGain","road feedback gain","\xD7",Math.max(.1,.25*t.roadFeedbackGain),n=>Math.min(2,Math.max(0,n))),r("turnInFrictionNm","turn-in friction","N\xB7m",Math.max(.1,.5*t.turnInFrictionNm),n=>Math.max(0,n))]}function x4(e){let t=xa(e.params),r=[];for(let n of["front","rear"]){if(t[n]!=="diff")continue;let o=ya(e.params.driveline?.[n]);if(o?.kind!=="clutch"&&o?.kind!=="torsen")continue;let a=(s,i)=>{let c=Ud[`${n}.${s}`];return{id:`driveline.${n}.${s}`,group:"Differential",label:c.label.charAt(0).toLowerCase()+c.label.slice(1),scope:Ur[n],unit:c.unit===": 1"?"":c.unit??"",defaultSpan:i,read:l=>ya(l.params.driveline?.[n])?.[s],write:(l,u)=>({...l,params:{...l.params,driveline:jd({...l.params.driveline,[n]:{...l.params.driveline?.[n],[s]:u}})}})}};o.kind==="clutch"?r.push(a("preloadNm",Math.max(5,.2*o.preloadNm)),a("rampDriveDeg",5),a("rampCoastDeg",5)):r.push(a("tbrDrive",Math.max(.25,.2*o.tbrDrive)),a("tbrCoast",Math.max(.25,.2*o.tbrCoast)))}return r}function R4(e){if(Uc(e.params)!=="hydraulic")return[];let t=[{id:"brakeSetup.barFront",group:"Brakes",label:`${d0("barFront").toLowerCase()}, front share`,unit:"-",defaultSpan:.05,read:a=>$n(a.params.brakeSetup).barFront,write:(a,s)=>({...a,params:{...a.params,brakeSetup:$n({...$n(a.params.brakeSetup),barFront:s})}})}];if(!e.params.brakeModel)return t;let r=sn(e.params.brakeModel),n=(a,s)=>s.circuit?a[s.circuit][s.key]:a[s.key],o=(a,s,i)=>({id:`brakeModel.${a.circuit?`${a.circuit}.`:""}${String(a.key)}`,group:"Brakes",label:m0(a.circuit?`${a.circuit}.${String(a.key)}`:a.key),unit:s,defaultSpan:i,read:c=>n(sn(c.params.brakeModel),a),write:(c,l)=>{let u=sn(c.params.brakeModel),m=a.circuit?{...u,[a.circuit]:{...u[a.circuit],[a.key]:l}}:{...u,[a.key]:l};return{...c,params:{...c.params,brakeModel:sn(m)}}}});return t.push(o({key:"masterFrontMm"},"mm",1.5),o({key:"masterRearMm"},"mm",1.5),o({key:"pedalRatio"},"-",.5),o({key:"pistonDiaMm",circuit:"front"},"mm",2),o({key:"pistonDiaMm",circuit:"rear"},"mm",2),o({key:"effRadiusMm",circuit:"front"},"mm",10),o({key:"effRadiusMm",circuit:"rear"},"mm",10)),r.valve!=="none"&&t.push(o({key:"valveKneeBar"},"bar",5)),r.valve==="proportioning"&&t.push(o({key:"valveSlope"},"-",.1)),t}var pD=e=>!!e&&typeof e=="object"&&"value"in e&&"label"in e;function fD(e){let t={...e};for(let r of Object.keys(t)){let n=t[r];pD(n)&&(t[r]={...n})}return t}function v4(e){let t=[];for(let r of Hw(e))for(let n of r.rows){let o=Math.abs(n.value);t.push({id:`param.${n.key}`,group:r.title,label:n.label,unit:n.unit,defaultSpan:o>0?o*.2:1,read:a=>{let s=a.params[n.key];return pD(s)?s.value:NaN},write:(a,s)=>{let i=fD(a.params);return si(i,n.label,s),{...a,params:i}}})}return t}function hD(e){let t={};for(let i of["front","rear"]){if(!rt(e.vehicle,i).measured)continue;let l="this axle is described by measured curves, so its linkage is not solved";for(let u of mD)for(let{key:m}of u.keys)for(let p of vr)t[`hp.${i}.${m}.${p}`]={why:l};for(let u of["uca","lca"])for(let m of Io)t[`arm.${i}.${u}.${m}`]={why:l};for(let u of Qa)t[`rocker.${i}.${u}`]={why:l};for(let u of["heave.outer","heave.anchor","roll.outer","roll.inner","rollBar.outer","rollBar.inner"]){let[m,p]=u.split(".");for(let d of vr)t[`${m}.${i}.${p}.${d}`]={why:l}}t[`cfg.${i}.springRate`]={why:"the measured curve set carries its own spring rate"}}let r=["rockerPivotA","rockerPivotB","rockerToPushrod","rockerToDamper"];for(let i of["front","rear"]){if(rt(e.vehicle,i).config.actuation!=="direct")continue;let c="this axle is direct-acting \u2014 there is no bell-crank";for(let l of r)for(let u of vr)t[`hp.${i}.${l}.${u}`]={why:c};for(let l of Qa)t[`rocker.${i}.${l}`]={why:c}}for(let i of["front","rear"]){let c=rt(e.vehicle,i);if(c.measured||c.config.actuation!=="decoupled")continue;let l="this axle is decoupled \u2014 the corner damper is out of circuit";for(let u of["rockerToDamper","damperChassis"])for(let m of vr)t[`hp.${i}.${u}.${m}`]={why:l,useInstead:`heave.${i}.outer.${m}`};t[`cfg.${i}.springRate`]={why:"a decoupled axle has no corner spring \u2014 its elements hold it up",useInstead:`heave.${i}.rate`}}for(let i of["front","rear"]){let c=rt(e.vehicle,i),l=e.params[Jf[i]]?.linkage;if(c.measured||!l||l.attach!=="rocker"||l.mount?.kind==="chassis")continue;let u=c.hardpoints,m=[0,1,2].map(d=>u.rockerPivotB[d]-u.rockerPivotA[d]),p=Math.hypot(m[0],m[1],m[2]);if(p>0)for(let d=0;d<3;d++)Math.abs(m[d]/p)<1-1e-12||(t[`heave.${i}.outer.${vr[d]}`]={why:`the rocker shaft runs along ${vr[d]} \u2014 this only slides the eye along it`})}for(let i of["front","rear"]){let c=rt(e.vehicle,i);if(c.measured)continue;let l=e.params[Hi[i]],u=[["roll",l],["rollBar",mn(c,l,e.params[Vu[i]])]];for(let[m,p]of u){let d=p?.linkage;if(!p||!d||p.design.kind==="none"||p.design.kind==="direct"||Br(c,d,p.design.kind))continue;let f=[0,1,2].map(b=>d.inner[b]-d.outer[b]),h=Math.hypot(f[0],f[1],f[2]);if(h>0)for(let b=0;b<3;b++)Math.abs(f[b]/h)<1-1e-12||(t[`${m}.${i}.inner.${vr[b]}`]={why:`the drop link runs along ${vr[b]} \u2014 this only changes its length`})}}for(let i of["front","rear"]){let c=rt(e.vehicle,i);if(c.measured||c.config.layout!=="mcpherson")continue;let l="this axle is a McPherson strut \u2014 there is no upper arm";for(let u of["ucaFront","ucaRear","uprightUpper"])for(let m of vr)t[`hp.${i}.${u}.${m}`]={why:l,useInstead:`hp.${i}.damperChassis.${m}`};for(let u of Io)t[`arm.${i}.uca.${u}`]={why:l};for(let u of["link.ucaFront","link.ucaRear","bush.ucaFront","bush.ucaRear"])t[`kc.${i}.${u}`]={why:l}}for(let i of["front","rear"]){let c=rt(e.vehicle,i);if(c.measured)continue;for(let u of["uca","lca"]){if(u==="uca"&&c.config.layout==="mcpherson")continue;let m=x1(c.hardpoints,u);if(m)for(let p of Io)t[`arm.${i}.${u}.${p}`]={why:m,useInstead:`hp.${i}.${Rr[u].fore}.z`}}let l=Ki(c.hardpoints);if(l&&c.config.actuation!=="direct")for(let u of Qa)t[`rocker.${i}.${u}`]={why:l,useInstead:`hp.${i}.${Sn.fore}.z`}}let n=[["arbFrontDesign","param.arb_front","the front anti-roll bar design in Vehicle Dynamics","front","roll"],["arbRearDesign","param.arb_rear","the rear anti-roll bar design in Vehicle Dynamics","rear","roll"],["heaveFrontDesign","param.heave_spring_front","the front third-spring design","front","heave"],["heaveRearDesign","param.heave_spring_rear","the rear third-spring design","rear","heave"]];for(let[i,c,l,u,m]of n){let p=e.params[i];if(!p?.design)continue;if(p.design.kind==="none"){m==="heave"&&(t[c]={why:`the ${u} heave element is None`});continue}let d=p.design.kind==="direct"?`${m}.${u}.wheelRate`:`${m}.${u}.rate`;t[c]={why:`computed from ${l}`,useInstead:d}}for(let i of["front","rear"]){let c=`param.arb_${i}`;if(t[c])continue;let l=mn(rt(e.vehicle,i),e.params[Hi[i]],e.params[Vu[i]]);l&&(t[c]={why:`computed from the ${i} anti-roll bar beside the roll element`,...l.design.kind==="direct"?{useInstead:`rollBar.${i}.wheelRate`}:{}})}for(let i of["front","rear"]){let c=`param.arb_${i}`;!t[c]&&e.params[Hi[i]]?.design.kind==="none"&&(t[c]={why:`the ${i} roll element is None`})}let o=e.params.aeroModelId||e.params.aeroModel?ey:ty;for(let[i,c]of Object.entries(o))t[`param.${i}`]={why:c};if(e.params.batteryModelId||e.params.batteryModel)for(let[i,c]of Object.entries(qd))t[`param.${i}`]={why:c};for(let[i,c]of Object.entries(Qd(e.params)))t[`param.${i}`]={why:c};let a={...Wf(e.params).readouts,...e.sessionAir?{rho:Wp}:{}};for(let[i,c]of Object.entries(a)){let l=`param.${i}`;!(l in t)&&!(l in gD)&&(t[l]={why:c})}for(let[i,c]of Object.entries(ry(e.params)))t[`param.${i}`]={why:c};let s=Uc(e.params)==="hydraulic";for(let[i,c]of Object.entries(dd(e.params)))t[`param.${i}`]=s?{why:c,useInstead:"brakeSetup.barFront"}:{why:c};return t}function bD(e){let t={...gD,...hD(e)};for(let[n,o]of Object.entries(t))o.useInstead&&t[o.useInstead]&&(t[n]={why:o.why});let r=n=>{let o=t[n.id];return o?{...n,supersededBy:o}:n};return[...o4(e),...i4(e),...u4(e),...d4(e),...g4(),...y4(e),...R4(e),...x4(e),...f4(e),...v4(e.params)].map(r)}var k4={spring_front:"cfg.front.springRate",spring_rear:"cfg.rear.springRate"},gD=Object.fromEntries(Object.entries(J0).map(([e,t])=>[`param.${e}`,{why:t,useInstead:k4[e]}])),dt=e=>e.scope?`${e.scope} \xB7 ${e.label}`:e.label;function gt(e){let t={};for(let n of bD(e))t[n.id]=n;let r=(n,o)=>{if(typeof o!="string")return;let a=EL(n,o);return a&&(n[o]=a),a};return new Proxy(t,{get:(n,o,a)=>typeof o=="string"&&!Object.hasOwn(n,o)?r(n,o)??Reflect.get(n,o,a):Reflect.get(n,o,a),has:(n,o)=>Reflect.has(n,o)||!!r(n,o)})}var A1=e=>e.step!==void 0&&Number.isFinite(e.step)&&e.step>0?e.step:0,w1=e=>A1(e)>0||(e.values?.length??0)>0,F1=e=>e.some(w1),yD=e=>1e-9*Math.max(1,Math.abs(e.lo),Math.abs(e.hi));function xD(e,t){if(!Number.isFinite(t))return t;if(e.values?.length){let s=e.values[0];for(let i of e.values)Math.abs(i-t)<Math.abs(s-t)&&(s=i);return s}let r=A1(e);if(!r||!Number.isFinite(e.start))return t;let n=yD(e),o=Math.round((t-e.start)/r),a=s=>e.start+s*r;return a(o)>e.hi+n&&a(o-1)>=e.lo-n?a(o-1):a(o)<e.lo-n&&a(o+1)<=e.hi+n?a(o+1):a(o)}var RD=(e,t)=>t.map((r,n)=>e[n]&&w1(e[n])?xD(e[n],r):r);function C1(e,t=1e3){if(e.values?.length)return e.values.length;let r=A1(e);if(!r||!Number.isFinite(e.start))return 1/0;let n=yD(e),o=Math.ceil((e.lo-n-e.start)/r),a=Math.floor((e.hi+n-e.start)/r);return Math.max(0,Math.min(t,a-o+1))}function T1(e,t,r){let n=RD(e.variables,t),o=n.every((a,s)=>a===t[s]);return{x:n,score:o?r:On(e,n)}}function D1(e,t){if(!e.variables.some(vD))return e;let r=e.variables.filter(o=>o.follows&&!o.fixed).map(o=>({id:o.id,follows:o.follows})),n=e.variables.filter(o=>!o.fixed&&!o.follows).map(o=>{if(kD(o))return{...o,lo:Math.min(...o.values),hi:Math.max(...o.values)};if(!o.around)return o;let{around:a,fixed:s,...i}=o,c=t(o.id);return Number.isFinite(c)?{...i,lo:c-a.minus,hi:c+a.plus}:i});return r.length?{...e,variables:n,followers:r}:{...e,variables:n}}var vD=e=>!!(e.fixed||e.around||e.follows)||kD(e),kD=e=>!!e.values?.length&&(e.lo!==Math.min(...e.values)||e.hi!==Math.max(...e.values));function Kt(e,t){if(!t.variables.some(vD))return t;let r=gt(e);return D1(t,n=>{let o=r[n];if(!o)return NaN;try{return o.read(e)}catch{return NaN}})}var rh=()=>({variables:[],constraints:[],objectives:[],watches:[],density:{...Di},envelope:{...Cu},operating:{...Si},lap:hf()});function Xr(e){return[...e.objectives,...e.constraints,...e.watches??[]]}var nh=e=>(e.metrics??xr()).byId;function E1(e,t){t=Kt(e,t);let r=gt(e),n=[];for(let o of t.variables){let a=r[o.id];a&&n.push({id:a.id,name:dt(a),unit:a.unit,lo:o.lo,hi:o.hi,start:a.read(e),...o.step!==void 0?{step:o.step}:{},...o.values?{values:o.values}:{}})}return n}function zi(e,t,r){t=Kt(e,t);let n=gt(e),o=e;return t.variables.forEach((a,s)=>{let i=n[a.id];i&&Number.isFinite(r[s])&&(o=i.write(o,r[s]))}),N1(e,o,t.followers,n)}function I1(e,t,r={}){let n=t.states??[],o=n.some(c=>c.follows);if(!o&&!t.envelopeFollows)return t;let a=Eo(e,{density:t.density,envelope:t.envelope,states:n,operating:t.operating,lap:t.lap,assemble:r.assemble,simParams:r.simParams,projectTrack:r.projectTrack,libraryTrack:r.libraryTrack,numerics:r.numerics}),s=n;if(o&&r.simParams)try{let c=a.ggv();c&&(s=Yx(n,c,A4(r)))}catch{s=n}let i=t.envelope;if(t.envelopeFollows&&s.length){let c=s.map(h=>a.poseAt(h)).filter(h=>h!==null),l=nh(r),u=_1(t,l),m=Xr(t).map(h=>({r:h,m:l[h.metricId]})).filter(({m:h})=>h&&h.id.startsWith("kin.")&&h.reads!=="state"&&(h.scope==="car"||u.includes(h.scope))),p=h=>{let b=Eo(e,{density:t.density,envelope:h,assemble:r.assemble,numerics:r.numerics});return m.every(({r:g,m:y})=>Number.isFinite(vt(b,y,g.at)))},d=c.length===s.length?S4(e,jx(c,u),u):null,f=d&&m.length?M4(d,p):d;f&&!Ux(f,t.envelope)&&(i=f)}return s===n&&i===t.envelope?t:{...t,states:s,envelope:i}}var th=3;function M4(e,t){let r=(c,l)=>t({...e,travelMin:c,travelMax:l}),n=e.travelMin-th,o=e.travelMax+th;if(r(n,o))return e;let a=(c,l,u)=>{for(;Math.abs(l-c)>1;){let m=Math.round((c+l)/2);u(m)?c=m:l=m}return c};if(r(n,1))o=a(1,o,c=>r(n,c));else if(r(-1,1))n=a(-1,n,c=>r(c,1)),o=a(1,o,c=>r(n,c));else return e;let s=Math.min(-1,Math.max(e.travelMin,n+th)),i=Math.max(1,Math.min(e.travelMax,o-th));return s===e.travelMin&&i===e.travelMax?e:{...e,travelMin:s,travelMax:i}}function _1(e,t){let r=new Set;for(let n of Xr(e)){let o=t[n.metricId];if(!(!o||!o.id.startsWith("kin.")||o.reads==="state")){if(o.scope==="car")return["front","rear"];r.add(o.scope)}}return r.size?["front","rear"].filter(n=>r.has(n)):["front","rear"]}function S4(e,t,r){if(!t)return null;let n=Ei(e.vehicle,e.params),{travelMin:o,travelMax:a}=t;for(let s of r.map(i=>n[i]))try{let i=ut(s,{travelMin:o,travelMax:a,steps:Di.travelSteps});if(i.covered)continue;let c=i.samples.filter(l=>l.converged).map(l=>l.travel);if(!c.length)continue;o=Math.max(o,Math.min(-1,Math.ceil(Math.min(...c))+1)),a=Math.min(a,Math.max(1,Math.floor(Math.max(...c))-1))}catch{continue}return o===t.travelMin&&a===t.travelMax?t:{...t,travelMin:o,travelMax:a}}function A4(e){let t=e.projectTrack?.();if(!t)return null;try{return zx($t(t.asset,t.numerics))}catch{return null}}function N1(e,t,r,n){if(!r?.length)return t;let o=t;for(let a of r){let s=n[a.id],i=n[a.follows];if(!s||!i)continue;let c=i.read(t)-i.read(e);Number.isFinite(c)&&c!==0&&(o=s.write(o,s.read(e)+c))}return o}function No(e,t){if(!Number.isFinite(t))return NaN;if(e.op==="max")return t-e.limit;if(e.op==="min")return e.limit-t;let r=e.limit2??e.limit;return Math.max(e.limit-t,t-r)}var MD=(e,t="")=>t&&t!=="-"?`${e} ${t}`:`${e}`;function SD(e,t,r){let n=t??$i[e.metricId],o=(n?bt(n):e.metricId)+Ja(e.at,n,r),a=s=>MD(s,n?.unit);return e.op==="max"?`${o} \u2264 ${a(e.limit)}`:e.op==="min"?`${o} \u2265 ${a(e.limit)}`:`${o} between ${e.limit} and ${a(e.limit2??e.limit)}`}function Ja(e,t,r){if(!e&&t?.reads!=="state")return"";e??={};let n=[];if(t?.reads==="state")if(e.stateId===Rn)n.push(a1(t));else{let o=e.stateId===void 0?r?.states?.[0]:r?.states?.find(a=>a.id===e.stateId);o&&n.push(o.name)}if(e.speed!==void 0&&n1(t)&&n.push(`${(e.speed*3.6).toFixed(0)} km/h`),e.ayG!==void 0&&o1(t)&&n.push(`${e.ayG.toFixed(2)} g`),e.courseId===Du&&t?.reads==="course")n.push(r1(t));else if(e.courseId&&t?.reads==="course"){let o=r?.lap.courses.find(a=>a.id===e.courseId);o&&n.push(sR(o))}return n.length?` @ ${n.join(", ")}`:""}function AD(e,t,r){let n=r/t.scale;return e.goal==="min"?e.weight*n:e.goal==="max"?-e.weight*n:e.weight*Math.max(0,Math.abs(r-(e.target??0))-Math.max(0,e.tolerance??0))/t.scale}var wD=5e-4;function FD(e,t){return e.cost!=="lap"&&e.cost!=="session"?0:Number.isFinite(t)?wD*Math.abs(t):0}function oh(e,t,r={}){return Eo(e,{density:t.density,envelope:t.envelope,states:t.states,operating:t.operating,lap:t.lap,assemble:r.assemble,simParams:r.simParams,projectTrack:r.projectTrack,libraryTrack:r.libraryTrack,sessionParams:r.sessionParams,session:r.session,numerics:r.numerics})}function es(e,t,r={}){t=Kt(e,t);let n=E1(e,t),o=gt(e),a=nh(r),s=t.constraints.map(m=>({spec:m,metric:a[m.metricId]})).filter(m=>!!m.metric),i=s.filter(m=>m.metric.cost==="geometry"),c=s.filter(m=>m.metric.cost!=="geometry"),l=t.objectives.map(m=>({spec:m,metric:a[m.metricId]})).filter(m=>!!m.metric),u=(m,p)=>{let d=0,f=[];for(let{spec:h,metric:b}of m){let g=vt(p,b,h.at);if(!Number.isFinite(g))return{ok:!1,violation:p.failure?.violation??400,reason:p.failure?.reason??`${bt(b)} could not be computed`};let y=No(h,g);y>0&&(d+=y/b.scale,f.push(`${SD(h,b,t)} (${MD(g.toFixed(3),b.unit)})`))}return f.length===0?Nc:{ok:!1,violation:d,reason:f.join("; ")}};return{name:"study",variables:n,build:m=>{let p=e;return t.variables.forEach((d,f)=>{let h=o[d.id];h&&(p=h.write(p,m[f]))}),p=N1(e,p,t.followers,o),{car:p,ev:oh(p,t,r)}},feasible:({ev:m})=>{let p=u(i,m);if(!p.ok)return p;for(let{spec:d,metric:f}of c)vt(m,f,d.at);for(let{spec:d,metric:f}of l)vt(m,f,d.at);return m.failure?{ok:!1,violation:m.failure.violation,reason:m.failure.reason}:u(c,m)},terms:({ev:m})=>l.map(({spec:p,metric:d})=>{let f=vt(m,d,p.at);return{name:bt(d)+Ja(p.at,d,t),raw:f,unit:d.unit,weight:p.weight,contribution:AD(p,d,f),resolution:Math.abs(p.weight)*FD(d,f)/d.scale}})}}function P1(e){let t=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(t)return`${t[1]}.${t[2]}`;let r=/^rocker\.(front|rear)\./.exec(e);if(r)return`${r[1]}.rocker`;let n=/^hp\.(front|rear)\.(ucaFront|ucaRear|lcaFront|lcaRear|rockerPivotA|rockerPivotB)\./.exec(e);return n?n[2].startsWith("rocker")?`${n[1]}.rocker`:`${n[1]}.${n[2].startsWith("uca")?"uca":"lca"}`:null}function CD(e,t){if(e.variables.some(o=>o.id===t))return!0;let r=Ua(t);if(!r||!_i.includes(r.axis))return!1;if(e.variables.some(o=>Pr(o.id)?.point===r.point))return!0;let n=P1(t);return!!n&&e.variables.some(o=>/^(arm|rocker)\./.test(o.id)&&P1(o.id)===n)}function w4(e,t){let r=e.followers??[],n=new Map(r.map(i=>[i.id,i.follows])),o=i=>{let c=t[i],l=Ua(i);return c&&l&&_i.includes(l.axis)?{name:dt({...c,label:c.label.replace(/ [xyz]$/,"")}),axis:l.axis}:{name:c?dt(c):`\u201C${i}\u201D`}},a=new Map,s=(i,c,l)=>{let u=a.get(i);u||a.set(i,u={text:l,axes:[]}),c&&u.axes.push(c)};for(let i of r){let c=t[i.id],l=t[i.follows],u=o(i.id),m=o(i.follows),p=d=>d&&d!=="x, y, z"?` in ${d}`:"";if(!c){s(`missing:${i.id}`,void 0,()=>`\u201C${i.id}\u201D is not a variable this car has.`);continue}if(c.supersededBy&&s(`superseded:${u.name}`,u.axis,d=>`${u.name}${p(d)} cannot be moved: ${c.supersededBy.why}.`),!l)s(`no-lead:${u.name}:${i.follows}`,u.axis,d=>`${u.name}${p(d)} moves with \u201C${i.follows}\u201D, which is not a variable this car has.`);else if(i.follows===i.id)s(`self:${u.name}`,u.axis,d=>`${u.name}${p(d)} cannot move with itself.`);else if(l.unit!==c.unit)s(`unit:${u.name}:${m.name}`,u.axis,d=>`${u.name}${p(d)} moves with ${m.name}, which is in ${l.unit} where it is in ${c.unit}. Link it to one in the same unit.`);else if(n.has(i.follows)){let d=o(n.get(i.follows));s(`chain:${u.name}:${m.name}`,u.axis,f=>`${u.name}${p(f)} moves with ${m.name}, which itself moves with ${d.name}. Link it to ${d.name}.`)}else CD(e,i.follows)||s(`still:${u.name}:${m.name}`,u.axis,d=>`${u.name}${p(d)} moves with ${m.name}, which the study does not move${p(d)}. Free that one, or give this its own bound.`)}return[...a.values()].map(i=>i.text(i.axes.join(", ")))}function O1(e,t,r={}){let n=t.variables.length>0&&t.variables.every(y=>y.fixed||y.follows),o=t.variables.some(y=>y.follows&&!y.fixed);t=Kt(e,t);let a=gt(e),s=[],i=nh(r),c=Xr(t).map(y=>y.metricId),l=c.some(y=>y.startsWith("dyn.")),u=c.some(y=>y.startsWith("lap."));if(c.some(y=>y.startsWith("kin."))){let y=t.envelope;y.travelMin<0&&y.travelMax>0||s.push("The travel the linkage is read over must reach both ways from the design ride: droop below zero, bump above."),(!(y.rollMaxDeg>0)||!(y.rollAtLimitDeg>=0))&&s.push("The roll the linkage is read over must be above zero.")}let m=Xr(t).filter(y=>i[y.metricId]?.reads==="state");if(m.length){let y=t.states??[];if(!y.length)s.push("This study reads targets at a state and has none. Take the car\u2019s five under Conditions.");else{let x=new Set([...y.map(R=>R.id),Rn]);for(let R of m){let v=i[R.metricId];if(R.at?.stateId&&!x.has(R.at.stateId))s.push(`${bt(v)} names a state this study no longer has. Point it at one of the states under Conditions.`);else if(R.at?.stateId===Rn&&!v.acrossStates)s.push(`${bt(v)} is read at one state at a time, not over every state.`);else if(v.appliesAt){let S=R.at?.stateId&&R.at.stateId!==Rn?y.find(F=>F.id===R.at.stateId):void 0,A=S?d1(v,S):null;A?s.push(`${bt(v)} ${A}. Point it at a state that does.`):!S&&!Kf(v,y)&&s.push(`${bt(v)} has no state to be read at: ${v.appliesAt(y[0])} in every state of this study.`)}}}r.assemble||s.push("This study reads targets at a state, and nothing here can assemble the car to find its pose.")}for(let y of t.states??[])(!(y.speedKmh>=0)||!Number.isFinite(y.ayG)||!Number.isFinite(y.axG))&&s.push(`The state \u201C${y.name}\u201D needs a speed of zero or more and finite accelerations.`),y.weight>0||s.push(`The state \u201C${y.name}\u201D needs a weight above zero.`);if(l&&!r.assemble&&s.push("This study reads whole-car metrics, and nothing here can assemble the car to read them from."),u&&!r.simParams&&s.push("This study reads lap metrics, and nothing here can prepare the car for a lap."),u&&!t.lap.courses.length&&s.push("This study reads lap metrics and has no course to drive. Add one under \u201CWhat the car drives\u201D."),u&&t.lap.courses.some(y=>y.course.kind==="project")&&!r.projectTrack?.()&&s.push("This study laps the project\u2019s track, and the project has none. Pick a manoeuvre, or load a track."),u)for(let y of t.lap.courses)y.course.kind==="track"&&!r.libraryTrack?.(y.course.trackId)&&s.push(`This study drives ${y.course.name}, which is not in the project\u2019s tracks, or has not loaded yet.`);let p=new Set([...t.lap.courses.map(y=>y.id),Du]);for(let y of Xr(t))if(y.at?.courseId&&!p.has(y.at.courseId)){let x=i[y.metricId];s.push(`${x?bt(x):y.metricId} names a course this study no longer has. Point it at one of the courses below.`)}u&&t.lap.ggvMode==="fast"&&t.variables.some(x=>/arb_|spring|heave_|front_mass_diss|cg_height|chassis_torsion|^hp\.|^roll\.|^rollBar\./.test(x.id.replace("param.","")))&&s.push("The fast grip envelope is a point mass: no load transfer, no trim. It cannot see bars, springs, roll centres, the chassis\u2019s twist or where the mass sits, and this study moves at least one of those."),n?s.push(o?"Every variable is fixed or moves with another \u2014 there is nothing to search.":"Every variable is fixed \u2014 there is nothing to search."):t.variables.length===0&&s.push("No variables selected \u2014 there is nothing to search."),t.objectives.length===0&&s.push("No objective selected. Constraints alone say which designs are legal, not which is better.");for(let y of t.variables){let x=a[y.id];if(!x){s.push(`\u201C${y.id}\u201D is not a variable this car has.`);continue}if(y.values&&y.values.length<2?s.push(`${dt(x)}: list two values or more, or fix it where it is.`):y.hi>y.lo?y.step!==void 0&&C1({...y,start:x.read(e)})<2&&s.push(`${dt(x)}: a step of ${y.step} ${x.unit} leaves no other place to land in its box. Make the step finer or the box wider, or fix it.`):s.push(`${dt(x)}: the upper bound must be above the lower one (${y.lo} to ${y.hi}).`),x.supersededBy){let v=x.supersededBy.useInstead?a[x.supersededBy.useInstead]:void 0,S=v?dt(v):void 0;s.push(`${dt(x)} cannot be searched: ${x.supersededBy.why}.`+(S?` Use ${S} instead.`:""))}let R=x.read(e);Number.isFinite(R)&&(R<y.lo||R>y.hi)&&s.push(`${dt(x)} starts at ${R.toFixed(1)} ${x.unit}, outside its own bounds.`)}let d=t.followers??[],f=new Map;for(let y of[...t.variables.map(x=>x.id),...d.map(x=>x.id)]){let x=P1(y);if(!x)continue;let R=f.get(x);R||f.set(x,R={arms:[],coords:[]}),(/^(arm|rocker)\./.test(y)?R.arms:R.coords).push(y)}for(let[y,x]of f){if(x.arms.length===0||x.coords.length===0)continue;let R=S=>a[S]?dt(a[S]):S,v=y.endsWith("rocker")?"rocker":`${y.endsWith("uca")?"upper":"lower"} arm`;s.push(`${y.startsWith("front")?"The front":"The rear"} ${v} is being moved two ways at once \u2014 as an axis (${x.arms.map(R).join(", ")}) and as pivot coordinates (${x.coords.map(R).join(", ")}). They describe the same ${v}, so whichever is applied second overwrites the other. Keep one.`)}let h=new Map,b=new Set(d.map(y=>y.id));for(let y of[...t.variables.map(x=>x.id),...b]){let x=Ua(y);if(!x)continue;let R=Pr(y),v=b.has(y)?"with":R?`${R.shape.kind}:${y.slice(y.lastIndexOf(".")+1).replace(/[uv]$/,"")}`:"axes",S=h.get(x.point);S||h.set(x.point,S=new Set),S.add(v)}for(let[y,x]of h){if(x.size<2||x.size===2&&x.has("axes")&&x.has("with"))continue;let R=[...x].map(w=>w.split(":")[0]),v=w=>R.filter(T=>T===w).length,S=[v("axes")?"in its axes":"",v("line")===1?"along a line":v("line")>1?"along two lines":"",v("plane")===1?"in a plane":v("plane")>1?"in two planes":"",v("with")?"with another point":""].filter(Boolean),A=a[`${y}.x`],F=A?dt({...A,label:A.label.replace(/ x$/,"")}):y;s.push(`${F} is moved more than one way at once \u2014 ${S.join(" and ")}. Each write moves it off the other's, so keep one.`)}s.push(...w4(t,a));for(let y of t.constraints){let x=i[y.metricId];if(!x){s.push(`\u201C${y.metricId}\u201D is not a metric.`);continue}y.op==="band"&&!((y.limit2??y.limit)>y.limit)&&s.push(`${bt(x)}: the band's upper limit must be above its lower one.`)}l&&!(t.operating.speed>0)&&s.push("Whole-car metrics need a speed to be read at; a yaw-moment diagram at rest is degenerate.");for(let y of Xr(t))if(y.at?.speed!==void 0&&!(y.at.speed>0)){let x=i[y.metricId];s.push(`${x?bt(x):y.metricId} is asked for at rest, where a yaw-moment diagram is degenerate.`)}for(let y of t.watches??[])i[y.metricId]||s.push(`\u201C${y.metricId}\u201D is not a metric.`);let g=new Set;for(let y of Xr(t)){let x=i[y.metricId],R=x?.unavailable?.(e);!x||!R||g.has(x.id)||(g.add(x.id),s.push(`${bt(x)} cannot be read on this car: ${R}.`))}for(let y of t.objectives)i[y.metricId]?y.weight>0?y.goal==="target"&&!Number.isFinite(y.target)?s.push(`${bt(i[y.metricId])}: \u201Chit a value\u201D needs a value.`):y.goal==="target"&&y.tolerance!==void 0&&!(y.tolerance>=0)&&s.push(`${bt(i[y.metricId])}: the tolerance must be zero or more.`):s.push(`${bt(i[y.metricId])}: weight must be positive.`):s.push(`\u201C${y.metricId}\u201D is not a metric.`);return s}var TD=.1,PD=2e3,L1=3;function V1(e,t,r={},n=PD){t=Kt(e,t);let o=es(e,t,r),a=nh(r),s=gt(e),i=o.variables.map(k=>k.start),c=k=>{let C=o.build(k);return o.feasible(C).ok&&o.terms(C),C},l=c(i),u=o.feasible(l),m=[...t.objectives,...t.constraints],p=(k,C=m)=>{let P={};for(let L of C){let E=a[L.metricId];E&&(P[`${L.metricId}@${Xa(L.at)}`]=vt(k.ev,E,L.at))}return P},d=k=>m.map(C=>k[`${C.metricId}@${Xa(C.at)}`]).map(C=>Number.isFinite(C)?C.toFixed(9):"x").join("|"),f=p(l,Xr(t)),h=d(f),b=[],g=[],y={},x=[],R=0;t.variables.forEach((k,C)=>{let P=s[k.id];if(!P)return;if(x.length>=L1&&R>n){g.push(P);return}let L=[...i];L[C]=i[C]+(k.hi-i[C])*.25||k.hi;let E=performance.now(),_=c(L),D=performance.now()-E;R+=D,x.push(D);let I=p(_);y[P.id]=I,d(I)===h&&b.push(P)});let v=t.variables[0],S=v?t.variables.indexOf(v):-1;for(let k=0;v&&x.length>0&&x.length<L1;k++){let C=[...i];C[S]=i[S]+(v.hi-i[S])*(.4+.15*k)||v.hi;let P=performance.now();c(C),x.push(performance.now()-P)}let A=[...x].sort((k,C)=>k-C),F=A.length?A[A.length>>1]:0,w=[],T=Xr(t).map(k=>k.metricId);if(T.some(k=>k.startsWith("dyn.trim")||k==="dyn.ymdMaxAy")){let k=l.ev.ymdLimit();k?.onGridEdge&&w.push("The yaw-moment diagram peaks on the edge of its swept grid, so the trim readings are where the sweep stopped rather than where the car does. Widen the \u03B2/\u03B4 envelope before trusting them."),!k&&l.ev.dynAvailable&&w.push("The yaw-moment diagram found no trim point, so anything read off the limit is unavailable.")}if(T.some(k=>k==="dyn.steeringTorque"||k==="dyn.steeringTorqueGradient")){let k=l.ev.tyre()?.model,C=k?yo(k):null;C==="assumed"?w.push("This tyre carries no explicit Mz coefficient block. Its steering-aligning contribution uses Magic Formula defaults, so optimise the curve only as a qualitative placeholder until Mz is imported or fitted."):C==="none"&&w.push("This tyre model has no aligning-moment curve. Steering metrics contain contact-patch force and jacking, but not the pneumatic-trail signal that normally warns the driver at the tyre limit.")}let M=["lap.minStabil","lap.understeerFrac"];if(T.some(k=>M.includes(k))){let C=l.ev.lapReserve()?.beyondFrac;if(C!==void 0&&Number.isFinite(C)){let P=(C*100).toFixed(0);C>=TD?w.push(`Over ${P} % of this course, some wheel is asked for more longitudinal force than its own tyre ellipse allows \u2014 the speed profile and the per-wheel reconstruction disagree that far. A reserve read there is the two models disagreeing rather than the car having nothing left, and a search pointed at one will optimise the disagreement. It concentrates in high-speed braking, so a shorter straight into the first corner is the usual cure.`):C>0&&w.push(`${P} % of this course is beyond the per-wheel tyre ellipse, which is the usual level of disagreement between the speed profile and the reconstruction. Reserves are readable; treat small differences between designs as smaller than they look.`)}}return w.push(...m1(l.ev,Xr(t).map(k=>({m:a[k.metricId],at:k.at})).filter(k=>!!k.m))),{msPerEval:F,values:f,samples:x.length,times:x,dead:b,moves:y,unprobed:g,warnings:w,beyondFrac:T.some(k=>M.includes(k))?l.ev.lapReserve()?.beyondFrac:void 0,startFeasible:u.ok,startReason:u.reason}}var C4=[{kind:"title",label:"Title",what:"The name, what it changes against the Reference, the version and the date",on:"both",make:()=>({kind:"title"})},{kind:"picture",label:"Picture",what:"The car in plan, to scale",on:"each",make:()=>({kind:"picture",half:!0})},{kind:"keyFigures",label:"Key figures",what:"Large numbers picked from the sheet, or formulas",on:"each",make:()=>({kind:"keyFigures",rows:T4.slice(0,4),half:!0})},{kind:"spec",label:"Setup",what:"The Setup by group, or rows picked one by one",on:"each",make:()=>({kind:"spec",rows:"essential"})},{kind:"parts",label:"Parts",what:"Each part by name",on:"each",make:()=>({kind:"parts"})},{kind:"characteristics",label:"Characteristics",what:"What follows from the Setup, at the layout\u2019s operating point",on:"each",make:()=>({kind:"characteristics",groups:[]})},{kind:"results",label:"Results",what:"The events, times, energy and points",on:"each",make:()=>({kind:"results"})},{kind:"chart",label:"Chart",what:"Speed round a lap, the cornering limit or the torque curve",on:"both",make:()=>({kind:"chart",chart:"grip",others:!0,half:!0})},{kind:"changes",label:"Changes since",what:"What was changed since the version compared against",on:"each",make:()=>({kind:"changes"})},{kind:"checks",label:"Checks",what:"The car\u2019s errors and warnings",on:"each",make:()=>({kind:"checks"})},{kind:"notes",label:"Notes",what:"Free text, on every page or one car\u2019s",on:"both",make:()=>({kind:"notes",text:"",cars:{}})},{kind:"comparison",label:"Comparison table",what:"The rows the cars differ in, side by side",on:"all",make:()=>({kind:"comparison"})}];var T4=["setup:m","characteristics:peak_power","characteristics:power_to_weight","characteristics:cla","characteristics:cda","characteristics:pack_energy","characteristics:maxAy","characteristics:top_speed"];var d0e=new Set(C4.map(e=>e.kind));var LD={travel:{name:"Wheel travel",unit:"mm",axis:"Wheel travel (mm, + bump)",from:-25,to:25,step:1,reach:150},roll:{name:"Body roll",unit:"\xB0",axis:"Body roll (\xB0, + right side down)",from:-3,to:3,step:.25,reach:12},steer:{name:"Rack",unit:"mm",axis:"Rack (mm, + right)",from:-30,to:30,step:1,reach:80},pitch:{name:"Body pitch",unit:"\xB0",axis:"Body pitch (\xB0, + nose down)",from:-2,to:2,step:.25,reach:8}};var B1=["FL","FR","RL","RR"],or=(e,t,r)=>({input:e,from:r?r[0]:LD[e].from,to:r?r[1]:LD[e].to,n:t}),b0e=[{id:"sides",name:"Inside and outside",cards:[{id:"camber-roll",form:"curves",title:"Camber to the road through roll",sweep:or("roll",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"toe-rack",form:"curves",title:"Wheel angle against the rack",sweep:or("steer",25),wheels:["FL","FR"],y:["toe"]},{id:"camber-rack",form:"curves",title:"Camber to the road through the steer",sweep:or("steer",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"load-roll",form:"curves",title:"Wheel loads through roll",sweep:or("roll",25),wheels:B1,y:["wheelLoad"]},{id:"travel-roll",form:"curves",title:"Wheel travel through roll",sweep:or("roll",25),wheels:B1,y:["travel"]},{id:"toe-roll",form:"curves",title:"Roll steer, all four",sweep:or("roll",25),wheels:B1,y:["toe"]}]},{id:"maps",name:"Travel and steer together",cards:[{id:"camber-map",form:"surface",title:"Camber over travel and rack",sweep:or("travel",17),second:or("steer",13),wheels:["FL"],y:["camber"]},{id:"bump-steer-map",form:"map",title:"Bump steer over travel and rack",sweep:or("travel",17),second:or("steer",13),wheels:["FL"],y:["bumpSteer"]},{id:"bump-steer-family",form:"curves",title:"Bump steer through travel, at five rack positions",sweep:or("travel",25),second:or("steer",5,[-20,20]),wheels:["FL"],y:["bumpSteer"]},{id:"scrub-map",form:"surface",title:"Scrub radius over travel and rack",sweep:or("travel",17),second:or("steer",13),wheels:["FL"],y:["scrubRadius"]}]}];function $1(e){let t=Number(e);return Number.isFinite(t)?Math.min(Ig,Math.max(Eg,t)):ur}var ED=6e4;var bye=[{within:60*6e4,every:ED},{within:1440*6e4,every:60*6e4},{within:720*60*6e4,every:1440*6e4},{within:1/0,every:10080*6e4}];var ID=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);var K1=e=>e==null;function G4(e,t){return e===t||K1(e)&&K1(t)?!0:typeof e=="number"&&typeof t=="number"&&Number.isNaN(e)&&Number.isNaN(t)}function $u(e,t){if(G4(e,t))return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!$u(e[r],t[r]))return!1;return!0}if(ID(e)&&ID(t)){for(let r of Object.keys(e))if(!$u(e[r],t[r]))return!1;for(let r of Object.keys(t))if(!(r in e)&&!K1(t[r]))return!1;return!0}return!1}var K4=new Set(["color","visible","source","origin"]),Aye=["id",...K4];var OD=.18/1.18,VD={induction:{kind:"natural"}},BD=e=>e.breathing??VD;function ah(e){switch(e?.kind){case"sae-j1349":return eu(99e3,25);case"measured":return eu(e.hPa*100,e.tempC);default:return eu(101325,20)}}var z4=ah(void 0);function $D(e,t){let r=ah(e.rated),n=e.induction;if(n.kind==="boosted"){let o=n.boostKPa*1e3;return Math.min(n.maxPressureRatio*t.p,o)/Math.min(n.maxPressureRatio*r.p,o)*(t.pDry/t.p)/(r.pDry/r.p)}return t.pDry/r.pDry*Math.sqrt(r.T/t.T)}function GD(e,t){let r=e.induction;if(r.kind==="table"){let o=s=>ot(r.densityAltitudeM,r.powerPct,s),a=o(ah(e.rated).densityAltitudeM);return a>0?Math.max(0,o(t.densityAltitudeM)/a):0}let n=e.frictionShare??OD;return Math.max(0,($D(e,t)-n)/(1-n))}var ND=new WeakMap;function H1(e,t){let r=e.asRated??e,n=`${t.p}|${t.pDry}|${t.T}`,o=ND.get(r);o||ND.set(r,o=new Map);let a=o.get(n);if(a)return a;let s=GD(BD(r),t),i={...r,torque:r.torque.map(c=>c*s),asRated:r};return o.set(n,i),i}function U4(e){return JSON.parse(z1(Y1(e,"public/laptime/index.json"),"utf8")).tracks}var X4=async e=>{let t=await fetch(e.url);if(!t.ok)throw new Error(`The track could not be read from ${tf(e)} (${t.status}).`);return new Uint8Array(await t.arrayBuffer())};function KD(e,t=new Map,r=X4){let n=U4(e);return async o=>{let a=o.kind==="catalogue"?`catalogue:${o.address}`:o.name,s=t.get(a);if(s)return structuredClone(s);let i;if(o.kind==="catalogue"&&o.link){if(!iu(o.address))throw new Error(`"${o.address}" is not a catalogue address`);if(!su(o.link))throw new Error("This track is linked to a source this version does not read from.");i=await Tx(await r(o.link),o.link,o.address)}else if(o.kind==="catalogue"){if(!iu(o.address))throw new Error(`"${o.address}" is not a catalogue address`);let c=JSON.parse(z1(Y1(e,"public/catalogue",Lx(o.address)),"utf8"));i=await Ex(c,o.address)}else{let c=n.find(l=>l.name===o.name)?.file;if(!c)throw new Error(`"${o.name}" is not in the bundled catalogue`);i=JSON.parse(z1(Y1(e,"public/laptime",c),"utf8"))}return t.set(a,i),structuredClone(i)}}var q4=1e-6;function HD(e,t,r){let n=e.cgReference;if(!n||!e.cg_height)return e;let o=_w(e,t,r);if(o===void 0||Math.abs(o-n.standingRadius)<q4)return e;let a=n.typed??e.cg_height.value;return{...e,cg_height:{...e.cg_height,value:ai(e.cg_height.value,n.standingRadius,o)},cgReference:{...n,standingRadius:o,typed:a}}}function zD(e,t,r){let n=e.rcRoad,o=e.rc_front,a=e.rc_rear;if(!n||!o||!a)return e;let s=Wd(e,t,r),i=qn(o.value,n.gainFront,n.radiusFront,s.front),c=qn(a.value,n.gainRear,n.radiusRear,s.rear);return i===o.value&&c===a.value?e:{...e,rc_front:{...o,value:i},rc_rear:{...a,value:c},rcRoad:{...n,radiusFront:s.front??n.radiusFront,radiusRear:s.rear??n.radiusRear}}}var YD=e=>({brakeFade:e.brakeFade,airTempC:e.airTempC,diffYaw:e.diffYaw,...Da(e.air)?{air:e.air}:{}});var ts=(e,t)=>t?e.find(r=>r.id===t)?.model:void 0;function rs(e){return{tire:t=>ts(e.tires,t),motor:t=>ts(e.motors,t),aero:t=>ts(e.aeros,t),battery:t=>ts(e.batteries,t),brake:t=>ts(e.brakes??[],t),damper:t=>ts(e.dampers??[],t),suspensionOf:t=>Ei(W1(e,t),t)}}function W1(e,t){let r=ts(e.suspensions,t.suspensionId);if(r)return r;let n=e.suspensions.find(o=>o.id===e.activeSuspensionId)??e.suspensions[0];if(!n)throw new Error("this project holds no suspension, so no car can be resolved");return n.model}function ns(e,t,r){let n={front:t.tire(e.tireModelId),rear:t.tire(e.tireModelIdRear)};return j1(Cw(t.suspensionOf(e),e,n),t,r)}function Q4(e){return Da(e.air)?mT(e.air,e.airTempC??ur):void 0}function Z4(e,t){return t?{...e,rho:{...e.rho,value:t.rho},readouts:{...e.readouts,rho:Wp}}:e}function J4(e,t,r){if(!r)return{rho:e.rho,motorModel:t,readouts:e.readouts};let{rho:n,readouts:o}=Z4(e,r);return{rho:n,motorModel:t&&yt(t)?H1(t,r):t,air:r,readouts:o}}function j1(e,t,r){let n=t.tire(e.tireModelId),o=t.tire(e.tireModelIdRear),a=zD(HD(Wf(Bw(Nw(Uw(e,t.aero(e.aeroModelId)),t.battery(e.batteryModelId)),t.damper(e.damperModelId),t.damper(e.damperModelIdRear)??t.damper(e.damperModelId)),n,o),n,o),n,o),{readouts:s,...i}=J4(a,t.motor(e.motorModelId),Q4(r));return{...a,...i,...s?{readouts:s}:{},tireModel:n,...o?{tireModelRear:o}:{},aeroModel:t.aero(e.aeroModelId),batteryModel:t.battery(e.batteryModelId),brakeModel:t.brake(e.brakeModelId),damperModel:t.damper(e.damperModelId),...ml(e,t.damper),ggvMode:r.ggvMode,quasiTransient:r.quasiTransient??!1,motorThermal:r.motorThermal??!1,brakeFade:r.brakeFade??!1,...r.airTempC!==void 0?{airTempC:r.airTempC}:{},...r.diffYaw?{diffYaw:!0}:{},airSettled:!0}}var nz=e=>e!==!1,oz=(e,t,r)=>r&&t>0?(e%t+t)%t:Math.min(Math.max(e,0),t);function az(e,t,r){let n=e.points.filter(o=>Number.isFinite(o.at)&&Number.isFinite(o.z)).map(o=>({...o,at:oz(o.at,t,r)})).sort((o,a)=>o.at-a.at);return n.filter((o,a)=>a===0||o.at-n[a-1].at>1e-9)}function sz(e,t,r){let n=az(e,t,r),o=n.length;if(o===0)return[];let a=d=>d<o-1?n[d+1].at-n[d].at:r?n[0].at+t-n[d].at:1/0,s=d=>d<o-1?(n[d+1].z-n[d].z)/a(d):r&&o>1?(n[0].z-n[d].z)/a(d):0,i=n.map(d=>Math.max(0,Number.isFinite(d.curve)?d.curve:0)/2),c=(d,f,h)=>i[d]+i[f]>h?h*i[d]/(i[d]+i[f]):i[d],l=d=>d<o-1||r?c(d,d<o-1?d+1:0,a(d)):Math.max(0,t-n[d].at),u=d=>d>0?c(d,d-1,a(d-1)):r?c(d,o-1,a(o-1)):n[d].at,m=d=>d>0?s(d-1):r&&o>1?s(o-1):n[d].at<=1e-9?s(d):0,p=d=>!r&&d===o-1&&o>1&&n[d].at>=t-1e-9?s(d-1):s(d);return n.map((d,f)=>{let h=l(f),b=u(f),g=Math.min(i[f],h,b),y=!r&&g<i[f]&&(f===o-1&&g===h||f===0&&g===b);return{at:d.at,z:d.z,gIn:m(f),gOut:p(f),half:g,asked:i[f],atEnd:y}})}function iz(e,t,r,n){let o=t-e.at;return n&&r>0?o-r*Math.round(o/r):o}function cz(e,t,r,n){for(let s of e){let i=iz(s,t,r,n);if(s.half>0&&Math.abs(i)<s.half){let c=i+s.half;return s.z-s.gIn*s.half+s.gIn*c+(s.gOut-s.gIn)/(4*s.half)*c*c}}let o=e[e.length-1],a=n?t-o.at+(t<o.at?r:0):t-o.at;for(let s of e)s.at<=t&&(o=s,a=t-s.at);return!n&&t<e[0].at?e[0].z:o.z+o.gOut*a}function WD(e,t,r,n){let o=nz(n),a=sz(e,r,o);return a.length?t.map(s=>cz(a,s,r,o)):t.map(()=>0)}function Gu(e,t){if(!t?.points.length)return e;let r=du(e),{zSmoothing:n,...o}=e;return{...o,z:WD(t,r,rR(e),e.closed)}}var sh={widthLeft:1.5,widthRight:1.5,bank:0,mu:1};function jD(e){return e.kind==="bundled"?{kind:"bundled",name:e.name}:e.kind==="catalogue"?{kind:"catalogue",id:e.id,address:e.address,...e.link?{link:e.link}:{}}:null}async function Ku(e,t){let r=jD(e.source);return UD(e,r?await t(r):void 0)}function UD(e,t){let{source:r}=e;if(r.kind==="segments"){let{segments:i,closed:c,spacing:l}=r,{asset:u}=fu(i,{name:e.name,closed:c,spacing:l,base:sh});return Gu(u,r.profile)}let n=r.sections??[];if(r.kind==="inline")return Gu(mf(r.asset,n,sh),r.profile);if(!t)throw new Error(`Track "${e.name}" has to be loaded before it can be resolved.`);let{widthLeft:o,widthRight:a,closed:s}=r;return Gu(mf({...t,...o!==void 0?{widthLeft:o}:{},...a!==void 0?{widthRight:a}:{},...s!==void 0?{closed:s}:{}},n,sh),r.profile)}var XRe=1/500;var qRe=5*Math.PI/180;var a1e=1/3;var dz=[4,2,1,.5,.25,.125];function XD(e,t,r={}){let n=[...r.steps??dz].sort((g,y)=>y-g),o=Bt(r.numerics),a=r.tolPct??.5,s=mr(e),i=e.ggvMode??"twoTrack",c=bn(s,!1,i),l={...o,dsTarget:n[0]??o.dsTarget},u=n.length?Aa(s,c,[$t(t,l)],l,i):void 0,m=Fo(s,c.rows),p=n.map((g,y)=>{let x={...o,dsTarget:g},R=Date.now(),v=$t(t,x),S=tr(c,v,x,{...u?{load:u}:{},...m?{shifts:m}:{}});return r.onStep?.(y+1,n.length),{dsTarget:g,npts:v.npts,lapTime:S.laptime,ms:Date.now()-R}}),d=p[p.length-1]?.lapTime??NaN,f=p.map(g=>{let y=g.lapTime-d;return{...g,delta:y,deltaPct:d?100*y/d:NaN}}),h=f.filter(g=>Math.abs(g.deltaPct)<=a),b=h.length?Math.max(...h.map(g=>g.dsTarget)):null;return{points:f,reference:d,recommended:b,tolPct:a}}function io(e,t={}){let r=e.settings,n=t.ggvMode??r.ggvMode,o=(t.quasiTransient??r.quasiTransient)&&n!=="fast",a=e.tracks.find(s=>s.id===e.activeTrackId)??e.tracks[0];return{ggvMode:n,quasiTransient:o,motorThermal:t.motorThermal??r.motorThermal,brakeFade:t.brakeFade??r.brakeFade,airTempC:$1(t.airTempC??r.airTempC),...Da(Yp(t.air??r.air))?{air:Yp(t.air??r.air)}:{},diffYaw:t.diffYaw??r.diffYaw,racingLine:t.racingLine??r.useRacingLine,standingStart:t.standingStart??(a?a.standingStart===!0:r.standingStart),lapCounts:t.lapCounts??r.lapCounts,numerics:Bt(r.numerics)}}async function ih(e,t){let r=e.tracks.find(n=>n.id===e.activeTrackId)??e.tracks[0];if(!r)throw new Error("this project holds no track \u2014 add one with track_select before running a lap event");return{entry:r,asset:await Ku(r,t)}}function X1(e,t){let r=structuredClone(e);for(let[n,o]of Object.entries(t))if(!si(r,n,o))throw new Error(`no parameter is labelled "${n}" on this car \u2014 read vehicle_get for the labels it has`);return r}var U1=(e,t)=>{let r=e?.name;return typeof r=="string"&&r?r:t};function hz(e,t){let r={};for(let n of Po){let o=e[n.doc]??[];for(let i of n.slots.slice(1)){let c=t[i.ref],l=typeof c=="string"?o.find(u=>u.id===c):void 0;l&&(r[i.key]={id:l.id,name:U1(l.model,l.id)})}let a=t[n.ref],s=typeof a=="string"?o.find(i=>i.id===a):void 0;if(s){r[n.doc]={id:s.id,name:U1(s.model,s.id)};continue}if(n.doc==="suspensions"){let i=o.find(c=>c.id===e.activeSuspensionId)??o[0];r[n.doc]=i?{id:i.id,name:U1(i.model,i.id),byFallback:!0}:null;continue}r[n.doc]=null}return r}function bz(e){return Object.values(e.events).map(t=>({id:t.id,label:t.label,kind:t.kind,time:t.time,lapTime:t.lapTime,distance:t.distance,laps:t.laps,...t.energy?{energyConsumedKwh:t.energy.consumed,energyRemaining:t.energy.remainingFraction}:{},...t.lapsOverridden?{lapsOverridden:t.lapsOverridden}:{},...t.incomplete?{incomplete:t.incomplete}:{},...t.energyTarget?{energyTarget:t.energyTarget}:{}}))}function qD(e){let t=new Map;for(let{name:r,events:n}of e)for(let o of n){let a=t.get(o.label);a||t.set(o.label,a={event:o.label,finished:[],stopped:[]}),(o.incomplete?a.stopped:a.finished).push(r)}return[...t.values()].filter(r=>r.stopped.length>0)}var q1=e=>e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;async function ch(e,t,r={}){let n=io(e,r.settings),{entry:o,asset:a}=await ih(e,t),s=rs(e),i=r.vehicleIds?.length?r.vehicleIds.map(f=>{let h=e.vehicles.find(b=>b.id===f);if(!h)throw new Error(`this project holds no vehicle "${f}"`);return h}):e.vehicles.filter(f=>f.visible);if(!i.length)throw new Error("no vehicle is visible in this project \u2014 name some in vehicleIds");let c=i.map(f=>{let h=r.overrides?.[f.id]?X1(f.params,r.overrides[f.id]):f.params;return ns(structuredClone(h),s,n)}),l=Ul(Pa(e.meta.rulesetId,e.rulesets)),u=Jl(c,a,n.numerics,l,{racingLine:n.racingLine,standingStart:n.standingStart,lapCounts:n.lapCounts}),m={};i.forEach((f,h)=>{m[f.id]=u[h]});let{scores:p,field:d}=sx(l,m);return{rulesetId:e.meta.rulesetId,track:o.name,settings:{ggvMode:n.ggvMode,quasiTransient:n.quasiTransient,motorThermal:n.motorThermal,brakeFade:n.brakeFade,airTempC:n.airTempC,...n.air?{air:n.air}:{},diffYaw:n.diffYaw,racingLine:n.racingLine,standingStart:n.standingStart},fleetScored:p!==null,vehicles:i.map((f,h)=>({id:f.id,name:u[h].name||String(f.params.name??f.id),events:bz(u[h]),metrics:ix(l,u[h],d?.[f.id]),fitted:hz(e,f.params),...p?.[f.id]?{score:{total:p[f.id].total,parts:{...p[f.id].parts}}}:{}})),raw:{results:m,scores:p,field:d}}}async function QD(e,t,r){let n=e.vehicles.find(i=>i.id===r.vehicleId);if(!n)throw new Error(`this project holds no vehicle "${r.vehicleId}"`);let o=io(e),{asset:a}=await ih(e,t),s=ns(structuredClone(n.params),rs(e),o);return XD(s,a,{...r.steps?{steps:r.steps}:{},numerics:o.numerics,...r.tolPct!==void 0?{tolPct:r.tolPct}:{},...r.onStep?{onStep:r.onStep}:{}})}var ake=Math.PI/180;var dke=Math.PI/180;var JD=["rollBar.front.wheelRate","param.arb_front","roll.front.rate","roll.front.wheelRate"];function Q1(e){for(let t of JD){let r=e.findIndex(n=>n.id===t);if(r>=0)return r}return-1}var eE="dyn.tlltdFront",Z1=1e-6;function lh(e){let t=gt(e),r=t["rollBar.front.wheelRate"];if(r&&!r.supersededBy){let c=r.read(e);if(c>0)return{id:r.id,def:r,now:c}}let n=t["param.arb_front"];if(!n)return{why:"the car states no front anti-roll bar"};let o=n.supersededBy,a=o?o.useInstead:n.id,s=a?t[a]:void 0;if(!s||s.supersededBy)return{why:`its front bar is ${(o?.why??"computed elsewhere").replace(/^computed from /,"")}, whose rate is not one number to re-solve`};let i=s.read(e);return i>0?{id:s.id,def:s,now:i}:xl(e.vehicle,e.params,"front")?{why:"its front bar stands beside a roll damper and is described by its section, whose rate is not one number to re-solve"}:{why:"the car has no front bar to re-solve: its rate is zero"}}function tE(e,t,r,n,o=Z1,a){let s=0,i=b=>(s++,e(b)-t),c=(b,g,y)=>({value:b,reading:t+g,reached:y,reads:s});if(a!==void 0&&a>=r&&a<=n){let b=i(a);if(Math.abs(b)<=o)return c(a,b,!0)}let l=r,u=n,m=i(l),p=i(u);if(!Number.isFinite(m)||!Number.isFinite(p))return c(NaN,NaN,!1);if(Math.abs(m)<=o)return c(l,m,!0);if(Math.abs(p)<=o)return c(u,p,!0);if(m*p>0)return Math.abs(m)<=Math.abs(p)?c(l,m,!1):c(u,p,!1);let d=0,f=l,h=m;for(let b=0;b<60;b++){if(f=(l*p-u*m)/(p-m),h=i(f),!Number.isFinite(h))return c(NaN,NaN,!1);if(Math.abs(h)<=o||Math.abs(u-l)<=1e-12*Math.max(1,Math.abs(f)))break;h*p>0?(u=f,p=h,d===-1&&(m/=2),d=-1):(l=f,m=h,d===1&&(p/=2),d=1)}return c(f,h,Math.abs(h)<=o)}function uh(e,t){let r=Q1(e.variables);if(r<0)return{why:"the front bar is not one of the variables"};let n=t.byId[eE];if(!n)return{why:"the balance cannot be read here"};let o=NaN;try{o=vt(e.build(Gr(e.variables)).ev,n)}catch{}return Number.isFinite(o)?{slot:r,target:o,metric:n}:{why:"the car\u2019s balance could not be read"}}function mh(e,t,r){let n=e.variables[r.slot],a=tE(i=>{let c=t.slice();c[r.slot]=i;try{return vt(e.build(c).ev,r.metric)}catch{return NaN}},r.target,Math.max(0,n.lo),Math.max(0,n.hi),Z1,t[r.slot]),s=t.slice();return Number.isFinite(a.value)&&(s[r.slot]=a.value),{x:s,held:{value:s[r.slot],balance:a.reading,target:r.target,reached:a.reached}}}var J1="param.m",ev=.01;function tv(e,t,r){return r===void 0||!Number.isFinite(r)||r===0||!Number.isFinite(e)||!Number.isFinite(t)?NaN:(e-t)/r}var cMe=Math.PI/180;var dh=.5,Pz=new Set(["lap","session"]);function Lz(e){return dt({...e,label:e.label.replace(/ [xyz]$/,"")})}function rE(e){let t=Ua(e);if(t)return[t.point];let r=Pr(e);if(r)return[r.point];let n=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(n){let a=Rr[n[2]];return[`hp.${n[1]}.${a.fore}`,`hp.${n[1]}.${a.aft}`]}let o=/^rocker\.(front|rear)\./.exec(e);return o?[`hp.${o[1]}.${Sn.fore}`,`hp.${o[1]}.${Sn.aft}`]:[]}function nE(e,t){let r=Kt(e,t),n=gt(e),o=new Map;for(let a of[...r.variables,...r.followers??[]])for(let s of rE(a.id)){if(o.has(s))continue;let i=_i.map(c=>`${s}.${c}`).filter(c=>n[c]&&!n[c].supersededBy);i.length&&o.set(s,{id:s,name:Lz(n[i[0]]),coords:i})}return[...o.values()]}function rv(e,t,r,n={},o=dh){let a=Kt(e,t),s=(n.metrics??xr()).byId,i=zi(e,a,r),c=nE(e,a),l=gt(i),u=[];a.objectives.forEach((k,C)=>{let P=s[k.metricId];P&&u.push({key:k.key??`target:${C}`,role:"target",metric:P,at:k.at})}),a.constraints.forEach((k,C)=>{let P=s[k.metricId];P&&u.push({key:k.key??`hold:${C}`,role:"hold",metric:P,at:k.at,hold:k})}),(a.watches??[]).forEach((k,C)=>{let P=s[k.metricId];P&&u.push({key:k.key??`watch:${C}`,role:"watch",metric:P,at:k.at})});let m=u.filter(k=>!Pz.has(k.metric.cost)),p=k=>{let C=oh(k,a,n),P=m.map(L=>vt(C,L.metric,L.at));return C.failure?null:P},d=p(i)??m.map(()=>NaN),f=[],h=[],b=[],g=1,y=[...d],x=[...d],R=k=>k.forEach((C,P)=>{Number.isFinite(C)&&(C>=y[P]||(y[P]=C),C<=x[P]||(x[P]=C))}),v=k=>{g++;try{return p(k())}catch{return null}};for(let k of c)for(let C of k.coords){let P=l[C],L=P.read(i),E=C.slice(C.lastIndexOf(".")+1),_=v(()=>P.write(i,L+o)),D=v(()=>P.write(i,L-o));if(!_||!D){b.push(`${k.name} ${E}`);continue}f.push({id:C,def:P,now:L,point:k,axis:E}),h.push([_,D]),R(_),R(D)}let S=new Map,A=k=>{let C=k.join("");if(S.has(C))return;let P=v(()=>f.reduce((L,E,_)=>E.def.write(L,E.now+k[_]*o),i));S.set(C,P),P&&R(P)};f.length>1&&m.forEach((k,C)=>{let P=h.map(([L,E])=>L[C]-d[C]>=E[C]-d[C]?1:-1);Number.isFinite(d[C])&&(A(P),A(P.map(L=>-L)))});let F=[...S.values()].filter(k=>!k).length;F&&b.push(`${F} of ${S.size} corners`);let w=u.map(k=>{let C={key:k.key,role:k.role,name:bt(k.metric)+Ja(k.at,k.metric,a),unit:k.metric.unit==="-"?"":k.metric.unit,...k.hold?{limit:{op:k.hold.op,limit:k.hold.limit,...k.hold.limit2!==void 0?{limit2:k.hold.limit2}:{}}}:{}},P=m.indexOf(k);if(P<0)return{...C,value:NaN,lo:NaN,hi:NaN,skipped:"read off a lap"};let L=d[P],E=Number.isFinite(L)?y[P]:NaN,_=Number.isFinite(L)?x[P]:NaN,D=h.map(([V,H])=>Math.max(Math.abs(V[P]-L),Math.abs(H[P]-L))),I=D.filter(Number.isFinite).reduce((V,H)=>V+H,0),N;if(I>0){let V=D.indexOf(Math.max(...D.filter(Number.isFinite)));N={point:f[V].point.name,axis:f[V].axis,share:D[V]/I}}let O=k.hold?Math.max(No(k.hold,E),No(k.hold,_)):void 0;return{...C,value:L,lo:E,hi:_,...N?{most:N}:{},...O!==void 0?{excess:O}:{}}}),T=new Set(c.flatMap(k=>k.coords)),M=a.variables.filter(k=>!rE(k.id).length&&!T.has(k.id)).length;return{mm:o,points:c,rows:w,evaluations:g,unsolved:b,settings:M}}function nv(e){if(!e.chassis)return e;let{chassis:t,...r}=e;return t.boxes.length?{...r,chassis:{boxes:t.boxes}}:r}var iFe=180/Math.PI;var p6={id:"racecar",label:"Race car",description:"Suspension kinematics, tyres, powertrain and quasi-steady-state lap simulation for a four-wheeled race car.",tools:["laptime","garage","kinematics","track","studies","dynamics","tires","aero","powertrain","battery","brakes","dampers","forces","calibration"],defaultRulesetId:Ta,templateIds:["fs-ev-comparison","fs-endurance-energy","fs-ev-single","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor","formula-1","touring-car","street-car","cup-car","stock-car","hill-climb","race-truck","suspension","direct-coilover","pushrod","pullrod","third-spring","mcpherson-strut","tyre-study"],collections:[{id:"start",label:"Start here",description:"What the model answers, then cars to build from.",templateIds:["fs-ev-comparison","fs-endurance-energy","suspension","tyre-study","fs-ev-single","formula-1","touring-car"]},{id:"formula-student",label:"Formula Student",description:"Electric and combustion cars on the five Formula Student events, by drive layout.",templateIds:["fs-ev-comparison","fs-endurance-energy","suspension","tyre-study","fs-ev-single","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor"]},{id:"circuits",label:"Circuit racing",description:"Single-seaters, GT, cup and road cars and a race truck on real circuits, with their heights.",templateIds:["formula-1","touring-car","street-car","cup-car","race-truck"]},{id:"ovals-hill-climbs",label:"Ovals and hill climbs",description:"A banked oval, and an open course climbed from rest in thin air.",templateIds:["stock-car","hill-climb"]},{id:"kinematics",label:"Suspension and kinematics",description:"Each suspension architecture: its hardpoints, its roll centres and what it does on track.",templateIds:["suspension","direct-coilover","pushrod","pullrod","third-spring","mcpherson-strut"]},{id:"tyres",label:"Tyres",description:"Grip curves, and what a tyre is worth on track.",templateIds:["tyre-study"]},{id:"powertrain",label:"Energy and powertrain",description:"What a pack lasts, and how each drive layout puts its power down.",templateIds:["fs-endurance-energy","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor"]}]};var OCe=p6.id;var os=.02;function bE(e){let t=Math.max(os,Math.abs(e.heaveMotionRatio)),r=Math.max(os,Math.abs(e.rollMotionRatio)),o=2*(e.cornerWheelRate+e.heaveWheelRate)/(t*t),a=2*(e.cornerDamper+(e.heaveWheelDamping??0))/(t*t),s=(e.cornerDamper+(e.rollWheelDamping??0))/(r*r);return{heaveRate:o,heaveDamper:a,rollWheelRate:e.cornerWheelRate+e.arbWheelRate,rollDamper:s}}var h6=(e,t)=>({od:t,id:Math.min(e.id,t-.5)}),b6=(e,t)=>e/(2*t*t);function hE(e,t){switch(e.kind){case"ubar":case"blade":case"torsionTube":return{...e,section:h6(e.section,t)};default:return e}}function sv(e,t,r){let n=Math.max(os,Math.abs(r));if(e?.kind==="coil"){let l=b6(t,n),u=e.rate;if(typeof u=="number")return{...e,rate:l};let m=Un(u,0);if(!(m>0))return{...e,rate:l};let p=l/m;return{...e,rate:{...u,y:u.y.map(d=>d*p)}}}let o=t/(n*n),a=e&&(e.kind==="ubar"||e.kind==="blade"||e.kind==="torsionTube")?e:{kind:"torsionTube",section:{od:20,id:16},length:400,leverArm:60,G:8e4},s=l=>hl(hE(a,l),0).rateAtLink,i=4,c=60;if(s(c)<o)return{kind:"direct",wheelRate:t};for(let l=0;l<80&&c-i>1e-9;l++){let u=.5*(i+c);s(u)<o?i=u:c=u}return hE(a,c)}function gE(e,t,r,n){let o=e?.design,a=sv(t?.design,r.rollWheelRate,n);return{heave:{design:{kind:"coil",rate:r.heaveRate,motionRatio:o?.kind==="coil"?o.motionRatio:1,gap:0,bothWays:!0},linkage:e?.linkage,damper:r.heaveDamper},arb:{design:a,linkage:t?.linkage,damper:a.kind==="coil"?r.rollDamper/2:r.rollDamper}}}var g6=Math.PI/180,ph=1e-6;function y6(e){return!(Le(e.rockerPivotA,e.rockerPivotB)<ph||Le(e.rockerToPushrod,e.rockerPivotA)<ph||Le(e.rockerToDamper,e.rockerPivotA)<ph||Le(e.rockerToDamper,e.damperChassis)<ph)}function vE(e){if(!y6(e.hardpoints))return!1;let t={...e,config:{...e.config,actuation:"rocker"}};try{let r=Tt(t);for(let n of[-20,-1,0,1,20]){let o=Ce(r,n,0);if(!o.ok||!Number.isFinite(o.state.metrics.damperLength))return!1}return!0}catch{return!1}}function iv(e){if(e.config.actuation!=="direct"||vE(e))return;let{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}=R6(e);return{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}}var yE=40;function fh(e,t={}){let r=e.hardpoints,n=r.pushrodOuter,o=r.damperChassis,a=Le(n,o),s=ne(n,Q($(o,n),x6)),i=t.armRod??Math.max(25,.15*a),c=t.armDamper??i,l=[s[0]-yE,s[1],s[2]],u=[s[0]+yE,s[1],s[2]],m=ee($(u,l)),p=$(n,s),d=ee($(p,Q(m,xE(p,m)))),f=ir(d,m,(t.armAngleDeg??60)*g6),h=ne(s,Q(f,i)),b=$(o,s),g=ee($(b,Q(m,xE(b,m)))),y=Q(ee(me(m,g)),t.damperSide??1),x=ne(s,Q(y,c));return{...r,rockerPivotA:l,rockerPivotB:u,rockerToPushrod:h,rockerToDamper:x}}var x6=.72,xE=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function RE(e){let t=ut(e,{travelMin:-5,travelMax:5,steps:3}),[r,,n]=t.samples;if(!r||!n)return 0;let o=n.travel-r.travel;return o!==0?Math.abs((n.metrics.damperLength-r.metrics.damperLength)/o):0}function R6(e,t={}){let r=t.target??RE(e),n=t.armAngleDeg,o=fh(e,{armAngleDeg:n});if(!(r>0))return o;let a=Le(e.hardpoints.pushrodOuter,e.hardpoints.damperChassis),s=Math.max(25,.15*a),i=(()=>{for(let d of[1,-1]){let f=fh(e,{armRod:s,armAngleDeg:n,damperSide:d}),h={...e,config:{...e.config,actuation:"rocker"},hardpoints:f};try{let b=Tt(h),g=Ce(b,15,0),y=Ce(b,-15,0);if(g.ok&&y.ok&&g.state.metrics.damperLength<y.state.metrics.damperLength)return d}catch{}}return 1})(),c=(d,f)=>{try{return RE({...e,config:{...e.config,actuation:"rocker"},hardpoints:fh(e,{armRod:d,armAngleDeg:n,armDamper:f,damperSide:i})})}catch{return Number.NaN}},l=[1,.6,.35,.2,1.7,2.6].map(d=>Math.max(12,s*d)),u=s,m=s,p=1/0;for(let d of l){let f=.25*d,h=6*d,b=d;for(let y=0;y<24;y++){let x=(f+h)/2,R=c(d,x);if(!Number.isFinite(R))break;b=x,R<r?f=x:h=x}let g=Math.abs(c(d,b)-r);if(Number.isFinite(g)&&g<p&&(p=g,u=d,m=b),p<1e-4*Math.max(1,r))break}return fh(e,{armRod:u,armAngleDeg:n,armDamper:m,damperSide:i})}var QCe=Array.from({length:19},(e,t)=>-45+5*t);var ZCe=Math.PI/180;function v6(e){let t=e.hardpoints,r=ee($(t.rockerPivotB,t.rockerPivotA)),n=Ln(t.rockerToDamper,t.rockerPivotA,r),o=.6*Zr($(t.rockerToDamper,n)),a=me(r,lk),s=Zr(a)>1e-6?ee(a):ee($(t.rockerToDamper,n));return{outer:ne(n,Q(s,o)),inner:ne(n,Q(s,-o)),attach:"rocker"}}var kE=(e,t)=>({...e,config:{...e.config,actuation:t}});function cv(e,t,r,n){let o=r==="front"?e.front:e.rear,a=t.decoupledElements?.[r],s=iv(o);if(a&&A6(o,t,r,a)){let L=a.kept;return{heave:L.heave??{design:{kind:"none"}},arb:L.arb??{design:{kind:"none"}},cornerDamper:L.damper,scalars:{heave:L.heaveSpring,arb:L.arbRate},rollBar:L.rollBar??null,...s?{crank:s}:{}}}let i=oi(o),c=o.config.springRate*i*i,l=J(t,r==="front"?"damper_front":"damper_rear")*i*i,u=r==="front"?t.arbFrontDesign:t.arbRearDesign,m=vl(e,t)[r],p=k6(u,a,n),d=p?0:m??J(t,r==="front"?"arb_front":"arb_rear"),f=ba(e,t)[r]??J(t,r==="front"?"heave_spring_front":"heave_spring_rear"),h=kE(s?{...o,hardpoints:{...o.hardpoints,...s}}:o,"decoupled"),b=r==="front"?t.heaveFrontDesign:t.heaveRearDesign,g=a?a.kept.heave:b,y=a?a.kept.arb:p?void 0:u,x=n?.heave??hh(g?.linkage,L=>Wo(h,L).atDesign)??Pb(h,"rockerToRocker"),R=!y||y.design.kind==="none"||y.design.kind==="coil",v=R?"coil":"ubar",S=y?.linkage&&(a||y.design.kind==="none"||y.linkage.attach!=="rocker")?y.linkage:void 0,A=n?.roll??hh(R?S:y?.linkage,L=>zo(h,L,{kind:v}).atDesign)??(R?v6(h):lw(h)),F=Wo(h,x).atDesign,w=zo(h,A,{kind:v}).atDesign,T=Hd(e,t),M=bE({cornerWheelRate:c,cornerDamper:l,arbWheelRate:d,heaveWheelRate:f,heaveWheelDamping:r==="front"?T.heaveFront:T.heaveRear,rollWheelDamping:r==="front"?T.rollFront:T.rollRear,heaveMotionRatio:F,rollMotionRatio:w}),k=!y||y.design.kind==="none"?{design:{kind:"coil",rate:1},linkage:A}:{...y,linkage:A},C=gE({design:g?.design??{kind:"none"},linkage:x,damper:g?.damper},k,M,w),P=(L,E)=>a&&E?.coilover&&L.linkage===E.linkage?{...L,coilover:E.coilover}:L;return{heave:P(C.heave,g),arb:P(C.arb,y),cornerDamper:J(t,r==="front"?"damper_front":"damper_rear")*w6(o,"rocker").f,rollBar:p?M6(h,p,m??0,a?.kept.rollBar?.linkage):null,...s?{crank:s}:{}}}function k6(e,t,r){if(!(!ha(e)||r?.roll))return t?t.kept.rollBar!==void 0&&!ha(t.kept.arb)?e:void 0:e}function M6(e,t,r,n){let{damper:o,...a}=t,s=a.design.kind,i=p=>zo(e,p,{kind:s}),c=hh(n,p=>i(p).atDesign)??a.linkage,l={...a,...c?{linkage:c}:{}},u=fa(a.design,c?i(c):null,0).wheelRate;if(Math.abs(u-r)<=1e-9*Math.max(1,r))return l;let m=hh(c,p=>i(p).atDesign)??uw(e);return{...a,design:sv(a.design,r,i(m).atDesign),linkage:m}}function S6(e,t){let r=t==="front"?e.heaveFrontDesign:e.heaveRearDesign,n=t==="front"?e.arbFrontDesign:e.arbRearDesign,o=t==="front"?e.rollBarFrontDesign:e.rollBarRearDesign;return{...r?{heave:r}:{},...n?{arb:n}:{},...o?{rollBar:o}:{},damper:J(e,t==="front"?"damper_front":"damper_rear"),heaveSpring:J(e,t==="front"?"heave_spring_front":"heave_spring_rear"),arbRate:J(e,t==="front"?"arb_front":"arb_rear")}}function A6(e,t,r,n){let o=e.config.decoupledSpring;return o!==void 0&&o.wrote===e.config.springRate&&$u(S6(t,r),n.wrote)}function hh(e,t){return e&&Math.abs(t(e))>=os?e:void 0}function w6(e,t){let r=t==="rocker"?iv(e):void 0,n=kE(r?{...e,hardpoints:{...e.hardpoints,...r}}:e,t),o=oi(e),a=oi(n);return{next:n,f:o>=os&&a>=os?(o/a)**2:1,...r?{crank:r}:{}}}var bh=[{id:"direct",name:"Direct-acting coilover",family:"GT / touring car",description:"Each lower wishbone drives a coilover straight into a chassis tower. No rod or rocker in the load path.",scope:"Both axles",tags:["Double wishbone","Coilover","Direct acting"]},{id:"pushrod",name:"Pushrod suspension",family:"Formula / prototype",description:"A rod from the lower wishbone pushes a rocker on the chassis shoulder. A 225 mm damper runs along the top at 1:1.",scope:"Both axles",tags:["Pushrod","Rocker","Inboard damper"]},{id:"pullrod",name:"Pullrod suspension",family:"Formula / low package",description:"A rod from the upper wishbone pulls a low rocker inside the side wall. A 225 mm damper runs along the floor at 1:1.",scope:"Both axles",tags:["Pullrod","Low rocker","Inboard damper"]},{id:"heave",name:"Third heave spring",family:"Formula / aero platform",description:"The pushrod car plus a front third spring worked by both rockers. It picks up after 5 mm of bump and stays out of roll.",scope:"Both axles, plus a front third spring",tags:["Pushrod","Third spring","Aero platform"]},{id:"decoupled",name:"Twin-rocker-bar decoupled modes",family:"Formula / prototype",description:"Each pushrod turns a long rocker bar. A shock between the bars takes heave, a diagonal one takes roll; no corner springs.",scope:"Both axles",tags:["Two rocker bars","Heave shock","Roll shock"]},{id:"mcpherson",name:"McPherson strut",family:"Road car",description:"A strut clamped to the upright runs up to a top mount on the tower: damper, spring seat and upper link in one. Coilover wishbones at the rear.",scope:"Front struts, rear double wishbones",tags:["McPherson","Strut","Road car"]}],lv=()=>({arbFront:void 0,arbRear:void 0,heaveFront:void 0,heaveRear:void 0}),F6={front:{rockerPivotA:[-47,223,405],rockerPivotB:[-47,267,445],rockerToPushrod:[8,242,429],rockerToDamper:[-47,190,485],damperChassis:[-272,190,485]},rear:{rockerPivotA:[65,228,415],rockerPivotB:[65,272,455],rockerToPushrod:[10,247,439],rockerToDamper:[65,195,495],damperChassis:[290,195,495]}},C6={front:{pushrodOuter:[-3,510,359],rockerPivotA:[-20,174,181],rockerPivotB:[-20,200,139],rockerToPushrod:[18,199,167],rockerToDamper:[-20,102,108],damperChassis:[205,102,108]},rear:{pushrodOuter:[-1,516,365],rockerPivotA:[39,177,181],rockerPivotB:[39,203,139],rockerToPushrod:[1,202,167],rockerToDamper:[39,112,111],damperChassis:[-186,112,111]}},T6=()=>({outer:[0,189,486],attach:"rocker",mount:{kind:"chassis",anchor:[-225,0,486]}}),P6={rate:60,motionRatio:1},L6={front:{rockerPivotA:[-50,310,621],rockerPivotB:[-50,357,659],rockerToPushrod:[10,330,644],rockerToDamper:[-50,281,704],damperChassis:[-275,281,704]},rear:{rockerPivotA:[73,306,621],rockerPivotB:[73,352,659],rockerToPushrod:[13,326,644],rockerToDamper:[73,271,710],damperChassis:[298,271,710]}},D6=e=>e==="front"?{outer:[-2,280,705],attach:"rocker",mount:{kind:"chassis",anchor:[-227,0,705]}}:{outer:[25,270,711],attach:"rocker",mount:{kind:"chassis",anchor:[250,0,711]}},E6={kind:"coil",rate:1560,motionRatio:1,gap:0,bothWays:!0},I6=40,_6={rockerPivotA:[50,130,440],rockerPivotB:[-50,130,440],rockerToPushrod:[10,170,460],rockerToDamper:[-20,64,440],damperChassis:[-20,64,215]},ME=()=>({outer:[-50,130,480],attach:"rocker",shaftStation:-50}),SE=()=>({outer:[50,130,400],inner:[50,130,480],attach:"rocker",shaftStationOuter:50,shaftStationInner:50}),N6=e=>[e[0],e[1],e[2]];function O6(e){let t=r=>({...r,hardpoints:{...r.hardpoints,...wE(_6)},config:{...r.config,actuation:"decoupled"}});return{...e,front:t(e.front),rear:t(e.rear)}}function wE(e){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,N6(r)]))}function FE(e,t=Na(),r=e==="pull"?C6:F6){let n=(o,a)=>({...o,hardpoints:{...o.hardpoints,...wE(r[a])},config:{...o.config,actuation:"rocker",rodType:e,...e==="pull"?{pushrodAttach:"upperArm"}:{}}});return{...t,front:n(t.front,"front"),rear:n(t.rear,"rear")}}function gh(e,t){let r=uv(e),n=Yi(e);if(e==="heave")return{meta:r,vehicle:n,components:{...lv(),heaveFront:{design:{...U0,...P6},linkage:T6()}}};if(e!=="decoupled")return{meta:r,vehicle:n,components:lv()};let o=cv(n,t,"front",{heave:ME(),roll:SE()}),a=cv(n,t,"rear",{heave:ME(),roll:SE()});return{meta:r,vehicle:n,components:{arbFront:o.arb,arbRear:a.arb,heaveFront:o.heave,heaveRear:a.heave}}}function Yi(e){let{name:t}=uv(e);if(e==="direct")return{...ru(),name:t};if(e==="mcpherson"){let n=nu(),o=Up();return{...n,front:{...o,config:{...o.config,loadedRadius:n.front.config.loadedRadius}},name:t}}let r=V6(FE(e==="pullrod"?"pull":"push"));return{...e==="decoupled"?O6(r):r,name:t}}var AE={front:221.7,rear:220.9};function V6(e){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:AE.front}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:AE.rear}}}}function uv(e){let t=bh.find(r=>r.id===e);if(!t)throw new Error(`Unknown suspension template: ${e}`);return t}function yh(){let e=t=>({design:{...E6},linkage:D6(t),damper:I6});return{meta:uv("heave"),vehicle:FE("push",fx(),L6),components:{...lv(),heaveFront:e("front"),heaveRear:e("rear")}}}var CE=[10,25,50,100,200,300],B6=[{id:"c1",label:"Soft",scale:.7},{id:"c2",label:"Medium",scale:1},{id:"c3",label:"Firm",scale:1.4}],TE=e=>Math.round(e*100)/100;function $6(e,t,r){let n=CE.map(o=>TE(r*o));return{id:e,label:t,speedMmS:[...CE],bumpN:n,reboundN:[...n]}}function G6(e){return{name:e.name,body:{...e.body},curves:B6.map(t=>$6(t.id,t.label,TE(e.coefficient*t.scale)))}}function Hu(e,t){let r=(t.heave??t.car).coefficient,n=(t.roll??t.car).coefficient,o=(a,s)=>a?.damper?{...a,damper:s}:a;return{arbFront:o(e.arbFront,n),arbRear:o(e.arbRear,n),heaveFront:o(e.heaveFront,r),heaveRear:o(e.heaveRear,r)}}function An(e,t){let r=i=>{if(!i)return;let c=e.dampers.length+1;for(;e.dampers.some(u=>u.id===`dmp${c}`);)c++;let l=`dmp${c}`;return e.dampers.push({id:l,color:lu[e.dampers.length%lu.length],model:G6(i)}),l},n=r(t.car),o=r(t.rear),a=r(t.heave),s=r(t.roll);for(let i of e.vehicles){let c=i.params;c.damperModelId=n,o&&(c.damperModelIdRear=o),a&&(c.heaveDamperModelId=a),s&&(c.rollDamperModelId=s)}}var Ht=e=>`${e} (typical)`,mv={car:{name:Ht("Formula Student damper"),coefficient:2.5,body:{extended:249,stroke:55}}},xh={car:mv.car,heave:{name:Ht("Formula Student heave damper"),coefficient:3.4,body:{extended:270,stroke:47}},roll:{name:Ht("Formula Student roll damper"),coefficient:3.7,body:{extended:322,stroke:100}}},Rh={car:{name:Ht("Formula 1 damper"),coefficient:6,body:{extended:240,stroke:40}},heave:{name:Ht("Formula 1 heave damper"),coefficient:40,body:{extended:240,stroke:40}}},PE={car:{name:Ht("GT damper"),coefficient:4.5,body:{extended:510,stroke:80}}},dv={car:{name:Ht("Sports car damper"),coefficient:2.4,body:{extended:515,stroke:110}}},LE={car:{name:Ht("Sports car strut"),coefficient:2.4,body:{extended:310,stroke:120}},rear:dv.car},DE={car:{name:Ht("Cup car strut"),coefficient:4,body:{extended:285,stroke:75}},rear:{name:Ht("Cup car rear damper"),coefficient:3.5,body:{extended:505,stroke:80}}},EE={car:{name:Ht("Stock car front damper"),coefficient:7.5,body:{extended:555,stroke:110}},rear:{name:Ht("Stock car rear damper"),coefficient:6.75,body:{extended:555,stroke:110}}},IE={car:{name:Ht("Hill-climb front damper"),coefficient:3,body:{extended:285,stroke:65}},rear:{name:Ht("Hill-climb rear damper"),coefficient:3.5,body:{extended:285,stroke:65}}},_E={car:{name:Ht("Race truck front damper"),coefficient:12,body:{extended:780,stroke:160}},rear:{name:Ht("Race truck rear damper"),coefficient:8.5,body:{extended:780,stroke:160}}};var Oo=(e,t)=>({diameter:e*25.4,width:t*25.4,offset:20,wall:4}),Wi=e=>({front:e,rear:e}),pv=Wi(Oo(13,7)),NE=Wi(Oo(18,12)),OE=Wi(Oo(18,10)),VE=Wi(Oo(17,8)),BE={rear:Oo(17,8)},$E=Wi(Oo(18,9)),GE=Wi(Oo(18,12)),KE={front:Oo(22.5,9)};function co(e,t){for(let r of e.suspensions){let n={...r.model.parts};for(let o of["front","rear"]){let a=t[o];a&&(n[o]={...n[o],rim:{...a}})}(n.front||n.rear)&&(r.model.parts=n)}}function Ui(e){return e.vehicles=e.vehicles.slice(0,1),e.activeVehicleId=e.vehicles[0]?.id??null,e}function Vo(e,t){let r=uu(e);return r.meta.rulesetId=t,r}function as(e,t,r,n){let o=Vo(e,t);return o.suspensions=[{...o.suspensions[0],model:n()}],o.vehicles=[$x(r,"v1",0)],o.activeVehicleId="v1",o}var[,K6,H6,z6,Y6,W6,j6,U6]=kx;function fv(e,t){delete e.arbFrontDesign,delete e.arbRearDesign,delete e.rollBarFrontDesign,delete e.rollBarRearDesign,delete e.heaveFrontDesign,delete e.heaveRearDesign,t.arbFront&&(e.arbFrontDesign=structuredClone(t.arbFront)),t.arbRear&&(e.arbRearDesign=structuredClone(t.arbRear)),t.heaveFront&&(e.heaveFrontDesign=structuredClone(t.heaveFront)),t.heaveRear&&(e.heaveRearDesign=structuredClone(t.heaveRear))}function HE(){return{...Yi("decoupled"),name:Na().name}}var X6=[{label:"Formula Student (decoupled)",vehicle:HE,components:e=>Hu(gh("decoupled",e).components,xh)},{label:"Formula 1 (third springs)",vehicle:()=>yh().vehicle,components:()=>Hu(yh().components,Rh)}],hv={"direct-coilover":"direct",pushrod:"pushrod",pullrod:"pullrod","third-spring":"heave","mcpherson-strut":"mcpherson"},q6=[...X6.map(e=>e.vehicle),...Object.values(hv).map(e=>()=>Yi(e))];function ji(e){let t=Hu(gh("decoupled",e.vehicles[0].params).components,xh);e.suspensions=[{...e.suspensions[0],model:HE()}];for(let r of e.vehicles)fv(r.params,t);return An(e,xh),co(e,pv),e}var ss={title:"OpenStreetMap",url:"https://www.openstreetmap.org/copyright",licence:"ODbL-1.0",credit:"\xA9 OpenStreetMap contributors"},vh={title:"USGS 3D Elevation Program, 1 m lidar terrain",url:"https://www.usgs.gov/3d-elevation-program",licence:"public-domain",credit:"U.S. Geological Survey, 3D Elevation Program"},zE={title:"Digitales Gel\xE4ndemodell DGM1 Rheinland-Pfalz",url:"https://www.geoportal.rlp.de/",licence:"dl-de-by-2.0",credit:"\xA9GeoBasis-DE / LVermGeoRP 2025, dl-de/by-2-0, www.lvermgeo.rlp.de [Daten bearbeitet]"},YE={title:"USDA National Agriculture Imagery Program (NAIP), 0.6 m aerial imagery",url:"https://imagery.nationalmap.gov/arcgis/rest/services/USGSNAIPImagery/ImageServer",licence:"public-domain",credit:"USDA Farm Service Agency, National Agriculture Imagery Program, via the USGS National Map"},Q6={id:"cota",name:"Circuit of the Americas, Austin",address:"e0c6ea889d708cf15f9c",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,vh,YE]}},Z6={id:"laguna-seca",name:"Laguna Seca, Monterey",address:"185b5811b9c423ef44ef",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,vh,YE]}},J6={id:"nordschleife",name:"Nordschleife, N\xFCrburg",address:"74c49603c7b2f15985c6",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,zE]}},eY={id:"brands-hatch",name:"Brands Hatch, Kent",address:"c4953e3c25eaba4a5b7e",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,{title:"Environment Agency LIDAR Composite DTM, 1 m",url:"https://environment.data.gov.uk/dataset/13787b9a-26a4-4775-8523-806d13af58fc",licence:"OGL-UK-3.0",credit:"\xA9 Environment Agency copyright and/or database right 2022. All rights reserved."}]}},tY={id:"bristol",name:"Bristol, Tennessee",address:"f0e23953669a414ad600",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,vh]}},rY={id:"pikes-peak",name:"Pikes Peak, Colorado",address:"3de137fe33b5c2875036",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,vh]},standingStart:!0},nY={source:"venue",altitudeM:3580,pressure:{kind:"standard"},humidityPct:0},oY=10,aY={id:"nurburg-sprint",name:"Sprintstrecke, N\xFCrburg",address:"1875636cdbb615aa2756",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,zE]}};function is(e,t){let{id:r,name:n,address:o,provenance:a,standingStart:s}=t,i={kind:"catalogue",id:r,address:o},c=ou(Dx({name:n,source:i}).model,structuredClone(a));return e.tracks=[{id:"tr1",name:n,source:i,provenance:c,...s?{standingStart:s}:{}}],e.activeTrackId="tr1",e.settings.standingStart=s===!0,e}function Bo(e,t,r){let n=e.vehicles[0].params,o=`m${e.motors.length+1}`;e.motors=[...e.motors,{id:o,color:Lo[e.motors.length%Lo.length],model:t}];let a=Dw({},{...n,motorModel:t});n.motorModelId=o,n.motorCount=1,a&&(n.driveline=a),n.gear_ratio&&(n.gear_ratio={...n.gear_ratio,value:r})}var sY=3.8,kh={hubPlanetary:14.5,inboardChain:4,engineChain:3.4},iY="Hub motor, 35 kW (example)";function bv(e,t,r,n,o,a){let s=e.vehicles[0].params;s.motorModelId=t,s.motorCount=r,s.motorPlacement=n,a&&(s.motorMount=a),s.driven_wheels={...s.driven_wheels,value:n==="awd"?4:2},s.gear_ratio={...s.gear_ratio,value:o}}function WE(e){let t=e.motors.find(r=>r.id==="m1");return t.model={...t.model,name:iY},t.id}function Mh(e,t,r){let n=Ui(ji(Vo(e,r)));return n.vehicles[0].params.name=t,n}function cY(){let e=Mh("Formula Student combustion car","Formula Student combustion","fs-cv");Bo(e,Fx(),kh.engineChain);let t=e.vehicles[0].params;return t.power_limit_kw&&(t.power_limit_kw={...t.power_limit_kw,value:0}),t.endurance_reserve&&(t.endurance_reserve={...t.endurance_reserve,value:0}),e}function lY(){let e=Mh("Formula Student AWD car","Formula Student AWD","fs-ev");return bv(e,WE(e),4,"awd",kh.hubPlanetary,"hub"),e}function uY(){let e=Mh("Formula Student RWD hub-motor car","Formula Student RWD hub motors","fs-ev");return bv(e,WE(e),2,"rear",kh.hubPlanetary,"hub"),e}function mY(){let e=Mh("Formula Student one-motor car","Formula Student RWD one motor","fs-ev"),t=`m${e.motors.length+1}`;return e.motors=[...e.motors,{id:t,color:Lo[e.motors.length%Lo.length],model:wx()}],bv(e,t,1,"rear",kh.inboardChain),e.vehicles[0].params.driveline={rear:structuredClone(er.clutch)},e}function dY(){let e=Ui(ji(Vo("Formula Student endurance energy","fs-ev"))),t=e.vehicles[0],r=structuredClone(t);if(r.id="v2",r.color=cu[1],r.params.name=`${t.params.name} flat out`,!r.params.endurance_reserve)throw new Error("the Formula Student preset states no energy reserve");return r.params.endurance_reserve={...r.params.endurance_reserve,value:0},e.vehicles.push(r),e}function pY(){let e=yh(),t=as("Formula 1 car","trackday",K6,()=>e.vehicle);return fv(t.vehicles[0].params,Hu(e.components,Rh)),An(t,Rh),co(t,NE),Bo(t,Cx(),sY),is(t,Q6)}function jE(e="GT car",t=ru){let r=as(e,"trackday",H6,t);return An(r,PE),co(r,OE),Bo(r,AT(),r.vehicles[0].params.gear_ratio.value),is(r,Z6)}function UE(e="Sports car",t=nu,r=dv,n=VE){let o=as(e,"trackday",z6,t);return An(o,r),co(o,n),Bo(o,wT(),o.vehicles[0].params.gear_ratio.value),is(o,J6)}function fY(){let e=as("Cup car","trackday",Y6,pT);return An(e,DE),co(e,$E),Bo(e,FT(),e.vehicles[0].params.gear_ratio.value),is(e,eY)}function hY(){let e=as("Stock car","trackday",W6,fT);return An(e,EE),co(e,GE),Bo(e,CT(),e.vehicles[0].params.gear_ratio.value),is(e,tY)}function bY(){let e=as("Hill-climb prototype","trackday",j6,hT);return An(e,IE),Bo(e,TT(),e.vehicles[0].params.gear_ratio.value),e.settings.air=structuredClone(nY),e.settings.airTempC=oY,is(e,rY)}function gY(){let e=as("Race truck","trackday",U6,bT);return An(e,_E),co(e,KE),Bo(e,PT(),e.vehicles[0].params.gear_ratio.value),is(e,aY)}function yY(e){let t=bh.find(o=>o.id===e);if(e==="direct")return jE(t.name,()=>Yi(e));if(e==="mcpherson")return UE(t.name,()=>Yi(e),LE,BE);let r=Ui(Vo(t.name,"trackday")),n=gh(e,r.vehicles[0].params);return r.suspensions=[{...r.suspensions[0],model:n.vehicle}],fv(r.vehicles[0].params,n.components),An(r,mv),co(r,pv),r}function zu(e,t,r){let n=hv[e],o=bh.find(a=>a.id===n);return{id:e,domain:"racecar",kind:"start",summary:t,title:o.name,blurb:`${o.description} ${r} Move a hardpoint in Kinematics and watch the motion ratio, camber and roll centre follow, then what it costs on track.`,tags:["kinematics","suspension",...o.tags.map(a=>a.toLowerCase())],openTool:"kinematics",load:()=>yY(n)}}var xY=[{id:"fs-ev-comparison",domain:"racecar",kind:"study",summary:"Four Formula Student cars scored on all five events: what mass, power and downforce buy.",title:"Formula Student \u2014 car comparison",blurb:"A generic Formula Student electric car and three what-ifs \u2014 15 % more downforce, 15 kg lighter, 15 % more power \u2014 scored side by side on the Formula Student electric events. All four run decoupled heave and roll suspension. A good first look at what each change buys.",tags:["formula student","comparison","lap sim"],openTool:"laptime",load:()=>ji(Vo("Formula Student comparison","fs-ev"))},{id:"fs-endurance-energy",domain:"racecar",kind:"study",summary:"The FS car flat out against its energy target: which finishes endurance, and the points.",title:"Formula Student \u2014 endurance energy",blurb:"The generic Formula Student electric car twice, scored together on the Formula Student electric events: once driven to its energy target, once flat out. The two differ in the endurance reserve and nothing else. Flat out the car laps faster and its pack runs out before the flag; on the target its speed is capped so the pack finishes with 5 % left. The endurance event shows the charge lap by lap, and the points what running dry costs.",tags:["formula student","endurance","energy","battery"],openTool:"laptime",load:dY},{id:"fs-ev-single",domain:"racecar",kind:"start",summary:"A generic Formula Student electric car on the five events, to set up as your own.",title:"Formula Student \u2014 single car",blurb:"One generic Formula Student electric car on the Formula Student electric events: 300 kg with driver, two motors, 80 kW, 10-inch tyres, decoupled heave and roll suspension. The uncluttered starting point for setting up your own car.",tags:["formula student","lap sim"],openTool:"laptime",load:()=>Ui(ji(Vo("Formula Student car","fs-ev")))},{id:"fs-combustion",domain:"racecar",kind:"start",summary:"A restricted 600 cc four through six gears and a clutch-pack diff, on the CV events.",title:"Formula Student \u2014 combustion, LSD",blurb:"The generic Formula Student car with an engine: a restricted 600 cc four of about 64 kW through a six-speed box and a chain to a clutch-pack limited-slip diff, on the Formula Student combustion events. The same 300 kg chassis, tyres and decoupled suspension as the electric layouts, so the drive is the difference. Efficiency is scored on the work at the crankshaft until fuel is modelled. Representative of the class, not a measurement of any car.",tags:["formula student","combustion","engine","limited-slip diff","lsd","lap sim"],openTool:"laptime",load:cY},{id:"fs-ev-awd",domain:"racecar",kind:"start",summary:"All-wheel drive from a motor in each hub, held to 80 kW at the pack.",title:"Formula Student \u2014 AWD, four hub motors",blurb:"The generic Formula Student electric car with a motor in each of its four hubs: 35 kW hub motors on 14.5 : 1 planetaries, held to the rules\u2019 80 kW at the pack, each wheel\u2019s torque its own and every wheel braking back into the pack. The same 300 kg chassis, tyres, suspension and pack as the other layouts, so the drive is the difference; the hub motors\u2019 unsprung mass is not added. Representative of the class, not a measurement of any car.",tags:["formula student","awd","all-wheel drive","hub motors","outboard motors","lap sim"],openTool:"laptime",load:lY},{id:"fs-ev-rwd-hubs",domain:"racecar",kind:"start",summary:"Rear-wheel drive from a motor in each rear hub, with no diff between them.",title:"Formula Student \u2014 RWD, two hub motors",blurb:"The generic Formula Student electric car driven by a motor in each rear hub: two 35 kW hub motors on 14.5 : 1 planetaries with no differential between them, so each rear wheel\u2019s torque is set on its own. The pair cannot use all of the rules\u2019 80 kW. The same 300 kg chassis, tyres, suspension and pack as the other layouts, so the drive is the difference. Representative of the class, not a measurement of any car.",tags:["formula student","rwd","rear-wheel drive","hub motors","outboard motors","lap sim"],openTool:"laptime",load:uY},{id:"fs-ev-one-motor",domain:"racecar",kind:"start",summary:"One inboard motor chained to a clutch-pack diff on the rear axle.",title:"Formula Student \u2014 RWD, one motor, LSD",blurb:"The generic Formula Student electric car on one inboard motor: an axial-flux motor of 230 Nm on the chassis, chained at 4 : 1 to a clutch-pack limited-slip diff on the rear axle. The rules\u2019 80 kW at the pack holds it below its peak, and it brakes back into the pack through the diff. The same 300 kg chassis, tyres, suspension and pack as the other layouts, so the drive is the difference. Representative of the class, not a measurement of any car.",tags:["formula student","rwd","inboard motor","limited-slip diff","lsd","lap sim"],openTool:"laptime",load:mY},{id:"formula-1",domain:"racecar",kind:"start",summary:"A generic Formula 1 car on a flying lap of Austin.",title:"Formula 1 car",blurb:"A generic Formula 1 car of the 18-inch era at Austin: 798 kg with driver, a 735 kW power unit through eight gears and a clutch-pack diff, four and a half square metres of lift area on a 3.6 m wheelbase, pushrods with a third spring and heave damper on each axle, slicks with 1.8 of peak grip. One flying lap, no scoring. Every number is representative of the class, none is a measurement.",tags:["formula 1","lap sim","aero"],openTool:"laptime",load:pY},{id:"touring-car",domain:"racecar",kind:"start",summary:"A generic GT car on a flying lap of Laguna Seca.",title:"GT car",blurb:"A generic GT car at Laguna Seca: 1300 kg with driver, a 410 kW four-litre through six gears and a clutch-pack diff, 2.8 m\xB2 of lift area, coilovers on double wishbones, 18-inch slicks. One flying lap, no scoring. Representative of the class, not a measurement of any car.",tags:["gt","lap sim"],openTool:"laptime",load:jE},{id:"street-car",domain:"racecar",kind:"start",summary:"A generic sports car on road tyres, round the Nordschleife.",title:"Sports car",blurb:"A generic sports car on the Nordschleife: 1600 kg with driver, a 220 kW turbocharged six through a six-speed double-clutch box and an open diff, road tyres with about 1.0 of grip, soft springs and a little aerodynamic lift. One flying lap, no scoring. The car to start from when the question is a road car, and the one that shows what a race car's numbers actually buy.",tags:["sports car","road car","lap sim"],openTool:"laptime",load:UE},{id:"cup-car",domain:"racecar",kind:"start",summary:"A generic front-driven cup hatchback round Brands Hatch.",title:"Cup car",blurb:"A generic front-wheel-drive cup hatchback at Brands Hatch: 1265 kg with driver, a 250 kW two-litre turbo through six gears and a clutch-pack diff, a splitter and a wing, a McPherson strut front, 18-inch slicks. One flying lap, no scoring. Representative of the class, not a measurement of any car.",tags:["cup car","front-wheel drive","lap sim"],openTool:"laptime",load:fY},{id:"stock-car",domain:"racecar",kind:"start",summary:"A generic stock car on Bristol\u2019s half-mile, banked 25\xB0.",title:"Stock car",blurb:"A generic stock car of the American oval series at Bristol, the half-mile banked 25\xB0: 1620 kg with driver, a 500 kW 5.9-litre V8 through five gears and a clutch-pack diff, double wishbones on stiff springs, 18-inch slicks, set up the same on both sides. One flying lap, no scoring. Representative of the class, not a measurement of any car.",tags:["stock car","oval","lap sim"],openTool:"laptime",load:hY},{id:"hill-climb",domain:"racecar",kind:"start",summary:"A generic hill-climb prototype up Pikes Peak, from rest, in thin air.",title:"Hill-climb prototype",blurb:"A generic hill-climb sports prototype on Pikes Peak, 19.99 km and 1,440 m up to the summit: 650 kg with driver, a 330 kW turbocharged two-litre through six gears and a clutch-pack diff, 3 m\xB2 of lift area, pushrods, 13-inch slicks. It runs in the mountain\u2019s thin air, which costs its wings a third of their downforce. One run, no scoring. Representative of the class, not a measurement of any car.",tags:["hill climb","altitude","lap sim"],openTool:"laptime",load:bY},{id:"race-truck",domain:"racecar",kind:"start",summary:"A generic European race truck round the N\xFCrburg Sprintstrecke, held to 160 km/h.",title:"Race truck",blurb:"A generic European circuit race truck on the N\xFCrburg Grand Prix circuit\u2019s 3.6 km Sprintstrecke: a cab-over tractor at the class\u2019s 5300 kg minimum, 60 % of it on the front axle, an 880 kW 13-litre diesel through a twelve-speed box to a locked rear axle, geared to the 160 km/h the rules hold it to, 315/70 R22.5 tyres. One flying lap, no scoring. Representative of the class, not a measurement of any truck.",tags:["race truck","truck racing","lap sim"],openTool:"laptime",load:gY},{id:"suspension",domain:"racecar",kind:"study",summary:"The FS car\u2019s decoupled wishbones: move a hardpoint and watch the roll centre follow.",title:"Suspension kinematics study",blurb:"Opens on the double-wishbone editor with one Formula Student car. Move a hardpoint and watch camber, bump steer, motion ratio and roll-centre migration follow \u2014 then see what it costs on track.",tags:["kinematics","geometry"],openTool:"kinematics",load:()=>Ui(ji(Vo("Suspension study","trackday")))},zu("direct-coilover","The GT car\u2019s wishbones driving coilovers straight into the towers, at Laguna Seca.","On the GT car, at Laguna Seca."),zu("pushrod","The FS car on pushrods: a rod from each lower wishbone works a rocker.","On the Formula Student car, at FSG."),zu("pullrod","The FS car on pullrods: a rod from each upper wishbone pulls a low rocker.","On the Formula Student car, at FSG."),zu("third-spring","The pushrod FS car plus a front third spring that picks up after 5 mm of bump.","On the Formula Student car, at FSG."),zu("mcpherson-strut","The sports car on McPherson struts at the front and double wishbones at the rear.","On the sports car, at the Nordschleife."),{id:"tyre-study",domain:"racecar",kind:"study",summary:"The FS tyre\u2019s grip curves at three loads, beside the other classes\u2019 tyres.",title:"Tyre model study",blurb:"One Formula Student car on its Magic Formula tyre, opened on the tyre analysis, where the grip curves that drive the whole lap come from. The library beside it holds the other seven classes' tyres and the illustrative MF6.2 example to compare against.",tags:["tyres","magic formula"],openTool:"tires",load:()=>Ui(ji(Vo("Tyre study","fs-ev")))}],XE=xY.map(e=>({...e,load:()=>Gx(e.load())}));var qE={width:320,height:200},VTe=[.6*qE.width-9,.6*qE.height-9];var QE=new WeakMap,ZE=new WeakMap,gv=e=>JSON.stringify(e,(t,r)=>r===1/0?"Infinity":r);function JE(e,t){if(!t){let a=QE.get(e);return a||(a=hr(e),QE.set(e,a)),a}let r=ZE.get(e);r||(r=new Map,ZE.set(e,r));let n=gv(t),o=r.get(n);return o||(r.size>=4&&r.clear(),o=hr(e,t),r.set(n,o)),o}var kY=Math.PI/180,MY=e=>e>1?e/100:e;function Yu(e){let t=null;return()=>(t??={v:e()}).v}function eI(e){let t=ut(e,{travelMin:-1,travelMax:1,steps:3}).samples[1],r=t.metrics.motionRatio??1;return{motionRatio:r,wheelRate:t.metrics.wheelRate??e.config.springRate*r*r}}var tI=new WeakMap,yv={heave:0,pitch:0,roll:0,steer:0},rI=[0,1,2,3,4],nI=[-20,-10,0,10,20];function aI(e,t){let r=Xn(e,yv),n=["front","rear"],o=c=>{let l=ti(c);return l?(l.left+l.right)/2:Number.NaN},a=n.map(c=>o(r[c])),s=n.map(()=>({rc:[],split:[]}));for(let c of rI){let l=c===0?null:Xn(e,{...yv,roll:c*kY});n.forEach((u,m)=>{let p=l?ti(l[u]):null,d=p&&Number.isFinite(a[m]);s[m].rc.push(d?t[m]+(p.left+p.right)/2-a[m]:t[m]),s[m].split.push(d?(p.left-p.right)/2:0)})}let i=n.map(()=>[]);for(let c of nI){let l=c===0?null:Xn(e,{...yv,heave:-c});n.forEach((u,m)=>{let p=l&&l[u].valid&&r[u].valid;i[m].push(p?t[m]+l[u].height-r[u].height:t[m])})}return{roll:{rollDeg:rI,rcFront:s[0].rc,rcRear:s[1].rc,rcSplitFront:s[0].split,rcSplitRear:s[1].split},heave:{drop:nI,rcFront:i[0],rcRear:i[1]}}}var oI=new WeakMap;function SY(e,t,r,n){let o=oI.get(e);o||(o=new Map,oI.set(e,o));let a=`${gv(r)}|${n[0]}|${n[1]}`,s=o.get(a);if(!s){o.size>=4&&o.clear();try{s=aI(JE(e,r),n)}catch{s=t.rigidMigration(n)}o.set(a,s)}return s}function AY(e){let t=tI.get(e);if(t)return t;let r=hr(e),n=Xn(r,{heave:0,pitch:0,roll:0,steer:0}),o=eI(e.front),a=eI(e.rear),s={wheelbase:e.config.wheelbase,trackFront:Qt(e.front),trackRear:Qt(e.rear),mrFront:o.motionRatio,mrRear:a.motionRatio,wheelRateFront:o.wheelRate,wheelRateRear:a.wheelRate,unsprungCgHeight:e.front.config.loadedRadius,rcHeightFront:n.front.valid?n.front.heightAboveGround:0,rcHeightRear:n.rear.valid?n.rear.heightAboveGround:0,rcGainFront:ni(n.front),rcGainRear:ni(n.rear),rigidMigration:i=>aI(r,i),kinFront:Yu(()=>Vs(e.front)),kinRear:Yu(()=>Vs(e.rear))};return tI.set(e,s),s}function sI(e,t,r,n){let o=AY(e),a=vl(e,t),s=ba(e,t),i=Aw(e,t),c=Hd(e,t),l=ww(e,t),u=Fw(t,e),m=zd(e,t),p=un(e.front),d=un(e.rear),f=pa(t.damperModel,t.damperSetup,o.mrFront,o.mrRear,t.damperModelRear??t.damperModel),h={rho:t.rho.value,area:t.A.value,cl:t.c_l.value,cw:t.c_w.value,copLongFront:1-Math.max(0,Math.min(1,J(t,"cop_long"))),copHeight:J(t,"cop_height"),...t.aeroModel?{model:t.aeroModel}:{},rideHeightFront:J(t,"ride_height_front"),rideHeightRear:J(t,"ride_height_rear")},b=9.81,g=MY(t.front_mass_diss.value),y=Ra(t,r,n),x=We(y.front),R=y.rear===y.front?x:We(y.rear),v=n??t.tireModelRear??r,S=t.m.value*b*g/2,A=t.m.value*b*(1-g)/2,F=x.corneringStiffness(S),w=R.corneringStiffness(A),T=(r?x.verticalStiffness():0)||J(t,"tire_vertical_rate"),M=(v?R.verticalStiffness():0)||J(t,"tire_vertical_rate"),k=an(r)??0,C=an(v)??0,P=Xd({freeRadius:k,staticLoad:S,tyreRate:T,surveyed:e.front.config.loadedRadius},{freeRadius:C,staticLoad:A,tyreRate:M,surveyed:e.rear.config.loadedRadius},g),L=wr(k,S,T,e.front.config.loadedRadius),E=wr(C,A,M,e.rear.config.loadedRadius),_=[qn(o.rcHeightFront,o.rcGainFront,e.front.config.loadedRadius,L),qn(o.rcHeightRear,o.rcGainRear,e.rear.config.loadedRadius,E)],D=Yu(()=>Ml(o.kinFront(),J(t,"camber_front_deg"))),I=Yu(()=>Ml(o.kinRear(),J(t,"camber_rear_deg"))),N=Yu(()=>SY(e,o,Ii(H),_)),O=Xc({...t,wheelbase:{...t.wheelbase,value:o.wheelbase}}),V=kl(t),H={massTotal:t.m.value,frontMassFrac:g,steeringSystem:t.steeringSystem,tv:Ld(t),cgHeight:ai(J(t,"cg_height"),t.cgReference?.standingRadius,P),cgStandingRadius:P,wheelbase:o.wheelbase,trackFront:o.trackFront,trackRear:o.trackRear,wheelRateFront:p?0:o.wheelRateFront,wheelRateRear:d?0:o.wheelRateRear,decoupledFront:p,decoupledRear:d,...u.front?{elementLinkagesFront:u.front}:{},...u.rear?{elementLinkagesRear:u.rear}:{},...m.front.source==="part"?{cornerCoiloverFront:m.front.coilover}:{},...m.rear.source==="part"?{cornerCoiloverRear:m.rear.coilover}:{},...m.heaveFront.coilover?{heaveCoiloverFront:m.heaveFront.coilover}:{},...m.heaveRear.coilover?{heaveCoiloverRear:m.heaveRear.coilover}:{},...i.front&&!p?{heaveSeatFront:i.front}:{},...i.rear&&!d?{heaveSeatRear:i.rear}:{},...m.rollFront.coilover?{rollCoiloverFront:m.rollFront.coilover}:{},...m.rollRear.coilover?{rollCoiloverRear:m.rollRear.coilover}:{},tireRate:T,...M!==T?{tireRateRear:M}:{},tireDamping:J(t,"tire_vertical_damping"),arbFront:a.front??J(t,"arb_front"),arbRear:a.rear??J(t,"arb_rear"),brakeBalanceFront:O.balanceFront,brakes:O,...V?{driveline:V}:{},heaveSpringFront:s.front??J(t,"heave_spring_front"),heaveSpringRear:s.rear??J(t,"heave_spring_rear"),unsprungPerCorner:J(t,"unsprung_mass"),unsprungCgHeight:wr(k,S,T,o.unsprungCgHeight),tyreFreeRadius:k,...C!==k?{tyreFreeRadiusRear:C}:{},rcHeightFront:_[0],rcHeightRear:_[1],corneringStiffnessFront:F,corneringStiffnessRear:w,get kinFront(){return D()},get kinRear(){return I()},damperFront:p?0:f?.front?.rate??J(t,"damper_front")*o.mrFront*o.mrFront,damperRear:d?0:f?.rear?.rate??J(t,"damper_rear")*o.mrRear*o.mrRear,...f?.front&&!p?{damperCurveFront:f.front.curve}:{},...f?.rear&&!d?{damperCurveRear:f.rear.curve}:{},heaveDamperFront:l.heaveFront?.rate??c.heaveFront,heaveDamperRear:l.heaveRear?.rate??c.heaveRear,rollDamperFront:l.rollFront?.rate??c.rollFront,rollDamperRear:l.rollRear?.rate??c.rollRear,...l.heaveFront?{heaveDamperCurveFront:l.heaveFront.curve}:{},...l.heaveRear?{heaveDamperCurveRear:l.heaveRear.curve}:{},...l.rollFront?{rollDamperCurveFront:l.rollFront.curve}:{},...l.rollRear?{rollDamperCurveRear:l.rollRear.curve}:{},unsprungCornerMass:J(t,"unsprung_mass"),get rollCentreCurve(){return N().roll},get rcHeaveCurve(){return N().heave},aero:h,yawInertia:J(t,"I_yaw"),rollInertia:J(t,"I_roll"),pitchInertia:J(t,"I_pitch"),...da(t)?{chassisTorsion:da(t)}:{},...il(t,"front")?{twistInertiaFront:il(t,"front")}:{},...il(t,"rear")?{twistInertiaRear:il(t,"rear")}:{},get steerFront(){return Yd(e.front,L)},ackermannPct:J(t,"ackermann_pct"),toeFrontDeg:J(t,"toe_front_deg"),toeRearDeg:J(t,"toe_rear_deg")};return H}var cI=e=>({tire:t=>t==null?void 0:t===e.tireModelIdRear&&e.tireModelRear?e.tireModelRear:e.tireModel,motor:()=>e.motorModel,aero:()=>e.aeroModel,battery:()=>e.batteryModel,brake:()=>e.brakeModel,damper:t=>t!=null&&t===e.damperModelIdRear&&e.damperModelRear?e.damperModelRear:t!=null&&t===e.heaveDamperModelId?e.heaveDamperModel:t!=null&&t===e.rollDamperModelId?e.rollDamperModel:e.damperModel}),Rv={ggvMode:"twoTrack"},iI=new WeakMap;function vv(e,t=Rv){let r=iI.get(e.vehicle);r||iI.set(e.vehicle,r=new WeakMap);let n=r.get(e.params);n||r.set(e.params,n=new Map);let o=JSON.stringify(t),a=n.get(o);if(!a){n.size>=8&&n.clear();let s={...cI(e.params),suspensionOf:()=>e.vehicle};n.set(o,a=ns(e.params,s,t))}return a}var lI=(e=Rv)=>t=>vv(t,e),Sh=(e=Rv)=>t=>sI(t.vehicle,j1(t.params,cI(t.params),e),t.params.tireModel,t.params.tireModelRear);function wY(e,t){return vv(e,t.switches)}var kv=e=>xr(e?.rulesets);function uI(e,t,r,n,o={},a=()=>r.standingStart){let s=vv(n,r.switches),i=(l,u)=>{let m=$p(l,t,{racingLine:r.racingLine,params:s});return{asset:m.asset,numerics:m.numerics,standingStart:u,racingLine:r.racingLine}},c=Object.fromEntries(Object.entries(o).map(([l,u])=>[l,i(u,a(l))]));return{course:e?i(e,r.standingStart):null,numerics:t,tracks:c,switches:r.switches}}var mI=e=>[...new Set(e.lap.courses.flatMap(t=>t.course.kind==="track"?[t.course.trackId]:[]))],dI=e=>{let t=e?.session;return t?{sessionParams:r=>wY(r,t),session:()=>t}:{}},ju=e=>({metrics:kv(e),assemble:Sh(e?.switches),simParams:lI(e?.switches),projectTrack:()=>e?.course??null,libraryTrack:t=>e?.tracks?.[t]??null,numerics:e?.numerics,...dI(e)}),FY=(e,t)=>({density:e.density,envelope:e.envelope,states:e.states,operating:e.operating,assemble:Sh(t)}),CY=(e,t)=>({...FY(e,t?.switches),lap:e.lap,simParams:lI(t?.switches),projectTrack:()=>t?.course??null,libraryTrack:r=>t?.tracks?.[r]??null,numerics:t?.numerics,...dI(t)}),pI="nelder-mead",fI=600,Wu=[0,.15,.15];function hI(e,t,r,n=Wu.length){let o=Av(t);return Wu.slice(0,Math.max(1,n)).map((a,s)=>({...e,seed:s+1,startJitter:a,car:o,...r?{lap:r}:{}}))}function bI(e,t,r=.5){let n=[];return e.forEach((o,a)=>{let s=o.hi-o.lo;if(s<=0)return;let i=Math.min(r,s*.01);t[a]<=o.lo+i?n.push({id:o.id,name:o.name,unit:o.unit,at:"lo",value:t[a],moved:t[a]-o.start}):t[a]>=o.hi-i&&n.push({id:o.id,name:o.name,unit:o.unit,at:"hi",value:t[a],moved:t[a]-o.start})}),n}function gI(e,t,r,n,o=.01){let a=kv(n).byId;return TY(e,t,r,n).filter(s=>s.excess>-o*(a[s.metricId]?.scale??1))}function TY(e,t,r,n){let o;try{o=Eo(zi(e,t,r),CY(t,n))}catch{return[]}return PY(o,t,kv(n))}function PY(e,t,r){let n=[];for(let o of t.constraints){let a=r.byId[o.metricId];if(!a)continue;let s=vt(e,a,o.at);if(!Number.isFinite(s))continue;let i=`${bt(a)}${Ja(o.at,a)}`;n.push({key:o.key,metricId:o.metricId,label:i,unit:a.unit==="-"?"":a.unit,value:s,excess:No(o,s)})}return n}var LY=.05;function DY(e,t){if(t.id.startsWith("hp.")||eh(t.id))return 1;let r=/^rocker\.(front|rear)\.(\w+)$/.exec(t.id);if(r){let a=r[1]==="front"?e.vehicle.front:e.vehicle.rear;return S1(_o(a.hardpoints),r[2],1)}let n=/^arm\.(front|rear)\.(uca|lca)\.(\w+)$/.exec(t.id);if(!n)return null;let o=n[1]==="front"?e.vehicle.front:e.vehicle.rear;return v1(so(o.hardpoints,n[2]),n[3],1)}function yI(e,t,r){let n=r.filter(p=>p.score.feasible);if(n.length<2)return null;let o=t.map(p=>DY(e,p)),a=o.every(p=>p!==null)?"mm":null,s=0,i="",c=0,l=n.reduce((p,d)=>d.score.total<p.score.total?d:p);for(let p of n)if(p!==l)for(let d=0;d<t.length;d++){let f=Math.abs(p.x[d]-l.x[d])*(o[d]??1);c+=f*f,f>s&&(s=f,i=t[d].name)}let u=n.map(p=>p.score.total),m=l.score.terms.reduce((p,d)=>p+(d.resolution??0),0);return{distance:Math.sqrt(c),worst:s,worstName:i,scoreSpread:Math.max(...u)-Math.min(...u),tolerance:Math.max(LY,m),unit:a}}var EY={steeringSystem:!0,brakeSetup:!0,driveline:!0,heaveFrontDesign:!0,heaveRearDesign:!0,arbFrontDesign:!0,arbRearDesign:!0,rollBarFrontDesign:!0,rollBarRearDesign:!0},xI=e=>Object.hasOwn(EY,e);function xv(e){let[t,r]=e.split("."),n=r==="front"?"Front":r==="rear"?"Rear":null;return n?t==="heave"?`heave${n}Design`:t==="roll"?`arb${n}Design`:t==="rollBar"?`rollBar${n}Design`:null:null}function IY(e){let t=e.split(".")[0];return t==="hp"||t==="arm"||t==="rocker"?"hardpoint":t==="cfg"?"config":t==="kc"?"compliance":t==="param"?"param":t==="brakeModel"?"part":xI(t)||xv(e)?"block":null}function Mv(e,t){t=Kt(e,t);let r=gt(e);return[...t.variables,...t.followers??[]].filter(n=>r[n.id]&&!r[n.id].supersededBy&&!IY(n.id)).map(n=>dt(r[n.id]))}function Ah(e,t,r){t=Kt(e,t);let n=gt(e),o=zi(e,t,r),a=[],s=new Set,i=new Set;for(let c of[...t.variables,...t.followers??[]]){let l=n[c.id];if(!l||l.supersededBy)continue;let u=l.read(o),[m,p,d,f]=c.id.split(".");if(m==="rocker"){let h=`${p}.rocker`;if(i.has(h))continue;i.add(h);let b=p==="front"?o.vehicle.front:o.vehicle.rear;for(let g of[Sn.fore,Sn.aft]){let y=b.hardpoints[g];for(let x=0;x<3;x++)a.push({kind:"hardpoint",axle:p,key:g,axis:x,value:y[x]})}}else if(m==="arm"){let h=`${p}.${d}`;if(i.has(h))continue;i.add(h);let b=p==="front"?o.vehicle.front:o.vehicle.rear,g=Rr[d];for(let y of[g.fore,g.aft]){let x=b.hardpoints[y];for(let R=0;R<3;R++)a.push({kind:"hardpoint",axle:p,key:y,axis:R,value:x[R]})}}else if(m==="hp"&&Pr(c.id)){let h=`${p}.${d}`;if(i.has(h))continue;i.add(h);let b=(p==="front"?o.vehicle.front:o.vehicle.rear).hardpoints[d];for(let g=0;g<3;g++)a.push({kind:"hardpoint",axle:p,key:d,axis:g,value:b[g]})}else if(m==="hp")a.push({kind:"hardpoint",axle:p,key:d,axis:"xyz".indexOf(f),value:u});else if(m==="cfg")a.push({kind:"config",axle:p,field:d,value:u});else if(m==="kc"){if(s.has(`kc.${p}`))continue;s.add(`kc.${p}`);let h=p==="front"?o.vehicle.front:o.vehicle.rear;a.push({kind:"compliance",axle:p,value:h.compliance})}else if(m==="param")a.push({kind:"param",label:dt(l),value:u});else if(m==="brakeModel"){if(s.has(m))continue;if(s.add(m),!o.params.brakeModel)throw new Error(`optimiser: "${c.id}" left the car with no brake part to adopt`);a.push({kind:"part",key:"brakeModel",fromId:e.params.brakeModelId,value:o.params.brakeModel})}else if(xI(m)||xv(c.id)){let h=xv(c.id)??m;if(s.has(h))continue;s.add(h);let b=o.params[h];if(!b)throw new Error(`optimiser: "${c.id}" left the car with no ${h} to adopt`);a.push({kind:"block",key:h,value:b})}else throw new Error(`optimiser: Adopt has no way to write "${c.id}" back into the project`)}return a}function Sv(e){let t=performance.now(),r=ju(e.lap),n=e.follow?I1(e.car,e.spec,r):e.spec,{dead:o,unprobed:a,...s}=V1(e.car,n,r);return{...s,deadIds:o.map(i=>i.id),unprobedIds:a.map(i=>i.id),elapsedMs:performance.now()-t,...e.follow?{followed:!0,fromCar:n===e.spec?null:{states:n.states,envelope:n.envelope}}:{}}}function RI(e){let t=performance.now();return{tolerance:rv(e.car,e.spec,e.x,ju(e.lap),e.mm),elapsedMs:performance.now()-t}}var Av=e=>e.vehicle.chassis?{...e,vehicle:nv(e.vehicle)}:e;function vI(e,t){try{let r=wv(e.car,e.spec,e.lap),n=Gs.find(u=>u.name===e.method);if(!n)throw new Error(`unknown method "${e.method}"`);t({kind:"progress",seed:e.seed,progress:{evaluations:0,budget:e.budget,x:Gr(r.variables),score:On(r,Gr(r.variables)),infeasible:0}});let o=e.from,a=o?{...r,variables:r.variables.map((u,m)=>({...u,start:Number.isFinite(o[m])?o[m]:u.start}))}:r,s=performance.now(),i=n.run(a,{budget:e.budget,seed:e.seed,startJitter:e.startJitter,progressEvery:20,onProgress:u=>t({kind:"progress",seed:e.seed,progress:u})}),c=performance.now()-s,l=i.score.feasible&&F1(r.variables)?T1(r,i.x,i.score):void 0;t({kind:"done",seed:e.seed,result:l?{...i,snapped:l}:i,elapsedMs:c})}catch(r){t({kind:"error",seed:e.seed,message:r instanceof Error?r.message:String(r)})}}var wv=(e,t,r)=>es(e,t,ju(r));function kI(e,t){let r=e.tireModelIdRear?t.tire(e.tireModelIdRear):void 0;return{tireModel:t.tire(e.tireModelId),...r?{tireModelRear:r}:{},motorModel:t.motor(e.motorModelId),aeroModel:t.aero(e.aeroModelId),batteryModel:t.battery(e.batteryModelId),brakeModel:t.brake(e.brakeModelId),damperModel:t.damper(e.damperModelId),...ml(e,t.damper)}}function MI(e,t,r,n){let{tireModelRear:o,damperModelRear:a,heaveDamperModel:s,rollDamperModel:i,...c}=r;return{vehicle:e,params:{...t,...c,...o?{tireModelRear:o}:{},...a?{damperModelRear:a}:{},...s?{heaveDamperModel:s}:{},...i?{rollDamperModel:i}:{}},...Da(n)?{sessionAir:!0}:{}}}var wh=e=>({ggvMode:e.ggvMode,quasiTransient:e.quasiTransient===!0&&e.ggvMode!=="fast",motorThermal:e.motorThermal===!0,...YD({brakeFade:e.brakeFade===!0,airTempC:e.airTempC,diffYaw:e.diffYaw===!0,...e.air?{air:e.air}:{}})});function _Y(e){if(!(e.plannedPath!==void 0||!e.track))return{track:e.track,numerics:e.numerics,settings:{racingLine:e.racingLine,standingStart:e.standingStart,...Object.keys(e.lapCounts).length?{lapCounts:e.lapCounts}:{}},switches:e.switches,rulesets:e.rulesets}}function SI(e,t){let r=t.plannedPath!==void 0,n=_Y(t);return{...uI(r?t.plannedPath:t.track,t.numerics,{racingLine:r?!1:t.racingLine,standingStart:t.standingStart,switches:t.switches},e,t.library,t.standingOf),...n?{session:n}:{},rulesets:t.rulesets}}function cs(e,t){let r=e.vehicles.find(o=>o.id===t);if(!r)throw new Error(`this project holds no vehicle "${t}"`);let n=rs(e);return MI(structuredClone(W1(e,r.params)),structuredClone(r.params),kI(r.params,n),io(e).air)}var NY="this project's laps follow a fixed trajectory from the planner, which the server cannot read \u2014 set Laptime back to the track to run this study here, or run it in the Studies tool";async function Fv(e,t,r,n){if(e.settings.pathPlanId)throw new Error(NY);let o=io(e),a=e.tracks.length?(await ih(e,t)).asset:null,s={};for(let i of n?mI(n):[]){let c=e.tracks.find(l=>l.id===i);c&&(s[i]=await Ku(c,t))}return SI(r,{track:a,numerics:o.numerics,racingLine:o.racingLine,standingStart:o.standingStart,lapCounts:o.lapCounts??{},switches:wh(o),rulesets:e.rulesets??[],library:s,standingOf:i=>e.tracks.find(c=>c.id===i)?.standingStart===!0})}async function AI(e,t,r,n){let o=cs(e,r),a=Kt(o,n),s=await Fv(e,t,o,a);return Sv({id:0,car:o,spec:a,lap:s})}async function wI(e,t,r,n){let o=cs(e,r),a=Kt(o,n),s=Mv(o,a);if(s.length)return{problems:[`Adopt has no way to write ${s.join(", ")} back into the project. Take them out of the study.`]};let i;try{i=await Fv(e,t,o,a)}catch(l){return{problems:[l instanceof Error?l.message:String(l)]}}let c=O1(o,a,{...ju(i),metrics:xr(e.rulesets)});return c.length?{problems:c}:{problems:[],msPerEval:Sv({id:0,car:o,spec:a,lap:i}).msPerEval,carFingerprint:Ca(Av(o))}}async function OY(e,t,r,n,o,a=[]){let s=hI(t,e,r,n),i=s.length*t.budget,c=null,l=[];for(let[u,m]of s.entries()){if(a.includes(m.seed))continue;await o?.tick();let p=[],d=null,f=null;if(vI(m,y=>{y.kind==="progress"?(p.push([y.progress.evaluations,y.progress.score.total]),y.progress.evaluations===0&&(c??=y.progress.score),o?.progress(u*t.budget+y.progress.evaluations,i)):y.kind==="done"?d={result:y.result,elapsedMs:y.elapsedMs}:f=y.message}),f)throw new Error(f);if(!d)throw new Error("the search stopped without a result");let{result:h,elapsedMs:b}=d,g={seed:m.seed,startJitter:m.startJitter,x:h.x,score:h.score,evaluations:h.evaluations,infeasible:h.infeasible,history:h.history,trace:p,elapsedMs:b,...h.snapped?{snapped:h.snapped}:{}};l.push(g),o?.progress((u+1)*t.budget,i),await o?.finished?.(g)}if(!c)throw new Error("the search never scored the starting design");return{method:t.method,budget:t.budget,designScore:c,runs:l}}async function FI(e,t,r,n){let o=cs(e,r.vehicleId),a=Kt(o,r.spec),s=Mv(o,a);if(s.length)throw new Error(`study_adopt has no way to write ${s.join(", ")} back into the project \u2014 take them out of the study`);let i=await Fv(e,t,o,a),c=r.method??pI;if(!Gs.some(x=>x.name===c))throw new Error(`unknown method "${c}" \u2014 it is one of ${Gs.map(x=>x.name).join(", ")}`);let l=r.budget??fI,u=Math.max(1,Math.min(r.seeds??Wu.length,Wu.length)),m=await OY(o,{spec:a,method:c,budget:l},i,u,n),p=wv(o,a,i),d=m.runs.map(x=>({seed:x.seed,startScore:m.designScore.total,score:x.score.total,feasible:x.score.feasible,...x.score.reason?{reason:x.score.reason}:{},terms:x.score.terms,x:x.x,evaluations:x.evaluations,infeasible:x.infeasible,bounds:bI(p.variables,x.x),constraints:gI(o,a,x.x,i),...x.snapped?{onSteps:{x:x.snapped.x,score:x.snapped.score.total,feasible:x.snapped.score.feasible,...x.snapped.score.reason?{reason:x.snapped.score.reason}:{},terms:x.snapped.score.terms}}:{}})),f=m.runs.reduce((x,R)=>Oc(R.score,x.score)?R:x),h=f.snapped?.score.feasible?f.snapped:null,b=h?h.x:f.x,g=r.tolerance??dh,y=f.score.feasible&&g>0?RI({id:0,car:o,spec:a,x:b,lap:i,mm:g}).tolerance:null;return{method:c,budget:l,seeds:d,spread:m.runs.length>1?yI(o,p.variables,m.runs.map(x=>({x:x.x,score:x.score}))):null,writes:Ah(o,a,b),...f.snapped?{adopts:h?"on its steps":`as found: on its steps it breaks a hold (${f.snapped.score.reason??"not legal"})`}:{},...y?{asBuilt:y}:{}}}var VY=(e,t)=>e[t]??[],BY=(e,t,r)=>r<=1?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function Fh(e){return e.kind==="param"?BY(e.start,e.end,Math.max(1,Math.round(e.steps))):e.kind==="part"?[...e.partIds]:[...e.values]}var CI=e=>e.kind==="param"?e.label:e.kind==="part"?`${e.part} model`:e.setting;function $Y(e,t){let r=e.vehicles.find(i=>i.id===t.vehicleId);if(!r)throw new Error(`this project holds no vehicle "${t.vehicleId}"`);if(!t.axes.length)throw new Error("a sweep needs at least one axis");let n=ns(structuredClone(r.params),rs(e),io(e)),o=Ww(n,{geometry:!0}),a=Zd(n);for(let i of t.axes){if(i.kind==="param"){let c=a.find(u=>u.label===i.label);if(!c)throw new Error(`no parameter is labelled "${i.label}" on this car \u2014 read vehicle_get for the labels it has`);let l=o[c.key];if(l)throw new Error(`"${i.label}" is a readout on this car, not an input: ${l}. Sweeping it would report exactly zero. Sweep what produces it instead.`)}if(i.kind==="part"){let c=Po.find(l=>l.doc===i.part);if(!c)throw new Error(`"${i.part}" is not a library \u2014 it is one of ${Po.map(l=>l.doc).join(", ")}`);for(let l of i.partIds)if(!VY(e,c.doc).some(u=>u.id===l))throw new Error(`the ${c.label} library holds no "${l}"`)}}if(t.holdBalance){let i=a.find(l=>l.key==="arb_front");if(t.axes.find(l=>l.kind==="param"&&l.label===i?.label))throw new Error(`holding the balance moves "${i.label}": it cannot also be an axis`)}let s=t.axes.reduce((i,c)=>i*Fh(c).length,1)+(t.priceInMass?TI:0);if(s>Gp)throw new Error(`that grid is ${s} runs, over the ${Gp} cap \u2014 a run is a whole session. Drop an axis or use fewer steps.`)}var TI=3,PI=(e,t)=>({...rh(),variables:[{id:e,lo:0,hi:2*t}]});function GY(e,t){let r=cs(e,t.vehicleId),n=lh(r);if("why"in n)throw new Error(`the balance cannot be held: ${n.why}`);let o=Sh(wh(io(e,t.settings))),a=uh(es(r,PI(n.id,n.now),{assemble:o}),xr(e.rulesets));if("why"in a)throw new Error(`the balance cannot be held: ${a.why}`);return{target:a.target,metric:a.metric,assemble:o,bar:dt(n.def),unit:n.def.unit,now:n.now}}function KY(e,t,r){let n=cs(e,t),o=lh(n);if("why"in o)return{value:NaN,balance:NaN,reached:!1};let a=PI(o.id,o.now),{x:s,held:i}=mh(es(n,a,{assemble:r.assemble}),[o.now],{slot:0,target:r.target,metric:r.metric}),c=e.vehicles.find(l=>l.id===t).params;for(let l of Ah(n,a,s))if(l.kind==="param")si(c,l.label,l.value);else if(l.kind==="block")Object.assign(c,{[l.key]:structuredClone(l.value)});else throw new Error(`a held balance has no way to write ${l.kind} back into the car`);return{value:i.value,balance:i.balance,reached:i.reached}}var LI=e=>e.map(t=>String(typeof t=="number"?Number(t.toPrecision(4)):t)).join(" \xD7 ");function HY(e,t){let r=[...new Set(e.flatMap(o=>(o.didNotFinish??[]).map(a=>a.label)))],n=e.map(o=>({name:LI(o.at),events:r.map(a=>({label:a,incomplete:o.didNotFinish?.find(s=>s.label===a)}))}));return qD(n).map(({event:o,finished:a,stopped:s})=>{let i=`${s.length} of ${e.length} points did not finish ${o}`;if(!a.length)return`${i}: every time there is a part-distance${t?" and scores zero":""}, so compare laps before time.`;let c=s.length>6?`${s.slice(0,6).join(", ")}, \u2026`:q1(s);return t?`${i}: ${c}. Their time there is a part-distance and scores zero, so read them as stopped, not slow \u2014 a points ranking favours the points that finished over faster ones that stopped.`:`${i}: ${c}. Their time there is a part-distance, so read them as stopped, not slow.`})}function zY(e){let t=[[]];for(let r of e){let n=Fh(r),o=[];for(let a of n)for(let s of t)o.push([...s,a]);t=o}return t}async function DI(e,t,r,n){$Y(e,r);let o=zY(r.axes),a=o.length+(r.priceInMass?TI:0),s=r.holdBalance?GY(e,r):null,i=[],c=!1,l=0,u=async(h,b={})=>{let g=structuredClone(e),y=g.vehicles.find(T=>T.id===r.vehicleId),x={...r.settings},R={...b};h&&r.axes.forEach((T,M)=>{let k=h[M];if(T.kind==="param")R[T.label]=k;else if(T.kind==="part"){let C=Po.find(P=>P.doc===T.part);y.params[C.ref]=k}else x[T.setting]=k}),Object.keys(R).length&&(y.params=X1(y.params,R));let v=s?KY(g,r.vehicleId,s):void 0,S=r.fleet?g.vehicles.filter(T=>T.visible||T.id===r.vehicleId).map(T=>T.id):[r.vehicleId],A=await ch(g,t,{vehicleIds:S,settings:x});c=A.fleetScored;let F=A.vehicles.find(T=>T.id===r.vehicleId),w=F.events.flatMap(T=>T.incomplete?[{label:T.label,...T.incomplete}]:[]);return n?.(++l,a),{at:h??[],metrics:F.metrics,...w.length?{didNotFinish:w}:{},...v?{held:v}:{}}};for(let h of o)i.push(await u(h));let m;if(r.priceInMass){let h=cs(e,r.vehicleId),b=gt(h)[J1],g=b.read(h),y=ev*g,x=dt(b),R=await u(null),v=await u(null,{[x]:g+y}),S=await u(null,{[x]:g-y}),A=Object.fromEntries(Object.keys(R.metrics).map(F=>[F,(v.metrics[F]-S.metrics[F])/(2*y)]));m={car:R.metrics,perKg:A,dKg:y};for(let F of i)F.asKg=Object.fromEntries(Object.keys(F.metrics).map(w=>[w,tv(F.metrics[w],R.metrics[w],A[w])]))}let p=Object.keys(i[0]?.metrics??{}),d=[];r.axes.forEach((h,b)=>{if(Fh(h).length<2)return;p.some(y=>{if(new Set(i.map(v=>`${v.at[b]}`)).size<2)return!1;let R=i.map(v=>v.metrics[y]).filter(Number.isFinite);return Math.max(...R)-Math.min(...R)>1e-9})||d.push(CI(h))});let f=[];if(c&&!r.fleet&&f.push("Points here were scored with this car alone, so it takes the maximum in every event and the points axis is flat by construction. Re-run with fleet: true to price a change in points."),f.push(...HY(i,c)),s&&io(e,r.settings).ggvMode==="fast"&&f.push("The fast envelope is a point mass: no balance reaches its laps, so a held sweep runs the same laps as a loose one. Hold it on the full envelope (settings.ggvMode)."),s){let h=i.filter(b=>b.held&&!b.held.reached).map(b=>LI(b.at));h.length&&f.push(`No ${s.bar} between 0 and twice the car's holds TLLTD at ${s.target.toFixed(2)} % at ${q1(h.length>6?[...h.slice(0,6),"\u2026"]:h)}: those points ran with the bar at the end nearer it, so their balance is not the car's.`)}return m&&f.push(`As mass: each point's change from the car as it is, over what 1 kg moves it, read at \xB1${m.dKg.toFixed(1)} kg. Negative is as much as taking that many kilograms off. A metric the mass hardly moves prices at nonsense: read the lap and event times.`),d.length&&f.push(`Nothing moved along ${d.join(", ")}. Exactly zero is a wiring question before it is a finding: check that a library part is not superseding the value, and that the switch it needs is on.`),{axes:r.axes.map(h=>({kind:h.kind,label:CI(h),values:Fh(h)})),runs:i,metricKeys:p,fleetScored:c,flat:d,caveats:f,...s?{hold:{bar:s.bar,unit:s.unit,now:s.now,tlltdPct:s.target}}:{},...m?{price:m}:{}}}function II(){if(typeof process.threadCpuUsage!="function")return performance.now();let e=process.threadCpuUsage();return(e.user+e.system)/1e3}async function WY(e,t){let r=KD(e.root);switch(e.kind){case"sweep":return DI(e.doc,r,e.req,t);case"convergence":return QD(e.doc,r,{vehicleId:e.vehicleId,...e.steps?{steps:e.steps}:{},...e.tolPct!==void 0?{tolPct:e.tolPct}:{},onStep:t});case"study":return FI(e.doc,r,{vehicleId:e.vehicleId,spec:e.spec,...e.method?{method:e.method}:{},...e.budget?{budget:e.budget}:{},...e.seeds?{seeds:e.seeds}:{},...e.tolerance!==void 0?{tolerance:e.tolerance}:{}},{progress:t,cancelled:()=>!1,tick:async()=>{}});case"fleet":return ch(e.doc,r,{...e.vehicleIds?{vehicleIds:e.vehicleIds}:{},...e.settings?{settings:e.settings}:{},...e.overrides?{overrides:e.overrides}:{}});case"probe":return AI(e.doc,r,e.vehicleId,e.spec);case"quote":return wI(e.doc,r,e.vehicleId,e.spec)}}if(EI){let e=EI,t=r=>e.postMessage(r);(async()=>{try{let r=await WY(YY,(n,o)=>t({type:"progress",done:n,total:o}));t({type:"done",result:r,cpuMs:II()})}catch(r){t({type:"failed",message:r instanceof Error?r.message:String(r),cpuMs:II()})}})()}export{WY as runJob,II as threadCpuMs};
|
|
226
|
+
`)),this.name="RulesetDefError",this.problems=r}},Wl=e=>typeof e=="number"&&Number.isFinite(e),Yl=e=>Wl(e)&&e>0,gr=(e,t)=>e===void 0||t(e);function C5(e){let t=[],r=(o,a=null)=>t.push({key:a,message:o});if(typeof e.id!="string"||e.id===""?r("A ruleset needs an id"):/^[A-Za-z0-9_-]+$/.test(e.id)||r(`The id "${e.id}" is letters, digits, "-" and "_" only`),typeof e.label!="string"&&r("A ruleset needs a label"),typeof e.description!="string"&&r("A ruleset needs a description, even an empty one"),Array.isArray(e.events)||r("A ruleset\u2019s events are a list"),Array.isArray(e.kpis)||r("A ruleset\u2019s KPIs are a list"),t.length)return t;for(let o of e.events){let a=o,s=typeof a?.id=="string"?`Event "${a.id}"`:"An event";if(typeof a!="object"||a===null||typeof a.id!="string"||typeof a.label!="string"){r(`${s} needs an id and a label`);continue}switch(a.kind){case"straightLineAccel":Yl(a.distance)||r(`${s} needs a distance above zero, in metres`),gr(a.vStart,i=>Wl(i)&&i>=0)||r(`${s}'s entry speed must be zero or more`);break;case"constantRadius":Yl(a.radius)||r(`${s} needs a radius above zero, in metres`),gr(a.laps,i=>Wl(i)&&i>=1)||r(`${s} runs at least one lap`);break;case"trackLap":gr(a.laps,i=>Wl(i)&&i>=1)||r(`${s} runs at least one lap`),gr(a.distance,Yl)||r(`${s}'s distance must be above zero, in metres`),gr(a.standingStart,i=>typeof i=="boolean")||r(`${s}'s standing start is yes or no`);break;default:r(`${s} is of a kind this build does not run: ${String(a.kind)}`)}}for(let o of e.kpis){let a=o;if(typeof a!="object"||a===null||typeof a.key!="string"){r("A KPI needs a key");continue}let s=a.key;typeof a.expr!="string"&&r("Needs a formula",s),typeof a.label!="string"&&r("Needs a label",s),gr(a.unit,i=>typeof i=="string")||r("Its unit is text",s),gr(a.over,i=>typeof i=="string")||r("Names its event by id",s),gr(a.format,i=>i==="time"||i==="points")||r("Is shown as a time, as points, or as a number",s),gr(a.max,Wl)||r("Its maximum is a number",s),gr(a.lowerBetter,i=>typeof i=="boolean")||r("Lower is better, or it is not",s),gr(a.hidden,i=>typeof i=="boolean")||r("Is hidden, or it is not",s)}gr(e.track?.minTurnRadius,Yl)||r("The tightest turn the rules allow is a radius above zero");let n=e.battery;for(let o of["packVoltageMax","segmentVoltageMax","powerLimitKw"])gr(n?.[o],Yl)||r(`The pack's ${o} must be above zero`);if(e.score!==void 0){let o=e.score?.parts;typeof e.score?.total!="string"||typeof o!="object"||o===null||Array.isArray(o)?r("The score names its total and its parts"):Object.values(o).every(a=>typeof a=="string")||r("Each part of the score names a KPI")}return t}function WC(e){let t=C5(e);if(t.length)return{plan:null,problems:t};let r=[];e.events.length===0&&r.push({key:null,message:"A ruleset runs at least one event"});let n=e.events.map(i=>i.id);e.traceEventId!=null&&!n.includes(e.traceEventId)&&r.push({key:null,message:`The plotted event "${e.traceEventId}" is not one of this ruleset's events`});let{plan:o,problems:a}=Pp(e.kpis,e.events);r.push(...a);let s=new Set(e.kpis.map(i=>i.key));if(e.score){s.has(e.score.total)||r.push({key:null,message:`The total "${e.score.total}" is not one of this ruleset's KPIs`});let i=Object.entries(e.score.parts);i.length===0&&r.push({key:null,message:"A ruleset that awards points names at least one part"});for(let[c,l]of i)s.has(l)||r.push({key:null,message:`The part "${c}" reads "${l}", which is not one of this ruleset's KPIs`})}return{plan:r.length?null:o,problems:r}}function Dp(e){return WC(e).problems}var Wy=e=>Number.isFinite(e)?e:NaN;function T5(e){return e.unit&&e.format!=="time"?`${e.label} (${e.unit})`:e.label}function Co(e){let t=structuredClone(e),{plan:r,problems:n}=WC(t);if(!r)throw new Lp(t.id,n);let o=new WeakMap,a=d=>{let f=o.get(d);return f||(f=Yy(r,d),o.set(d,f)),f},s=new Map(t.kpis.map(d=>[d.key,d])),i=new Map;for(let[d,f]of Object.entries(t.score?.parts??{}))i.has(f)||i.set(f,d);let c=d=>(f,h)=>{if(!h)return NaN;let b=h.kpis?.[d];if(b!==void 0)return Wy(b);let g=h,y=i.get(d);return y!==void 0?Wy(g.parts?.[y]):d===t.score?.total?Wy(g.total):NaN},l=t.kpis.filter(d=>!d.hidden).map(d=>{let f=r.field.has(d.key);return{key:d.key,label:T5(d),lowerBetter:d.lowerBetter??!1,...d.format?{format:d.format}:{},...f?{field:!0}:{},value:f?c(d.key):h=>a(h)[d.key]}}),u=t.score,m=u?d=>{let f=zl(r,d),h={};for(let[b,g]of Object.entries(f)){let y={},x={};for(let[R,v]of Object.entries(u.parts)){y[R]=g[v];let S=s.get(v)?.max;S!=null&&(x[R]=S)}h[b]={total:g[u.total],parts:y,...Object.keys(x).length?{maxima:x}:{},kpis:Object.fromEntries(t.kpis.map(R=>[R.key,g[R.key]]))}}return h}:void 0,p=m||(r.field.size>0?d=>{let f=zl(r,d),h={};for(let[b,g]of Object.entries(f))h[b]={kpis:Object.fromEntries(t.kpis.map(y=>[y.key,g[y.key]]))};return h}:void 0);return{id:t.id,label:t.label,description:t.description,events:t.events,metrics:l,...t.track?{track:t.track}:{},...t.battery?{battery:t.battery}:{},...t.traceEventId?{traceEventId:t.traceEventId}:{},...m?{score:m}:{},...p?{field:p}:{},definition:t}}var zr={accel:"accel",skidpad:"skidpad",autocross:"autocross",endurance:"endurance"},jC=[{kind:"straightLineAccel",id:zr.accel,label:"Acceleration (75 m)",distance:75},{kind:"constantRadius",id:zr.skidpad,label:"Skidpad",radius:8.375},{kind:"trackLap",id:zr.autocross,label:"Autocross (1 lap)",laps:1},{kind:"trackLap",id:zr.endurance,label:"Endurance (22 km)",distance:22e3}],UC=[{key:"autocross",label:"Autocross lap",format:"time",lowerBetter:!0,expr:"autocross.time"},{key:"accel",label:"Acceleration",format:"time",lowerBetter:!0,expr:"accel.time"},{key:"skidpad",label:"Skidpad lap",format:"time",lowerBetter:!0,expr:"skidpad.lapTime"},{key:"endurance",label:"Endurance",format:"time",lowerBetter:!0,expr:"endurance.time"},{key:"energy",label:"Energy",unit:"kWh",lowerBetter:!0,expr:"endurance.energy"},{key:"overall",label:"Overall",unit:"pts",format:"points",expr:"accelPts + skidpadPts + autocrossPts + endurancePts + efficiencyPts"},{key:"endurancePts",label:"Endurance",unit:"pts",format:"points",max:250,expr:"if(finite(finishedEndurance), 0.9 * 250 * ((1.333 * fleetmin(finishedEndurance) / min(finishedEndurance, 1.333 * fleetmin(finishedEndurance)) - 1) / 0.333) + 0.1 * 250, 0)"},{key:"efficiencyPts",label:"Efficiency",unit:"pts",format:"points",max:100,expr:"if(and(finite(finishedEndurance), finishedEndurance <= 1.333 * fleetmin(finishedEndurance)), 100 * ((1.5 * fleetmin(efficiencyFactor) - min(1.5 * fleetmin(efficiencyFactor), efficiencyFactor)) / (1.5 * fleetmin(efficiencyFactor) - fleetmin(efficiencyFactor))), 0)"},{key:"finishedEndurance",label:"Endurance, if finished",unit:"s",hidden:!0,expr:"if(endurance.finished, endurance.time, nan)"},{key:"efficiencyFactor",label:"Efficiency factor",unit:"s\xB2\xB7kWh",hidden:!0,expr:"finishedEndurance ^ 2 * endurance.energy"},{key:"accelPts",label:"Acceleration",unit:"pts",format:"points",max:75,hidden:!0,expr:"0.95 * 75 * ((1.5 * fleetmin(accel) / min(accel, 1.5 * fleetmin(accel)) - 1) / 0.5) + 0.05 * 75"},{key:"skidpadPts",label:"Skidpad",unit:"pts",format:"points",max:75,hidden:!0,expr:"0.95 * 75 * (((1.25 * fleetmin(skidpad) / min(skidpad, 1.25 * fleetmin(skidpad))) ^ 2 - 1) / 0.5625) + 0.05 * 75"},{key:"autocrossPts",label:"Autocross",unit:"pts",format:"points",max:100,hidden:!0,expr:"0.95 * 100 * ((1.25 * fleetmin(autocross) / min(autocross, 1.25 * fleetmin(autocross)) - 1) / 0.25) + 0.05 * 100"}],XC={total:"overall",parts:{[zr.accel]:"accelPts",[zr.skidpad]:"skidpadPts",[zr.autocross]:"autocrossPts",[zr.endurance]:"endurancePts",efficiency:"efficiencyPts"}},qC={id:"fs-ev",label:"Formula Student \u2014 Electric",description:"The four dynamic events (acceleration, skidpad, autocross, endurance) scored on the Formula Student point table, with efficiency from battery energy.",events:jC,kpis:UC,score:XC,track:{minTurnRadius:4.5},battery:Pv,traceEventId:zr.autocross},QC={id:"fs-cv",label:"Formula Student \u2014 Combustion",description:"Same events and point table as the electric class. An engine car\u2019s efficiency is scored on the work at its crankshaft until its fuel is modelled; an electric car\u2019s on its pack.",events:jC,kpis:UC,score:XC,track:{minTurnRadius:4.5},traceEventId:zr.autocross},jl=Co(qC),jy=Co(QC);var Uy="lap",P5=[{kind:"trackLap",id:Uy,label:Cp,laps:1}],ZC={id:"trackday",label:"Track day",description:"One flying lap of the selected track. Times and traces only \u2014 no scoring.",events:P5,kpis:[{key:"lap",label:"Lap time",format:"time",lowerBetter:!0,expr:"lap.time"},{key:"topSpeed",label:"Top speed",unit:"km/h",over:Uy,expr:"peak(speed)"},{key:"energy",label:"Energy / lap",unit:"kWh",lowerBetter:!0,expr:"lap.energy"}],traceEventId:Uy},Xy=Co(ZC);function To(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(To).join(",")}]`;let t=e,r=Object.keys(t).sort(),n=[];for(let o of r)t[o]!==void 0&&n.push(`${JSON.stringify(o)}:${To(t[o])}`);return`{${n.join(",")}}`}function Ca(e){let t=To(e),r=2166136261;for(let n=0;n<t.length;n++)r^=t.charCodeAt(n),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return r.toString(16).padStart(8,"0").slice(-6)}var yi=[jl,jy,Xy],Ta=jl.id,xi=e=>yi.some(t=>t.id===e),JC=new WeakMap,Ul=new Map,L5=64;function Ep(e){let t=JC.get(e);if(t!==void 0)return t;let r=To(e),n=Ul.get(r);return n===void 0&&(n=Dp(e).length?null:Co(e),Ul.size>=L5&&Ul.delete(Ul.keys().next().value),Ul.set(r,n)),JC.set(e,n),n}function Ip(e,t=[]){if(e==null)return;if(typeof e!="string")return Ep(e)??void 0;let r=yi.find(o=>o.id===e);if(r)return r;let n=t.find(o=>o.id===e);return n?Ep(n)??void 0:void 0}function Pa(e,t=[]){return Ip(e,t)??jl}function qy(e=[]){let t=e.filter(r=>!xi(r.id)).map(r=>Ep(r)).filter(r=>r!==null);return[...yi,...t]}var Xl=e=>e.definition??e.id;function _p(e,t,r){let n=e.length,o=new Array(n);for(let f=0;f<n;f++){let h=f+1<n?e[f+1]:r;o[f]=h-e[f]}let a=new Array(n).fill(0),s=new Array(n).fill(0),i=new Array(n).fill(0),c=new Array(n).fill(0);for(let f=0;f<n;f++){let h=o[(f-1+n)%n],b=o[f];a[f]=h,s[f]=2*(h+b),i[f]=b;let g=t[(f+1)%n],y=t[(f-1+n)%n];c[f]=6*((g-t[f])/b-(t[f]-y)/h)}let l=D5(a,s,i,c),u=new Array(n),m=new Array(n),p=new Array(n),d=new Array(n);for(let f=0;f<n;f++){let h=o[f],b=l[f],g=l[(f+1)%n],y=t[f],x=t[(f+1)%n];u[f]=y,p[f]=b/2,d[f]=(g-b)/(6*h),m[f]=(x-y)/h-h*(2*b+g)/6}return{n,eval:(f,h)=>u[f]+h*(m[f]+h*(p[f]+h*d[f])),d1:(f,h)=>m[f]+h*(2*p[f]+h*3*d[f]),d2:(f,h)=>2*p[f]+h*6*d[f]}}function Zy(e,t){let r=e.length,n=r-1,o=new Array(n);for(let u=0;u<n;u++)o[u]=e[u+1]-e[u];let a=new Array(r).fill(0);if(r>2){let u=r-2,m=new Array(u).fill(0),p=new Array(u).fill(0),d=new Array(u).fill(0),f=new Array(u).fill(0);for(let g=0;g<u;g++){let y=g+1;m[g]=o[y-1],p[g]=2*(o[y-1]+o[y]),d[g]=o[y],f[g]=6*((t[y+1]-t[y])/o[y]-(t[y]-t[y-1])/o[y-1])}let h=n>=3;if(h){let g=o[0]/o[1];p[0]+=o[0]*(1+g),d[0]-=o[0]*g;let y=o[n-1]/o[n-2];p[u-1]+=o[n-1]*(1+y),m[u-1]-=o[n-1]*y}let b=Qy(m,p,d,f);for(let g=0;g<u;g++)a[g+1]=b[g];h&&(a[0]=(1+o[0]/o[1])*a[1]-o[0]/o[1]*a[2],a[r-1]=(1+o[n-1]/o[n-2])*a[r-2]-o[n-1]/o[n-2]*a[r-3])}let s=new Array(n),i=new Array(n),c=new Array(n),l=new Array(n);for(let u=0;u<n;u++)s[u]=t[u],c[u]=a[u]/2,l[u]=(a[u+1]-a[u])/(6*o[u]),i[u]=(t[u+1]-t[u])/o[u]-o[u]*(2*a[u]+a[u+1])/6;return{n,eval:(u,m)=>s[u]+m*(i[u]+m*(c[u]+m*l[u])),d1:(u,m)=>i[u]+m*(2*c[u]+m*3*l[u]),d2:(u,m)=>2*c[u]+m*6*l[u]}}function D5(e,t,r,n){let o=t.length;if(o===1)return[n[0]/(t[0]+e[0]+r[0])];if(o===2){let f=t[0],h=r[0]+e[0],b=e[1]+r[1],g=t[1],y=f*g-h*b;return[(n[0]*g-h*n[1])/y,(f*n[1]-n[0]*b)/y]}let a=e[0],s=r[o-1],i=-t[0]||1e-30,c=t.slice();c[0]=t[0]-i,c[o-1]=t[o-1]-a*s/i;let l=Qy(e,c,r,n),u=new Array(o).fill(0);u[0]=i,u[o-1]=s;let m=Qy(e,c,r,u),p=(l[0]+a*l[o-1]/i)/(1+m[0]+a*m[o-1]/i),d=new Array(o);for(let f=0;f<o;f++)d[f]=l[f]-p*m[f];return d}function Qy(e,t,r,n){let o=t.length,a=new Array(o),s=new Array(o);a[0]=r[0]/t[0],s[0]=n[0]/t[0];for(let c=1;c<o;c++){let l=t[c]-e[c]*a[c-1];a[c]=r[c]/l,s[c]=(n[c]-e[c]*s[c-1])/l}let i=new Array(o);i[o-1]=s[o-1];for(let c=o-2;c>=0;c--)i[c]=s[c]-a[c]*i[c+1];return i}function ql(e){let t=e.z;if(!Array.isArray(t)||t.length<2)return null;let r=e.closed!==!1,n=e.x.length,o=r?n:n-1,a=[0];for(let l=0;l<o;l++){let u=(l+1)%n;a.push(a[l]+Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]))}let s=a[o],i=t.length,c=i===n?a.slice(0,n):Array.from({length:i},(l,u)=>r?u/i*s:u/(i-1)*s);return{z:t,pos:c,length:s,closed:r}}function eT(e,t,r){let n=e.pos[r]-e.pos[t];return e.closed?n>e.length/2?n-e.length:n<-e.length/2?n+e.length:n:n}function tT(e,t){let[r,n,o,a,s,i]=e,c=a*i-s*s,l=o*s-n*i,u=n*s-o*a,m=r*c+n*l+o*u;if(!(Math.abs(m)>1e-12*Math.max(1,Math.abs(r*a*i))))return null;let p=r*i-o*o,d=n*o-r*s,f=r*a-n*n;return[(c*t[0]+l*t[1]+u*t[2])/m,(l*t[0]+p*t[1]+d*t[2])/m,(u*t[0]+d*t[1]+f*t[2])/m]}function rT(e){let t=e.z.length;if(t<5)return 0;let r=[];for(let a=0;a<t;a++){let s=[a-2,a-1,a+1,a+2].map(h=>e.closed?(h+t)%t:h);if(s.some(h=>h<0||h>=t))continue;let i=s.map(h=>eT(e,a,h)),c=Math.max(...i.map(Math.abs));if(!(c>0))continue;let l=i.map(h=>h/c),u=[0,0,0,0,0];for(let h of l)for(let b=0;b<5;b++)u[b]+=h**b;let m=tT([u[0],u[1],u[2],u[2],u[3],u[4]],[1,0,0]);if(!m)continue;let p=l.map(h=>m[0]+m[1]*h+m[2]*h*h),d=0,f=1;p.forEach((h,b)=>{d+=h*e.z[s[b]],f+=h*h}),r.push(Math.abs(e.z[a]-d)/Math.sqrt(f))}if(!r.length)return 0;r.sort((a,s)=>a-s);let n=r.length>>1;return 1.4826*(r.length%2?r[n]:(r[n-1]+r[n])/2)}function E5(e,t,r){let n=e.z.length,o=[t],a=[0];for(let s of[-1,1])for(let i=1;i<n;i++){let c=e.closed?((t+s*i)%n+n)%n:t+s*i;if(c<0||c>=n)break;let l=eT(e,t,c);if(Math.abs(l)>=r||Math.sign(l)!==s)break;o.push(c),a.push(l)}return{j:o,t:a}}function I5(e,t,r){let{j:n,t:o}=E5(e,t,r);if(n.length<4)return null;let a=o.map(l=>(1-Math.abs(l/r)**3)**3),s=o.map(l=>l/r),i=[0,0,0,0,0];s.forEach((l,u)=>{let m=a[u];for(let p=0;p<5;p++)i[p]+=m,m*=l});let c=tT([i[0],i[1],i[2],i[2],i[3],i[4]],[1,0,0]);return c?{j:n,value:s.map((l,u)=>a[u]*(c[0]+c[1]*l+c[2]*l*l))}:null}function Jy(e,t){return t>0?e.z.map((r,n)=>{let o=I5(e,n,t/2);return o?o.value.reduce((a,s,i)=>a+s*e.z[o.j[i]],0):r}):[...e.z]}function _5(e,t){if(!(e>0)||!(t>0))return 0;let r=(22.5*t*e*e/1e-4**2)**.2;return Math.min(100/2,r)}function Np(e){let t=ql(e);if(!t)return 0;let r=rT(t);return r>1e-6?Math.max(10,_5(r,N5(t))):0}function N5(e){let t=[];for(let r=1;r<e.pos.length;r++)t.push(e.pos[r]-e.pos[r-1]);return e.closed&&e.pos.length&&t.push(e.length-e.pos[e.pos.length-1]+e.pos[0]),t.sort((r,n)=>r-n),t.length?t[t.length>>1]:0}function xn(e,t,r){let n=e.n;if(e.closed===!1){let a=r-t;return a===0?e.diag[t]:a===1?e.off1[t]:a===2?e.off2[t]:a===-1?e.off1[r]:a===-2?e.off2[r]:0}let o=((r-t)%n+n)%n;return o===0?e.diag[t]:o===1?e.off1[t]:o===2?e.off2[t]:o===n-1?e.off1[r]:o===n-2?e.off2[r]:0}function Vp(e,t){let r=e.n,n=new Array(r).fill(0);for(let o=0;o<r;o++){let a=e.diag[o]*t[o];for(let[s,i]of[[1,e.off1],[2,e.off2]]){(o+s<r||e.closed!==!1)&&(a+=i[o]*t[(o+s)%r]);let c=(o-s+r)%r;(o-s>=0||e.closed!==!1)&&(a+=i[c]*t[c])}n[o]=a}return n}function nT(e,t){let r=new Array(e).fill(0),n=new Array(e).fill(0),o=new Array(e).fill(0);for(let a=0;a<e;a++){a>=2&&(o[a]=r[a-2]!==0?t(a,a-2)/r[a-2]:0),a>=1&&(n[a]=r[a-1]!==0?(t(a,a-1)-o[a]*n[a-1])/r[a-1]:0);let s=t(a,a)-n[a]*n[a]-o[a]*o[a];if(!(s>0)||!Number.isFinite(s))return null;r[a]=Math.sqrt(s)}return{d:r,l1:n,l2:o}}function Op(e,t){let r=t.length,n=new Array(r).fill(0);for(let a=0;a<r;a++){let s=t[a];a>=1&&(s-=e.l1[a]*n[a-1]),a>=2&&(s-=e.l2[a]*n[a-2]),n[a]=s/e.d[a]}let o=new Array(r).fill(0);for(let a=r-1;a>=0;a--){let s=n[a];a+1<r&&(s-=e.l1[a+1]*o[a+1]),a+2<r&&(s-=e.l2[a+2]*o[a+2]),o[a]=s/e.d[a]}return o}function O5(e,t){let r=e[0][0]*e[1][1]-e[0][1]*e[1][0],n=Math.max(Math.abs(e[0][0]*e[1][1]),Math.abs(e[0][1]*e[1][0]),Number.MIN_VALUE);return!Number.isFinite(r)||Math.abs(r)<1e-12*n?null:[(t[0]*e[1][1]-e[0][1]*t[1])/r,(e[0][0]*t[1]-t[0]*e[1][0])/r]}function ex(e,t){let r=e.n;if(r<7)throw new Error(`periodic band solver needs n >= 7, got ${r}`);if(e.closed===!1){let b=nT(r,(y,x)=>xn(e,y,x));if(!b)return null;let g=Op(b,t);return g.every(Number.isFinite)?g:null}let n=r-2,a=nT(n,(b,g)=>xn(e,b,g));if(!a)return null;let s=new Array(n).fill(0),i=new Array(n).fill(0);for(let b=0;b<n;b++)s[b]=xn(e,b,r-2),i[b]=xn(e,b,r-1);let c=Op(a,t.slice(0,n)),l=Op(a,s),u=Op(a,i),m=(b,g)=>{let y=0;for(let x=0;x<b.length;x++)y+=b[x]*g[x];return y},p=[[xn(e,r-2,r-2)-m(s,l),xn(e,r-2,r-1)-m(s,u)],[xn(e,r-1,r-2)-m(i,l),xn(e,r-1,r-1)-m(i,u)]],d=[t[r-2]-m(s,c),t[r-1]-m(i,c)],f=O5(p,d);if(!f)return null;let h=new Array(r).fill(0);for(let b=0;b<n;b++)h[b]=c[b]-l[b]*f[0]-u[b]*f[1];return h[r-2]=f[0],h[r-1]=f[1],h.every(Number.isFinite)?h:null}function oT(e,t,r=0){let n=Math.max(...e.diag.map(Math.abs),1e-30),o=r>0?r:n*1e-12,a=Math.sqrt(t.reduce((s,i)=>s+i*i,0));for(let s=0;s<40;s++){let i={...e,diag:e.diag.map(l=>l+o)},c=ex(i,t);if(c){let l=Vp(i,c).map((m,p)=>m-t[p]);if(Math.sqrt(l.reduce((m,p)=>m+p*p,0))<=1e-6*Math.max(a,1e-12))return c}o=o===0?n*1e-12:o*10}return null}var aT=4,V5=8,tx=.001;function B5(e,t,r){let n=[];for(let c=1;c<e.length;c++){let l=e[c]-e[c-1];l>=tx&&n.push(l)}let o=Float64Array.from(n).sort(),a=o.length>>1,s=o.length?o.length%2?o[a]:.5*(o[a-1]+o[a]):0,i=t?n.length:n.length+1;return Math.max(3,Math.round(i/qw(r,s,i)))}function $5(e,t){let r=e.closed!==!1,n=[],o=[],a=(C,F)=>{let T=n.length-1;T>=0&&Math.hypot(C-n[T],F-o[T])<tx||(n.push(C),o.push(F))},s=e.x.length,i=r?s:s-1,c=new Array(i+1);c[0]=0;for(let C=0;C<i;C++){let F=(C+1)%s;c[C+1]=c[C]+Math.hypot(e.x[F]-e.x[C],e.y[F]-e.y[C])}let l=c[i],u=e.fit==="interpolate",m=u?s:B5(c,r,t),p=r?m:m-1,d=0;for(let C=0;C<=p&&!(r&&C===p);C++){if(u){a(e.x[C],e.y[C]);continue}let F=C*l/p;for(;d<i-1&&c[d+1]<F;)d++;let T=c[d+1]-c[d],M=T>0?(F-c[d])/T:0,k=(d+1)%s;a(e.x[d]+M*(e.x[k]-e.x[d]),e.y[d]+M*(e.y[k]-e.y[d]))}if(r)for(;n.length>2&&Math.hypot(n[n.length-1]-n[0],o[o.length-1]-o[0])<tx;)n.pop(),o.pop();let f=n.length,h=r?f:f-1,b=new Array(h+1);b[0]=0;for(let C=1;C<=h;C++){let F=C%f,T=n[F]-n[C-1],M=o[F]-o[C-1],k=Math.sqrt(Math.hypot(T,M))||1e-9;b[C]=b[C-1]+k}let g=r?_p(b.slice(0,f),n,b[f]):Zy(b,n),y=r?_p(b.slice(0,f),o,b[f]):Zy(b,o),x=new Array(h);for(let C=0;C<h;C++)x[C]=b[C+1]-b[C];let R=[0],v=[0],S=[0],A=0;for(let C=0;C<h;C++){let F=x[C]/aT;for(let T=0;T<aT;T++){let M=T*F;A+=Zg(k=>Math.hypot(g.d1(C,k),y.d1(C,k)),M,M+F),R.push(A),v.push(C),S.push(M+F)}}return{closed:r,sx:g,sy:y,h:x,sTable:R,segTable:v,uTable:S,length:A,rawCum:c,rawLength:l}}function Ql(e,t,r,n){if(e===void 0)return r.map(()=>t);if(typeof e=="number")return r.map(()=>e);let o=e.length;if(o===0)return r.map(()=>t);if(o===1)return r.map(()=>e[0]);let a=n.rawCum.length-1,s=o===(n.closed?a:a+1);return r.map(i=>{let c;if(s){let p=i*n.rawLength,d=0,f=a;for(;d<f;){let b=d+f+1>>1;n.rawCum[b]<=p?d=b:f=b-1}let h=d<a?n.rawCum[d+1]-n.rawCum[d]:0;c=d+(h>0?(p-n.rawCum[d])/h:0)}else c=n.closed?i*o:i*(o-1);let l=Math.min(Math.floor(c),o-1)%o,u=c-Math.floor(c),m=n.closed?(l+1)%o:Math.min(l+1,o-1);return e[l]+u*(e[m]-e[l])})}var G5=.01,K5=3,sT=10;function H5(e,t,r,n=sT){let o={step:0,uncertainty:1/0},a=e.length;if(a<8||!(r>0))return o;let s=Math.max(sT,n,6*r/a),i=(r-t[a-1])/2,c=0;for(;c<a/2&&t[c]+i<=s;)c++;let l=0;for(;l<a/2&&r-t[a-1-l]-i<=s;)l++;let u=Math.min(c,l);if(u<3)return o;let m=[],p=[],d=(x,R,v)=>{let S=x/s;m.push([1,S,S*S,S*S*S,R]),p.push(v)};for(let x=0;x<u;x++)d(t[x]+i,1,e[x]);for(let x=0;x<u;x++)d(t[a-1-x]-r+i,0,e[a-1-x]);let f=Array.from({length:5},()=>new Array(5).fill(0)),h=new Array(5).fill(0);m.forEach((x,R)=>{for(let v=0;v<5;v++){h[v]+=x[v]*p[R];for(let S=0;S<5;S++)f[v][S]+=x[v]*x[S]}});let b=Jr(f,h),g=Jr(f,[0,0,0,0,1]);if(b.singular||g.singular)return o;let y=0;return m.forEach((x,R)=>{let v=0;for(let S=0;S<5;S++)v+=x[S]*b.x[S];y+=(p[R]-v)**2}),{step:b.x[4],uncertainty:Math.sqrt(y/(m.length-5)*g.x[4])}}function z5(e,t){let r=t[t.length-1];return{pos:e===t.length-1?t.slice(0,e):Array.from({length:e},(o,a)=>a/e*r),loop:r}}function Y5(e,t,r){let{pos:n,loop:o}=z5(e.length,t),{step:a,uncertainty:s}=H5(e,n,o,r);return Math.abs(a)>Math.max(G5,K5*s)?{z:e.map((i,c)=>i+a*n[c]/o),drift:-a}:{z:e,drift:0}}function W5(e,t){let{sTable:r,segTable:n,uTable:o,h:a,sx:s,sy:i}=e,c=0,l=r.length-1;for(;c<l;){let y=c+l+1>>1;r[y]<=t?c=y:l=y-1}let u=Math.min(c,r.length-2),m=r[u],p=r[u+1],d=n[u+1],f=o[u+1],h=n[u]===d?o[u]:0,b=p-m,g=b>0?h+(t-m)/b*(f-h):h;for(let y=0;y<2;y++){let x=m+Zg(v=>Math.hypot(s.d1(d,v),i.d1(d,v)),h,g),R=Math.hypot(s.d1(d,g),i.d1(d,g));if(R<1e-12)break;g-=(x-t)/R}return{seg:d,du:Math.min(Math.max(g,0),a[d])}}var j5=3,rx=5;function U5(e,t,r,n=rx){return $p(e,t,r,n)}function $p(e,t,r,n,o=!1){let a=e.length;if(!(t>0)||!(n>0)||a<7)return[...e];let s=(n/(2*Math.PI*t))**4,i=new Array(a).fill(1+6*s),c=new Array(a).fill(-4*s),l=new Array(a).fill(s),u=[...e];if(!r&&(i[0]=i[a-1]=1+s,i[1]=i[a-2]=1+5*s,c[0]=c[a-2]=-2*s,o)){let m=1e9*(1+s);for(let p of[0,a-1])i[p]+=m,u[p]*=1+m}return ex({n:a,diag:i,off1:c,off2:l,closed:r},u)??[...e]}function $t(e,t){let r=Bt(t),n=$5(e,r.fitSpacing),o=n.length,a=Math.max(V5,Math.round(o/r.dsTarget)),s=n.closed?a:a+1,i=o/a,c=new Array(s),l=new Array(s),u=new Array(s),m=new Array(s).fill(i);n.closed||(m[s-1]=0);let p=new Array(s),d=new Array(s),f=new Array(s);for(let T=0;T<s;T++){let M=T*i,{seg:k,du:w}=W5(n,M);c[T]=n.sx.eval(k,w),l[T]=n.sy.eval(k,w),u[T]=M;let P=n.sx.d1(k,w),L=n.sy.d1(k,w),E=n.sx.d2(k,w),_=n.sy.d2(k,w),D=Math.hypot(P,L),I=Math.pow(P*P+L*L,1.5);p[T]=I>0?(P*_-L*E)/I:0,d[T]=D>0?-L/D:0,f[T]=D>0?P/D:0}let h=u.map(T=>o>0?Math.min(1,T/o):0),b=Array.isArray(e.z)&&e.z.length>1,g=b&&(e.zSmoothing??0)>0?e.zSmoothing:0,y=b&&n.closed?Y5(e.z,n.rawCum,g):null,x=y?y.z:e.z,R=g>0?ql(e):null,v=R?Jy({...R,z:x},g):x,S=Ql(v,0,h,n),A=new Array(s).fill(0);if(b){for(let M=0;M<s;M++){let k=n.closed?(M+1)%s:Math.min(M+1,s-1),w=n.closed?(M-1+s)%s:Math.max(M-1,0),P=n.closed?2:k-w,L=S[k]-S[w];A[M]=P>0?Math.atan2(L,P*i)*180/Math.PI:0}for(let M=0;M<s;M++){if(m[M]===0)continue;let k=n.closed?(M+1)%s:M+1,w=S[k]-S[M];m[M]=Math.hypot(i,w)}let T=0;for(let M=0;M<s;M++)u[M]=T,T+=m[M]}let C=b?m.reduce((T,M)=>T+M,0):o,F;if(b){F=new Array(s).fill(0);let T=Math.max(j5,e.zReach??Np(e)),M=Math.max(2,Math.round(T/i));if(n.closed?s>2*M:s>2*M+1){let k=0,w=0;for(let E=-M;E<=M;E++)k+=E*E,w+=E*E*E*E;let P=2*M+1,L=w-k*k/P;for(let E=0;E<s;E++){let _=n.closed?E:Math.min(Math.max(E,M),s-1-M),D=0,I=0;for(let V=-M;V<=M;V++){let H=S[n.closed?(_+V+s)%s:_+V];D+=(V*V-k/P)*H,I+=V*H}let N=2*D/L/(i*i),O=I/k/i;F[E]=N/Math.pow(1+O*O,1.5)}}}return{name:e.name,closed:n.closed,x:c,y:l,s:u,ds:m,curvature:e.turnReach?U5(p,i,n.closed,e.turnReach):p,npts:s,length:C,nx:d,ny:f,z:S,gradient:A,...F?{verticalCurvature:F}:{},widthLeft:Ql(e.widthLeft,1.5,h,n),widthRight:Ql(e.widthRight,1.5,h,n),bank:Ql(e.bank,0,h,n),mu:Ql(e.mu,1,h,n),...y?.drift?{elevationDrift:y.drift}:{}}}function iT(e,t,r){let n=Vp(e,r),o=0;for(let a=0;a<r.length;a++)o+=.5*r[a]*n[a]-t[a]*r[a];return o}function X5(e,t,r,n){let o=e.n,a=e.closed!==!1,s=(l,u)=>{let m=l+u;return a?(m%o+o)%o:m>=0&&m<o?m:null},i=[...t];for(let l=0;l<o;l++){if(r[l]==="free")continue;let u=n(l);if(u!==0)for(let m of[-2,-1,1,2]){let p=s(l,m);p!=null&&(i[p]-=xn(e,p,l)*u)}}let c={n:o,closed:e.closed,diag:[...e.diag],off1:[...e.off1],off2:[...e.off2]};for(let l=0;l<o;l++){if(r[l]==="free")continue;c.diag[l]=1,c.off1[l]=0,c.off2[l]=0;let u=s(l,-1),m=s(l,-2);u!=null&&(c.off1[u]=0),m!=null&&(c.off2[m]=0),i[l]=n(l)}return oT(c,i)}var q5=1e-4;function cT(e,t,r,n,o={}){let a=e.n,s=o.maxIter??60,i=o.tol??1e-9,c=o.bounds,l=(f,h)=>Math.min(n[h],Math.max(r[h],f)),u=r.map((f,h)=>c?.[h]==="hi"?n[h]:c?.[h]==="lo"?r[h]:l(0,h)),m=iT(e,t,u),p=new Array(a).fill("free"),d=!1;for(let f=0;f<s;f++){let h=Vp(e,u).map((x,R)=>x-t[R]),b=!1;for(let x=0;x<a;x++){let R=u[x]<=r[x]+i&&h[x]>=-i?"lo":u[x]>=n[x]-i&&h[x]<=i?"hi":"free";R!==p[x]&&(p[x]=R,b=!0)}if(d&&!b)return{x:u,iterations:f+1,converged:!0,bounds:p};let g=X5(e,t,p,x=>u[x]);if(!g)return{x:u,iterations:f+1,converged:!1,bounds:p};let y=!1;for(let x=1;x>1e-12;x*=.5){let R=!1,v=u.map((C,F)=>{if(p[F]!=="free")return C;let T=C+x*(g[F]-C),M=l(T,F);return M!==T&&(R=!0),M}),S=iT(e,t,v),A=0;for(let C=0;C<a;C++)A+=h[C]*(v[C]-u[C]);if(x===1&&!R||S<m&&S<=m+q5*A){u=v,m=S,d=x===1&&!R,y=!0;break}}if(!y)return{x:u,iterations:f+1,converged:!1,bounds:p}}return{x:u,iterations:s,converged:!1,bounds:p}}var nx={lineStep:2,carHalfWidth:.75,margin:.1,foldMargin:.25,referenceReach:5,passes:40,iterations:400},Q5=[1,.5,.25,.125,.0625,.03125,.015625,.0078125,.00390625,.001953125,.0009765625],Z5=e=>Math.sqrt(e.reduce((t,r)=>t+r*r,0)/(e.length||1));function Zl(e,t,r=!0){let n=e.length,o=new Array(n).fill(0);for(let a=0;a<n;a++){if(!r&&(a===0||a===n-1))continue;let s=(a-1+n)%n,i=(a+1)%n,c=e[a]-e[s],l=t[a]-t[s],u=e[i]-e[a],m=t[i]-t[a],p=e[i]-e[s],d=t[i]-t[s],f=Math.hypot(c,l),h=Math.hypot(u,m),b=Math.hypot(p,d),g=f*h*b;o[a]=g>1e-12?2*(c*m-l*u)/g:0}return o}var J5=Math.PI/180,lT=20;function e$(e,t){let r=e.npts,n=e.closed,o=e.x.map((d,f)=>d+t[f]*e.nx[f]),a=e.y.map((d,f)=>d+t[f]*e.ny[f]),s=[0];for(let d=1;d<r;d++)s.push(s[d-1]+Math.hypot(o[d]-o[d-1],a[d]-a[d-1]));let i=n?s[r-1]+Math.hypot(o[0]-o[r-1],a[0]-a[r-1]):s[r-1],c=n?[-1,0,1]:[0],l=[],u=[];for(let d of c)for(let f=0;f<r;f++)l.push(s[f]+d*i),u.push(f+d*r);n&&(l.push(2*i),u.push(2*r));let m=[0];for(let d=1;d<l.length;d++)m.push(m[d-1]+.5*(u[d]+u[d-1])*(l[d]-l[d-1]));let p=d=>{let f=0,h=l.length-1;for(;h-f>1;){let g=f+h>>1;l[g]<=d?f=g:h=g}let b=l[h]>l[f]?(d-l[f])/(l[h]-l[f]):0;return m[f]+(l[h]-l[f])*b*(u[f]+.5*b*(u[h]-u[f]))};return s.map((d,f)=>{let h=n?lT:Math.min(lT,d,i-d);if(!(h>0))return e.z[f];let b=(p(d+h)-p(d-h))/(2*h),g=n?(b%r+r)%r:Math.min(Math.max(b,0),r-1),y=Math.min(Math.floor(g),r-1),x=n?(y+1)%r:Math.min(y+1,r-1);return e.z[y]+(g-y)*(e.z[x]-e.z[y])})}function t$(e,t,r){let n=Array.isArray(e.z)&&e.z.length>1,o=t.bank.some(i=>i!==0),a=t.mu.some(i=>i!==1),s=n?e$(t,r):t.z;return{...n||o?{z:s.map((i,c)=>i+r[c]*Math.tan(t.bank[c]*J5))}:{},...n?{zReach:e.zReach??Np(e)}:{},...o?{bank:[...t.bank]}:{},...a?{mu:[...t.mu]}:{}}}function uT(e,t,r=!0){let n=e.length,o=new Array(n).fill(0);for(let a=0;a<n;a++){if(!r&&(a===0||a===n-1))continue;let s=(a-1+n)%n,i=(a+1)%n;o[a]=.5*(Math.hypot(e[a]-e[s],t[a]-t[s])+Math.hypot(e[i]-e[a],t[i]-t[a]))}return o}function r$(e,t,r,n,o){let a=e.length,s=new Array(a).fill(0),i={l:new Array(a).fill(0),d:new Array(a).fill(0),r:new Array(a).fill(0)},c=(l,u,m,p)=>l*p-u*m;for(let l=0;l<a;l++){if(!o&&(l===0||l===a-1))continue;let u=(l-1+a)%a,m=(l+1)%a,p=e[l]-e[u],d=t[l]-t[u],f=e[m]-e[l],h=t[m]-t[l],b=e[m]-e[u],g=t[m]-t[u],y=Math.hypot(p,d),x=Math.hypot(f,h),R=Math.hypot(b,g),v=y*x*R;if(!(v>1e-12))continue;let S=2*c(p,d,f,h)/v,A=Math.sqrt(.5*(y+x)),C=S/(2*A),F=(p*r[u]+d*n[u])/y,T=(b*r[u]+g*n[u])/R,M=(p*r[l]+d*n[l])/y,k=(f*r[l]+h*n[l])/x,w=(f*r[m]+h*n[m])/x,P=(b*r[m]+g*n[m])/R,L=-2*c(r[u],n[u],f,h)/v+S*(F/y+T/R),E=2*c(r[l],n[l],b,g)/v-S*(M/y-k/x),_=2*c(p,d,r[m],n[m])/v-S*(w/x+P/R);s[l]=S*A,i.l[l]=A*L-C*.5*F,i.d[l]=A*E+C*.5*(M-k),i.r[l]=A*_+C*.5*w}return{res:s,jac:i}}function n$(e,t,r,n,o){let a=n-r+1,s=e.l.slice(r,n+1),i=e.d.slice(r,n+1),c=e.r.slice(r,n+1),l=t.slice(r,n+1);o||(i[0]+=s[0],s[0]=0,i[a-1]+=c[a-1],c[a-1]=0);let u=(h,b)=>o?h[(b+a)%a]:b>=0&&b<a?h[b]:0,m=new Array(a),p=new Array(a),d=new Array(a),f=new Array(a);for(let h=0;h<a;h++){let b=u(c,h-1),g=u(s,h+1);m[h]=b*b+i[h]*i[h]+g*g,p[h]=i[h]*c[h]+g*u(i,h+1),d[h]=g*u(c,h+1),f[h]=-(b*u(l,h-1)+i[h]*l[h]+g*u(l,h+1))}return{M:{n:a,closed:o,diag:m,off1:p,off2:d},b:f}}function o$(e,t){let r=e.npts,n=e.closed;if(!(t>0)||r<7)return e;let o=n?r:r-1,a=0;for(let p=0;p<o;p++){let d=(p+1)%r;a+=Math.hypot(e.x[d]-e.x[p],e.y[d]-e.y[p])}let s=a/o,i=$p(e.x,s,n,t,!0),c=$p(e.y,s,n,t,!0),l=new Array(r),u=new Array(r);for(let p=0;p<r;p++){let d=n?(p-1+r)%r:Math.max(p-1,0),f=n?(p+1)%r:Math.min(p+1,r-1),h=i[f]-i[d],b=c[f]-c[d],g=Math.hypot(h,b)||1;l[p]=-b/g,u[p]=h/g}let m=Zl(i,c,n);return n||(m[0]=m[1],m[r-1]=m[r-2]),{...e,x:i,y:c,nx:l,ny:u,curvature:m}}var a$=6;function s$(e,t,r,n){let o=e.npts,a=e.closed?o:o-1,s=new Array(a);for(let l=0;l<a;l++){let u=(l+1)%o,m=Math.atan2(e.nx[l]*e.ny[u]-e.ny[l]*e.nx[u],e.nx[l]*e.nx[u]+e.ny[l]*e.ny[u]),p=Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]);s[l]=p>1e-9?m/p:0}let i=Math.max(0,Math.round(a$/(e.ds[0]||1))),c=1-n;for(let l=0;l<o;l++){let u=0,m=0;for(let p=-i-1;p<=i;p++){let d=e.closed?((l+p)%o+o)%o:l+p;d<0||d>=a||(u=Math.max(u,s[d]),m=Math.max(m,-s[d]))}u>0&&(t[l]=Math.max(r[l],Math.min(t[l],c/u))),m>0&&(r[l]=Math.min(t[l],Math.max(r[l],-c/m)))}}function ox(e,t={}){let r={...nx,...t},n=$t(e,{dsTarget:r.lineStep}),o=o$(n,r.referenceReach),a=o.npts,s=M=>({x:o.x.map((k,w)=>k+o.nx[w]*M[w]),y:o.y.map((k,w)=>k+o.ny[w]*M[w])}),i=M=>{let k=Zl(M.x,M.y,o.closed),w=uT(M.x,M.y,o.closed),P=0;for(let L=0;L<k.length;L++)P+=k[L]*k[L]*w[L];return P},c=Z5(n.curvature),l=uT(n.x,n.y,n.closed).reduce((M,k)=>M+k,0),u=new Array(a).fill(0),m=r.carHalfWidth+r.margin,p=new Array(a),d=new Array(a),f=0;for(let M=0;M<a;M++){let k=o.widthLeft[M]-m,w=-(o.widthRight[M]-m);if(k<w){f++;let P=(o.widthLeft[M]-o.widthRight[M])/2;p[M]=P,d[M]=P}else p[M]=k,d[M]=w}let h=[...p],b=[...d];s$(o,p,d,r.foldMargin);let g=M=>{let k=s(M),w=t$(e,o,M),P={name:`${e.name} \u2014 racing line`,x:k.x,y:k.y,closed:o.closed,widthLeft:h.map((O,V)=>Math.max(0,O-M[V])),widthRight:b.map((O,V)=>Math.max(0,M[V]-O)),...w,fit:"interpolate",turnReach:rx},L=1e-6,E=M.filter((O,V)=>O>=p[V]-L||O<=d[V]+L).length,_=Zl(k.x,k.y,o.closed),D=O=>1/Math.max(...O.map(Math.abs),1e-9),I=0,N=o.closed?k.x.length:k.x.length-1;for(let O=0;O<N;O++){let V=(O+1)%k.x.length,H=k.x[V]-k.x[O],U=k.y[V]-k.y[O];I+=w.z?Math.hypot(H,U,w.z[V]-w.z[O]):Math.hypot(H,U)}return{offset:M,s:[...o.s],asset:P,curvatureRms:{centreLine:c,racingLine:Math.sqrt(i(k)/(l||1))},infeasibleSamples:f,atBoundary:a?E/a:0,length:{centreLine:n.length,racingLine:I},worstRadius:{centreLine:D(n.curvature),racingLine:D(_)}}},y=o.closed?0:1,x=o.closed?a-1:a-2,R=x-y+1,v=new Array(R),S=new Array(R);for(let M=0;M<R;M++)v[M]=d[y+M],S[M]=p[y+M];if(!o.closed&&R>0){let M=(k,w)=>{if(v[k]=Math.max(v[k],d[w]),S[k]=Math.min(S[k],p[w]),v[k]>S[k]){let P=.5*(v[k]+S[k]);v[k]=P,S[k]=P}};M(0,0),M(R-1,a-1),v[0]=S[0]=Math.min(S[0],Math.max(v[0],0))}if(R<7)return g(u);let A=M=>{let k=s(M),P=[...Zl(k.x,k.y,o.closed).map(Math.abs)].sort((L,E)=>L-E);return{integral:i(k),tail:P[Math.floor(.99*(P.length-1))]}},C=[...u],F=A(u),T;for(let M=0;M<r.passes;M++){let k=s(C),{res:w,jac:P}=r$(k.x,k.y,o.nx,o.ny,o.closed),{M:L,b:E}=n$(P,w,y,x,o.closed),_=cT(L,E,v.map((N,O)=>N-C[y+O]),S.map((N,O)=>N-C[y+O]),{maxIter:r.iterations,bounds:T});T=_.bounds;let D=new Array(a).fill(0);for(let N=0;N<R;N++)D[y+N]=_.x[N];o.closed||(D[0]=D[1],D[a-1]=D[a-2]);let I=!1;for(let N of Q5){let O=C.map((H,U)=>H+N*D[U]),V=A(O);if(V.integral<F.integral*(1-1e-6)){C=O,F=V,I=!0;break}}if(!I)break}return g(C)}function ax(e){let t=Math.max(J(e,"track_front"),J(e,"track_rear"));return(t>0?t/2e3:.6)+.1}function Gp(e,t,r={}){if(!r.racingLine)return{asset:e,numerics:t,line:null};let n=r.params?ax(r.params):void 0,o=ox(e,{...r.line,...n?{carHalfWidth:n}:{}});return{asset:o.asset,numerics:{...t,fitSpacing:0},line:o}}function Jl(e,t,r={}){let n=Gp(e,t,r);return{track:$t(n.asset,n.numerics),line:n.line}}function sx(e=4,t=Jl){let r=new WeakMap;return(n,o,a={})=>{let s=a.racingLine===!0,i=s?[a.params?ax(a.params):null,a.line??null]:null,c=JSON.stringify([o,s,i]),l=r.get(n);l||(l=new Map,r.set(n,l));let u=l.get(c);if(u)return l.delete(c),l.set(c,u),u;let m=t(n,o,a);return l.set(c,m),l.size>e&&l.delete(l.keys().next().value),m}}var mT={racingLine:!1,standingStart:!1},Kp=256;function eu(e,t,r,n,o=mT,a=Jl){let s=Pa(n),{racingLine:i,standingStart:c,lapCounts:l}=o;return e.map(u=>{let{track:m}=a(t,r,{racingLine:i,params:u});return $y($l(u,s,{track:m,numerics:r,standingStart:c,lapCounts:l}))})}function ix(e,t){let r=Pa(e),n=r.score?r.score(t):null,o=r.field===r.score?n:r.field?r.field(t):null;return{scores:n,field:o}}function cx(e,t,r){let n={};for(let o of Pa(e).metrics)n[o.key]=o.value(t,r);return n}var Hp=37;var mx=287.05287,c$=461.495,zp=9.80665/(mx*.0065),l$=101325/(mx*288.15),u$=273.15,m$=-500,d$=6e3,p$=400,f$=1100,Yp={source:"car",altitudeM:0,pressure:{kind:"standard"},humidityPct:0};function h$(e){return 101325*Math.pow(1-.0065*e/288.15,zp)}function b$(e){return 288.15/.0065*(1-Math.pow(e/l$,1/(zp-1)))}function g$(e){return 288.15/.0065*(1-Math.pow(e/101325,1/zp))}function y$(e,t){return e*Math.pow(1-.0065*t/288.15,zp)}function x$(e){return 611.21*Math.exp((18.678-e/234.5)*(e/(257.14+e)))}function R$(e,t){switch(e.kind){case"standard":return h$(t);case"qnh":return y$(e.hPa*100,t);case"station":return e.hPa*100}}function tu(e,t,r=0,n=g$(e)){let o=t+u$,a=Math.min(.5*e,Math.max(0,Math.min(100,r))/100*x$(t)),s=e-a,i=s/(mx*o)+a/(c$*o);return{altitudeM:n,p:e,pDry:s,T:o,rho:i,densityAltitudeM:b$(i)}}function dT(e,t){return tu(R$(e.pressure,e.altitudeM),t,e.humidityPct,e.altitudeM)}var lx=(e,t,r)=>Math.min(r,Math.max(t,e)),ux=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Wp(e){if(!e||typeof e!="object")return structuredClone(Yp);let t=e,r=t.pressure??{},n=lx(ux(r.hPa,1013.25),p$,f$),o=r.kind==="qnh"?{kind:"qnh",hPa:n}:r.kind==="station"?{kind:"station",hPa:n}:{kind:"standard"};return{source:t.source==="venue"?"venue":"car",altitudeM:lx(ux(t.altitudeM,0),m$,d$),pressure:o,humidityPct:lx(ux(t.humidityPct,0),0,100)}}var Da=e=>e?.source==="venue",jp="the air the session states, at its venue";var v$=Math.PI/180;function k$(){return{ucaFront:[110,245,330],ucaRear:[-110,258,335],lcaFront:[130,185,112],lcaRear:[-130,205,116],tieInner:[-92,210,132],uprightUpper:[-6,542,352],uprightLower:[4,560,120],tieOuter:[-78,556,146],wheelCenter:[0,600,230],pushrodOuter:[8,520,128],rockerPivotA:[70,380,440],rockerPivotB:[-50,383,442],rockerToPushrod:[65,478.6,419.1],rockerToDamper:[10,280,440],damperChassis:[10,275,245]}}function M$(){return{ucaFront:[120,250,340],ucaRear:[-120,262,345],lcaFront:[140,190,118],lcaRear:[-140,210,122],tieInner:[120,215,150],uprightUpper:[-4,548,360],uprightLower:[6,566,126],tieOuter:[108,560,158],wheelCenter:[0,610,232],pushrodOuter:[10,526,132],rockerPivotA:[70,385,450],rockerPivotB:[-50,388,452],rockerToPushrod:[67,484.6,429.1],rockerToDamper:[12,286,450],damperChassis:[12,281,255]}}function dx(e){let t=-e*v$;return ee([0,Math.cos(t),Math.sin(t)])}function Up(){let e={rodType:"push",pushrodAttach:"lowerArm",steerMode:"rack",spinAxis:dx(-1),loadedRadius:230,springRate:35,rackAxis:[0,1,0]};return{hardpoints:k$(),config:e}}function ru(){let e={rodType:"pull",pushrodAttach:"lowerArm",steerMode:"fixed",spinAxis:dx(-1.5),loadedRadius:232,springRate:40,rackAxis:[0,1,0]};return{hardpoints:M$(),config:e}}function Xp(){let e=[-25,635,460],t=[-40,600,710],r={layout:"mcpherson",actuation:"direct",rodType:"push",pushrodAttach:"upright",steerMode:"rack",spinAxis:dx(-.5),loadedRadius:320,springRate:38,rackAxis:[0,1,0],rackTravel:70};return{hardpoints:{ucaFront:[49,426,430],ucaRear:[-99,425,431],lcaFront:[60,395,180],lcaRear:[-280,415,185],tieInner:[-150,375,256],uprightUpper:[...e],uprightLower:[0,720,145],tieOuter:[-140,705,230],wheelCenter:[0,775,320],pushrodOuter:[...e],damperChassis:[...t],rockerPivotA:[...t],rockerPivotB:[...t],rockerToPushrod:[...e],rockerToDamper:[...t]},config:r}}function px(){return{front:Up(),rear:ru(),config:{wheelbase:1600,trackFront:1200,trackRear:1220,frontAxleX:800}}}var S$=Math.PI/180;function pT(e){let t=-e*S$;return ee([0,Math.cos(t),Math.sin(t)])}function fx(e,t){let r=([l,u,m])=>[l*t.kx,u*t.ky,m*t.kz],n=e.hardpoints,o=Object.fromEntries(Object.entries(n).map(([l,u])=>[l,r(u)])),a=(l,u)=>{o[l]=[o[l][0],o[l][1],o[l][2]+u]},s=t.lowerInnerDz??0,i=t.upperInnerDz??0;a("lcaFront",s),a("lcaRear",s),a("tieInner",s),a("ucaFront",i),a("ucaRear",i);let c={...e.config,spinAxis:pT(t.camberDeg),loadedRadius:t.loadedRadius,springRate:t.springRate};if(t.actuation==="direct"){let l=o.pushrodOuter,u=[l[0],l[1]*.7,l[2]+1.3*t.loadedRadius];o.damperChassis=u,o.rockerPivotA=u,o.rockerPivotB=u,o.rockerToPushrod=l,o.rockerToDamper=u,c={...c,actuation:"direct",rodType:"push",pushrodAttach:"lowerArm"}}else c={...c,actuation:"rocker"};for(let l of Object.keys(o))o[l]=A$(o[l]);return{hardpoints:o,config:c}}function A$(e){return e.map(t=>Math.round(t*10)/10+0)}function Ea(e){return{name:e.name,front:fx(Up(),e.front),rear:fx(ru(),e.rear),config:{wheelbase:e.wheelbase,trackFront:e.trackFront,trackRear:e.trackRear,frontAxleX:e.wheelbase/2}}}function Ri(e,t,r){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:t}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:r}}}}var vi=600,Ia=610,ki=230,_a=232;function Na(){let e=px();return{...e,name:"Formula Student",front:{...e.front,config:{...e.front.config,actuation:"rocker"}},rear:{...e.rear,config:{...e.rear.config,actuation:"rocker"}}}}function hx(){return Ea({name:"Formula 1",wheelbase:3600,trackFront:1600,trackRear:1600,front:{kx:1.3,ky:800/vi,kz:355/ki,lowerInnerDz:-5,upperInnerDz:0,camberDeg:-3,loadedRadius:355,springRate:200},rear:{kx:1.3,ky:800/Ia,kz:355/_a,lowerInnerDz:35,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:220}})}function nu(){return Ri(Ea({name:"GT car",wheelbase:2700,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/vi,kz:325/ki,lowerInnerDz:18,upperInnerDz:5,camberDeg:-3.5,loadedRadius:325,springRate:110,actuation:"direct"},rear:{kx:1.2,ky:825/Ia,kz:325/_a,lowerInnerDz:36,upperInnerDz:15,camberDeg:-2,loadedRadius:325,springRate:120,actuation:"direct"}}),318.6,318.6)}function ou(){return Ri(Ea({name:"Sports car",wheelbase:2750,trackFront:1550,trackRear:1550,front:{kx:1.15,ky:775/vi,kz:320/ki,lowerInnerDz:36,upperInnerDz:15,camberDeg:-.5,loadedRadius:320,springRate:55,actuation:"direct"},rear:{kx:1.15,ky:775/Ia,kz:320/_a,lowerInnerDz:57,upperInnerDz:25,camberDeg:-1,loadedRadius:320,springRate:60,actuation:"direct"}}),305.4,309)}function w$(e,t,r,n,o,a){let s=Xp(),i=Object.fromEntries(Object.entries(s.hardpoints).map(([l,[u,m,p]])=>[l,[u,m+e,p]])),c=(l,u)=>{i[l]=[i[l][0],i[l][1],i[l][2]+u]};return c("lcaFront",t),c("lcaRear",t),c("tieInner",r),{hardpoints:i,config:{...s.config,spinAxis:pT(n),springRate:o,rackTravel:a}}}function fT(){return Ri({name:"Cup car",front:w$(55,-25,-23,-3.5,150,55),rear:fx(ru(),{kx:1.15,ky:820/Ia,kz:320/_a,lowerInnerDz:37,upperInnerDz:12,camberDeg:-2,loadedRadius:320,springRate:130,actuation:"direct"}),config:{wheelbase:2650,trackFront:1660,trackRear:1640,frontAxleX:2650/2},chassis:{boxes:[],body:"cup"}},306.3,311.6)}function hT(){return{...Ri(Ea({name:"Stock car",wheelbase:2794,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/vi,kz:355/ki,lowerInnerDz:20,upperInnerDz:5,camberDeg:-2.5,loadedRadius:355,springRate:175,actuation:"direct"},rear:{kx:1.2,ky:825/Ia,kz:355/_a,lowerInnerDz:40,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:150,actuation:"direct"}}),343.8,345.3),chassis:{boxes:[],body:"nascar"}}}function bT(){let e=Ri(Ea({name:"Hill-climb prototype",wheelbase:2550,trackFront:1580,trackRear:1540,front:{kx:1.1,ky:790/vi,kz:300/ki,lowerInnerDz:10,upperInnerDz:5,camberDeg:-2.5,loadedRadius:300,springRate:90},rear:{kx:1.1,ky:770/Ia,kz:300/_a,lowerInnerDz:30,upperInnerDz:15,camberDeg:-1.5,loadedRadius:300,springRate:120}}),293.3,290.8);return{...e,front:{...e.front,config:{...e.front.config,rackTravel:45}},chassis:{boxes:[],body:"hillclimb"}}}function gT(){let e=Ri(Ea({name:"Race truck",wheelbase:3700,trackFront:2050,trackRear:1950,front:{kx:1.5,ky:1025/vi,kz:506/ki,lowerInnerDz:40,upperInnerDz:10,camberDeg:-.5,loadedRadius:506,springRate:200,actuation:"direct"},rear:{kx:1.5,ky:975/Ia,kz:506/_a,lowerInnerDz:60,upperInnerDz:20,camberDeg:-.25,loadedRadius:506,springRate:160,actuation:"direct"}}),490.4,495.6);return{...e,front:{...e.front,config:{...e.front.config,rackTravel:60}},chassis:{boxes:[],body:"truck"}}}var Lt=(e,t,r)=>({value:e,label:t,unit:r}),yT=(e,t)=>({...ln[e],value:t});function xT(e,t,r){let n=[],o=[];for(let a=0;a<=r;a+=500)n.push(a),o.push(a<=t?e:e*t/a);return{rpm:n,torque:o}}function Oa(e,t,r,n,o){let a=[],s=[];for(let i=0;i<=r;i+=500){a.push(i);let c=i<=t?n:Math.min(n,9549*e/i);s.push(c/o)}return{rpm:a,torque:s}}function to(e){let t={name:e.name,m:Lt(e.m,"vehicle mass (with driver)","kg"),A:Lt(e.A,"frontal area","m^2"),c_l:Lt(e.cl,"downforce coefficient","-"),c_w:Lt(e.cw,"drag coefficient","-"),l_to_d_ratio:Lt(e.cw>0?e.cl/e.cw:0,"lift-to-drag ratio","-"),driven_wheels:Lt(e.drivenWheels,"driven wheels","-"),fr_0:Lt(-.012,"rolling-resistance coefficient","-"),front_aero_diss:Lt(e.frontAero,"front aero distribution","-"),front_mass_diss:Lt(e.frontMass,"front mass distribution","-"),r_dyn:Lt(e.rDyn,"dynamic tyre radius","m"),rho:Lt(1.2,"air density","kg/m^3"),gear_ratio:Lt(e.gearRatio,"gear ratio","-"),effi_pgb:Lt(e.drivetrainEfficiency,"drivetrain efficiency","-"),capacity:Lt(e.capacityAh,"pack capacity","Ah"),soc:Lt(1,"state of charge","-"),ocv:Lt(e.ocv,"pack open-circuit voltage","V"),power_scale:Lt(1,"power scaling factor","-"),power_limit_kw:yT("power_limit_kw",e.powerLimitKw),motor:e.motor,tireModelId:e.tireModelId};e.motorCount!==void 0&&(t.motorCount=e.motorCount),e.driveline&&(t.driveline=structuredClone(e.driveline)),e.motorPlacement&&(t.motorPlacement=e.motorPlacement);for(let[r,n]of Object.entries(e.dynamics))t[r]=yT(r,n);return t}var Mi={name:"Formula Student",m:300,A:1,cl:3,cw:1.3,frontMass:.47,frontAero:.45,rDyn:.222,drivenWheels:2,gearRatio:11.5,motor:xT(25,15e3,2e4),capacityAh:12,ocv:550,drivetrainEfficiency:.95,powerLimitKw:80,tireModelId:"t3",dynamics:{grip_scale:1,stiffness_scale:1,endurance_reserve:5,cg_height:300,tire_vertical_rate:110,unsprung_mass:8,brake_balance:.62,arb_front:20,arb_rear:15,damper_front:2.5,damper_rear:2.5,spring_front:35,spring_rear:40,mr_front:.94,mr_rear:.92,cop_long:.55,cop_height:300,ride_height_front:30,ride_height_rear:35,I_yaw:140,I_roll:45,I_pitch:130,camber_front_deg:-1,camber_rear_deg:-1.5,track_front:1200,track_rear:1220,wheelbase:1600,rc_front:5,rc_rear:4}},gx={name:"Formula 1",m:798,A:1.5,cl:3,cw:.9,frontMass:.46,frontAero:.44,rDyn:.35,drivenWheels:2,gearRatio:4.9,motor:Oa(735,2e3,12500,2500,2),motorCount:1,driveline:{rear:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t4",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:290,tire_vertical_rate:300,unsprung_mass:30,brake_balance:.58,arb_front:250,arb_rear:150,damper_front:6,damper_rear:6,spring_front:200,spring_rear:220,mr_front:.95,mr_rear:.91,heave_spring_front:800,heave_spring_rear:800,tire_vertical_damping:.5,cop_long:.56,cop_height:400,ride_height_front:35,ride_height_rear:70,I_yaw:800,I_roll:150,I_pitch:800,camber_front_deg:-3,camber_rear_deg:-1.5,track_front:1600,track_rear:1600,wheelbase:3600,rc_front:-4,rc_rear:78}},qp={name:"GT car",m:1300,A:2,cl:1.4,cw:.42,frontMass:.5,frontAero:.42,rDyn:.33,drivenWheels:2,gearRatio:3.43,motor:Oa(410,2e3,8e3,2e3,2),motorCount:1,driveline:{rear:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t5",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:450,tire_vertical_rate:280,unsprung_mass:45,brake_balance:.6,arb_front:40,arb_rear:25,damper_front:4.5,damper_rear:4.5,spring_front:110,spring_rear:120,mr_front:.79,mr_rear:.77,cop_long:.58,cop_height:500,ride_height_front:55,ride_height_rear:75,I_yaw:1800,I_roll:450,I_pitch:1800,camber_front_deg:-3.5,camber_rear_deg:-2,track_front:1650,track_rear:1650,wheelbase:2700,rc_front:48,rc_rear:80}},Qp={name:"Sports car",m:1600,A:2.2,cl:-.1,cw:.3,frontMass:.55,frontAero:.5,rDyn:.32,drivenWheels:2,gearRatio:3.14,motor:Oa(220,1500,6500,1400,2),motorCount:1,driveline:{rear:er.open},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t6",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:520,tire_vertical_rate:220,unsprung_mass:50,brake_balance:.65,arb_front:25,arb_rear:12,damper_front:2.4,damper_rear:2.4,spring_front:55,spring_rear:60,mr_front:.78,mr_rear:.75,cop_long:.5,cop_height:500,ride_height_front:130,ride_height_rear:140,I_yaw:2600,I_roll:550,I_pitch:2500,camber_front_deg:-.5,camber_rear_deg:-1,track_front:1550,track_rear:1550,wheelbase:2750,rc_front:80,rc_rear:122}},yx={name:"Cup car",m:1265,A:2.1,cl:.45,cw:.4,frontMass:.62,frontAero:.45,rDyn:.31,drivenWheels:2,gearRatio:3.5,motor:Oa(250,2e3,7e3,1190,2),motorCount:1,motorPlacement:"front",driveline:{front:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t7",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:480,tire_vertical_rate:280,unsprung_mass:40,brake_balance:.68,arb_front:20,arb_rear:90,damper_front:4,damper_rear:3.5,spring_front:150,spring_rear:130,mr_front:.95,mr_rear:.76,cop_long:.55,cop_height:450,ride_height_front:64,ride_height_rear:78,I_yaw:1700,I_roll:400,I_pitch:1700,camber_front_deg:-3.5,camber_rear_deg:-2,track_front:1660,track_rear:1640,wheelbase:2650,rc_front:60,rc_rear:84}},xx={name:"Stock car",m:1620,A:2.2,cl:.6,cw:.45,frontMass:.53,frontAero:.45,rDyn:.35,drivenWheels:2,gearRatio:4.1,motor:Oa(500,2500,9e3,1680,2),motorCount:1,driveline:{rear:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t8",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:430,tire_vertical_rate:320,unsprung_mass:55,brake_balance:.6,arb_front:60,arb_rear:15,damper_front:7.5,damper_rear:6.75,spring_front:175,spring_rear:150,mr_front:.8,mr_rear:.78,cop_long:.55,cop_height:500,ride_height_front:75,ride_height_rear:90,I_yaw:2500,I_roll:550,I_pitch:2500,camber_front_deg:-2.5,camber_rear_deg:-1.5,track_front:1650,track_rear:1650,wheelbase:2794,rc_front:53,rc_rear:91}},Rx={name:"Hill-climb prototype",m:650,A:1.2,cl:2.5,cw:.9,frontMass:.42,frontAero:.42,rDyn:.29,drivenWheels:2,gearRatio:4,motor:Oa(330,3e3,8500,1240,2),motorCount:1,driveline:{rear:er.clutch},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t9",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:280,tire_vertical_rate:200,unsprung_mass:25,brake_balance:.58,arb_front:40,arb_rear:30,damper_front:3,damper_rear:3.5,spring_front:90,spring_rear:120,mr_front:.94,mr_rear:.91,cop_long:.58,cop_height:350,ride_height_front:45,ride_height_rear:55,I_yaw:550,I_roll:120,I_pitch:550,camber_front_deg:-2.5,camber_rear_deg:-1.5,track_front:1580,track_rear:1540,wheelbase:2550,rc_front:27,rc_rear:65}},vx={name:"Race truck",m:5300,A:6.2,cl:-.1,cw:.65,frontMass:.6,frontAero:.6,rDyn:.502,drivenWheels:2,gearRatio:3.55,motor:Oa(880,100,3e3,88e3,2),motorCount:1,driveline:{rear:er.spool},capacityAh:200,ocv:800,drivetrainEfficiency:.9,powerLimitKw:0,tireModelId:"t10",dynamics:{grip_scale:1,stiffness_scale:1,cg_height:950,tire_vertical_rate:1e3,unsprung_mass:350,brake_balance:.75,arb_front:350,arb_rear:150,damper_front:12,damper_rear:8.5,spring_front:200,spring_rear:160,mr_front:.81,mr_rear:.8,cop_long:.4,cop_height:1500,ride_height_front:240,ride_height_rear:240,I_yaw:16e3,I_roll:3500,I_pitch:16e3,camber_front_deg:-.5,camber_rear_deg:-.25,track_front:2050,track_rear:1950,wheelbase:3700,rc_front:95,rc_rear:134}};function bx(e,t,r){return to(r({...structuredClone(e),name:t}))}var Zp={[Mi.name]:to(Mi),"Formula Student +15% downforce":bx(Mi,"Formula Student +15% downforce",e=>({...e,cl:e.cl*1.15,cw:e.cw*1.08})),"Formula Student -15 kg":bx(Mi,"Formula Student -15 kg",e=>({...e,m:e.m-15})),"Formula Student +15% power":bx(Mi,"Formula Student +15% power",e=>({...e,motor:xT(25*1.15,15e3,2e4),powerLimitKw:80*1.15})),[gx.name]:to(gx),[qp.name]:to(qp),[Qp.name]:to(Qp),[yx.name]:to(yx),[xx.name]:to(xx),[Rx.name]:to(Rx),[vx.name]:to(vx)},RT=Object.keys(Zp),kx=RT.slice(0,4),Mx=[Mi.name,gx.name,qp.name,Qp.name,yx.name,xx.name,Rx.name,vx.name];var qme={"Touring car":qp.name,"Street car":Qp.name};var F$={bg:"#11141b",panel:"#161b22",panel2:"#202d3a",border:"#334050",borderBright:"#526477",sunken:"#0b1219",ink:"#06090d"},C$={normal:"#eef3fa",dim:"#9baab9",bright:"#ffffff",white:"#ffffff"},T$={label:"#c8d2dc",grid:"#39424e",gridFaint:"#232b35",empty:"#1a2028"},P$={accent:"#6aa8ff",accentInk:"#0d1b30",warn:"#ffb454",good:"#4ec9a0",bad:"#ff6b6b",badSoft:"#ff8f8f"},L$=["#f0e442","#7b68ee","#f7a8b8","#d55e00","#d8b4fe","#b5e48c"],Jp={front:"#a6e22e",rear:"#00b4d8"},vT=["#5b4bd6","#4aa3ff","#4ec9a0","#f0e442"],Sx={power:"#ffb454",traction:"#f0845c",front:Jp.front,rear:Jp.rear,grip:"#73c9b3",braking:"#b48aff",crest:"#e88fd0",below:"rgba(214, 221, 230, 0.32)"},D$={chassis:"#4aa3ff",ballJoint:"#ffb454",arm:"#b8c3cf",tie:"#73c9b3",pushrod:"#e5c65f",rocker:"#9f91d4",kingpin:"#d8c968",arbBar:"#cf7898",arbArm:"#b96b86",arbLink:"#ffb454",heaveSpring:"#7ad7f0",wheelCentre:"#e7ecf3",contactPatch:"#ff6b6b",ground:"#15222e",groundFaint:"#0b151f"},E$={x:"#ff6b6b",y:"#57c75a",z:"#4aa3ff"},I$={line:"#b4bfcb"},_$={compression:"#b48aff",tension:"#ff6b6b"},N$={fz:"#e7ecf3",fx:"#7ad7f0",fy:"#ff54c8"},O$={drivenLine:"#4d7cff",axis:"#eef3fa",slip:"#ffe81a",drive:Sx.power,brake:Sx.braking},V$={ground:"#101920",grid:"#1a2630",gridMajor:"#26343f",horizon:"#1d2833",bridge:"#6f7a86",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},B$={chassis:"#435160",volume:"#303b47",tyre:"#435160",tyreLine:"#39424e",tyreFace:"#1c232d"},$$={centreLine:"#4aa3ff",corridorFill:"rgba(74,163,255,0.10)",boundary:"#3d4956",racingLine:"#ffb454",start:"#e7ecf3",finish:"#ff6b6b",direction:"#8b96a3"},G$={SURFACE:F$,TEXT:C$,CHART:T$,ROLE:P$,SERIES:L$,AXLE:Jp,LAP_SPEED:vT,LIMITER:Sx,RIG:D$,AXIS:E$,CONSTRUCTION:I$,FORCE:_$,TYRE_FORCE:N$,REPLAY:O$,SCENERY:V$,BODY:B$,TRACK:$$},kT=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):Object.freeze({...r})])),ef=kT(G$),rr=ef.SERIES,MT=(()=>{let e="#b06400",t="#d1343a",r={front:"#70bf03",rear:"#3392d0"},n={power:e,traction:"#d05a2a",front:r.front,rear:r.rear,grip:"#2a9a83",braking:"#7b55d0",crest:"#c2479f",below:"rgba(34, 39, 45, 0.28)"};return kT({SURFACE:{bg:"#f5f6f6",panel:"#fcfcfd",panel2:"#ffffff",border:"#d8dfe6",borderBright:"#b7c3ce",sunken:"#e8edf2",ink:"#ffffff"},TEXT:{normal:"#17212c",dim:"#606c79",bright:"#10171f",white:"#000000"},CHART:{label:"#3a424b",grid:"#c2c8cd",gridFaint:"#e2e5e7",empty:"#e8eae7"},ROLE:{accent:"#2162bd",accentInk:"#ffffff",warn:e,good:"#0f8a66",bad:t,badSoft:"#e2696d"},SERIES:["#b5a11a","#2844e3","#f47ec1","#9b3a1b","#764299","#58b977"],AXLE:r,LAP_SPEED:["#4b3bc4","#1a64c2","#0f8a66","#a87e00"],LIMITER:n,RIG:{chassis:"#1a64c2",ballJoint:"#c27200",arm:"#56616d",tie:"#24907b",pushrod:"#a3820f",rocker:"#6656b8",kingpin:"#8f7f10",arbBar:"#b04d77",arbArm:"#9a4767",arbLink:"#c27200",heaveSpring:"#1688ad",wheelCentre:"#15181c",contactPatch:t,ground:"#e2e6e8",groundFaint:"#edf0f1"},AXIS:{x:"#d93a3a",y:"#2f9d34",z:"#1a64c2"},CONSTRUCTION:{line:"#5a6570"},FORCE:{compression:"#7b55d0",tension:t},TYRE_FORCE:{fz:"#ffe600",fx:"#0f8fb0",fy:"#c8198f"},REPLAY:{drivenLine:"#2f5be0",axis:"#15181c",slip:"#c79a00",drive:n.power,brake:n.braking},SCENERY:{ground:"#dde3e1",grid:"#ccd3d1",gridMajor:"#b5bfbc",horizon:"#e8edf0",bridge:"#9aa3ab",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},BODY:{chassis:"#a9b3bd",volume:"#c7ced5",tyre:"#24282c",tyreLine:"#2c333a",tyreFace:"#c3cad0"},TRACK:{centreLine:"#1a64c2",corridorFill:"rgba(26,100,194,0.10)",boundary:"#a3acb4",racingLine:e,start:"#15181c",finish:t,direction:"#5c6570"}})})();var ST=e=>{let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());return t?`#${(t[1].length===3?t[1].replace(/./g,n=>n+n):t[1]).toLowerCase()}`:null},Zme=(()=>{let e=new Map,t=["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION","TEXT","CHART","SCENERY","BODY","SURFACE"];for(let r of t){let n=ef[r],o=MT[r];for(let a of Object.keys(n)){let s=ST(n[a]);s&&!e.has(s)&&e.set(s,o[a])}}return e})();var AT=(e,t)=>new Set(t.flatMap(r=>{let n=e[r];return Array.isArray(n)?[...n]:Object.values(n)}).map(ST).filter(r=>r!==null)),Jme=AT(MT,["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION"]),ede=AT(ef,Object.keys(ef).filter(e=>e!=="SURFACE"));function Ax(){return{kind:"simple",name:"Simple motor",rpm:[0,16e3,2e4],torque:[21,21,14],efficiency:.95}}function wx(){return{kind:"map",name:"Mapped motor",rpm:[0,8e3,16e3,2e4],torque:[24,24,21,16],effRpm:[1e3,5e3,9e3,13e3,17e3,2e4],effTorque:[4,8,12,16,21],effGrid:[[.78,.84,.86,.85,.82,.79],[.83,.9,.93,.92,.89,.86],[.85,.93,.96,.95,.92,.89],[.84,.92,.95,.94,.91,.88],[.82,.89,.92,.9,.87,.84]]}}function Fx(){return{kind:"simple",name:"Inboard motor, axial flux (example)",rpm:[0,4e3,4500,5e3,5500,6e3],torque:[230,230,204,184,167,153],efficiency:.95}}function Cx(){return{kind:"ice",name:"600 cc four, restricted (example)",rpm:[3e3,4e3,5e3,6e3,7e3,8e3,9e3,1e4,11e3,12e3,12500],torque:[40,46,52,56,59,61,62,60,56,49,45],idleRpm:3e3,limitRpm:12500,inertia:.012,gearbox:{primary:76/36,ratios:[33/12,32/16,30/18,26/18,30/23,29/24],efficiency:.9,upshiftTime:.1,downshiftTime:.08},breathing:{induction:{kind:"natural"}}}}function Tx(){return{kind:"ice",name:"Formula 1 power unit (example)",rpm:[4e3,5e3,6e3,7e3,8e3,9e3,1e4,10500,11e3,11500,12e3,12500],torque:[896,822,773,738,712,692,675,668,638,610,585,545],idleRpm:4e3,limitRpm:12500,inertia:.02,gearbox:{primary:1,ratios:[4,3.15,2.575,2.175,1.85,1.6,1.375,1.18],efficiency:.94,upshiftTime:0,downshiftTime:0,driveKept:1},breathing:{induction:{kind:"boosted",boostKPa:350,maxPressureRatio:5}}}}function wT(){return{kind:"ice",name:"GT race engine, 4.0 l (example)",rpm:[2500,3e3,3500,4e3,4500,5e3,5500,6e3,6500,7e3,7500,8e3],torque:[380,410,440,465,485,500,515,525,530,540,522,480],idleRpm:2500,limitRpm:8e3,inertia:.15,gearbox:{primary:1,ratios:[3,2.15,1.7,1.4,1.17,.98],efficiency:.93,upshiftTime:.05,downshiftTime:.08},breathing:{induction:{kind:"natural"}}}}function FT(){return{kind:"ice",name:"Turbocharged 3.0 l six (example)",rpm:[1e3,1500,1800,2500,3500,4500,5e3,5500,6e3,6500,7e3],torque:[230,340,400,400,400,400,400,382,350,315,280],idleRpm:1e3,limitRpm:7e3,inertia:.2,gearbox:{primary:1,ratios:[3.6,2.19,1.54,1.21,1,.83],efficiency:.92,upshiftTime:.2,downshiftTime:.2,driveKept:.8},breathing:{induction:{kind:"boosted",boostKPa:220,maxPressureRatio:3}}}}function CT(){return{kind:"ice",name:"Turbocharged 2.0 l four (example)",rpm:[2e3,2500,3e3,3500,4e3,4500,5e3,5500,6e3,6500,7e3],torque:[330,400,420,420,420,420,415,410,398,365,330],idleRpm:2e3,limitRpm:7e3,inertia:.15,gearbox:{primary:1,ratios:[2.92,2.05,1.61,1.32,1.12,.97],efficiency:.93,upshiftTime:.07,downshiftTime:.08},breathing:{induction:{kind:"boosted",boostKPa:250,maxPressureRatio:3.2}}}}function TT(){return{kind:"ice",name:"Stock car V8, 5.9 l (example)",rpm:[2500,3e3,3500,4e3,4500,5e3,5500,6e3,6500,7e3,7500,8e3,8500,9e3],torque:[450,480,510,535,555,570,585,595,600,598,590,578,562,525],idleRpm:2500,limitRpm:9e3,inertia:.18,gearbox:{primary:1,ratios:[2.8,2,1.55,1.24,1],efficiency:.93,upshiftTime:.1,downshiftTime:.1},breathing:{induction:{kind:"natural"}}}}function PT(){return{kind:"ice",name:"Turbocharged 2.0 l four, hill climb (example)",rpm:[3e3,3500,4e3,4500,5e3,5500,6e3,6500,7e3,7500,8e3,8500],torque:[314,380,446,462,462,462,458,450,437,420,388,347],idleRpm:3e3,limitRpm:8500,inertia:.1,gearbox:{primary:1,ratios:[2.69,2,1.6,1.33,1.14,1],efficiency:.93,upshiftTime:.05,downshiftTime:.08},breathing:{induction:{kind:"boosted",boostKPa:250,maxPressureRatio:4.5}}}}function LT(){return{kind:"ice",name:"Race truck diesel six, 13 l (example)",rpm:[800,1e3,1200,1400,1600,1800,2e3,2200,2400,2600,2800,3e3],torque:[3e3,4e3,4900,5500,5250,4670,4200,3820,3500,3230,3e3,2700],idleRpm:800,limitRpm:3e3,inertia:1.5,gearbox:{primary:1,ratios:[16,12.44,9.67,7.51,5.84,4.54,3.53,2.74,2.13,1.66,1.29,1],efficiency:.92,upshiftTime:.35,downshiftTime:.35},breathing:{induction:{kind:"boosted",boostKPa:350,maxPressureRatio:4.3}}}}function DT(e){return Ca(K$(e))}function K$(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;let t={...e};return delete t.name,delete t.parts,Array.isArray(t.vehicles)&&(t.vehicles=t.vehicles.map(r=>{if(r===null||typeof r!="object"||Array.isArray(r))return r;let n={...r};return delete n.name,n})),t}function au(e,t){return{...t,fingerprint:DT(e)}}var ET="CC-BY-4.0",H$={title:"PaceDynamics built-in library",url:"https://pacedyn.dev/",licence:ET},IT={fidelity:"generic",licence:ET,sources:[H$]};var tf=e=>au(e,IT);var _T=["raw.githubusercontent.com"],NT=["tum-csv"],Y$=/^[0-9a-f]{64}$/;function iu(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let{url:t,sha256:r,format:n}=e;if(typeof t!="string"||t.length>500||typeof r!="string"||!Y$.test(r)||!NT.includes(n))return!1;try{let o=new URL(t);return o.protocol==="https:"&&_T.includes(o.hostname)&&!o.username&&!o.password&&!o.port}catch{return!1}}var rf=e=>new URL(e.url).hostname;async function OT(e){let t=await globalThis.crypto.subtle.digest("SHA-256",e);return[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0")).join("")}function W$(e){let t=new URL(e).pathname.split("/").pop()??"";return decodeURIComponent(t).replace(/\.[^.]*$/,"")||"Linked track"}function j$(e,t){let r=[],n=[],o=[],a=[];for(let[s,i]of e.split(/\r?\n/).entries()){let c=i.trim();if(!c||c.startsWith("#"))continue;let l=c.split(",").map(u=>Number(u.trim()));if(l.length!==4||!l.every(Number.isFinite))throw new Error(`Line ${s+1} of ${t} is not four numbers.`);r.push(l[0]),n.push(l[1]),o.push(l[2]),a.push(l[3])}if(r.length<3)throw new Error(`${t} has ${r.length} points; a track needs at least 3.`);return{name:t,x:r,y:n,widthLeft:a,widthRight:o,closed:!0,fit:"interpolate"}}var U$={"tum-csv":j$};function VT(e,t){return U$[t.format](e,W$(t.url))}async function Px(e,t,r){let n=await OT(e);if(n!==t.sha256)throw new Error(`${rf(t)} did not return the file that was reviewed (its SHA-256 is ${n.slice(0,12)}\u2026, not ${t.sha256.slice(0,12)}\u2026).`);let o=VT(new TextDecoder().decode(e),t),a=await nf(o);if(a!==r)throw new Error(`Linked track ${r} does not convert to its name (it is ${a}).`);return o}var Lx=20,q$=new RegExp(`^[0-9a-f]{${Lx}}$`),cu=e=>typeof e=="string"&&q$.test(e);async function nf(e){let t=new TextEncoder().encode(To(e)),r=await globalThis.crypto.subtle.digest("SHA-256",t);return[...new Uint8Array(r)].map(n=>n.toString(16).padStart(2,"0")).join("").slice(0,Lx)}var Dx=e=>`tracks/${e}.json`;var Q$=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Ex(e){return{model:{name:e.name,source:e.source},...e.provenance?{provenance:e.provenance}:{}}}async function Ix(e,t){if(!Q$(e)||typeof e.name!="string"||!Array.isArray(e.x)||!Array.isArray(e.y)||e.x.length!==e.y.length||e.x.length<2)throw new Error(`Catalogue track ${t} is not a track.`);let r=await nf(e);if(r!==t)throw new Error(`Catalogue track ${t} does not match its name (it is ${r}).`);return e}var Va=(e,t,r,n=[])=>({doc:e,ref:t,refs:[t,...n.map(o=>o.ref)],slots:[{key:e,ref:t,label:r},...n],label:r}),Po=[Va("suspensions","suspensionId","suspension"),Va("tires","tireModelId","tyre",[{key:"tiresRear",ref:"tireModelIdRear",label:"rear tyre"}]),Va("motors","motorModelId","motor"),Va("aeros","aeroModelId","aero map"),Va("batteries","batteryModelId","battery"),Va("brakes","brakeModelId","brakes"),Va("dampers","damperModelId","dampers",[{key:"dampersRear",ref:"damperModelIdRear",label:"rear dampers"},{key:"dampersHeave",ref:"heaveDamperModelId",label:"heave dampers"},{key:"dampersRoll",ref:"rollDamperModelId",label:"roll dampers"}])];function of(e){let t={...e};for(let r of Po)for(let n of r.refs)delete t[n];return t}var af=rr,lu=af,_x=af,Lo=[...rr.slice(3),...rr.slice(0,3)],Vx=[...rr.slice(1),rr[0]],Nx=[...rr.slice(2),...rr.slice(0,2)],Ox=[...rr.slice(4),...rr.slice(0,4)],Bx=[...rr.slice(5),...rr.slice(0,5)],uu=[...rr.slice(2),...rr.slice(0,2)];function $x(){let e=globalThis.crypto;return e&&typeof e.randomUUID=="function"?e.randomUUID():`p-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Gx(e,t,r){let n=Zp[e];if(!n)throw new Error(`no preset vehicle named "${e}"`);return{id:t,params:{...il(structuredClone(n)),energy:{...Kr},suspensionId:"sus1"},visible:!0,color:lu[r%lu.length]}}function eG(){return kx.map((e,t)=>Gx(e,`v${t+1}`,t))}function tG(){return[Nc(),hg(),bg(),gg(),yg(),xg(),Rg(),vg(),kg(),Mg()].map((t,r)=>({id:`t${r+1}`,color:_x[r%_x.length],model:t}))}function rG(){return[Qh(),Zh(),Jh(),eb(),tb(),rb(),nb(),ob()].map((t,r)=>({id:`a${r+1}`,color:Nx[r%Nx.length],model:t}))}function nG(){return[Nh(),Oh(),Vh()].map((t,r)=>({id:`b${r+1}`,color:Ox[r%Ox.length],model:t}))}function oG(){return[{id:"brk1",color:Bx[0],model:structuredClone(Hg)}]}function aG(){return[{id:"dmp1",color:uu[0],model:structuredClone(Ed)}]}function sG(){return[Ax(),wx()].map((t,r)=>({id:`m${r+1}`,color:Lo[r%Lo.length],model:t}))}function Kx(e){let t=r=>({...r,provenance:tf(r.model)});return{...e,suspensions:e.suspensions.map(t),vehicles:e.vehicles.map(r=>({...r,provenance:tf(of(r.params))})),tires:e.tires.map(t),motors:e.motors.map(t),aeros:e.aeros.map(t),batteries:e.batteries.map(t),brakes:e.brakes.map(t),dampers:e.dampers.map(t)}}function mu(e="Untitled project"){let t=new Date().toISOString(),r=eG();return Kx({schemaVersion:Hp,meta:{id:$x(),name:e,domain:"racecar",rulesetId:Ta,createdAt:t,updatedAt:t},suspensions:[{id:"sus1",color:Vx[0],model:Na()}],activeSuspensionId:"sus1",vehicles:r,activeVehicleId:r[0]?.id??null,tires:tG(),motors:sG(),aeros:rG(),batteries:nG(),brakes:oG(),dampers:aG(),tracks:[],activeTrackId:null,mathChannels:[],rulesets:[],studies:[],activeStudyId:null,loadCases:[],reportLayouts:[],tyreSheets:[],kinSheets:[],lapSheets:[],plans:[],results:[],settings:{numerics:{...Al},ggvMode:"twoTrack",quasiTransient:!1,motorThermal:!1,brakeFade:!1,airTempC:ur,air:structuredClone(Yp),diffYaw:!1,lapCounts:{},pathPlanId:null,useRacingLine:!0,standingStart:!1}})}var iG=["front","rear"],Hx=9.81,cG=Math.PI/180;var Rn="*",zx=40,BT=.8;function Yx(e){let{s:t,curvature:r}=e;if(!t?.length||t.length!==r?.length)return null;let n=0,o=0,a=0,s=0;for(let i=0;i<t.length;i++){for(;a<t.length&&t[a]<=t[i]+2.5;)s+=Math.abs(r[a++]);for(;t[o]<t[i]-2.5;)s-=Math.abs(r[o++]);let c=s/Math.max(1,a-o);c>n&&(n=c)}return n>1e-6?1/n:null}function $T(e,t,r){let n=t.rows.map(c=>c.v),o=c=>Pt(n,t.rows.map(l=>l.ayMax),Math.min(n[n.length-1],Math.max(n[0],c))),a=(c,l,u)=>({speedKmh:Math.round(c*36)/10,ayG:Math.round(l/Hx*100)/100+0,axG:Math.round(u/Hx*100)/100+0}),s=t.vMax,i=Array.from({length:41},(c,l)=>20/3.6+l*Math.max(0,s-20/3.6)/40);switch(e){case"slowCorner":{if(r===null)return a(zx/3.6,o(zx/3.6),0);let c=10;for(let l=0;l<30;l++)c=Math.min(s,Math.sqrt(r*o(c)));return a(c,o(c),0)}case"fastCorner":return a(BT*s,o(BT*s),0);case"braking":{let c=i.reduce((l,u)=>t.axDecel(u,0)<t.axDecel(l,0)?u:l);return a(c,0,t.axDecel(c,0))}case"traction":{let c=i.reduce((l,u)=>t.axAccel(u,0)>t.axAccel(l,0)?u:l);return a(c,0,t.axAccel(c,0))}case"topSpeed":return a(s,0,0)}}function Wx(e,t,r){let n=!1,o=e.map(a=>{if(!a.follows)return a;let s=$T(a.follows,t,r);return![s.speedKmh,s.ayG,s.axG].every(Number.isFinite)||!t.rows.some(i=>i.ayMax>0)||s.speedKmh===a.speedKmh&&s.ayG===a.ayG&&s.axG===a.axG?a:(n=!0,{...a,...s})});return n?o:e}function jx(e,t){let r=e.speedKmh/3.6,n=e.ayG*Hx;if(!(Math.abs(n)>1e-6)||!(r>.1))return 0;let o=r*r/Math.abs(n);return Math.sign(n)*Math.atan(t/1e3/o)/cG}var GT=e=>e.ayG<0?"L":"R";function Ux(e,t=iG){if(!e.length||!t.length)return null;let r=t.flatMap(i=>i==="front"?["FL","FR"]:["RL","RR"]),n=0,o=0,a=0;for(let i of e){for(let c of r){let l=i.corners[c].travel;if(!Number.isFinite(l))return null;n=Math.min(n,l),o=Math.max(o,l)}a=Math.max(a,Math.abs(i.rollDeg))}let s=5;return{travelMin:Math.min(-1,Math.floor(n-s)),travelMax:Math.max(1,Math.ceil(o+s)),rollMaxDeg:Math.max(.5,Math.ceil((a+.5)*10)/10),rollAtLimitDeg:Math.ceil(a*10)/10}}var Xx=(e,t)=>e.travelMin===t.travelMin&&e.travelMax===t.travelMax&&e.rollMaxDeg===t.rollMaxDeg&&e.rollAtLimitDeg===t.rollAtLimitDeg;var ro=Math.PI/180,lG=9.81,du=.1,qx=20,KT=6,WT=50;function HT(e,t,r){let n=e(0),o=0;for(let p=t;p<=r+1e-9;p+=t){let d=e(p);if(d>n)n=d,o=p;else if(p>o+3*t)break}let a=Math.max(0,o-t),s=Math.min(r,o+t),i=.6180339887498949,c=s-i*(s-a),l=a+i*(s-a),u=e(c),m=e(l);for(let p=0;p<14;p++)u>m?(s=l,l=c,m=u,c=s-i*(s-a),u=e(c)):(a=c,c=l,u=m,l=a+i*(s-a),m=e(l));return u>n?u>=m?{force:u,at:c}:{force:m,at:l}:m>n?{force:m,at:l}:{force:n,at:o}}function Qx(e,t,r,n,o){let a=o*ro;if(t==="side")return HT(i=>r*e.Fy(r*i*ro,n,a),1,45);let s=t==="drive"?1:-1;return HT(i=>s*e.Fx(s*i,n,a),.02,.6)}function cf(e){let t=e?jm(e)?.gamma:void 0,r=[t?.min,t?.max].filter(o=>o!==void 0&&Number.isFinite(o));if(!r.length)return{lo:-KT,hi:KT,stated:!1};let n=Math.max(...r.map(Math.abs))/ro;return{lo:-n,hi:n,stated:!0}}function uG(e,t,r){if(!(r>t))return t;let n=Math.max(2,Math.ceil(r-t)+1),o=(r-t)/(n-1),a=t,s=-1/0;for(let h=0;h<n;h++){let b=t+h*o,g=e(b);g>s&&(s=g,a=b)}let i=Math.max(t,a-o),c=Math.min(r,a+o),l=.6180339887498949,u=c-l*(c-i),m=i+l*(c-i),p=e(u),d=e(m);for(let h=0;h<12;h++)p>d?(c=m,m=u,d=p,u=c-l*(c-i),p=e(u)):(i=u,u=m,p=d,m=i+l*(c-i),d=e(m));let f=p>=d?{g:u,v:p}:{g:m,v:d};return f.v>s?f.g:a}var zT=250,YT=new WeakMap;function mG(e,t,r,n,o,a,s){let i=YT.get(e);i||YT.set(e,i=new Map);let c=`${t}|${n}|${o}|${s.lo}|${s.hi}`,l=i.get(c);l||i.set(c,l=new Map);let u=f=>{let h=l.get(f);if(h===void 0){let b=Math.max(50,f*zT);h=uG(g=>Qx(r,n,o,b,g).force,s.lo,s.hi),l.set(f,h)}return h},m=Math.max(0,a)/zT,p=Math.floor(m),d=m-p;return d<1e-9?u(p):u(p)*(1-d)+u(p+1)*d}function Ba(e,t){return t==="front"?e.tireModel:e.tireModelRear??e.tireModel}var dG=new WeakMap,pG=new WeakMap,fG=new WeakMap,Zx=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n};function lf(e,t){let r=Ba(e,t);return r?Zx(dG,r,()=>Tc(r))?null:"This tyre\u2019s side force does not change with camber, so it wants no camber.":"The car runs the built-in simple tyre, which has no camber term."}function Jx(e,t){let r=Ba(e,t);return r?Zx(fG,r,()=>Um(r).none)?"This tyre file has no drive or brake grip.":Zx(pG,r,()=>{let n=We(r),o=r.kind==="magic"?r.fnomin:r.nominalLoad,a=n.Fx(.1,o,0),s=n.Fx(.1,o,3*ro);return Number.isFinite(a)&&Number.isFinite(s)&&Math.abs(s-a)>1})?null:"This tyre\u2019s drive and brake grip does not change with camber.":"The car runs the built-in simple tyre, which has no camber term."}function $a(e,t){return e==="side"||e==="ackermann"?Math.abs(t.ayG)>=du?e==="ackermann"&&!(eR(t)<=qx)?`is a corner wider than ${qx} m`:null:"does not corner":(e==="drive"?t.axG:-t.axG)>=du?null:e==="drive"?"does not drive":"does not brake"}var hG=e=>e.axG>=du?"drive":e.axG<=-du?"brake":null;function eR(e){let t=e.speedKmh/3.6,r=Math.abs(e.ayG)*lG;return r>1e-9?t*t/r:1/0}var sf=(e,t)=>`${e==="front"?"F":"R"}${t}`,bG=e=>e==="L"?"R":"L",gG=(e,t,r)=>Math.min(r,Math.max(t,e));function tR({ev:e,params:t,input:r,state:n,pose:o}){let a=`${J(t,"grip_scale")}|${J(t,"stiffness_scale")}`,s=eR(n),i=r.wheelbase*(1-r.frontMassFrac)/1e3,c=r.wheelbase*r.frontMassFrac/1e3,l=r.wheelbase/1e3,u=A=>(A==="front"?r.trackFront:r.trackRear)/2e3,m=(A,C,F,T,M)=>{let k=Te(e,A),w=Ba(t,A),P=Math.max(0,o.loads[C]),L=o.camber[C],E=gG(L,M.lo,M.hi),_=Qx(k,F,T,P,E),D=P<WT,I=w&&!D?mG(w,a,k,F,T,P,M):E,N=D?_.force:Qx(k,F,T,P,I).force,O=.05;return{corner:C,Fz:P,lifted:D,camber:L,read:E,outside:E!==L,wants:I,atEdge:!D&&(I-M.lo<O||M.hi-I<O),peak:_.force,slip:_.at,best:N}},p=(A,C,F)=>{let T=C[0].best+C[1].best,M=C[0].peak+C[1].peak;return{kind:A,wheels:C,lossCamber:T>0?Math.max(0,1-M/T):NaN,range:F}},d=new Map,f=A=>{if(d.has(A))return d.get(A)??null;let C=null;if(!$a("side",n)){let F=cf(Ba(t,A));C=[m(A,sf(A,o.outer),"side",1,F),m(A,sf(A,bG(o.outer)),"side",-1,F)]}return d.set(A,C),C},h=new Map,b=new Map,g=new Map,y,x=()=>{if(y!==void 0)return y;let A=f("front");if(!A||A[0].lifted||A[1].lifted)return y=null;let[C,F]=A,T=Math.sqrt(Math.max(s*s-c*c,1e-6)),M=u("front"),k=(Math.atan(l/(T-M))-Math.atan(l/(T+M)))/ro,w=S(C.corner),P=v("front",!1,w-C.slip),L=F.slip-C.slip+R("front",!0,P)-R("front",!1,P);return y={outer:w,has:S(F.corner)-w,wants:L,geometric:k}},R=(A,C,F)=>{let T=A==="front"?i:-c,M=(C?1:-1)*u(A),k=F*ro;return Math.atan2(T+s*Math.sin(k),s*Math.cos(k)-M)/ro},v=(A,C,F)=>{let T=-60,M=60;for(let k=0;k<50;k++){let w=(T+M)/2;R(A,C,w)<F?T=w:M=w}return(T+M)/2},S=A=>(n.ayG<0?-1:1)*o.steer[A];return{side(A){if(h.has(A))return h.get(A)??null;let C=lf(t,A)?null:f(A),F=C?p("side",C,cf(Ba(t,A))):null;return h.set(A,F),F},long(A){if(b.has(A))return b.get(A)??null;let C=hG(n),F=null;if(C&&!Jx(t,A)){let T=cf(Ba(t,A));F=p(C,[m(A,sf(A,"L"),C,1,T),m(A,sf(A,"R"),C,1,T)],T)}return b.set(A,F),F},toeLoss(A){let C=g.get(A);if(C!==void 0)return C;let F=f(A),T=NaN;if(F&&F[0].peak+F[1].peak>0){let M=Te(e,A),[k,w]=F,P=[{g:k,dt:1,inner:!1,steer:S(k.corner)},{g:w,dt:-1,inner:!0,steer:S(w.corner)}],L=N=>P.reduce((O,V)=>{let H=V.steer-R(A,V.inner,N);return O+V.dt*M.Fy(V.dt*H*ro,V.g.Fz,V.g.read*ro)},0),E=P.map(N=>N.steer-N.g.slip-R(A,N.inner,0)),_=Math.min(...E)-2,D=Math.max(...E)+2,I=yG(L,_,D,.25);T=Math.max(0,1-I/(k.peak+w.peak))}return g.set(A,T),T},ackermann(){if($a("ackermann",n))return NaN;let A=x();return!A||!(A.geometric>.001)?NaN:100*(A.has-A.wants)/A.geometric},split:x}}function yG(e,t,r,n){let o=-1/0,a=t;for(let d=t;d<=r+1e-9;d+=n){let f=e(d);f>o&&(o=f,a=d)}let s=a-n,i=a+n,c=.6180339887498949,l=i-c*(i-s),u=s+c*(i-s),m=e(l),p=e(u);for(let d=0;d<14;d++)m>p?(i=u,u=l,p=m,l=i-c*(i-s),m=e(l)):(s=l,l=u,m=p,u=s+c*(i-s),p=e(u));return Math.max(o,m,p)}var xG=9.81,jT=Math.PI/180,Si={speed:20,ayG:1.2};function rR(e,t={}){let r=t.operating??Si,n=t.assemble,o,a,s,i=new Map,c=new Map,l=new Map,u=new Map,m=new Map,p=v=>({speed:v?.speed!==void 0&&Number.isFinite(v.speed)&&v.speed>0?v.speed:r.speed,ayG:v?.ayG!==void 0&&Number.isFinite(v.ayG)?v.ayG:r.ayG}),d=()=>{if(o!==void 0)return o;if(!n)return o=null;try{o=n(e)}catch{o=null}return o},f=()=>{if(a!==void 0)return a;try{a=pn(e.params)}catch{a=null}return a},h=v=>{let S=p(v),A=`${S.speed}|${S.ayG}`,C=i.get(A);if(C!==void 0)return C;let F=f();if(!F)return i.set(A,null),null;let T={cornerStiffness:M=>F.corneringStiffness(M),ayG:S.ayG,speed:S.speed,fyAxle:(M,k)=>2*F.Fy(M,k/2),tire:F};return i.set(A,T),T},b=()=>{if(s!==void 0)return s;let v=d(),S=f();if(!v||!S)return s=null;try{s=la(S,v.massTotal*xG*1.2)}catch{s=null}return s},g=v=>{let S=p(v).speed,A=`${S}`,C=c.get(A);if(C!==void 0)return C;let F=d(),T=f(),M=null;if(F&&T)try{M=N0(F,T,S,{steering:!1})}catch{M=null}return c.set(A,M),M},y=v=>{let S=`${v.speedKmh}|${v.ayG}|${v.axG}`,A=m.get(S);if(A!==void 0)return A;let C=null,F=d();try{let T=F?.kinFront,M=F?.kinRear;if(F&&T&&M){let k=jx(v,F.wheelbase),w=v.speedKmh/3.6,P=Ro(F,T,M,w)(v.ayG,v.axG,0,k),L={FL:P.FL.travel,FR:P.FR.travel},E=ma(F,k*jT,L),_=k?E.camber:null,D={},I={};for(let O of["FL","FR","RL","RR"]){let V=O[1]==="R"?P[O].camberRoad:0-P[O].camberRoad;D[O]=V+(_?.[O]??0),I[O]=E.steer[O]/jT+(O[1]==="R"?1:-1)*P[O].bumpToe}let N=Xe(F,v.ayG,v.axG,w,0,k,L,P.steeringJacking);C={corners:P,rollDeg:P.FL.camberRoad-P.FL.camber,steerDeg:k,camber:D,outer:GT(v),loads:N,steer:I}}}catch{C=null}return m.set(S,C),C},x=new Map;return{operating:r,dynAvailable:!!n,poseAt:y,tyreAt:v=>{let S=`${v.speedKmh}|${v.ayG}|${v.axG}`,A=x.get(S);if(A!==void 0)return A;let C=y(v),F=d(),T=f(),M=C&&F&&T?tR({ev:T,params:e.params,input:F,state:v,pose:C}):null;return x.set(S,M),M},operatingAt:p,dynInput:d,tyre:f,dynCtx:h,grip:b,ymd:g,ymdLimit:v=>{let S=`${p(v).speed}`,A=l.get(S);if(A!==void 0)return A;let C=g(v),F=C?ky(C):null;return l.set(S,F),F},reserves:(v,S)=>{let A=p(S),C=`${v}|${A.speed}|${A.ayG}`,F=u.get(C);if(F!==void 0)return F;let T=d(),M=h(S),k=null;if(T&&M)try{k=El(T,M,v,b()??void 0)}catch{k=null}return u.set(C,k),k}}}var UT=["widthLeft","widthRight","bank","mu"];function pu(e){let t=e.x.length,r=new Array(t).fill(0);for(let n=1;n<t;n++)r[n]=r[n-1]+Math.hypot(e.x[n]-e.x[n-1],e.y[n]-e.y[n-1]);return r}function nR(e){let t=pu(e),r=e.x.length;return r===0?0:e.closed===!1||r<2?t[r-1]:t[r-1]+Math.hypot(e.x[0]-e.x[r-1],e.y[0]-e.y[r-1])}function mf(e,t,r,n={}){let o=t.length,a=l=>{let u=n[l];return u&&u.length===o?u.slice():new Array(o).fill(r[l])},s={widthLeft:a("widthLeft"),widthRight:a("widthRight"),bank:a("bank"),mu:a("mu")};if(!e.length)return s;let i=[...e].sort((l,u)=>l.from-u.from),c=o?t[o-1]:0;for(let l of i){if(!(l.to>l.from))continue;let u=Math.max(0,l.ramp??0),m=l.to>=c-1e-9;for(let p of UT){let d=l[p];if(d===void 0)continue;let f=s[p],h=r[p];for(let b=0;b<o&&t[b]<l.from;b++)h=f[b];for(let b=0;b<o;b++){let g=t[b];if(g<l.from||g>=l.to&&!(m&&g>=c-1e-9))continue;let y=g-l.from;f[b]=u>0&&y<u?h+(d-h)*(y/u):d}}}return s}function df(e,t,r){if(!t.length)return e;let n=pu(e),o=n.length,a={widthLeft:uf(e.widthLeft,r.widthLeft),widthRight:uf(e.widthRight,r.widthRight),bank:uf(e.bank,r.bank),mu:uf(e.mu,r.mu)},s={};for(let c of UT){let l=e[c];Array.isArray(l)&&l.length===o&&(s[c]=l)}let i=mf(t,n,a,s);return{...e,...i}}function uf(e,t){return typeof e=="number"?e:t}var QT=1,XT=4,ff=Math.PI/180,oR=e=>e===null||!Number.isFinite(e)||e===0?0:1/e;function aR(e){return e.kind==="arc"?Math.abs(e.radius)*Math.abs(e.angle)*ff:e.length}function pf(e,t){return e.kind==="straight"?0:e.kind==="arc"?oR(e.radius):t}function qT(e){return e.kind==="straight"?0:e.kind==="arc"?oR(e.radius):oR(e.endRadius)}var fu=(e,t,r,n,o)=>e+t*o+(n>0?(r-t)*o*o/(2*n):0);function hu(e,t={}){let r=Math.max(.05,t.spacing??QT),n=t.closed!==!1,o=t.start??{x:0,y:0,heading:0},a=t.base??{widthLeft:1.5,widthRight:1.5,bank:0,mu:1},s=[],i=[],c=[],l=[],u=e.reduce((k,w)=>k+aR(w),0),m=Math.max(n?3:2,Math.round(u/r)),p=u>0?u/m:r,d=o.x,f=o.y,h=o.heading*ff,b=e.length?pf(e[0],0):0,g=0,y=p,x=(k,w,P)=>{s.push(k),i.push(w),c.push(P)};x(d,f,0);let R=(k,w,P,L,E)=>{let _=E-L;if(_<=0)return;if(Math.abs(w-k)<1e-12){let I=fu(h,k,k,P,L);if(Math.abs(k)<1e-12)d+=_*Math.cos(I),f+=_*Math.sin(I);else{let N=I+k*_;d+=(Math.sin(N)-Math.sin(I))/k,f+=-(Math.cos(N)-Math.cos(I))/k}return}let D=_/XT;for(let I=0;I<XT;I++){let N=L+I*D,O=fu(h,k,w,P,N),V=fu(h,k,w,P,N+D/2),H=fu(h,k,w,P,N+D);d+=D/6*(Math.cos(O)+4*Math.cos(V)+Math.cos(H)),f+=D/6*(Math.sin(O)+4*Math.sin(V)+Math.sin(H))}};for(let k of e){let w=aR(k),P=pf(k,b),L=qT(k);if(l.push({from:g,to:g+w,...k.widthLeft!==void 0?{widthLeft:k.widthLeft}:{},...k.widthRight!==void 0?{widthRight:k.widthRight}:{},...k.bank!==void 0?{bank:k.bank}:{},...k.mu!==void 0?{mu:k.mu}:{},...k.ramp!==void 0?{ramp:k.ramp}:{}}),w<=0){b=L;continue}let E=0;for(;y<=g+w+1e-9;){let _=Math.min(w,y-g);R(P,L,w,E,_),E=_,x(d,f,g+_),y+=p}R(P,L,w,E,w),h=fu(h,P,L,w,w),b=L,g+=w}let v=s.length>1?Math.hypot(s[0]-s[s.length-1],i[0]-i[i.length-1]):0,S=g;n&&s.length>1&&(s.pop(),i.pop(),c.pop());let A=e.length?pf(e[0],b):0,C={gap:v,headingError:RG((h-o.heading*ff)/ff),curvatureError:b-A},F=[];for(let k=0;k<e.length;k++){let w=qT(e[k]),P=k+1<e.length?e[k+1]:n?e[0]:null;if(!P)continue;let L=pf(P,w);F.push({index:k,before:w,after:L,jump:Math.abs(L-w)})}let T=mf(l,c,a);return{asset:{name:t.name??"Track",x:s,y:i,fit:"interpolate",...n?{}:{closed:!1},...T},sections:l,joints:F,closure:C,length:S}}function RG(e){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t}var vG={halfWidthM:1.5,spacingM:.5};function bu(e){switch(e.kind){case"skidpad":return`${e.radiusM.toFixed(2)} m constant-radius circle`;case"acceleration":return`${e.distanceM.toFixed(0)} m straight from rest`;case"slalom":return`${e.gates} gates at ${e.pitchM.toFixed(1)} m, \xB1${e.offsetM.toFixed(2)} m`;case"curves":{let t=e.segments.filter(r=>r.kind==="arc").length;return`${t} ${t===1?"curve":"curves"} over ${JT(e).toFixed(0)} m`}}}function JT(e){switch(e.kind){case"skidpad":return 2*Math.PI*e.radiusM;case"acceleration":return e.distanceM;case"slalom":return e.leadInM+Math.max(1,e.gates)*e.pitchM;case"curves":return e.segments.reduce((t,r)=>t+(r.kind==="arc"?Math.abs(r.angle)*Math.PI*Math.abs(r.radius)/180:r.length),0)}}var eP=e=>e.kind==="skidpad"||e.kind==="curves"&&e.closed===!0,tP=e=>e.kind==="acceleration",rP=1.5,nP=3;function kG(e,t){let r=e.offsetM,n=e.pitchM,o=Math.max(1,e.gates)*n,a=Math.max(0,e.leadInM),s=rP*n,i=h=>{let b=Math.min(1,Math.max(0,h));return b*b*b*(b*(b*6-15)+10)},c=h=>Math.min(i(h/s),i((o-h)/s)),l=r*(Math.PI/n)**2,u=l>0?Math.max(.05,Math.min(t.spacingM,1/l*(nP*Math.PI/180))):t.spacingM,m=[],p=[],d=Math.max(1,Math.round(a/u));for(let h=0;h<d;h++)m.push(-a+a*h/d),p.push(0);let f=Math.max(8,Math.round(o/u));for(let h=0;h<=f;h++){let b=o*h/f;m.push(b),p.push(r*c(b)*Math.sin(Math.PI*b/n))}return{name:bu(e),x:m,y:p,closed:!1,widthLeft:t.halfWidthM,widthRight:t.halfWidthM,fit:"interpolate"}}function MG(e){switch(e.kind){case"skidpad":return[{kind:"arc",radius:e.radiusM,angle:360}];case"acceleration":return[{kind:"straight",length:e.distanceM}];case"curves":return e.segments;case"slalom":return null}}function sR(e,t={}){let r={...vG,...t},n=tP(e),o=MG(e);if(!o){let u=kG(e,r);return{asset:u,peakCurvature:ZT(u),worstJoint:0,standingStart:n}}let a=eP(e),s=o.reduce((u,m)=>m.kind==="arc"?Math.min(u,Math.abs(m.radius)):u,1/0),i=Number.isFinite(s)?Math.max(.05,Math.min(r.spacingM,s*(nP*Math.PI/180))):r.spacingM,c=hu(o,{name:bu(e),spacing:i,closed:a,base:{widthLeft:r.halfWidthM,widthRight:r.halfWidthM,bank:0,mu:1}}),l=a?c.joints:c.joints.filter(u=>u.index<o.length-1);return{asset:c.asset,peakCurvature:ZT(c.asset),worstJoint:l.reduce((u,m)=>Math.max(u,m.jump),0),standingStart:n}}function ZT(e){try{return Math.max(...$t(e).curvature.map(Math.abs))}catch{return NaN}}var Ai={courses:[{id:"c1",course:{kind:"manoeuvre",spec:{kind:"skidpad",radiusM:8.375}}}],ggvMode:"twoTrack"};function iR(e){return e.course.kind==="project"?"the project\u2019s track":e.course.kind==="track"?e.course.name:bu(e.course.spec)}var bf=()=>({courses:Ai.courses.map(e=>({...e})),ggvMode:Ai.ggvMode}),oP=new WeakMap,hf=new Map;function aP(e,t,r){if(e.kind==="project"||e.kind==="track"){let i=(e.kind==="project"?t.projectTrack?.():t.libraryTrack?.(e.trackId))??null;return i?{asset:i.asset,standingStart:i.standingStart,numerics:i.numerics}:null}let n=JSON.stringify(e.spec),o=hf.get(n);if(o)return{...o,numerics:r};let a=sR(e.spec),s={asset:a.asset,standingStart:a.standingStart};return hf.size>64&&hf.clear(),hf.set(n,s),{...s,numerics:r}}function cR(e,t,r={}){let n=r.lap??Ai,o=r.simParams,a=r.numerics??{},s=n.courses.length?n.courses:Ai.courses,i,c,l,u=new Map,m=new Map,p=new Map,d=new Map,f=R=>(R?.courseId?s.find(v=>v.id===R.courseId):void 0)??s[0],h=()=>{if(i!==void 0)return i;if(!o)return i=null;try{i={...o(e),ggvMode:n.ggvMode}}catch{i=null}return i},b=R=>{let v=f(R);if(!v)return null;let S=m.get(v.id);if(S!==void 0)return S;let A=aP(v.course,r,a),C=null;if(A)try{let F=JSON.stringify(A.numerics),T=oP.get(A.asset);T||(T=new Map,oP.set(A.asset,T));let M=T.get(F);M||(M=$t(A.asset,A.numerics),T.set(F,M)),C={id:v.id,track:M,standingStart:A.standingStart,numerics:A.numerics,name:A.asset.name}}catch{C=null}return m.set(v.id,C),C},g=()=>{if(c!==void 0)return c;let R=h();if(!R)return c=null;try{l=mr(R),c=bn(l,!1,n.ggvMode)}catch{c=null}return c},y=R=>{let v=b(R);if(!v)return null;let S=p.get(v.id);if(S!==void 0)return S;let A=g(),C=null;if(A)try{let F=l?Aa(l,A,[v.track],v.numerics,n.ggvMode,u):void 0,T=l?Fo(l,A.rows):void 0;C=tr(A,v.track,v.numerics,{standingStart:v.standingStart,...F?{load:F}:{},...T?{shifts:T}:{}})}catch{C=null}return p.set(v.id,C),C};return{lapSettings:n,get lapAvailable(){return!!o&&s.some(R=>!!aP(R.course,r,a))},lapParams:h,courses:()=>s,course:b,ggv:g,lap:y,lapReserve:R=>{let v=b(R);if(!v)return null;let S=d.get(v.id);if(S!==void 0)return S;let A=y(R),C=t.dynInput(),F=t.tyre(),T=null;if(A&&C&&F)try{let M=h();T=yp(C,F,Fp({...A,ds:v.track.ds,rows:g()?.rows,gradient:v.track.gradient,bank:v.track.bank,mu:v.track.mu}),M?{driven:o0(M)}:{})}catch{T=null}return d.set(v.id,T),T}}}var sP=180/Math.PI,lR={rise:0,sinPitch:0,sinRoll:0};function iP(e){let t=e.kc;return t?cP(e.vehicle,r=>t.ground0[r]):lR}function cP(e,t){let r=e.config,n=bo(r),o=0,a=0,s=0,i=0,c=0,l=0,u=0,m=0,p=0;for(let g of en){let y=Ue(g,r),x=y.axleX-n,R=y.sideSign*cr(e,y.isFront)/2,v=t(g);if(!Number.isFinite(v))return lR;o++,a+=x,s+=R,i+=v,c+=x*x,l+=R*R,u+=x*R,m+=x*v,p+=R*v}let d=o*(c*l-u*u)-a*(a*l-u*s)+s*(a*u-c*s);if(!(Math.abs(d)>1e-9))return{rise:i/o,sinPitch:0,sinRoll:0};let f=(i*(c*l-u*u)-a*(m*l-u*p)+s*(m*u-c*p))/d,h=(o*(m*l-u*p)-i*(a*l-u*s)+s*(a*p-m*s))/d,b=(o*(c*p-m*u)-a*(a*p-m*s)+i*(a*u-c*s))/d;return{rise:f,sinPitch:h,sinRoll:-b}}function gu(e,t){let r=e.kc,n=cP(e.vehicle,o=>(r?r.ground0[o]:0)+t[o]);return ee([-n.sinPitch,n.sinRoll,1])}function uR(e,t,r,n){let o=ee(Dn(e,Ue(t,r)));return-Math.asin(Math.max(-1,Math.min(1,Z(o,n))))*sP}function gf(e,t,r,n,o){let a=ee(Dn(n,Ue(t,r))),s=ee([1-a[0]*a[0],-a[0]*a[1],-a[0]*a[2]]),i=me(a,s),c=d=>[Z(d,s),Z(d,i),Z(d,a)],l=d=>ne(ne(Q(s,d[0]),Q(i,d[1])),Q(a,d[2])),u=e.points,m=c(u.spinAxis),p=ac({uprightUpper:c(u.uprightUpper),uprightLower:c(u.uprightLower),wheelCenter:c(u.wheelCenter),spinAxis:m,tieOuter:c(u.tieOuter),loadedRadius:o.loadedRadius,patchShift:o.patchShift&&SG(o.patchShift,e.metrics.toe/sP,Math.atan2(m[0],m[1]))});return{caster:p.caster,kpi:p.kpi,scrubRadius:p.scrubRadius,mechanicalTrail:p.mechanicalTrail,scrubAtWheel:p.scrubAtWheel,trailAtWheel:p.trailAtWheel,kingpinOffset:p.kingpinOffset,casterOffset:p.casterOffset,kingpinGround:l(p.kingpinGround),contactPatch:l(p.contactPatch),elbow:l([p.contactPatch[0],p.kingpinGround[1],p.kingpinGround[2]]),kingpinAtHub:l(p.kingpinAtHub)}}function SG(e,t,r){if(r===t)return e;let n=e.x*Math.cos(t)-e.y*Math.sin(t),o=e.x*Math.sin(t)+e.y*Math.cos(t);return{x:n*Math.cos(r)+o*Math.sin(r),y:o*Math.cos(r)-n*Math.sin(r)}}function yf(e,t){let r=iP(t);if(r===lR)return e;let n=o=>Math.max(-1,Math.min(1,o));return{...e,heave:e.heave-r.rise,pitch:Math.asin(n(Math.sin(e.pitch)-r.sinPitch)),roll:Math.asin(n(Math.sin(e.roll)-r.sinRoll))}}function Yr(e,t,r){let n=yf({heave:0,pitch:0,roll:0,steer:0},r);return e-yb(n,[t,0,0],bo(r.vehicle.config))}var AG=180/Math.PI;function mR(e,t){return!e.valid||!e.ic?!1:Math.hypot(e.ic[0]-e.cp[0],e.ic[1]-e.cp[1])<=t}function Dt(e,t,r){let n=Ue(t,e.vehicle.config),o=Zt(e,r),a=Bd(e,t,o[t]),s=a.at("uprightUpper"),i=a.at("uprightLower"),c=a.at("contactPatch"),l=a.at("wheelCenter"),u=w=>{let P=a.velocity(w);return[P[0],P[2]]},m=u(c),p=u(l),d=[c[0],c[2]],f=[l[0],l[2]];if(!a.solved)return{ic:null,line:null,cp:d,wc:f,road:[1,0],swingArmAngleDeg:NaN,tanTheta:NaN,tanThetaHub:NaN,valid:!1,unsolved:!0,sinAngle:0};let h=gu(e,{FL:o.FL.ground,FR:o.FR.ground,RL:o.RL.ground,RR:o.RR.ground}),b=Math.hypot(h[0],h[2]),g=[h[0]/b,h[2]/b],y=[g[1],-g[0]],x=w=>{let P=w[0]*g[0]+w[1]*g[1];return Math.abs(P)>1e-9?-(w[0]*y[0]+w[1]*y[1])/P:0},R=a.omega[1],v=Math.hypot(m[0],m[1]),S=Math.abs(R)*1e9>v?[d[0]+m[1]/R,d[1]-m[0]/R]:null,C=S?(w=>{let P=[s[0]-w[0],s[2]-w[1]],L=[i[0]-w[0],i[2]-w[1]];return Math.abs(P[0]*L[1]-P[1]*L[0])/(Math.hypot(...P)*Math.hypot(...L))})(S):0;if(!(Math.abs(m[0]*g[0]+m[1]*g[1])>1e-9))return{ic:S,line:null,cp:d,wc:f,road:y,swingArmAngleDeg:0,tanTheta:0,tanThetaHub:0,valid:!1,sinAngle:C};let F=[m[1]/v,-m[0]/v],T=S?[S[0]-d[0],S[1]-d[1]]:[n.isFront?-1:1,0],M=F[0]*T[0]+F[1]*T[1]<0?[-F[0],-F[1]]:F,k=x(m);return{ic:S,line:M,cp:d,wc:f,road:y,swingArmAngleDeg:Math.atan(k)*AG,tanTheta:k,tanThetaHub:x(p),valid:!0,sinAngle:C}}function lP(e,t,r,n){let o=r/Math.max(1e-6,n.cgHeight),a=t==="front",s=a?n.drive.front:1-n.drive.front,i=a?n.brakeBalanceFront:1-n.brakeBalanceFront,c=(a?n.drive.inboard.front:n.drive.inboard.rear)?e.tanThetaHub:e.tanTheta,l=(a?n.brakeInboard?.front:n.brakeInboard?.rear)?e.tanThetaHub:e.tanTheta,u=a?-1:1;return{brake:u*100*l*o*i,drive:u*100*c*o*s}}function xf(e){let t=Math.min(1,Math.max(0,e.frontMassFrac)),r=(1-t)*e.wheelbase,n=t*e.wheelbase;return{x:e.frontAxleX-r,z:e.cgHeight,lf:r,lr:n}}function uP(e,t,r,n,o){let a=o(e.front)&&o(e.rear),s=n>1e-9?(r-t.x)/n:0,i=e.front.height+s*(e.rear.height-e.front.height),c=e.front.lateral+s*(e.rear.lateral-e.front.lateral);return{axisHeightAtCg:i,axisLateralAtCg:c,arm:t.z-i,valid:a}}function mP(e,t,r){return r>1e-9?Math.atan2(t-e,r)*180/Math.PI:Number.NaN}function dP(e,t,r){let{left:n,right:o}=e,a=(n.height+o.height)/2,s=(n.x+o.x)/2;return{axisHeight:a,axisX:s,heightAboveGround:(n.heightAboveGround+o.heightAboveGround)/2,ahead:s-t.x,arm:t.z-a,sinAngle:Math.min(n.sinAngle,o.sinAngle),valid:r(n)&&r(o)}}function dR(e,t){return e.valid?W0([e.x,e.height],e.front.cp,e.rear.cp,e.sinAngle,t):!1}function no(e,t){let r={x:0,height:0,heightAboveGround:0,stationAlongGround:0,valid:!1,sinAngle:0,front:e,rear:t};if(!e.valid||!t.valid||!e.line||!t.line)return r;let n=e.ic?[e.ic[0]-e.cp[0],e.ic[1]-e.cp[1]]:e.line,o=t.ic?[t.ic[0]-t.cp[0],t.ic[1]-t.cp[1]]:t.line,a=Math.hypot(n[0],n[1]),s=Math.hypot(o[0],o[1]),i=a>0&&s>0?Math.abs(n[0]*o[1]-n[1]*o[0])/(a*s):0,c=$d(e.cp,n,t.cp,o);if(!c)return{...r,sinAngle:i};let l=e.cp[0]-t.cp[0],u=e.cp[1]-t.cp[1],m=Math.hypot(l,u)||1,p=l/m,d=u/m,f=(e.cp[0]+t.cp[0])/2,h=(e.cp[1]+t.cp[1])/2;return{x:c[0],height:c[1],heightAboveGround:(c[0]-t.cp[0])*-d+(c[1]-t.cp[1])*p,stationAlongGround:(c[0]-f)*p+(c[1]-h)*d,valid:!0,sinAngle:i,front:e,rear:t}}var FG=180/Math.PI,CG=Math.PI/180,pR=.5,Rf=2,fR=.25;function gP(e,t,r,n,o){let a=t.frontMassFrac;if(a===void 0||!Number.isFinite(a))return;let s=e.vehicle.config,i=s.wheelbase,c=xf({wheelbase:i,frontAxleX:s.frontAxleX,frontMassFrac:a,cgHeight:t.cgHeight}),l=i>1e-9?(s.frontAxleX-c.x)/i:0,u=(d,f)=>d+l*(f-d),m={left:no(...o.left),right:no(...o.right)},p={...c,z:Yr(t.cgHeight,c.x,e)};return{roll:{height:u(r.rollCentreHeight,n.rollCentreHeight),arm:t.cgHeight-u(r.rollCentreHeightChassis,n.rollCentreHeightChassis),slope:mP(r.rollCentreHeight,n.rollCentreHeight,i),usable:r.rollCentreHeightUsable&&n.rollCentreHeightUsable},pitch:dP(m,p,d=>dR(d,i))}}var TG=e=>e.frontMassFrac!==void 0&&Number.isFinite(e.frontMassFrac);function PG(e,t,r){return{FL:Dt(e,"FL",t),FR:Dt(e,"FR",t),RL:Dt(e,"RL",r),RR:Dt(e,"RR",r)}}var LG={heave:0,pitch:0,roll:0,steer:0},DG={FL:"FR",FR:"FL",RL:"RR",RR:"RL"},vf=e=>e.ok?e.state:{...e.nearest,converged:!1};function hR(e,t,r){return t.state?t.solved===!1?{...t.state,converged:!1}:t.state:vf(Ce(e,t.travel,t.steer,void 0,r))}var pP=new WeakMap;function fP(e,t){let r=e.ctx[t],n=Je(e.vehicle,t).config.loadedRadius,o=Sr(n,e.kc,t),a=pP.get(r);a||(a=new Map,pP.set(r,a));let s=a.get(o);if(!s){let i=go(t,e.vehicle.config,LG,e.vehicle);s=vf(Ce(r,i.travel,i.steer,void 0,o===n?void 0:{loadedRadius:o})),a.set(o,s)}return s}var vn=(e,t)=>!e||!e.lo.converged||!e.hi.converged?NaN:(t(e.hi)-t(e.lo))/(2*e.step),hP=(e,t,r)=>{if(!e||!e.lo.converged||!e.hi.converged)return NaN;let n=r(e.hi)-r(e.lo);return Math.abs(n)<1e-9?NaN:(t(e.hi)-t(e.lo))/n};function yP(e,t,r,n,o,a){let s=e.vehicle.config,i=vs(r),c=Je(e.vehicle,r),l=Ue(r,s),u=e.ctx[r],m=Zt(e,t),p=m[r],d={travel:p.travel,steer:p.steer},f=p.rigid?void 0:{loadedRadius:p.loadedRadius},h=hR(u,p,f),b=fP(e,r),g={lo:vf(Ce(u,d.travel-pR,d.steer,void 0,f)),hi:vf(Ce(u,d.travel+pR,d.steer,void 0,f)),step:pR},y=l.isFront?{lo:at(u,h.beta,d.steer-Rf,void 0,f),hi:at(u,h.beta,d.steer+Rf,void 0,f),step:Rf}:null,x=z=>{let Y=Zt(e,{...t,roll:t.roll+z*CG})[r];return hR(u,Y,Y.rigid?void 0:{loadedRadius:Y.loadedRadius})},R={lo:x(-fR),hi:x(fR),step:fR},v=IG(e,t,r,l.isFront,m,y),S=st(h.points.contactPatch,l),A=st(b.points.contactPatch,l),C=Math.abs(S[1])-Math.abs(A[1]),F=DG[r],T=m[F],M=hR(e.ctx[F],T,T.rigid?void 0:{loadedRadius:T.loadedRadius}),k=M.converged?C+Math.abs(M.points.contactPatch[1])-Math.abs(fP(e,F).points.contactPatch[1]):NaN,w=M.converged?Math.abs(S[1])+Math.abs(M.points.contactPatch[1]):NaN,P=o??Hr(e,t,i),L=Gd(P,Qt(c)),E=L?null:yw(P),_=ri(P),D=l.sideSign>0?P.icRight:P.icLeft,I=D?Math.hypot(D[0]-S[1],D[1]-S[2]):1/0,N=a??Dt(e,r,t),O=N.ic?Math.hypot(N.ic[0]-N.cp[0],N.ic[1]-N.cp[1]):1/0,V=lP(N,i,s.wheelbase,n),H=-vn(g,z=>z.points.damperLength),U=c.config.springRate,G=vn(R,z=>z.metrics.camber),B=gu(e,{FL:m.FL.ground,FR:m.FR.ground,RL:m.RL.ground,RR:m.RR.ground}),q=e.kc?.loadCase,re=z=>q?gf(z,r,s,B,{loadedRadius:p.loadedRadius,patchShift:q.patchShift[r]}):z.metrics,W=re(h);return{id:r,converged:h.converged,travel:h.travel,camber:h.metrics.camber,camberRoad:uR(h.points.spinAxis,r,s,B),toe:h.metrics.toe,caster:W.caster,kpi:W.kpi,scrubRadius:W.scrubRadius,mechanicalTrail:W.mechanicalTrail,scrubAtWheel:W.scrubAtWheel,trailAtWheel:W.trailAtWheel,kingpinOffset:W.kingpinOffset,casterOffset:W.casterOffset,steeringArm:h.metrics.steeringArm,camberGain:vn(g,z=>z.metrics.camber),bumpSteer:vn(g,z=>z.metrics.toe),trackScrubRate:vn(g,z=>Math.abs(st(z.points.contactPatch,l)[1])),casterGain:vn(g,z=>re(z).caster),kpiGain:vn(g,z=>re(z).kpi),scrubGain:vn(g,z=>re(z).scrubRadius),trailGain:vn(g,z=>re(z).mechanicalTrail),...l.isFront?{camberPerSteer:hP(y,z=>z.metrics.camber,z=>z.metrics.toe),steerJacking:-hP(y,z=>z.points.contactPatch[2],z=>z.metrics.toe),...v!==void 0?{steerLoad:v}:{}}:{},rollCamber:G,camberRecovery:-100*l.sideSign*G,rollSteer:l.sideSign*vn(R,z=>z.metrics.toe),halfTrackChange:C,trackChange:k,track:w,patchX:S[0],longitudinal:S[0]-A[0],rollCentreHeight:E?E.heightAboveGround:P.heightAboveGround,rollCentreHeightChassis:(E?E.height:P.height)-Yr(0,l.axleX,e),rollCentreLateral:P.lateralAlongGround,rollCentreValid:P.valid,rollCentreUsable:L,rollCentreHeightUsable:L||E!==null,transferHeight:_?_.heightAboveGround:NaN,transferHeightChassis:_?_.height-Yr(0,l.axleX,e):NaN,rollCentreSinAngle:P.sinAngle,fvsaLength:I,svsaLength:O,swingArmAngle:N.swingArmAngleDeg,svsaUsable:mR(N,s.wheelbase),svsaSinAngle:N.sinAngle,...i==="front"?{antiDive:V.brake,antiLift:V.drive}:{antiSquat:V.drive,antiLift:V.brake},decoupled:c.config.actuation==="decoupled",mcpherson:c.config.layout==="mcpherson",springRate:U,motionRatio:H,wheelRate:U*H*H,damperLength:h.points.damperLength,damperTravel:b.points.damperLength-h.points.damperLength,...EG(c,b.points.damperLength,h.points.damperLength,e.kc?.curve[r].spring?.law),rockerAngle:c.config.actuation==="direct"?0:(h.points.rockerAngle-b.points.rockerAngle)*FG,groundDisplacement:p.rigid?h.travel:p.ground,tyreDeflection:p.tyreDeflection,wheelLoad:p.load,loadedRadiusAt:p.loadedRadius,rideRate:p.rideRate,wheelRateAtLoad:p.wheelRateAtLoad,lifted:p.lifted,clearance:p.clearance??0,tyreRigid:p.rigid}}function EG(e,t,r,n){if(e.config.actuation==="decoupled")return{};let o=n?{droop:n.droopStated?n.droop:null,bump:n.bump}:Ms(t,e.config.coilover),a=t-r;return{...o.droop!==null?{damperToExtended:a-o.droop}:{},...o.bump!==null?{damperToClosed:o.bump-a}:{}}}function IG(e,t,r,n,o,a){if(!a||!n)return;let s=Mm(e,t,"front"),i=e.kc;if(!s||!i)return;let c=["FL","FR"],l=[0,0],u=[0,0],m={lo:[],hi:[]},p=0;for(let h=0;h<2;h++){let b=c[h],g=o[b],y=e.ctx[b],x=g.rigid?void 0:{loadedRadius:g.loadedRadius},S=(b==="FR"?1:-1)*(r==="FR"?1:-1)*Rf,A=g.state?{q:[...g.state.pose.t,...g.state.pose.omega],phi:g.state.points.rockerAngle}:void 0,C=zt(Ce(y,g.travel,g.steer-S,A,x)),F=zt(Ce(y,g.travel,g.steer+S,A,x));if(!C||!F)return NaN;l[h]=F.points.contactPatch[2]-C.points.contactPatch[2],u[h]=En(i.curve[b],g.travel,F.points.damperLength)-En(i.curve[b],g.travel,C.points.damperLength),m.lo.push(C),m.hi.push(F),b===r&&(p=F.metrics.toe-C.metrics.toe)}let d=i.elements?.front;if(d){let h=[o.FL.travel,o.FR.travel],b=hc(d,h,[m.hi[0],m.hi[1]]),g=hc(d,h,[m.lo[0],m.lo[1]]);u[0]+=b[0]-g[0],u[1]+=b[1]-g[1]}return Math.abs(p)>1e-9?s([0,0],l,u)[r==="FL"?0:1]/p:NaN}function yu(e,t,r,n,o,a){return yP(e,t,r==="front"?"FL":"RL",n,o,a)}function bR(e,t,r){let n=Math.min(Math.abs(e),Math.abs(t));return r>0?Math.atan2(n,r/2)*180/Math.PI:0}function gR(e,t,r,n){let o=TG(r)?PG(e,t,t):null,a=yu(e,t,"front",r,n?.front,o?.FL),s=yu(e,t,"rear",r,n?.rear,o?.RL),i=o?gP(e,r,a,s,{left:[o.FL,o.RL],right:[o.FR,o.RR]}):void 0;return{front:a,rear:s,wheelbaseChange:a.longitudinal-s.longitudinal,wheelbase:a.patchX-s.patchX,...i?{axes:i}:{}}}function kf(e,t,r){let n=e.config.actuation==="decoupled";return{decoupled:n,heave:n&&t?.design.kind==="coil"&&t.linkage&&Yo(t.linkage).kind!=="chassis"?t:void 0,roll:n&&r?.design.kind==="coil"&&r.linkage&&Br(e,r.linkage,"coil")?r:void 0}}var xP=16,_G=50,NG=10,OG=4,VG=["upperArm","lowerArm","tieRod","rod","dropLink"],RP=["ballJoint","rodEnd"],nr=e=>typeof e=="number"&&Number.isFinite(e)&&e>0;function xR(e,t){let r=e?.rim;if(r&&nr(r.diameter)&&nr(r.width)&&Number.isFinite(r.offset)&&Number.isFinite(r.wall)&&r.wall>=0)return{...r,from:"typed"};let n=uS(t);return n?{...n,offset:null,wall:OG,from:"tyre"}:null}function yR(e,t){let r=e?.body;if(!r||!nr(r.bodyDiameter))return null;let n=nr(r.shaftDiameter)?r.shaftDiameter:r.bodyDiameter,o=nr(r.stroke)?Math.max(0,r.extended-r.stroke-t):1/0;return{bodyRadius:r.bodyDiameter/2,shaftRadius:n/2,bodyLength:o}}function BG(e){return e&&e.location==="outboard"&&e.packaging?{...e.packaging,effRadius:e.effRadiusMm}:null}function $G(e){if(!e?.linkage||e.design.kind==="none")return null;let t=e.design,r=Math.max(0,H0(t)??0),n=t.kind==="ubar"||t.kind==="blade"||t.kind==="torsionTube"?t.section.od/2:0,o=t.kind==="ubar"?(t.armSection?.od??t.section.od)/2:t.kind==="blade"?Math.max(t.blade.width,t.blade.thickness)/2:n;return{axle:e,armLength:r,barRadius:n,armRadius:o}}function GG(e,t){if(!nr(t)||!e.config||!e.front)return null;let r=e,n=Je(r,"FL"),o=Je(r,"FR");if(n.config.steerMode!=="rack"||o.config.steerMode!=="rack")return null;let a=st(n.hardpoints.tieInner,Ue("FL",r.config)),s=st(o.hardpoints.tieInner,Ue("FR",r.config)),i=Math.hypot(s[0]-a[0],s[1]-a[1],s[2]-a[2]),c=Ot(n.config);if(!(i>2*c))return null;let l=c/i,u=(m,p)=>[m[0]+(p[0]-m[0])*l,m[1]+(p[1]-m[1])*l,m[2]+(p[2]-m[2])*l];return{a:u(a,s),b:u(s,a),radius:t/2}}function KG(e,t,r){if(!r||!e.config||!r.inboard.every(Number.isFinite)||!nr(r.diameter)||!nr(r.jointDiameter)||!Number.isFinite(r.outboard))return null;let[n,o]=t==="front"?["FL","FR"]:["RL","RR"];return{inboard:{left:st(r.inboard,Ue(n,e.config)),right:st(r.inboard,Ue(o,e.config))},outboard:r.outboard,radius:r.diameter/2,reach:r.jointDiameter/2,limits:{...nr(r.innerAngle)?{innerAngle:r.innerAngle}:{},...nr(r.outerAngle)?{outerAngle:r.outerAngle}:{},...nr(r.plunge)?{plunge:r.plunge}:{}}}}var RR=e=>typeof e=="number"&&Number.isFinite(e)&&e>0&&e<90;function vP(e,t,r){let n=Object.fromEntries(VG.map(i=>[i,(nr(e?.tubes?.[i])?e.tubes[i]:xP)/2])),o=Object.fromEntries(RP.map(i=>[i,(nr(e?.housings?.[i])?e.housings[i]:_G)/2])),a=yR(t.damper,o.rodEnd),s=Object.fromEntries(RP.filter(i=>RR(e?.jointLimits?.[i])).map(i=>[i,e.jointLimits[i]]));return{tube:n,strut:a?a.bodyRadius:xP/2,housing:o,...Object.keys(s).length?{jointLimit:s}:{},uprightWall:typeof e?.uprightWall=="number"&&Number.isFinite(e.uprightWall)&&e.uprightWall>=0?e.uprightWall:NG,rim:xR(e,t.tyre),...nr(e?.tyreGrowth)?{tyreGrowth:e.tyreGrowth}:{},brake:BG(t.brake),damper:a,...HG(t,o.rodEnd,r)}}function HG(e,t,r){let n=!!e.heave?.linkage&&e.heave.design.kind!=="none",o=!!e.arb?.linkage&&e.arb.design.kind==="coil"&&(!r||!!kf(r,void 0,e.arb).roll),a=n?yR(e.heaveDamper,t):null,s=o?yR(e.rollDamper,t):null,i=[...n&&!a?["heave"]:[],...o&&!s?["roll"]:[]];return{arb:$G(r&&mn(r,e.arb,e.rollBar)||e.arb),heave:a&&e.heave?{kind:"heave",axle:e.heave,damper:a}:null,roll:s&&e.arb?{kind:"roll",axle:e.arb,damper:s}:null,...i.length?{unsized:i}:{}}}function kP(e){let t=(r,n)=>r?n?"shafts":"hubs":"undriven";return{front:t(e.front>0,e.inboard.front),rear:t(e.front<1,e.inboard.rear)}}function zG(e,t={}){let r={heaveDamper:t.unitDampers?.heave??t.dampers?.front,rollDamper:t.unitDampers?.roll??t.dampers?.front},n=vP(e.parts?.front,{tyre:t.tyres?.front,brake:t.brakes?.front,damper:t.dampers?.front,arb:t.arbs?.front,rollBar:t.rollBars?.front,heave:t.heaves?.front,...r},e.front),o=vP(e.parts?.rear,{tyre:t.tyres?.rear??t.tyres?.front,brake:t.brakes?.rear,damper:t.dampers?.rear??t.dampers?.front,arb:t.arbs?.rear,rollBar:t.rollBars?.rear,heave:t.heaves?.rear,...r},e.rear),a=(s,i)=>{let c=e.parts?.[s]?.driveshaft,l=t.drive?.[s]??"shafts",u=c&&l==="shafts"?KG(e,s,c):null;return{...i,driveshaft:u,shaftIdle:c&&l!=="shafts"?l:null}};return{front:{...a("front",n),rackHousing:GG(e,e.parts?.front?.rackHousing)},rear:a("rear",o)}}function MP(e,t,r={}){return{...e,axles:zG(t,r)}}var Ga=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],oo=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],xu=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Wr=e=>{let t=Math.hypot(e[0],e[1],e[2]);return t>0?[e[0]/t,e[1]/t,e[2]/t]:[NaN,NaN,NaN]},FP=180/Math.PI,YG=[[1,0,0],[0,1,0],[0,0,1]],SP=(e,t)=>[e[0][0]*t[0]+e[1][0]*t[1]+e[2][0]*t[2],e[0][1]*t[0]+e[1][1]*t[1]+e[2][1]*t[2],e[0][2]*t[0]+e[1][2]*t[1]+e[2][2]*t[2]],WG=(e,t)=>[oo(e[0],t),oo(e[1],t),oo(e[2],t)];function AP(e,t,r){let n=Wr(Ga(t,e)),o=Wr(xu(n,Ga(r,e)));return[n,xu(o,n),o]}function jG(e,t){let r=n=>[t[0][0]*e[0][n]+t[1][0]*e[1][n]+t[2][0]*e[2][n],t[0][1]*e[0][n]+t[1][1]*e[1][n]+t[2][1]*e[2][n],t[0][2]*e[0][n]+t[1][2]*e[1][n]+t[2][2]*e[2][n]];return[r(0),r(1),r(2)]}function vR(e,t,r,n){let o=Wr(Ga(t,e)),a=b=>{let g=Ga(b,e),y=oo(g,o);return[g[0]-y*o[0],g[1]-y*o[1],g[2]-y*o[2]]},s=Wr(a(r)),i=Wr(a(n)),c=oo(xu(s,i),o),u=oo(s,i),m=c,p=1-u,[d,f,h]=o;return[[p*d*d+u,p*d*f+m*h,p*d*h-m*f],[p*d*f-m*h,p*f*f+u,p*f*h+m*d],[p*d*h+m*f,p*f*h-m*d,p*h*h+u]]}var UG=(e,t)=>Math.acos(Math.max(-1,Math.min(1,oo(Wr(e),Wr(t)))))*FP;function XG(e,t){return{upright:jG(AP(e.uprightLower,e.tieOuter,e.wheelCenter),AP(t.uprightLower,t.tieOuter,t.wheelCenter)),uca:t.mcpherson?null:vR(t.ucaFront,t.ucaRear,e.uprightUpper,t.uprightUpper),lca:vR(t.lcaFront,t.lcaRear,e.uprightLower,t.uprightLower),rocker:t.direct?null:vR(t.rockerPivotA,t.rockerPivotB,e.rockerToPushrod,t.rockerToPushrod)}}function qG(e){let t=Wr(e[0]),r=Math.abs(t[0])<.9?[1,0,0]:[0,1,0],n=Wr(xu(t,r)),o=xu(t,n),a=e.map(h=>{let b=Wr(h);return[oo(b,n),oo(b,o)]}),s=h=>{let b=Math.cos(h),g=Math.sin(h),y=0,x=0;for(let R=0;R<a.length;R++){let v=Math.abs(a[R][0]*b+a[R][1]*g);v>y&&([y,x]=[v,R])}return{v:y,at:x}},i=Math.PI/180,c=0,l=1/0;for(let h=0;h<180;h++){let b=s(h*i).v;b<l&&([c,l]=[h*i,b])}let u=c-i,m=c+i,p=(Math.sqrt(5)-1)/2;for(let h=0;h<30;h++){let b=m-p*(m-u),g=u+p*(m-u);s(b).v<s(g).v?m=g:u=b}let d=s((u+m)/2),f=d.v<l?d:s(c);return{angle:Math.asin(Math.min(1,Math.min(l,d.v)))*FP,at:f.at}}function wP(e){let t=null;for(let r of e)Number.isFinite(r.angle)&&(!t||r.angle>t.angle)&&(t={angle:r.angle,joint:r.joint});return t}var QG={upright:"upright",lowerArm:"lca",upperArm:"uca"};function ZG(e,t,r,n){let o=t.map(u=>XG(e,u)),a=Wr(Ga(e.uprightUpper,e.uprightLower)),s=(u,m,p)=>{let d=0,f=-1;for(let h=0;h<o.length;h++){let b=o[h],g=b[u]?UG(SP(b.upright,a),SP(b[u],a)):0;g>d&&([d,f]=[g,h])}return{joint:m,group:"ballJoint",angle:d,at:f,ends:p}},i=[s("lca","lower ball joint",["uprightLower","uprightUpper"])];e.mcpherson||i.push(s("uca","upper ball joint",["uprightUpper","uprightLower"]));let c=(u,m,p)=>{let d=[Ga(e[m],e[u])];for(let f=0;f<t.length;f++){let h=p(o[f]);if(!h)return null;d.push(WG(h,Ga(t[f][m],t[f][u])))}return d},l=[["tie rod, inner end",c("tieInner","tieOuter",()=>YG),["tieInner","tieOuter"]],["tie rod, outer end",c("tieInner","tieOuter",u=>u.upright),["tieOuter","tieInner"]]];e.direct||l.push([`${n}, rocker end`,c("rockerToPushrod","pushrodOuter",u=>u.rocker),["rockerToPushrod","pushrodOuter"]],[`${n}, outer end`,c("rockerToPushrod","pushrodOuter",u=>u[QG[r]]),["pushrodOuter","rockerToPushrod"]]);for(let[u,m,p]of l){if(!m)continue;let d=qG(m);i.push({joint:u,group:"rodEnd",angle:d.angle,at:d.angle>0?d.at-1:-1,ends:p})}return i}function Mf(e,t,r,n){let o=ZG(e,t,r,n);return{ballJoint:wP(o.filter(a=>a.group==="ballJoint")),rodEnd:wP(o.filter(a=>a.group==="rodEnd"))}}function Sf(e,t){let r=t.vehicle.config;return e.map(n=>{let o=n.axle==="front"?r.frontAxleX:r.frontAxleX-r.wheelbase,a=o+Math.min(n.xMin,n.xMax),s=o+Math.max(n.xMin,n.xMax),i=(a+s)/2;return{...n,min:[a,Math.min(n.yMin,n.yMax),Yr(Math.min(n.zMin,n.zMax),i,t)],max:[s,Math.max(n.yMin,n.yMax),Yr(Math.max(n.zMin,n.zMax),i,t)]}})}var Ka=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Fr=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Et=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Cr=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Ru=e=>Math.sqrt(Cr(e,e));function kR(e,t){return{min:e,max:t,support:r=>[r[0]>=0?t[0]:e[0],r[1]>=0?t[1]:e[1],r[2]>=0?t[2]:e[2]]}}function MR(e,t){return{min:[Math.min(e[0],t[0]),Math.min(e[1],t[1]),Math.min(e[2],t[2])],max:[Math.max(e[0],t[0]),Math.max(e[1],t[1]),Math.max(e[2],t[2])],support:r=>Cr(r,e)>=Cr(r,t)?e:t,samples:()=>Array.from({length:41},(r,n)=>Fr(e,Et(Ka(t,e),n/40)))}}function Ha(e){let t=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0];for(let n of e)for(let o=0;o<3;o++)t[o]=Math.min(t[o],n[o]),r[o]=Math.max(r[o],n[o]);return{min:t,max:r,support:n=>{let o=e[0],a=-1/0;for(let s of e){let i=Cr(n,s);i>a&&(a=i,o=s)}return o}}}function wi(e,t,r,n){let o=Et(t,1/(Ru(t)||1)),a=n/2,s=o.map(i=>r*Math.sqrt(Math.max(0,1-i*i))+a*Math.abs(i));return{min:Ka(e,s),max:Fr(e,s),support:i=>{let c=Cr(i,o),l=Ka(i,Et(o,c)),u=Ru(l),m=u>1e-12?Et(l,r/u):[0,0,0];return Fr(Fr(e,Et(o,c>=0?a:-a)),m)},samples:()=>{let i=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],c=Ka(i,Et(o,Cr(i,o))),l=Et(c,1/Ru(c)),u=[o[1]*l[2]-o[2]*l[1],o[2]*l[0]-o[0]*l[2],o[0]*l[1]-o[1]*l[0]],m=[];for(let p of[-1,-.5,0,.5,1]){let d=Fr(e,Et(o,p*a));m.push(d);let f=Math.abs(p)===1?[.5,1]:[1];for(let h of f)for(let b=0;b<72;b++){let g=b/72*2*Math.PI;m.push(Fr(d,Fr(Et(l,h*r*Math.cos(g)),Et(u,h*r*Math.sin(g)))))}}return m}}}function JG(e){let t=e[0],r=e.slice(1).map(c=>Ka(c,t)),n=r.length;if(n===0)return{v:t,w:[1]};let o=r.map(c=>r.map(l=>Cr(c,l))),a=r.map(c=>-Cr(c,t));for(let c=0;c<n;c++){let l=c;for(let u=c+1;u<n;u++)Math.abs(o[u][c])>Math.abs(o[l][c])&&(l=u);if(Math.abs(o[l][c])<1e-12)return null;[o[c],o[l]]=[o[l],o[c]],[a[c],a[l]]=[a[l],a[c]];for(let u=0;u<n;u++){if(u===c)continue;let m=o[u][c]/o[c][c];for(let p=c;p<n;p++)o[u][p]-=m*o[c][p];a[u]-=m*a[c]}}let s=a.map((c,l)=>c/o[l][l]),i=t;for(let c=0;c<n;c++)i=Fr(i,Et(r[c],s[c]));return{v:i,w:[1-s.reduce((c,l)=>c+l,0),...s]}}function eK(e){let t=null,r=1/0,n=e.length;for(let o=1;o<1<<n;o++){let a=e.filter((c,l)=>o&1<<l),s=JG(a.map(c=>c.w));if(!s||s.w.some(c=>c<-1e-9))continue;let i=Cr(s.v,s.v);(i<r-1e-12||Math.abs(i-r)<=1e-12&&t&&a.length<t.keep.length)&&(r=i,t={v:s.v,keep:a,weights:s.w})}return t??{v:e[0].w,keep:[e[0]],weights:[1]}}function Fi(e,t,r=1e-9){let n=i=>{let c=e.support(i),l=t.support(Et(i,-1));return{w:Ka(c,l),a:c,b:l}},o=(i,c)=>{let l=[0,0,0],u=[0,0,0];return i.keep.forEach((m,p)=>{l=Fr(l,Et(m.a,i.weights[p])),u=Fr(u,Et(m.b,i.weights[p]))}),{distance:c,onA:l,onB:u}},a=n([1,0,0]),s={v:a.w,keep:[a],weights:[1]};for(let i=0;i<64;i++){let c=s.v,l=Cr(c,c);if(l<1e-12)return o(s,0);let u=n(Et(c,-1));if(l-Cr(c,u.w)<=r*Math.max(1,l))return o(s,Math.sqrt(l));let m=eK([...s.keep,u]);if(m.keep.length===4)return o(m,0);if(Cr(m.v,m.v)>=l-1e-12)return o(s,Math.sqrt(l));s=m}return o(s,Ru(s.v))}function tK(e,t){let r=null;for(let o of t.samples?.()??[]){let a=1/0,s=0,i=0;for(let c=0;c<3;c++)o[c]-e.min[c]<a&&(a=o[c]-e.min[c],s=c,i=e.min[c]),e.max[c]-o[c]<a&&(a=e.max[c]-o[c],s=c,i=e.max[c]);a>0&&(!r||a>r.depth)&&(r={depth:a,point:o,axis:s,to:i})}if(!r)return null;let n=[...r.point];return n[r.axis]=r.to,{depth:r.depth,point:r.point,face:n}}function Af(e,t){let r=0;for(let n=0;n<3;n++){let o=Math.max(0,e.min[n]-t.max[n],t.min[n]-e.max[n]);r+=o*o}return Math.sqrt(r)}var PP={linkRadius:8,mountAllowance:15},rK=(e,t,r)=>e.z0+e.dzdx*t+e.dzdy*r;function nK(e,t){let r=Math.sin(e.pitch);return{z0:-e.heave+t*r,dzdx:-r,dzdy:Math.sin(e.roll)}}function LP(e){return nK(yf({heave:0,pitch:0,roll:0,steer:0},e),bo(e.vehicle.config))}var oK=[{name:"upper wishbone, front leg",inboard:"ucaFront",outboard:"uprightUpper",body:"upperArm",ends:["chassis","upright"]},{name:"upper wishbone, rear leg",inboard:"ucaRear",outboard:"uprightUpper",body:"upperArm",ends:["chassis","upright"]},{name:"lower wishbone, front leg",inboard:"lcaFront",outboard:"uprightLower",body:"lowerArm",ends:["chassis","upright"]},{name:"lower wishbone, rear leg",inboard:"lcaRear",outboard:"uprightLower",body:"lowerArm",ends:["chassis","upright"]},{name:"tie rod",inboard:"tieInner",outboard:"tieOuter",body:"tieRod",ends:["chassis","upright"]},{name:"pushrod",inboard:"rockerToPushrod",outboard:"pushrodOuter",body:"rod",ends:["rocker","rodAttach"]},{name:"strut",inboard:"damperChassis",outboard:"pushrodOuter",body:"strut",ends:["chassis","upright"]}];function SR(e){return oK.filter(t=>t.name==="strut"?e.mcpherson:t.name==="pushrod"?!e.direct:!(e.mcpherson&&t.name.startsWith("upper")))}var DP=(e,t,r)=>e.every((n,o)=>n>=t.min[o]-r&&n<=t.max[o]+r);function CP(e,t,r){let n=Ka(t,e),o=Ru(n);return o>1e-9?Fr(e,Et(n,r/o)):e}function AR(e,t,r){let n=Fi(e,t),o=n.distance>0?null:tK(e,t),a=n.distance>0?n.distance-r:-((o?.depth??0)+r),s=n.distance>0?{part:CP(n.onB,n.onA,r),box:n.onA}:o?{part:CP(o.point,o.face,-r),box:o.face}:{part:n.onB,box:n.onA};return{distance:a,gap:s}}function TP(e,t){let r=null;for(let{shape:n,pad:o,part:a,pose:s}of t){if(r){let c=Af(e,n);if(c>0&&c-o>=r.distance)continue}let i=AR(e,n,o);Number.isFinite(i.distance)&&(!r||i.distance<r.distance)&&(r={distance:i.distance,part:a,corner:s.corner,travel:s.travel,rack:s.rack,gap:i.gap})}return r}function aK(e,t){let r=[];for(let c of[e.min[0],e.max[0]])for(let l of[e.min[1],e.max[1]])r.push([c,l,e.min[2]]);let n=r.map(t),o=Math.min(...n),a=r.filter((c,l)=>n[l]<=o+.5),s=new Set(a.map(c=>c[0])),i=new Set(a.map(c=>c[1]));return{height:o,lowest:{x:s.size>1||e.min[0]===e.max[0]?null:a[0][0]===e.max[0]?"front":"rear",y:i.size>1||e.min[1]===e.max[1]?null:a[0][1]===e.max[1]?"right":"left"},at:Et(a.reduce((c,l)=>Fr(c,l),[0,0,0]),1/a.length)}}function EP(e,t){return{...aK(e,r=>r[2]-rK(t,r[0],r[1])),road:t}}function IP(e,t){let r=(a,s,i)=>a[0]*(s[1]*i[2]-s[2]*i[1])-a[1]*(s[0]*i[2]-s[2]*i[0])+a[2]*(s[0]*i[1]-s[1]*i[0]),n=r(e[0],e[1],e[2]);if(Math.abs(n)<1e-12)return null;let o=a=>e.map((s,i)=>s.map((c,l)=>l===a?t[i]:c));return[r(...o(0))/n,r(...o(1))/n,r(...o(2))/n]}function sK(e,t){let r=e.map(o=>({pose:o,part:`${o.corner} tyre`,pad:0,shape:wi(o.g.wheelCenter,o.g.spinAxis,o.corner[0]==="F"?t.tyreRadius.front:t.tyreRadius.rear,t.tyreWidth)})),n=e.flatMap(o=>SR(o.g).map(a=>{let s=o.g[a.inboard],i=o.g[a.outboard];return{pose:o,part:`${o.corner} ${a.name}`,pad:t.linkRadius,inboard:s,shape:MR(s,i)}})).filter(o=>o.inboard.every(Number.isFinite)&&[o.shape.min,o.shape.max].every(a=>a.every(Number.isFinite)));return{tyres:r,links:n}}function iK(e,t,r){let n=kR(e.min,e.max),o=t.links.filter(a=>!DP(a.inboard,e,r.mountAllowance+r.linkRadius));return{tyre:TP(n,t.tyres),link:TP(n,o)}}function _P(e,t,r){let n=sK(t,r);return e.map(o=>({boxId:o.id,...iK(o,n,r)}))}var cK={r:[1,0,0,0,1,0,0,0,1],t:[0,0,0]},OP={r:[1,0,0,0,-1,0,0,0,1],t:[0,0,0]},Gt=(e,t)=>[e.r[0]*t[0]+e.r[1]*t[1]+e.r[2]*t[2]+e.t[0],e.r[3]*t[0]+e.r[4]*t[1]+e.r[5]*t[2]+e.t[1],e.r[6]*t[0]+e.r[7]*t[1]+e.r[8]*t[2]+e.t[2]],wf=(e,t)=>[e.r[0]*t[0]+e.r[1]*t[1]+e.r[2]*t[2],e.r[3]*t[0]+e.r[4]*t[1]+e.r[5]*t[2],e.r[6]*t[0]+e.r[7]*t[1]+e.r[8]*t[2]];function VP(e){let t=[e.r[0],e.r[3],e.r[6],e.r[1],e.r[4],e.r[7],e.r[2],e.r[5],e.r[8]],r=wf({r:t,t:[0,0,0]},e.t);return{r:t,t:[-r[0],-r[1],-r[2]]}}function vu(e,t){let r=[];for(let n=0;n<3;n++)for(let o=0;o<3;o++)r.push(e.r[3*n]*t.r[o]+e.r[3*n+1]*t.r[3+o]+e.r[3*n+2]*t.r[6+o]);return{r,t:Gt(e,t.t)}}function wR(e){let t=xs(e,[1,0,0]),r=xs(e,[0,1,0]),n=xs(e,[0,0,1]);return[t[0],r[0],n[0],t[1],r[1],n[1],t[2],r[2],n[2]]}function lK(e){let r=e.map(a=>[...a]),n=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]];for(let a=0;a<60;a++){let s=0;for(let i=0;i<4;i++)for(let c=i+1;c<4;c++)s+=r[i][c]*r[i][c];if(s<1e-30)break;for(let i=0;i<4;i++)for(let c=i+1;c<4;c++){if(Math.abs(r[i][c])<1e-300)continue;let l=(r[c][c]-r[i][i])/(2*r[i][c]),u=Math.sign(l||1)/(Math.abs(l)+Math.sqrt(l*l+1)),m=1/Math.sqrt(u*u+1),p=u*m;for(let d=0;d<4;d++){let f=r[d][i],h=r[d][c];r[d][i]=m*f-p*h,r[d][c]=p*f+m*h}for(let d=0;d<4;d++){let f=r[i][d],h=r[c][d];r[i][d]=m*f-p*h,r[c][d]=p*f+m*h}for(let d=0;d<4;d++){let f=n[d][i],h=n[d][c];n[d][i]=m*f-p*h,n[d][c]=p*f+m*h}}}let o=0;for(let a=1;a<4;a++)r[a][a]>r[o][o]&&(o=a);return[n[0][o],n[1][o],n[2][o],n[3][o]]}var NP=e=>{let t=[0,0,0];for(let r of e)for(let n=0;n<3;n++)t[n]+=r[n]/e.length;return t};function BP(e,t){let r=Math.min(e.length,t.length);if(r===0)return{iso:cK,residuals:[]};let n=NP(e.slice(0,r)),o=NP(t.slice(0,r)),a=[0,0,0,0,0,0,0,0,0];for(let S=0;S<r;S++){let A=[e[S][0]-n[0],e[S][1]-n[1],e[S][2]-n[2]],C=[t[S][0]-o[0],t[S][1]-o[1],t[S][2]-o[2]];for(let F=0;F<3;F++)for(let T=0;T<3;T++)a[3*F+T]+=A[F]*C[T]}let[s,i,c,l,u,m,p,d,f]=a,h=[[s+u+f,m-d,p-c,i-l],[m-d,s-u-f,i+l,p+c],[p-c,i+l,-s+u-f,m+d],[i-l,p+c,m+d,-s-u+f]],b=lK(h),g=Math.hypot(b[0],b[1],b[2],b[3])||1,y=wR([b[0]/g,b[1]/g,b[2]/g,b[3]/g]),x=wf({r:y,t:[0,0,0]},n),R={r:y,t:[o[0]-x[0],o[1]-x[1],o[2]-x[2]]},v=[];for(let S=0;S<r;S++){let A=Gt(R,e[S]);v.push(Math.hypot(A[0]-t[S][0],A[1]-t[S][1],A[2]-t[S][2]))}return{iso:R,residuals:v}}var zfe=Math.PI/180;function $P(e,t,r,n){let o=(Math.sqrt(5)-1)/2,a=t,s=r,i=s-o*(s-a),c=a+o*(s-a),l=e(i),u=e(c);for(;s-a>n;)l<=u?(s=c,c=i,u=l,i=s-o*(s-a),l=e(i)):(a=i,i=c,l=u,c=a+o*(s-a),u=e(c));return l<=u?{x:i,v:l}:{x:c,v:u}}var uK=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],GP=e=>Math.hypot(e[0],e[1],e[2]);var mK=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r],KP=(...e)=>e.every(t=>t.every(Number.isFinite)),dK={rocker:"rocker",lowerArm:"lowerArm",upright:"upright"};function HP(e,t,r,n,o){if(kf(t,void 0,e.axle).roll)return[];let a=pw(e.axle,t,r,e.armLength);if(!KP(a.tip,a.outer,a.root))return[];let s=o.housing.rodEnd,i={kind:"link",corner:n},c=[{...i,id:`${n} drop link`,name:"drop link",body:"dropLink",ends:["arb",dK[e.axle.linkage.attach]],a:a.tip,b:a.outer,radius:o.tube.dropLink,housing:[s,s]}];if(e.armLength>0){c.push({...i,id:`${n} anti-roll bar arm`,name:"anti-roll bar arm",body:"arb",ends:["arb","arb"],a:a.root,b:a.tip,radius:e.armRadius,housing:[0,s]});let l=[a.root[0],-a.root[1],a.root[2]];c.push({...i,id:`${n} anti-roll bar`,name:"anti-roll bar",body:"arb",ends:["chassis","chassis"],a:a.root,b:l,radius:e.barRadius,housing:[0,0],shared:!0})}return c}function zP(e,t){return{kind:"link",id:`${t} rack housing`,name:"rack housing",corner:t,body:"rackHousing",ends:["rack","rack"],a:e.a,b:e.b,radius:e.radius,housing:[0,0],shared:!0,flat:!0}}function pK(e){let t=GP(e.spinAxis)||1,r=[e.spinAxis[0]/t,e.spinAxis[1]/t,e.spinAxis[2]/t],n=e.wheelCenter[1]>=0?1:-1;return r[1]*n<0?[-r[0],-r[1],-r[2]]:r}function fK(e,t){let r=pK(e);return[e.wheelCenter[0]-r[0]*t,e.wheelCenter[1]-r[1]*t,e.wheelCenter[2]-r[2]*t]}var hK=(e,t)=>t[1]==="L"?e.inboard.left:e.inboard.right;function YP(e,t,r){let n=hK(e,r),o=fK(t,e.outboard);return KP(n,o)?{kind:"link",id:`${r} driveshaft`,name:"driveshaft",corner:r,body:"driveshaft",ends:["chassis","upright"],a:n,b:o,radius:e.radius,housing:[e.reach,e.reach]}:null}function WP(e,t,r,n,o,a,s,i){let c=GP(uK(a.p,o.p)),l=Math.min(c,s.bodyLength),u=l>=c,m=c>1e-9?mK(o.p,a.p,l/c):o.p,p={kind:"link",corner:n,body:r},d={...p,id:`${e} body`,name:`${t} body`,ends:[o.body,u?a.body:r],endCorners:[o.corner,u?a.corner:n],a:o.p,b:m,radius:s.bodyRadius,housing:[i,u?i:0],flat:!0};return u?[d]:[d,{...p,id:`${e} shaft`,name:`${t} shaft`,ends:[r,a.body],endCorners:[n,a.corner],a:m,b:a.p,radius:s.shaftRadius,housing:[0,i]}]}var Ci=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Cf=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],Do=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],FR=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Tf=e=>Math.sqrt(FR(e,e)),CR=(e,t,r)=>Cf(e,Do(Ci(t,e),r));function XP(e,t,r){let n=e.diameter/2,o=Math.max(n,t),a=r/2,s=Math.min(a,e.width/2),i=(n+o)/2,c=[];for(let l=0;l<3;l++){let u=s+(a-s)*(l+1)/3;c.push({z0:-u,z1:u,r0:n+(i-n)*l/3,r1:n+(i-n)*(l+1)/3})}return c.push({z0:-a,z1:a,r0:i,r1:o}),c}function qP(e){let t=e.diameter/2,r=bK(e),n=e.width/2,o={z0:-n,z1:n,r0:r,r1:t};if(e.offset===null)return[o];let a=Math.min(n,Math.max(-n,e.offset));return[o,{z0:a,z1:n,r0:0,r1:r}]}var bK=e=>Math.max(0,e.diameter/2-e.wall);function gK(e,t){let r=Ci(e,t.centre),n=FR(r,t.axis),o=Ci(r,Do(t.axis,n)),a=Tf(o);if(a>1e-9)return{z:n,r:a,out:Do(o,1/a)};let s=Math.abs(t.axis[0])<.9?[1,0,0]:[0,1,0],i=Ci(s,Do(t.axis,FR(s,t.axis)));return{z:n,r:0,out:Do(i,1/Tf(i))}}function jP(e,t,r){if(!(t>e.z0&&t<e.z1&&r<e.r1&&(e.r0>0?r>e.r0:r>=0))){let s=Math.min(e.z1,Math.max(e.z0,t)),i=Math.min(e.r1,Math.max(e.r0,r));return{d:Math.hypot(t-s,r-i),z:s,r:i}}let o=[{d:t-e.z0,z:e.z0,r},{d:e.z1-t,z:e.z1,r},{d:e.r1-r,z:t,r:e.r1}];e.r0>0&&o.push({d:r-e.r0,z:t,r:e.r0});let a=o.reduce((s,i)=>i.d<s.d?i:s);return{d:-a.d,z:a.z,r:a.r}}var yK=16,UP=new WeakMap;function xK(e){let t=UP.get(e);if(t)return t;let r=Int32Array.from(e.keys()).sort((s,i)=>e[s].z0-e[i].z0||s-i),n=Float64Array.from(r,s=>e[s].z0),o=new Float64Array(r.length),a=-1/0;return r.forEach((s,i)=>{a=Math.max(a,e[s].z1),o[i]=a}),t={order:r,z0:n,reach:o},UP.set(e,t),t}function ku(e,t,r){let n=gK(e,r),o={d:1/0,z:0,r:0};if(t.length<yK)for(let a of t){let s=jP(a,n.z,n.r);s.d<o.d&&(o=s)}else{let{order:a,z0:s,reach:i}=xK(t),c=1/0,l=p=>{let d=jP(t[p],n.z,n.r);(d.d<o.d||d.d===o.d&&p<c)&&(o=d,c=p)},u=0,m=a.length;for(;u<m;){let p=u+m>>1;s[p]<=n.z?u=p+1:m=p}for(let p=u-1;p>=0&&n.z-i[p]<=Math.max(0,o.d);p--){let d=n.z-t[a[p]].z1;(d<=0||d<=o.d)&&l(a[p])}for(let p=u;p<a.length&&s[p]-n.z<=o.d;p++)l(a[p])}return{distance:o.d,on:Cf(Cf(r.centre,Do(r.axis,o.z)),Do(n.out,o.r))}}var Ff=(Math.sqrt(5)-1)/2;function RK(e,t,r,n){let o=t,a=r,s=a-Ff*(a-o),i=o+Ff*(a-o),c=e(s),l=e(i);for(;a-o>n;)c<=l?(a=i,i=s,l=c,s=a-Ff*(a-o),c=e(s)):(o=s,s=i,c=l,i=o+Ff*(a-o),l=e(i));return c<=l?s:i}var vK=24;function QP(e,t,r,n){let o=u=>ku(CR(e,t,u),r,n).distance,a=Tf(Ci(t,e))<1e-9?0:vK,s=0,i=o(0);for(let u=1;u<=a;u++){let m=o(u/a);m<i&&(i=m,s=u)}if(a===0)return{t:0,distance:i};let c=RK(o,Math.max(0,(s-1)/a),Math.min(1,(s+1)/a),1e-4),l=o(c);return l<i?{t:c,distance:l}:{t:s/a,distance:i}}function ZP(e,t,r,n,o){let{t:a}=QP(e,t,n,o),s=CR(e,t,a),i=ku(s,n,o);return{distance:i.distance-r,onPart:eL(s,i.on,r,i.distance),onWheel:i.on}}function JP(e,t,r,n){let o=null,a=i=>{let c=ku(i,r,n);(!o||c.distance<o.distance)&&(o={p:i,distance:c.distance,on:c.on})};for(let i of e)a(i);for(let i=0;i<e.length;i++)for(let c=i+1;c<e.length;c++){let l=QP(e[i],e[c],r,n);(!o||l.distance<o.distance)&&a(CR(e[i],e[c],l.t))}let s=o;return{distance:s.distance-t,onPart:eL(s.p,s.on,t,s.distance),onWheel:s.on}}function eL(e,t,r,n){let o=Ci(t,e),a=Tf(o);return a<1e-9||r===0?e:Cf(e,Do(o,(n>=0?r:-r)/a))}function Su(e,t){return e&&t>0?{...e,distance:Math.max(0,e.distance-t)}:e}var Pi=e=>e.allowance??0;function Df(e,t,r,n,o){let a=r[0]-t[0],s=r[1]-t[1],i=r[2]-t[2],c=n[0]-t[0],l=n[1]-t[1],u=n[2]-t[2],m=e[0]-t[0],p=e[1]-t[1],d=e[2]-t[2],f=a*m+s*p+i*d,h=c*m+l*p+u*d,b=(_,D,I)=>{o[0]=_,o[1]=D,o[2]=I;let N=e[0]-_,O=e[1]-D,V=e[2]-I;return N*N+O*O+V*V};if(f<=0&&h<=0)return b(t[0],t[1],t[2]);let g=e[0]-r[0],y=e[1]-r[1],x=e[2]-r[2],R=a*g+s*y+i*x,v=c*g+l*y+u*x;if(R>=0&&v<=R)return b(r[0],r[1],r[2]);let S=f*v-R*h;if(S<=0&&f>=0&&R<=0){let _=f/(f-R);return b(t[0]+_*a,t[1]+_*s,t[2]+_*i)}let A=e[0]-n[0],C=e[1]-n[1],F=e[2]-n[2],T=a*A+s*C+i*F,M=c*A+l*C+u*F;if(M>=0&&T<=M)return b(n[0],n[1],n[2]);let k=T*h-f*M;if(k<=0&&h>=0&&M<=0){let _=h/(h-M);return b(t[0]+_*c,t[1]+_*l,t[2]+_*u)}let w=R*M-T*v;if(w<=0&&v-R>=0&&T-M>=0){let _=(v-R)/(v-R+(T-M));return b(r[0]+_*(n[0]-r[0]),r[1]+_*(n[1]-r[1]),r[2]+_*(n[2]-r[2]))}let P=1/(w+k+S),L=k*P,E=S*P;return b(t[0]+a*L+c*E,t[1]+s*L+l*E,t[2]+i*L+u*E)}function TR(e,t,r,n,o,a){let s=t[0]-e[0],i=t[1]-e[1],c=t[2]-e[2],l=n[0]-r[0],u=n[1]-r[1],m=n[2]-r[2],p=e[0]-r[0],d=e[1]-r[1],f=e[2]-r[2],h=s*s+i*i+c*c,b=l*l+u*u+m*m,g=l*p+u*d+m*f,y=C=>C<0?0:C>1?1:C,x=0,R=0;if(h<=1e-12&&b<=1e-12)x=0,R=0;else if(h<=1e-12)R=y(g/b);else{let C=s*p+i*d+c*f;if(b<=1e-12)x=y(-C/h);else{let F=s*l+i*u+c*m,T=h*b-F*F;x=T>1e-12?y((F*g-C*b)/T):0,R=(F*x+g)/b,R<0?(R=0,x=y(-C/h)):R>1&&(R=1,x=y((F-C)/h))}}o[0]=e[0]+x*s,o[1]=e[1]+x*i,o[2]=e[2]+x*c,a[0]=r[0]+R*l,a[1]=r[1]+R*u,a[2]=r[2]+R*m;let v=o[0]-a[0],S=o[1]-a[1],A=o[2]-a[2];return v*v+S*S+A*A}function kK(e,t,r,n,o,a){let s=t[0]-e[0],i=t[1]-e[1],c=t[2]-e[2],l=n[0]-r[0],u=n[1]-r[1],m=n[2]-r[2],p=o[0]-r[0],d=o[1]-r[1],f=o[2]-r[2],h=i*f-c*d,b=c*p-s*f,g=s*d-i*p,y=l*h+u*b+m*g,x=Math.sqrt((s*s+i*i+c*c)*(l*l+u*u+m*m)*(p*p+d*d+f*f));if(Math.abs(y)<=1e-12*x)return!1;let R=1/y,v=e[0]-r[0],S=e[1]-r[1],A=e[2]-r[2],C=(v*h+S*b+A*g)*R;if(C<0||C>1)return!1;let F=S*m-A*u,T=A*l-v*m,M=v*u-S*l,k=(s*F+i*T+c*M)*R;if(k<0||C+k>1)return!1;let w=(p*F+d*T+f*M)*R;return w<0||w>1?!1:(a[0]=e[0]+w*s,a[1]=e[1]+w*i,a[2]=e[2]+w*c,!0)}function Ef(e,t,r,n,o,a,s){if(kK(e,t,r,n,o,s))return a[0]=s[0],a[1]=s[1],a[2]=s[2],0;let i=[0,0,0],c=[0,0,0],l=Df(e,r,n,o,s);a[0]=e[0],a[1]=e[1],a[2]=e[2];let u=(m,p,d)=>{m>=l||(l=m,a[0]=p[0],a[1]=p[1],a[2]=p[2],s[0]=d[0],s[1]=d[1],s[2]=d[2])};return u(Df(t,r,n,o,c),t,c),u(TR(e,t,r,n,i,c),i,c),u(TR(e,t,n,o,i,c),i,c),u(TR(e,t,o,r,i,c),i,c),l}function LR(e,t,r,n){let o=e.box,a=6*t,s=0;for(let i=0;i<3;i++){let c=Math.max(0,o[a+i]-n[i],r[i]-o[a+3+i]);s+=c*c}return s}function PR(e,t,r){for(let n of r){let o=0;for(let a=0;a<3;a++){let s=Math.max(Math.abs(n.c[a]-e[t+a]),Math.abs(e[t+3+a]-n.c[a]));o+=s*s}if(o<=n.r*n.r)return!0}return!1}function If(e,t,r,n,o){let a=n;if(!e.nodes)return a;let s=[0],i=[t(0)];for(;s.length;){let c=s.pop();if(i.pop()>=a||o.length&&PR(e.box,6*c,o))continue;if(e.right[c]<0){let f=e.start[c]+e.size[c];for(let h=e.start[c];h<f;h++){let b=r(h,a);if(b<a&&(a=b),a<=0)return 0}continue}let u=c+1,m=e.right[c],p=t(u),d=t(m);p<=d?(d<a&&(s.push(m),i.push(d)),p<a&&(s.push(u),i.push(p))):(p<a&&(s.push(u),i.push(p)),d<a&&(s.push(m),i.push(d)))}return a}function nL(e,t,r){let n=[Math.min(t[0],r[0]),Math.min(t[1],r[1]),Math.min(t[2],r[2])],o=[Math.max(t[0],r[0]),Math.max(t[1],r[1]),Math.max(t[2],r[2])],a=r[0]-t[0],s=r[1]-t[1],i=r[2]-t[2],c=a*a+s*s+i*i,l=e.box;return u=>{let m=6*u,p=(l[m]+l[m+3])/2,d=(l[m+1]+l[m+4])/2,f=(l[m+2]+l[m+5])/2,h=(l[m+3]-l[m])/2,b=(l[m+4]-l[m+1])/2,g=(l[m+5]-l[m+2])/2,y=c>1e-12?((p-t[0])*a+(d-t[1])*s+(f-t[2])*i)/c:0;y=y<0?0:y>1?1:y;let x=p-t[0]-y*a,R=d-t[1]-y*s,v=f-t[2]-y*i,S=Math.sqrt(x*x+R*R+v*v)-Math.sqrt(h*h+b*b+g*g);return Math.max(S,Math.sqrt(LR(e,u,n,o)))}}var Xt=(e,t,r)=>{let n=9*t+3*r;return[e.tri[n],e.tri[n+1],e.tri[n+2]]};function Au(e,t,r,n=1/0,o=[]){let a=Pi(e);return Su(MK(e,t,r,n+a,o),a)}function MK(e,t,r,n=1/0,o=[]){let a=nL(e,t,r),s=[0,0,0],i=[0,0,0],c=null,l=If(e,a,(u,m)=>{let p=1/0;return ao(Xt(e,u,0),Xt(e,u,1),Xt(e,u,2),o,(d,f,h)=>{let b=Math.sqrt(Ef(t,r,d,f,h,s,i));b<p&&(p=b),b<m&&(!c||b<c.distance)&&(c={distance:b,onMesh:[...i],onPart:[...s]})}),p},n,o);return c&&c.distance===l?c:null}function _f(e,t,r,n,o,a=1/0,s=[]){let i=Pi(e);return Su(SK(e,t,r,n,o,a+i,s),i)}function SK(e,t,r,n,o,a=1/0,s=[]){let i=wi(t,r,n,o),c=Math.hypot(r[0],r[1],r[2])||1,l=r[0]/c,u=r[1]/c,m=r[2]/c,p=o/2,d=[t[0]-p*l,t[1]-p*u,t[2]-p*m],f=[t[0]+p*l,t[1]+p*u,t[2]+p*m],h=e.box,b=nL(e,d,f),g=S=>{let A=6*S,C=(h[A]+h[A+3])/2,F=(h[A+1]+h[A+4])/2,T=(h[A+2]+h[A+5])/2,M=(h[A+3]-h[A])/2,k=(h[A+4]-h[A+1])/2,w=(h[A+5]-h[A+2])/2,P=(C-t[0])*l+(F-t[1])*u+(T-t[2])*m,L=Math.abs(l)*M+Math.abs(u)*k+Math.abs(m)*w,E=Math.max(0,Math.abs(P)-L-p);return Math.max(E,b(S)-n,Math.sqrt(LR(e,S,i.min,i.max)))},y=[0,0,0],x=[0,0,0],R=null,v=If(e,g,(S,A)=>{let C=1/0;return ao(Xt(e,S,0),Xt(e,S,1),Xt(e,S,2),s,(F,T,M)=>{let k=Math.min(A,C),w=(F[0]-t[0])*l+(F[1]-t[1])*u+(F[2]-t[2])*m,P=(T[0]-t[0])*l+(T[1]-t[1])*u+(T[2]-t[2])*m,L=(M[0]-t[0])*l+(M[1]-t[1])*u+(M[2]-t[2])*m;if(Math.max(0,Math.min(w,P,L)-p,-p-Math.max(w,P,L))>=k||Math.sqrt(Ef(d,f,F,T,M,y,x))-n>=k)return;let _=Fi(Ha([F,T,M]),i,1e-6);if(_.distance<k)if(_.distance>0)R={distance:_.distance,onMesh:_.onA,onPart:_.onB};else{let D=[0,0,0];Df(t,F,T,M,D),R={distance:0,onMesh:D,onPart:D}}_.distance<C&&(C=_.distance)}),C},a,s);return R&&R.distance===v?R:null}var DR=(e,t,r)=>Au(e,t,t,r)!==null;var Pf=(e,t)=>{let r=e[0]-t.c[0],n=e[1]-t.c[1],o=e[2]-t.c[2];return r*r+n*n+o*o<=t.r*t.r},Ti=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2,(e[2]+t[2])/2],za=(e,t)=>(e[0]-t[0])**2+(e[1]-t[1])**2+(e[2]-t[2])**2,AK=1,wK=6;function ao(e,t,r,n,o,a=0){if(!n.length)return o(e,t,r);let s=[0,0,0],i=n.filter(p=>Df(p.c,e,t,r,s)<=p.r*p.r);if(!i.length)return o(e,t,r);for(let p of i)if(Pf(e,p)&&Pf(t,p)&&Pf(r,p))return;if(Math.sqrt(Math.max(za(e,t),za(t,r),za(r,e)))<=Math.max(AK,Math.min(...i.map(p=>p.r))/8)||a>=wK){let p=[(e[0]+t[0]+r[0])/3,(e[1]+t[1]+r[1])/3,(e[2]+t[2]+r[2])/3];i.some(d=>Pf(p,d))||o(e,t,r);return}let l=Ti(e,t),u=Ti(t,r),m=Ti(r,e);ao(e,l,m,i,o,a+1),ao(l,t,u,i,o,a+1),ao(m,u,r,i,o,a+1),ao(l,u,m,i,o,a+1)}function FK(e,t,r,n){let o=[];return ao(e,t,r,n,(a,s,i)=>o.push([a,s,i])),o}var CK=e=>[Math.min(e[0][0],e[1][0],e[2][0]),Math.min(e[0][1],e[1][1],e[2][1]),Math.min(e[0][2],e[1][2],e[2][2]),Math.max(e[0][0],e[1][0],e[2][0]),Math.max(e[0][1],e[1][1],e[2][1]),Math.max(e[0][2],e[1][2],e[2][2])];function ER(e,t,r=1/0,n=[]){let o=Pi(e);return Su(TK(e,t,r+o,n),o)}function TK(e,t,r=1/0,n=[]){let o=null,a=If(e,s=>Math.sqrt(LR(e,s,t.min,t.max)),(s,i)=>{let c=1/0;return ao(Xt(e,s,0),Xt(e,s,1),Xt(e,s,2),n,(l,u,m)=>{let p=Ha([l,u,m]),d=Math.min(i,c),f=0;for(let b=0;b<3;b++){let g=Math.max(0,p.min[b]-t.max[b],t.min[b]-p.max[b]);f+=g*g}if(Math.sqrt(f)>=d)return;let h=Fi(p,t,1e-6);if(h.distance<d)if(h.distance>0)o={distance:h.distance,onMesh:h.onA,onPart:h.onB};else{let b=[(l[0]+u[0]+m[0])/3,(l[1]+u[1]+m[1])/3,(l[2]+u[2]+m[2])/3];o={distance:0,onMesh:b,onPart:b}}h.distance<c&&(c=h.distance)}),c},r,n);return o&&o.distance===a?o:null}function PK(e,t,r,n,o,a,s,i){let c=[0,0,0],l=[0,0,0],u=1/0,m=(f,h,b)=>{f>=u||(u=f,s[0]=h[0],s[1]=h[1],s[2]=h[2],i[0]=b[0],i[1]=b[1],i[2]=b[2])},p=[e,t,r],d=[n,o,a];for(let f=0;f<3;f++)if(m(Ef(p[f],p[(f+1)%3],n,o,a,c,l),c,l),u===0)return 0;for(let f=0;f<3;f++)if(m(Ef(d[f],d[(f+1)%3],e,t,r,c,l),l,c),u===0)return 0;return u}var LK=.002;function IR(e,t,r,n=1/0,o=[]){let a=Pi(e)+Pi(t);return Su(DK(e,t,r,n+a,o),a)}function DK(e,t,r,n=1/0,o=[]){if(!e.nodes||!t.nodes)return null;let a=new Float64Array(6*t.nodes).fill(NaN),s=x=>{let R=6*x;if(!Number.isNaN(a[R]))return R;let v=1/0,S=1/0,A=1/0,C=-1/0,F=-1/0,T=-1/0;for(let M=0;M<8;M++){let k=Gt(r,[t.box[R+(M&1?3:0)],t.box[R+1+(M&2?3:0)],t.box[R+2+(M&4?3:0)]]);k[0]<v&&(v=k[0]),k[0]>C&&(C=k[0]),k[1]<S&&(S=k[1]),k[1]>F&&(F=k[1]),k[2]<A&&(A=k[2]),k[2]>T&&(T=k[2])}return a.set([v,S,A,C,F,T],R),R},i=(x,R)=>{let v=6*x,S=s(R),A=0;for(let C=0;C<3;C++){let F=Math.max(0,e.box[v+C]-a[S+3+C],a[S+C]-e.box[v+3+C]);A+=F*F}return Math.sqrt(A)},c=(x,R)=>(x[R+3]-x[R])**2+(x[R+4]-x[R+1])**2+(x[R+5]-x[R+2])**2,l=(x,R,v)=>{let S=[Xt(x,R,0),Xt(x,R,1),Xt(x,R,2)];return v?S.map(A=>Gt(v,A)):S},u=new Map,m=new Map,p=(x,R,v,S)=>{let A=S.get(R);if(!A){A=[];let C=x.start[R]+x.size[R];for(let F=x.start[R];F<C;F++)for(let T of FK(...l(x,F,v),o))A.push({t:T,box:CK(T)});S.set(R,A)}return A},d=n,f=n,h=null,b=[0,0,0],g=[0,0,0],y=[[0,0,i(0,0)]];for(;y.length;){let[x,R,v]=y.pop();if(v>=f||o.length&&(PR(e.box,6*x,o)||PR(a,s(R),o)))continue;let S=e.right[x]<0,A=t.right[R]<0;if(S&&A){let k=p(t,R,r,m);if(!k.length)continue;for(let w of p(e,x,null,u))for(let P of k){let L=0;for(let _=0;_<3;_++){let D=Math.max(0,w.box[_]-P.box[3+_],P.box[_]-w.box[3+_]);L+=D*D}if(L>=f*f)continue;let E=Math.sqrt(PK(w.t[0],w.t[1],w.t[2],P.t[0],P.t[1],P.t[2],b,g));if(E<d&&(d=E,f=E*(1-LK),h={distance:E,onA:[...b],onB:[...g]},d<=0))return h}continue}let F=!S&&(A||c(e.box,6*x)>=c(a,s(R)))?[[x+1,R],[e.right[x],R]]:[[x,R+1],[x,t.right[R]]],T=F.map(([k,w])=>i(k,w)),M=T[0]<=T[1]?[1,0]:[0,1];for(let k of M)T[k]<f&&y.push([F[k][0],F[k][1],T[k]])}return h}function Mu(e,t){let r=e[0]-t.centre[0],n=e[1]-t.centre[1],o=e[2]-t.centre[2],a=r*t.axis[0]+n*t.axis[1]+o*t.axis[2],s=r-a*t.axis[0],i=n-a*t.axis[1],c=o-a*t.axis[2];return[a,Math.sqrt(s*s+i*i+c*c)]}function tL(e,t,r,n,o){let a=1/0;for(let s of o){let i=Math.max(0,s.z0-t,e-s.z1),c=Math.max(0,s.r0-n,r-s.r1),l=Math.hypot(i,c);l<a&&(a=l)}return a}var Lf=8;function oL(e,t,r,n=1/0,o=[]){let a=Pi(e);return Su(EK(e,t,r,n+a,o),a)}function EK(e,t,r,n=1/0,o=[]){if(!r.length)return null;let a=e.box,s=d=>{let f=6*d,h=1/0,b=-1/0,g=0;for(let S=0;S<8;S++){let[A,C]=Mu([a[f+(S&1?3:0)],a[f+1+(S&2?3:0)],a[f+2+(S&4?3:0)]],t);A<h&&(h=A),A>b&&(b=A),C>g&&(g=C)}let y=(a[f+3]-a[f])/2,x=(a[f+4]-a[f+1])/2,R=(a[f+5]-a[f+2])/2,[,v]=Mu([a[f]+y,a[f+1]+x,a[f+2]+R],t);return tL(h,b,Math.max(0,v-Math.sqrt(y*y+x*x+R*R)),g,r)},i=d=>ku(d,r,t),c=null,l=(d,f)=>{let h=i(d),b=Math.max(0,h.distance);return b<f&&(!c||b<c.distance)&&(c={distance:b,onMesh:d,onPart:b>0?h.on:d}),b},u=(d,f,h)=>{let b=M=>i([d[0]+(f[0]-d[0])*M,d[1]+(f[1]-d[1])*M,d[2]+(f[2]-d[2])*M]).distance,g=0,y=1/0;for(let M=1;M<Lf;M++){let k=b(M/Lf);k<y&&(y=k,g=M)}let x=(g-1)/Lf,R=(g+1)/Lf,v=(Math.sqrt(5)-1)/2,S=R-v*(R-x),A=x+v*(R-x),C=b(S),F=b(A);for(;R-x>.001;)C<=F?(R=A,A=S,F=C,S=R-v*(R-x),C=b(S)):(x=S,S=A,C=F,A=x+v*(R-x),F=b(A));let T=C<=F?S:A;return l([d[0]+(f[0]-d[0])*T,d[1]+(f[1]-d[1])*T,d[2]+(f[2]-d[2])*T],h)},m=(d,f,h,b,g)=>{let y=Mu(d,t),x=Mu(f,t),R=Mu(h,t),v=Math.max(za(d,f),za(f,h),za(h,d)),S=Math.max(y[1],x[1],R[1]);if(tL(Math.min(y[0],x[0],R[0]),Math.max(y[0],x[0],R[0]),Math.max(0,S-Math.sqrt(v)),S,r)>=b)return 1/0;if(v>rL*rL&&g<4){let k=Ti(d,f),w=Ti(f,h),P=Ti(h,d),L=1/0;for(let[E,_,D]of[[d,k,P],[k,f,w],[P,w,h],[k,w,P]])L=Math.min(L,m(E,_,D,Math.min(b,L),g+1));return L}let C=1/0,F=[d,f,h].map(k=>{let w=l(k,Math.min(b,C));return C=Math.min(C,w),w}),T=Math.min(b,C),M=(k,w,P,L)=>(P+L-Math.sqrt(za(k,w)))/2>=T?1/0:u(k,w,T);return C=Math.min(C,M(d,f,F[0],F[1]),M(f,h,F[1],F[2]),M(h,d,F[2],F[0])),C},p=If(e,s,(d,f)=>{let h=1/0;return ao(Xt(e,d,0),Xt(e,d,1),Xt(e,d,2),o,(b,g,y)=>{h=Math.min(h,m(b,g,y,Math.min(f,h),0))}),h},n,o);return c&&c.distance===p?c:null}var rL=25;var OR=["upright","wheel","upperArm","lowerArm","rocker","damperBody"],VR={upright:"upright",wheel:"wheel",upperArm:"upper wishbone",lowerArm:"lower wishbone",rocker:"rocker",damperBody:"damper body"},_K=.5;function BR(e,t,r){let n=[];switch(t){case"upright":case"wheel":e.mcpherson||n.push("uprightUpper"),n.push("uprightLower","tieOuter"),(e.mcpherson||r==="upright")&&n.push("pushrodOuter");break;case"upperArm":if(e.mcpherson)return[];n.push("ucaFront","ucaRear","uprightUpper"),r==="upperArm"&&n.push("pushrodOuter");break;case"lowerArm":n.push("lcaFront","lcaRear","uprightLower"),r==="lowerArm"&&!e.mcpherson&&n.push("pushrodOuter");break;case"rocker":if(e.direct)return[];n.push("rockerPivotA","rockerPivotB","rockerToPushrod","rockerToDamper");break;case"damperBody":if(e.decoupled||e.mcpherson)return[];n.push("damperChassis",e.direct?"pushrodOuter":"rockerToDamper");break}return n.filter(o=>e[o].every(Number.isFinite))}var NK=e=>e[1]==="L"?"left":"right",OK=e=>[e[0],-e[1],e[2]];function aL(e,t,r,n,o){let a=BR(r,t,o).filter(f=>e.placedOn[f]?.every(Number.isFinite)),s=NK(n)!==e.side,i=a.map(f=>s?OK(e.placedOn[f]):e.placedOn[f]),c=a.map(f=>r[f]),l=s?OP:null;if(t==="damperBody"){if(a.length<2)return null;let f=Nf(Li(i[1],i[0])),h=Nf(Li(c[1],c[0])),b=wR(lm(f,h)),g=Gt({r:b,t:[0,0,0]},i[0]),y={r:b,t:Li(c[0],g)};return{iso:l?vu(y,l):y,worst:null}}if(a.length<3)return null;let u=BP(i,c),m=Math.max(...u.residuals),p=0,d=-1;for(let f=0;f<a.length;f++){let h=0;for(let b=0;b<a.length;b++)b!==f&&(h+=Math.abs(NR(Li(i[f],i[b]))-NR(Li(c[f],c[b]))));h>d&&([p,d]=[f,h])}return{iso:l?vu(u.iso,l):u.iso,worst:{key:a[p],by:m}}}var sL=e=>!!e&&(!e.worst||e.worst.by<=_K);var VK=1,_R=.5;function BK(e,t,r=VK){let n=Nf(t.axis),o=Math.abs(n[0])<.9?[1,0,0]:[0,1,0],a=Nf(Li(o,iL(n,wu(o,n)))),s=KK(n,a),i=Math.floor(e.length/9),c=new Float64Array(9*i),l=1/0,u=-1/0;for(let h=0;h<3*i;h++){let b=[e[3*h]-t.centre[0],e[3*h+1]-t.centre[1],e[3*h+2]-t.centre[2]],g=wu(b,n);c[3*h]=wu(b,a),c[3*h+1]=wu(b,s),c[3*h+2]=g,g<l&&(l=g),g>u&&(u=g)}if(!i)return[];let m=Math.max(1,Math.ceil((u-l)/r)),p=new Float64Array(m).fill(1/0),d=new Float64Array(m).fill(-1/0);for(let h=0;h<i;h++){let b=[0,1,2].map(v=>[c[9*h+3*v],c[9*h+3*v+1],c[9*h+3*v+2]]),g=Math.min(b[0][2],b[1][2],b[2][2]),y=Math.max(b[0][2],b[1][2],b[2][2]),x=Math.max(0,Math.min(m-1,Math.floor((g-l)/r))),R=Math.max(0,Math.min(m-1,Math.floor((y-l)/r)));for(let v=x;v<=R;v++){let S=$K(b,l+v*r,l+(v+1)*r);if(!S.length)continue;let A=0;for(let F of S)A=Math.max(A,Math.hypot(F[0],F[1]));let C=GK(S);C<p[v]&&(p[v]=C),A>d[v]&&(d[v]=A)}}let f=[];for(let h=0;h<m;h++){if(!(d[h]>=0))continue;let b=p[h]<_R?0:p[h],g=f[f.length-1],y=l+h*r;g&&Math.abs(g.z1-y)<1e-9&&Math.abs(g.r0-b)<=_R&&Math.abs(g.r1-d[h])<=_R?(g.z1=y+r,g.r0=Math.min(g.r0,b),g.r1=Math.max(g.r1,d[h])):f.push({z0:y,z1:y+r,r0:b,r1:d[h]})}return f}function $K(e,t,r){let n=(o,a)=>{let s=[];for(let i=0;i<o.length;i++){let c=o[i],l=o[(i+1)%o.length],u=a(c),m=a(l);if(u>=0&&s.push(c),u>=0!=m>=0){let p=u/(u-m);s.push([c[0]+(l[0]-c[0])*p,c[1]+(l[1]-c[1])*p,c[2]+(l[2]-c[2])*p])}}return s};return n(n(e,o=>o[2]-t),o=>r-o[2])}function GK(e){let t=!1,r=!1,n=1/0;for(let o=0;o<e.length;o++){let a=e[o],s=e[(o+1)%e.length],i=a[0]*s[1]-a[1]*s[0];i>1e-12?t=!0:i<-1e-12&&(r=!0);let c=s[0]-a[0],l=s[1]-a[1],u=c*c+l*l,m=u>1e-18?Math.max(0,Math.min(1,-(a[0]*c+a[1]*l)/u)):0;n=Math.min(n,Math.hypot(a[0]+m*c,a[1]+m*l))}return t!==r?0:n}var Li=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],wu=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],KK=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],NR=e=>Math.sqrt(wu(e,e)),iL=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Nf=e=>iL(e,1/(NR(e)||1));function cL(e,t,r){if(!e.bands){let n=e.tree.tri,o=new Float64Array(n.length);for(let a=0;a+2<n.length;a+=3){let s=Gt(t,[n[a],n[a+1],n[a+2]]);o[a]=s[0],o[a+1]=s[1],o[a+2]=s[2]}e.bands=BK(o,r)}return e.bands}var pL=25,ht=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Tr=e=>Math.hypot(e[0],e[1],e[2]),yr=(e,t,r)=>[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r],GR={lowerArm:"lowerArm",upperArm:"upperArm",upright:"upright"},HK=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],Wa=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Fu=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],jr=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Of=e=>jr(e,1/(Tr(e)||1)),zK={"upper wishbone, front leg":{tube:"upperArm",joints:["ballJoint","ballJoint"]},"upper wishbone, rear leg":{tube:"upperArm",joints:["ballJoint","ballJoint"]},"lower wishbone, front leg":{tube:"lowerArm",joints:["ballJoint","ballJoint"]},"lower wishbone, rear leg":{tube:"lowerArm",joints:["ballJoint","ballJoint"]},"tie rod":{tube:"tieRod",joints:["rodEnd","rodEnd"]},pushrod:{tube:"rod",joints:["rodEnd","rodEnd"]},strut:{tube:"strut",joints:["ballJoint","ballJoint"]}},YK=(e,t)=>e.axles?.[t[0]==="F"?"front":"rear"]??null;function WK(e,t){let r=Of(e.spinAxis),n=ht(e.uprightUpper,e.uprightLower),o=Of(ht(n,jr(r,Wa(n,r)))),a=HK(r,o);a[0]<0&&(a=jr(a,-1));let s=t.discDiameter/2+t.caliperHeight,i=Math.max(0,Math.min(t.discDiameter/2,2*t.effRadius-t.discDiameter/2)),c=t.caliperAngle*Math.PI/180,l=Math.min(Math.PI/2,t.caliperLength/2/Math.max(1,s)),u=(p,d,f)=>Fu(Fu(e.wheelCenter,jr(r,f)),Fu(jr(o,d*Math.cos(p)),jr(a,d*Math.sin(p)))),m=[];for(let p of[t.discOffset-t.caliperWidth/2,t.discOffset+t.caliperWidth/2]){for(let d of[-1,-.5,0,.5,1])m.push(u(c+d*l,s,p));for(let d of[-1,1])m.push(u(c+d*l,i,p))}return m}function jK(e,t){let r=[];return e.mcpherson||r.push(e.uprightUpper),r.push(e.uprightLower,e.tieOuter),(e.mcpherson||t==="upright")&&r.push(e.pushrodOuter),r.filter(n=>n.every(Number.isFinite))}function fL(e,t,r,n,o){let a=[],s=YK(n,t),i=XK(s,e,t,r),c=!!s?.rackHousing&&t[0]==="F";for(let f of SR(e)){if(f.body==="upperArm"&&i.has("upperArm")||f.body==="lowerArm"&&i.has("lowerArm"))continue;let h=e[f.inboard],b=e[f.outboard];if(![...h,...b].every(Number.isFinite))continue;let g=[c&&f.name==="tie rod"?"rack":f.ends[0],f.ends[1]==="rodAttach"?GR[r]:f.ends[1]],y=zK[f.name],x=!s||!y?n.linkRadius:y.tube==="strut"?s.strut:s.tube[y.tube],R=s&&y?[s.housing[y.joints[0]],s.housing[y.joints[1]]]:[n.jointAllowance,n.jointAllowance];a.push({kind:"link",id:`${t} ${f.name}`,name:f.name,corner:t,body:f.body,ends:g,a:h,b,radius:x,housing:R})}let l=s?.damper;if(l&&!e.decoupled&&!e.mcpherson){let f=e.damperChassis,h=e.direct?e.pushrodOuter:e.rockerToDamper,b=e.direct?GR[r]:"rocker";if([...f,...h].every(Number.isFinite)){let g=WP(`${t} damper`,"damper","damper",t,{p:f,body:"chassis",corner:t},{p:h,body:b,corner:t},l,s.housing.rodEnd);a.push(...i.has("damperBody")?g.filter(y=>y.id!==`${t} damper body`):g)}}s?.arb&&o&&a.push(...HP(s.arb,o.def,o.r,t,s)),s?.rackHousing&&t[0]==="F"&&a.push(zP(s.rackHousing,t));let u=s?.driveshaft?YP(s.driveshaft,e,t):null;u&&a.push(u);let m={centre:e.wheelCenter,axis:Of(e.spinAxis)},p=t[0]==="F"?n.tyreRadius.front:n.tyreRadius.rear;a.push({kind:"tyre",id:`${t} tyre`,name:"tyre",corner:t,body:"wheel",centre:e.wheelCenter,axis:e.spinAxis,radius:p,width:n.tyreWidth,section:s?.rim?XP(s.rim,p,n.tyreWidth):null});let d=i.get("wheel");if(d?a.push({kind:"rim",id:`${t} rim`,name:"rim",corner:t,body:"wheel",frame:m,bands:cL(d.live,d.fit.iso,m),model:!0}):s?.rim&&a.push({kind:"rim",id:`${t} rim`,name:"rim",corner:t,body:"wheel",frame:m,bands:qP(s.rim)}),s){let f=jK(e,r);f.length&&!i.has("upright")&&a.push({kind:"hull",id:`${t} upright`,name:"upright",corner:t,body:"upright",points:f,radius:s.uprightWall}),s.brake&&a.push({kind:"hull",id:`${t} caliper`,name:"caliper",corner:t,body:"upright",points:WK(e,s.brake),radius:0})}for(let[f,h]of i)f!=="wheel"&&a.push(ZK(f,h.live,h.fit,e,t,r,n,s));return a}var UK={upright:"upright",upperArm:"upperArm",lowerArm:"lowerArm",rocker:"rocker",damperBody:"damper"};function XK(e,t,r,n){let o=new Map;if(!e?.models)return o;for(let a of OR){let s=e.models[a];if(!s)continue;let i=aL(s,a,t,r,n);sL(i)&&o.set(a,{live:s,fit:i})}return o}var qK=["ucaFront","ucaRear","lcaFront","lcaRear","uprightUpper","uprightLower"];function QK(e,t,r,n){switch(t){case"uprightUpper":return e==="upright"?"upperArm":"upright";case"uprightLower":return e==="upright"?"lowerArm":"upright";case"tieOuter":return"tieRod";case"pushrodOuter":return e==="damperBody"?GR[n]:r.mcpherson?"strut":"rod";case"rockerToPushrod":return"rod";case"rockerToDamper":return e==="rocker"?"damper":"rocker";default:return"chassis"}}function ZK(e,t,r,n,o,a,s,i){let c=BR(n,e,a).map(l=>({key:l,p:n[l],on:QK(e,l,n,a),reach:i?i.housing[qK.includes(l)?"ballJoint":"rodEnd"]:s.jointAllowance}));return{kind:"model",id:`${o} ${VR[e]} model`,name:`${VR[e]} model`,corner:o,body:UK[e],piece:e,tree:t.tree,iso:r.iso,inverse:VP(r.iso),ends:[...new Set(c.map(l=>l.on))],joints:c}}function JK(e,t,r){let n=e.ends[t];if(n==="chassis")return!1;let o=e.endCorners?.[t]??e.corner;return r.body===n&&r.corner===o||r.ends.some((a,s)=>a===n&&(r.endCorners?.[s]??r.corner)===o)}var lL=(e,t)=>(e.body==="rod"||e.body==="dropLink")&&e.ends[1]===t.body&&(e.endCorners?.[1]??e.corner)===t.corner,uL=(e,t)=>e.body==="damper"&&e.ends[1]===t.body;function HR(e,t,r){return e.find(({parts:[n,o]})=>n===t.name&&o===r.name||n===r.name&&o===t.name)}function hL(e,t,r=[]){let n=[],o=(m,p,d,f,h=!1)=>{let b=f?void 0:HR(r,m,p);n.push({a:m,b:p,name:`${m.name} / ${p.name}`,trim:d,skip:b?"ignored":f,...b?{reason:b.reason}:{},...h?{fixed:h}:{}})},a=e.filter(m=>m.kind==="link");for(let m=0;m<a.length;m++)for(let p=m+1;p<a.length;p++){let d=eH(a[m],a[p],r);d&&n.push(d)}let s=e.find(m=>m.kind==="tyre"&&m.section!==null),i=e.find(m=>m.kind==="rim");for(let m of a)s&&o(m,s,[0,0,0,0],null),i&&o(m,i,[0,0,0,0],null);let c=e.filter(m=>m.kind==="hull");for(let m of c)i&&o(m,i,[0,0,0,0],null,!0);let l=c.find(m=>m.name==="caliper");if(l)for(let m of a)o(m,l,[m.ends[0]==="upright"?m.housing[0]:0,m.ends[1]==="upright"?m.housing[1]:0,0,0],null);let u=e.filter(m=>m.kind==="model");for(let m=0;m<u.length;m++){let p=u[m];for(let d of a){let f=tH(p,d,r);f&&n.push(f)}s&&p.body!=="upright"&&o(p,s,[0,0,0,0],null),i&&o(p,i,[0,0,0,0],null,p.body==="upright"),l&&p.body!=="upright"&&o(p,l,[0,0,0,0],null);for(let d=m+1;d<u.length;d++)o(p,u[d],[0,0,0,0],null)}for(let m of t)for(let p of e)p.kind==="tyre"||p.kind==="model"||p.kind==="link"&&!p.shared?o(m,p,[0,0,0,0],null):p.kind==="link"&&p.corner[1]==="L"&&m.kind==="volume"&&o(m,p,[0,0,0,0],null,!0);return n}function eH(e,t,r=[]){if(e.body===t.body&&e.corner===t.corner)return null;let n=(i,c,l)=>JK(i,c,l)?i.housing[c]:0,o=[n(e,0,t),n(e,1,t),n(t,0,e),n(t,1,e)],a=lL(e,t)||lL(t,e)?"rod on arm":uL(e,t)||uL(t,e)?"damper on arm":null,s=a?void 0:HR(r,e,t);return{a:e,b:t,name:`${e.name} / ${t.name}`,trim:o,skip:s?"ignored":a,...s?{reason:s.reason}:{},...e.shared&&t.shared?{fixed:!0}:{}}}function tH(e,t,r=[]){if(t.body===e.body&&t.corner===e.corner)return null;let n=i=>{let c=t.ends[i];return c==="chassis"?0:(t.endCorners?.[i]??t.corner)===e.corner&&(c===e.body||e.ends.includes(c))?t.housing[i]:0},a=(t.body==="rod"||t.body==="dropLink")&&t.ends[1]===e.body&&(t.endCorners?.[1]??t.corner)===e.corner?"rod on arm":t.body==="damper"&&t.ends[1]===e.body?"damper on arm":null,s=a?void 0:HR(r,e,t);return{a:e,b:t,name:`${e.name} / ${t.name}`,trim:[0,0,n(0),n(1)],skip:s?"ignored":a,...s?{reason:s.reason}:{}}}function Cu(e,t,r,n){let o=Tr(ht(t,e));if(o<=r+n){let a=yr(e,t,.5);return[a,a]}return[yr(e,t,r/o),yr(e,t,1-n/o)]}function kn(e,t,r){let n=ht(t,e),o=Tr(n);return o>1e-9?yr(e,t,r/o):e}function mL(e,t,r,n){let o=ht(r,t),a=Tr(o),s=a>1e-12?jr(o,1/a):[1,0,0],i=Wa(ht(e,t),s),c=ht(ht(e,t),jr(s,i)),l=Tr(c),u=Math.max(0,Math.min(a,i)),m=l>n?jr(c,n/l):c,p=Fu(Fu(t,jr(s,u)),m);return{distance:Tr(ht(e,p)),on:p}}function bL(e,t,r,n){let o=ht(t,e),a=ht(n,r),s=ht(e,r),i=Wa(o,o),c=Wa(a,a),l=Wa(a,s),u=b=>Math.max(0,Math.min(1,b));if(i<=1e-12&&c<=1e-12)return{s:0,t:0};if(i<=1e-12)return{s:0,t:u(l/c)};let m=Wa(o,s);if(c<=1e-12)return{s:u(-m/i),t:0};let p=Wa(o,a),d=i*c-p*p,f=d>1e-12?u((p*l-m*c)/d):0,h=(p*f+l)/c;return h<0?(h=0,f=u(-m/i)):h>1&&(h=1,f=u((p-m)/i)),{s:f,t:h}}function rH(e,t,r,n,o){let{s:a,t:s}=bL(r,n,e,t);if(a>1e-9&&a<1-1e-9){let p=yr(r,n,a),d=yr(e,t,s),f=Tr(ht(d,p));if(f>=o)return{distance:f-o,onSeg:d,onCyl:kn(p,d,o)}}let i=p=>mL(yr(e,t,p),r,n,o).distance,l=[0,Tr(ht(t,e))<1e-12?0:$P(i,0,1,1e-7).x,1].reduce((p,d)=>i(d)<i(p)?d:p),u=yr(e,t,l),m=mL(u,r,n,o);return{distance:m.distance,onSeg:u,onCyl:m.on}}function KR(e,t,r){let n=ht(r,t),o=Tr(n);return!e.flat||o<1e-9?{shape:MR(t,r),pad:e.radius}:{shape:wi(yr(t,r,.5),jr(n,1/o),e.radius,o),pad:0}}function dL(e,t,r){let n=KR(e.part,e.p0,e.p1),o="part"in t?KR(t.part,t.p0,t.p1):t,a="part"in t?t.part.radius:t.radius,s=n.pad+o.pad;if(Af(n.shape,o.shape)-s>=r)return null;let i=-(e.part.radius+a);if("part"in t&&e.part.flat!==t.part.flat){let[l,u]=e.part.flat?[t,e]:[e,t],m=rH(l.p0,l.p1,u.p0,u.p1,u.part.radius),[p,d]=e.part.flat?[m.onCyl,m.onSeg]:[m.onSeg,m.onCyl];if(m.distance<=1e-9)return{distance:i,onA:p,onB:d};let f=l.part.radius;return e.part.flat?{distance:m.distance-f,onA:p,onB:kn(d,p,f)}:{distance:m.distance-f,onA:kn(p,d,f),onB:d}}if("part"in t&&e.part.flat&&t.part.flat){let{s:l,t:u}=bL(e.p0,e.p1,t.p0,t.p1),m=p=>p>1e-9&&p<1-1e-9;if(m(l)&&m(u)){let p=yr(e.p0,e.p1,l),d=yr(t.p0,t.p1,u),f=Tr(ht(d,p));if(f>=e.part.radius+t.part.radius)return{distance:f-e.part.radius-t.part.radius,onA:kn(p,d,e.part.radius),onB:kn(d,p,t.part.radius)}}}let c=Fi(n.shape,o.shape,e.part.flat||"part"in t&&t.part.flat?1e-6:1e-9);return c.distance<=0?{distance:i,onA:c.onA,onB:c.onB}:{distance:c.distance-s,onA:kn(c.onA,c.onB,n.pad),onB:kn(c.onB,c.onA,o.pad)}}var nH=["chassis","rack"];function oH(e,t,r,n){let o,a=!1;if(t.kind==="link"){let i=[0,0];for(let m of[0,1])nH.includes(t.ends[m])&&DR(e.tree,m===0?t.a:t.b,r.mountAllowance)&&(i[m]=t.housing[m],a=!0);let[c,l]=Cu(t.a,t.b,i[0],i[1]),u=Tr(ht(l,c));if(!t.flat||u<1e-9){let m=Au(e.tree,c,l,n+t.radius);o=m&&{...m,distance:m.distance-t.radius,onPart:m.distance>1e-9?kn(m.onPart,m.onMesh,t.radius):m.onPart}}else o=_f(e.tree,yr(c,l,.5),ht(l,c),t.radius,u,Math.max(0,n))}else o=_f(e.tree,t.centre,t.axis,t.radius,t.width,Math.max(0,n));if(!o)return null;let s=o.distance<=0;return{distance:s?0:o.distance,onA:o.onMesh,onB:s?o.onMesh:o.onPart,...s?{touches:!0}:{},...a?{mounted:!0}:{}}}function gL(e,t,r=1/0){let{a:n,b:o}=e;if(n.kind==="model"||o.kind==="model")return sH(e,t,r);if(n.kind==="mesh"&&(o.kind==="link"||o.kind==="tyre"))return oH(n,o,t,r);if(n.kind==="link"&&o.kind==="link"){let[a,s]=Cu(n.a,n.b,e.trim[0],e.trim[1]),[i,c]=Cu(o.a,o.b,e.trim[2],e.trim[3]);return dL({part:n,p0:a,p1:s},{part:o,p0:i,p1:c},r)}if(n.kind==="volume"&&(o.kind==="link"||o.kind==="tyre")){let a=kR(n.box.min,n.box.max),s=o.kind==="link"?KR(o,o.a,o.b):null,i=s?s.shape:wi(o.centre,o.axis,o.radius,o.width),c=s?s.pad:0,l=Af(a,i);if(l>0&&l-c>=r)return null;let u=AR(a,i,c);return{distance:u.distance,onA:u.gap.box,onB:u.gap.part}}if(n.kind==="link"&&(o.kind==="rim"||o.kind==="tyre"&&o.section)){let a=o.kind==="rim"?o.bands:o.section,s=o.kind==="rim"?o.frame:{centre:o.centre,axis:o.axis},i=ZP(n.a,n.b,n.radius,a,s);return{distance:i.distance,onA:i.onPart,onB:i.onWheel}}if(n.kind==="hull"&&o.kind==="rim"){let a=JP(n.points,n.radius,o.bands,o.frame);return{distance:a.distance,onA:a.onPart,onB:a.onWheel}}if(n.kind==="link"&&o.kind==="hull"){let[a,s]=Cu(n.a,n.b,e.trim[0],e.trim[1]);return dL({part:n,p0:a,p1:s},{shape:Ha(o.points),pad:o.radius,radius:o.radius},r)}return null}function Ya(e,t,r,n=!1){let o=e<=0;return{distance:o?0:e,onA:t,onB:o?t:r,...o?{touches:!0}:{},...n?{mounted:!0}:{}}}var aH=(e,t)=>e.joints.filter(r=>t.joints.some(n=>n.key===r.key)).map(r=>({c:r.p,r:2*r.reach})),$R=(e,t)=>t.map(r=>({c:Gt(e.inverse,r.c),r:r.r}));function sH(e,t,r){let{a:n,b:o}=e,a=(s,i)=>Gt(s.iso,i);if(n.kind==="model"&&o.kind==="link"){let[s,i]=Cu(o.a,o.b,e.trim[2],e.trim[3]),c=$R(n,[0,1].filter(d=>e.trim[2+d]>0).map(d=>({c:d===0?o.a:o.b,r:e.trim[2+d]+o.radius}))),l=Gt(n.inverse,s),u=Gt(n.inverse,i),m=Tr(ht(u,l));if(!o.flat||m<1e-9){let d=Au(n.tree,l,u,r+o.radius,c);if(!d)return null;let f=d.distance>1e-9?kn(d.onPart,d.onMesh,o.radius):d.onPart;return Ya(d.distance-o.radius,a(n,d.onMesh),a(n,f))}let p=_f(n.tree,yr(l,u,.5),ht(u,l),o.radius,m,Math.max(0,r),c);return p&&Ya(p.distance,a(n,p.onMesh),a(n,p.onPart))}if(n.kind==="model"&&o.kind==="model"){let s=IR(n.tree,o.tree,vu(n.inverse,o.iso),Math.max(0,r),$R(n,aH(n,o)));return s&&Ya(s.distance,a(n,s.onA),a(n,s.onB))}if(n.kind==="model"&&(o.kind==="rim"||o.kind==="tyre"&&o.section)){let s=o.kind==="rim"?o.bands:o.section,i=o.kind==="rim"?o.frame:{centre:o.centre,axis:o.axis},c={centre:Gt(n.inverse,i.centre),axis:wf(n.inverse,Of(i.axis))},l=oL(n.tree,c,s,Math.max(0,r));return l&&Ya(l.distance,a(n,l.onMesh),a(n,l.onPart))}if(n.kind==="model"&&o.kind==="hull"){let s=$R(n,n.joints.filter(l=>l.on==="upright").map(l=>({c:l.p,r:l.reach}))),i=ER(n.tree,Ha(o.points.map(l=>Gt(n.inverse,l))),r+o.radius,s);if(!i)return null;let c=i.distance>1e-9?kn(i.onPart,i.onMesh,o.radius):i.onPart;return Ya(i.distance-o.radius,a(n,i.onMesh),a(n,c))}if(n.kind==="volume"&&o.kind==="model"){let{min:s,max:i}=n.box,c=[];for(let u=0;u<8;u++)c.push(Gt(o.inverse,[u&1?i[0]:s[0],u&2?i[1]:s[1],u&4?i[2]:s[2]]));let l=ER(o.tree,Ha(c),Math.max(0,r));return l&&Ya(l.distance,a(o,l.onPart),a(o,l.onMesh))}if(n.kind==="mesh"&&o.kind==="model"){let s=o.joints.filter(l=>l.on==="chassis"),i=s.some(l=>DR(n.tree,l.p,t.mountAllowance)),c=IR(n.tree,o.tree,o.iso,Math.max(0,r),s.map(l=>({c:l.p,r:2*l.reach})));return c&&Ya(c.distance,c.onA,c.onB,i)}return null}var RL=152,vL={travelSteps:9,rackSteps:5};function cH(e){let t=(r,n)=>{let o=Sr(n,e.kc,r),a=e.kc?.input.corners[r];return a&&a.tyreRate>0&&Number.isFinite(a.tyreRate)?o+Math.max(0,a.staticLoad)/a.tyreRate:o};return{front:t("FL",e.vehicle.front.config.loadedRadius),rear:t("RL",e.vehicle.rear.config.loadedRadius)}}function zR(e,t){let r=qm(t);return{...PP,tyreRadius:cH(e),tyreWidth:r!==null?r*1e3:RL}}var yL={front:["FL","FR"],rear:["RL","RR"]},lH=e=>e.a.kind!=="volume"&&e.a.kind!=="mesh"&&(e.b.kind==="tyre"||e.b.kind==="rim"||e.b.kind==="hull");function uH(e,t,r,n,o){let a=null,s=(i,c)=>{for(let l of hL(fL(i,r,n,o),[])){if(l.skip||!lH(l)||!!l.fixed!==c)continue;let u=gL(l,o,a?.distance??1/0);u&&(!a||u.distance<a.distance)&&(a={distance:u.distance,pair:l.name})}};s(e,!0);for(let i of t)s(i,!1);return a}var xL=(e,t,r)=>r<=1||t===e?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function YR(e,t,r,n,o=vL,a={}){let s=e.vehicle,[i]=yL[t],c=Od(e,i,0,0)?.geometry;if(!c)return null;let l=Sf(s.chassis?.boxes??[],{vehicle:s,kc:e.kc}),u=t==="front"?Ot(s.front.config):0,m=u>0?xL(-u,u,Math.max(3,o.rackSteps|1)):[0],p=xL(Math.min(0,r.min),Math.max(0,r.max),Math.max(2,o.travelSteps)),d=[];for(let R of l.length?yL[t]:[i])for(let v of p)for(let S of m){let A=Od(e,R,v,S)?.geometry;A&&d.push({corner:R,travel:v,rack:S,g:A})}let f=null;if(l.length){for(let R of _P(l,d,zR(e,n)))for(let v of[R.tyre,R.link])v&&(!f||v.distance<f.distance)&&(f={distance:v.distance,part:v.part,boxId:R.boxId});f??={distance:NaN,part:"",boxId:""}}let h=s[t].config,b=d.filter(R=>R.corner===i).map(R=>R.g),g=Mf(c,b,h.pushrodAttach,h.rodType==="pull"?"pullrod":"pushrod"),y=MP({...zR(e,n),jointAllowance:pL},s,{...a,tyres:{front:n,rear:n}}),x=y.axles[t].rim?uH(c,b,i,h.pushrodAttach,y):null;return{chassis:f,wheel:x,...g}}var ja=Math.PI/180,Di={travelSteps:9,heaveSteps:5,rollSteps:4,rackSteps:6},Tu={travelMin:-25,travelMax:25,rollMaxDeg:3,rollAtLimitDeg:2.5};function mH(e){let t=e.params,r=t.cg_height?Ut({...t,surveyedRadiusFront:e.vehicle.front.config.loadedRadius,surveyedRadiusRear:e.vehicle.rear.config.loadedRadius}):null;return{cgHeight:r?r.cgHeight:300,...i0(t),drive:dd(t),...r?{frontMassFrac:r.frontMassFrac}:{}}}function WR(e,t){for(let r=1;r<e.length;r++){let n=3*t(r)+10;for(let o of["cpLeft","cpRight"]){let a=e[r-1][o],s=e[r][o];if(a&&s&&Math.hypot(s[0]-a[0],s[1]-a[1])>n)return r}}return-1}function jR(e,t=Di,r=Tu,n){let o=null,a=(D,I)=>(o||(o={violation:D,reason:I}),null),s=e.vehicle,i=D=>D==="front"?s.front:s.rear,c=null,l=null,u=()=>{if(c)return c;if(n)try{let D=n();if(D)return c=hr(s,D.kc),l=D.cgHeight,c}catch{a(500,"the car could not be stood on its tyre: its rates did not assemble")}return c=hr(s)},m=D=>D==="front"?"FL":"RL",p=D=>{let I=u();if(!I.kc)return;let N=i(D).config.loadedRadius,O=Sr(N,I.kc,m(D));return O===N?void 0:{loadedRadius:O}},d=(D,I)=>-bc(u(),m(D),I),f=new Map,h=new Map,b=new Map,g=new Map,y=new Map,x=new Map,R,v=new Map,S=new Map,A=new Map,C=new Map,F=new Map,T=null,M=()=>{if(T)return T;u();let D=mH(e);return T=l!==null&&Number.isFinite(l)?{...D,cgHeight:l}:D},k,w=()=>{let D=bR(r.travelMin,r.travelMax,s.config.wheelbase),I=2*Math.max(2,t.rollSteps)-1;return Array.from({length:I},(N,O)=>-D+2*D*O/(I-1))},P,L=()=>{if(P!==void 0)return P;let D=Tm(u().ctx.FL,Ot(s.front.config));return P=D?Pm(D):null,P},E=(D,I,N)=>{if(D.has(I))return D.get(I)??null;let O=N();return D.set(I,O),O};return{car:e,density:t,envelope:r,get failure(){return o},axisLength:(D,I)=>{let N=i(D),O=N.hardpoints;return I==="uca"&&N.config.layout==="mcpherson"?NaN:I==="uca"?Le(O.ucaFront,O.ucaRear):Le(O.lcaFront,O.lcaRear)},linkLength:D=>{let I=i(D).hardpoints;return Le(I.tieInner,I.tieOuter)},compliance:D=>E(h,D,()=>lg(i(D))??null),sweep:D=>E(f,D,()=>{let I;try{I=ut(i(D),{travelMin:r.travelMin,travelMax:r.travelMax,steps:t.travelSteps})}catch{return a(500,`the ${D} travel sweep threw`)}if(!I.covered){let O=I.samples.map(U=>U.travel),V=Math.max(...O)-Math.min(...O),H=r.travelMax-r.travelMin;return a(Math.max(0,H-V),`the ${D} linkage reaches only ${V.toFixed(0)} mm of the ${H.toFixed(0)} mm travel range`)}if(I.fold)return a(200,`the ${D} travel(beta) folds \u2014 the suspension goes over centre in range`);let N=I.samples.filter(O=>!O.converged).length;if(N>0)return a(100+10*N,`${N} of ${I.samples.length} ${D} travel solves did not converge`);if(D==="front"&&i("front").config.steerMode==="rack"){let O=L();if(O)return a(O.violation,O.reason)}return I}),rcHeave:D=>E(b,D,()=>{let I=[],N=[],O=Math.max(2,t.heaveSteps);try{for(let H=0;H<O;H++){let U=r.travelMin+(r.travelMax-r.travelMin)*H/(O-1);I.push(U),N.push(Hr(u(),{heave:d(D,U),pitch:0,roll:0,steer:0},D))}}catch{return a(500,`the ${D} roll-centre construction threw in heave`)}let V=WR(N,H=>Math.abs(I[H]-I[H-1]));return V>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[V].toFixed(0)} mm of travel`):{at:I,rc:N}}),rcRoll:D=>E(g,D,()=>{let I=[],N=[],O=Math.max(2,t.rollSteps);try{for(let H=0;H<O;H++){let U=r.rollMaxDeg*H/(O-1);I.push(U),N.push(Hr(u(),{heave:0,pitch:0,roll:U*ja,steer:0},D))}}catch{return a(500,`the ${D} roll-centre construction threw in roll`)}let V=WR(N,H=>Math.abs(N[H].cpLeft?.[0]??0)*Math.abs(I[H]-I[H-1])*ja);return V>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[V].toFixed(1)}\xB0 of roll`):{at:I,rc:N}}),rcPitch:D=>E(y,D,()=>{let I=w(),N=[];try{for(let V of I)N.push(Hr(u(),{heave:0,pitch:-V*ja,roll:0,steer:0},D))}catch{return a(500,`the ${D} roll-centre construction threw in pitch`)}let O=WR(N,V=>Math.abs(I[V]-I[V-1])*ja*s.config.wheelbase);return O>0?a(300,`the ${D} roll-centre construction lands on another branch at ${I[O].toFixed(2)}\xB0 of pitch`):{at:I,rc:N}}),pcHeave:()=>E(x,"heave",()=>{let D=[],I=[],N=Math.max(2,t.heaveSteps);try{for(let O=0;O<N;O++){let V=r.travelMin+(r.travelMax-r.travelMin)*O/(N-1);D.push(V);let H={heave:d("front",V),pitch:0,roll:0,steer:0},U={heave:d("rear",V),pitch:0,roll:0,steer:0},G=u();I.push({left:no(Dt(G,"FL",H),Dt(G,"RL",U)),right:no(Dt(G,"FR",H),Dt(G,"RR",U))})}}catch{return a(500,"the pitch-centre construction threw in heave")}return{at:D,pc:I}}),pcPitch:()=>E(x,"pitch",()=>{let D=w(),I=[];try{for(let N of D){let O={heave:0,pitch:-N*ja,roll:0,steer:0},V=u();I.push({left:no(Dt(V,"FL",O),Dt(V,"RL",O)),right:no(Dt(V,"FR",O),Dt(V,"RR",O))})}}catch{return a(500,"the pitch-centre construction threw in pitch")}return{at:D,pc:I}}),cg:()=>{if(R!==void 0)return R;let D=M();if(D.frontMassFrac===void 0||!Number.isFinite(D.frontMassFrac))return R=null;let I=s.config,N=xf({wheelbase:I.wheelbase,frontAxleX:I.frontAxleX,frontMassFrac:D.frontMassFrac,cgHeight:D.cgHeight});return R={...N,z:Yr(D.cgHeight,N.x,u())}},roadUnder:D=>{let I=v.get(D);return I===void 0&&(I=Yr(0,Ue(m(D),s.config).axleX,u()),v.set(D,I)),I},steer:()=>{if(k!==void 0)return k;try{k=zb(u(),{steerMax:Ot(s.front.config),steps:t.rackSteps})}catch{k=a(500,"the steering sweep threw")}let D=k?.filter(I=>!I.converged).length??0;if(k&&D>0){let I=L();k=I?a(I.violation,I.reason):a(100+10*D,`${D} of ${k.length} steering solves did not converge`)}return k??null},solveAt:(D,I,N=0)=>E(S,`${D}:${I}:${N}`,()=>{try{let O=Ce(u().ctx[m(D)],I,N,void 0,p(D));return O.ok?O.state:O.why==="unconverged"?a(100,`the ${D} corner did not solve at ${I.toFixed(0)} mm of travel`):a(100+Math.abs(O.travelMiss),`the ${D} corner reaches only ${(I+O.travelMiss).toFixed(0)} of ${I.toFixed(0)} mm of travel`)}catch{return a(150,`the ${D} corner solve threw at ${I.toFixed(0)} mm of travel`)}}),readout:D=>E(C,`${D.heave}:${D.pitch}:${D.roll}:${D.steer}`,()=>{try{return gR(u(),D,M())}catch{return a(500,"the derived readout threw")}}),readoutAtTravel:(D,I)=>E(F,`${D}:${I}`,()=>{try{return yu(u(),{heave:d(D,I),pitch:0,roll:0,steer:0},D,M())}catch{return a(500,`the ${D} readout threw at ${I.toFixed(0)} mm of travel`)}}),travelAtRoll:(D,I)=>{let N=i(D).hardpoints.wheelCenter[1]*Math.sin(I*ja),O=u();if(!O.kc)return N;try{let V=Zt(O,{heave:0,pitch:0,roll:I*ja,steer:0}),H=D==="front"?Math.max(V.FL.travel,V.FR.travel):Math.max(V.RL.travel,V.RR.travel);return Number.isFinite(H)?H:N}catch{return a(500,`the ${D} axle could not be rolled on its tyre`),N}},onTyre:()=>!!u().kc,contexts:u,keepOuts:D=>E(A,D,()=>{try{let I=e.params,N=D==="front"?I.tireModel:I.tireModelRear??I.tireModel,O={min:r.travelMin,max:r.travelMax},V={brakes:I.brakeModel,dampers:{front:I.damperModel,rear:I.damperModelRear??I.damperModel},drive:kP(dd(I))};return YR(u(),D,O,N,void 0,V)??a(100,`the ${D} corner did not solve at its design ride`)}catch{return a(500,`the ${D} keep-outs threw`)}})}}var dH=sx();function UR(e,t={}){let r=new Map;return{session(n){if(r.has(n))return r.get(n);let o=null,a=t.session?.();if(t.sessionParams&&a)try{let s=Ip(n,a.rulesets),i=s?.events.some(c=>c.kind==="trackLap");if(s&&(a.track||!i)){let c=t.sessionParams(e),{standingStart:l,lapCounts:u}=a.settings,m=a.track?eu([c],a.track,a.numerics,Xl(s),a.settings,dH)[0]:$l(c,s,{numerics:a.numerics,standingStart:l,lapCounts:u});o={};for(let p of s.metrics)qu(p)&&(o[p.key]=p.value(m,void 0))}}catch{o=null}return r.set(n,o),o}}}var Vf=.01;function pH(e,t){return t.bump!==null&&e>t.bump-Vf?{at:"closed",past:Math.max(0,e-t.bump)}:t.droopStated&&e<t.droop+Vf?{at:"toppedOut",past:Math.max(0,t.droop-e)}:t.seat!==null&&e<t.seat+Vf?{at:"unseated",past:Math.max(0,t.seat-e)}:{at:"free",past:0}}var kL=e=>({droop:e.droop,droopStated:e.droopStated,bump:e.bump,seat:e.holdsLoad&&Number.isFinite(e.free)?e.free:null}),fH=[["front","FL","FR"],["rear","RL","RR"]];function qR(e,t){let r=[];for(let[n,o,a]of fH){let s=[t[o],t[a]];for(let m of[o,a]){let p=e.curve[m],d=p.spring?.law;if(!p.spring||!d)continue;let f=Ab(p,t[m]);f===null||!Number.isFinite(f)||r.push(XR(m,n,n,f,p.spring.length0-f,kL(d),!0))}let i=e.elements?.[n];if(!i)continue;let c=i.heave?.law;if(c){let m=Qk(i,s),p=i.read.heave?.span0,d=n==="front"?"heaveFront":"heaveRear";r.push(XR(d,d,n,m,p!==void 0?p-m:null,kL(c),i.carriesLoad))}let l=i.rollStop,u=l?Zk(i,s):null;if(l&&u!==null){let m=l.length0-u,p=n==="front"?"rollFront":"rollRear",d={droop:l.droop??-1/0,droopStated:l.droop!==null,bump:l.bump,seat:null};r.push(XR(p,p,n,m,u,d,i.carriesLoad))}}return r}function XR(e,t,r,n,o,a,s){return{damper:e,place:t,axle:r,length:o,compression:n,toToppedOut:a.droopStated?n-a.droop:null,toClosed:a.bump!==null?a.bump-n:null,...pH(n,a),bumpStated:a.bump!==null,bounds:s}}var AL=Math.PI/180;function QR(e,t,r,n){let o=t.speedKmh/3.6,a=ib(e,o,t.axG,ho(e,t.ayG,0));if(!a||!e.aero)return null;let s=e.wheelbase,i=ys(e.aero,s),c=(h,b)=>Math.atan((b-h)/s)/AL,l={},u={};for(let h of en)l[h]=r.corners[h].travel,u[h]=r.corners[h].ground;let m=n.kc?qR(n.kc,l):[],p=e.aero.model,d=a.downFront+a.downRear,f=p?{balance:Math.abs(d)>1e-9?100*a.downFront/d:NaN,clA:(a.clFront+a.clRear)*a.area,cdA:a.cd*a.area,loopMargin:1-a.gain,dataMargin:wL(p,s,a.hFront,a.hRear)}:null;return{front:{height:a.hFront,...ML(m,"front")},rear:{height:a.hRear,...ML(m,"rear")},rakeDeg:c(a.hFront,a.hRear),pitchDeg:c(a.hFront,a.hRear)-c(i.hFront,i.hRear),rollDeg:Math.abs(r.rollDeg),aero:f,clearance:hH(n,u)}}function ML(e,t){let r=e.filter(o=>o.axle===t&&o.bounds),n=o=>{let a=o.filter(s=>s!==null&&Number.isFinite(s));return a.length?Math.min(...a):null};return{toBump:n(r.map(o=>o.toClosed)),toDroop:n(r.map(o=>o.toToppedOut))}}function wL(e,t,r,n){let o=(a,[s,i])=>Math.min(a-s,i-a);if(Yv(e)){let{x:a,y:s}=fs(e),i=[a[0],a[a.length-1]],c=[s[0],s[s.length-1]];return po(e)?SL(e.frame,t,i,c,r,n):Math.min(o(r,i),o(n,c))}return tm(e)?SL(e.frame,t,e.range.h,e.range.pitch,r,n):Math.min(o(r,e.range.hFront),o(n,e.range.hRear))}function SL(e,t,r,n,o,a){let s=hs(e,t,o,a),i=l=>t*Math.tan(l*AL),c=a-o;return Math.min(s.h-r[0],r[1]-s.h,c-i(n[0]),i(n[1])-c)}function hH(e,t){let r=e.vehicle.chassis?.boxes;if(!r?.length)return null;let n={vehicle:e.vehicle,kc:e.kc},o=e.vehicle.config,a=o.frontAxleX,s=o.frontAxleX-o.wheelbase,i=cr(e.vehicle,!0)/2,c=cr(e.vehicle,!1)/2,l={FL:[a,-i],FR:[a,i],RL:[s,-c],RR:[s,c]},u=[[0,0,0],[0,0,0],[0,0,0]],m=[0,0,0];for(let b of en){let g=[1,l[b][0],l[b][1]];for(let y=0;y<3;y++){m[y]+=g[y]*t[b];for(let x=0;x<3;x++)u[y][x]+=g[y]*g[x]}}let p=IP(u,m);if(!p)return null;let d=LP(n),f={z0:d.z0+p[0],dzdx:d.dzdx+p[1],dzdy:d.dzdy+p[2]},h=null;for(let b of Sf(r,n)){let g=EP(b,f);(!h||g.height<h.height)&&(h={height:g.height,volume:b.name})}return h}function Bf(e){return e.aeroModel?null:"The car runs on aero constants, which do not move with the platform; attach an aero model in Aerodynamics"}var bH={front:"front",rear:"rear",heaveFront:"front",heaveRear:"rear",rollFront:"front",rollRear:"rear"};function Pu(e,t,r,n){let o=Yd(e,t);return Nd.some(s=>{if(bH[s]!==r)return!1;let i=o[s].coilover,c=i?.extended!==void 0&&i.extended>0;return n==="droop"?c:c&&i?.stroke!==void 0&&i.stroke>0})?null:n==="droop"?`No ${r} damper states its extended length; state it on its part in Dampers, or under Elements \u203A Stops`:`No ${r} damper states its stroke; state its extended length and stroke on its part in Dampers, or under Elements \u203A Stops`}function ZR(e){return e.chassis?.boxes.length?null:"This suspension has no mockup volumes to measure the ground from; draw one under Kinematics \u203A Chassis"}var $f=Math.PI/180,Gf=1e-6;function CL(e,t){let r=e.length;if(r===0)return 0;if(0<=e[0])return t[0];if(0>=e[r-1])return t[r-1];let n=0;for(;e[n+1]<0;)n++;let o=(0-e[n])/(e[n+1]-e[n]);return t[n]+o*(t[n+1]-t[n])}function Lu(e){let t=e.measured;if(t)return CL(t.travel,t.camber);let r=ee(e.config.spinAxis);return-Math.asin(Math.max(-1,Math.min(1,r[2])))/$f}function Du(e){let t=e.measured;if(t)return CL(t.travel,t.toe);let[r,n]=e.config.spinAxis;return Math.atan2(r,n)/$f}function JR(e,t){let r=Math.abs(t.camber)>=Gf,n=Math.abs(t.toe)>=Gf;if(!r&&!n)return e;let o=e.measured;if(o)return{...e,measured:{...o,...r?{camber:o.camber.map(d=>d+t.camber)}:{},...n?{toe:o.toe.map(d=>d+t.toe)}:{}}};let[a,s]=e.config.spinAxis,i=Math.hypot(a,s);if(!(i>0))return e;let c=(Lu(e)+t.camber)*$f,l=(Du(e)+t.toe)*$f,[u,m]=n?[Math.sin(l),Math.cos(l)]:[a/i,s/i],p=[u*Math.cos(c),m*Math.cos(c),-Math.sin(c)];return{...e,config:{...e.config,spinAxis:p}}}function Kf(e){let t=e&&typeof e=="object"?e.value:void 0;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function gH(e,t){let r=t;return{front:Kf(r.camber_front_deg)??Lu(e.front),rear:Kf(r.camber_rear_deg)??Lu(e.rear)}}function yH(e,t){let r=t;return{front:Kf(r.toe_front_deg)??Du(e.front),rear:Kf(r.toe_rear_deg)??Du(e.rear)}}function xH(e){return{camber:{front:Lu(e.front),rear:Lu(e.rear)},toe:{front:Du(e.front),rear:Du(e.rear)}}}var FL=new WeakMap;function RH(e,t){let r=xH(e),n={front:{camber:t.camber.front-r.camber.front,toe:t.toe.front-r.toe.front},rear:{camber:t.camber.rear-r.camber.rear,toe:t.toe.rear-r.toe.rear}},o=u=>Math.abs(u.camber)<Gf&&Math.abs(u.toe)<Gf;if(o(n.front)&&o(n.rear))return e;let a=`${t.camber.front}|${t.camber.rear}|${t.toe.front}|${t.toe.rear}`,s=FL.get(e),i=s?.get(a);if(i)return i;let c=e.corners?Object.fromEntries(Object.entries(e.corners).map(([u,m])=>[u,m&&JR(m,n[vs(u)])])):void 0,l={...e,front:JR(e.front,n.front),rear:JR(e.rear,n.rear),...c?{corners:c}:{}};return s||FL.set(e,s=new Map),s.size>=16&&s.clear(),s.set(a,l),l}function Ei(e,t){return t?RH(e,{camber:gH(e,t),toe:yH(e,t)}):e}var vH=9.81;function Ii(e){let t=Xo(e),r=Math.max(0,e.unsprungPerCorner)*vH,n=a=>{let s=a==="FL"||a==="FR",i=s?"front":"rear",c=xt(e,i),l=c>0?c:1/0,u=Gh(e,i);return{staticLoad:t[a],springLoad:Math.max(0,t[a]-r),tyreRate:l,arbRate:s?e.arbFront:e.arbRear,heaveRate:(s?e.heaveSpringFront:e.heaveSpringRear)??0,...u>0?{staticLoadedRadius:wr(u,t[a],l,u)}:{}}},o={};for(let[a,s,i,c,l,u]of[["front",e.elementLinkagesFront,!!e.decoupledFront,e.heaveCoiloverFront,e.heaveSeatFront,e.rollCoiloverFront],["rear",e.elementLinkagesRear,!!e.decoupledRear,e.heaveCoiloverRear,e.heaveSeatRear,e.rollCoiloverRear]]){let m=!i&&!!l&&(l.gap>0||!l.bothWays);(s?.heave||s?.roll||i||m)&&(o[a]={...s,carriesLoad:i,...c?{coilover:c}:{},...l&&!i?{heaveSeat:l}:{},...u?{rollCoilover:u}:{}})}return{corners:{FL:n("FL"),FR:n("FR"),RL:n("RL"),RR:n("RR")},...o.front||o.rear?{elements:o}:{},...e.cornerCoiloverFront||e.cornerCoiloverRear?{cornerCoilover:{...e.cornerCoiloverFront?{front:e.cornerCoiloverFront}:{},...e.cornerCoiloverRear?{rear:e.cornerCoiloverRear}:{}}}:{}}}var TL=new WeakMap;function kH(e){let t=Ei(e.vehicle,e.params);if(t===e.vehicle)return e;let r=TL.get(e);return(!r||r.vehicle!==t)&&TL.set(e,r={...e,vehicle:t}),r}function Eo(e,t={}){let r=kH(e),n=rR(r,t),o=t.assemble?()=>{let m=n.dynInput();if(!m)throw new Error("the car did not assemble");return{kc:Ii(m),cgHeight:m.cgHeight}}:void 0,a=jR(r,t.density,t.envelope,o),s=cR(r,n,t),i=UR(r,t),c=t.states??[],l=new Map;return{...a,...n,...s,...i,get failure(){return a.failure},values:new Map,states:c,stateOf:m=>m===void 0?c[0]??null:c.find(p=>p.id===m)??null,platformAt:m=>{let p=`${m.speedKmh}|${m.ayG}|${m.axG}`,d=l.get(p);if(d!==void 0)return d;let f=n.poseAt(m),h=n.dynInput(),b=null;if(f&&h)try{b=QR(h,m,f,a.contexts())}catch{b=null}return l.set(p,b),b}}}var MH=["x","y","z"],SH=/^(line|plane)\((-?\d+),(-?\d+)\)([uv]?)$/,PL=Math.PI/18e3,LL=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],DL=(e,t)=>[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]],AH=e=>Math.hypot(e[0],e[1],e[2]),e1=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];function t1(e){let t=AH(e);return t>1e-9?e1(e,1/t):null}function wH(e,t){let r=e*PL,n=t*PL;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}function Pr(e){let t=e.lastIndexOf(".");if(t<0)return null;let r=SH.exec(e.slice(t+1));if(!r)return null;let n=r[1];return n==="line"!=(r[4]==="")?null:{point:e.slice(0,t),shape:{kind:n,dir:wH(Number(r[2]),Number(r[3]))},coord:n==="line"?"along":r[4]}}function EL(e){let t=t1(DL([0,0,1],e))??[1,0,0];(t[0]<-1e-9||Math.abs(t[0])<=1e-9&&t[1]<0)&&(t=e1(t,-1));let r=t1(DL(e,t))??[0,1,0];return(r[2]<-1e-9||Math.abs(r[2])<=1e-9&&r[1]<0)&&(r=e1(r,-1)),[t,r]}function r1(e){if(e.coord==="along")return e.shape.dir;let[t,r]=EL(e.shape.dir);return e.coord==="u"?t:r}function IL(e,t){let r=Pr(t);if(!r)return;let n=MH.map(u=>e[`${r.point}.${u}`]);if(n.some(u=>!u))return;let o=r1(r),a=[0,1,2].filter(u=>Math.abs(o[u])>1e-12),s=u=>n.map(m=>m.read(u)),i=n[0],c=a.map(u=>n[u].supersededBy).find(Boolean),l=i.label.replace(/ x$/,"");return{id:t,group:i.group,label:r.coord==="along"?`${l} along its line`:`${l} in its plane, ${r.coord}`,...i.scope?{scope:i.scope}:{},unit:i.unit,defaultSpan:i.defaultSpan,read:u=>LL(s(u),o),write:(u,m)=>{let p=s(u),d=m-LL(p,o),f=u;for(let h of a)f=n[h].write(f,p[h]+d*o[h]);return f},...c?{supersededBy:c}:{}}}var _i=["x","y","z"];var FH=/^(?:hp\.(?:front|rear)\.\w+|(?:heave|roll|rollBar)\.(?:front|rear)\.(?:outer|inner|anchor))$/;function Ua(e){let t=e.lastIndexOf("."),r=e.slice(0,t);if(t<0||!FH.test(r))return null;let n=e.slice(t+1);if(n==="x"||n==="y"||n==="z")return{point:r,axis:n};let o=Pr(e);return o?{point:r,axis:o.coord}:null}var Eu="*";function n1(e){let t={sum:"summed",min:"lowest",max:"highest",distance:"by length",harmonic:"overall"};return e?.across?`all courses, ${t[e.across]}`:"all courses"}var o1=e=>e?.reads==="speed"||e?.reads==="operating",a1=e=>e?.reads==="lateral"||e?.reads==="operating";function Xa(e){if(!e)return"";let t=[];return e.speed!==void 0&&Number.isFinite(e.speed)&&t.push(`v${e.speed}`),e.ayG!==void 0&&Number.isFinite(e.ayG)&&t.push(`a${e.ayG}`),e.courseId&&t.push(`c${e.courseId}`),e.stateId&&t.push(`s${e.stateId}`),t.join(",")}function Hf(e,t){return e?.appliesAt?t.find(r=>!e.appliesAt(r)):t[0]}function Ni(e,t,r){let n=r?.stateId?e.stateOf(r.stateId):Hf(t,e.states)??null;return n&&!t.appliesAt?.(n)?n:null}function vt(e,t,r){let n=`${t.id}@${Xa(r)}`,o=e.values.get(n);if(o!==void 0)return o;let a;try{a=r?.courseId===Eu&&t.reads==="course"?CH(e,t,r):r?.stateId===Rn&&t.reads==="state"?TH(e,t,r):t.read(e,r)}catch{a=NaN}return e.values.set(n,a),a}function CH(e,t,r){if(!t.across)return NaN;let n=e.courses();if(!n.length)return NaN;let o=n.map(s=>{let i={...r,courseId:s.id};return{v:vt(e,t,i),length:e.course(i)?.track.length??NaN}});if(o.some(s=>!Number.isFinite(s.v)))return NaN;if(t.across==="sum")return o.reduce((s,i)=>s+i.v,0);if(t.across==="min")return Math.min(...o.map(s=>s.v));if(t.across==="max")return Math.max(...o.map(s=>s.v));let a=o.reduce((s,i)=>s+i.length,0);return a>0?t.across==="harmonic"?a/o.reduce((s,i)=>s+i.length/i.v,0):o.reduce((s,i)=>s+i.v*i.length,0)/a:NaN}function TH(e,t,r){let n=t.appliesAt?e.states.filter(i=>!t.appliesAt(i)):e.states;if(!t.acrossStates||!n.length)return NaN;let o=n.map(i=>({v:vt(e,t,{...r,stateId:i.id}),w:i.weight,s:i})),a=t.appliesAt?o.filter(i=>Number.isFinite(i.v)||!e.poseAt(i.s)):o;if(!a.length||a.some(i=>!Number.isFinite(i.v)))return NaN;if(t.acrossStates==="max")return Math.max(...a.map(i=>i.v));if(t.acrossStates==="min")return Math.min(...a.map(i=>i.v));if(t.acrossStates==="span")return Math.max(...a.map(i=>i.v))-Math.min(...a.map(i=>i.v));let s=a.reduce((i,c)=>i+c.w,0);return s>0?a.reduce((i,c)=>i+c.v*c.w,0)/s:NaN}function s1(e){let t={mean:"weighted mean",max:"highest",min:"lowest",span:"span"};return e?.acrossStates?`every state, ${t[e.acrossStates]}`:"every state"}function bt(e){return`${e.quantity??e.groupShort??e.group} \xB7 ${e.label}`}var PH={front:"Front",rear:"Rear"},qa={heave:0,pitch:0,roll:0,steer:0},_L="RC height (chassis) [mm]";function NL(e,t){let r=0,n=0;for(let o=1;o<e.length;o++){let a=e[o]-e[o-1];if(Math.abs(a)<1e-9)continue;let s=(t[o]-t[o-1])/a;r+=s*s,n++}return n?Math.sqrt(r/n):NaN}function HL(e,t){let r=0;for(let n=1;n<e.length;n++){let o=e[n]-e[n-1];Math.abs(o)<1e-9||(r=Math.max(r,Math.abs((t[n]-t[n-1])/o)))}return r}var Mn=e=>e.length?Math.max(...e)-Math.min(...e):NaN;function i1(e){let t=(e??[]).filter(Number.isFinite);if(!t.length)return NaN;let r=t.reduce((n,o)=>n+o,0)/t.length;return Math.abs(r)>0?(Math.max(...t)-Math.min(...t))/Math.abs(r):NaN}function OL(e,t){if(!e.length)return;let r=0;for(let n=1;n<e.length;n++)Math.abs(e[n])<Math.abs(e[r])&&(r=n);return t[r]}function Vi(e,t,r){let n=e.stateOf(t?.stateId),o=n?e.poseAt(n):null;return o?r(o):NaN}var Iu=(e,t)=>`${e==="front"?"F":"R"}${t}`,VL=e=>e==="L"?"R":"L";function BL(e){let t=PH[e],r=M=>`kin.${e}.${M}`,n=(M,k)=>{let w=M.sweep(e);return w?{x:w.samples.map(P=>P.travel),y:w.samples.map(k)}:{x:[],y:[]}},o=M=>e==="front"?M.vehicle.front:M.vehicle.rear,a=M=>M.params[e==="front"?"heaveFrontDesign":"heaveRearDesign"],s=M=>M.params[e==="front"?"arbFrontDesign":"arbRearDesign"],i=e==="front"?"the front axle":"the rear axle";function c(M){return o(M).config.actuation==="decoupled"?`${i} is decoupled, with no corner damper \u2014 read its heave and roll elements`:null}function l(M){let k=a(M);return k&&k.design.kind!=="none"?null:`${i} has no heave element`}function u(M){let k=a(M);return k?.design.kind==="coil"&&k.linkage?null:`${i} has no heave element on a linkage`}function m(M){let k=s(M);return k&&k.design.kind!=="none"?null:`${i} has no roll element`}function p(M){let k=s(M);return k?.linkage&&k.design.kind!=="none"&&k.design.kind!=="direct"?null:`${i} has no roll element on a linkage`}let d=M=>{if(u(M.car))return null;let k=M.sweep(e);return k?Tb(o(M.car),a(M.car).linkage,k.samples):null},f=M=>Rl(M.vehicle,M.params,e);function h(M){return f(M)?null:un(o(M))?ha(s(M))?`${i}\u2019s roll element is itself a bar`:`${i} has no anti-roll bar beside its roll element`:`${i} is not decoupled: its anti-roll bar is its roll element`}function b(M){let k=f(M);return k?k.linkage&&k.design.kind!=="direct"?null:`${i}\u2019s anti-roll bar is stated at the wheel, on no linkage`:h(M)}let g=(M,k)=>{let w=M.sweep(e);if(!w)return null;let P=wb(o(M.car),k.linkage,k.design.kind,w.samples),L=P.atDesign<0?-1:1;return{travel:P.travel,ratio:P.ratio.map(E=>E*L),atDesign:P.atDesign*L}},y=M=>p(M.car)?null:g(M,s(M.car)),x=M=>b(M.car)?null:g(M,f(M.car)),R=M=>M.readout(qa)?.[e],v=M=>M.readoutAtTravel(e,M.envelope.travelMax),S=M=>{let k=n(M,w=>w.metrics.camber);return k.x.length?{key:r("camberGain"),title:`${t} camber vs travel`,xLabel:"travel [mm]",yLabel:"camber [\xB0]",...k}:null},A=M=>{let k=n(M,w=>w.metrics.toe);return k.x.length?{key:r("bumpSteer"),title:`${t} toe vs travel`,xLabel:"travel [mm]",yLabel:"toe [\xB0]",...k}:null},C=[{id:r("rcStatic"),group:`${t} roll centre`,label:"static height",unit:"mm",scale:30,scope:e,cost:"cheap",read:M=>M.rcRoll(e)?.rc[0]?.heightAboveGround??NaN},{id:r("rcHeaveWorst"),group:`${t} roll centre`,label:"worst migration vs travel",unit:"mm/mm",scale:.5,scope:e,cost:"cheap",read:M=>{let k=M.rcHeave(e);return k?HL(k.at,k.rc.map(w=>w.height)):NaN},curve:M=>{let k=M.rcHeave(e);return k?{key:r("rcHeaveWorst"),title:`${t} roll-centre height vs wheel travel`,xLabel:"travel [mm]",yLabel:_L,x:k.at,y:k.rc.map(w=>w.height-M.roadUnder(e))}:null}},{id:r("rcRollSpan"),group:`${t} roll centre`,label:"height span over the roll envelope",unit:"mm",scale:15,scope:e,cost:"cheap",read:M=>{let k=M.rcRoll(e);return k?Mn(k.rc.map(w=>w.height)):NaN},curve:M=>{let k=M.rcRoll(e);return k?{key:r("rcRollSpan"),title:`${t} roll-centre height vs body roll`,xLabel:"roll [\xB0]",yLabel:_L,x:k.at,y:k.rc.map(w=>w.height-M.roadUnder(e))}:null}},{id:r("rcLateralSpan"),group:`${t} roll centre`,label:"lateral migration over roll",unit:"mm",scale:50,scope:e,cost:"cheap",read:M=>{let k=M.rcRoll(e);return k?Mn(k.rc.map(w=>w.lateral)):NaN},curve:M=>{let k=M.rcRoll(e);return k?{key:r("rcLateralSpan"),title:`${t} roll-centre lateral position vs body roll`,xLabel:"roll [\xB0]",yLabel:"RC lateral [mm]",x:k.at,y:k.rc.map(w=>w.lateral)}:null}},{id:r("minSinAngle"),group:`${t} roll centre`,label:"construction conditioning (min sinAngle)",unit:"-",scale:.04,scope:e,cost:"cheap",read:M=>{let k=M.rcHeave(e),w=M.rcRoll(e);return!k||!w?NaN:Math.min(...k.rc.map(P=>P.sinAngle),...w.rc.map(P=>P.sinAngle))},curve:M=>{let k=M.rcHeave(e);return k?{key:r("minSinAngle"),title:`${t} construction conditioning vs travel`,xLabel:"travel [mm]",yLabel:"sinAngle",x:k.at,y:k.rc.map(w=>w.sinAngle)}:null}},{id:r("fvsaLength"),group:`${t} roll centre`,label:"front-view swing-arm length",unit:"mm",scale:500,scope:e,cost:"readout",read:M=>R(M)?.fvsaLength??NaN},{id:r("complianceSteer"),group:`${t} compliance`,label:"compliance steer",unit:"\xB0/kN lateral",scale:.05,scope:e,cost:"readout",read:M=>(M.compliance(e)?.toePerFy??0)*1e3},{id:r("complianceCamber"),group:`${t} compliance`,label:"compliance camber",unit:"\xB0/kN lateral",scale:.05,scope:e,cost:"readout",read:M=>(M.compliance(e)?.camberPerFy??0)*1e3},{id:r("complianceSteerLong"),group:`${t} compliance`,label:"compliance steer under braking",unit:"\xB0/kN longitudinal",scale:.05,scope:e,cost:"readout",read:M=>(M.compliance(e)?.toePerFx??0)*1e3},{id:r("steeringCompliance"),group:`${t} compliance`,label:"steer given back under aligning torque",unit:"\xB0/100 N\xB7m",scale:.2,scope:e,cost:"readout",read:M=>(M.compliance(e)?.toePerMz??0)*1e5},{id:r("staticCamber"),group:`${t} camber & toe`,label:"static camber",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:M=>{let k=M.solveAt(e,0);return k?k.metrics.camber:NaN}},{id:r("staticToe"),group:`${t} camber & toe`,label:"static toe",unit:"\xB0",scale:.5,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.toe??NaN},{id:r("camberGainDesign"),group:`${t} camber & toe`,label:"camber gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:M=>R(M)?.camberGain??NaN,curve:M=>S(M)},{id:r("rollCamber"),group:`${t} camber & toe`,label:"camber gain in roll",unit:"\xB0/\xB0",scale:.2,scope:e,cost:"readout",read:M=>R(M)?.rollCamber??NaN},{id:r("rollCamberRecovery"),group:`${t} camber & toe`,label:"camber recovery in roll",unit:"%",scale:20,scope:e,cost:"readout",read:M=>R(M)?.camberRecovery??NaN},{id:r("bumpSteerDesign"),group:`${t} camber & toe`,label:"bump steer at design",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:M=>R(M)?.bumpSteer??NaN,curve:M=>A(M)},{id:r("rollSteer"),group:`${t} camber & toe`,label:"roll steer",unit:"\xB0/\xB0",scale:.1,scope:e,cost:"readout",read:M=>R(M)?.rollSteer??NaN},{id:r("bumpSteer"),group:`${t} camber & toe`,label:"bump steer, RMS over the travel",unit:"\xB0/mm",scale:.02,scope:e,cost:"cheap",read:M=>{let k=n(M,w=>w.metrics.toe);return k.x.length?NL(k.x,k.y):NaN},curve:M=>A(M)},{id:r("camberGain"),group:`${t} camber & toe`,label:"camber gain, RMS over the travel",unit:"\xB0/mm",scale:.02,scope:e,cost:"cheap",read:M=>{let k=n(M,w=>w.metrics.camber);return k.x.length?NL(k.x,k.y):NaN},curve:M=>S(M)},{id:r("camberSpan"),group:`${t} camber & toe`,label:"camber range over travel",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:M=>Mn(n(M,k=>k.metrics.camber).y)},{id:r("toeSpan"),group:`${t} camber & toe`,label:"toe range over travel",unit:"\xB0",scale:.5,scope:e,cost:"cheap",read:M=>Mn(n(M,k=>k.metrics.toe).y)},{id:r("camberRecovery"),group:`${t} camber & toe`,label:"outer camber at limit roll",unit:"\xB0",scale:2,scope:e,cost:"cheap",read:M=>{let k=M.solveAt(e,M.travelAtRoll(e,M.envelope.rollAtLimitDeg)),w=M.solveAt(e,0);return!k||!w?NaN:Math.abs(k.metrics.camber-w.metrics.camber+M.envelope.rollAtLimitDeg)}},{id:r("stateCamberOuter"),group:`${t} camber & toe`,label:"outer camber to the road at a state",unit:"\xB0",scale:1,scope:e,cost:"cheap",reads:"state",acrossStates:"mean",read:(M,k)=>Vi(M,k,w=>w.camber[Iu(e,w.outer)])},{id:r("stateCamberInner"),group:`${t} camber & toe`,label:"inner camber to the road at a state",unit:"\xB0",scale:1,scope:e,cost:"cheap",reads:"state",acrossStates:"mean",read:(M,k)=>Vi(M,k,w=>w.camber[Iu(e,VL(w.outer))])},{id:r("stateToeOuter"),group:`${t} camber & toe`,label:"outer toe change at a state",unit:"\xB0",scale:.2,scope:e,cost:"cheap",reads:"state",acrossStates:"mean",read:(M,k)=>Vi(M,k,w=>w.corners[Iu(e,w.outer)].bumpToe)},{id:r("caster"),group:`${t} upright`,label:"caster",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.caster??NaN},{id:r("kpi"),group:`${t} upright`,label:"kingpin inclination",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.kpi??NaN},{id:r("scrubRadius"),group:`${t} upright`,label:"scrub radius",unit:"mm",scale:20,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.scrubRadius??NaN},{id:r("mechanicalTrail"),group:`${t} upright`,label:"mechanical trail",unit:"mm",scale:20,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.mechanicalTrail??NaN},{id:r("kingpinOffset"),group:`${t} upright`,label:"kingpin offset at hub height",unit:"mm",scale:20,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.kingpinOffset??NaN},{id:r("casterOffset"),group:`${t} upright`,label:"caster offset at hub height",unit:"mm",scale:10,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.casterOffset??NaN},{id:r("steeringArm"),group:`${t} upright`,label:"steering arm",unit:"mm",scale:20,scope:e,cost:"cheap",read:M=>M.solveAt(e,0)?.metrics.steeringArm??NaN},{id:r("casterGain"),group:`${t} upright`,label:"caster gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:M=>R(M)?.casterGain??NaN},{id:r("kpiGain"),group:`${t} upright`,label:"kingpin inclination gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:M=>R(M)?.kpiGain??NaN},{id:r("scrubGain"),group:`${t} upright`,label:"scrub radius gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:M=>R(M)?.scrubGain??NaN},{id:r("trailGain"),group:`${t} upright`,label:"mechanical trail gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:M=>R(M)?.trailGain??NaN},{id:r("motionRatio"),group:`${t} rates`,label:"motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:c,read:M=>{if(c(M.car))return NaN;let k=M.sweep(e);return k?OL(k.samples.map(w=>w.travel),k.samples.map(w=>w.metrics.motionRatio??NaN))??NaN:NaN},curve:M=>{if(c(M.car))return null;let k=n(M,w=>w.metrics.motionRatio??NaN);return k.x.length?{key:r("motionRatio"),title:`${t} motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",...k}:null}},{id:r("mrSpread"),group:`${t} rates`,label:"motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:c,read:M=>{if(c(M.car))return NaN;let k=M.sweep(e);if(!k)return NaN;let w=k.samples.map(L=>L.metrics.motionRatio??NaN).filter(Number.isFinite);if(!w.length)return NaN;let P=w.reduce((L,E)=>L+E,0)/w.length;return P>0?(Math.max(...w)-Math.min(...w))/P:NaN}},{id:r("wheelRate"),group:`${t} rates`,label:"wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:c,read:M=>{if(c(M.car))return NaN;let k=M.sweep(e);return k?OL(k.samples.map(w=>w.travel),k.samples.map(w=>w.metrics.wheelRate??NaN))??NaN:NaN}},{id:r("heaveMotionRatio"),group:`${t} rates`,label:"heave element motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:u,read:M=>d(M)?.atDesign??NaN,curve:M=>{let k=d(M);return k?{key:r("heaveMotionRatio"),title:`${t} heave element motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:k.travel,y:k.ratio}:null}},{id:r("heaveMrSpread"),group:`${t} rates`,label:"heave element motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:u,read:M=>i1(d(M)?.ratio)},{id:r("heaveWheelRate"),group:`${t} rates`,label:"heave element wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:l,read:M=>l(M.car)||!M.sweep(e)?NaN:ba(M.car.vehicle,M.car.params)[e]??NaN},{id:r("rollMotionRatio"),group:`${t} rates`,label:"roll element motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:p,read:M=>y(M)?.atDesign??NaN,curve:M=>{let k=y(M);return k?{key:r("rollMotionRatio"),title:`${t} roll element motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:k.travel,y:k.ratio}:null}},{id:r("rollMrSpread"),group:`${t} rates`,label:"roll element motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:p,read:M=>i1(y(M)?.ratio)},{id:r("rollWheelRate"),group:`${t} rates`,label:"roll element wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:m,read:M=>m(M.car)||!M.sweep(e)?NaN:vl(M.car.vehicle,M.car.params)[e].element??NaN},{id:r("rollBarMotionRatio"),group:`${t} rates`,label:"anti-roll bar motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:b,read:M=>x(M)?.atDesign??NaN,curve:M=>{let k=x(M);return k?{key:r("rollBarMotionRatio"),title:`${t} anti-roll bar motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:k.travel,y:k.ratio}:null}},{id:r("rollBarMrSpread"),group:`${t} rates`,label:"anti-roll bar motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:b,read:M=>i1(x(M)?.ratio)},{id:r("rollBarWheelRate"),group:`${t} rates`,label:"anti-roll bar wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:h,read:M=>h(M.car)||!M.sweep(e)?NaN:vl(M.car.vehicle,M.car.params)[e].bar??NaN},{id:r("ucaAxisLength"),group:`${t} package`,label:"upper arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:M=>M.axisLength(e,"uca")},{id:r("lcaAxisLength"),group:`${t} package`,label:"lower arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:M=>M.axisLength(e,"lca")},{id:r("linkLength"),group:`${t} package`,label:"tie/toe link length",unit:"mm",scale:100,scope:e,cost:"geometry",read:M=>M.linkLength(e)},{id:r("trackScrubRate"),group:`${t} package`,label:"track scrub rate",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:M=>M.readout(qa)?.[e].trackScrubRate??NaN},{id:r("trackChange"),group:`${t} package`,label:"track change at full bump",unit:"mm",scale:2,scope:e,cost:"readout",read:M=>v(M)?.trackChange??NaN},{id:r("stateTravelOuter"),group:`${t} package`,label:"outer wheel travel at a state",unit:"mm",scale:10,scope:e,cost:"cheap",reads:"state",acrossStates:"max",read:(M,k)=>Vi(M,k,w=>w.corners[Iu(e,w.outer)].travel)},{id:r("stateTravelInner"),group:`${t} package`,label:"inner wheel travel at a state",unit:"mm",scale:10,scope:e,cost:"cheap",reads:"state",acrossStates:"min",read:(M,k)=>Vi(M,k,w=>w.corners[Iu(e,VL(w.outer))].travel)},{id:r("damperStroke"),group:`${t} package`,label:"damper stroke over the travel",unit:"mm",scale:20,scope:e,cost:"cheap",unavailable:c,read:M=>c(M.car)?NaN:Mn(n(M,k=>k.metrics.damperLength).y),curve:M=>{if(c(M.car))return null;let k=n(M,w=>w.metrics.damperLength);return k.x.length?{key:r("damperStroke"),title:`${t} damper length vs travel`,xLabel:"travel [mm]",yLabel:"length [mm]",...k}:null}}];e==="front"&&C.push({id:r("camberPerSteer"),group:`${t} camber & toe`,label:"camber change with steer",unit:"\xB0/\xB0",scale:.05,scope:"front",cost:"readout",read:M=>R(M)?.camberPerSteer??NaN},{id:r("steerJacking"),group:`${t} upright`,label:"corner rise per degree of steer",unit:"mm/\xB0",scale:.05,scope:"front",cost:"readout",read:M=>R(M)?.steerJacking??NaN}),e==="front"?C.push({id:r("antiDive"),group:`${t} anti geometry`,label:"anti-dive",unit:"%",scale:20,scope:"front",cost:"readout",read:M=>M.readout(qa)?.front.antiDive??NaN}):C.push({id:r("antiSquat"),group:`${t} anti geometry`,label:"anti-squat (driving)",unit:"%",scale:20,scope:"rear",cost:"readout",read:M=>M.readout(qa)?.rear.antiSquat??NaN},{id:r("antiLift"),group:`${t} anti geometry`,label:"anti-lift (braking)",unit:"%",scale:20,scope:"rear",cost:"readout",read:M=>M.readout(qa)?.rear.antiLift??NaN});let F=M=>{let k=M.slice(t.length+1);return k.charAt(0).toUpperCase()+k.slice(1)};return[...new Set(C.map(M=>M.group))].flatMap(M=>C.filter(k=>k.group===M)).map(M=>({...M,quantity:`${t} \xB7 ${F(M.group)}`}))}function $L(e,t){let r=e.steer();if(!r)return NaN;let n=r.filter(a=>Number.isFinite(a.ackermannPct)&&a.inner>.3&&a.outer>.3);return n.length?n.reduce((a,s)=>t==="centre"?s.inner<a.inner?s:a:s.inner>a.inner?s:a).ackermannPct:NaN}var LH=[{id:"kin.front.ackermannCentre",group:"Steering",label:"Ackermann near centre",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>$L(e,"centre"),curve:e=>{let t=e.steer();if(!t)return null;let r=t.filter(n=>Number.isFinite(n.ackermannPct)&&n.inner>.3&&n.outer>.3);return r.length?{key:"kin.front.ackermann",title:"Ackermann vs steer",xLabel:"inner wheel steer [\xB0]",yLabel:"Ackermann [%]",x:r.map(n=>n.inner),y:r.map(n=>n.ackermannPct)}:null}},{id:"kin.front.ackermannLock",group:"Steering",label:"Ackermann at lock",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>$L(e,"lock")},{id:"kin.front.lockInner",group:"Steering",label:"inner wheel angle at full rack",unit:"\xB0",scale:5,scope:"front",cost:"cheap",read:e=>{let t=e.steer();return t?.length?Math.max(...t.map(r=>r.inner)):NaN}}],DH=[{id:"kin.car.trackFront",group:"Whole car",label:"front track",unit:"mm",scale:50,scope:"front",cost:"geometry",read:e=>2*e.car.vehicle.front.hardpoints.wheelCenter[1]},{id:"kin.car.trackRear",group:"Whole car",label:"rear track",unit:"mm",scale:50,scope:"rear",cost:"geometry",read:e=>2*e.car.vehicle.rear.hardpoints.wheelCenter[1]},{id:"kin.car.stateRoll",group:"Whole car",label:"body roll at a state",unit:"\xB0",scale:1,scope:"car",cost:"cheap",reads:"state",acrossStates:"max",read:(e,t)=>Vi(e,t,r=>Math.abs(r.rollDeg))},{id:"kin.car.wheelbaseChange",group:"Whole car",label:"wheelbase change at full bump",unit:"mm",scale:2,scope:"car",cost:"readout",read:e=>{let t=e.readoutAtTravel("front",e.envelope.travelMax),r=e.readoutAtTravel("rear",e.envelope.travelMax);return t&&r?t.longitudinal-r.longitudinal:NaN}}],Oi=(e,t)=>e.left.valid&&e.right.valid?(t(e.left)+t(e.right))/2:NaN,c1=(e,t)=>{let r=e.readout(qa)?.axes?.pitch;return r?.valid?t(r):NaN},GL=(e,t)=>{let r=e.readout(qa)?.axes?.roll;return r?.usable?t(r):NaN},EH=e=>(e.roadUnder("front")+e.roadUnder("rear"))/2;function KL(e){let t=e.rcRoll("front"),r=e.rcRoll("rear"),n=e.cg();if(!t||!r||!n)return null;let o=e.car.vehicle.config,a=t.rc.map((s,i)=>uP({front:s,rear:r.rc[i]},n,o.frontAxleX,o.wheelbase,()=>!0).arm);return{at:t.at,arm:a}}var IH="PC height (chassis) [mm]",_H=[{id:"kin.car.pcHeight",group:"Pitch axis",label:"pitch-centre height at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>c1(e,t=>t.heightAboveGround)},{id:"kin.car.pcAhead",group:"Pitch axis",label:"pitch centre ahead of the CG at design",unit:"mm",scale:300,scope:"car",cost:"readout",read:e=>c1(e,t=>t.ahead)},{id:"kin.car.pitchArm",group:"Pitch axis",label:"pitch arm at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>c1(e,t=>t.arm)},{id:"kin.car.pcHeaveWorst",group:"Pitch axis",label:"worst height migration vs travel",unit:"mm/mm",scale:.5,scope:"car",cost:"cheap",read:e=>{let t=e.pcHeave();return t?HL(t.at,t.pc.map(r=>Oi(r,n=>n.height))):NaN},curve:e=>{let t=e.pcHeave();if(!t)return null;let r=EH(e);return{key:"kin.car.pcHeaveWorst",title:"Pitch-centre height vs wheel travel",xLabel:"travel [mm]",yLabel:IH,x:t.at,y:t.pc.map(n=>Oi(n,o=>o.height)-r)}}},{id:"kin.car.pcPitchSpan",group:"Pitch axis",label:"height span over the pitch envelope",unit:"mm",scale:15,scope:"car",cost:"cheap",read:e=>{let t=e.pcPitch();return t?Mn(t.pc.map(r=>Oi(r,n=>n.heightAboveGround))):NaN},curve:e=>{let t=e.pcPitch();return t?{key:"kin.car.pcPitchSpan",title:"Pitch-centre height vs body pitch",xLabel:"pitch [\xB0, + nose down]",yLabel:"PC height above road [mm]",x:t.at,y:t.pc.map(r=>Oi(r,n=>n.heightAboveGround))}:null}},{id:"kin.car.pcAheadSpan",group:"Pitch axis",label:"fore-aft migration over the pitch envelope",unit:"mm",scale:300,scope:"car",cost:"cheap",read:e=>{let t=e.pcPitch();return t?Mn(t.pc.map(r=>Oi(r,n=>n.x))):NaN},curve:e=>{let t=e.pcPitch(),r=e.cg();return!t||!r?null:{key:"kin.car.pcAheadSpan",title:"Pitch centre ahead of the CG vs body pitch",xLabel:"pitch [\xB0, + nose down]",yLabel:"PC ahead of CG [mm]",x:t.at,y:t.pc.map(n=>Oi(n,o=>o.x)-r.x)}}},{id:"kin.car.pcMinSinAngle",group:"Pitch axis",label:"construction conditioning (min sinAngle)",unit:"-",scale:.01,scope:"car",cost:"cheap",read:e=>{let t=e.pcHeave(),r=e.pcPitch();return!t||!r?NaN:Math.min(...[...t.pc,...r.pc].map(n=>Math.min(n.left.sinAngle,n.right.sinAngle)))}},{id:"kin.car.rollArm",group:"Roll axis",label:"roll arm at design",unit:"mm",scale:30,scope:"car",cost:"readout",read:e=>GL(e,t=>t.arm)},{id:"kin.car.rollAxisSlope",group:"Roll axis",label:"slope at design (+ rising rearward)",unit:"\xB0",scale:.5,scope:"car",cost:"readout",read:e=>GL(e,t=>t.slope)},{id:"kin.car.rollArmSpan",group:"Roll axis",label:"roll-arm span over the roll envelope",unit:"mm",scale:15,scope:"car",cost:"cheap",read:e=>{let t=KL(e);return t?Mn(t.arm):NaN},curve:e=>{let t=KL(e);return t?{key:"kin.car.rollArmSpan",title:"Roll arm vs body roll",xLabel:"roll [\xB0]",yLabel:"roll arm [mm]",x:t.at,y:t.arm}:null}}],l1=[...BL("front"),...BL("rear"),...LH,...DH,..._H];var NH={front:"Front",rear:"Rear"};function WL(e){return e.chassis?.boxes.length?null:"This suspension has no mockup volumes to keep its parts out of; draw one under Kinematics \u203A Chassis"}function OH(e,t,r){let n=r==="front"?t.tireModel:t.tireModelRear??t.tireModel;return xR(e.parts?.[r],n)?null:`The ${r} axle states no rim, so its tyre and rim are not measured; state one under Kinematics \u203A Linkage \u203A Wheel`}function zL(e,t,r){let n=e.parts?.[t]?.jointLimits?.[r];return RR(n)?n:void 0}function YL(e){let t=NH[e],r=s=>`kin.${e}.${s}`,n=e==="front"?"over the travel and the rack":"over the travel",o=(s,i)=>{let c=s.keepOuts(e);return c?i(c)??NaN:NaN},a={group:`${t} keep-outs`,quantity:`${t} \xB7 Keep-outs`,scope:e,cost:"readout"};return[{...a,id:r("chassisClearance"),label:`least clearance to the chassis volumes ${n}`,unit:"mm",scale:5,unavailable:s=>WL(s.vehicle),read:s=>o(s,i=>i.chassis?.distance)},{...a,id:r("wheelClearance"),label:`least clearance inside the wheel ${n}`,unit:"mm",scale:5,unavailable:s=>OH(s.vehicle,s.params,e),read:s=>o(s,i=>i.wheel?.distance)},{...a,id:r("ballJointAngle"),label:`largest ball-joint angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.ballJoint?.angle),statedLimit:s=>zL(s.vehicle,e,"ballJoint")},{...a,id:r("rodEndAngle"),label:`largest rod-end angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.rodEnd?.angle),statedLimit:s=>zL(s.vehicle,e,"rodEnd")}]}var u1=[...YL("front"),...YL("rear")];var QL={front:"Front",rear:"Rear"},jL=e=>$a("side",e),VH=e=>$a("drive",e)&&$a("brake",e)?"neither brakes nor drives":null;function BH(e,t,r,n){let o=Ni(e,t,r),a=o?e.tyreAt(o):null;return a?n(a):NaN}function Bi(e,t){let r={...e,read:(n,o)=>BH(n,r,o,t)};return r}var UL=e=>e?100*e.lossCamber:NaN,XL=e=>e&&!e.lifted?e.camber-e.wants:NaN;function qL(e){let t=QL[e],r=s=>`tyre.${e}.${s}`,n={group:`${t} tyre`,quantity:`${t} \xB7 Tyre`,scope:e,cost:"cheap",reads:"state",acrossStates:"mean"},o={...n,appliesAt:jL,unavailable:s=>lf(s.params,e)},a=[Bi({...o,id:r("camberErrorOuter"),label:"camber error at the outer wheel",unit:"\xB0",scale:.5},s=>XL(s.side(e)?.wheels[0])),Bi({...o,id:r("camberErrorInner"),label:"camber error at the inner wheel",unit:"\xB0",scale:.5},s=>XL(s.side(e)?.wheels[1])),Bi({...o,id:r("sideLossCamber"),label:"side grip lost to camber",unit:"%",scale:1},s=>UL(s.side(e))),Bi({...n,appliesAt:jL,id:r("sideLossToe"),label:"side grip lost to the toe split",unit:"%",scale:1},s=>100*s.toeLoss(e)),Bi({...n,appliesAt:VH,unavailable:s=>Jx(s.params,e),id:r("longLossCamber"),label:"drive and brake grip lost to camber",unit:"%",scale:1},s=>UL(s.long(e)))];return e==="front"&&a.push(Bi({...n,appliesAt:s=>$a("ackermann",s),id:r("ackermannError"),label:"Ackermann against the tyre",unit:"%",scale:25},s=>s.ackermann())),a}var m1=[...qL("front"),...qL("rear")],$H=/^tyre\.(front|rear)\.(camberErrorOuter|camberErrorInner|sideLossCamber|longLossCamber)$/;function d1(e,t){let r=new Map,n=a=>a.name.charAt(0).toLowerCase()+a.name.slice(1),o=a=>`${a>0?"+":a<0?"\u2212":""}${Math.abs(a).toFixed(1)}\xB0`;for(let{m:a,at:s}of t){let i=$H.exec(a.id);if(!i)continue;let c=i[1],l=i[2]==="longLossCamber",u=s?.stateId==="*"?e.states.filter(m=>!a.appliesAt?.(m)):[Ni(e,a,s)].filter(m=>!!m);for(let m of u){let p=`${c}|${m.id}|${l}`;if(r.has(p))continue;let d=e.tyreAt(m),f=d?l?d.long(c):d.side(c):null;if(!f)continue;let{lo:h,hi:b,stated:g}=f.range,y=g?`the ${o(h)} \u2026 ${o(b)} its data covers`:`the \xB1${b.toFixed(0)}\xB0 read without a stated range`,x=A=>l?A===0?"left":"right":A===0?"outer":"inner",R=f.wheels.findIndex(A=>A.atEdge),v=f.wheels.findIndex(A=>A.outside&&!A.lifted),S=[];R>=0&&S.push(`the ${QL[c].toLowerCase()} ${x(R)} tyre wants ${o(f.wheels[R].wants)}, the edge of ${y}, and may want more`),v>=0&&S.push(`the ${x(v)} wheel has ${o(f.wheels[v].camber)}, past it, and is read at ${o(f.wheels[v].read)}`),S.length&&r.set(p,`In the ${n(m)} ${S.join("; ")}.`)}}return[...r.values()]}function p1(e,t){let r=e.appliesAt?.(t);return r?`is read at ${t.name}, which ${r}`:null}var GH={front:"Front",rear:"Rear"};function KH(e,t,r,n){let o=Ni(e,t,r),a=o?e.platformAt(o):null;return(a?n(a):null)??NaN}function Lr(e,t){let r={...e,read:(n,o)=>KH(n,r,o,t)};return r}var f1={cost:"cheap",reads:"state"},HH={unavailable:e=>Bf(e.params)};function ZL(e){let t=GH[e],r=o=>`platform.${e}.${o}`,n={...f1,group:`${t} platform`,quantity:`${t} \xB7 Platform`,scope:e};return[Lr({...n,id:r("rideHeight"),label:"ride height at a state",unit:"mm",scale:5,acrossStates:"min"},o=>o[e].height),Lr({...n,id:r("toBumpStop"),label:"travel left to the bump stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>Pu(o.vehicle,o.params,e,"bump")},o=>o[e].toBump),Lr({...n,id:r("toDroopStop"),label:"travel left to the droop stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>Pu(o.vehicle,o.params,e,"droop")},o=>o[e].toDroop)]}var zf={...f1,group:"Platform",scope:"car"},_u={...f1,...HH,group:"Aero platform",groupShort:"Aero",scope:"car"},h1=[...ZL("front"),...ZL("rear"),Lr({...zf,id:"platform.rake",label:"rake at a state",unit:"\xB0",scale:.2,acrossStates:"span"},e=>e.rakeDeg),Lr({...zf,id:"platform.pitch",label:"pitch at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.pitchDeg),Lr({...zf,id:"platform.roll",label:"body roll at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.rollDeg),Lr({...zf,id:"platform.groundClearance",label:"ground clearance at a state",unit:"mm",scale:5,acrossStates:"min",unavailable:e=>ZR(e.vehicle)},e=>e.clearance?.height),Lr({..._u,id:"platform.balance",label:"balance at a state",unit:"%",scale:1,acrossStates:"span"},e=>e.aero?.balance),Lr({..._u,id:"platform.clA",label:"downforce Cl\xB7A at a state",unit:"m\xB2",scale:.1,acrossStates:"mean"},e=>e.aero?.clA),Lr({..._u,id:"platform.cdA",label:"drag Cd\xB7A at a state",unit:"m\xB2",scale:.05,acrossStates:"mean"},e=>e.aero?.cdA),Lr({..._u,id:"platform.dataMargin",label:"margin to the model\u2019s data",unit:"mm",scale:5,acrossStates:"min"},e=>e.aero?.dataMargin),Lr({..._u,id:"platform.loopMargin",label:"aero-elastic margin, 1 \u2212 loop gain",unit:"-",scale:.1,acrossStates:"min"},e=>e.aero?.loopMargin)];var JL={understeer:"operating",yawFreq:"speed",yawZeta:"speed",yawStiffness:"operating",steeringTorque:"operating",steeringTorqueGradient:"operating"};function kt(e,t,r,n="cheap"){let o=My[e];if(!o)throw new Error(`no DYN_METRIC "${e}"`);return{id:`dyn.${e}`,group:t,label:o.label,unit:o.unit,scale:r,scope:"car",cost:n,...JL[e]?{reads:JL[e]}:{},read:(a,s)=>{let i=a.dynInput(),c=a.dynCtx(s);return i&&c?o.compute(i,c):NaN}}}function eD(e,t){let r=e.dynInput();if(!r)return null;let n=t("front"),o=t("rear");if(!n||!o||n.rc.length!==o.rc.length)return null;let a=e.roadUnder("front"),s=e.roadUnder("rear"),i=n.rc.map((c,l)=>{let u=ri(c),m=ri(o.rc[l]);if(!u||!m)return NaN;let p=RM(r,u.height-a,m.height-s);return 100*vM(r,{rcFront:u.heightAboveGround,rcRear:m.heightAboveGround,arm:p})});return{at:n.at,share:i}}function b1(e,t,r,n,o){let a=`dyn.${e}`;return{id:a,group:"Handling \u2014 balance",label:t,unit:"%",scale:1,scope:"car",cost:"cheap",read:s=>{let i=eD(s,o(s));return i?Mn(i.share):NaN},curve:s=>{let i=eD(s,o(s));return i?{key:a,title:r,xLabel:n,yLabel:"TLLTD front [%]",x:i.at,y:i.share}:null}}}var zH=[kt("understeer","Handling \u2014 balance",.1),kt("tlltdFront","Handling \u2014 balance",5),b1("tlltdHeaveSpan","TLLTD span over the travel","TLLTD vs wheel travel","travel [mm]",e=>t=>e.rcHeave(t)),b1("tlltdPitchSpan","TLLTD span over the pitch envelope","TLLTD vs body pitch","pitch [\xB0, + nose down]",e=>t=>e.rcPitch(t)),b1("tlltdRollSpan","TLLTD span over the roll envelope","TLLTD vs body roll","roll [\xB0]",e=>t=>e.rcRoll(t)),kt("rollStiffFront","Handling \u2014 balance",5)],YH=[kt("yawFreq","Handling \u2014 response",.5),kt("yawZeta","Handling \u2014 response",.2),kt("stabilitySpeed","Handling \u2014 response",50),kt("yawStiffness","Handling \u2014 response",2e4,"trim")],WH=[kt("steeringTorque","Steering feel",1,"trim"),kt("steeringTorqueGradient","Steering feel",2,"trim")],jH=[kt("rollGradient","Ride & body",.5),kt("pitchGradient","Ride & body",.5),kt("rideFreqFront","Ride & body",.5),kt("rideFreqRear","Ride & body",.5),kt("rollFreqNoDampers","Ride & body",.5),kt("pitchFreqNoDampers","Ride & body",.5),kt("rollFreq","Ride & body",.5),kt("pitchFreq","Ride & body",.5),kt("zetaFront","Ride & body",.2),kt("zetaRear","Ride & body",.2)],UH=[{id:"dyn.reserveStabil",group:"What the car has left",label:"Yaw stability reserve",unit:"N\xB7m",scale:200,scope:"car",cost:"trim",reads:"operating",read:(e,t)=>e.reserves("operating",t)?.stabil??NaN},{id:"dyn.reserveAgil",group:"What the car has left",label:"Yaw agility reserve",unit:"N\xB7m",scale:200,scope:"car",cost:"trim",reads:"operating",read:(e,t)=>e.reserves("operating",t)?.agil??NaN},{id:"dyn.limitBalance",group:"What the car has left",label:"Limit balance (+US / \u2212OS)",unit:"-",scale:.5,scope:"car",cost:"trim",reads:"speed",read:(e,t)=>e.reserves("limit",t)?.rel??NaN}],XH=[{id:"dyn.ymdMaxAy",group:"Yaw-moment diagram",label:"Max lateral acceleration",unit:"g",scale:.2,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymd(t)?.maxAy??NaN},{id:"dyn.ymdStability",group:"Yaw-moment diagram",label:"Stability \u2202CN/\u2202\u03B2 at the origin",unit:"1/rad",scale:5,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymd(t)?.stability??NaN},{id:"dyn.ymdControl",group:"Yaw-moment diagram",label:"Control \u2202CN/\u2202\u03B4 at the origin",unit:"1/rad",scale:.5,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymd(t)?.control??NaN},{id:"dyn.trimAy",group:"Yaw-moment diagram",label:"Trim limit \u2014 the fastest corner it can hold",unit:"g",scale:.2,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.ay??NaN},{id:"dyn.trimBeta",group:"Yaw-moment diagram",label:"Body slip at the trim limit",unit:"\xB0",scale:2,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.betaDeg??NaN},{id:"dyn.trimDelta",group:"Yaw-moment diagram",label:"Steer at the trim limit",unit:"\xB0",scale:2,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.deltaDeg??NaN},{id:"dyn.trimControlFrac",group:"Yaw-moment diagram",label:"Control left at the trim limit",unit:"-",scale:.25,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.controlFrac??NaN},{id:"dyn.trimStiffnessFrac",group:"Yaw-moment diagram",label:"Yaw stiffness left at the trim limit",unit:"-",scale:.25,scope:"car",cost:"diagram",reads:"speed",read:(e,t)=>e.ymdLimit(t)?.stiffnessFrac??NaN}],g1=[...zH,...YH,...WH,...jH,...UH,...XH];function qH(e,t){let r=e.lap(t),n=e.course(t);if(!r||!n)return NaN;let o=n.track.ds,a=0,s=0;for(let i=0;i<r.v.length-1;i++){let c=o[i]??0,l=.5*(r.v[i]+r.v[i+1]);c>0&&l>0&&(a+=c,s+=c/l)}return s>0?a/s:NaN}var y1=[{id:"lap.time",group:"Lap & manoeuvre",label:"Time",unit:"s",scale:.1,scope:"car",cost:"lap",reads:"course",across:"sum",read:(e,t)=>e.lap(t)?.laptime??NaN},{id:"lap.vMean",group:"Lap & manoeuvre",label:"Mean speed",unit:"km/h",scale:2,scope:"car",cost:"lap",reads:"course",across:"harmonic",read:(e,t)=>qH(e,t)*3.6},{id:"lap.vMin",group:"Lap & manoeuvre",label:"Minimum speed",unit:"km/h",scale:2,scope:"car",cost:"lap",reads:"course",across:"min",read:(e,t)=>{let r=e.lap(t);return r?Math.min(...r.v)*3.6:NaN}},{id:"lap.vMax",group:"Lap & manoeuvre",label:"Maximum speed",unit:"km/h",scale:5,scope:"car",cost:"lap",reads:"course",across:"max",read:(e,t)=>{let r=e.lap(t);return r?Math.max(...r.v)*3.6:NaN}},{id:"lap.ayPeak",group:"Lap & manoeuvre",label:"Peak lateral acceleration",unit:"g",scale:.1,scope:"car",cost:"lap",reads:"course",across:"max",read:(e,t)=>{let r=e.lap(t);return r?Math.max(...r.ay.map(Math.abs))/9.81:NaN}},{id:"lap.minStabil",group:"What the car had left",label:"Worst stability reserve",unit:"N\xB7m",scale:50,scope:"car",cost:"lap",reads:"course",across:"min",read:(e,t)=>e.lapReserve(t)?.minStabil??NaN},{id:"lap.understeerFrac",group:"What the car had left",label:"Lap fraction front-limited",unit:"-",scale:.1,scope:"car",cost:"lap",reads:"course",across:"distance",read:(e,t)=>e.lapReserve(t)?.understeerFrac??NaN},{id:"lap.beyondFrac",group:"What the car had left",label:"Beyond the tyre ellipse \u2014 a health warning, not a target",unit:"-",scale:.05,scope:"car",cost:"lap",reads:"course",across:"distance",read:(e,t)=>e.lapReserve(t)?.beyondFrac??NaN}];function QH(e,t){let r=/^(.*?)\s*\(([^)]+)\)\s*$/.exec(e);return r?{label:r[1],unit:r[2]}:{label:e,unit:t?"s":""}}function ZH(e){return e==="s"||e==="kWh"?.1:e==="km/h"?2:1}var tD=new WeakMap;function Yf(e){let t=tD.get(e);return t||(t=e.metrics.filter(qu).map(r=>{let{label:n,unit:o}=QH(r.label,r.format==="time");return{id:`event.${e.id}.${r.key}`,group:`Events \xB7 ${e.label}`,groupShort:"Events",label:n,unit:o,scale:ZH(o),scope:"car",cost:"session",read:a=>a.session(e.id)?.[r.key]??NaN}}),tD.set(e,t),t)}var x1=yi.flatMap(Yf);var Wf=[...l1,...u1,...m1,...h1,...g1,...y1,...x1],$i=Object.fromEntries(Wf.map(e=>[e.id,e]));var rD={all:Wf,byId:$i},nD=new WeakMap;function xr(e=[]){if(e.length===0)return rD;let t=nD.get(e);if(t)return t;let r=qy(e).filter(n=>!xi(n.id)).flatMap(Yf);return t=r.length?{all:[...Wf,...r],byId:{...$i,...Object.fromEntries(r.map(n=>[n.id,n]))}}:rD,nD.set(e,t),t}var e4=9.81;function jf(e,t=e.tireModel,r=e.tireModelRear){if(!t)return e;e=t4(e,t,r);let n=e.m.value*e4/4,o=Ra(e,t,r),a=We(o.front).rollingRadius(n),s=o.rear===o.front?a:We(o.rear).rollingRadius(n),i=r4(e,a,s);if(!(i>0))return e;let c={...e.r_dyn,value:i};return{...e,r_dyn:c,readouts:{...e.readouts,r_dyn:"the fitted tyre\u2019s rolling radius at the static load"}}}function t4(e,t,r){let n=Ra(e,t,r),o=We(n.front).verticalStiffness(),a=n.rear===n.front?o:We(n.rear).verticalStiffness();if(!(o>0&&a>0))return e;let s=o===a?"the fitted tyre\u2019s own vertical rate":`the fitted tyres\u2019 own vertical rates: front ${oD(o)}, rear ${oD(a)} N/mm`;return{...e,...e.tire_vertical_rate?{tire_vertical_rate:{...e.tire_vertical_rate,value:o}}:{},readouts:{...e.readouts,tire_vertical_rate:s}}}var oD=e=>Math.round(e*10)/10;function r4(e,t,r){switch(e.motorPlacement??"rear"){case"front":return t;case"awd":return t>0&&r>0?.5*(t+r):0;default:return r}}var Nu=180/Math.PI,Gi=Math.PI/180,n4=.2;function Uf(e,t){let r=$(t,e);return ee(r[0]<0?lb(r):r)}var Xf=e=>({side:Math.atan2(e[2],e[0])*Nu,plan:Math.atan2(e[1],e[0])*Nu}),qf=(e,t)=>ee([1,Math.tan(t*Gi),Math.tan(e*Gi)]),Ou=e=>Math.abs(e[0])>=n4,Qf=(e,t)=>Math.atan(t/Math.max(e,1))*Nu,Zf=(e,t)=>Math.tan(t*Gi)*Math.max(e,1);var Io=["side","plan","clock","len"],Rr={uca:{fore:"ucaFront",aft:"ucaRear",ball:"uprightUpper"},lca:{fore:"lcaFront",aft:"lcaRear",ball:"uprightLower"}},Vu={uca:"upper arm",lca:"lower arm"},o4=1,aD=(e,t)=>Uf(e[Rr[t].fore],e[Rr[t].aft]);function sD(e){let t=ee($(cb,Q(e,Z(cb,e))));return{e1:t,e2:me(e,t)}}function R1(e,t){let r=aD(e,t);if(!Ou(r))return`the ${Vu[t]}'s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it`;let n=Rr[t],o=Ln(e[n.ball],e[n.fore],r);return Math.hypot(...$(o,e[n.ball]))>=o4?null:`the ${Vu[t]}'s ball joint sits on its own pivot axis, so the arm has no length to swing on`}function so(e,t){let r=Rr[t],n=e[r.ball],o=aD(e,t),a=Ln(n,e[r.fore],o),s=$(a,n),i=Math.hypot(s[0],s[1],s[2]),{e1:c,e2:l}=sD(o),u=i>0?Q(s,1/i):c;return{...Xf(o),clock:Math.atan2(Z(u,l),Z(u,c))*Nu,len:i,sFront:Z($(e[r.fore],a),o),sRear:Z($(e[r.aft],a),o)}}function v1(e,t){let r=qf(e.side,e.plan),{e1:n,e2:o}=sD(r),a=ne(Q(n,Math.cos(e.clock*Gi)),Q(o,Math.sin(e.clock*Gi))),s=ne(t,Q(a,e.len));return{fore:ne(s,Q(r,e.sFront)),aft:ne(s,Q(r,e.sRear))}}function iD(e,t,r,n){let o=Rr[t],a={...so(e,t),[r]:n},{fore:s,aft:i}=v1(a,e[o.ball]);return{...e,[o.fore]:s,[o.aft]:i}}function cD(e,t){return t==="clock"?e.len:Math.abs(e.sFront-e.sRear)/2}function Jf(e,t,r){return t==="len"?r:Qf(cD(e,t),r)}function k1(e,t,r){return t==="len"?r:Zf(cD(e,t),r)}var Qa=["side","plan","atY","atZ"],Sn={fore:"rockerPivotA",aft:"rockerPivotB"},a4=5,lD=e=>Uf(e.rockerPivotA,e.rockerPivotB);function Ki(e){return Math.hypot(...$(e.rockerPivotB,e.rockerPivotA))<a4?"the rocker\u2019s two pivots are the same point, so there is no axis to describe":Ou(lD(e))?null:"the rocker\u2019s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it"}function _o(e){let t=lD(e),r=Ou(t)?t:[1,0,0],n=e.rockerPivotA,o=ne(n,Q(r,-n[0]/r[0]));return{...Xf(r),atY:o[1],atZ:o[2],sA:Z($(n,o),r),sB:Z($(e.rockerPivotB,o),r)}}function M1(e){let t=qf(e.side,e.plan),r=[0,e.atY,e.atZ];return{a:ne(r,Q(t,e.sA)),b:ne(r,Q(t,e.sB))}}function uD(e,t,r){if(Ki(e))return e;let{a:n,b:o}=M1({..._o(e),[t]:r});return{...e,rockerPivotA:n,rockerPivotB:o}}var mD=e=>Math.abs(e.sA-e.sB)/2;function S1(e,t,r){return t==="side"||t==="plan"?Qf(mD(e),r):r}function A1(e,t,r){return t==="side"||t==="plan"?Zf(mD(e),r):r}var Ur={front:"Front",rear:"Rear"},vr=["x","y","z"],rt=(e,t)=>t==="front"?e.front:e.rear,$u=(e,t,r)=>t==="front"?{...e,front:r}:{...e,rear:r},dD=[{kind:"inboard",keys:[{key:"ucaFront",label:"UCA front pivot"},{key:"ucaRear",label:"UCA rear pivot"},{key:"lcaFront",label:"LCA front pivot"},{key:"lcaRear",label:"LCA rear pivot"},{key:"tieInner",label:"tie/toe link inner"}]},{kind:"outboard",keys:[{key:"uprightUpper",label:"upper ball joint"},{key:"uprightLower",label:"lower ball joint"},{key:"tieOuter",label:"tie/toe link outer"},{key:"wheelCenter",label:"wheel centre"}]},{kind:"actuation",keys:[{key:"pushrodOuter",label:"push/pull rod outer"},{key:"rockerPivotA",label:"rocker pivot A"},{key:"rockerPivotB",label:"rocker pivot B"},{key:"rockerToPushrod",label:"rocker \u2014 rod end"},{key:"rockerToDamper",label:"rocker \u2014 damper end"},{key:"damperChassis",label:"damper chassis mount"}]}],pD={damperChassis:"strut top mount",pushrodOuter:"strut lower mount"},Za=30;function s4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r).config.layout==="mcpherson";for(let o of dD)for(let{key:a,label:s}of o.keys){let i=n&&pD[a]||s;for(let c=0;c<3;c++)t.push({id:`hp.${r}.${a}.${vr[c]}`,group:`${Ur[r]} hardpoints \u2014 ${o.kind}`,label:`${i} ${vr[c]}`,scope:Ur[r],unit:"mm",defaultSpan:Za,read:l=>rt(l.vehicle,r).hardpoints[a][c],write:(l,u)=>{let m=rt(l.vehicle,r),p=[...m.hardpoints[a]];p[c]=u;let d={...m.hardpoints,[a]:p};return{...l,vehicle:$u(l.vehicle,r,{...m,hardpoints:d})}}})}}return t}var i4={side:"axis side-view angle",plan:"axis plan-view angle",clock:"arm clock angle",len:"effective arm length"},c4={side:"\xB0",plan:"\xB0",clock:"\xB0",len:"mm"};function l4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r).config.layout==="mcpherson";for(let o of["uca","lca"]){let a=rt(e.vehicle,r).hardpoints,s=R1(a,o)?null:so(a,o);for(let i of Io)t.push({id:`arm.${r}.${o}.${i}`,group:`${Ur[r]} ${n?"arm axes":"wishbone axes"}`,label:`${Vu[o]} \u2014 ${i4[i]}`,scope:Ur[r],unit:c4[i],defaultSpan:s?Jf(s,i,Za):Za,read:c=>so(rt(c.vehicle,r).hardpoints,o)[i],write:(c,l)=>{let u=rt(c.vehicle,r),m=iD(u.hardpoints,o,i,l);return{...c,vehicle:$u(c.vehicle,r,{...u,hardpoints:m})}}})}}return t}var u4={side:"pivot axis side-view angle",plan:"pivot axis plan-view angle",atY:"pivot axis outboard, at the wheel-centre plane",atZ:"pivot axis height, at the wheel-centre plane"},m4={side:"\xB0",plan:"\xB0",atY:"mm",atZ:"mm"};function d4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r).hardpoints,o=Ki(n)?null:_o(n);for(let a of Qa)t.push({id:`rocker.${r}.${a}`,group:`${Ur[r]} rocker axis`,label:`rocker \u2014 ${u4[a]}`,scope:Ur[r],unit:m4[a],defaultSpan:o?S1(o,a,Za):Za,read:s=>_o(rt(s.vehicle,r).hardpoints)[a],write:(s,i)=>{let c=rt(s.vehicle,r),l=uD(c.hardpoints,a,i);return{...s,vehicle:$u(s.vehicle,r,{...c,hardpoints:l})}}})}return t}var eh={front:"heaveFrontDesign",rear:"heaveRearDesign"},Hi={front:"arbFrontDesign",rear:"arbRearDesign"},Bu={front:"rollBarFrontDesign",rear:"rollBarRearDesign"};function p4(e,t){return{heave:e.config.actuation==="decoupled"?"heave element":"third spring",roll:t?.design.kind==="coil"?"roll shock":"anti-roll bar"}}var th=e=>/^(heave|roll|rollBar)\.(front|rear)\.(outer|inner|anchor)\.[xyz]$/.test(e);function f4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r),o=e.params[eh[r]],a=e.params[Hi[r]],s=p4(n,a),i=h=>h.params[eh[r]],c=h=>h.params[Hi[r]],l=(h,b)=>({...h,params:{...h.params,[eh[r]]:b}}),u=(h,b)=>({...h,params:{...h.params,[Hi[r]]:b}}),m={group:`${Ur[r]} heave & roll elements`,scope:Ur[r]},p=(h,b,g,y,x)=>{for(let R of g)t.push({...m,id:`${h}.${vr[R]}`,label:`${b} ${vr[R]}`,unit:"mm",defaultSpan:Za,read:v=>y(v)[R],write:(v,S)=>{let A=[...y(v)];return A[R]=S,x(v,A)}})},d=(h,b,g,y,x)=>{t.push({...m,id:h,label:b,unit:"N/mm",defaultSpan:Math.max(5,g*.4),read:y,write:x})};if(o?.design.kind==="coil"){if(o.linkage){let h=g=>i(g).linkage;p(`heave.${r}.outer`,`${s.heave} eye`,[0,1,2],g=>h(g).outer,(g,y)=>l(g,{...i(g),linkage:{...h(g),outer:y}})),o.linkage.mount?.kind==="chassis"&&p(`heave.${r}.anchor`,`${s.heave} chassis anchor`,[0,2],g=>h(g).mount.anchor,(g,y)=>l(g,{...i(g),linkage:{...h(g),mount:{kind:"chassis",anchor:y}}}))}if(typeof o.design.rate=="number"){let h=b=>i(b).design;d(`heave.${r}.rate`,`${s.heave} spring rate (@element)`,o.design.rate,b=>h(b).rate,(b,g)=>l(b,{...i(b),design:{...h(b),rate:g}}))}}if(a&&a.design.kind!=="none"){if(a.linkage&&a.design.kind!=="direct"){let b=R=>c(R).linkage,g=Br(n,a.linkage,a.design.kind),[y,x]=g?["left arm eye","right arm eye"]:["drop-link pickup","arm tip"];p(`roll.${r}.outer`,`${s.roll} ${y}`,[0,1,2],R=>b(R).outer,(R,v)=>u(R,{...c(R),linkage:{...b(R),outer:v}})),p(`roll.${r}.inner`,`${s.roll} ${x}`,[0,1,2],R=>b(R).inner,(R,v)=>u(R,{...c(R),linkage:{...b(R),inner:v}}))}let h=a.design;if(h.kind==="coil"&&typeof h.rate=="number"){let b=g=>c(g).design;d(`roll.${r}.rate`,`${s.roll} spring rate (@element)`,h.rate,g=>b(g).rate,(g,y)=>u(g,{...c(g),design:{kind:"coil",rate:y}}))}else h.kind==="direct"&&d(`roll.${r}.wheelRate`,`${s.roll} rate (@wheel)`,h.wheelRate,b=>c(b).design.wheelRate,(b,g)=>u(b,{...c(b),design:{kind:"direct",wheelRate:g}}))}let f=mn(n,a,e.params[Bu[r]]);if(f){let h=g=>g.params[Bu[r]],b=(g,y)=>({...g,params:{...g.params,[Bu[r]]:y}});if(f.linkage&&f.design.kind!=="direct"){let g=y=>h(y).linkage;p(`rollBar.${r}.outer`,"anti-roll bar drop-link pickup",[0,1,2],y=>g(y).outer,(y,x)=>b(y,{...h(y),linkage:{...g(y),outer:x}})),p(`rollBar.${r}.inner`,"anti-roll bar arm tip",[0,1,2],y=>g(y).inner,(y,x)=>b(y,{...h(y),linkage:{...g(y),inner:x}}))}f.design.kind==="direct"&&d(`rollBar.${r}.wheelRate`,"anti-roll bar rate (@wheel)",f.design.wheelRate,g=>h(g).design.wheelRate,(g,y)=>b(g,{...h(g),design:{kind:"direct",wheelRate:y}}))}}return t}var h4=[{axle:"front",field:"springRate",group:"Springs & bars",label:"spring rate (@spring)",unit:"N/mm",fallback:35,span:e=>Math.max(5,e*.4)},{axle:"rear",field:"springRate",group:"Springs & bars",label:"spring rate (@spring)",unit:"N/mm",fallback:40,span:e=>Math.max(5,e*.4)},{axle:"front",field:"rackTravel",group:"Steering",label:"rack travel from centre",unit:"mm",fallback:35,span:()=>15,frontOnly:!0},{axle:"front",field:"rackRatio",group:"Steering",label:"rack per steering-wheel turn",unit:"mm/rev",fallback:55,span:()=>15,frontOnly:!0},{axle:"front",field:"loadedRadius",group:"Wheel & tyre",label:"loaded radius",unit:"mm",fallback:228,span:()=>15},{axle:"rear",field:"loadedRadius",group:"Wheel & tyre",label:"loaded radius",unit:"mm",fallback:228,span:()=>15}];function b4(e){let t=[];for(let r of["front","rear"]){let n=rt(e.vehicle,r).compliance;if(!n)continue;let o=(a,s,i,c)=>{let l=i(n);l===void 0||!(l>0)||!Number.isFinite(l)||t.push({id:`kc.${r}.${a}`,group:"Compliance",label:s,scope:Ur[r],unit:"N/mm",defaultSpan:Math.max(500,l*.4),read:u=>i(rt(u.vehicle,r).compliance??{})??l,write:(u,m)=>{let p=rt(u.vehicle,r),d={...p,compliance:c(p.compliance??{},Math.max(1,m))};return{...u,vehicle:$u(u.vehicle,r,d)}}})};for(let a of["ucaFront","ucaRear","lcaFront","lcaRear","tieRod","pushRod"])o(`link.${a}`,`${g4[a]} (link)`,s=>s.links?.[a],(s,i)=>({...s,links:{...s.links,[a]:i}}));for(let a of["ucaFront","ucaRear","lcaFront","lcaRear","tieInner","topMount"])o(`bush.${a}`,`${y4[a]} (bushing)`,s=>s.bushings?.[a],(s,i)=>({...s,bushings:{...s.bushings,[a]:i}}));r==="front"&&o("rack","rack to housing",a=>a.rack,(a,s)=>({...a,rack:s}))}return t}var g4={ucaFront:"UCA front leg",ucaRear:"UCA rear leg",lcaFront:"LCA front leg",lcaRear:"LCA rear leg",tieRod:"tie rod",pushRod:"push/pull rod"},y4={ucaFront:"UCA front pickup",ucaRear:"UCA rear pickup",lcaFront:"LCA front pickup",lcaRear:"LCA rear pickup",tieInner:"tie-rod inner",topMount:"strut top mount"};function x4(){return h4.map(e=>({id:`cfg.${e.axle}.${e.field}`,group:e.group,label:e.label,scope:Ur[e.axle],unit:e.unit,defaultSpan:e.span(e.fallback),read:t=>rt(t.vehicle,e.axle).config[e.field]??e.fallback,write:(t,r)=>{let n=rt(t.vehicle,e.axle),o={...n,config:{...n.config,[e.field]:r}};return{...t,vehicle:$u(t.vehicle,e.axle,o)}}}))}function R4(e){let t=Jo(e.params.steeringSystem);if(!t.enabled)return[];let r=(n,o,a,s,i)=>({id:`steeringSystem.${n}`,group:"Steering",label:o,unit:a,defaultSpan:s,read:c=>Jo(c.params.steeringSystem)[n],write:(c,l)=>({...c,params:{...c.params,steeringSystem:Jo({...c.params.steeringSystem,enabled:!0,[n]:i(l)})}})});return[r("roadFeedbackGain","road feedback gain","\xD7",Math.max(.1,.25*t.roadFeedbackGain),n=>Math.min(2,Math.max(0,n))),r("turnInFrictionNm","turn-in friction","N\xB7m",Math.max(.1,.5*t.turnInFrictionNm),n=>Math.max(0,n))]}function v4(e){let t=xa(e.params),r=[];for(let n of["front","rear"]){if(t[n]!=="diff")continue;let o=ya(e.params.driveline?.[n]);if(o?.kind!=="clutch"&&o?.kind!=="torsen")continue;let a=(s,i)=>{let c=Xd[`${n}.${s}`];return{id:`driveline.${n}.${s}`,group:"Differential",label:c.label.charAt(0).toLowerCase()+c.label.slice(1),scope:Ur[n],unit:c.unit===": 1"?"":c.unit??"",defaultSpan:i,read:l=>ya(l.params.driveline?.[n])?.[s],write:(l,u)=>({...l,params:{...l.params,driveline:Ud({...l.params.driveline,[n]:{...l.params.driveline?.[n],[s]:u}})}})}};o.kind==="clutch"?r.push(a("preloadNm",Math.max(5,.2*o.preloadNm)),a("rampDriveDeg",5),a("rampCoastDeg",5)):r.push(a("tbrDrive",Math.max(.25,.2*o.tbrDrive)),a("tbrCoast",Math.max(.25,.2*o.tbrCoast)))}return r}function k4(e){if(Xc(e.params)!=="hydraulic")return[];let t=[{id:"brakeSetup.barFront",group:"Brakes",label:`${p0("barFront").toLowerCase()}, front share`,unit:"-",defaultSpan:.05,read:a=>$n(a.params.brakeSetup).barFront,write:(a,s)=>({...a,params:{...a.params,brakeSetup:$n({...$n(a.params.brakeSetup),barFront:s})}})}];if(!e.params.brakeModel)return t;let r=sn(e.params.brakeModel),n=(a,s)=>s.circuit?a[s.circuit][s.key]:a[s.key],o=(a,s,i)=>({id:`brakeModel.${a.circuit?`${a.circuit}.`:""}${String(a.key)}`,group:"Brakes",label:d0(a.circuit?`${a.circuit}.${String(a.key)}`:a.key),unit:s,defaultSpan:i,read:c=>n(sn(c.params.brakeModel),a),write:(c,l)=>{let u=sn(c.params.brakeModel),m=a.circuit?{...u,[a.circuit]:{...u[a.circuit],[a.key]:l}}:{...u,[a.key]:l};return{...c,params:{...c.params,brakeModel:sn(m)}}}});return t.push(o({key:"masterFrontMm"},"mm",1.5),o({key:"masterRearMm"},"mm",1.5),o({key:"pedalRatio"},"-",.5),o({key:"pistonDiaMm",circuit:"front"},"mm",2),o({key:"pistonDiaMm",circuit:"rear"},"mm",2),o({key:"effRadiusMm",circuit:"front"},"mm",10),o({key:"effRadiusMm",circuit:"rear"},"mm",10)),r.valve!=="none"&&t.push(o({key:"valveKneeBar"},"bar",5)),r.valve==="proportioning"&&t.push(o({key:"valveSlope"},"-",.1)),t}var fD=e=>!!e&&typeof e=="object"&&"value"in e&&"label"in e;function hD(e){let t={...e};for(let r of Object.keys(t)){let n=t[r];fD(n)&&(t[r]={...n})}return t}function M4(e){let t=[];for(let r of zw(e))for(let n of r.rows){let o=Math.abs(n.value);t.push({id:`param.${n.key}`,group:r.title,label:n.label,unit:n.unit,defaultSpan:o>0?o*.2:1,read:a=>{let s=a.params[n.key];return fD(s)?s.value:NaN},write:(a,s)=>{let i=hD(a.params);return si(i,n.label,s),{...a,params:i}}})}return t}function bD(e){let t={};for(let i of["front","rear"]){if(!rt(e.vehicle,i).measured)continue;let l="this axle is described by measured curves, so its linkage is not solved";for(let u of dD)for(let{key:m}of u.keys)for(let p of vr)t[`hp.${i}.${m}.${p}`]={why:l};for(let u of["uca","lca"])for(let m of Io)t[`arm.${i}.${u}.${m}`]={why:l};for(let u of Qa)t[`rocker.${i}.${u}`]={why:l};for(let u of["heave.outer","heave.anchor","roll.outer","roll.inner","rollBar.outer","rollBar.inner"]){let[m,p]=u.split(".");for(let d of vr)t[`${m}.${i}.${p}.${d}`]={why:l}}t[`cfg.${i}.springRate`]={why:"the measured curve set carries its own spring rate"}}let r=["rockerPivotA","rockerPivotB","rockerToPushrod","rockerToDamper"];for(let i of["front","rear"]){if(rt(e.vehicle,i).config.actuation!=="direct")continue;let c="this axle is direct-acting \u2014 there is no bell-crank";for(let l of r)for(let u of vr)t[`hp.${i}.${l}.${u}`]={why:c};for(let l of Qa)t[`rocker.${i}.${l}`]={why:c}}for(let i of["front","rear"]){let c=rt(e.vehicle,i);if(c.measured||c.config.actuation!=="decoupled")continue;let l="this axle is decoupled \u2014 the corner damper is out of circuit";for(let u of["rockerToDamper","damperChassis"])for(let m of vr)t[`hp.${i}.${u}.${m}`]={why:l,useInstead:`heave.${i}.outer.${m}`};t[`cfg.${i}.springRate`]={why:"a decoupled axle has no corner spring \u2014 its elements hold it up",useInstead:`heave.${i}.rate`}}for(let i of["front","rear"]){let c=rt(e.vehicle,i),l=e.params[eh[i]]?.linkage;if(c.measured||!l||l.attach!=="rocker"||l.mount?.kind==="chassis")continue;let u=c.hardpoints,m=[0,1,2].map(d=>u.rockerPivotB[d]-u.rockerPivotA[d]),p=Math.hypot(m[0],m[1],m[2]);if(p>0)for(let d=0;d<3;d++)Math.abs(m[d]/p)<1-1e-12||(t[`heave.${i}.outer.${vr[d]}`]={why:`the rocker shaft runs along ${vr[d]} \u2014 this only slides the eye along it`})}for(let i of["front","rear"]){let c=rt(e.vehicle,i);if(c.measured)continue;let l=e.params[Hi[i]],u=[["roll",l],["rollBar",mn(c,l,e.params[Bu[i]])]];for(let[m,p]of u){let d=p?.linkage;if(!p||!d||p.design.kind==="none"||p.design.kind==="direct"||Br(c,d,p.design.kind))continue;let f=[0,1,2].map(b=>d.inner[b]-d.outer[b]),h=Math.hypot(f[0],f[1],f[2]);if(h>0)for(let b=0;b<3;b++)Math.abs(f[b]/h)<1-1e-12||(t[`${m}.${i}.inner.${vr[b]}`]={why:`the drop link runs along ${vr[b]} \u2014 this only changes its length`})}}for(let i of["front","rear"]){let c=rt(e.vehicle,i);if(c.measured||c.config.layout!=="mcpherson")continue;let l="this axle is a McPherson strut \u2014 there is no upper arm";for(let u of["ucaFront","ucaRear","uprightUpper"])for(let m of vr)t[`hp.${i}.${u}.${m}`]={why:l,useInstead:`hp.${i}.damperChassis.${m}`};for(let u of Io)t[`arm.${i}.uca.${u}`]={why:l};for(let u of["link.ucaFront","link.ucaRear","bush.ucaFront","bush.ucaRear"])t[`kc.${i}.${u}`]={why:l}}for(let i of["front","rear"]){let c=rt(e.vehicle,i);if(c.measured)continue;for(let u of["uca","lca"]){if(u==="uca"&&c.config.layout==="mcpherson")continue;let m=R1(c.hardpoints,u);if(m)for(let p of Io)t[`arm.${i}.${u}.${p}`]={why:m,useInstead:`hp.${i}.${Rr[u].fore}.z`}}let l=Ki(c.hardpoints);if(l&&c.config.actuation!=="direct")for(let u of Qa)t[`rocker.${i}.${u}`]={why:l,useInstead:`hp.${i}.${Sn.fore}.z`}}let n=[["arbFrontDesign","param.arb_front","the front anti-roll bar design in Vehicle Dynamics","front","roll"],["arbRearDesign","param.arb_rear","the rear anti-roll bar design in Vehicle Dynamics","rear","roll"],["heaveFrontDesign","param.heave_spring_front","the front third-spring design","front","heave"],["heaveRearDesign","param.heave_spring_rear","the rear third-spring design","rear","heave"]];for(let[i,c,l,u,m]of n){let p=e.params[i];if(!p?.design)continue;if(p.design.kind==="none"){m==="heave"&&(t[c]={why:`the ${u} heave element is None`});continue}let d=p.design.kind==="direct"?`${m}.${u}.wheelRate`:`${m}.${u}.rate`;t[c]={why:`computed from ${l}`,useInstead:d}}for(let i of["front","rear"]){let c=`param.arb_${i}`;if(t[c])continue;let l=mn(rt(e.vehicle,i),e.params[Hi[i]],e.params[Bu[i]]);l&&(t[c]={why:`computed from the ${i} anti-roll bar beside the roll element`,...l.design.kind==="direct"?{useInstead:`rollBar.${i}.wheelRate`}:{}})}for(let i of["front","rear"]){let c=`param.arb_${i}`;!t[c]&&e.params[Hi[i]]?.design.kind==="none"&&(t[c]={why:`the ${i} roll element is None`})}let o=e.params.aeroModelId||e.params.aeroModel?ty:ry;for(let[i,c]of Object.entries(o))t[`param.${i}`]={why:c};if(e.params.batteryModelId||e.params.batteryModel)for(let[i,c]of Object.entries(Qd))t[`param.${i}`]={why:c};for(let[i,c]of Object.entries(Zd(e.params)))t[`param.${i}`]={why:c};let a={...jf(e.params).readouts,...e.sessionAir?{rho:jp}:{}};for(let[i,c]of Object.entries(a)){let l=`param.${i}`;!(l in t)&&!(l in yD)&&(t[l]={why:c})}for(let[i,c]of Object.entries(ny(e.params)))t[`param.${i}`]={why:c};let s=Xc(e.params)==="hydraulic";for(let[i,c]of Object.entries(pd(e.params)))t[`param.${i}`]=s?{why:c,useInstead:"brakeSetup.barFront"}:{why:c};return t}function gD(e){let t={...yD,...bD(e)};for(let[n,o]of Object.entries(t))o.useInstead&&t[o.useInstead]&&(t[n]={why:o.why});let r=n=>{let o=t[n.id];return o?{...n,supersededBy:o}:n};return[...s4(e),...l4(e),...d4(e),...f4(e),...x4(),...R4(e),...k4(e),...v4(e),...b4(e),...M4(e.params)].map(r)}var S4={spring_front:"cfg.front.springRate",spring_rear:"cfg.rear.springRate"},yD=Object.fromEntries(Object.entries(ey).map(([e,t])=>[`param.${e}`,{why:t,useInstead:S4[e]}])),dt=e=>e.scope?`${e.scope} \xB7 ${e.label}`:e.label;function gt(e){let t={};for(let n of gD(e))t[n.id]=n;let r=(n,o)=>{if(typeof o!="string")return;let a=IL(n,o);return a&&(n[o]=a),a};return new Proxy(t,{get:(n,o,a)=>typeof o=="string"&&!Object.hasOwn(n,o)?r(n,o)??Reflect.get(n,o,a):Reflect.get(n,o,a),has:(n,o)=>Reflect.has(n,o)||!!r(n,o)})}var w1=e=>e.step!==void 0&&Number.isFinite(e.step)&&e.step>0?e.step:0,F1=e=>w1(e)>0||(e.values?.length??0)>0,C1=e=>e.some(F1),xD=e=>1e-9*Math.max(1,Math.abs(e.lo),Math.abs(e.hi));function RD(e,t){if(!Number.isFinite(t))return t;if(e.values?.length){let s=e.values[0];for(let i of e.values)Math.abs(i-t)<Math.abs(s-t)&&(s=i);return s}let r=w1(e);if(!r||!Number.isFinite(e.start))return t;let n=xD(e),o=Math.round((t-e.start)/r),a=s=>e.start+s*r;return a(o)>e.hi+n&&a(o-1)>=e.lo-n?a(o-1):a(o)<e.lo-n&&a(o+1)<=e.hi+n?a(o+1):a(o)}var vD=(e,t)=>t.map((r,n)=>e[n]&&F1(e[n])?RD(e[n],r):r);function T1(e,t=1e3){if(e.values?.length)return e.values.length;let r=w1(e);if(!r||!Number.isFinite(e.start))return 1/0;let n=xD(e),o=Math.ceil((e.lo-n-e.start)/r),a=Math.floor((e.hi+n-e.start)/r);return Math.max(0,Math.min(t,a-o+1))}function P1(e,t,r){let n=vD(e.variables,t),o=n.every((a,s)=>a===t[s]);return{x:n,score:o?r:On(e,n)}}function E1(e,t){if(!e.variables.some(kD))return e;let r=e.variables.filter(o=>o.follows&&!o.fixed).map(o=>({id:o.id,follows:o.follows})),n=e.variables.filter(o=>!o.fixed&&!o.follows).map(o=>{if(MD(o))return{...o,lo:Math.min(...o.values),hi:Math.max(...o.values)};if(!o.around)return o;let{around:a,fixed:s,...i}=o,c=t(o.id);return Number.isFinite(c)?{...i,lo:c-a.minus,hi:c+a.plus}:i});return r.length?{...e,variables:n,followers:r}:{...e,variables:n}}var kD=e=>!!(e.fixed||e.around||e.follows)||MD(e),MD=e=>!!e.values?.length&&(e.lo!==Math.min(...e.values)||e.hi!==Math.max(...e.values));function Kt(e,t){if(!t.variables.some(kD))return t;let r=gt(e);return E1(t,n=>{let o=r[n];if(!o)return NaN;try{return o.read(e)}catch{return NaN}})}var nh=()=>({variables:[],constraints:[],objectives:[],watches:[],density:{...Di},envelope:{...Tu},operating:{...Si},lap:bf()});function Xr(e){return[...e.objectives,...e.constraints,...e.watches??[]]}var oh=e=>(e.metrics??xr()).byId;function I1(e,t){t=Kt(e,t);let r=gt(e),n=[];for(let o of t.variables){let a=r[o.id];a&&n.push({id:a.id,name:dt(a),unit:a.unit,lo:o.lo,hi:o.hi,start:a.read(e),...o.step!==void 0?{step:o.step}:{},...o.values?{values:o.values}:{}})}return n}function zi(e,t,r){t=Kt(e,t);let n=gt(e),o=e;return t.variables.forEach((a,s)=>{let i=n[a.id];i&&Number.isFinite(r[s])&&(o=i.write(o,r[s]))}),O1(e,o,t.followers,n)}function _1(e,t,r={}){let n=t.states??[],o=n.some(c=>c.follows);if(!o&&!t.envelopeFollows)return t;let a=Eo(e,{density:t.density,envelope:t.envelope,states:n,operating:t.operating,lap:t.lap,assemble:r.assemble,simParams:r.simParams,projectTrack:r.projectTrack,libraryTrack:r.libraryTrack,numerics:r.numerics}),s=n;if(o&&r.simParams)try{let c=a.ggv();c&&(s=Wx(n,c,F4(r)))}catch{s=n}let i=t.envelope;if(t.envelopeFollows&&s.length){let c=s.map(h=>a.poseAt(h)).filter(h=>h!==null),l=oh(r),u=N1(t,l),m=Xr(t).map(h=>({r:h,m:l[h.metricId]})).filter(({m:h})=>h&&h.id.startsWith("kin.")&&h.reads!=="state"&&(h.scope==="car"||u.includes(h.scope))),p=h=>{let b=Eo(e,{density:t.density,envelope:h,assemble:r.assemble,numerics:r.numerics});return m.every(({r:g,m:y})=>Number.isFinite(vt(b,y,g.at)))},d=c.length===s.length?w4(e,Ux(c,u),u):null,f=d&&m.length?A4(d,p):d;f&&!Xx(f,t.envelope)&&(i=f)}return s===n&&i===t.envelope?t:{...t,states:s,envelope:i}}var rh=3;function A4(e,t){let r=(c,l)=>t({...e,travelMin:c,travelMax:l}),n=e.travelMin-rh,o=e.travelMax+rh;if(r(n,o))return e;let a=(c,l,u)=>{for(;Math.abs(l-c)>1;){let m=Math.round((c+l)/2);u(m)?c=m:l=m}return c};if(r(n,1))o=a(1,o,c=>r(n,c));else if(r(-1,1))n=a(-1,n,c=>r(c,1)),o=a(1,o,c=>r(n,c));else return e;let s=Math.min(-1,Math.max(e.travelMin,n+rh)),i=Math.max(1,Math.min(e.travelMax,o-rh));return s===e.travelMin&&i===e.travelMax?e:{...e,travelMin:s,travelMax:i}}function N1(e,t){let r=new Set;for(let n of Xr(e)){let o=t[n.metricId];if(!(!o||!o.id.startsWith("kin.")||o.reads==="state")){if(o.scope==="car")return["front","rear"];r.add(o.scope)}}return r.size?["front","rear"].filter(n=>r.has(n)):["front","rear"]}function w4(e,t,r){if(!t)return null;let n=Ei(e.vehicle,e.params),{travelMin:o,travelMax:a}=t;for(let s of r.map(i=>n[i]))try{let i=ut(s,{travelMin:o,travelMax:a,steps:Di.travelSteps});if(i.covered)continue;let c=i.samples.filter(l=>l.converged).map(l=>l.travel);if(!c.length)continue;o=Math.max(o,Math.min(-1,Math.ceil(Math.min(...c))+1)),a=Math.min(a,Math.max(1,Math.floor(Math.max(...c))-1))}catch{continue}return o===t.travelMin&&a===t.travelMax?t:{...t,travelMin:o,travelMax:a}}function F4(e){let t=e.projectTrack?.();if(!t)return null;try{return Yx($t(t.asset,t.numerics))}catch{return null}}function O1(e,t,r,n){if(!r?.length)return t;let o=t;for(let a of r){let s=n[a.id],i=n[a.follows];if(!s||!i)continue;let c=i.read(t)-i.read(e);Number.isFinite(c)&&c!==0&&(o=s.write(o,s.read(e)+c))}return o}function No(e,t){if(!Number.isFinite(t))return NaN;if(e.op==="max")return t-e.limit;if(e.op==="min")return e.limit-t;let r=e.limit2??e.limit;return Math.max(e.limit-t,t-r)}var SD=(e,t="")=>t&&t!=="-"?`${e} ${t}`:`${e}`;function AD(e,t,r){let n=t??$i[e.metricId],o=(n?bt(n):e.metricId)+Ja(e.at,n,r),a=s=>SD(s,n?.unit);return e.op==="max"?`${o} \u2264 ${a(e.limit)}`:e.op==="min"?`${o} \u2265 ${a(e.limit)}`:`${o} between ${e.limit} and ${a(e.limit2??e.limit)}`}function Ja(e,t,r){if(!e&&t?.reads!=="state")return"";e??={};let n=[];if(t?.reads==="state")if(e.stateId===Rn)n.push(s1(t));else{let o=e.stateId===void 0?r?.states?.[0]:r?.states?.find(a=>a.id===e.stateId);o&&n.push(o.name)}if(e.speed!==void 0&&o1(t)&&n.push(`${(e.speed*3.6).toFixed(0)} km/h`),e.ayG!==void 0&&a1(t)&&n.push(`${e.ayG.toFixed(2)} g`),e.courseId===Eu&&t?.reads==="course")n.push(n1(t));else if(e.courseId&&t?.reads==="course"){let o=r?.lap.courses.find(a=>a.id===e.courseId);o&&n.push(iR(o))}return n.length?` @ ${n.join(", ")}`:""}function wD(e,t,r){let n=r/t.scale;return e.goal==="min"?e.weight*n:e.goal==="max"?-e.weight*n:e.weight*Math.max(0,Math.abs(r-(e.target??0))-Math.max(0,e.tolerance??0))/t.scale}var FD=5e-4;function CD(e,t){return e.cost!=="lap"&&e.cost!=="session"?0:Number.isFinite(t)?FD*Math.abs(t):0}function ah(e,t,r={}){return Eo(e,{density:t.density,envelope:t.envelope,states:t.states,operating:t.operating,lap:t.lap,assemble:r.assemble,simParams:r.simParams,projectTrack:r.projectTrack,libraryTrack:r.libraryTrack,sessionParams:r.sessionParams,session:r.session,numerics:r.numerics})}function es(e,t,r={}){t=Kt(e,t);let n=I1(e,t),o=gt(e),a=oh(r),s=t.constraints.map(m=>({spec:m,metric:a[m.metricId]})).filter(m=>!!m.metric),i=s.filter(m=>m.metric.cost==="geometry"),c=s.filter(m=>m.metric.cost!=="geometry"),l=t.objectives.map(m=>({spec:m,metric:a[m.metricId]})).filter(m=>!!m.metric),u=(m,p)=>{let d=0,f=[];for(let{spec:h,metric:b}of m){let g=vt(p,b,h.at);if(!Number.isFinite(g))return{ok:!1,violation:p.failure?.violation??400,reason:p.failure?.reason??`${bt(b)} could not be computed`};let y=No(h,g);y>0&&(d+=y/b.scale,f.push(`${AD(h,b,t)} (${SD(g.toFixed(3),b.unit)})`))}return f.length===0?Oc:{ok:!1,violation:d,reason:f.join("; ")}};return{name:"study",variables:n,build:m=>{let p=e;return t.variables.forEach((d,f)=>{let h=o[d.id];h&&(p=h.write(p,m[f]))}),p=O1(e,p,t.followers,o),{car:p,ev:ah(p,t,r)}},feasible:({ev:m})=>{let p=u(i,m);if(!p.ok)return p;for(let{spec:d,metric:f}of c)vt(m,f,d.at);for(let{spec:d,metric:f}of l)vt(m,f,d.at);return m.failure?{ok:!1,violation:m.failure.violation,reason:m.failure.reason}:u(c,m)},terms:({ev:m})=>l.map(({spec:p,metric:d})=>{let f=vt(m,d,p.at);return{name:bt(d)+Ja(p.at,d,t),raw:f,unit:d.unit,weight:p.weight,contribution:wD(p,d,f),resolution:Math.abs(p.weight)*CD(d,f)/d.scale}})}}function L1(e){let t=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(t)return`${t[1]}.${t[2]}`;let r=/^rocker\.(front|rear)\./.exec(e);if(r)return`${r[1]}.rocker`;let n=/^hp\.(front|rear)\.(ucaFront|ucaRear|lcaFront|lcaRear|rockerPivotA|rockerPivotB)\./.exec(e);return n?n[2].startsWith("rocker")?`${n[1]}.rocker`:`${n[1]}.${n[2].startsWith("uca")?"uca":"lca"}`:null}function TD(e,t){if(e.variables.some(o=>o.id===t))return!0;let r=Ua(t);if(!r||!_i.includes(r.axis))return!1;if(e.variables.some(o=>Pr(o.id)?.point===r.point))return!0;let n=L1(t);return!!n&&e.variables.some(o=>/^(arm|rocker)\./.test(o.id)&&L1(o.id)===n)}function C4(e,t){let r=e.followers??[],n=new Map(r.map(i=>[i.id,i.follows])),o=i=>{let c=t[i],l=Ua(i);return c&&l&&_i.includes(l.axis)?{name:dt({...c,label:c.label.replace(/ [xyz]$/,"")}),axis:l.axis}:{name:c?dt(c):`\u201C${i}\u201D`}},a=new Map,s=(i,c,l)=>{let u=a.get(i);u||a.set(i,u={text:l,axes:[]}),c&&u.axes.push(c)};for(let i of r){let c=t[i.id],l=t[i.follows],u=o(i.id),m=o(i.follows),p=d=>d&&d!=="x, y, z"?` in ${d}`:"";if(!c){s(`missing:${i.id}`,void 0,()=>`\u201C${i.id}\u201D is not a variable this car has.`);continue}if(c.supersededBy&&s(`superseded:${u.name}`,u.axis,d=>`${u.name}${p(d)} cannot be moved: ${c.supersededBy.why}.`),!l)s(`no-lead:${u.name}:${i.follows}`,u.axis,d=>`${u.name}${p(d)} moves with \u201C${i.follows}\u201D, which is not a variable this car has.`);else if(i.follows===i.id)s(`self:${u.name}`,u.axis,d=>`${u.name}${p(d)} cannot move with itself.`);else if(l.unit!==c.unit)s(`unit:${u.name}:${m.name}`,u.axis,d=>`${u.name}${p(d)} moves with ${m.name}, which is in ${l.unit} where it is in ${c.unit}. Link it to one in the same unit.`);else if(n.has(i.follows)){let d=o(n.get(i.follows));s(`chain:${u.name}:${m.name}`,u.axis,f=>`${u.name}${p(f)} moves with ${m.name}, which itself moves with ${d.name}. Link it to ${d.name}.`)}else TD(e,i.follows)||s(`still:${u.name}:${m.name}`,u.axis,d=>`${u.name}${p(d)} moves with ${m.name}, which the study does not move${p(d)}. Free that one, or give this its own bound.`)}return[...a.values()].map(i=>i.text(i.axes.join(", ")))}function V1(e,t,r={}){let n=t.variables.length>0&&t.variables.every(y=>y.fixed||y.follows),o=t.variables.some(y=>y.follows&&!y.fixed);t=Kt(e,t);let a=gt(e),s=[],i=oh(r),c=Xr(t).map(y=>y.metricId),l=c.some(y=>y.startsWith("dyn.")),u=c.some(y=>y.startsWith("lap."));if(c.some(y=>y.startsWith("kin."))){let y=t.envelope;y.travelMin<0&&y.travelMax>0||s.push("The travel the linkage is read over must reach both ways from the design ride: droop below zero, bump above."),(!(y.rollMaxDeg>0)||!(y.rollAtLimitDeg>=0))&&s.push("The roll the linkage is read over must be above zero.")}let m=Xr(t).filter(y=>i[y.metricId]?.reads==="state");if(m.length){let y=t.states??[];if(!y.length)s.push("This study reads targets at a state and has none. Take the car\u2019s five under Conditions.");else{let x=new Set([...y.map(R=>R.id),Rn]);for(let R of m){let v=i[R.metricId];if(R.at?.stateId&&!x.has(R.at.stateId))s.push(`${bt(v)} names a state this study no longer has. Point it at one of the states under Conditions.`);else if(R.at?.stateId===Rn&&!v.acrossStates)s.push(`${bt(v)} is read at one state at a time, not over every state.`);else if(v.appliesAt){let S=R.at?.stateId&&R.at.stateId!==Rn?y.find(C=>C.id===R.at.stateId):void 0,A=S?p1(v,S):null;A?s.push(`${bt(v)} ${A}. Point it at a state that does.`):!S&&!Hf(v,y)&&s.push(`${bt(v)} has no state to be read at: ${v.appliesAt(y[0])} in every state of this study.`)}}}r.assemble||s.push("This study reads targets at a state, and nothing here can assemble the car to find its pose.")}for(let y of t.states??[])(!(y.speedKmh>=0)||!Number.isFinite(y.ayG)||!Number.isFinite(y.axG))&&s.push(`The state \u201C${y.name}\u201D needs a speed of zero or more and finite accelerations.`),y.weight>0||s.push(`The state \u201C${y.name}\u201D needs a weight above zero.`);if(l&&!r.assemble&&s.push("This study reads whole-car metrics, and nothing here can assemble the car to read them from."),u&&!r.simParams&&s.push("This study reads lap metrics, and nothing here can prepare the car for a lap."),u&&!t.lap.courses.length&&s.push("This study reads lap metrics and has no course to drive. Add one under \u201CWhat the car drives\u201D."),u&&t.lap.courses.some(y=>y.course.kind==="project")&&!r.projectTrack?.()&&s.push("This study laps the project\u2019s track, and the project has none. Pick a manoeuvre, or load a track."),u)for(let y of t.lap.courses)y.course.kind==="track"&&!r.libraryTrack?.(y.course.trackId)&&s.push(`This study drives ${y.course.name}, which is not in the project\u2019s tracks, or has not loaded yet.`);let p=new Set([...t.lap.courses.map(y=>y.id),Eu]);for(let y of Xr(t))if(y.at?.courseId&&!p.has(y.at.courseId)){let x=i[y.metricId];s.push(`${x?bt(x):y.metricId} names a course this study no longer has. Point it at one of the courses below.`)}u&&t.lap.ggvMode==="fast"&&t.variables.some(x=>/arb_|spring|heave_|front_mass_diss|cg_height|chassis_torsion|^hp\.|^roll\.|^rollBar\./.test(x.id.replace("param.","")))&&s.push("The fast grip envelope is a point mass: no load transfer, no trim. It cannot see bars, springs, roll centres, the chassis\u2019s twist or where the mass sits, and this study moves at least one of those."),n?s.push(o?"Every variable is fixed or moves with another \u2014 there is nothing to search.":"Every variable is fixed \u2014 there is nothing to search."):t.variables.length===0&&s.push("No variables selected \u2014 there is nothing to search."),t.objectives.length===0&&s.push("No objective selected. Constraints alone say which designs are legal, not which is better.");for(let y of t.variables){let x=a[y.id];if(!x){s.push(`\u201C${y.id}\u201D is not a variable this car has.`);continue}if(y.values&&y.values.length<2?s.push(`${dt(x)}: list two values or more, or fix it where it is.`):y.hi>y.lo?y.step!==void 0&&T1({...y,start:x.read(e)})<2&&s.push(`${dt(x)}: a step of ${y.step} ${x.unit} leaves no other place to land in its box. Make the step finer or the box wider, or fix it.`):s.push(`${dt(x)}: the upper bound must be above the lower one (${y.lo} to ${y.hi}).`),x.supersededBy){let v=x.supersededBy.useInstead?a[x.supersededBy.useInstead]:void 0,S=v?dt(v):void 0;s.push(`${dt(x)} cannot be searched: ${x.supersededBy.why}.`+(S?` Use ${S} instead.`:""))}let R=x.read(e);Number.isFinite(R)&&(R<y.lo||R>y.hi)&&s.push(`${dt(x)} starts at ${R.toFixed(1)} ${x.unit}, outside its own bounds.`)}let d=t.followers??[],f=new Map;for(let y of[...t.variables.map(x=>x.id),...d.map(x=>x.id)]){let x=L1(y);if(!x)continue;let R=f.get(x);R||f.set(x,R={arms:[],coords:[]}),(/^(arm|rocker)\./.test(y)?R.arms:R.coords).push(y)}for(let[y,x]of f){if(x.arms.length===0||x.coords.length===0)continue;let R=S=>a[S]?dt(a[S]):S,v=y.endsWith("rocker")?"rocker":`${y.endsWith("uca")?"upper":"lower"} arm`;s.push(`${y.startsWith("front")?"The front":"The rear"} ${v} is being moved two ways at once \u2014 as an axis (${x.arms.map(R).join(", ")}) and as pivot coordinates (${x.coords.map(R).join(", ")}). They describe the same ${v}, so whichever is applied second overwrites the other. Keep one.`)}let h=new Map,b=new Set(d.map(y=>y.id));for(let y of[...t.variables.map(x=>x.id),...b]){let x=Ua(y);if(!x)continue;let R=Pr(y),v=b.has(y)?"with":R?`${R.shape.kind}:${y.slice(y.lastIndexOf(".")+1).replace(/[uv]$/,"")}`:"axes",S=h.get(x.point);S||h.set(x.point,S=new Set),S.add(v)}for(let[y,x]of h){if(x.size<2||x.size===2&&x.has("axes")&&x.has("with"))continue;let R=[...x].map(F=>F.split(":")[0]),v=F=>R.filter(T=>T===F).length,S=[v("axes")?"in its axes":"",v("line")===1?"along a line":v("line")>1?"along two lines":"",v("plane")===1?"in a plane":v("plane")>1?"in two planes":"",v("with")?"with another point":""].filter(Boolean),A=a[`${y}.x`],C=A?dt({...A,label:A.label.replace(/ x$/,"")}):y;s.push(`${C} is moved more than one way at once \u2014 ${S.join(" and ")}. Each write moves it off the other's, so keep one.`)}s.push(...C4(t,a));for(let y of t.constraints){let x=i[y.metricId];if(!x){s.push(`\u201C${y.metricId}\u201D is not a metric.`);continue}y.op==="band"&&!((y.limit2??y.limit)>y.limit)&&s.push(`${bt(x)}: the band's upper limit must be above its lower one.`)}l&&!(t.operating.speed>0)&&s.push("Whole-car metrics need a speed to be read at; a yaw-moment diagram at rest is degenerate.");for(let y of Xr(t))if(y.at?.speed!==void 0&&!(y.at.speed>0)){let x=i[y.metricId];s.push(`${x?bt(x):y.metricId} is asked for at rest, where a yaw-moment diagram is degenerate.`)}for(let y of t.watches??[])i[y.metricId]||s.push(`\u201C${y.metricId}\u201D is not a metric.`);let g=new Set;for(let y of Xr(t)){let x=i[y.metricId],R=x?.unavailable?.(e);!x||!R||g.has(x.id)||(g.add(x.id),s.push(`${bt(x)} cannot be read on this car: ${R}.`))}for(let y of t.objectives)i[y.metricId]?y.weight>0?y.goal==="target"&&!Number.isFinite(y.target)?s.push(`${bt(i[y.metricId])}: \u201Chit a value\u201D needs a value.`):y.goal==="target"&&y.tolerance!==void 0&&!(y.tolerance>=0)&&s.push(`${bt(i[y.metricId])}: the tolerance must be zero or more.`):s.push(`${bt(i[y.metricId])}: weight must be positive.`):s.push(`\u201C${y.metricId}\u201D is not a metric.`);return s}var PD=.1,LD=2e3,D1=3;function B1(e,t,r={},n=LD){t=Kt(e,t);let o=es(e,t,r),a=oh(r),s=gt(e),i=o.variables.map(k=>k.start),c=k=>{let w=o.build(k);return o.feasible(w).ok&&o.terms(w),w},l=c(i),u=o.feasible(l),m=[...t.objectives,...t.constraints],p=(k,w=m)=>{let P={};for(let L of w){let E=a[L.metricId];E&&(P[`${L.metricId}@${Xa(L.at)}`]=vt(k.ev,E,L.at))}return P},d=k=>m.map(w=>k[`${w.metricId}@${Xa(w.at)}`]).map(w=>Number.isFinite(w)?w.toFixed(9):"x").join("|"),f=p(l,Xr(t)),h=d(f),b=[],g=[],y={},x=[],R=0;t.variables.forEach((k,w)=>{let P=s[k.id];if(!P)return;if(x.length>=D1&&R>n){g.push(P);return}let L=[...i];L[w]=i[w]+(k.hi-i[w])*.25||k.hi;let E=performance.now(),_=c(L),D=performance.now()-E;R+=D,x.push(D);let I=p(_);y[P.id]=I,d(I)===h&&b.push(P)});let v=t.variables[0],S=v?t.variables.indexOf(v):-1;for(let k=0;v&&x.length>0&&x.length<D1;k++){let w=[...i];w[S]=i[S]+(v.hi-i[S])*(.4+.15*k)||v.hi;let P=performance.now();c(w),x.push(performance.now()-P)}let A=[...x].sort((k,w)=>k-w),C=A.length?A[A.length>>1]:0,F=[],T=Xr(t).map(k=>k.metricId);if(T.some(k=>k.startsWith("dyn.trim")||k==="dyn.ymdMaxAy")){let k=l.ev.ymdLimit();k?.onGridEdge&&F.push("The yaw-moment diagram peaks on the edge of its swept grid, so the trim readings are where the sweep stopped rather than where the car does. Widen the \u03B2/\u03B4 envelope before trusting them."),!k&&l.ev.dynAvailable&&F.push("The yaw-moment diagram found no trim point, so anything read off the limit is unavailable.")}if(T.some(k=>k==="dyn.steeringTorque"||k==="dyn.steeringTorqueGradient")){let k=l.ev.tyre()?.model,w=k?yo(k):null;w==="assumed"?F.push("This tyre carries no explicit Mz coefficient block. Its steering-aligning contribution uses Magic Formula defaults, so optimise the curve only as a qualitative placeholder until Mz is imported or fitted."):w==="none"&&F.push("This tyre model has no aligning-moment curve. Steering metrics contain contact-patch force and jacking, but not the pneumatic-trail signal that normally warns the driver at the tyre limit.")}let M=["lap.minStabil","lap.understeerFrac"];if(T.some(k=>M.includes(k))){let w=l.ev.lapReserve()?.beyondFrac;if(w!==void 0&&Number.isFinite(w)){let P=(w*100).toFixed(0);w>=PD?F.push(`Over ${P} % of this course, some wheel is asked for more longitudinal force than its own tyre ellipse allows \u2014 the speed profile and the per-wheel reconstruction disagree that far. A reserve read there is the two models disagreeing rather than the car having nothing left, and a search pointed at one will optimise the disagreement. It concentrates in high-speed braking, so a shorter straight into the first corner is the usual cure.`):w>0&&F.push(`${P} % of this course is beyond the per-wheel tyre ellipse, which is the usual level of disagreement between the speed profile and the reconstruction. Reserves are readable; treat small differences between designs as smaller than they look.`)}}return F.push(...d1(l.ev,Xr(t).map(k=>({m:a[k.metricId],at:k.at})).filter(k=>!!k.m))),{msPerEval:C,values:f,samples:x.length,times:x,dead:b,moves:y,unprobed:g,warnings:F,beyondFrac:T.some(k=>M.includes(k))?l.ev.lapReserve()?.beyondFrac:void 0,startFeasible:u.ok,startReason:u.reason}}var P4=[{kind:"title",label:"Title",what:"The name, what it changes against the Reference, the version and the date",on:"both",make:()=>({kind:"title"})},{kind:"picture",label:"Picture",what:"The car in plan, to scale",on:"each",make:()=>({kind:"picture",half:!0})},{kind:"keyFigures",label:"Key figures",what:"Large numbers picked from the sheet, or formulas",on:"each",make:()=>({kind:"keyFigures",rows:L4.slice(0,4),half:!0})},{kind:"spec",label:"Setup",what:"The Setup by group, or rows picked one by one",on:"each",make:()=>({kind:"spec",rows:"essential"})},{kind:"parts",label:"Parts",what:"Each part by name",on:"each",make:()=>({kind:"parts"})},{kind:"characteristics",label:"Characteristics",what:"What follows from the Setup, at the layout\u2019s operating point",on:"each",make:()=>({kind:"characteristics",groups:[]})},{kind:"results",label:"Results",what:"The events, times, energy and points",on:"each",make:()=>({kind:"results"})},{kind:"chart",label:"Chart",what:"Speed round a lap, the cornering limit or the torque curve",on:"both",make:()=>({kind:"chart",chart:"grip",others:!0,half:!0})},{kind:"changes",label:"Changes since",what:"What was changed since the version compared against",on:"each",make:()=>({kind:"changes"})},{kind:"checks",label:"Checks",what:"The car\u2019s errors and warnings",on:"each",make:()=>({kind:"checks"})},{kind:"notes",label:"Notes",what:"Free text, on every page or one car\u2019s",on:"both",make:()=>({kind:"notes",text:"",cars:{}})},{kind:"comparison",label:"Comparison table",what:"The rows the cars differ in, side by side",on:"all",make:()=>({kind:"comparison"})}];var L4=["setup:m","characteristics:peak_power","characteristics:power_to_weight","characteristics:cla","characteristics:cda","characteristics:pack_energy","characteristics:maxAy","characteristics:top_speed"];var f0e=new Set(P4.map(e=>e.kind));var DD={travel:{name:"Wheel travel",unit:"mm",axis:"Wheel travel (mm, + bump)",from:-25,to:25,step:1,reach:150},roll:{name:"Body roll",unit:"\xB0",axis:"Body roll (\xB0, + right side down)",from:-3,to:3,step:.25,reach:12},steer:{name:"Rack",unit:"mm",axis:"Rack (mm, + right)",from:-30,to:30,step:1,reach:80},pitch:{name:"Body pitch",unit:"\xB0",axis:"Body pitch (\xB0, + nose down)",from:-2,to:2,step:.25,reach:8}};var $1=["FL","FR","RL","RR"],or=(e,t,r)=>({input:e,from:r?r[0]:DD[e].from,to:r?r[1]:DD[e].to,n:t}),y0e=[{id:"sides",name:"Inside and outside",cards:[{id:"camber-roll",form:"curves",title:"Camber to the road through roll",sweep:or("roll",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"toe-rack",form:"curves",title:"Wheel angle against the rack",sweep:or("steer",25),wheels:["FL","FR"],y:["toe"]},{id:"camber-rack",form:"curves",title:"Camber to the road through the steer",sweep:or("steer",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"load-roll",form:"curves",title:"Wheel loads through roll",sweep:or("roll",25),wheels:$1,y:["wheelLoad"]},{id:"travel-roll",form:"curves",title:"Wheel travel through roll",sweep:or("roll",25),wheels:$1,y:["travel"]},{id:"toe-roll",form:"curves",title:"Roll steer, all four",sweep:or("roll",25),wheels:$1,y:["toe"]}]},{id:"maps",name:"Travel and steer together",cards:[{id:"camber-map",form:"surface",title:"Camber over travel and rack",sweep:or("travel",17),second:or("steer",13),wheels:["FL"],y:["camber"]},{id:"bump-steer-map",form:"map",title:"Bump steer over travel and rack",sweep:or("travel",17),second:or("steer",13),wheels:["FL"],y:["bumpSteer"]},{id:"bump-steer-family",form:"curves",title:"Bump steer through travel, at five rack positions",sweep:or("travel",25),second:or("steer",5,[-20,20]),wheels:["FL"],y:["bumpSteer"]},{id:"scrub-map",form:"surface",title:"Scrub radius over travel and rack",sweep:or("travel",17),second:or("steer",13),wheels:["FL"],y:["scrubRadius"]}]}];function G1(e){let t=Number(e);return Number.isFinite(t)?Math.min(_g,Math.max(Ig,t)):ur}var ID=6e4;var yye=[{within:60*6e4,every:ID},{within:1440*6e4,every:60*6e4},{within:720*60*6e4,every:1440*6e4},{within:1/0,every:10080*6e4}];var _D=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);var H1=e=>e==null;function H4(e,t){return e===t||H1(e)&&H1(t)?!0:typeof e=="number"&&typeof t=="number"&&Number.isNaN(e)&&Number.isNaN(t)}function Gu(e,t){if(H4(e,t))return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!Gu(e[r],t[r]))return!1;return!0}if(_D(e)&&_D(t)){for(let r of Object.keys(e))if(!Gu(e[r],t[r]))return!1;for(let r of Object.keys(t))if(!(r in e)&&!H1(t[r]))return!1;return!0}return!1}var z4=new Set(["color","visible","source","origin"]),Fye=["id",...z4];var VD=.18/1.18,BD={induction:{kind:"natural"}},$D=e=>e.breathing??BD;function sh(e){switch(e?.kind){case"sae-j1349":return tu(99e3,25);case"measured":return tu(e.hPa*100,e.tempC);default:return tu(101325,20)}}var W4=sh(void 0);function GD(e,t){let r=sh(e.rated),n=e.induction;if(n.kind==="boosted"){let o=n.boostKPa*1e3;return Math.min(n.maxPressureRatio*t.p,o)/Math.min(n.maxPressureRatio*r.p,o)*(t.pDry/t.p)/(r.pDry/r.p)}return t.pDry/r.pDry*Math.sqrt(r.T/t.T)}function KD(e,t){let r=e.induction;if(r.kind==="table"){let o=s=>ot(r.densityAltitudeM,r.powerPct,s),a=o(sh(e.rated).densityAltitudeM);return a>0?Math.max(0,o(t.densityAltitudeM)/a):0}let n=e.frictionShare??VD;return Math.max(0,(GD(e,t)-n)/(1-n))}var OD=new WeakMap;function z1(e,t){let r=e.asRated??e,n=`${t.p}|${t.pDry}|${t.T}`,o=OD.get(r);o||OD.set(r,o=new Map);let a=o.get(n);if(a)return a;let s=KD($D(r),t),i={...r,torque:r.torque.map(c=>c*s),asRated:r};return o.set(n,i),i}function q4(e){return JSON.parse(Y1(W1(e,"public/laptime/index.json"),"utf8")).tracks}var Q4=async e=>{let t=await fetch(e.url);if(!t.ok)throw new Error(`The track could not be read from ${rf(e)} (${t.status}).`);return new Uint8Array(await t.arrayBuffer())};function HD(e,t=new Map,r=Q4){let n=q4(e);return async o=>{let a=o.kind==="catalogue"?`catalogue:${o.address}`:o.name,s=t.get(a);if(s)return structuredClone(s);let i;if(o.kind==="catalogue"&&o.link){if(!cu(o.address))throw new Error(`"${o.address}" is not a catalogue address`);if(!iu(o.link))throw new Error("This track is linked to a source this version does not read from.");i=await Px(await r(o.link),o.link,o.address)}else if(o.kind==="catalogue"){if(!cu(o.address))throw new Error(`"${o.address}" is not a catalogue address`);let c=JSON.parse(Y1(W1(e,"public/catalogue",Dx(o.address)),"utf8"));i=await Ix(c,o.address)}else{let c=n.find(l=>l.name===o.name)?.file;if(!c)throw new Error(`"${o.name}" is not in the bundled catalogue`);i=JSON.parse(Y1(W1(e,"public/laptime",c),"utf8"))}return t.set(a,i),structuredClone(i)}}var Z4=1e-6;function zD(e,t,r){let n=e.cgReference;if(!n||!e.cg_height)return e;let o=Nw(e,t,r);if(o===void 0||Math.abs(o-n.standingRadius)<Z4)return e;let a=n.typed??e.cg_height.value;return{...e,cg_height:{...e.cg_height,value:ai(e.cg_height.value,n.standingRadius,o)},cgReference:{...n,standingRadius:o,typed:a}}}function YD(e,t,r){let n=e.rcRoad,o=e.rc_front,a=e.rc_rear;if(!n||!o||!a)return e;let s=jd(e,t,r),i=qn(o.value,n.gainFront,n.radiusFront,s.front),c=qn(a.value,n.gainRear,n.radiusRear,s.rear);return i===o.value&&c===a.value?e:{...e,rc_front:{...o,value:i},rc_rear:{...a,value:c},rcRoad:{...n,radiusFront:s.front??n.radiusFront,radiusRear:s.rear??n.radiusRear}}}var WD=e=>({brakeFade:e.brakeFade,airTempC:e.airTempC,diffYaw:e.diffYaw,...Da(e.air)?{air:e.air}:{}});var ts=(e,t)=>t?e.find(r=>r.id===t)?.model:void 0;function rs(e){return{tire:t=>ts(e.tires,t),motor:t=>ts(e.motors,t),aero:t=>ts(e.aeros,t),battery:t=>ts(e.batteries,t),brake:t=>ts(e.brakes??[],t),damper:t=>ts(e.dampers??[],t),suspensionOf:t=>Ei(j1(e,t),t)}}function j1(e,t){let r=ts(e.suspensions,t.suspensionId);if(r)return r;let n=e.suspensions.find(o=>o.id===e.activeSuspensionId)??e.suspensions[0];if(!n)throw new Error("this project holds no suspension, so no car can be resolved");return n.model}function ns(e,t,r){let n={front:t.tire(e.tireModelId),rear:t.tire(e.tireModelIdRear)};return U1(Tw(t.suspensionOf(e),e,n),t,r)}function J4(e){return Da(e.air)?dT(e.air,e.airTempC??ur):void 0}function ez(e,t){return t?{...e,rho:{...e.rho,value:t.rho},readouts:{...e.readouts,rho:jp}}:e}function tz(e,t,r){if(!r)return{rho:e.rho,motorModel:t,readouts:e.readouts};let{rho:n,readouts:o}=ez(e,r);return{rho:n,motorModel:t&&yt(t)?z1(t,r):t,air:r,readouts:o}}function U1(e,t,r){let n=t.tire(e.tireModelId),o=t.tire(e.tireModelIdRear),a=YD(zD(jf($w(Ow(Xw(e,t.aero(e.aeroModelId)),t.battery(e.batteryModelId)),t.damper(e.damperModelId),t.damper(e.damperModelIdRear)??t.damper(e.damperModelId)),n,o),n,o),n,o),{readouts:s,...i}=tz(a,t.motor(e.motorModelId),J4(r));return{...a,...i,...s?{readouts:s}:{},tireModel:n,...o?{tireModelRear:o}:{},aeroModel:t.aero(e.aeroModelId),batteryModel:t.battery(e.batteryModelId),brakeModel:t.brake(e.brakeModelId),damperModel:t.damper(e.damperModelId),...dl(e,t.damper),ggvMode:r.ggvMode,quasiTransient:r.quasiTransient??!1,motorThermal:r.motorThermal??!1,brakeFade:r.brakeFade??!1,...r.airTempC!==void 0?{airTempC:r.airTempC}:{},...r.diffYaw?{diffYaw:!0}:{},airSettled:!0}}var az=e=>e!==!1,sz=(e,t,r)=>r&&t>0?(e%t+t)%t:Math.min(Math.max(e,0),t);function iz(e,t,r){let n=e.points.filter(o=>Number.isFinite(o.at)&&Number.isFinite(o.z)).map(o=>({...o,at:sz(o.at,t,r)})).sort((o,a)=>o.at-a.at);return n.filter((o,a)=>a===0||o.at-n[a-1].at>1e-9)}function cz(e,t,r){let n=iz(e,t,r),o=n.length;if(o===0)return[];let a=d=>d<o-1?n[d+1].at-n[d].at:r?n[0].at+t-n[d].at:1/0,s=d=>d<o-1?(n[d+1].z-n[d].z)/a(d):r&&o>1?(n[0].z-n[d].z)/a(d):0,i=n.map(d=>Math.max(0,Number.isFinite(d.curve)?d.curve:0)/2),c=(d,f,h)=>i[d]+i[f]>h?h*i[d]/(i[d]+i[f]):i[d],l=d=>d<o-1||r?c(d,d<o-1?d+1:0,a(d)):Math.max(0,t-n[d].at),u=d=>d>0?c(d,d-1,a(d-1)):r?c(d,o-1,a(o-1)):n[d].at,m=d=>d>0?s(d-1):r&&o>1?s(o-1):n[d].at<=1e-9?s(d):0,p=d=>!r&&d===o-1&&o>1&&n[d].at>=t-1e-9?s(d-1):s(d);return n.map((d,f)=>{let h=l(f),b=u(f),g=Math.min(i[f],h,b),y=!r&&g<i[f]&&(f===o-1&&g===h||f===0&&g===b);return{at:d.at,z:d.z,gIn:m(f),gOut:p(f),half:g,asked:i[f],atEnd:y}})}function lz(e,t,r,n){let o=t-e.at;return n&&r>0?o-r*Math.round(o/r):o}function uz(e,t,r,n){for(let s of e){let i=lz(s,t,r,n);if(s.half>0&&Math.abs(i)<s.half){let c=i+s.half;return s.z-s.gIn*s.half+s.gIn*c+(s.gOut-s.gIn)/(4*s.half)*c*c}}let o=e[e.length-1],a=n?t-o.at+(t<o.at?r:0):t-o.at;for(let s of e)s.at<=t&&(o=s,a=t-s.at);return!n&&t<e[0].at?e[0].z:o.z+o.gOut*a}function jD(e,t,r,n){let o=az(n),a=cz(e,r,o);return a.length?t.map(s=>uz(a,s,r,o)):t.map(()=>0)}function Ku(e,t){if(!t?.points.length)return e;let r=pu(e),{zSmoothing:n,...o}=e;return{...o,z:jD(t,r,nR(e),e.closed)}}var ih={widthLeft:1.5,widthRight:1.5,bank:0,mu:1};function UD(e){return e.kind==="bundled"?{kind:"bundled",name:e.name}:e.kind==="catalogue"?{kind:"catalogue",id:e.id,address:e.address,...e.link?{link:e.link}:{}}:null}async function Hu(e,t){let r=UD(e.source);return XD(e,r?await t(r):void 0)}function XD(e,t){let{source:r}=e;if(r.kind==="segments"){let{segments:i,closed:c,spacing:l}=r,{asset:u}=hu(i,{name:e.name,closed:c,spacing:l,base:ih});return Ku(u,r.profile)}let n=r.sections??[];if(r.kind==="inline")return Ku(df(r.asset,n,ih),r.profile);if(!t)throw new Error(`Track "${e.name}" has to be loaded before it can be resolved.`);let{widthLeft:o,widthRight:a,closed:s}=r;return Ku(df({...t,...o!==void 0?{widthLeft:o}:{},...a!==void 0?{widthRight:a}:{},...s!==void 0?{closed:s}:{}},n,ih),r.profile)}var QRe=1/500;var ZRe=5*Math.PI/180;var i1e=1/3;var fz=[4,2,1,.5,.25,.125];function qD(e,t,r={}){let n=[...r.steps??fz].sort((g,y)=>y-g),o=Bt(r.numerics),a=r.tolPct??.5,s=mr(e),i=e.ggvMode??"twoTrack",c=bn(s,!1,i),l={...o,dsTarget:n[0]??o.dsTarget},u=n.length?Aa(s,c,[$t(t,l)],l,i):void 0,m=Fo(s,c.rows),p=n.map((g,y)=>{let x={...o,dsTarget:g},R=Date.now(),v=$t(t,x),S=tr(c,v,x,{...u?{load:u}:{},...m?{shifts:m}:{}});return r.onStep?.(y+1,n.length),{dsTarget:g,npts:v.npts,lapTime:S.laptime,ms:Date.now()-R}}),d=p[p.length-1]?.lapTime??NaN,f=p.map(g=>{let y=g.lapTime-d;return{...g,delta:y,deltaPct:d?100*y/d:NaN}}),h=f.filter(g=>Math.abs(g.deltaPct)<=a),b=h.length?Math.max(...h.map(g=>g.dsTarget)):null;return{points:f,reference:d,recommended:b,tolPct:a}}function io(e,t={}){let r=e.settings,n=t.ggvMode??r.ggvMode,o=(t.quasiTransient??r.quasiTransient)&&n!=="fast",a=e.tracks.find(s=>s.id===e.activeTrackId)??e.tracks[0];return{ggvMode:n,quasiTransient:o,motorThermal:t.motorThermal??r.motorThermal,brakeFade:t.brakeFade??r.brakeFade,airTempC:G1(t.airTempC??r.airTempC),...Da(Wp(t.air??r.air))?{air:Wp(t.air??r.air)}:{},diffYaw:t.diffYaw??r.diffYaw,racingLine:t.racingLine??r.useRacingLine,standingStart:t.standingStart??(a?a.standingStart===!0:r.standingStart),lapCounts:t.lapCounts??r.lapCounts,numerics:Bt(r.numerics)}}async function ch(e,t){let r=e.tracks.find(n=>n.id===e.activeTrackId)??e.tracks[0];if(!r)throw new Error("this project holds no track \u2014 add one with track_select before running a lap event");return{entry:r,asset:await Hu(r,t)}}function q1(e,t){let r=structuredClone(e);for(let[n,o]of Object.entries(t))if(!si(r,n,o))throw new Error(`no parameter is labelled "${n}" on this car \u2014 read vehicle_get for the labels it has`);return r}var X1=(e,t)=>{let r=e?.name;return typeof r=="string"&&r?r:t};function gz(e,t){let r={};for(let n of Po){let o=e[n.doc]??[];for(let i of n.slots.slice(1)){let c=t[i.ref],l=typeof c=="string"?o.find(u=>u.id===c):void 0;l&&(r[i.key]={id:l.id,name:X1(l.model,l.id)})}let a=t[n.ref],s=typeof a=="string"?o.find(i=>i.id===a):void 0;if(s){r[n.doc]={id:s.id,name:X1(s.model,s.id)};continue}if(n.doc==="suspensions"){let i=o.find(c=>c.id===e.activeSuspensionId)??o[0];r[n.doc]=i?{id:i.id,name:X1(i.model,i.id),byFallback:!0}:null;continue}r[n.doc]=null}return r}function yz(e){return Object.values(e.events).map(t=>({id:t.id,label:t.label,kind:t.kind,time:t.time,lapTime:t.lapTime,distance:t.distance,laps:t.laps,...t.energy?{energyConsumedKwh:t.energy.consumed,energyRemaining:t.energy.remainingFraction}:{},...t.lapsOverridden?{lapsOverridden:t.lapsOverridden}:{},...t.incomplete?{incomplete:t.incomplete}:{},...t.energyTarget?{energyTarget:t.energyTarget}:{}}))}function QD(e){let t=new Map;for(let{name:r,events:n}of e)for(let o of n){let a=t.get(o.label);a||t.set(o.label,a={event:o.label,finished:[],stopped:[]}),(o.incomplete?a.stopped:a.finished).push(r)}return[...t.values()].filter(r=>r.stopped.length>0)}var Q1=e=>e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;async function lh(e,t,r={}){let n=io(e,r.settings),{entry:o,asset:a}=await ch(e,t),s=rs(e),i=r.vehicleIds?.length?r.vehicleIds.map(f=>{let h=e.vehicles.find(b=>b.id===f);if(!h)throw new Error(`this project holds no vehicle "${f}"`);return h}):e.vehicles.filter(f=>f.visible);if(!i.length)throw new Error("no vehicle is visible in this project \u2014 name some in vehicleIds");let c=i.map(f=>{let h=r.overrides?.[f.id]?q1(f.params,r.overrides[f.id]):f.params;return ns(structuredClone(h),s,n)}),l=Xl(Pa(e.meta.rulesetId,e.rulesets)),u=eu(c,a,n.numerics,l,{racingLine:n.racingLine,standingStart:n.standingStart,lapCounts:n.lapCounts}),m={};i.forEach((f,h)=>{m[f.id]=u[h]});let{scores:p,field:d}=ix(l,m);return{rulesetId:e.meta.rulesetId,track:o.name,settings:{ggvMode:n.ggvMode,quasiTransient:n.quasiTransient,motorThermal:n.motorThermal,brakeFade:n.brakeFade,airTempC:n.airTempC,...n.air?{air:n.air}:{},diffYaw:n.diffYaw,racingLine:n.racingLine,standingStart:n.standingStart},fleetScored:p!==null,vehicles:i.map((f,h)=>({id:f.id,name:u[h].name||String(f.params.name??f.id),events:yz(u[h]),metrics:cx(l,u[h],d?.[f.id]),fitted:gz(e,f.params),...p?.[f.id]?{score:{total:p[f.id].total,parts:{...p[f.id].parts}}}:{}})),raw:{results:m,scores:p,field:d}}}async function ZD(e,t,r){let n=e.vehicles.find(i=>i.id===r.vehicleId);if(!n)throw new Error(`this project holds no vehicle "${r.vehicleId}"`);let o=io(e),{asset:a}=await ch(e,t),s=ns(structuredClone(n.params),rs(e),o);return qD(s,a,{...r.steps?{steps:r.steps}:{},numerics:o.numerics,...r.tolPct!==void 0?{tolPct:r.tolPct}:{},...r.onStep?{onStep:r.onStep}:{}})}var ike=Math.PI/180;var fke=Math.PI/180;var eE=["rollBar.front.wheelRate","param.arb_front","roll.front.rate","roll.front.wheelRate"];function Z1(e){for(let t of eE){let r=e.findIndex(n=>n.id===t);if(r>=0)return r}return-1}var tE="dyn.tlltdFront",J1=1e-6;function uh(e){let t=gt(e),r=t["rollBar.front.wheelRate"];if(r&&!r.supersededBy){let c=r.read(e);if(c>0)return{id:r.id,def:r,now:c}}let n=t["param.arb_front"];if(!n)return{why:"the car states no front anti-roll bar"};let o=n.supersededBy,a=o?o.useInstead:n.id,s=a?t[a]:void 0;if(!s||s.supersededBy)return{why:`its front bar is ${(o?.why??"computed elsewhere").replace(/^computed from /,"")}, whose rate is not one number to re-solve`};let i=s.read(e);return i>0?{id:s.id,def:s,now:i}:Rl(e.vehicle,e.params,"front")?{why:"its front bar stands beside a roll damper and is described by its section, whose rate is not one number to re-solve"}:{why:"the car has no front bar to re-solve: its rate is zero"}}function rE(e,t,r,n,o=J1,a){let s=0,i=b=>(s++,e(b)-t),c=(b,g,y)=>({value:b,reading:t+g,reached:y,reads:s});if(a!==void 0&&a>=r&&a<=n){let b=i(a);if(Math.abs(b)<=o)return c(a,b,!0)}let l=r,u=n,m=i(l),p=i(u);if(!Number.isFinite(m)||!Number.isFinite(p))return c(NaN,NaN,!1);if(Math.abs(m)<=o)return c(l,m,!0);if(Math.abs(p)<=o)return c(u,p,!0);if(m*p>0)return Math.abs(m)<=Math.abs(p)?c(l,m,!1):c(u,p,!1);let d=0,f=l,h=m;for(let b=0;b<60;b++){if(f=(l*p-u*m)/(p-m),h=i(f),!Number.isFinite(h))return c(NaN,NaN,!1);if(Math.abs(h)<=o||Math.abs(u-l)<=1e-12*Math.max(1,Math.abs(f)))break;h*p>0?(u=f,p=h,d===-1&&(m/=2),d=-1):(l=f,m=h,d===1&&(p/=2),d=1)}return c(f,h,Math.abs(h)<=o)}function mh(e,t){let r=Z1(e.variables);if(r<0)return{why:"the front bar is not one of the variables"};let n=t.byId[tE];if(!n)return{why:"the balance cannot be read here"};let o=NaN;try{o=vt(e.build(Gr(e.variables)).ev,n)}catch{}return Number.isFinite(o)?{slot:r,target:o,metric:n}:{why:"the car\u2019s balance could not be read"}}function dh(e,t,r){let n=e.variables[r.slot],a=rE(i=>{let c=t.slice();c[r.slot]=i;try{return vt(e.build(c).ev,r.metric)}catch{return NaN}},r.target,Math.max(0,n.lo),Math.max(0,n.hi),J1,t[r.slot]),s=t.slice();return Number.isFinite(a.value)&&(s[r.slot]=a.value),{x:s,held:{value:s[r.slot],balance:a.reading,target:r.target,reached:a.reached}}}var ev="param.m",tv=.01;function rv(e,t,r){return r===void 0||!Number.isFinite(r)||r===0||!Number.isFinite(e)||!Number.isFinite(t)?NaN:(e-t)/r}var uMe=Math.PI/180;var ph=.5,Dz=new Set(["lap","session"]);function Ez(e){return dt({...e,label:e.label.replace(/ [xyz]$/,"")})}function nE(e){let t=Ua(e);if(t)return[t.point];let r=Pr(e);if(r)return[r.point];let n=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(n){let a=Rr[n[2]];return[`hp.${n[1]}.${a.fore}`,`hp.${n[1]}.${a.aft}`]}let o=/^rocker\.(front|rear)\./.exec(e);return o?[`hp.${o[1]}.${Sn.fore}`,`hp.${o[1]}.${Sn.aft}`]:[]}function oE(e,t){let r=Kt(e,t),n=gt(e),o=new Map;for(let a of[...r.variables,...r.followers??[]])for(let s of nE(a.id)){if(o.has(s))continue;let i=_i.map(c=>`${s}.${c}`).filter(c=>n[c]&&!n[c].supersededBy);i.length&&o.set(s,{id:s,name:Ez(n[i[0]]),coords:i})}return[...o.values()]}function nv(e,t,r,n={},o=ph){let a=Kt(e,t),s=(n.metrics??xr()).byId,i=zi(e,a,r),c=oE(e,a),l=gt(i),u=[];a.objectives.forEach((k,w)=>{let P=s[k.metricId];P&&u.push({key:k.key??`target:${w}`,role:"target",metric:P,at:k.at})}),a.constraints.forEach((k,w)=>{let P=s[k.metricId];P&&u.push({key:k.key??`hold:${w}`,role:"hold",metric:P,at:k.at,hold:k})}),(a.watches??[]).forEach((k,w)=>{let P=s[k.metricId];P&&u.push({key:k.key??`watch:${w}`,role:"watch",metric:P,at:k.at})});let m=u.filter(k=>!Dz.has(k.metric.cost)),p=k=>{let w=ah(k,a,n),P=m.map(L=>vt(w,L.metric,L.at));return w.failure?null:P},d=p(i)??m.map(()=>NaN),f=[],h=[],b=[],g=1,y=[...d],x=[...d],R=k=>k.forEach((w,P)=>{Number.isFinite(w)&&(w>=y[P]||(y[P]=w),w<=x[P]||(x[P]=w))}),v=k=>{g++;try{return p(k())}catch{return null}};for(let k of c)for(let w of k.coords){let P=l[w],L=P.read(i),E=w.slice(w.lastIndexOf(".")+1),_=v(()=>P.write(i,L+o)),D=v(()=>P.write(i,L-o));if(!_||!D){b.push(`${k.name} ${E}`);continue}f.push({id:w,def:P,now:L,point:k,axis:E}),h.push([_,D]),R(_),R(D)}let S=new Map,A=k=>{let w=k.join("");if(S.has(w))return;let P=v(()=>f.reduce((L,E,_)=>E.def.write(L,E.now+k[_]*o),i));S.set(w,P),P&&R(P)};f.length>1&&m.forEach((k,w)=>{let P=h.map(([L,E])=>L[w]-d[w]>=E[w]-d[w]?1:-1);Number.isFinite(d[w])&&(A(P),A(P.map(L=>-L)))});let C=[...S.values()].filter(k=>!k).length;C&&b.push(`${C} of ${S.size} corners`);let F=u.map(k=>{let w={key:k.key,role:k.role,name:bt(k.metric)+Ja(k.at,k.metric,a),unit:k.metric.unit==="-"?"":k.metric.unit,...k.hold?{limit:{op:k.hold.op,limit:k.hold.limit,...k.hold.limit2!==void 0?{limit2:k.hold.limit2}:{}}}:{}},P=m.indexOf(k);if(P<0)return{...w,value:NaN,lo:NaN,hi:NaN,skipped:"read off a lap"};let L=d[P],E=Number.isFinite(L)?y[P]:NaN,_=Number.isFinite(L)?x[P]:NaN,D=h.map(([V,H])=>Math.max(Math.abs(V[P]-L),Math.abs(H[P]-L))),I=D.filter(Number.isFinite).reduce((V,H)=>V+H,0),N;if(I>0){let V=D.indexOf(Math.max(...D.filter(Number.isFinite)));N={point:f[V].point.name,axis:f[V].axis,share:D[V]/I}}let O=k.hold?Math.max(No(k.hold,E),No(k.hold,_)):void 0;return{...w,value:L,lo:E,hi:_,...N?{most:N}:{},...O!==void 0?{excess:O}:{}}}),T=new Set(c.flatMap(k=>k.coords)),M=a.variables.filter(k=>!nE(k.id).length&&!T.has(k.id)).length;return{mm:o,points:c,rows:F,evaluations:g,unsolved:b,settings:M}}function ov(e){if(!e.chassis)return e;let{chassis:t,...r}=e;return t.boxes.length?{...r,chassis:{boxes:t.boxes}}:r}var lFe=180/Math.PI;var h6={id:"racecar",label:"Race car",description:"Suspension kinematics, tyres, powertrain and quasi-steady-state lap simulation for a four-wheeled race car.",tools:["laptime","garage","kinematics","track","studies","dynamics","tires","aero","powertrain","battery","brakes","dampers","forces","calibration"],defaultRulesetId:Ta,templateIds:["fs-ev-comparison","fs-endurance-energy","fs-ev-single","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor","formula-1","touring-car","street-car","cup-car","stock-car","hill-climb","race-truck","suspension","direct-coilover","pushrod","pullrod","third-spring","mcpherson-strut","tyre-study"],collections:[{id:"start",label:"Start here",description:"What the model answers, then cars to build from.",templateIds:["fs-ev-comparison","fs-endurance-energy","suspension","tyre-study","fs-ev-single","formula-1","touring-car"]},{id:"formula-student",label:"Formula Student",description:"Electric and combustion cars on the five Formula Student events, by drive layout.",templateIds:["fs-ev-comparison","fs-endurance-energy","suspension","tyre-study","fs-ev-single","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor"]},{id:"circuits",label:"Circuit racing",description:"Single-seaters, GT, cup and road cars and a race truck on real circuits, with their heights.",templateIds:["formula-1","touring-car","street-car","cup-car","race-truck"]},{id:"ovals-hill-climbs",label:"Ovals and hill climbs",description:"A banked oval, and an open course climbed from rest in thin air.",templateIds:["stock-car","hill-climb"]},{id:"kinematics",label:"Suspension and kinematics",description:"Each suspension architecture: its hardpoints, its roll centres and what it does on track.",templateIds:["suspension","direct-coilover","pushrod","pullrod","third-spring","mcpherson-strut"]},{id:"tyres",label:"Tyres",description:"Grip curves, and what a tyre is worth on track.",templateIds:["tyre-study"]},{id:"powertrain",label:"Energy and powertrain",description:"What a pack lasts, and how each drive layout puts its power down.",templateIds:["fs-endurance-energy","fs-combustion","fs-ev-awd","fs-ev-rwd-hubs","fs-ev-one-motor"]}]};var BCe=h6.id;var os=.02;function gE(e){let t=Math.max(os,Math.abs(e.heaveMotionRatio)),r=Math.max(os,Math.abs(e.rollMotionRatio)),o=2*(e.cornerWheelRate+e.heaveWheelRate)/(t*t),a=2*(e.cornerDamper+(e.heaveWheelDamping??0))/(t*t),s=(e.cornerDamper+(e.rollWheelDamping??0))/(r*r);return{heaveRate:o,heaveDamper:a,rollWheelRate:e.cornerWheelRate+e.arbWheelRate,rollDamper:s}}var g6=(e,t)=>({od:t,id:Math.min(e.id,t-.5)}),y6=(e,t)=>e/(2*t*t);function bE(e,t){switch(e.kind){case"ubar":case"blade":case"torsionTube":return{...e,section:g6(e.section,t)};default:return e}}function iv(e,t,r){let n=Math.max(os,Math.abs(r));if(e?.kind==="coil"){let l=y6(t,n),u=e.rate;if(typeof u=="number")return{...e,rate:l};let m=Un(u,0);if(!(m>0))return{...e,rate:l};let p=l/m;return{...e,rate:{...u,y:u.y.map(d=>d*p)}}}let o=t/(n*n),a=e&&(e.kind==="ubar"||e.kind==="blade"||e.kind==="torsionTube")?e:{kind:"torsionTube",section:{od:20,id:16},length:400,leverArm:60,G:8e4},s=l=>bl(bE(a,l),0).rateAtLink,i=4,c=60;if(s(c)<o)return{kind:"direct",wheelRate:t};for(let l=0;l<80&&c-i>1e-9;l++){let u=.5*(i+c);s(u)<o?i=u:c=u}return bE(a,c)}function yE(e,t,r,n){let o=e?.design,a=iv(t?.design,r.rollWheelRate,n);return{heave:{design:{kind:"coil",rate:r.heaveRate,motionRatio:o?.kind==="coil"?o.motionRatio:1,gap:0,bothWays:!0},linkage:e?.linkage,damper:r.heaveDamper},arb:{design:a,linkage:t?.linkage,damper:a.kind==="coil"?r.rollDamper/2:r.rollDamper}}}var x6=Math.PI/180,fh=1e-6;function R6(e){return!(Le(e.rockerPivotA,e.rockerPivotB)<fh||Le(e.rockerToPushrod,e.rockerPivotA)<fh||Le(e.rockerToDamper,e.rockerPivotA)<fh||Le(e.rockerToDamper,e.damperChassis)<fh)}function kE(e){if(!R6(e.hardpoints))return!1;let t={...e,config:{...e.config,actuation:"rocker"}};try{let r=Tt(t);for(let n of[-20,-1,0,1,20]){let o=Ce(r,n,0);if(!o.ok||!Number.isFinite(o.state.metrics.damperLength))return!1}return!0}catch{return!1}}function cv(e){if(e.config.actuation!=="direct"||kE(e))return;let{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}=k6(e);return{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}}var xE=40;function hh(e,t={}){let r=e.hardpoints,n=r.pushrodOuter,o=r.damperChassis,a=Le(n,o),s=ne(n,Q($(o,n),v6)),i=t.armRod??Math.max(25,.15*a),c=t.armDamper??i,l=[s[0]-xE,s[1],s[2]],u=[s[0]+xE,s[1],s[2]],m=ee($(u,l)),p=$(n,s),d=ee($(p,Q(m,RE(p,m)))),f=ir(d,m,(t.armAngleDeg??60)*x6),h=ne(s,Q(f,i)),b=$(o,s),g=ee($(b,Q(m,RE(b,m)))),y=Q(ee(me(m,g)),t.damperSide??1),x=ne(s,Q(y,c));return{...r,rockerPivotA:l,rockerPivotB:u,rockerToPushrod:h,rockerToDamper:x}}var v6=.72,RE=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function vE(e){let t=ut(e,{travelMin:-5,travelMax:5,steps:3}),[r,,n]=t.samples;if(!r||!n)return 0;let o=n.travel-r.travel;return o!==0?Math.abs((n.metrics.damperLength-r.metrics.damperLength)/o):0}function k6(e,t={}){let r=t.target??vE(e),n=t.armAngleDeg,o=hh(e,{armAngleDeg:n});if(!(r>0))return o;let a=Le(e.hardpoints.pushrodOuter,e.hardpoints.damperChassis),s=Math.max(25,.15*a),i=(()=>{for(let d of[1,-1]){let f=hh(e,{armRod:s,armAngleDeg:n,damperSide:d}),h={...e,config:{...e.config,actuation:"rocker"},hardpoints:f};try{let b=Tt(h),g=Ce(b,15,0),y=Ce(b,-15,0);if(g.ok&&y.ok&&g.state.metrics.damperLength<y.state.metrics.damperLength)return d}catch{}}return 1})(),c=(d,f)=>{try{return vE({...e,config:{...e.config,actuation:"rocker"},hardpoints:hh(e,{armRod:d,armAngleDeg:n,armDamper:f,damperSide:i})})}catch{return Number.NaN}},l=[1,.6,.35,.2,1.7,2.6].map(d=>Math.max(12,s*d)),u=s,m=s,p=1/0;for(let d of l){let f=.25*d,h=6*d,b=d;for(let y=0;y<24;y++){let x=(f+h)/2,R=c(d,x);if(!Number.isFinite(R))break;b=x,R<r?f=x:h=x}let g=Math.abs(c(d,b)-r);if(Number.isFinite(g)&&g<p&&(p=g,u=d,m=b),p<1e-4*Math.max(1,r))break}return hh(e,{armRod:u,armAngleDeg:n,armDamper:m,damperSide:i})}var JCe=Array.from({length:19},(e,t)=>-45+5*t);var eTe=Math.PI/180;function M6(e){let t=e.hardpoints,r=ee($(t.rockerPivotB,t.rockerPivotA)),n=Ln(t.rockerToDamper,t.rockerPivotA,r),o=.6*Zr($(t.rockerToDamper,n)),a=me(r,uk),s=Zr(a)>1e-6?ee(a):ee($(t.rockerToDamper,n));return{outer:ne(n,Q(s,o)),inner:ne(n,Q(s,-o)),attach:"rocker"}}var ME=(e,t)=>({...e,config:{...e.config,actuation:t}});function lv(e,t,r,n){let o=r==="front"?e.front:e.rear,a=t.decoupledElements?.[r],s=cv(o);if(a&&F6(o,t,r,a)){let L=a.kept;return{heave:L.heave??{design:{kind:"none"}},arb:L.arb??{design:{kind:"none"}},cornerDamper:L.damper,scalars:{heave:L.heaveSpring,arb:L.arbRate},rollBar:L.rollBar??null,...s?{crank:s}:{}}}let i=oi(o),c=o.config.springRate*i*i,l=J(t,r==="front"?"damper_front":"damper_rear")*i*i,u=r==="front"?t.arbFrontDesign:t.arbRearDesign,m=kl(e,t)[r],p=S6(u,a,n),d=p?0:m??J(t,r==="front"?"arb_front":"arb_rear"),f=ba(e,t)[r]??J(t,r==="front"?"heave_spring_front":"heave_spring_rear"),h=ME(s?{...o,hardpoints:{...o.hardpoints,...s}}:o,"decoupled"),b=r==="front"?t.heaveFrontDesign:t.heaveRearDesign,g=a?a.kept.heave:b,y=a?a.kept.arb:p?void 0:u,x=n?.heave??bh(g?.linkage,L=>Wo(h,L).atDesign)??Lb(h,"rockerToRocker"),R=!y||y.design.kind==="none"||y.design.kind==="coil",v=R?"coil":"ubar",S=y?.linkage&&(a||y.design.kind==="none"||y.linkage.attach!=="rocker")?y.linkage:void 0,A=n?.roll??bh(R?S:y?.linkage,L=>zo(h,L,{kind:v}).atDesign)??(R?M6(h):uw(h)),C=Wo(h,x).atDesign,F=zo(h,A,{kind:v}).atDesign,T=zd(e,t),M=gE({cornerWheelRate:c,cornerDamper:l,arbWheelRate:d,heaveWheelRate:f,heaveWheelDamping:r==="front"?T.heaveFront:T.heaveRear,rollWheelDamping:r==="front"?T.rollFront:T.rollRear,heaveMotionRatio:C,rollMotionRatio:F}),k=!y||y.design.kind==="none"?{design:{kind:"coil",rate:1},linkage:A}:{...y,linkage:A},w=yE({design:g?.design??{kind:"none"},linkage:x,damper:g?.damper},k,M,F),P=(L,E)=>a&&E?.coilover&&L.linkage===E.linkage?{...L,coilover:E.coilover}:L;return{heave:P(w.heave,g),arb:P(w.arb,y),cornerDamper:J(t,r==="front"?"damper_front":"damper_rear")*C6(o,"rocker").f,rollBar:p?A6(h,p,m??0,a?.kept.rollBar?.linkage):null,...s?{crank:s}:{}}}function S6(e,t,r){if(!(!ha(e)||r?.roll))return t?t.kept.rollBar!==void 0&&!ha(t.kept.arb)?e:void 0:e}function A6(e,t,r,n){let{damper:o,...a}=t,s=a.design.kind,i=p=>zo(e,p,{kind:s}),c=bh(n,p=>i(p).atDesign)??a.linkage,l={...a,...c?{linkage:c}:{}},u=fa(a.design,c?i(c):null,0).wheelRate;if(Math.abs(u-r)<=1e-9*Math.max(1,r))return l;let m=bh(c,p=>i(p).atDesign)??mw(e);return{...a,design:iv(a.design,r,i(m).atDesign),linkage:m}}function w6(e,t){let r=t==="front"?e.heaveFrontDesign:e.heaveRearDesign,n=t==="front"?e.arbFrontDesign:e.arbRearDesign,o=t==="front"?e.rollBarFrontDesign:e.rollBarRearDesign;return{...r?{heave:r}:{},...n?{arb:n}:{},...o?{rollBar:o}:{},damper:J(e,t==="front"?"damper_front":"damper_rear"),heaveSpring:J(e,t==="front"?"heave_spring_front":"heave_spring_rear"),arbRate:J(e,t==="front"?"arb_front":"arb_rear")}}function F6(e,t,r,n){let o=e.config.decoupledSpring;return o!==void 0&&o.wrote===e.config.springRate&&Gu(w6(t,r),n.wrote)}function bh(e,t){return e&&Math.abs(t(e))>=os?e:void 0}function C6(e,t){let r=t==="rocker"?cv(e):void 0,n=ME(r?{...e,hardpoints:{...e.hardpoints,...r}}:e,t),o=oi(e),a=oi(n);return{next:n,f:o>=os&&a>=os?(o/a)**2:1,...r?{crank:r}:{}}}var gh=[{id:"direct",name:"Direct-acting coilover",family:"GT / touring car",description:"Each lower wishbone drives a coilover straight into a chassis tower. No rod or rocker in the load path.",scope:"Both axles",tags:["Double wishbone","Coilover","Direct acting"]},{id:"pushrod",name:"Pushrod suspension",family:"Formula / prototype",description:"A rod from the lower wishbone pushes a rocker on the chassis shoulder. A 225 mm damper runs along the top at 1:1.",scope:"Both axles",tags:["Pushrod","Rocker","Inboard damper"]},{id:"pullrod",name:"Pullrod suspension",family:"Formula / low package",description:"A rod from the upper wishbone pulls a low rocker inside the side wall. A 225 mm damper runs along the floor at 1:1.",scope:"Both axles",tags:["Pullrod","Low rocker","Inboard damper"]},{id:"heave",name:"Third heave spring",family:"Formula / aero platform",description:"The pushrod car plus a front third spring worked by both rockers. It picks up after 5 mm of bump and stays out of roll.",scope:"Both axles, plus a front third spring",tags:["Pushrod","Third spring","Aero platform"]},{id:"decoupled",name:"Twin-rocker-bar decoupled modes",family:"Formula / prototype",description:"Each pushrod turns a long rocker bar. A shock between the bars takes heave, a diagonal one takes roll; no corner springs.",scope:"Both axles",tags:["Two rocker bars","Heave shock","Roll shock"]},{id:"mcpherson",name:"McPherson strut",family:"Road car",description:"A strut clamped to the upright runs up to a top mount on the tower: damper, spring seat and upper link in one. Coilover wishbones at the rear.",scope:"Front struts, rear double wishbones",tags:["McPherson","Strut","Road car"]}],uv=()=>({arbFront:void 0,arbRear:void 0,heaveFront:void 0,heaveRear:void 0}),T6={front:{rockerPivotA:[-47,223,405],rockerPivotB:[-47,267,445],rockerToPushrod:[8,242,429],rockerToDamper:[-47,190,485],damperChassis:[-272,190,485]},rear:{rockerPivotA:[65,228,415],rockerPivotB:[65,272,455],rockerToPushrod:[10,247,439],rockerToDamper:[65,195,495],damperChassis:[290,195,495]}},P6={front:{pushrodOuter:[-3,510,359],rockerPivotA:[-20,174,181],rockerPivotB:[-20,200,139],rockerToPushrod:[18,199,167],rockerToDamper:[-20,102,108],damperChassis:[205,102,108]},rear:{pushrodOuter:[-1,516,365],rockerPivotA:[39,177,181],rockerPivotB:[39,203,139],rockerToPushrod:[1,202,167],rockerToDamper:[39,112,111],damperChassis:[-186,112,111]}},L6=()=>({outer:[0,189,486],attach:"rocker",mount:{kind:"chassis",anchor:[-225,0,486]}}),D6={rate:60,motionRatio:1},E6={front:{rockerPivotA:[-50,310,621],rockerPivotB:[-50,357,659],rockerToPushrod:[10,330,644],rockerToDamper:[-50,281,704],damperChassis:[-275,281,704]},rear:{rockerPivotA:[73,306,621],rockerPivotB:[73,352,659],rockerToPushrod:[13,326,644],rockerToDamper:[73,271,710],damperChassis:[298,271,710]}},I6=e=>e==="front"?{outer:[-2,280,705],attach:"rocker",mount:{kind:"chassis",anchor:[-227,0,705]}}:{outer:[25,270,711],attach:"rocker",mount:{kind:"chassis",anchor:[250,0,711]}},_6={kind:"coil",rate:1560,motionRatio:1,gap:0,bothWays:!0},N6=40,O6={rockerPivotA:[50,130,440],rockerPivotB:[-50,130,440],rockerToPushrod:[10,170,460],rockerToDamper:[-20,64,440],damperChassis:[-20,64,215]},SE=()=>({outer:[-50,130,480],attach:"rocker",shaftStation:-50}),AE=()=>({outer:[50,130,400],inner:[50,130,480],attach:"rocker",shaftStationOuter:50,shaftStationInner:50}),V6=e=>[e[0],e[1],e[2]];function B6(e){let t=r=>({...r,hardpoints:{...r.hardpoints,...FE(O6)},config:{...r.config,actuation:"decoupled"}});return{...e,front:t(e.front),rear:t(e.rear)}}function FE(e){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,V6(r)]))}function CE(e,t=Na(),r=e==="pull"?P6:T6){let n=(o,a)=>({...o,hardpoints:{...o.hardpoints,...FE(r[a])},config:{...o.config,actuation:"rocker",rodType:e,...e==="pull"?{pushrodAttach:"upperArm"}:{}}});return{...t,front:n(t.front,"front"),rear:n(t.rear,"rear")}}function yh(e,t){let r=mv(e),n=Yi(e);if(e==="heave")return{meta:r,vehicle:n,components:{...uv(),heaveFront:{design:{...X0,...D6},linkage:L6()}}};if(e!=="decoupled")return{meta:r,vehicle:n,components:uv()};let o=lv(n,t,"front",{heave:SE(),roll:AE()}),a=lv(n,t,"rear",{heave:SE(),roll:AE()});return{meta:r,vehicle:n,components:{arbFront:o.arb,arbRear:a.arb,heaveFront:o.heave,heaveRear:a.heave}}}function Yi(e){let{name:t}=mv(e);if(e==="direct")return{...nu(),name:t};if(e==="mcpherson"){let n=ou(),o=Xp();return{...n,front:{...o,config:{...o.config,loadedRadius:n.front.config.loadedRadius}},name:t}}let r=$6(CE(e==="pullrod"?"pull":"push"));return{...e==="decoupled"?B6(r):r,name:t}}var wE={front:221.7,rear:220.9};function $6(e){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:wE.front}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:wE.rear}}}}function mv(e){let t=gh.find(r=>r.id===e);if(!t)throw new Error(`Unknown suspension template: ${e}`);return t}function xh(){let e=t=>({design:{..._6},linkage:I6(t),damper:N6});return{meta:mv("heave"),vehicle:CE("push",hx(),E6),components:{...uv(),heaveFront:e("front"),heaveRear:e("rear")}}}var TE=[10,25,50,100,200,300],G6=[{id:"c1",label:"Soft",scale:.7},{id:"c2",label:"Medium",scale:1},{id:"c3",label:"Firm",scale:1.4}],PE=e=>Math.round(e*100)/100;function K6(e,t,r){let n=TE.map(o=>PE(r*o));return{id:e,label:t,speedMmS:[...TE],bumpN:n,reboundN:[...n]}}function H6(e){return{name:e.name,body:{...e.body},curves:G6.map(t=>K6(t.id,t.label,PE(e.coefficient*t.scale)))}}function zu(e,t){let r=(t.heave??t.car).coefficient,n=(t.roll??t.car).coefficient,o=(a,s)=>a?.damper?{...a,damper:s}:a;return{arbFront:o(e.arbFront,n),arbRear:o(e.arbRear,n),heaveFront:o(e.heaveFront,r),heaveRear:o(e.heaveRear,r)}}function An(e,t){let r=i=>{if(!i)return;let c=e.dampers.length+1;for(;e.dampers.some(u=>u.id===`dmp${c}`);)c++;let l=`dmp${c}`;return e.dampers.push({id:l,color:uu[e.dampers.length%uu.length],model:H6(i)}),l},n=r(t.car),o=r(t.rear),a=r(t.heave),s=r(t.roll);for(let i of e.vehicles){let c=i.params;c.damperModelId=n,o&&(c.damperModelIdRear=o),a&&(c.heaveDamperModelId=a),s&&(c.rollDamperModelId=s)}}var Ht=e=>`${e} (typical)`,dv={car:{name:Ht("Formula Student damper"),coefficient:2.5,body:{extended:249,stroke:55}}},Rh={car:dv.car,heave:{name:Ht("Formula Student heave damper"),coefficient:3.4,body:{extended:270,stroke:47}},roll:{name:Ht("Formula Student roll damper"),coefficient:3.7,body:{extended:322,stroke:100}}},vh={car:{name:Ht("Formula 1 damper"),coefficient:6,body:{extended:240,stroke:40}},heave:{name:Ht("Formula 1 heave damper"),coefficient:40,body:{extended:240,stroke:40}}},LE={car:{name:Ht("GT damper"),coefficient:4.5,body:{extended:510,stroke:80}}},pv={car:{name:Ht("Sports car damper"),coefficient:2.4,body:{extended:515,stroke:110}}},DE={car:{name:Ht("Sports car strut"),coefficient:2.4,body:{extended:310,stroke:120}},rear:pv.car},EE={car:{name:Ht("Cup car strut"),coefficient:4,body:{extended:285,stroke:75}},rear:{name:Ht("Cup car rear damper"),coefficient:3.5,body:{extended:505,stroke:80}}},IE={car:{name:Ht("Stock car front damper"),coefficient:7.5,body:{extended:555,stroke:110}},rear:{name:Ht("Stock car rear damper"),coefficient:6.75,body:{extended:555,stroke:110}}},_E={car:{name:Ht("Hill-climb front damper"),coefficient:3,body:{extended:285,stroke:65}},rear:{name:Ht("Hill-climb rear damper"),coefficient:3.5,body:{extended:285,stroke:65}}},NE={car:{name:Ht("Race truck front damper"),coefficient:12,body:{extended:780,stroke:160}},rear:{name:Ht("Race truck rear damper"),coefficient:8.5,body:{extended:780,stroke:160}}};var Oo=(e,t)=>({diameter:e*25.4,width:t*25.4,offset:20,wall:4}),Wi=e=>({front:e,rear:e}),fv=Wi(Oo(13,7)),OE=Wi(Oo(18,12)),VE=Wi(Oo(18,10)),BE=Wi(Oo(17,8)),$E={rear:Oo(17,8)},GE=Wi(Oo(18,9)),KE=Wi(Oo(18,12)),HE={front:Oo(22.5,9)};function co(e,t){for(let r of e.suspensions){let n={...r.model.parts};for(let o of["front","rear"]){let a=t[o];a&&(n[o]={...n[o],rim:{...a}})}(n.front||n.rear)&&(r.model.parts=n)}}function Ui(e){return e.vehicles=e.vehicles.slice(0,1),e.activeVehicleId=e.vehicles[0]?.id??null,e}function Vo(e,t){let r=mu(e);return r.meta.rulesetId=t,r}function as(e,t,r,n){let o=Vo(e,t);return o.suspensions=[{...o.suspensions[0],model:n()}],o.vehicles=[Gx(r,"v1",0)],o.activeVehicleId="v1",o}var[,z6,Y6,W6,j6,U6,X6,q6]=Mx;function hv(e,t){delete e.arbFrontDesign,delete e.arbRearDesign,delete e.rollBarFrontDesign,delete e.rollBarRearDesign,delete e.heaveFrontDesign,delete e.heaveRearDesign,t.arbFront&&(e.arbFrontDesign=structuredClone(t.arbFront)),t.arbRear&&(e.arbRearDesign=structuredClone(t.arbRear)),t.heaveFront&&(e.heaveFrontDesign=structuredClone(t.heaveFront)),t.heaveRear&&(e.heaveRearDesign=structuredClone(t.heaveRear))}function zE(){return{...Yi("decoupled"),name:Na().name}}var Q6=[{label:"Formula Student (decoupled)",vehicle:zE,components:e=>zu(yh("decoupled",e).components,Rh)},{label:"Formula 1 (third springs)",vehicle:()=>xh().vehicle,components:()=>zu(xh().components,vh)}],bv={"direct-coilover":"direct",pushrod:"pushrod",pullrod:"pullrod","third-spring":"heave","mcpherson-strut":"mcpherson"},Z6=[...Q6.map(e=>e.vehicle),...Object.values(bv).map(e=>()=>Yi(e))];function ji(e){let t=zu(yh("decoupled",e.vehicles[0].params).components,Rh);e.suspensions=[{...e.suspensions[0],model:zE()}];for(let r of e.vehicles)hv(r.params,t);return An(e,Rh),co(e,fv),e}var ss={title:"OpenStreetMap",url:"https://www.openstreetmap.org/copyright",licence:"ODbL-1.0",credit:"\xA9 OpenStreetMap contributors"},kh={title:"USGS 3D Elevation Program, 1 m lidar terrain",url:"https://www.usgs.gov/3d-elevation-program",licence:"public-domain",credit:"U.S. Geological Survey, 3D Elevation Program"},YE={title:"Digitales Gel\xE4ndemodell DGM1 Rheinland-Pfalz",url:"https://www.geoportal.rlp.de/",licence:"dl-de-by-2.0",credit:"\xA9GeoBasis-DE / LVermGeoRP 2025, dl-de/by-2-0, www.lvermgeo.rlp.de [Daten bearbeitet]"},WE={title:"USDA National Agriculture Imagery Program (NAIP), 0.6 m aerial imagery",url:"https://imagery.nationalmap.gov/arcgis/rest/services/USGSNAIPImagery/ImageServer",licence:"public-domain",credit:"USDA Farm Service Agency, National Agriculture Imagery Program, via the USGS National Map"},J6={id:"cota",name:"Circuit of the Americas, Austin",address:"e0c6ea889d708cf15f9c",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,kh,WE]}},eY={id:"laguna-seca",name:"Laguna Seca, Monterey",address:"185b5811b9c423ef44ef",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,kh,WE]}},tY={id:"nordschleife",name:"Nordschleife, N\xFCrburg",address:"74c49603c7b2f15985c6",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,YE]}},rY={id:"brands-hatch",name:"Brands Hatch, Kent",address:"c4953e3c25eaba4a5b7e",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,{title:"Environment Agency LIDAR Composite DTM, 1 m",url:"https://environment.data.gov.uk/dataset/13787b9a-26a4-4775-8523-806d13af58fc",licence:"OGL-UK-3.0",credit:"\xA9 Environment Agency copyright and/or database right 2022. All rights reserved."}]}},nY={id:"bristol",name:"Bristol, Tennessee",address:"f0e23953669a414ad600",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,kh]}},oY={id:"pikes-peak",name:"Pikes Peak, Colorado",address:"3de137fe33b5c2875036",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,kh]},standingStart:!0},aY={source:"venue",altitudeM:3580,pressure:{kind:"standard"},humidityPct:0},sY=10,iY={id:"nurburg-sprint",name:"Sprintstrecke, N\xFCrburg",address:"1875636cdbb615aa2756",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[ss,YE]}};function is(e,t){let{id:r,name:n,address:o,provenance:a,standingStart:s}=t,i={kind:"catalogue",id:r,address:o},c=au(Ex({name:n,source:i}).model,structuredClone(a));return e.tracks=[{id:"tr1",name:n,source:i,provenance:c,...s?{standingStart:s}:{}}],e.activeTrackId="tr1",e.settings.standingStart=s===!0,e}function Bo(e,t,r){let n=e.vehicles[0].params,o=`m${e.motors.length+1}`;e.motors=[...e.motors,{id:o,color:Lo[e.motors.length%Lo.length],model:t}];let a=Ew({},{...n,motorModel:t});n.motorModelId=o,n.motorCount=1,a&&(n.driveline=a),n.gear_ratio&&(n.gear_ratio={...n.gear_ratio,value:r})}var cY=3.8,Mh={hubPlanetary:14.5,inboardChain:4,engineChain:3.4},lY="Hub motor, 35 kW (example)";function gv(e,t,r,n,o,a){let s=e.vehicles[0].params;s.motorModelId=t,s.motorCount=r,s.motorPlacement=n,a&&(s.motorMount=a),s.driven_wheels={...s.driven_wheels,value:n==="awd"?4:2},s.gear_ratio={...s.gear_ratio,value:o}}function jE(e){let t=e.motors.find(r=>r.id==="m1");return t.model={...t.model,name:lY},t.id}function Sh(e,t,r){let n=Ui(ji(Vo(e,r)));return n.vehicles[0].params.name=t,n}function uY(){let e=Sh("Formula Student combustion car","Formula Student combustion","fs-cv");Bo(e,Cx(),Mh.engineChain);let t=e.vehicles[0].params;return t.power_limit_kw&&(t.power_limit_kw={...t.power_limit_kw,value:0}),t.endurance_reserve&&(t.endurance_reserve={...t.endurance_reserve,value:0}),e}function mY(){let e=Sh("Formula Student AWD car","Formula Student AWD","fs-ev");return gv(e,jE(e),4,"awd",Mh.hubPlanetary,"hub"),e}function dY(){let e=Sh("Formula Student RWD hub-motor car","Formula Student RWD hub motors","fs-ev");return gv(e,jE(e),2,"rear",Mh.hubPlanetary,"hub"),e}function pY(){let e=Sh("Formula Student one-motor car","Formula Student RWD one motor","fs-ev"),t=`m${e.motors.length+1}`;return e.motors=[...e.motors,{id:t,color:Lo[e.motors.length%Lo.length],model:Fx()}],gv(e,t,1,"rear",Mh.inboardChain),e.vehicles[0].params.driveline={rear:structuredClone(er.clutch)},e}function fY(){let e=Ui(ji(Vo("Formula Student endurance energy","fs-ev"))),t=e.vehicles[0],r=structuredClone(t);if(r.id="v2",r.color=lu[1],r.params.name=`${t.params.name} flat out`,!r.params.endurance_reserve)throw new Error("the Formula Student preset states no energy reserve");return r.params.endurance_reserve={...r.params.endurance_reserve,value:0},e.vehicles.push(r),e}function hY(){let e=xh(),t=as("Formula 1 car","trackday",z6,()=>e.vehicle);return hv(t.vehicles[0].params,zu(e.components,vh)),An(t,vh),co(t,OE),Bo(t,Tx(),cY),is(t,J6)}function UE(e="GT car",t=nu){let r=as(e,"trackday",Y6,t);return An(r,LE),co(r,VE),Bo(r,wT(),r.vehicles[0].params.gear_ratio.value),is(r,eY)}function XE(e="Sports car",t=ou,r=pv,n=BE){let o=as(e,"trackday",W6,t);return An(o,r),co(o,n),Bo(o,FT(),o.vehicles[0].params.gear_ratio.value),is(o,tY)}function bY(){let e=as("Cup car","trackday",j6,fT);return An(e,EE),co(e,GE),Bo(e,CT(),e.vehicles[0].params.gear_ratio.value),is(e,rY)}function gY(){let e=as("Stock car","trackday",U6,hT);return An(e,IE),co(e,KE),Bo(e,TT(),e.vehicles[0].params.gear_ratio.value),is(e,nY)}function yY(){let e=as("Hill-climb prototype","trackday",X6,bT);return An(e,_E),Bo(e,PT(),e.vehicles[0].params.gear_ratio.value),e.settings.air=structuredClone(aY),e.settings.airTempC=sY,is(e,oY)}function xY(){let e=as("Race truck","trackday",q6,gT);return An(e,NE),co(e,HE),Bo(e,LT(),e.vehicles[0].params.gear_ratio.value),is(e,iY)}function RY(e){let t=gh.find(o=>o.id===e);if(e==="direct")return UE(t.name,()=>Yi(e));if(e==="mcpherson")return XE(t.name,()=>Yi(e),DE,$E);let r=Ui(Vo(t.name,"trackday")),n=yh(e,r.vehicles[0].params);return r.suspensions=[{...r.suspensions[0],model:n.vehicle}],hv(r.vehicles[0].params,n.components),An(r,dv),co(r,fv),r}function Yu(e,t,r){let n=bv[e],o=gh.find(a=>a.id===n);return{id:e,domain:"racecar",kind:"start",summary:t,title:o.name,blurb:`${o.description} ${r} Move a hardpoint in Kinematics and watch the motion ratio, camber and roll centre follow, then what it costs on track.`,tags:["kinematics","suspension",...o.tags.map(a=>a.toLowerCase())],openTool:"kinematics",load:()=>RY(n)}}var vY=[{id:"fs-ev-comparison",domain:"racecar",kind:"study",summary:"Four Formula Student cars scored on all five events: what mass, power and downforce buy.",title:"Formula Student \u2014 car comparison",blurb:"A generic Formula Student electric car and three what-ifs \u2014 15 % more downforce, 15 kg lighter, 15 % more power \u2014 scored side by side on the Formula Student electric events. All four run decoupled heave and roll suspension. A good first look at what each change buys.",tags:["formula student","comparison","lap sim"],openTool:"laptime",load:()=>ji(Vo("Formula Student comparison","fs-ev"))},{id:"fs-endurance-energy",domain:"racecar",kind:"study",summary:"The FS car flat out against its energy target: which finishes endurance, and the points.",title:"Formula Student \u2014 endurance energy",blurb:"The generic Formula Student electric car twice, scored together on the Formula Student electric events: once driven to its energy target, once flat out. The two differ in the endurance reserve and nothing else. Flat out the car laps faster and its pack runs out before the flag; on the target its speed is capped so the pack finishes with 5 % left. The endurance event shows the charge lap by lap, and the points what running dry costs.",tags:["formula student","endurance","energy","battery"],openTool:"laptime",load:fY},{id:"fs-ev-single",domain:"racecar",kind:"start",summary:"A generic Formula Student electric car on the five events, to set up as your own.",title:"Formula Student \u2014 single car",blurb:"One generic Formula Student electric car on the Formula Student electric events: 300 kg with driver, two motors, 80 kW, 10-inch tyres, decoupled heave and roll suspension. The uncluttered starting point for setting up your own car.",tags:["formula student","lap sim"],openTool:"laptime",load:()=>Ui(ji(Vo("Formula Student car","fs-ev")))},{id:"fs-combustion",domain:"racecar",kind:"start",summary:"A restricted 600 cc four through six gears and a clutch-pack diff, on the CV events.",title:"Formula Student \u2014 combustion, LSD",blurb:"The generic Formula Student car with an engine: a restricted 600 cc four of about 64 kW through a six-speed box and a chain to a clutch-pack limited-slip diff, on the Formula Student combustion events. The same 300 kg chassis, tyres and decoupled suspension as the electric layouts, so the drive is the difference. Efficiency is scored on the work at the crankshaft until fuel is modelled. Representative of the class, not a measurement of any car.",tags:["formula student","combustion","engine","limited-slip diff","lsd","lap sim"],openTool:"laptime",load:uY},{id:"fs-ev-awd",domain:"racecar",kind:"start",summary:"All-wheel drive from a motor in each hub, held to 80 kW at the pack.",title:"Formula Student \u2014 AWD, four hub motors",blurb:"The generic Formula Student electric car with a motor in each of its four hubs: 35 kW hub motors on 14.5 : 1 planetaries, held to the rules\u2019 80 kW at the pack, each wheel\u2019s torque its own and every wheel braking back into the pack. The same 300 kg chassis, tyres, suspension and pack as the other layouts, so the drive is the difference; the hub motors\u2019 unsprung mass is not added. Representative of the class, not a measurement of any car.",tags:["formula student","awd","all-wheel drive","hub motors","outboard motors","lap sim"],openTool:"laptime",load:mY},{id:"fs-ev-rwd-hubs",domain:"racecar",kind:"start",summary:"Rear-wheel drive from a motor in each rear hub, with no diff between them.",title:"Formula Student \u2014 RWD, two hub motors",blurb:"The generic Formula Student electric car driven by a motor in each rear hub: two 35 kW hub motors on 14.5 : 1 planetaries with no differential between them, so each rear wheel\u2019s torque is set on its own. The pair cannot use all of the rules\u2019 80 kW. The same 300 kg chassis, tyres, suspension and pack as the other layouts, so the drive is the difference. Representative of the class, not a measurement of any car.",tags:["formula student","rwd","rear-wheel drive","hub motors","outboard motors","lap sim"],openTool:"laptime",load:dY},{id:"fs-ev-one-motor",domain:"racecar",kind:"start",summary:"One inboard motor chained to a clutch-pack diff on the rear axle.",title:"Formula Student \u2014 RWD, one motor, LSD",blurb:"The generic Formula Student electric car on one inboard motor: an axial-flux motor of 230 Nm on the chassis, chained at 4 : 1 to a clutch-pack limited-slip diff on the rear axle. The rules\u2019 80 kW at the pack holds it below its peak, and it brakes back into the pack through the diff. The same 300 kg chassis, tyres, suspension and pack as the other layouts, so the drive is the difference. Representative of the class, not a measurement of any car.",tags:["formula student","rwd","inboard motor","limited-slip diff","lsd","lap sim"],openTool:"laptime",load:pY},{id:"formula-1",domain:"racecar",kind:"start",summary:"A generic Formula 1 car on a flying lap of Austin.",title:"Formula 1 car",blurb:"A generic Formula 1 car of the 18-inch era at Austin: 798 kg with driver, a 735 kW power unit through eight gears and a clutch-pack diff, four and a half square metres of lift area on a 3.6 m wheelbase, pushrods with a third spring and heave damper on each axle, slicks with 1.8 of peak grip. One flying lap, no scoring. Every number is representative of the class, none is a measurement.",tags:["formula 1","lap sim","aero"],openTool:"laptime",load:hY},{id:"touring-car",domain:"racecar",kind:"start",summary:"A generic GT car on a flying lap of Laguna Seca.",title:"GT car",blurb:"A generic GT car at Laguna Seca: 1300 kg with driver, a 410 kW four-litre through six gears and a clutch-pack diff, 2.8 m\xB2 of lift area, coilovers on double wishbones, 18-inch slicks. One flying lap, no scoring. Representative of the class, not a measurement of any car.",tags:["gt","lap sim"],openTool:"laptime",load:UE},{id:"street-car",domain:"racecar",kind:"start",summary:"A generic sports car on road tyres, round the Nordschleife.",title:"Sports car",blurb:"A generic sports car on the Nordschleife: 1600 kg with driver, a 220 kW turbocharged six through a six-speed double-clutch box and an open diff, road tyres with about 1.0 of grip, soft springs and a little aerodynamic lift. One flying lap, no scoring. The car to start from when the question is a road car, and the one that shows what a race car's numbers actually buy.",tags:["sports car","road car","lap sim"],openTool:"laptime",load:XE},{id:"cup-car",domain:"racecar",kind:"start",summary:"A generic front-driven cup hatchback round Brands Hatch.",title:"Cup car",blurb:"A generic front-wheel-drive cup hatchback at Brands Hatch: 1265 kg with driver, a 250 kW two-litre turbo through six gears and a clutch-pack diff, a splitter and a wing, a McPherson strut front, 18-inch slicks. One flying lap, no scoring. Representative of the class, not a measurement of any car.",tags:["cup car","front-wheel drive","lap sim"],openTool:"laptime",load:bY},{id:"stock-car",domain:"racecar",kind:"start",summary:"A generic stock car on Bristol\u2019s half-mile, banked 25\xB0.",title:"Stock car",blurb:"A generic stock car of the American oval series at Bristol, the half-mile banked 25\xB0: 1620 kg with driver, a 500 kW 5.9-litre V8 through five gears and a clutch-pack diff, double wishbones on stiff springs, 18-inch slicks, set up the same on both sides. One flying lap, no scoring. Representative of the class, not a measurement of any car.",tags:["stock car","oval","lap sim"],openTool:"laptime",load:gY},{id:"hill-climb",domain:"racecar",kind:"start",summary:"A generic hill-climb prototype up Pikes Peak, from rest, in thin air.",title:"Hill-climb prototype",blurb:"A generic hill-climb sports prototype on Pikes Peak, 19.99 km and 1,440 m up to the summit: 650 kg with driver, a 330 kW turbocharged two-litre through six gears and a clutch-pack diff, 3 m\xB2 of lift area, pushrods, 13-inch slicks. It runs in the mountain\u2019s thin air, which costs its wings a third of their downforce. One run, no scoring. Representative of the class, not a measurement of any car.",tags:["hill climb","altitude","lap sim"],openTool:"laptime",load:yY},{id:"race-truck",domain:"racecar",kind:"start",summary:"A generic European race truck round the N\xFCrburg Sprintstrecke, held to 160 km/h.",title:"Race truck",blurb:"A generic European circuit race truck on the N\xFCrburg Grand Prix circuit\u2019s 3.6 km Sprintstrecke: a cab-over tractor at the class\u2019s 5300 kg minimum, 60 % of it on the front axle, an 880 kW 13-litre diesel through a twelve-speed box to a locked rear axle, geared to the 160 km/h the rules hold it to, 315/70 R22.5 tyres. One flying lap, no scoring. Representative of the class, not a measurement of any truck.",tags:["race truck","truck racing","lap sim"],openTool:"laptime",load:xY},{id:"suspension",domain:"racecar",kind:"study",summary:"The FS car\u2019s decoupled wishbones: move a hardpoint and watch the roll centre follow.",title:"Suspension kinematics study",blurb:"Opens on the double-wishbone editor with one Formula Student car. Move a hardpoint and watch camber, bump steer, motion ratio and roll-centre migration follow \u2014 then see what it costs on track.",tags:["kinematics","geometry"],openTool:"kinematics",load:()=>Ui(ji(Vo("Suspension study","trackday")))},Yu("direct-coilover","The GT car\u2019s wishbones driving coilovers straight into the towers, at Laguna Seca.","On the GT car, at Laguna Seca."),Yu("pushrod","The FS car on pushrods: a rod from each lower wishbone works a rocker.","On the Formula Student car, at FSG."),Yu("pullrod","The FS car on pullrods: a rod from each upper wishbone pulls a low rocker.","On the Formula Student car, at FSG."),Yu("third-spring","The pushrod FS car plus a front third spring that picks up after 5 mm of bump.","On the Formula Student car, at FSG."),Yu("mcpherson-strut","The sports car on McPherson struts at the front and double wishbones at the rear.","On the sports car, at the Nordschleife."),{id:"tyre-study",domain:"racecar",kind:"study",summary:"The FS tyre\u2019s grip curves at three loads, beside the other classes\u2019 tyres.",title:"Tyre model study",blurb:"One Formula Student car on its Magic Formula tyre, opened on the tyre analysis, where the grip curves that drive the whole lap come from. The library beside it holds the other seven classes' tyres and the illustrative MF6.2 example to compare against.",tags:["tyres","magic formula"],openTool:"tires",load:()=>Ui(ji(Vo("Tyre study","fs-ev")))}],qE=vY.map(e=>({...e,load:()=>Kx(e.load())}));var QE={width:320,height:200},$Te=[.6*QE.width-9,.6*QE.height-9];var ZE=new WeakMap,JE=new WeakMap,yv=e=>JSON.stringify(e,(t,r)=>r===1/0?"Infinity":r);function eI(e,t){if(!t){let a=ZE.get(e);return a||(a=hr(e),ZE.set(e,a)),a}let r=JE.get(e);r||(r=new Map,JE.set(e,r));let n=yv(t),o=r.get(n);return o||(r.size>=4&&r.clear(),o=hr(e,t),r.set(n,o)),o}var SY=Math.PI/180,AY=e=>e>1?e/100:e;function Wu(e){let t=null;return()=>(t??={v:e()}).v}function tI(e){let t=ut(e,{travelMin:-1,travelMax:1,steps:3}).samples[1],r=t.metrics.motionRatio??1;return{motionRatio:r,wheelRate:t.metrics.wheelRate??e.config.springRate*r*r}}var rI=new WeakMap,xv={heave:0,pitch:0,roll:0,steer:0},nI=[0,1,2,3,4],oI=[-20,-10,0,10,20];function sI(e,t){let r=Xn(e,xv),n=["front","rear"],o=c=>{let l=ti(c);return l?(l.left+l.right)/2:Number.NaN},a=n.map(c=>o(r[c])),s=n.map(()=>({rc:[],split:[]}));for(let c of nI){let l=c===0?null:Xn(e,{...xv,roll:c*SY});n.forEach((u,m)=>{let p=l?ti(l[u]):null,d=p&&Number.isFinite(a[m]);s[m].rc.push(d?t[m]+(p.left+p.right)/2-a[m]:t[m]),s[m].split.push(d?(p.left-p.right)/2:0)})}let i=n.map(()=>[]);for(let c of oI){let l=c===0?null:Xn(e,{...xv,heave:-c});n.forEach((u,m)=>{let p=l&&l[u].valid&&r[u].valid;i[m].push(p?t[m]+l[u].height-r[u].height:t[m])})}return{roll:{rollDeg:nI,rcFront:s[0].rc,rcRear:s[1].rc,rcSplitFront:s[0].split,rcSplitRear:s[1].split},heave:{drop:oI,rcFront:i[0],rcRear:i[1]}}}var aI=new WeakMap;function wY(e,t,r,n){let o=aI.get(e);o||(o=new Map,aI.set(e,o));let a=`${yv(r)}|${n[0]}|${n[1]}`,s=o.get(a);if(!s){o.size>=4&&o.clear();try{s=sI(eI(e,r),n)}catch{s=t.rigidMigration(n)}o.set(a,s)}return s}function FY(e){let t=rI.get(e);if(t)return t;let r=hr(e),n=Xn(r,{heave:0,pitch:0,roll:0,steer:0}),o=tI(e.front),a=tI(e.rear),s={wheelbase:e.config.wheelbase,trackFront:Qt(e.front),trackRear:Qt(e.rear),mrFront:o.motionRatio,mrRear:a.motionRatio,wheelRateFront:o.wheelRate,wheelRateRear:a.wheelRate,unsprungCgHeight:e.front.config.loadedRadius,rcHeightFront:n.front.valid?n.front.heightAboveGround:0,rcHeightRear:n.rear.valid?n.rear.heightAboveGround:0,rcGainFront:ni(n.front),rcGainRear:ni(n.rear),rigidMigration:i=>sI(r,i),kinFront:Wu(()=>Vs(e.front)),kinRear:Wu(()=>Vs(e.rear))};return rI.set(e,s),s}function iI(e,t,r,n){let o=FY(e),a=kl(e,t),s=ba(e,t),i=ww(e,t),c=zd(e,t),l=Fw(e,t),u=Cw(t,e),m=Yd(e,t),p=un(e.front),d=un(e.rear),f=pa(t.damperModel,t.damperSetup,o.mrFront,o.mrRear,t.damperModelRear??t.damperModel),h={rho:t.rho.value,area:t.A.value,cl:t.c_l.value,cw:t.c_w.value,copLongFront:1-Math.max(0,Math.min(1,J(t,"cop_long"))),copHeight:J(t,"cop_height"),...t.aeroModel?{model:t.aeroModel}:{},rideHeightFront:J(t,"ride_height_front"),rideHeightRear:J(t,"ride_height_rear")},b=9.81,g=AY(t.front_mass_diss.value),y=Ra(t,r,n),x=We(y.front),R=y.rear===y.front?x:We(y.rear),v=n??t.tireModelRear??r,S=t.m.value*b*g/2,A=t.m.value*b*(1-g)/2,C=x.corneringStiffness(S),F=R.corneringStiffness(A),T=(r?x.verticalStiffness():0)||J(t,"tire_vertical_rate"),M=(v?R.verticalStiffness():0)||J(t,"tire_vertical_rate"),k=an(r)??0,w=an(v)??0,P=qd({freeRadius:k,staticLoad:S,tyreRate:T,surveyed:e.front.config.loadedRadius},{freeRadius:w,staticLoad:A,tyreRate:M,surveyed:e.rear.config.loadedRadius},g),L=wr(k,S,T,e.front.config.loadedRadius),E=wr(w,A,M,e.rear.config.loadedRadius),_=[qn(o.rcHeightFront,o.rcGainFront,e.front.config.loadedRadius,L),qn(o.rcHeightRear,o.rcGainRear,e.rear.config.loadedRadius,E)],D=Wu(()=>Sl(o.kinFront(),J(t,"camber_front_deg"))),I=Wu(()=>Sl(o.kinRear(),J(t,"camber_rear_deg"))),N=Wu(()=>wY(e,o,Ii(H),_)),O=qc({...t,wheelbase:{...t.wheelbase,value:o.wheelbase}}),V=Ml(t),H={massTotal:t.m.value,frontMassFrac:g,steeringSystem:t.steeringSystem,tv:Dd(t),cgHeight:ai(J(t,"cg_height"),t.cgReference?.standingRadius,P),cgStandingRadius:P,wheelbase:o.wheelbase,trackFront:o.trackFront,trackRear:o.trackRear,wheelRateFront:p?0:o.wheelRateFront,wheelRateRear:d?0:o.wheelRateRear,decoupledFront:p,decoupledRear:d,...u.front?{elementLinkagesFront:u.front}:{},...u.rear?{elementLinkagesRear:u.rear}:{},...m.front.source==="part"?{cornerCoiloverFront:m.front.coilover}:{},...m.rear.source==="part"?{cornerCoiloverRear:m.rear.coilover}:{},...m.heaveFront.coilover?{heaveCoiloverFront:m.heaveFront.coilover}:{},...m.heaveRear.coilover?{heaveCoiloverRear:m.heaveRear.coilover}:{},...i.front&&!p?{heaveSeatFront:i.front}:{},...i.rear&&!d?{heaveSeatRear:i.rear}:{},...m.rollFront.coilover?{rollCoiloverFront:m.rollFront.coilover}:{},...m.rollRear.coilover?{rollCoiloverRear:m.rollRear.coilover}:{},tireRate:T,...M!==T?{tireRateRear:M}:{},tireDamping:J(t,"tire_vertical_damping"),arbFront:a.front??J(t,"arb_front"),arbRear:a.rear??J(t,"arb_rear"),brakeBalanceFront:O.balanceFront,brakes:O,...V?{driveline:V}:{},heaveSpringFront:s.front??J(t,"heave_spring_front"),heaveSpringRear:s.rear??J(t,"heave_spring_rear"),unsprungPerCorner:J(t,"unsprung_mass"),unsprungCgHeight:wr(k,S,T,o.unsprungCgHeight),tyreFreeRadius:k,...w!==k?{tyreFreeRadiusRear:w}:{},rcHeightFront:_[0],rcHeightRear:_[1],corneringStiffnessFront:C,corneringStiffnessRear:F,get kinFront(){return D()},get kinRear(){return I()},damperFront:p?0:f?.front?.rate??J(t,"damper_front")*o.mrFront*o.mrFront,damperRear:d?0:f?.rear?.rate??J(t,"damper_rear")*o.mrRear*o.mrRear,...f?.front&&!p?{damperCurveFront:f.front.curve}:{},...f?.rear&&!d?{damperCurveRear:f.rear.curve}:{},heaveDamperFront:l.heaveFront?.rate??c.heaveFront,heaveDamperRear:l.heaveRear?.rate??c.heaveRear,rollDamperFront:l.rollFront?.rate??c.rollFront,rollDamperRear:l.rollRear?.rate??c.rollRear,...l.heaveFront?{heaveDamperCurveFront:l.heaveFront.curve}:{},...l.heaveRear?{heaveDamperCurveRear:l.heaveRear.curve}:{},...l.rollFront?{rollDamperCurveFront:l.rollFront.curve}:{},...l.rollRear?{rollDamperCurveRear:l.rollRear.curve}:{},unsprungCornerMass:J(t,"unsprung_mass"),get rollCentreCurve(){return N().roll},get rcHeaveCurve(){return N().heave},aero:h,yawInertia:J(t,"I_yaw"),rollInertia:J(t,"I_roll"),pitchInertia:J(t,"I_pitch"),...da(t)?{chassisTorsion:da(t)}:{},...cl(t,"front")?{twistInertiaFront:cl(t,"front")}:{},...cl(t,"rear")?{twistInertiaRear:cl(t,"rear")}:{},get steerFront(){return Wd(e.front,L)},ackermannPct:J(t,"ackermann_pct"),toeFrontDeg:J(t,"toe_front_deg"),toeRearDeg:J(t,"toe_rear_deg")};return H}var lI=e=>({tire:t=>t==null?void 0:t===e.tireModelIdRear&&e.tireModelRear?e.tireModelRear:e.tireModel,motor:()=>e.motorModel,aero:()=>e.aeroModel,battery:()=>e.batteryModel,brake:()=>e.brakeModel,damper:t=>t!=null&&t===e.damperModelIdRear&&e.damperModelRear?e.damperModelRear:t!=null&&t===e.heaveDamperModelId?e.heaveDamperModel:t!=null&&t===e.rollDamperModelId?e.rollDamperModel:e.damperModel}),vv={ggvMode:"twoTrack"},cI=new WeakMap;function kv(e,t=vv){let r=cI.get(e.vehicle);r||cI.set(e.vehicle,r=new WeakMap);let n=r.get(e.params);n||r.set(e.params,n=new Map);let o=JSON.stringify(t),a=n.get(o);if(!a){n.size>=8&&n.clear();let s={...lI(e.params),suspensionOf:()=>e.vehicle};n.set(o,a=ns(e.params,s,t))}return a}var uI=(e=vv)=>t=>kv(t,e),Ah=(e=vv)=>t=>iI(t.vehicle,U1(t.params,lI(t.params),e),t.params.tireModel,t.params.tireModelRear);function CY(e,t){return kv(e,t.switches)}var Mv=e=>xr(e?.rulesets);function mI(e,t,r,n,o={},a=()=>r.standingStart){let s=kv(n,r.switches),i=(l,u)=>{let m=Gp(l,t,{racingLine:r.racingLine,params:s});return{asset:m.asset,numerics:m.numerics,standingStart:u,racingLine:r.racingLine}},c=Object.fromEntries(Object.entries(o).map(([l,u])=>[l,i(u,a(l))]));return{course:e?i(e,r.standingStart):null,numerics:t,tracks:c,switches:r.switches}}var dI=e=>[...new Set(e.lap.courses.flatMap(t=>t.course.kind==="track"?[t.course.trackId]:[]))],pI=e=>{let t=e?.session;return t?{sessionParams:r=>CY(r,t),session:()=>t}:{}},Uu=e=>({metrics:Mv(e),assemble:Ah(e?.switches),simParams:uI(e?.switches),projectTrack:()=>e?.course??null,libraryTrack:t=>e?.tracks?.[t]??null,numerics:e?.numerics,...pI(e)}),TY=(e,t)=>({density:e.density,envelope:e.envelope,states:e.states,operating:e.operating,assemble:Ah(t)}),PY=(e,t)=>({...TY(e,t?.switches),lap:e.lap,simParams:uI(t?.switches),projectTrack:()=>t?.course??null,libraryTrack:r=>t?.tracks?.[r]??null,numerics:t?.numerics,...pI(t)}),fI="nelder-mead",hI=600,ju=[0,.15,.15];function bI(e,t,r,n=ju.length){let o=wv(t);return ju.slice(0,Math.max(1,n)).map((a,s)=>({...e,seed:s+1,startJitter:a,car:o,...r?{lap:r}:{}}))}function gI(e,t,r=.5){let n=[];return e.forEach((o,a)=>{let s=o.hi-o.lo;if(s<=0)return;let i=Math.min(r,s*.01);t[a]<=o.lo+i?n.push({id:o.id,name:o.name,unit:o.unit,at:"lo",value:t[a],moved:t[a]-o.start}):t[a]>=o.hi-i&&n.push({id:o.id,name:o.name,unit:o.unit,at:"hi",value:t[a],moved:t[a]-o.start})}),n}function yI(e,t,r,n,o=.01){let a=Mv(n).byId;return LY(e,t,r,n).filter(s=>s.excess>-o*(a[s.metricId]?.scale??1))}function LY(e,t,r,n){let o;try{o=Eo(zi(e,t,r),PY(t,n))}catch{return[]}return DY(o,t,Mv(n))}function DY(e,t,r){let n=[];for(let o of t.constraints){let a=r.byId[o.metricId];if(!a)continue;let s=vt(e,a,o.at);if(!Number.isFinite(s))continue;let i=`${bt(a)}${Ja(o.at,a)}`;n.push({key:o.key,metricId:o.metricId,label:i,unit:a.unit==="-"?"":a.unit,value:s,excess:No(o,s)})}return n}var EY=.05;function IY(e,t){if(t.id.startsWith("hp.")||th(t.id))return 1;let r=/^rocker\.(front|rear)\.(\w+)$/.exec(t.id);if(r){let a=r[1]==="front"?e.vehicle.front:e.vehicle.rear;return A1(_o(a.hardpoints),r[2],1)}let n=/^arm\.(front|rear)\.(uca|lca)\.(\w+)$/.exec(t.id);if(!n)return null;let o=n[1]==="front"?e.vehicle.front:e.vehicle.rear;return k1(so(o.hardpoints,n[2]),n[3],1)}function xI(e,t,r){let n=r.filter(p=>p.score.feasible);if(n.length<2)return null;let o=t.map(p=>IY(e,p)),a=o.every(p=>p!==null)?"mm":null,s=0,i="",c=0,l=n.reduce((p,d)=>d.score.total<p.score.total?d:p);for(let p of n)if(p!==l)for(let d=0;d<t.length;d++){let f=Math.abs(p.x[d]-l.x[d])*(o[d]??1);c+=f*f,f>s&&(s=f,i=t[d].name)}let u=n.map(p=>p.score.total),m=l.score.terms.reduce((p,d)=>p+(d.resolution??0),0);return{distance:Math.sqrt(c),worst:s,worstName:i,scoreSpread:Math.max(...u)-Math.min(...u),tolerance:Math.max(EY,m),unit:a}}var _Y={steeringSystem:!0,brakeSetup:!0,driveline:!0,heaveFrontDesign:!0,heaveRearDesign:!0,arbFrontDesign:!0,arbRearDesign:!0,rollBarFrontDesign:!0,rollBarRearDesign:!0},RI=e=>Object.hasOwn(_Y,e);function Rv(e){let[t,r]=e.split("."),n=r==="front"?"Front":r==="rear"?"Rear":null;return n?t==="heave"?`heave${n}Design`:t==="roll"?`arb${n}Design`:t==="rollBar"?`rollBar${n}Design`:null:null}function NY(e){let t=e.split(".")[0];return t==="hp"||t==="arm"||t==="rocker"?"hardpoint":t==="cfg"?"config":t==="kc"?"compliance":t==="param"?"param":t==="brakeModel"?"part":RI(t)||Rv(e)?"block":null}function Sv(e,t){t=Kt(e,t);let r=gt(e);return[...t.variables,...t.followers??[]].filter(n=>r[n.id]&&!r[n.id].supersededBy&&!NY(n.id)).map(n=>dt(r[n.id]))}function wh(e,t,r){t=Kt(e,t);let n=gt(e),o=zi(e,t,r),a=[],s=new Set,i=new Set;for(let c of[...t.variables,...t.followers??[]]){let l=n[c.id];if(!l||l.supersededBy)continue;let u=l.read(o),[m,p,d,f]=c.id.split(".");if(m==="rocker"){let h=`${p}.rocker`;if(i.has(h))continue;i.add(h);let b=p==="front"?o.vehicle.front:o.vehicle.rear;for(let g of[Sn.fore,Sn.aft]){let y=b.hardpoints[g];for(let x=0;x<3;x++)a.push({kind:"hardpoint",axle:p,key:g,axis:x,value:y[x]})}}else if(m==="arm"){let h=`${p}.${d}`;if(i.has(h))continue;i.add(h);let b=p==="front"?o.vehicle.front:o.vehicle.rear,g=Rr[d];for(let y of[g.fore,g.aft]){let x=b.hardpoints[y];for(let R=0;R<3;R++)a.push({kind:"hardpoint",axle:p,key:y,axis:R,value:x[R]})}}else if(m==="hp"&&Pr(c.id)){let h=`${p}.${d}`;if(i.has(h))continue;i.add(h);let b=(p==="front"?o.vehicle.front:o.vehicle.rear).hardpoints[d];for(let g=0;g<3;g++)a.push({kind:"hardpoint",axle:p,key:d,axis:g,value:b[g]})}else if(m==="hp")a.push({kind:"hardpoint",axle:p,key:d,axis:"xyz".indexOf(f),value:u});else if(m==="cfg")a.push({kind:"config",axle:p,field:d,value:u});else if(m==="kc"){if(s.has(`kc.${p}`))continue;s.add(`kc.${p}`);let h=p==="front"?o.vehicle.front:o.vehicle.rear;a.push({kind:"compliance",axle:p,value:h.compliance})}else if(m==="param")a.push({kind:"param",label:dt(l),value:u});else if(m==="brakeModel"){if(s.has(m))continue;if(s.add(m),!o.params.brakeModel)throw new Error(`optimiser: "${c.id}" left the car with no brake part to adopt`);a.push({kind:"part",key:"brakeModel",fromId:e.params.brakeModelId,value:o.params.brakeModel})}else if(RI(m)||Rv(c.id)){let h=Rv(c.id)??m;if(s.has(h))continue;s.add(h);let b=o.params[h];if(!b)throw new Error(`optimiser: "${c.id}" left the car with no ${h} to adopt`);a.push({kind:"block",key:h,value:b})}else throw new Error(`optimiser: Adopt has no way to write "${c.id}" back into the project`)}return a}function Av(e){let t=performance.now(),r=Uu(e.lap),n=e.follow?_1(e.car,e.spec,r):e.spec,{dead:o,unprobed:a,...s}=B1(e.car,n,r);return{...s,deadIds:o.map(i=>i.id),unprobedIds:a.map(i=>i.id),elapsedMs:performance.now()-t,...e.follow?{followed:!0,fromCar:n===e.spec?null:{states:n.states,envelope:n.envelope}}:{}}}function vI(e){let t=performance.now();return{tolerance:nv(e.car,e.spec,e.x,Uu(e.lap),e.mm),elapsedMs:performance.now()-t}}var wv=e=>e.vehicle.chassis?{...e,vehicle:ov(e.vehicle)}:e;function kI(e,t){try{let r=Fv(e.car,e.spec,e.lap),n=Gs.find(u=>u.name===e.method);if(!n)throw new Error(`unknown method "${e.method}"`);t({kind:"progress",seed:e.seed,progress:{evaluations:0,budget:e.budget,x:Gr(r.variables),score:On(r,Gr(r.variables)),infeasible:0}});let o=e.from,a=o?{...r,variables:r.variables.map((u,m)=>({...u,start:Number.isFinite(o[m])?o[m]:u.start}))}:r,s=performance.now(),i=n.run(a,{budget:e.budget,seed:e.seed,startJitter:e.startJitter,progressEvery:20,onProgress:u=>t({kind:"progress",seed:e.seed,progress:u})}),c=performance.now()-s,l=i.score.feasible&&C1(r.variables)?P1(r,i.x,i.score):void 0;t({kind:"done",seed:e.seed,result:l?{...i,snapped:l}:i,elapsedMs:c})}catch(r){t({kind:"error",seed:e.seed,message:r instanceof Error?r.message:String(r)})}}var Fv=(e,t,r)=>es(e,t,Uu(r));function MI(e,t){let r=e.tireModelIdRear?t.tire(e.tireModelIdRear):void 0;return{tireModel:t.tire(e.tireModelId),...r?{tireModelRear:r}:{},motorModel:t.motor(e.motorModelId),aeroModel:t.aero(e.aeroModelId),batteryModel:t.battery(e.batteryModelId),brakeModel:t.brake(e.brakeModelId),damperModel:t.damper(e.damperModelId),...dl(e,t.damper)}}function SI(e,t,r,n){let{tireModelRear:o,damperModelRear:a,heaveDamperModel:s,rollDamperModel:i,...c}=r;return{vehicle:e,params:{...t,...c,...o?{tireModelRear:o}:{},...a?{damperModelRear:a}:{},...s?{heaveDamperModel:s}:{},...i?{rollDamperModel:i}:{}},...Da(n)?{sessionAir:!0}:{}}}var Fh=e=>({ggvMode:e.ggvMode,quasiTransient:e.quasiTransient===!0&&e.ggvMode!=="fast",motorThermal:e.motorThermal===!0,...WD({brakeFade:e.brakeFade===!0,airTempC:e.airTempC,diffYaw:e.diffYaw===!0,...e.air?{air:e.air}:{}})});function OY(e){if(!(e.plannedPath!==void 0||!e.track))return{track:e.track,numerics:e.numerics,settings:{racingLine:e.racingLine,standingStart:e.standingStart,...Object.keys(e.lapCounts).length?{lapCounts:e.lapCounts}:{}},switches:e.switches,rulesets:e.rulesets}}function AI(e,t){let r=t.plannedPath!==void 0,n=OY(t);return{...mI(r?t.plannedPath:t.track,t.numerics,{racingLine:r?!1:t.racingLine,standingStart:t.standingStart,switches:t.switches},e,t.library,t.standingOf),...n?{session:n}:{},rulesets:t.rulesets}}function cs(e,t){let r=e.vehicles.find(o=>o.id===t);if(!r)throw new Error(`this project holds no vehicle "${t}"`);let n=rs(e);return SI(structuredClone(j1(e,r.params)),structuredClone(r.params),MI(r.params,n),io(e).air)}var VY="this project's laps follow a fixed trajectory from the planner, which the server cannot read \u2014 set Laptime back to the track to run this study here, or run it in the Studies tool";async function Cv(e,t,r,n){if(e.settings.pathPlanId)throw new Error(VY);let o=io(e),a=e.tracks.length?(await ch(e,t)).asset:null,s={};for(let i of n?dI(n):[]){let c=e.tracks.find(l=>l.id===i);c&&(s[i]=await Hu(c,t))}return AI(r,{track:a,numerics:o.numerics,racingLine:o.racingLine,standingStart:o.standingStart,lapCounts:o.lapCounts??{},switches:Fh(o),rulesets:e.rulesets??[],library:s,standingOf:i=>e.tracks.find(c=>c.id===i)?.standingStart===!0})}async function wI(e,t,r,n){let o=cs(e,r),a=Kt(o,n),s=await Cv(e,t,o,a);return Av({id:0,car:o,spec:a,lap:s})}async function FI(e,t,r,n){let o=cs(e,r),a=Kt(o,n),s=Sv(o,a);if(s.length)return{problems:[`Adopt has no way to write ${s.join(", ")} back into the project. Take them out of the study.`]};let i;try{i=await Cv(e,t,o,a)}catch(l){return{problems:[l instanceof Error?l.message:String(l)]}}let c=V1(o,a,{...Uu(i),metrics:xr(e.rulesets)});return c.length?{problems:c}:{problems:[],msPerEval:Av({id:0,car:o,spec:a,lap:i}).msPerEval,carFingerprint:Ca(wv(o))}}async function BY(e,t,r,n,o,a=[]){let s=bI(t,e,r,n),i=s.length*t.budget,c=null,l=[];for(let[u,m]of s.entries()){if(a.includes(m.seed))continue;await o?.tick();let p=[],d=null,f=null;if(kI(m,y=>{y.kind==="progress"?(p.push([y.progress.evaluations,y.progress.score.total]),y.progress.evaluations===0&&(c??=y.progress.score),o?.progress(u*t.budget+y.progress.evaluations,i)):y.kind==="done"?d={result:y.result,elapsedMs:y.elapsedMs}:f=y.message}),f)throw new Error(f);if(!d)throw new Error("the search stopped without a result");let{result:h,elapsedMs:b}=d,g={seed:m.seed,startJitter:m.startJitter,x:h.x,score:h.score,evaluations:h.evaluations,infeasible:h.infeasible,history:h.history,trace:p,elapsedMs:b,...h.snapped?{snapped:h.snapped}:{}};l.push(g),o?.progress((u+1)*t.budget,i),await o?.finished?.(g)}if(!c)throw new Error("the search never scored the starting design");return{method:t.method,budget:t.budget,designScore:c,runs:l}}async function CI(e,t,r,n){let o=cs(e,r.vehicleId),a=Kt(o,r.spec),s=Sv(o,a);if(s.length)throw new Error(`study_adopt has no way to write ${s.join(", ")} back into the project \u2014 take them out of the study`);let i=await Cv(e,t,o,a),c=r.method??fI;if(!Gs.some(x=>x.name===c))throw new Error(`unknown method "${c}" \u2014 it is one of ${Gs.map(x=>x.name).join(", ")}`);let l=r.budget??hI,u=Math.max(1,Math.min(r.seeds??ju.length,ju.length)),m=await BY(o,{spec:a,method:c,budget:l},i,u,n),p=Fv(o,a,i),d=m.runs.map(x=>({seed:x.seed,startScore:m.designScore.total,score:x.score.total,feasible:x.score.feasible,...x.score.reason?{reason:x.score.reason}:{},terms:x.score.terms,x:x.x,evaluations:x.evaluations,infeasible:x.infeasible,bounds:gI(p.variables,x.x),constraints:yI(o,a,x.x,i),...x.snapped?{onSteps:{x:x.snapped.x,score:x.snapped.score.total,feasible:x.snapped.score.feasible,...x.snapped.score.reason?{reason:x.snapped.score.reason}:{},terms:x.snapped.score.terms}}:{}})),f=m.runs.reduce((x,R)=>Vc(R.score,x.score)?R:x),h=f.snapped?.score.feasible?f.snapped:null,b=h?h.x:f.x,g=r.tolerance??ph,y=f.score.feasible&&g>0?vI({id:0,car:o,spec:a,x:b,lap:i,mm:g}).tolerance:null;return{method:c,budget:l,seeds:d,spread:m.runs.length>1?xI(o,p.variables,m.runs.map(x=>({x:x.x,score:x.score}))):null,writes:wh(o,a,b),...f.snapped?{adopts:h?"on its steps":`as found: on its steps it breaks a hold (${f.snapped.score.reason??"not legal"})`}:{},...y?{asBuilt:y}:{}}}var $Y=(e,t)=>e[t]??[],GY=(e,t,r)=>r<=1?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function Ch(e){return e.kind==="param"?GY(e.start,e.end,Math.max(1,Math.round(e.steps))):e.kind==="part"?[...e.partIds]:[...e.values]}var TI=e=>e.kind==="param"?e.label:e.kind==="part"?`${e.part} model`:e.setting;function KY(e,t){let r=e.vehicles.find(i=>i.id===t.vehicleId);if(!r)throw new Error(`this project holds no vehicle "${t.vehicleId}"`);if(!t.axes.length)throw new Error("a sweep needs at least one axis");let n=ns(structuredClone(r.params),rs(e),io(e)),o=jw(n,{geometry:!0}),a=Jd(n);for(let i of t.axes){if(i.kind==="param"){let c=a.find(u=>u.label===i.label);if(!c)throw new Error(`no parameter is labelled "${i.label}" on this car \u2014 read vehicle_get for the labels it has`);let l=o[c.key];if(l)throw new Error(`"${i.label}" is a readout on this car, not an input: ${l}. Sweeping it would report exactly zero. Sweep what produces it instead.`)}if(i.kind==="part"){let c=Po.find(l=>l.doc===i.part);if(!c)throw new Error(`"${i.part}" is not a library \u2014 it is one of ${Po.map(l=>l.doc).join(", ")}`);for(let l of i.partIds)if(!$Y(e,c.doc).some(u=>u.id===l))throw new Error(`the ${c.label} library holds no "${l}"`)}}if(t.holdBalance){let i=a.find(l=>l.key==="arb_front");if(t.axes.find(l=>l.kind==="param"&&l.label===i?.label))throw new Error(`holding the balance moves "${i.label}": it cannot also be an axis`)}let s=t.axes.reduce((i,c)=>i*Ch(c).length,1)+(t.priceInMass?PI:0);if(s>Kp)throw new Error(`that grid is ${s} runs, over the ${Kp} cap \u2014 a run is a whole session. Drop an axis or use fewer steps.`)}var PI=3,LI=(e,t)=>({...nh(),variables:[{id:e,lo:0,hi:2*t}]});function HY(e,t){let r=cs(e,t.vehicleId),n=uh(r);if("why"in n)throw new Error(`the balance cannot be held: ${n.why}`);let o=Ah(Fh(io(e,t.settings))),a=mh(es(r,LI(n.id,n.now),{assemble:o}),xr(e.rulesets));if("why"in a)throw new Error(`the balance cannot be held: ${a.why}`);return{target:a.target,metric:a.metric,assemble:o,bar:dt(n.def),unit:n.def.unit,now:n.now}}function zY(e,t,r){let n=cs(e,t),o=uh(n);if("why"in o)return{value:NaN,balance:NaN,reached:!1};let a=LI(o.id,o.now),{x:s,held:i}=dh(es(n,a,{assemble:r.assemble}),[o.now],{slot:0,target:r.target,metric:r.metric}),c=e.vehicles.find(l=>l.id===t).params;for(let l of wh(n,a,s))if(l.kind==="param")si(c,l.label,l.value);else if(l.kind==="block")Object.assign(c,{[l.key]:structuredClone(l.value)});else throw new Error(`a held balance has no way to write ${l.kind} back into the car`);return{value:i.value,balance:i.balance,reached:i.reached}}var DI=e=>e.map(t=>String(typeof t=="number"?Number(t.toPrecision(4)):t)).join(" \xD7 ");function YY(e,t){let r=[...new Set(e.flatMap(o=>(o.didNotFinish??[]).map(a=>a.label)))],n=e.map(o=>({name:DI(o.at),events:r.map(a=>({label:a,incomplete:o.didNotFinish?.find(s=>s.label===a)}))}));return QD(n).map(({event:o,finished:a,stopped:s})=>{let i=`${s.length} of ${e.length} points did not finish ${o}`;if(!a.length)return`${i}: every time there is a part-distance${t?" and scores zero":""}, so compare laps before time.`;let c=s.length>6?`${s.slice(0,6).join(", ")}, \u2026`:Q1(s);return t?`${i}: ${c}. Their time there is a part-distance and scores zero, so read them as stopped, not slow \u2014 a points ranking favours the points that finished over faster ones that stopped.`:`${i}: ${c}. Their time there is a part-distance, so read them as stopped, not slow.`})}function WY(e){let t=[[]];for(let r of e){let n=Ch(r),o=[];for(let a of n)for(let s of t)o.push([...s,a]);t=o}return t}async function EI(e,t,r,n){KY(e,r);let o=WY(r.axes),a=o.length+(r.priceInMass?PI:0),s=r.holdBalance?HY(e,r):null,i=[],c=!1,l=0,u=async(h,b={})=>{let g=structuredClone(e),y=g.vehicles.find(T=>T.id===r.vehicleId),x={...r.settings},R={...b};h&&r.axes.forEach((T,M)=>{let k=h[M];if(T.kind==="param")R[T.label]=k;else if(T.kind==="part"){let w=Po.find(P=>P.doc===T.part);y.params[w.ref]=k}else x[T.setting]=k}),Object.keys(R).length&&(y.params=q1(y.params,R));let v=s?zY(g,r.vehicleId,s):void 0,S=r.fleet?g.vehicles.filter(T=>T.visible||T.id===r.vehicleId).map(T=>T.id):[r.vehicleId],A=await lh(g,t,{vehicleIds:S,settings:x});c=A.fleetScored;let C=A.vehicles.find(T=>T.id===r.vehicleId),F=C.events.flatMap(T=>T.incomplete?[{label:T.label,...T.incomplete}]:[]);return n?.(++l,a),{at:h??[],metrics:C.metrics,...F.length?{didNotFinish:F}:{},...v?{held:v}:{}}};for(let h of o)i.push(await u(h));let m;if(r.priceInMass){let h=cs(e,r.vehicleId),b=gt(h)[ev],g=b.read(h),y=tv*g,x=dt(b),R=await u(null),v=await u(null,{[x]:g+y}),S=await u(null,{[x]:g-y}),A=Object.fromEntries(Object.keys(R.metrics).map(C=>[C,(v.metrics[C]-S.metrics[C])/(2*y)]));m={car:R.metrics,perKg:A,dKg:y};for(let C of i)C.asKg=Object.fromEntries(Object.keys(C.metrics).map(F=>[F,rv(C.metrics[F],R.metrics[F],A[F])]))}let p=Object.keys(i[0]?.metrics??{}),d=[];r.axes.forEach((h,b)=>{if(Ch(h).length<2)return;p.some(y=>{if(new Set(i.map(v=>`${v.at[b]}`)).size<2)return!1;let R=i.map(v=>v.metrics[y]).filter(Number.isFinite);return Math.max(...R)-Math.min(...R)>1e-9})||d.push(TI(h))});let f=[];if(c&&!r.fleet&&f.push("Points here were scored with this car alone, so it takes the maximum in every event and the points axis is flat by construction. Re-run with fleet: true to price a change in points."),f.push(...YY(i,c)),s&&io(e,r.settings).ggvMode==="fast"&&f.push("The fast envelope is a point mass: no balance reaches its laps, so a held sweep runs the same laps as a loose one. Hold it on the full envelope (settings.ggvMode)."),s){let h=i.filter(b=>b.held&&!b.held.reached).map(b=>DI(b.at));h.length&&f.push(`No ${s.bar} between 0 and twice the car's holds TLLTD at ${s.target.toFixed(2)} % at ${Q1(h.length>6?[...h.slice(0,6),"\u2026"]:h)}: those points ran with the bar at the end nearer it, so their balance is not the car's.`)}return m&&f.push(`As mass: each point's change from the car as it is, over what 1 kg moves it, read at \xB1${m.dKg.toFixed(1)} kg. Negative is as much as taking that many kilograms off. A metric the mass hardly moves prices at nonsense: read the lap and event times.`),d.length&&f.push(`Nothing moved along ${d.join(", ")}. Exactly zero is a wiring question before it is a finding: check that a library part is not superseding the value, and that the switch it needs is on.`),{axes:r.axes.map(h=>({kind:h.kind,label:TI(h),values:Ch(h)})),runs:i,metricKeys:p,fleetScored:c,flat:d,caveats:f,...s?{hold:{bar:s.bar,unit:s.unit,now:s.now,tlltdPct:s.target}}:{},...m?{price:m}:{}}}function _I(){if(typeof process.threadCpuUsage!="function")return performance.now();let e=process.threadCpuUsage();return(e.user+e.system)/1e3}async function UY(e,t){let r=HD(e.root);switch(e.kind){case"sweep":return EI(e.doc,r,e.req,t);case"convergence":return ZD(e.doc,r,{vehicleId:e.vehicleId,...e.steps?{steps:e.steps}:{},...e.tolPct!==void 0?{tolPct:e.tolPct}:{},onStep:t});case"study":return CI(e.doc,r,{vehicleId:e.vehicleId,spec:e.spec,...e.method?{method:e.method}:{},...e.budget?{budget:e.budget}:{},...e.seeds?{seeds:e.seeds}:{},...e.tolerance!==void 0?{tolerance:e.tolerance}:{}},{progress:t,cancelled:()=>!1,tick:async()=>{}});case"fleet":return lh(e.doc,r,{...e.vehicleIds?{vehicleIds:e.vehicleIds}:{},...e.settings?{settings:e.settings}:{},...e.overrides?{overrides:e.overrides}:{}});case"probe":return wI(e.doc,r,e.vehicleId,e.spec);case"quote":return FI(e.doc,r,e.vehicleId,e.spec)}}if(II){let e=II,t=r=>e.postMessage(r);(async()=>{try{let r=await UY(jY,(n,o)=>t({type:"progress",done:n,total:o}));t({type:"done",result:r,cpuMs:_I()})}catch(r){t({type:"failed",message:r instanceof Error?r.message:String(r),cpuMs:_I()})}})()}export{UY as runJob,_I as threadCpuMs};
|