@pacedyn/mcp 1.16.0 → 1.16.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/worker.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{parentPort as BT,workerData as q$}from"node:worker_threads";import{readFileSync as Oy}from"node:fs";import{join as Vy}from"node:path";var rl=e=>e.format!=="points"&&!e.field;var dt=e=>e?.kind==="ice";var fx={packVoltageMax:600,segmentVoltageMax:120,powerLimitKw:80};var Ee=e=>typeof e=="number"&&Number.isFinite(e);function GT(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(Ee))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(Ee))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(Ee))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(Ee))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(Ee))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 KT(e){return!e||typeof e!="object"?"The cell has no curve.":e.kind==="table"?GT(e):e.kind==="analytic"?!Ee(e.vCut)||!Ee(e.vNom)||!Ee(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?!Ee(e.r0)||e.r0<0?"The cell resistance must be a number and cannot be negative.":e.socAtNom!==void 0&&(!Ee(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 nl(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(!Ee(t.capacityAh)||t.capacityAh<=0)return"The cell capacity must be a positive number of amp-hours.";if(!Ee(t.vMin)||t.vMin<0)return"The cut-off voltage must be a number and cannot be negative.";if(!Ee(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(!Ee(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&&(!Ee(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&&(!Ee(t.massKg)||t.massKg<0))return"The cell mass must be a number and cannot be negative.";let r=KT(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(!Ee(o.heatCapacityJPerK)||o.heatCapacityJPerK<=0)return"The cell heat capacity must be a positive number of joules per kelvin.";if(!Ee(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&&!Ee(o.startC))return"The starting temperature must be a number.";if(o.entropicVPerK!==void 0&&!Ee(o.entropicVPerK))return"The entropic coefficient must be a number.";if(o.derateFromC!==void 0){if(!Ee(o.derateFromC))return"The temperature the derate starts at must be a number.";if(o.derateToC!==void 0){if(!Ee(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(!Ee(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 Bn(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 Ie(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 ol(e,t,r,n,o){let a=e.length,s=t.length;if(a===0||s===0)return 0;let i=Bn(e,n),c=Bn(t,o),l=Math.min(i.i+1,a-1),u=Math.min(c.i+1,s-1),m=r[c.i][i.i],f=r[c.i][l],p=r[u][i.i],d=r[u][l],h=m+i.t*(f-m),b=p+i.t*(d-p);return h+c.t*(b-h)}var Wo=[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1],ld={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]},hx=[0,.05,.1,.2,.5,.8,1],bx=[2.2,1.55,1.3,1.12,1,.97,.98];function gx(e){return Ie(hx,bx,e)}var yx=[-20,-10,0,10,25,40,60],xx=[4,2.8,2,1.4,1,.82,.75];function ud(e){return Ie(yx,xx,e)}var Rx=.5;function md(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=ld[t]??ld.other,l=e.socAtNom??Rx,u=Wo.includes(l)?[...Wo]:[...Wo,l].sort((h,b)=>h-b),m=Ie(Wo,c,l),f=m>0&&m<1?Math.log(i)/Math.log(m):1,p=[],d=[];for(let h of u){let b=Ie(Wo,c,h);p.push(o+s*Math.pow(b,f)),d.push(e.constantResistance?a:a*gx(h))}return{kind:"table",soc:u,ocv:p,r0:d}}function pd(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+=(Ie(t,r,s)+Ie(t,r,i))/2*(i-s)}return o}var jo=25,vx=new WeakMap;function wr(e){let t=vx.get(e);if(t)return t;let r=nl(e);if(r)throw new Error(r);let{cell:n,pack:o}=e,a=n.curve.kind==="table"?n.curve:md(n.curve,n.chemistry),s=o.series,i=o.parallel,c=s/i,l=a.rTempC,u=a.rGrid,m=i*n.capacityAh,f=s*n.vMin,p=n.iMaxA>0?i*n.iMaxA:1/0,d=n.iMaxChargeA!==void 0&&n.iMaxChargeA>0?n.iMaxChargeA:n.iMaxA/4,h=d>0?i*d:1/0,b=A=>s*Ie(a.soc,a.ocv,A),g=(A,w=jo)=>{let T=l&&u?ol(a.soc,l,u,A,w):Ie(a.soc,a.r0,A)*ud(w);return c*T+o.busResistance},y=(A,w,T)=>b(A)-w*g(A,T),R=(A,w,T)=>{if(!(A>0))return 0;let P=b(w),S=g(w,T);if(!(S>0))return A/P;let F=P*P-4*S*A;return F<0?NaN:2*A/(P+Math.sqrt(F))},k=(A,w,T)=>{if(!(A>0))return 0;let P=b(w),S=g(w,T);return S>0?2*A/(P+Math.sqrt(P*P+4*S*A)):A/P},v=A=>{let w=e.thermal;if(!w||w.derateFromC===void 0)return 1;let T=w.derateToC??w.derateFromC;return A<=w.derateFromC?1:!(T>w.derateFromC)||A>=T?0:1-(A-w.derateFromC)/(T-w.derateFromC)},x=(A,w,T=0)=>{let P=b(A),S=g(A,w),F=S>0?P/(2*S):1/0,C=G=>{if(!(S>0))return G*P;let H=Math.min(G,F);return H*(P-H*S)},L=S>0?Math.max(0,(P-f)/S):1/0,E=T>0&&Number.isFinite(T)?T:1/0,D=S>0?C(L):1/0,O=Number.isFinite(p)?C(p):1/0,_=S>0?P*P/(4*S):1/0,z=[["rules",E],["voltage-floor",D],["current",O],["matched-load",_]],I=z[0][0],N=z[0][1];for(let[G,H]of z)H<N&&(N=H,I=G);let B=v(w??jo);B<1&&(N=Number.isFinite(N)?N*B:N,I="temperature");let V=Number.isFinite(N)?R(N,A,w):1/0;return{watts:N,binding:I,rules:E,voltageFloor:D,current:O,matchedLoad:_,derate:B,amps:V,volts:Number.isFinite(V)?P-V*S:P}},M={model:e,table:a,capacityAh:m,chargeC:m*3600,energyKwh:m*(s*pd(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:f,currentCeiling:p,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:R,chargeCurrentFor:k,maxPower:x};return vx.set(e,M),M}function dd(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 kx={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},Mx={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},Sx={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 fd(){return{name:"Formula Student accumulator",cell:dd(kx),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 hd(){return{name:"LFP pack",cell:dd(Mx),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 bd(){return{name:"Road car pack",cell:dd(Sx),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 gd(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 al(e){if(e.kind==="ice"){let n=e.gearbox.efficiency;return{model:e,maxTorque:o=>o>e.limitRpm?0:Ie(e.rpm,e.torque,o),efficiency:()=>n}}let t=n=>Ie(e.rpm,e.torque,n),r=e.kind==="simple"?()=>e.efficiency:(n,o)=>ol(e.effRpm,e.effTorque,e.effGrid,n,o);return{model:e,maxTorque:t,efficiency:r}}function yd(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=d=>Math.max(0,e.terminalResistanceOhm*(1+.00393*(d-t))),l=d=>n>0&&o>0?n*Math.pow(Math.max(0,d)/o,a):0,u=(d,h,b)=>{let g=r>0?Math.abs(h)/r:0;return 1.5*c(b)*g*g+l(d)},m=(d,h)=>{let b=e.coolingWPerK*(h-e.coolantC)-l(d);return!(b>0)||r<=0?0:r*Math.sqrt(b/(1.5*c(h)))},f=e.coolingWPerK>0?e.heatCapacityJPerK/e.coolingWPerK:1/0,p=Number.isFinite(f)?.25*f:1/0;return{spec:e,startC:e.startC??e.coolantC,lossW:u,step(d,h,b){if(!(b>0)||!(e.heatCapacityJPerK>0))return d;let g=Number.isFinite(p)?Math.max(1,Math.ceil(b/p)):1,y=b/g,R=d;for(let k=0;k<g;k++)R+=(h-e.coolingWPerK*(R-e.coolantC))*y/e.heatCapacityJPerK;return R},continuousTorque:m,derate(d,h,b){if(s===void 0||i===void 0||!(i>s)||!(b>0)||h<=s)return 1;let g=Math.min(1,m(d,i)/b);return h>=i?g:1-(1-g)*(h-s)/(i-s)},equilibriumC(d){return e.coolingWPerK>0?e.coolantC+d/e.coolingWPerK:1/0}}}function qe(e,t){return t==="rear"&&e.tireRateRear!==void 0?e.tireRateRear:e.tireRate}function xd(e,t){let r=e.tyreFreeRadiusRear;return(t==="rear"&&r!==void 0?r:e.tyreFreeRadius)??0}var sl=9.81,Ax=(e,t)=>e*(t*t)/2*(Math.PI/180)/1e3,bs=(e,t)=>e+t>0?e*t/(e+t):0,Fx=.5;function il(e,t,r){if(!(r>0))return 1;let n=e*sl*t*(Math.PI/180)/r;return 1/(1-Math.min(Fx,n))}function Rd(e,t,r){return r>0?e*sl*t/(r*r):0}function wx(e,t,r,n,o){if(!(n>0)||!(o>0))return 1;let a=Rd(e,t,r)*(1/n+1/o);return 1/(1-Math.min(Fx,a))}function Ce(e){let t=4*e.unsprungPerCorner,r=Math.max(0,e.massTotal-t),n=r*e.frontMassFrac,o=r*(1-e.frontMassFrac),a=qe(e,"front"),s=qe(e,"rear"),i=e.wheelRateFront+(e.heaveSpringFront??0),c=e.wheelRateRear+(e.heaveSpringRear??0),l=bs(i,a),u=bs(c,s),m=(O,_)=>{let z=_/2;return z>0?1/(2*Math.PI)*Math.sqrt(O*1e3/z):0},f=m(l,n),p=m(u,o),d=bs(e.wheelRateFront+e.arbFront,a),h=bs(e.wheelRateRear+e.arbRear,s),b=Ax(d,e.trackFront),g=Ax(h,e.trackRear),y=b+g,R=y>0?b/y:.5,k=e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac),v=(e.cgHeight-k)/1e3,x=r*sl*v,M=il(r,v,y),A=y>0?x/y*M:0,w=e.massTotal*sl*e.cgHeight/e.wheelbase,T=2*l,P=2*u,S=wx(r,e.cgHeight,e.wheelbase,T,P),C=(T>0&&P>0?(w/T+w/P)/e.wheelbase*S:0)*(180/Math.PI),L=e.wheelbase*e.wheelbase*bs(T,P)*(Math.PI/180)/1e3,E=e.damperFront??2.5,D=e.damperRear??2.5;return{sprungMass:r,sprungFront:n,sprungRear:o,rideRateFront:l,rideRateRear:u,rideFreqFront:f,rideFreqRear:p,rollRateFront:b,rollRateRear:g,rollRateTotal:y,rollWheelRateFront:d,rollWheelRateRear:h,frontRollStiffFrac:R,rollGradient:A,pitchGradient:C,pitchRate:L,cgRollGain:M,cgPitchGain:S,rideDampingFront:E+(e.heaveDamperFront??0),rideDampingRear:D+(e.heaveDamperRear??0),rollDampingFront:E+(e.rollDamperFront??0),rollDampingRear:D+(e.rollDamperRear??0)}}var on=["clFront","clRear","cd"],an=e=>e.frame?.kind==="pitch";function Uo(e){return an(e)?{x:e.axes.h,y:e.axes.pitch}:{x:e.axes.hFront,y:e.axes.hRear}}var cl=e=>e.frame?.kind==="pitch",Cx=e=>e.kind==="map";var ll=45,Ze=e=>typeof e=="number"&&Number.isFinite(e);function ul(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(Ze))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 Tx(e,t){if(t===void 0)return null;for(let r of on){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(Ze)||!n.factor.every(Ze))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 Px(e,t){return t===void 0?null:!Ze(t.dCl)||!Ze(t.dBalance)||!Ze(t.dCd)?`The ${e} slopes must be numbers.`:!Ze(t.maxDeg)||!(t.maxDeg>0)?`The ${e} response needs a positive angle to be valid to.`:null}function gs(e){if(!e||typeof e!="object")return"Not an aero model.";if(!Ze(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=ul("front ride-height",e.axes?.hFront);if(i)return i;let c=ul("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(!Ze(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=ul("ride-height",e.axes?.h);if(i)return i;let c=ul("pitch",e.axes?.pitch,"\xB0","pitch");if(c)return c;let l=e.axes.pitch.find(u=>Math.abs(u)>=ll);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 on){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(Ze))return`${i} contains a value that is not a number.`}}return Tx("yaw",e.attitude?.yaw)??Tx("roll",e.attitude?.roll)}if(e.kind==="sensitivity"){let t;if(e.frame==null)t=["hFront","hRear"];else if(e.frame?.kind==="pitch"){if(!Ze(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||!Ze(r[t[0]])||!Ze(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 on){if(!e.at||!Ze(e.at[s]))return`${s} at the reference must be a number.`;let i=n?.[s];if(!i||!Ze(i[t[0]])||!Ze(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||!Ze(i[0])||!Ze(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])>=ll||Math.abs(i[1])>=ll))return`A pitch range reaching ${Math.abs(i[0])>=ll?i[0]:i[1]}\xB0 is not a car's attitude. Pitch is in degrees.`}return Px("yaw",e.attitude?.yaw)??Px("roll",e.attitude?.roll)}return`Unknown aero model kind "${e.kind}".`}var Lx=180/Math.PI;function Xo(e,t,r,n){let o=(n-r)/t;return{h:r+e.refX*o,pitch:Math.atan(o)*Lx}}function qo(e,t,r,n){let o=Math.tan(n/Lx);return{hFront:r-e.refX*o,hRear:r+(t-e.refX)*o}}var NG=180/Math.PI,HT=["hFront","hRear"],zT=["h","pitch"],Md=e=>e?.kind==="pitch"?zT:HT,Tt=(e,t)=>e[t],ml=(e,t)=>e[t],vd=(e,t)=>({[e[0]]:t(e[0]),[e[1]]:t(e[1])});function YT(e){if(!(!e.yaw&&!e.roll))return{...e.yaw?{yaw:{...e.yaw}}:{},...e.roll?{roll:{...e.roll}}:{}}}function Sd(e){let t=Md(e.frame),r=e.balanceFront,n=e.cl*r,o=e.cl*(1-r),a=vd(t,c=>Tt(e.dCl,c)*r+e.cl*Tt(e.dBalance,c)),s=vd(t,c=>Tt(e.dCl,c)*(1-r)-e.cl*Tt(e.dBalance,c)),i=YT(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:vd(t,c=>Tt(e.dCd,c))},range:{[t[0]]:[...ml(e.range,t[0])],[t[1]]:[...ml(e.range,t[1])]},provenance:{...e.provenance},...i?{attitude:i}:{}}}function pl(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 kd(e,t,r=11){let n=Array.from({length:r},(a,s)=>t.maxDeg*s/(r-1)),o=n.map(a=>pl(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 Dx(e){if(!(!e.attitude?.yaw&&!e.attitude?.roll))return{...e.attitude.yaw?{yaw:kd(e.at,e.attitude.yaw)}:{},...e.attitude.roll?{roll:kd(e.at,e.attitude.roll)}:{}}}function Ex(e,t,r,n=0,o=0){let[a,s]=Md(e.frame),i=t-Tt(e.ref,a),c=r-Tt(e.ref,s),l={clFront:e.at.clFront+Tt(e.slope.clFront,a)*i+Tt(e.slope.clFront,s)*c,clRear:e.at.clRear+Tt(e.slope.clRear,a)*i+Tt(e.slope.clRear,s)*c,cd:e.at.cd+Tt(e.slope.cd,a)*i+Tt(e.slope.cd,s)*c},u=e.attitude?.yaw?pl(e.at,e.attitude.yaw,n):{clFront:1,clRear:1,cd:1},m=e.attitude?.roll?pl(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 Ad(e){let[t,r]=Md(e.frame),n=[...ml(e.range,t)],o=[...ml(e.range,r)],a=i=>o.map(c=>n.map(l=>i(Ex(e,l,c)))),s=Dx(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 Fd=180/Math.PI,Ix=new WeakMap,_x=new WeakMap,wd=new WeakMap;function sn(e,t){let r=_x.get(e);if(r)return r;let n=t?.wheelbase,o=n!==void 0?wd.get(e)?.get(n):void 0;if(o)return o;let a=WT(e),s=a.map;if(!an(s)){let l=jT(e,a);return _x.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=UT(e,a,s.frame,n),c=wd.get(e);return c||(c=new Map,wd.set(e,c)),c.set(n,i),i}function WT(e){let t=Ix.get(e);if(t)return t;let r=gs(e);if(r)throw new Error(r);let n=e.kind==="map"?e:Ad(e),{x:o,y:a}=Uo(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},f=(y,R)=>{let k=Math.abs(R),v=y.clFront.deg[y.clFront.deg.length-1];return{clFront:Ie(y.clFront.deg,y.clFront.factor,k),clRear:Ie(y.clRear.deg,y.clRear.factor,k),cd:Ie(y.cd.deg,y.cd.factor,k),clamped:k>v}},p=(y,R)=>{if(!u)return m;let k=c?f(c,y):m,v=l?f(l,R):m;return{clFront:k.clFront*v.clFront,clRear:k.clRear*v.clRear,cd:k.cd*v.cd,clamped:k.clamped||v.clamped}},d=(y,R,k=0,v=0)=>{let x=Bn(o,y),M=Bn(a,R),A=Math.min(x.i+1,s-1),w=Math.min(M.i+1,i-1),T=S=>{let F=S[M.i][x.i],C=S[M.i][A],L=S[w][x.i],E=S[w][A],D=F+x.t*(C-F),O=L+x.t*(E-L);return D+M.t*(O-D)},P=p(k,v);return{clFront:u?T(n.clFront)*P.clFront:T(n.clFront),clRear:u?T(n.clRear)*P.clRear:T(n.clRear),cd:u?T(n.cd)*P.cd:T(n.cd),clampedRide:x.clamped||M.clamped,clampedAttitude:P.clamped}},h={x:[o[0],o[s-1]],y:[a[0],a[i-1]]},b=(y,R,k=!1,v=0,x=0)=>{let M=p(v,x),A=Bn(o,k?Math.min(Math.max(y,h.x[0]),h.x[1]):y),w=Bn(a,k?Math.min(Math.max(R,h.y[0]),h.y[1]):R),T=Math.min(A.i+1,s-1),P=Math.min(w.i+1,i-1),S=T>A.i?o[T]-o[A.i]:0,F=P>w.i?a[P]-a[w.i]:0,C={};for(let L of on){let E=n[L],D=E[w.i][A.i],O=E[w.i][T],_=E[P][A.i],z=E[P][T],I=A.clamped||S===0?0:((O-D)*(1-w.t)+(z-_)*w.t)/S,N=w.clamped||F===0?0:((_-D)*(1-A.t)+(z-O)*A.t)/F;C[L]=u?{x:I*M[L],y:N*M[L]}:{x:I,y:N}}return C},g={map:n,x:h.x,y:h.y,hasAttitude:u,factors:p,at:d,slopes:b};return Ix.set(e,g),g}function jT(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 on)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 UT(e,t,r,n){let o=r.refX,a=o/n,s=(l,u,m=0,f=0)=>{let p=(u-l)/n;return t.at(l+o*p,Math.atan(p)*Fd,m,f)},i=(l,u,m=!1,f=0,p=0)=>{let d=(u-l)/n,h=t.slopes(l+o*d,Math.atan(d)*Fd,m,f,p),b=Fd/(n*(1+d*d)),g={};for(let y of on)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)=>qo(r,n,l,u),fromAxles:(l,u)=>{let m=Xo(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 Cd(e){let t=e.clFront+e.clRear;return{cl:t,balanceFront:t!==0?e.clFront/t:.5}}var fe=(e,t)=>e*t/100,Qe=e=>e/100,Nx={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:fe(3,-.4),hRear:fe(3,.1)},dBalance:{hFront:Qe(-.3),hRear:Qe(.15)},dCd:{hFront:fe(1.3,-.1),hRear:fe(1.3,.05)},yaw:{dCl:fe(3,-1),dBalance:Qe(-.3),dCd:fe(1.3,.5),maxDeg:10},roll:{dCl:fe(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."},Ox={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:fe(3,-.3),hRear:fe(3,-.15)},dBalance:{hFront:Qe(-.15),hRear:Qe(.15)},dCd:{hFront:fe(.9,-.15),hRear:fe(.9,-.05)},yaw:{dCl:fe(3,-1.5),dBalance:Qe(.2),dCd:fe(.9,.8),maxDeg:8},roll:{dCl:fe(3,-1),dBalance:Qe(-.3),dCd:0,maxDeg:2},note:"Assumed class-level sensitivities for a ground-effect floor, ride height, yaw and roll; not measured."},Vx={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:fe(1.4,-.3),hRear:fe(1.4,.05)},dBalance:{hFront:Qe(-.25),hRear:Qe(.15)},dCd:{hFront:fe(.42,-.1),hRear:0},yaw:{dCl:fe(1.4,-.8),dBalance:Qe(-.2),dCd:fe(.42,.6),maxDeg:10},roll:{dCl:fe(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."},Bx={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:fe(.3,.5),maxDeg:10},note:"Assumed class-level sensitivities for a road car with no aero devices; not measured."},$x={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:fe(.45,-.4),hRear:fe(.45,.05)},dBalance:{hFront:Qe(-.25),hRear:Qe(.15)},dCd:{hFront:fe(.4,-.1),hRear:0},yaw:{dCl:fe(.45,-1.2),dBalance:Qe(-.2),dCd:fe(.4,.6),maxDeg:10},roll:{dCl:fe(.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."},Gx={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:fe(.6,-.35),hRear:fe(.6,.05)},dBalance:{hFront:Qe(-.25),hRear:Qe(.15)},dCd:{hFront:fe(.45,-.1),hRear:0},yaw:{dCl:fe(.6,-1),dBalance:Qe(-.2),dCd:fe(.45,.6),maxDeg:10},roll:{dCl:fe(.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."},Kx={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:fe(2.5,-.35),hRear:fe(2.5,.05)},dBalance:{hFront:Qe(-.25),hRear:Qe(.15)},dCd:{hFront:fe(.9,-.1),hRear:fe(.9,.05)},yaw:{dCl:fe(2.5,-1),dBalance:Qe(-.3),dCd:fe(.9,.5),maxDeg:10},roll:{dCl:fe(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."},Hx={name:"Race truck aero",area:6.2,cl:-.1,balanceFront:.6,cd:.65,ref:{hFront:110,hRear:240},range:{hFront:[60,160],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:fe(.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 Cr(e){return Sd({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 Td=()=>Cr(Nx),Pd=()=>Cr(Ox),Ld=()=>Cr(Vx),Dd=()=>Cr(Bx),Ed=()=>Cr($x),Id=()=>Cr(Gx),_d=()=>Cr(Kx),Nd=()=>Cr(Hx);function $n(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 dl(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,qe(e,"front")))/r,rear:(t.sprungMass*(1-n)+o*a(t.rideRateRear,qe(e,"rear")))/r}}function fl(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 Od(e,t){return e.wheelbase>0?e.massTotal*t*9.81/e.wheelbase:0}function Qo(e,t,r){let n=2*t.rideRateFront,o=2*t.rideRateRear;return!(n>0)||!(o>0)?0:Math.min(Rd(t.sprungMass,r,e.wheelbase),.5*n*o/(n+o))}function ys(e,t,r,n,o){let a=e.cgHeight,s=Od(e,r);if(n===0&&o===0&&s===0)return{height:a,forward:0,noseLoad:0,dropFront:0,dropRear:0};let i=dl(e,t),c=2*t.rideRateFront,l=2*t.rideRateRear,u=a,m=0,f=0,p=0;for(let h=0;h<6;h++){p=Qo(e,t,u);let b=n-s*u,g=o+s*u;if(p>0){let k=c*l-p*(c+l);m=(b*(l-p)-p*g)/k,f=(g*(c-p)-p*b)/k}else m=c>0?b/c:0,f=l>0?g/l:0;let y=fl(a,i,m,f),R=Math.abs(y-u);if(u=y,R<1e-9)break}let d=m-f;return{height:u,forward:e.wheelbase>0?u*d/e.wheelbase:0,noseLoad:p*d,dropFront:m,dropRear:f}}var Vd={yawDeg:0,rollDeg:0},zx=1e-4,XT=40,Yx=50;function cn(e,t,r=0){let n=e.aero?.model;if(!(!n||!sn(n,e).hasAttitude))return{yawDeg:r,rollDeg:Ce(e).rollGradient*t}}function Zo(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 qo(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=cl(r)?n(r.frame,r.ref.h,r.ref.pitch):r.ref;else if(r){let{x:a,y:s}=Uo(r),i=(a[0]+a[a.length-1])/2,c=(s[0]+s[s.length-1])/2;o=an(r)?n(r.frame,i,c):{hFront:i,hRear:c}}return{hFront:e.rideHeightFront??o.hFront,hRear:e.rideHeightRear??o.hRear}}var Wx=new WeakMap;function Tr(e,t,r=0,n){let o=e.aero;if(!o?.model)return null;let a=Wx.get(e);a||(a=new Map,Wx.set(e,a));let s=n&&sn(o.model,e).hasAttitude?n:Vd,i=s===Vd?`${t}|${r}`:`${t}|${r}|${s.yawDeg.toFixed(3)}|${s.rollDeg.toFixed(3)}`,c=a.get(i);if(c)return c;let l=qT(e,o,t,r,s);return a.size>4096&&a.clear(),a.set(i,l),l}function qT(e,t,r,n,o){let a=sn(t.model,e),s=Ce(e),i=2*s.rideRateFront,c=2*s.rideRateRear,l=Zo(t,e.wheelbase),u=.5*t.rho*r*r,m=a.area,f=e.wheelbase>0?t.copHeight/e.wheelbase:0,p=dl(e,s),d=Od(e,n),h=(T,P)=>fl(e.cgHeight,p,l.hFront-T,l.hRear-P),b=(T,P)=>l.hFront-T-(l.hRear-P),g=(T,P)=>{let S=a.at(T,P,o.yawDeg,o.rollDeg),F=u*m*S.clFront,C=u*m*S.clRear,L=u*m*S.cd,E=L*f,D=h(T,P),O=d*D,_=Qo(e,s,D)*b(T,P),z=F-O-E+_,I=C+O+E-_,N=T-l.hFront+(i>0?z/i:0),B=P-l.hRear+(c>0?I/c:0);return{c:S,downFront:F,downRear:C,drag:L,rF:N,rR:B,norm:Math.hypot(N,B)}},y=(T,P,S=!1)=>{let F=a.slopes(T,P,S,o.yawDeg,o.rollDeg),C=i>0?u*m/i:0,L=c>0?u*m/c:0;return[[C*(F.clFront.hFront-f*F.cd.hFront),C*(F.clFront.hRear-f*F.cd.hRear)],[L*(F.clRear.hFront+f*F.cd.hFront),L*(F.clRear.hRear+f*F.cd.hRear)]]},R=l.hFront,k=l.hRear,v=g(R,k),x=0;for(;v.norm>=zx&&x<XT;){x++;let T=y(R,k),P=i>0?d/i:0,S=c>0?d/c:0,F=Qo(e,s,h(R,k)),C=i>0?F/i:0,L=c>0?F/c:0,E=1+T[0][0]-P*p.front-C,D=T[0][1]-P*p.rear+C,O=T[1][0]+S*p.front+L,_=1+T[1][1]+S*p.rear-L,z=E*_-D*O,I,N;Math.abs(z)>1e-9?(I=-(_*v.rF-D*v.rR)/z,N=-(-O*v.rF+E*v.rR)/z):(I=-.5*v.rF,N=-.5*v.rR);let B=Math.max(1,Math.abs(I)/Yx,Math.abs(N)/Yx);I/=B,N/=B;let V=1;for(let G=0;G<6;G++){let H=g(R+V*I,k+V*N);if(H.norm<=v.norm||G===5){R+=V*I,k+=V*N,v=H;break}V*=.5}}let M=y(R,k,!0),A=2+M[0][0]+M[1][1],w=(1+M[0][0])*(1+M[1][1])-M[0][1]*M[1][0];return{v:r,axG:n,hFront:R,hRear:k,cgHeight:h(R,k),cgForward:e.wheelbase>0?h(R,k)*b(R,k)/e.wheelbase:0,cgNoseLoad:Qo(e,s,h(R,k))*b(R,k),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:QT(M),stable:w>0&&A>0,converged:v.norm<zx,iterations:x,clampedRide:v.c.clampedRide,yawDeg:o.yawDeg,rollDeg:o.rollDeg,clampedAttitude:v.c.clampedAttitude}}function QT(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 xs(e,t,r=0,n){let o=Tr(e,t,r,n);return o?{downforce:o.downforce,drag:o.drag,downFront:o.downFront,downRear:o.downRear}:e.aero?$n(e.aero,t):{downforce:0,drag:0,downFront:0,downRear:0}}function ZT(e,t,r,n){let o=$n(t,r),a=Ce(e),s=Zo(t,e.wheelbase),i=e.wheelbase>0?o.drag*t.copHeight/e.wheelbase:0,c=ys(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 Bd(e,t,r=0,n){let o=Tr(e,t,r,n);return o||(e.aero?ZT(e,e.aero,t,r):null)}function hl(e,t=0,r=0,n,o){if(e.aero&&t>0){if(e.aero.model){let i=Tr(e,t,r,n);return{height:i.cgHeight,forward:i.cgForward,noseLoad:i.cgNoseLoad}}let a=$n(e.aero,t),s=e.wheelbase>0?a.drag*e.aero.copHeight/e.wheelbase:0;return ys(e,o??Ce(e),r,a.downFront-s,a.downRear+s)}return r===0?{height:e.cgHeight,forward:0,noseLoad:0}:ys(e,o??Ce(e),r,0,0)}var jx=[0,1,0],$d=[0,0,1],te=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],K=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],U=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Gd=e=>[-e[0],-e[1],-e[2]],X=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],oe=(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]],JT=e=>X(e,e),ln=e=>Math.sqrt(X(e,e)),Rs=(e,t)=>JT(K(e,t)),Me=(e,t)=>ln(K(e,t)),q=e=>{let t=ln(e);return t<1e-12?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]};var un=(e,t,r)=>{let n=q(r),o=K(e,t);return te(t,U(n,X(o,n)))},Ux=(e,t,r)=>Me(e,un(e,t,r));var tP=1e-6;function rP(e){if(e<tP){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 st(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]=rP(r),a=oe(e,t),s=oe(e,a);return te(t,te(U(a,n),U(s,o)))}function Gt(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 st(U(o,r),e)}function ir(e,t){let r=t.length,n=e.map(a=>a.slice()),o=t.slice();return qx(n,o,r,new Array(r).fill(0))}function Xx(e,t,r){return qx(e,t,t.length,r)}function qx(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 f=s;f<r;f++)e[u][f]-=m*e[s][f];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 Qx=e=>{let t=0;for(let r of e)t=Math.max(t,Math.abs(r));return t},Zx=e=>{let t=0;for(let r of e)t+=r*r;return t},nP=Math.sqrt(Number.EPSILON);function Jx(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=Qx(c),u=Zx(c),m=.001,f=1,p=c.length,d=Array.from({length:p},()=>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),R=new Array(a).fill(0),k=new Array(a).fill(0),v=new Array(a).fill(0);for(let x=0;x<n;x++){if(l<o)return{x:i,residualNorm:l,iterations:x,converged:!0,condProxy:f};for(let T=0;T<a;T++){let P=nP*Math.max(Math.abs(i[T]),s[T]);for(let F=0;F<a;F++)k[F]=i[F];k[T]+=P;let S=e(k);for(let F=0;F<p;F++)d[F][T]=(S[F]-c[F])/P}let M=0;for(let T=0;T<a;T++){for(let S=0;S<a;S++){let F=0;for(let C=0;C<p;C++)F+=d[C][T]*d[C][S];h[T][S]=F}let P=0;for(let S=0;S<p;S++)P+=d[S][T]*c[S];g[T]=P,M=Math.max(M,h[T][T])}let A=Math.max(M,1e-9),w=!1;for(let T=0;T<18;T++){let P=m*A;for(let F=0;F<a;F++){let C=h[F],L=b[F];for(let E=0;E<a;E++)L[E]=F===E?C[E]+P:C[E];y[F]=-g[F]}let S=Xx(b,y,R);if(f=Math.max(f,S.condProxy),!S.singular){for(let L=0;L<a;L++)v[L]=i[L]+R[L];let F=e(v),C=Zx(F);if(C<u){for(let L=0;L<a;L++)i[L]=v[L];c=F,u=C,l=Qx(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:f}}function vs(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 Kd(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 eR=e=>[e[0],-e[1],-e[2],-e[3]];function tR(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 rR(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 nR(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 Hd(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],f=n+i+m;if(f>=n&&f>=i&&f>=m){let h=Math.sqrt(1+f),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 p=Math.sqrt(1-n-i+m),d=.5/p;return[(o-s)*d,(l+a)*d,(u+c)*d,.5*p]}function oR(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 aR(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 oP(e){let t=Math.abs(e[0])<.6?[1,0,0]:[0,1,0],r=q(oe(e,t));return[r,oe(e,r)]}function aP(e){let t=e.hardpoints,r=q(K(t.damperChassis,t.pushrodOuter)),[n,o]=oP(r);return{top:t.damperChassis,lower0:t.pushrodOuter,axis0:r,e1:n,e2:o}}function zd(e){let t=e.hardpoints,r=t.wheelCenter,n=q(K(t.ucaRear,t.ucaFront)),o=K(t.uprightUpper,t.ucaFront),a=X(o,n),s=K(o,U(n,a)),i=X(s,s),c=q(K(t.lcaRear,t.lcaFront)),l=K(t.uprightLower,t.lcaFront),u=Rs(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:q(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:aP(e)}:{}}}function Kt(e,t,r){let n=[t[3],t[4],t[5]],o=[t[0],t[1],t[2]],a=K(r,e.c0);return te(te(st(n,a),e.c0),o)}function Yd(e,t){return te(e.lcaFront,Gt(e.lbjRel0,e.lcaDir,t))}function Gn(e,t){return e.steerMovesRack?te(e.tieInner0,U(e.rackAxis,t)):e.tieInner0}function Wd(e,t,r,n){let o=Kt(e,t,e.lbj0),a=Yd(e,r),s=o[0]-a[0],i=o[1]-a[1],c=o[2]-a[2],l,u;if(e.strut){let d=e.strut,h=[t[3],t[4],t[5]],b=K(d.top,Kt(e,t,d.lower0));l=X(b,st(h,d.e1)),u=X(b,st(h,d.e2))}else{let d=Kt(e,t,e.ubj0),h=K(d,e.ucaFront),b=X(h,e.ucaDir),g=K(h,U(e.ucaDir,b));l=b-e.ubjAxial0,u=(X(g,g)-e.ubjRadius2)/e.ubjRadiusRef}let m=Kt(e,t,e.tro0),f=Gn(e,n),p=(Rs(m,f)-e.tieLen2)/e.tieLenRef;return[s,i,c,l,u,p]}var ks=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]),bl=e=>{let t=ks(e);return[e[0]/t,e[1]/t,e[2]/t]},sP=(e,t)=>K(e,U(t,X(e,t))),jd=e=>bl(oe(e,Math.abs(e[0])<.6?[1,0,0]:[0,1,0]));function iP(e,t){let r=e.ucaDir,n=te(e.ucaFront,U(r,e.ubjAxial0)),o=Math.sqrt(e.ubjRadius2),a=sP(K(e.ubj0,e.ucaFront),r),s=ks(a)>1e-9?bl(a):jd(r),i=oe(r,s),c=K(e.ubj0,e.lbj0),l=X(c,c);if(!(l>1e-18))return"free";let u=K(n,t),m=X(u,u),f=vs(2*o*X(s,u),2*o*X(i,u),l-m-o*o,2*o*Math.sqrt(m));if(f.free)return"free";let p=bl(c),d=(h,b)=>{let g=te(n,te(U(s,o*h),U(i,o*b))),y=bl(K(g,t));return{q1:rR(p,y),k:y,margin:f.margin,ok:f.ok}};return f.margin>0?[d(f.c1,f.s1),d(f.c2,f.s2)]:[d(f.c1,f.s1)]}function cP(e,t,r){let n=t.axis0,o=te(t.lower0,U(n,X(K(e.lbj0,t.lower0),n))),a=K(o,e.lbj0),s=ks(a),i=s>1e-9?U(a,1/s):jd(n),c=K(t.top,r),l=ks(c);if(!(l>1e-9))return"free";let u=U(c,1/l),m=s/l,f=1-m,p=f>=0?Math.sqrt((1-m)*(1+m)):0,d=jd(u),h=b=>{let g=b*p,y=te(U(u,g),U(d,Math.min(m,1))),R=K(U(u,Math.min(m,1)),U(d,g));return{q1:Kd(Hd(R,y,oe(R,y)),eR(Hd(i,n,oe(i,n)))),k:u,margin:f,ok:f>=0}};return f>0?[h(1),h(-1)]:[h(1)]}function lP(e,t,r,n){let{k:o}=n,a=tR(n.q1,K(e.tro0,e.lbj0)),s=X(a,o),i=K(a,U(o,s)),c=ks(i);if(!(c>1e-9))return"free";let l=U(i,1/c),u=oe(o,l),m=te(t,U(o,s)),f=K(m,r),p=X(f,f),d=vs(2*c*X(f,l),2*c*X(f,u),e.tieLen2-p-c*c,2*c*Math.sqrt(p));if(d.free)return"free";let h=(g,y)=>({q:Kd(nR(o,g,y),n.q1)});return{roots:d.margin>0?[h(d.c1,d.s1),h(d.c2,d.s2)]:[h(d.c1,d.s1)],margin:d.margin,ok:d.ok}}function sR(e,t,r,n=[0,0,0,0,0,0]){let o=Yd(e,t),a=Gn(e,r),s=oR([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?cP(e,e.strut,o):iP(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=lP(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:R}of b.roots){let k=i(R);y&&(!l||k>l.near)&&(l={q:R,margin:g,near:k}),!y&&(!u||k>u.near)&&(u={q:R,margin:g,near:k})}}let{q:m,margin:f}=l??u,p=aR(m),d=K(K(o,e.c0),st(p,K(e.lbj0,e.c0)));return{x:[d[0],d[1],d[2],p[0],p[1],p[2]],converged:l!==null,margin:f,free:!1}}function cR(e){let t=q(K(e.rockerPivotB,e.rockerPivotA));return{pivotA:e.rockerPivotA,axis:t,rprRel0:K(e.rockerToPushrod,e.rockerPivotA),rdmRel0:K(e.rockerToDamper,e.rockerPivotA),damperChassis:e.damperChassis,rodLen2:Rs(e.pushrodOuter,e.rockerToPushrod),damperLen0:Me(e.rockerToDamper,e.damperChassis)}}var uP=(e,t)=>te(e.pivotA,Gt(e.rprRel0,e.axis,t)),Ud=(e,t)=>te(e.pivotA,Gt(e.rdmRel0,e.axis,t));function Jo(e,t){return{pushrod:uP(e,t),damper:Ud(e,t)}}function lR(e,t,r=0){let n=X(e.rprRel0,e.axis),o=K(e.rprRel0,U(e.axis,n)),a=oe(e.axis,o),s=K(te(e.pivotA,U(e.axis,n)),t),i=X(o,o),c=X(s,s),l=vs(2*X(s,o),2*X(s,a),e.rodLen2-c-i,2*Math.sqrt(i*c));if(l.free){let p=Math.abs(e.rodLen2-c-i)<=1e-9*e.rodLen2;return{phi:r,damperLength:Me(Ud(e,r),e.damperChassis),converged:p,margin:0}}let u=iR(Math.atan2(l.s1,l.c1),r),m=iR(Math.atan2(l.s2,l.c2),r),f=Math.abs(m-r)<Math.abs(u-r)?m:u;return{phi:f,damperLength:Me(Ud(e,f),e.damperChassis),converged:l.ok,margin:l.margin}}function iR(e,t){let r=2*Math.PI;return e+r*Math.round((t-e)/r)}function uR(e,t,r,n){return te(t,st(U(q(r),n),K(e,t)))}function mR(e,t,r,n){let o=q(n),a=f=>{let p=K(f,r);return K(p,U(o,X(p,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,X(s,i)/(c*l))),m=X(oe(s,i),o)/(c*l);return Math.atan2(m,u)}function pR(e,t,r,n){return te(t,st(U(q(r),n),K(e,t)))}var gl=180/Math.PI,mP=(e,t,r)=>Math.max(t,Math.min(r,e)),dR=[NaN,NaN,NaN];function Ms(e){let t=q(e.spinAxis),r=q(K(e.uprightUpper,e.uprightLower)),n=-Math.asin(mP(t[2],-1,1))*gl,o=Math.atan2(t[0],t[1])*gl,a=Math.atan2(-r[0],r[2])*gl,s=Math.atan2(-r[1],r[2])*gl,i=q(te([0,0,-1],U(t,t[2]))),c=te(e.wheelCenter,U(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,f=w=>te(u,U(r,(w-u[2])/r[2])),p=m?f(l[2]):dR,d=m?f(e.wheelCenter[2]):dR,h=l[1]-p[1],b=p[0]-l[0],g=q(oe(t,[0,0,1])),y=oe([0,0,1],g),R=K(l,p),k=X(R,y),v=-X(R,g),x=e.wheelCenter[1]-d[1],M=d[0]-e.wheelCenter[0],A=Ux(e.tieOuter,u,r);return{camber:n,toe:o,caster:a,kpi:s,scrubRadius:h,mechanicalTrail:b,scrubAtWheel:k,trailAtWheel:v,kingpinOffset:x,casterOffset:M,steeringArm:A,contactPatch:l,kingpinGround:p,kingpinAtHub:d}}function rt(e){return{corner:e,inv:zd(e),rocker:cR(e.hardpoints)}}var pP=[20,20,20,.2,.2,.2];function hR(e,t,r,n=[0,0,0,0,0,0]){let o=sR(e,t,r,n);if(!o.free)return o;let a=dP(e,t,r,n);return{x:a.x,converged:a.converged,margin:0}}function dP(e,t,r,n=[0,0,0,0,0,0]){return Jx(o=>Wd(e,o,t,r),n,{scales:pP,tol:1e-10,maxIter:40})}var fP=.01,yl=1.2,ft=e=>e.ok?e.state:null,it=e=>e.ok?e.state:e.nearest;function ge(e,t,r,n,o){let a=0,s=Ne(e,a,r,n,o);if(Math.abs(s.travel-t)<1e-4)return fR(s,t,!1);let c=(Ne(e,.02,r,Xd(s),o).travel-s.travel)/.02;(!Number.isFinite(c)||Math.abs(c)<1e-6)&&(c=1);let l=f=>Math.max(-yl,Math.min(yl,f)),u=l((t-s.travel)/c),m=Ne(e,u,r,Xd(s),o);for(let f=0;f<12&&!(Math.abs(m.travel-t)<1e-4);f++){let p=m.travel-s.travel,d=Math.abs(p)<1e-9?u:u-(m.travel-t)*((u-a)/p);a=u,s=m,u=l(d),m=Ne(e,u,r,Xd(s),o)}return fR(m,t,Math.abs(u)===yl)}function fR(e,t,r){let n=e.travel-t,o=Math.abs(n)<=fP,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 Xd(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 hP(e,t,r,n,o){switch(e){case"upright":return Kt(t,r,o.pushrodOuter);case"upperArm":{let a=Kt(t,r,t.ubj0),s=mR(t.ubj0,a,t.ucaFront,t.ucaDir);return pR(o.pushrodOuter,t.ucaFront,t.ucaDir,s)}default:return uR(o.pushrodOuter,t.lcaFront,t.lcaDir,n)}}function Ne(e,t,r,n,o){let{inv:a,corner:s}=e,i=n?.q??[0,0,0,0,0,0],c=hR(a,t,r,i),l=c.x,u=[l[3],l[4],l[5]],m={t:[l[0],l[1],l[2]],omega:u},f=s.hardpoints,p=s.config,d=a.strut,h=d?d.top:Kt(a,l,f.uprightUpper),b=Kt(a,l,f.uprightLower),g=Kt(a,l,f.tieOuter),y=Kt(a,l,f.wheelCenter),R=q(st(u,p.spinAxis)),k=hP(d?"upright":p.pushrodAttach,a,l,t,f),v=d?d.top:f.damperChassis,x=d||p.actuation==="direct"?{phi:0,damperLength:Me(k,v),converged:!0,margin:1}:lR(e.rocker,k,n?.phi??0),M=Ms({uprightUpper:h,uprightLower:b,wheelCenter:y,spinAxis:R,tieOuter:g,loadedRadius:o?.loadedRadius??p.loadedRadius,patchShift:o?.patchShift});return{pose:m,beta:t,travel:l[2],steer:r,points:{uprightUpper:h,uprightLower:b,tieOuter:g,wheelCenter:y,pushrodOuter:k,spinAxis:R,contactPatch:M.contactPatch,kingpinGround:M.kingpinGround,kingpinAtHub:M.kingpinAtHub,rockerAngle:x.phi,damperLength:x.damperLength},metrics:{camber:M.camber,toe:M.toe,caster:M.caster,kpi:M.kpi,scrubRadius:M.scrubRadius,mechanicalTrail:M.mechanicalTrail,scrubAtWheel:M.scrubAtWheel,trailAtWheel:M.trailAtWheel,kingpinOffset:M.kingpinOffset,casterOffset:M.casterOffset,steeringArm:M.steeringArm,damperLength:x.damperLength},converged:c.converged&&x.converged,margin:Math.min(c.margin,x.margin)}}var ea=e=>e==="FL"||e==="FR"?"front":"rear",gR=e=>e==="FL"||e==="RL"?"left":"right";function Oe(e,t){return e.corners?.[t]??bP(e[ea(t)],gR(t))}function yR(e){let t=e.config.springSplit;return e.config.actuation==="decoupled"||t===void 0||!Number.isFinite(t)||Math.abs(t)>=1?0:t}var bR=new WeakMap;function bP(e,t){let r=yR(e);if(r===0)return e;let n=bR.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)},bR.set(e,n)}return n[t]}var cr=["FL","FR","RL","RR"],Rt=e=>2*e.hardpoints.wheelCenter[1],Ht=(e,t)=>t?Rt(Oe(e,"FL"))/2+Rt(Oe(e,"FR"))/2:Rt(Oe(e,"RL"))/2+Rt(Oe(e,"RR"))/2;function He(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 Pt(e,t){return[t.axleX+e[0],t.sideSign*e[1],e[2]]}function Pr(e,t){return[e[0],t.sideSign*e[1],e[2]]}function mn(e){return e.frontAxleX-e.wheelbase/2}function qd(e,t,r){return t[2]+e.heave+(t[0]-r)*Math.sin(e.pitch)-t[1]*Math.sin(e.roll)}function pn(e,t,r,n){let o=He(e,t),a=(n?Ht(n,o.isFront):o.isFront?t.trackFront:t.trackRear)/2,s=o.sideSign*a,i=o.axleX-mn(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 gP={travelMin:-40,travelMax:40,steps:41,steer:0};function Ss(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 ze(e,t={}){let r={...gP,...t},n=rt(e);return ta(n,r)}function ta(e,t){let r=t.steer,n=.01,o=Ne(e,n,r),a=Ne(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=Ne(e,0,r);u.push({beta:0,travel:m.travel,warm:Ss(m),converged:m.converged});let f=Ss(m);for(let R=1;R<=l;R++){let k=c*R/l,v=Ne(e,k,r,f);f=Ss(v),u.push({beta:k,travel:v.travel,warm:f,converged:v.converged})}f=Ss(m);for(let R=1;R<=l;R++){let k=-c*R/l,v=Ne(e,k,r,f);f=Ss(v),u.push({beta:k,travel:v.travel,warm:f,converged:v.converged})}u.sort((R,k)=>R.beta-k.beta);let p=u[u.length-1].travel>=u[0].travel,d=!1;for(let R=1;R<u.length;R++){let k=u[R].travel-u[R-1].travel;(p&&k<-1e-6||!p&&k>1e-6)&&(d=!0)}let h=u.filter(R=>R.converged).map(R=>R.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 R=0;R<t.steps;R++){let k=t.steps===1?t.travelMin:t.travelMin+(t.travelMax-t.travelMin)*R/(t.steps-1),v=yP(u,k,p),x=xP(u,v);y.push(Ne(e,v,r,x))}return RP(y,e.corner.config.actuation==="decoupled"?0:e.corner.config.springRate),{samples:y,covered:g,reach:b,fold:d,unconverged:y.filter(R=>!R.converged).length}}function yP(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 xP(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 Qd(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 RP(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=Qd(n,r,s),c=Qd(o,r,s),l=-Qd(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 xl=e=>e!==void 0&&Number.isFinite(e)&&e>0;function vP(e){return e&&xl(e.helperRate)&&xl(e.helperTravel)?{rate:e.helperRate,travel:e.helperTravel}:null}function Zd(e,t,r){let n=t/e;return r?n+Math.min(t/r.rate,r.travel):n}function As(e,t,r,n){if(!(e>0)||!Number.isFinite(e)||!(t>0)||!Number.isFinite(t))return null;let o=vP(n),a=-Zd(e,t,o),s=ra(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 ra(e,t){if(!Number.isFinite(e))return{droop:null,bump:null};let r=xl(t?.extended)&&t.extended>e?t.extended:null,n=r!==null&&xl(t?.stroke)?r-t.stroke:null;return{droop:r!==null?e-r:null,bump:n!==null&&n<e?e-n:null}}function Jd(e,t){if(!(e>0)||!Number.isFinite(e))return null;let r=ra(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 kP(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=Zd(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 MP(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=Zd(r,n,o)+t;return a<=0?0:a>=o.rate*o.travel/r+o.travel?r:r*o.rate/(r+o.rate)}function na(e,t){let r=kP(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 ef(e,t){let r=MP(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 tf(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 Rl={min:-60,max:60,steps:61},rf=e=>({travel:[e.min,e.max],force:[0,0],motionRatio:[0,0],spring:null}),xR=new WeakMap;function SP(e,t){let r=xR.get(e.corner);r||xR.set(e.corner,r=new Map);let n=`${t.min}|${t.max}|${t.steps}`,o=r.get(n);return o||r.set(n,o=ta(e,{travelMin:t.min,travelMax:t.max,steps:t.steps,steer:0})),o}function ws(e,t,r=Rl,n=e.corner.config.coilover){let o=e.corner.config;if(o.actuation==="decoupled")return rf(r);let a=SP(e,r),s=FP(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 rf(r);let c=CP(i,0);if(!(Math.abs(c.mr)>1e-6))return rf(r);let l=t/c.mr,u=As(s,l,c.L,n),m=u?AP(i,tf(u).map(h=>c.L-h)):i,f=m.map(h=>(u?na(u,c.L-h.L):l+s*(c.L-h.L))*h.mr-t),p=h=>h===null?null:m.find(b=>b.L===c.L-h)?.t??null,d=u?tf(u).map(p).filter(h=>h!==null):[];return{travel:m.map(h=>h.t),force:f,motionRatio:m.map(h=>h.mr),spring:{rate:s,preload:l,length0:c.L,law:u},...u?{stops:{droop:p(u.droop),bump:p(u.bump)}}:{},...d.length?{kinks:d}:{},length:m.map(h=>h.L)}}function nf(e,t){if(!e.spring)return null;let r=e.travel.length,n=e.length;if(n&&n.length===r&&r>=2){let s=lr(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+=(Fs(e,i)+Fs(e,c))/2*(c-i)}return a}function AP(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 FP(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:wP(e,n,r);return!(o>0)||!Number.isFinite(o)?t:t*o/(t+o)}function wP(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=Jo(e.rocker,n.points.rockerAngle),s=q(K(o.rockerPivotB,o.rockerPivotA)),i=(m,f)=>Math.abs(X(s,oe(K(m,o.rockerPivotA),q(K(f,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 Fs(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.motionRatio[0];let n=lr(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 Lr(e,t,r){if(!e.spring)return Qt(e,t);let{rate:n,preload:o,length0:a,law:s}=e.spring,i=Fs(e,0),c=a-r;return(s?na(s,c):o+n*c)*Fs(e,t)-o*i}function CP(e,t){let r=lr(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 lr(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 Qt(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.force[0];let n=lr(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 oa(e,t){let r=e.travel.length;if(r<3)return Cs(e,t);let n=lr(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 Cs(e,t){if(e.travel.length<2)return 0;let n=lr(e.travel,t);return(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n])}function De(e,t,r){let n=e.hardpoints;switch(t.attach){case"upright":{let o=K(t.outer,n.wheelCenter);return te(te(st(r.pose.omega,o),n.wheelCenter),r.pose.t)}case"lowerArm":{let o=q(K(n.lcaRear,n.lcaFront));return te(n.lcaFront,st(U(o,r.beta),K(t.outer,n.lcaFront)))}case"rocker":{let o=q(K(n.rockerPivotB,n.rockerPivotA));return te(n.rockerPivotA,Gt(K(t.outer,n.rockerPivotA),o,r.points.rockerAngle))}}}function dn(e,t,r){return e.config.actuation==="decoupled"&&t.attach==="rocker"&&r==="coil"}function of(e,t,r){return dn(e,t,r)?[t.inner[0],-t.inner[1],t.inner[2]]:t.inner}function aa(e,t,r){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return af(e,t,r.kind,ze(e,{travelMin:n,travelMax:o,steps:a}).samples)}function af(e,t,r,n){let o=q(K(t.outer,of(e,t,r))),a=[],s=[],i=t.outer;for(let p of n)a.push(p.travel),s.push(X(K(De(e,t,p),i),o));let c=a.length,l=new Array(c).fill(0);for(let p=0;p<c;p++){let d=Math.max(0,p-1),h=Math.min(c-1,p+1),b=a[h]-a[d];l[p]=b!==0?(s[h]-s[d])/b:0}let u=l[0];for(let p=1;p<c;p++)if(a[p]>=0){let d=a[p]-a[p-1],h=d!==0?(0-a[p-1])/d:0;u=l[p-1]+h*(l[p]-l[p-1]);break}let m=l.filter(p=>Math.abs(p)>1e-9).map(Math.sign),f=m.length>0&&m.some(p=>p!==m[0]);return{travel:a,ratio:l,linkTravel:s,atDesign:u,reverses:f}}function sf(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 cf(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 Ts=e=>e.mount??{kind:"rockerToRocker"},MR=e=>[e[0],0,e[2]],TP=e=>2*Math.abs(e[1]),PP=(e,t)=>Math.hypot(e[0]-t[0],e[2]-t[2]);function kl(e,t){return t.kind==="chassis"?PP(e,t.anchor):TP(e)}function Ps(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 Kn(e,t,r={}){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return lf(e,t,ze(e,{travelMin:n,travelMax:o,steps:a}).samples)}function lf(e,t,r){let n=Ts(t),o=d=>De(e,{...t,inner:t.outer},r[d]),a=[],s=[],i=[];for(let d=0;d<r.length;d++)a.push(r[d].travel),i.push(kl(o(d),n));let c=vR(a,i,0);for(let d of i)s.push(c-d);let l=a.length,u=new Array(l).fill(0);for(let d=0;d<l;d++){let h=Math.max(0,d-1),b=Math.min(l-1,d+1),g=a[b]-a[h];u[d]=g!==0?(s[b]-s[h])/g:0}let m=RR(a,20),f=RR(a,-20),p=Ps(o(m),o(f),n);return{travel:a,ratio:u,springTravel:s,atDesign:vR(a,u,0),installedLength:c,rollSensitivity:c-p}}function RR(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 vR(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 uf(e,t,r){let n={outer:t.outer,attach:t.attach},o=ze(e,{travelMin:-5,travelMax:5,steps:3}),a=d=>MR(De(e,{...n,inner:n.outer},o.samples[d])),s=a(1),i=a(2),c=a(0),l=i[0]-c[0],u=i[2]-c[2],m=Math.hypot(l,u),f=m>1e-9?[l/m,u/m]:[0,1],p=r??Math.max(80,2*Math.abs(t.outer[1])*.5);return[s[0]+f[0]*p,0,s[2]+f[1]*p]}function mf(e,t){let r=e.hardpoints,n=r.rockerPivotA,o=kR(vl(r.rockerPivotB,r.rockerPivotA)),a=Math.max(30,.6*SR(vl(r.rockerToDamper,n))),s=vl(r.rockerToDamper,n),i=kR(vl(s,LP(o,DP(s,o)))),c=EP(o,i),l=null,u=-1/0;for(let m=0;m<360;m+=10){let f=m*Math.PI/180,d={outer:[n[0]+a*(Math.cos(f)*i[0]+Math.sin(f)*c[0]),n[1]+a*(Math.cos(f)*i[1]+Math.sin(f)*c[1]),n[2]+a*(Math.cos(f)*i[2]+Math.sin(f)*c[2])],attach:"rocker"},h=t==="chassis"?{...d,mount:{kind:"chassis",anchor:uf(e,d)}}:d,b;try{b=Kn(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 vl=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],LP=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],DP=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],SR=e=>Math.hypot(e[0],e[1],e[2]),kR=e=>{let t=SR(e)||1;return[e[0]/t,e[1]/t,e[2]/t]},EP=(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 pf=.001,IP=e=>({outer:e.outer,inner:e.outer,attach:e.attach}),DR=(e,t,r)=>(kl(e.at0,t)-kl(r,t))/2,_P=(e,t)=>X(K(t,e.pickup.at0),e.axis);function df(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 AR(e,t){let r=[0,1,2].map(n=>df(e,t.map(o=>o[n])));return t.map((n,o)=>[r[0][o],r[1][o],r[2][o]])}function ff(e){return{travel:e,heave:e.map(t=>t/2),heaveRatio:e.map(()=>.5),roll:[...e],rollRatio:e.map(()=>1)}}function FR(e,t,r,n){let o=e.corner;if(!t.heave&&!t.roll)return{side:ff([n.min,n.max]),pickups:{}};let a=it(ge(e,0,0)),s={};if(t.heave&&r){let h=IP(t.heave);s.heave={corner:o,link:h,at0:De(o,h,a)}}if(t.roll){let h=t.roll;s.roll={pickup:{corner:o,link:h,at0:De(o,h,a)},axis:q(K(h.outer,of(o,h,t.rollKind??"coil")))}}let i=t.roll&&dn(o,t.roll,t.rollKind??"coil")?{near:t.roll,far:{...t.roll,outer:t.roll.inner}}:null,c=ta(e,{travelMin:n.min,travelMax:n.max,steps:n.steps,steer:0}),l=[],u=[],m=[],f=[],p=[];for(let h of c.samples)!h.converged||l.length>0&&h.travel<=l[l.length-1]+1e-6||(l.push(h.travel),u.push(s.heave&&r?DR(s.heave,r,De(o,s.heave.link,h)):h.travel/2),m.push(s.roll?_P(s.roll,De(o,s.roll.pickup.link,h)):h.travel),i&&(f.push(De(o,i.near,h)),p.push(De(o,i.far,h))));if(l.length<2)return{side:ff([n.min,n.max]),pickups:{}};let d={travel:l,heave:u,heaveRatio:df(l,u),roll:m,rollRatio:df(l,m)};return i&&(d.eyes={near:f,nearRatio:AR(l,f),far:p,farRatio:AR(l,p)}),{side:d,pickups:s}}function Ml(e,t,r){let n=lr(e,r);return t[n]+(r-e[n])/(e[n+1]-e[n])*(t[n+1]-t[n])}function wR(e,t,r){let n=lr(e,r);return(t[n+1]-t[n])/(e[n+1]-e[n])}function Ve(e,t){return{h:Ml(e.travel,e.heave,t),dh:Ml(e.travel,e.heaveRatio,t),ddh:wR(e.travel,e.heaveRatio,t),r:Ml(e.travel,e.roll,t),dr:Ml(e.travel,e.rollRatio,t),ddr:wR(e.travel,e.rollRatio,t)}}function CR(e,t,r,n){let o=lr(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 hf=(e,t)=>Math.hypot(e[0]-t[0],e[1]+t[1],e[2]-t[2]);function bf(e,t){let r=e.side[0].eyes,n=e.side[1].eyes;if(!r||!n)return null;let o=CR(e.side[0].travel,r.near,r.nearRatio,t[0]),a=CR(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]],f=X(c,l),p=X(c,u),d=(X(l,u)-f*p)/i;return{L:i,dL:[f,p],ddL:[[(X(l,l)-f*f)/i+X(c,o.dd),d],[d,(X(u,u)-p*p)/i+X(c,m)]]}}var ER=(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,NP=(e,t)=>e.bump!==null&&t>e.bump||e.droop!==null&&t<e.droop?e.rate:0;function Ls(e,t,r,n,o=0){let a=e.rollStop;if(!a)return r;let s=bf(e,t);if(!s)return r;let i=ER(a,a.length0-(n??s.L+o));return i===0?r:[r[0]-i*s.dL[0],r[1]-i*s.dL[1]]}function Sl(e,t){let r=ff(e.travel);return t==="heave"?{...e,heave:r.heave,heaveRatio:r.heaveRatio}:{...e,roll:r.roll,rollRatio:r.rollRatio}}var Al=(e,t)=>e?e.law?na(e.law,t):e.preload+e.rate*t:0,TR=(e,t)=>e?e.law?ef(e.law,t):e.rate:0;function Ds(e,t,r,n,o){let a=Al(e.heave,n),s=Al(e.roll,o);return[a*t.dh+s*t.dr,a*r.dh-s*r.dr]}var PR=(e,t)=>Ve(e[0],t).h+Ve(e[1],t).h;function OP(e,t){let r=e.gap>0?PR(t,e.gap):0;return e.bothWays?{free:r,pull:e.gap>0?PR(t,-e.gap):0}:{free:r,pull:null}}function VP(e,t,r){let n={...t,outer:t.inner},o=(u,m)=>{let f=ft(ge(e[0],u,0)),p=ft(ge(e[1],m,0));if(!f||!p)return NaN;let d=De(e[0].corner,t,f),h=De(e[1].corner,n,p);return Math.hypot(d[0]-h[0],d[1]+h[1],d[2]-h[2])},a=1,s=o(0,0),i=o(-a,a)-o(a,-a),c=Ve(r[0],a).r-Ve(r[1],-a).r-(Ve(r[0],-a).r-Ve(r[1],a).r),l=i/c;return Number.isFinite(s)&&s>0&&Number.isFinite(l)&&Math.abs(l)>pf?{length0:s,scale:l}:null}function IR(e,t,r,n=Rl){let o=r.heave?Ts(r.heave):void 0,a=FR(e[0],r,o,n),s=e[1].corner===e[0].corner?a:FR(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=r.carriesLoad?void 0:r.heaveSeat,m=u?u.rate:(t[0].heaveRate+t[1].heaveRate)/2,f=(t[0].arbRate+t[1].arbRate)/2,p=i.map(F=>Ve(F,0));c&&!(Math.abs(p[0].dh+p[1].dh)>pf)&&(i=[Sl(i[0],"heave"),Sl(i[1],"heave")],c=!1),l&&!(Math.abs(p[0].dr+p[1].dr)>pf)&&(i=[Sl(i[0],"roll"),Sl(i[1],"roll")],l=!1),p=i.map(F=>Ve(F,0));let d=p[0].dh+p[1].dh,h=p[0].dr+p[1].dr,b=m>0?2*m/(d*d):0,g=f>0?2*f/(h*h):0,y=0,R=0;if(r.carriesLoad){let F=[t[0].springLoad,t[1].springLoad];if(b>0&&g>0){let C=-p[0].dh*p[1].dr-p[1].dh*p[0].dr;Math.abs(C)>1e-12&&(y=(-F[0]*p[1].dr-F[1]*p[0].dr)/C,R=(p[0].dh*F[1]-p[1].dh*F[0])/C)}else b>0?y=(F[0]+F[1])/d:g>0&&(R=(F[0]-F[1])/h)}let k={};if(c&&o){let F=[a.pickups.heave,s.pickups.heave];k.heave={pickups:F,mount:o,span0:Ps(F[0].at0,F[1].at0,o)}}let v=k.heave?k.heave.span0:NaN,x=k.heave?r.coilover:void 0,M=r.carriesLoad?As(b,y,v,x):u?Jd(b,{...OP(u,i),length0:v,coilover:x}):null,A=b>0?{rate:b,preload:y,...M?{law:M}:{}}:null;if(l&&(k.roll={pickups:[a.pickups.roll.pickup,s.pickups.roll.pickup],axes:[a.pickups.roll.axis,s.pickups.roll.axis]},r.roll&&dn(e[0].corner,r.roll,r.rollKind??"coil"))){let F=VP(e,r.roll,i);F&&(k.roll.unit=F)}let w=g>0?{rate:g,preload:R}:null,T={side:i,heave:A,roll:w,force0:[0,0],carriesLoad:r.carriesLoad,read:k},P=k.roll?.unit,S=P&&g>0&&i[0].eyes&&i[1].eyes?ra(P.length0,r.rollCoilover):null;return P&&S&&(S.droop!==null||S.bump!==null)&&(T.rollStop={length0:P.length0,rate:1e3*g/(P.scale*P.scale),...S}),T.force0=Ls(T,[0,0],Ds(T,p[0],p[1],p[0].h+p[1].h,p[0].r-p[1].r)),T}function Es(e,t,r){let n=Ve(e.side[0],t[0]),o=Ve(e.side[1],t[1]),a=r?Ls(e,t,Ds(e,n,o,n.h+o.h+r.heave,n.r-o.r+r.roll),void 0,r.unit):Ls(e,t,Ds(e,n,o,n.h+o.h,n.r-o.r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function gf(e,t,r){let n=Ve(e.side[0],t[0]),o=Ve(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=TR(e.heave,a),c=TR(e.roll,s),l=Al(e.heave,a),u=Al(e.roll,s),m=i*n.dh*o.dh-c*n.dr*o.dr,f=[[i*n.dh*n.dh+l*n.ddh+c*n.dr*n.dr+u*n.ddr,m],[m,i*o.dh*o.dh+l*o.ddh+c*o.dr*o.dr-u*o.ddr]],p=e.rollStop,d=p?bf(e,t):null;if(!p||!d)return f;let h=p.length0-(r?d.L+r.unit:d.L),b=NP(p,h);if(b===0)return f;let g=ER(p,h),y=(k,v)=>b*d.dL[k]*d.dL[v]-g*d.ddL[k][v],R=m+y(0,1);return[[f[0][0]+y(0,0),R],[R,f[1][1]+y(1,1)]]}function yf(e,t,r){let n=gf(e,t);return n[r][0]+n[r][1]}function BP(e,t,r){let n=e.read.heave;if(!n)return Ve(e.side[0],t[0]).h+Ve(e.side[1],t[1]).h;let[o,a]=n.pickups;return n.span0-Ps(De(o.corner,o.link,r[0]),De(a.corner,a.link,r[1]),n.mount)}function $P(e,t,r){let n=e.read.roll;if(!n)return Ve(e.side[0],t[0]).r-Ve(e.side[1],t[1]).r;let o=a=>X(K(De(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function GP(e,t){let r=e.read.roll;if(!e.rollStop||!r)return;let[n,o]=r.pickups;return hf(De(n.corner,n.link,t[0]),De(o.corner,{...o.link,outer:o.link.inner},t[1]))}function Is(e,t,r){let n=Ve(e.side[0],t[0]),o=Ve(e.side[1],t[1]),a=Ls(e,t,Ds(e,n,o,BP(e,t,r),$P(e,t,r)),GP(e,r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function xf(e,t,r,n){let o=Ve(e.side[0],r),a=Ve(e.side[1],r),s=e.read.heave,i=s?.pickups[t],c=s&&i&&n?2*DR(i,s.mount,De(i.corner,i.link,n)):o.h+a.h,l=e.rollStop&&n?e.read.roll?.pickups[t]:void 0,u=l&&n?hf(De(l.corner,l.link,n),De(l.corner,{...l.link,outer:l.link.inner},n)):void 0;return Ls(e,[r,r],Ds(e,o,a,c,n?0:o.r-a.r),u)[t]-e.force0[t]}function Rf(e,t,r,n){let o=oa(e,r[n]);return t?.carriesLoad?o+yf(t,r,n):o}function _R(e,t){return Ve(e.side[0],t[0]).h+Ve(e.side[1],t[1]).h}function NR(e,t){return bf(e,t)?.L??null}var vf=e=>e==="FR"||e==="RR"?1:0,Fl=(e,t)=>e.elements?.[t==="FL"||t==="FR"?"front":"rear"]??null;var OR=e=>Number.isFinite(e)&&e>0?1/e:0;var VR=(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},KP=(e,t)=>[e[0][0]*t[0]+e[0][1]*t[1],e[1][0]*t[0]+e[1][1]*t[1]],BR=1e-8,HP=40;function zP(e,t,r,n){return{force:(s,i)=>{if(r){let u=Es(r,s,n);return[Qt(t[0],s[0])+i[0]+u[0],Qt(t[1],s[1])+i[1]+u[1]]}let c=(s[0]+s[1])/2,l=(s[0]-s[1])/2;return[Qt(t[0],s[0])+i[0]+e[0].heaveRate*c+e[0].arbRate*l,Qt(t[1],s[1])+i[1]+e[1].heaveRate*c-e[1].arbRate*l]},stiffness:(s,i=Cs)=>{if(r){let c=gf(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 sa(e,t,r,n,o,a=[0,0],s=[0,0],i=null,c){let l=[OR(r[0].tyreRate),OR(r[1].tyreRate)],u=[r[0].staticLoad,r[1].staticLoad],m=zP(r,n,i,c),f=C=>m.force(C,a),p=m.stiffness([0,0]),d=[l[0]>0?l[0]:1/Math.max(1,Math.abs(p[0][0])),l[1]>0?l[1]:1/Math.max(1,Math.abs(p[1][1]))],h=(C,L)=>{let E=L===1?f(C):m.force(C,[a[0]*L,a[1]*L]),D=[E[0]+s[0]*L,E[1]+s[1]*L],O=[C[0]+t[0]*L+D[0]*l[0]-e[0]*L,C[1]+t[1]*L+D[1]*l[1]-e[1]*L],_=[d[0]*(u[0]+D[0]),d[1]*(u[1]+D[1])],z=[_[0]<O[0],_[1]<O[1]];return{f:D,on:O,off:_,lifted:z,r:[Math.min(O[0],_[0]),Math.min(O[1],_[1])]}},b=(C,L)=>[L[0]?[d[0]*C[0][0],d[0]*C[0][1]]:[1+C[0][0]*l[0],C[0][1]*l[0]],L[1]?[d[1]*C[1][0],d[1]*C[1][1]]:[C[1][0]*l[1],1+C[1][1]*l[1]]],g=C=>Math.max(Math.abs(C[0]),Math.abs(C[1])),y=(C,L)=>{let E=[C[0],C[1]],D=h(E,L),O=!1,_=0;for(;_<HP;_++){if(g(D.r)<BR){O=!0;break}let z=VR(b(m.stiffness(E),D.lifted),[-D.r[0],-D.r[1]]);if(!z)break;let I=1,N=[E[0]+z[0],E[1]+z[1]],B=h(N,L);for(let V=0;V<8&&g(B.r)>g(D.r);V++)I/=2,N=[E[0]+I*z[0],E[1]+I*z[1]],B=h(N,L);E=N,D=B}return!O&&g(D.r)<BR&&(O=!0),{t:E,b:D,converged:O,it:_}},R=y(o?[o[0],o[1]]:[e[0]-t[0],e[1]-t[1]],1),k=R.it;if(!R.converged){let C=0,L=[0,0],E=.25;for(;C<1&&E>=1/256;){let D=Math.min(1,C+E),O=y(L,D);k+=O.it,O.converged?(C=D,L=O.t,D===1&&(R=O)):E/=2}}let{t:v,b:x,converged:M}=R,A=x.lifted,w=[A[0]?-u[0]:x.f[0],A[1]?-u[1]:x.f[1]],T=[A[0]?Math.max(0,x.on[0]):0,A[1]?Math.max(0,x.on[1]):0],P=m.stiffness(v,oa),S=b(P,A);return{t:v,dF:w,lifted:A,clearance:T,converged:M,iterations:k,respond:(C,L,E=[0,0])=>{let D=[A[0]?-d[0]*E[0]:C[0]-L[0]-E[0]*l[0],A[1]?-d[1]*E[1]:C[1]-L[1]-E[1]*l[1]],O=VR(S,D);if(!O)return[NaN,NaN];let _=KP(P,O);return[A[0]?0:_[0]+E[0],A[1]?0:_[1]+E[1]]}}}var Hn=e=>!(Number.isFinite(e.tyreRate)&&e.tyreRate>0);function zt(e,t,r){return t?.input.corners[r].staticLoadedRadius??e}var kf=["FL","FR","RL","RR"],KR={front:["FL","FR"],rear:["RL","RR"]},YP=512,WP=5e-4,jP=8;function wl(e,t){let r={},n={},o=new Map;for(let s of kf){let i=e.ctx[s],c=t.corners[s],l=c.staticLoadedRadius;n[s]=it(ge(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=`${kf.findIndex(p=>Oe(e.vehicle,p)===Oe(e.vehicle,s))}|${c.springLoad}|${u?`${u.extended}/${u.stroke}`:""}`,f=o.get(m);f?r[s]=f:(r[s]=u?ws(i,c.springLoad,void 0,u):ws(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=KR[s];a[s]=IR([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 HR(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 UP=e=>`${e.heave}|${e.pitch}|${e.roll}|${e.steer}`;function Mf(e,t,r){return{travel:r.travel,steer:r.steer,ground:r.travel,tyreDeflection:0,load:NaN,loadedRadius:zt(Oe(e.vehicle,t).config.loadedRadius,e.kc,t),lifted:!1,contactLength:0,converged:!0,rigid:!0,rideRate:NaN,wheelRateAtLoad:NaN}}var XP=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 $R(e,t,r,n){let o=KR[n],a=e.vehicle.config,s=o.map(w=>pn(w,a,r,e.vehicle)),i=[t.input.corners[o[0]],t.input.corners[o[1]]],c=t.loadCase;if(!c&&i.every(Hn))return{corners:[Mf(e,o[0],s[0]),Mf(e,o[1],s[1])],respond:null};let l=o.map(w=>t.curve[w]),u=t.elements?.[n]??null,m=o.map(w=>zt(Oe(e.vehicle,w).config.loadedRadius,t,w)),f=[s[0].travel+(c?.ground[o[0]]??0),s[1].travel+(c?.ground[o[1]]??0)],p=[c?.linkLoad[o[0]]??0,c?.linkLoad[o[1]]??0],d=[c?.patchShift[o[0]],c?.patchShift[o[1]]],h=[0,0],b=[0,0],g,y=sa(f,h,i,l,void 0,void 0,p,u),R=[void 0,void 0],k=[!0,!0],v=[0,0],x=!1;for(let w=0;w<jP;w++){w>0&&(y=sa(f,h,i,l,g,b,p,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],P=[0,0];for(let F=0;F<2;F++){let C=ge(e.ctx[o[F]],y.t[F],s[F].steer,XP(R[F]),{loadedRadius:m[F]-v[F],patchShift:d[F]}),L=it(C);R[F]=L,k[F]=C.ok,T[F]=L.points.contactPatch[2]-t.ground0[o[F]]-y.t[F]-v[F],P[F]=Lr(l[F],y.t[F],L.points.damperLength)-Qt(l[F],y.t[F])}if(u){let F=Is(u,y.t,[R[0],R[1]]),C=Es(u,y.t);P[0]+=F[0]-C[0],P[1]+=F[1]-C[1]}let S=Math.max(Math.abs(T[0]-h[0]),Math.abs(T[1]-h[1]),Math.abs(P[0]-b[0])/Math.max(1,i[0].tyreRate),Math.abs(P[1]-b[1])/Math.max(1,i[1].tyreRate));if(h=T,b=P,g=y.t,S<WP){x=!0;break}}let M=y.respond([1,1],[0,0]);return{corners:[0,1].map(w=>{let T=R[w];return{travel:y.t[w],steer:s[w].steer,ground:f[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:HR(m[w]-v[w],i[w].staticLoad+y.dF[w],i[w].tyreRate),converged:y.converged&&x&&k[w],rigid:!1,state:T,solved:k[w],rideRate:M[w],wheelRateAtLoad:Rf(l[w],u,y.t,w)}}),respond:y.respond}}function zR(e,t){let r=e.kc,n=UP(t),o=r.memo.get(n);if(o)return o;let a=$R(e,r,t,"front"),s=$R(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>=YP&&r.memo.clear(),r.memo.set(n,i),i}function vt(e,t){if(!e.kc){let r={};for(let n of kf)r[n]=Mf(e,n,pn(n,e.vehicle.config,t,e.vehicle));return r}return zR(e,t).corners}function Cl(e,t,r){return e.kc?zR(e,t).respond[r]:null}function _s(e,t,r,n=0){let o=e.kc;if(!o)return r;let a=o.input.corners[t];if(Hn(a))return r;let s=pn(t,e.vehicle.config,{heave:0,pitch:0,roll:0,steer:n},e.vehicle).steer,i=zt(Oe(e.vehicle,t).config.loadedRadius,o,t),c=o.loadCase,l=c?.linkLoad[t]??0,u=c?.patchShift[t],m=it(ge(e.ctx[t],r,s,void 0,{loadedRadius:i,patchShift:u})),f=Fl(o,t),p=Lr(o.curve[t],r,m.points.damperLength)+(f?xf(f,vf(t),r,m):a.heaveRate*r),h=Math.max(p+l,-a.staticLoad)/a.tyreRate;return(h===0?m:it(ge(e.ctx[t],r,s,void 0,{loadedRadius:i-h,patchShift:u}))).points.contactPatch[2]-o.ground0[t]-(c?.ground[t]??0)}var qP=180/Math.PI,QP=[0,0,1];function ZP(e,t){let r=Pr(e,t),n=U(oe(QP,r),-t.sideSign);return-Math.atan2(n[1],n[0])*qP}var YR=e=>1/Math.tan(e*Math.PI/180),WR=.05,jR=.001;function UR(e,t,r){if(!Number.isFinite(e)||!Number.isFinite(t))return NaN;if(!(Math.abs(e)<jR&&Math.abs(t)<jR))return e>0&&t>0?100*(YR(t)-YR(e))/r:NaN}function JP(e,t){let r=Ht(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=[WR,-WR].map(l=>{let{inner:u,outer:m}=a(t("FL",l).deg-n,t("FR",l).deg-o);return UR(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:f,outer:p}=a(l.deg-n,u.deg-o),d=UR(f,p,r);return{steerL:l.deg,steerR:u.deg,inner:f,outer:p,toeDiff:f-p,ackermannPct:d??i(),inside:d===void 0?null:m?"left":"right",converged:l.ok&&u.ok}}}function Sf(e,t){let r=e.vehicle.config,n={FL:He("FL",r),FR:He("FR",r)},o=t.travel??0,a=JP(e,(i,c)=>{let l=ft(ge(e.ctx[i],o,n[i].sideSign*c));return{deg:l?ZP(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 XR=35,qR=55,kt=e=>e.rackTravel&&e.rackTravel>0?e.rackTravel:XR,Af=e=>e.rackRatio&&e.rackRatio>0?e.rackRatio:qR;var Ff=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 QR(e,t,r,n,o){let a=ge(e,n,0,void 0,o),s=it(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=p=>{let d=[l],h=Ff(s);for(let b=1;b<=r;b++){let g=p*(t*b)/r,y=Ne(e,s.beta,g,h,o),R=ft(ge(e,n,g,Ff(y),o));if(!R||!y.converged){i++,d.push({...d[d.length-1]});continue}d.push({steer:R.metrics.toe,camber:R.metrics.camber,lift:-(y.points.contactPatch[2]-c),contactPatch:y.points.contactPatch,spinAxis:y.points.spinAxis,yaw:-y.metrics.toe*Math.PI/180}),h=Ff(y)}return d},m=u(1),f=u(-1);return{travelMm:n,unsolved:i,centre:l,positive:m,negative:f}}function eL(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=U(K(e[a].contactPatch,e[o].contactPatch),1/s),c=q(oe(r.spinAxis,[0,0,1])),l=oe([0,0,1],c);return{longitudinal:X(i,c),lateral:X(i,l),vertical:i[2],yaw:(e[a].yaw-e[o].yaw)/s}})}function ZR(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:eL(o,t)});return{travelMm:e.travelMm,inner:n(r?e.positive:e.negative),outer:n(r?e.negative:e.positive)}}function tL(e){return e.positive[1].steer-e.centre.steer<0}function rL(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:Af(e.config),innerJacobian:r.inner.jacobian,outerJacobian:r.outer.jacobian}}function wf(e,t,r=13,n=-40,o=40,a=5,s){let i=rt(e),c=Array.from({length:r+1},(b,g)=>t*g/r),l=QR(i,t,r,0,s),u=tL(l),m=ZR(l,c,u),f=Math.max(2,Math.floor(a)),p=Array.from({length:f},(b,g)=>n+(o-n)*g/(f-1));p.some(b=>Math.abs(b)<1e-9)||p.push(0),p.sort((b,g)=>b-g);let d=l.unsolved,h=p.map(b=>{if(Math.abs(b)<1e-9)return m;let g=QR(i,t,r,b,s);return d+=g.unsolved,ZR(g,c,u)});return{...rL(e,c,m),...JR(l.unsolved),travelSurface:{rackMm:c,rows:h,...JR(d)}}}var JR=e=>e>0?{unsolved:e}:{};function ur(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 Tl(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 ev(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 zn=(e,t,r)=>e+r*(t-e);function ia(e,t,r,n,o){let a=ur(e.rackMm,e.rows[n.lo][t][r],o);if(n.lo===n.hi)return a;let s=ur(e.rackMm,e.rows[n.hi][t][r],o);return zn(a,s,n.t)}function tv(e,t,r,n){let o=Tl(e.rackMm,e.rows[r.lo][t].jacobian,n);if(r.lo===r.hi)return o;let a=Tl(e.rackMm,e.rows[r.hi][t].jacobian,n);return{longitudinal:zn(o.longitudinal,a.longitudinal,r.t),lateral:zn(o.lateral,a.lateral,r.t),vertical:zn(o.vertical,a.vertical,r.t),yaw:zn(o.yaw,a.yaw,r.t)}}function ca(e,t,r,n){let o=e.travelSurface;if(!o||o.rackMm.length<2||o.rows.length===0)return la(e,t);let a=ev(o,r),s=ev(o,n),i=(p,d,h)=>{let b=o.rows[d.lo][p].steerDeg[h];return d.lo===d.hi?b:zn(b,o.rows[d.hi][p].steerDeg[h],d.t)},c=new Array(o.rackMm.length);for(let p=0;p<c.length;p++)c[p]=.5*(i("inner",a,p)+i("outer",s,p));let l=Math.max(0,t),u=c.length-1,m=o.rackMm[u],f=l>c[u];if(l<=c[0])m=o.rackMm[0],f=!1;else if(!f){let p=1;for(;p<c.length-1&&c[p]<l;)p++;let d=p-1,h=c[p]-c[d],b=Math.abs(h)>1e-12?(l-c[d])/h:0;m=zn(o.rackMm[d],o.rackMm[p],b)}return{innerDeg:ia(o,"inner","steerDeg",a,m),outerDeg:ia(o,"outer","steerDeg",s,m),innerCamber:ia(o,"inner","camberDeg",a,m),outerCamber:ia(o,"outer","camberDeg",s,m),innerLift:ia(o,"inner","liftMm",a,m),outerLift:ia(o,"outer","liftMm",s,m),innerJacobian:tv(o,"inner",a,m),outerJacobian:tv(o,"outer",s,m),atLock:f}}function la(e,t){let r=e.meanDeg.length-1;return{innerDeg:ur(e.meanDeg,e.innerDeg,t),outerDeg:ur(e.meanDeg,e.outerDeg,t),innerCamber:ur(e.meanDeg,e.innerCamber,t),outerCamber:ur(e.meanDeg,e.outerCamber,t),innerLift:e.innerLift?ur(e.meanDeg,e.innerLift,t):0,outerLift:e.outerLift?ur(e.meanDeg,e.outerLift,t):0,...e.innerJacobian&&e.outerJacobian?{innerJacobian:Tl(e.meanDeg,e.innerJacobian,t),outerJacobian:Tl(e.meanDeg,e.outerJacobian,t)}:{},atLock:r>=0&&t>e.meanDeg[r]}}var nL=()=>({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 ua(e,t,r=Ce(e),n){let o=e.steerFront;if(!o?.innerLift||!o.outerLift||o.meanDeg.length<2||Math.abs(t)<1e-12)return nL();let a=Math.abs(t),s=t>0,i=n&&o.travelSurface?ca(o,a,s?n.FL:n.FR,s?n.FR:n.FL):null,c=i?.innerLift??ur(o.meanDeg,o.innerLift,a),l=i?.outerLift??ur(o.meanDeg,o.outerLift,a),u=s?c:l,m=s?l:c,f=.5*(u+m),p=r.rollWheelRateFront,d=r.rollWheelRateRear,h=e.trackFront,b=e.trackRear,g=p*h*h+d*b*b,y=g>0?p*h*(m-u)/g:0,R={FL:u-f+.5*h*y,FR:m-f-.5*h*y,RL:.5*b*y,RR:-.5*b*y};return{lift:{FL:u,FR:m,RL:0,RR:0},travel:R,load:{FL:p*R.FL,FR:p*R.FR,RL:d*R.RL,RR:d*R.RR},rollDeg:y===0?0:-Math.atan(y)*180/Math.PI}}function Cf(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 Ns=9.81;function ma(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?Tr(e,t,r,cn(e,n,o)):$n(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 Tf(e,t,r=0,n=0,o=0){if(!e.aero?.model||t<=0)return!1;let a=Tr(e,t,r,cn(e,n,o));return a!=null&&(a.clampedRide||a.clampedAttitude)}function Yn(e){let t=e.loadFactor===void 0?e.massTotal*Ns:e.massTotal*Ns*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 rv(e,t=Ce(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*il(t.sprungMass,c,t.rollRateTotal),f=(m*t.frontRollStiffFrac+t.sprungFront*a+l*u)/n,p=(m*(1-t.frontRollStiffFrac)+t.sprungRear*s+l*u)/o;return{cf:f,cr:p}}function Pf(e){let{cf:t,cr:r}=rv(e);return t+r>0?t/(t+r):.5}function nv(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 f=u>0?1:-1,p=(f*a-c)*t;f*u>=f*p?(c=f*a,u-=p):(c+=u/t,u=0);let d=(f*s-l)*r;u!==0&&(f*u>=f*d?(l=f*s,u-=d):(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 Te(e,t,r,n=0,o=0,a=0,s,i){return Pl(e,t,r,n,o,a,s,i).loads}function Pl(e,t,r,n=0,o=0,a=0,s,i){let c=Yn(e),l=Ce(e),u=hl(e,n,r,cn(e,t,o),l),{cf:m,cr:f}=rv(e,l,u.height),p=m*t*Ns,d=f*t*Ns,h=e.massTotal*(r*Ns)*u.height/e.wheelbase-u.noseLoad,b=ma(e,n,r,t,o),g=(i??ua(e,a,l,s)).load,y={FL:c.FL-p-h/2+b.FL+g.FL,FR:c.FR+p-h/2+b.FR+g.FR,RL:c.RL-d+h/2+b.RL+g.RL,RR:c.RR+d+h/2+b.RR+g.RR};return nv(y,e.trackFront,e.trackRear)}var Lf=Math.PI/180;function Dl(e,t){let r=8*Lf,n=0,o=0;for(let a=1;a<=90;a++){let s=a*.5,i=Math.abs(e.Fy(s*Lf,t,0));if(i>n&&(n=i,r=s*Lf,o=a),a>o+12&&i<.995*n)break}return{aPeak:r,fyPeak:n}}function ov(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 Vs=.999;function Lt(e,t,r,n,o){if(t<=0)return 0;let{aPeak:a,fyPeak:s}=o??Dl(e,t),i=Math.min(Math.abs(r),Vs*s),c=n?-1:1,l=(v,x)=>Math.abs(e.forces({Fz:t,kappa:c*v,alpha:x}).Fy),u=.3,m=u,f=l(u,a);if(f<i){let v=0,x=u,M=NaN,A=f;for(let w=0;w<9;w++){let T=.5*(v+x),P=l(T,a);P>=i?(v=T,M=P):(x=T,A=P)}Number.isNaN(M)&&(M=l(0,a)),m=M<i?0:ov(v,M,x,A,i)}if(m<=0)return 0;let p=v=>{if(i===0)return c*e.forces({Fz:t,kappa:c*v,alpha:0}).Fx;let x=0,M=a,A=NaN,w=NaN;for(let T=0;T<5;T++){let P=.5*(x+M),S=l(v,P);S<i?(x=P,A=S):(M=P,w=S)}return Number.isNaN(A)&&(A=l(v,0)),Number.isNaN(w)&&(w=l(v,a)),c*e.forces({Fz:t,kappa:c*v,alpha:ov(x,A,M,w,i)}).Fx},d=4,h=v=>m*v/d,b=[0],g=1;for(let v=1;v<=d;v++)b.push(p(h(v))),b[v]>b[g]&&(g=v);let[y,R]=g===d?[d-1,d-2]:b[g-1]>=b[g+1]?[g-1,g+1]:[g+1,g-1],k=iL(p,h(g-1),h(Math.min(d,g+1)),h(g),b[g],h(y),b[y],h(R),b[R],oL);return c*Math.max(0,k)}var oL=.01,aL=20,sL=(3-Math.sqrt(5))/2;function iL(e,t,r,n,o,a,s,i,c,l){o=-o,s=-s,c=-c;let u=r-t,m=0;for(let f=0;f<aL;f++){let p=l*Math.abs(n)+1e-10,d=.5*(t+r);if(Math.abs(n-d)<=2*p-.5*(r-t))break;let h=!0;if(Math.abs(u)>p){let y=(n-a)*(o-c),R=(n-i)*(o-s),k=(n-i)*R-(n-a)*y;R=2*(R-y),R>0&&(k=-k),R=Math.abs(R);let v=u;if(u=m,Math.abs(k)<Math.abs(.5*R*v)&&k>R*(t-n)&&k<R*(r-n)){m=k/R;let x=n+m;(x-t<2*p||r-x<2*p)&&(m=d>=n?p:-p),h=!1}}h&&(u=n>=d?t-n:r-n,m=sL*u);let b=Math.abs(m)>=p?n+m:n+(m>=0?p:-p),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 If(e,t){return e.model?.kind==="simple"?null:iv(e,t)}var av=new WeakMap,Df=100,sv=1.35,Ef=18,mr=41,Ll=41,Os=65;function iv(e,t){let r=av.get(e);if(r)return r;let n=Math.log(sv),o=(p,d)=>{let h=M=>Math.abs(Lt(e,p,M,d)),b=h(0),g=t.muY(p)*p,y=new Float64Array(mr),R=b>0&&g>0?Math.max(1,t.muX(p)*p/b):1;if(!(b>0)||!(g>0))y.fill(1);else{let M=[],A=[];for(let T=0;T<Ll;T++){let P=Math.sin(.5*Math.PI*T/(Ll-1));M.push(P),A.push(T===0?1:T===Ll-1?0:Math.min(A[T-1],h(P*g)/b))}let w=Ll-1;for(let T=0;T<mr;T++){let P=T/(mr-1);for(;w>0&&A[w-1]<P;)w--;let S=w>0?A[w-1]-A[w]:0;y[T]=w===0?M[0]:M[w]+(S>0?(P-A[w])/S:0)*(M[w-1]-M[w])}y[0]=1,y[mr-1]=0}let k=new Float64Array(Os),v=M=>Math.atan2(y[M],M/(mr-1)/R),x=mr-2;for(let M=0;M<Os;M++){let A=.5*Math.PI*M/(Os-1),w=Math.cos(A),T=Math.sin(A);for(;x>0&&v(x)<A;)x--;let P=x/(mr-1)/R,S=y[x],F=(x+1)/(mr-1)/R,C=y[x+1],L=w*(C-S)-T*(F-P),E=Math.abs(L)>1e-12?(P*(C-S)-S*(F-P))/L:Math.hypot(P,S);k[M]=E>0?E:Math.hypot(P,S)}return{room:y,scale:R,edge:k}},a=Array.from({length:Ef},(p,d)=>Df*sv**d),s=a.map(p=>o(p,!1)),i=a.map(p=>o(p,!0)),c=(p,d)=>{let h=Math.min(1,Math.abs(d)*p.scale)*(mr-1),b=Math.min(mr-2,Math.floor(h));return p.room[b]+(h-b)*(p.room[b+1]-p.room[b])},l=p=>{let d=p>Df?Math.log(p/Df)/n:0;if(d>=Ef-1)return[Ef-2,1];let h=Math.floor(d);return[h,d-h]},u=(p,d,h)=>{if(h===0)return 1;let b=h<0?i:s,g=c(b[p],h);return d>0?g+d*(c(b[p+1],h)-g):g},m=(p,d,h)=>{let b=d<0?i:s,[g,y]=l(p),R=Math.atan2(Math.abs(h),Math.abs(d))/(.5*Math.PI)*(Os-1),k=Math.min(Os-2,Math.floor(R)),v=M=>M.edge[k]+(R-k)*(M.edge[k+1]-M.edge[k]),x=v(b[g]);return y>0?x+y*(v(b[g+1])-x):x},f={keeps(p,d){if(d===0)return 1;let[h,b]=l(p);return u(h,b,d)},atLoad(p){let[d,h]=l(p);return b=>u(d,h,b)},use(p,d,h){let b=Math.hypot(d,h);return b>0?Math.min(1,b/m(p,d,h)):0},reach:m};return av.set(e,f),f}var cL=[["front","FL","FR"],["rear","RL","RR"]];function pa(e,t,r,n){let o={...e},a=0,s=Vs;for(let[i,c,l]of cL){let u=(k,v)=>n(i,Math.max(0,v[k])).fyPeak,m=Math.min(s,e[c]),f=Math.min(s,e[l]),p=m*u(c,r)+f*u(l,r);if(!(p>0))continue;let d=u(c,t),h=u(l,t),b=m*d+f*h,g=b>0?p/b:1/0,y=m*g,R=f*g;y<=s?R<=s||(R=s,y=d>0?(p-s*h)/d:1/0):(y=s,R=h>0?(p-s*d)/h:1/0),(!(y<=s)||!(R<=s))&&(a+=Math.max(0,p-s*(d+h)),y=Math.min(s,y),R=Math.min(s,R)),o[c]=y,o[l]=R}return{util:o,short:a}}var cv=.001,lL=1e-5,lv=100;function uL(e,t,r,n){if(!(n>cv))return r;let o=t,a=Math.abs(r-t)<lv?t+Math.sign(r-t)*lv:r;for(let s=0;s<60&&Math.abs(a-o)>lL;s++){let i=.5*(o+a);e(i)>cv?a=i:o=i}return o}function El(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=uL(e,t,o,e(o));return a!==o&&(n=a),a},edge:()=>n}}function Il(e,t){let r=n=>{try{return ge(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 _f=40;function _l(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 uv=[0,0,0];function mL(e,t){let r=q(K(e.rockerPivotB,e.rockerPivotA)),n=q(K(e.rockerToPushrod,e.pushrodOuter)),o=q(K(e.damperChassis,e.rockerToDamper)),a=Math.abs(X(r,oe(K(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(X(r,oe(K(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}function Nl(e,t,r){if(e.mcpherson)return pL(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 f=q(K(n[m].c,n[m].r)),p=oe(K(n[m].r,o),f);a[0][m]=f[0],a[1][m]=f[1],a[2][m]=f[2],a[3][m]=p[0],a[4][m]=p[1],a[5][m]=p[2]}let s=oe(K(e.contactPatch,o),t),i=r??uv,c=[-t[0],-t[1],-t[2],-(s[0]+i[0]),-(s[1]+i[1]),-(s[2]+i[2])],l=ir(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]:mL(e,u[5]),condProxy:l.condProxy,singular:l.singular}}function pL(e,t,r){let n=e.wheelCenter,o=e.damperChassis,a=[{at:e.uprightLower,dir:q(K(e.lcaFront,e.uprightLower))},{at:e.uprightLower,dir:q(K(e.lcaRear,e.uprightLower))},{at:e.tieOuter,dir:q(K(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=oe(K(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=oe(K(e.contactPatch,n),t),c=r??uv,l=[-t[0],-t[1],-t[2],-(i[0]+c[0]),-(i[1]+c[1]),-(i[2]+c[2])],u=ir(s,l),m=u.x,f=[m[3],m[4],m[5]],p=q(K(o,e.pushrodOuter)),d=X(f,p),h=Math.hypot(f[0]-d*p[0],f[1]-d*p[1],f[2]-d*p[2]);return{ucaFront:NaN,ucaRear:NaN,lcaFront:m[0],lcaRear:m[1],tieRod:m[2],pushRod:u.singular?NaN:d,damper:u.singular?NaN:d,condProxy:u.condProxy,singular:u.singular,strutSide:u.singular?NaN:h,topMount:f}}function Nf(e,t){let r=q(e.spinAxis),n=oe(K(e.contactPatch,e.wheelCenter),t),o=X(n,r);return[-o*r[0],-o*r[1],-o*r[2]]}var dL=[0,0,0];function Bs(e,t,r,n){let o=e.direct?e.damperChassis:e.rockerToPushrod;if(e.mcpherson)return{...Nl(e,r,n),armResidual:0};if(t==="upright")return{...Nl(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=q(K(s.front,s.bj)),u=q(K(s.rear,s.bj)),m=q(K(e.tieInner,e.tieOuter)),f=[{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]}],p=[[],[],[],[],[],[]];for(let j=0;j<6;j++){let ee=f[j].dir,ne=oe(K(f[j].at,c),ee);p[0][j]=ee[0],p[1][j]=ee[1],p[2][j]=ee[2],p[3][j]=ne[0],p[4][j]=ne[1],p[5][j]=ne[2]}let d=oe(K(e.contactPatch,c),r),h=n??dL,b=[-r[0],-r[1],-r[2],-(d[0]+h[0]),-(d[1]+h[1]),-(d[2]+h[2])],g=ir(p,b),y=g.singular,R=g.x,k=R[0],v=R[1],x=R[2],M=[R[3],R[4],R[5]],A=q(K(i.rear,i.front)),w=q(K(o,e.pushrodOuter)),T=U(M,-1),P=(j,ee)=>X(A,oe(K(j,i.front),ee)),S=P(e.pushrodOuter,w),F=Math.abs(S)>1e-9?-P(i.bj,T)/S:NaN,C=te(T,U(w,F)),L=U(C,-1),E=q(K(i.front,i.bj)),D=q(K(i.rear,i.bj)),O=X(E,E),_=X(E,D),z=X(D,D),I=X(E,L),N=X(D,L),B=O*z-_*_,V=NaN,G=NaN,H=NaN;if(Math.abs(B)>1e-12){V=(I*z-N*_)/B,G=(O*N-_*I)/B;let j=te(U(E,V),U(D,G)),ee=K(L,j);H=Math.hypot(ee[0],ee[1],ee[2])}let Y=a?{f:k,r:v}:{f:V,r:G},J=a?{f:V,r:G}:{f:k,r:v};return{ucaFront:Y.f,ucaRear:Y.r,lcaFront:J.f,lcaRear:J.r,tieRod:x,pushRod:F,damper:y||!Number.isFinite(F)||e.decoupled?NaN:e.direct?F:fL(e,F),condProxy:g.condProxy,singular:y,armResidual:H}}function fL(e,t){let r=q(K(e.rockerPivotB,e.rockerPivotA)),n=q(K(e.rockerToPushrod,e.pushrodOuter)),o=q(K(e.damperChassis,e.rockerToDamper)),a=Math.abs(X(r,oe(K(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(X(r,oe(K(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}var lH=Math.PI/180;function $s(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 pv=["QSX3","QSX8","QSX13","QSX14"],hL=["QSX1"],Ol=["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",...pv];function bL(e){let t=["PKY6","PKY7","PVY3","PVY4","PHY3","PEY4","RVY3","QHZ3","QHZ4","QEZ5","QDZ8","QDZ9","QDZ10","QDZ11","SSZ3","SSZ4"];return e==="5.2"?[...t,"QBZ4","QDZ3"]:t}function gL(e){let t=new Set(bL(e)),r=Ol.filter(n=>!pv.includes(n));return[...r.filter(n=>!t.has(n)),...[...t].filter(n=>!r.includes(n)),...hL]}function yL(e,t){let r={...e};for(let n of t)r[n]!==void 0&&r[n]!==0&&(r[n]=-r[n]);return r}var Dr=(e,t,r)=>Number.isFinite(e[t])?e[t]:r;function dv(e,t){return t!=="5.2"?Dr(e,"PKY6",0)*Dr(e,"LKYC",1):Dr(e,"PKY1",-15)*Math.sin(Dr(e,"PKY4",2)*Math.atan(1/Dr(e,"PKY2",2)))*Dr(e,"LKY",1)*Dr(e,"PHY3",0)+Dr(e,"PVY3",0)*Dr(e,"LMUY",1)}var mv=.1;function fv(e){if(e.fitData)return"sae";let t=dv(e.coeffs,e.version);return t>mv?"sae":t<-mv?"iso":null}function Gs(e){return e.axisSystem??fv(e)??"sae"}function Vl(e){let t=new Set,r=n=>{for(let o of n)t.has(o)?t.delete(o):t.add(o)};return Gs(e)==="iso"&&r(Ol),e.axisSystem&&e.side==="left"&&r(gL(e.version)),t.size?yL(e.coeffs,t):e.coeffs}var mH=Math.PI/180;var $=(e,t)=>Number.isFinite(e)?e:t;function bv(e){let t=Vl(e);return{PCX1:$(t.PCX1,1.65),PDX1:$(t.PDX1,1),PDX2:$(t.PDX2,0),PDX3:$(t.PDX3,0),PEX1:$(t.PEX1,0),PEX2:$(t.PEX2,0),PEX3:$(t.PEX3,0),PEX4:$(t.PEX4,0),PHX1:$(t.PHX1,0),PHX2:$(t.PHX2,0),PKX1:$(t.PKX1,20),PKX2:$(t.PKX2,0),PKX3:$(t.PKX3,0),PPX1:$(t.PPX1,0),PPX2:$(t.PPX2,0),PPX3:$(t.PPX3,0),PPX4:$(t.PPX4,0),PVX1:$(t.PVX1,0),PVX2:$(t.PVX2,0),PCY1:$(t.PCY1,1.3),PDY1:$(t.PDY1,1),PDY2:$(t.PDY2,0),PDY3:$(t.PDY3,0),PEY1:$(t.PEY1,0),PEY2:$(t.PEY2,0),PEY3:$(t.PEY3,0),PEY4:$(t.PEY4,0),PEY5:$(t.PEY5,0),PHY1:$(t.PHY1,0),PHY2:$(t.PHY2,0),PHY3:$(t.PHY3,0),PKY1:$(t.PKY1,-15),PKY2:$(t.PKY2,2),PKY3:$(t.PKY3,0),PKY4:$(t.PKY4,2),PKY5:$(t.PKY5,0),PKY6:$(t.PKY6,0),PKY7:$(t.PKY7,0),PPY1:$(t.PPY1,0),PPY2:$(t.PPY2,0),PPY3:$(t.PPY3,0),PPY4:$(t.PPY4,0),PPY5:$(t.PPY5,0),PVY1:$(t.PVY1,0),PVY2:$(t.PVY2,0),PVY3:$(t.PVY3,0),PVY4:$(t.PVY4,0),RBX1:$(t.RBX1,0),RBX2:$(t.RBX2,0),RBX3:$(t.RBX3,0),RBY1:$(t.RBY1,0),RBY2:$(t.RBY2,0),RBY3:$(t.RBY3,0),RBY4:$(t.RBY4,0),RCX1:$(t.RCX1,1),RCY1:$(t.RCY1,1),REX1:$(t.REX1,0),REX2:$(t.REX2,0),REY1:$(t.REY1,0),REY2:$(t.REY2,0),RHX1:$(t.RHX1,0),RHY1:$(t.RHY1,0),RHY2:$(t.RHY2,0),RVY1:$(t.RVY1,0),RVY2:$(t.RVY2,0),RVY3:$(t.RVY3,0),RVY4:$(t.RVY4,0),RVY5:$(t.RVY5,1),RVY6:$(t.RVY6,0),PPZ1:$(t.PPZ1,0),PPZ2:$(t.PPZ2,0),QBZ1:$(t.QBZ1,8),QBZ2:$(t.QBZ2,0),QBZ3:$(t.QBZ3,0),QBZ4:$(t.QBZ4,0),QBZ5:$(t.QBZ5,0),QBZ6:$(t.QBZ6,0),QBZ9:$(t.QBZ9,0),QBZ10:$(t.QBZ10,0),QCZ1:$(t.QCZ1,1.1),QDZ1:$(t.QDZ1,.1),QDZ2:$(t.QDZ2,0),QDZ3:$(t.QDZ3,0),QDZ4:$(t.QDZ4,0),QDZ6:$(t.QDZ6,0),QDZ7:$(t.QDZ7,0),QDZ8:$(t.QDZ8,0),QDZ9:$(t.QDZ9,0),QDZ10:$(t.QDZ10,0),QDZ11:$(t.QDZ11,0),QEZ1:$(t.QEZ1,0),QEZ2:$(t.QEZ2,0),QEZ3:$(t.QEZ3,0),QEZ4:$(t.QEZ4,0),QEZ5:$(t.QEZ5,0),QHZ1:$(t.QHZ1,0),QHZ2:$(t.QHZ2,0),QHZ3:$(t.QHZ3,0),QHZ4:$(t.QHZ4,0),SSZ1:$(t.SSZ1,0),SSZ2:$(t.SSZ2,0),SSZ3:$(t.SSZ3,0),SSZ4:$(t.SSZ4,0),QSX1:$(t.QSX1,0),QSX2:$(t.QSX2,0),QSX3:$(t.QSX3,0),QSX4:$(t.QSX4,0),QSX5:$(t.QSX5,0),QSX6:$(t.QSX6,0),QSX7:$(t.QSX7,0),QSX8:$(t.QSX8,0),QSX9:$(t.QSX9,0),QSX10:$(t.QSX10,0),QSX11:$(t.QSX11,0),QSX12:$(t.QSX12,0),QSX13:$(t.QSX13,0),QSX14:$(t.QSX14,0),PPMX1:$(t.PPMX1,0),QSY1:$(t.QSY1,0),QSY2:$(t.QSY2,0),QSY3:$(t.QSY3,0),QSY4:$(t.QSY4,0),QSY5:$(t.QSY5,0),QSY6:$(t.QSY6,0),QSY7:$(t.QSY7,0),QSY8:$(t.QSY8,0),LONGVL:t.LONGVL!==void 0&&t.LONGVL>0?t.LONGVL:16.7,LCX:$(t.LCX,1),LCY:$(t.LCY,1),LEX:$(t.LEX,1),LEY:$(t.LEY,1),LFZO:$(t.LFZO,1),LHX:$(t.LHX,1),LHY:$(t.LHY,1),LKX:$(t.LKX,1),LKY:$(t.LKY,1),LKYC:$(t.LKYC,1),LKZC:$(t.LKZC,1),LMUX:$(t.LMUX,1),LMUY:$(t.LMUY,1),LMX:$(t.LMX,1),LMY:$(t.LMY,1),LVMX:$(t.LVMX,1),LRES:$(t.LRES,1),LS:$(t.LS,1),LTR:$(t.LTR,1),LVX:$(t.LVX,1),LVY:$(t.LVY,1),LVYKA:$(t.LVYKA,1),LXAL:$(t.LXAL,1),LYKA:$(t.LYKA,1)}}var hv=new WeakMap;function Ks(e){let t=hv.get(e);return t===void 0&&(t=bv(e),hv.set(e,t)),t}var gv=e=>e>=0?1:-1;function Bl(e,t,r=0,n){let o=Ks(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,f=o.PCY1*o.LCY,p=m*a,d=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(d)>1e-6?d:1e-6*(d<0?-1:1),R=h?(o.PHY1+o.PHY2*c)*o.LHY+(b*s-g)/y:(o.PHY1+o.PHY2*c)*o.LHY+o.PHY3*s,k=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=f*p!==0?d/(f*p):0;return{Fz:a,g:s,dfz:c,dpi:l,Fz0p:i,R0:u,Cy:f,Dy:p,By:v,SHy:R,SVy:k,Kya:d,muy:m,EyA:o.PEY1+o.PEY2*c,EyG:1+o.PEY5*s*s,EyS:o.PEY3+o.PEY4*s,LEY:o.LEY}}function $l(e,t,r=0,n){let o=Bl(e,t,r,n),a=Ks(e),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,muy:f,Kya:p,SVy:d,By:h,Cy:b,Dy:g,SHy:y}=o,R=(a.PHX1+a.PHX2*c)*a.LHX,k=(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,x=k*s,M=s*(a.PKX1+a.PKX2*c)*Math.exp(a.PKX3*c)*(1+a.PPX1*l+a.PPX2*l*l)*a.LKX,A=v*x!==0?M/(v*x):0,w=Math.abs(p)>1e-6?p:1e-6*(p<0?-1:1),T=e.version!=="5.2",P=s*(a.PVX1+a.PVX2*c)*a.LVX*a.LMUX,S=a.REX1+a.REX2*c;S>1&&(S=1);let F=a.REY1+a.REY2*c;return F>1&&(F=1),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,Cy:b,Dy:g,By:h,SHy:y,SVy:d,Kya:p,muy:f,EyA:o.EyA,EyG:o.EyG,EyS:o.EyS,LEY:o.LEY,SHx:R,Cx:v,Dx:x,Bx:A,SVx:P,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:S,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:F,DVykA:f*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:T?(a.QBZ1+a.QBZ2*c+a.QBZ3*c*c)*(1+a.QBZ5*Math.abs(i)+a.QBZ6*i*i)*(a.LKY/a.LMUY):(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:T?s*(m/u)*(a.QDZ1+a.QDZ2*c)*(1-a.PPZ1*l)*(1+a.QDZ3*Math.abs(i)+a.QDZ4*i*i)*a.LTR: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:p!==0?d/p:0,sixOne:T,kk:M/w*(M/w),sS0:m*(a.SSZ1+(a.SSZ3+a.SSZ4*c)*i)*a.LS,sS2:m*a.SSZ2*a.LS/u}}function Hs(e,t){let r=t+e.SHy,n=e.EyA*(e.EyG-e.EyS*gv(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 Gl(e,t){let r=t+e.SHx,n=e.ExA*(1-e.PEX4*gv(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 yv(e,t,r){if(r===0)return t;if(e.sixOne)return Math.sqrt(t*t+e.kk*r*r)*Math.sign(t);let n=Math.tan(t);return Math.atan(Math.sqrt(n*n+e.kk*r*r))*Math.sign(t)}function xL(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=yv(e,o,r),i=e.Bt*s;return e.Dt*Math.cos(e.Ct*Math.atan(i-a*(i-Math.atan(i))))*n}function RL(e,t,r,n){return e.Dr*Math.cos(Math.atan(e.Br*yv(e,t+e.SHy+e.arOff,r)))*n}function xv(e,t,r,n,o,a){let s=Math.cos(t),i=xL(e,t,r,s),c=RL(e,t,r,s);return-i*(o-a)+c+(e.sS0+e.sS2*o)*n}function Rv(e,t,r){let n=e.Bxa0*Math.cos(Math.atan(e.RBX2*t))*e.LXAL,o=r+e.SHxa,a=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*Gl(e,t)}function Of(e,t){let r=e.sS0===0&&e.sS2===0?0:Rv(e,0,t);return xv(e,t,0,r,Hs(e,t),0)}function Kl(e,t,r){let n=Hs(e,r),o=Rv(e,t,r),a=e.Byk0*Math.cos(Math.atan(e.RBY2*(r-e.RBY3)))*e.LYKA,s=t+e.SHyk,i=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:xv(e,r,t,o,m,u)}}var zs=(e,t)=>Math.max(.1,e.muY0+e.loadSensY*(t-e.nominalLoad)),Ys=(e,t)=>Math.max(.1,e.muX0+e.loadSensX*(t-e.nominalLoad)),vv=(e,t,r)=>zs(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cy*Math.atan(e.By*r)),kv=(e,t,r)=>Ys(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cx*Math.atan(e.Bx*r));function Vf(e,t){let r=Math.max(1,t.Fz),n=zs(e,r)*r,o=Ys(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 da=Math.PI/180;function fn(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 Mv(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?$s(r,t):1,s=n?$s(n,t):1,i=o?$s(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 fa(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}function Pe(e){let t=Mv(e),r=t,n=t,o=null,a=NaN,s=NaN,i=NaN,c=(v,x,M)=>(o!==null&&v===a&&x===s&&M===i||(o=$l(r,v,x,M),a=v,s=x,i=M),o),l=null,u=NaN,m=NaN,f=NaN,p=(v,x,M)=>(l!==null&&v===u&&x===m&&M===f||(l=Bl(r,v,x,M),u=v,m=x,f=M),l),d=v=>e.kind==="magic"?Kl(c(v.Fz,v.gamma??0,v.p),v.kappa,v.alpha):Vf(n,v),h=(v,x,M=0,A)=>e.kind==="magic"?Hs(p(x,M,A),v):vv(n,x,v),b=(v,x,M=0,A)=>e.kind==="magic"?Gl(c(x,M,A),v):kv(n,x,v),g=(v,x,M=0,A)=>e.kind==="magic"?Of(c(x,M,A),v):d({Fz:x,kappa:0,alpha:v,gamma:M,p:A}).Mz,y=v=>e.kind==="simple"?zs(n,v):fa(x=>h(x*da,v),45,1)/Math.max(1,v),R=v=>e.kind==="simple"?Ys(n,v):fa(x=>b(x,v),.6,.02)/Math.max(1,v),k=v=>{let x=.1*da;return Math.abs((h(x,v)-h(-x,v))/(2*x))};return{model:e,forces:d,Fx:b,Fy:h,Mz:g,muX:R,muY:y,corneringStiffness:k,verticalStiffness:()=>e.verticalStiffness,rollingRadius:v=>{if(e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS"))return 0;let x=e.unloadedR0??0;if(!(x>0))return 0;let M=e.verticalStiffness*1e3;if(!(M>0))return x;let A=e.rollingFraction??.306;return x-A*Math.max(0,v)/M},relaxationLength:v=>{let x=e.relaxation;if(!x)return 0;let M=x.carcassStiffness??0;if(!(M>0))return x.sigma;let A=k(Math.max(0,v));return A>0?A/(M*1e3):x.sigma}}}function ha(e){let t=Math.max(1,e.model.kind==="magic"?e.model.fnomin:e.model.nominalLoad);return e.Fy(2*da,t,0)-e.Fy(-2*da,t,0)>=0?1:-1}function Ws(e,t=e.kind==="magic"?e.fnomin:e.nominalLoad){let r=Pe(e),n=2*da,o=3*da,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 vL=Math.PI/180;function ye(e,t){return e.axle?e.axle(t):e}function zl(e,t){if(e===t)return e;let r=ha(e)*ha(t),n=(l,u)=>.5*(l+u),o=(l,u)=>l>0&&u>0?n(l,u):l>0?l:u>0?u:0,a=l=>{let u=e.forces(l),m=t.forces(l);return{Fx:n(u.Fx,m.Fx),Fy:n(u.Fy,r*m.Fy),Mz:n(u.Mz,r*m.Mz)}},s=(l,u,m=0,f)=>n(e.Fx(l,u,m,f),t.Fx(l,u,m,f)),i=(l,u,m=0,f)=>n(e.Fy(l,u,m,f),r*t.Fy(l,u,m,f)),c=(l,u,m=0,f)=>n(e.Mz(l,u,m,f),r*t.Mz(l,u,m,f));return{model:e.model,forces:a,Fx:s,Fy:i,Mz:c,muX:l=>fa(u=>s(u,l),.6,.02)/Math.max(1,l),muY:l=>fa(u=>i(u*vL,l),45,1)/Math.max(1,l),corneringStiffness:l=>n(e.corneringStiffness(l),t.corneringStiffness(l)),verticalStiffness:()=>o(e.verticalStiffness(),t.verticalStiffness()),rollingRadius:l=>o(e.rollingRadius(l),t.rollingRadius(l)),relaxationLength:l=>o(e.relaxationLength(l),t.relaxationLength(l)),axle:l=>l==="front"?e:t}}function ht(e){if(Sv.has(e))return e;let t=Av.get(e);if(t)return t;let r;if(e.axle){let n=e.axle("front"),o=e.axle("rear"),a=ht(n),s=ht(o);r=a===n&&s===o?e:zl(a,s)}else ha(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)};return Sv.add(r),r!==e&&Av.set(e,r),r}var Sv=new WeakSet,Av=new WeakMap;var Yl=25*(Math.PI/180);function kL(e){let t=.6180339887,r=0,n=Yl,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 js(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=Yl;if(s(Yl)<=a){let u=kL(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(Yl,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),f=s(m)-a;if(f<0?i=m:c=m,Math.abs(f)<=l)return m}return c}var Bf={shaft:!1,trail:0,hub:[0,0,0]};function wv(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 $f(e,t,r){let n=r.shaft?Nf(e,t):[0,0,0];if(r.trail!==0){let a=wv(e),s=[t[0],t[1],0],i=K(s,U(a,X(s,a)));n=te(n,oe(U(a,-r.trail),i))}let o=r.hub;return(o[0]!==0||o[1]!==0||o[2]!==0)&&(n=K(n,oe(K(e.contactPatch,e.wheelCenter),o))),{force:te(t,o),moment:n}}var ML=(e,t)=>{let r=e!==void 0&&e>0?1/e:0,n=t!==void 0&&t>0?1/t:0;return r+n},Wl={ucaFront:0,ucaRear:0,lcaFront:0,lcaRear:0,tieRod:0,pushRod:0,rack:0};function Wn(e){return!e.measured}function jn(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 Us(e,t){let r=e.corner.hardpoints,n=Jo(e.rocker,t.points.rockerAngle);return{ucaFront:r.ucaFront,ucaRear:r.ucaRear,lcaFront:r.lcaFront,lcaRear:r.lcaRear,tieInner:Gn(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 Gf(e,t,r=0){let n=t.links??{},o=t.bushings??{},a=(l,u,m)=>{let f=ML(u,m);return f>0&&Number.isFinite(l)?l*f: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 Cv(e,t,r,n){let o=Me(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 Xs(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:te(n.strut.top,t.topMount)}),t.ucaFront!==0||t.ucaRear!==0){let i=Cv(r.ucaFront,r.ucaRear,Me(r.uprightUpper,r.ucaFront)+t.ucaFront,Me(r.uprightUpper,r.ucaRear)+t.ucaRear);o.ubjAxial0=i.axial,o.ubjRadius2=i.radius2}if(t.lcaFront!==0||t.lcaRear!==0){let i=Cv(r.lcaFront,r.lcaRear,Me(r.uprightLower,r.lcaFront)+t.lcaFront,Me(r.uprightLower,r.lcaRear)+t.lcaRear),c=X(n.lbjRel0,n.lcaDir),l=K(n.lbjRel0,U(n.lcaDir,c)),u=Math.hypot(l[0],l[1],l[2]);o.lbjRel0=u>1e-9?te(U(n.lcaDir,i.axial),U(l,Math.sqrt(i.radius2)/u)):te(U(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=te(n.tieInner0,U(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 SL=8,AL=1e-5,FL=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 Kf(e,t,r){let n=$f(e,r.force,r.extras??Bf),o=r.alignMoment?te(n.moment,[0,0,r.alignMoment]):n.moment;return Bs(e,t,n.force,o)}function Ul(e,t,r,n,o,a,s=0){let i=Ne(e,t,r,o,a),c=e.corner.compliance;if(!(jn(c)&&Wn(e.corner)))return{state:i,forces:Kf(Us(e,i),e.corner.config.pushrodAttach,n),deflection:Wl,rigid:i,iterations:0,converged:!0,bypassed:!0};let u=i,m=e,f=e.corner.config.pushrodAttach,p=Kf(Us(e,i),f,n),d=Wl,h=!1,b=0;for(;b<SL;b++){let g=Us(m,u);if(p=Kf(g,f,n),p.singular)break;d=Gf(p,c,s),m=Xs(e,d);let y=Ne(m,t,r,FL(u),a),R=Me(y.points.wheelCenter,u.points.wheelCenter);if(u=y,R<AL){h=!0;break}}return{state:u,forces:p,deflection:d,rigid:i,iterations:b+1,converged:h&&u.converged,bypassed:!1}}var jl=1e3,Tv=1e5;function Pv(e,t,r,n,o){let a=Ul(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 Xl(e,t,r,n,o){let a={force:[0,0,n]},s=(b,g=0)=>Pv(e,t,r,{force:b,alignMoment:g},o),i=Pv(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,jl,n]),l=s([0,-jl,n]),u=s([jl,0,n]),m=s([-jl,0,n]),f=s([0,0,n],Tv),p=s([0,0,n],-Tv),d=(b,g)=>(b-g)/2,h=[i,c,l,u,m,f,p].every(b=>b.converged);return{toePerLateral:d(c.toe,l.toe),camberPerLateral:d(c.camber,l.camber),toePerLongitudinal:d(u.toe,m.toe),camberPerLongitudinal:d(u.camber,m.camber),toePerAligning:d(f.toe,p.toe),lateralPatch:d(c.patch[1],l.patch[1]),longitudinalPatch:d(u.patch[0],m.patch[0]),bypassed:!1,converged:h}}var wL=1e3;function Hf(e,t=wL){if(!jn(e.compliance)||!Wn(e))return;let r=rt(e),n=Ne(r,0,0),o=Xl(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 ba(e,t=-_f,r=_f,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=ze(e,{travelMin:t,travelMax:r,steps:n}),s=Hf(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 ql(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 hn(e,t){return{motionRatio:ql(e.travel,e.motionRatio,t),camber:ql(e.travel,e.camber,t),toe:ql(e.travel,e.toe,t),damperLen:ql(e.travel,e.damperLen,t)}}var Lv=Math.PI/180,CL=9.81;function bn(e,t,r,n=0){let o=Ce(e),a=e.wheelbase*(1-e.frontMassFrac),s=e.wheelbase*e.frontMassFrac,i=ma(e,n),c=e.aero?.model?(k,v,x)=>ma(e,n,v,k,x):()=>i,l=hn(t,0),u=hn(r,0),m=e.loadFactor,f=m!==void 0&&m!==1?(m-1)*e.massTotal*CL:0,p=f*e.frontMassFrac/2,d=f*(1-e.frontMassFrac)/2,h=(k,v)=>v>0&&Number.isFinite(v)&&k+v>0?v/(k+v):1,b=qe(e,"front"),g=qe(e,"rear"),y={F:h(e.wheelRateFront+(e.heaveSpringFront??0),b),R:h(e.wheelRateRear+(e.heaveSpringRear??0),g)},R={F:h(e.wheelRateFront+e.arbFront,b),R:h(e.wheelRateRear+e.arbRear,g)};return(k,v,x=0,M=0)=>{let A=c(k,v,x),w=o.rollGradient*k,T=w*Lv,P=o.pitchGradient*v*Lv,S=(O,_)=>{let z=_==="F"?e.trackFront:e.trackRear,I=_==="F"?o.rideRateFront:o.rideRateRear,N=(O==="R"?1:-1)*(z/2)*Math.tan(T),B=(_==="R"?s:-a)*Math.tan(P),V=`${_}${O}`,G=f?A[V]+(_==="F"?p:d):A[V],H=I>0?G/I:0;return{anti:N,sym:B+H}},F={FL:S("L","F"),FR:S("R","F"),RL:S("L","R"),RR:S("R","R")},C=O=>{let _=O[0];return F[O].sym*y[_]+F[O].anti*R[_]},L=ua(e,M,o,{FL:C("FL"),FR:C("FR")}),E=w+L.rollDeg,D=(O,_)=>{let z=_==="F"?t:r,I=_==="F"?l:u,N=`${_==="F"?"F":"R"}${O}`,B=F[N].sym+F[N].anti+L.travel[N],V=C(N)+L.travel[N]*R[_],G=B-V,H=hn(z,V),Y=(O==="R"?1:-1)*H.camber;return{travel:V,tyre:G,ground:B,camber:Y,camberRoad:Y+E,toe:H.toe,bumpToe:H.toe-I.toe,damperTravel:I.damperLen-H.damperLen}};return{FL:D("L","F"),FR:D("R","F"),RL:D("L","R"),RR:D("R","R"),steeringJacking:L}}}var zf=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Un(e){return{enabled:e?.enabled===!0,roadFeedbackGain:Math.min(2,Math.max(0,zf(e?.roadFeedbackGain,1))),turnInFrictionNm:Math.max(0,zf(e?.turnInFrictionNm,0)),columnStiffnessNmPerRad:Math.max(0,zf(e?.columnStiffnessNmPerRad,0))}}function Yf(e,t,r){let n=Un(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 Dv=()=>({totalNm:0,aligningNm:0,lateralNm:0,longitudinalNm:0,jackingNm:0});function Xn(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 qs(e,t,r,n="model",o){let a=e.steerFront;if(!Xn(e)||!a)return null;let s=t<0?-1:1,c=a.rackRatioMmPerRev/(2*Math.PI)/1e3,l=t>=0,u=o&&a.travelSurface?ca(a,Math.abs(t),l?o.FL:o.FR,l?o.FR:o.FL):la(a,Math.abs(t));if(!u.innerJacobian||!u.outerJacobian)return null;let m=(b,g)=>{let y=r[b],R=b==="FL"?-1:1,k=-R*y.Fy,x={aligning:1e3*(-R*y.Mz)*g.yaw,lateral:k*g.lateral,longitudinal:y.Fx*g.longitudinal,jacking:y.Fz*g.vertical},M=Dv();M.aligningNm=-s*x.aligning*c,M.lateralNm=-s*x.lateral*c,M.longitudinalNm=-s*x.longitudinal*c,M.jackingNm=-s*x.jacking*c,M.totalNm=M.aligningNm+M.lateralNm+M.longitudinalNm+M.jackingNm;let A=-s*(x.aligning+x.lateral+x.longitudinal+x.jacking);return{moment:M,rackN:A}},f=m("FL",l?u.innerJacobian:u.outerJacobian),p=m("FR",l?u.outerJacobian:u.innerJacobian),d=Dv();for(let b of[f.moment,p.moment])d.aligningNm+=b.aligningNm,d.lateralNm+=b.lateralNm,d.longitudinalNm+=b.longitudinalNm,d.jackingNm+=b.jackingNm,d.totalNm+=b.totalNm;let h=Yf(d.totalNm,t,e.steeringSystem);return d.totalNm=h.driverNm,{...d,roadNm:h.roadNm,assistanceNm:h.assistanceNm,frictionNm:h.frictionNm,columnTwistDeg:h.columnTwistDeg,rackForceN:f.rackN+p.rackN,aligningSource:n,perWheel:{FL:f.moment,FR:p.moment}}}var TL=e=>"front"in e&&"rear"in e;function ga(e,t){return TL(e)?e[t]:e}function jf(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)),f=(u-a[m])/o;return l[m]+f*(l[m+1]-l[m])};return{muX:l=>c(s,l),muY:l=>c(i,l)}}function Wf(e,t){let r=Math.max(0,t.Fz),n=e.muY(r)*r,o=e.muX(r)*r;if(!(n>0))return{fyUsed:0,fyMax:0,fyRes:0};let a=o>0?Math.min(1,Math.abs(t.Fx)/o):0,s=n*Math.sqrt(Math.max(0,1-a*a)),i=Math.abs(t.Fy);return{fyUsed:i,fyMax:s,fyRes:Math.max(0,s-i)}}function Ev(e,t,r){let n=Wf(e,t),o=Wf(e,r);return{left:n,right:o,fyRes:n.fyRes+o.fyRes}}function Er(e,t,r){let n=Ev(ga(e,"front"),t.FL,t.FR),o=Ev(ga(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 Qs=[{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"}],LL=Qs.flatMap(e=>[e.min,e.max]);function DL(e){let t={};for(let r of Qs){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 Ql(e){if(e.kind==="magic")return e.range??DL(e.coeffs)}function Uf(e){return Math.max(1,e.kind==="magic"?e.fnomin:e.nominalLoad)}function Iv(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 Zt(e){let t=_v.get(e);if(t!==void 0)return t;let r=10*Uf(e.model),{turnover:n,collapse:o}=IL(e,r),a=n??o??r;return _v.set(e,a),a}var _v=new WeakMap;function IL(e,t){let r=Uf(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 f=o(m*s);if(f<c){i=Iv(o,(m-2)*s,m*s,20,(p,d)=>p>d);break}c=f}let l=null,u=n(s);for(let m=2;m<=a;m++){let f=n(m*s);if(f>u){let p=Iv(n,(m-2)*s,m*s,40,(d,h)=>d<h);n(p)<.05*n(r)&&(l=p);break}u=f}return{turnover:i,collapse:l}}var Nv=.1;function Zl(e,t=Uf(e)){let r=Pe(e).muX(t);return{muX:r,none:Number.isFinite(r)&&r<Nv}}var Ov=["FL","FR","RL","RR"],_L=e=>e==="FL"||e==="RL",NL=e=>e==="FL"||e==="FR"?"front":"rear";function Jl(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 Ov)a[l]={...t[l]};let s=l=>{let u=0;for(let f of Ov)NL(f)===e.axle&&(a[f].Fx=e.sense*(f===e.strong?l-e.open/2:e.open/2),u-=(_L(f)?o:-o)*a[f].Fx);let m=Er(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 OL=[["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]],VL=[["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]],BL=[["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],["QBZ6","Camber influence Bt",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]],$L=[["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]],GL=[["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]],Bv=[["lateral",OL],["longitudinal",VL],["aligning",BL],["combined",$L],["scaling",GL]].flatMap(([e,t])=>t.map(([r,n,o])=>({key:r,section:e,text:n,fallback:o}))),fz=new Map(Bv.map(e=>[e.key,e]));var KL=/^\$\s*EDITED\s+([A-Z][A-Z0-9_]*)\s+was\s+(absent|[-+0-9.eE]+)\s*$/;function $v(e){let t={};for(let r of e.split(/\r?\n/)){let n=r.trim().match(KL);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 zL=/^\s*\$\s*UNLOADED_RADIUS_STAND_IN\s*=\s*([0-9.eE+-]+)/,YL=/^\$-+ written by (?:PaceDynamics|PaceLab)\b/m,WL=/^\$\s*AXIS_SYSTEM\s*=\s*(ISO-W|SAE)\b/m;function jL(e){let t=e.match(WL);return t?{axisSystem:t[1]==="SAE"?"sae":"iso",trustSide:!0}:YL.test(e)?{axisSystem:"sae",trustSide:!1}:{axisSystem:"iso",trustSide:!0}}function UL(e){return e>=62?"6.2":e>=61?"6.1":"5.2"}var Gv=new Map([["pa",1],["pascal",1],["kpa",1e3],["kilopascal",1e3],["mpa",1e6],["megapascal",1e6],["bar",1e5],["psi",6894.757293168]]);function XL(e,t,r){let n=r.PRESSURE?.trim().toLowerCase(),o=n===void 0?1:Gv.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 qL=new Map([["radians",1],["radian",1],["rad",1],["degrees",Math.PI/180],["degree",Math.PI/180],["deg",Math.PI/180]]);function QL(e,t){let r=(s,i)=>s===void 0?1:i.get(s.trim().toLowerCase()),n=r(t.ANGLE,qL),o={fz:1,kappa:1,alpha:n,gamma:n,p:r(t.PRESSURE,Gv)},a={};for(let s of Qs){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 Zs(e,t="imported",r={}){let n=jL(e),o=r.axisSystem??n.axisSystem,a={},s={},i={},c="",l;for(let g of e.split(/\r?\n/)){let y=g.match(zL);y&&(l=parseFloat(y[1]));let R=g.replace(/[$!].*$/,"").trim();if(!R)continue;if(R.startsWith("[")){c=(R.match(/^\[([^\]]*)/)?.[1]??"").trim().toUpperCase();continue}let k=R.indexOf("=");if(k<0)continue;let v=R.slice(0,k).trim().toUpperCase(),x=R.slice(k+1).trim(),M=x.match(/^'([^']*)'|^"([^"]*)"/);if(M){s[v]=M[1]??M[2]??"",c==="UNITS"&&(i[v]=s[v]);continue}let A=parseFloat(x);Number.isFinite(A)&&(a[v]=A)}let u=UL(a.FITTYP??62),m=$v(e),f=m?Object.fromEntries(Object.entries(m).filter(([g])=>a[g]!==void 0)):void 0,p=a.VERTICAL_STIFFNESS??a.KZ??0,d=XL(a,s,i),h=QL(a,i),b=[];return a.UNLOADED_RADIUS===void 0&&a.R0===void 0&&b.push("UNLOADED_RADIUS"),p<=0&&b.push("VERTICAL_STIFFNESS"),a.FNOMIN===void 0&&b.push("FNOMIN"),d===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:p>0?p/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:d??0,missing:b,...f&&Object.keys(f).length?{edited:f}:{},...h?{range:h}:{}}}function pr(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 eu(e){if(!e)return null;let t=e.sectionWidth;return t!==void 0&&t>0?t:null}var kz=Math.PI/180;var wz=Math.PI/180,Cz=180/Math.PI;function Js(){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 zv=`$ AXIS_SYSTEM = SAE (authored in the evaluation frame: y right)
2
+ import{parentPort as HT,workerData as eG}from"node:worker_threads";import{readFileSync as By}from"node:fs";import{join as $y}from"node:path";var sl=e=>e.format!=="points"&&!e.field;var ht=e=>e?.kind==="ice";var bx={packVoltageMax:600,segmentVoltageMax:120,powerLimitKw:80};var Ie=e=>typeof e=="number"&&Number.isFinite(e);function YT(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(Ie))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(Ie))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(Ie))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(Ie))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(Ie))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 WT(e){return!e||typeof e!="object"?"The cell has no curve.":e.kind==="table"?YT(e):e.kind==="analytic"?!Ie(e.vCut)||!Ie(e.vNom)||!Ie(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?!Ie(e.r0)||e.r0<0?"The cell resistance must be a number and cannot be negative.":e.socAtNom!==void 0&&(!Ie(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 il(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(!Ie(t.capacityAh)||t.capacityAh<=0)return"The cell capacity must be a positive number of amp-hours.";if(!Ie(t.vMin)||t.vMin<0)return"The cut-off voltage must be a number and cannot be negative.";if(!Ie(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(!Ie(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&&(!Ie(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&&(!Ie(t.massKg)||t.massKg<0))return"The cell mass must be a number and cannot be negative.";let r=WT(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(!Ie(o.heatCapacityJPerK)||o.heatCapacityJPerK<=0)return"The cell heat capacity must be a positive number of joules per kelvin.";if(!Ie(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&&!Ie(o.startC))return"The starting temperature must be a number.";if(o.entropicVPerK!==void 0&&!Ie(o.entropicVPerK))return"The entropic coefficient must be a number.";if(o.derateFromC!==void 0){if(!Ie(o.derateFromC))return"The temperature the derate starts at must be a number.";if(o.derateToC!==void 0){if(!Ie(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(!Ie(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 Bn(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 _e(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 cl(e,t,r,n,o){let a=e.length,s=t.length;if(a===0||s===0)return 0;let i=Bn(e,n),c=Bn(t,o),l=Math.min(i.i+1,a-1),u=Math.min(c.i+1,s-1),m=r[c.i][i.i],f=r[c.i][l],p=r[u][i.i],d=r[u][l],h=m+i.t*(f-m),b=p+i.t*(d-p);return h+c.t*(b-h)}var Xo=[0,.05,.1,.2,.3,.4,.5,.6,.7,.8,.9,1],md={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]},gx=[0,.05,.1,.2,.5,.8,1],yx=[2.2,1.55,1.3,1.12,1,.97,.98];function xx(e){return _e(gx,yx,e)}var Rx=[-20,-10,0,10,25,40,60],vx=[4,2.8,2,1.4,1,.82,.75];function pd(e){return _e(Rx,vx,e)}var kx=.5;function dd(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=md[t]??md.other,l=e.socAtNom??kx,u=Xo.includes(l)?[...Xo]:[...Xo,l].sort((h,b)=>h-b),m=_e(Xo,c,l),f=m>0&&m<1?Math.log(i)/Math.log(m):1,p=[],d=[];for(let h of u){let b=_e(Xo,c,h);p.push(o+s*Math.pow(b,f)),d.push(e.constantResistance?a:a*xx(h))}return{kind:"table",soc:u,ocv:p,r0:d}}function fd(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+=(_e(t,r,s)+_e(t,r,i))/2*(i-s)}return o}var qo=25,Mx=new WeakMap;function Cr(e){let t=Mx.get(e);if(t)return t;let r=il(e);if(r)throw new Error(r);let{cell:n,pack:o}=e,a=n.curve.kind==="table"?n.curve:dd(n.curve,n.chemistry),s=o.series,i=o.parallel,c=s/i,l=a.rTempC,u=a.rGrid,m=i*n.capacityAh,f=s*n.vMin,p=n.iMaxA>0?i*n.iMaxA:1/0,d=n.iMaxChargeA!==void 0&&n.iMaxChargeA>0?n.iMaxChargeA:n.iMaxA/4,h=d>0?i*d:1/0,b=A=>s*_e(a.soc,a.ocv,A),g=(A,w=qo)=>{let T=l&&u?cl(a.soc,l,u,A,w):_e(a.soc,a.r0,A)*pd(w);return c*T+o.busResistance},y=(A,w,T)=>b(A)-w*g(A,T),R=(A,w,T)=>{if(!(A>0))return 0;let P=b(w),S=g(w,T);if(!(S>0))return A/P;let F=P*P-4*S*A;return F<0?NaN:2*A/(P+Math.sqrt(F))},k=(A,w,T)=>{if(!(A>0))return 0;let P=b(w),S=g(w,T);return S>0?2*A/(P+Math.sqrt(P*P+4*S*A)):A/P},v=A=>{let w=e.thermal;if(!w||w.derateFromC===void 0)return 1;let T=w.derateToC??w.derateFromC;return A<=w.derateFromC?1:!(T>w.derateFromC)||A>=T?0:1-(A-w.derateFromC)/(T-w.derateFromC)},x=(A,w,T=0)=>{let P=b(A),S=g(A,w),F=S>0?P/(2*S):1/0,C=G=>{if(!(S>0))return G*P;let H=Math.min(G,F);return H*(P-H*S)},L=S>0?Math.max(0,(P-f)/S):1/0,E=T>0&&Number.isFinite(T)?T:1/0,D=S>0?C(L):1/0,N=Number.isFinite(p)?C(p):1/0,O=S>0?P*P/(4*S):1/0,z=[["rules",E],["voltage-floor",D],["current",N],["matched-load",O]],I=z[0][0],_=z[0][1];for(let[G,H]of z)H<_&&(_=H,I=G);let B=v(w??qo);B<1&&(_=Number.isFinite(_)?_*B:_,I="temperature");let V=Number.isFinite(_)?R(_,A,w):1/0;return{watts:_,binding:I,rules:E,voltageFloor:D,current:N,matchedLoad:O,derate:B,amps:V,volts:Number.isFinite(V)?P-V*S:P}},M={model:e,table:a,capacityAh:m,chargeC:m*3600,energyKwh:m*(s*fd(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:f,currentCeiling:p,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:R,chargeCurrentFor:k,maxPower:x};return Mx.set(e,M),M}function hd(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 Sx={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},Ax={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},Fx={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 bd(){return{name:"Formula Student accumulator",cell:hd(Sx),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 gd(){return{name:"LFP pack",cell:hd(Ax),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 yd(){return{name:"Road car pack",cell:hd(Fx),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 xd(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 ll(e){if(e.kind==="ice"){let n=e.gearbox.efficiency;return{model:e,maxTorque:o=>o>e.limitRpm?0:_e(e.rpm,e.torque,o),efficiency:()=>n}}let t=n=>_e(e.rpm,e.torque,n),r=e.kind==="simple"?()=>e.efficiency:(n,o)=>cl(e.effRpm,e.effTorque,e.effGrid,n,o);return{model:e,maxTorque:t,efficiency:r}}function Rd(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=d=>Math.max(0,e.terminalResistanceOhm*(1+.00393*(d-t))),l=d=>n>0&&o>0?n*Math.pow(Math.max(0,d)/o,a):0,u=(d,h,b)=>{let g=r>0?Math.abs(h)/r:0;return 1.5*c(b)*g*g+l(d)},m=(d,h)=>{let b=e.coolingWPerK*(h-e.coolantC)-l(d);return!(b>0)||r<=0?0:r*Math.sqrt(b/(1.5*c(h)))},f=e.coolingWPerK>0?e.heatCapacityJPerK/e.coolingWPerK:1/0,p=Number.isFinite(f)?.25*f:1/0;return{spec:e,startC:e.startC??e.coolantC,lossW:u,step(d,h,b){if(!(b>0)||!(e.heatCapacityJPerK>0))return d;let g=Number.isFinite(p)?Math.max(1,Math.ceil(b/p)):1,y=b/g,R=d;for(let k=0;k<g;k++)R+=(h-e.coolingWPerK*(R-e.coolantC))*y/e.heatCapacityJPerK;return R},continuousTorque:m,derate(d,h,b){if(s===void 0||i===void 0||!(i>s)||!(b>0)||h<=s)return 1;let g=Math.min(1,m(d,i)/b);return h>=i?g:1-(1-g)*(h-s)/(i-s)},equilibriumC(d){return e.coolingWPerK>0?e.coolantC+d/e.coolingWPerK:1/0}}}function Ze(e,t){return t==="rear"&&e.tireRateRear!==void 0?e.tireRateRear:e.tireRate}function vd(e,t){let r=e.tyreFreeRadiusRear;return(t==="rear"&&r!==void 0?r:e.tyreFreeRadius)??0}var ul=9.81,wx=(e,t)=>e*(t*t)/2*(Math.PI/180)/1e3,Rs=(e,t)=>e+t>0?e*t/(e+t):0,Cx=.5;function ml(e,t,r){if(!(r>0))return 1;let n=e*ul*t*(Math.PI/180)/r;return 1/(1-Math.min(Cx,n))}function kd(e,t,r){return r>0?e*ul*t/(r*r):0}function Tx(e,t,r,n,o){if(!(n>0)||!(o>0))return 1;let a=kd(e,t,r)*(1/n+1/o);return 1/(1-Math.min(Cx,a))}function Te(e){let t=4*e.unsprungPerCorner,r=Math.max(0,e.massTotal-t),n=r*e.frontMassFrac,o=r*(1-e.frontMassFrac),a=Ze(e,"front"),s=Ze(e,"rear"),i=e.wheelRateFront+(e.heaveSpringFront??0),c=e.wheelRateRear+(e.heaveSpringRear??0),l=Rs(i,a),u=Rs(c,s),m=(N,O)=>{let z=O/2;return z>0?1/(2*Math.PI)*Math.sqrt(N*1e3/z):0},f=m(l,n),p=m(u,o),d=Rs(e.wheelRateFront+e.arbFront,a),h=Rs(e.wheelRateRear+e.arbRear,s),b=wx(d,e.trackFront),g=wx(h,e.trackRear),y=b+g,R=y>0?b/y:.5,k=e.rcHeightFront+(e.rcHeightRear-e.rcHeightFront)*(1-e.frontMassFrac),v=(e.cgHeight-k)/1e3,x=r*ul*v,M=ml(r,v,y),A=y>0?x/y*M:0,w=e.massTotal*ul*e.cgHeight/e.wheelbase,T=2*l,P=2*u,S=Tx(r,e.cgHeight,e.wheelbase,T,P),C=(T>0&&P>0?(w/T+w/P)/e.wheelbase*S:0)*(180/Math.PI),L=e.wheelbase*e.wheelbase*Rs(T,P)*(Math.PI/180)/1e3,E=e.damperFront??2.5,D=e.damperRear??2.5;return{sprungMass:r,sprungFront:n,sprungRear:o,rideRateFront:l,rideRateRear:u,rideFreqFront:f,rideFreqRear:p,rollRateFront:b,rollRateRear:g,rollRateTotal:y,rollWheelRateFront:d,rollWheelRateRear:h,frontRollStiffFrac:R,rollGradient:A,pitchGradient:C,pitchRate:L,cgRollGain:M,cgPitchGain:S,rideDampingFront:E+(e.heaveDamperFront??0),rideDampingRear:D+(e.heaveDamperRear??0),rollDampingFront:E+(e.rollDamperFront??0),rollDampingRear:D+(e.rollDamperRear??0)}}var an=["clFront","clRear","cd"],sn=e=>e.frame?.kind==="pitch";function Qo(e){return sn(e)?{x:e.axes.h,y:e.axes.pitch}:{x:e.axes.hFront,y:e.axes.hRear}}var pl=e=>e.frame?.kind==="pitch",Px=e=>e.kind==="map";var dl=45,et=e=>typeof e=="number"&&Number.isFinite(e);function fl(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(et))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 Lx(e,t){if(t===void 0)return null;for(let r of an){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(et)||!n.factor.every(et))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 Dx(e,t){return t===void 0?null:!et(t.dCl)||!et(t.dBalance)||!et(t.dCd)?`The ${e} slopes must be numbers.`:!et(t.maxDeg)||!(t.maxDeg>0)?`The ${e} response needs a positive angle to be valid to.`:null}function vs(e){if(!e||typeof e!="object")return"Not an aero model.";if(!et(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=fl("front ride-height",e.axes?.hFront);if(i)return i;let c=fl("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(!et(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=fl("ride-height",e.axes?.h);if(i)return i;let c=fl("pitch",e.axes?.pitch,"\xB0","pitch");if(c)return c;let l=e.axes.pitch.find(u=>Math.abs(u)>=dl);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 an){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(et))return`${i} contains a value that is not a number.`}}return Lx("yaw",e.attitude?.yaw)??Lx("roll",e.attitude?.roll)}if(e.kind==="sensitivity"){let t;if(e.frame==null)t=["hFront","hRear"];else if(e.frame?.kind==="pitch"){if(!et(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||!et(r[t[0]])||!et(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 an){if(!e.at||!et(e.at[s]))return`${s} at the reference must be a number.`;let i=n?.[s];if(!i||!et(i[t[0]])||!et(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||!et(i[0])||!et(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])>=dl||Math.abs(i[1])>=dl))return`A pitch range reaching ${Math.abs(i[0])>=dl?i[0]:i[1]}\xB0 is not a car's attitude. Pitch is in degrees.`}return Dx("yaw",e.attitude?.yaw)??Dx("roll",e.attitude?.roll)}return`Unknown aero model kind "${e.kind}".`}var Ex=180/Math.PI;function Zo(e,t,r,n){let o=(n-r)/t;return{h:r+e.refX*o,pitch:Math.atan(o)*Ex}}function Jo(e,t,r,n){let o=Math.tan(n/Ex);return{hFront:r-e.refX*o,hRear:r+(t-e.refX)*o}}var $G=180/Math.PI,jT=["hFront","hRear"],UT=["h","pitch"],Ad=e=>e?.kind==="pitch"?UT:jT,Pt=(e,t)=>e[t],hl=(e,t)=>e[t],Md=(e,t)=>({[e[0]]:t(e[0]),[e[1]]:t(e[1])});function XT(e){if(!(!e.yaw&&!e.roll))return{...e.yaw?{yaw:{...e.yaw}}:{},...e.roll?{roll:{...e.roll}}:{}}}function Fd(e){let t=Ad(e.frame),r=e.balanceFront,n=e.cl*r,o=e.cl*(1-r),a=Md(t,c=>Pt(e.dCl,c)*r+e.cl*Pt(e.dBalance,c)),s=Md(t,c=>Pt(e.dCl,c)*(1-r)-e.cl*Pt(e.dBalance,c)),i=XT(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:Md(t,c=>Pt(e.dCd,c))},range:{[t[0]]:[...hl(e.range,t[0])],[t[1]]:[...hl(e.range,t[1])]},provenance:{...e.provenance},...i?{attitude:i}:{}}}function bl(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 Sd(e,t,r=11){let n=Array.from({length:r},(a,s)=>t.maxDeg*s/(r-1)),o=n.map(a=>bl(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 Ix(e){if(!(!e.attitude?.yaw&&!e.attitude?.roll))return{...e.attitude.yaw?{yaw:Sd(e.at,e.attitude.yaw)}:{},...e.attitude.roll?{roll:Sd(e.at,e.attitude.roll)}:{}}}function _x(e,t,r,n=0,o=0){let[a,s]=Ad(e.frame),i=t-Pt(e.ref,a),c=r-Pt(e.ref,s),l={clFront:e.at.clFront+Pt(e.slope.clFront,a)*i+Pt(e.slope.clFront,s)*c,clRear:e.at.clRear+Pt(e.slope.clRear,a)*i+Pt(e.slope.clRear,s)*c,cd:e.at.cd+Pt(e.slope.cd,a)*i+Pt(e.slope.cd,s)*c},u=e.attitude?.yaw?bl(e.at,e.attitude.yaw,n):{clFront:1,clRear:1,cd:1},m=e.attitude?.roll?bl(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 wd(e){let[t,r]=Ad(e.frame),n=[...hl(e.range,t)],o=[...hl(e.range,r)],a=i=>o.map(c=>n.map(l=>i(_x(e,l,c)))),s=Ix(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 Cd=180/Math.PI,Nx=new WeakMap,Ox=new WeakMap,Td=new WeakMap;function cn(e,t){let r=Ox.get(e);if(r)return r;let n=t?.wheelbase,o=n!==void 0?Td.get(e)?.get(n):void 0;if(o)return o;let a=qT(e),s=a.map;if(!sn(s)){let l=QT(e,a);return Ox.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=ZT(e,a,s.frame,n),c=Td.get(e);return c||(c=new Map,Td.set(e,c)),c.set(n,i),i}function qT(e){let t=Nx.get(e);if(t)return t;let r=vs(e);if(r)throw new Error(r);let n=e.kind==="map"?e:wd(e),{x:o,y:a}=Qo(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},f=(y,R)=>{let k=Math.abs(R),v=y.clFront.deg[y.clFront.deg.length-1];return{clFront:_e(y.clFront.deg,y.clFront.factor,k),clRear:_e(y.clRear.deg,y.clRear.factor,k),cd:_e(y.cd.deg,y.cd.factor,k),clamped:k>v}},p=(y,R)=>{if(!u)return m;let k=c?f(c,y):m,v=l?f(l,R):m;return{clFront:k.clFront*v.clFront,clRear:k.clRear*v.clRear,cd:k.cd*v.cd,clamped:k.clamped||v.clamped}},d=(y,R,k=0,v=0)=>{let x=Bn(o,y),M=Bn(a,R),A=Math.min(x.i+1,s-1),w=Math.min(M.i+1,i-1),T=S=>{let F=S[M.i][x.i],C=S[M.i][A],L=S[w][x.i],E=S[w][A],D=F+x.t*(C-F),N=L+x.t*(E-L);return D+M.t*(N-D)},P=p(k,v);return{clFront:u?T(n.clFront)*P.clFront:T(n.clFront),clRear:u?T(n.clRear)*P.clRear:T(n.clRear),cd:u?T(n.cd)*P.cd:T(n.cd),clampedRide:x.clamped||M.clamped,clampedAttitude:P.clamped}},h={x:[o[0],o[s-1]],y:[a[0],a[i-1]]},b=(y,R,k=!1,v=0,x=0)=>{let M=p(v,x),A=Bn(o,k?Math.min(Math.max(y,h.x[0]),h.x[1]):y),w=Bn(a,k?Math.min(Math.max(R,h.y[0]),h.y[1]):R),T=Math.min(A.i+1,s-1),P=Math.min(w.i+1,i-1),S=T>A.i?o[T]-o[A.i]:0,F=P>w.i?a[P]-a[w.i]:0,C={};for(let L of an){let E=n[L],D=E[w.i][A.i],N=E[w.i][T],O=E[P][A.i],z=E[P][T],I=A.clamped||S===0?0:((N-D)*(1-w.t)+(z-O)*w.t)/S,_=w.clamped||F===0?0:((O-D)*(1-A.t)+(z-N)*A.t)/F;C[L]=u?{x:I*M[L],y:_*M[L]}:{x:I,y:_}}return C},g={map:n,x:h.x,y:h.y,hasAttitude:u,factors:p,at:d,slopes:b};return Nx.set(e,g),g}function QT(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 an)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 ZT(e,t,r,n){let o=r.refX,a=o/n,s=(l,u,m=0,f=0)=>{let p=(u-l)/n;return t.at(l+o*p,Math.atan(p)*Cd,m,f)},i=(l,u,m=!1,f=0,p=0)=>{let d=(u-l)/n,h=t.slopes(l+o*d,Math.atan(d)*Cd,m,f,p),b=Cd/(n*(1+d*d)),g={};for(let y of an)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)=>Jo(r,n,l,u),fromAxles:(l,u)=>{let m=Zo(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 Pd(e){let t=e.clFront+e.clRear;return{cl:t,balanceFront:t!==0?e.clFront/t:.5}}var be=(e,t)=>e*t/100,Je=e=>e/100,Vx={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:be(3,-.4),hRear:be(3,.1)},dBalance:{hFront:Je(-.3),hRear:Je(.15)},dCd:{hFront:be(1.3,-.1),hRear:be(1.3,.05)},yaw:{dCl:be(3,-1),dBalance:Je(-.3),dCd:be(1.3,.5),maxDeg:10},roll:{dCl:be(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."},Bx={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:be(3,-.3),hRear:be(3,-.15)},dBalance:{hFront:Je(-.15),hRear:Je(.15)},dCd:{hFront:be(.9,-.15),hRear:be(.9,-.05)},yaw:{dCl:be(3,-1.5),dBalance:Je(.2),dCd:be(.9,.8),maxDeg:8},roll:{dCl:be(3,-1),dBalance:Je(-.3),dCd:0,maxDeg:2},note:"Assumed class-level sensitivities for a ground-effect floor, ride height, yaw and roll; not measured."},$x={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:be(1.4,-.3),hRear:be(1.4,.05)},dBalance:{hFront:Je(-.25),hRear:Je(.15)},dCd:{hFront:be(.42,-.1),hRear:0},yaw:{dCl:be(1.4,-.8),dBalance:Je(-.2),dCd:be(.42,.6),maxDeg:10},roll:{dCl:be(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."},Gx={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:be(.3,.5),maxDeg:10},note:"Assumed class-level sensitivities for a road car with no aero devices; not measured."},Kx={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:be(.45,-.4),hRear:be(.45,.05)},dBalance:{hFront:Je(-.25),hRear:Je(.15)},dCd:{hFront:be(.4,-.1),hRear:0},yaw:{dCl:be(.45,-1.2),dBalance:Je(-.2),dCd:be(.4,.6),maxDeg:10},roll:{dCl:be(.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."},Hx={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:be(.6,-.35),hRear:be(.6,.05)},dBalance:{hFront:Je(-.25),hRear:Je(.15)},dCd:{hFront:be(.45,-.1),hRear:0},yaw:{dCl:be(.6,-1),dBalance:Je(-.2),dCd:be(.45,.6),maxDeg:10},roll:{dCl:be(.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."},zx={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:be(2.5,-.35),hRear:be(2.5,.05)},dBalance:{hFront:Je(-.25),hRear:Je(.15)},dCd:{hFront:be(.9,-.1),hRear:be(.9,.05)},yaw:{dCl:be(2.5,-1),dBalance:Je(-.3),dCd:be(.9,.5),maxDeg:10},roll:{dCl:be(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."},Yx={name:"Race truck aero",area:6.2,cl:-.1,balanceFront:.6,cd:.65,ref:{hFront:110,hRear:240},range:{hFront:[60,160],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:be(.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 Tr(e){return Fd({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 Ld=()=>Tr(Vx),Dd=()=>Tr(Bx),Ed=()=>Tr($x),Id=()=>Tr(Gx),_d=()=>Tr(Kx),Nd=()=>Tr(Hx),Od=()=>Tr(zx),Vd=()=>Tr(Yx);function $n(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 gl(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,Ze(e,"front")))/r,rear:(t.sprungMass*(1-n)+o*a(t.rideRateRear,Ze(e,"rear")))/r}}function yl(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 Bd(e,t){return e.wheelbase>0?e.massTotal*t*9.81/e.wheelbase:0}function ea(e,t,r){let n=2*t.rideRateFront,o=2*t.rideRateRear;return!(n>0)||!(o>0)?0:Math.min(kd(t.sprungMass,r,e.wheelbase),.5*n*o/(n+o))}function ks(e,t,r,n,o){let a=e.cgHeight,s=Bd(e,r);if(n===0&&o===0&&s===0)return{height:a,forward:0,noseLoad:0,dropFront:0,dropRear:0};let i=gl(e,t),c=2*t.rideRateFront,l=2*t.rideRateRear,u=a,m=0,f=0,p=0;for(let h=0;h<6;h++){p=ea(e,t,u);let b=n-s*u,g=o+s*u;if(p>0){let k=c*l-p*(c+l);m=(b*(l-p)-p*g)/k,f=(g*(c-p)-p*b)/k}else m=c>0?b/c:0,f=l>0?g/l:0;let y=yl(a,i,m,f),R=Math.abs(y-u);if(u=y,R<1e-9)break}let d=m-f;return{height:u,forward:e.wheelbase>0?u*d/e.wheelbase:0,noseLoad:p*d,dropFront:m,dropRear:f}}var $d={yawDeg:0,rollDeg:0},Wx=1e-4,JT=40,jx=50;function ln(e,t,r=0){let n=e.aero?.model;if(!(!n||!cn(n,e).hasAttitude))return{yawDeg:r,rollDeg:Te(e).rollGradient*t}}function ta(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 Jo(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=pl(r)?n(r.frame,r.ref.h,r.ref.pitch):r.ref;else if(r){let{x:a,y:s}=Qo(r),i=(a[0]+a[a.length-1])/2,c=(s[0]+s[s.length-1])/2;o=sn(r)?n(r.frame,i,c):{hFront:i,hRear:c}}return{hFront:e.rideHeightFront??o.hFront,hRear:e.rideHeightRear??o.hRear}}var Ux=new WeakMap;function Pr(e,t,r=0,n){let o=e.aero;if(!o?.model)return null;let a=Ux.get(e);a||(a=new Map,Ux.set(e,a));let s=n&&cn(o.model,e).hasAttitude?n:$d,i=s===$d?`${t}|${r}`:`${t}|${r}|${s.yawDeg.toFixed(3)}|${s.rollDeg.toFixed(3)}`,c=a.get(i);if(c)return c;let l=eP(e,o,t,r,s);return a.size>4096&&a.clear(),a.set(i,l),l}function eP(e,t,r,n,o){let a=cn(t.model,e),s=Te(e),i=2*s.rideRateFront,c=2*s.rideRateRear,l=ta(t,e.wheelbase),u=.5*t.rho*r*r,m=a.area,f=e.wheelbase>0?t.copHeight/e.wheelbase:0,p=gl(e,s),d=Bd(e,n),h=(T,P)=>yl(e.cgHeight,p,l.hFront-T,l.hRear-P),b=(T,P)=>l.hFront-T-(l.hRear-P),g=(T,P)=>{let S=a.at(T,P,o.yawDeg,o.rollDeg),F=u*m*S.clFront,C=u*m*S.clRear,L=u*m*S.cd,E=L*f,D=h(T,P),N=d*D,O=ea(e,s,D)*b(T,P),z=F-N-E+O,I=C+N+E-O,_=T-l.hFront+(i>0?z/i:0),B=P-l.hRear+(c>0?I/c:0);return{c:S,downFront:F,downRear:C,drag:L,rF:_,rR:B,norm:Math.hypot(_,B)}},y=(T,P,S=!1)=>{let F=a.slopes(T,P,S,o.yawDeg,o.rollDeg),C=i>0?u*m/i:0,L=c>0?u*m/c:0;return[[C*(F.clFront.hFront-f*F.cd.hFront),C*(F.clFront.hRear-f*F.cd.hRear)],[L*(F.clRear.hFront+f*F.cd.hFront),L*(F.clRear.hRear+f*F.cd.hRear)]]},R=l.hFront,k=l.hRear,v=g(R,k),x=0;for(;v.norm>=Wx&&x<JT;){x++;let T=y(R,k),P=i>0?d/i:0,S=c>0?d/c:0,F=ea(e,s,h(R,k)),C=i>0?F/i:0,L=c>0?F/c:0,E=1+T[0][0]-P*p.front-C,D=T[0][1]-P*p.rear+C,N=T[1][0]+S*p.front+L,O=1+T[1][1]+S*p.rear-L,z=E*O-D*N,I,_;Math.abs(z)>1e-9?(I=-(O*v.rF-D*v.rR)/z,_=-(-N*v.rF+E*v.rR)/z):(I=-.5*v.rF,_=-.5*v.rR);let B=Math.max(1,Math.abs(I)/jx,Math.abs(_)/jx);I/=B,_/=B;let V=1;for(let G=0;G<6;G++){let H=g(R+V*I,k+V*_);if(H.norm<=v.norm||G===5){R+=V*I,k+=V*_,v=H;break}V*=.5}}let M=y(R,k,!0),A=2+M[0][0]+M[1][1],w=(1+M[0][0])*(1+M[1][1])-M[0][1]*M[1][0];return{v:r,axG:n,hFront:R,hRear:k,cgHeight:h(R,k),cgForward:e.wheelbase>0?h(R,k)*b(R,k)/e.wheelbase:0,cgNoseLoad:ea(e,s,h(R,k))*b(R,k),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:tP(M),stable:w>0&&A>0,converged:v.norm<Wx,iterations:x,clampedRide:v.c.clampedRide,yawDeg:o.yawDeg,rollDeg:o.rollDeg,clampedAttitude:v.c.clampedAttitude}}function tP(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 Ms(e,t,r=0,n){let o=Pr(e,t,r,n);return o?{downforce:o.downforce,drag:o.drag,downFront:o.downFront,downRear:o.downRear}:e.aero?$n(e.aero,t):{downforce:0,drag:0,downFront:0,downRear:0}}function rP(e,t,r,n){let o=$n(t,r),a=Te(e),s=ta(t,e.wheelbase),i=e.wheelbase>0?o.drag*t.copHeight/e.wheelbase:0,c=ks(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 Gd(e,t,r=0,n){let o=Pr(e,t,r,n);return o||(e.aero?rP(e,e.aero,t,r):null)}function xl(e,t=0,r=0,n,o){if(e.aero&&t>0){if(e.aero.model){let i=Pr(e,t,r,n);return{height:i.cgHeight,forward:i.cgForward,noseLoad:i.cgNoseLoad}}let a=$n(e.aero,t),s=e.wheelbase>0?a.drag*e.aero.copHeight/e.wheelbase:0;return ks(e,o??Te(e),r,a.downFront-s,a.downRear+s)}return r===0?{height:e.cgHeight,forward:0,noseLoad:0}:ks(e,o??Te(e),r,0,0)}var Xx=[0,1,0],Kd=[0,0,1],te=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],K=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],U=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],Hd=e=>[-e[0],-e[1],-e[2]],X=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],ae=(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]],nP=e=>X(e,e),un=e=>Math.sqrt(X(e,e)),Ss=(e,t)=>nP(K(e,t)),Me=(e,t)=>un(K(e,t)),q=e=>{let t=un(e);return t<1e-12?[0,0,0]:[e[0]/t,e[1]/t,e[2]/t]};var mn=(e,t,r)=>{let n=q(r),o=K(e,t);return te(t,U(n,X(o,n)))},qx=(e,t,r)=>Me(e,mn(e,t,r));var aP=1e-6;function sP(e){if(e<aP){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 ct(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]=sP(r),a=ae(e,t),s=ae(e,a);return te(t,te(U(a,n),U(s,o)))}function Gt(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 ct(U(o,r),e)}function cr(e,t){let r=t.length,n=e.map(a=>a.slice()),o=t.slice();return Zx(n,o,r,new Array(r).fill(0))}function Qx(e,t,r){return Zx(e,t,t.length,r)}function Zx(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 f=s;f<r;f++)e[u][f]-=m*e[s][f];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 Jx=e=>{let t=0;for(let r of e)t=Math.max(t,Math.abs(r));return t},eR=e=>{let t=0;for(let r of e)t+=r*r;return t},iP=Math.sqrt(Number.EPSILON);function tR(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=Jx(c),u=eR(c),m=.001,f=1,p=c.length,d=Array.from({length:p},()=>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),R=new Array(a).fill(0),k=new Array(a).fill(0),v=new Array(a).fill(0);for(let x=0;x<n;x++){if(l<o)return{x:i,residualNorm:l,iterations:x,converged:!0,condProxy:f};for(let T=0;T<a;T++){let P=iP*Math.max(Math.abs(i[T]),s[T]);for(let F=0;F<a;F++)k[F]=i[F];k[T]+=P;let S=e(k);for(let F=0;F<p;F++)d[F][T]=(S[F]-c[F])/P}let M=0;for(let T=0;T<a;T++){for(let S=0;S<a;S++){let F=0;for(let C=0;C<p;C++)F+=d[C][T]*d[C][S];h[T][S]=F}let P=0;for(let S=0;S<p;S++)P+=d[S][T]*c[S];g[T]=P,M=Math.max(M,h[T][T])}let A=Math.max(M,1e-9),w=!1;for(let T=0;T<18;T++){let P=m*A;for(let F=0;F<a;F++){let C=h[F],L=b[F];for(let E=0;E<a;E++)L[E]=F===E?C[E]+P:C[E];y[F]=-g[F]}let S=Qx(b,y,R);if(f=Math.max(f,S.condProxy),!S.singular){for(let L=0;L<a;L++)v[L]=i[L]+R[L];let F=e(v),C=eR(F);if(C<u){for(let L=0;L<a;L++)i[L]=v[L];c=F,u=C,l=Jx(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:f}}function As(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 zd(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 rR=e=>[e[0],-e[1],-e[2],-e[3]];function nR(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 oR(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 aR(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 Yd(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],f=n+i+m;if(f>=n&&f>=i&&f>=m){let h=Math.sqrt(1+f),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 p=Math.sqrt(1-n-i+m),d=.5/p;return[(o-s)*d,(l+a)*d,(u+c)*d,.5*p]}function sR(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 iR(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 cP(e){let t=Math.abs(e[0])<.6?[1,0,0]:[0,1,0],r=q(ae(e,t));return[r,ae(e,r)]}function lP(e){let t=e.hardpoints,r=q(K(t.damperChassis,t.pushrodOuter)),[n,o]=cP(r);return{top:t.damperChassis,lower0:t.pushrodOuter,axis0:r,e1:n,e2:o}}function Wd(e){let t=e.hardpoints,r=t.wheelCenter,n=q(K(t.ucaRear,t.ucaFront)),o=K(t.uprightUpper,t.ucaFront),a=X(o,n),s=K(o,U(n,a)),i=X(s,s),c=q(K(t.lcaRear,t.lcaFront)),l=K(t.uprightLower,t.lcaFront),u=Ss(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:q(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:lP(e)}:{}}}function Kt(e,t,r){let n=[t[3],t[4],t[5]],o=[t[0],t[1],t[2]],a=K(r,e.c0);return te(te(ct(n,a),e.c0),o)}function jd(e,t){return te(e.lcaFront,Gt(e.lbjRel0,e.lcaDir,t))}function Gn(e,t){return e.steerMovesRack?te(e.tieInner0,U(e.rackAxis,t)):e.tieInner0}function Ud(e,t,r,n){let o=Kt(e,t,e.lbj0),a=jd(e,r),s=o[0]-a[0],i=o[1]-a[1],c=o[2]-a[2],l,u;if(e.strut){let d=e.strut,h=[t[3],t[4],t[5]],b=K(d.top,Kt(e,t,d.lower0));l=X(b,ct(h,d.e1)),u=X(b,ct(h,d.e2))}else{let d=Kt(e,t,e.ubj0),h=K(d,e.ucaFront),b=X(h,e.ucaDir),g=K(h,U(e.ucaDir,b));l=b-e.ubjAxial0,u=(X(g,g)-e.ubjRadius2)/e.ubjRadiusRef}let m=Kt(e,t,e.tro0),f=Gn(e,n),p=(Ss(m,f)-e.tieLen2)/e.tieLenRef;return[s,i,c,l,u,p]}var Fs=e=>Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]),Rl=e=>{let t=Fs(e);return[e[0]/t,e[1]/t,e[2]/t]},uP=(e,t)=>K(e,U(t,X(e,t))),Xd=e=>Rl(ae(e,Math.abs(e[0])<.6?[1,0,0]:[0,1,0]));function mP(e,t){let r=e.ucaDir,n=te(e.ucaFront,U(r,e.ubjAxial0)),o=Math.sqrt(e.ubjRadius2),a=uP(K(e.ubj0,e.ucaFront),r),s=Fs(a)>1e-9?Rl(a):Xd(r),i=ae(r,s),c=K(e.ubj0,e.lbj0),l=X(c,c);if(!(l>1e-18))return"free";let u=K(n,t),m=X(u,u),f=As(2*o*X(s,u),2*o*X(i,u),l-m-o*o,2*o*Math.sqrt(m));if(f.free)return"free";let p=Rl(c),d=(h,b)=>{let g=te(n,te(U(s,o*h),U(i,o*b))),y=Rl(K(g,t));return{q1:oR(p,y),k:y,margin:f.margin,ok:f.ok}};return f.margin>0?[d(f.c1,f.s1),d(f.c2,f.s2)]:[d(f.c1,f.s1)]}function pP(e,t,r){let n=t.axis0,o=te(t.lower0,U(n,X(K(e.lbj0,t.lower0),n))),a=K(o,e.lbj0),s=Fs(a),i=s>1e-9?U(a,1/s):Xd(n),c=K(t.top,r),l=Fs(c);if(!(l>1e-9))return"free";let u=U(c,1/l),m=s/l,f=1-m,p=f>=0?Math.sqrt((1-m)*(1+m)):0,d=Xd(u),h=b=>{let g=b*p,y=te(U(u,g),U(d,Math.min(m,1))),R=K(U(u,Math.min(m,1)),U(d,g));return{q1:zd(Yd(R,y,ae(R,y)),rR(Yd(i,n,ae(i,n)))),k:u,margin:f,ok:f>=0}};return f>0?[h(1),h(-1)]:[h(1)]}function dP(e,t,r,n){let{k:o}=n,a=nR(n.q1,K(e.tro0,e.lbj0)),s=X(a,o),i=K(a,U(o,s)),c=Fs(i);if(!(c>1e-9))return"free";let l=U(i,1/c),u=ae(o,l),m=te(t,U(o,s)),f=K(m,r),p=X(f,f),d=As(2*c*X(f,l),2*c*X(f,u),e.tieLen2-p-c*c,2*c*Math.sqrt(p));if(d.free)return"free";let h=(g,y)=>({q:zd(aR(o,g,y),n.q1)});return{roots:d.margin>0?[h(d.c1,d.s1),h(d.c2,d.s2)]:[h(d.c1,d.s1)],margin:d.margin,ok:d.ok}}function cR(e,t,r,n=[0,0,0,0,0,0]){let o=jd(e,t),a=Gn(e,r),s=sR([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?pP(e,e.strut,o):mP(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=dP(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:R}of b.roots){let k=i(R);y&&(!l||k>l.near)&&(l={q:R,margin:g,near:k}),!y&&(!u||k>u.near)&&(u={q:R,margin:g,near:k})}}let{q:m,margin:f}=l??u,p=iR(m),d=K(K(o,e.c0),ct(p,K(e.lbj0,e.c0)));return{x:[d[0],d[1],d[2],p[0],p[1],p[2]],converged:l!==null,margin:f,free:!1}}function uR(e){let t=q(K(e.rockerPivotB,e.rockerPivotA));return{pivotA:e.rockerPivotA,axis:t,rprRel0:K(e.rockerToPushrod,e.rockerPivotA),rdmRel0:K(e.rockerToDamper,e.rockerPivotA),damperChassis:e.damperChassis,rodLen2:Ss(e.pushrodOuter,e.rockerToPushrod),damperLen0:Me(e.rockerToDamper,e.damperChassis)}}var fP=(e,t)=>te(e.pivotA,Gt(e.rprRel0,e.axis,t)),qd=(e,t)=>te(e.pivotA,Gt(e.rdmRel0,e.axis,t));function ra(e,t){return{pushrod:fP(e,t),damper:qd(e,t)}}function mR(e,t,r=0){let n=X(e.rprRel0,e.axis),o=K(e.rprRel0,U(e.axis,n)),a=ae(e.axis,o),s=K(te(e.pivotA,U(e.axis,n)),t),i=X(o,o),c=X(s,s),l=As(2*X(s,o),2*X(s,a),e.rodLen2-c-i,2*Math.sqrt(i*c));if(l.free){let p=Math.abs(e.rodLen2-c-i)<=1e-9*e.rodLen2;return{phi:r,damperLength:Me(qd(e,r),e.damperChassis),converged:p,margin:0}}let u=lR(Math.atan2(l.s1,l.c1),r),m=lR(Math.atan2(l.s2,l.c2),r),f=Math.abs(m-r)<Math.abs(u-r)?m:u;return{phi:f,damperLength:Me(qd(e,f),e.damperChassis),converged:l.ok,margin:l.margin}}function lR(e,t){let r=2*Math.PI;return e+r*Math.round((t-e)/r)}function pR(e,t,r,n){return te(t,ct(U(q(r),n),K(e,t)))}function dR(e,t,r,n){let o=q(n),a=f=>{let p=K(f,r);return K(p,U(o,X(p,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,X(s,i)/(c*l))),m=X(ae(s,i),o)/(c*l);return Math.atan2(m,u)}function fR(e,t,r,n){return te(t,ct(U(q(r),n),K(e,t)))}var vl=180/Math.PI,hP=(e,t,r)=>Math.max(t,Math.min(r,e)),hR=[NaN,NaN,NaN];function ws(e){let t=q(e.spinAxis),r=q(K(e.uprightUpper,e.uprightLower)),n=-Math.asin(hP(t[2],-1,1))*vl,o=Math.atan2(t[0],t[1])*vl,a=Math.atan2(-r[0],r[2])*vl,s=Math.atan2(-r[1],r[2])*vl,i=q(te([0,0,-1],U(t,t[2]))),c=te(e.wheelCenter,U(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,f=w=>te(u,U(r,(w-u[2])/r[2])),p=m?f(l[2]):hR,d=m?f(e.wheelCenter[2]):hR,h=l[1]-p[1],b=p[0]-l[0],g=q(ae(t,[0,0,1])),y=ae([0,0,1],g),R=K(l,p),k=X(R,y),v=-X(R,g),x=e.wheelCenter[1]-d[1],M=d[0]-e.wheelCenter[0],A=qx(e.tieOuter,u,r);return{camber:n,toe:o,caster:a,kpi:s,scrubRadius:h,mechanicalTrail:b,scrubAtWheel:k,trailAtWheel:v,kingpinOffset:x,casterOffset:M,steeringArm:A,contactPatch:l,kingpinGround:p,kingpinAtHub:d}}function nt(e){return{corner:e,inv:Wd(e),rocker:uR(e.hardpoints)}}var bP=[20,20,20,.2,.2,.2];function gR(e,t,r,n=[0,0,0,0,0,0]){let o=cR(e,t,r,n);if(!o.free)return o;let a=gP(e,t,r,n);return{x:a.x,converged:a.converged,margin:0}}function gP(e,t,r,n=[0,0,0,0,0,0]){return tR(o=>Ud(e,o,t,r),n,{scales:bP,tol:1e-10,maxIter:40})}var yP=.01,kl=1.2,bt=e=>e.ok?e.state:null,lt=e=>e.ok?e.state:e.nearest;function ge(e,t,r,n,o){let a=0,s=Oe(e,a,r,n,o);if(Math.abs(s.travel-t)<1e-4)return bR(s,t,!1);let c=(Oe(e,.02,r,Qd(s),o).travel-s.travel)/.02;(!Number.isFinite(c)||Math.abs(c)<1e-6)&&(c=1);let l=f=>Math.max(-kl,Math.min(kl,f)),u=l((t-s.travel)/c),m=Oe(e,u,r,Qd(s),o);for(let f=0;f<12&&!(Math.abs(m.travel-t)<1e-4);f++){let p=m.travel-s.travel,d=Math.abs(p)<1e-9?u:u-(m.travel-t)*((u-a)/p);a=u,s=m,u=l(d),m=Oe(e,u,r,Qd(s),o)}return bR(m,t,Math.abs(u)===kl)}function bR(e,t,r){let n=e.travel-t,o=Math.abs(n)<=yP,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 Qd(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 xP(e,t,r,n,o){switch(e){case"upright":return Kt(t,r,o.pushrodOuter);case"upperArm":{let a=Kt(t,r,t.ubj0),s=dR(t.ubj0,a,t.ucaFront,t.ucaDir);return fR(o.pushrodOuter,t.ucaFront,t.ucaDir,s)}default:return pR(o.pushrodOuter,t.lcaFront,t.lcaDir,n)}}function Oe(e,t,r,n,o){let{inv:a,corner:s}=e,i=n?.q??[0,0,0,0,0,0],c=gR(a,t,r,i),l=c.x,u=[l[3],l[4],l[5]],m={t:[l[0],l[1],l[2]],omega:u},f=s.hardpoints,p=s.config,d=a.strut,h=d?d.top:Kt(a,l,f.uprightUpper),b=Kt(a,l,f.uprightLower),g=Kt(a,l,f.tieOuter),y=Kt(a,l,f.wheelCenter),R=q(ct(u,p.spinAxis)),k=xP(d?"upright":p.pushrodAttach,a,l,t,f),v=d?d.top:f.damperChassis,x=d||p.actuation==="direct"?{phi:0,damperLength:Me(k,v),converged:!0,margin:1}:mR(e.rocker,k,n?.phi??0),M=ws({uprightUpper:h,uprightLower:b,wheelCenter:y,spinAxis:R,tieOuter:g,loadedRadius:o?.loadedRadius??p.loadedRadius,patchShift:o?.patchShift});return{pose:m,beta:t,travel:l[2],steer:r,points:{uprightUpper:h,uprightLower:b,tieOuter:g,wheelCenter:y,pushrodOuter:k,spinAxis:R,contactPatch:M.contactPatch,kingpinGround:M.kingpinGround,kingpinAtHub:M.kingpinAtHub,rockerAngle:x.phi,damperLength:x.damperLength},metrics:{camber:M.camber,toe:M.toe,caster:M.caster,kpi:M.kpi,scrubRadius:M.scrubRadius,mechanicalTrail:M.mechanicalTrail,scrubAtWheel:M.scrubAtWheel,trailAtWheel:M.trailAtWheel,kingpinOffset:M.kingpinOffset,casterOffset:M.casterOffset,steeringArm:M.steeringArm,damperLength:x.damperLength},converged:c.converged&&x.converged,margin:Math.min(c.margin,x.margin)}}var na=e=>e==="FL"||e==="FR"?"front":"rear",xR=e=>e==="FL"||e==="RL"?"left":"right";function Ve(e,t){return e.corners?.[t]??RP(e[na(t)],xR(t))}function RR(e){let t=e.config.springSplit;return e.config.actuation==="decoupled"||t===void 0||!Number.isFinite(t)||Math.abs(t)>=1?0:t}var yR=new WeakMap;function RP(e,t){let r=RR(e);if(r===0)return e;let n=yR.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)},yR.set(e,n)}return n[t]}var lr=["FL","FR","RL","RR"],kt=e=>2*e.hardpoints.wheelCenter[1],Ht=(e,t)=>t?kt(Ve(e,"FL"))/2+kt(Ve(e,"FR"))/2:kt(Ve(e,"RL"))/2+kt(Ve(e,"RR"))/2;function ze(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 Lt(e,t){return[t.axleX+e[0],t.sideSign*e[1],e[2]]}function Lr(e,t){return[e[0],t.sideSign*e[1],e[2]]}function pn(e){return e.frontAxleX-e.wheelbase/2}function Zd(e,t,r){return t[2]+e.heave+(t[0]-r)*Math.sin(e.pitch)-t[1]*Math.sin(e.roll)}function dn(e,t,r,n){let o=ze(e,t),a=(n?Ht(n,o.isFront):o.isFront?t.trackFront:t.trackRear)/2,s=o.sideSign*a,i=o.axleX-pn(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 vP={travelMin:-40,travelMax:40,steps:41,steer:0};function Cs(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 Ye(e,t={}){let r={...vP,...t},n=nt(e);return oa(n,r)}function oa(e,t){let r=t.steer,n=.01,o=Oe(e,n,r),a=Oe(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=Oe(e,0,r);u.push({beta:0,travel:m.travel,warm:Cs(m),converged:m.converged});let f=Cs(m);for(let R=1;R<=l;R++){let k=c*R/l,v=Oe(e,k,r,f);f=Cs(v),u.push({beta:k,travel:v.travel,warm:f,converged:v.converged})}f=Cs(m);for(let R=1;R<=l;R++){let k=-c*R/l,v=Oe(e,k,r,f);f=Cs(v),u.push({beta:k,travel:v.travel,warm:f,converged:v.converged})}u.sort((R,k)=>R.beta-k.beta);let p=u[u.length-1].travel>=u[0].travel,d=!1;for(let R=1;R<u.length;R++){let k=u[R].travel-u[R-1].travel;(p&&k<-1e-6||!p&&k>1e-6)&&(d=!0)}let h=u.filter(R=>R.converged).map(R=>R.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 R=0;R<t.steps;R++){let k=t.steps===1?t.travelMin:t.travelMin+(t.travelMax-t.travelMin)*R/(t.steps-1),v=kP(u,k,p),x=MP(u,v);y.push(Oe(e,v,r,x))}return SP(y,e.corner.config.actuation==="decoupled"?0:e.corner.config.springRate),{samples:y,covered:g,reach:b,fold:d,unconverged:y.filter(R=>!R.converged).length}}function kP(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 MP(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 Jd(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 SP(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=Jd(n,r,s),c=Jd(o,r,s),l=-Jd(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 Ml=e=>e!==void 0&&Number.isFinite(e)&&e>0;function AP(e){return e&&Ml(e.helperRate)&&Ml(e.helperTravel)?{rate:e.helperRate,travel:e.helperTravel}:null}function ef(e,t,r){let n=t/e;return r?n+Math.min(t/r.rate,r.travel):n}function Ts(e,t,r,n){if(!(e>0)||!Number.isFinite(e)||!(t>0)||!Number.isFinite(t))return null;let o=AP(n),a=-ef(e,t,o),s=aa(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 aa(e,t){if(!Number.isFinite(e))return{droop:null,bump:null};let r=Ml(t?.extended)&&t.extended>e?t.extended:null,n=r!==null&&Ml(t?.stroke)?r-t.stroke:null;return{droop:r!==null?e-r:null,bump:n!==null&&n<e?e-n:null}}function tf(e,t){if(!(e>0)||!Number.isFinite(e))return null;let r=aa(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 FP(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=ef(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 wP(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=ef(r,n,o)+t;return a<=0?0:a>=o.rate*o.travel/r+o.travel?r:r*o.rate/(r+o.rate)}function sa(e,t){let r=FP(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 rf(e,t){let r=wP(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 nf(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 Sl={min:-60,max:60,steps:61},of=e=>({travel:[e.min,e.max],force:[0,0],motionRatio:[0,0],spring:null}),vR=new WeakMap;function CP(e,t){let r=vR.get(e.corner);r||vR.set(e.corner,r=new Map);let n=`${t.min}|${t.max}|${t.steps}`,o=r.get(n);return o||r.set(n,o=oa(e,{travelMin:t.min,travelMax:t.max,steps:t.steps,steer:0})),o}function Ls(e,t,r=Sl,n=e.corner.config.coilover){let o=e.corner.config;if(o.actuation==="decoupled")return of(r);let a=CP(e,r),s=PP(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 of(r);let c=DP(i,0);if(!(Math.abs(c.mr)>1e-6))return of(r);let l=t/c.mr,u=Ts(s,l,c.L,n),m=u?TP(i,nf(u).map(h=>c.L-h)):i,f=m.map(h=>(u?sa(u,c.L-h.L):l+s*(c.L-h.L))*h.mr-t),p=h=>h===null?null:m.find(b=>b.L===c.L-h)?.t??null,d=u?nf(u).map(p).filter(h=>h!==null):[];return{travel:m.map(h=>h.t),force:f,motionRatio:m.map(h=>h.mr),spring:{rate:s,preload:l,length0:c.L,law:u},...u?{stops:{droop:p(u.droop),bump:p(u.bump)}}:{},...d.length?{kinks:d}:{},length:m.map(h=>h.L)}}function af(e,t){if(!e.spring)return null;let r=e.travel.length,n=e.length;if(n&&n.length===r&&r>=2){let s=ur(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+=(Ps(e,i)+Ps(e,c))/2*(c-i)}return a}function TP(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 PP(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:LP(e,n,r);return!(o>0)||!Number.isFinite(o)?t:t*o/(t+o)}function LP(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=ra(e.rocker,n.points.rockerAngle),s=q(K(o.rockerPivotB,o.rockerPivotA)),i=(m,f)=>Math.abs(X(s,ae(K(m,o.rockerPivotA),q(K(f,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 Ps(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.motionRatio[0];let n=ur(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 Dr(e,t,r){if(!e.spring)return Qt(e,t);let{rate:n,preload:o,length0:a,law:s}=e.spring,i=Ps(e,0),c=a-r;return(s?sa(s,c):o+n*c)*Ps(e,t)-o*i}function DP(e,t){let r=ur(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 ur(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 Qt(e,t){let r=e.travel.length;if(r===0)return 0;if(r===1)return e.force[0];let n=ur(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 ia(e,t){let r=e.travel.length;if(r<3)return Ds(e,t);let n=ur(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 Ds(e,t){if(e.travel.length<2)return 0;let n=ur(e.travel,t);return(e.force[n+1]-e.force[n])/(e.travel[n+1]-e.travel[n])}function Ee(e,t,r){let n=e.hardpoints;switch(t.attach){case"upright":{let o=K(t.outer,n.wheelCenter);return te(te(ct(r.pose.omega,o),n.wheelCenter),r.pose.t)}case"lowerArm":{let o=q(K(n.lcaRear,n.lcaFront));return te(n.lcaFront,ct(U(o,r.beta),K(t.outer,n.lcaFront)))}case"rocker":{let o=q(K(n.rockerPivotB,n.rockerPivotA));return te(n.rockerPivotA,Gt(K(t.outer,n.rockerPivotA),o,r.points.rockerAngle))}}}function fn(e,t,r){return e.config.actuation==="decoupled"&&t.attach==="rocker"&&r==="coil"}function sf(e,t,r){return fn(e,t,r)?[t.inner[0],-t.inner[1],t.inner[2]]:t.inner}function ca(e,t,r){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return cf(e,t,r.kind,Ye(e,{travelMin:n,travelMax:o,steps:a}).samples)}function cf(e,t,r,n){let o=q(K(t.outer,sf(e,t,r))),a=[],s=[],i=t.outer;for(let p of n)a.push(p.travel),s.push(X(K(Ee(e,t,p),i),o));let c=a.length,l=new Array(c).fill(0);for(let p=0;p<c;p++){let d=Math.max(0,p-1),h=Math.min(c-1,p+1),b=a[h]-a[d];l[p]=b!==0?(s[h]-s[d])/b:0}let u=l[0];for(let p=1;p<c;p++)if(a[p]>=0){let d=a[p]-a[p-1],h=d!==0?(0-a[p-1])/d:0;u=l[p-1]+h*(l[p]-l[p-1]);break}let m=l.filter(p=>Math.abs(p)>1e-9).map(Math.sign),f=m.length>0&&m.some(p=>p!==m[0]);return{travel:a,ratio:l,linkTravel:s,atDesign:u,reverses:f}}function lf(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 uf(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 Es=e=>e.mount??{kind:"rockerToRocker"},AR=e=>[e[0],0,e[2]],EP=e=>2*Math.abs(e[1]),IP=(e,t)=>Math.hypot(e[0]-t[0],e[2]-t[2]);function Fl(e,t){return t.kind==="chassis"?IP(e,t.anchor):EP(e)}function Is(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 Kn(e,t,r={}){let n=r.travelMin??-40,o=r.travelMax??40,a=r.steps??21;return mf(e,t,Ye(e,{travelMin:n,travelMax:o,steps:a}).samples)}function mf(e,t,r){let n=Es(t),o=d=>Ee(e,{...t,inner:t.outer},r[d]),a=[],s=[],i=[];for(let d=0;d<r.length;d++)a.push(r[d].travel),i.push(Fl(o(d),n));let c=MR(a,i,0);for(let d of i)s.push(c-d);let l=a.length,u=new Array(l).fill(0);for(let d=0;d<l;d++){let h=Math.max(0,d-1),b=Math.min(l-1,d+1),g=a[b]-a[h];u[d]=g!==0?(s[b]-s[h])/g:0}let m=kR(a,20),f=kR(a,-20),p=Is(o(m),o(f),n);return{travel:a,ratio:u,springTravel:s,atDesign:MR(a,u,0),installedLength:c,rollSensitivity:c-p}}function kR(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 MR(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 pf(e,t,r){let n={outer:t.outer,attach:t.attach},o=Ye(e,{travelMin:-5,travelMax:5,steps:3}),a=d=>AR(Ee(e,{...n,inner:n.outer},o.samples[d])),s=a(1),i=a(2),c=a(0),l=i[0]-c[0],u=i[2]-c[2],m=Math.hypot(l,u),f=m>1e-9?[l/m,u/m]:[0,1],p=r??Math.max(80,2*Math.abs(t.outer[1])*.5);return[s[0]+f[0]*p,0,s[2]+f[1]*p]}function df(e,t){let r=e.hardpoints,n=r.rockerPivotA,o=SR(Al(r.rockerPivotB,r.rockerPivotA)),a=Math.max(30,.6*FR(Al(r.rockerToDamper,n))),s=Al(r.rockerToDamper,n),i=SR(Al(s,_P(o,NP(s,o)))),c=OP(o,i),l=null,u=-1/0;for(let m=0;m<360;m+=10){let f=m*Math.PI/180,d={outer:[n[0]+a*(Math.cos(f)*i[0]+Math.sin(f)*c[0]),n[1]+a*(Math.cos(f)*i[1]+Math.sin(f)*c[1]),n[2]+a*(Math.cos(f)*i[2]+Math.sin(f)*c[2])],attach:"rocker"},h=t==="chassis"?{...d,mount:{kind:"chassis",anchor:pf(e,d)}}:d,b;try{b=Kn(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 Al=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],_P=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],NP=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],FR=e=>Math.hypot(e[0],e[1],e[2]),SR=e=>{let t=FR(e)||1;return[e[0]/t,e[1]/t,e[2]/t]},OP=(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 ff=.001,VP=e=>({outer:e.outer,inner:e.outer,attach:e.attach}),IR=(e,t,r)=>(Fl(e.at0,t)-Fl(r,t))/2,BP=(e,t)=>X(K(t,e.pickup.at0),e.axis);function hf(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 wR(e,t){let r=[0,1,2].map(n=>hf(e,t.map(o=>o[n])));return t.map((n,o)=>[r[0][o],r[1][o],r[2][o]])}function bf(e){return{travel:e,heave:e.map(t=>t/2),heaveRatio:e.map(()=>.5),roll:[...e],rollRatio:e.map(()=>1)}}function CR(e,t,r,n){let o=e.corner;if(!t.heave&&!t.roll)return{side:bf([n.min,n.max]),pickups:{}};let a=lt(ge(e,0,0)),s={};if(t.heave&&r){let h=VP(t.heave);s.heave={corner:o,link:h,at0:Ee(o,h,a)}}if(t.roll){let h=t.roll;s.roll={pickup:{corner:o,link:h,at0:Ee(o,h,a)},axis:q(K(h.outer,sf(o,h,t.rollKind??"coil")))}}let i=t.roll&&fn(o,t.roll,t.rollKind??"coil")?{near:t.roll,far:{...t.roll,outer:t.roll.inner}}:null,c=oa(e,{travelMin:n.min,travelMax:n.max,steps:n.steps,steer:0}),l=[],u=[],m=[],f=[],p=[];for(let h of c.samples)!h.converged||l.length>0&&h.travel<=l[l.length-1]+1e-6||(l.push(h.travel),u.push(s.heave&&r?IR(s.heave,r,Ee(o,s.heave.link,h)):h.travel/2),m.push(s.roll?BP(s.roll,Ee(o,s.roll.pickup.link,h)):h.travel),i&&(f.push(Ee(o,i.near,h)),p.push(Ee(o,i.far,h))));if(l.length<2)return{side:bf([n.min,n.max]),pickups:{}};let d={travel:l,heave:u,heaveRatio:hf(l,u),roll:m,rollRatio:hf(l,m)};return i&&(d.eyes={near:f,nearRatio:wR(l,f),far:p,farRatio:wR(l,p)}),{side:d,pickups:s}}function wl(e,t,r){let n=ur(e,r);return t[n]+(r-e[n])/(e[n+1]-e[n])*(t[n+1]-t[n])}function TR(e,t,r){let n=ur(e,r);return(t[n+1]-t[n])/(e[n+1]-e[n])}function Be(e,t){return{h:wl(e.travel,e.heave,t),dh:wl(e.travel,e.heaveRatio,t),ddh:TR(e.travel,e.heaveRatio,t),r:wl(e.travel,e.roll,t),dr:wl(e.travel,e.rollRatio,t),ddr:TR(e.travel,e.rollRatio,t)}}function PR(e,t,r,n){let o=ur(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 gf=(e,t)=>Math.hypot(e[0]-t[0],e[1]+t[1],e[2]-t[2]);function yf(e,t){let r=e.side[0].eyes,n=e.side[1].eyes;if(!r||!n)return null;let o=PR(e.side[0].travel,r.near,r.nearRatio,t[0]),a=PR(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]],f=X(c,l),p=X(c,u),d=(X(l,u)-f*p)/i;return{L:i,dL:[f,p],ddL:[[(X(l,l)-f*f)/i+X(c,o.dd),d],[d,(X(u,u)-p*p)/i+X(c,m)]]}}var _R=(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,$P=(e,t)=>e.bump!==null&&t>e.bump||e.droop!==null&&t<e.droop?e.rate:0;function _s(e,t,r,n,o=0){let a=e.rollStop;if(!a)return r;let s=yf(e,t);if(!s)return r;let i=_R(a,a.length0-(n??s.L+o));return i===0?r:[r[0]-i*s.dL[0],r[1]-i*s.dL[1]]}function Cl(e,t){let r=bf(e.travel);return t==="heave"?{...e,heave:r.heave,heaveRatio:r.heaveRatio}:{...e,roll:r.roll,rollRatio:r.rollRatio}}var Tl=(e,t)=>e?e.law?sa(e.law,t):e.preload+e.rate*t:0,LR=(e,t)=>e?e.law?rf(e.law,t):e.rate:0;function Ns(e,t,r,n,o){let a=Tl(e.heave,n),s=Tl(e.roll,o);return[a*t.dh+s*t.dr,a*r.dh-s*r.dr]}var DR=(e,t)=>Be(e[0],t).h+Be(e[1],t).h;function GP(e,t){let r=e.gap>0?DR(t,e.gap):0;return e.bothWays?{free:r,pull:e.gap>0?DR(t,-e.gap):0}:{free:r,pull:null}}function KP(e,t,r){let n={...t,outer:t.inner},o=(u,m)=>{let f=bt(ge(e[0],u,0)),p=bt(ge(e[1],m,0));if(!f||!p)return NaN;let d=Ee(e[0].corner,t,f),h=Ee(e[1].corner,n,p);return Math.hypot(d[0]-h[0],d[1]+h[1],d[2]-h[2])},a=1,s=o(0,0),i=o(-a,a)-o(a,-a),c=Be(r[0],a).r-Be(r[1],-a).r-(Be(r[0],-a).r-Be(r[1],a).r),l=i/c;return Number.isFinite(s)&&s>0&&Number.isFinite(l)&&Math.abs(l)>ff?{length0:s,scale:l}:null}function NR(e,t,r,n=Sl){let o=r.heave?Es(r.heave):void 0,a=CR(e[0],r,o,n),s=e[1].corner===e[0].corner?a:CR(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=r.carriesLoad?void 0:r.heaveSeat,m=u?u.rate:(t[0].heaveRate+t[1].heaveRate)/2,f=(t[0].arbRate+t[1].arbRate)/2,p=i.map(F=>Be(F,0));c&&!(Math.abs(p[0].dh+p[1].dh)>ff)&&(i=[Cl(i[0],"heave"),Cl(i[1],"heave")],c=!1),l&&!(Math.abs(p[0].dr+p[1].dr)>ff)&&(i=[Cl(i[0],"roll"),Cl(i[1],"roll")],l=!1),p=i.map(F=>Be(F,0));let d=p[0].dh+p[1].dh,h=p[0].dr+p[1].dr,b=m>0?2*m/(d*d):0,g=f>0?2*f/(h*h):0,y=0,R=0;if(r.carriesLoad){let F=[t[0].springLoad,t[1].springLoad];if(b>0&&g>0){let C=-p[0].dh*p[1].dr-p[1].dh*p[0].dr;Math.abs(C)>1e-12&&(y=(-F[0]*p[1].dr-F[1]*p[0].dr)/C,R=(p[0].dh*F[1]-p[1].dh*F[0])/C)}else b>0?y=(F[0]+F[1])/d:g>0&&(R=(F[0]-F[1])/h)}let k={};if(c&&o){let F=[a.pickups.heave,s.pickups.heave];k.heave={pickups:F,mount:o,span0:Is(F[0].at0,F[1].at0,o)}}let v=k.heave?k.heave.span0:NaN,x=k.heave?r.coilover:void 0,M=r.carriesLoad?Ts(b,y,v,x):u?tf(b,{...GP(u,i),length0:v,coilover:x}):null,A=b>0?{rate:b,preload:y,...M?{law:M}:{}}:null;if(l&&(k.roll={pickups:[a.pickups.roll.pickup,s.pickups.roll.pickup],axes:[a.pickups.roll.axis,s.pickups.roll.axis]},r.roll&&fn(e[0].corner,r.roll,r.rollKind??"coil"))){let F=KP(e,r.roll,i);F&&(k.roll.unit=F)}let w=g>0?{rate:g,preload:R}:null,T={side:i,heave:A,roll:w,force0:[0,0],carriesLoad:r.carriesLoad,read:k},P=k.roll?.unit,S=P&&g>0&&i[0].eyes&&i[1].eyes?aa(P.length0,r.rollCoilover):null;return P&&S&&(S.droop!==null||S.bump!==null)&&(T.rollStop={length0:P.length0,rate:1e3*g/(P.scale*P.scale),...S}),T.force0=_s(T,[0,0],Ns(T,p[0],p[1],p[0].h+p[1].h,p[0].r-p[1].r)),T}function Os(e,t,r){let n=Be(e.side[0],t[0]),o=Be(e.side[1],t[1]),a=r?_s(e,t,Ns(e,n,o,n.h+o.h+r.heave,n.r-o.r+r.roll),void 0,r.unit):_s(e,t,Ns(e,n,o,n.h+o.h,n.r-o.r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function xf(e,t,r){let n=Be(e.side[0],t[0]),o=Be(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=LR(e.heave,a),c=LR(e.roll,s),l=Tl(e.heave,a),u=Tl(e.roll,s),m=i*n.dh*o.dh-c*n.dr*o.dr,f=[[i*n.dh*n.dh+l*n.ddh+c*n.dr*n.dr+u*n.ddr,m],[m,i*o.dh*o.dh+l*o.ddh+c*o.dr*o.dr-u*o.ddr]],p=e.rollStop,d=p?yf(e,t):null;if(!p||!d)return f;let h=p.length0-(r?d.L+r.unit:d.L),b=$P(p,h);if(b===0)return f;let g=_R(p,h),y=(k,v)=>b*d.dL[k]*d.dL[v]-g*d.ddL[k][v],R=m+y(0,1);return[[f[0][0]+y(0,0),R],[R,f[1][1]+y(1,1)]]}function Rf(e,t,r){let n=xf(e,t);return n[r][0]+n[r][1]}function HP(e,t,r){let n=e.read.heave;if(!n)return Be(e.side[0],t[0]).h+Be(e.side[1],t[1]).h;let[o,a]=n.pickups;return n.span0-Is(Ee(o.corner,o.link,r[0]),Ee(a.corner,a.link,r[1]),n.mount)}function zP(e,t,r){let n=e.read.roll;if(!n)return Be(e.side[0],t[0]).r-Be(e.side[1],t[1]).r;let o=a=>X(K(Ee(n.pickups[a].corner,n.pickups[a].link,r[a]),n.pickups[a].at0),n.axes[a]);return o(0)-o(1)}function YP(e,t){let r=e.read.roll;if(!e.rollStop||!r)return;let[n,o]=r.pickups;return gf(Ee(n.corner,n.link,t[0]),Ee(o.corner,{...o.link,outer:o.link.inner},t[1]))}function Vs(e,t,r){let n=Be(e.side[0],t[0]),o=Be(e.side[1],t[1]),a=_s(e,t,Ns(e,n,o,HP(e,t,r),zP(e,t,r)),YP(e,r));return[a[0]-e.force0[0],a[1]-e.force0[1]]}function vf(e,t,r,n){let o=Be(e.side[0],r),a=Be(e.side[1],r),s=e.read.heave,i=s?.pickups[t],c=s&&i&&n?2*IR(i,s.mount,Ee(i.corner,i.link,n)):o.h+a.h,l=e.rollStop&&n?e.read.roll?.pickups[t]:void 0,u=l&&n?gf(Ee(l.corner,l.link,n),Ee(l.corner,{...l.link,outer:l.link.inner},n)):void 0;return _s(e,[r,r],Ns(e,o,a,c,n?0:o.r-a.r),u)[t]-e.force0[t]}function kf(e,t,r,n){let o=ia(e,r[n]);return t?.carriesLoad?o+Rf(t,r,n):o}function OR(e,t){return Be(e.side[0],t[0]).h+Be(e.side[1],t[1]).h}function VR(e,t){return yf(e,t)?.L??null}var Mf=e=>e==="FR"||e==="RR"?1:0,Pl=(e,t)=>e.elements?.[t==="FL"||t==="FR"?"front":"rear"]??null;var BR=e=>Number.isFinite(e)&&e>0?1/e:0;var $R=(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},WP=(e,t)=>[e[0][0]*t[0]+e[0][1]*t[1],e[1][0]*t[0]+e[1][1]*t[1]],GR=1e-8,jP=40;function UP(e,t,r,n){return{force:(s,i)=>{if(r){let u=Os(r,s,n);return[Qt(t[0],s[0])+i[0]+u[0],Qt(t[1],s[1])+i[1]+u[1]]}let c=(s[0]+s[1])/2,l=(s[0]-s[1])/2;return[Qt(t[0],s[0])+i[0]+e[0].heaveRate*c+e[0].arbRate*l,Qt(t[1],s[1])+i[1]+e[1].heaveRate*c-e[1].arbRate*l]},stiffness:(s,i=Ds)=>{if(r){let c=xf(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 la(e,t,r,n,o,a=[0,0],s=[0,0],i=null,c){let l=[BR(r[0].tyreRate),BR(r[1].tyreRate)],u=[r[0].staticLoad,r[1].staticLoad],m=UP(r,n,i,c),f=C=>m.force(C,a),p=m.stiffness([0,0]),d=[l[0]>0?l[0]:1/Math.max(1,Math.abs(p[0][0])),l[1]>0?l[1]:1/Math.max(1,Math.abs(p[1][1]))],h=(C,L)=>{let E=L===1?f(C):m.force(C,[a[0]*L,a[1]*L]),D=[E[0]+s[0]*L,E[1]+s[1]*L],N=[C[0]+t[0]*L+D[0]*l[0]-e[0]*L,C[1]+t[1]*L+D[1]*l[1]-e[1]*L],O=[d[0]*(u[0]+D[0]),d[1]*(u[1]+D[1])],z=[O[0]<N[0],O[1]<N[1]];return{f:D,on:N,off:O,lifted:z,r:[Math.min(N[0],O[0]),Math.min(N[1],O[1])]}},b=(C,L)=>[L[0]?[d[0]*C[0][0],d[0]*C[0][1]]:[1+C[0][0]*l[0],C[0][1]*l[0]],L[1]?[d[1]*C[1][0],d[1]*C[1][1]]:[C[1][0]*l[1],1+C[1][1]*l[1]]],g=C=>Math.max(Math.abs(C[0]),Math.abs(C[1])),y=(C,L)=>{let E=[C[0],C[1]],D=h(E,L),N=!1,O=0;for(;O<jP;O++){if(g(D.r)<GR){N=!0;break}let z=$R(b(m.stiffness(E),D.lifted),[-D.r[0],-D.r[1]]);if(!z)break;let I=1,_=[E[0]+z[0],E[1]+z[1]],B=h(_,L);for(let V=0;V<8&&g(B.r)>g(D.r);V++)I/=2,_=[E[0]+I*z[0],E[1]+I*z[1]],B=h(_,L);E=_,D=B}return!N&&g(D.r)<GR&&(N=!0),{t:E,b:D,converged:N,it:O}},R=y(o?[o[0],o[1]]:[e[0]-t[0],e[1]-t[1]],1),k=R.it;if(!R.converged){let C=0,L=[0,0],E=.25;for(;C<1&&E>=1/256;){let D=Math.min(1,C+E),N=y(L,D);k+=N.it,N.converged?(C=D,L=N.t,D===1&&(R=N)):E/=2}}let{t:v,b:x,converged:M}=R,A=x.lifted,w=[A[0]?-u[0]:x.f[0],A[1]?-u[1]:x.f[1]],T=[A[0]?Math.max(0,x.on[0]):0,A[1]?Math.max(0,x.on[1]):0],P=m.stiffness(v,ia),S=b(P,A);return{t:v,dF:w,lifted:A,clearance:T,converged:M,iterations:k,respond:(C,L,E=[0,0])=>{let D=[A[0]?-d[0]*E[0]:C[0]-L[0]-E[0]*l[0],A[1]?-d[1]*E[1]:C[1]-L[1]-E[1]*l[1]],N=$R(S,D);if(!N)return[NaN,NaN];let O=WP(P,N);return[A[0]?0:O[0]+E[0],A[1]?0:O[1]+E[1]]}}}var Hn=e=>!(Number.isFinite(e.tyreRate)&&e.tyreRate>0);function zt(e,t,r){return t?.input.corners[r].staticLoadedRadius??e}var Sf=["FL","FR","RL","RR"],zR={front:["FL","FR"],rear:["RL","RR"]},XP=512,qP=5e-4,QP=8;function Ll(e,t){let r={},n={},o=new Map;for(let s of Sf){let i=e.ctx[s],c=t.corners[s],l=c.staticLoadedRadius;n[s]=lt(ge(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=`${Sf.findIndex(p=>Ve(e.vehicle,p)===Ve(e.vehicle,s))}|${c.springLoad}|${u?`${u.extended}/${u.stroke}`:""}`,f=o.get(m);f?r[s]=f:(r[s]=u?Ls(i,c.springLoad,void 0,u):Ls(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=zR[s];a[s]=NR([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 YR(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 ZP=e=>`${e.heave}|${e.pitch}|${e.roll}|${e.steer}`;function Af(e,t,r){return{travel:r.travel,steer:r.steer,ground:r.travel,tyreDeflection:0,load:NaN,loadedRadius:zt(Ve(e.vehicle,t).config.loadedRadius,e.kc,t),lifted:!1,contactLength:0,converged:!0,rigid:!0,rideRate:NaN,wheelRateAtLoad:NaN}}var JP=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 KR(e,t,r,n){let o=zR[n],a=e.vehicle.config,s=o.map(w=>dn(w,a,r,e.vehicle)),i=[t.input.corners[o[0]],t.input.corners[o[1]]],c=t.loadCase;if(!c&&i.every(Hn))return{corners:[Af(e,o[0],s[0]),Af(e,o[1],s[1])],respond:null};let l=o.map(w=>t.curve[w]),u=t.elements?.[n]??null,m=o.map(w=>zt(Ve(e.vehicle,w).config.loadedRadius,t,w)),f=[s[0].travel+(c?.ground[o[0]]??0),s[1].travel+(c?.ground[o[1]]??0)],p=[c?.linkLoad[o[0]]??0,c?.linkLoad[o[1]]??0],d=[c?.patchShift[o[0]],c?.patchShift[o[1]]],h=[0,0],b=[0,0],g,y=la(f,h,i,l,void 0,void 0,p,u),R=[void 0,void 0],k=[!0,!0],v=[0,0],x=!1;for(let w=0;w<QP;w++){w>0&&(y=la(f,h,i,l,g,b,p,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],P=[0,0];for(let F=0;F<2;F++){let C=ge(e.ctx[o[F]],y.t[F],s[F].steer,JP(R[F]),{loadedRadius:m[F]-v[F],patchShift:d[F]}),L=lt(C);R[F]=L,k[F]=C.ok,T[F]=L.points.contactPatch[2]-t.ground0[o[F]]-y.t[F]-v[F],P[F]=Dr(l[F],y.t[F],L.points.damperLength)-Qt(l[F],y.t[F])}if(u){let F=Vs(u,y.t,[R[0],R[1]]),C=Os(u,y.t);P[0]+=F[0]-C[0],P[1]+=F[1]-C[1]}let S=Math.max(Math.abs(T[0]-h[0]),Math.abs(T[1]-h[1]),Math.abs(P[0]-b[0])/Math.max(1,i[0].tyreRate),Math.abs(P[1]-b[1])/Math.max(1,i[1].tyreRate));if(h=T,b=P,g=y.t,S<qP){x=!0;break}}let M=y.respond([1,1],[0,0]);return{corners:[0,1].map(w=>{let T=R[w];return{travel:y.t[w],steer:s[w].steer,ground:f[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:YR(m[w]-v[w],i[w].staticLoad+y.dF[w],i[w].tyreRate),converged:y.converged&&x&&k[w],rigid:!1,state:T,solved:k[w],rideRate:M[w],wheelRateAtLoad:kf(l[w],u,y.t,w)}}),respond:y.respond}}function WR(e,t){let r=e.kc,n=ZP(t),o=r.memo.get(n);if(o)return o;let a=KR(e,r,t,"front"),s=KR(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>=XP&&r.memo.clear(),r.memo.set(n,i),i}function Mt(e,t){if(!e.kc){let r={};for(let n of Sf)r[n]=Af(e,n,dn(n,e.vehicle.config,t,e.vehicle));return r}return WR(e,t).corners}function Dl(e,t,r){return e.kc?WR(e,t).respond[r]:null}function Bs(e,t,r,n=0){let o=e.kc;if(!o)return r;let a=o.input.corners[t];if(Hn(a))return r;let s=dn(t,e.vehicle.config,{heave:0,pitch:0,roll:0,steer:n},e.vehicle).steer,i=zt(Ve(e.vehicle,t).config.loadedRadius,o,t),c=o.loadCase,l=c?.linkLoad[t]??0,u=c?.patchShift[t],m=lt(ge(e.ctx[t],r,s,void 0,{loadedRadius:i,patchShift:u})),f=Pl(o,t),p=Dr(o.curve[t],r,m.points.damperLength)+(f?vf(f,Mf(t),r,m):a.heaveRate*r),h=Math.max(p+l,-a.staticLoad)/a.tyreRate;return(h===0?m:lt(ge(e.ctx[t],r,s,void 0,{loadedRadius:i-h,patchShift:u}))).points.contactPatch[2]-o.ground0[t]-(c?.ground[t]??0)}var eL=180/Math.PI,tL=[0,0,1];function rL(e,t){let r=Lr(e,t),n=U(ae(tL,r),-t.sideSign);return-Math.atan2(n[1],n[0])*eL}var jR=e=>1/Math.tan(e*Math.PI/180),UR=.05,XR=.001;function qR(e,t,r){if(!Number.isFinite(e)||!Number.isFinite(t))return NaN;if(!(Math.abs(e)<XR&&Math.abs(t)<XR))return e>0&&t>0?100*(jR(t)-jR(e))/r:NaN}function nL(e,t){let r=Ht(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=[UR,-UR].map(l=>{let{inner:u,outer:m}=a(t("FL",l).deg-n,t("FR",l).deg-o);return qR(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:f,outer:p}=a(l.deg-n,u.deg-o),d=qR(f,p,r);return{steerL:l.deg,steerR:u.deg,inner:f,outer:p,toeDiff:f-p,ackermannPct:d??i(),inside:d===void 0?null:m?"left":"right",converged:l.ok&&u.ok}}}function Ff(e,t){let r=e.vehicle.config,n={FL:ze("FL",r),FR:ze("FR",r)},o=t.travel??0,a=nL(e,(i,c)=>{let l=bt(ge(e.ctx[i],o,n[i].sideSign*c));return{deg:l?rL(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 QR=35,ZR=55,St=e=>e.rackTravel&&e.rackTravel>0?e.rackTravel:QR,wf=e=>e.rackRatio&&e.rackRatio>0?e.rackRatio:ZR;var Cf=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 JR(e,t,r,n,o){let a=ge(e,n,0,void 0,o),s=lt(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=p=>{let d=[l],h=Cf(s);for(let b=1;b<=r;b++){let g=p*(t*b)/r,y=Oe(e,s.beta,g,h,o),R=bt(ge(e,n,g,Cf(y),o));if(!R||!y.converged){i++,d.push({...d[d.length-1]});continue}d.push({steer:R.metrics.toe,camber:R.metrics.camber,lift:-(y.points.contactPatch[2]-c),contactPatch:y.points.contactPatch,spinAxis:y.points.spinAxis,yaw:-y.metrics.toe*Math.PI/180}),h=Cf(y)}return d},m=u(1),f=u(-1);return{travelMm:n,unsolved:i,centre:l,positive:m,negative:f}}function oL(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=U(K(e[a].contactPatch,e[o].contactPatch),1/s),c=q(ae(r.spinAxis,[0,0,1])),l=ae([0,0,1],c);return{longitudinal:X(i,c),lateral:X(i,l),vertical:i[2],yaw:(e[a].yaw-e[o].yaw)/s}})}function ev(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:oL(o,t)});return{travelMm:e.travelMm,inner:n(r?e.positive:e.negative),outer:n(r?e.negative:e.positive)}}function aL(e){return e.positive[1].steer-e.centre.steer<0}function sL(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:wf(e.config),innerJacobian:r.inner.jacobian,outerJacobian:r.outer.jacobian}}function Tf(e,t,r=13,n=-40,o=40,a=5,s){let i=nt(e),c=Array.from({length:r+1},(b,g)=>t*g/r),l=JR(i,t,r,0,s),u=aL(l),m=ev(l,c,u),f=Math.max(2,Math.floor(a)),p=Array.from({length:f},(b,g)=>n+(o-n)*g/(f-1));p.some(b=>Math.abs(b)<1e-9)||p.push(0),p.sort((b,g)=>b-g);let d=l.unsolved,h=p.map(b=>{if(Math.abs(b)<1e-9)return m;let g=JR(i,t,r,b,s);return d+=g.unsolved,ev(g,c,u)});return{...sL(e,c,m),...tv(l.unsolved),travelSurface:{rackMm:c,rows:h,...tv(d)}}}var tv=e=>e>0?{unsolved:e}:{};function mr(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 El(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 rv(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 zn=(e,t,r)=>e+r*(t-e);function ua(e,t,r,n,o){let a=mr(e.rackMm,e.rows[n.lo][t][r],o);if(n.lo===n.hi)return a;let s=mr(e.rackMm,e.rows[n.hi][t][r],o);return zn(a,s,n.t)}function nv(e,t,r,n){let o=El(e.rackMm,e.rows[r.lo][t].jacobian,n);if(r.lo===r.hi)return o;let a=El(e.rackMm,e.rows[r.hi][t].jacobian,n);return{longitudinal:zn(o.longitudinal,a.longitudinal,r.t),lateral:zn(o.lateral,a.lateral,r.t),vertical:zn(o.vertical,a.vertical,r.t),yaw:zn(o.yaw,a.yaw,r.t)}}function ma(e,t,r,n){let o=e.travelSurface;if(!o||o.rackMm.length<2||o.rows.length===0)return pa(e,t);let a=rv(o,r),s=rv(o,n),i=(p,d,h)=>{let b=o.rows[d.lo][p].steerDeg[h];return d.lo===d.hi?b:zn(b,o.rows[d.hi][p].steerDeg[h],d.t)},c=new Array(o.rackMm.length);for(let p=0;p<c.length;p++)c[p]=.5*(i("inner",a,p)+i("outer",s,p));let l=Math.max(0,t),u=c.length-1,m=o.rackMm[u],f=l>c[u];if(l<=c[0])m=o.rackMm[0],f=!1;else if(!f){let p=1;for(;p<c.length-1&&c[p]<l;)p++;let d=p-1,h=c[p]-c[d],b=Math.abs(h)>1e-12?(l-c[d])/h:0;m=zn(o.rackMm[d],o.rackMm[p],b)}return{innerDeg:ua(o,"inner","steerDeg",a,m),outerDeg:ua(o,"outer","steerDeg",s,m),innerCamber:ua(o,"inner","camberDeg",a,m),outerCamber:ua(o,"outer","camberDeg",s,m),innerLift:ua(o,"inner","liftMm",a,m),outerLift:ua(o,"outer","liftMm",s,m),innerJacobian:nv(o,"inner",a,m),outerJacobian:nv(o,"outer",s,m),atLock:f}}function pa(e,t){let r=e.meanDeg.length-1;return{innerDeg:mr(e.meanDeg,e.innerDeg,t),outerDeg:mr(e.meanDeg,e.outerDeg,t),innerCamber:mr(e.meanDeg,e.innerCamber,t),outerCamber:mr(e.meanDeg,e.outerCamber,t),innerLift:e.innerLift?mr(e.meanDeg,e.innerLift,t):0,outerLift:e.outerLift?mr(e.meanDeg,e.outerLift,t):0,...e.innerJacobian&&e.outerJacobian?{innerJacobian:El(e.meanDeg,e.innerJacobian,t),outerJacobian:El(e.meanDeg,e.outerJacobian,t)}:{},atLock:r>=0&&t>e.meanDeg[r]}}var iL=()=>({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 da(e,t,r=Te(e),n){let o=e.steerFront;if(!o?.innerLift||!o.outerLift||o.meanDeg.length<2||Math.abs(t)<1e-12)return iL();let a=Math.abs(t),s=t>0,i=n&&o.travelSurface?ma(o,a,s?n.FL:n.FR,s?n.FR:n.FL):null,c=i?.innerLift??mr(o.meanDeg,o.innerLift,a),l=i?.outerLift??mr(o.meanDeg,o.outerLift,a),u=s?c:l,m=s?l:c,f=.5*(u+m),p=r.rollWheelRateFront,d=r.rollWheelRateRear,h=e.trackFront,b=e.trackRear,g=p*h*h+d*b*b,y=g>0?p*h*(m-u)/g:0,R={FL:u-f+.5*h*y,FR:m-f-.5*h*y,RL:.5*b*y,RR:-.5*b*y};return{lift:{FL:u,FR:m,RL:0,RR:0},travel:R,load:{FL:p*R.FL,FR:p*R.FR,RL:d*R.RL,RR:d*R.RR},rollDeg:y===0?0:-Math.atan(y)*180/Math.PI}}function Pf(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 $s=9.81;function fa(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?Pr(e,t,r,ln(e,n,o)):$n(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 Lf(e,t,r=0,n=0,o=0){if(!e.aero?.model||t<=0)return!1;let a=Pr(e,t,r,ln(e,n,o));return a!=null&&(a.clampedRide||a.clampedAttitude)}function Yn(e){let t=e.loadFactor===void 0?e.massTotal*$s:e.massTotal*$s*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 ov(e,t=Te(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*ml(t.sprungMass,c,t.rollRateTotal),f=(m*t.frontRollStiffFrac+t.sprungFront*a+l*u)/n,p=(m*(1-t.frontRollStiffFrac)+t.sprungRear*s+l*u)/o;return{cf:f,cr:p}}function Df(e){let{cf:t,cr:r}=ov(e);return t+r>0?t/(t+r):.5}function av(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 f=u>0?1:-1,p=(f*a-c)*t;f*u>=f*p?(c=f*a,u-=p):(c+=u/t,u=0);let d=(f*s-l)*r;u!==0&&(f*u>=f*d?(l=f*s,u-=d):(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 Pe(e,t,r,n=0,o=0,a=0,s,i){return Il(e,t,r,n,o,a,s,i).loads}function Il(e,t,r,n=0,o=0,a=0,s,i){let c=Yn(e),l=Te(e),u=xl(e,n,r,ln(e,t,o),l),{cf:m,cr:f}=ov(e,l,u.height),p=m*t*$s,d=f*t*$s,h=e.massTotal*(r*$s)*u.height/e.wheelbase-u.noseLoad,b=fa(e,n,r,t,o),g=(i??da(e,a,l,s)).load,y={FL:c.FL-p-h/2+b.FL+g.FL,FR:c.FR+p-h/2+b.FR+g.FR,RL:c.RL-d+h/2+b.RL+g.RL,RR:c.RR+d+h/2+b.RR+g.RR};return av(y,e.trackFront,e.trackRear)}var Ef=Math.PI/180;function Nl(e,t){let r=8*Ef,n=0,o=0;for(let a=1;a<=90;a++){let s=a*.5,i=Math.abs(e.Fy(s*Ef,t,0));if(i>n&&(n=i,r=s*Ef,o=a),a>o+12&&i<.995*n)break}return{aPeak:r,fyPeak:n}}function sv(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 Ks=.999;function Dt(e,t,r,n,o){if(t<=0)return 0;let{aPeak:a,fyPeak:s}=o??Nl(e,t),i=Math.min(Math.abs(r),Ks*s),c=n?-1:1,l=(v,x)=>Math.abs(e.forces({Fz:t,kappa:c*v,alpha:x}).Fy),u=.3,m=u,f=l(u,a);if(f<i){let v=0,x=u,M=NaN,A=f;for(let w=0;w<9;w++){let T=.5*(v+x),P=l(T,a);P>=i?(v=T,M=P):(x=T,A=P)}Number.isNaN(M)&&(M=l(0,a)),m=M<i?0:sv(v,M,x,A,i)}if(m<=0)return 0;let p=v=>{if(i===0)return c*e.forces({Fz:t,kappa:c*v,alpha:0}).Fx;let x=0,M=a,A=NaN,w=NaN;for(let T=0;T<5;T++){let P=.5*(x+M),S=l(v,P);S<i?(x=P,A=S):(M=P,w=S)}return Number.isNaN(A)&&(A=l(v,0)),Number.isNaN(w)&&(w=l(v,a)),c*e.forces({Fz:t,kappa:c*v,alpha:sv(x,A,M,w,i)}).Fx},d=4,h=v=>m*v/d,b=[0],g=1;for(let v=1;v<=d;v++)b.push(p(h(v))),b[v]>b[g]&&(g=v);let[y,R]=g===d?[d-1,d-2]:b[g-1]>=b[g+1]?[g-1,g+1]:[g+1,g-1],k=mL(p,h(g-1),h(Math.min(d,g+1)),h(g),b[g],h(y),b[y],h(R),b[R],cL);return c*Math.max(0,k)}var cL=.01,lL=20,uL=(3-Math.sqrt(5))/2;function mL(e,t,r,n,o,a,s,i,c,l){o=-o,s=-s,c=-c;let u=r-t,m=0;for(let f=0;f<lL;f++){let p=l*Math.abs(n)+1e-10,d=.5*(t+r);if(Math.abs(n-d)<=2*p-.5*(r-t))break;let h=!0;if(Math.abs(u)>p){let y=(n-a)*(o-c),R=(n-i)*(o-s),k=(n-i)*R-(n-a)*y;R=2*(R-y),R>0&&(k=-k),R=Math.abs(R);let v=u;if(u=m,Math.abs(k)<Math.abs(.5*R*v)&&k>R*(t-n)&&k<R*(r-n)){m=k/R;let x=n+m;(x-t<2*p||r-x<2*p)&&(m=d>=n?p:-p),h=!1}}h&&(u=n>=d?t-n:r-n,m=uL*u);let b=Math.abs(m)>=p?n+m:n+(m>=0?p:-p),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 Nf(e,t){return e.model?.kind==="simple"?null:lv(e,t)}var iv=new WeakMap,If=100,cv=1.35,_f=18,pr=41,_l=41,Gs=65;function lv(e,t){let r=iv.get(e);if(r)return r;let n=Math.log(cv),o=(p,d)=>{let h=M=>Math.abs(Dt(e,p,M,d)),b=h(0),g=t.muY(p)*p,y=new Float64Array(pr),R=b>0&&g>0?Math.max(1,t.muX(p)*p/b):1;if(!(b>0)||!(g>0))y.fill(1);else{let M=[],A=[];for(let T=0;T<_l;T++){let P=Math.sin(.5*Math.PI*T/(_l-1));M.push(P),A.push(T===0?1:T===_l-1?0:Math.min(A[T-1],h(P*g)/b))}let w=_l-1;for(let T=0;T<pr;T++){let P=T/(pr-1);for(;w>0&&A[w-1]<P;)w--;let S=w>0?A[w-1]-A[w]:0;y[T]=w===0?M[0]:M[w]+(S>0?(P-A[w])/S:0)*(M[w-1]-M[w])}y[0]=1,y[pr-1]=0}let k=new Float64Array(Gs),v=M=>Math.atan2(y[M],M/(pr-1)/R),x=pr-2;for(let M=0;M<Gs;M++){let A=.5*Math.PI*M/(Gs-1),w=Math.cos(A),T=Math.sin(A);for(;x>0&&v(x)<A;)x--;let P=x/(pr-1)/R,S=y[x],F=(x+1)/(pr-1)/R,C=y[x+1],L=w*(C-S)-T*(F-P),E=Math.abs(L)>1e-12?(P*(C-S)-S*(F-P))/L:Math.hypot(P,S);k[M]=E>0?E:Math.hypot(P,S)}return{room:y,scale:R,edge:k}},a=Array.from({length:_f},(p,d)=>If*cv**d),s=a.map(p=>o(p,!1)),i=a.map(p=>o(p,!0)),c=(p,d)=>{let h=Math.min(1,Math.abs(d)*p.scale)*(pr-1),b=Math.min(pr-2,Math.floor(h));return p.room[b]+(h-b)*(p.room[b+1]-p.room[b])},l=p=>{let d=p>If?Math.log(p/If)/n:0;if(d>=_f-1)return[_f-2,1];let h=Math.floor(d);return[h,d-h]},u=(p,d,h)=>{if(h===0)return 1;let b=h<0?i:s,g=c(b[p],h);return d>0?g+d*(c(b[p+1],h)-g):g},m=(p,d,h)=>{let b=d<0?i:s,[g,y]=l(p),R=Math.atan2(Math.abs(h),Math.abs(d))/(.5*Math.PI)*(Gs-1),k=Math.min(Gs-2,Math.floor(R)),v=M=>M.edge[k]+(R-k)*(M.edge[k+1]-M.edge[k]),x=v(b[g]);return y>0?x+y*(v(b[g+1])-x):x},f={keeps(p,d){if(d===0)return 1;let[h,b]=l(p);return u(h,b,d)},atLoad(p){let[d,h]=l(p);return b=>u(d,h,b)},use(p,d,h){let b=Math.hypot(d,h);return b>0?Math.min(1,b/m(p,d,h)):0},reach:m};return iv.set(e,f),f}var pL=[["front","FL","FR"],["rear","RL","RR"]];function ha(e,t,r,n){let o={...e},a=0,s=Ks;for(let[i,c,l]of pL){let u=(k,v)=>n(i,Math.max(0,v[k])).fyPeak,m=Math.min(s,e[c]),f=Math.min(s,e[l]),p=m*u(c,r)+f*u(l,r);if(!(p>0))continue;let d=u(c,t),h=u(l,t),b=m*d+f*h,g=b>0?p/b:1/0,y=m*g,R=f*g;y<=s?R<=s||(R=s,y=d>0?(p-s*h)/d:1/0):(y=s,R=h>0?(p-s*d)/h:1/0),(!(y<=s)||!(R<=s))&&(a+=Math.max(0,p-s*(d+h)),y=Math.min(s,y),R=Math.min(s,R)),o[c]=y,o[l]=R}return{util:o,short:a}}var uv=.001,dL=1e-5,mv=100;function fL(e,t,r,n){if(!(n>uv))return r;let o=t,a=Math.abs(r-t)<mv?t+Math.sign(r-t)*mv:r;for(let s=0;s<60&&Math.abs(a-o)>dL;s++){let i=.5*(o+a);e(i)>uv?a=i:o=i}return o}function Ol(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=fL(e,t,o,e(o));return a!==o&&(n=a),a},edge:()=>n}}function Vl(e,t){let r=n=>{try{return ge(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 Of=40;function Bl(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 pv=[0,0,0];function hL(e,t){let r=q(K(e.rockerPivotB,e.rockerPivotA)),n=q(K(e.rockerToPushrod,e.pushrodOuter)),o=q(K(e.damperChassis,e.rockerToDamper)),a=Math.abs(X(r,ae(K(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(X(r,ae(K(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}function $l(e,t,r){if(e.mcpherson)return bL(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 f=q(K(n[m].c,n[m].r)),p=ae(K(n[m].r,o),f);a[0][m]=f[0],a[1][m]=f[1],a[2][m]=f[2],a[3][m]=p[0],a[4][m]=p[1],a[5][m]=p[2]}let s=ae(K(e.contactPatch,o),t),i=r??pv,c=[-t[0],-t[1],-t[2],-(s[0]+i[0]),-(s[1]+i[1]),-(s[2]+i[2])],l=cr(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]:hL(e,u[5]),condProxy:l.condProxy,singular:l.singular}}function bL(e,t,r){let n=e.wheelCenter,o=e.damperChassis,a=[{at:e.uprightLower,dir:q(K(e.lcaFront,e.uprightLower))},{at:e.uprightLower,dir:q(K(e.lcaRear,e.uprightLower))},{at:e.tieOuter,dir:q(K(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=ae(K(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=ae(K(e.contactPatch,n),t),c=r??pv,l=[-t[0],-t[1],-t[2],-(i[0]+c[0]),-(i[1]+c[1]),-(i[2]+c[2])],u=cr(s,l),m=u.x,f=[m[3],m[4],m[5]],p=q(K(o,e.pushrodOuter)),d=X(f,p),h=Math.hypot(f[0]-d*p[0],f[1]-d*p[1],f[2]-d*p[2]);return{ucaFront:NaN,ucaRear:NaN,lcaFront:m[0],lcaRear:m[1],tieRod:m[2],pushRod:u.singular?NaN:d,damper:u.singular?NaN:d,condProxy:u.condProxy,singular:u.singular,strutSide:u.singular?NaN:h,topMount:f}}function Vf(e,t){let r=q(e.spinAxis),n=ae(K(e.contactPatch,e.wheelCenter),t),o=X(n,r);return[-o*r[0],-o*r[1],-o*r[2]]}var gL=[0,0,0];function Hs(e,t,r,n){let o=e.direct?e.damperChassis:e.rockerToPushrod;if(e.mcpherson)return{...$l(e,r,n),armResidual:0};if(t==="upright")return{...$l(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=q(K(s.front,s.bj)),u=q(K(s.rear,s.bj)),m=q(K(e.tieInner,e.tieOuter)),f=[{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]}],p=[[],[],[],[],[],[]];for(let Y=0;Y<6;Y++){let ee=f[Y].dir,ne=ae(K(f[Y].at,c),ee);p[0][Y]=ee[0],p[1][Y]=ee[1],p[2][Y]=ee[2],p[3][Y]=ne[0],p[4][Y]=ne[1],p[5][Y]=ne[2]}let d=ae(K(e.contactPatch,c),r),h=n??gL,b=[-r[0],-r[1],-r[2],-(d[0]+h[0]),-(d[1]+h[1]),-(d[2]+h[2])],g=cr(p,b),y=g.singular,R=g.x,k=R[0],v=R[1],x=R[2],M=[R[3],R[4],R[5]],A=q(K(i.rear,i.front)),w=q(K(o,e.pushrodOuter)),T=U(M,-1),P=(Y,ee)=>X(A,ae(K(Y,i.front),ee)),S=P(e.pushrodOuter,w),F=Math.abs(S)>1e-9?-P(i.bj,T)/S:NaN,C=te(T,U(w,F)),L=U(C,-1),E=q(K(i.front,i.bj)),D=q(K(i.rear,i.bj)),N=X(E,E),O=X(E,D),z=X(D,D),I=X(E,L),_=X(D,L),B=N*z-O*O,V=NaN,G=NaN,H=NaN;if(Math.abs(B)>1e-12){V=(I*z-_*O)/B,G=(N*_-O*I)/B;let Y=te(U(E,V),U(D,G)),ee=K(L,Y);H=Math.hypot(ee[0],ee[1],ee[2])}let W=a?{f:k,r:v}:{f:V,r:G},J=a?{f:V,r:G}:{f:k,r:v};return{ucaFront:W.f,ucaRear:W.r,lcaFront:J.f,lcaRear:J.r,tieRod:x,pushRod:F,damper:y||!Number.isFinite(F)||e.decoupled?NaN:e.direct?F:yL(e,F),condProxy:g.condProxy,singular:y,armResidual:H}}function yL(e,t){let r=q(K(e.rockerPivotB,e.rockerPivotA)),n=q(K(e.rockerToPushrod,e.pushrodOuter)),o=q(K(e.damperChassis,e.rockerToDamper)),a=Math.abs(X(r,ae(K(e.rockerToPushrod,e.rockerPivotA),n))),s=Math.abs(X(r,ae(K(e.rockerToDamper,e.rockerPivotA),o)));return s<1e-9?0:t*a/s}var dH=Math.PI/180;function zs(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 fv=["QSX3","QSX8","QSX13","QSX14"],xL=["QSX1"],Gl=["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",...fv];function RL(e){let t=["PKY6","PKY7","PVY3","PVY4","PHY3","PEY4","RVY3","QHZ3","QHZ4","QEZ5","QDZ8","QDZ9","QDZ10","QDZ11","SSZ3","SSZ4"];return e==="5.2"?[...t,"QBZ4","QDZ3"]:t}function vL(e){let t=new Set(RL(e)),r=Gl.filter(n=>!fv.includes(n));return[...r.filter(n=>!t.has(n)),...[...t].filter(n=>!r.includes(n)),...xL]}function kL(e,t){let r={...e};for(let n of t)r[n]!==void 0&&r[n]!==0&&(r[n]=-r[n]);return r}var Er=(e,t,r)=>Number.isFinite(e[t])?e[t]:r;function hv(e,t){return t!=="5.2"?Er(e,"PKY6",0)*Er(e,"LKYC",1):Er(e,"PKY1",-15)*Math.sin(Er(e,"PKY4",2)*Math.atan(1/Er(e,"PKY2",2)))*Er(e,"LKY",1)*Er(e,"PHY3",0)+Er(e,"PVY3",0)*Er(e,"LMUY",1)}var dv=.1;function bv(e){if(e.fitData)return"sae";let t=hv(e.coeffs,e.version);return t>dv?"sae":t<-dv?"iso":null}function Ys(e){return e.axisSystem??bv(e)??"sae"}function Kl(e){let t=new Set,r=n=>{for(let o of n)t.has(o)?t.delete(o):t.add(o)};return Ys(e)==="iso"&&r(Gl),e.axisSystem&&e.side==="left"&&r(vL(e.version)),t.size?kL(e.coeffs,t):e.coeffs}var hH=Math.PI/180;var $=(e,t)=>Number.isFinite(e)?e:t;function yv(e){let t=Kl(e);return{PCX1:$(t.PCX1,1.65),PDX1:$(t.PDX1,1),PDX2:$(t.PDX2,0),PDX3:$(t.PDX3,0),PEX1:$(t.PEX1,0),PEX2:$(t.PEX2,0),PEX3:$(t.PEX3,0),PEX4:$(t.PEX4,0),PHX1:$(t.PHX1,0),PHX2:$(t.PHX2,0),PKX1:$(t.PKX1,20),PKX2:$(t.PKX2,0),PKX3:$(t.PKX3,0),PPX1:$(t.PPX1,0),PPX2:$(t.PPX2,0),PPX3:$(t.PPX3,0),PPX4:$(t.PPX4,0),PVX1:$(t.PVX1,0),PVX2:$(t.PVX2,0),PCY1:$(t.PCY1,1.3),PDY1:$(t.PDY1,1),PDY2:$(t.PDY2,0),PDY3:$(t.PDY3,0),PEY1:$(t.PEY1,0),PEY2:$(t.PEY2,0),PEY3:$(t.PEY3,0),PEY4:$(t.PEY4,0),PEY5:$(t.PEY5,0),PHY1:$(t.PHY1,0),PHY2:$(t.PHY2,0),PHY3:$(t.PHY3,0),PKY1:$(t.PKY1,-15),PKY2:$(t.PKY2,2),PKY3:$(t.PKY3,0),PKY4:$(t.PKY4,2),PKY5:$(t.PKY5,0),PKY6:$(t.PKY6,0),PKY7:$(t.PKY7,0),PPY1:$(t.PPY1,0),PPY2:$(t.PPY2,0),PPY3:$(t.PPY3,0),PPY4:$(t.PPY4,0),PPY5:$(t.PPY5,0),PVY1:$(t.PVY1,0),PVY2:$(t.PVY2,0),PVY3:$(t.PVY3,0),PVY4:$(t.PVY4,0),RBX1:$(t.RBX1,0),RBX2:$(t.RBX2,0),RBX3:$(t.RBX3,0),RBY1:$(t.RBY1,0),RBY2:$(t.RBY2,0),RBY3:$(t.RBY3,0),RBY4:$(t.RBY4,0),RCX1:$(t.RCX1,1),RCY1:$(t.RCY1,1),REX1:$(t.REX1,0),REX2:$(t.REX2,0),REY1:$(t.REY1,0),REY2:$(t.REY2,0),RHX1:$(t.RHX1,0),RHY1:$(t.RHY1,0),RHY2:$(t.RHY2,0),RVY1:$(t.RVY1,0),RVY2:$(t.RVY2,0),RVY3:$(t.RVY3,0),RVY4:$(t.RVY4,0),RVY5:$(t.RVY5,1),RVY6:$(t.RVY6,0),PPZ1:$(t.PPZ1,0),PPZ2:$(t.PPZ2,0),QBZ1:$(t.QBZ1,8),QBZ2:$(t.QBZ2,0),QBZ3:$(t.QBZ3,0),QBZ4:$(t.QBZ4,0),QBZ5:$(t.QBZ5,0),QBZ6:$(t.QBZ6,0),QBZ9:$(t.QBZ9,0),QBZ10:$(t.QBZ10,0),QCZ1:$(t.QCZ1,1.1),QDZ1:$(t.QDZ1,.1),QDZ2:$(t.QDZ2,0),QDZ3:$(t.QDZ3,0),QDZ4:$(t.QDZ4,0),QDZ6:$(t.QDZ6,0),QDZ7:$(t.QDZ7,0),QDZ8:$(t.QDZ8,0),QDZ9:$(t.QDZ9,0),QDZ10:$(t.QDZ10,0),QDZ11:$(t.QDZ11,0),QEZ1:$(t.QEZ1,0),QEZ2:$(t.QEZ2,0),QEZ3:$(t.QEZ3,0),QEZ4:$(t.QEZ4,0),QEZ5:$(t.QEZ5,0),QHZ1:$(t.QHZ1,0),QHZ2:$(t.QHZ2,0),QHZ3:$(t.QHZ3,0),QHZ4:$(t.QHZ4,0),SSZ1:$(t.SSZ1,0),SSZ2:$(t.SSZ2,0),SSZ3:$(t.SSZ3,0),SSZ4:$(t.SSZ4,0),QSX1:$(t.QSX1,0),QSX2:$(t.QSX2,0),QSX3:$(t.QSX3,0),QSX4:$(t.QSX4,0),QSX5:$(t.QSX5,0),QSX6:$(t.QSX6,0),QSX7:$(t.QSX7,0),QSX8:$(t.QSX8,0),QSX9:$(t.QSX9,0),QSX10:$(t.QSX10,0),QSX11:$(t.QSX11,0),QSX12:$(t.QSX12,0),QSX13:$(t.QSX13,0),QSX14:$(t.QSX14,0),PPMX1:$(t.PPMX1,0),QSY1:$(t.QSY1,0),QSY2:$(t.QSY2,0),QSY3:$(t.QSY3,0),QSY4:$(t.QSY4,0),QSY5:$(t.QSY5,0),QSY6:$(t.QSY6,0),QSY7:$(t.QSY7,0),QSY8:$(t.QSY8,0),LONGVL:t.LONGVL!==void 0&&t.LONGVL>0?t.LONGVL:16.7,LCX:$(t.LCX,1),LCY:$(t.LCY,1),LEX:$(t.LEX,1),LEY:$(t.LEY,1),LFZO:$(t.LFZO,1),LHX:$(t.LHX,1),LHY:$(t.LHY,1),LKX:$(t.LKX,1),LKY:$(t.LKY,1),LKYC:$(t.LKYC,1),LKZC:$(t.LKZC,1),LMUX:$(t.LMUX,1),LMUY:$(t.LMUY,1),LMX:$(t.LMX,1),LMY:$(t.LMY,1),LVMX:$(t.LVMX,1),LRES:$(t.LRES,1),LS:$(t.LS,1),LTR:$(t.LTR,1),LVX:$(t.LVX,1),LVY:$(t.LVY,1),LVYKA:$(t.LVYKA,1),LXAL:$(t.LXAL,1),LYKA:$(t.LYKA,1)}}var gv=new WeakMap;function Ws(e){let t=gv.get(e);return t===void 0&&(t=yv(e),gv.set(e,t)),t}var xv=e=>e>=0?1:-1;function Hl(e,t,r=0,n){let o=Ws(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,f=o.PCY1*o.LCY,p=m*a,d=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(d)>1e-6?d:1e-6*(d<0?-1:1),R=h?(o.PHY1+o.PHY2*c)*o.LHY+(b*s-g)/y:(o.PHY1+o.PHY2*c)*o.LHY+o.PHY3*s,k=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=f*p!==0?d/(f*p):0;return{Fz:a,g:s,dfz:c,dpi:l,Fz0p:i,R0:u,Cy:f,Dy:p,By:v,SHy:R,SVy:k,Kya:d,muy:m,EyA:o.PEY1+o.PEY2*c,EyG:1+o.PEY5*s*s,EyS:o.PEY3+o.PEY4*s,LEY:o.LEY}}function zl(e,t,r=0,n){let o=Hl(e,t,r,n),a=Ws(e),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,muy:f,Kya:p,SVy:d,By:h,Cy:b,Dy:g,SHy:y}=o,R=(a.PHX1+a.PHX2*c)*a.LHX,k=(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,x=k*s,M=s*(a.PKX1+a.PKX2*c)*Math.exp(a.PKX3*c)*(1+a.PPX1*l+a.PPX2*l*l)*a.LKX,A=v*x!==0?M/(v*x):0,w=Math.abs(p)>1e-6?p:1e-6*(p<0?-1:1),T=e.version!=="5.2",P=s*(a.PVX1+a.PVX2*c)*a.LVX*a.LMUX,S=a.REX1+a.REX2*c;S>1&&(S=1);let F=a.REY1+a.REY2*c;return F>1&&(F=1),{Fz:s,g:i,dfz:c,dpi:l,Fz0p:u,R0:m,Cy:b,Dy:g,By:h,SHy:y,SVy:d,Kya:p,muy:f,EyA:o.EyA,EyG:o.EyG,EyS:o.EyS,LEY:o.LEY,SHx:R,Cx:v,Dx:x,Bx:A,SVx:P,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:S,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:F,DVykA:f*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:T?(a.QBZ1+a.QBZ2*c+a.QBZ3*c*c)*(1+a.QBZ5*Math.abs(i)+a.QBZ6*i*i)*(a.LKY/a.LMUY):(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:T?s*(m/u)*(a.QDZ1+a.QDZ2*c)*(1-a.PPZ1*l)*(1+a.QDZ3*Math.abs(i)+a.QDZ4*i*i)*a.LTR: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:p!==0?d/p:0,sixOne:T,kk:M/w*(M/w),sS0:m*(a.SSZ1+(a.SSZ3+a.SSZ4*c)*i)*a.LS,sS2:m*a.SSZ2*a.LS/u}}function js(e,t){let r=t+e.SHy,n=e.EyA*(e.EyG-e.EyS*xv(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 Yl(e,t){let r=t+e.SHx,n=e.ExA*(1-e.PEX4*xv(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 Rv(e,t,r){if(r===0)return t;if(e.sixOne)return Math.sqrt(t*t+e.kk*r*r)*Math.sign(t);let n=Math.tan(t);return Math.atan(Math.sqrt(n*n+e.kk*r*r))*Math.sign(t)}function ML(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=Rv(e,o,r),i=e.Bt*s;return e.Dt*Math.cos(e.Ct*Math.atan(i-a*(i-Math.atan(i))))*n}function SL(e,t,r,n){return e.Dr*Math.cos(Math.atan(e.Br*Rv(e,t+e.SHy+e.arOff,r)))*n}function vv(e,t,r,n,o,a){let s=Math.cos(t),i=ML(e,t,r,s),c=SL(e,t,r,s);return-i*(o-a)+c+(e.sS0+e.sS2*o)*n}function kv(e,t,r){let n=e.Bxa0*Math.cos(Math.atan(e.RBX2*t))*e.LXAL,o=r+e.SHxa,a=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*Yl(e,t)}function Bf(e,t){let r=e.sS0===0&&e.sS2===0?0:kv(e,0,t);return vv(e,t,0,r,js(e,t),0)}function Wl(e,t,r){let n=js(e,r),o=kv(e,t,r),a=e.Byk0*Math.cos(Math.atan(e.RBY2*(r-e.RBY3)))*e.LYKA,s=t+e.SHyk,i=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:vv(e,r,t,o,m,u)}}var Us=(e,t)=>Math.max(.1,e.muY0+e.loadSensY*(t-e.nominalLoad)),Xs=(e,t)=>Math.max(.1,e.muX0+e.loadSensX*(t-e.nominalLoad)),Mv=(e,t,r)=>Us(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cy*Math.atan(e.By*r)),Sv=(e,t,r)=>Xs(e,Math.max(1,t))*Math.max(1,t)*Math.sin(e.Cx*Math.atan(e.Bx*r));function $f(e,t){let r=Math.max(1,t.Fz),n=Us(e,r)*r,o=Xs(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 ba=Math.PI/180;function hn(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 Av(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?zs(r,t):1,s=n?zs(n,t):1,i=o?zs(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 ga(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}function De(e){let t=Av(e),r=t,n=t,o=null,a=NaN,s=NaN,i=NaN,c=(v,x,M)=>(o!==null&&v===a&&x===s&&M===i||(o=zl(r,v,x,M),a=v,s=x,i=M),o),l=null,u=NaN,m=NaN,f=NaN,p=(v,x,M)=>(l!==null&&v===u&&x===m&&M===f||(l=Hl(r,v,x,M),u=v,m=x,f=M),l),d=v=>e.kind==="magic"?Wl(c(v.Fz,v.gamma??0,v.p),v.kappa,v.alpha):$f(n,v),h=(v,x,M=0,A)=>e.kind==="magic"?js(p(x,M,A),v):Mv(n,x,v),b=(v,x,M=0,A)=>e.kind==="magic"?Yl(c(x,M,A),v):Sv(n,x,v),g=(v,x,M=0,A)=>e.kind==="magic"?Bf(c(x,M,A),v):d({Fz:x,kappa:0,alpha:v,gamma:M,p:A}).Mz,y=v=>e.kind==="simple"?Us(n,v):ga(x=>h(x*ba,v),45,1)/Math.max(1,v),R=v=>e.kind==="simple"?Xs(n,v):ga(x=>b(x,v),.6,.02)/Math.max(1,v),k=v=>{let x=.1*ba;return Math.abs((h(x,v)-h(-x,v))/(2*x))};return{model:e,forces:d,Fx:b,Fy:h,Mz:g,muX:R,muY:y,corneringStiffness:k,verticalStiffness:()=>e.verticalStiffness,rollingRadius:v=>{if(e.kind==="magic"&&e.missing?.includes("UNLOADED_RADIUS"))return 0;let x=e.unloadedR0??0;if(!(x>0))return 0;let M=e.verticalStiffness*1e3;if(!(M>0))return x;let A=e.rollingFraction??.306;return x-A*Math.max(0,v)/M},relaxationLength:v=>{let x=e.relaxation;if(!x)return 0;let M=x.carcassStiffness??0;if(!(M>0))return x.sigma;let A=k(Math.max(0,v));return A>0?A/(M*1e3):x.sigma}}}function ya(e){let t=Math.max(1,e.model.kind==="magic"?e.model.fnomin:e.model.nominalLoad);return e.Fy(2*ba,t,0)-e.Fy(-2*ba,t,0)>=0?1:-1}function qs(e,t=e.kind==="magic"?e.fnomin:e.nominalLoad){let r=De(e),n=2*ba,o=3*ba,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 AL=Math.PI/180;function ye(e,t){return e.axle?e.axle(t):e}function Ul(e,t){if(e===t)return e;let r=ya(e)*ya(t),n=(l,u)=>.5*(l+u),o=(l,u)=>l>0&&u>0?n(l,u):l>0?l:u>0?u:0,a=l=>{let u=e.forces(l),m=t.forces(l);return{Fx:n(u.Fx,m.Fx),Fy:n(u.Fy,r*m.Fy),Mz:n(u.Mz,r*m.Mz)}},s=(l,u,m=0,f)=>n(e.Fx(l,u,m,f),t.Fx(l,u,m,f)),i=(l,u,m=0,f)=>n(e.Fy(l,u,m,f),r*t.Fy(l,u,m,f)),c=(l,u,m=0,f)=>n(e.Mz(l,u,m,f),r*t.Mz(l,u,m,f));return{model:e.model,forces:a,Fx:s,Fy:i,Mz:c,muX:l=>ga(u=>s(u,l),.6,.02)/Math.max(1,l),muY:l=>ga(u=>i(u*AL,l),45,1)/Math.max(1,l),corneringStiffness:l=>n(e.corneringStiffness(l),t.corneringStiffness(l)),verticalStiffness:()=>o(e.verticalStiffness(),t.verticalStiffness()),rollingRadius:l=>o(e.rollingRadius(l),t.rollingRadius(l)),relaxationLength:l=>o(e.relaxationLength(l),t.relaxationLength(l)),axle:l=>l==="front"?e:t}}function gt(e){if(Fv.has(e))return e;let t=wv.get(e);if(t)return t;let r;if(e.axle){let n=e.axle("front"),o=e.axle("rear"),a=gt(n),s=gt(o);r=a===n&&s===o?e:Ul(a,s)}else ya(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)};return Fv.add(r),r!==e&&wv.set(e,r),r}var Fv=new WeakSet,wv=new WeakMap;var Xl=25*(Math.PI/180);function FL(e){let t=.6180339887,r=0,n=Xl,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 Qs(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=Xl;if(s(Xl)<=a){let u=FL(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(Xl,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),f=s(m)-a;if(f<0?i=m:c=m,Math.abs(f)<=l)return m}return c}var Gf={shaft:!1,trail:0,hub:[0,0,0]};function Tv(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 Kf(e,t,r){let n=r.shaft?Vf(e,t):[0,0,0];if(r.trail!==0){let a=Tv(e),s=[t[0],t[1],0],i=K(s,U(a,X(s,a)));n=te(n,ae(U(a,-r.trail),i))}let o=r.hub;return(o[0]!==0||o[1]!==0||o[2]!==0)&&(n=K(n,ae(K(e.contactPatch,e.wheelCenter),o))),{force:te(t,o),moment:n}}var wL=(e,t)=>{let r=e!==void 0&&e>0?1/e:0,n=t!==void 0&&t>0?1/t:0;return r+n},ql={ucaFront:0,ucaRear:0,lcaFront:0,lcaRear:0,tieRod:0,pushRod:0,rack:0};function Wn(e){return!e.measured}function jn(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 Zs(e,t){let r=e.corner.hardpoints,n=ra(e.rocker,t.points.rockerAngle);return{ucaFront:r.ucaFront,ucaRear:r.ucaRear,lcaFront:r.lcaFront,lcaRear:r.lcaRear,tieInner:Gn(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 Hf(e,t,r=0){let n=t.links??{},o=t.bushings??{},a=(l,u,m)=>{let f=wL(u,m);return f>0&&Number.isFinite(l)?l*f: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 Pv(e,t,r,n){let o=Me(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 Js(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:te(n.strut.top,t.topMount)}),t.ucaFront!==0||t.ucaRear!==0){let i=Pv(r.ucaFront,r.ucaRear,Me(r.uprightUpper,r.ucaFront)+t.ucaFront,Me(r.uprightUpper,r.ucaRear)+t.ucaRear);o.ubjAxial0=i.axial,o.ubjRadius2=i.radius2}if(t.lcaFront!==0||t.lcaRear!==0){let i=Pv(r.lcaFront,r.lcaRear,Me(r.uprightLower,r.lcaFront)+t.lcaFront,Me(r.uprightLower,r.lcaRear)+t.lcaRear),c=X(n.lbjRel0,n.lcaDir),l=K(n.lbjRel0,U(n.lcaDir,c)),u=Math.hypot(l[0],l[1],l[2]);o.lbjRel0=u>1e-9?te(U(n.lcaDir,i.axial),U(l,Math.sqrt(i.radius2)/u)):te(U(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=te(n.tieInner0,U(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 CL=8,TL=1e-5,PL=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 zf(e,t,r){let n=Kf(e,r.force,r.extras??Gf),o=r.alignMoment?te(n.moment,[0,0,r.alignMoment]):n.moment;return Hs(e,t,n.force,o)}function Zl(e,t,r,n,o,a,s=0){let i=Oe(e,t,r,o,a),c=e.corner.compliance;if(!(jn(c)&&Wn(e.corner)))return{state:i,forces:zf(Zs(e,i),e.corner.config.pushrodAttach,n),deflection:ql,rigid:i,iterations:0,converged:!0,bypassed:!0};let u=i,m=e,f=e.corner.config.pushrodAttach,p=zf(Zs(e,i),f,n),d=ql,h=!1,b=0;for(;b<CL;b++){let g=Zs(m,u);if(p=zf(g,f,n),p.singular)break;d=Hf(p,c,s),m=Js(e,d);let y=Oe(m,t,r,PL(u),a),R=Me(y.points.wheelCenter,u.points.wheelCenter);if(u=y,R<TL){h=!0;break}}return{state:u,forces:p,deflection:d,rigid:i,iterations:b+1,converged:h&&u.converged,bypassed:!1}}var Ql=1e3,Lv=1e5;function Dv(e,t,r,n,o){let a=Zl(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 Jl(e,t,r,n,o){let a={force:[0,0,n]},s=(b,g=0)=>Dv(e,t,r,{force:b,alignMoment:g},o),i=Dv(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,Ql,n]),l=s([0,-Ql,n]),u=s([Ql,0,n]),m=s([-Ql,0,n]),f=s([0,0,n],Lv),p=s([0,0,n],-Lv),d=(b,g)=>(b-g)/2,h=[i,c,l,u,m,f,p].every(b=>b.converged);return{toePerLateral:d(c.toe,l.toe),camberPerLateral:d(c.camber,l.camber),toePerLongitudinal:d(u.toe,m.toe),camberPerLongitudinal:d(u.camber,m.camber),toePerAligning:d(f.toe,p.toe),lateralPatch:d(c.patch[1],l.patch[1]),longitudinalPatch:d(u.patch[0],m.patch[0]),bypassed:!1,converged:h}}var LL=1e3;function Yf(e,t=LL){if(!jn(e.compliance)||!Wn(e))return;let r=nt(e),n=Oe(r,0,0),o=Jl(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 xa(e,t=-Of,r=Of,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=Ye(e,{travelMin:t,travelMax:r,steps:n}),s=Yf(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 eu(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 bn(e,t){return{motionRatio:eu(e.travel,e.motionRatio,t),camber:eu(e.travel,e.camber,t),toe:eu(e.travel,e.toe,t),damperLen:eu(e.travel,e.damperLen,t)}}var Ev=Math.PI/180,DL=9.81;function gn(e,t,r,n=0){let o=Te(e),a=e.wheelbase*(1-e.frontMassFrac),s=e.wheelbase*e.frontMassFrac,i=fa(e,n),c=e.aero?.model?(k,v,x)=>fa(e,n,v,k,x):()=>i,l=bn(t,0),u=bn(r,0),m=e.loadFactor,f=m!==void 0&&m!==1?(m-1)*e.massTotal*DL:0,p=f*e.frontMassFrac/2,d=f*(1-e.frontMassFrac)/2,h=(k,v)=>v>0&&Number.isFinite(v)&&k+v>0?v/(k+v):1,b=Ze(e,"front"),g=Ze(e,"rear"),y={F:h(e.wheelRateFront+(e.heaveSpringFront??0),b),R:h(e.wheelRateRear+(e.heaveSpringRear??0),g)},R={F:h(e.wheelRateFront+e.arbFront,b),R:h(e.wheelRateRear+e.arbRear,g)};return(k,v,x=0,M=0)=>{let A=c(k,v,x),w=o.rollGradient*k,T=w*Ev,P=o.pitchGradient*v*Ev,S=(N,O)=>{let z=O==="F"?e.trackFront:e.trackRear,I=O==="F"?o.rideRateFront:o.rideRateRear,_=(N==="R"?1:-1)*(z/2)*Math.tan(T),B=(O==="R"?s:-a)*Math.tan(P),V=`${O}${N}`,G=f?A[V]+(O==="F"?p:d):A[V],H=I>0?G/I:0;return{anti:_,sym:B+H}},F={FL:S("L","F"),FR:S("R","F"),RL:S("L","R"),RR:S("R","R")},C=N=>{let O=N[0];return F[N].sym*y[O]+F[N].anti*R[O]},L=da(e,M,o,{FL:C("FL"),FR:C("FR")}),E=w+L.rollDeg,D=(N,O)=>{let z=O==="F"?t:r,I=O==="F"?l:u,_=`${O==="F"?"F":"R"}${N}`,B=F[_].sym+F[_].anti+L.travel[_],V=C(_)+L.travel[_]*R[O],G=B-V,H=bn(z,V),W=(N==="R"?1:-1)*H.camber;return{travel:V,tyre:G,ground:B,camber:W,camberRoad:W+E,toe:H.toe,bumpToe:H.toe-I.toe,damperTravel:I.damperLen-H.damperLen}};return{FL:D("L","F"),FR:D("R","F"),RL:D("L","R"),RR:D("R","R"),steeringJacking:L}}}var Wf=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Un(e){return{enabled:e?.enabled===!0,roadFeedbackGain:Math.min(2,Math.max(0,Wf(e?.roadFeedbackGain,1))),turnInFrictionNm:Math.max(0,Wf(e?.turnInFrictionNm,0)),columnStiffnessNmPerRad:Math.max(0,Wf(e?.columnStiffnessNmPerRad,0))}}function jf(e,t,r){let n=Un(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 Iv=()=>({totalNm:0,aligningNm:0,lateralNm:0,longitudinalNm:0,jackingNm:0});function Xn(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 ei(e,t,r,n="model",o){let a=e.steerFront;if(!Xn(e)||!a)return null;let s=t<0?-1:1,c=a.rackRatioMmPerRev/(2*Math.PI)/1e3,l=t>=0,u=o&&a.travelSurface?ma(a,Math.abs(t),l?o.FL:o.FR,l?o.FR:o.FL):pa(a,Math.abs(t));if(!u.innerJacobian||!u.outerJacobian)return null;let m=(b,g)=>{let y=r[b],R=b==="FL"?-1:1,k=-R*y.Fy,x={aligning:1e3*(-R*y.Mz)*g.yaw,lateral:k*g.lateral,longitudinal:y.Fx*g.longitudinal,jacking:y.Fz*g.vertical},M=Iv();M.aligningNm=-s*x.aligning*c,M.lateralNm=-s*x.lateral*c,M.longitudinalNm=-s*x.longitudinal*c,M.jackingNm=-s*x.jacking*c,M.totalNm=M.aligningNm+M.lateralNm+M.longitudinalNm+M.jackingNm;let A=-s*(x.aligning+x.lateral+x.longitudinal+x.jacking);return{moment:M,rackN:A}},f=m("FL",l?u.innerJacobian:u.outerJacobian),p=m("FR",l?u.outerJacobian:u.innerJacobian),d=Iv();for(let b of[f.moment,p.moment])d.aligningNm+=b.aligningNm,d.lateralNm+=b.lateralNm,d.longitudinalNm+=b.longitudinalNm,d.jackingNm+=b.jackingNm,d.totalNm+=b.totalNm;let h=jf(d.totalNm,t,e.steeringSystem);return d.totalNm=h.driverNm,{...d,roadNm:h.roadNm,assistanceNm:h.assistanceNm,frictionNm:h.frictionNm,columnTwistDeg:h.columnTwistDeg,rackForceN:f.rackN+p.rackN,aligningSource:n,perWheel:{FL:f.moment,FR:p.moment}}}var EL=e=>"front"in e&&"rear"in e;function Ra(e,t){return EL(e)?e[t]:e}function Xf(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)),f=(u-a[m])/o;return l[m]+f*(l[m+1]-l[m])};return{muX:l=>c(s,l),muY:l=>c(i,l)}}function Uf(e,t){let r=Math.max(0,t.Fz),n=e.muY(r)*r,o=e.muX(r)*r;if(!(n>0))return{fyUsed:0,fyMax:0,fyRes:0};let a=o>0?Math.min(1,Math.abs(t.Fx)/o):0,s=n*Math.sqrt(Math.max(0,1-a*a)),i=Math.abs(t.Fy);return{fyUsed:i,fyMax:s,fyRes:Math.max(0,s-i)}}function _v(e,t,r){let n=Uf(e,t),o=Uf(e,r);return{left:n,right:o,fyRes:n.fyRes+o.fyRes}}function Ir(e,t,r){let n=_v(Ra(e,"front"),t.FL,t.FR),o=_v(Ra(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 ti=[{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=ti.flatMap(e=>[e.min,e.max]);function NL(e){let t={};for(let r of ti){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 tu(e){if(e.kind==="magic")return e.range??NL(e.coeffs)}function qf(e){return Math.max(1,e.kind==="magic"?e.fnomin:e.nominalLoad)}function Nv(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 Zt(e){let t=Ov.get(e);if(t!==void 0)return t;let r=10*qf(e.model),{turnover:n,collapse:o}=VL(e,r),a=n??o??r;return Ov.set(e,a),a}var Ov=new WeakMap;function VL(e,t){let r=qf(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 f=o(m*s);if(f<c){i=Nv(o,(m-2)*s,m*s,20,(p,d)=>p>d);break}c=f}let l=null,u=n(s);for(let m=2;m<=a;m++){let f=n(m*s);if(f>u){let p=Nv(n,(m-2)*s,m*s,40,(d,h)=>d<h);n(p)<.05*n(r)&&(l=p);break}u=f}return{turnover:i,collapse:l}}var Vv=.1;function ru(e,t=qf(e)){let r=De(e).muX(t);return{muX:r,none:Number.isFinite(r)&&r<Vv}}var Bv=["FL","FR","RL","RR"],BL=e=>e==="FL"||e==="RL",$L=e=>e==="FL"||e==="FR"?"front":"rear";function nu(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 Bv)a[l]={...t[l]};let s=l=>{let u=0;for(let f of Bv)$L(f)===e.axle&&(a[f].Fx=e.sense*(f===e.strong?l-e.open/2:e.open/2),u-=(BL(f)?o:-o)*a[f].Fx);let m=Ir(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 GL=[["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]],KL=[["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]],HL=[["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],["QBZ6","Camber influence Bt",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]],zL=[["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]],YL=[["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]],Gv=[["lateral",GL],["longitudinal",KL],["aligning",HL],["combined",zL],["scaling",YL]].flatMap(([e,t])=>t.map(([r,n,o])=>({key:r,section:e,text:n,fallback:o}))),yz=new Map(Gv.map(e=>[e.key,e]));var WL=/^\$\s*EDITED\s+([A-Z][A-Z0-9_]*)\s+was\s+(absent|[-+0-9.eE]+)\s*$/;function Kv(e){let t={};for(let r of e.split(/\r?\n/)){let n=r.trim().match(WL);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 UL=/^\s*\$\s*UNLOADED_RADIUS_STAND_IN\s*=\s*([0-9.eE+-]+)/,XL=/^\$-+ written by (?:PaceDynamics|PaceLab)\b/m,qL=/^\$\s*AXIS_SYSTEM\s*=\s*(ISO-W|SAE)\b/m;function QL(e){let t=e.match(qL);return t?{axisSystem:t[1]==="SAE"?"sae":"iso",trustSide:!0}:XL.test(e)?{axisSystem:"sae",trustSide:!1}:{axisSystem:"iso",trustSide:!0}}function ZL(e){return e>=62?"6.2":e>=61?"6.1":"5.2"}var Hv=new Map([["pa",1],["pascal",1],["kpa",1e3],["kilopascal",1e3],["mpa",1e6],["megapascal",1e6],["bar",1e5],["psi",6894.757293168]]);function JL(e,t,r){let n=r.PRESSURE?.trim().toLowerCase(),o=n===void 0?1:Hv.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 eD=new Map([["radians",1],["radian",1],["rad",1],["degrees",Math.PI/180],["degree",Math.PI/180],["deg",Math.PI/180]]);function tD(e,t){let r=(s,i)=>s===void 0?1:i.get(s.trim().toLowerCase()),n=r(t.ANGLE,eD),o={fz:1,kappa:1,alpha:n,gamma:n,p:r(t.PRESSURE,Hv)},a={};for(let s of ti){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 ri(e,t="imported",r={}){let n=QL(e),o=r.axisSystem??n.axisSystem,a={},s={},i={},c="",l;for(let g of e.split(/\r?\n/)){let y=g.match(UL);y&&(l=parseFloat(y[1]));let R=g.replace(/[$!].*$/,"").trim();if(!R)continue;if(R.startsWith("[")){c=(R.match(/^\[([^\]]*)/)?.[1]??"").trim().toUpperCase();continue}let k=R.indexOf("=");if(k<0)continue;let v=R.slice(0,k).trim().toUpperCase(),x=R.slice(k+1).trim(),M=x.match(/^'([^']*)'|^"([^"]*)"/);if(M){s[v]=M[1]??M[2]??"",c==="UNITS"&&(i[v]=s[v]);continue}let A=parseFloat(x);Number.isFinite(A)&&(a[v]=A)}let u=ZL(a.FITTYP??62),m=Kv(e),f=m?Object.fromEntries(Object.entries(m).filter(([g])=>a[g]!==void 0)):void 0,p=a.VERTICAL_STIFFNESS??a.KZ??0,d=JL(a,s,i),h=tD(a,i),b=[];return a.UNLOADED_RADIUS===void 0&&a.R0===void 0&&b.push("UNLOADED_RADIUS"),p<=0&&b.push("VERTICAL_STIFFNESS"),a.FNOMIN===void 0&&b.push("FNOMIN"),d===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:p>0?p/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:d??0,missing:b,...f&&Object.keys(f).length?{edited:f}:{},...h?{range:h}:{}}}function dr(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 ou(e){if(!e)return null;let t=e.sectionWidth;return t!==void 0&&t>0?t:null}var Fz=Math.PI/180;var Lz=Math.PI/180,Dz=180/Math.PI;function ni(){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 Wv=`$ 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 Xf(){return Zs(zv,"Example MF6.2")}var JL=Math.PI/180,Yv=2,Wv=2;function jv(e){let t=Math.sin(Wv*Math.atan(1/Yv)),r=-e.corneringStiffness/(e.Fz0*t),n=e.camberStiffness/JL/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)
111
+ `;function Qf(){return ri(Wv,"Example MF6.2")}var nD=Math.PI/180,jv=2,Uv=2;function Xv(e){let t=Math.sin(Uv*Math.atan(1/jv)),r=-e.corneringStiffness/(e.Fz0*t),n=e.camberStiffness/nD/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(Yv)}
173
+ PKY2 = ${o(jv)}
174
174
  PKY3 = 0.8
175
- PKY4 = ${o(Wv)}
175
+ PKY4 = ${o(Uv)}
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 Ir(e){let t=Zs(jv(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 Uv={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},Xv={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},qv={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},Qv={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},Zv={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},Jv={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},e1={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},t1={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},qf=()=>Ir(Uv),Qf=()=>Ir(Xv),Zf=()=>Ir(qv),Jf=()=>Ir(Qv),eh=()=>Ir(Zv),th=()=>Ir(Jv),rh=()=>Ir(e1),nh=()=>Ir(t1);var r1=e=>Number.isFinite(e)&&e>0;function tu(e,t){let r=r1(t.grip)?t.grip:1,n=r1(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 ei={ok:!0,violation:0},qn=1e7;function _r(e,t){let r;try{r=e.build(t)}catch(s){return{total:qn*2,feasible:!1,terms:[],reason:`build failed: ${String(s)}`}}let n=e.feasible(r);if(!n.ok)return{total:qn+Math.max(0,n.violation),feasible:!1,terms:[],reason:n.reason};let o;try{o=e.terms(r)}catch(s){return{total:qn*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:qn*2,feasible:!1,terms:o,reason:"objective was not finite"}}var ti=(e,t)=>!t||(e.feasible!==t.feasible?e.feasible:e.total<t.total);function oh(e,t){return t.map((r,n)=>Math.min(e[n].hi,Math.max(e[n].lo,r)))}var Nr=e=>e.map(t=>t.start);function ru(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 eD(e){let t=0;for(;t===0;)t=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}function ah(e,t){let{budget:r}=t,n=Math.max(1,Math.floor(t.progressEvery??1)),o=e.variables,a=p=>oh(o,p.map((d,h)=>o[h].lo+d*(o[h].hi-o[h].lo))),s=p=>p.map((d,h)=>(d-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:p=>{if(i>=r)return l?.total??Number.POSITIVE_INFINITY;i++;let d=p.map(g=>Math.min(1,Math.max(0,g))),h=_r(e,a(d));h.feasible||c++;let b=ti(h,l)?h:l;return b===h&&(l=h,u=d),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:p=>({method:p,x:u?a(u):Nr(o),score:l??_r(e,Nr(o)),evaluations:i,history:m,infeasible:c})}}var sh=(e,t,r,n=0,o)=>{let a=t?r.norm(Nr(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 n1(e,t){let r=ah(e,t),n=ru(t.seed??1),o=e.variables.length;for(r.evaluate(sh(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 ya(e,t){let r=ah(e,t),n=e.variables.length,o=ru(t.seed??1),a=1,s=2,i=.5,c=.5,l=sh(e,t.warmStart!==!1,r,t.startJitter,o),u=.25;for(;r.left()>0;){let m=[{u:l,f:r.evaluate(l)}];for(let f=0;f<n&&r.left()>0;f++){let p=l.slice();p[f]+=p[f]+u>1?-u:u,m.push({u:p,f:r.evaluate(p)})}for(;r.left()>0;){m.sort((g,y)=>g.f-y.f);let f=m[n],p=new Array(n).fill(0);for(let g=0;g<n;g++)for(let y=0;y<n;y++)p[y]+=m[g].u[y]/n;let d=g=>p.map((y,R)=>y+g*(y-f.u[R])),h=d(a),b=r.evaluate(h);if(b<m[0].f){let g=d(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=d(-i),y=r.evaluate(g);if(y<f.f)m[n]={u:g,f:y};else{let R=m[0],k=0;for(let v=1;v<=n;v++)for(let x=0;x<n;x++)k=Math.max(k,Math.abs(m[v].u[x]-R.u[x]));if(k<1e-4)break;for(let v=1;v<=n&&r.left()>0;v++){let x=m[v].u.map((M,A)=>R.u[A]+c*(M-R.u[A]));m[v]={u:x,f:r.evaluate(x)}}}}}m.sort((f,p)=>f.f-p.f),l=m[0].u.map(f=>Math.min(1,Math.max(0,f+.05*(o()-.5)))),u=Math.max(.02,u*.5)}return r.result("nelder-mead")}function o1(e,t){let r=ah(e,t),n=e.variables.length,o=ru(t.seed??1),a=4+Math.floor(3*Math.log(n)),s=Math.floor(a/2),i=[];for(let M=1;M<=s;M++)i.push(Math.log(s+.5)-Math.log(M));let c=i.reduce((M,A)=>M+A,0);for(let M=0;M<s;M++)i[M]/=c;let l=1/i.reduce((M,A)=>M+A*A,0),u=(l+2)/(n+l+5),m=1+2*Math.max(0,Math.sqrt((l-1)/(n+1))-1)+u,f=(4+l/n)/(n+4+2*l/n),p=(n+2)/3,d=Math.min(1,p*2/((n+1.3)**2+l)),h=Math.min(1-d,p*2*(l-2+1/l)/((n+2)**2+l)),b=Math.sqrt(n)*(1-1/(4*n)+1/(21*n*n)),g=sh(e,t.warmStart!==!1,r,t.startJitter,o),y=.25,R=new Array(n).fill(1),k=new Array(n).fill(0),v=new Array(n).fill(0),x=0;for(;r.left()>0;){x++;let M=[];for(let S=0;S<a&&r.left()>0;S++){let F=[];for(let L=0;L<n;L++)F.push(eD(o));let C=g.map((L,E)=>L+y*R[E]*F[E]);M.push({z:F,u:C,f:r.evaluate(C)})}if(M.length<s)break;M.sort((S,F)=>S.f-F.f);let A=g.slice(),w=new Array(n).fill(0);g=new Array(n).fill(0);for(let S=0;S<s;S++)for(let F=0;F<n;F++)g[F]+=i[S]*M[S].u[F],w[F]+=i[S]*M[S].z[F];g=g.map(S=>Math.min(1,Math.max(0,S)));for(let S=0;S<n;S++)k[S]=(1-u)*k[S]+Math.sqrt(u*(2-u)*l)*w[S];let T=Math.sqrt(k.reduce((S,F)=>S+F*F,0)),P=T/Math.sqrt(1-(1-u)**(2*x))/b<1.4+2/(n+1)?1:0;for(let S=0;S<n;S++){let F=(g[S]-A[S])/(y*R[S]);v[S]=(1-f)*v[S]+P*Math.sqrt(f*(2-f)*l)*F}for(let S=0;S<n;S++){let F=0;for(let E=0;E<s;E++)F+=i[E]*M[E].z[S]*M[E].z[S];let C=R[S]*R[S],L=(1-d-h)*C+d*(v[S]*v[S]+(1-P)*f*(2-f)*C)+h*F*C;R[S]=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 xa=[{name:"random",run:n1},{name:"nelder-mead",run:ya},{name:"sep-cma-es",run:o1}];var Yz=Math.PI/180;var nu=Math.PI/180;var Xz={Fz:100,alpha:.25*nu,kappa:.005,gamma:.5*nu,p:6900},a1={Fz:100,alpha:1*nu,kappa:.02,gamma:.5*nu,p:6900};var s1=Math.PI/180,t6={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:s1},gamma:{rad:1,deg:s1},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 s6=Math.PI/180;var pD=Math.PI/180;var d6=3*pD;var y6=Math.PI/180;var P6=Math.PI/180;var RD={RCX1:1,RCY1:1,REX1:0,REY1:0,RBY3:0,RHX1:0,RHY1:0},l1={RBX1:15,RBX2:15,RBY1:18,RBY2:19,...RD};var G6=Math.PI/180;var AD=Math.PI/180,ou=[{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"},{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"}],rY=new Map(ou.map(e=>[e.id,e]));var nY=.01*AD;var We=Math.PI/180;var p1=new Set(ou.filter(e=>e.group!=="inputs"&&(e.unit==="N"||e.unit==="N\xB7m"||e.unit==="N/rad")).map(e=>e.id)),d1={alpha:{from:-15*We,to:15*We,n:61},kappa:{from:-.25,to:.25,n:61},gamma:{from:-6*We,to:6*We,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}},mh={alpha:{from:0,to:12*We,n:7},kappa:{from:-.2,to:.2,n:9},gamma:{from:-4*We,to:4*We,n:5},Fz:{from:400,to:1600,n:5},p:{from:6e4,to:12e4,n:4},V:{from:5,to:35,n:4}};var ph={alpha:{from:0,to:12*We,n:25},kappa:{from:-.2,to:.2,n:25},gamma:{from:-4*We,to:4*We,n:17},Fz:{from:300,to:1800,n:16},p:{from:6e4,to:12e4,n:13},V:{from:5,to:35,n:13}};var Se=(e,t,r,n={},o={})=>({id:e,form:"curves",sweep:[{input:t,...d1[t],...o}],x:t,y:r,...n}),au=(e,[t,r],n,o,a={})=>({id:e,form:"carpet",sweep:[{input:t,...mh[t]},{input:r,...mh[r]}],x:n,y:[o],...a}),Or=(e,t)=>({id:e,fixed:t}),Yt={input:"Fz",values:"car"},uh={alpha:0,kappa:0},Mt={kappa:0},u1={alpha:0},wD={input:"Fz",values:[500,1e3,1500]},CD=[{id:"overview",name:"Overview",cards:[Or("tyre","tyre"),Se("fy","alpha",["Fy"],{title:"Lateral force",hold:Mt}),Se("mz","alpha",["Mz"],{title:"Aligning moment",hold:Mt}),Se("fx","kappa",["Fx"],{title:"Longitudinal force",hold:u1}),au("combined-carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),Or("ellipse","ellipse")]},{id:"lateral",name:"Lateral",cards:[Se("fy-load","alpha",["Fy"],{title:"Lateral force per wheel load",series:Yt,hold:Mt}),Se("muy-load","alpha",["muY"],{title:"Lateral force per unit load",series:Yt,hold:Mt}),Se("fy-peak","alpha",["Fy"],{title:"Lateral force over its peak",series:Yt,hold:Mt,scale:{per:"peak"}},{from:0,to:15*We,n:61}),Se("muy-peak","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load"}),Se("calpha","Fz",["Calpha"],{title:"Cornering stiffness over load"}),Se("alpha-peak","Fz",["alphaPeak"],{title:"Slip angle at the peak over load"})]},{id:"aligning",name:"Aligning",cards:[Se("mz-load","alpha",["Mz"],{title:"Aligning moment per wheel load",series:Yt,hold:Mt}),Se("trail","alpha",["t"],{title:"Pneumatic trail",series:Yt,hold:Mt},{from:0,to:12*We,n:49}),Se("mzr","alpha",["Mzr"],{title:"Residual aligning moment",series:Yt,hold:Mt},{from:0,to:12*We,n:49}),au("gough",["alpha","Fz"],"Fy","Mz",{title:"Gough plot",hold:Mt}),Se("steering-feel","alpha",["t"],{title:"Steering feel",x:"FyRel",series:Yt,hold:Mt},{from:0,to:12*We,n:49})]},{id:"longitudinal",name:"Longitudinal",cards:[Se("fx-load","kappa",["Fx"],{title:"Longitudinal force per wheel load",series:Yt,hold:u1}),Se("mux-peak","Fz",["muXPeak"],{title:"Peak longitudinal \u03BC over load"}),Se("kx","Fz",["dFxdk"],{title:"Slip stiffness at zero slip over load",hold:uh}),Se("kappa-peak","Fz",["kappaPeak"],{title:"Slip ratio at the peak over load"})]},{id:"combined",name:"Combined",cards:[au("carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),au("envelope-load",["kappa","alpha"],"Fy","Fx",{title:"Friction envelope per load",scale:{per:"Fz"},facet:wD}),Se("fy-kappa","kappa",["Fy"],{title:"Side force while driving or braking",series:{input:"alpha",values:[2*We,4*We,8*We]}}),Se("fx-kappa","kappa",["Fx"],{title:"Driving force while cornering",series:{input:"alpha",values:[0,4*We,8*We]}}),Or("ellipse","ellipse")]},{id:"camber",name:"Camber",cards:[Se("fy-gamma","alpha",["Fy"],{title:"Lateral force per inclination",series:{input:"gamma",values:[-4,-2,0,2,4].map(e=>e*We)},hold:Mt}),Se("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",...ph.gamma},{input:"Fz",...ph.Fz,follow:!0}],x:"gamma",y:["Fz"],z:"muYPeak"},Se("camber-stiffness","alpha",["dFydg"],{title:"Camber stiffness at the point",series:Yt,hold:Mt}),Se("mx","alpha",["Mx"],{title:"Overturning moment",series:Yt,hold:Mt})]},{id:"rolling",name:"Rolling and radius",cards:[Se("my","V",["My"],{title:"Rolling-resistance moment",series:Yt,hold:uh}),Se("radius","Fz",["R0","Rl","Re"],{title:"Radius over load"},{from:0}),Se("p-roll","V",["Proll"],{title:"Rolling power",series:Yt,hold:uh})]},{id:"transient",name:"Transient",cards:[Se("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},Se("delta-fy","alpha",["Fy"],{title:"Lateral force, minus the reference",hold:Mt,scale:{delta:!0}}),Se("delta-mu","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load, minus the reference",scale:{delta:!0}}),Se("delta-calpha","Fz",["Calpha"],{title:"Cornering stiffness over load, minus the reference",scale:{delta:!0}})]},{id:"car",name:"Car",cards:[Or("operating","operating"),Or("wheels","wheels")]},{id:"fit",name:"Fit check",cards:[Or("fitLateral","fitLateral"),Or("fitLongitudinal","fitLongitudinal"),Or("fitCoupling","fitCoupling"),Or("fitEnvelope","fitEnvelope")]}];var _D=5670374e-14,dh=273.15,b1=.95,g1=60,su=10,ND=.55,Dt=25,fh=-20,hh=50,ni={tempC:[20,100,200,550,650,750],factor:[.8,.92,1,1,.85,.65]},oi={discMassKg:.5,discOuterMm:220,specificHeatJPerKgK:460,emissivity:.6,coolingWPerM2K:200,padCurve:{tempC:[...ni.tempC],factor:[...ni.factor]}},iu={...oi,discMassKg:.4,discOuterMm:200,padCurve:{tempC:[...ni.tempC],factor:[...ni.factor]}};function bh(e,t){let r=t==="front"?oi:iu,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 OD=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},ri=(e,t,r,n)=>Math.min(r,Math.max(t,OD(e,n)));function VD(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 gh(e,t){return{discMassKg:ri(e?.discMassKg,.05,20,t.discMassKg),discOuterMm:ri(e?.discOuterMm,50,600,t.discOuterMm),specificHeatJPerKgK:ri(e?.specificHeatJPerKgK,100,3e3,t.specificHeatJPerKgK),emissivity:ri(e?.emissivity,.02,1,t.emissivity),coolingWPerM2K:ri(e?.coolingWPerM2K,su,5e3,t.coolingWPerM2K),padCurve:VD(e?.padCurve,t.padCurve)}}function cu(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 yh(e,t=1){let r=e.discMassKg*e.specificHeatJPerKgK,n=e.discOuterMm*.001/2,o=2*Math.PI*n*n,a=g1/3.6,s=e.emissivity*_D*o,i=m=>su+(e.coolingWPerM2K-su)*Math.pow(Math.max(0,m)*t/a,ND),c=(m,f,p)=>{let d=m+dh,h=p+dh;return i(f)*o*(m-p)+s*(d**4-h**4)},l=(m,f)=>i(f)*o+4*s*Math.max(0,m+dh)**3,u=(m,f)=>r/l(f,m);return{heatCapacityJPerK:r,areaM2:o,convectionAt:i,coolingW:c,timeConstantS:u,step(m,f,p,d,h){if(!(d>0))return m+f/r;let b=u(p,m+Math.max(0,f)/r),g=Math.max(1,Math.ceil(d/(.25*b))),y=d/g,R=f/g;for(let k=0;k<g;k++)m+=(R-c(m,p,h)*y)/r;return m},padFactor:m=>cu(e.padCurve,m),window:y1(e.padCurve)}}function lu(e,t,r,n,o,a,s=Dt){let i=n.length,c=new Array(i),l=new Array(i),u=new Array(i),m=b1/Math.max(1,t),f=a,p=f,d=0,h=0,b=0;for(let g=0;g<i;g++){let y=Math.max(0,r[g]??0);c[g]=f,l[g]=y*n[g],u[g]=e.padFactor(f);let R=y*(o[g]??0);d+=R,f<e.window.fromC?h+=R:f>e.window.toC&&(b+=R);let k=g+1<i?n[g+1]:n[g],v=.5*(n[g]+k),x=v>0?(o[g]??0)/v:0;f=e.step(f,m*R,v,x,s),f>p&&(p=f)}return{tempC:c,heatW:l,padFactor:u,startC:a,endC:f,maxC:p,workJ:d,coldWorkJ:h,hotWorkJ:b}}function y1(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])&&cu(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 xh=1e5,k1=.001,Qn={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},vh={fullAtBar:10,maxPowerKw:0,fadeBelowKmh:0,distribution:"equal"};var kh=S1(mu(Qn,"Formula Student brakes")),Mh=40,M1={ideal:!1,barFront:Qn.barFront,pedalForceMaxN:0,testSpeedKmh:Mh,regen:vh};function x1(e){let{heat:t,...r}=e;return t?{...r,heat:{...t,padCurve:{tempC:[...t.padCurve.tempC],factor:[...t.padCurve.factor]}}}:r}function S1(e){let t=(r,n)=>r.heat?r:{...r,heat:bh(r,n)};return{...e,front:t(e.front,"front"),rear:t(e.rear,"rear")}}function mu(e,t){return{name:t,pedalRatio:e.pedalRatio,masterFrontMm:e.masterFrontMm,masterRearMm:e.masterRearMm,valve:e.valve,valveKneeBar:e.valveKneeBar,valveSlope:e.valveSlope,front:x1(e.front),rear:x1(e.rear),adjusterPitchMm:e.adjusterPitchMm,barLengthMm:e.barLengthMm}}function Sh(e,t){return A1({...e,barFront:t.barFront,pedalForceMaxN:t.pedalForceMaxN})}function Ah(e,t){let r=Br(t),n=e?dr(e):void 0;return{mode:r.ideal?"tyre":n?"hydraulic":"balance",hydraulic:n?Sh(n,r):Qn,regen:r.regen}}var BD=["none","proportioning","limiter"],uu=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},Je=(e,t,r,n)=>Math.min(r,Math.max(t,uu(e,n))),$D=(e,t)=>{let r=uu(e,t);return r>0?r:t};function R1(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(uu(e?.discs,n==="inboard"?1:t.discs)))),pistonsPerSide:Math.max(1,Math.min(6,Math.round(uu(e?.pistonsPerSide,t.pistonsPerSide)))),pistonDiaMm:Je(e?.pistonDiaMm,5,80,t.pistonDiaMm),padMu:Je(e?.padMu,.05,1.5,t.padMu),effRadiusMm:Je(e?.effRadiusMm,20,300,t.effRadiusMm),ratio:n==="inboard"?Je(e?.ratio,1,20,t.ratio):1,...e?.heat&&typeof e.heat=="object"?{heat:gh(e.heat,t.heat??r)}:{}}}function A1(e){let t=Qn;return{pedalRatio:Je(e?.pedalRatio,.5,15,t.pedalRatio),pedalForceMaxN:Je(e?.pedalForceMaxN,0,5e3,t.pedalForceMaxN),barFront:Je(e?.barFront,.05,.95,t.barFront),masterFrontMm:Je(e?.masterFrontMm,8,40,t.masterFrontMm),masterRearMm:Je(e?.masterRearMm,8,40,t.masterRearMm),valve:BD.includes(e?.valve)?e?.valve:t.valve,valveKneeBar:Je(e?.valveKneeBar,0,200,t.valveKneeBar),valveSlope:Je(e?.valveSlope,0,1,t.valveSlope),front:R1(e?.front,t.front,oi),rear:R1(e?.rear,t.rear,iu),adjusterPitchMm:$D(e?.adjusterPitchMm,t.adjusterPitchMm),barLengthMm:Je(e?.barLengthMm,0,500,t.barLengthMm)}}function GD(e){let t=vh;return{fullAtBar:Je(e?.fullAtBar,0,200,t.fullAtBar),maxPowerKw:Je(e?.maxPowerKw,0,1e3,t.maxPowerKw),fadeBelowKmh:Je(e?.fadeBelowKmh,0,100,t.fadeBelowKmh),distribution:e?.distribution==="wheel"?"wheel":"equal"}}function dr(e){let t=A1(e??void 0),r=typeof e?.name=="string"&&e.name.trim()?e.name:KD;return mu(t,r)}function Br(e){return{ideal:e?.ideal===!0,barFront:Je(e?.barFront,.05,.95,Qn.barFront),pedalForceMaxN:Je(e?.pedalForceMaxN,0,5e3,0),testSpeedKmh:Je(e?.testSpeedKmh,5,150,Mh),regen:GD(e?.regen)}}var KD="Formula Student brakes";var Rh=e=>Math.PI/4*(e*k1)**2;function gn(e,t){let r=e.pistonsPerSide*Rh(e.pistonDiaMm)*xh;return e.discs*2*e.padMu*r*e.effRadiusMm*k1*e.ratio/Math.max(.05,t)}function F1(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 ai(e,t){let r=Math.max(0,t)*e.pedalRatio,n=e.barFront*r/Rh(e.masterFrontMm)/xh,o=(1-e.barFront)*r/Rh(e.masterRearMm)/xh;return{front:n,rearIn:o,rear:F1(e,o)}}function HD(e,t){let r=ai(e,1);return{front:gn(e.front,t)*r.front,rear:gn(e.rear,t)*r.rearIn}}function si(e,t){let r=HD(e,t);return r.front/Math.max(1e-12,r.front+r.rear)}function ii(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=w1(t,l),m=t.maxPowerKw>0&&l>0?t.maxPowerKw*1e3/l:1/0,f=Math.max(0,e.fFront[c]),p=Math.max(0,e.fRear[c]),d=f+p>0?Math.min(1,m/(f+p)):1;r.push(l),n.push(f*d*u),o.push(p*d*u)}}function w1(e,t){let r=e.fadeBelowKmh/3.6;return r>0?Math.max(0,Math.min(1,t/r)):1}function Vr(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 v1=new WeakMap;function Zn(e){let t=v1.get(e);return t||(t=e.mode==="hydraulic"&&e.hydraulic?YD(e,e.hydraulic):zD(e),v1.set(e,t)),t}function zD(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 YD(e,t){let r=gn(t.front,e.tyreRadiusM),n=gn(t.rear,e.tyreRadiusM),o=e.regen,a=(c,l)=>{let u=ai(t,c),m=0,f=0;if(o&&u.front>0){let p=o.fullAtBar>0?Math.min(1,u.front/o.fullAtBar):1;m=p*Vr(o.v,o.front,l),f=p*Vr(o.v,o.rear,l)}return{front:r*u.front+m,rear:n*u.rear+f,regenFront:m,regenRear:f,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 f=0;f<60;f++){let p=.5*(m+u);i(p,l)<c?m=p:u=p}return u}}}function Fh(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 pu=Vs,WD=.1,Jn=(e,t)=>e.a*Math.sqrt(Math.max(0,1-(t/Math.max(1e-9,e.b))**2));function du(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 f=0;f<48;f++)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 f of[t,r]){let p=e(f);p>m&&(u=f,m=p)}return u}function Th(e,t,r){let n=Math.max(0,r-pu*t.b),o=Math.min(r,pu*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 Ph(e,t,r,n,o=0){let a=Math.max(0,r),s=Th(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],f=u.Fz/Math.max(1e-9,u.Fz+m.Fz),p=Math.max(0,Math.min(1,1-f/WD)),d=p>0&&a<pu*m.b?m.cap(a):0,h=d>l?l+p*(d-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:P=>2*Math.max(0,l-P)};let{lo:R,hi:k}=s,v=du(P=>{let S=Jn(e,P),F=Jn(t,a-P);return Math.min(S+F,2*Math.min(S,F)+y)},R,k),x=e.cap(v),M=t.cap(a-v),A=Math.max(2*l,Math.min(x+M,2*Math.min(x,M)+y)),w=(P,S,F)=>Math.min(y,Math.max(0,P-F))+Math.min(y,Math.max(0,S-F));return{...g,regenWheel:y,mixedMax:A,regenRoom:P=>{let S=w(i,c,P);if(!(a>0))return S;let F=D=>pu*D.b*Math.sqrt(Math.max(0,1-(P/Math.max(1e-9,D.a))**2)),C=Math.max(R,a-F(t)),L=Math.min(k,F(e));if(!(C<=L))return S;let E=du(D=>Math.min(y,Jn(e,D)-P)+Math.min(y,Jn(t,a-D)-P),C,L);return Math.max(S,w(e.cap(E),t.cap(a-E),P))}}}var wh=e=>Math.max(e.xNoLock,e.xLock),Ch=e=>Math.max(e.mixedMax,2*e.xLock);function Ra(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 va(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 ci(e,t,r,n){return e.shares?jD(e,e.shares,t,r,n):UD(e,t,r,n)}function C1(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 jD(e,t,r,n,o){let a=Ch(r),s=Ch(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=va(r,t.front*b),y=va(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,f=[{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&&f.push({u:b,by:"front"})}if(n.xLock>n.xNoLock){let b=t.rear>0?n.mixedMax/t.rear:1/0;b<i&&f.push({u:b,by:"rear"})}let{cand:p,force:d}=C1(f,l),h=e.demand(p.u,o);return{force:Math.max(0,Number.isFinite(d)?d:0),control:p.u,demand:h,limitedBy:p.by,lockFront:h.front/2>r.mixedMax/2*(1+1e-9),lockRear:h.rear/2>n.mixedMax/2*(1+1e-9)}}function UD(e,t,r,n){let o=wh(t),a=wh(r),s=v=>(v.front-v.regenFront)/2,i=v=>(v.rear-v.regenRear)/2,c=v=>{let x=e.demand(v,n);return s(x)<=o*(1+1e-12)&&i(x)<=a*(1+1e-12)},l=(v,x)=>{if(v(e.demand(x,n)))return x;let M=0,A=x;for(let w=0;w<60;w++){let T=.5*(M+A);v(e.demand(T,n))?M=T:A=T}return M},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),f=Number.isFinite(e.uMax)&&m>=e.uMax,p=v=>{let x=e.demand(v,n),M=Ra(t,s(x),x.regenFront),A=Ra(r,i(x),x.regenRear);return Number.isFinite(M)&&Number.isFinite(A)?M+A:-1/0},d=e.demand(m,n),h=o>0?s(d)/o:1/0,b=a>0?i(d)/a:1/0,g=[{u:m,by:f?"pedal":h>=b?"front":"rear"}];if(t.xLock>t.xNoLock){let v=l(x=>s(x)<=t.xNoLock,m);v<m&&g.push({u:v,by:"front"})}if(r.xLock>r.xNoLock){let v=l(x=>i(x)<=r.xNoLock,m);v<m&&g.push({u:v,by:"rear"})}let{cand:y,force:R}=C1(g,p),k=e.demand(y.u,n);return{force:Math.max(0,Number.isFinite(R)?R:0),control:y.u,demand:k,limitedBy:y.by,lockFront:s(k)>t.xNoLock*(1+1e-9),lockRear:i(k)>r.xNoLock*(1+1e-9)}}var $r={regen:!0,regenEfficiency:.6};function Gr(e,t){let r=e.energy??t??$r;return{regen:r.regen===!0,regenEfficiency:Math.min(1,Math.max(0,Number.isFinite(r.regenEfficiency)?r.regenEfficiency:0))}}function Kr(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 T1(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 bt(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 fu(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 d=o+a>>1;e[d]<=r?o=d:a=d}if(o===n-1)return t[n-1];let s=d=>e[d+1]-e[d],i=d=>(t[d+1]-t[d])/s(d),c=d=>{if(d===0||d===n-1){let[y,R]=d===0?[0,1]:[n-2,n-3],k=i(y)*(1+s(y)/(s(y)+s(R)))-i(R)*(s(y)/(s(y)+s(R)));return k*i(y)<=0?0:Math.abs(k)>2*Math.abs(i(y))?2*i(y):k}let h=i(d-1),b=i(d),g=(h*s(d)+b*s(d-1))/(s(d-1)+s(d));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),f=c(o+1),p=r-e[o];return t[o]+p*(m+p*((3*u-2*m-f)/l+p*(m+f-2*u)/(l*l)))}function li(e,t,r){return r.map(n=>bt(e,t,n))}var ui=e=>e.reduce((t,r)=>r>t?r:t,-1/0),ka=e=>e.reduce((t,r)=>r<t?r:t,1/0);var XD=[-.906179845938664,-.538469310105683,0,.538469310105683,.906179845938664],qD=[.236926885056189,.478628670499366,.568888888888889,.478628670499366,.236926885056189];function Lh(e,t,r){let n=.5*(r-t),o=.5*(t+r),a=0;for(let s=0;s<5;s++)a+=qD[s]*e(n*XD[s]+o);return n*a}var QD=Math.PI*2,ZD=.5/3.6;function mi(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 Dh(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*QD;c[g]=y*o/n,l[g]=s[g]*n/o}let u=ui(c),m=Kr(ka(c),u,u/ZD),f=li(c,l,m),{front:p,rear:d}=mi(t,r),h=f.map(g=>g*p),b=f.map(g=>g*d);return{vVehicle:m,fFront:h,fRear:b,vMax:u}}var P1=60/(2*Math.PI),L1=.1,D1=.08,E1=0;function Eh(e){let t=(r,n)=>r===void 0||!Number.isFinite(r)?n:Math.max(0,r);return{up:t(e.upshiftTime,L1),down:t(e.downshiftTime,D1)}}function Ih(e){let t=e.driveKept;return t===void 0||!Number.isFinite(t)?E1:Math.max(0,Math.min(1,t))}function _h(e,t,r){let{primary:n,ratios:o,efficiency:a}=e.gearbox,s=t>0&&r>0&&n>0,i=(b,g)=>b/P1*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,Ie(e.rpm,e.torque,b)),f=(b,g)=>{let y=c[g];return y?b*y.ratio/r*P1:0},p=(b,g)=>g===0&&c.length>0&&b<c[0].vIdle,d=(b,g)=>{let y=c[g];return y?p(b,g)?m(e.idleRpm)*y.ratio*l/r:b<y.vIdle||b>y.vLimit?0:m(f(b,g))*y.ratio*l/r:0},h=(b,g)=>{let y=c[g];return!y||p(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:f,torque:m,force:d,inertiaMass:h,slipping:p}}function Ma(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 Nh(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 I1=9.81,_1=Math.PI*2;function Et(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]*(_1/60),a[v]=t[v]/60*_1,s[v]=a[v]*u/l,i[v]=r[v]*l,c[v]=i[v]/u;let m=ui(s),f=m,p=.5/3.6,d=Kr(ka(s),m,m/p),h=li(s,c,d),b=Kr(ka(t),ui(t),250),g=li(t,o,b).map(v=>v*e.power_scale.value),y,R=f,k;if(e.motorModel?.kind==="ice"){k=_h(e.motorModel,l,u);let v=Kr(0,k.vMax,Math.max(2,Math.ceil(k.vMax/p)+1)),x=v.map(w=>Nh(k,w)),M=v.map(()=>0),A=e.motorPlacement==="front";y={vVehicle:v,fFront:A?x:M,fRear:A?M:x,vMax:k.vMax},R=k.vMax}else e.motorModel&&(y=Dh(e.motorModel,Math.max(1,Math.round(e.motorCount??e.driven_wheels.value)),e.motorPlacement??"rear",l,u),R=y.vMax);return{params:e,g:I1,FG:e.m.value*I1,vMax:R,vVehicle:d,fRad:h,uMotor:b,pMotor:g,vRad:s,fAxle:y,...k?{engine:k}:{}}}var yn=e=>e.motorModel?.kind==="ice"?mi(1,e.motorPlacement==="front"?"front":"rear"):mi(Math.max(1,Math.round(e.motorCount??e.driven_wheels?.value??2)),e.motorPlacement??"rear");function N1(e){let t=yn(e);return t.front>=2||t.rear>=2}function O1(e){return N1(e)?e.motorMount??"hub":"chassis"}function Oh(e){if(!e.motorModel)return{front:!1,rear:!0};let t=yn(e);return{front:t.front>0,rear:t.rear>0}}function Vh(e){let t=yn(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=O1(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 gt(e){return Ah(e.brakeModel,e.brakeSetup)}function hu(e){return Br(e.brakeSetup).ideal?"tyre":e.brakeModel||e.brakeModelId?"hydraulic":"balance"}function V1(e,t){if(!(dt(e.motorModel)||!Gr(e).regen))return ii(bu(Et(e)),t??gt(e).regen)}function bu(e){return e.fAxle??{vVehicle:e.vVehicle,fFront:e.vVehicle.map(()=>0),fRear:e.fRad.map(t=>t*e.params.driven_wheels.value)}}function Bh(e,t=gt(e)){if(t.mode==="hydraulic")return si(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+Q(e,"cg_height")/Math.max(1,Q(e,"wheelbase"))))}return Q(e,"brake_balance")}function $h(e,t=gt(e)){return{front:t.hydraulic.front.location==="inboard",rear:t.hydraulic.rear.location==="inboard"}}function Gh(e){let t=gt(e);return{brakeBalanceFront:Bh(e,t),brakeInboard:$h(e,t)}}function B1(e,t=gt(e)){if(t.mode==="tyre"||t.regen.distribution!=="wheel"||dt(e.motorModel))return;let r=yn(e),n={front:r.front>=2,rear:r.rear>=2};return n.front||n.rear?n:void 0}function pi(e){let t=gt(e),r=e.r_dyn.value,n=$h(e,t),o=Bh(e,t),a=B1(e,t),s=t.mode==="hydraulic"||a?V1(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 eE=9.81;function Kh(e,t){if(dt(e.motorModel))return()=>0;let r=gt(e),n=ii(t,r.regen);if(r.mode==="hydraulic"){let a=Zn({mode:"hydraulic",balanceFront:si(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 0;let c=a.demand(a.controlFor(s,i),i);return Math.min(s,c.regenFront+c.regenRear)}}let o=r.mode==="tyre"?tE(e):()=>Math.min(.99,Math.max(.01,Q(e,"brake_balance")));return(a,s,i)=>{if(!(a>0))return 0;let c=o(s,i);return Math.min(c*a,Vr(n.v,n.front,s))+Math.min((1-c)*a,Vr(n.v,n.rear,s))}}function tE(e){let t=e.m.value*eE,r=e.front_mass_diss.value>1?e.front_mass_diss.value/100:e.front_mass_diss.value,n=Q(e,"cg_height")/Math.max(1,Q(e,"wheelbase")),o=1-Math.max(0,Math.min(1,Q(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 $1(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 Hh={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"},...$1("front"),...$1("rear")},zh={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 Yh(e){let t=Hh[e];return`${t.label}, ${t.section}`.toLowerCase()}function Wh(e){let t=zh[e];return t.section?`${t.section} ${t.label.charAt(0).toLowerCase()}${t.label.slice(1)}`:t.label}var G1=new WeakMap;function fr(e){if(e.brakes)return e.brakes;let t=G1.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},G1.set(e,t)}return t}var Hr=e=>Zn(fr(e));var aE=Math.PI/180,Sa=Object.freeze({tbr:1,preloadN:0}),gu=Object.freeze({tbr:1/0,preloadN:0}),Uh=e=>e.faces*e.muClutch*e.rFrictionMm/e.rRampMm;function Xh(e,t){if(!(e>0)||Number.isNaN(t))return 0;let r=Math.tan(Math.min(90,t)*aE);return r>0?Math.min(1,e/r):1}function H1(e){if(e>=1)return 1/0;let t=e>0?e:0;return(1+t)/(1-t)}function yu(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)+yu(e.tbr)*Math.abs(t)}function fi(e,t,r){let n=o=>o!==void 0&&o>0&&r>0?o/r:0;switch(e.kind){case"open":return Sa;case"spool":return gu;case"independent":return t==="hubs"?Sa:gu;case"clutch":{let o=n(e.preloadNm);return t==="hubs"?{tbr:1,preloadN:o}:{tbr:H1(Xh(Uh(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 di(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 K1=4;function jh(e,t){let r=0;for(let a of e)r=Math.max(r,di(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=f=>{f>0&&f<1&&(r=Math.max(r,di(s.m1+f*i,s.m2+f*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 hi(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=Th(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=du(b=>Jn(e,b)+Jn(t,c-b),l.lo,l.hi),f=[{m1:l.c1,m2:l.c2}];for(let b=1;b<=K1&&m!==l.y1;b++){let g=l.y1+(m-l.y1)*b/K1;f.push({m1:e.cap(g),m2:t.cap(c-g)})}let p=jh(f,Sa),d=jh(f,gu);if(!(d>p))return u;let h=(jh(f,{tbr:s,preloadN:i})-p)/(d-p);return Math.min(a,u+(a-u)*Math.min(1,Math.max(0,h)))}function z1(e,t,r,n,o,a){return qh(e,o,hi(t,r,n,o,a))}function qh(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 Qh(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,f=l-s,p=f!==0?i-l*(i-o)/f:NaN;m?p>Math.min(o,i)&&p<Math.max(o,i)||(p=.5*(o+i)):Number.isFinite(p)?Math.abs(p-i)>10*Math.abs(l)&&(p=i+Math.sign(p-i)*10*Math.abs(l)):p=c;let d=e(p),h=d-p;if(u++,m&&h<0==l<0?s*=.5:(o=i,s=l),i=p,c=d,l=h,s<0!=l<0&&Math.abs(i-o)<=r)break}return{x:i,fx:c,evals:u}}function Y1(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),f=0;for(let p=o;l<a;p*=2){if(f=Math.min(f+p,m),f>m-n)return null;let d=t+u*f,h=e(d),b=h-d;if(l++,!(Math.abs(b)>n))return{x:d,fx:h,evals:l};if(c<0!=b<0)return j1(e,s,c,d,h,b,n,l,a);s=d,c=b}return null}function W1(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 j1(e,o,s,c,u,m,r,l,n);if(l>=n)return{x:c,fx:u,evals:l};let f=Math.abs(c-o),p=s!==m?m*(c-o)/(s-m):NaN,d=p*i>0?Math.min(Math.abs(p),10*Math.abs(m),2*f):2*f;o=c,s=m,c+=i*d}}function j1(e,t,r,n,o,a,s,i,c){let l=t,u=r,m=n,f=a,p=n,d=o,h=0;for(;i<c&&Math.abs(m-l)>s;){p=(l*f-m*u)/(f-u),d=e(p);let b=d-p;if(i++,!(Math.abs(b)>s))break;b<0==u<0?(l=p,u=b,h===-1&&(f*=.5),h=-1):(m=p,f=b,h===1&&(u*=.5),h=1)}return{x:p,fx:d,evals:i}}function xu(e,t){return Math.abs(e.fx-e.x)>t?e.x:e.fx}var sE=(e,t)=>{let r=e.brakes?.hydraulic?.[t];return!!r&&r.location==="inboard"&&r.discs===1};function Wt(e,t,r){let n=e.driveline?.[t];if(n)return r>=0?n.drive:sE(e,t)?n.coast:n.hubs}var U1=e=>e.tbr>1||e.preloadN>0;var iE=9.81,X1=["FL","FR","RL","RR"],Zh=e=>e==="FL"||e==="FR",Ru=e=>Zh(e)?"front":"rear",q1={front:["FL","FR"],rear:["RL","RR"]},yi=()=>({peak:new Map,freeBrake:new Map}),gi=25;function bi(e,t){let r=Math.max(0,e)/gi,n=Math.floor(r),o=r-n,a=t(n);return o>0?a+o*(t(n+1)-a):a}var xn=1e-4,cE=.05;function zr(e,t,r,n=yi(),o=!1){let a=r,s=e.massTotal,i=n.peak,c=(S,F)=>{let C=`${S}:${F}`,L=i.get(C);return L||(L=Dl(ye(t,S),Math.max(1,F*gi)),i.set(C,L)),L},l=(S,F)=>({aPeak:bi(F,C=>c(S,C).aPeak),fyPeak:bi(F,C=>c(S,C).fyPeak)}),u=n.freeBrake,m=(S,F)=>{let C=`${S}:${F}`,L=u.get(C);if(L===void 0){let E=Math.max(1,F*gi);L=Lt(ye(t,S),E,0,!0,c(S,F)),u.set(C,L)}return L},f=(S,F)=>F>0?bi(F,C=>m(S,C)):0,p=Hr(e),d=fr(e),h=S=>d.regen&&d.regenPerWheel?.[S]?Vr(d.regen.v,d.regen[S],a)/2:0,b=h("front"),g=h("rear"),y=(S,F,C)=>{let L=Math.max(0,F[S]),E=l(Ru(S),L);return Lt(ye(t,Ru(S)),L,C[S]*E.fyPeak,!0,E)},R=(S,F,C,L,E=!0)=>{let D=ne=>{let de=Math.max(0,F[ne]),W=ye(t,S),Z=l(S,de);return{Fz:de,a:Math.abs(f(S,de)),b:Z.fyPeak,slide:de>0?Math.abs(W.forces({Fz:de,kappa:-1,alpha:0}).Fx):0,cap:re=>Math.abs(Lt(W,de,re,!0,Z))}},O=ne=>Math.abs(C[ne])*l(Ru(ne),Math.max(0,F[ne])).fyPeak,[_,z]=q1[S],I=D(_),N=D(z),B=O(_)+O(z),V=Ph(I,N,B,L,S==="front"?b:g),G=E?V:{...V,xLock:0},H=Wt(e,S,-1),Y=H&&U1(H)?H:void 0;if(!Y)return{axle:S,eq:G,cap:G};let J=Number.isFinite(L)?L:I.cap(O(_))+N.cap(O(z)),j=z1(G,I,N,B,Y,J);return{axle:S,eq:G,cap:j,law:Y,strong:()=>I.cap(O(_))>=N.cap(O(z))?_:z}},k=(S,F,C,L)=>R(S,F,C,L).cap,v=(S,F,C)=>{let L=S.demand,E=p.shares?va(F,L.front):Ra(F,(L.front-L.regenFront)/2,L.regenFront),D=p.shares?va(C,L.rear):Ra(C,(L.rear-L.regenRear)/2,L.regenRear);return{front:Number.isFinite(E)?E:0,rear:Number.isFinite(D)?D:0}},x=S=>({muX:F=>F>0?Math.abs(f(S,F))/F:0,muY:F=>F>0?l(S,F).fyPeak/F:0}),M={front:x("front"),rear:x("rear")},A={lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},w={front:e.trackFront/2e3,rear:e.trackRear/2e3},T=(S,F,C,L,E)=>{let D=L.cap,O=E.cap,_=ci(p,D,O,a),z={arms:A,halfTrack:w,ayDir:Math.sign(S)};for(let I=0;I<2;I++){let N=v(_,D,O),B={};for(let G of X1){let H=Math.max(0,F[G]);B[G]={Fz:H,Fy:Math.abs(C[G])*l(Ru(G),H).fyPeak,Fx:-(Zh(G)?N.front:N.rear)/2}}let V=G=>{if(!G.law||!G.strong)return G.cap;let H={axle:G.axle,strong:G.strong(),full:2*G.cap.xNoLock,open:2*G.eq.xNoLock,sense:-1};return qh(G.eq,G.law,Jl(H,B,M,z))};D=V(L),O=V(E),_=ci(p,D,O,a)}return{limit:_,front:D,rear:O}};return{peakAt:l,axle:k,ceiling:(S,F,C)=>{let[L,E]=q1[S];return Math.abs(y(L,F,C)+y(E,F,C))},limitAt:(S,F,C,L=0)=>{let E={FL:0,FR:0,RL:0,RR:0},D=Te(e,S,0,a,0,F),O,_=de=>(O?.ax!==de&&(O={ax:de,loads:Te(e,S,(de+L)/iE,a,0,F)}),O.loads),z=El(de=>pa(C,_(de),D,l).short,-L,-1),I=C,N={front:0,rear:0},B,V,G=(de,W=!0)=>{let Z=z.at(de);E=_(Z),I=pa(C,E,D,l).util;let re=0,me=0,pe=0;for(let ie of X1){let ae=y(ie,E,I);re+=ae,Zh(ie)?me+=ae:pe+=ae}if(N={front:Math.abs(me),rear:Math.abs(pe)},p.mode!=="tyre"){let ie=R("front",E,I,Math.abs(me),W),ae=R("rear",E,I,Math.abs(pe),W);if(o&&(ie.law||ae.law)){let ce=T(S,E,I,ie,ae);B=ce.limit,V={front:ce.front,rear:ce.rear}}else B=ci(p,ie.cap,ae.cap,a),V={front:ie.cap,rear:ae.cap};re=-B.force}return re/s},H=Qh(G,0,xn),Y=xu(H,xn),J=Y;if(B?.lockFront||B?.lockRear){let de=Qh(Z=>G(Z,!1),0,xn);J=xu(de,xn);let W=Y1(G,de.x,H.x,xn,cE);W||G(H.x),Y=xu(W??H,xn)}let j=z.edge(),ee=j!==void 0&&Y<j;ee&&(Y=Math.min(0,j),G(Y),J=Math.max(J,Y));let ne={loads:E,ceiling:N,limit:B,axles:V};return{ax:Y,axUnlocked:J,...ee?{edge:j}:{},...ne,split:()=>ne.limit&&ne.axles?v(ne.limit,ne.axles.front,ne.axles.rear):{...ne.ceiling}}}}}var ku=9.81;function lE(e,t,r){let n=Te(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 J1=(e,t)=>t.mode==="hydraulic"&&!!fr(e).regen;function Fa(e,t,r=0,n,o=0){if(!e.brakes&&e.brakeBalanceFront==null)return e.frontMassFrac;let a=Hr(e);if(a.shares&&a.mode!=="tyre")return a.shares.front;let s=n&&J1(e,a)?ek(e,n):void 0,i=s?.shares??Q1.get(e);i||Q1.set(e,i=new Map);let c=Math.round(Math.abs(t)/.005),l=Math.round(Math.max(0,r)/.25),u=s?Math.round(o/.01):0,m=tk(c,l,u),f=i.get(m);if(f===void 0){let p=-c*.005,d=l*.25,h=e.massTotal*Math.abs(p)*ku;if(s){let b=nk(a,rk(e,s,c,l,u),h,d);f=b.front+b.rear>0?b.front/(b.front+b.rear):.5}else f=a.mode==="tyre"?lE(e,p,d):Fh(a,h,d);i.size>5e4&&i.clear(),i.set(m,f)}return f}var Q1=new WeakMap;function Mu(e,t,r,n,o=0){let a=Hr(e);if(!J1(e,a))return;let s=Math.round(Math.max(0,r)/(e.massTotal*ku)/.005),i=Math.round(Math.max(0,n)/.25);return nk(a,rk(e,ek(e,t),s,i,Math.round(o/.01)),Math.max(0,r),n)}var Z1=new WeakMap;function ek(e,t){let r=Z1.get(e);r||Z1.set(e,r=new WeakMap);let n=r.get(t);return n||r.set(t,n={ev:t,tyres:yi(),shares:new Map,rooms:new Map,speeds:new Map}),n}var tk=(e,t,r)=>(r*1001+e)*100003+t;function rk(e,t,r,n,o){let a=tk(r,n,o),s=t.rooms.get(a);if(!s){let i=n*.25,c=o*.01,l=t.speeds.get(n);l||(l={cap:zr(e,t.ev,i,t.tyres),dragG:-Math.max(0,xs(e,i).drag)/(e.massTotal*ku)},t.speeds.set(n,l));let{cap:u}=l,m=Te(e,c,-r*.005+l.dragG,i),f=Math.abs(c)*e.massTotal*ku,p=b=>{let[g,y]=b==="front"?["FL","FR"]:["RL","RR"],R=f*(b==="front"?e.frontMassFrac:1-e.frontMassFrac),k=u.peakAt(b,Math.max(0,m[g])).fyPeak+u.peakAt(b,Math.max(0,m[y])).fyPeak,v=R>0&&k>0?Math.min(1,R/k):0;return u.axle(b,m,{FL:v,FR:v,RL:v,RR:v},1/0)},d,h;s=(b,g)=>(b==="front"?d??=p("front"):h??=p("rear")).regenRoom(g),t.rooms.size>5e4&&t.rooms.clear(),t.rooms.set(a,s)}return s}function vu(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 nk(e,t,r,n){if(!(r>0))return vu(e,t,1,n);let o=c=>c.front+c.rear,a=e.controlFor(r,n),s=vu(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=vu(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=vu(e,t,l,n);o(u)<r?a=l:(i=l,s=u)}return s}var wa={rel:.003,abs:2,kappa:1e-5,iters:12},Jh={rel:1e-6,abs:.001,kappa:1e-12,iters:40};function eo(e,t,r,n=wa){let o=t>=0?1:-1,a=Math.abs(t),s=Math.max(n.abs,n.rel*a),i=e(0);if(Math.abs(i.Fx)-a>=0)return{kappa:0,forces:i};let c=0,l=i,u=Math.abs(i.Fx)-a,m=Math.min(.3,Math.max(.004,Math.abs(r)||.02)),f=e(o*m),p=Math.abs(f.Fx)-a,d=null;for(;p<0&&m<.3;){let g=Math.min(.3,m*1.9),y=e(o*g),R=Math.abs(y.Fx);if(R<Math.abs(f.Fx)){d={kappa:g,forces:y};break}c=m,l=f,u=p,m=g,f=y,p=R-a}if(p<0){let g=pE(e,o,c,l,m,f,d),y=Math.abs(g.forces.Fx);if(y<a)return{kappa:o*g.kappa,forces:g.forces};m=g.kappa,f=g.forces,p=y-a}let h=f,b=o*m;for(let g=0;g<n.iters&&m-c>n.kappa;g++){let y=p-u,R=Math.abs(y)>1e-12?(c*p-m*u)/y:.5*(c+m);R>c&&R<m||(R=.5*(c+m));let k=e(o*R),v=Math.abs(k.Fx)-a;if(h=k,b=o*R,Math.abs(v)<s)break;v<0?(c=R,u=v,p*=.5):(m=R,p=v,u*=.5)}return{kappa:b,forces:h}}var ok=1e-6,uE=40,mE=(3-Math.sqrt(5))/2;function pE(e,t,r,n,o,a,s){let i=a,c,l,u,m=-Math.abs(a.Fx),f,p,d=-Math.abs(n.Fx);if(s){c=s.kappa;let g=-Math.abs(s.forces.Fx);[l,f,u,p]=g<=d?[c,g,r,d]:[r,d,c,g]}else{c=.3;let g=.3*(1-ok),y=e(t*g),R=-Math.abs(y.Fx);if(R>=m)return{kappa:o,forces:a};[l,f,u,p]=[o,m,r,d],o=g,m=R,i=y}d<m&&([l,f]=[o,m],o=r,m=d,i=n);let h=c-r,b=0;for(let g=0;g<uE;g++){let y=ok*Math.abs(o)+1e-10,R=.5*(r+c);if(Math.abs(o-R)<=2*y-.5*(c-r))break;let k=!0;if(Math.abs(h)>y){let A=(o-l)*(m-p),w=(o-u)*(m-f),T=(o-u)*w-(o-l)*A;w=2*(w-A),w>0&&(T=-T),w=Math.abs(w);let P=h;if(h=b,Math.abs(T)<Math.abs(.5*w*P)&&T>w*(r-o)&&T<w*(c-o)){b=T/w;let S=o+b;(S-r<2*y||c-S<2*y)&&(b=R>=o?y:-y),k=!1}}k&&(h=o>=R?r-o:c-o,b=mE*h);let v=Math.abs(b)>=y?o+b:o+(b>=0?y:-y),x=e(t*v),M=-Math.abs(x.Fx);M<=m?(v>=o?r=o:c=o,u=l,p=f,l=o,f=m,o=v,m=M,i=x):(v<o?r=v:c=v,M<=f||l===o?(u=l,p=f,l=v,f=M):(M<=p||u===o||u===l)&&(u=v,p=M))}return{kappa:o,forces:i}}var Su=e=>Math.max(2,.003*Math.abs(e)),dE=(e,t)=>Math.max(t.abs,t.rel*Math.abs(e)),eb=.5,fE=.03;function hE(e,t,r,n,o){let a=.5*(e.vx+t.vx),s=v=>{let x=(1+v)*a/e.vx-1,M=(1+v)*a/t.vx-1,A=e.at(x),w=t.at(M);return{kappaM:v,kl:x,kr:M,fl:A,fr:w,g:A.Fx+w.Fx-r}},i=dE(r,o),c=Math.max(-eb,Math.min(eb,n)),l=s(c);if(Math.abs(c)>fE){let v=s(.8*c);(l.g-v.g)/(c-v.kappaM)>0||(l=s(0))}if(Math.abs(l.g)<i)return l;let u=l.g<0?1:-1,m=l,f=l,p=.004,d=l;for(let v=0;v<12;v++){let x=m.kappaM+u*p;if(Math.abs(x)>eb)break;let M=s(x);if(Math.abs(M.g)<i)return M;if(Math.abs(M.g)<Math.abs(d.g)&&(d=M),Math.sign(M.g)!==Math.sign(m.g)){f=M;break}if(u*(M.g-m.g)<=0)return d;m=M,p*=1.9}if(f===l)return d;let h=m,b=f,g=h.g,y=b.g,R=Math.abs(g)<Math.abs(y)?h:b,k=Math.min(1e-7,o.kappa);for(let v=0;v<30&&Math.abs(b.kappaM-h.kappaM)>k;v++){let x=y-g,M=Math.abs(x)>1e-12?(h.kappaM*y-b.kappaM*g)/x:.5*(h.kappaM+b.kappaM),A=Math.min(h.kappaM,b.kappaM),w=Math.max(h.kappaM,b.kappaM);M>A&&M<w||(M=.5*(A+w));let T=s(M);if(R=T,Math.abs(T.g)<i)break;Math.sign(T.g)===Math.sign(g)?(h=T,g=T.g,y*=.5):(b=T,y=T.g,g*=.5)}return R}function ak(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 tb(e,t,r,n,o,a=wa){let s=hE(e,t,r,o,a),i=s.fr.Fx-s.fl.Fx,c=Aa(n,r);if(Math.abs(i)<=c){let R=r-(s.fl.Fx+s.fr.Fx),k=Math.max(0,Math.abs(R)-Su(r))/2;return{left:{kappa:s.kl,forces:s.fl,want:s.fl.Fx+R/2,short:k},right:{kappa:s.kr,forces:s.fr,want:s.fr.Fx+R/2,short:k},locked:!0,spoolKappa:s.kappaM}}let l=Math.sign(i),u=r/2-l*c/2,m=r/2+l*c/2,f=eo(e.at,u,e.seed||s.kl,a),p=eo(t.at,m,t.seed||s.kr,a),d=Math.abs(u-f.forces.Fx)>Su(u),h=Math.abs(m-p.forces.Fx)>Su(m),b=Math.max(0,n.preloadN),g=yu(n.tbr);d&&!h?p=eo(t.at,ak(f.forces.Fx,l,b,g),p.kappa,a):h&&!d&&(f=eo(e.at,ak(p.forces.Fx,-l,b,g),f.kappa,a));let y=(R,k)=>({kappa:R.kappa,forces:R.forces,want:k,short:Math.max(0,Math.abs(k-R.forces.Fx)-Su(k))});return{left:y(f,u),right:y(p,m),locked:!1,spoolKappa:s.kappaM}}var bE={front:["FL","FR"],rear:["RL","RR"]},gE=Object.freeze({Fx:0,Fy:0,Mz:0});function Au(e,t,r,n){let o=r;for(let a of["front","rear"]){let[s,i]=bE[a],c=r[s]+r[i],l=Wt(e,a,c);if(!l||!(Aa(l,c)>0))continue;let u=ye(t,a),m=n.alpha[a],f=(a==="front"?e.trackFront:e.trackRear)/2e3,p=(h,b)=>{let g=Math.max(0,n.Fz[h]);return{at:g>0?y=>u.forces({Fz:g,kappa:y,alpha:m,gamma:0}):()=>gE,vx:Math.max(.05,1-b*n.curvature),seed:0}},d=tb(p(s,f),p(i,-f),c,l,n.seed?.[a]??0);n.seed&&(n.seed[a]=d.spoolKappa),o===r&&(o={...r}),o[s]=d.left.want,o[i]=d.right.want}return o}var Ae=9.81,se=Math.PI/180,yE=8,xE=1e-6,vn=["FL","FR","RL","RR"],Jt=e=>e==="FL"||e==="FR",Rn=e=>Jt(e)?"front":"rear";function Ri(e,t){let r=ye(e,"front"),n=ye(e,"rear");return r===n?ro(r,t):{front:ro(r,t),rear:ro(n,t)}}function ro(e,t){return jf(e,Math.min(t,Zt(e)))}var wu=e=>e==="FL"||e==="RL";function Ta(e,t,r=0,n,o=0){let a=t?.axG??0,s=Number.isFinite(t?.tvRearDiffN)?t?.tvRearDiffN:0;if(!(!!a&&Number.isFinite(a))&&!s)return null;let c=e.massTotal*a*Ae,l=a>=0?Math.min(1,Math.max(0,t?.driveFrontFrac??0)):Math.min(.99,Math.max(.01,Fa(e,a,r,n,o))),u=c*l/2,m=c*(1-l)/2;return{axG:a,fx:{FL:u,FR:u,RL:m-s/2,RR:m+s/2}}}function cb(e,t,r,n){return Math.abs(no(e,t,r,n!==void 0?{steerMaxDeg:n}:{}).peak.steerDeg)}function lb(e,t,r,n){let o=e.tv;if(!o?.enabled)return 0;let a=Fk(o)(t,Math.abs(r),n);return r<0?-a:a}function ub(e,t,r=0,n,o=0,a=0,s){let i=Ta(e,{axG:t,driveFrontFrac:a},r,n,o),c=i?i.fx:{FL:0,FR:0,RL:0,RR:0};return i&&s&&n?Au(e,n,c,s):c}var vi=e=>wu(e)?-1:1,mb=(e,t,r,n,o)=>t*e.Fy(t*r,n,t*o);function sb(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 RE(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?ca(o,n/se,u?r.FL:r.FR,u?r.FR:r.FL):la(o,n/se);return{innerMag:m.innerDeg*se,outerMag:m.outerDeg*se,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)),f=Math.atan(s/(u+a/2));c=n+i*(m-n),l=n+i*(f-n)}return{innerMag:c,outerMag:l,innerCamber:0,outerCamber:0,atLock:!1}}function oo(e,t,r){let n=(e.toeFrontDeg??0)*se,o=(e.toeRearDeg??0)*se,a=RE(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 pb(e,t,r){if(r.Fz<=0)return 0;let n=ht(ye(e,Rn(t))),o=vi(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 sk(e,t,r,n){if(!Xn(e))return null;let o=ht(ye(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:pb(o,s,i)}}return qs(e,r/se,a,fn(o.model),{FL:n.FL.travelMm,FR:n.FR.travelMm})}var ik=()=>({totalNm:[],aligningNm:[],lateralNm:[],longitudinalNm:[],jackingNm:[]});function ck(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 vE=Object.freeze({Fx:0,Fy:0,Mz:0});function lk(e,t,r){let n=t==="front"?(r?.FL??0)+(r?.FR??0):(r?.RL??0)+(r?.RR??0),o=Wt(e,t,n);return o&&Aa(o,n)>0?{F:n,law:o}:null}function It(e,t,r,n,o,a,s,i,c){let l=s?.fx,u=s?.axG??0,{wb:m,lf:f,lr:p,m:d}=sb(e),h=lk(e,"front",l),b=lk(e,"rear",l),g={front:0,rear:0},y=i!==void 0&&i>0&&Number.isFinite(i)?i:null,R=W=>y===null?r:Math.sqrt(Math.max(0,W)*y),k=ht(ye(t,"front")),v=ht(ye(t,"rear")),x=e.trackFront/2e3,M=e.trackRear/2e3,A=!!(e.kinFront&&e.kinRear),w=A&&y===null?bn(e,e.kinFront,e.kinRear,r):null,T=NaN,P=null,S=W=>{if(!A)return null;if(y===null)return w;let Z=R(W);return Z!==T&&(T=Z,P=bn(e,e.kinFront,e.kinRear,Z)),P},F={},C={FL:0,FR:0,RL:0,RR:0},L=e.kinFront?.compliance,E=e.kinRear?.compliance,D=!!(L||E),O=!!(L?.toePerMz||E?.toePerMz),_=W=>Jt(W)?L:E,z={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}},I=!1,N=W=>{let Z=W/r,re=y===null?n+f*Z/r:n+f/y,me=y===null?n-p*Z/r:n-p/y,pe=S(W),ie=R(W),ae=pe?pe(W/Ae,u,n/se,o/se):null,ce=ae?{FL:ae.FL.travel,FR:ae.FR.travel}:void 0,_e=Pl(e,W/Ae,u,ie,n/se,o/se,ce,ae?.steeringJacking),Fe=_e.loads;I=_e.overturned;let Re=oo(e,o,ce),ue=Re.steer,we=0,Ke=xe=>{let ve=Math.max(0,Fe[xe]),Le=vi(xe),he=Jt(xe)?k:v,be=_(xe),Ue=0,ke=0;if(be){let Vn=z[xe];Ue=be.toePerFy*Vn.fy+be.toePerFx*Vn.fx+be.toePerMz*Vn.mz,ke=be.camberPerFy*Vn.fy+be.camberPerFx*Vn.fx}let Xe=ue[xe]+(ae?Le*ae[xe].bumpToe*se:0)+Le*Ue*se,Bt=Xe-(Jt(xe)?re:me),Ct=(ae?ae[xe].camberRoad:0)*se+Le*(Re.camber[xe]+ke)*se;return{Fz:ve,mir:Le,t:he,gains:be,complianceToe:Ue,steerK:Xe,slip:Bt,camberRad:Ct}},tt=(xe,ve)=>{let Le=y===null?Z/r:1/y,he=Jt(xe)?f:-p,be=(wu(xe)?1:-1)*(Jt(xe)?x:M),Ue=(Math.cos(n)-be*Le)*Math.cos(ve.steerK)+(Math.sin(n)+he*Le)*Math.sin(ve.steerK);return{at:ve.Fz>0?ke=>ve.t.forces({Fz:ve.Fz,kappa:ke,alpha:ve.mir*ve.slip,gamma:ve.mir*ve.camberRad}):()=>vE,vx:Math.max(.05,Ue),seed:C[xe]}};for(let xe=0;xe<(D?yE:1);xe++){we=0;let ve=0,Le={};for(let he of vn){let be=Jt(he)?h:b;if(be&&!Le[he]){let[Yo,$t]=Jt(he)?["FL","FR"]:["RL","RR"],tl=Ke(Yo),px=Ke($t),dx=Rn(he),cd=tb(tt(Yo,tl),tt($t,px),be.F,be.law,g[dx],Jh);g[dx]=cd.spoolKappa,Le[Yo]={w:tl,share:cd.left},Le[$t]={w:px,share:cd.right}}let Ue=Le[he]?.w??Ke(he),{Fz:ke,mir:Xe,t:Bt,gains:Ct,complianceToe:Vn,steerK:od,slip:ad,camberRad:sd}=Ue,hs=l?.[he]??0,Ko,Ho=0,id=0,el=0,zo=Le[he]?.share;if(zo)C[he]=zo.kappa,id=zo.kappa,Ho=zo.forces.Fx,el=zo.short,Ko=Xe*zo.forces.Fy;else if(hs===0||ke<=0)Ko=mb(Bt,Xe,ad,ke,sd),el=ke<=0?Math.abs(hs):0;else{let $t=eo(tl=>Bt.forces({Fz:ke,kappa:tl,alpha:Xe*ad,gamma:Xe*sd}),hs,C[he],Jh);C[he]=$t.kappa,id=$t.kappa,Ho=$t.forces.Fx,el=Math.max(0,Math.abs(hs-Ho)-Math.max(wa.abs,wa.rel*Math.abs(hs))),Ko=Xe*$t.forces.Fy}if(F[he]={Fz:ke,travelMm:ae?.[he].travel??0,steerRad:od,slipRad:ad,camberRad:sd,Fy:Ko,Fx:Ho,kappa:id,fxShort:el,lifted:_e.lifted[he]},Ct){let Yo=O&&Ct.toePerMz?pb(Bt,he,F[he]):0;z[he]={fy:-Xe*Ko,fx:Ho,mz:-Xe*Yo*1e3};let $t=z[he];ve=Math.max(ve,Math.abs(Ct.toePerFy*$t.fy+Ct.toePerFx*$t.fx+Ct.toePerMz*$t.mz-Vn))}we+=Ko*Math.cos(od)+Ho*Math.sin(od)}if(ve<xE)break}return we/d},B=W=>{let Z=Te(e,0,u,W,0,o/se);return Z.FL+Z.FR+Z.RL+Z.RR},V=Math.max(20,3.5*B(r)/d);if(y!==null){V=4*Ae;for(let W=0;W<8;W++){let Z=Math.min(40*Ae,3.5*B(R(V))/d);if(Z<=V)break;V=Z}V=Math.max(20,V)}let G=W=>N(W)-W,H=Math.max(.001,V*1e-4),Y=(W,Z,re,me)=>{let pe=W,ie=re,ae=Z,ce=me,_e=pe;for(let Fe=0;Fe<40;Fe++){let Re=ce-ae,ue=Math.abs(Re)>1e-12?(pe*ce-ie*ae)/Re:.5*(pe+ie),we=Math.min(pe,ie),Ke=Math.max(pe,ie);ue>we&&ue<Ke||(ue=.5*(pe+ie));let tt=G(ue);if(_e=ue,Math.abs(tt)<1e-4||Ke-we<1e-6)break;tt<0==ae<0?(pe=ue,ae=tt,ce*=.5):(ie=ue,ce=tt,ae*=.5)}return _e},J=(W,Z,re,me=!1)=>{let pe=(Fe,Re)=>re>0?Fe>0&&Re<0:Re>0&&Fe<0,ie=W,ae=Z,ce=W+re*Math.min(Math.abs(Z),V);if(!me&&Math.abs(ce-W)>H){let Fe=G(ce);if(pe(ae,Fe))return{root:Y(ie,ae,ce,Fe),last:ie};ie=ce,ae=Fe}let _e=me?V/24:Math.max(V/24,Math.abs(ce-W)/4);for(let Fe=1;Fe<=24;Fe++){let Re=ie+re*_e;if(Math.abs(Re)>V)break;let ue=G(Re);if(pe(ae,ue))return{root:Y(ie,ae,Re,ue),last:ie};if(me&&ue*re<0&&(ue-ae)*re<0)break;ie=Re,ae=ue}return{root:null,last:ie}},j=c??null;if(c===void 0&&a!==void 0&&Number.isFinite(a)&&Math.abs(a)<=V){let W=G(a);if(Math.abs(W)<=1e-4)G(a+H)<0&&G(a-H)>0&&(j=a);else{let Z=J(a,W,Math.sign(W)).root;j=Z!==null&&(Z===0||Math.sign(Z)===Math.sign(a))?Z:null}}let ee=j===null;if(j===null){let W=G(0),Z=G(H),re=Math.abs(W)<=1e-4,me=re?y!==null?1:o!==0?Math.sign(o):Z>0?1:-1:Math.sign(W),pe=re?me*H:0,ie=re?me>0?Z:G(-H):W,ae=J(pe,ie,me);j=ae.root??(re?0:ae.last)}let ne=N(j);if(ee&&o!==0&&y===null){let W=Math.sign(o);if(j*W<=0||(F.RL.Fy+F.RR.Fy)*W<0){let Z={...F},re=I,me=W*Math.max(j*W+H,n*W*r*r/p),pe=null;if(me*W<V){let ie=G(me);if(ie*W>0)pe=J(me,ie,W).root;else{let ae=me+W*V/24,ce=G(ae);(ce-ie)*W>0&&(pe=J(ae,ce,W,ce*W<=0).root)}}pe!==null&&pe*W>0?(j=pe,ne=N(j)):(Object.assign(F,Z),I=re)}}let de=f*(F.FL.Fy*Math.cos(F.FL.steerRad)+F.FR.Fy*Math.cos(F.FR.steerRad))-p*(F.RL.Fy+F.RR.Fy);if(s||h||b){let W=Z=>(wu(Z)?1:-1)*(Jt(Z)?x:M);for(let Z of vn){let re=F[Z],me=Jt(Z)?f:-p;de+=me*re.Fx*Math.sin(re.steerRad)-W(Z)*re.Fx*Math.cos(re.steerRad)}}return y!==null&&j<-1e-6?{ay:NaN,cn:NaN,wheels:F,overturned:I,res:NaN}:{ay:j/Ae,cn:de/(d*Ae*m),wheels:F,overturned:I,res:ne-j}}function kE(e,t,r,n,o,a,s,i=0){let c=20*se,l=.001,u=(h,b)=>{let g=It(e,t,r,h,n,b,s);return{cn:g.cn-i,ay:g.ay*Ae}},m=h=>n===0||i!==0||Math.abs(h)<.05||Math.sign(h)===Math.sign(n),f=(h,b,g,y)=>{let R=u(h,y);if(Math.abs(R.cn)<1e-5)return{beta:h,trimmed:!0};let k=y===void 0?void 0:R.ay,v={pos:{b:h,cn:R.cn,ay:k},neg:{b:h,cn:R.cn,ay:k}},x=null,M=h,A=Math.abs(R.cn);for(let w=0;w<b.length&&!x;w++)for(let T of[v.pos,v.neg]){let P=T===v.pos?1:-1,S=h+P*b[w];if(Math.abs(S)>c)continue;let F=u(S,T.ay);if(Math.abs(F.cn)<A&&m(F.ay)&&(A=Math.abs(F.cn),M=S),F.cn===0&&m(F.ay))return{beta:S,trimmed:!0};if(F.cn<0!=T.cn<0){let C={lo:T.b,hi:S,ayLo:T.ay},L=uk(u,C),E=u(L,T.ay);if(Math.abs(E.cn)<l&&m(E.ay))return x=C,{beta:L,trimmed:!0}}T.b=S,T.cn=F.cn,y!==void 0&&(T.ay=F.ay)}return x?{beta:uk(u,x),trimmed:!0}:g?{beta:M,trimmed:!1}:null},p=[.25,.75,2,5].map(h=>h*se);if(o!==void 0&&Number.isFinite(o)&&Math.abs(o)<=c){let h=f(o,p,!1,a);if(h)return h;if(!s&&i===0&&a!==void 0&&Number.isFinite(a)){let b=ME(e,t,r,n,o,a,c);if(b&&m(b.ay))return{beta:b.beta,trimmed:!0,ay:b.ay}}}let d=[1,3,7,15,20].map(h=>h*se).filter(h=>h<=c);return f(0,d,!0)??{beta:0,trimmed:!1}}function uk(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),f=m.cn;if(o!==void 0&&(o=m.ay),i=u,Math.abs(f)<1e-5||Math.abs(n-r)<1e-5)break;f<0==a<0?(r=u,a=f,s*=.5):(n=u,s=f,a*=.5)}return i}function ME(e,t,r,n,o,a,s){let i=(f,p)=>{let d=It(e,t,r,f,n,void 0,null,void 0,p);return{r:d.res,c:d.cn}},c=o,l=a,u=i(c,l),m=0;for(let f=0;f<SE;f++){let p=i(c+rb,l),d=i(c,l+nb),h=(p.r-u.r)/rb,b=(d.r-u.r)/nb,g=(p.c-u.c)/rb,y=(d.c-u.c)/nb,R=h*y-b*g;if(!Number.isFinite(R)||R===0||Math.abs(R)<CE*(Math.abs(h*y)+Math.abs(b*g)))return null;if(f===0)m=Math.sign(R);else if(Math.sign(R)!==m)return null;if(Math.abs(u.r)<=1e-4&&Math.abs(u.c)<=1e-5)return{beta:c,ay:l};let k=(u.c*b-u.r*y)/R,v=(u.r*g-u.c*h)/R,x=Math.min(1,AE/Math.max(Math.abs(k),1e-300),FE/Math.max(Math.abs(v),1e-300));if(c+=x*k,l+=x*v,Math.abs(c-o)>wE||Math.abs(c)>s||l*a<0)return null;u=i(c,l)}return null}var SE=8,rb=1e-5,nb=.001,AE=1*se,FE=2,wE=5*se,CE=.5;function gk(e,t,r,n,o,a,s,i){let c=It(e,t,r,n,o,a,s,void 0,i),l=c.ay*Ae/r,u={},m=0;for(let d of vn){let h=c.wheels[d],b=ye(t,Rn(d)),g=Zt(b),y=b.muY(Math.min(h.Fz,g)),R=b.muX(Math.min(h.Fz,g));m+=h.fxShort,u[d]={Fz:h.Fz,steerDeg:h.steerRad/se,slipDeg:h.slipRad/se,camberDeg:h.camberRad/se,Fy:h.Fy,Fx:h.Fx,Mz:pb(b,d,h),gripUtil:y*h.Fz>0?Math.hypot(h.Fy/(y*h.Fz),R*h.Fz>0?h.Fx/(R*h.Fz):0):0,...h.Fz>g?{pastTurnover:!0}:{},lifted:h.lifted}}let f=qs(e,o/se,u,fn(ye(t,"front").model),{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}),p=oo(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/se,yawRate:l*180/Math.PI,steerDeg:o/se,...p.atLock?{lockDeg:(p.steer.FL+p.steer.FR)/2/se}:{},converged:!0,trimmed:!c.overturned,overturned:c.overturned,driving:!1,fxShortfall:m,...f?{steering:f}:{}}}function Wr(e,t,r,n,o,a,s=0){let i=Math.max(8,r),c=to(e,t,i,n,o,a,s);return n!==0&&o?.driving===void 0&&(c.driving=HE(e,t,i,c,a,s)),c}function to(e,t,r,n,o,a,s){let i=n*se,c=Ta(e,a,r,t),l=o&&Number.isFinite(o.ay)?o.ay*Ae:void 0,u=o&&Number.isFinite(o.beta)?o.beta*se:void 0,{beta:m,trimmed:f,ay:p}=kE(e,t,r,i,u,l,c,s),d=gk(e,t,r,m,i,l,c,p),h={...d,trimmed:f&&!d.overturned};return h.driving=n===0?h.trimmed:o?.driving!==void 0&&o.driving&&h.trimmed&&Math.abs(h.beta-o.beta)<=TE,h}var TE=3;function no(e,t,r,n={}){let o=Math.max(8,r),a=n.direction??1,s=n.yawDemandCn??0,i=n.steerMaxDeg??PE,c=typeof n.op=="function"?n.op:()=>n.op,l=typeof n.op=="function"?null:`${o}|${a}|${s}|${i}|${n.op?`${n.op.axG}|${n.op.driveFrontFrac??""}|${n.op.tvRearDiffN??""}`:""}`;if(l!==null){let x=ob.get(e)?.get(t)?.get(l);if(x)return x}let u=(x,M)=>M.trimmed&&Math.abs(M.beta-x.beta)<=Cu&&Math.abs(M.ay-x.ay)*Ae<=Tu,m=!1,f=(x,M)=>{let A=to(e,t,o,a*x,M,c(a*x),s);return u(M,A)?(A.driving=!0,A):(m=A.overturned,null)},p=[to(e,t,o,0,void 0,c(0),s)],d=null,h=!1,b,g=x=>{let M=p.length-1;for(;M>1&&x.sb*(p[M].beta-p[M-1].beta)>=0;)M--;let A=a*(x.state.ay-p[M].ay)>0,w=T=>x.sb*(T.beta-x.state.beta)>0||a*T.steerDeg>=a*x.state.steerDeg||A&&a*T.ay>=a*x.state.ay;for(;p.length>Math.max(2,M)&&w(p[p.length-1]);)p.pop();b={state:x.state,stall:p[p.length-1]},p.push(x.state),d=Math.abs(x.state.steerDeg)},y=(x,M=!1)=>M||$E(p[p.length-1],x)?GE(e,t,o,a,p,x,c,s):null,R=p[0].trimmed?p[0]:null;if(!R){let x=0;for(let M=mk;M<=i&&!R;M+=mk){let A=to(e,t,o,a*M,void 0,c(a*M),s);if(A.trimmed){let w=M;R=A;for(let T=0;T<6;T++){let P=.5*(x+w),S=to(e,t,o,a*P,void 0,c(a*P),s);S.trimmed?(w=P,R=S):x=P}}else x=M}R&&(R.driving=!0,p.push(R))}if(R){let x=Math.abs(R.steerDeg),M=Math.min(ab,100/(o*o)),A=R;for(;x<i;){let w=Math.min(i,x+M),T=f(w,A);if(T){let L=y(T);if(L){g(L);break}if(p.push(T),w>=i||Ak(e,a*w))break;Math.abs(T.beta-A.beta)<.5*Cu&&Math.abs(T.ay-A.ay)*Ae<.5*Tu&&(M=Math.min(ab,1.5*M)),x=w,A=T;continue}if(M>LE){M*=.5;continue}let P=m,S=!1,F=null;for(let L of DE){let E=Math.min(i,x+L);if(E<=x)continue;let D=f(E,A);if(D){if(F=y(D,!0),F)break;p.push(D),x=E,A=D,M=Math.min(ab,100/(o*o)),S=!0;break}}if(S)continue;if(F){g(F);break}d=x,h=P;let C=P?null:BE(e,t,o,a,p,c,s);C&&g(C);break}}else d=0;let k=p[0];for(let x of p)a*x.ay>a*k.ay&&(k=x);let v={states:p,foldDeg:d,rollover:h,peak:k,...b?{fold:b}:{}};if(l!==null){let x=ob.get(e);x||(x=new WeakMap,ob.set(e,x));let M=x.get(t);M||(M=new Map,x.set(t,M)),M.size>256&&M.clear(),M.set(l,v)}return v}var ob=new WeakMap,PE=90,Cu=1.5,Tu=2.5,ab=5,LE=.002,DE=[.5,1],mk=2.5,yk=.01,Yr=.001,EE=.05,IE=.25,_E=5,NE=2,pk=1e-8,OE=1e-7,VE=1e-6;function xk(e,t,r,n,o,a,s){let i=n*se,c=o.ay*Ae,l=b=>{let g=It(e,t,r,i,b*se,c,Ta(e,a(b),r,t));return{g:g.cn-s,ay:g.ay}},u=o.steerDeg,m=l(u),f=u+(u<0?-.001:.001),p=l(f),d=()=>p.g===0||Math.abs(f-u)<pk;for(let b=0;b<40&&Math.sign(m.g)===Math.sign(p.g)&&!d();b++){let g=(p.g-m.g)/(f-u),y=g!==0?f-p.g/g:f+2*(f-u);if(!Number.isFinite(y))return null;let R=2*Math.abs(f-u)+.001;if(y=f+Math.max(-R,Math.min(R,y-f)),u=f,m=p,f=y,p=l(f),Math.abs(f-o.steerDeg)>NE)return null}let h={x:f,ay:p.ay};if(Math.sign(m.g)!==Math.sign(p.g)){let b=u,g=m.g,y=f,R=p.g;for(let k=0;k<60&&R!==0&&Math.abs(y-b)>pk;k++){let v=(b*R-y*g)/(R-g),x=l(v);if(h={x:v,ay:x.ay},x.g===0)break;Math.sign(x.g)===Math.sign(g)?(b=v,g=x.g,R*=.5):(y=v,R=x.g,g*=.5)}}else if(!d())return null;return Math.abs(h.ay-o.ay)*Ae>Tu?null:{steerDeg:h.x,ay:h.ay}}function xi(e,t,r,n,o){let a=gk(e,t,r,n.beta*se,n.steerDeg*se,n.ay*Ae,Ta(e,o(n.steerDeg),r,t));return{...a,trimmed:!a.overturned,driving:!a.overturned}}function BE(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 f=Rk(e,t,r,a,s),p=f(u.beta,u),d=f(c.beta,c);if(!p||!d)return null;let h=n*d.steerDeg>=n*p.steerDeg,b=h?p:d,g=h?d:p,y=h?m:-m,R=null;for(let x=yk;Math.abs(g.beta-c.beta)<=Cu;x*=1.5){let M=f(g.beta+y*x);if(!M)return null;if(n*M.steerDeg<=n*g.steerDeg){R=M;break}b=g,g=M}if(!R)return null;let k=vk(f,n,b,g,R);if(!k)return null;let v=xi(e,t,r,k,a);return!v.trimmed||Math.abs(v.beta-c.beta)>Cu||Math.abs(v.ay-c.ay)*Ae>Tu?null:{state:v,sb:m}}function Rk(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=xk(e,t,r,s,i,n,o);if(!c)return null;let l={beta:s,...c};return a.push(l),l}}function $E(e,t){let r=Math.abs(t.beta-e.beta);return r>IE&&r>_E*Math.abs(t.steerDeg-e.steerDeg)}function GE(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],f=Math.sign(a.beta-l.beta);if(f===0||Math.sign(l.beta-m.beta)!==f||!m.driving)return null;let p=Rk(e,t,r,s,i),d=p(m.beta,m),h=p(l.beta,l);if(!d||!h||n*h.steerDeg<n*d.steerDeg)return null;let b=d,g=h,y=null;for(let R=yk;f*(a.beta-g.beta)>0;R=Math.min(EE,1.5*R)){let k=p(f*(a.beta-g.beta)>R?g.beta+f*R:a.beta);if(!k)return null;let v=n*k.steerDeg<=n*g.steerDeg;if(!y)v&&(y=[b,g,k]);else if(!v){let x=vk(p,n,...y);if(!x)return null;let M=xi(e,t,r,x,s);return M.trimmed?{state:M,sb:f}:null}b=g,g=k}return null}function vk(e,t,r,n,o){let a=p=>-t*p.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,f=0;for(let p=0;p<100;p++){let d=.5*(s+i);if(Math.abs(c.beta-d)<=2*Yr-.5*(i-s))break;let h=!0;if(Math.abs(m)>Yr){let g=(c.beta-l.beta)*(a(c)-a(u)),y=(c.beta-u.beta)*(a(c)-a(l)),R=(c.beta-u.beta)*y-(c.beta-l.beta)*g;y=2*(y-g),y>0&&(R=-R),y=Math.abs(y);let k=m;if(m=f,Math.abs(R)<Math.abs(.5*y*k)&&R>y*(s-c.beta)&&R<y*(i-c.beta)){f=R/y;let v=c.beta+f;(v-s<2*Yr||i-v<2*Yr)&&(f=d>=c.beta?Yr:-Yr),h=!1}}h&&(m=c.beta>=d?s-c.beta:i-c.beta,f=Mk*m);let b=e(Math.abs(f)>=Yr?c.beta+f:c.beta+(f>=0?Yr:-Yr));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 db(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],f=u[u.length-1],p=l(m),d=l(f);if(p>0||d<0)return null;if(d===0)return xi(e,t,r,f,i);let h=m;for(let b=0;b<60&&Math.abs(f.beta-m.beta)>1e-9;b++){let g=(m.beta*d-f.beta*p)/(d-p),y=u[0];for(let x of u)Math.abs(x.beta-g)<Math.abs(y.beta-g)&&(y=x);let R=xk(e,t,r,g,y,i,c);if(!R)return null;let k={beta:g,...R};u.push(k),h=k;let v=l(k);if(Math.abs(v)<("steerDeg"in a?OE:VE))break;v<0?(m=k,p=v,d*=.5):(f=k,d=v,p*=.5)}return xi(e,t,r,h,i)}function KE(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 db(e,t,r,n.fold,a,{steerDeg:o});let u=typeof a.op=="function"?a.op(o):a.op,m=to(e,t,r,o,l,u,a.yawDemandCn??0);return m.driving?m:null}function HE(e,t,r,n,o,a){if(!n.trimmed)return!1;let s=n.steerDeg<0?-1:1,{states:i}=no(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)],f=Math.abs(m.steerDeg)-Math.abs(u.steerDeg),p=f>0?Math.min(1,Math.max(0,(c-Math.abs(u.steerDeg))/f)):0,d=u.beta+p*(m.beta-u.beta),h=u.ay+p*(m.ay-u.ay);return Math.abs(n.beta-d)<=1&&Math.abs(n.ay-h)<=.05}function kn(e,t,r,n,o){let a=Math.max(8,r),s=n>=0?1:-1,i=Math.abs(n),c=(b,g)=>Wr(e,t,a,s*b,g,o),l=no(e,t,a,{direction:s,op:o}),{fold:u}=l;if(u&&Math.abs(u.state.steerDeg)<=Ca){if(i>Math.abs(u.state.ay))return fk(e,t,a,s,i,o);if(i>Math.abs(u.stall.ay)){let b=db(e,t,a,u,{direction:s,op:o},{ayG:i});if(b)return b}}let m=l.states.filter(b=>Math.abs(b.steerDeg)<=Ca),f=m[m.length-1],p=l.states.length>m.length;p&&Math.abs(f.steerDeg)<Ca&&m.push(c(Ca,f));let d=m.findIndex(b=>Math.abs(b.ay)>=i);if(d===0)return Wr(e,t,a,0,void 0,o);if(d>0)return dk(m[d-1],m[d],i,c);let h=kk(m,c,void 0,p||l.foldDeg===null);return h.ay>=i?dk(h.below,h.state,i,c):l.foldDeg!==null&&l.foldDeg<Ca?fk(e,t,a,s,i,o):h.state}var Ca=20;function dk(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 f=a.f===o.f?.5*(o.steer+a.steer):o.steer-o.f*(a.steer-o.steer)/(a.f-o.f),p=n(f,i),d=Math.abs(p.ay)-r;if(Math.abs(d)<u&&(l=p,u=Math.abs(d)),Math.abs(d)<=zE||a.steer-o.steer<=YE)break;d<0?(o={steer:f,f:d},c===-1&&(a.f*=.5),c=-1):(a={steer:f,f:d},c===1&&(o.f*=.5),c=1)}return l}var zE=1e-9,YE=1e-7;function kk(e,t,r,n=!1){let o=r??0;if(r===void 0)for(let x=1;x<e.length;x++)Math.abs(e[x].ay)>Math.abs(e[o].ay)&&(o=x);let a=e[Math.max(0,o-1)],s=Math.abs(e[o].steerDeg),i=WE/4,c,l,u,m,f,p,d,h,b=null,g;if(o>0&&o<e.length-1){let x=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(x.steerDeg),u=s,m=-Math.abs(e[o].ay);let[M,A]=Math.abs(a.ay)>=Math.abs(x.ay)?[a,x]:[x,a];f=Math.abs(M.steerDeg),p=-Math.abs(M.ay),d=Math.abs(A.steerDeg),h=-Math.abs(A.ay)}else{let x=Math.abs(e[o].lockDeg??e[o].steerDeg),M=x-jE,A=o>0&&n&&M>Math.abs(a.steerDeg)?t(M,a):null;if(!A||Math.abs(A.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=x,u=M,m=-Math.abs(A.ay),b=A,f=x,p=-Math.abs(e[o].ay),d=c,h=-Math.abs(a.ay)}let y=l-c,R=0;for(let x=0;x<100;x++){let M=.5*(c+l);if(Math.abs(u-M)<=2*i-.5*(l-c))break;let A=!0;if(Math.abs(y)>i){let S=(u-f)*(m-h),F=(u-d)*(m-p),C=(u-d)*F-(u-f)*S;F=2*(F-S),F>0&&(C=-C),F=Math.abs(F);let L=y;if(y=R,Math.abs(C)<Math.abs(.5*F*L)&&C>F*(c-u)&&C<F*(l-u)){R=C/F;let E=u+R;(E-c<2*i||l-E<2*i)&&(R=M>=u?i:-i),A=!1}}A&&(y=u>=M?c-u:l-u,R=Mk*y);let w=Math.abs(R)>=i?u+R:u+(R>=0?i:-i),T=g(w),P=-Math.abs(T.ay);P<=m?(w>=u?c=u:l=u,d=f,h=p,f=u,p=m,u=w,m=P,b=T):(w<u?c=w:l=w,P<=p||f===u?(d=f,h=p,f=w,p=P):(P<=h||d===u||d===f)&&(d=w,h=P))}let k=b??t(s,a),v=Math.abs(k.steerDeg)>s?e[o]:a;return{state:k,below:v,ay:Math.abs(k.ay)}}var WE=.001,jE=.01,Mk=(3-Math.sqrt(5))/2;function fk(e,t,r,n,o,a){let s=l=>Math.abs(Wr(e,t,r,n*l,void 0,a).ay),i=0,c=Ca;if(s(c)<o)return Wr(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 Wr(e,t,r,n*.5*(i+c),void 0,a)}function fb(e,t,r,n,o){let a=kn(e,t,r,n,o);return a.steering?Math.abs(a.steering.totalNm):NaN}function hb(e,t,r,n,o){if(!Xn(e))return NaN;let a=n<0?-1:1,s=Math.abs(n),i=kn(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,f=Wr(e,t,r,a*u,void 0,o),p=Wr(e,t,r,a*m,void 0,o),d=f.steering?Math.abs(f.steering.totalNm):NaN,h=p.steering?Math.abs(p.steering.totalNm):NaN,b=Math.abs(p.ay)-Math.abs(f.ay);if(Number.isFinite(d)&&Number.isFinite(h)&&b>=.01||l===.4&&Number.isFinite(d)&&Number.isFinite(h)&&b>.001)return(h-d)/b}return NaN}function ib(e,t,r,n,o,a){let s=Math.max(8,r),i=It(e,t,s,n*se,o*se,void 0,Ta(e,a,s,t));return{ay:i.ay,cn:i.cn}}function bb(e,t,r,n,o){let a=Math.max(8,r),s=kn(e,t,a,n,o),i=.5,c=ib(e,t,a,s.beta+i,s.steerDeg,o).cn,l=ib(e,t,a,s.beta-i,s.steerDeg,o).cn;return(c-l)/(2*i*se)*e.massTotal*Ae*(e.wheelbase/1e3)}function gb(e,t,r,n){let o=Math.max(8,r),{branch:a,opts:s}=UE(e,t,o,n);return Sk(e,t,o,a,s)}function UE(e,t,r,n){if(!e.tv?.enabled){let s=n?{op:n}:{};return{branch:no(e,t,r,s),opts:s}}let o=cb(e,t,r),a={op:s=>{let i=lb(e,r,s,o);return i===0?n:{axG:n?.axG??0,driveFrontFrac:n?.driveFrontFrac,tvRearDiffN:i}}};return{branch:no(e,t,r,a),opts:a}}function Sk(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 xi(e,t,r,n.peak,a);let i=(l,u)=>to(e,t,r,l,u,a(l),s),c=n.states[0].driving||!n.peak.driving?n.states:n.states.slice(1);return kk(c,i,c.indexOf(n.peak),n.foldDeg===null).state}function yb(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(Ae*o)),s=(n.betaMaxDeg??10)*se,i=(n.deltaMaxDeg??10)*se,[c,l]=n.betaRangeDeg?[n.betaRangeDeg[0]*se,n.betaRangeDeg[1]*se]:[-s,s],[u,m]=n.deltaRangeDeg?[n.deltaRangeDeg[0]*se,n.deltaRangeDeg[1]*se]:[-i,i],{lf:f,lr:p}=sb(e),d=o===void 0?0:p/o,h=o===void 0?0:(f+p)/o,b=n.nLines??9,g=n.nPts??21,y=n.steering!==!1&&Xn(e),R=y?fn(ye(t,"front").model):void 0,k=(I,N,B,V)=>B===1?I:I+(N-I)*V/(B-1),v=e.tv?.enabled?cb(e,t,a):0,x=I=>{let N=lb(e,a,I/se,v);return!n.axG&&N===0?null:Ta(e,{axG:n.axG??0,driveFrontFrac:n.driveFrontFrac,tvRearDiffN:N},a,t)},{lf:M,lr:A}=sb(e),w=n.reserves?Ri(t,e.massTotal*Ae*1.2):null,T=I=>w?Er(w,{FL:I.FL,FR:I.FR,RL:I.RL,RR:I.RR},{lf:M,lr:A}):null,P=[],S={ay:[],cn:[]},F=0;for(let I=0;I<b;I++){let N=k(u,m,b,I),B=x(N),V=[],G=[],H=[],Y=[],J=w?{stabil:[],agil:[]}:void 0,j=y?ik():void 0,ee;for(let W=0;W<g;W++){let Z=k(c,l,g,W),re=It(e,t,a,Z,N,ee,B,o);if(ee=Number.isFinite(re.ay)?re.ay*Ae:void 0,V.push(re.ay),G.push(re.cn),H.push(Z/se),Y.push(N/se),J){let me=T(re.wheels);J.stabil.push(me.stabil),J.agil.push(me.agil)}j&&ck(j,sk(e,t,N,re.wheels)),Math.abs(re.ay)>F&&(F=Math.abs(re.ay))}P.push({label:`\u03B4 ${(N/se).toFixed(0)}\xB0`,ay:V,cn:G,betaDeg:H,deltaDeg:Y,reserve:J,steering:j});let ne=null,de=1/0;for(let W=1;W<G.length;W++){if(!Number.isFinite(G[W-1])||!Number.isFinite(G[W])||G[W-1]!==0&&G[W-1]<0==G[W]<0)continue;let Z=G[W-1]===G[W]?0:G[W-1]/(G[W-1]-G[W]),re=V[W-1]+Z*(V[W]-V[W-1]);if(o===void 0&&N!==0&&Math.abs(re)>=.05&&Math.sign(re)!==Math.sign(N))continue;let me=Math.abs(H[W-1]+Z*(H[W]-H[W-1])-d/se);me<de&&(de=me,ne=re)}ne!==null&&(S.ay.push(ne),S.cn.push(0))}let C=[];for(let I=0;I<b;I++){let N=k(c,l,b,I),B=[],V=[],G=[],H=[],Y=w?{stabil:[],agil:[]}:void 0,J=y?ik():void 0,j;for(let ee=0;ee<g;ee++){let ne=k(u,m,g,ee),de=It(e,t,a,N,ne,j,x(ne),o);if(j=Number.isFinite(de.ay)?de.ay*Ae:void 0,B.push(de.ay),V.push(de.cn),G.push(N/se),H.push(ne/se),Y){let W=T(de.wheels);Y.stabil.push(W.stabil),Y.agil.push(W.agil)}J&&ck(J,sk(e,t,ne,de.wheels))}C.push({label:`\u03B2 ${(N/se).toFixed(0)}\xB0`,ay:B,cn:V,betaDeg:G,deltaDeg:H,reserve:Y,steering:J})}let L=.5*se,E=x(h),D,O;if(o===void 0)D=(It(e,t,a,d+L,h,void 0,E,o).cn-It(e,t,a,d-L,h,void 0,E,o).cn)/(2*L),O=(It(e,t,a,d,h+L,void 0,x(h+L),o).cn-It(e,t,a,d,h-L,void 0,x(h-L),o).cn)/(2*L);else{let I=(V,G)=>It(e,t,a,V,G,void 0,x(G),o).cn,N=(V,G,H)=>Number.isFinite(V)?(-3*V+4*G-H)/(2*L):(H-G)/L,B=I(d,h);D=-N(B,I(d-L,h),I(d-2*L,h)),O=N(B,I(d,h+L),I(d,h+2*L))}let _=0;if(E&&E.axG){let I=It(e,t,a,d,h,void 0,E,o),N=0;for(let B of vn)N+=I.wheels[B].fxShort;_=N/Math.abs(e.massTotal*E.axG*Ae)}let z=S.ay.reduce((I,N)=>Math.max(I,Math.abs(N)),0);return{isoBeta:C,isoDelta:P,trim:S,maxAy:F,stability:D,control:O,speed:o===void 0?a:Math.sqrt(z*Ae*o),...o!==void 0?{radius:o}:{},axG:E?.axG??0,axShortfall:_,...R?{steeringAligningSource:R}:{}}}function Ak(e,t){return oo(e,t*se).atLock}function XE(e,t,r,n,o=zr(e,t,r)){let a=r,s=e.massTotal,i=vn.filter(g=>Jt(g)?n.drivenFront:n.drivenRear),c=o.peakAt,l={front:n.drivenFront?Wt(e,"front",1):void 0,rear:n.drivenRear?Wt(e,"rear",1):void 0},u=new Map,m=(g,y)=>{let R=`${g}:${y}`,k=u.get(R);if(k===void 0){let v=Math.max(1,y*gi);k=Lt(ye(t,g),v,0,!1,c(g,v)),u.set(R,k)}return k},f=(g,y)=>y>0?bi(y,R=>m(g,R)):0,p=(g,y,R,k)=>{let v=ye(t,g),x=E=>{let D=Math.max(0,R[E]),O=c(g,D);return{Fz:D,a:f(g,D),b:O.fyPeak,slide:0,cap:_=>D>0?Lt(v,D,_,!1,O):0}},[M,A]=g==="front"?["FL","FR"]:["RL","RR"],w=x(M),T=x(A),P=k[M]*w.b,S=k[A]*T.b,F=w.cap(P)+T.cap(S),C=hi(w,T,P+S,y,F);return{l:M,r:A,full:C,asHeld:()=>({axle:g,strong:w.cap(P)>=T.cap(S)?M:A,full:C,open:hi(w,T,P+S,Sa,F),sense:1})}},d=g=>({muX:y=>y>0?f(g,y)/y:0,muY:y=>y>0?c(g,y).fyPeak/y:0}),h={front:d("front"),rear:d("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,R,k=0)=>{let v={FL:0,FR:0,RL:0,RR:0},x=Te(e,g,0,a,0,y),M,A=C=>(M?.ax!==C&&(M={ax:C,loads:Te(e,g,(C+k)/Ae,a,0,y)}),M.loads),w=El(C=>pa(R,A(C),x,c).short,-k,1),T=R,P=C=>{let L=w.at(C);v=A(L),T=pa(R,v,x,c).util;let E=0,D=n.diffYaw?{fx:{FL:0,FR:0,RL:0,RR:0},axles:[]}:null;for(let O of i){let _=l[Rn(O)];if(_){if(wu(O)){let B=p(Rn(O),_,v,T);E+=B.full,D&&(D.fx[B.l]=D.fx[B.r]=B.full/2,D.axles.push(B.asHeld()))}continue}let z=Math.max(0,v[O]),I=c(Rn(O),z),N=Lt(ye(t,Rn(O)),z,T[O]*I.fyPeak,!1,I);E+=N,D&&(D.fx[O]=N)}if(D){let O={};for(let _ of vn){let z=Math.max(0,v[_]);O[_]={Fz:z,Fy:T[_]*c(Rn(_),z).fyPeak,Fx:D.fx[_]}}for(let _ of D.axles)E+=Jl(_,O,h,b(g))-_.full}return E/s},S=W1(P,-k,xn).fx,F=w.edge();return F!==void 0&&S>F&&(S=F,P(S)),{ax:S,loads:v}}}}var Fu=.05,hk=.001,bk=16,Pu=8;function xb(e,t,r,n){let o=Math.max(Pu,r),a=n.nSteer??7,s=e.tv?.enabled?cb(e,t,o,n.steerMaxDeg):0,i=I=>{let N=lb(e,o,I,s);return N===0?void 0:{axG:0,tvRearDiffN:N}},c=n.yawDemandCn??0,l={op:i,yawDemandCn:c,...n.steerMaxDeg!==void 0?{steerMaxDeg:n.steerMaxDeg}:{}},u=no(e,t,o,l),m=I=>{let N={},B={};for(let V of vn)N[V]=I.wheels[V].slipDeg*se,B[V]=Math.min(1,I.wheels[V].gripUtil);return{steerDeg:I.steerDeg,ayMs:Math.max(0,I.ay*Ae),ayG:I.ay,slip:N,util:B,scrub:I.ay>0?qE(I,e.massTotal):0}},f=null,p=I=>{if(f&&I===f.steerDeg)return m(f);let N=KE(e,t,o,u,I,l);if(N)return m(N);let B=u.states[0];for(let V of u.states)V.steerDeg<=I&&(B=V);return m(B)},d=u.peak.driving&&u.peak.ay>0?Sk(e,t,o,u,l):null,h=d?Math.max(0,d.ay*Ae):0,b=d?[...u.states.filter(I=>I.steerDeg<d.steerDeg),d]:u.states,g=d?b.findIndex(I=>I.ay*Ae>=.995*h):0,y=b[g].steerDeg,{fold:R}=u;if(d&&R&&u.peak===R.state){let I=.995*h/Ae,N=u.states.indexOf(R.stall),B=N-1;for(;B>0&&u.states[B].beta===R.stall.beta;)B--;let V=Math.sign(R.stall.beta-u.states[B].beta),G=N;for(;G>0&&u.states[G].ay>=I&&Math.sign(u.states[G].beta-u.states[G-1].beta)!==-V;)G--;u.states[G].ay<I&&(f=db(e,t,o,R,l,{ayG:I},u.states.slice(G,N+1)))}if(f)y=f.steerDeg;else if(g>0){let I=b[g-1].steerDeg,N=y;for(let B=0;B<8&&N-I>.001;B++){let V=.5*(I+N);p(V).ayMs>=.995*h?N=V:I=V}y=N}let k=[];for(let I=0;I<(h>0?a:1);I++){let N=I/(a-1);k.push(p(y*(N+Math.sin(Math.PI/2*N))/2))}k[0].ayMs=0;let v=[],x=[],M=[],A=[],w=zr(e,t,o,void 0,n.diffYaw===!0),T=XE(e,t,o,n,w),P=n.axDrag??0,S=I=>{let N=w.limitAt(I.ayMs/Ae,I.steerDeg,I.util,P+I.scrub);return{axD:N.edge!==void 0&&N.edge>0?N.edge:N.ax,locked:N.axUnlocked-N.ax>Fu}},F=I=>T.limitAt(I.ayMs/Ae,I.steerDeg,I.util,P+I.scrub).ax,C=k.map(I=>({p:I,axA:F(I),...S(I)})),L=[];for(let I=0;I+1<C.length;I++){let N=C[I],B=C[I+1],V=[];N.locked!==B.locked?V.push({read:S,past:G=>G.locked===B.locked,braking:!0}):(B.axA>N.axA+Fu&&V.push({read:G=>({axA:F(G)}),past:G=>(G.axA??-1/0)>N.axA}),-B.axD>-N.axD+Fu&&V.push({read:S,past:G=>-(G.axD??0)>-N.axD}));for(let{read:G,past:H,braking:Y}of V){let J=N.p.steerDeg,j=B.p.steerDeg,ee=null,ne=N.axD,de=B.axD;for(let W=0;W<bk&&j-J>hk&&!(Y&&Math.abs(de-ne)<=Fu);W++){let Z=.5*(J+j),re=p(Z),me=G(re);H(me)?(j=Z,ee={p:re,r:me},de=me.axD??de):(J=Z,ne=me.axD??ne)}if(ee){let{p:W,r:Z}=ee,re=Z.axD!==void 0&&Z.locked!==void 0?{axD:Z.axD,locked:Z.locked}:S(W);L.push({p:W,axA:Z.axA??F(W),...re})}}}C.push(...L),C.sort((I,N)=>I.p.steerDeg-N.p.steerDeg);let E=I=>I.axA+P+I.p.scrub,D=.001*Math.max(1,k[k.length-1].ayMs),O=[];for(let I=0;I+1<C.length;I++){let N=C[I],B=C[I+1];if(!(E(N)>=0&&E(B)<0))continue;let V=N.p.steerDeg,G=B.p.steerDeg,H=null,Y=null;for(let j=0;j<bk&&G-V>hk;j++){let ee=.5*(V+G),ne=p(ee);E({p:ne,axA:F(ne)})>=0?(V=ee,H=ne):(G=ee,Y=ne)}let J=H??Y;J&&J.ayMs>N.p.ayMs&&J.ayMs<B.p.ayMs&&O.push({p:J,axA:-(P+J.scrub),steady:!0,...S(J)})}C.push(...O),C.sort((I,N)=>I.p.steerDeg-N.p.steerDeg);let _=!1;for(let{p:I,axA:N,axD:B,steady:V}of C){let G=v.length-1,H=G>=0&&(V||_?!(I.ayMs>v[G]):I.ayMs-v[G]<D);_=V===!0&&!H,H?(x[G]=Math.max(x[G],N),M[G]=Math.min(M[G],B)):(v.push(I.ayMs),x.push(N),M.push(B),A.push(I.scrub))}for(let I=v.length-2;I>=0;I--)x[I]=Math.max(x[I],x[I+1]),M[I]=Math.min(M[I],M[I+1]);return{ayMax:v[v.length-1],ay:v,axAccel:x,axDecel:M,axScrub:A,rollover:u.rollover,atLock:d!==null&&Ak(e,d.steerDeg)}}function qE(e,t){let r=e.beta*se,n=0;for(let o of vn){let a=e.wheels[o],s=a.steerDeg*se-r;n+=a.Fx*(Math.cos(s)-1)-a.Fy*Math.sin(s)}return n/t}var R9=Math.PI/180,v9={speeds:Array.from({length:23},(e,t)=>8+t),steerMaxDeg:14,steerSteps:29};function wk(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 Pa={enabled:!1,kp:3e3,ffLow:150,ffHigh:300,vLow:18,vHigh:25},Fk=e=>wk(e.ffLow,e.ffHigh,e.vLow,e.vHigh);var hr={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"},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"}},QE=["k_yaw","k_roll","k_pitch"];function ki(e){for(let t of QE)delete e[t];for(let t of Object.keys(hr)){let r=e[t];if(!r){e[t]={...hr[t]};continue}e[t]={...r,label:hr[t].label,unit:hr[t].unit}}return e}function Q(e,t){return e[t]?.value??hr[t].value}function Lu(e){let t=(r,n)=>e[r]?.value??n;return{enabled:t("tv_enabled",0)>=.5,kp:t("tv_kp",Pa.kp),ffLow:t("tv_ff_low",Pa.ffLow),ffHigh:t("tv_ff_high",Pa.ffHigh),vLow:t("tv_v_low",Pa.vLow),vHigh:t("tv_v_high",Pa.vHigh)}}var Ck=[10,25,50,100,200,300];function Rb(e,t,r,n,o){let s=Ck.map(i=>Math.round(i<=25?r*i:r*25+n*(i-25)));return{id:e,label:t,speedMmS:[...Ck],reboundN:s,bumpN:s.map(i=>Math.round(i*o))}}var Du={name:"Generic FS damper",curves:[Rb("c1","Soft",1.6,1,.65),Rb("c2","Medium",3,1.6,.65),Rb("c3","Firm",8,2.4,.65)]};function Eu(e){let t=e.curves.length;return t>0?e.curves[Math.floor((t-1)/2)].id:""}var Mn=25;function La(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 Tk(e,t){return t>=0?La(e.rebound,t):-La(e.bump,-t)}function Pk(e,t,r){return t*Tk(e,t*r)}var vb=(e,t)=>e.curves.find(r=>r.id===t);function Mi(e,t){let r=vb(e,Eu(e)),n=(t&&vb(e,t.bump))??r,o=(t&&vb(e,t.rebound))??r;return{bump:{speedMmS:n?.speedMmS??[],forceN:n?.bumpN??[]},rebound:{speedMmS:o?.speedMmS??[],forceN:o?.reboundN??[]}}}var Iu=5e3;function Si(e,t){let r=t>0?t:1,n=[],o=[],a=e.bump.speedMmS.map(c=>c/r).filter(c=>c<Iu),s=e.rebound.speedMmS.map(c=>c/r).filter(c=>c<Iu),i=c=>{n.push(c),o.push(Pk(e,r,c))};i(-Iu);for(let c=a.length-1;c>=0;c--)i(-a[c]);i(0);for(let c of s)i(c);return i(Iu),{kind:"map",input:"velocity",x:n,y:o}}var kb=64;function Ai(e,t,r){let n=t>0?t:1,o=Math.max(r,1e-6),a=0;for(let s=0;s<kb;s++){let i=Math.sin((s+.5)*Math.PI/kb),c=n*o*i;a+=n*(La(e.rebound,c)+La(e.bump,c))*i}return a*(Math.PI/kb)/(Math.PI*o)}function ao(e,t,r,n,o=e){let a=(c,l,u)=>{if(!c||c.curves.length===0)return;let m=Mi(c,l);return{law:m,curve:Si(m,u),rate:Ai(m,u,Mn)}},s=a(e,t?.front,r),i=a(o??e,t?.rear,n);return!s&&!i?null:{...s?{front:s}:{},...i?{rear:i}:{}}}var Lk=(e,t)=>({...e,y:e.y.map(r=>r*t)}),ZE=e=>({...e,x:e.x.map(t=>-t).reverse(),y:e.y.map(t=>-t).reverse()});function Mb(e,t,r){let n=Math.abs(r)>0?Math.abs(r):1,o=Mi(e,t);return{law:o,curve:Lk(Si(o,n),.5),rate:Ai(o,n,Mn)/2,mr:n,ratio:n,share:.5}}function Sb(e,t,r,n,o){let a=n*(Math.abs(r)>0?Math.abs(r):1),s=Mi(e,t),i=Lk(Si(s,a),1/n);return{law:s,curve:o?ZE(i):i,rate:Ai(s,a,Mn)/n,mr:a/n,ratio:a,share:1/n}}function Fi(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 _u=["front","rear","heaveFront","heaveRear","rollFront","rollRear"];function wi(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 jr(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 Ti(e){return e.kind==="coil"?2:1}function Ci(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 Ek(e){return Ci(e)/2}function Ik(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 Dk(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 JE(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 Pi(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*Ci(e.section)/e.barLength,a=2*o/(n*n),s=Ek(e.armSection??e.section),i=3*e.E*s/n**3,c=e.dropLinkRate??1/0;return{rateAtLink:Dk([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*Ci(e.section)/e.barLength,a=2*o/(n*n),s=3*e.E*Ik(e.blade)/n**3,i=e.dropLinkRate??1/0;return{rateAtLink:Dk([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*Ci(e.section)/e.length,a=2*o/(n*n);return{rateAtLink:a,contributions:{barTwist:a},torsional:o}}case"coil":{let n=jr(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=JE(e.linkTravel,e.force,t);return{rateAtLink:Math.max(0,n),contributions:{},torsional:0}}}}function Nu(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?sf(t,r):1,o=t?cf(t,r):0,a=Pi(e,o).rateAtLink;return{wheelRate:Math.max(0,a*n*n),motionRatio:n,rateAtLink:a}}function Li(e,t){let r=e.damper??0;return!r||e.design.kind==="none"?0:Ti(e.design)*r*t*t}var eI=150;function tI(e){return X(e,[0,-.5,1])<-1e-9?U(e,-1):e}function _k(e){let t=e.hardpoints,r=K(t.rockerPivotB,t.rockerPivotA),n=te(t.rockerPivotA,U(K(t.rockerToDamper,t.rockerPivotA),.6)),o=tI(q(oe(r,K(t.rockerToDamper,t.rockerPivotA))));return{outer:n,inner:te(n,U(o,eI)),attach:"rocker"}}function _t(e,t){let r={};for(let o of cr)r[o]=rt(Oe(e,o));let n={vehicle:e,ctx:r};return t&&(n.kc=wl(n,t)),n}function rI(e,t,r,n){let o=e.corner.hardpoints,a=Jo(e.rocker,t.points.rockerAngle),s=i=>Pt(i,r);return{ucaFront:s(o.ucaFront),ucaRear:s(o.ucaRear),lcaFront:s(o.lcaFront),lcaRear:s(o.lcaRear),tieInner:s(Gn(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:Pr(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 Ou(e,t,r,n){let o=He(t,e.vehicle.config),a=o.isFront?o.sideSign*n:0,s;try{s=ft(ge(e.ctx[t],r,a))}catch{return null}if(!s)return null;let i=Oe(e.vehicle,t).config.loadedRadius,c=rI(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 Vu=.5;function nI(e,t){let r=([i,c,l])=>{let u=q(K(c,i)),m=K(l,i),f=q(K(m,U(u,X(m,u))));return[u,f,oe(u,f)]},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=K(i,e[0]);return te(t[0],[0,1,2].map(l=>a[l][0]*c[0]+a[l][1]*c[1]+a[l][2]*c[2]))}}}var Nk=e=>[(e[2][1]-e[1][2])/2,(e[0][2]-e[2][0])/2,(e[1][0]-e[0][1])/2];function Bu(e,t,r){let n=He(t,e.vehicle.config),o=e.ctx[t],a=r.rigid?void 0:{loadedRadius:r.loadedRadius},s=r.state?null:ge(o,r.travel,r.steer,void 0,a),i=r.state??it(s),c=ge(o,r.travel+Vu,r.steer,void 0,a),l=ge(o,r.travel-Vu,r.steer,void 0,a),u=(s?s.ok:r.converged)&&c.ok&&l.ok,m=it(c),f=it(l),p=(T,P)=>Pt(T.points[P],n),d=o.inv.strut?"pushrodOuter":"uprightUpper",h=p(i,d),b=p(i,"uprightLower"),g=T=>{let P=K(b,h);return Math.hypot(...oe(P,K(p(i,T),h)))/Math.hypot(...P)},y=g("tieOuter")>=g("wheelCenter")?"tieOuter":"wheelCenter",R=[h,b,p(i,y)],k=T=>nI(R,[p(T,d),p(T,"uprightLower"),p(T,y)]),v=k(m),x=k(f),M=Nk(v.rot),A=Nk(x.rot),w=[NaN,NaN,NaN];return{solved:u,state:i,at:T=>p(i,T),velocity:T=>u?U(K(v.move(T),x.move(T)),1/(2*Vu)):w,omega:u?U(K(M,A),1/(2*Vu)):w}}function Ab(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 Ok(e,t,r){let n=Bu(e,t,vt(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 Vk(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 Bk(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 oI(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 aI=.1*Math.PI/180;function $k(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]))*aI<=o*n}function $u(e,t){return!e.valid||!e.cpLeft||!e.cpRight?!1:$k([e.lateral,e.height],e.cpLeft,e.cpRight,e.sinAngle,t)}function Di(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}var sI=1;function Gk(e){let t=Di(e);if(!t||!e.cpLeft||!e.cpRight||Math.abs(t.left-t.right)>sI)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)}}function Da(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 br(e,t,r){let n=r==="front"?"FL":"RL",o=r==="front"?"FR":"RR",a=Ok(e,n,t),s=Ok(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=Vk(a),c=Vk(s),l=Bk(a,i),u=Bk(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 f=i?[i[0]-a.cp[0],i[1]-a.cp[1]]:l,p=c?[c[0]-s.cp[0],c[1]-s.cp[1]]:u,d=Math.hypot(f[0],f[1]),h=Math.hypot(p[0],p[1]),b=d>0&&h>0?Math.abs(f[0]*p[1]-f[1]*p[0])/(d*h):0,g=Ab(a.cp,f,s.cp,p)??oI(a.cp,l,s.cp);if(!g)return{...m,sinAngle:b};let y=s.cp[0]-a.cp[0],R=s.cp[1]-a.cp[1],k=Math.hypot(y,R)||1,v=y/k,x=R/k,M=(a.cp[0]+s.cp[0])/2,A=(a.cp[1]+s.cp[1])/2,w=(g[0]-a.cp[0])*-x+(g[1]-a.cp[1])*v,T=(g[0]-M)*v+(g[1]-A)*x;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 Ur(e,t){return{front:br(e,t,"front"),rear:br(e,t,"rear")}}function Gu(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 iI(e,t){return{camber:Gu(e.travel,e.camber,t),toe:Gu(e.travel,e.toe,t),motionRatio:Gu(e.travel,e.motionRatio,t),damperLen:e.damperLen?Gu(e.travel,e.damperLen,t):0}}var Kk=e=>iI(e,0).motionRatio;function Fb(e,t){if(e.kind!=="coil")return null;let r=t??e.motionRatio,n=jr(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 Ku(e,t){if(e.kind==="none")return 0;if(e.kind==="tabulated"){let n=a=>cI(e,a);return(n(.5)-n(-.5))/(2*.5)/2}if((e.gap??0)>0)return 0;let r=t??e.motionRatio;return jr(e.rate,0)*r*r/2}function Ei(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 cI(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 wb={kind:"coil",rate:120,motionRatio:.7,gap:5,bothWays:!1};var Hk=new WeakMap;function zu(e,t){let r=Hk.get(e);r||(r=new Map,Hk.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=Kn(e,t);return r.set(n,a),a}var lI=32,Ii=new Map,zk=new WeakMap,uI=1;function mI(e){let t=zk.get(e);return t===void 0&&(t=uI++,zk.set(e,t)),t}function Cb(e,t){if(!t.linkage)return null;let r=dn(e,t.linkage,t.design.kind),n=`${mI(e)}|${r?"unit":"bar"}|${JSON.stringify(t.linkage)}`,o=Ii.get(n);if(o)return o;let a=aa(e,t.linkage,{kind:t.design.kind});return Ii.size>=lI&&Ii.delete(Ii.keys().next().value),Ii.set(n,a),a}function io(e,t,r=0){let n=(o,a)=>{if(!(!o||o.design.kind==="none"))return Nu(o.design,Cb(a,o),r).wheelRate};return{front:n(t.arbFrontDesign,e.front),rear:n(t.arbRearDesign,e.rear)}}function Ea(e,t){let r=(n,o)=>{if(!n||n.design.kind==="none")return;let a=n.linkage?zu(o,n.linkage).atDesign:void 0;return Ku(n.design,a)};return{front:r(t.heaveFrontDesign,e.front),rear:r(t.heaveRearDesign,e.rear)}}function Xk(e,t){let r=(a,s)=>{if(!a||a.design.kind!=="coil")return;let i=a.linkage?zu(s,a.linkage).atDesign:void 0;return Fb(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 Yu(e,t){let r=(o,a)=>o?Ei(o,Tb(o,a)):0,n=(o,a)=>o?Li(o,Pb(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 Tb=(e,t)=>e.linkage?zu(t,e.linkage).atDesign:void 0,Pb=(e,t)=>Nu(e.design,Cb(t,e),0).motionRatio;function qk(e,t){let r=t.damperSetup,n=t.heaveDamperModel??t.damperModel,o=t.rollDamperModel??t.damperModel,a=(f,p,d)=>{if(!f||!n?.curves.length)return;let h=Tb(f,p);if(Ei(f,h)>0)return Mb(n,r?.[d],h??(f.design.kind==="coil"?f.design.motionRatio:1))},s=(f,p,d)=>{if(!f||!o?.curves.length)return;let h=Pb(f,p);if(!(Li(f,h)>0))return;let b=Cb(p,f)!==null;return Sb(o,r?.[d],h,Ti(f.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 Wu(e,t){let r=t.heaveDamperModel??t.damperModel,n=t.rollDamperModel??t.damperModel,o=(i,c)=>so(i)?{source:"none"}:wi(i.config.coilover,c),a=(i,c)=>{if(!i)return{source:"none"};let l=Ei(i,Tb(i,c))>0;return wi(i.coilover,l?r:void 0)},s=(i,c)=>{if(!i||i.design.kind!=="coil")return{source:"none"};let l=Li(i,Pb(i,c))>0;return wi(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 Qk(e){let t=(r,n)=>{let o={};return r?.linkage&&r.design.kind==="coil"&&(o.heave=r.linkage),n?.linkage&&n.design.kind!=="none"&&n.design.kind!=="direct"&&(o.roll=n.linkage,o.rollKind=n.design.kind),o.heave||o.roll?o:void 0};return{front:t(e.heaveFrontDesign,e.arbFrontDesign),rear:t(e.heaveRearDesign,e.arbRearDesign)}}var so=e=>e.config.actuation==="decoupled",co="a decoupled axle damps in its heave and roll elements, set below";function Zk(e,t,r={}){let n={...t},o=(m,f)=>{let p=n[m];p&&typeof p=="object"&&"value"in p&&(n[m]={...p,value:f})},{front:a,rear:s}=io(e,t);a!==void 0&&o("arb_front",a),s!==void 0&&o("arb_rear",s);for(let[m,f,p]of[[t.heaveFrontDesign,e.front,"heave_spring_front"],[t.heaveRearDesign,e.rear,"heave_spring_rear"]]){if(!m||m.design.kind==="none")continue;let d=m.linkage?zu(f,m.linkage).atDesign:void 0;o(p,Ku(m.design,d))}let i=dI(e,t,r),c=pI(e,i);n.kinFront=c.kinFront,n.kinRear=c.kinRear;let l=bI(e,i);n.steerFront=c.steerFront,Number.isFinite(l.ackermannPct)&&o("ackermann_pct",l.ackermannPct);let u=m=>so(m)?0:m.measured?.springRate??m.config.springRate;o("spring_front",u(e.front)),o("spring_rear",u(e.rear));for(let[m,f]of[[e.front,"spring_front"],[e.rear,"spring_rear"]])so(m)&&(n.readouts={...n.readouts,[f]:"a decoupled axle has no corner spring; its heave and roll elements carry the car"});for(let[m,f]of[[e.front,"damper_front"],[e.rear,"damper_rear"]])so(m)&&(o(f,0),n.readouts={...n.readouts,[f]:co});return o("mr_front",l.mrFront),o("mr_rear",l.mrRear),o("wheelbase",l.wheelbase),o("track_front",l.trackFront),o("track_rear",l.trackRear),o("rc_front",l.rcFront),o("rc_rear",l.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:l.rcGainFront,gainRear:l.rcGainRear},n}function pI(e,t){return{kinFront:Wk(e.front),kinRear:Wk(e.rear),steerFront:e.front.measured?void 0:ju(e.front,t)}}var Yk=new WeakMap;function Wk(e){let t=Yk.get(e);return t||Yk.set(e,t=ba(e)),t}function dI(e,t,r={}){return fI(e,t,r.front,r.rear)}function fI(e,t,r,n){let o=e.front.config.loadedRadius;if(!((pr(r??t.tireModel)??0)>0))return o;let a={...t,surveyedRadiusFront:o,surveyedRadiusRear:e.rear.config.loadedRadius};return Uu(a,r,n).front??o}var jk=new WeakMap;function ju(e,t=e.config.loadedRadius){let r=jk.get(e);r||(r=new Map,jk.set(e,r));let n=r.get(t);if(n)return n;let o=t===e.config.loadedRadius?void 0:{loadedRadius:t},a=wf(e,kt(e.config),void 0,void 0,void 0,void 0,o);return r.size>=4&&r.clear(),r.set(t,a),a}var Uk=new WeakMap;function hI(e){return ze(e,{travelMin:-1,travelMax:1,steps:3}).samples[1].metrics.motionRatio??1}var Hu=e=>e.measured?Kk(e.measured):hI(e);function bI(e,t=e.front.config.loadedRadius){let r=()=>e.front.measured?void 0:ju(e.front,t);return{...gI(e),get steerFront(){return r()},get ackermannPct(){let n=r();return n?Cf(n,Rt(e.front),e.config.wheelbase):Number.NaN}}}function gI(e){let t=Uk.get(e);if(t)return t;let r=e.front.measured,n=e.rear.measured,a=!r||!n?Ur(_t(e),{heave:0,pitch:0,roll:0,steer:0}):null,s={wheelbase:e.config.wheelbase,trackFront:r?r.track:Rt(e.front),trackRear:n?n.track:Rt(e.rear),mrFront:Hu(e.front),mrRear:Hu(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:Da(a.front),rcGainRear:n||!a?0:Da(a.rear),rcFrontValid:r?!0:!!a?.front.valid,rcRearValid:n?!0:!!a?.rear.valid};return Uk.set(e,s),s}var St={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}},tM=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),gr=(e,t,r,n=1/0)=>typeof e=="number"&&Number.isFinite(e)?Math.min(n,Math.max(r,e)):t;function lo(e){if(tM(e))switch(e.kind){case"open":case"spool":return{kind:e.kind};case"clutch":{let t=St.clutch;return{kind:"clutch",preloadNm:gr(e.preloadNm,t.preloadNm,0),rampDriveDeg:gr(e.rampDriveDeg,t.rampDriveDeg,1,90),rampCoastDeg:gr(e.rampCoastDeg,t.rampCoastDeg,1,90),faces:Math.round(gr(e.faces,t.faces,0)),muClutch:gr(e.muClutch,t.muClutch,0,1),rFrictionMm:gr(e.rFrictionMm,t.rFrictionMm,1),rRampMm:gr(e.rRampMm,t.rRampMm,1)}}case"torsen":{let t=St.torsen,r=gr(e.preloadNm,0,0);return{kind:"torsen",tbrDrive:gr(e.tbrDrive,t.tbrDrive,1),tbrCoast:gr(e.tbrCoast,t.tbrCoast,1),...r>0?{preloadNm:r}:{}}}default:return}}function Xu(e){if(!tM(e))return;let t=lo(e.front),r=lo(e.rear);return t||r?{...t?{front:t}:{},...r?{rear:r}:{}}:void 0}function _i(e){let t=yn(e),r=n=>n>=2?"independent":n===1?"diff":"none";return{front:r(t.front),rear:r(t.rear)}}function Ni(e){if(!e.driveline)return;let t=_i(e),r=e.r_dyn.value,n=s=>{if(t[s]!=="diff")return;let i=lo(e.driveline?.[s]);if(!(!i||i.kind==="independent"))return{kind:i.kind,drive:fi(i,"drive",r),coast:fi(i,"coast",r),hubs:fi(i,"hubs",r)}},o=n("front"),a=n("rear");return o||a?{...o?{front:o}:{},...a?{rear:a}:{}}:void 0}var yI={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"}},Jk=e=>{let t=e==="front"?"Front":"Rear";return Object.fromEntries(Object.entries(yI).map(([r,n])=>[`${e}.${r}`,{section:t,...n}]))},qu={...Jk("front"),...Jk("rear")},eM=e=>e.motorModel?.kind==="ice"?e.motorPlacement==="front"?"front":"rear":null;function rM(e,t){let r=eM(t);if(!(!r||eM(e)===r||t.driveline?.[r]))return{...t.driveline,[r]:{...St.clutch}}}function jt(e,t,r,n){return e>0?!(r>0)||!Number.isFinite(r)?e:Math.max(1,e-t/r):n}function Qu(e,t,r){let n=Math.max(0,Math.min(1,r)),o=jt(e.freeRadius,e.staticLoad,e.tyreRate,e.surveyed),a=jt(t.freeRadius,t.staticLoad,t.tyreRate,t.surveyed);return n*o+(1-n)*a}function Ia(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 Xr(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 Oi(e,t){if(!e)return RI(t);let r=t-hn(e,0).camber;return r?{...e,camber:e.camber.map(n=>n+r)}:e}function xI(e){return{kinFront:Oi(e.kinFront,Q(e,"camber_front_deg")),kinRear:Oi(e.kinRear,Q(e,"camber_rear_deg"))}}function RI(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 nM=9.81,oM=e=>e>1?e/100:e;function _a(e,t,r){let n=t??e.tireModel??Js(),o=r??e.tireModelRear??n,a={grip:Q(e,"grip_scale"),stiffness:Q(e,"stiffness_scale")},s=tu(n,a);return{front:s,rear:o===n?s:tu(o,a)}}function yr(e,t,r){let n=_a(e,t,r),o=Pe(n.front);return ht(n.rear===n.front?o:zl(o,Pe(n.rear)))}function Lb(e,t,r){let n=oM(e.front_mass_diss.value),o=_a(e,t,r),a=Pe(o.front),s=o.rear===o.front?a:Pe(o.rear),i=t??e.tireModel,c=r??e.tireModelRear??i,l=e.m.value*nM*n/2,u=e.m.value*nM*(1-n)/2,m=(i?a.verticalStiffness():0)||Q(e,"tire_vertical_rate"),f=(c?s.verticalStiffness():0)||Q(e,"tire_vertical_rate"),p=pr(i)??0,d=pr(c)??0,h=e.surveyedRadiusFront&&e.surveyedRadiusRear?Qu({freeRadius:p,staticLoad:l,tyreRate:m,surveyed:e.surveyedRadiusFront},{freeRadius:d,staticLoad:u,tyreRate:f,surveyed:e.surveyedRadiusRear},n):void 0,b=e.surveyedRadiusFront?jt(p,l,m,e.surveyedRadiusFront):void 0,g=e.surveyedRadiusRear?jt(d,u,f,e.surveyedRadiusRear):void 0;return{ev:a,evR:s,Wf:l,Wr:u,tireRate:m,tireRateRear:f,tyreFreeRadius:p,tyreFreeRadiusRear:d,cgStandingRadius:h,standingFront:b,standingRear:g}}function Uu(e,t,r){let n=Lb(e,t,r);return{front:n.standingFront,rear:n.standingRear}}function aM(e,t,r){return Lb(e,t,r).cgStandingRadius}function yt(e,t,r){let n=oM(e.front_mass_diss.value),o=Q(e,"mr_front")||1,a=Q(e,"mr_rear")||1,{ev:s,evR:i,Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:f,tyreFreeRadiusRear:p,cgStandingRadius:d,standingFront:h,standingRear:b}=Lb(e,t,r),g=pi(e),y=Ni(e),R=ao(e.damperModel,e.damperSetup,o,a,e.damperModelRear??e.damperModel),k=e.readouts?.damper_front===co,v=e.readouts?.damper_rear===co,x={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,Q(e,"cop_long"))),copHeight:Q(e,"cop_height"),...e.aeroModel?{model:e.aeroModel}:{},rideHeightFront:Q(e,"ride_height_front"),rideHeightRear:Q(e,"ride_height_rear")};return{massTotal:e.m.value,frontMassFrac:n,steeringSystem:e.steeringSystem,tv:Lu(e),cgHeight:Ia(Q(e,"cg_height"),e.cgReference?.standingRadius,d),...d!==void 0?{cgStandingRadius:d}:{},wheelbase:Q(e,"wheelbase"),trackFront:Q(e,"track_front"),trackRear:Q(e,"track_rear"),wheelRateFront:Q(e,"spring_front")*o*o,wheelRateRear:Q(e,"spring_rear")*a*a,tireRate:u,...m!==u?{tireRateRear:m}:{},tireDamping:Q(e,"tire_vertical_damping"),arbFront:Q(e,"arb_front"),arbRear:Q(e,"arb_rear"),brakeBalanceFront:g.balanceFront,brakes:g,...y?{driveline:y}:{},heaveSpringFront:Q(e,"heave_spring_front"),heaveSpringRear:Q(e,"heave_spring_rear"),unsprungPerCorner:Q(e,"unsprung_mass"),unsprungCgHeight:vI(e,{Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:f,tyreFreeRadiusRear:p,standingFront:h,standingRear:b}),tyreFreeRadius:f,...p!==f?{tyreFreeRadiusRear:p}:{},rcHeightFront:Xr(Q(e,"rc_front"),e.rcRoad?.gainFront,e.rcRoad?.radiusFront,h),rcHeightRear:Xr(Q(e,"rc_rear"),e.rcRoad?.gainRear,e.rcRoad?.radiusRear,b),corneringStiffnessFront:s.corneringStiffness(c),corneringStiffnessRear:i.corneringStiffness(l),damperFront:R?.front&&!k?R.front.rate:Q(e,"damper_front")*o*o,damperRear:R?.rear&&!v?R.rear.rate:Q(e,"damper_rear")*a*a,...R?.front&&!k?{damperCurveFront:R.front.curve}:{},...R?.rear&&!v?{damperCurveRear:R.rear.curve}:{},aero:x,ackermannPct:Q(e,"ackermann_pct"),toeFrontDeg:Q(e,"toe_front_deg"),toeRearDeg:Q(e,"toe_rear_deg"),yawInertia:Q(e,"I_yaw"),steerFront:e.steerFront,...xI(e)}}function vI(e,t){let r=(a,s,i,c)=>a??(s>0?jt(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 Zu={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 sM(e,t=e.batteryModel){if(!t)return e;let r=wr(t),n=(o,a)=>({...o,value:a});return{...e,capacity:n(e.capacity,r.capacityAh),ocv:n(e.ocv,r.voltageAtFull)}}var cM={damper_front:`the damper part sets it: its front curve at ${Mn} mm/s`,damper_rear:`the damper part sets it (the rear's own, where the car names one): its rear curve at ${Mn} mm/s`};function Ju(e){let t=!!(e.damperModelId||e.damperModel),r=t||!!(e.damperModelIdRear||e.damperModelRear);return{...t?{damper_front:cM.damper_front}:{},...r?{damper_rear:cM.damper_rear}:{}}}function lM(e,t=e.damperModel,r=e.damperModelRear??t){if(!t&&!r)return e;let n=Q(e,"mr_front")||1,o=Q(e,"mr_rear")||1,a=ao(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!==co&&(i.damper_front=s(e.damper_front,"damper front",a.front.rate/(n*n))),a.rear&&e.readouts?.damper_rear!==co&&(i.damper_rear=s(e.damper_rear,"damper rear",a.rear.rate/(o*o))),i}var uM={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}},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 qr(e){return!!e&&typeof e=="object"&&"value"in e&&"label"in e}var AI={Batteriekapazit\u00E4t:"pack capacity",Rollwiderstandsbeiwert:"rolling-resistance coefficient"},pM=e=>AI[e]??e;function em(e){let t=[];for(let r of Object.keys(e)){if(r==="motor"||r==="name")continue;let n=e[r];qr(n)&&t.push({key:r,label:pM(n.label),value:n.value,unit:n.unit})}return t}var FI=[{title:"Mass & chassis",keys:["m","front_mass_diss","cg_height","unsprung_mass","wheelbase","track_front","track_rear","rc_front","rc_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"]}],wI=.5,mM=e=>e==="infinite"?1/0:typeof e=="number"?e:null,CI=e=>/front/.test(e)?e.replace("front","rear"):/rear/.test(e)?e.replace("rear","front"):null,Z7=(()=>{let e=uM.rows,t=o=>{let a=CI(o),s=mM(e[o]?.score),i=a&&e[a]?mM(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>=wI&&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 Db={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 dM(e){let t=new Map;for(let a of em(e))t.set(a.key,a);let r=new Set,n=[];for(let a of FI){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=em(e).filter(a=>!r.has(a.key));return o.length&&n.push({title:"Other",rows:o}),n}var Eb={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"},Ib={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"},fM=e=>!!(e.aeroModelId||e.aeroModel);function TI(e){let t=n=>n!=null&&n.design.kind!=="none",r={};return t(e.arbFrontDesign)&&(r.arb_front="the front anti-roll bar design sets it"),t(e.arbRearDesign)&&(r.arb_rear="the rear anti-roll bar design sets it"),t(e.heaveFrontDesign)&&(r.heave_spring_front="the front third-spring design sets it"),t(e.heaveRearDesign)&&(r.heave_spring_rear="the rear third-spring design sets it"),r}var PI=e=>!!(e.batteryModelId||e.batteryModel);function LI(e,t){let r={};return t.geometry&&Object.assign(r,Db,TI(e)),fM(e)&&Object.assign(r,Eb),PI(e)&&Object.assign(r,Zu),Object.assign(r,Ju(e)),e.readouts&&Object.assign(r,e.readouts),r}function hM(e,t){let r=LI(e,t);return fM(e)||Object.assign(r,Ib),r}function _b(e){let t=e.cop_long;return qr(t)?1-t.value:.5}function DI(e,t){let r=e.front_aero_diss,n=e.cop_long;!qr(r)||!qr(n)||(t===r.label?n.value=1-r.value:t===n.label&&(r.value=1-n.value))}function EI(e,t){DI(e,t);let r=e.c_l,n=e.c_w,o=e.l_to_d_ratio;!qr(r)||!qr(n)||(t===r.label||t===n.label?qr(o)&&n.value!==0&&(o.value=r.value/n.value):qr(o)&&t===o.label&&o.value!==0&&(n.value=r.value/o.value))}function tm(e,t,r){let n=!1;for(let o of Object.keys(e)){if(o==="motor"||o==="name")continue;let a=e[o];if(qr(a)&&pM(a.label)===t){a.value=r,n=!0;break}}return n&&EI(e,t),n}function rm(e,t,r=0,n,o){let a=()=>({cl:e.c_l.value,cw:e.c_w.value,frontShare:_b(e),A:e.A.value,platform:null});if(!e.aeroModel)return a();let s=Tr(n??yt(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:_b(e),A:s.area,platform:s}}var bM=e=>typeof e=="object"&&e!==null&&typeof e.value=="number"&&typeof e.label=="string";function gM(e,t=e.aeroModel){if(!t)return e;let r=sn(t,{wheelbase:Q(e,"wheelbase")}).at(Q(e,"ride_height_front"),Q(e,"ride_height_rear")),{cl:n,balanceFront:o}=Cd(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(bM(e.cop_long)?e.cop_long:void 0,hr.cop_long,1-o)};return bM(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 Vi={dsTarget:.25,accelStep:.25,vTol:.002,scanSteps:24,seamIters:8,fitSpacing:1},II=32;function yM(e,t,r){let n=Math.round(e/t);return Math.max(1,Math.min(Number.isFinite(n)?n:1,Math.floor(r/II)||1))}function ct(e){let t=Vi,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 xM=Math.PI/180,nm=.02,RM=new WeakMap;function Bi(e){let t=RM.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)*xM,l=(e.bank?.[i]??0)*xM,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 RM.set(e,s),s}function om(e,t,r){return e.n0[t]+e.k[t]*r*r}function vM(e,t){return e.k[t]<0?Math.sqrt(Math.max(0,e.n0[t])/-e.k[t]):1/0}function kM(e,t){if(!e)return null;let r=1/0,n=-1/0;for(let o=0;o<e.n0.length;o++){let a=om(e,o,t[o]??0);a<r&&(r=a),a>n&&(n=a)}return r>=1-nm&&n<=1+nm?null:{lo:r,hi:n}}var Na=[.1,.25,.5,.75,1,1.25,1.5,2,2.5];function MM(e){let t=e.lo>=1-nm?1:1-1.25*(1-e.lo)-.05,r=e.hi<=1+nm?1:1+1.25*(e.hi-1)+.05,n=[...Na].reverse().find(a=>a<=t)??Na[0],o=Na.find(a=>a>=r)??Na[Na.length-1];return Na.filter(a=>a>=n&&a<=o)}function Nb(e,t,r){return r<1?Math.max(e,t):Math.min(e,t)}function SM(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=m=>c+l*m*m;return n?{vMax:s.vMax,axAccel:(m,f,p=1,d=1)=>s.axAccel(m,f,p,d)+t.axAccel(u(m),m,f,p,d)-r.axAccel(m,f,p,d),axDecel:(m,f,p=1,d=1)=>{let h=b=>s.axDecel(m,f,p,b)+t.axDecel(u(m),m,f,p,b)-r.axDecel(m,f,p,b);return d===1?h(1):Nb(h(d),h(1),d)},ay:(m,f,p=1)=>Math.max(0,s.ay(m,f,p)+t.ay(u(m),m,f,p)-r.ay(m,f,p)),scrub:(m,f,p=1)=>(s.scrub?.(m,f,p)??0)+t.scrub(u(m),m,f,p)-(r.scrub?.(m,f,p)??0)}:{vMax:s.vMax,axAccel:(m,f,p=1,d=1)=>t.axAccel(u(m),m,f,p,d),axDecel:(m,f,p=1,d=1)=>t.axDecel(u(m),m,f,p,d),ay:(m,f,p=1)=>t.ay(u(m),m,f,p),scrub:(m,f,p=1)=>t.scrub(u(m),m,f,p)}}}function am(e,t,r,n,o){let a=e.length,s=r?a:a-1,i=A=>r?(A+1)%a:A+1,{brakeAhead:c,apexAhead:l}=_I(e,t,r),u=new Array(a),m=new Array(a),f=new Array(a),p=new Array(a).fill(0),d=0,h=0,b=0,g=Math.max(0,Math.min(1,n.kept)),y=g>=1?0:n.up,R=g>=1?0:n.down,k=4*y*(1-g),v=A=>{let{v:w,gear:T,tau:P,target:S}=A;d=0,h=0,b=0;for(let F=0;F<s;F++){let C=i(F),L=e[C];for(let O=0;P<=0&&O<n.count;O++){let _=T;if(w<L-1e-9?n.best(w)>T&&(n.rpm(w,T)>=n.limitRpm||c[F]>=w*k)?_=T+1:T>0&&w<n.vIdle(T)&&(_=T-1):L<w-1e-9&&T>0&&n.best(l[F])<T&&n.rpm(w,T-1)<=n.limitRpm&&(_=T-1),_===T)break;S=_,_>T?d++:h++,P=_>T?y:R,P<=0&&(T=S)}u[F]=w,m[F]=T+1,f[F]=n.rpm(w,T);let E=P>0;p[F]=E?1:0;let D=L;if(!E)w<L&&(D=Math.min(L,Math.sqrt(Math.max(0,w*w+2*o(F,w,n.share(w,T))*t[F]))));else if(w<L){let O=o(F,w,g>0?g*n.share(w,T):0),_=Math.min(L,Math.sqrt(Math.max(0,w*w+2*O*t[F]))),z=w+_>0?2*t[F]/(w+_):1/0;if(z<=P)D=_,b+=z,P-=z;else{let I=Math.min(L,Math.max(0,w+O*P)),N=Math.max(0,t[F]-(w+I)*.5*P);b+=P,P=0,T=S,D=Math.min(L,Math.sqrt(Math.max(0,I*I+2*o(F,I,n.share(I,T))*N)))}}else{let O=w+D>0?2*t[F]/(w+D):0;b+=Math.min(O,P),P-=O,P<=0&&(T=S)}w=D}return{v:w,gear:T,tau:P,target:S}},x=n.best(e[0]),M={v:e[0],gear:x,tau:0,target:x};if(r)for(let A=0;A<6;A++){let w=v(M),T=Math.abs(w.v-M.v)<=1e-9&&w.gear===M.gear&&w.target===M.target&&Math.abs(w.tau-M.tau)<=1e-12;if(M=w,T)break}else{let A=v(M);u[a-1]=A.v,m[a-1]=A.gear+1,f[a-1]=n.rpm(A.v,A.gear),p[a-1]=A.tau>0?1:0}return{v:u,gear:m,rpm:f,shifting:p,upshifts:d,downshifts:h,gapTime:b}}function _I(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,f=e[m]<e[u]-1e-9;s=f?0:s+t[u],i=f?Math.min(i,e[m]):e[u],l<n&&(o[u]=s,a[u]=i)}return{brakeAhead:o,apexAhead:a}}var Ob=.001,Vb=9.81,$i=(e,t)=>sm(e?.gradient?.[t]??0);function sm(e){return e===0?0:-Vb*Math.sin(e*Math.PI/180)}function An(e,t){let r=new Array(t);for(let n=0;n<t;n++)r[n]=sm(e?.[n]??0);return r}var Sn=(e,t)=>{let r=e?.mu?.[t];return r!=null&&r>0?r:1},uo=(e,t)=>e?.bank?.[t]??0;function NI(e,t,r,n,o,a){let s=e.ay(t,r,Sn(o,a)),i=uo(o,a);if(!i)return s;let c=i*Math.PI/180,l=n===0?0:-Math.sign(n)*Vb*Math.sin(c);return Math.max(0,(s+l)/Math.cos(c))}function Ye(e,t){if(!t)return e;let r=t*Math.PI/180;return e*Math.cos(r)+Vb*Math.sin(r)}function Bb(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 mo=(e,t,r)=>t?t(r):e,OI=1e-4;function Oa(e,t,r,n,o,a,s){let i=ct(r),c=[];for(let l=0;l<t.length;l++){let u=t[l],m=Math.abs(u),f=mo(e,o,l),p=a!==void 0&&a>0?Math.min(f.vMax,a):f.vMax,d=s?Math.min(p,s(l)):p,h=m<=0?d:Bb(b=>b*b*m-NI(f,b,0,u,n,l),Ob,d,i.scanSteps,Math.min(i.vTol,OI));c.push({v:h,ax:0,ay:h*h*u})}return c}function VI(e,t,r,n,o,a,s=1,i=0,c=0,l){if(r.v<=t.v)return 0;let u=p=>{let d=Ye(p*p*n,c),h=(l?e.axDecel(p,Math.abs(d),s,l(p)):e.axDecel(p,Math.abs(d),s))+i;return Math.sqrt(Math.max(0,p*p+2*h*o))},m=r.v;r.v=Bb(p=>u(p)-t.v,Ob,r.v,a.scanSteps,a.vTol),r.ay=r.v*r.v*n;let f=Math.abs(Ye(r.ay,c));return r.ax=(l?e.axDecel(r.v,f,s,l(r.v)):e.axDecel(r.v,f,s))+i,m-r.v}function BI(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(Ye(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 AM(e,t,r,n,o,a){let s=ct(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 f=(m+1)%i;u=Math.max(u,VI(mo(e,o,m),t[f],t[m],r.curvature[m],r.ds[m],s,Sn(r,m),$i(r,m),uo(r,m),a?p=>a(m,p):void 0))}if(u<=s.vTol)break}return c}function FM(e,t,r,n,o,a){let s=ct(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 f=(m+1)%i;u=Math.max(u,BI(mo(e,o,m),t[f],t[m],r.curvature[m],r.ds[m],Sn(r,m),$i(r,m),uo(r,m),a?a[m]:1))}if(u<=s.vTol)break}return c}function $I(e,t,r){let n=r.load?Bi(t):null;if(!n||!r.load)return{pick:r.envelope};let o=t.npts;return{pick:SM(n,r.load,e,r.envelope),cap:a=>vM(n,a%o),n:(a,s)=>om(n,a,s)}}function wM(e,t,r,n,o,a,s){return am(n,r.ds,o,a,(i,c,l)=>{let u=c*c*r.curvature[i];return mo(e,t,i).axAccel(c,Math.abs(Ye(u,uo(r,i))),Sn(r,i),s?l*s[i]:l)+$i(r,i)})}function CM(e,t){return{gear:e.gear.slice(0,t),engineRpm:e.rpm.slice(0,t),shifting:e.shifting.slice(0,t)}}function TM(e,t,r,n){if(!e.scrub)return{};let o=!1,a=n.map((s,i)=>{let c=mo(e,t,i),l=Ye(s*s*r.curvature[i],uo(r,i)),u=c.scrub?c.scrub(s,Math.abs(l),Sn(r,i)):0;return u!==0&&(o=!0),u});return o?{axScrub:a}:{}}function At(e,t,r,n={}){let o=ct(r),a=t.npts,s=t.closed&&!n.standingStart,{pick:i,cap:c,n:l}=$I(e,t,n),u=n.driveDerate,m=n.brakeFade;if(!s)return GI(e,t,o,n.standingStart===!0,i,u,n.vCeiling,m,c,l,n.shifts);let f=Oa(e,t.curvature,o,t,i,n.vCeiling,c),p=AM(e,f,t,o,i,m),d=FM(e,f,t,o,i,u),h=n.shifts?wM(e,i,t,f.map(k=>k.v),!0,n.shifts,u):void 0;if(h)for(let k=0;k<a;k++)f[k].v=h.v[k];for(let k=0;k<a;k++){let v=f[k];v.ay=v.v*v.v*t.curvature[k];let x=f[(k+1)%a].v;v.ax=(x*x-v.v*v.v)/(2*t.ds[k])}let b=f.map(k=>k.v),g=f.map(k=>k.ax),y=f.map(k=>k.ay),R=0;for(let k=0;k<a;k++){let v=b[k]+b[(k+1)%a];v>0&&(R+=2*t.ds[k]/v)}return{states:f,v:b,ax:g,ay:y,laptime:R,sweeps:{backward:p,forward:d},...l?{loadFactor:b.map((k,v)=>l(v,k))}:{},...TM(e,i,t,b),...h?CM(h,a):{}}}function GI(e,t,r,n,o,a,s,i,c,l,u){let m=t.npts,f=t.closed?m:m-1,p=f+1,d=new Array(p);for(let R=0;R<p;R++)d[R]=t.curvature[R%m];let h=Oa(e,d,r,t,o,s,c);n&&(h[0].v=0);for(let R=f-1;R>=0;R--){let k=h[R],v=h[R+1];if(k.v<=v.v)continue;let x=mo(e,o,R),M=w=>{let T=Ye(w*w*t.curvature[R],uo(t,R)),P=(i?x.axDecel(w,Math.abs(T),Sn(t,R),i(R,w)):x.axDecel(w,Math.abs(T),Sn(t,R)))+$i(t,R);return Math.sqrt(Math.max(0,w*w+2*P*t.ds[R]))},A=n&&R===0?k.v:Ob;k.v=Bb(w=>M(w)-v.v,A,k.v,r.scanSteps,r.vTol)}for(let R=0;R<f;R++){let k=h[R],v=h[R+1];k.ay=k.v*k.v*t.curvature[R];let x=Ye(k.ay,uo(t,R));k.ax=mo(e,o,R).axAccel(k.v,Math.abs(x),Sn(t,R),a?a[R]:1)+$i(t,R),v.v=Math.min(v.v,Math.sqrt(Math.max(0,k.v*k.v+2*k.ax*t.ds[R])))}let b=u?wM(e,o,t,h.map(R=>R.v),!1,u,a):void 0;if(b)for(let R=0;R<p;R++)h[R].v=b.v[R];let g=0;for(let R=0;R<f;R++){let k=h[R].v+h[R+1].v;k>0&&(g+=2*t.ds[R]/k)}let y=h.slice(0,m);for(let R=0;R<m;R++){let k=y[R];k.ay=k.v*k.v*t.curvature[R];let v=R<f?h[R+1].v:k.v;k.ax=t.ds[R]>0?(v*v-k.v*k.v)/(2*t.ds[R]):0}return{states:y,v:y.map(R=>R.v),ax:y.map(R=>R.ax),ay:y.map(R=>R.ay),laptime:g,sweeps:{backward:1,forward:1},...l?{loadFactor:y.map((R,k)=>l(k,R.v))}:{},...TM(e,o,t,y.map(R=>R.v)),...b?CM(b,m):{}}}var PM=(e,t)=>{let r=e[t]?.value;return Number.isFinite(r)&&r>0?r:0};function po(e,t,r){let n=e.m.value,o=e.r_dyn?.value??0,a=PM(e,"I_wheel"),s=e.motorModel?.kind==="ice"?0:PM(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,f=u*a/c,p=n+m+f;return{mass:n,driven:m,undriven:f,effective:p,powerFactor:n/p,tractionFactor:n/(n+f)}}function fo(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 Gi=36e5,IM=Math.PI*2,$b=e=>Math.max(0,Math.min(1,e));function Gb(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=al(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/IM),l=Math.max(0,i*o/(n*a)),u=r.efficiency(c,l);return u>.01?u:.5}}var LM=new WeakMap;function Va(e){if(e.batteryModel)return e.batteryModel;let t=e.capacity.value,r=e.ocv.value,n=LM.get(e);if(n&&n.capacityAh===t&&n.ocv===r)return n.model;let o=gd(t,r);return LM.set(e,{capacityAh:t,ocv:r,model:o}),o}function Kb(e){let t=e.params,r=Kh(t,bu(e));if(dt(t.motorModel)||gt(t).mode!=="hydraulic")return r;let n;return(o,a,s,i=0)=>{if(!(o>0))return 0;n??=KI(e);let c=Mu(n.inp,n.ev,o,a,i);return c?Math.min(o,c.regenFront+c.regenRear):r(o,a,s)}}var DM=new WeakMap;function KI(e){let t=e.params,r=DM.get(t);if(!r){let n=Gr(t);r={inp:yt(n.regen?t:{...t,energy:{...n,regen:!0}}),ev:yr(t)},DM.set(t,r)}return r}var Ki=e=>e.airTempC??Dt;function im(e,t){return e.thermal?e.thermal.startC??t:jo}function EM(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 _M=()=>({windingC:[],derate:[],lossW:[],torqueNm:[],ampsRms:[]});function HI(e){let t=e.motorModel;if(dt(t))return;let r=t?al(t).maxTorque:s=>Ie(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/IM),peak:r,torque:(s,i,c)=>Math.min(Math.abs(s)*o/(n*a),c*r(i))}}function zI(e,t){let r=e.motorModel?.thermal;if(!r||!t)return;let n=r.torqueConstant;return{...t,th:yd(r),amps:o=>n>0?Math.abs(o)/n:0}}function YI(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),f=u?c/l:1,p=r*f;return{dq:m*p,lossJ:m*m*e.resistance(n,o)*p,energyJ:l*p,short:c>i,cutoff:u,seconds:p}}function WI(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 jI(e){let{drivenFront:t,drivenRear:r}=fo(e);return po(e.params,t,r)}function Ba(e,t,r,n,o=$r,a,s,i,c,l,u){let m=e.params,f=m.rho.value,p=m.fr_0.value,d=m.m.value,h=e.FG,b=m.aeroModel?yt(m):void 0,g=Gb(m),y=wr(Va(m)),R=y.chargeC,k=$b(a??m.soc.value),v=Ki(m),x=s??im(y,v),M=x,A=0,w=0,T=0,P=0,S=-1,F=-1,C=-1,L=i||m.motorModel?.thermal?HI(m):void 0,E=zI(m,L),D=E?E.th.startC:0,O=D,_=0,z=1,I=-1,N=0,B=0,V=Kb(e),G=m.motorModel?.kind==="ice",H=u?.scrub,Y=H?d/jI(e).tractionFactor:0,J=Math.min(t.length,r.length);for(let j=0;j<J;j++){let ee=r[j],ne=ee*ee,de=n[j]-(c?.[j]??0),{cl:W,cw:Z,A:re}=rm(m,ee,de/9.81,b),me=.5*f*W*re*ne,pe=.5*f*Z*re*ne,ie=(h+me)*-p,ae=H?-Y*(H[j]??0):0,ce=ie+pe+ae+d*de,_e=ce*t[j],Fe=j+1<r.length?r[j+1]:ee,Re=.5*(ee+Fe),ue=Re>0?t[j]/Re:0,we=0,Ke=k,tt=x,xe=0,ve=0,Le=ue;if(G){ce>0&&(ve=_e/g(ee,ce),A+=ve/Gi),l?.netKwh.push(A-w),l?.powerKw?.push(ue>0?ve/ue/1e3:0);continue}if(ce>0){let he=_e/g(ee,ce),be=YI(y,he,ue,k,x);be.short&&S<0&&(S=j),be.cutoff&&F<0&&(F=j);let Ue=k*R,ke=Math.min(be.dq,Ue),Xe=be.dq>0?ke/be.dq:1;ke>=Ue&&C<0&&(C=j),A+=be.energyJ*Xe/Gi,ve=be.energyJ*Xe,Le=be.seconds,T+=be.lossJ*Xe,P+=ke,ue>0&&(xe=ke/be.seconds),k=$b(k-ke/R),x=EM(y,x,be.dq>0&&ue>0?ke/ue:0,be.lossJ*Xe,ue,v),x>M&&(M=x),we=ce}else if(o.regen){let he=u?Ye(u.ay[j],u.bank?.[j]??0)/9.81:0,be=V(-ce,ee,de/9.81,he),Ue=o.regenEfficiency*be*t[j],ke=WI(y,Ue,ue,k,x),Xe=(1-k)*R,Bt=Math.min(ke.dq,Xe),Ct=ke.dq>0?Bt/ke.dq:1;w+=ke.energyJ*Ct/Gi,ve=-ke.energyJ*Ct,T+=ke.lossJ*Ct,P-=Bt,ue>0&&(xe=-Bt/ue),k=$b(k+Bt/R),x=EM(y,x,Bt>0&&ue>0?-Bt/ue:0,ke.lossJ*Ct,ue,v),x>M&&(M=x),we=-be*Ct}if(l?.netKwh.push(A-w),l?.powerKw?.push(ue>0?ve/Le/1e3:0),l?.pack){let he=l.pack;he.soc.push(Ke),he.amps.push(xe),he.volts.push(y.ocv(Ke)-xe*y.resistance(Ke,tt)),he.cellC.push(tt)}if(E){let he=E.rpm(ee),be=E.th.derate(he,D,E.peak(he));be<z&&(z=be),be<1&&I<0&&(I=j),B+=ue,be<1&&(N+=ue);let Ue=E.torque(we,he,be),ke=E.th.lossW(he,Ue,D);_+=ke*ue,i&&(i.windingC.push(D),i.derate.push(be),i.lossW.push(ke),i.torqueNm.push(Ue),i.ampsRms.push(E.amps(Ue))),D=E.th.step(D,ke,ue),D>O&&(O=D)}else L&&i&&i.torqueNm.push(L.torque(we,L.rpm(ee),1))}return{drive:A,regen:w,net:A-w,chargeAh:P/3600,loss:T/Gi,socEnd:k,shortAt:S,cutoffAt:F,emptyAt:C,tempEndC:x,tempMaxC:M,...E?{motorTempEndC:D,motorTempMaxC:O,motorLossKwh:_/Gi,motorDerateMin:z,motorDerateAt:I,motorDerateTimeFrac:B>0?N/B:0}:{}}}var UI=.5,XI=.02,qI=6;function NM(e,t,r,n,o,a,s,i){let c=n(),l=1,u=d=>{let h=_M(),b=Ba(e,t,d.v,d.ax,r,o,a,h,s,void 0,{ay:d.ay,bank:i,...d.axScrub?{scrub:d.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 f=m.trace.derate.slice(),p=!1;for(let d=0;d<qI;d++){let h=n(f);l++;let b=Math.abs(h.laptime-c.laptime);if(c=h,m=u(c),b<XI){p=!0;break}let g=m.trace.derate,y=new Array(f.length);for(let R=0;R<f.length;R++)y[R]=f[R]+UI*((g[R]??1)-f[R]);f=y}return{lap:c,derate:f,solves:l,converged:p,peakWindingC:m.peak,derateTimeFrac:m.frac}}var QI=.1;function OM(e){let t=e.power_limit_kw?.value??0;return t>0?t*1e3:0}function Hb(e,t,r){return e.motorModel?.kind==="ice"?1/0:wr(Va(e)).maxPower(t??e.soc.value,r,OM(e)).watts}function cm(e,t,r,n){let o=Hb(e,r,n);if(!Number.isFinite(o))return 1/0;if(o<=0)return 0;let a=Math.max(QI,t),s=Gb(e),i=o*(e.effi_pgb?.value??.9)/a;return o*s(t,i)/a}var ZI=180/Math.PI;function lm(e,t,r,n){let o=e*t,a=e*(1-t);return o/r-a/n}var um=e=>e*9.81*ZI;var Vq=Math.PI/180;function mm(e,t,r,n=0){let o=Te(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?lm(e.massTotal,e.frontMassFrac,2*i,2*c):0,u=um(l),m=u>.15?"understeer":u<-.15?"oversteer":"neutral";return{gradient:u,balance:m,cAlphaFront:i,cAlphaRear:c}}var Wq=Math.PI/180,jq=180/Math.PI;var VM=2220446049250313e-31;function t2(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 f=0;f<t;f++)e[a][f]*=m;for(let f=0;f<t;f++)e[f][a]*=l}}}}}function r2(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 n2(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])<=VM*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 f=.5*(u-l),p=f*f+m,d=Math.sqrt(Math.abs(p));l+=s,p>=0?(d=f+(f>=0?Math.abs(d):-Math.abs(d)),r[a-1]=r[a]=l+d,d!==0&&(r[a]=l-m/d),n[a-1]=n[a]=0):(r[a-1]=r[a]=l+f,n[a]=d,n[a-1]=-d),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 f=a-2,p=0,d=0,h=0;for(;f>=c;f--){let b=e[f][f],g=l-b,y=u-b;p=(g*y-m)/e[f+1][f]+e[f][f+1],d=e[f+1][f+1]-b-g-y,h=e[f+2][f+1];let R=Math.abs(p)+Math.abs(d)+Math.abs(h);if(p/=R,d/=R,h/=R,f===c)break;let k=Math.abs(e[f][f-1])*(Math.abs(d)+Math.abs(h)),v=Math.abs(p)*(Math.abs(e[f-1][f-1])+Math.abs(b)+Math.abs(e[f+1][f+1]));if(k<=VM*v)break}for(let b=f+2;b<=a;b++)e[b][b-2]=0,b!==f+2&&(e[b][b-3]=0);for(let b=f;b<=a-1;b++){b!==f&&(p=e[b][b-1],d=e[b+1][b-1],h=b!==a-1?e[b+2][b-1]:0,l=Math.abs(p)+Math.abs(d)+Math.abs(h),l!==0&&(p/=l,d/=l,h/=l));let g=Math.sqrt(p*p+d*d+h*h),y=p>=0?g:-g;if(y!==0){b===f?c!==f&&(e[b][b-1]=-e[b][b-1]):e[b][b-1]=-y*l,p+=y,l=p/y,u=d/y;let R=h/y;d/=p,h/=p;for(let v=b;v<=a;v++){let x=e[b][v]+d*e[b+1][v];b!==a-1&&(x+=h*e[b+2][v],e[b+2][v]-=x*R),e[b+1][v]-=x*u,e[b][v]-=x*l}let k=a<b+3?a:b+3;for(let v=c;v<=k;v++){let x=l*e[v][b]+u*e[v][b+1];b!==a-1&&(x+=R*e[v][b+2],e[v][b+2]-=x*h),e[v][b+1]-=x*d,e[v][b]-=x}}}}}}while(c<a-1&&a>=0)}return r.map((i,c)=>({re:i,im:n[c]}))}function BM(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 t2(r),r2(r),n2(r)}function $M(e){let t=[],r=new Array(e.length).fill(!1),n=BM(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 zb(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 f=e[c][c],p=t[c][c],d=f*f+p*p;for(let h=c+1;h<r;h++){let b=(e[h][c]*f+t[h][c]*p)/d,g=(t[h][c]*f-e[h][c]*p)/d;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 f=0,p=0;for(let d=c+1;d<r;d++)f+=e[c][d]*o[d]-t[c][d]*a[d],p+=e[c][d]*a[d]+t[c][d]*o[d];o[c]=-(f*l+p*u)/m,a[c]=-(p*l-f*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 o2(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 zb(r,n)}function pm(e,t=r=>o2(e,r)){return $M(e).map(r=>({...r,vector:t(r.eigenvalue)}))}function $a(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 GM(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 $a(pm(i),c,0)}function KM(e,t,r,n){let o=(r==="front"?t.sprungFront:t.sprungRear)/2;if(o<=0)return{dampingRatio:0,criticalDamping:0,naturalFreqDamped:0};let a=r==="front"?t.rideRateFront:t.rideRateRear,s=r==="front"?e.wheelRateFront+(e.heaveSpringFront??0):e.wheelRateRear+(e.heaveSpringRear??0),i=GM({sprungMass:o,unsprungMass:e.unsprungCornerMass??e.unsprungPerCorner,springRate:s,damperRate:n,tireRate:qe(e,r),tireDamping:e.tireDamping}),c=2*Math.sqrt(a*1e3*o);return{dampingRatio:i?.dampingRatio??0,criticalDamping:c/1e3,naturalFreqDamped:i?.dampedFreq??0}}function dm(e,t,r){let n=Ce(e);return{front:KM(e,n,"front",t??n.rideDampingFront),rear:KM(e,n,"rear",r??n.rideDampingRear)}}var sQ=180/Math.PI;var Yb=["FL","FR","RL","RR"],le={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},Ga=20,HM=[le.zFL,le.zFR,le.zRL,le.zRR],zM=[le.vzFL,le.vzFR,le.vzRL,le.vzRR],Qr={fzFL:0,fzFR:1,fzRL:2,fzRR:3,fzBody:4,myBody:5,mxBody:6,fx:7,fy:8,mz:9},Wb=10;function fm(e){let t=Array.from({length:Ga},()=>new Array(Ga).fill(0)),r=Array.from({length:Ga},()=>new Array(Wb).fill(0));t[le.zFL][le.vzFL]=1,t[le.zFR][le.vzFR]=1,t[le.zRL][le.vzRL]=1,t[le.zRR][le.vzRR]=1,t[le.zBody][le.vzBody]=1,t[le.pitch][le.pitchRate]=1,t[le.roll][le.rollRate]=1,t[le.x][le.vx]=1,t[le.y][le.vy]=1,t[le.yaw][le.yawRate]=1;let{inertia:n}=e,o=[1,0,3,2],a=(s,i,c,l)=>{s[HM[i]]-=c,s[zM[i]]-=l,s[le.zBody]+=c,s[le.vzBody]+=l,s[le.pitch]-=c*e.leverX[i],s[le.pitchRate]-=l*e.leverX[i],s[le.roll]+=c*e.leverY[i],s[le.rollRate]+=l*e.leverY[i]};for(let s=0;s<4;s++){let i=s<2,c=M=>M?i?M.front:M.rear:0,l=e.springRate[s]+c(e.heaveSpring),u=e.springRate[s]+c(e.arb),m=e.damperRate[s]+c(e.heaveDamper),f=e.damperRate[s]+c(e.rollDamper),p=(l+u)/2,d=(l-u)/2,h=(m+f)/2,b=(m-f)/2,g=new Array(Ga).fill(0);a(g,s,p,h),(d!==0||b!==0)&&a(g,o[s],d,b);let y=e.wheelMass[s],R=e.leverX[s],k=e.leverY[s],v=HM[s],x=zM[s];for(let M=0;M<Ga;M++){let A=g[M];A!==0&&(t[x][M]+=A/y,t[le.vzBody][M]-=A/e.bodyMass,t[le.pitchRate][M]+=R*A/n.yy,t[le.rollRate][M]-=k*A/n.xx)}t[x][v]-=e.tyreRate[s]/y,t[x][x]-=e.tyreDamping[s]/y,r[x][Qr.fzFL+s]=1/y}return r[le.vzBody][Qr.fzBody]=1/e.bodyMass,r[le.pitchRate][Qr.myBody]=1/n.yy,r[le.rollRate][Qr.mxBody]=1/n.xx,r[le.vx][Qr.fx]=1/e.totalMass,r[le.vy][Qr.fy]=1/e.totalMass,r[le.yawRate][Qr.mz]=1/n.zz,{A:t,B:r,params:e}}function jb(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,f=qe(e,"front")*1e3,p=qe(e,"rear")*1e3,d=(e.tireDamping??0)*1e3;return{bodyMass:i,totalMass:e.massTotal,wheelMass:[s,s,s,s],inertia:{xx:e.rollInertia??i*.6*.6,yy:e.pitchInertia??i*1.2*1.2,zz:e.yawInertia??e.massTotal*1.2*1.2},leverX:[r,r,-n,-n],leverY:[o,-o,a,-a],springRate:[c,c,l,l],damperRate:[u,u,m,m],tyreRate:[f,f,p,p],tyreDamping:[d,d,d,d],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}}}var YM=le.rollRate+1;function WM(e){let t=e.params,r=[...t.wheelMass,t.bodyMass,t.inertia.yy,t.inertia.xx];if(!r.every(i=>i>0))return{};let n=e.A.slice(0,YM).map(i=>i.slice(0,YM));if(!n.every(i=>i.every(Number.isFinite)))return{};let a=pm(n,i=>{let c=i.re*i.re-i.im*i.im,l=2*i.re*i.im,u=r.map((f,p)=>r.map((d,h)=>(p===h?c:0)-i.re*n[2*p+1][2*h+1]-n[2*p+1][2*h])),m=r.map((f,p)=>r.map((d,h)=>(p===h?l:0)-i.im*n[2*p+1][2*h+1]));return zb(u,m)}),s=i=>{let c=r.map((u,m)=>u*(i[m].re**2+i[m].im**2)),l=c.reduce((u,m)=>u+m,0)||1;return[c[0]+c[1]+c[2]+c[3],c[4],c[5],c[6]].map(u=>u/l)};return{heave:$a(a,s,1),pitch:$a(a,s,2),roll:$a(a,s,3)}}function jM(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 hm(e){let t=Ce(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=WM(fm(jb(e)));return{roll:jM(m.roll,a,s),pitch:jM(m.pitch,l,u)}}var bm=9.81,Zr=Math.PI/180;function UM(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 Ka(e,t,r,n,o){let{wb:a,lf:s,lr:i,m:c}=UM(e),l=0;for(let R=0;R<16;R++){let k=l/r,v=o-n-s*k/r,x=-n+i*k/r,M=Te(e,l/bm,0,r),A=Math.max(0,M.FL+M.FR),w=Math.max(0,M.RL+M.RR),T=t(v,A),P=t(x,w),S=(T*Math.cos(o)+P)/c;if(l=.5*(l+S),Math.abs(S-l)<1e-4)break}let u=l/r,m=o-n-s*u/r,f=-n+i*u/r,p=Te(e,l/bm,0,r),d=Math.max(0,p.FL+p.FR),h=Math.max(0,p.RL+p.RR),b=t(m,d),g=t(f,h),y=s*b*Math.cos(o)-i*g;return{ay:l/bm,cn:y/(c*bm*a)}}function Ub(e,t,r,n={}){let o=Math.max(8,r),a=(n.betaMaxDeg??10)*Zr,s=(n.deltaMaxDeg??10)*Zr,i=n.nLines??9,c=n.nPts??21,l=(g,y,R,k)=>R===1?g:g+(y-g)*k/(R-1),u=[],m={ay:[],cn:[]},f=0;for(let g=0;g<i;g++){let y=l(-s,s,i,g),R=[],k=[],v=[],x=[];for(let M=0;M<c;M++){let A=l(-a,a,c,M),w=Ka(e,t,o,A,y);R.push(w.ay),k.push(w.cn),v.push(A/Zr),x.push(y/Zr),Math.abs(w.ay)>f&&(f=Math.abs(w.ay))}u.push({label:`\u03B4 ${(y/Zr).toFixed(0)}\xB0`,ay:R,cn:k,betaDeg:v,deltaDeg:x});for(let M=1;M<k.length;M++)if(k[M-1]===0||k[M-1]<0!=k[M]<0){let A=k[M-1]===k[M]?0:k[M-1]/(k[M-1]-k[M]);m.ay.push(R[M-1]+A*(R[M]-R[M-1])),m.cn.push(0);break}}let p=[];for(let g=0;g<i;g++){let y=l(-a,a,i,g),R=[],k=[],v=[],x=[];for(let M=0;M<c;M++){let A=l(-s,s,c,M),w=Ka(e,t,o,y,A);R.push(w.ay),k.push(w.cn),v.push(y/Zr),x.push(A/Zr)}p.push({label:`\u03B2 ${(y/Zr).toFixed(0)}\xB0`,ay:R,cn:k,betaDeg:v,deltaDeg:x})}let d=.5*Zr,h=(Ka(e,t,o,d,0).cn-Ka(e,t,o,-d,0).cn)/(2*d),b=(Ka(e,t,o,0,d).cn-Ka(e,t,o,0,-d).cn)/(2*d);return{isoBeta:p,isoDelta:u,trim:m,maxAy:f,stability:h,control:b,speed:o}}function a2(e){return!e.corneringStiffnessFront||!e.corneringStiffnessRear?null:{Cf:2*e.corneringStiffnessFront,Cr:2*e.corneringStiffnessRear}}function Hi(e,t){let r=a2(e);if(!r)return null;let{Cf:n,Cr:o}=r,{wb:a,lf:s,lr:i,m:c}=UM(e),l=e.yawInertia??c*1*1,u=Math.max(3,t),m=-(n+o)/(c*u),f=(-s*n+i*o)/(c*u)-u,p=(-s*n+i*o)/(l*u),d=-(s*s*n+i*i*o)/(l*u),h=m+d,b=m*d-f*p,g=h*h-4*b,y,R,k;if(g<0)y=h/2,R=Math.sqrt(Math.max(0,b)),k=R>0?-h/(2*R):1;else{let C=Math.sqrt(g);y=Math.max((h+C)/2,(h-C)/2),R=Math.sqrt(Math.abs(b)),k=R>0?-h/(2*R):1}let v=h<0&&b>0,x=lm(c,e.frontMassFrac,n,o),M=um(x),A=M>.15?"understeer":M<-.15?"oversteer":"neutral",w=s*n-i*o,T=C=>C*3.6,P=null,S=null;w>1e-6?S=T(Math.sqrt(n*o*a*a/(c*w))):w<-1e-6&&(P=T(Math.sqrt(n*o*a*a/(c*-w))));let F=u/(a+x*u*u);return{stable:v,yawFreq:R/(2*Math.PI),dampingRatio:k,eigReal:y,understeerGradient:M,balance:A,characteristicSpeed:P,criticalSpeed:S,yawRateGain:F}}var XM=Math.PI/180;function ZM(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 qM(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 JM(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,f]of[[s,1-c],[Math.min(o-1,s+1),c]])if(!(f<=0))for(let[p,d]of[[i,1-l],[Math.min(a-1,i+1),l]])d<=0||(u+=f*d*n(e.isoDelta[m],p,m));return u}function eS(e,t,r){let n=e.isoDelta[0],o=(n.betaDeg[1]-n.betaDeg[0])*XM||1,a=e.isoDelta.length>1?(e.isoDelta[1].deltaDeg[0]-e.isoDelta[0].deltaDeg[0])*XM:1,s=x=>JM(e,t,r,x),i=s((x,M)=>x.ay[M]),c=s((x,M)=>x.cn[M]),l=s((x,M)=>x.betaDeg[M]),u=s((x,M)=>x.deltaDeg[M]),m=s((x,M)=>qM(x.cn,M,o)),f=s((x,M,A)=>qM(e.isoDelta.map(w=>w.cn[M]),A,a||1)),p=Math.max(1e-6,e.maxAy),d=Math.abs(i)/p,h=Math.max(1e-6,...e.isoDelta.flatMap(x=>x.cn.filter(Number.isFinite).map(Math.abs))),b=Math.abs(c)/h,g=i===0?c:c*Math.sign(i),y=[];y.push(`${ZM(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 R=Math.abs(e.stability)>1e-9?m/e.stability:1;R<.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."):R<.85?y.push(`Yaw stiffness is down to about ${(100*R).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*R).toFixed(0)} %), so the car still opposes a change in body slip about as firmly as it does in a straight line.`);let k=Math.abs(e.control),v=k>1e-9?Math.abs(f)/k: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.`),d>.97?y.push(`At the edge of the diagram: ${Math.abs(i).toFixed(2)} g is essentially all this car has at this speed.`):d<.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:f,gripUsed:d,notes:y}}var QM=1e-4;function Xb(e){let t=null,r=f=>{if(!t)return!0;let p=Math.abs(f),d=Math.abs(t.ay);return p>d*(1+QM)?!0:p<d*(1-QM)?!1:f>0&&t.ay<0};for(let f=0;f<e.isoDelta.length;f++){let p=e.isoDelta[f];for(let d=1;d<p.cn.length;d++){if(!(p.cn[d-1]===0||p.cn[d-1]<0!=p.cn[d]<0))continue;let b=p.cn[d-1]===p.cn[d]?0:p.cn[d-1]/(p.cn[d-1]-p.cn[d]),g=p.ay[d-1]+b*(p.ay[d]-p.ay[d-1]);r(g)&&(t={ay:g,d:f,b:b<.5?d-1:d})}}if(!t)return null;let n=eS(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}}var s2=["tv_kp"];function tS(e=0){let t=e<0,r=e>0,n=t||r,o=[{key:"damper_front",why:"dampers act on velocity; every point here is at constant attitude"},{key:"damper_rear",why:"dampers act on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",why:"tyre damping acts on velocity; every point here is at constant attitude"},{key:"I_yaw",why:"inertia resists change; a steady corner has none"},{key:"I_roll",why:"inertia resists change; a steady corner has none"},{key:"I_pitch",why:"inertia resists change; a steady corner has none"},{key:"capacity",why:"energy does not enter a single steady-state point"},{key:"ocv",why:"energy does not enter a single steady-state point"},{key:"soc",why:"energy does not enter a single steady-state point"},...s2.map(s=>({key:s,why:"the feedback gain multiplies a yaw error, and a trimmed point has none \u2014 the feedforward does move this diagram"}))];t||o.push({key:"brake_balance",why:r?"the diagram is drawn under acceleration, not braking":"no braking: the diagram is drawn at constant speed"});let a=n?"the longitudinal condition is set directly; what a motor could deliver is the lap solver\u2019s question":"no tractive force is applied at a constant speed";for(let s of["gear_ratio","power_scale","power_limit_kw","driven_wheels","effi_pgb"])o.push({key:s,why:a});for(let s of["I_wheel","I_rotor"])o.push({key:s,why:n?"rotating inertia is longitudinal, and `ax` is set here rather than solved \u2014 nothing in this picture spins a wheel up":"rotating inertia only acts where the car changes speed"});return o.push({key:"v_limit_endurance",why:"a limiter constrains a lap\u2019s speed profile; this diagram is drawn at one imposed speed"}),o.push({key:"endurance_reserve",why:"an energy budget sets the long event\u2019s speed ceiling; this diagram is drawn at one imposed speed"}),o.push({key:"fr_0",why:n?"rolling resistance is a drag term; `ax` is what the car does, not what the tyres are handed":"rolling resistance is longitudinal"}),o.push({key:"r_dyn",why:n?"the force each tyre carries is set here in newtons; a radius would only convert it to a torque":"the rolling radius only matters where a wheel is driven or braked"}),o}var i2=tS(0);function rS(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 c2=rS(0);var l2=9.81;function u2(e){let t=e.wheelbase/1e3;return{lf:t*(1-e.frontMassFrac),lr:t*e.frontMassFrac}}function zi(e,t,r,n){let o=t.tire;if(!o)return null;let s=(r==="limit"?gb(e,o,t.speed):kn(e,o,t.speed,t.ayG)).wheels;return Er(n??ro(o,e.massTotal*l2*1.2),{FL:s.FL,FR:s.FR,RL:s.RL,RR:s.RR},u2(e))}function m2(e){if(!e.tire)return e.cornerStiffness;let t=ye(e.tire,"front"),r=ye(e.tire,"rear");return{front:n=>t.corneringStiffness(n),rear:n=>r.corneringStiffness(n)}}var nS=[{key:"understeer",label:"Understeer gradient",unit:"\xB0/g",compute:(e,t)=>mm(e,t.ayG,m2(t),t.speed).gradient},{key:"rollGradient",label:"Roll gradient",unit:"\xB0/g",compute:e=>Ce(e).rollGradient},{key:"pitchGradient",label:"Pitch gradient",unit:"\xB0/g",compute:e=>Ce(e).pitchGradient},{key:"tlltdFront",label:"TLLTD front",unit:"%",compute:e=>100*Pf(e)},{key:"rollStiffFront",label:"Front roll-stiffness",unit:"%",compute:e=>100*Ce(e).frontRollStiffFrac},{key:"rideFreqFront",label:"Ride freq front",unit:"Hz",compute:e=>Ce(e).rideFreqFront},{key:"rideFreqRear",label:"Ride freq rear",unit:"Hz",compute:e=>Ce(e).rideFreqRear},{key:"rollFreq",label:"Roll-mode freq",unit:"Hz",compute:e=>hm(e).roll.freq},{key:"pitchFreq",label:"Pitch-mode freq",unit:"Hz",compute:e=>hm(e).pitch.freq},{key:"zetaFront",label:"Damping \u03B6 front",unit:"-",compute:e=>dm(e).front.dampingRatio},{key:"zetaRear",label:"Damping \u03B6 rear",unit:"-",compute:e=>dm(e).rear.dampingRatio},{key:"yawFreq",label:"Yaw natural freq",unit:"Hz",compute:(e,t)=>Hi(e,t.speed)?.yawFreq??NaN},{key:"yawZeta",label:"Yaw damping \u03B6",unit:"-",compute:(e,t)=>Hi(e,t.speed)?.dampingRatio??NaN},{key:"stabilitySpeed",label:"Char./critical speed",unit:"km/h",compute:(e,t)=>{let r=Hi(e,t.speed);return r?r.criticalSpeed??r.characteristicSpeed??NaN:NaN}},{key:"maxAy",label:"Max lateral accel",unit:"g",compute:(e,t)=>t.fyAxle?Ub(e,t.fyAxle,t.speed,{betaMaxDeg:12,deltaMaxDeg:12}).maxAy:NaN},{key:"yawReserveRear",label:"Yaw stability reserve",unit:"N\xB7m",compute:(e,t)=>zi(e,t,"operating")?.stabil??NaN},{key:"yawReserveFront",label:"Yaw agility reserve",unit:"N\xB7m",compute:(e,t)=>zi(e,t,"operating")?.agil??NaN},{key:"limitBalance",label:"Limit balance (+US / \u2212OS)",unit:"-",compute:(e,t)=>zi(e,t,"limit")?.rel??NaN},{key:"yawStiffness",label:"Yaw stiffness N_\u03B2",unit:"N\xB7m/rad",compute:(e,t)=>t.tire?bb(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorque",label:"Steering holding torque",unit:"N\xB7m",compute:(e,t)=>t.tire?fb(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorqueGradient",label:"Steering feedback gradient",unit:"N\xB7m/g",compute:(e,t)=>t.tire?hb(e,t.tire,t.speed,t.ayG):NaN}],qb=Object.fromEntries(nS.map(e=>[e.key,e]));var Jr=9.81;function p2(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 d2={front:!1,rear:!0};function Ha(e,t,r){let n=e.muX(t)*t,o=e.muY(t)*t;if(!(n>0))return 0;let a=o>0?Math.min(1,r/o):1;return n*Math.sqrt(1-a*a)}function oS(e,t,r,n,o,a){let s=e[t]+e[r];if(!(s>0))return;let i=Ha(n,o[t],a[t]),c=Ha(n,o[r],a[r]);i+c>0||(i=n.muX(o[t])*o[t],c=n.muX(o[r])*o[r]),i+c>0&&(e[t]=s*i/(i+c),e[r]=s-e[t])}function aS(e,t,r,n,o,a={},s="open"){if(!e.rear)return 1;if(!e.front)return 0;let i=(f,p,d)=>d?di(f,p,d):s==="own"?f+p:2*Math.min(f,p),c=i(Ha(n,t.FL,r.FL),Ha(n,t.FR,r.FR),a.front),l=i(Ha(o,t.RL,r.RL),Ha(o,t.RR,r.RR),a.rear);if(c+l>0)return c/(c+l);let u=n.muX(t.FL)*t.FL+n.muX(t.FR)*t.FR,m=o.muX(t.RL)*t.RL+o.muX(t.RR)*t.RR;return u+m>0?u/(u+m):.5}function Qb(e,t,r,n){return{car:t?cS(t,r.loadFactor[n]):e,ayTyre:Ye(r.ay[n],r.bank?.[n]??0),axCar:r.ax[n]-(r.axGrade?.[n]??0)}}function sS(e,t){if(!e.aero?.model)return 0;let r=Math.min(t.v.length,t.ax.length,t.ay.length),n=t.loadFactor?ym(e):void 0,o=0,a=0;for(let s=0;s<r;s++){let i=t.ds?.[s]??1,c=Qb(e,n,t,s);o+=i,Tf(c.car,t.v[s],c.axCar/Jr,c.ayTyre/Jr)&&(a+=i)}return o>0?a/o:0}function iS(e,t,r){let n=Zt(ye(t,"front")),o=Zt(ye(t,"rear")),a=Math.min(r.v.length,r.ax.length,r.ay.length),s=r.loadFactor?ym(e):void 0,i=0,c=0;for(let l=0;l<a;l++){let u=r.ds?.[l]??1,m=Qb(e,s,r,l);i+=u;let f=Te(m.car,m.ayTyre/Jr,m.axCar/Jr,r.v[l]);(f.FL>n||f.FR>n||f.RL>o||f.RR>o)&&(c+=u)}return i>0?c/i:0}function gm(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=Ri(t,e.massTotal*Jr*1.2),l=ga(c,"front"),u=ga(c,"rear"),m=ht(ye(t,"front")),f=ht(ye(t,"rear")),p=n.perWheel?If(m,l):null,d=n.perWheel?f===m?p:If(f,u):null,h=n.driven??d2,b={front:Wt(e,"front",1),rear:Wt(e,"rear",1)},g={front:0,rear:0},y=new Array(o),R=new Array(o),k=new Array(o),v=1/0,x=0,M=0,A=Zt(m),w=Zt(f),T=0,P=0,S=0,F=0,C=0,L=0,E=["FL","FR","RL","RR"],D=n.perWheel?Object.fromEntries(E.map(_=>[_,{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,O=r.loadFactor?ym(e):void 0;for(let _=0;_<o;_++){let z=Qb(e,O,r,_),{ayTyre:I,axCar:N}=z,B=I/Jr,V=Te(z.car,B,N/Jr,r.v[_]),G=e.massTotal*I,H=G*i/a,Y=G*s/a,J=js(m,H,V.FL,V.FR,C),j=js(f,Y,V.RL,V.RR,L);C=J,L=j;let ee={FL:Math.abs(m.Fy(J,V.FL,0)),FR:Math.abs(m.Fy(J,V.FR,0)),RL:Math.abs(f.Fy(j,V.RL,0)),RR:Math.abs(f.Fy(j,V.RR,0))},ne=(N-(r.axDrag?.[_]??0)-(r.axScrub?.[_]??0))/Jr,de=ne>0&&h.front?aS(h,V,ee,l,u,b,"own"):0,W=r.v[_]*r.v[_],Z=e.driveline?{Fz:V,alpha:{front:J,rear:j},curvature:W>1?r.ay[_]/W:0,seed:g}:void 0,re={...ub(e,ne,r.v[_],t,B,de,Z)};ne>0&&(b.front||oS(re,"FL","FR",l,V,ee),b.rear||oS(re,"RL","RR",u,V,ee));let me=!1,pe=!1;for(let ce of["FL","FR","RL","RR"]){let _e=(ce==="FL"||ce==="FR"?l:u).muX(V[ce])*V[ce];Math.abs(re[ce])>_e&&(me=!0),V[ce]>(ce==="FL"||ce==="FR"?A:w)&&(pe=!0)}pe&&(M+=r.ds?.[_]??1);let ie=Er(c,{FL:{Fz:V.FL,Fy:ee.FL,Fx:re.FL},FR:{Fz:V.FR,Fy:ee.FR,Fx:re.FR},RL:{Fz:V.RL,Fy:ee.RL,Fx:re.RL},RR:{Fz:V.RR,Fy:ee.RR,Fx:re.RR}},{lf:s,lr:i});if(y[_]=ie.stabil,R[_]=ie.agil,k[_]=ie.rel,D){let ce=.5*(V.FL+V.FR),_e=.5*(V.RL+V.RR),Fe=l.muX(ce)*ce,Re=u.muX(_e)*_e;for(let ue of E){let we=V[ue],Ke=ue==="FL"||ue==="FR",tt=Ke?l:u,xe=tt.muY(we)*we,ve=tt.muX(we)*we,Le=D[ue],he=Ke?J:j;Le.Fz[_]=we,Le.alpha[_]=he,Le.Fy[_]=ee[ue],Le.Fx[_]=re[ue],Le.Mz[_]=we>0?(Ke?m:f).Mz(he,we,0):0,Le.FxCap[_]=ve,Le.FyCap[_]=xe;let be=xe>0?Math.min(1,Math.abs(ee[ue])/xe):0,Ue=p2(re[ue],ve,Ke?Fe:Re),ke=Ke?p:d,Xe=ke&&we>0?ke.reach(we,Math.sign(re[ue])*Ue,be):1;Le.used[_]=Math.hypot(be,Ue)/Xe}}ie.stabil<v&&(v=ie.stabil,x=_);let ae=r.ds?.[_]??1;F+=ae,ie.diff>0&&(T+=ae),me&&(P+=ae),Tf(z.car,r.v[_],N/Jr,B)&&(S+=ae)}return{stabil:y,agil:R,rel:k,minStabil:Number.isFinite(v)?v:0,minStabilAt:x,pastTurnoverFrac:F>0?M/F:0,understeerFrac:F>0?T/F:0,beyondFrac:F>0?P/F:0,aeroOutsideFrac:F>0?S/F:0,wheels:D}}function ym(e){return Object.create(e,{loadFactor:{value:1,writable:!0,enumerable:!0}})}function cS(e,t){return e.loadFactor=t,e}var Zb=9.81;function Jb(e,t,r,n={}){let o=r.v.length,a=e.massTotal,s=Hr(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),f=m-(r.axDrag?.[l]??0)-(r.axScrub?.[l]??0),p=-a*f;if(!(p>0))continue;let d=Ye(r.ay[l],r.bank?.[l]??0)/Zb,h=Math.min(.99,Math.max(.01,Fa(e,f/Zb,u,t,d)));c.front[l]=p*h,c.rear[l]=p*(1-h);let b=i?Mu(e,t,p,u,d):void 0;if(c.regen&&n.regen&&(c.regen[l]=b?Math.min(p,b.regenFront+b.regenRear):n.regen(p,u,m/Zb)),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(p,u),u);c.pFront[l]=g.pFront,c.pRear[l]=g.pRear,c.pedalN[l]=g.pedalN}}return c}var bZ=Math.PI/180;var gZ=Yb.map(vi);var yZ=[le.zFL,le.zFR,le.zRL,le.zRR];var xZ=Array.from({length:le.rollRate+1},(e,t)=>t);var F2=9.81,w2=.001,C2=.6,T2=2,pS=4;function dS(e,t,r,n=pS){let o=Math.min(e.v.length,t.npts),{ds:a,closed:s}=t,i=r.massTotal*F2*r.wheelbase,c=P2(e.ay.slice(0,o).map((m,f)=>m/Math.max(w2,e.v[f])),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 f=m===0?s?o-1:-1:m-1,p=m===o-1?s?0:-1:m+1;if(f<0||p<0)continue;let d=a[f]+a[m];if(!(d>0))continue;u[m]=e.v[m]*(c[p]-c[f])/d;let h=Math.sign(c[m]);l[m]=h===0?0:h*r.yawInertia*u[m]/i}return{demand:l,rdot:u}}function P2(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,f=0;for(let p=1;p<=s&&!(!r&&c+p>=o||(f+=t[(c+p-1)%o],!(f<l)));p++){let d=1-f/l;u+=d*e[(c+p)%o],m+=d}f=0;for(let p=1;p<=s&&!(!r&&c-p<0);p++){let d=(c-p+o)%o;if(f+=t[d],!(f<l))break;let h=1-f/l;u+=h*e[d],m+=h}i[c]=u/m}return i}function fS(e,t,r,n,o={}){let a=o.maxIter??20,s=o.tol??.001,i=Math.min(1,Math.max(.001,o.relax??C2)),c=o.smoothM??pS,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=At(e.steady,t,n,l),m=[u.laptime],f=new Array(t.npts).fill(0),p=f.slice(),d=u,h=0,b=!1,g=0;for(let k=0;k<a;k++){h=k+1;let v=dS(d,t,r,c);f=v.demand.map((A,w)=>f[w]+i*(A-f[w])),p=v.rdot;let x=At(e.steady,t,n,{...l,envelope:A=>e.at(f[A]??0)});m.push(x.laptime);let M=Math.abs(x.laptime-d.laptime);if(d=x,g=M<=s?g+1:0,g>=T2){b=!0;break}}let y=0,R=0;for(let k=0;k<t.npts;k++)R+=t.ds[k],e.clamps(f[k]??0)&&(y+=t.ds[k]);return{...d,steady:u,demand:f,rdot:p,history:m,iterations:h,converged:b,clampedFrac:R>0?y/R:0}}var CZ=Math.PI/180;var pJ=180/Math.PI;function za(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=f=>{let p=e[f];return i*(r-s)*(r-p)/((a-s)*(a-p))+c*(r-a)*(r-p)/((s-a)*(s-p))+t[f]*(r-a)*(r-s)/((p-a)*(p-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 bS(e,t){let r=e.filter(p=>p.atLock),n=e.filter(p=>!p.atLock),o=r.length>0&&n.length>0&&r[r.length-1].v<n[0].v,a=p=>({vs:p.map(h=>h.v),ayMax:p.map(h=>h.ayMax),radius:p.map(h=>Math.max(h.v,t)**2/h.ayMax),accel:p[0].axAccelN.map((h,b)=>p.map(g=>g.axAccelN[b])),decel:p[0].axDecelN.map((h,b)=>p.map(g=>g.axDecelN[b])),scrub:p[0].axScrubN.map((h,b)=>p.map(g=>g.axScrubN[b]))}),s=(p,d)=>({axAccelN:p.accel.map(h=>za(p.vs,h,d)),axDecelN:p.decel.map(h=>za(p.vs,h,d)),axScrubN:p.scrub.map(h=>za(p.vs,h,d))});if(!o){let p=a(e);return d=>({ayMax:za(p.vs,p.ayMax,d),...s(p,d)})}let i=a(r),c=a(n),l=i.vs[i.vs.length-1],u=c.vs[0],m=p=>Math.max(p,t)**2/za(i.vs,i.radius,p),f=p=>p>=u||c.vs.length<2?za(c.vs,c.ayMax,p):c.ayMax[0]+(c.ayMax[1]-c.ayMax[0])/(c.vs[1]-c.vs[0])*(p-u);return p=>{if(p<=l)return{ayMax:m(p),...s(i,p)};if(p>=u)return{ayMax:f(p),...s(c,p)};let d=m(p),h=f(p);return d<h?{ayMax:d,...s(i,p)}:{ayMax:h,...s(c,p)}}}function j2(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 gS(e,t,r,n,o){let a=r>t?Math.max(2,Math.min(5,Math.floor(n))):1,s=[];for(let f=0;f<a;f++)s.push(e(a===1?t:t+(r-t)*f/(a-1)));let i=bS(s,t),c=[],l=a,u=(f,p)=>{let d=.5*(f+p),h=e(d);l++;let b=j2(i(d),h);s.splice(s.findIndex(g=>g.v>d),0,h),i=bS(s,t),b>o&&c.push({lo:f,hi:d,misfit:b},{lo:d,hi:p,misfit:b})},m=s.map(f=>f.v);for(let f=0;f+1<m.length&&l<n;f++)m[f+1]-m[f]>=1&&u(m[f],m[f+1]);if(m.length>1){let f=.5*(m[0]+m[1]);if(s.some(p=>p.v===f))for(let[p,d]of[[m[0],f],[f,m[1]]]){if(l>=n||d-p<1)break;let h=c.findIndex(b=>b.lo===p&&b.hi===d);h>=0&&c.splice(h,1),u(p,d)}}for(;l<n&&c.length>0;){let f=0;for(let b=1;b<c.length;b++)c[b].misfit>c[f].misfit&&(f=b);let{lo:p,hi:d,misfit:h}=c.splice(f,1)[0];if(h<=o)break;d-p<1||u(p,d)}return{anchors:s,at:i}}var U2=2,X2=.5,Yi=Math.PI/180,yS=21,q2={nCoarse:11,nSteer:13,nNorm:41,nAngle:45},Q2={nCoarse:11,nSteer:13,nNorm:41,nAngle:61},Z2=.005,J2=.05,eg=e=>e<0?0:e>1?1:e;function e_(e,t,r,n){let o=e.massTotal,a=n.nSteer??7,s=(n.drivenFront?2:0)+(n.drivenRear?2:0),i=Te(e,0,0,r),c=Math.max(1,(i.FL+i.FR+i.RL+i.RR)/4),l=8*Yi,u=0,m=(b,g,y)=>{for(let R=b;R<=g;R+=y){let k=Math.abs(t.Fy(R*Yi,c,0));k>u&&(u=k,l=R*Yi)}};m(1,45,1),m(Math.max(.1,l/Yi-1),l/Yi+1,.1);let f=[],p=[],d=[],h=[];for(let b=0;b<a;b++){let g=b/(a-1),y=l*(g+Math.sin(Math.PI/2*g))/2,R=Math.abs(t.Fy(y,c,0));f.push(4*R/o),p.push(s*Lt(t,c,R,!1)/o),d.push(4*Lt(t,c,R,!0)/o),h.push(-4*R*Math.sin(y)/o)}return f[0]=0,{ayMax:4*u/o,ay:f,axAccel:p,axDecel:d,axScrub:h,rollover:!1}}function xr(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?Q2:q2),{nCoarse:c,nSteer:l,nAngle:u}=i,m=Kr(0,1,i.nNorm).map(B=>Math.sin(Math.PI/2*B)),f=e.params,p=f.m.value,d=f.rho.value,h=f.fr_0.value,b=f.driven_wheels.value,g=f.power_scale.value,y=e.FG,R=yt(f);s!==1&&(R.loadFactor=s);let k=yr(f),v=T1(0,n?.vRes??(e.engine?X2:U2),e.vMax);v[v.length-1]<e.vMax&&v.push(e.vMax);let x=e.fRad.map(B=>B*b),M=e.fAxle,{drivenFront:A,drivenRear:w}=fo(e),T=po(f,A,w),P=(B,V)=>{let G=M?bt(M.vVehicle,B,V):NaN;return Number.isFinite(G)?G:1/0},S=B=>{let V=B*B,{cl:G,cw:H,A:Y}=rm(f,B,0,R),J=.5*d*-H*Y*V,j=.5*d*-G*Y*V,ee=h*(-j+y);return J+ee},F=B=>{let V=S(B)/p*T.powerFactor,G=S(B)/p*T.tractionFactor,H;if(e.engine){let J=S(B);H=Ma(e.engine,B,T.effective,J,g).accel-V}else if(M){let J=0;A&&(J+=P(M.fFront,B)),w&&(J+=P(M.fRear,B)),H=g*J/p*T.powerFactor}else{let J=bt(e.vVehicle,x,B),j=g*J/p*T.powerFactor;H=Number.isFinite(j)?j:1/0}let Y=cm(f,B,o)/p*T.powerFactor;return{axDrag:V,axDragTyre:G,axDrive:H,axPackCap:Y,axPower:Math.min(H,Y)}},C=v.map(F),L=e.vMax;for(let B=1;B<v.length;B++){let V=C[B].axDrive+C[B].axDrag;if(V>0)continue;let G=C[B-1].axDrive+C[B-1].axDrag;L=G>0?v[B-1]+(v[B]-v[B-1])*G/(G-V):v[B-1];break}let E=Math.min(e.vMax,(1+J2)*L),D=r==="fast"?e_:xb,O=B=>{let V=D(R,k,B,{drivenFront:A,drivenRear:w,nSteer:l,yawDemandCn:a,axDrag:S(B)/p,...f.diffYaw?{diffYaw:!0}:{}}),G=V.ay[0],H=V.ay[V.ay.length-1],Y=ne=>Math.min(Math.max(ne*V.ayMax,G),H),J=m.map(ne=>fu(V.ay,V.axAccel,Y(ne))*T.tractionFactor),j=m.map(ne=>fu(V.ay,V.axDecel,Y(ne))),ee=m.map(ne=>fu(V.ay,V.axScrub,Y(ne))*T.tractionFactor);return{v:B,ayMax:V.ayMax,axAccelN:J,axDecelN:j,axScrubN:ee,atLock:V.atLock===!0}},_=r==="fast"?0:Math.min(Pu,E),z=gS(O,_,E,c,i.anchorTol??Z2),I=[],N=[];for(let B=0;B<v.length;B++){let V=v[B],{axDrag:G,axDragTyre:H,axDrive:Y,axPackCap:J,axPower:j}=C[B],{ayMax:ee,axAccelN:ne,axDecelN:de,axScrubN:W}=z.at(V);I.push({v:V,ayMax:ee,axTyreAcc:ne[0],axTyreDec:de[0],axDrive:Y,axPackCap:J,axPower:j,axDrag:G,axDragTyre:H,axAccelN:ne,axDecelN:de,axScrubN:W});let Z=[],re=[];for(let pe=0;pe<u;pe++){let ie=Math.PI*pe/(u-1),ae=ee*Math.cos(ie),ce=eg(Math.abs(Math.cos(ie)));Z.push({ax:Math.min(bt(m,ne,ce)+H,j+G)+bt(m,W,ce),ay:ae,v:V})}for(let pe=u-1;pe>=0;pe--){let ie=Math.PI*pe/(u-1),ae=ee*Math.cos(ie),ce=eg(Math.abs(Math.cos(ie)));re.push({ax:bt(m,de,ce)+G+bt(m,W,ce),ay:ae,v:V})}let me=(pe,ie,ae)=>Array.from({length:yS},(ce,_e)=>({ax:ie+(ae-ie)*(_e+1)/(yS+1),ay:pe,v:V}));N.push([...Z,...me(-ee,Z[Z.length-1].ax,re[0].ax),...re,...me(ee,re[re.length-1].ax,Z[0].ax)])}return{...RS(I,m),rows:I,norm:m,surf:N}}function Ya(e,t){return e?.length?t.map(r=>Rm(e,r)):t.map(()=>0)}function Rm(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 RS(e,t){let r=e[e.length-1].v,n=d=>{if(d<=e[0].v)return{i0:0,i1:0,t:0};if(d>=r)return{i0:e.length-1,i1:e.length-1,t:0};let h=0,b=e.length-1;for(;b-h>1;){let g=h+b>>1;e[g].v<=d?h=g:b=g}return{i0:h,i1:b,t:(d-e[h].v)/(e[b].v-e[h].v)}},o=d=>{let{i0:h,i1:b,t:g}=n(d);return{a:e[h],b:e[b],t:h===b?0:g}},a=(d,h,b)=>d===0||h===b?h:h+d*(b-h),s=(d,h,b,g)=>d===0?bt(t,h,g):a(d,bt(t,h,g),bt(t,b,g)),i=(d,h)=>h>=1?d.axPower:Math.min(h*d.axDrive,d.axPackCap),c=({a:d,b:h,t:b},g,y)=>d.axScrubN?y*s(b,d.axScrubN,h.axScrubN,g):0,l=d=>d.axDragTyre??d.axDrag,u=({a:d,b:h,t:b},g,y)=>{let R=y*a(b,d.ayMax,h.ayMax);return R>0?eg(g/R):1},m=(d,h,b=1,g=1)=>{let{a:y,b:R,t:k}=d,v=u(d,h,b),x=b*s(k,y.axAccelN,R.axAccelN,v)+a(k,l(y),l(R)),M=a(k,i(y,g),k===0?0:i(R,g))+a(k,y.axDrag,R.axDrag);return Math.min(x,M)+c(d,v,b)},f=(d,h,b=1,g=1)=>{let{a:y,b:R,t:k}=d,v=u(d,h,b),x=s(k,y.axDecelN,R.axDecelN,v);return(g===1||x>0?b*x:g*b*x)+a(k,y.axDrag,R.axDrag)+c(d,v,b)},p=({a:d,b:h,t:b},g,y=1)=>{let R=t.length-1,k=d.axAccelN,v=h.axAccelN,x=d.axDecelN,M=h.axDecelN,A=d.axScrubN,w=h.axScrubN,T=D=>k[D]+b*(v[D]-k[D]),P=D=>x[D]+b*(M[D]-x[D]),S=D=>A?y*(A[D]+b*(w[D]-A[D])):0,F=a(b,d.ayMax,h.ayMax),C=a(b,d.axDrag,h.axDrag),L=a(b,l(d),l(h)),E=a(b,d.axPower,h.axPower);for(let D=R;D>=0;D--){let O=Math.min(y*T(D)+L,E+C)+S(D),_=y*P(D)+C+S(D);if(!(g<=O+1e-6&&g>=_-1e-6))continue;if(D===R)return t[D]*y*F;let z=(V,G,H)=>{if(H(G))return 1;let Y=(V-g)/(V-G);return Y>0?Math.min(Y,1):0},I=V=>g<=V+1e-6,N=V=>g>=V-1e-6,B=Math.min(z(y*T(D)+L+S(D),y*T(D+1)+L+S(D+1),I),z(E+C+S(D),E+C+S(D+1),I),z(y*P(D)+C+S(D),y*P(D+1)+C+S(D+1),N));return(t[D]+B*(t[D+1]-t[D]))*y*F}return 0};return{vMax:r,axAccel:(d,h,b=1,g=1)=>m(o(d),h,b,g),axDecel:(d,h,b=1,g=1)=>f(o(d),h,b,g),ay:(d,h,b=1)=>p(o(d),h,b),scrub:(d,h,b=1)=>{let g=o(d);return c(g,u(g,h,b),b)}}}function t_(e,t,r){let n=e.params,o=n.m.value,{drivenFront:a,drivenRear:s}=fo(e),i=po(n,a,s);return c=>cm(n,c,t,r)/o*i.powerFactor}function Wi(e,t,r,n){let o=t_(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{...RS(a,e.norm),rows:a,norm:e.norm}}var r_=[-.2,-.08,0,.06,.12,.2,.3];function vS(e,t=!1,r="twoTrack",n,o,a=r_){let s=[...new Set([...a,0])].sort((d,h)=>d-h),i=s.map(d=>xr(e,t,r,n,o,d)),c=i[s.indexOf(0)],l=s[0],u=s[s.length-1],m=d=>{if(d<=l)return{i:0,t:0};if(d>=u)return{i:s.length-1,t:0};let h=0;for(;h<s.length-2&&s[h+1]<=d;)h++;return{i:h,t:(d-s[h])/(s[h+1]-s[h])}},f=d=>{let h=b=>{let{i:g,t:y}=m(b);return{a:d[g],b:d[Math.min(d.length-1,g+1)],t:y}};return b=>{let{a:g,b:y,t:R}=h(b);if(R===0)return g;let k=(v,x)=>v+R*(x-v);return{vMax:g.vMax,axAccel:(v,x,M=1,A=1)=>k(g.axAccel(v,x,M,A),y.axAccel(v,x,M,A)),axDecel:(v,x,M=1,A=1)=>k(g.axDecel(v,x,M,A),y.axDecel(v,x,M,A)),ay:(v,x,M=1)=>k(g.ay(v,x,M),y.ay(v,x,M)),scrub:(v,x,M=1)=>k(g.scrub?.(v,x,M)??0,y.scrub?.(v,x,M)??0)}}},p=d=>d<l||d>u;return{anchors:s,steady:c,clamps:p,at:f(i),atSoc(d,h,b){let g=i.map(y=>Wi(y,d,h,b));return{anchors:s,steady:g[s.indexOf(0)],clamps:p,at:f(g)}}}}function kS(e,t,r,n="twoTrack",o){let a=[...new Set([...t,1])].sort((i,c)=>i-c),s=a.map(i=>i===1?r:xr(e,!1,n,o,void 0,0,i));return{...xS(a,s),atSoc:(i,c,l)=>xS(a,s.map(u=>Wi(u,i,c,l)))}}function xS(e,t){let r=e.length-1,n=1,o=0,a=0,s=0,i=1,c=0,l=0,u=p=>{if(n=1,!(p>e[0]))return void(o=0);if(p>=e[r])return void(o=r);let d=0;for(;d<r-1&&e[d+1]<=p;)d++;if(o=d,p===e[d])return;a=d+1;let h=e[d],b=e[d+1];if(r<2){n=2,c=(p-h)/(b-h),i=1-c;return}s=d===0?2:d+1===r||p-e[d-1]<e[d+2]-p?d-1:d+2;let g=e[s];n=3,i=(p-b)*(p-g)/((h-b)*(h-g)),c=(p-h)*(p-g)/((b-h)*(b-g)),l=(p-h)*(p-b)/((g-h)*(g-b))},m=p=>{let d=p(t[o]);if(n===1)return d;let h=p(t[a]);if(n===2)return i*d+c*h;let b=i*d+c*h+l*p(t[s]);return Math.min(Math.max(d,h),Math.max(Math.min(d,h),b))},f=(p,d,h,b,g)=>{if(u(p),n===1||h===0)return m(k=>g(k,h));let y=m(k=>k.ay(d,0,b));if(!(y>0))return m(k=>g(k,h));let R=h/y;return m(k=>g(k,R*k.ay(d,0,b)))};return{anchors:e,axAccel:(p,d,h,b=1,g=1)=>f(p,d,h,b,(y,R)=>y.axAccel(d,R,b,g)),axDecel:(p,d,h,b=1,g=1)=>{let y=R=>f(p,d,h,b,(k,v)=>k.axDecel(d,v,b,R));return g===1?y(1):Nb(y(g),y(1),g)},scrub:(p,d,h,b=1)=>f(p,d,h,b,(g,y)=>g.scrub?.(d,y,b)??0),ay:(p,d,h,b=1)=>{if(u(p),n===1||h===0)return m(k=>k.ay(d,h,b));let g=k=>h>0?k.axAccel(d,0,b):-k.axDecel(d,0,b),y=m(g);if(!(y>0))return m(k=>k.ay(d,h,b));let R=h/y;return m(k=>k.ay(d,R*g(k),b))}}}var MS=new WeakMap;function tg(e,t){let r=MS.get(e);if(!r){let n=Gr(e).regen?Kb(t??Et(e)):void 0;r={inp:yt(e),ev:yr(e),...n?{regen:n}:{}},MS.set(e,r)}return r}function rg(e,t,r){let n=tg(e,r);return Jb(n.inp,n.ev,t,n.regen?{regen:n.regen}:{})}function ng(e){let t=gt(e);if(t.mode!=="hydraulic")return null;let r=a=>a.heat?{heat:yh(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 n_(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 og(e,t,r,n,o,a=Dt){if(!e)return null;let s=n_(t);return{...e.front?{front:lu(e.front.heat,e.front.discs,s.front,r,n,o.front,a)}:{},...e.rear?{rear:lu(e.rear.heat,e.rear.discs,s.rear,r,n,o.rear,a)}:{}}}var o_=.5,a_=.02,s_=6,vm=9,SS=1e-9,i_={FL:0,FR:0,RL:0,RR:0};function ag(e){return e?[...new Set([...e.padCurve.factor,1])].sort((t,r)=>t-r):[1]}function c_(e,t,r){let n=fr(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 AS(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 FS(e,t,r,n,o=()=>0){let a=Array.from({length:vm},(m,f)=>r*f/(vm-1)),s=yi(),{front:i,rear:c}=n,l=a.map(m=>{let f=o(m),p=h=>zr(h,t,m,s).limitAt(0,0,i_,f).ax,d=p(e);return i.map(h=>c.map(b=>{if(h===1&&b===1)return 1;let g=d<0?p(c_(e,h,b))/d:1;return Math.abs(g-1)<SS?1:g}))}),u=a[1]-a[0];return{share(m,f,p){if(f===1&&p===1)return 1;let d=u>0?Math.min(vm-2,Math.max(0,Math.floor(m/u))):0,h=u>0?Math.min(1,Math.max(0,(m-a[d])/u)):0,b=AS(i,f),g=AS(c,p),y=k=>{let v=l[k],x=Math.min(i.length-1,b.i+1),M=Math.min(c.length-1,g.i+1),A=v[b.i][g.i]+g.t*(v[b.i][M]-v[b.i][g.i]),w=v[x][g.i]+g.t*(v[x][M]-v[x][g.i]);return A+b.t*(w-A)},R=y(d)+h*(y(Math.min(vm-1,d+1))-y(d));return Math.abs(R-1)<SS?1:R}}}function l_(e,t){let{front:r,rear:n}=t;return(o,a)=>e.share(a,r?.[o]??1,n?.[o]??1)}var u_=e=>(e.front??[]).every(t=>t===1)&&(e.rear??[]).every(t=>t===1);function wS(e,t,r){let n=e(),o=1,a=t(n);if(u_(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<s_;c++){let l=e(l_(r,s));o++;let u=Math.abs(l.laptime-n.laptime);if(n=l,u<a_){i=!0;break}a=t(n);let m=(d,h)=>d&&h?d.map((b,g)=>b+o_*((h[g]??1)-b)):d,f=m(s.front,a.front),p=m(s.rear,a.rear);s={...f?{front:f}:{},...p?{rear:p}:{}}}return{lap:n,pads:s,solves:o,converged:i}}function Fn(e,t){let r=e.engine;if(!r||r.gears.length===0||t.length===0)return;let n=e.params,{drivenFront:o,drivenRear:a}=fo(e),s=po(n,o,a).effective,i=n.power_scale.value,{up:c,down:l}=Eh(r.engine.gearbox),u=r.engine.idleRpm,m=(f,p,d)=>(i*r.force(f,p)+d)/(s+r.inertiaMass(f,p));return{count:r.gears.length,up:c,down:l,kept:Ih(r.engine.gearbox),limitRpm:r.engine.limitRpm,best:f=>Ma(r,f,s,Rm(t,f)*s,i).gear,share:(f,p)=>{let d=Rm(t,f),h=d*s,b=Ma(r,f,s,h,i);if(p===b.gear)return 1;let g=b.accel-d;return g>0?Math.min(1,Math.max(0,(m(f,p,h)-d)/g)):0},rpm:(f,p)=>r.slipping(f,p)?u:r.rpm(f,p),vIdle:f=>r.gears[f]?.vIdle??0}}var CS=new WeakMap;function ig(e){let t=CS.get(e.ggv);return t===void 0&&(t=Fn(e.vehicle,e.ggv.rows)??null,CS.set(e.ggv,t)),t??void 0}function m_(e){return e.gear&&e.engineRpm&&e.shifting?{gear:e.gear,rpm:e.engineRpm,shifting:e.shifting}:{}}function p_(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}:{},...m_(t)}}var Mm=class extends Error{constructor(t){super(t),this.name="EventError"}};function d_(e,t){let{ggv:r}=t,n=ct(t.numerics),o=n.accelStep,a=Math.max(1,Math.round(e.distance/o)),s=Oa(r,new Array(a+1).fill(0),n);s[0].v=e.vStart??0;for(let d=0;d<s.length-1;d++){let h=s[d],b=s[d+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=ig(t),c=i?am(s.map(d=>d.v),new Array(a).fill(o),!1,i,(d,h,b)=>r.axAccel(h,0,1,b)):void 0;if(c){for(let d=0;d<=a;d++)s[d].v=c.v[d];for(let d=0;d<a;d++)s[d].ax=(s[d+1].v*s[d+1].v-s[d].v*s[d].v)/(2*o)}let l=0;for(let d=0;d<a;d++){let h=s[d].v+s[d+1].v;h>0&&(l+=2*o/h)}let u=s.slice(0,a).map(d=>d.v),m=s.slice(0,a).map(d=>d.ax),f=new Array(a).fill(o),p=f.map((d,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:p,x:p,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:OS(t,f,[...u,s[a].v],m,1)}}function f_(e,t){let r=Math.max(1,Math.round(e.laps??1)),[n]=Oa(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=OS(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 Sm(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 h_(e,t){let r=e.distance!=null?t.v_limit_endurance?.value??0:0;return r>0?r/3.6:void 0}function b_(e,t){if(e.distance==null||dt(t.motorModel))return 0;let r=t.endurance_reserve?.value??0;return r>0?Math.min(r,95)/100:0}var TS=1;function IS(e,t,r,n){return{v:r.v,ax:r.ax,ay:r.ay,ds:t.ds,axDrag:Ya(e.ggv.rows,r.v),...r.axScrub?{axScrub:r.axScrub}:{},axGrade:n,...t.bank?{bank:t.bank}:{}}}var PS=new WeakMap;function _S(e){let t=e.vehicle.params;if(!t.brakeFade)return null;let r=PS.get(t);if(r===void 0){let n=ng(t),o=n?gt(t):null;if(!n||!o||o.mode!=="hydraulic")r=null;else{let a=tg(t,e.vehicle),s=e.ggv.rows,i=FS(a.inp,a.ev,e.vehicle.vMax,{front:ag(o.hydraulic.front.heat),rear:ag(o.hydraulic.rear.heat)},c=>Ya(s,[c])[0]);r={discs:n,table:i}}PS.set(t,r)}return r}function g_(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=ig(e),u=(g,y)=>e.yaw?fS(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}:{}}):At(Wi(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=An(t.gradient,t.npts),f=g=>n.motorThermal?NM(e.vehicle,t.ds,e.energyOpts??$r,y=>u(y,g),o,a,m,t.bank).lap:u(void 0,g),p=_S(e);if(!p)return f();let d=Ki(n),h=r.discC??{front:d,rear:d};return wS(f,g=>{let y=og(p.discs,rg(n,IS(e,t,g,m),e.vehicle),g.v,t.ds,h,d);return{...y?.front?{front:y.front.padFactor}:{},...y?.rear?{rear:y.rear.padFactor}:{}}},p.table).lap}function y_(e,t){let r=h_(e,t.vehicle.params),n=b_(e,t.vehicle.params);return n>0?v_(e,t,n,r):ji(e,t,r)}function km(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 LS=5,x_=.1,R_=.005,DS=12;function v_(e,t,r,n){let o=ji(e,t,n),a=1,s=(d,h,b)=>({...d,energyTarget:{reserve:r,capKmh:h===void 0?null:h*3.6,met:b,solves:a}}),i=km(o,r);if(i>=0)return s(o,n,!0);let c=Math.min(n??1/0,t.ggv.vMax),l=c/2,u=ji(e,t,l);a++;let m=km(u,r);for(;m<0&&l>LS&&a<DS;)c=l,i=m,l=Math.max(LS,l/2),u=ji(e,t,l),a++,m=km(u,r);if(m<0)return s(u,l,!1);let f=l,p=0;for(;a<DS&&c-l>x_&&m>R_;){let d=c-l,h=Math.min(c-.05*d,Math.max(l+.05*d,l+m*d/(m-i))),b=ji(e,t,h);a++;let g=km(b,r);g>=0?(l=h,m=g,u=b,f=h,p===1&&(i/=2),p=1):(c=h,i=g,p===-1&&(m/=2),p=-1)}return s(u,f,!0)}function NS(e,t,r){return r===0?e:e&&!t}function ji(e,t,r){let n=t.track;if(!n)throw new Mm(`Event "${e.id}" needs a track.`);let o=Sm(e,n),a=e.standingStart??t.standingStart??!1,s=H=>NS(a,n.closed,H),i=t.vehicle.params,c=wr(Va(i)),l=c.capacityAh,u=i.soc.value,m=Ki(i),f=im(c,m),p=0,d=0,h=0,b=0,g=[],y=!1,R=-1/0,k=0,v=0,x=!1,M=-1/0,A=0,w=0,T=-1/0,P=(H,Y,J=1)=>{H.tempMaxC>T&&(T=H.tempMaxC),H.motorTempMaxC!==void 0&&(y=!0,x=!0,H.motorTempMaxC>R&&(R=H.motorTempMaxC),H.motorTempMaxC>M&&(M=H.motorTempMaxC),k+=(H.motorDerateTimeFrac??0)*Y,A+=(H.motorDerateTimeFrac??0)*Y,v+=(H.motorLossKwh??0)/J,w+=(H.motorLossKwh??0)/J)},S=null,F,C=ng(i),L={front:m,rear:m},E=null,D=_S(t)!==null,O=(H,Y)=>D&&(Math.abs(H.front-Y.front)>TS||Math.abs(H.rear-Y.rear)>TS),_=(H,Y,J)=>{let j=Hb(i,H,Y);if(E&&E.launch===J&&!S_(j,E.pw)&&!O(L,E.discC))return E.lap;let ee=g_(t,n,{soc:H,packTempC:Y,launched:J,...r?{vCeiling:r}:{},...D?{discC:L}:{}});return E={pw:j,launch:J,discC:L,lap:ee},ee},z=An(n.gradient,n.npts),I=(H,Y,J)=>Ba(t.vehicle,n.ds,H.v,H.ax,t.energyOpts,Y,J,void 0,z,void 0,{ay:H.ay,bank:n.bank,...H.axScrub?{scrub:H.axScrub}:{}}),N=new WeakMap,B=(H,Y)=>{let J=N.get(H);return J||(J=rg(i,IS(t,n,H,z),t.vehicle),N.set(H,J)),og(C,J,H.v,n.ds,Y,m)},V=(H,Y,J)=>{let j=`${(100*J/n.npts).toFixed(0)} % of the way through lap ${H+1}`,ee=Y.cutoffAt>=0&&Y.cutoffAt<=Y.emptyAt;return{lapsCompleted:H,lapsAsked:o,why:ee?`the pack reached its ${c.voltageFloor.toFixed(0)} V cut-off ${j}`:`the pack ran out ${j}`}};for(let H=0;H<o;H++){if(u<=0){F={lapsCompleted:H,lapsAsked:o,why:"the pack was empty"};break}let Y=s(H),J=u,j=f;x=!1,M=-1/0,A=0,w=0,T=-1/0;let ee=_(u,f,Y),ne=I(ee,u,f);if(ne.emptyAt>=0){F=V(H,ne,ne.emptyAt);break}let W=_(ne.socEnd,ne.tempEndC,Y).laptime-ee.laptime,Z,re,me,pe,ie=f,ae=-1,ce=null,_e=1;if(W<=sg)Z=ee.laptime,re=ne.net,me=ne.loss,pe=ne.chargeAh,ie=ne.tempEndC,P(ne,Z),_e=1;else{let Re=Math.min(k_,Math.max(2,Math.ceil(W/(2*sg))));_e=Re;let ue=u,we=f;Z=0,re=0,me=0,pe=0;for(let Ke=0;Ke<Re;Ke++){let tt=_(ue,we,Y),xe=I(tt,ue,we),ve=xe.emptyAt>=0?xe.emptyAt/n.npts:1;if(ve*Re<1){ae=Math.round(n.npts*(Ke/Re+ve)),ce=xe;break}if(Z+=tt.laptime/Re,P(xe,tt.laptime/Re,Re),re+=xe.net/Re/ve,me+=xe.loss/Re/ve,pe+=xe.chargeAh/Re/ve,ue-=xe.chargeAh/Re/ve/l,we+=(xe.tempEndC-we)/Re,ue<=0){ae=Math.round(n.npts*(Ke+1)/Re),ce=xe;break}}if(ie=we,ae>=0&&ce){F=V(H,ce,ae);break}u=ue}p+=Z,d+=re,h+=me,b+=pe,W<=sg&&(u=ne.socEnd),f=ie;let Fe=C?B(ee,L):null;Fe&&(L={front:Fe.front?.endC??L.front,rear:Fe.rear?.endC??L.rear}),g.push({lap:H+1,time:Z,elapsed:p,entryTime:ee.laptime,socStart:J,socEnd:u,packTempStartC:j,packTempEndC:f,packTempMaxC:Number.isFinite(T)?T:j,energyKwh:re,lossKwh:me,chargeAh:pe,launched:Y,substeps:_e,...r?{vCeiling:r}:{},...x?{motor:{peakWindingC:M,derateTimeFrac:Z>0?A/Z:0,lossKwh:w}}:{},...Fe?{brakes:{...Fe.front?{front:ES(Fe.front)}:{},...Fe.rear?{rear:ES(Fe.rear)}:{}}}:{}}),S=ee}if(!S){let H=ig(t);S=At(Wi(t.ggv,t.vehicle,u),n,t.numerics,{standingStart:a,...t.load?{load:t.load.atSoc(t.vehicle,u)}:{},...H?{shifts:H}:{}}),F=F??{lapsCompleted:0,lapsAsked:o,why:"the pack was empty"}}let G=g.length;return{id:e.id,label:e.label,kind:e.kind,time:p,distance:n.length*G,laps:G,lapTime:S.laptime,trace:p_(n,S),energy:{consumed:d,loss:h,...dt(i.motorModel)?{}:{native:{value:b,unit:"Ah"}},remainingFraction:dt(i.motorModel)?1:u,...y?{motor:{peakWindingC:R,derateTimeFrac:p>0?k/p:0,lossKwh:v}}:{}},lapLog:g,...F?{incomplete:F}:{}}}var sg=.05;function ES(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 k_=4,M_=.001;function S_(e,t){return e===t?!1:!Number.isFinite(e)||!Number.isFinite(t)?!0:Math.abs(e-t)>M_*Math.max(1,Math.abs(t))}function OS(e,t,r,n,o,a){return A_(e,t,o,()=>({v:r,ax:n,...a?{lateral:a}:{}}))}function A_(e,t,r,n){let o=e.energyOpts,a=e.vehicle.params.soc.value,s=0,i=0,c=0;for(let l=0;l<r;l++){let u=n(l),m=Ba(e.vehicle,t,u.v,u.ax,o,a,void 0,void 0,void 0,void 0,u.lateral);s+=m.net,i+=m.loss,c+=m.chargeAh,a=m.socEnd}return dt(e.vehicle.params.motorModel)?{consumed:s,loss:i,remainingFraction:1}:{consumed:s,loss:i,native:{value:c,unit:"Ah"},remainingFraction:a}}function VS(e,t){switch(e.kind){case"straightLineAccel":return d_(e,t);case"constantRadius":return f_(e,t);case"trackLap":return y_(e,t)}}function cg(e,t){let r={};for(let n of e)r[n.id]=VS(n,t);return r}function BS(e,t){if(e.kind!=="trackLap")return e;let{distance:r,...n}=e;return{...n,laps:Math.max(1,Math.round(t))}}function ho(e,t,r,n,o="twoTrack",a){let s=1/0,i=-1/0;for(let f of r){let p=Bi(f);if(!p)continue;let d=kM(p,At(t,f,n).v);d&&(s=Math.min(s,d.lo),i=Math.max(i,d.hi))}if(!(i>=s))return;let c=MM({lo:s,hi:i}),l=c.join(","),u=a?.get(l);if(u)return u;let m=kS(e,c,t,o);return a?.set(l,m),m}var Ui=e=>e.distance/Math.max(1,e.laps);function Xi(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 F_=e=>e.v.map(t=>t*3.6),w_=e=>e.ax.map(t=>t/9.81),C_=e=>e.ay.map(t=>t/9.81),T_=e=>e.ay.map((t,r)=>e.v[r]>1e-6?t/(e.v[r]*e.v[r]):0),Am=(e,t,r)=>e?.slice()??new Array(t.s.length).fill(r),P_=e=>Am(e.z,e,0),L_=e=>e.gradient?e.gradient.map(t=>100*Math.tan(t*Math.PI/180)):Am(void 0,e,0),D_=e=>Am(e.bank,e,0),E_=e=>Am(e.mu,e,1);function I_(e){let t=e.s.length,r=Xi(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 lg=[{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 $S(e){let t=Xi(e);return{ds:t,vars:{s:e.s,ds:t,t:I_(e),v:e.v,speed:F_(e),ax:e.ax,ay:e.ay,axg:w_(e),ayg:C_(e),curv:T_(e),z:P_(e),grade:L_(e),bank:D_(e),grip:E_(e)}}}function GS(e,t){return{v:e.v,ax:e.ax,ay:e.ay,ds:Xi({s:e.s,length:t}),axGrade:An(e.gradient,e.v.length),...e.bank?{bank:e.bank}:{},...e.loadFactor?{loadFactor:e.loadFactor}:{}}}function KS(e,t){let r=yt(e);return{pastTurnover:iS(r,yr(e),t),...e.aeroModel?{aeroOutside:sS(r,t)}:{}}}var Fm="Flying lap";function ug(e,t){return e.kind!=="trackLap"||e.label!==Fm?e.label:e.standingStart??t?"Run":e.label}function __(e){let t=yt(e);return{yawInertia:t.yawInertia??0,massTotal:t.massTotal,wheelbase:t.wheelbase/1e3}}function N_(e,t,r){let n=e.params,o=n.ggvMode??"twoTrack",a=n.quasiTransient?vS(e,!1,o):null,s=a?a.steady:xr(e,!1,o),i=t?ho(e,s,[t],r,o):void 0;return{ggv:s,...a?{yaw:{family:a,car:__(n)}}:{},...i?{load:i}:{}}}function O_(e,t){let r=t.lapCounts,n=t.standingStart??!1,o=!1,a=e.events.map(s=>{let i=r?.[s.id]!=null?BS(s,r[s.id]):s,c=ug(i,n),l=c===i.label?i:{...i,label:c};return l!==s&&(o=!0),l});return o?a:e.events}function V_(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=Sm(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 B_(e,t){for(let[r,n]of Object.entries(e))n.trace&&(e[r]={...n,...KS(t,GS(n.trace,Ui(n)))})}function qi(e,t,r={}){let n=Et(e),o=N_(n,r.track,r.numerics),{ggv:a}=o,s=cg(O_(t,r),{vehicle:n,...o,track:r.track,energyOpts:Gr(e,r.energyOpts),numerics:r.numerics,standingStart:r.standingStart});return V_(s,t,r),B_(s,n.params),{name:e.name,rulesetId:t.id,events:s,ggv:a}}function mg(e){return{...e,ggv:{rows:e.ggv.rows,vMax:e.ggv.vMax,surf:e.ggv.surf}}}var pg=["<","<=",">",">=","==","!="],Be=class extends Error{at;constructor(t,r){super(t),this.name="ExprError",this.at=r}},Qi=e=>e>="0"&&e<="9",HS=e=>/[A-Za-z_]/.test(e),$_=e=>/[A-Za-z0-9_]/.test(e);function G_(e){let t=[],r=0;for(;r<e.length;){let n=e[r];if(n===" "||n===" "||n===`
224
- `||n==="\r"){r++;continue}if(Qi(n)||n==="."&&Qi(e[r+1]??"")){let o=r;for(;r<e.length&&(Qi(e[r])||e[r]===".");)r++;if(e[r]==="e"||e[r]==="E"){let i=r;if(r++,(e[r]==="+"||e[r]==="-")&&r++,Qi(e[r]??""))for(;r<e.length&&Qi(e[r]);)r++;else r=i}let a=e.slice(o,r),s=Number(a);if(!Number.isFinite(s))throw new Be(`"${a}" is not a number`,o);t.push({t:"num",value:s,at:o});continue}if(HS(n)){let o=r;for(;;){for(;r<e.length&&$_(e[r]);)r++;if(e[r]==="."&&HS(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(pg.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 Be(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 Be(`"${n}" is not something this expression can contain`,r)}return t.push({t:"end",at:e.length}),t}function dg(e){let t=G_(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 Be(`Expected ${b} here`,n().at)};function i(){let h=c(),b=n();if(b.t!=="op"||!pg.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"&&pg.includes(y.value))throw new Be("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=f(),b=n().at;return a("^")?{kind:"binary",op:"^",left:h,right:u(),at:b}:h}function f(){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 Be("The expression ends before it is finished",h.at):new Be(`"${h.value}" cannot start a value`,h.at)}let p=i(),d=n();if(d.t!=="end")throw new Be(`"${d.value}" is left over \u2014 check for a missing operator`,d.at);return p}function fg(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 Zi=(e,t)=>typeof e=="number"?new Array(t).fill(e):e;function K_(e){let t=1;for(let r of e)Array.isArray(r)&&(t=Math.max(t,r.length));return t}function Nt(e,t){if(e.every(a=>typeof a=="number"))return t(...e);let r=K_(e),n=e.map(a=>Zi(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 $e=(e,t)=>({arity:e,call:r=>Nt(r,t)}),bo=e=>e!==0&&!Number.isNaN(e),Rr=e=>e?1:0;function zS(e,t,r){let n=YS(t,r,"integrate"),o=n.length,a=Zi(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 YS(e,t,r){if(!e.ds||e.ds.length===0)throw new Be(`${r}() needs to know the sample spacing, and this context has none`,t);return e.ds}var wm={abs:$e(1,Math.abs),sqrt:$e(1,Math.sqrt),sign:$e(1,Math.sign),floor:$e(1,Math.floor),ceil:$e(1,Math.ceil),round:$e(1,Math.round),exp:$e(1,Math.exp),log:$e(1,Math.log),sin:$e(1,Math.sin),cos:$e(1,Math.cos),tan:$e(1,Math.tan),atan:$e(1,Math.atan),atan2:$e(2,Math.atan2),hypot:$e(2,Math.hypot),min:$e(2,Math.min),max:$e(2,Math.max),clamp:$e(3,(e,t,r)=>Math.min(r,Math.max(t,e))),if:$e(3,(e,t,r)=>bo(e)?t:r),and:$e(2,(e,t)=>Rr(bo(e)&&bo(t))),or:$e(2,(e,t)=>Rr(bo(e)||bo(t))),not:$e(1,e=>Rr(!bo(e))),finite:$e(1,e=>Rr(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=zS(e,t,0),n=t.ds,o=Zi(e,n.length),a=n.length-1;return r[a]+(o[a]+o[0])/2*n[a]}},integrate:{arity:1,call:([e],t)=>zS(e,t,0)},cum:{arity:1,call:([e],t)=>{let r=t.ds?.length??(Array.isArray(e)?e.length:1),n=Zi(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=YS(t,0,"deriv"),n=r.length,o=Zi(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}}},Wa={g:9.81,pi:Math.PI,e:Math.E,nan:NaN,inf:1/0},Ji={fleetmin:"min",fleetmax:"max"};function go(e){switch(e.kind){case"call":return Object.hasOwn(Ji,e.name)||e.args.some(go);case"unary":return go(e.arg);case"binary":return go(e.left)||go(e.right);default:return!1}}var H_=e=>typeof e=="number"?`${e}`:`between ${e[0]} and ${e[1]}`;function z_(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 Y_(e,t){let r=t.map(c=>({k:c,d:z_(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 vr(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(Wa,e.name))return Wa[e.name];let r=[...Object.keys(t.vars),...Object.keys(Wa)].sort();throw new Be(Y_(e.name,r),e.at)}case"unary":return Nt([vr(e.arg,t)],r=>-r);case"binary":{let r=vr(e.left,t),n=vr(e.right,t);switch(e.op){case"+":return Nt([r,n],(o,a)=>o+a);case"-":return Nt([r,n],(o,a)=>o-a);case"*":return Nt([r,n],(o,a)=>o*a);case"/":return Nt([r,n],(o,a)=>a===0?0:o/a);case"^":return Nt([r,n],(o,a)=>o**a);case"<":return Nt([r,n],(o,a)=>Rr(o<a));case"<=":return Nt([r,n],(o,a)=>Rr(o<=a));case">":return Nt([r,n],(o,a)=>Rr(o>a));case">=":return Nt([r,n],(o,a)=>Rr(o>=a));case"==":return Nt([r,n],(o,a)=>Rr(o===a));case"!=":return Nt([r,n],(o,a)=>Rr(o!==a))}break}case"call":{let r=Object.hasOwn(Ji,e.name)?Ji[e.name]:void 0;if(r){if(!t.fleet)throw new Be(`${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 Be(`${e.name}() takes 1 argument, not ${e.args.length}`,e.at);return t.fleet(e.args[0],r,e.at)}let n=Object.hasOwn(wm,e.name)?wm[e.name]:void 0;if(!n){let s=[...Object.keys(wm),...t.fleet?Object.keys(Ji):[]];throw new Be(`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 Be(`${e.name}() takes ${H_(n.arity)} argument${o===1&&a===1?"":"s"}, not ${e.args.length}`,e.at);return n.call(e.args.map(s=>vr(s,t)),t)}}throw new Be("Unreachable node",0)}var ja=e=>Number.isFinite(e)?e:NaN,hg=[{name:"time",unit:"s",what:"the whole event, every lap",read:e=>ja(e?.time)},{name:"lapTime",unit:"s",what:"one lap \u2014 the last one completed",read:e=>ja(e?.lapTime)},{name:"distance",unit:"m",what:"distance covered",read:e=>ja(e?.distance)},{name:"laps",unit:"-",what:"laps completed",read:e=>ja(e?.laps)},{name:"energy",unit:"kWh",what:"energy drawn over the event",read:e=>ja(e?.energy?.consumed)},{name:"remaining",unit:"-",what:"share of the pack or tank left afterwards",read:e=>ja(e?.energy?.remainingFraction)},{name:"finished",unit:"-",what:"1 when the car ran the whole event, else 0",read:e=>e&&!e.incomplete?1:0}],WS=/^[A-Za-z_][A-Za-z0-9_]*$/,W_=new Set([...Object.keys(Wa),...lg.map(e=>e.name)]);function Cm(e,t,r=[]){let n=[],o=new Set(r),a=t.map(b=>b.id),s=new Set;for(let b of a)WS.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(!WS.test(b.key)){n.push({key:b.key,message:`"${b.key}" must be one word \u2014 letters, digits and _`});continue}if(W_.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,dg(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,[...fg(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=j_(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 f=(b,g,y)=>{throw new Be("fleetmin() and fleetmax() cannot sit inside one another",y)},p=new Set,d={};for(let b of a)for(let g of hg)d[`${b}.${g.name}`]=1;for(let b of o)d[b]=1;for(let b of i.keys())d[b]=1;let h={};for(let b of lg)h[b.name]=[1,1];for(let b of m){let g=i.get(b),y=c.get(b);(go(y)||l.get(b).some(x=>p.has(x)))&&p.add(b);let R=g.over!=null?{...d,...h}:d,k=g.over!=null?[1,1]:void 0,v=(x,M,A)=>{let w=vr(x,{vars:R,ds:k,fleet:f});if(Array.isArray(w))throw new Be("fleetmin() and fleetmax() compare one number per car \u2014 reduce the channel first, e.g. peak(v)",A);return w};try{let x=vr(y,{vars:R,ds:k,fleet:v});Array.isArray(x)&&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(x){let M=x;n.push({key:b,message:M.message,at:M.at})}}return n.length?{plan:null,problems:n}:{plan:{order:m.map(b=>({def:i.get(b),node:c.get(b)})),field:p,eventIds:a},problems:n}}function j_(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 U_(e,t,r={}){let n={...r};for(let o of e.eventIds){let a=t.events[o];for(let s of hg)n[`${o}.${s.name}`]=s.read(a)}return{vars:n,laps:new Map,events:t.events}}function jS(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?$S({...n.trace,length:Ui(n)}):null,e.laps.set(t.over,r)}return r?{vars:{...e.vars,...r.vars},ds:r.ds}:null}var US=e=>Array.isArray(e)?NaN:e;function XS(e,t,r,n={}){let o=Object.keys(t),a=o.map(i=>U_(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 f of a)f.vars[i.key]=NaN;continue}let u=new Map,m=(f,p)=>{let d=u.get(f);if(d!==void 0)return d;let h=NaN;for(let b of a){let g=jS(b,i);if(!g)continue;let y=US(vr(f,g));Number.isFinite(y)&&(Number.isNaN(h)||(p==="min"?y<h:y>h))&&(h=y)}return u.set(f,h),h};for(let f of a){let p=jS(f,i);f.vars[i.key]=p?US(vr(c,l?{...p,fleet:m}:p)):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 ec(e,t,r){return XS(e,t,!0,r)}function bg(e,t,r){return XS(e,{car:t},!1,r?{car:r}:void 0).car}var Tm=class extends Error{problems;constructor(t,r){super(`Ruleset "${t}" does not compile:
223
+ `}function _r(e){let t=ri(Xv(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 qv={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},Qv={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},Zv={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},Jv={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},e1={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},t1={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},r1={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},n1={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},Zf=()=>_r(qv),Jf=()=>_r(Qv),eh=()=>_r(Zv),th=()=>_r(Jv),rh=()=>_r(e1),nh=()=>_r(t1),oh=()=>_r(r1),ah=()=>_r(n1);var o1=e=>Number.isFinite(e)&&e>0;function au(e,t){let r=o1(t.grip)?t.grip:1,n=o1(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 oi={ok:!0,violation:0},qn=1e7;function Nr(e,t){let r;try{r=e.build(t)}catch(s){return{total:qn*2,feasible:!1,terms:[],reason:`build failed: ${String(s)}`}}let n=e.feasible(r);if(!n.ok)return{total:qn+Math.max(0,n.violation),feasible:!1,terms:[],reason:n.reason};let o;try{o=e.terms(r)}catch(s){return{total:qn*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:qn*2,feasible:!1,terms:o,reason:"objective was not finite"}}var ai=(e,t)=>!t||(e.feasible!==t.feasible?e.feasible:e.total<t.total);function sh(e,t){return t.map((r,n)=>Math.min(e[n].hi,Math.max(e[n].lo,r)))}var Or=e=>e.map(t=>t.start);function su(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 oD(e){let t=0;for(;t===0;)t=e();return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e())}function ih(e,t){let{budget:r}=t,n=Math.max(1,Math.floor(t.progressEvery??1)),o=e.variables,a=p=>sh(o,p.map((d,h)=>o[h].lo+d*(o[h].hi-o[h].lo))),s=p=>p.map((d,h)=>(d-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:p=>{if(i>=r)return l?.total??Number.POSITIVE_INFINITY;i++;let d=p.map(g=>Math.min(1,Math.max(0,g))),h=Nr(e,a(d));h.feasible||c++;let b=ai(h,l)?h:l;return b===h&&(l=h,u=d),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:p=>({method:p,x:u?a(u):Or(o),score:l??Nr(e,Or(o)),evaluations:i,history:m,infeasible:c})}}var ch=(e,t,r,n=0,o)=>{let a=t?r.norm(Or(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 a1(e,t){let r=ih(e,t),n=su(t.seed??1),o=e.variables.length;for(r.evaluate(ch(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 va(e,t){let r=ih(e,t),n=e.variables.length,o=su(t.seed??1),a=1,s=2,i=.5,c=.5,l=ch(e,t.warmStart!==!1,r,t.startJitter,o),u=.25;for(;r.left()>0;){let m=[{u:l,f:r.evaluate(l)}];for(let f=0;f<n&&r.left()>0;f++){let p=l.slice();p[f]+=p[f]+u>1?-u:u,m.push({u:p,f:r.evaluate(p)})}for(;r.left()>0;){m.sort((g,y)=>g.f-y.f);let f=m[n],p=new Array(n).fill(0);for(let g=0;g<n;g++)for(let y=0;y<n;y++)p[y]+=m[g].u[y]/n;let d=g=>p.map((y,R)=>y+g*(y-f.u[R])),h=d(a),b=r.evaluate(h);if(b<m[0].f){let g=d(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=d(-i),y=r.evaluate(g);if(y<f.f)m[n]={u:g,f:y};else{let R=m[0],k=0;for(let v=1;v<=n;v++)for(let x=0;x<n;x++)k=Math.max(k,Math.abs(m[v].u[x]-R.u[x]));if(k<1e-4)break;for(let v=1;v<=n&&r.left()>0;v++){let x=m[v].u.map((M,A)=>R.u[A]+c*(M-R.u[A]));m[v]={u:x,f:r.evaluate(x)}}}}}m.sort((f,p)=>f.f-p.f),l=m[0].u.map(f=>Math.min(1,Math.max(0,f+.05*(o()-.5)))),u=Math.max(.02,u*.5)}return r.result("nelder-mead")}function s1(e,t){let r=ih(e,t),n=e.variables.length,o=su(t.seed??1),a=4+Math.floor(3*Math.log(n)),s=Math.floor(a/2),i=[];for(let M=1;M<=s;M++)i.push(Math.log(s+.5)-Math.log(M));let c=i.reduce((M,A)=>M+A,0);for(let M=0;M<s;M++)i[M]/=c;let l=1/i.reduce((M,A)=>M+A*A,0),u=(l+2)/(n+l+5),m=1+2*Math.max(0,Math.sqrt((l-1)/(n+1))-1)+u,f=(4+l/n)/(n+4+2*l/n),p=(n+2)/3,d=Math.min(1,p*2/((n+1.3)**2+l)),h=Math.min(1-d,p*2*(l-2+1/l)/((n+2)**2+l)),b=Math.sqrt(n)*(1-1/(4*n)+1/(21*n*n)),g=ch(e,t.warmStart!==!1,r,t.startJitter,o),y=.25,R=new Array(n).fill(1),k=new Array(n).fill(0),v=new Array(n).fill(0),x=0;for(;r.left()>0;){x++;let M=[];for(let S=0;S<a&&r.left()>0;S++){let F=[];for(let L=0;L<n;L++)F.push(oD(o));let C=g.map((L,E)=>L+y*R[E]*F[E]);M.push({z:F,u:C,f:r.evaluate(C)})}if(M.length<s)break;M.sort((S,F)=>S.f-F.f);let A=g.slice(),w=new Array(n).fill(0);g=new Array(n).fill(0);for(let S=0;S<s;S++)for(let F=0;F<n;F++)g[F]+=i[S]*M[S].u[F],w[F]+=i[S]*M[S].z[F];g=g.map(S=>Math.min(1,Math.max(0,S)));for(let S=0;S<n;S++)k[S]=(1-u)*k[S]+Math.sqrt(u*(2-u)*l)*w[S];let T=Math.sqrt(k.reduce((S,F)=>S+F*F,0)),P=T/Math.sqrt(1-(1-u)**(2*x))/b<1.4+2/(n+1)?1:0;for(let S=0;S<n;S++){let F=(g[S]-A[S])/(y*R[S]);v[S]=(1-f)*v[S]+P*Math.sqrt(f*(2-f)*l)*F}for(let S=0;S<n;S++){let F=0;for(let E=0;E<s;E++)F+=i[E]*M[E].z[S]*M[E].z[S];let C=R[S]*R[S],L=(1-d-h)*C+d*(v[S]*v[S]+(1-P)*f*(2-f)*C)+h*F*C;R[S]=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 ka=[{name:"random",run:a1},{name:"nelder-mead",run:va},{name:"sep-cma-es",run:s1}];var Xz=Math.PI/180;var iu=Math.PI/180;var Jz={Fz:100,alpha:.25*iu,kappa:.005,gamma:.5*iu,p:6900},i1={Fz:100,alpha:1*iu,kappa:.02,gamma:.5*iu,p:6900};var c1=Math.PI/180,a6={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:c1},gamma:{rad:1,deg:c1},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 u6=Math.PI/180;var bD=Math.PI/180;var g6=3*bD;var k6=Math.PI/180;var I6=Math.PI/180;var SD={RCX1:1,RCY1:1,REX1:0,REY1:0,RBY3:0,RHX1:0,RHY1:0},m1={RBX1:15,RBX2:15,RBY1:18,RBY2:19,...SD};var Y6=Math.PI/180;var TD=Math.PI/180,cu=[{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"},{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"}],sY=new Map(cu.map(e=>[e.id,e]));var iY=.01*TD;var Ue=Math.PI/180;var f1=new Set(cu.filter(e=>e.group!=="inputs"&&(e.unit==="N"||e.unit==="N\xB7m"||e.unit==="N/rad")).map(e=>e.id)),h1={alpha:{from:-15*Ue,to:15*Ue,n:61},kappa:{from:-.25,to:.25,n:61},gamma:{from:-6*Ue,to:6*Ue,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}},dh={alpha:{from:0,to:12*Ue,n:7},kappa:{from:-.2,to:.2,n:9},gamma:{from:-4*Ue,to:4*Ue,n:5},Fz:{from:400,to:1600,n:5},p:{from:6e4,to:12e4,n:4},V:{from:5,to:35,n:4}};var fh={alpha:{from:0,to:12*Ue,n:25},kappa:{from:-.2,to:.2,n:25},gamma:{from:-4*Ue,to:4*Ue,n:17},Fz:{from:300,to:1800,n:16},p:{from:6e4,to:12e4,n:13},V:{from:5,to:35,n:13}};var Se=(e,t,r,n={},o={})=>({id:e,form:"curves",sweep:[{input:t,...h1[t],...o}],x:t,y:r,...n}),lu=(e,[t,r],n,o,a={})=>({id:e,form:"carpet",sweep:[{input:t,...dh[t]},{input:r,...dh[r]}],x:n,y:[o],...a}),Vr=(e,t)=>({id:e,fixed:t}),Yt={input:"Fz",values:"car"},ph={alpha:0,kappa:0},At={kappa:0},p1={alpha:0},LD={input:"Fz",values:[500,1e3,1500]},DD=[{id:"overview",name:"Overview",cards:[Vr("tyre","tyre"),Se("fy","alpha",["Fy"],{title:"Lateral force",hold:At}),Se("mz","alpha",["Mz"],{title:"Aligning moment",hold:At}),Se("fx","kappa",["Fx"],{title:"Longitudinal force",hold:p1}),lu("combined-carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),Vr("ellipse","ellipse")]},{id:"lateral",name:"Lateral",cards:[Se("fy-load","alpha",["Fy"],{title:"Lateral force per wheel load",series:Yt,hold:At}),Se("muy-load","alpha",["muY"],{title:"Lateral force per unit load",series:Yt,hold:At}),Se("fy-peak","alpha",["Fy"],{title:"Lateral force over its peak",series:Yt,hold:At,scale:{per:"peak"}},{from:0,to:15*Ue,n:61}),Se("muy-peak","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load"}),Se("calpha","Fz",["Calpha"],{title:"Cornering stiffness over load"}),Se("alpha-peak","Fz",["alphaPeak"],{title:"Slip angle at the peak over load"})]},{id:"aligning",name:"Aligning",cards:[Se("mz-load","alpha",["Mz"],{title:"Aligning moment per wheel load",series:Yt,hold:At}),Se("trail","alpha",["t"],{title:"Pneumatic trail",series:Yt,hold:At},{from:0,to:12*Ue,n:49}),Se("mzr","alpha",["Mzr"],{title:"Residual aligning moment",series:Yt,hold:At},{from:0,to:12*Ue,n:49}),lu("gough",["alpha","Fz"],"Fy","Mz",{title:"Gough plot",hold:At}),Se("steering-feel","alpha",["t"],{title:"Steering feel",x:"FyRel",series:Yt,hold:At},{from:0,to:12*Ue,n:49})]},{id:"longitudinal",name:"Longitudinal",cards:[Se("fx-load","kappa",["Fx"],{title:"Longitudinal force per wheel load",series:Yt,hold:p1}),Se("mux-peak","Fz",["muXPeak"],{title:"Peak longitudinal \u03BC over load"}),Se("kx","Fz",["dFxdk"],{title:"Slip stiffness at zero slip over load",hold:ph}),Se("kappa-peak","Fz",["kappaPeak"],{title:"Slip ratio at the peak over load"})]},{id:"combined",name:"Combined",cards:[lu("carpet",["kappa","alpha"],"Fy","Fx",{title:"Combined-slip carpet"}),lu("envelope-load",["kappa","alpha"],"Fy","Fx",{title:"Friction envelope per load",scale:{per:"Fz"},facet:LD}),Se("fy-kappa","kappa",["Fy"],{title:"Side force while driving or braking",series:{input:"alpha",values:[2*Ue,4*Ue,8*Ue]}}),Se("fx-kappa","kappa",["Fx"],{title:"Driving force while cornering",series:{input:"alpha",values:[0,4*Ue,8*Ue]}}),Vr("ellipse","ellipse")]},{id:"camber",name:"Camber",cards:[Se("fy-gamma","alpha",["Fy"],{title:"Lateral force per inclination",series:{input:"gamma",values:[-4,-2,0,2,4].map(e=>e*Ue)},hold:At}),Se("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",...fh.gamma},{input:"Fz",...fh.Fz,follow:!0}],x:"gamma",y:["Fz"],z:"muYPeak"},Se("camber-stiffness","alpha",["dFydg"],{title:"Camber stiffness at the point",series:Yt,hold:At}),Se("mx","alpha",["Mx"],{title:"Overturning moment",series:Yt,hold:At})]},{id:"rolling",name:"Rolling and radius",cards:[Se("my","V",["My"],{title:"Rolling-resistance moment",series:Yt,hold:ph}),Se("radius","Fz",["R0","Rl","Re"],{title:"Radius over load"},{from:0}),Se("p-roll","V",["Proll"],{title:"Rolling power",series:Yt,hold:ph})]},{id:"transient",name:"Transient",cards:[Se("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},Se("delta-fy","alpha",["Fy"],{title:"Lateral force, minus the reference",hold:At,scale:{delta:!0}}),Se("delta-mu","Fz",["muYPeak"],{title:"Peak lateral \u03BC over load, minus the reference",scale:{delta:!0}}),Se("delta-calpha","Fz",["Calpha"],{title:"Cornering stiffness over load, minus the reference",scale:{delta:!0}})]},{id:"car",name:"Car",cards:[Vr("operating","operating"),Vr("wheels","wheels")]},{id:"fit",name:"Fit check",cards:[Vr("fitLateral","fitLateral"),Vr("fitLongitudinal","fitLongitudinal"),Vr("fitCoupling","fitCoupling"),Vr("fitEnvelope","fitEnvelope")]}];var BD=5670374e-14,hh=273.15,y1=.95,x1=60,uu=10,$D=.55,Et=25,bh=-20,gh=50,ii={tempC:[20,100,200,550,650,750],factor:[.8,.92,1,1,.85,.65]},ci={discMassKg:.5,discOuterMm:220,specificHeatJPerKgK:460,emissivity:.6,coolingWPerM2K:200,padCurve:{tempC:[...ii.tempC],factor:[...ii.factor]}},mu={...ci,discMassKg:.4,discOuterMm:200,padCurve:{tempC:[...ii.tempC],factor:[...ii.factor]}};function yh(e,t){let r=t==="front"?ci:mu,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 GD=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},si=(e,t,r,n)=>Math.min(r,Math.max(t,GD(e,n)));function KD(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 xh(e,t){return{discMassKg:si(e?.discMassKg,.05,20,t.discMassKg),discOuterMm:si(e?.discOuterMm,50,600,t.discOuterMm),specificHeatJPerKgK:si(e?.specificHeatJPerKgK,100,3e3,t.specificHeatJPerKgK),emissivity:si(e?.emissivity,.02,1,t.emissivity),coolingWPerM2K:si(e?.coolingWPerM2K,uu,5e3,t.coolingWPerM2K),padCurve:KD(e?.padCurve,t.padCurve)}}function pu(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 Rh(e,t=1){let r=e.discMassKg*e.specificHeatJPerKgK,n=e.discOuterMm*.001/2,o=2*Math.PI*n*n,a=x1/3.6,s=e.emissivity*BD*o,i=m=>uu+(e.coolingWPerM2K-uu)*Math.pow(Math.max(0,m)*t/a,$D),c=(m,f,p)=>{let d=m+hh,h=p+hh;return i(f)*o*(m-p)+s*(d**4-h**4)},l=(m,f)=>i(f)*o+4*s*Math.max(0,m+hh)**3,u=(m,f)=>r/l(f,m);return{heatCapacityJPerK:r,areaM2:o,convectionAt:i,coolingW:c,timeConstantS:u,step(m,f,p,d,h){if(!(d>0))return m+f/r;let b=u(p,m+Math.max(0,f)/r),g=Math.max(1,Math.ceil(d/(.25*b))),y=d/g,R=f/g;for(let k=0;k<g;k++)m+=(R-c(m,p,h)*y)/r;return m},padFactor:m=>pu(e.padCurve,m),window:R1(e.padCurve)}}function du(e,t,r,n,o,a,s=Et){let i=n.length,c=new Array(i),l=new Array(i),u=new Array(i),m=y1/Math.max(1,t),f=a,p=f,d=0,h=0,b=0;for(let g=0;g<i;g++){let y=Math.max(0,r[g]??0);c[g]=f,l[g]=y*n[g],u[g]=e.padFactor(f);let R=y*(o[g]??0);d+=R,f<e.window.fromC?h+=R:f>e.window.toC&&(b+=R);let k=g+1<i?n[g+1]:n[g],v=.5*(n[g]+k),x=v>0?(o[g]??0)/v:0;f=e.step(f,m*R,v,x,s),f>p&&(p=f)}return{tempC:c,heatW:l,padFactor:u,startC:a,endC:f,maxC:p,workJ:d,coldWorkJ:h,hotWorkJ:b}}function R1(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])&&pu(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 vh=1e5,S1=.001,Qn={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},Mh={fullAtBar:10,maxPowerKw:0,fadeBelowKmh:0,distribution:"equal"};var Sh=F1(hu(Qn,"Formula Student brakes")),Ah=40,A1={ideal:!1,barFront:Qn.barFront,pedalForceMaxN:0,testSpeedKmh:Ah,regen:Mh};function v1(e){let{heat:t,...r}=e;return t?{...r,heat:{...t,padCurve:{tempC:[...t.padCurve.tempC],factor:[...t.padCurve.factor]}}}:r}function F1(e){let t=(r,n)=>r.heat?r:{...r,heat:yh(r,n)};return{...e,front:t(e.front,"front"),rear:t(e.rear,"rear")}}function hu(e,t){return{name:t,pedalRatio:e.pedalRatio,masterFrontMm:e.masterFrontMm,masterRearMm:e.masterRearMm,valve:e.valve,valveKneeBar:e.valveKneeBar,valveSlope:e.valveSlope,front:v1(e.front),rear:v1(e.rear),adjusterPitchMm:e.adjusterPitchMm,barLengthMm:e.barLengthMm}}function Fh(e,t){return w1({...e,barFront:t.barFront,pedalForceMaxN:t.pedalForceMaxN})}function wh(e,t){let r=$r(t),n=e?fr(e):void 0;return{mode:r.ideal?"tyre":n?"hydraulic":"balance",hydraulic:n?Fh(n,r):Qn,regen:r.regen}}var HD=["none","proportioning","limiter"],fu=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t},tt=(e,t,r,n)=>Math.min(r,Math.max(t,fu(e,n))),zD=(e,t)=>{let r=fu(e,t);return r>0?r:t};function k1(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(fu(e?.discs,n==="inboard"?1:t.discs)))),pistonsPerSide:Math.max(1,Math.min(6,Math.round(fu(e?.pistonsPerSide,t.pistonsPerSide)))),pistonDiaMm:tt(e?.pistonDiaMm,5,80,t.pistonDiaMm),padMu:tt(e?.padMu,.05,1.5,t.padMu),effRadiusMm:tt(e?.effRadiusMm,20,300,t.effRadiusMm),ratio:n==="inboard"?tt(e?.ratio,1,20,t.ratio):1,...e?.heat&&typeof e.heat=="object"?{heat:xh(e.heat,t.heat??r)}:{}}}function w1(e){let t=Qn;return{pedalRatio:tt(e?.pedalRatio,.5,15,t.pedalRatio),pedalForceMaxN:tt(e?.pedalForceMaxN,0,5e3,t.pedalForceMaxN),barFront:tt(e?.barFront,.05,.95,t.barFront),masterFrontMm:tt(e?.masterFrontMm,8,40,t.masterFrontMm),masterRearMm:tt(e?.masterRearMm,8,40,t.masterRearMm),valve:HD.includes(e?.valve)?e?.valve:t.valve,valveKneeBar:tt(e?.valveKneeBar,0,200,t.valveKneeBar),valveSlope:tt(e?.valveSlope,0,1,t.valveSlope),front:k1(e?.front,t.front,ci),rear:k1(e?.rear,t.rear,mu),adjusterPitchMm:zD(e?.adjusterPitchMm,t.adjusterPitchMm),barLengthMm:tt(e?.barLengthMm,0,500,t.barLengthMm)}}function YD(e){let t=Mh;return{fullAtBar:tt(e?.fullAtBar,0,200,t.fullAtBar),maxPowerKw:tt(e?.maxPowerKw,0,1e3,t.maxPowerKw),fadeBelowKmh:tt(e?.fadeBelowKmh,0,100,t.fadeBelowKmh),distribution:e?.distribution==="wheel"?"wheel":"equal"}}function fr(e){let t=w1(e??void 0),r=typeof e?.name=="string"&&e.name.trim()?e.name:WD;return hu(t,r)}function $r(e){return{ideal:e?.ideal===!0,barFront:tt(e?.barFront,.05,.95,Qn.barFront),pedalForceMaxN:tt(e?.pedalForceMaxN,0,5e3,0),testSpeedKmh:tt(e?.testSpeedKmh,5,150,Ah),regen:YD(e?.regen)}}var WD="Formula Student brakes";var kh=e=>Math.PI/4*(e*S1)**2;function yn(e,t){let r=e.pistonsPerSide*kh(e.pistonDiaMm)*vh;return e.discs*2*e.padMu*r*e.effRadiusMm*S1*e.ratio/Math.max(.05,t)}function C1(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 li(e,t){let r=Math.max(0,t)*e.pedalRatio,n=e.barFront*r/kh(e.masterFrontMm)/vh,o=(1-e.barFront)*r/kh(e.masterRearMm)/vh;return{front:n,rearIn:o,rear:C1(e,o)}}function jD(e,t){let r=li(e,1);return{front:yn(e.front,t)*r.front,rear:yn(e.rear,t)*r.rearIn}}function ui(e,t){let r=jD(e,t);return r.front/Math.max(1e-12,r.front+r.rear)}function mi(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=T1(t,l),m=t.maxPowerKw>0&&l>0?t.maxPowerKw*1e3/l:1/0,f=Math.max(0,e.fFront[c]),p=Math.max(0,e.fRear[c]),d=f+p>0?Math.min(1,m/(f+p)):1;r.push(l),n.push(f*d*u),o.push(p*d*u)}}function T1(e,t){let r=e.fadeBelowKmh/3.6;return r>0?Math.max(0,Math.min(1,t/r)):1}function Br(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 M1=new WeakMap;function Zn(e){let t=M1.get(e);return t||(t=e.mode==="hydraulic"&&e.hydraulic?XD(e,e.hydraulic):UD(e),M1.set(e,t)),t}function UD(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 XD(e,t){let r=yn(t.front,e.tyreRadiusM),n=yn(t.rear,e.tyreRadiusM),o=e.regen,a=(c,l)=>{let u=li(t,c),m=0,f=0;if(o&&u.front>0){let p=o.fullAtBar>0?Math.min(1,u.front/o.fullAtBar):1;m=p*Br(o.v,o.front,l),f=p*Br(o.v,o.rear,l)}return{front:r*u.front+m,rear:n*u.rear+f,regenFront:m,regenRear:f,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 f=0;f<60;f++){let p=.5*(m+u);i(p,l)<c?m=p:u=p}return u}}}function Ch(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 bu=Ks,qD=.1,Jn=(e,t)=>e.a*Math.sqrt(Math.max(0,1-(t/Math.max(1e-9,e.b))**2));function gu(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 f=0;f<48;f++)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 f of[t,r]){let p=e(f);p>m&&(u=f,m=p)}return u}function Lh(e,t,r){let n=Math.max(0,r-bu*t.b),o=Math.min(r,bu*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 Dh(e,t,r,n,o=0){let a=Math.max(0,r),s=Lh(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],f=u.Fz/Math.max(1e-9,u.Fz+m.Fz),p=Math.max(0,Math.min(1,1-f/qD)),d=p>0&&a<bu*m.b?m.cap(a):0,h=d>l?l+p*(d-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:P=>2*Math.max(0,l-P)};let{lo:R,hi:k}=s,v=gu(P=>{let S=Jn(e,P),F=Jn(t,a-P);return Math.min(S+F,2*Math.min(S,F)+y)},R,k),x=e.cap(v),M=t.cap(a-v),A=Math.max(2*l,Math.min(x+M,2*Math.min(x,M)+y)),w=(P,S,F)=>Math.min(y,Math.max(0,P-F))+Math.min(y,Math.max(0,S-F));return{...g,regenWheel:y,mixedMax:A,regenRoom:P=>{let S=w(i,c,P);if(!(a>0))return S;let F=D=>bu*D.b*Math.sqrt(Math.max(0,1-(P/Math.max(1e-9,D.a))**2)),C=Math.max(R,a-F(t)),L=Math.min(k,F(e));if(!(C<=L))return S;let E=gu(D=>Math.min(y,Jn(e,D)-P)+Math.min(y,Jn(t,a-D)-P),C,L);return Math.max(S,w(e.cap(E),t.cap(a-E),P))}}}var Th=e=>Math.max(e.xNoLock,e.xLock),Ph=e=>Math.max(e.mixedMax,2*e.xLock);function Ma(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 Sa(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 pi(e,t,r,n){return e.shares?QD(e,e.shares,t,r,n):ZD(e,t,r,n)}function P1(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 QD(e,t,r,n,o){let a=Ph(r),s=Ph(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=Sa(r,t.front*b),y=Sa(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,f=[{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&&f.push({u:b,by:"front"})}if(n.xLock>n.xNoLock){let b=t.rear>0?n.mixedMax/t.rear:1/0;b<i&&f.push({u:b,by:"rear"})}let{cand:p,force:d}=P1(f,l),h=e.demand(p.u,o);return{force:Math.max(0,Number.isFinite(d)?d:0),control:p.u,demand:h,limitedBy:p.by,lockFront:h.front/2>r.mixedMax/2*(1+1e-9),lockRear:h.rear/2>n.mixedMax/2*(1+1e-9)}}function ZD(e,t,r,n){let o=Th(t),a=Th(r),s=v=>(v.front-v.regenFront)/2,i=v=>(v.rear-v.regenRear)/2,c=v=>{let x=e.demand(v,n);return s(x)<=o*(1+1e-12)&&i(x)<=a*(1+1e-12)},l=(v,x)=>{if(v(e.demand(x,n)))return x;let M=0,A=x;for(let w=0;w<60;w++){let T=.5*(M+A);v(e.demand(T,n))?M=T:A=T}return M},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),f=Number.isFinite(e.uMax)&&m>=e.uMax,p=v=>{let x=e.demand(v,n),M=Ma(t,s(x),x.regenFront),A=Ma(r,i(x),x.regenRear);return Number.isFinite(M)&&Number.isFinite(A)?M+A:-1/0},d=e.demand(m,n),h=o>0?s(d)/o:1/0,b=a>0?i(d)/a:1/0,g=[{u:m,by:f?"pedal":h>=b?"front":"rear"}];if(t.xLock>t.xNoLock){let v=l(x=>s(x)<=t.xNoLock,m);v<m&&g.push({u:v,by:"front"})}if(r.xLock>r.xNoLock){let v=l(x=>i(x)<=r.xNoLock,m);v<m&&g.push({u:v,by:"rear"})}let{cand:y,force:R}=P1(g,p),k=e.demand(y.u,n);return{force:Math.max(0,Number.isFinite(R)?R:0),control:y.u,demand:k,limitedBy:y.by,lockFront:s(k)>t.xNoLock*(1+1e-9),lockRear:i(k)>r.xNoLock*(1+1e-9)}}var Gr={regen:!0,regenEfficiency:.6};function Kr(e,t){let r=e.energy??t??Gr;return{regen:r.regen===!0,regenEfficiency:Math.min(1,Math.max(0,Number.isFinite(r.regenEfficiency)?r.regenEfficiency:0))}}function Hr(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 L1(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 yt(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 yu(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 d=o+a>>1;e[d]<=r?o=d:a=d}if(o===n-1)return t[n-1];let s=d=>e[d+1]-e[d],i=d=>(t[d+1]-t[d])/s(d),c=d=>{if(d===0||d===n-1){let[y,R]=d===0?[0,1]:[n-2,n-3],k=i(y)*(1+s(y)/(s(y)+s(R)))-i(R)*(s(y)/(s(y)+s(R)));return k*i(y)<=0?0:Math.abs(k)>2*Math.abs(i(y))?2*i(y):k}let h=i(d-1),b=i(d),g=(h*s(d)+b*s(d-1))/(s(d-1)+s(d));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),f=c(o+1),p=r-e[o];return t[o]+p*(m+p*((3*u-2*m-f)/l+p*(m+f-2*u)/(l*l)))}function di(e,t,r){return r.map(n=>yt(e,t,n))}var fi=e=>e.reduce((t,r)=>r>t?r:t,-1/0),Aa=e=>e.reduce((t,r)=>r<t?r:t,1/0);var JD=[-.906179845938664,-.538469310105683,0,.538469310105683,.906179845938664],eE=[.236926885056189,.478628670499366,.568888888888889,.478628670499366,.236926885056189];function Eh(e,t,r){let n=.5*(r-t),o=.5*(t+r),a=0;for(let s=0;s<5;s++)a+=eE[s]*e(n*JD[s]+o);return n*a}var tE=Math.PI*2,rE=.5/3.6;function hi(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 Ih(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*tE;c[g]=y*o/n,l[g]=s[g]*n/o}let u=fi(c),m=Hr(Aa(c),u,u/rE),f=di(c,l,m),{front:p,rear:d}=hi(t,r),h=f.map(g=>g*p),b=f.map(g=>g*d);return{vVehicle:m,fFront:h,fRear:b,vMax:u}}var D1=60/(2*Math.PI),E1=.1,I1=.08,_1=0;function _h(e){let t=(r,n)=>r===void 0||!Number.isFinite(r)?n:Math.max(0,r);return{up:t(e.upshiftTime,E1),down:t(e.downshiftTime,I1)}}function Nh(e){let t=e.driveKept;return t===void 0||!Number.isFinite(t)?_1:Math.max(0,Math.min(1,t))}function Oh(e,t,r){let{primary:n,ratios:o,efficiency:a}=e.gearbox,s=t>0&&r>0&&n>0,i=(b,g)=>b/D1*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,_e(e.rpm,e.torque,b)),f=(b,g)=>{let y=c[g];return y?b*y.ratio/r*D1:0},p=(b,g)=>g===0&&c.length>0&&b<c[0].vIdle,d=(b,g)=>{let y=c[g];return y?p(b,g)?m(e.idleRpm)*y.ratio*l/r:b<y.vIdle||b>y.vLimit?0:m(f(b,g))*y.ratio*l/r:0},h=(b,g)=>{let y=c[g];return!y||p(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:f,torque:m,force:d,inertiaMass:h,slipping:p}}function Fa(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 Vh(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 N1=9.81,O1=Math.PI*2;function It(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]*(O1/60),a[v]=t[v]/60*O1,s[v]=a[v]*u/l,i[v]=r[v]*l,c[v]=i[v]/u;let m=fi(s),f=m,p=.5/3.6,d=Hr(Aa(s),m,m/p),h=di(s,c,d),b=Hr(Aa(t),fi(t),250),g=di(t,o,b).map(v=>v*e.power_scale.value),y,R=f,k;if(e.motorModel?.kind==="ice"){k=Oh(e.motorModel,l,u);let v=Hr(0,k.vMax,Math.max(2,Math.ceil(k.vMax/p)+1)),x=v.map(w=>Vh(k,w)),M=v.map(()=>0),A=e.motorPlacement==="front";y={vVehicle:v,fFront:A?x:M,fRear:A?M:x,vMax:k.vMax},R=k.vMax}else e.motorModel&&(y=Ih(e.motorModel,Math.max(1,Math.round(e.motorCount??e.driven_wheels.value)),e.motorPlacement??"rear",l,u),R=y.vMax);return{params:e,g:N1,FG:e.m.value*N1,vMax:R,vVehicle:d,fRad:h,uMotor:b,pMotor:g,vRad:s,fAxle:y,...k?{engine:k}:{}}}var xn=e=>e.motorModel?.kind==="ice"?hi(1,e.motorPlacement==="front"?"front":"rear"):hi(Math.max(1,Math.round(e.motorCount??e.driven_wheels?.value??2)),e.motorPlacement??"rear");function V1(e){let t=xn(e);return t.front>=2||t.rear>=2}function B1(e){return V1(e)?e.motorMount??"hub":"chassis"}function Bh(e){if(!e.motorModel)return{front:!1,rear:!0};let t=xn(e);return{front:t.front>0,rear:t.rear>0}}function $h(e){let t=xn(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=B1(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 xt(e){return wh(e.brakeModel,e.brakeSetup)}function xu(e){return $r(e.brakeSetup).ideal?"tyre":e.brakeModel||e.brakeModelId?"hydraulic":"balance"}function $1(e,t){if(!(ht(e.motorModel)||!Kr(e).regen))return mi(Ru(It(e)),t??xt(e).regen)}function Ru(e){return e.fAxle??{vVehicle:e.vVehicle,fFront:e.vVehicle.map(()=>0),fRear:e.fRad.map(t=>t*e.params.driven_wheels.value)}}function Gh(e,t=xt(e)){if(t.mode==="hydraulic")return ui(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+Q(e,"cg_height")/Math.max(1,Q(e,"wheelbase"))))}return Q(e,"brake_balance")}function Kh(e,t=xt(e)){return{front:t.hydraulic.front.location==="inboard",rear:t.hydraulic.rear.location==="inboard"}}function Hh(e){let t=xt(e);return{brakeBalanceFront:Gh(e,t),brakeInboard:Kh(e,t)}}function G1(e,t=xt(e)){if(t.mode==="tyre"||t.regen.distribution!=="wheel"||ht(e.motorModel))return;let r=xn(e),n={front:r.front>=2,rear:r.rear>=2};return n.front||n.rear?n:void 0}function bi(e){let t=xt(e),r=e.r_dyn.value,n=Kh(e,t),o=Gh(e,t),a=G1(e,t),s=t.mode==="hydraulic"||a?$1(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 oE=9.81;function zh(e,t){if(ht(e.motorModel))return()=>0;let r=xt(e),n=mi(t,r.regen);if(r.mode==="hydraulic"){let a=Zn({mode:"hydraulic",balanceFront:ui(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 0;let c=a.demand(a.controlFor(s,i),i);return Math.min(s,c.regenFront+c.regenRear)}}let o=r.mode==="tyre"?aE(e):()=>Math.min(.99,Math.max(.01,Q(e,"brake_balance")));return(a,s,i)=>{if(!(a>0))return 0;let c=o(s,i);return Math.min(c*a,Br(n.v,n.front,s))+Math.min((1-c)*a,Br(n.v,n.rear,s))}}function aE(e){let t=e.m.value*oE,r=e.front_mass_diss.value>1?e.front_mass_diss.value/100:e.front_mass_diss.value,n=Q(e,"cg_height")/Math.max(1,Q(e,"wheelbase")),o=1-Math.max(0,Math.min(1,Q(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 K1(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 Yh={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"},...K1("front"),...K1("rear")},Wh={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 jh(e){let t=Yh[e];return`${t.label}, ${t.section}`.toLowerCase()}function Uh(e){let t=Wh[e];return t.section?`${t.section} ${t.label.charAt(0).toLowerCase()}${t.label.slice(1)}`:t.label}var H1=new WeakMap;function hr(e){if(e.brakes)return e.brakes;let t=H1.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},H1.set(e,t)}return t}var zr=e=>Zn(hr(e));var lE=Math.PI/180,wa=Object.freeze({tbr:1,preloadN:0}),vu=Object.freeze({tbr:1/0,preloadN:0}),qh=e=>e.faces*e.muClutch*e.rFrictionMm/e.rRampMm;function Qh(e,t){if(!(e>0)||Number.isNaN(t))return 0;let r=Math.tan(Math.min(90,t)*lE);return r>0?Math.min(1,e/r):1}function Y1(e){if(e>=1)return 1/0;let t=e>0?e:0;return(1+t)/(1-t)}function ku(e){return e===1/0?1:e>1?(e-1)/(e+1):0}function Ca(e,t){return e.tbr===1/0?1/0:(e.preloadN>0?e.preloadN:0)+ku(e.tbr)*Math.abs(t)}function yi(e,t,r){let n=o=>o!==void 0&&o>0&&r>0?o/r:0;switch(e.kind){case"open":return wa;case"spool":return vu;case"independent":return t==="hubs"?wa:vu;case"clutch":{let o=n(e.preloadNm);return t==="hubs"?{tbr:1,preloadN:o}:{tbr:Y1(Qh(qh(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 gi(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 z1=4;function Xh(e,t){let r=0;for(let a of e)r=Math.max(r,gi(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=f=>{f>0&&f<1&&(r=Math.max(r,gi(s.m1+f*i,s.m2+f*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 xi(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=Lh(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=gu(b=>Jn(e,b)+Jn(t,c-b),l.lo,l.hi),f=[{m1:l.c1,m2:l.c2}];for(let b=1;b<=z1&&m!==l.y1;b++){let g=l.y1+(m-l.y1)*b/z1;f.push({m1:e.cap(g),m2:t.cap(c-g)})}let p=Xh(f,wa),d=Xh(f,vu);if(!(d>p))return u;let h=(Xh(f,{tbr:s,preloadN:i})-p)/(d-p);return Math.min(a,u+(a-u)*Math.min(1,Math.max(0,h)))}function W1(e,t,r,n,o,a){return Zh(e,o,xi(t,r,n,o,a))}function Zh(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 Jh(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,f=l-s,p=f!==0?i-l*(i-o)/f:NaN;m?p>Math.min(o,i)&&p<Math.max(o,i)||(p=.5*(o+i)):Number.isFinite(p)?Math.abs(p-i)>10*Math.abs(l)&&(p=i+Math.sign(p-i)*10*Math.abs(l)):p=c;let d=e(p),h=d-p;if(u++,m&&h<0==l<0?s*=.5:(o=i,s=l),i=p,c=d,l=h,s<0!=l<0&&Math.abs(i-o)<=r)break}return{x:i,fx:c,evals:u}}function j1(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),f=0;for(let p=o;l<a;p*=2){if(f=Math.min(f+p,m),f>m-n)return null;let d=t+u*f,h=e(d),b=h-d;if(l++,!(Math.abs(b)>n))return{x:d,fx:h,evals:l};if(c<0!=b<0)return X1(e,s,c,d,h,b,n,l,a);s=d,c=b}return null}function U1(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 X1(e,o,s,c,u,m,r,l,n);if(l>=n)return{x:c,fx:u,evals:l};let f=Math.abs(c-o),p=s!==m?m*(c-o)/(s-m):NaN,d=p*i>0?Math.min(Math.abs(p),10*Math.abs(m),2*f):2*f;o=c,s=m,c+=i*d}}function X1(e,t,r,n,o,a,s,i,c){let l=t,u=r,m=n,f=a,p=n,d=o,h=0;for(;i<c&&Math.abs(m-l)>s;){p=(l*f-m*u)/(f-u),d=e(p);let b=d-p;if(i++,!(Math.abs(b)>s))break;b<0==u<0?(l=p,u=b,h===-1&&(f*=.5),h=-1):(m=p,f=b,h===1&&(u*=.5),h=1)}return{x:p,fx:d,evals:i}}function Mu(e,t){return Math.abs(e.fx-e.x)>t?e.x:e.fx}var uE=(e,t)=>{let r=e.brakes?.hydraulic?.[t];return!!r&&r.location==="inboard"&&r.discs===1};function Wt(e,t,r){let n=e.driveline?.[t];if(n)return r>=0?n.drive:uE(e,t)?n.coast:n.hubs}var q1=e=>e.tbr>1||e.preloadN>0;var mE=9.81,Q1=["FL","FR","RL","RR"],eb=e=>e==="FL"||e==="FR",Su=e=>eb(e)?"front":"rear",Z1={front:["FL","FR"],rear:["RL","RR"]},ki=()=>({peak:new Map,freeBrake:new Map}),vi=25;function Ri(e,t){let r=Math.max(0,e)/vi,n=Math.floor(r),o=r-n,a=t(n);return o>0?a+o*(t(n+1)-a):a}var Rn=1e-4,pE=.05;function Yr(e,t,r,n=ki(),o=!1){let a=r,s=e.massTotal,i=n.peak,c=(S,F)=>{let C=`${S}:${F}`,L=i.get(C);return L||(L=Nl(ye(t,S),Math.max(1,F*vi)),i.set(C,L)),L},l=(S,F)=>({aPeak:Ri(F,C=>c(S,C).aPeak),fyPeak:Ri(F,C=>c(S,C).fyPeak)}),u=n.freeBrake,m=(S,F)=>{let C=`${S}:${F}`,L=u.get(C);if(L===void 0){let E=Math.max(1,F*vi);L=Dt(ye(t,S),E,0,!0,c(S,F)),u.set(C,L)}return L},f=(S,F)=>F>0?Ri(F,C=>m(S,C)):0,p=zr(e),d=hr(e),h=S=>d.regen&&d.regenPerWheel?.[S]?Br(d.regen.v,d.regen[S],a)/2:0,b=h("front"),g=h("rear"),y=(S,F,C)=>{let L=Math.max(0,F[S]),E=l(Su(S),L);return Dt(ye(t,Su(S)),L,C[S]*E.fyPeak,!0,E)},R=(S,F,C,L,E=!0,D=1)=>{let N=de=>{let j=Math.max(0,F[de]),Z=ye(t,S),re=l(S,j),oe={Fz:j,a:Math.abs(f(S,j)),b:re.fyPeak,slide:j>0?Math.abs(Z.forces({Fz:j,kappa:-1,alpha:0}).Fx):0,cap:le=>Math.abs(Dt(Z,j,le,!0,re))};return D===1?oe:{Fz:j,a:D*oe.a,b:D*oe.b,slide:D*oe.slide,cap:le=>D*oe.cap(le/D)}},O=de=>D*Math.abs(C[de])*l(Su(de),Math.max(0,F[de])).fyPeak,[z,I]=Z1[S],_=N(z),B=N(I),V=O(z)+O(I),G=Dh(_,B,V,L,S==="front"?b:g),H=E?G:{...G,xLock:0},W=Wt(e,S,-1),J=W&&q1(W)?W:void 0;if(!J)return{axle:S,eq:H,cap:H};let Y=Number.isFinite(L)?L:_.cap(O(z))+B.cap(O(I)),ee=W1(H,_,B,V,J,Y);return{axle:S,eq:H,cap:ee,law:J,strong:()=>_.cap(O(z))>=B.cap(O(I))?z:I}},k=(S,F,C,L,E=1)=>R(S,F,C,L,!0,E).cap,v=(S,F,C)=>{let L=S.demand,E=p.shares?Sa(F,L.front):Ma(F,(L.front-L.regenFront)/2,L.regenFront),D=p.shares?Sa(C,L.rear):Ma(C,(L.rear-L.regenRear)/2,L.regenRear);return{front:Number.isFinite(E)?E:0,rear:Number.isFinite(D)?D:0}},x=S=>({muX:F=>F>0?Math.abs(f(S,F))/F:0,muY:F=>F>0?l(S,F).fyPeak/F:0}),M={front:x("front"),rear:x("rear")},A={lf:e.wheelbase/1e3*(1-e.frontMassFrac),lr:e.wheelbase/1e3*e.frontMassFrac},w={front:e.trackFront/2e3,rear:e.trackRear/2e3},T=(S,F,C,L,E)=>{let D=L.cap,N=E.cap,O=pi(p,D,N,a),z={arms:A,halfTrack:w,ayDir:Math.sign(S)};for(let I=0;I<2;I++){let _=v(O,D,N),B={};for(let G of Q1){let H=Math.max(0,F[G]);B[G]={Fz:H,Fy:Math.abs(C[G])*l(Su(G),H).fyPeak,Fx:-(eb(G)?_.front:_.rear)/2}}let V=G=>{if(!G.law||!G.strong)return G.cap;let H={axle:G.axle,strong:G.strong(),full:2*G.cap.xNoLock,open:2*G.eq.xNoLock,sense:-1};return Zh(G.eq,G.law,nu(H,B,M,z))};D=V(L),N=V(E),O=pi(p,D,N,a)}return{limit:O,front:D,rear:N}};return{peakAt:l,axle:k,ceiling:(S,F,C)=>{let[L,E]=Z1[S];return Math.abs(y(L,F,C)+y(E,F,C))},limitAt:(S,F,C,L=0)=>{let E={FL:0,FR:0,RL:0,RR:0},D=Pe(e,S,0,a,0,F),N,O=de=>(N?.ax!==de&&(N={ax:de,loads:Pe(e,S,(de+L)/mE,a,0,F)}),N.loads),z=Ol(de=>ha(C,O(de),D,l).short,-L,-1),I=C,_={front:0,rear:0},B,V,G=(de,j=!0)=>{let Z=z.at(de);E=O(Z),I=ha(C,E,D,l).util;let re=0,oe=0,le=0;for(let ue of Q1){let ie=y(ue,E,I);re+=ie,eb(ue)?oe+=ie:le+=ie}if(_={front:Math.abs(oe),rear:Math.abs(le)},p.mode!=="tyre"){let ue=R("front",E,I,Math.abs(oe),j),ie=R("rear",E,I,Math.abs(le),j);if(o&&(ue.law||ie.law)){let fe=T(S,E,I,ue,ie);B=fe.limit,V={front:fe.front,rear:fe.rear}}else B=pi(p,ue.cap,ie.cap,a),V={front:ue.cap,rear:ie.cap};re=-B.force}return re/s},H=Jh(G,0,Rn),W=Mu(H,Rn),J=W;if(B?.lockFront||B?.lockRear){let de=Jh(Z=>G(Z,!1),0,Rn);J=Mu(de,Rn);let j=j1(G,de.x,H.x,Rn,pE);j||G(H.x),W=Mu(j??H,Rn)}let Y=z.edge(),ee=Y!==void 0&&W<Y;ee&&(W=Math.min(0,Y),G(W),J=Math.max(J,W));let ne={loads:E,ceiling:_,limit:B,axles:V};return{ax:W,axUnlocked:J,...ee?{edge:Y}:{},...ne,split:()=>ne.limit&&ne.axles?v(ne.limit,ne.axles.front,ne.axles.rear):{...ne.ceiling}}}}}var Fu=9.81;function dE(e,t,r){let n=Pe(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 tk=(e,t)=>t.mode==="hydraulic"&&!!hr(e).regen;function Ta(e,t,r=0,n,o=0,a=1){if(!e.brakes&&e.brakeBalanceFront==null)return e.frontMassFrac;let s=zr(e);if(s.shares&&s.mode!=="tyre")return s.shares.front;let i=n&&tk(e,s)?ok(e,n):void 0,c=i?rk(a):eo,l=i?nk(i,c).shares:J1.get(e);l||J1.set(e,l=new Map);let u=Math.round(Math.abs(t)/.005),m=Math.round(Math.max(0,r)/.25),f=i?Math.round(o/.01):0,p=ak(u,m,f),d=l.get(p);if(d===void 0){let h=-u*.005,b=m*.25,g=e.massTotal*Math.abs(h)*Fu;if(i){let y=ik(s,sk(e,i,u,m,f,c),g,b);d=y.front+y.rear>0?y.front/(y.front+y.rear):.5}else d=s.mode==="tyre"?dE(e,h,b):Ch(s,g,b);l.size>5e4&&l.clear(),l.set(p,d)}return d}var J1=new WeakMap;function wu(e,t,r,n,o=0,a=1){let s=zr(e);if(!tk(e,s))return;let i=Math.round(Math.max(0,r)/(e.massTotal*Fu)/.005),c=Math.round(Math.max(0,n)/.25);return ik(s,sk(e,ok(e,t),i,c,Math.round(o/.01),rk(a)),Math.max(0,r),n)}var eo=100,rk=e=>e>0&&Number.isFinite(e)?Math.max(1,Math.round(e*eo)):eo;function nk(e,t){if(t===eo)return e;let r=e.roads.get(t);return r||e.roads.set(t,r={shares:new Map,rooms:new Map}),r}var ek=new WeakMap;function ok(e,t){let r=ek.get(e);r||ek.set(e,r=new WeakMap);let n=r.get(t);return n||r.set(t,n={ev:t,tyres:ki(),shares:new Map,rooms:new Map,speeds:new Map,roads:new Map}),n}var ak=(e,t,r)=>(r*1001+e)*100003+t;function sk(e,t,r,n,o,a=eo){let s=ak(r,n,o),i=nk(t,a),c=a===eo?1:a/eo,l=i.rooms.get(s);if(!l){let u=n*.25,m=o*.01,f=t.speeds.get(n);f||(f={cap:Yr(e,t.ev,u,t.tyres),dragG:-Math.max(0,Ms(e,u).drag)/(e.massTotal*Fu)},t.speeds.set(n,f));let{cap:p}=f,d=Pe(e,m,-r*.005+f.dragG,u),h=Math.abs(m)*e.massTotal*Fu,b=R=>{let[k,v]=R==="front"?["FL","FR"]:["RL","RR"],x=h*(R==="front"?e.frontMassFrac:1-e.frontMassFrac),M=c*(p.peakAt(R,Math.max(0,d[k])).fyPeak+p.peakAt(R,Math.max(0,d[v])).fyPeak),A=x>0&&M>0?Math.min(1,x/M):0;return p.axle(R,d,{FL:A,FR:A,RL:A,RR:A},1/0,c)},g,y;l=(R,k)=>(R==="front"?g??=b("front"):y??=b("rear")).regenRoom(k),i.rooms.size>5e4&&i.rooms.clear(),i.rooms.set(s,l)}return l}function Au(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 ik(e,t,r,n){if(!(r>0))return Au(e,t,1,n);let o=c=>c.front+c.rear,a=e.controlFor(r,n),s=Au(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=Au(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=Au(e,t,l,n);o(u)<r?a=l:(i=l,s=u)}return s}var Pa={rel:.003,abs:2,kappa:1e-5,iters:12},tb={rel:1e-6,abs:.001,kappa:1e-12,iters:40};function to(e,t,r,n=Pa){let o=t>=0?1:-1,a=Math.abs(t),s=Math.max(n.abs,n.rel*a),i=e(0);if(Math.abs(i.Fx)-a>=0)return{kappa:0,forces:i};let c=0,l=i,u=Math.abs(i.Fx)-a,m=Math.min(.3,Math.max(.004,Math.abs(r)||.02)),f=e(o*m),p=Math.abs(f.Fx)-a,d=null;for(;p<0&&m<.3;){let g=Math.min(.3,m*1.9),y=e(o*g),R=Math.abs(y.Fx);if(R<Math.abs(f.Fx)){d={kappa:g,forces:y};break}c=m,l=f,u=p,m=g,f=y,p=R-a}if(p<0){let g=bE(e,o,c,l,m,f,d),y=Math.abs(g.forces.Fx);if(y<a)return{kappa:o*g.kappa,forces:g.forces};m=g.kappa,f=g.forces,p=y-a}let h=f,b=o*m;for(let g=0;g<n.iters&&m-c>n.kappa;g++){let y=p-u,R=Math.abs(y)>1e-12?(c*p-m*u)/y:.5*(c+m);R>c&&R<m||(R=.5*(c+m));let k=e(o*R),v=Math.abs(k.Fx)-a;if(h=k,b=o*R,Math.abs(v)<s)break;v<0?(c=R,u=v,p*=.5):(m=R,p=v,u*=.5)}return{kappa:b,forces:h}}var ck=1e-6,fE=40,hE=(3-Math.sqrt(5))/2;function bE(e,t,r,n,o,a,s){let i=a,c,l,u,m=-Math.abs(a.Fx),f,p,d=-Math.abs(n.Fx);if(s){c=s.kappa;let g=-Math.abs(s.forces.Fx);[l,f,u,p]=g<=d?[c,g,r,d]:[r,d,c,g]}else{c=.3;let g=.3*(1-ck),y=e(t*g),R=-Math.abs(y.Fx);if(R>=m)return{kappa:o,forces:a};[l,f,u,p]=[o,m,r,d],o=g,m=R,i=y}d<m&&([l,f]=[o,m],o=r,m=d,i=n);let h=c-r,b=0;for(let g=0;g<fE;g++){let y=ck*Math.abs(o)+1e-10,R=.5*(r+c);if(Math.abs(o-R)<=2*y-.5*(c-r))break;let k=!0;if(Math.abs(h)>y){let A=(o-l)*(m-p),w=(o-u)*(m-f),T=(o-u)*w-(o-l)*A;w=2*(w-A),w>0&&(T=-T),w=Math.abs(w);let P=h;if(h=b,Math.abs(T)<Math.abs(.5*w*P)&&T>w*(r-o)&&T<w*(c-o)){b=T/w;let S=o+b;(S-r<2*y||c-S<2*y)&&(b=R>=o?y:-y),k=!1}}k&&(h=o>=R?r-o:c-o,b=hE*h);let v=Math.abs(b)>=y?o+b:o+(b>=0?y:-y),x=e(t*v),M=-Math.abs(x.Fx);M<=m?(v>=o?r=o:c=o,u=l,p=f,l=o,f=m,o=v,m=M,i=x):(v<o?r=v:c=v,M<=f||l===o?(u=l,p=f,l=v,f=M):(M<=p||u===o||u===l)&&(u=v,p=M))}return{kappa:o,forces:i}}var Cu=e=>Math.max(2,.003*Math.abs(e)),gE=(e,t)=>Math.max(t.abs,t.rel*Math.abs(e)),rb=.5,yE=.03;function xE(e,t,r,n,o){let a=.5*(e.vx+t.vx),s=v=>{let x=(1+v)*a/e.vx-1,M=(1+v)*a/t.vx-1,A=e.at(x),w=t.at(M);return{kappaM:v,kl:x,kr:M,fl:A,fr:w,g:A.Fx+w.Fx-r}},i=gE(r,o),c=Math.max(-rb,Math.min(rb,n)),l=s(c);if(Math.abs(c)>yE){let v=s(.8*c);(l.g-v.g)/(c-v.kappaM)>0||(l=s(0))}if(Math.abs(l.g)<i)return l;let u=l.g<0?1:-1,m=l,f=l,p=.004,d=l;for(let v=0;v<12;v++){let x=m.kappaM+u*p;if(Math.abs(x)>rb)break;let M=s(x);if(Math.abs(M.g)<i)return M;if(Math.abs(M.g)<Math.abs(d.g)&&(d=M),Math.sign(M.g)!==Math.sign(m.g)){f=M;break}if(u*(M.g-m.g)<=0)return d;m=M,p*=1.9}if(f===l)return d;let h=m,b=f,g=h.g,y=b.g,R=Math.abs(g)<Math.abs(y)?h:b,k=Math.min(1e-7,o.kappa);for(let v=0;v<30&&Math.abs(b.kappaM-h.kappaM)>k;v++){let x=y-g,M=Math.abs(x)>1e-12?(h.kappaM*y-b.kappaM*g)/x:.5*(h.kappaM+b.kappaM),A=Math.min(h.kappaM,b.kappaM),w=Math.max(h.kappaM,b.kappaM);M>A&&M<w||(M=.5*(A+w));let T=s(M);if(R=T,Math.abs(T.g)<i)break;Math.sign(T.g)===Math.sign(g)?(h=T,g=T.g,y*=.5):(b=T,y=T.g,g*=.5)}return R}function lk(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 nb(e,t,r,n,o,a=Pa){let s=xE(e,t,r,o,a),i=s.fr.Fx-s.fl.Fx,c=Ca(n,r);if(Math.abs(i)<=c){let R=r-(s.fl.Fx+s.fr.Fx),k=Math.max(0,Math.abs(R)-Cu(r))/2;return{left:{kappa:s.kl,forces:s.fl,want:s.fl.Fx+R/2,short:k},right:{kappa:s.kr,forces:s.fr,want:s.fr.Fx+R/2,short:k},locked:!0,spoolKappa:s.kappaM}}let l=Math.sign(i),u=r/2-l*c/2,m=r/2+l*c/2,f=to(e.at,u,e.seed||s.kl,a),p=to(t.at,m,t.seed||s.kr,a),d=Math.abs(u-f.forces.Fx)>Cu(u),h=Math.abs(m-p.forces.Fx)>Cu(m),b=Math.max(0,n.preloadN),g=ku(n.tbr);d&&!h?p=to(t.at,lk(f.forces.Fx,l,b,g),p.kappa,a):h&&!d&&(f=to(e.at,lk(p.forces.Fx,-l,b,g),f.kappa,a));let y=(R,k)=>({kappa:R.kappa,forces:R.forces,want:k,short:Math.max(0,Math.abs(k-R.forces.Fx)-Cu(k))});return{left:y(f,u),right:y(p,m),locked:!1,spoolKappa:s.kappaM}}var RE={front:["FL","FR"],rear:["RL","RR"]},vE=Object.freeze({Fx:0,Fy:0,Mz:0});function Tu(e,t,r,n){let o=r;for(let a of["front","rear"]){let[s,i]=RE[a],c=r[s]+r[i],l=Wt(e,a,c);if(!l||!(Ca(l,c)>0))continue;let u=ye(t,a),m=n.alpha[a],f=(a==="front"?e.trackFront:e.trackRear)/2e3,p=n.grip??1,d=y=>R=>u.forces({Fz:y,kappa:R,alpha:m,gamma:0}),h=y=>R=>{let k=u.forces({Fz:y,kappa:R,alpha:m,gamma:0});return{Fx:p*k.Fx,Fy:p*k.Fy,Mz:p*k.Mz}},b=(y,R)=>{let k=Math.max(0,n.Fz[y]);return{at:k>0?p===1?d(k):h(k):()=>vE,vx:Math.max(.05,1-R*n.curvature),seed:0}},g=nb(b(s,f),b(i,-f),c,l,n.seed?.[a]??0);n.seed&&(n.seed[a]=g.spoolKappa),o===r&&(o={...r}),o[s]=g.left.want,o[i]=g.right.want}return o}var Ae=9.81,se=Math.PI/180,kE=8,ME=1e-6,kn=["FL","FR","RL","RR"],Jt=e=>e==="FL"||e==="FR",vn=e=>Jt(e)?"front":"rear";function Si(e,t){let r=ye(e,"front"),n=ye(e,"rear");return r===n?no(r,t):{front:no(r,t),rear:no(n,t)}}function no(e,t){return Xf(e,Math.min(t,Zt(e)))}var Lu=e=>e==="FL"||e==="RL";function Da(e,t,r=0,n,o=0,a=1){let s=t?.axG??0,i=Number.isFinite(t?.tvRearDiffN)?t?.tvRearDiffN:0;if(!(!!s&&Number.isFinite(s))&&!i)return null;let l=e.massTotal*s*Ae,u=s>=0?Math.min(1,Math.max(0,t?.driveFrontFrac??0)):Math.min(.99,Math.max(.01,Ta(e,s,r,n,o,a))),m=l*u/2,f=l*(1-u)/2;return{axG:s,fx:{FL:m,FR:m,RL:f-i/2,RR:f+i/2}}}function ub(e,t,r,n){return Math.abs(oo(e,t,r,n!==void 0?{steerMaxDeg:n}:{}).peak.steerDeg)}function mb(e,t,r,n){let o=e.tv;if(!o?.enabled)return 0;let a=Pk(o)(t,Math.abs(r),n);return r<0?-a:a}function pb(e,t,r=0,n,o=0,a=0,s,i=1){let c=Da(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?Tu(e,n,l,s):l}var Ai=e=>Lu(e)?-1:1,db=(e,t,r,n,o)=>t*e.Fy(t*r,n,t*o);function cb(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 SE(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?ma(o,n/se,u?r.FL:r.FR,u?r.FR:r.FL):pa(o,n/se);return{innerMag:m.innerDeg*se,outerMag:m.outerDeg*se,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)),f=Math.atan(s/(u+a/2));c=n+i*(m-n),l=n+i*(f-n)}return{innerMag:c,outerMag:l,innerCamber:0,outerCamber:0,atLock:!1}}function ao(e,t,r){let n=(e.toeFrontDeg??0)*se,o=(e.toeRearDeg??0)*se,a=SE(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 fb(e,t,r){if(r.Fz<=0)return 0;let n=gt(ye(e,vn(t))),o=Ai(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 uk(e,t,r,n){if(!Xn(e))return null;let o=gt(ye(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:fb(o,s,i)}}return ei(e,r/se,a,hn(o.model),{FL:n.FL.travelMm,FR:n.FR.travelMm})}var mk=()=>({totalNm:[],aligningNm:[],lateralNm:[],longitudinalNm:[],jackingNm:[]});function pk(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 AE=Object.freeze({Fx:0,Fy:0,Mz:0});function dk(e,t,r){let n=t==="front"?(r?.FL??0)+(r?.FR??0):(r?.RL??0)+(r?.RR??0),o=Wt(e,t,n);return o&&Ca(o,n)>0?{F:n,law:o}:null}function _t(e,t,r,n,o,a,s,i,c){let l=s?.fx,u=s?.axG??0,{wb:m,lf:f,lr:p,m:d}=cb(e),h=dk(e,"front",l),b=dk(e,"rear",l),g={front:0,rear:0},y=i!==void 0&&i>0&&Number.isFinite(i)?i:null,R=j=>y===null?r:Math.sqrt(Math.max(0,j)*y),k=gt(ye(t,"front")),v=gt(ye(t,"rear")),x=e.trackFront/2e3,M=e.trackRear/2e3,A=!!(e.kinFront&&e.kinRear),w=A&&y===null?gn(e,e.kinFront,e.kinRear,r):null,T=NaN,P=null,S=j=>{if(!A)return null;if(y===null)return w;let Z=R(j);return Z!==T&&(T=Z,P=gn(e,e.kinFront,e.kinRear,Z)),P},F={},C={FL:0,FR:0,RL:0,RR:0},L=e.kinFront?.compliance,E=e.kinRear?.compliance,D=!!(L||E),N=!!(L?.toePerMz||E?.toePerMz),O=j=>Jt(j)?L:E,z={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}},I=!1,_=j=>{let Z=j/r,re=y===null?n+f*Z/r:n+f/y,oe=y===null?n-p*Z/r:n-p/y,le=S(j),ue=R(j),ie=le?le(j/Ae,u,n/se,o/se):null,fe=ie?{FL:ie.FL.travel,FR:ie.FR.travel}:void 0,Fe=Il(e,j/Ae,u,ue,n/se,o/se,fe,ie?.steeringJacking),we=Fe.loads;I=Fe.overturned;let Re=ao(e,o,fe),me=Re.steer,Ne=0,Ce=xe=>{let ke=Math.max(0,we[xe]),Le=Ai(xe),pe=Jt(xe)?k:v,he=O(xe),Qe=0,ve=0;if(he){let ir=z[xe];Qe=he.toePerFy*ir.fy+he.toePerFx*ir.fx+he.toePerMz*ir.mz,ve=he.camberPerFy*ir.fy+he.camberPerFx*ir.fx}let je=me[xe]+(ie?Le*ie[xe].bumpToe*se:0)+Le*Qe*se,He=je-(Jt(xe)?re:oe),it=(ie?ie[xe].camberRoad:0)*se+Le*(Re.camber[xe]+ve)*se;return{Fz:ke,mir:Le,t:pe,gains:he,complianceToe:Qe,steerK:je,slip:He,camberRad:it}},qe=(xe,ke)=>{let Le=y===null?Z/r:1/y,pe=Jt(xe)?f:-p,he=(Lu(xe)?1:-1)*(Jt(xe)?x:M),Qe=(Math.cos(n)-he*Le)*Math.cos(ke.steerK)+(Math.sin(n)+pe*Le)*Math.sin(ke.steerK);return{at:ke.Fz>0?ve=>ke.t.forces({Fz:ke.Fz,kappa:ve,alpha:ke.mir*ke.slip,gamma:ke.mir*ke.camberRad}):()=>AE,vx:Math.max(.05,Qe),seed:C[xe]}};for(let xe=0;xe<(D?kE:1);xe++){Ne=0;let ke=0,Le={};for(let pe of kn){let he=Jt(pe)?h:b;if(he&&!Le[pe]){let[Uo,$t]=Jt(pe)?["FL","FR"]:["RL","RR"],al=Ce(Uo),fx=Ce($t),hx=vn(pe),ud=nb(qe(Uo,al),qe($t,fx),he.F,he.law,g[hx],tb);g[hx]=ud.spoolKappa,Le[Uo]={w:al,share:ud.left},Le[$t]={w:fx,share:ud.right}}let Qe=Le[pe]?.w??Ce(pe),{Fz:ve,mir:je,t:He,gains:it,complianceToe:ir,steerK:Ho,slip:zo,camberRad:ys}=Qe,xs=l?.[pe]??0,Yo,Wo=0,ld=0,ol=0,jo=Le[pe]?.share;if(jo)C[pe]=jo.kappa,ld=jo.kappa,Wo=jo.forces.Fx,ol=jo.short,Yo=je*jo.forces.Fy;else if(xs===0||ve<=0)Yo=db(He,je,zo,ve,ys),ol=ve<=0?Math.abs(xs):0;else{let $t=to(al=>He.forces({Fz:ve,kappa:al,alpha:je*zo,gamma:je*ys}),xs,C[pe],tb);C[pe]=$t.kappa,ld=$t.kappa,Wo=$t.forces.Fx,ol=Math.max(0,Math.abs(xs-Wo)-Math.max(Pa.abs,Pa.rel*Math.abs(xs))),Yo=je*$t.forces.Fy}if(F[pe]={Fz:ve,travelMm:ie?.[pe].travel??0,steerRad:Ho,slipRad:zo,camberRad:ys,Fy:Yo,Fx:Wo,kappa:ld,fxShort:ol,lifted:Fe.lifted[pe]},it){let Uo=N&&it.toePerMz?fb(He,pe,F[pe]):0;z[pe]={fy:-je*Yo,fx:Wo,mz:-je*Uo*1e3};let $t=z[pe];ke=Math.max(ke,Math.abs(it.toePerFy*$t.fy+it.toePerFx*$t.fx+it.toePerMz*$t.mz-ir))}Ne+=Yo*Math.cos(Ho)+Wo*Math.sin(Ho)}if(ke<ME)break}return Ne/d},B=j=>{let Z=Pe(e,0,u,j,0,o/se);return Z.FL+Z.FR+Z.RL+Z.RR},V=Math.max(20,3.5*B(r)/d);if(y!==null){V=4*Ae;for(let j=0;j<8;j++){let Z=Math.min(40*Ae,3.5*B(R(V))/d);if(Z<=V)break;V=Z}V=Math.max(20,V)}let G=j=>_(j)-j,H=Math.max(.001,V*1e-4),W=(j,Z,re,oe)=>{let le=j,ue=re,ie=Z,fe=oe,Fe=le;for(let we=0;we<40;we++){let Re=fe-ie,me=Math.abs(Re)>1e-12?(le*fe-ue*ie)/Re:.5*(le+ue),Ne=Math.min(le,ue),Ce=Math.max(le,ue);me>Ne&&me<Ce||(me=.5*(le+ue));let qe=G(me);if(Fe=me,Math.abs(qe)<1e-4||Ce-Ne<1e-6)break;qe<0==ie<0?(le=me,ie=qe,fe*=.5):(ue=me,fe=qe,ie*=.5)}return Fe},J=(j,Z,re,oe=!1)=>{let le=(we,Re)=>re>0?we>0&&Re<0:Re>0&&we<0,ue=j,ie=Z,fe=j+re*Math.min(Math.abs(Z),V);if(!oe&&Math.abs(fe-j)>H){let we=G(fe);if(le(ie,we))return{root:W(ue,ie,fe,we),last:ue};ue=fe,ie=we}let Fe=oe?V/24:Math.max(V/24,Math.abs(fe-j)/4);for(let we=1;we<=24;we++){let Re=ue+re*Fe;if(Math.abs(Re)>V)break;let me=G(Re);if(le(ie,me))return{root:W(ue,ie,Re,me),last:ue};if(oe&&me*re<0&&(me-ie)*re<0)break;ue=Re,ie=me}return{root:null,last:ue}},Y=c??null;if(c===void 0&&a!==void 0&&Number.isFinite(a)&&Math.abs(a)<=V){let j=G(a);if(Math.abs(j)<=1e-4)G(a+H)<0&&G(a-H)>0&&(Y=a);else{let Z=J(a,j,Math.sign(j)).root;Y=Z!==null&&(Z===0||Math.sign(Z)===Math.sign(a))?Z:null}}let ee=Y===null;if(Y===null){let j=G(0),Z=G(H),re=Math.abs(j)<=1e-4,oe=re?y!==null?1:o!==0?Math.sign(o):Z>0?1:-1:Math.sign(j),le=re?oe*H:0,ue=re?oe>0?Z:G(-H):j,ie=J(le,ue,oe);Y=ie.root??(re?0:ie.last)}let ne=_(Y);if(ee&&o!==0&&y===null){let j=Math.sign(o);if(Y*j<=0||(F.RL.Fy+F.RR.Fy)*j<0){let Z={...F},re=I,oe=j*Math.max(Y*j+H,n*j*r*r/p),le=null;if(oe*j<V){let ue=G(oe);if(ue*j>0)le=J(oe,ue,j).root;else{let ie=oe+j*V/24,fe=G(ie);(fe-ue)*j>0&&(le=J(ie,fe,j,fe*j<=0).root)}}le!==null&&le*j>0?(Y=le,ne=_(Y)):(Object.assign(F,Z),I=re)}}let de=f*(F.FL.Fy*Math.cos(F.FL.steerRad)+F.FR.Fy*Math.cos(F.FR.steerRad))-p*(F.RL.Fy+F.RR.Fy);if(s||h||b){let j=Z=>(Lu(Z)?1:-1)*(Jt(Z)?x:M);for(let Z of kn){let re=F[Z],oe=Jt(Z)?f:-p;de+=oe*re.Fx*Math.sin(re.steerRad)-j(Z)*re.Fx*Math.cos(re.steerRad)}}return y!==null&&Y<-1e-6?{ay:NaN,cn:NaN,wheels:F,overturned:I,res:NaN}:{ay:Y/Ae,cn:de/(d*Ae*m),wheels:F,overturned:I,res:ne-Y}}function FE(e,t,r,n,o,a,s,i=0){let c=20*se,l=.001,u=(h,b)=>{let g=_t(e,t,r,h,n,b,s);return{cn:g.cn-i,ay:g.ay*Ae}},m=h=>n===0||i!==0||Math.abs(h)<.05||Math.sign(h)===Math.sign(n),f=(h,b,g,y)=>{let R=u(h,y);if(Math.abs(R.cn)<1e-5)return{beta:h,trimmed:!0};let k=y===void 0?void 0:R.ay,v={pos:{b:h,cn:R.cn,ay:k},neg:{b:h,cn:R.cn,ay:k}},x=null,M=h,A=Math.abs(R.cn);for(let w=0;w<b.length&&!x;w++)for(let T of[v.pos,v.neg]){let P=T===v.pos?1:-1,S=h+P*b[w];if(Math.abs(S)>c)continue;let F=u(S,T.ay);if(Math.abs(F.cn)<A&&m(F.ay)&&(A=Math.abs(F.cn),M=S),F.cn===0&&m(F.ay))return{beta:S,trimmed:!0};if(F.cn<0!=T.cn<0){let C={lo:T.b,hi:S,ayLo:T.ay},L=fk(u,C),E=u(L,T.ay);if(Math.abs(E.cn)<l&&m(E.ay))return x=C,{beta:L,trimmed:!0}}T.b=S,T.cn=F.cn,y!==void 0&&(T.ay=F.ay)}return x?{beta:fk(u,x),trimmed:!0}:g?{beta:M,trimmed:!1}:null},p=[.25,.75,2,5].map(h=>h*se);if(o!==void 0&&Number.isFinite(o)&&Math.abs(o)<=c){let h=f(o,p,!1,a);if(h)return h;if(!s&&i===0&&a!==void 0&&Number.isFinite(a)){let b=wE(e,t,r,n,o,a,c);if(b&&m(b.ay))return{beta:b.beta,trimmed:!0,ay:b.ay}}}let d=[1,3,7,15,20].map(h=>h*se).filter(h=>h<=c);return f(0,d,!0)??{beta:0,trimmed:!1}}function fk(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),f=m.cn;if(o!==void 0&&(o=m.ay),i=u,Math.abs(f)<1e-5||Math.abs(n-r)<1e-5)break;f<0==a<0?(r=u,a=f,s*=.5):(n=u,s=f,a*=.5)}return i}function wE(e,t,r,n,o,a,s){let i=(f,p)=>{let d=_t(e,t,r,f,n,void 0,null,void 0,p);return{r:d.res,c:d.cn}},c=o,l=a,u=i(c,l),m=0;for(let f=0;f<CE;f++){let p=i(c+ob,l),d=i(c,l+ab),h=(p.r-u.r)/ob,b=(d.r-u.r)/ab,g=(p.c-u.c)/ob,y=(d.c-u.c)/ab,R=h*y-b*g;if(!Number.isFinite(R)||R===0||Math.abs(R)<DE*(Math.abs(h*y)+Math.abs(b*g)))return null;if(f===0)m=Math.sign(R);else if(Math.sign(R)!==m)return null;if(Math.abs(u.r)<=1e-4&&Math.abs(u.c)<=1e-5)return{beta:c,ay:l};let k=(u.c*b-u.r*y)/R,v=(u.r*g-u.c*h)/R,x=Math.min(1,TE/Math.max(Math.abs(k),1e-300),PE/Math.max(Math.abs(v),1e-300));if(c+=x*k,l+=x*v,Math.abs(c-o)>LE||Math.abs(c)>s||l*a<0)return null;u=i(c,l)}return null}var CE=8,ob=1e-5,ab=.001,TE=1*se,PE=2,LE=5*se,DE=.5;function vk(e,t,r,n,o,a,s,i){let c=_t(e,t,r,n,o,a,s,void 0,i),l=c.ay*Ae/r,u={},m=0;for(let d of kn){let h=c.wheels[d],b=ye(t,vn(d)),g=Zt(b),y=b.muY(Math.min(h.Fz,g)),R=b.muX(Math.min(h.Fz,g));m+=h.fxShort,u[d]={Fz:h.Fz,steerDeg:h.steerRad/se,slipDeg:h.slipRad/se,camberDeg:h.camberRad/se,Fy:h.Fy,Fx:h.Fx,Mz:fb(b,d,h),gripUtil:y*h.Fz>0?Math.hypot(h.Fy/(y*h.Fz),R*h.Fz>0?h.Fx/(R*h.Fz):0):0,...h.Fz>g?{pastTurnover:!0}:{},lifted:h.lifted}}let f=ei(e,o/se,u,hn(ye(t,"front").model),{FL:c.wheels.FL.travelMm,FR:c.wheels.FR.travelMm}),p=ao(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/se,yawRate:l*180/Math.PI,steerDeg:o/se,...p.atLock?{lockDeg:(p.steer.FL+p.steer.FR)/2/se}:{},converged:!0,trimmed:!c.overturned,overturned:c.overturned,driving:!1,fxShortfall:m,...f?{steering:f}:{}}}function jr(e,t,r,n,o,a,s=0){let i=Math.max(8,r),c=ro(e,t,i,n,o,a,s);return n!==0&&o?.driving===void 0&&(c.driving=jE(e,t,i,c,a,s)),c}function ro(e,t,r,n,o,a,s){let i=n*se,c=Da(e,a,r,t),l=o&&Number.isFinite(o.ay)?o.ay*Ae:void 0,u=o&&Number.isFinite(o.beta)?o.beta*se:void 0,{beta:m,trimmed:f,ay:p}=FE(e,t,r,i,u,l,c,s),d=vk(e,t,r,m,i,l,c,p),h={...d,trimmed:f&&!d.overturned};return h.driving=n===0?h.trimmed:o?.driving!==void 0&&o.driving&&h.trimmed&&Math.abs(h.beta-o.beta)<=EE,h}var EE=3;function oo(e,t,r,n={}){let o=Math.max(8,r),a=n.direction??1,s=n.yawDemandCn??0,i=n.steerMaxDeg??IE,c=typeof n.op=="function"?n.op:()=>n.op,l=typeof n.op=="function"?null:`${o}|${a}|${s}|${i}|${n.op?`${n.op.axG}|${n.op.driveFrontFrac??""}|${n.op.tvRearDiffN??""}`:""}`;if(l!==null){let x=sb.get(e)?.get(t)?.get(l);if(x)return x}let u=(x,M)=>M.trimmed&&Math.abs(M.beta-x.beta)<=Du&&Math.abs(M.ay-x.ay)*Ae<=Eu,m=!1,f=(x,M)=>{let A=ro(e,t,o,a*x,M,c(a*x),s);return u(M,A)?(A.driving=!0,A):(m=A.overturned,null)},p=[ro(e,t,o,0,void 0,c(0),s)],d=null,h=!1,b,g=x=>{let M=p.length-1;for(;M>1&&x.sb*(p[M].beta-p[M-1].beta)>=0;)M--;let A=a*(x.state.ay-p[M].ay)>0,w=T=>x.sb*(T.beta-x.state.beta)>0||a*T.steerDeg>=a*x.state.steerDeg||A&&a*T.ay>=a*x.state.ay;for(;p.length>Math.max(2,M)&&w(p[p.length-1]);)p.pop();b={state:x.state,stall:p[p.length-1]},p.push(x.state),d=Math.abs(x.state.steerDeg)},y=(x,M=!1)=>M||zE(p[p.length-1],x)?YE(e,t,o,a,p,x,c,s):null,R=p[0].trimmed?p[0]:null;if(!R){let x=0;for(let M=hk;M<=i&&!R;M+=hk){let A=ro(e,t,o,a*M,void 0,c(a*M),s);if(A.trimmed){let w=M;R=A;for(let T=0;T<6;T++){let P=.5*(x+w),S=ro(e,t,o,a*P,void 0,c(a*P),s);S.trimmed?(w=P,R=S):x=P}}else x=M}R&&(R.driving=!0,p.push(R))}if(R){let x=Math.abs(R.steerDeg),M=Math.min(ib,100/(o*o)),A=R;for(;x<i;){let w=Math.min(i,x+M),T=f(w,A);if(T){let L=y(T);if(L){g(L);break}if(p.push(T),w>=i||Tk(e,a*w))break;Math.abs(T.beta-A.beta)<.5*Du&&Math.abs(T.ay-A.ay)*Ae<.5*Eu&&(M=Math.min(ib,1.5*M)),x=w,A=T;continue}if(M>_E){M*=.5;continue}let P=m,S=!1,F=null;for(let L of NE){let E=Math.min(i,x+L);if(E<=x)continue;let D=f(E,A);if(D){if(F=y(D,!0),F)break;p.push(D),x=E,A=D,M=Math.min(ib,100/(o*o)),S=!0;break}}if(S)continue;if(F){g(F);break}d=x,h=P;let C=P?null:HE(e,t,o,a,p,c,s);C&&g(C);break}}else d=0;let k=p[0];for(let x of p)a*x.ay>a*k.ay&&(k=x);let v={states:p,foldDeg:d,rollover:h,peak:k,...b?{fold:b}:{}};if(l!==null){let x=sb.get(e);x||(x=new WeakMap,sb.set(e,x));let M=x.get(t);M||(M=new Map,x.set(t,M)),M.size>256&&M.clear(),M.set(l,v)}return v}var sb=new WeakMap,IE=90,Du=1.5,Eu=2.5,ib=5,_E=.002,NE=[.5,1],hk=2.5,kk=.01,Wr=.001,OE=.05,VE=.25,BE=5,$E=2,bk=1e-8,GE=1e-7,KE=1e-6;function Mk(e,t,r,n,o,a,s){let i=n*se,c=o.ay*Ae,l=b=>{let g=_t(e,t,r,i,b*se,c,Da(e,a(b),r,t));return{g:g.cn-s,ay:g.ay}},u=o.steerDeg,m=l(u),f=u+(u<0?-.001:.001),p=l(f),d=()=>p.g===0||Math.abs(f-u)<bk;for(let b=0;b<40&&Math.sign(m.g)===Math.sign(p.g)&&!d();b++){let g=(p.g-m.g)/(f-u),y=g!==0?f-p.g/g:f+2*(f-u);if(!Number.isFinite(y))return null;let R=2*Math.abs(f-u)+.001;if(y=f+Math.max(-R,Math.min(R,y-f)),u=f,m=p,f=y,p=l(f),Math.abs(f-o.steerDeg)>$E)return null}let h={x:f,ay:p.ay};if(Math.sign(m.g)!==Math.sign(p.g)){let b=u,g=m.g,y=f,R=p.g;for(let k=0;k<60&&R!==0&&Math.abs(y-b)>bk;k++){let v=(b*R-y*g)/(R-g),x=l(v);if(h={x:v,ay:x.ay},x.g===0)break;Math.sign(x.g)===Math.sign(g)?(b=v,g=x.g,R*=.5):(y=v,R=x.g,g*=.5)}}else if(!d())return null;return Math.abs(h.ay-o.ay)*Ae>Eu?null:{steerDeg:h.x,ay:h.ay}}function Mi(e,t,r,n,o){let a=vk(e,t,r,n.beta*se,n.steerDeg*se,n.ay*Ae,Da(e,o(n.steerDeg),r,t));return{...a,trimmed:!a.overturned,driving:!a.overturned}}function HE(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 f=Sk(e,t,r,a,s),p=f(u.beta,u),d=f(c.beta,c);if(!p||!d)return null;let h=n*d.steerDeg>=n*p.steerDeg,b=h?p:d,g=h?d:p,y=h?m:-m,R=null;for(let x=kk;Math.abs(g.beta-c.beta)<=Du;x*=1.5){let M=f(g.beta+y*x);if(!M)return null;if(n*M.steerDeg<=n*g.steerDeg){R=M;break}b=g,g=M}if(!R)return null;let k=Ak(f,n,b,g,R);if(!k)return null;let v=Mi(e,t,r,k,a);return!v.trimmed||Math.abs(v.beta-c.beta)>Du||Math.abs(v.ay-c.ay)*Ae>Eu?null:{state:v,sb:m}}function Sk(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=Mk(e,t,r,s,i,n,o);if(!c)return null;let l={beta:s,...c};return a.push(l),l}}function zE(e,t){let r=Math.abs(t.beta-e.beta);return r>VE&&r>BE*Math.abs(t.steerDeg-e.steerDeg)}function YE(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],f=Math.sign(a.beta-l.beta);if(f===0||Math.sign(l.beta-m.beta)!==f||!m.driving)return null;let p=Sk(e,t,r,s,i),d=p(m.beta,m),h=p(l.beta,l);if(!d||!h||n*h.steerDeg<n*d.steerDeg)return null;let b=d,g=h,y=null;for(let R=kk;f*(a.beta-g.beta)>0;R=Math.min(OE,1.5*R)){let k=p(f*(a.beta-g.beta)>R?g.beta+f*R:a.beta);if(!k)return null;let v=n*k.steerDeg<=n*g.steerDeg;if(!y)v&&(y=[b,g,k]);else if(!v){let x=Ak(p,n,...y);if(!x)return null;let M=Mi(e,t,r,x,s);return M.trimmed?{state:M,sb:f}:null}b=g,g=k}return null}function Ak(e,t,r,n,o){let a=p=>-t*p.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,f=0;for(let p=0;p<100;p++){let d=.5*(s+i);if(Math.abs(c.beta-d)<=2*Wr-.5*(i-s))break;let h=!0;if(Math.abs(m)>Wr){let g=(c.beta-l.beta)*(a(c)-a(u)),y=(c.beta-u.beta)*(a(c)-a(l)),R=(c.beta-u.beta)*y-(c.beta-l.beta)*g;y=2*(y-g),y>0&&(R=-R),y=Math.abs(y);let k=m;if(m=f,Math.abs(R)<Math.abs(.5*y*k)&&R>y*(s-c.beta)&&R<y*(i-c.beta)){f=R/y;let v=c.beta+f;(v-s<2*Wr||i-v<2*Wr)&&(f=d>=c.beta?Wr:-Wr),h=!1}}h&&(m=c.beta>=d?s-c.beta:i-c.beta,f=wk*m);let b=e(Math.abs(f)>=Wr?c.beta+f:c.beta+(f>=0?Wr:-Wr));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 hb(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],f=u[u.length-1],p=l(m),d=l(f);if(p>0||d<0)return null;if(d===0)return Mi(e,t,r,f,i);let h=m;for(let b=0;b<60&&Math.abs(f.beta-m.beta)>1e-9;b++){let g=(m.beta*d-f.beta*p)/(d-p),y=u[0];for(let x of u)Math.abs(x.beta-g)<Math.abs(y.beta-g)&&(y=x);let R=Mk(e,t,r,g,y,i,c);if(!R)return null;let k={beta:g,...R};u.push(k),h=k;let v=l(k);if(Math.abs(v)<("steerDeg"in a?GE:KE))break;v<0?(m=k,p=v,d*=.5):(f=k,d=v,p*=.5)}return Mi(e,t,r,h,i)}function WE(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 hb(e,t,r,n.fold,a,{steerDeg:o});let u=typeof a.op=="function"?a.op(o):a.op,m=ro(e,t,r,o,l,u,a.yawDemandCn??0);return m.driving?m:null}function jE(e,t,r,n,o,a){if(!n.trimmed)return!1;let s=n.steerDeg<0?-1:1,{states:i}=oo(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)],f=Math.abs(m.steerDeg)-Math.abs(u.steerDeg),p=f>0?Math.min(1,Math.max(0,(c-Math.abs(u.steerDeg))/f)):0,d=u.beta+p*(m.beta-u.beta),h=u.ay+p*(m.ay-u.ay);return Math.abs(n.beta-d)<=1&&Math.abs(n.ay-h)<=.05}function Mn(e,t,r,n,o){let a=Math.max(8,r),s=n>=0?1:-1,i=Math.abs(n),c=(b,g)=>jr(e,t,a,s*b,g,o),l=oo(e,t,a,{direction:s,op:o}),{fold:u}=l;if(u&&Math.abs(u.state.steerDeg)<=La){if(i>Math.abs(u.state.ay))return yk(e,t,a,s,i,o);if(i>Math.abs(u.stall.ay)){let b=hb(e,t,a,u,{direction:s,op:o},{ayG:i});if(b)return b}}let m=l.states.filter(b=>Math.abs(b.steerDeg)<=La),f=m[m.length-1],p=l.states.length>m.length;p&&Math.abs(f.steerDeg)<La&&m.push(c(La,f));let d=m.findIndex(b=>Math.abs(b.ay)>=i);if(d===0)return jr(e,t,a,0,void 0,o);if(d>0)return gk(m[d-1],m[d],i,c);let h=Fk(m,c,void 0,p||l.foldDeg===null);return h.ay>=i?gk(h.below,h.state,i,c):l.foldDeg!==null&&l.foldDeg<La?yk(e,t,a,s,i,o):h.state}var La=20;function gk(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 f=a.f===o.f?.5*(o.steer+a.steer):o.steer-o.f*(a.steer-o.steer)/(a.f-o.f),p=n(f,i),d=Math.abs(p.ay)-r;if(Math.abs(d)<u&&(l=p,u=Math.abs(d)),Math.abs(d)<=UE||a.steer-o.steer<=XE)break;d<0?(o={steer:f,f:d},c===-1&&(a.f*=.5),c=-1):(a={steer:f,f:d},c===1&&(o.f*=.5),c=1)}return l}var UE=1e-9,XE=1e-7;function Fk(e,t,r,n=!1){let o=r??0;if(r===void 0)for(let x=1;x<e.length;x++)Math.abs(e[x].ay)>Math.abs(e[o].ay)&&(o=x);let a=e[Math.max(0,o-1)],s=Math.abs(e[o].steerDeg),i=qE/4,c,l,u,m,f,p,d,h,b=null,g;if(o>0&&o<e.length-1){let x=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(x.steerDeg),u=s,m=-Math.abs(e[o].ay);let[M,A]=Math.abs(a.ay)>=Math.abs(x.ay)?[a,x]:[x,a];f=Math.abs(M.steerDeg),p=-Math.abs(M.ay),d=Math.abs(A.steerDeg),h=-Math.abs(A.ay)}else{let x=Math.abs(e[o].lockDeg??e[o].steerDeg),M=x-QE,A=o>0&&n&&M>Math.abs(a.steerDeg)?t(M,a):null;if(!A||Math.abs(A.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=x,u=M,m=-Math.abs(A.ay),b=A,f=x,p=-Math.abs(e[o].ay),d=c,h=-Math.abs(a.ay)}let y=l-c,R=0;for(let x=0;x<100;x++){let M=.5*(c+l);if(Math.abs(u-M)<=2*i-.5*(l-c))break;let A=!0;if(Math.abs(y)>i){let S=(u-f)*(m-h),F=(u-d)*(m-p),C=(u-d)*F-(u-f)*S;F=2*(F-S),F>0&&(C=-C),F=Math.abs(F);let L=y;if(y=R,Math.abs(C)<Math.abs(.5*F*L)&&C>F*(c-u)&&C<F*(l-u)){R=C/F;let E=u+R;(E-c<2*i||l-E<2*i)&&(R=M>=u?i:-i),A=!1}}A&&(y=u>=M?c-u:l-u,R=wk*y);let w=Math.abs(R)>=i?u+R:u+(R>=0?i:-i),T=g(w),P=-Math.abs(T.ay);P<=m?(w>=u?c=u:l=u,d=f,h=p,f=u,p=m,u=w,m=P,b=T):(w<u?c=w:l=w,P<=p||f===u?(d=f,h=p,f=w,p=P):(P<=h||d===u||d===f)&&(d=w,h=P))}let k=b??t(s,a),v=Math.abs(k.steerDeg)>s?e[o]:a;return{state:k,below:v,ay:Math.abs(k.ay)}}var qE=.001,QE=.01,wk=(3-Math.sqrt(5))/2;function yk(e,t,r,n,o,a){let s=l=>Math.abs(jr(e,t,r,n*l,void 0,a).ay),i=0,c=La;if(s(c)<o)return jr(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 jr(e,t,r,n*.5*(i+c),void 0,a)}function bb(e,t,r,n,o){let a=Mn(e,t,r,n,o);return a.steering?Math.abs(a.steering.totalNm):NaN}function gb(e,t,r,n,o){if(!Xn(e))return NaN;let a=n<0?-1:1,s=Math.abs(n),i=Mn(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,f=jr(e,t,r,a*u,void 0,o),p=jr(e,t,r,a*m,void 0,o),d=f.steering?Math.abs(f.steering.totalNm):NaN,h=p.steering?Math.abs(p.steering.totalNm):NaN,b=Math.abs(p.ay)-Math.abs(f.ay);if(Number.isFinite(d)&&Number.isFinite(h)&&b>=.01||l===.4&&Number.isFinite(d)&&Number.isFinite(h)&&b>.001)return(h-d)/b}return NaN}function lb(e,t,r,n,o,a){let s=Math.max(8,r),i=_t(e,t,s,n*se,o*se,void 0,Da(e,a,s,t));return{ay:i.ay,cn:i.cn}}function yb(e,t,r,n,o){let a=Math.max(8,r),s=Mn(e,t,a,n,o),i=.5,c=lb(e,t,a,s.beta+i,s.steerDeg,o).cn,l=lb(e,t,a,s.beta-i,s.steerDeg,o).cn;return(c-l)/(2*i*se)*e.massTotal*Ae*(e.wheelbase/1e3)}function xb(e,t,r,n){let o=Math.max(8,r),{branch:a,opts:s}=ZE(e,t,o,n);return Ck(e,t,o,a,s)}function ZE(e,t,r,n){if(!e.tv?.enabled){let s=n?{op:n}:{};return{branch:oo(e,t,r,s),opts:s}}let o=ub(e,t,r),a={op:s=>{let i=mb(e,r,s,o);return i===0?n:{axG:n?.axG??0,driveFrontFrac:n?.driveFrontFrac,tvRearDiffN:i}}};return{branch:oo(e,t,r,a),opts:a}}function Ck(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 Mi(e,t,r,n.peak,a);let i=(l,u)=>ro(e,t,r,l,u,a(l),s),c=n.states[0].driving||!n.peak.driving?n.states:n.states.slice(1);return Fk(c,i,c.indexOf(n.peak),n.foldDeg===null).state}function Rb(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(Ae*o)),s=(n.betaMaxDeg??10)*se,i=(n.deltaMaxDeg??10)*se,[c,l]=n.betaRangeDeg?[n.betaRangeDeg[0]*se,n.betaRangeDeg[1]*se]:[-s,s],[u,m]=n.deltaRangeDeg?[n.deltaRangeDeg[0]*se,n.deltaRangeDeg[1]*se]:[-i,i],{lf:f,lr:p}=cb(e),d=o===void 0?0:p/o,h=o===void 0?0:(f+p)/o,b=n.nLines??9,g=n.nPts??21,y=n.steering!==!1&&Xn(e),R=y?hn(ye(t,"front").model):void 0,k=(I,_,B,V)=>B===1?I:I+(_-I)*V/(B-1),v=e.tv?.enabled?ub(e,t,a):0,x=I=>{let _=mb(e,a,I/se,v);return!n.axG&&_===0?null:Da(e,{axG:n.axG??0,driveFrontFrac:n.driveFrontFrac,tvRearDiffN:_},a,t)},{lf:M,lr:A}=cb(e),w=n.reserves?Si(t,e.massTotal*Ae*1.2):null,T=I=>w?Ir(w,{FL:I.FL,FR:I.FR,RL:I.RL,RR:I.RR},{lf:M,lr:A}):null,P=[],S={ay:[],cn:[]},F=0;for(let I=0;I<b;I++){let _=k(u,m,b,I),B=x(_),V=[],G=[],H=[],W=[],J=w?{stabil:[],agil:[]}:void 0,Y=y?mk():void 0,ee;for(let j=0;j<g;j++){let Z=k(c,l,g,j),re=_t(e,t,a,Z,_,ee,B,o);if(ee=Number.isFinite(re.ay)?re.ay*Ae:void 0,V.push(re.ay),G.push(re.cn),H.push(Z/se),W.push(_/se),J){let oe=T(re.wheels);J.stabil.push(oe.stabil),J.agil.push(oe.agil)}Y&&pk(Y,uk(e,t,_,re.wheels)),Math.abs(re.ay)>F&&(F=Math.abs(re.ay))}P.push({label:`\u03B4 ${(_/se).toFixed(0)}\xB0`,ay:V,cn:G,betaDeg:H,deltaDeg:W,reserve:J,steering:Y});let ne=null,de=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 Z=G[j-1]===G[j]?0:G[j-1]/(G[j-1]-G[j]),re=V[j-1]+Z*(V[j]-V[j-1]);if(o===void 0&&_!==0&&Math.abs(re)>=.05&&Math.sign(re)!==Math.sign(_))continue;let oe=Math.abs(H[j-1]+Z*(H[j]-H[j-1])-d/se);oe<de&&(de=oe,ne=re)}ne!==null&&(S.ay.push(ne),S.cn.push(0))}let C=[];for(let I=0;I<b;I++){let _=k(c,l,b,I),B=[],V=[],G=[],H=[],W=w?{stabil:[],agil:[]}:void 0,J=y?mk():void 0,Y;for(let ee=0;ee<g;ee++){let ne=k(u,m,g,ee),de=_t(e,t,a,_,ne,Y,x(ne),o);if(Y=Number.isFinite(de.ay)?de.ay*Ae:void 0,B.push(de.ay),V.push(de.cn),G.push(_/se),H.push(ne/se),W){let j=T(de.wheels);W.stabil.push(j.stabil),W.agil.push(j.agil)}J&&pk(J,uk(e,t,ne,de.wheels))}C.push({label:`\u03B2 ${(_/se).toFixed(0)}\xB0`,ay:B,cn:V,betaDeg:G,deltaDeg:H,reserve:W,steering:J})}let L=.5*se,E=x(h),D,N;if(o===void 0)D=(_t(e,t,a,d+L,h,void 0,E,o).cn-_t(e,t,a,d-L,h,void 0,E,o).cn)/(2*L),N=(_t(e,t,a,d,h+L,void 0,x(h+L),o).cn-_t(e,t,a,d,h-L,void 0,x(h-L),o).cn)/(2*L);else{let I=(V,G)=>_t(e,t,a,V,G,void 0,x(G),o).cn,_=(V,G,H)=>Number.isFinite(V)?(-3*V+4*G-H)/(2*L):(H-G)/L,B=I(d,h);D=-_(B,I(d-L,h),I(d-2*L,h)),N=_(B,I(d,h+L),I(d,h+2*L))}let O=0;if(E&&E.axG){let I=_t(e,t,a,d,h,void 0,E,o),_=0;for(let B of kn)_+=I.wheels[B].fxShort;O=_/Math.abs(e.massTotal*E.axG*Ae)}let z=S.ay.reduce((I,_)=>Math.max(I,Math.abs(_)),0);return{isoBeta:C,isoDelta:P,trim:S,maxAy:F,stability:D,control:N,speed:o===void 0?a:Math.sqrt(z*Ae*o),...o!==void 0?{radius:o}:{},axG:E?.axG??0,axShortfall:O,...R?{steeringAligningSource:R}:{}}}function Tk(e,t){return ao(e,t*se).atLock}function JE(e,t,r,n,o=Yr(e,t,r)){let a=r,s=e.massTotal,i=kn.filter(g=>Jt(g)?n.drivenFront:n.drivenRear),c=o.peakAt,l={front:n.drivenFront?Wt(e,"front",1):void 0,rear:n.drivenRear?Wt(e,"rear",1):void 0},u=new Map,m=(g,y)=>{let R=`${g}:${y}`,k=u.get(R);if(k===void 0){let v=Math.max(1,y*vi);k=Dt(ye(t,g),v,0,!1,c(g,v)),u.set(R,k)}return k},f=(g,y)=>y>0?Ri(y,R=>m(g,R)):0,p=(g,y,R,k)=>{let v=ye(t,g),x=E=>{let D=Math.max(0,R[E]),N=c(g,D);return{Fz:D,a:f(g,D),b:N.fyPeak,slide:0,cap:O=>D>0?Dt(v,D,O,!1,N):0}},[M,A]=g==="front"?["FL","FR"]:["RL","RR"],w=x(M),T=x(A),P=k[M]*w.b,S=k[A]*T.b,F=w.cap(P)+T.cap(S),C=xi(w,T,P+S,y,F);return{l:M,r:A,full:C,asHeld:()=>({axle:g,strong:w.cap(P)>=T.cap(S)?M:A,full:C,open:xi(w,T,P+S,wa,F),sense:1})}},d=g=>({muX:y=>y>0?f(g,y)/y:0,muY:y=>y>0?c(g,y).fyPeak/y:0}),h={front:d("front"),rear:d("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,R,k=0)=>{let v={FL:0,FR:0,RL:0,RR:0},x=Pe(e,g,0,a,0,y),M,A=C=>(M?.ax!==C&&(M={ax:C,loads:Pe(e,g,(C+k)/Ae,a,0,y)}),M.loads),w=Ol(C=>ha(R,A(C),x,c).short,-k,1),T=R,P=C=>{let L=w.at(C);v=A(L),T=ha(R,v,x,c).util;let E=0,D=n.diffYaw?{fx:{FL:0,FR:0,RL:0,RR:0},axles:[]}:null;for(let N of i){let O=l[vn(N)];if(O){if(Lu(N)){let B=p(vn(N),O,v,T);E+=B.full,D&&(D.fx[B.l]=D.fx[B.r]=B.full/2,D.axles.push(B.asHeld()))}continue}let z=Math.max(0,v[N]),I=c(vn(N),z),_=Dt(ye(t,vn(N)),z,T[N]*I.fyPeak,!1,I);E+=_,D&&(D.fx[N]=_)}if(D){let N={};for(let O of kn){let z=Math.max(0,v[O]);N[O]={Fz:z,Fy:T[O]*c(vn(O),z).fyPeak,Fx:D.fx[O]}}for(let O of D.axles)E+=nu(O,N,h,b(g))-O.full}return E/s},S=U1(P,-k,Rn).fx,F=w.edge();return F!==void 0&&S>F&&(S=F,P(S)),{ax:S,loads:v}}}}var Pu=.05,xk=.001,Rk=16,Iu=8;function vb(e,t,r,n){let o=Math.max(Iu,r),a=n.nSteer??7,s=e.tv?.enabled?ub(e,t,o,n.steerMaxDeg):0,i=I=>{let _=mb(e,o,I,s);return _===0?void 0:{axG:0,tvRearDiffN:_}},c=n.yawDemandCn??0,l={op:i,yawDemandCn:c,...n.steerMaxDeg!==void 0?{steerMaxDeg:n.steerMaxDeg}:{}},u=oo(e,t,o,l),m=I=>{let _={},B={};for(let V of kn)_[V]=I.wheels[V].slipDeg*se,B[V]=Math.min(1,I.wheels[V].gripUtil);return{steerDeg:I.steerDeg,ayMs:Math.max(0,I.ay*Ae),ayG:I.ay,slip:_,util:B,scrub:I.ay>0?eI(I,e.massTotal):0}},f=null,p=I=>{if(f&&I===f.steerDeg)return m(f);let _=WE(e,t,o,u,I,l);if(_)return m(_);let B=u.states[0];for(let V of u.states)V.steerDeg<=I&&(B=V);return m(B)},d=u.peak.driving&&u.peak.ay>0?Ck(e,t,o,u,l):null,h=d?Math.max(0,d.ay*Ae):0,b=d?[...u.states.filter(I=>I.steerDeg<d.steerDeg),d]:u.states,g=d?b.findIndex(I=>I.ay*Ae>=.995*h):0,y=b[g].steerDeg,{fold:R}=u;if(d&&R&&u.peak===R.state){let I=.995*h/Ae,_=u.states.indexOf(R.stall),B=_-1;for(;B>0&&u.states[B].beta===R.stall.beta;)B--;let V=Math.sign(R.stall.beta-u.states[B].beta),G=_;for(;G>0&&u.states[G].ay>=I&&Math.sign(u.states[G].beta-u.states[G-1].beta)!==-V;)G--;u.states[G].ay<I&&(f=hb(e,t,o,R,l,{ayG:I},u.states.slice(G,_+1)))}if(f)y=f.steerDeg;else if(g>0){let I=b[g-1].steerDeg,_=y;for(let B=0;B<8&&_-I>.001;B++){let V=.5*(I+_);p(V).ayMs>=.995*h?_=V:I=V}y=_}let k=[];for(let I=0;I<(h>0?a:1);I++){let _=I/(a-1);k.push(p(y*(_+Math.sin(Math.PI/2*_))/2))}k[0].ayMs=0;let v=[],x=[],M=[],A=[],w=Yr(e,t,o,void 0,n.diffYaw===!0),T=JE(e,t,o,n,w),P=n.axDrag??0,S=I=>{let _=w.limitAt(I.ayMs/Ae,I.steerDeg,I.util,P+I.scrub);return{axD:_.edge!==void 0&&_.edge>0?_.edge:_.ax,locked:_.axUnlocked-_.ax>Pu}},F=I=>T.limitAt(I.ayMs/Ae,I.steerDeg,I.util,P+I.scrub).ax,C=k.map(I=>({p:I,axA:F(I),...S(I)})),L=[];for(let I=0;I+1<C.length;I++){let _=C[I],B=C[I+1],V=[];_.locked!==B.locked?V.push({read:S,past:G=>G.locked===B.locked,braking:!0}):(B.axA>_.axA+Pu&&V.push({read:G=>({axA:F(G)}),past:G=>(G.axA??-1/0)>_.axA}),-B.axD>-_.axD+Pu&&V.push({read:S,past:G=>-(G.axD??0)>-_.axD}));for(let{read:G,past:H,braking:W}of V){let J=_.p.steerDeg,Y=B.p.steerDeg,ee=null,ne=_.axD,de=B.axD;for(let j=0;j<Rk&&Y-J>xk&&!(W&&Math.abs(de-ne)<=Pu);j++){let Z=.5*(J+Y),re=p(Z),oe=G(re);H(oe)?(Y=Z,ee={p:re,r:oe},de=oe.axD??de):(J=Z,ne=oe.axD??ne)}if(ee){let{p:j,r:Z}=ee,re=Z.axD!==void 0&&Z.locked!==void 0?{axD:Z.axD,locked:Z.locked}:S(j);L.push({p:j,axA:Z.axA??F(j),...re})}}}C.push(...L),C.sort((I,_)=>I.p.steerDeg-_.p.steerDeg);let E=I=>I.axA+P+I.p.scrub,D=.001*Math.max(1,k[k.length-1].ayMs),N=[];for(let I=0;I+1<C.length;I++){let _=C[I],B=C[I+1];if(!(E(_)>=0&&E(B)<0))continue;let V=_.p.steerDeg,G=B.p.steerDeg,H=null,W=null;for(let Y=0;Y<Rk&&G-V>xk;Y++){let ee=.5*(V+G),ne=p(ee);E({p:ne,axA:F(ne)})>=0?(V=ee,H=ne):(G=ee,W=ne)}let J=H??W;J&&J.ayMs>_.p.ayMs&&J.ayMs<B.p.ayMs&&N.push({p:J,axA:-(P+J.scrub),steady:!0,...S(J)})}C.push(...N),C.sort((I,_)=>I.p.steerDeg-_.p.steerDeg);let O=!1;for(let{p:I,axA:_,axD:B,steady:V}of C){let G=v.length-1,H=G>=0&&(V||O?!(I.ayMs>v[G]):I.ayMs-v[G]<D);O=V===!0&&!H,H?(x[G]=Math.max(x[G],_),M[G]=Math.min(M[G],B)):(v.push(I.ayMs),x.push(_),M.push(B),A.push(I.scrub))}for(let I=v.length-2;I>=0;I--)x[I]=Math.max(x[I],x[I+1]),M[I]=Math.min(M[I],M[I+1]);return{ayMax:v[v.length-1],ay:v,axAccel:x,axDecel:M,axScrub:A,rollover:u.rollover,atLock:d!==null&&Tk(e,d.steerDeg)}}function eI(e,t){let r=e.beta*se,n=0;for(let o of kn){let a=e.wheels[o],s=a.steerDeg*se-r;n+=a.Fx*(Math.cos(s)-1)-a.Fy*Math.sin(s)}return n/t}var S9=Math.PI/180,A9={speeds:Array.from({length:23},(e,t)=>8+t),steerMaxDeg:14,steerSteps:29};function Lk(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 Ea={enabled:!1,kp:3e3,ffLow:150,ffHigh:300,vLow:18,vHigh:25},Pk=e=>Lk(e.ffLow,e.ffHigh,e.vLow,e.vHigh);var br={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"},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"}},tI=["k_yaw","k_roll","k_pitch"];function Fi(e){for(let t of tI)delete e[t];for(let t of Object.keys(br)){let r=e[t];if(!r){e[t]={...br[t]};continue}e[t]={...r,label:br[t].label,unit:br[t].unit}}return e}function Q(e,t){return e[t]?.value??br[t].value}function _u(e){let t=(r,n)=>e[r]?.value??n;return{enabled:t("tv_enabled",0)>=.5,kp:t("tv_kp",Ea.kp),ffLow:t("tv_ff_low",Ea.ffLow),ffHigh:t("tv_ff_high",Ea.ffHigh),vLow:t("tv_v_low",Ea.vLow),vHigh:t("tv_v_high",Ea.vHigh)}}var Dk=[10,25,50,100,200,300];function kb(e,t,r,n,o){let s=Dk.map(i=>Math.round(i<=25?r*i:r*25+n*(i-25)));return{id:e,label:t,speedMmS:[...Dk],reboundN:s,bumpN:s.map(i=>Math.round(i*o))}}var Nu={name:"Generic FS damper",curves:[kb("c1","Soft",1.6,1,.65),kb("c2","Medium",3,1.6,.65),kb("c3","Firm",8,2.4,.65)]};function Ou(e){let t=e.curves.length;return t>0?e.curves[Math.floor((t-1)/2)].id:""}var Sn=25;function Ia(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 Ek(e,t){return t>=0?Ia(e.rebound,t):-Ia(e.bump,-t)}function Ik(e,t,r){return t*Ek(e,t*r)}var Mb=(e,t)=>e.curves.find(r=>r.id===t);function wi(e,t){let r=Mb(e,Ou(e)),n=(t&&Mb(e,t.bump))??r,o=(t&&Mb(e,t.rebound))??r;return{bump:{speedMmS:n?.speedMmS??[],forceN:n?.bumpN??[]},rebound:{speedMmS:o?.speedMmS??[],forceN:o?.reboundN??[]}}}var Vu=5e3;function Ci(e,t){let r=t>0?t:1,n=[],o=[],a=e.bump.speedMmS.map(c=>c/r).filter(c=>c<Vu),s=e.rebound.speedMmS.map(c=>c/r).filter(c=>c<Vu),i=c=>{n.push(c),o.push(Ik(e,r,c))};i(-Vu);for(let c=a.length-1;c>=0;c--)i(-a[c]);i(0);for(let c of s)i(c);return i(Vu),{kind:"map",input:"velocity",x:n,y:o}}var Sb=64;function Ti(e,t,r){let n=t>0?t:1,o=Math.max(r,1e-6),a=0;for(let s=0;s<Sb;s++){let i=Math.sin((s+.5)*Math.PI/Sb),c=n*o*i;a+=n*(Ia(e.rebound,c)+Ia(e.bump,c))*i}return a*(Math.PI/Sb)/(Math.PI*o)}function so(e,t,r,n,o=e){let a=(c,l,u)=>{if(!c||c.curves.length===0)return;let m=wi(c,l);return{law:m,curve:Ci(m,u),rate:Ti(m,u,Sn)}},s=a(e,t?.front,r),i=a(o??e,t?.rear,n);return!s&&!i?null:{...s?{front:s}:{},...i?{rear:i}:{}}}var _k=(e,t)=>({...e,y:e.y.map(r=>r*t)}),rI=e=>({...e,x:e.x.map(t=>-t).reverse(),y:e.y.map(t=>-t).reverse()});function Ab(e,t,r){let n=Math.abs(r)>0?Math.abs(r):1,o=wi(e,t);return{law:o,curve:_k(Ci(o,n),.5),rate:Ti(o,n,Sn)/2,mr:n,ratio:n,share:.5}}function Fb(e,t,r,n,o){let a=n*(Math.abs(r)>0?Math.abs(r):1),s=wi(e,t),i=_k(Ci(s,a),1/n);return{law:s,curve:o?rI(i):i,rate:Ti(s,a,Sn)/n,mr:a/n,ratio:a,share:1/n}}function Pi(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 Bu=["front","rear","heaveFront","heaveRear","rollFront","rollRear"];function Li(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 Ur(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 Ei(e){return e.kind==="coil"?2:1}function Di(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 Ok(e){return Di(e)/2}function Vk(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 Nk(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 nI(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 Ii(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*Di(e.section)/e.barLength,a=2*o/(n*n),s=Ok(e.armSection??e.section),i=3*e.E*s/n**3,c=e.dropLinkRate??1/0;return{rateAtLink:Nk([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*Di(e.section)/e.barLength,a=2*o/(n*n),s=3*e.E*Vk(e.blade)/n**3,i=e.dropLinkRate??1/0;return{rateAtLink:Nk([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*Di(e.section)/e.length,a=2*o/(n*n);return{rateAtLink:a,contributions:{barTwist:a},torsional:o}}case"coil":{let n=Ur(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=nI(e.linkTravel,e.force,t);return{rateAtLink:Math.max(0,n),contributions:{},torsional:0}}}}function $u(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?lf(t,r):1,o=t?uf(t,r):0,a=Ii(e,o).rateAtLink;return{wheelRate:Math.max(0,a*n*n),motionRatio:n,rateAtLink:a}}function _i(e,t){let r=e.damper??0;return!r||e.design.kind==="none"?0:Ei(e.design)*r*t*t}var oI=150;function aI(e){return X(e,[0,-.5,1])<-1e-9?U(e,-1):e}function Bk(e){let t=e.hardpoints,r=K(t.rockerPivotB,t.rockerPivotA),n=te(t.rockerPivotA,U(K(t.rockerToDamper,t.rockerPivotA),.6)),o=aI(q(ae(r,K(t.rockerToDamper,t.rockerPivotA))));return{outer:n,inner:te(n,U(o,oI)),attach:"rocker"}}function Nt(e,t){let r={};for(let o of lr)r[o]=nt(Ve(e,o));let n={vehicle:e,ctx:r};return t&&(n.kc=Ll(n,t)),n}function sI(e,t,r,n){let o=e.corner.hardpoints,a=ra(e.rocker,t.points.rockerAngle),s=i=>Lt(i,r);return{ucaFront:s(o.ucaFront),ucaRear:s(o.ucaRear),lcaFront:s(o.lcaFront),lcaRear:s(o.lcaRear),tieInner:s(Gn(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:Lr(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 Gu(e,t,r,n){let o=ze(t,e.vehicle.config),a=o.isFront?o.sideSign*n:0,s;try{s=bt(ge(e.ctx[t],r,a))}catch{return null}if(!s)return null;let i=Ve(e.vehicle,t).config.loadedRadius,c=sI(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 Ku=.5;function iI(e,t){let r=([i,c,l])=>{let u=q(K(c,i)),m=K(l,i),f=q(K(m,U(u,X(m,u))));return[u,f,ae(u,f)]},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=K(i,e[0]);return te(t[0],[0,1,2].map(l=>a[l][0]*c[0]+a[l][1]*c[1]+a[l][2]*c[2]))}}}var $k=e=>[(e[2][1]-e[1][2])/2,(e[0][2]-e[2][0])/2,(e[1][0]-e[0][1])/2];function Hu(e,t,r){let n=ze(t,e.vehicle.config),o=e.ctx[t],a=r.rigid?void 0:{loadedRadius:r.loadedRadius},s=r.state?null:ge(o,r.travel,r.steer,void 0,a),i=r.state??lt(s),c=ge(o,r.travel+Ku,r.steer,void 0,a),l=ge(o,r.travel-Ku,r.steer,void 0,a),u=(s?s.ok:r.converged)&&c.ok&&l.ok,m=lt(c),f=lt(l),p=(T,P)=>Lt(T.points[P],n),d=o.inv.strut?"pushrodOuter":"uprightUpper",h=p(i,d),b=p(i,"uprightLower"),g=T=>{let P=K(b,h);return Math.hypot(...ae(P,K(p(i,T),h)))/Math.hypot(...P)},y=g("tieOuter")>=g("wheelCenter")?"tieOuter":"wheelCenter",R=[h,b,p(i,y)],k=T=>iI(R,[p(T,d),p(T,"uprightLower"),p(T,y)]),v=k(m),x=k(f),M=$k(v.rot),A=$k(x.rot),w=[NaN,NaN,NaN];return{solved:u,state:i,at:T=>p(i,T),velocity:T=>u?U(K(v.move(T),x.move(T)),1/(2*Ku)):w,omega:u?U(K(M,A),1/(2*Ku)):w}}function wb(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 Gk(e,t,r){let n=Hu(e,t,Mt(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 Kk(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 Hk(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 cI(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 lI=.1*Math.PI/180;function zk(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]))*lI<=o*n}function zu(e,t){return!e.valid||!e.cpLeft||!e.cpRight?!1:zk([e.lateral,e.height],e.cpLeft,e.cpRight,e.sinAngle,t)}function Ni(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}var uI=1;function Yk(e){let t=Ni(e);if(!t||!e.cpLeft||!e.cpRight||Math.abs(t.left-t.right)>uI)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)}}function _a(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 gr(e,t,r){let n=r==="front"?"FL":"RL",o=r==="front"?"FR":"RR",a=Gk(e,n,t),s=Gk(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=Kk(a),c=Kk(s),l=Hk(a,i),u=Hk(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 f=i?[i[0]-a.cp[0],i[1]-a.cp[1]]:l,p=c?[c[0]-s.cp[0],c[1]-s.cp[1]]:u,d=Math.hypot(f[0],f[1]),h=Math.hypot(p[0],p[1]),b=d>0&&h>0?Math.abs(f[0]*p[1]-f[1]*p[0])/(d*h):0,g=wb(a.cp,f,s.cp,p)??cI(a.cp,l,s.cp);if(!g)return{...m,sinAngle:b};let y=s.cp[0]-a.cp[0],R=s.cp[1]-a.cp[1],k=Math.hypot(y,R)||1,v=y/k,x=R/k,M=(a.cp[0]+s.cp[0])/2,A=(a.cp[1]+s.cp[1])/2,w=(g[0]-a.cp[0])*-x+(g[1]-a.cp[1])*v,T=(g[0]-M)*v+(g[1]-A)*x;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 Xr(e,t){return{front:gr(e,t,"front"),rear:gr(e,t,"rear")}}function Yu(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 mI(e,t){return{camber:Yu(e.travel,e.camber,t),toe:Yu(e.travel,e.toe,t),motionRatio:Yu(e.travel,e.motionRatio,t),damperLen:e.damperLen?Yu(e.travel,e.damperLen,t):0}}var Wk=e=>mI(e,0).motionRatio;function Cb(e,t){if(e.kind!=="coil")return null;let r=t??e.motionRatio,n=Ur(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 Wu(e,t){if(e.kind==="none")return 0;if(e.kind==="tabulated"){let n=a=>pI(e,a);return(n(.5)-n(-.5))/(2*.5)/2}if((e.gap??0)>0)return 0;let r=t??e.motionRatio;return Ur(e.rate,0)*r*r/2}function Oi(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 pI(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 Tb={kind:"coil",rate:120,motionRatio:.7,gap:5,bothWays:!1};var jk=new WeakMap;function Uu(e,t){let r=jk.get(e);r||(r=new Map,jk.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=Kn(e,t);return r.set(n,a),a}var dI=32,Vi=new Map,Uk=new WeakMap,fI=1;function hI(e){let t=Uk.get(e);return t===void 0&&(t=fI++,Uk.set(e,t)),t}function Pb(e,t){if(!t.linkage)return null;let r=fn(e,t.linkage,t.design.kind),n=`${hI(e)}|${r?"unit":"bar"}|${JSON.stringify(t.linkage)}`,o=Vi.get(n);if(o)return o;let a=ca(e,t.linkage,{kind:t.design.kind});return Vi.size>=dI&&Vi.delete(Vi.keys().next().value),Vi.set(n,a),a}function co(e,t,r=0){let n=(o,a)=>{if(!(!o||o.design.kind==="none"))return $u(o.design,Pb(a,o),r).wheelRate};return{front:n(t.arbFrontDesign,e.front),rear:n(t.arbRearDesign,e.rear)}}function Na(e,t){let r=(n,o)=>{if(!n||n.design.kind==="none")return;let a=n.linkage?Uu(o,n.linkage).atDesign:void 0;return Wu(n.design,a)};return{front:r(t.heaveFrontDesign,e.front),rear:r(t.heaveRearDesign,e.rear)}}function Jk(e,t){let r=(a,s)=>{if(!a||a.design.kind!=="coil")return;let i=a.linkage?Uu(s,a.linkage).atDesign:void 0;return Cb(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 Xu(e,t){let r=(o,a)=>o?Oi(o,Lb(o,a)):0,n=(o,a)=>o?_i(o,Db(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 Lb=(e,t)=>e.linkage?Uu(t,e.linkage).atDesign:void 0,Db=(e,t)=>$u(e.design,Pb(t,e),0).motionRatio;function eM(e,t){let r=t.damperSetup,n=t.heaveDamperModel??t.damperModel,o=t.rollDamperModel??t.damperModel,a=(f,p,d)=>{if(!f||!n?.curves.length)return;let h=Lb(f,p);if(Oi(f,h)>0)return Ab(n,r?.[d],h??(f.design.kind==="coil"?f.design.motionRatio:1))},s=(f,p,d)=>{if(!f||!o?.curves.length)return;let h=Db(f,p);if(!(_i(f,h)>0))return;let b=Pb(p,f)!==null;return Fb(o,r?.[d],h,Ei(f.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 qu(e,t){let r=t.heaveDamperModel??t.damperModel,n=t.rollDamperModel??t.damperModel,o=(i,c)=>io(i)?{source:"none"}:Li(i.config.coilover,c),a=(i,c)=>{if(!i)return{source:"none"};let l=Oi(i,Lb(i,c))>0;return Li(i.coilover,l?r:void 0)},s=(i,c)=>{if(!i||i.design.kind!=="coil")return{source:"none"};let l=_i(i,Db(i,c))>0;return Li(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 tM(e){let t=(r,n)=>{let o={};return r?.linkage&&r.design.kind==="coil"&&(o.heave=r.linkage),n?.linkage&&n.design.kind!=="none"&&n.design.kind!=="direct"&&(o.roll=n.linkage,o.rollKind=n.design.kind),o.heave||o.roll?o:void 0};return{front:t(e.heaveFrontDesign,e.arbFrontDesign),rear:t(e.heaveRearDesign,e.arbRearDesign)}}var io=e=>e.config.actuation==="decoupled",lo="a decoupled axle damps in its heave and roll elements, set below";function rM(e,t,r={}){let n={...t},o=(m,f)=>{let p=n[m];p&&typeof p=="object"&&"value"in p&&(n[m]={...p,value:f})},{front:a,rear:s}=co(e,t);a!==void 0&&o("arb_front",a),s!==void 0&&o("arb_rear",s);for(let[m,f,p]of[[t.heaveFrontDesign,e.front,"heave_spring_front"],[t.heaveRearDesign,e.rear,"heave_spring_rear"]]){if(!m||m.design.kind==="none")continue;let d=m.linkage?Uu(f,m.linkage).atDesign:void 0;o(p,Wu(m.design,d))}let i=gI(e,t,r),c=bI(e,i);n.kinFront=c.kinFront,n.kinRear=c.kinRear;let l=RI(e,i);n.steerFront=c.steerFront,Number.isFinite(l.ackermannPct)&&o("ackermann_pct",l.ackermannPct);let u=m=>io(m)?0:m.measured?.springRate??m.config.springRate;o("spring_front",u(e.front)),o("spring_rear",u(e.rear));for(let[m,f]of[[e.front,"spring_front"],[e.rear,"spring_rear"]])io(m)&&(n.readouts={...n.readouts,[f]:"a decoupled axle has no corner spring; its heave and roll elements carry the car"});for(let[m,f]of[[e.front,"damper_front"],[e.rear,"damper_rear"]])io(m)&&(o(f,0),n.readouts={...n.readouts,[f]:lo});return o("mr_front",l.mrFront),o("mr_rear",l.mrRear),o("wheelbase",l.wheelbase),o("track_front",l.trackFront),o("track_rear",l.trackRear),o("rc_front",l.rcFront),o("rc_rear",l.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:l.rcGainFront,gainRear:l.rcGainRear},n}function bI(e,t){return{kinFront:qk(e.front),kinRear:qk(e.rear),steerFront:e.front.measured?void 0:Qu(e.front,t)}}var Xk=new WeakMap;function qk(e){let t=Xk.get(e);return t||Xk.set(e,t=xa(e)),t}function gI(e,t,r={}){return yI(e,t,r.front,r.rear)}function yI(e,t,r,n){let o=e.front.config.loadedRadius;if(!((dr(r??t.tireModel)??0)>0))return o;let a={...t,surveyedRadiusFront:o,surveyedRadiusRear:e.rear.config.loadedRadius};return Zu(a,r,n).front??o}var Qk=new WeakMap;function Qu(e,t=e.config.loadedRadius){let r=Qk.get(e);r||(r=new Map,Qk.set(e,r));let n=r.get(t);if(n)return n;let o=t===e.config.loadedRadius?void 0:{loadedRadius:t},a=Tf(e,St(e.config),void 0,void 0,void 0,void 0,o);return r.size>=4&&r.clear(),r.set(t,a),a}var Zk=new WeakMap;function xI(e){return Ye(e,{travelMin:-1,travelMax:1,steps:3}).samples[1].metrics.motionRatio??1}var ju=e=>e.measured?Wk(e.measured):xI(e);function RI(e,t=e.front.config.loadedRadius){let r=()=>e.front.measured?void 0:Qu(e.front,t);return{...vI(e),get steerFront(){return r()},get ackermannPct(){let n=r();return n?Pf(n,kt(e.front),e.config.wheelbase):Number.NaN}}}function vI(e){let t=Zk.get(e);if(t)return t;let r=e.front.measured,n=e.rear.measured,a=!r||!n?Xr(Nt(e),{heave:0,pitch:0,roll:0,steer:0}):null,s={wheelbase:e.config.wheelbase,trackFront:r?r.track:kt(e.front),trackRear:n?n.track:kt(e.rear),mrFront:ju(e.front),mrRear:ju(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:_a(a.front),rcGainRear:n||!a?0:_a(a.rear),rcFrontValid:r?!0:!!a?.front.valid,rcRearValid:n?!0:!!a?.rear.valid};return Zk.set(e,s),s}var Ft={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}},aM=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),yr=(e,t,r,n=1/0)=>typeof e=="number"&&Number.isFinite(e)?Math.min(n,Math.max(r,e)):t;function uo(e){if(aM(e))switch(e.kind){case"open":case"spool":return{kind:e.kind};case"clutch":{let t=Ft.clutch;return{kind:"clutch",preloadNm:yr(e.preloadNm,t.preloadNm,0),rampDriveDeg:yr(e.rampDriveDeg,t.rampDriveDeg,1,90),rampCoastDeg:yr(e.rampCoastDeg,t.rampCoastDeg,1,90),faces:Math.round(yr(e.faces,t.faces,0)),muClutch:yr(e.muClutch,t.muClutch,0,1),rFrictionMm:yr(e.rFrictionMm,t.rFrictionMm,1),rRampMm:yr(e.rRampMm,t.rRampMm,1)}}case"torsen":{let t=Ft.torsen,r=yr(e.preloadNm,0,0);return{kind:"torsen",tbrDrive:yr(e.tbrDrive,t.tbrDrive,1),tbrCoast:yr(e.tbrCoast,t.tbrCoast,1),...r>0?{preloadNm:r}:{}}}default:return}}function Ju(e){if(!aM(e))return;let t=uo(e.front),r=uo(e.rear);return t||r?{...t?{front:t}:{},...r?{rear:r}:{}}:void 0}function Bi(e){let t=xn(e),r=n=>n>=2?"independent":n===1?"diff":"none";return{front:r(t.front),rear:r(t.rear)}}function $i(e){if(!e.driveline)return;let t=Bi(e),r=e.r_dyn.value,n=s=>{if(t[s]!=="diff")return;let i=uo(e.driveline?.[s]);if(!(!i||i.kind==="independent"))return{kind:i.kind,drive:yi(i,"drive",r),coast:yi(i,"coast",r),hubs:yi(i,"hubs",r)}},o=n("front"),a=n("rear");return o||a?{...o?{front:o}:{},...a?{rear:a}:{}}:void 0}var kI={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"}},nM=e=>{let t=e==="front"?"Front":"Rear";return Object.fromEntries(Object.entries(kI).map(([r,n])=>[`${e}.${r}`,{section:t,...n}]))},em={...nM("front"),...nM("rear")},oM=e=>e.motorModel?.kind==="ice"?e.motorPlacement==="front"?"front":"rear":null;function sM(e,t){let r=oM(t);if(!(!r||oM(e)===r||t.driveline?.[r]))return{...t.driveline,[r]:{...Ft.clutch}}}function jt(e,t,r,n){return e>0?!(r>0)||!Number.isFinite(r)?e:Math.max(1,e-t/r):n}function tm(e,t,r){let n=Math.max(0,Math.min(1,r)),o=jt(e.freeRadius,e.staticLoad,e.tyreRate,e.surveyed),a=jt(t.freeRadius,t.staticLoad,t.tyreRate,t.surveyed);return n*o+(1-n)*a}function Oa(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 qr(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 Gi(e,t){if(!e)return SI(t);let r=t-bn(e,0).camber;return r?{...e,camber:e.camber.map(n=>n+r)}:e}function MI(e){return{kinFront:Gi(e.kinFront,Q(e,"camber_front_deg")),kinRear:Gi(e.kinRear,Q(e,"camber_rear_deg"))}}function SI(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 iM=9.81,cM=e=>e>1?e/100:e;function Va(e,t,r){let n=t??e.tireModel??ni(),o=r??e.tireModelRear??n,a={grip:Q(e,"grip_scale"),stiffness:Q(e,"stiffness_scale")},s=au(n,a);return{front:s,rear:o===n?s:au(o,a)}}function xr(e,t,r){let n=Va(e,t,r),o=De(n.front);return gt(n.rear===n.front?o:Ul(o,De(n.rear)))}function Eb(e,t,r){let n=cM(e.front_mass_diss.value),o=Va(e,t,r),a=De(o.front),s=o.rear===o.front?a:De(o.rear),i=t??e.tireModel,c=r??e.tireModelRear??i,l=e.m.value*iM*n/2,u=e.m.value*iM*(1-n)/2,m=(i?a.verticalStiffness():0)||Q(e,"tire_vertical_rate"),f=(c?s.verticalStiffness():0)||Q(e,"tire_vertical_rate"),p=dr(i)??0,d=dr(c)??0,h=e.surveyedRadiusFront&&e.surveyedRadiusRear?tm({freeRadius:p,staticLoad:l,tyreRate:m,surveyed:e.surveyedRadiusFront},{freeRadius:d,staticLoad:u,tyreRate:f,surveyed:e.surveyedRadiusRear},n):void 0,b=e.surveyedRadiusFront?jt(p,l,m,e.surveyedRadiusFront):void 0,g=e.surveyedRadiusRear?jt(d,u,f,e.surveyedRadiusRear):void 0;return{ev:a,evR:s,Wf:l,Wr:u,tireRate:m,tireRateRear:f,tyreFreeRadius:p,tyreFreeRadiusRear:d,cgStandingRadius:h,standingFront:b,standingRear:g}}function Zu(e,t,r){let n=Eb(e,t,r);return{front:n.standingFront,rear:n.standingRear}}function lM(e,t,r){return Eb(e,t,r).cgStandingRadius}function Rt(e,t,r){let n=cM(e.front_mass_diss.value),o=Q(e,"mr_front")||1,a=Q(e,"mr_rear")||1,{ev:s,evR:i,Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:f,tyreFreeRadiusRear:p,cgStandingRadius:d,standingFront:h,standingRear:b}=Eb(e,t,r),g=bi(e),y=$i(e),R=so(e.damperModel,e.damperSetup,o,a,e.damperModelRear??e.damperModel),k=e.readouts?.damper_front===lo,v=e.readouts?.damper_rear===lo,x={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,Q(e,"cop_long"))),copHeight:Q(e,"cop_height"),...e.aeroModel?{model:e.aeroModel}:{},rideHeightFront:Q(e,"ride_height_front"),rideHeightRear:Q(e,"ride_height_rear")};return{massTotal:e.m.value,frontMassFrac:n,steeringSystem:e.steeringSystem,tv:_u(e),cgHeight:Oa(Q(e,"cg_height"),e.cgReference?.standingRadius,d),...d!==void 0?{cgStandingRadius:d}:{},wheelbase:Q(e,"wheelbase"),trackFront:Q(e,"track_front"),trackRear:Q(e,"track_rear"),wheelRateFront:Q(e,"spring_front")*o*o,wheelRateRear:Q(e,"spring_rear")*a*a,tireRate:u,...m!==u?{tireRateRear:m}:{},tireDamping:Q(e,"tire_vertical_damping"),arbFront:Q(e,"arb_front"),arbRear:Q(e,"arb_rear"),brakeBalanceFront:g.balanceFront,brakes:g,...y?{driveline:y}:{},heaveSpringFront:Q(e,"heave_spring_front"),heaveSpringRear:Q(e,"heave_spring_rear"),unsprungPerCorner:Q(e,"unsprung_mass"),unsprungCgHeight:AI(e,{Wf:c,Wr:l,tireRate:u,tireRateRear:m,tyreFreeRadius:f,tyreFreeRadiusRear:p,standingFront:h,standingRear:b}),tyreFreeRadius:f,...p!==f?{tyreFreeRadiusRear:p}:{},rcHeightFront:qr(Q(e,"rc_front"),e.rcRoad?.gainFront,e.rcRoad?.radiusFront,h),rcHeightRear:qr(Q(e,"rc_rear"),e.rcRoad?.gainRear,e.rcRoad?.radiusRear,b),corneringStiffnessFront:s.corneringStiffness(c),corneringStiffnessRear:i.corneringStiffness(l),damperFront:R?.front&&!k?R.front.rate:Q(e,"damper_front")*o*o,damperRear:R?.rear&&!v?R.rear.rate:Q(e,"damper_rear")*a*a,...R?.front&&!k?{damperCurveFront:R.front.curve}:{},...R?.rear&&!v?{damperCurveRear:R.rear.curve}:{},aero:x,ackermannPct:Q(e,"ackermann_pct"),toeFrontDeg:Q(e,"toe_front_deg"),toeRearDeg:Q(e,"toe_rear_deg"),yawInertia:Q(e,"I_yaw"),steerFront:e.steerFront,...MI(e)}}function AI(e,t){let r=(a,s,i,c)=>a??(s>0?jt(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 rm={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 uM(e,t=e.batteryModel){if(!t)return e;let r=Cr(t),n=(o,a)=>({...o,value:a});return{...e,capacity:n(e.capacity,r.capacityAh),ocv:n(e.ocv,r.voltageAtFull)}}var pM={damper_front:`the damper part sets it: its front curve at ${Sn} mm/s`,damper_rear:`the damper part sets it (the rear's own, where the car names one): its rear curve at ${Sn} mm/s`};function nm(e){let t=!!(e.damperModelId||e.damperModel),r=t||!!(e.damperModelIdRear||e.damperModelRear);return{...t?{damper_front:pM.damper_front}:{},...r?{damper_rear:pM.damper_rear}:{}}}function dM(e,t=e.damperModel,r=e.damperModelRear??t){if(!t&&!r)return e;let n=Q(e,"mr_front")||1,o=Q(e,"mr_rear")||1,a=so(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!==lo&&(i.damper_front=s(e.damper_front,"damper front",a.front.rate/(n*n))),a.rear&&e.readouts?.damper_rear!==lo&&(i.damper_rear=s(e.damper_rear,"damper rear",a.rear.rate/(o*o))),i}var fM={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}},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 Qr(e){return!!e&&typeof e=="object"&&"value"in e&&"label"in e}var TI={Batteriekapazit\u00E4t:"pack capacity",Rollwiderstandsbeiwert:"rolling-resistance coefficient"},bM=e=>TI[e]??e;function om(e){let t=[];for(let r of Object.keys(e)){if(r==="motor"||r==="name")continue;let n=e[r];Qr(n)&&t.push({key:r,label:bM(n.label),value:n.value,unit:n.unit})}return t}var PI=[{title:"Mass & chassis",keys:["m","front_mass_diss","cg_height","unsprung_mass","wheelbase","track_front","track_rear","rc_front","rc_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"]}],LI=.5,hM=e=>e==="infinite"?1/0:typeof e=="number"?e:null,DI=e=>/front/.test(e)?e.replace("front","rear"):/rear/.test(e)?e.replace("rear","front"):null,rq=(()=>{let e=fM.rows,t=o=>{let a=DI(o),s=hM(e[o]?.score),i=a&&e[a]?hM(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>=LI&&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 Ib={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 gM(e){let t=new Map;for(let a of om(e))t.set(a.key,a);let r=new Set,n=[];for(let a of PI){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=om(e).filter(a=>!r.has(a.key));return o.length&&n.push({title:"Other",rows:o}),n}var _b={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"},Nb={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"},yM=e=>!!(e.aeroModelId||e.aeroModel);function EI(e){let t=n=>n!=null&&n.design.kind!=="none",r={};return t(e.arbFrontDesign)&&(r.arb_front="the front anti-roll bar design sets it"),t(e.arbRearDesign)&&(r.arb_rear="the rear anti-roll bar design sets it"),t(e.heaveFrontDesign)&&(r.heave_spring_front="the front third-spring design sets it"),t(e.heaveRearDesign)&&(r.heave_spring_rear="the rear third-spring design sets it"),r}var II=e=>!!(e.batteryModelId||e.batteryModel);function _I(e,t){let r={};return t.geometry&&Object.assign(r,Ib,EI(e)),yM(e)&&Object.assign(r,_b),II(e)&&Object.assign(r,rm),Object.assign(r,nm(e)),e.readouts&&Object.assign(r,e.readouts),r}function xM(e,t){let r=_I(e,t);return yM(e)||Object.assign(r,Nb),r}function Ob(e){let t=e.cop_long;return Qr(t)?1-t.value:.5}function NI(e,t){let r=e.front_aero_diss,n=e.cop_long;!Qr(r)||!Qr(n)||(t===r.label?n.value=1-r.value:t===n.label&&(r.value=1-n.value))}function OI(e,t){NI(e,t);let r=e.c_l,n=e.c_w,o=e.l_to_d_ratio;!Qr(r)||!Qr(n)||(t===r.label||t===n.label?Qr(o)&&n.value!==0&&(o.value=r.value/n.value):Qr(o)&&t===o.label&&o.value!==0&&(n.value=r.value/o.value))}function am(e,t,r){let n=!1;for(let o of Object.keys(e)){if(o==="motor"||o==="name")continue;let a=e[o];if(Qr(a)&&bM(a.label)===t){a.value=r,n=!0;break}}return n&&OI(e,t),n}function sm(e,t,r=0,n,o){let a=()=>({cl:e.c_l.value,cw:e.c_w.value,frontShare:Ob(e),A:e.A.value,platform:null});if(!e.aeroModel)return a();let s=Pr(n??Rt(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:Ob(e),A:s.area,platform:s}}var RM=e=>typeof e=="object"&&e!==null&&typeof e.value=="number"&&typeof e.label=="string";function vM(e,t=e.aeroModel){if(!t)return e;let r=cn(t,{wheelbase:Q(e,"wheelbase")}).at(Q(e,"ride_height_front"),Q(e,"ride_height_rear")),{cl:n,balanceFront:o}=Pd(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(RM(e.cop_long)?e.cop_long:void 0,br.cop_long,1-o)};return RM(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 Ki={dsTarget:.25,accelStep:.25,vTol:.002,scanSteps:24,seamIters:8,fitSpacing:1},VI=32;function kM(e,t,r){let n=Math.round(e/t);return Math.max(1,Math.min(Number.isFinite(n)?n:1,Math.floor(r/VI)||1))}function ut(e){let t=Ki,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 MM=Math.PI/180,im=.02,SM=new WeakMap;function Hi(e){let t=SM.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)*MM,l=(e.bank?.[i]??0)*MM,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 SM.set(e,s),s}function cm(e,t,r){return e.n0[t]+e.k[t]*r*r}function AM(e,t){return e.k[t]<0?Math.sqrt(Math.max(0,e.n0[t])/-e.k[t]):1/0}function FM(e,t){if(!e)return null;let r=1/0,n=-1/0;for(let o=0;o<e.n0.length;o++){let a=cm(e,o,t[o]??0);a<r&&(r=a),a>n&&(n=a)}return r>=1-im&&n<=1+im?null:{lo:r,hi:n}}var Ba=[.1,.25,.5,.75,1,1.25,1.5,2,2.5];function wM(e){let t=e.lo>=1-im?1:1-1.25*(1-e.lo)-.05,r=e.hi<=1+im?1:1+1.25*(e.hi-1)+.05,n=[...Ba].reverse().find(a=>a<=t)??Ba[0],o=Ba.find(a=>a>=r)??Ba[Ba.length-1];return Ba.filter(a=>a>=n&&a<=o)}function Vb(e,t,r){return r<1?Math.max(e,t):Math.min(e,t)}function CM(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=m=>c+l*m*m;return n?{vMax:s.vMax,axAccel:(m,f,p=1,d=1)=>s.axAccel(m,f,p,d)+t.axAccel(u(m),m,f,p,d)-r.axAccel(m,f,p,d),axDecel:(m,f,p=1,d=1)=>{let h=b=>s.axDecel(m,f,p,b)+t.axDecel(u(m),m,f,p,b)-r.axDecel(m,f,p,b);return d===1?h(1):Vb(h(d),h(1),d)},ay:(m,f,p=1)=>Math.max(0,s.ay(m,f,p)+t.ay(u(m),m,f,p)-r.ay(m,f,p)),scrub:(m,f,p=1)=>(s.scrub?.(m,f,p)??0)+t.scrub(u(m),m,f,p)-(r.scrub?.(m,f,p)??0)}:{vMax:s.vMax,axAccel:(m,f,p=1,d=1)=>t.axAccel(u(m),m,f,p,d),axDecel:(m,f,p=1,d=1)=>t.axDecel(u(m),m,f,p,d),ay:(m,f,p=1)=>t.ay(u(m),m,f,p),scrub:(m,f,p=1)=>t.scrub(u(m),m,f,p)}}}function lm(e,t,r,n,o){let a=e.length,s=r?a:a-1,i=A=>r?(A+1)%a:A+1,{brakeAhead:c,apexAhead:l}=BI(e,t,r),u=new Array(a),m=new Array(a),f=new Array(a),p=new Array(a).fill(0),d=0,h=0,b=0,g=Math.max(0,Math.min(1,n.kept)),y=g>=1?0:n.up,R=g>=1?0:n.down,k=4*y*(1-g),v=A=>{let{v:w,gear:T,tau:P,target:S}=A;d=0,h=0,b=0;for(let F=0;F<s;F++){let C=i(F),L=e[C];for(let N=0;P<=0&&N<n.count;N++){let O=T;if(w<L-1e-9?n.best(w)>T&&(n.rpm(w,T)>=n.limitRpm||c[F]>=w*k)?O=T+1:T>0&&w<n.vIdle(T)&&(O=T-1):L<w-1e-9&&T>0&&n.best(l[F])<T&&n.rpm(w,T-1)<=n.limitRpm&&(O=T-1),O===T)break;S=O,O>T?d++:h++,P=O>T?y:R,P<=0&&(T=S)}u[F]=w,m[F]=T+1,f[F]=n.rpm(w,T);let E=P>0;p[F]=E?1:0;let D=L;if(!E)w<L&&(D=Math.min(L,Math.sqrt(Math.max(0,w*w+2*o(F,w,n.share(w,T))*t[F]))));else if(w<L){let N=o(F,w,g>0?g*n.share(w,T):0),O=Math.min(L,Math.sqrt(Math.max(0,w*w+2*N*t[F]))),z=w+O>0?2*t[F]/(w+O):1/0;if(z<=P)D=O,b+=z,P-=z;else{let I=Math.min(L,Math.max(0,w+N*P)),_=Math.max(0,t[F]-(w+I)*.5*P);b+=P,P=0,T=S,D=Math.min(L,Math.sqrt(Math.max(0,I*I+2*o(F,I,n.share(I,T))*_)))}}else{let N=w+D>0?2*t[F]/(w+D):0;b+=Math.min(N,P),P-=N,P<=0&&(T=S)}w=D}return{v:w,gear:T,tau:P,target:S}},x=n.best(e[0]),M={v:e[0],gear:x,tau:0,target:x};if(r)for(let A=0;A<6;A++){let w=v(M),T=Math.abs(w.v-M.v)<=1e-9&&w.gear===M.gear&&w.target===M.target&&Math.abs(w.tau-M.tau)<=1e-12;if(M=w,T)break}else{let A=v(M);u[a-1]=A.v,m[a-1]=A.gear+1,f[a-1]=n.rpm(A.v,A.gear),p[a-1]=A.tau>0?1:0}return{v:u,gear:m,rpm:f,shifting:p,upshifts:d,downshifts:h,gapTime:b}}function BI(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,f=e[m]<e[u]-1e-9;s=f?0:s+t[u],i=f?Math.min(i,e[m]):e[u],l<n&&(o[u]=s,a[u]=i)}return{brakeAhead:o,apexAhead:a}}var Bb=.001,$b=9.81,zi=(e,t)=>um(e?.gradient?.[t]??0);function um(e){return e===0?0:-$b*Math.sin(e*Math.PI/180)}function Fn(e,t){let r=new Array(t);for(let n=0;n<t;n++)r[n]=um(e?.[n]??0);return r}function mm(e,t){let r=e?.[t];return r!=null&&r>0?r:1}var An=(e,t)=>mm(e?.mu,t),mo=(e,t)=>e?.bank?.[t]??0;function $I(e,t,r,n,o,a){let s=e.ay(t,r,An(o,a)),i=mo(o,a);if(!i)return s;let c=i*Math.PI/180,l=n===0?0:-Math.sign(n)*$b*Math.sin(c);return Math.max(0,(s+l)/Math.cos(c))}function We(e,t){if(!t)return e;let r=t*Math.PI/180;return e*Math.cos(r)+$b*Math.sin(r)}function Gb(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 po=(e,t,r)=>t?t(r):e,GI=1e-4;function $a(e,t,r,n,o,a,s){let i=ut(r),c=[];for(let l=0;l<t.length;l++){let u=t[l],m=Math.abs(u),f=po(e,o,l),p=a!==void 0&&a>0?Math.min(f.vMax,a):f.vMax,d=s?Math.min(p,s(l)):p,h=m<=0?d:Gb(b=>b*b*m-$I(f,b,0,u,n,l),Bb,d,i.scanSteps,Math.min(i.vTol,GI));c.push({v:h,ax:0,ay:h*h*u})}return c}function KI(e,t,r,n,o,a,s=1,i=0,c=0,l){if(r.v<=t.v)return 0;let u=p=>{let d=We(p*p*n,c),h=(l?e.axDecel(p,Math.abs(d),s,l(p)):e.axDecel(p,Math.abs(d),s))+i;return Math.sqrt(Math.max(0,p*p+2*h*o))},m=r.v;r.v=Gb(p=>u(p)-t.v,Bb,r.v,a.scanSteps,a.vTol),r.ay=r.v*r.v*n;let f=Math.abs(We(r.ay,c));return r.ax=(l?e.axDecel(r.v,f,s,l(r.v)):e.axDecel(r.v,f,s))+i,m-r.v}function HI(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(We(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 TM(e,t,r,n,o,a){let s=ut(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 f=(m+1)%i;u=Math.max(u,KI(po(e,o,m),t[f],t[m],r.curvature[m],r.ds[m],s,An(r,m),zi(r,m),mo(r,m),a?p=>a(m,p):void 0))}if(u<=s.vTol)break}return c}function PM(e,t,r,n,o,a){let s=ut(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 f=(m+1)%i;u=Math.max(u,HI(po(e,o,m),t[f],t[m],r.curvature[m],r.ds[m],An(r,m),zi(r,m),mo(r,m),a?a[m]:1))}if(u<=s.vTol)break}return c}function zI(e,t,r){let n=r.load?Hi(t):null;if(!n||!r.load)return{pick:r.envelope};let o=t.npts;return{pick:CM(n,r.load,e,r.envelope),cap:a=>AM(n,a%o),n:(a,s)=>cm(n,a,s)}}function LM(e,t,r,n,o,a,s){return lm(n,r.ds,o,a,(i,c,l)=>{let u=c*c*r.curvature[i];return po(e,t,i).axAccel(c,Math.abs(We(u,mo(r,i))),An(r,i),s?l*s[i]:l)+zi(r,i)})}function DM(e,t){return{gear:e.gear.slice(0,t),engineRpm:e.rpm.slice(0,t),shifting:e.shifting.slice(0,t)}}function EM(e,t,r,n){if(!e.scrub)return{};let o=!1,a=n.map((s,i)=>{let c=po(e,t,i),l=We(s*s*r.curvature[i],mo(r,i)),u=c.scrub?c.scrub(s,Math.abs(l),An(r,i)):0;return u!==0&&(o=!0),u});return o?{axScrub:a}:{}}function wt(e,t,r,n={}){let o=ut(r),a=t.npts,s=t.closed&&!n.standingStart,{pick:i,cap:c,n:l}=zI(e,t,n),u=n.driveDerate,m=n.brakeFade;if(!s)return YI(e,t,o,n.standingStart===!0,i,u,n.vCeiling,m,c,l,n.shifts);let f=$a(e,t.curvature,o,t,i,n.vCeiling,c),p=TM(e,f,t,o,i,m),d=PM(e,f,t,o,i,u),h=n.shifts?LM(e,i,t,f.map(k=>k.v),!0,n.shifts,u):void 0;if(h)for(let k=0;k<a;k++)f[k].v=h.v[k];for(let k=0;k<a;k++){let v=f[k];v.ay=v.v*v.v*t.curvature[k];let x=f[(k+1)%a].v;v.ax=(x*x-v.v*v.v)/(2*t.ds[k])}let b=f.map(k=>k.v),g=f.map(k=>k.ax),y=f.map(k=>k.ay),R=0;for(let k=0;k<a;k++){let v=b[k]+b[(k+1)%a];v>0&&(R+=2*t.ds[k]/v)}return{states:f,v:b,ax:g,ay:y,laptime:R,sweeps:{backward:p,forward:d},...l?{loadFactor:b.map((k,v)=>l(v,k))}:{},...EM(e,i,t,b),...h?DM(h,a):{}}}function YI(e,t,r,n,o,a,s,i,c,l,u){let m=t.npts,f=t.closed?m:m-1,p=f+1,d=new Array(p);for(let R=0;R<p;R++)d[R]=t.curvature[R%m];let h=$a(e,d,r,t,o,s,c);n&&(h[0].v=0);for(let R=f-1;R>=0;R--){let k=h[R],v=h[R+1];if(k.v<=v.v)continue;let x=po(e,o,R),M=w=>{let T=We(w*w*t.curvature[R],mo(t,R)),P=(i?x.axDecel(w,Math.abs(T),An(t,R),i(R,w)):x.axDecel(w,Math.abs(T),An(t,R)))+zi(t,R);return Math.sqrt(Math.max(0,w*w+2*P*t.ds[R]))},A=n&&R===0?k.v:Bb;k.v=Gb(w=>M(w)-v.v,A,k.v,r.scanSteps,r.vTol)}for(let R=0;R<f;R++){let k=h[R],v=h[R+1];k.ay=k.v*k.v*t.curvature[R];let x=We(k.ay,mo(t,R));k.ax=po(e,o,R).axAccel(k.v,Math.abs(x),An(t,R),a?a[R]:1)+zi(t,R),v.v=Math.min(v.v,Math.sqrt(Math.max(0,k.v*k.v+2*k.ax*t.ds[R])))}let b=u?LM(e,o,t,h.map(R=>R.v),!1,u,a):void 0;if(b)for(let R=0;R<p;R++)h[R].v=b.v[R];let g=0;for(let R=0;R<f;R++){let k=h[R].v+h[R+1].v;k>0&&(g+=2*t.ds[R]/k)}let y=h.slice(0,m);for(let R=0;R<m;R++){let k=y[R];k.ay=k.v*k.v*t.curvature[R];let v=R<f?h[R+1].v:k.v;k.ax=t.ds[R]>0?(v*v-k.v*k.v)/(2*t.ds[R]):0}return{states:y,v:y.map(R=>R.v),ax:y.map(R=>R.ax),ay:y.map(R=>R.ay),laptime:g,sweeps:{backward:1,forward:1},...l?{loadFactor:y.map((R,k)=>l(k,R.v))}:{},...EM(e,o,t,y.map(R=>R.v)),...b?DM(b,m):{}}}var IM=(e,t)=>{let r=e[t]?.value;return Number.isFinite(r)&&r>0?r:0};function fo(e,t,r){let n=e.m.value,o=e.r_dyn?.value??0,a=IM(e,"I_wheel"),s=e.motorModel?.kind==="ice"?0:IM(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,f=u*a/c,p=n+m+f;return{mass:n,driven:m,undriven:f,effective:p,powerFactor:n/p,tractionFactor:n/(n+f)}}function ho(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 Yi=36e5,VM=Math.PI*2,Kb=e=>Math.max(0,Math.min(1,e));function Hb(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=ll(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/VM),l=Math.max(0,i*o/(n*a)),u=r.efficiency(c,l);return u>.01?u:.5}}var _M=new WeakMap;function Ga(e){if(e.batteryModel)return e.batteryModel;let t=e.capacity.value,r=e.ocv.value,n=_M.get(e);if(n&&n.capacityAh===t&&n.ocv===r)return n.model;let o=xd(t,r);return _M.set(e,{capacityAh:t,ocv:r,model:o}),o}function zb(e){let t=e.params,r=zh(t,Ru(e));if(ht(t.motorModel)||xt(t).mode!=="hydraulic")return r;let n;return(o,a,s,i=0)=>{if(!(o>0))return 0;n??=WI(e);let c=wu(n.inp,n.ev,o,a,i);return c?Math.min(o,c.regenFront+c.regenRear):r(o,a,s)}}var NM=new WeakMap;function WI(e){let t=e.params,r=NM.get(t);if(!r){let n=Kr(t);r={inp:Rt(n.regen?t:{...t,energy:{...n,regen:!0}}),ev:xr(t)},NM.set(t,r)}return r}var Wi=e=>e.airTempC??Et;function pm(e,t){return e.thermal?e.thermal.startC??t:qo}function OM(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 BM=()=>({windingC:[],derate:[],lossW:[],torqueNm:[],ampsRms:[]});function jI(e){let t=e.motorModel;if(ht(t))return;let r=t?ll(t).maxTorque:s=>_e(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/VM),peak:r,torque:(s,i,c)=>Math.min(Math.abs(s)*o/(n*a),c*r(i))}}function UI(e,t){let r=e.motorModel?.thermal;if(!r||!t)return;let n=r.torqueConstant;return{...t,th:Rd(r),amps:o=>n>0?Math.abs(o)/n:0}}function XI(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),f=u?c/l:1,p=r*f;return{dq:m*p,lossJ:m*m*e.resistance(n,o)*p,energyJ:l*p,short:c>i,cutoff:u,seconds:p}}function qI(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 QI(e){let{drivenFront:t,drivenRear:r}=ho(e);return fo(e.params,t,r)}function Ka(e,t,r,n,o=Gr,a,s,i,c,l,u){let m=e.params,f=m.rho.value,p=m.fr_0.value,d=m.m.value,h=e.FG,b=m.aeroModel?Rt(m):void 0,g=Hb(m),y=Cr(Ga(m)),R=y.chargeC,k=Kb(a??m.soc.value),v=Wi(m),x=s??pm(y,v),M=x,A=0,w=0,T=0,P=0,S=-1,F=-1,C=-1,L=i||m.motorModel?.thermal?jI(m):void 0,E=UI(m,L),D=E?E.th.startC:0,N=D,O=0,z=1,I=-1,_=0,B=0,V=zb(e),G=m.motorModel?.kind==="ice",H=u?.scrub,W=H?d/QI(e).tractionFactor:0,J=Math.min(t.length,r.length);for(let Y=0;Y<J;Y++){let ee=r[Y],ne=ee*ee,de=n[Y]-(c?.[Y]??0),{cl:j,cw:Z,A:re}=sm(m,ee,de/9.81,b),oe=.5*f*j*re*ne,le=.5*f*Z*re*ne,ue=(h+oe)*-p,ie=H?-W*(H[Y]??0):0,fe=ue+le+ie+d*de,Fe=fe*t[Y],we=Y+1<r.length?r[Y+1]:ee,Re=.5*(ee+we),me=Re>0?t[Y]/Re:0,Ne=0,Ce=k,qe=x,xe=0,ke=0,Le=me;if(G){fe>0&&(ke=Fe/g(ee,fe),A+=ke/Yi),l?.netKwh.push(A-w),l?.powerKw?.push(me>0?ke/me/1e3:0);continue}if(fe>0){let pe=Fe/g(ee,fe),he=XI(y,pe,me,k,x);he.short&&S<0&&(S=Y),he.cutoff&&F<0&&(F=Y);let Qe=k*R,ve=Math.min(he.dq,Qe),je=he.dq>0?ve/he.dq:1;ve>=Qe&&C<0&&(C=Y),A+=he.energyJ*je/Yi,ke=he.energyJ*je,Le=he.seconds,T+=he.lossJ*je,P+=ve,me>0&&(xe=ve/he.seconds),k=Kb(k-ve/R),x=OM(y,x,he.dq>0&&me>0?ve/me:0,he.lossJ*je,me,v),x>M&&(M=x),Ne=fe}else if(o.regen){let pe=u?We(u.ay[Y],u.bank?.[Y]??0)/9.81:0,he=V(-fe,ee,de/9.81,pe),Qe=o.regenEfficiency*he*t[Y],ve=qI(y,Qe,me,k,x),je=(1-k)*R,He=Math.min(ve.dq,je),it=ve.dq>0?He/ve.dq:1;w+=ve.energyJ*it/Yi,ke=-ve.energyJ*it,T+=ve.lossJ*it,P-=He,me>0&&(xe=-He/me),k=Kb(k+He/R),x=OM(y,x,He>0&&me>0?-He/me:0,ve.lossJ*it,me,v),x>M&&(M=x),Ne=-he*it}if(l?.netKwh.push(A-w),l?.powerKw?.push(me>0?ke/Le/1e3:0),l?.pack){let pe=l.pack;pe.soc.push(Ce),pe.amps.push(xe),pe.volts.push(y.ocv(Ce)-xe*y.resistance(Ce,qe)),pe.cellC.push(qe)}if(E){let pe=E.rpm(ee),he=E.th.derate(pe,D,E.peak(pe));he<z&&(z=he),he<1&&I<0&&(I=Y),B+=me,he<1&&(_+=me);let Qe=E.torque(Ne,pe,he),ve=E.th.lossW(pe,Qe,D);O+=ve*me,i&&(i.windingC.push(D),i.derate.push(he),i.lossW.push(ve),i.torqueNm.push(Qe),i.ampsRms.push(E.amps(Qe))),D=E.th.step(D,ve,me),D>N&&(N=D)}else L&&i&&i.torqueNm.push(L.torque(Ne,L.rpm(ee),1))}return{drive:A,regen:w,net:A-w,chargeAh:P/3600,loss:T/Yi,socEnd:k,shortAt:S,cutoffAt:F,emptyAt:C,tempEndC:x,tempMaxC:M,...E?{motorTempEndC:D,motorTempMaxC:N,motorLossKwh:O/Yi,motorDerateMin:z,motorDerateAt:I,motorDerateTimeFrac:B>0?_/B:0}:{}}}var ZI=.5,JI=.02,e2=6;function $M(e,t,r,n,o,a,s,i){let c=n(),l=1,u=d=>{let h=BM(),b=Ka(e,t,d.v,d.ax,r,o,a,h,s,void 0,{ay:d.ay,bank:i,...d.axScrub?{scrub:d.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 f=m.trace.derate.slice(),p=!1;for(let d=0;d<e2;d++){let h=n(f);l++;let b=Math.abs(h.laptime-c.laptime);if(c=h,m=u(c),b<JI){p=!0;break}let g=m.trace.derate,y=new Array(f.length);for(let R=0;R<f.length;R++)y[R]=f[R]+ZI*((g[R]??1)-f[R]);f=y}return{lap:c,derate:f,solves:l,converged:p,peakWindingC:m.peak,derateTimeFrac:m.frac}}var t2=.1;function GM(e){let t=e.power_limit_kw?.value??0;return t>0?t*1e3:0}function Yb(e,t,r){return e.motorModel?.kind==="ice"?1/0:Cr(Ga(e)).maxPower(t??e.soc.value,r,GM(e)).watts}function dm(e,t,r,n){let o=Yb(e,r,n);if(!Number.isFinite(o))return 1/0;if(o<=0)return 0;let a=Math.max(t2,t),s=Hb(e),i=o*(e.effi_pgb?.value??.9)/a;return o*s(t,i)/a}var r2=180/Math.PI;function fm(e,t,r,n){let o=e*t,a=e*(1-t);return o/r-a/n}var hm=e=>e*9.81*r2;var Kq=Math.PI/180;function bm(e,t,r,n=0){let o=Pe(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?fm(e.massTotal,e.frontMassFrac,2*i,2*c):0,u=hm(l),m=u>.15?"understeer":u<-.15?"oversteer":"neutral";return{gradient:u,balance:m,cAlphaFront:i,cAlphaRear:c}}var qq=Math.PI/180,Qq=180/Math.PI;var KM=2220446049250313e-31;function a2(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 f=0;f<t;f++)e[a][f]*=m;for(let f=0;f<t;f++)e[f][a]*=l}}}}}function s2(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 i2(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])<=KM*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 f=.5*(u-l),p=f*f+m,d=Math.sqrt(Math.abs(p));l+=s,p>=0?(d=f+(f>=0?Math.abs(d):-Math.abs(d)),r[a-1]=r[a]=l+d,d!==0&&(r[a]=l-m/d),n[a-1]=n[a]=0):(r[a-1]=r[a]=l+f,n[a]=d,n[a-1]=-d),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 f=a-2,p=0,d=0,h=0;for(;f>=c;f--){let b=e[f][f],g=l-b,y=u-b;p=(g*y-m)/e[f+1][f]+e[f][f+1],d=e[f+1][f+1]-b-g-y,h=e[f+2][f+1];let R=Math.abs(p)+Math.abs(d)+Math.abs(h);if(p/=R,d/=R,h/=R,f===c)break;let k=Math.abs(e[f][f-1])*(Math.abs(d)+Math.abs(h)),v=Math.abs(p)*(Math.abs(e[f-1][f-1])+Math.abs(b)+Math.abs(e[f+1][f+1]));if(k<=KM*v)break}for(let b=f+2;b<=a;b++)e[b][b-2]=0,b!==f+2&&(e[b][b-3]=0);for(let b=f;b<=a-1;b++){b!==f&&(p=e[b][b-1],d=e[b+1][b-1],h=b!==a-1?e[b+2][b-1]:0,l=Math.abs(p)+Math.abs(d)+Math.abs(h),l!==0&&(p/=l,d/=l,h/=l));let g=Math.sqrt(p*p+d*d+h*h),y=p>=0?g:-g;if(y!==0){b===f?c!==f&&(e[b][b-1]=-e[b][b-1]):e[b][b-1]=-y*l,p+=y,l=p/y,u=d/y;let R=h/y;d/=p,h/=p;for(let v=b;v<=a;v++){let x=e[b][v]+d*e[b+1][v];b!==a-1&&(x+=h*e[b+2][v],e[b+2][v]-=x*R),e[b+1][v]-=x*u,e[b][v]-=x*l}let k=a<b+3?a:b+3;for(let v=c;v<=k;v++){let x=l*e[v][b]+u*e[v][b+1];b!==a-1&&(x+=R*e[v][b+2],e[v][b+2]-=x*h),e[v][b+1]-=x*d,e[v][b]-=x}}}}}}while(c<a-1&&a>=0)}return r.map((i,c)=>({re:i,im:n[c]}))}function HM(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 a2(r),s2(r),i2(r)}function zM(e){let t=[],r=new Array(e.length).fill(!1),n=HM(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 Wb(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 f=e[c][c],p=t[c][c],d=f*f+p*p;for(let h=c+1;h<r;h++){let b=(e[h][c]*f+t[h][c]*p)/d,g=(t[h][c]*f-e[h][c]*p)/d;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 f=0,p=0;for(let d=c+1;d<r;d++)f+=e[c][d]*o[d]-t[c][d]*a[d],p+=e[c][d]*a[d]+t[c][d]*o[d];o[c]=-(f*l+p*u)/m,a[c]=-(p*l-f*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 c2(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 Wb(r,n)}function gm(e,t=r=>c2(e,r)){return zM(e).map(r=>({...r,vector:t(r.eigenvalue)}))}function Ha(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 YM(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 Ha(gm(i),c,0)}function WM(e,t,r,n){let o=(r==="front"?t.sprungFront:t.sprungRear)/2;if(o<=0)return{dampingRatio:0,criticalDamping:0,naturalFreqDamped:0};let a=r==="front"?t.rideRateFront:t.rideRateRear,s=r==="front"?e.wheelRateFront+(e.heaveSpringFront??0):e.wheelRateRear+(e.heaveSpringRear??0),i=YM({sprungMass:o,unsprungMass:e.unsprungCornerMass??e.unsprungPerCorner,springRate:s,damperRate:n,tireRate:Ze(e,r),tireDamping:e.tireDamping}),c=2*Math.sqrt(a*1e3*o);return{dampingRatio:i?.dampingRatio??0,criticalDamping:c/1e3,naturalFreqDamped:i?.dampedFreq??0}}function ym(e,t,r){let n=Te(e);return{front:WM(e,n,"front",t??n.rideDampingFront),rear:WM(e,n,"rear",r??n.rideDampingRear)}}var uQ=180/Math.PI;var jb=["FL","FR","RL","RR"],ce={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},za=20,jM=[ce.zFL,ce.zFR,ce.zRL,ce.zRR],UM=[ce.vzFL,ce.vzFR,ce.vzRL,ce.vzRR],Zr={fzFL:0,fzFR:1,fzRL:2,fzRR:3,fzBody:4,myBody:5,mxBody:6,fx:7,fy:8,mz:9},Ub=10;function xm(e){let t=Array.from({length:za},()=>new Array(za).fill(0)),r=Array.from({length:za},()=>new Array(Ub).fill(0));t[ce.zFL][ce.vzFL]=1,t[ce.zFR][ce.vzFR]=1,t[ce.zRL][ce.vzRL]=1,t[ce.zRR][ce.vzRR]=1,t[ce.zBody][ce.vzBody]=1,t[ce.pitch][ce.pitchRate]=1,t[ce.roll][ce.rollRate]=1,t[ce.x][ce.vx]=1,t[ce.y][ce.vy]=1,t[ce.yaw][ce.yawRate]=1;let{inertia:n}=e,o=[1,0,3,2],a=(s,i,c,l)=>{s[jM[i]]-=c,s[UM[i]]-=l,s[ce.zBody]+=c,s[ce.vzBody]+=l,s[ce.pitch]-=c*e.leverX[i],s[ce.pitchRate]-=l*e.leverX[i],s[ce.roll]+=c*e.leverY[i],s[ce.rollRate]+=l*e.leverY[i]};for(let s=0;s<4;s++){let i=s<2,c=M=>M?i?M.front:M.rear:0,l=e.springRate[s]+c(e.heaveSpring),u=e.springRate[s]+c(e.arb),m=e.damperRate[s]+c(e.heaveDamper),f=e.damperRate[s]+c(e.rollDamper),p=(l+u)/2,d=(l-u)/2,h=(m+f)/2,b=(m-f)/2,g=new Array(za).fill(0);a(g,s,p,h),(d!==0||b!==0)&&a(g,o[s],d,b);let y=e.wheelMass[s],R=e.leverX[s],k=e.leverY[s],v=jM[s],x=UM[s];for(let M=0;M<za;M++){let A=g[M];A!==0&&(t[x][M]+=A/y,t[ce.vzBody][M]-=A/e.bodyMass,t[ce.pitchRate][M]+=R*A/n.yy,t[ce.rollRate][M]-=k*A/n.xx)}t[x][v]-=e.tyreRate[s]/y,t[x][x]-=e.tyreDamping[s]/y,r[x][Zr.fzFL+s]=1/y}return r[ce.vzBody][Zr.fzBody]=1/e.bodyMass,r[ce.pitchRate][Zr.myBody]=1/n.yy,r[ce.rollRate][Zr.mxBody]=1/n.xx,r[ce.vx][Zr.fx]=1/e.totalMass,r[ce.vy][Zr.fy]=1/e.totalMass,r[ce.yawRate][Zr.mz]=1/n.zz,{A:t,B:r,params:e}}function Xb(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,f=Ze(e,"front")*1e3,p=Ze(e,"rear")*1e3,d=(e.tireDamping??0)*1e3;return{bodyMass:i,totalMass:e.massTotal,wheelMass:[s,s,s,s],inertia:{xx:e.rollInertia??i*.6*.6,yy:e.pitchInertia??i*1.2*1.2,zz:e.yawInertia??e.massTotal*1.2*1.2},leverX:[r,r,-n,-n],leverY:[o,-o,a,-a],springRate:[c,c,l,l],damperRate:[u,u,m,m],tyreRate:[f,f,p,p],tyreDamping:[d,d,d,d],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}}}var XM=ce.rollRate+1;function qM(e){let t=e.params,r=[...t.wheelMass,t.bodyMass,t.inertia.yy,t.inertia.xx];if(!r.every(i=>i>0))return{};let n=e.A.slice(0,XM).map(i=>i.slice(0,XM));if(!n.every(i=>i.every(Number.isFinite)))return{};let a=gm(n,i=>{let c=i.re*i.re-i.im*i.im,l=2*i.re*i.im,u=r.map((f,p)=>r.map((d,h)=>(p===h?c:0)-i.re*n[2*p+1][2*h+1]-n[2*p+1][2*h])),m=r.map((f,p)=>r.map((d,h)=>(p===h?l:0)-i.im*n[2*p+1][2*h+1]));return Wb(u,m)}),s=i=>{let c=r.map((u,m)=>u*(i[m].re**2+i[m].im**2)),l=c.reduce((u,m)=>u+m,0)||1;return[c[0]+c[1]+c[2]+c[3],c[4],c[5],c[6]].map(u=>u/l)};return{heave:Ha(a,s,1),pitch:Ha(a,s,2),roll:Ha(a,s,3)}}function QM(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 Rm(e){let t=Te(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=qM(xm(Xb(e)));return{roll:QM(m.roll,a,s),pitch:QM(m.pitch,l,u)}}var vm=9.81,Jr=Math.PI/180;function ZM(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 Ya(e,t,r,n,o){let{wb:a,lf:s,lr:i,m:c}=ZM(e),l=0;for(let R=0;R<16;R++){let k=l/r,v=o-n-s*k/r,x=-n+i*k/r,M=Pe(e,l/vm,0,r),A=Math.max(0,M.FL+M.FR),w=Math.max(0,M.RL+M.RR),T=t(v,A),P=t(x,w),S=(T*Math.cos(o)+P)/c;if(l=.5*(l+S),Math.abs(S-l)<1e-4)break}let u=l/r,m=o-n-s*u/r,f=-n+i*u/r,p=Pe(e,l/vm,0,r),d=Math.max(0,p.FL+p.FR),h=Math.max(0,p.RL+p.RR),b=t(m,d),g=t(f,h),y=s*b*Math.cos(o)-i*g;return{ay:l/vm,cn:y/(c*vm*a)}}function qb(e,t,r,n={}){let o=Math.max(8,r),a=(n.betaMaxDeg??10)*Jr,s=(n.deltaMaxDeg??10)*Jr,i=n.nLines??9,c=n.nPts??21,l=(g,y,R,k)=>R===1?g:g+(y-g)*k/(R-1),u=[],m={ay:[],cn:[]},f=0;for(let g=0;g<i;g++){let y=l(-s,s,i,g),R=[],k=[],v=[],x=[];for(let M=0;M<c;M++){let A=l(-a,a,c,M),w=Ya(e,t,o,A,y);R.push(w.ay),k.push(w.cn),v.push(A/Jr),x.push(y/Jr),Math.abs(w.ay)>f&&(f=Math.abs(w.ay))}u.push({label:`\u03B4 ${(y/Jr).toFixed(0)}\xB0`,ay:R,cn:k,betaDeg:v,deltaDeg:x});for(let M=1;M<k.length;M++)if(k[M-1]===0||k[M-1]<0!=k[M]<0){let A=k[M-1]===k[M]?0:k[M-1]/(k[M-1]-k[M]);m.ay.push(R[M-1]+A*(R[M]-R[M-1])),m.cn.push(0);break}}let p=[];for(let g=0;g<i;g++){let y=l(-a,a,i,g),R=[],k=[],v=[],x=[];for(let M=0;M<c;M++){let A=l(-s,s,c,M),w=Ya(e,t,o,y,A);R.push(w.ay),k.push(w.cn),v.push(y/Jr),x.push(A/Jr)}p.push({label:`\u03B2 ${(y/Jr).toFixed(0)}\xB0`,ay:R,cn:k,betaDeg:v,deltaDeg:x})}let d=.5*Jr,h=(Ya(e,t,o,d,0).cn-Ya(e,t,o,-d,0).cn)/(2*d),b=(Ya(e,t,o,0,d).cn-Ya(e,t,o,0,-d).cn)/(2*d);return{isoBeta:p,isoDelta:u,trim:m,maxAy:f,stability:h,control:b,speed:o}}function l2(e){return!e.corneringStiffnessFront||!e.corneringStiffnessRear?null:{Cf:2*e.corneringStiffnessFront,Cr:2*e.corneringStiffnessRear}}function ji(e,t){let r=l2(e);if(!r)return null;let{Cf:n,Cr:o}=r,{wb:a,lf:s,lr:i,m:c}=ZM(e),l=e.yawInertia??c*1*1,u=Math.max(3,t),m=-(n+o)/(c*u),f=(-s*n+i*o)/(c*u)-u,p=(-s*n+i*o)/(l*u),d=-(s*s*n+i*i*o)/(l*u),h=m+d,b=m*d-f*p,g=h*h-4*b,y,R,k;if(g<0)y=h/2,R=Math.sqrt(Math.max(0,b)),k=R>0?-h/(2*R):1;else{let C=Math.sqrt(g);y=Math.max((h+C)/2,(h-C)/2),R=Math.sqrt(Math.abs(b)),k=R>0?-h/(2*R):1}let v=h<0&&b>0,x=fm(c,e.frontMassFrac,n,o),M=hm(x),A=M>.15?"understeer":M<-.15?"oversteer":"neutral",w=s*n-i*o,T=C=>C*3.6,P=null,S=null;w>1e-6?S=T(Math.sqrt(n*o*a*a/(c*w))):w<-1e-6&&(P=T(Math.sqrt(n*o*a*a/(c*-w))));let F=u/(a+x*u*u);return{stable:v,yawFreq:R/(2*Math.PI),dampingRatio:k,eigReal:y,understeerGradient:M,balance:A,characteristicSpeed:P,criticalSpeed:S,yawRateGain:F}}var JM=Math.PI/180;function rS(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 eS(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 nS(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,f]of[[s,1-c],[Math.min(o-1,s+1),c]])if(!(f<=0))for(let[p,d]of[[i,1-l],[Math.min(a-1,i+1),l]])d<=0||(u+=f*d*n(e.isoDelta[m],p,m));return u}function oS(e,t,r){let n=e.isoDelta[0],o=(n.betaDeg[1]-n.betaDeg[0])*JM||1,a=e.isoDelta.length>1?(e.isoDelta[1].deltaDeg[0]-e.isoDelta[0].deltaDeg[0])*JM:1,s=x=>nS(e,t,r,x),i=s((x,M)=>x.ay[M]),c=s((x,M)=>x.cn[M]),l=s((x,M)=>x.betaDeg[M]),u=s((x,M)=>x.deltaDeg[M]),m=s((x,M)=>eS(x.cn,M,o)),f=s((x,M,A)=>eS(e.isoDelta.map(w=>w.cn[M]),A,a||1)),p=Math.max(1e-6,e.maxAy),d=Math.abs(i)/p,h=Math.max(1e-6,...e.isoDelta.flatMap(x=>x.cn.filter(Number.isFinite).map(Math.abs))),b=Math.abs(c)/h,g=i===0?c:c*Math.sign(i),y=[];y.push(`${rS(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 R=Math.abs(e.stability)>1e-9?m/e.stability:1;R<.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."):R<.85?y.push(`Yaw stiffness is down to about ${(100*R).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*R).toFixed(0)} %), so the car still opposes a change in body slip about as firmly as it does in a straight line.`);let k=Math.abs(e.control),v=k>1e-9?Math.abs(f)/k: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.`),d>.97?y.push(`At the edge of the diagram: ${Math.abs(i).toFixed(2)} g is essentially all this car has at this speed.`):d<.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:f,gripUsed:d,notes:y}}var tS=1e-4;function Qb(e){let t=null,r=f=>{if(!t)return!0;let p=Math.abs(f),d=Math.abs(t.ay);return p>d*(1+tS)?!0:p<d*(1-tS)?!1:f>0&&t.ay<0};for(let f=0;f<e.isoDelta.length;f++){let p=e.isoDelta[f];for(let d=1;d<p.cn.length;d++){if(!(p.cn[d-1]===0||p.cn[d-1]<0!=p.cn[d]<0))continue;let b=p.cn[d-1]===p.cn[d]?0:p.cn[d-1]/(p.cn[d-1]-p.cn[d]),g=p.ay[d-1]+b*(p.ay[d]-p.ay[d-1]);r(g)&&(t={ay:g,d:f,b:b<.5?d-1:d})}}if(!t)return null;let n=oS(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}}var u2=["tv_kp"];function aS(e=0){let t=e<0,r=e>0,n=t||r,o=[{key:"damper_front",why:"dampers act on velocity; every point here is at constant attitude"},{key:"damper_rear",why:"dampers act on velocity; every point here is at constant attitude"},{key:"tire_vertical_damping",why:"tyre damping acts on velocity; every point here is at constant attitude"},{key:"I_yaw",why:"inertia resists change; a steady corner has none"},{key:"I_roll",why:"inertia resists change; a steady corner has none"},{key:"I_pitch",why:"inertia resists change; a steady corner has none"},{key:"capacity",why:"energy does not enter a single steady-state point"},{key:"ocv",why:"energy does not enter a single steady-state point"},{key:"soc",why:"energy does not enter a single steady-state point"},...u2.map(s=>({key:s,why:"the feedback gain multiplies a yaw error, and a trimmed point has none \u2014 the feedforward does move this diagram"}))];t||o.push({key:"brake_balance",why:r?"the diagram is drawn under acceleration, not braking":"no braking: the diagram is drawn at constant speed"});let a=n?"the longitudinal condition is set directly; what a motor could deliver is the lap solver\u2019s question":"no tractive force is applied at a constant speed";for(let s of["gear_ratio","power_scale","power_limit_kw","driven_wheels","effi_pgb"])o.push({key:s,why:a});for(let s of["I_wheel","I_rotor"])o.push({key:s,why:n?"rotating inertia is longitudinal, and `ax` is set here rather than solved \u2014 nothing in this picture spins a wheel up":"rotating inertia only acts where the car changes speed"});return o.push({key:"v_limit_endurance",why:"a limiter constrains a lap\u2019s speed profile; this diagram is drawn at one imposed speed"}),o.push({key:"endurance_reserve",why:"an energy budget sets the long event\u2019s speed ceiling; this diagram is drawn at one imposed speed"}),o.push({key:"fr_0",why:n?"rolling resistance is a drag term; `ax` is what the car does, not what the tyres are handed":"rolling resistance is longitudinal"}),o.push({key:"r_dyn",why:n?"the force each tyre carries is set here in newtons; a radius would only convert it to a torque":"the rolling radius only matters where a wheel is driven or braked"}),o}var m2=aS(0);function sS(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 p2=sS(0);var d2=9.81;function f2(e){let t=e.wheelbase/1e3;return{lf:t*(1-e.frontMassFrac),lr:t*e.frontMassFrac}}function Ui(e,t,r,n){let o=t.tire;if(!o)return null;let s=(r==="limit"?xb(e,o,t.speed):Mn(e,o,t.speed,t.ayG)).wheels;return Ir(n??no(o,e.massTotal*d2*1.2),{FL:s.FL,FR:s.FR,RL:s.RL,RR:s.RR},f2(e))}function h2(e){if(!e.tire)return e.cornerStiffness;let t=ye(e.tire,"front"),r=ye(e.tire,"rear");return{front:n=>t.corneringStiffness(n),rear:n=>r.corneringStiffness(n)}}var iS=[{key:"understeer",label:"Understeer gradient",unit:"\xB0/g",compute:(e,t)=>bm(e,t.ayG,h2(t),t.speed).gradient},{key:"rollGradient",label:"Roll gradient",unit:"\xB0/g",compute:e=>Te(e).rollGradient},{key:"pitchGradient",label:"Pitch gradient",unit:"\xB0/g",compute:e=>Te(e).pitchGradient},{key:"tlltdFront",label:"TLLTD front",unit:"%",compute:e=>100*Df(e)},{key:"rollStiffFront",label:"Front roll-stiffness",unit:"%",compute:e=>100*Te(e).frontRollStiffFrac},{key:"rideFreqFront",label:"Ride freq front",unit:"Hz",compute:e=>Te(e).rideFreqFront},{key:"rideFreqRear",label:"Ride freq rear",unit:"Hz",compute:e=>Te(e).rideFreqRear},{key:"rollFreq",label:"Roll-mode freq",unit:"Hz",compute:e=>Rm(e).roll.freq},{key:"pitchFreq",label:"Pitch-mode freq",unit:"Hz",compute:e=>Rm(e).pitch.freq},{key:"zetaFront",label:"Damping \u03B6 front",unit:"-",compute:e=>ym(e).front.dampingRatio},{key:"zetaRear",label:"Damping \u03B6 rear",unit:"-",compute:e=>ym(e).rear.dampingRatio},{key:"yawFreq",label:"Yaw natural freq",unit:"Hz",compute:(e,t)=>ji(e,t.speed)?.yawFreq??NaN},{key:"yawZeta",label:"Yaw damping \u03B6",unit:"-",compute:(e,t)=>ji(e,t.speed)?.dampingRatio??NaN},{key:"stabilitySpeed",label:"Char./critical speed",unit:"km/h",compute:(e,t)=>{let r=ji(e,t.speed);return r?r.criticalSpeed??r.characteristicSpeed??NaN:NaN}},{key:"maxAy",label:"Max lateral accel",unit:"g",compute:(e,t)=>t.fyAxle?qb(e,t.fyAxle,t.speed,{betaMaxDeg:12,deltaMaxDeg:12}).maxAy:NaN},{key:"yawReserveRear",label:"Yaw stability reserve",unit:"N\xB7m",compute:(e,t)=>Ui(e,t,"operating")?.stabil??NaN},{key:"yawReserveFront",label:"Yaw agility reserve",unit:"N\xB7m",compute:(e,t)=>Ui(e,t,"operating")?.agil??NaN},{key:"limitBalance",label:"Limit balance (+US / \u2212OS)",unit:"-",compute:(e,t)=>Ui(e,t,"limit")?.rel??NaN},{key:"yawStiffness",label:"Yaw stiffness N_\u03B2",unit:"N\xB7m/rad",compute:(e,t)=>t.tire?yb(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorque",label:"Steering holding torque",unit:"N\xB7m",compute:(e,t)=>t.tire?bb(e,t.tire,t.speed,t.ayG):NaN},{key:"steeringTorqueGradient",label:"Steering feedback gradient",unit:"N\xB7m/g",compute:(e,t)=>t.tire?gb(e,t.tire,t.speed,t.ayG):NaN}],Zb=Object.fromEntries(iS.map(e=>[e.key,e]));var en=9.81;function b2(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 g2={front:!1,rear:!0};function Wa(e,t,r){let n=e.muX(t)*t,o=e.muY(t)*t;if(!(n>0))return 0;let a=o>0?Math.min(1,r/o):1;return n*Math.sqrt(1-a*a)}function cS(e,t,r,n,o,a){let s=e[t]+e[r];if(!(s>0))return;let i=Wa(n,o[t],a[t]),c=Wa(n,o[r],a[r]);i+c>0||(i=n.muX(o[t])*o[t],c=n.muX(o[r])*o[r]),i+c>0&&(e[t]=s*i/(i+c),e[r]=s-e[t])}function lS(e,t,r,n,o,a={},s="open"){if(!e.rear)return 1;if(!e.front)return 0;let i=(f,p,d)=>d?gi(f,p,d):s==="own"?f+p:2*Math.min(f,p),c=i(Wa(n,t.FL,r.FL),Wa(n,t.FR,r.FR),a.front),l=i(Wa(o,t.RL,r.RL),Wa(o,t.RR,r.RR),a.rear);if(c+l>0)return c/(c+l);let u=n.muX(t.FL)*t.FL+n.muX(t.FR)*t.FR,m=o.muX(t.RL)*t.RL+o.muX(t.RR)*t.RR;return u+m>0?u/(u+m):.5}function Jb(e,t,r,n){return{car:t?pS(t,r.loadFactor[n]):e,ayTyre:We(r.ay[n],r.bank?.[n]??0),axCar:r.ax[n]-(r.axGrade?.[n]??0)}}function uS(e,t){if(!e.aero?.model)return 0;let r=Math.min(t.v.length,t.ax.length,t.ay.length),n=t.loadFactor?Mm(e):void 0,o=0,a=0;for(let s=0;s<r;s++){let i=t.ds?.[s]??1,c=Jb(e,n,t,s);o+=i,Lf(c.car,t.v[s],c.axCar/en,c.ayTyre/en)&&(a+=i)}return o>0?a/o:0}function mS(e,t,r){let n=Zt(ye(t,"front")),o=Zt(ye(t,"rear")),a=Math.min(r.v.length,r.ax.length,r.ay.length),s=r.loadFactor?Mm(e):void 0,i=0,c=0;for(let l=0;l<a;l++){let u=r.ds?.[l]??1,m=Jb(e,s,r,l);i+=u;let f=Pe(m.car,m.ayTyre/en,m.axCar/en,r.v[l]);(f.FL>n||f.FR>n||f.RL>o||f.RR>o)&&(c+=u)}return i>0?c/i:0}function km(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=Si(t,e.massTotal*en*1.2),l=Ra(c,"front"),u=Ra(c,"rear"),m={mu:1},f=V=>({muX:G=>m.mu*V.muX(G),muY:G=>m.mu*V.muY(G)}),p=r.mu?f(l):l,d=r.mu?u===l?p:f(u):u,h=r.mu?{front:p,rear:d}:c,b=gt(ye(t,"front")),g=gt(ye(t,"rear")),y=n.perWheel?Nf(b,l):null,R=n.perWheel?g===b?y:Nf(g,u):null,k=n.driven??g2,v={front:Wt(e,"front",1),rear:Wt(e,"rear",1)},x={front:0,rear:0},M=new Array(o),A=new Array(o),w=new Array(o),T=1/0,P=0,S=0,F=Zt(b),C=Zt(g),L=0,E=0,D=0,N=0,O=0,z=0,I=["FL","FR","RL","RR"],_=n.perWheel?Object.fromEntries(I.map(V=>[V,{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,B=r.loadFactor?Mm(e):void 0;for(let V=0;V<o;V++){let G=Jb(e,B,r,V),{ayTyre:H,axCar:W}=G,J=H/en,Y=Pe(G.car,J,W/en,r.v[V]),ee=r.mu?mm(r.mu,V):1;m.mu=ee;let ne=e.massTotal*H,de=ne*i/a,j=ne*s/a,Z=Qs(b,de/ee,Y.FL,Y.FR,O),re=Qs(g,j/ee,Y.RL,Y.RR,z);O=Z,z=re;let oe={FL:ee*Math.abs(b.Fy(Z,Y.FL,0)),FR:ee*Math.abs(b.Fy(Z,Y.FR,0)),RL:ee*Math.abs(g.Fy(re,Y.RL,0)),RR:ee*Math.abs(g.Fy(re,Y.RR,0))},le=(W-(r.axDrag?.[V]??0)-(r.axScrub?.[V]??0))/en,ue=le>0&&k.front?lS(k,Y,oe,p,d,v,"own"):0,ie=r.v[V]*r.v[V],fe=e.driveline?{Fz:Y,alpha:{front:Z,rear:re},curvature:ie>1?r.ay[V]/ie:0,seed:x,...ee!==1?{grip:ee}:{}}:void 0,Fe={...pb(e,le,r.v[V],t,J,ue,fe,ee)};le>0&&(v.front||cS(Fe,"FL","FR",p,Y,oe),v.rear||cS(Fe,"RL","RR",d,Y,oe));let we=!1,Re=!1;for(let Ce of["FL","FR","RL","RR"]){let qe=(Ce==="FL"||Ce==="FR"?p:d).muX(Y[Ce])*Y[Ce];Math.abs(Fe[Ce])>qe&&(we=!0),Y[Ce]>(Ce==="FL"||Ce==="FR"?F:C)&&(Re=!0)}Re&&(S+=r.ds?.[V]??1);let me=Ir(h,{FL:{Fz:Y.FL,Fy:oe.FL,Fx:Fe.FL},FR:{Fz:Y.FR,Fy:oe.FR,Fx:Fe.FR},RL:{Fz:Y.RL,Fy:oe.RL,Fx:Fe.RL},RR:{Fz:Y.RR,Fy:oe.RR,Fx:Fe.RR}},{lf:s,lr:i});if(M[V]=me.stabil,A[V]=me.agil,w[V]=me.rel,_){let Ce=.5*(Y.FL+Y.FR),qe=.5*(Y.RL+Y.RR),xe=p.muX(Ce)*Ce,ke=d.muX(qe)*qe;for(let Le of I){let pe=Y[Le],he=Le==="FL"||Le==="FR",Qe=he?p:d,ve=Qe.muY(pe)*pe,je=Qe.muX(pe)*pe,He=_[Le],it=he?Z:re;He.Fz[V]=pe,He.alpha[V]=it,He.Fy[V]=oe[Le],He.Fx[V]=Fe[Le],He.Mz[V]=pe>0?ee*(he?b:g).Mz(it,pe,0):0,He.FxCap[V]=je,He.FyCap[V]=ve;let ir=ve>0?Math.min(1,Math.abs(oe[Le])/ve):0,Ho=b2(Fe[Le],je,he?xe:ke),zo=he?y:R,ys=zo&&pe>0?zo.reach(pe,Math.sign(Fe[Le])*Ho,ir):1;He.used[V]=Math.hypot(ir,Ho)/ys}}me.stabil<T&&(T=me.stabil,P=V);let Ne=r.ds?.[V]??1;N+=Ne,me.diff>0&&(L+=Ne),we&&(E+=Ne),Lf(G.car,r.v[V],W/en,J)&&(D+=Ne)}return{stabil:M,agil:A,rel:w,minStabil:Number.isFinite(T)?T:0,minStabilAt:P,pastTurnoverFrac:N>0?S/N:0,understeerFrac:N>0?L/N:0,beyondFrac:N>0?E/N:0,aeroOutsideFrac:N>0?D/N:0,wheels:_}}function Mm(e){return Object.create(e,{loadFactor:{value:1,writable:!0,enumerable:!0}})}function pS(e,t){return e.loadFactor=t,e}var eg=9.81;function tg(e,t,r,n={}){let o=r.v.length,a=e.massTotal,s=zr(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),f=m-(r.axDrag?.[l]??0)-(r.axScrub?.[l]??0),p=-a*f;if(!(p>0))continue;let d=We(r.ay[l],r.bank?.[l]??0)/eg,h=Math.min(.99,Math.max(.01,Ta(e,f/eg,u,t,d)));c.front[l]=p*h,c.rear[l]=p*(1-h);let b=i?wu(e,t,p,u,d):void 0;if(c.regen&&n.regen&&(c.regen[l]=b?Math.min(p,b.regenFront+b.regenRear):n.regen(p,u,m/eg)),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(p,u),u);c.pFront[l]=g.pFront,c.pRear[l]=g.pRear,c.pedalN[l]=g.pedalN}}return c}var RZ=Math.PI/180;var vZ=jb.map(Ai);var kZ=[ce.zFL,ce.zFR,ce.zRL,ce.zRR];var MZ=Array.from({length:ce.rollRate+1},(e,t)=>t);var P2=9.81,L2=.001,D2=.6,E2=2,bS=4;function gS(e,t,r,n=bS){let o=Math.min(e.v.length,t.npts),{ds:a,closed:s}=t,i=r.massTotal*P2*r.wheelbase,c=I2(e.ay.slice(0,o).map((m,f)=>m/Math.max(L2,e.v[f])),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 f=m===0?s?o-1:-1:m-1,p=m===o-1?s?0:-1:m+1;if(f<0||p<0)continue;let d=a[f]+a[m];if(!(d>0))continue;u[m]=e.v[m]*(c[p]-c[f])/d;let h=Math.sign(c[m]);l[m]=h===0?0:h*r.yawInertia*u[m]/i}return{demand:l,rdot:u}}function I2(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,f=0;for(let p=1;p<=s&&!(!r&&c+p>=o||(f+=t[(c+p-1)%o],!(f<l)));p++){let d=1-f/l;u+=d*e[(c+p)%o],m+=d}f=0;for(let p=1;p<=s&&!(!r&&c-p<0);p++){let d=(c-p+o)%o;if(f+=t[d],!(f<l))break;let h=1-f/l;u+=h*e[d],m+=h}i[c]=u/m}return i}function yS(e,t,r,n,o={}){let a=o.maxIter??20,s=o.tol??.001,i=Math.min(1,Math.max(.001,o.relax??D2)),c=o.smoothM??bS,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=wt(e.steady,t,n,l),m=[u.laptime],f=new Array(t.npts).fill(0),p=f.slice(),d=u,h=0,b=!1,g=0;for(let k=0;k<a;k++){h=k+1;let v=gS(d,t,r,c);f=v.demand.map((A,w)=>f[w]+i*(A-f[w])),p=v.rdot;let x=wt(e.steady,t,n,{...l,envelope:A=>e.at(f[A]??0)});m.push(x.laptime);let M=Math.abs(x.laptime-d.laptime);if(d=x,g=M<=s?g+1:0,g>=E2){b=!0;break}}let y=0,R=0;for(let k=0;k<t.npts;k++)R+=t.ds[k],e.clamps(f[k]??0)&&(y+=t.ds[k]);return{...d,steady:u,demand:f,rdot:p,history:m,iterations:h,converged:b,clampedFrac:R>0?y/R:0}}var DZ=Math.PI/180;var gJ=180/Math.PI;function ja(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=f=>{let p=e[f];return i*(r-s)*(r-p)/((a-s)*(a-p))+c*(r-a)*(r-p)/((s-a)*(s-p))+t[f]*(r-a)*(r-s)/((p-a)*(p-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 RS(e,t){let r=e.filter(p=>p.atLock),n=e.filter(p=>!p.atLock),o=r.length>0&&n.length>0&&r[r.length-1].v<n[0].v,a=p=>({vs:p.map(h=>h.v),ayMax:p.map(h=>h.ayMax),radius:p.map(h=>Math.max(h.v,t)**2/h.ayMax),accel:p[0].axAccelN.map((h,b)=>p.map(g=>g.axAccelN[b])),decel:p[0].axDecelN.map((h,b)=>p.map(g=>g.axDecelN[b])),scrub:p[0].axScrubN.map((h,b)=>p.map(g=>g.axScrubN[b]))}),s=(p,d)=>({axAccelN:p.accel.map(h=>ja(p.vs,h,d)),axDecelN:p.decel.map(h=>ja(p.vs,h,d)),axScrubN:p.scrub.map(h=>ja(p.vs,h,d))});if(!o){let p=a(e);return d=>({ayMax:ja(p.vs,p.ayMax,d),...s(p,d)})}let i=a(r),c=a(n),l=i.vs[i.vs.length-1],u=c.vs[0],m=p=>Math.max(p,t)**2/ja(i.vs,i.radius,p),f=p=>p>=u||c.vs.length<2?ja(c.vs,c.ayMax,p):c.ayMax[0]+(c.ayMax[1]-c.ayMax[0])/(c.vs[1]-c.vs[0])*(p-u);return p=>{if(p<=l)return{ayMax:m(p),...s(i,p)};if(p>=u)return{ayMax:f(p),...s(c,p)};let d=m(p),h=f(p);return d<h?{ayMax:d,...s(i,p)}:{ayMax:h,...s(c,p)}}}function Q2(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 vS(e,t,r,n,o){let a=r>t?Math.max(2,Math.min(5,Math.floor(n))):1,s=[];for(let f=0;f<a;f++)s.push(e(a===1?t:t+(r-t)*f/(a-1)));let i=RS(s,t),c=[],l=a,u=(f,p)=>{let d=.5*(f+p),h=e(d);l++;let b=Q2(i(d),h);s.splice(s.findIndex(g=>g.v>d),0,h),i=RS(s,t),b>o&&c.push({lo:f,hi:d,misfit:b},{lo:d,hi:p,misfit:b})},m=s.map(f=>f.v);for(let f=0;f+1<m.length&&l<n;f++)m[f+1]-m[f]>=1&&u(m[f],m[f+1]);if(m.length>1){let f=.5*(m[0]+m[1]);if(s.some(p=>p.v===f))for(let[p,d]of[[m[0],f],[f,m[1]]]){if(l>=n||d-p<1)break;let h=c.findIndex(b=>b.lo===p&&b.hi===d);h>=0&&c.splice(h,1),u(p,d)}}for(;l<n&&c.length>0;){let f=0;for(let b=1;b<c.length;b++)c[b].misfit>c[f].misfit&&(f=b);let{lo:p,hi:d,misfit:h}=c.splice(f,1)[0];if(h<=o)break;d-p<1||u(p,d)}return{anchors:s,at:i}}var Z2=2,J2=.5,Xi=Math.PI/180,kS=21,e_={nCoarse:11,nSteer:13,nNorm:41,nAngle:45},t_={nCoarse:11,nSteer:13,nNorm:41,nAngle:61},r_=.005,n_=.05,rg=e=>e<0?0:e>1?1:e;function o_(e,t,r,n){let o=e.massTotal,a=n.nSteer??7,s=(n.drivenFront?2:0)+(n.drivenRear?2:0),i=Pe(e,0,0,r),c=Math.max(1,(i.FL+i.FR+i.RL+i.RR)/4),l=8*Xi,u=0,m=(b,g,y)=>{for(let R=b;R<=g;R+=y){let k=Math.abs(t.Fy(R*Xi,c,0));k>u&&(u=k,l=R*Xi)}};m(1,45,1),m(Math.max(.1,l/Xi-1),l/Xi+1,.1);let f=[],p=[],d=[],h=[];for(let b=0;b<a;b++){let g=b/(a-1),y=l*(g+Math.sin(Math.PI/2*g))/2,R=Math.abs(t.Fy(y,c,0));f.push(4*R/o),p.push(s*Dt(t,c,R,!1)/o),d.push(4*Dt(t,c,R,!0)/o),h.push(-4*R*Math.sin(y)/o)}return f[0]=0,{ayMax:4*u/o,ay:f,axAccel:p,axDecel:d,axScrub:h,rollover:!1}}function Rr(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?t_:e_),{nCoarse:c,nSteer:l,nAngle:u}=i,m=Hr(0,1,i.nNorm).map(B=>Math.sin(Math.PI/2*B)),f=e.params,p=f.m.value,d=f.rho.value,h=f.fr_0.value,b=f.driven_wheels.value,g=f.power_scale.value,y=e.FG,R=Rt(f);s!==1&&(R.loadFactor=s);let k=xr(f),v=L1(0,n?.vRes??(e.engine?J2:Z2),e.vMax);v[v.length-1]<e.vMax&&v.push(e.vMax);let x=e.fRad.map(B=>B*b),M=e.fAxle,{drivenFront:A,drivenRear:w}=ho(e),T=fo(f,A,w),P=(B,V)=>{let G=M?yt(M.vVehicle,B,V):NaN;return Number.isFinite(G)?G:1/0},S=B=>{let V=B*B,{cl:G,cw:H,A:W}=sm(f,B,0,R),J=.5*d*-H*W*V,Y=.5*d*-G*W*V,ee=h*(-Y+y);return J+ee},F=B=>{let V=S(B)/p*T.powerFactor,G=S(B)/p*T.tractionFactor,H;if(e.engine){let J=S(B);H=Fa(e.engine,B,T.effective,J,g).accel-V}else if(M){let J=0;A&&(J+=P(M.fFront,B)),w&&(J+=P(M.fRear,B)),H=g*J/p*T.powerFactor}else{let J=yt(e.vVehicle,x,B),Y=g*J/p*T.powerFactor;H=Number.isFinite(Y)?Y:1/0}let W=dm(f,B,o)/p*T.powerFactor;return{axDrag:V,axDragTyre:G,axDrive:H,axPackCap:W,axPower:Math.min(H,W)}},C=v.map(F),L=e.vMax;for(let B=1;B<v.length;B++){let V=C[B].axDrive+C[B].axDrag;if(V>0)continue;let G=C[B-1].axDrive+C[B-1].axDrag;L=G>0?v[B-1]+(v[B]-v[B-1])*G/(G-V):v[B-1];break}let E=Math.min(e.vMax,(1+n_)*L),D=r==="fast"?o_:vb,N=B=>{let V=D(R,k,B,{drivenFront:A,drivenRear:w,nSteer:l,yawDemandCn:a,axDrag:S(B)/p,...f.diffYaw?{diffYaw:!0}:{}}),G=V.ay[0],H=V.ay[V.ay.length-1],W=ne=>Math.min(Math.max(ne*V.ayMax,G),H),J=m.map(ne=>yu(V.ay,V.axAccel,W(ne))*T.tractionFactor),Y=m.map(ne=>yu(V.ay,V.axDecel,W(ne))),ee=m.map(ne=>yu(V.ay,V.axScrub,W(ne))*T.tractionFactor);return{v:B,ayMax:V.ayMax,axAccelN:J,axDecelN:Y,axScrubN:ee,atLock:V.atLock===!0}},O=r==="fast"?0:Math.min(Iu,E),z=vS(N,O,E,c,i.anchorTol??r_),I=[],_=[];for(let B=0;B<v.length;B++){let V=v[B],{axDrag:G,axDragTyre:H,axDrive:W,axPackCap:J,axPower:Y}=C[B],{ayMax:ee,axAccelN:ne,axDecelN:de,axScrubN:j}=z.at(V);I.push({v:V,ayMax:ee,axTyreAcc:ne[0],axTyreDec:de[0],axDrive:W,axPackCap:J,axPower:Y,axDrag:G,axDragTyre:H,axAccelN:ne,axDecelN:de,axScrubN:j});let Z=[],re=[];for(let le=0;le<u;le++){let ue=Math.PI*le/(u-1),ie=ee*Math.cos(ue),fe=rg(Math.abs(Math.cos(ue)));Z.push({ax:Math.min(yt(m,ne,fe)+H,Y+G)+yt(m,j,fe),ay:ie,v:V})}for(let le=u-1;le>=0;le--){let ue=Math.PI*le/(u-1),ie=ee*Math.cos(ue),fe=rg(Math.abs(Math.cos(ue)));re.push({ax:yt(m,de,fe)+G+yt(m,j,fe),ay:ie,v:V})}let oe=(le,ue,ie)=>Array.from({length:kS},(fe,Fe)=>({ax:ue+(ie-ue)*(Fe+1)/(kS+1),ay:le,v:V}));_.push([...Z,...oe(-ee,Z[Z.length-1].ax,re[0].ax),...re,...oe(ee,re[re.length-1].ax,Z[0].ax)])}return{...SS(I,m),rows:I,norm:m,surf:_}}function Ua(e,t){return e?.length?t.map(r=>Am(e,r)):t.map(()=>0)}function Am(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 SS(e,t){let r=e[e.length-1].v,n=d=>{if(d<=e[0].v)return{i0:0,i1:0,t:0};if(d>=r)return{i0:e.length-1,i1:e.length-1,t:0};let h=0,b=e.length-1;for(;b-h>1;){let g=h+b>>1;e[g].v<=d?h=g:b=g}return{i0:h,i1:b,t:(d-e[h].v)/(e[b].v-e[h].v)}},o=d=>{let{i0:h,i1:b,t:g}=n(d);return{a:e[h],b:e[b],t:h===b?0:g}},a=(d,h,b)=>d===0||h===b?h:h+d*(b-h),s=(d,h,b,g)=>d===0?yt(t,h,g):a(d,yt(t,h,g),yt(t,b,g)),i=(d,h)=>h>=1?d.axPower:Math.min(h*d.axDrive,d.axPackCap),c=({a:d,b:h,t:b},g,y)=>d.axScrubN?y*s(b,d.axScrubN,h.axScrubN,g):0,l=d=>d.axDragTyre??d.axDrag,u=({a:d,b:h,t:b},g,y)=>{let R=y*a(b,d.ayMax,h.ayMax);return R>0?rg(g/R):1},m=(d,h,b=1,g=1)=>{let{a:y,b:R,t:k}=d,v=u(d,h,b),x=b*s(k,y.axAccelN,R.axAccelN,v)+a(k,l(y),l(R)),M=a(k,i(y,g),k===0?0:i(R,g))+a(k,y.axDrag,R.axDrag);return Math.min(x,M)+c(d,v,b)},f=(d,h,b=1,g=1)=>{let{a:y,b:R,t:k}=d,v=u(d,h,b),x=s(k,y.axDecelN,R.axDecelN,v);return(g===1||x>0?b*x:g*b*x)+a(k,y.axDrag,R.axDrag)+c(d,v,b)},p=({a:d,b:h,t:b},g,y=1)=>{let R=t.length-1,k=d.axAccelN,v=h.axAccelN,x=d.axDecelN,M=h.axDecelN,A=d.axScrubN,w=h.axScrubN,T=D=>k[D]+b*(v[D]-k[D]),P=D=>x[D]+b*(M[D]-x[D]),S=D=>A?y*(A[D]+b*(w[D]-A[D])):0,F=a(b,d.ayMax,h.ayMax),C=a(b,d.axDrag,h.axDrag),L=a(b,l(d),l(h)),E=a(b,d.axPower,h.axPower);for(let D=R;D>=0;D--){let N=Math.min(y*T(D)+L,E+C)+S(D),O=y*P(D)+C+S(D);if(!(g<=N+1e-6&&g>=O-1e-6))continue;if(D===R)return t[D]*y*F;let z=(V,G,H)=>{if(H(G))return 1;let W=(V-g)/(V-G);return W>0?Math.min(W,1):0},I=V=>g<=V+1e-6,_=V=>g>=V-1e-6,B=Math.min(z(y*T(D)+L+S(D),y*T(D+1)+L+S(D+1),I),z(E+C+S(D),E+C+S(D+1),I),z(y*P(D)+C+S(D),y*P(D+1)+C+S(D+1),_));return(t[D]+B*(t[D+1]-t[D]))*y*F}return 0};return{vMax:r,axAccel:(d,h,b=1,g=1)=>m(o(d),h,b,g),axDecel:(d,h,b=1,g=1)=>f(o(d),h,b,g),ay:(d,h,b=1)=>p(o(d),h,b),scrub:(d,h,b=1)=>{let g=o(d);return c(g,u(g,h,b),b)}}}function a_(e,t,r){let n=e.params,o=n.m.value,{drivenFront:a,drivenRear:s}=ho(e),i=fo(n,a,s);return c=>dm(n,c,t,r)/o*i.powerFactor}function qi(e,t,r,n){let o=a_(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{...SS(a,e.norm),rows:a,norm:e.norm}}var s_=[-.2,-.08,0,.06,.12,.2,.3];function AS(e,t=!1,r="twoTrack",n,o,a=s_){let s=[...new Set([...a,0])].sort((d,h)=>d-h),i=s.map(d=>Rr(e,t,r,n,o,d)),c=i[s.indexOf(0)],l=s[0],u=s[s.length-1],m=d=>{if(d<=l)return{i:0,t:0};if(d>=u)return{i:s.length-1,t:0};let h=0;for(;h<s.length-2&&s[h+1]<=d;)h++;return{i:h,t:(d-s[h])/(s[h+1]-s[h])}},f=d=>{let h=b=>{let{i:g,t:y}=m(b);return{a:d[g],b:d[Math.min(d.length-1,g+1)],t:y}};return b=>{let{a:g,b:y,t:R}=h(b);if(R===0)return g;let k=(v,x)=>v+R*(x-v);return{vMax:g.vMax,axAccel:(v,x,M=1,A=1)=>k(g.axAccel(v,x,M,A),y.axAccel(v,x,M,A)),axDecel:(v,x,M=1,A=1)=>k(g.axDecel(v,x,M,A),y.axDecel(v,x,M,A)),ay:(v,x,M=1)=>k(g.ay(v,x,M),y.ay(v,x,M)),scrub:(v,x,M=1)=>k(g.scrub?.(v,x,M)??0,y.scrub?.(v,x,M)??0)}}},p=d=>d<l||d>u;return{anchors:s,steady:c,clamps:p,at:f(i),atSoc(d,h,b){let g=i.map(y=>qi(y,d,h,b));return{anchors:s,steady:g[s.indexOf(0)],clamps:p,at:f(g)}}}}function FS(e,t,r,n="twoTrack",o){let a=[...new Set([...t,1])].sort((i,c)=>i-c),s=a.map(i=>i===1?r:Rr(e,!1,n,o,void 0,0,i));return{...MS(a,s),atSoc:(i,c,l)=>MS(a,s.map(u=>qi(u,i,c,l)))}}function MS(e,t){let r=e.length-1,n=1,o=0,a=0,s=0,i=1,c=0,l=0,u=p=>{if(n=1,!(p>e[0]))return void(o=0);if(p>=e[r])return void(o=r);let d=0;for(;d<r-1&&e[d+1]<=p;)d++;if(o=d,p===e[d])return;a=d+1;let h=e[d],b=e[d+1];if(r<2){n=2,c=(p-h)/(b-h),i=1-c;return}s=d===0?2:d+1===r||p-e[d-1]<e[d+2]-p?d-1:d+2;let g=e[s];n=3,i=(p-b)*(p-g)/((h-b)*(h-g)),c=(p-h)*(p-g)/((b-h)*(b-g)),l=(p-h)*(p-b)/((g-h)*(g-b))},m=p=>{let d=p(t[o]);if(n===1)return d;let h=p(t[a]);if(n===2)return i*d+c*h;let b=i*d+c*h+l*p(t[s]);return Math.min(Math.max(d,h),Math.max(Math.min(d,h),b))},f=(p,d,h,b,g)=>{if(u(p),n===1||h===0)return m(k=>g(k,h));let y=m(k=>k.ay(d,0,b));if(!(y>0))return m(k=>g(k,h));let R=h/y;return m(k=>g(k,R*k.ay(d,0,b)))};return{anchors:e,axAccel:(p,d,h,b=1,g=1)=>f(p,d,h,b,(y,R)=>y.axAccel(d,R,b,g)),axDecel:(p,d,h,b=1,g=1)=>{let y=R=>f(p,d,h,b,(k,v)=>k.axDecel(d,v,b,R));return g===1?y(1):Vb(y(g),y(1),g)},scrub:(p,d,h,b=1)=>f(p,d,h,b,(g,y)=>g.scrub?.(d,y,b)??0),ay:(p,d,h,b=1)=>{if(u(p),n===1||h===0)return m(k=>k.ay(d,h,b));let g=k=>h>0?k.axAccel(d,0,b):-k.axDecel(d,0,b),y=m(g);if(!(y>0))return m(k=>k.ay(d,h,b));let R=h/y;return m(k=>k.ay(d,R*g(k),b))}}}var wS=new WeakMap;function ng(e,t){let r=wS.get(e);if(!r){let n=Kr(e).regen?zb(t??It(e)):void 0;r={inp:Rt(e),ev:xr(e),...n?{regen:n}:{}},wS.set(e,r)}return r}function og(e,t,r){let n=ng(e,r);return tg(n.inp,n.ev,t,n.regen?{regen:n.regen}:{})}function ag(e){let t=xt(e);if(t.mode!=="hydraulic")return null;let r=a=>a.heat?{heat:Rh(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 i_(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 sg(e,t,r,n,o,a=Et){if(!e)return null;let s=i_(t);return{...e.front?{front:du(e.front.heat,e.front.discs,s.front,r,n,o.front,a)}:{},...e.rear?{rear:du(e.rear.heat,e.rear.discs,s.rear,r,n,o.rear,a)}:{}}}var c_=.5,l_=.02,u_=6,Fm=9,CS=1e-9,m_={FL:0,FR:0,RL:0,RR:0};function ig(e){return e?[...new Set([...e.padCurve.factor,1])].sort((t,r)=>t-r):[1]}function p_(e,t,r){let n=hr(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 TS(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 PS(e,t,r,n,o=()=>0){let a=Array.from({length:Fm},(m,f)=>r*f/(Fm-1)),s=ki(),{front:i,rear:c}=n,l=a.map(m=>{let f=o(m),p=h=>Yr(h,t,m,s).limitAt(0,0,m_,f).ax,d=p(e);return i.map(h=>c.map(b=>{if(h===1&&b===1)return 1;let g=d<0?p(p_(e,h,b))/d:1;return Math.abs(g-1)<CS?1:g}))}),u=a[1]-a[0];return{share(m,f,p){if(f===1&&p===1)return 1;let d=u>0?Math.min(Fm-2,Math.max(0,Math.floor(m/u))):0,h=u>0?Math.min(1,Math.max(0,(m-a[d])/u)):0,b=TS(i,f),g=TS(c,p),y=k=>{let v=l[k],x=Math.min(i.length-1,b.i+1),M=Math.min(c.length-1,g.i+1),A=v[b.i][g.i]+g.t*(v[b.i][M]-v[b.i][g.i]),w=v[x][g.i]+g.t*(v[x][M]-v[x][g.i]);return A+b.t*(w-A)},R=y(d)+h*(y(Math.min(Fm-1,d+1))-y(d));return Math.abs(R-1)<CS?1:R}}}function d_(e,t){let{front:r,rear:n}=t;return(o,a)=>e.share(a,r?.[o]??1,n?.[o]??1)}var f_=e=>(e.front??[]).every(t=>t===1)&&(e.rear??[]).every(t=>t===1);function LS(e,t,r){let n=e(),o=1,a=t(n);if(f_(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<u_;c++){let l=e(d_(r,s));o++;let u=Math.abs(l.laptime-n.laptime);if(n=l,u<l_){i=!0;break}a=t(n);let m=(d,h)=>d&&h?d.map((b,g)=>b+c_*((h[g]??1)-b)):d,f=m(s.front,a.front),p=m(s.rear,a.rear);s={...f?{front:f}:{},...p?{rear:p}:{}}}return{lap:n,pads:s,solves:o,converged:i}}function wn(e,t){let r=e.engine;if(!r||r.gears.length===0||t.length===0)return;let n=e.params,{drivenFront:o,drivenRear:a}=ho(e),s=fo(n,o,a).effective,i=n.power_scale.value,{up:c,down:l}=_h(r.engine.gearbox),u=r.engine.idleRpm,m=(f,p,d)=>(i*r.force(f,p)+d)/(s+r.inertiaMass(f,p));return{count:r.gears.length,up:c,down:l,kept:Nh(r.engine.gearbox),limitRpm:r.engine.limitRpm,best:f=>Fa(r,f,s,Am(t,f)*s,i).gear,share:(f,p)=>{let d=Am(t,f),h=d*s,b=Fa(r,f,s,h,i);if(p===b.gear)return 1;let g=b.accel-d;return g>0?Math.min(1,Math.max(0,(m(f,p,h)-d)/g)):0},rpm:(f,p)=>r.slipping(f,p)?u:r.rpm(f,p),vIdle:f=>r.gears[f]?.vIdle??0}}var DS=new WeakMap;function lg(e){let t=DS.get(e.ggv);return t===void 0&&(t=wn(e.vehicle,e.ggv.rows)??null,DS.set(e.ggv,t)),t??void 0}function h_(e){return e.gear&&e.engineRpm&&e.shifting?{gear:e.gear,rpm:e.engineRpm,shifting:e.shifting}:{}}function b_(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}:{},...h_(t)}}var Cm=class extends Error{constructor(t){super(t),this.name="EventError"}};function g_(e,t){let{ggv:r}=t,n=ut(t.numerics),o=n.accelStep,a=Math.max(1,Math.round(e.distance/o)),s=$a(r,new Array(a+1).fill(0),n);s[0].v=e.vStart??0;for(let d=0;d<s.length-1;d++){let h=s[d],b=s[d+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=lg(t),c=i?lm(s.map(d=>d.v),new Array(a).fill(o),!1,i,(d,h,b)=>r.axAccel(h,0,1,b)):void 0;if(c){for(let d=0;d<=a;d++)s[d].v=c.v[d];for(let d=0;d<a;d++)s[d].ax=(s[d+1].v*s[d+1].v-s[d].v*s[d].v)/(2*o)}let l=0;for(let d=0;d<a;d++){let h=s[d].v+s[d+1].v;h>0&&(l+=2*o/h)}let u=s.slice(0,a).map(d=>d.v),m=s.slice(0,a).map(d=>d.ax),f=new Array(a).fill(o),p=f.map((d,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:p,x:p,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:GS(t,f,[...u,s[a].v],m,1)}}function y_(e,t){let r=Math.max(1,Math.round(e.laps??1)),[n]=$a(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=GS(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 Tm(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 x_(e,t){let r=e.distance!=null?t.v_limit_endurance?.value??0:0;return r>0?r/3.6:void 0}function R_(e,t){if(e.distance==null||ht(t.motorModel))return 0;let r=t.endurance_reserve?.value??0;return r>0?Math.min(r,95)/100:0}var ES=1;function VS(e,t,r,n){return{v:r.v,ax:r.ax,ay:r.ay,ds:t.ds,axDrag:Ua(e.ggv.rows,r.v),...r.axScrub?{axScrub:r.axScrub}:{},axGrade:n,...t.bank?{bank:t.bank}:{}}}var IS=new WeakMap;function BS(e){let t=e.vehicle.params;if(!t.brakeFade)return null;let r=IS.get(t);if(r===void 0){let n=ag(t),o=n?xt(t):null;if(!n||!o||o.mode!=="hydraulic")r=null;else{let a=ng(t,e.vehicle),s=e.ggv.rows,i=PS(a.inp,a.ev,e.vehicle.vMax,{front:ig(o.hydraulic.front.heat),rear:ig(o.hydraulic.rear.heat)},c=>Ua(s,[c])[0]);r={discs:n,table:i}}IS.set(t,r)}return r}function v_(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=lg(e),u=(g,y)=>e.yaw?yS(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}:{}}):wt(qi(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=Fn(t.gradient,t.npts),f=g=>n.motorThermal?$M(e.vehicle,t.ds,e.energyOpts??Gr,y=>u(y,g),o,a,m,t.bank).lap:u(void 0,g),p=BS(e);if(!p)return f();let d=Wi(n),h=r.discC??{front:d,rear:d};return LS(f,g=>{let y=sg(p.discs,og(n,VS(e,t,g,m),e.vehicle),g.v,t.ds,h,d);return{...y?.front?{front:y.front.padFactor}:{},...y?.rear?{rear:y.rear.padFactor}:{}}},p.table).lap}function k_(e,t){let r=x_(e,t.vehicle.params),n=R_(e,t.vehicle.params);return n>0?A_(e,t,n,r):Qi(e,t,r)}function wm(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 _S=5,M_=.1,S_=.005,NS=12;function A_(e,t,r,n){let o=Qi(e,t,n),a=1,s=(d,h,b)=>({...d,energyTarget:{reserve:r,capKmh:h===void 0?null:h*3.6,met:b,solves:a}}),i=wm(o,r);if(i>=0)return s(o,n,!0);let c=Math.min(n??1/0,t.ggv.vMax),l=c/2,u=Qi(e,t,l);a++;let m=wm(u,r);for(;m<0&&l>_S&&a<NS;)c=l,i=m,l=Math.max(_S,l/2),u=Qi(e,t,l),a++,m=wm(u,r);if(m<0)return s(u,l,!1);let f=l,p=0;for(;a<NS&&c-l>M_&&m>S_;){let d=c-l,h=Math.min(c-.05*d,Math.max(l+.05*d,l+m*d/(m-i))),b=Qi(e,t,h);a++;let g=wm(b,r);g>=0?(l=h,m=g,u=b,f=h,p===1&&(i/=2),p=1):(c=h,i=g,p===-1&&(m/=2),p=-1)}return s(u,f,!0)}function $S(e,t,r){return r===0?e:e&&!t}function Qi(e,t,r){let n=t.track;if(!n)throw new Cm(`Event "${e.id}" needs a track.`);let o=Tm(e,n),a=e.standingStart??t.standingStart??!1,s=H=>$S(a,n.closed,H),i=t.vehicle.params,c=Cr(Ga(i)),l=c.capacityAh,u=i.soc.value,m=Wi(i),f=pm(c,m),p=0,d=0,h=0,b=0,g=[],y=!1,R=-1/0,k=0,v=0,x=!1,M=-1/0,A=0,w=0,T=-1/0,P=(H,W,J=1)=>{H.tempMaxC>T&&(T=H.tempMaxC),H.motorTempMaxC!==void 0&&(y=!0,x=!0,H.motorTempMaxC>R&&(R=H.motorTempMaxC),H.motorTempMaxC>M&&(M=H.motorTempMaxC),k+=(H.motorDerateTimeFrac??0)*W,A+=(H.motorDerateTimeFrac??0)*W,v+=(H.motorLossKwh??0)/J,w+=(H.motorLossKwh??0)/J)},S=null,F,C=ag(i),L={front:m,rear:m},E=null,D=BS(t)!==null,N=(H,W)=>D&&(Math.abs(H.front-W.front)>ES||Math.abs(H.rear-W.rear)>ES),O=(H,W,J)=>{let Y=Yb(i,H,W);if(E&&E.launch===J&&!C_(Y,E.pw)&&!N(L,E.discC))return E.lap;let ee=v_(t,n,{soc:H,packTempC:W,launched:J,...r?{vCeiling:r}:{},...D?{discC:L}:{}});return E={pw:Y,launch:J,discC:L,lap:ee},ee},z=Fn(n.gradient,n.npts),I=(H,W,J)=>Ka(t.vehicle,n.ds,H.v,H.ax,t.energyOpts,W,J,void 0,z,void 0,{ay:H.ay,bank:n.bank,...H.axScrub?{scrub:H.axScrub}:{}}),_=new WeakMap,B=(H,W)=>{let J=_.get(H);return J||(J=og(i,VS(t,n,H,z),t.vehicle),_.set(H,J)),sg(C,J,H.v,n.ds,W,m)},V=(H,W,J)=>{let Y=`${(100*J/n.npts).toFixed(0)} % of the way through lap ${H+1}`,ee=W.cutoffAt>=0&&W.cutoffAt<=W.emptyAt;return{lapsCompleted:H,lapsAsked:o,why:ee?`the pack reached its ${c.voltageFloor.toFixed(0)} V cut-off ${Y}`:`the pack ran out ${Y}`}};for(let H=0;H<o;H++){if(u<=0){F={lapsCompleted:H,lapsAsked:o,why:"the pack was empty"};break}let W=s(H),J=u,Y=f;x=!1,M=-1/0,A=0,w=0,T=-1/0;let ee=O(u,f,W),ne=I(ee,u,f);if(ne.emptyAt>=0){F=V(H,ne,ne.emptyAt);break}let j=O(ne.socEnd,ne.tempEndC,W).laptime-ee.laptime,Z,re,oe,le,ue=f,ie=-1,fe=null,Fe=1;if(j<=cg)Z=ee.laptime,re=ne.net,oe=ne.loss,le=ne.chargeAh,ue=ne.tempEndC,P(ne,Z),Fe=1;else{let Re=Math.min(F_,Math.max(2,Math.ceil(j/(2*cg))));Fe=Re;let me=u,Ne=f;Z=0,re=0,oe=0,le=0;for(let Ce=0;Ce<Re;Ce++){let qe=O(me,Ne,W),xe=I(qe,me,Ne),ke=xe.emptyAt>=0?xe.emptyAt/n.npts:1;if(ke*Re<1){ie=Math.round(n.npts*(Ce/Re+ke)),fe=xe;break}if(Z+=qe.laptime/Re,P(xe,qe.laptime/Re,Re),re+=xe.net/Re/ke,oe+=xe.loss/Re/ke,le+=xe.chargeAh/Re/ke,me-=xe.chargeAh/Re/ke/l,Ne+=(xe.tempEndC-Ne)/Re,me<=0){ie=Math.round(n.npts*(Ce+1)/Re),fe=xe;break}}if(ue=Ne,ie>=0&&fe){F=V(H,fe,ie);break}u=me}p+=Z,d+=re,h+=oe,b+=le,j<=cg&&(u=ne.socEnd),f=ue;let we=C?B(ee,L):null;we&&(L={front:we.front?.endC??L.front,rear:we.rear?.endC??L.rear}),g.push({lap:H+1,time:Z,elapsed:p,entryTime:ee.laptime,socStart:J,socEnd:u,packTempStartC:Y,packTempEndC:f,packTempMaxC:Number.isFinite(T)?T:Y,energyKwh:re,lossKwh:oe,chargeAh:le,launched:W,substeps:Fe,...r?{vCeiling:r}:{},...x?{motor:{peakWindingC:M,derateTimeFrac:Z>0?A/Z:0,lossKwh:w}}:{},...we?{brakes:{...we.front?{front:OS(we.front)}:{},...we.rear?{rear:OS(we.rear)}:{}}}:{}}),S=ee}if(!S){let H=lg(t);S=wt(qi(t.ggv,t.vehicle,u),n,t.numerics,{standingStart:a,...t.load?{load:t.load.atSoc(t.vehicle,u)}:{},...H?{shifts:H}:{}}),F=F??{lapsCompleted:0,lapsAsked:o,why:"the pack was empty"}}let G=g.length;return{id:e.id,label:e.label,kind:e.kind,time:p,distance:n.length*G,laps:G,lapTime:S.laptime,trace:b_(n,S),energy:{consumed:d,loss:h,...ht(i.motorModel)?{}:{native:{value:b,unit:"Ah"}},remainingFraction:ht(i.motorModel)?1:u,...y?{motor:{peakWindingC:R,derateTimeFrac:p>0?k/p:0,lossKwh:v}}:{}},lapLog:g,...F?{incomplete:F}:{}}}var cg=.05;function OS(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 F_=4,w_=.001;function C_(e,t){return e===t?!1:!Number.isFinite(e)||!Number.isFinite(t)?!0:Math.abs(e-t)>w_*Math.max(1,Math.abs(t))}function GS(e,t,r,n,o,a){return T_(e,t,o,()=>({v:r,ax:n,...a?{lateral:a}:{}}))}function T_(e,t,r,n){let o=e.energyOpts,a=e.vehicle.params.soc.value,s=0,i=0,c=0;for(let l=0;l<r;l++){let u=n(l),m=Ka(e.vehicle,t,u.v,u.ax,o,a,void 0,void 0,void 0,void 0,u.lateral);s+=m.net,i+=m.loss,c+=m.chargeAh,a=m.socEnd}return ht(e.vehicle.params.motorModel)?{consumed:s,loss:i,remainingFraction:1}:{consumed:s,loss:i,native:{value:c,unit:"Ah"},remainingFraction:a}}function KS(e,t){switch(e.kind){case"straightLineAccel":return g_(e,t);case"constantRadius":return y_(e,t);case"trackLap":return k_(e,t)}}function ug(e,t){let r={};for(let n of e)r[n.id]=KS(n,t);return r}function HS(e,t){if(e.kind!=="trackLap")return e;let{distance:r,...n}=e;return{...n,laps:Math.max(1,Math.round(t))}}function bo(e,t,r,n,o="twoTrack",a){let s=1/0,i=-1/0;for(let f of r){let p=Hi(f);if(!p)continue;let d=FM(p,wt(t,f,n).v);d&&(s=Math.min(s,d.lo),i=Math.max(i,d.hi))}if(!(i>=s))return;let c=wM({lo:s,hi:i}),l=c.join(","),u=a?.get(l);if(u)return u;let m=FS(e,c,t,o);return a?.set(l,m),m}var Zi=e=>e.distance/Math.max(1,e.laps);function Ji(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 P_=e=>e.v.map(t=>t*3.6),L_=e=>e.ax.map(t=>t/9.81),D_=e=>e.ay.map(t=>t/9.81),E_=e=>e.ay.map((t,r)=>e.v[r]>1e-6?t/(e.v[r]*e.v[r]):0),Pm=(e,t,r)=>e?.slice()??new Array(t.s.length).fill(r),I_=e=>Pm(e.z,e,0),__=e=>e.gradient?e.gradient.map(t=>100*Math.tan(t*Math.PI/180)):Pm(void 0,e,0),N_=e=>Pm(e.bank,e,0),O_=e=>Pm(e.mu,e,1);function V_(e){let t=e.s.length,r=Ji(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 mg=[{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 zS(e){let t=Ji(e);return{ds:t,vars:{s:e.s,ds:t,t:V_(e),v:e.v,speed:P_(e),ax:e.ax,ay:e.ay,axg:L_(e),ayg:D_(e),curv:E_(e),z:I_(e),grade:__(e),bank:N_(e),grip:O_(e)}}}function YS(e,t){return{v:e.v,ax:e.ax,ay:e.ay,ds:Ji({s:e.s,length:t}),axGrade:Fn(e.gradient,e.v.length),...e.bank?{bank:e.bank}:{},...e.loadFactor?{loadFactor:e.loadFactor}:{}}}function WS(e,t){let r=Rt(e);return{pastTurnover:mS(r,xr(e),t),...e.aeroModel?{aeroOutside:uS(r,t)}:{}}}var Lm="Flying lap";function pg(e,t){return e.kind!=="trackLap"||e.label!==Lm?e.label:e.standingStart??t?"Run":e.label}function B_(e){let t=Rt(e);return{yawInertia:t.yawInertia??0,massTotal:t.massTotal,wheelbase:t.wheelbase/1e3}}function $_(e,t,r){let n=e.params,o=n.ggvMode??"twoTrack",a=n.quasiTransient?AS(e,!1,o):null,s=a?a.steady:Rr(e,!1,o),i=t?bo(e,s,[t],r,o):void 0;return{ggv:s,...a?{yaw:{family:a,car:B_(n)}}:{},...i?{load:i}:{}}}function G_(e,t){let r=t.lapCounts,n=t.standingStart??!1,o=!1,a=e.events.map(s=>{let i=r?.[s.id]!=null?HS(s,r[s.id]):s,c=pg(i,n),l=c===i.label?i:{...i,label:c};return l!==s&&(o=!0),l});return o?a:e.events}function K_(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=Tm(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 H_(e,t){for(let[r,n]of Object.entries(e))n.trace&&(e[r]={...n,...WS(t,YS(n.trace,Zi(n)))})}function ec(e,t,r={}){let n=It(e),o=$_(n,r.track,r.numerics),{ggv:a}=o,s=ug(G_(t,r),{vehicle:n,...o,track:r.track,energyOpts:Kr(e,r.energyOpts),numerics:r.numerics,standingStart:r.standingStart});return K_(s,t,r),H_(s,n.params),{name:e.name,rulesetId:t.id,events:s,ggv:a}}function dg(e){return{...e,ggv:{rows:e.ggv.rows,vMax:e.ggv.vMax,surf:e.ggv.surf}}}var fg=["<","<=",">",">=","==","!="],$e=class extends Error{at;constructor(t,r){super(t),this.name="ExprError",this.at=r}},tc=e=>e>="0"&&e<="9",jS=e=>/[A-Za-z_]/.test(e),z_=e=>/[A-Za-z0-9_]/.test(e);function Y_(e){let t=[],r=0;for(;r<e.length;){let n=e[r];if(n===" "||n===" "||n===`
224
+ `||n==="\r"){r++;continue}if(tc(n)||n==="."&&tc(e[r+1]??"")){let o=r;for(;r<e.length&&(tc(e[r])||e[r]===".");)r++;if(e[r]==="e"||e[r]==="E"){let i=r;if(r++,(e[r]==="+"||e[r]==="-")&&r++,tc(e[r]??""))for(;r<e.length&&tc(e[r]);)r++;else r=i}let a=e.slice(o,r),s=Number(a);if(!Number.isFinite(s))throw new $e(`"${a}" is not a number`,o);t.push({t:"num",value:s,at:o});continue}if(jS(n)){let o=r;for(;;){for(;r<e.length&&z_(e[r]);)r++;if(e[r]==="."&&jS(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(fg.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 $e(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 $e(`"${n}" is not something this expression can contain`,r)}return t.push({t:"end",at:e.length}),t}function hg(e){let t=Y_(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 $e(`Expected ${b} here`,n().at)};function i(){let h=c(),b=n();if(b.t!=="op"||!fg.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"&&fg.includes(y.value))throw new $e("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=f(),b=n().at;return a("^")?{kind:"binary",op:"^",left:h,right:u(),at:b}:h}function f(){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 $e("The expression ends before it is finished",h.at):new $e(`"${h.value}" cannot start a value`,h.at)}let p=i(),d=n();if(d.t!=="end")throw new $e(`"${d.value}" is left over \u2014 check for a missing operator`,d.at);return p}function bg(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 rc=(e,t)=>typeof e=="number"?new Array(t).fill(e):e;function W_(e){let t=1;for(let r of e)Array.isArray(r)&&(t=Math.max(t,r.length));return t}function Ot(e,t){if(e.every(a=>typeof a=="number"))return t(...e);let r=W_(e),n=e.map(a=>rc(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 Ge=(e,t)=>({arity:e,call:r=>Ot(r,t)}),go=e=>e!==0&&!Number.isNaN(e),vr=e=>e?1:0;function US(e,t,r){let n=XS(t,r,"integrate"),o=n.length,a=rc(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 XS(e,t,r){if(!e.ds||e.ds.length===0)throw new $e(`${r}() needs to know the sample spacing, and this context has none`,t);return e.ds}var Dm={abs:Ge(1,Math.abs),sqrt:Ge(1,Math.sqrt),sign:Ge(1,Math.sign),floor:Ge(1,Math.floor),ceil:Ge(1,Math.ceil),round:Ge(1,Math.round),exp:Ge(1,Math.exp),log:Ge(1,Math.log),sin:Ge(1,Math.sin),cos:Ge(1,Math.cos),tan:Ge(1,Math.tan),atan:Ge(1,Math.atan),atan2:Ge(2,Math.atan2),hypot:Ge(2,Math.hypot),min:Ge(2,Math.min),max:Ge(2,Math.max),clamp:Ge(3,(e,t,r)=>Math.min(r,Math.max(t,e))),if:Ge(3,(e,t,r)=>go(e)?t:r),and:Ge(2,(e,t)=>vr(go(e)&&go(t))),or:Ge(2,(e,t)=>vr(go(e)||go(t))),not:Ge(1,e=>vr(!go(e))),finite:Ge(1,e=>vr(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=US(e,t,0),n=t.ds,o=rc(e,n.length),a=n.length-1;return r[a]+(o[a]+o[0])/2*n[a]}},integrate:{arity:1,call:([e],t)=>US(e,t,0)},cum:{arity:1,call:([e],t)=>{let r=t.ds?.length??(Array.isArray(e)?e.length:1),n=rc(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=XS(t,0,"deriv"),n=r.length,o=rc(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}}},Xa={g:9.81,pi:Math.PI,e:Math.E,nan:NaN,inf:1/0},nc={fleetmin:"min",fleetmax:"max"};function yo(e){switch(e.kind){case"call":return Object.hasOwn(nc,e.name)||e.args.some(yo);case"unary":return yo(e.arg);case"binary":return yo(e.left)||yo(e.right);default:return!1}}var j_=e=>typeof e=="number"?`${e}`:`between ${e[0]} and ${e[1]}`;function U_(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 X_(e,t){let r=t.map(c=>({k:c,d:U_(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 kr(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(Xa,e.name))return Xa[e.name];let r=[...Object.keys(t.vars),...Object.keys(Xa)].sort();throw new $e(X_(e.name,r),e.at)}case"unary":return Ot([kr(e.arg,t)],r=>-r);case"binary":{let r=kr(e.left,t),n=kr(e.right,t);switch(e.op){case"+":return Ot([r,n],(o,a)=>o+a);case"-":return Ot([r,n],(o,a)=>o-a);case"*":return Ot([r,n],(o,a)=>o*a);case"/":return Ot([r,n],(o,a)=>a===0?0:o/a);case"^":return Ot([r,n],(o,a)=>o**a);case"<":return Ot([r,n],(o,a)=>vr(o<a));case"<=":return Ot([r,n],(o,a)=>vr(o<=a));case">":return Ot([r,n],(o,a)=>vr(o>a));case">=":return Ot([r,n],(o,a)=>vr(o>=a));case"==":return Ot([r,n],(o,a)=>vr(o===a));case"!=":return Ot([r,n],(o,a)=>vr(o!==a))}break}case"call":{let r=Object.hasOwn(nc,e.name)?nc[e.name]:void 0;if(r){if(!t.fleet)throw new $e(`${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 $e(`${e.name}() takes 1 argument, not ${e.args.length}`,e.at);return t.fleet(e.args[0],r,e.at)}let n=Object.hasOwn(Dm,e.name)?Dm[e.name]:void 0;if(!n){let s=[...Object.keys(Dm),...t.fleet?Object.keys(nc):[]];throw new $e(`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 $e(`${e.name}() takes ${j_(n.arity)} argument${o===1&&a===1?"":"s"}, not ${e.args.length}`,e.at);return n.call(e.args.map(s=>kr(s,t)),t)}}throw new $e("Unreachable node",0)}var qa=e=>Number.isFinite(e)?e:NaN,gg=[{name:"time",unit:"s",what:"the whole event, every lap",read:e=>qa(e?.time)},{name:"lapTime",unit:"s",what:"one lap \u2014 the last one completed",read:e=>qa(e?.lapTime)},{name:"distance",unit:"m",what:"distance covered",read:e=>qa(e?.distance)},{name:"laps",unit:"-",what:"laps completed",read:e=>qa(e?.laps)},{name:"energy",unit:"kWh",what:"energy drawn over the event",read:e=>qa(e?.energy?.consumed)},{name:"remaining",unit:"-",what:"share of the pack or tank left afterwards",read:e=>qa(e?.energy?.remainingFraction)},{name:"finished",unit:"-",what:"1 when the car ran the whole event, else 0",read:e=>e&&!e.incomplete?1:0}],qS=/^[A-Za-z_][A-Za-z0-9_]*$/,q_=new Set([...Object.keys(Xa),...mg.map(e=>e.name)]);function Em(e,t,r=[]){let n=[],o=new Set(r),a=t.map(b=>b.id),s=new Set;for(let b of a)qS.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(!qS.test(b.key)){n.push({key:b.key,message:`"${b.key}" must be one word \u2014 letters, digits and _`});continue}if(q_.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,hg(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,[...bg(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=Q_(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 f=(b,g,y)=>{throw new $e("fleetmin() and fleetmax() cannot sit inside one another",y)},p=new Set,d={};for(let b of a)for(let g of gg)d[`${b}.${g.name}`]=1;for(let b of o)d[b]=1;for(let b of i.keys())d[b]=1;let h={};for(let b of mg)h[b.name]=[1,1];for(let b of m){let g=i.get(b),y=c.get(b);(yo(y)||l.get(b).some(x=>p.has(x)))&&p.add(b);let R=g.over!=null?{...d,...h}:d,k=g.over!=null?[1,1]:void 0,v=(x,M,A)=>{let w=kr(x,{vars:R,ds:k,fleet:f});if(Array.isArray(w))throw new $e("fleetmin() and fleetmax() compare one number per car \u2014 reduce the channel first, e.g. peak(v)",A);return w};try{let x=kr(y,{vars:R,ds:k,fleet:v});Array.isArray(x)&&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(x){let M=x;n.push({key:b,message:M.message,at:M.at})}}return n.length?{plan:null,problems:n}:{plan:{order:m.map(b=>({def:i.get(b),node:c.get(b)})),field:p,eventIds:a},problems:n}}function Q_(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 Z_(e,t,r={}){let n={...r};for(let o of e.eventIds){let a=t.events[o];for(let s of gg)n[`${o}.${s.name}`]=s.read(a)}return{vars:n,laps:new Map,events:t.events}}function QS(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?zS({...n.trace,length:Zi(n)}):null,e.laps.set(t.over,r)}return r?{vars:{...e.vars,...r.vars},ds:r.ds}:null}var ZS=e=>Array.isArray(e)?NaN:e;function JS(e,t,r,n={}){let o=Object.keys(t),a=o.map(i=>Z_(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 f of a)f.vars[i.key]=NaN;continue}let u=new Map,m=(f,p)=>{let d=u.get(f);if(d!==void 0)return d;let h=NaN;for(let b of a){let g=QS(b,i);if(!g)continue;let y=ZS(kr(f,g));Number.isFinite(y)&&(Number.isNaN(h)||(p==="min"?y<h:y>h))&&(h=y)}return u.set(f,h),h};for(let f of a){let p=QS(f,i);f.vars[i.key]=p?ZS(kr(c,l?{...p,fleet:m}:p)):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 oc(e,t,r){return JS(e,t,!0,r)}function yg(e,t,r){return JS(e,{car:t},!1,r?{car:r}:void 0).car}var Im=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}},rc=e=>typeof e=="number"&&Number.isFinite(e),tc=e=>rc(e)&&e>0,Ot=(e,t)=>e===void 0||t(e);function X_(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":tc(a.distance)||r(`${s} needs a distance above zero, in metres`),Ot(a.vStart,i=>rc(i)&&i>=0)||r(`${s}'s entry speed must be zero or more`);break;case"constantRadius":tc(a.radius)||r(`${s} needs a radius above zero, in metres`),Ot(a.laps,i=>rc(i)&&i>=1)||r(`${s} runs at least one lap`);break;case"trackLap":Ot(a.laps,i=>rc(i)&&i>=1)||r(`${s} runs at least one lap`),Ot(a.distance,tc)||r(`${s}'s distance must be above zero, in metres`),Ot(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),Ot(a.unit,i=>typeof i=="string")||r("Its unit is text",s),Ot(a.over,i=>typeof i=="string")||r("Names its event by id",s),Ot(a.format,i=>i==="time"||i==="points")||r("Is shown as a time, as points, or as a number",s),Ot(a.max,rc)||r("Its maximum is a number",s),Ot(a.lowerBetter,i=>typeof i=="boolean")||r("Lower is better, or it is not",s),Ot(a.hidden,i=>typeof i=="boolean")||r("Is hidden, or it is not",s)}Ot(e.track?.minTurnRadius,tc)||r("The tightest turn the rules allow is a radius above zero");let n=e.battery;for(let o of["packVoltageMax","segmentVoltageMax","powerLimitKw"])Ot(n?.[o],tc)||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 qS(e){let t=X_(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}=Cm(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 Pm(e){return qS(e).problems}var gg=e=>Number.isFinite(e)?e:NaN;function q_(e){return e.unit&&e.format!=="time"?`${e.label} (${e.unit})`:e.label}function wn(e){let t=structuredClone(e),{plan:r,problems:n}=qS(t);if(!r)throw new Tm(t.id,n);let o=new WeakMap,a=p=>{let d=o.get(p);return d||(d=bg(r,p),o.set(p,d)),d},s=new Map(t.kpis.map(p=>[p.key,p])),i=new Map;for(let[p,d]of Object.entries(t.score?.parts??{}))i.has(d)||i.set(d,p);let c=p=>(d,h)=>{if(!h)return NaN;let b=h.kpis?.[p];if(b!==void 0)return gg(b);let g=h,y=i.get(p);return y!==void 0?gg(g.parts?.[y]):p===t.score?.total?gg(g.total):NaN},l=t.kpis.filter(p=>!p.hidden).map(p=>{let d=r.field.has(p.key);return{key:p.key,label:q_(p),lowerBetter:p.lowerBetter??!1,...p.format?{format:p.format}:{},...d?{field:!0}:{},value:d?c(p.key):h=>a(h)[p.key]}}),u=t.score,m=u?p=>{let d=ec(r,p),h={};for(let[b,g]of Object.entries(d)){let y={},R={};for(let[k,v]of Object.entries(u.parts)){y[k]=g[v];let x=s.get(v)?.max;x!=null&&(R[k]=x)}h[b]={total:g[u.total],parts:y,...Object.keys(R).length?{maxima:R}:{},kpis:Object.fromEntries(t.kpis.map(k=>[k.key,g[k.key]]))}}return h}:void 0,f=m||(r.field.size>0?p=>{let d=ec(r,p),h={};for(let[b,g]of Object.entries(d))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}:{},...f?{field:f}:{},definition:t}}var er={accel:"accel",skidpad:"skidpad",autocross:"autocross",endurance:"endurance"},QS=[{kind:"straightLineAccel",id:er.accel,label:"Acceleration (75 m)",distance:75},{kind:"constantRadius",id:er.skidpad,label:"Skidpad",radius:8.375},{kind:"trackLap",id:er.autocross,label:"Autocross (1 lap)",laps:1},{kind:"trackLap",id:er.endurance,label:"Endurance (22 km)",distance:22e3}],ZS=[{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"}],JS={total:"overall",parts:{[er.accel]:"accelPts",[er.skidpad]:"skidpadPts",[er.autocross]:"autocrossPts",[er.endurance]:"endurancePts",efficiency:"efficiencyPts"}},eA={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:QS,kpis:ZS,score:JS,track:{minTurnRadius:4.5},battery:fx,traceEventId:er.autocross},tA={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:QS,kpis:ZS,score:JS,track:{minTurnRadius:4.5},traceEventId:er.autocross},nc=wn(eA),yg=wn(tA);var xg="lap",Q_=[{kind:"trackLap",id:xg,label:Fm,laps:1}],rA={id:"trackday",label:"Track day",description:"One flying lap of the selected track. Times and traces only \u2014 no scoring.",events:Q_,kpis:[{key:"lap",label:"Lap time",format:"time",lowerBetter:!0,expr:"lap.time"},{key:"topSpeed",label:"Top speed",unit:"km/h",over:xg,expr:"peak(speed)"},{key:"energy",label:"Energy / lap",unit:"kWh",lowerBetter:!0,expr:"lap.energy"}],traceEventId:xg},Rg=wn(rA);function Cn(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(Cn).join(",")}]`;let t=e,r=Object.keys(t).sort(),n=[];for(let o of r)t[o]!==void 0&&n.push(`${JSON.stringify(o)}:${Cn(t[o])}`);return`{${n.join(",")}}`}function yo(e){let t=Cn(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 Ua=[nc,yg,Rg],xo=nc.id,Xa=e=>Ua.some(t=>t.id===e),nA=new WeakMap,oc=new Map,Z_=64;function Lm(e){let t=nA.get(e);if(t!==void 0)return t;let r=Cn(e),n=oc.get(r);return n===void 0&&(n=Pm(e).length?null:wn(e),oc.size>=Z_&&oc.delete(oc.keys().next().value),oc.set(r,n)),nA.set(e,n),n}function Dm(e,t=[]){if(e==null)return;if(typeof e!="string")return Lm(e)??void 0;let r=Ua.find(o=>o.id===e);if(r)return r;let n=t.find(o=>o.id===e);return n?Lm(n)??void 0:void 0}function Ro(e,t=[]){return Dm(e,t)??nc}function vg(e=[]){let t=e.filter(r=>!Xa(r.id)).map(r=>Lm(r)).filter(r=>r!==null);return[...Ua,...t]}var ac=e=>e.definition??e.id;function Em(e,t,r){let n=e.length,o=new Array(n);for(let d=0;d<n;d++){let h=d+1<n?e[d+1]:r;o[d]=h-e[d]}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 d=0;d<n;d++){let h=o[(d-1+n)%n],b=o[d];a[d]=h,s[d]=2*(h+b),i[d]=b;let g=t[(d+1)%n],y=t[(d-1+n)%n];c[d]=6*((g-t[d])/b-(t[d]-y)/h)}let l=J_(a,s,i,c),u=new Array(n),m=new Array(n),f=new Array(n),p=new Array(n);for(let d=0;d<n;d++){let h=o[d],b=l[d],g=l[(d+1)%n],y=t[d],R=t[(d+1)%n];u[d]=y,f[d]=b/2,p[d]=(g-b)/(6*h),m[d]=(R-y)/h-h*(2*b+g)/6}return{n,eval:(d,h)=>u[d]+h*(m[d]+h*(f[d]+h*p[d])),d1:(d,h)=>m[d]+h*(2*f[d]+h*3*p[d]),d2:(d,h)=>2*f[d]+h*6*p[d]}}function Mg(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),f=new Array(u).fill(0),p=new Array(u).fill(0),d=new Array(u).fill(0);for(let g=0;g<u;g++){let y=g+1;m[g]=o[y-1],f[g]=2*(o[y-1]+o[y]),p[g]=o[y],d[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];f[0]+=o[0]*(1+g),p[0]-=o[0]*g;let y=o[n-1]/o[n-2];f[u-1]+=o[n-1]*(1+y),m[u-1]-=o[n-1]*y}let b=kg(m,f,p,d);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 J_(e,t,r,n){let o=t.length;if(o===1)return[n[0]/(t[0]+e[0]+r[0])];if(o===2){let d=t[0],h=r[0]+e[0],b=e[1]+r[1],g=t[1],y=d*g-h*b;return[(n[0]*g-h*n[1])/y,(d*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=kg(e,c,r,n),u=new Array(o).fill(0);u[0]=i,u[o-1]=s;let m=kg(e,c,r,u),f=(l[0]+a*l[o-1]/i)/(1+m[0]+a*m[o-1]/i),p=new Array(o);for(let d=0;d<o;d++)p[d]=l[d]-f*m[d];return p}function kg(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 sc(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 oA(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 aA(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 f=r*i-o*o,p=n*o-r*s,d=r*a-n*n;return[(c*t[0]+l*t[1]+u*t[2])/m,(l*t[0]+f*t[1]+p*t[2])/m,(u*t[0]+p*t[1]+d*t[2])/m]}function sA(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=>oA(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=aA([u[0],u[1],u[2],u[2],u[3],u[4]],[1,0,0]);if(!m)continue;let f=l.map(h=>m[0]+m[1]*h+m[2]*h*h),p=0,d=1;f.forEach((h,b)=>{p+=h*e.z[s[b]],d+=h*h}),r.push(Math.abs(e.z[a]-p)/Math.sqrt(d))}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 eN(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=oA(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 tN(e,t,r){let{j:n,t:o}=eN(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 f=0;f<5;f++)i[f]+=m,m*=l});let c=aA([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 Sg(e,t){return t>0?e.z.map((r,n)=>{let o=tN(e,n,t/2);return o?o.value.reduce((a,s,i)=>a+s*e.z[o.j[i]],0):r}):[...e.z]}function rN(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 Im(e){let t=sc(e);if(!t)return 0;let r=sA(t);return r>1e-6?Math.max(10,rN(r,nN(t))):0}function nN(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 kr(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 Nm(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 iA(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 _m(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 oN(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 Ag(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=iA(r,(y,R)=>kr(e,y,R));if(!b)return null;let g=_m(b,t);return g.every(Number.isFinite)?g:null}let n=r-2,a=iA(n,(b,g)=>kr(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]=kr(e,b,r-2),i[b]=kr(e,b,r-1);let c=_m(a,t.slice(0,n)),l=_m(a,s),u=_m(a,i),m=(b,g)=>{let y=0;for(let R=0;R<b.length;R++)y+=b[R]*g[R];return y},f=[[kr(e,r-2,r-2)-m(s,l),kr(e,r-2,r-1)-m(s,u)],[kr(e,r-1,r-2)-m(i,l),kr(e,r-1,r-1)-m(i,u)]],p=[t[r-2]-m(s,c),t[r-1]-m(i,c)],d=oN(f,p);if(!d)return null;let h=new Array(r).fill(0);for(let b=0;b<n;b++)h[b]=c[b]-l[b]*d[0]-u[b]*d[1];return h[r-2]=d[0],h[r-1]=d[1],h.every(Number.isFinite)?h:null}function cA(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=Ag(i,t);if(c){let l=Nm(i,c).map((m,f)=>m-t[f]);if(Math.sqrt(l.reduce((m,f)=>m+f*f,0))<=1e-6*Math.max(a,1e-12))return c}o=o===0?n*1e-12:o*10}return null}var lA=4,aN=8,Fg=.001;function sN(e,t,r){let n=[];for(let c=1;c<e.length;c++){let l=e[c]-e[c-1];l>=Fg&&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/yM(r,s,i)))}function iN(e,t){let r=e.closed!==!1,n=[],o=[],a=(A,w)=>{let T=n.length-1;T>=0&&Math.hypot(A-n[T],w-o[T])<Fg||(n.push(A),o.push(w))},s=e.x.length,i=r?s:s-1,c=new Array(i+1);c[0]=0;for(let A=0;A<i;A++){let w=(A+1)%s;c[A+1]=c[A]+Math.hypot(e.x[w]-e.x[A],e.y[w]-e.y[A])}let l=c[i],u=e.fit==="interpolate",m=u?s:sN(c,r,t),f=r?m:m-1,p=0;for(let A=0;A<=f&&!(r&&A===f);A++){if(u){a(e.x[A],e.y[A]);continue}let w=A*l/f;for(;p<i-1&&c[p+1]<w;)p++;let T=c[p+1]-c[p],P=T>0?(w-c[p])/T:0,S=(p+1)%s;a(e.x[p]+P*(e.x[S]-e.x[p]),e.y[p]+P*(e.y[S]-e.y[p]))}if(r)for(;n.length>2&&Math.hypot(n[n.length-1]-n[0],o[o.length-1]-o[0])<Fg;)n.pop(),o.pop();let d=n.length,h=r?d:d-1,b=new Array(h+1);b[0]=0;for(let A=1;A<=h;A++){let w=A%d,T=n[w]-n[A-1],P=o[w]-o[A-1],S=Math.sqrt(Math.hypot(T,P))||1e-9;b[A]=b[A-1]+S}let g=r?Em(b.slice(0,d),n,b[d]):Mg(b,n),y=r?Em(b.slice(0,d),o,b[d]):Mg(b,o),R=new Array(h);for(let A=0;A<h;A++)R[A]=b[A+1]-b[A];let k=[0],v=[0],x=[0],M=0;for(let A=0;A<h;A++){let w=R[A]/lA;for(let T=0;T<lA;T++){let P=T*w;M+=Lh(S=>Math.hypot(g.d1(A,S),y.d1(A,S)),P,P+w),k.push(M),v.push(A),x.push(P+w)}}return{closed:r,sx:g,sy:y,h:R,sTable:k,segTable:v,uTable:x,length:M,rawCum:c,rawLength:l}}function ic(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 f=i*n.rawLength,p=0,d=a;for(;p<d;){let b=p+d+1>>1;n.rawCum[b]<=f?p=b:d=b-1}let h=p<a?n.rawCum[p+1]-n.rawCum[p]:0;c=p+(h>0?(f-n.rawCum[p])/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 cN=.01,lN=3,uA=10;function uN(e,t,r,n=uA){let o={step:0,uncertainty:1/0},a=e.length;if(a<8||!(r>0))return o;let s=Math.max(uA,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=[],f=[],p=(R,k,v)=>{let x=R/s;m.push([1,x,x*x,x*x*x,k]),f.push(v)};for(let R=0;R<u;R++)p(t[R]+i,1,e[R]);for(let R=0;R<u;R++)p(t[a-1-R]-r+i,0,e[a-1-R]);let d=Array.from({length:5},()=>new Array(5).fill(0)),h=new Array(5).fill(0);m.forEach((R,k)=>{for(let v=0;v<5;v++){h[v]+=R[v]*f[k];for(let x=0;x<5;x++)d[v][x]+=R[v]*R[x]}});let b=ir(d,h),g=ir(d,[0,0,0,0,1]);if(b.singular||g.singular)return o;let y=0;return m.forEach((R,k)=>{let v=0;for(let x=0;x<5;x++)v+=R[x]*b.x[x];y+=(f[k]-v)**2}),{step:b.x[4],uncertainty:Math.sqrt(y/(m.length-5)*g.x[4])}}function mN(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 pN(e,t,r){let{pos:n,loop:o}=mN(e.length,t),{step:a,uncertainty:s}=uN(e,n,o,r);return Math.abs(a)>Math.max(cN,lN*s)?{z:e.map((i,c)=>i+a*n[c]/o),drift:-a}:{z:e,drift:0}}function dN(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],f=r[u+1],p=n[u+1],d=o[u+1],h=n[u]===p?o[u]:0,b=f-m,g=b>0?h+(t-m)/b*(d-h):h;for(let y=0;y<2;y++){let R=m+Lh(v=>Math.hypot(s.d1(p,v),i.d1(p,v)),h,g),k=Math.hypot(s.d1(p,g),i.d1(p,g));if(k<1e-12)break;g-=(R-t)/k}return{seg:p,du:Math.min(Math.max(g,0),a[p])}}var fN=3,wg=5;function hN(e,t,r,n=wg){return Vm(e,t,r,n)}function Vm(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 f of[0,a-1])i[f]+=m,u[f]*=1+m}return Ag({n:a,diag:i,off1:c,off2:l,closed:r},u)??[...e]}function lt(e,t){let r=ct(t),n=iN(e,r.fitSpacing),o=n.length,a=Math.max(aN,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 f=new Array(s),p=new Array(s),d=new Array(s);for(let T=0;T<s;T++){let P=T*i,{seg:S,du:F}=dN(n,P);c[T]=n.sx.eval(S,F),l[T]=n.sy.eval(S,F),u[T]=P;let C=n.sx.d1(S,F),L=n.sy.d1(S,F),E=n.sx.d2(S,F),D=n.sy.d2(S,F),O=Math.hypot(C,L),_=Math.pow(C*C+L*L,1.5);f[T]=_>0?(C*D-L*E)/_:0,p[T]=O>0?-L/O:0,d[T]=O>0?C/O: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?pN(e.z,n.rawCum,g):null,R=y?y.z:e.z,k=g>0?sc(e):null,v=k?Sg({...k,z:R},g):R,x=ic(v,0,h,n),M=new Array(s).fill(0);if(b){for(let P=0;P<s;P++){let S=n.closed?(P+1)%s:Math.min(P+1,s-1),F=n.closed?(P-1+s)%s:Math.max(P-1,0),C=n.closed?2:S-F,L=x[S]-x[F];M[P]=C>0?Math.atan2(L,C*i)*180/Math.PI:0}for(let P=0;P<s;P++){if(m[P]===0)continue;let S=n.closed?(P+1)%s:P+1,F=x[S]-x[P];m[P]=Math.hypot(i,F)}let T=0;for(let P=0;P<s;P++)u[P]=T,T+=m[P]}let A=b?m.reduce((T,P)=>T+P,0):o,w;if(b){w=new Array(s).fill(0);let T=Math.max(fN,e.zReach??Im(e)),P=Math.max(2,Math.round(T/i));if(n.closed?s>2*P:s>2*P+1){let S=0,F=0;for(let E=-P;E<=P;E++)S+=E*E,F+=E*E*E*E;let C=2*P+1,L=F-S*S/C;for(let E=0;E<s;E++){let D=n.closed?E:Math.min(Math.max(E,P),s-1-P),O=0,_=0;for(let N=-P;N<=P;N++){let B=x[n.closed?(D+N+s)%s:D+N];O+=(N*N-S/C)*B,_+=N*B}let z=2*O/L/(i*i),I=_/S/i;w[E]=z/Math.pow(1+I*I,1.5)}}}return{name:e.name,closed:n.closed,x:c,y:l,s:u,ds:m,curvature:e.turnReach?hN(f,i,n.closed,e.turnReach):f,npts:s,length:A,nx:p,ny:d,z:x,gradient:M,...w?{verticalCurvature:w}:{},widthLeft:ic(e.widthLeft,1.5,h,n),widthRight:ic(e.widthRight,1.5,h,n),bank:ic(e.bank,0,h,n),mu:ic(e.mu,1,h,n),...y?.drift?{elevationDrift:y.drift}:{}}}function mA(e,t,r){let n=Nm(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 bN(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 f=s(l,m);f!=null&&(i[f]-=kr(e,f,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 cA(c,i)}var gN=1e-4;function pA(e,t,r,n,o={}){let a=e.n,s=o.maxIter??60,i=o.tol??1e-9,c=o.bounds,l=(d,h)=>Math.min(n[h],Math.max(r[h],d)),u=r.map((d,h)=>c?.[h]==="hi"?n[h]:c?.[h]==="lo"?r[h]:l(0,h)),m=mA(e,t,u),f=new Array(a).fill("free"),p=!1;for(let d=0;d<s;d++){let h=Nm(e,u).map((R,k)=>R-t[k]),b=!1;for(let R=0;R<a;R++){let k=u[R]<=r[R]+i&&h[R]>=-i?"lo":u[R]>=n[R]-i&&h[R]<=i?"hi":"free";k!==f[R]&&(f[R]=k,b=!0)}if(p&&!b)return{x:u,iterations:d+1,converged:!0,bounds:f};let g=bN(e,t,f,R=>u[R]);if(!g)return{x:u,iterations:d+1,converged:!1,bounds:f};let y=!1;for(let R=1;R>1e-12;R*=.5){let k=!1,v=u.map((A,w)=>{if(f[w]!=="free")return A;let T=A+R*(g[w]-A),P=l(T,w);return P!==T&&(k=!0),P}),x=mA(e,t,v),M=0;for(let A=0;A<a;A++)M+=h[A]*(v[A]-u[A]);if(R===1&&!k||x<m&&x<=m+gN*M){u=v,m=x,p=R===1&&!k,y=!0;break}}if(!y)return{x:u,iterations:d+1,converged:!1,bounds:f}}return{x:u,iterations:s,converged:!1,bounds:f}}var Cg={lineStep:2,carHalfWidth:.75,margin:.1,foldMargin:.25,referenceReach:5,passes:40,iterations:400},yN=[1,.5,.25,.125,.0625,.03125,.015625,.0078125,.00390625,.001953125,.0009765625],xN=e=>Math.sqrt(e.reduce((t,r)=>t+r*r,0)/(e.length||1));function cc(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],f=e[i]-e[s],p=t[i]-t[s],d=Math.hypot(c,l),h=Math.hypot(u,m),b=Math.hypot(f,p),g=d*h*b;o[a]=g>1e-12?2*(c*m-l*u)/g:0}return o}var RN=Math.PI/180,dA=20;function vN(e,t){let r=e.npts,n=e.closed,o=e.x.map((p,d)=>p+t[d]*e.nx[d]),a=e.y.map((p,d)=>p+t[d]*e.ny[d]),s=[0];for(let p=1;p<r;p++)s.push(s[p-1]+Math.hypot(o[p]-o[p-1],a[p]-a[p-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 p of c)for(let d=0;d<r;d++)l.push(s[d]+p*i),u.push(d+p*r);n&&(l.push(2*i),u.push(2*r));let m=[0];for(let p=1;p<l.length;p++)m.push(m[p-1]+.5*(u[p]+u[p-1])*(l[p]-l[p-1]));let f=p=>{let d=0,h=l.length-1;for(;h-d>1;){let g=d+h>>1;l[g]<=p?d=g:h=g}let b=l[h]>l[d]?(p-l[d])/(l[h]-l[d]):0;return m[d]+(l[h]-l[d])*b*(u[d]+.5*b*(u[h]-u[d]))};return s.map((p,d)=>{let h=n?dA:Math.min(dA,p,i-p);if(!(h>0))return e.z[d];let b=(f(p+h)-f(p-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),R=n?(y+1)%r:Math.min(y+1,r-1);return e.z[y]+(g-y)*(e.z[R]-e.z[y])})}function kN(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?vN(t,r):t.z;return{...n||o?{z:s.map((i,c)=>i+r[c]*Math.tan(t.bank[c]*RN))}:{},...n?{zReach:e.zReach??Im(e)}:{},...o?{bank:[...t.bank]}:{},...a?{mu:[...t.mu]}:{}}}function fA(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 MN(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,f)=>l*f-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,f=e[l]-e[u],p=t[l]-t[u],d=e[m]-e[l],h=t[m]-t[l],b=e[m]-e[u],g=t[m]-t[u],y=Math.hypot(f,p),R=Math.hypot(d,h),k=Math.hypot(b,g),v=y*R*k;if(!(v>1e-12))continue;let x=2*c(f,p,d,h)/v,M=Math.sqrt(.5*(y+R)),A=x/(2*M),w=(f*r[u]+p*n[u])/y,T=(b*r[u]+g*n[u])/k,P=(f*r[l]+p*n[l])/y,S=(d*r[l]+h*n[l])/R,F=(d*r[m]+h*n[m])/R,C=(b*r[m]+g*n[m])/k,L=-2*c(r[u],n[u],d,h)/v+x*(w/y+T/k),E=2*c(r[l],n[l],b,g)/v-x*(P/y-S/R),D=2*c(f,p,r[m],n[m])/v-x*(F/R+C/k);s[l]=x*M,i.l[l]=M*L-A*.5*w,i.d[l]=M*E+A*.5*(P-S),i.r[l]=M*D+A*.5*F}return{res:s,jac:i}}function SN(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),f=new Array(a),p=new Array(a),d=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,f[h]=i[h]*c[h]+g*u(i,h+1),p[h]=g*u(c,h+1),d[h]=-(b*u(l,h-1)+i[h]*l[h]+g*u(l,h+1))}return{M:{n:a,closed:o,diag:m,off1:f,off2:p},b:d}}function AN(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 f=0;f<o;f++){let p=(f+1)%r;a+=Math.hypot(e.x[p]-e.x[f],e.y[p]-e.y[f])}let s=a/o,i=Vm(e.x,s,n,t,!0),c=Vm(e.y,s,n,t,!0),l=new Array(r),u=new Array(r);for(let f=0;f<r;f++){let p=n?(f-1+r)%r:Math.max(f-1,0),d=n?(f+1)%r:Math.min(f+1,r-1),h=i[d]-i[p],b=c[d]-c[p],g=Math.hypot(h,b)||1;l[f]=-b/g,u[f]=h/g}let m=cc(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 FN=6;function wN(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]),f=Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]);s[l]=f>1e-9?m/f:0}let i=Math.max(0,Math.round(FN/(e.ds[0]||1))),c=1-n;for(let l=0;l<o;l++){let u=0,m=0;for(let f=-i-1;f<=i;f++){let p=e.closed?((l+f)%o+o)%o:l+f;p<0||p>=a||(u=Math.max(u,s[p]),m=Math.max(m,-s[p]))}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 Tg(e,t={}){let r={...Cg,...t},n=lt(e,{dsTarget:r.lineStep}),o=AN(n,r.referenceReach),a=o.npts,s=P=>({x:o.x.map((S,F)=>S+o.nx[F]*P[F]),y:o.y.map((S,F)=>S+o.ny[F]*P[F])}),i=P=>{let S=cc(P.x,P.y,o.closed),F=fA(P.x,P.y,o.closed),C=0;for(let L=0;L<S.length;L++)C+=S[L]*S[L]*F[L];return C},c=xN(n.curvature),l=fA(n.x,n.y,n.closed).reduce((P,S)=>P+S,0),u=new Array(a).fill(0),m=r.carHalfWidth+r.margin,f=new Array(a),p=new Array(a),d=0;for(let P=0;P<a;P++){let S=o.widthLeft[P]-m,F=-(o.widthRight[P]-m);if(S<F){d++;let C=(o.widthLeft[P]-o.widthRight[P])/2;f[P]=C,p[P]=C}else f[P]=S,p[P]=F}let h=[...f],b=[...p];wN(o,f,p,r.foldMargin);let g=P=>{let S=s(P),F=kN(e,o,P),C={name:`${e.name} \u2014 racing line`,x:S.x,y:S.y,closed:o.closed,widthLeft:h.map((I,N)=>Math.max(0,I-P[N])),widthRight:b.map((I,N)=>Math.max(0,P[N]-I)),...F,fit:"interpolate",turnReach:wg},L=1e-6,E=P.filter((I,N)=>I>=f[N]-L||I<=p[N]+L).length,D=cc(S.x,S.y,o.closed),O=I=>1/Math.max(...I.map(Math.abs),1e-9),_=0,z=o.closed?S.x.length:S.x.length-1;for(let I=0;I<z;I++){let N=(I+1)%S.x.length,B=S.x[N]-S.x[I],V=S.y[N]-S.y[I];_+=F.z?Math.hypot(B,V,F.z[N]-F.z[I]):Math.hypot(B,V)}return{offset:P,s:[...o.s],asset:C,curvatureRms:{centreLine:c,racingLine:Math.sqrt(i(S)/(l||1))},infeasibleSamples:d,atBoundary:a?E/a:0,length:{centreLine:n.length,racingLine:_},worstRadius:{centreLine:O(n.curvature),racingLine:O(D)}}},y=o.closed?0:1,R=o.closed?a-1:a-2,k=R-y+1,v=new Array(k),x=new Array(k);for(let P=0;P<k;P++)v[P]=p[y+P],x[P]=f[y+P];if(!o.closed&&k>0){let P=(S,F)=>{if(v[S]=Math.max(v[S],p[F]),x[S]=Math.min(x[S],f[F]),v[S]>x[S]){let C=.5*(v[S]+x[S]);v[S]=C,x[S]=C}};P(0,0),P(k-1,a-1),v[0]=x[0]=Math.min(x[0],Math.max(v[0],0))}if(k<7)return g(u);let M=P=>{let S=s(P),C=[...cc(S.x,S.y,o.closed).map(Math.abs)].sort((L,E)=>L-E);return{integral:i(S),tail:C[Math.floor(.99*(C.length-1))]}},A=[...u],w=M(u),T;for(let P=0;P<r.passes;P++){let S=s(A),{res:F,jac:C}=MN(S.x,S.y,o.nx,o.ny,o.closed),{M:L,b:E}=SN(C,F,y,R,o.closed),D=pA(L,E,v.map((z,I)=>z-A[y+I]),x.map((z,I)=>z-A[y+I]),{maxIter:r.iterations,bounds:T});T=D.bounds;let O=new Array(a).fill(0);for(let z=0;z<k;z++)O[y+z]=D.x[z];o.closed||(O[0]=O[1],O[a-1]=O[a-2]);let _=!1;for(let z of yN){let I=A.map((B,V)=>B+z*O[V]),N=M(I);if(N.integral<w.integral*(1-1e-6)){A=I,w=N,_=!0;break}}if(!_)break}return g(A)}function Pg(e){let t=Math.max(Q(e,"track_front"),Q(e,"track_rear"));return(t>0?t/2e3:.6)+.1}function Bm(e,t,r={}){if(!r.racingLine)return{asset:e,numerics:t,line:null};let n=r.params?Pg(r.params):void 0,o=Tg(e,{...r.line,...n?{carHalfWidth:n}:{}});return{asset:o.asset,numerics:{...t,fitSpacing:0},line:o}}function lc(e,t,r={}){let n=Bm(e,t,r);return{track:lt(n.asset,n.numerics),line:n.line}}function Lg(e=4,t=lc){let r=new WeakMap;return(n,o,a={})=>{let s=a.racingLine===!0,i=s?[a.params?Pg(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 hA={racingLine:!1,standingStart:!1},$m=256;function uc(e,t,r,n,o=hA,a=lc){let s=Ro(n),{racingLine:i,standingStart:c,lapCounts:l}=o;return e.map(u=>{let{track:m}=a(t,r,{racingLine:i,params:u});return mg(qi(u,s,{track:m,numerics:r,standingStart:c,lapCounts:l}))})}function Dg(e,t){let r=Ro(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 Eg(e,t,r){let n={};for(let o of Ro(e).metrics)n[o.key]=o.value(t,r);return n}var Gm=36;var Ng=287.05287,TN=461.495,Km=9.80665/(Ng*.0065),PN=101325/(Ng*288.15),LN=273.15,DN=-500,EN=6e3,IN=400,_N=1100,Hm={source:"car",altitudeM:0,pressure:{kind:"standard"},humidityPct:0};function NN(e){return 101325*Math.pow(1-.0065*e/288.15,Km)}function ON(e){return 288.15/.0065*(1-Math.pow(e/PN,1/(Km-1)))}function VN(e){return 288.15/.0065*(1-Math.pow(e/101325,1/Km))}function BN(e,t){return e*Math.pow(1-.0065*t/288.15,Km)}function $N(e){return 611.21*Math.exp((18.678-e/234.5)*(e/(257.14+e)))}function GN(e,t){switch(e.kind){case"standard":return NN(t);case"qnh":return BN(e.hPa*100,t);case"station":return e.hPa*100}}function mc(e,t,r=0,n=VN(e)){let o=t+LN,a=Math.min(.5*e,Math.max(0,Math.min(100,r))/100*$N(t)),s=e-a,i=s/(Ng*o)+a/(TN*o);return{altitudeM:n,p:e,pDry:s,T:o,rho:i,densityAltitudeM:ON(i)}}function bA(e,t){return mc(GN(e.pressure,e.altitudeM),t,e.humidityPct,e.altitudeM)}var Ig=(e,t,r)=>Math.min(r,Math.max(t,e)),_g=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function zm(e){if(!e||typeof e!="object")return structuredClone(Hm);let t=e,r=t.pressure??{},n=Ig(_g(r.hPa,1013.25),IN,_N),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:Ig(_g(t.altitudeM,0),DN,EN),pressure:o,humidityPct:Ig(_g(t.humidityPct,0),0,100)}}var pc=e=>e?.source==="venue";var KN=Math.PI/180;function HN(){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:[10,480,420],rockerToDamper:[10,280,440],damperChassis:[10,275,245]}}function zN(){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:[12,486,430],rockerToDamper:[12,286,450],damperChassis:[12,281,255]}}function Og(e){let t=-e*KN;return q([0,Math.cos(t),Math.sin(t)])}function Ym(){let e={rodType:"push",pushrodAttach:"lowerArm",steerMode:"rack",spinAxis:Og(-1),loadedRadius:230,springRate:35,rackAxis:[0,1,0]};return{hardpoints:HN(),config:e}}function dc(){let e={rodType:"pull",pushrodAttach:"lowerArm",steerMode:"fixed",spinAxis:Og(-1.5),loadedRadius:232,springRate:40,rackAxis:[0,1,0]};return{hardpoints:zN(),config:e}}function Wm(){let e=[-25,635,460],t=[-40,600,710],r={layout:"mcpherson",actuation:"direct",rodType:"push",pushrodAttach:"upright",steerMode:"rack",spinAxis:Og(-.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 Vg(){return{front:Ym(),rear:dc(),config:{wheelbase:1600,trackFront:1200,trackRear:1220,frontAxleX:800}}}var YN=Math.PI/180;function gA(e){let t=-e*YN;return q([0,Math.cos(t),Math.sin(t)])}function Bg(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:gA(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]=WN(o[l]);return{hardpoints:o,config:c}}function WN(e){return e.map(t=>Math.round(t*10)/10+0)}function ko(e){return{name:e.name,front:Bg(Ym(),e.front),rear:Bg(dc(),e.rear),config:{wheelbase:e.wheelbase,trackFront:e.trackFront,trackRear:e.trackRear,frontAxleX:e.wheelbase/2}}}function qa(e,t,r){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:t}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:r}}}}var Qa=600,Mo=610,Za=230,So=232;function Ao(){let e=Vg();return{...e,name:"Formula Student",front:{...e.front,config:{...e.front.config,actuation:"rocker"}},rear:{...e.rear,config:{...e.rear.config,actuation:"rocker"}}}}function $g(){return ko({name:"Formula 1",wheelbase:3600,trackFront:1600,trackRear:1600,front:{kx:1.3,ky:800/Qa,kz:355/Za,lowerInnerDz:-5,upperInnerDz:0,camberDeg:-3,loadedRadius:355,springRate:200},rear:{kx:1.3,ky:800/Mo,kz:355/So,lowerInnerDz:35,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:220}})}function fc(){return qa(ko({name:"GT car",wheelbase:2700,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/Qa,kz:325/Za,lowerInnerDz:18,upperInnerDz:5,camberDeg:-3.5,loadedRadius:325,springRate:110,actuation:"direct"},rear:{kx:1.2,ky:825/Mo,kz:325/So,lowerInnerDz:36,upperInnerDz:15,camberDeg:-2,loadedRadius:325,springRate:120,actuation:"direct"}}),318.6,318.6)}function hc(){return qa(ko({name:"Sports car",wheelbase:2750,trackFront:1550,trackRear:1550,front:{kx:1.15,ky:775/Qa,kz:320/Za,lowerInnerDz:36,upperInnerDz:15,camberDeg:-.5,loadedRadius:320,springRate:55,actuation:"direct"},rear:{kx:1.15,ky:775/Mo,kz:320/So,lowerInnerDz:57,upperInnerDz:25,camberDeg:-1,loadedRadius:320,springRate:60,actuation:"direct"}}),305.4,309)}function jN(e,t,r,n,o,a){let s=Wm(),i=Object.fromEntries(Object.entries(s.hardpoints).map(([l,[u,m,f]])=>[l,[u,m+e,f]])),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:gA(n),springRate:o,rackTravel:a}}}function yA(){return qa({name:"Cup car",front:jN(55,-25,-23,-3.5,150,55),rear:Bg(dc(),{kx:1.15,ky:820/Mo,kz:320/So,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 xA(){return{...qa(ko({name:"Stock car",wheelbase:2794,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/Qa,kz:355/Za,lowerInnerDz:20,upperInnerDz:5,camberDeg:-2.5,loadedRadius:355,springRate:175,actuation:"direct"},rear:{kx:1.2,ky:825/Mo,kz:355/So,lowerInnerDz:40,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:150,actuation:"direct"}}),343.8,345.3),chassis:{boxes:[],body:"nascar"}}}function RA(){let e=qa(ko({name:"Hill-climb prototype",wheelbase:2550,trackFront:1580,trackRear:1540,front:{kx:1.1,ky:790/Qa,kz:300/Za,lowerInnerDz:10,upperInnerDz:5,camberDeg:-2.5,loadedRadius:300,springRate:90},rear:{kx:1.1,ky:770/Mo,kz:300/So,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 vA(){let e=qa(ko({name:"Race truck",wheelbase:3700,trackFront:2050,trackRear:1950,front:{kx:1.5,ky:1025/Qa,kz:506/Za,lowerInnerDz:40,upperInnerDz:10,camberDeg:-.5,loadedRadius:506,springRate:200,actuation:"direct"},rear:{kx:1.5,ky:975/Mo,kz:506/So,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 nt=(e,t,r)=>({value:e,label:t,unit:r}),kA=(e,t)=>({...hr[e],value:t});function MA(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 Fo(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 en(e){let t={name:e.name,m:nt(e.m,"vehicle mass (with driver)","kg"),A:nt(e.A,"frontal area","m^2"),c_l:nt(e.cl,"downforce coefficient","-"),c_w:nt(e.cw,"drag coefficient","-"),l_to_d_ratio:nt(e.cw>0?e.cl/e.cw:0,"lift-to-drag ratio","-"),driven_wheels:nt(e.drivenWheels,"driven wheels","-"),fr_0:nt(-.012,"rolling-resistance coefficient","-"),front_aero_diss:nt(e.frontAero,"front aero distribution","-"),front_mass_diss:nt(e.frontMass,"front mass distribution","-"),r_dyn:nt(e.rDyn,"dynamic tyre radius","m"),rho:nt(1.2,"air density","kg/m^3"),gear_ratio:nt(e.gearRatio,"gear ratio","-"),effi_pgb:nt(e.drivetrainEfficiency,"drivetrain efficiency","-"),capacity:nt(e.capacityAh,"pack capacity","Ah"),soc:nt(1,"state of charge","-"),ocv:nt(e.ocv,"pack open-circuit voltage","V"),power_scale:nt(1,"power scaling factor","-"),power_limit_kw:kA("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]=kA(r,n);return t}var Ja={name:"Formula Student",m:300,A:1,cl:3,cw:1.3,frontMass:.47,frontAero:.45,rDyn:.222,drivenWheels:2,gearRatio:11.5,motor:MA(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}},Kg={name:"Formula 1",m:798,A:1.5,cl:3,cw:.9,frontMass:.46,frontAero:.44,rDyn:.35,drivenWheels:2,gearRatio:4.9,motor:Fo(735,2e3,12500,2500,2),motorCount:1,driveline:{rear:St.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}},jm={name:"GT car",m:1300,A:2,cl:1.4,cw:.42,frontMass:.5,frontAero:.42,rDyn:.33,drivenWheels:2,gearRatio:3.43,motor:Fo(410,2e3,8e3,2e3,2),motorCount:1,driveline:{rear:St.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}},Um={name:"Sports car",m:1600,A:2.2,cl:-.1,cw:.3,frontMass:.55,frontAero:.5,rDyn:.32,drivenWheels:2,gearRatio:3.14,motor:Fo(220,1500,6500,1400,2),motorCount:1,driveline:{rear:St.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}},Hg={name:"Cup car",m:1265,A:2.1,cl:.45,cw:.4,frontMass:.62,frontAero:.45,rDyn:.31,drivenWheels:2,gearRatio:3.5,motor:Fo(250,2e3,7e3,1190,2),motorCount:1,motorPlacement:"front",driveline:{front:St.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}},zg={name:"Stock car",m:1620,A:2.2,cl:.6,cw:.45,frontMass:.53,frontAero:.45,rDyn:.35,drivenWheels:2,gearRatio:4.1,motor:Fo(500,2500,9e3,1680,2),motorCount:1,driveline:{rear:St.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}},Yg={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:Fo(330,3e3,8500,1240,2),motorCount:1,driveline:{rear:St.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}},Wg={name:"Race truck",m:5300,A:6.2,cl:-.1,cw:.65,frontMass:.6,frontAero:.6,rDyn:.502,drivenWheels:2,gearRatio:3.55,motor:Fo(880,100,3e3,88e3,2),motorCount:1,driveline:{rear:St.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:110,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 Gg(e,t,r){return en(r({...structuredClone(e),name:t}))}var Xm={[Ja.name]:en(Ja),"Formula Student +15% downforce":Gg(Ja,"Formula Student +15% downforce",e=>({...e,cl:e.cl*1.15,cw:e.cw*1.08})),"Formula Student -15 kg":Gg(Ja,"Formula Student -15 kg",e=>({...e,m:e.m-15})),"Formula Student +15% power":Gg(Ja,"Formula Student +15% power",e=>({...e,motor:MA(25*1.15,15e3,2e4),powerLimitKw:80*1.15})),[Kg.name]:en(Kg),[jm.name]:en(jm),[Um.name]:en(Um),[Hg.name]:en(Hg),[zg.name]:en(zg),[Yg.name]:en(Yg),[Wg.name]:en(Wg)},SA=Object.keys(Xm),jg=SA.slice(0,4),Ug=[Ja.name,Kg.name,jm.name,Um.name,Hg.name,zg.name,Yg.name,Wg.name];var soe={"Touring car":jm.name,"Street car":Um.name};var UN={bg:"#0e1116",panel:"#161b22",panel2:"#1c232d",border:"#2a323d",borderBright:"#39424e",sunken:"#11161c",ink:"#06090d"},XN={normal:"#d6dde6",dim:"#8b96a3",bright:"#e7ecf3",white:"#ffffff"},qN={label:"#c8d2dc",grid:"#39424e",gridFaint:"#232b35",empty:"#1a2028"},QN={accent:"#4aa3ff",accentInk:"#04121f",warn:"#ffb454",good:"#4ec9a0",bad:"#ff6b6b",badSoft:"#ff8f8f"},ZN=["#f0e442","#7b68ee","#f7a8b8","#d55e00","#d8b4fe","#b5e48c"],qm={front:"#a6e22e",rear:"#00b4d8"},AA=["#5b4bd6","#4aa3ff","#4ec9a0","#f0e442"],Xg={power:"#ffb454",traction:"#f0845c",front:qm.front,rear:qm.rear,grip:"#73c9b3",braking:"#b48aff",crest:"#e88fd0",below:"rgba(214, 221, 230, 0.32)"},JN={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"},eO={x:"#ff6b6b",y:"#57c75a",z:"#4aa3ff"},tO={line:"#b4bfcb"},rO={compression:"#b48aff",tension:"#ff6b6b"},nO={fz:"#e7ecf3",fx:"#7ad7f0",fy:"#ff54c8"},oO={drivenLine:"#4d7cff",axis:"#eef3fa",slip:"#ffe81a",drive:Xg.power,brake:Xg.braking},aO={ground:"#101920",grid:"#1a2630",gridMajor:"#26343f",horizon:"#1d2833",bridge:"#6f7a86",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},sO={chassis:"#435160",volume:"#303b47",tyre:"#435160",tyreLine:"#39424e",tyreFace:"#1c232d"},iO={centreLine:"#4aa3ff",corridorFill:"rgba(74,163,255,0.10)",boundary:"#3d4956",racingLine:"#ffb454",start:"#e7ecf3",finish:"#ff6b6b",direction:"#8b96a3"},cO={SURFACE:UN,TEXT:XN,CHART:qN,ROLE:QN,SERIES:ZN,AXLE:qm,LAP_SPEED:AA,LIMITER:Xg,RIG:JN,AXIS:eO,CONSTRUCTION:tO,FORCE:rO,TYRE_FORCE:nO,REPLAY:oO,SCENERY:aO,BODY:sO,TRACK:iO},FA=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):Object.freeze({...r})])),Qm=FA(cO),Ft=Qm.SERIES,wA=(()=>{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 FA({SURFACE:{bg:"#f4f5f3",panel:"#fbfbfa",panel2:"#ffffff",border:"#d6dadd",borderBright:"#b7bec4",sunken:"#eceeeb",ink:"#ffffff"},TEXT:{normal:"#22272d",dim:"#5c6570",bright:"#0f1215",white:"#000000"},CHART:{label:"#3a424b",grid:"#c2c8cd",gridFaint:"#e2e5e7",empty:"#e8eae7"},ROLE:{accent:"#1a64c2",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:"#15181c",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 CA=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},coe=(()=>{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=Qm[r],o=wA[r];for(let a of Object.keys(n)){let s=CA(n[a]);s&&!e.has(s)&&e.set(s,o[a])}}return e})();var TA=(e,t)=>new Set(t.flatMap(r=>{let n=e[r];return Array.isArray(n)?[...n]:Object.values(n)}).map(CA).filter(r=>r!==null)),loe=TA(wA,["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION"]),uoe=TA(Qm,Object.keys(Qm).filter(e=>e!=="SURFACE"));function qg(){return{kind:"simple",name:"Simple motor",rpm:[0,16e3,2e4],torque:[21,21,14],efficiency:.95}}function Qg(){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 Zg(){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 Jg(){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 e0(){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 PA(){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 LA(){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 DA(){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 EA(){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 IA(){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 _A(){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 NA(e){return yo(lO(e))}function lO(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;let t={...e};return delete t.name,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 bc(e,t){return{...t,fingerprint:NA(e)}}var OA="CC-BY-4.0",uO={title:"PaceDynamics built-in library",url:"https://pacedyn.dev/",licence:OA},VA={fidelity:"generic",licence:OA,sources:[uO]};var Zm=e=>bc(e,VA);var BA=["raw.githubusercontent.com"],$A=["tum-csv"],pO=/^[0-9a-f]{64}$/;function yc(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"||!pO.test(r)||!$A.includes(n))return!1;try{let o=new URL(t);return o.protocol==="https:"&&BA.includes(o.hostname)&&!o.username&&!o.password&&!o.port}catch{return!1}}var Jm=e=>new URL(e.url).hostname;async function GA(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 dO(e){let t=new URL(e).pathname.split("/").pop()??"";return decodeURIComponent(t).replace(/\.[^.]*$/,"")||"Linked track"}function fO(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 hO={"tum-csv":fO};function KA(e,t){return hO[t.format](e,dO(t.url))}async function t0(e,t,r){let n=await GA(e);if(n!==t.sha256)throw new Error(`${Jm(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=KA(new TextDecoder().decode(e),t),a=await ep(o);if(a!==r)throw new Error(`Linked track ${r} does not convert to its name (it is ${a}).`);return o}var r0=20,gO=new RegExp(`^[0-9a-f]{${r0}}$`),xc=e=>typeof e=="string"&&gO.test(e);async function ep(e){let t=new TextEncoder().encode(Cn(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,r0)}var n0=e=>`tracks/${e}.json`;var yO=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function o0(e){return{model:{name:e.name,source:e.source},...e.provenance?{provenance:e.provenance}:{}}}async function a0(e,t){if(!yO(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 ep(e);if(r!==t)throw new Error(`Catalogue track ${t} does not match its name (it is ${r}).`);return e}var wo=(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}),Tn=[wo("suspensions","suspensionId","suspension"),wo("tires","tireModelId","tyre",[{key:"tiresRear",ref:"tireModelIdRear",label:"rear tyre"}]),wo("motors","motorModelId","motor"),wo("aeros","aeroModelId","aero map"),wo("batteries","batteryModelId","battery"),wo("brakes","brakeModelId","brakes"),wo("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 tp(e){let t={...e};for(let r of Tn)for(let n of r.refs)delete t[n];return t}var rp=Ft,Rc=rp,s0=rp,Pn=[...Ft.slice(3),...Ft.slice(0,3)],l0=[...Ft.slice(1),Ft[0]],i0=[...Ft.slice(2),...Ft.slice(0,2)],c0=[...Ft.slice(4),...Ft.slice(0,4)],u0=[...Ft.slice(5),...Ft.slice(0,5)],vc=[...Ft.slice(2),...Ft.slice(0,2)];function m0(){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 p0(e,t,r){let n=Xm[e];if(!n)throw new Error(`no preset vehicle named "${e}"`);return{id:t,params:{...ki(structuredClone(n)),energy:{...$r},suspensionId:"sus1"},visible:!0,color:Rc[r%Rc.length]}}function vO(){return jg.map((e,t)=>p0(e,`v${t+1}`,t))}function kO(){return[Js(),Xf(),qf(),Qf(),Zf(),Jf(),eh(),th(),rh(),nh()].map((t,r)=>({id:`t${r+1}`,color:s0[r%s0.length],model:t}))}function MO(){return[Td(),Pd(),Ld(),Dd(),Ed(),Id(),_d(),Nd()].map((t,r)=>({id:`a${r+1}`,color:i0[r%i0.length],model:t}))}function SO(){return[fd(),hd(),bd()].map((t,r)=>({id:`b${r+1}`,color:c0[r%c0.length],model:t}))}function AO(){return[{id:"brk1",color:u0[0],model:structuredClone(kh)}]}function FO(){return[{id:"dmp1",color:vc[0],model:structuredClone(Du)}]}function wO(){return[qg(),Qg()].map((t,r)=>({id:`m${r+1}`,color:Pn[r%Pn.length],model:t}))}function d0(e){let t=r=>({...r,provenance:Zm(r.model)});return{...e,suspensions:e.suspensions.map(t),vehicles:e.vehicles.map(r=>({...r,provenance:Zm(tp(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 kc(e="Untitled project"){let t=new Date().toISOString(),r=vO();return d0({schemaVersion:Gm,meta:{id:m0(),name:e,domain:"racecar",rulesetId:xo,createdAt:t,updatedAt:t},suspensions:[{id:"sus1",color:l0[0],model:Ao()}],activeSuspensionId:"sus1",vehicles:r,activeVehicleId:r[0]?.id??null,tires:kO(),motors:wO(),aeros:MO(),batteries:SO(),brakes:AO(),dampers:FO(),tracks:[],activeTrackId:null,mathChannels:[],rulesets:[],studies:[],activeStudyId:null,loadCases:[],reportLayouts:[],tyreSheets:[],kinSheets:[],lapSheets:[],plans:[],results:[],settings:{numerics:{...Vi},ggvMode:"twoTrack",quasiTransient:!1,motorThermal:!1,brakeFade:!1,airTempC:Dt,air:structuredClone(Hm),diffYaw:!1,lapCounts:{},pathPlanId:null,useRacingLine:!0,standingStart:!1}})}var CO=["front","rear"],f0=9.81,TO=Math.PI/180;var Mr="*",h0=40,HA=.8;function b0(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 zA(e,t,r){let n=t.rows.map(c=>c.v),o=c=>bt(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/f0*100)/100+0,axG:Math.round(u/f0*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(h0/3.6,o(h0/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(HA*s,o(HA*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 g0(e,t,r){let n=!1,o=e.map(a=>{if(!a.follows)return a;let s=zA(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 y0(e,t){let r=e.speedKmh/3.6,n=e.ayG*f0;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)/TO}var YA=e=>e.ayG<0?"L":"R";function x0(e,t=CO){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 R0=(e,t)=>e.travelMin===t.travelMin&&e.travelMax===t.travelMax&&e.rollMaxDeg===t.rollMaxDeg&&e.rollAtLimitDeg===t.rollAtLimitDeg;var tn=Math.PI/180,PO=9.81,Mc=.1,v0=20,WA=6,qA=50;function jA(e,t,r){let n=e(0),o=0;for(let f=t;f<=r+1e-9;f+=t){let p=e(f);if(p>n)n=p,o=f;else if(f>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 f=0;f<14;f++)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 k0(e,t,r,n,o){let a=o*tn;if(t==="side")return jA(i=>r*e.Fy(r*i*tn,n,a),1,45);let s=t==="drive"?1:-1;return jA(i=>s*e.Fx(s*i,n,a),.02,.6)}function op(e){let t=e?Ql(e)?.gamma:void 0,r=[t?.min,t?.max].filter(o=>o!==void 0&&Number.isFinite(o));if(!r.length)return{lo:-WA,hi:WA,stated:!1};let n=Math.max(...r.map(Math.abs))/tn;return{lo:-n,hi:n,stated:!0}}function LO(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),f=e(u),p=e(m);for(let h=0;h<12;h++)f>p?(c=m,m=u,p=f,u=c-l*(c-i),f=e(u)):(i=u,u=m,f=p,m=i+l*(c-i),p=e(m));let d=f>=p?{g:u,v:f}:{g:m,v:p};return d.v>s?d.g:a}var UA=250,XA=new WeakMap;function DO(e,t,r,n,o,a,s){let i=XA.get(e);i||XA.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=d=>{let h=l.get(d);if(h===void 0){let b=Math.max(50,d*UA);h=LO(g=>k0(r,n,o,b,g).force,s.lo,s.hi),l.set(d,h)}return h},m=Math.max(0,a)/UA,f=Math.floor(m),p=m-f;return p<1e-9?u(f):u(f)*(1-p)+u(f+1)*p}function es(e,t){return t==="front"?e.tireModel:e.tireModelRear??e.tireModel}var EO=new WeakMap,IO=new WeakMap,_O=new WeakMap,M0=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n};function ap(e,t){let r=es(e,t);return r?M0(EO,r,()=>Ws(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 S0(e,t){let r=es(e,t);return r?M0(_O,r,()=>Zl(r).none)?"This tyre file has no drive or brake grip.":M0(IO,r,()=>{let n=Pe(r),o=r.kind==="magic"?r.fnomin:r.nominalLoad,a=n.Fx(.1,o,0),s=n.Fx(.1,o,3*tn);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 Co(e,t){return e==="side"||e==="ackermann"?Math.abs(t.ayG)>=Mc?e==="ackermann"&&!(QA(t)<=v0)?`is a corner wider than ${v0} m`:null:"does not corner":(e==="drive"?t.axG:-t.axG)>=Mc?null:e==="drive"?"does not drive":"does not brake"}var NO=e=>e.axG>=Mc?"drive":e.axG<=-Mc?"brake":null;function QA(e){let t=e.speedKmh/3.6,r=Math.abs(e.ayG)*PO;return r>1e-9?t*t/r:1/0}var np=(e,t)=>`${e==="front"?"F":"R"}${t}`,OO=e=>e==="L"?"R":"L",VO=(e,t,r)=>Math.min(r,Math.max(t,e));function A0({ev:e,params:t,input:r,state:n,pose:o}){let a=`${Q(t,"grip_scale")}|${Q(t,"stiffness_scale")}`,s=QA(n),i=r.wheelbase*(1-r.frontMassFrac)/1e3,c=r.wheelbase*r.frontMassFrac/1e3,l=r.wheelbase/1e3,u=k=>(k==="front"?r.trackFront:r.trackRear)/2e3,m=(k,v,x,M,A)=>{let w=ye(e,k),T=es(t,k),P=Math.max(0,o.loads[v]),S=o.camber[v],F=VO(S,A.lo,A.hi),C=k0(w,x,M,P,F),L=P<qA,E=T&&!L?DO(T,a,w,x,M,P,A):F,D=L?C.force:k0(w,x,M,P,E).force,O=.05;return{corner:v,Fz:P,lifted:L,camber:S,read:F,outside:F!==S,wants:E,atEdge:!L&&(E-A.lo<O||A.hi-E<O),peak:C.force,slip:C.at,best:D}},f=(k,v,x)=>{let M=v[0].best+v[1].best,A=v[0].peak+v[1].peak;return{kind:k,wheels:v,lossCamber:M>0?Math.max(0,1-A/M):NaN,range:x}},p=new Map,d=k=>{if(p.has(k))return p.get(k)??null;let v=null;if(!Co("side",n)){let x=op(es(t,k));v=[m(k,np(k,o.outer),"side",1,x),m(k,np(k,OO(o.outer)),"side",-1,x)]}return p.set(k,v),v},h=new Map,b=new Map,g=new Map,y=(k,v,x)=>{let M=k==="front"?i:-c,A=(v?1:-1)*u(k),w=x*tn;return Math.atan2(M+s*Math.sin(w),s*Math.cos(w)-A)/tn},R=k=>(n.ayG<0?-1:1)*o.steer[k];return{side(k){if(h.has(k))return h.get(k)??null;let v=ap(t,k)?null:d(k),x=v?f("side",v,op(es(t,k))):null;return h.set(k,x),x},long(k){if(b.has(k))return b.get(k)??null;let v=NO(n),x=null;if(v&&!S0(t,k)){let M=op(es(t,k));x=f(v,[m(k,np(k,"L"),v,1,M),m(k,np(k,"R"),v,1,M)],M)}return b.set(k,x),x},toeLoss(k){let v=g.get(k);if(v!==void 0)return v;let x=d(k),M=NaN;if(x&&x[0].peak+x[1].peak>0){let A=ye(e,k),[w,T]=x,P=[{g:w,dt:1,inner:!1,steer:R(w.corner)},{g:T,dt:-1,inner:!0,steer:R(T.corner)}],S=D=>P.reduce((O,_)=>{let z=_.steer-y(k,_.inner,D);return O+_.dt*A.Fy(_.dt*z*tn,_.g.Fz,_.g.read*tn)},0),F=P.map(D=>D.steer-D.g.slip-y(k,D.inner,0)),C=Math.min(...F)-2,L=Math.max(...F)+2,E=BO(S,C,L,.25);M=Math.max(0,1-E/(w.peak+T.peak))}return g.set(k,M),M},ackermann(){if(Co("ackermann",n))return NaN;let k=d("front");if(!k||k[0].lifted||k[1].lifted)return NaN;let[v,x]=k,M=Math.sqrt(Math.max(s*s-c*c,1e-6)),A=u("front"),w=(Math.atan(l/(M-A))-Math.atan(l/(M+A)))/tn;if(!(w>.001))return NaN;let T=R(x.corner)-R(v.corner),P=w+(x.slip-v.slip);return 100*(T-P)/w}}}function BO(e,t,r,n){let o=-1/0,a=t;for(let p=t;p<=r+1e-9;p+=n){let d=e(p);d>o&&(o=d,a=p)}let s=a-n,i=a+n,c=.6180339887498949,l=i-c*(i-s),u=s+c*(i-s),m=e(l),f=e(u);for(let p=0;p<14;p++)m>f?(i=u,u=l,f=m,l=i-c*(i-s),m=e(l)):(s=l,l=u,m=f,u=s+c*(i-s),f=e(u));return Math.max(o,m,f)}var $O=9.81,ZA=Math.PI/180,Sc={speed:20,ayG:1.2};function F0(e,t={}){let r=t.operating??Sc,n=t.assemble,o,a,s,i=new Map,c=new Map,l=new Map,u=new Map,m=new Map,f=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}),p=()=>{if(o!==void 0)return o;if(!n)return o=null;try{o=n(e)}catch{o=null}return o},d=()=>{if(a!==void 0)return a;try{a=yr(e.params)}catch{a=null}return a},h=v=>{let x=f(v),M=`${x.speed}|${x.ayG}`,A=i.get(M);if(A!==void 0)return A;let w=d();if(!w)return i.set(M,null),null;let T={cornerStiffness:P=>w.corneringStiffness(P),ayG:x.ayG,speed:x.speed,fyAxle:(P,S)=>2*w.Fy(P,S/2),tire:w};return i.set(M,T),T},b=()=>{if(s!==void 0)return s;let v=p(),x=d();if(!v||!x)return s=null;try{s=ro(x,v.massTotal*$O*1.2)}catch{s=null}return s},g=v=>{let x=f(v).speed,M=`${x}`,A=c.get(M);if(A!==void 0)return A;let w=p(),T=d(),P=null;if(w&&T)try{P=yb(w,T,x,{steering:!1})}catch{P=null}return c.set(M,P),P},y=v=>{let x=`${v.speedKmh}|${v.ayG}|${v.axG}`,M=m.get(x);if(M!==void 0)return M;let A=null,w=p();try{let T=w?.kinFront,P=w?.kinRear;if(w&&T&&P){let S=y0(v,w.wheelbase),F=v.speedKmh/3.6,C=bn(w,T,P,F)(v.ayG,v.axG,0,S),L={FL:C.FL.travel,FR:C.FR.travel},E=oo(w,S*ZA,L),D=S?E.camber:null,O={},_={};for(let I of["FL","FR","RL","RR"]){let N=I[1]==="R"?C[I].camberRoad:0-C[I].camberRoad;O[I]=N+(D?.[I]??0),_[I]=E.steer[I]/ZA+(I[1]==="R"?1:-1)*C[I].bumpToe}let z=Te(w,v.ayG,v.axG,F,0,S,L,C.steeringJacking);A={corners:C,rollDeg:C.FL.camberRoad-C.FL.camber,steerDeg:S,camber:O,outer:YA(v),loads:z,steer:_}}}catch{A=null}return m.set(x,A),A},R=new Map;return{operating:r,dynAvailable:!!n,poseAt:y,tyreAt:v=>{let x=`${v.speedKmh}|${v.ayG}|${v.axG}`,M=R.get(x);if(M!==void 0)return M;let A=y(v),w=p(),T=d(),P=A&&w&&T?A0({ev:T,params:e.params,input:w,state:v,pose:A}):null;return R.set(x,P),P},operatingAt:f,dynInput:p,tyre:d,dynCtx:h,grip:b,ymd:g,ymdLimit:v=>{let x=`${f(v).speed}`,M=l.get(x);if(M!==void 0)return M;let A=g(v),w=A?Xb(A):null;return l.set(x,w),w},reserves:(v,x)=>{let M=f(x),A=`${v}|${M.speed}|${M.ayG}`,w=u.get(A);if(w!==void 0)return w;let T=p(),P=h(x),S=null;if(T&&P)try{S=zi(T,P,v,b()??void 0)}catch{S=null}return u.set(A,S),S}}}var JA=["widthLeft","widthRight","bank","mu"];function Ac(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 w0(e){let t=Ac(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 ip(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 f of JA){let p=l[f];if(p===void 0)continue;let d=s[f],h=r[f];for(let b=0;b<o&&t[b]<l.from;b++)h=d[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;d[b]=u>0&&y<u?h+(p-h)*(y/u):p}}}return s}function cp(e,t,r){if(!t.length)return e;let n=Ac(e),o=n.length,a={widthLeft:sp(e.widthLeft,r.widthLeft),widthRight:sp(e.widthRight,r.widthRight),bank:sp(e.bank,r.bank),mu:sp(e.mu,r.mu)},s={};for(let c of JA){let l=e[c];Array.isArray(l)&&l.length===o&&(s[c]=l)}let i=ip(t,n,a,s);return{...e,...i}}function sp(e,t){return typeof e=="number"?e:t}var rF=1,eF=4,up=Math.PI/180,C0=e=>e===null||!Number.isFinite(e)||e===0?0:1/e;function T0(e){return e.kind==="arc"?Math.abs(e.radius)*Math.abs(e.angle)*up:e.length}function lp(e,t){return e.kind==="straight"?0:e.kind==="arc"?C0(e.radius):t}function tF(e){return e.kind==="straight"?0:e.kind==="arc"?C0(e.radius):C0(e.endRadius)}var Fc=(e,t,r,n,o)=>e+t*o+(n>0?(r-t)*o*o/(2*n):0);function wc(e,t={}){let r=Math.max(.05,t.spacing??rF),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((S,F)=>S+T0(F),0),m=Math.max(n?3:2,Math.round(u/r)),f=u>0?u/m:r,p=o.x,d=o.y,h=o.heading*up,b=e.length?lp(e[0],0):0,g=0,y=f,R=(S,F,C)=>{s.push(S),i.push(F),c.push(C)};R(p,d,0);let k=(S,F,C,L,E)=>{let D=E-L;if(D<=0)return;if(Math.abs(F-S)<1e-12){let _=Fc(h,S,S,C,L);if(Math.abs(S)<1e-12)p+=D*Math.cos(_),d+=D*Math.sin(_);else{let z=_+S*D;p+=(Math.sin(z)-Math.sin(_))/S,d+=-(Math.cos(z)-Math.cos(_))/S}return}let O=D/eF;for(let _=0;_<eF;_++){let z=L+_*O,I=Fc(h,S,F,C,z),N=Fc(h,S,F,C,z+O/2),B=Fc(h,S,F,C,z+O);p+=O/6*(Math.cos(I)+4*Math.cos(N)+Math.cos(B)),d+=O/6*(Math.sin(I)+4*Math.sin(N)+Math.sin(B))}};for(let S of e){let F=T0(S),C=lp(S,b),L=tF(S);if(l.push({from:g,to:g+F,...S.widthLeft!==void 0?{widthLeft:S.widthLeft}:{},...S.widthRight!==void 0?{widthRight:S.widthRight}:{},...S.bank!==void 0?{bank:S.bank}:{},...S.mu!==void 0?{mu:S.mu}:{},...S.ramp!==void 0?{ramp:S.ramp}:{}}),F<=0){b=L;continue}let E=0;for(;y<=g+F+1e-9;){let D=Math.min(F,y-g);k(C,L,F,E,D),E=D,R(p,d,g+D),y+=f}k(C,L,F,E,F),h=Fc(h,C,L,F,F),b=L,g+=F}let v=s.length>1?Math.hypot(s[0]-s[s.length-1],i[0]-i[i.length-1]):0,x=g;n&&s.length>1&&(s.pop(),i.pop(),c.pop());let M=e.length?lp(e[0],b):0,A={gap:v,headingError:GO((h-o.heading*up)/up),curvatureError:b-M},w=[];for(let S=0;S<e.length;S++){let F=tF(e[S]),C=S+1<e.length?e[S+1]:n?e[0]:null;if(!C)continue;let L=lp(C,F);w.push({index:S,before:F,after:L,jump:Math.abs(L-F)})}let T=ip(l,c,a);return{asset:{name:t.name??"Track",x:s,y:i,fit:"interpolate",...n?{}:{closed:!1},...T},sections:l,joints:w,closure:A,length:x}}function GO(e){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t}var KO={halfWidthM:1.5,spacingM:.5};function Cc(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 ${oF(e).toFixed(0)} m`}}}function oF(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 aF=e=>e.kind==="skidpad"||e.kind==="curves"&&e.closed===!0,sF=e=>e.kind==="acceleration",iF=1.5,cF=3;function HO(e,t){let r=e.offsetM,n=e.pitchM,o=Math.max(1,e.gates)*n,a=Math.max(0,e.leadInM),s=iF*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*(cF*Math.PI/180))):t.spacingM,m=[],f=[],p=Math.max(1,Math.round(a/u));for(let h=0;h<p;h++)m.push(-a+a*h/p),f.push(0);let d=Math.max(8,Math.round(o/u));for(let h=0;h<=d;h++){let b=o*h/d;m.push(b),f.push(r*c(b)*Math.sin(Math.PI*b/n))}return{name:Cc(e),x:m,y:f,closed:!1,widthLeft:t.halfWidthM,widthRight:t.halfWidthM,fit:"interpolate"}}function zO(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 P0(e,t={}){let r={...KO,...t},n=sF(e),o=zO(e);if(!o){let u=HO(e,r);return{asset:u,peakCurvature:nF(u),worstJoint:0,standingStart:n}}let a=aF(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*(cF*Math.PI/180))):r.spacingM,c=wc(o,{name:Cc(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:nF(c.asset),worstJoint:l.reduce((u,m)=>Math.max(u,m.jump),0),standingStart:n}}function nF(e){try{return Math.max(...lt(e).curvature.map(Math.abs))}catch{return NaN}}var pp={courses:[{id:"c1",course:{kind:"manoeuvre",spec:{kind:"skidpad",radiusM:8.375}}}],ggvMode:"twoTrack"};function L0(e){return e.course.kind==="project"?"the project\u2019s track":e.course.kind==="track"?e.course.name:Cc(e.course.spec)}var lF=new WeakMap,mp=new Map;function uF(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=mp.get(n);if(o)return{...o,numerics:r};let a=P0(e.spec),s={asset:a.asset,standingStart:a.standingStart};return mp.size>64&&mp.clear(),mp.set(n,s),{...s,numerics:r}}function D0(e,t,r={}){let n=r.lap??pp,o=r.simParams,a=r.numerics??{},s=n.courses.length?n.courses:pp.courses,i,c,l,u=new Map,m=new Map,f=new Map,p=new Map,d=k=>(k?.courseId?s.find(v=>v.id===k.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=k=>{let v=d(k);if(!v)return null;let x=m.get(v.id);if(x!==void 0)return x;let M=uF(v.course,r,a),A=null;if(M)try{let w=JSON.stringify(M.numerics),T=lF.get(M.asset);T||(T=new Map,lF.set(M.asset,T));let P=T.get(w);P||(P=lt(M.asset,M.numerics),T.set(w,P)),A={id:v.id,track:P,standingStart:M.standingStart,numerics:M.numerics,name:M.asset.name}}catch{A=null}return m.set(v.id,A),A},g=()=>{if(c!==void 0)return c;let k=h();if(!k)return c=null;try{l=Et(k),c=xr(l,!1,n.ggvMode)}catch{c=null}return c},y=k=>{let v=b(k);if(!v)return null;let x=f.get(v.id);if(x!==void 0)return x;let M=g(),A=null;if(M)try{let w=l?ho(l,M,[v.track],v.numerics,n.ggvMode,u):void 0,T=l?Fn(l,M.rows):void 0;A=At(M,v.track,v.numerics,{standingStart:v.standingStart,...w?{load:w}:{},...T?{shifts:T}:{}})}catch{A=null}return f.set(v.id,A),A};return{lapSettings:n,get lapAvailable(){return!!o&&s.some(k=>!!uF(k.course,r,a))},lapParams:h,courses:()=>s,course:b,ggv:g,lap:y,lapReserve:k=>{let v=b(k);if(!v)return null;let x=p.get(v.id);if(x!==void 0)return x;let M=y(k),A=t.dynInput(),w=t.tyre(),T=null;if(M&&A&&w)try{let P=h();T=gm(A,w,{v:M.v,ax:M.ax,ay:M.ay,ds:v.track.ds,axDrag:Ya(g()?.rows,M.v),...M.axScrub?{axScrub:M.axScrub}:{},axGrade:An(v.track.gradient,M.v.length),bank:v.track.bank,...M.loadFactor?{loadFactor:M.loadFactor}:{}},P?{driven:Oh(P)}:{})}catch{T=null}return p.set(v.id,T),T}}}var mF=180/Math.PI,E0={rise:0,sinPitch:0,sinRoll:0};function pF(e){let t=e.kc;return t?dF(e.vehicle,r=>t.ground0[r]):E0}function dF(e,t){let r=e.config,n=mn(r),o=0,a=0,s=0,i=0,c=0,l=0,u=0,m=0,f=0;for(let g of cr){let y=He(g,r),R=y.axleX-n,k=y.sideSign*Ht(e,y.isFront)/2,v=t(g);if(!Number.isFinite(v))return E0;o++,a+=R,s+=k,i+=v,c+=R*R,l+=k*k,u+=R*k,m+=R*v,f+=k*v}let p=o*(c*l-u*u)-a*(a*l-u*s)+s*(a*u-c*s);if(!(Math.abs(p)>1e-9))return{rise:i/o,sinPitch:0,sinRoll:0};let d=(i*(c*l-u*u)-a*(m*l-u*f)+s*(m*u-c*f))/p,h=(o*(m*l-u*f)-i*(a*l-u*s)+s*(a*f-m*s))/p,b=(o*(c*f-m*u)-a*(a*f-m*s)+i*(a*u-c*s))/p;return{rise:d,sinPitch:h,sinRoll:-b}}function Tc(e,t){let r=e.kc,n=dF(e.vehicle,o=>(r?r.ground0[o]:0)+t[o]);return q([-n.sinPitch,n.sinRoll,1])}function I0(e,t,r,n){let o=q(Pr(e,He(t,r)));return-Math.asin(Math.max(-1,Math.min(1,X(o,n))))*mF}function dp(e,t,r,n,o){let a=q(Pr(n,He(t,r))),s=q([1-a[0]*a[0],-a[0]*a[1],-a[0]*a[2]]),i=oe(a,s),c=p=>[X(p,s),X(p,i),X(p,a)],l=p=>te(te(U(s,p[0]),U(i,p[1])),U(a,p[2])),u=e.points,m=c(u.spinAxis),f=Ms({uprightUpper:c(u.uprightUpper),uprightLower:c(u.uprightLower),wheelCenter:c(u.wheelCenter),spinAxis:m,tieOuter:c(u.tieOuter),loadedRadius:o.loadedRadius,patchShift:o.patchShift&&YO(o.patchShift,e.metrics.toe/mF,Math.atan2(m[0],m[1]))});return{caster:f.caster,kpi:f.kpi,scrubRadius:f.scrubRadius,mechanicalTrail:f.mechanicalTrail,scrubAtWheel:f.scrubAtWheel,trailAtWheel:f.trailAtWheel,kingpinOffset:f.kingpinOffset,casterOffset:f.casterOffset,kingpinGround:l(f.kingpinGround),contactPatch:l(f.contactPatch),elbow:l([f.contactPatch[0],f.kingpinGround[1],f.kingpinGround[2]]),kingpinAtHub:l(f.kingpinAtHub)}}function YO(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 fp(e,t){let r=pF(t);if(r===E0)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 Ln(e,t,r){let n=fp({heave:0,pitch:0,roll:0,steer:0},r);return e-qd(n,[t,0,0],mn(r.vehicle.config))}var WO=180/Math.PI;function _0(e,t){return!e.valid||!e.ic?!1:Math.hypot(e.ic[0]-e.cp[0],e.ic[1]-e.cp[1])<=t}function hp(e,t,r){let n=He(t,e.vehicle.config),o=vt(e,r),a=Bu(e,t,o[t]),s=a.at("uprightUpper"),i=a.at("uprightLower"),c=a.at("contactPatch"),l=a.at("wheelCenter"),u=F=>{let C=a.velocity(F);return[C[0],C[2]]},m=u(c),f=u(l),p=[c[0],c[2]],d=[l[0],l[2]];if(!a.solved)return{ic:null,line:null,cp:p,wc:d,road:[1,0],swingArmAngleDeg:NaN,tanTheta:NaN,tanThetaHub:NaN,valid:!1,unsolved:!0,sinAngle:0};let h=Tc(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]],R=F=>{let C=F[0]*g[0]+F[1]*g[1];return Math.abs(C)>1e-9?-(F[0]*y[0]+F[1]*y[1])/C:0},k=a.omega[1],v=Math.hypot(m[0],m[1]),x=Math.abs(k)*1e9>v?[p[0]+m[1]/k,p[1]-m[0]/k]:null,A=x?(F=>{let C=[s[0]-F[0],s[2]-F[1]],L=[i[0]-F[0],i[2]-F[1]];return Math.abs(C[0]*L[1]-C[1]*L[0])/(Math.hypot(...C)*Math.hypot(...L))})(x):0;if(!(Math.abs(m[0]*g[0]+m[1]*g[1])>1e-9))return{ic:x,line:null,cp:p,wc:d,road:y,swingArmAngleDeg:0,tanTheta:0,tanThetaHub:0,valid:!1,sinAngle:A};let w=[m[1]/v,-m[0]/v],T=x?[x[0]-p[0],x[1]-p[1]]:[n.isFront?-1:1,0],P=w[0]*T[0]+w[1]*T[1]<0?[-w[0],-w[1]]:w,S=R(m);return{ic:x,line:P,cp:p,wc:d,road:y,swingArmAngleDeg:Math.atan(S)*WO,tanTheta:S,tanThetaHub:R(f),valid:!0,sinAngle:A}}function fF(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}}var UO=180/Math.PI,XO=Math.PI/180,N0=.5,bp=2,O0=.25,qO={heave:0,pitch:0,roll:0,steer:0},QO={FL:"FR",FR:"FL",RL:"RR",RR:"RL"},gp=e=>e.ok?e.state:{...e.nearest,converged:!1};function V0(e,t,r){return t.state?t.solved===!1?{...t.state,converged:!1}:t.state:gp(ge(e,t.travel,t.steer,void 0,r))}var hF=new WeakMap;function bF(e,t){let r=e.ctx[t],n=Oe(e.vehicle,t).config.loadedRadius,o=zt(n,e.kc,t),a=hF.get(r);a||(a=new Map,hF.set(r,a));let s=a.get(o);if(!s){let i=pn(t,e.vehicle.config,qO,e.vehicle);s=gp(ge(r,i.travel,i.steer,void 0,o===n?void 0:{loadedRadius:o})),a.set(o,s)}return s}var Sr=(e,t)=>!e||!e.lo.converged||!e.hi.converged?NaN:(t(e.hi)-t(e.lo))/(2*e.step),gF=(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 xF(e,t,r,n,o){let a=e.vehicle.config,s=ea(r),i=Oe(e.vehicle,r),c=He(r,a),l=e.ctx[r],u=vt(e,t),m=u[r],f={travel:m.travel,steer:m.steer},p=m.rigid?void 0:{loadedRadius:m.loadedRadius},d=V0(l,m,p),h=bF(e,r),b={lo:gp(ge(l,f.travel-N0,f.steer,void 0,p)),hi:gp(ge(l,f.travel+N0,f.steer,void 0,p)),step:N0},g=c.isFront?{lo:Ne(l,d.beta,f.steer-bp,void 0,p),hi:Ne(l,d.beta,f.steer+bp,void 0,p),step:bp}:null,y=Y=>{let J=vt(e,{...t,roll:t.roll+Y*XO})[r];return V0(l,J,J.rigid?void 0:{loadedRadius:J.loadedRadius})},R={lo:y(-O0),hi:y(O0),step:O0},k=JO(e,t,r,c.isFront,u,g),v=Pt(d.points.contactPatch,c),x=Pt(h.points.contactPatch,c),M=Math.abs(v[1])-Math.abs(x[1]),A=QO[r],w=u[A],T=V0(e.ctx[A],w,w.rigid?void 0:{loadedRadius:w.loadedRadius}),P=T.converged?M+Math.abs(T.points.contactPatch[1])-Math.abs(bF(e,A).points.contactPatch[1]):NaN,S=o??br(e,t,s),F=$u(S,Rt(i)),C=F?null:Gk(S),L=c.sideSign>0?S.icRight:S.icLeft,E=L?Math.hypot(L[0]-v[1],L[1]-v[2]):1/0,D=hp(e,r,t),O=D.ic?Math.hypot(D.ic[0]-D.cp[0],D.ic[1]-D.cp[1]):1/0,_=fF(D,s,a.wheelbase,n),z=-Sr(b,Y=>Y.points.damperLength),I=i.config.springRate,N=Sr(R,Y=>Y.metrics.camber),B=Tc(e,{FL:u.FL.ground,FR:u.FR.ground,RL:u.RL.ground,RR:u.RR.ground}),V=e.kc?.loadCase,G=Y=>V?dp(Y,r,a,B,{loadedRadius:m.loadedRadius,patchShift:V.patchShift[r]}):Y.metrics,H=G(d);return{id:r,converged:d.converged,travel:d.travel,camber:d.metrics.camber,camberRoad:I0(d.points.spinAxis,r,a,B),toe:d.metrics.toe,caster:H.caster,kpi:H.kpi,scrubRadius:H.scrubRadius,mechanicalTrail:H.mechanicalTrail,scrubAtWheel:H.scrubAtWheel,trailAtWheel:H.trailAtWheel,kingpinOffset:H.kingpinOffset,casterOffset:H.casterOffset,steeringArm:d.metrics.steeringArm,camberGain:Sr(b,Y=>Y.metrics.camber),bumpSteer:Sr(b,Y=>Y.metrics.toe),trackScrubRate:Sr(b,Y=>Math.abs(Pt(Y.points.contactPatch,c)[1])),casterGain:Sr(b,Y=>G(Y).caster),kpiGain:Sr(b,Y=>G(Y).kpi),scrubGain:Sr(b,Y=>G(Y).scrubRadius),trailGain:Sr(b,Y=>G(Y).mechanicalTrail),...c.isFront?{camberPerSteer:gF(g,Y=>Y.metrics.camber,Y=>Y.metrics.toe),steerJacking:-gF(g,Y=>Y.points.contactPatch[2],Y=>Y.metrics.toe),...k!==void 0?{steerLoad:k}:{}}:{},rollCamber:N,camberRecovery:-100*c.sideSign*N,rollSteer:c.sideSign*Sr(R,Y=>Y.metrics.toe),halfTrackChange:M,trackChange:P,longitudinal:v[0]-x[0],rollCentreHeight:C?C.heightAboveGround:S.heightAboveGround,rollCentreHeightChassis:(C?C.height:S.height)-Ln(0,c.axleX,e),rollCentreLateral:S.lateralAlongGround,rollCentreValid:S.valid,rollCentreUsable:F,rollCentreHeightUsable:F||C!==null,rollCentreSinAngle:S.sinAngle,fvsaLength:E,svsaLength:O,swingArmAngle:D.swingArmAngleDeg,svsaUsable:_0(D,a.wheelbase),svsaSinAngle:D.sinAngle,...s==="front"?{antiDive:_.brake,antiLift:_.drive}:{antiSquat:_.drive,antiLift:_.brake},decoupled:i.config.actuation==="decoupled",mcpherson:i.config.layout==="mcpherson",springRate:I,motionRatio:z,wheelRate:I*z*z,damperLength:d.points.damperLength,damperTravel:h.points.damperLength-d.points.damperLength,...ZO(i,h.points.damperLength,d.points.damperLength,e.kc?.curve[r].spring?.law),rockerAngle:i.config.actuation==="direct"?0:(d.points.rockerAngle-h.points.rockerAngle)*UO,groundDisplacement:m.rigid?d.travel:m.ground,tyreDeflection:m.tyreDeflection,wheelLoad:m.load,loadedRadiusAt:m.loadedRadius,rideRate:m.rideRate,wheelRateAtLoad:m.wheelRateAtLoad,lifted:m.lifted,clearance:m.clearance??0,tyreRigid:m.rigid}}function ZO(e,t,r,n){if(e.config.actuation==="decoupled")return{};let o=n?{droop:n.droopStated?n.droop:null,bump:n.bump}:ra(t,e.config.coilover),a=t-r;return{...o.droop!==null?{damperToExtended:a-o.droop}:{},...o.bump!==null?{damperToClosed:o.bump-a}:{}}}function JO(e,t,r,n,o,a){if(!a||!n)return;let s=Cl(e,t,"front"),i=e.kc;if(!s||!i)return;let c=["FL","FR"],l=[0,0],u=[0,0],m={lo:[],hi:[]},f=0;for(let h=0;h<2;h++){let b=c[h],g=o[b],y=e.ctx[b],R=g.rigid?void 0:{loadedRadius:g.loadedRadius},x=(b==="FR"?1:-1)*(r==="FR"?1:-1)*bp,M=g.state?{q:[...g.state.pose.t,...g.state.pose.omega],phi:g.state.points.rockerAngle}:void 0,A=ft(ge(y,g.travel,g.steer-x,M,R)),w=ft(ge(y,g.travel,g.steer+x,M,R));if(!A||!w)return NaN;l[h]=w.points.contactPatch[2]-A.points.contactPatch[2],u[h]=Lr(i.curve[b],g.travel,w.points.damperLength)-Lr(i.curve[b],g.travel,A.points.damperLength),m.lo.push(A),m.hi.push(w),b===r&&(f=w.metrics.toe-A.metrics.toe)}let p=i.elements?.front;if(p){let h=[o.FL.travel,o.FR.travel],b=Is(p,h,[m.hi[0],m.hi[1]]),g=Is(p,h,[m.lo[0],m.lo[1]]);u[0]+=b[0]-g[0],u[1]+=b[1]-g[1]}return Math.abs(f)>1e-9?s([0,0],l,u)[r==="FL"?0:1]/f:NaN}function Pc(e,t,r,n,o){return xF(e,t,r==="front"?"FL":"RL",n,o)}function B0(e,t,r,n){let o=Pc(e,t,"front",r,n?.front),a=Pc(e,t,"rear",r,n?.rear);return{front:o,rear:a,wheelbaseChange:o.longitudinal-a.longitudinal}}function yp(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),Ln(Math.min(n.zMin,n.zMax),i,t)],max:[s,Math.max(n.yMin,n.yMax),Ln(Math.max(n.zMin,n.zMax),i,t)]}})}var To=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Ut=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],ot=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],tr=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Lc=e=>Math.sqrt(tr(e,e));function eV(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 tV(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=>tr(r,e)>=tr(r,t)?e:t,samples:()=>Array.from({length:41},(r,n)=>Ut(e,ot(To(t,e),n/40)))}}function rV(e,t,r,n){let o=ot(t,1/(Lc(t)||1)),a=n/2,s=o.map(i=>r*Math.sqrt(Math.max(0,1-i*i))+a*Math.abs(i));return{min:To(e,s),max:Ut(e,s),support:i=>{let c=tr(i,o),l=To(i,ot(o,c)),u=Lc(l),m=u>1e-12?ot(l,r/u):[0,0,0];return Ut(Ut(e,ot(o,c>=0?a:-a)),m)},samples:()=>{let i=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],c=To(i,ot(o,tr(i,o))),l=ot(c,1/Lc(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 f of[-1,-.5,0,.5,1]){let p=Ut(e,ot(o,f*a));m.push(p);let d=Math.abs(f)===1?[.5,1]:[1];for(let h of d)for(let b=0;b<72;b++){let g=b/72*2*Math.PI;m.push(Ut(p,Ut(ot(l,h*r*Math.cos(g)),ot(u,h*r*Math.sin(g)))))}}return m}}}function nV(e){let t=e[0],r=e.slice(1).map(c=>To(c,t)),n=r.length;if(n===0)return{v:t,w:[1]};let o=r.map(c=>r.map(l=>tr(c,l))),a=r.map(c=>-tr(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 f=c;f<n;f++)o[u][f]-=m*o[c][f];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=Ut(i,ot(r[c],s[c]));return{v:i,w:[1-s.reduce((c,l)=>c+l,0),...s]}}function oV(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=nV(a.map(c=>c.w));if(!s||s.w.some(c=>c<-1e-9))continue;let i=tr(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 aV(e,t){let r=s=>{let i=e.support(s),c=t.support(ot(s,-1));return{w:To(i,c),a:i,b:c}},n=(s,i)=>{let c=[0,0,0],l=[0,0,0];return s.keep.forEach((u,m)=>{c=Ut(c,ot(u.a,s.weights[m])),l=Ut(l,ot(u.b,s.weights[m]))}),{distance:i,onA:c,onB:l}},o=r([1,0,0]),a={v:o.w,keep:[o],weights:[1]};for(let s=0;s<64;s++){let i=a.v,c=tr(i,i);if(c<1e-12)return n(a,0);let l=r(ot(i,-1));if(c-tr(i,l.w)<=1e-9*Math.max(1,c))return n(a,Math.sqrt(c));let u=oV([...a.keep,l]);if(u.keep.length===4)return n(u,0);if(tr(u.v,u.v)>=c-1e-12)return n(a,Math.sqrt(c));a=u}return n(a,Lc(a.v))}function sV(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 iV(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 kF={linkRadius:8,mountAllowance:15},cV=(e,t,r)=>e.z0+e.dzdx*t+e.dzdy*r;function lV(e,t){let r=Math.sin(e.pitch);return{z0:-e.heave+t*r,dzdx:-r,dzdy:Math.sin(e.roll)}}function MF(e){return lV(fp({heave:0,pitch:0,roll:0,steer:0},e),mn(e.vehicle.config))}var uV=[{name:"upper wishbone, front leg",inboard:"ucaFront",outboard:"uprightUpper"},{name:"upper wishbone, rear leg",inboard:"ucaRear",outboard:"uprightUpper"},{name:"lower wishbone, front leg",inboard:"lcaFront",outboard:"uprightLower"},{name:"lower wishbone, rear leg",inboard:"lcaRear",outboard:"uprightLower"},{name:"tie rod",inboard:"tieInner",outboard:"tieOuter"},{name:"pushrod",inboard:"rockerToPushrod",outboard:"pushrodOuter"},{name:"strut",inboard:"damperChassis",outboard:"pushrodOuter"}];function mV(e){return uV.filter(t=>t.name==="strut"?e.mcpherson:t.name==="pushrod"?!e.direct:!(e.mcpherson&&t.name.startsWith("upper")))}var pV=(e,t,r)=>e.every((n,o)=>n>=t.min[o]-r&&n<=t.max[o]+r);function RF(e,t,r){let n=To(t,e),o=Lc(n);return o>1e-9?Ut(e,ot(n,r/o)):e}function vF(e,t){let r=null;for(let{shape:n,pad:o,part:a,pose:s}of t){if(r&&iV(e,n)-o>=r.distance)continue;let i=aV(e,n),c=i.distance>0?null:sV(e,n),l=i.distance>0?i.distance-o:-((c?.depth??0)+o);if(Number.isFinite(l)&&(!r||l<r.distance)){let u=i.distance>0?{part:RF(i.onB,i.onA,o),box:i.onA}:c?{part:RF(c.point,c.face,-o),box:c.face}:{part:i.onB,box:i.onA};r={distance:l,part:a,corner:s.corner,travel:s.travel,rack:s.rack,gap:u}}}return r}function dV(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:ot(a.reduce((c,l)=>Ut(c,l),[0,0,0]),1/a.length)}}function SF(e,t){return{...dV(e,r=>r[2]-cV(t,r[0],r[1])),road:t}}function AF(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 fV(e,t){let r=e.map(o=>({pose:o,part:`${o.corner} tyre`,pad:0,shape:rV(o.g.wheelCenter,o.g.spinAxis,o.corner[0]==="F"?t.tyreRadius.front:t.tyreRadius.rear,t.tyreWidth)})),n=e.flatMap(o=>mV(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:tV(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 hV(e,t,r){let n=eV(e.min,e.max),o=t.links.filter(a=>!pV(a.inboard,e,r.mountAllowance+r.linkRadius));return{tyre:vF(n,t.tyres),link:vF(n,o)}}function FF(e,t,r){let n=fV(t,r);return e.map(o=>({boxId:o.id,...hV(o,n,r)}))}var DF=152,EF={travelSteps:9,rackSteps:5},Po=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],rn=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Dc=(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]],rr=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]},IF=180/Math.PI,bV=[[1,0,0],[0,1,0],[0,0,1]],wF=(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]],gV=(e,t)=>[rn(e[0],t),rn(e[1],t),rn(e[2],t)];function CF(e,t,r){let n=rr(Po(t,e)),o=rr(Dc(n,Po(r,e)));return[n,Dc(o,n),o]}function yV(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 $0(e,t,r,n){let o=rr(Po(t,e)),a=b=>{let g=Po(b,e),y=rn(g,o);return[g[0]-y*o[0],g[1]-y*o[1],g[2]-y*o[2]]},s=rr(a(r)),i=rr(a(n)),c=rn(Dc(s,i),o),u=rn(s,i),m=c,f=1-u,[p,d,h]=o;return[[f*p*p+u,f*p*d+m*h,f*p*h-m*d],[f*p*d-m*h,f*d*d+u,f*d*h+m*p],[f*p*h+m*d,f*d*h-m*p,f*h*h+u]]}var xV=(e,t)=>Math.acos(Math.max(-1,Math.min(1,rn(rr(e),rr(t)))))*IF;function RV(e,t){return{upright:yV(CF(e.uprightLower,e.tieOuter,e.wheelCenter),CF(t.uprightLower,t.tieOuter,t.wheelCenter)),uca:t.mcpherson?null:$0(t.ucaFront,t.ucaRear,e.uprightUpper,t.uprightUpper),lca:$0(t.lcaFront,t.lcaRear,e.uprightLower,t.uprightLower),rocker:t.direct?null:$0(t.rockerPivotA,t.rockerPivotB,e.rockerToPushrod,t.rockerToPushrod)}}function _F(e){let t=rr(e[0]),r=Math.abs(t[0])<.9?[1,0,0]:[0,1,0],n=rr(Dc(t,r)),o=Dc(t,n),a=e.map(d=>{let h=rr(d);return[rn(h,n),rn(h,o)]}),s=d=>{let h=Math.cos(d),b=Math.sin(d),g=0;for(let[y,R]of a)g=Math.max(g,Math.abs(y*h+R*b));return g},i=Math.PI/180,c=0,l=1/0;for(let d=0;d<180;d++){let h=s(d*i);h<l&&([c,l]=[d*i,h])}let u=c-i,m=c+i,f=(Math.sqrt(5)-1)/2;for(let d=0;d<30;d++){let h=m-f*(m-u),b=u+f*(m-u);s(h)<s(b)?m=b:u=h}let p=Math.min(l,s((u+m)/2));return Math.asin(Math.min(1,p))*IF}function TF(e){let t=null;for(let r of e)Number.isFinite(r.angle)&&(!t||r.angle>t.angle)&&(t=r);return t}var vV={upright:"upright",lowerArm:"lca",upperArm:"uca"};function NF(e,t,r,n){let o=t.map(m=>RV(e,m)),a=rr(Po(e.uprightUpper,e.uprightLower)),s=m=>Math.max(0,...o.map(f=>f[m]?xV(wF(f.upright,a),wF(f[m],a)):0)),i=[{angle:s("lca"),joint:"lower ball joint"}];e.mcpherson||i.push({angle:s("uca"),joint:"upper ball joint"});let c=(m,f,p)=>{let d=[Po(e[f],e[m])];for(let h=0;h<t.length;h++){let b=p(o[h]);if(!b)return null;d.push(gV(b,Po(t[h][f],t[h][m])))}return d},l=[["tie rod, inner end",c("tieInner","tieOuter",()=>bV)],["tie rod, outer end",c("tieInner","tieOuter",m=>m.upright)]];e.direct||l.push([`${n}, rocker end`,c("rockerToPushrod","pushrodOuter",m=>m.rocker)],[`${n}, outer end`,c("rockerToPushrod","pushrodOuter",m=>m[vV[r]])]);let u=l.filter(m=>m[1]!==null).map(([m,f])=>({joint:m,angle:_F(f)}));return{ballJoint:TF(i),rodEnd:TF(u)}}function kV(e){let t=(r,n)=>{let o=zt(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 OF(e,t){let r=eu(t);return{...kF,tyreRadius:kV(e),tyreWidth:r!==null?r*1e3:DF}}var PF={front:["FL","FR"],rear:["RL","RR"]},LF=(e,t,r)=>r<=1||t===e?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function G0(e,t,r,n,o=EF){let a=e.vehicle,[s]=PF[t],i=Ou(e,s,0,0)?.geometry;if(!i)return null;let c=yp(a.chassis?.boxes??[],{vehicle:a,kc:e.kc}),l=t==="front"?kt(a.front.config):0,u=l>0?LF(-l,l,Math.max(3,o.rackSteps|1)):[0],m=LF(Math.min(0,r.min),Math.max(0,r.max),Math.max(2,o.travelSteps)),f=[];for(let b of c.length?PF[t]:[s])for(let g of m)for(let y of u){let R=Ou(e,b,g,y)?.geometry;R&&f.push({corner:b,travel:g,rack:y,g:R})}let p=null;if(c.length){for(let b of FF(c,f,OF(e,n)))for(let g of[b.tyre,b.link])g&&(!p||g.distance<p.distance)&&(p={distance:g.distance,part:g.part,boxId:b.boxId});p??={distance:NaN,part:"",boxId:""}}let d=a[t].config,h=NF(i,f.filter(b=>b.corner===s).map(b=>b.g),d.pushrodAttach,d.rodType==="pull"?"pullrod":"pushrod");return{chassis:p,...h}}var xp=Math.PI/180,Ec={travelSteps:9,heaveSteps:5,rollSteps:4,rackSteps:6},Rp={travelMin:-25,travelMax:25,rollMaxDeg:3,rollAtLimitDeg:2.5};function MV(e){let t=e.params;return{cgHeight:t.cg_height?yt({...t,surveyedRadiusFront:e.vehicle.front.config.loadedRadius,surveyedRadiusRear:e.vehicle.rear.config.loadedRadius}).cgHeight:300,...Gh(t),drive:Vh(t)}}function VF(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 K0(e,t=Ec,r=Rp,n){let o=null,a=(C,L)=>(o||(o={violation:C,reason:L}),null),s=e.vehicle,i=C=>C==="front"?s.front:s.rear,c=null,l=null,u=()=>{if(c)return c;if(n)try{let C=n();if(C)return c=_t(s,C.kc),l=C.cgHeight,c}catch{a(500,"the car could not be stood on its tyre: its rates did not assemble")}return c=_t(s)},m=C=>C==="front"?"FL":"RL",f=C=>{let L=u();if(!L.kc)return;let E=i(C).config.loadedRadius,D=zt(E,L.kc,m(C));return D===E?void 0:{loadedRadius:D}},p=(C,L)=>-_s(u(),m(C),L),d=new Map,h=new Map,b=new Map,g=new Map,y=new Map,R=new Map,k=new Map,v=new Map,x=new Map,M=null,A=()=>{if(M)return M;u();let C=MV(e);return M=l!==null&&Number.isFinite(l)?{...C,cgHeight:l}:C},w,T,P=()=>{if(T!==void 0)return T;let C=Il(u().ctx.FL,kt(s.front.config));return T=C?_l(C):null,T},S=(C,L,E)=>{if(C.has(L))return C.get(L)??null;let D=E();return C.set(L,D),D};return{car:e,density:t,envelope:r,get failure(){return o},axisLength:(C,L)=>{let E=i(C),D=E.hardpoints;return L==="uca"&&E.config.layout==="mcpherson"?NaN:L==="uca"?Me(D.ucaFront,D.ucaRear):Me(D.lcaFront,D.lcaRear)},linkLength:C=>{let L=i(C).hardpoints;return Me(L.tieInner,L.tieOuter)},compliance:C=>S(h,C,()=>Hf(i(C))??null),sweep:C=>S(d,C,()=>{let L;try{L=ze(i(C),{travelMin:r.travelMin,travelMax:r.travelMax,steps:t.travelSteps})}catch{return a(500,`the ${C} travel sweep threw`)}if(!L.covered){let D=L.samples.map(z=>z.travel),O=Math.max(...D)-Math.min(...D),_=r.travelMax-r.travelMin;return a(Math.max(0,_-O),`the ${C} linkage reaches only ${O.toFixed(0)} mm of the ${_.toFixed(0)} mm travel range`)}if(L.fold)return a(200,`the ${C} travel(beta) folds \u2014 the suspension goes over centre in range`);let E=L.samples.filter(D=>!D.converged).length;if(E>0)return a(100+10*E,`${E} of ${L.samples.length} ${C} travel solves did not converge`);if(C==="front"&&i("front").config.steerMode==="rack"){let D=P();if(D)return a(D.violation,D.reason)}return L}),rcHeave:C=>S(b,C,()=>{let L=[],E=[],D=Math.max(2,t.heaveSteps);try{for(let _=0;_<D;_++){let z=r.travelMin+(r.travelMax-r.travelMin)*_/(D-1);L.push(z),E.push(br(u(),{heave:p(C,z),pitch:0,roll:0,steer:0},C))}}catch{return a(500,`the ${C} roll-centre construction threw in heave`)}let O=VF(E,_=>Math.abs(L[_]-L[_-1]));return O>0?a(300,`the ${C} roll-centre construction lands on another branch at ${L[O].toFixed(0)} mm of travel`):{at:L,rc:E}}),rcRoll:C=>S(g,C,()=>{let L=[],E=[],D=Math.max(2,t.rollSteps);try{for(let _=0;_<D;_++){let z=r.rollMaxDeg*_/(D-1);L.push(z),E.push(br(u(),{heave:0,pitch:0,roll:z*xp,steer:0},C))}}catch{return a(500,`the ${C} roll-centre construction threw in roll`)}let O=VF(E,_=>Math.abs(E[_].cpLeft?.[0]??0)*Math.abs(L[_]-L[_-1])*xp);return O>0?a(300,`the ${C} roll-centre construction lands on another branch at ${L[O].toFixed(1)}\xB0 of roll`):{at:L,rc:E}}),roadUnder:C=>{let L=y.get(C);return L===void 0&&(L=Ln(0,He(m(C),s.config).axleX,u()),y.set(C,L)),L},steer:()=>{if(w!==void 0)return w;try{w=Sf(u(),{steerMax:kt(s.front.config),steps:t.rackSteps})}catch{w=a(500,"the steering sweep threw")}let C=w?.filter(L=>!L.converged).length??0;if(w&&C>0){let L=P();w=L?a(L.violation,L.reason):a(100+10*C,`${C} of ${w.length} steering solves did not converge`)}return w??null},solveAt:(C,L,E=0)=>S(R,`${C}:${L}:${E}`,()=>{try{let D=ge(u().ctx[m(C)],L,E,void 0,f(C));return D.ok?D.state:D.why==="unconverged"?a(100,`the ${C} corner did not solve at ${L.toFixed(0)} mm of travel`):a(100+Math.abs(D.travelMiss),`the ${C} corner reaches only ${(L+D.travelMiss).toFixed(0)} of ${L.toFixed(0)} mm of travel`)}catch{return a(150,`the ${C} corner solve threw at ${L.toFixed(0)} mm of travel`)}}),readout:C=>S(v,`${C.heave}:${C.pitch}:${C.roll}:${C.steer}`,()=>{try{return B0(u(),C,A())}catch{return a(500,"the derived readout threw")}}),readoutAtTravel:(C,L)=>S(x,`${C}:${L}`,()=>{try{return Pc(u(),{heave:p(C,L),pitch:0,roll:0,steer:0},C,A())}catch{return a(500,`the ${C} readout threw at ${L.toFixed(0)} mm of travel`)}}),travelAtRoll:(C,L)=>{let E=i(C).hardpoints.wheelCenter[1]*Math.sin(L*xp),D=u();if(!D.kc)return E;try{let O=vt(D,{heave:0,pitch:0,roll:L*xp,steer:0}),_=C==="front"?Math.max(O.FL.travel,O.FR.travel):Math.max(O.RL.travel,O.RR.travel);return Number.isFinite(_)?_:E}catch{return a(500,`the ${C} axle could not be rolled on its tyre`),E}},onTyre:()=>!!u().kc,contexts:u,keepOuts:C=>S(k,C,()=>{try{let L=e.params,E=C==="front"?L.tireModel:L.tireModelRear??L.tireModel,D={min:r.travelMin,max:r.travelMax};return G0(u(),C,D,E)??a(100,`the ${C} corner did not solve at its design ride`)}catch{return a(500,`the ${C} keep-outs threw`)}})}}var SV=Lg();function H0(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=Dm(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?uc([c],a.track,a.numerics,ac(s),a.settings,SV)[0]:qi(c,s,{numerics:a.numerics,standingStart:l,lapCounts:u});o={};for(let f of s.metrics)rl(f)&&(o[f.key]=f.value(m,void 0))}}catch{o=null}return r.set(n,o),o}}}var vp=.01;function AV(e,t){return t.bump!==null&&e>t.bump-vp?{at:"closed",past:Math.max(0,e-t.bump)}:t.droopStated&&e<t.droop+vp?{at:"toppedOut",past:Math.max(0,t.droop-e)}:t.seat!==null&&e<t.seat+vp?{at:"unseated",past:Math.max(0,t.seat-e)}:{at:"free",past:0}}var BF=e=>({droop:e.droop,droopStated:e.droopStated,bump:e.bump,seat:e.holdsLoad&&Number.isFinite(e.free)?e.free:null}),FV=[["front","FL","FR"],["rear","RL","RR"]];function Y0(e,t){let r=[];for(let[n,o,a]of FV){let s=[t[o],t[a]];for(let m of[o,a]){let f=e.curve[m],p=f.spring?.law;if(!f.spring||!p)continue;let d=nf(f,t[m]);d===null||!Number.isFinite(d)||r.push(z0(m,n,n,d,f.spring.length0-d,BF(p),!0))}let i=e.elements?.[n];if(!i)continue;let c=i.heave?.law;if(c){let m=_R(i,s),f=i.read.heave?.span0,p=n==="front"?"heaveFront":"heaveRear";r.push(z0(p,p,n,m,f!==void 0?f-m:null,BF(c),i.carriesLoad))}let l=i.rollStop,u=l?NR(i,s):null;if(l&&u!==null){let m=l.length0-u,f=n==="front"?"rollFront":"rollRear",p={droop:l.droop??-1/0,droopStated:l.droop!==null,bump:l.bump,seat:null};r.push(z0(f,f,n,m,u,p,i.carriesLoad))}}return r}function z0(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,...AV(n,a),bumpStated:a.bump!==null,bounds:s}}var KF=Math.PI/180;function W0(e,t,r,n){let o=t.speedKmh/3.6,a=Bd(e,o,t.axG,cn(e,t.ayG,0));if(!a||!e.aero)return null;let s=e.wheelbase,i=Zo(e.aero,s),c=(h,b)=>Math.atan((b-h)/s)/KF,l={},u={};for(let h of cr)l[h]=r.corners[h].travel,u[h]=r.corners[h].ground;let m=n.kc?Y0(n.kc,l):[],f=e.aero.model,p=a.downFront+a.downRear,d=f?{balance:Math.abs(p)>1e-9?100*a.downFront/p:NaN,clA:(a.clFront+a.clRear)*a.area,cdA:a.cd*a.area,loopMargin:1-a.gain,dataMargin:HF(f,s,a.hFront,a.hRear)}:null;return{front:{height:a.hFront,...$F(m,"front")},rear:{height:a.hRear,...$F(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:d,clearance:wV(n,u)}}function $F(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 HF(e,t,r,n){let o=(a,[s,i])=>Math.min(a-s,i-a);if(Cx(e)){let{x:a,y:s}=Uo(e),i=[a[0],a[a.length-1]],c=[s[0],s[s.length-1]];return an(e)?GF(e.frame,t,i,c,r,n):Math.min(o(r,i),o(n,c))}return cl(e)?GF(e.frame,t,e.range.h,e.range.pitch,r,n):Math.min(o(r,e.range.hFront),o(n,e.range.hRear))}function GF(e,t,r,n,o,a){let s=Xo(e,t,o,a),i=l=>t*Math.tan(l*KF),c=a-o;return Math.min(s.h-r[0],r[1]-s.h,c-i(n[0]),i(n[1])-c)}function wV(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=Ht(e.vehicle,!0)/2,c=Ht(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 cr){let g=[1,l[b][0],l[b][1]];for(let y=0;y<3;y++){m[y]+=g[y]*t[b];for(let R=0;R<3;R++)u[y][R]+=g[y]*g[R]}}let f=AF(u,m);if(!f)return null;let p=MF(n),d={z0:p.z0+f[0],dzdx:p.dzdx+f[1],dzdy:p.dzdy+f[2]},h=null;for(let b of yp(r,n)){let g=SF(b,d);(!h||g.height<h.height)&&(h={height:g.height,volume:b.name})}return h}function kp(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 CV={front:"front",rear:"rear",heaveFront:"front",heaveRear:"rear",rollFront:"front",rollRear:"rear"};function Ic(e,t,r,n){let o=Wu(e,t);return _u.some(s=>{if(CV[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 j0(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 Mp=Math.PI/180,Sp=1e-6;function YF(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 _c(e){let t=e.measured;if(t)return YF(t.travel,t.camber);let r=q(e.config.spinAxis);return-Math.asin(Math.max(-1,Math.min(1,r[2])))/Mp}function Nc(e){let t=e.measured;if(t)return YF(t.travel,t.toe);let[r,n]=e.config.spinAxis;return Math.atan2(r,n)/Mp}function U0(e,t){let r=Math.abs(t.camber)>=Sp,n=Math.abs(t.toe)>=Sp;if(!r&&!n)return e;let o=e.measured;if(o)return{...e,measured:{...o,...r?{camber:o.camber.map(p=>p+t.camber)}:{},...n?{toe:o.toe.map(p=>p+t.toe)}:{}}};let[a,s]=e.config.spinAxis,i=Math.hypot(a,s);if(!(i>0))return e;let c=(_c(e)+t.camber)*Mp,l=(Nc(e)+t.toe)*Mp,[u,m]=n?[Math.sin(l),Math.cos(l)]:[a/i,s/i],f=[u*Math.cos(c),m*Math.cos(c),-Math.sin(c)];return{...e,config:{...e.config,spinAxis:f}}}function Ap(e){let t=e&&typeof e=="object"?e.value:void 0;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function TV(e,t){let r=t;return{front:Ap(r.camber_front_deg)??_c(e.front),rear:Ap(r.camber_rear_deg)??_c(e.rear)}}function PV(e,t){let r=t;return{front:Ap(r.toe_front_deg)??Nc(e.front),rear:Ap(r.toe_rear_deg)??Nc(e.rear)}}function LV(e){return{camber:{front:_c(e.front),rear:_c(e.rear)},toe:{front:Nc(e.front),rear:Nc(e.rear)}}}var zF=new WeakMap;function DV(e,t){let r=LV(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)<Sp&&Math.abs(u.toe)<Sp;if(o(n.front)&&o(n.rear))return e;let a=`${t.camber.front}|${t.camber.rear}|${t.toe.front}|${t.toe.rear}`,s=zF.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&&U0(m,n[ea(u)])])):void 0,l={...e,front:U0(e.front,n.front),rear:U0(e.rear,n.rear),...c?{corners:c}:{}};return s||zF.set(e,s=new Map),s.size>=16&&s.clear(),s.set(a,l),l}function ts(e,t){return t?DV(e,{camber:TV(e,t),toe:PV(e,t)}):e}var EV=9.81;function rs(e){let t=Yn(e),r=Math.max(0,e.unsprungPerCorner)*EV,n=a=>{let s=a==="FL"||a==="FR",i=s?"front":"rear",c=qe(e,i),l=c>0?c:1/0,u=xd(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:jt(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 WF=new WeakMap;function IV(e){let t=ts(e.vehicle,e.params);if(t===e.vehicle)return e;let r=WF.get(e);return(!r||r.vehicle!==t)&&WF.set(e,r={...e,vehicle:t}),r}function Dn(e,t={}){let r=IV(e),n=F0(r,t),o=t.assemble?()=>{let m=n.dynInput();if(!m)throw new Error("the car did not assemble");return{kc:rs(m),cgHeight:m.cgHeight}}:void 0,a=K0(r,t.density,t.envelope,o),s=D0(r,n,t),i=H0(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(f=>f.id===m)??null,platformAt:m=>{let f=`${m.speedKmh}|${m.ayG}|${m.axG}`,p=l.get(f);if(p!==void 0)return p;let d=n.poseAt(m),h=n.dynInput(),b=null;if(d&&h)try{b=W0(h,m,d,a.contexts())}catch{b=null}return l.set(f,b),b}}}var _V=["x","y","z"],NV=/^(line|plane)\((-?\d+),(-?\d+)\)([uv]?)$/,jF=Math.PI/18e3,UF=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],XF=(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]],OV=e=>Math.hypot(e[0],e[1],e[2]),X0=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];function q0(e){let t=OV(e);return t>1e-9?X0(e,1/t):null}function VV(e,t){let r=e*jF,n=t*jF;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}function Xt(e){let t=e.lastIndexOf(".");if(t<0)return null;let r=NV.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:VV(Number(r[2]),Number(r[3]))},coord:n==="line"?"along":r[4]}}function qF(e){let t=q0(XF([0,0,1],e))??[1,0,0];(t[0]<-1e-9||Math.abs(t[0])<=1e-9&&t[1]<0)&&(t=X0(t,-1));let r=q0(XF(e,t))??[0,1,0];return(r[2]<-1e-9||Math.abs(r[2])<=1e-9&&r[1]<0)&&(r=X0(r,-1)),[t,r]}function Q0(e){if(e.coord==="along")return e.shape.dir;let[t,r]=qF(e.shape.dir);return e.coord==="u"?t:r}function QF(e,t){let r=Xt(t);if(!r)return;let n=_V.map(u=>e[`${r.point}.${u}`]);if(n.some(u=>!u))return;let o=Q0(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=>UF(s(u),o),write:(u,m)=>{let f=s(u),p=m-UF(f,o),d=u;for(let h of a)d=n[h].write(d,f[h]+p*o[h]);return d},...c?{supersededBy:c}:{}}}var ns=["x","y","z"];var BV=/^(?:hp\.(?:front|rear)\.\w+|(?:heave|roll)\.(?:front|rear)\.(?:outer|inner|anchor))$/;function Lo(e){let t=e.lastIndexOf("."),r=e.slice(0,t);if(t<0||!BV.test(r))return null;let n=e.slice(t+1);if(n==="x"||n==="y"||n==="z")return{point:r,axis:n};let o=Xt(e);return o?{point:r,axis:o.coord}:null}var Oc="*";function Z0(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 J0=e=>e?.reads==="speed"||e?.reads==="operating",ey=e=>e?.reads==="lateral"||e?.reads==="operating";function Do(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 Fp(e,t){return e?.appliesAt?t.find(r=>!e.appliesAt(r)):t[0]}function os(e,t,r){let n=r?.stateId?e.stateOf(r.stateId):Fp(t,e.states)??null;return n&&!t.appliesAt?.(n)?n:null}function ut(e,t,r){let n=`${t.id}@${Do(r)}`,o=e.values.get(n);if(o!==void 0)return o;let a;try{a=r?.courseId===Oc&&t.reads==="course"?$V(e,t,r):r?.stateId===Mr&&t.reads==="state"?GV(e,t,r):t.read(e,r)}catch{a=NaN}return e.values.set(n,a),a}function $V(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:ut(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 GV(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:ut(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 ty(e){let t={mean:"weighted mean",max:"highest",min:"lowest",span:"span"};return e?.acrossStates?`every state, ${t[e.acrossStates]}`:"every state"}function je(e){return`${e.quantity??e.groupShort??e.group} \xB7 ${e.label}`}var KV={front:"Front",rear:"Rear"},Vc={heave:0,pitch:0,roll:0,steer:0},ZF="RC height (chassis) [mm]";function JF(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 HV(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 Bc=e=>e.length?Math.max(...e)-Math.min(...e):NaN;function ew(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 tw(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 as(e,t,r){let n=e.stateOf(t?.stateId),o=n?e.poseAt(n):null;return o?r(o):NaN}var $c=(e,t)=>`${e==="front"?"F":"R"}${t}`,rw=e=>e==="L"?"R":"L";function nw(e){let t=KV[e],r=x=>`kin.${e}.${x}`,n=(x,M)=>{let A=x.sweep(e);return A?{x:A.samples.map(w=>w.travel),y:A.samples.map(M)}:{x:[],y:[]}},o=x=>e==="front"?x.vehicle.front:x.vehicle.rear,a=x=>x.params[e==="front"?"heaveFrontDesign":"heaveRearDesign"],s=x=>x.params[e==="front"?"arbFrontDesign":"arbRearDesign"],i=e==="front"?"the front axle":"the rear axle";function c(x){return o(x).config.actuation==="decoupled"?`${i} is decoupled, with no corner damper \u2014 read its heave and roll elements`:null}function l(x){let M=a(x);return M&&M.design.kind!=="none"?null:`${i} has no heave element`}function u(x){let M=a(x);return M?.design.kind==="coil"&&M.linkage?null:`${i} has no heave element on a linkage`}function m(x){let M=s(x);return M&&M.design.kind!=="none"?null:`${i} has no roll element`}function f(x){let M=s(x);return M?.linkage&&M.design.kind!=="none"&&M.design.kind!=="direct"?null:`${i} has no roll element on a linkage`}let p=x=>{if(u(x.car))return null;let M=x.sweep(e);return M?lf(o(x.car),a(x.car).linkage,M.samples):null},d=x=>{if(f(x.car))return null;let M=x.sweep(e);if(!M)return null;let A=s(x.car),w=af(o(x.car),A.linkage,A.design.kind,M.samples),T=w.atDesign<0?-1:1;return{travel:w.travel,ratio:w.ratio.map(P=>P*T),atDesign:w.atDesign*T}},h=x=>x.readout(Vc)?.[e],b=x=>x.readoutAtTravel(e,x.envelope.travelMax),g=x=>{let M=n(x,A=>A.metrics.camber);return M.x.length?{key:r("camberGain"),title:`${t} camber vs travel`,xLabel:"travel [mm]",yLabel:"camber [\xB0]",...M}:null},y=x=>{let M=n(x,A=>A.metrics.toe);return M.x.length?{key:r("bumpSteer"),title:`${t} toe vs travel`,xLabel:"travel [mm]",yLabel:"toe [\xB0]",...M}:null},R=[{id:r("rcStatic"),group:`${t} roll centre`,label:"static height",unit:"mm",scale:30,scope:e,cost:"cheap",read:x=>x.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:x=>{let M=x.rcHeave(e);return M?HV(M.at,M.rc.map(A=>A.height)):NaN},curve:x=>{let M=x.rcHeave(e);return M?{key:r("rcHeaveWorst"),title:`${t} roll-centre height vs wheel travel`,xLabel:"travel [mm]",yLabel:ZF,x:M.at,y:M.rc.map(A=>A.height-x.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:x=>{let M=x.rcRoll(e);return M?Bc(M.rc.map(A=>A.height)):NaN},curve:x=>{let M=x.rcRoll(e);return M?{key:r("rcRollSpan"),title:`${t} roll-centre height vs body roll`,xLabel:"roll [\xB0]",yLabel:ZF,x:M.at,y:M.rc.map(A=>A.height-x.roadUnder(e))}:null}},{id:r("rcLateralSpan"),group:`${t} roll centre`,label:"lateral migration over roll",unit:"mm",scale:50,scope:e,cost:"cheap",read:x=>{let M=x.rcRoll(e);return M?Bc(M.rc.map(A=>A.lateral)):NaN},curve:x=>{let M=x.rcRoll(e);return M?{key:r("rcLateralSpan"),title:`${t} roll-centre lateral position vs body roll`,xLabel:"roll [\xB0]",yLabel:"RC lateral [mm]",x:M.at,y:M.rc.map(A=>A.lateral)}:null}},{id:r("minSinAngle"),group:`${t} roll centre`,label:"construction conditioning (min sinAngle)",unit:"-",scale:.04,scope:e,cost:"cheap",read:x=>{let M=x.rcHeave(e),A=x.rcRoll(e);return!M||!A?NaN:Math.min(...M.rc.map(w=>w.sinAngle),...A.rc.map(w=>w.sinAngle))},curve:x=>{let M=x.rcHeave(e);return M?{key:r("minSinAngle"),title:`${t} construction conditioning vs travel`,xLabel:"travel [mm]",yLabel:"sinAngle",x:M.at,y:M.rc.map(A=>A.sinAngle)}:null}},{id:r("fvsaLength"),group:`${t} roll centre`,label:"front-view swing-arm length",unit:"mm",scale:500,scope:e,cost:"readout",read:x=>h(x)?.fvsaLength??NaN},{id:r("complianceSteer"),group:`${t} compliance`,label:"compliance steer",unit:"\xB0/kN lateral",scale:.05,scope:e,cost:"readout",read:x=>(x.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:x=>(x.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:x=>(x.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:x=>(x.compliance(e)?.toePerMz??0)*1e5},{id:r("staticCamber"),group:`${t} camber & toe`,label:"static camber",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:x=>{let M=x.solveAt(e,0);return M?M.metrics.camber:NaN}},{id:r("staticToe"),group:`${t} camber & toe`,label:"static toe",unit:"\xB0",scale:.5,scope:e,cost:"cheap",read:x=>x.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:x=>h(x)?.camberGain??NaN,curve:x=>g(x)},{id:r("rollCamber"),group:`${t} camber & toe`,label:"camber gain in roll",unit:"\xB0/\xB0",scale:.2,scope:e,cost:"readout",read:x=>h(x)?.rollCamber??NaN},{id:r("rollCamberRecovery"),group:`${t} camber & toe`,label:"camber recovery in roll",unit:"%",scale:20,scope:e,cost:"readout",read:x=>h(x)?.camberRecovery??NaN},{id:r("bumpSteerDesign"),group:`${t} camber & toe`,label:"bump steer at design",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:x=>h(x)?.bumpSteer??NaN,curve:x=>y(x)},{id:r("rollSteer"),group:`${t} camber & toe`,label:"roll steer",unit:"\xB0/\xB0",scale:.1,scope:e,cost:"readout",read:x=>h(x)?.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:x=>{let M=n(x,A=>A.metrics.toe);return M.x.length?JF(M.x,M.y):NaN},curve:x=>y(x)},{id:r("camberGain"),group:`${t} camber & toe`,label:"camber gain, RMS over the travel",unit:"\xB0/mm",scale:.02,scope:e,cost:"cheap",read:x=>{let M=n(x,A=>A.metrics.camber);return M.x.length?JF(M.x,M.y):NaN},curve:x=>g(x)},{id:r("camberSpan"),group:`${t} camber & toe`,label:"camber range over travel",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:x=>Bc(n(x,M=>M.metrics.camber).y)},{id:r("toeSpan"),group:`${t} camber & toe`,label:"toe range over travel",unit:"\xB0",scale:.5,scope:e,cost:"cheap",read:x=>Bc(n(x,M=>M.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:x=>{let M=x.solveAt(e,x.travelAtRoll(e,x.envelope.rollAtLimitDeg)),A=x.solveAt(e,0);return!M||!A?NaN:Math.abs(M.metrics.camber-A.metrics.camber+x.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:(x,M)=>as(x,M,A=>A.camber[$c(e,A.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:(x,M)=>as(x,M,A=>A.camber[$c(e,rw(A.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:(x,M)=>as(x,M,A=>A.corners[$c(e,A.outer)].bumpToe)},{id:r("caster"),group:`${t} upright`,label:"caster",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:x=>x.solveAt(e,0)?.metrics.caster??NaN},{id:r("kpi"),group:`${t} upright`,label:"kingpin inclination",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:x=>x.solveAt(e,0)?.metrics.kpi??NaN},{id:r("scrubRadius"),group:`${t} upright`,label:"scrub radius",unit:"mm",scale:20,scope:e,cost:"cheap",read:x=>x.solveAt(e,0)?.metrics.scrubRadius??NaN},{id:r("mechanicalTrail"),group:`${t} upright`,label:"mechanical trail",unit:"mm",scale:20,scope:e,cost:"cheap",read:x=>x.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:x=>x.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:x=>x.solveAt(e,0)?.metrics.casterOffset??NaN},{id:r("steeringArm"),group:`${t} upright`,label:"steering arm",unit:"mm",scale:20,scope:e,cost:"cheap",read:x=>x.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:x=>h(x)?.casterGain??NaN},{id:r("kpiGain"),group:`${t} upright`,label:"kingpin inclination gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:x=>h(x)?.kpiGain??NaN},{id:r("scrubGain"),group:`${t} upright`,label:"scrub radius gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:x=>h(x)?.scrubGain??NaN},{id:r("trailGain"),group:`${t} upright`,label:"mechanical trail gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:x=>h(x)?.trailGain??NaN},{id:r("motionRatio"),group:`${t} rates`,label:"motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:c,read:x=>{if(c(x.car))return NaN;let M=x.sweep(e);return M?tw(M.samples.map(A=>A.travel),M.samples.map(A=>A.metrics.motionRatio??NaN))??NaN:NaN},curve:x=>{if(c(x.car))return null;let M=n(x,A=>A.metrics.motionRatio??NaN);return M.x.length?{key:r("motionRatio"),title:`${t} motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",...M}:null}},{id:r("mrSpread"),group:`${t} rates`,label:"motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:c,read:x=>{if(c(x.car))return NaN;let M=x.sweep(e);if(!M)return NaN;let A=M.samples.map(T=>T.metrics.motionRatio??NaN).filter(Number.isFinite);if(!A.length)return NaN;let w=A.reduce((T,P)=>T+P,0)/A.length;return w>0?(Math.max(...A)-Math.min(...A))/w:NaN}},{id:r("wheelRate"),group:`${t} rates`,label:"wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:c,read:x=>{if(c(x.car))return NaN;let M=x.sweep(e);return M?tw(M.samples.map(A=>A.travel),M.samples.map(A=>A.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:x=>p(x)?.atDesign??NaN,curve:x=>{let M=p(x);return M?{key:r("heaveMotionRatio"),title:`${t} heave element motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:M.travel,y:M.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:x=>ew(p(x)?.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:x=>l(x.car)||!x.sweep(e)?NaN:Ea(x.car.vehicle,x.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:f,read:x=>d(x)?.atDesign??NaN,curve:x=>{let M=d(x);return M?{key:r("rollMotionRatio"),title:`${t} roll element motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:M.travel,y:M.ratio}:null}},{id:r("rollMrSpread"),group:`${t} rates`,label:"roll element motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:f,read:x=>ew(d(x)?.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:x=>m(x.car)||!x.sweep(e)?NaN:io(x.car.vehicle,x.car.params)[e]??NaN},{id:r("ucaAxisLength"),group:`${t} package`,label:"upper arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:x=>x.axisLength(e,"uca")},{id:r("lcaAxisLength"),group:`${t} package`,label:"lower arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:x=>x.axisLength(e,"lca")},{id:r("linkLength"),group:`${t} package`,label:"tie/toe link length",unit:"mm",scale:100,scope:e,cost:"geometry",read:x=>x.linkLength(e)},{id:r("trackScrubRate"),group:`${t} package`,label:"track scrub rate",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:x=>x.readout(Vc)?.[e].trackScrubRate??NaN},{id:r("trackChange"),group:`${t} package`,label:"track change at full bump",unit:"mm",scale:2,scope:e,cost:"readout",read:x=>b(x)?.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:(x,M)=>as(x,M,A=>A.corners[$c(e,A.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:(x,M)=>as(x,M,A=>A.corners[$c(e,rw(A.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:x=>c(x.car)?NaN:Bc(n(x,M=>M.metrics.damperLength).y),curve:x=>{if(c(x.car))return null;let M=n(x,A=>A.metrics.damperLength);return M.x.length?{key:r("damperStroke"),title:`${t} damper length vs travel`,xLabel:"travel [mm]",yLabel:"length [mm]",...M}:null}}];e==="front"&&R.push({id:r("camberPerSteer"),group:`${t} camber & toe`,label:"camber change with steer",unit:"\xB0/\xB0",scale:.05,scope:"front",cost:"readout",read:x=>h(x)?.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:x=>h(x)?.steerJacking??NaN}),e==="front"?R.push({id:r("antiDive"),group:`${t} anti geometry`,label:"anti-dive",unit:"%",scale:20,scope:"front",cost:"readout",read:x=>x.readout(Vc)?.front.antiDive??NaN}):R.push({id:r("antiSquat"),group:`${t} anti geometry`,label:"anti-squat (driving)",unit:"%",scale:20,scope:"rear",cost:"readout",read:x=>x.readout(Vc)?.rear.antiSquat??NaN},{id:r("antiLift"),group:`${t} anti geometry`,label:"anti-lift (braking)",unit:"%",scale:20,scope:"rear",cost:"readout",read:x=>x.readout(Vc)?.rear.antiLift??NaN});let k=x=>{let M=x.slice(t.length+1);return M.charAt(0).toUpperCase()+M.slice(1)};return[...new Set(R.map(x=>x.group))].flatMap(x=>R.filter(M=>M.group===x)).map(x=>({...x,quantity:`${t} \xB7 ${k(x.group)}`}))}function ow(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 zV=[{id:"kin.front.ackermannCentre",group:"Steering",label:"Ackermann near centre",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>ow(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=>ow(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}}],YV=[{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)=>as(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}}],ry=[...nw("front"),...nw("rear"),...zV,...YV];var WV={front:"Front",rear:"Rear"};function sw(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 aw(e){let t=WV[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=>sw(s.vehicle),read:s=>o(s,i=>i.chassis?.distance)},{...a,id:r("ballJointAngle"),label:`largest ball-joint angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.ballJoint?.angle)},{...a,id:r("rodEndAngle"),label:`largest rod-end angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.rodEnd?.angle)}]}var ny=[...aw("front"),...aw("rear")];var mw={front:"Front",rear:"Rear"},iw=e=>Co("side",e),jV=e=>Co("drive",e)&&Co("brake",e)?"neither brakes nor drives":null;function UV(e,t,r,n){let o=os(e,t,r),a=o?e.tyreAt(o):null;return a?n(a):NaN}function ss(e,t){let r={...e,read:(n,o)=>UV(n,r,o,t)};return r}var cw=e=>e?100*e.lossCamber:NaN,lw=e=>e&&!e.lifted?e.camber-e.wants:NaN;function uw(e){let t=mw[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:iw,unavailable:s=>ap(s.params,e)},a=[ss({...o,id:r("camberErrorOuter"),label:"camber error at the outer wheel",unit:"\xB0",scale:.5},s=>lw(s.side(e)?.wheels[0])),ss({...o,id:r("camberErrorInner"),label:"camber error at the inner wheel",unit:"\xB0",scale:.5},s=>lw(s.side(e)?.wheels[1])),ss({...o,id:r("sideLossCamber"),label:"side grip lost to camber",unit:"%",scale:1},s=>cw(s.side(e))),ss({...n,appliesAt:iw,id:r("sideLossToe"),label:"side grip lost to the toe split",unit:"%",scale:1},s=>100*s.toeLoss(e)),ss({...n,appliesAt:jV,unavailable:s=>S0(s.params,e),id:r("longLossCamber"),label:"drive and brake grip lost to camber",unit:"%",scale:1},s=>cw(s.long(e)))];return e==="front"&&a.push(ss({...n,appliesAt:s=>Co("ackermann",s),id:r("ackermannError"),label:"Ackermann against the tyre",unit:"%",scale:25},s=>s.ackermann())),a}var oy=[...uw("front"),...uw("rear")],XV=/^tyre\.(front|rear)\.(camberErrorOuter|camberErrorInner|sideLossCamber|longLossCamber)$/;function ay(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=XV.exec(a.id);if(!i)continue;let c=i[1],l=i[2]==="longLossCamber",u=s?.stateId==="*"?e.states.filter(m=>!a.appliesAt?.(m)):[os(e,a,s)].filter(m=>!!m);for(let m of u){let f=`${c}|${m.id}|${l}`;if(r.has(f))continue;let p=e.tyreAt(m),d=p?l?p.long(c):p.side(c):null;if(!d)continue;let{lo:h,hi:b,stated:g}=d.range,y=g?`the ${o(h)} \u2026 ${o(b)} its data covers`:`the \xB1${b.toFixed(0)}\xB0 read without a stated range`,R=M=>l?M===0?"left":"right":M===0?"outer":"inner",k=d.wheels.findIndex(M=>M.atEdge),v=d.wheels.findIndex(M=>M.outside&&!M.lifted),x=[];k>=0&&x.push(`the ${mw[c].toLowerCase()} ${R(k)} tyre wants ${o(d.wheels[k].wants)}, the edge of ${y}, and may want more`),v>=0&&x.push(`the ${R(v)} wheel has ${o(d.wheels[v].camber)}, past it, and is read at ${o(d.wheels[v].read)}`),x.length&&r.set(f,`In the ${n(m)} ${x.join("; ")}.`)}}return[...r.values()]}function sy(e,t){let r=e.appliesAt?.(t);return r?`is read at ${t.name}, which ${r}`:null}var qV={front:"Front",rear:"Rear"};function QV(e,t,r,n){let o=os(e,t,r),a=o?e.platformAt(o):null;return(a?n(a):null)??NaN}function qt(e,t){let r={...e,read:(n,o)=>QV(n,r,o,t)};return r}var iy={cost:"cheap",reads:"state"},ZV={unavailable:e=>kp(e.params)};function pw(e){let t=qV[e],r=o=>`platform.${e}.${o}`,n={...iy,group:`${t} platform`,quantity:`${t} \xB7 Platform`,scope:e};return[qt({...n,id:r("rideHeight"),label:"ride height at a state",unit:"mm",scale:5,acrossStates:"min"},o=>o[e].height),qt({...n,id:r("toBumpStop"),label:"travel left to the bump stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>Ic(o.vehicle,o.params,e,"bump")},o=>o[e].toBump),qt({...n,id:r("toDroopStop"),label:"travel left to the droop stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>Ic(o.vehicle,o.params,e,"droop")},o=>o[e].toDroop)]}var wp={...iy,group:"Platform",scope:"car"},Gc={...iy,...ZV,group:"Aero platform",groupShort:"Aero",scope:"car"},cy=[...pw("front"),...pw("rear"),qt({...wp,id:"platform.rake",label:"rake at a state",unit:"\xB0",scale:.2,acrossStates:"span"},e=>e.rakeDeg),qt({...wp,id:"platform.pitch",label:"pitch at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.pitchDeg),qt({...wp,id:"platform.roll",label:"body roll at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.rollDeg),qt({...wp,id:"platform.groundClearance",label:"ground clearance at a state",unit:"mm",scale:5,acrossStates:"min",unavailable:e=>j0(e.vehicle)},e=>e.clearance?.height),qt({...Gc,id:"platform.balance",label:"balance at a state",unit:"%",scale:1,acrossStates:"span"},e=>e.aero?.balance),qt({...Gc,id:"platform.clA",label:"downforce Cl\xB7A at a state",unit:"m\xB2",scale:.1,acrossStates:"mean"},e=>e.aero?.clA),qt({...Gc,id:"platform.cdA",label:"drag Cd\xB7A at a state",unit:"m\xB2",scale:.05,acrossStates:"mean"},e=>e.aero?.cdA),qt({...Gc,id:"platform.dataMargin",label:"margin to the model\u2019s data",unit:"mm",scale:5,acrossStates:"min"},e=>e.aero?.dataMargin),qt({...Gc,id:"platform.loopMargin",label:"aero-elastic margin, 1 \u2212 loop gain",unit:"-",scale:.1,acrossStates:"min"},e=>e.aero?.loopMargin)];var dw={understeer:"operating",yawFreq:"speed",yawZeta:"speed",yawStiffness:"operating",steeringTorque:"operating",steeringTorqueGradient:"operating"};function at(e,t,r,n="cheap"){let o=qb[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,...dw[e]?{reads:dw[e]}:{},read:(a,s)=>{let i=a.dynInput(),c=a.dynCtx(s);return i&&c?o.compute(i,c):NaN}}}var JV=[at("understeer","Handling \u2014 balance",.1),at("tlltdFront","Handling \u2014 balance",5),at("rollStiffFront","Handling \u2014 balance",5)],e3=[at("yawFreq","Handling \u2014 response",.5),at("yawZeta","Handling \u2014 response",.2),at("stabilitySpeed","Handling \u2014 response",50),at("yawStiffness","Handling \u2014 response",2e4,"trim")],t3=[at("steeringTorque","Steering feel",1,"trim"),at("steeringTorqueGradient","Steering feel",2,"trim")],r3=[at("rollGradient","Ride & body",.5),at("pitchGradient","Ride & body",.5),at("rideFreqFront","Ride & body",.5),at("rideFreqRear","Ride & body",.5),at("rollFreq","Ride & body",.5),at("pitchFreq","Ride & body",.5),at("zetaFront","Ride & body",.2),at("zetaRear","Ride & body",.2)],n3=[{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}],o3=[{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}],ly=[...JV,...e3,...t3,...r3,...n3,...o3];function a3(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 uy=[{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)=>a3(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 s3(e,t){let r=/^(.*?)\s*\(([^)]+)\)\s*$/.exec(e);return r?{label:r[1],unit:r[2]}:{label:e,unit:t?"s":""}}function i3(e){return e==="s"||e==="kWh"?.1:e==="km/h"?2:1}var fw=new WeakMap;function Cp(e){let t=fw.get(e);return t||(t=e.metrics.filter(rl).map(r=>{let{label:n,unit:o}=s3(r.label,r.format==="time");return{id:`event.${e.id}.${r.key}`,group:`Events \xB7 ${e.label}`,groupShort:"Events",label:n,unit:o,scale:i3(o),scope:"car",cost:"session",read:a=>a.session(e.id)?.[r.key]??NaN}}),fw.set(e,t),t)}var my=Ua.flatMap(Cp);var Tp=[...ry,...ny,...oy,...cy,...ly,...uy,...my],is=Object.fromEntries(Tp.map(e=>[e.id,e]));var hw={all:Tp,byId:is},bw=new WeakMap;function nr(e=[]){if(e.length===0)return hw;let t=bw.get(e);if(t)return t;let r=vg(e).filter(n=>!Xa(n.id)).flatMap(Cp);return t=r.length?{all:[...Tp,...r],byId:{...is,...Object.fromEntries(r.map(n=>[n.id,n]))}}:hw,bw.set(e,t),t}var Kc=180/Math.PI,cs=Math.PI/180,l3=.2;function Pp(e,t){let r=K(t,e);return q(r[0]<0?Gd(r):r)}var Lp=e=>({side:Math.atan2(e[2],e[0])*Kc,plan:Math.atan2(e[1],e[0])*Kc}),Dp=(e,t)=>q([1,Math.tan(t*cs),Math.tan(e*cs)]),Hc=e=>Math.abs(e[0])>=l3,Ep=(e,t)=>Math.atan(t/Math.max(e,1))*Kc,Ip=(e,t)=>Math.tan(t*cs)*Math.max(e,1);var En=["side","plan","clock","len"],Vt={uca:{fore:"ucaFront",aft:"ucaRear",ball:"uprightUpper"},lca:{fore:"lcaFront",aft:"lcaRear",ball:"uprightLower"}},zc={uca:"upper arm",lca:"lower arm"},u3=1,gw=(e,t)=>Pp(e[Vt[t].fore],e[Vt[t].aft]);function yw(e){let t=q(K($d,U(e,X($d,e))));return{e1:t,e2:oe(e,t)}}function py(e,t){let r=gw(e,t);if(!Hc(r))return`the ${zc[t]}'s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it`;let n=Vt[t],o=un(e[n.ball],e[n.fore],r);return Math.hypot(...K(o,e[n.ball]))>=u3?null:`the ${zc[t]}'s ball joint sits on its own pivot axis, so the arm has no length to swing on`}function nn(e,t){let r=Vt[t],n=e[r.ball],o=gw(e,t),a=un(n,e[r.fore],o),s=K(a,n),i=Math.hypot(s[0],s[1],s[2]),{e1:c,e2:l}=yw(o),u=i>0?U(s,1/i):c;return{...Lp(o),clock:Math.atan2(X(u,l),X(u,c))*Kc,len:i,sFront:X(K(e[r.fore],a),o),sRear:X(K(e[r.aft],a),o)}}function dy(e,t){let r=Dp(e.side,e.plan),{e1:n,e2:o}=yw(r),a=te(U(n,Math.cos(e.clock*cs)),U(o,Math.sin(e.clock*cs))),s=te(t,U(a,e.len));return{fore:te(s,U(r,e.sFront)),aft:te(s,U(r,e.sRear))}}function xw(e,t,r,n){let o=Vt[t],a={...nn(e,t),[r]:n},{fore:s,aft:i}=dy(a,e[o.ball]);return{...e,[o.fore]:s,[o.aft]:i}}function Rw(e,t){return t==="clock"?e.len:Math.abs(e.sFront-e.sRear)/2}function _p(e,t,r){return t==="len"?r:Ep(Rw(e,t),r)}function fy(e,t,r){return t==="len"?r:Ip(Rw(e,t),r)}var Eo=["side","plan","atY","atZ"],Ar={fore:"rockerPivotA",aft:"rockerPivotB"},m3=5,vw=e=>Pp(e.rockerPivotA,e.rockerPivotB);function ls(e){return Math.hypot(...K(e.rockerPivotB,e.rockerPivotA))<m3?"the rocker\u2019s two pivots are the same point, so there is no axis to describe":Hc(vw(e))?null:"the rocker\u2019s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it"}function In(e){let t=vw(e),r=Hc(t)?t:[1,0,0],n=e.rockerPivotA,o=te(n,U(r,-n[0]/r[0]));return{...Lp(r),atY:o[1],atZ:o[2],sA:X(K(n,o),r),sB:X(K(e.rockerPivotB,o),r)}}function hy(e){let t=Dp(e.side,e.plan),r=[0,e.atY,e.atZ];return{a:te(r,U(t,e.sA)),b:te(r,U(t,e.sB))}}function kw(e,t,r){if(ls(e))return e;let{a:n,b:o}=hy({...In(e),[t]:r});return{...e,rockerPivotA:n,rockerPivotB:o}}var Mw=e=>Math.abs(e.sA-e.sB)/2;function by(e,t,r){return t==="side"||t==="plan"?Ep(Mw(e),r):r}function gy(e,t,r){return t==="side"||t==="plan"?Ip(Mw(e),r):r}var ar={front:"Front",rear:"Rear"},or=["x","y","z"],Ge=(e,t)=>t==="front"?e.front:e.rear,Yc=(e,t,r)=>t==="front"?{...e,front:r}:{...e,rear:r},Sw=[{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"}]}],Aw={damperChassis:"strut top mount",pushrodOuter:"strut lower mount"},Io=30;function p3(e){let t=[];for(let r of["front","rear"]){let n=Ge(e.vehicle,r).config.layout==="mcpherson";for(let o of Sw)for(let{key:a,label:s}of o.keys){let i=n&&Aw[a]||s;for(let c=0;c<3;c++)t.push({id:`hp.${r}.${a}.${or[c]}`,group:`${ar[r]} hardpoints \u2014 ${o.kind}`,label:`${i} ${or[c]}`,scope:ar[r],unit:"mm",defaultSpan:Io,read:l=>Ge(l.vehicle,r).hardpoints[a][c],write:(l,u)=>{let m=Ge(l.vehicle,r),f=[...m.hardpoints[a]];f[c]=u;let p={...m.hardpoints,[a]:f};return{...l,vehicle:Yc(l.vehicle,r,{...m,hardpoints:p})}}})}}return t}var d3={side:"axis side-view angle",plan:"axis plan-view angle",clock:"arm clock angle",len:"effective arm length"},f3={side:"\xB0",plan:"\xB0",clock:"\xB0",len:"mm"};function h3(e){let t=[];for(let r of["front","rear"]){let n=Ge(e.vehicle,r).config.layout==="mcpherson";for(let o of["uca","lca"]){let a=Ge(e.vehicle,r).hardpoints,s=py(a,o)?null:nn(a,o);for(let i of En)t.push({id:`arm.${r}.${o}.${i}`,group:`${ar[r]} ${n?"arm axes":"wishbone axes"}`,label:`${zc[o]} \u2014 ${d3[i]}`,scope:ar[r],unit:f3[i],defaultSpan:s?_p(s,i,Io):Io,read:c=>nn(Ge(c.vehicle,r).hardpoints,o)[i],write:(c,l)=>{let u=Ge(c.vehicle,r),m=xw(u.hardpoints,o,i,l);return{...c,vehicle:Yc(c.vehicle,r,{...u,hardpoints:m})}}})}}return t}var b3={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"},g3={side:"\xB0",plan:"\xB0",atY:"mm",atZ:"mm"};function y3(e){let t=[];for(let r of["front","rear"]){let n=Ge(e.vehicle,r).hardpoints,o=ls(n)?null:In(n);for(let a of Eo)t.push({id:`rocker.${r}.${a}`,group:`${ar[r]} rocker axis`,label:`rocker \u2014 ${b3[a]}`,scope:ar[r],unit:g3[a],defaultSpan:o?by(o,a,Io):Io,read:s=>In(Ge(s.vehicle,r).hardpoints)[a],write:(s,i)=>{let c=Ge(s.vehicle,r),l=kw(c.hardpoints,a,i);return{...s,vehicle:Yc(s.vehicle,r,{...c,hardpoints:l})}}})}return t}var Np={front:"heaveFrontDesign",rear:"heaveRearDesign"},yy={front:"arbFrontDesign",rear:"arbRearDesign"};function x3(e,t){return{heave:e.config.actuation==="decoupled"?"heave element":"third spring",roll:t?.design.kind==="coil"?"roll shock":"anti-roll bar"}}var Op=e=>/^(heave|roll)\.(front|rear)\.(outer|inner|anchor)\.[xyz]$/.test(e);function R3(e){let t=[];for(let r of["front","rear"]){let n=Ge(e.vehicle,r),o=e.params[Np[r]],a=e.params[yy[r]],s=x3(n,a),i=d=>d.params[Np[r]],c=d=>d.params[yy[r]],l=(d,h)=>({...d,params:{...d.params,[Np[r]]:h}}),u=(d,h)=>({...d,params:{...d.params,[yy[r]]:h}}),m={group:`${ar[r]} heave & roll elements`,scope:ar[r]},f=(d,h,b,g,y)=>{for(let R of b)t.push({...m,id:`${d}.${or[R]}`,label:`${h} ${or[R]}`,unit:"mm",defaultSpan:Io,read:k=>g(k)[R],write:(k,v)=>{let x=[...g(k)];return x[R]=v,y(k,x)}})},p=(d,h,b,g,y)=>{t.push({...m,id:d,label:h,unit:"N/mm",defaultSpan:Math.max(5,b*.4),read:g,write:y})};if(o?.design.kind==="coil"){if(o.linkage){let d=b=>i(b).linkage;f(`heave.${r}.outer`,`${s.heave} eye`,[0,1,2],b=>d(b).outer,(b,g)=>l(b,{...i(b),linkage:{...d(b),outer:g}})),o.linkage.mount?.kind==="chassis"&&f(`heave.${r}.anchor`,`${s.heave} chassis anchor`,[0,2],b=>d(b).mount.anchor,(b,g)=>l(b,{...i(b),linkage:{...d(b),mount:{kind:"chassis",anchor:g}}}))}if(typeof o.design.rate=="number"){let d=h=>i(h).design;p(`heave.${r}.rate`,`${s.heave} spring rate (@element)`,o.design.rate,h=>d(h).rate,(h,b)=>l(h,{...i(h),design:{...d(h),rate:b}}))}}if(a&&a.design.kind!=="none"){if(a.linkage&&a.design.kind!=="direct"){let h=R=>c(R).linkage,b=dn(n,a.linkage,a.design.kind),[g,y]=b?["left arm eye","right arm eye"]:["drop-link pickup","arm tip"];f(`roll.${r}.outer`,`${s.roll} ${g}`,[0,1,2],R=>h(R).outer,(R,k)=>u(R,{...c(R),linkage:{...h(R),outer:k}})),f(`roll.${r}.inner`,`${s.roll} ${y}`,[0,1,2],R=>h(R).inner,(R,k)=>u(R,{...c(R),linkage:{...h(R),inner:k}}))}let d=a.design;if(d.kind==="coil"&&typeof d.rate=="number"){let h=b=>c(b).design;p(`roll.${r}.rate`,`${s.roll} spring rate (@element)`,d.rate,b=>h(b).rate,(b,g)=>u(b,{...c(b),design:{kind:"coil",rate:g}}))}else d.kind==="direct"&&p(`roll.${r}.wheelRate`,`${s.roll} rate (@wheel)`,d.wheelRate,h=>c(h).design.wheelRate,(h,b)=>u(h,{...c(h),design:{kind:"direct",wheelRate:b}}))}}return t}var v3=[{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 k3(e){let t=[];for(let r of["front","rear"]){let n=Ge(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:ar[r],unit:"N/mm",defaultSpan:Math.max(500,l*.4),read:u=>i(Ge(u.vehicle,r).compliance??{})??l,write:(u,m)=>{let f=Ge(u.vehicle,r),p={...f,compliance:c(f.compliance??{},Math.max(1,m))};return{...u,vehicle:Yc(u.vehicle,r,p)}}})};for(let a of["ucaFront","ucaRear","lcaFront","lcaRear","tieRod","pushRod"])o(`link.${a}`,`${M3[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}`,`${S3[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 M3={ucaFront:"UCA front leg",ucaRear:"UCA rear leg",lcaFront:"LCA front leg",lcaRear:"LCA rear leg",tieRod:"tie rod",pushRod:"push/pull rod"},S3={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 A3(){return v3.map(e=>({id:`cfg.${e.axle}.${e.field}`,group:e.group,label:e.label,scope:ar[e.axle],unit:e.unit,defaultSpan:e.span(e.fallback),read:t=>Ge(t.vehicle,e.axle).config[e.field]??e.fallback,write:(t,r)=>{let n=Ge(t.vehicle,e.axle),o={...n,config:{...n.config,[e.field]:r}};return{...t,vehicle:Yc(t.vehicle,e.axle,o)}}}))}function F3(e){let t=Un(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=>Un(c.params.steeringSystem)[n],write:(c,l)=>({...c,params:{...c.params,steeringSystem:Un({...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 w3(e){let t=_i(e.params),r=[];for(let n of["front","rear"]){if(t[n]!=="diff")continue;let o=lo(e.params.driveline?.[n]);if(o?.kind!=="clutch"&&o?.kind!=="torsen")continue;let a=(s,i)=>{let c=qu[`${n}.${s}`];return{id:`driveline.${n}.${s}`,group:"Differential",label:c.label.charAt(0).toLowerCase()+c.label.slice(1),scope:ar[n],unit:c.unit===": 1"?"":c.unit??"",defaultSpan:i,read:l=>lo(l.params.driveline?.[n])?.[s],write:(l,u)=>({...l,params:{...l.params,driveline:Xu({...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 C3(e){if(hu(e.params)!=="hydraulic")return[];let t=[{id:"brakeSetup.barFront",group:"Brakes",label:`${Wh("barFront").toLowerCase()}, front share`,unit:"-",defaultSpan:.05,read:a=>Br(a.params.brakeSetup).barFront,write:(a,s)=>({...a,params:{...a.params,brakeSetup:Br({...Br(a.params.brakeSetup),barFront:s})}})}];if(!e.params.brakeModel)return t;let r=dr(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:Yh(a.circuit?`${a.circuit}.${String(a.key)}`:a.key),unit:s,defaultSpan:i,read:c=>n(dr(c.params.brakeModel),a),write:(c,l)=>{let u=dr(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:dr(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 Fw=e=>!!e&&typeof e=="object"&&"value"in e&&"label"in e;function ww(e){let t={...e};for(let r of Object.keys(t)){let n=t[r];Fw(n)&&(t[r]={...n})}return t}function T3(e){let t=[];for(let r of dM(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 Fw(s)?s.value:NaN},write:(a,s)=>{let i=ww(a.params);return tm(i,n.label,s),{...a,params:i}}})}return t}function Cw(e){let t={};for(let s of["front","rear"]){if(!Ge(e.vehicle,s).measured)continue;let c="this axle is described by measured curves, so its linkage is not solved";for(let l of Sw)for(let{key:u}of l.keys)for(let m of or)t[`hp.${s}.${u}.${m}`]={why:c};for(let l of["uca","lca"])for(let u of En)t[`arm.${s}.${l}.${u}`]={why:c};for(let l of Eo)t[`rocker.${s}.${l}`]={why:c};for(let l of["heave.outer","heave.anchor","roll.outer","roll.inner"]){let[u,m]=l.split(".");for(let f of or)t[`${u}.${s}.${m}.${f}`]={why:c}}t[`cfg.${s}.springRate`]={why:"the measured curve set carries its own spring rate"}}let r=["rockerPivotA","rockerPivotB","rockerToPushrod","rockerToDamper"];for(let s of["front","rear"]){if(Ge(e.vehicle,s).config.actuation!=="direct")continue;let i="this axle is direct-acting \u2014 there is no bell-crank";for(let c of r)for(let l of or)t[`hp.${s}.${c}.${l}`]={why:i};for(let c of Eo)t[`rocker.${s}.${c}`]={why:i}}for(let s of["front","rear"]){let i=Ge(e.vehicle,s);if(i.measured||i.config.actuation!=="decoupled")continue;let c="this axle is decoupled \u2014 the corner damper is out of circuit";for(let l of["rockerToDamper","damperChassis"])for(let u of or)t[`hp.${s}.${l}.${u}`]={why:c,useInstead:`heave.${s}.outer.${u}`};t[`cfg.${s}.springRate`]={why:"a decoupled axle has no corner spring \u2014 its elements hold it up",useInstead:`heave.${s}.rate`}}for(let s of["front","rear"]){let i=Ge(e.vehicle,s),c=e.params[Np[s]]?.linkage;if(i.measured||!c||c.attach!=="rocker"||c.mount?.kind==="chassis")continue;let l=i.hardpoints,u=[0,1,2].map(f=>l.rockerPivotB[f]-l.rockerPivotA[f]),m=Math.hypot(u[0],u[1],u[2]);if(m>0)for(let f=0;f<3;f++)Math.abs(u[f]/m)<1-1e-12||(t[`heave.${s}.outer.${or[f]}`]={why:`the rocker shaft runs along ${or[f]} \u2014 this only slides the eye along it`})}for(let s of["front","rear"]){let i=Ge(e.vehicle,s);if(i.measured||i.config.layout!=="mcpherson")continue;let c="this axle is a McPherson strut \u2014 there is no upper arm";for(let l of["ucaFront","ucaRear","uprightUpper"])for(let u of or)t[`hp.${s}.${l}.${u}`]={why:c,useInstead:`hp.${s}.damperChassis.${u}`};for(let l of En)t[`arm.${s}.uca.${l}`]={why:c};for(let l of["link.ucaFront","link.ucaRear","bush.ucaFront","bush.ucaRear"])t[`kc.${s}.${l}`]={why:c}}for(let s of["front","rear"]){let i=Ge(e.vehicle,s);if(i.measured)continue;for(let l of["uca","lca"]){if(l==="uca"&&i.config.layout==="mcpherson")continue;let u=py(i.hardpoints,l);if(u)for(let m of En)t[`arm.${s}.${l}.${m}`]={why:u,useInstead:`hp.${s}.${Vt[l].fore}.z`}}let c=ls(i.hardpoints);if(c&&i.config.actuation!=="direct")for(let l of Eo)t[`rocker.${s}.${l}`]={why:c,useInstead:`hp.${s}.${Ar.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[s,i,c,l,u]of n){let m=e.params[s];if(!m?.design||m.design.kind==="none")continue;let f=m.design.kind==="direct"?`${u}.${l}.wheelRate`:`${u}.${l}.rate`;t[i]={why:`computed from ${c}`,useInstead:f}}let o=e.params.aeroModelId||e.params.aeroModel?Eb:Ib;for(let[s,i]of Object.entries(o))t[`param.${s}`]={why:i};if(e.params.batteryModelId||e.params.batteryModel)for(let[s,i]of Object.entries(Zu))t[`param.${s}`]={why:i};for(let[s,i]of Object.entries(Ju(e.params)))t[`param.${s}`]={why:i};let a=hu(e.params);return a==="hydraulic"?t["param.brake_balance"]={why:"set by the balance bar and the brake hardware",useInstead:"brakeSetup.barFront"}:a==="tyre"&&(t["param.brake_balance"]={why:"tyre-limited brakes split as the grip does"}),t}function Tw(e){let t={...L3,...Cw(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[...p3(e),...h3(e),...y3(e),...R3(e),...A3(),...F3(e),...C3(e),...w3(e),...k3(e),...T3(e.params)].map(r)}var P3={spring_front:"cfg.front.springRate",spring_rear:"cfg.rear.springRate"},L3=Object.fromEntries(Object.entries(Db).map(([e,t])=>[`param.${e}`,{why:t,useInstead:P3[e]}])),et=e=>e.scope?`${e.scope} \xB7 ${e.label}`:e.label;function xt(e){let t={};for(let n of Tw(e))t[n.id]=n;let r=(n,o)=>{if(typeof o!="string")return;let a=QF(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 xy=e=>e.step!==void 0&&Number.isFinite(e.step)&&e.step>0?e.step:0,Ry=e=>xy(e)>0||(e.values?.length??0)>0,vy=e=>e.some(Ry),Pw=e=>1e-9*Math.max(1,Math.abs(e.lo),Math.abs(e.hi));function Lw(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=xy(e);if(!r||!Number.isFinite(e.start))return t;let n=Pw(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 Dw=(e,t)=>t.map((r,n)=>e[n]&&Ry(e[n])?Lw(e[n],r):r);function ky(e,t=1e3){if(e.values?.length)return e.values.length;let r=xy(e);if(!r||!Number.isFinite(e.start))return 1/0;let n=Pw(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 My(e,t,r){let n=Dw(e.variables,t),o=n.every((a,s)=>a===t[s]);return{x:n,score:o?r:_r(e,n)}}function Fy(e,t){if(!e.variables.some(Iw))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(_w(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 Iw=e=>!!(e.fixed||e.around||e.follows)||_w(e),_w=e=>!!e.values?.length&&(e.lo!==Math.min(...e.values)||e.hi!==Math.max(...e.values));function mt(e,t){if(!t.variables.some(Iw))return t;let r=xt(e);return Fy(t,n=>{let o=r[n];if(!o)return NaN;try{return o.read(e)}catch{return NaN}})}function sr(e){return[...e.objectives,...e.constraints,...e.watches??[]]}var Bp=e=>(e.metrics??nr()).byId;function wy(e,t){t=mt(e,t);let r=xt(e),n=[];for(let o of t.variables){let a=r[o.id];a&&n.push({id:a.id,name:et(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 us(e,t,r){t=mt(e,t);let n=xt(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]))}),Py(e,o,t.followers,n)}function Cy(e,t,r={}){let n=t.states??[],o=n.some(c=>c.follows);if(!o&&!t.envelopeFollows)return t;let a=Dn(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=g0(n,c,I3(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=Bp(r),u=Ty(t,l),m=sr(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))),f=h=>{let b=Dn(e,{density:t.density,envelope:h,assemble:r.assemble,numerics:r.numerics});return m.every(({r:g,m:y})=>Number.isFinite(ut(b,y,g.at)))},p=c.length===s.length?E3(e,x0(c,u),u):null,d=p&&m.length?D3(p,f):p;d&&!R0(d,t.envelope)&&(i=d)}return s===n&&i===t.envelope?t:{...t,states:s,envelope:i}}var Vp=3;function D3(e,t){let r=(c,l)=>t({...e,travelMin:c,travelMax:l}),n=e.travelMin-Vp,o=e.travelMax+Vp;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+Vp)),i=Math.max(1,Math.min(e.travelMax,o-Vp));return s===e.travelMin&&i===e.travelMax?e:{...e,travelMin:s,travelMax:i}}function Ty(e,t){let r=new Set;for(let n of sr(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 E3(e,t,r){if(!t)return null;let n=ts(e.vehicle,e.params),{travelMin:o,travelMax:a}=t;for(let s of r.map(i=>n[i]))try{let i=ze(s,{travelMin:o,travelMax:a,steps:Ec.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 I3(e){let t=e.projectTrack?.();if(!t)return null;try{return b0(lt(t.asset,t.numerics))}catch{return null}}function Py(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 _n(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 Nw=(e,t="")=>t&&t!=="-"?`${e} ${t}`:`${e}`;function Ow(e,t,r){let n=t??is[e.metricId],o=(n?je(n):e.metricId)+_o(e.at,n,r),a=s=>Nw(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 _o(e,t,r){if(!e&&t?.reads!=="state")return"";e??={};let n=[];if(t?.reads==="state")if(e.stateId===Mr)n.push(ty(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&&J0(t)&&n.push(`${(e.speed*3.6).toFixed(0)} km/h`),e.ayG!==void 0&&ey(t)&&n.push(`${e.ayG.toFixed(2)} g`),e.courseId===Oc&&t?.reads==="course")n.push(Z0(t));else if(e.courseId&&t?.reads==="course"){let o=r?.lap.courses.find(a=>a.id===e.courseId);o&&n.push(L0(o))}return n.length?` @ ${n.join(", ")}`:""}function Vw(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 Bw=5e-4;function $w(e,t){return e.cost!=="lap"&&e.cost!=="session"?0:Number.isFinite(t)?Bw*Math.abs(t):0}function $p(e,t,r={}){return Dn(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 Gp(e,t,r={}){t=mt(e,t);let n=wy(e,t),o=xt(e),a=Bp(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,f)=>{let p=0,d=[];for(let{spec:h,metric:b}of m){let g=ut(f,b,h.at);if(!Number.isFinite(g))return{ok:!1,violation:f.failure?.violation??400,reason:f.failure?.reason??`${je(b)} could not be computed`};let y=_n(h,g);y>0&&(p+=y/b.scale,d.push(`${Ow(h,b,t)} (${Nw(g.toFixed(3),b.unit)})`))}return d.length===0?ei:{ok:!1,violation:p,reason:d.join("; ")}};return{name:"study",variables:n,build:m=>{let f=e;return t.variables.forEach((p,d)=>{let h=o[p.id];h&&(f=h.write(f,m[d]))}),f=Py(e,f,t.followers,o),{car:f,ev:$p(f,t,r)}},feasible:({ev:m})=>{let f=u(i,m);if(!f.ok)return f;for(let{spec:p,metric:d}of c)ut(m,d,p.at);for(let{spec:p,metric:d}of l)ut(m,d,p.at);return m.failure?{ok:!1,violation:m.failure.violation,reason:m.failure.reason}:u(c,m)},terms:({ev:m})=>l.map(({spec:f,metric:p})=>{let d=ut(m,p,f.at);return{name:je(p)+_o(f.at,p,t),raw:d,unit:p.unit,weight:f.weight,contribution:Vw(f,p,d),resolution:Math.abs(f.weight)*$w(p,d)/p.scale}})}}function Sy(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 Gw(e,t){if(e.variables.some(o=>o.id===t))return!0;let r=Lo(t);if(!r||!ns.includes(r.axis))return!1;if(e.variables.some(o=>Xt(o.id)?.point===r.point))return!0;let n=Sy(t);return!!n&&e.variables.some(o=>/^(arm|rocker)\./.test(o.id)&&Sy(o.id)===n)}function _3(e,t){let r=e.followers??[],n=new Map(r.map(i=>[i.id,i.follows])),o=i=>{let c=t[i],l=Lo(i);return c&&l&&ns.includes(l.axis)?{name:et({...c,label:c.label.replace(/ [xyz]$/,"")}),axis:l.axis}:{name:c?et(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),f=p=>p&&p!=="x, y, z"?` in ${p}`:"";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,p=>`${u.name}${f(p)} cannot be moved: ${c.supersededBy.why}.`),!l)s(`no-lead:${u.name}:${i.follows}`,u.axis,p=>`${u.name}${f(p)} 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,p=>`${u.name}${f(p)} cannot move with itself.`);else if(l.unit!==c.unit)s(`unit:${u.name}:${m.name}`,u.axis,p=>`${u.name}${f(p)} 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 p=o(n.get(i.follows));s(`chain:${u.name}:${m.name}`,u.axis,d=>`${u.name}${f(d)} moves with ${m.name}, which itself moves with ${p.name}. Link it to ${p.name}.`)}else Gw(e,i.follows)||s(`still:${u.name}:${m.name}`,u.axis,p=>`${u.name}${f(p)} moves with ${m.name}, which the study does not move${f(p)}. Free that one, or give this its own bound.`)}return[...a.values()].map(i=>i.text(i.axes.join(", ")))}function Ly(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=mt(e,t);let a=xt(e),s=[],i=Bp(r),c=sr(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=sr(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 R=new Set([...y.map(k=>k.id),Mr]);for(let k of m){let v=i[k.metricId];if(k.at?.stateId&&!R.has(k.at.stateId))s.push(`${je(v)} names a state this study no longer has. Point it at one of the states under Conditions.`);else if(k.at?.stateId===Mr&&!v.acrossStates)s.push(`${je(v)} is read at one state at a time, not over every state.`);else if(v.appliesAt){let x=k.at?.stateId&&k.at.stateId!==Mr?y.find(A=>A.id===k.at.stateId):void 0,M=x?sy(v,x):null;M?s.push(`${je(v)} ${M}. Point it at a state that does.`):!x&&!Fp(v,y)&&s.push(`${je(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 f=new Set([...t.lap.courses.map(y=>y.id),Oc]);for(let y of sr(t))if(y.at?.courseId&&!f.has(y.at.courseId)){let R=i[y.metricId];s.push(`${R?je(R):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(R=>/arb_|spring|heave_|front_mass_diss|cg_height|^hp\./.test(R.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 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 R=a[y.id];if(!R){s.push(`\u201C${y.id}\u201D is not a variable this car has.`);continue}if(y.values&&y.values.length<2?s.push(`${et(R)}: list two values or more, or fix it where it is.`):y.hi>y.lo?y.step!==void 0&&ky({...y,start:R.read(e)})<2&&s.push(`${et(R)}: a step of ${y.step} ${R.unit} leaves no other place to land in its box. Make the step finer or the box wider, or fix it.`):s.push(`${et(R)}: the upper bound must be above the lower one (${y.lo} to ${y.hi}).`),R.supersededBy){let v=R.supersededBy.useInstead?a[R.supersededBy.useInstead]:void 0,x=v?et(v):void 0;s.push(`${et(R)} cannot be searched: ${R.supersededBy.why}.`+(x?` Use ${x} instead.`:""))}let k=R.read(e);Number.isFinite(k)&&(k<y.lo||k>y.hi)&&s.push(`${et(R)} starts at ${k.toFixed(1)} ${R.unit}, outside its own bounds.`)}let p=t.followers??[],d=new Map;for(let y of[...t.variables.map(R=>R.id),...p.map(R=>R.id)]){let R=Sy(y);if(!R)continue;let k=d.get(R);k||d.set(R,k={arms:[],coords:[]}),(/^(arm|rocker)\./.test(y)?k.arms:k.coords).push(y)}for(let[y,R]of d){if(R.arms.length===0||R.coords.length===0)continue;let k=x=>a[x]?et(a[x]):x,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 (${R.arms.map(k).join(", ")}) and as pivot coordinates (${R.coords.map(k).join(", ")}). They describe the same ${v}, so whichever is applied second overwrites the other. Keep one.`)}let h=new Map,b=new Set(p.map(y=>y.id));for(let y of[...t.variables.map(R=>R.id),...b]){let R=Lo(y);if(!R)continue;let k=Xt(y),v=b.has(y)?"with":k?`${k.shape.kind}:${y.slice(y.lastIndexOf(".")+1).replace(/[uv]$/,"")}`:"axes",x=h.get(R.point);x||h.set(R.point,x=new Set),x.add(v)}for(let[y,R]of h){if(R.size<2||R.size===2&&R.has("axes")&&R.has("with"))continue;let k=[...R].map(w=>w.split(":")[0]),v=w=>k.filter(T=>T===w).length,x=[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),M=a[`${y}.x`],A=M?et({...M,label:M.label.replace(/ x$/,"")}):y;s.push(`${A} is moved more than one way at once \u2014 ${x.join(" and ")}. Each write moves it off the other's, so keep one.`)}s.push(..._3(t,a));for(let y of t.constraints){let R=i[y.metricId];if(!R){s.push(`\u201C${y.metricId}\u201D is not a metric.`);continue}y.op==="band"&&!((y.limit2??y.limit)>y.limit)&&s.push(`${je(R)}: 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 sr(t))if(y.at?.speed!==void 0&&!(y.at.speed>0)){let R=i[y.metricId];s.push(`${R?je(R):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 sr(t)){let R=i[y.metricId],k=R?.unavailable?.(e);!R||!k||g.has(R.id)||(g.add(R.id),s.push(`${je(R)} cannot be read on this car: ${k}.`))}for(let y of t.objectives)i[y.metricId]?y.weight>0?y.goal==="target"&&!Number.isFinite(y.target)?s.push(`${je(i[y.metricId])}: \u201Chit a value\u201D needs a value.`):y.goal==="target"&&y.tolerance!==void 0&&!(y.tolerance>=0)&&s.push(`${je(i[y.metricId])}: the tolerance must be zero or more.`):s.push(`${je(i[y.metricId])}: weight must be positive.`):s.push(`\u201C${y.metricId}\u201D is not a metric.`);return s}var Kw=.1,Hw=2e3,Ay=3;function Dy(e,t,r={},n=Hw){t=mt(e,t);let o=Gp(e,t,r),a=Bp(r),s=xt(e),i=o.variables.map(S=>S.start),c=S=>{let F=o.build(S);return o.feasible(F).ok&&o.terms(F),F},l=c(i),u=o.feasible(l),m=[...t.objectives,...t.constraints],f=(S,F=m)=>{let C={};for(let L of F){let E=a[L.metricId];E&&(C[`${L.metricId}@${Do(L.at)}`]=ut(S.ev,E,L.at))}return C},p=S=>m.map(F=>S[`${F.metricId}@${Do(F.at)}`]).map(F=>Number.isFinite(F)?F.toFixed(9):"x").join("|"),d=f(l,sr(t)),h=p(d),b=[],g=[],y={},R=[],k=0;t.variables.forEach((S,F)=>{let C=s[S.id];if(!C)return;if(R.length>=Ay&&k>n){g.push(C);return}let L=[...i];L[F]=i[F]+(S.hi-i[F])*.25||S.hi;let E=performance.now(),D=c(L),O=performance.now()-E;k+=O,R.push(O);let _=f(D);y[C.id]=_,p(_)===h&&b.push(C)});let v=t.variables[0],x=v?t.variables.indexOf(v):-1;for(let S=0;v&&R.length>0&&R.length<Ay;S++){let F=[...i];F[x]=i[x]+(v.hi-i[x])*(.4+.15*S)||v.hi;let C=performance.now();c(F),R.push(performance.now()-C)}let M=[...R].sort((S,F)=>S-F),A=M.length?M[M.length>>1]:0,w=[],T=sr(t).map(S=>S.metricId);if(T.some(S=>S.startsWith("dyn.trim")||S==="dyn.ymdMaxAy")){let S=l.ev.ymdLimit();S?.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."),!S&&l.ev.dynAvailable&&w.push("The yaw-moment diagram found no trim point, so anything read off the limit is unavailable.")}if(T.some(S=>S==="dyn.steeringTorque"||S==="dyn.steeringTorqueGradient")){let S=l.ev.tyre()?.model,F=S?fn(S):null;F==="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."):F==="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 P=["lap.minStabil","lap.understeerFrac"];if(T.some(S=>P.includes(S))){let F=l.ev.lapReserve()?.beyondFrac;if(F!==void 0&&Number.isFinite(F)){let C=(F*100).toFixed(0);F>=Kw?w.push(`Over ${C} % 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.`):F>0&&w.push(`${C} % 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(...ay(l.ev,sr(t).map(S=>({m:a[S.metricId],at:S.at})).filter(S=>!!S.m))),{msPerEval:A,values:d,samples:R.length,times:R,dead:b,moves:y,unprobed:g,warnings:w,beyondFrac:T.some(S=>P.includes(S))?l.ev.lapReserve()?.beyondFrac:void 0,startFeasible:u.ok,startReason:u.reason}}var O3=[{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:V3.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 V3=["setup:m","characteristics:peak_power","characteristics:power_to_weight","characteristics:cla","characteristics:cda","characteristics:pack_energy","characteristics:maxAy","characteristics:top_speed"];var ale=new Set(O3.map(e=>e.kind));var zw={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 Ey=["FL","FR","RL","RR"],wt=(e,t,r)=>({input:e,from:r?r[0]:zw[e].from,to:r?r[1]:zw[e].to,n:t}),lle=[{id:"sides",name:"Inside and outside",cards:[{id:"camber-roll",form:"curves",title:"Camber to the road through roll",sweep:wt("roll",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"toe-rack",form:"curves",title:"Wheel angle against the rack",sweep:wt("steer",25),wheels:["FL","FR"],y:["toe"]},{id:"camber-rack",form:"curves",title:"Camber to the road through the steer",sweep:wt("steer",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"load-roll",form:"curves",title:"Wheel loads through roll",sweep:wt("roll",25),wheels:Ey,y:["wheelLoad"]},{id:"travel-roll",form:"curves",title:"Wheel travel through roll",sweep:wt("roll",25),wheels:Ey,y:["travel"]},{id:"toe-roll",form:"curves",title:"Roll steer, all four",sweep:wt("roll",25),wheels:Ey,y:["toe"]}]},{id:"maps",name:"Travel and steer together",cards:[{id:"camber-map",form:"surface",title:"Camber over travel and rack",sweep:wt("travel",17),second:wt("steer",13),wheels:["FL"],y:["camber"]},{id:"bump-steer-map",form:"map",title:"Bump steer over travel and rack",sweep:wt("travel",17),second:wt("steer",13),wheels:["FL"],y:["bumpSteer"]},{id:"bump-steer-family",form:"curves",title:"Bump steer through travel, at five rack positions",sweep:wt("travel",25),second:wt("steer",5,[-20,20]),wheels:["FL"],y:["bumpSteer"]},{id:"scrub-map",form:"surface",title:"Scrub radius over travel and rack",sweep:wt("travel",17),second:wt("steer",13),wheels:["FL"],y:["scrubRadius"]}]}];function Iy(e){let t=Number(e);return Number.isFinite(t)?Math.min(hh,Math.max(fh,t)):Dt}var Ww=6e4;var sue=[{within:60*6e4,every:Ww},{within:1440*6e4,every:60*6e4},{within:720*60*6e4,every:1440*6e4},{within:1/0,every:10080*6e4}];var q3=new Set(["color","visible","source","origin"]),gue=["id",...q3];var Xw=.18/1.18,qw={induction:{kind:"natural"}},Qw=e=>e.breathing??qw;function Kp(e){switch(e?.kind){case"sae-j1349":return mc(99e3,25);case"measured":return mc(e.hPa*100,e.tempC);default:return mc(101325,20)}}var Z3=Kp(void 0);function Zw(e,t){let r=Kp(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 Jw(e,t){let r=e.induction;if(r.kind==="table"){let o=s=>Ie(r.densityAltitudeM,r.powerPct,s),a=o(Kp(e.rated).densityAltitudeM);return a>0?Math.max(0,o(t.densityAltitudeM)/a):0}let n=e.frictionShare??Xw;return Math.max(0,(Zw(e,t)-n)/(1-n))}var Uw=new WeakMap;function Ny(e,t){let r=e.asRated??e,n=`${t.p}|${t.pDry}|${t.T}`,o=Uw.get(r);o||Uw.set(r,o=new Map);let a=o.get(n);if(a)return a;let s=Jw(Qw(r),t),i={...r,torque:r.torque.map(c=>c*s),asRated:r};return o.set(n,i),i}function r5(e){return JSON.parse(Oy(Vy(e,"public/laptime/index.json"),"utf8")).tracks}var n5=async e=>{let t=await fetch(e.url);if(!t.ok)throw new Error(`The track could not be read from ${Jm(e)} (${t.status}).`);return new Uint8Array(await t.arrayBuffer())};function eC(e,t=new Map,r=n5){let n=r5(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(!xc(o.address))throw new Error(`"${o.address}" is not a catalogue address`);if(!yc(o.link))throw new Error("This track is linked to a source this version does not read from.");i=await t0(await r(o.link),o.link,o.address)}else if(o.kind==="catalogue"){if(!xc(o.address))throw new Error(`"${o.address}" is not a catalogue address`);let c=JSON.parse(Oy(Vy(e,"public/catalogue",n0(o.address)),"utf8"));i=await a0(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(Oy(Vy(e,"public/laptime",c),"utf8"))}return t.set(a,i),structuredClone(i)}}var o5=9.81;function tC(e,t=e.tireModel,r=e.tireModelRear){if(!t)return e;let n=e.m.value*o5/4,o=_a(e,t,r),a=Pe(o.front).rollingRadius(n),s=o.rear===o.front?a:Pe(o.rear).rollingRadius(n),i=a5(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 a5(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 s5=1e-6;function rC(e,t,r){let n=e.cgReference;if(!n||!e.cg_height)return e;let o=aM(e,t,r);if(o===void 0||Math.abs(o-n.standingRadius)<s5)return e;let a=n.typed??e.cg_height.value;return{...e,cg_height:{...e.cg_height,value:Ia(e.cg_height.value,n.standingRadius,o)},cgReference:{...n,standingRadius:o,typed:a}}}function nC(e,t,r){let n=e.rcRoad,o=e.rc_front,a=e.rc_rear;if(!n||!o||!a)return e;let s=Uu(e,t,r),i=Xr(o.value,n.gainFront,n.radiusFront,s.front),c=Xr(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 oC=e=>({brakeFade:e.brakeFade,airTempC:e.airTempC,diffYaw:e.diffYaw,...pc(e.air)?{air:e.air}:{}});var No=(e,t)=>t?e.find(r=>r.id===t)?.model:void 0;function Oo(e){return{tire:t=>No(e.tires,t),motor:t=>No(e.motors,t),aero:t=>No(e.aeros,t),battery:t=>No(e.batteries,t),brake:t=>No(e.brakes??[],t),damper:t=>No(e.dampers??[],t),suspensionOf:t=>ts(By(e,t),t)}}function By(e,t){let r=No(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 Vo(e,t,r){let n={front:t.tire(e.tireModelId),rear:t.tire(e.tireModelIdRear)};return $y(Zk(t.suspensionOf(e),e,n),t,r)}function i5(e){return pc(e.air)?bA(e.air,e.airTempC??Dt):void 0}var c5="the air the session states, at its venue";function l5(e,t){return t?{...e,rho:{...e.rho,value:t.rho},readouts:{...e.readouts,rho:c5}}:e}function u5(e,t,r){if(!r)return{rho:e.rho,motorModel:t,readouts:e.readouts};let{rho:n,readouts:o}=l5(e,r);return{rho:n,motorModel:t&&dt(t)?Ny(t,r):t,air:r,readouts:o}}function $y(e,t,r){let n=t.tire(e.tireModelId),o=t.tire(e.tireModelIdRear),a=nC(rC(tC(lM(sM(gM(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}=u5(a,t.motor(e.motorModelId),i5(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),...Fi(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 f5=e=>e!==!1,h5=(e,t,r)=>r&&t>0?(e%t+t)%t:Math.min(Math.max(e,0),t);function b5(e,t,r){let n=e.points.filter(o=>Number.isFinite(o.at)&&Number.isFinite(o.z)).map(o=>({...o,at:h5(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 g5(e,t,r){let n=b5(e,t,r),o=n.length;if(o===0)return[];let a=p=>p<o-1?n[p+1].at-n[p].at:r?n[0].at+t-n[p].at:1/0,s=p=>p<o-1?(n[p+1].z-n[p].z)/a(p):r&&o>1?(n[0].z-n[p].z)/a(p):0,i=n.map(p=>Math.max(0,Number.isFinite(p.curve)?p.curve:0)/2),c=(p,d,h)=>i[p]+i[d]>h?h*i[p]/(i[p]+i[d]):i[p],l=p=>p<o-1||r?c(p,p<o-1?p+1:0,a(p)):Math.max(0,t-n[p].at),u=p=>p>0?c(p,p-1,a(p-1)):r?c(p,o-1,a(o-1)):n[p].at,m=p=>p>0?s(p-1):r&&o>1?s(o-1):n[p].at<=1e-9?s(p):0,f=p=>!r&&p===o-1&&o>1&&n[p].at>=t-1e-9?s(p-1):s(p);return n.map((p,d)=>{let h=l(d),b=u(d),g=Math.min(i[d],h,b),y=!r&&g<i[d]&&(d===o-1&&g===h||d===0&&g===b);return{at:p.at,z:p.z,gIn:m(d),gOut:f(d),half:g,asked:i[d],atEnd:y}})}function y5(e,t,r,n){let o=t-e.at;return n&&r>0?o-r*Math.round(o/r):o}function x5(e,t,r,n){for(let s of e){let i=y5(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 aC(e,t,r,n){let o=f5(n),a=g5(e,r,o);return a.length?t.map(s=>x5(a,s,r,o)):t.map(()=>0)}function Wc(e,t){if(!t?.points.length)return e;let r=Ac(e),{zSmoothing:n,...o}=e;return{...o,z:aC(t,r,w0(e),e.closed)}}var Hp={widthLeft:1.5,widthRight:1.5,bank:0,mu:1};function sC(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 jc(e,t){let r=sC(e.source);return iC(e,r?await t(r):void 0)}function iC(e,t){let{source:r}=e;if(r.kind==="segments"){let{segments:i,closed:c,spacing:l}=r,{asset:u}=wc(i,{name:e.name,closed:c,spacing:l,base:Hp});return Wc(u,r.profile)}let n=r.sections??[];if(r.kind==="inline")return Wc(cp(r.asset,n,Hp),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 Wc(cp({...t,...o!==void 0?{widthLeft:o}:{},...a!==void 0?{widthRight:a}:{},...s!==void 0?{closed:s}:{}},n,Hp),r.profile)}var Upe=1/500;var Xpe=5*Math.PI/180;var ode=1/3;var M5=[4,2,1,.5,.25,.125];function cC(e,t,r={}){let n=[...r.steps??M5].sort((g,y)=>y-g),o=ct(r.numerics),a=r.tolPct??.5,s=Et(e),i=e.ggvMode??"twoTrack",c=xr(s,!1,i),l={...o,dsTarget:n[0]??o.dsTarget},u=n.length?ho(s,c,[lt(t,l)],l,i):void 0,m=Fn(s,c.rows),f=n.map((g,y)=>{let R={...o,dsTarget:g},k=Date.now(),v=lt(t,R),x=At(c,v,R,{...u?{load:u}:{},...m?{shifts:m}:{}});return r.onStep?.(y+1,n.length),{dsTarget:g,npts:v.npts,lapTime:x.laptime,ms:Date.now()-k}}),p=f[f.length-1]?.lapTime??NaN,d=f.map(g=>{let y=g.lapTime-p;return{...g,delta:y,deltaPct:p?100*y/p:NaN}}),h=d.filter(g=>Math.abs(g.deltaPct)<=a),b=h.length?Math.max(...h.map(g=>g.dsTarget)):null;return{points:d,reference:p,recommended:b,tolPct:a}}function ms(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:Iy(t.airTempC??r.airTempC),...pc(zm(t.air??r.air))?{air:zm(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:ct(r.numerics)}}async function zp(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 jc(r,t)}}function F5(e,t){let r=structuredClone(e);for(let[n,o]of Object.entries(t))if(!tm(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 Gy=(e,t)=>{let r=e?.name;return typeof r=="string"&&r?r:t};function w5(e,t){let r={};for(let n of Tn){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:Gy(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:Gy(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:Gy(i.model,i.id),byFallback:!0}:null;continue}r[n.doc]=null}return r}function C5(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 lC(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 uC=e=>e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;async function Yp(e,t,r={}){let n=ms(e,r.settings),{entry:o,asset:a}=await zp(e,t),s=Oo(e),i=r.vehicleIds?.length?r.vehicleIds.map(d=>{let h=e.vehicles.find(b=>b.id===d);if(!h)throw new Error(`this project holds no vehicle "${d}"`);return h}):e.vehicles.filter(d=>d.visible);if(!i.length)throw new Error("no vehicle is visible in this project \u2014 name some in vehicleIds");let c=i.map(d=>{let h=r.overrides?.[d.id]?F5(d.params,r.overrides[d.id]):d.params;return Vo(structuredClone(h),s,n)}),l=ac(Ro(e.meta.rulesetId,e.rulesets)),u=uc(c,a,n.numerics,l,{racingLine:n.racingLine,standingStart:n.standingStart,lapCounts:n.lapCounts}),m={};i.forEach((d,h)=>{m[d.id]=u[h]});let{scores:f,field:p}=Dg(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:f!==null,vehicles:i.map((d,h)=>({id:d.id,name:u[h].name||String(d.params.name??d.id),events:C5(u[h]),metrics:Eg(l,u[h],p?.[d.id]),fitted:w5(e,d.params),...f?.[d.id]?{score:{total:f[d.id].total,parts:{...f[d.id].parts}}}:{}})),raw:{results:m,scores:f,field:p}}}async function mC(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=ms(e),{asset:a}=await zp(e,t),s=Vo(structuredClone(n.params),Oo(e),o);return cC(s,a,{...r.steps?{steps:r.steps}:{},numerics:o.numerics,...r.tolPct!==void 0?{tolPct:r.tolPct}:{},...r.onStep?{onStep:r.onStep}:{}})}var T5=(e,t)=>e[t]??[],P5=(e,t,r)=>r<=1?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function Wp(e){return e.kind==="param"?P5(e.start,e.end,Math.max(1,Math.round(e.steps))):e.kind==="part"?[...e.partIds]:[...e.values]}var pC=e=>e.kind==="param"?e.label:e.kind==="part"?`${e.part} model`:e.setting;function L5(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=Vo(structuredClone(r.params),Oo(e),ms(e)),o=hM(n,{geometry:!0}),a=em(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=Tn.find(l=>l.doc===i.part);if(!c)throw new Error(`"${i.part}" is not a library \u2014 it is one of ${Tn.map(l=>l.doc).join(", ")}`);for(let l of i.partIds)if(!T5(e,c.doc).some(u=>u.id===l))throw new Error(`the ${c.label} library holds no "${l}"`)}}let s=t.axes.reduce((i,c)=>i*Wp(c).length,1);if(s>$m)throw new Error(`that grid is ${s} runs, over the ${$m} cap \u2014 a run is a whole session. Drop an axis or use fewer steps.`)}var D5=e=>e.map(t=>String(typeof t=="number"?Number(t.toPrecision(4)):t)).join(" \xD7 ");function E5(e,t){let r=[...new Set(e.flatMap(o=>(o.didNotFinish??[]).map(a=>a.label)))],n=e.map(o=>({name:D5(o.at),events:r.map(a=>({label:a,incomplete:o.didNotFinish?.find(s=>s.label===a)}))}));return lC(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`:uC(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 I5(e){let t=[[]];for(let r of e){let n=Wp(r),o=[];for(let a of n)for(let s of t)o.push([...s,a]);t=o}return t}async function dC(e,t,r,n){L5(e,r);let o=I5(r.axes),a=[],s=!1;for(let[u,m]of o.entries()){let f=structuredClone(e),p=f.vehicles.find(k=>k.id===r.vehicleId),d={...r.settings},h={};r.axes.forEach((k,v)=>{let x=m[v];if(k.kind==="param")h[k.label]=x;else if(k.kind==="part"){let M=Tn.find(A=>A.doc===k.part);p.params[M.ref]=x}else d[k.setting]=x});let b=r.fleet?f.vehicles.filter(k=>k.visible||k.id===r.vehicleId).map(k=>k.id):[r.vehicleId],g=await Yp(f,t,{vehicleIds:b,settings:d,...Object.keys(h).length?{overrides:{[r.vehicleId]:h}}:{}});s=g.fleetScored;let y=g.vehicles.find(k=>k.id===r.vehicleId),R=y.events.flatMap(k=>k.incomplete?[{label:k.label,...k.incomplete}]:[]);a.push({at:m,metrics:y.metrics,...R.length?{didNotFinish:R}:{}}),n?.(u+1,o.length)}let i=Object.keys(a[0]?.metrics??{}),c=[];r.axes.forEach((u,m)=>{if(Wp(u).length<2)return;i.some(p=>{if(new Set(a.map(b=>`${b.at[m]}`)).size<2)return!1;let h=a.map(b=>b.metrics[p]).filter(Number.isFinite);return Math.max(...h)-Math.min(...h)>1e-9})||c.push(pC(u))});let l=[];return s&&!r.fleet&&l.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."),l.push(...E5(a,s)),c.length&&l.push(`Nothing moved along ${c.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(u=>({kind:u.kind,label:pC(u),values:Wp(u)})),runs:a,metricKeys:i,fleetScored:s,flat:c,caveats:l}}var uhe=Math.PI/180;var jp=.5,U5=new Set(["lap","session"]);function X5(e){return et({...e,label:e.label.replace(/ [xyz]$/,"")})}function hC(e){let t=Lo(e);if(t)return[t.point];let r=Xt(e);if(r)return[r.point];let n=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(n){let a=Vt[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]}.${Ar.fore}`,`hp.${o[1]}.${Ar.aft}`]:[]}function bC(e,t){let r=mt(e,t),n=xt(e),o=new Map;for(let a of[...r.variables,...r.followers??[]])for(let s of hC(a.id)){if(o.has(s))continue;let i=ns.map(c=>`${s}.${c}`).filter(c=>n[c]&&!n[c].supersededBy);i.length&&o.set(s,{id:s,name:X5(n[i[0]]),coords:i})}return[...o.values()]}function Ky(e,t,r,n={},o=jp){let a=mt(e,t),s=(n.metrics??nr()).byId,i=us(e,a,r),c=bC(e,a),l=xt(i),u=[];a.objectives.forEach((S,F)=>{let C=s[S.metricId];C&&u.push({key:S.key??`target:${F}`,role:"target",metric:C,at:S.at})}),a.constraints.forEach((S,F)=>{let C=s[S.metricId];C&&u.push({key:S.key??`hold:${F}`,role:"hold",metric:C,at:S.at,hold:S})}),(a.watches??[]).forEach((S,F)=>{let C=s[S.metricId];C&&u.push({key:S.key??`watch:${F}`,role:"watch",metric:C,at:S.at})});let m=u.filter(S=>!U5.has(S.metric.cost)),f=S=>{let F=$p(S,a,n),C=m.map(L=>ut(F,L.metric,L.at));return F.failure?null:C},p=f(i)??m.map(()=>NaN),d=[],h=[],b=[],g=1,y=[...p],R=[...p],k=S=>S.forEach((F,C)=>{Number.isFinite(F)&&(F>=y[C]||(y[C]=F),F<=R[C]||(R[C]=F))}),v=S=>{g++;try{return f(S())}catch{return null}};for(let S of c)for(let F of S.coords){let C=l[F],L=C.read(i),E=F.slice(F.lastIndexOf(".")+1),D=v(()=>C.write(i,L+o)),O=v(()=>C.write(i,L-o));if(!D||!O){b.push(`${S.name} ${E}`);continue}d.push({id:F,def:C,now:L,point:S,axis:E}),h.push([D,O]),k(D),k(O)}let x=new Map,M=S=>{let F=S.join("");if(x.has(F))return;let C=v(()=>d.reduce((L,E,D)=>E.def.write(L,E.now+S[D]*o),i));x.set(F,C),C&&k(C)};d.length>1&&m.forEach((S,F)=>{let C=h.map(([L,E])=>L[F]-p[F]>=E[F]-p[F]?1:-1);Number.isFinite(p[F])&&(M(C),M(C.map(L=>-L)))});let A=[...x.values()].filter(S=>!S).length;A&&b.push(`${A} of ${x.size} corners`);let w=u.map(S=>{let F={key:S.key,role:S.role,name:je(S.metric)+_o(S.at,S.metric,a),unit:S.metric.unit==="-"?"":S.metric.unit,...S.hold?{limit:{op:S.hold.op,limit:S.hold.limit,...S.hold.limit2!==void 0?{limit2:S.hold.limit2}:{}}}:{}},C=m.indexOf(S);if(C<0)return{...F,value:NaN,lo:NaN,hi:NaN,skipped:"read off a lap"};let L=p[C],E=Number.isFinite(L)?y[C]:NaN,D=Number.isFinite(L)?R[C]:NaN,O=h.map(([N,B])=>Math.max(Math.abs(N[C]-L),Math.abs(B[C]-L))),_=O.filter(Number.isFinite).reduce((N,B)=>N+B,0),z;if(_>0){let N=O.indexOf(Math.max(...O.filter(Number.isFinite)));z={point:d[N].point.name,axis:d[N].axis,share:O[N]/_}}let I=S.hold?Math.max(_n(S.hold,E),_n(S.hold,D)):void 0;return{...F,value:L,lo:E,hi:D,...z?{most:z}:{},...I!==void 0?{excess:I}:{}}}),T=new Set(c.flatMap(S=>S.coords)),P=a.variables.filter(S=>!hC(S.id).length&&!T.has(S.id)).length;return{mm:o,points:c,rows:w,evaluations:g,unsolved:b,settings:P}}function Hy(e){if(!e.chassis)return e;let{chassis:t,...r}=e;return t.boxes.length?{...r,chassis:{boxes:t.boxes}}:r}var Gye=180/Math.PI;var PB={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:xo,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 fRe=PB.id;var Uc=.02;function TC(e){let t=Math.max(Uc,Math.abs(e.heaveMotionRatio)),r=Math.max(Uc,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 DB=(e,t)=>({od:t,id:Math.min(e.id,t-.5)}),EB=(e,t)=>e/(2*t*t);function CC(e,t){switch(e.kind){case"ubar":case"blade":case"torsionTube":return{...e,section:DB(e.section,t)};default:return e}}function PC(e,t,r){let n=Math.max(Uc,Math.abs(r));if(e?.kind==="coil"){let l=EB(t,n),u=e.rate;if(typeof u=="number")return{...e,rate:l};let m=jr(u,0);if(!(m>0))return{...e,rate:l};let f=l/m;return{...e,rate:{...u,y:u.y.map(p=>p*f)}}}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=>Pi(CC(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 CC(a,c)}function LC(e,t,r,n){let o=e?.design,a=PC(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 IB=Math.PI/180,Up=1e-6;function _B(e){return!(Me(e.rockerPivotA,e.rockerPivotB)<Up||Me(e.rockerToPushrod,e.rockerPivotA)<Up||Me(e.rockerToDamper,e.rockerPivotA)<Up||Me(e.rockerToDamper,e.damperChassis)<Up)}function _C(e){if(!_B(e.hardpoints))return!1;let t={...e,config:{...e.config,actuation:"rocker"}};try{let r=rt(t);for(let n of[-20,-1,0,1,20]){let o=ge(r,n,0);if(!o.ok||!Number.isFinite(o.state.metrics.damperLength))return!1}return!0}catch{return!1}}function NC(e){if(e.config.actuation!=="direct"||_C(e))return;let{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}=OB(e);return{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}}var DC=40;function Xp(e,t={}){let r=e.hardpoints,n=r.pushrodOuter,o=r.damperChassis,a=Me(n,o),s=te(n,U(K(o,n),NB)),i=t.armRod??Math.max(25,.15*a),c=t.armDamper??i,l=[s[0]-DC,s[1],s[2]],u=[s[0]+DC,s[1],s[2]],m=q(K(u,l)),f=K(n,s),p=q(K(f,U(m,EC(f,m)))),d=Gt(p,m,(t.armAngleDeg??60)*IB),h=te(s,U(d,i)),b=K(o,s),g=q(K(b,U(m,EC(b,m)))),y=U(q(oe(m,g)),t.damperSide??1),R=te(s,U(y,c));return{...r,rockerPivotA:l,rockerPivotB:u,rockerToPushrod:h,rockerToDamper:R}}var NB=.72,EC=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function IC(e){let t=ze(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 OB(e,t={}){let r=t.target??IC(e),n=t.armAngleDeg,o=Xp(e,{armAngleDeg:n});if(!(r>0))return o;let a=Me(e.hardpoints.pushrodOuter,e.hardpoints.damperChassis),s=Math.max(25,.15*a),i=(()=>{for(let p of[1,-1]){let d=Xp(e,{armRod:s,armAngleDeg:n,damperSide:p}),h={...e,config:{...e.config,actuation:"rocker"},hardpoints:d};try{let b=rt(h),g=ge(b,15,0),y=ge(b,-15,0);if(g.ok&&y.ok&&g.state.metrics.damperLength<y.state.metrics.damperLength)return p}catch{}}return 1})(),c=(p,d)=>{try{return IC({...e,config:{...e.config,actuation:"rocker"},hardpoints:Xp(e,{armRod:p,armAngleDeg:n,armDamper:d,damperSide:i})})}catch{return Number.NaN}},l=[1,.6,.35,.2,1.7,2.6].map(p=>Math.max(12,s*p)),u=s,m=s,f=1/0;for(let p of l){let d=.25*p,h=6*p,b=p;for(let y=0;y<24;y++){let R=(d+h)/2,k=c(p,R);if(!Number.isFinite(k))break;b=R,k<r?d=R:h=R}let g=Math.abs(c(p,b)-r);if(Number.isFinite(g)&&g<f&&(f=g,u=p,m=b),f<1e-4*Math.max(1,r))break}return Xp(e,{armRod:u,armAngleDeg:n,armDamper:m,damperSide:i})}var CRe=Array.from({length:19},(e,t)=>-45+5*t);var TRe=Math.PI/180;function VB(e){let t=e.hardpoints,r=q(K(t.rockerPivotB,t.rockerPivotA)),n=un(t.rockerToDamper,t.rockerPivotA,r),o=.6*ln(K(t.rockerToDamper,n)),a=oe(r,jx),s=ln(a)>1e-6?q(a):q(K(t.rockerToDamper,n));return{outer:te(n,U(s,o)),inner:te(n,U(s,-o)),attach:"rocker"}}var BB=(e,t)=>({...e,config:{...e.config,actuation:t}});function Wy(e,t,r,n){let o=r==="front"?e.front:e.rear,a=Hu(o),s=o.config.springRate*a*a,i=Q(t,r==="front"?"damper_front":"damper_rear")*a*a,c=r==="front"?t.arbFrontDesign:t.arbRearDesign,l=io(e,t)[r]??Q(t,r==="front"?"arb_front":"arb_rear"),u=Ea(e,t)[r]??Q(t,r==="front"?"heave_spring_front":"heave_spring_rear"),m=NC(o),f=BB(m?{...o,hardpoints:{...o.hardpoints,...m}}:o,"decoupled"),p=r==="front"?t.heaveFrontDesign:t.heaveRearDesign,d=n?.heave??OC(p?.linkage,w=>Kn(f,w).atDesign)??mf(f,"rockerToRocker"),h=!c||c.design.kind==="none"||c.design.kind==="coil",b=h?"coil":"ubar",g=c?.linkage&&(c.design.kind==="none"||c.linkage.attach!=="rocker")?c.linkage:void 0,y=n?.roll??OC(h?g:c?.linkage,w=>aa(f,w,{kind:b}).atDesign)??(h?VB(f):_k(f)),R=Kn(f,d).atDesign,k=aa(f,y,{kind:b}).atDesign,v=Yu(e,t),x=TC({cornerWheelRate:s,cornerDamper:i,arbWheelRate:l,heaveWheelRate:u,heaveWheelDamping:r==="front"?v.heaveFront:v.heaveRear,rollWheelDamping:r==="front"?v.rollFront:v.rollRear,heaveMotionRatio:R,rollMotionRatio:k}),M=!c||c.design.kind==="none"?{design:{kind:"coil",rate:1},linkage:y}:{...c,linkage:y},A=LC({design:p?.design??{kind:"none"},linkage:d,damper:p?.damper},M,x,k);return m?{...A,crank:m}:A}function OC(e,t){return e&&Math.abs(t(e))>=Uc?e:void 0}var qp=[{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"]}],jy=()=>({arbFront:void 0,arbRear:void 0,heaveFront:void 0,heaveRear:void 0}),$B={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]}},GB={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]}},KB=()=>({outer:[0,189,486],attach:"rocker",mount:{kind:"chassis",anchor:[-225,0,486]}}),HB={rate:60,motionRatio:1},zB={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]}},YB=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]}},WB={kind:"coil",rate:1560,motionRatio:1,gap:0,bothWays:!0},jB=40,UB={rockerPivotA:[50,130,440],rockerPivotB:[-50,130,440],rockerToPushrod:[10,170,460],rockerToDamper:[-20,64,440],damperChassis:[-20,64,215]},VC=()=>({outer:[-50,130,480],attach:"rocker",shaftStation:-50}),BC=()=>({outer:[50,130,400],inner:[50,130,480],attach:"rocker",shaftStationOuter:50,shaftStationInner:50}),XB=e=>[e[0],e[1],e[2]];function qB(e){let t=r=>({...r,hardpoints:{...r.hardpoints,...GC(UB)},config:{...r.config,actuation:"decoupled"}});return{...e,front:t(e.front),rear:t(e.rear)}}function GC(e){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,XB(r)]))}function KC(e,t=Ao(),r=e==="pull"?GB:$B){let n=(o,a)=>({...o,hardpoints:{...o.hardpoints,...GC(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 Qp(e,t){let r=Uy(e),n=ps(e);if(e==="heave")return{meta:r,vehicle:n,components:{...jy(),heaveFront:{design:{...wb,...HB},linkage:KB()}}};if(e!=="decoupled")return{meta:r,vehicle:n,components:jy()};let o=Wy(n,t,"front",{heave:VC(),roll:BC()}),a=Wy(n,t,"rear",{heave:VC(),roll:BC()});return{meta:r,vehicle:n,components:{arbFront:o.arb,arbRear:a.arb,heaveFront:o.heave,heaveRear:a.heave}}}function ps(e){let{name:t}=Uy(e);if(e==="direct")return{...fc(),name:t};if(e==="mcpherson"){let n=hc(),o=Wm();return{...n,front:{...o,config:{...o.config,loadedRadius:n.front.config.loadedRadius}},name:t}}let r=QB(KC(e==="pullrod"?"pull":"push"));return{...e==="decoupled"?qB(r):r,name:t}}var $C={front:221.7,rear:220.9};function QB(e){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:$C.front}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:$C.rear}}}}function Uy(e){let t=qp.find(r=>r.id===e);if(!t)throw new Error(`Unknown suspension template: ${e}`);return t}function Zp(){let e=t=>({design:{...WB},linkage:YB(t),damper:jB});return{meta:Uy("heave"),vehicle:KC("push",$g(),zB),components:{...jy(),heaveFront:e("front"),heaveRear:e("rear")}}}var HC=[10,25,50,100,200,300],ZB=[{id:"c1",label:"Soft",scale:.7},{id:"c2",label:"Medium",scale:1},{id:"c3",label:"Firm",scale:1.4}],zC=e=>Math.round(e*100)/100;function JB(e,t,r){let n=HC.map(o=>zC(r*o));return{id:e,label:t,speedMmS:[...HC],bumpN:n,reboundN:[...n]}}function e$(e){return{name:e.name,body:{...e.body},curves:ZB.map(t=>JB(t.id,t.label,zC(e.coefficient*t.scale)))}}function Xc(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 Fr(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:vc[e.dampers.length%vc.length],model:e$(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 pt=e=>`${e} (typical)`,Xy={car:{name:pt("Formula Student damper"),coefficient:2.5,body:{extended:249,stroke:55}}},Jp={car:Xy.car,heave:{name:pt("Formula Student heave damper"),coefficient:3.4,body:{extended:270,stroke:47}},roll:{name:pt("Formula Student roll damper"),coefficient:3.7,body:{extended:322,stroke:100}}},ed={car:{name:pt("Formula 1 damper"),coefficient:6,body:{extended:240,stroke:40}},heave:{name:pt("Formula 1 heave damper"),coefficient:40,body:{extended:240,stroke:40}}},YC={car:{name:pt("GT damper"),coefficient:4.5,body:{extended:510,stroke:80}}},qy={car:{name:pt("Sports car damper"),coefficient:2.4,body:{extended:515,stroke:110}}},WC={car:{name:pt("Sports car strut"),coefficient:2.4,body:{extended:310,stroke:120}},rear:qy.car},jC={car:{name:pt("Cup car strut"),coefficient:4,body:{extended:285,stroke:75}},rear:{name:pt("Cup car rear damper"),coefficient:3.5,body:{extended:505,stroke:80}}},UC={car:{name:pt("Stock car front damper"),coefficient:7.5,body:{extended:555,stroke:110}},rear:{name:pt("Stock car rear damper"),coefficient:6.75,body:{extended:555,stroke:110}}},XC={car:{name:pt("Hill-climb front damper"),coefficient:3,body:{extended:285,stroke:65}},rear:{name:pt("Hill-climb rear damper"),coefficient:3.5,body:{extended:285,stroke:65}}},qC={car:{name:pt("Race truck front damper"),coefficient:12,body:{extended:780,stroke:160}},rear:{name:pt("Race truck rear damper"),coefficient:8.5,body:{extended:780,stroke:160}}};function fs(e){return e.vehicles=e.vehicles.slice(0,1),e.activeVehicleId=e.vehicles[0]?.id??null,e}function Nn(e,t){let r=kc(e);return r.meta.rulesetId=t,r}function Bo(e,t,r,n){let o=Nn(e,t);return o.suspensions=[{...o.suspensions[0],model:n()}],o.vehicles=[p0(r,"v1",0)],o.activeVehicleId="v1",o}var[,t$,r$,n$,o$,a$,s$,i$]=Ug;function Qy(e,t){delete e.arbFrontDesign,delete e.arbRearDesign,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 QC(){return{...ps("decoupled"),name:Ao().name}}var c$=[{label:"Formula Student (decoupled)",vehicle:QC,components:e=>Xc(Qp("decoupled",e).components,Jp)},{label:"Formula 1 (third springs)",vehicle:()=>Zp().vehicle,components:()=>Xc(Zp().components,ed)}],Zy={"direct-coilover":"direct",pushrod:"pushrod",pullrod:"pullrod","third-spring":"heave","mcpherson-strut":"mcpherson"},l$=[...c$.map(e=>e.vehicle),...Object.values(Zy).map(e=>()=>ps(e))];function ds(e){let t=Xc(Qp("decoupled",e.vehicles[0].params).components,Jp);e.suspensions=[{...e.suspensions[0],model:QC()}];for(let r of e.vehicles)Qy(r.params,t);return Fr(e,Jp),e}var $o={title:"OpenStreetMap",url:"https://www.openstreetmap.org/copyright",licence:"ODbL-1.0",credit:"\xA9 OpenStreetMap contributors"},td={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"},ZC={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]"},JC={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"},u$={id:"cota",name:"Circuit of the Americas, Austin",address:"e0c6ea889d708cf15f9c",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[$o,td,JC]}},m$={id:"laguna-seca",name:"Laguna Seca, Monterey",address:"185b5811b9c423ef44ef",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[$o,td,JC]}},p$={id:"nordschleife",name:"Nordschleife, N\xFCrburg",address:"74c49603c7b2f15985c6",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[$o,ZC]}},d$={id:"brands-hatch",name:"Brands Hatch, Kent",address:"c4953e3c25eaba4a5b7e",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[$o,{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."}]}},f$={id:"bristol",name:"Bristol, Tennessee",address:"f0e23953669a414ad600",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[$o,td]}},h$={id:"pikes-peak",name:"Pikes Peak, Colorado",address:"3de137fe33b5c2875036",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[$o,td]},standingStart:!0},b$={source:"venue",altitudeM:3580,pressure:{kind:"standard"},humidityPct:0},g$=10,y$={id:"nurburg-sprint",name:"Sprintstrecke, N\xFCrburg",address:"1875636cdbb615aa2756",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[$o,ZC]}};function Go(e,t){let{id:r,name:n,address:o,provenance:a,standingStart:s}=t,i={kind:"catalogue",id:r,address:o},c=bc(o0({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 On(e,t,r){let n=e.vehicles[0].params,o=`m${e.motors.length+1}`;e.motors=[...e.motors,{id:o,color:Pn[e.motors.length%Pn.length],model:t}];let a=rM({},{...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 x$=3.8,rd={hubPlanetary:14.5,inboardChain:4,engineChain:3.4},R$="Hub motor, 35 kW (example)";function Jy(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 eT(e){let t=e.motors.find(r=>r.id==="m1");return t.model={...t.model,name:R$},t.id}function nd(e,t,r){let n=fs(ds(Nn(e,r)));return n.vehicles[0].params.name=t,n}function v$(){let e=nd("Formula Student combustion car","Formula Student combustion","fs-cv");On(e,Jg(),rd.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 k$(){let e=nd("Formula Student AWD car","Formula Student AWD","fs-ev");return Jy(e,eT(e),4,"awd",rd.hubPlanetary,"hub"),e}function M$(){let e=nd("Formula Student RWD hub-motor car","Formula Student RWD hub motors","fs-ev");return Jy(e,eT(e),2,"rear",rd.hubPlanetary,"hub"),e}function S$(){let e=nd("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:Pn[e.motors.length%Pn.length],model:Zg()}],Jy(e,t,1,"rear",rd.inboardChain),e.vehicles[0].params.driveline={rear:structuredClone(St.clutch)},e}function A$(){let e=fs(ds(Nn("Formula Student endurance energy","fs-ev"))),t=e.vehicles[0],r=structuredClone(t);if(r.id="v2",r.color=Rc[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 F$(){let e=Zp(),t=Bo("Formula 1 car","trackday",t$,()=>e.vehicle);return Qy(t.vehicles[0].params,Xc(e.components,ed)),Fr(t,ed),On(t,e0(),x$),Go(t,u$)}function tT(e="GT car",t=fc){let r=Bo(e,"trackday",r$,t);return Fr(r,YC),On(r,PA(),r.vehicles[0].params.gear_ratio.value),Go(r,m$)}function rT(e="Sports car",t=hc,r=qy){let n=Bo(e,"trackday",n$,t);return Fr(n,r),On(n,LA(),n.vehicles[0].params.gear_ratio.value),Go(n,p$)}function w$(){let e=Bo("Cup car","trackday",o$,yA);return Fr(e,jC),On(e,DA(),e.vehicles[0].params.gear_ratio.value),Go(e,d$)}function C$(){let e=Bo("Stock car","trackday",a$,xA);return Fr(e,UC),On(e,EA(),e.vehicles[0].params.gear_ratio.value),Go(e,f$)}function T$(){let e=Bo("Hill-climb prototype","trackday",s$,RA);return Fr(e,XC),On(e,IA(),e.vehicles[0].params.gear_ratio.value),e.settings.air=structuredClone(b$),e.settings.airTempC=g$,Go(e,h$)}function P$(){let e=Bo("Race truck","trackday",i$,vA);return Fr(e,qC),On(e,_A(),e.vehicles[0].params.gear_ratio.value),Go(e,y$)}function L$(e){let t=qp.find(o=>o.id===e);if(e==="direct")return tT(t.name,()=>ps(e));if(e==="mcpherson")return rT(t.name,()=>ps(e),WC);let r=fs(Nn(t.name,"trackday")),n=Qp(e,r.vehicles[0].params);return r.suspensions=[{...r.suspensions[0],model:n.vehicle}],Qy(r.vehicles[0].params,n.components),Fr(r,Xy),r}function qc(e,t,r){let n=Zy[e],o=qp.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:()=>L$(n)}}var D$=[{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:()=>ds(Nn("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:A$},{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:()=>fs(ds(Nn("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:v$},{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:k$},{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:M$},{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:S$},{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:F$},{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:tT},{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:rT},{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:w$},{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:C$},{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:T$},{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:P$},{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:()=>fs(ds(Nn("Suspension study","trackday")))},qc("direct-coilover","The GT car\u2019s wishbones driving coilovers straight into the towers, at Laguna Seca.","On the GT car, at Laguna Seca."),qc("pushrod","The FS car on pushrods: a rod from each lower wishbone works a rocker.","On the Formula Student car, at FSG."),qc("pullrod","The FS car on pullrods: a rod from each upper wishbone pulls a low rocker.","On the Formula Student car, at FSG."),qc("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."),qc("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:()=>fs(ds(Nn("Tyre study","fs-ev")))}],nT=D$.map(e=>({...e,load:()=>d0(e.load())}));var oT={width:320,height:200},dve=[.6*oT.width-9,.6*oT.height-9];var aT=new WeakMap,sT=new WeakMap,ex=e=>JSON.stringify(e,(t,r)=>r===1/0?"Infinity":r);function iT(e,t){if(!t){let a=aT.get(e);return a||(a=_t(e),aT.set(e,a)),a}let r=sT.get(e);r||(r=new Map,sT.set(e,r));let n=ex(t),o=r.get(n);return o||(r.size>=4&&r.clear(),o=_t(e,t),r.set(n,o)),o}var _$=Math.PI/180,N$=e=>e>1?e/100:e;function Qc(e){let t=null;return()=>(t??={v:e()}).v}function cT(e){let t=ze(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 lT=new WeakMap,tx={heave:0,pitch:0,roll:0,steer:0},uT=[0,1,2,3,4],mT=[-20,-10,0,10,20];function dT(e,t){let r=Ur(e,tx),n=["front","rear"],o=c=>{let l=Di(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 uT){let l=c===0?null:Ur(e,{...tx,roll:c*_$});n.forEach((u,m)=>{let f=l?Di(l[u]):null,p=f&&Number.isFinite(a[m]);s[m].rc.push(p?t[m]+(f.left+f.right)/2-a[m]:t[m]),s[m].split.push(p?(f.left-f.right)/2:0)})}let i=n.map(()=>[]);for(let c of mT){let l=c===0?null:Ur(e,{...tx,heave:-c});n.forEach((u,m)=>{let f=l&&l[u].valid&&r[u].valid;i[m].push(f?t[m]+l[u].height-r[u].height:t[m])})}return{roll:{rollDeg:uT,rcFront:s[0].rc,rcRear:s[1].rc,rcSplitFront:s[0].split,rcSplitRear:s[1].split},heave:{drop:mT,rcFront:i[0],rcRear:i[1]}}}var pT=new WeakMap;function O$(e,t,r,n){let o=pT.get(e);o||(o=new Map,pT.set(e,o));let a=`${ex(r)}|${n[0]}|${n[1]}`,s=o.get(a);if(!s){o.size>=4&&o.clear();try{s=dT(iT(e,r),n)}catch{s=t.rigidMigration(n)}o.set(a,s)}return s}function V$(e){let t=lT.get(e);if(t)return t;let r=_t(e),n=Ur(r,{heave:0,pitch:0,roll:0,steer:0}),o=cT(e.front),a=cT(e.rear),s={wheelbase:e.config.wheelbase,trackFront:Rt(e.front),trackRear:Rt(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:Da(n.front),rcGainRear:Da(n.rear),rigidMigration:i=>dT(r,i),kinFront:Qc(()=>ba(e.front)),kinRear:Qc(()=>ba(e.rear))};return lT.set(e,s),s}function fT(e,t,r,n){let o=V$(e),a=io(e,t),s=Ea(e,t),i=Xk(e,t),c=Yu(e,t),l=qk(e,t),u=Qk(t),m=Wu(e,t),f=so(e.front),p=so(e.rear),d=ao(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,Q(t,"cop_long"))),copHeight:Q(t,"cop_height"),...t.aeroModel?{model:t.aeroModel}:{},rideHeightFront:Q(t,"ride_height_front"),rideHeightRear:Q(t,"ride_height_rear")},b=9.81,g=N$(t.front_mass_diss.value),y=_a(t,r,n),R=Pe(y.front),k=y.rear===y.front?R:Pe(y.rear),v=n??t.tireModelRear??r,x=t.m.value*b*g/2,M=t.m.value*b*(1-g)/2,A=R.corneringStiffness(x),w=k.corneringStiffness(M),T=(r?R.verticalStiffness():0)||Q(t,"tire_vertical_rate"),P=(v?k.verticalStiffness():0)||Q(t,"tire_vertical_rate"),S=pr(r)??0,F=pr(v)??0,C=Qu({freeRadius:S,staticLoad:x,tyreRate:T,surveyed:e.front.config.loadedRadius},{freeRadius:F,staticLoad:M,tyreRate:P,surveyed:e.rear.config.loadedRadius},g),L=jt(S,x,T,e.front.config.loadedRadius),E=jt(F,M,P,e.rear.config.loadedRadius),D=[Xr(o.rcHeightFront,o.rcGainFront,e.front.config.loadedRadius,L),Xr(o.rcHeightRear,o.rcGainRear,e.rear.config.loadedRadius,E)],O=Qc(()=>Oi(o.kinFront(),Q(t,"camber_front_deg"))),_=Qc(()=>Oi(o.kinRear(),Q(t,"camber_rear_deg"))),z=Qc(()=>O$(e,o,rs(B),D)),I=pi({...t,wheelbase:{...t.wheelbase,value:o.wheelbase}}),N=Ni(t),B={massTotal:t.m.value,frontMassFrac:g,steeringSystem:t.steeringSystem,tv:Lu(t),cgHeight:Ia(Q(t,"cg_height"),t.cgReference?.standingRadius,C),cgStandingRadius:C,wheelbase:o.wheelbase,trackFront:o.trackFront,trackRear:o.trackRear,wheelRateFront:f?0:o.wheelRateFront,wheelRateRear:p?0:o.wheelRateRear,decoupledFront:f,decoupledRear:p,...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&&!f?{heaveSeatFront:i.front}:{},...i.rear&&!p?{heaveSeatRear:i.rear}:{},...m.rollFront.coilover?{rollCoiloverFront:m.rollFront.coilover}:{},...m.rollRear.coilover?{rollCoiloverRear:m.rollRear.coilover}:{},tireRate:T,...P!==T?{tireRateRear:P}:{},tireDamping:Q(t,"tire_vertical_damping"),arbFront:a.front??Q(t,"arb_front"),arbRear:a.rear??Q(t,"arb_rear"),brakeBalanceFront:I.balanceFront,brakes:I,...N?{driveline:N}:{},heaveSpringFront:s.front??Q(t,"heave_spring_front"),heaveSpringRear:s.rear??Q(t,"heave_spring_rear"),unsprungPerCorner:Q(t,"unsprung_mass"),unsprungCgHeight:jt(S,x,T,o.unsprungCgHeight),tyreFreeRadius:S,...F!==S?{tyreFreeRadiusRear:F}:{},rcHeightFront:D[0],rcHeightRear:D[1],corneringStiffnessFront:A,corneringStiffnessRear:w,get kinFront(){return O()},get kinRear(){return _()},damperFront:f?0:d?.front?.rate??Q(t,"damper_front")*o.mrFront*o.mrFront,damperRear:p?0:d?.rear?.rate??Q(t,"damper_rear")*o.mrRear*o.mrRear,...d?.front&&!f?{damperCurveFront:d.front.curve}:{},...d?.rear&&!p?{damperCurveRear:d.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:Q(t,"unsprung_mass"),get rollCentreCurve(){return z().roll},get rcHeaveCurve(){return z().heave},aero:h,yawInertia:Q(t,"I_yaw"),rollInertia:Q(t,"I_roll"),pitchInertia:Q(t,"I_pitch"),get steerFront(){return ju(e.front,L)},ackermannPct:Q(t,"ackermann_pct"),toeFrontDeg:Q(t,"toe_front_deg"),toeRearDeg:Q(t,"toe_rear_deg")};return B}var bT=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}),nx={ggvMode:"twoTrack"},hT=new WeakMap;function ox(e,t=nx){let r=hT.get(e.vehicle);r||hT.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={...bT(e.params),suspensionOf:()=>e.vehicle};n.set(o,a=Vo(e.params,s,t))}return a}var gT=(e=nx)=>t=>ox(t,e),yT=(e=nx)=>t=>fT(t.vehicle,$y(t.params,bT(t.params),e),t.params.tireModel,t.params.tireModelRear);function B$(e,t){return ox(e,t.switches)}var ax=e=>nr(e?.rulesets);function xT(e,t,r,n,o={},a=()=>r.standingStart){let s=ox(n,r.switches),i=(l,u)=>{let m=Bm(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 RT=e=>[...new Set(e.lap.courses.flatMap(t=>t.course.kind==="track"?[t.course.trackId]:[]))],vT=e=>{let t=e?.session;return t?{sessionParams:r=>B$(r,t),session:()=>t}:{}},Jc=e=>({metrics:ax(e),assemble:yT(e?.switches),simParams:gT(e?.switches),projectTrack:()=>e?.course??null,libraryTrack:t=>e?.tracks?.[t]??null,numerics:e?.numerics,...vT(e)}),$$=(e,t)=>({density:e.density,envelope:e.envelope,states:e.states,operating:e.operating,lap:e.lap,assemble:yT(t?.switches),simParams:gT(t?.switches),projectTrack:()=>t?.course??null,libraryTrack:r=>t?.tracks?.[r]??null,numerics:t?.numerics,...vT(t)}),kT="nelder-mead",MT=600,Zc=[0,.15,.15];function ST(e,t,r,n=Zc.length){let o=cx(t);return Zc.slice(0,Math.max(1,n)).map((a,s)=>({...e,seed:s+1,startJitter:a,car:o,...r?{lap:r}:{}}))}function AT(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 FT(e,t,r,n,o=.01){let a=ax(n).byId;return G$(e,t,r,n).filter(s=>s.excess>-o*(a[s.metricId]?.scale??1))}function G$(e,t,r,n){let o;try{o=Dn(us(e,t,r),$$(t,n))}catch{return[]}return K$(o,t,ax(n))}function K$(e,t,r){let n=[];for(let o of t.constraints){let a=r.byId[o.metricId];if(!a)continue;let s=ut(e,a,o.at);if(!Number.isFinite(s))continue;let i=`${je(a)}${_o(o.at,a)}`;n.push({key:o.key,metricId:o.metricId,label:i,unit:a.unit==="-"?"":a.unit,value:s,excess:_n(o,s)})}return n}var H$=.05;function z$(e,t){if(t.id.startsWith("hp.")||Op(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 gy(In(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 fy(nn(o.hardpoints,n[2]),n[3],1)}function wT(e,t,r){let n=r.filter(f=>f.score.feasible);if(n.length<2)return null;let o=t.map(f=>z$(e,f)),a=o.every(f=>f!==null)?"mm":null,s=0,i="",c=0,l=n.reduce((f,p)=>p.score.total<f.score.total?p:f);for(let f of n)if(f!==l)for(let p=0;p<t.length;p++){let d=Math.abs(f.x[p]-l.x[p])*(o[p]??1);c+=d*d,d>s&&(s=d,i=t[p].name)}let u=n.map(f=>f.score.total),m=l.score.terms.reduce((f,p)=>f+(p.resolution??0),0);return{distance:Math.sqrt(c),worst:s,worstName:i,scoreSpread:Math.max(...u)-Math.min(...u),tolerance:Math.max(H$,m),unit:a}}var Y$={steeringSystem:!0,brakeSetup:!0,driveline:!0,heaveFrontDesign:!0,heaveRearDesign:!0,arbFrontDesign:!0,arbRearDesign:!0},CT=e=>Object.hasOwn(Y$,e);function rx(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`:null:null}function W$(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":CT(t)||rx(e)?"block":null}function sx(e,t){t=mt(e,t);let r=xt(e);return[...t.variables,...t.followers??[]].filter(n=>r[n.id]&&!r[n.id].supersededBy&&!W$(n.id)).map(n=>et(r[n.id]))}function TT(e,t,r){t=mt(e,t);let n=xt(e),o=us(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,f,p,d]=c.id.split(".");if(m==="rocker"){let h=`${f}.rocker`;if(i.has(h))continue;i.add(h);let b=f==="front"?o.vehicle.front:o.vehicle.rear;for(let g of[Ar.fore,Ar.aft]){let y=b.hardpoints[g];for(let R=0;R<3;R++)a.push({kind:"hardpoint",axle:f,key:g,axis:R,value:y[R]})}}else if(m==="arm"){let h=`${f}.${p}`;if(i.has(h))continue;i.add(h);let b=f==="front"?o.vehicle.front:o.vehicle.rear,g=Vt[p];for(let y of[g.fore,g.aft]){let R=b.hardpoints[y];for(let k=0;k<3;k++)a.push({kind:"hardpoint",axle:f,key:y,axis:k,value:R[k]})}}else if(m==="hp"&&Xt(c.id)){let h=`${f}.${p}`;if(i.has(h))continue;i.add(h);let b=(f==="front"?o.vehicle.front:o.vehicle.rear).hardpoints[p];for(let g=0;g<3;g++)a.push({kind:"hardpoint",axle:f,key:p,axis:g,value:b[g]})}else if(m==="hp")a.push({kind:"hardpoint",axle:f,key:p,axis:"xyz".indexOf(d),value:u});else if(m==="cfg")a.push({kind:"config",axle:f,field:p,value:u});else if(m==="kc"){if(s.has(`kc.${f}`))continue;s.add(`kc.${f}`);let h=f==="front"?o.vehicle.front:o.vehicle.rear;a.push({kind:"compliance",axle:f,value:h.compliance})}else if(m==="param")a.push({kind:"param",label:et(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(CT(m)||rx(c.id)){let h=rx(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 ix(e){let t=performance.now(),r=Jc(e.lap),n=e.follow?Cy(e.car,e.spec,r):e.spec,{dead:o,unprobed:a,...s}=Dy(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 PT(e){let t=performance.now();return{tolerance:Ky(e.car,e.spec,e.x,Jc(e.lap),e.mm),elapsedMs:performance.now()-t}}var cx=e=>e.vehicle.chassis?{...e,vehicle:Hy(e.vehicle)}:e;function LT(e,t){try{let r=lx(e.car,e.spec,e.lap),n=xa.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:Nr(r.variables),score:_r(r,Nr(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&&vy(r.variables)?My(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 lx=(e,t,r)=>Gp(e,t,Jc(r));function DT(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),...Fi(e,t.damper)}}function ET(e,t,r){let{tireModelRear:n,damperModelRear:o,heaveDamperModel:a,rollDamperModel:s,...i}=r;return{vehicle:e,params:{...t,...i,...n?{tireModelRear:n}:{},...o?{damperModelRear:o}:{},...a?{heaveDamperModel:a}:{},...s?{rollDamperModel:s}:{}}}}var IT=e=>({ggvMode:e.ggvMode,quasiTransient:e.quasiTransient===!0&&e.ggvMode!=="fast",motorThermal:e.motorThermal===!0,...oC({brakeFade:e.brakeFade===!0,airTempC:e.airTempC,diffYaw:e.diffYaw===!0,...e.air?{air:e.air}:{}})});function j$(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 _T(e,t){let r=t.plannedPath!==void 0,n=j$(t);return{...xT(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 ux(e,t){let r=e.vehicles.find(o=>o.id===t);if(!r)throw new Error(`this project holds no vehicle "${t}"`);let n=Oo(e);return ET(structuredClone(By(e,r.params)),structuredClone(r.params),DT(r.params,n))}var U$="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 mx(e,t,r,n){if(e.settings.pathPlanId)throw new Error(U$);let o=ms(e),a=e.tracks.length?(await zp(e,t)).asset:null,s={};for(let i of n?RT(n):[]){let c=e.tracks.find(l=>l.id===i);c&&(s[i]=await jc(c,t))}return _T(r,{track:a,numerics:o.numerics,racingLine:o.racingLine,standingStart:o.standingStart,lapCounts:o.lapCounts??{},switches:IT(o),rulesets:e.rulesets??[],library:s,standingOf:i=>e.tracks.find(c=>c.id===i)?.standingStart===!0})}async function NT(e,t,r,n){let o=ux(e,r),a=mt(o,n),s=await mx(e,t,o,a);return ix({id:0,car:o,spec:a,lap:s})}async function OT(e,t,r,n){let o=ux(e,r),a=mt(o,n),s=sx(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 mx(e,t,o,a)}catch(l){return{problems:[l instanceof Error?l.message:String(l)]}}let c=Ly(o,a,{...Jc(i),metrics:nr(e.rulesets)});return c.length?{problems:c}:{problems:[],msPerEval:ix({id:0,car:o,spec:a,lap:i}).msPerEval,carFingerprint:yo(cx(o))}}async function X$(e,t,r,n,o,a=[]){let s=ST(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 f=[],p=null,d=null;if(LT(m,y=>{y.kind==="progress"?(f.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"?p={result:y.result,elapsedMs:y.elapsedMs}:d=y.message}),d)throw new Error(d);if(!p)throw new Error("the search stopped without a result");let{result:h,elapsedMs:b}=p,g={seed:m.seed,startJitter:m.startJitter,x:h.x,score:h.score,evaluations:h.evaluations,infeasible:h.infeasible,history:h.history,trace:f,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 VT(e,t,r,n){let o=ux(e,r.vehicleId),a=mt(o,r.spec),s=sx(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 mx(e,t,o,a),c=r.method??kT;if(!xa.some(R=>R.name===c))throw new Error(`unknown method "${c}" \u2014 it is one of ${xa.map(R=>R.name).join(", ")}`);let l=r.budget??MT,u=Math.max(1,Math.min(r.seeds??Zc.length,Zc.length)),m=await X$(o,{spec:a,method:c,budget:l},i,u,n),f=lx(o,a,i),p=m.runs.map(R=>({seed:R.seed,startScore:m.designScore.total,score:R.score.total,feasible:R.score.feasible,...R.score.reason?{reason:R.score.reason}:{},terms:R.score.terms,x:R.x,evaluations:R.evaluations,infeasible:R.infeasible,bounds:AT(f.variables,R.x),constraints:FT(o,a,R.x,i),...R.snapped?{onSteps:{x:R.snapped.x,score:R.snapped.score.total,feasible:R.snapped.score.feasible,...R.snapped.score.reason?{reason:R.snapped.score.reason}:{},terms:R.snapped.score.terms}}:{}})),d=m.runs.reduce((R,k)=>ti(k.score,R.score)?k:R),h=d.snapped?.score.feasible?d.snapped:null,b=h?h.x:d.x,g=r.tolerance??jp,y=d.score.feasible&&g>0?PT({id:0,car:o,spec:a,x:b,lap:i,mm:g}).tolerance:null;return{method:c,budget:l,seeds:p,spread:m.runs.length>1?wT(o,f.variables,m.runs.map(R=>({x:R.x,score:R.score}))):null,writes:TT(o,a,b),...d.snapped?{adopts:h?"on its steps":`as found: on its steps it breaks a hold (${d.snapped.score.reason??"not legal"})`}:{},...y?{asBuilt:y}:{}}}function $T(){if(typeof process.threadCpuUsage!="function")return performance.now();let e=process.threadCpuUsage();return(e.user+e.system)/1e3}async function Q$(e,t){let r=eC(e.root);switch(e.kind){case"sweep":return dC(e.doc,r,e.req,t);case"convergence":return mC(e.doc,r,{vehicleId:e.vehicleId,...e.steps?{steps:e.steps}:{},...e.tolPct!==void 0?{tolPct:e.tolPct}:{},onStep:t});case"study":return VT(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 Yp(e.doc,r,{...e.vehicleIds?{vehicleIds:e.vehicleIds}:{},...e.settings?{settings:e.settings}:{},...e.overrides?{overrides:e.overrides}:{}});case"probe":return NT(e.doc,r,e.vehicleId,e.spec);case"quote":return OT(e.doc,r,e.vehicleId,e.spec)}}if(BT){let e=BT,t=r=>e.postMessage(r);(async()=>{try{let r=await Q$(q$,(n,o)=>t({type:"progress",done:n,total:o}));t({type:"done",result:r,cpuMs:$T()})}catch(r){t({type:"failed",message:r instanceof Error?r.message:String(r),cpuMs:$T()})}})()}export{Q$ as runJob,$T as threadCpuMs};
226
+ `)),this.name="RulesetDefError",this.problems=r}},sc=e=>typeof e=="number"&&Number.isFinite(e),ac=e=>sc(e)&&e>0,Vt=(e,t)=>e===void 0||t(e);function J_(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":ac(a.distance)||r(`${s} needs a distance above zero, in metres`),Vt(a.vStart,i=>sc(i)&&i>=0)||r(`${s}'s entry speed must be zero or more`);break;case"constantRadius":ac(a.radius)||r(`${s} needs a radius above zero, in metres`),Vt(a.laps,i=>sc(i)&&i>=1)||r(`${s} runs at least one lap`);break;case"trackLap":Vt(a.laps,i=>sc(i)&&i>=1)||r(`${s} runs at least one lap`),Vt(a.distance,ac)||r(`${s}'s distance must be above zero, in metres`),Vt(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),Vt(a.unit,i=>typeof i=="string")||r("Its unit is text",s),Vt(a.over,i=>typeof i=="string")||r("Names its event by id",s),Vt(a.format,i=>i==="time"||i==="points")||r("Is shown as a time, as points, or as a number",s),Vt(a.max,sc)||r("Its maximum is a number",s),Vt(a.lowerBetter,i=>typeof i=="boolean")||r("Lower is better, or it is not",s),Vt(a.hidden,i=>typeof i=="boolean")||r("Is hidden, or it is not",s)}Vt(e.track?.minTurnRadius,ac)||r("The tightest turn the rules allow is a radius above zero");let n=e.battery;for(let o of["packVoltageMax","segmentVoltageMax","powerLimitKw"])Vt(n?.[o],ac)||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 eA(e){let t=J_(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}=Em(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 _m(e){return eA(e).problems}var xg=e=>Number.isFinite(e)?e:NaN;function eN(e){return e.unit&&e.format!=="time"?`${e.label} (${e.unit})`:e.label}function Cn(e){let t=structuredClone(e),{plan:r,problems:n}=eA(t);if(!r)throw new Im(t.id,n);let o=new WeakMap,a=p=>{let d=o.get(p);return d||(d=yg(r,p),o.set(p,d)),d},s=new Map(t.kpis.map(p=>[p.key,p])),i=new Map;for(let[p,d]of Object.entries(t.score?.parts??{}))i.has(d)||i.set(d,p);let c=p=>(d,h)=>{if(!h)return NaN;let b=h.kpis?.[p];if(b!==void 0)return xg(b);let g=h,y=i.get(p);return y!==void 0?xg(g.parts?.[y]):p===t.score?.total?xg(g.total):NaN},l=t.kpis.filter(p=>!p.hidden).map(p=>{let d=r.field.has(p.key);return{key:p.key,label:eN(p),lowerBetter:p.lowerBetter??!1,...p.format?{format:p.format}:{},...d?{field:!0}:{},value:d?c(p.key):h=>a(h)[p.key]}}),u=t.score,m=u?p=>{let d=oc(r,p),h={};for(let[b,g]of Object.entries(d)){let y={},R={};for(let[k,v]of Object.entries(u.parts)){y[k]=g[v];let x=s.get(v)?.max;x!=null&&(R[k]=x)}h[b]={total:g[u.total],parts:y,...Object.keys(R).length?{maxima:R}:{},kpis:Object.fromEntries(t.kpis.map(k=>[k.key,g[k.key]]))}}return h}:void 0,f=m||(r.field.size>0?p=>{let d=oc(r,p),h={};for(let[b,g]of Object.entries(d))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}:{},...f?{field:f}:{},definition:t}}var er={accel:"accel",skidpad:"skidpad",autocross:"autocross",endurance:"endurance"},tA=[{kind:"straightLineAccel",id:er.accel,label:"Acceleration (75 m)",distance:75},{kind:"constantRadius",id:er.skidpad,label:"Skidpad",radius:8.375},{kind:"trackLap",id:er.autocross,label:"Autocross (1 lap)",laps:1},{kind:"trackLap",id:er.endurance,label:"Endurance (22 km)",distance:22e3}],rA=[{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"}],nA={total:"overall",parts:{[er.accel]:"accelPts",[er.skidpad]:"skidpadPts",[er.autocross]:"autocrossPts",[er.endurance]:"endurancePts",efficiency:"efficiencyPts"}},oA={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:tA,kpis:rA,score:nA,track:{minTurnRadius:4.5},battery:bx,traceEventId:er.autocross},aA={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:tA,kpis:rA,score:nA,track:{minTurnRadius:4.5},traceEventId:er.autocross},ic=Cn(oA),Rg=Cn(aA);var vg="lap",tN=[{kind:"trackLap",id:vg,label:Lm,laps:1}],sA={id:"trackday",label:"Track day",description:"One flying lap of the selected track. Times and traces only \u2014 no scoring.",events:tN,kpis:[{key:"lap",label:"Lap time",format:"time",lowerBetter:!0,expr:"lap.time"},{key:"topSpeed",label:"Top speed",unit:"km/h",over:vg,expr:"peak(speed)"},{key:"energy",label:"Energy / lap",unit:"kWh",lowerBetter:!0,expr:"lap.energy"}],traceEventId:vg},kg=Cn(sA);function Tn(e){if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(Tn).join(",")}]`;let t=e,r=Object.keys(t).sort(),n=[];for(let o of r)t[o]!==void 0&&n.push(`${JSON.stringify(o)}:${Tn(t[o])}`);return`{${n.join(",")}}`}function xo(e){let t=Tn(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 Qa=[ic,Rg,kg],Ro=ic.id,Za=e=>Qa.some(t=>t.id===e),iA=new WeakMap,cc=new Map,rN=64;function Nm(e){let t=iA.get(e);if(t!==void 0)return t;let r=Tn(e),n=cc.get(r);return n===void 0&&(n=_m(e).length?null:Cn(e),cc.size>=rN&&cc.delete(cc.keys().next().value),cc.set(r,n)),iA.set(e,n),n}function Om(e,t=[]){if(e==null)return;if(typeof e!="string")return Nm(e)??void 0;let r=Qa.find(o=>o.id===e);if(r)return r;let n=t.find(o=>o.id===e);return n?Nm(n)??void 0:void 0}function vo(e,t=[]){return Om(e,t)??ic}function Mg(e=[]){let t=e.filter(r=>!Za(r.id)).map(r=>Nm(r)).filter(r=>r!==null);return[...Qa,...t]}var lc=e=>e.definition??e.id;function Vm(e,t,r){let n=e.length,o=new Array(n);for(let d=0;d<n;d++){let h=d+1<n?e[d+1]:r;o[d]=h-e[d]}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 d=0;d<n;d++){let h=o[(d-1+n)%n],b=o[d];a[d]=h,s[d]=2*(h+b),i[d]=b;let g=t[(d+1)%n],y=t[(d-1+n)%n];c[d]=6*((g-t[d])/b-(t[d]-y)/h)}let l=nN(a,s,i,c),u=new Array(n),m=new Array(n),f=new Array(n),p=new Array(n);for(let d=0;d<n;d++){let h=o[d],b=l[d],g=l[(d+1)%n],y=t[d],R=t[(d+1)%n];u[d]=y,f[d]=b/2,p[d]=(g-b)/(6*h),m[d]=(R-y)/h-h*(2*b+g)/6}return{n,eval:(d,h)=>u[d]+h*(m[d]+h*(f[d]+h*p[d])),d1:(d,h)=>m[d]+h*(2*f[d]+h*3*p[d]),d2:(d,h)=>2*f[d]+h*6*p[d]}}function Ag(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),f=new Array(u).fill(0),p=new Array(u).fill(0),d=new Array(u).fill(0);for(let g=0;g<u;g++){let y=g+1;m[g]=o[y-1],f[g]=2*(o[y-1]+o[y]),p[g]=o[y],d[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];f[0]+=o[0]*(1+g),p[0]-=o[0]*g;let y=o[n-1]/o[n-2];f[u-1]+=o[n-1]*(1+y),m[u-1]-=o[n-1]*y}let b=Sg(m,f,p,d);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 nN(e,t,r,n){let o=t.length;if(o===1)return[n[0]/(t[0]+e[0]+r[0])];if(o===2){let d=t[0],h=r[0]+e[0],b=e[1]+r[1],g=t[1],y=d*g-h*b;return[(n[0]*g-h*n[1])/y,(d*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=Sg(e,c,r,n),u=new Array(o).fill(0);u[0]=i,u[o-1]=s;let m=Sg(e,c,r,u),f=(l[0]+a*l[o-1]/i)/(1+m[0]+a*m[o-1]/i),p=new Array(o);for(let d=0;d<o;d++)p[d]=l[d]-f*m[d];return p}function Sg(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 uc(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 cA(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 lA(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 f=r*i-o*o,p=n*o-r*s,d=r*a-n*n;return[(c*t[0]+l*t[1]+u*t[2])/m,(l*t[0]+f*t[1]+p*t[2])/m,(u*t[0]+p*t[1]+d*t[2])/m]}function uA(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=>cA(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=lA([u[0],u[1],u[2],u[2],u[3],u[4]],[1,0,0]);if(!m)continue;let f=l.map(h=>m[0]+m[1]*h+m[2]*h*h),p=0,d=1;f.forEach((h,b)=>{p+=h*e.z[s[b]],d+=h*h}),r.push(Math.abs(e.z[a]-p)/Math.sqrt(d))}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 oN(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=cA(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 aN(e,t,r){let{j:n,t:o}=oN(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 f=0;f<5;f++)i[f]+=m,m*=l});let c=lA([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 Fg(e,t){return t>0?e.z.map((r,n)=>{let o=aN(e,n,t/2);return o?o.value.reduce((a,s,i)=>a+s*e.z[o.j[i]],0):r}):[...e.z]}function sN(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 Bm(e){let t=uc(e);if(!t)return 0;let r=uA(t);return r>1e-6?Math.max(10,sN(r,iN(t))):0}function iN(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 Mr(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 Gm(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 mA(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 $m(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 cN(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 wg(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=mA(r,(y,R)=>Mr(e,y,R));if(!b)return null;let g=$m(b,t);return g.every(Number.isFinite)?g:null}let n=r-2,a=mA(n,(b,g)=>Mr(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]=Mr(e,b,r-2),i[b]=Mr(e,b,r-1);let c=$m(a,t.slice(0,n)),l=$m(a,s),u=$m(a,i),m=(b,g)=>{let y=0;for(let R=0;R<b.length;R++)y+=b[R]*g[R];return y},f=[[Mr(e,r-2,r-2)-m(s,l),Mr(e,r-2,r-1)-m(s,u)],[Mr(e,r-1,r-2)-m(i,l),Mr(e,r-1,r-1)-m(i,u)]],p=[t[r-2]-m(s,c),t[r-1]-m(i,c)],d=cN(f,p);if(!d)return null;let h=new Array(r).fill(0);for(let b=0;b<n;b++)h[b]=c[b]-l[b]*d[0]-u[b]*d[1];return h[r-2]=d[0],h[r-1]=d[1],h.every(Number.isFinite)?h:null}function pA(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=wg(i,t);if(c){let l=Gm(i,c).map((m,f)=>m-t[f]);if(Math.sqrt(l.reduce((m,f)=>m+f*f,0))<=1e-6*Math.max(a,1e-12))return c}o=o===0?n*1e-12:o*10}return null}var dA=4,lN=8,Cg=.001;function uN(e,t,r){let n=[];for(let c=1;c<e.length;c++){let l=e[c]-e[c-1];l>=Cg&&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/kM(r,s,i)))}function mN(e,t){let r=e.closed!==!1,n=[],o=[],a=(A,w)=>{let T=n.length-1;T>=0&&Math.hypot(A-n[T],w-o[T])<Cg||(n.push(A),o.push(w))},s=e.x.length,i=r?s:s-1,c=new Array(i+1);c[0]=0;for(let A=0;A<i;A++){let w=(A+1)%s;c[A+1]=c[A]+Math.hypot(e.x[w]-e.x[A],e.y[w]-e.y[A])}let l=c[i],u=e.fit==="interpolate",m=u?s:uN(c,r,t),f=r?m:m-1,p=0;for(let A=0;A<=f&&!(r&&A===f);A++){if(u){a(e.x[A],e.y[A]);continue}let w=A*l/f;for(;p<i-1&&c[p+1]<w;)p++;let T=c[p+1]-c[p],P=T>0?(w-c[p])/T:0,S=(p+1)%s;a(e.x[p]+P*(e.x[S]-e.x[p]),e.y[p]+P*(e.y[S]-e.y[p]))}if(r)for(;n.length>2&&Math.hypot(n[n.length-1]-n[0],o[o.length-1]-o[0])<Cg;)n.pop(),o.pop();let d=n.length,h=r?d:d-1,b=new Array(h+1);b[0]=0;for(let A=1;A<=h;A++){let w=A%d,T=n[w]-n[A-1],P=o[w]-o[A-1],S=Math.sqrt(Math.hypot(T,P))||1e-9;b[A]=b[A-1]+S}let g=r?Vm(b.slice(0,d),n,b[d]):Ag(b,n),y=r?Vm(b.slice(0,d),o,b[d]):Ag(b,o),R=new Array(h);for(let A=0;A<h;A++)R[A]=b[A+1]-b[A];let k=[0],v=[0],x=[0],M=0;for(let A=0;A<h;A++){let w=R[A]/dA;for(let T=0;T<dA;T++){let P=T*w;M+=Eh(S=>Math.hypot(g.d1(A,S),y.d1(A,S)),P,P+w),k.push(M),v.push(A),x.push(P+w)}}return{closed:r,sx:g,sy:y,h:R,sTable:k,segTable:v,uTable:x,length:M,rawCum:c,rawLength:l}}function mc(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 f=i*n.rawLength,p=0,d=a;for(;p<d;){let b=p+d+1>>1;n.rawCum[b]<=f?p=b:d=b-1}let h=p<a?n.rawCum[p+1]-n.rawCum[p]:0;c=p+(h>0?(f-n.rawCum[p])/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 pN=.01,dN=3,fA=10;function fN(e,t,r,n=fA){let o={step:0,uncertainty:1/0},a=e.length;if(a<8||!(r>0))return o;let s=Math.max(fA,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=[],f=[],p=(R,k,v)=>{let x=R/s;m.push([1,x,x*x,x*x*x,k]),f.push(v)};for(let R=0;R<u;R++)p(t[R]+i,1,e[R]);for(let R=0;R<u;R++)p(t[a-1-R]-r+i,0,e[a-1-R]);let d=Array.from({length:5},()=>new Array(5).fill(0)),h=new Array(5).fill(0);m.forEach((R,k)=>{for(let v=0;v<5;v++){h[v]+=R[v]*f[k];for(let x=0;x<5;x++)d[v][x]+=R[v]*R[x]}});let b=cr(d,h),g=cr(d,[0,0,0,0,1]);if(b.singular||g.singular)return o;let y=0;return m.forEach((R,k)=>{let v=0;for(let x=0;x<5;x++)v+=R[x]*b.x[x];y+=(f[k]-v)**2}),{step:b.x[4],uncertainty:Math.sqrt(y/(m.length-5)*g.x[4])}}function hN(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 bN(e,t,r){let{pos:n,loop:o}=hN(e.length,t),{step:a,uncertainty:s}=fN(e,n,o,r);return Math.abs(a)>Math.max(pN,dN*s)?{z:e.map((i,c)=>i+a*n[c]/o),drift:-a}:{z:e,drift:0}}function gN(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],f=r[u+1],p=n[u+1],d=o[u+1],h=n[u]===p?o[u]:0,b=f-m,g=b>0?h+(t-m)/b*(d-h):h;for(let y=0;y<2;y++){let R=m+Eh(v=>Math.hypot(s.d1(p,v),i.d1(p,v)),h,g),k=Math.hypot(s.d1(p,g),i.d1(p,g));if(k<1e-12)break;g-=(R-t)/k}return{seg:p,du:Math.min(Math.max(g,0),a[p])}}var yN=3,Tg=5;function xN(e,t,r,n=Tg){return Hm(e,t,r,n)}function Hm(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 f of[0,a-1])i[f]+=m,u[f]*=1+m}return wg({n:a,diag:i,off1:c,off2:l,closed:r},u)??[...e]}function mt(e,t){let r=ut(t),n=mN(e,r.fitSpacing),o=n.length,a=Math.max(lN,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 f=new Array(s),p=new Array(s),d=new Array(s);for(let T=0;T<s;T++){let P=T*i,{seg:S,du:F}=gN(n,P);c[T]=n.sx.eval(S,F),l[T]=n.sy.eval(S,F),u[T]=P;let C=n.sx.d1(S,F),L=n.sy.d1(S,F),E=n.sx.d2(S,F),D=n.sy.d2(S,F),N=Math.hypot(C,L),O=Math.pow(C*C+L*L,1.5);f[T]=O>0?(C*D-L*E)/O:0,p[T]=N>0?-L/N:0,d[T]=N>0?C/N: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?bN(e.z,n.rawCum,g):null,R=y?y.z:e.z,k=g>0?uc(e):null,v=k?Fg({...k,z:R},g):R,x=mc(v,0,h,n),M=new Array(s).fill(0);if(b){for(let P=0;P<s;P++){let S=n.closed?(P+1)%s:Math.min(P+1,s-1),F=n.closed?(P-1+s)%s:Math.max(P-1,0),C=n.closed?2:S-F,L=x[S]-x[F];M[P]=C>0?Math.atan2(L,C*i)*180/Math.PI:0}for(let P=0;P<s;P++){if(m[P]===0)continue;let S=n.closed?(P+1)%s:P+1,F=x[S]-x[P];m[P]=Math.hypot(i,F)}let T=0;for(let P=0;P<s;P++)u[P]=T,T+=m[P]}let A=b?m.reduce((T,P)=>T+P,0):o,w;if(b){w=new Array(s).fill(0);let T=Math.max(yN,e.zReach??Bm(e)),P=Math.max(2,Math.round(T/i));if(n.closed?s>2*P:s>2*P+1){let S=0,F=0;for(let E=-P;E<=P;E++)S+=E*E,F+=E*E*E*E;let C=2*P+1,L=F-S*S/C;for(let E=0;E<s;E++){let D=n.closed?E:Math.min(Math.max(E,P),s-1-P),N=0,O=0;for(let _=-P;_<=P;_++){let B=x[n.closed?(D+_+s)%s:D+_];N+=(_*_-S/C)*B,O+=_*B}let z=2*N/L/(i*i),I=O/S/i;w[E]=z/Math.pow(1+I*I,1.5)}}}return{name:e.name,closed:n.closed,x:c,y:l,s:u,ds:m,curvature:e.turnReach?xN(f,i,n.closed,e.turnReach):f,npts:s,length:A,nx:p,ny:d,z:x,gradient:M,...w?{verticalCurvature:w}:{},widthLeft:mc(e.widthLeft,1.5,h,n),widthRight:mc(e.widthRight,1.5,h,n),bank:mc(e.bank,0,h,n),mu:mc(e.mu,1,h,n),...y?.drift?{elevationDrift:y.drift}:{}}}function hA(e,t,r){let n=Gm(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 RN(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 f=s(l,m);f!=null&&(i[f]-=Mr(e,f,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 pA(c,i)}var vN=1e-4;function bA(e,t,r,n,o={}){let a=e.n,s=o.maxIter??60,i=o.tol??1e-9,c=o.bounds,l=(d,h)=>Math.min(n[h],Math.max(r[h],d)),u=r.map((d,h)=>c?.[h]==="hi"?n[h]:c?.[h]==="lo"?r[h]:l(0,h)),m=hA(e,t,u),f=new Array(a).fill("free"),p=!1;for(let d=0;d<s;d++){let h=Gm(e,u).map((R,k)=>R-t[k]),b=!1;for(let R=0;R<a;R++){let k=u[R]<=r[R]+i&&h[R]>=-i?"lo":u[R]>=n[R]-i&&h[R]<=i?"hi":"free";k!==f[R]&&(f[R]=k,b=!0)}if(p&&!b)return{x:u,iterations:d+1,converged:!0,bounds:f};let g=RN(e,t,f,R=>u[R]);if(!g)return{x:u,iterations:d+1,converged:!1,bounds:f};let y=!1;for(let R=1;R>1e-12;R*=.5){let k=!1,v=u.map((A,w)=>{if(f[w]!=="free")return A;let T=A+R*(g[w]-A),P=l(T,w);return P!==T&&(k=!0),P}),x=hA(e,t,v),M=0;for(let A=0;A<a;A++)M+=h[A]*(v[A]-u[A]);if(R===1&&!k||x<m&&x<=m+vN*M){u=v,m=x,p=R===1&&!k,y=!0;break}}if(!y)return{x:u,iterations:d+1,converged:!1,bounds:f}}return{x:u,iterations:s,converged:!1,bounds:f}}var Pg={lineStep:2,carHalfWidth:.75,margin:.1,foldMargin:.25,referenceReach:5,passes:40,iterations:400},kN=[1,.5,.25,.125,.0625,.03125,.015625,.0078125,.00390625,.001953125,.0009765625],MN=e=>Math.sqrt(e.reduce((t,r)=>t+r*r,0)/(e.length||1));function pc(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],f=e[i]-e[s],p=t[i]-t[s],d=Math.hypot(c,l),h=Math.hypot(u,m),b=Math.hypot(f,p),g=d*h*b;o[a]=g>1e-12?2*(c*m-l*u)/g:0}return o}var SN=Math.PI/180,gA=20;function AN(e,t){let r=e.npts,n=e.closed,o=e.x.map((p,d)=>p+t[d]*e.nx[d]),a=e.y.map((p,d)=>p+t[d]*e.ny[d]),s=[0];for(let p=1;p<r;p++)s.push(s[p-1]+Math.hypot(o[p]-o[p-1],a[p]-a[p-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 p of c)for(let d=0;d<r;d++)l.push(s[d]+p*i),u.push(d+p*r);n&&(l.push(2*i),u.push(2*r));let m=[0];for(let p=1;p<l.length;p++)m.push(m[p-1]+.5*(u[p]+u[p-1])*(l[p]-l[p-1]));let f=p=>{let d=0,h=l.length-1;for(;h-d>1;){let g=d+h>>1;l[g]<=p?d=g:h=g}let b=l[h]>l[d]?(p-l[d])/(l[h]-l[d]):0;return m[d]+(l[h]-l[d])*b*(u[d]+.5*b*(u[h]-u[d]))};return s.map((p,d)=>{let h=n?gA:Math.min(gA,p,i-p);if(!(h>0))return e.z[d];let b=(f(p+h)-f(p-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),R=n?(y+1)%r:Math.min(y+1,r-1);return e.z[y]+(g-y)*(e.z[R]-e.z[y])})}function FN(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?AN(t,r):t.z;return{...n||o?{z:s.map((i,c)=>i+r[c]*Math.tan(t.bank[c]*SN))}:{},...n?{zReach:e.zReach??Bm(e)}:{},...o?{bank:[...t.bank]}:{},...a?{mu:[...t.mu]}:{}}}function yA(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 wN(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,f)=>l*f-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,f=e[l]-e[u],p=t[l]-t[u],d=e[m]-e[l],h=t[m]-t[l],b=e[m]-e[u],g=t[m]-t[u],y=Math.hypot(f,p),R=Math.hypot(d,h),k=Math.hypot(b,g),v=y*R*k;if(!(v>1e-12))continue;let x=2*c(f,p,d,h)/v,M=Math.sqrt(.5*(y+R)),A=x/(2*M),w=(f*r[u]+p*n[u])/y,T=(b*r[u]+g*n[u])/k,P=(f*r[l]+p*n[l])/y,S=(d*r[l]+h*n[l])/R,F=(d*r[m]+h*n[m])/R,C=(b*r[m]+g*n[m])/k,L=-2*c(r[u],n[u],d,h)/v+x*(w/y+T/k),E=2*c(r[l],n[l],b,g)/v-x*(P/y-S/R),D=2*c(f,p,r[m],n[m])/v-x*(F/R+C/k);s[l]=x*M,i.l[l]=M*L-A*.5*w,i.d[l]=M*E+A*.5*(P-S),i.r[l]=M*D+A*.5*F}return{res:s,jac:i}}function CN(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),f=new Array(a),p=new Array(a),d=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,f[h]=i[h]*c[h]+g*u(i,h+1),p[h]=g*u(c,h+1),d[h]=-(b*u(l,h-1)+i[h]*l[h]+g*u(l,h+1))}return{M:{n:a,closed:o,diag:m,off1:f,off2:p},b:d}}function TN(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 f=0;f<o;f++){let p=(f+1)%r;a+=Math.hypot(e.x[p]-e.x[f],e.y[p]-e.y[f])}let s=a/o,i=Hm(e.x,s,n,t,!0),c=Hm(e.y,s,n,t,!0),l=new Array(r),u=new Array(r);for(let f=0;f<r;f++){let p=n?(f-1+r)%r:Math.max(f-1,0),d=n?(f+1)%r:Math.min(f+1,r-1),h=i[d]-i[p],b=c[d]-c[p],g=Math.hypot(h,b)||1;l[f]=-b/g,u[f]=h/g}let m=pc(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 PN=6;function LN(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]),f=Math.hypot(e.x[u]-e.x[l],e.y[u]-e.y[l]);s[l]=f>1e-9?m/f:0}let i=Math.max(0,Math.round(PN/(e.ds[0]||1))),c=1-n;for(let l=0;l<o;l++){let u=0,m=0;for(let f=-i-1;f<=i;f++){let p=e.closed?((l+f)%o+o)%o:l+f;p<0||p>=a||(u=Math.max(u,s[p]),m=Math.max(m,-s[p]))}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 Lg(e,t={}){let r={...Pg,...t},n=mt(e,{dsTarget:r.lineStep}),o=TN(n,r.referenceReach),a=o.npts,s=P=>({x:o.x.map((S,F)=>S+o.nx[F]*P[F]),y:o.y.map((S,F)=>S+o.ny[F]*P[F])}),i=P=>{let S=pc(P.x,P.y,o.closed),F=yA(P.x,P.y,o.closed),C=0;for(let L=0;L<S.length;L++)C+=S[L]*S[L]*F[L];return C},c=MN(n.curvature),l=yA(n.x,n.y,n.closed).reduce((P,S)=>P+S,0),u=new Array(a).fill(0),m=r.carHalfWidth+r.margin,f=new Array(a),p=new Array(a),d=0;for(let P=0;P<a;P++){let S=o.widthLeft[P]-m,F=-(o.widthRight[P]-m);if(S<F){d++;let C=(o.widthLeft[P]-o.widthRight[P])/2;f[P]=C,p[P]=C}else f[P]=S,p[P]=F}let h=[...f],b=[...p];LN(o,f,p,r.foldMargin);let g=P=>{let S=s(P),F=FN(e,o,P),C={name:`${e.name} \u2014 racing line`,x:S.x,y:S.y,closed:o.closed,widthLeft:h.map((I,_)=>Math.max(0,I-P[_])),widthRight:b.map((I,_)=>Math.max(0,P[_]-I)),...F,fit:"interpolate",turnReach:Tg},L=1e-6,E=P.filter((I,_)=>I>=f[_]-L||I<=p[_]+L).length,D=pc(S.x,S.y,o.closed),N=I=>1/Math.max(...I.map(Math.abs),1e-9),O=0,z=o.closed?S.x.length:S.x.length-1;for(let I=0;I<z;I++){let _=(I+1)%S.x.length,B=S.x[_]-S.x[I],V=S.y[_]-S.y[I];O+=F.z?Math.hypot(B,V,F.z[_]-F.z[I]):Math.hypot(B,V)}return{offset:P,s:[...o.s],asset:C,curvatureRms:{centreLine:c,racingLine:Math.sqrt(i(S)/(l||1))},infeasibleSamples:d,atBoundary:a?E/a:0,length:{centreLine:n.length,racingLine:O},worstRadius:{centreLine:N(n.curvature),racingLine:N(D)}}},y=o.closed?0:1,R=o.closed?a-1:a-2,k=R-y+1,v=new Array(k),x=new Array(k);for(let P=0;P<k;P++)v[P]=p[y+P],x[P]=f[y+P];if(!o.closed&&k>0){let P=(S,F)=>{if(v[S]=Math.max(v[S],p[F]),x[S]=Math.min(x[S],f[F]),v[S]>x[S]){let C=.5*(v[S]+x[S]);v[S]=C,x[S]=C}};P(0,0),P(k-1,a-1),v[0]=x[0]=Math.min(x[0],Math.max(v[0],0))}if(k<7)return g(u);let M=P=>{let S=s(P),C=[...pc(S.x,S.y,o.closed).map(Math.abs)].sort((L,E)=>L-E);return{integral:i(S),tail:C[Math.floor(.99*(C.length-1))]}},A=[...u],w=M(u),T;for(let P=0;P<r.passes;P++){let S=s(A),{res:F,jac:C}=wN(S.x,S.y,o.nx,o.ny,o.closed),{M:L,b:E}=CN(C,F,y,R,o.closed),D=bA(L,E,v.map((z,I)=>z-A[y+I]),x.map((z,I)=>z-A[y+I]),{maxIter:r.iterations,bounds:T});T=D.bounds;let N=new Array(a).fill(0);for(let z=0;z<k;z++)N[y+z]=D.x[z];o.closed||(N[0]=N[1],N[a-1]=N[a-2]);let O=!1;for(let z of kN){let I=A.map((B,V)=>B+z*N[V]),_=M(I);if(_.integral<w.integral*(1-1e-6)){A=I,w=_,O=!0;break}}if(!O)break}return g(A)}function Dg(e){let t=Math.max(Q(e,"track_front"),Q(e,"track_rear"));return(t>0?t/2e3:.6)+.1}function zm(e,t,r={}){if(!r.racingLine)return{asset:e,numerics:t,line:null};let n=r.params?Dg(r.params):void 0,o=Lg(e,{...r.line,...n?{carHalfWidth:n}:{}});return{asset:o.asset,numerics:{...t,fitSpacing:0},line:o}}function dc(e,t,r={}){let n=zm(e,t,r);return{track:mt(n.asset,n.numerics),line:n.line}}function Eg(e=4,t=dc){let r=new WeakMap;return(n,o,a={})=>{let s=a.racingLine===!0,i=s?[a.params?Dg(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 xA={racingLine:!1,standingStart:!1},Ym=256;function fc(e,t,r,n,o=xA,a=dc){let s=vo(n),{racingLine:i,standingStart:c,lapCounts:l}=o;return e.map(u=>{let{track:m}=a(t,r,{racingLine:i,params:u});return dg(ec(u,s,{track:m,numerics:r,standingStart:c,lapCounts:l}))})}function Ig(e,t){let r=vo(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 _g(e,t,r){let n={};for(let o of vo(e).metrics)n[o.key]=o.value(t,r);return n}var Wm=36;var Vg=287.05287,EN=461.495,jm=9.80665/(Vg*.0065),IN=101325/(Vg*288.15),_N=273.15,NN=-500,ON=6e3,VN=400,BN=1100,Um={source:"car",altitudeM:0,pressure:{kind:"standard"},humidityPct:0};function $N(e){return 101325*Math.pow(1-.0065*e/288.15,jm)}function GN(e){return 288.15/.0065*(1-Math.pow(e/IN,1/(jm-1)))}function KN(e){return 288.15/.0065*(1-Math.pow(e/101325,1/jm))}function HN(e,t){return e*Math.pow(1-.0065*t/288.15,jm)}function zN(e){return 611.21*Math.exp((18.678-e/234.5)*(e/(257.14+e)))}function YN(e,t){switch(e.kind){case"standard":return $N(t);case"qnh":return HN(e.hPa*100,t);case"station":return e.hPa*100}}function hc(e,t,r=0,n=KN(e)){let o=t+_N,a=Math.min(.5*e,Math.max(0,Math.min(100,r))/100*zN(t)),s=e-a,i=s/(Vg*o)+a/(EN*o);return{altitudeM:n,p:e,pDry:s,T:o,rho:i,densityAltitudeM:GN(i)}}function RA(e,t){return hc(YN(e.pressure,e.altitudeM),t,e.humidityPct,e.altitudeM)}var Ng=(e,t,r)=>Math.min(r,Math.max(t,e)),Og=(e,t)=>{let r=Number(e);return Number.isFinite(r)?r:t};function Xm(e){if(!e||typeof e!="object")return structuredClone(Um);let t=e,r=t.pressure??{},n=Ng(Og(r.hPa,1013.25),VN,BN),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:Ng(Og(t.altitudeM,0),NN,ON),pressure:o,humidityPct:Ng(Og(t.humidityPct,0),0,100)}}var bc=e=>e?.source==="venue";var WN=Math.PI/180;function jN(){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:[10,480,420],rockerToDamper:[10,280,440],damperChassis:[10,275,245]}}function UN(){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:[12,486,430],rockerToDamper:[12,286,450],damperChassis:[12,281,255]}}function Bg(e){let t=-e*WN;return q([0,Math.cos(t),Math.sin(t)])}function qm(){let e={rodType:"push",pushrodAttach:"lowerArm",steerMode:"rack",spinAxis:Bg(-1),loadedRadius:230,springRate:35,rackAxis:[0,1,0]};return{hardpoints:jN(),config:e}}function gc(){let e={rodType:"pull",pushrodAttach:"lowerArm",steerMode:"fixed",spinAxis:Bg(-1.5),loadedRadius:232,springRate:40,rackAxis:[0,1,0]};return{hardpoints:UN(),config:e}}function Qm(){let e=[-25,635,460],t=[-40,600,710],r={layout:"mcpherson",actuation:"direct",rodType:"push",pushrodAttach:"upright",steerMode:"rack",spinAxis:Bg(-.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 $g(){return{front:qm(),rear:gc(),config:{wheelbase:1600,trackFront:1200,trackRear:1220,frontAxleX:800}}}var XN=Math.PI/180;function vA(e){let t=-e*XN;return q([0,Math.cos(t),Math.sin(t)])}function Gg(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:vA(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]=qN(o[l]);return{hardpoints:o,config:c}}function qN(e){return e.map(t=>Math.round(t*10)/10+0)}function Mo(e){return{name:e.name,front:Gg(qm(),e.front),rear:Gg(gc(),e.rear),config:{wheelbase:e.wheelbase,trackFront:e.trackFront,trackRear:e.trackRear,frontAxleX:e.wheelbase/2}}}function Ja(e,t,r){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:t}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:r}}}}var es=600,So=610,ts=230,Ao=232;function Fo(){let e=$g();return{...e,name:"Formula Student",front:{...e.front,config:{...e.front.config,actuation:"rocker"}},rear:{...e.rear,config:{...e.rear.config,actuation:"rocker"}}}}function Kg(){return Mo({name:"Formula 1",wheelbase:3600,trackFront:1600,trackRear:1600,front:{kx:1.3,ky:800/es,kz:355/ts,lowerInnerDz:-5,upperInnerDz:0,camberDeg:-3,loadedRadius:355,springRate:200},rear:{kx:1.3,ky:800/So,kz:355/Ao,lowerInnerDz:35,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:220}})}function yc(){return Ja(Mo({name:"GT car",wheelbase:2700,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/es,kz:325/ts,lowerInnerDz:18,upperInnerDz:5,camberDeg:-3.5,loadedRadius:325,springRate:110,actuation:"direct"},rear:{kx:1.2,ky:825/So,kz:325/Ao,lowerInnerDz:36,upperInnerDz:15,camberDeg:-2,loadedRadius:325,springRate:120,actuation:"direct"}}),318.6,318.6)}function xc(){return Ja(Mo({name:"Sports car",wheelbase:2750,trackFront:1550,trackRear:1550,front:{kx:1.15,ky:775/es,kz:320/ts,lowerInnerDz:36,upperInnerDz:15,camberDeg:-.5,loadedRadius:320,springRate:55,actuation:"direct"},rear:{kx:1.15,ky:775/So,kz:320/Ao,lowerInnerDz:57,upperInnerDz:25,camberDeg:-1,loadedRadius:320,springRate:60,actuation:"direct"}}),305.4,309)}function QN(e,t,r,n,o,a){let s=Qm(),i=Object.fromEntries(Object.entries(s.hardpoints).map(([l,[u,m,f]])=>[l,[u,m+e,f]])),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:vA(n),springRate:o,rackTravel:a}}}function kA(){return Ja({name:"Cup car",front:QN(55,-25,-23,-3.5,150,55),rear:Gg(gc(),{kx:1.15,ky:820/So,kz:320/Ao,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 MA(){return{...Ja(Mo({name:"Stock car",wheelbase:2794,trackFront:1650,trackRear:1650,front:{kx:1.2,ky:825/es,kz:355/ts,lowerInnerDz:20,upperInnerDz:5,camberDeg:-2.5,loadedRadius:355,springRate:175,actuation:"direct"},rear:{kx:1.2,ky:825/So,kz:355/Ao,lowerInnerDz:40,upperInnerDz:15,camberDeg:-1.5,loadedRadius:355,springRate:150,actuation:"direct"}}),343.8,345.3),chassis:{boxes:[],body:"nascar"}}}function SA(){let e=Ja(Mo({name:"Hill-climb prototype",wheelbase:2550,trackFront:1580,trackRear:1540,front:{kx:1.1,ky:790/es,kz:300/ts,lowerInnerDz:10,upperInnerDz:5,camberDeg:-2.5,loadedRadius:300,springRate:90},rear:{kx:1.1,ky:770/So,kz:300/Ao,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 AA(){let e=Ja(Mo({name:"Race truck",wheelbase:3700,trackFront:2050,trackRear:1950,front:{kx:1.5,ky:1025/es,kz:506/ts,lowerInnerDz:40,upperInnerDz:10,camberDeg:-.5,loadedRadius:506,springRate:200,actuation:"direct"},rear:{kx:1.5,ky:975/So,kz:506/Ao,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 ot=(e,t,r)=>({value:e,label:t,unit:r}),FA=(e,t)=>({...br[e],value:t});function wA(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 wo(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 tn(e){let t={name:e.name,m:ot(e.m,"vehicle mass (with driver)","kg"),A:ot(e.A,"frontal area","m^2"),c_l:ot(e.cl,"downforce coefficient","-"),c_w:ot(e.cw,"drag coefficient","-"),l_to_d_ratio:ot(e.cw>0?e.cl/e.cw:0,"lift-to-drag ratio","-"),driven_wheels:ot(e.drivenWheels,"driven wheels","-"),fr_0:ot(-.012,"rolling-resistance coefficient","-"),front_aero_diss:ot(e.frontAero,"front aero distribution","-"),front_mass_diss:ot(e.frontMass,"front mass distribution","-"),r_dyn:ot(e.rDyn,"dynamic tyre radius","m"),rho:ot(1.2,"air density","kg/m^3"),gear_ratio:ot(e.gearRatio,"gear ratio","-"),effi_pgb:ot(e.drivetrainEfficiency,"drivetrain efficiency","-"),capacity:ot(e.capacityAh,"pack capacity","Ah"),soc:ot(1,"state of charge","-"),ocv:ot(e.ocv,"pack open-circuit voltage","V"),power_scale:ot(1,"power scaling factor","-"),power_limit_kw:FA("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]=FA(r,n);return t}var rs={name:"Formula Student",m:300,A:1,cl:3,cw:1.3,frontMass:.47,frontAero:.45,rDyn:.222,drivenWheels:2,gearRatio:11.5,motor:wA(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}},zg={name:"Formula 1",m:798,A:1.5,cl:3,cw:.9,frontMass:.46,frontAero:.44,rDyn:.35,drivenWheels:2,gearRatio:4.9,motor:wo(735,2e3,12500,2500,2),motorCount:1,driveline:{rear:Ft.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}},Zm={name:"GT car",m:1300,A:2,cl:1.4,cw:.42,frontMass:.5,frontAero:.42,rDyn:.33,drivenWheels:2,gearRatio:3.43,motor:wo(410,2e3,8e3,2e3,2),motorCount:1,driveline:{rear:Ft.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}},Jm={name:"Sports car",m:1600,A:2.2,cl:-.1,cw:.3,frontMass:.55,frontAero:.5,rDyn:.32,drivenWheels:2,gearRatio:3.14,motor:wo(220,1500,6500,1400,2),motorCount:1,driveline:{rear:Ft.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}},Yg={name:"Cup car",m:1265,A:2.1,cl:.45,cw:.4,frontMass:.62,frontAero:.45,rDyn:.31,drivenWheels:2,gearRatio:3.5,motor:wo(250,2e3,7e3,1190,2),motorCount:1,motorPlacement:"front",driveline:{front:Ft.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}},Wg={name:"Stock car",m:1620,A:2.2,cl:.6,cw:.45,frontMass:.53,frontAero:.45,rDyn:.35,drivenWheels:2,gearRatio:4.1,motor:wo(500,2500,9e3,1680,2),motorCount:1,driveline:{rear:Ft.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}},jg={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:wo(330,3e3,8500,1240,2),motorCount:1,driveline:{rear:Ft.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}},Ug={name:"Race truck",m:5300,A:6.2,cl:-.1,cw:.65,frontMass:.6,frontAero:.6,rDyn:.502,drivenWheels:2,gearRatio:3.55,motor:wo(880,100,3e3,88e3,2),motorCount:1,driveline:{rear:Ft.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:110,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 Hg(e,t,r){return tn(r({...structuredClone(e),name:t}))}var ep={[rs.name]:tn(rs),"Formula Student +15% downforce":Hg(rs,"Formula Student +15% downforce",e=>({...e,cl:e.cl*1.15,cw:e.cw*1.08})),"Formula Student -15 kg":Hg(rs,"Formula Student -15 kg",e=>({...e,m:e.m-15})),"Formula Student +15% power":Hg(rs,"Formula Student +15% power",e=>({...e,motor:wA(25*1.15,15e3,2e4),powerLimitKw:80*1.15})),[zg.name]:tn(zg),[Zm.name]:tn(Zm),[Jm.name]:tn(Jm),[Yg.name]:tn(Yg),[Wg.name]:tn(Wg),[jg.name]:tn(jg),[Ug.name]:tn(Ug)},CA=Object.keys(ep),Xg=CA.slice(0,4),qg=[rs.name,zg.name,Zm.name,Jm.name,Yg.name,Wg.name,jg.name,Ug.name];var moe={"Touring car":Zm.name,"Street car":Jm.name};var ZN={bg:"#0e1116",panel:"#161b22",panel2:"#1c232d",border:"#2a323d",borderBright:"#39424e",sunken:"#11161c",ink:"#06090d"},JN={normal:"#d6dde6",dim:"#8b96a3",bright:"#e7ecf3",white:"#ffffff"},eO={label:"#c8d2dc",grid:"#39424e",gridFaint:"#232b35",empty:"#1a2028"},tO={accent:"#4aa3ff",accentInk:"#04121f",warn:"#ffb454",good:"#4ec9a0",bad:"#ff6b6b",badSoft:"#ff8f8f"},rO=["#f0e442","#7b68ee","#f7a8b8","#d55e00","#d8b4fe","#b5e48c"],tp={front:"#a6e22e",rear:"#00b4d8"},TA=["#5b4bd6","#4aa3ff","#4ec9a0","#f0e442"],Qg={power:"#ffb454",traction:"#f0845c",front:tp.front,rear:tp.rear,grip:"#73c9b3",braking:"#b48aff",crest:"#e88fd0",below:"rgba(214, 221, 230, 0.32)"},nO={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"},oO={x:"#ff6b6b",y:"#57c75a",z:"#4aa3ff"},aO={line:"#b4bfcb"},sO={compression:"#b48aff",tension:"#ff6b6b"},iO={fz:"#e7ecf3",fx:"#7ad7f0",fy:"#ff54c8"},cO={drivenLine:"#4d7cff",axis:"#eef3fa",slip:"#ffe81a",drive:Qg.power,brake:Qg.braking},lO={ground:"#101920",grid:"#1a2630",gridMajor:"#26343f",horizon:"#1d2833",bridge:"#6f7a86",coneLeft:"#2f63c9",coneRight:"#d9b51f",coneStart:"#ee7a2c"},uO={chassis:"#435160",volume:"#303b47",tyre:"#435160",tyreLine:"#39424e",tyreFace:"#1c232d"},mO={centreLine:"#4aa3ff",corridorFill:"rgba(74,163,255,0.10)",boundary:"#3d4956",racingLine:"#ffb454",start:"#e7ecf3",finish:"#ff6b6b",direction:"#8b96a3"},pO={SURFACE:ZN,TEXT:JN,CHART:eO,ROLE:tO,SERIES:rO,AXLE:tp,LAP_SPEED:TA,LIMITER:Qg,RIG:nO,AXIS:oO,CONSTRUCTION:aO,FORCE:sO,TYRE_FORCE:iO,REPLAY:cO,SCENERY:lO,BODY:uO,TRACK:mO},PA=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[t,Array.isArray(r)?Object.freeze([...r]):Object.freeze({...r})])),rp=PA(pO),Ct=rp.SERIES,LA=(()=>{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 PA({SURFACE:{bg:"#f4f5f3",panel:"#fbfbfa",panel2:"#ffffff",border:"#d6dadd",borderBright:"#b7bec4",sunken:"#eceeeb",ink:"#ffffff"},TEXT:{normal:"#22272d",dim:"#5c6570",bright:"#0f1215",white:"#000000"},CHART:{label:"#3a424b",grid:"#c2c8cd",gridFaint:"#e2e5e7",empty:"#e8eae7"},ROLE:{accent:"#1a64c2",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:"#15181c",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 DA=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},doe=(()=>{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=rp[r],o=LA[r];for(let a of Object.keys(n)){let s=DA(n[a]);s&&!e.has(s)&&e.set(s,o[a])}}return e})();var EA=(e,t)=>new Set(t.flatMap(r=>{let n=e[r];return Array.isArray(n)?[...n]:Object.values(n)}).map(DA).filter(r=>r!==null)),foe=EA(LA,["SERIES","AXLE","LAP_SPEED","LIMITER","ROLE","RIG","FORCE","TYRE_FORCE","REPLAY","AXIS","TRACK","CONSTRUCTION"]),hoe=EA(rp,Object.keys(rp).filter(e=>e!=="SURFACE"));function Zg(){return{kind:"simple",name:"Simple motor",rpm:[0,16e3,2e4],torque:[21,21,14],efficiency:.95}}function Jg(){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 e0(){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 t0(){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 r0(){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 IA(){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 _A(){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 NA(){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 OA(){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 VA(){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 BA(){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 $A(e){return xo(dO(e))}function dO(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;let t={...e};return delete t.name,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 Rc(e,t){return{...t,fingerprint:$A(e)}}var GA="CC-BY-4.0",fO={title:"PaceDynamics built-in library",url:"https://pacedyn.dev/",licence:GA},KA={fidelity:"generic",licence:GA,sources:[fO]};var np=e=>Rc(e,KA);var HA=["raw.githubusercontent.com"],zA=["tum-csv"],bO=/^[0-9a-f]{64}$/;function kc(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"||!bO.test(r)||!zA.includes(n))return!1;try{let o=new URL(t);return o.protocol==="https:"&&HA.includes(o.hostname)&&!o.username&&!o.password&&!o.port}catch{return!1}}var op=e=>new URL(e.url).hostname;async function YA(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 gO(e){let t=new URL(e).pathname.split("/").pop()??"";return decodeURIComponent(t).replace(/\.[^.]*$/,"")||"Linked track"}function yO(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 xO={"tum-csv":yO};function WA(e,t){return xO[t.format](e,gO(t.url))}async function n0(e,t,r){let n=await YA(e);if(n!==t.sha256)throw new Error(`${op(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=WA(new TextDecoder().decode(e),t),a=await ap(o);if(a!==r)throw new Error(`Linked track ${r} does not convert to its name (it is ${a}).`);return o}var o0=20,vO=new RegExp(`^[0-9a-f]{${o0}}$`),Mc=e=>typeof e=="string"&&vO.test(e);async function ap(e){let t=new TextEncoder().encode(Tn(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,o0)}var a0=e=>`tracks/${e}.json`;var kO=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function s0(e){return{model:{name:e.name,source:e.source},...e.provenance?{provenance:e.provenance}:{}}}async function i0(e,t){if(!kO(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 ap(e);if(r!==t)throw new Error(`Catalogue track ${t} does not match its name (it is ${r}).`);return e}var Co=(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}),Pn=[Co("suspensions","suspensionId","suspension"),Co("tires","tireModelId","tyre",[{key:"tiresRear",ref:"tireModelIdRear",label:"rear tyre"}]),Co("motors","motorModelId","motor"),Co("aeros","aeroModelId","aero map"),Co("batteries","batteryModelId","battery"),Co("brakes","brakeModelId","brakes"),Co("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 sp(e){let t={...e};for(let r of Pn)for(let n of r.refs)delete t[n];return t}var ip=Ct,Sc=ip,c0=ip,Ln=[...Ct.slice(3),...Ct.slice(0,3)],m0=[...Ct.slice(1),Ct[0]],l0=[...Ct.slice(2),...Ct.slice(0,2)],u0=[...Ct.slice(4),...Ct.slice(0,4)],p0=[...Ct.slice(5),...Ct.slice(0,5)],Ac=[...Ct.slice(2),...Ct.slice(0,2)];function d0(){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 f0(e,t,r){let n=ep[e];if(!n)throw new Error(`no preset vehicle named "${e}"`);return{id:t,params:{...Fi(structuredClone(n)),energy:{...Gr},suspensionId:"sus1"},visible:!0,color:Sc[r%Sc.length]}}function AO(){return Xg.map((e,t)=>f0(e,`v${t+1}`,t))}function FO(){return[ni(),Qf(),Zf(),Jf(),eh(),th(),rh(),nh(),oh(),ah()].map((t,r)=>({id:`t${r+1}`,color:c0[r%c0.length],model:t}))}function wO(){return[Ld(),Dd(),Ed(),Id(),_d(),Nd(),Od(),Vd()].map((t,r)=>({id:`a${r+1}`,color:l0[r%l0.length],model:t}))}function CO(){return[bd(),gd(),yd()].map((t,r)=>({id:`b${r+1}`,color:u0[r%u0.length],model:t}))}function TO(){return[{id:"brk1",color:p0[0],model:structuredClone(Sh)}]}function PO(){return[{id:"dmp1",color:Ac[0],model:structuredClone(Nu)}]}function LO(){return[Zg(),Jg()].map((t,r)=>({id:`m${r+1}`,color:Ln[r%Ln.length],model:t}))}function h0(e){let t=r=>({...r,provenance:np(r.model)});return{...e,suspensions:e.suspensions.map(t),vehicles:e.vehicles.map(r=>({...r,provenance:np(sp(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 Fc(e="Untitled project"){let t=new Date().toISOString(),r=AO();return h0({schemaVersion:Wm,meta:{id:d0(),name:e,domain:"racecar",rulesetId:Ro,createdAt:t,updatedAt:t},suspensions:[{id:"sus1",color:m0[0],model:Fo()}],activeSuspensionId:"sus1",vehicles:r,activeVehicleId:r[0]?.id??null,tires:FO(),motors:LO(),aeros:wO(),batteries:CO(),brakes:TO(),dampers:PO(),tracks:[],activeTrackId:null,mathChannels:[],rulesets:[],studies:[],activeStudyId:null,loadCases:[],reportLayouts:[],tyreSheets:[],kinSheets:[],lapSheets:[],plans:[],results:[],settings:{numerics:{...Ki},ggvMode:"twoTrack",quasiTransient:!1,motorThermal:!1,brakeFade:!1,airTempC:Et,air:structuredClone(Um),diffYaw:!1,lapCounts:{},pathPlanId:null,useRacingLine:!0,standingStart:!1}})}var DO=["front","rear"],b0=9.81,EO=Math.PI/180;var Sr="*",g0=40,jA=.8;function y0(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 UA(e,t,r){let n=t.rows.map(c=>c.v),o=c=>yt(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/b0*100)/100+0,axG:Math.round(u/b0*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(g0/3.6,o(g0/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(jA*s,o(jA*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 x0(e,t,r){let n=!1,o=e.map(a=>{if(!a.follows)return a;let s=UA(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 R0(e,t){let r=e.speedKmh/3.6,n=e.ayG*b0;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)/EO}var XA=e=>e.ayG<0?"L":"R";function v0(e,t=DO){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 k0=(e,t)=>e.travelMin===t.travelMin&&e.travelMax===t.travelMax&&e.rollMaxDeg===t.rollMaxDeg&&e.rollAtLimitDeg===t.rollAtLimitDeg;var rn=Math.PI/180,IO=9.81,wc=.1,M0=20,qA=6,eF=50;function QA(e,t,r){let n=e(0),o=0;for(let f=t;f<=r+1e-9;f+=t){let p=e(f);if(p>n)n=p,o=f;else if(f>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 f=0;f<14;f++)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 S0(e,t,r,n,o){let a=o*rn;if(t==="side")return QA(i=>r*e.Fy(r*i*rn,n,a),1,45);let s=t==="drive"?1:-1;return QA(i=>s*e.Fx(s*i,n,a),.02,.6)}function lp(e){let t=e?tu(e)?.gamma:void 0,r=[t?.min,t?.max].filter(o=>o!==void 0&&Number.isFinite(o));if(!r.length)return{lo:-qA,hi:qA,stated:!1};let n=Math.max(...r.map(Math.abs))/rn;return{lo:-n,hi:n,stated:!0}}function _O(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),f=e(u),p=e(m);for(let h=0;h<12;h++)f>p?(c=m,m=u,p=f,u=c-l*(c-i),f=e(u)):(i=u,u=m,f=p,m=i+l*(c-i),p=e(m));let d=f>=p?{g:u,v:f}:{g:m,v:p};return d.v>s?d.g:a}var ZA=250,JA=new WeakMap;function NO(e,t,r,n,o,a,s){let i=JA.get(e);i||JA.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=d=>{let h=l.get(d);if(h===void 0){let b=Math.max(50,d*ZA);h=_O(g=>S0(r,n,o,b,g).force,s.lo,s.hi),l.set(d,h)}return h},m=Math.max(0,a)/ZA,f=Math.floor(m),p=m-f;return p<1e-9?u(f):u(f)*(1-p)+u(f+1)*p}function ns(e,t){return t==="front"?e.tireModel:e.tireModelRear??e.tireModel}var OO=new WeakMap,VO=new WeakMap,BO=new WeakMap,A0=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n};function up(e,t){let r=ns(e,t);return r?A0(OO,r,()=>qs(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 F0(e,t){let r=ns(e,t);return r?A0(BO,r,()=>ru(r).none)?"This tyre file has no drive or brake grip.":A0(VO,r,()=>{let n=De(r),o=r.kind==="magic"?r.fnomin:r.nominalLoad,a=n.Fx(.1,o,0),s=n.Fx(.1,o,3*rn);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 To(e,t){return e==="side"||e==="ackermann"?Math.abs(t.ayG)>=wc?e==="ackermann"&&!(tF(t)<=M0)?`is a corner wider than ${M0} m`:null:"does not corner":(e==="drive"?t.axG:-t.axG)>=wc?null:e==="drive"?"does not drive":"does not brake"}var $O=e=>e.axG>=wc?"drive":e.axG<=-wc?"brake":null;function tF(e){let t=e.speedKmh/3.6,r=Math.abs(e.ayG)*IO;return r>1e-9?t*t/r:1/0}var cp=(e,t)=>`${e==="front"?"F":"R"}${t}`,GO=e=>e==="L"?"R":"L",KO=(e,t,r)=>Math.min(r,Math.max(t,e));function w0({ev:e,params:t,input:r,state:n,pose:o}){let a=`${Q(t,"grip_scale")}|${Q(t,"stiffness_scale")}`,s=tF(n),i=r.wheelbase*(1-r.frontMassFrac)/1e3,c=r.wheelbase*r.frontMassFrac/1e3,l=r.wheelbase/1e3,u=k=>(k==="front"?r.trackFront:r.trackRear)/2e3,m=(k,v,x,M,A)=>{let w=ye(e,k),T=ns(t,k),P=Math.max(0,o.loads[v]),S=o.camber[v],F=KO(S,A.lo,A.hi),C=S0(w,x,M,P,F),L=P<eF,E=T&&!L?NO(T,a,w,x,M,P,A):F,D=L?C.force:S0(w,x,M,P,E).force,N=.05;return{corner:v,Fz:P,lifted:L,camber:S,read:F,outside:F!==S,wants:E,atEdge:!L&&(E-A.lo<N||A.hi-E<N),peak:C.force,slip:C.at,best:D}},f=(k,v,x)=>{let M=v[0].best+v[1].best,A=v[0].peak+v[1].peak;return{kind:k,wheels:v,lossCamber:M>0?Math.max(0,1-A/M):NaN,range:x}},p=new Map,d=k=>{if(p.has(k))return p.get(k)??null;let v=null;if(!To("side",n)){let x=lp(ns(t,k));v=[m(k,cp(k,o.outer),"side",1,x),m(k,cp(k,GO(o.outer)),"side",-1,x)]}return p.set(k,v),v},h=new Map,b=new Map,g=new Map,y=(k,v,x)=>{let M=k==="front"?i:-c,A=(v?1:-1)*u(k),w=x*rn;return Math.atan2(M+s*Math.sin(w),s*Math.cos(w)-A)/rn},R=k=>(n.ayG<0?-1:1)*o.steer[k];return{side(k){if(h.has(k))return h.get(k)??null;let v=up(t,k)?null:d(k),x=v?f("side",v,lp(ns(t,k))):null;return h.set(k,x),x},long(k){if(b.has(k))return b.get(k)??null;let v=$O(n),x=null;if(v&&!F0(t,k)){let M=lp(ns(t,k));x=f(v,[m(k,cp(k,"L"),v,1,M),m(k,cp(k,"R"),v,1,M)],M)}return b.set(k,x),x},toeLoss(k){let v=g.get(k);if(v!==void 0)return v;let x=d(k),M=NaN;if(x&&x[0].peak+x[1].peak>0){let A=ye(e,k),[w,T]=x,P=[{g:w,dt:1,inner:!1,steer:R(w.corner)},{g:T,dt:-1,inner:!0,steer:R(T.corner)}],S=D=>P.reduce((N,O)=>{let z=O.steer-y(k,O.inner,D);return N+O.dt*A.Fy(O.dt*z*rn,O.g.Fz,O.g.read*rn)},0),F=P.map(D=>D.steer-D.g.slip-y(k,D.inner,0)),C=Math.min(...F)-2,L=Math.max(...F)+2,E=HO(S,C,L,.25);M=Math.max(0,1-E/(w.peak+T.peak))}return g.set(k,M),M},ackermann(){if(To("ackermann",n))return NaN;let k=d("front");if(!k||k[0].lifted||k[1].lifted)return NaN;let[v,x]=k,M=Math.sqrt(Math.max(s*s-c*c,1e-6)),A=u("front"),w=(Math.atan(l/(M-A))-Math.atan(l/(M+A)))/rn;if(!(w>.001))return NaN;let T=R(x.corner)-R(v.corner),P=w+(x.slip-v.slip);return 100*(T-P)/w}}}function HO(e,t,r,n){let o=-1/0,a=t;for(let p=t;p<=r+1e-9;p+=n){let d=e(p);d>o&&(o=d,a=p)}let s=a-n,i=a+n,c=.6180339887498949,l=i-c*(i-s),u=s+c*(i-s),m=e(l),f=e(u);for(let p=0;p<14;p++)m>f?(i=u,u=l,f=m,l=i-c*(i-s),m=e(l)):(s=l,l=u,m=f,u=s+c*(i-s),f=e(u));return Math.max(o,m,f)}var zO=9.81,rF=Math.PI/180,Cc={speed:20,ayG:1.2};function C0(e,t={}){let r=t.operating??Cc,n=t.assemble,o,a,s,i=new Map,c=new Map,l=new Map,u=new Map,m=new Map,f=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}),p=()=>{if(o!==void 0)return o;if(!n)return o=null;try{o=n(e)}catch{o=null}return o},d=()=>{if(a!==void 0)return a;try{a=xr(e.params)}catch{a=null}return a},h=v=>{let x=f(v),M=`${x.speed}|${x.ayG}`,A=i.get(M);if(A!==void 0)return A;let w=d();if(!w)return i.set(M,null),null;let T={cornerStiffness:P=>w.corneringStiffness(P),ayG:x.ayG,speed:x.speed,fyAxle:(P,S)=>2*w.Fy(P,S/2),tire:w};return i.set(M,T),T},b=()=>{if(s!==void 0)return s;let v=p(),x=d();if(!v||!x)return s=null;try{s=no(x,v.massTotal*zO*1.2)}catch{s=null}return s},g=v=>{let x=f(v).speed,M=`${x}`,A=c.get(M);if(A!==void 0)return A;let w=p(),T=d(),P=null;if(w&&T)try{P=Rb(w,T,x,{steering:!1})}catch{P=null}return c.set(M,P),P},y=v=>{let x=`${v.speedKmh}|${v.ayG}|${v.axG}`,M=m.get(x);if(M!==void 0)return M;let A=null,w=p();try{let T=w?.kinFront,P=w?.kinRear;if(w&&T&&P){let S=R0(v,w.wheelbase),F=v.speedKmh/3.6,C=gn(w,T,P,F)(v.ayG,v.axG,0,S),L={FL:C.FL.travel,FR:C.FR.travel},E=ao(w,S*rF,L),D=S?E.camber:null,N={},O={};for(let I of["FL","FR","RL","RR"]){let _=I[1]==="R"?C[I].camberRoad:0-C[I].camberRoad;N[I]=_+(D?.[I]??0),O[I]=E.steer[I]/rF+(I[1]==="R"?1:-1)*C[I].bumpToe}let z=Pe(w,v.ayG,v.axG,F,0,S,L,C.steeringJacking);A={corners:C,rollDeg:C.FL.camberRoad-C.FL.camber,steerDeg:S,camber:N,outer:XA(v),loads:z,steer:O}}}catch{A=null}return m.set(x,A),A},R=new Map;return{operating:r,dynAvailable:!!n,poseAt:y,tyreAt:v=>{let x=`${v.speedKmh}|${v.ayG}|${v.axG}`,M=R.get(x);if(M!==void 0)return M;let A=y(v),w=p(),T=d(),P=A&&w&&T?w0({ev:T,params:e.params,input:w,state:v,pose:A}):null;return R.set(x,P),P},operatingAt:f,dynInput:p,tyre:d,dynCtx:h,grip:b,ymd:g,ymdLimit:v=>{let x=`${f(v).speed}`,M=l.get(x);if(M!==void 0)return M;let A=g(v),w=A?Qb(A):null;return l.set(x,w),w},reserves:(v,x)=>{let M=f(x),A=`${v}|${M.speed}|${M.ayG}`,w=u.get(A);if(w!==void 0)return w;let T=p(),P=h(x),S=null;if(T&&P)try{S=Ui(T,P,v,b()??void 0)}catch{S=null}return u.set(A,S),S}}}var nF=["widthLeft","widthRight","bank","mu"];function Tc(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 T0(e){let t=Tc(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 pp(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 f of nF){let p=l[f];if(p===void 0)continue;let d=s[f],h=r[f];for(let b=0;b<o&&t[b]<l.from;b++)h=d[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;d[b]=u>0&&y<u?h+(p-h)*(y/u):p}}}return s}function dp(e,t,r){if(!t.length)return e;let n=Tc(e),o=n.length,a={widthLeft:mp(e.widthLeft,r.widthLeft),widthRight:mp(e.widthRight,r.widthRight),bank:mp(e.bank,r.bank),mu:mp(e.mu,r.mu)},s={};for(let c of nF){let l=e[c];Array.isArray(l)&&l.length===o&&(s[c]=l)}let i=pp(t,n,a,s);return{...e,...i}}function mp(e,t){return typeof e=="number"?e:t}var sF=1,oF=4,hp=Math.PI/180,P0=e=>e===null||!Number.isFinite(e)||e===0?0:1/e;function L0(e){return e.kind==="arc"?Math.abs(e.radius)*Math.abs(e.angle)*hp:e.length}function fp(e,t){return e.kind==="straight"?0:e.kind==="arc"?P0(e.radius):t}function aF(e){return e.kind==="straight"?0:e.kind==="arc"?P0(e.radius):P0(e.endRadius)}var Pc=(e,t,r,n,o)=>e+t*o+(n>0?(r-t)*o*o/(2*n):0);function Lc(e,t={}){let r=Math.max(.05,t.spacing??sF),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((S,F)=>S+L0(F),0),m=Math.max(n?3:2,Math.round(u/r)),f=u>0?u/m:r,p=o.x,d=o.y,h=o.heading*hp,b=e.length?fp(e[0],0):0,g=0,y=f,R=(S,F,C)=>{s.push(S),i.push(F),c.push(C)};R(p,d,0);let k=(S,F,C,L,E)=>{let D=E-L;if(D<=0)return;if(Math.abs(F-S)<1e-12){let O=Pc(h,S,S,C,L);if(Math.abs(S)<1e-12)p+=D*Math.cos(O),d+=D*Math.sin(O);else{let z=O+S*D;p+=(Math.sin(z)-Math.sin(O))/S,d+=-(Math.cos(z)-Math.cos(O))/S}return}let N=D/oF;for(let O=0;O<oF;O++){let z=L+O*N,I=Pc(h,S,F,C,z),_=Pc(h,S,F,C,z+N/2),B=Pc(h,S,F,C,z+N);p+=N/6*(Math.cos(I)+4*Math.cos(_)+Math.cos(B)),d+=N/6*(Math.sin(I)+4*Math.sin(_)+Math.sin(B))}};for(let S of e){let F=L0(S),C=fp(S,b),L=aF(S);if(l.push({from:g,to:g+F,...S.widthLeft!==void 0?{widthLeft:S.widthLeft}:{},...S.widthRight!==void 0?{widthRight:S.widthRight}:{},...S.bank!==void 0?{bank:S.bank}:{},...S.mu!==void 0?{mu:S.mu}:{},...S.ramp!==void 0?{ramp:S.ramp}:{}}),F<=0){b=L;continue}let E=0;for(;y<=g+F+1e-9;){let D=Math.min(F,y-g);k(C,L,F,E,D),E=D,R(p,d,g+D),y+=f}k(C,L,F,E,F),h=Pc(h,C,L,F,F),b=L,g+=F}let v=s.length>1?Math.hypot(s[0]-s[s.length-1],i[0]-i[i.length-1]):0,x=g;n&&s.length>1&&(s.pop(),i.pop(),c.pop());let M=e.length?fp(e[0],b):0,A={gap:v,headingError:YO((h-o.heading*hp)/hp),curvatureError:b-M},w=[];for(let S=0;S<e.length;S++){let F=aF(e[S]),C=S+1<e.length?e[S+1]:n?e[0]:null;if(!C)continue;let L=fp(C,F);w.push({index:S,before:F,after:L,jump:Math.abs(L-F)})}let T=pp(l,c,a);return{asset:{name:t.name??"Track",x:s,y:i,fit:"interpolate",...n?{}:{closed:!1},...T},sections:l,joints:w,closure:A,length:x}}function YO(e){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t}var WO={halfWidthM:1.5,spacingM:.5};function Dc(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 ${cF(e).toFixed(0)} m`}}}function cF(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 lF=e=>e.kind==="skidpad"||e.kind==="curves"&&e.closed===!0,uF=e=>e.kind==="acceleration",mF=1.5,pF=3;function jO(e,t){let r=e.offsetM,n=e.pitchM,o=Math.max(1,e.gates)*n,a=Math.max(0,e.leadInM),s=mF*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*(pF*Math.PI/180))):t.spacingM,m=[],f=[],p=Math.max(1,Math.round(a/u));for(let h=0;h<p;h++)m.push(-a+a*h/p),f.push(0);let d=Math.max(8,Math.round(o/u));for(let h=0;h<=d;h++){let b=o*h/d;m.push(b),f.push(r*c(b)*Math.sin(Math.PI*b/n))}return{name:Dc(e),x:m,y:f,closed:!1,widthLeft:t.halfWidthM,widthRight:t.halfWidthM,fit:"interpolate"}}function UO(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 D0(e,t={}){let r={...WO,...t},n=uF(e),o=UO(e);if(!o){let u=jO(e,r);return{asset:u,peakCurvature:iF(u),worstJoint:0,standingStart:n}}let a=lF(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*(pF*Math.PI/180))):r.spacingM,c=Lc(o,{name:Dc(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:iF(c.asset),worstJoint:l.reduce((u,m)=>Math.max(u,m.jump),0),standingStart:n}}function iF(e){try{return Math.max(...mt(e).curvature.map(Math.abs))}catch{return NaN}}var gp={courses:[{id:"c1",course:{kind:"manoeuvre",spec:{kind:"skidpad",radiusM:8.375}}}],ggvMode:"twoTrack"};function E0(e){return e.course.kind==="project"?"the project\u2019s track":e.course.kind==="track"?e.course.name:Dc(e.course.spec)}var dF=new WeakMap,bp=new Map;function fF(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=bp.get(n);if(o)return{...o,numerics:r};let a=D0(e.spec),s={asset:a.asset,standingStart:a.standingStart};return bp.size>64&&bp.clear(),bp.set(n,s),{...s,numerics:r}}function I0(e,t,r={}){let n=r.lap??gp,o=r.simParams,a=r.numerics??{},s=n.courses.length?n.courses:gp.courses,i,c,l,u=new Map,m=new Map,f=new Map,p=new Map,d=k=>(k?.courseId?s.find(v=>v.id===k.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=k=>{let v=d(k);if(!v)return null;let x=m.get(v.id);if(x!==void 0)return x;let M=fF(v.course,r,a),A=null;if(M)try{let w=JSON.stringify(M.numerics),T=dF.get(M.asset);T||(T=new Map,dF.set(M.asset,T));let P=T.get(w);P||(P=mt(M.asset,M.numerics),T.set(w,P)),A={id:v.id,track:P,standingStart:M.standingStart,numerics:M.numerics,name:M.asset.name}}catch{A=null}return m.set(v.id,A),A},g=()=>{if(c!==void 0)return c;let k=h();if(!k)return c=null;try{l=It(k),c=Rr(l,!1,n.ggvMode)}catch{c=null}return c},y=k=>{let v=b(k);if(!v)return null;let x=f.get(v.id);if(x!==void 0)return x;let M=g(),A=null;if(M)try{let w=l?bo(l,M,[v.track],v.numerics,n.ggvMode,u):void 0,T=l?wn(l,M.rows):void 0;A=wt(M,v.track,v.numerics,{standingStart:v.standingStart,...w?{load:w}:{},...T?{shifts:T}:{}})}catch{A=null}return f.set(v.id,A),A};return{lapSettings:n,get lapAvailable(){return!!o&&s.some(k=>!!fF(k.course,r,a))},lapParams:h,courses:()=>s,course:b,ggv:g,lap:y,lapReserve:k=>{let v=b(k);if(!v)return null;let x=p.get(v.id);if(x!==void 0)return x;let M=y(k),A=t.dynInput(),w=t.tyre(),T=null;if(M&&A&&w)try{let P=h();T=km(A,w,{v:M.v,ax:M.ax,ay:M.ay,ds:v.track.ds,axDrag:Ua(g()?.rows,M.v),...M.axScrub?{axScrub:M.axScrub}:{},axGrade:Fn(v.track.gradient,M.v.length),bank:v.track.bank,...M.loadFactor?{loadFactor:M.loadFactor}:{},...v.track.mu.some(S=>S!==1)?{mu:v.track.mu}:{}},P?{driven:Bh(P)}:{})}catch{T=null}return p.set(v.id,T),T}}}var hF=180/Math.PI,_0={rise:0,sinPitch:0,sinRoll:0};function bF(e){let t=e.kc;return t?gF(e.vehicle,r=>t.ground0[r]):_0}function gF(e,t){let r=e.config,n=pn(r),o=0,a=0,s=0,i=0,c=0,l=0,u=0,m=0,f=0;for(let g of lr){let y=ze(g,r),R=y.axleX-n,k=y.sideSign*Ht(e,y.isFront)/2,v=t(g);if(!Number.isFinite(v))return _0;o++,a+=R,s+=k,i+=v,c+=R*R,l+=k*k,u+=R*k,m+=R*v,f+=k*v}let p=o*(c*l-u*u)-a*(a*l-u*s)+s*(a*u-c*s);if(!(Math.abs(p)>1e-9))return{rise:i/o,sinPitch:0,sinRoll:0};let d=(i*(c*l-u*u)-a*(m*l-u*f)+s*(m*u-c*f))/p,h=(o*(m*l-u*f)-i*(a*l-u*s)+s*(a*f-m*s))/p,b=(o*(c*f-m*u)-a*(a*f-m*s)+i*(a*u-c*s))/p;return{rise:d,sinPitch:h,sinRoll:-b}}function Ec(e,t){let r=e.kc,n=gF(e.vehicle,o=>(r?r.ground0[o]:0)+t[o]);return q([-n.sinPitch,n.sinRoll,1])}function N0(e,t,r,n){let o=q(Lr(e,ze(t,r)));return-Math.asin(Math.max(-1,Math.min(1,X(o,n))))*hF}function yp(e,t,r,n,o){let a=q(Lr(n,ze(t,r))),s=q([1-a[0]*a[0],-a[0]*a[1],-a[0]*a[2]]),i=ae(a,s),c=p=>[X(p,s),X(p,i),X(p,a)],l=p=>te(te(U(s,p[0]),U(i,p[1])),U(a,p[2])),u=e.points,m=c(u.spinAxis),f=ws({uprightUpper:c(u.uprightUpper),uprightLower:c(u.uprightLower),wheelCenter:c(u.wheelCenter),spinAxis:m,tieOuter:c(u.tieOuter),loadedRadius:o.loadedRadius,patchShift:o.patchShift&&XO(o.patchShift,e.metrics.toe/hF,Math.atan2(m[0],m[1]))});return{caster:f.caster,kpi:f.kpi,scrubRadius:f.scrubRadius,mechanicalTrail:f.mechanicalTrail,scrubAtWheel:f.scrubAtWheel,trailAtWheel:f.trailAtWheel,kingpinOffset:f.kingpinOffset,casterOffset:f.casterOffset,kingpinGround:l(f.kingpinGround),contactPatch:l(f.contactPatch),elbow:l([f.contactPatch[0],f.kingpinGround[1],f.kingpinGround[2]]),kingpinAtHub:l(f.kingpinAtHub)}}function XO(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 xp(e,t){let r=bF(t);if(r===_0)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 Dn(e,t,r){let n=xp({heave:0,pitch:0,roll:0,steer:0},r);return e-Zd(n,[t,0,0],pn(r.vehicle.config))}var qO=180/Math.PI;function O0(e,t){return!e.valid||!e.ic?!1:Math.hypot(e.ic[0]-e.cp[0],e.ic[1]-e.cp[1])<=t}function Rp(e,t,r){let n=ze(t,e.vehicle.config),o=Mt(e,r),a=Hu(e,t,o[t]),s=a.at("uprightUpper"),i=a.at("uprightLower"),c=a.at("contactPatch"),l=a.at("wheelCenter"),u=F=>{let C=a.velocity(F);return[C[0],C[2]]},m=u(c),f=u(l),p=[c[0],c[2]],d=[l[0],l[2]];if(!a.solved)return{ic:null,line:null,cp:p,wc:d,road:[1,0],swingArmAngleDeg:NaN,tanTheta:NaN,tanThetaHub:NaN,valid:!1,unsolved:!0,sinAngle:0};let h=Ec(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]],R=F=>{let C=F[0]*g[0]+F[1]*g[1];return Math.abs(C)>1e-9?-(F[0]*y[0]+F[1]*y[1])/C:0},k=a.omega[1],v=Math.hypot(m[0],m[1]),x=Math.abs(k)*1e9>v?[p[0]+m[1]/k,p[1]-m[0]/k]:null,A=x?(F=>{let C=[s[0]-F[0],s[2]-F[1]],L=[i[0]-F[0],i[2]-F[1]];return Math.abs(C[0]*L[1]-C[1]*L[0])/(Math.hypot(...C)*Math.hypot(...L))})(x):0;if(!(Math.abs(m[0]*g[0]+m[1]*g[1])>1e-9))return{ic:x,line:null,cp:p,wc:d,road:y,swingArmAngleDeg:0,tanTheta:0,tanThetaHub:0,valid:!1,sinAngle:A};let w=[m[1]/v,-m[0]/v],T=x?[x[0]-p[0],x[1]-p[1]]:[n.isFront?-1:1,0],P=w[0]*T[0]+w[1]*T[1]<0?[-w[0],-w[1]]:w,S=R(m);return{ic:x,line:P,cp:p,wc:d,road:y,swingArmAngleDeg:Math.atan(S)*qO,tanTheta:S,tanThetaHub:R(f),valid:!0,sinAngle:A}}function yF(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}}var ZO=180/Math.PI,JO=Math.PI/180,V0=.5,vp=2,B0=.25,eV={heave:0,pitch:0,roll:0,steer:0},tV={FL:"FR",FR:"FL",RL:"RR",RR:"RL"},kp=e=>e.ok?e.state:{...e.nearest,converged:!1};function $0(e,t,r){return t.state?t.solved===!1?{...t.state,converged:!1}:t.state:kp(ge(e,t.travel,t.steer,void 0,r))}var xF=new WeakMap;function RF(e,t){let r=e.ctx[t],n=Ve(e.vehicle,t).config.loadedRadius,o=zt(n,e.kc,t),a=xF.get(r);a||(a=new Map,xF.set(r,a));let s=a.get(o);if(!s){let i=dn(t,e.vehicle.config,eV,e.vehicle);s=kp(ge(r,i.travel,i.steer,void 0,o===n?void 0:{loadedRadius:o})),a.set(o,s)}return s}var Ar=(e,t)=>!e||!e.lo.converged||!e.hi.converged?NaN:(t(e.hi)-t(e.lo))/(2*e.step),vF=(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 MF(e,t,r,n,o){let a=e.vehicle.config,s=na(r),i=Ve(e.vehicle,r),c=ze(r,a),l=e.ctx[r],u=Mt(e,t),m=u[r],f={travel:m.travel,steer:m.steer},p=m.rigid?void 0:{loadedRadius:m.loadedRadius},d=$0(l,m,p),h=RF(e,r),b={lo:kp(ge(l,f.travel-V0,f.steer,void 0,p)),hi:kp(ge(l,f.travel+V0,f.steer,void 0,p)),step:V0},g=c.isFront?{lo:Oe(l,d.beta,f.steer-vp,void 0,p),hi:Oe(l,d.beta,f.steer+vp,void 0,p),step:vp}:null,y=W=>{let J=Mt(e,{...t,roll:t.roll+W*JO})[r];return $0(l,J,J.rigid?void 0:{loadedRadius:J.loadedRadius})},R={lo:y(-B0),hi:y(B0),step:B0},k=nV(e,t,r,c.isFront,u,g),v=Lt(d.points.contactPatch,c),x=Lt(h.points.contactPatch,c),M=Math.abs(v[1])-Math.abs(x[1]),A=tV[r],w=u[A],T=$0(e.ctx[A],w,w.rigid?void 0:{loadedRadius:w.loadedRadius}),P=T.converged?M+Math.abs(T.points.contactPatch[1])-Math.abs(RF(e,A).points.contactPatch[1]):NaN,S=o??gr(e,t,s),F=zu(S,kt(i)),C=F?null:Yk(S),L=c.sideSign>0?S.icRight:S.icLeft,E=L?Math.hypot(L[0]-v[1],L[1]-v[2]):1/0,D=Rp(e,r,t),N=D.ic?Math.hypot(D.ic[0]-D.cp[0],D.ic[1]-D.cp[1]):1/0,O=yF(D,s,a.wheelbase,n),z=-Ar(b,W=>W.points.damperLength),I=i.config.springRate,_=Ar(R,W=>W.metrics.camber),B=Ec(e,{FL:u.FL.ground,FR:u.FR.ground,RL:u.RL.ground,RR:u.RR.ground}),V=e.kc?.loadCase,G=W=>V?yp(W,r,a,B,{loadedRadius:m.loadedRadius,patchShift:V.patchShift[r]}):W.metrics,H=G(d);return{id:r,converged:d.converged,travel:d.travel,camber:d.metrics.camber,camberRoad:N0(d.points.spinAxis,r,a,B),toe:d.metrics.toe,caster:H.caster,kpi:H.kpi,scrubRadius:H.scrubRadius,mechanicalTrail:H.mechanicalTrail,scrubAtWheel:H.scrubAtWheel,trailAtWheel:H.trailAtWheel,kingpinOffset:H.kingpinOffset,casterOffset:H.casterOffset,steeringArm:d.metrics.steeringArm,camberGain:Ar(b,W=>W.metrics.camber),bumpSteer:Ar(b,W=>W.metrics.toe),trackScrubRate:Ar(b,W=>Math.abs(Lt(W.points.contactPatch,c)[1])),casterGain:Ar(b,W=>G(W).caster),kpiGain:Ar(b,W=>G(W).kpi),scrubGain:Ar(b,W=>G(W).scrubRadius),trailGain:Ar(b,W=>G(W).mechanicalTrail),...c.isFront?{camberPerSteer:vF(g,W=>W.metrics.camber,W=>W.metrics.toe),steerJacking:-vF(g,W=>W.points.contactPatch[2],W=>W.metrics.toe),...k!==void 0?{steerLoad:k}:{}}:{},rollCamber:_,camberRecovery:-100*c.sideSign*_,rollSteer:c.sideSign*Ar(R,W=>W.metrics.toe),halfTrackChange:M,trackChange:P,longitudinal:v[0]-x[0],rollCentreHeight:C?C.heightAboveGround:S.heightAboveGround,rollCentreHeightChassis:(C?C.height:S.height)-Dn(0,c.axleX,e),rollCentreLateral:S.lateralAlongGround,rollCentreValid:S.valid,rollCentreUsable:F,rollCentreHeightUsable:F||C!==null,rollCentreSinAngle:S.sinAngle,fvsaLength:E,svsaLength:N,swingArmAngle:D.swingArmAngleDeg,svsaUsable:O0(D,a.wheelbase),svsaSinAngle:D.sinAngle,...s==="front"?{antiDive:O.brake,antiLift:O.drive}:{antiSquat:O.drive,antiLift:O.brake},decoupled:i.config.actuation==="decoupled",mcpherson:i.config.layout==="mcpherson",springRate:I,motionRatio:z,wheelRate:I*z*z,damperLength:d.points.damperLength,damperTravel:h.points.damperLength-d.points.damperLength,...rV(i,h.points.damperLength,d.points.damperLength,e.kc?.curve[r].spring?.law),rockerAngle:i.config.actuation==="direct"?0:(d.points.rockerAngle-h.points.rockerAngle)*ZO,groundDisplacement:m.rigid?d.travel:m.ground,tyreDeflection:m.tyreDeflection,wheelLoad:m.load,loadedRadiusAt:m.loadedRadius,rideRate:m.rideRate,wheelRateAtLoad:m.wheelRateAtLoad,lifted:m.lifted,clearance:m.clearance??0,tyreRigid:m.rigid}}function rV(e,t,r,n){if(e.config.actuation==="decoupled")return{};let o=n?{droop:n.droopStated?n.droop:null,bump:n.bump}:aa(t,e.config.coilover),a=t-r;return{...o.droop!==null?{damperToExtended:a-o.droop}:{},...o.bump!==null?{damperToClosed:o.bump-a}:{}}}function nV(e,t,r,n,o,a){if(!a||!n)return;let s=Dl(e,t,"front"),i=e.kc;if(!s||!i)return;let c=["FL","FR"],l=[0,0],u=[0,0],m={lo:[],hi:[]},f=0;for(let h=0;h<2;h++){let b=c[h],g=o[b],y=e.ctx[b],R=g.rigid?void 0:{loadedRadius:g.loadedRadius},x=(b==="FR"?1:-1)*(r==="FR"?1:-1)*vp,M=g.state?{q:[...g.state.pose.t,...g.state.pose.omega],phi:g.state.points.rockerAngle}:void 0,A=bt(ge(y,g.travel,g.steer-x,M,R)),w=bt(ge(y,g.travel,g.steer+x,M,R));if(!A||!w)return NaN;l[h]=w.points.contactPatch[2]-A.points.contactPatch[2],u[h]=Dr(i.curve[b],g.travel,w.points.damperLength)-Dr(i.curve[b],g.travel,A.points.damperLength),m.lo.push(A),m.hi.push(w),b===r&&(f=w.metrics.toe-A.metrics.toe)}let p=i.elements?.front;if(p){let h=[o.FL.travel,o.FR.travel],b=Vs(p,h,[m.hi[0],m.hi[1]]),g=Vs(p,h,[m.lo[0],m.lo[1]]);u[0]+=b[0]-g[0],u[1]+=b[1]-g[1]}return Math.abs(f)>1e-9?s([0,0],l,u)[r==="FL"?0:1]/f:NaN}function Ic(e,t,r,n,o){return MF(e,t,r==="front"?"FL":"RL",n,o)}function G0(e,t,r,n){let o=Ic(e,t,"front",r,n?.front),a=Ic(e,t,"rear",r,n?.rear);return{front:o,rear:a,wheelbaseChange:o.longitudinal-a.longitudinal}}function Mp(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),Dn(Math.min(n.zMin,n.zMax),i,t)],max:[s,Math.max(n.yMin,n.yMax),Dn(Math.max(n.zMin,n.zMax),i,t)]}})}var Po=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],Ut=(e,t)=>[e[0]+t[0],e[1]+t[1],e[2]+t[2]],at=(e,t)=>[e[0]*t,e[1]*t,e[2]*t],tr=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],_c=e=>Math.sqrt(tr(e,e));function oV(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 aV(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=>tr(r,e)>=tr(r,t)?e:t,samples:()=>Array.from({length:41},(r,n)=>Ut(e,at(Po(t,e),n/40)))}}function sV(e,t,r,n){let o=at(t,1/(_c(t)||1)),a=n/2,s=o.map(i=>r*Math.sqrt(Math.max(0,1-i*i))+a*Math.abs(i));return{min:Po(e,s),max:Ut(e,s),support:i=>{let c=tr(i,o),l=Po(i,at(o,c)),u=_c(l),m=u>1e-12?at(l,r/u):[0,0,0];return Ut(Ut(e,at(o,c>=0?a:-a)),m)},samples:()=>{let i=Math.abs(o[0])<.9?[1,0,0]:[0,1,0],c=Po(i,at(o,tr(i,o))),l=at(c,1/_c(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 f of[-1,-.5,0,.5,1]){let p=Ut(e,at(o,f*a));m.push(p);let d=Math.abs(f)===1?[.5,1]:[1];for(let h of d)for(let b=0;b<72;b++){let g=b/72*2*Math.PI;m.push(Ut(p,Ut(at(l,h*r*Math.cos(g)),at(u,h*r*Math.sin(g)))))}}return m}}}function iV(e){let t=e[0],r=e.slice(1).map(c=>Po(c,t)),n=r.length;if(n===0)return{v:t,w:[1]};let o=r.map(c=>r.map(l=>tr(c,l))),a=r.map(c=>-tr(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 f=c;f<n;f++)o[u][f]-=m*o[c][f];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=Ut(i,at(r[c],s[c]));return{v:i,w:[1-s.reduce((c,l)=>c+l,0),...s]}}function cV(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=iV(a.map(c=>c.w));if(!s||s.w.some(c=>c<-1e-9))continue;let i=tr(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 lV(e,t){let r=s=>{let i=e.support(s),c=t.support(at(s,-1));return{w:Po(i,c),a:i,b:c}},n=(s,i)=>{let c=[0,0,0],l=[0,0,0];return s.keep.forEach((u,m)=>{c=Ut(c,at(u.a,s.weights[m])),l=Ut(l,at(u.b,s.weights[m]))}),{distance:i,onA:c,onB:l}},o=r([1,0,0]),a={v:o.w,keep:[o],weights:[1]};for(let s=0;s<64;s++){let i=a.v,c=tr(i,i);if(c<1e-12)return n(a,0);let l=r(at(i,-1));if(c-tr(i,l.w)<=1e-9*Math.max(1,c))return n(a,Math.sqrt(c));let u=cV([...a.keep,l]);if(u.keep.length===4)return n(u,0);if(tr(u.v,u.v)>=c-1e-12)return n(a,Math.sqrt(c));a=u}return n(a,_c(a.v))}function uV(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 mV(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 FF={linkRadius:8,mountAllowance:15},pV=(e,t,r)=>e.z0+e.dzdx*t+e.dzdy*r;function dV(e,t){let r=Math.sin(e.pitch);return{z0:-e.heave+t*r,dzdx:-r,dzdy:Math.sin(e.roll)}}function wF(e){return dV(xp({heave:0,pitch:0,roll:0,steer:0},e),pn(e.vehicle.config))}var fV=[{name:"upper wishbone, front leg",inboard:"ucaFront",outboard:"uprightUpper"},{name:"upper wishbone, rear leg",inboard:"ucaRear",outboard:"uprightUpper"},{name:"lower wishbone, front leg",inboard:"lcaFront",outboard:"uprightLower"},{name:"lower wishbone, rear leg",inboard:"lcaRear",outboard:"uprightLower"},{name:"tie rod",inboard:"tieInner",outboard:"tieOuter"},{name:"pushrod",inboard:"rockerToPushrod",outboard:"pushrodOuter"},{name:"strut",inboard:"damperChassis",outboard:"pushrodOuter"}];function hV(e){return fV.filter(t=>t.name==="strut"?e.mcpherson:t.name==="pushrod"?!e.direct:!(e.mcpherson&&t.name.startsWith("upper")))}var bV=(e,t,r)=>e.every((n,o)=>n>=t.min[o]-r&&n<=t.max[o]+r);function SF(e,t,r){let n=Po(t,e),o=_c(n);return o>1e-9?Ut(e,at(n,r/o)):e}function AF(e,t){let r=null;for(let{shape:n,pad:o,part:a,pose:s}of t){if(r&&mV(e,n)-o>=r.distance)continue;let i=lV(e,n),c=i.distance>0?null:uV(e,n),l=i.distance>0?i.distance-o:-((c?.depth??0)+o);if(Number.isFinite(l)&&(!r||l<r.distance)){let u=i.distance>0?{part:SF(i.onB,i.onA,o),box:i.onA}:c?{part:SF(c.point,c.face,-o),box:c.face}:{part:i.onB,box:i.onA};r={distance:l,part:a,corner:s.corner,travel:s.travel,rack:s.rack,gap:u}}}return r}function gV(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:at(a.reduce((c,l)=>Ut(c,l),[0,0,0]),1/a.length)}}function CF(e,t){return{...gV(e,r=>r[2]-pV(t,r[0],r[1])),road:t}}function TF(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 yV(e,t){let r=e.map(o=>({pose:o,part:`${o.corner} tyre`,pad:0,shape:sV(o.g.wheelCenter,o.g.spinAxis,o.corner[0]==="F"?t.tyreRadius.front:t.tyreRadius.rear,t.tyreWidth)})),n=e.flatMap(o=>hV(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:aV(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 xV(e,t,r){let n=oV(e.min,e.max),o=t.links.filter(a=>!bV(a.inboard,e,r.mountAllowance+r.linkRadius));return{tyre:AF(n,t.tyres),link:AF(n,o)}}function PF(e,t,r){let n=yV(t,r);return e.map(o=>({boxId:o.id,...xV(o,n,r)}))}var NF=152,OF={travelSteps:9,rackSteps:5},Lo=(e,t)=>[e[0]-t[0],e[1]-t[1],e[2]-t[2]],nn=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],Nc=(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]],rr=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]},VF=180/Math.PI,RV=[[1,0,0],[0,1,0],[0,0,1]],LF=(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]],vV=(e,t)=>[nn(e[0],t),nn(e[1],t),nn(e[2],t)];function DF(e,t,r){let n=rr(Lo(t,e)),o=rr(Nc(n,Lo(r,e)));return[n,Nc(o,n),o]}function kV(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 K0(e,t,r,n){let o=rr(Lo(t,e)),a=b=>{let g=Lo(b,e),y=nn(g,o);return[g[0]-y*o[0],g[1]-y*o[1],g[2]-y*o[2]]},s=rr(a(r)),i=rr(a(n)),c=nn(Nc(s,i),o),u=nn(s,i),m=c,f=1-u,[p,d,h]=o;return[[f*p*p+u,f*p*d+m*h,f*p*h-m*d],[f*p*d-m*h,f*d*d+u,f*d*h+m*p],[f*p*h+m*d,f*d*h-m*p,f*h*h+u]]}var MV=(e,t)=>Math.acos(Math.max(-1,Math.min(1,nn(rr(e),rr(t)))))*VF;function SV(e,t){return{upright:kV(DF(e.uprightLower,e.tieOuter,e.wheelCenter),DF(t.uprightLower,t.tieOuter,t.wheelCenter)),uca:t.mcpherson?null:K0(t.ucaFront,t.ucaRear,e.uprightUpper,t.uprightUpper),lca:K0(t.lcaFront,t.lcaRear,e.uprightLower,t.uprightLower),rocker:t.direct?null:K0(t.rockerPivotA,t.rockerPivotB,e.rockerToPushrod,t.rockerToPushrod)}}function BF(e){let t=rr(e[0]),r=Math.abs(t[0])<.9?[1,0,0]:[0,1,0],n=rr(Nc(t,r)),o=Nc(t,n),a=e.map(d=>{let h=rr(d);return[nn(h,n),nn(h,o)]}),s=d=>{let h=Math.cos(d),b=Math.sin(d),g=0;for(let[y,R]of a)g=Math.max(g,Math.abs(y*h+R*b));return g},i=Math.PI/180,c=0,l=1/0;for(let d=0;d<180;d++){let h=s(d*i);h<l&&([c,l]=[d*i,h])}let u=c-i,m=c+i,f=(Math.sqrt(5)-1)/2;for(let d=0;d<30;d++){let h=m-f*(m-u),b=u+f*(m-u);s(h)<s(b)?m=b:u=h}let p=Math.min(l,s((u+m)/2));return Math.asin(Math.min(1,p))*VF}function EF(e){let t=null;for(let r of e)Number.isFinite(r.angle)&&(!t||r.angle>t.angle)&&(t=r);return t}var AV={upright:"upright",lowerArm:"lca",upperArm:"uca"};function $F(e,t,r,n){let o=t.map(m=>SV(e,m)),a=rr(Lo(e.uprightUpper,e.uprightLower)),s=m=>Math.max(0,...o.map(f=>f[m]?MV(LF(f.upright,a),LF(f[m],a)):0)),i=[{angle:s("lca"),joint:"lower ball joint"}];e.mcpherson||i.push({angle:s("uca"),joint:"upper ball joint"});let c=(m,f,p)=>{let d=[Lo(e[f],e[m])];for(let h=0;h<t.length;h++){let b=p(o[h]);if(!b)return null;d.push(vV(b,Lo(t[h][f],t[h][m])))}return d},l=[["tie rod, inner end",c("tieInner","tieOuter",()=>RV)],["tie rod, outer end",c("tieInner","tieOuter",m=>m.upright)]];e.direct||l.push([`${n}, rocker end`,c("rockerToPushrod","pushrodOuter",m=>m.rocker)],[`${n}, outer end`,c("rockerToPushrod","pushrodOuter",m=>m[AV[r]])]);let u=l.filter(m=>m[1]!==null).map(([m,f])=>({joint:m,angle:BF(f)}));return{ballJoint:EF(i),rodEnd:EF(u)}}function FV(e){let t=(r,n)=>{let o=zt(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 GF(e,t){let r=ou(t);return{...FF,tyreRadius:FV(e),tyreWidth:r!==null?r*1e3:NF}}var IF={front:["FL","FR"],rear:["RL","RR"]},_F=(e,t,r)=>r<=1||t===e?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function H0(e,t,r,n,o=OF){let a=e.vehicle,[s]=IF[t],i=Gu(e,s,0,0)?.geometry;if(!i)return null;let c=Mp(a.chassis?.boxes??[],{vehicle:a,kc:e.kc}),l=t==="front"?St(a.front.config):0,u=l>0?_F(-l,l,Math.max(3,o.rackSteps|1)):[0],m=_F(Math.min(0,r.min),Math.max(0,r.max),Math.max(2,o.travelSteps)),f=[];for(let b of c.length?IF[t]:[s])for(let g of m)for(let y of u){let R=Gu(e,b,g,y)?.geometry;R&&f.push({corner:b,travel:g,rack:y,g:R})}let p=null;if(c.length){for(let b of PF(c,f,GF(e,n)))for(let g of[b.tyre,b.link])g&&(!p||g.distance<p.distance)&&(p={distance:g.distance,part:g.part,boxId:b.boxId});p??={distance:NaN,part:"",boxId:""}}let d=a[t].config,h=$F(i,f.filter(b=>b.corner===s).map(b=>b.g),d.pushrodAttach,d.rodType==="pull"?"pullrod":"pushrod");return{chassis:p,...h}}var Sp=Math.PI/180,Oc={travelSteps:9,heaveSteps:5,rollSteps:4,rackSteps:6},Ap={travelMin:-25,travelMax:25,rollMaxDeg:3,rollAtLimitDeg:2.5};function wV(e){let t=e.params;return{cgHeight:t.cg_height?Rt({...t,surveyedRadiusFront:e.vehicle.front.config.loadedRadius,surveyedRadiusRear:e.vehicle.rear.config.loadedRadius}).cgHeight:300,...Hh(t),drive:$h(t)}}function KF(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 z0(e,t=Oc,r=Ap,n){let o=null,a=(C,L)=>(o||(o={violation:C,reason:L}),null),s=e.vehicle,i=C=>C==="front"?s.front:s.rear,c=null,l=null,u=()=>{if(c)return c;if(n)try{let C=n();if(C)return c=Nt(s,C.kc),l=C.cgHeight,c}catch{a(500,"the car could not be stood on its tyre: its rates did not assemble")}return c=Nt(s)},m=C=>C==="front"?"FL":"RL",f=C=>{let L=u();if(!L.kc)return;let E=i(C).config.loadedRadius,D=zt(E,L.kc,m(C));return D===E?void 0:{loadedRadius:D}},p=(C,L)=>-Bs(u(),m(C),L),d=new Map,h=new Map,b=new Map,g=new Map,y=new Map,R=new Map,k=new Map,v=new Map,x=new Map,M=null,A=()=>{if(M)return M;u();let C=wV(e);return M=l!==null&&Number.isFinite(l)?{...C,cgHeight:l}:C},w,T,P=()=>{if(T!==void 0)return T;let C=Vl(u().ctx.FL,St(s.front.config));return T=C?Bl(C):null,T},S=(C,L,E)=>{if(C.has(L))return C.get(L)??null;let D=E();return C.set(L,D),D};return{car:e,density:t,envelope:r,get failure(){return o},axisLength:(C,L)=>{let E=i(C),D=E.hardpoints;return L==="uca"&&E.config.layout==="mcpherson"?NaN:L==="uca"?Me(D.ucaFront,D.ucaRear):Me(D.lcaFront,D.lcaRear)},linkLength:C=>{let L=i(C).hardpoints;return Me(L.tieInner,L.tieOuter)},compliance:C=>S(h,C,()=>Yf(i(C))??null),sweep:C=>S(d,C,()=>{let L;try{L=Ye(i(C),{travelMin:r.travelMin,travelMax:r.travelMax,steps:t.travelSteps})}catch{return a(500,`the ${C} travel sweep threw`)}if(!L.covered){let D=L.samples.map(z=>z.travel),N=Math.max(...D)-Math.min(...D),O=r.travelMax-r.travelMin;return a(Math.max(0,O-N),`the ${C} linkage reaches only ${N.toFixed(0)} mm of the ${O.toFixed(0)} mm travel range`)}if(L.fold)return a(200,`the ${C} travel(beta) folds \u2014 the suspension goes over centre in range`);let E=L.samples.filter(D=>!D.converged).length;if(E>0)return a(100+10*E,`${E} of ${L.samples.length} ${C} travel solves did not converge`);if(C==="front"&&i("front").config.steerMode==="rack"){let D=P();if(D)return a(D.violation,D.reason)}return L}),rcHeave:C=>S(b,C,()=>{let L=[],E=[],D=Math.max(2,t.heaveSteps);try{for(let O=0;O<D;O++){let z=r.travelMin+(r.travelMax-r.travelMin)*O/(D-1);L.push(z),E.push(gr(u(),{heave:p(C,z),pitch:0,roll:0,steer:0},C))}}catch{return a(500,`the ${C} roll-centre construction threw in heave`)}let N=KF(E,O=>Math.abs(L[O]-L[O-1]));return N>0?a(300,`the ${C} roll-centre construction lands on another branch at ${L[N].toFixed(0)} mm of travel`):{at:L,rc:E}}),rcRoll:C=>S(g,C,()=>{let L=[],E=[],D=Math.max(2,t.rollSteps);try{for(let O=0;O<D;O++){let z=r.rollMaxDeg*O/(D-1);L.push(z),E.push(gr(u(),{heave:0,pitch:0,roll:z*Sp,steer:0},C))}}catch{return a(500,`the ${C} roll-centre construction threw in roll`)}let N=KF(E,O=>Math.abs(E[O].cpLeft?.[0]??0)*Math.abs(L[O]-L[O-1])*Sp);return N>0?a(300,`the ${C} roll-centre construction lands on another branch at ${L[N].toFixed(1)}\xB0 of roll`):{at:L,rc:E}}),roadUnder:C=>{let L=y.get(C);return L===void 0&&(L=Dn(0,ze(m(C),s.config).axleX,u()),y.set(C,L)),L},steer:()=>{if(w!==void 0)return w;try{w=Ff(u(),{steerMax:St(s.front.config),steps:t.rackSteps})}catch{w=a(500,"the steering sweep threw")}let C=w?.filter(L=>!L.converged).length??0;if(w&&C>0){let L=P();w=L?a(L.violation,L.reason):a(100+10*C,`${C} of ${w.length} steering solves did not converge`)}return w??null},solveAt:(C,L,E=0)=>S(R,`${C}:${L}:${E}`,()=>{try{let D=ge(u().ctx[m(C)],L,E,void 0,f(C));return D.ok?D.state:D.why==="unconverged"?a(100,`the ${C} corner did not solve at ${L.toFixed(0)} mm of travel`):a(100+Math.abs(D.travelMiss),`the ${C} corner reaches only ${(L+D.travelMiss).toFixed(0)} of ${L.toFixed(0)} mm of travel`)}catch{return a(150,`the ${C} corner solve threw at ${L.toFixed(0)} mm of travel`)}}),readout:C=>S(v,`${C.heave}:${C.pitch}:${C.roll}:${C.steer}`,()=>{try{return G0(u(),C,A())}catch{return a(500,"the derived readout threw")}}),readoutAtTravel:(C,L)=>S(x,`${C}:${L}`,()=>{try{return Ic(u(),{heave:p(C,L),pitch:0,roll:0,steer:0},C,A())}catch{return a(500,`the ${C} readout threw at ${L.toFixed(0)} mm of travel`)}}),travelAtRoll:(C,L)=>{let E=i(C).hardpoints.wheelCenter[1]*Math.sin(L*Sp),D=u();if(!D.kc)return E;try{let N=Mt(D,{heave:0,pitch:0,roll:L*Sp,steer:0}),O=C==="front"?Math.max(N.FL.travel,N.FR.travel):Math.max(N.RL.travel,N.RR.travel);return Number.isFinite(O)?O:E}catch{return a(500,`the ${C} axle could not be rolled on its tyre`),E}},onTyre:()=>!!u().kc,contexts:u,keepOuts:C=>S(k,C,()=>{try{let L=e.params,E=C==="front"?L.tireModel:L.tireModelRear??L.tireModel,D={min:r.travelMin,max:r.travelMax};return H0(u(),C,D,E)??a(100,`the ${C} corner did not solve at its design ride`)}catch{return a(500,`the ${C} keep-outs threw`)}})}}var CV=Eg();function Y0(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=Om(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?fc([c],a.track,a.numerics,lc(s),a.settings,CV)[0]:ec(c,s,{numerics:a.numerics,standingStart:l,lapCounts:u});o={};for(let f of s.metrics)sl(f)&&(o[f.key]=f.value(m,void 0))}}catch{o=null}return r.set(n,o),o}}}var Fp=.01;function TV(e,t){return t.bump!==null&&e>t.bump-Fp?{at:"closed",past:Math.max(0,e-t.bump)}:t.droopStated&&e<t.droop+Fp?{at:"toppedOut",past:Math.max(0,t.droop-e)}:t.seat!==null&&e<t.seat+Fp?{at:"unseated",past:Math.max(0,t.seat-e)}:{at:"free",past:0}}var HF=e=>({droop:e.droop,droopStated:e.droopStated,bump:e.bump,seat:e.holdsLoad&&Number.isFinite(e.free)?e.free:null}),PV=[["front","FL","FR"],["rear","RL","RR"]];function j0(e,t){let r=[];for(let[n,o,a]of PV){let s=[t[o],t[a]];for(let m of[o,a]){let f=e.curve[m],p=f.spring?.law;if(!f.spring||!p)continue;let d=af(f,t[m]);d===null||!Number.isFinite(d)||r.push(W0(m,n,n,d,f.spring.length0-d,HF(p),!0))}let i=e.elements?.[n];if(!i)continue;let c=i.heave?.law;if(c){let m=OR(i,s),f=i.read.heave?.span0,p=n==="front"?"heaveFront":"heaveRear";r.push(W0(p,p,n,m,f!==void 0?f-m:null,HF(c),i.carriesLoad))}let l=i.rollStop,u=l?VR(i,s):null;if(l&&u!==null){let m=l.length0-u,f=n==="front"?"rollFront":"rollRear",p={droop:l.droop??-1/0,droopStated:l.droop!==null,bump:l.bump,seat:null};r.push(W0(f,f,n,m,u,p,i.carriesLoad))}}return r}function W0(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,...TV(n,a),bumpStated:a.bump!==null,bounds:s}}var WF=Math.PI/180;function U0(e,t,r,n){let o=t.speedKmh/3.6,a=Gd(e,o,t.axG,ln(e,t.ayG,0));if(!a||!e.aero)return null;let s=e.wheelbase,i=ta(e.aero,s),c=(h,b)=>Math.atan((b-h)/s)/WF,l={},u={};for(let h of lr)l[h]=r.corners[h].travel,u[h]=r.corners[h].ground;let m=n.kc?j0(n.kc,l):[],f=e.aero.model,p=a.downFront+a.downRear,d=f?{balance:Math.abs(p)>1e-9?100*a.downFront/p:NaN,clA:(a.clFront+a.clRear)*a.area,cdA:a.cd*a.area,loopMargin:1-a.gain,dataMargin:jF(f,s,a.hFront,a.hRear)}:null;return{front:{height:a.hFront,...zF(m,"front")},rear:{height:a.hRear,...zF(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:d,clearance:LV(n,u)}}function zF(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 jF(e,t,r,n){let o=(a,[s,i])=>Math.min(a-s,i-a);if(Px(e)){let{x:a,y:s}=Qo(e),i=[a[0],a[a.length-1]],c=[s[0],s[s.length-1]];return sn(e)?YF(e.frame,t,i,c,r,n):Math.min(o(r,i),o(n,c))}return pl(e)?YF(e.frame,t,e.range.h,e.range.pitch,r,n):Math.min(o(r,e.range.hFront),o(n,e.range.hRear))}function YF(e,t,r,n,o,a){let s=Zo(e,t,o,a),i=l=>t*Math.tan(l*WF),c=a-o;return Math.min(s.h-r[0],r[1]-s.h,c-i(n[0]),i(n[1])-c)}function LV(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=Ht(e.vehicle,!0)/2,c=Ht(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 lr){let g=[1,l[b][0],l[b][1]];for(let y=0;y<3;y++){m[y]+=g[y]*t[b];for(let R=0;R<3;R++)u[y][R]+=g[y]*g[R]}}let f=TF(u,m);if(!f)return null;let p=wF(n),d={z0:p.z0+f[0],dzdx:p.dzdx+f[1],dzdy:p.dzdy+f[2]},h=null;for(let b of Mp(r,n)){let g=CF(b,d);(!h||g.height<h.height)&&(h={height:g.height,volume:b.name})}return h}function wp(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 DV={front:"front",rear:"rear",heaveFront:"front",heaveRear:"rear",rollFront:"front",rollRear:"rear"};function Vc(e,t,r,n){let o=qu(e,t);return Bu.some(s=>{if(DV[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 X0(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 Cp=Math.PI/180,Tp=1e-6;function XF(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 Bc(e){let t=e.measured;if(t)return XF(t.travel,t.camber);let r=q(e.config.spinAxis);return-Math.asin(Math.max(-1,Math.min(1,r[2])))/Cp}function $c(e){let t=e.measured;if(t)return XF(t.travel,t.toe);let[r,n]=e.config.spinAxis;return Math.atan2(r,n)/Cp}function q0(e,t){let r=Math.abs(t.camber)>=Tp,n=Math.abs(t.toe)>=Tp;if(!r&&!n)return e;let o=e.measured;if(o)return{...e,measured:{...o,...r?{camber:o.camber.map(p=>p+t.camber)}:{},...n?{toe:o.toe.map(p=>p+t.toe)}:{}}};let[a,s]=e.config.spinAxis,i=Math.hypot(a,s);if(!(i>0))return e;let c=(Bc(e)+t.camber)*Cp,l=($c(e)+t.toe)*Cp,[u,m]=n?[Math.sin(l),Math.cos(l)]:[a/i,s/i],f=[u*Math.cos(c),m*Math.cos(c),-Math.sin(c)];return{...e,config:{...e.config,spinAxis:f}}}function Pp(e){let t=e&&typeof e=="object"?e.value:void 0;return typeof t=="number"&&Number.isFinite(t)?t:void 0}function EV(e,t){let r=t;return{front:Pp(r.camber_front_deg)??Bc(e.front),rear:Pp(r.camber_rear_deg)??Bc(e.rear)}}function IV(e,t){let r=t;return{front:Pp(r.toe_front_deg)??$c(e.front),rear:Pp(r.toe_rear_deg)??$c(e.rear)}}function _V(e){return{camber:{front:Bc(e.front),rear:Bc(e.rear)},toe:{front:$c(e.front),rear:$c(e.rear)}}}var UF=new WeakMap;function NV(e,t){let r=_V(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)<Tp&&Math.abs(u.toe)<Tp;if(o(n.front)&&o(n.rear))return e;let a=`${t.camber.front}|${t.camber.rear}|${t.toe.front}|${t.toe.rear}`,s=UF.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&&q0(m,n[na(u)])])):void 0,l={...e,front:q0(e.front,n.front),rear:q0(e.rear,n.rear),...c?{corners:c}:{}};return s||UF.set(e,s=new Map),s.size>=16&&s.clear(),s.set(a,l),l}function os(e,t){return t?NV(e,{camber:EV(e,t),toe:IV(e,t)}):e}var OV=9.81;function as(e){let t=Yn(e),r=Math.max(0,e.unsprungPerCorner)*OV,n=a=>{let s=a==="FL"||a==="FR",i=s?"front":"rear",c=Ze(e,i),l=c>0?c:1/0,u=vd(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:jt(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 qF=new WeakMap;function VV(e){let t=os(e.vehicle,e.params);if(t===e.vehicle)return e;let r=qF.get(e);return(!r||r.vehicle!==t)&&qF.set(e,r={...e,vehicle:t}),r}function En(e,t={}){let r=VV(e),n=C0(r,t),o=t.assemble?()=>{let m=n.dynInput();if(!m)throw new Error("the car did not assemble");return{kc:as(m),cgHeight:m.cgHeight}}:void 0,a=z0(r,t.density,t.envelope,o),s=I0(r,n,t),i=Y0(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(f=>f.id===m)??null,platformAt:m=>{let f=`${m.speedKmh}|${m.ayG}|${m.axG}`,p=l.get(f);if(p!==void 0)return p;let d=n.poseAt(m),h=n.dynInput(),b=null;if(d&&h)try{b=U0(h,m,d,a.contexts())}catch{b=null}return l.set(f,b),b}}}var BV=["x","y","z"],$V=/^(line|plane)\((-?\d+),(-?\d+)\)([uv]?)$/,QF=Math.PI/18e3,ZF=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],JF=(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]],GV=e=>Math.hypot(e[0],e[1],e[2]),Q0=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];function Z0(e){let t=GV(e);return t>1e-9?Q0(e,1/t):null}function KV(e,t){let r=e*QF,n=t*QF;return[Math.cos(n)*Math.cos(r),Math.cos(n)*Math.sin(r),Math.sin(n)]}function Xt(e){let t=e.lastIndexOf(".");if(t<0)return null;let r=$V.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:KV(Number(r[2]),Number(r[3]))},coord:n==="line"?"along":r[4]}}function ew(e){let t=Z0(JF([0,0,1],e))??[1,0,0];(t[0]<-1e-9||Math.abs(t[0])<=1e-9&&t[1]<0)&&(t=Q0(t,-1));let r=Z0(JF(e,t))??[0,1,0];return(r[2]<-1e-9||Math.abs(r[2])<=1e-9&&r[1]<0)&&(r=Q0(r,-1)),[t,r]}function J0(e){if(e.coord==="along")return e.shape.dir;let[t,r]=ew(e.shape.dir);return e.coord==="u"?t:r}function tw(e,t){let r=Xt(t);if(!r)return;let n=BV.map(u=>e[`${r.point}.${u}`]);if(n.some(u=>!u))return;let o=J0(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=>ZF(s(u),o),write:(u,m)=>{let f=s(u),p=m-ZF(f,o),d=u;for(let h of a)d=n[h].write(d,f[h]+p*o[h]);return d},...c?{supersededBy:c}:{}}}var ss=["x","y","z"];var HV=/^(?:hp\.(?:front|rear)\.\w+|(?:heave|roll)\.(?:front|rear)\.(?:outer|inner|anchor))$/;function Do(e){let t=e.lastIndexOf("."),r=e.slice(0,t);if(t<0||!HV.test(r))return null;let n=e.slice(t+1);if(n==="x"||n==="y"||n==="z")return{point:r,axis:n};let o=Xt(e);return o?{point:r,axis:o.coord}:null}var Gc="*";function ey(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 ty=e=>e?.reads==="speed"||e?.reads==="operating",ry=e=>e?.reads==="lateral"||e?.reads==="operating";function Eo(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 Lp(e,t){return e?.appliesAt?t.find(r=>!e.appliesAt(r)):t[0]}function is(e,t,r){let n=r?.stateId?e.stateOf(r.stateId):Lp(t,e.states)??null;return n&&!t.appliesAt?.(n)?n:null}function pt(e,t,r){let n=`${t.id}@${Eo(r)}`,o=e.values.get(n);if(o!==void 0)return o;let a;try{a=r?.courseId===Gc&&t.reads==="course"?zV(e,t,r):r?.stateId===Sr&&t.reads==="state"?YV(e,t,r):t.read(e,r)}catch{a=NaN}return e.values.set(n,a),a}function zV(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:pt(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 YV(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:pt(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 ny(e){let t={mean:"weighted mean",max:"highest",min:"lowest",span:"span"};return e?.acrossStates?`every state, ${t[e.acrossStates]}`:"every state"}function Xe(e){return`${e.quantity??e.groupShort??e.group} \xB7 ${e.label}`}var WV={front:"Front",rear:"Rear"},Kc={heave:0,pitch:0,roll:0,steer:0},rw="RC height (chassis) [mm]";function nw(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 jV(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 Hc=e=>e.length?Math.max(...e)-Math.min(...e):NaN;function ow(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 aw(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 cs(e,t,r){let n=e.stateOf(t?.stateId),o=n?e.poseAt(n):null;return o?r(o):NaN}var zc=(e,t)=>`${e==="front"?"F":"R"}${t}`,sw=e=>e==="L"?"R":"L";function iw(e){let t=WV[e],r=x=>`kin.${e}.${x}`,n=(x,M)=>{let A=x.sweep(e);return A?{x:A.samples.map(w=>w.travel),y:A.samples.map(M)}:{x:[],y:[]}},o=x=>e==="front"?x.vehicle.front:x.vehicle.rear,a=x=>x.params[e==="front"?"heaveFrontDesign":"heaveRearDesign"],s=x=>x.params[e==="front"?"arbFrontDesign":"arbRearDesign"],i=e==="front"?"the front axle":"the rear axle";function c(x){return o(x).config.actuation==="decoupled"?`${i} is decoupled, with no corner damper \u2014 read its heave and roll elements`:null}function l(x){let M=a(x);return M&&M.design.kind!=="none"?null:`${i} has no heave element`}function u(x){let M=a(x);return M?.design.kind==="coil"&&M.linkage?null:`${i} has no heave element on a linkage`}function m(x){let M=s(x);return M&&M.design.kind!=="none"?null:`${i} has no roll element`}function f(x){let M=s(x);return M?.linkage&&M.design.kind!=="none"&&M.design.kind!=="direct"?null:`${i} has no roll element on a linkage`}let p=x=>{if(u(x.car))return null;let M=x.sweep(e);return M?mf(o(x.car),a(x.car).linkage,M.samples):null},d=x=>{if(f(x.car))return null;let M=x.sweep(e);if(!M)return null;let A=s(x.car),w=cf(o(x.car),A.linkage,A.design.kind,M.samples),T=w.atDesign<0?-1:1;return{travel:w.travel,ratio:w.ratio.map(P=>P*T),atDesign:w.atDesign*T}},h=x=>x.readout(Kc)?.[e],b=x=>x.readoutAtTravel(e,x.envelope.travelMax),g=x=>{let M=n(x,A=>A.metrics.camber);return M.x.length?{key:r("camberGain"),title:`${t} camber vs travel`,xLabel:"travel [mm]",yLabel:"camber [\xB0]",...M}:null},y=x=>{let M=n(x,A=>A.metrics.toe);return M.x.length?{key:r("bumpSteer"),title:`${t} toe vs travel`,xLabel:"travel [mm]",yLabel:"toe [\xB0]",...M}:null},R=[{id:r("rcStatic"),group:`${t} roll centre`,label:"static height",unit:"mm",scale:30,scope:e,cost:"cheap",read:x=>x.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:x=>{let M=x.rcHeave(e);return M?jV(M.at,M.rc.map(A=>A.height)):NaN},curve:x=>{let M=x.rcHeave(e);return M?{key:r("rcHeaveWorst"),title:`${t} roll-centre height vs wheel travel`,xLabel:"travel [mm]",yLabel:rw,x:M.at,y:M.rc.map(A=>A.height-x.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:x=>{let M=x.rcRoll(e);return M?Hc(M.rc.map(A=>A.height)):NaN},curve:x=>{let M=x.rcRoll(e);return M?{key:r("rcRollSpan"),title:`${t} roll-centre height vs body roll`,xLabel:"roll [\xB0]",yLabel:rw,x:M.at,y:M.rc.map(A=>A.height-x.roadUnder(e))}:null}},{id:r("rcLateralSpan"),group:`${t} roll centre`,label:"lateral migration over roll",unit:"mm",scale:50,scope:e,cost:"cheap",read:x=>{let M=x.rcRoll(e);return M?Hc(M.rc.map(A=>A.lateral)):NaN},curve:x=>{let M=x.rcRoll(e);return M?{key:r("rcLateralSpan"),title:`${t} roll-centre lateral position vs body roll`,xLabel:"roll [\xB0]",yLabel:"RC lateral [mm]",x:M.at,y:M.rc.map(A=>A.lateral)}:null}},{id:r("minSinAngle"),group:`${t} roll centre`,label:"construction conditioning (min sinAngle)",unit:"-",scale:.04,scope:e,cost:"cheap",read:x=>{let M=x.rcHeave(e),A=x.rcRoll(e);return!M||!A?NaN:Math.min(...M.rc.map(w=>w.sinAngle),...A.rc.map(w=>w.sinAngle))},curve:x=>{let M=x.rcHeave(e);return M?{key:r("minSinAngle"),title:`${t} construction conditioning vs travel`,xLabel:"travel [mm]",yLabel:"sinAngle",x:M.at,y:M.rc.map(A=>A.sinAngle)}:null}},{id:r("fvsaLength"),group:`${t} roll centre`,label:"front-view swing-arm length",unit:"mm",scale:500,scope:e,cost:"readout",read:x=>h(x)?.fvsaLength??NaN},{id:r("complianceSteer"),group:`${t} compliance`,label:"compliance steer",unit:"\xB0/kN lateral",scale:.05,scope:e,cost:"readout",read:x=>(x.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:x=>(x.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:x=>(x.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:x=>(x.compliance(e)?.toePerMz??0)*1e5},{id:r("staticCamber"),group:`${t} camber & toe`,label:"static camber",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:x=>{let M=x.solveAt(e,0);return M?M.metrics.camber:NaN}},{id:r("staticToe"),group:`${t} camber & toe`,label:"static toe",unit:"\xB0",scale:.5,scope:e,cost:"cheap",read:x=>x.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:x=>h(x)?.camberGain??NaN,curve:x=>g(x)},{id:r("rollCamber"),group:`${t} camber & toe`,label:"camber gain in roll",unit:"\xB0/\xB0",scale:.2,scope:e,cost:"readout",read:x=>h(x)?.rollCamber??NaN},{id:r("rollCamberRecovery"),group:`${t} camber & toe`,label:"camber recovery in roll",unit:"%",scale:20,scope:e,cost:"readout",read:x=>h(x)?.camberRecovery??NaN},{id:r("bumpSteerDesign"),group:`${t} camber & toe`,label:"bump steer at design",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:x=>h(x)?.bumpSteer??NaN,curve:x=>y(x)},{id:r("rollSteer"),group:`${t} camber & toe`,label:"roll steer",unit:"\xB0/\xB0",scale:.1,scope:e,cost:"readout",read:x=>h(x)?.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:x=>{let M=n(x,A=>A.metrics.toe);return M.x.length?nw(M.x,M.y):NaN},curve:x=>y(x)},{id:r("camberGain"),group:`${t} camber & toe`,label:"camber gain, RMS over the travel",unit:"\xB0/mm",scale:.02,scope:e,cost:"cheap",read:x=>{let M=n(x,A=>A.metrics.camber);return M.x.length?nw(M.x,M.y):NaN},curve:x=>g(x)},{id:r("camberSpan"),group:`${t} camber & toe`,label:"camber range over travel",unit:"\xB0",scale:1,scope:e,cost:"cheap",read:x=>Hc(n(x,M=>M.metrics.camber).y)},{id:r("toeSpan"),group:`${t} camber & toe`,label:"toe range over travel",unit:"\xB0",scale:.5,scope:e,cost:"cheap",read:x=>Hc(n(x,M=>M.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:x=>{let M=x.solveAt(e,x.travelAtRoll(e,x.envelope.rollAtLimitDeg)),A=x.solveAt(e,0);return!M||!A?NaN:Math.abs(M.metrics.camber-A.metrics.camber+x.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:(x,M)=>cs(x,M,A=>A.camber[zc(e,A.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:(x,M)=>cs(x,M,A=>A.camber[zc(e,sw(A.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:(x,M)=>cs(x,M,A=>A.corners[zc(e,A.outer)].bumpToe)},{id:r("caster"),group:`${t} upright`,label:"caster",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:x=>x.solveAt(e,0)?.metrics.caster??NaN},{id:r("kpi"),group:`${t} upright`,label:"kingpin inclination",unit:"\xB0",scale:5,scope:e,cost:"cheap",read:x=>x.solveAt(e,0)?.metrics.kpi??NaN},{id:r("scrubRadius"),group:`${t} upright`,label:"scrub radius",unit:"mm",scale:20,scope:e,cost:"cheap",read:x=>x.solveAt(e,0)?.metrics.scrubRadius??NaN},{id:r("mechanicalTrail"),group:`${t} upright`,label:"mechanical trail",unit:"mm",scale:20,scope:e,cost:"cheap",read:x=>x.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:x=>x.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:x=>x.solveAt(e,0)?.metrics.casterOffset??NaN},{id:r("steeringArm"),group:`${t} upright`,label:"steering arm",unit:"mm",scale:20,scope:e,cost:"cheap",read:x=>x.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:x=>h(x)?.casterGain??NaN},{id:r("kpiGain"),group:`${t} upright`,label:"kingpin inclination gain in bump",unit:"\xB0/mm",scale:.02,scope:e,cost:"readout",read:x=>h(x)?.kpiGain??NaN},{id:r("scrubGain"),group:`${t} upright`,label:"scrub radius gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:x=>h(x)?.scrubGain??NaN},{id:r("trailGain"),group:`${t} upright`,label:"mechanical trail gain in bump",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:x=>h(x)?.trailGain??NaN},{id:r("motionRatio"),group:`${t} rates`,label:"motion ratio at design",unit:"-",scale:.2,scope:e,cost:"cheap",unavailable:c,read:x=>{if(c(x.car))return NaN;let M=x.sweep(e);return M?aw(M.samples.map(A=>A.travel),M.samples.map(A=>A.metrics.motionRatio??NaN))??NaN:NaN},curve:x=>{if(c(x.car))return null;let M=n(x,A=>A.metrics.motionRatio??NaN);return M.x.length?{key:r("motionRatio"),title:`${t} motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",...M}:null}},{id:r("mrSpread"),group:`${t} rates`,label:"motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:c,read:x=>{if(c(x.car))return NaN;let M=x.sweep(e);if(!M)return NaN;let A=M.samples.map(T=>T.metrics.motionRatio??NaN).filter(Number.isFinite);if(!A.length)return NaN;let w=A.reduce((T,P)=>T+P,0)/A.length;return w>0?(Math.max(...A)-Math.min(...A))/w:NaN}},{id:r("wheelRate"),group:`${t} rates`,label:"wheel rate at design",unit:"N/mm",scale:10,scope:e,cost:"cheap",unavailable:c,read:x=>{if(c(x.car))return NaN;let M=x.sweep(e);return M?aw(M.samples.map(A=>A.travel),M.samples.map(A=>A.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:x=>p(x)?.atDesign??NaN,curve:x=>{let M=p(x);return M?{key:r("heaveMotionRatio"),title:`${t} heave element motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:M.travel,y:M.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:x=>ow(p(x)?.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:x=>l(x.car)||!x.sweep(e)?NaN:Na(x.car.vehicle,x.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:f,read:x=>d(x)?.atDesign??NaN,curve:x=>{let M=d(x);return M?{key:r("rollMotionRatio"),title:`${t} roll element motion ratio vs travel`,xLabel:"travel [mm]",yLabel:"MR [-]",x:M.travel,y:M.ratio}:null}},{id:r("rollMrSpread"),group:`${t} rates`,label:"roll element motion-ratio spread",unit:"frac",scale:.1,scope:e,cost:"cheap",unavailable:f,read:x=>ow(d(x)?.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:x=>m(x.car)||!x.sweep(e)?NaN:co(x.car.vehicle,x.car.params)[e]??NaN},{id:r("ucaAxisLength"),group:`${t} package`,label:"upper arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:x=>x.axisLength(e,"uca")},{id:r("lcaAxisLength"),group:`${t} package`,label:"lower arm pivot-axis length",unit:"mm",scale:80,scope:e,cost:"geometry",read:x=>x.axisLength(e,"lca")},{id:r("linkLength"),group:`${t} package`,label:"tie/toe link length",unit:"mm",scale:100,scope:e,cost:"geometry",read:x=>x.linkLength(e)},{id:r("trackScrubRate"),group:`${t} package`,label:"track scrub rate",unit:"mm/mm",scale:.05,scope:e,cost:"readout",read:x=>x.readout(Kc)?.[e].trackScrubRate??NaN},{id:r("trackChange"),group:`${t} package`,label:"track change at full bump",unit:"mm",scale:2,scope:e,cost:"readout",read:x=>b(x)?.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:(x,M)=>cs(x,M,A=>A.corners[zc(e,A.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:(x,M)=>cs(x,M,A=>A.corners[zc(e,sw(A.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:x=>c(x.car)?NaN:Hc(n(x,M=>M.metrics.damperLength).y),curve:x=>{if(c(x.car))return null;let M=n(x,A=>A.metrics.damperLength);return M.x.length?{key:r("damperStroke"),title:`${t} damper length vs travel`,xLabel:"travel [mm]",yLabel:"length [mm]",...M}:null}}];e==="front"&&R.push({id:r("camberPerSteer"),group:`${t} camber & toe`,label:"camber change with steer",unit:"\xB0/\xB0",scale:.05,scope:"front",cost:"readout",read:x=>h(x)?.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:x=>h(x)?.steerJacking??NaN}),e==="front"?R.push({id:r("antiDive"),group:`${t} anti geometry`,label:"anti-dive",unit:"%",scale:20,scope:"front",cost:"readout",read:x=>x.readout(Kc)?.front.antiDive??NaN}):R.push({id:r("antiSquat"),group:`${t} anti geometry`,label:"anti-squat (driving)",unit:"%",scale:20,scope:"rear",cost:"readout",read:x=>x.readout(Kc)?.rear.antiSquat??NaN},{id:r("antiLift"),group:`${t} anti geometry`,label:"anti-lift (braking)",unit:"%",scale:20,scope:"rear",cost:"readout",read:x=>x.readout(Kc)?.rear.antiLift??NaN});let k=x=>{let M=x.slice(t.length+1);return M.charAt(0).toUpperCase()+M.slice(1)};return[...new Set(R.map(x=>x.group))].flatMap(x=>R.filter(M=>M.group===x)).map(x=>({...x,quantity:`${t} \xB7 ${k(x.group)}`}))}function cw(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 UV=[{id:"kin.front.ackermannCentre",group:"Steering",label:"Ackermann near centre",unit:"%",scale:25,scope:"front",cost:"cheap",read:e=>cw(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=>cw(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}}],XV=[{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)=>cs(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}}],oy=[...iw("front"),...iw("rear"),...UV,...XV];var qV={front:"Front",rear:"Rear"};function uw(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 lw(e){let t=qV[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=>uw(s.vehicle),read:s=>o(s,i=>i.chassis?.distance)},{...a,id:r("ballJointAngle"),label:`largest ball-joint angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.ballJoint?.angle)},{...a,id:r("rodEndAngle"),label:`largest rod-end angle ${n}`,unit:"\xB0",scale:1,read:s=>o(s,i=>i.rodEnd?.angle)}]}var ay=[...lw("front"),...lw("rear")];var hw={front:"Front",rear:"Rear"},mw=e=>To("side",e),QV=e=>To("drive",e)&&To("brake",e)?"neither brakes nor drives":null;function ZV(e,t,r,n){let o=is(e,t,r),a=o?e.tyreAt(o):null;return a?n(a):NaN}function ls(e,t){let r={...e,read:(n,o)=>ZV(n,r,o,t)};return r}var pw=e=>e?100*e.lossCamber:NaN,dw=e=>e&&!e.lifted?e.camber-e.wants:NaN;function fw(e){let t=hw[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:mw,unavailable:s=>up(s.params,e)},a=[ls({...o,id:r("camberErrorOuter"),label:"camber error at the outer wheel",unit:"\xB0",scale:.5},s=>dw(s.side(e)?.wheels[0])),ls({...o,id:r("camberErrorInner"),label:"camber error at the inner wheel",unit:"\xB0",scale:.5},s=>dw(s.side(e)?.wheels[1])),ls({...o,id:r("sideLossCamber"),label:"side grip lost to camber",unit:"%",scale:1},s=>pw(s.side(e))),ls({...n,appliesAt:mw,id:r("sideLossToe"),label:"side grip lost to the toe split",unit:"%",scale:1},s=>100*s.toeLoss(e)),ls({...n,appliesAt:QV,unavailable:s=>F0(s.params,e),id:r("longLossCamber"),label:"drive and brake grip lost to camber",unit:"%",scale:1},s=>pw(s.long(e)))];return e==="front"&&a.push(ls({...n,appliesAt:s=>To("ackermann",s),id:r("ackermannError"),label:"Ackermann against the tyre",unit:"%",scale:25},s=>s.ackermann())),a}var sy=[...fw("front"),...fw("rear")],JV=/^tyre\.(front|rear)\.(camberErrorOuter|camberErrorInner|sideLossCamber|longLossCamber)$/;function iy(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=JV.exec(a.id);if(!i)continue;let c=i[1],l=i[2]==="longLossCamber",u=s?.stateId==="*"?e.states.filter(m=>!a.appliesAt?.(m)):[is(e,a,s)].filter(m=>!!m);for(let m of u){let f=`${c}|${m.id}|${l}`;if(r.has(f))continue;let p=e.tyreAt(m),d=p?l?p.long(c):p.side(c):null;if(!d)continue;let{lo:h,hi:b,stated:g}=d.range,y=g?`the ${o(h)} \u2026 ${o(b)} its data covers`:`the \xB1${b.toFixed(0)}\xB0 read without a stated range`,R=M=>l?M===0?"left":"right":M===0?"outer":"inner",k=d.wheels.findIndex(M=>M.atEdge),v=d.wheels.findIndex(M=>M.outside&&!M.lifted),x=[];k>=0&&x.push(`the ${hw[c].toLowerCase()} ${R(k)} tyre wants ${o(d.wheels[k].wants)}, the edge of ${y}, and may want more`),v>=0&&x.push(`the ${R(v)} wheel has ${o(d.wheels[v].camber)}, past it, and is read at ${o(d.wheels[v].read)}`),x.length&&r.set(f,`In the ${n(m)} ${x.join("; ")}.`)}}return[...r.values()]}function cy(e,t){let r=e.appliesAt?.(t);return r?`is read at ${t.name}, which ${r}`:null}var e3={front:"Front",rear:"Rear"};function t3(e,t,r,n){let o=is(e,t,r),a=o?e.platformAt(o):null;return(a?n(a):null)??NaN}function qt(e,t){let r={...e,read:(n,o)=>t3(n,r,o,t)};return r}var ly={cost:"cheap",reads:"state"},r3={unavailable:e=>wp(e.params)};function bw(e){let t=e3[e],r=o=>`platform.${e}.${o}`,n={...ly,group:`${t} platform`,quantity:`${t} \xB7 Platform`,scope:e};return[qt({...n,id:r("rideHeight"),label:"ride height at a state",unit:"mm",scale:5,acrossStates:"min"},o=>o[e].height),qt({...n,id:r("toBumpStop"),label:"travel left to the bump stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>Vc(o.vehicle,o.params,e,"bump")},o=>o[e].toBump),qt({...n,id:r("toDroopStop"),label:"travel left to the droop stop",unit:"mm",scale:5,acrossStates:"min",unavailable:o=>Vc(o.vehicle,o.params,e,"droop")},o=>o[e].toDroop)]}var Dp={...ly,group:"Platform",scope:"car"},Yc={...ly,...r3,group:"Aero platform",groupShort:"Aero",scope:"car"},uy=[...bw("front"),...bw("rear"),qt({...Dp,id:"platform.rake",label:"rake at a state",unit:"\xB0",scale:.2,acrossStates:"span"},e=>e.rakeDeg),qt({...Dp,id:"platform.pitch",label:"pitch at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.pitchDeg),qt({...Dp,id:"platform.roll",label:"body roll at a state",unit:"\xB0",scale:.2,acrossStates:"max"},e=>e.rollDeg),qt({...Dp,id:"platform.groundClearance",label:"ground clearance at a state",unit:"mm",scale:5,acrossStates:"min",unavailable:e=>X0(e.vehicle)},e=>e.clearance?.height),qt({...Yc,id:"platform.balance",label:"balance at a state",unit:"%",scale:1,acrossStates:"span"},e=>e.aero?.balance),qt({...Yc,id:"platform.clA",label:"downforce Cl\xB7A at a state",unit:"m\xB2",scale:.1,acrossStates:"mean"},e=>e.aero?.clA),qt({...Yc,id:"platform.cdA",label:"drag Cd\xB7A at a state",unit:"m\xB2",scale:.05,acrossStates:"mean"},e=>e.aero?.cdA),qt({...Yc,id:"platform.dataMargin",label:"margin to the model\u2019s data",unit:"mm",scale:5,acrossStates:"min"},e=>e.aero?.dataMargin),qt({...Yc,id:"platform.loopMargin",label:"aero-elastic margin, 1 \u2212 loop gain",unit:"-",scale:.1,acrossStates:"min"},e=>e.aero?.loopMargin)];var gw={understeer:"operating",yawFreq:"speed",yawZeta:"speed",yawStiffness:"operating",steeringTorque:"operating",steeringTorqueGradient:"operating"};function st(e,t,r,n="cheap"){let o=Zb[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,...gw[e]?{reads:gw[e]}:{},read:(a,s)=>{let i=a.dynInput(),c=a.dynCtx(s);return i&&c?o.compute(i,c):NaN}}}var n3=[st("understeer","Handling \u2014 balance",.1),st("tlltdFront","Handling \u2014 balance",5),st("rollStiffFront","Handling \u2014 balance",5)],o3=[st("yawFreq","Handling \u2014 response",.5),st("yawZeta","Handling \u2014 response",.2),st("stabilitySpeed","Handling \u2014 response",50),st("yawStiffness","Handling \u2014 response",2e4,"trim")],a3=[st("steeringTorque","Steering feel",1,"trim"),st("steeringTorqueGradient","Steering feel",2,"trim")],s3=[st("rollGradient","Ride & body",.5),st("pitchGradient","Ride & body",.5),st("rideFreqFront","Ride & body",.5),st("rideFreqRear","Ride & body",.5),st("rollFreq","Ride & body",.5),st("pitchFreq","Ride & body",.5),st("zetaFront","Ride & body",.2),st("zetaRear","Ride & body",.2)],i3=[{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}],c3=[{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}],my=[...n3,...o3,...a3,...s3,...i3,...c3];function l3(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 py=[{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)=>l3(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 u3(e,t){let r=/^(.*?)\s*\(([^)]+)\)\s*$/.exec(e);return r?{label:r[1],unit:r[2]}:{label:e,unit:t?"s":""}}function m3(e){return e==="s"||e==="kWh"?.1:e==="km/h"?2:1}var yw=new WeakMap;function Ep(e){let t=yw.get(e);return t||(t=e.metrics.filter(sl).map(r=>{let{label:n,unit:o}=u3(r.label,r.format==="time");return{id:`event.${e.id}.${r.key}`,group:`Events \xB7 ${e.label}`,groupShort:"Events",label:n,unit:o,scale:m3(o),scope:"car",cost:"session",read:a=>a.session(e.id)?.[r.key]??NaN}}),yw.set(e,t),t)}var dy=Qa.flatMap(Ep);var Ip=[...oy,...ay,...sy,...uy,...my,...py,...dy],us=Object.fromEntries(Ip.map(e=>[e.id,e]));var xw={all:Ip,byId:us},Rw=new WeakMap;function nr(e=[]){if(e.length===0)return xw;let t=Rw.get(e);if(t)return t;let r=Mg(e).filter(n=>!Za(n.id)).flatMap(Ep);return t=r.length?{all:[...Ip,...r],byId:{...us,...Object.fromEntries(r.map(n=>[n.id,n]))}}:xw,Rw.set(e,t),t}var Wc=180/Math.PI,ms=Math.PI/180,d3=.2;function _p(e,t){let r=K(t,e);return q(r[0]<0?Hd(r):r)}var Np=e=>({side:Math.atan2(e[2],e[0])*Wc,plan:Math.atan2(e[1],e[0])*Wc}),Op=(e,t)=>q([1,Math.tan(t*ms),Math.tan(e*ms)]),jc=e=>Math.abs(e[0])>=d3,Vp=(e,t)=>Math.atan(t/Math.max(e,1))*Wc,Bp=(e,t)=>Math.tan(t*ms)*Math.max(e,1);var In=["side","plan","clock","len"],Bt={uca:{fore:"ucaFront",aft:"ucaRear",ball:"uprightUpper"},lca:{fore:"lcaFront",aft:"lcaRear",ball:"uprightLower"}},Uc={uca:"upper arm",lca:"lower arm"},f3=1,vw=(e,t)=>_p(e[Bt[t].fore],e[Bt[t].aft]);function kw(e){let t=q(K(Kd,U(e,X(Kd,e))));return{e1:t,e2:ae(e,t)}}function fy(e,t){let r=vw(e,t);if(!jc(r))return`the ${Uc[t]}'s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it`;let n=Bt[t],o=mn(e[n.ball],e[n.fore],r);return Math.hypot(...K(o,e[n.ball]))>=f3?null:`the ${Uc[t]}'s ball joint sits on its own pivot axis, so the arm has no length to swing on`}function on(e,t){let r=Bt[t],n=e[r.ball],o=vw(e,t),a=mn(n,e[r.fore],o),s=K(a,n),i=Math.hypot(s[0],s[1],s[2]),{e1:c,e2:l}=kw(o),u=i>0?U(s,1/i):c;return{...Np(o),clock:Math.atan2(X(u,l),X(u,c))*Wc,len:i,sFront:X(K(e[r.fore],a),o),sRear:X(K(e[r.aft],a),o)}}function hy(e,t){let r=Op(e.side,e.plan),{e1:n,e2:o}=kw(r),a=te(U(n,Math.cos(e.clock*ms)),U(o,Math.sin(e.clock*ms))),s=te(t,U(a,e.len));return{fore:te(s,U(r,e.sFront)),aft:te(s,U(r,e.sRear))}}function Mw(e,t,r,n){let o=Bt[t],a={...on(e,t),[r]:n},{fore:s,aft:i}=hy(a,e[o.ball]);return{...e,[o.fore]:s,[o.aft]:i}}function Sw(e,t){return t==="clock"?e.len:Math.abs(e.sFront-e.sRear)/2}function $p(e,t,r){return t==="len"?r:Vp(Sw(e,t),r)}function by(e,t,r){return t==="len"?r:Bp(Sw(e,t),r)}var Io=["side","plan","atY","atZ"],Fr={fore:"rockerPivotA",aft:"rockerPivotB"},h3=5,Aw=e=>_p(e.rockerPivotA,e.rockerPivotB);function ps(e){return Math.hypot(...K(e.rockerPivotB,e.rockerPivotA))<h3?"the rocker\u2019s two pivots are the same point, so there is no axis to describe":jc(Aw(e))?null:"the rocker\u2019s pivot axis is nearly across the car, where its side- and plan-view angles stop describing it"}function _n(e){let t=Aw(e),r=jc(t)?t:[1,0,0],n=e.rockerPivotA,o=te(n,U(r,-n[0]/r[0]));return{...Np(r),atY:o[1],atZ:o[2],sA:X(K(n,o),r),sB:X(K(e.rockerPivotB,o),r)}}function gy(e){let t=Op(e.side,e.plan),r=[0,e.atY,e.atZ];return{a:te(r,U(t,e.sA)),b:te(r,U(t,e.sB))}}function Fw(e,t,r){if(ps(e))return e;let{a:n,b:o}=gy({..._n(e),[t]:r});return{...e,rockerPivotA:n,rockerPivotB:o}}var ww=e=>Math.abs(e.sA-e.sB)/2;function yy(e,t,r){return t==="side"||t==="plan"?Vp(ww(e),r):r}function xy(e,t,r){return t==="side"||t==="plan"?Bp(ww(e),r):r}var ar={front:"Front",rear:"Rear"},or=["x","y","z"],Ke=(e,t)=>t==="front"?e.front:e.rear,Xc=(e,t,r)=>t==="front"?{...e,front:r}:{...e,rear:r},Cw=[{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"}]}],Tw={damperChassis:"strut top mount",pushrodOuter:"strut lower mount"},_o=30;function b3(e){let t=[];for(let r of["front","rear"]){let n=Ke(e.vehicle,r).config.layout==="mcpherson";for(let o of Cw)for(let{key:a,label:s}of o.keys){let i=n&&Tw[a]||s;for(let c=0;c<3;c++)t.push({id:`hp.${r}.${a}.${or[c]}`,group:`${ar[r]} hardpoints \u2014 ${o.kind}`,label:`${i} ${or[c]}`,scope:ar[r],unit:"mm",defaultSpan:_o,read:l=>Ke(l.vehicle,r).hardpoints[a][c],write:(l,u)=>{let m=Ke(l.vehicle,r),f=[...m.hardpoints[a]];f[c]=u;let p={...m.hardpoints,[a]:f};return{...l,vehicle:Xc(l.vehicle,r,{...m,hardpoints:p})}}})}}return t}var g3={side:"axis side-view angle",plan:"axis plan-view angle",clock:"arm clock angle",len:"effective arm length"},y3={side:"\xB0",plan:"\xB0",clock:"\xB0",len:"mm"};function x3(e){let t=[];for(let r of["front","rear"]){let n=Ke(e.vehicle,r).config.layout==="mcpherson";for(let o of["uca","lca"]){let a=Ke(e.vehicle,r).hardpoints,s=fy(a,o)?null:on(a,o);for(let i of In)t.push({id:`arm.${r}.${o}.${i}`,group:`${ar[r]} ${n?"arm axes":"wishbone axes"}`,label:`${Uc[o]} \u2014 ${g3[i]}`,scope:ar[r],unit:y3[i],defaultSpan:s?$p(s,i,_o):_o,read:c=>on(Ke(c.vehicle,r).hardpoints,o)[i],write:(c,l)=>{let u=Ke(c.vehicle,r),m=Mw(u.hardpoints,o,i,l);return{...c,vehicle:Xc(c.vehicle,r,{...u,hardpoints:m})}}})}}return t}var R3={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"},v3={side:"\xB0",plan:"\xB0",atY:"mm",atZ:"mm"};function k3(e){let t=[];for(let r of["front","rear"]){let n=Ke(e.vehicle,r).hardpoints,o=ps(n)?null:_n(n);for(let a of Io)t.push({id:`rocker.${r}.${a}`,group:`${ar[r]} rocker axis`,label:`rocker \u2014 ${R3[a]}`,scope:ar[r],unit:v3[a],defaultSpan:o?yy(o,a,_o):_o,read:s=>_n(Ke(s.vehicle,r).hardpoints)[a],write:(s,i)=>{let c=Ke(s.vehicle,r),l=Fw(c.hardpoints,a,i);return{...s,vehicle:Xc(s.vehicle,r,{...c,hardpoints:l})}}})}return t}var Gp={front:"heaveFrontDesign",rear:"heaveRearDesign"},Ry={front:"arbFrontDesign",rear:"arbRearDesign"};function M3(e,t){return{heave:e.config.actuation==="decoupled"?"heave element":"third spring",roll:t?.design.kind==="coil"?"roll shock":"anti-roll bar"}}var Kp=e=>/^(heave|roll)\.(front|rear)\.(outer|inner|anchor)\.[xyz]$/.test(e);function S3(e){let t=[];for(let r of["front","rear"]){let n=Ke(e.vehicle,r),o=e.params[Gp[r]],a=e.params[Ry[r]],s=M3(n,a),i=d=>d.params[Gp[r]],c=d=>d.params[Ry[r]],l=(d,h)=>({...d,params:{...d.params,[Gp[r]]:h}}),u=(d,h)=>({...d,params:{...d.params,[Ry[r]]:h}}),m={group:`${ar[r]} heave & roll elements`,scope:ar[r]},f=(d,h,b,g,y)=>{for(let R of b)t.push({...m,id:`${d}.${or[R]}`,label:`${h} ${or[R]}`,unit:"mm",defaultSpan:_o,read:k=>g(k)[R],write:(k,v)=>{let x=[...g(k)];return x[R]=v,y(k,x)}})},p=(d,h,b,g,y)=>{t.push({...m,id:d,label:h,unit:"N/mm",defaultSpan:Math.max(5,b*.4),read:g,write:y})};if(o?.design.kind==="coil"){if(o.linkage){let d=b=>i(b).linkage;f(`heave.${r}.outer`,`${s.heave} eye`,[0,1,2],b=>d(b).outer,(b,g)=>l(b,{...i(b),linkage:{...d(b),outer:g}})),o.linkage.mount?.kind==="chassis"&&f(`heave.${r}.anchor`,`${s.heave} chassis anchor`,[0,2],b=>d(b).mount.anchor,(b,g)=>l(b,{...i(b),linkage:{...d(b),mount:{kind:"chassis",anchor:g}}}))}if(typeof o.design.rate=="number"){let d=h=>i(h).design;p(`heave.${r}.rate`,`${s.heave} spring rate (@element)`,o.design.rate,h=>d(h).rate,(h,b)=>l(h,{...i(h),design:{...d(h),rate:b}}))}}if(a&&a.design.kind!=="none"){if(a.linkage&&a.design.kind!=="direct"){let h=R=>c(R).linkage,b=fn(n,a.linkage,a.design.kind),[g,y]=b?["left arm eye","right arm eye"]:["drop-link pickup","arm tip"];f(`roll.${r}.outer`,`${s.roll} ${g}`,[0,1,2],R=>h(R).outer,(R,k)=>u(R,{...c(R),linkage:{...h(R),outer:k}})),f(`roll.${r}.inner`,`${s.roll} ${y}`,[0,1,2],R=>h(R).inner,(R,k)=>u(R,{...c(R),linkage:{...h(R),inner:k}}))}let d=a.design;if(d.kind==="coil"&&typeof d.rate=="number"){let h=b=>c(b).design;p(`roll.${r}.rate`,`${s.roll} spring rate (@element)`,d.rate,b=>h(b).rate,(b,g)=>u(b,{...c(b),design:{kind:"coil",rate:g}}))}else d.kind==="direct"&&p(`roll.${r}.wheelRate`,`${s.roll} rate (@wheel)`,d.wheelRate,h=>c(h).design.wheelRate,(h,b)=>u(h,{...c(h),design:{kind:"direct",wheelRate:b}}))}}return t}var A3=[{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 F3(e){let t=[];for(let r of["front","rear"]){let n=Ke(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:ar[r],unit:"N/mm",defaultSpan:Math.max(500,l*.4),read:u=>i(Ke(u.vehicle,r).compliance??{})??l,write:(u,m)=>{let f=Ke(u.vehicle,r),p={...f,compliance:c(f.compliance??{},Math.max(1,m))};return{...u,vehicle:Xc(u.vehicle,r,p)}}})};for(let a of["ucaFront","ucaRear","lcaFront","lcaRear","tieRod","pushRod"])o(`link.${a}`,`${w3[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}`,`${C3[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 w3={ucaFront:"UCA front leg",ucaRear:"UCA rear leg",lcaFront:"LCA front leg",lcaRear:"LCA rear leg",tieRod:"tie rod",pushRod:"push/pull rod"},C3={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 T3(){return A3.map(e=>({id:`cfg.${e.axle}.${e.field}`,group:e.group,label:e.label,scope:ar[e.axle],unit:e.unit,defaultSpan:e.span(e.fallback),read:t=>Ke(t.vehicle,e.axle).config[e.field]??e.fallback,write:(t,r)=>{let n=Ke(t.vehicle,e.axle),o={...n,config:{...n.config,[e.field]:r}};return{...t,vehicle:Xc(t.vehicle,e.axle,o)}}}))}function P3(e){let t=Un(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=>Un(c.params.steeringSystem)[n],write:(c,l)=>({...c,params:{...c.params,steeringSystem:Un({...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 L3(e){let t=Bi(e.params),r=[];for(let n of["front","rear"]){if(t[n]!=="diff")continue;let o=uo(e.params.driveline?.[n]);if(o?.kind!=="clutch"&&o?.kind!=="torsen")continue;let a=(s,i)=>{let c=em[`${n}.${s}`];return{id:`driveline.${n}.${s}`,group:"Differential",label:c.label.charAt(0).toLowerCase()+c.label.slice(1),scope:ar[n],unit:c.unit===": 1"?"":c.unit??"",defaultSpan:i,read:l=>uo(l.params.driveline?.[n])?.[s],write:(l,u)=>({...l,params:{...l.params,driveline:Ju({...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 D3(e){if(xu(e.params)!=="hydraulic")return[];let t=[{id:"brakeSetup.barFront",group:"Brakes",label:`${Uh("barFront").toLowerCase()}, front share`,unit:"-",defaultSpan:.05,read:a=>$r(a.params.brakeSetup).barFront,write:(a,s)=>({...a,params:{...a.params,brakeSetup:$r({...$r(a.params.brakeSetup),barFront:s})}})}];if(!e.params.brakeModel)return t;let r=fr(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:jh(a.circuit?`${a.circuit}.${String(a.key)}`:a.key),unit:s,defaultSpan:i,read:c=>n(fr(c.params.brakeModel),a),write:(c,l)=>{let u=fr(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:fr(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 Pw=e=>!!e&&typeof e=="object"&&"value"in e&&"label"in e;function Lw(e){let t={...e};for(let r of Object.keys(t)){let n=t[r];Pw(n)&&(t[r]={...n})}return t}function E3(e){let t=[];for(let r of gM(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 Pw(s)?s.value:NaN},write:(a,s)=>{let i=Lw(a.params);return am(i,n.label,s),{...a,params:i}}})}return t}function Dw(e){let t={};for(let s of["front","rear"]){if(!Ke(e.vehicle,s).measured)continue;let c="this axle is described by measured curves, so its linkage is not solved";for(let l of Cw)for(let{key:u}of l.keys)for(let m of or)t[`hp.${s}.${u}.${m}`]={why:c};for(let l of["uca","lca"])for(let u of In)t[`arm.${s}.${l}.${u}`]={why:c};for(let l of Io)t[`rocker.${s}.${l}`]={why:c};for(let l of["heave.outer","heave.anchor","roll.outer","roll.inner"]){let[u,m]=l.split(".");for(let f of or)t[`${u}.${s}.${m}.${f}`]={why:c}}t[`cfg.${s}.springRate`]={why:"the measured curve set carries its own spring rate"}}let r=["rockerPivotA","rockerPivotB","rockerToPushrod","rockerToDamper"];for(let s of["front","rear"]){if(Ke(e.vehicle,s).config.actuation!=="direct")continue;let i="this axle is direct-acting \u2014 there is no bell-crank";for(let c of r)for(let l of or)t[`hp.${s}.${c}.${l}`]={why:i};for(let c of Io)t[`rocker.${s}.${c}`]={why:i}}for(let s of["front","rear"]){let i=Ke(e.vehicle,s);if(i.measured||i.config.actuation!=="decoupled")continue;let c="this axle is decoupled \u2014 the corner damper is out of circuit";for(let l of["rockerToDamper","damperChassis"])for(let u of or)t[`hp.${s}.${l}.${u}`]={why:c,useInstead:`heave.${s}.outer.${u}`};t[`cfg.${s}.springRate`]={why:"a decoupled axle has no corner spring \u2014 its elements hold it up",useInstead:`heave.${s}.rate`}}for(let s of["front","rear"]){let i=Ke(e.vehicle,s),c=e.params[Gp[s]]?.linkage;if(i.measured||!c||c.attach!=="rocker"||c.mount?.kind==="chassis")continue;let l=i.hardpoints,u=[0,1,2].map(f=>l.rockerPivotB[f]-l.rockerPivotA[f]),m=Math.hypot(u[0],u[1],u[2]);if(m>0)for(let f=0;f<3;f++)Math.abs(u[f]/m)<1-1e-12||(t[`heave.${s}.outer.${or[f]}`]={why:`the rocker shaft runs along ${or[f]} \u2014 this only slides the eye along it`})}for(let s of["front","rear"]){let i=Ke(e.vehicle,s);if(i.measured||i.config.layout!=="mcpherson")continue;let c="this axle is a McPherson strut \u2014 there is no upper arm";for(let l of["ucaFront","ucaRear","uprightUpper"])for(let u of or)t[`hp.${s}.${l}.${u}`]={why:c,useInstead:`hp.${s}.damperChassis.${u}`};for(let l of In)t[`arm.${s}.uca.${l}`]={why:c};for(let l of["link.ucaFront","link.ucaRear","bush.ucaFront","bush.ucaRear"])t[`kc.${s}.${l}`]={why:c}}for(let s of["front","rear"]){let i=Ke(e.vehicle,s);if(i.measured)continue;for(let l of["uca","lca"]){if(l==="uca"&&i.config.layout==="mcpherson")continue;let u=fy(i.hardpoints,l);if(u)for(let m of In)t[`arm.${s}.${l}.${m}`]={why:u,useInstead:`hp.${s}.${Bt[l].fore}.z`}}let c=ps(i.hardpoints);if(c&&i.config.actuation!=="direct")for(let l of Io)t[`rocker.${s}.${l}`]={why:c,useInstead:`hp.${s}.${Fr.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[s,i,c,l,u]of n){let m=e.params[s];if(!m?.design||m.design.kind==="none")continue;let f=m.design.kind==="direct"?`${u}.${l}.wheelRate`:`${u}.${l}.rate`;t[i]={why:`computed from ${c}`,useInstead:f}}let o=e.params.aeroModelId||e.params.aeroModel?_b:Nb;for(let[s,i]of Object.entries(o))t[`param.${s}`]={why:i};if(e.params.batteryModelId||e.params.batteryModel)for(let[s,i]of Object.entries(rm))t[`param.${s}`]={why:i};for(let[s,i]of Object.entries(nm(e.params)))t[`param.${s}`]={why:i};let a=xu(e.params);return a==="hydraulic"?t["param.brake_balance"]={why:"set by the balance bar and the brake hardware",useInstead:"brakeSetup.barFront"}:a==="tyre"&&(t["param.brake_balance"]={why:"tyre-limited brakes split as the grip does"}),t}function Ew(e){let t={..._3,...Dw(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[...b3(e),...x3(e),...k3(e),...S3(e),...T3(),...P3(e),...D3(e),...L3(e),...F3(e),...E3(e.params)].map(r)}var I3={spring_front:"cfg.front.springRate",spring_rear:"cfg.rear.springRate"},_3=Object.fromEntries(Object.entries(Ib).map(([e,t])=>[`param.${e}`,{why:t,useInstead:I3[e]}])),rt=e=>e.scope?`${e.scope} \xB7 ${e.label}`:e.label;function vt(e){let t={};for(let n of Ew(e))t[n.id]=n;let r=(n,o)=>{if(typeof o!="string")return;let a=tw(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 vy=e=>e.step!==void 0&&Number.isFinite(e.step)&&e.step>0?e.step:0,ky=e=>vy(e)>0||(e.values?.length??0)>0,My=e=>e.some(ky),Iw=e=>1e-9*Math.max(1,Math.abs(e.lo),Math.abs(e.hi));function _w(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=vy(e);if(!r||!Number.isFinite(e.start))return t;let n=Iw(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 Nw=(e,t)=>t.map((r,n)=>e[n]&&ky(e[n])?_w(e[n],r):r);function Sy(e,t=1e3){if(e.values?.length)return e.values.length;let r=vy(e);if(!r||!Number.isFinite(e.start))return 1/0;let n=Iw(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 Ay(e,t,r){let n=Nw(e.variables,t),o=n.every((a,s)=>a===t[s]);return{x:n,score:o?r:Nr(e,n)}}function Cy(e,t){if(!e.variables.some(Vw))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(Bw(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 Vw=e=>!!(e.fixed||e.around||e.follows)||Bw(e),Bw=e=>!!e.values?.length&&(e.lo!==Math.min(...e.values)||e.hi!==Math.max(...e.values));function dt(e,t){if(!t.variables.some(Vw))return t;let r=vt(e);return Cy(t,n=>{let o=r[n];if(!o)return NaN;try{return o.read(e)}catch{return NaN}})}function sr(e){return[...e.objectives,...e.constraints,...e.watches??[]]}var zp=e=>(e.metrics??nr()).byId;function Ty(e,t){t=dt(e,t);let r=vt(e),n=[];for(let o of t.variables){let a=r[o.id];a&&n.push({id:a.id,name:rt(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 ds(e,t,r){t=dt(e,t);let n=vt(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]))}),Dy(e,o,t.followers,n)}function Py(e,t,r={}){let n=t.states??[],o=n.some(c=>c.follows);if(!o&&!t.envelopeFollows)return t;let a=En(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=x0(n,c,V3(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=zp(r),u=Ly(t,l),m=sr(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))),f=h=>{let b=En(e,{density:t.density,envelope:h,assemble:r.assemble,numerics:r.numerics});return m.every(({r:g,m:y})=>Number.isFinite(pt(b,y,g.at)))},p=c.length===s.length?O3(e,v0(c,u),u):null,d=p&&m.length?N3(p,f):p;d&&!k0(d,t.envelope)&&(i=d)}return s===n&&i===t.envelope?t:{...t,states:s,envelope:i}}var Hp=3;function N3(e,t){let r=(c,l)=>t({...e,travelMin:c,travelMax:l}),n=e.travelMin-Hp,o=e.travelMax+Hp;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+Hp)),i=Math.max(1,Math.min(e.travelMax,o-Hp));return s===e.travelMin&&i===e.travelMax?e:{...e,travelMin:s,travelMax:i}}function Ly(e,t){let r=new Set;for(let n of sr(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 O3(e,t,r){if(!t)return null;let n=os(e.vehicle,e.params),{travelMin:o,travelMax:a}=t;for(let s of r.map(i=>n[i]))try{let i=Ye(s,{travelMin:o,travelMax:a,steps:Oc.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 V3(e){let t=e.projectTrack?.();if(!t)return null;try{return y0(mt(t.asset,t.numerics))}catch{return null}}function Dy(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 Nn(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 $w=(e,t="")=>t&&t!=="-"?`${e} ${t}`:`${e}`;function Gw(e,t,r){let n=t??us[e.metricId],o=(n?Xe(n):e.metricId)+No(e.at,n,r),a=s=>$w(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 No(e,t,r){if(!e&&t?.reads!=="state")return"";e??={};let n=[];if(t?.reads==="state")if(e.stateId===Sr)n.push(ny(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&&ty(t)&&n.push(`${(e.speed*3.6).toFixed(0)} km/h`),e.ayG!==void 0&&ry(t)&&n.push(`${e.ayG.toFixed(2)} g`),e.courseId===Gc&&t?.reads==="course")n.push(ey(t));else if(e.courseId&&t?.reads==="course"){let o=r?.lap.courses.find(a=>a.id===e.courseId);o&&n.push(E0(o))}return n.length?` @ ${n.join(", ")}`:""}function Kw(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 Hw=5e-4;function zw(e,t){return e.cost!=="lap"&&e.cost!=="session"?0:Number.isFinite(t)?Hw*Math.abs(t):0}function Yp(e,t,r={}){return En(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 Wp(e,t,r={}){t=dt(e,t);let n=Ty(e,t),o=vt(e),a=zp(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,f)=>{let p=0,d=[];for(let{spec:h,metric:b}of m){let g=pt(f,b,h.at);if(!Number.isFinite(g))return{ok:!1,violation:f.failure?.violation??400,reason:f.failure?.reason??`${Xe(b)} could not be computed`};let y=Nn(h,g);y>0&&(p+=y/b.scale,d.push(`${Gw(h,b,t)} (${$w(g.toFixed(3),b.unit)})`))}return d.length===0?oi:{ok:!1,violation:p,reason:d.join("; ")}};return{name:"study",variables:n,build:m=>{let f=e;return t.variables.forEach((p,d)=>{let h=o[p.id];h&&(f=h.write(f,m[d]))}),f=Dy(e,f,t.followers,o),{car:f,ev:Yp(f,t,r)}},feasible:({ev:m})=>{let f=u(i,m);if(!f.ok)return f;for(let{spec:p,metric:d}of c)pt(m,d,p.at);for(let{spec:p,metric:d}of l)pt(m,d,p.at);return m.failure?{ok:!1,violation:m.failure.violation,reason:m.failure.reason}:u(c,m)},terms:({ev:m})=>l.map(({spec:f,metric:p})=>{let d=pt(m,p,f.at);return{name:Xe(p)+No(f.at,p,t),raw:d,unit:p.unit,weight:f.weight,contribution:Kw(f,p,d),resolution:Math.abs(f.weight)*zw(p,d)/p.scale}})}}function Fy(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 Yw(e,t){if(e.variables.some(o=>o.id===t))return!0;let r=Do(t);if(!r||!ss.includes(r.axis))return!1;if(e.variables.some(o=>Xt(o.id)?.point===r.point))return!0;let n=Fy(t);return!!n&&e.variables.some(o=>/^(arm|rocker)\./.test(o.id)&&Fy(o.id)===n)}function B3(e,t){let r=e.followers??[],n=new Map(r.map(i=>[i.id,i.follows])),o=i=>{let c=t[i],l=Do(i);return c&&l&&ss.includes(l.axis)?{name:rt({...c,label:c.label.replace(/ [xyz]$/,"")}),axis:l.axis}:{name:c?rt(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),f=p=>p&&p!=="x, y, z"?` in ${p}`:"";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,p=>`${u.name}${f(p)} cannot be moved: ${c.supersededBy.why}.`),!l)s(`no-lead:${u.name}:${i.follows}`,u.axis,p=>`${u.name}${f(p)} 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,p=>`${u.name}${f(p)} cannot move with itself.`);else if(l.unit!==c.unit)s(`unit:${u.name}:${m.name}`,u.axis,p=>`${u.name}${f(p)} 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 p=o(n.get(i.follows));s(`chain:${u.name}:${m.name}`,u.axis,d=>`${u.name}${f(d)} moves with ${m.name}, which itself moves with ${p.name}. Link it to ${p.name}.`)}else Yw(e,i.follows)||s(`still:${u.name}:${m.name}`,u.axis,p=>`${u.name}${f(p)} moves with ${m.name}, which the study does not move${f(p)}. Free that one, or give this its own bound.`)}return[...a.values()].map(i=>i.text(i.axes.join(", ")))}function Ey(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=dt(e,t);let a=vt(e),s=[],i=zp(r),c=sr(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=sr(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 R=new Set([...y.map(k=>k.id),Sr]);for(let k of m){let v=i[k.metricId];if(k.at?.stateId&&!R.has(k.at.stateId))s.push(`${Xe(v)} names a state this study no longer has. Point it at one of the states under Conditions.`);else if(k.at?.stateId===Sr&&!v.acrossStates)s.push(`${Xe(v)} is read at one state at a time, not over every state.`);else if(v.appliesAt){let x=k.at?.stateId&&k.at.stateId!==Sr?y.find(A=>A.id===k.at.stateId):void 0,M=x?cy(v,x):null;M?s.push(`${Xe(v)} ${M}. Point it at a state that does.`):!x&&!Lp(v,y)&&s.push(`${Xe(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 f=new Set([...t.lap.courses.map(y=>y.id),Gc]);for(let y of sr(t))if(y.at?.courseId&&!f.has(y.at.courseId)){let R=i[y.metricId];s.push(`${R?Xe(R):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(R=>/arb_|spring|heave_|front_mass_diss|cg_height|^hp\./.test(R.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 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 R=a[y.id];if(!R){s.push(`\u201C${y.id}\u201D is not a variable this car has.`);continue}if(y.values&&y.values.length<2?s.push(`${rt(R)}: list two values or more, or fix it where it is.`):y.hi>y.lo?y.step!==void 0&&Sy({...y,start:R.read(e)})<2&&s.push(`${rt(R)}: a step of ${y.step} ${R.unit} leaves no other place to land in its box. Make the step finer or the box wider, or fix it.`):s.push(`${rt(R)}: the upper bound must be above the lower one (${y.lo} to ${y.hi}).`),R.supersededBy){let v=R.supersededBy.useInstead?a[R.supersededBy.useInstead]:void 0,x=v?rt(v):void 0;s.push(`${rt(R)} cannot be searched: ${R.supersededBy.why}.`+(x?` Use ${x} instead.`:""))}let k=R.read(e);Number.isFinite(k)&&(k<y.lo||k>y.hi)&&s.push(`${rt(R)} starts at ${k.toFixed(1)} ${R.unit}, outside its own bounds.`)}let p=t.followers??[],d=new Map;for(let y of[...t.variables.map(R=>R.id),...p.map(R=>R.id)]){let R=Fy(y);if(!R)continue;let k=d.get(R);k||d.set(R,k={arms:[],coords:[]}),(/^(arm|rocker)\./.test(y)?k.arms:k.coords).push(y)}for(let[y,R]of d){if(R.arms.length===0||R.coords.length===0)continue;let k=x=>a[x]?rt(a[x]):x,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 (${R.arms.map(k).join(", ")}) and as pivot coordinates (${R.coords.map(k).join(", ")}). They describe the same ${v}, so whichever is applied second overwrites the other. Keep one.`)}let h=new Map,b=new Set(p.map(y=>y.id));for(let y of[...t.variables.map(R=>R.id),...b]){let R=Do(y);if(!R)continue;let k=Xt(y),v=b.has(y)?"with":k?`${k.shape.kind}:${y.slice(y.lastIndexOf(".")+1).replace(/[uv]$/,"")}`:"axes",x=h.get(R.point);x||h.set(R.point,x=new Set),x.add(v)}for(let[y,R]of h){if(R.size<2||R.size===2&&R.has("axes")&&R.has("with"))continue;let k=[...R].map(w=>w.split(":")[0]),v=w=>k.filter(T=>T===w).length,x=[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),M=a[`${y}.x`],A=M?rt({...M,label:M.label.replace(/ x$/,"")}):y;s.push(`${A} is moved more than one way at once \u2014 ${x.join(" and ")}. Each write moves it off the other's, so keep one.`)}s.push(...B3(t,a));for(let y of t.constraints){let R=i[y.metricId];if(!R){s.push(`\u201C${y.metricId}\u201D is not a metric.`);continue}y.op==="band"&&!((y.limit2??y.limit)>y.limit)&&s.push(`${Xe(R)}: 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 sr(t))if(y.at?.speed!==void 0&&!(y.at.speed>0)){let R=i[y.metricId];s.push(`${R?Xe(R):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 sr(t)){let R=i[y.metricId],k=R?.unavailable?.(e);!R||!k||g.has(R.id)||(g.add(R.id),s.push(`${Xe(R)} cannot be read on this car: ${k}.`))}for(let y of t.objectives)i[y.metricId]?y.weight>0?y.goal==="target"&&!Number.isFinite(y.target)?s.push(`${Xe(i[y.metricId])}: \u201Chit a value\u201D needs a value.`):y.goal==="target"&&y.tolerance!==void 0&&!(y.tolerance>=0)&&s.push(`${Xe(i[y.metricId])}: the tolerance must be zero or more.`):s.push(`${Xe(i[y.metricId])}: weight must be positive.`):s.push(`\u201C${y.metricId}\u201D is not a metric.`);return s}var Ww=.1,jw=2e3,wy=3;function Iy(e,t,r={},n=jw){t=dt(e,t);let o=Wp(e,t,r),a=zp(r),s=vt(e),i=o.variables.map(S=>S.start),c=S=>{let F=o.build(S);return o.feasible(F).ok&&o.terms(F),F},l=c(i),u=o.feasible(l),m=[...t.objectives,...t.constraints],f=(S,F=m)=>{let C={};for(let L of F){let E=a[L.metricId];E&&(C[`${L.metricId}@${Eo(L.at)}`]=pt(S.ev,E,L.at))}return C},p=S=>m.map(F=>S[`${F.metricId}@${Eo(F.at)}`]).map(F=>Number.isFinite(F)?F.toFixed(9):"x").join("|"),d=f(l,sr(t)),h=p(d),b=[],g=[],y={},R=[],k=0;t.variables.forEach((S,F)=>{let C=s[S.id];if(!C)return;if(R.length>=wy&&k>n){g.push(C);return}let L=[...i];L[F]=i[F]+(S.hi-i[F])*.25||S.hi;let E=performance.now(),D=c(L),N=performance.now()-E;k+=N,R.push(N);let O=f(D);y[C.id]=O,p(O)===h&&b.push(C)});let v=t.variables[0],x=v?t.variables.indexOf(v):-1;for(let S=0;v&&R.length>0&&R.length<wy;S++){let F=[...i];F[x]=i[x]+(v.hi-i[x])*(.4+.15*S)||v.hi;let C=performance.now();c(F),R.push(performance.now()-C)}let M=[...R].sort((S,F)=>S-F),A=M.length?M[M.length>>1]:0,w=[],T=sr(t).map(S=>S.metricId);if(T.some(S=>S.startsWith("dyn.trim")||S==="dyn.ymdMaxAy")){let S=l.ev.ymdLimit();S?.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."),!S&&l.ev.dynAvailable&&w.push("The yaw-moment diagram found no trim point, so anything read off the limit is unavailable.")}if(T.some(S=>S==="dyn.steeringTorque"||S==="dyn.steeringTorqueGradient")){let S=l.ev.tyre()?.model,F=S?hn(S):null;F==="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."):F==="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 P=["lap.minStabil","lap.understeerFrac"];if(T.some(S=>P.includes(S))){let F=l.ev.lapReserve()?.beyondFrac;if(F!==void 0&&Number.isFinite(F)){let C=(F*100).toFixed(0);F>=Ww?w.push(`Over ${C} % 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.`):F>0&&w.push(`${C} % 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(...iy(l.ev,sr(t).map(S=>({m:a[S.metricId],at:S.at})).filter(S=>!!S.m))),{msPerEval:A,values:d,samples:R.length,times:R,dead:b,moves:y,unprobed:g,warnings:w,beyondFrac:T.some(S=>P.includes(S))?l.ev.lapReserve()?.beyondFrac:void 0,startFeasible:u.ok,startReason:u.reason}}var G3=[{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:K3.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 K3=["setup:m","characteristics:peak_power","characteristics:power_to_weight","characteristics:cla","characteristics:cda","characteristics:pack_energy","characteristics:maxAy","characteristics:top_speed"];var ule=new Set(G3.map(e=>e.kind));var Uw={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 _y=["FL","FR","RL","RR"],Tt=(e,t,r)=>({input:e,from:r?r[0]:Uw[e].from,to:r?r[1]:Uw[e].to,n:t}),fle=[{id:"sides",name:"Inside and outside",cards:[{id:"camber-roll",form:"curves",title:"Camber to the road through roll",sweep:Tt("roll",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"toe-rack",form:"curves",title:"Wheel angle against the rack",sweep:Tt("steer",25),wheels:["FL","FR"],y:["toe"]},{id:"camber-rack",form:"curves",title:"Camber to the road through the steer",sweep:Tt("steer",25),wheels:["FL","FR"],y:["camberRoad"]},{id:"load-roll",form:"curves",title:"Wheel loads through roll",sweep:Tt("roll",25),wheels:_y,y:["wheelLoad"]},{id:"travel-roll",form:"curves",title:"Wheel travel through roll",sweep:Tt("roll",25),wheels:_y,y:["travel"]},{id:"toe-roll",form:"curves",title:"Roll steer, all four",sweep:Tt("roll",25),wheels:_y,y:["toe"]}]},{id:"maps",name:"Travel and steer together",cards:[{id:"camber-map",form:"surface",title:"Camber over travel and rack",sweep:Tt("travel",17),second:Tt("steer",13),wheels:["FL"],y:["camber"]},{id:"bump-steer-map",form:"map",title:"Bump steer over travel and rack",sweep:Tt("travel",17),second:Tt("steer",13),wheels:["FL"],y:["bumpSteer"]},{id:"bump-steer-family",form:"curves",title:"Bump steer through travel, at five rack positions",sweep:Tt("travel",25),second:Tt("steer",5,[-20,20]),wheels:["FL"],y:["bumpSteer"]},{id:"scrub-map",form:"surface",title:"Scrub radius over travel and rack",sweep:Tt("travel",17),second:Tt("steer",13),wheels:["FL"],y:["scrubRadius"]}]}];function Ny(e){let t=Number(e);return Number.isFinite(t)?Math.min(gh,Math.max(bh,t)):Et}var qw=6e4;var mue=[{within:60*6e4,every:qw},{within:1440*6e4,every:60*6e4},{within:720*60*6e4,every:1440*6e4},{within:1/0,every:10080*6e4}];var e5=new Set(["color","visible","source","origin"]),kue=["id",...e5];var Jw=.18/1.18,eC={induction:{kind:"natural"}},tC=e=>e.breathing??eC;function jp(e){switch(e?.kind){case"sae-j1349":return hc(99e3,25);case"measured":return hc(e.hPa*100,e.tempC);default:return hc(101325,20)}}var r5=jp(void 0);function rC(e,t){let r=jp(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 nC(e,t){let r=e.induction;if(r.kind==="table"){let o=s=>_e(r.densityAltitudeM,r.powerPct,s),a=o(jp(e.rated).densityAltitudeM);return a>0?Math.max(0,o(t.densityAltitudeM)/a):0}let n=e.frictionShare??Jw;return Math.max(0,(rC(e,t)-n)/(1-n))}var Zw=new WeakMap;function Vy(e,t){let r=e.asRated??e,n=`${t.p}|${t.pDry}|${t.T}`,o=Zw.get(r);o||Zw.set(r,o=new Map);let a=o.get(n);if(a)return a;let s=nC(tC(r),t),i={...r,torque:r.torque.map(c=>c*s),asRated:r};return o.set(n,i),i}function s5(e){return JSON.parse(By($y(e,"public/laptime/index.json"),"utf8")).tracks}var i5=async e=>{let t=await fetch(e.url);if(!t.ok)throw new Error(`The track could not be read from ${op(e)} (${t.status}).`);return new Uint8Array(await t.arrayBuffer())};function oC(e,t=new Map,r=i5){let n=s5(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(!Mc(o.address))throw new Error(`"${o.address}" is not a catalogue address`);if(!kc(o.link))throw new Error("This track is linked to a source this version does not read from.");i=await n0(await r(o.link),o.link,o.address)}else if(o.kind==="catalogue"){if(!Mc(o.address))throw new Error(`"${o.address}" is not a catalogue address`);let c=JSON.parse(By($y(e,"public/catalogue",a0(o.address)),"utf8"));i=await i0(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(By($y(e,"public/laptime",c),"utf8"))}return t.set(a,i),structuredClone(i)}}var c5=9.81;function aC(e,t=e.tireModel,r=e.tireModelRear){if(!t)return e;let n=e.m.value*c5/4,o=Va(e,t,r),a=De(o.front).rollingRadius(n),s=o.rear===o.front?a:De(o.rear).rollingRadius(n),i=l5(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 l5(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 u5=1e-6;function sC(e,t,r){let n=e.cgReference;if(!n||!e.cg_height)return e;let o=lM(e,t,r);if(o===void 0||Math.abs(o-n.standingRadius)<u5)return e;let a=n.typed??e.cg_height.value;return{...e,cg_height:{...e.cg_height,value:Oa(e.cg_height.value,n.standingRadius,o)},cgReference:{...n,standingRadius:o,typed:a}}}function iC(e,t,r){let n=e.rcRoad,o=e.rc_front,a=e.rc_rear;if(!n||!o||!a)return e;let s=Zu(e,t,r),i=qr(o.value,n.gainFront,n.radiusFront,s.front),c=qr(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 cC=e=>({brakeFade:e.brakeFade,airTempC:e.airTempC,diffYaw:e.diffYaw,...bc(e.air)?{air:e.air}:{}});var Oo=(e,t)=>t?e.find(r=>r.id===t)?.model:void 0;function Vo(e){return{tire:t=>Oo(e.tires,t),motor:t=>Oo(e.motors,t),aero:t=>Oo(e.aeros,t),battery:t=>Oo(e.batteries,t),brake:t=>Oo(e.brakes??[],t),damper:t=>Oo(e.dampers??[],t),suspensionOf:t=>os(Gy(e,t),t)}}function Gy(e,t){let r=Oo(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 Bo(e,t,r){let n={front:t.tire(e.tireModelId),rear:t.tire(e.tireModelIdRear)};return Ky(rM(t.suspensionOf(e),e,n),t,r)}function m5(e){return bc(e.air)?RA(e.air,e.airTempC??Et):void 0}var p5="the air the session states, at its venue";function d5(e,t){return t?{...e,rho:{...e.rho,value:t.rho},readouts:{...e.readouts,rho:p5}}:e}function f5(e,t,r){if(!r)return{rho:e.rho,motorModel:t,readouts:e.readouts};let{rho:n,readouts:o}=d5(e,r);return{rho:n,motorModel:t&&ht(t)?Vy(t,r):t,air:r,readouts:o}}function Ky(e,t,r){let n=t.tire(e.tireModelId),o=t.tire(e.tireModelIdRear),a=iC(sC(aC(dM(uM(vM(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}=f5(a,t.motor(e.motorModelId),m5(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),...Pi(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 y5=e=>e!==!1,x5=(e,t,r)=>r&&t>0?(e%t+t)%t:Math.min(Math.max(e,0),t);function R5(e,t,r){let n=e.points.filter(o=>Number.isFinite(o.at)&&Number.isFinite(o.z)).map(o=>({...o,at:x5(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 v5(e,t,r){let n=R5(e,t,r),o=n.length;if(o===0)return[];let a=p=>p<o-1?n[p+1].at-n[p].at:r?n[0].at+t-n[p].at:1/0,s=p=>p<o-1?(n[p+1].z-n[p].z)/a(p):r&&o>1?(n[0].z-n[p].z)/a(p):0,i=n.map(p=>Math.max(0,Number.isFinite(p.curve)?p.curve:0)/2),c=(p,d,h)=>i[p]+i[d]>h?h*i[p]/(i[p]+i[d]):i[p],l=p=>p<o-1||r?c(p,p<o-1?p+1:0,a(p)):Math.max(0,t-n[p].at),u=p=>p>0?c(p,p-1,a(p-1)):r?c(p,o-1,a(o-1)):n[p].at,m=p=>p>0?s(p-1):r&&o>1?s(o-1):n[p].at<=1e-9?s(p):0,f=p=>!r&&p===o-1&&o>1&&n[p].at>=t-1e-9?s(p-1):s(p);return n.map((p,d)=>{let h=l(d),b=u(d),g=Math.min(i[d],h,b),y=!r&&g<i[d]&&(d===o-1&&g===h||d===0&&g===b);return{at:p.at,z:p.z,gIn:m(d),gOut:f(d),half:g,asked:i[d],atEnd:y}})}function k5(e,t,r,n){let o=t-e.at;return n&&r>0?o-r*Math.round(o/r):o}function M5(e,t,r,n){for(let s of e){let i=k5(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 lC(e,t,r,n){let o=y5(n),a=v5(e,r,o);return a.length?t.map(s=>M5(a,s,r,o)):t.map(()=>0)}function qc(e,t){if(!t?.points.length)return e;let r=Tc(e),{zSmoothing:n,...o}=e;return{...o,z:lC(t,r,T0(e),e.closed)}}var Up={widthLeft:1.5,widthRight:1.5,bank:0,mu:1};function uC(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 Qc(e,t){let r=uC(e.source);return mC(e,r?await t(r):void 0)}function mC(e,t){let{source:r}=e;if(r.kind==="segments"){let{segments:i,closed:c,spacing:l}=r,{asset:u}=Lc(i,{name:e.name,closed:c,spacing:l,base:Up});return qc(u,r.profile)}let n=r.sections??[];if(r.kind==="inline")return qc(dp(r.asset,n,Up),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 qc(dp({...t,...o!==void 0?{widthLeft:o}:{},...a!==void 0?{widthRight:a}:{},...s!==void 0?{closed:s}:{}},n,Up),r.profile)}var Jpe=1/500;var ede=5*Math.PI/180;var lde=1/3;var w5=[4,2,1,.5,.25,.125];function pC(e,t,r={}){let n=[...r.steps??w5].sort((g,y)=>y-g),o=ut(r.numerics),a=r.tolPct??.5,s=It(e),i=e.ggvMode??"twoTrack",c=Rr(s,!1,i),l={...o,dsTarget:n[0]??o.dsTarget},u=n.length?bo(s,c,[mt(t,l)],l,i):void 0,m=wn(s,c.rows),f=n.map((g,y)=>{let R={...o,dsTarget:g},k=Date.now(),v=mt(t,R),x=wt(c,v,R,{...u?{load:u}:{},...m?{shifts:m}:{}});return r.onStep?.(y+1,n.length),{dsTarget:g,npts:v.npts,lapTime:x.laptime,ms:Date.now()-k}}),p=f[f.length-1]?.lapTime??NaN,d=f.map(g=>{let y=g.lapTime-p;return{...g,delta:y,deltaPct:p?100*y/p:NaN}}),h=d.filter(g=>Math.abs(g.deltaPct)<=a),b=h.length?Math.max(...h.map(g=>g.dsTarget)):null;return{points:d,reference:p,recommended:b,tolPct:a}}function fs(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:Ny(t.airTempC??r.airTempC),...bc(Xm(t.air??r.air))?{air:Xm(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:ut(r.numerics)}}async function Xp(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 Qc(r,t)}}function P5(e,t){let r=structuredClone(e);for(let[n,o]of Object.entries(t))if(!am(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 Hy=(e,t)=>{let r=e?.name;return typeof r=="string"&&r?r:t};function L5(e,t){let r={};for(let n of Pn){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:Hy(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:Hy(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:Hy(i.model,i.id),byFallback:!0}:null;continue}r[n.doc]=null}return r}function D5(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 dC(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 fC=e=>e.length<2?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;async function qp(e,t,r={}){let n=fs(e,r.settings),{entry:o,asset:a}=await Xp(e,t),s=Vo(e),i=r.vehicleIds?.length?r.vehicleIds.map(d=>{let h=e.vehicles.find(b=>b.id===d);if(!h)throw new Error(`this project holds no vehicle "${d}"`);return h}):e.vehicles.filter(d=>d.visible);if(!i.length)throw new Error("no vehicle is visible in this project \u2014 name some in vehicleIds");let c=i.map(d=>{let h=r.overrides?.[d.id]?P5(d.params,r.overrides[d.id]):d.params;return Bo(structuredClone(h),s,n)}),l=lc(vo(e.meta.rulesetId,e.rulesets)),u=fc(c,a,n.numerics,l,{racingLine:n.racingLine,standingStart:n.standingStart,lapCounts:n.lapCounts}),m={};i.forEach((d,h)=>{m[d.id]=u[h]});let{scores:f,field:p}=Ig(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:f!==null,vehicles:i.map((d,h)=>({id:d.id,name:u[h].name||String(d.params.name??d.id),events:D5(u[h]),metrics:_g(l,u[h],p?.[d.id]),fitted:L5(e,d.params),...f?.[d.id]?{score:{total:f[d.id].total,parts:{...f[d.id].parts}}}:{}})),raw:{results:m,scores:f,field:p}}}async function hC(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=fs(e),{asset:a}=await Xp(e,t),s=Bo(structuredClone(n.params),Vo(e),o);return pC(s,a,{...r.steps?{steps:r.steps}:{},numerics:o.numerics,...r.tolPct!==void 0?{tolPct:r.tolPct}:{},...r.onStep?{onStep:r.onStep}:{}})}var E5=(e,t)=>e[t]??[],I5=(e,t,r)=>r<=1?[e]:Array.from({length:r},(n,o)=>e+(t-e)*o/(r-1));function Qp(e){return e.kind==="param"?I5(e.start,e.end,Math.max(1,Math.round(e.steps))):e.kind==="part"?[...e.partIds]:[...e.values]}var bC=e=>e.kind==="param"?e.label:e.kind==="part"?`${e.part} model`:e.setting;function _5(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=Bo(structuredClone(r.params),Vo(e),fs(e)),o=xM(n,{geometry:!0}),a=om(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=Pn.find(l=>l.doc===i.part);if(!c)throw new Error(`"${i.part}" is not a library \u2014 it is one of ${Pn.map(l=>l.doc).join(", ")}`);for(let l of i.partIds)if(!E5(e,c.doc).some(u=>u.id===l))throw new Error(`the ${c.label} library holds no "${l}"`)}}let s=t.axes.reduce((i,c)=>i*Qp(c).length,1);if(s>Ym)throw new Error(`that grid is ${s} runs, over the ${Ym} cap \u2014 a run is a whole session. Drop an axis or use fewer steps.`)}var N5=e=>e.map(t=>String(typeof t=="number"?Number(t.toPrecision(4)):t)).join(" \xD7 ");function O5(e,t){let r=[...new Set(e.flatMap(o=>(o.didNotFinish??[]).map(a=>a.label)))],n=e.map(o=>({name:N5(o.at),events:r.map(a=>({label:a,incomplete:o.didNotFinish?.find(s=>s.label===a)}))}));return dC(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`:fC(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 V5(e){let t=[[]];for(let r of e){let n=Qp(r),o=[];for(let a of n)for(let s of t)o.push([...s,a]);t=o}return t}async function gC(e,t,r,n){_5(e,r);let o=V5(r.axes),a=[],s=!1;for(let[u,m]of o.entries()){let f=structuredClone(e),p=f.vehicles.find(k=>k.id===r.vehicleId),d={...r.settings},h={};r.axes.forEach((k,v)=>{let x=m[v];if(k.kind==="param")h[k.label]=x;else if(k.kind==="part"){let M=Pn.find(A=>A.doc===k.part);p.params[M.ref]=x}else d[k.setting]=x});let b=r.fleet?f.vehicles.filter(k=>k.visible||k.id===r.vehicleId).map(k=>k.id):[r.vehicleId],g=await qp(f,t,{vehicleIds:b,settings:d,...Object.keys(h).length?{overrides:{[r.vehicleId]:h}}:{}});s=g.fleetScored;let y=g.vehicles.find(k=>k.id===r.vehicleId),R=y.events.flatMap(k=>k.incomplete?[{label:k.label,...k.incomplete}]:[]);a.push({at:m,metrics:y.metrics,...R.length?{didNotFinish:R}:{}}),n?.(u+1,o.length)}let i=Object.keys(a[0]?.metrics??{}),c=[];r.axes.forEach((u,m)=>{if(Qp(u).length<2)return;i.some(p=>{if(new Set(a.map(b=>`${b.at[m]}`)).size<2)return!1;let h=a.map(b=>b.metrics[p]).filter(Number.isFinite);return Math.max(...h)-Math.min(...h)>1e-9})||c.push(bC(u))});let l=[];return s&&!r.fleet&&l.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."),l.push(...O5(a,s)),c.length&&l.push(`Nothing moved along ${c.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(u=>({kind:u.kind,label:bC(u),values:Qp(u)})),runs:a,metricKeys:i,fleetScored:s,flat:c,caveats:l}}var hhe=Math.PI/180;var Zp=.5,Z5=new Set(["lap","session"]);function J5(e){return rt({...e,label:e.label.replace(/ [xyz]$/,"")})}function xC(e){let t=Do(e);if(t)return[t.point];let r=Xt(e);if(r)return[r.point];let n=/^arm\.(front|rear)\.(uca|lca)\./.exec(e);if(n){let a=Bt[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]}.${Fr.fore}`,`hp.${o[1]}.${Fr.aft}`]:[]}function RC(e,t){let r=dt(e,t),n=vt(e),o=new Map;for(let a of[...r.variables,...r.followers??[]])for(let s of xC(a.id)){if(o.has(s))continue;let i=ss.map(c=>`${s}.${c}`).filter(c=>n[c]&&!n[c].supersededBy);i.length&&o.set(s,{id:s,name:J5(n[i[0]]),coords:i})}return[...o.values()]}function zy(e,t,r,n={},o=Zp){let a=dt(e,t),s=(n.metrics??nr()).byId,i=ds(e,a,r),c=RC(e,a),l=vt(i),u=[];a.objectives.forEach((S,F)=>{let C=s[S.metricId];C&&u.push({key:S.key??`target:${F}`,role:"target",metric:C,at:S.at})}),a.constraints.forEach((S,F)=>{let C=s[S.metricId];C&&u.push({key:S.key??`hold:${F}`,role:"hold",metric:C,at:S.at,hold:S})}),(a.watches??[]).forEach((S,F)=>{let C=s[S.metricId];C&&u.push({key:S.key??`watch:${F}`,role:"watch",metric:C,at:S.at})});let m=u.filter(S=>!Z5.has(S.metric.cost)),f=S=>{let F=Yp(S,a,n),C=m.map(L=>pt(F,L.metric,L.at));return F.failure?null:C},p=f(i)??m.map(()=>NaN),d=[],h=[],b=[],g=1,y=[...p],R=[...p],k=S=>S.forEach((F,C)=>{Number.isFinite(F)&&(F>=y[C]||(y[C]=F),F<=R[C]||(R[C]=F))}),v=S=>{g++;try{return f(S())}catch{return null}};for(let S of c)for(let F of S.coords){let C=l[F],L=C.read(i),E=F.slice(F.lastIndexOf(".")+1),D=v(()=>C.write(i,L+o)),N=v(()=>C.write(i,L-o));if(!D||!N){b.push(`${S.name} ${E}`);continue}d.push({id:F,def:C,now:L,point:S,axis:E}),h.push([D,N]),k(D),k(N)}let x=new Map,M=S=>{let F=S.join("");if(x.has(F))return;let C=v(()=>d.reduce((L,E,D)=>E.def.write(L,E.now+S[D]*o),i));x.set(F,C),C&&k(C)};d.length>1&&m.forEach((S,F)=>{let C=h.map(([L,E])=>L[F]-p[F]>=E[F]-p[F]?1:-1);Number.isFinite(p[F])&&(M(C),M(C.map(L=>-L)))});let A=[...x.values()].filter(S=>!S).length;A&&b.push(`${A} of ${x.size} corners`);let w=u.map(S=>{let F={key:S.key,role:S.role,name:Xe(S.metric)+No(S.at,S.metric,a),unit:S.metric.unit==="-"?"":S.metric.unit,...S.hold?{limit:{op:S.hold.op,limit:S.hold.limit,...S.hold.limit2!==void 0?{limit2:S.hold.limit2}:{}}}:{}},C=m.indexOf(S);if(C<0)return{...F,value:NaN,lo:NaN,hi:NaN,skipped:"read off a lap"};let L=p[C],E=Number.isFinite(L)?y[C]:NaN,D=Number.isFinite(L)?R[C]:NaN,N=h.map(([_,B])=>Math.max(Math.abs(_[C]-L),Math.abs(B[C]-L))),O=N.filter(Number.isFinite).reduce((_,B)=>_+B,0),z;if(O>0){let _=N.indexOf(Math.max(...N.filter(Number.isFinite)));z={point:d[_].point.name,axis:d[_].axis,share:N[_]/O}}let I=S.hold?Math.max(Nn(S.hold,E),Nn(S.hold,D)):void 0;return{...F,value:L,lo:E,hi:D,...z?{most:z}:{},...I!==void 0?{excess:I}:{}}}),T=new Set(c.flatMap(S=>S.coords)),P=a.variables.filter(S=>!xC(S.id).length&&!T.has(S.id)).length;return{mm:o,points:c,rows:w,evaluations:g,unsolved:b,settings:P}}function Yy(e){if(!e.chassis)return e;let{chassis:t,...r}=e;return t.boxes.length?{...r,chassis:{boxes:t.boxes}}:r}var Wye=180/Math.PI;var IB={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:Ro,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 xRe=IB.id;var Zc=.02;function EC(e){let t=Math.max(Zc,Math.abs(e.heaveMotionRatio)),r=Math.max(Zc,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 NB=(e,t)=>({od:t,id:Math.min(e.id,t-.5)}),OB=(e,t)=>e/(2*t*t);function DC(e,t){switch(e.kind){case"ubar":case"blade":case"torsionTube":return{...e,section:NB(e.section,t)};default:return e}}function IC(e,t,r){let n=Math.max(Zc,Math.abs(r));if(e?.kind==="coil"){let l=OB(t,n),u=e.rate;if(typeof u=="number")return{...e,rate:l};let m=Ur(u,0);if(!(m>0))return{...e,rate:l};let f=l/m;return{...e,rate:{...u,y:u.y.map(p=>p*f)}}}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=>Ii(DC(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 DC(a,c)}function _C(e,t,r,n){let o=e?.design,a=IC(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 VB=Math.PI/180,Jp=1e-6;function BB(e){return!(Me(e.rockerPivotA,e.rockerPivotB)<Jp||Me(e.rockerToPushrod,e.rockerPivotA)<Jp||Me(e.rockerToDamper,e.rockerPivotA)<Jp||Me(e.rockerToDamper,e.damperChassis)<Jp)}function BC(e){if(!BB(e.hardpoints))return!1;let t={...e,config:{...e.config,actuation:"rocker"}};try{let r=nt(t);for(let n of[-20,-1,0,1,20]){let o=ge(r,n,0);if(!o.ok||!Number.isFinite(o.state.metrics.damperLength))return!1}return!0}catch{return!1}}function $C(e){if(e.config.actuation!=="direct"||BC(e))return;let{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}=GB(e);return{rockerPivotA:t,rockerPivotB:r,rockerToPushrod:n,rockerToDamper:o}}var NC=40;function ed(e,t={}){let r=e.hardpoints,n=r.pushrodOuter,o=r.damperChassis,a=Me(n,o),s=te(n,U(K(o,n),$B)),i=t.armRod??Math.max(25,.15*a),c=t.armDamper??i,l=[s[0]-NC,s[1],s[2]],u=[s[0]+NC,s[1],s[2]],m=q(K(u,l)),f=K(n,s),p=q(K(f,U(m,OC(f,m)))),d=Gt(p,m,(t.armAngleDeg??60)*VB),h=te(s,U(d,i)),b=K(o,s),g=q(K(b,U(m,OC(b,m)))),y=U(q(ae(m,g)),t.damperSide??1),R=te(s,U(y,c));return{...r,rockerPivotA:l,rockerPivotB:u,rockerToPushrod:h,rockerToDamper:R}}var $B=.72,OC=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2];function VC(e){let t=Ye(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 GB(e,t={}){let r=t.target??VC(e),n=t.armAngleDeg,o=ed(e,{armAngleDeg:n});if(!(r>0))return o;let a=Me(e.hardpoints.pushrodOuter,e.hardpoints.damperChassis),s=Math.max(25,.15*a),i=(()=>{for(let p of[1,-1]){let d=ed(e,{armRod:s,armAngleDeg:n,damperSide:p}),h={...e,config:{...e.config,actuation:"rocker"},hardpoints:d};try{let b=nt(h),g=ge(b,15,0),y=ge(b,-15,0);if(g.ok&&y.ok&&g.state.metrics.damperLength<y.state.metrics.damperLength)return p}catch{}}return 1})(),c=(p,d)=>{try{return VC({...e,config:{...e.config,actuation:"rocker"},hardpoints:ed(e,{armRod:p,armAngleDeg:n,armDamper:d,damperSide:i})})}catch{return Number.NaN}},l=[1,.6,.35,.2,1.7,2.6].map(p=>Math.max(12,s*p)),u=s,m=s,f=1/0;for(let p of l){let d=.25*p,h=6*p,b=p;for(let y=0;y<24;y++){let R=(d+h)/2,k=c(p,R);if(!Number.isFinite(k))break;b=R,k<r?d=R:h=R}let g=Math.abs(c(p,b)-r);if(Number.isFinite(g)&&g<f&&(f=g,u=p,m=b),f<1e-4*Math.max(1,r))break}return ed(e,{armRod:u,armAngleDeg:n,armDamper:m,damperSide:i})}var ERe=Array.from({length:19},(e,t)=>-45+5*t);var IRe=Math.PI/180;function KB(e){let t=e.hardpoints,r=q(K(t.rockerPivotB,t.rockerPivotA)),n=mn(t.rockerToDamper,t.rockerPivotA,r),o=.6*un(K(t.rockerToDamper,n)),a=ae(r,Xx),s=un(a)>1e-6?q(a):q(K(t.rockerToDamper,n));return{outer:te(n,U(s,o)),inner:te(n,U(s,-o)),attach:"rocker"}}var HB=(e,t)=>({...e,config:{...e.config,actuation:t}});function Uy(e,t,r,n){let o=r==="front"?e.front:e.rear,a=ju(o),s=o.config.springRate*a*a,i=Q(t,r==="front"?"damper_front":"damper_rear")*a*a,c=r==="front"?t.arbFrontDesign:t.arbRearDesign,l=co(e,t)[r]??Q(t,r==="front"?"arb_front":"arb_rear"),u=Na(e,t)[r]??Q(t,r==="front"?"heave_spring_front":"heave_spring_rear"),m=$C(o),f=HB(m?{...o,hardpoints:{...o.hardpoints,...m}}:o,"decoupled"),p=r==="front"?t.heaveFrontDesign:t.heaveRearDesign,d=n?.heave??GC(p?.linkage,w=>Kn(f,w).atDesign)??df(f,"rockerToRocker"),h=!c||c.design.kind==="none"||c.design.kind==="coil",b=h?"coil":"ubar",g=c?.linkage&&(c.design.kind==="none"||c.linkage.attach!=="rocker")?c.linkage:void 0,y=n?.roll??GC(h?g:c?.linkage,w=>ca(f,w,{kind:b}).atDesign)??(h?KB(f):Bk(f)),R=Kn(f,d).atDesign,k=ca(f,y,{kind:b}).atDesign,v=Xu(e,t),x=EC({cornerWheelRate:s,cornerDamper:i,arbWheelRate:l,heaveWheelRate:u,heaveWheelDamping:r==="front"?v.heaveFront:v.heaveRear,rollWheelDamping:r==="front"?v.rollFront:v.rollRear,heaveMotionRatio:R,rollMotionRatio:k}),M=!c||c.design.kind==="none"?{design:{kind:"coil",rate:1},linkage:y}:{...c,linkage:y},A=_C({design:p?.design??{kind:"none"},linkage:d,damper:p?.damper},M,x,k);return m?{...A,crank:m}:A}function GC(e,t){return e&&Math.abs(t(e))>=Zc?e:void 0}var td=[{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"]}],Xy=()=>({arbFront:void 0,arbRear:void 0,heaveFront:void 0,heaveRear:void 0}),zB={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]}},YB={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]}},WB=()=>({outer:[0,189,486],attach:"rocker",mount:{kind:"chassis",anchor:[-225,0,486]}}),jB={rate:60,motionRatio:1},UB={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]}},XB=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]}},qB={kind:"coil",rate:1560,motionRatio:1,gap:0,bothWays:!0},QB=40,ZB={rockerPivotA:[50,130,440],rockerPivotB:[-50,130,440],rockerToPushrod:[10,170,460],rockerToDamper:[-20,64,440],damperChassis:[-20,64,215]},KC=()=>({outer:[-50,130,480],attach:"rocker",shaftStation:-50}),HC=()=>({outer:[50,130,400],inner:[50,130,480],attach:"rocker",shaftStationOuter:50,shaftStationInner:50}),JB=e=>[e[0],e[1],e[2]];function e$(e){let t=r=>({...r,hardpoints:{...r.hardpoints,...YC(ZB)},config:{...r.config,actuation:"decoupled"}});return{...e,front:t(e.front),rear:t(e.rear)}}function YC(e){return Object.fromEntries(Object.entries(e).map(([t,r])=>[t,JB(r)]))}function WC(e,t=Fo(),r=e==="pull"?YB:zB){let n=(o,a)=>({...o,hardpoints:{...o.hardpoints,...YC(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 rd(e,t){let r=qy(e),n=hs(e);if(e==="heave")return{meta:r,vehicle:n,components:{...Xy(),heaveFront:{design:{...Tb,...jB},linkage:WB()}}};if(e!=="decoupled")return{meta:r,vehicle:n,components:Xy()};let o=Uy(n,t,"front",{heave:KC(),roll:HC()}),a=Uy(n,t,"rear",{heave:KC(),roll:HC()});return{meta:r,vehicle:n,components:{arbFront:o.arb,arbRear:a.arb,heaveFront:o.heave,heaveRear:a.heave}}}function hs(e){let{name:t}=qy(e);if(e==="direct")return{...yc(),name:t};if(e==="mcpherson"){let n=xc(),o=Qm();return{...n,front:{...o,config:{...o.config,loadedRadius:n.front.config.loadedRadius}},name:t}}let r=t$(WC(e==="pullrod"?"pull":"push"));return{...e==="decoupled"?e$(r):r,name:t}}var zC={front:221.7,rear:220.9};function t$(e){return{...e,front:{...e.front,config:{...e.front.config,loadedRadius:zC.front}},rear:{...e.rear,config:{...e.rear.config,loadedRadius:zC.rear}}}}function qy(e){let t=td.find(r=>r.id===e);if(!t)throw new Error(`Unknown suspension template: ${e}`);return t}function nd(){let e=t=>({design:{...qB},linkage:XB(t),damper:QB});return{meta:qy("heave"),vehicle:WC("push",Kg(),UB),components:{...Xy(),heaveFront:e("front"),heaveRear:e("rear")}}}var jC=[10,25,50,100,200,300],r$=[{id:"c1",label:"Soft",scale:.7},{id:"c2",label:"Medium",scale:1},{id:"c3",label:"Firm",scale:1.4}],UC=e=>Math.round(e*100)/100;function n$(e,t,r){let n=jC.map(o=>UC(r*o));return{id:e,label:t,speedMmS:[...jC],bumpN:n,reboundN:[...n]}}function o$(e){return{name:e.name,body:{...e.body},curves:r$.map(t=>n$(t.id,t.label,UC(e.coefficient*t.scale)))}}function Jc(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 wr(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:Ac[e.dampers.length%Ac.length],model:o$(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 ft=e=>`${e} (typical)`,Qy={car:{name:ft("Formula Student damper"),coefficient:2.5,body:{extended:249,stroke:55}}},od={car:Qy.car,heave:{name:ft("Formula Student heave damper"),coefficient:3.4,body:{extended:270,stroke:47}},roll:{name:ft("Formula Student roll damper"),coefficient:3.7,body:{extended:322,stroke:100}}},ad={car:{name:ft("Formula 1 damper"),coefficient:6,body:{extended:240,stroke:40}},heave:{name:ft("Formula 1 heave damper"),coefficient:40,body:{extended:240,stroke:40}}},XC={car:{name:ft("GT damper"),coefficient:4.5,body:{extended:510,stroke:80}}},Zy={car:{name:ft("Sports car damper"),coefficient:2.4,body:{extended:515,stroke:110}}},qC={car:{name:ft("Sports car strut"),coefficient:2.4,body:{extended:310,stroke:120}},rear:Zy.car},QC={car:{name:ft("Cup car strut"),coefficient:4,body:{extended:285,stroke:75}},rear:{name:ft("Cup car rear damper"),coefficient:3.5,body:{extended:505,stroke:80}}},ZC={car:{name:ft("Stock car front damper"),coefficient:7.5,body:{extended:555,stroke:110}},rear:{name:ft("Stock car rear damper"),coefficient:6.75,body:{extended:555,stroke:110}}},JC={car:{name:ft("Hill-climb front damper"),coefficient:3,body:{extended:285,stroke:65}},rear:{name:ft("Hill-climb rear damper"),coefficient:3.5,body:{extended:285,stroke:65}}},eT={car:{name:ft("Race truck front damper"),coefficient:12,body:{extended:780,stroke:160}},rear:{name:ft("Race truck rear damper"),coefficient:8.5,body:{extended:780,stroke:160}}};function gs(e){return e.vehicles=e.vehicles.slice(0,1),e.activeVehicleId=e.vehicles[0]?.id??null,e}function On(e,t){let r=Fc(e);return r.meta.rulesetId=t,r}function $o(e,t,r,n){let o=On(e,t);return o.suspensions=[{...o.suspensions[0],model:n()}],o.vehicles=[f0(r,"v1",0)],o.activeVehicleId="v1",o}var[,a$,s$,i$,c$,l$,u$,m$]=qg;function Jy(e,t){delete e.arbFrontDesign,delete e.arbRearDesign,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 tT(){return{...hs("decoupled"),name:Fo().name}}var p$=[{label:"Formula Student (decoupled)",vehicle:tT,components:e=>Jc(rd("decoupled",e).components,od)},{label:"Formula 1 (third springs)",vehicle:()=>nd().vehicle,components:()=>Jc(nd().components,ad)}],ex={"direct-coilover":"direct",pushrod:"pushrod",pullrod:"pullrod","third-spring":"heave","mcpherson-strut":"mcpherson"},d$=[...p$.map(e=>e.vehicle),...Object.values(ex).map(e=>()=>hs(e))];function bs(e){let t=Jc(rd("decoupled",e.vehicles[0].params).components,od);e.suspensions=[{...e.suspensions[0],model:tT()}];for(let r of e.vehicles)Jy(r.params,t);return wr(e,od),e}var Go={title:"OpenStreetMap",url:"https://www.openstreetmap.org/copyright",licence:"ODbL-1.0",credit:"\xA9 OpenStreetMap contributors"},sd={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"},rT={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]"},nT={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"},f$={id:"cota",name:"Circuit of the Americas, Austin",address:"e0c6ea889d708cf15f9c",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Go,sd,nT]}},h$={id:"laguna-seca",name:"Laguna Seca, Monterey",address:"185b5811b9c423ef44ef",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Go,sd,nT]}},b$={id:"nordschleife",name:"Nordschleife, N\xFCrburg",address:"74c49603c7b2f15985c6",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Go,rT]}},g$={id:"brands-hatch",name:"Brands Hatch, Kent",address:"c4953e3c25eaba4a5b7e",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Go,{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."}]}},y$={id:"bristol",name:"Bristol, Tennessee",address:"f0e23953669a414ad600",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Go,sd]}},x$={id:"pikes-peak",name:"Pikes Peak, Colorado",address:"3de137fe33b5c2875036",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Go,sd]},standingStart:!0},R$={source:"venue",altitudeM:3580,pressure:{kind:"standard"},humidityPct:0},v$=10,k$={id:"nurburg-sprint",name:"Sprintstrecke, N\xFCrburg",address:"1875636cdbb615aa2756",provenance:{fidelity:"derived",licence:"ODbL-1.0",sources:[Go,rT]}};function Ko(e,t){let{id:r,name:n,address:o,provenance:a,standingStart:s}=t,i={kind:"catalogue",id:r,address:o},c=Rc(s0({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 Vn(e,t,r){let n=e.vehicles[0].params,o=`m${e.motors.length+1}`;e.motors=[...e.motors,{id:o,color:Ln[e.motors.length%Ln.length],model:t}];let a=sM({},{...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 M$=3.8,id={hubPlanetary:14.5,inboardChain:4,engineChain:3.4},S$="Hub motor, 35 kW (example)";function tx(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 oT(e){let t=e.motors.find(r=>r.id==="m1");return t.model={...t.model,name:S$},t.id}function cd(e,t,r){let n=gs(bs(On(e,r)));return n.vehicles[0].params.name=t,n}function A$(){let e=cd("Formula Student combustion car","Formula Student combustion","fs-cv");Vn(e,t0(),id.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 F$(){let e=cd("Formula Student AWD car","Formula Student AWD","fs-ev");return tx(e,oT(e),4,"awd",id.hubPlanetary,"hub"),e}function w$(){let e=cd("Formula Student RWD hub-motor car","Formula Student RWD hub motors","fs-ev");return tx(e,oT(e),2,"rear",id.hubPlanetary,"hub"),e}function C$(){let e=cd("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:Ln[e.motors.length%Ln.length],model:e0()}],tx(e,t,1,"rear",id.inboardChain),e.vehicles[0].params.driveline={rear:structuredClone(Ft.clutch)},e}function T$(){let e=gs(bs(On("Formula Student endurance energy","fs-ev"))),t=e.vehicles[0],r=structuredClone(t);if(r.id="v2",r.color=Sc[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 P$(){let e=nd(),t=$o("Formula 1 car","trackday",a$,()=>e.vehicle);return Jy(t.vehicles[0].params,Jc(e.components,ad)),wr(t,ad),Vn(t,r0(),M$),Ko(t,f$)}function aT(e="GT car",t=yc){let r=$o(e,"trackday",s$,t);return wr(r,XC),Vn(r,IA(),r.vehicles[0].params.gear_ratio.value),Ko(r,h$)}function sT(e="Sports car",t=xc,r=Zy){let n=$o(e,"trackday",i$,t);return wr(n,r),Vn(n,_A(),n.vehicles[0].params.gear_ratio.value),Ko(n,b$)}function L$(){let e=$o("Cup car","trackday",c$,kA);return wr(e,QC),Vn(e,NA(),e.vehicles[0].params.gear_ratio.value),Ko(e,g$)}function D$(){let e=$o("Stock car","trackday",l$,MA);return wr(e,ZC),Vn(e,OA(),e.vehicles[0].params.gear_ratio.value),Ko(e,y$)}function E$(){let e=$o("Hill-climb prototype","trackday",u$,SA);return wr(e,JC),Vn(e,VA(),e.vehicles[0].params.gear_ratio.value),e.settings.air=structuredClone(R$),e.settings.airTempC=v$,Ko(e,x$)}function I$(){let e=$o("Race truck","trackday",m$,AA);return wr(e,eT),Vn(e,BA(),e.vehicles[0].params.gear_ratio.value),Ko(e,k$)}function _$(e){let t=td.find(o=>o.id===e);if(e==="direct")return aT(t.name,()=>hs(e));if(e==="mcpherson")return sT(t.name,()=>hs(e),qC);let r=gs(On(t.name,"trackday")),n=rd(e,r.vehicles[0].params);return r.suspensions=[{...r.suspensions[0],model:n.vehicle}],Jy(r.vehicles[0].params,n.components),wr(r,Qy),r}function el(e,t,r){let n=ex[e],o=td.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:()=>_$(n)}}var N$=[{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:()=>bs(On("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:T$},{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:()=>gs(bs(On("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:A$},{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:F$},{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:w$},{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:C$},{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:P$},{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:aT},{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:sT},{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:L$},{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:D$},{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:E$},{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:I$},{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:()=>gs(bs(On("Suspension study","trackday")))},el("direct-coilover","The GT car\u2019s wishbones driving coilovers straight into the towers, at Laguna Seca.","On the GT car, at Laguna Seca."),el("pushrod","The FS car on pushrods: a rod from each lower wishbone works a rocker.","On the Formula Student car, at FSG."),el("pullrod","The FS car on pullrods: a rod from each upper wishbone pulls a low rocker.","On the Formula Student car, at FSG."),el("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."),el("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:()=>gs(bs(On("Tyre study","fs-ev")))}],iT=N$.map(e=>({...e,load:()=>h0(e.load())}));var cT={width:320,height:200},yve=[.6*cT.width-9,.6*cT.height-9];var lT=new WeakMap,uT=new WeakMap,rx=e=>JSON.stringify(e,(t,r)=>r===1/0?"Infinity":r);function mT(e,t){if(!t){let a=lT.get(e);return a||(a=Nt(e),lT.set(e,a)),a}let r=uT.get(e);r||(r=new Map,uT.set(e,r));let n=rx(t),o=r.get(n);return o||(r.size>=4&&r.clear(),o=Nt(e,t),r.set(n,o)),o}var B$=Math.PI/180,$$=e=>e>1?e/100:e;function tl(e){let t=null;return()=>(t??={v:e()}).v}function pT(e){let t=Ye(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 dT=new WeakMap,nx={heave:0,pitch:0,roll:0,steer:0},fT=[0,1,2,3,4],hT=[-20,-10,0,10,20];function gT(e,t){let r=Xr(e,nx),n=["front","rear"],o=c=>{let l=Ni(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 fT){let l=c===0?null:Xr(e,{...nx,roll:c*B$});n.forEach((u,m)=>{let f=l?Ni(l[u]):null,p=f&&Number.isFinite(a[m]);s[m].rc.push(p?t[m]+(f.left+f.right)/2-a[m]:t[m]),s[m].split.push(p?(f.left-f.right)/2:0)})}let i=n.map(()=>[]);for(let c of hT){let l=c===0?null:Xr(e,{...nx,heave:-c});n.forEach((u,m)=>{let f=l&&l[u].valid&&r[u].valid;i[m].push(f?t[m]+l[u].height-r[u].height:t[m])})}return{roll:{rollDeg:fT,rcFront:s[0].rc,rcRear:s[1].rc,rcSplitFront:s[0].split,rcSplitRear:s[1].split},heave:{drop:hT,rcFront:i[0],rcRear:i[1]}}}var bT=new WeakMap;function G$(e,t,r,n){let o=bT.get(e);o||(o=new Map,bT.set(e,o));let a=`${rx(r)}|${n[0]}|${n[1]}`,s=o.get(a);if(!s){o.size>=4&&o.clear();try{s=gT(mT(e,r),n)}catch{s=t.rigidMigration(n)}o.set(a,s)}return s}function K$(e){let t=dT.get(e);if(t)return t;let r=Nt(e),n=Xr(r,{heave:0,pitch:0,roll:0,steer:0}),o=pT(e.front),a=pT(e.rear),s={wheelbase:e.config.wheelbase,trackFront:kt(e.front),trackRear:kt(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:_a(n.front),rcGainRear:_a(n.rear),rigidMigration:i=>gT(r,i),kinFront:tl(()=>xa(e.front)),kinRear:tl(()=>xa(e.rear))};return dT.set(e,s),s}function yT(e,t,r,n){let o=K$(e),a=co(e,t),s=Na(e,t),i=Jk(e,t),c=Xu(e,t),l=eM(e,t),u=tM(t),m=qu(e,t),f=io(e.front),p=io(e.rear),d=so(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,Q(t,"cop_long"))),copHeight:Q(t,"cop_height"),...t.aeroModel?{model:t.aeroModel}:{},rideHeightFront:Q(t,"ride_height_front"),rideHeightRear:Q(t,"ride_height_rear")},b=9.81,g=$$(t.front_mass_diss.value),y=Va(t,r,n),R=De(y.front),k=y.rear===y.front?R:De(y.rear),v=n??t.tireModelRear??r,x=t.m.value*b*g/2,M=t.m.value*b*(1-g)/2,A=R.corneringStiffness(x),w=k.corneringStiffness(M),T=(r?R.verticalStiffness():0)||Q(t,"tire_vertical_rate"),P=(v?k.verticalStiffness():0)||Q(t,"tire_vertical_rate"),S=dr(r)??0,F=dr(v)??0,C=tm({freeRadius:S,staticLoad:x,tyreRate:T,surveyed:e.front.config.loadedRadius},{freeRadius:F,staticLoad:M,tyreRate:P,surveyed:e.rear.config.loadedRadius},g),L=jt(S,x,T,e.front.config.loadedRadius),E=jt(F,M,P,e.rear.config.loadedRadius),D=[qr(o.rcHeightFront,o.rcGainFront,e.front.config.loadedRadius,L),qr(o.rcHeightRear,o.rcGainRear,e.rear.config.loadedRadius,E)],N=tl(()=>Gi(o.kinFront(),Q(t,"camber_front_deg"))),O=tl(()=>Gi(o.kinRear(),Q(t,"camber_rear_deg"))),z=tl(()=>G$(e,o,as(B),D)),I=bi({...t,wheelbase:{...t.wheelbase,value:o.wheelbase}}),_=$i(t),B={massTotal:t.m.value,frontMassFrac:g,steeringSystem:t.steeringSystem,tv:_u(t),cgHeight:Oa(Q(t,"cg_height"),t.cgReference?.standingRadius,C),cgStandingRadius:C,wheelbase:o.wheelbase,trackFront:o.trackFront,trackRear:o.trackRear,wheelRateFront:f?0:o.wheelRateFront,wheelRateRear:p?0:o.wheelRateRear,decoupledFront:f,decoupledRear:p,...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&&!f?{heaveSeatFront:i.front}:{},...i.rear&&!p?{heaveSeatRear:i.rear}:{},...m.rollFront.coilover?{rollCoiloverFront:m.rollFront.coilover}:{},...m.rollRear.coilover?{rollCoiloverRear:m.rollRear.coilover}:{},tireRate:T,...P!==T?{tireRateRear:P}:{},tireDamping:Q(t,"tire_vertical_damping"),arbFront:a.front??Q(t,"arb_front"),arbRear:a.rear??Q(t,"arb_rear"),brakeBalanceFront:I.balanceFront,brakes:I,..._?{driveline:_}:{},heaveSpringFront:s.front??Q(t,"heave_spring_front"),heaveSpringRear:s.rear??Q(t,"heave_spring_rear"),unsprungPerCorner:Q(t,"unsprung_mass"),unsprungCgHeight:jt(S,x,T,o.unsprungCgHeight),tyreFreeRadius:S,...F!==S?{tyreFreeRadiusRear:F}:{},rcHeightFront:D[0],rcHeightRear:D[1],corneringStiffnessFront:A,corneringStiffnessRear:w,get kinFront(){return N()},get kinRear(){return O()},damperFront:f?0:d?.front?.rate??Q(t,"damper_front")*o.mrFront*o.mrFront,damperRear:p?0:d?.rear?.rate??Q(t,"damper_rear")*o.mrRear*o.mrRear,...d?.front&&!f?{damperCurveFront:d.front.curve}:{},...d?.rear&&!p?{damperCurveRear:d.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:Q(t,"unsprung_mass"),get rollCentreCurve(){return z().roll},get rcHeaveCurve(){return z().heave},aero:h,yawInertia:Q(t,"I_yaw"),rollInertia:Q(t,"I_roll"),pitchInertia:Q(t,"I_pitch"),get steerFront(){return Qu(e.front,L)},ackermannPct:Q(t,"ackermann_pct"),toeFrontDeg:Q(t,"toe_front_deg"),toeRearDeg:Q(t,"toe_rear_deg")};return B}var RT=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}),ax={ggvMode:"twoTrack"},xT=new WeakMap;function sx(e,t=ax){let r=xT.get(e.vehicle);r||xT.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={...RT(e.params),suspensionOf:()=>e.vehicle};n.set(o,a=Bo(e.params,s,t))}return a}var vT=(e=ax)=>t=>sx(t,e),kT=(e=ax)=>t=>yT(t.vehicle,Ky(t.params,RT(t.params),e),t.params.tireModel,t.params.tireModelRear);function H$(e,t){return sx(e,t.switches)}var ix=e=>nr(e?.rulesets);function MT(e,t,r,n,o={},a=()=>r.standingStart){let s=sx(n,r.switches),i=(l,u)=>{let m=zm(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 ST=e=>[...new Set(e.lap.courses.flatMap(t=>t.course.kind==="track"?[t.course.trackId]:[]))],AT=e=>{let t=e?.session;return t?{sessionParams:r=>H$(r,t),session:()=>t}:{}},nl=e=>({metrics:ix(e),assemble:kT(e?.switches),simParams:vT(e?.switches),projectTrack:()=>e?.course??null,libraryTrack:t=>e?.tracks?.[t]??null,numerics:e?.numerics,...AT(e)}),z$=(e,t)=>({density:e.density,envelope:e.envelope,states:e.states,operating:e.operating,lap:e.lap,assemble:kT(t?.switches),simParams:vT(t?.switches),projectTrack:()=>t?.course??null,libraryTrack:r=>t?.tracks?.[r]??null,numerics:t?.numerics,...AT(t)}),FT="nelder-mead",wT=600,rl=[0,.15,.15];function CT(e,t,r,n=rl.length){let o=ux(t);return rl.slice(0,Math.max(1,n)).map((a,s)=>({...e,seed:s+1,startJitter:a,car:o,...r?{lap:r}:{}}))}function TT(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 PT(e,t,r,n,o=.01){let a=ix(n).byId;return Y$(e,t,r,n).filter(s=>s.excess>-o*(a[s.metricId]?.scale??1))}function Y$(e,t,r,n){let o;try{o=En(ds(e,t,r),z$(t,n))}catch{return[]}return W$(o,t,ix(n))}function W$(e,t,r){let n=[];for(let o of t.constraints){let a=r.byId[o.metricId];if(!a)continue;let s=pt(e,a,o.at);if(!Number.isFinite(s))continue;let i=`${Xe(a)}${No(o.at,a)}`;n.push({key:o.key,metricId:o.metricId,label:i,unit:a.unit==="-"?"":a.unit,value:s,excess:Nn(o,s)})}return n}var j$=.05;function U$(e,t){if(t.id.startsWith("hp.")||Kp(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 xy(_n(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 by(on(o.hardpoints,n[2]),n[3],1)}function LT(e,t,r){let n=r.filter(f=>f.score.feasible);if(n.length<2)return null;let o=t.map(f=>U$(e,f)),a=o.every(f=>f!==null)?"mm":null,s=0,i="",c=0,l=n.reduce((f,p)=>p.score.total<f.score.total?p:f);for(let f of n)if(f!==l)for(let p=0;p<t.length;p++){let d=Math.abs(f.x[p]-l.x[p])*(o[p]??1);c+=d*d,d>s&&(s=d,i=t[p].name)}let u=n.map(f=>f.score.total),m=l.score.terms.reduce((f,p)=>f+(p.resolution??0),0);return{distance:Math.sqrt(c),worst:s,worstName:i,scoreSpread:Math.max(...u)-Math.min(...u),tolerance:Math.max(j$,m),unit:a}}var X$={steeringSystem:!0,brakeSetup:!0,driveline:!0,heaveFrontDesign:!0,heaveRearDesign:!0,arbFrontDesign:!0,arbRearDesign:!0},DT=e=>Object.hasOwn(X$,e);function ox(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`:null:null}function q$(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":DT(t)||ox(e)?"block":null}function cx(e,t){t=dt(e,t);let r=vt(e);return[...t.variables,...t.followers??[]].filter(n=>r[n.id]&&!r[n.id].supersededBy&&!q$(n.id)).map(n=>rt(r[n.id]))}function ET(e,t,r){t=dt(e,t);let n=vt(e),o=ds(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,f,p,d]=c.id.split(".");if(m==="rocker"){let h=`${f}.rocker`;if(i.has(h))continue;i.add(h);let b=f==="front"?o.vehicle.front:o.vehicle.rear;for(let g of[Fr.fore,Fr.aft]){let y=b.hardpoints[g];for(let R=0;R<3;R++)a.push({kind:"hardpoint",axle:f,key:g,axis:R,value:y[R]})}}else if(m==="arm"){let h=`${f}.${p}`;if(i.has(h))continue;i.add(h);let b=f==="front"?o.vehicle.front:o.vehicle.rear,g=Bt[p];for(let y of[g.fore,g.aft]){let R=b.hardpoints[y];for(let k=0;k<3;k++)a.push({kind:"hardpoint",axle:f,key:y,axis:k,value:R[k]})}}else if(m==="hp"&&Xt(c.id)){let h=`${f}.${p}`;if(i.has(h))continue;i.add(h);let b=(f==="front"?o.vehicle.front:o.vehicle.rear).hardpoints[p];for(let g=0;g<3;g++)a.push({kind:"hardpoint",axle:f,key:p,axis:g,value:b[g]})}else if(m==="hp")a.push({kind:"hardpoint",axle:f,key:p,axis:"xyz".indexOf(d),value:u});else if(m==="cfg")a.push({kind:"config",axle:f,field:p,value:u});else if(m==="kc"){if(s.has(`kc.${f}`))continue;s.add(`kc.${f}`);let h=f==="front"?o.vehicle.front:o.vehicle.rear;a.push({kind:"compliance",axle:f,value:h.compliance})}else if(m==="param")a.push({kind:"param",label:rt(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(DT(m)||ox(c.id)){let h=ox(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 lx(e){let t=performance.now(),r=nl(e.lap),n=e.follow?Py(e.car,e.spec,r):e.spec,{dead:o,unprobed:a,...s}=Iy(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 IT(e){let t=performance.now();return{tolerance:zy(e.car,e.spec,e.x,nl(e.lap),e.mm),elapsedMs:performance.now()-t}}var ux=e=>e.vehicle.chassis?{...e,vehicle:Yy(e.vehicle)}:e;function _T(e,t){try{let r=mx(e.car,e.spec,e.lap),n=ka.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:Or(r.variables),score:Nr(r,Or(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&&My(r.variables)?Ay(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 mx=(e,t,r)=>Wp(e,t,nl(r));function NT(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),...Pi(e,t.damper)}}function OT(e,t,r){let{tireModelRear:n,damperModelRear:o,heaveDamperModel:a,rollDamperModel:s,...i}=r;return{vehicle:e,params:{...t,...i,...n?{tireModelRear:n}:{},...o?{damperModelRear:o}:{},...a?{heaveDamperModel:a}:{},...s?{rollDamperModel:s}:{}}}}var VT=e=>({ggvMode:e.ggvMode,quasiTransient:e.quasiTransient===!0&&e.ggvMode!=="fast",motorThermal:e.motorThermal===!0,...cC({brakeFade:e.brakeFade===!0,airTempC:e.airTempC,diffYaw:e.diffYaw===!0,...e.air?{air:e.air}:{}})});function Q$(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 BT(e,t){let r=t.plannedPath!==void 0,n=Q$(t);return{...MT(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 px(e,t){let r=e.vehicles.find(o=>o.id===t);if(!r)throw new Error(`this project holds no vehicle "${t}"`);let n=Vo(e);return OT(structuredClone(Gy(e,r.params)),structuredClone(r.params),NT(r.params,n))}var Z$="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 dx(e,t,r,n){if(e.settings.pathPlanId)throw new Error(Z$);let o=fs(e),a=e.tracks.length?(await Xp(e,t)).asset:null,s={};for(let i of n?ST(n):[]){let c=e.tracks.find(l=>l.id===i);c&&(s[i]=await Qc(c,t))}return BT(r,{track:a,numerics:o.numerics,racingLine:o.racingLine,standingStart:o.standingStart,lapCounts:o.lapCounts??{},switches:VT(o),rulesets:e.rulesets??[],library:s,standingOf:i=>e.tracks.find(c=>c.id===i)?.standingStart===!0})}async function $T(e,t,r,n){let o=px(e,r),a=dt(o,n),s=await dx(e,t,o,a);return lx({id:0,car:o,spec:a,lap:s})}async function GT(e,t,r,n){let o=px(e,r),a=dt(o,n),s=cx(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 dx(e,t,o,a)}catch(l){return{problems:[l instanceof Error?l.message:String(l)]}}let c=Ey(o,a,{...nl(i),metrics:nr(e.rulesets)});return c.length?{problems:c}:{problems:[],msPerEval:lx({id:0,car:o,spec:a,lap:i}).msPerEval,carFingerprint:xo(ux(o))}}async function J$(e,t,r,n,o,a=[]){let s=CT(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 f=[],p=null,d=null;if(_T(m,y=>{y.kind==="progress"?(f.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"?p={result:y.result,elapsedMs:y.elapsedMs}:d=y.message}),d)throw new Error(d);if(!p)throw new Error("the search stopped without a result");let{result:h,elapsedMs:b}=p,g={seed:m.seed,startJitter:m.startJitter,x:h.x,score:h.score,evaluations:h.evaluations,infeasible:h.infeasible,history:h.history,trace:f,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 KT(e,t,r,n){let o=px(e,r.vehicleId),a=dt(o,r.spec),s=cx(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 dx(e,t,o,a),c=r.method??FT;if(!ka.some(R=>R.name===c))throw new Error(`unknown method "${c}" \u2014 it is one of ${ka.map(R=>R.name).join(", ")}`);let l=r.budget??wT,u=Math.max(1,Math.min(r.seeds??rl.length,rl.length)),m=await J$(o,{spec:a,method:c,budget:l},i,u,n),f=mx(o,a,i),p=m.runs.map(R=>({seed:R.seed,startScore:m.designScore.total,score:R.score.total,feasible:R.score.feasible,...R.score.reason?{reason:R.score.reason}:{},terms:R.score.terms,x:R.x,evaluations:R.evaluations,infeasible:R.infeasible,bounds:TT(f.variables,R.x),constraints:PT(o,a,R.x,i),...R.snapped?{onSteps:{x:R.snapped.x,score:R.snapped.score.total,feasible:R.snapped.score.feasible,...R.snapped.score.reason?{reason:R.snapped.score.reason}:{},terms:R.snapped.score.terms}}:{}})),d=m.runs.reduce((R,k)=>ai(k.score,R.score)?k:R),h=d.snapped?.score.feasible?d.snapped:null,b=h?h.x:d.x,g=r.tolerance??Zp,y=d.score.feasible&&g>0?IT({id:0,car:o,spec:a,x:b,lap:i,mm:g}).tolerance:null;return{method:c,budget:l,seeds:p,spread:m.runs.length>1?LT(o,f.variables,m.runs.map(R=>({x:R.x,score:R.score}))):null,writes:ET(o,a,b),...d.snapped?{adopts:h?"on its steps":`as found: on its steps it breaks a hold (${d.snapped.score.reason??"not legal"})`}:{},...y?{asBuilt:y}:{}}}function zT(){if(typeof process.threadCpuUsage!="function")return performance.now();let e=process.threadCpuUsage();return(e.user+e.system)/1e3}async function tG(e,t){let r=oC(e.root);switch(e.kind){case"sweep":return gC(e.doc,r,e.req,t);case"convergence":return hC(e.doc,r,{vehicleId:e.vehicleId,...e.steps?{steps:e.steps}:{},...e.tolPct!==void 0?{tolPct:e.tolPct}:{},onStep:t});case"study":return KT(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 qp(e.doc,r,{...e.vehicleIds?{vehicleIds:e.vehicleIds}:{},...e.settings?{settings:e.settings}:{},...e.overrides?{overrides:e.overrides}:{}});case"probe":return $T(e.doc,r,e.vehicleId,e.spec);case"quote":return GT(e.doc,r,e.vehicleId,e.spec)}}if(HT){let e=HT,t=r=>e.postMessage(r);(async()=>{try{let r=await tG(eG,(n,o)=>t({type:"progress",done:n,total:o}));t({type:"done",result:r,cpuMs:zT()})}catch(r){t({type:"failed",message:r instanceof Error?r.message:String(r),cpuMs:zT()})}})()}export{tG as runJob,zT as threadCpuMs};